chore: wire work-repo kg.mjs prime in SessionStart hook#33
Closed
dafilipaj wants to merge 3 commits into
Closed
Conversation
Adds a SessionStart hook that invokes the productiveio/work knowledge graph's prime command with --topic=ai-harness. Surfaces the AI-harness knowledge cluster (ai-agent/knowledge principles + conventions) when starting Claude Code sessions in this repo — CLI tools for Claude workflows benefit from the same principles. The hook is graceful: `|| true` makes it a silent no-op if the productiveio/work clone isn't reachable at ../../scripts/kg.mjs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The hook hard-coded ../../scripts/kg.mjs, which only resolves correctly when the repo is opened at repos/<name>/. From a worktree at repos/<name>-worktrees/<branch>/ (or worktrees/<name>-<branch>/ at the project root) the path missed by one level and the hook silently no-oped because of the `|| true` safety net. Walk up from $PWD looking for scripts/kg.mjs with knowledge-graph.json as a sibling guard. Works at any depth, still exits cleanly when no kg.mjs is found upward. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Walk now stops at $HOME (or /) instead of always at /, tightening the
code-exec surface to user-controlled territory.
- Replaced `exec node ...; true` with `{ node ...; break; }` so that a
found-but-failing kg.mjs exits 0 (via break + trailing `true`), matching
the description's claim of "graceful" behavior.
Verified locally: scenarios A (kg reachable), B (not reachable), and
C (kg.mjs throws non-zero) all exit 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Prodiskutirali smo, cilj je da hookovi butu opt-in. Zatvaram za sada. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a SessionStart hook that runs the
productiveio/workknowledge graph'sprime --topic=ai-harnesswhen Claude Code sessions start in this repo. Surfaces ai-agent's principles and conventions (32+ docs covering ZFC, token economy, tool boundaries, instruction layering, etc.) — directly applicable to authoring marketplace skills and agents here.How it works
The hook walks up from
$PWDlooking for a directory containing bothscripts/kg.mjsandknowledge-graph.json— i.e. aproductiveio/workclone. On the first match it runsnode $d/scripts/kg.mjs prime --topic=ai-harness 2>/dev/null(stderr suppressed), then breaks out of the loop.The walk stops at
$HOME(or/, whichever comes first) so it can't traverse system roots, and the{ node ...; break; }form keeps the hook graceful even ifkg.mjsitself fails —breakexits 0 and the trailingtruecatches the loop fall-through, so a found-but-failingkg.mjswon't error out the session.If no
productiveio/workclone is found in the walk, the loop falls through totrue— sessions stay healthy when it isn't cloned nearby.Sample output
Companion PRs
repo-knowledge-docnode type and topic detectionTest plan
Start a new Claude Code session in a worktree of this repo (with
productiveio/workcloned nearby) and confirm the topic block appears.Confirm the hook is graceful when
productiveio/workis not nearby — start a session in a folder outside any clone (e.g./tmp); session should start cleanly with no error.Manually run the exact shipped command and confirm exit 0:
bash -c 'd=$PWD; while [ "$d" != "$HOME" ] && [ "$d" != "/" ]; do [ -f "$d/scripts/kg.mjs" ] && [ -f "$d/knowledge-graph.json" ] && { node "$d/scripts/kg.mjs" prime --topic=ai-harness 2>/dev/null; break; }; d=$(dirname "$d"); done; true'Generated with Claude Code