Repository navigation
feat: add setup hooks for agent session integration - #41
Conversation
Principle 7 asks a tool to make its context ambient through the agent's own session hooks. axi-sdk-js ships installSessionStartHooks for exactly that and this tool did not call it, so every agent had to be told about forgejo-axi by hand. setup hooks writes the SessionStart registration for Claude Code, Codex and OpenCode. It contacts no host and reads no credential, so it works before the CLI is configured -- which is when a first-time user runs it. Rerunning is a no-op, so it is the repair path as well as the install path. The SDK declines silently when the entry point is not an installed forgejo-axi binary: a dev checkout, a bundler, some other runner. That refusal is right, but reporting it as a successful install would be a confident lie about a file that was never written. So the command asks the SDK's own shouldInstallHooksForNodeAxiExecPath first and reports installed:false with the entry point and a reason instead. A target that genuinely could not be written is a SETUP_FAILED error and exit 1, never a quiet exit 0. MainOptions gains an optional execPath, defaulting to argv[1], so the tests can drive both outcomes the way they already drive stdout, stdin and env.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe CLI adds local SessionStart hook installation for Claude Code, Codex, and OpenCode. It also adds ordered field selection for pull request, issue, and workflow-run detail views. ChangesSetup hooks
Detail field selection
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: 🔵 Low · up to The new command registers forgejo-axi across Claude, Codex, and OpenCode configuration files. If installation fails partway through or is interrupted, the environments may be left in different states, so owners should confirm that rerunning reliably repairs every target; otherwise the PR is mergeable with that follow-up awareness. Sequence Diagram(s)sequenceDiagram
participant CLI
participant SDKHookInstaller
participant AgentConfigFiles
CLI->>CLI: validate execPath and arguments
CLI->>SDKHookInstaller: install session hooks
SDKHookInstaller->>AgentConfigFiles: write agent settings
AgentConfigFiles-->>SDKHookInstaller: return write results
SDKHookInstaller-->>CLI: return status or failures
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What this adds
forgejo-axi setup hooks-- the SessionStart hook registration that makes this tool's context ambient in an agent session.Principle 7 asks for exactly this,
axi-sdk-jsshipsinstallSessionStartHooksfor it, and this tool did not call it. Every agent had to be told aboutforgejo-axiby hand.The command writes the registration for Claude Code (
~/.claude/settings.json), Codex (~/.codex/hooks.jsonand~/.codex/config.toml) and OpenCode (~/.config/opencode/plugins/). It contacts no host and reads no credential, so it works before the CLI is configured at all -- which is when a first-time user runs it. Rerunning is a no-op, so it is the repair path as well as the install path.The part I would most like reviewed
installSessionStartHooksdeclines silently when the entry point is not an installedforgejo-axibinary -- a dev checkout, a.tsentry under a loader, some other runner. That refusal is correct and I did not want to defeat it.But a thin wrapper around it would have printed
installed: truewhile writing nothing, which is a confident lie about a file that does not exist. So the command asks the SDK's own exported predicateshouldInstallHooksForNodeAxiExecPathfirst, and when it says no, reports:Exit 0, because that is a definite answer about a supported situation rather than a failure -- the same reading the contract already gives an unsupported capability. A target that genuinely could not be written is different: that is
SETUP_FAILEDand exit 1, with the offending paths indetails.If you would rather the decline be an error, or the predicate call be dropped in favour of trusting the SDK, say so and I will change it -- it is the one judgement call in this PR.
Other notes
setupis registered through the existingdispatchhelper, sosetup --help,setup hooks --help, andUnknown setup command: <x>all behave like the other families for free.MainOptionsgains an optionalexecPath, defaulting toprocess.argv[1]. That is what lets the tests drive both outcomes, the same waystdout,stdinandenvare already injected there. Under vitestargv[1]is the vitest binary, so without this the tests would exercise the decline path only and silently prove nothing about installation.installSessionStartHooksandshouldInstallHooksForNodeAxiExecPathare both in the pinned 0.1.9.Verification
npm run checkpasses: lint, typecheck, 243 tests (237 before, 6 added in a newtest/setup.test.ts), smoke.npm run gen:skillregenerated; the byte comparison incheckpasses.SETUP_FAILEDand exit 1; unknown subcommand exit 2; and both help texts.mkdtempscratchHOME. I also confirmed by hand that my real~/.claude/settings.jsonwas untouched, since a test for a command that writes to the home directory is not one to take on trust.Live lanes: neither was run. This change touches no API request, response handling, or fixture, so
docs/live-test-matrix.mddoes not call for one. Stating it explicitly per CONTRIBUTING.Summary by CodeRabbit
setup hooksto install or repair supported agent session integrations.--fields LIST|allto pull request, issue, and workflow run details.