mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The `paperclipai` CLI is how humans and other agents drive Paperclip
from a terminal or script
> - Many `client/*` command files declare `-C, --company-id` with
`.requiredOption(...)`, so commander aborts argument parsing before the
command's action ever runs
> - Every one of those same actions calls `resolveCommandContext(opts, {
requireCompany: true })`, which already resolves the company id from
`--company-id` -> `PAPERCLIP_COMPANY_ID` -> the context profile, and
throws a clear error only when all three are empty
> - So a command like `agent list` fails immediately on a bare parse
error even when the caller has `PAPERCLIP_COMPANY_ID` exported or a
context profile set, while a sibling command like `issue list` (no
`requiredOption`) works fine from the same environment — same resolver,
inconsistent enforcement point
> - This pull request replaces `.requiredOption("-C, --company-id <id>",
...)` with `.option(...)` at every site backed by
`resolveCommandContext(..., { requireCompany: true })`, leaving
`requireCompany: true` untouched so the resolver still enforces the
requirement, just with its existing, more informative error message
> - The benefit is that `--company-id` behaves consistently across every
client command: env var and context-profile fallback always work, and
the error message when nothing is set comes from one place instead of
commander's generic "required option not specified"
## Linked Issues or Issue Description
No public GitHub issue exists for this yet, so following the Enhancement
proposal template inline:
**What existing behavior does this improve?**
The `-C, --company-id` option on CLI client commands under
`cli/src/commands/client/`.
**Subsystem affected**
Unsure / cross-cutting within the CLI — this is not one of the listed
subsystems (server/, ui/, packages/db, packages/shared,
packages/adapters, packages/plugins); it is
`cli/src/commands/client/**`.
**Current behavior**
28 commands across
`cli/src/commands/client/{activity,agent,approval,company,goal,plugin,project,secrets,token}.ts`
declare `-C, --company-id` via commander's `.requiredOption(...)`.
Commander enforces that flag at argument-parse time and exits with a
generic `error: required option '-C, --company-id <id>' not specified`
before the command's action function runs — even though every one of
those actions calls `resolveCommandContext(opts, { requireCompany: true
})`, which is fully capable of resolving the company id from
`PAPERCLIP_COMPANY_ID` or the context profile. Other commands in the
same CLI (e.g. `issue list`) use `.option(...)` for the same flag and
already work from env/profile. The result is an inconsistent, confusing
failure mode depending on which command you call.
**Proposed behavior**
All 28 sites use `.option("-C, --company-id <id>", ...)` instead of
`.requiredOption(...)`. `requireCompany: true` stays in
`resolveCommandContext`, so a company id is still required end-to-end —
it can now come from `--company-id`, `PAPERCLIP_COMPANY_ID`, or the
context profile, uniformly, with one shared, descriptive error message
when none of the three are set.
**Breaking changes**
None for correctly-configured callers. A caller that relied on
commander's parse-time rejection (rather than the resolver's `Company ID
is required...` message) would see a different error message, but the
exit-code behavior (non-zero, no company id resolved) is unchanged. No
response shape, output format, or successful-path behavior changes.
## What Changed
- Replaced `.requiredOption("-C, --company-id <id>", ...)` with
`.option("-C, --company-id <id>", ...)` at all 28 call sites across
`cli/src/commands/client/activity.ts`, `agent.ts`, `approval.ts`,
`company.ts`, `goal.ts`, `plugin.ts`, `project.ts`, `secrets.ts`, and
`token.ts`.
- Left `resolveCommandContext(opts, { requireCompany: true })` unchanged
everywhere — enforcement still happens there, with its existing error
message.
- Added `cli/src/__tests__/company-id-option.test.ts`, a regression test
modelled on `auth-command-registration.test.ts` that registers every
affected command family (`company`, `issue`, `agent`, `approval`,
`activity`, `dashboard`, `feedback`, `goal`, `plugin`, `project`,
`secrets`, `token`), walks the full command tree, and asserts
`--company-id` is never `mandatory` (commander's `.requiredOption`
discriminator) and never declared more than once on the same command.
## Verification
```
$ grep -rn 'requiredOption("-C' cli/src/commands/client/
# exit code 1, no matches
```
```
$ cd cli && pnpm exec vitest run src/__tests__/company-id-option.test.ts
Test Files 1 passed (1)
Tests 2 passed (2)
```
Red on the unpatched tree (reverting only the fix files reproduces 9+
offending commands):
```
$ git stash push -- cli/src/commands/client/*.ts
$ pnpm exec vitest run src/__tests__/company-id-option.test.ts
❯ … 1 failed
AssertionError: --company-id must never be mandatory; offending commands: …
$ git stash pop
```
```
$ pnpm -C cli build
# green (tsc --noEmit at the repo root reports ~139 pre-existing errors in
# server/src/** from a missing built @paperclipai/plugin-sdk dist, present
# identically on the unpatched tree and unrelated to this diff;
# cli/src/commands/client/** itself has zero new type errors)
```
Behavioral check via `cli/src/index.ts`:
```
$ PAPERCLIP_COMPANY_ID=test-co-123 PAPERCLIP_API_KEY=fake pnpm exec tsx src/index.ts agent list --json
API error 401: Unauthorized
# past argument parsing, into an HTTP/auth error — this is the intended fix
$ pnpm exec tsx src/index.ts agent list --json --context /tmp/pc-empty-context.json
Company ID is required. Pass --company-id, set PAPERCLIP_COMPANY_ID, or set context profile companyId via `paperclipai context set`.
```
## Risks
Low risk. This only relaxes a commander-level parse constraint; the
underlying requirement (`requireCompany: true`) is untouched, so every
affected command still refuses to proceed without a resolvable company
id. The main behavioral shift is the error message and the point at
which the error surfaces (resolver instead of commander), which is
strictly more informative. No API, schema, or persisted-data changes.
## Model Used
Claude (Anthropic), Claude Opus, extended thinking / chain-of-thought
reasoning enabled, with tool use (repo grep/read/edit, test execution)
throughout implementation and verification.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
## Related PRs found during duplicate search
- #4276 (`feat(cli): unify issue flag matrix (A+B) — -C optional +
per-subcommand guards`) — open, overlapping intent (also makes `-C`
optional) but scoped to `issue create` only plus a separate flag-hint
feature; does not touch the other 27 sites this PR fixes. Not a
duplicate.
- #2538 (`Refine CLI company commands behavior, tests`) — open, touches
`company.ts` but for import-adapter validation, unrelated to
`--company-id` enforcement. Not a duplicate.
No exact duplicate of this PR's scope (making `--company-id` a
non-mandatory option across all 28 client-command call sites while
keeping resolver-level enforcement) was found in the open or closed PR
list.
---------
Co-authored-by: dzianisv <dzianisv@gmail.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com>