Skip to content

feat(doctor): catch OpenClaw plugins switched off, and warn while a tool has not asked yet - #1663

Merged
SaulMoro merged 14 commits into
Tencent:mainfrom
hz89Dev:feat/1221-close
Nov 2, 2026
Merged

SaulMoro merged 14 commits into
Tencent:mainfrom
hz89Dev:feat/1221-close

Conversation

@hz89Dev

@hz89Dev hz89Dev commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#1660 left #1221 open on its remaining items. The biggest one: doctor still could not tell you that OpenClaw would never run the team hooks once plugins.enabled was false. This PR covers that and the other open items. It also changes one #1660 rule: when a team uses three tools and a member opens only one of them today, doctor should not fail for the two tools that have not asked about the project yet.

What doctor reports for a read gate now:

gate verdict                                      doctor   exit   pull
met                                               ✔        0      ✔
unanswered (tool has not asked about it yet)      ⚠        0      ⚠ dimmed
blocked (refused, switched off, unreadable)       ✖        1      ✖

Each open item and what moved:

#1221
├── doctor reports the gates from locate
│   └── OpenClaw: two read gates on the hook adapter, resolved in locate
│       ├── "OpenClaw hook enabled"              hooks.internal.entries.<hook>.enabled
│       └── "OpenClaw loads teamai's team hooks plugin"
│                                                plugins.enabled, allow/deny, entries, load.paths
├── adding a tool starts with its descriptor
│   └── TOOL_IDS → TOOLS satisfies Record<ToolId, …>; autocompact, skill
│       allowed-tools, search evidence, stop-reply and shell come from TOOLS,
│       and the type check flags each table a new tool is missing from
├── Hermes 8,000-character plugin budget
│   └── doctor reads ~/.hermes/logs/agent.log and warns when the last logged
│       session skipped teamai.instructions (budget, section count, max_chars, raised)
├── self scope leaves the tree dirty
│   └── with sharing.gitExclude, CodeBuddy, Qoder and Qoder CN team hooks go to
│       settings.local.json (as Claude's did since #1000), and git ignores it
├── OpenClaw AI call leaves a session
│   └── checked on 2026.8.1 and 2026.10.9: `openclaw agent exec --json` leaves
│       none; recorded as verified
└── WorkBuddy bundled runtime
    └── Node and PortableGit are found under <root>/binaries/<name>/versions/<version>-<variant>
        in ~/.workbuddy, ~/.workbuddy-ai and WORKBUDDY_CONFIG_DIR, newest first

Example: OpenClaw with plugins switched off.

  ✔ OpenClaw hook enabled
  ✖ OpenClaw loads teamai's team hooks plugin
    → ~/.openclaw/teamai/teamai-team-hooks.mjs holds the team's hooks, but OpenClaw runs a plugin only once
      openclaw.json loads and enables it, and in ~/.openclaw/openclaw.json plugins are switched off
      (plugins.enabled: false); turn them on. teamai leaves that setting to you.

doctor --json adds "warning": true to a check that warns. Existing fields are unchanged.

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 typecheck, which includes the lint plugin's project)
  • npm run lint passes, including node scripts/check-docs.mjs
  • npx vitest run passes (651 files, 20211 tests, 24 skipped, at 61712f3; the doctor suites, 18 files and 526 tests, again after the unreadable-store fix)
  • Added/updated tests for the change
    • locate-hooks: OpenClaw gates on every scope; CodeBuddy, Qoder and Qoder CN self rows read both files
    • doctor-delivery: each OpenClaw plugin config that blocks (switched off, not allowed, denied, entry disabled, not in load.paths), mixed-case ids, JSON5, and a plugin built without the workspace hook
    • hermes-hooks: unseen, rendered, crowded out (budget, count), too long, raised
    • bundled-runtime: both WorkBuddy roots, node.exe, newest version, .installing. dirs, WORKBUDDY_CONFIG_DIR
    • E2E self-mode-git-exclude-915: CodeBuddy and Qoder keep git status clean, keep the member's own keys, and hooks remove cleans up (12/12)
    • tool-facts lint rule reads TOOL_IDS from source

Real CLI (npm run build, node dist/index.js, temp HOME and repo per case):

1. Pi, team skill, no trust entry
   ⚠ Pi trusts this project, so it loads its team skills      doctor exit=0, "✔ All checks passed!"
2. OpenClaw, openclaw.json as teamai leaves it
   ✔ OpenClaw hook enabled / ✔ OpenClaw loads teamai's team hooks plugin
   then plugins.enabled: false → ✖ (message above)            doctor exit=1
3. Hermes
   no agent.log                                               no check, exit=0
   "…teamai.instructions … exceeded the aggregate session budget (8000 chars) and was skipped"
   ⚠ Hermes's last logged session took teamai's instructions section
     → The Hermes session at 2026-11-01 10:22:03 got none of the team instructions: …   exit=0
   a later "Session plugin prompt section: id=teamai.instructions" line → ✔
4. CodeBuddy, self mode with sharing.gitExclude
   git status: clean; team hook in .codebuddy/settings.local.json: 1; in settings.json: 0
   .git/info/exclude: /.codebuddy/settings.local.json
5. Pi, trust.json {"<project>": false} at mode 000
   ✖ Pi trusts this project … trust.json cannot be read (EACCES: permission denied, …), so whether Pi trusts this project is unknown   exit=1
   same file readable                                         ✖ … sets "<project>": false   exit=1
   no trust.json                                              ⚠                             exit=0
6. WorkBuddy, ~/.workbuddy/binaries/node/versions/22.22.2-6/bin/node present
   ~/.teamai/bin/teamai: exec ".../.workbuddy/binaries/node/versions/22.22.2-6/bin/node" ".../dist/index.js" "$@"

CodeBuddy reads .codebuddy/settings.local.json hooks (the verified read in TOOLS). Checked with CodeBuddy Code 2.179.1 from the npm tarball on 2026-11-02, using an isolated HOME. A git repo had SessionStart and UserPromptSubmit hooks that each touch a marker, in both .codebuddy/settings.json and .codebuddy/settings.local.json. Running codebuddy -p hi from the repo root fired all four markers before the auth error. Running it from a subdirectory fired none, so the read is from the current directory only (cwdOnly). Qoder's settings.local.json read is from source (qodercli 1.1.81 loads project, then local hooks), since a run needs a login. The Qoder CN read is assumed.

The Hermes log lines follow the format in Hermes v0.22.5 plugins_dispatch.py. The OpenClaw gates follow OpenClaw's plugin loader. The no-session result comes from openclaw sessions --all-agents --json after openclaw agent exec, on 2026.8.1 and 2026.10.9 (mock model).

Not run here: Windows paths (node.exe is unit-tested only), the GitLab and GitHub providers, and agents other than Pi, OpenClaw, Hermes, CodeBuddy and WorkBuddy. CI covers these.

Related Issues

Part of #1221. With this PR merged, what stays open:

Notes for Reviewers

  • The ⚠ for an unanswered gate changes feat(doctor): fail until each tool trusts the project or approves its team MCP servers #1660's result for that one case, so Codex with no entry for the project now warns too. A gate that is refused, switched off or unreadable still fails.
  • The OpenClaw plugin gate counts only once teamai has written the plugin file, and the hook gate only once the workspace hook exists. A JSON5 openclaw.json is reported as unreadable under both gates rather than guessed at.
  • The Hermes check reads only the last line about teamai.instructions. Hermes logs a rendered section at INFO, so with logging.level above INFO an older skip can stay the last line.
  • Only an absent trust or approval store means "not asked yet". A store that is there but cannot be read or parsed fails, as before. One reader in read-gates.ts makes that distinction for every gate store.
  • Upgrading a single-repo CodeBuddy or Qoder project: the first pull on this release moves the team hook from .codebuddy/settings.json (or .qoder/settings.json) to settings.local.json, which leaves the tracked file modified once. Commit that change once, as Claude projects did after feat: keep the resources teamai delivers in project scope out of git (#915) #1000.
  • Qoder and Qoder CN share .qoder/settings.local.json. The Qoder CN read is marked assumed.

…sts the rest

ToolId came from the keys of DEFAULT_TOOL_PATHS, so a new tool started in
types.ts and nine partial tables outside TOOLS failed open for it. Now:

- TOOL_IDS in src/tools.ts defines ToolId; TOOLS and DEFAULT_TOOL_PATHS are
  checked against it in both directions.
- Per-tool facts move into the descriptor as required fields: hooks
  subagentStop, stopReply, shell and teamHooks; MCP judgedTeamaiOnly;
  autoCompact, skillAllowedTools, searchEvidence, projectFromHome and
  legacyAgentMd. CODEX_TOOL_IDS derives from launch. Version detectors and
  bundled shells become exhaustive records; adapter built-in hooks are keyed
  by hook adapter.
- teamai/tool-facts rejects a list of tool ids or a partial tool-keyed table
  outside src/tools.ts. Ordered registries, alias maps and frozen history
  carry an explained disable.

Values are copied from the deleted tables; behaviour is unchanged.
Verified: tsc, npm run lint, the rule's 40 fixtures (one per tool id read
from TOOLS), and the full vitest suite (2 load timeouts in
workflow-reconciliation that pass alone).
A member with Pi, Muse and Claude Code installed who only uses Claude today
got a failing doctor and a "check(s) failed" banner after every pull until
they opened each tool once. A trust or approval the tool has never asked
about is not broken: the tool asks the first time it opens there.

Each read gate now answers met, unanswered or blocked. Unanswered (no entry
in the tool's store, a server only waiting for approval) is a pass with a
warning: doctor prints it with the fix and exits 0, and pull shows it dimmed.
Blocked (an explicit no, a setting that turns the read off, a store teamai
cannot read) still fails. A check may now return 'warn'; doctor --json marks
it with "warning": true.

Verified: tsc, npm run lint, doctor-read-gates (67) and pull-post-checks (14).
… locate

OpenClaw loads teamai's workspace hook only while hooks.internal enables its
entry, and the team hooks plugin only while plugins.enabled is not false,
plugins.deny and plugins.allow leave it in, its entry is not disabled and
plugins.load.paths lists it. doctor checked the first by hand and the second
not at all.

The OpenClaw hook adapter now declares both as read gates in TOOLS, locate
resolves them against the openclaw.json OpenClaw reads (OPENCLAW_CONFIG_PATH,
profile and state dir included), and doctor reports them through the same
read-gate checks as trust and approval. A config teamai cannot parse (JSON5)
is reported as unreadable instead of disabled.

Tested: doctor-delivery OpenClaw cases (each blocking config, a loading one,
no plugin file, JSON5), the locate hooks matrix rows for every OpenClaw home
variant, tsc, npm run lint.
Hermes renders plugin prompt sections once per session in section id order,
within a shared budget of 8,000 characters and 32 sections, and drops a
section that does not fit whole. In a project the team instructions reach
Hermes only through teamai's section, so another plugin whose id sorts first
can take them away while every other check passes.

Which sections other plugins add is only known once they run, so doctor reads
the outcome Hermes logged last for teamai.instructions in logs/agent.log:
rendered passes, crowded out by the budget fails with the plugins.disabled
fix, and a skip of teamai's own making fails with `teamai hooks inject`.
Nothing logged yet adds no check.

Tested: hermes-hooks unit tests over log lines in Hermes v0.22.5's format
(plugins_dispatch.py, hermes_logging.py), tsc, oxlint, doc checks.
Calls through `openclaw agent exec --json --message-file -` on OpenClaw
2026.8.1 and 2026.10.9, with a mock model in a throwaway state dir, left
`openclaw sessions --all-agents --json` at count 0; `--state-dir` is the
only way to keep one. 2026.8.1 is the first release with `agent exec`.
…le-repo team

With sharing.gitExclude on, a single-repo team kept Claude Code's team hooks
in the checkout's .claude/settings.local.json, but wrote CodeBuddy's and
Qoder's into the tracked .codebuddy/settings.json and .qoder/settings.json, so
every pull left git status dirty.

CodeBuddy and Qoder merge the hooks of a settings.local.json beside their
project settings, as Claude Code does. TOOLS now records that read
(CodeBuddy Code 2.179.1 verified with a real `-p` run; qodercli 1.1.81 from its
bundle; Qoder CN assumed from the shared codebase), and
selfLocalSettingsOf derives from it which tools take the team hooks there and
which local files are the member's own in every checkout. The member's other
keys in that file, such as CodeBuddy's MCP approvals, are kept.

Tested: a new self-mode E2E case for CodeBuddy and Qoder (git status clean
after init and pull, team hooks only in settings.local.json, member keys kept,
`hooks remove` takes them away) fails before and passes after; the rest of
self-mode-git-exclude-915 still passes; locate hooks matrix; npm run lint.
… unpacks them

teamai looked for WorkBuddy's Node in ~/.workbuddy/bundled/node/versions,
which no release has used: WorkBuddy 5.6.2 and 5.7.6 unpack every runtime into
<data root>/binaries/<name>/versions/<version>-<variant> (VENDOR_ASSETS in
main/index.js), with bin/node, or node.exe on Windows. So hook commands never
got WorkBuddy's Node and fell back to CodeBuddy's or teamai's own.

The data root is ~/.workbuddy for WorkBuddy and ~/.workbuddy-ai for WorkBuddy
AI, the international edition that ships the same engine (bundle id
com.workbuddy.workbuddy-ai, product.json dataFolderName), not a 5.7 layout.
WORKBUDDY_CONFIG_DIR moves it. teamai now looks under each, takes the newest
version dir that holds the binary, and skips the `current` file and unfinished
unpacks beside them. The docs that called .workbuddy-ai "WorkBuddy 5.7+" now
name the edition.

Tested: bundled-runtime unit tests for both roots, node.exe on Windows,
WORKBUDDY_CONFIG_DIR, newest complete version past `current` and an
`.installing.` dir, and WorkBuddy AI's PortableGit; tsc, oxlint, doc checks.
…ered prompt does

Codex asks about a project the first time it opens there, so a config with no
entry for it is a question not answered yet. The read-gate tests moved to the
warning with that change; these two in the MCP and agent delivery suites still
expected a failure.
The plugin's tsconfig keeps src/ outside its rootDir, so importing TOOLS broke
`tsc -p oxlint-plugin-teamai`. The test now reads TOOL_IDS from src/tools.ts
as text, a second source for the TOOLS keys the rule parses.
- The OpenClaw plugin gate no longer depends on teamai's workspace hook being
  there: a team with hooks but no workspace hook was left unchecked.
- OpenClaw trims and lowercases plugin ids, so `plugins.allow` and
  `plugins.deny` match teamai's id the same way (doctor and inject share it).
- Hermes's log names no project, so a section other plugins crowded out may be
  another project's: that now warns, and the message says it was the last
  session on this machine. A section teamai's own plugin failed still fails.
- The auto-compact targets come from each tool's `autoCompact` instead of a
  hand-written kind list a new kind could miss.
- WorkBuddy runtime dirs compare their `-<variant>` too.
- Smaller: the OpenClaw plugin id and path have one spelling, a doc comment
  back on its function, indented lint-disable comments, every dot escaped in
  the Hermes section id, tests that assert on every row.

Tested: doctor-delivery (OpenClaw rows, plugin gate without the workspace
hook, mixed-case ids), hermes-hooks, bundled-runtime, autocompact, openclaw
suites; tsc; npm run lint.
…k gate as it was

Hermes's log names no project, and its other reachable skip, a section over
4,000 characters, depends on the project as much as being crowded out does: a
long section in project A failed doctor in project B with a fix that did not
apply. Every skip now warns, a too-long section points at the project's own
length check, and the check runs only while the plugin is installed.

Also: Claude's settings hook location gets its read gate whether or not it has
a file again, as before this branch; and a .qoder/settings.local.json Qoder and
Qoder CN share is tested against each one's records.

Tested: hermes-hooks (max_chars and raised skips), doctor-delivery, locate and
hooks suites; tsc; npm run lint.
A section over 4,000 characters is now its own outcome of the log parser, so
the doctor fix for it cannot drift from the log format, and the message names
the session by its time instead of calling it the last one: a later session
outside any project logs nothing. The agent's troubleshooting entry lists the
three causes and the step for each.

Tested: hermes-hooks (too-long, raised), doctor-delivery; tsc; npm run lint.
The check is named for the last logged session, as its fix line now says, and
the too-long case ends with starting a new Hermes session like the others.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
  • [P3 nit] src/tools.ts:1230 marks CodeBuddy’s settings.local.json hook read as verified, but the PR description records only TeamAI writing that file—not a CodeBuddy run demonstrating it reads those hooks. Add the tool version, run date, and command for that verification, as required by the Code Review Rules.

No confident runtime bugs found. The PR description satisfies the real-CLI testing requirement; the additional provider/agent coverage deferred to CI is not blocking.

Review was read-only; nothing from the PR was run, built, or installed.

@hz89Dev

hz89Dev commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Added the run record to the PR body (Test Plan, after the real-CLI block). CodeBuddy Code 2.179.1 was installed from the npm tarball on 2026-11-02 and run as codebuddy -p hi with an isolated HOME. SessionStart and UserPromptSubmit hooks in both .codebuddy/settings.json and .codebuddy/settings.local.json fired from the repo root, and none fired from a subdirectory. That is why the read is verified and cwdOnly.

@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.

The OpenClaw plugin check works as described. I ran it with the built CLI against this head and against the base. It fails with exit 1 in each of these cases:

  • plugins.enabled is false;
  • deny lists the plugin, even when allow lists it too;
  • allow leaves the plugin out;
  • the plugins block is missing.

This matches OpenClaw's config-activation-shared.ts. A Pi project with no trust entry now warns with exit 0, and --json shows "warning": true. doctor leaves openclaw.json untouched.

[P1 blocking] An unreadable trust or approval file now passes with a warning

read-gates.ts reads every store except Codex's through readJsonObject, readCommentedJsonObject or readFileSafe. All three turn any read error (EACCES, EISDIR, EIO) into missing. Before this PR, missing meant ✖. It now means "not asked yet", which shows ⚠ with exit 0.

Repro with the built CLI: set ~/.pi/agent/trust.json to {"<project>": false}, then chmod 000 it.

-- doctor, base: exit 1
  ✖ Pi trusts this project, so it loads its team skills
-- doctor, this PR: exit 0
  ⚠ Pi trusts this project, so it loads its team skills
    → … trust.json has no entry for <project> or a folder above it. Start `pi` in <project> and choose Trust …
✔ All checks passed!

The member refused trust, but doctor passes and tells them the file has no entry. The PR's own table and the new docs say an unreadable answer fails with ✖. By the same path, this also hits Muse, Copilot and Qoder folder trust and the Claude, Qoder, CodeBuddy and Cursor MCP approvals. I only ran Pi.

Codex already gets this right (codex-project-trust.ts). One reader in read-gates.ts built on the existing readFileIfExists would tell an absent file apart from an unreadable one, so the existing unreadable(...) path turns the second into ✖:

async function readStore(file: string, stripComments = false): Promise<JsonObjectRead> {
  let raw: string | null;
  try {
    raw = await readFileIfExists(file);
  } catch (error) {
    return { kind: 'invalid', error: `could not be read (${error instanceof Error ? error.message : String(error)})` };
  }
  if (raw === null) return { kind: 'missing' };
  // parse as readJsonObject / readCommentedJsonObject do today
}

Use it instead of readJsonObject and readCommentedJsonObject in the gate readers, and instead of the two readFileSafe calls in cursorMcpApproval. A test with a mode-000 store would pin this down.

[P3 nit] A one-time modified file after upgrade

For an existing single-repo CodeBuddy or Qoder install, the first pull on this release moves the team hook to settings.local.json, and leaves M .codebuddy/settings.json behind. Claude went through the same move in #1000. One line in the PR body telling members to commit that change once would help.

[P3 nit] A commented openclaw.json now fails both OpenClaw checks

A // comment in openclaw.json makes both OpenClaw checks fail, where the base failed one. This fails closed as the body says. Reading that file as JSON5 is the open #1221 item.

Notes

  • CI review: its one nit asked for a CodeBuddy run record for settings.local.json. The body now has one (CodeBuddy Code 2.179.1, 2026-11-02, codebuddy -p hi). That review ran before the body edit.
  • This PR conflicts with #1664 in 23 files, so whichever lands second needs a rebase.
  • When this was written, the macOS Lint & Test jobs and E2E shard 2/3 were still running. Everything else was green.

… be read

Since a gate the tool has not asked about yet warns, only an absent store
may mean "not asked". The gate readers folded every read error (EACCES,
EISDIR, EIO) into "missing", so a refused trust.json the member could not
read passed with a warning and exit 0.

One reader, readStore, now tells an absent store from one that is there
but cannot be read or parsed; the second keeps the verdict unknown and
fails. It replaces readJsonObject and the Copilot comment reader for every
gate store. Cursor's approval lists do the same, and the CLI counts as run
once its cli-config.json exists, readable or not.

Proof: a Pi test with a directory at trust.json fails before and passes
after. Real CLI: trust.json {"<project>": false} at mode 000 now fails
(exit 1, "cannot be read (EACCES ...)"), a readable false still fails, and
no trust.json still warns (exit 0).
@hz89Dev

hz89Dev commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the P1 in 6e2b133. Only an absent store now counts as "not asked yet".

  • readStore in read-gates.ts is built on readFileIfExists. It returns unreadable for a store that is there but cannot be read or parsed, and unreadable(...) turns that into ✖.
  • It replaces readJsonObject and the Copilot comment reader for every gate store: Pi, Muse, Copilot, Qoder, Claude hooks and MCP, CodeBuddy and OpenClaw.
  • Cursor's two approval lists use the same split. The CLI now counts as run once cli-config.json exists, readable or not.
  • The team's own .cursor/mcp.json read is unchanged.

Test: doctor-read-gates has a Pi case with a directory at trust.json (EISDIR, so it holds as root too). It received "warn" before the fix and passes after.

Real CLI, your repro:

trust.json {"<project>": false}, mode 000   ✖ … trust.json cannot be read (EACCES: permission denied, …), so whether Pi trusts this project is unknown   exit=1
same file, readable                          ✖ … sets "<project>": false   exit=1
no trust.json                                ⚠                             exit=0

P3 upgrade note: added to Notes for Reviewers. P3 JSON5: agreed. It fails closed, and that #1221 item stays open.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

No confident new findings in the specified PR diff.

  • Resolved: The earlier CodeBuddy verification nit is addressed: the description now records CodeBuddy Code 2.179.1, November 2, 2026, codebuddy -p hi, and the hook-marker results.
  • Testing sufficient: The description includes build and representative real-CLI verification records. Coverage explicitly deferred to CI is not blocking.

Review was read-only; nothing from the PR was run, built, or installed.

@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.

The blocking finding is fixed in 6e2b133. readStore builds on readFileIfExists, so only an absent store reads as "not asked yet". A store that is there but cannot be read or parsed fails with ✖. This holds for every trust and approval store, Cursor's two lists included, and the new EISDIR case covers it. The upgrade note is in the body, and the JSON5 item stays open on #1221. CI is green at this head. Approving.

@SaulMoro
SaulMoro merged commit 03f0c03 into Tencent:main Nov 2, 2026
18 checks passed
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