KeiSeiKit-1.0/_primitives/_rust
Parfii-bot 52a02dfbff feat(live-graph): WebSocket activity stream — orchestrator-centric live view
User pushback: "транслирует в онлайне какие агенты создаются? основное
окно агента, а дальше при запусках появляются новые ветки, мы показываем
в онлайне как агенты собираются и работают"

Earlier `kei-graph-export` rendered the static SUBSTRATE (all 581 atoms,
catalog-style). User wanted the LIFECYCLE: orchestrator at center, every
new agent as a fading-in branch, every tool call as a pulse, every
completion as a fade-out. TTL = until done; pure online, no history
accumulation per user direction.

Three-layer architecture, all conforming to schema /tmp/agent-events-schema.md:

LAYER 1 — Event emitters (4 hooks)
  hooks/agent-event-spawn.sh   PreToolUse:Agent  → agent_spawn event
  hooks/agent-event-done.sh    PostToolUse:Agent → agent_done event
                               (parses STATUS-TRUTH MARKER for outcome,
                                computes cost_usd from token×pricing table)
  hooks/tool-use-event.sh      PreToolUse:Bash|Read|Edit|Write|Grep|Glob|NotebookEdit
                               → tool_use event
  hooks/skill-record.sh        EXTENDED — second emit step writes skill_use
                               event in addition to existing kei-ledger
                               record-skill call

  All 4 are POSIX /bin/sh, defensive (never block, exit 0), bypass via
  KEI_EVENTS_BYPASS=1. Append-only JSONL to
  ~/.claude/memory/agent-events.jsonl.

  Smoke: 4 synthetic invocations cover spawn/done/tool/filter cases.

LAYER 2 — kei-graph-stream Rust daemon
  _primitives/_rust/kei-graph-stream/  (~480 LOC, 5 files + 1 test)

  - Tails events.jsonl every 200ms (poll-based, no notify dep).
  - Parses each event, updates AliveState (insert on spawn, remove on done).
  - Broadcasts {"type":"event","data":<event>} to all WebSocket clients.
  - On client connect: sends {"type":"snapshot","alive":[...]} first.
  - Heartbeat: {"type":"ping"} every 30s.
  - axum 0.7 + ws feature (already in Cargo.lock via kei-cortex).
  - Bypass: KEI_GRAPH_STREAM_BYPASS=1.

  Bound to 127.0.0.1:8201 (loopback only). Endpoints:
    GET /stream  → WebSocket upgrade
    GET /health  → "kei-graph-stream alive"

  4 unit + 1 integration test. cargo build clean.

  Installed binary: ~/.cargo/bin/kei-graph-stream
  Launchd plist: io.keisei.graph-stream (RunAtLoad, KeepAlive)
  Loaded as PID 52678, /health 200 OK verified.

LAYER 3 — live-graph.html (single-file frontend)
  ~/Projects/lbm-graph-viz/live-graph.html  (~464 LOC, self-contained)

  - SVG full-viewport, dark #0f172a, CSS grid background.
  - Pinned center node "main" (orchestrator), gold #fbbf24, glowing.
  - Agents radiate via D3 force-simulation; color-by-model
    (sonnet=green, opus=red, haiku=blue, default=gray).
  - On agent_spawn: fade-in 300ms, edge from main to new node.
  - On tool_use: pulse on agent node (r 8→12→8 over 400ms) +
    floating tool name label fades 800ms.
  - On agent_done: outcome-color flash → fade-out 800ms → remove.
  - WebSocket client: ws://127.0.0.1:8201/stream, exponential-backoff
    reconnect (1s→30s).
  - Top-right status badge: ● connected | ○ reconnecting | ✕ disconnected.
  - Bottom counters: alive / spawned / tool calls / done / last event age.
  - No build step. D3 v7 from CDN. Pure HTML+JS+CSS.

End-to-end smoke (this machine, just now):
  - daemon health 200 OK
  - hook injected agent_spawn → daemon broadcasts → AliveState=1
  - hook injected agent_done  → daemon broadcasts → AliveState=0
  - frontend file syntax-checked clean

What this does NOT do (deferred, by user direction "это онлайн"):
  - History persistence — agents who finished are GONE from the graph.
    Per-session log remains in events.jsonl + sleep-sync if user wants
    to consult later, but the live view is RIGHT NOW only.
  - Sub-agent attribution beyond "main" — orchestrator-direct tool calls
    show on the orchestrator node. Sub-agent's internal tool calls would
    need session-id correlation; current schema has agent_id="main"
    placeholder for non-Agent tool calls.
  - Replay mode — no time-scrubber. Possible follow-up if useful.
  - Auth on WebSocket — bound to 127.0.0.1 only. Local-only by design.

=== STATUS-TRUTH MARKER ===
shipped: functional
stubs: 0
cargo-check: PASS
behaviour-verified: yes
follow-up-required:
  - Sub-agent tool-call attribution (correlate session_id chain)
  - Replay mode with time scrubber (if user finds use)
  - Tool aggregator nodes ("Bash bucket" with N) instead of per-agent pulses

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 13:30:24 +08:00
..
firewall-diff KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
frustration-matrix KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-agent-runtime KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-artifact KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-atom-discovery KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-auth KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-auth-apple KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-auth-google KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-auth-magiclink KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-auth-webauthn KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-backend-daytona KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-brain-view KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-cache KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-capability KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-changelog KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-chat-store KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-compute-baremetal KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-compute-digitalocean KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-compute-linode KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-compute-vultr KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-conflict-scan KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-content-store KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-cortex KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-cron-scheduler KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-crossdomain KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-curator KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-db-contract feat(frontend-loop): kei-db-contract primitive + frontend-validator agent + auto-dev-guard hook 2026-05-01 15:34:39 +08:00
kei-decision KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-decompose KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-diff KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-discover KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-dna-index KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-entity-store KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-export-trajectories KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-forge KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-fork KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-frustration-loop KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-gateway KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-gdrive-import KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-git-bitbucket KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-git-forgejo KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-git-gitea KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-git-gitlab KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-graph-check KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-graph-export feat(graph): live runtime DNA viewer — kei-graph-export + lbm-graph-viz adapter 2026-05-02 13:07:21 +08:00
kei-graph-stream feat(live-graph): WebSocket activity stream — orchestrator-centric live view 2026-05-02 13:30:24 +08:00
kei-hibernate KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-import-project KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-leak-matrix KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-ledger feat(tracking): close 3 last observability gaps — toolStats + skill-record + numeric-claims journal 2026-05-02 03:42:09 +08:00
kei-ledger-sign KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-llm-bridge-mlx KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-llm-llamacpp KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-llm-mlx KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-llm-ollama KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-llm-router KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-machine-probe KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-mcp KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-memory chore(kit): wire kei-db-contract into installer + drop final #[path] hack 2026-05-01 17:55:52 +08:00
kei-memory-postgres KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-memory-redis KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-memory-sled KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-memory-sqlite KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-migrate KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-model feat(secrets+catalog): orphan-detector for env vars + image/video/voice models 2026-05-02 00:06:16 +08:00
kei-model-router KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-net-ipsec KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-net-openvpn KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-net-wireguard KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-notify-discord KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-notify-slack KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-notify-sms KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-notify-telegram KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-pet KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-ping KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-pipe KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-projects-index KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-projects-watcher KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-provision KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-prune KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-refactor-engine KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-registry feat(secrets+catalog): orphan-detector for env vars + image/video/voice models 2026-05-02 00:06:16 +08:00
kei-replay KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-router KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-runtime KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-runtime-core KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-sage KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-scheduler KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-search-core KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-shared KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-skill-importer KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-skills KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-social-store KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-spawn KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-store KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-svc-systemd KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-task KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-tlog KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-token-tracker KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-tty KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
kei-watch KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
keisei KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
mock-render KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
ssh-check KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
tokens-sync KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
visual-diff KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
.gitignore KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
Cargo.lock feat(live-graph): WebSocket activity stream — orchestrator-centric live view 2026-05-02 13:30:24 +08:00
Cargo.toml feat(live-graph): WebSocket activity stream — orchestrator-centric live view 2026-05-02 13:30:24 +08:00