clanka 0.8.6 → 0.10.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.d.ts +6 -1
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +34 -3
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +178 -2
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +7 -1
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/Agent.d.ts +82 -8
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +556 -113
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +86 -5
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.d.ts +2 -0
- package/dist/AgentCallerConfig.test.d.ts.map +1 -0
- package/dist/AgentCallerConfig.test.js +335 -0
- package/dist/AgentCallerConfig.test.js.map +1 -0
- package/dist/AgentEnvironment.d.ts +76 -0
- package/dist/AgentEnvironment.d.ts.map +1 -0
- package/dist/AgentEnvironment.js +119 -0
- package/dist/AgentEnvironment.js.map +1 -0
- package/dist/AgentEnvironment.test.d.ts +2 -0
- package/dist/AgentEnvironment.test.d.ts.map +1 -0
- package/dist/AgentEnvironment.test.js +304 -0
- package/dist/AgentEnvironment.test.js.map +1 -0
- package/dist/AgentExecutor.d.ts +342 -183
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +607 -127
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +287 -31
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +5 -1
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +15 -2
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentOutput.d.ts +70 -5
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +65 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/AgentSkills.d.ts +37 -0
- package/dist/AgentSkills.d.ts.map +1 -1
- package/dist/AgentSkills.js +96 -32
- package/dist/AgentSkills.js.map +1 -1
- package/dist/AgentSkills.test.js +14 -2
- package/dist/AgentSkills.test.js.map +1 -1
- package/dist/AgentSubagents.test.d.ts +2 -0
- package/dist/AgentSubagents.test.d.ts.map +1 -0
- package/dist/AgentSubagents.test.js +494 -0
- package/dist/AgentSubagents.test.js.map +1 -0
- package/dist/AgentTools.d.ts +356 -14
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +214 -35
- package/dist/AgentTools.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +19 -2
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/ToolkitRenderer.d.ts.map +1 -1
- package/dist/ToolkitRenderer.js +6 -1
- package/dist/ToolkitRenderer.js.map +1 -1
- package/dist/bin/{Effect-rADALOOD.mjs → Effect-2jPlJ8eu.mjs} +43 -38
- package/dist/bin/Effect-2jPlJ8eu.mjs.map +1 -0
- package/dist/bin/{McpClient-NazR2OwL.mjs → McpClient-1W508adc.mjs} +3 -3
- package/dist/bin/{McpClient-NazR2OwL.mjs.map → McpClient-1W508adc.mjs.map} +1 -1
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs → OutputFormatter-BFAv48k9.mjs} +17 -5
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs.map → OutputFormatter-BFAv48k9.mjs.map} +1 -1
- package/dist/bin/{Schema-C7NXAOWA.mjs → Schema-D-7VuCiC.mjs} +2 -2
- package/dist/bin/{Schema-C7NXAOWA.mjs.map → Schema-D-7VuCiC.mjs.map} +1 -1
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs → SemanticSearch-Cb8aqvGv.mjs} +4 -4
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs.map → SemanticSearch-Cb8aqvGv.mjs.map} +1 -1
- package/dist/bin/{Stream-CSLA1_GD.mjs → Stream-DEu2tfCV.mjs} +12 -3
- package/dist/bin/Stream-DEu2tfCV.mjs.map +1 -0
- package/dist/bin/cli.mjs +13333 -12470
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +279 -3
- package/src/Acp.ts +34 -4
- package/src/AcpImage.test.ts +7 -1
- package/src/Agent.test.ts +109 -4
- package/src/Agent.ts +874 -140
- package/src/AgentCallerConfig.test.ts +522 -0
- package/src/AgentEnvironment.test.ts +504 -0
- package/src/AgentEnvironment.ts +161 -0
- package/src/AgentExecutor.test.ts +414 -37
- package/src/AgentExecutor.ts +1028 -191
- package/src/AgentExecutorImage.test.ts +5 -1
- package/src/AgentImage.test.ts +21 -3
- package/src/AgentOutput.ts +91 -1
- package/src/AgentSkills.test.ts +14 -2
- package/src/AgentSkills.ts +117 -34
- package/src/AgentSubagents.test.ts +824 -0
- package/src/AgentTools.ts +377 -53
- package/src/OutputFormatter.ts +19 -2
- package/src/ToolkitRenderer.ts +7 -1
- package/dist/bin/Effect-rADALOOD.mjs.map +0 -1
- package/dist/bin/Stream-CSLA1_GD.mjs.map +0 -1
|
@@ -3,14 +3,21 @@ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
|
|
|
3
3
|
import * as NodeServices from "@effect/platform-node/NodeServices"
|
|
4
4
|
import * as Deferred from "effect/Deferred"
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
|
+
import * as Fiber from "effect/Fiber"
|
|
6
7
|
import * as FileSystem from "effect/FileSystem"
|
|
7
8
|
import * as Layer from "effect/Layer"
|
|
8
9
|
import * as Stream from "effect/Stream"
|
|
10
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient"
|
|
11
|
+
import * as HttpEffect from "effect/http/HttpEffect"
|
|
9
12
|
import * as HttpServer from "effect/http/HttpServer"
|
|
10
13
|
import * as RpcClient from "effect/rpc/RpcClient"
|
|
11
14
|
import * as RpcSerialization from "effect/rpc/RpcSerialization"
|
|
12
15
|
import * as RpcServer from "effect/rpc/RpcServer"
|
|
16
|
+
import * as NodeFs from "node:fs"
|
|
17
|
+
import * as NodeOs from "node:os"
|
|
18
|
+
import * as NodePath from "node:path"
|
|
13
19
|
import * as AgentExecutor from "./AgentExecutor.ts"
|
|
20
|
+
import { subagentsUnavailable } from "./AgentTools.ts"
|
|
14
21
|
|
|
15
22
|
const withRpc = <A, E, R>(
|
|
16
23
|
f: (
|
|
@@ -53,36 +60,57 @@ describe("RPC subagent executor", () => {
|
|
|
53
60
|
it.live("routes concurrent delegates to their originating scripts", () =>
|
|
54
61
|
withRpc((executor) =>
|
|
55
62
|
Effect.gen(function* () {
|
|
63
|
+
const { environment } = yield* executor.capabilities
|
|
56
64
|
const firstStarted = yield* Deferred.make<void>()
|
|
57
65
|
const secondStarted = yield* Deferred.make<void>()
|
|
58
66
|
const outputs = yield* Effect.all(
|
|
59
67
|
[
|
|
60
68
|
executor
|
|
61
69
|
.execute({
|
|
62
|
-
|
|
70
|
+
environment,
|
|
71
|
+
onEnvironment: () => Effect.void,
|
|
72
|
+
script:
|
|
73
|
+
'console.log("first:" + (await delegate({ prompt: "first" })).output)',
|
|
63
74
|
onTaskComplete: () => Effect.void,
|
|
64
75
|
onImage: () => Effect.void,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
subagents: {
|
|
77
|
+
...subagentsUnavailable,
|
|
78
|
+
delegate: ({ prompt }) =>
|
|
79
|
+
Effect.gen(function* () {
|
|
80
|
+
assert.strictEqual(prompt, "first")
|
|
81
|
+
yield* Deferred.succeed(firstStarted, undefined)
|
|
82
|
+
yield* Deferred.await(secondStarted)
|
|
83
|
+
return {
|
|
84
|
+
id: "1",
|
|
85
|
+
status: "completed" as const,
|
|
86
|
+
output: "first-output",
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
72
90
|
})
|
|
73
91
|
.pipe(Stream.runCollect),
|
|
74
92
|
executor
|
|
75
93
|
.execute({
|
|
76
|
-
|
|
94
|
+
environment,
|
|
95
|
+
onEnvironment: () => Effect.void,
|
|
96
|
+
script:
|
|
97
|
+
'console.log("second:" + (await delegate({ prompt: "second" })).output)',
|
|
77
98
|
onTaskComplete: () => Effect.void,
|
|
78
99
|
onImage: () => Effect.void,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
subagents: {
|
|
101
|
+
...subagentsUnavailable,
|
|
102
|
+
delegate: ({ prompt }) =>
|
|
103
|
+
Effect.gen(function* () {
|
|
104
|
+
assert.strictEqual(prompt, "second")
|
|
105
|
+
yield* Deferred.succeed(secondStarted, undefined)
|
|
106
|
+
yield* Deferred.await(firstStarted)
|
|
107
|
+
return {
|
|
108
|
+
id: "2",
|
|
109
|
+
status: "completed" as const,
|
|
110
|
+
output: "second-output",
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
86
114
|
})
|
|
87
115
|
.pipe(Stream.runCollect),
|
|
88
116
|
],
|
|
@@ -99,31 +127,52 @@ describe("RPC subagent executor", () => {
|
|
|
99
127
|
() =>
|
|
100
128
|
withRpc((executor) =>
|
|
101
129
|
Effect.gen(function* () {
|
|
130
|
+
const { environment } = yield* executor.capabilities
|
|
102
131
|
const output = yield* executor
|
|
103
132
|
.execute({
|
|
104
|
-
|
|
133
|
+
environment,
|
|
134
|
+
onEnvironment: () => Effect.void,
|
|
135
|
+
script:
|
|
136
|
+
'console.log("parent:" + (await delegate({ prompt: "outer" })).output)',
|
|
105
137
|
onTaskComplete: () => Effect.void,
|
|
106
138
|
onImage: () => Effect.void,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
subagents: {
|
|
140
|
+
...subagentsUnavailable,
|
|
141
|
+
delegate: ({ prompt }) =>
|
|
142
|
+
Effect.gen(function* () {
|
|
143
|
+
assert.strictEqual(prompt, "outer")
|
|
144
|
+
const childOutput = yield* executor
|
|
145
|
+
.execute({
|
|
146
|
+
environment,
|
|
147
|
+
onEnvironment: () => Effect.void,
|
|
148
|
+
script:
|
|
149
|
+
'console.log("child:" + (await delegate({ prompt: "inner" })).output)',
|
|
150
|
+
onTaskComplete: () => Effect.void,
|
|
151
|
+
onImage: () => Effect.void,
|
|
152
|
+
subagents: {
|
|
153
|
+
...subagentsUnavailable,
|
|
154
|
+
delegate: ({ prompt: innerPrompt }) =>
|
|
155
|
+
Effect.sync(() => {
|
|
156
|
+
assert.strictEqual(innerPrompt, "inner")
|
|
157
|
+
return {
|
|
158
|
+
id: "2",
|
|
159
|
+
status: "completed" as const,
|
|
160
|
+
output: "inner-output",
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
.pipe(Stream.runCollect)
|
|
166
|
+
assert.isTrue(
|
|
167
|
+
childOutput.join("").endsWith("child:inner-output\n"),
|
|
168
|
+
)
|
|
169
|
+
return {
|
|
170
|
+
id: "1",
|
|
171
|
+
status: "completed" as const,
|
|
172
|
+
output: childOutput.join("").trim().split("\n").at(-1)!,
|
|
173
|
+
}
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
127
176
|
})
|
|
128
177
|
.pipe(Stream.runCollect)
|
|
129
178
|
assert.isTrue(output.join("").endsWith("parent:child:inner-output\n"))
|
|
@@ -131,3 +180,331 @@ describe("RPC subagent executor", () => {
|
|
|
131
180
|
),
|
|
132
181
|
)
|
|
133
182
|
})
|
|
183
|
+
|
|
184
|
+
// Both executor modes with the same limits. The RPC mode serves
|
|
185
|
+
// `layerRpcServer` through an in-memory web handler, so requests go through
|
|
186
|
+
// the real serialization without opening a socket.
|
|
187
|
+
const executorModes = {
|
|
188
|
+
local: (limits: AgentExecutor.Limits) =>
|
|
189
|
+
Layer.unwrap(
|
|
190
|
+
Effect.gen(function* () {
|
|
191
|
+
const fs = yield* FileSystem.FileSystem
|
|
192
|
+
const directory = yield* fs.makeTempDirectoryScoped()
|
|
193
|
+
return AgentExecutor.layerLocal({ directory, limits })
|
|
194
|
+
}),
|
|
195
|
+
).pipe(
|
|
196
|
+
Layer.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer)),
|
|
197
|
+
),
|
|
198
|
+
rpc: (limits: AgentExecutor.Limits) =>
|
|
199
|
+
Layer.unwrap(
|
|
200
|
+
Effect.gen(function* () {
|
|
201
|
+
const fs = yield* FileSystem.FileSystem
|
|
202
|
+
const directory = yield* fs.makeTempDirectoryScoped()
|
|
203
|
+
const { protocol, httpEffect } =
|
|
204
|
+
yield* RpcServer.makeProtocolWithHttpEffect()
|
|
205
|
+
yield* Layer.build(
|
|
206
|
+
AgentExecutor.layerRpcServer({ directory, limits }).pipe(
|
|
207
|
+
Layer.provide(Layer.succeed(RpcServer.Protocol, protocol)),
|
|
208
|
+
Layer.provide(FetchHttpClient.layer),
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
const handler = HttpEffect.toWebHandler(httpEffect)
|
|
212
|
+
return AgentExecutor.layerRpc.pipe(
|
|
213
|
+
Layer.provide(
|
|
214
|
+
RpcClient.layerProtocolHttp({ url: "http://executor.test/" }),
|
|
215
|
+
),
|
|
216
|
+
Layer.provide(FetchHttpClient.layer),
|
|
217
|
+
Layer.provide(
|
|
218
|
+
Layer.succeed(FetchHttpClient.Fetch, (input, init) =>
|
|
219
|
+
handler(new Request(input, init)),
|
|
220
|
+
),
|
|
221
|
+
),
|
|
222
|
+
)
|
|
223
|
+
}),
|
|
224
|
+
).pipe(
|
|
225
|
+
Layer.provide(
|
|
226
|
+
Layer.mergeAll(NodeServices.layer, RpcSerialization.layerNdjson),
|
|
227
|
+
),
|
|
228
|
+
),
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const runScript = (script: string) =>
|
|
232
|
+
Effect.gen(function* () {
|
|
233
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
234
|
+
const { environment } = yield* executor.capabilities
|
|
235
|
+
return yield* executor
|
|
236
|
+
.execute({
|
|
237
|
+
environment,
|
|
238
|
+
onEnvironment: () => Effect.void,
|
|
239
|
+
script,
|
|
240
|
+
onTaskComplete: () => Effect.void,
|
|
241
|
+
subagents: subagentsUnavailable,
|
|
242
|
+
onImage: () => Effect.void,
|
|
243
|
+
})
|
|
244
|
+
.pipe(Stream.mkString)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
// Puts a `gh` that only sleeps first on PATH, so the test needs neither the
|
|
248
|
+
// real CLI nor the network.
|
|
249
|
+
const withSlowGh = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
250
|
+
Effect.acquireUseRelease(
|
|
251
|
+
Effect.sync(() => {
|
|
252
|
+
const directory = NodeFs.mkdtempSync(
|
|
253
|
+
NodePath.join(NodeOs.tmpdir(), "slow-gh-"),
|
|
254
|
+
)
|
|
255
|
+
const gh = NodePath.join(directory, "gh")
|
|
256
|
+
NodeFs.writeFileSync(gh, "#!/bin/sh\nsleep 10\n")
|
|
257
|
+
NodeFs.chmodSync(gh, 0o755)
|
|
258
|
+
const path = process.env.PATH
|
|
259
|
+
process.env.PATH = `${directory}${NodePath.delimiter}${path}`
|
|
260
|
+
return { directory, path }
|
|
261
|
+
}),
|
|
262
|
+
() => effect,
|
|
263
|
+
({ directory, path }) =>
|
|
264
|
+
Effect.sync(() => {
|
|
265
|
+
process.env.PATH = path
|
|
266
|
+
NodeFs.rmSync(directory, { recursive: true, force: true })
|
|
267
|
+
}),
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
for (const [mode, executorLayer] of Object.entries(executorModes)) {
|
|
271
|
+
describe(`${mode} executor environment`, () => {
|
|
272
|
+
// A cancelled script keeps the directory it changed to, as an ACP
|
|
273
|
+
// `session/cancel` or a `stopAgent` continues the same agent afterwards.
|
|
274
|
+
it.live("returns the environment when the caller interrupts", () =>
|
|
275
|
+
Effect.gen(function* () {
|
|
276
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
277
|
+
const { environment } = yield* executor.capabilities
|
|
278
|
+
const ready = yield* Deferred.make<void>()
|
|
279
|
+
const updates: Array<AgentExecutor.ExecutionEnvironment> = []
|
|
280
|
+
const fiber = yield* executor
|
|
281
|
+
.execute({
|
|
282
|
+
script: `await changeDirectory("..")
|
|
283
|
+
console.log("ready")
|
|
284
|
+
await sleep(60000)`,
|
|
285
|
+
environment,
|
|
286
|
+
onEnvironment: (update) =>
|
|
287
|
+
Effect.sync(() => {
|
|
288
|
+
updates.push(update)
|
|
289
|
+
}),
|
|
290
|
+
onTaskComplete: () => Effect.void,
|
|
291
|
+
subagents: subagentsUnavailable,
|
|
292
|
+
onImage: () => Effect.void,
|
|
293
|
+
})
|
|
294
|
+
.pipe(
|
|
295
|
+
Stream.runForEach((text) =>
|
|
296
|
+
text.includes("ready")
|
|
297
|
+
? Deferred.succeed(ready, undefined)
|
|
298
|
+
: Effect.void,
|
|
299
|
+
),
|
|
300
|
+
Effect.forkScoped,
|
|
301
|
+
)
|
|
302
|
+
yield* Deferred.await(ready)
|
|
303
|
+
yield* Fiber.interrupt(fiber)
|
|
304
|
+
assert.strictEqual(updates.length, 1)
|
|
305
|
+
assert.strictEqual(updates[0]!.cwd, NodePath.dirname(environment.cwd))
|
|
306
|
+
}).pipe(
|
|
307
|
+
Effect.scoped,
|
|
308
|
+
Effect.timeout("5 seconds"),
|
|
309
|
+
Effect.provide(executorLayer({})),
|
|
310
|
+
),
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
// The caller is still busy with output from before the change when it
|
|
314
|
+
// interrupts. Whatever the script got done by then, the environment
|
|
315
|
+
// returned matches it: the marker shows it got past `changeDirectory`.
|
|
316
|
+
it.live(
|
|
317
|
+
"returns the environment when the caller interrupts while behind",
|
|
318
|
+
() =>
|
|
319
|
+
Effect.gen(function* () {
|
|
320
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
321
|
+
const { environment } = yield* executor.capabilities
|
|
322
|
+
const marker = NodePath.join(environment.cwd, "changed")
|
|
323
|
+
const busy = yield* Deferred.make<void>()
|
|
324
|
+
const updates: Array<AgentExecutor.ExecutionEnvironment> = []
|
|
325
|
+
const fiber = yield* executor
|
|
326
|
+
.execute({
|
|
327
|
+
script: `console.log("before")
|
|
328
|
+
await sleep(50)
|
|
329
|
+
await changeDirectory("..")
|
|
330
|
+
await writeFile({ path: ${JSON.stringify(marker)}, content: "" })
|
|
331
|
+
await sleep(60000)`,
|
|
332
|
+
environment,
|
|
333
|
+
onEnvironment: (update) =>
|
|
334
|
+
Effect.sync(() => {
|
|
335
|
+
updates.push(update)
|
|
336
|
+
}),
|
|
337
|
+
onTaskComplete: () => Effect.void,
|
|
338
|
+
subagents: subagentsUnavailable,
|
|
339
|
+
onImage: () => Effect.void,
|
|
340
|
+
})
|
|
341
|
+
.pipe(
|
|
342
|
+
Stream.runForEach(() =>
|
|
343
|
+
Deferred.succeed(busy, undefined).pipe(
|
|
344
|
+
Effect.andThen(Effect.never),
|
|
345
|
+
),
|
|
346
|
+
),
|
|
347
|
+
Effect.forkScoped,
|
|
348
|
+
)
|
|
349
|
+
yield* Deferred.await(busy)
|
|
350
|
+
yield* Effect.gen(function* () {
|
|
351
|
+
while (!NodeFs.existsSync(marker)) {
|
|
352
|
+
yield* Effect.sleep("10 millis")
|
|
353
|
+
}
|
|
354
|
+
}).pipe(Effect.timeoutOption("500 millis"))
|
|
355
|
+
const changed = NodeFs.existsSync(marker)
|
|
356
|
+
yield* Fiber.interrupt(fiber)
|
|
357
|
+
assert.strictEqual(updates.length, 1)
|
|
358
|
+
assert.strictEqual(
|
|
359
|
+
updates[0]!.cwd,
|
|
360
|
+
changed ? NodePath.dirname(environment.cwd) : environment.cwd,
|
|
361
|
+
)
|
|
362
|
+
}).pipe(
|
|
363
|
+
Effect.scoped,
|
|
364
|
+
Effect.timeout("5 seconds"),
|
|
365
|
+
Effect.provide(executorLayer({})),
|
|
366
|
+
),
|
|
367
|
+
)
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
describe(`${mode} executor limits`, () => {
|
|
371
|
+
it.live("stops a bash command at the caller's command timeout", () =>
|
|
372
|
+
Effect.gen(function* () {
|
|
373
|
+
const output = yield* runScript(`
|
|
374
|
+
try {
|
|
375
|
+
await bash({ command: 'sleep 10 && echo fini""shed', timeoutMs: 60000 })
|
|
376
|
+
} catch (error) {
|
|
377
|
+
console.log("REJECTED:", String(error))
|
|
378
|
+
}`)
|
|
379
|
+
assert.include(output, "REJECTED:")
|
|
380
|
+
assert.match(output, /timed out/i)
|
|
381
|
+
assert.notInclude(output, "finished")
|
|
382
|
+
}).pipe(
|
|
383
|
+
Effect.timeout("3 seconds"),
|
|
384
|
+
Effect.provide(executorLayer({ commandTimeout: "300 millis" })),
|
|
385
|
+
),
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
it.live("stops a gh command at the caller's command timeout", () =>
|
|
389
|
+
Effect.gen(function* () {
|
|
390
|
+
const output = yield* runScript(`
|
|
391
|
+
try {
|
|
392
|
+
await gh(["api", "user"])
|
|
393
|
+
console.log("GH" + "_RETURNED")
|
|
394
|
+
} catch (error) {
|
|
395
|
+
console.log("REJECTED:", String(error))
|
|
396
|
+
}`)
|
|
397
|
+
assert.include(output, "REJECTED:")
|
|
398
|
+
assert.match(output, /timed out/i)
|
|
399
|
+
assert.notInclude(output, "GH_RETURNED")
|
|
400
|
+
}).pipe(
|
|
401
|
+
Effect.timeout("3 seconds"),
|
|
402
|
+
Effect.provide(executorLayer({ commandTimeout: "300 millis" })),
|
|
403
|
+
withSlowGh,
|
|
404
|
+
),
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
it.live("describes the caller's command timeout to the model", () =>
|
|
408
|
+
Effect.gen(function* () {
|
|
409
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
410
|
+
const { toolsDts } = yield* executor.capabilities
|
|
411
|
+
assert.include(toolsDts, "180000")
|
|
412
|
+
assert.notInclude(toolsDts, "120000")
|
|
413
|
+
assert.notInclude(toolsDts, "4 minutes")
|
|
414
|
+
}).pipe(Effect.provide(executorLayer({ commandTimeout: "3 minutes" }))),
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
it.live("ends a script at the caller's script timeout", () =>
|
|
418
|
+
Effect.gen(function* () {
|
|
419
|
+
const output = yield* runScript(`
|
|
420
|
+
console.log("before")
|
|
421
|
+
await sleep(10000)
|
|
422
|
+
console.log("after")`)
|
|
423
|
+
assert.include(output, "before")
|
|
424
|
+
assert.notInclude(output, "after")
|
|
425
|
+
assert.match(output, /timed out/i)
|
|
426
|
+
}).pipe(
|
|
427
|
+
Effect.timeout("3 seconds"),
|
|
428
|
+
Effect.provide(executorLayer({ scriptTimeout: "300 millis" })),
|
|
429
|
+
),
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
// The busy loop is the watchdog: it gives up after 2 seconds, so a
|
|
433
|
+
// regression fails the assertions instead of hanging the test runner.
|
|
434
|
+
it.live(
|
|
435
|
+
"ends a script that is busy in JavaScript at the script timeout",
|
|
436
|
+
() =>
|
|
437
|
+
Effect.gen(function* () {
|
|
438
|
+
const output = yield* runScript(`
|
|
439
|
+
await sleep(1)
|
|
440
|
+
const giveUp = Date.now() + 2000
|
|
441
|
+
while (Date.now() < giveUp) {}
|
|
442
|
+
console.log("BUSY" + "_LOOP_FINISHED")`)
|
|
443
|
+
assert.notInclude(output, "BUSY_LOOP_FINISHED")
|
|
444
|
+
assert.match(output, /timed out/i)
|
|
445
|
+
}).pipe(
|
|
446
|
+
Effect.timeout("5 seconds"),
|
|
447
|
+
Effect.provide(executorLayer({ scriptTimeout: "300 millis" })),
|
|
448
|
+
),
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
it.live("runs tool calls chained after the script returns", () =>
|
|
452
|
+
Effect.gen(function* () {
|
|
453
|
+
const output = yield* runScript(`
|
|
454
|
+
sleep(100).then(() => {
|
|
455
|
+
console.log("FIRST" + "_CONTINUATION")
|
|
456
|
+
return sleep(100).then(() => console.log("SECOND" + "_CONTINUATION"))
|
|
457
|
+
})
|
|
458
|
+
console.log("MAIN" + "_DONE")`)
|
|
459
|
+
assert.include(output, "MAIN_DONE")
|
|
460
|
+
assert.include(output, "FIRST_CONTINUATION")
|
|
461
|
+
assert.include(output, "SECOND_CONTINUATION")
|
|
462
|
+
}).pipe(Effect.timeout("3 seconds"), Effect.provide(executorLayer({}))),
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
// The timeout is the watchdog: a script left waiting fails the test.
|
|
466
|
+
it.live(
|
|
467
|
+
"ends a script whose worker exits while a tool call is running",
|
|
468
|
+
() =>
|
|
469
|
+
Effect.gen(function* () {
|
|
470
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
471
|
+
const { environment } = yield* executor.capabilities
|
|
472
|
+
const output = yield* executor
|
|
473
|
+
.execute({
|
|
474
|
+
environment,
|
|
475
|
+
onEnvironment: () => Effect.void,
|
|
476
|
+
// `delegate` never finishes. The worker then exits through
|
|
477
|
+
// the host's `process`, the way a crashed worker would.
|
|
478
|
+
script: `
|
|
479
|
+
delegate({ prompt: "never finishes" })
|
|
480
|
+
sleep(100).then(() => console.constructor.constructor("return process")().exit(7))`,
|
|
481
|
+
onTaskComplete: () => Effect.void,
|
|
482
|
+
subagents: {
|
|
483
|
+
...subagentsUnavailable,
|
|
484
|
+
delegate: () => Effect.never,
|
|
485
|
+
},
|
|
486
|
+
onImage: () => Effect.void,
|
|
487
|
+
})
|
|
488
|
+
.pipe(Stream.mkString)
|
|
489
|
+
assert.include(output, "code 7")
|
|
490
|
+
}).pipe(Effect.timeout("3 seconds"), Effect.provide(executorLayer({}))),
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
it.live("keeps the start and end of long bash output", () =>
|
|
494
|
+
Effect.gen(function* () {
|
|
495
|
+
const executor = yield* AgentExecutor.AgentExecutor
|
|
496
|
+
const output = yield* executor.executeUnsafe({
|
|
497
|
+
tool: "bash",
|
|
498
|
+
params: { command: "seq 1 1000000" },
|
|
499
|
+
})
|
|
500
|
+
assert(typeof output === "string")
|
|
501
|
+
assert.isBelow(output.length, 10_000 + 500)
|
|
502
|
+
assert.isTrue(output.startsWith("1\n2\n3\n"), "start kept")
|
|
503
|
+
assert.isTrue(output.trimEnd().endsWith("999999\n1000000"), "end kept")
|
|
504
|
+
}).pipe(
|
|
505
|
+
Effect.timeout("10 seconds"),
|
|
506
|
+
Effect.provide(executorLayer({ commandOutputChars: 10_000 })),
|
|
507
|
+
),
|
|
508
|
+
)
|
|
509
|
+
})
|
|
510
|
+
}
|