@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
package/dist/lib/agent-shells.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { cpSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, symlinkSync, } from "node:fs";
|
|
1
|
+
import { cpSync, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, symlinkSync, } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
2
3
|
import { basename, dirname, join, relative } from "node:path";
|
|
3
4
|
import { CHART_APPROXIMATION_NOTES } from "./chart-guidance.js";
|
|
5
|
+
import { projectRawSnapshot } from "./compiled-raw.js";
|
|
4
6
|
import { WORKFLOW_PACKAGE_DIR } from "./interf-detect.js";
|
|
5
|
-
import { ensureCompiledZoneTargets, readCompiledSchemaFile, compiledZoneAbsolutePath, } from "./compiled-schema.js";
|
|
7
|
+
import { WORKFLOW_SCHEMA_FILE, ensureCompiledZoneTargets, readCompiledSchemaFile, compiledZoneAbsolutePath, resolveWorkflowSchemaPath, } from "./compiled-schema.js";
|
|
6
8
|
import { stageExecutionShellsRoot, workflowImprovementLoopRoot, workflowPackagePathForCompiled, compiledInterfConfigPath, compiledRuntimeRoot, } from "./compiled-paths.js";
|
|
7
9
|
import { resolveWorkflowImprovementReviewSourcePaths } from "./workflow-review-paths.js";
|
|
10
|
+
import { listFilesRecursive } from "./filesystem.js";
|
|
8
11
|
const LOCAL_SKILL_ROOTS = [
|
|
9
12
|
".claude/skills",
|
|
10
13
|
".codex/skills",
|
|
11
14
|
".agents/skills",
|
|
12
15
|
".cursor/skills",
|
|
13
16
|
];
|
|
14
|
-
function writeNativeAgentSurface(rootPath, agentsContent, skillName, skillContent) {
|
|
17
|
+
export function writeNativeAgentSurface(rootPath, agentsContent, skillName, skillContent) {
|
|
15
18
|
let changed = false;
|
|
16
19
|
changed = writeIfChanged(join(rootPath, "AGENTS.md"), `${agentsContent.trimEnd()}\n`) || changed;
|
|
17
20
|
changed =
|
|
@@ -25,10 +28,10 @@ function compiledQuerySkillSourcePath(compiledPath) {
|
|
|
25
28
|
function compiledZoneSummaryLines(compiledPath) {
|
|
26
29
|
const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
|
|
27
30
|
if (!schema)
|
|
28
|
-
return ["- No
|
|
31
|
+
return ["- No workflow schema is available yet."];
|
|
29
32
|
return schema.zones
|
|
30
|
-
.filter((zone) => zone.
|
|
31
|
-
.map((zone) => `- \`${zone.id}\` -> \`${zone.path}\` (${zone.kind})`);
|
|
33
|
+
.filter((zone) => zone.kind !== "runtime")
|
|
34
|
+
.map((zone) => `- \`${zone.id}\` -> \`${zone.path}\` (${zone.role} ${zone.kind})`);
|
|
32
35
|
}
|
|
33
36
|
export function renderCompiledAgents(compiledPath, name, workflowId, about, options = {}) {
|
|
34
37
|
const workflowOriginSelected = options.workflowOriginSelected ?? workflowId;
|
|
@@ -37,8 +40,8 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
|
|
|
37
40
|
return [
|
|
38
41
|
`# ${name}`,
|
|
39
42
|
"",
|
|
40
|
-
"This is a compiled dataset built by Interf
|
|
41
|
-
"It is a file-based layer on top of the raw files, built for agents to navigate, retrieve evidence, and
|
|
43
|
+
"This is a compiled dataset built by Interf.",
|
|
44
|
+
"It is a file-based layer on top of the raw files, built for agents to navigate, retrieve evidence, and reach source-backed answers more reliably.",
|
|
42
45
|
"",
|
|
43
46
|
...(about
|
|
44
47
|
? [
|
|
@@ -48,29 +51,29 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
|
|
|
48
51
|
: []),
|
|
49
52
|
"## How to use this compiled dataset",
|
|
50
53
|
"",
|
|
51
|
-
"1. Use the local native `interf-query` skill that Interf
|
|
54
|
+
"1. Use the local native `interf-query` skill that Interf generated for this compiled dataset.",
|
|
52
55
|
"2. Let the workflow docs and compiled output zones guide retrieval instead of assuming a fixed note layout.",
|
|
53
56
|
"3. Use `raw/` when you need direct quotes, exact chart values, table lookups, or verification.",
|
|
54
57
|
"",
|
|
55
58
|
"## How this compiled dataset works",
|
|
56
59
|
"",
|
|
57
|
-
"- `.interf/interf.json` points to the local `raw/` snapshot via `source.path` and back to the
|
|
60
|
+
"- `.interf/interf.json` points to the local `raw/` snapshot via `source.path` and back to the project root via `source.control_path`.",
|
|
58
61
|
`- Workflow seed: \`${workflowOriginSelected}\`.`,
|
|
59
62
|
...(workflowLocalDraft
|
|
60
63
|
? ["- This compiled dataset now carries a local workflow draft improved from that seed. Recompiling this compiled dataset reuses the local `.interf/workflow/` package."]
|
|
61
64
|
: []),
|
|
62
65
|
`- Active local workflow id: \`${workflowId}\`.`,
|
|
63
66
|
"- `.interf/workflow/` is the local editable method package for this compiled dataset.",
|
|
64
|
-
|
|
67
|
+
`- \`.interf/workflow/${WORKFLOW_SCHEMA_FILE}\` is the deterministic zone contract for this compiled dataset.`,
|
|
65
68
|
"- `.interf/workflow/improve/` is the editable source for workflow-improvement loops.",
|
|
66
69
|
"- `.interf/workflow/use/query/` is the editable source for the generated native query shell.",
|
|
67
|
-
"- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf
|
|
70
|
+
"- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf projects into native execution shells for automated runs.",
|
|
68
71
|
"- Native local query skills are generated under local agent skill directories such as `.claude/skills/` and `.codex/skills/`.",
|
|
69
72
|
"- `raw/` contains the local raw snapshot used for evidence and verification.",
|
|
70
|
-
|
|
73
|
+
`- Workflow zones are declared in \`.interf/workflow/${WORKFLOW_SCHEMA_FILE}\`.`,
|
|
71
74
|
...zoneLines,
|
|
72
75
|
"- `.interf/runtime/` holds CLI-owned runtime artifacts.",
|
|
73
|
-
"- `.interf/tests/`
|
|
76
|
+
"- `.interf/tests/` mirrors the latest dataset-level comparison and keeps detailed target runs plus preserved sandboxes.",
|
|
74
77
|
"- `.interf/tests/targets/` holds detailed raw and compiled target runs plus preserved test sandboxes.",
|
|
75
78
|
"",
|
|
76
79
|
"## Manual query rules",
|
|
@@ -100,7 +103,6 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
|
|
|
100
103
|
].join("\n");
|
|
101
104
|
}
|
|
102
105
|
export function renderCompiledQuerySkill() {
|
|
103
|
-
const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note.toLowerCase()}`);
|
|
104
106
|
return [
|
|
105
107
|
"# Manual Query Loop",
|
|
106
108
|
"",
|
|
@@ -108,15 +110,15 @@ export function renderCompiledQuerySkill() {
|
|
|
108
110
|
"",
|
|
109
111
|
"Default loop:",
|
|
110
112
|
"1. Read `workflow/README.md` and this file first.",
|
|
111
|
-
|
|
112
|
-
"3. Use `raw/` for direct quotes, verification, exact
|
|
113
|
+
`2. Use the workflow zones declared in \`workflow/${WORKFLOW_SCHEMA_FILE}\` before falling back to \`raw/\`.`,
|
|
114
|
+
"3. Use `raw/` for direct quotes, verification, exact lookups, and cases where the compiled layer is missing or ambiguous.",
|
|
113
115
|
"",
|
|
114
116
|
"Answering rule:",
|
|
115
117
|
"- do not modify files under `raw/`",
|
|
116
|
-
"- treat the workflow
|
|
117
|
-
"- when
|
|
118
|
-
"- use `raw/` to confirm source page, metric family, or
|
|
119
|
-
|
|
118
|
+
"- treat the workflow as the method layer and the compiled zones as the working retrieval surface",
|
|
119
|
+
"- say explicitly when an answer depends on approximation, bounded inference, or a raw-source re-check",
|
|
120
|
+
"- use `raw/` to confirm source page, metric family, provenance, or exact wording when the compiled layer is missing or ambiguous",
|
|
121
|
+
"- do not invent navigation or note structure beyond what this workflow declares",
|
|
120
122
|
"- when the compiled layer is insufficient, verify in `raw/` and then answer",
|
|
121
123
|
"",
|
|
122
124
|
"You can edit this file to bias manual question-answering behavior for this compiled dataset.",
|
|
@@ -128,7 +130,7 @@ function renderRawTestAgents() {
|
|
|
128
130
|
return [
|
|
129
131
|
"# Raw Test Shell",
|
|
130
132
|
"",
|
|
131
|
-
"This is an isolated raw-files test shell generated by Interf
|
|
133
|
+
"This is an isolated raw-files test shell generated by Interf.",
|
|
132
134
|
"There is no compiled dataset in this shell.",
|
|
133
135
|
"",
|
|
134
136
|
"## How to use this shell",
|
|
@@ -229,7 +231,7 @@ function loadCompiledSchema(compiledPath) {
|
|
|
229
231
|
const workflowRoot = workflowPackagePathForCompiled(compiledPath);
|
|
230
232
|
const schema = readCompiledSchemaFile(workflowRoot);
|
|
231
233
|
if (!schema) {
|
|
232
|
-
throw new Error(`Missing workflow
|
|
234
|
+
throw new Error(`Missing workflow schema at ${join(workflowRoot, WORKFLOW_SCHEMA_FILE)}`);
|
|
233
235
|
}
|
|
234
236
|
return schema;
|
|
235
237
|
}
|
|
@@ -239,7 +241,7 @@ function zoneMap(schema) {
|
|
|
239
241
|
function zoneOrThrow(zones, zoneId) {
|
|
240
242
|
const zone = zones.get(zoneId);
|
|
241
243
|
if (!zone) {
|
|
242
|
-
throw new Error(`Missing
|
|
244
|
+
throw new Error(`Missing workflow schema zone "${zoneId}" for stage shell projection.`);
|
|
243
245
|
}
|
|
244
246
|
return zone;
|
|
245
247
|
}
|
|
@@ -312,7 +314,7 @@ function renderStageExecutionAgents(compiledName, workflowId, stage) {
|
|
|
312
314
|
return [
|
|
313
315
|
`# ${compiledName} — ${stage.label} Execution Shell`,
|
|
314
316
|
"",
|
|
315
|
-
"This is an ephemeral stage-execution shell generated by Interf
|
|
317
|
+
"This is an ephemeral stage-execution shell generated by Interf.",
|
|
316
318
|
"It is for automated pipeline execution only, not for manual querying.",
|
|
317
319
|
"",
|
|
318
320
|
"## Start Here",
|
|
@@ -329,7 +331,7 @@ function renderStageExecutionAgents(compiledName, workflowId, stage) {
|
|
|
329
331
|
"- For file zones, `runtime/paths.json` points to the exact file path inside those mount roots.",
|
|
330
332
|
"- declared compiled zone paths are also projected at the shell root so workflow-relative contract paths stay valid.",
|
|
331
333
|
"- `runtime/` = stage contract and machine-readable path map for this shell.",
|
|
332
|
-
"- `workflow/` = workflow metadata,
|
|
334
|
+
"- `workflow/` = workflow metadata, workflow schema, and docs for the current stage only.",
|
|
333
335
|
"",
|
|
334
336
|
"## Boundaries",
|
|
335
337
|
"",
|
|
@@ -360,12 +362,12 @@ function renderStageExecutionSkill(stage, stageMethodDoc) {
|
|
|
360
362
|
"name: interf-stage",
|
|
361
363
|
"description: >",
|
|
362
364
|
` Native local execution skill for the ${stage.label} stage in this`,
|
|
363
|
-
" Interf
|
|
365
|
+
" Interf run. Use it only inside an automated stage execution shell.",
|
|
364
366
|
"---",
|
|
365
367
|
"",
|
|
366
|
-
`# Interf
|
|
368
|
+
`# Interf Stage Execution — ${stage.label}`,
|
|
367
369
|
"",
|
|
368
|
-
"This local native skill exists for automated Interf
|
|
370
|
+
"This local native skill exists for automated Interf stage execution.",
|
|
369
371
|
"Read `runtime/stage-contract.json` first.",
|
|
370
372
|
"Then read `runtime/paths.json` and use the mounted `inputs/` and `outputs/` zones for this stage.",
|
|
371
373
|
"Do not switch into manual query mode.",
|
|
@@ -399,9 +401,9 @@ function renderCompiledQueryNativeSkill(querySkillContent) {
|
|
|
399
401
|
" its raw fallback.",
|
|
400
402
|
"---",
|
|
401
403
|
"",
|
|
402
|
-
"# Interf
|
|
404
|
+
"# Interf Query",
|
|
403
405
|
"",
|
|
404
|
-
"This is the native local query skill for a compiled dataset built by Interf
|
|
406
|
+
"This is the native local query skill for a compiled dataset built by Interf.",
|
|
405
407
|
"Use it when reading this compiled dataset manually.",
|
|
406
408
|
"Editable source: `.interf/workflow/use/query/SKILL.md`.",
|
|
407
409
|
"",
|
|
@@ -417,9 +419,9 @@ function projectWorkflowMetadata(compiledPath, shellRoot, stage) {
|
|
|
417
419
|
if (existsSync(workflowJsonPath)) {
|
|
418
420
|
linkPath(workflowJsonPath, join(shellWorkflowRoot, "workflow.json"));
|
|
419
421
|
}
|
|
420
|
-
const compiledSchemaPath =
|
|
421
|
-
if (
|
|
422
|
-
linkPath(compiledSchemaPath, join(shellWorkflowRoot,
|
|
422
|
+
const compiledSchemaPath = resolveWorkflowSchemaPath(compiledWorkflowRoot);
|
|
423
|
+
if (compiledSchemaPath) {
|
|
424
|
+
linkPath(compiledSchemaPath, join(shellWorkflowRoot, WORKFLOW_SCHEMA_FILE));
|
|
423
425
|
}
|
|
424
426
|
const readmePath = join(compiledWorkflowRoot, "README.md");
|
|
425
427
|
if (existsSync(readmePath)) {
|
|
@@ -509,6 +511,13 @@ export function syncStageExecutionShellWrites(compiledPath, shellRoot, stage, wr
|
|
|
509
511
|
continue;
|
|
510
512
|
const compiledZonePath = compiledZoneAbsolutePath(compiledPath, zone);
|
|
511
513
|
if (shellZoneStat.isDirectory()) {
|
|
514
|
+
const shellZoneFiles = listFilesRecursive(shellZonePath);
|
|
515
|
+
const compiledZoneFiles = existsSync(compiledZonePath)
|
|
516
|
+
? listFilesRecursive(compiledZonePath)
|
|
517
|
+
: [];
|
|
518
|
+
if (shellZoneFiles.length === 0 && compiledZoneFiles.length > 0) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
512
521
|
rmSync(compiledZonePath, { recursive: true, force: true });
|
|
513
522
|
mkdirSync(dirname(compiledZonePath), { recursive: true });
|
|
514
523
|
cpSync(shellZonePath, compiledZonePath, {
|
|
@@ -645,26 +654,191 @@ function freezePreservedShell(rootPath, shellType) {
|
|
|
645
654
|
}
|
|
646
655
|
export function renderClaudeBootstrap(content) {
|
|
647
656
|
return [
|
|
648
|
-
"<!-- Generated compatibility mirror of AGENTS.md. Interf
|
|
657
|
+
"<!-- Generated compatibility mirror of AGENTS.md. Interf may rewrite this file. -->",
|
|
649
658
|
"",
|
|
650
659
|
content.trimEnd(),
|
|
651
660
|
"",
|
|
652
661
|
].join("\n");
|
|
653
662
|
}
|
|
663
|
+
function renderWorkflowAuthoringAgents(options) {
|
|
664
|
+
return [
|
|
665
|
+
`# ${options.label} — Workflow Authoring Shell`,
|
|
666
|
+
"",
|
|
667
|
+
"This is an automated workflow-authoring shell generated by Interf.",
|
|
668
|
+
"It exists to create or refine one standalone workflow for the files and checks in this dataset.",
|
|
669
|
+
"",
|
|
670
|
+
"## Start Here",
|
|
671
|
+
"",
|
|
672
|
+
"1. Read `runtime/authoring-context.json` now.",
|
|
673
|
+
`2. Read \`workflow/README.md\`, \`workflow/workflow.json\`, and \`workflow/${WORKFLOW_SCHEMA_FILE}\` now.`,
|
|
674
|
+
"3. Review `artifacts/source-dataset/raw/` and `artifacts/preview-compiled/` if present.",
|
|
675
|
+
"4. Use the local native `interf-workflow-author` skill now.",
|
|
676
|
+
"",
|
|
677
|
+
"## Boundaries",
|
|
678
|
+
"",
|
|
679
|
+
`- New workflow id: \`${options.workflowId}\`.`,
|
|
680
|
+
`- Seed workflow: \`${options.baseWorkflowId}\`.`,
|
|
681
|
+
"- Edit only files under `workflow/`.",
|
|
682
|
+
"- Do not edit raw dataset files or preview artifacts.",
|
|
683
|
+
"- Keep the workflow valid for the current compiler API and workflow schema.",
|
|
684
|
+
"- Prefer direct file-reading and search tools over shell commands for routine file inspection.",
|
|
685
|
+
"- Do not use shell helpers like `cat`, `sed`, `ls`, or `find` when a native read/search tool can inspect the same files.",
|
|
686
|
+
"",
|
|
687
|
+
"## Goal",
|
|
688
|
+
"",
|
|
689
|
+
"- produce one standalone workflow tuned to the files and checks in this dataset",
|
|
690
|
+
"- preserve deterministic stage and zone contracts",
|
|
691
|
+
"- stop once the workflow edits are complete",
|
|
692
|
+
"",
|
|
693
|
+
].join("\n");
|
|
694
|
+
}
|
|
695
|
+
function renderWorkflowAuthoringSkill() {
|
|
696
|
+
return [
|
|
697
|
+
"---",
|
|
698
|
+
"name: interf-workflow-author",
|
|
699
|
+
"description: >",
|
|
700
|
+
" Native local workflow-authoring skill for an automated Interf workflow draft run.",
|
|
701
|
+
"---",
|
|
702
|
+
"",
|
|
703
|
+
"# Interf Workflow Authoring",
|
|
704
|
+
"",
|
|
705
|
+
"Read `runtime/authoring-context.json` first.",
|
|
706
|
+
"Then review the seeded package under `workflow/`, the raw dataset snapshot under `artifacts/source-dataset/raw/`, and any preview compiled outputs under `artifacts/preview-compiled/`.",
|
|
707
|
+
"",
|
|
708
|
+
"Rules:",
|
|
709
|
+
"- edit only `workflow/`",
|
|
710
|
+
`- keep \`workflow.json\`, \`${WORKFLOW_SCHEMA_FILE}\`, and any changed stage docs aligned`,
|
|
711
|
+
"- prefer small, defensible package edits over random churn",
|
|
712
|
+
"- keep the package standalone; do not introduce runtime inheritance or fallback assumptions",
|
|
713
|
+
"- do not introduce wikilinks unless the workflow also creates the target note by exact basename or explicit relative path",
|
|
714
|
+
"- respect stage boundaries: do not make structure outputs link to notes or entrypoints first created by later stages",
|
|
715
|
+
"- prefer conservative routing changes over speculative note sprawl",
|
|
716
|
+
"- prefer direct file-reading and search tools over shell commands for routine file inspection",
|
|
717
|
+
"- do not use shell helpers like `cat`, `sed`, `ls`, or `find` when a native read/search tool can inspect the same files",
|
|
718
|
+
"- do not hardcode benchmark answers into workflow docs",
|
|
719
|
+
"- do not edit raw dataset files or preview artifacts",
|
|
720
|
+
"",
|
|
721
|
+
].join("\n");
|
|
722
|
+
}
|
|
723
|
+
function authoringCopyIfExists(sourcePath, targetPath) {
|
|
724
|
+
if (!existsSync(sourcePath))
|
|
725
|
+
return;
|
|
726
|
+
mkdirSync(dirname(targetPath), { recursive: true });
|
|
727
|
+
cpSync(sourcePath, targetPath, {
|
|
728
|
+
recursive: true,
|
|
729
|
+
force: true,
|
|
730
|
+
errorOnExist: false,
|
|
731
|
+
preserveTimestamps: true,
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
function projectCompiledPreviewSnapshot(previewCompiledPath, shellRoot) {
|
|
735
|
+
const previewRoot = join(shellRoot, "artifacts", "preview-compiled");
|
|
736
|
+
mkdirSync(previewRoot, { recursive: true });
|
|
737
|
+
authoringCopyIfExists(join(previewCompiledPath, "AGENTS.md"), join(previewRoot, "AGENTS.md"));
|
|
738
|
+
authoringCopyIfExists(join(previewCompiledPath, "CLAUDE.md"), join(previewRoot, "CLAUDE.md"));
|
|
739
|
+
const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(previewCompiledPath));
|
|
740
|
+
for (const zone of schema?.zones ?? []) {
|
|
741
|
+
if (zone.kind === "runtime" || zone.role === "input")
|
|
742
|
+
continue;
|
|
743
|
+
const absolutePath = compiledZoneAbsolutePath(previewCompiledPath, zone);
|
|
744
|
+
if (!existsSync(absolutePath))
|
|
745
|
+
continue;
|
|
746
|
+
authoringCopyIfExists(absolutePath, join(previewRoot, zone.path));
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function projectCompiledPreviewRuntime(previewCompiledPath, shellRoot) {
|
|
750
|
+
const targetRoot = join(shellRoot, "artifacts", "preview-runtime");
|
|
751
|
+
mkdirSync(targetRoot, { recursive: true });
|
|
752
|
+
const runtimeRoot = compiledRuntimeRoot(previewCompiledPath);
|
|
753
|
+
for (const artifactName of [
|
|
754
|
+
"run.json",
|
|
755
|
+
"state.json",
|
|
756
|
+
"health.json",
|
|
757
|
+
"view-spec.json",
|
|
758
|
+
"raw-snapshot.json",
|
|
759
|
+
"execution-shells",
|
|
760
|
+
"logs",
|
|
761
|
+
]) {
|
|
762
|
+
authoringCopyIfExists(join(runtimeRoot, artifactName), join(targetRoot, artifactName));
|
|
763
|
+
}
|
|
764
|
+
}
|
|
654
765
|
function improvementWorkflowDocsPath(compiledPath) {
|
|
655
766
|
return join(workflowPackagePathForCompiled(compiledPath), "improve");
|
|
656
767
|
}
|
|
768
|
+
export function createWorkflowAuthoringShell(options) {
|
|
769
|
+
const shellRoot = mkdtempSync(join(tmpdir(), `interf-workflow-author-${options.workflowId}-`));
|
|
770
|
+
mkdirSync(join(shellRoot, "runtime"), { recursive: true });
|
|
771
|
+
mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
|
|
772
|
+
mkdirSync(join(shellRoot, "logs"), { recursive: true });
|
|
773
|
+
const context = {
|
|
774
|
+
kind: "interf-workflow-authoring",
|
|
775
|
+
version: 1,
|
|
776
|
+
generated_at: new Date().toISOString(),
|
|
777
|
+
workflow_id: options.workflowId,
|
|
778
|
+
workflow_label: options.label,
|
|
779
|
+
seed_workflow_id: options.baseWorkflowId,
|
|
780
|
+
task_prompt: options.taskPrompt,
|
|
781
|
+
dataset: {
|
|
782
|
+
source_path: options.datasetPath,
|
|
783
|
+
checks: {
|
|
784
|
+
count: options.checks.length,
|
|
785
|
+
questions: options.checks.map((check, index) => ({
|
|
786
|
+
id: check.id ?? `check-${index + 1}`,
|
|
787
|
+
question: check.question,
|
|
788
|
+
})),
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
preview: options.preview
|
|
792
|
+
? {
|
|
793
|
+
prepared: true,
|
|
794
|
+
compile_ok: options.preview.compileResult.ok,
|
|
795
|
+
failed_stage: options.preview.compileResult.failedStage,
|
|
796
|
+
}
|
|
797
|
+
: {
|
|
798
|
+
prepared: false,
|
|
799
|
+
compile_ok: null,
|
|
800
|
+
failed_stage: null,
|
|
801
|
+
},
|
|
802
|
+
};
|
|
803
|
+
writeFileSync(join(shellRoot, "runtime", "authoring-context.json"), `${JSON.stringify(context, null, 2)}\n`);
|
|
804
|
+
projectRawSnapshot({
|
|
805
|
+
sourcePath: options.datasetPath,
|
|
806
|
+
destinationPath: join(shellRoot, "artifacts", "source-dataset", "raw"),
|
|
807
|
+
compiledPath: shellRoot,
|
|
808
|
+
mode: "copy",
|
|
809
|
+
prune: true,
|
|
810
|
+
preserveTimestamps: true,
|
|
811
|
+
});
|
|
812
|
+
if (options.preview) {
|
|
813
|
+
projectCompiledPreviewSnapshot(options.preview.compiledPath, shellRoot);
|
|
814
|
+
projectCompiledPreviewRuntime(options.preview.compiledPath, shellRoot);
|
|
815
|
+
}
|
|
816
|
+
linkPath(options.workflowPath, join(shellRoot, "workflow"));
|
|
817
|
+
writeNativeAgentSurface(shellRoot, renderWorkflowAuthoringAgents({
|
|
818
|
+
workflowId: options.workflowId,
|
|
819
|
+
label: options.label,
|
|
820
|
+
baseWorkflowId: options.baseWorkflowId,
|
|
821
|
+
}), "interf-workflow-author", renderWorkflowAuthoringSkill());
|
|
822
|
+
return {
|
|
823
|
+
rootPath: shellRoot,
|
|
824
|
+
workflowBeforePath: join(shellRoot, "artifacts", "workflow-before"),
|
|
825
|
+
workflowAfterPath: join(shellRoot, "artifacts", "workflow-after"),
|
|
826
|
+
promptLogPath: join(shellRoot, "logs", "workflow-author.prompt.txt"),
|
|
827
|
+
eventLogPath: join(shellRoot, "logs", "workflow-author.events.ndjson"),
|
|
828
|
+
statusLogPath: join(shellRoot, "logs", "workflow-author.status.log"),
|
|
829
|
+
};
|
|
830
|
+
}
|
|
657
831
|
function renderWorkflowImprovementAgents(compiledName, workflowId, loopIndex) {
|
|
658
832
|
return [
|
|
659
833
|
`# ${compiledName} — Workflow Improvement Shell`,
|
|
660
834
|
"",
|
|
661
|
-
"This is an automated workflow-improvement shell generated by Interf
|
|
835
|
+
"This is an automated workflow-improvement shell generated by Interf.",
|
|
662
836
|
"It exists to review failed compile/test runs and edit the workflow package for the next variation.",
|
|
663
837
|
"",
|
|
664
838
|
"## Start Here",
|
|
665
839
|
"",
|
|
666
840
|
"1. Read `runtime/loop-context.json` now.",
|
|
667
|
-
|
|
841
|
+
`2. Read \`workflow/README.md\`, \`workflow/workflow.json\`, and \`workflow/${WORKFLOW_SCHEMA_FILE}\` now.`,
|
|
668
842
|
"3. Read `workflow/improve/SKILL.md` now.",
|
|
669
843
|
"4. Use the local native `interf-workflow-improver` skill now.",
|
|
670
844
|
"",
|
|
@@ -675,7 +849,7 @@ function renderWorkflowImprovementAgents(compiledName, workflowId, loopIndex) {
|
|
|
675
849
|
"- Edit only files under `workflow/`.",
|
|
676
850
|
"- Do not edit truth checks, test specs, raw dataset files, or generated compiled outputs.",
|
|
677
851
|
"- Review compiled outputs under `artifacts/compiled-view/` and test/runtime evidence under `artifacts/`.",
|
|
678
|
-
"- Keep the workflow valid for the current compiler API and
|
|
852
|
+
"- Keep the workflow valid for the current compiler API and workflow schema.",
|
|
679
853
|
"",
|
|
680
854
|
"## Goal",
|
|
681
855
|
"",
|
|
@@ -696,11 +870,11 @@ function renderWorkflowImprovementSkill(workflowId, loopIndex, improvementDoc) {
|
|
|
696
870
|
"---",
|
|
697
871
|
"name: interf-workflow-improver",
|
|
698
872
|
"description: >",
|
|
699
|
-
" Native local workflow-improvement skill for this Interf
|
|
873
|
+
" Native local workflow-improvement skill for this Interf run.",
|
|
700
874
|
" Use it only inside an automated workflow-improvement shell.",
|
|
701
875
|
"---",
|
|
702
876
|
"",
|
|
703
|
-
`# Interf
|
|
877
|
+
`# Interf Workflow Improvement — ${workflowId}`,
|
|
704
878
|
"",
|
|
705
879
|
"This local native skill exists for automated workflow-improvement loops.",
|
|
706
880
|
"Read `runtime/loop-context.json` first.",
|
package/dist/lib/agents.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export type { Agent, AgentAutomationReadiness, AgentPreflightOptions, AgentPrefl
|
|
|
2
2
|
export { detectAgents, supportsAutomatedRuns, resolveAgent, } from "./agent-detection.js";
|
|
3
3
|
export { buildAgentPreflightPrompt, runAgentPreflight, ensureAgentAutomatedRunReady, } from "./agent-preflight.js";
|
|
4
4
|
export { spawnAgent, } from "./agent-execution.js";
|
|
5
|
-
export { buildAgentArgs } from "./agent-args.js";
|
|
5
|
+
export { buildAgentArgs, buildAgentEnv } from "./agent-args.js";
|
|
6
6
|
export { extractAgentFailureStatus, classifyTerminalVisibleStatus, hasAgentStalled, } from "./agent-status.js";
|
package/dist/lib/agents.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { detectAgents, supportsAutomatedRuns, resolveAgent, } from "./agent-detection.js";
|
|
2
2
|
export { buildAgentPreflightPrompt, runAgentPreflight, ensureAgentAutomatedRunReady, } from "./agent-preflight.js";
|
|
3
3
|
export { spawnAgent, } from "./agent-execution.js";
|
|
4
|
-
export { buildAgentArgs } from "./agent-args.js";
|
|
4
|
+
export { buildAgentArgs, buildAgentEnv } from "./agent-args.js";
|
|
5
5
|
export { extractAgentFailureStatus, classifyTerminalVisibleStatus, hasAgentStalled, } from "./agent-status.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { COMPILED_ZONE_KINDS, type CompiledZoneKind } from "./workflow-primitives.js";
|
|
2
|
+
export declare const BUILTIN_COMPILED_STAGE_IDS: {
|
|
3
|
+
readonly SUMMARIZE: "summarize";
|
|
4
|
+
readonly STRUCTURE: "structure";
|
|
5
|
+
readonly SHAPE: "shape";
|
|
6
|
+
};
|
|
7
|
+
export type BuiltinCompiledStageId = typeof BUILTIN_COMPILED_STAGE_IDS[keyof typeof BUILTIN_COMPILED_STAGE_IDS];
|
|
8
|
+
export declare const BUILTIN_COMPILED_ZONE_IDS: {
|
|
9
|
+
readonly RAW: "raw";
|
|
10
|
+
readonly SUMMARIES: "summaries";
|
|
11
|
+
readonly KNOWLEDGE_ENTITIES: "knowledge-entities";
|
|
12
|
+
readonly KNOWLEDGE_CLAIMS: "knowledge-claims";
|
|
13
|
+
readonly KNOWLEDGE_INDEXES: "knowledge-indexes";
|
|
14
|
+
readonly HOME: "home";
|
|
15
|
+
readonly RUNTIME: "runtime";
|
|
16
|
+
};
|
|
17
|
+
export type BuiltinCompiledZoneId = typeof BUILTIN_COMPILED_ZONE_IDS[keyof typeof BUILTIN_COMPILED_ZONE_IDS];
|
|
18
|
+
export interface BuiltinCompiledZoneSpec {
|
|
19
|
+
id: BuiltinCompiledZoneId;
|
|
20
|
+
role: "input" | "working" | "output" | "runtime";
|
|
21
|
+
path: string;
|
|
22
|
+
kind: CompiledZoneKind;
|
|
23
|
+
required: boolean;
|
|
24
|
+
description: string;
|
|
25
|
+
}
|
|
26
|
+
export interface BuiltinCompiledStageAccessPattern {
|
|
27
|
+
id: BuiltinCompiledStageId;
|
|
28
|
+
contract_type: string;
|
|
29
|
+
reads: BuiltinCompiledZoneId[];
|
|
30
|
+
writes: BuiltinCompiledZoneId[];
|
|
31
|
+
}
|
|
32
|
+
export declare function listBuiltinCompiledZoneSpecs(): BuiltinCompiledZoneSpec[];
|
|
33
|
+
export declare function listBuiltinCompiledFallbackStages(): BuiltinCompiledStageAccessPattern[];
|
|
34
|
+
export declare function requiredCompiledZoneOwners<TStage extends {
|
|
35
|
+
id: string;
|
|
36
|
+
writes: readonly string[];
|
|
37
|
+
}>(stages: readonly TStage[], zoneId: BuiltinCompiledZoneId): string[];
|
|
38
|
+
export { COMPILED_ZONE_KINDS };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { PACKAGE_ROOT } from "./config.js";
|
|
4
|
+
import { readJsonFileWithSchema } from "./parse.js";
|
|
5
|
+
import { WorkflowCompiledSchemaSchema } from "./schema.js";
|
|
6
|
+
import { COMPILED_ZONE_KINDS } from "./workflow-primitives.js";
|
|
7
|
+
export const BUILTIN_COMPILED_STAGE_IDS = {
|
|
8
|
+
SUMMARIZE: "summarize",
|
|
9
|
+
STRUCTURE: "structure",
|
|
10
|
+
SHAPE: "shape",
|
|
11
|
+
};
|
|
12
|
+
export const BUILTIN_COMPILED_ZONE_IDS = {
|
|
13
|
+
RAW: "raw",
|
|
14
|
+
SUMMARIES: "summaries",
|
|
15
|
+
KNOWLEDGE_ENTITIES: "knowledge-entities",
|
|
16
|
+
KNOWLEDGE_CLAIMS: "knowledge-claims",
|
|
17
|
+
KNOWLEDGE_INDEXES: "knowledge-indexes",
|
|
18
|
+
HOME: "home",
|
|
19
|
+
RUNTIME: "runtime",
|
|
20
|
+
};
|
|
21
|
+
const BUILTIN_ZONE_ID_SET = new Set(Object.values(BUILTIN_COMPILED_ZONE_IDS));
|
|
22
|
+
const BUILTIN_STAGE_ID_SET = new Set(Object.values(BUILTIN_COMPILED_STAGE_IDS));
|
|
23
|
+
const BuiltinWorkflowStageSchema = z.object({
|
|
24
|
+
id: z.string(),
|
|
25
|
+
contract_type: z.string(),
|
|
26
|
+
reads: z.array(z.string()).min(1),
|
|
27
|
+
writes: z.array(z.string()).min(1),
|
|
28
|
+
});
|
|
29
|
+
const BuiltinWorkflowPackageSchema = z.object({
|
|
30
|
+
stages: z.array(BuiltinWorkflowStageSchema).min(1),
|
|
31
|
+
});
|
|
32
|
+
let builtinCompiledContractCache = null;
|
|
33
|
+
function builtinWorkflowRootPath() {
|
|
34
|
+
return join(PACKAGE_ROOT, "builtin-workflows", "interf");
|
|
35
|
+
}
|
|
36
|
+
function builtinWorkflowPath(relativePath) {
|
|
37
|
+
return join(builtinWorkflowRootPath(), relativePath);
|
|
38
|
+
}
|
|
39
|
+
function assertBuiltinZoneId(value) {
|
|
40
|
+
if (!BUILTIN_ZONE_ID_SET.has(value)) {
|
|
41
|
+
throw new Error(`Built-in Interf workflow schema declares unsupported zone id "${value}".`);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function assertBuiltinStageId(value) {
|
|
46
|
+
if (!BUILTIN_STAGE_ID_SET.has(value)) {
|
|
47
|
+
throw new Error(`Built-in Interf workflow package declares unsupported stage id "${value}".`);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function loadBuiltinCompiledContract() {
|
|
52
|
+
if (builtinCompiledContractCache)
|
|
53
|
+
return builtinCompiledContractCache;
|
|
54
|
+
const schema = readJsonFileWithSchema(builtinWorkflowPath("workflow.schema.json"), "built-in Interf workflow schema", WorkflowCompiledSchemaSchema);
|
|
55
|
+
if (!schema) {
|
|
56
|
+
throw new Error(`Missing or invalid built-in workflow schema at ${builtinWorkflowPath("workflow.schema.json")}.`);
|
|
57
|
+
}
|
|
58
|
+
const workflow = readJsonFileWithSchema(builtinWorkflowPath("workflow.json"), "built-in Interf workflow package", BuiltinWorkflowPackageSchema);
|
|
59
|
+
if (!workflow) {
|
|
60
|
+
throw new Error(`Missing or invalid built-in workflow package at ${builtinWorkflowPath("workflow.json")}.`);
|
|
61
|
+
}
|
|
62
|
+
const zones = schema.zones.map((zone) => ({
|
|
63
|
+
id: assertBuiltinZoneId(zone.id),
|
|
64
|
+
role: zone.role,
|
|
65
|
+
path: zone.path,
|
|
66
|
+
kind: zone.kind,
|
|
67
|
+
required: zone.required,
|
|
68
|
+
description: zone.description,
|
|
69
|
+
}));
|
|
70
|
+
const stages = workflow.stages.map((stage) => ({
|
|
71
|
+
id: assertBuiltinStageId(stage.id),
|
|
72
|
+
contract_type: stage.contract_type,
|
|
73
|
+
reads: stage.reads.map(assertBuiltinZoneId),
|
|
74
|
+
writes: stage.writes.map(assertBuiltinZoneId),
|
|
75
|
+
}));
|
|
76
|
+
builtinCompiledContractCache = { zones, stages };
|
|
77
|
+
return builtinCompiledContractCache;
|
|
78
|
+
}
|
|
79
|
+
export function listBuiltinCompiledZoneSpecs() {
|
|
80
|
+
return loadBuiltinCompiledContract().zones.map((zone) => ({ ...zone }));
|
|
81
|
+
}
|
|
82
|
+
export function listBuiltinCompiledFallbackStages() {
|
|
83
|
+
return loadBuiltinCompiledContract().stages.map((stage) => ({
|
|
84
|
+
...stage,
|
|
85
|
+
reads: [...stage.reads],
|
|
86
|
+
writes: [...stage.writes],
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
export function requiredCompiledZoneOwners(stages, zoneId) {
|
|
90
|
+
return Array.from(new Set(stages
|
|
91
|
+
.filter((stage) => stage.writes.includes(zoneId))
|
|
92
|
+
.map((stage) => stage.id)));
|
|
93
|
+
}
|
|
94
|
+
export { COMPILED_ZONE_KINDS };
|
|
@@ -15,10 +15,6 @@ export interface CompiledCompileResult {
|
|
|
15
15
|
ok: boolean;
|
|
16
16
|
stageResults: Record<string, WorkflowStageResult>;
|
|
17
17
|
failedStage: string | null;
|
|
18
|
-
summarize: CompiledSummarizeResult | null;
|
|
19
|
-
structure: WorkflowStageResult | null;
|
|
20
|
-
shape: WorkflowStageResult | null;
|
|
21
|
-
compile: WorkflowStageResult | null;
|
|
22
18
|
}
|
|
23
19
|
export type StageShellRetentionMode = "on-failure" | "always";
|
|
24
20
|
export declare function resolveCompiledContext(compiledPath: string): {
|