KeiSeiKit-1.0/hooks
Parfii-bot a31a056f61 feat(graph): live runtime DNA viewer — kei-graph-export + lbm-graph-viz adapter
User pushback: "можно нашего Кейси подключить к обсидиан? будет в
онлайне строить граф из всех наших агентов?"

Closer-to-question architecture: don't build new Obsidian plugin —
re-use the legacy `~/Projects/lbm-graph-viz/` D3 viewer (lineage:
keicode → living-graph → lbm → lbm-graph-viz → keisei-graph). Strip
its Hebbian/co-change edges, replace with DNA-derived edges from the
kei-registry + kei-ledger. Open in any browser, file://...index.html.

NEW Rust crate `_primitives/_rust/kei-graph-export/` (~440 LOC, 5 files)

Reads:
  ~/.claude/registry.sqlite       (730 active blocks)
  ~/.claude/agents/ledger.sqlite  (6 agents post-cleanup)
  _manifests/*.toml               (38 agent manifests)

Emits 581-node, 291-edge graph. Edge types:
  block_dep        171  manifest → atom (blocks=[])
  path_ref          99  manifest → atom (path:NAME refs)
  branch_lineage    11  parent_branch → branch
  agent_uses_manifest 10  agent → manifest (slug from branch name)

Output formats:
  --format spaces-fragment  →  `window.RUNTIME_SPACE = {...}` JS file
  --format json             →  raw {nodes, links} for downstream tools

Block-name lookup is multi-resolution: each block is registered under
display name + lowercased + file-stem slug (from path basename) so
manifest references like `blocks = ["baseline"]` resolve to a registry
row whose `name` column holds "BASELINE — inherit from Main Claude".
Without this fix the graph had 0 block_dep edges; with it, 171.

NEW background updater `hooks/graph-export-watcher.sh` + launchd plist
template `_primitives/templates/io.keisei.graph-export.plist`

5-second loop:
  while true; do
      kei-graph-export --format spaces-fragment --output <viz>/data-runtime.js.tmp
      mv <viz>/data-runtime.js.tmp <viz>/data-runtime.js  # atomic
      sleep 5
  done

launchd plist substitutes `HOME_DIR` and `HOOKS_DIR` placeholders at
install time. RunAtLoad=true, KeepAlive=true. Logs to
~/.claude/memory/graph-export.log. Bypass: GRAPH_EXPORT_BYPASS=1.

Loaded into user-side launchd (PID 16474 confirmed running). File
mtime advances every 5s — live updates verified.

PATCH `~/Projects/lbm-graph-viz/index.html` (outside kit, surgical)

Three changes:
  1. Add `<script src="data-runtime.js">` BEFORE `spaces.js` (window
     global available when SPACES is defined).
  2. After spaces.js: `if (window.RUNTIME_SPACE) SPACES.runtime = window.RUNTIME_SPACE;`
  3. Auto-refresh setInterval(5s): fetch data-runtime.js, eval (re-
     assigns window.RUNTIME_SPACE), hash-compare, re-render via
     `rebuildGraph()` if currently viewing the runtime space.

window.RUNTIME_SPACE (not const RUNTIME_SPACE) avoids the
"const cannot be re-declared" error on subsequent eval() calls.

Effect: open file://~/Projects/lbm-graph-viz/index.html in any
browser, switch to "Runtime" space — full DNA graph of every agent /
atom / skill / branch / manifest / hook / primitive / rule, force-
laid-out by D3. Updates every 5 seconds without page reload.

What this does NOT do (deferred):
  - Obsidian mirror — separate work, would emit .md per node into
    ~/Projects/KeiSeiVault/. Useful for backlinks navigation but
    file-watcher latency similar to current 5s polling.
  - Skill-invocation edges — table is empty until next Skill tool
    use; will populate naturally.
  - Scoped queries (orphan finder, hot-path PageRank). Out of scope
    for v1; the JSON --format export feeds any downstream tool.
  - `agent_uses_manifest` heuristic warns on unknown subagent slugs
    (e.g. `physics-deriver` with no manifest yet). Non-fatal.

=== STATUS-TRUTH MARKER ===
shipped: functional
stubs: 0
cargo-check: PASS
behaviour-verified: yes
follow-up-required:
  - Obsidian vault mirror (Phase C, separate work)
  - Skill-edges populate from real Skill use (not blockered)
  - Hot-path PageRank highlighting in viewer (cosmetic)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 13:07:21 +08:00
..
_lib KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
affect-live-scan.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-capability-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-capability-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-fork-done.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-fork-logger.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-heartbeat-tick.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
agent-outcome-backfill.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
agent-stub-scan.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
alignment-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
assemble-agents.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
assemble-validate.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
auto-dev-guard.sh feat(frontend-loop): kei-db-contract primitive + frontend-validator agent + auto-dev-guard hook 2026-05-01 15:34:39 +08:00
auto-encyclopedia-refresh.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
auto-register-on-edit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
block-dangerous.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
check-error-patterns.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
citation-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
decompose-rules-on-edit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
destructive-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
disk-headroom-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
disk-reclaim.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
error-spike-detector.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
extract-task-durations.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
graph-export-watcher.sh feat(graph): live runtime DNA viewer — kei-graph-export + lbm-graph-viz adapter 2026-05-02 13:07:21 +08:00
hooks.json feat(frontend-loop): kei-db-contract primitive + frontend-validator agent + auto-dev-guard hook 2026-05-01 15:34:39 +08:00
milestone-commit-hook.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-downgrade.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-hand-edit-agents.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
no-python-without-approval.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
numeric-claims-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
numeric-claims-record.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
orchestrator-branch-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
orchestrator-dirty-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
phase-b-rem.sh feat(sleep): cloud-agent reasoning + Telegram delivery to whitelist 2026-05-02 04:38:52 +08:00
post-commit-audit.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
post-write-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
recurrence-suggest.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
rust-first.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
safety-guard.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
session-end-dump.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
site-wysiwyd-check.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
skill-record.sh feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
sleep-report-tg.sh feat(sleep): cloud-agent reasoning + Telegram delivery to whitelist 2026-05-02 04:38:52 +08:00
stop-verify.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
task-timer.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
tomd-preread.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00