@namzu/sdk 71.1.0 → 73.0.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 (380) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +1 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  6. package/dist/agents/examples/SupervisorAgent.js +5 -0
  7. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  8. package/dist/authorization/protected-paths.d.ts.map +1 -1
  9. package/dist/authorization/protected-paths.js +4 -0
  10. package/dist/authorization/protected-paths.js.map +1 -1
  11. package/dist/compaction/index.d.ts +1 -1
  12. package/dist/compaction/index.d.ts.map +1 -1
  13. package/dist/compaction/index.js +1 -1
  14. package/dist/compaction/index.js.map +1 -1
  15. package/dist/compaction/manual.d.ts +24 -1
  16. package/dist/compaction/manual.d.ts.map +1 -1
  17. package/dist/compaction/manual.js +80 -21
  18. package/dist/compaction/manual.js.map +1 -1
  19. package/dist/compaction/model-summary.d.ts +24 -6
  20. package/dist/compaction/model-summary.d.ts.map +1 -1
  21. package/dist/compaction/model-summary.js +108 -23
  22. package/dist/compaction/model-summary.js.map +1 -1
  23. package/dist/compaction/precompute.d.ts +179 -0
  24. package/dist/compaction/precompute.d.ts.map +1 -0
  25. package/dist/compaction/precompute.js +274 -0
  26. package/dist/compaction/precompute.js.map +1 -0
  27. package/dist/compaction/restore.d.ts +23 -0
  28. package/dist/compaction/restore.d.ts.map +1 -1
  29. package/dist/compaction/restore.js +59 -1
  30. package/dist/compaction/restore.js.map +1 -1
  31. package/dist/compaction/summary.d.ts +37 -2
  32. package/dist/compaction/summary.d.ts.map +1 -1
  33. package/dist/compaction/summary.js +46 -6
  34. package/dist/compaction/summary.js.map +1 -1
  35. package/dist/config/runtime.d.ts +4 -0
  36. package/dist/config/runtime.d.ts.map +1 -1
  37. package/dist/config/runtime.js +20 -3
  38. package/dist/config/runtime.js.map +1 -1
  39. package/dist/connector/index.d.ts +2 -2
  40. package/dist/connector/index.d.ts.map +1 -1
  41. package/dist/connector/index.js +1 -1
  42. package/dist/connector/index.js.map +1 -1
  43. package/dist/connector/mcp/client.d.ts +26 -6
  44. package/dist/connector/mcp/client.d.ts.map +1 -1
  45. package/dist/connector/mcp/client.js +49 -7
  46. package/dist/connector/mcp/client.js.map +1 -1
  47. package/dist/connector/mcp/index.d.ts +2 -0
  48. package/dist/connector/mcp/index.d.ts.map +1 -1
  49. package/dist/connector/mcp/index.js +1 -0
  50. package/dist/connector/mcp/index.js.map +1 -1
  51. package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
  52. package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
  53. package/dist/connector/mcp/sandbox-stdio.js +178 -0
  54. package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
  55. package/dist/connector/mcp/stdio-program.d.ts +34 -0
  56. package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
  57. package/dist/connector/mcp/stdio-program.js +47 -0
  58. package/dist/connector/mcp/stdio-program.js.map +1 -0
  59. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  60. package/dist/connector/mcp/stdio.js +5 -2
  61. package/dist/connector/mcp/stdio.js.map +1 -1
  62. package/dist/connector/web/guarded-fetch.d.ts +51 -2
  63. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  64. package/dist/connector/web/guarded-fetch.js +140 -19
  65. package/dist/connector/web/guarded-fetch.js.map +1 -1
  66. package/dist/connector/web/index.d.ts +2 -2
  67. package/dist/connector/web/index.d.ts.map +1 -1
  68. package/dist/connector/web/index.js +1 -1
  69. package/dist/connector/web/index.js.map +1 -1
  70. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  71. package/dist/manager/agent/lifecycle.js +9 -1
  72. package/dist/manager/agent/lifecycle.js.map +1 -1
  73. package/dist/manager/session/turn-recorder.d.ts +26 -0
  74. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  75. package/dist/manager/session/turn-recorder.js +72 -5
  76. package/dist/manager/session/turn-recorder.js.map +1 -1
  77. package/dist/peers/protocol.d.ts +9 -0
  78. package/dist/peers/protocol.d.ts.map +1 -1
  79. package/dist/peers/protocol.js +4 -0
  80. package/dist/peers/protocol.js.map +1 -1
  81. package/dist/peers/record.d.ts +6 -0
  82. package/dist/peers/record.d.ts.map +1 -1
  83. package/dist/peers/record.js +4 -0
  84. package/dist/peers/record.js.map +1 -1
  85. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  86. package/dist/plugin/hook-module/capabilities.js +24 -13
  87. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  88. package/dist/plugin/hook-module/host.d.ts +31 -0
  89. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  90. package/dist/plugin/hook-module/host.js +56 -13
  91. package/dist/plugin/hook-module/host.js.map +1 -1
  92. package/dist/plugin/hook-module/index.d.ts +3 -2
  93. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  94. package/dist/plugin/hook-module/index.js +2 -1
  95. package/dist/plugin/hook-module/index.js.map +1 -1
  96. package/dist/plugin/index.d.ts +3 -2
  97. package/dist/plugin/index.d.ts.map +1 -1
  98. package/dist/plugin/index.js +2 -1
  99. package/dist/plugin/index.js.map +1 -1
  100. package/dist/plugin/shell-hook-execute.d.ts +55 -0
  101. package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
  102. package/dist/plugin/shell-hook-execute.js +73 -0
  103. package/dist/plugin/shell-hook-execute.js.map +1 -0
  104. package/dist/plugin/shell-hook-restrict.d.ts +31 -0
  105. package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
  106. package/dist/plugin/shell-hook-restrict.js +69 -0
  107. package/dist/plugin/shell-hook-restrict.js.map +1 -0
  108. package/dist/plugin/shell-hook.d.ts +59 -2
  109. package/dist/plugin/shell-hook.d.ts.map +1 -1
  110. package/dist/plugin/shell-hook.js +79 -12
  111. package/dist/plugin/shell-hook.js.map +1 -1
  112. package/dist/public-runtime.d.ts +11 -7
  113. package/dist/public-runtime.d.ts.map +1 -1
  114. package/dist/public-runtime.js +9 -6
  115. package/dist/public-runtime.js.map +1 -1
  116. package/dist/public-tools.d.ts +1 -1
  117. package/dist/public-tools.d.ts.map +1 -1
  118. package/dist/public-tools.js +1 -1
  119. package/dist/public-tools.js.map +1 -1
  120. package/dist/public-types.d.ts +5 -2
  121. package/dist/public-types.d.ts.map +1 -1
  122. package/dist/registry/command/kernel-commands.d.ts +7 -1
  123. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  124. package/dist/registry/command/kernel-commands.js +40 -2
  125. package/dist/registry/command/kernel-commands.js.map +1 -1
  126. package/dist/registry/tool/execute.d.ts +8 -0
  127. package/dist/registry/tool/execute.d.ts.map +1 -1
  128. package/dist/registry/tool/execute.js +12 -0
  129. package/dist/registry/tool/execute.js.map +1 -1
  130. package/dist/runtime/jobs/websocket-source.d.ts +2 -22
  131. package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
  132. package/dist/runtime/jobs/websocket-source.js +2 -33
  133. package/dist/runtime/jobs/websocket-source.js.map +1 -1
  134. package/dist/runtime/query/budget-nudge.d.ts +27 -0
  135. package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
  136. package/dist/runtime/query/budget-nudge.js +66 -0
  137. package/dist/runtime/query/budget-nudge.js.map +1 -0
  138. package/dist/runtime/query/compact-session.d.ts +9 -0
  139. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  140. package/dist/runtime/query/compact-session.js +158 -76
  141. package/dist/runtime/query/compact-session.js.map +1 -1
  142. package/dist/runtime/query/events.d.ts +7 -0
  143. package/dist/runtime/query/events.d.ts.map +1 -1
  144. package/dist/runtime/query/events.js +29 -11
  145. package/dist/runtime/query/events.js.map +1 -1
  146. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  147. package/dist/runtime/query/executor/tool-call-admission.js +51 -10
  148. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  149. package/dist/runtime/query/guard.d.ts +8 -0
  150. package/dist/runtime/query/guard.d.ts.map +1 -1
  151. package/dist/runtime/query/guard.js +20 -0
  152. package/dist/runtime/query/guard.js.map +1 -1
  153. package/dist/runtime/query/index.d.ts +6 -0
  154. package/dist/runtime/query/index.d.ts.map +1 -1
  155. package/dist/runtime/query/index.js +3 -0
  156. package/dist/runtime/query/index.js.map +1 -1
  157. package/dist/runtime/query/iteration/index.d.ts +2 -0
  158. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  159. package/dist/runtime/query/iteration/index.js +27 -1
  160. package/dist/runtime/query/iteration/index.js.map +1 -1
  161. package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
  162. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  163. package/dist/runtime/query/iteration/phases/compaction.js +164 -43
  164. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  165. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  166. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  167. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  168. package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
  169. package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
  170. package/dist/runtime/query/iteration/phases/precompute.js +240 -0
  171. package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
  172. package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
  173. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  174. package/dist/runtime/query/turn/outcome-ledger.js +28 -0
  175. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  176. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  177. package/dist/scheduler/completion-inbox.js +15 -0
  178. package/dist/scheduler/completion-inbox.js.map +1 -1
  179. package/dist/store/goal/gates.d.ts +53 -0
  180. package/dist/store/goal/gates.d.ts.map +1 -0
  181. package/dist/store/goal/gates.js +664 -0
  182. package/dist/store/goal/gates.js.map +1 -0
  183. package/dist/store/goal/index.d.ts +16 -1
  184. package/dist/store/goal/index.d.ts.map +1 -1
  185. package/dist/store/goal/index.js +74 -0
  186. package/dist/store/goal/index.js.map +1 -1
  187. package/dist/store/session-index/index.d.ts +13 -0
  188. package/dist/store/session-index/index.d.ts.map +1 -1
  189. package/dist/store/session-index/index.js +1 -0
  190. package/dist/store/session-index/index.js.map +1 -1
  191. package/dist/store/session-index/rebuild.d.ts +12 -0
  192. package/dist/store/session-index/rebuild.d.ts.map +1 -1
  193. package/dist/store/session-index/rebuild.js +20 -4
  194. package/dist/store/session-index/rebuild.js.map +1 -1
  195. package/dist/store/session-index/sqlite.d.ts +20 -0
  196. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  197. package/dist/store/session-index/sqlite.js +50 -12
  198. package/dist/store/session-index/sqlite.js.map +1 -1
  199. package/dist/tools/admit-facts.d.ts.map +1 -1
  200. package/dist/tools/admit-facts.js +59 -0
  201. package/dist/tools/admit-facts.js.map +1 -1
  202. package/dist/tools/builtins/bash.js +1 -1
  203. package/dist/tools/builtins/bash.js.map +1 -1
  204. package/dist/tools/builtins/browser.d.ts.map +1 -1
  205. package/dist/tools/builtins/browser.js +2 -0
  206. package/dist/tools/builtins/browser.js.map +1 -1
  207. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  208. package/dist/tools/builtins/monitor.js +1 -0
  209. package/dist/tools/builtins/monitor.js.map +1 -1
  210. package/dist/tools/builtins/search-tools.js +2 -2
  211. package/dist/tools/builtins/search-tools.js.map +1 -1
  212. package/dist/tools/builtins/sleep-guard.js +1 -1
  213. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  214. package/dist/tools/builtins/wait-for-job.js +1 -1
  215. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  216. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  217. package/dist/tools/coordinator/ask-user-question.js +92 -3
  218. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  219. package/dist/tools/coordinator/index.d.ts.map +1 -1
  220. package/dist/tools/coordinator/index.js +3 -0
  221. package/dist/tools/coordinator/index.js.map +1 -1
  222. package/dist/tools/defineTool.d.ts +2 -0
  223. package/dist/tools/defineTool.d.ts.map +1 -1
  224. package/dist/tools/defineTool.js +3 -0
  225. package/dist/tools/defineTool.js.map +1 -1
  226. package/dist/tools/goal/confirmation.d.ts +40 -2
  227. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  228. package/dist/tools/goal/confirmation.js +117 -0
  229. package/dist/tools/goal/confirmation.js.map +1 -1
  230. package/dist/tools/goal/index.d.ts.map +1 -1
  231. package/dist/tools/goal/index.js +14 -2
  232. package/dist/tools/goal/index.js.map +1 -1
  233. package/dist/tools/memory/save.d.ts.map +1 -1
  234. package/dist/tools/memory/save.js +1 -0
  235. package/dist/tools/memory/save.js.map +1 -1
  236. package/dist/tools/schedules/index.d.ts +1 -0
  237. package/dist/tools/schedules/index.d.ts.map +1 -1
  238. package/dist/tools/schedules/index.js +1 -0
  239. package/dist/tools/schedules/index.js.map +1 -1
  240. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  241. package/dist/tools/schedules/loop-tool.js +1 -0
  242. package/dist/tools/schedules/loop-tool.js.map +1 -1
  243. package/dist/tools/schedules/present.d.ts.map +1 -1
  244. package/dist/tools/schedules/present.js +2 -0
  245. package/dist/tools/schedules/present.js.map +1 -1
  246. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  247. package/dist/tools/schedules/schedule-tool.js +79 -9
  248. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  249. package/dist/tools/schedules/self-tool.d.ts +16 -0
  250. package/dist/tools/schedules/self-tool.d.ts.map +1 -0
  251. package/dist/tools/schedules/self-tool.js +140 -0
  252. package/dist/tools/schedules/self-tool.js.map +1 -0
  253. package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
  254. package/dist/tools/schedules/timer-tools.js +1 -0
  255. package/dist/tools/schedules/timer-tools.js.map +1 -1
  256. package/dist/tools/schedules/types.d.ts +63 -0
  257. package/dist/tools/schedules/types.d.ts.map +1 -1
  258. package/dist/toolsets/manager.d.ts +10 -0
  259. package/dist/toolsets/manager.d.ts.map +1 -1
  260. package/dist/toolsets/manager.js +56 -7
  261. package/dist/toolsets/manager.js.map +1 -1
  262. package/dist/turn/memory-promoter.d.ts.map +1 -1
  263. package/dist/turn/memory-promoter.js +20 -4
  264. package/dist/turn/memory-promoter.js.map +1 -1
  265. package/dist/types/agent/base.d.ts +6 -0
  266. package/dist/types/agent/base.d.ts.map +1 -1
  267. package/dist/types/agent/supervisor.d.ts +10 -0
  268. package/dist/types/agent/supervisor.d.ts.map +1 -1
  269. package/dist/types/agent/task.d.ts +11 -0
  270. package/dist/types/agent/task.d.ts.map +1 -1
  271. package/dist/types/agent/task.js.map +1 -1
  272. package/dist/types/goal/index.d.ts +66 -0
  273. package/dist/types/goal/index.d.ts.map +1 -1
  274. package/dist/types/hitl/index.d.ts +8 -0
  275. package/dist/types/hitl/index.d.ts.map +1 -1
  276. package/dist/types/hitl/index.js.map +1 -1
  277. package/dist/types/message/index.d.ts +7 -0
  278. package/dist/types/message/index.d.ts.map +1 -1
  279. package/dist/types/message/index.js.map +1 -1
  280. package/dist/types/session/events.d.ts +7 -0
  281. package/dist/types/session/events.d.ts.map +1 -1
  282. package/dist/types/session/events.js.map +1 -1
  283. package/dist/types/session/outcome.d.ts +12 -0
  284. package/dist/types/session/outcome.d.ts.map +1 -1
  285. package/dist/types/session/outcome.js.map +1 -1
  286. package/dist/types/session/records.d.ts +79 -1
  287. package/dist/types/session/records.d.ts.map +1 -1
  288. package/dist/types/session/records.js +24 -0
  289. package/dist/types/session/records.js.map +1 -1
  290. package/dist/types/tool/index.d.ts +7 -0
  291. package/dist/types/tool/index.d.ts.map +1 -1
  292. package/dist/types/tool/index.js.map +1 -1
  293. package/dist/types/tool/presentation.d.ts +21 -0
  294. package/dist/types/tool/presentation.d.ts.map +1 -1
  295. package/package.json +6 -6
  296. package/src/agents/QueryAgent.ts +1 -0
  297. package/src/agents/examples/SupervisorAgent.ts +5 -0
  298. package/src/authorization/protected-paths.ts +4 -0
  299. package/src/compaction/index.ts +1 -0
  300. package/src/compaction/manual.ts +130 -23
  301. package/src/compaction/model-summary.ts +118 -23
  302. package/src/compaction/precompute.ts +390 -0
  303. package/src/compaction/restore.ts +74 -1
  304. package/src/compaction/summary.ts +69 -3
  305. package/src/config/runtime.ts +20 -3
  306. package/src/connector/index.ts +3 -0
  307. package/src/connector/mcp/client.ts +49 -7
  308. package/src/connector/mcp/index.ts +5 -0
  309. package/src/connector/mcp/sandbox-stdio.ts +214 -0
  310. package/src/connector/mcp/stdio-program.ts +68 -0
  311. package/src/connector/mcp/stdio.ts +5 -2
  312. package/src/connector/web/guarded-fetch.ts +197 -30
  313. package/src/connector/web/index.ts +4 -1
  314. package/src/manager/agent/lifecycle.ts +10 -1
  315. package/src/manager/session/turn-recorder.ts +92 -5
  316. package/src/peers/protocol.ts +4 -0
  317. package/src/peers/record.ts +4 -0
  318. package/src/plugin/hook-module/capabilities.ts +36 -14
  319. package/src/plugin/hook-module/host.ts +86 -13
  320. package/src/plugin/hook-module/index.ts +3 -0
  321. package/src/plugin/index.ts +3 -0
  322. package/src/plugin/shell-hook-execute.ts +126 -0
  323. package/src/plugin/shell-hook-restrict.ts +66 -0
  324. package/src/plugin/shell-hook.ts +138 -10
  325. package/src/public-runtime.ts +41 -0
  326. package/src/public-tools.ts +2 -0
  327. package/src/public-types.ts +21 -0
  328. package/src/registry/command/kernel-commands.ts +62 -3
  329. package/src/registry/tool/execute.ts +14 -0
  330. package/src/runtime/jobs/websocket-source.ts +2 -46
  331. package/src/runtime/query/budget-nudge.ts +92 -0
  332. package/src/runtime/query/compact-session.ts +195 -70
  333. package/src/runtime/query/events.ts +29 -11
  334. package/src/runtime/query/executor/tool-call-admission.ts +62 -17
  335. package/src/runtime/query/guard.ts +22 -0
  336. package/src/runtime/query/index.ts +10 -0
  337. package/src/runtime/query/iteration/index.ts +26 -1
  338. package/src/runtime/query/iteration/phases/compaction.ts +173 -43
  339. package/src/runtime/query/iteration/phases/context.ts +6 -0
  340. package/src/runtime/query/iteration/phases/precompute.ts +277 -0
  341. package/src/runtime/query/turn/outcome-ledger.ts +34 -0
  342. package/src/scheduler/completion-inbox.ts +14 -0
  343. package/src/store/goal/gates.ts +738 -0
  344. package/src/store/goal/index.ts +109 -0
  345. package/src/store/session-index/index.ts +14 -0
  346. package/src/store/session-index/rebuild.ts +22 -4
  347. package/src/store/session-index/sqlite.ts +63 -14
  348. package/src/tools/admit-facts.ts +64 -0
  349. package/src/tools/builtins/bash.ts +1 -1
  350. package/src/tools/builtins/browser.ts +4 -0
  351. package/src/tools/builtins/monitor.ts +2 -0
  352. package/src/tools/builtins/search-tools.ts +2 -2
  353. package/src/tools/builtins/sleep-guard.ts +1 -1
  354. package/src/tools/builtins/wait-for-job.ts +1 -1
  355. package/src/tools/coordinator/ask-user-question.ts +124 -13
  356. package/src/tools/coordinator/index.ts +3 -0
  357. package/src/tools/defineTool.ts +5 -0
  358. package/src/tools/goal/confirmation.ts +171 -3
  359. package/src/tools/goal/index.ts +15 -3
  360. package/src/tools/memory/save.ts +2 -0
  361. package/src/tools/schedules/index.ts +1 -0
  362. package/src/tools/schedules/loop-tool.ts +2 -0
  363. package/src/tools/schedules/present.ts +2 -0
  364. package/src/tools/schedules/schedule-tool.ts +84 -9
  365. package/src/tools/schedules/self-tool.ts +152 -0
  366. package/src/tools/schedules/timer-tools.ts +2 -0
  367. package/src/tools/schedules/types.ts +62 -0
  368. package/src/toolsets/manager.ts +55 -8
  369. package/src/turn/memory-promoter.ts +24 -3
  370. package/src/types/agent/base.ts +7 -0
  371. package/src/types/agent/supervisor.ts +11 -0
  372. package/src/types/agent/task.ts +12 -0
  373. package/src/types/goal/index.ts +72 -0
  374. package/src/types/hitl/index.ts +8 -0
  375. package/src/types/message/index.ts +7 -0
  376. package/src/types/session/events.ts +7 -0
  377. package/src/types/session/outcome.ts +16 -1
  378. package/src/types/session/records.ts +27 -0
  379. package/src/types/tool/index.ts +7 -0
  380. package/src/types/tool/presentation.ts +22 -0
@@ -0,0 +1,664 @@
1
+ /** Most gates one goal may carry. */
2
+ export const GOAL_GATE_MAX_ENTRIES = 8;
3
+ /** Most words in one gate's command. */
4
+ export const GOAL_GATE_MAX_ARGS = 64;
5
+ /** Longest single word of a gate's command, in characters. */
6
+ export const GOAL_GATE_MAX_ARG_CHARS = 2048;
7
+ /** Longest folder path a gate may name, in characters. */
8
+ export const GOAL_GATE_MAX_CWD_CHARS = 512;
9
+ /** Longest name a gate may carry, in characters. */
10
+ export const GOAL_GATE_MAX_NAME_CHARS = 120;
11
+ /** Longest output tail kept for a gate result, in characters. */
12
+ export const GOAL_GATE_MAX_TAIL_CHARS = 2000;
13
+ /** Longest a gate may run, in milliseconds (one hour). */
14
+ export const GOAL_GATE_MAX_TIMEOUT_MS = 3_600_000;
15
+ /** Shortest a gate may be given, in milliseconds. */
16
+ export const GOAL_GATE_MIN_TIMEOUT_MS = 1_000;
17
+ /** How long a gate may run when its entry says nothing, in milliseconds (five minutes). */
18
+ export const GOAL_GATE_DEFAULT_TIMEOUT_MS = 300_000;
19
+ /** Rounds in a row that may end with a failing gate before the goal stops, when nothing says otherwise. */
20
+ export const GOAL_GATE_DEFAULT_MAX_FAILING_ROUNDS = 3;
21
+ /** The block code of a goal stopped because its gates kept failing. */
22
+ export const GOAL_GATES_BLOCK_CODE = 'gates-failing';
23
+ // Controls (C0 and C1), and the marks that hide, reorder or isolate text (zero-width, line and
24
+ // paragraph separators, direction marks and isolates, the byte order mark, the soft hyphen): a
25
+ // command or a name carrying one can read as something it is not when the list is shown.
26
+ const CONTROL_CHARACTER =
27
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is refused.
28
+ /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff]/u;
29
+ /** Characters that need quoting for a person to read a word as one word. */
30
+ const PLAIN_WORD = /^[A-Za-z0-9_@%+=:,./-]+$/u;
31
+ /** A command as one line for a person to read. Never run: the host runs the list. */
32
+ export function goalGateCommandText(command) {
33
+ return command
34
+ .map((word) => (PLAIN_WORD.test(word) ? word : `'${word.replace(/'/gu, "'\\''")}'`))
35
+ .join(' ');
36
+ }
37
+ /** Whether a gate's result is a pass. */
38
+ export function goalGatePassed(result) {
39
+ return result.status === 'passed';
40
+ }
41
+ /** The names of the gates that did not pass. */
42
+ export function goalGateFailedNames(results) {
43
+ return results.filter((result) => !goalGatePassed(result)).map((result) => result.name);
44
+ }
45
+ /**
46
+ * Reads one gate entry, or says what is wrong with it. The command is a list
47
+ * of words; an empty word, a NUL or a control character in any word, a list
48
+ * that is too long and a program that is only a shell given a line to run are
49
+ * refused here so no host sees them.
50
+ */
51
+ export function parseGoalGateEntry(value) {
52
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
53
+ return { ok: false, problem: 'a gate must be a mapping with a command' };
54
+ }
55
+ const raw = value;
56
+ for (const key of Object.keys(raw)) {
57
+ if (key !== 'command' && key !== 'name' && key !== 'cwd' && key !== 'timeoutMs') {
58
+ return { ok: false, problem: `${key} is not a gate field (command, name, cwd, timeoutMs)` };
59
+ }
60
+ }
61
+ const command = raw.command;
62
+ if (!Array.isArray(command) || command.length === 0) {
63
+ return {
64
+ ok: false,
65
+ problem: 'command must be a list of words, the program first (never one line for a shell)',
66
+ };
67
+ }
68
+ if (command.length > GOAL_GATE_MAX_ARGS) {
69
+ return { ok: false, problem: `command may have at most ${GOAL_GATE_MAX_ARGS} words` };
70
+ }
71
+ const words = [];
72
+ for (const word of command) {
73
+ if (typeof word !== 'string')
74
+ return { ok: false, problem: 'every word of command must be text' };
75
+ if (word.length > GOAL_GATE_MAX_ARG_CHARS) {
76
+ return {
77
+ ok: false,
78
+ problem: `a word of command is longer than ${GOAL_GATE_MAX_ARG_CHARS} characters`,
79
+ };
80
+ }
81
+ if (CONTROL_CHARACTER.test(word)) {
82
+ return { ok: false, problem: 'a word of command holds a control character' };
83
+ }
84
+ words.push(word);
85
+ }
86
+ const program = words[0];
87
+ if (program.trim() === '' || program !== program.trim()) {
88
+ return { ok: false, problem: 'the program (first word of command) must be a name or a path' };
89
+ }
90
+ const shellLine = shellLineProblem(words);
91
+ if (shellLine !== undefined)
92
+ return { ok: false, problem: shellLine };
93
+ let cwd;
94
+ if (raw.cwd !== undefined) {
95
+ if (typeof raw.cwd !== 'string' || raw.cwd.trim() === '') {
96
+ return { ok: false, problem: 'cwd must be a folder inside the project, relative to it' };
97
+ }
98
+ const problem = cwdProblem(raw.cwd);
99
+ if (problem !== undefined)
100
+ return { ok: false, problem };
101
+ cwd = raw.cwd;
102
+ }
103
+ let timeoutMs;
104
+ if (raw.timeoutMs !== undefined) {
105
+ if (typeof raw.timeoutMs !== 'number' ||
106
+ !Number.isSafeInteger(raw.timeoutMs) ||
107
+ raw.timeoutMs < GOAL_GATE_MIN_TIMEOUT_MS ||
108
+ raw.timeoutMs > GOAL_GATE_MAX_TIMEOUT_MS) {
109
+ return {
110
+ ok: false,
111
+ problem: `timeoutMs must be a whole number from ${GOAL_GATE_MIN_TIMEOUT_MS} to ${GOAL_GATE_MAX_TIMEOUT_MS}`,
112
+ };
113
+ }
114
+ timeoutMs = raw.timeoutMs;
115
+ }
116
+ let name = goalGateCommandText(words);
117
+ if (raw.name !== undefined) {
118
+ if (typeof raw.name !== 'string' ||
119
+ raw.name.trim() === '' ||
120
+ CONTROL_CHARACTER.test(raw.name)) {
121
+ return { ok: false, problem: 'name must be a short line of text' };
122
+ }
123
+ name = raw.name.trim();
124
+ }
125
+ if (name.length > GOAL_GATE_MAX_NAME_CHARS)
126
+ name = `${name.slice(0, GOAL_GATE_MAX_NAME_CHARS - 1)}…`;
127
+ return {
128
+ ok: true,
129
+ entry: {
130
+ name,
131
+ command: words,
132
+ ...(cwd !== undefined ? { cwd } : {}),
133
+ ...(timeoutMs !== undefined ? { timeoutMs } : {}),
134
+ },
135
+ };
136
+ }
137
+ /** Shells: a line to run is given with a flag, whichever way the flag is written. */
138
+ const SHELL_PROGRAMS = new Set([
139
+ 'sh',
140
+ 'bash',
141
+ 'zsh',
142
+ 'dash',
143
+ 'ash',
144
+ 'ksh',
145
+ 'mksh',
146
+ 'pdksh',
147
+ 'yash',
148
+ 'rbash',
149
+ 'rksh',
150
+ 'rzsh',
151
+ 'csh',
152
+ 'tcsh',
153
+ 'fish',
154
+ 'nu',
155
+ 'nushell',
156
+ 'elvish',
157
+ 'xonsh',
158
+ 'rc',
159
+ 'cmd',
160
+ 'powershell',
161
+ 'powershell_ise',
162
+ 'pwsh',
163
+ 'pwsh-preview',
164
+ ]);
165
+ /** Programs that hand their arguments to a shell as one line, whatever the flags. */
166
+ const LINE_PROGRAMS = new Set(['wsl', 'ssh', 'mosh', 'rsh', 'forfiles', 'mshta']);
167
+ /** Subcommands of the package runners that still read the runner's own flags after them. */
168
+ const RUNNER_SUBCOMMANDS = new Set(['exec', 'x', 'dlx', 'run', 'run-script']);
169
+ /** Flags of the package runners that take a value, so the value is not taken for the subcommand. */
170
+ const RUNNER_VALUE_FLAGS = new Set([
171
+ '-C',
172
+ '-F',
173
+ '-w',
174
+ '-p',
175
+ '--dir',
176
+ '--filter',
177
+ '--prefix',
178
+ '--workspace',
179
+ '--cwd',
180
+ '--package',
181
+ '--registry',
182
+ '--userconfig',
183
+ '--loglevel',
184
+ '--use-node-version',
185
+ ]);
186
+ const CODE_RUNNERS = {
187
+ python: { cluster: 'c' },
188
+ pypy: { cluster: 'c' },
189
+ py: { cluster: 'c' },
190
+ node: { cluster: 'ep', long: ['eval', 'print'] },
191
+ nodejs: { cluster: 'ep', long: ['eval', 'print'] },
192
+ tsx: { cluster: 'ep', long: ['eval', 'print'] },
193
+ 'ts-node': { cluster: 'ep', long: ['eval', 'print'] },
194
+ 'ts-node-esm': { cluster: 'ep', long: ['eval', 'print'] },
195
+ 'babel-node': { cluster: 'ep', long: ['eval', 'print'] },
196
+ coffee: { cluster: 'ec' },
197
+ bun: { cluster: 'ep', long: ['eval', 'print'], words: ['repl'] },
198
+ deno: { cluster: 'e', long: ['eval', 'print'], words: ['eval', 'repl'] },
199
+ ruby: { cluster: 'e' },
200
+ jruby: { cluster: 'e' },
201
+ perl: { cluster: 'eE' },
202
+ raku: { cluster: 'e' },
203
+ php: { cluster: 'rRBE', long: ['run'] },
204
+ lua: { cluster: 'e' },
205
+ luajit: { cluster: 'e' },
206
+ osascript: { cluster: 'e' },
207
+ rscript: { cluster: 'e', long: ['expression'] },
208
+ r: { cluster: 'e', long: ['expression'] },
209
+ julia: { cluster: 'eEp', long: ['eval', 'print'] },
210
+ groovy: { cluster: 'e' },
211
+ scala: { cluster: 'e' },
212
+ clojure: { cluster: 'e' },
213
+ clj: { cluster: 'e' },
214
+ elixir: { cluster: 'e', long: ['eval'] },
215
+ erl: { cluster: 'e' },
216
+ racket: { cluster: 'e', long: ['eval'] },
217
+ ghc: { cluster: 'e' },
218
+ ghci: { cluster: 'e' },
219
+ jshell: { cluster: 'c' },
220
+ guile: { cluster: 'ce' },
221
+ tclsh: { cluster: 'c' },
222
+ expect: { cluster: 'c' },
223
+ psql: { cluster: 'c', long: ['command'] },
224
+ mysql: { cluster: 'e', long: ['execute'] },
225
+ mariadb: { cluster: 'e', long: ['execute'] },
226
+ mongosh: { long: ['eval'] },
227
+ mongo: { long: ['eval'] },
228
+ gdb: { cluster: 'e', long: ['eval-command', 'ex', 'iex', 'init-eval-command'] },
229
+ sqlite: {},
230
+ tar: { cluster: 'I', long: ['to-command', 'checkpoint-action', 'use-compress-program'] },
231
+ rsync: { cluster: 'e', long: ['rsh'] },
232
+ su: { cluster: 'c', long: ['command'] },
233
+ runuser: { cluster: 'c', long: ['command'] },
234
+ sg: { cluster: 'c' },
235
+ script: { cluster: 'c', long: ['command'] },
236
+ sudo: { cluster: 'si', long: ['shell', 'login'] },
237
+ doas: { cluster: 's' },
238
+ vim: { cluster: 'c', long: ['cmd'] },
239
+ nvim: { cluster: 'c', long: ['cmd'] },
240
+ vi: { cluster: 'c', long: ['cmd'] },
241
+ ex: { cluster: 'c', long: ['cmd'] },
242
+ emacs: { cluster: 'ef', long: ['eval', 'funcall', 'execute'] },
243
+ emacsclient: { cluster: 'e', long: ['eval'] },
244
+ npx: { cluster: 'c', long: ['call', 'shell-mode'], leadingOnly: true },
245
+ npm: { cluster: 'c', long: ['call', 'shell-mode'], leadingOnly: true },
246
+ pnpm: { cluster: 'c', long: ['call', 'shell-mode'], leadingOnly: true },
247
+ yarn: { cluster: 'c', long: ['call', 'shell-mode'], leadingOnly: true },
248
+ };
249
+ /**
250
+ * Programs whose first plain word is a program text (awk, sed): refused unless
251
+ * the program comes from a file (`-f`) and no inline program is added.
252
+ */
253
+ const PROGRAM_TEXT_RUNNERS = new Set(['awk', 'gawk', 'mawk', 'nawk', 'sed', 'gsed']);
254
+ /** Python's modules that run a string given to them. */
255
+ const PYTHON_CODE_MODULES = new Set(['timeit', 'code', 'codeop', 'runpy', 'idlelib']);
256
+ /** The program's own name: no folder, lowercase, no Windows extension, no version (`python3.12`). */
257
+ function programName(program) {
258
+ // Windows reads `cmd.`, `cmd.exe ` and `cmd.exe:stream` as cmd.exe.
259
+ const base = (program.trim().split(/[\\/]/u).pop() ?? program)
260
+ .toLowerCase()
261
+ .replace(/:.*$/u, '')
262
+ .replace(/[. ]+$/u, '');
263
+ const noExtension = base.replace(/\.(exe|cmd|bat|com|ps1)$/u, '');
264
+ const noVersion = noExtension.replace(/[-_.]?\d+(?:\.\d+)*[a-z]?$/u, '');
265
+ return noVersion === '' ? noExtension : noVersion;
266
+ }
267
+ /** A flag as PowerShell reads it: any dash or slash, lowercase, without `:value`. */
268
+ function powershellFlag(word) {
269
+ return word
270
+ .trim()
271
+ .toLowerCase()
272
+ .replace(/^[-/–—―]+/u, '')
273
+ .split(/[:=]/u)[0];
274
+ }
275
+ function powershellRunsLine(words) {
276
+ return words.some((word) => {
277
+ if (!/^[-/–—―]/u.test(word.trim()))
278
+ return false;
279
+ const flag = powershellFlag(word);
280
+ if (flag === '')
281
+ return false;
282
+ // PowerShell takes any unique start of a flag name: -c, -com, -enc, -e, -ec, -cwa.
283
+ return ('command'.startsWith(flag) ||
284
+ 'encodedcommand'.startsWith(flag) ||
285
+ 'commandwithargs'.startsWith(flag) ||
286
+ flag === 'ec' ||
287
+ flag === 'cwa');
288
+ });
289
+ }
290
+ const COMMAND_FLAG_PROGRAMS = {
291
+ 'nix-shell': { long: ['run', 'command'], prefix: ['-c'] },
292
+ nix: { long: ['command'], prefix: ['-c'] },
293
+ nodemon: { long: ['exec'], prefix: ['-x'] },
294
+ lldb: {
295
+ long: [
296
+ 'one-line',
297
+ 'one-line-before-file',
298
+ 'one-line-on-crash',
299
+ 'source',
300
+ 'source-before-file',
301
+ 'source-on-crash',
302
+ ],
303
+ prefix: ['-o', '-O', '-s', '-S', '-k', '-K'],
304
+ },
305
+ tmux: {
306
+ words: [
307
+ 'run-shell',
308
+ 'run',
309
+ 'if-shell',
310
+ 'if',
311
+ 'pipe-pane',
312
+ 'pipep',
313
+ 'new-session',
314
+ 'new',
315
+ 'new-window',
316
+ 'neww',
317
+ 'split-window',
318
+ 'splitw',
319
+ 'respawn-pane',
320
+ 'respawnp',
321
+ 'respawn-window',
322
+ 'respawnw',
323
+ 'display-popup',
324
+ 'popup',
325
+ ],
326
+ },
327
+ rc: { prefix: ['-c'] },
328
+ sbcl: { long: ['eval'] },
329
+ clisp: { prefix: ['-x'] },
330
+ csi: { prefix: ['-e', '-p'], long: ['eval', 'print'] },
331
+ runghc: { prefix: ['-e'] },
332
+ runhaskell: { prefix: ['-e'] },
333
+ crystal: { words: ['eval'] },
334
+ 'redis-cli': { words: ['eval', 'evalsha', 'eval_ro', 'evalsha_ro', 'fcall', 'fcall_ro'] },
335
+ fzf: { long: ['preview', 'bind', 'with-shell'] },
336
+ zip: { long: ['unzip-command'], prefix: ['-TT'] },
337
+ find: { words: ['-exec', '-execdir', '-ok', '-okdir'] },
338
+ rg: { long: ['pre', 'hostname-bin'] },
339
+ ripgrep: { long: ['pre', 'hostname-bin'] },
340
+ };
341
+ function commandFlagRuns(rule, words) {
342
+ const trimmed = words.map((word) => word.trim());
343
+ const lowered = trimmed.map((word) => word.toLowerCase());
344
+ for (const word of trimmed) {
345
+ if (rule.long?.some((long) => word === `--${long}` || word.startsWith(`--${long}=`)) === true) {
346
+ return true;
347
+ }
348
+ if (rule.prefix?.some((flag) => word.startsWith(flag) && !word.startsWith('--')) === true &&
349
+ /^-[^-]/u.test(word)) {
350
+ return true;
351
+ }
352
+ }
353
+ if (rule.words?.some((word) => lowered.includes(word.toLowerCase())) === true)
354
+ return true;
355
+ return (rule.sequences?.some((sequence) => {
356
+ let from = 0;
357
+ return sequence.every((part) => {
358
+ const at = lowered.indexOf(part, from);
359
+ if (at < 0)
360
+ return false;
361
+ from = at + 1;
362
+ return true;
363
+ });
364
+ }) === true);
365
+ }
366
+ /** Modules of `ansible -m` that run a command on the target. */
367
+ const ANSIBLE_COMMAND_MODULES = new Set([
368
+ 'shell',
369
+ 'command',
370
+ 'raw',
371
+ 'script',
372
+ 'expect',
373
+ 'win_shell',
374
+ 'win_command',
375
+ ]);
376
+ function ansibleRunsCommand(words) {
377
+ const moduleOf = (value) => {
378
+ if (value === undefined)
379
+ return false;
380
+ const last = value.trim().toLowerCase().split('.').pop() ?? '';
381
+ return ANSIBLE_COMMAND_MODULES.has(last);
382
+ };
383
+ for (let index = 0; index < words.length; index += 1) {
384
+ const word = words[index].trim();
385
+ if (word === '-m' || word === '--module-name') {
386
+ if (moduleOf(words[index + 1]))
387
+ return true;
388
+ }
389
+ else if (word.startsWith('--module-name=')) {
390
+ if (moduleOf(word.slice('--module-name='.length)))
391
+ return true;
392
+ }
393
+ else if (/^-m[^-]/u.test(word) && moduleOf(word.slice(2))) {
394
+ return true;
395
+ }
396
+ }
397
+ return false;
398
+ }
399
+ const GIT_VALUE_FLAGS = new Set([
400
+ '-C',
401
+ '--git-dir',
402
+ '--work-tree',
403
+ '--namespace',
404
+ '--super-prefix',
405
+ '--attr-source',
406
+ ]);
407
+ /** The subcommand of a git line: the first plain word after git's own flags. */
408
+ function gitSubcommand(words) {
409
+ for (let index = 0; index < words.length; index += 1) {
410
+ const word = words[index].trim();
411
+ if (GIT_VALUE_FLAGS.has(word)) {
412
+ index += 1;
413
+ continue;
414
+ }
415
+ if (!word.startsWith('-'))
416
+ return word.toLowerCase();
417
+ }
418
+ return undefined;
419
+ }
420
+ /**
421
+ * git subcommands and flags that run a command: `rebase -x`, `bisect run`,
422
+ * `submodule foreach`, `filter-branch --*-filter`, `difftool -x`, `grep -O`,
423
+ * `--upload-pack`, `--receive-pack`, `archive --exec`, `clone -u`.
424
+ */
425
+ function gitRunsCommand(words) {
426
+ const trimmed = words.map((word) => word.trim());
427
+ if (trimmed.some((word) => /^--(upload-pack|receive-pack|exec|extcmd|open-files-in-pager)(=|$)/u.test(word) ||
428
+ /^--[a-z]+(?:-[a-z]+)*-filter(=|$)/u.test(word))) {
429
+ return true;
430
+ }
431
+ const sub = gitSubcommand(trimmed);
432
+ const rest = trimmed.slice(trimmed.findIndex((word) => word.toLowerCase() === sub) + 1);
433
+ if (sub === 'bisect' && rest.some((word) => word.toLowerCase() === 'run'))
434
+ return true;
435
+ if (sub === 'submodule' && rest.some((word) => word.toLowerCase() === 'foreach'))
436
+ return true;
437
+ if (sub === 'rebase' && rest.some((word) => /^-[A-Za-z]*x/u.test(word)))
438
+ return true;
439
+ if (sub === 'difftool' && rest.some((word) => /^-[A-Za-z]*x/u.test(word)))
440
+ return true;
441
+ if (sub === 'grep' && rest.some((word) => /^-[A-Za-z]*O/u.test(word)))
442
+ return true;
443
+ if (sub === 'clone' && rest.some((word) => /^-[A-Za-z]*u/u.test(word)))
444
+ return true;
445
+ return false;
446
+ }
447
+ /** `cmd` runs the rest of its line behind /c, /k or /r, however the switches are joined (`/d/s/c`). */
448
+ function cmdRunsLine(words) {
449
+ return words.some((word) => /^\/(?:[a-z:][^/]*\/)*[ckr]/iu.test(word.trim()));
450
+ }
451
+ function shellRunsLine(name, words) {
452
+ if (name === 'powershell' || name === 'pwsh')
453
+ return powershellRunsLine(words);
454
+ if (name === 'cmd')
455
+ return cmdRunsLine(words);
456
+ return words.some((word) => {
457
+ const flag = word.trim();
458
+ // Any single-dash cluster that holds c: -c, -lc, -xec, -euxfc, -cprint.
459
+ if (/^-[A-Za-z0-9]*c/u.test(flag))
460
+ return true;
461
+ // fish and nushell spell it out.
462
+ return /^--(command|commands)(=|$)/u.test(flag);
463
+ });
464
+ }
465
+ function clusterHas(word, letters) {
466
+ const match = /^-([A-Za-z0-9]+)/u.exec(word.trim());
467
+ if (match === null)
468
+ return false;
469
+ return [...match[1]].some((letter) => letters.includes(letter));
470
+ }
471
+ function runnerRunsCode(name, runner, words) {
472
+ // sqlite3 runs a shell line from a dot command given as an argument.
473
+ if (name === 'sqlite' &&
474
+ words.some((word) => /^\s*\.(shell|system|import|output|once|excel|www)\b/u.test(word) ||
475
+ /^\s*\.read\s+["']?[|!]/u.test(word))) {
476
+ return true;
477
+ }
478
+ let afterModuleFlag = false;
479
+ for (let index = 0; index < words.length; index += 1) {
480
+ const word = words[index].trim();
481
+ if (runner.leadingOnly === true) {
482
+ if (RUNNER_VALUE_FLAGS.has(word)) {
483
+ index += 1;
484
+ continue;
485
+ }
486
+ // A subcommand that takes the runner's own flags goes on; any other word is the tool's.
487
+ if (!word.startsWith('-') && !RUNNER_SUBCOMMANDS.has(word))
488
+ return false;
489
+ }
490
+ if (runner.cluster !== undefined && clusterHas(word, runner.cluster))
491
+ return true;
492
+ if (runner.long?.some((long) => word === `--${long}` || word.startsWith(`--${long}=`)) === true) {
493
+ return true;
494
+ }
495
+ if (runner.words?.includes(word) === true)
496
+ return true;
497
+ // An inline module is code too: node --import data:text/javascript,… , deno run https://…
498
+ // The same behind an `=` (--import=data:…, --require=data:…, --loader=https://…).
499
+ if ((name === 'node' || name === 'nodejs' || name === 'bun' || name === 'deno') &&
500
+ /^(data:|https?:\/\/)/iu.test(word.replace(/^--?[A-Za-z][A-Za-z-]*=/u, ''))) {
501
+ return true;
502
+ }
503
+ if (name === 'python' || name === 'pypy' || name === 'py') {
504
+ if (afterModuleFlag && PYTHON_CODE_MODULES.has(word))
505
+ return true;
506
+ afterModuleFlag = /^-[A-Za-z]*m$/u.test(word);
507
+ }
508
+ }
509
+ return false;
510
+ }
511
+ function programTextRuns(words) {
512
+ let fromFile = false;
513
+ for (const raw of words) {
514
+ const word = raw.trim();
515
+ if (/^-[A-Za-z0-9]*[eE]/u.test(word) || /^--(source|expression|exec)(=|$)/u.test(word)) {
516
+ return true;
517
+ }
518
+ if (/^-[A-Za-z0-9]*f/u.test(word) || /^--file(=|$)/u.test(word))
519
+ fromFile = true;
520
+ }
521
+ return !fromFile;
522
+ }
523
+ /** `git -c name=value` sets configuration, and `alias.x=!line` or `core.sshCommand` runs a line. */
524
+ function gitSetsConfiguration(words) {
525
+ for (let index = 0; index < words.length; index += 1) {
526
+ const word = words[index].trim();
527
+ if (/^-c/u.test(word) || /^--config-env(=|$)/u.test(word) || word === '--exec-path')
528
+ return true;
529
+ if (GIT_VALUE_FLAGS.has(word)) {
530
+ index += 1;
531
+ continue;
532
+ }
533
+ if (!word.startsWith('-'))
534
+ return false;
535
+ }
536
+ return false;
537
+ }
538
+ /** Variables that make a program load or run something else (a preload, a startup script, a pager or ssh command). */
539
+ const RISKY_ENVIRONMENT = /^(?:LD_.*|DYLD_.*|BASH_ENV|ENV|SHELLOPTS|BASHOPTS|PS4|PROMPT_COMMAND|IFS|PATH|PATHEXT|COMSPEC|PYTHON(?:STARTUP|HOME|PATH)|NODE_(?:OPTIONS|PATH)|PERL5?(?:OPT|LIB)|RUBY(?:OPT|LIB)|GIT_(?:SSH|SSH_COMMAND|PAGER|EXTERNAL_DIFF|ASKPASS|EDITOR|SEQUENCE_EDITOR|PROXY_COMMAND|EXEC_PATH|CONFIG.*)|SSH_ASKPASS|PAGER|EDITOR|VISUAL|LESSOPEN|LESSCLOSE|MANPAGER)$/u;
540
+ const SHELL_LINE_MESSAGE = 'a shell given a line to run (sh -c, cmd /c, powershell -Command) is not allowed: write the program and its arguments as separate words';
541
+ const INLINE_CODE_MESSAGE = 'a program given code or a command line to run (python -c, node -e, perl -e, su -c, …) is not allowed: put the code in a file in the project and name the file';
542
+ /**
543
+ * A command that hands a shell, or an interpreter, a line or a piece of code to
544
+ * run is the string-for-a-shell this list exists to avoid: `sh -c "…"`,
545
+ * `bash -euxfc "…"`, `cmd /r …`, `powershell -Command …`, `python -c …`,
546
+ * `node -e …`, and the same behind `env`, `nice`, `timeout`, `xargs` or a path.
547
+ * Refused by name and by flag in every position, so a repository's file cannot
548
+ * smuggle one in as a list. A script file given to a shell or an interpreter
549
+ * (`sh ./check.sh`, `node check.js`) is the project's own file and passes.
550
+ *
551
+ * This catches the common shell and inline-code forms, with a list of programs
552
+ * that run a command through a flag or a subcommand. It is a mistake-catcher
553
+ * and not a boundary: a list can still start any program, and a program can
554
+ * read a flag by an abbreviation or a spelling this list does not know. The
555
+ * boundary is the person's approval of the exact list when it comes from a
556
+ * project's checked-in file (see the CLI).
557
+ */
558
+ function shellLineProblem(words) {
559
+ // Every position, not only the first: a wrapper (`env`, `nice -n 5`, `sudo -u x`, `xargs`,
560
+ // `docker run image`) puts the program anywhere behind its own options.
561
+ for (let index = 0; index < words.length; index += 1) {
562
+ const name = programName(words[index]);
563
+ const rest = words.slice(index + 1);
564
+ // A short Windows name (POWERS~1.EXE) is the same program under a name this list cannot read.
565
+ if (/~\d+\.(exe|cmd|bat|com)$/iu.test(words[index].trim())) {
566
+ return 'a short Windows name (like POWERS~1.EXE) hides which program runs: write its full name';
567
+ }
568
+ if (LINE_PROGRAMS.has(name) && rest.length > 0) {
569
+ return `${name} runs its arguments as a line for a shell: name the program as separate words, not through ${name}`;
570
+ }
571
+ // `env -S 'sh -c …'` splits one word into a command and runs it.
572
+ if (name === 'env' && rest.some((word) => /^(-[A-Za-z]*S|--split-string)/u.test(word.trim()))) {
573
+ return 'env -S runs one word as a command line: write the program and its arguments as separate words';
574
+ }
575
+ // `env NAME=value program`: a variable that makes the program run something else.
576
+ if (name === 'env') {
577
+ const risky = rest.find((word) => {
578
+ const assignment = /^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(word.trim());
579
+ return assignment !== null && RISKY_ENVIRONMENT.test(assignment[1]);
580
+ });
581
+ if (risky !== undefined) {
582
+ return `${risky.split('=')[0]} changes which program or line runs: set it in the project, not in the gate`;
583
+ }
584
+ }
585
+ if (SHELL_PROGRAMS.has(name) && shellRunsLine(name, rest))
586
+ return SHELL_LINE_MESSAGE;
587
+ const runner = CODE_RUNNERS[name];
588
+ if (runner !== undefined && runnerRunsCode(name, runner, rest))
589
+ return INLINE_CODE_MESSAGE;
590
+ if (PROGRAM_TEXT_RUNNERS.has(name) && rest.length > 0 && programTextRuns(rest)) {
591
+ return `${name} given its program as text is not allowed: put the program in a file and name it with -f`;
592
+ }
593
+ if (name === 'git' && gitSetsConfiguration(rest)) {
594
+ return 'git -c sets configuration that can run a command: set it in a config file instead';
595
+ }
596
+ if (name === 'git' && gitRunsCommand(rest)) {
597
+ return 'a git flag or subcommand that runs a command (rebase -x, bisect run, submodule foreach, --upload-pack, filter-branch --*-filter) is not allowed: run the commands as separate gates';
598
+ }
599
+ const flagRule = COMMAND_FLAG_PROGRAMS[name];
600
+ if (flagRule !== undefined && commandFlagRuns(flagRule, rest)) {
601
+ return `${name} given a command to run through one of its flags or subcommands is not allowed: name that command as the gate instead`;
602
+ }
603
+ if (name === 'ansible' && ansibleRunsCommand(rest)) {
604
+ return 'ansible -m shell (or command, raw, script) runs a command line: name the program as separate words';
605
+ }
606
+ }
607
+ return undefined;
608
+ }
609
+ /** A folder a gate names must stay inside the project: relative, no `..`, no drive or root. */
610
+ function cwdProblem(cwd) {
611
+ if (cwd.length > GOAL_GATE_MAX_CWD_CHARS) {
612
+ return `cwd is longer than ${GOAL_GATE_MAX_CWD_CHARS} characters`;
613
+ }
614
+ if (CONTROL_CHARACTER.test(cwd))
615
+ return 'cwd holds a control character';
616
+ if (/^([A-Za-z]:|[\\/]|~)/u.test(cwd) || cwd.startsWith('\\\\')) {
617
+ return 'cwd must be inside the project, relative to it (no absolute path, drive or ~)';
618
+ }
619
+ if (cwd.split(/[\\/]+/u).some((part) => part === '..')) {
620
+ return 'cwd must stay inside the project (no ..)';
621
+ }
622
+ return undefined;
623
+ }
624
+ /**
625
+ * The gates a goal is created with, checked: at most {@link GOAL_GATE_MAX_ENTRIES}
626
+ * entries, each valid, and a failing-round cap of at least 1. Throws a
627
+ * `TypeError` naming the first problem. `undefined` for no gates.
628
+ */
629
+ export function goalGatesFrom(spec) {
630
+ if (spec === undefined || spec.entries.length === 0)
631
+ return undefined;
632
+ if (spec.entries.length > GOAL_GATE_MAX_ENTRIES) {
633
+ throw new TypeError(`a goal may carry at most ${GOAL_GATE_MAX_ENTRIES} gates.`);
634
+ }
635
+ const entries = [];
636
+ const names = new Set();
637
+ for (const [index, raw] of spec.entries.entries()) {
638
+ const parsed = parseGoalGateEntry(raw);
639
+ if (!parsed.ok)
640
+ throw new TypeError(`goal gate ${index + 1}: ${parsed.problem}.`);
641
+ // A result is found by its gate's name, so two gates may not share one.
642
+ if (names.has(parsed.entry.name)) {
643
+ throw new TypeError(`goal gate ${index + 1}: the name ${parsed.entry.name} is used twice.`);
644
+ }
645
+ names.add(parsed.entry.name);
646
+ entries.push(parsed.entry);
647
+ }
648
+ const cap = spec.maxFailingRounds ?? GOAL_GATE_DEFAULT_MAX_FAILING_ROUNDS;
649
+ if (!Number.isSafeInteger(cap) || cap < 1) {
650
+ throw new TypeError('goal gate maxFailingRounds must be a whole number of at least 1.');
651
+ }
652
+ return { entries, maxFailingRounds: cap, failingRounds: 0, results: [] };
653
+ }
654
+ /** The end of a text, bounded, with the cut marked. */
655
+ export function goalGateTail(text, max = GOAL_GATE_MAX_TAIL_CHARS) {
656
+ const trimmed = text.replace(/\s+$/u, '');
657
+ return trimmed.length > max ? `…${trimmed.slice(trimmed.length - (max - 1))}` : trimmed;
658
+ }
659
+ /** The sentence for a goal stopped by its gates. */
660
+ export function goalGatesBlockSentence(gates, names) {
661
+ const rounds = gates.maxFailingRounds;
662
+ return `${rounds} round${rounds === 1 ? '' : 's'} in a row ended with a completion gate failing: ${names.join('; ')}.`;
663
+ }
664
+ //# sourceMappingURL=gates.js.map