clanka 0.21.0 → 0.22.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.
- package/dist/Acp.test.js +19 -7
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts +4 -4
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +140 -99
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +5 -4
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentBashJobs.test.js +47 -32
- package/dist/AgentBashJobs.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.js +26 -7
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +71 -41
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +86 -79
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +108 -83
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +2 -2
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +3 -2
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +218 -29
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +318 -290
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +218 -199
- package/dist/AgentTools.js.map +1 -1
- package/dist/AgentTools.test.js +2 -2
- package/dist/AgentTools.test.js.map +1 -1
- package/dist/bin/cli.mjs +308 -289
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +31 -10
- package/src/Agent.test.ts +5 -4
- package/src/Agent.ts +175 -140
- package/src/AgentBashJobs.test.ts +70 -38
- package/src/AgentCallerConfig.test.ts +39 -7
- package/src/AgentExecutor.test.ts +132 -91
- package/src/AgentExecutor.ts +120 -105
- package/src/AgentExecutorImage.test.ts +2 -2
- package/src/AgentImage.test.ts +4 -3
- package/src/AgentSubagents.test.ts +825 -562
- package/src/AgentTools.test.ts +2 -2
- package/src/AgentTools.ts +331 -288
package/src/AgentTools.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as ExaSearch from "./ExaSearch.ts"
|
|
|
7
7
|
import * as WebToMarkdown from "./WebToMarkdown.ts"
|
|
8
8
|
import type * as HttpClient from "effect/http/HttpClient"
|
|
9
9
|
import type * as PlatformError from "effect/PlatformError"
|
|
10
|
+
import * as Clock from "effect/Clock"
|
|
10
11
|
import * as Context from "effect/Context"
|
|
11
12
|
import * as Duration from "effect/Duration"
|
|
12
13
|
import * as Effect from "effect/Effect"
|
|
@@ -57,130 +58,153 @@ export class TaskCompleter extends Context.Service<
|
|
|
57
58
|
>()("clanka/AgentTools/TaskCompleter") {}
|
|
58
59
|
|
|
59
60
|
/**
|
|
61
|
+
* What a task is: a background `bash` command or a sub-agent started with
|
|
62
|
+
* `delegate`.
|
|
63
|
+
*
|
|
60
64
|
* @since 1.0.0
|
|
61
65
|
* @category Models
|
|
62
66
|
*/
|
|
63
|
-
export const
|
|
64
|
-
"completed",
|
|
65
|
-
"running",
|
|
66
|
-
"failed",
|
|
67
|
-
"cancelled",
|
|
68
|
-
])
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
* @category Models
|
|
73
|
-
*/
|
|
74
|
-
export type SubagentStatus = typeof SubagentStatus.Type
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @since 1.0.0
|
|
78
|
-
* @category Models
|
|
79
|
-
*/
|
|
80
|
-
export const SubagentResult = Schema.Struct({
|
|
81
|
-
id: Schema.String,
|
|
82
|
-
status: SubagentStatus,
|
|
83
|
-
output: Schema.optional(Schema.String),
|
|
84
|
-
})
|
|
67
|
+
export const TaskKind = Schema.Literals(["bash", "agent"])
|
|
85
68
|
|
|
86
69
|
/**
|
|
87
70
|
* @since 1.0.0
|
|
88
71
|
* @category Models
|
|
89
72
|
*/
|
|
90
|
-
export type
|
|
73
|
+
export type TaskKind = typeof TaskKind.Type
|
|
91
74
|
|
|
92
75
|
/**
|
|
93
76
|
* @since 1.0.0
|
|
94
77
|
* @category Models
|
|
95
78
|
*/
|
|
96
|
-
export const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
export const TaskStatus = Schema.Literals([
|
|
80
|
+
"running",
|
|
81
|
+
"completed",
|
|
82
|
+
"failed",
|
|
83
|
+
"stopped",
|
|
84
|
+
])
|
|
100
85
|
|
|
101
86
|
/**
|
|
102
87
|
* @since 1.0.0
|
|
103
88
|
* @category Models
|
|
104
89
|
*/
|
|
105
|
-
export type
|
|
90
|
+
export type TaskStatus = typeof TaskStatus.Type
|
|
106
91
|
|
|
107
92
|
/**
|
|
93
|
+
* A background `bash` command or a sub-agent, as returned by the task
|
|
94
|
+
* functions. Both kinds share one id space per executor.
|
|
95
|
+
*
|
|
108
96
|
* @since 1.0.0
|
|
109
97
|
* @category Models
|
|
110
98
|
*/
|
|
111
|
-
export const
|
|
112
|
-
id: Schema.String
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
export const Task = Schema.Struct({
|
|
100
|
+
id: Schema.String.annotate({
|
|
101
|
+
documentation: "The task id, which can be managed with the task tools.",
|
|
102
|
+
}),
|
|
103
|
+
kind: TaskKind,
|
|
104
|
+
status: TaskStatus,
|
|
105
|
+
/** The bash command, or the sub-agent's prompt. */
|
|
106
|
+
description: Schema.String,
|
|
107
|
+
/** Output so far while running; the final output, or the error, once ended. */
|
|
108
|
+
output: Schema.String,
|
|
109
|
+
/** bash only: set when the command exited on its own. */
|
|
110
|
+
exitCode: Schema.optional(Schema.Number),
|
|
115
111
|
})
|
|
116
112
|
|
|
117
113
|
/**
|
|
118
114
|
* @since 1.0.0
|
|
119
115
|
* @category Models
|
|
120
116
|
*/
|
|
121
|
-
export type
|
|
117
|
+
export type Task = typeof Task.Type
|
|
122
118
|
|
|
123
119
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
120
|
+
* The sub-agent side of the task functions, for one agent. The executor
|
|
121
|
+
* resolves bash tasks itself and hands agent tasks to these, so every
|
|
122
|
+
* function only receives ids of agents that this agent started.
|
|
126
123
|
*
|
|
127
124
|
* @since 1.0.0
|
|
128
125
|
* @category Models
|
|
129
126
|
*/
|
|
130
|
-
export interface
|
|
127
|
+
export interface AgentTasks {
|
|
131
128
|
/**
|
|
132
|
-
* Start a sub-agent
|
|
133
|
-
* finished, and dies if the agent failed.
|
|
134
|
-
* straight away with `status: "running"`.
|
|
129
|
+
* Start a sub-agent under the id the executor allocated. In the foreground
|
|
130
|
+
* it resolves once the agent has finished, and dies if the agent failed.
|
|
131
|
+
* In the background it resolves straight away with `status: "running"`.
|
|
135
132
|
*/
|
|
136
133
|
readonly delegate: (options: {
|
|
134
|
+
readonly id: string
|
|
137
135
|
readonly prompt: string
|
|
138
136
|
readonly background: boolean
|
|
139
|
-
}) => Effect.Effect<
|
|
137
|
+
}) => Effect.Effect<Task>
|
|
140
138
|
/**
|
|
141
|
-
*
|
|
142
|
-
* Failures are returned as results, not raised.
|
|
139
|
+
* The agent's status and output so far. A final status counts as reported.
|
|
143
140
|
*/
|
|
144
|
-
readonly
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
readonly taskOutput: (id: string) => Effect.Effect<Task, string>
|
|
142
|
+
/**
|
|
143
|
+
* Wait up to `timeoutMs` for the listed agents to end, then report the
|
|
144
|
+
* ones that ended all at once. Agents still running at the deadline are
|
|
145
|
+
* returned as running and keep going. Failures are returned as tasks, not
|
|
146
|
+
* raised. The executor calls it once per batch, after waiting for any bash
|
|
147
|
+
* tasks in the batch, with the time left, so nothing is reported while the
|
|
148
|
+
* batch is still waiting.
|
|
149
|
+
*/
|
|
150
|
+
readonly waitTasks: (
|
|
151
|
+
ids: ReadonlyArray<string>,
|
|
152
|
+
options: { readonly timeoutMs: number },
|
|
153
|
+
) => Effect.Effect<ReadonlyArray<Task>, string>
|
|
147
154
|
/**
|
|
148
155
|
* Steer a running agent, or start a new turn on a finished one.
|
|
149
156
|
*/
|
|
150
157
|
readonly messageAgent: (options: {
|
|
151
158
|
readonly id: string
|
|
152
159
|
readonly message: string
|
|
153
|
-
}) => Effect.Effect<
|
|
160
|
+
}) => Effect.Effect<void, string>
|
|
154
161
|
/**
|
|
155
162
|
* Interrupt an agent and everything it spawned.
|
|
156
163
|
*/
|
|
157
|
-
readonly
|
|
158
|
-
|
|
164
|
+
readonly stopTask: (id: string) => Effect.Effect<Task, string>
|
|
165
|
+
/**
|
|
166
|
+
* The agents this agent started.
|
|
167
|
+
*/
|
|
168
|
+
readonly listTasks: Effect.Effect<ReadonlyArray<Task>>
|
|
159
169
|
}
|
|
160
170
|
|
|
161
171
|
/**
|
|
162
172
|
* @since 1.0.0
|
|
163
173
|
* @category Context
|
|
164
174
|
*/
|
|
165
|
-
export class
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
>()("clanka/AgentTools/
|
|
175
|
+
export class AgentTaskExecutor extends Context.Service<
|
|
176
|
+
AgentTaskExecutor,
|
|
177
|
+
AgentTasks
|
|
178
|
+
>()("clanka/AgentTools/AgentTaskExecutor") {}
|
|
169
179
|
|
|
170
180
|
/**
|
|
171
|
-
*
|
|
181
|
+
* An `AgentTasks` implementation for contexts that cannot spawn agents.
|
|
172
182
|
*
|
|
173
183
|
* @since 1.0.0
|
|
174
184
|
* @category Context
|
|
175
185
|
*/
|
|
176
|
-
export const
|
|
186
|
+
export const agentTasksUnavailable: AgentTasks = {
|
|
177
187
|
delegate: () => Effect.die(new Error("Sub-agents are not available here")),
|
|
178
|
-
|
|
188
|
+
taskOutput: () => Effect.fail("Sub-agents are not available here"),
|
|
189
|
+
waitTasks: () => Effect.fail("Sub-agents are not available here"),
|
|
179
190
|
messageAgent: () => Effect.fail("Sub-agents are not available here"),
|
|
180
|
-
|
|
181
|
-
|
|
191
|
+
stopTask: () => Effect.fail("Sub-agents are not available here"),
|
|
192
|
+
listTasks: Effect.succeed([]),
|
|
182
193
|
}
|
|
183
194
|
|
|
195
|
+
/**
|
|
196
|
+
* The agent running the current script. Tasks are only visible to the agent
|
|
197
|
+
* that started them; scripts without an agent share the `undefined` owner.
|
|
198
|
+
* The executor sets it from `ExecuteOptions.agentId`.
|
|
199
|
+
*
|
|
200
|
+
* @since 1.0.0
|
|
201
|
+
* @category Context
|
|
202
|
+
*/
|
|
203
|
+
export class TaskOwner extends Context.Reference<string | undefined>(
|
|
204
|
+
"clanka/AgentTools/TaskOwner",
|
|
205
|
+
{ defaultValue: () => undefined },
|
|
206
|
+
) {}
|
|
207
|
+
|
|
184
208
|
/**
|
|
185
209
|
* An image read by `readFile`, handed to the Agent so it can be spliced onto
|
|
186
210
|
* the Prompt for the next model turn.
|
|
@@ -204,74 +228,36 @@ export class ImageAttacher extends Context.Service<
|
|
|
204
228
|
>()("clanka/AgentTools/ImageAttacher") {}
|
|
205
229
|
|
|
206
230
|
/**
|
|
207
|
-
*
|
|
208
|
-
* @category Models
|
|
209
|
-
*/
|
|
210
|
-
export const BashJobStatus = Schema.Literals([
|
|
211
|
-
"running",
|
|
212
|
-
"completed",
|
|
213
|
-
"failed",
|
|
214
|
-
"stopped",
|
|
215
|
-
])
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* @since 1.0.0
|
|
219
|
-
* @category Models
|
|
220
|
-
*/
|
|
221
|
-
export type BashJobStatus = typeof BashJobStatus.Type
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* A `bash` command and its state: the task that `bash`, `jobOutput`,
|
|
225
|
-
* `waitJob` and `stopJob` return. `exitCode` is set once the command has
|
|
226
|
-
* exited; a non-zero exit is `failed`. A foreground `bash` command that
|
|
227
|
-
* fails rejects instead of returning a task.
|
|
231
|
+
* A task that has started, handed to the `TaskWatcher`.
|
|
228
232
|
*
|
|
229
233
|
* @since 1.0.0
|
|
230
234
|
* @category Models
|
|
231
235
|
*/
|
|
232
|
-
export
|
|
233
|
-
id: Schema.String,
|
|
234
|
-
status: BashJobStatus,
|
|
235
|
-
exitCode: Schema.optional(Schema.Number),
|
|
236
|
-
output: Schema.String,
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* @since 1.0.0
|
|
241
|
-
* @category Models
|
|
242
|
-
*/
|
|
243
|
-
export type BashJob = typeof BashJob.Type
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* A background `bash` job, handed to the `JobWatcher` when it starts.
|
|
247
|
-
*
|
|
248
|
-
* @since 1.0.0
|
|
249
|
-
* @category Models
|
|
250
|
-
*/
|
|
251
|
-
export interface BackgroundJob {
|
|
236
|
+
export interface TaskHandle {
|
|
252
237
|
readonly id: string
|
|
253
|
-
|
|
254
|
-
|
|
238
|
+
readonly kind: TaskKind
|
|
239
|
+
/** Waits for the task to end and succeeds with its final state. */
|
|
240
|
+
readonly await: Effect.Effect<Task>
|
|
255
241
|
/**
|
|
256
|
-
* Marks the
|
|
257
|
-
* already was: by `
|
|
258
|
-
* an earlier `claim`.
|
|
242
|
+
* Marks the task's final state as reported. Succeeds with `false` when it
|
|
243
|
+
* already was: by `stopTask`, `waitTasks`, a `taskOutput` call that
|
|
244
|
+
* returned it, or an earlier `claim`.
|
|
259
245
|
*/
|
|
260
246
|
readonly claim: Effect.Effect<boolean>
|
|
261
247
|
}
|
|
262
248
|
|
|
263
249
|
/**
|
|
264
|
-
* Receives every background `bash`
|
|
250
|
+
* Receives every background `bash` task as it starts: those started with
|
|
265
251
|
* `background: true` and those moved to the background at their timeout. A
|
|
266
252
|
* command that `bash` returns finished is never handed over.
|
|
267
|
-
* The executor sets it from `ExecuteOptions.
|
|
253
|
+
* The executor sets it from `ExecuteOptions.onTask`.
|
|
268
254
|
*
|
|
269
255
|
* @since 1.0.0
|
|
270
256
|
* @category Context
|
|
271
257
|
*/
|
|
272
|
-
export class
|
|
273
|
-
(
|
|
274
|
-
>("clanka/AgentTools/
|
|
258
|
+
export class TaskWatcher extends Context.Reference<
|
|
259
|
+
(task: TaskHandle) => Effect.Effect<void>
|
|
260
|
+
>("clanka/AgentTools/TaskWatcher", {
|
|
275
261
|
defaultValue: () => () => Effect.void,
|
|
276
262
|
}) {}
|
|
277
263
|
|
|
@@ -321,21 +307,20 @@ export class CommandLimits extends Context.Reference<{
|
|
|
321
307
|
*/
|
|
322
308
|
export const makeBashTool = (timeout: Duration.Duration) =>
|
|
323
309
|
Tool.make("bash", {
|
|
324
|
-
description:
|
|
325
|
-
'Run a bash command and return a task with its job id, status, exit code and output. A command that fails before it is returned rejects with its exit code and output. With `background: true` it returns straight away with status "running" while the command keeps going. A command still running at its timeout is not stopped: it is moved to the background and returned as "running" with the output so far. Wait for a job with "waitJob", read it with "jobOutput" and stop it with "stopJob"; a background job that fails is reported with status "failed" and its exitCode.',
|
|
310
|
+
description: "Run a bash command and return a task.",
|
|
326
311
|
parameters: Schema.Struct({
|
|
327
312
|
command: Schema.String,
|
|
328
313
|
timeoutMs: Schema.optional(Schema.Finite).annotate({
|
|
329
|
-
documentation: `How long to wait in ms before moving the
|
|
314
|
+
documentation: `How long to wait in ms before moving the task to the background (default and max: ${Duration.toMillis(timeout)})`,
|
|
330
315
|
}),
|
|
331
316
|
background: Schema.optional(Schema.Boolean).annotate({
|
|
332
317
|
documentation:
|
|
333
|
-
|
|
318
|
+
"Start the command in the background. Defaults to false which always returns 'completed' tasks.",
|
|
334
319
|
}),
|
|
335
320
|
}).annotate({
|
|
336
321
|
identifier: "command",
|
|
337
322
|
}),
|
|
338
|
-
success:
|
|
323
|
+
success: Task,
|
|
339
324
|
dependencies: [CurrentDirectory],
|
|
340
325
|
})
|
|
341
326
|
|
|
@@ -350,7 +335,7 @@ const globNamesDirectory = (glob: string) =>
|
|
|
350
335
|
* @category Context
|
|
351
336
|
*/
|
|
352
337
|
export const makeContextNoop = (cwd?: string) =>
|
|
353
|
-
|
|
338
|
+
AgentTaskExecutor.context(agentTasksUnavailable).pipe(
|
|
354
339
|
Context.add(CurrentDirectory, cwd ?? "/"),
|
|
355
340
|
Context.add(DirectoryChanger, () => Effect.die("Not implemented")),
|
|
356
341
|
Context.add(TaskCompleter, () => Effect.void),
|
|
@@ -364,14 +349,14 @@ export const makeContextNoop = (cwd?: string) =>
|
|
|
364
349
|
export const AgentTools = Toolkit.make(
|
|
365
350
|
Tool.make("changeDirectory", {
|
|
366
351
|
description:
|
|
367
|
-
"Change the executor's working directory to an existing directory and return its absolute path.
|
|
352
|
+
"Change the executor's working directory to an existing directory and return its absolute path. The change persists across your scripts.",
|
|
368
353
|
parameters: Schema.String.annotate({ identifier: "directory" }),
|
|
369
354
|
success: Schema.String,
|
|
370
355
|
dependencies: [DirectoryChanger],
|
|
371
356
|
}),
|
|
372
357
|
Tool.make("readFile", {
|
|
373
358
|
description:
|
|
374
|
-
"Read a file and optionally filter the lines to return. Returns null if the file doesn't exist. For png/jpeg/gif/webp files the image itself is attached to your next turn
|
|
359
|
+
"Read a file and optionally filter the lines to return. Returns null if the file doesn't exist. For png/jpeg/gif/webp files the image itself is attached to your next turn.",
|
|
375
360
|
parameters: Schema.Struct({
|
|
376
361
|
path: Schema.String,
|
|
377
362
|
startLine: Schema.optional(Schema.Number),
|
|
@@ -404,52 +389,23 @@ export const AgentTools = Toolkit.make(
|
|
|
404
389
|
}),
|
|
405
390
|
Tool.make("delegate", {
|
|
406
391
|
description:
|
|
407
|
-
|
|
392
|
+
"Delegate a task to another software engineer / sub-agent. With `background: true` the sub-agent works in the background, and its result is sent to you when it finishes.",
|
|
408
393
|
parameters: Schema.Struct({
|
|
409
394
|
prompt: Schema.String,
|
|
410
395
|
background: Schema.optional(Schema.Boolean),
|
|
411
396
|
}),
|
|
412
|
-
success:
|
|
413
|
-
failure: Schema.String,
|
|
414
|
-
dependencies: [SubagentExecutor],
|
|
415
|
-
}),
|
|
416
|
-
Tool.make("waitAgents", {
|
|
417
|
-
description:
|
|
418
|
-
'Wait until the given sub-agents have finished, or all of your sub-agents when no ids are passed. A failed agent is returned with status "failed" and its error as the output; it does not throw.',
|
|
419
|
-
parameters: Schema.UndefinedOr(Schema.Array(Schema.String)).annotate({
|
|
420
|
-
identifier: "ids",
|
|
421
|
-
}),
|
|
422
|
-
success: Schema.Array(SubagentResult),
|
|
397
|
+
success: Task,
|
|
423
398
|
failure: Schema.String,
|
|
424
|
-
dependencies: [
|
|
399
|
+
dependencies: [AgentTaskExecutor],
|
|
425
400
|
}),
|
|
426
401
|
Tool.make("messageAgent", {
|
|
427
|
-
description:
|
|
428
|
-
"Send a message to one of your sub-agents. A running agent receives it as steering; a finished agent starts a new turn on top of its previous conversation. Returns straight away; the result is sent to you as a <subagent> message.",
|
|
402
|
+
description: "Send a message to one of your sub-agents.",
|
|
429
403
|
parameters: Schema.Struct({
|
|
430
404
|
id: Schema.String,
|
|
431
405
|
message: Schema.String,
|
|
432
406
|
}),
|
|
433
|
-
success: SubagentResult,
|
|
434
407
|
failure: Schema.String,
|
|
435
|
-
dependencies: [
|
|
436
|
-
}),
|
|
437
|
-
Tool.make("stopAgent", {
|
|
438
|
-
description:
|
|
439
|
-
"Stop one of your sub-agents and every agent it started. Returns its final status.",
|
|
440
|
-
parameters: Schema.String.annotate({
|
|
441
|
-
identifier: "id",
|
|
442
|
-
}),
|
|
443
|
-
success: SubagentResult,
|
|
444
|
-
failure: Schema.String,
|
|
445
|
-
dependencies: [SubagentExecutor],
|
|
446
|
-
}),
|
|
447
|
-
Tool.make("listAgents", {
|
|
448
|
-
description:
|
|
449
|
-
"List the sub-agents you have started in this run, with their status.",
|
|
450
|
-
parameters: Schema.Void,
|
|
451
|
-
success: Schema.Array(SubagentInfo),
|
|
452
|
-
dependencies: [SubagentExecutor],
|
|
408
|
+
dependencies: [AgentTaskExecutor],
|
|
453
409
|
}),
|
|
454
410
|
Tool.make("glob", {
|
|
455
411
|
description: "Find files matching a glob pattern.",
|
|
@@ -469,36 +425,44 @@ export const AgentTools = Toolkit.make(
|
|
|
469
425
|
dependencies: [CurrentDirectory],
|
|
470
426
|
}),
|
|
471
427
|
makeBashTool(defaultBashTimeout),
|
|
472
|
-
Tool.make("
|
|
428
|
+
Tool.make("taskOutput", {
|
|
473
429
|
description:
|
|
474
|
-
"Return the status and output so far of a background bash
|
|
430
|
+
"Return the status and output so far of one of your tasks: a background bash command or a sub-agent.",
|
|
475
431
|
parameters: Schema.String.annotate({
|
|
476
432
|
identifier: "id",
|
|
477
433
|
}),
|
|
478
|
-
success:
|
|
434
|
+
success: Task,
|
|
479
435
|
failure: Schema.String,
|
|
436
|
+
dependencies: [AgentTaskExecutor],
|
|
480
437
|
}),
|
|
481
|
-
Tool.make("
|
|
438
|
+
Tool.make("waitTasks", {
|
|
482
439
|
description:
|
|
483
|
-
|
|
440
|
+
"Wait until the given tasks have ended and return them, in the order given.",
|
|
484
441
|
parameters: Schema.Struct({
|
|
485
|
-
|
|
442
|
+
ids: Schema.Array(Schema.String),
|
|
486
443
|
timeoutMs: Schema.optional(Schema.Finite).annotate({
|
|
487
444
|
documentation:
|
|
488
|
-
"How long to wait in ms (default and max: the bash timeout)",
|
|
445
|
+
"How long to wait in ms (default and max: the bash command timeout)",
|
|
489
446
|
}),
|
|
490
447
|
}),
|
|
491
|
-
success:
|
|
448
|
+
success: Schema.Array(Task),
|
|
492
449
|
failure: Schema.String,
|
|
450
|
+
dependencies: [AgentTaskExecutor],
|
|
493
451
|
}),
|
|
494
|
-
Tool.make("
|
|
495
|
-
description:
|
|
496
|
-
"Stop a background bash job and return its final status and output.",
|
|
452
|
+
Tool.make("stopTask", {
|
|
453
|
+
description: "Stop one of your tasks.",
|
|
497
454
|
parameters: Schema.String.annotate({
|
|
498
455
|
identifier: "id",
|
|
499
456
|
}),
|
|
500
|
-
success:
|
|
457
|
+
success: Task,
|
|
501
458
|
failure: Schema.String,
|
|
459
|
+
dependencies: [AgentTaskExecutor],
|
|
460
|
+
}),
|
|
461
|
+
Tool.make("listTasks", {
|
|
462
|
+
description: "List the tasks you have started, with their status.",
|
|
463
|
+
parameters: Schema.Void,
|
|
464
|
+
success: Schema.Array(Task),
|
|
465
|
+
dependencies: [AgentTaskExecutor],
|
|
502
466
|
}),
|
|
503
467
|
Tool.make("applyPatch", {
|
|
504
468
|
description:
|
|
@@ -639,59 +603,58 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
639
603
|
return { fiber, output: output.render }
|
|
640
604
|
})
|
|
641
605
|
|
|
642
|
-
// Every
|
|
643
|
-
//
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
return
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
606
|
+
// Every task started on this executor, bash and agent alike, so both
|
|
607
|
+
// kinds share one id space. Each is only visible to the agent that
|
|
608
|
+
// started it.
|
|
609
|
+
const tasks = new Map<string, TaskEntry>()
|
|
610
|
+
let nextTaskId = 1
|
|
611
|
+
const registerAgentTask = Effect.fnUntraced(function* () {
|
|
612
|
+
const id = String(nextTaskId++)
|
|
613
|
+
tasks.set(id, { kind: "agent", id, owner: yield* TaskOwner })
|
|
614
|
+
return id
|
|
615
|
+
})
|
|
616
|
+
// Every `bash` command is a task, so any of them can be addressed by
|
|
617
|
+
// id. Only the ones still running when `bash` returns go to the
|
|
618
|
+
// `TaskWatcher`.
|
|
619
|
+
const addBashTask = Effect.fnUntraced(function* (
|
|
620
|
+
description: string,
|
|
621
|
+
command: Omit<RunningCommand, "reported">,
|
|
655
622
|
) {
|
|
656
|
-
const
|
|
623
|
+
const entry: BashEntry = {
|
|
624
|
+
kind: "bash",
|
|
625
|
+
id: String(nextTaskId++),
|
|
626
|
+
owner: yield* TaskOwner,
|
|
627
|
+
description,
|
|
628
|
+
command: { ...command, reported: false },
|
|
629
|
+
}
|
|
630
|
+
tasks.set(entry.id, entry)
|
|
631
|
+
return entry
|
|
632
|
+
})
|
|
633
|
+
const watchBashTask = Effect.fnUntraced(function* (entry: BashEntry) {
|
|
634
|
+
const watch = yield* TaskWatcher
|
|
657
635
|
yield* watch({
|
|
658
|
-
id,
|
|
659
|
-
|
|
660
|
-
|
|
636
|
+
id: entry.id,
|
|
637
|
+
kind: "bash",
|
|
638
|
+
await: Fiber.await(entry.command.fiber).pipe(
|
|
639
|
+
Effect.map(() => bashTask(entry)),
|
|
661
640
|
),
|
|
662
641
|
claim: Effect.sync(() => {
|
|
663
|
-
if (
|
|
664
|
-
|
|
642
|
+
if (entry.command.reported) return false
|
|
643
|
+
entry.command.reported = true
|
|
665
644
|
return true
|
|
666
645
|
}),
|
|
667
646
|
})
|
|
668
647
|
})
|
|
669
|
-
const
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return job
|
|
680
|
-
}
|
|
681
|
-
// Waits up to `timeout` for a command to exit. A caller that is
|
|
682
|
-
// interrupted first stops the command.
|
|
683
|
-
const awaitCommand = (
|
|
684
|
-
running: RunningCommand | Omit<RunningCommand, "reported">,
|
|
685
|
-
timeout: Duration.Duration | undefined,
|
|
686
|
-
) => {
|
|
687
|
-
const awaited = Fiber.await(running.fiber)
|
|
688
|
-
return (
|
|
689
|
-
timeout === undefined
|
|
690
|
-
? Effect.asSome(awaited)
|
|
691
|
-
: Effect.timeoutOption(awaited, timeout)
|
|
692
|
-
).pipe(Effect.onInterrupt(() => Fiber.interrupt(running.fiber)))
|
|
693
|
-
}
|
|
694
|
-
|
|
648
|
+
const findTask = Effect.fnUntraced(function* (id: string) {
|
|
649
|
+
const owner = yield* TaskOwner
|
|
650
|
+
const entry = tasks.get(id)
|
|
651
|
+
if (entry === undefined || entry.owner !== owner) {
|
|
652
|
+
return yield* Effect.fail(
|
|
653
|
+
`No task with id ${JSON.stringify(id)}. You can only address tasks you started; call listTasks() to see them.`,
|
|
654
|
+
)
|
|
655
|
+
}
|
|
656
|
+
return entry
|
|
657
|
+
})
|
|
695
658
|
/**
|
|
696
659
|
* Image branch of `readFile`: the bytes go to the `ImageAttacher` for
|
|
697
660
|
* the next model turn and the script only sees a marker.
|
|
@@ -907,17 +870,23 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
907
870
|
cwd,
|
|
908
871
|
stdin: "ignore",
|
|
909
872
|
})
|
|
910
|
-
const
|
|
873
|
+
const entry = yield* addBashTask(
|
|
874
|
+
options.command,
|
|
875
|
+
yield* startCommand(cmd),
|
|
876
|
+
)
|
|
911
877
|
if (options.background !== true) {
|
|
912
|
-
const exit = yield* awaitCommand(
|
|
878
|
+
const exit = yield* awaitCommand(
|
|
879
|
+
entry.command,
|
|
880
|
+
Duration.millis(timeoutMs),
|
|
881
|
+
)
|
|
913
882
|
if (Option.isSome(exit)) {
|
|
914
883
|
// A finished command is reported here, so it is never pushed.
|
|
915
884
|
const exitCode = yield* exit.value
|
|
916
|
-
const
|
|
917
|
-
if (exitCode === 0) return
|
|
885
|
+
const task = reportBash(entry)
|
|
886
|
+
if (exitCode === 0) return task
|
|
918
887
|
return yield* Effect.die(
|
|
919
888
|
new Error(
|
|
920
|
-
`Command failed with exit code ${exitCode}: ${
|
|
889
|
+
`Command failed with exit code ${exitCode}: ${task.output}`,
|
|
921
890
|
),
|
|
922
891
|
)
|
|
923
892
|
}
|
|
@@ -925,38 +894,93 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
925
894
|
// Snapshot the task before yielding to the watcher: the command can
|
|
926
895
|
// finish while it is being handed over, and its final state must
|
|
927
896
|
// reach the model only once. A finished task is never handed over.
|
|
928
|
-
const
|
|
929
|
-
if (
|
|
930
|
-
return
|
|
897
|
+
const task = reportBash(entry)
|
|
898
|
+
if (task.status === "running") yield* watchBashTask(entry)
|
|
899
|
+
return task
|
|
931
900
|
}, Effect.orDie),
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
901
|
+
taskOutput: Effect.fn("AgentTools.taskOutput")(function* (
|
|
902
|
+
input: unknown,
|
|
903
|
+
) {
|
|
904
|
+
const id = yield* decodeTaskOutput(input)
|
|
905
|
+
yield* Effect.logInfo(`Calling "taskOutput"`).pipe(
|
|
935
906
|
Effect.annotateLogs({ id }),
|
|
936
907
|
)
|
|
937
|
-
|
|
908
|
+
const entry = yield* findTask(id)
|
|
909
|
+
if (entry.kind === "bash") return reportBash(entry)
|
|
910
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
911
|
+
return yield* agentTasks.taskOutput(id)
|
|
938
912
|
}),
|
|
939
|
-
|
|
940
|
-
const
|
|
913
|
+
waitTasks: Effect.fn("AgentTools.waitTasks")(function* (input: unknown) {
|
|
914
|
+
const { ids, timeoutMs: requestedMs } = yield* decodeWaitTasks(input)
|
|
941
915
|
const maxMs = bashTimeoutMs(yield* CommandLimits)
|
|
942
|
-
const timeoutMs = Math.min(
|
|
943
|
-
yield* Effect.logInfo(`Calling "
|
|
944
|
-
Effect.annotateLogs({
|
|
916
|
+
const timeoutMs = Math.min(requestedMs ?? maxMs, maxMs)
|
|
917
|
+
yield* Effect.logInfo(`Calling "waitTasks"`).pipe(
|
|
918
|
+
Effect.annotateLogs({ ids, timeoutMs }),
|
|
919
|
+
)
|
|
920
|
+
const entries = yield* Effect.forEach(ids, findTask)
|
|
921
|
+
const bashEntries = entries.filter(
|
|
922
|
+
(entry): entry is BashEntry => entry.kind === "bash",
|
|
923
|
+
)
|
|
924
|
+
const agentIds = entries.flatMap((entry) =>
|
|
925
|
+
entry.kind === "agent" ? [entry.id] : [],
|
|
926
|
+
)
|
|
927
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
928
|
+
// Nothing is reported until the batch is ready to return: a script
|
|
929
|
+
// stopped while it waits never receives it, so the tasks that ended
|
|
930
|
+
// first must still be pushed. The bash tasks are waited for first,
|
|
931
|
+
// without reporting them. Then one `AgentTasks.waitTasks` call waits
|
|
932
|
+
// for the agents with the time left and reports them together, so
|
|
933
|
+
// over RPC only its single response can be cut off. The agents keep
|
|
934
|
+
// running meanwhile. Tasks still running at the deadline are
|
|
935
|
+
// returned as running and keep going.
|
|
936
|
+
const startedAt = yield* Clock.currentTimeMillis
|
|
937
|
+
yield* Effect.forEach(
|
|
938
|
+
bashEntries,
|
|
939
|
+
(entry) => Fiber.await(entry.command.fiber),
|
|
940
|
+
{ concurrency: "unbounded", discard: true },
|
|
941
|
+
).pipe(Effect.timeoutOption(timeoutMs))
|
|
942
|
+
const agentResults =
|
|
943
|
+
agentIds.length === 0
|
|
944
|
+
? []
|
|
945
|
+
: yield* agentTasks.waitTasks(agentIds, {
|
|
946
|
+
timeoutMs: Math.max(
|
|
947
|
+
0,
|
|
948
|
+
timeoutMs - ((yield* Clock.currentTimeMillis) - startedAt),
|
|
949
|
+
),
|
|
950
|
+
})
|
|
951
|
+
const ended = new Map(
|
|
952
|
+
[...bashEntries.map(reportBash), ...agentResults].map((task) => [
|
|
953
|
+
task.id,
|
|
954
|
+
task,
|
|
955
|
+
]),
|
|
945
956
|
)
|
|
946
|
-
|
|
947
|
-
// Ending the wait leaves the job running.
|
|
948
|
-
yield* Effect.timeoutOption(Fiber.await(running.fiber), timeoutMs)
|
|
949
|
-
return reportJob(options.id, running)
|
|
957
|
+
return ids.map((id) => ended.get(id)!)
|
|
950
958
|
}),
|
|
951
|
-
|
|
952
|
-
const id = yield*
|
|
953
|
-
yield* Effect.logInfo(`Calling "
|
|
959
|
+
stopTask: Effect.fn("AgentTools.stopTask")(function* (input: unknown) {
|
|
960
|
+
const id = yield* decodeStopTask(input)
|
|
961
|
+
yield* Effect.logInfo(`Calling "stopTask"`).pipe(
|
|
954
962
|
Effect.annotateLogs({ id }),
|
|
955
963
|
)
|
|
956
|
-
const
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
964
|
+
const entry = yield* findTask(id)
|
|
965
|
+
if (entry.kind === "agent") {
|
|
966
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
967
|
+
return yield* agentTasks.stopTask(id)
|
|
968
|
+
}
|
|
969
|
+
yield* Fiber.interrupt(entry.command.fiber)
|
|
970
|
+
return reportBash(entry)
|
|
971
|
+
}),
|
|
972
|
+
listTasks: Effect.fn("AgentTools.listTasks")(function* () {
|
|
973
|
+
yield* Effect.logInfo(`Calling "listTasks"`)
|
|
974
|
+
const owner = yield* TaskOwner
|
|
975
|
+
const bashTasks = Array.Array.from(tasks.values()).flatMap((entry) =>
|
|
976
|
+
entry.kind === "bash" && entry.owner === owner
|
|
977
|
+
? [bashTask(entry)]
|
|
978
|
+
: [],
|
|
979
|
+
)
|
|
980
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
981
|
+
return [...bashTasks, ...(yield* agentTasks.listTasks)].toSorted(
|
|
982
|
+
(a, b) => Number(a.id) - Number(b.id),
|
|
983
|
+
)
|
|
960
984
|
}),
|
|
961
985
|
gh: Effect.fn("AgentTools.gh")(function* (args) {
|
|
962
986
|
yield* Effect.logInfo(`Calling "gh"`).pipe(
|
|
@@ -1144,18 +1168,9 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
1144
1168
|
yield* Effect.logInfo(`Calling "delegate"`).pipe(
|
|
1145
1169
|
Effect.annotateLogs({ background }),
|
|
1146
1170
|
)
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
waitAgents: Effect.fn("AgentTools.waitAgents")(function* (
|
|
1151
|
-
input: unknown,
|
|
1152
|
-
) {
|
|
1153
|
-
const ids = yield* decodeWaitAgents(input)
|
|
1154
|
-
yield* Effect.logInfo(`Calling "waitAgents"`).pipe(
|
|
1155
|
-
Effect.annotateLogs({ ids }),
|
|
1156
|
-
)
|
|
1157
|
-
const subagents = yield* SubagentExecutor
|
|
1158
|
-
return yield* subagents.waitAgents(ids)
|
|
1171
|
+
const id = yield* registerAgentTask()
|
|
1172
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
1173
|
+
return yield* agentTasks.delegate({ id, prompt, background })
|
|
1159
1174
|
}),
|
|
1160
1175
|
messageAgent: Effect.fn("AgentTools.messageAgent")(function* (
|
|
1161
1176
|
input: unknown,
|
|
@@ -1164,21 +1179,14 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
1164
1179
|
yield* Effect.logInfo(`Calling "messageAgent"`).pipe(
|
|
1165
1180
|
Effect.annotateLogs({ id: options.id }),
|
|
1166
1181
|
)
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
)
|
|
1175
|
-
const subagents = yield* SubagentExecutor
|
|
1176
|
-
return yield* subagents.stopAgent(id)
|
|
1177
|
-
}),
|
|
1178
|
-
listAgents: Effect.fn("AgentTools.listAgents")(function* () {
|
|
1179
|
-
yield* Effect.logInfo(`Calling "listAgents"`)
|
|
1180
|
-
const subagents = yield* SubagentExecutor
|
|
1181
|
-
return yield* subagents.listAgents
|
|
1182
|
+
const entry = yield* findTask(options.id)
|
|
1183
|
+
if (entry.kind === "bash") {
|
|
1184
|
+
return yield* Effect.fail(
|
|
1185
|
+
`messageAgent only addresses sub-agents, and task ${JSON.stringify(entry.id)} is a bash task. Use taskOutput or stopTask with it instead.`,
|
|
1186
|
+
)
|
|
1187
|
+
}
|
|
1188
|
+
const agentTasks = yield* AgentTaskExecutor
|
|
1189
|
+
return yield* agentTasks.messageAgent(options)
|
|
1182
1190
|
}),
|
|
1183
1191
|
taskComplete: Effect.fn("AgentTools.taskComplete")(function* (
|
|
1184
1192
|
message: unknown,
|
|
@@ -1235,34 +1243,25 @@ const decodeDelegate = decodeParams(
|
|
|
1235
1243
|
AgentTools.tools.delegate.parametersSchema,
|
|
1236
1244
|
'delegate requires an options object, for example: delegate({ prompt: "..." }) or delegate({ prompt: "...", background: true }).',
|
|
1237
1245
|
)
|
|
1238
|
-
const decodeWaitAgents = decodeParams(
|
|
1239
|
-
AgentTools.tools.waitAgents.parametersSchema,
|
|
1240
|
-
'waitAgents takes an optional array of agent ids, for example: waitAgents(["3", "4"]).',
|
|
1241
|
-
)
|
|
1242
1246
|
const decodeMessageAgent = decodeParams(
|
|
1243
1247
|
AgentTools.tools.messageAgent.parametersSchema,
|
|
1244
1248
|
'messageAgent requires an options object, for example: messageAgent({ id: "3", message: "..." }).',
|
|
1245
1249
|
)
|
|
1246
|
-
const
|
|
1247
|
-
AgentTools.tools.
|
|
1248
|
-
'
|
|
1250
|
+
const decodeTaskOutput = decodeParams(
|
|
1251
|
+
AgentTools.tools.taskOutput.parametersSchema,
|
|
1252
|
+
'taskOutput requires a task id, for example: taskOutput("1").',
|
|
1249
1253
|
)
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
'jobOutput requires a job id, for example: jobOutput("1").',
|
|
1254
|
+
const decodeWaitTasks = decodeParams(
|
|
1255
|
+
AgentTools.tools.waitTasks.parametersSchema,
|
|
1256
|
+
'waitTasks requires an options object, for example: waitTasks({ ids: ["3", "4"] }) or waitTasks({ ids: ["3"], timeoutMs: 60000 }).',
|
|
1254
1257
|
)
|
|
1255
|
-
|
|
1258
|
+
|
|
1259
|
+
/** The caller's `bash` timeout, which also bounds `waitTasks`. */
|
|
1256
1260
|
const bashTimeoutMs = (limits: typeof CommandLimits.Service) =>
|
|
1257
1261
|
Duration.toMillis(limits.timeout ?? defaultBashTimeout)
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
'waitJob requires an options object, for example: waitJob({ id: "1" }) or waitJob({ id: "1", timeoutMs: 60000 }).',
|
|
1262
|
-
)
|
|
1263
|
-
const decodeStopJob = decodeParams(
|
|
1264
|
-
AgentTools.tools.stopJob.parametersSchema,
|
|
1265
|
-
'stopJob requires a job id, for example: stopJob("1").',
|
|
1262
|
+
const decodeStopTask = decodeParams(
|
|
1263
|
+
AgentTools.tools.stopTask.parametersSchema,
|
|
1264
|
+
'stopTask requires a task id, for example: stopTask("1").',
|
|
1266
1265
|
)
|
|
1267
1266
|
|
|
1268
1267
|
interface RunningCommand {
|
|
@@ -1278,24 +1277,68 @@ interface RunningCommand {
|
|
|
1278
1277
|
reported: boolean
|
|
1279
1278
|
}
|
|
1280
1279
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1280
|
+
// Waits up to `timeout` for a command to exit. A caller that is
|
|
1281
|
+
// interrupted first stops the command.
|
|
1282
|
+
const awaitCommand = (
|
|
1283
|
+
command: Omit<RunningCommand, "reported">,
|
|
1284
|
+
timeout: Duration.Duration | undefined,
|
|
1285
|
+
) => {
|
|
1286
|
+
const awaited = Fiber.await(command.fiber)
|
|
1287
|
+
return (
|
|
1288
|
+
timeout === undefined
|
|
1289
|
+
? Effect.asSome(awaited)
|
|
1290
|
+
: Effect.timeoutOption(awaited, timeout)
|
|
1291
|
+
).pipe(Effect.onInterrupt(() => Fiber.interrupt(command.fiber)))
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
interface BashEntry {
|
|
1295
|
+
readonly kind: "bash"
|
|
1296
|
+
readonly id: string
|
|
1297
|
+
readonly owner: string | undefined
|
|
1298
|
+
readonly description: string
|
|
1299
|
+
readonly command: RunningCommand
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/** The executor only records who owns an agent task; the agent tracks it. */
|
|
1303
|
+
interface AgentEntry {
|
|
1304
|
+
readonly kind: "agent"
|
|
1305
|
+
readonly id: string
|
|
1306
|
+
readonly owner: string | undefined
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
type TaskEntry = BashEntry | AgentEntry
|
|
1310
|
+
|
|
1311
|
+
// A bash task's final state, once returned to the script, is not pushed.
|
|
1312
|
+
const reportBash = (entry: BashEntry): Task => {
|
|
1313
|
+
const task = bashTask(entry)
|
|
1314
|
+
if (task.status !== "running") entry.command.reported = true
|
|
1315
|
+
return task
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
const bashTask = ({ id, description, command }: BashEntry): Task => {
|
|
1319
|
+
const exit = command.fiber.pollUnsafe()
|
|
1320
|
+
const output = command.output()
|
|
1321
|
+
if (exit === undefined) {
|
|
1322
|
+
return { id, kind: "bash", status: "running", description, output }
|
|
1323
|
+
}
|
|
1285
1324
|
if (Exit.isSuccess(exit)) {
|
|
1286
1325
|
return {
|
|
1287
1326
|
id,
|
|
1327
|
+
kind: "bash",
|
|
1288
1328
|
status: exit.value === 0 ? "completed" : "failed",
|
|
1289
|
-
|
|
1329
|
+
description,
|
|
1290
1330
|
output,
|
|
1331
|
+
exitCode: exit.value,
|
|
1291
1332
|
}
|
|
1292
1333
|
}
|
|
1293
1334
|
if (Cause.hasInterruptsOnly(exit.cause)) {
|
|
1294
|
-
return { id, status: "stopped", output }
|
|
1335
|
+
return { id, kind: "bash", status: "stopped", description, output }
|
|
1295
1336
|
}
|
|
1296
1337
|
return {
|
|
1297
1338
|
id,
|
|
1339
|
+
kind: "bash",
|
|
1298
1340
|
status: "failed",
|
|
1341
|
+
description,
|
|
1299
1342
|
output: `${output}${output === "" ? "" : "\n"}${Cause.pretty(exit.cause)}`,
|
|
1300
1343
|
}
|
|
1301
1344
|
}
|