@mmnto/totem 1.14.11 → 1.14.13
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/adversarial.test.js +20 -15
- package/dist/adversarial.test.js.map +1 -1
- package/dist/compile-lesson.d.ts +58 -2
- package/dist/compile-lesson.d.ts.map +1 -1
- package/dist/compile-lesson.js +307 -29
- package/dist/compile-lesson.js.map +1 -1
- package/dist/compile-lesson.test.js +491 -19
- package/dist/compile-lesson.test.js.map +1 -1
- package/dist/compiler-schema.d.ts +154 -9
- package/dist/compiler-schema.d.ts.map +1 -1
- package/dist/compiler-schema.js +88 -10
- package/dist/compiler-schema.js.map +1 -1
- package/dist/compiler.d.ts +12 -4
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +25 -5
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.test.js +194 -50
- package/dist/compiler.test.js.map +1 -1
- package/dist/config-schema.d.ts +45 -0
- package/dist/config-schema.d.ts.map +1 -1
- package/dist/config-schema.js +21 -0
- package/dist/config-schema.js.map +1 -1
- package/dist/config-schema.test.js +50 -1
- package/dist/config-schema.test.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/rule-engine.d.ts +56 -13
- package/dist/rule-engine.d.ts.map +1 -1
- package/dist/rule-engine.js +62 -40
- package/dist/rule-engine.js.map +1 -1
- package/dist/rule-engine.test.js +87 -56
- package/dist/rule-engine.test.js.map +1 -1
- package/dist/rule-metrics.d.ts +40 -0
- package/dist/rule-metrics.d.ts.map +1 -1
- package/dist/rule-metrics.js +28 -0
- package/dist/rule-metrics.js.map +1 -1
- package/dist/rule-metrics.test.js +104 -3
- package/dist/rule-metrics.test.js.map +1 -1
- package/dist/rule-tester.d.ts.map +1 -1
- package/dist/rule-tester.js +9 -3
- package/dist/rule-tester.js.map +1 -1
- package/dist/test-utils.d.ts +9 -0
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js +13 -0
- package/dist/test-utils.js.map +1 -1
- package/package.json +1 -1
package/dist/adversarial.test.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
import { applyRules, applyRulesToAdditions, } from './compiler.js';
|
|
3
|
+
import { makeRuleEngineCtx } from './test-utils.js';
|
|
4
|
+
let ctx;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
ctx = makeRuleEngineCtx();
|
|
7
|
+
});
|
|
3
8
|
// ─── Adversarial Evaluation Harness ─────────────────
|
|
4
9
|
//
|
|
5
10
|
// Tests that compiled Totem rules catch planted bugs in realistic diffs.
|
|
@@ -37,7 +42,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
37
42
|
+ - run: npm run test
|
|
38
43
|
- run: pnpm build
|
|
39
44
|
`;
|
|
40
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
45
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
41
46
|
expect(violations.length).toBeGreaterThan(0); // totem-ignore
|
|
42
47
|
expect(violations.some((v) => v.rule.lessonHeading === 'Never use npm')).toBe(true);
|
|
43
48
|
});
|
|
@@ -52,7 +57,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
52
57
|
+ console.error(error);
|
|
53
58
|
}
|
|
54
59
|
`;
|
|
55
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
60
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
56
61
|
expect(violations.some((v) => v.rule.lessonHeading === 'Use err not error')).toBe(true);
|
|
57
62
|
});
|
|
58
63
|
it('catches debugger statements left in production code', () => {
|
|
@@ -66,7 +71,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
66
71
|
+ debugger;
|
|
67
72
|
return res.json();
|
|
68
73
|
`;
|
|
69
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
74
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
70
75
|
const debugViolations = violations.filter((v) => v.rule.lessonHeading === 'No debugger in production');
|
|
71
76
|
expect(debugViolations).toHaveLength(2);
|
|
72
77
|
});
|
|
@@ -80,7 +85,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
80
85
|
+ return fetchData().catch(() => {})
|
|
81
86
|
}
|
|
82
87
|
`;
|
|
83
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
88
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
84
89
|
expect(violations.some((v) => v.rule.lessonHeading === 'No empty catch blocks')).toBe(true);
|
|
85
90
|
});
|
|
86
91
|
it('catches TODO comments in new code', () => {
|
|
@@ -93,7 +98,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
93
98
|
+ // FIXME: this is a temporary hack
|
|
94
99
|
return validateToken(token);
|
|
95
100
|
`;
|
|
96
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
101
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
97
102
|
const todoViolations = violations.filter((v) => v.rule.lessonHeading === 'No TODO in production');
|
|
98
103
|
expect(todoViolations).toHaveLength(2);
|
|
99
104
|
});
|
|
@@ -107,7 +112,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
107
112
|
+ password: 'hunter2',
|
|
108
113
|
};
|
|
109
114
|
`;
|
|
110
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
115
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
111
116
|
expect(violations.some((v) => v.rule.lessonHeading === 'No hardcoded secrets')).toBe(true);
|
|
112
117
|
});
|
|
113
118
|
it('catches TypeScript any type', () => {
|
|
@@ -120,7 +125,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
120
125
|
+ metadata: any;
|
|
121
126
|
}
|
|
122
127
|
`;
|
|
123
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
128
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
124
129
|
expect(violations.some((v) => v.rule.lessonHeading === 'No any types')).toBe(true);
|
|
125
130
|
});
|
|
126
131
|
it('passes a clean diff with no violations', () => {
|
|
@@ -133,7 +138,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
133
138
|
+ return \`Hello, \${name}!\`;
|
|
134
139
|
}
|
|
135
140
|
`;
|
|
136
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
141
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
137
142
|
expect(violations).toHaveLength(0);
|
|
138
143
|
});
|
|
139
144
|
it('respects inline suppression (totem-ignore)', () => {
|
|
@@ -145,7 +150,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
145
150
|
+ debugger; // totem-ignore
|
|
146
151
|
run();
|
|
147
152
|
`;
|
|
148
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
153
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
149
154
|
const debugViolations = violations.filter((v) => v.rule.lessonHeading === 'No debugger in production');
|
|
150
155
|
expect(debugViolations).toHaveLength(0);
|
|
151
156
|
});
|
|
@@ -165,7 +170,7 @@ describe('adversarial evaluation harness', () => {
|
|
|
165
170
|
+ const data: any = fetch('/api');
|
|
166
171
|
}
|
|
167
172
|
`;
|
|
168
|
-
const violations = applyRules(ADVERSARIAL_RULES, diff);
|
|
173
|
+
const violations = applyRules(ctx, ADVERSARIAL_RULES, diff);
|
|
169
174
|
// Should catch: debugger, TODO, error (not err), any
|
|
170
175
|
expect(violations.length).toBeGreaterThanOrEqual(4); // totem-ignore
|
|
171
176
|
const headings = new Set(violations.map((v) => v.rule.lessonHeading));
|
|
@@ -204,7 +209,7 @@ describe('AST gating suppresses false positives', () => {
|
|
|
204
209
|
astContext: 'string',
|
|
205
210
|
},
|
|
206
211
|
];
|
|
207
|
-
const violations = applyRulesToAdditions(rules, additions);
|
|
212
|
+
const violations = applyRulesToAdditions(ctx, rules, additions);
|
|
208
213
|
expect(violations).toHaveLength(0);
|
|
209
214
|
});
|
|
210
215
|
it('skips violations in comment-context additions', () => {
|
|
@@ -218,7 +223,7 @@ describe('AST gating suppresses false positives', () => {
|
|
|
218
223
|
astContext: 'comment',
|
|
219
224
|
},
|
|
220
225
|
];
|
|
221
|
-
const violations = applyRulesToAdditions(rules, additions);
|
|
226
|
+
const violations = applyRulesToAdditions(ctx, rules, additions);
|
|
222
227
|
expect(violations).toHaveLength(0);
|
|
223
228
|
});
|
|
224
229
|
it('still catches violations in code-context additions', () => {
|
|
@@ -232,7 +237,7 @@ describe('AST gating suppresses false positives', () => {
|
|
|
232
237
|
astContext: 'code',
|
|
233
238
|
},
|
|
234
239
|
];
|
|
235
|
-
const violations = applyRulesToAdditions(rules, additions);
|
|
240
|
+
const violations = applyRulesToAdditions(ctx, rules, additions);
|
|
236
241
|
expect(violations.length).toBeGreaterThan(0); // totem-ignore
|
|
237
242
|
expect(violations.some((v) => v.rule.lessonHeading === 'No debugger in production')).toBe(true);
|
|
238
243
|
});
|
|
@@ -248,7 +253,7 @@ describe('AST gating suppresses false positives', () => {
|
|
|
248
253
|
// astContext is undefined
|
|
249
254
|
},
|
|
250
255
|
];
|
|
251
|
-
const violations = applyRulesToAdditions(rules, additions);
|
|
256
|
+
const violations = applyRulesToAdditions(ctx, rules, additions);
|
|
252
257
|
expect(violations.length).toBeGreaterThan(0); // totem-ignore
|
|
253
258
|
});
|
|
254
259
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial.test.js","sourceRoot":"","sources":["../src/adversarial.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial.test.js","sourceRoot":"","sources":["../src/adversarial.test.ts"],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,EAAE;QAC3E,MAAM,KAAK,GAAG,iBAAiB,CAAC;QAEhC,+DAA+D;QAC/D,MAAM,SAAS,GAAmB;YAChC;gBACE,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,aAAa;gBACnB,UAAU,EAAE,CAAC;gBACb,aAAa,EAAE,IAAI;gBACnB,0BAA0B;aAC3B;SACF,CAAC;QAEF,MAAM,UAAU,GAAG,qBAAqB,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAChE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/compile-lesson.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CompiledRule, CompilerOutput, RegexValidation } from './compiler-schema.js';
|
|
1
|
+
import type { CompiledRule, CompilerOutput, NonCompilableReasonCode, RegexValidation } from './compiler-schema.js';
|
|
2
2
|
import type { RuleTestResult } from './rule-tester.js';
|
|
3
3
|
export interface LessonInput {
|
|
4
4
|
index: number;
|
|
@@ -11,20 +11,59 @@ export interface LessonInput {
|
|
|
11
11
|
* downstream consumers (totem doctor, Layer 4 fallthrough reporting per ADR-088)
|
|
12
12
|
* can distinguish why a lesson produced no rule without string-matching
|
|
13
13
|
* human-readable messages.
|
|
14
|
+
*
|
|
15
|
+
* mmnto-ai/totem#1481 aligned this internal type 1:1 with the persisted
|
|
16
|
+
* `NonCompilableReasonCode` enum so ledger writers can pass the code through
|
|
17
|
+
* without a mapping table. `'non-compilable'` renamed to `'out-of-scope'`,
|
|
18
|
+
* `'security-verify-rejected'` renamed to `'security-rule-rejected'`, and
|
|
19
|
+
* four producer-facing codes joined: `'no-pattern-generated'`,
|
|
20
|
+
* `'pattern-syntax-invalid'`, `'pattern-zero-match'`, `'no-pattern-found'`.
|
|
21
|
+
* Fresh compile runs MUST NOT emit `'legacy-unknown'`; that sentinel exists
|
|
22
|
+
* solely for migrating pre-#1481 2-tuples.
|
|
23
|
+
*/
|
|
24
|
+
export type CompileLessonReasonCode = Exclude<NonCompilableReasonCode, 'legacy-unknown'>;
|
|
25
|
+
/**
|
|
26
|
+
* Single event inside a lesson's compile pipeline. Appended to a per-lesson
|
|
27
|
+
* `trace` array on every pipeline step (generate / verify / retry / result)
|
|
28
|
+
* and surfaced via `CompileLessonResult.trace` for the CLI `--verbose`
|
|
29
|
+
* renderer (mmnto-ai/totem#1482).
|
|
30
|
+
*
|
|
31
|
+
* `layer` numbers align with the ADR-088 staging (1 = manual, 2 = example-
|
|
32
|
+
* based, 3 = Layer 3 LLM with verify-retry). Consumers MUST tolerate unknown
|
|
33
|
+
* layer numbers so a future ADR-088 phase (dedicated Layer 1 / Layer 2
|
|
34
|
+
* telemetry) can emit without breaking the renderer.
|
|
35
|
+
*
|
|
36
|
+
* `patternHash` is a stable 16-character sha256 prefix of the emitted
|
|
37
|
+
* pattern, included only on `generate` events. Callers use it to correlate
|
|
38
|
+
* retries ("this retry produced the same pattern") without forwarding the
|
|
39
|
+
* pattern string itself.
|
|
40
|
+
*
|
|
41
|
+
* `reasonCode` is only set on the terminal `result` event when the lesson
|
|
42
|
+
* skipped. A compiled or failed lesson omits the field.
|
|
14
43
|
*/
|
|
15
|
-
export
|
|
44
|
+
export interface LayerTraceEvent {
|
|
45
|
+
layer: number;
|
|
46
|
+
action: 'generate' | 'verify' | 'retry' | 'result';
|
|
47
|
+
outcome: string;
|
|
48
|
+
patternHash?: string;
|
|
49
|
+
reasonCode?: Exclude<NonCompilableReasonCode, 'legacy-unknown'>;
|
|
50
|
+
}
|
|
16
51
|
export type CompileLessonResult = {
|
|
17
52
|
status: 'compiled';
|
|
18
53
|
rule: CompiledRule;
|
|
54
|
+
trace?: LayerTraceEvent[];
|
|
19
55
|
} | {
|
|
20
56
|
status: 'skipped';
|
|
21
57
|
hash: string;
|
|
22
58
|
reason?: string;
|
|
23
59
|
reasonCode: CompileLessonReasonCode;
|
|
60
|
+
trace?: LayerTraceEvent[];
|
|
24
61
|
} | {
|
|
25
62
|
status: 'failed';
|
|
63
|
+
trace?: LayerTraceEvent[];
|
|
26
64
|
} | {
|
|
27
65
|
status: 'noop';
|
|
66
|
+
trace?: LayerTraceEvent[];
|
|
28
67
|
};
|
|
29
68
|
export interface CompileLessonCallbacks {
|
|
30
69
|
onWarn?: (heading: string, message: string) => void;
|
|
@@ -160,6 +199,23 @@ export declare function formatExampleFailure(result: RuleTestResult): string;
|
|
|
160
199
|
* Returns { rule, rejectReason } so callers can report why a pattern was rejected.
|
|
161
200
|
*/
|
|
162
201
|
export declare function buildManualRule(lesson: LessonInput, existingByHash: Map<string, CompiledRule>): BuildRuleResult;
|
|
202
|
+
/**
|
|
203
|
+
* Security-context signal for the missing-Example-Hit check. Either the
|
|
204
|
+
* compile orchestrator asserts the pack is security-scoped
|
|
205
|
+
* (`deps.securityContext === true`) OR the rule under construction already
|
|
206
|
+
* carries `immutable: true` (set by the pack manifest, ADR-089). Both
|
|
207
|
+
* paths trigger the zero-tolerance reject per ADR-088 Decision 3.
|
|
208
|
+
*
|
|
209
|
+
* The LLM-emitted `CompilerOutput` does not currently carry an `immutable`
|
|
210
|
+
* field (packs set it at pack-merge time), so the second signal only
|
|
211
|
+
* engages on the Pipeline 1 manual-rule path where `buildManualRule`
|
|
212
|
+
* could synthesize an immutable rule directly. A future change that
|
|
213
|
+
* threads `immutable` through `CompilerOutput` can wire Pipeline 2/3
|
|
214
|
+
* into this helper without touching the call sites.
|
|
215
|
+
*/
|
|
216
|
+
export declare function isSecurityContext(deps: CompileLessonDeps, rule?: {
|
|
217
|
+
immutable?: boolean;
|
|
218
|
+
} | null): boolean;
|
|
163
219
|
/**
|
|
164
220
|
* Compile a single lesson into a rule.
|
|
165
221
|
* Handles both manual patterns (zero LLM) and LLM-compiled patterns.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-lesson.d.ts","sourceRoot":"","sources":["../src/compile-lesson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile-lesson.d.ts","sourceRoot":"","sources":["../src/compile-lesson.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,uBAAuB,EACvB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKvD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;AAEzF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;CACjE;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;CAAE,GACrE;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,uBAAuB,CAAC;IACpC,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC;CAC3B,GACD;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;CAA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