@interf/compiler 0.33.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +122 -226
  2. package/dist/cli/commands/agents.js +1 -32
  3. package/dist/cli/commands/benchmark.d.ts +2 -3
  4. package/dist/cli/commands/benchmark.js +1 -31
  5. package/dist/cli/commands/build-plan.js +26 -50
  6. package/dist/cli/commands/build.d.ts +2 -3
  7. package/dist/cli/commands/build.js +1 -31
  8. package/dist/cli/commands/graphs.js +177 -32
  9. package/dist/cli/commands/mcp.d.ts +1 -0
  10. package/dist/cli/commands/mcp.js +223 -126
  11. package/dist/cli/commands/project.js +10 -36
  12. package/dist/cli/commands/reset.d.ts +2 -3
  13. package/dist/cli/commands/reset.js +1 -22
  14. package/dist/cli/commands/runs.js +86 -33
  15. package/dist/cli/commands/status.js +3 -24
  16. package/dist/cli/commands/traces.js +1 -29
  17. package/dist/cli/commands/wizard.js +17 -29
  18. package/dist/cli/lib/http-client.d.ts +39 -0
  19. package/dist/cli/lib/http-client.js +73 -0
  20. package/dist/packages/build-plans/authoring/brief.d.ts +25 -4
  21. package/dist/packages/build-plans/authoring/build-plan-authoring.d.ts +42 -1
  22. package/dist/packages/build-plans/authoring/build-plan-authoring.js +470 -63
  23. package/dist/packages/build-plans/authoring/build-plan-edit-session.d.ts +9 -0
  24. package/dist/packages/build-plans/authoring/build-plan-edit-session.js +27 -10
  25. package/dist/packages/build-plans/authoring/build-plan-improvement.js +62 -8
  26. package/dist/packages/build-plans/authoring/lib/build-plan-edit-utils.d.ts +1 -0
  27. package/dist/packages/build-plans/package/build-plan-definitions.d.ts +0 -1
  28. package/dist/packages/build-plans/package/build-plan-definitions.js +5 -3
  29. package/dist/packages/build-plans/package/build-plan-stage-runner.d.ts +1 -0
  30. package/dist/packages/build-plans/package/build-plan-stage-runner.js +2 -1
  31. package/dist/packages/build-plans/package/builtin-build-plan.d.ts +2 -2
  32. package/dist/packages/build-plans/package/builtin-build-plan.js +3 -3
  33. package/dist/packages/build-plans/package/context-interface.d.ts +3 -0
  34. package/dist/packages/build-plans/package/context-interface.js +5 -5
  35. package/dist/packages/build-plans/package/interf-build-plan-package.js +22 -22
  36. package/dist/packages/build-plans/package/local-build-plans.d.ts +10 -5
  37. package/dist/packages/build-plans/package/local-build-plans.js +57 -32
  38. package/dist/packages/contracts/index.d.ts +4 -3
  39. package/dist/packages/contracts/index.js +2 -1
  40. package/dist/packages/contracts/lib/context-graph-layer.d.ts +161 -0
  41. package/dist/packages/contracts/lib/context-graph-layer.js +216 -0
  42. package/dist/packages/contracts/lib/project-paths.d.ts +7 -0
  43. package/dist/packages/contracts/lib/project-paths.js +9 -0
  44. package/dist/packages/contracts/lib/project-schema.d.ts +264 -1
  45. package/dist/packages/contracts/lib/project-schema.js +38 -13
  46. package/dist/packages/contracts/lib/schema.d.ts +556 -23
  47. package/dist/packages/contracts/lib/schema.js +279 -18
  48. package/dist/packages/contracts/utils/filesystem.d.ts +1 -0
  49. package/dist/packages/contracts/utils/filesystem.js +29 -1
  50. package/dist/packages/projects/lib/schema.d.ts +6 -8
  51. package/dist/packages/projects/lib/schema.js +3 -1
  52. package/dist/packages/projects/source-config.d.ts +0 -5
  53. package/dist/packages/projects/source-config.js +9 -22
  54. package/dist/packages/runtime/actions/fields.d.ts +4 -0
  55. package/dist/packages/runtime/actions/form-builders.js +79 -31
  56. package/dist/packages/runtime/actions/form-validators.js +9 -3
  57. package/dist/packages/runtime/actions/helpers.js +3 -3
  58. package/dist/packages/runtime/actions/registry.d.ts +1 -1
  59. package/dist/packages/runtime/actions/registry.js +1 -1
  60. package/dist/packages/runtime/actions/requests.d.ts +1 -1
  61. package/dist/packages/runtime/actions/requests.js +12 -6
  62. package/dist/packages/runtime/actions/schemas.d.ts +7 -0
  63. package/dist/packages/runtime/actions/schemas.js +1 -0
  64. package/dist/packages/runtime/agent-handoff.js +8 -7
  65. package/dist/packages/runtime/agents/lib/execution-profile.d.ts +14 -0
  66. package/dist/packages/runtime/agents/lib/execution-profile.js +23 -0
  67. package/dist/packages/runtime/agents/lib/execution.js +14 -8
  68. package/dist/packages/runtime/agents/lib/executors.d.ts +1 -0
  69. package/dist/packages/runtime/agents/lib/executors.js +11 -2
  70. package/dist/packages/runtime/agents/lib/logs.d.ts +10 -0
  71. package/dist/packages/runtime/agents/lib/logs.js +32 -8
  72. package/dist/packages/runtime/agents/lib/preflight.js +4 -1
  73. package/dist/packages/runtime/agents/lib/render.d.ts +18 -0
  74. package/dist/packages/runtime/agents/lib/render.js +44 -18
  75. package/dist/packages/runtime/agents/lib/shell-templates.js +105 -63
  76. package/dist/packages/runtime/agents/lib/shells.d.ts +29 -0
  77. package/dist/packages/runtime/agents/lib/shells.js +158 -32
  78. package/dist/packages/runtime/agents/lib/source-context-scan.d.ts +10 -0
  79. package/dist/packages/runtime/agents/lib/source-context-scan.js +388 -0
  80. package/dist/packages/runtime/agents/lib/status.js +1 -14
  81. package/dist/packages/runtime/agents/lib/string-utils.d.ts +16 -0
  82. package/dist/packages/runtime/agents/lib/string-utils.js +36 -0
  83. package/dist/packages/runtime/agents/lib/types.d.ts +1 -0
  84. package/dist/packages/runtime/agents/providers/codex.js +2 -0
  85. package/dist/packages/runtime/agents/role-executors.js +2 -1
  86. package/dist/packages/runtime/auth/session-store.js +11 -3
  87. package/dist/packages/runtime/benchmark-question-draft.d.ts +3 -0
  88. package/dist/packages/runtime/benchmark-question-draft.js +57 -28
  89. package/dist/packages/runtime/build/artifact-status.d.ts +1 -1
  90. package/dist/packages/runtime/build/artifact-status.js +1 -1
  91. package/dist/packages/runtime/build/build-evidence.d.ts +2 -1
  92. package/dist/packages/runtime/build/build-evidence.js +11 -5
  93. package/dist/packages/runtime/build/build-pipeline.js +89 -5
  94. package/dist/packages/runtime/build/build-stage-plan.js +3 -1
  95. package/dist/packages/runtime/build/build-stage-runner.js +169 -32
  96. package/dist/packages/runtime/build/build-target.d.ts +3 -0
  97. package/dist/packages/runtime/build/build-target.js +25 -1
  98. package/dist/packages/runtime/build/check-evaluator.d.ts +1 -1
  99. package/dist/packages/runtime/build/check-evaluator.js +655 -4
  100. package/dist/packages/runtime/build/context-graph-paths.d.ts +13 -0
  101. package/dist/packages/runtime/build/context-graph-paths.js +27 -0
  102. package/dist/packages/runtime/build/index.d.ts +2 -2
  103. package/dist/packages/runtime/build/index.js +2 -2
  104. package/dist/packages/runtime/build/inspect-map.d.ts +10 -0
  105. package/dist/packages/runtime/build/inspect-map.js +270 -0
  106. package/dist/packages/runtime/build/lib/schema.d.ts +246 -53
  107. package/dist/packages/runtime/build/lib/schema.js +173 -15
  108. package/dist/packages/runtime/build/native-entrypoint.d.ts +2 -0
  109. package/dist/packages/runtime/build/native-entrypoint.js +286 -0
  110. package/dist/packages/runtime/build/runtime-contracts.js +9 -3
  111. package/dist/packages/runtime/build/runtime-log-paths.d.ts +3 -0
  112. package/dist/packages/runtime/build/runtime-log-paths.js +16 -0
  113. package/dist/packages/runtime/build/runtime-prompt.js +6 -4
  114. package/dist/packages/runtime/build/runtime-runs.js +63 -10
  115. package/dist/packages/runtime/build/runtime-types.d.ts +4 -1
  116. package/dist/packages/runtime/build/runtime.d.ts +3 -1
  117. package/dist/packages/runtime/build/runtime.js +3 -1
  118. package/dist/packages/runtime/build/source-files.js +11 -2
  119. package/dist/packages/runtime/build/source-inventory.d.ts +1 -0
  120. package/dist/packages/runtime/build/source-inventory.js +246 -7
  121. package/dist/packages/runtime/build/source-manifest.d.ts +11 -0
  122. package/dist/packages/runtime/build/source-manifest.js +30 -2
  123. package/dist/packages/runtime/build/stage-evidence.js +80 -11
  124. package/dist/packages/runtime/build/stage-manifest.d.ts +45 -0
  125. package/dist/packages/runtime/build/stage-manifest.js +1125 -0
  126. package/dist/packages/runtime/build/stage-reuse.js +12 -0
  127. package/dist/packages/runtime/build/stage-session.d.ts +81 -0
  128. package/dist/packages/runtime/build/stage-session.js +308 -0
  129. package/dist/packages/runtime/build/state-io.js +10 -11
  130. package/dist/packages/runtime/build/state-view.js +1 -1
  131. package/dist/packages/runtime/build/state.d.ts +1 -1
  132. package/dist/packages/runtime/build/state.js +1 -1
  133. package/dist/packages/runtime/build/summary-coverage-index.d.ts +21 -0
  134. package/dist/packages/runtime/build/summary-coverage-index.js +189 -0
  135. package/dist/packages/runtime/build/traces.js +3 -3
  136. package/dist/packages/runtime/build/validate-context-graph.d.ts +1 -1
  137. package/dist/packages/runtime/build/validate-context-graph.js +5 -5
  138. package/dist/packages/runtime/build/validate.d.ts +1 -1
  139. package/dist/packages/runtime/build/validate.js +1 -1
  140. package/dist/packages/runtime/client.d.ts +3 -3
  141. package/dist/packages/runtime/client.js +8 -13
  142. package/dist/packages/runtime/context-checks.js +13 -0
  143. package/dist/packages/runtime/context-graph-scaffold.js +2 -1
  144. package/dist/packages/runtime/context-graph-semantic-graph.d.ts +9 -0
  145. package/dist/packages/runtime/context-graph-semantic-graph.js +416 -0
  146. package/dist/packages/runtime/execution/lib/schema.d.ts +34 -31
  147. package/dist/packages/runtime/index.d.ts +2 -2
  148. package/dist/packages/runtime/index.js +1 -1
  149. package/dist/packages/runtime/native-run-handlers.d.ts +38 -0
  150. package/dist/packages/runtime/native-run-handlers.js +52 -33
  151. package/dist/packages/runtime/plan-artifact-contract.js +1 -1
  152. package/dist/packages/runtime/project-source-state.d.ts +4 -4
  153. package/dist/packages/runtime/project-source-state.js +5 -2
  154. package/dist/packages/runtime/project-store.d.ts +5 -0
  155. package/dist/packages/runtime/project-store.js +30 -3
  156. package/dist/packages/runtime/requested-artifacts.js +1 -1
  157. package/dist/packages/runtime/run-observability.js +9 -4
  158. package/dist/packages/runtime/runtime-action-proposals.js +3 -3
  159. package/dist/packages/runtime/runtime-build-plans.js +47 -3
  160. package/dist/packages/runtime/runtime-build-runs.js +9 -16
  161. package/dist/packages/runtime/runtime-caches.d.ts +26 -0
  162. package/dist/packages/runtime/runtime-caches.js +47 -0
  163. package/dist/packages/runtime/runtime-jobs.js +6 -6
  164. package/dist/packages/runtime/runtime-project-mutations.js +1 -0
  165. package/dist/packages/runtime/runtime-project-reads.d.ts +4 -1
  166. package/dist/packages/runtime/runtime-project-reads.js +229 -36
  167. package/dist/packages/runtime/runtime-proposal-helpers.js +6 -6
  168. package/dist/packages/runtime/runtime-resource-builders.d.ts +4 -2
  169. package/dist/packages/runtime/runtime-resource-builders.js +16 -14
  170. package/dist/packages/runtime/runtime-status.d.ts +14 -0
  171. package/dist/packages/runtime/runtime-status.js +15 -0
  172. package/dist/packages/runtime/runtime-verify-runs.js +6 -5
  173. package/dist/packages/runtime/runtime.d.ts +439 -22
  174. package/dist/packages/runtime/runtime.js +16 -2
  175. package/dist/packages/runtime/schemas/actions.d.ts +24 -0
  176. package/dist/packages/runtime/schemas/agents.d.ts +28 -0
  177. package/dist/packages/runtime/schemas/agents.js +33 -0
  178. package/dist/packages/runtime/schemas/build-plans.d.ts +181 -8
  179. package/dist/packages/runtime/schemas/build-plans.js +36 -2
  180. package/dist/packages/runtime/schemas/context-graphs.d.ts +1522 -0
  181. package/dist/packages/runtime/schemas/context-graphs.js +110 -0
  182. package/dist/packages/runtime/schemas/files.d.ts +7 -347
  183. package/dist/packages/runtime/schemas/files.js +1 -24
  184. package/dist/packages/runtime/schemas/index.d.ts +1 -0
  185. package/dist/packages/runtime/schemas/index.js +1 -0
  186. package/dist/packages/runtime/schemas/jobs.js +4 -0
  187. package/dist/packages/runtime/schemas/projects.d.ts +48 -21
  188. package/dist/packages/runtime/schemas/projects.js +34 -10
  189. package/dist/packages/runtime/schemas/runs.d.ts +1009 -240
  190. package/dist/packages/runtime/schemas/runs.js +17 -0
  191. package/dist/packages/runtime/service/openapi.js +1 -0
  192. package/dist/packages/runtime/service/operations.d.ts +1666 -145
  193. package/dist/packages/runtime/service/operations.js +147 -17
  194. package/dist/packages/runtime/service/routes.d.ts +11 -3
  195. package/dist/packages/runtime/service/routes.js +11 -3
  196. package/dist/packages/runtime/service/server-app-boot.js +2 -2
  197. package/dist/packages/runtime/service/server-helpers.d.ts +11 -0
  198. package/dist/packages/runtime/service/server-helpers.js +19 -0
  199. package/dist/packages/runtime/service/server-routes-action-proposals.js +4 -2
  200. package/dist/packages/runtime/service/server-routes-agents.js +19 -85
  201. package/dist/packages/runtime/service/server-routes-build-plans.js +14 -11
  202. package/dist/packages/runtime/service/server-routes-project-context.js +102 -7
  203. package/dist/packages/runtime/service/server-routes-project-jobs.js +19 -12
  204. package/dist/packages/runtime/service/server-routes-project-runs.js +5 -2
  205. package/dist/packages/runtime/service/server-routes-projects.js +6 -2
  206. package/dist/packages/runtime/service/server-routes-runs.js +11 -4
  207. package/dist/packages/runtime/verify/lib/schema.js +12 -0
  208. package/dist/packages/runtime/verify/test-file-guard.d.ts +2 -0
  209. package/dist/packages/runtime/verify/test-file-guard.js +29 -0
  210. package/dist/packages/runtime/verify/verify-execution.d.ts +7 -0
  211. package/dist/packages/runtime/verify/verify-execution.js +109 -35
  212. package/dist/packages/runtime/verify/verify-paths.d.ts +1 -0
  213. package/dist/packages/runtime/verify/verify-paths.js +4 -0
  214. package/dist/packages/runtime/verify/verify-specs.js +49 -39
  215. package/dist/packages/runtime/wire-schemas.d.ts +1 -1
  216. package/dist/packages/runtime/wire-schemas.js +1 -1
  217. package/package.json +2 -8
  218. package/public-repo/CONTRIBUTING.md +10 -3
  219. package/public-repo/README.md +122 -226
  220. package/public-repo/build-plans/interf-default/README.md +15 -12
  221. package/public-repo/build-plans/interf-default/build/stages/entrypoint/SKILL.md +74 -0
  222. package/public-repo/build-plans/interf-default/build/stages/knowledge/SKILL.md +95 -0
  223. package/public-repo/build-plans/interf-default/build/stages/summarize/SKILL.md +38 -5
  224. package/public-repo/build-plans/interf-default/build-plan.json +27 -23
  225. package/public-repo/build-plans/interf-default/build-plan.schema.json +24 -20
  226. package/public-repo/build-plans/interf-default/use/query/SKILL.md +8 -7
  227. package/public-repo/openapi/local-service.openapi.json +11637 -4213
  228. package/public-repo/skills/interf/SKILL.md +174 -134
  229. package/dist/packages/runtime/build/runtime-paths.d.ts +0 -8
  230. package/dist/packages/runtime/build/runtime-paths.js +0 -26
  231. package/dist/packages/runtime/build/state-paths.d.ts +0 -7
  232. package/dist/packages/runtime/build/state-paths.js +0 -22
  233. package/public-repo/build-plans/interf-default/build/stages/shape/SKILL.md +0 -34
  234. package/public-repo/build-plans/interf-default/build/stages/structure/SKILL.md +0 -28
@@ -14,6 +14,31 @@ export declare function validateStageExecutionShellInputs(options: {
14
14
  summary: string;
15
15
  };
16
16
  export declare function writeNativeAgentSurface(rootPath: string, agentsContent: string, skillName: string, skillContent: string): boolean;
17
+ /**
18
+ * One data-driven shell constructor shared by every agent job (stage execution,
19
+ * Build Plan authoring, Build Plan improvement). The shared skeleton lives here
20
+ * exactly once: create the shell root, create the requested subdirectories, and
21
+ * write the native agent surface (AGENTS.md / CLAUDE.md / SKILL.md) the agent
22
+ * boots from. Job-specific projection (runtime inputs, source locators, build
23
+ * plan trees, artifact mounts) stays in each caller — `createAgentShell` only
24
+ * owns the skeleton, so a reader traces shell setup through one function instead
25
+ * of three near-identical ones.
26
+ *
27
+ * `rootPath` is resolved by the caller (the three job kinds keep their distinct
28
+ * storage roots: stage shells under the Context Graph, improvement loops under
29
+ * the loop root, authoring shells under the Project's service job storage).
30
+ */
31
+ export declare function createAgentShell(options: {
32
+ rootPath: string;
33
+ subdirs: readonly string[];
34
+ nativeSurface: {
35
+ agentsContent: string;
36
+ skillName: string;
37
+ skillContent: string;
38
+ };
39
+ }): {
40
+ rootPath: string;
41
+ };
17
42
  export declare function pruneStageExecutionShells(contextGraphPath: string): void;
18
43
  export declare function projectContextGraphQueryShell(contextGraphPath: string, contextGraphName: string, buildPlanId: string, options?: {
19
44
  buildPlanOriginSelected?: string | null;
@@ -36,6 +61,7 @@ export declare function createBuildPlanAuthoringShell(options: {
36
61
  requestedArtifacts?: RequestedArtifact[];
37
62
  sourceContext?: SourceContext | null;
38
63
  artifactRequirements?: BuildPlanAuthoringArtifactRequirement[];
64
+ shellRoot?: string;
39
65
  }): {
40
66
  rootPath: string;
41
67
  buildPlanBeforePath: string;
@@ -43,7 +69,9 @@ export declare function createBuildPlanAuthoringShell(options: {
43
69
  promptLogPath: string;
44
70
  eventLogPath: string;
45
71
  statusLogPath: string;
72
+ reasoningLogPath: string;
46
73
  };
74
+ export declare function freezeBuildPlanAuthoringShell(rootPath: string): string | null;
47
75
  export declare function createBuildPlanImprovementShell(options: {
48
76
  contextGraphPath: string;
49
77
  contextGraphName: string;
@@ -59,5 +87,6 @@ export declare function createBuildPlanImprovementShell(options: {
59
87
  promptLogPath: string;
60
88
  eventLogPath: string;
61
89
  statusLogPath: string;
90
+ reasoningLogPath: string;
62
91
  };
63
92
  export declare function freezeBuildPlanImprovementShell(rootPath: string): string | null;
@@ -2,12 +2,14 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
2
2
  import { tmpdir } from "node:os";
3
3
  import { join, relative, resolve } from "node:path";
4
4
  import { buildShellSourceState, loadBuildStageInputs, loadContextGraphSourceManifest, loadContextGraphSourceState, } from "../../build/source-manifest.js";
5
+ import { writeStageExpectedInputs, } from "../../build/stage-manifest.js";
6
+ import { resolveBuildContext, } from "../../build/build-target.js";
5
7
  import { CHECK_PARAM_CONTRACTS, CHECK_KINDS, SourceManifestSchema, StageInputsSchema, } from "../../../contracts/lib/schema.js";
6
- import { stageExecutionShellsRoot, buildPlanImprovementLoopRoot, buildPlanPackagePathForContextGraph, contextGraphInterfConfigPath, contextGraphRuntimeSourceManifestPath, contextGraphRuntimeRoot, } from "../../build/context-graph-paths.js";
8
+ import { stageExecutionShellsRoot, buildPlanImprovementLoopRoot, buildPlanPackagePathForContextGraph, contextGraphInterfConfigPath, contextGraphRuntimeSourceManifestPath, contextGraphRuntimeStageExpectedInputsPath, contextGraphRuntimeRoot, } from "../../build/context-graph-paths.js";
7
9
  import { writeFileAtomic, writeJsonAtomic } from "../../build/atomic-fs.js";
8
10
  import { resolveBuildPlanImprovementReviewSourcePaths } from "../../../build-plans/package/build-plan-review-paths.js";
9
11
  import { copyIfExists, copyResolvedTree, freezePreservedShell, writeIfChanged, writeNativeSkillCopies, } from "./shell-fs.js";
10
- import { shellLogsPath, shellRuntimePath, } from "./shell-paths.js";
12
+ import { shellRuntimePath, } from "./shell-paths.js";
11
13
  import { writeStageExecutionWorkspaceManifest, } from "./shell-workspace.js";
12
14
  import { readBuildPlanImprovementDoc, readContextGraphQuerySkillSource, renderBuildPlanAuthoringAgents, renderBuildPlanAuthoringSkill, renderBuildPlanImprovementAgents, renderBuildPlanImprovementSkill, renderClaudeBootstrap, renderSourceFilesTestAgents, renderSourceFilesTestQuerySkill, renderStageExecutionAgents, renderStageExecutionSkill, renderContextGraphAgents, renderContextGraphQueryNativeSkill, renderContextGraphQuerySkill, } from "./shell-templates.js";
13
15
  import { buildStageArtifactMounts, ensureBuildExecutionSurface, projectBuildPlanMetadata, projectStageArtifactMountAliases, projectContextGraphReviewArtifactsState, projectContextGraphRuntimeArtifacts, projectContextGraphSchemaArtifacts, readStageBuildPlanDoc, stageMaterializedArtifactSet, syncStageExecutionShellWrites, writeExecutionShellPathsFile, } from "./shell-projection.js";
@@ -97,6 +99,28 @@ export function writeNativeAgentSurface(rootPath, agentsContent, skillName, skil
97
99
  changed = writeNativeSkillCopies(rootPath, skillName, skillContent) || changed;
98
100
  return changed;
99
101
  }
102
+ /**
103
+ * One data-driven shell constructor shared by every agent job (stage execution,
104
+ * Build Plan authoring, Build Plan improvement). The shared skeleton lives here
105
+ * exactly once: create the shell root, create the requested subdirectories, and
106
+ * write the native agent surface (AGENTS.md / CLAUDE.md / SKILL.md) the agent
107
+ * boots from. Job-specific projection (runtime inputs, source locators, build
108
+ * plan trees, artifact mounts) stays in each caller — `createAgentShell` only
109
+ * owns the skeleton, so a reader traces shell setup through one function instead
110
+ * of three near-identical ones.
111
+ *
112
+ * `rootPath` is resolved by the caller (the three job kinds keep their distinct
113
+ * storage roots: stage shells under the Context Graph, improvement loops under
114
+ * the loop root, authoring shells under the Project's service job storage).
115
+ */
116
+ export function createAgentShell(options) {
117
+ mkdirSync(options.rootPath, { recursive: true });
118
+ for (const subdir of options.subdirs) {
119
+ mkdirSync(join(options.rootPath, subdir), { recursive: true });
120
+ }
121
+ writeNativeAgentSurface(options.rootPath, options.nativeSurface.agentsContent, options.nativeSurface.skillName, options.nativeSurface.skillContent);
122
+ return { rootPath: options.rootPath };
123
+ }
100
124
  export function pruneStageExecutionShells(contextGraphPath) {
101
125
  rmSync(stageExecutionShellsRoot(contextGraphPath), { recursive: true, force: true });
102
126
  }
@@ -113,13 +137,15 @@ export function createStageExecutionShell(contextGraphPath, contextGraphName, bu
113
137
  const materializedArtifacts = stageMaterializedArtifactSet(schema, stage, writeArtifacts);
114
138
  const cleanWriteArtifacts = new Set(stage.writes.filter((artifactId) => !stage.reads.includes(artifactId)));
115
139
  const shellsRoot = stageExecutionShellsRoot(contextGraphPath);
116
- const shellRoot = join(shellsRoot, `${stage.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`);
117
- mkdirSync(shellRoot, { recursive: true });
118
- mkdirSync(join(shellRoot, "runtime"), { recursive: true });
119
- mkdirSync(join(shellRoot, ".interf", "runtime"), { recursive: true });
120
- mkdirSync(join(shellRoot, "inputs"), { recursive: true });
121
- mkdirSync(join(shellRoot, "outputs"), { recursive: true });
122
- mkdirSync(shellLogsPath(shellRoot), { recursive: true });
140
+ const { rootPath: shellRoot } = createAgentShell({
141
+ rootPath: join(shellsRoot, `${stage.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`),
142
+ subdirs: ["runtime", join(".interf", "runtime"), "inputs", "outputs", "logs"],
143
+ nativeSurface: {
144
+ agentsContent: renderStageExecutionAgents(contextGraphName, buildPlanId, stage),
145
+ skillName: "interf-stage",
146
+ skillContent: renderStageExecutionSkill(stage, readStageBuildPlanDoc(contextGraphPath, stage)),
147
+ },
148
+ });
123
149
  copyResolvedTree({
124
150
  sourcePath: contextGraphInterfConfigPath(contextGraphPath),
125
151
  targetPath: join(shellRoot, "interf.json"),
@@ -129,6 +155,17 @@ export function createStageExecutionShell(contextGraphPath, contextGraphName, bu
129
155
  const sourceState = loadContextGraphSourceState(contextGraphPath);
130
156
  const stageInputs = loadBuildStageInputs(contextGraphPath, stage.id);
131
157
  const sourceManifest = loadContextGraphSourceManifest(contextGraphPath);
158
+ if (!existsSync(contextGraphRuntimeStageExpectedInputsPath(contextGraphPath, stage.id))) {
159
+ writeStageExpectedInputs({ contextGraphPath, stage });
160
+ }
161
+ const buildContext = resolveBuildContext(contextGraphPath);
162
+ writeJsonAtomic(shellRuntimePath(shellRoot, "project.json"), {
163
+ kind: "interf-stage-project-context",
164
+ version: 1,
165
+ project: buildContext.project,
166
+ build_plan: buildPlanId,
167
+ stage: stage.id,
168
+ });
132
169
  if (sourceManifest) {
133
170
  writeJsonAtomic(shellRuntimePath(shellRoot, "source-manifest.json"), sourceManifest);
134
171
  copyIfExists(contextGraphRuntimeSourceManifestPath(contextGraphPath), join(shellRoot, ".interf", "runtime", "source-manifest.json"), "stage-execution");
@@ -137,13 +174,12 @@ export function createStageExecutionShell(contextGraphPath, contextGraphName, bu
137
174
  writeJsonAtomic(shellRuntimePath(shellRoot, "stage-inputs.json"), stageInputs);
138
175
  writeJsonAtomic(shellRuntimePath(shellRoot, "source-state.json"), buildShellSourceState(sourceState, stageInputs));
139
176
  }
177
+ copyIfExists(contextGraphRuntimeStageExpectedInputsPath(contextGraphPath, stage.id), shellRuntimePath(shellRoot, "expected-inputs.json"), "stage-execution");
140
178
  writeStageSelfCheckScript(shellRoot);
141
179
  projectContextGraphSchemaArtifacts(contextGraphPath, shellRoot, schema, new Set([...stage.reads, ...stage.writes]), materializedArtifacts, cleanWriteArtifacts);
142
180
  projectBuildPlanMetadata(contextGraphPath, shellRoot, stage);
143
181
  projectStageArtifactMountAliases(shellRoot, stage, schema);
144
182
  writeExecutionShellPathsFile(shellRoot, buildPlanId, stage, buildStageArtifactMounts(contextGraphPath, shellRoot, stage, schema));
145
- const agentsContent = renderStageExecutionAgents(contextGraphName, buildPlanId, stage);
146
- writeNativeAgentSurface(shellRoot, agentsContent, "interf-stage", renderStageExecutionSkill(stage, readStageBuildPlanDoc(contextGraphPath, stage)));
147
183
  writeStageExecutionWorkspaceManifest({
148
184
  contextGraphPath,
149
185
  shellRoot,
@@ -166,7 +202,7 @@ function writeStageSelfCheckScript(shellRoot) {
166
202
  "",
167
203
  `const { evaluateChecks } = await import(${JSON.stringify(checkEvaluatorModuleUrl)});`,
168
204
  `const { RuntimeStageContractSchema } = await import(${JSON.stringify(runtimeSchemaModuleUrl)});`,
169
- `const { SourceManifestSchema, StageEvidenceSchema, StageInputsSchema } = await import(${JSON.stringify(contractsSchemaModuleUrl)});`,
205
+ `const { ResourceRefSchema, ReviewedInputSchema, SourceManifestSchema, StageEvidenceSchema, StageInputsSchema } = await import(${JSON.stringify(contractsSchemaModuleUrl)});`,
170
206
  "",
171
207
  "const shellRoot = resolve(dirname(fileURLToPath(import.meta.url)), \"..\");",
172
208
  "const contractPath = resolve(shellRoot, \"runtime\", \"stage-contract.json\");",
@@ -174,6 +210,7 @@ function writeStageSelfCheckScript(shellRoot) {
174
210
  "const artifactResults = [];",
175
211
  "const evidenceFailures = [];",
176
212
  "const inputFailures = [];",
213
+ "const coverageFailures = [];",
177
214
  "const stageInputsPath = resolve(shellRoot, \"runtime\", \"stage-inputs.json\");",
178
215
  "",
179
216
  "if (!existsSync(stageInputsPath)) {",
@@ -198,6 +235,62 @@ function writeStageSelfCheckScript(shellRoot) {
198
235
  " }",
199
236
  "}",
200
237
  "",
238
+ "const expectedInputsPath = resolve(shellRoot, \"runtime\", \"expected-inputs.json\");",
239
+ "const reviewedInputsPath = resolve(shellRoot, \"runtime\", \"reviewed-inputs.json\");",
240
+ "let expectedInputs = [];",
241
+ "if (!existsSync(expectedInputsPath)) {",
242
+ " coverageFailures.push(\"runtime/expected-inputs.json was not written.\");",
243
+ "} else {",
244
+ " try {",
245
+ " const file = JSON.parse(readFileSync(expectedInputsPath, \"utf8\"));",
246
+ " if (file.kind !== \"interf-stage-expected-inputs\" || file.stage_id !== contract.stage) {",
247
+ " coverageFailures.push(`expected inputs file is not for stage ${contract.stage}.`);",
248
+ " }",
249
+ " expectedInputs = Array.isArray(file.expected)",
250
+ " ? file.expected.map((entry) => ResourceRefSchema.parse(entry))",
251
+ " : [];",
252
+ " if (!Array.isArray(file.expected)) {",
253
+ " coverageFailures.push(\"expected inputs file must contain an expected array.\");",
254
+ " }",
255
+ " } catch (error) {",
256
+ " coverageFailures.push(`expected inputs JSON is invalid: ${error instanceof Error ? error.message : String(error)}`);",
257
+ " }",
258
+ "}",
259
+ "",
260
+ "if (!existsSync(reviewedInputsPath)) {",
261
+ " coverageFailures.push(\"runtime/reviewed-inputs.json was not written.\");",
262
+ "} else {",
263
+ " try {",
264
+ " const file = JSON.parse(readFileSync(reviewedInputsPath, \"utf8\"));",
265
+ " if (file.kind !== \"interf-stage-reviewed-inputs\" || file.stage_id !== contract.stage) {",
266
+ " coverageFailures.push(`reviewed inputs file is not for stage ${contract.stage}.`);",
267
+ " }",
268
+ " const reviewed = Array.isArray(file.reviewed)",
269
+ " ? file.reviewed.map((entry) => ReviewedInputSchema.parse(entry))",
270
+ " : [];",
271
+ " if (!Array.isArray(file.reviewed)) {",
272
+ " coverageFailures.push(\"reviewed inputs file must contain a reviewed array.\");",
273
+ " }",
274
+ " const expectedIds = new Set(expectedInputs.map((entry) => entry.id));",
275
+ " const reviewedIds = new Set(reviewed.map((entry) => entry.resource_id));",
276
+ " for (const entry of reviewed) {",
277
+ " if (!expectedIds.has(entry.resource_id)) {",
278
+ " coverageFailures.push(`reviewed input ${entry.resource_id} is not in runtime/expected-inputs.json.`);",
279
+ " }",
280
+ " if ((entry.decision === \"missing\" || entry.decision === \"blocked\" || entry.decision === \"not-relevant\") && !entry.reason) {",
281
+ " coverageFailures.push(`reviewed input ${entry.resource_id} needs a reason for decision ${entry.decision}.`);",
282
+ " }",
283
+ " }",
284
+ " for (const input of expectedInputs) {",
285
+ " if (input.required !== false && !reviewedIds.has(input.id)) {",
286
+ " coverageFailures.push(`required expected input ${input.id} was not reviewed.`);",
287
+ " }",
288
+ " }",
289
+ " } catch (error) {",
290
+ " coverageFailures.push(`reviewed inputs JSON is invalid: ${error instanceof Error ? error.message : String(error)}`);",
291
+ " }",
292
+ "}",
293
+ "",
201
294
  "for (const writeContract of contract.artifacts.write_contracts) {",
202
295
  " const result = evaluateChecks(writeContract.checks, {",
203
296
  " rootPath: shellRoot,",
@@ -238,7 +331,10 @@ function writeStageSelfCheckScript(shellRoot) {
238
331
  " if (evidenceItemsWithRefs.length === 0) {",
239
332
  " evidenceFailures.push(\"stage evidence needs at least one source/output evidence item.\");",
240
333
  " }",
241
- " const writableArtifacts = new Set(contract.artifacts.writes);",
334
+ " const writableArtifacts = new Set([",
335
+ " ...contract.artifacts.writes,",
336
+ " ...contract.artifacts.write_contracts.map((writeContract) => writeContract.artifact_id),",
337
+ " ]);",
242
338
  " for (const item of evidence.items) {",
243
339
  " for (const ref of item.output_refs) {",
244
340
  " if (!writableArtifacts.has(ref.artifact_id)) {",
@@ -255,12 +351,12 @@ function writeStageSelfCheckScript(shellRoot) {
255
351
  " }",
256
352
  "}",
257
353
  "",
258
- "if (failures.length === 0 && evidenceFailures.length === 0 && inputFailures.length === 0) {",
354
+ "if (failures.length === 0 && evidenceFailures.length === 0 && inputFailures.length === 0 && coverageFailures.length === 0) {",
259
355
  " console.log(`VALID: ${contract.stage} stage outputs satisfy ${passedChecks}/${totalChecks} deterministic check(s).`);",
260
356
  " process.exit(0);",
261
357
  "}",
262
358
  "",
263
- "console.log(`INVALID: ${failures.length + evidenceFailures.length + inputFailures.length} required deterministic check(s) failed for stage ${contract.stage}.`);",
359
+ "console.log(`INVALID: ${failures.length + evidenceFailures.length + inputFailures.length + coverageFailures.length} required deterministic check(s) failed for stage ${contract.stage}.`);",
264
360
  "for (const { artifact, failure } of failures) {",
265
361
  " console.log(`- ${artifact.artifact_id} (${artifact.path}) / ${failure.check_id}: ${failure.summary}`);",
266
362
  " if (failure.details) {",
@@ -273,6 +369,9 @@ function writeStageSelfCheckScript(shellRoot) {
273
369
  "for (const failure of inputFailures) {",
274
370
  " console.log(`- stage input: ${failure}`);",
275
371
  "}",
372
+ "for (const failure of coverageFailures) {",
373
+ " console.log(`- stage coverage: ${failure}`);",
374
+ "}",
276
375
  "process.exit(1);",
277
376
  "",
278
377
  ].join("\n");
@@ -282,10 +381,28 @@ export function freezeStageExecutionShell(rootPath) {
282
381
  return freezePreservedShell(rootPath, "stage-execution");
283
382
  }
284
383
  export function createBuildPlanAuthoringShell(options) {
285
- const shellRoot = mkdtempSync(join(tmpdir(), `interf-build-plan-author-${options.buildPlanId}-`));
286
- mkdirSync(join(shellRoot, "runtime"), { recursive: true });
287
- mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
288
- mkdirSync(join(shellRoot, "logs"), { recursive: true });
384
+ const { rootPath: shellRoot } = createAgentShell({
385
+ // Durable Project job storage in the launched path; ephemeral /tmp only when
386
+ // no durable root was supplied (unit tests of the draft/parse path).
387
+ rootPath: options.shellRoot ??
388
+ mkdtempSync(join(tmpdir(), `interf-build-plan-author-${options.buildPlanId}-`)),
389
+ subdirs: ["runtime", "artifacts", "logs"],
390
+ nativeSurface: {
391
+ agentsContent: renderBuildPlanAuthoringAgents({
392
+ buildPlanId: options.buildPlanId,
393
+ label: options.label,
394
+ referenceBuildPlanId: options.referenceBuildPlanId ?? null,
395
+ }),
396
+ skillName: "interf-build-plan-author",
397
+ skillContent: renderBuildPlanAuthoringSkill(),
398
+ },
399
+ });
400
+ // source_context is resolved ONCE by the caller (runBuildPlanAuthoringDraft):
401
+ // caller-supplied context wins, else the cheap contents-free Source scan,
402
+ // else null. The shell is a pure consumer here so authoring-context.json and
403
+ // the persisted authoring brief always carry the SAME value. Do not re-derive
404
+ // or re-scan it in the shell.
405
+ const sourceContext = options.sourceContext ?? null;
289
406
  const context = {
290
407
  kind: "interf-build-plan-authoring",
291
408
  version: 1,
@@ -303,7 +420,7 @@ export function createBuildPlanAuthoringShell(options) {
303
420
  artifact_requirements: options.artifactRequirements ?? [],
304
421
  project: {
305
422
  source_folder_path: options.sourceFolderPath,
306
- source_context: options.sourceContext ?? null,
423
+ source_context: sourceContext,
307
424
  },
308
425
  };
309
426
  writeFileSync(join(shellRoot, "runtime", "authoring-context.json"), `${JSON.stringify(context, null, 2)}\n`);
@@ -315,18 +432,13 @@ export function createBuildPlanAuthoringShell(options) {
315
432
  kind: "local-folder",
316
433
  locator: options.sourceFolderPath,
317
434
  },
318
- note: "Interf does not pre-scan Source files for Build Plan authoring. The authoring agent inspects this locator through its own Source access.",
435
+ note: "Interf attaches a cheap, contents-free Source scan (folder names, file counts, file kinds, sampled filenames, filename date ranges) to runtime/authoring-context.json.project.source_context. It never reads file contents. Use it to shape stages, then inspect this locator through your own Source access before locking the plan.",
319
436
  }, null, 2)}\n`);
320
437
  copyResolvedTree({
321
438
  sourcePath: options.buildPlanPath,
322
439
  targetPath: join(shellRoot, "build-plan"),
323
440
  shellType: "build-plan-authoring",
324
441
  });
325
- writeNativeAgentSurface(shellRoot, renderBuildPlanAuthoringAgents({
326
- buildPlanId: options.buildPlanId,
327
- label: options.label,
328
- referenceBuildPlanId: options.referenceBuildPlanId ?? null,
329
- }), "interf-build-plan-author", renderBuildPlanAuthoringSkill());
330
442
  return {
331
443
  rootPath: shellRoot,
332
444
  buildPlanBeforePath: join(shellRoot, "artifacts", "build-plan-before"),
@@ -334,15 +446,28 @@ export function createBuildPlanAuthoringShell(options) {
334
446
  promptLogPath: join(shellRoot, "logs", "build-plan-author.prompt.txt"),
335
447
  eventLogPath: join(shellRoot, "logs", "build-plan-author.events.ndjson"),
336
448
  statusLogPath: join(shellRoot, "logs", "build-plan-author.status.log"),
449
+ // Same canonical convention as the stage path: reasoning is teed into the
450
+ // shell's runtime/ dir so it is preserved when the shell is frozen.
451
+ reasoningLogPath: join(shellRoot, "runtime", "agent-reasoning.jsonl"),
337
452
  };
338
453
  }
454
+ export function freezeBuildPlanAuthoringShell(rootPath) {
455
+ return freezePreservedShell(rootPath, "build-plan-authoring");
456
+ }
339
457
  export function createBuildPlanImprovementShell(options) {
340
458
  const schema = ensureBuildExecutionSurface(options.contextGraphPath);
341
459
  const loopRootPath = buildPlanImprovementLoopRoot(options.contextGraphPath, options.runId, options.loopIndex);
342
- const shellRoot = join(loopRootPath, "shell");
343
- mkdirSync(shellRoot, { recursive: true });
344
- mkdirSync(join(shellRoot, "runtime"), { recursive: true });
345
- mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
460
+ const { rootPath: shellRoot } = createAgentShell({
461
+ rootPath: join(loopRootPath, "shell"),
462
+ subdirs: ["runtime", "artifacts"],
463
+ nativeSurface: {
464
+ agentsContent: renderBuildPlanImprovementAgents(options.contextGraphName, options.buildPlanId, options.loopIndex),
465
+ skillName: "interf-build-plan-improver",
466
+ skillContent: renderBuildPlanImprovementSkill(options.buildPlanId, options.loopIndex, readBuildPlanImprovementDoc(options.contextGraphPath)),
467
+ },
468
+ });
469
+ // Improvement logs live one level up in the loop root (not the shell), so the
470
+ // loop record can index them beside build-plan-before/after.
346
471
  mkdirSync(join(loopRootPath, "logs"), { recursive: true });
347
472
  writeFileSync(join(shellRoot, "runtime", "loop-context.json"), `${JSON.stringify(options.context, null, 2)}\n`);
348
473
  projectContextGraphReviewArtifactsState(options.contextGraphPath, shellRoot, schema);
@@ -366,8 +491,6 @@ export function createBuildPlanImprovementShell(options) {
366
491
  if (reviewSources.targetTestSandboxes) {
367
492
  copyIfExists(reviewSources.targetTestSandboxes, join(shellRoot, "artifacts", "test-sandboxes"), "build-plan-improvement");
368
493
  }
369
- const agentsContent = renderBuildPlanImprovementAgents(options.contextGraphName, options.buildPlanId, options.loopIndex);
370
- writeNativeAgentSurface(shellRoot, agentsContent, "interf-build-plan-improver", renderBuildPlanImprovementSkill(options.buildPlanId, options.loopIndex, readBuildPlanImprovementDoc(options.contextGraphPath)));
371
494
  return {
372
495
  rootPath: shellRoot,
373
496
  loopRootPath,
@@ -376,6 +499,9 @@ export function createBuildPlanImprovementShell(options) {
376
499
  promptLogPath: join(loopRootPath, "logs", "build-plan-improver.prompt.txt"),
377
500
  eventLogPath: join(loopRootPath, "logs", "build-plan-improver.events.ndjson"),
378
501
  statusLogPath: join(loopRootPath, "logs", "build-plan-improver.status.log"),
502
+ // Reasoning is teed into the shell's runtime/ dir (same convention as the
503
+ // stage path) so it is preserved when the improvement shell is frozen.
504
+ reasoningLogPath: join(shellRoot, "runtime", "agent-reasoning.jsonl"),
379
505
  };
380
506
  }
381
507
  export function freezeBuildPlanImprovementShell(rootPath) {
@@ -0,0 +1,10 @@
1
+ import type { SourceContext } from "../../../build-plans/authoring/brief.js";
2
+ /**
3
+ * Produce a populated SourceContext for the authoring agent from a cheap,
4
+ * contents-free scan. Returns null when the Source has no readable files so
5
+ * callers can fall back to the existing null (no fabricated inventory). A
6
+ * genuine read failure on the Source root returns an explicit read-error
7
+ * SourceContext instead, so an unreadable Source never silently degrades into
8
+ * a generic plan.
9
+ */
10
+ export declare function scanSourceContext(sourceFolderPath: string): SourceContext | null;