wingfoil 0.2.2 → 0.3.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 (454) hide show
  1. package/README.md +83 -43
  2. package/dist/agent/discovery.d.ts +72 -0
  3. package/dist/agent/discovery.d.ts.map +1 -0
  4. package/dist/agent/discovery.js +210 -0
  5. package/dist/agent/discovery.js.map +1 -0
  6. package/dist/agent/execute.d.ts +206 -0
  7. package/dist/agent/execute.d.ts.map +1 -0
  8. package/dist/agent/execute.js +581 -0
  9. package/dist/agent/execute.js.map +1 -0
  10. package/dist/agent/index.d.ts +23 -0
  11. package/dist/agent/index.d.ts.map +1 -0
  12. package/dist/agent/index.js +85 -0
  13. package/dist/agent/index.js.map +1 -0
  14. package/dist/agent/launch.d.ts +133 -0
  15. package/dist/agent/launch.d.ts.map +1 -0
  16. package/dist/agent/launch.js +380 -0
  17. package/dist/agent/launch.js.map +1 -0
  18. package/dist/agent/manifest.d.ts +30 -0
  19. package/dist/agent/manifest.d.ts.map +1 -0
  20. package/dist/agent/manifest.js +93 -0
  21. package/dist/agent/manifest.js.map +1 -0
  22. package/dist/agent/placeholders.d.ts +49 -0
  23. package/dist/agent/placeholders.d.ts.map +1 -0
  24. package/dist/agent/placeholders.js +177 -0
  25. package/dist/agent/placeholders.js.map +1 -0
  26. package/dist/agent/run-log.d.ts +254 -0
  27. package/dist/agent/run-log.d.ts.map +1 -0
  28. package/dist/agent/run-log.js +612 -0
  29. package/dist/agent/run-log.js.map +1 -0
  30. package/dist/agent/schema.d.ts +100 -0
  31. package/dist/agent/schema.d.ts.map +1 -0
  32. package/dist/agent/schema.js +89 -0
  33. package/dist/agent/schema.js.map +1 -0
  34. package/dist/agent/step.d.ts +41 -0
  35. package/dist/agent/step.d.ts.map +1 -0
  36. package/dist/agent/step.js +95 -0
  37. package/dist/agent/step.js.map +1 -0
  38. package/dist/build-info.json +4 -0
  39. package/dist/cli/error.d.ts +11 -2
  40. package/dist/cli/error.d.ts.map +1 -1
  41. package/dist/cli/error.js +27 -6
  42. package/dist/cli/error.js.map +1 -1
  43. package/dist/cli/exit.d.ts +33 -3
  44. package/dist/cli/exit.d.ts.map +1 -1
  45. package/dist/cli/exit.js +54 -3
  46. package/dist/cli/exit.js.map +1 -1
  47. package/dist/cli/index.d.ts +1 -1
  48. package/dist/cli/index.d.ts.map +1 -1
  49. package/dist/cli/index.js +2 -1
  50. package/dist/cli/index.js.map +1 -1
  51. package/dist/cli/init-command.d.ts.map +1 -1
  52. package/dist/cli/init-command.js +4 -2
  53. package/dist/cli/init-command.js.map +1 -1
  54. package/dist/cli/mcp-command.d.ts +13 -4
  55. package/dist/cli/mcp-command.d.ts.map +1 -1
  56. package/dist/cli/mcp-command.js +25 -8
  57. package/dist/cli/mcp-command.js.map +1 -1
  58. package/dist/cli/output.d.ts +12 -4
  59. package/dist/cli/output.d.ts.map +1 -1
  60. package/dist/cli/output.js +15 -4
  61. package/dist/cli/output.js.map +1 -1
  62. package/dist/cli/program.d.ts +1 -1
  63. package/dist/cli/program.d.ts.map +1 -1
  64. package/dist/cli/program.js +162 -40
  65. package/dist/cli/program.js.map +1 -1
  66. package/dist/cli/registrar.d.ts +1 -1
  67. package/dist/cli/registrar.d.ts.map +1 -1
  68. package/dist/cli/registrar.js +67 -6
  69. package/dist/cli/registrar.js.map +1 -1
  70. package/dist/cli/suggest.d.ts +20 -0
  71. package/dist/cli/suggest.d.ts.map +1 -0
  72. package/dist/cli/suggest.js +49 -0
  73. package/dist/cli/suggest.js.map +1 -0
  74. package/dist/cli/warning.d.ts +26 -0
  75. package/dist/cli/warning.d.ts.map +1 -0
  76. package/dist/cli/warning.js +66 -0
  77. package/dist/cli/warning.js.map +1 -0
  78. package/dist/cli.js +11 -2
  79. package/dist/cli.js.map +1 -1
  80. package/dist/core/agent-execute.d.ts +44 -0
  81. package/dist/core/agent-execute.d.ts.map +1 -0
  82. package/dist/core/agent-execute.js +71 -0
  83. package/dist/core/agent-execute.js.map +1 -0
  84. package/dist/core/agent-list.d.ts +95 -0
  85. package/dist/core/agent-list.d.ts.map +1 -0
  86. package/dist/core/agent-list.js +207 -0
  87. package/dist/core/agent-list.js.map +1 -0
  88. package/dist/core/agent-show.d.ts +44 -0
  89. package/dist/core/agent-show.d.ts.map +1 -0
  90. package/dist/core/agent-show.js +188 -0
  91. package/dist/core/agent-show.js.map +1 -0
  92. package/dist/core/approval-authority.d.ts +17 -14
  93. package/dist/core/approval-authority.d.ts.map +1 -1
  94. package/dist/core/approval-authority.js +9 -9
  95. package/dist/core/approval-authority.js.map +1 -1
  96. package/dist/core/builtin-asset.d.ts +18 -15
  97. package/dist/core/builtin-asset.d.ts.map +1 -1
  98. package/dist/core/builtin-asset.js +17 -14
  99. package/dist/core/builtin-asset.js.map +1 -1
  100. package/dist/core/builtin-integrity.d.ts +12 -2
  101. package/dist/core/builtin-integrity.d.ts.map +1 -1
  102. package/dist/core/builtin-integrity.js +85 -9
  103. package/dist/core/builtin-integrity.js.map +1 -1
  104. package/dist/core/confinement.d.ts +3 -1
  105. package/dist/core/confinement.d.ts.map +1 -1
  106. package/dist/core/confinement.js +7 -4
  107. package/dist/core/confinement.js.map +1 -1
  108. package/dist/core/context.d.ts +150 -98
  109. package/dist/core/context.d.ts.map +1 -1
  110. package/dist/core/context.js +602 -66
  111. package/dist/core/context.js.map +1 -1
  112. package/dist/core/directive-assign.d.ts +33 -7
  113. package/dist/core/directive-assign.d.ts.map +1 -1
  114. package/dist/core/directive-assign.js +67 -27
  115. package/dist/core/directive-assign.js.map +1 -1
  116. package/dist/core/directive-scope.d.ts +36 -0
  117. package/dist/core/directive-scope.d.ts.map +1 -0
  118. package/dist/core/directive-scope.js +34 -0
  119. package/dist/core/directive-scope.js.map +1 -0
  120. package/dist/core/directives-list.d.ts +13 -3
  121. package/dist/core/directives-list.d.ts.map +1 -1
  122. package/dist/core/directives-list.js +18 -6
  123. package/dist/core/directives-list.js.map +1 -1
  124. package/dist/core/dry-run.d.ts +33 -0
  125. package/dist/core/dry-run.d.ts.map +1 -0
  126. package/dist/core/dry-run.js +45 -0
  127. package/dist/core/dry-run.js.map +1 -0
  128. package/dist/core/element-ref.d.ts +23 -0
  129. package/dist/core/element-ref.d.ts.map +1 -0
  130. package/dist/core/element-ref.js +24 -0
  131. package/dist/core/element-ref.js.map +1 -0
  132. package/dist/core/error-details.d.ts +20 -0
  133. package/dist/core/error-details.d.ts.map +1 -0
  134. package/dist/core/error-details.js +65 -0
  135. package/dist/core/error-details.js.map +1 -0
  136. package/dist/core/exit-code.d.ts.map +1 -1
  137. package/dist/core/exit-code.js +6 -7
  138. package/dist/core/exit-code.js.map +1 -1
  139. package/dist/core/git-identity.d.ts +46 -11
  140. package/dist/core/git-identity.d.ts.map +1 -1
  141. package/dist/core/git-identity.js +140 -27
  142. package/dist/core/git-identity.js.map +1 -1
  143. package/dist/core/index.d.ts +184 -10
  144. package/dist/core/index.d.ts.map +1 -1
  145. package/dist/core/index.js +1045 -185
  146. package/dist/core/index.js.map +1 -1
  147. package/dist/core/init.d.ts +45 -5
  148. package/dist/core/init.d.ts.map +1 -1
  149. package/dist/core/init.js +134 -24
  150. package/dist/core/init.js.map +1 -1
  151. package/dist/core/loaders.d.ts +170 -14
  152. package/dist/core/loaders.d.ts.map +1 -1
  153. package/dist/core/loaders.js +570 -89
  154. package/dist/core/loaders.js.map +1 -1
  155. package/dist/core/memory-add-link.d.ts +28 -0
  156. package/dist/core/memory-add-link.d.ts.map +1 -0
  157. package/dist/core/memory-add-link.js +67 -0
  158. package/dist/core/memory-add-link.js.map +1 -0
  159. package/dist/core/memory-add-type.d.ts +25 -1
  160. package/dist/core/memory-add-type.d.ts.map +1 -1
  161. package/dist/core/memory-add-type.js +59 -1
  162. package/dist/core/memory-add-type.js.map +1 -1
  163. package/dist/core/memory-amend.d.ts +80 -0
  164. package/dist/core/memory-amend.d.ts.map +1 -0
  165. package/dist/core/memory-amend.js +160 -0
  166. package/dist/core/memory-amend.js.map +1 -0
  167. package/dist/core/memory-supersede.d.ts +28 -0
  168. package/dist/core/memory-supersede.d.ts.map +1 -0
  169. package/dist/core/memory-supersede.js +79 -0
  170. package/dist/core/memory-supersede.js.map +1 -0
  171. package/dist/core/memory-transition.d.ts +190 -30
  172. package/dist/core/memory-transition.d.ts.map +1 -1
  173. package/dist/core/memory-transition.js +480 -59
  174. package/dist/core/memory-transition.js.map +1 -1
  175. package/dist/core/registry.d.ts +82 -10
  176. package/dist/core/registry.d.ts.map +1 -1
  177. package/dist/core/registry.js +50 -0
  178. package/dist/core/registry.js.map +1 -1
  179. package/dist/core/relevance.d.ts +74 -12
  180. package/dist/core/relevance.d.ts.map +1 -1
  181. package/dist/core/relevance.js +45 -27
  182. package/dist/core/relevance.js.map +1 -1
  183. package/dist/core/require-reason.d.ts.map +1 -1
  184. package/dist/core/require-reason.js +6 -5
  185. package/dist/core/require-reason.js.map +1 -1
  186. package/dist/core/required-fields.d.ts +28 -0
  187. package/dist/core/required-fields.d.ts.map +1 -0
  188. package/dist/core/required-fields.js +60 -0
  189. package/dist/core/required-fields.js.map +1 -0
  190. package/dist/core/revision.d.ts +82 -0
  191. package/dist/core/revision.d.ts.map +1 -0
  192. package/dist/core/revision.js +144 -0
  193. package/dist/core/revision.js.map +1 -0
  194. package/dist/core/types.d.ts +28 -2
  195. package/dist/core/types.d.ts.map +1 -1
  196. package/dist/core/types.js +12 -3
  197. package/dist/core/types.js.map +1 -1
  198. package/dist/core/workflow-core-checks.d.ts +34 -0
  199. package/dist/core/workflow-core-checks.d.ts.map +1 -0
  200. package/dist/core/workflow-core-checks.js +403 -0
  201. package/dist/core/workflow-core-checks.js.map +1 -0
  202. package/dist/core/workflow-create-remove.d.ts +65 -0
  203. package/dist/core/workflow-create-remove.d.ts.map +1 -0
  204. package/dist/core/workflow-create-remove.js +277 -0
  205. package/dist/core/workflow-create-remove.js.map +1 -0
  206. package/dist/core/workflow-deduction.d.ts +48 -0
  207. package/dist/core/workflow-deduction.d.ts.map +1 -0
  208. package/dist/core/workflow-deduction.js +523 -0
  209. package/dist/core/workflow-deduction.js.map +1 -0
  210. package/dist/core/workflow-diagnostics.d.ts +83 -0
  211. package/dist/core/workflow-diagnostics.d.ts.map +1 -0
  212. package/dist/core/workflow-diagnostics.js +375 -0
  213. package/dist/core/workflow-diagnostics.js.map +1 -0
  214. package/dist/core/workflow-exit-state.d.ts +125 -0
  215. package/dist/core/workflow-exit-state.d.ts.map +1 -0
  216. package/dist/core/workflow-exit-state.js +243 -0
  217. package/dist/core/workflow-exit-state.js.map +1 -0
  218. package/dist/core/workflow-finalize.d.ts +37 -0
  219. package/dist/core/workflow-finalize.d.ts.map +1 -0
  220. package/dist/core/workflow-finalize.js +153 -0
  221. package/dist/core/workflow-finalize.js.map +1 -0
  222. package/dist/core/workflow-list-show.d.ts +176 -0
  223. package/dist/core/workflow-list-show.d.ts.map +1 -0
  224. package/dist/core/workflow-list-show.js +268 -0
  225. package/dist/core/workflow-list-show.js.map +1 -0
  226. package/dist/core/workflow-next.d.ts +268 -0
  227. package/dist/core/workflow-next.d.ts.map +1 -0
  228. package/dist/core/workflow-next.js +503 -0
  229. package/dist/core/workflow-next.js.map +1 -0
  230. package/dist/core/workflow-registry.d.ts +52 -0
  231. package/dist/core/workflow-registry.d.ts.map +1 -0
  232. package/dist/core/workflow-registry.js +158 -0
  233. package/dist/core/workflow-registry.js.map +1 -0
  234. package/dist/core/workflow-start-end.d.ts +71 -0
  235. package/dist/core/workflow-start-end.d.ts.map +1 -0
  236. package/dist/core/workflow-start-end.js +298 -0
  237. package/dist/core/workflow-start-end.js.map +1 -0
  238. package/dist/core/workflow-status.d.ts +83 -0
  239. package/dist/core/workflow-status.d.ts.map +1 -0
  240. package/dist/core/workflow-status.js +125 -0
  241. package/dist/core/workflow-status.js.map +1 -0
  242. package/dist/core/write-guard.d.ts +51 -8
  243. package/dist/core/write-guard.d.ts.map +1 -1
  244. package/dist/core/write-guard.js +139 -9
  245. package/dist/core/write-guard.js.map +1 -1
  246. package/dist/directives/index.d.ts +3 -2
  247. package/dist/directives/index.d.ts.map +1 -1
  248. package/dist/directives/index.js +5 -3
  249. package/dist/directives/index.js.map +1 -1
  250. package/dist/directives/schema.d.ts +34 -29
  251. package/dist/directives/schema.d.ts.map +1 -1
  252. package/dist/directives/schema.js +35 -29
  253. package/dist/directives/schema.js.map +1 -1
  254. package/dist/directives/version.d.ts +28 -0
  255. package/dist/directives/version.d.ts.map +1 -0
  256. package/dist/directives/version.js +51 -0
  257. package/dist/directives/version.js.map +1 -0
  258. package/dist/dna/edit.d.ts +7 -6
  259. package/dist/dna/edit.d.ts.map +1 -1
  260. package/dist/dna/edit.js +96 -41
  261. package/dist/dna/edit.js.map +1 -1
  262. package/dist/dna/mutate.js +18 -3
  263. package/dist/dna/mutate.js.map +1 -1
  264. package/dist/dna/path.d.ts +2 -2
  265. package/dist/dna/roles.d.ts +1 -1
  266. package/dist/dna/schema.d.ts +61 -3
  267. package/dist/dna/schema.d.ts.map +1 -1
  268. package/dist/dna/schema.js +121 -6
  269. package/dist/dna/schema.js.map +1 -1
  270. package/dist/mcp/dna-resource.d.ts.map +1 -1
  271. package/dist/mcp/dna-resource.js +4 -4
  272. package/dist/mcp/dna-resource.js.map +1 -1
  273. package/dist/mcp/index.d.ts +8 -4
  274. package/dist/mcp/index.d.ts.map +1 -1
  275. package/dist/mcp/index.js +13 -2
  276. package/dist/mcp/index.js.map +1 -1
  277. package/dist/mcp/memory-resource.d.ts.map +1 -1
  278. package/dist/mcp/memory-resource.js +30 -19
  279. package/dist/mcp/memory-resource.js.map +1 -1
  280. package/dist/mcp/prompt.d.ts +61 -24
  281. package/dist/mcp/prompt.d.ts.map +1 -1
  282. package/dist/mcp/prompt.js +176 -47
  283. package/dist/mcp/prompt.js.map +1 -1
  284. package/dist/mcp/read-only.d.ts +39 -0
  285. package/dist/mcp/read-only.d.ts.map +1 -1
  286. package/dist/mcp/read-only.js +61 -0
  287. package/dist/mcp/read-only.js.map +1 -1
  288. package/dist/mcp/registrar.d.ts +10 -0
  289. package/dist/mcp/registrar.d.ts.map +1 -1
  290. package/dist/mcp/registrar.js +48 -12
  291. package/dist/mcp/registrar.js.map +1 -1
  292. package/dist/mcp/server.d.ts +21 -14
  293. package/dist/mcp/server.d.ts.map +1 -1
  294. package/dist/mcp/server.js +41 -15
  295. package/dist/mcp/server.js.map +1 -1
  296. package/dist/mcp/session-resource.d.ts +13 -0
  297. package/dist/mcp/session-resource.d.ts.map +1 -0
  298. package/dist/mcp/session-resource.js +65 -0
  299. package/dist/mcp/session-resource.js.map +1 -0
  300. package/dist/mcp/workflow-resource.d.ts +18 -0
  301. package/dist/mcp/workflow-resource.d.ts.map +1 -1
  302. package/dist/mcp/workflow-resource.js +37 -8
  303. package/dist/mcp/workflow-resource.js.map +1 -1
  304. package/dist/memory/add.d.ts +110 -24
  305. package/dist/memory/add.d.ts.map +1 -1
  306. package/dist/memory/add.js +251 -64
  307. package/dist/memory/add.js.map +1 -1
  308. package/dist/memory/audit.d.ts +152 -39
  309. package/dist/memory/audit.d.ts.map +1 -1
  310. package/dist/memory/audit.js +257 -103
  311. package/dist/memory/audit.js.map +1 -1
  312. package/dist/memory/commit-message.d.ts +60 -38
  313. package/dist/memory/commit-message.d.ts.map +1 -1
  314. package/dist/memory/commit-message.js +167 -21
  315. package/dist/memory/commit-message.js.map +1 -1
  316. package/dist/memory/entry.d.ts.map +1 -1
  317. package/dist/memory/entry.js +1 -2
  318. package/dist/memory/entry.js.map +1 -1
  319. package/dist/memory/frontmatter-edit.d.ts +16 -4
  320. package/dist/memory/frontmatter-edit.d.ts.map +1 -1
  321. package/dist/memory/frontmatter-edit.js +13 -1
  322. package/dist/memory/frontmatter-edit.js.map +1 -1
  323. package/dist/memory/git-log.d.ts +18 -6
  324. package/dist/memory/git-log.d.ts.map +1 -1
  325. package/dist/memory/git-log.js +40 -13
  326. package/dist/memory/git-log.js.map +1 -1
  327. package/dist/memory/history.d.ts +73 -12
  328. package/dist/memory/history.d.ts.map +1 -1
  329. package/dist/memory/history.js +128 -44
  330. package/dist/memory/history.js.map +1 -1
  331. package/dist/memory/index.d.ts +13 -11
  332. package/dist/memory/index.d.ts.map +1 -1
  333. package/dist/memory/index.js +34 -3
  334. package/dist/memory/index.js.map +1 -1
  335. package/dist/memory/query.d.ts +161 -19
  336. package/dist/memory/query.d.ts.map +1 -1
  337. package/dist/memory/query.js +435 -55
  338. package/dist/memory/query.js.map +1 -1
  339. package/dist/memory/schema.d.ts +52 -3
  340. package/dist/memory/schema.d.ts.map +1 -1
  341. package/dist/memory/schema.js +132 -8
  342. package/dist/memory/schema.js.map +1 -1
  343. package/dist/memory/state-machine.d.ts +65 -10
  344. package/dist/memory/state-machine.d.ts.map +1 -1
  345. package/dist/memory/state-machine.js +134 -46
  346. package/dist/memory/state-machine.js.map +1 -1
  347. package/dist/memory/submit.d.ts +52 -3
  348. package/dist/memory/submit.d.ts.map +1 -1
  349. package/dist/memory/submit.js +118 -11
  350. package/dist/memory/submit.js.map +1 -1
  351. package/dist/storage/build-stamp.d.ts +18 -0
  352. package/dist/storage/build-stamp.d.ts.map +1 -0
  353. package/dist/storage/build-stamp.js +68 -0
  354. package/dist/storage/build-stamp.js.map +1 -0
  355. package/dist/storage/builtin-adapters.d.ts +32 -0
  356. package/dist/storage/builtin-adapters.d.ts.map +1 -0
  357. package/dist/storage/builtin-adapters.js +100 -0
  358. package/dist/storage/builtin-adapters.js.map +1 -0
  359. package/dist/storage/builtin-directives.d.ts +0 -29
  360. package/dist/storage/builtin-directives.d.ts.map +1 -1
  361. package/dist/storage/builtin-directives.js +9 -4
  362. package/dist/storage/builtin-directives.js.map +1 -1
  363. package/dist/storage/commit.d.ts +310 -3
  364. package/dist/storage/commit.d.ts.map +1 -1
  365. package/dist/storage/commit.js +807 -33
  366. package/dist/storage/commit.js.map +1 -1
  367. package/dist/storage/document.d.ts +6 -0
  368. package/dist/storage/document.d.ts.map +1 -1
  369. package/dist/storage/document.js +10 -1
  370. package/dist/storage/document.js.map +1 -1
  371. package/dist/storage/dry-run.d.ts +65 -0
  372. package/dist/storage/dry-run.d.ts.map +1 -0
  373. package/dist/storage/dry-run.js +150 -0
  374. package/dist/storage/dry-run.js.map +1 -0
  375. package/dist/storage/errors.d.ts +26 -0
  376. package/dist/storage/errors.d.ts.map +1 -1
  377. package/dist/storage/errors.js +27 -1
  378. package/dist/storage/errors.js.map +1 -1
  379. package/dist/storage/frontmatter.d.ts +1 -1
  380. package/dist/storage/frontmatter.js +1 -1
  381. package/dist/storage/git-read.d.ts +64 -0
  382. package/dist/storage/git-read.d.ts.map +1 -0
  383. package/dist/storage/git-read.js +107 -0
  384. package/dist/storage/git-read.js.map +1 -0
  385. package/dist/storage/index.d.ts +13 -5
  386. package/dist/storage/index.d.ts.map +1 -1
  387. package/dist/storage/index.js +39 -2
  388. package/dist/storage/index.js.map +1 -1
  389. package/dist/storage/layout.d.ts +2 -2
  390. package/dist/storage/layout.d.ts.map +1 -1
  391. package/dist/storage/layout.js +2 -7
  392. package/dist/storage/layout.js.map +1 -1
  393. package/dist/storage/memory-path.d.ts +18 -5
  394. package/dist/storage/memory-path.d.ts.map +1 -1
  395. package/dist/storage/memory-path.js +41 -5
  396. package/dist/storage/memory-path.js.map +1 -1
  397. package/dist/storage/snapshot.js +1 -1
  398. package/dist/storage/templates.d.ts +33 -6
  399. package/dist/storage/templates.d.ts.map +1 -1
  400. package/dist/storage/templates.js +170 -16
  401. package/dist/storage/templates.js.map +1 -1
  402. package/dist/validation/config-version.d.ts +19 -0
  403. package/dist/validation/config-version.d.ts.map +1 -0
  404. package/dist/validation/config-version.js +53 -0
  405. package/dist/validation/config-version.js.map +1 -0
  406. package/dist/validation/diagnostic.d.ts +40 -0
  407. package/dist/validation/diagnostic.d.ts.map +1 -0
  408. package/dist/validation/diagnostic.js +41 -0
  409. package/dist/validation/diagnostic.js.map +1 -0
  410. package/dist/validation/format.d.ts +74 -0
  411. package/dist/validation/format.d.ts.map +1 -0
  412. package/dist/validation/format.js +104 -0
  413. package/dist/validation/format.js.map +1 -0
  414. package/dist/validation/id.d.ts +14 -0
  415. package/dist/validation/id.d.ts.map +1 -1
  416. package/dist/validation/id.js +35 -11
  417. package/dist/validation/id.js.map +1 -1
  418. package/dist/validation/identity.d.ts +40 -0
  419. package/dist/validation/identity.d.ts.map +1 -0
  420. package/dist/validation/identity.js +78 -0
  421. package/dist/validation/identity.js.map +1 -0
  422. package/dist/validation/index.d.ts +9 -3
  423. package/dist/validation/index.d.ts.map +1 -1
  424. package/dist/validation/index.js +30 -1
  425. package/dist/validation/index.js.map +1 -1
  426. package/dist/validation/secret-scan.d.ts +3 -2
  427. package/dist/validation/secret-scan.d.ts.map +1 -1
  428. package/dist/validation/secret-scan.js +32 -11
  429. package/dist/validation/secret-scan.js.map +1 -1
  430. package/dist/validation/warning.d.ts +30 -16
  431. package/dist/validation/warning.d.ts.map +1 -1
  432. package/dist/validation/warning.js +74 -7
  433. package/dist/validation/warning.js.map +1 -1
  434. package/dist/workflow/bindings.d.ts +152 -0
  435. package/dist/workflow/bindings.d.ts.map +1 -0
  436. package/dist/workflow/bindings.js +249 -0
  437. package/dist/workflow/bindings.js.map +1 -0
  438. package/dist/workflow/create.d.ts +13 -0
  439. package/dist/workflow/create.d.ts.map +1 -0
  440. package/dist/workflow/create.js +41 -0
  441. package/dist/workflow/create.js.map +1 -0
  442. package/dist/workflow/deduce.d.ts +400 -0
  443. package/dist/workflow/deduce.d.ts.map +1 -0
  444. package/dist/workflow/deduce.js +1109 -0
  445. package/dist/workflow/deduce.js.map +1 -0
  446. package/dist/workflow/manifest-edit.d.ts +19 -0
  447. package/dist/workflow/manifest-edit.d.ts.map +1 -0
  448. package/dist/workflow/manifest-edit.js +124 -0
  449. package/dist/workflow/manifest-edit.js.map +1 -0
  450. package/dist/workflow/schema.d.ts +158 -19
  451. package/dist/workflow/schema.d.ts.map +1 -1
  452. package/dist/workflow/schema.js +163 -15
  453. package/dist/workflow/schema.js.map +1 -1
  454. package/package.json +18 -8
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attributionLine = exports.agentCommandFound = exports.uuidV5 = exports.SESSION_ID_NAMESPACE = exports.runSummaryLine = exports.renderLaunchArgv = exports.readJsonPath = exports.LOOKUP_TIMEOUT_MS = exports.launchBanner = exports.launchAgent = exports.assignedSessionId = exports.serializeRunRecord = exports.runLogPreflight = exports.runLogDirPrefix = exports.RUN_TOKEN_KEYS = exports.RUN_RECORD_KEYS = exports.runIdElementId = exports.resolveRunLogPath = exports.requireWritableRunLog = exports.recordSubject = exports.recordRun = exports.readRunLogsAt = exports.readRunLogAt = exports.parseRunLog = exports.notesField = exports.NOT_REPORTED = exports.NO_WORKFLOW = exports.nextRunId = exports.isRunLogPath = exports.isRunId = exports.formatRunId = exports.executionNotesSection = exports.deriveNotesField = exports.ADHOC_PHASE = exports.W_ADAPTER_IGNORED = exports.loadAdapter = exports.listAdaptersAtRev = exports.E_ADAPTER_DUPLICATE = exports.duplicateAdapterRefusal = exports.ADAPTERS_DIR_PATH = exports.adapterTreeDiagnosticsAtRev = exports.requiredPlaceholderIssues = exports.placeholderIssues = exports.E_ADAPTER_PLACEHOLDER = exports.ADAPTER_PLACEHOLDERS = exports.parseAdapterManifest = exports.E_ADAPTER_MANIFEST = exports.AdapterManifest = exports.ADAPTER_MANIFEST_FORMAT = exports.MODULE_NAME = void 0;
4
+ exports.withRunFiles = exports.selectAgent = exports.runningBuildMcpServer = exports.renderMcpTemplate = exports.renderBootstrap = exports.mcpPreflight = exports.MCP_UNREACHABLE_MESSAGE = exports.MCP_PREFLIGHT_TIMEOUT_MS = exports.launchPlan = exports.handoffLine = exports.FRESH_MODE = exports.DEFAULT_ROLE_WARNING = exports.DEFAULT_ROLE = exports.agentExecutePipeline = exports.ATTRIBUTION_LINE_PREFIX = void 0;
5
+ /**
6
+ * `agent` module — launching an agent's own CLI through a declared adapter (`adr-012`,
7
+ * `spec-016-agent-execution` §1). It owns adapter manifest loading and validation (task-177: the strict
8
+ * schema §2.2, the placeholder rules §2.3, discovery and loading at a revision §2.1, §3.2 step 5, and
9
+ * the report of what under `.wingfoil/agents/` is not an adapter, `bug-290`), the run log (task-206),
10
+ * `agent execute`'s pipeline up to the spawn (task-218, `./execute.ts`) and the launch (task-228,
11
+ * `./launch.ts`). Its operations are registered under the `agent` `CoreModule` (`src/core/index.ts`).
12
+ */
13
+ exports.MODULE_NAME = 'agent';
14
+ var schema_1 = require("./schema");
15
+ Object.defineProperty(exports, "ADAPTER_MANIFEST_FORMAT", { enumerable: true, get: function () { return schema_1.ADAPTER_MANIFEST_FORMAT; } });
16
+ Object.defineProperty(exports, "AdapterManifest", { enumerable: true, get: function () { return schema_1.AdapterManifest; } });
17
+ var manifest_1 = require("./manifest");
18
+ Object.defineProperty(exports, "E_ADAPTER_MANIFEST", { enumerable: true, get: function () { return manifest_1.E_ADAPTER_MANIFEST; } });
19
+ Object.defineProperty(exports, "parseAdapterManifest", { enumerable: true, get: function () { return manifest_1.parseAdapterManifest; } });
20
+ var placeholders_1 = require("./placeholders");
21
+ Object.defineProperty(exports, "ADAPTER_PLACEHOLDERS", { enumerable: true, get: function () { return placeholders_1.ADAPTER_PLACEHOLDERS; } });
22
+ Object.defineProperty(exports, "E_ADAPTER_PLACEHOLDER", { enumerable: true, get: function () { return placeholders_1.E_ADAPTER_PLACEHOLDER; } });
23
+ Object.defineProperty(exports, "placeholderIssues", { enumerable: true, get: function () { return placeholders_1.placeholderIssues; } });
24
+ Object.defineProperty(exports, "requiredPlaceholderIssues", { enumerable: true, get: function () { return placeholders_1.requiredPlaceholderIssues; } });
25
+ var discovery_1 = require("./discovery");
26
+ Object.defineProperty(exports, "adapterTreeDiagnosticsAtRev", { enumerable: true, get: function () { return discovery_1.adapterTreeDiagnosticsAtRev; } });
27
+ Object.defineProperty(exports, "ADAPTERS_DIR_PATH", { enumerable: true, get: function () { return discovery_1.ADAPTERS_DIR_PATH; } });
28
+ Object.defineProperty(exports, "duplicateAdapterRefusal", { enumerable: true, get: function () { return discovery_1.duplicateAdapterRefusal; } });
29
+ Object.defineProperty(exports, "E_ADAPTER_DUPLICATE", { enumerable: true, get: function () { return discovery_1.E_ADAPTER_DUPLICATE; } });
30
+ Object.defineProperty(exports, "listAdaptersAtRev", { enumerable: true, get: function () { return discovery_1.listAdaptersAtRev; } });
31
+ Object.defineProperty(exports, "loadAdapter", { enumerable: true, get: function () { return discovery_1.loadAdapter; } });
32
+ Object.defineProperty(exports, "W_ADAPTER_IGNORED", { enumerable: true, get: function () { return discovery_1.W_ADAPTER_IGNORED; } });
33
+ var run_log_1 = require("./run-log");
34
+ Object.defineProperty(exports, "ADHOC_PHASE", { enumerable: true, get: function () { return run_log_1.ADHOC_PHASE; } });
35
+ Object.defineProperty(exports, "deriveNotesField", { enumerable: true, get: function () { return run_log_1.deriveNotesField; } });
36
+ Object.defineProperty(exports, "executionNotesSection", { enumerable: true, get: function () { return run_log_1.executionNotesSection; } });
37
+ Object.defineProperty(exports, "formatRunId", { enumerable: true, get: function () { return run_log_1.formatRunId; } });
38
+ Object.defineProperty(exports, "isRunId", { enumerable: true, get: function () { return run_log_1.isRunId; } });
39
+ Object.defineProperty(exports, "isRunLogPath", { enumerable: true, get: function () { return run_log_1.isRunLogPath; } });
40
+ Object.defineProperty(exports, "nextRunId", { enumerable: true, get: function () { return run_log_1.nextRunId; } });
41
+ Object.defineProperty(exports, "NO_WORKFLOW", { enumerable: true, get: function () { return run_log_1.NO_WORKFLOW; } });
42
+ Object.defineProperty(exports, "NOT_REPORTED", { enumerable: true, get: function () { return run_log_1.NOT_REPORTED; } });
43
+ Object.defineProperty(exports, "notesField", { enumerable: true, get: function () { return run_log_1.notesField; } });
44
+ Object.defineProperty(exports, "parseRunLog", { enumerable: true, get: function () { return run_log_1.parseRunLog; } });
45
+ Object.defineProperty(exports, "readRunLogAt", { enumerable: true, get: function () { return run_log_1.readRunLogAt; } });
46
+ Object.defineProperty(exports, "readRunLogsAt", { enumerable: true, get: function () { return run_log_1.readRunLogsAt; } });
47
+ Object.defineProperty(exports, "recordRun", { enumerable: true, get: function () { return run_log_1.recordRun; } });
48
+ Object.defineProperty(exports, "recordSubject", { enumerable: true, get: function () { return run_log_1.recordSubject; } });
49
+ Object.defineProperty(exports, "requireWritableRunLog", { enumerable: true, get: function () { return run_log_1.requireWritableRunLog; } });
50
+ Object.defineProperty(exports, "resolveRunLogPath", { enumerable: true, get: function () { return run_log_1.resolveRunLogPath; } });
51
+ Object.defineProperty(exports, "runIdElementId", { enumerable: true, get: function () { return run_log_1.runIdElementId; } });
52
+ Object.defineProperty(exports, "RUN_RECORD_KEYS", { enumerable: true, get: function () { return run_log_1.RUN_RECORD_KEYS; } });
53
+ Object.defineProperty(exports, "RUN_TOKEN_KEYS", { enumerable: true, get: function () { return run_log_1.RUN_TOKEN_KEYS; } });
54
+ Object.defineProperty(exports, "runLogDirPrefix", { enumerable: true, get: function () { return run_log_1.runLogDirPrefix; } });
55
+ Object.defineProperty(exports, "runLogPreflight", { enumerable: true, get: function () { return run_log_1.runLogPreflight; } });
56
+ Object.defineProperty(exports, "serializeRunRecord", { enumerable: true, get: function () { return run_log_1.serializeRunRecord; } });
57
+ var launch_1 = require("./launch");
58
+ Object.defineProperty(exports, "assignedSessionId", { enumerable: true, get: function () { return launch_1.assignedSessionId; } });
59
+ Object.defineProperty(exports, "launchAgent", { enumerable: true, get: function () { return launch_1.launchAgent; } });
60
+ Object.defineProperty(exports, "launchBanner", { enumerable: true, get: function () { return launch_1.launchBanner; } });
61
+ Object.defineProperty(exports, "LOOKUP_TIMEOUT_MS", { enumerable: true, get: function () { return launch_1.LOOKUP_TIMEOUT_MS; } });
62
+ Object.defineProperty(exports, "readJsonPath", { enumerable: true, get: function () { return launch_1.readJsonPath; } });
63
+ Object.defineProperty(exports, "renderLaunchArgv", { enumerable: true, get: function () { return launch_1.renderLaunchArgv; } });
64
+ Object.defineProperty(exports, "runSummaryLine", { enumerable: true, get: function () { return launch_1.runSummaryLine; } });
65
+ Object.defineProperty(exports, "SESSION_ID_NAMESPACE", { enumerable: true, get: function () { return launch_1.SESSION_ID_NAMESPACE; } });
66
+ Object.defineProperty(exports, "uuidV5", { enumerable: true, get: function () { return launch_1.uuidV5; } });
67
+ var execute_1 = require("./execute");
68
+ Object.defineProperty(exports, "agentCommandFound", { enumerable: true, get: function () { return execute_1.agentCommandFound; } });
69
+ Object.defineProperty(exports, "attributionLine", { enumerable: true, get: function () { return execute_1.attributionLine; } });
70
+ Object.defineProperty(exports, "ATTRIBUTION_LINE_PREFIX", { enumerable: true, get: function () { return execute_1.ATTRIBUTION_LINE_PREFIX; } });
71
+ Object.defineProperty(exports, "agentExecutePipeline", { enumerable: true, get: function () { return execute_1.agentExecutePipeline; } });
72
+ Object.defineProperty(exports, "DEFAULT_ROLE", { enumerable: true, get: function () { return execute_1.DEFAULT_ROLE; } });
73
+ Object.defineProperty(exports, "DEFAULT_ROLE_WARNING", { enumerable: true, get: function () { return execute_1.DEFAULT_ROLE_WARNING; } });
74
+ Object.defineProperty(exports, "FRESH_MODE", { enumerable: true, get: function () { return execute_1.FRESH_MODE; } });
75
+ Object.defineProperty(exports, "handoffLine", { enumerable: true, get: function () { return execute_1.handoffLine; } });
76
+ Object.defineProperty(exports, "launchPlan", { enumerable: true, get: function () { return execute_1.launchPlan; } });
77
+ Object.defineProperty(exports, "MCP_PREFLIGHT_TIMEOUT_MS", { enumerable: true, get: function () { return execute_1.MCP_PREFLIGHT_TIMEOUT_MS; } });
78
+ Object.defineProperty(exports, "MCP_UNREACHABLE_MESSAGE", { enumerable: true, get: function () { return execute_1.MCP_UNREACHABLE_MESSAGE; } });
79
+ Object.defineProperty(exports, "mcpPreflight", { enumerable: true, get: function () { return execute_1.mcpPreflight; } });
80
+ Object.defineProperty(exports, "renderBootstrap", { enumerable: true, get: function () { return execute_1.renderBootstrap; } });
81
+ Object.defineProperty(exports, "renderMcpTemplate", { enumerable: true, get: function () { return execute_1.renderMcpTemplate; } });
82
+ Object.defineProperty(exports, "runningBuildMcpServer", { enumerable: true, get: function () { return execute_1.runningBuildMcpServer; } });
83
+ Object.defineProperty(exports, "selectAgent", { enumerable: true, get: function () { return execute_1.selectAgent; } });
84
+ Object.defineProperty(exports, "withRunFiles", { enumerable: true, get: function () { return execute_1.withRunFiles; } });
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;GAOG;AACU,QAAA,WAAW,GAAG,OAAgB,CAAC;AAE5C,mCAAoE;AAA3D,iHAAA,uBAAuB,OAAA;AAAE,yGAAA,eAAe,OAAA;AACjD,uCAAsE;AAA7D,8GAAA,kBAAkB,OAAA;AAAE,gHAAA,oBAAoB,OAAA;AAEjD,+CAA2H;AAAlH,oHAAA,oBAAoB,OAAA;AAAE,qHAAA,qBAAqB,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,yHAAA,yBAAyB,OAAA;AAElG,yCAA8K;AAArK,wHAAA,2BAA2B,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,oHAAA,uBAAuB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAExJ,qCAwBmB;AAvBjB,sGAAA,WAAW,OAAA;AACX,2GAAA,gBAAgB,OAAA;AAChB,gHAAA,qBAAqB,OAAA;AACrB,sGAAA,WAAW,OAAA;AACX,kGAAA,OAAO,OAAA;AACP,uGAAA,YAAY,OAAA;AACZ,oGAAA,SAAS,OAAA;AACT,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AACZ,qGAAA,UAAU,OAAA;AACV,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AACZ,wGAAA,aAAa,OAAA;AACb,oGAAA,SAAS,OAAA;AACT,wGAAA,aAAa,OAAA;AACb,gHAAA,qBAAqB,OAAA;AACrB,4GAAA,iBAAiB,OAAA;AACjB,yGAAA,cAAc,OAAA;AACd,0GAAA,eAAe,OAAA;AACf,yGAAA,cAAc,OAAA;AACd,0GAAA,eAAe,OAAA;AACf,0GAAA,eAAe,OAAA;AACf,6GAAA,kBAAkB,OAAA;AAWpB,mCAUkB;AAThB,2GAAA,iBAAiB,OAAA;AACjB,qGAAA,WAAW,OAAA;AACX,sGAAA,YAAY,OAAA;AACZ,2GAAA,iBAAiB,OAAA;AACjB,sGAAA,YAAY,OAAA;AACZ,0GAAA,gBAAgB,OAAA;AAChB,wGAAA,cAAc,OAAA;AACd,8GAAA,oBAAoB,OAAA;AACpB,gGAAA,MAAM,OAAA;AAGR,qCAkBmB;AAjBjB,4GAAA,iBAAiB,OAAA;AACjB,0GAAA,eAAe,OAAA;AACf,kHAAA,uBAAuB,OAAA;AACvB,+GAAA,oBAAoB,OAAA;AACpB,uGAAA,YAAY,OAAA;AACZ,+GAAA,oBAAoB,OAAA;AACpB,qGAAA,UAAU,OAAA;AACV,sGAAA,WAAW,OAAA;AACX,qGAAA,UAAU,OAAA;AACV,mHAAA,wBAAwB,OAAA;AACxB,kHAAA,uBAAuB,OAAA;AACvB,uGAAA,YAAY,OAAA;AACZ,0GAAA,eAAe,OAAA;AACf,4GAAA,iBAAiB,OAAA;AACjB,gHAAA,qBAAqB,OAAA;AACrB,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `wingfoil agent execute`, the launch half (`spec-016-agent-execution` §3.3 steps 13–18, task-228):
3
+ * what follows the pre-launch pipeline (`./execute.ts`) once every check has passed.
4
+ *
5
+ * 13. The banner, `run <run-id>: launching <agent> (<adapter>) as <role> on <type>:<id>`, as a notice
6
+ * on stderr (`reportNotice`): the CLI renders it in the active `--format`.
7
+ * 14. The spawn: the adapter's `command` with `launch.interactive.args` (+ `session.assign_args` under
8
+ * `session.id: assign`), every placeholder filling whole argv elements ({@link renderLaunchArgv}),
9
+ * no shell, the agent inheriting stdin, stdout and stderr, its working directory the project root,
10
+ * the environment passed through unchanged (`adr-012` point 1). This is REQ-PERF-01's "agent ready".
11
+ * 15. The wait. From the spawn until the record is committed `SIGINT` and `SIGQUIT` are ignored (the
12
+ * terminal delivers them to the agent itself, in the same foreground process group) and `SIGTERM`
13
+ * and `SIGHUP` are forwarded to the agent while it runs, so a run ended by a signal is still recorded
14
+ * as `signal:<NAME>`.
15
+ * 16. The post-run lookups (§2.6): `version_args`, `session.lookup_args`, `usage.lookup_args`, each run as
16
+ * `command` + argv with a time limit ({@link LOOKUP_TIMEOUT_MS}); one argv declared twice runs once.
17
+ * A lookup that fails, times out or prints no JSON, and a value of the wrong type, yield
18
+ * `not-reported` and a `warning:` line; the lookup never fails the run.
19
+ * 17. The record (§4.2), appended and committed by `recordRun` (task-206): `agent: record <run-id>`.
20
+ * 18. The outcome: success only when the agent exited `0` and the record was committed.
21
+ *
22
+ * **Determinism.** The argv, the session id and every record field but `duration_ms` are pure functions
23
+ * of committed state and the run's inputs; the temporary-file paths and the Node executable are host
24
+ * values that never reach the context (`spec-016` Consequences). `duration_ms` is wall-clock by design:
25
+ * a record of what happened, never part of a context (`dl-114` Q2).
26
+ */
27
+ import { type ChildProcess, type SpawnOptions } from 'node:child_process';
28
+ import { type CoreResult } from '../core/types';
29
+ import type { AdapterManifest } from './schema';
30
+ import { type RunRecord } from './run-log';
31
+ /** How long one post-run lookup may run (§2.6, §3.3 step 16). */
32
+ export declare const LOOKUP_TIMEOUT_MS = 10000;
33
+ /**
34
+ * The namespace of the assigned session ids (§2.6): the version 5 UUID of the name
35
+ * `wingfoil:spec-016:session` in RFC 4122's URL namespace, fixed here so no clock or random source is
36
+ * involved.
37
+ */
38
+ export declare const SESSION_ID_NAMESPACE = "a432dcd6-576d-5991-9503-2b23aa4139db";
39
+ /** RFC 4122 §4.3 name-based UUID, version 5 (SHA-1) of `name` in `namespace`. */
40
+ export declare function uuidV5(namespace: string, name: string): string;
41
+ /**
42
+ * The session id WingFoil assigns (§2.6 `assign`): the v5 UUID of `<absolute repository root>\n<run id>`
43
+ * in {@link SESSION_ID_NAMESPACE}. Unique per clone and run, derived, never random. Per clone by design
44
+ * (it hashes the root): the run id is the identifier across clones (`dl-135` Q3 (a)).
45
+ */
46
+ export declare function assignedSessionId(root: string, runId: string): string;
47
+ /** The values the launch placeholders take (§2.3). */
48
+ export interface LaunchValues {
49
+ readonly bootstrap: string;
50
+ /** Absolute paths of the temporary files the launch declared. */
51
+ readonly files: Partial<Record<'bootstrap_file' | 'mcp_config_file', string>>;
52
+ readonly mcpServer: {
53
+ readonly command: string;
54
+ readonly args: readonly string[];
55
+ };
56
+ /** The rendered `mcp.template`, passed as one whole argv element; read only under `mcp.via: config-arg`. */
57
+ readonly mcpConfig?: string | undefined;
58
+ /** The assigned session id; read only under `session.id: assign`. */
59
+ readonly sessionId: string;
60
+ }
61
+ /**
62
+ * The launch argv (§3.3 step 14): `launch.interactive.args` rendered, then `session.assign_args`
63
+ * rendered when the session id is assigned. The `command` is not part of it.
64
+ */
65
+ export declare function renderLaunchArgv(manifest: AdapterManifest, values: LaunchValues): string[];
66
+ /**
67
+ * The value at the dotted `path` of a JSON value (§2.2 `session.field`, `usage.fields`): each segment a
68
+ * key of a plain object; `undefined` when a segment is absent or the value on the way is not an object.
69
+ */
70
+ export declare function readJsonPath(document: unknown, path: string): unknown;
71
+ /** What starts the agent: `child_process.spawn`'s shape, overridable by an in-process caller (tests). */
72
+ export type SpawnAgent = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
73
+ /** The host facts the launch reads, each overridable by an in-process caller (tests). */
74
+ export interface LaunchHost {
75
+ /** What starts the agent; `child_process.spawn` by default. */
76
+ readonly spawn?: SpawnAgent;
77
+ /** {@link LOOKUP_TIMEOUT_MS} by default. */
78
+ readonly lookupTimeoutMs?: number;
79
+ }
80
+ /** What the launch needs from the pre-launch pipeline (`PreparedLaunch`, `./execute.ts`). */
81
+ export interface LaunchInput {
82
+ readonly runId: string;
83
+ /** `<type>:<id>`. */
84
+ readonly element: string;
85
+ readonly workflow: string;
86
+ readonly phase: string;
87
+ readonly role: string;
88
+ readonly mode: string;
89
+ readonly agent: {
90
+ readonly name: string;
91
+ };
92
+ readonly adapter: {
93
+ readonly name: string;
94
+ readonly kind: string;
95
+ readonly manifest: AdapterManifest;
96
+ };
97
+ readonly stateRef: string;
98
+ readonly logPath: string;
99
+ /** Root-relative path of the element's document at `state_ref`. */
100
+ readonly elementPath: string;
101
+ /** Root-relative path of the element type's template file, when the type declares one. */
102
+ readonly templatePath: string | undefined;
103
+ readonly bootstrap: string;
104
+ readonly mcpServer: {
105
+ readonly command: string;
106
+ readonly args: readonly string[];
107
+ };
108
+ readonly files: Partial<Record<'bootstrap_file' | 'mcp_config_file', string>>;
109
+ /** The rendered `mcp.template` under `mcp.via: config-arg` (§2.3 `{mcp_config}`); `undefined` otherwise. */
110
+ readonly mcpConfig?: string | undefined;
111
+ }
112
+ /** A launched run, recorded: what `agent execute` reports (§3.4's `{ "run": <record> }`). */
113
+ export interface RecordedLaunch {
114
+ readonly run: RunRecord;
115
+ /** The `agent: record <run-id>` commit. */
116
+ readonly sha: string;
117
+ }
118
+ /** §3.4's post-run summary line, without a prefix. */
119
+ export declare function runSummaryLine(record: RunRecord, sha: string): string;
120
+ /** The step-13 banner (§3.3), without a prefix. */
121
+ export declare function launchBanner(input: LaunchInput): string;
122
+ /**
123
+ * §3.3 steps 13–18 for a launch every pre-launch check has passed. `releaseSignals` is called right
124
+ * before the spawn, after the launch has installed its own listeners: it hands the process's signals
125
+ * over from the pre-launch cleanup (`withRunFiles`) to the launch (§3.3 step 15) with no gap between.
126
+ *
127
+ * @returns The recorded run (the agent exited `0` and the record was committed); otherwise `IO`
128
+ * `agent command '<command>' could not be started …` (no run, no record), `IO` `agent exited
129
+ * <exit_status>; run <run-id> recorded` with `details: {run_id, exit_status}` and the summary as a
130
+ * detail line, or `recordRun`'s refusal, the record in its `details` (the run is never lost).
131
+ */
132
+ export declare function launchAgent(root: string, input: LaunchInput, host: LaunchHost, releaseSignals: () => void): Promise<CoreResult<RecordedLaunch>>;
133
+ //# sourceMappingURL=launch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../src/agent/launch.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SESSION_ID_NAMESPACE = exports.LOOKUP_TIMEOUT_MS = void 0;
4
+ exports.uuidV5 = uuidV5;
5
+ exports.assignedSessionId = assignedSessionId;
6
+ exports.renderLaunchArgv = renderLaunchArgv;
7
+ exports.readJsonPath = readJsonPath;
8
+ exports.runSummaryLine = runSummaryLine;
9
+ exports.launchBanner = launchBanner;
10
+ exports.launchAgent = launchAgent;
11
+ /**
12
+ * `wingfoil agent execute`, the launch half (`spec-016-agent-execution` §3.3 steps 13–18, task-228):
13
+ * what follows the pre-launch pipeline (`./execute.ts`) once every check has passed.
14
+ *
15
+ * 13. The banner, `run <run-id>: launching <agent> (<adapter>) as <role> on <type>:<id>`, as a notice
16
+ * on stderr (`reportNotice`): the CLI renders it in the active `--format`.
17
+ * 14. The spawn: the adapter's `command` with `launch.interactive.args` (+ `session.assign_args` under
18
+ * `session.id: assign`), every placeholder filling whole argv elements ({@link renderLaunchArgv}),
19
+ * no shell, the agent inheriting stdin, stdout and stderr, its working directory the project root,
20
+ * the environment passed through unchanged (`adr-012` point 1). This is REQ-PERF-01's "agent ready".
21
+ * 15. The wait. From the spawn until the record is committed `SIGINT` and `SIGQUIT` are ignored (the
22
+ * terminal delivers them to the agent itself, in the same foreground process group) and `SIGTERM`
23
+ * and `SIGHUP` are forwarded to the agent while it runs, so a run ended by a signal is still recorded
24
+ * as `signal:<NAME>`.
25
+ * 16. The post-run lookups (§2.6): `version_args`, `session.lookup_args`, `usage.lookup_args`, each run as
26
+ * `command` + argv with a time limit ({@link LOOKUP_TIMEOUT_MS}); one argv declared twice runs once.
27
+ * A lookup that fails, times out or prints no JSON, and a value of the wrong type, yield
28
+ * `not-reported` and a `warning:` line; the lookup never fails the run.
29
+ * 17. The record (§4.2), appended and committed by `recordRun` (task-206): `agent: record <run-id>`.
30
+ * 18. The outcome: success only when the agent exited `0` and the record was committed.
31
+ *
32
+ * **Determinism.** The argv, the session id and every record field but `duration_ms` are pure functions
33
+ * of committed state and the run's inputs; the temporary-file paths and the Node executable are host
34
+ * values that never reach the context (`spec-016` Consequences). `duration_ms` is wall-clock by design:
35
+ * a record of what happened, never part of a context (`dl-114` Q2).
36
+ */
37
+ const node_child_process_1 = require("node:child_process");
38
+ const node_crypto_1 = require("node:crypto");
39
+ const node_path_1 = require("node:path");
40
+ const node_perf_hooks_1 = require("node:perf_hooks");
41
+ const storage_1 = require("../storage");
42
+ const warning_1 = require("../validation/warning");
43
+ const types_1 = require("../core/types");
44
+ const run_log_1 = require("./run-log");
45
+ /**
46
+ * How much one post-run lookup may print before it is stopped (§2.6): `execFile`'s `maxBuffer`, which
47
+ * bounds stdout and stderr each, so a lookup with valid stdout and over 1 MiB on stderr loses its values.
48
+ */
49
+ const LOOKUP_MAX_BYTES = 1024 * 1024;
50
+ /** How long one post-run lookup may run (§2.6, §3.3 step 16). */
51
+ exports.LOOKUP_TIMEOUT_MS = 10000;
52
+ /**
53
+ * The namespace of the assigned session ids (§2.6): the version 5 UUID of the name
54
+ * `wingfoil:spec-016:session` in RFC 4122's URL namespace, fixed here so no clock or random source is
55
+ * involved.
56
+ */
57
+ exports.SESSION_ID_NAMESPACE = 'a432dcd6-576d-5991-9503-2b23aa4139db';
58
+ /** RFC 4122 §4.3 name-based UUID, version 5 (SHA-1) of `name` in `namespace`. */
59
+ function uuidV5(namespace, name) {
60
+ const hash = (0, node_crypto_1.createHash)('sha1')
61
+ .update(Buffer.concat([Buffer.from(namespace.replace(/-/g, ''), 'hex'), Buffer.from(name, 'utf-8')]))
62
+ .digest();
63
+ const bytes = Buffer.from(hash.subarray(0, 16));
64
+ bytes[6] = (bytes[6] & 0x0f) | 0x50;
65
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
66
+ const hex = bytes.toString('hex');
67
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
68
+ }
69
+ /**
70
+ * The session id WingFoil assigns (§2.6 `assign`): the v5 UUID of `<absolute repository root>\n<run id>`
71
+ * in {@link SESSION_ID_NAMESPACE}. Unique per clone and run, derived, never random. Per clone by design
72
+ * (it hashes the root): the run id is the identifier across clones (`dl-135` Q3 (a)).
73
+ */
74
+ function assignedSessionId(root, runId) {
75
+ return uuidV5(exports.SESSION_ID_NAMESPACE, `${root}\n${runId}`);
76
+ }
77
+ /** One argv template rendered: each `{name}` element replaced by its value, `{mcp_args}` by several. */
78
+ function renderArgv(template, values) {
79
+ const single = {
80
+ '{bootstrap}': values.bootstrap,
81
+ '{bootstrap_file}': values.files.bootstrap_file,
82
+ '{mcp_config_file}': values.files.mcp_config_file,
83
+ '{mcp_config}': values.mcpConfig,
84
+ '{mcp_command}': values.mcpServer.command,
85
+ '{session_id}': values.sessionId,
86
+ };
87
+ return template.flatMap((element) => {
88
+ if (element === '{mcp_args}')
89
+ return [...values.mcpServer.args];
90
+ // The manifest validator admits a placeholder only as a whole element, and only where it has a
91
+ // value (§2.3), so every token here is one of these.
92
+ return [single[element] ?? element];
93
+ });
94
+ }
95
+ /**
96
+ * The launch argv (§3.3 step 14): `launch.interactive.args` rendered, then `session.assign_args`
97
+ * rendered when the session id is assigned. The `command` is not part of it.
98
+ */
99
+ function renderLaunchArgv(manifest, values) {
100
+ const assign = manifest.session.id === 'assign' ? (manifest.session.assign_args ?? []) : [];
101
+ return [...renderArgv(manifest.launch.interactive.args, values), ...renderArgv(assign, values)];
102
+ }
103
+ /**
104
+ * The value at the dotted `path` of a JSON value (§2.2 `session.field`, `usage.fields`): each segment a
105
+ * key of a plain object; `undefined` when a segment is absent or the value on the way is not an object.
106
+ */
107
+ function readJsonPath(document, path) {
108
+ let value = document;
109
+ for (const key of path.split('.')) {
110
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
111
+ return undefined;
112
+ if (!Object.prototype.hasOwnProperty.call(value, key))
113
+ return undefined;
114
+ value = value[key];
115
+ }
116
+ return value;
117
+ }
118
+ /** The agent's `command`, as spawned: a name stays a name (the OS searches `PATH`), a path is resolved against the root. */
119
+ function commandToSpawn(root, command) {
120
+ return (0, node_path_1.isAbsolute)(command) || command.includes('/') || command.includes('\\') ? (0, node_path_1.resolve)(root, command) : command;
121
+ }
122
+ /** The signals `agent execute` takes over while the agent runs (§3.3 step 15). */
123
+ const IGNORED_SIGNALS = process.platform === 'win32' ? ['SIGINT'] : ['SIGINT', 'SIGQUIT'];
124
+ const FORWARDED_SIGNALS = process.platform === 'win32' ? ['SIGTERM'] : ['SIGTERM', 'SIGHUP'];
125
+ /**
126
+ * Install §3.3 step 15's signal handling **before the spawn** (review fix 1: a signal between the
127
+ * pre-launch cleanup's release and the spawn must neither kill `agent execute` nor orphan the agent):
128
+ * `SIGINT`/`SIGQUIT` ignored, `SIGTERM`/`SIGHUP` forwarded to the agent while it runs. One that arrives
129
+ * before the agent exists is remembered and sent as soon as it is attached; once the agent has exited
130
+ * they are ignored, until the record is committed.
131
+ */
132
+ function takeOverSignals() {
133
+ let child;
134
+ let pending;
135
+ const forward = (signal) => {
136
+ if (child === undefined)
137
+ pending = signal;
138
+ else if (child.exitCode === null && child.signalCode === null)
139
+ child.kill(signal);
140
+ };
141
+ const installed = [
142
+ ...IGNORED_SIGNALS.map((signal) => [signal, () => undefined]),
143
+ ...FORWARDED_SIGNALS.map((signal) => [signal, () => forward(signal)]),
144
+ ];
145
+ for (const [signal, listener] of installed)
146
+ process.on(signal, listener);
147
+ return {
148
+ attach(spawned) {
149
+ child = spawned;
150
+ if (pending !== undefined)
151
+ forward(pending);
152
+ },
153
+ restore() {
154
+ for (const [signal, listener] of installed)
155
+ process.removeListener(signal, listener);
156
+ },
157
+ };
158
+ }
159
+ /** Spawn the agent and wait for it: its exit status and the wall-clock duration, or why it could not start. */
160
+ function runAgent(spawnAgent, command, args, root, onSpawn) {
161
+ return new Promise((settle) => {
162
+ let child;
163
+ const start = node_perf_hooks_1.performance.now();
164
+ try {
165
+ child = spawnAgent(command, args, { cwd: root, stdio: 'inherit', env: process.env });
166
+ }
167
+ catch (error) {
168
+ settle({ ok: false, reason: error instanceof Error ? error.message : String(error) });
169
+ return;
170
+ }
171
+ onSpawn(child);
172
+ let spawned = false;
173
+ child.once('spawn', () => {
174
+ spawned = true;
175
+ });
176
+ child.once('error', (error) => {
177
+ if (!spawned)
178
+ settle({ ok: false, reason: error.message });
179
+ });
180
+ child.once('exit', (code, signal) => {
181
+ const durationMs = Math.max(0, Math.round(node_perf_hooks_1.performance.now() - start));
182
+ settle({ ok: true, exitStatus: signal !== null ? `signal:${signal}` : (code ?? 0), durationMs });
183
+ });
184
+ });
185
+ }
186
+ /** Run `command` + `args` with the time limit, no shell, in the root; stdout captured. */
187
+ function runLookup(command, args, root, timeoutMs) {
188
+ return new Promise((settle) => {
189
+ (0, node_child_process_1.execFile)(command, [...args], { cwd: root, env: process.env, timeout: timeoutMs, killSignal: 'SIGKILL', maxBuffer: LOOKUP_MAX_BYTES, encoding: 'utf-8' }, (error, stdout) => {
190
+ if (error === null)
191
+ return settle({ ok: true, stdout });
192
+ const failed = error;
193
+ if (failed.killed === true)
194
+ return settle({ ok: false, reason: `timed out after ${timeoutMs} ms` });
195
+ if (failed.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER')
196
+ return settle({ ok: false, reason: `printed more than ${LOOKUP_MAX_BYTES / 1024 / 1024} MiB on stdout or stderr` });
197
+ if (typeof failed.code === 'number')
198
+ return settle({ ok: false, reason: `exited ${failed.code}` });
199
+ if (failed.signal)
200
+ return settle({ ok: false, reason: `ended by ${failed.signal}` });
201
+ return settle({ ok: false, reason: failed.code !== undefined ? `could not start: ${failed.code}` : failed.message });
202
+ });
203
+ });
204
+ }
205
+ /** The first JSON value a lookup printed, or why there is none. */
206
+ function parseLookup(outcome) {
207
+ if (!outcome.ok)
208
+ return outcome;
209
+ try {
210
+ return { ok: true, document: JSON.parse(outcome.stdout) };
211
+ }
212
+ catch {
213
+ return { ok: false, reason: 'printed no JSON' };
214
+ }
215
+ }
216
+ /**
217
+ * Every count unreported. A function, not a module constant: `./run-log` can still be loading when this
218
+ * module is first evaluated (`src/core` ↔ `src/agent` import cycle), so `NOT_REPORTED` is read at call time.
219
+ */
220
+ const noTokens = () => ({ input: run_log_1.NOT_REPORTED, output: run_log_1.NOT_REPORTED, cache_read: run_log_1.NOT_REPORTED, cache_write: run_log_1.NOT_REPORTED });
221
+ /**
222
+ * §3.3 step 16: `agent_version`, the session id, the model and the tokens, from the adapter's
223
+ * declarations (§2.2, §2.6). Every lookup runs after the agent exited; an argv declared for both the
224
+ * session and the usage runs once. A failure is `not-reported` and one warning; never a refusal.
225
+ */
226
+ async function postRunFacts(input) {
227
+ const { manifest, adapterName } = input;
228
+ const command = commandToSpawn(input.root, manifest.command);
229
+ const warn = (text) => (0, warning_1.reportWarning)(`adapter '${adapterName}': ${text}`);
230
+ const runs = new Map();
231
+ const lookup = (argv) => {
232
+ const rendered = renderArgv(argv, input.values);
233
+ const key = JSON.stringify(rendered);
234
+ if (!runs.has(key))
235
+ runs.set(key, runLookup(command, rendered, input.root, input.timeoutMs));
236
+ return runs.get(key);
237
+ };
238
+ let agentVersion = run_log_1.NOT_REPORTED;
239
+ if (manifest.version_args !== undefined) {
240
+ const outcome = await lookup(manifest.version_args);
241
+ const first = outcome.ok ? outcome.stdout.split('\n').map((line) => line.trim()).find((line) => line !== '') : undefined;
242
+ if (first !== undefined)
243
+ agentVersion = first;
244
+ else
245
+ warn(`version_args ${outcome.ok ? 'printed nothing' : `failed (${outcome.reason})`}: agent_version recorded as not-reported`);
246
+ }
247
+ let session = input.assigned ?? run_log_1.NOT_REPORTED;
248
+ if (manifest.session.id === 'lookup' && manifest.session.lookup_args !== undefined && manifest.session.field !== undefined) {
249
+ const parsed = parseLookup(await lookup(manifest.session.lookup_args));
250
+ if (!parsed.ok)
251
+ warn(`the session lookup failed (${parsed.reason}): session recorded as not-reported`);
252
+ else {
253
+ const value = readJsonPath(parsed.document, manifest.session.field);
254
+ if (typeof value === 'string' && value !== '')
255
+ session = value;
256
+ else
257
+ warn("the session lookup's session id is not a non-empty string: recorded as not-reported");
258
+ }
259
+ }
260
+ let model = run_log_1.NOT_REPORTED;
261
+ let tokens = noTokens();
262
+ if (manifest.usage.from === 'lookup' && manifest.usage.lookup_args !== undefined) {
263
+ const parsed = parseLookup(await lookup(manifest.usage.lookup_args));
264
+ if (!parsed.ok)
265
+ warn(`the usage lookup failed (${parsed.reason}): model and tokens recorded as not-reported`);
266
+ else {
267
+ const fields = manifest.usage.fields ?? {};
268
+ if (fields.model !== undefined) {
269
+ const value = readJsonPath(parsed.document, fields.model);
270
+ if (typeof value === 'string' && value !== '')
271
+ model = value;
272
+ else if (value !== undefined)
273
+ warn("the usage lookup's model is not a non-empty string: recorded as not-reported");
274
+ }
275
+ const count = (key) => {
276
+ const path = fields[key];
277
+ if (path === undefined)
278
+ return run_log_1.NOT_REPORTED;
279
+ const value = readJsonPath(parsed.document, path);
280
+ if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
281
+ return value;
282
+ if (value !== undefined)
283
+ warn(`the usage lookup's ${key} is not a non-negative integer: recorded as not-reported`);
284
+ return run_log_1.NOT_REPORTED;
285
+ };
286
+ tokens = { input: count('input'), output: count('output'), cache_read: count('cache_read'), cache_write: count('cache_write') };
287
+ }
288
+ }
289
+ return { agent_version: agentVersion, model, session, tokens };
290
+ }
291
+ /** §3.4's post-run summary line, without a prefix. */
292
+ function runSummaryLine(record, sha) {
293
+ return `run ${record.id}: agent exited ${String(record.exit_status)} after ${(record.duration_ms / 1000).toFixed(1)} s (recorded in ${sha.slice(0, 7)})`;
294
+ }
295
+ /** The step-13 banner (§3.3), without a prefix. */
296
+ function launchBanner(input) {
297
+ return `run ${input.runId}: launching ${input.agent.name} (${input.adapter.kind}/${input.adapter.name}) as ${input.role} on ${input.element}`;
298
+ }
299
+ /**
300
+ * §3.3 steps 13–18 for a launch every pre-launch check has passed. `releaseSignals` is called right
301
+ * before the spawn, after the launch has installed its own listeners: it hands the process's signals
302
+ * over from the pre-launch cleanup (`withRunFiles`) to the launch (§3.3 step 15) with no gap between.
303
+ *
304
+ * @returns The recorded run (the agent exited `0` and the record was committed); otherwise `IO`
305
+ * `agent command '<command>' could not be started …` (no run, no record), `IO` `agent exited
306
+ * <exit_status>; run <run-id> recorded` with `details: {run_id, exit_status}` and the summary as a
307
+ * detail line, or `recordRun`'s refusal, the record in its `details` (the run is never lost).
308
+ */
309
+ async function launchAgent(root, input, host, releaseSignals) {
310
+ const { manifest } = input.adapter;
311
+ const assigned = manifest.session.id === 'assign' ? assignedSessionId(root, input.runId) : undefined;
312
+ const values = {
313
+ bootstrap: input.bootstrap,
314
+ files: input.files,
315
+ mcpServer: input.mcpServer,
316
+ mcpConfig: input.mcpConfig,
317
+ sessionId: assigned ?? '',
318
+ };
319
+ const argv = renderLaunchArgv(manifest, values);
320
+ // Step 13 — the banner; step 14 — the spawn; step 15 — the wait, with the signals taken over.
321
+ (0, warning_1.reportNotice)(launchBanner(input));
322
+ // The launch's listeners go in before the pre-launch cleanup's come out: no signal finds neither.
323
+ const signals = takeOverSignals();
324
+ releaseSignals();
325
+ try {
326
+ const ran = await runAgent(host.spawn ?? node_child_process_1.spawn, commandToSpawn(root, manifest.command), argv, root, (child) => signals.attach(child));
327
+ if (!ran.ok) {
328
+ return (0, types_1.coreErr)({ code: 'IO', message: `agent command '${manifest.command}' could not be started (adapter '${input.adapter.name}'): ${ran.reason}` });
329
+ }
330
+ // Step 16 — the post-run lookups.
331
+ const facts = await postRunFacts({
332
+ root,
333
+ adapterName: input.adapter.name,
334
+ manifest,
335
+ assigned,
336
+ values,
337
+ timeoutMs: host.lookupTimeoutMs ?? exports.LOOKUP_TIMEOUT_MS,
338
+ });
339
+ const elementId = input.element.slice(input.element.indexOf(':') + 1);
340
+ const record = {
341
+ id: input.runId,
342
+ element: input.element,
343
+ workflow: input.workflow,
344
+ phase: input.phase,
345
+ role: input.role,
346
+ mode: input.mode,
347
+ agent: input.agent.name,
348
+ adapter: `${input.adapter.kind}/${input.adapter.name}`,
349
+ agent_version: facts.agent_version,
350
+ model: facts.model,
351
+ session: facts.session,
352
+ tokens: facts.tokens,
353
+ wingfoil: (0, storage_1.readBuildStamp)(),
354
+ state_ref: input.stateRef,
355
+ duration_ms: ran.durationMs,
356
+ exit_status: ran.exitStatus,
357
+ result: 'n/a',
358
+ notes: input.templatePath === undefined
359
+ ? 'none'
360
+ : (0, run_log_1.deriveNotesField)(root, { elementId, elementPath: input.elementPath, templatePath: input.templatePath, stateRef: input.stateRef }),
361
+ };
362
+ // Step 17 — append and commit.
363
+ const recorded = (0, run_log_1.recordRun)(root, input.logPath, record);
364
+ if (!recorded.ok)
365
+ return recorded;
366
+ // Step 18 — the outcome.
367
+ if (record.exit_status !== 0) {
368
+ return (0, types_1.coreErr)({
369
+ code: 'IO',
370
+ message: `agent exited ${String(record.exit_status)}; run ${record.id} recorded`,
371
+ details: { run_id: record.id, exit_status: record.exit_status, issues: [{ detail: runSummaryLine(record, recorded.value.sha) }] },
372
+ });
373
+ }
374
+ return (0, types_1.coreOk)({ run: record, sha: recorded.value.sha });
375
+ }
376
+ finally {
377
+ signals.restore();
378
+ }
379
+ }
380
+ //# sourceMappingURL=launch.js.map