Skip to content

feat: add full support for the Grok tool - #2261

Open
JasonRUAN wants to merge 31 commits into
Tencent:mainfrom
JasonRUAN:feature/clawpro_teamai_support_grok
Open

JasonRUAN wants to merge 31 commits into
Tencent:mainfrom
JasonRUAN:feature/clawpro_teamai_support_grok

Conversation

@JasonRUAN

@JasonRUAN JasonRUAN commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor
  • Introduce the tool-grok package and Grok model handling, covering tool definitions, detection, launch, session adapters, and token usage parsing
  • Extend hook hosts to Grok by reusing Claude/Cursor hook settings with Grok-specific dedup guards, and adapt the fast path and dispatch CLI
  • Add the Grok folder-trust gate so team skills, rules, hooks, and MCP load only from trusted folders
  • Add TOML-format MCP rendering and install/uninstall for Grok, and write model config into .grok/config.toml with scan and reconcile support
  • Register Grok in the tool list, default paths, types, and launch adapters, with tests and fixtures

Summary

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
  • The test files that cover what I changed pass (npx vitest run <test files>); the full npx vitest run passes if the change touches src/__tests__/helpers/, a vitest*.config.ts, package.json or package-lock.json. CI runs the full suite on every push to a PR.
  • Added/updated tests for the change
  • Runtime change: one real-CLI run in a world (npm run verify:world; npm run -s verify -- help says how, and help drivers for where a step runs), pasted below with its verdict, combination and entry point, commands, build line and the ledger's last line. Not needed for a docs-only, tests-only or lint-rule-only change.

VERIFIED: grok x git x workspace scope via teamai pull

$ npm run verify:world
20261203T142521-f30656
Build 327ced2, teamai 0.22.0, sha256 6b05c0a4a501

$ npm run -s verify -- teamai 20261203T142521-f30656 --pass TEAMAI_NONINTERACTIVE init https://teamai.test/team/repo.git --provider git --agent grok --scope workspace
$ npm run -s verify -- sh 20261203T142521-f30656 mkdir -p .grok
$ npm run -s verify -- teamai 20261203T142521-f30656 --pass TEAMAI_NONINTERACTIVE pull
$ npm run -s verify -- ledger 20261203T142521-f30656

Ledger: CLEAN

Related Issues

Notes for Reviewers

- Introduce the tool-grok package and Grok model handling, covering tool definitions, detection, launch, session adapters, and token usage parsing
- Extend hook hosts to Grok by reusing Claude/Cursor hook settings with Grok-specific dedup guards, and adapt the fast path and dispatch CLI
- Add the Grok folder-trust gate so team skills, rules, hooks, and MCP load only from trusted folders
- Add TOML-format MCP rendering and install/uninstall for Grok, and write model config into .grok/config.toml with scan and reconcile support
- Register Grok in the tool list, default paths, types, and launch adapters, with tests and fixtures
This change tightens data handling at Grok's entry points for robustness and safety, without changing external behavior:

- Tool replies, session records, usage stats, and model configs now use zod schemas for structured validation, replacing scattered ad-hoc type checks. Malformed fields degrade safely or are ignored, keeping bad data out of downstream flows.
- Session, usage, and model config files are read and written through the regular-file helpers, ensuring only regular files are handled and avoiding risks from symlinks or other special files.
- The linter's baseline ID set is recalibrated so vendor fields in model configs are no longer mistaken for teamai tool IDs.
This change brings two tools into teamai's supported-tool surface, covering both the member-facing docs and the test matrices that pin down where each tool reads and writes:

- Adds Grok and WorkBuddy Pro to the tool support guide and every localized README matrix, including install paths, skills/rules/agents locations, hook and MCP layouts, and capability footnotes.
- Registers the new tool ids with the agent catalog and the generated tool-id set so lint rules and agent lookups recognize them.
- Extends the locate and channel test matrices with user and project rows for both tools, including Grok's folder-trust read gate and WorkBuddy Pro's shared MCP file layout.
Fix the misjudgment when a mapping tool has an empty record in the managed MCP
manifest. An empty record was treated as owning no servers, so members' own MCP
servers were mistaken for earlier teamai writes and wrongly retained, preventing
the config from being cleaned up. The check now distinguishes "no tool recorded
the file" from "a tool recorded it with an empty list", and only the former is
conservatively treated as a leftover write, removing the misjudgment against
members' own configs.

Also fully integrate WorkBuddy Pro as a supported tool: register it as a platform,
agent and launcher, and cover it in the MCP location matrix, conformance tests
and multilingual tool-support docs, giving it the same skills, rules, MCP and
session capabilities as existing tools while keeping all READMEs and the tool
matrix in sync.
The ownership rewrite turned `const other` into a multiline binding but
dropped the blank line before it, which `teamai/require-readable-spacing`
rejects. Restore it.

It also replaced `owned ? [...owned(target)] : []` with
`owned?.(target) ?? []`, passing the callback's `readonly string[]`
through to the mutable `owned` field on `McpFileObservation` (TS4104).
Widen that field to `readonly string[]`: its only consumer calls
`includes`, and the sibling `state.servers` field is already readonly.
WorkBuddy Pro was added to LAUNCH_ORDER, so the hardcoded tool lists in
doctor-scorers and tool-launch-call tests no longer matched the generated
messages. Add workbuddypro to those expectations.

The Pi request-log test and the conversation token E2E used fixed 2026-09-01/02
timestamps. With a 90-day request-log retention those records are now filtered
out, leaving requests.jsonl empty. Use the current time where the date is
immaterial, and freeze Date to the fixture date where the requestDaily keys
depend on it.
recordedStart kept the raw whitespace of `ps -o lstart=` while the
production processesOf parser collapses it. On macOS the recorded start
never matched the live one, so a recorded shell was judged a different
process, nothing was signalled, and the stop returned no left pids:
one test timed out with an orphaned child and another saw [].

Normalize the test's start string the same way processesOf does.
Registers Grok across teamai's workflow-driven launch stack so it behaves like
the other launchable tools: selectable via TEAMAI_AI_TOOL and ai.tool, and
launchable from workflows with its own isolated home directory.

Home resolution for launchable tools now also honors a descriptor's declared
root variable, so a tool can own its home configuration without relying on a
launch adapter entry. The lint rules that guard launcher imports and tool home
environment variables are extended to recognize Grok, and the affected tests
cover the new tool across launch, instance and global-hook scenarios.
User-facing errors that enumerate launchable tools now include Grok, keeping
configuration guidance accurate on every path.
Brings the member-facing tool support documentation in line with the launch
stack, where Grok is now a recognized and launchable tool. Both language
editions now describe Grok alongside the other supported tools and name the
home-directory variable it reads, so the published support matrix stays in
sync with what the CLI actually does.

This matters for members who move or isolate a tool's configuration: the
variable Grok reads is now discoverable in the same reference as every other
supported tool, instead of having to be inferred from the source.
@jeff-r2026 jeff-r2026 self-assigned this Dec 3, 2026
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Reviewed commit 16d927f90047. High risk: hold the merge and have two maintainers review the same fixed commit.

Important

  1. [P1 blocking] Protect delivered model credentials (src/grok-models.ts:153). The write does not request private permissions, so a new config can be created with mode 0644 under a typical umask. Project model delivery does not register the config for Git exclusion. Use a private write and protect the workspace config before delivering credentials.
  2. [P1 blocking] Keep model config and ownership in sync (src/local-agent.ts:9374, :9377, :5438). Delivering A and B as separate incremental updates leaves both on disk but records only B, so an empty snapshot cannot remove A. A manifest save failure also leaves untracked changes, and uninstall does not clean up delivered Grok models. Preserve incremental ownership, roll back on persistence failure, and use the same ownership record for uninstall.
  3. [P1 blocking] Preserve personal models and validate merged TOML (src/grok-models.ts:29, :90, :144). An unmanaged model with the same ID is silently replaced. Valid headers with trailing comments or single-quoted keys can be missed, producing duplicate tables. Header-like text inside multiline values can be mistaken for a real table and deleted. Parse the config, check ownership, and validate the result before replacing it.
  4. [P1 blocking] Reconcile defaults when a snapshot removes a model (src/grok-models.ts:150). If TeamAI initially sets A as the default, a snapshot that replaces A with B or removes all delivered models leaves the default pointing at A. Repair defaults set by TeamAI without overriding member choices.
  5. [P1 blocking] Keep Git protection for earlier MCP mappings (src/mcp-reconcile.ts:2401). An empty ownership record for the current mapping does not establish that a shared config is free of values left by earlier mappings. Preserve protection when remaining entries cannot be accounted for. This affects existing tools as well as Grok.
  6. [P1 blocking] Parse native Grok JSON in the headless step launcher (packages/tool-launch/src/run-step-launch.ts:490). The checked-in fixture returns text and sessionId, which the generic reader does not recognize. When Grok exits successfully with that response but no separate result file, the step reports that no valid workflow result was written.
  7. [P1 blocking] Emit MCP timeouts in the server table (src/resources/mcp-format.ts:611). With headers or environment variables present, timeout fields land inside the child table instead of configuring the server. Emit them before opening a subtable.
  8. [P1 blocking] Deduplicate hooks per event and command (src/claude-hook-host.ts:153). The presence of a native Grok Stop hook can suppress an inherited Claude PreToolUse command even if no replacement exists. Skip only the inherited hook that has a matching replacement.
  9. [P1 blocking] Add the actual real-CLI verification record to the PR. The Test Plan checkbox is marked, but the body contains only the template. Add one representative verify:world run with the command, build, verdict, and final ledger line; no full matrix is required.
  10. [P2 non-blocking] Fix model inventory scope (src/local-agent.ts:2857). The workspace scan returns nothing for Grok while the user scan can include workspace files.
  11. [P2 non-blocking] Complete Doctor's folder-trust checks (packages/tool-grok/src/definitions.ts:29, src/read-gates.ts:263, :268). Project rules and generated context lack the gate. A commented setting can be read as active, and an unreadable trust file raises an error instead of producing a diagnosis.
  12. [P2 non-blocking] Fix Grok session metadata and availability (packages/tool-grok/src/session-adapter.ts:39, :177, :210). Numeric timestamps in the fixture become 1970 dates. Reads by exact transcript path can pick another copy's summary when IDs collide and needlessly rescan summaries. A computed store path alone does not make the store available.

Nits

  • [P3 nit] src/grok-models.ts:137, :140: Only a missing file should be treated as empty; a writable but unreadable config can otherwise be overwritten. The removal set also adds IDs redundantly.
  • [P3 nit] src/claude-hook-host.ts:179: Recognize the immediately preceding hook prefix so upgrades do not duplicate unmarked hooks when ownership records are missing.
  • [P3 nit] src/resources/mcp-format.ts:588: HTTP and SSE produce identical config. Verify both transports with Grok or narrow the declared support.

Pre-existing

  • [P2 non-blocking] src/local-agent.ts:5984: Direct Codex MCP installation saves ownership and splices TOML without validating the result. Extending a valid inline mcp_servers table this way produces invalid TOML. The PR extends that path to Grok; it is not a new Codex regression.

Verification: GitHub reported 17 passing checks and one skipped remote-provider E2E for this commit. Both separate Codex review runs ended in startup_failure, with no review result. I checked the pinned diff and confirmed the timeout placement and both TOML parse failures with an independent parser. I did not run the native Grok CLI.

Protects the credentials teamai delivers into Grok's configuration from being
read or committed by others. Newly created Grok config files are written with
owner-only permissions, and workspace-scoped model keys are registered in the
repository's local exclude list so a delivered API key never enters git.

This closes a credential-leak path in the workspace sync flow without changing
how model configuration is delivered: the key stays available to Grok in the
expected location, but is no longer exposed through file permissions or
version control. Tests cover both the filesystem and repository sides so the
protection holds for every workspace-bound Grok setup.
Makes Grok model delivery reliable across incremental snapshots and teardown.
Previously delivered Grok models stay owned and tracked when later deliveries
arrive, an empty snapshot removes them cleanly, and remove-http now takes those
models out of the recorded Grok config instead of leaving them behind.

Delivery is also transactional: a failure while committing the delivery record
restores the original config and its permissions, so a broken write never
leaves a partially updated Grok setup. Tests cover incremental ownership,
empty-snapshot cleanup, teardown, and rollback on commit failure.
Replaces the line-based Grok TOML handling with a table-aware parser so model
delivery can distinguish teamai-owned tables from member-owned ones. Tables
that carry a delivered id but were not written by teamai are left untouched,
and duplicate or oddly quoted headers no longer lead to duplicated or
invalid configuration.

Merged configs are validated as TOML before they are written, and delivery
fails loudly instead of overwriting settings it does not own. Tests cover
unmanaged tables, quoted keys, trailing comments, duplicate headers, and
multiline values that look like headers.
Keeps the default model selection in a Grok config in sync with what a
snapshot actually delivers. Defaults left behind by earlier deliveries are
now repaired when their model table is replaced or removed, including the
case where the table was already gone, so a stale id can no longer point at
a model teamai no longer delivers.

Member-owned defaults are preserved: a default that names a model teamai
never delivered is left untouched, and removing one delivered model does not
disturb unrelated settings. Tests cover default replacement, full removal,
orphaned defaults, and defaults outside teamai's ownership.
Corrects how doctor decides whether a delivered MCP server's credentials need
to be excluded from git. An empty ownership record no longer counts as proof
that nothing needs excluding: when a tool currently maps the file but owns no
servers, any server still on disk is reported and its credential file is
offered for exclusion. This closes the case where an earlier tool mapping
left a server behind and a later empty record hid it.

The behavior applies consistently whether no tool noted the file or the
current mapping owns nothing. A regression test covers the empty-record case
where a previous mapping left a value behind.
Teaches teamai to parse Grok's headless JSON response as a step result when
the tool writes no result file, so a successful step no longer loses its
answer, session id, and token usage. JSON answers are exposed as structured
output and plain text answers as text, with usage read from either naming
convention Grok may print.

Also detects errors reported inside an otherwise successful Grok response,
including non-terminal stop reasons, and turns them into a tool failure
instead of treating exit code zero as success. Tests cover result parsing,
plain answers, and error detection from native stdout.
Moves the startup and tool timeout settings ahead of the transport-specific
lines when rendering Grok's MCP configuration. When a server also emitted a
nested table for headers or environment variables, the timeout keys were
written after that header and ended up in the wrong table, so Grok silently
ignored them.

Both HTTP and stdio servers now carry the timeouts on the server itself.
Tests parse the rendered TOML to confirm the shape, the headers, and the
environment values all land where Grok expects them.
The claude-targeted team command used to skip delivery to Grok whenever
Grok's hook file mentioned --tool grok anywhere. A single native hook could
then suppress unrelated events or commands, for example a Stop entry hiding
a PreToolUse command or a different team command.

The guard now matches the exact event and command pair in Grok's own hook
file, at both the user and workspace paths, on POSIX and PowerShell. It also
falls back to the raw event name when no claude-to-Copilot mapping exists,
so events outside the known set still get an accurate guard. Tests cover
native hooks not replacing other commands or events and the user versus
workspace hook file split.
grokModelsIn used to walk the parsed TOML by hand, checking that model was
an object and parsing each entry separately. It now parses the whole
document through a zod schema, so the [model.*] table is kept only when all
of its entries are well formed, and unowned tables stay out of the model
hash.

Quoted keys and table headers now track quote state explicitly so stray
characters cannot leak into keys. Write failures carry the original parse
error as a cause, and the table parser has a named return type.
The claude-team-only fixture still carried the old Grok guard, which skipped
a team command whenever --tool grok appeared anywhere in a hook file. The
fixture now embeds the event-and-command guard instead, so a native Grok
hook only suppresses the matching PostToolUse command.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 327ced26178e, superseding my earlier review for the current head. The update fixes several blockers, but I still recommend holding the merge. Risk remains high; please have two maintainers review the same fixed commit.

Fixed in this update: Headless Grok steps now read native JSON results; MCP timeouts are emitted in the server table; an empty current MCP ownership record no longer suppresses earlier-mapping evidence. Incremental model delivery retains earlier ownership records, and manifest save failures trigger rollback. Workspace model delivery now checks Git exclusion, and HTTP source teardown cleans up recorded Grok models.

Important

  1. [P1 blocking] Make existing Grok configs private and replace them atomically (src/grok-models.ts:367). The mode passed to the current writer only applies on creation: an existing 0644 config stays 0644 after credentials are written. The same writer truncates the live file before writing, so interruption can leave a partial config. Use an atomic replacement with explicit 0600 permissions.
  2. [P1 blocking] Apply workspace Git protection to direct Grok MCP installs (src/local-agent.ts:5996). The TOML branch bypasses the credential check used by the JSON path. Refuse to write credential-bearing entries if the workspace config cannot be kept out of Git; the model-delivery protection does not cover this entry point.
  3. [P1 blocking] Preserve member settings during model updates and cleanup (src/grok-models.ts:106, :254, :277, :378). The scanner does not recognize array-of-tables headers, so an unrelated table immediately following a managed model can be deleted with it. Whole-file blank-line normalization changes unrelated multiline values, and the ownership hash ignores additional fields that replacement then removes. The default handling also misses quoted keys and can mishandle a # inside a quoted model ID. Validate preservation of the existing settings, not just whether the generated TOML parses.
  4. [P1 blocking] Match the hook that will actually run (src/claude-hook-host.ts:119, :339). Team commands now match event and command, but not the matcher; a narrower Grok hook can suppress a broader inherited hook even when it will not run. Built-in dispatch still skips based on a file-wide marker, so a native Stop hook can suppress an inherited SessionStart with no replacement.
  5. [P1 blocking] Add the required isolated real-CLI verification record. Thanks for adding the commands and screenshots. The PR still needs one representative verify:world run with the command, build identifier, explicit verdict, and final ledger line. The hook-dispatch command is listed without its outcome. No full matrix is necessary.

[P2 non-blocking] The workspace model inventory still reports at the wrong scope; the folder-trust diagnostics and session timestamp issues from the earlier review remain. Pre-existing [P2 non-blocking]: the direct TOML MCP install path can still write invalid config when an existing mcp_servers table is inline; this limitation was inherited from Codex. [P3 nit]: Native SSE behavior is still unverified.

Verification: 17 GitHub checks passed and one remote-provider E2E was skipped. Codex Review on Assign ended in startup_failure with no review result. I verified the existing-file permission behavior and TOML table-boundary issue with small independent samples; I did not run the native Grok CLI.

…al handling

Makes Grok's Claude-shaped hook copy step aside only for the exact built-in
being dispatched, comparing event, matcher and command on every path, so a
matching entry in Grok's own file no longer suppresses unrelated hooks.

Model delivery now treats any extra field in a managed model table as a member
edit and refuses to replace or remove it. Writes are atomic and owner-only,
non-regular files at the config path are left alone, and a merged config that
would change any setting teamai does not manage is rejected outright.

MCP installs in a project tree now exclude credentials carried by TOML entries
from git in the same order as JSON ones, so a write failure cannot leave a
manifest entry for an unprotected server. Tests cover matcher-aware hook
skips, config ownership, and credential exclusion.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 19eb5095cb58. Several previous blockers are fixed, but I still recommend holding the merge.

The model writer now replaces the config atomically with explicit 0600 permissions, the initial direct MCP install checks Git protection, and the hook guards now account for matchers and dispatch events. The PR description now has a representative verify:world run with a clean ledger. That record is for the previous commit; this is a note, not a blocker.

  1. [P1 blocking] Preserve MCP credential protection after installation (src/local-agent.ts:6010, src/mcp-reconcile.ts:3137). The TOML manifest entry does not store resolved. Recovery falls back to calling the object-based credential detector on a raw TOML block string, which returns false. If the exclusion is lost, Doctor and pull can miss that the config still needs protection. Persist the credential classification and make the fallback handle TOML. On update, preserve the old record until the replacement is written; a failed write currently leaves the old block with the new hash.
  2. [P1 blocking] Do not delete member-owned model subtables on teardown (src/local-agent.ts:5093, src/grok-models.ts:308). If a member adds a settings subtable under a delivered model, the parent hash still matches, but teardown removes the entire subtree. This path bypasses the check that now protects unmanaged settings during delivery. Share the guard or remove only the owned fields.
  3. [P1 blocking] Preserve the selected default when its model remains delivered (src/grok-models.ts:415, :435). With A and B both delivered and B selected as default, a snapshot listing A first removes and recreates both tables and silently switches the default to A. Repair the default only when its selected model actually goes away.
  4. [P1 blocking] Match the stored command when deduplicating project team hooks (src/hooks.ts:2013, :2037). The inherited hook's guard is built before the project gate wraps the command, but the native Grok file stores the wrapped command. The exact comparison misses the equivalent native entry and both copies can run. Compare equivalent rendered forms and cover a workspace hook with both copies installed.

[P2 non-blocking] Workspace model inventory still reports at user scope, and Doctor can still misread folder-trust comments. The direct TOML install path also still needs merged-document validation for existing inline tables, an older Codex limitation now shared by Grok. The Grok call reader should reject explicit errors even when partial text is present, and headless steps should reject metadata-only replies when there is no result file.

CI at review time: Ubuntu lint failed on Node 20, 22, and 24, and the Windows-safe unit test step failed; other jobs were still running. See CI. The separate Codex run ended in startup_failure and did not produce a review. I reviewed the pinned diff; I did not run the native Grok CLI.

Grok hook and model-config readers used to accept unknown values and lean on
hand-rolled type checks. They now take typed JSON and TOML inputs validated
by zod schemas, so malformed hook files or member settings cannot be treated
as valid data.

The regenerated hook fixture now carries the event/matcher/command guard
that Grok's own hook files use, keeping the test in step with the guard the
CLI actually emits.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on c54946065647. I still recommend holding the merge. This update tightens the schemas and refreshes a fixture, but the four blockers from the previous round remain:

  • [P1 blocking] MCP credential protection: The direct TOML install still saves the ownership record without resolved (src/local-agent.ts:6010). Recovery still passes a raw TOML block to the object-based credential detector, so it can miss that Git protection needs to be restored (src/mcp-reconcile.ts:3137).
  • [P1 blocking] Model teardown: The removal path still bypasses the delivery preservation check and can delete a member-added subtable under a delivered model (src/local-agent.ts:5093).
  • [P1 blocking] Model default: A full snapshot still clears the selected default while replacing the table, even when the same model is delivered again. If it is not first in the snapshot, the default switches to another model (src/grok-models.ts:427, :447).
  • [P1 blocking] Project hook deduplication: The guard still compares the command before the project wrapper is applied, while the native Grok entry stores the wrapped command. Both copies can run (src/hooks.ts:2013, :2037).

The previously recorded verify:world run remains valid as evidence for its recorded build; its older SHA is not a blocker. As of this review, the new head's CI has failures in the Ubuntu Lint & Test jobs on Node 20, 22, and 24, with other jobs still running. The Codex run ended in startup_failure, not a review verdict. This pass was a pinned-diff review, not a native Grok CLI run.

The Grok model reader used the WithoutBigInt variants of smol-toml's table
and value types. Those annotations now use the base TomlTable and TomlValue
names instead. The change is types-only: parsed config and member-settings
behavior stays the same.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on d8159b343d09. This commit changes only TypeScript type imports and annotations in src/grok-models.ts; I found no new blocker in that delta. The four runtime blockers in the previous review remain:

  • [P1 blocking] Direct TOML MCP installs still do not persist the credential classification needed to recover Git protection (src/local-agent.ts:6010, src/mcp-reconcile.ts:3137).
  • [P1 blocking] Grok model teardown can still delete a member-owned subtable (src/local-agent.ts:5093).
  • [P1 blocking] Refreshing a retained model can still switch the member's selected default (src/grok-models.ts:427, :447).
  • [P1 blocking] Project hook deduplication still compares the pre-wrapper command against the wrapped native entry, allowing both copies to run (src/hooks.ts:2013, :2037).

I still recommend holding the merge. At review time, this head had six passing checks, one skipped check, and nine unfinished checks, with no failures reported yet. This was a diff review, not a native Grok CLI run.

…MCP delivery

Keeps a member's own choices intact when teamai removes or replaces a delivered
Grok model. Tables that gained settings teamai does not manage are left in
place with their record, and the default model stays on the one the member
selected as long as it is still delivered, instead of snapping back to the
first entry.

Hook guards now compare the command as Copilot and Grok actually store it,
including the project gate, so the duplicate copy steps aside only when the
hosts really run the same entry. MCP credential detection also understands
TOML blocks and their header variants, and an install records the outcome
alongside ownership so a failed write cannot leave a server unprotected while
claiming it was checked.

Tests cover member-edited tables, stored hook commands, TOML credentials, and
the install manifest outcome.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on c3f53693fc5a. I still recommend holding the merge. This update addresses the previous credential-recovery gap, preserves member-owned model subtables during teardown, and keeps the selected default when that model is refreshed. It also fixes the project-wrapper mismatch for ordinary team hook commands. The remaining blockers are narrower:

  • [P1 blocking] Serialize model and MCP updates to the shared Grok config. Model delivery (src/local-agent.ts:5470) rewrites the same file as MCP reconciliation (src/mcp-reconcile.ts:2996) without taking the MCP lock. When each reads the old file before either writes, the last atomic replacement can discard the other successful update. Use the same lock for the complete read/modify/write operation, including cleanup.
  • [P1 blocking] Validate direct MCP installs before changing the config or ownership record (src/local-agent.ts:6019, :6024). A valid inline mcp_servers table cannot be extended by appending an explicit server subtable. The direct install can leave Grok unable to read the whole config, including unrelated model settings. This weakness was inherited from the Codex path, but Grok now shares the file with model delivery. Reuse the validated merge from pull and preserve the prior record on failure.
  • [P1 blocking] Only deduplicate against a hook Grok actually loads (src/claude-hook-host.ts:314, :389). An untrusted workspace can have a previously delivered native hook on disk without loading it. If an inherited user hook runs, the on-disk match can suppress it even though the native copy never runs. Also limit the early dispatch guard to compatible inherited hosts. Folder-based team hooks still need a check for host-specific workspace variable rendering (src/hooks.ts:2018).
  • [P1 blocking] Retain cleanup records for unreadable configs (src/local-agent.ts:5084). Teardown treats all read failures as absence; a transient read error can leave the model and key on disk without marking cleanup incomplete. Treat only a missing file as already gone.

CI at review time: CI reported lint failures on Ubuntu Node 20, 22, and 24 and a Windows-safe unit-test failure; other checks were unfinished. Codex Review on Assign ended in startup_failure, not a review verdict. This pass was a pinned-diff review, not a native Grok CLI run.

A held team hook can outlive its manifest record. Its PowerShell command may
carry the POSIX gate Grok and Copilot store as a single-quoted literal, and
regating only the outer command left that embedded gate on yesterday's child
roots.

Regating now walks the quoted literals in a PowerShell payload and updates
any POSIX gate it finds, so held hooks land on today's children on both
shells. Test helpers no longer mistake quoted gate text for live code.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 56d4eeeea463. This update addresses a separate Windows hook re-gating case and changes test and manifest-record construction. I found no new blocker in this delta, but the four blockers from the previous review remain:

  • [P1 blocking] Model delivery and MCP reconciliation can still replace the same Grok config under different locks, losing an update (src/local-agent.ts:5471).
  • [P1 blocking] Direct MCP installation still does not validate the merged TOML before saving ownership and writing the config (src/local-agent.ts:6029).
  • [P1 blocking] Hook deduplication still treats an on-disk project hook as active even when folder trust prevents Grok from loading it (src/claude-hook-host.ts:314).
  • [P1 blocking] Teardown still treats an unreadable Grok config as absent rather than preserving the record for a retry (src/local-agent.ts:5084).

I still recommend holding the merge. At review time the latest head had five passing checks, one skipped check, and ten unfinished checks, with no failures yet reported. This was a pinned-diff review, not a native Grok CLI run.

Grok model delivery and MCP reconciliation rewrite the same config.toml,
so overlapping runs could read or overwrite each other's changes. A failed
model commit also had to finish restoring its snapshot before MCP could
safely touch the file.

Both paths now hold the MCP lock across the whole read-modify-write, including
the rollback on a failed commit. Tests verify the lock is held at each write,
released afterwards, and that MCP servers survive model removal.
An install against a Codex or Grok config with an inline mcp_servers table
could produce invalid TOML, and ownership migration could write a legacy
record before that bad edit was rejected. Installs now validate the original
file and the rendered result before any ownership write, so a rejected edit
leaves the config, manifest, and Git exclusions alone.

An existing server's ownership is committed only after the config write
succeeds; a new credential install still records it first. Shared helpers
now validate a TOML config and restore its original bytes on a failed write.
Cleanup treated any read or stat failure on a recorded config as "the file is
gone" and dropped its record, so a temporary EACCES or EIO left delivered
models behind with no way to retry. Reads now distinguish a missing file from
an access failure: only ENOENT clears the record, while other errors keep it
and mark the run failed.

Tests cover retrying remove-http and uninstall for Grok and WorkBuddy after
open and lstat failures, along with the already-missing config case.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 99ac1655bc79. Three points from the previous review are fixed: model config updates and cleanup now share the MCP lock, direct MCP install validates the merged TOML before writing, and unreadable model configs now keep teardown incomplete rather than being treated as absent. I still recommend holding the merge for the remaining issues below.

  • [P1 blocking] Only suppress inherited hooks when Grok loads the replacement (src/claude-hook-host.ts:293, :314). The project hook file is still included based on its path alone. If Grok runs an inherited user hook in an untrusted workspace and the matching native hook exists only in that workspace's file, the guard skips the inherited hook even though Grok does not load the replacement. Keep the fallback unless the replacement is active.
  • [P1 blocking] Keep MCP ownership when uninstall cannot parse the config (src/local-agent.ts:6347, :6401). An unfinished TOML value can hide a recorded server from the block finder. The removal then makes no config change but still forgets the record; after the member repairs the syntax, the credential-bearing server can reappear untracked. Apply the same fail-closed TOML validation as install and keep the record for retry. The underlying weakness was inherited from the Codex path; this PR extends it to Grok.
  • [P2 non-blocking] Handle TOML on MCP relocation (src/local-agent.ts:6149, :6190). The old entry is still read as JSON on this cleanup path, so a move can leave the old Grok server behind. Use the recorded format when removing the old entry.

CI was still running at review time: six checks passed, one was skipped, and nine were unfinished, with no failures yet reported. The separate Codex review ended in startup_failure. This was a pinned-diff review, not a native Grok CLI run.

A Claude or Cursor copy used to step aside as soon as Grok's hook file
contained the teamai marker, regardless of whether Grok actually loaded that
entry for the workspace. It now asks Grok's own inspector whether a candidate
is enabled, trusted for the workspace, and present in the right location, so
a stale or disabled entry no longer suppresses the inherited hook.

A hidden probe command carries the check into the shell guard, and command
matching now ignores malformed or non-command siblings. Historical guards are
still rendered for ownership recovery, tracked by a three-state guard version.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 7bf447a9c4b4. I still recommend holding the merge. The hook guard now checks Grok's inspection output and requires project trust for a project-sourced replacement. That addresses the previous untrusted-folder finding.

  • [P1 blocking] Preserve ownership when TOML MCP uninstall cannot read the server (src/local-agent.ts:6347, :6401). The uninstall path still splices without validating the current TOML, then drops the ownership record even if the splice changed nothing. A syntax error can hide a recorded server from the block finder; after the member repairs the file, the server and its credentials can remain without a record for retry. Apply the same fail-closed validation as install, before changing either the config or the record.
  • [P2 non-blocking] Avoid spending the hook deadline on live inspection (src/claude-hook-host.ts:390). A compatible hook now waits synchronously for a new Grok process for up to 1.5 seconds before dispatching. Please verify this fits the closing-hook budget, and that inspection reflects what an already-running session actually loaded rather than only the current files. Neither behavior was verified with the native CLI in this pass.

CI was still running at review time, with a failure in the Windows-safe unit-test step. The separate Codex review ended in startup_failure and did not produce a verdict.

The Grok hook probe relied on teamai being on PATH and compared hook source
directories by raw path, so a linked workspace or a CLI installed under
~/.teamai/bin could be missed. The probe now sets that bin on PATH for the
call and compares canonical, realpath-resolved directories; a Claude settings
copy no longer has to live in a .claude folder to be recognized.

Uninstall now validates the TOML before and after removing a server. If the
config cannot be parsed or the edit would be invalid, ownership is kept and
the file is left untouched, so a repair and retry can finish the removal.
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Follow-up on 0cb114821a98. The previous MCP uninstall blocker is fixed: uninstall now validates both the original TOML and the proposed edit before it can discard ownership.

  • [P1 blocking] Keep cleanup retryable when a delivered model is still present but cannot be safely removed (src/local-agent.ts:5096, :7766). If a member adds an extra field directly to a delivered model table, the strict grokModelsIn schema omits that model. Teardown then skips it before the member-settings check, does not add the file to left.models, and can discard the manifest while the original delivered API key remains. An absent model and a present-but-edited model need different outcomes: preserve the member's edit and retain the cleanup record with a diagnostic. The existing subtable protection does not cover this case.

I still recommend holding the merge for this issue. CI was in progress at review time (six passed, one skipped, nine unfinished, no reported failures). Codex Review on Assign ended in startup_failure. This was a pinned-diff review; I did not run the native Grok CLI.

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