Skip to content

chore: wire work-repo kg.mjs prime in SessionStart hook#33

Closed
dafilipaj wants to merge 3 commits into
mainfrom
chore/wire-kg-prime-hook
Closed

chore: wire work-repo kg.mjs prime in SessionStart hook#33
dafilipaj wants to merge 3 commits into
mainfrom
chore/wire-kg-prime-hook

Conversation

@dafilipaj
Copy link
Copy Markdown
Contributor

@dafilipaj dafilipaj commented May 15, 2026

Summary

Adds a SessionStart hook that runs the productiveio/work knowledge graph's prime --topic=ai-harness when 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 $PWD looking for a directory containing both scripts/kg.mjs and knowledge-graph.json — i.e. a productiveio/work clone. On the first match it runs node $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 if kg.mjs itself fails — break exits 0 and the trailing true catches the loop fall-through, so a found-but-failing kg.mjs won't error out the session.

If no productiveio/work clone is found in the walk, the loop falls through to true — sessions stay healthy when it isn't cloned nearby.

Sample output

Topic 'ai-harness' detected (--topic=ai-harness)
32 repo-knowledge-doc nodes — top 5:
  repo-knowledge:ai-agent/principles/root-cause-first.md — Fix root cause, not the local symptom
  repo-knowledge:ai-agent/principles/token-economy.md — Token economy
  repo-knowledge:ai-agent/principles/tool-boundaries.md — Tools are data conduits
  repo-knowledge:ai-agent/principles/zfc.md — Zero Framework Cognition
  repo-knowledge:ai-agent/architecture/deep-modules.md — Prefer deep modules
  ... 27 more — kg.mjs list --type=repo-knowledge-doc --topic=ai-harness

Companion PRs

  • productiveio/work#287 — adds the repo-knowledge-doc node type and topic detection
  • productiveio/claude-plugins#83 — same hook
  • productiveio/ai-agent#1255 — same hook

Test plan

  • Start a new Claude Code session in a worktree of this repo (with productiveio/work cloned nearby) and confirm the topic block appears.

  • Confirm the hook is graceful when productiveio/work is 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

dafilipaj and others added 3 commits May 15, 2026 12:33
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>
@dafilipaj dafilipaj marked this pull request as ready for review May 19, 2026 13:01
@dafilipaj dafilipaj requested a review from trogulja May 19, 2026 13:01
@dafilipaj
Copy link
Copy Markdown
Contributor Author

Prodiskutirali smo, cilj je da hookovi butu opt-in. Zatvaram za sada.

@dafilipaj dafilipaj closed this May 20, 2026
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.

1 participant