Skip to content

feat(cli): claude wrapper attach auto-wires @commonlyai/mcp by default (closes #440) - #448

Closed
samxu01 wants to merge 1 commit into
mainfrom
worktree-2026-05-24-claude-wrapper-default-mcp
Closed

samxu01 wants to merge 1 commit into
mainfrom
worktree-2026-05-24-claude-wrapper-default-mcp

Conversation

@samxu01

@samxu01 samxu01 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

commonly agent attach claude without --env now installs a sensible default environment that wires up @commonlyai/mcp via stdio. Agents get commonly_* kernel tools out of the box — parity with cloud-codex, which boots with the same MCP server pre-wired in ~/.codex/config.toml.

Why

Before this, a fresh commonly agent attach claude --pod X produced an agent that couldn't call any commonly_* tool (no commonly_post_message, no commonly_read_context, etc.) — the agent would receive chat.mention events and respond purely through text output piped back via the runtime token's /messages POST. That's fine for pure chat agents but blocks any agent that needs to attach a file, react, open a DM, or write memory mid-turn. Cloud-codex doesn't have this gap because its deployment template seeds ~/.codex/config.toml with the MCP server. The local CLI wrapper was the odd one out.

Changes

  • buildDefaultEnvironment(adapterName) in cli/src/commands/agent.js — returns a minimal env spec with one MCP entry (name: commonly, command: ['npx', '-y', '@commonlyai/mcp@latest'], env placeholders for the per-attach token + instance URL).
  • Wired into performAttach — applied only when --env is omitted, so explicit user configs are respected as-is.
  • ADAPTERS_WITH_DEFAULT_MCP = new Set(['claude']) — codex wrapper doesn't read --mcp-config (it uses ~/.codex/config.toml, which the local wrapper doesn't write yet); stub doesn't run a real CLI. Both return null from buildDefaultEnvironment.
  • Tests: 2 new performAttach cases (claude gets default, stub doesn't) + 2 buildDefaultEnvironment unit tests.
  • Drive-by fix: stale pre-existing attach.test case asserting the legacy runtimeType='local-cli' + wrappedCli='stub' pair — runtimeType is per-adapter post-refactor.

Test plan

  • Local: cd cli && NODE_OPTIONS=--experimental-vm-modules npx jest __tests__/attach.test.mjs — 10/10 pass.
  • Local: claude environment + adapter tests still green (20 passed, 1 skipped).
  • CI: backend type-check + unit suite passes. CLI tests are not run by CI today (separate gap; filing follow-up).
  • Manual: after deploy + token rotation, fresh commonly agent attach claude --pod X should produce an agent that can call commonly_post_message on its first turn without --env.

Follow-ups

  • Codex CLI wrapper MCP wiring — same end goal, different mechanism (~/.codex/config.toml).
  • CI gap — cli/__tests__/*.test.mjs are not part of Test & Coverage. Worth surfacing.

Closes #440.

🤖 Generated with Claude Code

`commonly agent attach claude` without --env now installs a sensible
default environment that wires up `@commonlyai/mcp` via stdio. Agents get
commonly_* kernel tools out of the box — parity with cloud-codex, which
boots with the same MCP server pre-wired in ~/.codex/config.toml.

Operators can still opt out by passing an explicit --env that omits the
MCP block.

- Adds buildDefaultEnvironment(adapterName) returning a minimal MCP-only
  env for adapters in ADAPTERS_WITH_DEFAULT_MCP. Only `claude` qualifies
  today — codex wrapper doesn't read --mcp-config (it uses
  ~/.codex/config.toml, which the local wrapper doesn't write yet; that
  gap is a follow-up).
- ${COMMONLY_API_URL} / ${COMMONLY_AGENT_TOKEN} placeholders are
  substituted at spawn-time by adapters/claude.js, so the env stays
  secret-free and survives across re-attach.
- Two new attach.test.mjs cases (claude gets default, stub doesn't) +
  two unit tests for buildDefaultEnvironment.
- Fixes a stale pre-existing attach.test that asserted the legacy
  runtimeType='local-cli' + wrappedCli='stub' pair — runtimeType is
  per-adapter ('stub' for stub, 'claude-code' for claude) post-refactor.

Closes #440.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
samxu01 added a commit that referenced this pull request May 24, 2026
#448, closes #440)

`commonly agent attach claude` without --env now installs a sensible default
environment that wires up `@commonlyai/mcp` via stdio. Agents get commonly_*
kernel tools out of the box — parity with cloud-codex, which boots with the
same MCP server pre-wired in ~/.codex/config.toml. Operators can still opt
out by passing an explicit --env that omits the MCP block.

- buildDefaultEnvironment(adapterName) returns a minimal MCP-only env for
  adapters in ADAPTERS_WITH_DEFAULT_MCP. Only `claude` qualifies today;
  codex wrapper doesn't read --mcp-config (separate gap: #449).
- ${COMMONLY_API_URL} / ${COMMONLY_AGENT_TOKEN} placeholders substituted
  at spawn-time by adapters/claude.js, so the env stays secret-free.
- 4 new test cases. Drive-by fix: stale pre-existing attach.test asserting
  legacy runtimeType='local-cli' + wrappedCli='stub' pair.

Follow-ups filed: #449 (codex wrapper MCP), #450 (CI gap: cli/ tests not
run by Test & Coverage).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@samxu01

samxu01 commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

Squash-merged to main per feedback-pr-merge-pattern.

@samxu01 samxu01 closed this May 24, 2026
samxu01 added a commit that referenced this pull request May 24, 2026
CLI test suite at cli/__tests__/*.test.mjs had never been part of CI. Gap
surfaced live during PR #448 verification — a stale test asserting the
legacy runtimeType='local-cli'+wrappedCli='stub' pair had been failing on
main for weeks, undetected.

- .github/workflows/tests.yml: add `cli` to the install step (npm ci
  --include=dev) + add a "Run CLI tests" step after the commonly-mcp tests.
- cli/__tests__/adapters.timeout-env.test.mjs: replace the inline `on: ()
  => {}` child-process stubs with a shared makeKillableChild() that
  captures listeners and emits close(143) on kill(). Without this the
  spawn promise hangs on the never-emitted 'close' event (3 tests hit
  jest's 5s default and reported as failures, only because the new CI
  step was the first time they ran in CI).
- cli/__tests__/attach.test.mjs: drop the claude-adapter integration test
  that depended on `claude --version` succeeding on PATH (CI runners
  don't have claude installed). The buildDefaultEnvironment unit tests +
  stub-adapter test already prove the shape.

After: Test & Coverage green, kind cluster smoke test green, all 8 gating
checks pass. 13/13 CLI suites pass locally, 135 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

claude CLI wrapper doesn't auto-load @commonlyai/mcp tools (Phase-4 #6)

1 participant