@interf/compiler 0.4.0 → 0.5.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 (160) hide show
  1. package/README.md +71 -69
  2. package/builtin-workflows/interf/README.md +6 -6
  3. package/builtin-workflows/interf/compile/stages/shape/SKILL.md +7 -7
  4. package/builtin-workflows/interf/compile/stages/structure/SKILL.md +2 -2
  5. package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +1 -1
  6. package/builtin-workflows/interf/{workspace.schema.json → compiled.schema.json} +5 -5
  7. package/builtin-workflows/interf/improve/SKILL.md +3 -3
  8. package/builtin-workflows/interf/use/query/SKILL.md +2 -2
  9. package/builtin-workflows/interf/workflow.json +42 -31
  10. package/dist/commands/check-draft.d.ts +19 -0
  11. package/dist/commands/check-draft.js +110 -0
  12. package/dist/commands/compile-controller.d.ts +4 -4
  13. package/dist/commands/compile-controller.js +117 -81
  14. package/dist/commands/compile.d.ts +5 -5
  15. package/dist/commands/compile.js +61 -62
  16. package/dist/commands/compiled-flow.d.ts +23 -0
  17. package/dist/commands/compiled-flow.js +112 -0
  18. package/dist/commands/create-workflow-wizard.d.ts +3 -3
  19. package/dist/commands/create-workflow-wizard.js +11 -11
  20. package/dist/commands/create.d.ts +2 -2
  21. package/dist/commands/create.js +50 -57
  22. package/dist/commands/default.js +2 -2
  23. package/dist/commands/executor-flow.d.ts +20 -1
  24. package/dist/commands/executor-flow.js +67 -7
  25. package/dist/commands/init.js +242 -289
  26. package/dist/commands/list.js +14 -10
  27. package/dist/commands/reset.js +6 -6
  28. package/dist/commands/source-config-wizard.d.ts +12 -8
  29. package/dist/commands/source-config-wizard.js +356 -119
  30. package/dist/commands/status.js +49 -26
  31. package/dist/commands/test-flow.d.ts +23 -10
  32. package/dist/commands/test-flow.js +278 -58
  33. package/dist/commands/test.d.ts +7 -1
  34. package/dist/commands/test.js +264 -65
  35. package/dist/commands/verify.js +23 -14
  36. package/dist/index.d.ts +7 -7
  37. package/dist/index.js +4 -4
  38. package/dist/lib/agent-args.js +2 -1
  39. package/dist/lib/agent-constants.js +1 -1
  40. package/dist/lib/agent-render.js +4 -4
  41. package/dist/lib/agent-shells.d.ts +8 -8
  42. package/dist/lib/agent-shells.js +231 -142
  43. package/dist/lib/compiled-compile.d.ts +52 -0
  44. package/dist/lib/compiled-compile.js +274 -0
  45. package/dist/lib/compiled-home.d.ts +5 -0
  46. package/dist/lib/compiled-home.js +32 -0
  47. package/dist/lib/compiled-layout.d.ts +2 -0
  48. package/dist/lib/compiled-layout.js +60 -0
  49. package/dist/lib/compiled-paths.d.ts +41 -0
  50. package/dist/lib/compiled-paths.js +111 -0
  51. package/dist/lib/{workspace-raw.d.ts → compiled-raw.d.ts} +8 -7
  52. package/dist/lib/{workspace-raw.js → compiled-raw.js} +16 -14
  53. package/dist/lib/compiled-reset.d.ts +1 -0
  54. package/dist/lib/compiled-reset.js +44 -0
  55. package/dist/lib/compiled-schema.d.ts +27 -0
  56. package/dist/lib/compiled-schema.js +110 -0
  57. package/dist/lib/config.d.ts +0 -1
  58. package/dist/lib/config.js +0 -1
  59. package/dist/lib/discovery.d.ts +1 -1
  60. package/dist/lib/discovery.js +3 -3
  61. package/dist/lib/interf-bootstrap.d.ts +1 -1
  62. package/dist/lib/interf-bootstrap.js +4 -4
  63. package/dist/lib/interf-detect.d.ts +10 -10
  64. package/dist/lib/interf-detect.js +78 -56
  65. package/dist/lib/interf-scaffold.d.ts +2 -2
  66. package/dist/lib/interf-scaffold.js +90 -57
  67. package/dist/lib/interf-workflow-package.d.ts +3 -3
  68. package/dist/lib/interf-workflow-package.js +30 -30
  69. package/dist/lib/interf.d.ts +5 -5
  70. package/dist/lib/interf.js +4 -4
  71. package/dist/lib/local-workflows.d.ts +4 -4
  72. package/dist/lib/local-workflows.js +35 -70
  73. package/dist/lib/obsidian.d.ts +1 -1
  74. package/dist/lib/parse.js +92 -1
  75. package/dist/lib/project-paths.d.ts +13 -0
  76. package/dist/lib/project-paths.js +29 -0
  77. package/dist/lib/runtime-acceptance.d.ts +7 -1
  78. package/dist/lib/runtime-acceptance.js +194 -59
  79. package/dist/lib/runtime-contracts.d.ts +2 -4
  80. package/dist/lib/runtime-contracts.js +17 -161
  81. package/dist/lib/runtime-inventory.d.ts +7 -0
  82. package/dist/lib/runtime-inventory.js +29 -0
  83. package/dist/lib/runtime-paths.js +5 -5
  84. package/dist/lib/runtime-prompt.js +9 -6
  85. package/dist/lib/runtime-reconcile.d.ts +2 -3
  86. package/dist/lib/runtime-reconcile.js +92 -171
  87. package/dist/lib/runtime-runs.js +30 -39
  88. package/dist/lib/runtime-types.d.ts +10 -19
  89. package/dist/lib/runtime.d.ts +2 -2
  90. package/dist/lib/runtime.js +1 -1
  91. package/dist/lib/schema.d.ts +163 -140
  92. package/dist/lib/schema.js +163 -124
  93. package/dist/lib/source-config.d.ts +24 -20
  94. package/dist/lib/source-config.js +154 -116
  95. package/dist/lib/state-artifacts.d.ts +5 -5
  96. package/dist/lib/state-artifacts.js +8 -8
  97. package/dist/lib/state-health.d.ts +4 -4
  98. package/dist/lib/state-health.js +108 -126
  99. package/dist/lib/state-io.d.ts +8 -8
  100. package/dist/lib/state-io.js +77 -50
  101. package/dist/lib/state-paths.js +5 -5
  102. package/dist/lib/state-view.d.ts +4 -4
  103. package/dist/lib/state-view.js +52 -55
  104. package/dist/lib/state.d.ts +5 -5
  105. package/dist/lib/state.js +4 -4
  106. package/dist/lib/summarize-plan.d.ts +3 -2
  107. package/dist/lib/summarize-plan.js +18 -16
  108. package/dist/lib/test-execution.js +9 -9
  109. package/dist/lib/test-matrices.d.ts +3 -3
  110. package/dist/lib/test-matrices.js +6 -6
  111. package/dist/lib/test-paths.d.ts +4 -4
  112. package/dist/lib/test-paths.js +16 -10
  113. package/dist/lib/test-sandbox.d.ts +1 -1
  114. package/dist/lib/test-sandbox.js +38 -31
  115. package/dist/lib/test-targets.d.ts +2 -2
  116. package/dist/lib/test-targets.js +11 -11
  117. package/dist/lib/test-types.d.ts +1 -1
  118. package/dist/lib/test.d.ts +1 -1
  119. package/dist/lib/test.js +1 -1
  120. package/dist/lib/util.d.ts +2 -0
  121. package/dist/lib/util.js +14 -1
  122. package/dist/lib/validate-compiled.d.ts +27 -0
  123. package/dist/lib/validate-compiled.js +236 -0
  124. package/dist/lib/validate-helpers.d.ts +0 -8
  125. package/dist/lib/validate-helpers.js +0 -30
  126. package/dist/lib/validate.d.ts +4 -4
  127. package/dist/lib/validate.js +49 -15
  128. package/dist/lib/workflow-abi.d.ts +37 -46
  129. package/dist/lib/workflow-abi.js +51 -76
  130. package/dist/lib/workflow-definitions.d.ts +11 -11
  131. package/dist/lib/workflow-definitions.js +36 -53
  132. package/dist/lib/workflow-helpers.d.ts +2 -3
  133. package/dist/lib/workflow-helpers.js +9 -13
  134. package/dist/lib/workflow-improvement.d.ts +3 -3
  135. package/dist/lib/workflow-improvement.js +48 -48
  136. package/dist/lib/workflow-review-paths.d.ts +3 -3
  137. package/dist/lib/workflow-review-paths.js +11 -11
  138. package/dist/lib/workflow-stage-runner.d.ts +1 -1
  139. package/dist/lib/workflow-stage-runner.js +8 -8
  140. package/dist/lib/workflows.d.ts +9 -9
  141. package/dist/lib/workflows.js +15 -17
  142. package/package.json +10 -9
  143. package/dist/commands/workspace-flow.d.ts +0 -23
  144. package/dist/commands/workspace-flow.js +0 -109
  145. package/dist/lib/registry.d.ts +0 -16
  146. package/dist/lib/registry.js +0 -65
  147. package/dist/lib/validate-workspace.d.ts +0 -121
  148. package/dist/lib/validate-workspace.js +0 -407
  149. package/dist/lib/workspace-compile.d.ts +0 -54
  150. package/dist/lib/workspace-compile.js +0 -476
  151. package/dist/lib/workspace-home.d.ts +0 -5
  152. package/dist/lib/workspace-home.js +0 -32
  153. package/dist/lib/workspace-layout.d.ts +0 -2
  154. package/dist/lib/workspace-layout.js +0 -60
  155. package/dist/lib/workspace-paths.d.ts +0 -41
  156. package/dist/lib/workspace-paths.js +0 -107
  157. package/dist/lib/workspace-reset.d.ts +0 -1
  158. package/dist/lib/workspace-reset.js +0 -43
  159. package/dist/lib/workspace-schema.d.ts +0 -17
  160. package/dist/lib/workspace-schema.js +0 -74
@@ -0,0 +1,52 @@
1
+ import { type WorkflowExecutor } from "./executors.js";
2
+ import { type CompiledWorkflowId, type WorkflowStageDefinition } from "./workflow-definitions.js";
3
+ import { type WorkflowReporter, type WorkflowStageResult } from "./workflow-helpers.js";
4
+ export interface CompiledStageExecutionDefinition extends WorkflowStageDefinition {
5
+ }
6
+ export interface CompiledSummarizeResult extends WorkflowStageResult {
7
+ skipped: boolean;
8
+ plan: {
9
+ sourceCount: number;
10
+ summaryCount: number;
11
+ targetCount: number;
12
+ };
13
+ }
14
+ export interface CompiledCompileResult {
15
+ ok: boolean;
16
+ stageResults: Record<string, WorkflowStageResult>;
17
+ failedStage: string | null;
18
+ summarize: CompiledSummarizeResult | null;
19
+ structure: WorkflowStageResult | null;
20
+ shape: WorkflowStageResult | null;
21
+ compile: WorkflowStageResult | null;
22
+ }
23
+ export type StageShellRetentionMode = "on-failure" | "always";
24
+ export declare function resolveCompiledContext(compiledPath: string): {
25
+ compiledName: string;
26
+ sourcePath: string;
27
+ controlPath: string;
28
+ workflowId: CompiledWorkflowId;
29
+ };
30
+ export declare function compiledExecutionStages(workflowId: CompiledWorkflowId, compiledPath: string): CompiledStageExecutionDefinition[];
31
+ export declare function runCompiledSummarize(options: {
32
+ executor: WorkflowExecutor;
33
+ compiledPath: string;
34
+ reporter?: WorkflowReporter;
35
+ reportSummary?: boolean;
36
+ reportStep?: boolean;
37
+ stageDefinition?: CompiledStageExecutionDefinition;
38
+ fullPass?: boolean;
39
+ }): Promise<CompiledSummarizeResult>;
40
+ export declare function runCompiledCompile(options: {
41
+ executor: WorkflowExecutor;
42
+ compiledPath: string;
43
+ reporter?: WorkflowReporter;
44
+ reportStep?: boolean;
45
+ preserveStageShells?: StageShellRetentionMode;
46
+ }): Promise<WorkflowStageResult>;
47
+ export declare function compileCompiled(options: {
48
+ executor: WorkflowExecutor;
49
+ compiledPath: string;
50
+ reporter?: WorkflowReporter;
51
+ preserveStageShells?: StageShellRetentionMode;
52
+ }): Promise<CompiledCompileResult>;
@@ -0,0 +1,274 @@
1
+ import { join } from "node:path";
2
+ import { createStageExecutionShell, freezeStageExecutionShell, pruneStageExecutionShells, syncStageExecutionShellWrites, } from "./agent-shells.js";
3
+ import { readInterfConfig, refreshCompiledBootstrapGuidance, resolveSourceFolderPath, resolveSourceControlPath, resolveSourceInputPath, } from "./interf.js";
4
+ import { reconcileCompiledStageRun, } from "./runtime-reconcile.js";
5
+ import { refreshCompiledArtifacts, } from "./state.js";
6
+ import { buildRuntimeStageContract, } from "./runtime.js";
7
+ import { validateWorkflowPackage } from "./local-workflows.js";
8
+ import { formatActiveCompiledWorkflowStageStep, getActiveCompiledStagePolicyNotes, getActiveCompiledWorkflow, resolveCompiledWorkflowFromConfig, resolveActiveCompiledStageAcceptance, } from "./workflow-definitions.js";
9
+ import { validateCompiledStage, validateCompiledWorkflow, } from "./validate.js";
10
+ import { buildLocalSkillContractExtension, buildStageInstructions, reportBlankLine, reportLine, reportValidationFailure, workflowCompileStageDirectory, } from "./workflow-helpers.js";
11
+ import { executeValidatedStage, } from "./workflow-stage-runner.js";
12
+ import { syncCompiledRawSnapshot } from "./compiled-raw.js";
13
+ import { workflowPackagePathForCompiled, } from "./compiled-paths.js";
14
+ import { compiledContractArtifactPathsForZoneIds, findCompiledSchemaZone, readCompiledSchemaFile, } from "./compiled-schema.js";
15
+ import { discoverSourceFiles } from "./discovery.js";
16
+ import { listFilesRecursive } from "./filesystem.js";
17
+ export function resolveCompiledContext(compiledPath) {
18
+ const config = readInterfConfig(compiledPath);
19
+ const workflowId = resolveCompiledWorkflowFromConfig(config);
20
+ return {
21
+ compiledName: config?.name ?? "compiled",
22
+ sourcePath: resolveSourceFolderPath(compiledPath, config),
23
+ controlPath: resolveSourceControlPath(compiledPath),
24
+ workflowId,
25
+ };
26
+ }
27
+ export function compiledExecutionStages(workflowId, compiledPath) {
28
+ return getActiveCompiledWorkflow(compiledPath, workflowId)
29
+ .stages;
30
+ }
31
+ function zoneArtifactCount(compiledPath, zonePath, kind) {
32
+ const absolutePath = join(compiledPath, zonePath);
33
+ try {
34
+ if (kind === "file") {
35
+ return listFilesRecursive(absolutePath).length > 0 ? 1 : 0;
36
+ }
37
+ }
38
+ catch {
39
+ if (kind === "file")
40
+ return 0;
41
+ }
42
+ return listFilesRecursive(absolutePath).length;
43
+ }
44
+ function resolveStageContractArtifacts(compiledPath, stageDefinition) {
45
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
46
+ if (!schema) {
47
+ throw new Error(`Missing compiled schema for stage "${stageDefinition.id}" at ${workflowPackagePathForCompiled(compiledPath)}.`);
48
+ }
49
+ return {
50
+ reads: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.reads),
51
+ writes: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.writes),
52
+ };
53
+ }
54
+ function buildStageCounts(compiledPath, stageDefinition) {
55
+ const context = resolveCompiledContext(compiledPath);
56
+ const sourceTotal = discoverSourceFiles(context.sourcePath, compiledPath).totalCount;
57
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
58
+ const zoneCounts = {};
59
+ if (schema) {
60
+ for (const zoneId of new Set([...stageDefinition.reads, ...stageDefinition.writes])) {
61
+ const zone = findCompiledSchemaZone(schema, zoneId);
62
+ if (!zone)
63
+ continue;
64
+ zoneCounts[zoneId] = zoneArtifactCount(compiledPath, zone.path, zone.kind);
65
+ }
66
+ }
67
+ return {
68
+ source_total: sourceTotal,
69
+ read_zone_total: stageDefinition.reads.length,
70
+ write_zone_total: stageDefinition.writes.length,
71
+ ...zoneCounts,
72
+ };
73
+ }
74
+ function buildStageContract(compiledPath, workflowId, stageDefinition) {
75
+ const config = readInterfConfig(compiledPath);
76
+ const localSkills = buildLocalSkillContractExtension(compiledPath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use them to refine this workflow stage while still honoring the declared reads, writes, and proof rules.");
77
+ const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
78
+ const stageArtifacts = resolveStageContractArtifacts(compiledPath, stageDefinition);
79
+ return buildRuntimeStageContract({
80
+ compiledName: config?.name ?? "compiled",
81
+ stageId: stageDefinition.id,
82
+ stageLabel: stageDefinition.label,
83
+ counts: buildStageCounts(compiledPath, stageDefinition),
84
+ stageReadArtifacts: stageArtifacts.reads,
85
+ stageWriteArtifacts: stageArtifacts.writes,
86
+ workflowNotes: getActiveCompiledStagePolicyNotes(compiledPath, workflowId, stageDefinition.id),
87
+ localSkillDocs: localSkills.reads,
88
+ instructions,
89
+ acceptance: resolveActiveCompiledStageAcceptance(compiledPath, workflowId, stageDefinition.id),
90
+ });
91
+ }
92
+ async function runCompiledStage(options) {
93
+ const context = resolveCompiledContext(options.compiledPath);
94
+ const stageDefinition = options.stageDefinition;
95
+ const contract = buildStageContract(options.compiledPath, context.workflowId, stageDefinition);
96
+ const localSkills = buildLocalSkillContractExtension(options.compiledPath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use them to refine this workflow stage while still honoring the declared reads, writes, and proof rules.");
97
+ const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
98
+ if (options.reportStep !== false) {
99
+ reportBlankLine(options.reporter);
100
+ reportLine(options.reporter, `${formatActiveCompiledWorkflowStageStep(options.compiledPath, context.workflowId, stageDefinition.id)} (${stageDefinition.description.toLowerCase()})`);
101
+ }
102
+ const shell = createStageExecutionShell(options.compiledPath, context.compiledName, context.workflowId, stageDefinition, contract.artifacts.writes);
103
+ try {
104
+ return await executeValidatedStage({
105
+ executor: options.executor,
106
+ compiledPath: options.compiledPath,
107
+ executionPath: shell.rootPath,
108
+ targetName: context.compiledName,
109
+ workflow: context.workflowId,
110
+ workflowSourcePath: options.compiledPath,
111
+ stageDefinition,
112
+ instructions,
113
+ summary: `Executing ${stageDefinition.label.toLowerCase()}.`,
114
+ contract,
115
+ statusLines: [
116
+ `Emit exactly one startup line: STATUS: loaded ${stageDefinition.label.toLowerCase()} stage.`,
117
+ "Emit STATUS: reading declared inputs after you confirm the shell contract and local docs.",
118
+ "Emit STATUS: writing declared outputs after the stage starts updating the compiled zones.",
119
+ `Emit DONE: ${stageDefinition.id} complete when the declared outputs and proof are on disk.`,
120
+ ],
121
+ reporter: options.reporter,
122
+ completionCheck: () => validateCompiledStage(options.compiledPath, stageDefinition.id).ok,
123
+ syncWrites: () => syncStageExecutionShellWrites(options.compiledPath, shell.rootPath, stageDefinition, contract.artifacts.writes),
124
+ reconcile: () => reconcileCompiledStageRun(options.compiledPath, stageDefinition),
125
+ refreshArtifacts: () => refreshCompiledArtifacts(options.compiledPath, { ensureViewSpec: true }),
126
+ validate: () => validateCompiledStage(options.compiledPath, stageDefinition.id),
127
+ });
128
+ }
129
+ finally {
130
+ freezeStageExecutionShell(shell.rootPath);
131
+ }
132
+ }
133
+ export async function runCompiledSummarize(options) {
134
+ const context = resolveCompiledContext(options.compiledPath);
135
+ const stageDefinition = options.stageDefinition
136
+ ?? compiledExecutionStages(context.workflowId, options.compiledPath).find((stage) => stage.id === "summarize");
137
+ if (!stageDefinition) {
138
+ return {
139
+ ok: false,
140
+ code: 1,
141
+ skipped: true,
142
+ plan: { sourceCount: 0, summaryCount: 0, targetCount: 0 },
143
+ summary: "Workflow does not declare a summarize stage.",
144
+ };
145
+ }
146
+ const sourceCount = discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount;
147
+ const result = await runCompiledStage({
148
+ executor: options.executor,
149
+ compiledPath: options.compiledPath,
150
+ reporter: options.reporter,
151
+ reportStep: options.reportStep,
152
+ stageDefinition,
153
+ });
154
+ return {
155
+ ...result,
156
+ skipped: false,
157
+ plan: {
158
+ sourceCount,
159
+ summaryCount: 0,
160
+ targetCount: sourceCount,
161
+ },
162
+ };
163
+ }
164
+ export async function runCompiledCompile(options) {
165
+ const preserveMode = options.preserveStageShells ?? "on-failure";
166
+ if (preserveMode !== "always") {
167
+ pruneStageExecutionShells(options.compiledPath);
168
+ }
169
+ let lastResult = { ok: true, code: 0 };
170
+ try {
171
+ const context = resolveCompiledContext(options.compiledPath);
172
+ for (const stageDefinition of compiledExecutionStages(context.workflowId, options.compiledPath)) {
173
+ const result = await runCompiledStage({
174
+ executor: options.executor,
175
+ compiledPath: options.compiledPath,
176
+ reporter: options.reporter,
177
+ reportStep: options.reportStep,
178
+ stageDefinition,
179
+ });
180
+ lastResult = result;
181
+ if (!result.ok)
182
+ return result;
183
+ }
184
+ return lastResult;
185
+ }
186
+ finally {
187
+ if (preserveMode !== "always" && lastResult.ok) {
188
+ pruneStageExecutionShells(options.compiledPath);
189
+ }
190
+ }
191
+ }
192
+ export async function compileCompiled(options) {
193
+ const preserveMode = options.preserveStageShells ?? "on-failure";
194
+ if (preserveMode !== "always") {
195
+ pruneStageExecutionShells(options.compiledPath);
196
+ }
197
+ let result = {
198
+ ok: true,
199
+ stageResults: {},
200
+ failedStage: null,
201
+ summarize: null,
202
+ structure: null,
203
+ shape: null,
204
+ compile: null,
205
+ };
206
+ try {
207
+ const sourceInputPath = resolveSourceInputPath(options.compiledPath);
208
+ syncCompiledRawSnapshot(options.compiledPath, sourceInputPath);
209
+ refreshCompiledBootstrapGuidance(options.compiledPath);
210
+ const workflowValidation = validateWorkflowPackage(join(options.compiledPath, ".interf", "workflow"));
211
+ if (!workflowValidation.ok) {
212
+ reportValidationFailure(options.reporter, workflowValidation.summary, workflowValidation.errors);
213
+ return {
214
+ ...result,
215
+ ok: false,
216
+ failedStage: "workflow",
217
+ compile: {
218
+ ok: false,
219
+ code: 1,
220
+ summary: workflowValidation.summary,
221
+ },
222
+ };
223
+ }
224
+ const context = resolveCompiledContext(options.compiledPath);
225
+ const stages = compiledExecutionStages(context.workflowId, options.compiledPath);
226
+ for (const stageDefinition of stages) {
227
+ const stageResult = await runCompiledStage({
228
+ executor: options.executor,
229
+ compiledPath: options.compiledPath,
230
+ reporter: options.reporter,
231
+ reportStep: true,
232
+ stageDefinition,
233
+ });
234
+ 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
+ if (!stageResult.ok) {
253
+ result.ok = false;
254
+ result.failedStage = stageDefinition.id;
255
+ result.compile = stageResult;
256
+ return result;
257
+ }
258
+ }
259
+ const workflowValidationResult = validateCompiledWorkflow(options.compiledPath);
260
+ result.ok = workflowValidationResult.ok;
261
+ result.failedStage = workflowValidationResult.ok ? null : workflowValidationResult.stage;
262
+ result.compile = {
263
+ ok: workflowValidationResult.ok,
264
+ code: workflowValidationResult.ok ? 0 : 1,
265
+ summary: workflowValidationResult.summary,
266
+ };
267
+ return result;
268
+ }
269
+ finally {
270
+ if (preserveMode !== "always" && result.ok) {
271
+ pruneStageExecutionShells(options.compiledPath);
272
+ }
273
+ }
274
+ }
@@ -0,0 +1,5 @@
1
+ export declare const UNCOMPILED_COMPILED_HOME_NOTICE = "Not yet compiled. Run `interf compile` to build the compiled dataset.";
2
+ export declare function renderUncompiledCompiledHome(compiledName: string, about?: string): string;
3
+ export declare function compiledHomeHasCompilePlaceholder(content: string): boolean;
4
+ export declare function readCompiledHomeContent(dirPath: string): string | null;
5
+ export declare function compiledHomeIsShaped(dirPath: string): boolean;
@@ -0,0 +1,32 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { compiledHomePath } from "./compiled-schema.js";
3
+ export const UNCOMPILED_COMPILED_HOME_NOTICE = "Not yet compiled. Run `interf compile` to build the compiled dataset.";
4
+ export function renderUncompiledCompiledHome(compiledName, about) {
5
+ return [
6
+ `# ${compiledName} — Home`,
7
+ "",
8
+ UNCOMPILED_COMPILED_HOME_NOTICE,
9
+ ...(about ? ["", `About: ${about}`] : []),
10
+ "",
11
+ ].join("\n");
12
+ }
13
+ export function compiledHomeHasCompilePlaceholder(content) {
14
+ return content.includes(UNCOMPILED_COMPILED_HOME_NOTICE);
15
+ }
16
+ export function readCompiledHomeContent(dirPath) {
17
+ const homePath = compiledHomePath(dirPath);
18
+ if (!existsSync(homePath))
19
+ return null;
20
+ try {
21
+ return readFileSync(homePath, "utf8");
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ export function compiledHomeIsShaped(dirPath) {
28
+ const content = readCompiledHomeContent(dirPath);
29
+ if (content === null)
30
+ return false;
31
+ return !compiledHomeHasCompilePlaceholder(content);
32
+ }
@@ -0,0 +1,2 @@
1
+ export declare function normalizeLegacyCompiledLayout(compiledPath: string): boolean;
2
+ export declare function compiledNeedsLegacyLayoutNormalization(compiledPath: string): boolean;
@@ -0,0 +1,60 @@
1
+ import { existsSync, mkdirSync, readdirSync, renameSync, } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { COMPILED_CONFIG_FILE, COMPILED_INTERF_DIR, COMPILED_RUNTIME_DIR, COMPILED_TEST_DIR, COMPILED_WORKFLOW_DIR, workflowPackagePathForCompiled, compiledInterfConfigPath, compiledInterfRoot, compiledRuntimeRoot, } from "./compiled-paths.js";
4
+ const LEGACY_COMPILED_CONFIG_FILE = "interf.json";
5
+ const LEGACY_WORKFLOW_DIR = "workflow";
6
+ function movePathIfMissing(sourcePath, targetPath) {
7
+ if (!existsSync(sourcePath)) {
8
+ return false;
9
+ }
10
+ if (existsSync(targetPath)) {
11
+ return false;
12
+ }
13
+ mkdirSync(dirname(targetPath), { recursive: true });
14
+ renameSync(sourcePath, targetPath);
15
+ return true;
16
+ }
17
+ export function normalizeLegacyCompiledLayout(compiledPath) {
18
+ const interfRoot = compiledInterfRoot(compiledPath);
19
+ const runtimeRoot = compiledRuntimeRoot(compiledPath);
20
+ let changed = false;
21
+ changed = movePathIfMissing(join(compiledPath, LEGACY_COMPILED_CONFIG_FILE), compiledInterfConfigPath(compiledPath)) || changed;
22
+ changed = movePathIfMissing(join(compiledPath, LEGACY_WORKFLOW_DIR), workflowPackagePathForCompiled(compiledPath)) || changed;
23
+ if (!existsSync(interfRoot)) {
24
+ return changed;
25
+ }
26
+ for (const entry of readdirSync(interfRoot)) {
27
+ if (entry === COMPILED_RUNTIME_DIR ||
28
+ entry === COMPILED_TEST_DIR ||
29
+ entry === COMPILED_WORKFLOW_DIR ||
30
+ entry === COMPILED_CONFIG_FILE) {
31
+ continue;
32
+ }
33
+ changed = movePathIfMissing(join(interfRoot, entry), join(runtimeRoot, entry)) || changed;
34
+ }
35
+ return changed;
36
+ }
37
+ export function compiledNeedsLegacyLayoutNormalization(compiledPath) {
38
+ if (existsSync(join(compiledPath, LEGACY_COMPILED_CONFIG_FILE)) &&
39
+ !existsSync(compiledInterfConfigPath(compiledPath))) {
40
+ return true;
41
+ }
42
+ if (!existsSync(join(compiledPath, COMPILED_INTERF_DIR)))
43
+ return false;
44
+ if (existsSync(join(compiledPath, LEGACY_WORKFLOW_DIR)) &&
45
+ !existsSync(workflowPackagePathForCompiled(compiledPath))) {
46
+ return true;
47
+ }
48
+ for (const entry of readdirSync(join(compiledPath, COMPILED_INTERF_DIR))) {
49
+ if (entry === COMPILED_RUNTIME_DIR ||
50
+ entry === COMPILED_TEST_DIR ||
51
+ entry === COMPILED_WORKFLOW_DIR ||
52
+ entry === COMPILED_CONFIG_FILE) {
53
+ continue;
54
+ }
55
+ if (!existsSync(join(compiledRuntimeRoot(compiledPath), entry))) {
56
+ return true;
57
+ }
58
+ }
59
+ return false;
60
+ }
@@ -0,0 +1,41 @@
1
+ export declare const COMPILED_INTERF_DIR = ".interf";
2
+ export declare const COMPILED_CONFIG_FILE = "interf.json";
3
+ export declare const COMPILED_WORKFLOW_DIR = "workflow";
4
+ export declare const COMPILED_TEST_DIR = "tests";
5
+ export declare const COMPILED_TEST_TARGETS_DIR = "targets";
6
+ export declare const COMPILED_RUNTIME_DIR = "runtime";
7
+ export declare const COMPILED_RUNTIME_STATE_FILE = "state.json";
8
+ export declare const COMPILED_RUNTIME_HEALTH_FILE = "health.json";
9
+ export declare const COMPILED_RUNTIME_VIEW_SPEC_FILE = "view-spec.json";
10
+ export declare const COMPILED_RUNTIME_RAW_SNAPSHOT_FILE = "raw-snapshot.json";
11
+ export declare const COMPILED_RUNTIME_INVENTORY_FILE = "inventory.json";
12
+ export declare const COMPILED_RUNTIME_RUN_FILE = "run.json";
13
+ export declare const COMPILED_RUNTIME_RUN_HISTORY_FILE = "run-history.jsonl";
14
+ export declare const COMPILED_RUNTIME_STAGE_CONTRACT_FILE = "stage-contract.json";
15
+ export declare function compiledRuntimeRoot(compiledPath: string): string;
16
+ export declare function compiledRuntimeFilePath(compiledPath: string, fileName: string): string;
17
+ export declare function compiledInterfRoot(compiledPath: string): string;
18
+ export declare function compiledInterfConfigPath(compiledPath: string): string;
19
+ export declare function workflowPackagePathForCompiled(compiledPath: string): string;
20
+ export declare function testRootForCompiled(compiledPath: string): string;
21
+ export declare function testRunsRootForCompiled(compiledPath: string): string;
22
+ export declare function testTargetsRootForCompiled(compiledPath: string): string;
23
+ export declare function latestTestComparisonPathForCompiled(compiledPath: string): string;
24
+ export declare function stageExecutionShellsRoot(compiledPath: string): string;
25
+ export declare function workflowImprovementLoopsRoot(compiledPath: string): string;
26
+ export declare function workflowImprovementRunRoot(compiledPath: string, runId: string): string;
27
+ export declare function workflowImprovementLoopRoot(compiledPath: string, runId: string, loopIndex: number): string;
28
+ export declare function targetTestRunsRootForCompiled(compiledPath: string): string;
29
+ export declare function targetTestSandboxesRootForCompiled(compiledPath: string): string;
30
+ export declare function compiledRuntimeLogsRoot(compiledPath: string): string;
31
+ export declare function compiledQueryAcceptanceRoot(compiledPath: string): string;
32
+ export declare function compiledRuntimeStatePath(compiledPath: string): string;
33
+ export declare function compiledRuntimeHealthPath(compiledPath: string): string;
34
+ export declare function compiledRuntimeViewSpecPath(compiledPath: string): string;
35
+ export declare function compiledRawSnapshotMetadataPath(compiledPath: string): string;
36
+ export declare function compiledRuntimeInventoryPath(compiledPath: string): string;
37
+ export declare function compiledRuntimeRunPath(compiledPath: string): string;
38
+ export declare function compiledRuntimeRunHistoryPath(compiledPath: string): string;
39
+ export declare function compiledRuntimeStageContractPath(compiledPath: string): string;
40
+ export declare function resolveSourceControlPathForCompiled(compiledPath: string): string;
41
+ export declare function defaultControlPathForCompiled(compiledPath: string): string;
@@ -0,0 +1,111 @@
1
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
2
+ export const COMPILED_INTERF_DIR = ".interf";
3
+ export const COMPILED_CONFIG_FILE = "interf.json";
4
+ export const COMPILED_WORKFLOW_DIR = "workflow";
5
+ export const COMPILED_TEST_DIR = "tests";
6
+ export const COMPILED_TEST_TARGETS_DIR = "targets";
7
+ export const COMPILED_RUNTIME_DIR = "runtime";
8
+ export const COMPILED_RUNTIME_STATE_FILE = "state.json";
9
+ export const COMPILED_RUNTIME_HEALTH_FILE = "health.json";
10
+ export const COMPILED_RUNTIME_VIEW_SPEC_FILE = "view-spec.json";
11
+ export const COMPILED_RUNTIME_RAW_SNAPSHOT_FILE = "raw-snapshot.json";
12
+ export const COMPILED_RUNTIME_INVENTORY_FILE = "inventory.json";
13
+ export const COMPILED_RUNTIME_RUN_FILE = "run.json";
14
+ export const COMPILED_RUNTIME_RUN_HISTORY_FILE = "run-history.jsonl";
15
+ export const COMPILED_RUNTIME_STAGE_CONTRACT_FILE = "stage-contract.json";
16
+ export function compiledRuntimeRoot(compiledPath) {
17
+ return join(compiledPath, COMPILED_INTERF_DIR, COMPILED_RUNTIME_DIR);
18
+ }
19
+ export function compiledRuntimeFilePath(compiledPath, fileName) {
20
+ return join(compiledRuntimeRoot(compiledPath), fileName);
21
+ }
22
+ export function compiledInterfRoot(compiledPath) {
23
+ return join(compiledPath, COMPILED_INTERF_DIR);
24
+ }
25
+ export function compiledInterfConfigPath(compiledPath) {
26
+ return join(compiledInterfRoot(compiledPath), COMPILED_CONFIG_FILE);
27
+ }
28
+ export function workflowPackagePathForCompiled(compiledPath) {
29
+ return join(compiledInterfRoot(compiledPath), COMPILED_WORKFLOW_DIR);
30
+ }
31
+ export function testRootForCompiled(compiledPath) {
32
+ return join(compiledInterfRoot(compiledPath), COMPILED_TEST_DIR);
33
+ }
34
+ export function testRunsRootForCompiled(compiledPath) {
35
+ return join(testRootForCompiled(compiledPath), "runs");
36
+ }
37
+ export function testTargetsRootForCompiled(compiledPath) {
38
+ return join(testRootForCompiled(compiledPath), COMPILED_TEST_TARGETS_DIR);
39
+ }
40
+ export function latestTestComparisonPathForCompiled(compiledPath) {
41
+ return join(testRootForCompiled(compiledPath), "latest.json");
42
+ }
43
+ export function stageExecutionShellsRoot(compiledPath) {
44
+ return join(compiledRuntimeRoot(compiledPath), "execution-shells");
45
+ }
46
+ export function workflowImprovementLoopsRoot(compiledPath) {
47
+ return join(compiledRuntimeRoot(compiledPath), "improvement-loops");
48
+ }
49
+ export function workflowImprovementRunRoot(compiledPath, runId) {
50
+ return join(workflowImprovementLoopsRoot(compiledPath), runId);
51
+ }
52
+ export function workflowImprovementLoopRoot(compiledPath, runId, loopIndex) {
53
+ return join(workflowImprovementRunRoot(compiledPath, runId), `loop-${String(loopIndex).padStart(2, "0")}`);
54
+ }
55
+ export function targetTestRunsRootForCompiled(compiledPath) {
56
+ return join(testTargetsRootForCompiled(compiledPath), "runs");
57
+ }
58
+ export function targetTestSandboxesRootForCompiled(compiledPath) {
59
+ return join(testTargetsRootForCompiled(compiledPath), "sandboxes");
60
+ }
61
+ export function compiledRuntimeLogsRoot(compiledPath) {
62
+ return join(compiledRuntimeRoot(compiledPath), "logs");
63
+ }
64
+ export function compiledQueryAcceptanceRoot(compiledPath) {
65
+ return join(compiledRuntimeRoot(compiledPath), "query-acceptance");
66
+ }
67
+ export function compiledRuntimeStatePath(compiledPath) {
68
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_STATE_FILE);
69
+ }
70
+ export function compiledRuntimeHealthPath(compiledPath) {
71
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_HEALTH_FILE);
72
+ }
73
+ export function compiledRuntimeViewSpecPath(compiledPath) {
74
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_VIEW_SPEC_FILE);
75
+ }
76
+ export function compiledRawSnapshotMetadataPath(compiledPath) {
77
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RAW_SNAPSHOT_FILE);
78
+ }
79
+ export function compiledRuntimeInventoryPath(compiledPath) {
80
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_INVENTORY_FILE);
81
+ }
82
+ export function compiledRuntimeRunPath(compiledPath) {
83
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RUN_FILE);
84
+ }
85
+ export function compiledRuntimeRunHistoryPath(compiledPath) {
86
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RUN_HISTORY_FILE);
87
+ }
88
+ export function compiledRuntimeStageContractPath(compiledPath) {
89
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_STAGE_CONTRACT_FILE);
90
+ }
91
+ export function resolveSourceControlPathForCompiled(compiledPath) {
92
+ let cursor = resolve(compiledPath);
93
+ 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
+ const parent = dirname(cursor);
102
+ if (parent === cursor)
103
+ break;
104
+ cursor = parent;
105
+ }
106
+ throw new Error(`Compiled dataset is not under the canonical project layout: ${compiledPath}`);
107
+ }
108
+ export function defaultControlPathForCompiled(compiledPath) {
109
+ const relativePath = relative(compiledPath, resolveSourceControlPathForCompiled(compiledPath));
110
+ return relativePath.length > 0 ? relativePath.split(sep).join("/") : ".";
111
+ }
@@ -1,13 +1,13 @@
1
1
  import type { InterfConfig } from "./schema.js";
2
- export interface WorkspaceRawSyncResult {
2
+ export interface CompiledRawSyncResult {
3
3
  sourceTotal: number;
4
4
  copied: number;
5
5
  removed: number;
6
6
  }
7
7
  type RawSnapshotMaterializeMode = "copy" | "link-or-copy";
8
- export declare function resolveWorkspaceRawPath(workspacePath: string, config?: {
8
+ export declare function resolveCompiledRawPath(compiledPath: string, config?: {
9
9
  [x: string]: unknown;
10
- type: "workspace";
10
+ type: "compiled";
11
11
  name: string;
12
12
  checks: {
13
13
  question: string;
@@ -25,6 +25,7 @@ export declare function resolveWorkspaceRawPath(workspacePath: string, config?:
25
25
  source: {
26
26
  path: string;
27
27
  control_path?: string | undefined;
28
+ dataset_path?: string | undefined;
28
29
  };
29
30
  about?: string | undefined;
30
31
  workflow?: string | undefined;
@@ -35,14 +36,14 @@ export declare function resolveWorkspaceRawPath(workspacePath: string, config?:
35
36
  local_draft?: boolean | undefined;
36
37
  } | undefined;
37
38
  } | null): string;
38
- export declare function syncWorkspaceRawSnapshot(workspacePath: string, sourcePath?: string): WorkspaceRawSyncResult;
39
- export declare function ensureWorkspaceRawBinding(workspacePath: string): InterfConfig | null;
39
+ export declare function syncCompiledRawSnapshot(compiledPath: string, sourcePath?: string): CompiledRawSyncResult;
40
+ export declare function ensureCompiledRawBinding(compiledPath: string): InterfConfig | null;
40
41
  export declare function projectRawSnapshot(options: {
41
42
  sourcePath: string;
42
43
  destinationPath: string;
43
- workspacePath: string;
44
+ compiledPath: string;
44
45
  mode?: RawSnapshotMaterializeMode;
45
46
  prune?: boolean;
46
47
  preserveTimestamps?: boolean;
47
- }): WorkspaceRawSyncResult;
48
+ }): CompiledRawSyncResult;
48
49
  export {};