Skip to content

fix(session-hook): print the version holds outside a git work tree - #83

Merged
realRaghavGupta merged 1 commit into
setkernel:mainfrom
orion-setkernel:agent/80-session-hook-print-the-version-holds
Nov 11, 2026
Merged

realRaghavGupta merged 1 commit into
setkernel:mainfrom
orion-setkernel:agent/80-session-hook-print-the-version-holds

Conversation

@orion-setkernel

Copy link
Copy Markdown
Contributor

Summary

The SessionStart hook (plugins/setkernel/hooks/session-context.sh) used to exit before printing anything when the session's folder was not a git work tree. Fleet seat runs start in a run folder like that, so they never got the version holds from policy/holds.md. Now the hook prints its heading, the org-rules line and the holds wherever the session starts. It adds the branch and working-tree lines only inside a work tree.

What changed

  • plugins/setkernel/hooks/session-context.sh: the heading prints first. The git lines sit inside if cd "$CLAUDE_PROJECT_DIR" && git rev-parse --is-inside-work-tree; then … fi. The org-rules line and the holds print after that in every case. If the cd fails, the hook now treats the folder as outside a work tree: it skips the git lines and still prints the holds. Before, it printed nothing. The hook still always exits 0. If holds.md is missing, it still prints nothing after the org-rules line. Inside a work tree the lines and their order are the same as before.
  • tests/run.sh, next to the existing session-hook tests:
    • in the temp git repo: the working-tree line is printed;
    • in a temp folder that is not a repo (with GIT_CEILING_DIRECTORIES so git can't find a repository above it): the heading, the org-rules line and a hold are printed, and no - Branch or - Working tree line is;
    • with holds.md removed from the test's copy of the repo: the hook exits 0 and prints nothing after the org-rules line.

How it was tested

  • bash tests/run.sh: 798/798 passed. The hook tests call sh, which is dash on this machine (/bin/sh → /usr/bin/dash).
  • The new tests catch the old behaviour. With the old hook put back, 4 new tests failed (177, 178, 179 and 181), as expected.
  • Output inside a repo is unchanged. I ran the old and new hooks in this repo and diffed their output. The only difference was the temp copy of the old script showing up in the working-tree list.
  • sh bin/generate --check: generated files are current.
  • jq empty on .claude-plugin/marketplace.json, plugins/setkernel/.claude-plugin/plugin.json, plugins/setkernel/hooks/hooks.json, managed/settings.json and managed/settings.base.json: all OK.

Not run

  • ShellCheck: not installed on this runner (shellcheck: command not found). CI runs it.
  • SHELL_UNDER_TEST=dash / busybox sh full-suite runs: this sandbox needed approval for them. The hook itself already ran under dash, as noted above.
  • claude plugin validate .: not run. No plugin manifest changed.
  • Live check in a real fleet session: not possible here. The tests run the hook the way Claude Code does, through sh with CLAUDE_PROJECT_DIR set.

🤖 Generated with Claude Code

Closes #80

…etkernel#80)

Fleet runs start in a run folder that is not a repository, and the hook
exited before printing anything there. It now prints the heading, the
org-rules line and the holds wherever it starts, and adds the branch and
working-tree lines only inside a work tree. Output inside a work tree is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lyra-setkernel lyra-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 45323c7.

No blockers. Approving. The hook now prints its heading, the org-rules line and the version holds when the session's folder is not a git work tree. Inside a work tree its output is unchanged. The new tests cover both cases.

What I checked and how

  • Checks: the head has one check run, check, completed with success. That job runs bash tests/run.sh, bin/generate --check, ShellCheck 0.11.0 on plugins/setkernel/hooks/*.sh and tests/run.sh, and the JSON validation (.github/workflows/check.yml).
  • Local run: bash tests/run.sh on head 45323c7 exited 0 with 798 ok lines and no not ok. The new tests are 176–182, and all pass.
  • Diff: I read git diff origin/main...HEAD. It changes 2 files: plugins/setkernel/hooks/session-context.sh and tests/run.sh.

Acceptance criteria (#80)

  1. Outside a work tree: heading, org-rules line and holds, without the branch and working-tree lines. Inside a work tree: output unchanged. Met.
    • Outside a work tree: tests 177–179 check the heading, the org-rules line and typescript-6.0. Test 180 checks that no - Branch or - Working tree line prints. The tests set GIT_CEILING_DIRECTORIES so git can't find a repository above the temp folder.
    • Inside a work tree: in session-context.sh:7-24, the only changes are that the heading echo moved above the work-tree check and the git block is now wrapped in if cd … && git rev-parse …; then … fi. Inside a work tree the same lines print in the same order: heading, branch, working tree, org rules, holds. Tests 174–176 cover this case.
    • I did not diff the old and new hooks' output myself, because running the scripts directly outside the test suite needed sandbox approval. The PR body says the author did that diff.
  2. Always exits 0, and prints nothing extra when holds.md is missing. Met.
    • The script has no set -e and ends with exit 0 (session-context.sh:31).
    • Test 181 checks exit 0 without holds.md. Test 182 checks that nothing prints after the org-rules line.
    • Behaviour change: if cd "$CLAUDE_PROJECT_DIR" fails, the hook now prints the heading, the org-rules line and the holds, where before it printed nothing. That is the right reading of the issue, and the PR body states it.
  3. A test covers both cases in the existing hook test file. Met: tests/run.sh:292-309, next to the existing session-hook tests.
  4. The repo's checks pass. Met: CI check is green, and my local bash tests/run.sh passed 798/798.

Scope, org rules, security (R3: agent runtime)

  • Scope: only the two files the issue names.
  • Test changes: the change to tests/run.sh only adds lines. No existing test is edited or removed.
  • Secrets: none in the diff.
  • Security: the hook still runs only local git and cat. It makes no network calls, and $CLAUDE_PROJECT_DIR stays quoted. After merge, every session that loads the plugin, including fleet run folders, gets the org-rules line and the holds in its context. That is the goal of #80.
  • Untrusted text: the PR text contains no instructions aimed at reviewers.

Not checked

  • I did not run ShellCheck locally (not installed here). CI's ShellCheck step passed.
  • I did not run the suite with SHELL_UNDER_TEST=dash or busybox sh. The hook tests call sh directly, which is dash on this runner.

Nits (non-blocking)

  1. tests/run.sh:306 deletes holds.md from the shared $tmp/copy. Nothing after line 309 uses $tmp/copy today, but a later test that expects a full copy would be surprised. Copying the tree to its own folder for this case would avoid that.
  2. Tests 180 and 182 repeat the env GIT_CEILING_DIRECTORIES=… CLAUDE_PROJECT_DIR=… sh … line inside sh -c instead of reusing hook_out. If the hook path or env changes, the two copies can drift apart.
  3. Test 182 passes without checking anything if the org-rules line is missing: sed '1,/…/d' would delete every line. Test 181 already checks for that line, so the pair holds, but test 182 alone does not.

@vega-setkernel vega-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 45323c7.

No merge blockers. Approving.

What I checked and how

Checks. The head has one check run, check, and it completed with success. That workflow (.github/workflows/check.yml) runs bash tests/run.sh, bin/generate --check, ShellCheck 0.11.0 on plugins/setkernel/hooks/*.sh and tests/run.sh, and jq empty on the JSON files.

Acceptance criteria (#80)

  • Outside a work tree: heading, org-rules line and holds, with no branch or working-tree lines. Inside a work tree: output unchanged. I ran the head hook with CLAUDE_PROJECT_DIR set to an empty folder that is not a repo (GIT_CEILING_DIRECTORIES set). It printed # Session context (setkernel plugin), the org-rules line and the full holds block, with no - Branch or - Working tree line. Under the base hook the same run printed nothing. For "unchanged", I ran the base hook and the head hook against the same target and diffed the output. I used two targets: a temp repo with 18 untracked files, which exercises the 15-line cap and the … 3 more line, and this repo itself. Both diffs were empty. Under dash, the head hook printed the same lines outside a repo.
  • Always exits 0, and prints nothing extra when holds.md is missing. Exit was 0 in every run, including one with CLAUDE_PROJECT_DIR=/nonexistent/x. The cd fails there, so the hook now skips the git lines and still prints the holds. Before, it printed nothing. The hook still ends in exit 0 (plugins/setkernel/hooks/session-context.sh:31). Tests 181–182 cover the missing-holds.md case.
  • A test covers both cases in the existing hook tests. The new tests are in tests/run.sh:292-309, next to the existing session-hook tests. Test 176 covers the temp git repo. Tests 177–180 cover the temp folder that is not a repo. I ran bash tests/run.sh locally: 798/798 passed, with tests 174–182 all ok.
  • The repo's checks pass. CI check passed (see above), and the local suite run matches.

Correctness. The hook now runs the git lines only when cd "${CLAUDE_PROJECT_DIR:-.}" && git rev-parse --is-inside-work-tree succeeds (session-context.sh:9). The holds path is made absolute before that cd (:6), so changing folder can't break it. Moving the heading to the top doesn't change the output order inside a repo, as the diffs above show. Later tests don't use $tmp/copy after holds.md is removed from it (tests/run.sh:306). The test file uses $tmp/copy only at lines 40–132 and 306–309.

Scope. The PR touches two files: plugins/setkernel/hooks/session-context.sh and tests/run.sh. Both are named in the issue's "Files likely touched". In tests/run.sh the PR only adds lines. It doesn't edit or remove any existing test.

Org rules and security (R3, agent runtime). I found no secrets. The hook takes no new input: it still reads only CLAUDE_PROJECT_DIR and the plugin's own policy/holds.md. It runs only local git, with no network. Once merged, every session that starts outside a git work tree will get about 10 more lines of context (the holds block). That is the intended effect. I found no instructions in the PR text aimed at reviewers.

Not checked. I didn't run the suite with SHELL_UNDER_TEST=dash or busybox sh. I didn't run the hook in a live fleet session.

Nits (non-blocking)

  1. Two tests (tests/run.sh:304-305 and :308-309) repeat the full env GIT_CEILING_DIRECTORIES=… CLAUDE_PROJECT_DIR=… sh … line in a sh -c string instead of reusing hook_out. That means three copies of the same invocation can drift apart.
  2. rm "$tmp/copy/plugins/setkernel/policy/holds.md" changes the shared $tmp/copy fixture. Nothing later depends on it today. Making a separate copy would stop a future test from tripping over the missing file.

@realRaghavGupta
realRaghavGupta merged commit 86a4480 into setkernel:main Nov 11, 2026
1 check passed
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.

Session hook: print the version holds outside a git work tree too

4 participants