@mmnto/totem 1.14.8 → 1.14.9
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.
- package/dist/ast-grep-query.d.ts +22 -2
- package/dist/ast-grep-query.d.ts.map +1 -1
- package/dist/ast-grep-query.js +34 -5
- package/dist/ast-grep-query.js.map +1 -1
- package/dist/ast-grep-query.test.js +45 -1
- package/dist/ast-grep-query.test.js.map +1 -1
- package/dist/compile-lesson.d.ts +24 -1
- package/dist/compile-lesson.d.ts.map +1 -1
- package/dist/compile-lesson.js +112 -58
- package/dist/compile-lesson.js.map +1 -1
- package/dist/compile-lesson.test.js +283 -14
- package/dist/compile-lesson.test.js.map +1 -1
- package/dist/compile-manifest.d.ts +14 -1
- package/dist/compile-manifest.d.ts.map +1 -1
- package/dist/compile-manifest.js +107 -3
- package/dist/compile-manifest.js.map +1 -1
- package/dist/compile-manifest.test.js +123 -1
- package/dist/compile-manifest.test.js.map +1 -1
- package/dist/compile-smoke-gate.d.ts +42 -0
- package/dist/compile-smoke-gate.d.ts.map +1 -0
- package/dist/compile-smoke-gate.js +135 -0
- package/dist/compile-smoke-gate.js.map +1 -0
- package/dist/compile-smoke-gate.test.d.ts +2 -0
- package/dist/compile-smoke-gate.test.d.ts.map +1 -0
- package/dist/compile-smoke-gate.test.js +202 -0
- package/dist/compile-smoke-gate.test.js.map +1 -0
- package/dist/compiler-schema.d.ts +286 -24
- package/dist/compiler-schema.d.ts.map +1 -1
- package/dist/compiler-schema.js +128 -5
- package/dist/compiler-schema.js.map +1 -1
- package/dist/compiler-schema.test.d.ts +2 -0
- package/dist/compiler-schema.test.d.ts.map +1 -0
- package/dist/compiler-schema.test.js +263 -0
- package/dist/compiler-schema.test.js.map +1 -0
- package/dist/compiler.d.ts +22 -5
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +9 -3
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.test.js +17 -2
- package/dist/compiler.test.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/ledger.d.ts +1 -1
- package/dist/lesson-pattern.d.ts +26 -0
- package/dist/lesson-pattern.d.ts.map +1 -1
- package/dist/lesson-pattern.js +35 -1
- package/dist/lesson-pattern.js.map +1 -1
- package/dist/lesson-pattern.test.js +72 -0
- package/dist/lesson-pattern.test.js.map +1 -1
- package/dist/rule-engine.d.ts.map +1 -1
- package/dist/rule-engine.js +25 -7
- package/dist/rule-engine.js.map +1 -1
- package/dist/rule-engine.test.js +98 -4
- package/dist/rule-engine.test.js.map +1 -1
- package/dist/rule-tester.d.ts.map +1 -1
- package/dist/rule-tester.js +9 -2
- package/dist/rule-tester.js.map +1 -1
- package/dist/rule-tester.test.js +41 -0
- package/dist/rule-tester.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-schema.d.ts","sourceRoot":"","sources":["../src/compiler-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,kBAAkB;
|
|
1
|
+
{"version":3,"file":"compiler-schema.d.ts","sourceRoot":"","sources":["../src/compiler-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB;;;;;;gCAIb,CAAC;AAEjB,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;;gCAAmB,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC;AAsGzC,eAAO,MAAM,kBAAkB;IAjG7B,0EAA0E;;IAE1E,+DAA+D;;IAE/D,sDAAsD;;IAEtD,sEAAsE;;IAEtE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C,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,gBAAgB,KACvB,IAAI,CAAC"}
|
package/dist/compiler-schema.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
// ─── NapiConfig / compound ast-grep rule schemas ────
|
|
3
|
+
/**
|
|
4
|
+
* Schema mirroring `@ast-grep/napi`'s `NapiConfig` interface for compound
|
|
5
|
+
* structural rules. The `rule` key is required at the Zod layer so the
|
|
6
|
+
* parse-time failure is loud and readable; the inner tree shape is handed
|
|
7
|
+
* off to `@ast-grep/napi` at the engine boundary for the authoritative
|
|
8
|
+
* validity check (see `validateAstGrepPattern`). `passthrough()` lets
|
|
9
|
+
* future napi fields (e.g. `constraints`, `transform`) survive a parse
|
|
10
|
+
* without a schema bump.
|
|
11
|
+
*
|
|
12
|
+
* The rule body is a recursive structural tree (combinators like `all`,
|
|
13
|
+
* `any`, `not`, `inside`, `has`, `precedes`, `follows`). Rather than
|
|
14
|
+
* modelling the full recursive schema with `z.lazy()`, we accept any
|
|
15
|
+
* object shape here and lean on napi to reject malformed trees. That
|
|
16
|
+
* keeps the Zod layer cheap and the authoritative check centralized.
|
|
17
|
+
*/
|
|
18
|
+
export const NapiConfigSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
rule: z.record(z.unknown()),
|
|
21
|
+
})
|
|
22
|
+
.passthrough();
|
|
23
|
+
/**
|
|
24
|
+
* Named alias of `NapiConfigSchema` for grep-ability. The field on
|
|
25
|
+
* `CompiledRule` is named `astGrepYamlRule` (see ADR-087); the alias
|
|
26
|
+
* lets a reader search for `AstGrepYamlRuleSchema` and land on the
|
|
27
|
+
* right definition without first knowing it's a napi config.
|
|
28
|
+
*/
|
|
29
|
+
export const AstGrepYamlRuleSchema = NapiConfigSchema;
|
|
2
30
|
// ─── Compiled rule schemas ──────────────────────────
|
|
3
|
-
|
|
31
|
+
const CompiledRuleBaseSchema = z.object({
|
|
4
32
|
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
5
33
|
lessonHash: z.string(),
|
|
6
34
|
/** Human-readable heading from the lesson (for diagnostics) */
|
|
@@ -13,8 +41,27 @@ export const CompiledRuleSchema = z.object({
|
|
|
13
41
|
engine: z.enum(['regex', 'ast', 'ast-grep']),
|
|
14
42
|
/** Tree-sitter S-expression query (required when engine is 'ast') */
|
|
15
43
|
astQuery: z.string().optional(),
|
|
16
|
-
/**
|
|
17
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Flat ast-grep pattern source (a single JS/TS expression). Mutually
|
|
46
|
+
* exclusive with `astGrepYamlRule` when `engine === 'ast-grep'`; the
|
|
47
|
+
* superRefine below enforces that.
|
|
48
|
+
*/
|
|
49
|
+
astGrepPattern: z.string().optional(),
|
|
50
|
+
/**
|
|
51
|
+
* Compound ast-grep rule (NapiConfig shape). Holds structural trees
|
|
52
|
+
* that cannot be expressed as a single source snippet (all / any /
|
|
53
|
+
* not / inside / has / precedes / follows combinators). Mutually
|
|
54
|
+
* exclusive with `astGrepPattern`; see the superRefine on this
|
|
55
|
+
* schema. Smoke-test wiring lands in mmnto/totem#1408.
|
|
56
|
+
*/
|
|
57
|
+
astGrepYamlRule: AstGrepYamlRuleSchema.optional(),
|
|
58
|
+
/**
|
|
59
|
+
* Optional code snippet the rule is expected to match. Stored from
|
|
60
|
+
* compiler output so the smoke-test runner (wired in
|
|
61
|
+
* mmnto/totem#1408) can re-validate the rule offline. Optional in
|
|
62
|
+
* 1.14.9; flips to required when #1408 turns on the gate.
|
|
63
|
+
*/
|
|
64
|
+
badExample: z.string().optional(),
|
|
18
65
|
/** ISO timestamp of when this rule was compiled */
|
|
19
66
|
compiledAt: z.string(),
|
|
20
67
|
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
@@ -43,6 +90,35 @@ export const CompiledRuleSchema = z.object({
|
|
|
43
90
|
*/
|
|
44
91
|
manual: z.boolean().optional(),
|
|
45
92
|
});
|
|
93
|
+
/**
|
|
94
|
+
* Shared mutual-exclusion check between the flat `astGrepPattern` string
|
|
95
|
+
* and the structural `astGrepYamlRule` object. Used by both
|
|
96
|
+
* `CompiledRuleSchema` and `CompilerOutputSchema` so the gate fires at
|
|
97
|
+
* both the LLM-output boundary and the persisted-rule boundary. Empty
|
|
98
|
+
* strings count as "not present" because `engineFields` writes
|
|
99
|
+
* `pattern: ''` alongside every ast-grep rule.
|
|
100
|
+
*/
|
|
101
|
+
function refineAstGrepMutualExclusion(data, ctx) {
|
|
102
|
+
if (data.engine !== 'ast-grep')
|
|
103
|
+
return;
|
|
104
|
+
const hasPattern = typeof data.astGrepPattern === 'string' && data.astGrepPattern.length > 0;
|
|
105
|
+
const hasYaml = data.astGrepYamlRule !== undefined;
|
|
106
|
+
if (hasPattern && hasYaml) {
|
|
107
|
+
ctx.addIssue({
|
|
108
|
+
code: z.ZodIssueCode.custom,
|
|
109
|
+
message: 'ast-grep rule cannot define both astGrepPattern and astGrepYamlRule',
|
|
110
|
+
path: ['astGrepYamlRule'],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (!hasPattern && !hasYaml) {
|
|
114
|
+
ctx.addIssue({
|
|
115
|
+
code: z.ZodIssueCode.custom,
|
|
116
|
+
message: 'ast-grep rule must define either astGrepPattern or astGrepYamlRule',
|
|
117
|
+
path: ['astGrepPattern'],
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export const CompiledRuleSchema = CompiledRuleBaseSchema.superRefine(refineAstGrepMutualExclusion);
|
|
46
122
|
/**
|
|
47
123
|
* A non-compilable lesson entry. Pre-#1280 these were opaque hash strings;
|
|
48
124
|
* post-#1280 they're {hash, title} tuples for human-readable triage. The
|
|
@@ -70,16 +146,63 @@ export const CompiledRulesFileSchema = z.object({
|
|
|
70
146
|
});
|
|
71
147
|
// ─── Compiler output schema ─────────────────────────
|
|
72
148
|
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
73
|
-
|
|
149
|
+
const CompilerOutputBaseSchema = z.object({
|
|
74
150
|
compilable: z.boolean(),
|
|
75
151
|
pattern: z.string().optional(),
|
|
76
152
|
message: z.string().optional(),
|
|
77
153
|
fileGlobs: z.array(z.string()).optional(),
|
|
78
154
|
engine: z.enum(['regex', 'ast', 'ast-grep']).optional(),
|
|
79
155
|
astQuery: z.string().optional(),
|
|
80
|
-
|
|
156
|
+
/** Flat ast-grep pattern source. Mutually exclusive with `astGrepYamlRule`. */
|
|
157
|
+
astGrepPattern: z.string().optional(),
|
|
158
|
+
/** Compound ast-grep rule (NapiConfig). Mutually exclusive with `astGrepPattern`. */
|
|
159
|
+
astGrepYamlRule: AstGrepYamlRuleSchema.optional(),
|
|
160
|
+
/**
|
|
161
|
+
* Code snippet the rule is expected to match. Flipped from optional to
|
|
162
|
+
* engine-conditional required in mmnto-ai/totem#1409 - regex and
|
|
163
|
+
* ast-grep rules must carry a non-empty snippet so the compile-time
|
|
164
|
+
* smoke gate (#1408) can execute the rule against known-bad code
|
|
165
|
+
* before it lands in compiled-rules.json. The Zod field stays
|
|
166
|
+
* optional here; the `refineBadExampleRequired` superRefine below
|
|
167
|
+
* enforces the engine-conditional requirement so the error message
|
|
168
|
+
* can name the engine and cite the ticket.
|
|
169
|
+
*/
|
|
170
|
+
badExample: z.string().optional(),
|
|
81
171
|
severity: z.enum(['error', 'warning']).optional(),
|
|
82
172
|
/** LLM explanation for why a lesson was marked non-compilable */
|
|
83
173
|
reason: z.string().optional(),
|
|
84
174
|
});
|
|
175
|
+
/**
|
|
176
|
+
* Enforce that Pipeline 2 / Pipeline 3 LLM output carries a non-empty
|
|
177
|
+
* `badExample` for every rule whose engine is covered by the compile-time
|
|
178
|
+
* smoke gate (regex and ast-grep, per mmnto-ai/totem#1408). The `ast`
|
|
179
|
+
* engine (Tree-sitter S-expression queries) is exempt because the smoke
|
|
180
|
+
* gate does not yet evaluate those rules - forcing `badExample` there
|
|
181
|
+
* would reject every ast-engine rule the LLM emits today.
|
|
182
|
+
*
|
|
183
|
+
* An absent `engine` field counts as `regex` because `buildCompiledRule`
|
|
184
|
+
* defaults a missing engine to regex. Without that equivalence the LLM
|
|
185
|
+
* could omit `engine` and bypass the gate silently.
|
|
186
|
+
*
|
|
187
|
+
* Applies only to compilable rules. Non-compilable output carries
|
|
188
|
+
* `reason` instead of a rule and has nothing for the gate to execute.
|
|
189
|
+
*/
|
|
190
|
+
function refineBadExampleRequired(data, ctx) {
|
|
191
|
+
if (!data.compilable)
|
|
192
|
+
return;
|
|
193
|
+
const engineRequiresBadExample = data.engine !== 'ast';
|
|
194
|
+
if (!engineRequiresBadExample)
|
|
195
|
+
return;
|
|
196
|
+
if (typeof data.badExample === 'string' && data.badExample.length > 0)
|
|
197
|
+
return;
|
|
198
|
+
ctx.addIssue({
|
|
199
|
+
code: z.ZodIssueCode.custom,
|
|
200
|
+
message: 'badExample is required (non-empty string) for regex and ast-grep engines (mmnto-ai/totem#1409)',
|
|
201
|
+
path: ['badExample'],
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
export const CompilerOutputSchema = CompilerOutputBaseSchema.superRefine((data, ctx) => {
|
|
205
|
+
refineAstGrepMutualExclusion(data, ctx);
|
|
206
|
+
refineBadExampleRequired(data, ctx);
|
|
207
|
+
});
|
|
85
208
|
//# sourceMappingURL=compiler-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-schema.js","sourceRoot":"","sources":["../src/compiler-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,uDAAuD;AAEvD,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"compiler-schema.js","sourceRoot":"","sources":["../src/compiler-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,uDAAuD;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,CAA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ourceRoot":"","sources":["../src/compiler-schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { AstGrepYamlRuleSchema, CompiledRuleSchema, CompilerOutputSchema, NapiConfigSchema, } from './compiler-schema.js';
|
|
3
|
+
// ─── NapiConfigSchema / AstGrepYamlRuleSchema ────────
|
|
4
|
+
describe('NapiConfigSchema', () => {
|
|
5
|
+
it('accepts a minimal compound rule with a rule key', () => {
|
|
6
|
+
const parsed = NapiConfigSchema.parse({
|
|
7
|
+
rule: { pattern: 'foo($A)' },
|
|
8
|
+
});
|
|
9
|
+
expect(parsed.rule).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
it('accepts nested combinators (all / any / inside)', () => {
|
|
12
|
+
const parsed = NapiConfigSchema.parse({
|
|
13
|
+
rule: {
|
|
14
|
+
all: [{ pattern: 'foo($A)' }, { inside: { kind: 'function_declaration' } }],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
expect(parsed.rule).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
it('rejects an object missing the rule key at parse time', () => {
|
|
20
|
+
expect(() => NapiConfigSchema.parse({ notRule: {} })).toThrow();
|
|
21
|
+
});
|
|
22
|
+
it('is exported as an alias under AstGrepYamlRuleSchema', () => {
|
|
23
|
+
const input = { rule: { pattern: 'foo($A)' } };
|
|
24
|
+
const viaNapi = NapiConfigSchema.parse(input);
|
|
25
|
+
const viaAlias = AstGrepYamlRuleSchema.parse(input);
|
|
26
|
+
expect(viaAlias).toEqual(viaNapi);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
// ─── CompiledRuleSchema mutual exclusion ─────────────
|
|
30
|
+
describe('CompiledRuleSchema mutual exclusion', () => {
|
|
31
|
+
const baseRule = {
|
|
32
|
+
lessonHash: 'abc123def456',
|
|
33
|
+
lessonHeading: 'Test rule',
|
|
34
|
+
pattern: '',
|
|
35
|
+
message: 'Use the right thing',
|
|
36
|
+
engine: 'ast-grep',
|
|
37
|
+
compiledAt: '2026-04-13T12:00:00Z',
|
|
38
|
+
};
|
|
39
|
+
it('accepts ast-grep engine with only astGrepPattern', () => {
|
|
40
|
+
const parsed = CompiledRuleSchema.parse({
|
|
41
|
+
...baseRule,
|
|
42
|
+
astGrepPattern: 'console.log($A)',
|
|
43
|
+
});
|
|
44
|
+
expect(parsed.astGrepPattern).toBe('console.log($A)');
|
|
45
|
+
expect(parsed.astGrepYamlRule).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
it('accepts ast-grep engine with only astGrepYamlRule', () => {
|
|
48
|
+
const parsed = CompiledRuleSchema.parse({
|
|
49
|
+
...baseRule,
|
|
50
|
+
astGrepYamlRule: { rule: { pattern: 'console.log($A)' } },
|
|
51
|
+
});
|
|
52
|
+
expect(parsed.astGrepYamlRule).toBeDefined();
|
|
53
|
+
expect(parsed.astGrepPattern).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
it('CompiledRule rejects ast-grep engine with both pattern and yaml definitions', () => {
|
|
56
|
+
expect(() => CompiledRuleSchema.parse({
|
|
57
|
+
...baseRule,
|
|
58
|
+
astGrepPattern: 'console.log($A)',
|
|
59
|
+
astGrepYamlRule: { rule: { pattern: 'console.log($A)' } },
|
|
60
|
+
})).toThrow(/cannot define both astGrepPattern and astGrepYamlRule/);
|
|
61
|
+
});
|
|
62
|
+
it('CompiledRule rejects ast-grep engine with neither pattern nor yaml definitions', () => {
|
|
63
|
+
expect(() => CompiledRuleSchema.parse(baseRule)).toThrow(/must define either astGrepPattern or astGrepYamlRule/);
|
|
64
|
+
});
|
|
65
|
+
it('treats empty-string astGrepPattern as "not present" for mutual exclusion', () => {
|
|
66
|
+
// Empty-string pattern + yaml object is the legit compound-rule shape because
|
|
67
|
+
// engineFields writes pattern: '' for ast-grep rules.
|
|
68
|
+
const parsed = CompiledRuleSchema.parse({
|
|
69
|
+
...baseRule,
|
|
70
|
+
astGrepPattern: '',
|
|
71
|
+
astGrepYamlRule: { rule: { pattern: 'foo' } },
|
|
72
|
+
});
|
|
73
|
+
expect(parsed.astGrepYamlRule).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
it('accepts regex engine without either ast-grep field', () => {
|
|
76
|
+
const parsed = CompiledRuleSchema.parse({
|
|
77
|
+
...baseRule,
|
|
78
|
+
engine: 'regex',
|
|
79
|
+
pattern: '\\bfoo\\b',
|
|
80
|
+
});
|
|
81
|
+
expect(parsed.engine).toBe('regex');
|
|
82
|
+
});
|
|
83
|
+
it('accepts ast engine without either ast-grep field', () => {
|
|
84
|
+
const parsed = CompiledRuleSchema.parse({
|
|
85
|
+
...baseRule,
|
|
86
|
+
engine: 'ast',
|
|
87
|
+
astQuery: '(catch_clause) @c',
|
|
88
|
+
});
|
|
89
|
+
expect(parsed.engine).toBe('ast');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
// ─── CompilerOutputSchema parallels ──────────────────
|
|
93
|
+
describe('CompilerOutputSchema mutual exclusion', () => {
|
|
94
|
+
it('rejects compiler output with both ast-grep fields', () => {
|
|
95
|
+
expect(() => CompilerOutputSchema.parse({
|
|
96
|
+
compilable: true,
|
|
97
|
+
engine: 'ast-grep',
|
|
98
|
+
message: 'msg',
|
|
99
|
+
astGrepPattern: 'foo($A)',
|
|
100
|
+
astGrepYamlRule: { rule: { pattern: 'foo($A)' } },
|
|
101
|
+
})).toThrow(/cannot define both astGrepPattern and astGrepYamlRule/);
|
|
102
|
+
});
|
|
103
|
+
it('accepts compiler output with only astGrepYamlRule', () => {
|
|
104
|
+
// Post mmnto-ai/totem#1409: every compilable ast-grep output must
|
|
105
|
+
// carry a non-empty badExample, so the happy path here includes one.
|
|
106
|
+
const parsed = CompilerOutputSchema.parse({
|
|
107
|
+
compilable: true,
|
|
108
|
+
engine: 'ast-grep',
|
|
109
|
+
message: 'msg',
|
|
110
|
+
astGrepYamlRule: { rule: { pattern: 'foo($A)' } },
|
|
111
|
+
badExample: 'foo(1)',
|
|
112
|
+
});
|
|
113
|
+
expect(parsed.astGrepYamlRule).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
// ─── CompiledRule badExample optional field ──────────
|
|
117
|
+
describe('CompiledRule badExample field', () => {
|
|
118
|
+
const baseRule = {
|
|
119
|
+
lessonHash: 'abc123def456',
|
|
120
|
+
lessonHeading: 'Test rule',
|
|
121
|
+
pattern: '\\bfoo\\b',
|
|
122
|
+
message: 'No foo',
|
|
123
|
+
engine: 'regex',
|
|
124
|
+
compiledAt: '2026-04-13T12:00:00Z',
|
|
125
|
+
};
|
|
126
|
+
it('accepts a CompiledRule with badExample set', () => {
|
|
127
|
+
const parsed = CompiledRuleSchema.parse({
|
|
128
|
+
...baseRule,
|
|
129
|
+
badExample: 'const foo = 1;',
|
|
130
|
+
});
|
|
131
|
+
expect(parsed.badExample).toBe('const foo = 1;');
|
|
132
|
+
});
|
|
133
|
+
it('accepts a CompiledRule without badExample (optional on the persisted shape)', () => {
|
|
134
|
+
// CompiledRule stays optional because Pipeline 1 (manual) rules
|
|
135
|
+
// have not yet been taught to emit badExample — that work is
|
|
136
|
+
// deferred to mmnto-ai/totem#1414. Only CompilerOutput (the LLM
|
|
137
|
+
// gate) flips to required in mmnto-ai/totem#1409.
|
|
138
|
+
const parsed = CompiledRuleSchema.parse(baseRule);
|
|
139
|
+
expect(parsed.badExample).toBeUndefined();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
// ─── CompilerOutput badExample required per engine (mmnto-ai/totem#1409) ──
|
|
143
|
+
describe('CompilerOutput badExample required by engine', () => {
|
|
144
|
+
it('accepts a regex CompilerOutput with a non-empty badExample', () => {
|
|
145
|
+
const parsed = CompilerOutputSchema.parse({
|
|
146
|
+
compilable: true,
|
|
147
|
+
pattern: '\\bfoo\\b',
|
|
148
|
+
message: 'No foo',
|
|
149
|
+
engine: 'regex',
|
|
150
|
+
badExample: 'const foo = 1;',
|
|
151
|
+
});
|
|
152
|
+
expect(parsed.badExample).toBe('const foo = 1;');
|
|
153
|
+
});
|
|
154
|
+
it('accepts an ast-grep CompilerOutput with a non-empty badExample', () => {
|
|
155
|
+
const parsed = CompilerOutputSchema.parse({
|
|
156
|
+
compilable: true,
|
|
157
|
+
message: 'No console.log',
|
|
158
|
+
engine: 'ast-grep',
|
|
159
|
+
astGrepPattern: 'console.log($A)',
|
|
160
|
+
badExample: 'console.log("debug");',
|
|
161
|
+
});
|
|
162
|
+
expect(parsed.badExample).toBe('console.log("debug");');
|
|
163
|
+
});
|
|
164
|
+
it('rejects a regex CompilerOutput missing badExample', () => {
|
|
165
|
+
const result = CompilerOutputSchema.safeParse({
|
|
166
|
+
compilable: true,
|
|
167
|
+
pattern: '\\bfoo\\b',
|
|
168
|
+
message: 'No foo',
|
|
169
|
+
engine: 'regex',
|
|
170
|
+
});
|
|
171
|
+
expect(result.success).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
it('rejects a regex CompilerOutput with an empty badExample string', () => {
|
|
174
|
+
const result = CompilerOutputSchema.safeParse({
|
|
175
|
+
compilable: true,
|
|
176
|
+
pattern: '\\bfoo\\b',
|
|
177
|
+
message: 'No foo',
|
|
178
|
+
engine: 'regex',
|
|
179
|
+
badExample: '',
|
|
180
|
+
});
|
|
181
|
+
expect(result.success).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
it('rejects an ast-grep CompilerOutput missing badExample', () => {
|
|
184
|
+
const result = CompilerOutputSchema.safeParse({
|
|
185
|
+
compilable: true,
|
|
186
|
+
message: 'No console.log',
|
|
187
|
+
engine: 'ast-grep',
|
|
188
|
+
astGrepPattern: 'console.log($A)',
|
|
189
|
+
});
|
|
190
|
+
expect(result.success).toBe(false);
|
|
191
|
+
});
|
|
192
|
+
it('rejects an ast-grep compound CompilerOutput missing badExample', () => {
|
|
193
|
+
const result = CompilerOutputSchema.safeParse({
|
|
194
|
+
compilable: true,
|
|
195
|
+
message: 'No const inside for-loop',
|
|
196
|
+
engine: 'ast-grep',
|
|
197
|
+
astGrepYamlRule: {
|
|
198
|
+
rule: {
|
|
199
|
+
pattern: 'const $VAR = $VAL',
|
|
200
|
+
inside: { kind: 'for_statement', stopBy: 'end' },
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
expect(result.success).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
it('accepts an ast engine CompilerOutput without badExample (exempt engine)', () => {
|
|
207
|
+
// Tree-sitter S-expression rules are not covered by the smoke gate
|
|
208
|
+
// in mmnto-ai/totem#1408, so the schema does not force a badExample
|
|
209
|
+
// on them. The exemption is load-bearing: removing it would reject
|
|
210
|
+
// every ast-engine rule the LLM emits today.
|
|
211
|
+
const parsed = CompilerOutputSchema.parse({
|
|
212
|
+
compilable: true,
|
|
213
|
+
message: 'AST check',
|
|
214
|
+
engine: 'ast',
|
|
215
|
+
astQuery: '(catch_clause) @c',
|
|
216
|
+
});
|
|
217
|
+
expect(parsed.engine).toBe('ast');
|
|
218
|
+
expect(parsed.badExample).toBeUndefined();
|
|
219
|
+
});
|
|
220
|
+
it('accepts a non-compilable CompilerOutput without badExample', () => {
|
|
221
|
+
// When compilable is false, there is no rule to smoke-test, so
|
|
222
|
+
// badExample stays optional. The reason field is what matters.
|
|
223
|
+
const parsed = CompilerOutputSchema.parse({
|
|
224
|
+
compilable: false,
|
|
225
|
+
reason: 'Conceptual architectural principle',
|
|
226
|
+
});
|
|
227
|
+
expect(parsed.compilable).toBe(false);
|
|
228
|
+
});
|
|
229
|
+
it('rejects a CompilerOutput with no engine field but no badExample (defaults to regex)', () => {
|
|
230
|
+
// buildCompiledRule defaults a missing engine to regex, so the
|
|
231
|
+
// schema treats the absent case the same way for gate purposes.
|
|
232
|
+
// This closes the back door where the LLM could omit engine to
|
|
233
|
+
// skip the required badExample.
|
|
234
|
+
const result = CompilerOutputSchema.safeParse({
|
|
235
|
+
compilable: true,
|
|
236
|
+
pattern: '\\bnpm\\b',
|
|
237
|
+
message: 'Use pnpm instead of npm',
|
|
238
|
+
});
|
|
239
|
+
expect(result.success).toBe(false);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
// ─── RuleEventCallback discriminator (mmnto/totem#1408) ─────
|
|
243
|
+
describe('RuleEventCallback discriminator', () => {
|
|
244
|
+
it('accepts the three distinct event variants without conflating them', () => {
|
|
245
|
+
const events = [];
|
|
246
|
+
const cb = (event, hash, context) => {
|
|
247
|
+
events.push(`${event}:${hash}:${context?.failureReason ?? ''}`);
|
|
248
|
+
};
|
|
249
|
+
cb('trigger', 'h1');
|
|
250
|
+
cb('suppress', 'h2', { file: 'f', line: 1, justification: 'ok' });
|
|
251
|
+
cb('failure', 'h3', { file: 'f', line: 1, failureReason: 'napi panic' });
|
|
252
|
+
expect(events).toEqual(['trigger:h1:', 'suppress:h2:', 'failure:h3:napi panic']);
|
|
253
|
+
});
|
|
254
|
+
it('keeps suppress and failure as separate values per the #1412 postmerge GCA boundary', () => {
|
|
255
|
+
// The two discriminator values are not string-equal and must be handled on
|
|
256
|
+
// distinct code paths. This test locks that in at the type level so a
|
|
257
|
+
// future refactor that collapses them fails here loudly.
|
|
258
|
+
const suppress = 'suppress';
|
|
259
|
+
const failure = 'failure';
|
|
260
|
+
expect(suppress).not.toBe(failure);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
//# sourceMappingURL=compiler-schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-schema.test.js","sourceRoot":"","sources":["../src/compiler-schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAG9C,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,wDAAwD;AAExD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MA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AAE;YACrD,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE,aAAa,IAAI,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC,CAAC;QAEF,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACpB,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,cAAc,EAAE,uBAAuB,CAAC,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC5F,2EAA2E;QAC3E,sEAAsE;QACtE,yDAAyD;QACzD,MAAM,QAAQ,GAAuC,UAAU,CAAC;QAChE,MAAM,OAAO,GAAuC,SAAS,CAAC;QAC9D,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/compiler.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* This file retains: hashing, regex validation, file I/O, and LLM response parsing.
|
|
9
9
|
*/
|
|
10
|
-
import type { CompiledRule, CompiledRulesFile, CompilerOutput, RegexValidation } from './compiler-schema.js';
|
|
11
|
-
export type { AstContext, CompiledRule, CompiledRulesFile, CompilerOutput, DiffAddition, RegexValidation, RuleEventCallback, RuleEventContext, Violation, } from './compiler-schema.js';
|
|
12
|
-
export { CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, } from './compiler-schema.js';
|
|
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';
|
|
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. */
|
|
@@ -47,10 +47,27 @@ export declare function saveCompiledRulesFile(rulesPath: string, data: CompiledR
|
|
|
47
47
|
* e.g., "*.ts" → "**\/*.ts" (shallow → recursive)
|
|
48
48
|
*/
|
|
49
49
|
export declare function sanitizeFileGlobs(globs: unknown[]): string[];
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Build engine-specific fields for a compiled rule.
|
|
52
|
+
*
|
|
53
|
+
* Overloaded so only the `'ast-grep'` branch accepts a compound
|
|
54
|
+
* `Record<string, unknown>`; `'regex'` and `'ast'` are string-only.
|
|
55
|
+
* This prevents callers from passing a compound object to the regex
|
|
56
|
+
* engine and silently producing `"[object Object]"` via `String(pattern)`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function engineFields(engine: 'regex' | 'ast', pattern: string): {
|
|
59
|
+
pattern: string;
|
|
60
|
+
astQuery?: string;
|
|
61
|
+
};
|
|
62
|
+
export declare function engineFields(engine: 'ast-grep', pattern: string | Record<string, unknown>): {
|
|
63
|
+
pattern: string;
|
|
64
|
+
astGrepPattern?: string;
|
|
65
|
+
astGrepYamlRule?: AstGrepYamlRule;
|
|
66
|
+
};
|
|
51
67
|
export declare function engineFields(engine: 'regex' | 'ast' | 'ast-grep', pattern: string | Record<string, unknown>): {
|
|
52
68
|
pattern: string;
|
|
53
|
-
astGrepPattern?: string
|
|
69
|
+
astGrepPattern?: string;
|
|
70
|
+
astGrepYamlRule?: AstGrepYamlRule;
|
|
54
71
|
astQuery?: string;
|
|
55
72
|
};
|
|
56
73
|
export declare function parseCompilerResponse(response: string): CompilerOutput | null;
|
package/dist/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAM9B,YAAY,EACV,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,
|
|
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,kBA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C,GACxC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC;AAQnF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,UAAU,EACpC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AA2CF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CA4B7E"}
|
package/dist/compiler.js
CHANGED
|
@@ -13,7 +13,7 @@ import safeRegex from 'safe-regex2';
|
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { CompiledRulesFileSchema, CompilerOutputSchema } from './compiler-schema.js';
|
|
15
15
|
import { TotemParseError } from './errors.js';
|
|
16
|
-
export { CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, } from './compiler-schema.js';
|
|
16
|
+
export { AstGrepYamlRuleSchema, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, NapiConfigSchema, } 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 ────────────────────────────────────────
|
|
@@ -162,13 +162,19 @@ function normalizeShallowGlob(glob) {
|
|
|
162
162
|
// Shallow pattern — prepend **/
|
|
163
163
|
return `${negated ? '!' : ''}**/${bare}`;
|
|
164
164
|
}
|
|
165
|
-
/** Build engine-specific fields for a compiled rule. */
|
|
166
165
|
export function engineFields(engine, pattern) {
|
|
167
166
|
switch (engine) {
|
|
168
167
|
case 'regex':
|
|
169
168
|
return { pattern: String(pattern) };
|
|
170
169
|
case 'ast-grep':
|
|
171
|
-
|
|
170
|
+
// Route strings to the flat field and objects to the compound field.
|
|
171
|
+
// mmnto/totem#1407 split the fields for explicit mutual exclusion; the
|
|
172
|
+
// caller is responsible for passing exactly one shape. The superRefine
|
|
173
|
+
// on CompiledRuleSchema gates the persisted rule.
|
|
174
|
+
if (typeof pattern === 'string') {
|
|
175
|
+
return { pattern: '', astGrepPattern: pattern };
|
|
176
|
+
}
|
|
177
|
+
return { pattern: '', astGrepYamlRule: pattern };
|
|
172
178
|
case 'ast':
|
|
173
179
|
return { pattern: '', astQuery: String(pattern) };
|
|
174
180
|
}
|
package/dist/compiler.js.map
CHANGED
|
@@ -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;
|
|
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,M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