@interf/compiler 0.6.3 → 0.6.5

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 (115) hide show
  1. package/README.md +92 -94
  2. package/dist/cli/commands/check-draft.js +4 -4
  3. package/dist/cli/commands/compile-controller.js +23 -23
  4. package/dist/cli/commands/compile.js +2 -2
  5. package/dist/cli/commands/compiled-flow.js +4 -4
  6. package/dist/cli/commands/create-workflow-wizard.js +8 -8
  7. package/dist/cli/commands/create.js +5 -5
  8. package/dist/cli/commands/default.js +1 -1
  9. package/dist/cli/commands/init.js +44 -44
  10. package/dist/cli/commands/list.js +2 -2
  11. package/dist/cli/commands/reset.js +1 -1
  12. package/dist/cli/commands/source-config-wizard.d.ts +1 -1
  13. package/dist/cli/commands/source-config-wizard.js +40 -40
  14. package/dist/cli/commands/status.js +5 -5
  15. package/dist/cli/commands/test-flow.js +26 -26
  16. package/dist/cli/commands/test.js +12 -12
  17. package/dist/lib/chart-guidance.d.ts +1 -1
  18. package/dist/lib/chart-guidance.js +1 -8
  19. package/dist/lib/discovery.d.ts +1 -7
  20. package/dist/lib/discovery.js +1 -84
  21. package/dist/lib/filesystem.d.ts +1 -2
  22. package/dist/lib/filesystem.js +1 -55
  23. package/dist/lib/logger.d.ts +1 -3
  24. package/dist/lib/logger.js +1 -10
  25. package/dist/lib/parse.d.ts +1 -8
  26. package/dist/lib/parse.js +1 -145
  27. package/dist/lib/util.d.ts +1 -4
  28. package/dist/lib/util.js +1 -25
  29. package/dist/packages/agents/index.d.ts +1 -0
  30. package/dist/packages/agents/index.js +1 -0
  31. package/dist/packages/agents/lib/chart-guidance.d.ts +1 -0
  32. package/dist/packages/agents/lib/chart-guidance.js +8 -0
  33. package/dist/packages/agents/lib/compiled-bootstrap.d.ts +3 -0
  34. package/dist/packages/agents/lib/compiled-bootstrap.js +18 -0
  35. package/dist/packages/agents/lib/executors.d.ts +2 -2
  36. package/dist/packages/agents/lib/shells.d.ts +3 -1
  37. package/dist/packages/agents/lib/shells.js +22 -20
  38. package/dist/packages/agents/lib/user-config.js +1 -1
  39. package/dist/packages/compiler/compiled-compile.d.ts +4 -48
  40. package/dist/packages/compiler/compiled-compile.js +4 -256
  41. package/dist/packages/compiler/compiled-paths.d.ts +40 -0
  42. package/dist/packages/compiler/compiled-paths.js +106 -0
  43. package/dist/packages/compiler/compiled-pipeline.d.ts +39 -0
  44. package/dist/packages/compiler/compiled-pipeline.js +134 -0
  45. package/dist/packages/compiler/compiled-schema.js +2 -2
  46. package/dist/packages/compiler/compiled-stage-plan.d.ts +15 -0
  47. package/dist/packages/compiler/compiled-stage-plan.js +79 -0
  48. package/dist/packages/compiler/compiled-stage-runner.d.ts +10 -0
  49. package/dist/packages/compiler/compiled-stage-runner.js +46 -0
  50. package/dist/packages/compiler/compiled-target.d.ts +11 -0
  51. package/dist/packages/compiler/compiled-target.js +16 -0
  52. package/dist/packages/compiler/discovery.d.ts +7 -0
  53. package/dist/packages/compiler/discovery.js +80 -0
  54. package/dist/packages/compiler/lib/schema.js +2 -0
  55. package/dist/packages/compiler/raw-snapshot.d.ts +49 -0
  56. package/dist/packages/compiler/raw-snapshot.js +102 -0
  57. package/dist/packages/compiler/reset.d.ts +2 -0
  58. package/dist/packages/compiler/reset.js +72 -0
  59. package/dist/packages/compiler/runtime-acceptance.js +3 -3
  60. package/dist/packages/compiler/runtime-contracts.js +1 -1
  61. package/dist/packages/compiler/runtime-paths.js +1 -1
  62. package/dist/packages/compiler/runtime-reconcile.js +3 -3
  63. package/dist/packages/compiler/runtime-runs.js +2 -2
  64. package/dist/packages/compiler/state-health.js +3 -3
  65. package/dist/packages/compiler/state-io.js +3 -3
  66. package/dist/packages/compiler/state-paths.js +1 -1
  67. package/dist/packages/compiler/state-view.js +2 -2
  68. package/dist/packages/compiler/validate-compiled.js +3 -3
  69. package/dist/packages/compiler/validate.js +4 -4
  70. package/dist/packages/project-model/compiled-paths.d.ts +1 -40
  71. package/dist/packages/project-model/compiled-paths.js +1 -106
  72. package/dist/packages/project-model/compiled-raw.d.ts +1 -49
  73. package/dist/packages/project-model/compiled-raw.js +1 -102
  74. package/dist/packages/project-model/compiled-reset.d.ts +1 -2
  75. package/dist/packages/project-model/compiled-reset.js +1 -72
  76. package/dist/packages/project-model/interf-bootstrap.d.ts +1 -3
  77. package/dist/packages/project-model/interf-bootstrap.js +1 -18
  78. package/dist/packages/project-model/interf-detect.js +4 -4
  79. package/dist/packages/project-model/interf-scaffold.js +7 -7
  80. package/dist/packages/project-model/source-config.js +6 -5
  81. package/dist/packages/shared/file-types.d.ts +1 -0
  82. package/dist/packages/shared/file-types.js +4 -0
  83. package/dist/packages/shared/filesystem.d.ts +2 -0
  84. package/dist/packages/shared/filesystem.js +55 -0
  85. package/dist/packages/shared/index.d.ts +7 -0
  86. package/dist/packages/shared/index.js +7 -0
  87. package/dist/packages/shared/logger.d.ts +3 -0
  88. package/dist/packages/shared/logger.js +10 -0
  89. package/dist/packages/shared/naming.d.ts +1 -0
  90. package/dist/packages/shared/naming.js +8 -0
  91. package/dist/packages/shared/parse.d.ts +8 -0
  92. package/dist/packages/shared/parse.js +145 -0
  93. package/dist/packages/shared/path-guards.d.ts +2 -0
  94. package/dist/packages/shared/path-guards.js +14 -0
  95. package/dist/packages/shared/util.d.ts +3 -0
  96. package/dist/packages/shared/util.js +3 -0
  97. package/dist/packages/testing/test-execution.js +3 -3
  98. package/dist/packages/testing/test-paths.js +1 -1
  99. package/dist/packages/testing/test-sandbox.js +3 -3
  100. package/dist/packages/testing/test-specs.js +1 -1
  101. package/dist/packages/workflow-authoring/workflow-authoring.js +5 -4
  102. package/dist/packages/workflow-authoring/workflow-improvement.js +6 -5
  103. package/dist/packages/workflow-package/builtin-compiled-workflow.js +1 -1
  104. package/dist/packages/workflow-package/context-interface.d.ts +96 -0
  105. package/dist/packages/workflow-package/context-interface.js +146 -0
  106. package/dist/packages/workflow-package/index.d.ts +2 -0
  107. package/dist/packages/workflow-package/index.js +2 -0
  108. package/dist/packages/workflow-package/interf-workflow-package.js +75 -28
  109. package/dist/packages/workflow-package/local-workflows.d.ts +5 -2
  110. package/dist/packages/workflow-package/local-workflows.js +15 -13
  111. package/dist/packages/workflow-package/workflow-definitions.d.ts +11 -7
  112. package/dist/packages/workflow-package/workflow-definitions.js +10 -3
  113. package/dist/packages/workflow-package/workflow-helpers.js +4 -4
  114. package/dist/packages/workflow-package/workflow-review-paths.js +1 -1
  115. package/package.json +3 -2
@@ -0,0 +1,3 @@
1
+ import { renderClaudeBootstrap } from "./shells.js";
2
+ export { renderClaudeBootstrap };
3
+ export declare function refreshCompiledBootstrapGuidance(dirPath: string): boolean;
@@ -0,0 +1,18 @@
1
+ import { basename } from "node:path";
2
+ import { readInterfConfig } from "../../project-model/interf-detect.js";
3
+ import { projectCompiledQueryShell, renderClaudeBootstrap } from "./shells.js";
4
+ export { renderClaudeBootstrap };
5
+ export function refreshCompiledBootstrapGuidance(dirPath) {
6
+ const config = readInterfConfig(dirPath);
7
+ if (!config)
8
+ return false;
9
+ const compiledName = config.name ?? basename(dirPath);
10
+ const workflowId = config.workflow ?? "interf";
11
+ const workflowOriginSelected = config.workflow_origin?.selected ?? workflowId;
12
+ const workflowLocalDraft = config.workflow_origin?.local_draft === true;
13
+ const about = typeof config.about === "string" && config.about.length > 0 ? config.about : undefined;
14
+ return projectCompiledQueryShell(dirPath, compiledName, workflowId, about, {
15
+ workflowOriginSelected,
16
+ workflowLocalDraft,
17
+ });
18
+ }
@@ -1,4 +1,4 @@
1
- import type { RuntimeExecutorInfo } from "../../../lib/schema.js";
1
+ import type { RuntimeExecutorInfo } from "../../compiler/lib/schema.js";
2
2
  import type { Agent } from "./types.js";
3
3
  export type WorkflowExecutorKind = "local-agent" | "connected-provider" | "managed";
4
4
  export interface WorkflowExecutionProfile {
@@ -20,7 +20,7 @@ export interface WorkflowExecutor {
20
20
  executionProfile?: WorkflowExecutionProfile;
21
21
  execute(rootPath: string, prompt: string, options?: WorkflowExecuteOptions): Promise<number>;
22
22
  }
23
- export type { RuntimeExecutorInfo } from "../../../lib/schema.js";
23
+ export type { RuntimeExecutorInfo } from "../../compiler/lib/schema.js";
24
24
  export declare function buildRuntimeExecutorInfo(executor: WorkflowExecutor): RuntimeExecutorInfo;
25
25
  export declare function createLocalAgentExecutor(agent: Agent, executionProfile?: WorkflowExecutionProfile): WorkflowExecutor;
26
26
  export declare function resolveLocalExecutor(options?: {
@@ -1,4 +1,6 @@
1
- import type { RuntimeContractType, SourceTruthCheck, WorkflowImprovementContext, WorkflowZoneId } from "../../../lib/schema.js";
1
+ import type { RuntimeContractType, WorkflowImprovementContext } from "../../compiler/lib/schema.js";
2
+ import type { SourceTruthCheck } from "../../project-model/lib/schema.js";
3
+ import { type ContextInterfaceZoneId as WorkflowZoneId } from "../../workflow-package/context-interface.js";
2
4
  export interface NativeStageDefinition {
3
5
  id: string;
4
6
  label: string;
@@ -1,12 +1,13 @@
1
1
  import { cpSync, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, symlinkSync, } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
3
  import { basename, dirname, join, relative } from "node:path";
4
- import { CHART_APPROXIMATION_NOTES } from "../../../lib/chart-guidance.js";
5
- import { projectRawSnapshot } from "../../../lib/compiled-raw.js";
6
- import { WORKFLOW_PACKAGE_DIR } from "../../../lib/interf-detect.js";
7
- import { WORKFLOW_SCHEMA_FILE, ensureCompiledZoneTargets, readCompiledSchemaFile, compiledZoneAbsolutePath, resolveWorkflowSchemaPath, } from "../../../lib/compiled-schema.js";
8
- import { stageExecutionShellsRoot, workflowImprovementLoopRoot, workflowPackagePathForCompiled, compiledInterfConfigPath, compiledRuntimeRoot, } from "../../../lib/compiled-paths.js";
9
- import { listFilesRecursive } from "../../../lib/filesystem.js";
4
+ import { CHART_APPROXIMATION_NOTES } from "./chart-guidance.js";
5
+ import { projectRawSnapshot } from "../../compiler/raw-snapshot.js";
6
+ import { WORKFLOW_PACKAGE_DIR } from "../../project-model/interf-detect.js";
7
+ import { CONTEXT_INTERFACE_FILE as WORKFLOW_SCHEMA_FILE, contextInterfaceZoneAbsolutePath as compiledZoneAbsolutePath, readContextInterface as readCompiledSchemaFile, resolveContextInterfacePath as resolveWorkflowSchemaPath, } from "../../workflow-package/context-interface.js";
8
+ import { stageExecutionShellsRoot, workflowImprovementLoopRoot, workflowPackagePathForCompiled, compiledInterfConfigPath, compiledRuntimeRoot, } from "../../compiler/compiled-paths.js";
9
+ import { ensureCompiledZoneTargets } from "../../compiler/compiled-schema.js";
10
+ import { listFilesRecursive } from "../../shared/filesystem.js";
10
11
  import { resolveWorkflowImprovementReviewSourcePaths } from "../../workflow-package/workflow-review-paths.js";
11
12
  const LOCAL_SKILL_ROOTS = [
12
13
  ".claude/skills",
@@ -40,8 +41,8 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
40
41
  return [
41
42
  `# ${name}`,
42
43
  "",
43
- "This is a context folder built by Interf.",
44
- "Technically, it is the compiled context for this dataset entry: a file-based task context layer on top of the raw files, prepared for agents to navigate, retrieve evidence, and reach source-backed answers more reliably.",
44
+ "This is portable context built by Interf.",
45
+ "Technically, it is the compiled context for this dataset entry: a file-based context layer on top of the raw files, prepared for agents to navigate, retrieve evidence, and answer more reliably from the source files.",
45
46
  "",
46
47
  ...(about
47
48
  ? [
@@ -49,22 +50,23 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
49
50
  "",
50
51
  ]
51
52
  : []),
52
- "## How to use this context folder",
53
+ "## How to use this portable context",
53
54
  "",
54
- "1. Use the local native `interf-query` skill that Interf generated for this context folder.",
55
+ "1. Use the local native `interf-query` skill that Interf generated for this portable context.",
55
56
  "2. Let the workflow docs and declared output zones guide retrieval instead of assuming a fixed note layout.",
56
57
  "3. Use `raw/` when you need direct quotes, exact chart values, table lookups, or verification.",
57
58
  "",
58
59
  "## How this compiled context works",
59
60
  "",
61
+ "- The workflow package defines the context interface this compiled context implements on disk.",
60
62
  "- `.interf/interf.json` points to the local `raw/` snapshot via `source.path` and back to the project root via `source.control_path`.",
61
63
  `- Workflow seed: \`${workflowOriginSelected}\`.`,
62
64
  ...(workflowLocalDraft
63
- ? ["- This compiled context now carries a local workflow draft improved from that seed. Recompiling this context folder reuses the local `.interf/workflow/` package."]
65
+ ? ["- This compiled context now carries a local workflow draft improved from that seed. Recompiling this portable context reuses the local `.interf/workflow/` package."]
64
66
  : []),
65
67
  `- Active local workflow id: \`${workflowId}\`.`,
66
68
  "- `.interf/workflow/` is the local editable method package for this compiled context.",
67
- `- \`.interf/workflow/${WORKFLOW_SCHEMA_FILE}\` is the deterministic zone contract for this compiled context.`,
69
+ `- \`.interf/workflow/${WORKFLOW_SCHEMA_FILE}\` is the deterministic context interface for this compiled context.`,
68
70
  "- `.interf/workflow/improve/` is the editable source for workflow-improvement loops.",
69
71
  "- `.interf/workflow/use/query/` is the editable source for the generated native query shell.",
70
72
  "- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf projects into native execution shells for automated runs.",
@@ -87,8 +89,8 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
87
89
  "## Commands",
88
90
  "",
89
91
  "```",
90
- "interf compile build this context folder",
91
- "interf test run checks against this context folder",
92
+ "interf compile build this portable context",
93
+ "interf test run checks against this portable context",
92
94
  "interf verify stage <id> verify one workflow stage",
93
95
  "interf verify compiled verify the full compiled context output",
94
96
  "interf status show deterministic health",
@@ -97,7 +99,7 @@ export function renderCompiledAgents(compiledPath, name, workflowId, about, opti
97
99
  "## Rules",
98
100
  "",
99
101
  "- Do not modify files under `raw/`.",
100
- "- Treat compiled notes as working task context artifacts, not final truth.",
102
+ "- Treat compiled notes as working context artifacts, not final truth.",
101
103
  "- When confidence is low, verify against `raw/` before answering strongly.",
102
104
  "",
103
105
  ].join("\n");
@@ -121,7 +123,7 @@ export function renderCompiledQuerySkill() {
121
123
  "- do not invent navigation or note structure beyond what this workflow declares",
122
124
  "- when the compiled context is insufficient, verify in `raw/` and then answer",
123
125
  "",
124
- "You can edit this file to bias manual question-answering behavior for this context folder.",
126
+ "You can edit this file to bias manual question-answering behavior for this portable context.",
125
127
  "",
126
128
  ].join("\n");
127
129
  }
@@ -396,7 +398,7 @@ function renderCompiledQueryNativeSkill(querySkillContent) {
396
398
  "---",
397
399
  "name: interf-query",
398
400
  "description: >",
399
- " Native local query skill for this context folder built by Interf",
401
+ " Native local query skill for this portable context built by Interf",
400
402
  " Compiler. Use it for manual questions against the compiled context",
401
403
  " and its raw fallback.",
402
404
  "---",
@@ -404,7 +406,7 @@ function renderCompiledQueryNativeSkill(querySkillContent) {
404
406
  "# Interf Query",
405
407
  "",
406
408
  "This is the native local query skill for a compiled context built by Interf.",
407
- "Use it when reading this context folder manually.",
409
+ "Use it when reading this portable context manually.",
408
410
  "Editable source: `.interf/workflow/use/query/SKILL.md`.",
409
411
  "",
410
412
  querySkillContent.trim(),
@@ -687,7 +689,7 @@ function renderWorkflowAuthoringAgents(options) {
687
689
  "## Goal",
688
690
  "",
689
691
  "- produce one standalone workflow tuned to the files and checks in this task",
690
- "- preserve deterministic stage and zone contracts",
692
+ "- preserve deterministic stage and context-interface contracts",
691
693
  "- stop once the workflow edits are complete",
692
694
  "",
693
695
  ].join("\n");
@@ -853,7 +855,7 @@ function renderWorkflowImprovementAgents(compiledName, workflowId, loopIndex) {
853
855
  "",
854
856
  "## Goal",
855
857
  "",
856
- "- create a better workflow variation for this task",
858
+ "- create a better workflow variation for this kind of work",
857
859
  "- preserve deterministic compiled-context structure",
858
860
  "- stop after the workflow edits are complete",
859
861
  "",
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
- import { readJsonFileWithSchema } from "../../../lib/parse.js";
4
+ import { readJsonFileWithSchema } from "../../shared/parse.js";
5
5
  import { InterfUserConfigSchema } from "./schema.js";
6
6
  export const INTERF_HOME = join(homedir(), ".interf");
7
7
  export const USER_CONFIG_PATH = join(INTERF_HOME, "config.json");
@@ -1,48 +1,4 @@
1
- import { type WorkflowExecutor } from "../agents/lib/executors.js";
2
- import { type CompiledWorkflowId, type WorkflowStageDefinition } from "../workflow-package/workflow-definitions.js";
3
- import { type WorkflowReporter, type WorkflowStageResult } from "../workflow-package/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
- }
19
- export type StageShellRetentionMode = "on-failure" | "always";
20
- export declare function resolveCompiledContext(compiledPath: string): {
21
- compiledName: string;
22
- sourcePath: string;
23
- controlPath: string;
24
- workflowId: CompiledWorkflowId;
25
- };
26
- export declare function compiledExecutionStages(workflowId: CompiledWorkflowId, compiledPath: string): CompiledStageExecutionDefinition[];
27
- export declare function runCompiledSummarize(options: {
28
- executor: WorkflowExecutor;
29
- compiledPath: string;
30
- reporter?: WorkflowReporter;
31
- reportSummary?: boolean;
32
- reportStep?: boolean;
33
- stageDefinition?: CompiledStageExecutionDefinition;
34
- fullPass?: boolean;
35
- }): Promise<CompiledSummarizeResult>;
36
- export declare function runCompiledCompile(options: {
37
- executor: WorkflowExecutor;
38
- compiledPath: string;
39
- reporter?: WorkflowReporter;
40
- reportStep?: boolean;
41
- preserveStageShells?: StageShellRetentionMode;
42
- }): Promise<WorkflowStageResult>;
43
- export declare function compileCompiled(options: {
44
- executor: WorkflowExecutor;
45
- compiledPath: string;
46
- reporter?: WorkflowReporter;
47
- preserveStageShells?: StageShellRetentionMode;
48
- }): Promise<CompiledCompileResult>;
1
+ export * from "./compiled-target.js";
2
+ export * from "./compiled-stage-plan.js";
3
+ export * from "./compiled-stage-runner.js";
4
+ export * from "./compiled-pipeline.js";
@@ -1,256 +1,4 @@
1
- import { join } from "node:path";
2
- import { createStageExecutionShell, freezeStageExecutionShell, pruneStageExecutionShells, syncStageExecutionShellWrites, } from "../agents/lib/shells.js";
3
- import { readInterfConfig, resolveSourceFolderPath, resolveSourceControlPath, resolveSourceInputPath, } from "../project-model/interf-detect.js";
4
- import { refreshCompiledBootstrapGuidance, } from "../project-model/interf-bootstrap.js";
5
- import { reconcileCompiledStageRun, } from "./runtime-reconcile.js";
6
- import { refreshCompiledArtifacts, } from "./state.js";
7
- import { buildRuntimeStageContract, } from "./runtime.js";
8
- import { validateWorkflowPackage } from "../workflow-package/local-workflows.js";
9
- import { formatActiveCompiledWorkflowStageStep, getActiveCompiledStagePolicyNotes, getActiveCompiledWorkflow, resolveRequiredCompiledWorkflowFromConfig, resolveActiveCompiledStageAcceptance, } from "../workflow-package/workflow-definitions.js";
10
- import { validateCompiledStage, validateCompiledWorkflow, } from "./validate.js";
11
- import { buildLocalSkillContractExtension, buildStageInstructions, reportBlankLine, reportLine, reportValidationFailure, workflowCompileStageDirectory, } from "../workflow-package/workflow-helpers.js";
12
- import { executeValidatedStage, } from "../workflow-package/workflow-stage-runner.js";
13
- import { syncCompiledRawSnapshot } from "../project-model/compiled-raw.js";
14
- import { workflowPackagePathForCompiled, } from "../project-model/compiled-paths.js";
15
- import { compiledContractArtifactPathsForZoneIds, findCompiledSchemaZone, readCompiledSchemaFile, } from "./compiled-schema.js";
16
- import { discoverSourceFiles } from "../../lib/discovery.js";
17
- import { listFilesRecursive } from "../../lib/filesystem.js";
18
- export function resolveCompiledContext(compiledPath) {
19
- const config = readInterfConfig(compiledPath);
20
- const workflowId = resolveRequiredCompiledWorkflowFromConfig(config, `.interf/interf.json for ${compiledPath}`);
21
- return {
22
- compiledName: config?.name ?? "compiled",
23
- sourcePath: resolveSourceFolderPath(compiledPath, config),
24
- controlPath: resolveSourceControlPath(compiledPath),
25
- workflowId,
26
- };
27
- }
28
- export function compiledExecutionStages(workflowId, compiledPath) {
29
- return getActiveCompiledWorkflow(compiledPath, workflowId)
30
- .stages;
31
- }
32
- function zoneArtifactCount(compiledPath, zonePath, kind) {
33
- const absolutePath = join(compiledPath, zonePath);
34
- try {
35
- if (kind === "file") {
36
- return listFilesRecursive(absolutePath).length > 0 ? 1 : 0;
37
- }
38
- }
39
- catch {
40
- if (kind === "file")
41
- return 0;
42
- }
43
- return listFilesRecursive(absolutePath).length;
44
- }
45
- function resolveStageContractArtifacts(compiledPath, stageDefinition) {
46
- const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
47
- if (!schema) {
48
- throw new Error(`Missing workflow schema for stage "${stageDefinition.id}" at ${workflowPackagePathForCompiled(compiledPath)}.`);
49
- }
50
- return {
51
- reads: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.reads),
52
- writes: compiledContractArtifactPathsForZoneIds(schema, stageDefinition.writes),
53
- };
54
- }
55
- function buildStageCounts(compiledPath, stageDefinition) {
56
- const context = resolveCompiledContext(compiledPath);
57
- const sourceTotal = discoverSourceFiles(context.sourcePath, compiledPath).totalCount;
58
- const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
59
- const zoneCounts = {};
60
- if (schema) {
61
- for (const zoneId of new Set([...stageDefinition.reads, ...stageDefinition.writes])) {
62
- const zone = findCompiledSchemaZone(schema, zoneId);
63
- if (!zone)
64
- continue;
65
- zoneCounts[zoneId] = zoneArtifactCount(compiledPath, zone.path, zone.kind);
66
- }
67
- }
68
- return {
69
- source_total: sourceTotal,
70
- read_zone_total: stageDefinition.reads.length,
71
- write_zone_total: stageDefinition.writes.length,
72
- ...zoneCounts,
73
- };
74
- }
75
- function buildStageContract(compiledPath, workflowId, stageDefinition) {
76
- const config = readInterfConfig(compiledPath);
77
- const localSkills = buildLocalSkillContractExtension(compiledPath, [workflowCompileStageDirectory(stageDefinition.skillDir)], "Use them to refine this workflow stage while still honoring the declared reads, writes, and proof rules.");
78
- const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
79
- const stageArtifacts = resolveStageContractArtifacts(compiledPath, stageDefinition);
80
- return buildRuntimeStageContract({
81
- compiledName: config?.name ?? "compiled",
82
- stageId: stageDefinition.id,
83
- stageLabel: stageDefinition.label,
84
- counts: buildStageCounts(compiledPath, stageDefinition),
85
- stageReadArtifacts: stageArtifacts.reads,
86
- stageWriteArtifacts: stageArtifacts.writes,
87
- workflowNotes: getActiveCompiledStagePolicyNotes(compiledPath, workflowId, stageDefinition.id),
88
- localSkillDocs: localSkills.reads,
89
- instructions,
90
- acceptance: resolveActiveCompiledStageAcceptance(compiledPath, workflowId, stageDefinition.id),
91
- });
92
- }
93
- async function runCompiledStage(options) {
94
- const context = resolveCompiledContext(options.compiledPath);
95
- const stageDefinition = options.stageDefinition;
96
- const contract = buildStageContract(options.compiledPath, context.workflowId, stageDefinition);
97
- 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.");
98
- const instructions = buildStageInstructions(stageDefinition.skillDir, localSkills);
99
- if (options.reportStep !== false) {
100
- reportBlankLine(options.reporter);
101
- reportLine(options.reporter, `${formatActiveCompiledWorkflowStageStep(options.compiledPath, context.workflowId, stageDefinition.id)} (${stageDefinition.description.toLowerCase()})`);
102
- }
103
- const shell = createStageExecutionShell(options.compiledPath, context.compiledName, context.workflowId, stageDefinition, contract.artifacts.writes);
104
- try {
105
- return await executeValidatedStage({
106
- executor: options.executor,
107
- compiledPath: options.compiledPath,
108
- executionPath: shell.rootPath,
109
- targetName: context.compiledName,
110
- workflow: context.workflowId,
111
- workflowSourcePath: options.compiledPath,
112
- stageDefinition,
113
- instructions,
114
- summary: `Executing ${stageDefinition.label.toLowerCase()}.`,
115
- contract,
116
- statusLines: [
117
- `Emit exactly one startup line: STATUS: loaded ${stageDefinition.label.toLowerCase()} stage.`,
118
- "Emit STATUS: reading declared inputs after you confirm the shell contract and local docs.",
119
- "Emit STATUS: writing declared outputs after the stage starts updating the compiled zones.",
120
- `Emit DONE: ${stageDefinition.id} complete when the declared outputs and proof are on disk.`,
121
- ],
122
- reporter: options.reporter,
123
- completionCheck: () => validateCompiledStage(options.compiledPath, stageDefinition.id).ok,
124
- syncWrites: () => syncStageExecutionShellWrites(options.compiledPath, shell.rootPath, stageDefinition, contract.artifacts.writes),
125
- reconcile: () => reconcileCompiledStageRun(options.compiledPath, stageDefinition),
126
- refreshArtifacts: () => refreshCompiledArtifacts(options.compiledPath, { ensureViewSpec: true }),
127
- validate: () => validateCompiledStage(options.compiledPath, stageDefinition.id),
128
- });
129
- }
130
- finally {
131
- freezeStageExecutionShell(shell.rootPath);
132
- }
133
- }
134
- export async function runCompiledSummarize(options) {
135
- const context = resolveCompiledContext(options.compiledPath);
136
- const stageDefinition = options.stageDefinition
137
- ?? compiledExecutionStages(context.workflowId, options.compiledPath).find((stage) => stage.id === "summarize");
138
- if (!stageDefinition) {
139
- return {
140
- ok: false,
141
- code: 1,
142
- skipped: true,
143
- plan: { sourceCount: 0, summaryCount: 0, targetCount: 0 },
144
- summary: "Workflow does not declare a summarize stage.",
145
- };
146
- }
147
- const sourceCount = discoverSourceFiles(context.sourcePath, options.compiledPath).totalCount;
148
- const result = await runCompiledStage({
149
- executor: options.executor,
150
- compiledPath: options.compiledPath,
151
- reporter: options.reporter,
152
- reportStep: options.reportStep,
153
- stageDefinition,
154
- });
155
- return {
156
- ...result,
157
- skipped: false,
158
- plan: {
159
- sourceCount,
160
- summaryCount: 0,
161
- targetCount: sourceCount,
162
- },
163
- };
164
- }
165
- export async function runCompiledCompile(options) {
166
- const preserveMode = options.preserveStageShells ?? "on-failure";
167
- if (preserveMode !== "always") {
168
- pruneStageExecutionShells(options.compiledPath);
169
- }
170
- let lastResult = { ok: true, code: 0 };
171
- try {
172
- const context = resolveCompiledContext(options.compiledPath);
173
- for (const stageDefinition of compiledExecutionStages(context.workflowId, options.compiledPath)) {
174
- const result = await runCompiledStage({
175
- executor: options.executor,
176
- compiledPath: options.compiledPath,
177
- reporter: options.reporter,
178
- reportStep: options.reportStep,
179
- stageDefinition,
180
- });
181
- lastResult = result;
182
- if (!result.ok)
183
- return result;
184
- }
185
- return lastResult;
186
- }
187
- finally {
188
- if (preserveMode !== "always" && lastResult.ok) {
189
- pruneStageExecutionShells(options.compiledPath);
190
- }
191
- }
192
- }
193
- export async function compileCompiled(options) {
194
- const preserveMode = options.preserveStageShells ?? "on-failure";
195
- if (preserveMode !== "always") {
196
- pruneStageExecutionShells(options.compiledPath);
197
- }
198
- let result = {
199
- ok: true,
200
- stageResults: {},
201
- failedStage: null,
202
- };
203
- try {
204
- const sourceInputPath = resolveSourceInputPath(options.compiledPath);
205
- syncCompiledRawSnapshot(options.compiledPath, sourceInputPath);
206
- refreshCompiledBootstrapGuidance(options.compiledPath);
207
- const workflowValidation = validateWorkflowPackage(join(options.compiledPath, ".interf", "workflow"));
208
- if (!workflowValidation.ok) {
209
- reportValidationFailure(options.reporter, workflowValidation.summary, workflowValidation.errors);
210
- return {
211
- ...result,
212
- ok: false,
213
- failedStage: "workflow",
214
- stageResults: {
215
- ...result.stageResults,
216
- workflow: {
217
- ok: false,
218
- code: 1,
219
- summary: workflowValidation.summary,
220
- },
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 (!stageResult.ok) {
236
- result.ok = false;
237
- result.failedStage = stageDefinition.id;
238
- return result;
239
- }
240
- }
241
- const workflowValidationResult = validateCompiledWorkflow(options.compiledPath);
242
- result.ok = workflowValidationResult.ok;
243
- result.failedStage = workflowValidationResult.ok ? null : workflowValidationResult.stage;
244
- result.stageResults.compiled = {
245
- ok: workflowValidationResult.ok,
246
- code: workflowValidationResult.ok ? 0 : 1,
247
- summary: workflowValidationResult.summary,
248
- };
249
- return result;
250
- }
251
- finally {
252
- if (preserveMode !== "always" && result.ok) {
253
- pruneStageExecutionShells(options.compiledPath);
254
- }
255
- }
256
- }
1
+ export * from "./compiled-target.js";
2
+ export * from "./compiled-stage-plan.js";
3
+ export * from "./compiled-stage-runner.js";
4
+ export * from "./compiled-pipeline.js";
@@ -0,0 +1,40 @@
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 testTargetsRootForCompiled(compiledPath: string): string;
22
+ export declare function stageExecutionShellsRoot(compiledPath: string): string;
23
+ export declare function workflowImprovementLoopsRoot(compiledPath: string): string;
24
+ export declare function workflowImprovementRunRoot(compiledPath: string, runId: string): string;
25
+ export declare function workflowImprovementLoopRoot(compiledPath: string, runId: string, loopIndex: number): string;
26
+ export declare function targetTestRunsRootForCompiled(compiledPath: string): string;
27
+ export declare function targetTestSandboxesRootForCompiled(compiledPath: string): string;
28
+ export declare function compiledRuntimeLogsRoot(compiledPath: string): string;
29
+ export declare function compiledRuntimeArchivedStageContractPath(compiledPath: string, runId: string): string;
30
+ export declare function compiledQueryAcceptanceRoot(compiledPath: string): string;
31
+ export declare function compiledRuntimeStatePath(compiledPath: string): string;
32
+ export declare function compiledRuntimeHealthPath(compiledPath: string): string;
33
+ export declare function compiledRuntimeViewSpecPath(compiledPath: string): string;
34
+ export declare function compiledRawSnapshotMetadataPath(compiledPath: string): string;
35
+ export declare function compiledRuntimeInventoryPath(compiledPath: string): string;
36
+ export declare function compiledRuntimeRunPath(compiledPath: string): string;
37
+ export declare function compiledRuntimeRunHistoryPath(compiledPath: string): string;
38
+ export declare function compiledRuntimeStageContractPath(compiledPath: string): string;
39
+ export declare function resolveSourceControlPathForCompiled(compiledPath: string): string;
40
+ export declare function defaultControlPathForCompiled(compiledPath: string): string;
@@ -0,0 +1,106 @@
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 testTargetsRootForCompiled(compiledPath) {
35
+ return join(testRootForCompiled(compiledPath), COMPILED_TEST_TARGETS_DIR);
36
+ }
37
+ export function stageExecutionShellsRoot(compiledPath) {
38
+ return join(compiledRuntimeRoot(compiledPath), "execution-shells");
39
+ }
40
+ export function workflowImprovementLoopsRoot(compiledPath) {
41
+ return join(compiledRuntimeRoot(compiledPath), "improvement-loops");
42
+ }
43
+ export function workflowImprovementRunRoot(compiledPath, runId) {
44
+ return join(workflowImprovementLoopsRoot(compiledPath), runId);
45
+ }
46
+ export function workflowImprovementLoopRoot(compiledPath, runId, loopIndex) {
47
+ return join(workflowImprovementRunRoot(compiledPath, runId), `loop-${String(loopIndex).padStart(2, "0")}`);
48
+ }
49
+ export function targetTestRunsRootForCompiled(compiledPath) {
50
+ return join(testTargetsRootForCompiled(compiledPath), "runs");
51
+ }
52
+ export function targetTestSandboxesRootForCompiled(compiledPath) {
53
+ return join(testTargetsRootForCompiled(compiledPath), "sandboxes");
54
+ }
55
+ export function compiledRuntimeLogsRoot(compiledPath) {
56
+ return join(compiledRuntimeRoot(compiledPath), "logs");
57
+ }
58
+ export function compiledRuntimeArchivedStageContractPath(compiledPath, runId) {
59
+ return join(compiledRuntimeLogsRoot(compiledPath), `${runId}.stage-contract.json`);
60
+ }
61
+ export function compiledQueryAcceptanceRoot(compiledPath) {
62
+ return join(compiledRuntimeRoot(compiledPath), "query-acceptance");
63
+ }
64
+ export function compiledRuntimeStatePath(compiledPath) {
65
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_STATE_FILE);
66
+ }
67
+ export function compiledRuntimeHealthPath(compiledPath) {
68
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_HEALTH_FILE);
69
+ }
70
+ export function compiledRuntimeViewSpecPath(compiledPath) {
71
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_VIEW_SPEC_FILE);
72
+ }
73
+ export function compiledRawSnapshotMetadataPath(compiledPath) {
74
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RAW_SNAPSHOT_FILE);
75
+ }
76
+ export function compiledRuntimeInventoryPath(compiledPath) {
77
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_INVENTORY_FILE);
78
+ }
79
+ export function compiledRuntimeRunPath(compiledPath) {
80
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RUN_FILE);
81
+ }
82
+ export function compiledRuntimeRunHistoryPath(compiledPath) {
83
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_RUN_HISTORY_FILE);
84
+ }
85
+ export function compiledRuntimeStageContractPath(compiledPath) {
86
+ return compiledRuntimeFilePath(compiledPath, COMPILED_RUNTIME_STAGE_CONTRACT_FILE);
87
+ }
88
+ export function resolveSourceControlPathForCompiled(compiledPath) {
89
+ let cursor = resolve(compiledPath);
90
+ while (true) {
91
+ const parent = dirname(cursor);
92
+ if (basename(parent) === "interf" &&
93
+ basename(cursor) !== "tests" &&
94
+ basename(cursor) !== "workflows") {
95
+ return dirname(parent);
96
+ }
97
+ if (parent === cursor)
98
+ break;
99
+ cursor = parent;
100
+ }
101
+ throw new Error(`Context folder is not under the canonical project layout: ${compiledPath}`);
102
+ }
103
+ export function defaultControlPathForCompiled(compiledPath) {
104
+ const relativePath = relative(compiledPath, resolveSourceControlPathForCompiled(compiledPath));
105
+ return relativePath.length > 0 ? relativePath.split(sep).join("/") : ".";
106
+ }