Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Knowledge skill: documented frontmatter contract omits required `id` and `convention` — a note written from SKILL.md can never validate

Open christauff opened this issue 4 months ago • 2 comments

Verified against main @ d1d6240 (fresh read-only clone, this session). Two small things in the Knowledge skill, the second is separable and marked as such.

Both are cheap fixes; filing because the first one makes the documented add path produce an invalid note 100% of the time, which is the kind of thing that quietly erodes archive conformance rather than failing loudly.


1. SKILL.md and KnowledgeSchema.ts disagree on the required field set

LifeOS/install/skills/Knowledge/SKILL.md:105 (the add <type> procedure) states the required frontmatter:

5. Create the note with proper frontmatter from `_schema.md` — schemas require: `title`,
   `type`, `tags` (min 1), `created`, `updated`, `quality` (0-10), plus type-specific
   body sections.

LifeOS/install/LIFEOS/TOOLS/KnowledgeSchema.ts:80-105 defines the envelope, and REQUIRED_KEYS is derived from it:

// KnowledgeSchema.ts:81
{ key: "id",         format: "text", required: true,  query: "stable link target; survives rename" },
// …
// KnowledgeSchema.ts:101
{ key: "convention", format: "text", required: true,  query: "schema-version / migration-state key (kb-v3)" },

// KnowledgeSchema.ts:105
export const REQUIRED_KEYS = ENVELOPE.filter((f) => f.required).map((f) => f.key);

Side by side:

Required per SKILL.md:105 Required per REQUIRED_KEYS (schema)
title, type, tags, created, updated, quality id, type, title, tags, quality, created, updated, convention

id and convention are required by the validator and appear nowhere in SKILL.md — grep -n "convention\|kb-v3\|mintId" skills/Knowledge/SKILL.md returns nothing. convention is also not merely presence-checked; KnowledgeSchema.ts:470 requires the exact value:

if (deq(get("convention")) !== SCHEMA_VERSION) v.push({ key: "convention", problem: `not ${SCHEMA_VERSION} (dialect not migrated)` });

…and id is expected to be a deterministic mint, mintId(slug, created) → kb_<12 hex> (KnowledgeSchema.ts:135-138), which a user hand-writing frontmatter has no way to guess.

The doc points to ~/.claude/LIFEOS/MEMORY/KNOWLEDGE/_schema.md as the authority (SKILL.md:24, :105, :117, :415), but that file isn't shipped or generated on install — that's #1583, and it's why the schema source is currently the only discoverable place these two fields exist. This issue is about the field list itself being wrong even once #1583 is resolved, since the list is also stated inline at :105.

Reproduction

Build the note exactly as SKILL.md:105 specifies and run it through the shipped validator:

// run from LifeOS/install/LIFEOS/TOOLS/
import { parseNote, validate, REQUIRED_KEYS } from "./KnowledgeSchema";

const note = `---
title: Example Idea
type: idea
tags:
  - security
created: 2026-07-27
updated: 2026-07-27
quality: 7
---

# Example Idea
`;

console.log("REQUIRED_KEYS:", REQUIRED_KEYS.join(", "));
console.log(validate(parseNote(note), "example-idea", "idea"));

Actual output:

REQUIRED_KEYS: id, type, title, tags, quality, created, updated, convention
[
  { key: "convention", problem: "not kb-v3 (dialect not migrated)" },
  { key: "id",         problem: "required envelope field missing" },
  { key: "convention", problem: "required envelope field missing" }
]

Expected: zero violations for a note that follows the documented contract.

Suggested fix

Smallest change is to make SKILL.md:105 name the full set and say where id comes from, e.g.:

5. Create the note with proper frontmatter — required: `id` (mint via
   `mintId(slug, created)` from `LIFEOS/TOOLS/KnowledgeSchema.ts` → `kb_<12hex>`),
   `type`, `title`, `tags` (min 1), `quality` (0-10), `created`, `updated`, and
   `convention: kb-v3`. Plus type-specific body sections.

The durable version is to stop restating the list in prose at all: GenerateKnowledgeSchemaDoc.ts already exists and derives from ENVELOPE, so having SKILL.md link to the generated doc rather than hand-maintain a parallel list would keep the two from drifting again on the next schema bump.

One thing I checked so you don't have to: PR #1640 does not resolve this. It wires GenerateKnowledgeSchemaDoc into DocIntegrity, but that generator's OUT is hardcoded to MEMORY/KNOWLEDGE/_schema.md (line 24) and it never touches skills/Knowledge/SKILL.md. So #1640 plus #1583 together would make _schema.md exist and be correct, while SKILL.md:105 still states the wrong six-field list inline.

Two smaller adjacent drifts, same file, if you're touching it anyway

  • SKILL.md:101 says "Validate type is one of: People, Companies, Ideas, Research", and the skill description (:4) and overview (:14) both say "four entity domains". CANONICAL_TYPES has been six since kb-v3 — person, company, idea, blog, research, book (KnowledgeSchema.ts:36, dirs at :40-47). Blogs and Books notes are unreachable through the documented add path.
  • SKILL.md:124-135 lists 8 relationship types; RELATION_VOCAB (KnowledgeSchema.ts:118-121) has 9 — derived-from was added for the source_blog edge and isn't documented.

2. (Separable) KnowledgeLint exits 0 unconditionally, so it can't gate anything

LifeOS/install/LIFEOS/TOOLS/KnowledgeLint.ts has exactly two exit paths and both are process.exit(0):

  • :91 — after the --json report
  • :117 — after the human-readable report

grep -n "process.exit" KnowledgeLint.ts → 91: process.exit(0) / 117: process.exit(0). Nothing in main() reads nonConformant.length or fullyConformant when choosing an exit code; the counts are only ever printed.

That matters because the file's own header describes it as a gate (KnowledgeLint.ts:9-10):

 * Report-only (never edits). Wire it as a write-time hook and a periodic sweep;
 * `MigrateKnowledge.ts` is what fixes what this finds.

A write-time hook, a pre-commit hook, or a CI step can only act on the exit code. As shipped, bun KnowledgeLint.ts && echo ok prints ok with an archive that is 0% conformant. "Report-only" is a reasonable default for the interactive human summary, but right now advisory-only is a property of there being no failure branch rather than a deliberate choice, and there's no flag to opt into strictness.

Interacts with #1 in the unhelpful direction: a user who followed the docs writes non-conformant notes, and the tool positioned to catch that reports the problem while still signalling success to whatever wired it up.

Suggested fix direction

Keep the default at 0 so nothing existing breaks, and add an opt-in gate flag:

const strict = args.includes("--strict");
// …
const failing = total - envelopeConformant;   // envelope axis only; completeness gaps
                                              // are an enrichment signal, not a failure
process.exit(strict && failing > 0 ? 1 : 0);

Gating on the envelope axis rather than full conformance preserves the two-axis split the tool already draws at :44-49 — completeness gaps (required for type …) are honest enrichment debt and shouldn't fail a build, whereas envelope violations mean the schema wasn't applied. A --max-violations N variant would work equally well if you'd rather allow a ratcheting threshold during migration.

If advisory-only is the intended contract, a line in the header block saying so would settle it — the current "wire it as a write-time hook" reads as an invitation to gate.


Versions: Knowledge SKILL.md version: 1.0.13, SCHEMA_VERSION = "kb-v3". Duplicate check run against all open+closed issues for Knowledge, frontmatter, schema, KnowledgeLint — nearest neighbour is #1583 (missing _schema.md), which is a different defect; noted above where the two touch.

Filing as a report rather than a PR, since the README notes the public repo is generated from a private source tree. If a patch is easier to port than a description, say the word and I'll send both sections.

Thanks for moving as fast as you do on this.

christauff avatar Jul 28 '26 02:07 christauff

Three corrections to my own report, from a further verification pass. The two in section 2 are holes in my suggested fix, not in the defect.

1. Misattributed quote. I wrote that the skill description (:4) and the overview (:14) "both say four entity domains." Only :14 uses that phrase; :4 enumerates "People, Companies, Ideas, and Research notes" without it. The substantive point stands — both understate six canonical types as four — but the attribution was wrong.

2. My --strict sketch has two holes.

  • It patches only one of the two exits. I identified both exit points in the body (:91 for --json, :117 for the human report) and then showed the fix at only one. Applied at :117 alone, --json still exits 0 unconditionally — and --json is precisely what a CI step or write-time hook would use, which is the whole case I was making. Compute the code once before the branch and use it at both:

    const code = strict && failing > 0 ? 1 : 0;
    
  • It gates green on an absent archive. listNotes() returns [] for a missing directory (:29), so total = 0, envelopeConformant = 0, failing = 0, and --strict exits 0. That's the fresh-install state, given that #1583 establishes the KNOWLEDGE tree isn't shipped or generated on install — so the gate would pass green on a nonexistent archive, and equally on a mistyped --dir. Needs a total === 0 guard that fails under --strict unless something like --allow-empty is passed.

3. Minor citation fixes. ENVELOPE spans :80-102, with ENVELOPE_KEY_ORDER at :104 and REQUIRED_KEYS at :105 — I bundled all three under ":80-105 defines the envelope." The REQUIRED_KEYS line as shipped carries a type annotation my quote dropped (export const REQUIRED_KEYS: readonly string[] = …). And the _schema.md reference list should include :222 as a fifth site.

The reproduction and the underlying mismatch are unaffected by all of the above — I re-ran the validator repro and it still produces the same three violations in the same order.

christauff avatar Jul 28 '26 02:07 christauff

Doc contract fixed: the skill now documents all eight required fields including id (with the mint recipe) and convention: kb-v3, the domain count is corrected to six, and the relation vocabulary to nine including derived-from. The KnowledgeLint --strict half is a genuine design question — your own follow-up found the --json exit hole and the empty-archive false-green, which is exactly the kind of care that makes these reports easy to act on. That piece stays in the queue.

danielmiessler avatar Jul 29 '26 12:07 danielmiessler