@interf/compiler 0.5.0 → 0.6.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 (113) hide show
  1. package/README.md +126 -188
  2. package/builtin-workflows/interf/README.md +22 -10
  3. package/builtin-workflows/interf/compile/stages/shape/SKILL.md +6 -3
  4. package/builtin-workflows/interf/compile/stages/structure/SKILL.md +3 -0
  5. package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +18 -2
  6. package/builtin-workflows/interf/improve/SKILL.md +2 -2
  7. package/builtin-workflows/interf/workflow.json +18 -4
  8. package/builtin-workflows/interf/{compiled.schema.json → workflow.schema.json} +9 -2
  9. package/dist/commands/check-draft.js +3 -3
  10. package/dist/commands/compile-controller.js +9 -16
  11. package/dist/commands/compile.d.ts +19 -1
  12. package/dist/commands/compile.js +98 -28
  13. package/dist/commands/create-workflow-wizard.d.ts +20 -2
  14. package/dist/commands/create-workflow-wizard.js +163 -27
  15. package/dist/commands/create.d.ts +1 -1
  16. package/dist/commands/create.js +67 -60
  17. package/dist/commands/dataset-selection.d.ts +6 -0
  18. package/dist/commands/dataset-selection.js +11 -0
  19. package/dist/commands/default.js +3 -3
  20. package/dist/commands/doctor.js +8 -8
  21. package/dist/commands/executor-flow.d.ts +1 -1
  22. package/dist/commands/executor-flow.js +5 -2
  23. package/dist/commands/init.d.ts +5 -0
  24. package/dist/commands/init.js +56 -48
  25. package/dist/commands/list.js +6 -3
  26. package/dist/commands/reset.js +1 -1
  27. package/dist/commands/source-config-wizard.d.ts +2 -2
  28. package/dist/commands/source-config-wizard.js +50 -17
  29. package/dist/commands/test-flow.js +5 -16
  30. package/dist/commands/test.d.ts +0 -6
  31. package/dist/commands/test.js +9 -17
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/lib/agent-args.d.ts +1 -0
  35. package/dist/lib/agent-args.js +10 -0
  36. package/dist/lib/agent-execution.js +2 -1
  37. package/dist/lib/agent-preflight.js +2 -1
  38. package/dist/lib/agent-shells.d.ts +26 -1
  39. package/dist/lib/agent-shells.js +214 -40
  40. package/dist/lib/agents.d.ts +1 -1
  41. package/dist/lib/agents.js +1 -1
  42. package/dist/lib/builtin-compiled-workflow.d.ts +38 -0
  43. package/dist/lib/builtin-compiled-workflow.js +94 -0
  44. package/dist/lib/compiled-compile.d.ts +0 -4
  45. package/dist/lib/compiled-compile.js +11 -30
  46. package/dist/lib/compiled-paths.d.ts +1 -2
  47. package/dist/lib/compiled-paths.js +8 -13
  48. package/dist/lib/compiled-raw.d.ts +2 -2
  49. package/dist/lib/compiled-reset.d.ts +1 -0
  50. package/dist/lib/compiled-reset.js +42 -14
  51. package/dist/lib/compiled-schema.d.ts +11 -7
  52. package/dist/lib/compiled-schema.js +47 -16
  53. package/dist/lib/discovery.d.ts +1 -1
  54. package/dist/lib/discovery.js +2 -2
  55. package/dist/lib/executors.d.ts +1 -1
  56. package/dist/lib/executors.js +2 -2
  57. package/dist/lib/interf-detect.d.ts +0 -1
  58. package/dist/lib/interf-detect.js +7 -18
  59. package/dist/lib/interf-scaffold.js +4 -11
  60. package/dist/lib/interf-workflow-package.d.ts +8 -3
  61. package/dist/lib/interf-workflow-package.js +128 -62
  62. package/dist/lib/interf.d.ts +1 -1
  63. package/dist/lib/interf.js +1 -1
  64. package/dist/lib/local-workflows.d.ts +4 -3
  65. package/dist/lib/local-workflows.js +127 -104
  66. package/dist/lib/project-paths.d.ts +2 -4
  67. package/dist/lib/project-paths.js +13 -10
  68. package/dist/lib/runtime-acceptance.js +15 -3
  69. package/dist/lib/runtime-contracts.js +3 -2
  70. package/dist/lib/runtime-paths.d.ts +1 -0
  71. package/dist/lib/runtime-paths.js +4 -1
  72. package/dist/lib/runtime-prompt.js +4 -4
  73. package/dist/lib/runtime-reconcile.js +90 -64
  74. package/dist/lib/runtime-runs.js +29 -102
  75. package/dist/lib/runtime.d.ts +1 -1
  76. package/dist/lib/runtime.js +1 -1
  77. package/dist/lib/schema.d.ts +104 -54
  78. package/dist/lib/schema.js +32 -116
  79. package/dist/lib/source-config.js +21 -22
  80. package/dist/lib/state-health.js +4 -2
  81. package/dist/lib/state-io.js +2 -110
  82. package/dist/lib/state-view.js +8 -8
  83. package/dist/lib/state.d.ts +1 -0
  84. package/dist/lib/state.js +7 -0
  85. package/dist/lib/test-execution.js +2 -2
  86. package/dist/lib/test-paths.js +12 -3
  87. package/dist/lib/test-sandbox.js +4 -17
  88. package/dist/lib/test-specs.js +1 -1
  89. package/dist/lib/validate-compiled.js +13 -8
  90. package/dist/lib/validate.d.ts +5 -1
  91. package/dist/lib/validate.js +30 -22
  92. package/dist/lib/workflow-authoring.d.ts +26 -0
  93. package/dist/lib/workflow-authoring.js +119 -0
  94. package/dist/lib/workflow-definitions.d.ts +14 -3
  95. package/dist/lib/workflow-definitions.js +21 -17
  96. package/dist/lib/workflow-edit-session.d.ts +16 -0
  97. package/dist/lib/workflow-edit-session.js +57 -0
  98. package/dist/lib/workflow-edit-utils.d.ts +10 -0
  99. package/dist/lib/workflow-edit-utils.js +39 -0
  100. package/dist/lib/workflow-improvement.js +30 -217
  101. package/dist/lib/workflow-primitives.d.ts +2 -0
  102. package/dist/lib/workflow-primitives.js +5 -0
  103. package/dist/lib/workflow-stage-policy.d.ts +5 -0
  104. package/dist/lib/workflow-stage-policy.js +31 -0
  105. package/package.json +7 -8
  106. package/dist/lib/compiled-layout.d.ts +0 -2
  107. package/dist/lib/compiled-layout.js +0 -60
  108. package/dist/lib/obsidian.d.ts +0 -1
  109. package/dist/lib/obsidian.js +0 -15
  110. package/dist/lib/summarize-plan.d.ts +0 -17
  111. package/dist/lib/summarize-plan.js +0 -124
  112. package/dist/lib/workflow-abi.d.ts +0 -129
  113. package/dist/lib/workflow-abi.js +0 -156
@@ -5,7 +5,7 @@ import { reconcileCompiledStageRun, } from "./runtime-reconcile.js";
5
5
  import { refreshCompiledArtifacts, } from "./state.js";
6
6
  import { buildRuntimeStageContract, } from "./runtime.js";
7
7
  import { validateWorkflowPackage } from "./local-workflows.js";
8
- import { formatActiveCompiledWorkflowStageStep, getActiveCompiledStagePolicyNotes, getActiveCompiledWorkflow, resolveCompiledWorkflowFromConfig, resolveActiveCompiledStageAcceptance, } from "./workflow-definitions.js";
8
+ import { formatActiveCompiledWorkflowStageStep, getActiveCompiledStagePolicyNotes, getActiveCompiledWorkflow, resolveRequiredCompiledWorkflowFromConfig, resolveActiveCompiledStageAcceptance, } from "./workflow-definitions.js";
9
9
  import { validateCompiledStage, validateCompiledWorkflow, } from "./validate.js";
10
10
  import { buildLocalSkillContractExtension, buildStageInstructions, reportBlankLine, reportLine, reportValidationFailure, workflowCompileStageDirectory, } from "./workflow-helpers.js";
11
11
  import { executeValidatedStage, } from "./workflow-stage-runner.js";
@@ -16,7 +16,7 @@ import { discoverSourceFiles } from "./discovery.js";
16
16
  import { listFilesRecursive } from "./filesystem.js";
17
17
  export function resolveCompiledContext(compiledPath) {
18
18
  const config = readInterfConfig(compiledPath);
19
- const workflowId = resolveCompiledWorkflowFromConfig(config);
19
+ const workflowId = resolveRequiredCompiledWorkflowFromConfig(config, `.interf/interf.json for ${compiledPath}`);
20
20
  return {
21
21
  compiledName: config?.name ?? "compiled",
22
22
  sourcePath: resolveSourceFolderPath(compiledPath, config),
@@ -44,7 +44,7 @@ function zoneArtifactCount(compiledPath, zonePath, kind) {
44
44
  function resolveStageContractArtifacts(compiledPath, stageDefinition) {
45
45
  const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
46
46
  if (!schema) {
47
- throw new Error(`Missing compiled schema for stage "${stageDefinition.id}" at ${workflowPackagePathForCompiled(compiledPath)}.`);
47
+ throw new Error(`Missing workflow schema for stage "${stageDefinition.id}" at ${workflowPackagePathForCompiled(compiledPath)}.`);
48
48
  }
49
49
  return {
50
50
  reads: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.reads),
@@ -198,10 +198,6 @@ export async function compileCompiled(options) {
198
198
  ok: true,
199
199
  stageResults: {},
200
200
  failedStage: null,
201
- summarize: null,
202
- structure: null,
203
- shape: null,
204
- compile: null,
205
201
  };
206
202
  try {
207
203
  const sourceInputPath = resolveSourceInputPath(options.compiledPath);
@@ -214,10 +210,13 @@ export async function compileCompiled(options) {
214
210
  ...result,
215
211
  ok: false,
216
212
  failedStage: "workflow",
217
- compile: {
218
- ok: false,
219
- code: 1,
220
- summary: workflowValidation.summary,
213
+ stageResults: {
214
+ ...result.stageResults,
215
+ workflow: {
216
+ ok: false,
217
+ code: 1,
218
+ summary: workflowValidation.summary,
219
+ },
221
220
  },
222
221
  };
223
222
  }
@@ -232,34 +231,16 @@ export async function compileCompiled(options) {
232
231
  stageDefinition,
233
232
  });
234
233
  result.stageResults[stageDefinition.id] = stageResult;
235
- if (stageDefinition.id === "summarize") {
236
- result.summarize = {
237
- ...stageResult,
238
- skipped: false,
239
- plan: {
240
- sourceCount: discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount,
241
- summaryCount: 0,
242
- targetCount: discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount,
243
- },
244
- };
245
- }
246
- else if (stageDefinition.id === "structure") {
247
- result.structure = stageResult;
248
- }
249
- else if (stageDefinition.id === "shape") {
250
- result.shape = stageResult;
251
- }
252
234
  if (!stageResult.ok) {
253
235
  result.ok = false;
254
236
  result.failedStage = stageDefinition.id;
255
- result.compile = stageResult;
256
237
  return result;
257
238
  }
258
239
  }
259
240
  const workflowValidationResult = validateCompiledWorkflow(options.compiledPath);
260
241
  result.ok = workflowValidationResult.ok;
261
242
  result.failedStage = workflowValidationResult.ok ? null : workflowValidationResult.stage;
262
- result.compile = {
243
+ result.stageResults.compiled = {
263
244
  ok: workflowValidationResult.ok,
264
245
  code: workflowValidationResult.ok ? 0 : 1,
265
246
  summary: workflowValidationResult.summary,
@@ -18,9 +18,7 @@ export declare function compiledInterfRoot(compiledPath: string): string;
18
18
  export declare function compiledInterfConfigPath(compiledPath: string): string;
19
19
  export declare function workflowPackagePathForCompiled(compiledPath: string): string;
20
20
  export declare function testRootForCompiled(compiledPath: string): string;
21
- export declare function testRunsRootForCompiled(compiledPath: string): string;
22
21
  export declare function testTargetsRootForCompiled(compiledPath: string): string;
23
- export declare function latestTestComparisonPathForCompiled(compiledPath: string): string;
24
22
  export declare function stageExecutionShellsRoot(compiledPath: string): string;
25
23
  export declare function workflowImprovementLoopsRoot(compiledPath: string): string;
26
24
  export declare function workflowImprovementRunRoot(compiledPath: string, runId: string): string;
@@ -28,6 +26,7 @@ export declare function workflowImprovementLoopRoot(compiledPath: string, runId:
28
26
  export declare function targetTestRunsRootForCompiled(compiledPath: string): string;
29
27
  export declare function targetTestSandboxesRootForCompiled(compiledPath: string): string;
30
28
  export declare function compiledRuntimeLogsRoot(compiledPath: string): string;
29
+ export declare function compiledRuntimeArchivedStageContractPath(compiledPath: string, runId: string): string;
31
30
  export declare function compiledQueryAcceptanceRoot(compiledPath: string): string;
32
31
  export declare function compiledRuntimeStatePath(compiledPath: string): string;
33
32
  export declare function compiledRuntimeHealthPath(compiledPath: string): string;
@@ -31,15 +31,9 @@ export function workflowPackagePathForCompiled(compiledPath) {
31
31
  export function testRootForCompiled(compiledPath) {
32
32
  return join(compiledInterfRoot(compiledPath), COMPILED_TEST_DIR);
33
33
  }
34
- export function testRunsRootForCompiled(compiledPath) {
35
- return join(testRootForCompiled(compiledPath), "runs");
36
- }
37
34
  export function testTargetsRootForCompiled(compiledPath) {
38
35
  return join(testRootForCompiled(compiledPath), COMPILED_TEST_TARGETS_DIR);
39
36
  }
40
- export function latestTestComparisonPathForCompiled(compiledPath) {
41
- return join(testRootForCompiled(compiledPath), "latest.json");
42
- }
43
37
  export function stageExecutionShellsRoot(compiledPath) {
44
38
  return join(compiledRuntimeRoot(compiledPath), "execution-shells");
45
39
  }
@@ -61,6 +55,9 @@ export function targetTestSandboxesRootForCompiled(compiledPath) {
61
55
  export function compiledRuntimeLogsRoot(compiledPath) {
62
56
  return join(compiledRuntimeRoot(compiledPath), "logs");
63
57
  }
58
+ export function compiledRuntimeArchivedStageContractPath(compiledPath, runId) {
59
+ return join(compiledRuntimeLogsRoot(compiledPath), `${runId}.stage-contract.json`);
60
+ }
64
61
  export function compiledQueryAcceptanceRoot(compiledPath) {
65
62
  return join(compiledRuntimeRoot(compiledPath), "query-acceptance");
66
63
  }
@@ -91,14 +88,12 @@ export function compiledRuntimeStageContractPath(compiledPath) {
91
88
  export function resolveSourceControlPathForCompiled(compiledPath) {
92
89
  let cursor = resolve(compiledPath);
93
90
  while (true) {
94
- if (basename(cursor) === "compiled") {
95
- const datasetRoot = dirname(cursor);
96
- const interfRoot = dirname(datasetRoot);
97
- if (basename(interfRoot) === "interf") {
98
- return dirname(interfRoot);
99
- }
100
- }
101
91
  const parent = dirname(cursor);
92
+ if (basename(parent) === "interf" &&
93
+ basename(cursor) !== "tests" &&
94
+ basename(cursor) !== "workflows") {
95
+ return dirname(parent);
96
+ }
102
97
  if (parent === cursor)
103
98
  break;
104
99
  cursor = parent;
@@ -9,6 +9,7 @@ export declare function resolveCompiledRawPath(compiledPath: string, config?: {
9
9
  [x: string]: unknown;
10
10
  type: "compiled";
11
11
  name: string;
12
+ workflow: string;
12
13
  checks: {
13
14
  question: string;
14
15
  id?: string | undefined;
@@ -24,11 +25,10 @@ export declare function resolveCompiledRawPath(compiledPath: string, config?: {
24
25
  }[];
25
26
  source: {
26
27
  path: string;
28
+ dataset_path: string;
27
29
  control_path?: string | undefined;
28
- dataset_path?: string | undefined;
29
30
  };
30
31
  about?: string | undefined;
31
- workflow?: string | undefined;
32
32
  max_attempts?: number | undefined;
33
33
  max_loops?: number | undefined;
34
34
  workflow_origin?: {
@@ -1 +1,2 @@
1
+ export declare function clearCompiledRuntimeDerivedArtifacts(compiledPath: string): void;
1
2
  export declare function resetCompiledGeneratedState(compiledPath: string, scope?: "compile" | "all"): void;
@@ -1,9 +1,8 @@
1
- import { existsSync, rmSync } from "node:fs";
1
+ import { existsSync, readdirSync, rmSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { compiledKnowledgeRootPath, compiledSummariesPath, } from "./compiled-schema.js";
4
- import { initCompiledState, refreshCompiledArtifacts, saveState, } from "./state.js";
5
- import { saveEmptyCompiledInventory } from "./state-io.js";
6
- import { stageExecutionShellsRoot, testRootForCompiled, testTargetsRootForCompiled, workflowImprovementLoopsRoot, compiledQueryAcceptanceRoot, compiledRuntimeRoot, compiledRuntimeLogsRoot, } from "./compiled-paths.js";
3
+ import { readCompiledSchemaFile, } from "./compiled-schema.js";
4
+ import { initializeCompiledRuntimeState, } from "./state.js";
5
+ import { stageExecutionShellsRoot, testRootForCompiled, testTargetsRootForCompiled, workflowImprovementLoopsRoot, compiledQueryAcceptanceRoot, compiledRuntimeRoot, compiledRuntimeLogsRoot, workflowPackagePathForCompiled, } from "./compiled-paths.js";
7
6
  function removeIfExists(path) {
8
7
  if (existsSync(path)) {
9
8
  rmSync(path, { recursive: true, force: true });
@@ -15,24 +14,53 @@ const COMPILE_RUNTIME_RESET_ENTRIES = [
15
14
  "view-spec.json",
16
15
  "inventory.json",
17
16
  "run.json",
17
+ "raw-snapshot.json",
18
18
  "stage-contract.json",
19
- "summarize-targets.json",
20
19
  ];
21
- function resetCompiledRuntimeFiles(compiledPath) {
20
+ const PRESERVED_COMPILED_ROOTS = new Set([
21
+ ".agents",
22
+ ".claude",
23
+ ".codex",
24
+ ".cursor",
25
+ ".gitignore",
26
+ ".interf",
27
+ ".interfignore",
28
+ "AGENTS.md",
29
+ "CLAUDE.md",
30
+ ]);
31
+ export function clearCompiledRuntimeDerivedArtifacts(compiledPath) {
22
32
  const runtimeRoot = compiledRuntimeRoot(compiledPath);
23
33
  for (const entry of COMPILE_RUNTIME_RESET_ENTRIES) {
24
34
  removeIfExists(join(runtimeRoot, entry));
25
35
  }
26
36
  removeIfExists(compiledQueryAcceptanceRoot(compiledPath));
27
37
  }
38
+ function activeCompiledInputRoots(compiledPath) {
39
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
40
+ const roots = new Set();
41
+ for (const zone of schema?.zones ?? []) {
42
+ if (zone.role !== "input")
43
+ continue;
44
+ const root = zone.path.split("/")[0]?.trim();
45
+ if (root)
46
+ roots.add(root);
47
+ }
48
+ return roots;
49
+ }
50
+ function resetCompiledGeneratedOutputs(compiledPath) {
51
+ const preservedInputRoots = activeCompiledInputRoots(compiledPath);
52
+ for (const entry of readdirSync(compiledPath)) {
53
+ if (PRESERVED_COMPILED_ROOTS.has(entry))
54
+ continue;
55
+ if (preservedInputRoots.has(entry))
56
+ continue;
57
+ removeIfExists(join(compiledPath, entry));
58
+ }
59
+ }
28
60
  export function resetCompiledGeneratedState(compiledPath, scope = "compile") {
29
- removeIfExists(compiledSummariesPath(compiledPath));
30
- removeIfExists(compiledKnowledgeRootPath(compiledPath));
31
- removeIfExists(join(compiledPath, ".obsidian"));
32
- resetCompiledRuntimeFiles(compiledPath);
33
- saveState(compiledPath, initCompiledState());
34
- saveEmptyCompiledInventory(compiledPath);
35
- refreshCompiledArtifacts(compiledPath, { ensureViewSpec: true });
61
+ resetCompiledGeneratedOutputs(compiledPath);
62
+ clearCompiledRuntimeDerivedArtifacts(compiledPath);
63
+ initializeCompiledRuntimeState(compiledPath);
36
64
  if (scope === "all") {
37
65
  removeIfExists(stageExecutionShellsRoot(compiledPath));
38
66
  removeIfExists(workflowImprovementLoopsRoot(compiledPath));
@@ -1,13 +1,15 @@
1
- import { type BuiltinCompiledZoneId } from "./workflow-abi.js";
1
+ import { type BuiltinCompiledZoneId } from "./builtin-compiled-workflow.js";
2
2
  import { type WorkflowCompiledSchema, type WorkflowCompiledZone, type WorkflowZoneId } from "./schema.js";
3
3
  export interface WorkflowSchemaStageLike {
4
4
  id: string;
5
5
  writes: readonly string[];
6
6
  }
7
- export { BUILTIN_COMPILED_ZONE_IDS } from "./workflow-abi.js";
8
- export declare const COMPILED_SCHEMA_FILE = "compiled.schema.json";
9
- export declare function compiledSchemaFilePath(rootPath: string): string;
10
- export declare function compiledSchemaRelativePath(): string;
7
+ export { BUILTIN_COMPILED_ZONE_IDS } from "./builtin-compiled-workflow.js";
8
+ export declare const WORKFLOW_SCHEMA_FILE = "workflow.schema.json";
9
+ export declare function workflowSchemaFilePath(rootPath: string): string;
10
+ export declare function resolveWorkflowSchemaPath(rootPath: string): string | null;
11
+ export declare function workflowSchemaExists(rootPath: string): boolean;
12
+ export declare function workflowSchemaRelativePath(): string;
11
13
  export declare function listCompiledSchemaZones(schema: WorkflowCompiledSchema): WorkflowCompiledZone[];
12
14
  export declare function findCompiledSchemaZone(schema: WorkflowCompiledSchema, zoneId: WorkflowZoneId): WorkflowCompiledZone | null;
13
15
  export declare function compiledZoneAbsolutePath(compiledPath: string, zone: Pick<WorkflowCompiledZone, "path">): string;
@@ -22,6 +24,8 @@ export declare function compiledKnowledgeIndexesPath(compiledPath: string): stri
22
24
  export declare function compiledKnowledgeRootPath(compiledPath: string): string;
23
25
  export declare function compiledHomePath(compiledPath: string): string;
24
26
  export declare function ensureCompiledZoneTargets(compiledPath: string, schema: WorkflowCompiledSchema): void;
25
- export declare function buildCompiledSchema(stages: WorkflowSchemaStageLike[], label?: string): WorkflowCompiledSchema;
26
- export declare function writeCompiledSchemaFile(rootPath: string, stages: WorkflowSchemaStageLike[], label?: string): WorkflowCompiledSchema;
27
+ export declare function buildWorkflowSchema(stages: WorkflowSchemaStageLike[], label?: string): WorkflowCompiledSchema;
28
+ export declare function writeWorkflowSchemaFile(rootPath: string, stages: WorkflowSchemaStageLike[], label?: string): WorkflowCompiledSchema;
29
+ export declare function writeWorkflowSchemaDocument(rootPath: string, schema: WorkflowCompiledSchema): WorkflowCompiledSchema;
30
+ export declare function readWorkflowSchemaFile(rootPath: string): WorkflowCompiledSchema | null;
27
31
  export declare function readCompiledSchemaFile(rootPath: string): WorkflowCompiledSchema | null;
@@ -1,16 +1,24 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
- import { readJsonFileWithSchema } from "./parse.js";
4
- import { BUILTIN_COMPILED_ZONE_IDS, listBuiltinCompiledZoneSpecs, requiredCompiledZoneOwners, } from "./workflow-abi.js";
3
+ import { warnInterf } from "./logger.js";
4
+ import { readJsonFileUnchecked } from "./parse.js";
5
+ import { BUILTIN_COMPILED_ZONE_IDS, listBuiltinCompiledZoneSpecs, requiredCompiledZoneOwners, } from "./builtin-compiled-workflow.js";
5
6
  import { WorkflowCompiledSchemaSchema, } from "./schema.js";
6
- export { BUILTIN_COMPILED_ZONE_IDS } from "./workflow-abi.js";
7
- export const COMPILED_SCHEMA_FILE = "compiled.schema.json";
7
+ export { BUILTIN_COMPILED_ZONE_IDS } from "./builtin-compiled-workflow.js";
8
+ export const WORKFLOW_SCHEMA_FILE = "workflow.schema.json";
8
9
  const BUILTIN_COMPILED_ZONE_SPEC_BY_ID = new Map(listBuiltinCompiledZoneSpecs().map((zone) => [zone.id, zone]));
9
- export function compiledSchemaFilePath(rootPath) {
10
- return join(rootPath, COMPILED_SCHEMA_FILE);
10
+ export function workflowSchemaFilePath(rootPath) {
11
+ return join(rootPath, WORKFLOW_SCHEMA_FILE);
11
12
  }
12
- export function compiledSchemaRelativePath() {
13
- return `workflow/${COMPILED_SCHEMA_FILE}`;
13
+ export function resolveWorkflowSchemaPath(rootPath) {
14
+ const path = workflowSchemaFilePath(rootPath);
15
+ return existsSync(path) ? path : null;
16
+ }
17
+ export function workflowSchemaExists(rootPath) {
18
+ return existsSync(workflowSchemaFilePath(rootPath));
19
+ }
20
+ export function workflowSchemaRelativePath() {
21
+ return `workflow/${WORKFLOW_SCHEMA_FILE}`;
14
22
  }
15
23
  export function listCompiledSchemaZones(schema) {
16
24
  return [...schema.zones];
@@ -77,11 +85,18 @@ function pushZone(zones, zone) {
77
85
  return;
78
86
  zones.push(zone);
79
87
  }
80
- export function buildCompiledSchema(stages, label = "Compiled dataset schema") {
88
+ function normalizeWorkflowSchema(schema) {
89
+ return {
90
+ ...schema,
91
+ kind: "workflow-schema",
92
+ };
93
+ }
94
+ export function buildWorkflowSchema(stages, label = "Workflow schema") {
81
95
  const zones = [];
82
96
  for (const zone of listBuiltinCompiledZoneSpecs()) {
83
97
  pushZone(zones, {
84
98
  id: zone.id,
99
+ role: zone.role,
85
100
  path: zone.path,
86
101
  kind: zone.kind,
87
102
  required: zone.required,
@@ -90,21 +105,37 @@ export function buildCompiledSchema(stages, label = "Compiled dataset schema") {
90
105
  });
91
106
  }
92
107
  return {
93
- kind: "compiled-schema",
108
+ kind: "workflow-schema",
94
109
  version: 1,
95
110
  target_type: "compiled",
96
111
  label,
97
112
  zones,
98
113
  };
99
114
  }
100
- export function writeCompiledSchemaFile(rootPath, stages, label) {
101
- const schema = buildCompiledSchema(stages, label);
102
- writeFileSync(compiledSchemaFilePath(rootPath), `${JSON.stringify(schema, null, 2)}\n`);
115
+ export function writeWorkflowSchemaFile(rootPath, stages, label) {
116
+ const schema = buildWorkflowSchema(stages, label);
117
+ writeWorkflowSchemaDocument(rootPath, schema);
103
118
  return schema;
104
119
  }
105
- export function readCompiledSchemaFile(rootPath) {
106
- const path = compiledSchemaFilePath(rootPath);
120
+ export function writeWorkflowSchemaDocument(rootPath, schema) {
121
+ const normalized = normalizeWorkflowSchema(schema);
122
+ writeFileSync(workflowSchemaFilePath(rootPath), `${JSON.stringify(normalized, null, 2)}\n`);
123
+ return normalized;
124
+ }
125
+ export function readWorkflowSchemaFile(rootPath) {
126
+ const path = workflowSchemaFilePath(rootPath);
107
127
  if (!existsSync(path))
108
128
  return null;
109
- return readJsonFileWithSchema(path, "compiled schema", WorkflowCompiledSchemaSchema);
129
+ const raw = readJsonFileUnchecked(path, "workflow schema");
130
+ if (raw === null)
131
+ return null;
132
+ const parsed = WorkflowCompiledSchemaSchema.safeParse(raw);
133
+ if (!parsed.success) {
134
+ warnInterf(`Warning: failed to validate workflow schema at ${path}: ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
135
+ return null;
136
+ }
137
+ return normalizeWorkflowSchema(parsed.data);
138
+ }
139
+ export function readCompiledSchemaFile(rootPath) {
140
+ return readWorkflowSchemaFile(rootPath);
110
141
  }
@@ -4,4 +4,4 @@ export interface DiscoveryResult {
4
4
  ignoredCount: number;
5
5
  }
6
6
  export declare function discoverSourceFiles(sourcePath: string, compiledPath: string): DiscoveryResult;
7
- export declare function loadIgnorePatterns(knowledgeBasePath: string): string[];
7
+ export declare function loadIgnorePatterns(compiledPath: string): string[];
@@ -36,8 +36,8 @@ export function discoverSourceFiles(sourcePath, compiledPath) {
36
36
  ignoredCount,
37
37
  };
38
38
  }
39
- export function loadIgnorePatterns(knowledgeBasePath) {
40
- const ignorePath = join(knowledgeBasePath, ".interfignore");
39
+ export function loadIgnorePatterns(compiledPath) {
40
+ const ignorePath = join(compiledPath, ".interfignore");
41
41
  if (!existsSync(ignorePath))
42
42
  return [];
43
43
  return readFileSync(ignorePath, "utf-8")
@@ -18,7 +18,7 @@ export interface WorkflowExecutor {
18
18
  displayName: string;
19
19
  command?: string | null;
20
20
  executionProfile?: WorkflowExecutionProfile;
21
- execute(knowledgeBasePath: string, prompt: string, options?: WorkflowExecuteOptions): Promise<number>;
21
+ execute(rootPath: string, prompt: string, options?: WorkflowExecuteOptions): Promise<number>;
22
22
  }
23
23
  export type { RuntimeExecutorInfo } from "./schema.js";
24
24
  export declare function buildRuntimeExecutorInfo(executor: WorkflowExecutor): RuntimeExecutorInfo;
@@ -18,8 +18,8 @@ export function createLocalAgentExecutor(agent, executionProfile = {}) {
18
18
  displayName: agent.displayName,
19
19
  command: agent.command,
20
20
  executionProfile,
21
- execute(knowledgeBasePath, prompt, options) {
22
- return spawnAgent(agent, knowledgeBasePath, prompt, {
21
+ execute(rootPath, prompt, options) {
22
+ return spawnAgent(agent, rootPath, prompt, {
23
23
  eventLogPath: options?.eventLogPath,
24
24
  statusLogPath: options?.statusLogPath,
25
25
  executionProfile,
@@ -10,7 +10,6 @@ export declare const WORKFLOW_CONTAINER_NAME = "workflows";
10
10
  export declare const TEST_CONTAINER_NAME = "tests";
11
11
  export declare const INTERF_CONFIG_FILE = "interf.json";
12
12
  export declare const WORKFLOW_PACKAGE_DIR = "workflow";
13
- export declare function prepareCompiledLayout(dirPath: string): boolean;
14
13
  export declare function readInterfConfig(dirPath: string): InterfConfig | null;
15
14
  export declare function hasSourceFolderInput(config: InterfConfig | null | undefined): config is InterfConfig & {
16
15
  source: {
@@ -4,7 +4,6 @@ import { warnInterf } from "./logger.js";
4
4
  import { readJsonFileUnchecked } from "./parse.js";
5
5
  import { compiledCompiledPathForDataset, projectInterfRoot, } from "./project-paths.js";
6
6
  import { resolveSourceControlPathForCompiled, compiledInterfConfigPath, } from "./compiled-paths.js";
7
- import { normalizeLegacyCompiledLayout, compiledNeedsLegacyLayoutNormalization, } from "./compiled-layout.js";
8
7
  import { InterfConfigSchema, } from "./schema.js";
9
8
  import { assertPathWithinRoot } from "./util.js";
10
9
  export const INTERF_CONTAINER_NAME = "interf";
@@ -12,12 +11,6 @@ export const WORKFLOW_CONTAINER_NAME = "workflows";
12
11
  export const TEST_CONTAINER_NAME = "tests";
13
12
  export const INTERF_CONFIG_FILE = "interf.json";
14
13
  export const WORKFLOW_PACKAGE_DIR = "workflow";
15
- export function prepareCompiledLayout(dirPath) {
16
- if (!compiledNeedsLegacyLayoutNormalization(dirPath)) {
17
- return false;
18
- }
19
- return normalizeLegacyCompiledLayout(dirPath);
20
- }
21
14
  export function readInterfConfig(dirPath) {
22
15
  const configPath = compiledInterfConfigPath(dirPath);
23
16
  if (!existsSync(configPath))
@@ -41,7 +34,6 @@ export function hasSourceFolderInput(config) {
41
34
  return typeof config?.source?.path === "string" && config.source.path.length > 0;
42
35
  }
43
36
  export function detectInterf(cwd) {
44
- prepareCompiledLayout(cwd);
45
37
  const config = readInterfConfig(cwd);
46
38
  if (config)
47
39
  return { path: cwd, config };
@@ -58,7 +50,6 @@ export function resolveCompiled(cwd) {
58
50
  };
59
51
  }
60
52
  export function resolveSourceFolderPath(compiledPath, config = null) {
61
- prepareCompiledLayout(compiledPath);
62
53
  const resolvedConfig = config ?? readInterfConfig(compiledPath);
63
54
  if (hasSourceFolderInput(resolvedConfig)) {
64
55
  return assertPathWithinRoot(compiledPath, resolve(compiledPath, resolvedConfig.source.path), "Compiled raw source path");
@@ -66,17 +57,15 @@ export function resolveSourceFolderPath(compiledPath, config = null) {
66
57
  return resolve(compiledPath, "raw");
67
58
  }
68
59
  export function resolveSourceControlPath(compiledPath) {
69
- prepareCompiledLayout(compiledPath);
70
60
  return resolveSourceControlPathForCompiled(compiledPath);
71
61
  }
72
62
  export function resolveSourceInputPath(compiledPath) {
73
- prepareCompiledLayout(compiledPath);
74
- const projectPath = resolveSourceControlPathForCompiled(compiledPath);
75
63
  const config = readInterfConfig(compiledPath);
76
64
  if (typeof config?.source?.dataset_path === "string" && config.source.dataset_path.length > 0) {
65
+ const projectPath = resolveSourceControlPathForCompiled(compiledPath);
77
66
  return assertPathWithinRoot(projectPath, resolve(compiledPath, config.source.dataset_path), "Dataset source path");
78
67
  }
79
- return projectPath;
68
+ throw new Error(`Compiled dataset is missing source.dataset_path in ${compiledInterfConfigPath(compiledPath)}.`);
80
69
  }
81
70
  export function listCompiledDatasetsForSourceFolder(sourcePath) {
82
71
  const interfRoot = projectInterfRoot(sourcePath);
@@ -91,11 +80,12 @@ export function listCompiledDatasetsForSourceFolder(sourcePath) {
91
80
  return [];
92
81
  }
93
82
  return readdirSync(interfRoot)
94
- .filter((entry) => !entry.startsWith(".") && entry !== WORKFLOW_CONTAINER_NAME)
83
+ .filter((entry) => !entry.startsWith(".") &&
84
+ entry !== WORKFLOW_CONTAINER_NAME &&
85
+ entry !== TEST_CONTAINER_NAME)
95
86
  .map((entry) => compiledCompiledPathForDataset(sourcePath, entry))
96
87
  .filter((compiledPath) => existsSync(compiledPath))
97
88
  .map((compiledPath) => {
98
- prepareCompiledLayout(compiledPath);
99
89
  const config = readInterfConfig(compiledPath);
100
90
  return config ? { path: compiledPath, config } : null;
101
91
  })
@@ -112,7 +102,7 @@ export function assertCompiledContainer(sourcePath) {
112
102
  if (entry.startsWith("."))
113
103
  return false;
114
104
  const entryPath = join(interfRoot, entry);
115
- if (entry === WORKFLOW_CONTAINER_NAME) {
105
+ if (entry === WORKFLOW_CONTAINER_NAME || entry === TEST_CONTAINER_NAME) {
116
106
  try {
117
107
  return !statSync(entryPath).isDirectory();
118
108
  }
@@ -146,7 +136,7 @@ export function assertCompiledContainer(sourcePath) {
146
136
  const unexpectedEntries = readdirSync(containerPath).filter((entry) => {
147
137
  if (entry.startsWith("."))
148
138
  return false;
149
- if (entry === WORKFLOW_CONTAINER_NAME)
139
+ if (entry === WORKFLOW_CONTAINER_NAME || entry === TEST_CONTAINER_NAME)
150
140
  return false;
151
141
  const entryPath = join(containerPath, entry);
152
142
  try {
@@ -161,7 +151,6 @@ export function assertCompiledContainer(sourcePath) {
161
151
  if (!existsSync(compiledPath)) {
162
152
  return false;
163
153
  }
164
- prepareCompiledLayout(compiledPath);
165
154
  return !readInterfConfig(compiledPath);
166
155
  });
167
156
  if (unexpectedEntries.length > 0) {
@@ -1,9 +1,7 @@
1
1
  import { mkdirSync, existsSync, writeFileSync, } from "node:fs";
2
2
  import { basename, join, relative, sep } from "node:path";
3
3
  import { getCompiledWorkflow } from "./workflow-definitions.js";
4
- import { refreshCompiledArtifacts, saveState, initCompiledState, } from "./state.js";
5
- import { saveEmptyCompiledInventory } from "./state-io.js";
6
- import { writeObsidianDefaults } from "./obsidian.js";
4
+ import { initializeCompiledRuntimeState, } from "./state.js";
7
5
  import { assertCompiledContainer, assertWritableTargetDir, assertCompiledName, } from "./interf-detect.js";
8
6
  import { refreshCompiledBootstrapGuidance } from "./interf-bootstrap.js";
9
7
  import { seedCompiledWorkflowPackage } from "./interf-workflow-package.js";
@@ -20,7 +18,6 @@ const DEFAULT_INTERFIGNORE = [
20
18
  ".interf/tests/",
21
19
  ".interf/tests/targets/sandboxes/",
22
20
  ".interf/runtime/",
23
- ".obsidian/",
24
21
  "",
25
22
  ].join("\n");
26
23
  const UNCOMPILED_COMPILED_PLACEHOLDER = "Not yet compiled. Run `interf compile` to build the compiled dataset.";
@@ -47,17 +44,16 @@ function compiledGitignoreEntries(compiledPath) {
47
44
  ".interf/tests/",
48
45
  ".interf/tests/targets/sandboxes/",
49
46
  ".interf/runtime/",
50
- ".obsidian/",
51
47
  ];
52
48
  }
53
49
  function scaffoldCompiledOutputs(compiledPath, compiledName, about) {
54
50
  const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
55
51
  if (!schema) {
56
- throw new Error(`Missing compiled schema at ${workflowPackagePathForCompiled(compiledPath)}.`);
52
+ throw new Error(`Missing workflow schema at ${workflowPackagePathForCompiled(compiledPath)}.`);
57
53
  }
58
54
  ensureCompiledZoneTargets(compiledPath, schema);
59
55
  for (const zone of schema.zones) {
60
- if (!zone.required || zone.kind !== "file" || zone.id === "raw")
56
+ if (!zone.required || zone.kind !== "file" || zone.role !== "output")
61
57
  continue;
62
58
  const targetPath = join(compiledPath, zone.path);
63
59
  if (existsSync(targetPath))
@@ -110,10 +106,7 @@ export function createCompiled(name, sourcePath, workflowId = "interf", about, d
110
106
  scaffoldCompiledOutputs(compiledPath, name, about);
111
107
  refreshCompiledBootstrapGuidance(compiledPath);
112
108
  writeFileSync(join(compiledPath, ".gitignore"), [...compiledGitignoreEntries(compiledPath), ""].join("\n"));
113
- saveState(compiledPath, initCompiledState());
114
- saveEmptyCompiledInventory(compiledPath);
115
- refreshCompiledArtifacts(compiledPath, { ensureViewSpec: true });
116
- writeObsidianDefaults(compiledPath, "compiled");
109
+ initializeCompiledRuntimeState(compiledPath);
117
110
  return compiledPath;
118
111
  }
119
112
  export function defaultCompiledNameForSource(sourcePath) {
@@ -14,7 +14,12 @@ export declare function createLocalWorkflowPackageFromTemplate(options: {
14
14
  workflowId: string;
15
15
  label: string;
16
16
  hint: string;
17
- summarizeBias: string;
18
- structureBias: string;
19
- shapeBias: string;
17
+ stagePolicyNotes: Record<string, string[]>;
18
+ }): string;
19
+ export declare function seedLocalWorkflowPackageFromBase(options: {
20
+ sourcePath: string;
21
+ baseWorkflowId: string;
22
+ workflowId: string;
23
+ label: string;
24
+ hint: string;
20
25
  }): string;