Skip to content

T197: A sage agent never runs gh in any form: copy, link or alias #70

Closed

Description

@erickb336

Paths updated after #56 merged (2026-10-06). Sources now live in packages/; plugins/sage/ is build output (never edit it; npm run check fails on a hand edit). Hook: packages/sage-claude/hooks/sage-hook.mjs. State tool logic: packages/sage-core/state.mjs (the Claude wrapper is packages/sage-claude/skills/sage/sage.mjs). Skills and agents: packages/sage-claude/skills/, packages/sage-claude/agents/. Line numbers in this issue are from before the move.

Task: T197 · small · risk flag: auth (needs 2 clean review cycles) · build after #57 (T199), same code

Goal

A sage agent never runs gh in any form: by its path, a copy, a link, a shell alias, a PowerShell alias, a git alias or a gh alias. Only the main session runs gh.

Why

The hook's merge and push rules look for the words gh, merge, git and push in one command line. Two commands defeat them. A security review of PR #33 found these allowed for an agent:

  • cp "$(command -v gh)" /tmp/x, then /tmp/x pr merge 41 --squash --delete-branch --match-head-commit <sha> (also /tmp/x*)
  • Set-Alias m gh, then m pr merge 41 ...
  • a git alias or a gh alias set from a config file write, then git m or gh m 41 ...

With a logged-in gh, each is a real merge by an agent. The hook already resolves the real program of a command for its process rule (programsRun, used by agentProblem), so it can do the same for gh.

Scope

  • packages/sage-claude/hooks/sage-hook.mjs: in the agent rule (agentProblem), refuse a run of gh by its resolved program: the name gh, any path whose file is gh, and any file that is the same file as the real gh on PATH (compare device and inode). Refuse alias, Set-Alias, New-Alias, git config alias.* and gh alias set from an agent when the text names gh.
  • Implementers today open their pull requests with gh pr create. Keep that working: allow an agent's gh pr create, gh pr view, gh pr comment, gh pr edit, gh pr checks, gh issue view and gh api with a GET only, in their plain form; refuse every other gh form for agents. List the forms in the refusal text.
  • Tests in scripts/sage-hook.test.mjs. Never run the real gh in a test: use a fake file on a fake PATH.

Acceptance

  • Each example above is refused for an agent; the allowed forms pass; the main session is unchanged.
  • The new tests fail on main and pass on the branch.
  • npm run build, npm run check, npm test pass.

How this hand-off works

  • This issue is a task of sage, the agent kit in this repository. The sage keeps its own record of the task (its logbook) under the id in the title.
  • Work on a new branch named codex/<task id in lower case>-<short name>, for example codex/t199-brace-words.
  • Open a pull request whose title ends with the task id in parentheses, for example (T199). Start its body with Closes #<this issue> and Sage task <id>.
  • The sage then runs its reviews (code, security when the task has a risk flag, and QA) and merges when the review cycles are clean. Never merge, never push to main, never force-push.
  • In the pull request body, give the evidence: the commands you ran and their last lines (the test counts), and say what you did not check.

Rules for every sage task

  1. Read AGENTS.md first. Edit only sources; never edit a generated file (a skill marked "Generated", or instructions/core.md), and never edit upstream/pstack/ by hand.
  2. Run npm run build, then npm run check and npm test. All must pass. The full test run can take over 5 minutes.
  3. A rule that matters goes into code with a test. Show that each new test fails on main and passes on your branch: check out main in a separate worktree (git worktree add --detach <tmp> origin/main), never with git stash.
  4. Never let any code you run read or signal the real process list. Put a fake ps, pgrep and kill first on PATH for every test run.
  5. Never pass a test string to a real shell (bash, zsh, sh, eval, child_process with shell: true). Attack strings go to the hook's parser only.
  6. A flaky test is a bug: fix it or remove it in the same task. Never re-run a test until it passes. No assertion on wall-clock or CPU time unless it has a wide margin and a reason in the test.
  7. The README graphics come from scripts/graphics.mjs (npm run graphics); never edit an SVG in docs/assets by hand.
  8. Write text for people at about 80% of Simplified Technical English (writing/ste-80.md), with the approved words of writing/dictionary.md.
  9. Stop at a product question: write it in the pull request with your recommendation instead of guessing.

Activity

  1. added
    codex
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions