@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
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync, statSync, writeFileSync, } from "node:fs";
2
- import { join, relative } from "node:path";
2
+ import { extname, join, relative } from "node:path";
3
3
  import { listFilesRecursive } from "./filesystem.js";
4
4
  import { compiledZoneAbsolutePath, findCompiledSchemaZone, readCompiledSchemaFile, } from "./compiled-schema.js";
5
5
  import { parseJsonFrontmatter } from "./parse.js";
@@ -7,7 +7,7 @@ import { loadRuntimeRun } from "./runtime.js";
7
7
  import { initCompiledState, loadState, refreshCompiledArtifacts, saveState, } from "./state.js";
8
8
  import { compiledInventoryFromEntries } from "./runtime-inventory.js";
9
9
  import { compiledRuntimeRoot } from "./compiled-paths.js";
10
- import { isOutputMarkdownFile } from "./validate.js";
10
+ import { extractSynthAbstract, isOutputMarkdownFile } from "./validate.js";
11
11
  function readActiveRunStartedAtMs(dirPath) {
12
12
  const run = loadRuntimeRun(dirPath);
13
13
  if (!run)
@@ -49,72 +49,101 @@ function summaryAbstract(content) {
49
49
  const parsed = parseJsonFrontmatter(content);
50
50
  if (!parsed)
51
51
  return null;
52
- const frontmatterAbstract = typeof parsed.frontmatter.abstract === "string"
53
- ? parsed.frontmatter.abstract.trim()
54
- : "";
55
- if (frontmatterAbstract.length > 0)
56
- return frontmatterAbstract;
57
- const match = parsed.body.match(/^## Abstract\s+([\s\S]*?)(?:\n## |\n# |$)/m);
58
- const bodyAbstract = match?.[1]?.trim() ?? "";
59
- return bodyAbstract.length > 0 ? bodyAbstract : null;
52
+ return extractSynthAbstract(parsed.frontmatter, parsed.body);
53
+ }
54
+ function listZoneArtifacts(dirPath, zone) {
55
+ const absolutePath = compiledZoneAbsolutePath(dirPath, zone);
56
+ if (!existsSync(absolutePath) || zone.kind === "runtime")
57
+ return [];
58
+ if (zone.kind === "file") {
59
+ try {
60
+ return statSync(absolutePath).isFile() ? [absolutePath] : [];
61
+ }
62
+ catch {
63
+ return [];
64
+ }
65
+ }
66
+ return listFilesRecursive(absolutePath);
67
+ }
68
+ function buildInventoryMetadata(options) {
69
+ const metadata = {
70
+ zone_id: options.zoneId,
71
+ zone_kind: options.zoneKind,
72
+ file_extension: extname(options.filePath).toLowerCase() || null,
73
+ };
74
+ if (!options.parsedFrontmatter) {
75
+ return metadata;
76
+ }
77
+ metadata.frontmatter_scanned = true;
78
+ const abstract = summaryAbstract(readFileSync(options.filePath, "utf8"));
79
+ if (abstract) {
80
+ metadata.abstract = abstract;
81
+ metadata.abstract_read = true;
82
+ }
83
+ const frontmatter = options.parsedFrontmatter.frontmatter;
84
+ if (typeof frontmatter.source_kind === "string") {
85
+ metadata.source_kind = frontmatter.source_kind;
86
+ }
87
+ if (typeof frontmatter.evidence_tier === "string") {
88
+ metadata.evidence_tier = frontmatter.evidence_tier;
89
+ }
90
+ if (typeof frontmatter.truth_mode === "string") {
91
+ metadata.truth_mode = frontmatter.truth_mode;
92
+ }
93
+ return metadata;
60
94
  }
61
95
  function buildStageInventoryEntries(dirPath, stage) {
62
96
  const schema = readCompiledSchemaFile(join(dirPath, ".interf", "workflow"));
63
97
  if (!schema)
64
98
  return [];
65
- const inputZone = stage.reads
99
+ const readableInputZones = stage.reads
66
100
  .map((zoneId) => findCompiledSchemaZone(schema, zoneId))
67
- .find((zone) => zone && zone.kind !== "runtime");
68
- const outputZone = stage.writes
101
+ .filter((zone) => zone !== null && zone.kind !== "runtime");
102
+ const outputZones = stage.writes
69
103
  .map((zoneId) => findCompiledSchemaZone(schema, zoneId))
70
- .find((zone) => zone && zone.kind !== "runtime");
71
- if (!inputZone || !outputZone)
104
+ .filter((zone) => zone !== null && zone.kind !== "runtime");
105
+ if (outputZones.length === 0)
72
106
  return [];
73
- const outputRoot = compiledZoneAbsolutePath(dirPath, outputZone);
74
- if (!existsSync(outputRoot))
75
- return [];
76
- return listFilesRecursive(outputRoot, isOutputMarkdownFile)
77
- .map((filePath) => {
78
- const content = readFileSync(filePath, "utf8");
79
- const parsed = parseJsonFrontmatter(content);
80
- if (!parsed)
81
- return null;
82
- const inputPath = typeof parsed.frontmatter.source === "string"
83
- ? parsed.frontmatter.source.trim()
84
- : typeof parsed.frontmatter.source_file === "string"
85
- ? parsed.frontmatter.source_file.trim()
86
- : typeof parsed.frontmatter.raw === "string"
87
- ? parsed.frontmatter.raw.trim()
88
- : "";
89
- if (inputPath.length === 0)
90
- return null;
91
- const abstract = summaryAbstract(content);
92
- return {
93
- input_zone: inputZone.id,
94
- input_path: inputPath,
95
- output_zone: outputZone.id,
96
- output_path: relative(dirPath, filePath).replaceAll("\\", "/"),
97
- state: typeof parsed.frontmatter.state === "string"
98
- ? parsed.frontmatter.state
99
- : "complete",
100
- metadata: {
101
- source_kind: typeof parsed.frontmatter.source_kind === "string"
102
- ? parsed.frontmatter.source_kind
103
- : "unknown",
104
- evidence_tier: typeof parsed.frontmatter.evidence_tier === "string"
105
- ? parsed.frontmatter.evidence_tier
106
- : "primary",
107
- truth_mode: typeof parsed.frontmatter.truth_mode === "string"
108
- ? parsed.frontmatter.truth_mode
109
- : "reported-data",
110
- abstract,
111
- frontmatter_scanned: true,
112
- abstract_read: Boolean(abstract),
113
- },
114
- };
115
- })
116
- .filter((entry) => entry !== null)
117
- .sort((left, right) => left.input_path.localeCompare(right.input_path));
107
+ const entries = [];
108
+ for (const outputZone of outputZones) {
109
+ for (const filePath of listZoneArtifacts(dirPath, outputZone)) {
110
+ const relativeOutputPath = relative(dirPath, filePath).replaceAll("\\", "/");
111
+ const parsed = isOutputMarkdownFile(filePath)
112
+ ? parseJsonFrontmatter(readFileSync(filePath, "utf8"))
113
+ : null;
114
+ const sourcePath = typeof parsed?.frontmatter.source === "string"
115
+ ? parsed.frontmatter.source.trim()
116
+ : "";
117
+ const sourceZoneId = typeof parsed?.frontmatter.source_zone === "string"
118
+ ? parsed.frontmatter.source_zone.trim()
119
+ : "";
120
+ const inputZone = sourceZoneId.length > 0
121
+ ? readableInputZones.find((zone) => zone.id === sourceZoneId) ?? null
122
+ : readableInputZones.length === 1
123
+ ? readableInputZones[0]
124
+ : null;
125
+ entries.push({
126
+ ...(inputZone && sourcePath.length > 0
127
+ ? {
128
+ input_zone: inputZone.id,
129
+ input_path: sourcePath,
130
+ }
131
+ : {}),
132
+ output_zone: outputZone.id,
133
+ output_path: relativeOutputPath,
134
+ ...(typeof parsed?.frontmatter.state === "string"
135
+ ? { state: parsed.frontmatter.state }
136
+ : {}),
137
+ metadata: buildInventoryMetadata({
138
+ zoneId: outputZone.id,
139
+ zoneKind: outputZone.kind,
140
+ filePath,
141
+ parsedFrontmatter: parsed,
142
+ }),
143
+ });
144
+ }
145
+ }
146
+ return entries.sort((left, right) => `${left.output_zone}:${left.output_path}`.localeCompare(`${right.output_zone}:${right.output_path}`));
118
147
  }
119
148
  function writeStageInventory(dirPath, stageId, entries) {
120
149
  writeFileSync(join(compiledRuntimeRoot(dirPath), "inventory.json"), JSON.stringify(compiledInventoryFromEntries(entries, stageId), null, 2) + "\n");
@@ -137,10 +166,7 @@ export function reconcileCompiledStageRun(dirPath, stage) {
137
166
  if (!writeZones.some((zone) => anyPathUpdatedSince(compiledZoneAbsolutePath(dirPath, zone), startedAtMs))) {
138
167
  return false;
139
168
  }
140
- const inventoryEntries = buildStageInventoryEntries(dirPath, stage);
141
- if (inventoryEntries.length > 0) {
142
- writeStageInventory(dirPath, stage.id, inventoryEntries);
143
- }
169
+ writeStageInventory(dirPath, stage.id, buildStageInventoryEntries(dirPath, stage));
144
170
  const currentState = {
145
171
  ...initCompiledState(),
146
172
  ...(loadState(dirPath) ?? {}),
@@ -5,7 +5,7 @@ import { countFilesRecursive } from "./filesystem.js";
5
5
  import { buildRuntimeExecutorInfo } from "./executors.js";
6
6
  import { RuntimeRunSchema, } from "./schema.js";
7
7
  import { getWorkflowStageDefinition, getWorkflowStagePosition, getWorkflowStages, } from "./workflow-definitions.js";
8
- import { eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
8
+ import { archivedStageContractPath, eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
9
9
  import { warnInterf } from "./logger.js";
10
10
  export function loadRuntimeRun(dirPath) {
11
11
  const path = runPath(dirPath);
@@ -16,7 +16,8 @@ export function loadRuntimeRun(dirPath) {
16
16
  const parsed = RuntimeRunSchema.safeParse(raw);
17
17
  if (parsed.success)
18
18
  return parsed.data;
19
- return normalizeRuntimeRunRecord(raw);
19
+ warnInterf(`Warning: failed to validate runtime run at ${path}: ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
20
+ return null;
20
21
  }
21
22
  catch (error) {
22
23
  warnInterf(`Warning: failed to read runtime run at ${path}: ${error instanceof Error ? error.message : String(error)}`);
@@ -33,28 +34,34 @@ export function writeStageContract(dirPath, contract) {
33
34
  writeFileSync(path, JSON.stringify(contract, null, 2) + "\n");
34
35
  return path;
35
36
  }
37
+ function writeArchivedStageContract(dirPath, runId, contract) {
38
+ const path = archivedStageContractPath(dirPath, runId);
39
+ mkdirSync(dirname(path), { recursive: true });
40
+ writeFileSync(path, JSON.stringify(contract, null, 2) + "\n");
41
+ return path;
42
+ }
36
43
  export async function runExecutorStage(options) {
37
- const run = startRuntimeRun(options);
38
- const prompt = options.buildPrompt(run.contract_path);
39
- writeRuntimeRunPrompt(options.compiledPath, run.run_id, prompt);
44
+ const startedRun = startRuntimeRun(options);
45
+ const prompt = options.buildPrompt(startedRun.activeContractPath);
46
+ writeRuntimeRunPrompt(options.compiledPath, startedRun.run.run_id, prompt);
40
47
  const executionPath = options.executionPath ?? options.compiledPath;
41
48
  const code = await options.executor.execute(executionPath, prompt, {
42
- eventLogPath: eventLogPath(options.compiledPath, run.run_id),
43
- statusLogPath: statusLogPath(options.compiledPath, run.run_id),
49
+ eventLogPath: eventLogPath(options.compiledPath, startedRun.run.run_id),
50
+ statusLogPath: statusLogPath(options.compiledPath, startedRun.run.run_id),
44
51
  completionCheck: options.completionCheck,
45
52
  });
46
53
  finalizeRuntimeRun(options.compiledPath, code);
47
54
  return code;
48
55
  }
49
56
  export async function runExecutorSummarizeStage(options) {
50
- const run = startRuntimeRun(options);
51
- const prompt = options.buildPrompt(run.contract_path);
57
+ const startedRun = startRuntimeRun(options);
58
+ const prompt = options.buildPrompt(startedRun.activeContractPath);
52
59
  let lastReported = 0;
53
- writeRuntimeRunPrompt(options.compiledPath, run.run_id, prompt);
60
+ writeRuntimeRunPrompt(options.compiledPath, startedRun.run.run_id, prompt);
54
61
  const executionPath = options.executionPath ?? options.compiledPath;
55
62
  const progressPromise = options.executor.execute(executionPath, prompt, {
56
- eventLogPath: eventLogPath(options.compiledPath, run.run_id),
57
- statusLogPath: statusLogPath(options.compiledPath, run.run_id),
63
+ eventLogPath: eventLogPath(options.compiledPath, startedRun.run.run_id),
64
+ statusLogPath: statusLogPath(options.compiledPath, startedRun.run.run_id),
58
65
  completionCheck: options.completionCheck,
59
66
  });
60
67
  const timer = setInterval(() => {
@@ -65,7 +72,7 @@ export async function runExecutorSummarizeStage(options) {
65
72
  lastReported = completed;
66
73
  updateRuntimeRun(options.compiledPath, {
67
74
  counts: {
68
- ...run.counts,
75
+ ...startedRun.run.counts,
69
76
  completed_summaries: completed,
70
77
  target_summaries: options.targetCount,
71
78
  },
@@ -163,7 +170,8 @@ function startRuntimeRun(options) {
163
170
  artifacts: options.contract.artifacts,
164
171
  policies: options.contract.policies,
165
172
  };
166
- const contractPath = writeStageContract(options.compiledPath, contract);
173
+ const activeContractPath = writeStageContract(options.compiledPath, contract);
174
+ const archivedContractPath = writeArchivedStageContract(options.compiledPath, runId, contract);
167
175
  const run = {
168
176
  kind: "interf-run",
169
177
  version: 1,
@@ -179,7 +187,7 @@ function startRuntimeRun(options) {
179
187
  started_at: generatedAt,
180
188
  updated_at: generatedAt,
181
189
  finished_at: null,
182
- contract_path: relative(options.compiledPath, contractPath),
190
+ contract_path: relative(options.compiledPath, archivedContractPath),
183
191
  ...(options.executionPath ? { execution_path: relative(options.compiledPath, options.executionPath) } : {}),
184
192
  counts: { ...contract.counts },
185
193
  output_artifacts: [...contract.artifacts.writes],
@@ -192,7 +200,12 @@ function startRuntimeRun(options) {
192
200
  exit_code: null,
193
201
  error: null,
194
202
  };
195
- return beginRuntimeRun(options.compiledPath, run);
203
+ return {
204
+ run: beginRuntimeRun(options.compiledPath, run),
205
+ activeContractPath: options.executionPath
206
+ ? "runtime/stage-contract.json"
207
+ : relative(options.compiledPath, activeContractPath),
208
+ };
196
209
  }
197
210
  function finalizeRuntimeRun(dirPath, code) {
198
211
  const current = loadRuntimeRun(dirPath);
@@ -221,92 +234,6 @@ function writeRuntimeRunPrompt(dirPath, runId, prompt) {
221
234
  function createRunId() {
222
235
  return `run_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
223
236
  }
224
- function normalizeRuntimeRunRecord(raw) {
225
- if (!raw || typeof raw !== "object")
226
- return null;
227
- const record = raw;
228
- const executor = record.executor;
229
- if (record.kind !== "interf-run" ||
230
- typeof record.version !== "number" ||
231
- typeof record.run_id !== "string" ||
232
- typeof record.target_name !== "string" ||
233
- typeof record.workflow !== "string" ||
234
- typeof record.stage !== "string" ||
235
- !executor ||
236
- typeof executor !== "object" ||
237
- typeof record.started_at !== "string" ||
238
- typeof record.updated_at !== "string" ||
239
- typeof record.contract_path !== "string" ||
240
- typeof record.summary !== "string") {
241
- return null;
242
- }
243
- const normalizedTargetType = inferRuntimeTargetType(record.target_type);
244
- if (!normalizedTargetType)
245
- return null;
246
- const executorRecord = executor;
247
- const normalized = {
248
- kind: "interf-run",
249
- version: record.version,
250
- run_id: record.run_id,
251
- target_type: normalizedTargetType,
252
- target_name: record.target_name,
253
- workflow: record.workflow,
254
- stage: record.stage,
255
- stage_label: typeof record.stage_label === "string" ? record.stage_label : record.stage,
256
- contract_type: typeof record.contract_type === "string"
257
- ? inferRuntimeContractType(record.contract_type, record.stage)
258
- : inferRuntimeContractType(record.target_type, record.stage),
259
- status: normalizeRuntimeRunStatus(record),
260
- executor: {
261
- kind: executorRecord.kind,
262
- name: executorRecord.name,
263
- display_name: executorRecord.display_name,
264
- command: typeof executorRecord.command === "string" ? executorRecord.command : null,
265
- model: typeof executorRecord.model === "string" ? executorRecord.model : null,
266
- effort: typeof executorRecord.effort === "string" ? executorRecord.effort : null,
267
- profile: typeof executorRecord.profile === "string" ? executorRecord.profile : null,
268
- timeout_ms: typeof executorRecord.timeout_ms === "number" ? executorRecord.timeout_ms : null,
269
- },
270
- started_at: record.started_at,
271
- updated_at: record.updated_at,
272
- finished_at: typeof record.finished_at === "string" ? record.finished_at : null,
273
- contract_path: record.contract_path,
274
- execution_path: typeof record.execution_path === "string" ? record.execution_path : undefined,
275
- counts: record.counts && typeof record.counts === "object" ? record.counts : {},
276
- output_artifacts: Array.isArray(record.output_artifacts) ? record.output_artifacts : [],
277
- logs: record.logs && typeof record.logs === "object" ? record.logs : undefined,
278
- summary: record.summary,
279
- exit_code: typeof record.exit_code === "number" ? record.exit_code : null,
280
- error: typeof record.error === "string" ? record.error : null,
281
- };
282
- const parsed = RuntimeRunSchema.safeParse(normalized);
283
- return parsed.success ? parsed.data : null;
284
- }
285
- function normalizeRuntimeRunStatus(record) {
286
- const status = record.status;
287
- if (status === "running" || status === "succeeded" || status === "failed")
288
- return status;
289
- if (typeof record.exit_code === "number")
290
- return record.exit_code === 0 ? "succeeded" : "failed";
291
- if (typeof record.error === "string" && record.error.length > 0)
292
- return "failed";
293
- return "running";
294
- }
295
- function inferRuntimeTargetType(targetType) {
296
- if (targetType === "compiled") {
297
- return "compiled";
298
- }
299
- return null;
300
- }
301
- function inferRuntimeContractType(contractType, stage) {
302
- if (typeof contractType === "string" && /^[a-z0-9][a-z0-9-]{0,79}$/.test(contractType)) {
303
- return contractType;
304
- }
305
- if (typeof stage === "string" && /^[a-z0-9][a-z0-9-]{0,79}$/.test(stage)) {
306
- return stage;
307
- }
308
- return "compiled";
309
- }
310
237
  function replaceOrAppendRunHistoryEntry(dirPath, run) {
311
238
  const historyPath = runHistoryPath(dirPath);
312
239
  if (!existsSync(historyPath)) {
@@ -1,5 +1,5 @@
1
1
  export type { RuntimeRunPatch, RuntimeRunStatus, RuntimeStageAcceptanceValidation, RuntimeStageContractDraft, RuntimeStageExecutionOptions, RuntimeSummarizeExecutionOptions, RuntimeStageContractOptions, } from "./runtime-types.js";
2
- export { eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
2
+ export { archivedStageContractPath, eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
3
3
  export { validateStageContractAcceptance } from "./runtime-acceptance.js";
4
4
  export { buildStagePrompt } from "./runtime-prompt.js";
5
5
  export { buildRuntimeStageContract, } from "./runtime-contracts.js";
@@ -1,4 +1,4 @@
1
- export { eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
1
+ export { archivedStageContractPath, eventLogPath, logsDirPath, promptLogPath, runHistoryPath, runPath, stageContractPath, statusLogPath, } from "./runtime-paths.js";
2
2
  export { validateStageContractAcceptance } from "./runtime-acceptance.js";
3
3
  export { buildStagePrompt } from "./runtime-prompt.js";
4
4
  export { buildRuntimeStageContract, } from "./runtime-contracts.js";