@neta-art/cohub-cli 10.23.0 → 10.25.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 (369) hide show
  1. package/README.md +18 -5
  2. package/bin/cohub.js +4 -1
  3. package/dist/board-gpu/page.js +1566 -71230
  4. package/dist/bootstrap.js +67 -27
  5. package/dist/build.json +1 -1
  6. package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
  7. package/dist/chunks/about.js +102 -0
  8. package/dist/chunks/app-realtime.js +2216 -0
  9. package/dist/chunks/app-realtime2.js +2 -0
  10. package/dist/chunks/app-ref.js +88 -0
  11. package/dist/chunks/apps.js +1423 -0
  12. package/dist/chunks/auth.js +175 -0
  13. package/dist/chunks/avatar.js +146 -0
  14. package/dist/chunks/board-export-resources.js +232 -0
  15. package/dist/chunks/board-export.js +874 -0
  16. package/dist/chunks/board-export2.js +2 -0
  17. package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
  18. package/dist/chunks/board-kernel2.js +4 -0
  19. package/dist/chunks/board-profile.js +69 -0
  20. package/dist/chunks/board-simulate.js +315 -0
  21. package/dist/chunks/board-time.js +34 -0
  22. package/dist/chunks/boards.js +1943 -0
  23. package/dist/{board-kernel → chunks}/browserAll.js +9 -8
  24. package/dist/chunks/channels.js +64 -0
  25. package/dist/chunks/client.js +12606 -0
  26. package/dist/chunks/command-input.js +17 -0
  27. package/dist/chunks/commander.js +2962 -0
  28. package/dist/chunks/cron-jobs.js +163 -0
  29. package/dist/chunks/daemon.js +545 -0
  30. package/dist/chunks/daemon2.js +2 -0
  31. package/dist/chunks/desktop.js +172 -0
  32. package/dist/chunks/endpoint-options.js +26 -0
  33. package/dist/chunks/env-proxy.js +35 -0
  34. package/dist/chunks/environment.js +154 -0
  35. package/dist/chunks/feedback.js +120 -0
  36. package/dist/chunks/generations.js +379 -0
  37. package/dist/chunks/host.js +9 -0
  38. package/dist/chunks/http-put.js +131 -0
  39. package/dist/chunks/id.js +2416 -0
  40. package/dist/{board-kernel → chunks}/init.js +1 -1
  41. package/dist/chunks/install.js +11959 -0
  42. package/dist/chunks/launch.js +374 -0
  43. package/dist/chunks/local-media.js +47 -0
  44. package/dist/chunks/me.js +134 -0
  45. package/dist/chunks/media.js +315 -0
  46. package/dist/chunks/models.js +242 -0
  47. package/dist/chunks/operands.js +46 -0
  48. package/dist/chunks/package-paths.js +13 -0
  49. package/dist/chunks/policy.js +221 -0
  50. package/dist/chunks/preferences.js +29 -0
  51. package/dist/chunks/profile.js +64 -0
  52. package/dist/chunks/prompts.js +41 -0
  53. package/dist/chunks/public.js +2 -0
  54. package/dist/chunks/public2.js +244 -0
  55. package/dist/chunks/references.js +197 -0
  56. package/dist/chunks/referrals.js +90 -0
  57. package/dist/chunks/rolldown-runtime.js +26 -0
  58. package/dist/chunks/rooms-connect.js +2 -0
  59. package/dist/chunks/rooms-connect2.js +151 -0
  60. package/dist/chunks/rooms-rtc.js +309 -0
  61. package/dist/chunks/rooms.js +211 -0
  62. package/dist/chunks/run.js +220 -0
  63. package/dist/chunks/runtime.js +638 -0
  64. package/dist/chunks/runtime2.js +286 -0
  65. package/dist/chunks/runtimes.js +48 -0
  66. package/dist/chunks/safe-remote-image.js +198 -0
  67. package/dist/chunks/schemas.js +6017 -0
  68. package/dist/chunks/search.js +113 -0
  69. package/dist/chunks/self-update.js +238 -0
  70. package/dist/chunks/serve.js +1246 -0
  71. package/dist/chunks/session-status.js +24 -0
  72. package/dist/chunks/skills.js +35 -0
  73. package/dist/chunks/spaces.js +5080 -0
  74. package/dist/chunks/src.js +405 -0
  75. package/dist/chunks/supervisor.js +2511 -0
  76. package/dist/chunks/supervisor2.js +2 -0
  77. package/dist/chunks/tasks.js +82 -0
  78. package/dist/chunks/themes.js +2898 -0
  79. package/dist/chunks/version.js +2 -0
  80. package/dist/chunks/version2.js +22 -0
  81. package/dist/chunks/version3.js +18 -0
  82. package/dist/chunks/web.js +7 -0
  83. package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
  84. package/dist/runtime/native/pi-extension.js +174 -166
  85. package/dist/runtime/worker.js +27 -16
  86. package/package.json +8 -9
  87. package/dist/about.d.ts +0 -2
  88. package/dist/about.js +0 -71
  89. package/dist/app-download.d.ts +0 -11
  90. package/dist/app-download.js +0 -252
  91. package/dist/app-ref.d.ts +0 -5
  92. package/dist/app-ref.js +0 -8
  93. package/dist/app-target.d.ts +0 -26
  94. package/dist/app-target.js +0 -55
  95. package/dist/auth.d.ts +0 -45
  96. package/dist/auth.js +0 -307
  97. package/dist/avatar.d.ts +0 -55
  98. package/dist/avatar.js +0 -104
  99. package/dist/board-command-support.d.ts +0 -6
  100. package/dist/board-command-support.js +0 -88
  101. package/dist/board-export-resources.d.ts +0 -12
  102. package/dist/board-export-resources.js +0 -51
  103. package/dist/board-export.d.ts +0 -110
  104. package/dist/board-export.js +0 -592
  105. package/dist/board-fonts.d.ts +0 -11
  106. package/dist/board-fonts.js +0 -10
  107. package/dist/board-gpu/daemon.d.ts +0 -11
  108. package/dist/board-gpu/daemon.js +0 -295
  109. package/dist/board-gpu/index.d.ts +0 -33
  110. package/dist/board-gpu/index.js +0 -189
  111. package/dist/board-gpu/protocol.d.ts +0 -77
  112. package/dist/board-gpu/protocol.js +0 -1
  113. package/dist/board-kernel.d.ts +0 -5
  114. package/dist/board-media-export.d.ts +0 -17
  115. package/dist/board-media-export.js +0 -164
  116. package/dist/board-media.d.ts +0 -5
  117. package/dist/board-media.js +0 -66
  118. package/dist/board-profile.d.ts +0 -21
  119. package/dist/board-profile.js +0 -67
  120. package/dist/board-simulate.d.ts +0 -67
  121. package/dist/board-simulate.js +0 -259
  122. package/dist/board-time.d.ts +0 -3
  123. package/dist/board-time.js +0 -34
  124. package/dist/bootstrap.d.ts +0 -2
  125. package/dist/client.d.ts +0 -5
  126. package/dist/client.js +0 -24
  127. package/dist/command-input.d.ts +0 -4
  128. package/dist/command-input.js +0 -16
  129. package/dist/commands/app-commerce.d.ts +0 -2
  130. package/dist/commands/app-commerce.js +0 -228
  131. package/dist/commands/app-domains.d.ts +0 -2
  132. package/dist/commands/app-domains.js +0 -133
  133. package/dist/commands/apps.d.ts +0 -4
  134. package/dist/commands/apps.js +0 -827
  135. package/dist/commands/auth.d.ts +0 -2
  136. package/dist/commands/auth.js +0 -186
  137. package/dist/commands/boards/authoring.d.ts +0 -2
  138. package/dist/commands/boards/authoring.js +0 -166
  139. package/dist/commands/boards/examples.d.ts +0 -10
  140. package/dist/commands/boards/examples.js +0 -118
  141. package/dist/commands/boards.d.ts +0 -13
  142. package/dist/commands/boards.js +0 -836
  143. package/dist/commands/channels.d.ts +0 -2
  144. package/dist/commands/channels.js +0 -74
  145. package/dist/commands/cron-jobs.d.ts +0 -2
  146. package/dist/commands/cron-jobs.js +0 -155
  147. package/dist/commands/decision.d.ts +0 -4
  148. package/dist/commands/decision.js +0 -113
  149. package/dist/commands/desktop.d.ts +0 -10
  150. package/dist/commands/desktop.js +0 -233
  151. package/dist/commands/feedback.d.ts +0 -2
  152. package/dist/commands/feedback.js +0 -131
  153. package/dist/commands/generations.d.ts +0 -2
  154. package/dist/commands/generations.js +0 -427
  155. package/dist/commands/host.d.ts +0 -2
  156. package/dist/commands/host.js +0 -11
  157. package/dist/commands/me.d.ts +0 -2
  158. package/dist/commands/me.js +0 -118
  159. package/dist/commands/models.d.ts +0 -28
  160. package/dist/commands/models.js +0 -271
  161. package/dist/commands/profile.d.ts +0 -2
  162. package/dist/commands/profile.js +0 -81
  163. package/dist/commands/prompts.d.ts +0 -2
  164. package/dist/commands/prompts.js +0 -37
  165. package/dist/commands/public.d.ts +0 -20
  166. package/dist/commands/public.js +0 -291
  167. package/dist/commands/references.d.ts +0 -2
  168. package/dist/commands/references.js +0 -193
  169. package/dist/commands/referrals.d.ts +0 -2
  170. package/dist/commands/referrals.js +0 -88
  171. package/dist/commands/rooms-connect.d.ts +0 -17
  172. package/dist/commands/rooms-connect.js +0 -140
  173. package/dist/commands/rooms-rtc-binary.d.ts +0 -2
  174. package/dist/commands/rooms-rtc-binary.js +0 -107
  175. package/dist/commands/rooms-rtc.d.ts +0 -21
  176. package/dist/commands/rooms-rtc.js +0 -171
  177. package/dist/commands/rooms.d.ts +0 -3
  178. package/dist/commands/rooms.js +0 -277
  179. package/dist/commands/run.d.ts +0 -13
  180. package/dist/commands/run.js +0 -246
  181. package/dist/commands/runtime.d.ts +0 -3
  182. package/dist/commands/runtime.js +0 -320
  183. package/dist/commands/sandboxd-binary.d.ts +0 -11
  184. package/dist/commands/sandboxd-binary.js +0 -238
  185. package/dist/commands/search.d.ts +0 -2
  186. package/dist/commands/search.js +0 -114
  187. package/dist/commands/session-access.d.ts +0 -2
  188. package/dist/commands/session-access.js +0 -70
  189. package/dist/commands/skills.d.ts +0 -2
  190. package/dist/commands/skills.js +0 -34
  191. package/dist/commands/space-activity.d.ts +0 -26
  192. package/dist/commands/space-activity.js +0 -147
  193. package/dist/commands/space-commerce.d.ts +0 -2
  194. package/dist/commands/space-commerce.js +0 -514
  195. package/dist/commands/space-displays.d.ts +0 -2
  196. package/dist/commands/space-displays.js +0 -620
  197. package/dist/commands/space-files.d.ts +0 -5
  198. package/dist/commands/space-files.js +0 -215
  199. package/dist/commands/space-invitations.d.ts +0 -29
  200. package/dist/commands/space-invitations.js +0 -189
  201. package/dist/commands/space-turns.d.ts +0 -49
  202. package/dist/commands/space-turns.js +0 -205
  203. package/dist/commands/space-wallet.d.ts +0 -2
  204. package/dist/commands/space-wallet.js +0 -64
  205. package/dist/commands/space-webhooks.d.ts +0 -7
  206. package/dist/commands/space-webhooks.js +0 -73
  207. package/dist/commands/spaces.d.ts +0 -25
  208. package/dist/commands/spaces.js +0 -2139
  209. package/dist/commands/tasks.d.ts +0 -8
  210. package/dist/commands/tasks.js +0 -80
  211. package/dist/commands/version.d.ts +0 -2
  212. package/dist/commands/version.js +0 -21
  213. package/dist/endpoint-options.d.ts +0 -4
  214. package/dist/endpoint-options.js +0 -26
  215. package/dist/env-proxy.d.ts +0 -5
  216. package/dist/env-proxy.js +0 -20
  217. package/dist/help-path.d.ts +0 -18
  218. package/dist/help-path.js +0 -223
  219. package/dist/host/auth.d.ts +0 -20
  220. package/dist/host/auth.js +0 -119
  221. package/dist/host/login-env.d.ts +0 -1
  222. package/dist/host/login-env.js +0 -31
  223. package/dist/host/runtime.d.ts +0 -35
  224. package/dist/host/runtime.js +0 -395
  225. package/dist/host/runtimes.d.ts +0 -9
  226. package/dist/host/runtimes.js +0 -42
  227. package/dist/host/serve.d.ts +0 -2
  228. package/dist/host/serve.js +0 -117
  229. package/dist/host/workspaces.d.ts +0 -2
  230. package/dist/host/workspaces.js +0 -18
  231. package/dist/http-put.d.ts +0 -25
  232. package/dist/http-put.js +0 -132
  233. package/dist/index.d.ts +0 -2
  234. package/dist/index.js +0 -129
  235. package/dist/launcher.d.ts +0 -4
  236. package/dist/launcher.js +0 -38
  237. package/dist/local-media.d.ts +0 -2
  238. package/dist/local-media.js +0 -30
  239. package/dist/network-error.d.ts +0 -3
  240. package/dist/network-error.js +0 -22
  241. package/dist/output.d.ts +0 -46
  242. package/dist/output.js +0 -244
  243. package/dist/runtime/archive-store.d.ts +0 -54
  244. package/dist/runtime/archive-store.js +0 -379
  245. package/dist/runtime/cli-path.d.ts +0 -5
  246. package/dist/runtime/cli-path.js +0 -27
  247. package/dist/runtime/codex-usage.d.ts +0 -7
  248. package/dist/runtime/codex-usage.js +0 -11
  249. package/dist/runtime/connection.d.ts +0 -42
  250. package/dist/runtime/connection.js +0 -789
  251. package/dist/runtime/diagnostics.d.ts +0 -107
  252. package/dist/runtime/diagnostics.js +0 -392
  253. package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
  254. package/dist/runtime/harnesses/chained-projection.js +0 -95
  255. package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
  256. package/dist/runtime/harnesses/chained-transcript.js +0 -62
  257. package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
  258. package/dist/runtime/harnesses/claude-approval.js +0 -124
  259. package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
  260. package/dist/runtime/harnesses/claude-transcript.js +0 -138
  261. package/dist/runtime/harnesses/claude.d.ts +0 -8
  262. package/dist/runtime/harnesses/claude.js +0 -225
  263. package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
  264. package/dist/runtime/harnesses/codex-approval.js +0 -69
  265. package/dist/runtime/harnesses/codex.d.ts +0 -4
  266. package/dist/runtime/harnesses/codex.js +0 -269
  267. package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
  268. package/dist/runtime/harnesses/cursor-transcript.js +0 -183
  269. package/dist/runtime/harnesses/cursor.d.ts +0 -24
  270. package/dist/runtime/harnesses/cursor.js +0 -620
  271. package/dist/runtime/harnesses/index.d.ts +0 -16
  272. package/dist/runtime/harnesses/index.js +0 -73
  273. package/dist/runtime/harnesses/pi.d.ts +0 -4
  274. package/dist/runtime/harnesses/pi.js +0 -247
  275. package/dist/runtime/harnesses/process.d.ts +0 -31
  276. package/dist/runtime/harnesses/process.js +0 -75
  277. package/dist/runtime/harnesses/stream-json.d.ts +0 -48
  278. package/dist/runtime/harnesses/stream-json.js +0 -336
  279. package/dist/runtime/harnesses/types.d.ts +0 -117
  280. package/dist/runtime/harnesses/types.js +0 -1
  281. package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
  282. package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
  283. package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
  284. package/dist/runtime/harnesses/workbuddy.js +0 -123
  285. package/dist/runtime/instance.d.ts +0 -20
  286. package/dist/runtime/instance.js +0 -247
  287. package/dist/runtime/json-rpc.d.ts +0 -53
  288. package/dist/runtime/json-rpc.js +0 -212
  289. package/dist/runtime/launch.d.ts +0 -25
  290. package/dist/runtime/launch.js +0 -247
  291. package/dist/runtime/local-workspace.d.ts +0 -15
  292. package/dist/runtime/local-workspace.js +0 -52
  293. package/dist/runtime/model-catalog.d.ts +0 -12
  294. package/dist/runtime/model-catalog.js +0 -84
  295. package/dist/runtime/native/adapters.d.ts +0 -15
  296. package/dist/runtime/native/adapters.js +0 -11
  297. package/dist/runtime/native/approvals.d.ts +0 -18
  298. package/dist/runtime/native/approvals.js +0 -54
  299. package/dist/runtime/native/archive.d.ts +0 -19
  300. package/dist/runtime/native/archive.js +0 -142
  301. package/dist/runtime/native/attach.d.ts +0 -36
  302. package/dist/runtime/native/attach.js +0 -128
  303. package/dist/runtime/native/codex-link.d.ts +0 -60
  304. package/dist/runtime/native/codex-link.js +0 -322
  305. package/dist/runtime/native/config.d.ts +0 -16
  306. package/dist/runtime/native/config.js +0 -24
  307. package/dist/runtime/native/daemon.d.ts +0 -92
  308. package/dist/runtime/native/daemon.js +0 -380
  309. package/dist/runtime/native/execution.d.ts +0 -26
  310. package/dist/runtime/native/execution.js +0 -34
  311. package/dist/runtime/native/identity.d.ts +0 -9
  312. package/dist/runtime/native/identity.js +0 -15
  313. package/dist/runtime/native/ingest.d.ts +0 -263
  314. package/dist/runtime/native/ingest.js +0 -884
  315. package/dist/runtime/native/install.d.ts +0 -9
  316. package/dist/runtime/native/install.js +0 -113
  317. package/dist/runtime/native/paths.d.ts +0 -2
  318. package/dist/runtime/native/paths.js +0 -7
  319. package/dist/runtime/native/pi-extension.d.ts +0 -36
  320. package/dist/runtime/native/pi-link.d.ts +0 -69
  321. package/dist/runtime/native/pi-link.js +0 -269
  322. package/dist/runtime/native/results.d.ts +0 -41
  323. package/dist/runtime/native/results.js +0 -128
  324. package/dist/runtime/native/sessions.d.ts +0 -45
  325. package/dist/runtime/native/sessions.js +0 -87
  326. package/dist/runtime/native/transcript.d.ts +0 -89
  327. package/dist/runtime/native/transcript.js +0 -656
  328. package/dist/runtime/native/translate.d.ts +0 -46
  329. package/dist/runtime/native/translate.js +0 -299
  330. package/dist/runtime/native/transport.d.ts +0 -7
  331. package/dist/runtime/native/transport.js +0 -16
  332. package/dist/runtime/native/version.d.ts +0 -5
  333. package/dist/runtime/native/version.js +0 -21
  334. package/dist/runtime/preferences.d.ts +0 -7
  335. package/dist/runtime/preferences.js +0 -22
  336. package/dist/runtime/presentation.d.ts +0 -32
  337. package/dist/runtime/presentation.js +0 -124
  338. package/dist/runtime/process-group.d.ts +0 -5
  339. package/dist/runtime/process-group.js +0 -161
  340. package/dist/runtime/projection-store.d.ts +0 -27
  341. package/dist/runtime/projection-store.js +0 -30
  342. package/dist/runtime/space-binding.d.ts +0 -48
  343. package/dist/runtime/space-binding.js +0 -342
  344. package/dist/runtime/supervisor.d.ts +0 -19
  345. package/dist/runtime/supervisor.js +0 -441
  346. package/dist/runtime/turn-projection.d.ts +0 -41
  347. package/dist/runtime/turn-projection.js +0 -120
  348. package/dist/runtime/worker.d.ts +0 -1
  349. package/dist/safe-remote-image.d.ts +0 -36
  350. package/dist/safe-remote-image.js +0 -191
  351. package/dist/self-update.d.ts +0 -7
  352. package/dist/self-update.js +0 -202
  353. package/dist/session-status.d.ts +0 -6
  354. package/dist/session-status.js +0 -16
  355. package/dist/space-files/limit.d.ts +0 -2
  356. package/dist/space-files/limit.js +0 -16
  357. package/dist/space-files/operands.d.ts +0 -17
  358. package/dist/space-files/operands.js +0 -33
  359. package/dist/space-files/transfer.d.ts +0 -53
  360. package/dist/space-files/transfer.js +0 -297
  361. package/dist/space-files/upload.d.ts +0 -17
  362. package/dist/space-files/upload.js +0 -76
  363. package/dist/space.d.ts +0 -44
  364. package/dist/space.js +0 -192
  365. package/dist/version.d.ts +0 -2
  366. package/dist/version.js +0 -17
  367. package/dist/web.d.ts +0 -1
  368. package/dist/web.js +0 -4
  369. /package/dist/{board-kernel → chunks}/lexer.js +0 -0
@@ -1,123 +0,0 @@
1
- import { homedir } from "node:os";
2
- import { basename, join } from "node:path";
3
- import { copyNativeArchive } from "../native/archive.js";
4
- import { projectChainedSession, projectionMeta, projectionToolId, rebindSessionId, toolResultText } from "./chained-projection.js";
5
- import { chainedSessionHeader, projectDirectory as projectFolder, projectTranscript } from "./chained-transcript.js";
6
- import { readWorkbuddyTranscript, WORKBUDDY_REPLY_ENDED } from "./workbuddy-transcript.js";
7
- import { DEFAULT_MODEL, runStreamJson, streamJsonHelp, streamJsonModel } from "./stream-json.js";
8
- /** WorkBuddy's CLI is CodeBuddy Code; both share its data root. */
9
- const dataRoot = () => process.env.CODEBUDDY_CONFIG_DIR?.trim() || join(homedir(), ".codebuddy");
10
- const MAX_NAME_BYTES = 255;
11
- const TRUNCATED_NAME_BYTES = 180;
12
- const projectBase = (cwd) => cwd.replace(/[/\\:]/g, "-").replace(/^-+/, "").replace(/-+$/, "").replace(/-+/g, "-");
13
- function truncated(base) {
14
- let prefix = "", bytes = 0;
15
- for (const character of base) {
16
- const size = Buffer.byteLength(character, "utf8");
17
- if (bytes + size > TRUNCATED_NAME_BYTES)
18
- break;
19
- bytes += size;
20
- prefix += character;
21
- }
22
- return prefix;
23
- }
24
- /** Mirrors CodeBuddy's project naming, including its truncation hash for long paths. */
25
- export function workbuddyProjectName(cwd) {
26
- const base = projectBase(cwd);
27
- if (Buffer.byteLength(base, "utf8") <= MAX_NAME_BYTES)
28
- return base;
29
- const prefix = truncated(base);
30
- let hash = 5381;
31
- for (const byte of Buffer.from(base, "utf8"))
32
- hash = 33 * hash ^ byte;
33
- return `${prefix}-${(hash >>> 0).toString(36)}`;
34
- }
35
- const projectDirectory = (cwd) => join(dataRoot(), "projects", workbuddyProjectName(cwd));
36
- const projectsRoot = () => join(dataRoot(), "projects");
37
- /** Every subdirectory's project name starts with this, hashed long names included. */
38
- const projectPrefix = (cwd) => truncated(projectBase(cwd));
39
- const profile = {
40
- harness: "workbuddy",
41
- label: "WorkBuddy",
42
- binary: "codebuddy",
43
- provider: "codebuddy",
44
- dataRoot,
45
- projectDirectory,
46
- effortLevels: ["minimal", "low", "medium", "high", "xhigh", "max"],
47
- promptUuid: false,
48
- };
49
- /** The CLI lists selectable models (built-in and `models.json`) in its `--model` help. */
50
- export function workbuddyModels(help) {
51
- const list = /--model <model>[\s\S]*?Currently supported:\s*\(([^)]*)\)/.exec(help)?.[1] ?? "";
52
- const ids = [...new Set(list.split(",").map((id) => id.trim()).filter((id) => /^[\w.:/@-]{1,255}$/.test(id) && id !== DEFAULT_MODEL))];
53
- if (!ids.length)
54
- throw new Error("WorkBuddy lists no models; sign in to WorkBuddy or configure a model");
55
- // The CLI ignores an effort level a model does not support.
56
- return [streamJsonModel(profile, DEFAULT_MODEL, "Default", { reasoning: true, isDefault: true }), ...ids.map((id) => streamJsonModel(profile, id, id, { reasoning: true }))];
57
- }
58
- export const workbuddyHarness = {
59
- id: "workbuddy",
60
- binary: profile.binary,
61
- models: async (executable, cwd) => workbuddyModels(await streamJsonHelp(profile, executable, cwd)),
62
- run: (executor, turn) => runStreamJson(profile, executor, turn),
63
- session: {
64
- path: (nativeSessionId, cwd) => join(projectDirectory(cwd), `${nativeSessionId}.jsonl`),
65
- startsWithoutFile: true,
66
- // CodeBuddy stores Responses-style items: one record per message, call or result.
67
- project: (input) => {
68
- const names = new Map();
69
- return projectChainedSession(input, "workbuddy", { id: "id", parent: "parentId" }, (segment) => {
70
- const base = { timestamp: Date.parse(segment.message.createdAt) || 0, sessionId: input.nativeSessionId, cwd: input.cwd, cohub: projectionMeta(input, segment.message) };
71
- if (segment.role === "user") {
72
- if (segment.blocks.some((block) => block.type === "tool_result")) {
73
- return segment.blocks.flatMap((block) => block.type === "tool_result"
74
- ? [{ ...base, type: "function_call_result", callId: projectionToolId(block.tool_use_id), name: names.get(block.tool_use_id) ?? "tool", status: "completed", output: { type: "text", text: toolResultText(block) } }]
75
- : []);
76
- }
77
- const content = segment.blocks.flatMap((block) => block.type === "text" ? [{ type: "input_text", text: block.text }]
78
- : block.type === "image" && block.source.type === "base64" ? [{ type: "input_image", image: `data:${block.source.media_type};base64,${block.source.data}` }]
79
- : []);
80
- return content.length ? [{ ...base, type: "message", role: "user", content, providerData: { startsNewUserRequest: true } }] : [];
81
- }
82
- const records = [];
83
- for (const block of segment.blocks) {
84
- if (block.type === "text") {
85
- const previous = records.at(-1);
86
- if (previous?.type === "message")
87
- previous.content.push({ type: "output_text", text: block.text });
88
- else
89
- records.push({ ...base, type: "message", role: "assistant", status: "completed", content: [{ type: "output_text", text: block.text }] });
90
- }
91
- else if (block.type === "tool_use") {
92
- names.set(block.id, block.name);
93
- records.push({ ...base, type: "function_call", callId: projectionToolId(block.id), name: block.name, arguments: JSON.stringify(block.input) });
94
- }
95
- }
96
- return records;
97
- });
98
- },
99
- rebind: rebindSessionId,
100
- archive: {
101
- // The copy takes a fresh id: the archived one may already exist here, and is never replaced.
102
- target: ({ id, cwd }) => join(projectDirectory(cwd), `${id}.jsonl`),
103
- async import(input) {
104
- const { checksum } = await copyNativeArchive({ ...input, sessionId: input.id });
105
- return { checksum, nativeSessionId: input.id };
106
- },
107
- },
108
- },
109
- transcript: {
110
- roots: () => [projectsRoot()],
111
- acceptsDirectory: (path, root, cwd) => projectFolder(path, root, projectPrefix(cwd)),
112
- acceptsTranscript: (path, cwd) => projectTranscript(path, projectsRoot(), projectPrefix(cwd)),
113
- header: (path, signal) => chainedSessionHeader(path, "workbuddy", signal),
114
- read: (path, signal) => readWorkbuddyTranscript(path, basename(path, ".jsonl"), signal),
115
- boundaries: ['"role":"user"', '"role":"assistant"', '"type":"turn-metrics"'],
116
- turnEndRecorded: false,
117
- replyEnded: (turn) => WORKBUDDY_REPLY_ENDED.includes(turn.messages.at(-1)?.stopReason ?? ""),
118
- userFinalMarked: false,
119
- globalTurnKeys: false,
120
- // CodeBuddy keeps no field of a stream-json prompt, so Cohub's Turns are tracked in the ledger.
121
- marksCohubTurns: false,
122
- },
123
- };
@@ -1,20 +0,0 @@
1
- import type { RuntimeSummary } from "./presentation.js";
2
- export declare function runtimeInstancesRoot(): string;
3
- export declare function runtimeInstanceDirectory(identity: string, spaceId: string): string;
4
- type Response = {
5
- status: RuntimeSummary;
6
- result?: unknown;
7
- };
8
- export declare function requestRuntimeInstance(directory: string, action?: "status" | "stop", force?: boolean): Promise<RuntimeSummary | null>;
9
- /** Send a control action to the running Runtime; `null` when none runs. */
10
- export declare function controlRuntimeInstance(directory: string, action: string, payload?: Record<string, unknown>, timeoutMs?: number): Promise<Response | null>;
11
- export declare const UNCONFIRMED_WORK = "Unconfirmed executions remain";
12
- export declare function stopRuntimeInstance(directory: string, force?: boolean): Promise<RuntimeSummary | null>;
13
- export declare function watchRuntimeInstance(directory: string, onStatus: (status: RuntimeSummary) => void, signal?: AbortSignal): Promise<boolean>;
14
- export type RuntimeInstanceHandle = {
15
- changed(): void;
16
- close(): Promise<void>;
17
- };
18
- /** Private local IPC is both the single-instance guard and the control surface. */
19
- export declare function ownRuntimeInstance(directory: string, status: () => RuntimeSummary, stop: (force: boolean) => Promise<void>, control?: (action: string, message: Record<string, unknown>) => Promise<unknown>): Promise<RuntimeInstanceHandle>;
20
- export {};
@@ -1,247 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
3
- import { createConnection, createServer } from "node:net";
4
- import { homedir } from "node:os";
5
- import { join } from "node:path";
6
- import { setTimeout as delay } from "node:timers/promises";
7
- import { withRuntimeSpaceBindingsLock } from "./space-binding.js";
8
- const MAX_WATCHERS = 16;
9
- export function runtimeInstancesRoot() {
10
- return join(homedir(), ".local", "state", "cohub", "instances");
11
- }
12
- export function runtimeInstanceDirectory(identity, spaceId) {
13
- const key = createHash("sha256").update(`${identity}\0${spaceId}`).digest("hex").slice(0, 24);
14
- return join(runtimeInstancesRoot(), key);
15
- }
16
- function alive(pid) {
17
- if (!Number.isSafeInteger(pid) || pid <= 0)
18
- return true;
19
- try {
20
- process.kill(pid, 0);
21
- return true;
22
- }
23
- catch (error) {
24
- return error.code !== "ESRCH";
25
- }
26
- }
27
- async function readRecord(directory) {
28
- try {
29
- const value = JSON.parse(await readFile(join(directory, "owner.json"), "utf8"));
30
- if (!Number.isSafeInteger(value.pid) || typeof value.nonce !== "string" || typeof value.socket !== "string")
31
- throw new Error("Invalid Runtime instance record");
32
- return value;
33
- }
34
- catch (error) {
35
- if (error.code === "ENOENT")
36
- return null;
37
- throw error;
38
- }
39
- }
40
- function request(record, action, payload, timeoutMs) {
41
- return new Promise((resolve, reject) => {
42
- const socket = createConnection(record.socket);
43
- const timer = setTimeout(() => { socket.destroy(); reject(new Error("Runtime control timed out")); }, timeoutMs);
44
- let buffer = "";
45
- let settled = false;
46
- const finish = (error, value) => {
47
- if (settled)
48
- return;
49
- settled = true;
50
- clearTimeout(timer);
51
- socket.destroy();
52
- if (error)
53
- reject(error);
54
- else if (value)
55
- resolve(value);
56
- };
57
- socket.on("connect", () => socket.write(`${JSON.stringify({ ...payload, nonce: record.nonce, action })}\n`));
58
- socket.on("error", (error) => finish(error));
59
- socket.on("close", () => finish(new Error("Runtime control closed")));
60
- socket.on("data", (chunk) => {
61
- buffer += chunk.toString();
62
- if (buffer.length > 64 * 1024) {
63
- finish(new Error("Runtime response too large"));
64
- return;
65
- }
66
- if (!buffer.includes("\n"))
67
- return;
68
- try {
69
- const response = JSON.parse(buffer.slice(0, buffer.indexOf("\n")));
70
- if (response.error)
71
- finish(new Error(response.error));
72
- else if (response.nonce !== record.nonce || response.status?.pid !== record.pid)
73
- finish(new Error("Runtime identity changed"));
74
- else
75
- finish(undefined, { status: response.status, result: response.result });
76
- }
77
- catch (error) {
78
- finish(error instanceof Error ? error : new Error(String(error)));
79
- }
80
- });
81
- });
82
- }
83
- export async function requestRuntimeInstance(directory, action = "status", force = false) {
84
- return (await controlRuntimeInstance(directory, action, { force }))?.status ?? null;
85
- }
86
- /** Send a control action to the running Runtime; `null` when none runs. */
87
- export async function controlRuntimeInstance(directory, action, payload = {}, timeoutMs = 3000) {
88
- const record = await readRecord(directory);
89
- if (!record || !alive(record.pid))
90
- return null;
91
- try {
92
- return await request(record, action, payload, timeoutMs);
93
- }
94
- catch (error) {
95
- // A reused PID is not proof of ownership. Missing/refused endpoints cannot
96
- // belong to a serving Runtime; timeouts and permission errors remain uncertain.
97
- if (["ENOENT", "ECONNREFUSED"].includes(error.code ?? ""))
98
- return null;
99
- throw error;
100
- }
101
- }
102
- export const UNCONFIRMED_WORK = "Unconfirmed executions remain";
103
- export async function stopRuntimeInstance(directory, force = false) {
104
- const local = await requestRuntimeInstance(directory, "stop", force);
105
- const until = Date.now() + 15_000;
106
- let running = Boolean(local);
107
- while (running && Date.now() < until) {
108
- await delay(250);
109
- try {
110
- running = Boolean(await requestRuntimeInstance(directory));
111
- }
112
- catch {
113
- running = true;
114
- } // An unreachable control socket does not prove the process stopped.
115
- }
116
- if (running)
117
- throw new Error("Runtime is still stopping; inspect logs");
118
- return local;
119
- }
120
- export async function watchRuntimeInstance(directory, onStatus, signal) {
121
- const record = await readRecord(directory).catch(() => null);
122
- if (!record || !alive(record.pid) || signal?.aborted)
123
- return false;
124
- let streamed = false;
125
- await new Promise((resolve) => {
126
- const socket = createConnection(record.socket);
127
- const abort = () => socket.destroy();
128
- let buffer = "";
129
- signal?.addEventListener("abort", abort, { once: true });
130
- socket.on("connect", () => socket.write(`${JSON.stringify({ action: "watch", nonce: record.nonce })}\n`));
131
- socket.on("data", (chunk) => {
132
- buffer += chunk.toString();
133
- for (let end = buffer.indexOf("\n"); end >= 0; end = buffer.indexOf("\n")) {
134
- const line = buffer.slice(0, end);
135
- buffer = buffer.slice(end + 1);
136
- try {
137
- const response = JSON.parse(line);
138
- if (response.nonce !== record.nonce || response.status?.pid !== record.pid) {
139
- socket.destroy();
140
- return;
141
- }
142
- streamed = true;
143
- onStatus(response.status);
144
- }
145
- catch {
146
- socket.destroy();
147
- return;
148
- }
149
- }
150
- if (buffer.length > 64 * 1024)
151
- socket.destroy();
152
- });
153
- socket.on("error", () => socket.destroy());
154
- socket.on("close", () => { signal?.removeEventListener("abort", abort); resolve(); });
155
- });
156
- return streamed;
157
- }
158
- /** Private local IPC is both the single-instance guard and the control surface. */
159
- export async function ownRuntimeInstance(directory, status, stop, control = async () => { throw new Error("Unknown Runtime control request"); }) {
160
- await mkdir(directory, { recursive: true, mode: 0o700 });
161
- return withRuntimeSpaceBindingsLock(async () => {
162
- if (await requestRuntimeInstance(directory))
163
- throw new Error("Runtime already running; use status");
164
- const socketPath = process.platform === "win32"
165
- ? `\\\\.\\pipe\\cohub-${createHash("sha256").update(directory).digest("hex").slice(0, 24)}`
166
- : join(directory, "control.sock");
167
- if (process.platform !== "win32")
168
- await rm(socketPath, { force: true });
169
- const record = { pid: process.pid, nonce: randomUUID(), socket: socketPath };
170
- const clients = new Set();
171
- const watchers = new Set();
172
- const statusLine = () => `${JSON.stringify({ nonce: record.nonce, status: status() })}\n`;
173
- const server = createServer((socket) => {
174
- clients.add(socket);
175
- socket.setTimeout(3000, () => socket.destroy());
176
- socket.on("error", () => socket.destroy());
177
- socket.on("close", () => { clients.delete(socket); watchers.delete(socket); });
178
- let input = "";
179
- socket.on("data", (chunk) => {
180
- input += chunk.toString();
181
- if (input.length > 4096) {
182
- socket.destroy();
183
- return;
184
- }
185
- if (!input.includes("\n"))
186
- return;
187
- socket.removeAllListeners("data");
188
- // The request arrived; answering it may take longer than an idle client is allowed.
189
- socket.setTimeout(0);
190
- void (async () => {
191
- const message = JSON.parse(input.slice(0, input.indexOf("\n")));
192
- if (message.nonce !== record.nonce) {
193
- socket.destroy();
194
- return;
195
- }
196
- if (message.action === "watch") {
197
- if (watchers.size >= MAX_WATCHERS) {
198
- socket.destroy();
199
- return;
200
- }
201
- watchers.add(socket);
202
- socket.write(statusLine());
203
- return;
204
- }
205
- let result;
206
- if (message.action === "stop")
207
- await stop(message.force === true);
208
- else if (message.action !== "status")
209
- result = await control(String(message.action), message);
210
- socket.end(`${JSON.stringify({ nonce: record.nonce, status: status(), ...(result === undefined ? {} : { result }) })}\n`);
211
- })().catch((error) => socket.end(`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`));
212
- });
213
- });
214
- await new Promise((resolve, reject) => {
215
- server.once("error", reject);
216
- server.listen(socketPath, () => { server.removeListener("error", reject); resolve(); });
217
- });
218
- try {
219
- if (process.platform !== "win32")
220
- await chmod(socketPath, 0o600);
221
- const temporary = join(directory, `${record.nonce}.tmp`);
222
- await writeFile(temporary, JSON.stringify(record), { mode: 0o600 });
223
- await rename(temporary, join(directory, "owner.json"));
224
- }
225
- catch (error) {
226
- server.close();
227
- throw error;
228
- }
229
- return {
230
- changed: () => {
231
- if (!watchers.size)
232
- return;
233
- const line = statusLine();
234
- for (const watcher of watchers)
235
- watcher.write(line);
236
- },
237
- close: async () => {
238
- for (const client of clients)
239
- client.destroy();
240
- await new Promise((resolve) => server.close(() => resolve()));
241
- // Never remove a replacement owner's files.
242
- if ((await readRecord(directory))?.nonce === record.nonce)
243
- await rm(join(directory, "owner.json"));
244
- },
245
- };
246
- }, { path: join(directory, "owner.json") });
247
- }
@@ -1,53 +0,0 @@
1
- export type JsonRecord = Record<string, unknown>;
2
- export declare const record: (value: unknown) => JsonRecord;
3
- /** LF framing without rescanning the accumulated record on every pipe chunk. */
4
- export declare class JsonLineDecoder {
5
- private onValue;
6
- private maxBytes;
7
- private decoder;
8
- private fragments;
9
- private bytes;
10
- constructor(onValue: (value: JsonRecord) => void, maxBytes?: number);
11
- private append;
12
- private emit;
13
- push(chunk: Buffer): void;
14
- end(): void;
15
- }
16
- /** Anything surfacing while the host closes the process; not a failure. */
17
- export declare class RpcProcessClosedError extends Error {
18
- constructor();
19
- }
20
- export declare function harnessEnvironment(): NodeJS.ProcessEnv;
21
- export declare class JsonRpcProcess {
22
- private mode;
23
- private child;
24
- /** Process-group id of the harness process, for deferred cleanup confirmation. */
25
- get processGroupId(): number | null;
26
- private pending;
27
- private listeners;
28
- private failureListeners;
29
- private timeoutListeners;
30
- private failure;
31
- private nextId;
32
- private stderr;
33
- private closed;
34
- private closing;
35
- private inputEnded;
36
- /** `pi` and `jsonrpc` correlate request responses; `stream` delivers every line as an event. */
37
- constructor(binary: string, args: string[], cwd: string, mode: "pi" | "jsonrpc" | "stream", context?: Record<string, string>);
38
- private fail;
39
- private receive;
40
- write(value: unknown): void;
41
- request(method: string, params?: JsonRecord, timeoutMs?: number): Promise<JsonRecord>;
42
- /** Signal end of input; a stream-mode CLI flushes its transcript and exits. */
43
- endInput(): void;
44
- /** Ask a CLI that stops on SIGINT to end its current Turn. Windows has no SIGINT, so the process tree is stopped. */
45
- interrupt(): void;
46
- /** Whether the process exits within the timeout. */
47
- exited(timeoutMs: number): Promise<boolean>;
48
- onEvent(listener: (event: JsonRecord) => void): () => boolean;
49
- onFailure(listener: (error: Error) => void): () => boolean;
50
- onTimeout(listener: (method: string, timeoutMs: number) => void): () => boolean;
51
- close(): Promise<void>;
52
- private closeProcessGroup;
53
- }
@@ -1,212 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { StringDecoder } from "node:string_decoder";
3
- import { RUNTIME_MAX_FRAME_BYTES } from "@neta-art/cohub";
4
- import { stopProcessGroup } from "./process-group.js";
5
- export const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
6
- /** LF framing without rescanning the accumulated record on every pipe chunk. */
7
- export class JsonLineDecoder {
8
- onValue;
9
- maxBytes;
10
- decoder = new StringDecoder("utf8");
11
- fragments = [];
12
- bytes = 0;
13
- constructor(onValue, maxBytes = RUNTIME_MAX_FRAME_BYTES) {
14
- this.onValue = onValue;
15
- this.maxBytes = maxBytes;
16
- }
17
- append(fragment) {
18
- this.bytes += Buffer.byteLength(fragment);
19
- if (this.bytes > this.maxBytes)
20
- throw new Error("RPC frame is too large");
21
- this.fragments.push(fragment);
22
- }
23
- emit() {
24
- const line = this.fragments.join("");
25
- this.fragments = [];
26
- this.bytes = 0;
27
- if (!line.trim())
28
- return;
29
- const value = JSON.parse(line);
30
- if (!value || typeof value !== "object" || Array.isArray(value))
31
- throw new Error("RPC frame must be an object");
32
- this.onValue(value);
33
- }
34
- push(chunk) {
35
- const text = this.decoder.write(chunk);
36
- let start = 0;
37
- for (let end = text.indexOf("\n"); end >= 0; end = text.indexOf("\n", start)) {
38
- this.append(text.slice(start, end));
39
- this.emit();
40
- start = end + 1;
41
- }
42
- if (start < text.length)
43
- this.append(text.slice(start));
44
- }
45
- end() { this.append(this.decoder.end()); this.emit(); }
46
- }
47
- /** Anything surfacing while the host closes the process; not a failure. */
48
- export class RpcProcessClosedError extends Error {
49
- constructor() { super("RPC process closed"); this.name = "RpcProcessClosedError"; }
50
- }
51
- export function harnessEnvironment() {
52
- return Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("COHUB_") && !["WORKER_SECRET", "DATABASE_URL", "REDIS_URL"].includes(key)));
53
- }
54
- export class JsonRpcProcess {
55
- mode;
56
- child;
57
- /** Process-group id of the harness process, for deferred cleanup confirmation. */
58
- get processGroupId() { return this.child.pid ?? null; }
59
- pending = new Map();
60
- listeners = new Set();
61
- failureListeners = new Set();
62
- timeoutListeners = new Set();
63
- failure = null;
64
- nextId = 0;
65
- stderr = "";
66
- closed;
67
- closing = null;
68
- inputEnded = false;
69
- /** `pi` and `jsonrpc` correlate request responses; `stream` delivers every line as an event. */
70
- constructor(binary, args, cwd, mode, context = {}) {
71
- this.mode = mode;
72
- this.child = spawn(binary, args, { cwd, env: { ...harnessEnvironment(), ...context }, stdio: "pipe", detached: process.platform !== "win32", windowsHide: true });
73
- this.closed = new Promise((resolve) => this.child.once("close", () => resolve()));
74
- const decoder = new JsonLineDecoder((value) => this.receive(value));
75
- this.child.stdout.on("data", (chunk) => { try {
76
- decoder.push(chunk);
77
- }
78
- catch (error) {
79
- this.fail(error);
80
- } });
81
- this.child.stdout.on("end", () => { try {
82
- decoder.end();
83
- }
84
- catch (error) {
85
- this.fail(error);
86
- } });
87
- this.child.stderr.on("data", (chunk) => { this.stderr = (this.stderr + chunk.toString()).slice(-8192); });
88
- this.child.on("error", (error) => this.fail(error));
89
- this.child.stdin.on("error", (error) => this.fail(error));
90
- this.child.once("close", (code, signal) => this.fail(new Error(signal ? `${binary} terminated by ${signal}: ${this.stderr}` : `${binary} exited (${code}): ${this.stderr}`)));
91
- }
92
- fail(value) {
93
- if (this.failure)
94
- return;
95
- this.failure = this.closing || this.inputEnded ? new RpcProcessClosedError() : value instanceof Error ? value : new Error(String(value));
96
- for (const pending of this.pending.values()) {
97
- clearTimeout(pending.timer);
98
- pending.reject(this.failure);
99
- }
100
- this.pending.clear();
101
- for (const listener of this.failureListeners)
102
- listener(this.failure);
103
- }
104
- receive(value) {
105
- const key = value.id == null ? null : String(value.id);
106
- const response = this.mode === "pi" ? value.type === "response" : this.mode === "jsonrpc" && ("result" in value || "error" in value);
107
- if (key && response) {
108
- const pending = this.pending.get(key);
109
- if (!pending)
110
- return;
111
- this.pending.delete(key);
112
- clearTimeout(pending.timer);
113
- if (value.error || value.success === false)
114
- pending.reject(new Error(typeof value.error === "string" ? value.error : String(record(value.error).message ?? "RPC request failed")));
115
- else
116
- pending.resolve(record(this.mode === "pi" ? value.data : value.result));
117
- return;
118
- }
119
- for (const listener of this.listeners)
120
- listener(value);
121
- }
122
- write(value) {
123
- if (this.failure)
124
- throw this.failure;
125
- const data = `${JSON.stringify(value)}\n`;
126
- if (this.child.stdin.writableLength + Buffer.byteLength(data) > RUNTIME_MAX_FRAME_BYTES)
127
- throw new Error("RPC input backpressure limit exceeded");
128
- this.child.stdin.write(data);
129
- }
130
- request(method, params = {}, timeoutMs = 30_000) {
131
- if (this.failure)
132
- return Promise.reject(this.failure);
133
- const id = String(++this.nextId);
134
- return new Promise((resolve, reject) => {
135
- const timer = setTimeout(() => {
136
- this.pending.delete(id);
137
- for (const listener of this.timeoutListeners)
138
- listener(method, timeoutMs);
139
- reject(new Error(`${method} timed out`));
140
- }, timeoutMs);
141
- this.pending.set(id, { resolve, reject, timer });
142
- try {
143
- this.write(this.mode === "pi" ? { ...params, id, type: method } : { id, method, params });
144
- }
145
- catch (error) {
146
- clearTimeout(timer);
147
- this.pending.delete(id);
148
- reject(error);
149
- }
150
- });
151
- }
152
- /** Signal end of input; a stream-mode CLI flushes its transcript and exits. */
153
- endInput() {
154
- if (this.failure)
155
- return;
156
- // The exit that follows is expected, not a failure.
157
- this.inputEnded = true;
158
- this.child.stdin.end();
159
- }
160
- /** Ask a CLI that stops on SIGINT to end its current Turn. Windows has no SIGINT, so the process tree is stopped. */
161
- interrupt() {
162
- if (this.failure)
163
- return;
164
- if (process.platform === "win32")
165
- void this.close().catch(() => undefined);
166
- else
167
- this.child.kill("SIGINT");
168
- }
169
- /** Whether the process exits within the timeout. */
170
- async exited(timeoutMs) {
171
- let timer;
172
- const timeout = new Promise((resolve) => { timer = setTimeout(() => resolve(false), timeoutMs); });
173
- try {
174
- return await Promise.race([this.closed.then(() => true), timeout]);
175
- }
176
- finally {
177
- clearTimeout(timer);
178
- }
179
- }
180
- onEvent(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); }
181
- onFailure(listener) {
182
- this.failureListeners.add(listener);
183
- if (this.failure)
184
- queueMicrotask(() => { if (this.failure && this.failureListeners.has(listener))
185
- listener(this.failure); });
186
- return () => this.failureListeners.delete(listener);
187
- }
188
- onTimeout(listener) {
189
- this.timeoutListeners.add(listener);
190
- return () => this.timeoutListeners.delete(listener);
191
- }
192
- close() {
193
- this.closing ??= this.closeProcessGroup();
194
- return this.closing;
195
- }
196
- async closeProcessGroup() {
197
- try {
198
- if (this.child.pid)
199
- await stopProcessGroup(this.child.pid);
200
- }
201
- finally {
202
- this.child.stdin.destroy();
203
- this.child.stdout.destroy();
204
- this.child.stderr.destroy();
205
- this.fail(new RpcProcessClosedError());
206
- this.listeners.clear();
207
- this.failureListeners.clear();
208
- this.timeoutListeners.clear();
209
- }
210
- await this.closed;
211
- }
212
- }