@interf/compiler 0.5.0 → 0.5.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.
Files changed (42) hide show
  1. package/README.md +6 -7
  2. package/dist/commands/compile-controller.js +3 -3
  3. package/dist/commands/test-flow.js +5 -16
  4. package/dist/lib/agent-shells.js +1 -1
  5. package/dist/lib/{workflow-abi.d.ts → builtin-compiled-workflow.d.ts} +2 -2
  6. package/dist/lib/{workflow-abi.js → builtin-compiled-workflow.js} +2 -5
  7. package/dist/lib/compiled-compile.js +2 -2
  8. package/dist/lib/compiled-paths.d.ts +0 -2
  9. package/dist/lib/compiled-paths.js +5 -13
  10. package/dist/lib/compiled-raw.d.ts +2 -2
  11. package/dist/lib/compiled-schema.d.ts +2 -2
  12. package/dist/lib/compiled-schema.js +2 -2
  13. package/dist/lib/interf-detect.d.ts +0 -1
  14. package/dist/lib/interf-detect.js +7 -18
  15. package/dist/lib/interf.d.ts +1 -1
  16. package/dist/lib/interf.js +1 -1
  17. package/dist/lib/local-workflows.js +1 -1
  18. package/dist/lib/project-paths.d.ts +2 -4
  19. package/dist/lib/project-paths.js +13 -10
  20. package/dist/lib/runtime-prompt.js +1 -3
  21. package/dist/lib/runtime-reconcile.js +3 -14
  22. package/dist/lib/runtime-runs.js +2 -87
  23. package/dist/lib/schema.d.ts +33 -40
  24. package/dist/lib/schema.js +17 -104
  25. package/dist/lib/source-config.js +21 -22
  26. package/dist/lib/state-health.js +4 -2
  27. package/dist/lib/state-io.js +2 -110
  28. package/dist/lib/state-view.js +2 -2
  29. package/dist/lib/summarize-plan.js +1 -5
  30. package/dist/lib/test-paths.js +12 -3
  31. package/dist/lib/test-sandbox.js +4 -17
  32. package/dist/lib/test-specs.js +1 -1
  33. package/dist/lib/validate-compiled.js +4 -2
  34. package/dist/lib/validate.d.ts +2 -0
  35. package/dist/lib/validate.js +27 -12
  36. package/dist/lib/workflow-definitions.d.ts +3 -2
  37. package/dist/lib/workflow-definitions.js +9 -2
  38. package/dist/lib/workflow-primitives.d.ts +2 -0
  39. package/dist/lib/workflow-primitives.js +5 -0
  40. package/package.json +6 -6
  41. package/dist/lib/compiled-layout.d.ts +0 -2
  42. package/dist/lib/compiled-layout.js +0 -60
@@ -61,13 +61,6 @@ export declare const CompiledStateSchema: z.ZodObject<{
61
61
  }, z.core.$strip>>>;
62
62
  last_add: z.ZodOptional<z.ZodNullable<z.ZodString>>;
63
63
  last_compile: z.ZodOptional<z.ZodNullable<z.ZodString>>;
64
- summarized: z.ZodOptional<z.ZodNumber>;
65
- structured: z.ZodOptional<z.ZodNumber>;
66
- shaped: z.ZodOptional<z.ZodNumber>;
67
- compiled: z.ZodOptional<z.ZodNumber>;
68
- last_summarize: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
- last_structure: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
- last_shape: z.ZodOptional<z.ZodNullable<z.ZodString>>;
71
64
  inventory_complete: z.ZodOptional<z.ZodBoolean>;
72
65
  abstracts_read: z.ZodOptional<z.ZodNumber>;
73
66
  full_reads: z.ZodOptional<z.ZodNumber>;
@@ -75,7 +68,7 @@ export declare const CompiledStateSchema: z.ZodObject<{
75
68
  claim_count: z.ZodOptional<z.ZodNumber>;
76
69
  warning_count: z.ZodOptional<z.ZodNumber>;
77
70
  error_count: z.ZodOptional<z.ZodNumber>;
78
- }, z.core.$strip>;
71
+ }, z.core.$strict>;
79
72
  export declare const ViewSectionSchema: z.ZodObject<{
80
73
  id: z.ZodString;
81
74
  type: z.ZodEnum<{
@@ -242,7 +235,7 @@ export declare const RuntimeExecutorInfoSchema: z.ZodObject<{
242
235
  profile: z.ZodOptional<z.ZodNullable<z.ZodString>>;
243
236
  timeout_ms: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
244
237
  }, z.core.$strip>;
245
- export declare const RuntimeStageInstructionsSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
238
+ export declare const RuntimeStageInstructionsSchema: z.ZodObject<{
246
239
  stage_skill_dir: z.ZodString;
247
240
  effective_mode: z.ZodEnum<{
248
241
  builtin: "builtin";
@@ -255,8 +248,8 @@ export declare const RuntimeStageInstructionsSchema: z.ZodPipe<z.ZodTransform<un
255
248
  }>>;
256
249
  local_docs: z.ZodArray<z.ZodString>;
257
250
  mode_sources: z.ZodArray<z.ZodString>;
258
- }, z.core.$strip>>;
259
- export declare const RuntimeStageAcceptanceSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
251
+ }, z.core.$strict>;
252
+ export declare const RuntimeStageAcceptanceSchema: z.ZodObject<{
260
253
  artifacts_exist: z.ZodOptional<z.ZodArray<z.ZodString>>;
261
254
  stage_truthy: z.ZodOptional<z.ZodArray<z.ZodString>>;
262
255
  stage_equals_counts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -268,7 +261,7 @@ export declare const RuntimeStageAcceptanceSchema: z.ZodPipe<z.ZodTransform<unkn
268
261
  markdown_abstract_valid_zones: z.ZodOptional<z.ZodArray<z.ZodString>>;
269
262
  wikilinks_valid_in_zones: z.ZodOptional<z.ZodArray<z.ZodString>>;
270
263
  artifacts_must_not_contain: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
271
- }, z.core.$strip>>;
264
+ }, z.core.$strict>;
272
265
  export declare const RuntimeStageContractSchema: z.ZodObject<{
273
266
  kind: z.ZodLiteral<"interf-stage-contract">;
274
267
  version: z.ZodLiteral<1>;
@@ -301,7 +294,7 @@ export declare const RuntimeStageContractSchema: z.ZodObject<{
301
294
  profile: z.ZodOptional<z.ZodNullable<z.ZodString>>;
302
295
  timeout_ms: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
303
296
  }, z.core.$strip>;
304
- instructions: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
297
+ instructions: z.ZodObject<{
305
298
  stage_skill_dir: z.ZodString;
306
299
  effective_mode: z.ZodEnum<{
307
300
  builtin: "builtin";
@@ -314,9 +307,9 @@ export declare const RuntimeStageContractSchema: z.ZodObject<{
314
307
  }>>;
315
308
  local_docs: z.ZodArray<z.ZodString>;
316
309
  mode_sources: z.ZodArray<z.ZodString>;
317
- }, z.core.$strip>>;
310
+ }, z.core.$strict>;
318
311
  counts: z.ZodRecord<z.ZodString, z.ZodNumber>;
319
- acceptance: z.ZodOptional<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
312
+ acceptance: z.ZodOptional<z.ZodObject<{
320
313
  artifacts_exist: z.ZodOptional<z.ZodArray<z.ZodString>>;
321
314
  stage_truthy: z.ZodOptional<z.ZodArray<z.ZodString>>;
322
315
  stage_equals_counts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -328,7 +321,7 @@ export declare const RuntimeStageContractSchema: z.ZodObject<{
328
321
  markdown_abstract_valid_zones: z.ZodOptional<z.ZodArray<z.ZodString>>;
329
322
  wikilinks_valid_in_zones: z.ZodOptional<z.ZodArray<z.ZodString>>;
330
323
  artifacts_must_not_contain: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
331
- }, z.core.$strip>>>;
324
+ }, z.core.$strict>>;
332
325
  artifacts: z.ZodObject<{
333
326
  reads: z.ZodArray<z.ZodString>;
334
327
  writes: z.ZodArray<z.ZodString>;
@@ -395,26 +388,26 @@ export declare const RuntimeRunSchema: z.ZodObject<{
395
388
  exit_code: z.ZodNullable<z.ZodNumber>;
396
389
  error: z.ZodNullable<z.ZodString>;
397
390
  }, z.core.$strip>;
398
- export declare const CompiledInventoryEntrySchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
391
+ export declare const CompiledInventoryEntrySchema: z.ZodObject<{
399
392
  input_zone: z.ZodString;
400
393
  input_path: z.ZodString;
401
394
  output_zone: z.ZodString;
402
395
  output_path: z.ZodString;
403
396
  state: z.ZodOptional<z.ZodString>;
404
397
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
405
- }, z.core.$strip>>;
398
+ }, z.core.$strict>;
406
399
  export declare const CompiledInventorySchema: z.ZodObject<{
407
400
  kind: z.ZodOptional<z.ZodLiteral<"compiled-runtime-ledger">>;
408
401
  version: z.ZodOptional<z.ZodNumber>;
409
402
  stage: z.ZodOptional<z.ZodString>;
410
- entries: z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
403
+ entries: z.ZodArray<z.ZodObject<{
411
404
  input_zone: z.ZodString;
412
405
  input_path: z.ZodString;
413
406
  output_zone: z.ZodString;
414
407
  output_path: z.ZodString;
415
408
  state: z.ZodOptional<z.ZodString>;
416
409
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
417
- }, z.core.$strip>>>;
410
+ }, z.core.$strict>>;
418
411
  total: z.ZodNumber;
419
412
  }, z.core.$strip>;
420
413
  export declare const TestCaseExpectSchema: z.ZodObject<{
@@ -424,7 +417,7 @@ export declare const TestCaseExpectSchema: z.ZodObject<{
424
417
  min_words: z.ZodOptional<z.ZodNumber>;
425
418
  max_words: z.ZodOptional<z.ZodNumber>;
426
419
  }, z.core.$strip>;
427
- export declare const TestCaseSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
420
+ export declare const TestCaseSchema: z.ZodObject<{
428
421
  id: z.ZodString;
429
422
  question: z.ZodString;
430
423
  file: z.ZodOptional<z.ZodString>;
@@ -437,15 +430,15 @@ export declare const TestCaseSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>,
437
430
  max_words: z.ZodOptional<z.ZodNumber>;
438
431
  }, z.core.$strip>>;
439
432
  strictness: z.ZodOptional<z.ZodString>;
440
- }, z.core.$strip>>;
441
- export declare const TestSpecSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
433
+ }, z.core.$strip>;
434
+ export declare const TestSpecSchema: z.ZodObject<{
442
435
  type: z.ZodEnum<{
443
436
  compiled: "compiled";
444
437
  raw: "raw";
445
438
  }>;
446
439
  name: z.ZodString;
447
440
  description: z.ZodOptional<z.ZodString>;
448
- cases: z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
441
+ cases: z.ZodArray<z.ZodObject<{
449
442
  id: z.ZodString;
450
443
  question: z.ZodString;
451
444
  file: z.ZodOptional<z.ZodString>;
@@ -458,8 +451,8 @@ export declare const TestSpecSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>,
458
451
  max_words: z.ZodOptional<z.ZodNumber>;
459
452
  }, z.core.$strip>>;
460
453
  strictness: z.ZodOptional<z.ZodString>;
461
- }, z.core.$strip>>>;
462
- }, z.core.$strip>>;
454
+ }, z.core.$strip>>;
455
+ }, z.core.$strip>;
463
456
  export declare const SourceTruthCheckSchema: z.ZodObject<{
464
457
  id: z.ZodOptional<z.ZodString>;
465
458
  question: z.ZodString;
@@ -476,10 +469,10 @@ export declare const SourceTruthCheckSchema: z.ZodObject<{
476
469
  export declare const SourceCompiledMaxAttemptsSchema: z.ZodNumber;
477
470
  export declare const SourceCompiledMaxLoopsSchema: z.ZodNumber;
478
471
  export declare const DatasetNameSchema: z.ZodString;
479
- export declare const SourceDatasetConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
472
+ export declare const SourceDatasetConfigSchema: z.ZodObject<{
480
473
  id: z.ZodOptional<z.ZodString>;
481
474
  name: z.ZodString;
482
- path: z.ZodString;
475
+ path: z.ZodDefault<z.ZodString>;
483
476
  about: z.ZodOptional<z.ZodString>;
484
477
  workflow: z.ZodOptional<z.ZodString>;
485
478
  max_attempts: z.ZodOptional<z.ZodNumber>;
@@ -497,12 +490,12 @@ export declare const SourceDatasetConfigSchema: z.ZodPipe<z.ZodTransform<unknown
497
490
  }, z.core.$strip>>;
498
491
  strictness: z.ZodOptional<z.ZodString>;
499
492
  }, z.core.$strict>>>;
500
- }, z.core.$strict>>;
501
- export declare const CompiledInterfConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
493
+ }, z.core.$strict>;
494
+ export declare const CompiledInterfConfigSchema: z.ZodObject<{
502
495
  type: z.ZodLiteral<"compiled">;
503
496
  name: z.ZodString;
504
497
  about: z.ZodOptional<z.ZodString>;
505
- workflow: z.ZodOptional<z.ZodString>;
498
+ workflow: z.ZodString;
506
499
  max_attempts: z.ZodOptional<z.ZodNumber>;
507
500
  max_loops: z.ZodOptional<z.ZodNumber>;
508
501
  checks: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -525,14 +518,14 @@ export declare const CompiledInterfConfigSchema: z.ZodPipe<z.ZodTransform<unknow
525
518
  source: z.ZodObject<{
526
519
  path: z.ZodString;
527
520
  control_path: z.ZodOptional<z.ZodString>;
528
- dataset_path: z.ZodOptional<z.ZodString>;
521
+ dataset_path: z.ZodString;
529
522
  }, z.core.$strip>;
530
- }, z.core.$loose>>;
531
- export declare const InterfConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
523
+ }, z.core.$loose>;
524
+ export declare const InterfConfigSchema: z.ZodObject<{
532
525
  type: z.ZodLiteral<"compiled">;
533
526
  name: z.ZodString;
534
527
  about: z.ZodOptional<z.ZodString>;
535
- workflow: z.ZodOptional<z.ZodString>;
528
+ workflow: z.ZodString;
536
529
  max_attempts: z.ZodOptional<z.ZodNumber>;
537
530
  max_loops: z.ZodOptional<z.ZodNumber>;
538
531
  checks: z.ZodDefault<z.ZodArray<z.ZodObject<{
@@ -555,9 +548,9 @@ export declare const InterfConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unkno
555
548
  source: z.ZodObject<{
556
549
  path: z.ZodString;
557
550
  control_path: z.ZodOptional<z.ZodString>;
558
- dataset_path: z.ZodOptional<z.ZodString>;
551
+ dataset_path: z.ZodString;
559
552
  }, z.core.$strip>;
560
- }, z.core.$loose>>;
553
+ }, z.core.$loose>;
561
554
  export declare const WorkflowImprovementLoopSummarySchema: z.ZodObject<{
562
555
  variation: z.ZodNumber;
563
556
  kind: z.ZodEnum<{
@@ -734,10 +727,10 @@ export type WorkflowPackageValidation = z.infer<typeof WorkflowPackageValidation
734
727
  export type WorkflowImprovementLoopRecord = z.infer<typeof WorkflowImprovementLoopRecordSchema>;
735
728
  export type WorkflowImprovementRunLedger = z.infer<typeof WorkflowImprovementRunLedgerSchema>;
736
729
  export declare const SourceFolderConfigSchema: z.ZodObject<{
737
- datasets: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
730
+ datasets: z.ZodOptional<z.ZodArray<z.ZodObject<{
738
731
  id: z.ZodOptional<z.ZodString>;
739
732
  name: z.ZodString;
740
- path: z.ZodString;
733
+ path: z.ZodDefault<z.ZodString>;
741
734
  about: z.ZodOptional<z.ZodString>;
742
735
  workflow: z.ZodOptional<z.ZodString>;
743
736
  max_attempts: z.ZodOptional<z.ZodNumber>;
@@ -755,7 +748,7 @@ export declare const SourceFolderConfigSchema: z.ZodObject<{
755
748
  }, z.core.$strip>>;
756
749
  strictness: z.ZodOptional<z.ZodString>;
757
750
  }, z.core.$strict>>>;
758
- }, z.core.$strict>>>>;
751
+ }, z.core.$strict>>>;
759
752
  }, z.core.$strict>;
760
753
  export declare const TestCheckResultSchema: z.ZodObject<{
761
754
  label: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { COMPILED_ZONE_KINDS, } from "./workflow-abi.js";
2
+ import { COMPILED_ZONE_KINDS, } from "./workflow-primitives.js";
3
3
  const JsonRecordSchema = z.record(z.string(), z.unknown());
4
4
  const COMPILED_RELATIVE_PATH_SEGMENT = /^(?!\.{1,2}$)[^/\\]+$/;
5
5
  function isCompiledRelativePath(value) {
@@ -37,13 +37,6 @@ export const CompiledStateSchema = z.object({
37
37
  stages: z.record(z.string().regex(WorkflowIdPattern), CompiledStageStateSchema).optional(),
38
38
  last_add: z.string().nullable().optional(),
39
39
  last_compile: z.string().nullable().optional(),
40
- summarized: z.number().optional(),
41
- structured: z.number().optional(),
42
- shaped: z.number().optional(),
43
- compiled: z.number().optional(),
44
- last_summarize: z.string().nullable().optional(),
45
- last_structure: z.string().nullable().optional(),
46
- last_shape: z.string().nullable().optional(),
47
40
  inventory_complete: z.boolean().optional(),
48
41
  abstracts_read: z.number().optional(),
49
42
  full_reads: z.number().optional(),
@@ -51,7 +44,7 @@ export const CompiledStateSchema = z.object({
51
44
  claim_count: z.number().optional(),
52
45
  warning_count: z.number().optional(),
53
46
  error_count: z.number().optional(),
54
- });
47
+ }).strict();
55
48
  export const ViewSectionSchema = z.object({
56
49
  id: z.string(),
57
50
  type: z.enum(["status", "cards", "graph", "documents", "table"]),
@@ -149,36 +142,14 @@ export const RuntimeExecutorInfoSchema = z.object({
149
142
  profile: z.string().nullable().optional(),
150
143
  timeout_ms: z.number().nullable().optional(),
151
144
  });
152
- export const RuntimeStageInstructionsSchema = z.preprocess((value) => {
153
- if (!value || typeof value !== "object" || Array.isArray(value))
154
- return value;
155
- const raw = value;
156
- const legacyBundledSkill = typeof raw.bundled_skill === "string" && raw.bundled_skill.length > 0
157
- ? raw.bundled_skill.split(/[\\/]/).filter(Boolean).pop()
158
- : undefined;
159
- return {
160
- ...raw,
161
- stage_skill_dir: raw.stage_skill_dir ?? legacyBundledSkill,
162
- };
163
- }, z.object({
145
+ export const RuntimeStageInstructionsSchema = z.object({
164
146
  stage_skill_dir: z.string().regex(WorkflowIdPattern),
165
147
  effective_mode: z.enum(["builtin", "extend", "override"]),
166
148
  local_mode: z.enum(["extend", "override"]).nullable(),
167
149
  local_docs: z.array(z.string()),
168
150
  mode_sources: z.array(z.string()),
169
- }));
170
- export const RuntimeStageAcceptanceSchema = z.preprocess((value) => {
171
- if (!value || typeof value !== "object" || Array.isArray(value))
172
- return value;
173
- const raw = value;
174
- return {
175
- ...raw,
176
- stage_truthy: raw.stage_truthy ?? raw.state_truthy,
177
- stage_equals_counts: raw.stage_equals_counts ?? raw.state_equals_counts,
178
- stage_at_least: raw.stage_at_least ?? raw.state_at_least,
179
- stage_at_least_counts: raw.stage_at_least_counts ?? raw.state_at_least_counts,
180
- };
181
- }, z.object({
151
+ }).strict();
152
+ export const RuntimeStageAcceptanceSchema = z.object({
182
153
  artifacts_exist: z.array(z.string()).optional(),
183
154
  stage_truthy: z.array(z.string()).optional(),
184
155
  stage_equals_counts: z.record(z.string(), z.string()).optional(),
@@ -190,7 +161,7 @@ export const RuntimeStageAcceptanceSchema = z.preprocess((value) => {
190
161
  markdown_abstract_valid_zones: z.array(WorkflowZoneIdSchema).optional(),
191
162
  wikilinks_valid_in_zones: z.array(WorkflowZoneIdSchema).optional(),
192
163
  artifacts_must_not_contain: z.record(z.string(), z.array(z.string().min(1))).optional(),
193
- }));
164
+ }).strict();
194
165
  export const RuntimeStageContractSchema = z.object({
195
166
  kind: z.literal("interf-stage-contract"),
196
167
  version: z.literal(1),
@@ -258,36 +229,14 @@ export const RuntimeRunSchema = z.object({
258
229
  exit_code: z.number().nullable(),
259
230
  error: z.string().nullable(),
260
231
  });
261
- export const CompiledInventoryEntrySchema = z.preprocess((value) => {
262
- if (!value || typeof value !== "object" || Array.isArray(value))
263
- return value;
264
- const raw = value;
265
- if (typeof raw.source !== "string" && typeof raw.summary !== "string")
266
- return raw;
267
- return {
268
- input_zone: raw.input_zone ?? "raw",
269
- input_path: raw.input_path ?? raw.source,
270
- output_zone: raw.output_zone ?? "summaries",
271
- output_path: raw.output_path ?? raw.summary,
272
- state: raw.state,
273
- metadata: {
274
- source_kind: raw.source_kind,
275
- evidence_tier: raw.evidence_tier,
276
- truth_mode: raw.truth_mode,
277
- status: raw.status,
278
- abstract: raw.abstract,
279
- frontmatter_scanned: raw.frontmatter_scanned,
280
- abstract_read: raw.abstract_read,
281
- },
282
- };
283
- }, z.object({
232
+ export const CompiledInventoryEntrySchema = z.object({
284
233
  input_zone: WorkflowZoneIdSchema,
285
234
  input_path: z.string().min(1),
286
235
  output_zone: WorkflowZoneIdSchema,
287
236
  output_path: z.string().min(1),
288
237
  state: z.string().min(1).optional(),
289
238
  metadata: JsonRecordSchema.optional(),
290
- }));
239
+ }).strict();
291
240
  export const CompiledInventorySchema = z.object({
292
241
  kind: z.literal("compiled-runtime-ledger").optional(),
293
242
  version: z.number().int().min(1).optional(),
@@ -327,32 +276,14 @@ const TestCaseCoreSchema = z.object({
327
276
  });
328
277
  }
329
278
  });
330
- export const TestCaseSchema = z.preprocess((value) => {
331
- if (!value || typeof value !== "object" || Array.isArray(value))
332
- return value;
333
- const raw = value;
334
- return {
335
- ...raw,
336
- question: raw.question ?? raw.check ?? raw.ask,
337
- answer: raw.answer ?? raw.expected ?? raw.pass_when,
338
- };
339
- }, TestCaseCoreSchema);
279
+ export const TestCaseSchema = TestCaseCoreSchema;
340
280
  const TestSpecCoreSchema = z.object({
341
281
  type: TestTargetTypeSchema,
342
282
  name: z.string().min(1),
343
283
  description: z.string().min(1).optional(),
344
284
  cases: z.array(TestCaseSchema).min(1),
345
285
  });
346
- export const TestSpecSchema = z.preprocess((value) => {
347
- if (!value || typeof value !== "object" || Array.isArray(value))
348
- return value;
349
- const raw = value;
350
- return {
351
- ...raw,
352
- type: raw.type ?? "compiled",
353
- cases: raw.cases ?? raw.checks,
354
- };
355
- }, TestSpecCoreSchema);
286
+ export const TestSpecSchema = TestSpecCoreSchema;
356
287
  export const SourceTruthCheckSchema = z.object({
357
288
  id: z.string().regex(WorkflowIdPattern).optional(),
358
289
  question: z.string().min(1),
@@ -376,39 +307,21 @@ export const DatasetNameSchema = z
376
307
  .string()
377
308
  .regex(DatasetNamePattern, "Dataset names must use lowercase letters, numbers, and dashes only.")
378
309
  .refine((value) => !RESERVED_DATASET_NAMES.has(value), "Dataset name is reserved.");
379
- export const SourceDatasetConfigSchema = z.preprocess((value) => {
380
- if (!value || typeof value !== "object" || Array.isArray(value))
381
- return value;
382
- const raw = value;
383
- return {
384
- ...raw,
385
- path: raw.path ?? ".",
386
- };
387
- }, z.object({
310
+ export const SourceDatasetConfigSchema = z.object({
388
311
  id: z.string().regex(WorkflowIdPattern).optional(),
389
312
  name: DatasetNameSchema,
390
- path: z.string().min(1),
313
+ path: z.string().min(1).default("."),
391
314
  about: z.string().min(1).optional(),
392
315
  workflow: WorkflowIdSchema.optional(),
393
316
  max_attempts: SourceCompiledMaxAttemptsSchema.optional(),
394
317
  max_loops: SourceCompiledMaxLoopsSchema.optional(),
395
318
  checks: z.array(SourceTruthCheckSchema).default([]),
396
- }).strict());
397
- export const CompiledInterfConfigSchema = z.preprocess((value) => {
398
- if (!value || typeof value !== "object" || Array.isArray(value))
399
- return value;
400
- const raw = value;
401
- return {
402
- ...raw,
403
- type: "compiled",
404
- source: raw.source ?? { path: "./raw" },
405
- checks: raw.checks ?? [],
406
- };
407
- }, z.object({
319
+ }).strict();
320
+ export const CompiledInterfConfigSchema = z.object({
408
321
  type: z.literal("compiled"),
409
322
  name: DatasetNameSchema,
410
323
  about: z.string().optional(),
411
- workflow: WorkflowIdSchema.optional(),
324
+ workflow: WorkflowIdSchema,
412
325
  max_attempts: SourceCompiledMaxAttemptsSchema.optional(),
413
326
  max_loops: SourceCompiledMaxLoopsSchema.optional(),
414
327
  checks: z.array(SourceTruthCheckSchema).default([]),
@@ -419,9 +332,9 @@ export const CompiledInterfConfigSchema = z.preprocess((value) => {
419
332
  source: z.object({
420
333
  path: z.string(),
421
334
  control_path: z.string().optional(),
422
- dataset_path: z.string().optional(),
335
+ dataset_path: z.string(),
423
336
  }),
424
- }).passthrough());
337
+ }).passthrough();
425
338
  export const InterfConfigSchema = CompiledInterfConfigSchema;
426
339
  export const WorkflowImprovementLoopSummarySchema = z.object({
427
340
  variation: z.number().int().min(1),
@@ -83,19 +83,22 @@ function toWritableSourceProjectConfig(config) {
83
83
  const datasets = config?.datasets ?? [];
84
84
  if (datasets.length > 0) {
85
85
  return {
86
- datasets: datasets.map((dataset) => ({
87
- name: dataset.name,
88
- ...(dataset.path && dataset.path !== "." ? { path: dataset.path } : {}),
89
- ...(dataset.about ? { about: dataset.about } : {}),
90
- ...(dataset.workflow && dataset.workflow !== "interf" ? { workflow: dataset.workflow } : {}),
91
- ...(typeof dataset.max_attempts === "number" ? { max_attempts: dataset.max_attempts } : {}),
92
- ...(typeof dataset.max_loops === "number" ? { max_loops: dataset.max_loops } : {}),
93
- checks: dataset.checks,
94
- })),
86
+ datasets: datasets.map((dataset) => toWritableSourceDatasetConfig(dataset)),
95
87
  };
96
88
  }
97
89
  return {};
98
90
  }
91
+ function toWritableSourceDatasetConfig(dataset) {
92
+ return {
93
+ name: dataset.name,
94
+ ...(dataset.path && dataset.path !== "." ? { path: dataset.path } : {}),
95
+ ...(dataset.about ? { about: dataset.about } : {}),
96
+ ...(dataset.workflow && dataset.workflow !== "interf" ? { workflow: dataset.workflow } : {}),
97
+ ...(typeof dataset.max_attempts === "number" ? { max_attempts: dataset.max_attempts } : {}),
98
+ ...(typeof dataset.max_loops === "number" ? { max_loops: dataset.max_loops } : {}),
99
+ checks: dataset.checks,
100
+ };
101
+ }
99
102
  export function saveSourceFolderConfig(sourcePath, config) {
100
103
  writeFileSync(sourceConfigPath(sourcePath), JSON.stringify(toWritableSourceProjectConfig(config), null, 2) + "\n");
101
104
  }
@@ -104,21 +107,17 @@ export function appendSourceDatasetChecks(sourcePath, datasetName, checks) {
104
107
  const currentDataset = findSourceDatasetConfig(existing, datasetName);
105
108
  const otherDatasets = listSourceDatasetConfigs(existing).filter((dataset) => dataset.name !== datasetName);
106
109
  const currentChecks = currentDataset?.checks ?? [];
110
+ const nextDataset = {
111
+ ...toWritableSourceDatasetConfig(currentDataset ?? {
112
+ name: datasetName,
113
+ path: ".",
114
+ checks: [],
115
+ }),
116
+ checks: [...currentChecks, ...checks],
117
+ };
107
118
  saveSourceFolderConfig(sourcePath, {
108
119
  datasets: [
109
- {
110
- name: datasetName,
111
- path: currentDataset?.path ?? ".",
112
- ...(currentDataset?.about ? { about: currentDataset.about } : {}),
113
- ...(currentDataset?.workflow ? { workflow: currentDataset.workflow } : {}),
114
- ...(typeof currentDataset?.max_attempts === "number"
115
- ? { max_attempts: currentDataset.max_attempts }
116
- : {}),
117
- ...(typeof currentDataset?.max_loops === "number"
118
- ? { max_loops: currentDataset.max_loops }
119
- : {}),
120
- checks: [...currentChecks, ...checks],
121
- },
120
+ nextDataset,
122
121
  ...otherDatasets,
123
122
  ],
124
123
  });
@@ -7,7 +7,7 @@ import { loadState } from "./state-io.js";
7
7
  import { validateCompiled, validateCompiledStage, validateCompiledWorkflow, } from "./validate.js";
8
8
  import { readCompiledSchemaFile } from "./compiled-schema.js";
9
9
  import { workflowPackagePathForCompiled } from "./compiled-paths.js";
10
- import { getActiveCompiledWorkflow, resolveCompiledWorkflowFromConfig } from "./workflow-definitions.js";
10
+ import { getActiveCompiledWorkflow, resolveRequiredCompiledWorkflowFromConfig } from "./workflow-definitions.js";
11
11
  import { listFilesRecursive } from "./filesystem.js";
12
12
  function countZoneArtifacts(compiledPath, zonePath, kind) {
13
13
  const absolutePath = join(compiledPath, zonePath);
@@ -26,7 +26,9 @@ export function computeCompiledHealth(dirPath) {
26
26
  const state = loadState(dirPath);
27
27
  const validation = validateCompiled(dirPath);
28
28
  const activeRun = loadRuntimeRun(dirPath);
29
- const workflowId = config ? resolveCompiledWorkflowFromConfig(config) : null;
29
+ const workflowId = config
30
+ ? resolveRequiredCompiledWorkflowFromConfig(config, `.interf/interf.json for ${dirPath}`)
31
+ : null;
30
32
  let workflow = null;
31
33
  if (workflowId) {
32
34
  try {
@@ -1,17 +1,10 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
2
2
  import { warnInterf } from "./logger.js";
3
3
  import { readJsonFileUnchecked, readJsonFileWithSchema } from "./parse.js";
4
- import { CompiledHealthSchema, CompiledInventorySchema, CompiledRawSnapshotSchema, CompiledStateSchema, CompiledViewSpecSchema, } from "./schema.js";
5
- import { compiledInventoryEntryCount, compiledInventoryTotal, emptyCompiledInventory, } from "./runtime-inventory.js";
4
+ import { CompiledHealthSchema, CompiledRawSnapshotSchema, CompiledStateSchema, CompiledViewSpecSchema, } from "./schema.js";
5
+ import { emptyCompiledInventory, } from "./runtime-inventory.js";
6
6
  import { healthPath, rawSnapshotPath, statePath, viewSpecPath } from "./state-paths.js";
7
7
  import { compiledRuntimeInventoryPath, compiledRuntimeRoot, } from "./compiled-paths.js";
8
- const NORMALIZABLE_RUNTIME_TIMESTAMP_FIELDS = [
9
- "last_add",
10
- "last_summarize",
11
- "last_structure",
12
- "last_shape",
13
- "last_compile",
14
- ];
15
8
  export function loadState(dirPath) {
16
9
  const path = statePath(dirPath);
17
10
  if (!existsSync(path))
@@ -21,18 +14,8 @@ export function loadState(dirPath) {
21
14
  return null;
22
15
  const parsed = CompiledStateSchema.safeParse(raw);
23
16
  if (parsed.success) {
24
- const healed = healParsedRuntimeState(dirPath, parsed.data);
25
- if (healed !== null) {
26
- saveState(dirPath, healed);
27
- return healed;
28
- }
29
17
  return parsed.data;
30
18
  }
31
- const normalized = normalizeRuntimeState(raw);
32
- if (normalized !== null) {
33
- saveState(dirPath, normalized);
34
- return normalized;
35
- }
36
19
  warnInterf(`Warning: failed to validate runtime state at ${path}: ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
37
20
  return null;
38
21
  }
@@ -81,97 +64,6 @@ export function initCompiledState() {
81
64
  error_count: 0,
82
65
  };
83
66
  }
84
- function normalizeRuntimeState(raw) {
85
- if (!raw || typeof raw !== "object" || Array.isArray(raw))
86
- return null;
87
- const normalized = { ...raw };
88
- let changed = false;
89
- for (const field of NORMALIZABLE_RUNTIME_TIMESTAMP_FIELDS) {
90
- const timestamp = normalizeRuntimeTimestampField(normalized[field]);
91
- if (timestamp !== undefined && timestamp !== normalized[field]) {
92
- normalized[field] = timestamp;
93
- changed = true;
94
- }
95
- }
96
- if (!changed)
97
- return null;
98
- const parsed = CompiledStateSchema.safeParse(normalized);
99
- return parsed.success ? parsed.data : null;
100
- }
101
- function healParsedRuntimeState(dirPath, state) {
102
- const hasLegacyStageFields = (typeof state.last_summarize === "string" && state.last_summarize.length > 0) ||
103
- (typeof state.last_structure === "string" && state.last_structure.length > 0) ||
104
- (typeof state.last_shape === "string" && state.last_shape.length > 0);
105
- const hasStageMap = Boolean(state.stages) &&
106
- typeof state.stages === "object" &&
107
- Object.keys(state.stages ?? {}).length > 0;
108
- if (state.version >= 2 && (hasStageMap || !hasLegacyStageFields))
109
- return null;
110
- const next = {
111
- ...initCompiledState(),
112
- ...state,
113
- stages: { ...(state.stages ?? {}) },
114
- };
115
- if (typeof state.last_summarize === "string" && state.last_summarize.length > 0) {
116
- next.stages.summarize = {
117
- contract_type: "compiled-file-evidence",
118
- status: "succeeded",
119
- finished_at: state.last_summarize,
120
- counts: {
121
- summarized: state.summarized ?? 0,
122
- expected_summary_total: state.summarized ?? 0,
123
- },
124
- zone_counts: {
125
- summaries: state.summarized ?? 0,
126
- },
127
- };
128
- }
129
- if (typeof state.last_structure === "string" && state.last_structure.length > 0) {
130
- next.stages.structure = {
131
- contract_type: "compiled-knowledge-structure",
132
- status: "succeeded",
133
- finished_at: state.last_structure,
134
- counts: {
135
- summary_total: state.structured ?? state.summarized ?? 0,
136
- },
137
- };
138
- }
139
- if (typeof state.last_shape === "string" && state.last_shape.length > 0) {
140
- next.stages.shape = {
141
- contract_type: "compiled-query-shape",
142
- status: "succeeded",
143
- finished_at: state.last_shape,
144
- counts: {
145
- summary_total: state.shaped ?? state.summarized ?? 0,
146
- },
147
- };
148
- }
149
- const inventoryPath = compiledRuntimeInventoryPath(dirPath);
150
- if (existsSync(inventoryPath)) {
151
- const inventory = readJsonFileWithSchema(inventoryPath, "compiled inventory", CompiledInventorySchema);
152
- const inventoryTotal = compiledInventoryTotal(inventory);
153
- if (inventory &&
154
- inventoryTotal === (state.summarized ?? 0) &&
155
- compiledInventoryEntryCount(inventory) === (state.summarized ?? 0)) {
156
- next.inventory_complete = true;
157
- }
158
- }
159
- return next;
160
- }
161
- function normalizeRuntimeTimestampField(value) {
162
- if (typeof value === "string" || value === null)
163
- return value;
164
- if (!value || typeof value !== "object" || Array.isArray(value))
165
- return undefined;
166
- const record = value;
167
- for (const key of ["generated_at", "finished_at", "updated_at", "started_at", "timestamp"]) {
168
- const candidate = record[key];
169
- if (typeof candidate === "string" && candidate.length > 0) {
170
- return candidate;
171
- }
172
- }
173
- return undefined;
174
- }
175
67
  function loadViewSpec(filePath, schema) {
176
68
  try {
177
69
  const raw = JSON.parse(readFileSync(filePath, "utf8"));
@@ -6,7 +6,7 @@ import { loadCompiledViewSpec, saveCompiledViewSpec, } from "./state-io.js";
6
6
  import { rawSnapshotPath } from "./state-paths.js";
7
7
  import { compiledRuntimeRoot, workflowPackagePathForCompiled } from "./compiled-paths.js";
8
8
  import { readCompiledSchemaFile } from "./compiled-schema.js";
9
- import { getActiveCompiledWorkflow, resolveCompiledWorkflowFromConfig } from "./workflow-definitions.js";
9
+ import { getActiveCompiledWorkflow, resolveRequiredCompiledWorkflowFromConfig } from "./workflow-definitions.js";
10
10
  export function ensureCompiledViewSpec(dirPath) {
11
11
  const existing = loadCompiledViewSpec(dirPath);
12
12
  const now = new Date().toISOString();
@@ -70,7 +70,7 @@ export function normalizeCompiledViewSpec(existing, defaults) {
70
70
  }
71
71
  function buildDefaultCompiledViewSpec(dirPath, compiledName, generatedAt) {
72
72
  const config = readInterfConfig(dirPath);
73
- const workflowId = resolveCompiledWorkflowFromConfig(config);
73
+ const workflowId = resolveRequiredCompiledWorkflowFromConfig(config, `.interf/interf.json for ${dirPath}`);
74
74
  const workflow = getActiveCompiledWorkflow(dirPath, workflowId);
75
75
  const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(dirPath));
76
76
  const zoneDocumentPaths = (schema?.zones ?? [])