Skip to content

feat: OKF export + KG graph visualizer + KG-graph-health (P6/P1/P5)#222

Merged
wtthornton merged 7 commits into
mainfrom
enhance-okf-graphviz-p5
Jul 8, 2026
Merged

feat: OKF export + KG graph visualizer + KG-graph-health (P6/P1/P5)#222
wtthornton merged 7 commits into
mainfrom
enhance-okf-graphviz-p5

Conversation

@wtthornton

Copy link
Copy Markdown
Owner

Reconciled onto current main (3.25.0) after finding the original work was built on a 3-versions-stale base.

What's here

  • P6 — OKF export: --layout okf on brain_export (frontmatter-first concept docs + reserved index.md/log.md). Makes any brain a spec-conformant OKF producer.
  • P1 — KG visualizer: build_kg_graph serializer + GET /snapshot/graph (1-hop focus star, edge confidence/status/contradicted/stability/evidence) + a Cytoscape.js dashboard panel (vendored, offline/CSP-safe).
  • P5 — KG-graph-health: build_kg_health scorer + graph_health_counts aggregate SQL + GET /snapshot/graph/health (orphan/stale/contradicted ratios, ok/warn/degraded) + a dashboard "Health" readout. Carve-out after confirming the memory-store freshness/GC scorecard already shipped upstream — this adds only the KG-graph rot it doesn't measure.

Verification

  • ruff + mypy-strict clean; 307 unit tests pass (targeted suites); OpenAPI contract regenerated (drift gate green).
  • DB-only pieces (graph_health_counts SQL) are covered by a requires_postgres integration test that CI runs against ephemeral Postgres — validating the SQL against a real schema.
  • Frontend (Cytoscape panel) is node --check-clean but not browser-run in this session (no Playwright smoke).

🤖 Generated with Claude Code

wtthornton and others added 7 commits July 8, 2026 13:39
Add `--layout okf` to brain_export: frontmatter-first concept docs (non-empty
`type` from tier, JSON-encoded string scalars so arbitrary values stay
parseable YAML, READ-ONLY banner moved into the body) plus reserved bundle-root
index.md (grouped by tier, relative links, okf_version) and log.md (ISO date
headings, newest first). Redaction and secret-tag skipping are shared with the
managed-agents path; manifest gains okf_version. Makes any brain a
spec-conformant OKF producer, viewable in OKF's own visualizer.

5 new unit tests cover frontmatter-first conformance, YAML safety on
colon/quote values, reserved index/log structure, redaction, and manifest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…izer (P1 backend)

Add the backend for the knowledge-graph visualizer panel. build_kg_graph
(visual_snapshot.py) is a pure transform of a 1-hop get_neighbors result into a
{nodes, edges} star graph, carrying the signals that make the KG richer than a
plain hyperlink graph: edge confidence, status, contradicted, stability (FSRS
decay), evidence_count. A correct 1-hop star (expand-on-click re-roots on a
neighbour) is the right primitive — multi-hop rows lack the subject side, so a
2-hop dump would draw wrong edges.

GET /snapshot/graph?entity=<uuid>&limit=<n> (X-Project-Id header) composes the
already-tested kg_service.get_neighbors + _validate_uuid_field with the
serializer. 6 new unit tests cover the serializer (dedup, signal mapping,
contradicted/stale, missing fields, empty).

Follow-up before release: a DB-gated integration test for the endpoint against a
live KG (the serializer — where the logic lives — is fully unit-tested here).
Frontend Cytoscape panel is the next P1 increment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make /snapshot/graph accept the project via ?project= query (falling back to the
X-Project-Id header) so the dashboard calls it like GET /snapshot. Add TestClient
coverage for every branch — 400 (no project), 422 (bad entity UUID), 503 (no KG
configured), and the success path (monkeypatched KG service → {nodes, edges}) —
plus an OpenAPI-presence check. Regenerate the OpenAPI contract snapshot for the
new route (openapi.json + openapi-3.22.0.json) so the drift gate stays green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Re-apply the KG visualizer panel onto the current (EPIC-078) dashboard. Adds a
"Graph" page rendering GET /snapshot/graph with vendored (offline, CSP-safe)
Cytoscape.js: edge opacity/width = confidence, red-dashed = contradicted,
dotted/faded = stale/superseded, focus node ringed. Click a neighbour to
re-centre (1-hop expand); click an edge for predicate/confidence/status/
stability(decay)/evidence. KPI tiles, legend, entity-UUID input, help entry.
XSS-safe IIFE, no bundler — matches dashboard conventions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…cs (P5)

The memory-store diagnostics scorecard (freshness/staleness/GC, shipped in 3.25)
covers memory *entries*, not the KG's typed/evidenced edges. Add the missing
KG-graph-health slice:

- build_kg_health(counts) — pure scorer: orphan_ratio, stale_ratio,
  contradicted_ratio, an ok/warn/degraded status, and actionable
  recommendations (6 unit tests).
- PostgresKnowledgeGraphStore.graph_health_counts() + brain-scoped aggregate
  SQL (orphan entities = active entity with no active edge; edge counts by
  status + contradicted).
- kg_service.graph_health() wrapper; GET /snapshot/graph/health endpoint
  (?project= or X-Project-Id), fully mock-tested (400/503/success/openapi).

Carve-out of the original P5 after reconciling with 3.25.0: the general
freshness/GC recommendations already shipped upstream; this adds only the
KG-specific graph rot they don't measure. build_kg_health + endpoint are unit-
tested; graph_health_counts SQL is DB-gated (needs a live KG to verify).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a "Health" button that fetches GET /snapshot/graph/health and shows the
status (ok/warn/degraded), orphan/stale/contradicted counts + ratios, and any
recommendations in the detail pane — making graph rot visible alongside the
focus view.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Validates the P5 aggregate SQL against a real schema in CI (ephemeral Postgres):
seeds 3 entities (one orphan) + 1 edge, asserts entities_active/orphan_entities/
edge counts. Skips locally when TAPPS_TEST_POSTGRES_DSN is unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wtthornton wtthornton merged commit 92b61fc into main Jul 8, 2026
2 of 3 checks passed
@wtthornton wtthornton deleted the enhance-okf-graphviz-p5 branch July 8, 2026 21:11
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