@mmnto/totem 1.2.0 → 1.3.1
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-schema.d.ts +201 -0
- package/dist/compiler-schema.d.ts.map +1 -0
- package/dist/compiler-schema.js +46 -0
- package/dist/compiler-schema.js.map +1 -0
- package/dist/compiler.d.ts +14 -230
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +17 -380
- package/dist/compiler.js.map +1 -1
- package/dist/diff-parser.d.ts +8 -0
- package/dist/diff-parser.d.ts.map +1 -0
- package/dist/diff-parser.js +70 -0
- package/dist/diff-parser.js.map +1 -0
- package/dist/embedders/embedder.d.ts.map +1 -1
- package/dist/embedders/embedder.js +3 -7
- package/dist/embedders/embedder.js.map +1 -1
- package/dist/embedders/gemini-embedder.d.ts.map +1 -1
- package/dist/embedders/gemini-embedder.js +7 -9
- package/dist/embedders/gemini-embedder.js.map +1 -1
- package/dist/embedders/openai-embedder.d.ts.map +1 -1
- package/dist/embedders/openai-embedder.js +4 -4
- package/dist/embedders/openai-embedder.js.map +1 -1
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +3 -2
- package/dist/exporter.js.map +1 -1
- package/dist/lock.d.ts.map +1 -1
- package/dist/lock.js +2 -2
- package/dist/lock.js.map +1 -1
- package/dist/rule-engine.d.ts +31 -0
- package/dist/rule-engine.d.ts.map +1 -0
- package/dist/rule-engine.js +278 -0
- package/dist/rule-engine.js.map +1 -0
- package/dist/sarif.d.ts.map +1 -1
- package/dist/sarif.js +2 -1
- package/dist/sarif.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
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 — 'regex' for line-level matching, 'ast' for Tree-sitter S-expression queries, 'ast-grep' for ast-grep structural patterns */
|
|
12
|
+
engine: z.ZodEnum<["regex", "ast", "ast-grep"]>;
|
|
13
|
+
/** Tree-sitter S-expression query (required when engine is 'ast') */
|
|
14
|
+
astQuery: z.ZodOptional<z.ZodString>;
|
|
15
|
+
/** ast-grep pattern — string for simple patterns, object for compound rules (has/inside/not) */
|
|
16
|
+
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
17
|
+
/** ISO timestamp of when this rule was compiled */
|
|
18
|
+
compiledAt: z.ZodString;
|
|
19
|
+
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
20
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
21
|
+
/** Optional file glob patterns — rule only applies to matching files (e.g., ["*.sh", "*.yml"]) */
|
|
22
|
+
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
23
|
+
/** Rule category for Trap Ledger classification */
|
|
24
|
+
category: z.ZodOptional<z.ZodEnum<["security", "architecture", "style", "performance"]>>;
|
|
25
|
+
/** Severity level — error blocks CI, warning reports but doesn't fail */
|
|
26
|
+
severity: z.ZodOptional<z.ZodEnum<["error", "warning"]>>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
lessonHash: string;
|
|
29
|
+
lessonHeading: string;
|
|
30
|
+
pattern: string;
|
|
31
|
+
message: string;
|
|
32
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
33
|
+
compiledAt: string;
|
|
34
|
+
astQuery?: string | undefined;
|
|
35
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
36
|
+
createdAt?: string | undefined;
|
|
37
|
+
fileGlobs?: string[] | undefined;
|
|
38
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
39
|
+
severity?: "error" | "warning" | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
lessonHash: string;
|
|
42
|
+
lessonHeading: string;
|
|
43
|
+
pattern: string;
|
|
44
|
+
message: string;
|
|
45
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
46
|
+
compiledAt: string;
|
|
47
|
+
astQuery?: string | undefined;
|
|
48
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
49
|
+
createdAt?: string | undefined;
|
|
50
|
+
fileGlobs?: string[] | undefined;
|
|
51
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
52
|
+
severity?: "error" | "warning" | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
export type CompiledRule = z.infer<typeof CompiledRuleSchema>;
|
|
55
|
+
export declare const CompiledRulesFileSchema: z.ZodObject<{
|
|
56
|
+
version: z.ZodLiteral<1>;
|
|
57
|
+
rules: z.ZodArray<z.ZodObject<{
|
|
58
|
+
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
59
|
+
lessonHash: z.ZodString;
|
|
60
|
+
/** Human-readable heading from the lesson (for diagnostics) */
|
|
61
|
+
lessonHeading: z.ZodString;
|
|
62
|
+
/** Regex pattern to match against added diff lines */
|
|
63
|
+
pattern: z.ZodString;
|
|
64
|
+
/** Human-readable violation message shown when the pattern matches */
|
|
65
|
+
message: z.ZodString;
|
|
66
|
+
/** Engine type — 'regex' for line-level matching, 'ast' for Tree-sitter S-expression queries, 'ast-grep' for ast-grep structural patterns */
|
|
67
|
+
engine: z.ZodEnum<["regex", "ast", "ast-grep"]>;
|
|
68
|
+
/** Tree-sitter S-expression query (required when engine is 'ast') */
|
|
69
|
+
astQuery: z.ZodOptional<z.ZodString>;
|
|
70
|
+
/** ast-grep pattern — string for simple patterns, object for compound rules (has/inside/not) */
|
|
71
|
+
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
72
|
+
/** ISO timestamp of when this rule was compiled */
|
|
73
|
+
compiledAt: z.ZodString;
|
|
74
|
+
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
75
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
76
|
+
/** Optional file glob patterns — rule only applies to matching files (e.g., ["*.sh", "*.yml"]) */
|
|
77
|
+
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
78
|
+
/** Rule category for Trap Ledger classification */
|
|
79
|
+
category: z.ZodOptional<z.ZodEnum<["security", "architecture", "style", "performance"]>>;
|
|
80
|
+
/** Severity level — error blocks CI, warning reports but doesn't fail */
|
|
81
|
+
severity: z.ZodOptional<z.ZodEnum<["error", "warning"]>>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
lessonHash: string;
|
|
84
|
+
lessonHeading: string;
|
|
85
|
+
pattern: string;
|
|
86
|
+
message: string;
|
|
87
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
88
|
+
compiledAt: string;
|
|
89
|
+
astQuery?: string | undefined;
|
|
90
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
91
|
+
createdAt?: string | undefined;
|
|
92
|
+
fileGlobs?: string[] | undefined;
|
|
93
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
94
|
+
severity?: "error" | "warning" | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
lessonHash: string;
|
|
97
|
+
lessonHeading: string;
|
|
98
|
+
pattern: string;
|
|
99
|
+
message: string;
|
|
100
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
101
|
+
compiledAt: string;
|
|
102
|
+
astQuery?: string | undefined;
|
|
103
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
104
|
+
createdAt?: string | undefined;
|
|
105
|
+
fileGlobs?: string[] | undefined;
|
|
106
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
107
|
+
severity?: "error" | "warning" | undefined;
|
|
108
|
+
}>, "many">;
|
|
109
|
+
/** Lesson hashes that the LLM determined cannot be compiled (conceptual/architectural). */
|
|
110
|
+
nonCompilable: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
version: 1;
|
|
113
|
+
rules: {
|
|
114
|
+
lessonHash: string;
|
|
115
|
+
lessonHeading: string;
|
|
116
|
+
pattern: string;
|
|
117
|
+
message: string;
|
|
118
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
119
|
+
compiledAt: string;
|
|
120
|
+
astQuery?: string | undefined;
|
|
121
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
122
|
+
createdAt?: string | undefined;
|
|
123
|
+
fileGlobs?: string[] | undefined;
|
|
124
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
125
|
+
severity?: "error" | "warning" | undefined;
|
|
126
|
+
}[];
|
|
127
|
+
nonCompilable?: string[] | undefined;
|
|
128
|
+
}, {
|
|
129
|
+
version: 1;
|
|
130
|
+
rules: {
|
|
131
|
+
lessonHash: string;
|
|
132
|
+
lessonHeading: string;
|
|
133
|
+
pattern: string;
|
|
134
|
+
message: string;
|
|
135
|
+
engine: "regex" | "ast" | "ast-grep";
|
|
136
|
+
compiledAt: string;
|
|
137
|
+
astQuery?: string | undefined;
|
|
138
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
139
|
+
createdAt?: string | undefined;
|
|
140
|
+
fileGlobs?: string[] | undefined;
|
|
141
|
+
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
142
|
+
severity?: "error" | "warning" | undefined;
|
|
143
|
+
}[];
|
|
144
|
+
nonCompilable?: string[] | undefined;
|
|
145
|
+
}>;
|
|
146
|
+
export type CompiledRulesFile = z.infer<typeof CompiledRulesFileSchema>;
|
|
147
|
+
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
148
|
+
export declare const CompilerOutputSchema: z.ZodObject<{
|
|
149
|
+
compilable: z.ZodBoolean;
|
|
150
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
151
|
+
message: z.ZodOptional<z.ZodString>;
|
|
152
|
+
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
153
|
+
engine: z.ZodOptional<z.ZodEnum<["regex", "ast", "ast-grep"]>>;
|
|
154
|
+
astQuery: z.ZodOptional<z.ZodString>;
|
|
155
|
+
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
156
|
+
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
compilable: boolean;
|
|
158
|
+
pattern?: string | undefined;
|
|
159
|
+
message?: string | undefined;
|
|
160
|
+
engine?: "regex" | "ast" | "ast-grep" | undefined;
|
|
161
|
+
astQuery?: string | undefined;
|
|
162
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
163
|
+
fileGlobs?: string[] | undefined;
|
|
164
|
+
}, {
|
|
165
|
+
compilable: boolean;
|
|
166
|
+
pattern?: string | undefined;
|
|
167
|
+
message?: string | undefined;
|
|
168
|
+
engine?: "regex" | "ast" | "ast-grep" | undefined;
|
|
169
|
+
astQuery?: string | undefined;
|
|
170
|
+
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
171
|
+
fileGlobs?: string[] | undefined;
|
|
172
|
+
}>;
|
|
173
|
+
export type CompilerOutput = z.infer<typeof CompilerOutputSchema>;
|
|
174
|
+
export interface Violation {
|
|
175
|
+
/** The rule that was violated */
|
|
176
|
+
rule: CompiledRule;
|
|
177
|
+
/** The file path from the diff where the violation occurred */
|
|
178
|
+
file: string;
|
|
179
|
+
/** The matching line content */
|
|
180
|
+
line: string;
|
|
181
|
+
/** 1-based line number within the diff hunk (approximate) */
|
|
182
|
+
lineNumber: number;
|
|
183
|
+
}
|
|
184
|
+
/** Syntactic context of a diff line, determined by AST analysis. */
|
|
185
|
+
export type AstContext = 'code' | 'string' | 'comment' | 'regex';
|
|
186
|
+
export interface DiffAddition {
|
|
187
|
+
file: string;
|
|
188
|
+
line: string;
|
|
189
|
+
lineNumber: number;
|
|
190
|
+
/** Content of the preceding line in the new file (context or added), null if first in hunk */
|
|
191
|
+
precedingLine: string | null;
|
|
192
|
+
/** Syntactic context from AST analysis — undefined means not classified (fail-open as code) */
|
|
193
|
+
astContext?: AstContext;
|
|
194
|
+
}
|
|
195
|
+
export interface RegexValidation {
|
|
196
|
+
valid: boolean;
|
|
197
|
+
reason?: string;
|
|
198
|
+
}
|
|
199
|
+
/** Callback for observability — invoked when a rule is suppressed or triggered. */
|
|
200
|
+
export type RuleEventCallback = (event: 'trigger' | 'suppress', lessonHash: string) => void;
|
|
201
|
+
//# sourceMappingURL=compiler-schema.d.ts.map
|
|
@@ -0,0 +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;IAC7B,0EAA0E;;IAE1E,+DAA+D;;IAE/D,sDAAsD;;IAEtD,sEAAsE;;IAEtE,6IAA6I;;IAE7I,qEAAqE;;IAErE,gGAAgG;;IAEhG,mDAAmD;;IAEnD,iFAAiF;;IAEjF,kGAAkG;;IAElG,mDAAmD;;IAEnD,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEzE,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,uBAAuB;;;QA5BlC,0EAA0E;;QAE1E,+DAA+D;;QAE/D,sDAAsD;;QAEtD,sEAAsE;;QAEtE,6IAA6I;;QAE7I,qEAAqE;;QAErE,gGAAgG;;QAEhG,mDAAmD;;QAEnD,i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Compiled rule schemas ──────────────────────────
|
|
3
|
+
export const CompiledRuleSchema = z.object({
|
|
4
|
+
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
5
|
+
lessonHash: z.string(),
|
|
6
|
+
/** Human-readable heading from the lesson (for diagnostics) */
|
|
7
|
+
lessonHeading: z.string(),
|
|
8
|
+
/** Regex pattern to match against added diff lines */
|
|
9
|
+
pattern: z.string(),
|
|
10
|
+
/** Human-readable violation message shown when the pattern matches */
|
|
11
|
+
message: z.string(),
|
|
12
|
+
/** Engine type — 'regex' for line-level matching, 'ast' for Tree-sitter S-expression queries, 'ast-grep' for ast-grep structural patterns */
|
|
13
|
+
engine: z.enum(['regex', 'ast', 'ast-grep']),
|
|
14
|
+
/** Tree-sitter S-expression query (required when engine is 'ast') */
|
|
15
|
+
astQuery: z.string().optional(),
|
|
16
|
+
/** ast-grep pattern — string for simple patterns, object for compound rules (has/inside/not) */
|
|
17
|
+
astGrepPattern: z.union([z.string(), z.record(z.unknown())]).optional(),
|
|
18
|
+
/** ISO timestamp of when this rule was compiled */
|
|
19
|
+
compiledAt: z.string(),
|
|
20
|
+
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
21
|
+
createdAt: z.string().optional(),
|
|
22
|
+
/** Optional file glob patterns — rule only applies to matching files (e.g., ["*.sh", "*.yml"]) */
|
|
23
|
+
fileGlobs: z.array(z.string()).optional(),
|
|
24
|
+
/** Rule category for Trap Ledger classification */
|
|
25
|
+
category: z.enum(['security', 'architecture', 'style', 'performance']).optional(),
|
|
26
|
+
/** Severity level — error blocks CI, warning reports but doesn't fail */
|
|
27
|
+
severity: z.enum(['error', 'warning']).optional(),
|
|
28
|
+
});
|
|
29
|
+
export const CompiledRulesFileSchema = z.object({
|
|
30
|
+
version: z.literal(1),
|
|
31
|
+
rules: z.array(CompiledRuleSchema),
|
|
32
|
+
/** Lesson hashes that the LLM determined cannot be compiled (conceptual/architectural). */
|
|
33
|
+
nonCompilable: z.array(z.string()).optional(),
|
|
34
|
+
});
|
|
35
|
+
// ─── Compiler output schema ─────────────────────────
|
|
36
|
+
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
37
|
+
export const CompilerOutputSchema = z.object({
|
|
38
|
+
compilable: z.boolean(),
|
|
39
|
+
pattern: z.string().optional(),
|
|
40
|
+
message: z.string().optional(),
|
|
41
|
+
fileGlobs: z.array(z.string()).optional(),
|
|
42
|
+
engine: z.enum(['regex', 'ast', 'ast-grep']).optional(),
|
|
43
|
+
astQuery: z.string().optional(),
|
|
44
|
+
astGrepPattern: z.union([z.string(), z.record(z.unknown())]).optional(),
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=compiler-schema.js.map
|
|
@@ -0,0 +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,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,6IAA6I;IAC7I,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAC5C,qEAAqE;IACrE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,gGAAgG;IAChG,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAA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AAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE;IACvD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACxE,CAAC,CAAC"}
|
package/dist/compiler.d.ts
CHANGED
|
@@ -1,213 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** ast-grep pattern — string for simple patterns, object for compound rules (has/inside/not) */
|
|
16
|
-
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
17
|
-
/** ISO timestamp of when this rule was compiled */
|
|
18
|
-
compiledAt: z.ZodString;
|
|
19
|
-
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
20
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
21
|
-
/** Optional file glob patterns — rule only applies to matching files (e.g., ["*.sh", "*.yml"]) */
|
|
22
|
-
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
23
|
-
/** Rule category for Trap Ledger classification */
|
|
24
|
-
category: z.ZodOptional<z.ZodEnum<["security", "architecture", "style", "performance"]>>;
|
|
25
|
-
/** Severity level — error blocks CI, warning reports but doesn't fail */
|
|
26
|
-
severity: z.ZodOptional<z.ZodEnum<["error", "warning"]>>;
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
28
|
-
lessonHash: string;
|
|
29
|
-
lessonHeading: string;
|
|
30
|
-
pattern: string;
|
|
31
|
-
message: string;
|
|
32
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
33
|
-
compiledAt: string;
|
|
34
|
-
astQuery?: string | undefined;
|
|
35
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
36
|
-
createdAt?: string | undefined;
|
|
37
|
-
fileGlobs?: string[] | undefined;
|
|
38
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
39
|
-
severity?: "error" | "warning" | undefined;
|
|
40
|
-
}, {
|
|
41
|
-
lessonHash: string;
|
|
42
|
-
lessonHeading: string;
|
|
43
|
-
pattern: string;
|
|
44
|
-
message: string;
|
|
45
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
46
|
-
compiledAt: string;
|
|
47
|
-
astQuery?: string | undefined;
|
|
48
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
49
|
-
createdAt?: string | undefined;
|
|
50
|
-
fileGlobs?: string[] | undefined;
|
|
51
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
52
|
-
severity?: "error" | "warning" | undefined;
|
|
53
|
-
}>;
|
|
54
|
-
export type CompiledRule = z.infer<typeof CompiledRuleSchema>;
|
|
55
|
-
export declare const CompiledRulesFileSchema: z.ZodObject<{
|
|
56
|
-
version: z.ZodLiteral<1>;
|
|
57
|
-
rules: z.ZodArray<z.ZodObject<{
|
|
58
|
-
/** SHA-256 hash (first 16 hex chars) of heading + body — detects edits */
|
|
59
|
-
lessonHash: z.ZodString;
|
|
60
|
-
/** Human-readable heading from the lesson (for diagnostics) */
|
|
61
|
-
lessonHeading: z.ZodString;
|
|
62
|
-
/** Regex pattern to match against added diff lines */
|
|
63
|
-
pattern: z.ZodString;
|
|
64
|
-
/** Human-readable violation message shown when the pattern matches */
|
|
65
|
-
message: z.ZodString;
|
|
66
|
-
/** Engine type — 'regex' for line-level matching, 'ast' for Tree-sitter S-expression queries, 'ast-grep' for ast-grep structural patterns */
|
|
67
|
-
engine: z.ZodEnum<["regex", "ast", "ast-grep"]>;
|
|
68
|
-
/** Tree-sitter S-expression query (required when engine is 'ast') */
|
|
69
|
-
astQuery: z.ZodOptional<z.ZodString>;
|
|
70
|
-
/** ast-grep pattern — string for simple patterns, object for compound rules (has/inside/not) */
|
|
71
|
-
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
72
|
-
/** ISO timestamp of when this rule was compiled */
|
|
73
|
-
compiledAt: z.ZodString;
|
|
74
|
-
/** ISO timestamp of when this rule was first created (survives recompilation) */
|
|
75
|
-
createdAt: z.ZodOptional<z.ZodString>;
|
|
76
|
-
/** Optional file glob patterns — rule only applies to matching files (e.g., ["*.sh", "*.yml"]) */
|
|
77
|
-
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
78
|
-
/** Rule category for Trap Ledger classification */
|
|
79
|
-
category: z.ZodOptional<z.ZodEnum<["security", "architecture", "style", "performance"]>>;
|
|
80
|
-
/** Severity level — error blocks CI, warning reports but doesn't fail */
|
|
81
|
-
severity: z.ZodOptional<z.ZodEnum<["error", "warning"]>>;
|
|
82
|
-
}, "strip", z.ZodTypeAny, {
|
|
83
|
-
lessonHash: string;
|
|
84
|
-
lessonHeading: string;
|
|
85
|
-
pattern: string;
|
|
86
|
-
message: string;
|
|
87
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
88
|
-
compiledAt: string;
|
|
89
|
-
astQuery?: string | undefined;
|
|
90
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
91
|
-
createdAt?: string | undefined;
|
|
92
|
-
fileGlobs?: string[] | undefined;
|
|
93
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
94
|
-
severity?: "error" | "warning" | undefined;
|
|
95
|
-
}, {
|
|
96
|
-
lessonHash: string;
|
|
97
|
-
lessonHeading: string;
|
|
98
|
-
pattern: string;
|
|
99
|
-
message: string;
|
|
100
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
101
|
-
compiledAt: string;
|
|
102
|
-
astQuery?: string | undefined;
|
|
103
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
104
|
-
createdAt?: string | undefined;
|
|
105
|
-
fileGlobs?: string[] | undefined;
|
|
106
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
107
|
-
severity?: "error" | "warning" | undefined;
|
|
108
|
-
}>, "many">;
|
|
109
|
-
/** Lesson hashes that the LLM determined cannot be compiled (conceptual/architectural). */
|
|
110
|
-
nonCompilable: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
111
|
-
}, "strip", z.ZodTypeAny, {
|
|
112
|
-
version: 1;
|
|
113
|
-
rules: {
|
|
114
|
-
lessonHash: string;
|
|
115
|
-
lessonHeading: string;
|
|
116
|
-
pattern: string;
|
|
117
|
-
message: string;
|
|
118
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
119
|
-
compiledAt: string;
|
|
120
|
-
astQuery?: string | undefined;
|
|
121
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
122
|
-
createdAt?: string | undefined;
|
|
123
|
-
fileGlobs?: string[] | undefined;
|
|
124
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
125
|
-
severity?: "error" | "warning" | undefined;
|
|
126
|
-
}[];
|
|
127
|
-
nonCompilable?: string[] | undefined;
|
|
128
|
-
}, {
|
|
129
|
-
version: 1;
|
|
130
|
-
rules: {
|
|
131
|
-
lessonHash: string;
|
|
132
|
-
lessonHeading: string;
|
|
133
|
-
pattern: string;
|
|
134
|
-
message: string;
|
|
135
|
-
engine: "regex" | "ast" | "ast-grep";
|
|
136
|
-
compiledAt: string;
|
|
137
|
-
astQuery?: string | undefined;
|
|
138
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
139
|
-
createdAt?: string | undefined;
|
|
140
|
-
fileGlobs?: string[] | undefined;
|
|
141
|
-
category?: "security" | "architecture" | "style" | "performance" | undefined;
|
|
142
|
-
severity?: "error" | "warning" | undefined;
|
|
143
|
-
}[];
|
|
144
|
-
nonCompilable?: string[] | undefined;
|
|
145
|
-
}>;
|
|
146
|
-
export type CompiledRulesFile = z.infer<typeof CompiledRulesFileSchema>;
|
|
147
|
-
export interface Violation {
|
|
148
|
-
/** The rule that was violated */
|
|
149
|
-
rule: CompiledRule;
|
|
150
|
-
/** The file path from the diff where the violation occurred */
|
|
151
|
-
file: string;
|
|
152
|
-
/** The matching line content */
|
|
153
|
-
line: string;
|
|
154
|
-
/** 1-based line number within the diff hunk (approximate) */
|
|
155
|
-
lineNumber: number;
|
|
156
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Compiler facade — re-exports from focused modules.
|
|
3
|
+
*
|
|
4
|
+
* Schemas and types: ./compiler-schema.ts
|
|
5
|
+
* Diff parsing: ./diff-parser.ts
|
|
6
|
+
* Rule execution: ./rule-engine.ts
|
|
7
|
+
*
|
|
8
|
+
* This file retains: hashing, regex validation, file I/O, and LLM response parsing.
|
|
9
|
+
*/
|
|
10
|
+
import type { CompiledRule, CompiledRulesFile, CompilerOutput, RegexValidation } from './compiler-schema.js';
|
|
11
|
+
export type { AstContext, CompiledRule, CompiledRulesFile, CompilerOutput, DiffAddition, RegexValidation, RuleEventCallback, Violation, } from './compiler-schema.js';
|
|
12
|
+
export { CompiledRuleSchema, CompiledRulesFileSchema, CompilerOutputSchema, } from './compiler-schema.js';
|
|
13
|
+
export { extractAddedLines } from './diff-parser.js';
|
|
14
|
+
export { applyAstRulesToAdditions, applyRules, applyRulesToAdditions, matchesGlob, } from './rule-engine.js';
|
|
157
15
|
/** Hash a lesson's heading + body to detect changes since compilation. */
|
|
158
16
|
export declare function hashLesson(heading: string, body: string): string;
|
|
159
|
-
export interface RegexValidation {
|
|
160
|
-
valid: boolean;
|
|
161
|
-
reason?: string;
|
|
162
|
-
}
|
|
163
17
|
/**
|
|
164
18
|
* Validate that a pattern string is a syntactically valid RegExp
|
|
165
19
|
* and is not vulnerable to ReDoS (catastrophic backtracking).
|
|
166
20
|
*/
|
|
167
21
|
export declare function validateRegex(pattern: string): RegexValidation;
|
|
168
|
-
/** Syntactic context of a diff line, determined by AST analysis. */
|
|
169
|
-
export type AstContext = 'code' | 'string' | 'comment' | 'regex';
|
|
170
|
-
export interface DiffAddition {
|
|
171
|
-
file: string;
|
|
172
|
-
line: string;
|
|
173
|
-
lineNumber: number;
|
|
174
|
-
/** Content of the preceding line in the new file (context or added), null if first in hunk */
|
|
175
|
-
precedingLine: string | null;
|
|
176
|
-
/** Syntactic context from AST analysis — undefined means not classified (fail-open as code) */
|
|
177
|
-
astContext?: AstContext;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Extract added lines from a unified diff.
|
|
181
|
-
* Returns only lines that start with `+` (excluding `+++` file headers).
|
|
182
|
-
* Tracks the preceding line content (context or added) for suppression support.
|
|
183
|
-
*/
|
|
184
|
-
export declare function extractAddedLines(diff: string): DiffAddition[];
|
|
185
|
-
/**
|
|
186
|
-
* Check if a file path matches a single glob pattern.
|
|
187
|
-
* Supports: `*.ext`, `**\/*.ext`, `dir/**\/*.ext`, `dir/**`, literal filenames.
|
|
188
|
-
*/
|
|
189
|
-
export declare function matchesGlob(filePath: string, glob: string): boolean;
|
|
190
|
-
/** Callback for observability — invoked when a rule is suppressed or triggered. */
|
|
191
|
-
export type RuleEventCallback = (event: 'trigger' | 'suppress', lessonHash: string) => void;
|
|
192
|
-
/**
|
|
193
|
-
* Apply compiled rules against pre-extracted diff additions.
|
|
194
|
-
* Skips additions with non-code AST context (strings, comments, regex).
|
|
195
|
-
* Optional `onRuleEvent` callback enables observability metrics collection.
|
|
196
|
-
*/
|
|
197
|
-
export declare function applyRulesToAdditions(rules: CompiledRule[], additions: DiffAddition[], onRuleEvent?: RuleEventCallback): Violation[];
|
|
198
|
-
/**
|
|
199
|
-
* Apply AST-engine compiled rules against pre-extracted diff additions.
|
|
200
|
-
* Handles both Tree-sitter S-expression ('ast') and ast-grep ('ast-grep') engines.
|
|
201
|
-
* Async because it reads files and runs Tree-sitter queries.
|
|
202
|
-
* Handles fileGlobs filtering and suppression same as regex rules.
|
|
203
|
-
*/
|
|
204
|
-
export declare function applyAstRulesToAdditions(rules: CompiledRule[], additions: DiffAddition[], cwd: string, onRuleEvent?: RuleEventCallback): Promise<Violation[]>;
|
|
205
|
-
/**
|
|
206
|
-
* Apply compiled rules against added lines from a diff.
|
|
207
|
-
* Returns all violations found.
|
|
208
|
-
* @param excludeFiles — file paths to skip (e.g., compiled-rules.json to avoid self-matches)
|
|
209
|
-
*/
|
|
210
|
-
export declare function applyRules(rules: CompiledRule[], diff: string, excludeFiles?: string[]): Violation[];
|
|
211
22
|
/** Load compiled rules from a JSON file. Returns empty array if file missing. */
|
|
212
23
|
export declare function loadCompiledRules(rulesPath: string, onWarn?: (msg: string) => void): CompiledRule[];
|
|
213
24
|
/** Load the full compiled rules file (rules + non-compilable cache). */
|
|
@@ -216,33 +27,6 @@ export declare function loadCompiledRulesFile(rulesPath: string, onWarn?: (msg:
|
|
|
216
27
|
export declare function saveCompiledRules(rulesPath: string, rules: CompiledRule[]): void;
|
|
217
28
|
/** Save the full compiled rules file (rules + non-compilable cache). */
|
|
218
29
|
export declare function saveCompiledRulesFile(rulesPath: string, data: CompiledRulesFile): void;
|
|
219
|
-
/** Schema for the structured JSON the LLM returns when compiling a lesson. */
|
|
220
|
-
export declare const CompilerOutputSchema: z.ZodObject<{
|
|
221
|
-
compilable: z.ZodBoolean;
|
|
222
|
-
pattern: z.ZodOptional<z.ZodString>;
|
|
223
|
-
message: z.ZodOptional<z.ZodString>;
|
|
224
|
-
fileGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
225
|
-
engine: z.ZodOptional<z.ZodEnum<["regex", "ast", "ast-grep"]>>;
|
|
226
|
-
astQuery: z.ZodOptional<z.ZodString>;
|
|
227
|
-
astGrepPattern: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
228
|
-
}, "strip", z.ZodTypeAny, {
|
|
229
|
-
compilable: boolean;
|
|
230
|
-
astQuery?: string | undefined;
|
|
231
|
-
pattern?: string | undefined;
|
|
232
|
-
message?: string | undefined;
|
|
233
|
-
engine?: "regex" | "ast" | "ast-grep" | undefined;
|
|
234
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
235
|
-
fileGlobs?: string[] | undefined;
|
|
236
|
-
}, {
|
|
237
|
-
compilable: boolean;
|
|
238
|
-
astQuery?: string | undefined;
|
|
239
|
-
pattern?: string | undefined;
|
|
240
|
-
message?: string | undefined;
|
|
241
|
-
engine?: "regex" | "ast" | "ast-grep" | undefined;
|
|
242
|
-
astGrepPattern?: string | Record<string, unknown> | undefined;
|
|
243
|
-
fileGlobs?: string[] | undefined;
|
|
244
|
-
}>;
|
|
245
|
-
export type CompilerOutput = z.infer<typeof CompilerOutputSchema>;
|
|
246
30
|
/**
|
|
247
31
|
* Parse the LLM's compilation response. Extracts JSON from the response text,
|
|
248
32
|
* validates it, and returns the structured output or null if unparseable.
|
package/dist/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"
|
|
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,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,k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