Repository navigation
doctor: read a CodeBuddy skill's hooks from its SKILL.md front matter - #1239
Conversation
The second half of Cygnux-Labs#1128 item 3, on top of the plugin half (Cygnux-Labs#1195, merged as `085344b2b9`). A skill's hooks are a `hooks` key in the front matter of a `SKILL.md` under `<configDir>/skills`, so a skill with a `PreToolUse` hook can answer a call Tracekit decided, and doctor named none of them: `D-HOOKS-ORDER` now names those files too. `_codebuddy_skills` walks `<configDir>/skills` five folders deep, the depth CodeBuddy's own loader scans (`MAX_SCAN_DEPTH`, and its skills watcher walks that root recursively), reads each `SKILL.md` with doctor's own reader (so a FIFO or a device where one should be can't hang it, and nothing over 4 MiB is read), and stops at 256 of them so a hostile tree can't stall the check. A skill is named only for `PreToolUse` or `PermissionRequest`, and only when the event lists an entry carrying a non-empty `hooks` array, which is what CodeBuddy's `parseFrontmatterHooks` requires (it skips an unknown event and a value that isn't an array). The front matter is read one key at a time rather than parsed whole, and that is what the second test is for: a real `SKILL.md` writes `description: |`, a block scalar `yamlmini` rejects, so parsing the whole front matter would raise and read no hooks from a skill CodeBuddy loads fine. CodeBuddy parses the front matter with a full YAML parser and hands only its `hooks` to `parseFrontmatterHooks`, so doctor takes the `hooks` block alone and a key beside it that doctor can't parse hides nothing. Wording: a skill gets the sentence a plugin does, "a skill's hooks, which may answer after Tracekit's (their order isn't known)", and "only where its hook answers last", because the bundle gives no place for either in the order relative to the settings files. `docs/limits.md`'s CodeBuddy row says a skill's front-matter hooks are read now, and that a plugin's own skills and an SDK host's in-code hooks are not. Tests, in `tests/test_doctor_v2.py`: a skill whose front matter registers `PreToolUse` is named; one that writes `description: |` is still named (and `yamlmini` is asserted to reject that front matter, so the test fails if the reader is widened back to a whole-front-matter parse); one with no front matter, no `hooks`, only another event, an empty event, or an entry with no hooks is not named; a `SKILL.md` six folders down is not read while five folders down is; and a FIFO where one should be doesn't hang doctor. With the skill read taken out of the return, the three naming tests fail. Part of Cygnux-Labs#1128 Signed-off-by: pm25coder <pm25coder@gmail.com>
|
Thanks, @pm25coder. CI is running on |
The branch's red is main's own and main has since fixed it. `Offline evals (Linux)` failed on `Thresholds the docs promise` at the fourth gate, `[.latency[] | .p99_ref <= 15 and .max_us <= 10000] | all`, and it failed the same way on **main's own CI at `085344b2b9`**, which is this branch's base: 35 passed, 12 skipped, that one step red. `9c87e62a8` replaced that gate -- `p99_ref` is a multiple of a reference time, which a slow runner moves -- with `max_us <= 10000` plus a new step, `eval/e21_relative.py`, that compares against main on the same runner (fails only over 5% slower). Main's next commit's run passed the job. So main goes in, which carries the fix and reruns CI. The three files this branch changes are merged three-way against (base `085344b2b9`, this branch, main's tip); the rest of the tree is main's own. Signed-off-by: pm25coder <pm25coder@gmail.com>
|
The one red on What failed. The gate before it — "Deterministic results equal the committed files", which diffs every policy decision against the committed results apart from machine, engine and latency fields — passed, so no decision moved; only the latency ratio did. Why it isn't this change. That expression divides by a reference time, so a slow runner moves it. The same job failed the same way on main's own CI at This change is three files — doctor's CodeBuddy plugin and skill reads, their tests, and one What |
|
@pm25coder Thanks, CI is green on |
|
@pm25coder Thanks for this. The review found that CodeBuddy loads skill hooks more narrowly than the PR assumes, so in the default setup the new warning names hooks that never run. We checked it in the published
So with default settings and That also removes two problems the walk has today:
Two smaller ones: the 256 cap The doctor-output ask from before still stands, on the reworked check. |
…oks run
Reworked on the review: a skill's `hooks` in a `SKILL.md`'s front matter are **off by default**, so naming that
file warned about a hook CodeBuddy never registers.
`AgentTask.registerFrontmatterHooks` (`@tencent-ai/codebuddy-code` 2.187.0, `dist/codebuddy.js`) reads
`await this.settingsManager.get("allowUntrustedFrontmatterHooks")`, treats a read that fails as false, and for a
source it doesn't trust only logs "Frontmatter hooks from … skipped (source not admin-trusted; enable
`allowUntrustedFrontmatterHooks` in settings to allow)". When it is on, what registers goes to
`scopedHookRegistry.register(this.subAgentSession.id, …)` — the sub-agent a forked skill runs. So the folder walk
is gone: `_codebuddy_untrusted_hooks` reads the switch out of the same three settings files `_codebuddy_off`
reads (the last that sets it decides, a literal `true`), and the check names that settings file, says the hooks
answer inside the sub-agent a forked skill runs, and gives the switch as the fix.
That also removes the two failures the walk had, both reproduced here before removing it:
- **a crash** — a `hooks:` block nested 500 deep raises `RecursionError` (the review said ~1,600; 500 already
does it here), and doctor caught only `YAMLError`/`ValueError`, so `tracekit doctor` exited 1 with no verdict;
- **a stall** — a flow list continued over 20,000 lines took **394 s** to parse on this host (the review measured
67 s), and up to 256 such files were read.
No SKILL.md is read now, so there is nothing to bound: the switch is three settings files.
Tests: the default setup names nothing (`SKILL.md` with a `PreToolUse` under the skills root); the switch on names
the settings file in force and says where the hooks answer; a string `"true"` and `1` are not the switch on, a
literal `true` is, and a later `false` in `settings.local.json` lifts it. With the switch read taken out, both
switch tests fail.
`docs/limits.md`'s CodeBuddy row now names `allowUntrustedFrontmatterHooks` and says the hooks answer only inside
a forked skill's sub-agent; `docs/doctor.md`'s `D-HOOKS-ORDER` row, stale since Cygnux-Labs#1195, is corrected in the same PR.
Part of Cygnux-Labs#1128
Signed-off-by: pm25coder <pm25coder@gmail.com>
The previous commit's three-way merge on `docs/limits.md` silently took this branch's older text for two rows main had since reworded, and dropped a third (`Whether a sub-agent's own tool calls fire the hooks isn't tested …`) that main added. Both docs are rebuilt from main's current copy with only this PR's sentence swapped in, and checked line by line: every line of main's copy is still there but the one replaced. `tracekit/doctor.py` and `tests/test_doctor_v2.py` are unchanged by this commit; their merge kept every line of main's (the only main lines absent are the ones this PR itself rewrites). Signed-off-by: pm25coder <pm25coder@gmail.com>
The previous commit re-shipped this branch's own `doctor.py` instead of the one its merge with main had produced, which dropped 19 lines of main's from it. The two Python files are taken from `616231f4` (whose merge kept every line of main's but the ten this PR rewrites), and the two docs from the rebuild on main's copy. Checked per file: main lines absent = 10 in `doctor.py` and 0, 1, 1 in the rest, which are exactly the lines this PR replaces. Signed-off-by: pm25coder <pm25coder@gmail.com>
|
Reworked along all five points — head is 1. Front-matter hooks are off by default. Confirmed in 2.187.0: 2. Registered only for a forked skill's sub-agent. Also confirmed: what passes the trust check goes to The smallest change you named is the one I made: 3. The crash, reproduced, and slightly worse than reported. A 5. The smaller ones. The 256- The Commands: made Default ( $ HOME=<scratch>/home python -m tracekit doctor # in <scratch>/proj
dev setup OK: every call is decided and recorded, but the agent runs as you and could switch Tracekit off; system mode or Tracekit Box close that (D-PROCESS-BOUNDARY)
(19 more checks not listed: tracekit doctor --verbose)With the switch on: $ HOME=<scratch>/home python -m tracekit doctor # "allowUntrustedFrontmatterHooks": true
OK with 2 warnings of 19 checks
WARN Dev mode: the agent runs as you, so it could rewrite the record. To close that: system mode, https://github.com/Cygnux-Labs/Tracekit/wiki/Deploy (D-PROCESS-BOUNDARY)
fix: use system mode where the agent must not reach the signer: from a root-owned clone of the release (https://github.com/Cygnux-Labs/Tracekit/wiki/Deploy#laptop-system-mode), sudo /usr/bin/python3 -m tracekit init --v2 --user <agent-user>
WARN a skill's front-matter hooks, which <scratch>\home\.codebuddy\settings.json lets run (allowUntrustedFrontmatterHooks) and which may answer after Tracekit's inside the sub-agent a forked skill runs (their order isn't known), and CodeBuddy takes the last hook's permissionDecision: a skill's allow runs a call Tracekit denied only where its hook answers last (D-HOOKS-ORDER)
fix: unset allowUntrustedFrontmatterHooks in <scratch>\home\.codebuddy\settings.json, or have no skill front-matter hook that answers permissionDecision allow
(17 more checks not listed: tracekit doctor --verbose)Verification on this head, on main's extracted tree ( One thing worth flagging about my own process: my first push of this rework merged main into the branch, and the three-way merge on |
|
Thanks @pm25coder. We see the rework in |
|
@pm25coder Thanks, the rework is right. We ran
Two small things before merge:
|
`docs/doctor.md`: the reworded cell read "... in its config.toml an enabled plugin's own ..." -- the comma went with the parenthetical it replaced. It now reads "... in its config.toml, an enabled plugin's own ...". Both docs are rebuilt from main's current copy (`d629be745c`) with only this PR's sentence swapped in. Per file, main's lines absent from what ships: 10 in `doctor.py`, 0 in the test file, 1 in each doc -- the lines this PR rewrites. Signed-off-by: pm25coder <pm25coder@gmail.com>
76273c4 to
18493ca
Compare
|
Both points done, head is 1. The comma. You were right, and it was mine: reworking the cell replaced the parenthetical that carried the 2. The verbose run. Fair criticism, and the two tells you spotted were real: the blocks I pasted came from two I also rebuilt both docs on main's current copy ( |
|
Thanks @pm25coder. Both are in: the comma, and two real |
|
One more piece of evidence while CI runs, in case it is useful: the whole This is a Windows host, which is why some of them fail here and not on your runners. Also checked on that tree: no reference to the removed walk survives ( |
|
CI is green on Every shard passed ( Nothing further from me on this branch. Thanks for the careful reads: the front-matter switch was the whole point I had missed, and both small asks were real. |
|
Thanks @pm25coder. Green on |
|
Merged as 840e0b5. Thanks @pm25coder: doctor now warns about a skill's front-matter hooks only when CodeBuddy would actually run them, and no skill file can crash or stall it. |
The second half of #1128 item 3, on top of the plugin half (#1195, merged as
085344b2b9).Reworked on the review: a skill's
hooksin aSKILL.md's front matter are off by default, so naming that file warned about a hook CodeBuddy never registers. The folder walk is gone.What doctor reads now.
_codebuddy_untrusted_hooksreadsallowUntrustedFrontmatterHooksfrom the same three settings files_codebuddy_offreads (the user'ssettings.json, the project's.codebuddy/settings.json, thensettings.local.jsonbeside it; the last that sets the key decides, a literaltrue), andD-HOOKS-ORDERnames that settings file. The wording says where such hooks can answer: inside the sub-agent a forked skill runs, with the order unknown, as for a plugin.The bundle (
@tencent-ai/codebuddy-code2.187.0,dist/codebuddy.js):AgentTask.registerFrontmatterHooksreadsawait this.settingsManager.get("allowUntrustedFrontmatterHooks"), treats a failed read as false, and for a source it doesn't trust only logs "Frontmatter hooks from … skipped (source not admin-trusted; enableallowUntrustedFrontmatterHooksin settings to allow)". What does register goes toscopedHookRegistry.register(this.subAgentSession.id, …)— a sub-agent session, removed when it ends.No SKILL.md is parsed now, so the two failures the walk had are gone by construction rather than capped. Both reproduced here before removing it: a
hooks:block nested 500 deep raisesRecursionError(500, not ~1,600, on this host), which doctor caught only asYAMLError/ValueError, sotracekit doctorexited 1 with no verdict; and a flow list continued over 20,000 lines took 394 s to parse here (the review measured 67 s).Docs.
docs/limits.md's CodeBuddy row namesallowUntrustedFrontmatterHooksand says the hooks answer only inside a forked skill's sub-agent;docs/doctor.md'sD-HOOKS-ORDERrow, stale since #1195, is corrected here.Tests in
tests/test_doctor_v2.py: the default setup names nothing (aSKILL.mdwithPreToolUseunder the skills root); the switch on names the settings file in force and says where the hooks answer; a string"true"and1are not the switch on, a literaltrueis, and a laterfalseinsettings.local.jsonlifts it. With the switch read taken out, both switch tests fail.Part of #1128
tracekit doctor --verbose, run on18493caabaTwo real runs on this head (a Windows host, so the separators in the paths below are its own), a scratch CodeBuddy
config built for the occasion: Tracekit's CodeBuddy hooks written into
<scratch>\.codebuddy\settings.jsonwithagent_hooks.install("codebuddy", …), and<scratch>\.codebuddy\skills\guard\SKILL.mdcarrying aPreToolUseentry. Nothing was edited except that the machine's own paths are replaced: the scratch home with
<scratch>, theinterpreter I ran it with with
<python>, the extracted tree with<tree>, and%LOCALAPPDATA%with<local-appdata>.allowUntrustedFrontmatterHooksabsent (the default) —D-HOOKS-ORDERis ok:"allowUntrustedFrontmatterHooks": truein<scratch>\.codebuddy\settings.json—D-HOOKS-ORDERis WARN andnames that file:
Both runs also show the checks around it unchanged: the hooks are present, they name their event, and no settings
file turns them off. On this head the suites read
-k "codebuddy or ORDER"8 passed, 2 skipped, 8 subtests andtests/test_docs.py17 passed, 2 skipped, 10 subtests.