Skip to content

feat(doctor): fail until each tool trusts the project or approves its team MCP servers - #1660

Merged
SaulMoro merged 17 commits into
Tencent:mainfrom
hz89Dev:feat/1221-doctor-read-gates
Nov 2, 2026
Merged

SaulMoro merged 17 commits into
Tencent:mainfrom
hz89Dev:feat/1221-doctor-read-gates

Conversation

@hz89Dev

@hz89Dev hz89Dev commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

pull writes team skills, MCP servers and hooks into a project, but several tools load them only after the member trusts the project or approves its servers. Until then the files sit there unused, while teamai doctor said everything was fine. Doctor now reads each tool's own answer and fails, naming the prompt or the line that gives it, until the tool will actually load what teamai delivered. Pull still writes either way.

TOOLS (src/tools.ts)     readGates: ['pi-project-trust', ...]    declared per resource
locate()                 readGates: ReadGate[]                   files placed (env moves, worktrees)
read-gates.ts            readGateVerdict(gate, held)             reads the tool's own store; never writes
doctor-delivery.ts       skills / agents / MCP / hooks checks    one check per gate
Tool (version run) What waits Where its answer is
Pi 1.4.0 (gate from 0.79.0) .pi/skills, .pi/mcp.json ~/.pi/agent/trust.json, defaultProjectTrust
Muse Code 1.4.14 .agents/skills, .mcp.json, .muse/hooks.json ~/.config/muse/trust.json
Copilot CLI 1.0.105 .github/mcp.json, .github/hooks trustedFolders in ~/.copilot/config.json
Qoder CLI 1.1.81 .qoder/settings.json permissions.trustDirectories, mcp.*ProjectMcpServers
Claude Code 2.1.316 .mcp.json servers enabled/disabledMcpjsonServers, trust in ~/.claude.json
Claude Code 2.1.316 teamai's hooks disableAllHooks in .claude/settings.local.json, then .claude/settings.json, then ~/.claude/settings.json
CodeBuddy Code 2.179.1 .mcp.json servers .codebuddy/settings.local.json
Cursor CLI 2026.10.21 .cursor/mcp.json servers ~/.cursor/projects/<project>/mcp-approvals.json, mcp-disabled.json
Codex (existing) project agents, .codex/config.toml [projects] in ~/.codex/config.toml

Also from #1221:

  • Pi reads AGENTS.override.md only from 0.84.0 (absent from the @earendil-works/pi-coding-agent 0.83.0 loader, present in 0.84.0; no @mariozechner release has it). When the override holds the team instructions, doctor now fails on an older Pi.
  • OpenCode V2 does apply instructions (packages/core/src/config/plugin/instruction.ts, v2.0.30 to v2.2.5). teamai leaves its entries out on V2 because its plugin adds the same files, and V2 would load them twice. The pull message, two doctor fixes and the comments said V2 ignores them. The behaviour stays; the wording changed.
  • Hermes does read <root>/.hermes/skills for a root in skills.trusted_project_dirs; comment fixed.

Docs: docs/guide/diagnostics.md (+ zh-CN) gains "A tool has not trusted the project yet", with real doctor output and the prompt that clears each one. skill-data troubleshooting gains the matching entry.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes (includes node scripts/check-docs.mjs)
  • npx vitest run passes: 648 files, 20093 tests at b91797a; after f525a4b, the doctor, locate and hook suites (49 files, 5672 tests)
  • Added/updated tests for the change: doctor-read-gates.test.ts (62, through buildChecks), doctor-pi-override-version.test.ts (4), and the locate matrix rows for every gate (locate-mcp, locate-hooks, locate-matrix)

Real CLI, built at b91797a on 2026-11-02 (the Claude hooks run at f525a4b). Each run used an isolated HOME, a local bare team remote and a fresh git checkout, then real teamai init + pull + doctor. Long fix lines are cut.

Claude, Pi, Muse, Copilot and Qoder, before and after granting each answer in the tool's own file. The real tools confirm both states:

$ teamai doctor   # no tool has trusted web-app yet
  ✖ Pi trusts this project, so it loads its team skills
  ✖ Muse Code trusts this project, so it loads its team skills
  ✖ Claude Code approves this project's team MCP servers
  ✖ Copilot CLI trusts this folder, so it loads its team MCP servers
  ✖ Qoder CLI trusts this folder, so it loads its team MCP servers
  ✖ Qoder CLI approves this project's team MCP servers
  ✖ Pi trusts this project, so it loads its team MCP servers
  ✖ Muse Code trusts this project, so it loads its team MCP servers
  [pi 1.4.0] pi mcp list:
    /work/web-app/.pi/mcp.json is ignored because the project is not trusted. Start pi in the project to trust it.
  [muse Muse Code 1.4.14] muse skills list --source project:
    - project-skills-untrusted: project skills skipped because workspace is untrusted (.agents/skills)
# grant each verdict by hand
$ teamai doctor
  ✔ (all eight)
  [pi 1.4.0] pi mcp list:   issues: failed (codemode, project)   # loaded now; the stub package does not exist
  [muse] muse skills list:  release-notes  project  on
doctor exit: 0

CodeBuddy (its own project, since Claude shares .mcp.json): ✖ CodeBuddy Code approves this project's team MCP servers, then ✔ after enabledMcpjsonServers in .codebuddy/settings.local.json, then doctor exit: 0.

Cursor CLI, with the real cursor-agent 2026.10.21 giving every answer:

$ teamai doctor   # cursor-agent has never run on this machine (IDE member)
  ✔ Cursor CLI approves this project's team MCP servers
$ cursor-agent mcp list
  issues: not loaded (needs approval)
$ teamai doctor
  ✖ Cursor CLI approves this project's team MCP servers
    → ... issues waits for approval. Run `cursor-agent mcp enable issues` in /work/web-app, ...
$ cursor-agent mcp enable issues
  ✓ Enabled and approved MCP server: issues
$ teamai doctor
  ✔ Cursor CLI approves this project's team MCP servers
# the team bumps the server: @acme/issues-mcp@2
$ teamai pull && teamai doctor
  ✖ Cursor CLI approves this project's team MCP servers
$ cursor-agent mcp list
  issues: not loaded (needs approval)

Claude Code hooks. teamai keeps a team-repo project's hooks in ~/.claude/settings.json (#264), and the project's own settings can still turn them off. claude -p 2.1.316 with a SessionStart hook behaves the same way: it skips the hook with true in settings.local.json, runs it with false, and the local file's false wins over the project's true.

$ teamai doctor
  ✔ Claude Code has not turned hooks off with disableAllHooks
$ echo '{"disableAllHooks": true}' > .claude/settings.local.json && teamai doctor
  ✖ Claude Code has not turned hooks off with disableAllHooks
    → /work/home/.claude/settings.json holds teamai's hooks, but Claude Code runs no hooks while the settings that decide set disableAllHooks, and /work/web-app/.claude/settings.local.json sets it. Remove "disableAllHooks" from ..., or set it to false.
  doctor exit: 1
$ echo '{"disableAllHooks": false}' > .claude/settings.local.json && teamai doctor
  ✔ Claude Code has not turned hooks off with disableAllHooks
  doctor exit: 0

Pi AGENTS.override.md, user scope, with the real @mariozechner/pi-coding-agent 0.73.1 and @earendil-works/pi-coding-agent 1.4.0:

$ pi --version && teamai doctor
  0.73.1
  ✖ Pi reads the AGENTS.override.md holding the team instructions
    → Pi 0.73.1 reads ~/.pi/agent/AGENTS.md, not ~/.pi/agent/AGENTS.override.md, ... Upgrade Pi (`npm uninstall -g @mariozechner/pi-coding-agent && npm install -g @earendil-works/pi-coding-agent`), ...
  doctor exit: 1
$ pi --version && teamai doctor
  1.4.0
  ✔ Pi reads the AGENTS.override.md holding the team instructions
  doctor exit: 0

The uninstall step is needed. Installing @earendil-works/pi-coding-agent over 0.73.1 stops with npm error File exists: .../bin/pi.

Related Issues

Part of #1221: "doctor does not check workspace trust (Claude, Muse), project trust (Codex agents, Pi), folder trust (Copilot) or MCP approval", "doctor reports the conditions and gates from locate", the stale comments, and the Pi AGENTS.override.md minimum version (0.84.0, not 1.4.0 as the issue says).

Notes for Reviewers

  • How each gate decides. Each one follows the tool's own lookup, read from its source or bundle and checked against the real CLI:
    • Pi takes the nearest trust.json entry walking up from the checkout.
    • Muse keys its decision on the real path of the git root.
    • Copilot's trusted folders cover subfolders, and a worktree counts when its main checkout is trusted.
    • Claude counts approvals only once ~/.claude.json trusts the main checkout.
    • Cursor's key is sha256({ path, server }) over the entry after ${env:...} resolution, so an approval of an earlier definition does not count.
  • Choices.
    • A Cursor member who never ran the CLI (no cli-config.json) is taken to be on the IDE, whose approvals doctor cannot read, and passes.
    • Pi before 0.79.0 has no project trust, so its gate counts as met.
    • Gates apply only to installed tools, in project scope, and MCP approval gates only where a project file is read (not the local scope).
  • Not gated.
    • Claude Code and Cursor workspace trust: their dialog stops the session until answered.
    • CodeBuddy trust: it does not hold back MCP.
    • Qoder CN: its trust store was not run.
    • Cursor IDE approvals.
    • Claude Code managed policy (disableAllHooks or allowManagedHooksOnly set by an admin).
  • Not changed. The comment inside the generated OpenCode plugin (opencode-hooks.ts:278) still says V2 ignores instructions. Doctor compares that plugin byte for byte, so editing it would mark every installed plugin out of date.
  • Not run here.
    • Windows path forms.
    • The gitlab and github providers, left to CI.
    • Copilot was run on 1.0.105 from npm. An older 0.0.x keeps trust differently and was not run.
  • Merge danger. Two-way door: doctor and docs only, nothing that pull writes changes. Blast radius: members whose tools have not trusted the project now see failing doctor checks. That is the point, and each one names the fix.

Codex project trust was evaluated inline by the agents check and by a
Codex-only MCP check. Both now ask read-gates.ts for the verdict of each
gate locate declares, so a new trust or approval gate is one case there.

Proof: the Codex trust tests in doctor-mcp-delivery and
doctor-agent-places pass unchanged; typecheck and lint pass.
Pi 1.4.0 loads a project's .pi/skills and .pi/mcp.json only in a trusted
project, and pi -p treats an undecided one as untrusted. doctor now reads
Pi's trust.json (nearest entry walking up, then defaultProjectTrust) and
names the line that trusts the project.

Proof: doctor-read-gates tests (verdicts recorded from Pi 1.4.0 runs in
an isolated HOME); mutating each branch fails its case; locate matrix
rows declare the gate.
…f hooks

Muse Code 1.4.14 loads a project's .agents/skills, .mcp.json and
.muse/hooks.json only in a trusted workspace, keyed by the real path of
the checkout's own git root, and muse exec runs an undecided one
untrusted. doctor now reads Muse's trust.json and names the entry to add.
Hook files gain read gates in the descriptor, as agents and MCP have.

Proof: doctor-read-gates tests (verdicts recorded from Muse 1.4.14 runs
in an isolated HOME: untrusted, trusted, parent key, linked worktree,
XDG_CONFIG_HOME); locate matrix rows declare the gate.
Copilot CLI 1.0.105 loads workspace MCP servers and repo hooks only in a
trusted folder, and copilot -p skips them. doctor now reads
trustedFolders (or the older trusted_folders) from Copilot's
config.json, which opens with // comment lines: an entry covers the
folders under it, and a linked worktree takes its main checkout's.

Proof: doctor-read-gates tests (verdicts recorded from Copilot CLI
1.0.105 runs in an isolated HOME: parent folder, sibling prefix, worktree,
COPILOT_HOME, legacy key, workspace and self-mode hooks); locate matrix
rows declare the gate.
An interactive Qoder CLI 1.1.81 session ignores a project's
.qoder/settings.json (MCP servers, self-mode hooks) until the user
settings' permissions.trustDirectories covers the folder, and starts a
project server only once it is approved by name in
mcp.enabledProjectMcpServers. A name in mcp.disabledProjectMcpServers
stays off in qodercli -p too. doctor now reads both verdicts.

Proof: doctor-read-gates tests (verdicts recorded from Qoder CLI 1.1.81
runs in an isolated HOME: ancestor, folderTrust off, project settings
cannot self-trust, QODER_CONFIG_DIR, rejection in project settings);
locate matrix rows declare the gates. Qoder CN shares the project file
but its trust store was not run, so it has no gate.
An interactive Claude Code 2.1.316 session starts a .mcp.json server
only once it is approved, and never one in disabledMcpjsonServers.
Approvals live in settings files: ~/.claude/settings.json counts always,
the project's settings.json and the main checkout's settings.local.json
only once ~/.claude.json trusts the main checkout. doctor now merges them
as Claude Code does and names the dialog or the key that approves. A
local scope in ~/.claude.json waits on no approval and gets no check.

Proof: doctor-read-gates tests (rules recorded from Claude Code 2.1.316
runs in an isolated HOME: untrusted, trusted, user settings, rejection,
linked worktree, local scope); locate matrix rows declare the gate.
…ervers

CodeBuddy Code 2.179.1 reads the approval of a project's .mcp.json
servers from <cwd>/.codebuddy/settings.local.json only
(CODEBUDDY_PROJECT_CONFIG_DIR moves it), and holds a pending server back
in codebuddy -p too. doctor now reads that file. A local scope in
.codebuddy.json waits on no approval and gets no check.

Proof: doctor-read-gates tests (rules recorded from CodeBuddy Code
2.179.1 runs in an isolated HOME: by name, enable all, rejection, user
settings ignored, CODEBUDDY_PROJECT_CONFIG_DIR, local scope); locate
matrix row declares the gate.
… servers

Cursor CLI 2026.10.21 keeps a project's approvals in
~/.cursor/projects/<slug of the real git root>/: mcp-disabled.json names
servers it never loads or asks about again, mcp-approvals.json holds
<name>-<hash>, the hash taken over the server with the env of the shell
Cursor runs in. doctor cannot redo that hash, so it reports a declined
server, and a server with no approval once the CLI approved others here,
naming cursor-agent mcp enable. With no CLI state (a Cursor IDE member),
the check passes.

Proof: mcp disable/enable recorded with Cursor CLI 2026.10.21 in an
isolated HOME on 2026-11-02 (mcp-disabled.json is an array of names);
doctor-read-gates tests; locate matrix row declares the gate.
The diagnostics guide (English and Chinese) gets the doctor output of a
new checkout, the prompts that clear it, a rejected server, a headless
machine, and where each tool keeps its answer. The troubleshooting
reference tells the agent to have the member accept the prompt rather
than edit a trust file unasked.

The example output is from a real teamai pull and doctor run in an
isolated HOME, paths renamed.
OpenCode V2 applies configured `instructions` entries
(packages/core/src/config/plugin/instruction.ts at v2.0.30, v2.1.2 and
v2.2.5: "configured `instructions` entries are explicit requests"). teamai
leaves them out on V2 because its plugin adds the same files, and V2 would
load them twice. Pull and doctor told members the opposite. The behaviour
stays; the pull message, two doctor fixes and the comments now give the
real reason.

The Hermes comment in source.ts also said Hermes never reads
<root>/.hermes/skills; it does for a root listed in
skills.trusted_project_dirs (agent/skill_utils.py).
Pi reads AGENTS.override.md before AGENTS.md only from 0.84.0: the
resource loader of @earendil-works/pi-coding-agent 0.83.0 has no
override candidate and 0.84.0 has it, and no @mariozechner release does.
With an override present, user-scope pull writes the team instructions
there, so an older Pi saw none of them while doctor passed.

Doctor now runs `pi --version` when Pi's target is the override and fails
below 0.84.0, naming the upgrade or the move back to AGENTS.md. Without
a pi on PATH or a parseable version the check is not added.
Pi added project trust in 0.79.0 (its changelog: "Pi now asks before
loading project-local settings, resources, instructions, and packages";
0.78.1 ships no trust.json handling). On an older Pi doctor failed the
trust check and named a prompt that does not exist. getAgentVersion now
detects `pi`, and the gate counts as met below 0.79.0.

Also from review: unreadable() and approvalVerdict() take named
arguments, since their string parameters were easy to swap, and the
three settings-list approvals share listedApproval().
Every Pi before 0.74.0 is @mariozechner/pi-coding-agent, whose `pi`
command makes `npm install -g @earendil-works/pi-coding-agent` stop with
EEXIST (reproduced in an isolated npm prefix over 0.73.1). The fix text
now uninstalls it first. The check reads Pi's version through
getAgentVersion and semver, and its name spells Pi like the trust
checks.

Docs: the Pi row of the trust table says 0.79.0, and the headless
trust.json example says it is for a runner with no trust.json yet, as
it replaces the file.
A project MCP file can be read by several tools: Claude writes .mcp.json
and Muse Code reads it too. The MCP read-gate checks went through every
tool in toolPaths, so with Muse absent doctor still failed "Muse Code
trusts this project". They now skip a tool whose `installed` gate is
unmet, as the other doctor checks do; hook gates already did, through
writable().
The Cursor CLI 2026.10.21 approves `<name>-<16 hex>`, the first 16 hex
of sha256(JSON.stringify({ path: <project root>, server: <its
.cursor/mcp.json entry> })), and an approval of an earlier definition no
longer loads the server. doctor took any approval of the name, so a pull
that changed a server's command kept passing while the CLI held it back.
It now computes the key; an entry reading ${...} is hashed resolved with
the shell's env, so for those any approval of the name still counts.

With no mcp-approvals.json the CLI approves nothing. doctor now holds the
servers back once the CLI has run on this machine (its cli-config.json),
and keeps passing for a member on the Cursor IDE alone. The gate places
both files the way the CLI does: CURSOR_DATA_DIR for projects/,
CURSOR_CONFIG_DIR else XDG_CONFIG_HOME/cursor for cli-config.json.

Checked with the real cursor-agent 2026.10.21 in an isolated HOME: doctor
passes before the CLI runs, fails after `cursor-agent mcp list` shows
"needs approval", passes after `mcp enable`, and fails again after the
team bumps the server and pull rewrites it, when `mcp list` again shows
"needs approval".
The Cursor CLI hashes a server after resolving its ${env:NAME}, ${NAME}
and ${NAME:-default} with its shell's env, leaving an unset name as
written. doctor took any approval of the name for such an entry, so an
approval of an earlier definition still passed. It now resolves them the
same way (the CLI's own pattern) with doctor's env and compares the full
key; a mismatch counts as waiting, and the fix says which env doctor used.

Checked against cursor-agent 2026.10.21: an entry mixing ${env:...},
${NAME:-default} and unset names, approved with ISSUES_TOKEN=abc, gets
issues-aee3481da24f25bf from both the CLI and this resolver.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

No confident, actionable findings in the specified PR diff.

The PR description satisfies the testing requirement: it records built, real-CLI verification at b91797a2 on November 2, 2026, including failing and passing trust/approval states. The deferred provider coverage is not blocking.

Review was read-only; I did not run, build, or install anything from the PR.

Claude Code keeps no per-hook approval, but `disableAllHooks` in the
settings file that decides stops every hook, teamai's included: the
checkout's .claude/settings.local.json, then its .claude/settings.json,
then the user settings.json. Checked with `claude -p` 2.1.316 and a
SessionStart hook: true in settings.local.json skips it, false runs it,
and local false over project true runs it.

Claude's hook channels declare a claude-hooks-enabled gate. A team-repo
project keeps its team hooks in the user settings (Tencent#264), whose gates
locate placed through the user view and so dropped; it now places a
project's gates on them, which only Claude declares. Managed policy,
which can also turn hooks off, is not read.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

No confident, actionable findings in the specified PR diff.

The PR description satisfies the testing requirement: it records built, real-CLI verification on November 2, 2026, including failing and passing trust/approval states, plus the Claude hooks run at f525a4b7. Deferred provider and Windows coverage is not blocking.

The earlier pass raised no findings, so none require resolution.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Approving at f525a4b.

Built-CLI run at b91797a on an isolated HOME: one team skill and one MCP server, then init and pull with Claude and Pi in project scope.

teamai doctor Base build This PR
No trust or approval yet exit 0, no gate lines exit 1: ✖ Pi skills, ✖ Pi MCP, ✖ Claude MCP approval
After writing the entries by hand into ~/.pi/agent/trust.json, ~/.claude.json and .claude/settings.local.json exit 0 exit 0, all three ✔
  • Fails closed: a malformed trust.json or ~/.claude.json fails the check instead of passing it. The trust and approval files are byte-identical after doctor.

  • Worktrees and paths: a linked worktree fails the Pi gate until it has its own entry. A Claude approval in the main checkout's settings.local.json counts for its worktrees. A symlinked project path passes when the entries use the real path.

  • Agrees with Pi: real Pi 1.4.0 pi mcp list ignores the untrusted project and loads the trusted one, matching doctor.

  • Pi override version: the 0.84.0 minimum for AGENTS.override.md matches the npm tarballs: 0.83.0 has no override support and 0.84.0 does.

  • Last commit: disableAllHooks (f525a4b) I read rather than ran. It follows the local → project → user order and treats an unparseable file as unreadable, not as a pass.

  • [P3 nit] src/read-gates.ts:127-128 treats Pi 0.79.0 with defaultProjectTrust: "always" as trusted. That setting first shipped in 0.79.1 (Pi CHANGELOG and the 0.79.0 tarball), so the floor for that branch should be 0.79.1.

CI review: no findings at b91797a or f525a4b, and I agree.

Not checked:

  • Muse, Copilot, Qoder, CodeBuddy and Cursor with the real tools; the description's record covers each.
  • Whether Claude's trust walk-up reaches folders above the repo root.
  • Windows and the gitlab/github providers, left to CI.

The plugins.enabled gate from #1221's doctor section is not covered here and stays open there.

@SaulMoro
SaulMoro merged commit 3881fdc into Tencent:main Nov 2, 2026
17 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…#1660)

`teamai doctor` now fails until each tool trusts the project or approves its team MCP servers, so delivered skills, MCP servers and hooks are actually loaded. It reads each tool's own answer and never writes it: Pi, Muse Code, Copilot CLI, Qoder CLI, Claude Code (MCP approval and `disableAllHooks`), CodeBuddy Code, Cursor CLI and Codex. It also fails on a Pi older than 0.84.0 when the team instructions sit in `AGENTS.override.md`, and corrects the OpenCode V2 `instructions` and Hermes wording.

Related to Tencent#1221
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.

3 participants