Skip to content

fix(skills): the data-vs-run guard fires only on the words the shell runs (#832) - #854

Draft
hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/832-prebash-data-vs-execution
Draft

hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/832-prebash-data-vs-execution

Conversation

@hr1juldey

Copy link
Copy Markdown

Fixes #832.

Problem

Quoted data that merely names the words — another tool's CLI in a string, a hook filename inside a commit message — tripped both the agent guard and the save gate:

  • echo "note: graft-hooks.cjs is only named in this quoted text" → denied: "Trail's hook scripts run only from the host's hooks, never by hand"
  • echo "the other tool's command is: npx skills update" → answered by the save gate
  • the same echo from a subagent → denied for being a subagent, on a command that runs nothing

Root cause

  • hookUnrun (src/trace/shell-words.ts) had no echo/printf branch — they fell to return false, so quoting a filename read as a run; its git bookkeeping branch also rejected any quoted body (-m messages, -S patterns are bodies).
  • The save-gate entry (src/claude/pre-bash-skills.ts) tested SAVE_GATE against raw command text.

Fix

  • hookUnrun: echo/printf leave the hook unrun (their quoted arguments are the words; a redirect still writes, a pipe is judged per segment upstream); git bookkeeping verbs treat quoted messages/patterns as words. Fed to an interpreter (echo … | node graft-hooks.cjs) is still the run.
  • New runsTrailSkillsGate: bareCommand of some simple command is the trail CLI (trail/graft/trail-dev, npx @nanonets/graft/@trailhq/trail-code) with skills add|lesson|update as its subcommand. The subagent deny now only ever sees genuine trail-skills commands.

Tests

Two new tests (RED first): quoted-data cases answer null while a real trail skills add still gates; hook-name-in-quoted-data is null while the piped form keeps its hook-script hit. Full suite: 4550 tests, 6 failures — exactly the pre-existing set on main.

…runs

Quoted data that merely names the words tripped both gates:

- a hook script named inside quoted data (an echo note, a git commit
  message, a git log -S pattern) denied with 'hook scripts run only from
  the host's hooks, never by hand' — hookUnrun had no echo/printf branch
  and its git bookkeeping branch rejected any quoted body, so the words
  read as a run. echo/printf now leave the hook unrun (their quoted
  arguments are the words), and git bookkeeping verbs treat quoted
  messages and search patterns as words. A pipe to an interpreter is
  still the run.
- the save gate answered to 'npx skills update' or 'skills add' sitting
  in quoted prose, because SAVE_GATE matched raw text. The gate entry is
  now runsTrailSkillsGate: some simple command's program (bareCommand,
  the parser the agent guard trusts) is the trail CLI with a gate verb
  as its subcommand. A subagent quoting the words is no longer denied
  for being a subagent on a command that runs nothing.
@github-actions

Copy link
Copy Markdown
Contributor

🌱 graft blast radius

2 areas changed → 2 areas can be affected. 3 dependent symbols, depth 2.
Tests: no test reaches Shell Word Parsing; 1 area updated its tests.
Tag: @anirudhkumar-nanonets — Pre-Bash Hooks · @shhdwi — 4 of 4 areas

flowchart TB
  A0(("Pre-Bash Hooks<br/>2 symbols"))
  A1(("Risk Assessment<br/>1 symbol"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0,A1 reached;
Loading
Can be affected Symbols Nearest hop Reached from
Pre-Bash Hooks 2 src/claude/pre-bash.ts:L252-L286 main — calls, depth 1 Pre-Bash Skills Gate
Risk Assessment 1 src/skills/risk.ts:L383-L383 leavesHookUnrun — calls, depth 1 Shell Word Parsing
Who knows this code — 2 people across 4 areas
Area Who knows it
Shell Word Parsing · changed @shhdwi — 1 commit, last 28d ago
Pre-Bash Skills Gate · changed @shhdwi — 1 commit, last 27d ago
Pre-Bash Hooks · affected @anirudhkumar-nanonets — 23 commits, last 10d ago · @shhdwi — 16 commits, last 22d ago
Risk Assessment · affected @shhdwi — 1 commit, last 28d ago

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

All 3 dependent symbols, grouped by area

Pre-Bash Hooks — 2 symbols in 2 files

  • src/claude/pre-bash.ts:L252-L286 — main (calls, depth 1)
    275: const { preBashSkills } = await import('./pre-bash-skills.js');
  • src/claude/hooks.ts:L537-L627 — main (calls, depth 2)

Risk Assessment — 1 symbol in 1 file

  • src/skills/risk.ts:L383-L383 — leavesHookUnrun (calls, depth 1)
    383: const leavesHookUnrun = <T>(head: string, bodies: string[], hitOf: (text: string) => T | null) => hookUnrun(head, bodies, hitOf, namesHook);
Test signal per changed area — 1 ✓ · 1 ✗

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✗ Shell Word Parsing — 0 of 1 reached · no test file reaches it
    • not reached: hookUnrun
  • ✓ Pre-Bash Skills Gate — 1 of 2 reached · 1 test file changed here: test/claude-pre-bash-skills.test.ts
    • not reached: runsTrailSkillsGate
10 test suites also reference this code

12 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.

  • test/claude-guard-review.test.ts
  • test/claude-hooks-perf.test.ts
  • test/claude-hooks-review.test.ts
  • test/claude-host-standdown.test.ts
  • test/claude-skills-journey-fixtures.ts
  • test/skills-gated-retry.test.ts
  • test/skills-guard-text.test.ts
  • test/skills-hook-read.test.ts
  • test/skills-restore-version-guard.test.ts
  • test/skills-risk-login.test.ts

graft blast · origin/main...HEAD · depth 2 · 4 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

This branch has not been deployed

No deployments
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.

Pre-Bash guard and skill-save gate match command text, so quoted data is denied

1 participant