Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(dashboard): hook-order safety and current-run lesson publication (#753)
FallingLighte7f44d376238
diff --git a/understand-anything-plugin/hooks/auto-update-prompt.md b/understand-anything-plugin/hooks/auto-update-prompt.mdindex 5a7fbb2a..df243e99 100644--- a/understand-anything-plugin/hooks/auto-update-prompt.md+++ b/understand-anything-plugin/hooks/auto-update-prompt.md@@ -100,7 +100,7 @@ node "$PLUGIN_ROOT/skills/understand/finalize-incremental.mjs" "$PROJECT_ROOT"The finalizer performs deterministic graph/layer/tour validation and independently reruns the shared symbol check on the exact graph before writing. It atomically saves `knowledge-graph.json`, patches changed fingerprints while preserving untouched entries, removes deleted fingerprints, and only then writes `meta.json`. A graph-save failure must never advance the fingerprint or commit baseline. If symbol loss is first detected here, follow the same one-retry procedure, rerun merge and any required architecture/tour phases, then finalize; an already-used or unsuccessful repair must stop with the old graph and baselines intact.-After the finalizer exits successfully, publish lessons with the same rules as **Lesson publication** in SKILL.md's incremental save gate: atomically move `$UA_DIR/intermediate/code-lessons.normalized.json` over `$UA_DIR/code-lessons.json` when present; when lessons were attempted but skipped or failed, delete a served `$UA_DIR/code-lessons.json` instead; when the finalizer failed, touch nothing so the previous graph and lessons stay consistent. `PARTIAL_UPDATE` never attempts lessons and leaves the served sidecar untouched.+After the finalizer exits successfully, publish lessons with the same rules as **Lesson publication** in SKILL.md's incremental save gate — only lessons staged by the current invocation: atomically move `$UA_DIR/intermediate/code-lessons.normalized.json` over `$UA_DIR/code-lessons.json` when this run staged it; when lessons were attempted but skipped or failed, delete a served `$UA_DIR/code-lessons.json` instead; when the finalizer failed, touch nothing so the previous graph and lessons stay consistent. `PARTIAL_UPDATE` never attempts lessons and leaves the served sidecar untouched.Report:diff --git a/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx b/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsxindex 2e02e4f0..bbdc8e2a 100644--- a/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx+++ b/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx@@ -298,6 +298,22 @@ export default function CodeViewer({?.scrollIntoView({ block: "center", behavior: "smooth" });};+ // Nullable-safe derived view state — must stay above the `if (!node)`+ // early return so the component's hook order cannot change when the+ // selected node appears or disappears (review: hook-order crash).+ const source = state.source;+ const language = source?.language ?? fallbackLanguage(node?.filePath);+ const isMarkdown = language === "markdown";+ const showRendered = isMarkdown && mdView === "rendered";++ // Scroll to the selected lesson range after the source lines mount+ // following a Rendered → Source switch (review #4). Only reacts to+ // view-mode switches; direct selection scrolls synchronously in+ // toggleSection, so the deps intentionally cover showRendered only.+ useEffect(() => {+ if (!showRendered && lessonHighlight) scrollToLine(lessonHighlight.start);+ }, [showRendered]);+if (!node) {return (<div className="h-full w-full flex items-center justify-center bg-surface">@@ -306,10 +322,6 @@ export default function CodeViewer({);}- const source = state.source;- const language = source?.language ?? fallbackLanguage(node.filePath);- const isMarkdown = language === "markdown";- const showRendered = isMarkdown && mdView === "rendered";const lineInfo = highlightedRange? `${t.codeViewer.lines} ${highlightedRange.start}-${highlightedRange.end}`: t.codeViewer.fullFile;@@ -333,14 +345,6 @@ export default function CodeViewer({}};- // Scroll to the selected lesson range after the source lines mount- // following a Rendered → Source switch (review #4). Only reacts to- // view-mode switches; direct selection scrolls synchronously in- // toggleSection, so the deps intentionally cover showRendered only.- useEffect(() => {- if (!showRendered && lessonHighlight) scrollToLine(lessonHighlight.start);- }, [showRendered]);-return (<div className="h-full w-full flex flex-col bg-surface overflow-hidden"><div className="flex items-start gap-3 px-4 py-3 bg-elevated border-b border-border-subtle shrink-0">diff --git a/understand-anything-plugin/skills/understand/SKILL.md b/understand-anything-plugin/skills/understand/SKILL.mdindex 3e472a68..9444d106 100644--- a/understand-anything-plugin/skills/understand/SKILL.md+++ b/understand-anything-plugin/skills/understand/SKILL.md@@ -676,11 +676,12 @@ node "<SKILL_DIR>/finalize-incremental.mjs" "$PROJECT_ROOT"This helper validates/deduplicates nodes and edges, reconciles layers/tour, and independently reruns the shared symbol validator on the exact graph to be saved. It then atomically saves the graph, patches only changed fingerprints while preserving all others, removes deleted fingerprints, and only then advances `meta.json`. A cached successful merge report cannot bypass the save check. If symbol loss is first detected here, use the same one-retry procedure above, rerun merge and any required architecture/tour phases, then finalize again; if the retry was already used or remains unresolved, **STOP** with the old graph and baselines intact.-**Lesson publication.** `$UA_DIR/code-lessons.json` is only ever written after the graph/tour it describes is saved:+**Lesson publication.** `$UA_DIR/code-lessons.json` is only ever written after the graph/tour it describes is saved, and only from lessons staged by the current invocation:-- If the finalizer exits successfully and `$UA_DIR/intermediate/code-lessons.normalized.json` exists, atomically move it over `$UA_DIR/code-lessons.json`.+- If this run attempted lessons, the finalizer exited successfully, and this run's staged `$UA_DIR/intermediate/code-lessons.normalized.json` exists, atomically move it over `$UA_DIR/code-lessons.json`.- If this run attempted lessons and they were skipped or failed (no staged document) while `$UA_DIR/code-lessons.json` exists, delete it — stale lessons with `tourOrder` badges for a rebuilt tour must not survive.- If the finalizer fails (**STOP**), touch nothing: the previous `$UA_DIR/code-lessons.json` stays beside the previous graph and tour.+- If this run never attempted lessons — review-only `--review` reruns that skip Phase 5 and scratch cleanup, for example — leave `$UA_DIR/code-lessons.json` untouched, even when a staged document left behind by an earlier interrupted run is present; abandoned staged lessons must not be published beside a saved tour.- `PARTIAL_UPDATE` never attempts lessons (it keeps the existing file untouched — see the Code Lessons section above), so with no staged document the served sidecar stays as-is.- Without `--review`, report the incremental summary and **STOP**. Do not run Phase 6 or the full-save Phase 7; this is what prevents the ordinary local update from paying for whole-graph review.@@ -858,7 +859,7 @@ Report to the user: `[Phase 7/7] Saving knowledge graph...`1. Write the final knowledge graph to `$UA_DIR/knowledge-graph.json`.- Then publish lessons under the same rules as **Lesson publication** in the incremental save gate: if `$UA_DIR/intermediate/code-lessons.normalized.json` exists, atomically move it over `$UA_DIR/code-lessons.json`; if lessons were attempted but skipped or failed, delete a served `$UA_DIR/code-lessons.json` instead so no stale sidecar survives beside the new graph and tour.+ Then publish lessons under the same rules as **Lesson publication** in the incremental save gate — only when this run executed the Code Lessons step: if this run staged `$UA_DIR/intermediate/code-lessons.normalized.json`, atomically move it over `$UA_DIR/code-lessons.json`; if lessons were attempted but skipped or failed, delete a served `$UA_DIR/code-lessons.json` instead so no stale sidecar survives beside the new graph and tour. On runs that skipped Phase 5 (e.g. `--review` reruns on the same commit), leave `$UA_DIR/code-lessons.json` untouched — an abandoned staged document from an earlier interrupted run must not be published.2. **Generate structural fingerprints baseline.** This creates the basis for future automatic incremental updates and **must succeed before `meta.json` is written** — otherwise auto-update sees a fresh commit hash with no fingerprints to compare against, classifies every file as STRUCTURAL, and escalates to `FULL_UPDATE` on every subsequent commit (issue #152).