clanka 0.24.1 → 0.24.3
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/AgentExecutor.test.js +7 -3
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +3 -1
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +22 -22
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +11 -3
- package/dist/AgentTools.js.map +1 -1
- package/dist/ClaudeAgent.d.ts.map +1 -1
- package/dist/ClaudeAgent.js +5 -1
- package/dist/ClaudeAgent.js.map +1 -1
- package/dist/ClaudeAgent.test.js +45 -0
- package/dist/ClaudeAgent.test.js.map +1 -1
- package/dist/bin/cli.mjs +8 -3
- package/package.json +1 -1
- package/src/AgentExecutor.test.ts +17 -3
- package/src/AgentSubagents.test.ts +6 -1
- package/src/AgentTools.ts +13 -3
- package/src/ClaudeAgent.test.ts +62 -0
- package/src/ClaudeAgent.ts +7 -1
package/dist/bin/cli.mjs
CHANGED
|
@@ -11913,7 +11913,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11913
11913
|
}
|
|
11914
11914
|
const task = reportBash(entry);
|
|
11915
11915
|
if (task.status === "running") yield* watchBashTask(entry);
|
|
11916
|
-
return task;
|
|
11916
|
+
return options.background === true ? task : backgroundRunningOutput(task);
|
|
11917
11917
|
}, orDie),
|
|
11918
11918
|
taskOutput: fn("AgentTools.taskOutput")(function* (input) {
|
|
11919
11919
|
const id = yield* decodeTaskOutput(input);
|
|
@@ -11941,7 +11941,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11941
11941
|
}).pipe(timeoutOption(timeoutMs));
|
|
11942
11942
|
const agentResults = agentIds.length === 0 ? [] : yield* agentTasks.waitTasks(agentIds, { timeoutMs: Math.max(0, timeoutMs - ((yield* currentTimeMillis) - startedAt)) });
|
|
11943
11943
|
const ended = new Map([...bashEntries.map(reportBash), ...agentResults].map((task) => [task.id, task]));
|
|
11944
|
-
return ids.map((id) => ended.get(id));
|
|
11944
|
+
return ids.map((id) => backgroundRunningOutput(ended.get(id)));
|
|
11945
11945
|
}),
|
|
11946
11946
|
stopTask: fn("AgentTools.stopTask")(function* (input) {
|
|
11947
11947
|
const id = yield* decodeStopTask(input);
|
|
@@ -12179,6 +12179,10 @@ const makeOutputBuffer = (maxChars) => {
|
|
|
12179
12179
|
};
|
|
12180
12180
|
};
|
|
12181
12181
|
var ApplyPatchError = class extends TaggedClass$1("ApplyPatchError") {};
|
|
12182
|
+
const backgroundRunningOutput = (task) => task.status === "running" ? {
|
|
12183
|
+
...task,
|
|
12184
|
+
output: `Task "${task.id}" is still running in the background`
|
|
12185
|
+
} : task;
|
|
12182
12186
|
// src/TypeBuilder.ts
|
|
12183
12187
|
const resolveDocumentation = resolveAt("documentation");
|
|
12184
12188
|
const identifierPattern = /^[$A-Z_a-z][$0-9A-Z_a-z]*$/u;
|
|
@@ -28631,7 +28635,7 @@ const transformToolCallParams$1 = fnUntraced(function* (options, toolName, toolP
|
|
|
28631
28635
|
return yield* decodeEffect(codec)(toolParams).pipe(flatMap$1((decoded) => encodeUnknownEffect(tool.parametersSchema)(decoded)), orElseSucceed(() => toolParams));
|
|
28632
28636
|
});
|
|
28633
28637
|
// package.json
|
|
28634
|
-
var version$1 = "0.24.
|
|
28638
|
+
var version$1 = "0.24.3";
|
|
28635
28639
|
// src/ClaudeAgent.ts
|
|
28636
28640
|
const minimumClaudeCodeVersion = "2.1.248";
|
|
28637
28641
|
const serverName = "clanka";
|
|
@@ -28803,6 +28807,7 @@ const resultError = (message, code) => {
|
|
|
28803
28807
|
}));
|
|
28804
28808
|
case "invalid_request": return aiError(new InvalidRequestError$1({ description }));
|
|
28805
28809
|
}
|
|
28810
|
+
if (status === 429 || /Request rejected \(429\)|\brate_limit_error\b/i.test(description)) return aiError(new RateLimitError({ metadata: { description } }));
|
|
28806
28811
|
return aiError(/prompt is too long/i.test(description) ? new InvalidRequestError$1({ description }) : new UnknownError({ description }));
|
|
28807
28812
|
};
|
|
28808
28813
|
const makeConverter = () => {
|
package/package.json
CHANGED
|
@@ -610,13 +610,19 @@ try {
|
|
|
610
610
|
kind: "bash",
|
|
611
611
|
status: "running",
|
|
612
612
|
description: command,
|
|
613
|
-
output: "
|
|
613
|
+
output: 'Task "1" is still running in the background',
|
|
614
614
|
})
|
|
615
615
|
assert.strictEqual(
|
|
616
616
|
yield* waitForLog(environment.cwd, started),
|
|
617
617
|
"start\n",
|
|
618
618
|
"still running after the script ended",
|
|
619
619
|
)
|
|
620
|
+
assert.include(
|
|
621
|
+
yield* runScript(
|
|
622
|
+
`console.log("OUTPUT:", (await taskOutput("1")).output)`,
|
|
623
|
+
),
|
|
624
|
+
"OUTPUT: early",
|
|
625
|
+
)
|
|
620
626
|
openGate(environment.cwd)
|
|
621
627
|
assert.strictEqual(
|
|
622
628
|
yield* waitForLog(environment.cwd, finished),
|
|
@@ -688,7 +694,7 @@ console.log("WAITED:", (await waitTasks({ ids: [task.id] })).map(show).join())`)
|
|
|
688
694
|
const { environment } = yield* executor.capabilities
|
|
689
695
|
const output = yield* runScript(`
|
|
690
696
|
const task = await bash({
|
|
691
|
-
command: ${JSON.stringify(gatedCommand(environment.cwd))},
|
|
697
|
+
command: ${JSON.stringify(`echo early && ${gatedCommand(environment.cwd)}`)},
|
|
692
698
|
background: true,
|
|
693
699
|
})
|
|
694
700
|
const waits = [
|
|
@@ -696,8 +702,16 @@ const waits = [
|
|
|
696
702
|
...(await waitTasks({ ids: [task.id] })),
|
|
697
703
|
...(await waitTasks({ ids: [task.id], timeoutMs: 60000 })),
|
|
698
704
|
]
|
|
699
|
-
console.log("WAITS:", JSON.stringify(waits.map((task) => task.status)))
|
|
705
|
+
console.log("WAITS:", JSON.stringify(waits.map((task) => task.status)))
|
|
706
|
+
console.log("OUTPUTS:", JSON.stringify(waits.map((task) => task.output)))`)
|
|
700
707
|
assert.include(output, 'WAITS: ["running","running","running"]')
|
|
708
|
+
assert.include(
|
|
709
|
+
output,
|
|
710
|
+
"OUTPUTS: " +
|
|
711
|
+
JSON.stringify(
|
|
712
|
+
Array(3).fill('Task "1" is still running in the background'),
|
|
713
|
+
),
|
|
714
|
+
)
|
|
701
715
|
assert.strictEqual(
|
|
702
716
|
yield* waitForLog(environment.cwd, started),
|
|
703
717
|
"start\n",
|
|
@@ -992,7 +992,8 @@ console.log("ROOT:" + JSON.stringify(mine.map((task) => task.kind + ":" + task.s
|
|
|
992
992
|
"wait",
|
|
993
993
|
`const child = await subagent({ prompt: "TASK-CHILD", background: true })
|
|
994
994
|
const [task] = await waitTasks({ ids: [child.id], timeoutMs: 200 })
|
|
995
|
-
console.log("WAITED:" + task.status)
|
|
995
|
+
console.log("WAITED:" + task.status)
|
|
996
|
+
console.log("OUTPUT:" + task.output)`,
|
|
996
997
|
),
|
|
997
998
|
)
|
|
998
999
|
case 1:
|
|
@@ -1010,6 +1011,10 @@ console.log("WAITED:" + task.status)`,
|
|
|
1010
1011
|
})
|
|
1011
1012
|
|
|
1012
1013
|
assert.include(waited, "WAITED:running", "returned at the deadline")
|
|
1014
|
+
assert.include(
|
|
1015
|
+
waited,
|
|
1016
|
+
'OUTPUT:Task "1" is still running in the background',
|
|
1017
|
+
)
|
|
1013
1018
|
assert.isFalse(childInterrupted, "the deadline does not stop the agent")
|
|
1014
1019
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
1015
1020
|
const root = calls.filter((call) => call.role === "root")
|
package/src/AgentTools.ts
CHANGED
|
@@ -105,7 +105,7 @@ export const Task = Schema.Struct({
|
|
|
105
105
|
status: TaskStatus,
|
|
106
106
|
/** The bash command, or the sub-agent's prompt. */
|
|
107
107
|
description: Schema.String,
|
|
108
|
-
/** Output so far
|
|
108
|
+
/** Output so far, a background-running notice after a timeout, or the final output/error. */
|
|
109
109
|
output: Schema.String,
|
|
110
110
|
/** bash only: set when the command exited on its own. */
|
|
111
111
|
exitCode: Schema.optional(Schema.Number),
|
|
@@ -931,7 +931,9 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
931
931
|
// reach the model only once. A finished task is never handed over.
|
|
932
932
|
const task = reportBash(entry)
|
|
933
933
|
if (task.status === "running") yield* watchBashTask(entry)
|
|
934
|
-
return
|
|
934
|
+
return options.background === true
|
|
935
|
+
? task
|
|
936
|
+
: backgroundRunningOutput(task)
|
|
935
937
|
}, Effect.orDie),
|
|
936
938
|
taskOutput: Effect.fn("AgentTools.taskOutput")(function* (
|
|
937
939
|
input: unknown,
|
|
@@ -989,7 +991,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
989
991
|
task,
|
|
990
992
|
]),
|
|
991
993
|
)
|
|
992
|
-
return ids.map((id) => ended.get(id)!)
|
|
994
|
+
return ids.map((id) => backgroundRunningOutput(ended.get(id)!))
|
|
993
995
|
}),
|
|
994
996
|
stopTask: Effect.fn("AgentTools.stopTask")(function* (input: unknown) {
|
|
995
997
|
const id = yield* decodeStopTask(input)
|
|
@@ -1414,3 +1416,11 @@ const makeOutputBuffer = (maxChars: number | undefined) => {
|
|
|
1414
1416
|
class ApplyPatchError extends Data.TaggedClass("ApplyPatchError")<{
|
|
1415
1417
|
readonly message: string
|
|
1416
1418
|
}> {}
|
|
1419
|
+
|
|
1420
|
+
const backgroundRunningOutput = (task: Task): Task =>
|
|
1421
|
+
task.status === "running"
|
|
1422
|
+
? {
|
|
1423
|
+
...task,
|
|
1424
|
+
output: `Task "${task.id}" is still running in the background`,
|
|
1425
|
+
}
|
|
1426
|
+
: task
|
package/src/ClaudeAgent.test.ts
CHANGED
|
@@ -250,6 +250,68 @@ describe("ClaudeAgent", () => {
|
|
|
250
250
|
)
|
|
251
251
|
})
|
|
252
252
|
|
|
253
|
+
it.effect("classifies credential cooldowns as retryable rate limits", () =>
|
|
254
|
+
Effect.gen(function* () {
|
|
255
|
+
const description =
|
|
256
|
+
"API Error: Request rejected (429) · All credentials for model claude-fable-5-2 are cooling down (last error: rate_limit_error: This request would exceed your account's rate limit. Please try again later.) (reset after 29m52s)"
|
|
257
|
+
for (const result of [
|
|
258
|
+
{ subtype: "success", is_error: true, result: description },
|
|
259
|
+
{ subtype: "error_during_execution", errors: [description] },
|
|
260
|
+
{
|
|
261
|
+
subtype: "success",
|
|
262
|
+
is_error: true,
|
|
263
|
+
result: "API Error: Request rejected (429)",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
subtype: "success",
|
|
267
|
+
is_error: true,
|
|
268
|
+
result: "rate_limit_error: Please try again later.",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
subtype: "success",
|
|
272
|
+
is_error: true,
|
|
273
|
+
result: "Too many requests",
|
|
274
|
+
api_error_status: 429,
|
|
275
|
+
},
|
|
276
|
+
]) {
|
|
277
|
+
const error = yield* Stream.fromIterable([
|
|
278
|
+
{ ...frame, type: "result", ...result },
|
|
279
|
+
] as Array<any>).pipe(
|
|
280
|
+
ClaudeAgent.toStreamParts,
|
|
281
|
+
Stream.runCollect,
|
|
282
|
+
Effect.flip,
|
|
283
|
+
)
|
|
284
|
+
assert.strictEqual(error.reason._tag, "RateLimitError")
|
|
285
|
+
if (error.reason._tag !== "RateLimitError") return
|
|
286
|
+
assert.isTrue(error.isRetryable)
|
|
287
|
+
assert.strictEqual(
|
|
288
|
+
error.reason.metadata.description,
|
|
289
|
+
"result" in result ? result.result : description,
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
it.effect("keeps unrelated request rejections non-retryable", () =>
|
|
296
|
+
Effect.gen(function* () {
|
|
297
|
+
const error = yield* Stream.fromIterable([
|
|
298
|
+
{
|
|
299
|
+
...frame,
|
|
300
|
+
type: "result",
|
|
301
|
+
subtype: "success",
|
|
302
|
+
is_error: true,
|
|
303
|
+
result: "API Error: Request rejected (403)",
|
|
304
|
+
api_error_status: 403,
|
|
305
|
+
},
|
|
306
|
+
] as Array<any>).pipe(
|
|
307
|
+
ClaudeAgent.toStreamParts,
|
|
308
|
+
Stream.runCollect,
|
|
309
|
+
Effect.flip,
|
|
310
|
+
)
|
|
311
|
+
assert.isFalse(error.isRetryable)
|
|
312
|
+
}),
|
|
313
|
+
)
|
|
314
|
+
|
|
253
315
|
it.effect("converts a tool step to response parts", () =>
|
|
254
316
|
Effect.gen(function* () {
|
|
255
317
|
const parts = yield* Stream.fromIterable(toolStep as Array<any>).pipe(
|
package/src/ClaudeAgent.ts
CHANGED
|
@@ -344,7 +344,13 @@ const resultError = (
|
|
|
344
344
|
case "invalid_request":
|
|
345
345
|
return aiError(new AiError.InvalidRequestError({ description }))
|
|
346
346
|
}
|
|
347
|
-
//
|
|
347
|
+
// Credential cooldowns can outlast Claude Code's own retries.
|
|
348
|
+
if (
|
|
349
|
+
status === 429 ||
|
|
350
|
+
/Request rejected \(429\)|\brate_limit_error\b/i.test(description)
|
|
351
|
+
) {
|
|
352
|
+
return aiError(new AiError.RateLimitError({ metadata: { description } }))
|
|
353
|
+
}
|
|
348
354
|
return aiError(
|
|
349
355
|
/prompt is too long/i.test(description)
|
|
350
356
|
? new AiError.InvalidRequestError({ description })
|