@stigmer/cli 0.1.0-dev.20261017064309.g94d062a29f89 → 0.1.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 (760) hide show
  1. package/README.md +5 -4
  2. package/auth/auth0.js +1 -1
  3. package/auth/auth0.js.map +1 -1
  4. package/auth/token.d.ts +26 -4
  5. package/auth/token.d.ts.map +1 -1
  6. package/auth/token.js +120 -24
  7. package/auth/token.js.map +1 -1
  8. package/client/client.d.ts.map +1 -1
  9. package/client/client.js +21 -8
  10. package/client/client.js.map +1 -1
  11. package/command-tree.d.ts +63 -0
  12. package/command-tree.d.ts.map +1 -0
  13. package/command-tree.js +128 -0
  14. package/command-tree.js.map +1 -0
  15. package/commands/access-history/index.d.ts.map +1 -1
  16. package/commands/access-history/index.js +13 -1
  17. package/commands/access-history/index.js.map +1 -1
  18. package/commands/agent-exec-flags.d.ts +2 -0
  19. package/commands/agent-exec-flags.d.ts.map +1 -1
  20. package/commands/agent-exec-flags.js +9 -5
  21. package/commands/agent-exec-flags.js.map +1 -1
  22. package/commands/apikey/duration.d.ts.map +1 -1
  23. package/commands/apikey/duration.js +1 -2
  24. package/commands/apikey/duration.js.map +1 -1
  25. package/commands/apikey/index.d.ts.map +1 -1
  26. package/commands/apikey/index.js +3 -4
  27. package/commands/apikey/index.js.map +1 -1
  28. package/commands/apply.d.ts.map +1 -1
  29. package/commands/apply.js +2 -32
  30. package/commands/apply.js.map +1 -1
  31. package/commands/auth/index.d.ts.map +1 -1
  32. package/commands/auth/index.js +7 -5
  33. package/commands/auth/index.js.map +1 -1
  34. package/commands/auth/whoami.js +1 -1
  35. package/commands/config/index.js +3 -3
  36. package/commands/config/kv.d.ts.map +1 -1
  37. package/commands/config/kv.js +18 -14
  38. package/commands/config/kv.js.map +1 -1
  39. package/commands/connect.d.ts.map +1 -1
  40. package/commands/connect.js +18 -2
  41. package/commands/connect.js.map +1 -1
  42. package/commands/download.d.ts.map +1 -1
  43. package/commands/download.js +81 -54
  44. package/commands/download.js.map +1 -1
  45. package/commands/eval.d.ts.map +1 -1
  46. package/commands/eval.js +17 -19
  47. package/commands/eval.js.map +1 -1
  48. package/commands/file.d.ts +3 -0
  49. package/commands/file.d.ts.map +1 -0
  50. package/commands/file.js +64 -0
  51. package/commands/file.js.map +1 -0
  52. package/commands/get.d.ts.map +1 -1
  53. package/commands/get.js +20 -13
  54. package/commands/get.js.map +1 -1
  55. package/commands/help.d.ts +15 -0
  56. package/commands/help.d.ts.map +1 -0
  57. package/commands/help.js +175 -0
  58. package/commands/help.js.map +1 -0
  59. package/commands/internal-daemon.d.ts.map +1 -1
  60. package/commands/internal-daemon.js +9 -2
  61. package/commands/internal-daemon.js.map +1 -1
  62. package/commands/list.d.ts.map +1 -1
  63. package/commands/list.js +22 -1
  64. package/commands/list.js.map +1 -1
  65. package/commands/logs.js +1 -1
  66. package/commands/logs.js.map +1 -1
  67. package/commands/mcp-server.d.ts +16 -6
  68. package/commands/mcp-server.d.ts.map +1 -1
  69. package/commands/mcp-server.js +51 -26
  70. package/commands/mcp-server.js.map +1 -1
  71. package/commands/provider-key/index.d.ts +3 -0
  72. package/commands/provider-key/index.d.ts.map +1 -0
  73. package/commands/provider-key/index.js +156 -0
  74. package/commands/provider-key/index.js.map +1 -0
  75. package/commands/push.js +8 -8
  76. package/commands/push.js.map +1 -1
  77. package/commands/resume.d.ts.map +1 -1
  78. package/commands/resume.js +17 -11
  79. package/commands/resume.js.map +1 -1
  80. package/commands/routine.d.ts.map +1 -1
  81. package/commands/routine.js +42 -3
  82. package/commands/routine.js.map +1 -1
  83. package/commands/run.d.ts.map +1 -1
  84. package/commands/run.js +34 -15
  85. package/commands/run.js.map +1 -1
  86. package/commands/runs/approve.d.ts.map +1 -1
  87. package/commands/runs/approve.js +10 -2
  88. package/commands/runs/approve.js.map +1 -1
  89. package/commands/runs/control.d.ts.map +1 -1
  90. package/commands/runs/control.js +24 -16
  91. package/commands/runs/control.js.map +1 -1
  92. package/commands/runs/index.d.ts.map +1 -1
  93. package/commands/runs/index.js +1 -2
  94. package/commands/runs/index.js.map +1 -1
  95. package/commands/runs/logs.d.ts.map +1 -1
  96. package/commands/runs/logs.js +7 -4
  97. package/commands/runs/logs.js.map +1 -1
  98. package/commands/runs/to-eval-case.d.ts.map +1 -1
  99. package/commands/runs/to-eval-case.js +13 -4
  100. package/commands/runs/to-eval-case.js.map +1 -1
  101. package/commands/runs/trace.js +1 -1
  102. package/commands/runs/trace.js.map +1 -1
  103. package/commands/search.js +2 -3
  104. package/commands/search.js.map +1 -1
  105. package/commands/service-account/index.d.ts.map +1 -1
  106. package/commands/service-account/index.js +4 -2
  107. package/commands/service-account/index.js.map +1 -1
  108. package/commands/session-help.d.ts +5 -0
  109. package/commands/session-help.d.ts.map +1 -0
  110. package/commands/session-help.js +38 -0
  111. package/commands/session-help.js.map +1 -0
  112. package/commands/setup.js +5 -5
  113. package/commands/setup.js.map +1 -1
  114. package/commands/shared.d.ts +10 -2
  115. package/commands/shared.d.ts.map +1 -1
  116. package/commands/shared.js +30 -3
  117. package/commands/shared.js.map +1 -1
  118. package/commands/tag.d.ts.map +1 -1
  119. package/commands/tag.js +11 -6
  120. package/commands/tag.js.map +1 -1
  121. package/commands/up.d.ts.map +1 -1
  122. package/commands/up.js +51 -21
  123. package/commands/up.js.map +1 -1
  124. package/commands/validate.js +2 -2
  125. package/commands/validate.js.map +1 -1
  126. package/commands/version.d.ts.map +1 -1
  127. package/commands/version.js +8 -4
  128. package/commands/version.js.map +1 -1
  129. package/config/config.d.ts +5 -22
  130. package/config/config.d.ts.map +1 -1
  131. package/config/config.js +56 -47
  132. package/config/config.js.map +1 -1
  133. package/config/index.d.ts +2 -2
  134. package/config/index.d.ts.map +1 -1
  135. package/config/index.js +1 -1
  136. package/config/index.js.map +1 -1
  137. package/config/keys.js +4 -4
  138. package/config/keys.js.map +1 -1
  139. package/config/paths.js +2 -2
  140. package/config/paths.js.map +1 -1
  141. package/config/resolve.d.ts +12 -2
  142. package/config/resolve.d.ts.map +1 -1
  143. package/config/resolve.js +18 -8
  144. package/config/resolve.js.map +1 -1
  145. package/errors/classify.d.ts +20 -0
  146. package/errors/classify.d.ts.map +1 -1
  147. package/errors/classify.js +97 -21
  148. package/errors/classify.js.map +1 -1
  149. package/errors/command-line.d.ts +14 -0
  150. package/errors/command-line.d.ts.map +1 -0
  151. package/errors/command-line.js +90 -0
  152. package/errors/command-line.js.map +1 -0
  153. package/errors/handle.js +2 -2
  154. package/errors/handle.js.map +1 -1
  155. package/errors/index.d.ts +2 -2
  156. package/errors/index.d.ts.map +1 -1
  157. package/errors/index.js +12 -2
  158. package/errors/index.js.map +1 -1
  159. package/errors/usage-error.js +1 -1
  160. package/errors/usage-error.js.map +1 -1
  161. package/global-options.d.ts +35 -0
  162. package/global-options.d.ts.map +1 -0
  163. package/global-options.js +81 -0
  164. package/global-options.js.map +1 -0
  165. package/local/artifact.d.ts +1 -20
  166. package/local/artifact.d.ts.map +1 -1
  167. package/local/artifact.js +35 -117
  168. package/local/artifact.js.map +1 -1
  169. package/local/constants.d.ts +3 -9
  170. package/local/constants.d.ts.map +1 -1
  171. package/local/constants.js +3 -9
  172. package/local/constants.js.map +1 -1
  173. package/local/daemon/components.d.ts +18 -5
  174. package/local/daemon/components.d.ts.map +1 -1
  175. package/local/daemon/components.js +61 -23
  176. package/local/daemon/components.js.map +1 -1
  177. package/local/daemon/env.d.ts +1 -5
  178. package/local/daemon/env.d.ts.map +1 -1
  179. package/local/daemon/env.js +0 -2
  180. package/local/daemon/env.js.map +1 -1
  181. package/local/daemon/host.d.ts +5 -0
  182. package/local/daemon/host.d.ts.map +1 -1
  183. package/local/daemon/host.js +68 -21
  184. package/local/daemon/host.js.map +1 -1
  185. package/local/daemon/index.d.ts +2 -1
  186. package/local/daemon/index.d.ts.map +1 -1
  187. package/local/daemon/index.js +2 -1
  188. package/local/daemon/index.js.map +1 -1
  189. package/local/daemon/launch.d.ts +58 -9
  190. package/local/daemon/launch.d.ts.map +1 -1
  191. package/local/daemon/launch.js +210 -64
  192. package/local/daemon/launch.js.map +1 -1
  193. package/local/daemon/process.d.ts +11 -7
  194. package/local/daemon/process.d.ts.map +1 -1
  195. package/local/daemon/process.js +74 -38
  196. package/local/daemon/process.js.map +1 -1
  197. package/local/daemon/signals.d.ts +3 -0
  198. package/local/daemon/signals.d.ts.map +1 -0
  199. package/local/daemon/signals.js +19 -0
  200. package/local/daemon/signals.js.map +1 -0
  201. package/local/daemon/supervisor.d.ts +9 -2
  202. package/local/daemon/supervisor.d.ts.map +1 -1
  203. package/local/daemon/supervisor.js +81 -22
  204. package/local/daemon/supervisor.js.map +1 -1
  205. package/local/daemon/types.d.ts +6 -1
  206. package/local/daemon/types.d.ts.map +1 -1
  207. package/local/daemon/types.js +2 -3
  208. package/local/daemon/types.js.map +1 -1
  209. package/local/llm-config.d.ts +4 -2
  210. package/local/llm-config.d.ts.map +1 -1
  211. package/local/llm-config.js +15 -9
  212. package/local/llm-config.js.map +1 -1
  213. package/local/logs/view.d.ts.map +1 -1
  214. package/local/logs/view.js +5 -6
  215. package/local/logs/view.js.map +1 -1
  216. package/local/net/tcp.d.ts +8 -6
  217. package/local/net/tcp.d.ts.map +1 -1
  218. package/local/net/tcp.js +13 -8
  219. package/local/net/tcp.js.map +1 -1
  220. package/local/paths.d.ts +1 -1
  221. package/local/paths.d.ts.map +1 -1
  222. package/local/paths.js +2 -3
  223. package/local/paths.js.map +1 -1
  224. package/local/provider-reach.d.ts +18 -0
  225. package/local/provider-reach.d.ts.map +1 -0
  226. package/local/provider-reach.js +109 -0
  227. package/local/provider-reach.js.map +1 -0
  228. package/local/reset.d.ts.map +1 -1
  229. package/local/reset.js +1 -2
  230. package/local/reset.js.map +1 -1
  231. package/local/runtime/index.d.ts.map +1 -1
  232. package/local/runtime/index.js +1 -2
  233. package/local/runtime/index.js.map +1 -1
  234. package/local/runtime/node.js +1 -1
  235. package/local/runtime/runner.js +2 -2
  236. package/local/runtime/runner.js.map +1 -1
  237. package/local/runtime/runtimes-install.js +1 -1
  238. package/local/runtime/server.d.ts.map +1 -1
  239. package/local/runtime/server.js +2 -4
  240. package/local/runtime/server.js.map +1 -1
  241. package/local/runtime/which.js +1 -1
  242. package/local/runtime/which.js.map +1 -1
  243. package/local/setup/wizard.d.ts +1 -1
  244. package/local/setup/wizard.d.ts.map +1 -1
  245. package/local/setup/wizard.js +7 -5
  246. package/local/setup/wizard.js.map +1 -1
  247. package/local/state/health-state.d.ts +6 -0
  248. package/local/state/health-state.d.ts.map +1 -1
  249. package/local/state/health-state.js +6 -2
  250. package/local/state/health-state.js.map +1 -1
  251. package/local/state/lock.d.ts +3 -2
  252. package/local/state/lock.d.ts.map +1 -1
  253. package/local/state/lock.js +26 -28
  254. package/local/state/lock.js.map +1 -1
  255. package/local/state/log-rotation.d.ts.map +1 -1
  256. package/local/state/log-rotation.js +2 -3
  257. package/local/state/log-rotation.js.map +1 -1
  258. package/local/state/pidfile.d.ts +24 -1
  259. package/local/state/pidfile.d.ts.map +1 -1
  260. package/local/state/pidfile.js +54 -6
  261. package/local/state/pidfile.js.map +1 -1
  262. package/local/state/proc.d.ts +31 -0
  263. package/local/state/proc.d.ts.map +1 -1
  264. package/local/state/proc.js +98 -1
  265. package/local/state/proc.js.map +1 -1
  266. package/local/state/startup-config.d.ts +2 -2
  267. package/local/status.d.ts +2 -4
  268. package/local/status.d.ts.map +1 -1
  269. package/local/status.js +26 -41
  270. package/local/status.js.map +1 -1
  271. package/local/temporal/download.d.ts +9 -5
  272. package/local/temporal/download.d.ts.map +1 -1
  273. package/local/temporal/download.js +29 -8
  274. package/local/temporal/download.js.map +1 -1
  275. package/local/temporal/index.d.ts +1 -1
  276. package/local/temporal/index.d.ts.map +1 -1
  277. package/local/temporal/index.js +1 -1
  278. package/local/temporal/index.js.map +1 -1
  279. package/local/temporal/manager.d.ts +31 -5
  280. package/local/temporal/manager.d.ts.map +1 -1
  281. package/local/temporal/manager.js +74 -35
  282. package/local/temporal/manager.js.map +1 -1
  283. package/local/temporal/supervisor.js +1 -1
  284. package/local/temporal/supervisor.js.map +1 -1
  285. package/local/webconsole/index.d.ts +5 -2
  286. package/local/webconsole/index.d.ts.map +1 -1
  287. package/local/webconsole/index.js +8 -6
  288. package/local/webconsole/index.js.map +1 -1
  289. package/marketplace/github.js +1 -1
  290. package/marketplace/github.js.map +1 -1
  291. package/marketplace/official.js +1 -1
  292. package/marketplace/official.js.map +1 -1
  293. package/output/command-result.d.ts +6 -0
  294. package/output/command-result.d.ts.map +1 -1
  295. package/output/command-result.js +13 -2
  296. package/output/command-result.js.map +1 -1
  297. package/output/confirm.d.ts.map +1 -1
  298. package/output/confirm.js +2 -3
  299. package/output/confirm.js.map +1 -1
  300. package/output/format.d.ts.map +1 -1
  301. package/output/format.js +5 -6
  302. package/output/format.js.map +1 -1
  303. package/output/index.d.ts +2 -2
  304. package/output/index.d.ts.map +1 -1
  305. package/output/index.js +2 -2
  306. package/output/index.js.map +1 -1
  307. package/output/printable.d.ts +8 -0
  308. package/output/printable.d.ts.map +1 -0
  309. package/output/printable.js +24 -0
  310. package/output/printable.js.map +1 -0
  311. package/output/proto.d.ts.map +1 -1
  312. package/output/proto.js +3 -4
  313. package/output/proto.js.map +1 -1
  314. package/output/style.js +2 -2
  315. package/output/style.js.map +1 -1
  316. package/output/table.d.ts +20 -1
  317. package/output/table.d.ts.map +1 -1
  318. package/output/table.js +75 -17
  319. package/output/table.js.map +1 -1
  320. package/package.json +13 -10
  321. package/program.d.ts +0 -14
  322. package/program.d.ts.map +1 -1
  323. package/program.js +57 -119
  324. package/program.js.map +1 -1
  325. package/registry/aliases.d.ts.map +1 -1
  326. package/registry/aliases.js +0 -3
  327. package/registry/aliases.js.map +1 -1
  328. package/registry/index.d.ts +1 -1
  329. package/registry/index.d.ts.map +1 -1
  330. package/registry/index.js +1 -1
  331. package/registry/index.js.map +1 -1
  332. package/registry/metadata.d.ts +0 -15
  333. package/registry/metadata.d.ts.map +1 -1
  334. package/registry/metadata.js +16 -57
  335. package/registry/metadata.js.map +1 -1
  336. package/registry/registry.d.ts +1 -5
  337. package/registry/registry.d.ts.map +1 -1
  338. package/registry/registry.js +3 -11
  339. package/registry/registry.js.map +1 -1
  340. package/registry/verb-support.d.ts.map +1 -1
  341. package/registry/verb-support.js +28 -5
  342. package/registry/verb-support.js.map +1 -1
  343. package/resources/agent/quality.d.ts +10 -5
  344. package/resources/agent/quality.d.ts.map +1 -1
  345. package/resources/agent/quality.js +19 -9
  346. package/resources/agent/quality.js.map +1 -1
  347. package/resources/agent/resolve.js +3 -3
  348. package/resources/agent/resolve.js.map +1 -1
  349. package/resources/apply/apply.d.ts +4 -3
  350. package/resources/apply/apply.d.ts.map +1 -1
  351. package/resources/apply/apply.js +54 -41
  352. package/resources/apply/apply.js.map +1 -1
  353. package/resources/apply/handlers.d.ts.map +1 -1
  354. package/resources/apply/handlers.js +3 -4
  355. package/resources/apply/handlers.js.map +1 -1
  356. package/resources/channel.d.ts.map +1 -1
  357. package/resources/channel.js +3 -4
  358. package/resources/channel.js.map +1 -1
  359. package/resources/connect/connect.js +2 -2
  360. package/resources/connect/connect.js.map +1 -1
  361. package/resources/delete.d.ts.map +1 -1
  362. package/resources/delete.js +38 -4
  363. package/resources/delete.js.map +1 -1
  364. package/resources/documents.js +1 -1
  365. package/resources/documents.js.map +1 -1
  366. package/resources/download.d.ts +43 -3
  367. package/resources/download.d.ts.map +1 -1
  368. package/resources/download.js +169 -34
  369. package/resources/download.js.map +1 -1
  370. package/resources/eval-run/options.d.ts +3 -1
  371. package/resources/eval-run/options.d.ts.map +1 -1
  372. package/resources/eval-run/options.js +36 -18
  373. package/resources/eval-run/options.js.map +1 -1
  374. package/resources/eval-run/report.d.ts +4 -2
  375. package/resources/eval-run/report.d.ts.map +1 -1
  376. package/resources/eval-run/report.js +9 -7
  377. package/resources/eval-run/report.js.map +1 -1
  378. package/resources/eval-run/run.d.ts +2 -1
  379. package/resources/eval-run/run.d.ts.map +1 -1
  380. package/resources/eval-run/run.js +13 -7
  381. package/resources/eval-run/run.js.map +1 -1
  382. package/resources/file.d.ts +27 -0
  383. package/resources/file.d.ts.map +1 -0
  384. package/resources/file.js +82 -0
  385. package/resources/file.js.map +1 -0
  386. package/resources/get-bindings.d.ts.map +1 -1
  387. package/resources/get-bindings.js +18 -0
  388. package/resources/get-bindings.js.map +1 -1
  389. package/resources/git.d.ts +1 -1
  390. package/resources/git.js +1 -1
  391. package/resources/list.d.ts +21 -2
  392. package/resources/list.d.ts.map +1 -1
  393. package/resources/list.js +148 -31
  394. package/resources/list.js.map +1 -1
  395. package/resources/plugin.d.ts.map +1 -1
  396. package/resources/plugin.js +4 -0
  397. package/resources/plugin.js.map +1 -1
  398. package/resources/provider-key.d.ts +81 -0
  399. package/resources/provider-key.d.ts.map +1 -0
  400. package/resources/provider-key.js +261 -0
  401. package/resources/provider-key.js.map +1 -0
  402. package/resources/reference.d.ts +15 -21
  403. package/resources/reference.d.ts.map +1 -1
  404. package/resources/reference.js +42 -88
  405. package/resources/reference.js.map +1 -1
  406. package/resources/render.d.ts +31 -7
  407. package/resources/render.d.ts.map +1 -1
  408. package/resources/render.js +66 -38
  409. package/resources/render.js.map +1 -1
  410. package/resources/routine.d.ts +21 -5
  411. package/resources/routine.d.ts.map +1 -1
  412. package/resources/routine.js +104 -15
  413. package/resources/routine.js.map +1 -1
  414. package/resources/run/agent-exec.d.ts +12 -2
  415. package/resources/run/agent-exec.d.ts.map +1 -1
  416. package/resources/run/agent-exec.js +85 -38
  417. package/resources/run/agent-exec.js.map +1 -1
  418. package/resources/run/create.d.ts +16 -12
  419. package/resources/run/create.d.ts.map +1 -1
  420. package/resources/run/create.js +14 -15
  421. package/resources/run/create.js.map +1 -1
  422. package/resources/run/engines.d.ts +32 -0
  423. package/resources/run/engines.d.ts.map +1 -0
  424. package/resources/run/engines.js +39 -0
  425. package/resources/run/engines.js.map +1 -0
  426. package/resources/run/environment.d.ts +11 -0
  427. package/resources/run/environment.d.ts.map +1 -0
  428. package/resources/run/environment.js +30 -0
  429. package/resources/run/environment.js.map +1 -0
  430. package/resources/run/epilogue.d.ts +1 -1
  431. package/resources/run/epilogue.d.ts.map +1 -1
  432. package/resources/run/epilogue.js +18 -19
  433. package/resources/run/epilogue.js.map +1 -1
  434. package/resources/run/files.d.ts +104 -0
  435. package/resources/run/files.d.ts.map +1 -0
  436. package/resources/run/files.js +316 -0
  437. package/resources/run/files.js.map +1 -0
  438. package/resources/run/header.d.ts +11 -9
  439. package/resources/run/header.d.ts.map +1 -1
  440. package/resources/run/header.js +14 -14
  441. package/resources/run/header.js.map +1 -1
  442. package/resources/run/prepare.d.ts +31 -25
  443. package/resources/run/prepare.d.ts.map +1 -1
  444. package/resources/run/prepare.js +42 -51
  445. package/resources/run/prepare.js.map +1 -1
  446. package/resources/run/references.d.ts.map +1 -1
  447. package/resources/run/references.js +6 -5
  448. package/resources/run/references.js.map +1 -1
  449. package/resources/run/resolve.js +1 -1
  450. package/resources/run/resolve.js.map +1 -1
  451. package/resources/run/resume.d.ts +3 -1
  452. package/resources/run/resume.d.ts.map +1 -1
  453. package/resources/run/resume.js +25 -10
  454. package/resources/run/resume.js.map +1 -1
  455. package/resources/run/stream.d.ts +34 -2
  456. package/resources/run/stream.d.ts.map +1 -1
  457. package/resources/run/stream.js +92 -8
  458. package/resources/run/stream.js.map +1 -1
  459. package/resources/run/workspace.d.ts +9 -12
  460. package/resources/run/workspace.d.ts.map +1 -1
  461. package/resources/run/workspace.js +29 -36
  462. package/resources/run/workspace.js.map +1 -1
  463. package/resources/run-approve.d.ts.map +1 -1
  464. package/resources/run-approve.js +2 -11
  465. package/resources/run-approve.js.map +1 -1
  466. package/resources/run-control.d.ts +3 -3
  467. package/resources/run-control.d.ts.map +1 -1
  468. package/resources/run-control.js +4 -5
  469. package/resources/run-control.js.map +1 -1
  470. package/resources/run-format.d.ts +2 -2
  471. package/resources/run-format.d.ts.map +1 -1
  472. package/resources/run-format.js +3 -4
  473. package/resources/run-format.js.map +1 -1
  474. package/resources/run-logs.d.ts +2 -0
  475. package/resources/run-logs.d.ts.map +1 -1
  476. package/resources/run-logs.js +16 -6
  477. package/resources/run-logs.js.map +1 -1
  478. package/resources/run-scores.d.ts +6 -2
  479. package/resources/run-scores.d.ts.map +1 -1
  480. package/resources/run-scores.js +7 -4
  481. package/resources/run-scores.js.map +1 -1
  482. package/resources/run-to-eval-case.js +2 -2
  483. package/resources/run-to-eval-case.js.map +1 -1
  484. package/resources/runs.d.ts +3 -3
  485. package/resources/runs.d.ts.map +1 -1
  486. package/resources/runs.js +5 -5
  487. package/resources/runs.js.map +1 -1
  488. package/resources/search.d.ts.map +1 -1
  489. package/resources/search.js +1 -2
  490. package/resources/search.js.map +1 -1
  491. package/resources/service-account.d.ts +2 -0
  492. package/resources/service-account.d.ts.map +1 -1
  493. package/resources/service-account.js +3 -1
  494. package/resources/service-account.js.map +1 -1
  495. package/resources/session.d.ts +4 -3
  496. package/resources/session.d.ts.map +1 -1
  497. package/resources/session.js +10 -7
  498. package/resources/session.js.map +1 -1
  499. package/resources/skill.d.ts +1 -1
  500. package/resources/skill.d.ts.map +1 -1
  501. package/resources/skill.js +7 -8
  502. package/resources/skill.js.map +1 -1
  503. package/resources/stream/answer.d.ts +1 -2
  504. package/resources/stream/answer.d.ts.map +1 -1
  505. package/resources/stream/answer.js +3 -16
  506. package/resources/stream/answer.js.map +1 -1
  507. package/resources/stream/composer.d.ts +16 -0
  508. package/resources/stream/composer.d.ts.map +1 -0
  509. package/resources/stream/composer.js +171 -0
  510. package/resources/stream/composer.js.map +1 -0
  511. package/resources/stream/ink.d.ts +20 -4
  512. package/resources/stream/ink.d.ts.map +1 -1
  513. package/resources/stream/ink.js +34 -3
  514. package/resources/stream/ink.js.map +1 -1
  515. package/resources/stream/render-plaintext.d.ts +1 -0
  516. package/resources/stream/render-plaintext.d.ts.map +1 -1
  517. package/resources/stream/render-plaintext.js +21 -4
  518. package/resources/stream/render-plaintext.js.map +1 -1
  519. package/resources/stream/tty.js +1 -1
  520. package/resources/stream/tty.js.map +1 -1
  521. package/resources/tag.d.ts.map +1 -1
  522. package/resources/tag.js +7 -8
  523. package/resources/tag.js.map +1 -1
  524. package/resources/usage.d.ts +3 -2
  525. package/resources/usage.d.ts.map +1 -1
  526. package/resources/usage.js +19 -16
  527. package/resources/usage.js.map +1 -1
  528. package/resources/validate.d.ts.map +1 -1
  529. package/resources/validate.js +1 -12
  530. package/resources/validate.js.map +1 -1
  531. package/resources/version.d.ts +17 -3
  532. package/resources/version.d.ts.map +1 -1
  533. package/resources/version.js +105 -14
  534. package/resources/version.js.map +1 -1
  535. package/resources/views/agent.d.ts +3 -0
  536. package/resources/views/agent.d.ts.map +1 -0
  537. package/resources/views/agent.js +54 -0
  538. package/resources/views/agent.js.map +1 -0
  539. package/resources/views/environment.d.ts +3 -0
  540. package/resources/views/environment.d.ts.map +1 -0
  541. package/resources/views/environment.js +37 -0
  542. package/resources/views/environment.js.map +1 -0
  543. package/resources/views/index.d.ts +22 -0
  544. package/resources/views/index.d.ts.map +1 -0
  545. package/resources/views/index.js +70 -0
  546. package/resources/views/index.js.map +1 -0
  547. package/resources/views/organization.d.ts +3 -0
  548. package/resources/views/organization.d.ts.map +1 -0
  549. package/resources/views/organization.js +27 -0
  550. package/resources/views/organization.js.map +1 -0
  551. package/resources/views/routine.d.ts +3 -0
  552. package/resources/views/routine.d.ts.map +1 -0
  553. package/resources/views/routine.js +37 -0
  554. package/resources/views/routine.js.map +1 -0
  555. package/resources/views/run.d.ts +3 -0
  556. package/resources/views/run.d.ts.map +1 -0
  557. package/resources/views/run.js +45 -0
  558. package/resources/views/run.js.map +1 -0
  559. package/resources/views/session.d.ts +5 -0
  560. package/resources/views/session.d.ts.map +1 -0
  561. package/resources/views/session.js +85 -0
  562. package/resources/views/session.js.map +1 -0
  563. package/resources/views/skill.d.ts +5 -0
  564. package/resources/views/skill.d.ts.map +1 -0
  565. package/resources/views/skill.js +48 -0
  566. package/resources/views/skill.js.map +1 -0
  567. package/resources/views/view.d.ts +66 -0
  568. package/resources/views/view.d.ts.map +1 -0
  569. package/resources/views/view.js +130 -0
  570. package/resources/views/view.js.map +1 -0
  571. package/resources/views/words.d.ts +52 -0
  572. package/resources/views/words.d.ts.map +1 -0
  573. package/resources/views/words.js +190 -0
  574. package/resources/views/words.js.map +1 -0
  575. package/runtime.d.ts +22 -0
  576. package/runtime.d.ts.map +1 -1
  577. package/runtime.js +33 -2
  578. package/runtime.js.map +1 -1
  579. package/src/auth/auth0.ts +1 -1
  580. package/src/auth/token.ts +136 -26
  581. package/src/client/client.ts +23 -16
  582. package/src/command-tree.ts +152 -0
  583. package/src/commands/access-history/index.ts +15 -2
  584. package/src/commands/agent-exec-flags.ts +11 -5
  585. package/src/commands/apikey/duration.ts +1 -2
  586. package/src/commands/apikey/index.ts +3 -4
  587. package/src/commands/apply.ts +3 -22
  588. package/src/commands/auth/index.ts +7 -5
  589. package/src/commands/auth/whoami.ts +1 -1
  590. package/src/commands/config/index.ts +3 -3
  591. package/src/commands/config/kv.ts +18 -14
  592. package/src/commands/connect.ts +21 -3
  593. package/src/commands/download.ts +106 -62
  594. package/src/commands/eval.ts +22 -21
  595. package/src/commands/file.ts +80 -0
  596. package/src/commands/get.ts +19 -13
  597. package/src/commands/help.ts +182 -0
  598. package/src/commands/internal-daemon.ts +9 -2
  599. package/src/commands/list.ts +22 -1
  600. package/src/commands/logs.ts +1 -1
  601. package/src/commands/mcp-server.ts +57 -28
  602. package/src/commands/provider-key/index.ts +192 -0
  603. package/src/commands/push.ts +8 -8
  604. package/src/commands/resume.ts +20 -12
  605. package/src/commands/routine.ts +58 -5
  606. package/src/commands/run.ts +37 -17
  607. package/src/commands/runs/approve.ts +13 -4
  608. package/src/commands/runs/control.ts +50 -27
  609. package/src/commands/runs/index.ts +1 -2
  610. package/src/commands/runs/logs.ts +9 -5
  611. package/src/commands/runs/to-eval-case.ts +18 -6
  612. package/src/commands/runs/trace.ts +1 -1
  613. package/src/commands/search.ts +2 -3
  614. package/src/commands/service-account/index.ts +7 -2
  615. package/src/commands/session-help.ts +39 -0
  616. package/src/commands/setup.ts +5 -5
  617. package/src/commands/shared.ts +32 -3
  618. package/src/commands/tag.ts +13 -7
  619. package/src/commands/up.ts +55 -21
  620. package/src/commands/validate.ts +2 -2
  621. package/src/commands/version.ts +9 -4
  622. package/src/config/config.ts +66 -69
  623. package/src/config/index.ts +1 -2
  624. package/src/config/keys.ts +4 -4
  625. package/src/config/paths.ts +2 -2
  626. package/src/config/resolve.ts +20 -8
  627. package/src/errors/classify.ts +110 -21
  628. package/src/errors/command-line.ts +95 -0
  629. package/src/errors/handle.ts +2 -2
  630. package/src/errors/index.ts +12 -2
  631. package/src/errors/usage-error.ts +1 -1
  632. package/src/global-options.ts +100 -0
  633. package/src/local/artifact.ts +46 -140
  634. package/src/local/constants.ts +3 -9
  635. package/src/local/daemon/components.ts +78 -22
  636. package/src/local/daemon/env.ts +3 -8
  637. package/src/local/daemon/host.ts +64 -19
  638. package/src/local/daemon/index.ts +2 -1
  639. package/src/local/daemon/launch.ts +251 -72
  640. package/src/local/daemon/process.ts +78 -46
  641. package/src/local/daemon/signals.ts +19 -0
  642. package/src/local/daemon/supervisor.ts +84 -21
  643. package/src/local/daemon/types.ts +8 -4
  644. package/src/local/llm-config.ts +15 -9
  645. package/src/local/logs/view.ts +5 -6
  646. package/src/local/net/tcp.ts +18 -11
  647. package/src/local/paths.ts +2 -3
  648. package/src/local/provider-reach.ts +124 -0
  649. package/src/local/reset.ts +1 -2
  650. package/src/local/runtime/index.ts +1 -2
  651. package/src/local/runtime/node.ts +1 -1
  652. package/src/local/runtime/runner.ts +2 -2
  653. package/src/local/runtime/runtimes-install.ts +1 -1
  654. package/src/local/runtime/server.ts +2 -4
  655. package/src/local/runtime/which.ts +1 -1
  656. package/src/local/setup/wizard.ts +7 -5
  657. package/src/local/state/health-state.ts +10 -2
  658. package/src/local/state/lock.ts +26 -28
  659. package/src/local/state/log-rotation.ts +2 -3
  660. package/src/local/state/pidfile.ts +61 -6
  661. package/src/local/state/proc.ts +104 -1
  662. package/src/local/state/startup-config.ts +2 -2
  663. package/src/local/status.ts +30 -41
  664. package/src/local/temporal/download.ts +31 -9
  665. package/src/local/temporal/index.ts +1 -1
  666. package/src/local/temporal/manager.ts +94 -34
  667. package/src/local/temporal/supervisor.ts +1 -1
  668. package/src/local/webconsole/index.ts +8 -5
  669. package/src/marketplace/github.ts +1 -1
  670. package/src/marketplace/official.ts +1 -1
  671. package/src/output/command-result.ts +14 -2
  672. package/src/output/confirm.ts +2 -3
  673. package/src/output/format.ts +5 -6
  674. package/src/output/index.ts +8 -1
  675. package/src/output/printable.ts +26 -0
  676. package/src/output/proto.ts +3 -4
  677. package/src/output/style.ts +2 -2
  678. package/src/output/table.ts +118 -15
  679. package/src/program.ts +58 -128
  680. package/src/registry/aliases.ts +0 -3
  681. package/src/registry/index.ts +0 -1
  682. package/src/registry/metadata.ts +16 -64
  683. package/src/registry/registry.ts +3 -13
  684. package/src/registry/verb-support.ts +28 -5
  685. package/src/resources/agent/quality.ts +29 -8
  686. package/src/resources/agent/resolve.ts +3 -3
  687. package/src/resources/apply/apply.ts +58 -49
  688. package/src/resources/apply/handlers.ts +3 -4
  689. package/src/resources/channel.ts +3 -4
  690. package/src/resources/connect/connect.ts +2 -2
  691. package/src/resources/delete.ts +44 -4
  692. package/src/resources/documents.ts +1 -1
  693. package/src/resources/download.ts +239 -43
  694. package/src/resources/eval-run/options.ts +38 -17
  695. package/src/resources/eval-run/report.ts +11 -5
  696. package/src/resources/eval-run/run.ts +13 -9
  697. package/src/resources/file.ts +114 -0
  698. package/src/resources/get-bindings.ts +18 -0
  699. package/src/resources/git.ts +1 -1
  700. package/src/resources/list.ts +178 -34
  701. package/src/resources/plugin.ts +3 -0
  702. package/src/resources/provider-key.ts +327 -0
  703. package/src/resources/reference.ts +41 -85
  704. package/src/resources/render.ts +72 -38
  705. package/src/resources/routine.ts +152 -15
  706. package/src/resources/run/agent-exec.ts +95 -44
  707. package/src/resources/run/create.ts +27 -24
  708. package/src/resources/run/engines.ts +57 -0
  709. package/src/resources/run/environment.ts +43 -0
  710. package/src/resources/run/epilogue.ts +18 -17
  711. package/src/resources/run/files.ts +433 -0
  712. package/src/resources/run/header.ts +18 -18
  713. package/src/resources/run/prepare.ts +67 -74
  714. package/src/resources/run/references.ts +6 -5
  715. package/src/resources/run/resolve.ts +1 -1
  716. package/src/resources/run/resume.ts +28 -9
  717. package/src/resources/run/stream.ts +110 -9
  718. package/src/resources/run/workspace.ts +37 -47
  719. package/src/resources/run-approve.ts +2 -14
  720. package/src/resources/run-control.ts +4 -5
  721. package/src/resources/run-format.ts +3 -4
  722. package/src/resources/run-logs.ts +17 -6
  723. package/src/resources/run-scores.ts +14 -4
  724. package/src/resources/run-to-eval-case.ts +2 -2
  725. package/src/resources/runs.ts +5 -5
  726. package/src/resources/search.ts +1 -2
  727. package/src/resources/service-account.ts +4 -1
  728. package/src/resources/session.ts +10 -7
  729. package/src/resources/skill.ts +7 -8
  730. package/src/resources/stream/answer.ts +3 -19
  731. package/src/resources/stream/composer.ts +170 -0
  732. package/src/resources/stream/ink.tsx +74 -10
  733. package/src/resources/stream/render-plaintext.ts +22 -4
  734. package/src/resources/stream/tty.ts +1 -1
  735. package/src/resources/tag.ts +7 -9
  736. package/src/resources/usage.ts +19 -15
  737. package/src/resources/validate.ts +1 -10
  738. package/src/resources/version.ts +117 -15
  739. package/src/resources/views/agent.ts +60 -0
  740. package/src/resources/views/environment.ts +41 -0
  741. package/src/resources/views/index.ts +82 -0
  742. package/src/resources/views/organization.ts +29 -0
  743. package/src/resources/views/routine.ts +39 -0
  744. package/src/resources/views/run.ts +46 -0
  745. package/src/resources/views/session.ts +91 -0
  746. package/src/resources/views/skill.ts +49 -0
  747. package/src/resources/views/view.ts +188 -0
  748. package/src/resources/views/words.ts +191 -0
  749. package/src/runtime.ts +51 -2
  750. package/errors/exit-codes.d.ts +0 -10
  751. package/errors/exit-codes.d.ts.map +0 -1
  752. package/errors/exit-codes.js +0 -15
  753. package/errors/exit-codes.js.map +0 -1
  754. package/resources/run/attachments.d.ts +0 -24
  755. package/resources/run/attachments.d.ts.map +0 -1
  756. package/resources/run/attachments.js +0 -237
  757. package/resources/run/attachments.js.map +0 -1
  758. package/src/errors/exit-codes.ts +0 -17
  759. package/src/resources/run/attachments.ts +0 -300
  760. package/src/types/marked-terminal.d.ts +0 -31
@@ -13,12 +13,25 @@
13
13
  // uses it to show the stack's output in the terminal — or in `docker logs` —
14
14
  // while the log files keep receiving the same bytes. The detached daemon
15
15
  // installs no mirror: its own stdout is already redirected to daemon.log.
16
+ //
17
+ // A child counts as exited only once its output is in: on the stdio `close`,
18
+ // or a short grace after `exit` when a grandchild keeps the pipe open. Node
19
+ // fires `exit` before the last chunks arrive, so observing it there would end
20
+ // the log stream under a late write and drop the child's final words. Those
21
+ // words are what a failed start is explained by: the host keeps the last few
22
+ // stderr lines, which the supervisor records beside the failure (stigmer#1845).
16
23
 
17
24
  import { spawn } from "node:child_process";
18
25
  import { createWriteStream } from "node:fs";
19
26
  import { killProcessGroup } from "../state/proc.js";
20
27
  import type { ChildHandle, Clock, ExitInfo, ProcessHost, SpawnRequest } from "./types.js";
21
28
 
29
+ /** How long after `exit` the host waits for the child's stdio to close. */
30
+ export const EXIT_OUTPUT_GRACE_MS = 500;
31
+ /** How many trailing stderr lines a handle keeps, and how long each may be. */
32
+ export const STDERR_TAIL_LINES = 10;
33
+ export const STDERR_TAIL_LINE_MAX = 1024;
34
+
22
35
  /** Receives one complete output line from a child, with the component that wrote it. */
23
36
  export type OutputMirror = (component: string, line: string) => void;
24
37
 
@@ -42,7 +55,7 @@ export class NodeProcessHost implements ProcessHost {
42
55
  stdio: ["ignore", "pipe", "pipe"],
43
56
  });
44
57
 
45
- let exited = false;
58
+ let exitInfo: ExitInfo | null = null;
46
59
  let exitCb: ((info: ExitInfo) => void) | null = null;
47
60
  let readyCb: (() => void) | null = null;
48
61
  let ready = false;
@@ -54,8 +67,14 @@ export class NodeProcessHost implements ProcessHost {
54
67
  // streams interleave, so each keeps its own partial line.
55
68
  const mirrorStdout = this.lineMirror(request.name);
56
69
  const mirrorStderr = this.lineMirror(request.name);
70
+ const stderrTail: string[] = [];
71
+ const keepStderr = lineAssembler((line) => {
72
+ stderrTail.push(line.length > STDERR_TAIL_LINE_MAX ? `${line.slice(0, STDERR_TAIL_LINE_MAX)}…` : line);
73
+ if (stderrTail.length > STDERR_TAIL_LINES) stderrTail.shift();
74
+ });
57
75
 
58
76
  child.stdout?.on("data", (chunk: Buffer) => {
77
+ if (exitInfo !== null) return;
59
78
  out.write(chunk);
60
79
  mirrorStdout(chunk);
61
80
  if (marker !== undefined && !ready) {
@@ -67,27 +86,47 @@ export class NodeProcessHost implements ProcessHost {
67
86
  }
68
87
  });
69
88
  child.stderr?.on("data", (chunk: Buffer) => {
89
+ if (exitInfo !== null) return;
70
90
  out.write(chunk);
71
91
  mirrorStderr(chunk);
92
+ keepStderr(chunk);
72
93
  });
73
94
 
74
- child.on("exit", (code, signal) => {
75
- exited = true;
95
+ // The one place a child becomes exited, whichever of `error`, `exit` and
96
+ // `close` arrives, and in whatever order: once only.
97
+ let grace: NodeJS.Timeout | null = null;
98
+ const observeExit = (info: ExitInfo): void => {
99
+ if (exitInfo !== null) return;
100
+ if (grace !== null) clearTimeout(grace);
76
101
  mirrorStdout(null);
77
102
  mirrorStderr(null);
103
+ keepStderr(null);
78
104
  out.end();
79
- exitCb?.({ code, signal });
105
+ exitInfo = info;
106
+ exitCb?.(info);
107
+ };
108
+
109
+ let exitEvent: ExitInfo | null = null;
110
+ child.on("exit", (code, signal) => {
111
+ exitEvent = { code, signal };
112
+ const info = exitEvent;
113
+ grace = setTimeout(() => observeExit(info), EXIT_OUTPUT_GRACE_MS);
114
+ grace.unref();
80
115
  });
116
+ child.on("close", (code, signal) => observeExit(exitEvent ?? { code, signal }));
81
117
  child.on("error", (err) => {
82
- out.write(`failed to spawn ${request.command}: ${String(err)}\n`);
83
- exited = true;
84
- exitCb?.({ code: null, signal: null });
118
+ const line = `failed to spawn ${request.command}: ${String(err)}`;
119
+ out.write(`${line}\n`);
120
+ keepStderr(Buffer.from(`${line}\n`));
121
+ observeExit({ code: null, signal: null });
85
122
  });
86
123
 
87
124
  const pid = child.pid ?? -1;
88
125
  return {
89
126
  pid,
90
- hasExited: () => exited,
127
+ hasExited: () => exitInfo !== null,
128
+ exitInfo: () => exitInfo,
129
+ stderrTail: () => [...stderrTail],
91
130
  onExit: (cb) => {
92
131
  exitCb = cb;
93
132
  },
@@ -107,20 +146,26 @@ export class NodeProcessHost implements ProcessHost {
107
146
  private lineMirror(component: string): (chunk: Buffer | null) => void {
108
147
  const mirror = this.mirror;
109
148
  if (mirror === undefined) return () => {};
110
- let partial = "";
111
- return (chunk) => {
112
- if (chunk === null) {
113
- if (partial !== "") mirror(component, partial);
114
- partial = "";
115
- return;
116
- }
117
- const lines = (partial + chunk.toString("utf8")).split("\n");
118
- partial = lines.pop() ?? "";
119
- for (const line of lines) mirror(component, line);
120
- };
149
+ return lineAssembler((line) => mirror(component, line));
121
150
  }
122
151
  }
123
152
 
153
+ // Assemble complete lines from a byte stream and hand each to `onLine`. A
154
+ // `null` chunk flushes the trailing partial line.
155
+ function lineAssembler(onLine: (line: string) => void): (chunk: Buffer | null) => void {
156
+ let partial = "";
157
+ return (chunk) => {
158
+ if (chunk === null) {
159
+ if (partial !== "") onLine(partial);
160
+ partial = "";
161
+ return;
162
+ }
163
+ const lines = (partial + chunk.toString("utf8")).split("\n");
164
+ partial = lines.pop() ?? "";
165
+ for (const line of lines) onLine(line);
166
+ };
167
+ }
168
+
124
169
  /** Real wall-clock implementation of Clock. */
125
170
  export const systemClock: Clock = {
126
171
  now: () => Date.now(),
@@ -4,7 +4,8 @@ export { buildComponents, buildRunnerEnv, buildServerEnv } from "./components.js
4
4
  export { type DaemonConfig, type DaemonEnvInputs, DaemonEnvVar, buildDaemonEnv, readDaemonConfig } from "./env.js";
5
5
  export { NodeProcessHost, type NodeProcessHostOptions, type OutputMirror, systemClock } from "./host.js";
6
6
  export { down, isRunning, type UpForegroundDeps, type UpOptions, up, upForeground } from "./launch.js";
7
- export { type InternalDaemonDeps, type TemporalControl, runInternalDaemon, waitForShutdownSignal } from "./process.js";
7
+ export { type InternalDaemonDeps, type TemporalControl, runInternalDaemon } from "./process.js";
8
+ export { shutdownOnSignals } from "./signals.js";
8
9
  export {
9
10
  HEALTH_CHECK_INTERVAL_MS,
10
11
  MAX_RESTARTS,
@@ -9,6 +9,18 @@
9
9
  // answers; the foreground shape calls the same daemon body in-process, which
10
10
  // is what a container entrypoint, a systemd unit or a tmux pane wants: one
11
11
  // process to watch, signals delivered to it, the stack's output on its stdio.
12
+ //
13
+ // When the stack does not start, both shapes say why from the daemon's own
14
+ // record, the health snapshot `stigmer status` reads: which component failed,
15
+ // how, and its last stderr lines (stigmer#1845). The detached shape watches
16
+ // the daemon for the whole wait, so a start that has given up is reported at
17
+ // once, not when the wait runs out.
18
+ //
19
+ // A running stack is never touched by `up`: it refuses while the daemon on
20
+ // record lives, and sweeps only a dead daemon's leftovers. `down` reports a
21
+ // stack stopped only once nothing of it is left: the daemon's own teardown,
22
+ // then one sweep of whatever a daemon that died untidily left behind, waiting
23
+ // for each leftover to exit (stigmer#1175).
12
24
 
13
25
  import { spawn } from "node:child_process";
14
26
  import { mkdirSync, openSync } from "node:fs";
@@ -17,12 +29,13 @@ import { join } from "node:path";
17
29
  import { type Config, load as loadConfig } from "../../config/config.js";
18
30
  import { log } from "../../logger.js";
19
31
  import { CliExitError } from "../../errors/cli-exit-error.js";
20
- import { ExitCode } from "../../errors/exit-codes.js";
21
- import { DAEMON_PID_FILE, SERVER_PORT } from "../constants.js";
32
+ import { ExitCode } from "@stigmer/client/exit-codes";
33
+ import { DAEMON_PID_FILE, HEALTH_STATE_FILE, SERVER_PORT } from "../constants.js";
22
34
  import { tcpConnects, waitForTcp } from "../net/tcp.js";
23
35
  import { dataDir, logDir } from "../paths.js";
24
- import { readPidFile, removePidFile } from "../state/pidfile.js";
25
- import { findProcessByPort, isOtherLiveProcess, isProcessAlive, killProcess } from "../state/proc.js";
36
+ import { componentLogsHint, loadHealthState } from "../state/health-state.js";
37
+ import { readPidRecord, recordedLiveProcess, removePidFile } from "../state/pidfile.js";
38
+ import { findProcessByPort, isOtherLiveProcess, isProcessAlive, killProcess, processCommand } from "../state/proc.js";
26
39
  import { type StartupConfig, removeStartupConfig, saveStartupConfig } from "../state/startup-config.js";
27
40
  import { rotateLogs } from "../state/log-rotation.js";
28
41
  import { resolveApiKey, resolveProvider } from "../llm-config.js";
@@ -30,14 +43,19 @@ import { resolveOperatorIdentity } from "../operator-config.js";
30
43
  import { ensureRunner } from "../runtime/runner.js";
31
44
  import { ensureServer } from "../runtime/server.js";
32
45
  import { TemporalManager } from "../temporal/manager.js";
46
+ import type { ProviderReach } from "../provider-reach.js";
47
+ import { localRunnerReach } from "./components.js";
33
48
  import { buildDaemonEnv, type DaemonEnvInputs, readDaemonConfig } from "./env.js";
34
49
  import { NodeProcessHost, type OutputMirror } from "./host.js";
35
- import { type InternalDaemonDeps, runInternalDaemon, waitForShutdownSignal } from "./process.js";
50
+ import { type InternalDaemonDeps, runInternalDaemon } from "./process.js";
51
+ import { shutdownOnSignals } from "./signals.js";
52
+ import { GRACEFUL_STOP_TIMEOUT_MS } from "./supervisor.js";
36
53
 
37
54
  /** How long `up` waits for the server's gRPC port after spawning the daemon. */
38
55
  const READY_TIMEOUT_MS = 60_000;
39
- /** How long to wait for the daemon to come up before checking it is still alive. */
40
- const DAEMON_SETTLE_MS = 3_000;
56
+ /** The components whose failure stops the stack, in start order: the first
57
+ * one recorded failed is the one a failed start names. */
58
+ const CRITICAL_COMPONENTS = ["temporal", "stigmer-server"] as const;
41
59
  /** How long `down` waits for graceful daemon exit before force-killing. */
42
60
  const STOP_TIMEOUT_MS = 15_000;
43
61
  const STOP_POLL_MS = 500;
@@ -47,6 +65,17 @@ export interface UpOptions {
47
65
  noWeb?: boolean;
48
66
  }
49
67
 
68
+ /** What a started stack reports to the person who started it (`stigmer up`'s card). */
69
+ export interface UpReport {
70
+ /**
71
+ * The providers the stack's runner reaches, judged over the environment
72
+ * the daemon gives it (the value the server was handed as
73
+ * STIGMER_RUNNER_PROVIDERS, unless the operator exported one), or
74
+ * undefined when the stack starts no runner.
75
+ */
76
+ readonly runnerReach: readonly ProviderReach[] | undefined;
77
+ }
78
+
50
79
  /** Everything both `up` shapes need once the heavy resolution is done. */
51
80
  interface PreparedLaunch {
52
81
  data: string;
@@ -56,34 +85,101 @@ interface PreparedLaunch {
56
85
  }
57
86
 
58
87
  /** Start the local stack in the background. Throws on any startup failure. */
59
- export async function up(options: UpOptions = {}, home: string = homedir()): Promise<void> {
88
+ export async function up(options: UpOptions = {}, home: string = homedir()): Promise<UpReport> {
60
89
  const { data, logs, temporalAddress, env } = await prepareLaunch(options, home);
61
90
 
62
91
  const daemonPid = spawnDaemon(env, join(logs, "daemon.log"));
63
92
  log.info("daemon process started", { pid: daemonPid });
64
93
 
65
- await sleep(DAEMON_SETTLE_MS);
66
- if (!isProcessAlive(daemonPid)) {
67
- throw new CliExitError("daemon process crashed during startup", ExitCode.General, [
68
- `Check ${join(logs, "daemon.log")} for details.`,
69
- ]);
94
+ /* v8 ignore next -- @preserve: up() spawns the real daemon, which no unit test starts; waitForStack has its own tests, and the cli-up lane runs this end to end */
95
+ await waitForStack({ data, logs, daemonPid });
96
+
97
+ saveStartupConfig(data, buildStartupConfig(data, logs, temporalAddress, daemonPid, options));
98
+ /* v8 ignore next -- @preserve: up() spawns the real daemon, which no unit test starts; the cli-up lane's smoke-getting-started runs it end to end, and upReport has its own tests */
99
+ return upReport(env);
100
+ }
101
+
102
+ /** What waitForStack watches: the detached daemon, and where it records. */
103
+ export interface StackWait {
104
+ data: string;
105
+ logs: string;
106
+ daemonPid: number;
107
+ /** Default SERVER_PORT; injectable for tests. */
108
+ port?: number;
109
+ /** Default READY_TIMEOUT_MS; injectable for tests. */
110
+ timeoutMs?: number;
111
+ }
112
+
113
+ /**
114
+ * Wait until the server answers, watching the daemon the whole time: the
115
+ * daemon exits as soon as a critical component fails, so its exit ends the
116
+ * wait at once, with the reason it recorded. Throws the failure, or, with no
117
+ * record, says the daemon died (its log has the rest) or that the wait ran out.
118
+ */
119
+ export async function waitForStack(wait: StackWait): Promise<void> {
120
+ const { data, logs, daemonPid } = wait;
121
+ try {
122
+ await waitForTcp({
123
+ port: wait.port ?? SERVER_PORT,
124
+ timeoutMs: wait.timeoutMs ?? READY_TIMEOUT_MS,
125
+ label: "stigmer-server",
126
+ getExit: () => (isProcessAlive(daemonPid) ? null : { code: null, signal: null }),
127
+ });
128
+ } catch (err) {
129
+ const failure = startupFailure(data, daemonPid);
130
+ if (failure !== null) throw failure;
131
+ if (!isProcessAlive(daemonPid)) {
132
+ throw new CliExitError("daemon process crashed during startup", ExitCode.General, [
133
+ `Check ${join(logs, "daemon.log")} for details.`,
134
+ ]);
135
+ }
136
+ throw err;
70
137
  }
138
+ }
71
139
 
72
- await waitForTcp({ port: SERVER_PORT, timeoutMs: READY_TIMEOUT_MS, label: "stigmer-server" });
140
+ /**
141
+ * Why the stack did not start, from the daemon's own record: the first
142
+ * critical component recorded failed, how it failed, its last stderr lines and
143
+ * where its full log is. Null when there is no such record from this daemon
144
+ * (`daemonPid`): one left by an earlier run never speaks for this one.
145
+ */
146
+ export function startupFailure(data: string, daemonPid: number): CliExitError | null {
147
+ const snapshot = loadHealthState(join(data, HEALTH_STATE_FILE));
148
+ if (snapshot === null || snapshot.daemon_pid !== daemonPid) return null;
149
+ for (const name of CRITICAL_COMPONENTS) {
150
+ const component = snapshot.components[name];
151
+ if (component?.state !== "failed") continue;
152
+ const output = (component.last_output ?? []).map((line) => ` ${line}`);
153
+ return new CliExitError(`${name} did not start: ${component.last_error ?? "it failed"}`, ExitCode.General, [
154
+ ...output,
155
+ componentLogsHint(name),
156
+ ]);
157
+ }
158
+ return null;
159
+ }
73
160
 
74
- saveStartupConfig(data, buildStartupConfig(data, logs, temporalAddress, daemonPid, options));
161
+ // The daemon reads its configuration from the very environment the launcher
162
+ // built, so reading it here gives the runner environment the daemon builds.
163
+ function upReport(env: NodeJS.ProcessEnv): UpReport {
164
+ return { runnerReach: localRunnerReach(readDaemonConfig(env), env) };
75
165
  }
76
166
 
77
167
  /** Seams of the foreground launcher, injectable for tests. */
78
168
  export interface UpForegroundDeps {
79
169
  /** The daemon body (default: the real one). */
80
170
  runDaemon?: (deps: InternalDaemonDeps) => Promise<number>;
81
- /** Resolves when the stack should shut down (default: the first SIGTERM/SIGINT). */
82
- waitForShutdown?: () => Promise<void>;
171
+ /**
172
+ * Aborted when the stack should stop (default: the first SIGTERM/SIGINT,
173
+ * armed just before the daemon body starts, so a Ctrl-C while dependencies
174
+ * are still resolving ends the launcher at once, as it always has).
175
+ */
176
+ shutdown?: AbortSignal;
83
177
  /** Receives each line the server and runner write (default: a `[component]`-prefixed stdout mirror). */
84
178
  mirror?: OutputMirror;
85
- /** Invoked once the stack is serving — the moment a detached `up` would have returned. */
86
- onReady?: () => void | Promise<void>;
179
+ /** Invoked once the stack is serving — the moment a detached `up` would have returned — with what it reports. */
180
+ onReady?: (report: UpReport) => void | Promise<void>;
181
+ /** The port the stack's server listens on, refused when already held (default SERVER_PORT). */
182
+ serverPort?: number;
87
183
  }
88
184
 
89
185
  /**
@@ -104,18 +200,19 @@ export async function upForeground(
104
200
  home: string = homedir(),
105
201
  deps: UpForegroundDeps = {},
106
202
  ): Promise<number> {
107
- const { data, logs, temporalAddress, env } = await prepareLaunch(options, home);
203
+ const { data, logs, temporalAddress, env } = await prepareLaunch(options, home, deps.serverPort);
108
204
  const runDaemon = deps.runDaemon ?? runInternalDaemon;
109
205
 
110
206
  return runDaemon({
111
207
  config: readDaemonConfig(env),
112
208
  env,
113
209
  host: new NodeProcessHost({ mirror: deps.mirror ?? mirrorToStdout }),
114
- waitForShutdown: deps.waitForShutdown ?? waitForShutdownSignal,
210
+ shutdown: deps.shutdown ?? shutdownOnSignals(),
115
211
  onStarted: async () => {
116
212
  saveStartupConfig(data, buildStartupConfig(data, logs, temporalAddress, process.pid, options));
117
- await deps.onReady?.();
213
+ await deps.onReady?.(upReport(env));
118
214
  },
215
+ serverPort: deps.serverPort,
119
216
  });
120
217
  }
121
218
 
@@ -129,14 +226,13 @@ const mirrorToStdout: OutputMirror = (component, line) => {
129
226
  // The part of `up` that is the same whether the daemon then runs detached or
130
227
  // right here: refuse a second stack, prepare the state dirs, resolve every
131
228
  // heavy dependency, and encode the launcher→daemon contract.
132
- async function prepareLaunch(options: UpOptions, home: string): Promise<PreparedLaunch> {
229
+ async function prepareLaunch(options: UpOptions, home: string, serverPort: number = SERVER_PORT): Promise<PreparedLaunch> {
133
230
  const data = dataDir(home);
134
231
  const logs = logDir(home);
135
232
 
136
- cleanupOrphans(data);
137
- if (await isRunning(home)) {
138
- throw new CliExitError("daemon is already running", ExitCode.General);
139
- }
233
+ refuseRunningStack(data);
234
+ await cleanupOrphans(data);
235
+ await refuseHeldPort(serverPort);
140
236
 
141
237
  mkdirSync(data, { recursive: true });
142
238
  mkdirSync(logs, { recursive: true });
@@ -174,16 +270,23 @@ async function prepareLaunch(options: UpOptions, home: string): Promise<Prepared
174
270
  return { data, logs, temporalAddress: temporal.address, env };
175
271
  }
176
272
 
177
- /** Stop the local stack. Returns false if nothing was running. */
178
- export async function down(home: string = homedir()): Promise<boolean> {
273
+ /**
274
+ * Stop the local stack. Returns false if nothing was running. `serverPort` is
275
+ * where to look for a stack whose daemon left no PID file; tests move it off
276
+ * the real port.
277
+ */
278
+ export async function down(home: string = homedir(), serverPort: number = SERVER_PORT): Promise<boolean> {
179
279
  const data = dataDir(home);
180
- let pid = readPidFile(join(data, DAEMON_PID_FILE));
181
- if (pid === null) pid = findProcessByPort(SERVER_PORT);
280
+ // A daemon on record is signalled only while it is the process recorded; a
281
+ // record naming another program now is stale, like a dead one. With no
282
+ // record at all, the server port's holder is the stack only when it is a
283
+ // Stigmer process (the rule refuseHeldPort applies to the same port).
284
+ const pidPath = join(data, DAEMON_PID_FILE);
285
+ const pid = readPidRecord(pidPath) === null ? stigmerPortHolder(serverPort) : recordedLiveProcess(pidPath);
182
286
 
183
287
  if (pid === null || !isOtherLiveProcess(pid)) {
184
- removePidFile(join(data, DAEMON_PID_FILE));
185
- await stopManagedTemporal(home);
186
- cleanupOrphans(data);
288
+ removePidFile(pidPath);
289
+ await clearLeftovers(home, data);
187
290
  return false;
188
291
  }
189
292
 
@@ -191,34 +294,80 @@ export async function down(home: string = homedir()): Promise<boolean> {
191
294
  killProcess(pid, "SIGTERM");
192
295
  log.info("sent SIGTERM to daemon", { pid });
193
296
 
194
- const deadline = Date.now() + STOP_TIMEOUT_MS;
195
- while (Date.now() < deadline) {
196
- if (!isProcessAlive(pid)) {
197
- removePidFile(join(data, DAEMON_PID_FILE));
198
- removeStartupConfig(data);
199
- return true;
200
- }
201
- await sleep(STOP_POLL_MS);
297
+ if (!(await waitForExit(pid, STOP_TIMEOUT_MS))) {
298
+ log.warn("daemon did not stop gracefully, force killing", { pid });
299
+ killProcess(pid, "SIGKILL");
202
300
  }
203
-
204
- log.warn("daemon did not stop gracefully, force killing", { pid });
205
- killProcess(pid, "SIGKILL");
206
- removePidFile(join(data, DAEMON_PID_FILE));
301
+ removePidFile(pidPath);
207
302
  removeStartupConfig(data);
208
- await stopManagedTemporal(home);
209
- cleanupOrphans(data);
303
+ // Nothing to do after a clean teardown; after a forced one, or a daemon that
304
+ // could not finish its own, this is what stops the rest.
305
+ await clearLeftovers(home, data);
210
306
  return true;
211
307
  }
212
308
 
213
- /** Whether the daemon is running: a live peer's PID, else a server-port fallback. */
214
- export async function isRunning(home: string = homedir()): Promise<boolean> {
215
- const data = dataDir(home);
216
- const pid = readPidFile(join(data, DAEMON_PID_FILE));
217
- if (pid !== null) {
218
- if (isOtherLiveProcess(pid)) return true;
219
- removePidFile(join(data, DAEMON_PID_FILE)); // stale (dead, or a previous life of our own PID)
309
+ /**
310
+ * Whether the daemon is running: the live daemon on record, else a server-port
311
+ * fallback. `serverPort` is that port; tests move it off the real one.
312
+ */
313
+ export async function isRunning(home: string = homedir(), serverPort: number = SERVER_PORT): Promise<boolean> {
314
+ const pidPath = join(dataDir(home), DAEMON_PID_FILE);
315
+ if (recordedLiveProcess(pidPath) !== null) return true;
316
+ removePidFile(pidPath); // stale (dead, a previous life of our own PID, or another program now)
317
+ return tcpConnects(serverPort, "127.0.0.1", 1000);
318
+ }
319
+
320
+ // The process holding the server's port when its command line names Stigmer;
321
+ // null for nothing, or for another program, which `down` leaves alone.
322
+ function stigmerPortHolder(port: number): number | null {
323
+ const holder = findProcessByPort(port);
324
+ if (holder === null) return null;
325
+ const command = processCommand(holder);
326
+ if (command !== null && command.includes("stigmer")) return holder;
327
+ log.info(`port ${port} is held by a program that is not Stigmer; leaving it alone`, {
328
+ pid: holder,
329
+ ...(command === null ? {} : { command: shorten(command) }),
330
+ });
331
+ return null;
332
+ }
333
+
334
+ // Refuse to start beside a stack that is running, still starting or still
335
+ // stopping: the daemon on record is alive. Nothing is touched; `down` is the
336
+ // one way to stop it. A recorded PID that is dead, our own, or names another
337
+ // program now is a leftover, never a stack: its record is dropped here, so the
338
+ // sweep after (cleanupOrphans) neither re-reads nor re-reports it.
339
+ function refuseRunningStack(data: string): void {
340
+ const pidPath = join(data, DAEMON_PID_FILE);
341
+ const pid = recordedLiveProcess(pidPath);
342
+ if (pid === null) {
343
+ removePidFile(pidPath);
344
+ return;
220
345
  }
221
- return tcpConnects(SERVER_PORT, "127.0.0.1", 1000);
346
+ throw new CliExitError(`the local Stigmer stack is already running (daemon pid ${pid})`, ExitCode.General, [
347
+ "Stop it with: stigmer down",
348
+ ]);
349
+ }
350
+
351
+ // Refuse to start beside whatever already answers on the server's port: an
352
+ // earlier stack still up, or another program. A server started beside it would
353
+ // die on "address in use" while its readiness checks connected to the other
354
+ // program, so this is refused before anything starts, naming the holder.
355
+ // `stigmer down` is offered only for a Stigmer process, the only holder it
356
+ // stops when no daemon PID file names the stack.
357
+ async function refuseHeldPort(port: number): Promise<void> {
358
+ if (!(await tcpConnects(port, "127.0.0.1", 1000))) return;
359
+ const holder = findProcessByPort(port);
360
+ const command = holder === null ? null : processCommand(holder);
361
+ const named = holder === null ? "" : ` by pid ${holder}${command === null ? "" : ` (${shorten(command)})`}`;
362
+ const hint =
363
+ command !== null && command.includes("stigmer")
364
+ ? "It looks like an earlier Stigmer stack; stop it with: stigmer down"
365
+ : "Stop the program holding it, then run stigmer up again.";
366
+ throw new CliExitError(`port ${port} is already in use${named}`, ExitCode.General, [hint]);
367
+ }
368
+
369
+ function shorten(command: string): string {
370
+ return command.length > 120 ? `${command.slice(0, 119)}…` : command;
222
371
  }
223
372
 
224
373
  // Re-exec this CLI as the detached internal-daemon, returning its PID. Replaying
@@ -241,21 +390,50 @@ function spawnDaemon(env: NodeJS.ProcessEnv, daemonLog: string): number {
241
390
  return child.pid;
242
391
  }
243
392
 
244
- // Kill any daemon/server/runner left alive by a previous, improperly-stopped
245
- // run. A recorded PID that is our own is a leftover, never a peer (the fresh
246
- // PID namespace of a restarted container hands the launcher the PID its last
247
- // life had) — signalling it would be signalling ourselves.
248
- function cleanupOrphans(data: string): void {
249
- for (const name of [DAEMON_PID_FILE, "stigmer-server.pid", "runner.pid"]) {
250
- const pidPath = join(data, name);
251
- const pid = readPidFile(pidPath);
252
- if (pid === null) continue;
253
- if (isOtherLiveProcess(pid)) {
254
- log.warn("killing orphaned process from a previous run", { file: name, pid });
255
- killProcess(pid, "SIGTERM");
256
- }
257
- removePidFile(pidPath);
393
+ // Stop whatever a daemon that is gone left behind, in reverse start order: the
394
+ // recorded children, then managed Temporal.
395
+ async function clearLeftovers(home: string, data: string): Promise<void> {
396
+ await cleanupOrphans(data);
397
+ await stopManagedTemporal(home);
398
+ }
399
+
400
+ // Stop any daemon/server/runner left alive by a previous, improperly-stopped
401
+ // run, and return once each has exited: SIGTERM, then SIGKILL after the
402
+ // supervisor's grace, all in parallel, so a caller that next binds the
403
+ // server's port never races a dying server. Only the recorded PID is
404
+ // signalled, never its group, and only while it is the process recorded
405
+ // (recordedLiveProcess): a reused PID now naming another program is left
406
+ // alone and its file removed (stigmer#2750). A recorded PID that is our own is
407
+ // a leftover, never a peer (the fresh PID namespace of a restarted container
408
+ // hands the launcher the PID its last life had) — signalling it would be
409
+ // signalling ourselves.
410
+ async function cleanupOrphans(data: string): Promise<void> {
411
+ await Promise.all(
412
+ [DAEMON_PID_FILE, "stigmer-server.pid", "runner.pid"].map(async (name) => {
413
+ const pidPath = join(data, name);
414
+ const pid = recordedLiveProcess(pidPath);
415
+ if (pid !== null) {
416
+ log.warn("stopping orphaned process from a previous run", { file: name, pid });
417
+ killProcess(pid, "SIGTERM");
418
+ if (!(await waitForExit(pid, GRACEFUL_STOP_TIMEOUT_MS))) {
419
+ log.warn("orphaned process did not stop gracefully, force killing", { file: name, pid });
420
+ killProcess(pid, "SIGKILL");
421
+ await waitForExit(pid, GRACEFUL_STOP_TIMEOUT_MS);
422
+ }
423
+ }
424
+ removePidFile(pidPath);
425
+ }),
426
+ );
427
+ }
428
+
429
+ // Poll until `pid` has exited; false if it outlives `timeoutMs`.
430
+ async function waitForExit(pid: number, timeoutMs: number): Promise<boolean> {
431
+ const deadline = Date.now() + timeoutMs;
432
+ while (isProcessAlive(pid)) {
433
+ if (Date.now() >= deadline) return false;
434
+ await sleep(STOP_POLL_MS);
258
435
  }
436
+ return true;
259
437
  }
260
438
 
261
439
  async function stopManagedTemporal(home: string): Promise<void> {
@@ -270,8 +448,9 @@ async function stopManagedTemporal(home: string): Promise<void> {
270
448
  // the config file, so the launcher must write it into the daemon contract explicitly
271
449
  // — unlike a shell-exported key, it cannot flow by env inheritance. resolveApiKey's
272
450
  // precedence (env var > config file) makes both cases one code path; when the env
273
- // var is set this re-writes the same value. Anthropic is the only provider the
274
- // local stack executes on, so it is the only key with a persisted delivery path.
451
+ // var is set this re-writes the same value. The Anthropic key is the one `stigmer
452
+ // setup` saves, so it is the only key with a persisted delivery path; the runner
453
+ // reaches other providers through the environment it inherits.
275
454
  function resolveLlmKeyInputs(config: Config): Pick<DaemonEnvInputs, "anthropicApiKey"> {
276
455
  if (resolveProvider(config) !== "anthropic") return {};
277
456
  const key = resolveApiKey(config);