@mmnto/totem 0.17.0 → 0.18.0
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/compiler.d.ts +144 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +177 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compiler.test.d.ts +2 -0
- package/dist/compiler.test.d.ts.map +1 -0
- package/dist/compiler.test.js +259 -0
- package/dist/compiler.test.js.map +1 -0
- package/dist/config-schema.d.ts +6 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CompiledRuleSchema: z.ZodObject<{
|
|
3
|
+
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
4
|
+
lessonHash: z.ZodString;
|
|
5
|
+
/** Human-readable heading from the lesson (for diagnostics) */
|
|
6
|
+
lessonHeading: z.ZodString;
|
|
7
|
+
/** Regex pattern to match against added diff lines */
|
|
8
|
+
pattern: z.ZodString;
|
|
9
|
+
/** Human-readable violation message shown when the pattern matches */
|
|
10
|
+
message: z.ZodString;
|
|
11
|
+
/** Engine type — only 'regex' for MVP */
|
|
12
|
+
engine: z.ZodLiteral<"regex">;
|
|
13
|
+
/** ISO timestamp of when this rule was compiled */
|
|
14
|
+
compiledAt: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
lessonHash: string;
|
|
17
|
+
lessonHeading: string;
|
|
18
|
+
pattern: string;
|
|
19
|
+
message: string;
|
|
20
|
+
engine: "regex";
|
|
21
|
+
compiledAt: string;
|
|
22
|
+
}, {
|
|
23
|
+
lessonHash: string;
|
|
24
|
+
lessonHeading: string;
|
|
25
|
+
pattern: string;
|
|
26
|
+
message: string;
|
|
27
|
+
engine: "regex";
|
|
28
|
+
compiledAt: string;
|
|
29
|
+
}>;
|
|
30
|
+
export type CompiledRule = z.infer<typeof CompiledRuleSchema>;
|
|
31
|
+
export declare const CompiledRulesFileSchema: z.ZodObject<{
|
|
32
|
+
version: z.ZodLiteral<1>;
|
|
33
|
+
rules: z.ZodArray<z.ZodObject<{
|
|
34
|
+
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
35
|
+
lessonHash: z.ZodString;
|
|
36
|
+
/** Human-readable heading from the lesson (for diagnostics) */
|
|
37
|
+
lessonHeading: z.ZodString;
|
|
38
|
+
/** Regex pattern to match against added diff lines */
|
|
39
|
+
pattern: z.ZodString;
|
|
40
|
+
/** Human-readable violation message shown when the pattern matches */
|
|
41
|
+
message: z.ZodString;
|
|
42
|
+
/** Engine type — only 'regex' for MVP */
|
|
43
|
+
engine: z.ZodLiteral<"regex">;
|
|
44
|
+
/** ISO timestamp of when this rule was compiled */
|
|
45
|
+
compiledAt: z.ZodString;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
lessonHash: string;
|
|
48
|
+
lessonHeading: string;
|
|
49
|
+
pattern: string;
|
|
50
|
+
message: string;
|
|
51
|
+
engine: "regex";
|
|
52
|
+
compiledAt: string;
|
|
53
|
+
}, {
|
|
54
|
+
lessonHash: string;
|
|
55
|
+
lessonHeading: string;
|
|
56
|
+
pattern: string;
|
|
57
|
+
message: string;
|
|
58
|
+
engine: "regex";
|
|
59
|
+
compiledAt: string;
|
|
60
|
+
}>, "many">;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
version: 1;
|
|
63
|
+
rules: {
|
|
64
|
+
lessonHash: string;
|
|
65
|
+
lessonHeading: string;
|
|
66
|
+
pattern: string;
|
|
67
|
+
message: string;
|
|
68
|
+
engine: "regex";
|
|
69
|
+
compiledAt: string;
|
|
70
|
+
}[];
|
|
71
|
+
}, {
|
|
72
|
+
version: 1;
|
|
73
|
+
rules: {
|
|
74
|
+
lessonHash: string;
|
|
75
|
+
lessonHeading: string;
|
|
76
|
+
pattern: string;
|
|
77
|
+
message: string;
|
|
78
|
+
engine: "regex";
|
|
79
|
+
compiledAt: string;
|
|
80
|
+
}[];
|
|
81
|
+
}>;
|
|
82
|
+
export type CompiledRulesFile = z.infer<typeof CompiledRulesFileSchema>;
|
|
83
|
+
export interface Violation {
|
|
84
|
+
/** The rule that was violated */
|
|
85
|
+
rule: CompiledRule;
|
|
86
|
+
/** The file path from the diff where the violation occurred */
|
|
87
|
+
file: string;
|
|
88
|
+
/** The matching line content */
|
|
89
|
+
line: string;
|
|
90
|
+
/** 1-based line number within the diff hunk (approximate) */
|
|
91
|
+
lineNumber: number;
|
|
92
|
+
}
|
|
93
|
+
/** Hash a lesson's heading + body to detect changes since compilation. */
|
|
94
|
+
export declare function hashLesson(heading: string, body: string): string;
|
|
95
|
+
export interface RegexValidation {
|
|
96
|
+
valid: boolean;
|
|
97
|
+
reason?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Validate that a pattern string is a syntactically valid RegExp
|
|
101
|
+
* and is not vulnerable to ReDoS (catastrophic backtracking).
|
|
102
|
+
*/
|
|
103
|
+
export declare function validateRegex(pattern: string): RegexValidation;
|
|
104
|
+
interface DiffAddition {
|
|
105
|
+
file: string;
|
|
106
|
+
line: string;
|
|
107
|
+
lineNumber: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Extract added lines from a unified diff.
|
|
111
|
+
* Returns only lines that start with `+` (excluding `+++` file headers).
|
|
112
|
+
*/
|
|
113
|
+
export declare function extractAddedLines(diff: string): DiffAddition[];
|
|
114
|
+
/**
|
|
115
|
+
* Apply compiled rules against added lines from a diff.
|
|
116
|
+
* Returns all violations found.
|
|
117
|
+
*/
|
|
118
|
+
export declare function applyRules(rules: CompiledRule[], diff: string): Violation[];
|
|
119
|
+
/** Load compiled rules from a JSON file. Returns empty array if file missing or invalid. */
|
|
120
|
+
export declare function loadCompiledRules(rulesPath: string): CompiledRule[];
|
|
121
|
+
/** Save compiled rules to a JSON file. */
|
|
122
|
+
export declare function saveCompiledRules(rulesPath: string, rules: CompiledRule[]): void;
|
|
123
|
+
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
124
|
+
export declare const CompilerOutputSchema: z.ZodObject<{
|
|
125
|
+
compilable: z.ZodBoolean;
|
|
126
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
127
|
+
message: z.ZodOptional<z.ZodString>;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
compilable: boolean;
|
|
130
|
+
pattern?: string | undefined;
|
|
131
|
+
message?: string | undefined;
|
|
132
|
+
}, {
|
|
133
|
+
compilable: boolean;
|
|
134
|
+
pattern?: string | undefined;
|
|
135
|
+
message?: string | undefined;
|
|
136
|
+
}>;
|
|
137
|
+
export type CompilerOutput = z.infer<typeof CompilerOutputSchema>;
|
|
138
|
+
/**
|
|
139
|
+
* Parse the LLM's compilation response. Extracts JSON from the response text,
|
|
140
|
+
* validates it, and returns the structured output or null if unparseable.
|
|
141
|
+
*/
|
|
142
|
+
export declare function parseCompilerResponse(response: string): CompilerOutput | null;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,kBAAkB;IAC7B,0EAA0E;;IAE1E,+DAA+D;;IAE/D,sDAAsD;;IAEtD,sEAAsE;;IAEtE,yCAAyC;;IAEzC,mDAAmD;;;;;;;;;;;;;;;;EAEnD,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,uBAAuB;;;QAhBlC,0EAA0E;;QAE1E,+DAA+D;;QAE/D,sDAAsD;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;EAI/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAa7E"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import safeRegex from 'safe-regex2';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
// ─── Schemas ─────────────────────────────────────────
|
|
6
|
+
export const CompiledRuleSchema = z.object({
|
|
7
|
+
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
8
|
+
lessonHash: z.string(),
|
|
9
|
+
/** Human-readable heading from the lesson (for diagnostics) */
|
|
10
|
+
lessonHeading: z.string(),
|
|
11
|
+
/** Regex pattern to match against added diff lines */
|
|
12
|
+
pattern: z.string(),
|
|
13
|
+
/** Human-readable violation message shown when the pattern matches */
|
|
14
|
+
message: z.string(),
|
|
15
|
+
/** Engine type — only 'regex' for MVP */
|
|
16
|
+
engine: z.literal('regex'),
|
|
17
|
+
/** ISO timestamp of when this rule was compiled */
|
|
18
|
+
compiledAt: z.string(),
|
|
19
|
+
});
|
|
20
|
+
export const CompiledRulesFileSchema = z.object({
|
|
21
|
+
version: z.literal(1),
|
|
22
|
+
rules: z.array(CompiledRuleSchema),
|
|
23
|
+
});
|
|
24
|
+
// ─── Hashing ─────────────────────────────────────────
|
|
25
|
+
const HASH_SLICE_LEN = 16;
|
|
26
|
+
/** Hash a lesson's heading + body to detect changes since compilation. */
|
|
27
|
+
export function hashLesson(heading, body) {
|
|
28
|
+
return crypto
|
|
29
|
+
.createHash('sha256')
|
|
30
|
+
.update(`${heading}\n${body}`)
|
|
31
|
+
.digest('hex')
|
|
32
|
+
.slice(0, HASH_SLICE_LEN);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate that a pattern string is a syntactically valid RegExp
|
|
36
|
+
* and is not vulnerable to ReDoS (catastrophic backtracking).
|
|
37
|
+
*/
|
|
38
|
+
export function validateRegex(pattern) {
|
|
39
|
+
try {
|
|
40
|
+
new RegExp(pattern);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { valid: false, reason: 'invalid syntax' };
|
|
44
|
+
}
|
|
45
|
+
if (!safeRegex(pattern)) {
|
|
46
|
+
return { valid: false, reason: 'ReDoS vulnerability detected' };
|
|
47
|
+
}
|
|
48
|
+
return { valid: true };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extract added lines from a unified diff.
|
|
52
|
+
* Returns only lines that start with `+` (excluding `+++` file headers).
|
|
53
|
+
*/
|
|
54
|
+
export function extractAddedLines(diff) {
|
|
55
|
+
const additions = [];
|
|
56
|
+
let currentFile = '';
|
|
57
|
+
let lineNum = 0;
|
|
58
|
+
for (const rawLine of diff.split('\n')) {
|
|
59
|
+
// Track current file from diff headers
|
|
60
|
+
// git quotes paths containing spaces: +++ "b/path with spaces/file.ts"
|
|
61
|
+
if (rawLine.startsWith('+++')) {
|
|
62
|
+
let pathPart = rawLine.slice(4); // strip "+++ "
|
|
63
|
+
// Strip surrounding quotes (git adds them for paths with spaces)
|
|
64
|
+
if (pathPart.startsWith('"') && pathPart.endsWith('"')) {
|
|
65
|
+
pathPart = pathPart.slice(1, -1);
|
|
66
|
+
}
|
|
67
|
+
// Strip the "b/" prefix git uses for the destination file
|
|
68
|
+
currentFile = pathPart.startsWith('b/') ? pathPart.slice(2) : pathPart;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// Parse hunk header for line numbers: @@ -X,Y +Z,W @@
|
|
72
|
+
const hunkMatch = rawLine.match(/^@@ -\d+(?:,\d+)? \+(\d+)/);
|
|
73
|
+
if (hunkMatch) {
|
|
74
|
+
lineNum = parseInt(hunkMatch[1], 10) - 1; // will be incremented on first line
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Skip diff metadata lines
|
|
78
|
+
if (rawLine.startsWith('---') || rawLine.startsWith('diff ') || rawLine.startsWith('index ')) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
// Count lines for position tracking
|
|
82
|
+
if (rawLine.startsWith('+')) {
|
|
83
|
+
lineNum++;
|
|
84
|
+
additions.push({
|
|
85
|
+
file: currentFile,
|
|
86
|
+
line: rawLine.slice(1), // strip the leading +
|
|
87
|
+
lineNumber: lineNum,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (!rawLine.startsWith('-')) {
|
|
91
|
+
// Context line (no prefix or space prefix) — increment line counter
|
|
92
|
+
lineNum++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return additions;
|
|
96
|
+
}
|
|
97
|
+
// ─── Rule execution ──────────────────────────────────
|
|
98
|
+
/**
|
|
99
|
+
* Apply compiled rules against added lines from a diff.
|
|
100
|
+
* Returns all violations found.
|
|
101
|
+
*/
|
|
102
|
+
export function applyRules(rules, diff) {
|
|
103
|
+
const additions = extractAddedLines(diff);
|
|
104
|
+
if (additions.length === 0 || rules.length === 0)
|
|
105
|
+
return [];
|
|
106
|
+
const violations = [];
|
|
107
|
+
for (const rule of rules) {
|
|
108
|
+
let re;
|
|
109
|
+
try {
|
|
110
|
+
re = new RegExp(rule.pattern);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Skip invalid patterns (shouldn't happen if validation gate works)
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
for (const addition of additions) {
|
|
117
|
+
if (re.test(addition.line)) {
|
|
118
|
+
violations.push({
|
|
119
|
+
rule,
|
|
120
|
+
file: addition.file,
|
|
121
|
+
line: addition.line,
|
|
122
|
+
lineNumber: addition.lineNumber,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return violations;
|
|
128
|
+
}
|
|
129
|
+
// ─── File I/O ────────────────────────────────────────
|
|
130
|
+
/** Load compiled rules from a JSON file. Returns empty array if file missing or invalid. */
|
|
131
|
+
export function loadCompiledRules(rulesPath) {
|
|
132
|
+
if (!fs.existsSync(rulesPath))
|
|
133
|
+
return [];
|
|
134
|
+
try {
|
|
135
|
+
const raw = fs.readFileSync(rulesPath, 'utf-8');
|
|
136
|
+
const parsed = CompiledRulesFileSchema.parse(JSON.parse(raw));
|
|
137
|
+
return parsed.rules;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Save compiled rules to a JSON file. */
|
|
144
|
+
export function saveCompiledRules(rulesPath, rules) {
|
|
145
|
+
const data = { version: 1, rules };
|
|
146
|
+
fs.writeFileSync(rulesPath, JSON.stringify(data, null, 2) + '\n', {
|
|
147
|
+
encoding: 'utf-8',
|
|
148
|
+
mode: 0o644,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// ─── LLM response parsing ───────────────────────────
|
|
152
|
+
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
153
|
+
export const CompilerOutputSchema = z.object({
|
|
154
|
+
compilable: z.boolean(),
|
|
155
|
+
pattern: z.string().optional(),
|
|
156
|
+
message: z.string().optional(),
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* Parse the LLM's compilation response. Extracts JSON from the response text,
|
|
160
|
+
* validates it, and returns the structured output or null if unparseable.
|
|
161
|
+
*/
|
|
162
|
+
export function parseCompilerResponse(response) {
|
|
163
|
+
// Try to extract JSON from the response (LLMs often wrap in ```json blocks)
|
|
164
|
+
const jsonMatch = response.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
|
|
165
|
+
const jsonStr = jsonMatch ? jsonMatch[1] : response.trim();
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(jsonStr);
|
|
168
|
+
const result = CompilerOutputSchema.safeParse(parsed);
|
|
169
|
+
if (!result.success)
|
|
170
|
+
return null;
|
|
171
|
+
return result.data;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,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;AAExB,wDAAwD;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,0EAA0E;IAC1E,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,+DAA+D;IAC/D,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,sDAAsD;IACtD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,sEAAsE;IACtE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,yCAAyC;IACzC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAC1B,mDAAmD;IACnD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC;CACnC,CAAC,CAAC;AAiBH,wDAAwD;AAExD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,IAAY;IACtD,OAAO,MAAM;SACV,UAAU,CAAC,QAAQ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:fs';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { applyRules, extractAddedLines, hashLesson, loadCompiledRules, parseCompilerResponse, saveCompiledRules, validateRegex, } from './compiler.js';
|
|
6
|
+
// ─── hashLesson ──────────────────────────────────────
|
|
7
|
+
describe('hashLesson', () => {
|
|
8
|
+
it('returns a 16-char hex string', () => {
|
|
9
|
+
const hash = hashLesson('heading', 'body');
|
|
10
|
+
expect(hash).toMatch(/^[0-9a-f]{16}$/);
|
|
11
|
+
});
|
|
12
|
+
it('returns different hashes for different inputs', () => {
|
|
13
|
+
const h1 = hashLesson('heading1', 'body');
|
|
14
|
+
const h2 = hashLesson('heading2', 'body');
|
|
15
|
+
expect(h1).not.toBe(h2);
|
|
16
|
+
});
|
|
17
|
+
it('returns stable hashes for the same input', () => {
|
|
18
|
+
const h1 = hashLesson('heading', 'body');
|
|
19
|
+
const h2 = hashLesson('heading', 'body');
|
|
20
|
+
expect(h1).toBe(h2);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
// ─── validateRegex ───────────────────────────────────
|
|
24
|
+
describe('validateRegex', () => {
|
|
25
|
+
it('accepts a valid regex', () => {
|
|
26
|
+
expect(validateRegex('\\bfoo\\b')).toEqual({ valid: true });
|
|
27
|
+
});
|
|
28
|
+
it('accepts a simple string pattern', () => {
|
|
29
|
+
expect(validateRegex('console.log')).toEqual({ valid: true });
|
|
30
|
+
});
|
|
31
|
+
it('accepts a complex but safe pattern', () => {
|
|
32
|
+
// Anchored API key format — complex but not vulnerable
|
|
33
|
+
expect(validateRegex('^[A-Za-z0-9]{32,}$')).toEqual({ valid: true });
|
|
34
|
+
});
|
|
35
|
+
it('rejects an invalid regex', () => {
|
|
36
|
+
const result = validateRegex('[invalid');
|
|
37
|
+
expect(result.valid).toBe(false);
|
|
38
|
+
expect(result.reason).toBe('invalid syntax');
|
|
39
|
+
});
|
|
40
|
+
it('rejects unbalanced parentheses', () => {
|
|
41
|
+
const result = validateRegex('(unclosed');
|
|
42
|
+
expect(result.valid).toBe(false);
|
|
43
|
+
expect(result.reason).toBe('invalid syntax');
|
|
44
|
+
});
|
|
45
|
+
it('rejects ReDoS pattern: nested quantifiers (a+)+', () => {
|
|
46
|
+
const result = validateRegex('(a+)+$');
|
|
47
|
+
expect(result.valid).toBe(false);
|
|
48
|
+
expect(result.reason).toBe('ReDoS vulnerability detected');
|
|
49
|
+
});
|
|
50
|
+
it('rejects ReDoS pattern: nested character class quantifiers ([a-zA-Z]+)*', () => {
|
|
51
|
+
const result = validateRegex('([a-zA-Z]+)*');
|
|
52
|
+
expect(result.valid).toBe(false);
|
|
53
|
+
expect(result.reason).toBe('ReDoS vulnerability detected');
|
|
54
|
+
});
|
|
55
|
+
it('rejects ReDoS pattern: nested repetition (.*a){10}', () => {
|
|
56
|
+
const result = validateRegex('(.*a){10}');
|
|
57
|
+
expect(result.valid).toBe(false);
|
|
58
|
+
expect(result.reason).toBe('ReDoS vulnerability detected');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
// ─── extractAddedLines ──────────────────────────────
|
|
62
|
+
describe('extractAddedLines', () => {
|
|
63
|
+
it('extracts added lines from a unified diff', () => {
|
|
64
|
+
const diff = `diff --git a/src/foo.ts b/src/foo.ts
|
|
65
|
+
index abc1234..def5678 100644
|
|
66
|
+
--- a/src/foo.ts
|
|
67
|
+
+++ b/src/foo.ts
|
|
68
|
+
@@ -1,3 +1,4 @@
|
|
69
|
+
const a = 1;
|
|
70
|
+
-const b = 2;
|
|
71
|
+
+const b = 3;
|
|
72
|
+
+const c = 4;
|
|
73
|
+
const d = 5;
|
|
74
|
+
`;
|
|
75
|
+
const additions = extractAddedLines(diff);
|
|
76
|
+
expect(additions).toHaveLength(2);
|
|
77
|
+
expect(additions[0]).toEqual({ file: 'src/foo.ts', line: 'const b = 3;', lineNumber: 2 });
|
|
78
|
+
expect(additions[1]).toEqual({ file: 'src/foo.ts', line: 'const c = 4;', lineNumber: 3 });
|
|
79
|
+
});
|
|
80
|
+
it('handles multiple files', () => {
|
|
81
|
+
const diff = `diff --git a/a.ts b/a.ts
|
|
82
|
+
--- a/a.ts
|
|
83
|
+
+++ b/a.ts
|
|
84
|
+
@@ -1,2 +1,3 @@
|
|
85
|
+
line1
|
|
86
|
+
+added in a
|
|
87
|
+
line2
|
|
88
|
+
diff --git a/b.ts b/b.ts
|
|
89
|
+
--- a/b.ts
|
|
90
|
+
+++ b/b.ts
|
|
91
|
+
@@ -1,2 +1,3 @@
|
|
92
|
+
line1
|
|
93
|
+
+added in b
|
|
94
|
+
line2
|
|
95
|
+
`;
|
|
96
|
+
const additions = extractAddedLines(diff);
|
|
97
|
+
expect(additions).toHaveLength(2);
|
|
98
|
+
expect(additions[0].file).toBe('a.ts');
|
|
99
|
+
expect(additions[1].file).toBe('b.ts');
|
|
100
|
+
});
|
|
101
|
+
it('returns empty array for empty diff', () => {
|
|
102
|
+
expect(extractAddedLines('')).toEqual([]);
|
|
103
|
+
});
|
|
104
|
+
it('handles quoted filenames with spaces', () => {
|
|
105
|
+
const diff = `diff --git "a/path with spaces/file.ts" "b/path with spaces/file.ts"
|
|
106
|
+
--- "a/path with spaces/file.ts"
|
|
107
|
+
+++ "b/path with spaces/file.ts"
|
|
108
|
+
@@ -1,2 +1,3 @@
|
|
109
|
+
line1
|
|
110
|
+
+added line
|
|
111
|
+
line2
|
|
112
|
+
`;
|
|
113
|
+
const additions = extractAddedLines(diff);
|
|
114
|
+
expect(additions).toHaveLength(1);
|
|
115
|
+
expect(additions[0].file).toBe('path with spaces/file.ts');
|
|
116
|
+
});
|
|
117
|
+
it('returns empty array for deletion-only diff', () => {
|
|
118
|
+
const diff = `diff --git a/foo.ts b/foo.ts
|
|
119
|
+
--- a/foo.ts
|
|
120
|
+
+++ b/foo.ts
|
|
121
|
+
@@ -1,3 +1,2 @@
|
|
122
|
+
line1
|
|
123
|
+
-removed
|
|
124
|
+
line2
|
|
125
|
+
`;
|
|
126
|
+
expect(extractAddedLines(diff)).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
// ─── applyRules ──────────────────────────────────────
|
|
130
|
+
describe('applyRules', () => {
|
|
131
|
+
const makeRule = (pattern, message) => ({
|
|
132
|
+
lessonHash: 'abc123',
|
|
133
|
+
lessonHeading: 'Test rule',
|
|
134
|
+
pattern,
|
|
135
|
+
message,
|
|
136
|
+
engine: 'regex',
|
|
137
|
+
compiledAt: new Date().toISOString(),
|
|
138
|
+
});
|
|
139
|
+
const diff = `diff --git a/src/app.ts b/src/app.ts
|
|
140
|
+
--- a/src/app.ts
|
|
141
|
+
+++ b/src/app.ts
|
|
142
|
+
@@ -1,3 +1,5 @@
|
|
143
|
+
import { foo } from './foo';
|
|
144
|
+
+import { error } from './errors';
|
|
145
|
+
+const result = npm.install('package');
|
|
146
|
+
export default foo;
|
|
147
|
+
`;
|
|
148
|
+
it('detects a simple pattern violation', () => {
|
|
149
|
+
const rules = [makeRule('\\bnpm\\.install\\b', 'Do not call npm.install directly')];
|
|
150
|
+
const violations = applyRules(rules, diff);
|
|
151
|
+
expect(violations).toHaveLength(1);
|
|
152
|
+
expect(violations[0].rule.message).toBe('Do not call npm.install directly');
|
|
153
|
+
expect(violations[0].file).toBe('src/app.ts');
|
|
154
|
+
});
|
|
155
|
+
it('returns no violations when patterns do not match', () => {
|
|
156
|
+
const rules = [makeRule('\\byarn\\b', 'Do not use yarn')];
|
|
157
|
+
const violations = applyRules(rules, diff);
|
|
158
|
+
expect(violations).toHaveLength(0);
|
|
159
|
+
});
|
|
160
|
+
it('applies multiple rules', () => {
|
|
161
|
+
const rules = [
|
|
162
|
+
makeRule('\\bnpm\\b', 'Do not use npm'),
|
|
163
|
+
makeRule('\\berror\\b', 'Use err, not error'),
|
|
164
|
+
];
|
|
165
|
+
const violations = applyRules(rules, diff);
|
|
166
|
+
expect(violations).toHaveLength(2);
|
|
167
|
+
});
|
|
168
|
+
it('skips rules with invalid patterns', () => {
|
|
169
|
+
const rules = [makeRule('[invalid', 'Bad pattern')];
|
|
170
|
+
const violations = applyRules(rules, diff);
|
|
171
|
+
expect(violations).toHaveLength(0);
|
|
172
|
+
});
|
|
173
|
+
it('returns empty for empty diff', () => {
|
|
174
|
+
const rules = [makeRule('anything', 'test')];
|
|
175
|
+
expect(applyRules(rules, '')).toEqual([]);
|
|
176
|
+
});
|
|
177
|
+
it('returns empty for empty rules', () => {
|
|
178
|
+
expect(applyRules([], diff)).toEqual([]);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
// ─── loadCompiledRules / saveCompiledRules ───────────
|
|
182
|
+
describe('compiled rules file I/O', () => {
|
|
183
|
+
let tmpDir;
|
|
184
|
+
beforeEach(() => {
|
|
185
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'totem-compiler-'));
|
|
186
|
+
});
|
|
187
|
+
afterEach(() => {
|
|
188
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
189
|
+
});
|
|
190
|
+
it('round-trips rules through save and load', () => {
|
|
191
|
+
const rulesPath = path.join(tmpDir, 'compiled-rules.json');
|
|
192
|
+
const rules = [
|
|
193
|
+
{
|
|
194
|
+
lessonHash: 'abc123def456',
|
|
195
|
+
lessonHeading: 'Use err not error',
|
|
196
|
+
pattern: '\\berror\\b',
|
|
197
|
+
message: 'Use err instead of error in catch blocks',
|
|
198
|
+
engine: 'regex',
|
|
199
|
+
compiledAt: '2026-03-08T12:00:00Z',
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
saveCompiledRules(rulesPath, rules);
|
|
203
|
+
const loaded = loadCompiledRules(rulesPath);
|
|
204
|
+
expect(loaded).toEqual(rules);
|
|
205
|
+
});
|
|
206
|
+
it('returns empty array for missing file', () => {
|
|
207
|
+
const loaded = loadCompiledRules(path.join(tmpDir, 'nonexistent.json'));
|
|
208
|
+
expect(loaded).toEqual([]);
|
|
209
|
+
});
|
|
210
|
+
it('returns empty array for invalid JSON', () => {
|
|
211
|
+
const rulesPath = path.join(tmpDir, 'bad.json');
|
|
212
|
+
fs.writeFileSync(rulesPath, 'not valid json');
|
|
213
|
+
expect(loadCompiledRules(rulesPath)).toEqual([]);
|
|
214
|
+
});
|
|
215
|
+
it('returns empty array for wrong schema', () => {
|
|
216
|
+
const rulesPath = path.join(tmpDir, 'wrong.json');
|
|
217
|
+
fs.writeFileSync(rulesPath, JSON.stringify({ version: 99, rules: [] }));
|
|
218
|
+
expect(loadCompiledRules(rulesPath)).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
// ─── parseCompilerResponse ──────────────────────────
|
|
222
|
+
describe('parseCompilerResponse', () => {
|
|
223
|
+
it('parses a valid compilable response', () => {
|
|
224
|
+
const response = JSON.stringify({
|
|
225
|
+
compilable: true,
|
|
226
|
+
pattern: '\\bnpm\\b',
|
|
227
|
+
message: 'Use pnpm instead of npm',
|
|
228
|
+
});
|
|
229
|
+
const result = parseCompilerResponse(response);
|
|
230
|
+
expect(result).toEqual({
|
|
231
|
+
compilable: true,
|
|
232
|
+
pattern: '\\bnpm\\b',
|
|
233
|
+
message: 'Use pnpm instead of npm',
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
it('parses a non-compilable response', () => {
|
|
237
|
+
const response = JSON.stringify({ compilable: false });
|
|
238
|
+
const result = parseCompilerResponse(response);
|
|
239
|
+
expect(result).toEqual({ compilable: false });
|
|
240
|
+
});
|
|
241
|
+
it('extracts JSON from a code fence', () => {
|
|
242
|
+
const response = `Here is the compiled rule:
|
|
243
|
+
\`\`\`json
|
|
244
|
+
{"compilable": true, "pattern": "console\\\\.log", "message": "Remove debug logging"}
|
|
245
|
+
\`\`\``;
|
|
246
|
+
const result = parseCompilerResponse(response);
|
|
247
|
+
expect(result).not.toBeNull();
|
|
248
|
+
expect(result.compilable).toBe(true);
|
|
249
|
+
expect(result.pattern).toBe('console\\.log');
|
|
250
|
+
});
|
|
251
|
+
it('returns null for completely invalid output', () => {
|
|
252
|
+
expect(parseCompilerResponse('I cannot compile this lesson.')).toBeNull();
|
|
253
|
+
});
|
|
254
|
+
it('returns null for JSON with wrong schema', () => {
|
|
255
|
+
const response = JSON.stringify({ foo: 'bar' });
|
|
256
|
+
expect(parseCompilerResponse(response)).toBeNull();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=compiler.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.test.js","sourceRoot":"","sources":["../src/compiler.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,EACL,UAAU,EAEV,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,wDAAwD;AAExD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,EAAE,GAAG,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,EAAE,GAAG,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CA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 @@ export declare const IngestTargetSchema: z.ZodObject<{
|
|
|
9
9
|
type: z.ZodEnum<["code", "session_log", "spec"]>;
|
|
10
10
|
strategy: z.ZodEnum<["typescript-ast", "markdown-heading", "session-log", "schema-file", "test-file"]>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
glob: string;
|
|
13
12
|
type: "code" | "session_log" | "spec";
|
|
13
|
+
glob: string;
|
|
14
14
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
15
15
|
}, {
|
|
16
|
-
glob: string;
|
|
17
16
|
type: "code" | "session_log" | "spec";
|
|
17
|
+
glob: string;
|
|
18
18
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
19
19
|
}>;
|
|
20
20
|
export declare const OpenAIProviderSchema: z.ZodObject<{
|
|
@@ -154,12 +154,12 @@ export declare const TotemConfigSchema: z.ZodObject<{
|
|
|
154
154
|
type: z.ZodEnum<["code", "session_log", "spec"]>;
|
|
155
155
|
strategy: z.ZodEnum<["typescript-ast", "markdown-heading", "session-log", "schema-file", "test-file"]>;
|
|
156
156
|
}, "strip", z.ZodTypeAny, {
|
|
157
|
-
glob: string;
|
|
158
157
|
type: "code" | "session_log" | "spec";
|
|
158
|
+
glob: string;
|
|
159
159
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
160
160
|
}, {
|
|
161
|
-
glob: string;
|
|
162
161
|
type: "code" | "session_log" | "spec";
|
|
162
|
+
glob: string;
|
|
163
163
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
164
164
|
}>, "many">;
|
|
165
165
|
/** Embedding provider configuration (optional for Lite tier) */
|
|
@@ -246,8 +246,8 @@ export declare const TotemConfigSchema: z.ZodObject<{
|
|
|
246
246
|
}>, "many">>;
|
|
247
247
|
}, "strip", z.ZodTypeAny, {
|
|
248
248
|
targets: {
|
|
249
|
-
glob: string;
|
|
250
249
|
type: "code" | "session_log" | "spec";
|
|
250
|
+
glob: string;
|
|
251
251
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
252
252
|
}[];
|
|
253
253
|
totemDir: string;
|
|
@@ -279,8 +279,8 @@ export declare const TotemConfigSchema: z.ZodObject<{
|
|
|
279
279
|
}[] | undefined;
|
|
280
280
|
}, {
|
|
281
281
|
targets: {
|
|
282
|
-
glob: string;
|
|
283
282
|
type: "code" | "session_log" | "spec";
|
|
283
|
+
glob: string;
|
|
284
284
|
strategy: "typescript-ast" | "markdown-heading" | "session-log" | "schema-file" | "test-file";
|
|
285
285
|
}[];
|
|
286
286
|
embedding?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type { ResolvedFile } from './ingest/sync.js';
|
|
|
11
11
|
export { getChangedFiles, getHeadSha, resolveFiles, runSync } from './ingest/sync.js';
|
|
12
12
|
export type { DriftResult, ParsedLesson } from './drift-detector.js';
|
|
13
13
|
export { detectDrift, extractFileReferences, parseLessonsFile, rewriteLessonsFile, } from './drift-detector.js';
|
|
14
|
+
export type { CompiledRule, CompiledRulesFile, CompilerOutput, Violation } from './compiler.js';
|
|
15
|
+
export { applyRules, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, extractAddedLines, hashLesson, loadCompiledRules, parseCompilerResponse, type RegexValidation, saveCompiledRules, validateRegex, } from './compiler.js';
|
|
14
16
|
export { generateLessonHeading } from './lesson-format.js';
|
|
15
17
|
export { sanitize } from './sanitize.js';
|
|
16
18
|
export { wrapXml } from './xml-format.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,oBAAoB,C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,eAAe,EACpB,iBAAiB,EACjB,aAAa,GACd,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { TOTEM_TABLE_NAME } from './store/lance-schema.js';
|
|
|
6
6
|
export { LanceStore } from './store/lance-store.js';
|
|
7
7
|
export { getChangedFiles, getHeadSha, resolveFiles, runSync } from './ingest/sync.js';
|
|
8
8
|
export { detectDrift, extractFileReferences, parseLessonsFile, rewriteLessonsFile, } from './drift-detector.js';
|
|
9
|
+
export { applyRules, CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, extractAddedLines, hashLesson, loadCompiledRules, parseCompilerResponse, saveCompiledRules, validateRegex, } from './compiler.js';
|
|
9
10
|
// Utilities
|
|
10
11
|
export { generateLessonHeading } from './lesson-format.js';
|
|
11
12
|
export { sanitize } from './sanitize.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAc5B,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAItD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,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}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmnto/totem",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Persistent memory and context layer for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"openai": "^4.77.0",
|
|
19
19
|
"remark-frontmatter": "^5.0.0",
|
|
20
20
|
"remark-parse": "^11.0.0",
|
|
21
|
+
"safe-regex2": "^5.0.0",
|
|
21
22
|
"typescript": "^5.7.0",
|
|
22
23
|
"unified": "^11.0.0",
|
|
23
24
|
"yaml": "^2.4.0",
|