@mmnto/totem 1.14.11 → 1.14.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -96,6 +96,21 @@ const CompiledRuleBaseSchema = z.object({
96
96
  * - #1479 Layer 3 security branch rejects outright on verify failure.
97
97
  */
98
98
  immutable: z.boolean().optional(),
99
+ /**
100
+ * ADR-088 Phase 1 Layer 3 (mmnto-ai/totem#1480). True when the rule was
101
+ * compiled from a lesson that lacked an Example Hit block, meaning no
102
+ * ground-truth fixture exists to verify the pattern against. Pipeline 2
103
+ * / Pipeline 3 / Pipeline 1 writers set this when the lesson body carries
104
+ * no `**Example Hit:**` field. Security rules with `immutable === true`
105
+ * or `deps.securityContext === true` are rejected outright rather than
106
+ * shipped unverified (see compile-lesson.ts).
107
+ *
108
+ * Absent (undefined) means the rule is verified. Never write literal
109
+ * `false`; absence preserves pre-#1480 manifest hashes via
110
+ * canonicalStringify — `{unverified: undefined}` and an absent key
111
+ * produce identical output.
112
+ */
113
+ unverified: z.boolean().optional(),
99
114
  });
100
115
  /**
101
116
  * Shared mutual-exclusion check between the flat `astGrepPattern` string
@@ -127,29 +142,92 @@ function refineAstGrepMutualExclusion(data, ctx) {
127
142
  }
128
143
  export const CompiledRuleSchema = CompiledRuleBaseSchema.superRefine(refineAstGrepMutualExclusion);
129
144
  /**
130
- * A non-compilable lesson entry. Pre-#1280 these were opaque hash strings;
131
- * post-#1280 they're {hash, title} tuples for human-readable triage. The
132
- * loader normalizes legacy strings to tuples on read so downstream code only
133
- * ever sees the tuple form.
145
+ * Machine-readable reason for why a lesson could not be compiled into a rule.
146
+ * mmnto-ai/totem#1481 upgraded the `nonCompilable` ledger from opaque 2-tuples
147
+ * to 4-tuples with an explicit reason code so `totem doctor` and downstream
148
+ * telemetry can distinguish outcomes without string-matching.
149
+ *
150
+ * Enum order matches the compile-pipeline exit points (see compile-lesson.ts)
151
+ * followed by the legacy migration sentinel. `'legacy-unknown'` exists only
152
+ * so data written by pre-#1481 compile runs (2-tuple shape) round-trips
153
+ * through the Read schema, up-converts in memory, and re-persists without
154
+ * losing the hash/title pair. Fresh compile runs MUST NOT emit
155
+ * `'legacy-unknown'`; enforcement sits at producers, not the schema.
134
156
  */
135
- export const NonCompilableEntrySchema = z
157
+ export const NonCompilableReasonCodeSchema = z.enum([
158
+ 'no-pattern-generated',
159
+ 'pattern-syntax-invalid',
160
+ 'pattern-zero-match',
161
+ 'verify-retry-exhausted',
162
+ 'security-rule-rejected',
163
+ 'no-pattern-found',
164
+ 'out-of-scope',
165
+ 'missing-badexample',
166
+ 'legacy-unknown',
167
+ ]);
168
+ /**
169
+ * Strict Write schema for `nonCompilable` entries. Every persisted entry
170
+ * carries the 4-tuple `{hash, title, reasonCode, reason?}` shape. Accepts
171
+ * `'legacy-unknown'` so migrated pre-#1481 2-tuples round-trip to disk
172
+ * safely on the first post-upgrade compile; the behavioral invariant that
173
+ * fresh producers never emit `'legacy-unknown'` lives at the call sites,
174
+ * not here.
175
+ *
176
+ * Design precedent: lesson 400fed87 (Read/Write schema invariants). If
177
+ * writes routed through the permissive Read schema, the union-plus-
178
+ * transform pipeline would silently re-accept legacy 2-tuples on every
179
+ * save and the migration would never complete.
180
+ */
181
+ export const NonCompilableEntryWriteSchema = z.object({
182
+ hash: z.string(),
183
+ title: z.string(),
184
+ reasonCode: NonCompilableReasonCodeSchema,
185
+ reason: z.string().optional(),
186
+ });
187
+ /**
188
+ * Permissive Read schema for `nonCompilable` entries. Accepts three shapes:
189
+ * - Legacy string (pre-#1280): just the hash.
190
+ * - Legacy 2-tuple (#1280 to #1481): `{hash, title}`.
191
+ * - Modern 4-tuple (#1481+): `{hash, title, reasonCode, reason?}`.
192
+ * The transform normalizes every shape to the modern 4-tuple. Legacy shapes
193
+ * get `reasonCode: 'legacy-unknown'` and no `reason`.
194
+ */
195
+ export const NonCompilableEntryReadSchema = z
136
196
  .union([
137
197
  z.string(),
198
+ // Modern 4-tuple MUST come before the legacy 2-tuple in the union so
199
+ // Zod's left-to-right matching grabs the richer shape first. If the
200
+ // legacy 2-tuple sat ahead of the modern one, a full 4-tuple would
201
+ // match the 2-tuple schema (which requires only `hash` + `title`) and
202
+ // silently drop `reasonCode` / `reason` before transform could see them.
203
+ NonCompilableEntryWriteSchema,
138
204
  z.object({
139
205
  hash: z.string(),
140
206
  title: z.string(),
141
207
  }),
142
208
  ])
143
- .transform((entry) => typeof entry === 'string' ? { hash: entry, title: '(legacy entry)' } : entry);
209
+ .transform((entry) => {
210
+ if (typeof entry === 'string') {
211
+ return { hash: entry, title: '(legacy entry)', reasonCode: 'legacy-unknown' };
212
+ }
213
+ if ('reasonCode' in entry) {
214
+ return entry;
215
+ }
216
+ return { hash: entry.hash, title: entry.title, reasonCode: 'legacy-unknown' };
217
+ });
144
218
  export const CompiledRulesFileSchema = z.object({
145
219
  version: z.literal(1),
146
220
  rules: z.array(CompiledRuleSchema),
147
221
  /**
148
- * Lesson hashes that the LLM determined cannot be compiled (conceptual/architectural).
149
- * Stored as `{hash, title}` tuples for observability (#1280). Legacy `string[]` form
150
- * is accepted on read and normalized to tuples by `NonCompilableEntrySchema.transform`.
222
+ * Lessons that could not be compiled into a rule. 4-tuple shape since
223
+ * mmnto-ai/totem#1481: {hash, title, reasonCode, reason?}. The Read
224
+ * schema accepts the pre-#1280 string shape and the #1280-era 2-tuple
225
+ * and migrates both to the 4-tuple with `reasonCode: 'legacy-unknown'`.
226
+ * Every write site MUST route through `NonCompilableEntryWriteSchema`
227
+ * (or an equivalent structural check) to prevent the permissive Read
228
+ * transform from legitimizing legacy shapes on save.
151
229
  */
152
- nonCompilable: z.array(NonCompilableEntrySchema).optional(),
230
+ nonCompilable: z.array(NonCompilableEntryReadSchema).optional(),
153
231
  });
154
232
  // ─── Compiler output schema ─────────────────────────
155
233
  /** Schema for the structured JSON the LLM returns when compiling a lesson. */
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-schema.js","sourceRoot":"","sources":["../src/compiler-schema.ts"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CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACxC,wBAAwB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC"}
@@ -8,8 +8,8 @@
8
8
  * This file retains: hashing, regex validation, file I/O, and LLM response parsing.
9
9
  */
10
10
  import type { AstGrepYamlRule, CompiledRule, CompiledRulesFile, CompilerOutput, RegexValidation } from './compiler-schema.js';
11
- export type { AstContext, AstGrepYamlRule, CompiledRule, CompiledRulesFile, CompilerOutput, DiffAddition, NapiConfig, RegexValidation, RuleEventCallback, RuleEventContext, Violation, } from './compiler-schema.js';
12
- export { AstGrepYamlRuleSchema, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, NapiConfigSchema, } from './compiler-schema.js';
11
+ export type { AstContext, AstGrepYamlRule, CompiledRule, CompiledRulesFile, CompilerOutput, DiffAddition, NapiConfig, NonCompilableEntry, NonCompilableReasonCode, RegexValidation, RuleEventCallback, RuleEventContext, Violation, } from './compiler-schema.js';
12
+ export { AstGrepYamlRuleSchema, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, NapiConfigSchema, NonCompilableEntryReadSchema, NonCompilableEntryWriteSchema, NonCompilableReasonCodeSchema, } from './compiler-schema.js';
13
13
  export { extractAddedLines } from './diff-parser.js';
14
14
  export { applyAstRulesToAdditions, applyRules, applyRulesToAdditions, type CoreLogger, extractJustification, matchesGlob, setCoreLogger, } from './rule-engine.js';
15
15
  /** Hash a lesson's heading + body to detect changes since compilation. */
@@ -39,7 +39,15 @@ export declare function loadCompiledRules(rulesPath: string, onWarn?: (msg: stri
39
39
  export declare function loadCompiledRulesFile(rulesPath: string, onWarn?: (msg: string) => void): CompiledRulesFile;
40
40
  /** Save compiled rules to a JSON file. */
41
41
  export declare function saveCompiledRules(rulesPath: string, rules: CompiledRule[]): void;
42
- /** Save the full compiled rules file (rules + non-compilable cache). */
42
+ /**
43
+ * Save the full compiled rules file (rules + non-compilable cache).
44
+ *
45
+ * Every `nonCompilable` entry is validated through the strict Write schema
46
+ * before serialization per the Read/Write schema invariant (lesson
47
+ * 400fed87). If a caller ever passes Read-schema-shaped data back through
48
+ * save, we surface the bug as a `TotemParseError` rather than letting the
49
+ * permissive union silently re-accept legacy shapes on disk.
50
+ */
43
51
  export declare function saveCompiledRulesFile(rulesPath: string, data: CompiledRulesFile): void;
44
52
  /**
45
53
  * Expand brace patterns, normalize shallow globs, and strip unsupported syntax.
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAM9B,YAAY,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,qBAAqB,EACrB,KAAK,UAAU,EACf,oBAAoB,EACpB,WAAW,EACX,aAAa,GACd,MAAM,kBAAkB,CAAC;AAM1B,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhE;AAID;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAY9D;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CA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:crypto';
11
11
  import * as fs from 'node:fs';
12
12
  import safeRegex from 'safe-regex2';
13
13
  import { z } from 'zod';
14
- import { CompiledRulesFileSchema, CompilerOutputSchema } from './compiler-schema.js';
14
+ import { CompiledRulesFileSchema, CompilerOutputSchema, NonCompilableEntryWriteSchema, } from './compiler-schema.js';
15
15
  import { TotemParseError } from './errors.js';
16
- export { AstGrepYamlRuleSchema, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, NapiConfigSchema, } from './compiler-schema.js';
16
+ export { AstGrepYamlRuleSchema, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, NapiConfigSchema, NonCompilableEntryReadSchema, NonCompilableEntryWriteSchema, NonCompilableReasonCodeSchema, } from './compiler-schema.js';
17
17
  export { extractAddedLines } from './diff-parser.js';
18
18
  export { applyAstRulesToAdditions, applyRules, applyRulesToAdditions, extractJustification, matchesGlob, setCoreLogger, } from './rule-engine.js';
19
19
  // ─── Hashing ────────────────────────────────────────
@@ -106,9 +106,29 @@ export function saveCompiledRules(rulesPath, rules) {
106
106
  mode: 0o644,
107
107
  });
108
108
  }
109
- /** Save the full compiled rules file (rules + non-compilable cache). */
109
+ /**
110
+ * Save the full compiled rules file (rules + non-compilable cache).
111
+ *
112
+ * Every `nonCompilable` entry is validated through the strict Write schema
113
+ * before serialization per the Read/Write schema invariant (lesson
114
+ * 400fed87). If a caller ever passes Read-schema-shaped data back through
115
+ * save, we surface the bug as a `TotemParseError` rather than letting the
116
+ * permissive union silently re-accept legacy shapes on disk.
117
+ */
110
118
  export function saveCompiledRulesFile(rulesPath, data) {
111
- fs.writeFileSync(rulesPath, JSON.stringify(data, null, 2) + '\n', {
119
+ const validatedNonCompilable = data.nonCompilable?.map((entry, idx) => {
120
+ const parsed = NonCompilableEntryWriteSchema.safeParse(entry);
121
+ if (!parsed.success) {
122
+ throw new TotemParseError(`nonCompilable[${idx}] failed strict write validation: ${parsed.error.issues
123
+ .map((i) => i.message)
124
+ .join('; ')}`, 'Route ledger writes through NonCompilableEntryWriteSchema so legacy shapes do not leak back to disk.', parsed.error);
125
+ }
126
+ return parsed.data;
127
+ });
128
+ const payload = validatedNonCompilable
129
+ ? { ...data, nonCompilable: validatedNonCompilable }
130
+ : data;
131
+ fs.writeFileSync(rulesPath, JSON.stringify(payload, null, 2) + '\n', {
112
132
  encoding: 'utf-8',
113
133
  mode: 0o644,
114
134
  });
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiB9C,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,qBAAqB,EAErB,oBAAoB,EACpB,WAAW,EACX,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,uDAAuD;AAEvD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,IAAY;IACtD,OAAO,MAAM;SACV,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CAAC,GAAG,OAAO,KAAK,IAAI,EAAE,CAAC;SAC7B,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;AAC9B,CAAC;AAED,u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,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -665,6 +665,8 @@ describe('nonCompilable tuple schema (#1280)', () => {
665
665
  it('loads legacy string-only nonCompilable arrays without errors', async () => {
666
666
  // Pre-#1280: nonCompilable was Array<string>. Existing 1.13.0 compiled-rules.json
667
667
  // files in the wild have this shape. The schema must keep accepting them.
668
+ // mmnto-ai/totem#1481: strings migrate to the 4-tuple shape with
669
+ // reasonCode: 'legacy-unknown'.
668
670
  const { loadCompiledRulesFile } = await import('./compiler.js');
669
671
  const rulesPath = path.join(tmpDir, 'compiled-rules.json');
670
672
  fs.writeFileSync(rulesPath, JSON.stringify({
@@ -673,13 +675,16 @@ describe('nonCompilable tuple schema (#1280)', () => {
673
675
  nonCompilable: ['legacy-hash-aaa', 'legacy-hash-bbb'],
674
676
  }));
675
677
  const loaded = loadCompiledRulesFile(rulesPath);
676
- // Loader normalizes legacy strings to {hash, title} tuples for downstream uniformity.
677
678
  expect(loaded.nonCompilable).toEqual([
678
- { hash: 'legacy-hash-aaa', title: '(legacy entry)' },
679
- { hash: 'legacy-hash-bbb', title: '(legacy entry)' },
679
+ { hash: 'legacy-hash-aaa', title: '(legacy entry)', reasonCode: 'legacy-unknown' },
680
+ { hash: 'legacy-hash-bbb', title: '(legacy entry)', reasonCode: 'legacy-unknown' },
680
681
  ]);
681
682
  });
682
- it('loads new tuple-form nonCompilable arrays', async () => {
683
+ it('loads legacy 2-tuple nonCompilable arrays and migrates to 4-tuple', async () => {
684
+ // Pre-mmnto-ai/totem#1481: nonCompilable was Array<{hash, title}>. Files
685
+ // compiled between #1280 and #1481 carry this shape. The Read transform
686
+ // normalizes them to the 4-tuple with reasonCode: 'legacy-unknown' and
687
+ // preserves the original title.
683
688
  const { loadCompiledRulesFile } = await import('./compiler.js');
684
689
  const rulesPath = path.join(tmpDir, 'compiled-rules.json');
685
690
  fs.writeFileSync(rulesPath, JSON.stringify({
@@ -692,13 +697,53 @@ describe('nonCompilable tuple schema (#1280)', () => {
692
697
  }));
693
698
  const loaded = loadCompiledRulesFile(rulesPath);
694
699
  expect(loaded.nonCompilable).toEqual([
695
- { hash: 'newer-hash-1', title: 'Async error handling without context' },
696
- { hash: 'newer-hash-2', title: 'SSR hydration mismatch logging' },
700
+ {
701
+ hash: 'newer-hash-1',
702
+ title: 'Async error handling without context',
703
+ reasonCode: 'legacy-unknown',
704
+ },
705
+ {
706
+ hash: 'newer-hash-2',
707
+ title: 'SSR hydration mismatch logging',
708
+ reasonCode: 'legacy-unknown',
709
+ },
710
+ ]);
711
+ });
712
+ it('loads modern 4-tuple nonCompilable arrays without transforming them', async () => {
713
+ // Post-mmnto-ai/totem#1481 shape. The Read schema recognizes the full
714
+ // 4-tuple and passes it through unchanged (no 'legacy-unknown' coercion).
715
+ const { loadCompiledRulesFile } = await import('./compiler.js');
716
+ const rulesPath = path.join(tmpDir, 'compiled-rules.json');
717
+ fs.writeFileSync(rulesPath, JSON.stringify({
718
+ version: 1,
719
+ rules: [],
720
+ nonCompilable: [
721
+ {
722
+ hash: 'modern-1',
723
+ title: 'Cannot distill into a rule',
724
+ reasonCode: 'out-of-scope',
725
+ reason: 'Architectural principle.',
726
+ },
727
+ { hash: 'modern-2', title: 'Missing example', reasonCode: 'missing-badexample' },
728
+ ],
729
+ }));
730
+ const loaded = loadCompiledRulesFile(rulesPath);
731
+ expect(loaded.nonCompilable).toEqual([
732
+ {
733
+ hash: 'modern-1',
734
+ title: 'Cannot distill into a rule',
735
+ reasonCode: 'out-of-scope',
736
+ reason: 'Architectural principle.',
737
+ },
738
+ { hash: 'modern-2', title: 'Missing example', reasonCode: 'missing-badexample' },
697
739
  ]);
698
740
  });
699
- it('loads mixed legacy + tuple arrays', async () => {
700
- // Migration scenario: a project with stale legacy entries plus new tuple entries
701
- // (e.g., someone upgraded mid-cycle). Loader normalizes both to tuples.
741
+ it('loads mixed legacy + 2-tuple + 4-tuple arrays', async () => {
742
+ // Migration scenario: a project with stale legacy strings, intermediate
743
+ // 2-tuples, and fresh 4-tuples coexisting (e.g., someone upgraded mid
744
+ // cycle across multiple schema versions). Loader normalizes the first
745
+ // two shapes to 4-tuples with reasonCode: 'legacy-unknown' and leaves
746
+ // the modern entry untouched.
702
747
  const { loadCompiledRulesFile } = await import('./compiler.js');
703
748
  const rulesPath = path.join(tmpDir, 'compiled-rules.json');
704
749
  fs.writeFileSync(rulesPath, JSON.stringify({
@@ -707,37 +752,91 @@ describe('nonCompilable tuple schema (#1280)', () => {
707
752
  nonCompilable: [
708
753
  'legacy-hash',
709
754
  { hash: 'tuple-hash', title: 'Has a real title' },
755
+ { hash: 'modern-hash', title: 'Modern entry', reasonCode: 'out-of-scope' },
710
756
  'another-legacy',
711
757
  ],
712
758
  }));
713
759
  const loaded = loadCompiledRulesFile(rulesPath);
714
760
  expect(loaded.nonCompilable).toEqual([
715
- { hash: 'legacy-hash', title: '(legacy entry)' },
716
- { hash: 'tuple-hash', title: 'Has a real title' },
717
- { hash: 'another-legacy', title: '(legacy entry)' },
761
+ { hash: 'legacy-hash', title: '(legacy entry)', reasonCode: 'legacy-unknown' },
762
+ { hash: 'tuple-hash', title: 'Has a real title', reasonCode: 'legacy-unknown' },
763
+ { hash: 'modern-hash', title: 'Modern entry', reasonCode: 'out-of-scope' },
764
+ { hash: 'another-legacy', title: '(legacy entry)', reasonCode: 'legacy-unknown' },
718
765
  ]);
719
766
  });
720
- it('round-trips tuple entries through save and load', async () => {
767
+ it('Write schema rejects malformed shapes with a loud error', async () => {
768
+ // Read schema is permissive (accepts 3 shapes); Write schema is strict.
769
+ // mmnto-ai/totem#1481 locks this separation so legacy 2-tuples cannot
770
+ // round-trip through save and silently stay legacy on disk.
771
+ const { NonCompilableEntryWriteSchema } = await import('./compiler.js');
772
+ // Legacy string: rejected on write.
773
+ expect(NonCompilableEntryWriteSchema.safeParse('raw-hash').success).toBe(false);
774
+ // Legacy 2-tuple: rejected on write.
775
+ expect(NonCompilableEntryWriteSchema.safeParse({ hash: 'h', title: 't' }).success).toBe(false);
776
+ // Modern 4-tuple: accepted.
777
+ expect(NonCompilableEntryWriteSchema.safeParse({
778
+ hash: 'h',
779
+ title: 't',
780
+ reasonCode: 'out-of-scope',
781
+ }).success).toBe(true);
782
+ // reasonCode: 'legacy-unknown' is explicitly accepted on write so migrated
783
+ // 2-tuples can round-trip to disk on the first post-#1481 compile (the
784
+ // behavioral invariant that fresh producers never emit 'legacy-unknown'
785
+ // lives at the call site, not the schema).
786
+ expect(NonCompilableEntryWriteSchema.safeParse({
787
+ hash: 'h',
788
+ title: 't',
789
+ reasonCode: 'legacy-unknown',
790
+ }).success).toBe(true);
791
+ });
792
+ it('saveCompiledRulesFile rejects malformed nonCompilable entries', async () => {
793
+ // The writer is the last line of defense for the Read/Write invariant
794
+ // (lesson 400fed87). If a caller wires up a Read-shape entry into the
795
+ // save path, we fail loudly rather than persist it.
796
+ const { saveCompiledRulesFile } = await import('./compiler.js');
797
+ const rulesPath = path.join(tmpDir, 'compiled-rules.json');
798
+ const malformed = {
799
+ version: 1,
800
+ rules: [],
801
+ // Deliberately a legacy 2-tuple — Read-shape leaking into Write path.
802
+ nonCompilable: [{ hash: 'h', title: 't' }],
803
+ };
804
+ expect(() => saveCompiledRulesFile(rulesPath, malformed)).toThrowError(/nonCompilable\[0\] failed strict write validation/);
805
+ });
806
+ it('round-trips 4-tuple entries through save and load', async () => {
721
807
  const { loadCompiledRulesFile, saveCompiledRulesFile } = await import('./compiler.js');
722
808
  const rulesPath = path.join(tmpDir, 'compiled-rules.json');
723
809
  saveCompiledRulesFile(rulesPath, {
724
810
  version: 1,
725
811
  rules: [],
726
812
  nonCompilable: [
727
- { hash: 'roundtrip-1', title: 'First entry' },
728
- { hash: 'roundtrip-2', title: 'Second entry' },
813
+ {
814
+ hash: 'roundtrip-1',
815
+ title: 'First entry',
816
+ reasonCode: 'out-of-scope',
817
+ reason: 'Architectural principle, not a pattern.',
818
+ },
819
+ { hash: 'roundtrip-2', title: 'Second entry', reasonCode: 'missing-badexample' },
729
820
  ],
730
821
  });
731
822
  const loaded = loadCompiledRulesFile(rulesPath);
732
823
  expect(loaded.nonCompilable).toEqual([
733
- { hash: 'roundtrip-1', title: 'First entry' },
734
- { hash: 'roundtrip-2', title: 'Second entry' },
824
+ {
825
+ hash: 'roundtrip-1',
826
+ title: 'First entry',
827
+ reasonCode: 'out-of-scope',
828
+ reason: 'Architectural principle, not a pattern.',
829
+ },
830
+ { hash: 'roundtrip-2', title: 'Second entry', reasonCode: 'missing-badexample' },
735
831
  ]);
736
832
  });
737
- it('save normalizes legacy strings to tuples on the next round-trip', async () => {
738
- // The loader normalizes on read, so when the same data flows back through save,
739
- // the disk file gets the canonical tuple form. Legacy strings are a one-way
740
- // migration: once loaded, they're tuples; once saved, they stay tuples.
833
+ it('save migrates legacy strings through load, persisting as 4-tuples with legacy-unknown', async () => {
834
+ // The Read transform normalizes legacy strings to 4-tuples on load
835
+ // (reasonCode: 'legacy-unknown'). When the normalized data flows back
836
+ // through save, the strict Write schema accepts `'legacy-unknown'`
837
+ // so migration round-trips safely on the first post-#1481 compile.
838
+ // Fresh compile paths still never emit `'legacy-unknown'` themselves
839
+ // (producer-side invariant, not schema-side).
741
840
  const { loadCompiledRulesFile, saveCompiledRulesFile } = await import('./compiler.js');
742
841
  const rulesPath = path.join(tmpDir, 'compiled-rules.json');
743
842
  fs.writeFileSync(rulesPath, JSON.stringify({
@@ -748,7 +847,48 @@ describe('nonCompilable tuple schema (#1280)', () => {
748
847
  const firstLoad = loadCompiledRulesFile(rulesPath);
749
848
  saveCompiledRulesFile(rulesPath, firstLoad);
750
849
  const onDisk = JSON.parse(fs.readFileSync(rulesPath, 'utf-8'));
751
- expect(onDisk.nonCompilable).toEqual([{ hash: 'legacy-only', title: '(legacy entry)' }]);
850
+ expect(onDisk.nonCompilable).toEqual([
851
+ { hash: 'legacy-only', title: '(legacy entry)', reasonCode: 'legacy-unknown' },
852
+ ]);
853
+ });
854
+ });
855
+ // ─── Manifest-hash backward compatibility (mmnto-ai/totem#1480) ──
856
+ describe('CompiledRule manifest-hash stability with unverified flag', () => {
857
+ it('canonicalStringify yields identical output for undefined unverified and an absent field', async () => {
858
+ // Invariant #10: a CompiledRule compiled without `unverified` (absent)
859
+ // hashes identically to the same rule pre-#1480. The guard is that
860
+ // `canonicalStringify` walks `Object.keys` and ignores entries with
861
+ // `undefined` values (JSON.stringify drops them anyway). Explicit
862
+ // `unverified: false` would add the key and break every pre-#1480
863
+ // manifest hash on disk. We never write that literal; this test
864
+ // anchors the property.
865
+ const { canonicalStringify } = await import('./compile-manifest.js');
866
+ const preRule = {
867
+ lessonHash: 'abc123def4567890',
868
+ lessonHeading: 'Test rule',
869
+ pattern: '\\bfoo\\b',
870
+ message: 'No foo',
871
+ engine: 'regex',
872
+ compiledAt: '2026-01-01T00:00:00Z',
873
+ };
874
+ const postRule = { ...preRule, unverified: undefined };
875
+ expect(canonicalStringify(preRule)).toBe(canonicalStringify(postRule));
876
+ });
877
+ it('canonicalStringify differs when unverified is explicitly true', async () => {
878
+ // Negative control: the flag does change the hash when set. An
879
+ // unverified rule is a different rule from a verified one; they must
880
+ // hash differently so the manifest reflects the governance signal.
881
+ const { canonicalStringify } = await import('./compile-manifest.js');
882
+ const verifiedRule = {
883
+ lessonHash: 'abc123def4567890',
884
+ lessonHeading: 'Test rule',
885
+ pattern: '\\bfoo\\b',
886
+ message: 'No foo',
887
+ engine: 'regex',
888
+ compiledAt: '2026-01-01T00:00:00Z',
889
+ };
890
+ const unverifiedRule = { ...verifiedRule, unverified: true };
891
+ expect(canonicalStringify(verifiedRule)).not.toBe(canonicalStringify(unverifiedRule));
752
892
  });
753
893
  });
754
894
  // ─── CompiledRuleSchema: status / archivedReason ────