@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.
- package/README.md +126 -188
- package/builtin-workflows/interf/README.md +22 -10
- package/builtin-workflows/interf/compile/stages/shape/SKILL.md +6 -3
- package/builtin-workflows/interf/compile/stages/structure/SKILL.md +3 -0
- package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +18 -2
- package/builtin-workflows/interf/improve/SKILL.md +2 -2
- package/builtin-workflows/interf/workflow.json +18 -4
- package/builtin-workflows/interf/{compiled.schema.json → workflow.schema.json} +9 -2
- package/dist/commands/check-draft.js +3 -3
- package/dist/commands/compile-controller.js +9 -16
- package/dist/commands/compile.d.ts +19 -1
- package/dist/commands/compile.js +98 -28
- package/dist/commands/create-workflow-wizard.d.ts +20 -2
- package/dist/commands/create-workflow-wizard.js +163 -27
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +67 -60
- package/dist/commands/dataset-selection.d.ts +6 -0
- package/dist/commands/dataset-selection.js +11 -0
- package/dist/commands/default.js +3 -3
- package/dist/commands/doctor.js +8 -8
- package/dist/commands/executor-flow.d.ts +1 -1
- package/dist/commands/executor-flow.js +5 -2
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.js +56 -48
- package/dist/commands/list.js +6 -3
- package/dist/commands/reset.js +1 -1
- package/dist/commands/source-config-wizard.d.ts +2 -2
- package/dist/commands/source-config-wizard.js +50 -17
- package/dist/commands/test-flow.js +5 -16
- package/dist/commands/test.d.ts +0 -6
- package/dist/commands/test.js +9 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/agent-args.d.ts +1 -0
- package/dist/lib/agent-args.js +10 -0
- package/dist/lib/agent-execution.js +2 -1
- package/dist/lib/agent-preflight.js +2 -1
- package/dist/lib/agent-shells.d.ts +26 -1
- package/dist/lib/agent-shells.js +214 -40
- package/dist/lib/agents.d.ts +1 -1
- package/dist/lib/agents.js +1 -1
- package/dist/lib/builtin-compiled-workflow.d.ts +38 -0
- package/dist/lib/builtin-compiled-workflow.js +94 -0
- package/dist/lib/compiled-compile.d.ts +0 -4
- package/dist/lib/compiled-compile.js +11 -30
- package/dist/lib/compiled-paths.d.ts +1 -2
- package/dist/lib/compiled-paths.js +8 -13
- package/dist/lib/compiled-raw.d.ts +2 -2
- package/dist/lib/compiled-reset.d.ts +1 -0
- package/dist/lib/compiled-reset.js +42 -14
- package/dist/lib/compiled-schema.d.ts +11 -7
- package/dist/lib/compiled-schema.js +47 -16
- package/dist/lib/discovery.d.ts +1 -1
- package/dist/lib/discovery.js +2 -2
- package/dist/lib/executors.d.ts +1 -1
- package/dist/lib/executors.js +2 -2
- package/dist/lib/interf-detect.d.ts +0 -1
- package/dist/lib/interf-detect.js +7 -18
- package/dist/lib/interf-scaffold.js +4 -11
- package/dist/lib/interf-workflow-package.d.ts +8 -3
- package/dist/lib/interf-workflow-package.js +128 -62
- package/dist/lib/interf.d.ts +1 -1
- package/dist/lib/interf.js +1 -1
- package/dist/lib/local-workflows.d.ts +4 -3
- package/dist/lib/local-workflows.js +127 -104
- package/dist/lib/project-paths.d.ts +2 -4
- package/dist/lib/project-paths.js +13 -10
- package/dist/lib/runtime-acceptance.js +15 -3
- package/dist/lib/runtime-contracts.js +3 -2
- package/dist/lib/runtime-paths.d.ts +1 -0
- package/dist/lib/runtime-paths.js +4 -1
- package/dist/lib/runtime-prompt.js +4 -4
- package/dist/lib/runtime-reconcile.js +90 -64
- package/dist/lib/runtime-runs.js +29 -102
- package/dist/lib/runtime.d.ts +1 -1
- package/dist/lib/runtime.js +1 -1
- package/dist/lib/schema.d.ts +104 -54
- package/dist/lib/schema.js +32 -116
- package/dist/lib/source-config.js +21 -22
- package/dist/lib/state-health.js +4 -2
- package/dist/lib/state-io.js +2 -110
- package/dist/lib/state-view.js +8 -8
- package/dist/lib/state.d.ts +1 -0
- package/dist/lib/state.js +7 -0
- package/dist/lib/test-execution.js +2 -2
- package/dist/lib/test-paths.js +12 -3
- package/dist/lib/test-sandbox.js +4 -17
- package/dist/lib/test-specs.js +1 -1
- package/dist/lib/validate-compiled.js +13 -8
- package/dist/lib/validate.d.ts +5 -1
- package/dist/lib/validate.js +30 -22
- package/dist/lib/workflow-authoring.d.ts +26 -0
- package/dist/lib/workflow-authoring.js +119 -0
- package/dist/lib/workflow-definitions.d.ts +14 -3
- package/dist/lib/workflow-definitions.js +21 -17
- package/dist/lib/workflow-edit-session.d.ts +16 -0
- package/dist/lib/workflow-edit-session.js +57 -0
- package/dist/lib/workflow-edit-utils.d.ts +10 -0
- package/dist/lib/workflow-edit-utils.js +39 -0
- package/dist/lib/workflow-improvement.js +30 -217
- package/dist/lib/workflow-primitives.d.ts +2 -0
- package/dist/lib/workflow-primitives.js +5 -0
- package/dist/lib/workflow-stage-policy.d.ts +5 -0
- package/dist/lib/workflow-stage-policy.js +31 -0
- package/package.json +7 -8
- package/dist/lib/compiled-layout.d.ts +0 -2
- package/dist/lib/compiled-layout.js +0 -60
- package/dist/lib/obsidian.d.ts +0 -1
- package/dist/lib/obsidian.js +0 -15
- package/dist/lib/summarize-plan.d.ts +0 -17
- package/dist/lib/summarize-plan.js +0 -124
- package/dist/lib/workflow-abi.d.ts +0 -129
- 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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
99
|
+
const readableInputZones = stage.reads
|
|
66
100
|
.map((zoneId) => findCompiledSchemaZone(schema, zoneId))
|
|
67
|
-
.
|
|
68
|
-
const
|
|
101
|
+
.filter((zone) => zone !== null && zone.kind !== "runtime");
|
|
102
|
+
const outputZones = stage.writes
|
|
69
103
|
.map((zoneId) => findCompiledSchemaZone(schema, zoneId))
|
|
70
|
-
.
|
|
71
|
-
if (
|
|
104
|
+
.filter((zone) => zone !== null && zone.kind !== "runtime");
|
|
105
|
+
if (outputZones.length === 0)
|
|
72
106
|
return [];
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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) ?? {}),
|
package/dist/lib/runtime-runs.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
38
|
-
const prompt = options.buildPrompt(
|
|
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
|
|
51
|
-
const prompt = options.buildPrompt(
|
|
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
|
|
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,
|
|
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
|
|
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)) {
|
package/dist/lib/runtime.d.ts
CHANGED
|
@@ -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";
|
package/dist/lib/runtime.js
CHANGED
|
@@ -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";
|