From 7cfcd4dea831f73551121024c10f8c7b2f58d023 Mon Sep 17 00:00:00 2001 From: elhoim Date: Tue, 28 Jul 2026 07:15:06 +0000 Subject: [PATCH] feat(knowledge): regenerate _schema.md on the doc-integrity pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GenerateKnowledgeSchemaDoc.ts is currently dead code — nothing invokes it. Two consequences: _schema.md does not exist on a fresh install, and where it does exist it drifts from KnowledgeSchema.ts, which is the declared source of truth. That drift is not theoretical. On the archive this was found on, _schema.md declared kb-v3 while describing 0.9% of the notes it governed, and the gap went unnoticed because nothing regenerated the doc. Wire the generator into DocIntegrity so the doc is rebuilt from the schema on every integrity pass. Fire-and-forget, non-fatal on failure, and run as a subprocess rather than imported because the generator executes main() on import. --- LifeOS/install/hooks/DocIntegrity.hook.ts | 7 +++++++ .../hooks/handlers/RebuildKnowledgeSchema.ts | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 LifeOS/install/hooks/handlers/RebuildKnowledgeSchema.ts diff --git a/LifeOS/install/hooks/DocIntegrity.hook.ts b/LifeOS/install/hooks/DocIntegrity.hook.ts index 154235fd46..8c94126211 100755 --- a/LifeOS/install/hooks/DocIntegrity.hook.ts +++ b/LifeOS/install/hooks/DocIntegrity.hook.ts @@ -19,6 +19,7 @@ import { readHookInput, parseTranscriptFromInput } from './lib/hook-io'; import { handleDocCrossRefIntegrity } from './handlers/DocCrossRefIntegrity'; import { handleRebuildArchSummary } from './handlers/RebuildArchSummary'; import { handleMemoryDirIntegrity } from './handlers/MemoryDirIntegrity'; +import { handleRebuildKnowledgeSchema } from './handlers/RebuildKnowledgeSchema'; async function main() { const input = await readHookInput(); @@ -59,6 +60,12 @@ async function main() { console.error('[DocIntegrity] Memory-dir handler failed:', err); } + try { + await handleRebuildKnowledgeSchema(); + } catch (err) { + console.error('[DocIntegrity] Knowledge-schema regen failed:', err); + } + process.exit(0); } diff --git a/LifeOS/install/hooks/handlers/RebuildKnowledgeSchema.ts b/LifeOS/install/hooks/handlers/RebuildKnowledgeSchema.ts new file mode 100644 index 0000000000..2beee6d878 --- /dev/null +++ b/LifeOS/install/hooks/handlers/RebuildKnowledgeSchema.ts @@ -0,0 +1,21 @@ +/** + * RebuildKnowledgeSchema — regenerate `MEMORY/KNOWLEDGE/_schema.md` from + * `KnowledgeSchema.ts` (the pure-data source of truth) on the doc-integrity + * pass, so the schema doc never drifts from the schema and exists on every + * install. Fire-and-forget; a failure is non-fatal (logged by the caller). + * + * Runs the standalone generator as a subprocess rather than importing it, + * because `GenerateKnowledgeSchemaDoc.ts` executes `main()` on import. + */ +import { spawn } from "child_process"; +import { join } from "path"; +import { getLifeosDir } from "../lib/paths"; + +export async function handleRebuildKnowledgeSchema(): Promise { + const generator = join(getLifeosDir(), "TOOLS", "GenerateKnowledgeSchemaDoc.ts"); + await new Promise((resolve) => { + const child = spawn("bun", [generator], { stdio: "ignore" }); + child.on("close", () => resolve()); + child.on("error", () => resolve()); + }); +}