@stringsync/splates 0.0.0-stage → 0.0.45

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 (251) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +308 -2
  3. package/acp-extensions.d.ts +82 -0
  4. package/add.d.ts +53 -0
  5. package/adherence.d.ts +49 -0
  6. package/age.d.ts +2 -0
  7. package/agent-connection.d.ts +171 -0
  8. package/agent-errors.d.ts +2 -0
  9. package/agent-process.d.ts +65 -0
  10. package/agent-stream.d.ts +91 -0
  11. package/agents.d.ts +15 -0
  12. package/artifact-room.d.ts +47 -0
  13. package/artifact-viewers.d.ts +6 -0
  14. package/artifact.d.ts +30 -0
  15. package/artifacts.d.ts +161 -0
  16. package/asked.d.ts +146 -0
  17. package/asked.js +7 -0
  18. package/assumed.d.ts +34 -0
  19. package/attach.d.ts +30 -0
  20. package/attachments.d.ts +43 -0
  21. package/baselines.d.ts +55 -0
  22. package/claim.d.ts +17 -0
  23. package/cloudflare-api.d.ts +25 -0
  24. package/cloudflare-error.d.ts +5 -0
  25. package/cloudflared-tunnel-provider.d.ts +27 -0
  26. package/codex-limits.d.ts +19 -0
  27. package/compaction.d.ts +17 -0
  28. package/config-source.d.ts +13 -0
  29. package/config.d.ts +98 -0
  30. package/config.js +7 -0
  31. package/conversation-archive.d.ts +6 -0
  32. package/conversation-background.d.ts +21 -0
  33. package/conversation-choice.d.ts +4 -0
  34. package/conversation-files.d.ts +51 -0
  35. package/conversation-given.d.ts +8 -0
  36. package/conversation-host.d.ts +102 -0
  37. package/conversation-listing.d.ts +15 -0
  38. package/conversation-log.d.ts +301 -0
  39. package/conversation-messages.d.ts +18 -0
  40. package/conversation-name.d.ts +28 -0
  41. package/conversation-options.d.ts +73 -0
  42. package/conversation-reference.d.ts +2 -0
  43. package/conversation-state.d.ts +472 -0
  44. package/conversation-turns.d.ts +115 -0
  45. package/conversation.d.ts +209 -0
  46. package/conversations.d.ts +140 -0
  47. package/coordinator-state.d.ts +28 -0
  48. package/creds.d.ts +123 -0
  49. package/darwin-temperature.d.ts +7 -0
  50. package/decided.d.ts +18 -0
  51. package/demo.d.ts +29 -0
  52. package/dev/api.d.ts +209 -0
  53. package/dev/assets.d.ts +24 -0
  54. package/dev/conversation-address.d.ts +47 -0
  55. package/dev/conversation-feed.d.ts +166 -0
  56. package/dev/live-stream.d.ts +29 -0
  57. package/dev/worker.d.ts +33 -0
  58. package/dev-access.d.ts +61 -0
  59. package/dev-artifacts.d.ts +22 -0
  60. package/dev-budgets.d.ts +18 -0
  61. package/dev-conversation-events.d.ts +39 -0
  62. package/dev-conversation-routes.d.ts +90 -0
  63. package/dev-creds.d.ts +17 -0
  64. package/dev-dictation-connection.d.ts +18 -0
  65. package/dev-dictation.d.ts +17 -0
  66. package/dev-http.d.ts +76 -0
  67. package/dev-open.d.ts +15 -0
  68. package/dev-options.d.ts +133 -0
  69. package/dev-outcomes.d.ts +21 -0
  70. package/dev-pages.d.ts +16 -0
  71. package/dev-picker.d.ts +57 -0
  72. package/dev-port-socket.d.ts +26 -0
  73. package/dev-ports.d.ts +11 -0
  74. package/dev-project-watch.d.ts +44 -0
  75. package/dev-project.d.ts +168 -0
  76. package/dev-push.d.ts +59 -0
  77. package/dev-restart.d.ts +141 -0
  78. package/dev-servers.d.ts +30 -0
  79. package/dev-setup-native.d.ts +23 -0
  80. package/dev-setup-opencode.d.ts +29 -0
  81. package/dev-setup.d.ts +16 -0
  82. package/dev-shell.d.ts +70 -0
  83. package/dev-slot.d.ts +28 -0
  84. package/dev-sockets.d.ts +13 -0
  85. package/dev-task-ports.d.ts +73 -0
  86. package/dev-tasks.d.ts +20 -0
  87. package/dev-terminal-connection.d.ts +19 -0
  88. package/dev-terminal.d.ts +42 -0
  89. package/dev-todos.d.ts +35 -0
  90. package/dev-transcriber.d.ts +15 -0
  91. package/dev-tunnel.d.ts +38 -0
  92. package/dev-versions.d.ts +53 -0
  93. package/dev-workers.d.ts +55 -0
  94. package/dev.d.ts +24 -0
  95. package/diff.d.ts +29 -0
  96. package/dispatched.d.ts +16 -0
  97. package/editors.d.ts +22 -0
  98. package/escalate.d.ts +27 -0
  99. package/events.d.ts +311 -0
  100. package/everywhere.d.ts +41 -0
  101. package/exhibit.d.ts +21 -0
  102. package/exit.d.ts +54 -0
  103. package/fact-todos.d.ts +18 -0
  104. package/fake-agent.d.ts +107 -0
  105. package/fake-agent.js +284 -0
  106. package/finding-facts.d.ts +38 -0
  107. package/findings.d.ts +84 -0
  108. package/fold.d.ts +43 -0
  109. package/follow.d.ts +41 -0
  110. package/format.d.ts +68 -0
  111. package/git.d.ts +112 -0
  112. package/handed-out.d.ts +79 -0
  113. package/handoff.d.ts +23 -0
  114. package/heavy-run.d.ts +12 -0
  115. package/heavy.d.ts +28 -0
  116. package/heavy.js +16 -0
  117. package/held.d.ts +22 -0
  118. package/index-0tfvy823.js +272 -0
  119. package/index-43pq33n4.js +157 -0
  120. package/index-4776671w.js +698 -0
  121. package/index-d4hjrzaq.js +464 -0
  122. package/index-gcfq7awr.js +740 -0
  123. package/index-k73tsw5g.js +101 -0
  124. package/index-kaa44k7q.js +59 -0
  125. package/index-vcv9m93e.js +1265 -0
  126. package/index-xmfmy729.js +249 -0
  127. package/index.d.ts +2 -0
  128. package/index.js +26928 -0
  129. package/init.d.ts +28 -0
  130. package/journal.d.ts +57 -0
  131. package/landed.d.ts +14 -0
  132. package/lane-todos.d.ts +44 -0
  133. package/lane.d.ts +55 -0
  134. package/lanes-from-tags.d.ts +17 -0
  135. package/lanes.d.ts +96 -0
  136. package/legacy-names.d.ts +70 -0
  137. package/legacy-ps.d.ts +31 -0
  138. package/limits.d.ts +32 -0
  139. package/list.d.ts +18 -0
  140. package/load-config.d.ts +44 -0
  141. package/log.d.ts +14 -0
  142. package/machine.d.ts +42 -0
  143. package/merge.d.ts +35 -0
  144. package/migrate-config.d.ts +31 -0
  145. package/models.d.ts +24 -0
  146. package/needs.d.ts +115 -0
  147. package/notices.d.ts +39 -0
  148. package/offered.d.ts +39 -0
  149. package/opencode-usage.d.ts +37 -0
  150. package/outcomes.d.ts +114 -0
  151. package/package.json +74 -5
  152. package/path.d.ts +13 -0
  153. package/plan.d.ts +236 -0
  154. package/port-forward.d.ts +22 -0
  155. package/port-pipe.d.ts +36 -0
  156. package/ports-list.d.ts +19 -0
  157. package/probe-runtime.d.ts +5 -0
  158. package/probe-runtime.js +13 -0
  159. package/project-reaches.d.ts +23 -0
  160. package/projects.d.ts +136 -0
  161. package/prompts.d.ts +128 -0
  162. package/pty.d.ts +39 -0
  163. package/pulse.d.ts +8 -0
  164. package/recommend.d.ts +31 -0
  165. package/release.d.ts +41 -0
  166. package/remote-process.d.ts +26 -0
  167. package/remote-pty.d.ts +29 -0
  168. package/remote-worker.d.ts +77 -0
  169. package/remove.d.ts +31 -0
  170. package/repository.d.ts +91 -0
  171. package/retry.d.ts +34 -0
  172. package/roster.d.ts +63 -0
  173. package/saved-ports-host.d.ts +25 -0
  174. package/saved-tunnel.d.ts +44 -0
  175. package/server-worker-socket.d.ts +21 -0
  176. package/setup-areas.d.ts +7 -0
  177. package/setup-opencode-model-error.d.ts +3 -0
  178. package/setup-opencode-models.d.ts +54 -0
  179. package/setup-opencode-recipe.d.ts +26 -0
  180. package/setup-opencode.d.ts +46 -0
  181. package/setup.d.ts +102 -0
  182. package/shared-browser.d.ts +50 -0
  183. package/shell.d.ts +17 -0
  184. package/show.d.ts +106 -0
  185. package/skill-checks.d.ts +73 -0
  186. package/skill-checks.js +10 -0
  187. package/skills.d.ts +16 -0
  188. package/slot-tunnel.d.ts +27 -0
  189. package/slots.d.ts +135 -0
  190. package/snapshot.d.ts +75 -0
  191. package/splates-artifact.d.ts +3 -0
  192. package/splates-creds.d.ts +3 -0
  193. package/splates-dev.d.ts +22 -0
  194. package/splates-flags.d.ts +34 -0
  195. package/splates-lane.d.ts +3 -0
  196. package/splates-projects.d.ts +3 -0
  197. package/splates-setup.d.ts +17 -0
  198. package/splates-slots.d.ts +3 -0
  199. package/splates-todo.d.ts +3 -0
  200. package/splates-tunnel.d.ts +3 -0
  201. package/splates-worker.d.ts +3 -0
  202. package/splates.d.ts +28 -0
  203. package/stats.d.ts +186 -0
  204. package/supervise.d.ts +50 -0
  205. package/system-changes.d.ts +67 -0
  206. package/system.d.ts +28 -0
  207. package/systems.d.ts +119 -0
  208. package/systems.js +21 -0
  209. package/table.d.ts +5 -0
  210. package/task-log.d.ts +35 -0
  211. package/task-ports.d.ts +25 -0
  212. package/tell.d.ts +47 -0
  213. package/todo-edit.d.ts +60 -0
  214. package/todo-file.d.ts +6 -0
  215. package/todo-lanes.d.ts +82 -0
  216. package/todo-list.d.ts +26 -0
  217. package/todo-take.d.ts +27 -0
  218. package/todo.d.ts +146 -0
  219. package/todos.d.ts +157 -0
  220. package/tool-calls.d.ts +18 -0
  221. package/tunnel-provider.d.ts +37 -0
  222. package/tunnel-provider.js +0 -0
  223. package/tunnel-remove.d.ts +28 -0
  224. package/tunnel-setup.d.ts +104 -0
  225. package/unix-worker-listener.d.ts +23 -0
  226. package/unix-worker-socket.d.ts +30 -0
  227. package/update.d.ts +29 -0
  228. package/update.js +10 -0
  229. package/vocabulary.d.ts +9 -0
  230. package/wait.d.ts +36 -0
  231. package/watch.d.ts +46 -0
  232. package/watched.d.ts +43 -0
  233. package/websocket-worker-socket.d.ts +18 -0
  234. package/worker-call-host.d.ts +51 -0
  235. package/worker-channel.d.ts +83 -0
  236. package/worker-connection.d.ts +24 -0
  237. package/worker-daemon.d.ts +64 -0
  238. package/worker-git.d.ts +18 -0
  239. package/worker-list.d.ts +49 -0
  240. package/worker-machine.d.ts +34 -0
  241. package/worker-port-host.d.ts +21 -0
  242. package/worker-process-host.d.ts +29 -0
  243. package/worker-protocol.d.ts +104 -0
  244. package/worker-pty-host.d.ts +34 -0
  245. package/worker-registry.d.ts +68 -0
  246. package/worker-replay.d.ts +25 -0
  247. package/worker-run.d.ts +20 -0
  248. package/worker-session.d.ts +189 -0
  249. package/worker-socket.d.ts +15 -0
  250. package/worktree-service.d.ts +113 -0
  251. package/worktree.d.ts +232 -0
@@ -0,0 +1,464 @@
1
+ import {
2
+ legacyName,
3
+ legacyWarnings
4
+ } from "./index-k73tsw5g.js";
5
+
6
+ // agent-stream.ts
7
+ import { Dispatcher } from "webappwiz/events";
8
+
9
+ class AgentStream2 {
10
+ process;
11
+ readable;
12
+ writable;
13
+ dispatcher = new Dispatcher;
14
+ events = this.dispatcher.events;
15
+ base;
16
+ frames = [];
17
+ more = Promise.withResolvers();
18
+ ended = false;
19
+ partial = "";
20
+ _seq = 0;
21
+ _dispatched = 0;
22
+ _lastId = null;
23
+ _asking = null;
24
+ midFrame = false;
25
+ detaching = null;
26
+ writer = null;
27
+ writing = Promise.resolve();
28
+ constructor(process, { base = 0 } = {}) {
29
+ this.process = process;
30
+ this.base = base;
31
+ this.read(process.output);
32
+ this.readable = new ReadableStream({
33
+ pull: (controller) => this.pull(controller),
34
+ cancel: () => {
35
+ this.ended = true;
36
+ this.more.resolve();
37
+ }
38
+ }, { highWaterMark: 0 });
39
+ this.writable = new WritableStream({
40
+ write: (message) => this.send(this.outgoing(message)),
41
+ close: () => this.input().close(),
42
+ abort: (reason) => this.input().abort(reason)
43
+ });
44
+ }
45
+ get seq() {
46
+ return this._seq;
47
+ }
48
+ get dispatched() {
49
+ return this._dispatched;
50
+ }
51
+ get lastId() {
52
+ return this._lastId;
53
+ }
54
+ get asking() {
55
+ return this._asking;
56
+ }
57
+ detach() {
58
+ this.detaching ??= Promise.withResolvers();
59
+ if (!this.midFrame) {
60
+ this.detaching.resolve();
61
+ }
62
+ return this.detaching.promise;
63
+ }
64
+ respond(id, answer) {
65
+ return this.send({ jsonrpc: "2.0", id, ...answer });
66
+ }
67
+ async read(frames) {
68
+ const decoder = new TextDecoder;
69
+ try {
70
+ for await (const frame of frames) {
71
+ this.partial += decoder.decode(frame.bytes, { stream: true });
72
+ if (!this.partial.endsWith(`
73
+ `)) {
74
+ continue;
75
+ }
76
+ const lines = this.partial.split(`
77
+ `);
78
+ this.partial = "";
79
+ this.frames.push({ seq: frame.seq, messages: lines.flatMap(parse) });
80
+ this.more.resolve();
81
+ }
82
+ } catch {} finally {
83
+ this.ended = true;
84
+ this.more.resolve();
85
+ }
86
+ }
87
+ async pull(controller) {
88
+ for (;; ) {
89
+ if (this.detaching !== null && !this.midFrame) {
90
+ this.detaching.resolve();
91
+ return new Promise(() => {});
92
+ }
93
+ const frame = this.frames[0];
94
+ if (frame === undefined) {
95
+ if (this.ended) {
96
+ controller.close();
97
+ return;
98
+ }
99
+ await this.more.promise;
100
+ this.more = Promise.withResolvers();
101
+ continue;
102
+ }
103
+ const message = frame.messages.shift();
104
+ if (message === undefined) {
105
+ this.finish(frame);
106
+ continue;
107
+ }
108
+ this._seq = frame.seq;
109
+ this.midFrame = true;
110
+ const kept = this.incoming(message);
111
+ if (kept === null) {
112
+ continue;
113
+ }
114
+ this._asking = "method" in kept && "id" in kept && kept.id !== undefined ? kept.id : null;
115
+ this.dispatcher.dispatch("handling", frame.seq);
116
+ controller.enqueue(kept);
117
+ await settled();
118
+ if (frame.messages.length === 0) {
119
+ this.finish(frame);
120
+ }
121
+ return;
122
+ }
123
+ }
124
+ finish(frame) {
125
+ this.frames.shift();
126
+ this.midFrame = false;
127
+ this._dispatched = frame.seq;
128
+ this.dispatcher.dispatch("dispatched", frame.seq);
129
+ }
130
+ incoming(message) {
131
+ if ("method" in message || typeof message.id !== "number") {
132
+ return message;
133
+ }
134
+ if (message.id < this.base) {
135
+ this.dispatcher.dispatch("stale", message);
136
+ return null;
137
+ }
138
+ return { ...message, id: message.id - this.base };
139
+ }
140
+ outgoing(message) {
141
+ if (!("method" in message) || !("id" in message)) {
142
+ return message;
143
+ }
144
+ if (typeof message.id !== "number") {
145
+ return message;
146
+ }
147
+ const id = message.id + this.base;
148
+ this._lastId = id;
149
+ this.dispatcher.dispatch("request", { id, method: message.method });
150
+ return { ...message, id };
151
+ }
152
+ send(message) {
153
+ const line = new TextEncoder().encode(`${JSON.stringify(message)}
154
+ `);
155
+ const written = this.writing.then(() => this.input().write(line));
156
+ this.writing = written.catch(() => {});
157
+ return written;
158
+ }
159
+ input() {
160
+ this.writer ??= this.process.input.getWriter();
161
+ return this.writer;
162
+ }
163
+ }
164
+ function parse(line) {
165
+ const trimmed = line.trim();
166
+ if (trimmed === "") {
167
+ return [];
168
+ }
169
+ try {
170
+ const message = JSON.parse(trimmed);
171
+ return typeof message === "object" && message !== null ? [message] : [];
172
+ } catch {
173
+ return [];
174
+ }
175
+ }
176
+ function settled() {
177
+ return new Promise((resolve) => setImmediate(resolve));
178
+ }
179
+
180
+ // agent-process.ts
181
+ import * as acp from "@agentclientprotocol/sdk";
182
+ import { Duration as Duration2 } from "webappwiz/time";
183
+
184
+ // legacy-ps.ts
185
+ import {
186
+ NodePs
187
+ } from "webappwiz/system";
188
+ class LegacyNamesPs {
189
+ inner;
190
+ constructor(inner) {
191
+ this.inner = inner;
192
+ }
193
+ get platform() {
194
+ return this.inner.platform;
195
+ }
196
+ get pid() {
197
+ return this.inner.pid;
198
+ }
199
+ get hostname() {
200
+ return this.inner.hostname;
201
+ }
202
+ get args() {
203
+ return this.inner.args;
204
+ }
205
+ get self() {
206
+ return this.inner.self;
207
+ }
208
+ env(name) {
209
+ const value = this.inner.env(name);
210
+ const old = legacyName(name);
211
+ if (value !== undefined || old === null) {
212
+ return value;
213
+ }
214
+ const legacy = this.inner.env(old);
215
+ if (legacy !== undefined) {
216
+ legacyWarnings.once(old, name);
217
+ }
218
+ return legacy;
219
+ }
220
+ alive(pid) {
221
+ return this.inner.alive(pid);
222
+ }
223
+ spawn(argv, opts) {
224
+ return this.inner.spawn(argv, withLegacyEnv(opts));
225
+ }
226
+ spawnCapture(argv, opts) {
227
+ return this.inner.spawnCapture(argv, withLegacyEnv(opts));
228
+ }
229
+ start(argv, opts) {
230
+ return this.inner.start(argv, withLegacyEnv(opts));
231
+ }
232
+ startOnTerminal(argv, opts) {
233
+ return this.inner.startOnTerminal(argv, withLegacyEnv(opts));
234
+ }
235
+ processes() {
236
+ return this.inner.processes();
237
+ }
238
+ listening() {
239
+ return this.inner.listening();
240
+ }
241
+ cwd() {
242
+ return this.inner.cwd();
243
+ }
244
+ cd(path) {
245
+ this.inner.cd(path);
246
+ }
247
+ exit(code) {
248
+ this.inner.exit(code);
249
+ }
250
+ on(signal, handler) {
251
+ return this.inner.on(signal, handler);
252
+ }
253
+ once(event, handler) {
254
+ return this.inner.once(event, handler);
255
+ }
256
+ }
257
+ function systemPs() {
258
+ return new LegacyNamesPs(new NodePs);
259
+ }
260
+ function withLegacyEnv(opts) {
261
+ if (opts === undefined || opts.env === undefined && opts.unset === undefined) {
262
+ return opts;
263
+ }
264
+ const env = { ...opts.env };
265
+ for (const [name, value] of Object.entries(opts.env ?? {})) {
266
+ const old = legacyName(name);
267
+ if (old !== null && !(old in env)) {
268
+ env[old] = value;
269
+ }
270
+ }
271
+ const unset = (opts.unset ?? []).flatMap((name) => {
272
+ const old = legacyName(name);
273
+ return old === null ? [name] : [name, old];
274
+ });
275
+ return {
276
+ ...opts,
277
+ ...opts.env === undefined ? {} : { env },
278
+ ...opts.unset === undefined ? {} : { unset }
279
+ };
280
+ }
281
+
282
+ // supervise.ts
283
+ import { Duration, SystemTimer } from "webappwiz/time";
284
+ var RESTART = 75;
285
+ var UPDATE = 76;
286
+ var SERVING = "SPLATES_DEV_SERVING";
287
+ var UNBUILT = "SPLATES_DEV_UNBUILT";
288
+ var NEWEST = ["bunx", "@stringsync/splates@latest"];
289
+ var WORKER_PAUSE = Duration.secs(1);
290
+ async function supervise(ps, {
291
+ build = null,
292
+ env = {},
293
+ cwd,
294
+ worker = null,
295
+ timer = new SystemTimer
296
+ } = {}) {
297
+ let splates = ps.self;
298
+ let argv = [...splates, ...ps.args];
299
+ let building = build;
300
+ const quiet = ps.on("SIGINT", () => {});
301
+ const stopping = new AbortController;
302
+ let stopped = 0;
303
+ const stopOn = (signal, code) => ps.on(signal, () => {
304
+ stopped = code;
305
+ stopping.abort();
306
+ });
307
+ const terminated = stopOn("SIGTERM", 128 + 15);
308
+ const hungUp = stopOn("SIGHUP", 128 + 1);
309
+ const working = new AbortController;
310
+ if (worker !== null) {
311
+ keep(ps, () => [...splates, ...worker], {
312
+ env,
313
+ cwd,
314
+ signal: working.signal,
315
+ timer
316
+ });
317
+ }
318
+ try {
319
+ for (;; ) {
320
+ const built = building === null || (await ps.spawn(building.argv, { cwd: building.cwd })).exitCode === 0;
321
+ if (stopping.signal.aborted) {
322
+ return stopped;
323
+ }
324
+ let exitCode;
325
+ try {
326
+ ({ exitCode } = await ps.spawn(argv, {
327
+ env: {
328
+ ...env,
329
+ [SERVING]: "1",
330
+ ...built ? {} : { [UNBUILT]: "1" }
331
+ },
332
+ cwd,
333
+ signal: stopping.signal
334
+ }));
335
+ } catch (error) {
336
+ if (stopping.signal.aborted) {
337
+ return stopped;
338
+ }
339
+ throw error;
340
+ }
341
+ if (exitCode === UPDATE) {
342
+ splates = NEWEST;
343
+ argv = [...splates, ...ps.args];
344
+ building = null;
345
+ } else if (exitCode !== RESTART) {
346
+ return exitCode;
347
+ }
348
+ }
349
+ } finally {
350
+ working.abort();
351
+ quiet.dispose();
352
+ terminated.dispose();
353
+ hungUp.dispose();
354
+ }
355
+ }
356
+ async function keep(ps, argv, { timer, ...opts }) {
357
+ while (!opts.signal.aborted) {
358
+ await ps.spawn(argv(), opts).catch(() => {});
359
+ await new Promise((resolve) => {
360
+ const pause = timer.setTimeout(resolve, WORKER_PAUSE);
361
+ opts.signal.addEventListener("abort", () => {
362
+ pause.dispose();
363
+ resolve();
364
+ }, { once: true });
365
+ });
366
+ }
367
+ }
368
+
369
+ // agent-process.ts
370
+ function framed2(bytes) {
371
+ let seq = 0;
372
+ return bytes.pipeThrough(new TransformStream({
373
+ transform: (chunk, controller) => controller.enqueue({ bytes: chunk, seq: ++seq })
374
+ }));
375
+ }
376
+ function launcherOf(launch) {
377
+ return {
378
+ launch,
379
+ resume: (handle) => {
380
+ throw new Error(`nothing here takes back channel ${handle.channel} of worker ${handle.worker}`);
381
+ }
382
+ };
383
+ }
384
+ var launch = (argv, cwd, env) => {
385
+ const child = systemPs().start(argv, { cwd, env, unset: [SERVING] });
386
+ let tail = "";
387
+ (async () => {
388
+ const decoder = new TextDecoder;
389
+ for await (const chunk of child.stderr) {
390
+ tail = (tail + decoder.decode(chunk)).slice(-STDERR_CHARS);
391
+ }
392
+ })().catch(() => {});
393
+ return {
394
+ pid: child.pid,
395
+ input: child.stdin,
396
+ output: framed2(child.stdout),
397
+ ack: () => {},
398
+ handle: null,
399
+ stderr: () => tail,
400
+ exited: child.exited.catch((error) => {
401
+ tail = `cannot start ${argv[0]} in ${cwd}: ${error instanceof Error ? error.message : String(error)}`;
402
+ return 127;
403
+ }),
404
+ kill: () => child.kill()
405
+ };
406
+ };
407
+ var STDERR_CHARS = 2000;
408
+ var LIST_WAIT = Duration2.secs(30);
409
+ var LIST_PAGES = 10;
410
+ async function listSessions(agent, cwd, run, timer) {
411
+ const process = run(agent.argv, cwd, {});
412
+ let timeout = null;
413
+ try {
414
+ const connection = new acp.ClientSideConnection(() => ({
415
+ sessionUpdate: async () => {},
416
+ requestPermission: async () => ({ outcome: { outcome: "cancelled" } })
417
+ }), new AgentStream2(process));
418
+ const listing = (async () => {
419
+ const initialized = await connection.initialize({
420
+ protocolVersion: acp.PROTOCOL_VERSION,
421
+ clientCapabilities: {}
422
+ });
423
+ const capabilities = initialized.agentCapabilities;
424
+ if (capabilities?.loadSession !== true || capabilities.sessionCapabilities?.list == null) {
425
+ return [];
426
+ }
427
+ const sessions = [];
428
+ let cursor = null;
429
+ for (let page = 0;page < LIST_PAGES; page++) {
430
+ const listed = await connection.listSessions({
431
+ cwd,
432
+ cursor
433
+ });
434
+ for (const each of listed.sessions) {
435
+ if (each.cwd === cwd) {
436
+ sessions.push({
437
+ agent: agent.id,
438
+ session: each.sessionId,
439
+ title: each.title ?? null,
440
+ updatedAt: each.updatedAt ?? null
441
+ });
442
+ }
443
+ }
444
+ cursor = listed.nextCursor ?? null;
445
+ if (cursor === null) {
446
+ break;
447
+ }
448
+ }
449
+ return sessions;
450
+ })();
451
+ const gaveUp = new Promise((_, reject) => {
452
+ timeout = timer.setTimeout(() => reject(new Error(`${agent.name} did not list its sessions`)), LIST_WAIT);
453
+ });
454
+ const died = process.exited.then((code) => {
455
+ throw new Error(`${agent.name} exited with code ${code}`);
456
+ });
457
+ return await Promise.race([listing, gaveUp, died]);
458
+ } finally {
459
+ timeout?.dispose();
460
+ process.kill();
461
+ }
462
+ }
463
+
464
+ export { AgentStream2, systemPs, RESTART, UPDATE, SERVING, UNBUILT, supervise, framed2, launcherOf, launch, listSessions };