@interf/compiler 0.5.1 → 0.6.3

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 (353) hide show
  1. package/README.md +160 -201
  2. package/builtin-workflows/interf/README.md +22 -10
  3. package/builtin-workflows/interf/compile/stages/shape/SKILL.md +8 -5
  4. package/builtin-workflows/interf/compile/stages/structure/SKILL.md +3 -0
  5. package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +18 -2
  6. package/builtin-workflows/interf/improve/SKILL.md +4 -4
  7. package/builtin-workflows/interf/use/query/SKILL.md +1 -1
  8. package/builtin-workflows/interf/workflow.json +19 -5
  9. package/builtin-workflows/interf/{compiled.schema.json → workflow.schema.json} +10 -3
  10. package/dist/bin.js +2 -28
  11. package/dist/{commands → cli/commands}/check-draft.d.ts +2 -2
  12. package/dist/{commands → cli/commands}/check-draft.js +13 -13
  13. package/dist/{commands → cli/commands}/compile-controller.d.ts +3 -3
  14. package/dist/{commands → cli/commands}/compile-controller.js +39 -44
  15. package/dist/cli/commands/compile.d.ts +33 -0
  16. package/dist/{commands → cli/commands}/compile.js +107 -33
  17. package/dist/{commands → cli/commands}/compiled-flow.d.ts +3 -4
  18. package/dist/{commands → cli/commands}/compiled-flow.js +9 -14
  19. package/dist/{commands → cli/commands}/create-workflow-wizard.d.ts +20 -2
  20. package/dist/cli/commands/create-workflow-wizard.js +288 -0
  21. package/dist/{commands → cli/commands}/create.d.ts +2 -2
  22. package/dist/cli/commands/create.js +166 -0
  23. package/dist/cli/commands/dataset-selection.d.ts +6 -0
  24. package/dist/cli/commands/dataset-selection.js +11 -0
  25. package/dist/{commands → cli/commands}/default.js +5 -5
  26. package/dist/{commands → cli/commands}/doctor.js +12 -13
  27. package/dist/{commands → cli/commands}/executor-flow.d.ts +2 -2
  28. package/dist/{commands → cli/commands}/executor-flow.js +17 -17
  29. package/dist/cli/commands/init.d.ts +11 -0
  30. package/dist/{commands → cli/commands}/init.js +202 -109
  31. package/dist/{commands → cli/commands}/list.js +9 -6
  32. package/dist/{commands → cli/commands}/reset.js +5 -5
  33. package/dist/{commands → cli/commands}/source-config-wizard.d.ts +10 -5
  34. package/dist/{commands → cli/commands}/source-config-wizard.js +202 -95
  35. package/dist/{commands → cli/commands}/status.js +20 -11
  36. package/dist/{commands → cli/commands}/test-flow.d.ts +13 -4
  37. package/dist/{commands → cli/commands}/test-flow.js +30 -26
  38. package/dist/cli/commands/test.d.ts +14 -0
  39. package/dist/{commands → cli/commands}/test.js +48 -40
  40. package/dist/{commands → cli/commands}/verify.js +4 -4
  41. package/dist/cli/index.d.ts +21 -0
  42. package/dist/cli/index.js +33 -0
  43. package/dist/index.d.ts +22 -11
  44. package/dist/index.js +15 -6
  45. package/dist/lib/agent-args.d.ts +1 -3
  46. package/dist/lib/agent-args.js +1 -42
  47. package/dist/lib/agent-constants.d.ts +1 -5
  48. package/dist/lib/agent-constants.js +1 -28
  49. package/dist/lib/agent-detection.d.ts +1 -7
  50. package/dist/lib/agent-detection.js +1 -65
  51. package/dist/lib/agent-execution.d.ts +1 -2
  52. package/dist/lib/agent-execution.js +1 -242
  53. package/dist/lib/agent-logs.d.ts +1 -2
  54. package/dist/lib/agent-logs.js +1 -17
  55. package/dist/lib/agent-preflight.d.ts +1 -7
  56. package/dist/lib/agent-preflight.js +1 -76
  57. package/dist/lib/agent-render.d.ts +1 -8
  58. package/dist/lib/agent-render.js +1 -218
  59. package/dist/lib/agent-shells.d.ts +1 -44
  60. package/dist/lib/agent-shells.js +1 -847
  61. package/dist/lib/agent-status.d.ts +1 -3
  62. package/dist/lib/agent-status.js +1 -58
  63. package/dist/lib/agent-types.d.ts +1 -30
  64. package/dist/lib/agent-types.js +1 -1
  65. package/dist/lib/agents.d.ts +1 -6
  66. package/dist/lib/agents.js +1 -5
  67. package/dist/lib/builtin-compiled-workflow.d.ts +1 -129
  68. package/dist/lib/builtin-compiled-workflow.js +1 -153
  69. package/dist/lib/compiled-compile.d.ts +1 -52
  70. package/dist/lib/compiled-compile.js +1 -274
  71. package/dist/lib/compiled-paths.d.ts +1 -39
  72. package/dist/lib/compiled-paths.js +3 -103
  73. package/dist/lib/compiled-raw.d.ts +1 -49
  74. package/dist/lib/compiled-raw.js +3 -102
  75. package/dist/lib/compiled-reset.d.ts +1 -1
  76. package/dist/lib/compiled-reset.js +3 -44
  77. package/dist/lib/compiled-schema.d.ts +1 -27
  78. package/dist/lib/compiled-schema.js +1 -110
  79. package/dist/lib/discovery.d.ts +1 -1
  80. package/dist/lib/discovery.js +2 -2
  81. package/dist/lib/execution-profile.d.ts +1 -17
  82. package/dist/lib/execution-profile.js +1 -84
  83. package/dist/lib/executors.d.ts +1 -32
  84. package/dist/lib/executors.js +1 -43
  85. package/dist/lib/interf-bootstrap.d.ts +1 -3
  86. package/dist/lib/interf-bootstrap.js +3 -18
  87. package/dist/lib/interf-detect.d.ts +1 -33
  88. package/dist/lib/interf-detect.js +3 -176
  89. package/dist/lib/interf-scaffold.d.ts +1 -2
  90. package/dist/lib/interf-scaffold.js +3 -121
  91. package/dist/lib/interf-workflow-package.d.ts +1 -20
  92. package/dist/lib/interf-workflow-package.js +1 -276
  93. package/dist/lib/interf.d.ts +1 -5
  94. package/dist/lib/interf.js +3 -4
  95. package/dist/lib/local-workflows.d.ts +1 -53
  96. package/dist/lib/local-workflows.js +1 -399
  97. package/dist/lib/package-root.d.ts +1 -0
  98. package/dist/lib/package-root.js +1 -0
  99. package/dist/lib/project-paths.d.ts +1 -11
  100. package/dist/lib/project-paths.js +3 -32
  101. package/dist/lib/runtime-acceptance.d.ts +1 -9
  102. package/dist/lib/runtime-acceptance.js +1 -257
  103. package/dist/lib/runtime-contracts.d.ts +1 -2
  104. package/dist/lib/runtime-contracts.js +1 -47
  105. package/dist/lib/runtime-inventory.d.ts +1 -7
  106. package/dist/lib/runtime-inventory.js +1 -29
  107. package/dist/lib/runtime-paths.d.ts +1 -7
  108. package/dist/lib/runtime-paths.js +1 -23
  109. package/dist/lib/runtime-prompt.d.ts +1 -2
  110. package/dist/lib/runtime-prompt.js +1 -46
  111. package/dist/lib/runtime-reconcile.d.ts +1 -2
  112. package/dist/lib/runtime-reconcile.js +1 -156
  113. package/dist/lib/runtime-runs.d.ts +1 -11
  114. package/dist/lib/runtime-runs.js +1 -250
  115. package/dist/lib/runtime-types.d.ts +1 -43
  116. package/dist/lib/runtime-types.js +1 -1
  117. package/dist/lib/runtime.d.ts +1 -6
  118. package/dist/lib/runtime.js +1 -5
  119. package/dist/lib/schema.d.ts +4 -1016
  120. package/dist/lib/schema.js +6 -539
  121. package/dist/lib/source-config.d.ts +1 -39
  122. package/dist/lib/source-config.js +3 -293
  123. package/dist/lib/state-artifacts.d.ts +1 -8
  124. package/dist/lib/state-artifacts.js +1 -13
  125. package/dist/lib/state-health.d.ts +1 -4
  126. package/dist/lib/state-health.js +1 -132
  127. package/dist/lib/state-io.d.ts +1 -10
  128. package/dist/lib/state-io.js +1 -76
  129. package/dist/lib/state-paths.d.ts +1 -4
  130. package/dist/lib/state-paths.js +1 -13
  131. package/dist/lib/state-view.d.ts +1 -4
  132. package/dist/lib/state-view.js +1 -103
  133. package/dist/lib/state.d.ts +1 -6
  134. package/dist/lib/state.js +1 -5
  135. package/dist/lib/test-execution.d.ts +1 -14
  136. package/dist/lib/test-execution.js +3 -525
  137. package/dist/lib/test-matrices.d.ts +1 -90
  138. package/dist/lib/test-matrices.js +3 -96
  139. package/dist/lib/test-paths.d.ts +1 -12
  140. package/dist/lib/test-paths.js +3 -59
  141. package/dist/lib/test-profile-presets.d.ts +1 -57
  142. package/dist/lib/test-profile-presets.js +3 -50
  143. package/dist/lib/test-sandbox.d.ts +1 -11
  144. package/dist/lib/test-sandbox.js +3 -105
  145. package/dist/lib/test-specs.d.ts +1 -7
  146. package/dist/lib/test-specs.js +3 -114
  147. package/dist/lib/test-targets.d.ts +1 -5
  148. package/dist/lib/test-targets.js +3 -38
  149. package/dist/lib/test-types.d.ts +1 -17
  150. package/dist/lib/test-types.js +3 -1
  151. package/dist/lib/test.d.ts +1 -4
  152. package/dist/lib/test.js +3 -3
  153. package/dist/lib/validate-compiled.d.ts +1 -27
  154. package/dist/lib/validate-compiled.js +1 -238
  155. package/dist/lib/validate-helpers.d.ts +1 -12
  156. package/dist/lib/validate-helpers.js +1 -41
  157. package/dist/lib/validate.d.ts +1 -19
  158. package/dist/lib/validate.js +1 -256
  159. package/dist/lib/workflow-authoring.d.ts +1 -0
  160. package/dist/lib/workflow-authoring.js +1 -0
  161. package/dist/lib/workflow-definitions.d.ts +1 -68
  162. package/dist/lib/workflow-definitions.js +1 -206
  163. package/dist/lib/workflow-edit-session.d.ts +1 -0
  164. package/dist/lib/workflow-edit-session.js +1 -0
  165. package/dist/lib/workflow-edit-utils.d.ts +1 -0
  166. package/dist/lib/workflow-edit-utils.js +1 -0
  167. package/dist/lib/workflow-helpers.d.ts +1 -38
  168. package/dist/lib/workflow-helpers.js +1 -167
  169. package/dist/lib/workflow-improvement.d.ts +1 -22
  170. package/dist/lib/workflow-improvement.js +1 -396
  171. package/dist/lib/workflow-primitives.d.ts +1 -2
  172. package/dist/lib/workflow-primitives.js +1 -5
  173. package/dist/lib/workflow-review-paths.d.ts +1 -10
  174. package/dist/lib/workflow-review-paths.js +1 -27
  175. package/dist/lib/workflow-stage-policy.d.ts +1 -0
  176. package/dist/lib/workflow-stage-policy.js +1 -0
  177. package/dist/lib/workflow-stage-runner.d.ts +1 -41
  178. package/dist/lib/workflow-stage-runner.js +1 -109
  179. package/dist/lib/workflows.d.ts +1 -15
  180. package/dist/lib/workflows.js +1 -31
  181. package/dist/packages/agents/index.d.ts +17 -0
  182. package/dist/packages/agents/index.js +15 -0
  183. package/dist/packages/agents/lib/agents.d.ts +6 -0
  184. package/dist/packages/agents/lib/agents.js +5 -0
  185. package/dist/packages/agents/lib/args.d.ts +4 -0
  186. package/dist/packages/agents/lib/args.js +52 -0
  187. package/dist/packages/agents/lib/constants.d.ts +5 -0
  188. package/dist/packages/agents/lib/constants.js +28 -0
  189. package/dist/packages/agents/lib/detection.d.ts +7 -0
  190. package/dist/packages/agents/lib/detection.js +65 -0
  191. package/dist/packages/agents/lib/execution-profile.d.ts +17 -0
  192. package/dist/packages/agents/lib/execution-profile.js +84 -0
  193. package/dist/packages/agents/lib/execution.d.ts +2 -0
  194. package/dist/packages/agents/lib/execution.js +243 -0
  195. package/dist/packages/agents/lib/executors.d.ts +32 -0
  196. package/dist/packages/agents/lib/executors.js +45 -0
  197. package/dist/packages/agents/lib/logs.d.ts +2 -0
  198. package/dist/packages/agents/lib/logs.js +17 -0
  199. package/dist/packages/agents/lib/preflight.d.ts +7 -0
  200. package/dist/packages/agents/lib/preflight.js +77 -0
  201. package/dist/packages/agents/lib/render.d.ts +8 -0
  202. package/dist/packages/agents/lib/render.js +218 -0
  203. package/dist/packages/agents/lib/schema.d.ts +8 -0
  204. package/dist/packages/agents/lib/schema.js +7 -0
  205. package/dist/packages/agents/lib/shells.d.ts +69 -0
  206. package/dist/packages/agents/lib/shells.js +1021 -0
  207. package/dist/packages/agents/lib/status.d.ts +3 -0
  208. package/dist/packages/agents/lib/status.js +58 -0
  209. package/dist/packages/agents/lib/types.d.ts +30 -0
  210. package/dist/packages/agents/lib/types.js +1 -0
  211. package/dist/{lib → packages/agents/lib}/user-config.d.ts +1 -0
  212. package/dist/{lib → packages/agents/lib}/user-config.js +3 -2
  213. package/dist/packages/compiler/compiled-compile.d.ts +48 -0
  214. package/dist/packages/compiler/compiled-compile.js +256 -0
  215. package/dist/packages/compiler/compiled-schema.d.ts +31 -0
  216. package/dist/packages/compiler/compiled-schema.js +141 -0
  217. package/dist/packages/compiler/index.d.ts +24 -0
  218. package/dist/packages/compiler/index.js +23 -0
  219. package/dist/packages/compiler/lib/schema.d.ts +684 -0
  220. package/dist/packages/compiler/lib/schema.js +361 -0
  221. package/dist/packages/compiler/runtime-acceptance.d.ts +9 -0
  222. package/dist/packages/compiler/runtime-acceptance.js +269 -0
  223. package/dist/packages/compiler/runtime-contracts.d.ts +2 -0
  224. package/dist/packages/compiler/runtime-contracts.js +48 -0
  225. package/dist/packages/compiler/runtime-inventory.d.ts +7 -0
  226. package/dist/packages/compiler/runtime-inventory.js +29 -0
  227. package/dist/packages/compiler/runtime-paths.d.ts +8 -0
  228. package/dist/packages/compiler/runtime-paths.js +26 -0
  229. package/dist/packages/compiler/runtime-prompt.d.ts +2 -0
  230. package/dist/packages/compiler/runtime-prompt.js +48 -0
  231. package/dist/packages/compiler/runtime-reconcile.d.ts +2 -0
  232. package/dist/packages/compiler/runtime-reconcile.js +193 -0
  233. package/dist/packages/compiler/runtime-runs.d.ts +11 -0
  234. package/dist/packages/compiler/runtime-runs.js +262 -0
  235. package/dist/packages/compiler/runtime-types.d.ts +43 -0
  236. package/dist/packages/compiler/runtime-types.js +1 -0
  237. package/dist/packages/compiler/runtime.d.ts +6 -0
  238. package/dist/packages/compiler/runtime.js +5 -0
  239. package/dist/packages/compiler/state-artifacts.d.ts +8 -0
  240. package/dist/packages/compiler/state-artifacts.js +13 -0
  241. package/dist/packages/compiler/state-health.d.ts +4 -0
  242. package/dist/packages/compiler/state-health.js +132 -0
  243. package/dist/packages/compiler/state-io.d.ts +10 -0
  244. package/dist/packages/compiler/state-io.js +76 -0
  245. package/dist/packages/compiler/state-paths.d.ts +4 -0
  246. package/dist/packages/compiler/state-paths.js +13 -0
  247. package/dist/packages/compiler/state-view.d.ts +4 -0
  248. package/dist/packages/compiler/state-view.js +103 -0
  249. package/dist/packages/compiler/state.d.ts +7 -0
  250. package/dist/packages/compiler/state.js +12 -0
  251. package/dist/packages/compiler/validate-compiled.d.ts +27 -0
  252. package/dist/packages/compiler/validate-compiled.js +241 -0
  253. package/dist/packages/compiler/validate-helpers.d.ts +12 -0
  254. package/dist/packages/compiler/validate-helpers.js +41 -0
  255. package/dist/packages/compiler/validate.d.ts +21 -0
  256. package/dist/packages/compiler/validate.js +249 -0
  257. package/dist/packages/compiler/workflow-primitives.d.ts +2 -0
  258. package/dist/packages/compiler/workflow-primitives.js +5 -0
  259. package/dist/packages/compiler/workflows.d.ts +15 -0
  260. package/dist/packages/compiler/workflows.js +31 -0
  261. package/dist/packages/project-model/compiled-paths.d.ts +40 -0
  262. package/dist/packages/project-model/compiled-paths.js +106 -0
  263. package/dist/packages/project-model/compiled-raw.d.ts +49 -0
  264. package/dist/packages/project-model/compiled-raw.js +102 -0
  265. package/dist/packages/project-model/compiled-reset.d.ts +2 -0
  266. package/dist/packages/project-model/compiled-reset.js +72 -0
  267. package/dist/packages/project-model/index.d.ts +11 -0
  268. package/dist/packages/project-model/index.js +10 -0
  269. package/dist/packages/project-model/interf-bootstrap.d.ts +3 -0
  270. package/dist/packages/project-model/interf-bootstrap.js +18 -0
  271. package/dist/packages/project-model/interf-detect.d.ts +33 -0
  272. package/dist/packages/project-model/interf-detect.js +176 -0
  273. package/dist/packages/project-model/interf-scaffold.d.ts +2 -0
  274. package/dist/packages/project-model/interf-scaffold.js +124 -0
  275. package/dist/packages/project-model/interf.d.ts +5 -0
  276. package/dist/packages/project-model/interf.js +4 -0
  277. package/dist/packages/project-model/lib/schema.d.ts +125 -0
  278. package/dist/packages/project-model/lib/schema.js +62 -0
  279. package/dist/packages/project-model/project-paths.d.ts +11 -0
  280. package/dist/packages/project-model/project-paths.js +32 -0
  281. package/dist/packages/project-model/source-config.d.ts +38 -0
  282. package/dist/packages/project-model/source-config.js +297 -0
  283. package/dist/packages/testing/index.d.ts +13 -0
  284. package/dist/packages/testing/index.js +10 -0
  285. package/dist/packages/testing/lib/schema.d.ts +261 -0
  286. package/dist/packages/testing/lib/schema.js +119 -0
  287. package/dist/packages/testing/test-execution.d.ts +14 -0
  288. package/dist/packages/testing/test-execution.js +525 -0
  289. package/dist/packages/testing/test-matrices.d.ts +90 -0
  290. package/dist/packages/testing/test-matrices.js +96 -0
  291. package/dist/packages/testing/test-paths.d.ts +12 -0
  292. package/dist/packages/testing/test-paths.js +59 -0
  293. package/dist/packages/testing/test-profile-presets.d.ts +57 -0
  294. package/dist/packages/testing/test-profile-presets.js +50 -0
  295. package/dist/packages/testing/test-sandbox.d.ts +11 -0
  296. package/dist/packages/testing/test-sandbox.js +105 -0
  297. package/dist/packages/testing/test-specs.d.ts +7 -0
  298. package/dist/packages/testing/test-specs.js +114 -0
  299. package/dist/packages/testing/test-targets.d.ts +5 -0
  300. package/dist/packages/testing/test-targets.js +38 -0
  301. package/dist/packages/testing/test-types.d.ts +16 -0
  302. package/dist/packages/testing/test-types.js +1 -0
  303. package/dist/packages/testing/test.d.ts +4 -0
  304. package/dist/packages/testing/test.js +3 -0
  305. package/dist/packages/workflow-authoring/index.d.ts +4 -0
  306. package/dist/packages/workflow-authoring/index.js +4 -0
  307. package/dist/packages/workflow-authoring/lib/workflow-edit-utils.d.ts +10 -0
  308. package/dist/packages/workflow-authoring/lib/workflow-edit-utils.js +39 -0
  309. package/dist/packages/workflow-authoring/workflow-authoring.d.ts +26 -0
  310. package/dist/packages/workflow-authoring/workflow-authoring.js +120 -0
  311. package/dist/packages/workflow-authoring/workflow-edit-session.d.ts +16 -0
  312. package/dist/packages/workflow-authoring/workflow-edit-session.js +57 -0
  313. package/dist/packages/workflow-authoring/workflow-improvement.d.ts +23 -0
  314. package/dist/packages/workflow-authoring/workflow-improvement.js +209 -0
  315. package/dist/packages/workflow-package/builtin-compiled-workflow.d.ts +38 -0
  316. package/dist/packages/workflow-package/builtin-compiled-workflow.js +94 -0
  317. package/dist/packages/workflow-package/index.d.ts +9 -0
  318. package/dist/packages/workflow-package/index.js +9 -0
  319. package/dist/packages/workflow-package/interf-workflow-package.d.ts +25 -0
  320. package/dist/packages/workflow-package/interf-workflow-package.js +342 -0
  321. package/dist/{lib/config.d.ts → packages/workflow-package/lib/package-root.d.ts} +0 -1
  322. package/dist/packages/workflow-package/lib/package-root.js +6 -0
  323. package/dist/packages/workflow-package/local-workflows.d.ts +54 -0
  324. package/dist/packages/workflow-package/local-workflows.js +422 -0
  325. package/dist/packages/workflow-package/workflow-definitions.d.ts +78 -0
  326. package/dist/packages/workflow-package/workflow-definitions.js +203 -0
  327. package/dist/packages/workflow-package/workflow-helpers.d.ts +38 -0
  328. package/dist/packages/workflow-package/workflow-helpers.js +167 -0
  329. package/dist/packages/workflow-package/workflow-review-paths.d.ts +10 -0
  330. package/dist/packages/workflow-package/workflow-review-paths.js +27 -0
  331. package/dist/packages/workflow-package/workflow-stage-policy.d.ts +5 -0
  332. package/dist/packages/workflow-package/workflow-stage-policy.js +31 -0
  333. package/dist/packages/workflow-package/workflow-stage-runner.d.ts +41 -0
  334. package/dist/packages/workflow-package/workflow-stage-runner.js +109 -0
  335. package/package.json +44 -21
  336. package/dist/commands/compile.d.ts +0 -15
  337. package/dist/commands/create-workflow-wizard.js +0 -125
  338. package/dist/commands/create.js +0 -162
  339. package/dist/commands/init.d.ts +0 -3
  340. package/dist/commands/test.d.ts +0 -9
  341. package/dist/lib/compiled-home.d.ts +0 -5
  342. package/dist/lib/compiled-home.js +0 -32
  343. package/dist/lib/config.js +0 -9
  344. package/dist/lib/obsidian.d.ts +0 -1
  345. package/dist/lib/obsidian.js +0 -15
  346. package/dist/lib/summarize-plan.d.ts +0 -17
  347. package/dist/lib/summarize-plan.js +0 -120
  348. /package/dist/{commands → cli/commands}/default.d.ts +0 -0
  349. /package/dist/{commands → cli/commands}/doctor.d.ts +0 -0
  350. /package/dist/{commands → cli/commands}/list.d.ts +0 -0
  351. /package/dist/{commands → cli/commands}/reset.d.ts +0 -0
  352. /package/dist/{commands → cli/commands}/status.d.ts +0 -0
  353. /package/dist/{commands → cli/commands}/verify.d.ts +0 -0
@@ -0,0 +1,1021 @@
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";
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";
10
+ import { resolveWorkflowImprovementReviewSourcePaths } from "../../workflow-package/workflow-review-paths.js";
11
+ const LOCAL_SKILL_ROOTS = [
12
+ ".claude/skills",
13
+ ".codex/skills",
14
+ ".agents/skills",
15
+ ".cursor/skills",
16
+ ];
17
+ export function writeNativeAgentSurface(rootPath, agentsContent, skillName, skillContent) {
18
+ let changed = false;
19
+ changed = writeIfChanged(join(rootPath, "AGENTS.md"), `${agentsContent.trimEnd()}\n`) || changed;
20
+ changed =
21
+ writeIfChanged(join(rootPath, "CLAUDE.md"), renderClaudeBootstrap(agentsContent)) || changed;
22
+ changed = writeNativeSkillCopies(rootPath, skillName, skillContent) || changed;
23
+ return changed;
24
+ }
25
+ function compiledQuerySkillSourcePath(compiledPath) {
26
+ return join(workflowPackagePathForCompiled(compiledPath), "use", "query", "SKILL.md");
27
+ }
28
+ function compiledZoneSummaryLines(compiledPath) {
29
+ const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
30
+ if (!schema)
31
+ return ["- No workflow schema is available yet."];
32
+ return schema.zones
33
+ .filter((zone) => zone.kind !== "runtime")
34
+ .map((zone) => `- \`${zone.id}\` -> \`${zone.path}\` (${zone.role} ${zone.kind})`);
35
+ }
36
+ export function renderCompiledAgents(compiledPath, name, workflowId, about, options = {}) {
37
+ const workflowOriginSelected = options.workflowOriginSelected ?? workflowId;
38
+ const workflowLocalDraft = options.workflowLocalDraft === true;
39
+ const zoneLines = compiledZoneSummaryLines(compiledPath);
40
+ return [
41
+ `# ${name}`,
42
+ "",
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.",
45
+ "",
46
+ ...(about
47
+ ? [
48
+ `About: ${about}`,
49
+ "",
50
+ ]
51
+ : []),
52
+ "## How to use this context folder",
53
+ "",
54
+ "1. Use the local native `interf-query` skill that Interf generated for this context folder.",
55
+ "2. Let the workflow docs and declared output zones guide retrieval instead of assuming a fixed note layout.",
56
+ "3. Use `raw/` when you need direct quotes, exact chart values, table lookups, or verification.",
57
+ "",
58
+ "## How this compiled context works",
59
+ "",
60
+ "- `.interf/interf.json` points to the local `raw/` snapshot via `source.path` and back to the project root via `source.control_path`.",
61
+ `- Workflow seed: \`${workflowOriginSelected}\`.`,
62
+ ...(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."]
64
+ : []),
65
+ `- Active local workflow id: \`${workflowId}\`.`,
66
+ "- `.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.`,
68
+ "- `.interf/workflow/improve/` is the editable source for workflow-improvement loops.",
69
+ "- `.interf/workflow/use/query/` is the editable source for the generated native query shell.",
70
+ "- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf projects into native execution shells for automated runs.",
71
+ "- Native local query skills are generated under local agent skill directories such as `.claude/skills/` and `.codex/skills/`.",
72
+ "- `raw/` contains the local raw snapshot used for evidence and verification.",
73
+ `- Workflow zones are declared in \`.interf/workflow/${WORKFLOW_SCHEMA_FILE}\`.`,
74
+ ...zoneLines,
75
+ "- `.interf/runtime/` holds runtime artifacts written by Interf.",
76
+ "- `.interf/tests/` mirrors the latest saved comparison and keeps detailed target runs plus preserved sandboxes.",
77
+ "- `.interf/tests/targets/` holds detailed raw and compiled target runs plus preserved test sandboxes.",
78
+ "",
79
+ "## Manual query rules",
80
+ "",
81
+ "- Prefer the workflow-declared context outputs before `raw/`.",
82
+ "- Use the generated native `interf-query` skill for manual querying. The editable source lives at `.interf/workflow/use/query/SKILL.md`.",
83
+ "- Treat `.interf/` as method/runtime metadata, not answer evidence, unless explicitly asked to inspect workflow or test history.",
84
+ "- Use `raw/` for quotes, verification, ambiguity, or evidence the compiled context does not expose well.",
85
+ "- If exact chart, table, or image-derived evidence matters, inspect the raw source and say whether the answer was text-derived, table-derived, or chart-derived.",
86
+ "",
87
+ "## Commands",
88
+ "",
89
+ "```",
90
+ "interf compile build this context folder",
91
+ "interf test run checks against this context folder",
92
+ "interf verify stage <id> verify one workflow stage",
93
+ "interf verify compiled verify the full compiled context output",
94
+ "interf status show deterministic health",
95
+ "```",
96
+ "",
97
+ "## Rules",
98
+ "",
99
+ "- Do not modify files under `raw/`.",
100
+ "- Treat compiled notes as working task context artifacts, not final truth.",
101
+ "- When confidence is low, verify against `raw/` before answering strongly.",
102
+ "",
103
+ ].join("\n");
104
+ }
105
+ export function renderCompiledQuerySkill() {
106
+ return [
107
+ "# Manual Query Loop",
108
+ "",
109
+ "This file is the editable authoring source for the generated native local `interf-query` skill.",
110
+ "",
111
+ "Default loop:",
112
+ "1. Read `workflow/README.md` and this file first.",
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 context is missing the needed evidence or is ambiguous.",
115
+ "",
116
+ "Answering rule:",
117
+ "- do not modify files under `raw/`",
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 context is missing the needed evidence or is ambiguous",
121
+ "- do not invent navigation or note structure beyond what this workflow declares",
122
+ "- when the compiled context is insufficient, verify in `raw/` and then answer",
123
+ "",
124
+ "You can edit this file to bias manual question-answering behavior for this context folder.",
125
+ "",
126
+ ].join("\n");
127
+ }
128
+ function renderRawTestAgents() {
129
+ const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note}`);
130
+ return [
131
+ "# Raw Test Shell",
132
+ "",
133
+ "This is an isolated raw-files test shell generated by Interf.",
134
+ "There is no compiled context in this shell.",
135
+ "",
136
+ "## How to use this shell",
137
+ "",
138
+ "1. Read this file first.",
139
+ "2. Use the local native `interf-query` skill available in this shell.",
140
+ "3. Read only from `raw/`.",
141
+ "",
142
+ "## Rules",
143
+ "",
144
+ "- Answer only from the files under `raw/`.",
145
+ "- There is no compiled context here, so do not assume any compiled-context output zones exist.",
146
+ "- Do not treat hidden runtime files or test artifacts as evidence.",
147
+ ...chartNotes,
148
+ "- Write the requested answer and trace files, then stop.",
149
+ "",
150
+ ].join("\n");
151
+ }
152
+ function renderRawTestQuerySkill() {
153
+ const chartNotes = CHART_APPROXIMATION_NOTES.map((note, index) => `${index + 3}. ${note}`);
154
+ return [
155
+ "---",
156
+ "name: interf-query",
157
+ "description: >",
158
+ " Native local query skill for an Interf raw test shell. Use it only",
159
+ " to answer baseline questions directly from `raw/`.",
160
+ "---",
161
+ "",
162
+ "# Interf Raw Test Query",
163
+ "",
164
+ "This is the native local query skill for an isolated raw-files test shell.",
165
+ "",
166
+ "Loop:",
167
+ "1. Read `raw/` directly.",
168
+ "2. Verify exact claims against the raw files before answering strongly.",
169
+ ...chartNotes,
170
+ "8. Do not rely on compiled context artifacts because they do not exist in this shell.",
171
+ "",
172
+ ].join("\n");
173
+ }
174
+ function readCompiledQuerySkillSource(compiledPath) {
175
+ const filePath = compiledQuerySkillSourcePath(compiledPath);
176
+ if (!existsSync(filePath)) {
177
+ throw new Error(`Missing compiled query skill source at ${filePath}. Interf compile runs the local workflow package directly, so reseed or repair this compiled context instead of auto-healing query docs.`);
178
+ }
179
+ return readFileSync(filePath, "utf8").trim();
180
+ }
181
+ function stageShellWorkflowRoot(shellRoot) {
182
+ return join(shellRoot, WORKFLOW_PACKAGE_DIR);
183
+ }
184
+ function shellInputZonePath(shellRoot, zoneId) {
185
+ return join(shellRoot, "inputs", zoneId);
186
+ }
187
+ function shellOutputZonePath(shellRoot, zoneId) {
188
+ return join(shellRoot, "outputs", zoneId);
189
+ }
190
+ function shellZoneAliasMountPath(shellRoot, zone, mountKind) {
191
+ const mountRoot = mountKind === "inputs"
192
+ ? shellInputZonePath(shellRoot, zone.id)
193
+ : shellOutputZonePath(shellRoot, zone.id);
194
+ return zone.kind === "file"
195
+ ? join(mountRoot, basename(zone.path))
196
+ : mountRoot;
197
+ }
198
+ function describeShellZoneAliasMountPath(zone, mountKind) {
199
+ return zone.kind === "file"
200
+ ? `${mountKind}/${zone.id}/${basename(zone.path)}`
201
+ : `${mountKind}/${zone.id}`;
202
+ }
203
+ function shellRuntimePath(shellRoot, relativePath) {
204
+ return join(shellRoot, "runtime", relativePath);
205
+ }
206
+ function writeIfChanged(path, content) {
207
+ if (existsSync(path) && readFileSync(path, "utf8") === content) {
208
+ return false;
209
+ }
210
+ mkdirSync(dirname(path), { recursive: true });
211
+ writeFileSync(path, content);
212
+ return true;
213
+ }
214
+ function writeNativeSkillCopies(rootPath, skillName, content) {
215
+ let changed = false;
216
+ for (const skillsRoot of LOCAL_SKILL_ROOTS) {
217
+ const skillPath = join(rootPath, skillsRoot, skillName, "SKILL.md");
218
+ changed = writeIfChanged(skillPath, content) || changed;
219
+ }
220
+ return changed;
221
+ }
222
+ function linkPath(targetPath, linkPathname) {
223
+ mkdirSync(dirname(linkPathname), { recursive: true });
224
+ symlinkSync(targetPath, linkPathname);
225
+ }
226
+ function linkRelativePath(targetPath, linkPathname) {
227
+ mkdirSync(dirname(linkPathname), { recursive: true });
228
+ symlinkSync(relative(dirname(linkPathname), targetPath), linkPathname);
229
+ }
230
+ function loadCompiledSchema(compiledPath) {
231
+ const workflowRoot = workflowPackagePathForCompiled(compiledPath);
232
+ const schema = readCompiledSchemaFile(workflowRoot);
233
+ if (!schema) {
234
+ throw new Error(`Missing workflow schema at ${join(workflowRoot, WORKFLOW_SCHEMA_FILE)}`);
235
+ }
236
+ return schema;
237
+ }
238
+ function zoneMap(schema) {
239
+ return new Map(schema.zones.map((zone) => [zone.id, zone]));
240
+ }
241
+ function zoneOrThrow(zones, zoneId) {
242
+ const zone = zones.get(zoneId);
243
+ if (!zone) {
244
+ throw new Error(`Missing workflow schema zone "${zoneId}" for stage shell projection.`);
245
+ }
246
+ return zone;
247
+ }
248
+ function normalizeArtifactRelativePath(path) {
249
+ return path
250
+ .replaceAll("\\", "/")
251
+ .replace(/^\.?\//, "")
252
+ .replace(/\/+$/g, "");
253
+ }
254
+ function relativePathEqualsOrWithin(basePath, candidatePath) {
255
+ const base = normalizeArtifactRelativePath(basePath);
256
+ const candidate = normalizeArtifactRelativePath(candidatePath);
257
+ if (base.length === 0 || candidate.length === 0)
258
+ return false;
259
+ return candidate === base || candidate.startsWith(`${base}/`);
260
+ }
261
+ function stageWriteZoneSet(schema, stage) {
262
+ return new Set(stage.writes.filter((zoneId) => schema.zones.some((zone) => zone.id === zoneId)));
263
+ }
264
+ function stageMaterializedZoneSet(schema, stage, writeArtifacts = []) {
265
+ const materialized = stageWriteZoneSet(schema, stage);
266
+ for (const zone of schema.zones) {
267
+ if (zone.kind === "runtime" && stage.reads.includes(zone.id)) {
268
+ materialized.add(zone.id);
269
+ }
270
+ }
271
+ for (const artifactPath of writeArtifacts) {
272
+ const normalizedArtifactPath = normalizeArtifactRelativePath(artifactPath);
273
+ if (normalizedArtifactPath.length === 0)
274
+ continue;
275
+ const owner = schema.zones.find((zone) => relativePathEqualsOrWithin(zone.path, normalizedArtifactPath));
276
+ if (owner) {
277
+ materialized.add(owner.id);
278
+ }
279
+ }
280
+ return materialized;
281
+ }
282
+ function ensureShellLocalProjection(sourcePath, targetPath, zone) {
283
+ if (existsSync(sourcePath)) {
284
+ copyResolvedTree({
285
+ sourcePath,
286
+ targetPath,
287
+ shellType: "stage-execution",
288
+ });
289
+ return;
290
+ }
291
+ if (zone.kind === "file") {
292
+ mkdirSync(dirname(targetPath), { recursive: true });
293
+ return;
294
+ }
295
+ mkdirSync(targetPath, { recursive: true });
296
+ }
297
+ function ensureCompiledExecutionSurface(compiledPath) {
298
+ mkdirSync(compiledRuntimeRoot(compiledPath), { recursive: true });
299
+ mkdirSync(workflowPackagePathForCompiled(compiledPath), { recursive: true });
300
+ const schema = loadCompiledSchema(compiledPath);
301
+ ensureCompiledZoneTargets(compiledPath, schema);
302
+ return schema;
303
+ }
304
+ function readStageMethodDoc(compiledPath, stage) {
305
+ const path = join(workflowPackagePathForCompiled(compiledPath), "compile", "stages", stage.skillDir, "SKILL.md");
306
+ if (!existsSync(path))
307
+ return null;
308
+ return readFileSync(path, "utf8").trim();
309
+ }
310
+ function stageWorkflowDocsPath(compiledPath, stage) {
311
+ return join(workflowPackagePathForCompiled(compiledPath), "compile", "stages", stage.skillDir);
312
+ }
313
+ function renderStageExecutionAgents(compiledName, workflowId, stage) {
314
+ return [
315
+ `# ${compiledName} — ${stage.label} Execution Shell`,
316
+ "",
317
+ "This is an ephemeral stage-execution shell generated by Interf.",
318
+ "It is for automated pipeline execution only, not for manual querying.",
319
+ "",
320
+ "## Start Here",
321
+ "",
322
+ "1. Read `runtime/stage-contract.json` now.",
323
+ "2. Read `runtime/paths.json` now.",
324
+ "3. Use the local native `interf-stage` skill now.",
325
+ `4. Execute only the current stage: \`${stage.id}\` (${stage.label}).`,
326
+ "",
327
+ "## Shell ABI",
328
+ "",
329
+ "- `inputs/<zone-id>/` = read mounts for the current stage.",
330
+ "- `outputs/<zone-id>/` = write mounts for the current stage.",
331
+ "- For file zones, `runtime/paths.json` points to the exact file path inside those mount roots.",
332
+ "- declared compiled zone paths are also projected at the shell root so workflow-relative contract paths stay valid.",
333
+ "- `runtime/` = stage contract and machine-readable path map for this shell.",
334
+ "- `workflow/` = workflow metadata, workflow schema, and docs for the current stage only.",
335
+ "",
336
+ "## Boundaries",
337
+ "",
338
+ `- Workflow: \`${workflowId}\`.`,
339
+ `- Contract type: \`${stage.contractType}\`.`,
340
+ "- This shell has its own AGENTS/CLAUDE/native skills. It does not inherit the compiled-context query shell.",
341
+ "- The compiled context root itself is not linked into this shell.",
342
+ "- Do not switch into query mode or act like a user-facing assistant.",
343
+ "- Do not modify files under `inputs/` unless the same zone is also mounted under `outputs/`.",
344
+ "",
345
+ "## Current Stage Zones",
346
+ "",
347
+ `- reads: ${stage.reads.join(", ")}`,
348
+ `- writes: ${stage.writes.join(", ")}`,
349
+ "",
350
+ "## Goal",
351
+ "",
352
+ "- complete the current stage",
353
+ "- honor the deterministic contract",
354
+ "- write outputs through the declared zone mounts",
355
+ "- stop when the stage is complete",
356
+ "",
357
+ ].join("\n");
358
+ }
359
+ function renderStageExecutionSkill(stage, stageMethodDoc) {
360
+ return [
361
+ "---",
362
+ "name: interf-stage",
363
+ "description: >",
364
+ ` Native local execution skill for the ${stage.label} stage in this`,
365
+ " Interf run. Use it only inside an automated stage execution shell.",
366
+ "---",
367
+ "",
368
+ `# Interf Stage Execution — ${stage.label}`,
369
+ "",
370
+ "This local native skill exists for automated Interf stage execution.",
371
+ "Read `runtime/stage-contract.json` first.",
372
+ "Then read `runtime/paths.json` and use the mounted `inputs/` and `outputs/` zones for this stage.",
373
+ "Do not switch into manual query mode.",
374
+ "",
375
+ "## Current Stage",
376
+ "",
377
+ `- id: \`${stage.id}\``,
378
+ `- label: ${stage.label}`,
379
+ `- contract type: \`${stage.contractType}\``,
380
+ `- reads: ${stage.reads.join(", ")}`,
381
+ `- writes: ${stage.writes.join(", ")}`,
382
+ `- editable source: \`workflow/compile/stages/${stage.skillDir}/SKILL.md\``,
383
+ "",
384
+ ...(stageMethodDoc
385
+ ? [
386
+ "## Stage Method",
387
+ "",
388
+ stageMethodDoc,
389
+ "",
390
+ ]
391
+ : []),
392
+ ].join("\n");
393
+ }
394
+ function renderCompiledQueryNativeSkill(querySkillContent) {
395
+ return [
396
+ "---",
397
+ "name: interf-query",
398
+ "description: >",
399
+ " Native local query skill for this context folder built by Interf",
400
+ " Compiler. Use it for manual questions against the compiled context",
401
+ " and its raw fallback.",
402
+ "---",
403
+ "",
404
+ "# Interf Query",
405
+ "",
406
+ "This is the native local query skill for a compiled context built by Interf.",
407
+ "Use it when reading this context folder manually.",
408
+ "Editable source: `.interf/workflow/use/query/SKILL.md`.",
409
+ "",
410
+ querySkillContent.trim(),
411
+ "",
412
+ ].join("\n");
413
+ }
414
+ function projectWorkflowMetadata(compiledPath, shellRoot, stage) {
415
+ const shellWorkflowRoot = stageShellWorkflowRoot(shellRoot);
416
+ mkdirSync(join(shellWorkflowRoot, "compile", "stages"), { recursive: true });
417
+ const compiledWorkflowRoot = workflowPackagePathForCompiled(compiledPath);
418
+ const workflowJsonPath = join(compiledWorkflowRoot, "workflow.json");
419
+ if (existsSync(workflowJsonPath)) {
420
+ linkPath(workflowJsonPath, join(shellWorkflowRoot, "workflow.json"));
421
+ }
422
+ const compiledSchemaPath = resolveWorkflowSchemaPath(compiledWorkflowRoot);
423
+ if (compiledSchemaPath) {
424
+ linkPath(compiledSchemaPath, join(shellWorkflowRoot, WORKFLOW_SCHEMA_FILE));
425
+ }
426
+ const readmePath = join(compiledWorkflowRoot, "README.md");
427
+ if (existsSync(readmePath)) {
428
+ linkPath(readmePath, join(shellWorkflowRoot, "README.md"));
429
+ }
430
+ const stageDocsPath = stageWorkflowDocsPath(compiledPath, stage);
431
+ if (existsSync(stageDocsPath)) {
432
+ linkPath(stageDocsPath, join(shellWorkflowRoot, "compile", "stages", stage.skillDir));
433
+ }
434
+ }
435
+ function projectCompiledSchemaZones(compiledPath, shellRoot, schema, zoneIds, materializedZoneIds) {
436
+ const allowedZoneIds = zoneIds ? new Set(zoneIds) : null;
437
+ for (const zone of schema.zones) {
438
+ if (allowedZoneIds && !allowedZoneIds.has(zone.id))
439
+ continue;
440
+ const sourcePath = compiledZoneAbsolutePath(compiledPath, zone);
441
+ const targetPath = join(shellRoot, zone.path);
442
+ if (materializedZoneIds?.has(zone.id)) {
443
+ ensureShellLocalProjection(sourcePath, targetPath, zone);
444
+ continue;
445
+ }
446
+ linkPath(sourcePath, targetPath);
447
+ }
448
+ }
449
+ function buildStageZoneMounts(compiledPath, shellRoot, stage, schema) {
450
+ const zones = zoneMap(schema);
451
+ const mountFor = (zoneId) => {
452
+ const zone = zoneOrThrow(zones, zoneId);
453
+ return {
454
+ zone_id: zone.id,
455
+ compiled_path: zone.path,
456
+ shell_root_path: zone.path,
457
+ input_mount_path: stage.reads.includes(zoneId)
458
+ ? describeShellZoneAliasMountPath(zone, "inputs")
459
+ : null,
460
+ output_mount_path: stage.writes.includes(zoneId)
461
+ ? describeShellZoneAliasMountPath(zone, "outputs")
462
+ : null,
463
+ };
464
+ };
465
+ return {
466
+ reads: stage.reads.map(mountFor),
467
+ writes: stage.writes.map(mountFor),
468
+ };
469
+ }
470
+ function projectStageZoneMountAliases(shellRoot, stage, schema) {
471
+ const zones = zoneMap(schema);
472
+ for (const zoneId of new Set([...stage.reads, ...stage.writes])) {
473
+ const zone = zoneOrThrow(zones, zoneId);
474
+ const targetPath = join(shellRoot, zone.path);
475
+ if (stage.reads.includes(zoneId)) {
476
+ linkRelativePath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "inputs"));
477
+ }
478
+ if (stage.writes.includes(zoneId)) {
479
+ linkRelativePath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "outputs"));
480
+ }
481
+ }
482
+ }
483
+ function writeExecutionShellPathsFile(shellRoot, workflowId, stage, mounts) {
484
+ const paths = {
485
+ kind: "interf-execution-shell",
486
+ version: 1,
487
+ workflow: workflowId,
488
+ stage: stage.id,
489
+ reads: mounts.reads,
490
+ writes: mounts.writes,
491
+ };
492
+ writeFileSync(shellRuntimePath(shellRoot, "paths.json"), `${JSON.stringify(paths, null, 2)}\n`);
493
+ }
494
+ export function syncStageExecutionShellWrites(compiledPath, shellRoot, stage, writeArtifacts = []) {
495
+ const schema = ensureCompiledExecutionSurface(compiledPath);
496
+ const zones = zoneMap(schema);
497
+ const stageWriteZones = Array.from(stageWriteZoneSet(schema, stage))
498
+ .map((zoneId) => zoneOrThrow(zones, zoneId));
499
+ for (const zone of stageWriteZones) {
500
+ const canonicalShellZonePath = join(shellRoot, zone.path);
501
+ const outputAliasPath = shellZoneAliasMountPath(shellRoot, zone, "outputs");
502
+ const shellZonePath = zone.kind === "file" &&
503
+ existsSync(outputAliasPath) &&
504
+ !lstatSync(outputAliasPath).isSymbolicLink()
505
+ ? outputAliasPath
506
+ : canonicalShellZonePath;
507
+ if (!existsSync(shellZonePath))
508
+ continue;
509
+ const shellZoneStat = lstatSync(shellZonePath);
510
+ if (shellZoneStat.isSymbolicLink())
511
+ continue;
512
+ const compiledZonePath = compiledZoneAbsolutePath(compiledPath, zone);
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
+ }
521
+ rmSync(compiledZonePath, { recursive: true, force: true });
522
+ mkdirSync(dirname(compiledZonePath), { recursive: true });
523
+ cpSync(shellZonePath, compiledZonePath, {
524
+ recursive: true,
525
+ force: true,
526
+ });
527
+ continue;
528
+ }
529
+ mkdirSync(dirname(compiledZonePath), { recursive: true });
530
+ copyFileSync(shellZonePath, compiledZonePath);
531
+ }
532
+ for (const artifactPath of writeArtifacts) {
533
+ const normalizedArtifactPath = normalizeArtifactRelativePath(artifactPath);
534
+ if (normalizedArtifactPath.length === 0 ||
535
+ stageWriteZones.some((zone) => relativePathEqualsOrWithin(zone.path, normalizedArtifactPath))) {
536
+ continue;
537
+ }
538
+ const shellArtifactPath = join(shellRoot, normalizedArtifactPath);
539
+ if (!existsSync(shellArtifactPath))
540
+ continue;
541
+ const compiledArtifactPath = join(compiledPath, normalizedArtifactPath);
542
+ const shellArtifactStat = lstatSync(shellArtifactPath);
543
+ if (shellArtifactStat.isSymbolicLink())
544
+ continue;
545
+ if (shellArtifactStat.isDirectory()) {
546
+ rmSync(compiledArtifactPath, { recursive: true, force: true });
547
+ mkdirSync(dirname(compiledArtifactPath), { recursive: true });
548
+ cpSync(shellArtifactPath, compiledArtifactPath, {
549
+ recursive: true,
550
+ force: true,
551
+ });
552
+ continue;
553
+ }
554
+ mkdirSync(dirname(compiledArtifactPath), { recursive: true });
555
+ copyFileSync(shellArtifactPath, compiledArtifactPath);
556
+ }
557
+ }
558
+ function preservedShellManifestPath(rootPath) {
559
+ return shellRuntimePath(rootPath, "preserved-shell.json");
560
+ }
561
+ function shouldSkipFrozenStageShellRelativePath(relativePath) {
562
+ const normalized = relativePath.replaceAll("\\", "/");
563
+ return normalized === "execution-shells" ||
564
+ normalized.endsWith("/execution-shells") ||
565
+ normalized.includes("/execution-shells/") ||
566
+ normalized === "improvement-loops" ||
567
+ normalized.endsWith("/improvement-loops") ||
568
+ normalized.includes("/improvement-loops/");
569
+ }
570
+ function copyResolvedTree(options) {
571
+ const relativePath = options.relativePath ?? "";
572
+ if (options.shellType === "stage-execution" && shouldSkipFrozenStageShellRelativePath(relativePath)) {
573
+ return { materializedSymlinks: 0 };
574
+ }
575
+ const stat = lstatSync(options.sourcePath);
576
+ if (stat.isSymbolicLink()) {
577
+ const realTarget = realpathSync(options.sourcePath);
578
+ const realStat = statSync(realTarget);
579
+ if (realStat.isDirectory()) {
580
+ const mappedTarget = options.materializedRealPaths?.get(realTarget);
581
+ if (mappedTarget) {
582
+ linkRelativePath(mappedTarget, options.targetPath);
583
+ return { materializedSymlinks: 1 };
584
+ }
585
+ return {
586
+ materializedSymlinks: 1 + copyResolvedTree({
587
+ sourcePath: realTarget,
588
+ targetPath: options.targetPath,
589
+ shellType: options.shellType,
590
+ relativePath,
591
+ activeRealPaths: options.activeRealPaths,
592
+ materializedRealPaths: options.materializedRealPaths,
593
+ }).materializedSymlinks,
594
+ };
595
+ }
596
+ mkdirSync(dirname(options.targetPath), { recursive: true });
597
+ copyFileSync(realTarget, options.targetPath);
598
+ return { materializedSymlinks: 1 };
599
+ }
600
+ if (stat.isDirectory()) {
601
+ const realSource = realpathSync(options.sourcePath);
602
+ const mappedTarget = options.materializedRealPaths?.get(realSource);
603
+ if (mappedTarget && mappedTarget !== options.targetPath) {
604
+ linkRelativePath(mappedTarget, options.targetPath);
605
+ return { materializedSymlinks: 0 };
606
+ }
607
+ const nextRealPaths = new Set([...(options.activeRealPaths ?? []), realSource]);
608
+ const nextMaterializedRealPaths = new Map(options.materializedRealPaths ?? []);
609
+ nextMaterializedRealPaths.set(realSource, options.targetPath);
610
+ mkdirSync(options.targetPath, { recursive: true });
611
+ let materializedSymlinks = 0;
612
+ for (const entry of readdirSync(options.sourcePath)) {
613
+ const childRelativePath = relativePath.length > 0 ? `${relativePath}/${entry}` : entry;
614
+ const copied = copyResolvedTree({
615
+ sourcePath: join(options.sourcePath, entry),
616
+ targetPath: join(options.targetPath, entry),
617
+ shellType: options.shellType,
618
+ relativePath: childRelativePath,
619
+ activeRealPaths: nextRealPaths,
620
+ materializedRealPaths: nextMaterializedRealPaths,
621
+ });
622
+ materializedSymlinks += copied.materializedSymlinks;
623
+ }
624
+ return { materializedSymlinks };
625
+ }
626
+ mkdirSync(dirname(options.targetPath), { recursive: true });
627
+ copyFileSync(options.sourcePath, options.targetPath);
628
+ return { materializedSymlinks: 0 };
629
+ }
630
+ function freezePreservedShell(rootPath, shellType) {
631
+ if (!existsSync(rootPath))
632
+ return null;
633
+ const manifestPath = preservedShellManifestPath(rootPath);
634
+ if (existsSync(manifestPath))
635
+ return manifestPath;
636
+ const tempRoot = `${rootPath}.frozen-${Date.now().toString(36)}`;
637
+ const copied = copyResolvedTree({
638
+ sourcePath: rootPath,
639
+ targetPath: tempRoot,
640
+ shellType,
641
+ });
642
+ const manifest = {
643
+ kind: "interf-preserved-shell",
644
+ version: 1,
645
+ shell_type: shellType,
646
+ generated_at: new Date().toISOString(),
647
+ root_path: rootPath,
648
+ materialized_symlinks: copied.materializedSymlinks,
649
+ };
650
+ writeFileSync(preservedShellManifestPath(tempRoot), `${JSON.stringify(manifest, null, 2)}\n`);
651
+ rmSync(rootPath, { recursive: true, force: true });
652
+ renameSync(tempRoot, rootPath);
653
+ return manifestPath;
654
+ }
655
+ export function renderClaudeBootstrap(content) {
656
+ return [
657
+ "<!-- Generated compatibility mirror of AGENTS.md. Interf may rewrite this file. -->",
658
+ "",
659
+ content.trimEnd(),
660
+ "",
661
+ ].join("\n");
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 task.",
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 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 task",
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 snapshot under `artifacts/source-dataset/raw/`, and any preview context 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 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
+ }
765
+ function improvementWorkflowDocsPath(compiledPath) {
766
+ return join(workflowPackagePathForCompiled(compiledPath), "improve");
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
+ }
831
+ function renderWorkflowImprovementAgents(compiledName, workflowId, loopIndex) {
832
+ return [
833
+ `# ${compiledName} — Workflow Improvement Shell`,
834
+ "",
835
+ "This is an automated workflow-improvement shell generated by Interf.",
836
+ "It exists to review failed compile/test runs and edit the workflow package for the next variation.",
837
+ "",
838
+ "## Start Here",
839
+ "",
840
+ "1. Read `runtime/loop-context.json` now.",
841
+ `2. Read \`workflow/README.md\`, \`workflow/workflow.json\`, and \`workflow/${WORKFLOW_SCHEMA_FILE}\` now.`,
842
+ "3. Read `workflow/improve/SKILL.md` now.",
843
+ "4. Use the local native `interf-workflow-improver` skill now.",
844
+ "",
845
+ "## Boundaries",
846
+ "",
847
+ `- Workflow: \`${workflowId}\`.`,
848
+ `- Improvement loop: ${loopIndex}.`,
849
+ "- Edit only files under `workflow/`.",
850
+ "- Do not edit checks, test specs, raw files, or generated context outputs.",
851
+ "- Review context outputs under `artifacts/compiled-view/` and test/runtime evidence under `artifacts/`.",
852
+ "- Keep the workflow valid for the current compiler API and workflow schema.",
853
+ "",
854
+ "## Goal",
855
+ "",
856
+ "- create a better workflow variation for this task",
857
+ "- preserve deterministic compiled-context structure",
858
+ "- stop after the workflow edits are complete",
859
+ "",
860
+ ].join("\n");
861
+ }
862
+ function readWorkflowImprovementDoc(compiledPath) {
863
+ const path = join(improvementWorkflowDocsPath(compiledPath), "SKILL.md");
864
+ if (!existsSync(path))
865
+ return null;
866
+ return readFileSync(path, "utf8").trim();
867
+ }
868
+ function renderWorkflowImprovementSkill(workflowId, loopIndex, improvementDoc) {
869
+ return [
870
+ "---",
871
+ "name: interf-workflow-improver",
872
+ "description: >",
873
+ " Native local workflow-improvement skill for this Interf run.",
874
+ " Use it only inside an automated workflow-improvement shell.",
875
+ "---",
876
+ "",
877
+ `# Interf Workflow Improvement — ${workflowId}`,
878
+ "",
879
+ "This local native skill exists for automated workflow-improvement loops.",
880
+ "Read `runtime/loop-context.json` first.",
881
+ "Then review the linked workflow package, `artifacts/compiled-view/`, preserved stage shells, runtime logs, and saved test outputs before editing `workflow/`.",
882
+ "",
883
+ "## Current Loop",
884
+ "",
885
+ `- workflow: \`${workflowId}\``,
886
+ `- loop index: ${loopIndex}`,
887
+ "- editable source: `workflow/improve/SKILL.md`",
888
+ "",
889
+ ...(improvementDoc
890
+ ? [
891
+ "## Improvement Method",
892
+ "",
893
+ improvementDoc,
894
+ "",
895
+ ]
896
+ : []),
897
+ ].join("\n");
898
+ }
899
+ function projectCompiledReviewArtifactsSnapshot(compiledPath, shellRoot, schema) {
900
+ const compiledViewRoot = join(shellRoot, "artifacts", "compiled-view");
901
+ mkdirSync(compiledViewRoot, { recursive: true });
902
+ for (const zone of schema.zones) {
903
+ if (zone.kind === "runtime" || zone.path === "raw")
904
+ continue;
905
+ const sourcePath = compiledZoneAbsolutePath(compiledPath, zone);
906
+ if (!existsSync(sourcePath))
907
+ continue;
908
+ copyResolvedTree({
909
+ sourcePath,
910
+ targetPath: join(compiledViewRoot, zone.path),
911
+ shellType: "workflow-improvement",
912
+ });
913
+ }
914
+ }
915
+ function linkIfExists(targetPath, linkPathname) {
916
+ if (!existsSync(targetPath))
917
+ return;
918
+ linkPath(targetPath, linkPathname);
919
+ }
920
+ function copyIfExists(sourcePath, targetPath, shellType) {
921
+ if (!existsSync(sourcePath))
922
+ return;
923
+ copyResolvedTree({
924
+ sourcePath,
925
+ targetPath,
926
+ shellType,
927
+ });
928
+ }
929
+ function projectCompiledRuntimeArtifacts(compiledPath, shellRoot) {
930
+ const runtimeTarget = join(shellRoot, "artifacts", "compiled-runtime");
931
+ mkdirSync(runtimeTarget, { recursive: true });
932
+ const runtimeRoot = compiledRuntimeRoot(compiledPath);
933
+ const artifactNames = [
934
+ "run.json",
935
+ "run-history.jsonl",
936
+ "state.json",
937
+ "health.json",
938
+ "view-spec.json",
939
+ "raw-snapshot.json",
940
+ "logs",
941
+ ];
942
+ for (const artifactName of artifactNames) {
943
+ copyIfExists(join(runtimeRoot, artifactName), join(runtimeTarget, artifactName), "workflow-improvement");
944
+ }
945
+ }
946
+ export function pruneStageExecutionShells(compiledPath) {
947
+ rmSync(stageExecutionShellsRoot(compiledPath), { recursive: true, force: true });
948
+ }
949
+ export function projectCompiledQueryShell(compiledPath, compiledName, workflowId, about, options) {
950
+ const agentsContent = renderCompiledAgents(compiledPath, compiledName, workflowId, about, options);
951
+ const querySkillContent = readCompiledQuerySkillSource(compiledPath);
952
+ return writeNativeAgentSurface(compiledPath, agentsContent, "interf-query", renderCompiledQueryNativeSkill(querySkillContent));
953
+ }
954
+ export function projectRawTestQueryShell(rootPath) {
955
+ return writeNativeAgentSurface(rootPath, renderRawTestAgents(), "interf-query", renderRawTestQuerySkill());
956
+ }
957
+ export function createStageExecutionShell(compiledPath, compiledName, workflowId, stage, writeArtifacts = []) {
958
+ const schema = ensureCompiledExecutionSurface(compiledPath);
959
+ const materializedZones = stageMaterializedZoneSet(schema, stage, writeArtifacts);
960
+ const shellsRoot = stageExecutionShellsRoot(compiledPath);
961
+ const shellRoot = join(shellsRoot, `${stage.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`);
962
+ mkdirSync(shellRoot, { recursive: true });
963
+ mkdirSync(join(shellRoot, "runtime"), { recursive: true });
964
+ mkdirSync(join(shellRoot, "inputs"), { recursive: true });
965
+ mkdirSync(join(shellRoot, "outputs"), { recursive: true });
966
+ linkPath(compiledInterfConfigPath(compiledPath), join(shellRoot, "interf.json"));
967
+ linkPath(join(compiledRuntimeRoot(compiledPath), "stage-contract.json"), shellRuntimePath(shellRoot, "stage-contract.json"));
968
+ projectCompiledSchemaZones(compiledPath, shellRoot, schema, new Set([...stage.reads, ...stage.writes]), materializedZones);
969
+ projectWorkflowMetadata(compiledPath, shellRoot, stage);
970
+ projectStageZoneMountAliases(shellRoot, stage, schema);
971
+ writeExecutionShellPathsFile(shellRoot, workflowId, stage, buildStageZoneMounts(compiledPath, shellRoot, stage, schema));
972
+ const agentsContent = renderStageExecutionAgents(compiledName, workflowId, stage);
973
+ writeNativeAgentSurface(shellRoot, agentsContent, "interf-stage", renderStageExecutionSkill(stage, readStageMethodDoc(compiledPath, stage)));
974
+ return {
975
+ rootPath: shellRoot,
976
+ };
977
+ }
978
+ export function freezeStageExecutionShell(rootPath) {
979
+ return freezePreservedShell(rootPath, "stage-execution");
980
+ }
981
+ export function createWorkflowImprovementShell(options) {
982
+ const schema = ensureCompiledExecutionSurface(options.compiledPath);
983
+ const loopRootPath = workflowImprovementLoopRoot(options.compiledPath, options.runId, options.loopIndex);
984
+ const shellRoot = join(loopRootPath, "shell");
985
+ mkdirSync(shellRoot, { recursive: true });
986
+ mkdirSync(join(shellRoot, "runtime"), { recursive: true });
987
+ mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
988
+ mkdirSync(join(loopRootPath, "logs"), { recursive: true });
989
+ writeFileSync(join(shellRoot, "runtime", "loop-context.json"), `${JSON.stringify(options.context, null, 2)}\n`);
990
+ projectCompiledReviewArtifactsSnapshot(options.compiledPath, shellRoot, schema);
991
+ linkPath(workflowPackagePathForCompiled(options.compiledPath), join(shellRoot, "workflow"));
992
+ copyIfExists(compiledInterfConfigPath(options.compiledPath), join(shellRoot, "interf.json"), "workflow-improvement");
993
+ projectCompiledRuntimeArtifacts(options.compiledPath, shellRoot);
994
+ const reviewSources = resolveWorkflowImprovementReviewSourcePaths(options.compiledPath);
995
+ if (reviewSources.executionShells) {
996
+ copyIfExists(reviewSources.executionShells, join(shellRoot, "artifacts", "execution-shells"), "workflow-improvement");
997
+ }
998
+ if (reviewSources.testComparisons) {
999
+ copyIfExists(reviewSources.testComparisons, join(shellRoot, "artifacts", "test-comparisons"), "workflow-improvement");
1000
+ }
1001
+ if (reviewSources.targetTestRuns) {
1002
+ copyIfExists(reviewSources.targetTestRuns, join(shellRoot, "artifacts", "test-runs"), "workflow-improvement");
1003
+ }
1004
+ if (reviewSources.targetTestSandboxes) {
1005
+ copyIfExists(reviewSources.targetTestSandboxes, join(shellRoot, "artifacts", "test-sandboxes"), "workflow-improvement");
1006
+ }
1007
+ const agentsContent = renderWorkflowImprovementAgents(options.compiledName, options.workflowId, options.loopIndex);
1008
+ writeNativeAgentSurface(shellRoot, agentsContent, "interf-workflow-improver", renderWorkflowImprovementSkill(options.workflowId, options.loopIndex, readWorkflowImprovementDoc(options.compiledPath)));
1009
+ return {
1010
+ rootPath: shellRoot,
1011
+ loopRootPath,
1012
+ workflowBeforePath: join(loopRootPath, "workflow-before"),
1013
+ workflowAfterPath: join(loopRootPath, "workflow-after"),
1014
+ promptLogPath: join(loopRootPath, "logs", "workflow-improver.prompt.txt"),
1015
+ eventLogPath: join(loopRootPath, "logs", "workflow-improver.events.ndjson"),
1016
+ statusLogPath: join(loopRootPath, "logs", "workflow-improver.status.log"),
1017
+ };
1018
+ }
1019
+ export function freezeWorkflowImprovementShell(rootPath) {
1020
+ return freezePreservedShell(rootPath, "workflow-improvement");
1021
+ }