@interf/compiler 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/README.md +137 -243
  2. package/builtin-workflows/interf/README.md +19 -0
  3. package/builtin-workflows/interf/compile/stages/shape/SKILL.md +28 -0
  4. package/builtin-workflows/interf/compile/stages/structure/SKILL.md +18 -0
  5. package/builtin-workflows/interf/compile/stages/summarize/SKILL.md +18 -0
  6. package/builtin-workflows/interf/improve/SKILL.md +18 -0
  7. package/builtin-workflows/interf/use/query/SKILL.md +28 -0
  8. package/builtin-workflows/interf/workflow.json +120 -0
  9. package/builtin-workflows/interf/workspace.schema.json +75 -0
  10. package/dist/bin.d.ts +0 -1
  11. package/dist/bin.js +0 -1
  12. package/dist/commands/compile-controller.d.ts +14 -0
  13. package/dist/commands/compile-controller.js +409 -0
  14. package/dist/commands/compile.d.ts +8 -9
  15. package/dist/commands/compile.js +151 -153
  16. package/dist/commands/create-workflow-wizard.d.ts +4 -2
  17. package/dist/commands/create-workflow-wizard.js +33 -31
  18. package/dist/commands/create.d.ts +0 -1
  19. package/dist/commands/create.js +16 -12
  20. package/dist/commands/default.d.ts +0 -1
  21. package/dist/commands/default.js +1 -2
  22. package/dist/commands/doctor.d.ts +0 -1
  23. package/dist/commands/doctor.js +7 -22
  24. package/dist/commands/executor-flow.d.ts +0 -1
  25. package/dist/commands/executor-flow.js +0 -1
  26. package/dist/commands/init.d.ts +0 -1
  27. package/dist/commands/init.js +72 -15
  28. package/dist/commands/list.d.ts +0 -1
  29. package/dist/commands/list.js +0 -1
  30. package/dist/commands/reset.d.ts +0 -1
  31. package/dist/commands/reset.js +0 -1
  32. package/dist/commands/source-config-wizard.d.ts +28 -7
  33. package/dist/commands/source-config-wizard.js +159 -63
  34. package/dist/commands/status.d.ts +0 -1
  35. package/dist/commands/status.js +0 -1
  36. package/dist/commands/test-flow.d.ts +20 -10
  37. package/dist/commands/test-flow.js +89 -23
  38. package/dist/commands/test.d.ts +0 -1
  39. package/dist/commands/test.js +36 -72
  40. package/dist/commands/verify.d.ts +0 -1
  41. package/dist/commands/verify.js +0 -1
  42. package/dist/commands/workspace-flow.d.ts +3 -3
  43. package/dist/commands/workspace-flow.js +30 -12
  44. package/dist/index.d.ts +5 -6
  45. package/dist/index.js +3 -4
  46. package/dist/lib/agent-args.d.ts +0 -1
  47. package/dist/lib/agent-args.js +0 -1
  48. package/dist/lib/agent-constants.d.ts +0 -1
  49. package/dist/lib/agent-constants.js +0 -1
  50. package/dist/lib/agent-detection.d.ts +0 -1
  51. package/dist/lib/agent-detection.js +0 -1
  52. package/dist/lib/agent-execution.d.ts +0 -1
  53. package/dist/lib/agent-execution.js +47 -12
  54. package/dist/lib/agent-logs.d.ts +0 -1
  55. package/dist/lib/agent-logs.js +0 -1
  56. package/dist/lib/agent-preflight.d.ts +0 -1
  57. package/dist/lib/agent-preflight.js +1 -2
  58. package/dist/lib/agent-render.d.ts +0 -1
  59. package/dist/lib/agent-render.js +0 -1
  60. package/dist/lib/agent-shells.d.ts +30 -3
  61. package/dist/lib/agent-shells.js +527 -63
  62. package/dist/lib/agent-status.d.ts +0 -1
  63. package/dist/lib/agent-status.js +0 -1
  64. package/dist/lib/agent-types.d.ts +0 -1
  65. package/dist/lib/agent-types.js +0 -1
  66. package/dist/lib/agents.d.ts +0 -9
  67. package/dist/lib/agents.js +0 -9
  68. package/dist/lib/chart-guidance.d.ts +1 -0
  69. package/dist/lib/chart-guidance.js +8 -0
  70. package/dist/lib/config.d.ts +0 -3
  71. package/dist/lib/config.js +0 -5
  72. package/dist/lib/discovery.d.ts +0 -1
  73. package/dist/lib/discovery.js +0 -1
  74. package/dist/lib/execution-profile.d.ts +0 -1
  75. package/dist/lib/execution-profile.js +0 -1
  76. package/dist/lib/executors.d.ts +0 -1
  77. package/dist/lib/executors.js +0 -1
  78. package/dist/lib/filesystem.d.ts +0 -1
  79. package/dist/lib/filesystem.js +0 -1
  80. package/dist/lib/interf-bootstrap.d.ts +0 -1
  81. package/dist/lib/interf-bootstrap.js +6 -2
  82. package/dist/lib/interf-detect.d.ts +2 -2
  83. package/dist/lib/interf-detect.js +25 -8
  84. package/dist/lib/interf-scaffold.d.ts +0 -1
  85. package/dist/lib/interf-scaffold.js +54 -21
  86. package/dist/lib/interf-workflow-package.d.ts +18 -1
  87. package/dist/lib/interf-workflow-package.js +164 -23
  88. package/dist/lib/interf.d.ts +1 -2
  89. package/dist/lib/interf.js +1 -2
  90. package/dist/lib/local-workflows.d.ts +10 -5
  91. package/dist/lib/local-workflows.js +208 -97
  92. package/dist/lib/logger.d.ts +0 -1
  93. package/dist/lib/logger.js +0 -1
  94. package/dist/lib/obsidian.d.ts +0 -1
  95. package/dist/lib/obsidian.js +0 -1
  96. package/dist/lib/parse.d.ts +0 -1
  97. package/dist/lib/parse.js +0 -1
  98. package/dist/lib/registry.d.ts +0 -1
  99. package/dist/lib/registry.js +0 -1
  100. package/dist/lib/runtime-acceptance.d.ts +0 -1
  101. package/dist/lib/runtime-acceptance.js +1 -2
  102. package/dist/lib/runtime-contracts.d.ts +0 -1
  103. package/dist/lib/runtime-contracts.js +14 -8
  104. package/dist/lib/runtime-paths.d.ts +0 -1
  105. package/dist/lib/runtime-paths.js +5 -10
  106. package/dist/lib/runtime-prompt.d.ts +0 -1
  107. package/dist/lib/runtime-prompt.js +8 -23
  108. package/dist/lib/runtime-reconcile.d.ts +0 -1
  109. package/dist/lib/runtime-reconcile.js +7 -3
  110. package/dist/lib/runtime-runs.d.ts +0 -1
  111. package/dist/lib/runtime-runs.js +4 -5
  112. package/dist/lib/runtime-types.d.ts +0 -1
  113. package/dist/lib/runtime-types.js +0 -1
  114. package/dist/lib/runtime.d.ts +0 -1
  115. package/dist/lib/runtime.js +0 -1
  116. package/dist/lib/schema.d.ts +356 -51
  117. package/dist/lib/schema.js +189 -54
  118. package/dist/lib/source-config.d.ts +17 -8
  119. package/dist/lib/source-config.js +125 -11
  120. package/dist/lib/state-artifacts.d.ts +0 -1
  121. package/dist/lib/state-artifacts.js +0 -1
  122. package/dist/lib/state-health.d.ts +0 -1
  123. package/dist/lib/state-health.js +2 -3
  124. package/dist/lib/state-io.d.ts +1 -1
  125. package/dist/lib/state-io.js +9 -10
  126. package/dist/lib/state-paths.d.ts +0 -1
  127. package/dist/lib/state-paths.js +5 -11
  128. package/dist/lib/state-view.d.ts +0 -1
  129. package/dist/lib/state-view.js +7 -8
  130. package/dist/lib/state.d.ts +0 -1
  131. package/dist/lib/state.js +0 -1
  132. package/dist/lib/summarize-plan.d.ts +0 -1
  133. package/dist/lib/summarize-plan.js +3 -3
  134. package/dist/lib/test-execution.d.ts +14 -0
  135. package/dist/lib/{benchmark-execution.js → test-execution.js} +122 -120
  136. package/dist/lib/test-matrices.d.ts +90 -0
  137. package/dist/lib/test-matrices.js +96 -0
  138. package/dist/lib/test-paths.d.ts +12 -0
  139. package/dist/lib/test-paths.js +44 -0
  140. package/dist/lib/test-profile-presets.d.ts +57 -0
  141. package/dist/lib/test-profile-presets.js +50 -0
  142. package/dist/lib/test-sandbox.d.ts +11 -0
  143. package/dist/lib/{benchmark-sandbox.js → test-sandbox.js} +18 -13
  144. package/dist/lib/test-specs.d.ts +7 -0
  145. package/dist/lib/test-specs.js +114 -0
  146. package/dist/lib/test-targets.d.ts +5 -0
  147. package/dist/lib/test-targets.js +38 -0
  148. package/dist/lib/test-types.d.ts +17 -0
  149. package/dist/lib/test-types.js +1 -0
  150. package/dist/lib/test.d.ts +4 -0
  151. package/dist/lib/test.js +3 -0
  152. package/dist/lib/user-config.d.ts +0 -1
  153. package/dist/lib/user-config.js +0 -1
  154. package/dist/lib/util.d.ts +0 -2
  155. package/dist/lib/util.js +0 -2
  156. package/dist/lib/validate-helpers.d.ts +0 -1
  157. package/dist/lib/validate-helpers.js +0 -1
  158. package/dist/lib/validate-workspace.d.ts +0 -1
  159. package/dist/lib/validate-workspace.js +34 -25
  160. package/dist/lib/validate.d.ts +0 -1
  161. package/dist/lib/validate.js +55 -9
  162. package/dist/lib/workflow-abi.d.ts +138 -0
  163. package/dist/lib/workflow-abi.js +181 -0
  164. package/dist/lib/workflow-definitions.d.ts +26 -5
  165. package/dist/lib/workflow-definitions.js +105 -168
  166. package/dist/lib/workflow-helpers.d.ts +1 -2
  167. package/dist/lib/workflow-helpers.js +32 -21
  168. package/dist/lib/workflow-improvement.d.ts +22 -0
  169. package/dist/lib/workflow-improvement.js +396 -0
  170. package/dist/lib/workflow-review-paths.d.ts +10 -0
  171. package/dist/lib/workflow-review-paths.js +27 -0
  172. package/dist/lib/workflow-stage-runner.d.ts +1 -1
  173. package/dist/lib/workflow-stage-runner.js +4 -1
  174. package/dist/lib/workflows.d.ts +1 -2
  175. package/dist/lib/workflows.js +1 -2
  176. package/dist/lib/workspace-compile.d.ts +0 -1
  177. package/dist/lib/workspace-compile.js +146 -109
  178. package/dist/lib/workspace-home.d.ts +5 -0
  179. package/dist/lib/workspace-home.js +32 -0
  180. package/dist/lib/workspace-layout.d.ts +2 -0
  181. package/dist/lib/workspace-layout.js +60 -0
  182. package/dist/lib/workspace-paths.d.ts +41 -0
  183. package/dist/lib/workspace-paths.js +107 -0
  184. package/dist/lib/workspace-raw.d.ts +20 -2
  185. package/dist/lib/workspace-raw.js +6 -8
  186. package/dist/lib/workspace-reset.d.ts +0 -1
  187. package/dist/lib/workspace-reset.js +27 -5
  188. package/dist/lib/workspace-schema.d.ts +1 -10
  189. package/dist/lib/workspace-schema.js +16 -74
  190. package/package.json +17 -16
  191. package/dist/bin.d.ts.map +0 -1
  192. package/dist/bin.js.map +0 -1
  193. package/dist/commands/compile.d.ts.map +0 -1
  194. package/dist/commands/compile.js.map +0 -1
  195. package/dist/commands/create-workflow-wizard.d.ts.map +0 -1
  196. package/dist/commands/create-workflow-wizard.js.map +0 -1
  197. package/dist/commands/create.d.ts.map +0 -1
  198. package/dist/commands/create.js.map +0 -1
  199. package/dist/commands/default.d.ts.map +0 -1
  200. package/dist/commands/default.js.map +0 -1
  201. package/dist/commands/doctor.d.ts.map +0 -1
  202. package/dist/commands/doctor.js.map +0 -1
  203. package/dist/commands/executor-flow.d.ts.map +0 -1
  204. package/dist/commands/executor-flow.js.map +0 -1
  205. package/dist/commands/init.d.ts.map +0 -1
  206. package/dist/commands/init.js.map +0 -1
  207. package/dist/commands/list.d.ts.map +0 -1
  208. package/dist/commands/list.js.map +0 -1
  209. package/dist/commands/reset.d.ts.map +0 -1
  210. package/dist/commands/reset.js.map +0 -1
  211. package/dist/commands/source-config-wizard.d.ts.map +0 -1
  212. package/dist/commands/source-config-wizard.js.map +0 -1
  213. package/dist/commands/status.d.ts.map +0 -1
  214. package/dist/commands/status.js.map +0 -1
  215. package/dist/commands/test-flow.d.ts.map +0 -1
  216. package/dist/commands/test-flow.js.map +0 -1
  217. package/dist/commands/test.d.ts.map +0 -1
  218. package/dist/commands/test.js.map +0 -1
  219. package/dist/commands/verify.d.ts.map +0 -1
  220. package/dist/commands/verify.js.map +0 -1
  221. package/dist/commands/workspace-flow.d.ts.map +0 -1
  222. package/dist/commands/workspace-flow.js.map +0 -1
  223. package/dist/index.d.ts.map +0 -1
  224. package/dist/index.js.map +0 -1
  225. package/dist/lib/agent-args.d.ts.map +0 -1
  226. package/dist/lib/agent-args.js.map +0 -1
  227. package/dist/lib/agent-constants.d.ts.map +0 -1
  228. package/dist/lib/agent-constants.js.map +0 -1
  229. package/dist/lib/agent-detection.d.ts.map +0 -1
  230. package/dist/lib/agent-detection.js.map +0 -1
  231. package/dist/lib/agent-execution.d.ts.map +0 -1
  232. package/dist/lib/agent-execution.js.map +0 -1
  233. package/dist/lib/agent-logs.d.ts.map +0 -1
  234. package/dist/lib/agent-logs.js.map +0 -1
  235. package/dist/lib/agent-preflight.d.ts.map +0 -1
  236. package/dist/lib/agent-preflight.js.map +0 -1
  237. package/dist/lib/agent-render.d.ts.map +0 -1
  238. package/dist/lib/agent-render.js.map +0 -1
  239. package/dist/lib/agent-shells.d.ts.map +0 -1
  240. package/dist/lib/agent-shells.js.map +0 -1
  241. package/dist/lib/agent-skills.d.ts +0 -21
  242. package/dist/lib/agent-skills.d.ts.map +0 -1
  243. package/dist/lib/agent-skills.js +0 -215
  244. package/dist/lib/agent-skills.js.map +0 -1
  245. package/dist/lib/agent-status.d.ts.map +0 -1
  246. package/dist/lib/agent-status.js.map +0 -1
  247. package/dist/lib/agent-types.d.ts.map +0 -1
  248. package/dist/lib/agent-types.js.map +0 -1
  249. package/dist/lib/agents.d.ts.map +0 -1
  250. package/dist/lib/agents.js.map +0 -1
  251. package/dist/lib/benchmark-execution.d.ts +0 -13
  252. package/dist/lib/benchmark-execution.d.ts.map +0 -1
  253. package/dist/lib/benchmark-execution.js.map +0 -1
  254. package/dist/lib/benchmark-paths.d.ts +0 -13
  255. package/dist/lib/benchmark-paths.d.ts.map +0 -1
  256. package/dist/lib/benchmark-paths.js +0 -44
  257. package/dist/lib/benchmark-paths.js.map +0 -1
  258. package/dist/lib/benchmark-sandbox.d.ts +0 -12
  259. package/dist/lib/benchmark-sandbox.d.ts.map +0 -1
  260. package/dist/lib/benchmark-sandbox.js.map +0 -1
  261. package/dist/lib/benchmark-specs.d.ts +0 -8
  262. package/dist/lib/benchmark-specs.d.ts.map +0 -1
  263. package/dist/lib/benchmark-specs.js +0 -115
  264. package/dist/lib/benchmark-specs.js.map +0 -1
  265. package/dist/lib/benchmark-targets.d.ts +0 -5
  266. package/dist/lib/benchmark-targets.d.ts.map +0 -1
  267. package/dist/lib/benchmark-targets.js +0 -38
  268. package/dist/lib/benchmark-targets.js.map +0 -1
  269. package/dist/lib/benchmark-types.d.ts +0 -18
  270. package/dist/lib/benchmark-types.d.ts.map +0 -1
  271. package/dist/lib/benchmark-types.js +0 -2
  272. package/dist/lib/benchmark-types.js.map +0 -1
  273. package/dist/lib/benchmark.d.ts +0 -5
  274. package/dist/lib/benchmark.d.ts.map +0 -1
  275. package/dist/lib/benchmark.js +0 -4
  276. package/dist/lib/benchmark.js.map +0 -1
  277. package/dist/lib/config.d.ts.map +0 -1
  278. package/dist/lib/config.js.map +0 -1
  279. package/dist/lib/discovery.d.ts.map +0 -1
  280. package/dist/lib/discovery.js.map +0 -1
  281. package/dist/lib/eval-packs.d.ts +0 -158
  282. package/dist/lib/eval-packs.d.ts.map +0 -1
  283. package/dist/lib/eval-packs.js +0 -149
  284. package/dist/lib/eval-packs.js.map +0 -1
  285. package/dist/lib/execution-profile.d.ts.map +0 -1
  286. package/dist/lib/execution-profile.js.map +0 -1
  287. package/dist/lib/executors.d.ts.map +0 -1
  288. package/dist/lib/executors.js.map +0 -1
  289. package/dist/lib/filesystem.d.ts.map +0 -1
  290. package/dist/lib/filesystem.js.map +0 -1
  291. package/dist/lib/interf-bootstrap.d.ts.map +0 -1
  292. package/dist/lib/interf-bootstrap.js.map +0 -1
  293. package/dist/lib/interf-detect.d.ts.map +0 -1
  294. package/dist/lib/interf-detect.js.map +0 -1
  295. package/dist/lib/interf-scaffold.d.ts.map +0 -1
  296. package/dist/lib/interf-scaffold.js.map +0 -1
  297. package/dist/lib/interf-workflow-package.d.ts.map +0 -1
  298. package/dist/lib/interf-workflow-package.js.map +0 -1
  299. package/dist/lib/interf.d.ts.map +0 -1
  300. package/dist/lib/interf.js.map +0 -1
  301. package/dist/lib/local-workflows.d.ts.map +0 -1
  302. package/dist/lib/local-workflows.js.map +0 -1
  303. package/dist/lib/logger.d.ts.map +0 -1
  304. package/dist/lib/logger.js.map +0 -1
  305. package/dist/lib/obsidian.d.ts.map +0 -1
  306. package/dist/lib/obsidian.js.map +0 -1
  307. package/dist/lib/parse.d.ts.map +0 -1
  308. package/dist/lib/parse.js.map +0 -1
  309. package/dist/lib/registry.d.ts.map +0 -1
  310. package/dist/lib/registry.js.map +0 -1
  311. package/dist/lib/runtime-acceptance.d.ts.map +0 -1
  312. package/dist/lib/runtime-acceptance.js.map +0 -1
  313. package/dist/lib/runtime-contracts.d.ts.map +0 -1
  314. package/dist/lib/runtime-contracts.js.map +0 -1
  315. package/dist/lib/runtime-paths.d.ts.map +0 -1
  316. package/dist/lib/runtime-paths.js.map +0 -1
  317. package/dist/lib/runtime-prompt.d.ts.map +0 -1
  318. package/dist/lib/runtime-prompt.js.map +0 -1
  319. package/dist/lib/runtime-reconcile.d.ts.map +0 -1
  320. package/dist/lib/runtime-reconcile.js.map +0 -1
  321. package/dist/lib/runtime-runs.d.ts.map +0 -1
  322. package/dist/lib/runtime-runs.js.map +0 -1
  323. package/dist/lib/runtime-types.d.ts.map +0 -1
  324. package/dist/lib/runtime-types.js.map +0 -1
  325. package/dist/lib/runtime.d.ts.map +0 -1
  326. package/dist/lib/runtime.js.map +0 -1
  327. package/dist/lib/schema.d.ts.map +0 -1
  328. package/dist/lib/schema.js.map +0 -1
  329. package/dist/lib/source-config.d.ts.map +0 -1
  330. package/dist/lib/source-config.js.map +0 -1
  331. package/dist/lib/state-artifacts.d.ts.map +0 -1
  332. package/dist/lib/state-artifacts.js.map +0 -1
  333. package/dist/lib/state-health.d.ts.map +0 -1
  334. package/dist/lib/state-health.js.map +0 -1
  335. package/dist/lib/state-io.d.ts.map +0 -1
  336. package/dist/lib/state-io.js.map +0 -1
  337. package/dist/lib/state-paths.d.ts.map +0 -1
  338. package/dist/lib/state-paths.js.map +0 -1
  339. package/dist/lib/state-view.d.ts.map +0 -1
  340. package/dist/lib/state-view.js.map +0 -1
  341. package/dist/lib/state.d.ts.map +0 -1
  342. package/dist/lib/state.js.map +0 -1
  343. package/dist/lib/summarize-plan.d.ts.map +0 -1
  344. package/dist/lib/summarize-plan.js.map +0 -1
  345. package/dist/lib/user-config.d.ts.map +0 -1
  346. package/dist/lib/user-config.js.map +0 -1
  347. package/dist/lib/util.d.ts.map +0 -1
  348. package/dist/lib/util.js.map +0 -1
  349. package/dist/lib/validate-helpers.d.ts.map +0 -1
  350. package/dist/lib/validate-helpers.js.map +0 -1
  351. package/dist/lib/validate-workspace.d.ts.map +0 -1
  352. package/dist/lib/validate-workspace.js.map +0 -1
  353. package/dist/lib/validate.d.ts.map +0 -1
  354. package/dist/lib/validate.js.map +0 -1
  355. package/dist/lib/workflow-definitions.d.ts.map +0 -1
  356. package/dist/lib/workflow-definitions.js.map +0 -1
  357. package/dist/lib/workflow-helpers.d.ts.map +0 -1
  358. package/dist/lib/workflow-helpers.js.map +0 -1
  359. package/dist/lib/workflow-stage-runner.d.ts.map +0 -1
  360. package/dist/lib/workflow-stage-runner.js.map +0 -1
  361. package/dist/lib/workflow-starter-docs.d.ts +0 -7
  362. package/dist/lib/workflow-starter-docs.d.ts.map +0 -1
  363. package/dist/lib/workflow-starter-docs.js +0 -3
  364. package/dist/lib/workflow-starter-docs.js.map +0 -1
  365. package/dist/lib/workflows.d.ts.map +0 -1
  366. package/dist/lib/workflows.js.map +0 -1
  367. package/dist/lib/workspace-compile.d.ts.map +0 -1
  368. package/dist/lib/workspace-compile.js.map +0 -1
  369. package/dist/lib/workspace-docs.d.ts +0 -3
  370. package/dist/lib/workspace-docs.d.ts.map +0 -1
  371. package/dist/lib/workspace-docs.js +0 -82
  372. package/dist/lib/workspace-docs.js.map +0 -1
  373. package/dist/lib/workspace-raw.d.ts.map +0 -1
  374. package/dist/lib/workspace-raw.js.map +0 -1
  375. package/dist/lib/workspace-reset.d.ts.map +0 -1
  376. package/dist/lib/workspace-reset.js.map +0 -1
  377. package/dist/lib/workspace-schema.d.ts.map +0 -1
  378. package/dist/lib/workspace-schema.js.map +0 -1
  379. package/skills/benchmark/SKILL.md +0 -122
  380. package/skills/workflow/create/SKILL.md +0 -141
  381. package/skills/workspace/shape/SKILL.md +0 -15
  382. package/skills/workspace/structure/SKILL.md +0 -15
  383. package/skills/workspace/summarize/SKILL.md +0 -15
  384. package/templates/workspace/README.md +0 -24
  385. package/templates/workspace/interfignore +0 -2
@@ -1,16 +1,179 @@
1
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, symlinkSync, } from "node:fs";
2
- import { dirname, join } from "node:path";
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";
3
4
  import { WORKFLOW_PACKAGE_DIR } from "./interf-detect.js";
4
- import { renderWorkspaceAgents, renderWorkspaceQuerySkill, } from "./workspace-docs.js";
5
5
  import { ensureWorkspaceZoneTargets, readWorkspaceSchemaFile, workspaceZoneAbsolutePath, } from "./workspace-schema.js";
6
+ import { stageExecutionShellsRoot, workflowImprovementLoopRoot, workflowPackagePathForWorkspace, workspaceInterfConfigPath, workspaceRuntimeRoot, } from "./workspace-paths.js";
7
+ import { resolveWorkflowImprovementReviewSourcePaths } from "./workflow-review-paths.js";
6
8
  const LOCAL_SKILL_ROOTS = [
7
9
  ".claude/skills",
8
10
  ".codex/skills",
9
11
  ".agents/skills",
10
12
  ".cursor/skills",
11
13
  ];
12
- function stageShellsRoot(workspacePath) {
13
- return join(workspacePath, ".interf", "execution-shells");
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 workspaceQuerySkillSourcePath(workspacePath) {
23
+ return join(workflowPackagePathForWorkspace(workspacePath), "use", "query", "SKILL.md");
24
+ }
25
+ export function renderWorkspaceAgents(name, workflowId, about, options = {}) {
26
+ const workflowOriginSelected = options.workflowOriginSelected ?? workflowId;
27
+ const workflowLocalDraft = options.workflowLocalDraft === true;
28
+ return [
29
+ `# ${name}`,
30
+ "",
31
+ "This is a compiled workspace built by Interf Compiler.",
32
+ "It is a file-based layer on top of the raw files, built for agents to navigate, retrieve evidence, and answer more accurately.",
33
+ "",
34
+ ...(about
35
+ ? [
36
+ `About: ${about}`,
37
+ "",
38
+ ]
39
+ : []),
40
+ "## How to use this workspace",
41
+ "",
42
+ "1. Use the local native `interf-query` skill that Interf Compiler generated for this workspace.",
43
+ "2. Start from `home.md`, then use `knowledge/` and `summaries/`.",
44
+ "3. Use `raw/` when you need direct quotes, exact chart values, table lookups, or verification.",
45
+ "",
46
+ "## How this workspace works",
47
+ "",
48
+ "- `.interf/interf.json` points to the workspace-local `raw/` snapshot via `source.path` and back to the dataset control plane via `source.control_path`.",
49
+ `- Workflow seed: \`${workflowOriginSelected}\`.`,
50
+ ...(workflowLocalDraft
51
+ ? ["- This workspace now carries a local workflow draft improved from that seed. Recompiling this workspace reuses the local `.interf/workflow/` package."]
52
+ : []),
53
+ `- Active local workflow id: \`${workflowId}\`.`,
54
+ "- `.interf/workflow/` is the local editable method package for this workspace.",
55
+ "- `.interf/workflow/workspace.schema.json` is the deterministic output shape for this workspace.",
56
+ "- `.interf/workflow/improve/` is the editable source for workflow-improvement loops.",
57
+ "- `.interf/workflow/use/query/` is the editable source for the generated native query shell.",
58
+ "- `.interf/workflow/compile/stages/` defines stage-specific docs that Interf Compiler projects into native execution shells for automated runs.",
59
+ "- Native local query skills are generated under local agent skill directories such as `.claude/skills/` and `.codex/skills/`.",
60
+ "- `raw/` contains the workspace-local raw snapshot used for evidence and verification.",
61
+ "- `summaries/` contains per-file evidence objects.",
62
+ "- `knowledge/` contains the cross-file knowledge layer and navigation structure.",
63
+ "- `home.md` is the starting note.",
64
+ "- `.interf/runtime/` holds CLI-owned runtime artifacts.",
65
+ "- `.interf/tests/` holds saved raw-vs-compiled test comparisons for this workspace.",
66
+ "- `.interf/tests/targets/` holds detailed raw and compiled target runs plus preserved test sandboxes.",
67
+ "",
68
+ "## Manual query rules",
69
+ "",
70
+ "- Prefer `home.md`, `knowledge/`, and `summaries/` before `raw/`.",
71
+ "- Use the generated native `interf-query` skill for manual querying. The editable source lives at `.interf/workflow/use/query/SKILL.md`.",
72
+ "- Treat `.interf/` as method/runtime metadata, not answer evidence, unless explicitly asked to inspect workflow or test history.",
73
+ "- Use `raw/` for quotes, verification, ambiguity, or evidence the compiled layer does not expose well.",
74
+ "- If the compiled layer already contains a bounded chart-derived read for the exact metric and year the user asked about, answer from that compiled read first.",
75
+ "- 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.",
76
+ "",
77
+ "## Commands",
78
+ "",
79
+ "```",
80
+ "interf compile build this compiled workspace",
81
+ "interf test run saved truth checks against this workspace",
82
+ "interf verify summarize verify summary coverage",
83
+ "interf verify structure verify cross-file structure outputs",
84
+ "interf verify compile verify compile outputs",
85
+ "interf status show deterministic health",
86
+ "```",
87
+ "",
88
+ "## Rules",
89
+ "",
90
+ "- Do not modify files under `raw/`.",
91
+ "- Treat compiled notes as working retrieval artifacts, not final truth.",
92
+ "- When confidence is low, verify against `raw/` before answering strongly.",
93
+ "",
94
+ ].join("\n");
95
+ }
96
+ export function renderWorkspaceQuerySkill() {
97
+ const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note.toLowerCase()}`);
98
+ return [
99
+ "# Manual Query Loop",
100
+ "",
101
+ "This file is the editable authoring source for the generated native local `interf-query` skill.",
102
+ "",
103
+ "Default loop:",
104
+ "1. Read `home.md` first.",
105
+ "2. Browse `knowledge/` before `raw/`.",
106
+ "3. Use `summaries/` for source-grounded evidence.",
107
+ "4. Use `raw/` for direct quotes, verification, exact table lookups, and cases where the compiled layer is missing or ambiguous.",
108
+ "",
109
+ "Answering rule:",
110
+ "- do not modify files under `raw/`",
111
+ "- when a number is chart-derived, say that explicitly",
112
+ "- if the compiled layer already contains a bounded chart-derived read for the exact metric and year, answer from that compiled read first",
113
+ "- use `raw/` to confirm source page, metric family, or provenance, not to replace a good compiled bounded read with a second incompatible range",
114
+ "- when the compiled layer preserves a bounded chart-derived range, keep that bounded range in the answer instead of collapsing it to a midpoint or pseudo-exact single value",
115
+ "- when reading charts, verify you are on the correct metric family and year before answering",
116
+ "- keep historical annual charts separate from current-quarter snapshots, sector splits, or nearby lookalike panels",
117
+ ...chartNotes,
118
+ "- if multiple compiled notes mention the same chart read, keep the answer consistent with the most focused workspace note instead of synthesizing a new midpoint or shifted band",
119
+ "- when the compiled layer is insufficient, verify in `raw/` and then answer",
120
+ "",
121
+ "You can edit this file to bias manual question-answering behavior for this workspace.",
122
+ "",
123
+ ].join("\n");
124
+ }
125
+ function renderRawTestAgents() {
126
+ const chartNotes = CHART_APPROXIMATION_NOTES.map((note) => `- ${note}`);
127
+ return [
128
+ "# Raw Test Shell",
129
+ "",
130
+ "This is an isolated raw-files test shell generated by Interf Compiler.",
131
+ "There is no compiled workspace in this shell.",
132
+ "",
133
+ "## How to use this shell",
134
+ "",
135
+ "1. Read this file first.",
136
+ "2. Use the local native `interf-query` skill available in this shell.",
137
+ "3. Read only from `raw/`.",
138
+ "",
139
+ "## Rules",
140
+ "",
141
+ "- Answer only from the files under `raw/`.",
142
+ "- There is no compiled workspace here, so do not assume `home.md`, `knowledge/`, or `summaries/` exist.",
143
+ "- Do not treat hidden runtime files or test artifacts as evidence.",
144
+ ...chartNotes,
145
+ "- Write the requested answer and trace files, then stop.",
146
+ "",
147
+ ].join("\n");
148
+ }
149
+ function renderRawTestQuerySkill() {
150
+ const chartNotes = CHART_APPROXIMATION_NOTES.map((note, index) => `${index + 3}. ${note}`);
151
+ return [
152
+ "---",
153
+ "name: interf-query",
154
+ "description: >",
155
+ " Native local query skill for an Interf raw test shell. Use it only",
156
+ " to answer baseline questions directly from `raw/`.",
157
+ "---",
158
+ "",
159
+ "# Interf Raw Test Query",
160
+ "",
161
+ "This is the native local query skill for an isolated raw-files test shell.",
162
+ "",
163
+ "Loop:",
164
+ "1. Read `raw/` directly.",
165
+ "2. Verify exact claims against the raw files before answering strongly.",
166
+ ...chartNotes,
167
+ "8. Do not rely on compiled workspace artifacts because they do not exist in this shell.",
168
+ "",
169
+ ].join("\n");
170
+ }
171
+ function readWorkspaceQuerySkillSource(workspacePath) {
172
+ const filePath = workspaceQuerySkillSourcePath(workspacePath);
173
+ if (!existsSync(filePath)) {
174
+ throw new Error(`Missing workspace query skill source at ${filePath}. Interf compile runs the workspace-local workflow package directly, so reseed or repair this workspace instead of auto-healing query docs.`);
175
+ }
176
+ return readFileSync(filePath, "utf8").trim();
14
177
  }
15
178
  function stageShellWorkflowRoot(shellRoot) {
16
179
  return join(shellRoot, WORKFLOW_PACKAGE_DIR);
@@ -21,6 +184,19 @@ function shellInputZonePath(shellRoot, zoneId) {
21
184
  function shellOutputZonePath(shellRoot, zoneId) {
22
185
  return join(shellRoot, "outputs", zoneId);
23
186
  }
187
+ function shellZoneAliasMountPath(shellRoot, zone, mountKind) {
188
+ const mountRoot = mountKind === "inputs"
189
+ ? shellInputZonePath(shellRoot, zone.id)
190
+ : shellOutputZonePath(shellRoot, zone.id);
191
+ return zone.kind === "file"
192
+ ? join(mountRoot, basename(zone.path))
193
+ : mountRoot;
194
+ }
195
+ function describeShellZoneAliasMountPath(zone, mountKind) {
196
+ return zone.kind === "file"
197
+ ? `${mountKind}/${zone.id}/${basename(zone.path)}`
198
+ : `${mountKind}/${zone.id}`;
199
+ }
24
200
  function shellRuntimePath(shellRoot, relativePath) {
25
201
  return join(shellRoot, "runtime", relativePath);
26
202
  }
@@ -44,10 +220,15 @@ function linkPath(targetPath, linkPathname) {
44
220
  mkdirSync(dirname(linkPathname), { recursive: true });
45
221
  symlinkSync(targetPath, linkPathname);
46
222
  }
223
+ function linkRelativePath(targetPath, linkPathname) {
224
+ mkdirSync(dirname(linkPathname), { recursive: true });
225
+ symlinkSync(relative(dirname(linkPathname), targetPath), linkPathname);
226
+ }
47
227
  function loadWorkspaceSchema(workspacePath) {
48
- const schema = readWorkspaceSchemaFile(join(workspacePath, WORKFLOW_PACKAGE_DIR));
228
+ const workflowRoot = workflowPackagePathForWorkspace(workspacePath);
229
+ const schema = readWorkspaceSchemaFile(workflowRoot);
49
230
  if (!schema) {
50
- throw new Error(`Missing workflow workspace schema at ${join(workspacePath, WORKFLOW_PACKAGE_DIR, "workspace.schema.json")}`);
231
+ throw new Error(`Missing workflow workspace schema at ${join(workflowRoot, "workspace.schema.json")}`);
51
232
  }
52
233
  return schema;
53
234
  }
@@ -62,26 +243,26 @@ function zoneOrThrow(zones, zoneId) {
62
243
  return zone;
63
244
  }
64
245
  function ensureWorkspaceExecutionSurface(workspacePath) {
65
- mkdirSync(join(workspacePath, ".interf"), { recursive: true });
66
- mkdirSync(join(workspacePath, WORKFLOW_PACKAGE_DIR), { recursive: true });
246
+ mkdirSync(workspaceRuntimeRoot(workspacePath), { recursive: true });
247
+ mkdirSync(workflowPackagePathForWorkspace(workspacePath), { recursive: true });
67
248
  const schema = loadWorkspaceSchema(workspacePath);
68
249
  ensureWorkspaceZoneTargets(workspacePath, schema);
69
250
  return schema;
70
251
  }
71
252
  function readStageMethodDoc(workspacePath, stage) {
72
- const path = join(workspacePath, WORKFLOW_PACKAGE_DIR, "compile", "stages", stage.skillDir, "SKILL.md");
253
+ const path = join(workflowPackagePathForWorkspace(workspacePath), "compile", "stages", stage.skillDir, "SKILL.md");
73
254
  if (!existsSync(path))
74
255
  return null;
75
256
  return readFileSync(path, "utf8").trim();
76
257
  }
77
258
  function stageWorkflowDocsPath(workspacePath, stage) {
78
- return join(workspacePath, WORKFLOW_PACKAGE_DIR, "compile", "stages", stage.skillDir);
259
+ return join(workflowPackagePathForWorkspace(workspacePath), "compile", "stages", stage.skillDir);
79
260
  }
80
261
  function renderStageExecutionAgents(workspaceName, workflowId, stage) {
81
262
  return [
82
263
  `# ${workspaceName} — ${stage.label} Execution Shell`,
83
264
  "",
84
- "This is an ephemeral Interf stage-execution shell.",
265
+ "This is an ephemeral stage-execution shell generated by Interf Compiler.",
85
266
  "It is for automated pipeline execution only, not for manual querying.",
86
267
  "",
87
268
  "## Start Here",
@@ -95,7 +276,8 @@ function renderStageExecutionAgents(workspaceName, workflowId, stage) {
95
276
  "",
96
277
  "- `inputs/<zone-id>/` = read mounts for the current stage.",
97
278
  "- `outputs/<zone-id>/` = write mounts for the current stage.",
98
- "- schema-declared workspace paths are also projected at the shell root so workflow-relative contract paths stay valid.",
279
+ "- For file zones, `runtime/paths.json` points to the exact file path inside those mount roots.",
280
+ "- declared workspace zone paths are also projected at the shell root so workflow-relative contract paths stay valid.",
99
281
  "- `runtime/` = stage contract and machine-readable path map for this shell.",
100
282
  "- `workflow/` = workflow metadata, workspace schema, and docs for the current stage only.",
101
283
  "",
@@ -127,13 +309,13 @@ function renderStageExecutionSkill(stage, stageMethodDoc) {
127
309
  "---",
128
310
  "name: interf-stage",
129
311
  "description: >",
130
- ` Native local execution skill for the ${stage.label} stage in this Interf`,
131
- " compile run. Use it only inside an automated stage execution shell.",
312
+ ` Native local execution skill for the ${stage.label} stage in this`,
313
+ " Interf Compiler run. Use it only inside an automated stage execution shell.",
132
314
  "---",
133
315
  "",
134
- `# Interf Stage Execution — ${stage.label}`,
316
+ `# Interf Compiler Stage Execution — ${stage.label}`,
135
317
  "",
136
- "This local native skill exists for automated Interf stage execution.",
318
+ "This local native skill exists for automated Interf Compiler stage execution.",
137
319
  "Read `runtime/stage-contract.json` first.",
138
320
  "Then read `runtime/paths.json` and use the mounted `inputs/` and `outputs/` zones for this stage.",
139
321
  "Do not switch into manual query mode.",
@@ -157,50 +339,52 @@ function renderStageExecutionSkill(stage, stageMethodDoc) {
157
339
  : []),
158
340
  ].join("\n");
159
341
  }
160
- function renderWorkspaceQueryNativeSkill() {
342
+ function renderWorkspaceQueryNativeSkill(querySkillContent) {
161
343
  return [
162
344
  "---",
163
345
  "name: interf-query",
164
346
  "description: >",
165
- " Native local query skill for this Interf compiled workspace. Use it for",
166
- " manual questions against the compiled workspace and its raw fallback.",
347
+ " Native local query skill for this compiled workspace built by Interf",
348
+ " Compiler. Use it for manual questions against the compiled workspace and",
349
+ " its raw fallback.",
167
350
  "---",
168
351
  "",
169
- "# Interf Query",
352
+ "# Interf Compiler Query",
170
353
  "",
171
- "This is the native local query skill for an Interf compiled workspace.",
354
+ "This is the native local query skill for a compiled workspace built by Interf Compiler.",
172
355
  "Use it when reading this workspace manually.",
173
- "Editable source: `workflow/use/query/SKILL.md`.",
356
+ "Editable source: `.interf/workflow/use/query/SKILL.md`.",
174
357
  "",
175
- renderWorkspaceQuerySkill().trim(),
358
+ querySkillContent.trim(),
176
359
  "",
177
360
  ].join("\n");
178
361
  }
179
- function syncWorkspaceNativeQuerySkillCopies(workspacePath) {
180
- return writeNativeSkillCopies(workspacePath, "interf-query", renderWorkspaceQueryNativeSkill());
181
- }
182
362
  function projectWorkflowMetadata(workspacePath, shellRoot, stage) {
183
- const workflowRoot = stageShellWorkflowRoot(shellRoot);
184
- mkdirSync(join(workflowRoot, "compile", "stages"), { recursive: true });
185
- const workflowJsonPath = join(workspacePath, WORKFLOW_PACKAGE_DIR, "workflow.json");
363
+ const shellWorkflowRoot = stageShellWorkflowRoot(shellRoot);
364
+ mkdirSync(join(shellWorkflowRoot, "compile", "stages"), { recursive: true });
365
+ const workspaceWorkflowRoot = workflowPackagePathForWorkspace(workspacePath);
366
+ const workflowJsonPath = join(workspaceWorkflowRoot, "workflow.json");
186
367
  if (existsSync(workflowJsonPath)) {
187
- linkPath(workflowJsonPath, join(workflowRoot, "workflow.json"));
368
+ linkPath(workflowJsonPath, join(shellWorkflowRoot, "workflow.json"));
188
369
  }
189
- const workspaceSchemaPath = join(workspacePath, WORKFLOW_PACKAGE_DIR, "workspace.schema.json");
370
+ const workspaceSchemaPath = join(workspaceWorkflowRoot, "workspace.schema.json");
190
371
  if (existsSync(workspaceSchemaPath)) {
191
- linkPath(workspaceSchemaPath, join(workflowRoot, "workspace.schema.json"));
372
+ linkPath(workspaceSchemaPath, join(shellWorkflowRoot, "workspace.schema.json"));
192
373
  }
193
- const readmePath = join(workspacePath, WORKFLOW_PACKAGE_DIR, "README.md");
374
+ const readmePath = join(workspaceWorkflowRoot, "README.md");
194
375
  if (existsSync(readmePath)) {
195
- linkPath(readmePath, join(workflowRoot, "README.md"));
376
+ linkPath(readmePath, join(shellWorkflowRoot, "README.md"));
196
377
  }
197
378
  const stageDocsPath = stageWorkflowDocsPath(workspacePath, stage);
198
379
  if (existsSync(stageDocsPath)) {
199
- linkPath(stageDocsPath, join(workflowRoot, "compile", "stages", stage.skillDir));
380
+ linkPath(stageDocsPath, join(shellWorkflowRoot, "compile", "stages", stage.skillDir));
200
381
  }
201
382
  }
202
- function projectWorkspaceSchemaZones(workspacePath, shellRoot, schema) {
383
+ function projectWorkspaceSchemaZones(workspacePath, shellRoot, schema, zoneIds) {
384
+ const allowedZoneIds = zoneIds ? new Set(zoneIds) : null;
203
385
  for (const zone of schema.zones) {
386
+ if (allowedZoneIds && !allowedZoneIds.has(zone.id))
387
+ continue;
204
388
  linkPath(workspaceZoneAbsolutePath(workspacePath, zone), join(shellRoot, zone.path));
205
389
  }
206
390
  }
@@ -212,8 +396,12 @@ function buildStageZoneMounts(workspacePath, shellRoot, stage, schema) {
212
396
  zone_id: zone.id,
213
397
  workspace_path: zone.path,
214
398
  shell_root_path: zone.path,
215
- input_mount_path: stage.reads.includes(zoneId) ? `inputs/${zone.id}` : null,
216
- output_mount_path: stage.writes.includes(zoneId) ? `outputs/${zone.id}` : null,
399
+ input_mount_path: stage.reads.includes(zoneId)
400
+ ? describeShellZoneAliasMountPath(zone, "inputs")
401
+ : null,
402
+ output_mount_path: stage.writes.includes(zoneId)
403
+ ? describeShellZoneAliasMountPath(zone, "outputs")
404
+ : null,
217
405
  };
218
406
  };
219
407
  return {
@@ -227,10 +415,10 @@ function projectStageZoneMountAliases(workspacePath, shellRoot, stage, schema) {
227
415
  const zone = zoneOrThrow(zones, zoneId);
228
416
  const targetPath = workspaceZoneAbsolutePath(workspacePath, zone);
229
417
  if (stage.reads.includes(zoneId)) {
230
- linkPath(targetPath, shellInputZonePath(shellRoot, zoneId));
418
+ linkPath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "inputs"));
231
419
  }
232
420
  if (stage.writes.includes(zoneId)) {
233
- linkPath(targetPath, shellOutputZonePath(shellRoot, zoneId));
421
+ linkPath(targetPath, shellZoneAliasMountPath(shellRoot, zone, "outputs"));
234
422
  }
235
423
  }
236
424
  }
@@ -245,50 +433,326 @@ function writeExecutionShellPathsFile(shellRoot, workflowId, stage, mounts) {
245
433
  };
246
434
  writeFileSync(shellRuntimePath(shellRoot, "paths.json"), `${JSON.stringify(paths, null, 2)}\n`);
247
435
  }
436
+ export function syncStageExecutionShellWrites(workspacePath, shellRoot, stage) {
437
+ const schema = ensureWorkspaceExecutionSurface(workspacePath);
438
+ const zones = zoneMap(schema);
439
+ for (const zoneId of new Set(stage.writes)) {
440
+ const zone = zoneOrThrow(zones, zoneId);
441
+ const shellZonePath = join(shellRoot, zone.path);
442
+ if (!existsSync(shellZonePath))
443
+ continue;
444
+ const shellZoneStat = lstatSync(shellZonePath);
445
+ if (shellZoneStat.isSymbolicLink())
446
+ continue;
447
+ const workspaceZonePath = workspaceZoneAbsolutePath(workspacePath, zone);
448
+ if (shellZoneStat.isDirectory()) {
449
+ rmSync(workspaceZonePath, { recursive: true, force: true });
450
+ mkdirSync(dirname(workspaceZonePath), { recursive: true });
451
+ cpSync(shellZonePath, workspaceZonePath, {
452
+ recursive: true,
453
+ force: true,
454
+ });
455
+ continue;
456
+ }
457
+ mkdirSync(dirname(workspaceZonePath), { recursive: true });
458
+ copyFileSync(shellZonePath, workspaceZonePath);
459
+ }
460
+ }
461
+ function preservedShellManifestPath(rootPath) {
462
+ return shellRuntimePath(rootPath, "preserved-shell.json");
463
+ }
464
+ function shouldSkipFrozenStageShellRelativePath(relativePath) {
465
+ const normalized = relativePath.replaceAll("\\", "/");
466
+ return normalized === "execution-shells" ||
467
+ normalized.endsWith("/execution-shells") ||
468
+ normalized.includes("/execution-shells/") ||
469
+ normalized === "improvement-loops" ||
470
+ normalized.endsWith("/improvement-loops") ||
471
+ normalized.includes("/improvement-loops/");
472
+ }
473
+ function copyResolvedTree(options) {
474
+ const relativePath = options.relativePath ?? "";
475
+ if (options.shellType === "stage-execution" && shouldSkipFrozenStageShellRelativePath(relativePath)) {
476
+ return { materializedSymlinks: 0 };
477
+ }
478
+ const stat = lstatSync(options.sourcePath);
479
+ if (stat.isSymbolicLink()) {
480
+ const realTarget = realpathSync(options.sourcePath);
481
+ const realStat = statSync(realTarget);
482
+ if (realStat.isDirectory()) {
483
+ const mappedTarget = options.materializedRealPaths?.get(realTarget);
484
+ if (mappedTarget) {
485
+ linkRelativePath(mappedTarget, options.targetPath);
486
+ return { materializedSymlinks: 1 };
487
+ }
488
+ return {
489
+ materializedSymlinks: 1 + copyResolvedTree({
490
+ sourcePath: realTarget,
491
+ targetPath: options.targetPath,
492
+ shellType: options.shellType,
493
+ relativePath,
494
+ activeRealPaths: options.activeRealPaths,
495
+ materializedRealPaths: options.materializedRealPaths,
496
+ }).materializedSymlinks,
497
+ };
498
+ }
499
+ mkdirSync(dirname(options.targetPath), { recursive: true });
500
+ copyFileSync(realTarget, options.targetPath);
501
+ return { materializedSymlinks: 1 };
502
+ }
503
+ if (stat.isDirectory()) {
504
+ const realSource = realpathSync(options.sourcePath);
505
+ const mappedTarget = options.materializedRealPaths?.get(realSource);
506
+ if (mappedTarget && mappedTarget !== options.targetPath) {
507
+ linkRelativePath(mappedTarget, options.targetPath);
508
+ return { materializedSymlinks: 0 };
509
+ }
510
+ const nextRealPaths = new Set([...(options.activeRealPaths ?? []), realSource]);
511
+ const nextMaterializedRealPaths = new Map(options.materializedRealPaths ?? []);
512
+ nextMaterializedRealPaths.set(realSource, options.targetPath);
513
+ mkdirSync(options.targetPath, { recursive: true });
514
+ let materializedSymlinks = 0;
515
+ for (const entry of readdirSync(options.sourcePath)) {
516
+ const childRelativePath = relativePath.length > 0 ? `${relativePath}/${entry}` : entry;
517
+ const copied = copyResolvedTree({
518
+ sourcePath: join(options.sourcePath, entry),
519
+ targetPath: join(options.targetPath, entry),
520
+ shellType: options.shellType,
521
+ relativePath: childRelativePath,
522
+ activeRealPaths: nextRealPaths,
523
+ materializedRealPaths: nextMaterializedRealPaths,
524
+ });
525
+ materializedSymlinks += copied.materializedSymlinks;
526
+ }
527
+ return { materializedSymlinks };
528
+ }
529
+ mkdirSync(dirname(options.targetPath), { recursive: true });
530
+ copyFileSync(options.sourcePath, options.targetPath);
531
+ return { materializedSymlinks: 0 };
532
+ }
533
+ function freezePreservedShell(rootPath, shellType) {
534
+ if (!existsSync(rootPath))
535
+ return null;
536
+ const manifestPath = preservedShellManifestPath(rootPath);
537
+ if (existsSync(manifestPath))
538
+ return manifestPath;
539
+ const tempRoot = `${rootPath}.frozen-${Date.now().toString(36)}`;
540
+ const copied = copyResolvedTree({
541
+ sourcePath: rootPath,
542
+ targetPath: tempRoot,
543
+ shellType,
544
+ });
545
+ const manifest = {
546
+ kind: "interf-preserved-shell",
547
+ version: 1,
548
+ shell_type: shellType,
549
+ generated_at: new Date().toISOString(),
550
+ root_path: rootPath,
551
+ materialized_symlinks: copied.materializedSymlinks,
552
+ };
553
+ writeFileSync(preservedShellManifestPath(tempRoot), `${JSON.stringify(manifest, null, 2)}\n`);
554
+ rmSync(rootPath, { recursive: true, force: true });
555
+ renameSync(tempRoot, rootPath);
556
+ return manifestPath;
557
+ }
248
558
  export function renderClaudeBootstrap(content) {
249
559
  return [
250
- "<!-- Generated from AGENTS.md. Edit AGENTS.md; Interf will rewrite this file. -->",
560
+ "<!-- Generated compatibility mirror of AGENTS.md. Interf Compiler may rewrite this file. -->",
251
561
  "",
252
562
  content.trimEnd(),
253
563
  "",
254
564
  ].join("\n");
255
565
  }
566
+ function improvementWorkflowDocsPath(workspacePath) {
567
+ return join(workflowPackagePathForWorkspace(workspacePath), "improve");
568
+ }
569
+ function renderWorkflowImprovementAgents(workspaceName, workflowId, loopIndex) {
570
+ return [
571
+ `# ${workspaceName} — Workflow Improvement Shell`,
572
+ "",
573
+ "This is an automated workflow-improvement shell generated by Interf Compiler.",
574
+ "It exists to review failed compile/test runs and edit the workflow package for the next variation.",
575
+ "",
576
+ "## Start Here",
577
+ "",
578
+ "1. Read `runtime/loop-context.json` now.",
579
+ "2. Read `workflow/README.md`, `workflow/workflow.json`, and `workflow/workspace.schema.json` now.",
580
+ "3. Read `workflow/improve/SKILL.md` now.",
581
+ "4. Use the local native `interf-workflow-improver` skill now.",
582
+ "",
583
+ "## Boundaries",
584
+ "",
585
+ `- Workflow: \`${workflowId}\`.`,
586
+ `- Improvement loop: ${loopIndex}.`,
587
+ "- Edit only files under `workflow/`.",
588
+ "- Do not edit truth checks, test specs, raw dataset files, or generated workspace outputs.",
589
+ "- Review compiled outputs under `artifacts/workspace-view/` and test/runtime evidence under `artifacts/`.",
590
+ "- Keep the workflow valid for the current compiler API and workspace schema.",
591
+ "",
592
+ "## Goal",
593
+ "",
594
+ "- create a better workflow variation for this dataset",
595
+ "- preserve deterministic workspace structure",
596
+ "- stop after the workflow edits are complete",
597
+ "",
598
+ ].join("\n");
599
+ }
600
+ function readWorkflowImprovementDoc(workspacePath) {
601
+ const path = join(improvementWorkflowDocsPath(workspacePath), "SKILL.md");
602
+ if (!existsSync(path))
603
+ return null;
604
+ return readFileSync(path, "utf8").trim();
605
+ }
606
+ function renderWorkflowImprovementSkill(workflowId, loopIndex, improvementDoc) {
607
+ return [
608
+ "---",
609
+ "name: interf-workflow-improver",
610
+ "description: >",
611
+ " Native local workflow-improvement skill for this Interf Compiler run.",
612
+ " Use it only inside an automated workflow-improvement shell.",
613
+ "---",
614
+ "",
615
+ `# Interf Compiler Workflow Improvement — ${workflowId}`,
616
+ "",
617
+ "This local native skill exists for automated workflow-improvement loops.",
618
+ "Read `runtime/loop-context.json` first.",
619
+ "Then review the linked workflow package, `artifacts/workspace-view/`, preserved stage shells, runtime logs, and saved test outputs before editing `workflow/`.",
620
+ "",
621
+ "## Current Loop",
622
+ "",
623
+ `- workflow: \`${workflowId}\``,
624
+ `- loop index: ${loopIndex}`,
625
+ "- editable source: `workflow/improve/SKILL.md`",
626
+ "",
627
+ ...(improvementDoc
628
+ ? [
629
+ "## Improvement Method",
630
+ "",
631
+ improvementDoc,
632
+ "",
633
+ ]
634
+ : []),
635
+ ].join("\n");
636
+ }
637
+ function projectWorkspaceReviewArtifactsSnapshot(workspacePath, shellRoot, schema) {
638
+ const workspaceViewRoot = join(shellRoot, "artifacts", "workspace-view");
639
+ mkdirSync(workspaceViewRoot, { recursive: true });
640
+ for (const zone of schema.zones) {
641
+ if (zone.kind === "runtime" || zone.path === "raw")
642
+ continue;
643
+ const sourcePath = workspaceZoneAbsolutePath(workspacePath, zone);
644
+ if (!existsSync(sourcePath))
645
+ continue;
646
+ copyResolvedTree({
647
+ sourcePath,
648
+ targetPath: join(workspaceViewRoot, zone.path),
649
+ shellType: "workflow-improvement",
650
+ });
651
+ }
652
+ }
653
+ function linkIfExists(targetPath, linkPathname) {
654
+ if (!existsSync(targetPath))
655
+ return;
656
+ linkPath(targetPath, linkPathname);
657
+ }
658
+ function copyIfExists(sourcePath, targetPath, shellType) {
659
+ if (!existsSync(sourcePath))
660
+ return;
661
+ copyResolvedTree({
662
+ sourcePath,
663
+ targetPath,
664
+ shellType,
665
+ });
666
+ }
667
+ function projectWorkspaceRuntimeArtifacts(workspacePath, shellRoot) {
668
+ const runtimeTarget = join(shellRoot, "artifacts", "workspace-runtime");
669
+ mkdirSync(runtimeTarget, { recursive: true });
670
+ const runtimeRoot = workspaceRuntimeRoot(workspacePath);
671
+ const artifactNames = [
672
+ "run.json",
673
+ "run-history.jsonl",
674
+ "state.json",
675
+ "health.json",
676
+ "view-spec.json",
677
+ "raw-snapshot.json",
678
+ "logs",
679
+ ];
680
+ for (const artifactName of artifactNames) {
681
+ copyIfExists(join(runtimeRoot, artifactName), join(runtimeTarget, artifactName), "workflow-improvement");
682
+ }
683
+ }
256
684
  export function pruneStageExecutionShells(workspacePath) {
257
- rmSync(stageShellsRoot(workspacePath), { recursive: true, force: true });
685
+ rmSync(stageExecutionShellsRoot(workspacePath), { recursive: true, force: true });
258
686
  }
259
- export function projectWorkspaceQueryShell(workspacePath, workspaceName, workflowId, about) {
260
- const agentsContent = renderWorkspaceAgents(workspaceName, workflowId, about);
261
- const querySkillContent = renderWorkspaceQuerySkill();
262
- let changed = false;
263
- changed = writeIfChanged(join(workspacePath, "AGENTS.md"), agentsContent) || changed;
264
- changed =
265
- writeIfChanged(join(workspacePath, "CLAUDE.md"), renderClaudeBootstrap(agentsContent)) || changed;
266
- const querySkillPath = join(workspacePath, WORKFLOW_PACKAGE_DIR, "use", "query", "SKILL.md");
267
- mkdirSync(dirname(querySkillPath), { recursive: true });
268
- changed = writeIfChanged(querySkillPath, querySkillContent) || changed;
269
- changed = syncWorkspaceNativeQuerySkillCopies(workspacePath) || changed;
270
- return changed;
687
+ export function projectWorkspaceQueryShell(workspacePath, workspaceName, workflowId, about, options) {
688
+ const agentsContent = renderWorkspaceAgents(workspaceName, workflowId, about, options);
689
+ const querySkillContent = readWorkspaceQuerySkillSource(workspacePath);
690
+ return writeNativeAgentSurface(workspacePath, agentsContent, "interf-query", renderWorkspaceQueryNativeSkill(querySkillContent));
691
+ }
692
+ export function projectRawTestQueryShell(rootPath) {
693
+ return writeNativeAgentSurface(rootPath, renderRawTestAgents(), "interf-query", renderRawTestQuerySkill());
271
694
  }
272
695
  export function createStageExecutionShell(workspacePath, workspaceName, workflowId, stage) {
273
696
  const schema = ensureWorkspaceExecutionSurface(workspacePath);
274
- const shellsRoot = stageShellsRoot(workspacePath);
697
+ const shellsRoot = stageExecutionShellsRoot(workspacePath);
275
698
  const shellRoot = join(shellsRoot, `${stage.id}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`);
276
699
  mkdirSync(shellRoot, { recursive: true });
277
700
  mkdirSync(join(shellRoot, "runtime"), { recursive: true });
278
701
  mkdirSync(join(shellRoot, "inputs"), { recursive: true });
279
702
  mkdirSync(join(shellRoot, "outputs"), { recursive: true });
280
- linkPath(join(workspacePath, "interf.json"), join(shellRoot, "interf.json"));
281
- linkPath(join(workspacePath, ".interf", "stage-contract.json"), shellRuntimePath(shellRoot, "stage-contract.json"));
282
- projectWorkspaceSchemaZones(workspacePath, shellRoot, schema);
703
+ linkPath(workspaceInterfConfigPath(workspacePath), join(shellRoot, "interf.json"));
704
+ linkPath(join(workspaceRuntimeRoot(workspacePath), "stage-contract.json"), shellRuntimePath(shellRoot, "stage-contract.json"));
705
+ projectWorkspaceSchemaZones(workspacePath, shellRoot, schema, new Set([...stage.reads, ...stage.writes]));
283
706
  projectWorkflowMetadata(workspacePath, shellRoot, stage);
284
707
  projectStageZoneMountAliases(workspacePath, shellRoot, stage, schema);
285
708
  writeExecutionShellPathsFile(shellRoot, workflowId, stage, buildStageZoneMounts(workspacePath, shellRoot, stage, schema));
286
709
  const agentsContent = renderStageExecutionAgents(workspaceName, workflowId, stage);
287
- writeFileSync(join(shellRoot, "AGENTS.md"), `${agentsContent}\n`);
288
- writeFileSync(join(shellRoot, "CLAUDE.md"), renderClaudeBootstrap(agentsContent));
289
- writeNativeSkillCopies(shellRoot, "interf-stage", renderStageExecutionSkill(stage, readStageMethodDoc(workspacePath, stage)));
710
+ writeNativeAgentSurface(shellRoot, agentsContent, "interf-stage", renderStageExecutionSkill(stage, readStageMethodDoc(workspacePath, stage)));
290
711
  return {
291
712
  rootPath: shellRoot,
292
713
  };
293
714
  }
294
- //# sourceMappingURL=agent-shells.js.map
715
+ export function freezeStageExecutionShell(rootPath) {
716
+ return freezePreservedShell(rootPath, "stage-execution");
717
+ }
718
+ export function createWorkflowImprovementShell(options) {
719
+ const schema = ensureWorkspaceExecutionSurface(options.workspacePath);
720
+ const loopRootPath = workflowImprovementLoopRoot(options.workspacePath, options.runId, options.loopIndex);
721
+ const shellRoot = join(loopRootPath, "shell");
722
+ mkdirSync(shellRoot, { recursive: true });
723
+ mkdirSync(join(shellRoot, "runtime"), { recursive: true });
724
+ mkdirSync(join(shellRoot, "artifacts"), { recursive: true });
725
+ mkdirSync(join(loopRootPath, "logs"), { recursive: true });
726
+ writeFileSync(join(shellRoot, "runtime", "loop-context.json"), `${JSON.stringify(options.context, null, 2)}\n`);
727
+ projectWorkspaceReviewArtifactsSnapshot(options.workspacePath, shellRoot, schema);
728
+ linkPath(workflowPackagePathForWorkspace(options.workspacePath), join(shellRoot, "workflow"));
729
+ copyIfExists(workspaceInterfConfigPath(options.workspacePath), join(shellRoot, "interf.json"), "workflow-improvement");
730
+ projectWorkspaceRuntimeArtifacts(options.workspacePath, shellRoot);
731
+ const reviewSources = resolveWorkflowImprovementReviewSourcePaths(options.workspacePath);
732
+ if (reviewSources.executionShells) {
733
+ copyIfExists(reviewSources.executionShells, join(shellRoot, "artifacts", "execution-shells"), "workflow-improvement");
734
+ }
735
+ if (reviewSources.testComparisons) {
736
+ copyIfExists(reviewSources.testComparisons, join(shellRoot, "artifacts", "test-comparisons"), "workflow-improvement");
737
+ }
738
+ if (reviewSources.targetTestRuns) {
739
+ copyIfExists(reviewSources.targetTestRuns, join(shellRoot, "artifacts", "test-runs"), "workflow-improvement");
740
+ }
741
+ if (reviewSources.targetTestSandboxes) {
742
+ copyIfExists(reviewSources.targetTestSandboxes, join(shellRoot, "artifacts", "test-sandboxes"), "workflow-improvement");
743
+ }
744
+ const agentsContent = renderWorkflowImprovementAgents(options.workspaceName, options.workflowId, options.loopIndex);
745
+ writeNativeAgentSurface(shellRoot, agentsContent, "interf-workflow-improver", renderWorkflowImprovementSkill(options.workflowId, options.loopIndex, readWorkflowImprovementDoc(options.workspacePath)));
746
+ return {
747
+ rootPath: shellRoot,
748
+ loopRootPath,
749
+ workflowBeforePath: join(loopRootPath, "workflow-before"),
750
+ workflowAfterPath: join(loopRootPath, "workflow-after"),
751
+ promptLogPath: join(loopRootPath, "logs", "workflow-improver.prompt.txt"),
752
+ eventLogPath: join(loopRootPath, "logs", "workflow-improver.events.ndjson"),
753
+ statusLogPath: join(loopRootPath, "logs", "workflow-improver.status.log"),
754
+ };
755
+ }
756
+ export function freezeWorkflowImprovementShell(rootPath) {
757
+ return freezePreservedShell(rootPath, "workflow-improvement");
758
+ }