@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
@@ -1,847 +1 @@
1
- import { cpSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, symlinkSync, } from "node:fs";
2
- import { basename, dirname, join, relative } from "node:path";
3
- import { CHART_APPROXIMATION_NOTES } from "./chart-guidance.js";
4
- import { WORKFLOW_PACKAGE_DIR } from "./interf-detect.js";
5
- import { ensureCompiledZoneTargets, readCompiledSchemaFile, compiledZoneAbsolutePath, } from "./compiled-schema.js";
6
- import { stageExecutionShellsRoot, workflowImprovementLoopRoot, workflowPackagePathForCompiled, compiledInterfConfigPath, compiledRuntimeRoot, } from "./compiled-paths.js";
7
- import { resolveWorkflowImprovementReviewSourcePaths } from "./workflow-review-paths.js";
8
- const LOCAL_SKILL_ROOTS = [
9
- ".claude/skills",
10
- ".codex/skills",
11
- ".agents/skills",
12
- ".cursor/skills",
13
- ];
14
- function writeNativeAgentSurface(rootPath, agentsContent, skillName, skillContent) {
15
- let changed = false;
16
- changed = writeIfChanged(join(rootPath, "AGENTS.md"), `${agentsContent.trimEnd()}\n`) || changed;
17
- changed =
18
- writeIfChanged(join(rootPath, "CLAUDE.md"), renderClaudeBootstrap(agentsContent)) || changed;
19
- changed = writeNativeSkillCopies(rootPath, skillName, skillContent) || changed;
20
- return changed;
21
- }
22
- function compiledQuerySkillSourcePath(compiledPath) {
23
- return join(workflowPackagePathForCompiled(compiledPath), "use", "query", "SKILL.md");
24
- }
25
- function compiledZoneSummaryLines(compiledPath) {
26
- const schema = readCompiledSchemaFile(workflowPackagePathForCompiled(compiledPath));
27
- if (!schema)
28
- return ["- No compiled schema is available yet."];
29
- return schema.zones
30
- .filter((zone) => zone.id !== "raw" && zone.kind !== "runtime")
31
- .map((zone) => `- \`${zone.id}\` -> \`${zone.path}\` (${zone.kind})`);
32
- }
33
- export function renderCompiledAgents(compiledPath, name, workflowId, about, options = {}) {
34
- const workflowOriginSelected = options.workflowOriginSelected ?? workflowId;
35
- const workflowLocalDraft = options.workflowLocalDraft === true;
36
- const zoneLines = compiledZoneSummaryLines(compiledPath);
37
- return [
38
- `# ${name}`,
39
- "",
40
- "This is a compiled dataset built by Interf Compiler.",
41
- "It is a file-based layer on top of the raw files, built for agents to navigate, retrieve evidence, and answer more accurately.",
42
- "",
43
- ...(about
44
- ? [
45
- `About: ${about}`,
46
- "",
47
- ]
48
- : []),
49
- "## How to use this compiled dataset",
50
- "",
51
- "1. Use the local native `interf-query` skill that Interf Compiler generated for this compiled dataset.",
52
- "2. Let the workflow docs and compiled output zones guide retrieval instead of assuming a fixed note layout.",
53
- "3. Use `raw/` when you need direct quotes, exact chart values, table lookups, or verification.",
54
- "",
55
- "## How this compiled dataset works",
56
- "",
57
- "- `.interf/interf.json` points to the local `raw/` snapshot via `source.path` and back to the dataset control plane via `source.control_path`.",
58
- `- Workflow seed: \`${workflowOriginSelected}\`.`,
59
- ...(workflowLocalDraft
60
- ? ["- This compiled dataset now carries a local workflow draft improved from that seed. Recompiling this compiled dataset reuses the local `.interf/workflow/` package."]
61
- : []),
62
- `- Active local workflow id: \`${workflowId}\`.`,
63
- "- `.interf/workflow/` is the local editable method package for this compiled dataset.",
64
- "- `.interf/workflow/compiled.schema.json` is the deterministic output shape for this compiled dataset.",
65
- "- `.interf/workflow/improve/` is the editable source for workflow-improvement loops.",
66
- "- `.interf/workflow/use/query/` is the editable source for the generated native query shell.",
67
- "- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf Compiler projects into native execution shells for automated runs.",
68
- "- Native local query skills are generated under local agent skill directories such as `.claude/skills/` and `.codex/skills/`.",
69
- "- `raw/` contains the local raw snapshot used for evidence and verification.",
70
- "- Compiled output zones are declared in `.interf/workflow/compiled.schema.json`.",
71
- ...zoneLines,
72
- "- `.interf/runtime/` holds CLI-owned runtime artifacts.",
73
- "- `.interf/tests/` mirrors the latest dataset-level comparison and keeps detailed target runs plus preserved sandboxes.",
74
- "- `.interf/tests/targets/` holds detailed raw and compiled target runs plus preserved test sandboxes.",
75
- "",
76
- "## Manual query rules",
77
- "",
78
- "- Prefer the workflow-declared compiled outputs before `raw/`.",
79
- "- Use the generated native `interf-query` skill for manual querying. The editable source lives at `.interf/workflow/use/query/SKILL.md`.",
80
- "- Treat `.interf/` as method/runtime metadata, not answer evidence, unless explicitly asked to inspect workflow or test history.",
81
- "- Use `raw/` for quotes, verification, ambiguity, or evidence the compiled layer does not expose well.",
82
- "- 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.",
83
- "",
84
- "## Commands",
85
- "",
86
- "```",
87
- "interf compile build this compiled dataset",
88
- "interf test run saved truth checks against this compiled dataset",
89
- "interf verify stage <id> verify one workflow stage",
90
- "interf verify compiled verify the full workflow output",
91
- "interf status show deterministic health",
92
- "```",
93
- "",
94
- "## Rules",
95
- "",
96
- "- Do not modify files under `raw/`.",
97
- "- Treat compiled notes as working retrieval artifacts, not final truth.",
98
- "- When confidence is low, verify against `raw/` before answering strongly.",
99
- "",
100
- ].join("\n");
101
- }
102
- export function renderCompiledQuerySkill() {
103
- const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note.toLowerCase()}`);
104
- return [
105
- "# Manual Query Loop",
106
- "",
107
- "This file is the editable authoring source for the generated native local `interf-query` skill.",
108
- "",
109
- "Default loop:",
110
- "1. Read `workflow/README.md` and this file first.",
111
- "2. Use the compiled output zones declared in `workflow/compiled.schema.json` before falling back to `raw/`.",
112
- "3. Use `raw/` for direct quotes, verification, exact table lookups, and cases where the compiled layer is missing or ambiguous.",
113
- "",
114
- "Answering rule:",
115
- "- do not modify files under `raw/`",
116
- "- treat the workflow package as the method layer and the compiled zones as the working retrieval surface",
117
- "- when a number is chart-derived, say that explicitly",
118
- "- use `raw/` to confirm source page, metric family, or provenance when the compiled layer is missing or ambiguous",
119
- ...chartNotes,
120
- "- when the compiled layer is insufficient, verify in `raw/` and then answer",
121
- "",
122
- "You can edit this file to bias manual question-answering behavior for this compiled dataset.",
123
- "",
124
- ].join("\n");
125
- }
126
- function renderRawTestAgents() {
127
- const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note}`);
128
- return [
129
- "# Raw Test Shell",
130
- "",
131
- "This is an isolated raw-files test shell generated by Interf Compiler.",
132
- "There is no compiled dataset in this shell.",
133
- "",
134
- "## How to use this shell",
135
- "",
136
- "1. Read this file first.",
137
- "2. Use the local native `interf-query` skill available in this shell.",
138
- "3. Read only from `raw/`.",
139
- "",
140
- "## Rules",
141
- "",
142
- "- Answer only from the files under `raw/`.",
143
- "- There is no compiled dataset here, so do not assume any compiled output zones exist.",
144
- "- Do not treat hidden runtime files or test artifacts as evidence.",
145
- ...chartNotes,
146
- "- Write the requested answer and trace files, then stop.",
147
- "",
148
- ].join("\n");
149
- }
150
- function renderRawTestQuerySkill() {
151
- const chartNotes = CHART_APPROXIMATION_NOTES.map((note, index) => `${index + 3}. ${note}`);
152
- return [
153
- "---",
154
- "name: interf-query",
155
- "description: >",
156
- " Native local query skill for an Interf raw test shell. Use it only",
157
- " to answer baseline questions directly from `raw/`.",
158
- "---",
159
- "",
160
- "# Interf Raw Test Query",
161
- "",
162
- "This is the native local query skill for an isolated raw-files test shell.",
163
- "",
164
- "Loop:",
165
- "1. Read `raw/` directly.",
166
- "2. Verify exact claims against the raw files before answering strongly.",
167
- ...chartNotes,
168
- "8. Do not rely on compiled dataset artifacts because they do not exist in this shell.",
169
- "",
170
- ].join("\n");
171
- }
172
- function readCompiledQuerySkillSource(compiledPath) {
173
- const filePath = compiledQuerySkillSourcePath(compiledPath);
174
- if (!existsSync(filePath)) {
175
- throw new Error(`Missing compiled query skill source at ${filePath}. Interf compile runs the local workflow package directly, so reseed or repair this compiled dataset instead of auto-healing query docs.`);
176
- }
177
- return readFileSync(filePath, "utf8").trim();
178
- }
179
- function stageShellWorkflowRoot(shellRoot) {
180
- return join(shellRoot, WORKFLOW_PACKAGE_DIR);
181
- }
182
- function shellInputZonePath(shellRoot, zoneId) {
183
- return join(shellRoot, "inputs", zoneId);
184
- }
185
- function shellOutputZonePath(shellRoot, zoneId) {
186
- return join(shellRoot, "outputs", zoneId);
187
- }
188
- function shellZoneAliasMountPath(shellRoot, zone, mountKind) {
189
- const mountRoot = mountKind === "inputs"
190
- ? shellInputZonePath(shellRoot, zone.id)
191
- : shellOutputZonePath(shellRoot, zone.id);
192
- return zone.kind === "file"
193
- ? join(mountRoot, basename(zone.path))
194
- : mountRoot;
195
- }
196
- function describeShellZoneAliasMountPath(zone, mountKind) {
197
- return zone.kind === "file"
198
- ? `${mountKind}/${zone.id}/${basename(zone.path)}`
199
- : `${mountKind}/${zone.id}`;
200
- }
201
- function shellRuntimePath(shellRoot, relativePath) {
202
- return join(shellRoot, "runtime", relativePath);
203
- }
204
- function writeIfChanged(path, content) {
205
- if (existsSync(path) && readFileSync(path, "utf8") === content) {
206
- return false;
207
- }
208
- mkdirSync(dirname(path), { recursive: true });
209
- writeFileSync(path, content);
210
- return true;
211
- }
212
- function writeNativeSkillCopies(rootPath, skillName, content) {
213
- let changed = false;
214
- for (const skillsRoot of LOCAL_SKILL_ROOTS) {
215
- const skillPath = join(rootPath, skillsRoot, skillName, "SKILL.md");
216
- changed = writeIfChanged(skillPath, content) || changed;
217
- }
218
- return changed;
219
- }
220
- function linkPath(targetPath, linkPathname) {
221
- mkdirSync(dirname(linkPathname), { recursive: true });
222
- symlinkSync(targetPath, linkPathname);
223
- }
224
- function linkRelativePath(targetPath, linkPathname) {
225
- mkdirSync(dirname(linkPathname), { recursive: true });
226
- symlinkSync(relative(dirname(linkPathname), targetPath), linkPathname);
227
- }
228
- function loadCompiledSchema(compiledPath) {
229
- const workflowRoot = workflowPackagePathForCompiled(compiledPath);
230
- const schema = readCompiledSchemaFile(workflowRoot);
231
- if (!schema) {
232
- throw new Error(`Missing workflow compiled schema at ${join(workflowRoot, "compiled.schema.json")}`);
233
- }
234
- return schema;
235
- }
236
- function zoneMap(schema) {
237
- return new Map(schema.zones.map((zone) => [zone.id, zone]));
238
- }
239
- function zoneOrThrow(zones, zoneId) {
240
- const zone = zones.get(zoneId);
241
- if (!zone) {
242
- throw new Error(`Missing compiled schema zone "${zoneId}" for stage shell projection.`);
243
- }
244
- return zone;
245
- }
246
- function normalizeArtifactRelativePath(path) {
247
- return path
248
- .replaceAll("\\", "/")
249
- .replace(/^\.?\//, "")
250
- .replace(/\/+$/g, "");
251
- }
252
- function relativePathEqualsOrWithin(basePath, candidatePath) {
253
- const base = normalizeArtifactRelativePath(basePath);
254
- const candidate = normalizeArtifactRelativePath(candidatePath);
255
- if (base.length === 0 || candidate.length === 0)
256
- return false;
257
- return candidate === base || candidate.startsWith(`${base}/`);
258
- }
259
- function stageWriteZoneSet(schema, stage) {
260
- return new Set(stage.writes.filter((zoneId) => schema.zones.some((zone) => zone.id === zoneId)));
261
- }
262
- function stageMaterializedZoneSet(schema, stage, writeArtifacts = []) {
263
- const materialized = stageWriteZoneSet(schema, stage);
264
- for (const zone of schema.zones) {
265
- if (zone.kind === "runtime" && stage.reads.includes(zone.id)) {
266
- materialized.add(zone.id);
267
- }
268
- }
269
- for (const artifactPath of writeArtifacts) {
270
- const normalizedArtifactPath = normalizeArtifactRelativePath(artifactPath);
271
- if (normalizedArtifactPath.length === 0)
272
- continue;
273
- const owner = schema.zones.find((zone) => relativePathEqualsOrWithin(zone.path, normalizedArtifactPath));
274
- if (owner) {
275
- materialized.add(owner.id);
276
- }
277
- }
278
- return materialized;
279
- }
280
- function ensureShellLocalProjection(sourcePath, targetPath, zone) {
281
- if (existsSync(sourcePath)) {
282
- copyResolvedTree({
283
- sourcePath,
284
- targetPath,
285
- shellType: "stage-execution",
286
- });
287
- return;
288
- }
289
- if (zone.kind === "file") {
290
- mkdirSync(dirname(targetPath), { recursive: true });
291
- return;
292
- }
293
- mkdirSync(targetPath, { recursive: true });
294
- }
295
- function ensureCompiledExecutionSurface(compiledPath) {
296
- mkdirSync(compiledRuntimeRoot(compiledPath), { recursive: true });
297
- mkdirSync(workflowPackagePathForCompiled(compiledPath), { recursive: true });
298
- const schema = loadCompiledSchema(compiledPath);
299
- ensureCompiledZoneTargets(compiledPath, schema);
300
- return schema;
301
- }
302
- function readStageMethodDoc(compiledPath, stage) {
303
- const path = join(workflowPackagePathForCompiled(compiledPath), "compile", "stages", stage.skillDir, "SKILL.md");
304
- if (!existsSync(path))
305
- return null;
306
- return readFileSync(path, "utf8").trim();
307
- }
308
- function stageWorkflowDocsPath(compiledPath, stage) {
309
- return join(workflowPackagePathForCompiled(compiledPath), "compile", "stages", stage.skillDir);
310
- }
311
- function renderStageExecutionAgents(compiledName, workflowId, stage) {
312
- return [
313
- `# ${compiledName} — ${stage.label} Execution Shell`,
314
- "",
315
- "This is an ephemeral stage-execution shell generated by Interf Compiler.",
316
- "It is for automated pipeline execution only, not for manual querying.",
317
- "",
318
- "## Start Here",
319
- "",
320
- "1. Read `runtime/stage-contract.json` now.",
321
- "2. Read `runtime/paths.json` now.",
322
- "3. Use the local native `interf-stage` skill now.",
323
- `4. Execute only the current stage: \`${stage.id}\` (${stage.label}).`,
324
- "",
325
- "## Shell ABI",
326
- "",
327
- "- `inputs/<zone-id>/` = read mounts for the current stage.",
328
- "- `outputs/<zone-id>/` = write mounts for the current stage.",
329
- "- For file zones, `runtime/paths.json` points to the exact file path inside those mount roots.",
330
- "- declared compiled zone paths are also projected at the shell root so workflow-relative contract paths stay valid.",
331
- "- `runtime/` = stage contract and machine-readable path map for this shell.",
332
- "- `workflow/` = workflow metadata, compiled schema, and docs for the current stage only.",
333
- "",
334
- "## Boundaries",
335
- "",
336
- `- Workflow: \`${workflowId}\`.`,
337
- `- Contract type: \`${stage.contractType}\`.`,
338
- "- This shell has its own AGENTS/CLAUDE/native skills. It does not inherit the compiled-dataset query shell.",
339
- "- The compiled dataset root itself is not linked into this shell.",
340
- "- Do not switch into query mode or act like a user-facing assistant.",
341
- "- Do not modify files under `inputs/` unless the same zone is also mounted under `outputs/`.",
342
- "",
343
- "## Current Stage Zones",
344
- "",
345
- `- reads: ${stage.reads.join(", ")}`,
346
- `- writes: ${stage.writes.join(", ")}`,
347
- "",
348
- "## Goal",
349
- "",
350
- "- complete the current stage",
351
- "- honor the deterministic contract",
352
- "- write outputs through the declared zone mounts",
353
- "- stop when the stage is complete",
354
- "",
355
- ].join("\n");
356
- }
357
- function renderStageExecutionSkill(stage, stageMethodDoc) {
358
- return [
359
- "---",
360
- "name: interf-stage",
361
- "description: >",
362
- ` Native local execution skill for the ${stage.label} stage in this`,
363
- " Interf Compiler run. Use it only inside an automated stage execution shell.",
364
- "---",
365
- "",
366
- `# Interf Compiler Stage Execution — ${stage.label}`,
367
- "",
368
- "This local native skill exists for automated Interf Compiler stage execution.",
369
- "Read `runtime/stage-contract.json` first.",
370
- "Then read `runtime/paths.json` and use the mounted `inputs/` and `outputs/` zones for this stage.",
371
- "Do not switch into manual query mode.",
372
- "",
373
- "## Current Stage",
374
- "",
375
- `- id: \`${stage.id}\``,
376
- `- label: ${stage.label}`,
377
- `- contract type: \`${stage.contractType}\``,
378
- `- reads: ${stage.reads.join(", ")}`,
379
- `- writes: ${stage.writes.join(", ")}`,
380
- `- editable source: \`workflow/compile/stages/${stage.skillDir}/SKILL.md\``,
381
- "",
382
- ...(stageMethodDoc
383
- ? [
384
- "## Stage Method",
385
- "",
386
- stageMethodDoc,
387
- "",
388
- ]
389
- : []),
390
- ].join("\n");
391
- }
392
- function renderCompiledQueryNativeSkill(querySkillContent) {
393
- return [
394
- "---",
395
- "name: interf-query",
396
- "description: >",
397
- " Native local query skill for this compiled dataset built by Interf",
398
- " Compiler. Use it for manual questions against the compiled dataset and",
399
- " its raw fallback.",
400
- "---",
401
- "",
402
- "# Interf Compiler Query",
403
- "",
404
- "This is the native local query skill for a compiled dataset built by Interf Compiler.",
405
- "Use it when reading this compiled dataset manually.",
406
- "Editable source: `.interf/workflow/use/query/SKILL.md`.",
407
- "",
408
- querySkillContent.trim(),
409
- "",
410
- ].join("\n");
411
- }
412
- function projectWorkflowMetadata(compiledPath, shellRoot, stage) {
413
- const shellWorkflowRoot = stageShellWorkflowRoot(shellRoot);
414
- mkdirSync(join(shellWorkflowRoot, "compile", "stages"), { recursive: true });
415
- const compiledWorkflowRoot = workflowPackagePathForCompiled(compiledPath);
416
- const workflowJsonPath = join(compiledWorkflowRoot, "workflow.json");
417
- if (existsSync(workflowJsonPath)) {
418
- linkPath(workflowJsonPath, join(shellWorkflowRoot, "workflow.json"));
419
- }
420
- const compiledSchemaPath = join(compiledWorkflowRoot, "compiled.schema.json");
421
- if (existsSync(compiledSchemaPath)) {
422
- linkPath(compiledSchemaPath, join(shellWorkflowRoot, "compiled.schema.json"));
423
- }
424
- const readmePath = join(compiledWorkflowRoot, "README.md");
425
- if (existsSync(readmePath)) {
426
- linkPath(readmePath, join(shellWorkflowRoot, "README.md"));
427
- }
428
- const stageDocsPath = stageWorkflowDocsPath(compiledPath, stage);
429
- if (existsSync(stageDocsPath)) {
430
- linkPath(stageDocsPath, join(shellWorkflowRoot, "compile", "stages", stage.skillDir));
431
- }
432
- }
433
- function projectCompiledSchemaZones(compiledPath, shellRoot, schema, zoneIds, materializedZoneIds) {
434
- const allowedZoneIds = zoneIds ? new Set(zoneIds) : null;
435
- for (const zone of schema.zones) {
436
- if (allowedZoneIds && !allowedZoneIds.has(zone.id))
437
- continue;
438
- const sourcePath = compiledZoneAbsolutePath(compiledPath, zone);
439
- const targetPath = join(shellRoot, zone.path);
440
- if (materializedZoneIds?.has(zone.id)) {
441
- ensureShellLocalProjection(sourcePath, targetPath, zone);
442
- continue;
443
- }
444
- linkPath(sourcePath, targetPath);
445
- }
446
- }
447
- function buildStageZoneMounts(compiledPath, shellRoot, stage, schema) {
448
- const zones = zoneMap(schema);
449
- const mountFor = (zoneId) => {
450
- const zone = zoneOrThrow(zones, zoneId);
451
- return {
452
- zone_id: zone.id,
453
- compiled_path: zone.path,
454
- shell_root_path: zone.path,
455
- input_mount_path: stage.reads.includes(zoneId)
456
- ? describeShellZoneAliasMountPath(zone, "inputs")
457
- : null,
458
- output_mount_path: stage.writes.includes(zoneId)
459
- ? describeShellZoneAliasMountPath(zone, "outputs")
460
- : null,
461
- };
462
- };
463
- return {
464
- reads: stage.reads.map(mountFor),
465
- writes: stage.writes.map(mountFor),
466
- };
467
- }
468
- function projectStageZoneMountAliases(shellRoot, stage, schema) {
469
- const zones = zoneMap(schema);
470
- for (const zoneId of new Set([...stage.reads, ...stage.writes])) {
471
- const zone = zoneOrThrow(zones, zoneId);
472
- const targetPath = join(shellRoot, zone.path);
473
- if (stage.reads.includes(zoneId)) {
474
- linkRelativePath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "inputs"));
475
- }
476
- if (stage.writes.includes(zoneId)) {
477
- linkRelativePath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "outputs"));
478
- }
479
- }
480
- }
481
- function writeExecutionShellPathsFile(shellRoot, workflowId, stage, mounts) {
482
- const paths = {
483
- kind: "interf-execution-shell",
484
- version: 1,
485
- workflow: workflowId,
486
- stage: stage.id,
487
- reads: mounts.reads,
488
- writes: mounts.writes,
489
- };
490
- writeFileSync(shellRuntimePath(shellRoot, "paths.json"), `${JSON.stringify(paths, null, 2)}\n`);
491
- }
492
- export function syncStageExecutionShellWrites(compiledPath, shellRoot, stage, writeArtifacts = []) {
493
- const schema = ensureCompiledExecutionSurface(compiledPath);
494
- const zones = zoneMap(schema);
495
- const stageWriteZones = Array.from(stageWriteZoneSet(schema, stage))
496
- .map((zoneId) => zoneOrThrow(zones, zoneId));
497
- for (const zone of stageWriteZones) {
498
- const canonicalShellZonePath = join(shellRoot, zone.path);
499
- const outputAliasPath = shellZoneAliasMountPath(shellRoot, zone, "outputs");
500
- const shellZonePath = zone.kind === "file" &&
501
- existsSync(outputAliasPath) &&
502
- !lstatSync(outputAliasPath).isSymbolicLink()
503
- ? outputAliasPath
504
- : canonicalShellZonePath;
505
- if (!existsSync(shellZonePath))
506
- continue;
507
- const shellZoneStat = lstatSync(shellZonePath);
508
- if (shellZoneStat.isSymbolicLink())
509
- continue;
510
- const compiledZonePath = compiledZoneAbsolutePath(compiledPath, zone);
511
- if (shellZoneStat.isDirectory()) {
512
- rmSync(compiledZonePath, { recursive: true, force: true });
513
- mkdirSync(dirname(compiledZonePath), { recursive: true });
514
- cpSync(shellZonePath, compiledZonePath, {
515
- recursive: true,
516
- force: true,
517
- });
518
- continue;
519
- }
520
- mkdirSync(dirname(compiledZonePath), { recursive: true });
521
- copyFileSync(shellZonePath, compiledZonePath);
522
- }
523
- for (const artifactPath of writeArtifacts) {
524
- const normalizedArtifactPath = normalizeArtifactRelativePath(artifactPath);
525
- if (normalizedArtifactPath.length === 0 ||
526
- stageWriteZones.some((zone) => relativePathEqualsOrWithin(zone.path, normalizedArtifactPath))) {
527
- continue;
528
- }
529
- const shellArtifactPath = join(shellRoot, normalizedArtifactPath);
530
- if (!existsSync(shellArtifactPath))
531
- continue;
532
- const compiledArtifactPath = join(compiledPath, normalizedArtifactPath);
533
- const shellArtifactStat = lstatSync(shellArtifactPath);
534
- if (shellArtifactStat.isSymbolicLink())
535
- continue;
536
- if (shellArtifactStat.isDirectory()) {
537
- rmSync(compiledArtifactPath, { recursive: true, force: true });
538
- mkdirSync(dirname(compiledArtifactPath), { recursive: true });
539
- cpSync(shellArtifactPath, compiledArtifactPath, {
540
- recursive: true,
541
- force: true,
542
- });
543
- continue;
544
- }
545
- mkdirSync(dirname(compiledArtifactPath), { recursive: true });
546
- copyFileSync(shellArtifactPath, compiledArtifactPath);
547
- }
548
- }
549
- function preservedShellManifestPath(rootPath) {
550
- return shellRuntimePath(rootPath, "preserved-shell.json");
551
- }
552
- function shouldSkipFrozenStageShellRelativePath(relativePath) {
553
- const normalized = relativePath.replaceAll("\\", "/");
554
- return normalized === "execution-shells" ||
555
- normalized.endsWith("/execution-shells") ||
556
- normalized.includes("/execution-shells/") ||
557
- normalized === "improvement-loops" ||
558
- normalized.endsWith("/improvement-loops") ||
559
- normalized.includes("/improvement-loops/");
560
- }
561
- function copyResolvedTree(options) {
562
- const relativePath = options.relativePath ?? "";
563
- if (options.shellType === "stage-execution" && shouldSkipFrozenStageShellRelativePath(relativePath)) {
564
- return { materializedSymlinks: 0 };
565
- }
566
- const stat = lstatSync(options.sourcePath);
567
- if (stat.isSymbolicLink()) {
568
- const realTarget = realpathSync(options.sourcePath);
569
- const realStat = statSync(realTarget);
570
- if (realStat.isDirectory()) {
571
- const mappedTarget = options.materializedRealPaths?.get(realTarget);
572
- if (mappedTarget) {
573
- linkRelativePath(mappedTarget, options.targetPath);
574
- return { materializedSymlinks: 1 };
575
- }
576
- return {
577
- materializedSymlinks: 1 + copyResolvedTree({
578
- sourcePath: realTarget,
579
- targetPath: options.targetPath,
580
- shellType: options.shellType,
581
- relativePath,
582
- activeRealPaths: options.activeRealPaths,
583
- materializedRealPaths: options.materializedRealPaths,
584
- }).materializedSymlinks,
585
- };
586
- }
587
- mkdirSync(dirname(options.targetPath), { recursive: true });
588
- copyFileSync(realTarget, options.targetPath);
589
- return { materializedSymlinks: 1 };
590
- }
591
- if (stat.isDirectory()) {
592
- const realSource = realpathSync(options.sourcePath);
593
- const mappedTarget = options.materializedRealPaths?.get(realSource);
594
- if (mappedTarget && mappedTarget !== options.targetPath) {
595
- linkRelativePath(mappedTarget, options.targetPath);
596
- return { materializedSymlinks: 0 };
597
- }
598
- const nextRealPaths = new Set([...(options.activeRealPaths ?? []), realSource]);
599
- const nextMaterializedRealPaths = new Map(options.materializedRealPaths ?? []);
600
- nextMaterializedRealPaths.set(realSource, options.targetPath);
601
- mkdirSync(options.targetPath, { recursive: true });
602
- let materializedSymlinks = 0;
603
- for (const entry of readdirSync(options.sourcePath)) {
604
- const childRelativePath = relativePath.length > 0 ? `${relativePath}/${entry}` : entry;
605
- const copied = copyResolvedTree({
606
- sourcePath: join(options.sourcePath, entry),
607
- targetPath: join(options.targetPath, entry),
608
- shellType: options.shellType,
609
- relativePath: childRelativePath,
610
- activeRealPaths: nextRealPaths,
611
- materializedRealPaths: nextMaterializedRealPaths,
612
- });
613
- materializedSymlinks += copied.materializedSymlinks;
614
- }
615
- return { materializedSymlinks };
616
- }
617
- mkdirSync(dirname(options.targetPath), { recursive: true });
618
- copyFileSync(options.sourcePath, options.targetPath);
619
- return { materializedSymlinks: 0 };
620
- }
621
- function freezePreservedShell(rootPath, shellType) {
622
- if (!existsSync(rootPath))
623
- return null;
624
- const manifestPath = preservedShellManifestPath(rootPath);
625
- if (existsSync(manifestPath))
626
- return manifestPath;
627
- const tempRoot = `${rootPath}.frozen-${Date.now().toString(36)}`;
628
- const copied = copyResolvedTree({
629
- sourcePath: rootPath,
630
- targetPath: tempRoot,
631
- shellType,
632
- });
633
- const manifest = {
634
- kind: "interf-preserved-shell",
635
- version: 1,
636
- shell_type: shellType,
637
- generated_at: new Date().toISOString(),
638
- root_path: rootPath,
639
- materialized_symlinks: copied.materializedSymlinks,
640
- };
641
- writeFileSync(preservedShellManifestPath(tempRoot), `${JSON.stringify(manifest, null, 2)}\n`);
642
- rmSync(rootPath, { recursive: true, force: true });
643
- renameSync(tempRoot, rootPath);
644
- return manifestPath;
645
- }
646
- export function renderClaudeBootstrap(content) {
647
- return [
648
- "<!-- Generated compatibility mirror of AGENTS.md. Interf Compiler may rewrite this file. -->",
649
- "",
650
- content.trimEnd(),
651
- "",
652
- ].join("\n");
653
- }
654
- function improvementWorkflowDocsPath(compiledPath) {
655
- return join(workflowPackagePathForCompiled(compiledPath), "improve");
656
- }
657
- function renderWorkflowImprovementAgents(compiledName, workflowId, loopIndex) {
658
- return [
659
- `# ${compiledName} — Workflow Improvement Shell`,
660
- "",
661
- "This is an automated workflow-improvement shell generated by Interf Compiler.",
662
- "It exists to review failed compile/test runs and edit the workflow package for the next variation.",
663
- "",
664
- "## Start Here",
665
- "",
666
- "1. Read `runtime/loop-context.json` now.",
667
- "2. Read `workflow/README.md`, `workflow/workflow.json`, and `workflow/compiled.schema.json` now.",
668
- "3. Read `workflow/improve/SKILL.md` now.",
669
- "4. Use the local native `interf-workflow-improver` skill now.",
670
- "",
671
- "## Boundaries",
672
- "",
673
- `- Workflow: \`${workflowId}\`.`,
674
- `- Improvement loop: ${loopIndex}.`,
675
- "- Edit only files under `workflow/`.",
676
- "- Do not edit truth checks, test specs, raw dataset files, or generated compiled outputs.",
677
- "- Review compiled outputs under `artifacts/compiled-view/` and test/runtime evidence under `artifacts/`.",
678
- "- Keep the workflow valid for the current compiler API and compiled schema.",
679
- "",
680
- "## Goal",
681
- "",
682
- "- create a better workflow variation for this dataset",
683
- "- preserve deterministic compiled structure",
684
- "- stop after the workflow edits are complete",
685
- "",
686
- ].join("\n");
687
- }
688
- function readWorkflowImprovementDoc(compiledPath) {
689
- const path = join(improvementWorkflowDocsPath(compiledPath), "SKILL.md");
690
- if (!existsSync(path))
691
- return null;
692
- return readFileSync(path, "utf8").trim();
693
- }
694
- function renderWorkflowImprovementSkill(workflowId, loopIndex, improvementDoc) {
695
- return [
696
- "---",
697
- "name: interf-workflow-improver",
698
- "description: >",
699
- " Native local workflow-improvement skill for this Interf Compiler run.",
700
- " Use it only inside an automated workflow-improvement shell.",
701
- "---",
702
- "",
703
- `# Interf Compiler Workflow Improvement — ${workflowId}`,
704
- "",
705
- "This local native skill exists for automated workflow-improvement loops.",
706
- "Read `runtime/loop-context.json` first.",
707
- "Then review the linked workflow package, `artifacts/compiled-view/`, preserved stage shells, runtime logs, and saved test outputs before editing `workflow/`.",
708
- "",
709
- "## Current Loop",
710
- "",
711
- `- workflow: \`${workflowId}\``,
712
- `- loop index: ${loopIndex}`,
713
- "- editable source: `workflow/improve/SKILL.md`",
714
- "",
715
- ...(improvementDoc
716
- ? [
717
- "## Improvement Method",
718
- "",
719
- improvementDoc,
720
- "",
721
- ]
722
- : []),
723
- ].join("\n");
724
- }
725
- function projectCompiledReviewArtifactsSnapshot(compiledPath, shellRoot, schema) {
726
- const compiledViewRoot = join(shellRoot, "artifacts", "compiled-view");
727
- mkdirSync(compiledViewRoot, { recursive: true });
728
- for (const zone of schema.zones) {
729
- if (zone.kind === "runtime" || zone.path === "raw")
730
- continue;
731
- const sourcePath = compiledZoneAbsolutePath(compiledPath, zone);
732
- if (!existsSync(sourcePath))
733
- continue;
734
- copyResolvedTree({
735
- sourcePath,
736
- targetPath: join(compiledViewRoot, zone.path),
737
- shellType: "workflow-improvement",
738
- });
739
- }
740
- }
741
- function linkIfExists(targetPath, linkPathname) {
742
- if (!existsSync(targetPath))
743
- return;
744
- linkPath(targetPath, linkPathname);
745
- }
746
- function copyIfExists(sourcePath, targetPath, shellType) {
747
- if (!existsSync(sourcePath))
748
- return;
749
- copyResolvedTree({
750
- sourcePath,
751
- targetPath,
752
- shellType,
753
- });
754
- }
755
- function projectCompiledRuntimeArtifacts(compiledPath, shellRoot) {
756
- const runtimeTarget = join(shellRoot, "artifacts", "compiled-runtime");
757
- mkdirSync(runtimeTarget, { recursive: true });
758
- const runtimeRoot = compiledRuntimeRoot(compiledPath);
759
- const artifactNames = [
760
- "run.json",
761
- "run-history.jsonl",
762
- "state.json",
763
- "health.json",
764
- "view-spec.json",
765
- "raw-snapshot.json",
766
- "logs",
767
- ];
768
- for (const artifactName of artifactNames) {
769
- copyIfExists(join(runtimeRoot, artifactName), join(runtimeTarget, artifactName), "workflow-improvement");
770
- }
771
- }
772
- export function pruneStageExecutionShells(compiledPath) {
773
- rmSync(stageExecutionShellsRoot(compiledPath), { recursive: true, force: true });
774
- }
775
- export function projectCompiledQueryShell(compiledPath, compiledName, workflowId, about, options) {
776
- const agentsContent = renderCompiledAgents(compiledPath, compiledName, workflowId, about, options);
777
- const querySkillContent = readCompiledQuerySkillSource(compiledPath);
778
- return writeNativeAgentSurface(compiledPath, agentsContent, "interf-query", renderCompiledQueryNativeSkill(querySkillContent));
779
- }
780
- export function projectRawTestQueryShell(rootPath) {
781
- return writeNativeAgentSurface(rootPath, renderRawTestAgents(), "interf-query", renderRawTestQuerySkill());
782
- }
783
- export function createStageExecutionShell(compiledPath, compiledName, workflowId, stage, writeArtifacts = []) {
784
- const schema = ensureCompiledExecutionSurface(compiledPath);
785
- const materializedZones = stageMaterializedZoneSet(schema, stage, writeArtifacts);
786
- const shellsRoot = stageExecutionShellsRoot(compiledPath);
787
- const shellRoot = join(shellsRoot, `${stage.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`);
788
- mkdirSync(shellRoot, { recursive: true });
789
- mkdirSync(join(shellRoot, "runtime"), { recursive: true });
790
- mkdirSync(join(shellRoot, "inputs"), { recursive: true });
791
- mkdirSync(join(shellRoot, "outputs"), { recursive: true });
792
- linkPath(compiledInterfConfigPath(compiledPath), join(shellRoot, "interf.json"));
793
- linkPath(join(compiledRuntimeRoot(compiledPath), "stage-contract.json"), shellRuntimePath(shellRoot, "stage-contract.json"));
794
- projectCompiledSchemaZones(compiledPath, shellRoot, schema, new Set([...stage.reads, ...stage.writes]), materializedZones);
795
- projectWorkflowMetadata(compiledPath, shellRoot, stage);
796
- projectStageZoneMountAliases(shellRoot, stage, schema);
797
- writeExecutionShellPathsFile(shellRoot, workflowId, stage, buildStageZoneMounts(compiledPath, shellRoot, stage, schema));
798
- const agentsContent = renderStageExecutionAgents(compiledName, workflowId, stage);
799
- writeNativeAgentSurface(shellRoot, agentsContent, "interf-stage", renderStageExecutionSkill(stage, readStageMethodDoc(compiledPath, stage)));
800
- return {
801
- rootPath: shellRoot,
802
- };
803
- }
804
- export function freezeStageExecutionShell(rootPath) {
805
- return freezePreservedShell(rootPath, "stage-execution");
806
- }
807
- export function createWorkflowImprovementShell(options) {
808
- const schema = ensureCompiledExecutionSurface(options.compiledPath);
809
- const loopRootPath = workflowImprovementLoopRoot(options.compiledPath, options.runId, options.loopIndex);
810
- const shellRoot = join(loopRootPath, "shell");
811
- mkdirSync(shellRoot, { recursive: true });
812
- mkdirSync(join(shellRoot, "runtime"), { recursive: true });
813
- mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
814
- mkdirSync(join(loopRootPath, "logs"), { recursive: true });
815
- writeFileSync(join(shellRoot, "runtime", "loop-context.json"), `${JSON.stringify(options.context, null, 2)}\n`);
816
- projectCompiledReviewArtifactsSnapshot(options.compiledPath, shellRoot, schema);
817
- linkPath(workflowPackagePathForCompiled(options.compiledPath), join(shellRoot, "workflow"));
818
- copyIfExists(compiledInterfConfigPath(options.compiledPath), join(shellRoot, "interf.json"), "workflow-improvement");
819
- projectCompiledRuntimeArtifacts(options.compiledPath, shellRoot);
820
- const reviewSources = resolveWorkflowImprovementReviewSourcePaths(options.compiledPath);
821
- if (reviewSources.executionShells) {
822
- copyIfExists(reviewSources.executionShells, join(shellRoot, "artifacts", "execution-shells"), "workflow-improvement");
823
- }
824
- if (reviewSources.testComparisons) {
825
- copyIfExists(reviewSources.testComparisons, join(shellRoot, "artifacts", "test-comparisons"), "workflow-improvement");
826
- }
827
- if (reviewSources.targetTestRuns) {
828
- copyIfExists(reviewSources.targetTestRuns, join(shellRoot, "artifacts", "test-runs"), "workflow-improvement");
829
- }
830
- if (reviewSources.targetTestSandboxes) {
831
- copyIfExists(reviewSources.targetTestSandboxes, join(shellRoot, "artifacts", "test-sandboxes"), "workflow-improvement");
832
- }
833
- const agentsContent = renderWorkflowImprovementAgents(options.compiledName, options.workflowId, options.loopIndex);
834
- writeNativeAgentSurface(shellRoot, agentsContent, "interf-workflow-improver", renderWorkflowImprovementSkill(options.workflowId, options.loopIndex, readWorkflowImprovementDoc(options.compiledPath)));
835
- return {
836
- rootPath: shellRoot,
837
- loopRootPath,
838
- workflowBeforePath: join(loopRootPath, "workflow-before"),
839
- workflowAfterPath: join(loopRootPath, "workflow-after"),
840
- promptLogPath: join(loopRootPath, "logs", "workflow-improver.prompt.txt"),
841
- eventLogPath: join(loopRootPath, "logs", "workflow-improver.events.ndjson"),
842
- statusLogPath: join(loopRootPath, "logs", "workflow-improver.status.log"),
843
- };
844
- }
845
- export function freezeWorkflowImprovementShell(rootPath) {
846
- return freezePreservedShell(rootPath, "workflow-improvement");
847
- }
1
+ export * from "../packages/agents/lib/shells.js";