Skip to content

fix(cli): send, tools and inbox act as the home's agent only; printed next commands carry --home - #12

Merged
sanctrl merged 2 commits into
mainfrom
fix/key-out-of-reach
Nov 18, 2026
Merged

sanctrl merged 2 commits into
mainfrom
fix/key-out-of-reach

Conversation

@sanctrl

@sanctrl sanctrl commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What changes

Testing found two things:

  • With another agent's key exported, agentchat send went out as that agent with only ok: true on screen, and tools call answered as it. The listener refuses the same state.
  • With --home <dir>, every command the CLI printed next left --home out. Run as printed, they acted on ~/.agentchat, and the printed logout could delete the default home's only key.

What this PR does:

  • The hands follow the listener's rule. send, tools call, tools list and inbox refuse in one line when AGENTCHAT_API_KEY is exported and is not the home's key, or is exported while the home holds none. They refuse before anything reaches the server, and the key they send is always the one in credentials.
    • The same key exported works as before.
    • The refusal names the way out with no key on a command line: printenv AGENTCHAT_API_KEY | agentchat --home <dir> login --api-key -.
    • doctor's listener-identity check names every command it stops.
  • Every printed next command carries the home. A new invocationFor(home) adds --home <dir> unless the home is ~/.agentchat and a bare command reaches it, that is, no AGENTCHAT_HOME points elsewhere. The path is quoted for the platform's shell when it has to be.
    • It is used for the engine's printed steps (register --code, status, logout, login) and for the listener's, watch's and doctor's hints.
  • Docs and --help: login is shown with a prompt or stdin only, never --api-key <key> or AGENTCHAT_API_KEY. README and SECURITY.md say what an exported key does to every command.

The answer / work / full profiles are not touched. Preset runs keep the identity store unreadable to answer runs exactly as before. --with-key is unchanged: the owner's explicit opt-in.

Merge order: after the agent-core PR (agentchatme/agentchat-agent-core#21). This PR does not depend on it: it builds and passes against the bundled agent-core 0.5.2. The engine's refusals for status, doctor and login come with that release when the pin moves at the release step. No version number is set here.

Verification

  • Tests: pnpm type-check, pnpm build, pnpm test and scripts/release-smoke.sh on Node 22 (macOS): 8 files, 86 passed, 1 skipped (87); smoke ok.

    • New tests in tests/cli.test.ts (6) cover:
      • the four hands refuse a foreign exported key, and the MCP double sees no request;
      • the same key exported works, with the home's key on the wire;
      • a home with no key and one exported is refused;
      • invocationFor and its quoting;
      • status and the register gate print --home <dir>;
      • the refusals name the home.
    • 5 of the 6 fail on origin/main. The one that passes on main, the same key exported, guards behaviour that already worked.
    • A 7th checks the engine's login and status refusals. It is skipped until the agent-core pin moves, and passes with the new engine linked in.
  • Review: independent review by a separate agent with fresh context. It was given the code and the requirements, and it ran the suites. Its blocker was the new tests expecting an unquoted --home, which would fail on Windows CI; expectations are now built with shellArg. Should-fix items, fixed:

    • --home was dropped when AGENTCHAT_HOME pointed elsewhere. Now it is left out only when the home is ~/.agentchat and a bare command reaches it.
    • The service log's hint now names the home.
    • Probes in status and doctor use the home's key only.
    • The doctor check keeps its name listener-identity, so the engine's env-key check does not duplicate it after the pin moves.

    Its point 'decide: env-only for the hands' is decided as refuse, matching the listener and SECURITY.md's one-identity promise (see Risk).

  • Live check: n/a before release. After release, the check is send with a foreign key exported, and following the printed commands after --home.

Risk and rollback

  • Behaviour change: a script that ran AGENTCHAT_API_KEY=… agentchat send … against a home with no key is now refused. It runs agentchat login once first (it takes the exported key into an empty home), then send. The README never documented the env-only form for these commands.
  • After the pin moves, status (the engine's) still shows an env-only identity while send refuses it. status is informational, and its refusal of a split, where both keys exist and differ, comes with the engine.
  • Rollback: revert.

… next commands carry --home

- send, tools call, tools list and inbox follow the listener's rule: an
  exported AGENTCHAT_API_KEY that is not the home's key (or one exported
  while the home holds none) stops them in one line before anything reaches
  the server; the key they send is always the one in `credentials`.
- invocationFor(home) adds `--home <dir>` (quoted for the platform's shell
  when needed) unless the home is ~/.agentchat and a bare command reaches it;
  every printed next step uses it, so a printed `logout` can no longer act
  on another home.
- The refusal's way out puts no key on a command line
  (`printenv AGENTCHAT_API_KEY | agentchat --home <dir> login --api-key -`);
  status and doctor probes use the home's key only.
- --help, README and SECURITY.md: login by prompt or stdin only; what an
  exported key does to every command.
@sanctrl
sanctrl merged commit 330ac8f into main Nov 18, 2026
8 of 9 checks passed
@sanctrl
sanctrl deleted the fix/key-out-of-reach branch November 18, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant