Repository navigation
fix(hooks): record what a CodeBuddy session does, and what it loads - #1547
Conversation
|
No confident findings in the specified diff. The PR description includes sufficient testing: a built, real-CLI run reproduces the CodeBuddy payloads and records both events and skill usage. The unavailable plugin is explicitly disclosed; additional host coverage is not blocking. Review was read-only. I did not run, build, or install anything from the PR. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@Walternater Thanks for taking #1516. #1545 (opened earlier) fixes the same issue. We review both in full, the first one ready merges, and the other closes. This PR already avoids the two blockers we raised there: CodeBuddy /name prompts still count (one usage line on this branch and on main), and it merges cleanly with main at 793e0351, where tsc passes. use_skill is labelled source, and the tool-support pages are in sync. For a member with only a project-scope config, the CodeBuddy usage record and tool_use event now land in the project, where main records nothing. tsc, lint and the changed test files pass, and the three new tests fail on main.
What blocks approval:
-
[P1 blocking] The fallback to the session's workspace runs for every tool, so another repo's activity is recorded under a team. The new fallback in the hook-scope resolution doesn't check the tool. With the built CLI, a Claude session starts in team project A, then sends its hooks from repo B, which has no teamai:
this branch: events "type":"session_start", "tool":"claude", "cwd":"<R>/team-a" "type":"tool_use", "tool":"claude", "cwd":"<R>/team-a" "type":"prompt_submit", "tool":"claude", "cwd":"<R>/team-a" team-a/.teamai/usage.jsonl: 1 line (B's /hello-skill) main: only the session_startB's activity is reported to team A, with its
cwdrewritten to A. That breaks #748 (a directory without teamai runs no team handlers) and the issue's own "Claude channels unchanged" item. The body says every other host's path is unchanged. From the code, Codex team hooks (codex-team-hooks.ts:272) and scoring (scoring.ts:122) resolve through the same function, so they're affected too, though we didn't run them. Limiting the fallback tocodebuddy, the host that sends an extension-hostcwd, keeps every other tool as it is. -
[P2 non-blocking on its own; we hold approval for an important item in scope] No recovery for a member with both a user-scope and a project-scope config. We raised this on #1545, and it reproduces here. The extension-host
cwd/resolves to the user config, so the fallback never runs: theuse_skillcall is lost, and thetool_useevent is recorded withcwd: "/". Members who installed at user scope and then joined a project are a common case. Recovery should also apply when thecwdresolves only to the user scope and the session started in a project.
Non-blocking:
- [P2 non-blocking]
resolveHookScopenow names two unrelated exported functions: the existing one insrc/types.ts:3425, and the new one insrc/dashboard-collector.ts. A distinct name for the new one would keep a search from landing on the wrong one. - [P3 nit] Two neighbouring CodeBuddy comments in
src/tools.tsdisagree: one says the IDE sendsskill, the next that its skill tool isuse_skill.
The CI review found nothing. It ran no code, so it couldn't see the cross-tool case. E2E shard 2/3 and the Lint & Test jobs were still running when we checked.
Three causes, all in teamai-cli (Tencent#1516): - The CodeBuddy plugin sends the extension host's own directory as the post-tool-use cwd, which holds no teamai scope, so every handler that needs one was dropped and the session's tool use was never recorded. The scope is now resolved from the workspace the session recorded, as it already is for a cwd that is gone — for that host alone, so every other host's payload keeps the scope its own directory holds (Tencent#748). A member who installed at user scope and then joined a project gets the project's scope back, not the user scope the extension host's directory resolves to. - The plugin's skill tool is `use_skill`, which was not in the tool's registered skill calls, so the call was never a skill use. - A manual slash command lands as `@command://name`, which the `/name` form cannot match, so the prompt named no skill. The `@command://name` form is anchored at the start of the prompt, so a command URI quoted in the conversation is not a skill use, and `/name` still counts for CodeBuddy.
1698832 to
5fcb64c
Compare
|
Thanks for the review — all three points are addressed in
One more change worth naming: the recorded-workspace cache is keyed by the session and the home the events live in, so two sessions in different homes cannot read each other's answer. |
|
No confident findings in the specified diff. The PR description documents sufficient testing: a built, real-CLI reproduction records tool-use and prompt-submit events, plus skill usage through both CodeBuddy channels. The unavailable plugin is explicitly disclosed; additional host coverage is not blocking. The earlier review reported no findings, so none require resolution. Review was read-only. I did not run, build, or install anything from the PR. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Thanks, approving 5fcb64c5. All four points from the last review are fixed. I checked each with the built CLI:
- Fallback now limited to CodeBuddy. A Claude session that starts in team repo A and then works in repo B records only the session start in A, and nothing for B, the same as main.
- User-scope plus project-scope install. When the plugin sends
/, the events now carry the project directory, and the project'susage.jsonlgets theuse_skillcall and the@command://prompt. On main the event sayscwd: /and nothing is recorded. - Sessions that belong to the user scope stay there. A session opened in HOME, or in a git directory with no project config, still records to
~/.teamai/user-usage.jsonl. With no config at all, nothing is recorded, the same as main. - Other tools behave as on main. For tools other than CodeBuddy,
resolveHookScopeForreturns what main's code did, and nocwdis rewritten. That covers Codex team hooks and scoring. - The name and the two comments are fixed.
The PR's three test files pass (110 tests), on this head and merged into current main, where tsc is clean too.
[P3 nit], optional: the CodeBuddy CLI shares the codebuddy id and sends its real working directory. If a CLI session starts in project P and later reports a directory that only the user scope covers, that activity now goes to P, with its cwd rewritten. On main it went to the user scope. This needs the CLI to leave the project directory, so it's rare, and no data is lost. One way to tighten it: skip the recovery when the reported directory is inside a git work tree, which the extension host's / never is.
…encent#1547) CodeBuddy's plugin sends the extension host's directory instead of the workspace, so its tool-use and prompt events fell back to the user scope or were dropped. For CodeBuddy only, teamai now resolves the hook scope from the workspace the session recorded at its start, including when a user-scope install also exists, and records the IDE's skill tool and the plugin's use_skill. Other tools resolve their scope from their own cwd as before. Fixes Tencent#1516.
Summary
Under the VSCode CodeBuddy plugin, every
post-tool-usedispatch ran onlylocal-agent-sync: the handlers that need a teamai scope (dashboard-report,skill-use) were dropped, so tool-use events and skill usage were never recorded for that host.Three independent causes, all in teamai-cli:
cwd— it holds no teamai scope, so the scope resolution failed and the config-dependent handlers were dropped.use_skill, which was not among the tool's registered skill calls, so the call was never a skill use.@command://name, which the/nameprompt form cannot match.What changed
src/dashboard-collector.ts).hookScopeDiralready falls back to the recorded scope for a cwd that is gone; a cwd that holds no teamai scope now falls back the same way — the workspace the session recorded.resolveHookScopeForresolves the config and the directory together, so the dispatch works in the workspace (the payload's owncwdis replaced with it) instead of the extension host's directory. The recorded workspace is read once per process.HOSTS_SENDING_OWN_CWD). Every other host's payload names the workspace it works in, so its scope stays what that directory holds: a repository without teamai runs no team handlers ([bug] TeamAI hooks reach projects that never set it up: Stop nudge, and skill usage pushed to another team's stats #748), and another repository's work is never reported to the team the session started in. This is the change asked for in the review of the first version of this PR, where the fallback ran for every tool.use_skillis a CodeBuddy skill call (src/tools.ts).@command://nameis a prompt form (src/tools.ts,src/skill-use.ts). A tool'spromptFormtakes one form or several, so CodeBuddy keeps counting/nameas well. The command URI is anchored at the start of the prompt, so a command URI quoted in the conversation is not a skill use.Test Plan
Real-CLI verification
The built CLI (
npm run build), three small team repos made withteamai init . --self, and a skill under~/.codebuddy/skillsand~/.claude/skills. Every scenario sends the payloadcwdthe host sends, throughteamai hook-dispatch <event> --tool <tool> --stdin.post-tool-useand theUserPromptSubmitcarry the extension host's own directory ("/").main (5807b7d):
S1 records no tool use and no skill usage at all — the whole of the session's work is missing. S3 records the events with
cwd: /and the usage in the user scope, not the project the session works in.this branch:
S1 records both channels — the
use_skillcall and the@command://prompt — with the workspace as the cwd. S2 is unchanged from main: the other repository's work is not reported to the team. S3 records the events with the workspace as the cwd and the usage in the project's scope.The CodeBuddy plugin itself was not available here, so the plugin's own payload is reproduced from the report in #1516 (its
cwdis the extension host's, its skill tool isuse_skill, its manual slash command lands as@command://name); every other host's path is unchanged.npx tsc --noEmitpassesnpm run lintpassesnpx vitest runover the hook, skill-use, usage, tool-support, contribute, scoring, doctor and codex-hook suites — 22 files, 827 tests, all passNotes for Reviewers
HOSTS_SENDING_OWN_CWDnames the host whose payload is the extension host's directory; every other host resolves its scope from its own cwd, exactly as before this PR. S2 in the record above is the cross-repository case from the review: a Claude session that starts in a team repo and then works in another repository records nothing for that repository, as on main.resolveHookScopeForreplaces a user-scope answer with the project the session recorded, so a member who installed at user scope and then joined a project reports to the project (S3). A payload that holds a project scope of its own keeps it.src/__tests__/hook-scope-1516.test.tscovers the scope resolution: the recorded scope when the payload names none, the payload's own scope when it holds one, the project scope when the payload holds only the user scope, and no scope at all for a session that recorded nothing — plus the cross-repository case, which must stay unanswered for every host but CodeBuddy. The last two fail on the previous head of this branch.src/__tests__/skill-use.test.tsgains theuse_skillcall, the@command://nameprompt, the command URI quoted in the conversation (counted by nobody) and the plain/nameprompt for CodeBuddy. The first two fail on the previous head of this branch.hook-dispatch-cli.test.tsmocks the scope resolution, which now answers with the config and the directory together.docs/guide/reporting.mdand its Chinese page list the prompt forms a skill use is counted by; the CodeBuddy one is added.use_skillcall is markedevidence: 'source', notverified: the plugin's own bundle registers that name (see [bug] CodeBuddy host: tool_use events & skill usage never recorded — 3 independent causes in hook dispatch (v0.28.1) #1516), and a capture of a real CodeBuddy session is what would make itverified— the tool-support test only asks for a capture for theverifiedones.resolveHookScopeFor, asresolveHookScopealready names another one (src/types.ts).Closes #1516.