šŸ› fix(doctor): take a hook that sets its gh to as-agent and runs "$@" as routed (#537)

Merged
AT
5d ago
+122-4

Slice: #116
State: #537

niyam doctor no longer warns about a hook that builds its gh in the positional parameters and runs it as "$@". Such a hook runs set -- gh, then, where niyam's launcher is, set -- "$agent" as-agent --session "$session" -- gh. Its plain set -- gh is the cloud's fallback, which the proxy authenticates, so it is not counted. Every other gh is still named, and so is set -- gh with no as-agent form beside it.

Why. On 2026-11-21, doctor 0.7.12 in athya_mono warned that .claude/hooks/sarathi-install.sh "reaches GitHub outside as-agent, so gets 401". The script does route its gh through as-agent on the Mac:

  • hooksHittingLock drops each command naming as-agent, and that dropped the reassignment.
  • It kept set -- gh, which GH matches.
  • "$@" api names no gh.

This is a fix under P-43 (#116), as #211 was for the same check, so the slice's approval carries it (P-40).

Shape:

  • withoutRoutedSetGh in src/as-agent.ts drops set -- gh commands only when the same judged text has set -- … as-agent … -- gh.
  • It runs after the cloud-only cut, so on a Mac an as-agent form past a cloud-only exit excuses nothing.
  • Rejected: taking the whole script as routed, as routedByHelper does. That would pass a plain gh beside it.

Tests:

  • src/as-agent.test.ts, the athya_mono shape: not named. With a plain gh api added: named. Also named: set -- gh alone; set -- gh; gh api x on one line; an as-agent form only past a cloud-only exit (on a Mac). The then … else set -- gh form: not named.
  • src/doctor.test.ts, on a Mac and in a cloud session: no ā–² for the routed hook, and a ā–² once a plain gh api is beside it.

README ("Hooks that call GitHub") and a Record in docs/decisions.md say so.

Evidence:

  • Replayed hooksHittingLock on athya_mono's own .claude/settings.json, .claude/sarathi.json and the scripts they run, read from GitHub at main on 2026-11-21.
    • On a Mac, before: ['.claude/settings.json SessionStart hook .claude/hooks/sarathi-install.sh'].
    • On a Mac, after: [].
    • In a cloud session, scripts/cloud/session-start.sh is still named, as before; that is a separate, unchanged verdict.
  • pnpm check: exit 0. src/as-agent.test.ts and src/doctor.test.ts gave 125 pass, 0 fail. test:scripts gave 133 pass, 0 fail, with coverage 100% lines and 97.24% branches. Typecheck, lint, pins, pariksha, hooks:check, build and smoke all passed.

After merge: a release (0.7.13). Then niyam doctor in athya_mono drops the ā–². Nothing in athya_mono changes.

šŸ¤– Generated with Claude Code


Summary by cubic

niyam doctor no longer warns about a hook that builds its gh in the positional parameters and runs it as "$@", when the hook also routes through as-agent via niyam's launcher. Such a hook runs set -- gh, then set -- "$agent" as-agent --session "$session" -- gh; its plain set -- gh is the cloud's fallback, which the proxy authenticates, so it is not counted.

  • Runs withoutRoutedSetGh, which drops set -- gh only when the same judged text has an as-agent form, looked for after the cloud-only cut so a form past that exit on a Mac excuses nothing.
  • Keeps every other gh, set -- gh alone, and a set -- gh that runs a command substitution like set -- gh "$(gh api x)", whose nested gh stays named.
  • Rejected taking the whole script as routed, as routedByHelper does; that would pass a plain gh beside it.