feat(knowledge): warn at write time when a note lands off-schema - #1687
Open
elhoim wants to merge 3 commits into
Open
feat(knowledge): warn at write time when a note lands off-schema#1687elhoim wants to merge 3 commits into
elhoim wants to merge 3 commits into
Conversation
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.
RebuildKnowledgeSchema (danielmiessler#1685) keeps _schema.md honest against KnowledgeSchema.ts, so the DOC can no longer drift from the CODE. Nothing checks whether the NOTES conform to either. That gap is how an archive reached 0.9% conformance without a single warning: a bulk import wrote 1,744 notes off-schema, later writers copied their frontmatter and spread the dialect, and KnowledgeLint — the one tool that could have said so — is invoked by nothing in the tree. It only ever runs when a human remembers to type it. Add a read-only conformance check alongside the regen. It calls validate() from KnowledgeSchema directly rather than shelling out, reports a percentage plus the top violation classes, names the repair command (MigrateKnowledge.ts), and emits a typed event for Pulse. Reports only. Never edits, never blocks — non-conformance is a soft warning, matching MemoryDirIntegrity's contract. Verified on a 1,801-note archive: reports 100.0% clean, and a deliberately downgraded note is caught as '1x convention — not kb-v3'. Stacks on danielmiessler#1685.
MemorySystem.renderInitialNote is the sanctioned way a note is born on the schema, but nothing prevents a writer from bypassing it. A bulk import did exactly that and wrote 1,744 notes off-schema; every writer afterwards read a neighbouring note, copied its frontmatter, and spread the legacy dialect further. The convention was documented and unenforced. danielmiessler#1686 reports the damage on the Stop pass. This reports it at the write, while the author is still in the loop and the fix is one edit instead of a migration. Advisory only. Emits additionalContext naming the violations and pointing at renderInitialNote; never blocks, because the note is already on disk by PostToolUse and a hard gate on note-writing would be worse than the drift. Silent for every path outside MEMORY/KNOWLEDGE/<Type>/*.md, including _index.md and _schema.md. Verified: silent on a conformant note, silent on _schema.md, _index.md and a settings.json path, and on a note downgraded to kb-v2 it emits the violation plus the repair route. Stacks on danielmiessler#1686.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacks on #1686. That PR reports non-conformance on the Stop pass. This one reports it at the write, while the author is still in the loop and the fix is one edit rather than a migration.
Why a write-time signal
MemorySystem.renderInitialNoteis the sanctioned way a note is born on the schema. Nothing prevents a writer from bypassing it.A bulk import did exactly that and wrote 1,744 notes off-schema. Every writer afterwards read a neighbouring note, copied its frontmatter, and spread the legacy dialect further — including, on the archive where this was found, two agents that were explicitly trying to match house style. Copying a sibling is the intuitive move, and it is precisely the wrong one.
The convention was documented and unenforced. This is the smallest thing that makes it visible at the point of failure.
Contract
additionalContextnaming the violations and pointing atrenderInitialNote.PostToolUse, and a hard gate on note-writing would be worse than the drift it prevents.MEMORY/KNOWLEDGE/<Type>/*.md, including_index.mdand_schema.md.KnowledgeSchema.validate()— one file, no subprocess.Verified
_schema.mdIdeas/_index.mdsettings.jsonpathconvention: kb-v2The warning it emits:
The set
Four PRs close this end to end: #1684 fixes a rule that could never be satisfied, #1685 stops the doc drifting from the code, #1686 makes note-level drift visible, and this makes it visible at the moment it happens.