@mmnto/cli 1.34.3 → 1.36.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.
Files changed (70) hide show
  1. package/dist/commands/eject.d.ts.map +1 -1
  2. package/dist/commands/eject.js +64 -2
  3. package/dist/commands/eject.js.map +1 -1
  4. package/dist/commands/eject.test.js +51 -0
  5. package/dist/commands/eject.test.js.map +1 -1
  6. package/dist/commands/hook-run.d.ts +91 -0
  7. package/dist/commands/hook-run.d.ts.map +1 -0
  8. package/dist/commands/hook-run.js +149 -0
  9. package/dist/commands/hook-run.js.map +1 -0
  10. package/dist/commands/hook-run.test.d.ts +2 -0
  11. package/dist/commands/hook-run.test.d.ts.map +1 -0
  12. package/dist/commands/hook-run.test.js +264 -0
  13. package/dist/commands/hook-run.test.js.map +1 -0
  14. package/dist/commands/hook-test.d.ts +29 -0
  15. package/dist/commands/hook-test.d.ts.map +1 -0
  16. package/dist/commands/hook-test.js +132 -0
  17. package/dist/commands/hook-test.js.map +1 -0
  18. package/dist/commands/init-templates.d.ts +11 -0
  19. package/dist/commands/init-templates.d.ts.map +1 -1
  20. package/dist/commands/init-templates.js +119 -0
  21. package/dist/commands/init-templates.js.map +1 -1
  22. package/dist/commands/init.d.ts +21 -0
  23. package/dist/commands/init.d.ts.map +1 -1
  24. package/dist/commands/init.js +90 -1
  25. package/dist/commands/init.js.map +1 -1
  26. package/dist/commands/init.test.js +91 -2
  27. package/dist/commands/init.test.js.map +1 -1
  28. package/dist/hook/classification.d.ts +45 -0
  29. package/dist/hook/classification.d.ts.map +1 -0
  30. package/dist/hook/classification.js +24 -0
  31. package/dist/hook/classification.js.map +1 -0
  32. package/dist/hook/classification.test.d.ts +2 -0
  33. package/dist/hook/classification.test.d.ts.map +1 -0
  34. package/dist/hook/classification.test.js +40 -0
  35. package/dist/hook/classification.test.js.map +1 -0
  36. package/dist/hook/loader.d.ts +47 -0
  37. package/dist/hook/loader.d.ts.map +1 -0
  38. package/dist/hook/loader.js +66 -0
  39. package/dist/hook/loader.js.map +1 -0
  40. package/dist/hook/loader.test.d.ts +2 -0
  41. package/dist/hook/loader.test.d.ts.map +1 -0
  42. package/dist/hook/loader.test.js +205 -0
  43. package/dist/hook/loader.test.js.map +1 -0
  44. package/dist/hook/runtime.d.ts +47 -0
  45. package/dist/hook/runtime.d.ts.map +1 -0
  46. package/dist/hook/runtime.js +85 -0
  47. package/dist/hook/runtime.js.map +1 -0
  48. package/dist/hook/runtime.test.d.ts +2 -0
  49. package/dist/hook/runtime.test.d.ts.map +1 -0
  50. package/dist/hook/runtime.test.js +135 -0
  51. package/dist/hook/runtime.test.js.map +1 -0
  52. package/dist/hook/schema.d.ts +385 -0
  53. package/dist/hook/schema.d.ts.map +1 -0
  54. package/dist/hook/schema.js +164 -0
  55. package/dist/hook/schema.js.map +1 -0
  56. package/dist/hook/schema.test.d.ts +2 -0
  57. package/dist/hook/schema.test.d.ts.map +1 -0
  58. package/dist/hook/schema.test.js +233 -0
  59. package/dist/hook/schema.test.js.map +1 -0
  60. package/dist/hook/test-runner.d.ts +64 -0
  61. package/dist/hook/test-runner.d.ts.map +1 -0
  62. package/dist/hook/test-runner.js +57 -0
  63. package/dist/hook/test-runner.js.map +1 -0
  64. package/dist/hook/test-runner.test.d.ts +2 -0
  65. package/dist/hook/test-runner.test.d.ts.map +1 -0
  66. package/dist/hook/test-runner.test.js +237 -0
  67. package/dist/hook/test-runner.test.js.map +1 -0
  68. package/dist/index.js +57 -4
  69. package/dist/index.js.map +1 -1
  70. package/package.json +2 -2
@@ -0,0 +1,385 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Hook rule schemas for the bot-pack wiring engine (ADR-104).
4
+ *
5
+ * Two surfaces:
6
+ * - `HooksYamlSchema` describes a pack's `hooks.yaml` (authoring surface).
7
+ * - `CompiledHooksManifestSchema` describes `.totem/compiled-hooks.json`
8
+ * (runtime surface produced by `totem sync` from installed packs).
9
+ *
10
+ * The compiled manifest carries the staleness metadata required by
11
+ * ADR-104 § Decision 3: schemaVersion + compiledAt + sourcePackVersions.
12
+ */
13
+ declare const HookCheckTypeSchema: z.ZodEnum<["reject-if-match", "reject-if-no-match"]>;
14
+ export type HookCheckType = z.infer<typeof HookCheckTypeSchema>;
15
+ /**
16
+ * Authoring-surface schema for a single hook rule in a pack's `hooks.yaml`.
17
+ *
18
+ * The optional `recoveryHint` field (ADR-104 § Decision 1) gives agents the
19
+ * WHAT-INSTEAD on a block — recommended but not required in V1. Adoption
20
+ * tracked toward a V2 upgrade-to-required trigger (>80% of published rules
21
+ * carry it, OR an empirically-observed retry-loop incident).
22
+ *
23
+ * The `verification_shadow` field is reserved for the Spine Rule
24
+ * classification path (ADR-104 § Convergence + Q1 binding). In V1 the engine
25
+ * MUST warn-and-ignore any verification_shadow on a hook rule (hooks are
26
+ * Interpretive Rule class — no formal verification obligation). Schema
27
+ * accepts it permissively so future Spine-Rule promotion does not require
28
+ * a schema break.
29
+ */
30
+ export declare const HookRuleSchema: z.ZodObject<{
31
+ id: z.ZodString;
32
+ trigger: z.ZodObject<{
33
+ tool: z.ZodString;
34
+ pattern: z.ZodEffects<z.ZodString, string, string>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ tool: string;
37
+ pattern: string;
38
+ }, {
39
+ tool: string;
40
+ pattern: string;
41
+ }>;
42
+ check: z.ZodObject<{
43
+ pattern: z.ZodEffects<z.ZodString, string, string>;
44
+ type: z.ZodEnum<["reject-if-match", "reject-if-no-match"]>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ type: "reject-if-match" | "reject-if-no-match";
47
+ pattern: string;
48
+ }, {
49
+ type: "reject-if-match" | "reject-if-no-match";
50
+ pattern: string;
51
+ }>;
52
+ message: z.ZodString;
53
+ recoveryHint: z.ZodOptional<z.ZodString>;
54
+ verification_shadow: z.ZodOptional<z.ZodUnknown>;
55
+ }, "strip", z.ZodTypeAny, {
56
+ check: {
57
+ type: "reject-if-match" | "reject-if-no-match";
58
+ pattern: string;
59
+ };
60
+ message: string;
61
+ id: string;
62
+ trigger: {
63
+ tool: string;
64
+ pattern: string;
65
+ };
66
+ recoveryHint?: string | undefined;
67
+ verification_shadow?: unknown;
68
+ }, {
69
+ check: {
70
+ type: "reject-if-match" | "reject-if-no-match";
71
+ pattern: string;
72
+ };
73
+ message: string;
74
+ id: string;
75
+ trigger: {
76
+ tool: string;
77
+ pattern: string;
78
+ };
79
+ recoveryHint?: string | undefined;
80
+ verification_shadow?: unknown;
81
+ }>;
82
+ export type HookRule = z.infer<typeof HookRuleSchema>;
83
+ export declare const HOOKS_YAML_SCHEMA_VERSION: 1;
84
+ /**
85
+ * Per-pack `hooks.yaml` file shape. The `version` field is the contract
86
+ * for forward-compat: when `totem sync` parses an unknown version (higher
87
+ * than the runner supports), it warns-and-skips that pack entirely
88
+ * (ADR-104 § Decision 4).
89
+ */
90
+ export declare const HooksYamlSchema: z.ZodEffects<z.ZodObject<{
91
+ version: z.ZodNumber;
92
+ hooks: z.ZodArray<z.ZodObject<{
93
+ id: z.ZodString;
94
+ trigger: z.ZodObject<{
95
+ tool: z.ZodString;
96
+ pattern: z.ZodEffects<z.ZodString, string, string>;
97
+ }, "strip", z.ZodTypeAny, {
98
+ tool: string;
99
+ pattern: string;
100
+ }, {
101
+ tool: string;
102
+ pattern: string;
103
+ }>;
104
+ check: z.ZodObject<{
105
+ pattern: z.ZodEffects<z.ZodString, string, string>;
106
+ type: z.ZodEnum<["reject-if-match", "reject-if-no-match"]>;
107
+ }, "strip", z.ZodTypeAny, {
108
+ type: "reject-if-match" | "reject-if-no-match";
109
+ pattern: string;
110
+ }, {
111
+ type: "reject-if-match" | "reject-if-no-match";
112
+ pattern: string;
113
+ }>;
114
+ message: z.ZodString;
115
+ recoveryHint: z.ZodOptional<z.ZodString>;
116
+ verification_shadow: z.ZodOptional<z.ZodUnknown>;
117
+ }, "strip", z.ZodTypeAny, {
118
+ check: {
119
+ type: "reject-if-match" | "reject-if-no-match";
120
+ pattern: string;
121
+ };
122
+ message: string;
123
+ id: string;
124
+ trigger: {
125
+ tool: string;
126
+ pattern: string;
127
+ };
128
+ recoveryHint?: string | undefined;
129
+ verification_shadow?: unknown;
130
+ }, {
131
+ check: {
132
+ type: "reject-if-match" | "reject-if-no-match";
133
+ pattern: string;
134
+ };
135
+ message: string;
136
+ id: string;
137
+ trigger: {
138
+ tool: string;
139
+ pattern: string;
140
+ };
141
+ recoveryHint?: string | undefined;
142
+ verification_shadow?: unknown;
143
+ }>, "many">;
144
+ }, "strip", z.ZodTypeAny, {
145
+ hooks: {
146
+ check: {
147
+ type: "reject-if-match" | "reject-if-no-match";
148
+ pattern: string;
149
+ };
150
+ message: string;
151
+ id: string;
152
+ trigger: {
153
+ tool: string;
154
+ pattern: string;
155
+ };
156
+ recoveryHint?: string | undefined;
157
+ verification_shadow?: unknown;
158
+ }[];
159
+ version: number;
160
+ }, {
161
+ hooks: {
162
+ check: {
163
+ type: "reject-if-match" | "reject-if-no-match";
164
+ pattern: string;
165
+ };
166
+ message: string;
167
+ id: string;
168
+ trigger: {
169
+ tool: string;
170
+ pattern: string;
171
+ };
172
+ recoveryHint?: string | undefined;
173
+ verification_shadow?: unknown;
174
+ }[];
175
+ version: number;
176
+ }>, {
177
+ hooks: {
178
+ check: {
179
+ type: "reject-if-match" | "reject-if-no-match";
180
+ pattern: string;
181
+ };
182
+ message: string;
183
+ id: string;
184
+ trigger: {
185
+ tool: string;
186
+ pattern: string;
187
+ };
188
+ recoveryHint?: string | undefined;
189
+ verification_shadow?: unknown;
190
+ }[];
191
+ version: number;
192
+ }, {
193
+ hooks: {
194
+ check: {
195
+ type: "reject-if-match" | "reject-if-no-match";
196
+ pattern: string;
197
+ };
198
+ message: string;
199
+ id: string;
200
+ trigger: {
201
+ tool: string;
202
+ pattern: string;
203
+ };
204
+ recoveryHint?: string | undefined;
205
+ verification_shadow?: unknown;
206
+ }[];
207
+ version: number;
208
+ }>;
209
+ export type HooksYaml = z.infer<typeof HooksYamlSchema>;
210
+ export declare const COMPILED_HOOKS_SCHEMA_VERSION: 1;
211
+ /**
212
+ * A compiled hook rule carries provenance (`packId`) so rejection messages
213
+ * can name `<packId>/<ruleId>` (ADR-104 § Decision 1) and so staleness
214
+ * checks can scope per-pack.
215
+ */
216
+ export declare const CompiledHookRuleSchema: z.ZodObject<{
217
+ id: z.ZodString;
218
+ trigger: z.ZodObject<{
219
+ tool: z.ZodString;
220
+ pattern: z.ZodEffects<z.ZodString, string, string>;
221
+ }, "strip", z.ZodTypeAny, {
222
+ tool: string;
223
+ pattern: string;
224
+ }, {
225
+ tool: string;
226
+ pattern: string;
227
+ }>;
228
+ check: z.ZodObject<{
229
+ pattern: z.ZodEffects<z.ZodString, string, string>;
230
+ type: z.ZodEnum<["reject-if-match", "reject-if-no-match"]>;
231
+ }, "strip", z.ZodTypeAny, {
232
+ type: "reject-if-match" | "reject-if-no-match";
233
+ pattern: string;
234
+ }, {
235
+ type: "reject-if-match" | "reject-if-no-match";
236
+ pattern: string;
237
+ }>;
238
+ message: z.ZodString;
239
+ recoveryHint: z.ZodOptional<z.ZodString>;
240
+ verification_shadow: z.ZodOptional<z.ZodUnknown>;
241
+ } & {
242
+ packId: z.ZodString;
243
+ }, "strip", z.ZodTypeAny, {
244
+ check: {
245
+ type: "reject-if-match" | "reject-if-no-match";
246
+ pattern: string;
247
+ };
248
+ message: string;
249
+ id: string;
250
+ trigger: {
251
+ tool: string;
252
+ pattern: string;
253
+ };
254
+ packId: string;
255
+ recoveryHint?: string | undefined;
256
+ verification_shadow?: unknown;
257
+ }, {
258
+ check: {
259
+ type: "reject-if-match" | "reject-if-no-match";
260
+ pattern: string;
261
+ };
262
+ message: string;
263
+ id: string;
264
+ trigger: {
265
+ tool: string;
266
+ pattern: string;
267
+ };
268
+ packId: string;
269
+ recoveryHint?: string | undefined;
270
+ verification_shadow?: unknown;
271
+ }>;
272
+ export type CompiledHookRule = z.infer<typeof CompiledHookRuleSchema>;
273
+ /**
274
+ * Runtime-surface manifest produced by `totem sync` and read on every
275
+ * `totem hook run` invocation. The metadata fields are load-bearing for
276
+ * ADR-104 § Decision 3 (staleness detection):
277
+ *
278
+ * - `schemaVersion`: bumps on breaking structural change to this manifest
279
+ * - `compiledAt`: ISO 8601 timestamp of last compile
280
+ * - `sourcePackVersions`: pack name → version at compile time; compared
281
+ * against package.json resolutions to emit `[totem:hook-stale]` warnings
282
+ * when packs have updated since last compile
283
+ */
284
+ export declare const CompiledHooksManifestSchema: z.ZodObject<{
285
+ schemaVersion: z.ZodLiteral<1>;
286
+ compiledAt: z.ZodString;
287
+ sourcePackVersions: z.ZodRecord<z.ZodString, z.ZodString>;
288
+ hooks: z.ZodArray<z.ZodObject<{
289
+ id: z.ZodString;
290
+ trigger: z.ZodObject<{
291
+ tool: z.ZodString;
292
+ pattern: z.ZodEffects<z.ZodString, string, string>;
293
+ }, "strip", z.ZodTypeAny, {
294
+ tool: string;
295
+ pattern: string;
296
+ }, {
297
+ tool: string;
298
+ pattern: string;
299
+ }>;
300
+ check: z.ZodObject<{
301
+ pattern: z.ZodEffects<z.ZodString, string, string>;
302
+ type: z.ZodEnum<["reject-if-match", "reject-if-no-match"]>;
303
+ }, "strip", z.ZodTypeAny, {
304
+ type: "reject-if-match" | "reject-if-no-match";
305
+ pattern: string;
306
+ }, {
307
+ type: "reject-if-match" | "reject-if-no-match";
308
+ pattern: string;
309
+ }>;
310
+ message: z.ZodString;
311
+ recoveryHint: z.ZodOptional<z.ZodString>;
312
+ verification_shadow: z.ZodOptional<z.ZodUnknown>;
313
+ } & {
314
+ packId: z.ZodString;
315
+ }, "strip", z.ZodTypeAny, {
316
+ check: {
317
+ type: "reject-if-match" | "reject-if-no-match";
318
+ pattern: string;
319
+ };
320
+ message: string;
321
+ id: string;
322
+ trigger: {
323
+ tool: string;
324
+ pattern: string;
325
+ };
326
+ packId: string;
327
+ recoveryHint?: string | undefined;
328
+ verification_shadow?: unknown;
329
+ }, {
330
+ check: {
331
+ type: "reject-if-match" | "reject-if-no-match";
332
+ pattern: string;
333
+ };
334
+ message: string;
335
+ id: string;
336
+ trigger: {
337
+ tool: string;
338
+ pattern: string;
339
+ };
340
+ packId: string;
341
+ recoveryHint?: string | undefined;
342
+ verification_shadow?: unknown;
343
+ }>, "many">;
344
+ }, "strip", z.ZodTypeAny, {
345
+ hooks: {
346
+ check: {
347
+ type: "reject-if-match" | "reject-if-no-match";
348
+ pattern: string;
349
+ };
350
+ message: string;
351
+ id: string;
352
+ trigger: {
353
+ tool: string;
354
+ pattern: string;
355
+ };
356
+ packId: string;
357
+ recoveryHint?: string | undefined;
358
+ verification_shadow?: unknown;
359
+ }[];
360
+ schemaVersion: 1;
361
+ compiledAt: string;
362
+ sourcePackVersions: Record<string, string>;
363
+ }, {
364
+ hooks: {
365
+ check: {
366
+ type: "reject-if-match" | "reject-if-no-match";
367
+ pattern: string;
368
+ };
369
+ message: string;
370
+ id: string;
371
+ trigger: {
372
+ tool: string;
373
+ pattern: string;
374
+ };
375
+ packId: string;
376
+ recoveryHint?: string | undefined;
377
+ verification_shadow?: unknown;
378
+ }[];
379
+ schemaVersion: 1;
380
+ compiledAt: string;
381
+ sourcePackVersions: Record<string, string>;
382
+ }>;
383
+ export type CompiledHooksManifest = z.infer<typeof CompiledHooksManifestSchema>;
384
+ export {};
385
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/hook/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;GAUG;AAEH,QAAA,MAAM,mBAAmB,sDAAoD,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AA4EhE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOzB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,eAAO,MAAM,yBAAyB,EAAG,CAAU,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBxB,CAAC;AAEL,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,6BAA6B,EAAG,CAAU,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
@@ -0,0 +1,164 @@
1
+ import { z } from 'zod';
2
+ import { isRegexSafe } from '@mmnto/totem';
3
+ /**
4
+ * Hook rule schemas for the bot-pack wiring engine (ADR-104).
5
+ *
6
+ * Two surfaces:
7
+ * - `HooksYamlSchema` describes a pack's `hooks.yaml` (authoring surface).
8
+ * - `CompiledHooksManifestSchema` describes `.totem/compiled-hooks.json`
9
+ * (runtime surface produced by `totem sync` from installed packs).
10
+ *
11
+ * The compiled manifest carries the staleness metadata required by
12
+ * ADR-104 § Decision 3: schemaVersion + compiledAt + sourcePackVersions.
13
+ */
14
+ const HookCheckTypeSchema = z.enum(['reject-if-match', 'reject-if-no-match']);
15
+ /**
16
+ * Generous upper bound on pack-supplied regex pattern length. Real rules in
17
+ * the existing corpus run well under 200 chars; 512 leaves headroom while
18
+ * capping the attack surface against deliberately-bloated inputs. Bounding
19
+ * length at the schema layer also makes ReDoS-style worst-case payloads
20
+ * easier to reason about (the engine never compiles 10KB patterns).
21
+ */
22
+ const MAX_PATTERN_LENGTH = 512;
23
+ /**
24
+ * Validate that a regex pattern is well-formed AND safe from catastrophic
25
+ * backtracking. Runs at parse time (Tenet 4: don't fail open silently on
26
+ * invalid input). Three layers, gated in order with `fatal: true` so an
27
+ * earlier failure short-circuits — otherwise Zod would run `isRegexSafe`
28
+ * against an unbounded-length or syntactically-invalid input:
29
+ *
30
+ * 1. Bounded length (`MAX_PATTERN_LENGTH`) — caps the attack surface against
31
+ * deliberately-bloated patterns.
32
+ * 2. Syntactically valid (compiles via `new RegExp`).
33
+ * 3. Free of nested unbounded-quantifier shapes via `safe-regex2`
34
+ * (re-exported from core as `isRegexSafe`). Without this, a pack
35
+ * publishing a pattern like `(a+)+$` would hang `evaluateHook` on
36
+ * crafted tool-call payloads. Pack-supplied patterns come from
37
+ * third-party npm, so ReDoS rejection at parse time is load-bearing
38
+ * for the engine's availability guarantee.
39
+ */
40
+ const RegexPatternSchema = z.string().superRefine((p, ctx) => {
41
+ if (p.length < 1) {
42
+ ctx.addIssue({
43
+ code: z.ZodIssueCode.custom,
44
+ message: 'pattern must not be empty',
45
+ fatal: true,
46
+ });
47
+ return z.NEVER;
48
+ }
49
+ if (p.length > MAX_PATTERN_LENGTH) {
50
+ ctx.addIssue({
51
+ code: z.ZodIssueCode.custom,
52
+ message: `pattern exceeds ${MAX_PATTERN_LENGTH}-char limit`,
53
+ fatal: true,
54
+ });
55
+ return z.NEVER;
56
+ }
57
+ try {
58
+ new RegExp(p);
59
+ // totem-context: intentional — catch below is throw-as-control-flow for regex validation
60
+ }
61
+ catch {
62
+ ctx.addIssue({
63
+ code: z.ZodIssueCode.custom,
64
+ message: 'pattern is not a valid regular expression',
65
+ fatal: true,
66
+ });
67
+ return z.NEVER;
68
+ }
69
+ if (!isRegexSafe(p)) {
70
+ ctx.addIssue({
71
+ code: z.ZodIssueCode.custom,
72
+ message: 'pattern has catastrophic-backtracking risk (ReDoS); reshape to bounded quantifiers',
73
+ fatal: true,
74
+ });
75
+ return z.NEVER;
76
+ }
77
+ });
78
+ const HookTriggerSchema = z.object({
79
+ tool: z.string().min(1),
80
+ pattern: RegexPatternSchema,
81
+ });
82
+ const HookCheckSchema = z.object({
83
+ pattern: RegexPatternSchema,
84
+ type: HookCheckTypeSchema,
85
+ });
86
+ /**
87
+ * Authoring-surface schema for a single hook rule in a pack's `hooks.yaml`.
88
+ *
89
+ * The optional `recoveryHint` field (ADR-104 § Decision 1) gives agents the
90
+ * WHAT-INSTEAD on a block — recommended but not required in V1. Adoption
91
+ * tracked toward a V2 upgrade-to-required trigger (>80% of published rules
92
+ * carry it, OR an empirically-observed retry-loop incident).
93
+ *
94
+ * The `verification_shadow` field is reserved for the Spine Rule
95
+ * classification path (ADR-104 § Convergence + Q1 binding). In V1 the engine
96
+ * MUST warn-and-ignore any verification_shadow on a hook rule (hooks are
97
+ * Interpretive Rule class — no formal verification obligation). Schema
98
+ * accepts it permissively so future Spine-Rule promotion does not require
99
+ * a schema break.
100
+ */
101
+ export const HookRuleSchema = z.object({
102
+ id: z.string().min(1),
103
+ trigger: HookTriggerSchema,
104
+ check: HookCheckSchema,
105
+ message: z.string().min(1),
106
+ recoveryHint: z.string().optional(),
107
+ verification_shadow: z.unknown().optional(),
108
+ });
109
+ export const HOOKS_YAML_SCHEMA_VERSION = 1;
110
+ /**
111
+ * Per-pack `hooks.yaml` file shape. The `version` field is the contract
112
+ * for forward-compat: when `totem sync` parses an unknown version (higher
113
+ * than the runner supports), it warns-and-skips that pack entirely
114
+ * (ADR-104 § Decision 4).
115
+ */
116
+ export const HooksYamlSchema = z
117
+ .object({
118
+ version: z.number().int().positive(),
119
+ hooks: z.array(HookRuleSchema),
120
+ })
121
+ .superRefine((data, ctx) => {
122
+ // Duplicate hook ids within a single pack would make the
123
+ // `<packId>/<ruleId>` provenance in rejection messages (ADR-104 § Decision 1)
124
+ // ambiguous. Enforce uniqueness at parse time so a misauthored pack fails
125
+ // on load rather than producing non-deterministic rejection trails.
126
+ const seen = new Set();
127
+ data.hooks.forEach((hook, i) => {
128
+ if (seen.has(hook.id)) {
129
+ ctx.addIssue({
130
+ code: z.ZodIssueCode.custom,
131
+ message: `Duplicate hook id within pack: ${hook.id}`,
132
+ path: ['hooks', i, 'id'],
133
+ });
134
+ }
135
+ seen.add(hook.id);
136
+ });
137
+ });
138
+ export const COMPILED_HOOKS_SCHEMA_VERSION = 1;
139
+ /**
140
+ * A compiled hook rule carries provenance (`packId`) so rejection messages
141
+ * can name `<packId>/<ruleId>` (ADR-104 § Decision 1) and so staleness
142
+ * checks can scope per-pack.
143
+ */
144
+ export const CompiledHookRuleSchema = HookRuleSchema.extend({
145
+ packId: z.string().min(1),
146
+ });
147
+ /**
148
+ * Runtime-surface manifest produced by `totem sync` and read on every
149
+ * `totem hook run` invocation. The metadata fields are load-bearing for
150
+ * ADR-104 § Decision 3 (staleness detection):
151
+ *
152
+ * - `schemaVersion`: bumps on breaking structural change to this manifest
153
+ * - `compiledAt`: ISO 8601 timestamp of last compile
154
+ * - `sourcePackVersions`: pack name → version at compile time; compared
155
+ * against package.json resolutions to emit `[totem:hook-stale]` warnings
156
+ * when packs have updated since last compile
157
+ */
158
+ export const CompiledHooksManifestSchema = z.object({
159
+ schemaVersion: z.literal(COMPILED_HOOKS_SCHEMA_VERSION),
160
+ compiledAt: z.string().datetime(),
161
+ sourcePackVersions: z.record(z.string(), z.string()),
162
+ hooks: z.array(CompiledHookRuleSchema),
163
+ });
164
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.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AE,CAAC;IACpD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC;CACvC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schema.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.test.d.ts","sourceRoot":"","sources":["../../src/hook/schema.test.ts"],"names":[],"mappings":""}