blun-king-cli 9.1.424 → 9.1.425
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/bin/subagent-max-tokens-handoff-policy.cjs +55 -0
- package/blun.mjs +25 -6
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const MAX_SUBAGENT_HANDOFF_ATTEMPTS = 1;
|
|
4
|
+
const MAX_PARTIAL_HANDOFF_CHARS = 6000;
|
|
5
|
+
const SUBAGENT_MAX_TOKENS_ERROR =
|
|
6
|
+
"Subagent turn failed before completing its final summary: reason=max_tokens";
|
|
7
|
+
const SUBAGENT_MAX_TOKENS_HANDOFF_PROMPT = [
|
|
8
|
+
"Your previous turn reached max_tokens before its final handoff.",
|
|
9
|
+
"Do not call any tools and do not repeat completed work.",
|
|
10
|
+
"Return one concise recovery handoff of at most 1200 words with:",
|
|
11
|
+
"1. completed work and concrete findings",
|
|
12
|
+
"2. exact files changed or created",
|
|
13
|
+
"3. checks already run and their actual results",
|
|
14
|
+
"4. unfinished work or blockers",
|
|
15
|
+
"5. the exact next action for the parent or this same agent",
|
|
16
|
+
"State clearly that the task is incomplete when anything remains.",
|
|
17
|
+
].join("\n");
|
|
18
|
+
|
|
19
|
+
function shouldRequestSubagentHandoff(stopReason, attempts) {
|
|
20
|
+
return stopReason === "max_tokens"
|
|
21
|
+
&& Number.isSafeInteger(attempts)
|
|
22
|
+
&& attempts >= 0
|
|
23
|
+
&& attempts < MAX_SUBAGENT_HANDOFF_ATTEMPTS;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function boundedPartialHandoff(partialSummary) {
|
|
27
|
+
const normalized = typeof partialSummary === "string" ? partialSummary.trim() : "";
|
|
28
|
+
if (normalized.length <= MAX_PARTIAL_HANDOFF_CHARS) return normalized;
|
|
29
|
+
return `${normalized.slice(0, MAX_PARTIAL_HANDOFF_CHARS)}\n[partial handoff truncated]`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function buildSubagentMaxTokensFailure(partialSummary) {
|
|
33
|
+
const partial = boundedPartialHandoff(partialSummary);
|
|
34
|
+
const lines = [
|
|
35
|
+
`${SUBAGENT_MAX_TOKENS_ERROR}.`,
|
|
36
|
+
"The automatic concise handoff also reached max_tokens.",
|
|
37
|
+
];
|
|
38
|
+
if (partial.length > 0) {
|
|
39
|
+
lines.push("", "[partial_handoff]", partial, "[/partial_handoff]");
|
|
40
|
+
}
|
|
41
|
+
lines.push(
|
|
42
|
+
"",
|
|
43
|
+
"Resume the same subagent instead of starting the task again; its context and completed tool work are preserved.",
|
|
44
|
+
);
|
|
45
|
+
return lines.join("\n");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
MAX_PARTIAL_HANDOFF_CHARS,
|
|
50
|
+
MAX_SUBAGENT_HANDOFF_ATTEMPTS,
|
|
51
|
+
SUBAGENT_MAX_TOKENS_ERROR,
|
|
52
|
+
SUBAGENT_MAX_TOKENS_HANDOFF_PROMPT,
|
|
53
|
+
buildSubagentMaxTokensFailure,
|
|
54
|
+
shouldRequestSubagentHandoff,
|
|
55
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -252261,7 +252261,21 @@ async function runChildTurnToCompletion(child, signal) {
|
|
|
252261
252261
|
if (typeof statusCode === "number") error.statusCode = statusCode;
|
|
252262
252262
|
throw error;
|
|
252263
252263
|
}
|
|
252264
|
-
|
|
252264
|
+
return completion.stopReason;
|
|
252265
|
+
}
|
|
252266
|
+
async function completeChildTurnWithMaxTokensHandoff(child, signal) {
|
|
252267
|
+
let stopReason = await runChildTurnToCompletion(child, signal);
|
|
252268
|
+
let handoffAttempts = 0;
|
|
252269
|
+
while (shouldRequestSubagentHandoff(stopReason, handoffAttempts)) {
|
|
252270
|
+
handoffAttempts += 1;
|
|
252271
|
+
signal.throwIfAborted();
|
|
252272
|
+
if (child.turn.prompt([{
|
|
252273
|
+
type: "text",
|
|
252274
|
+
text: SUBAGENT_MAX_TOKENS_HANDOFF_PROMPT
|
|
252275
|
+
}], SUBAGENT_PROMPT_ORIGIN) === null) throw new Error("Subagent could not start its max_tokens recovery handoff.");
|
|
252276
|
+
stopReason = await runChildTurnToCompletion(child, signal);
|
|
252277
|
+
}
|
|
252278
|
+
if (stopReason === "max_tokens") throw new Error(buildSubagentMaxTokensFailure(lastAssistantText(child)));
|
|
252265
252279
|
}
|
|
252266
252280
|
function providerRateLimitErrorFromPayload(error) {
|
|
252267
252281
|
const requestId = typeof error.details?.["requestId"] === "string" ? error.details["requestId"] : null;
|
|
@@ -252280,7 +252294,7 @@ function shouldSuppressQueuedAttemptFailureEvent(options, error) {
|
|
|
252280
252294
|
if (isProviderRateLimitError(error)) return true;
|
|
252281
252295
|
return isAbortError$4(error) || options.signal.aborted;
|
|
252282
252296
|
}
|
|
252283
|
-
var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, buildSubagentUsageDelta, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH,
|
|
252297
|
+
var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, buildSubagentUsageDelta, SUBAGENT_MAX_TOKENS_ERROR, SUBAGENT_MAX_TOKENS_HANDOFF_PROMPT, buildSubagentMaxTokensFailure, shouldRequestSubagentHandoff, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH, TOOL_CALL_DISABLED_MESSAGE, SUBAGENT_PROMPT_ORIGIN, SIDE_QUESTION_SYSTEM_REMINDER, SessionSubagentHost;
|
|
252284
252298
|
var init_subagent_host = __esmMin((() => {
|
|
252285
252299
|
init_src$4();
|
|
252286
252300
|
init_errors$8();
|
|
@@ -252294,10 +252308,15 @@ var init_subagent_host = __esmMin((() => {
|
|
|
252294
252308
|
init_summary_continuation();
|
|
252295
252309
|
({ DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation } = createRequire(import.meta.url)("./bin/subagent-timeout-policy.cjs"));
|
|
252296
252310
|
({ buildSubagentUsageDelta } = createRequire(import.meta.url)("./bin/subagent-usage-rollup-policy.cjs"));
|
|
252311
|
+
({
|
|
252312
|
+
SUBAGENT_MAX_TOKENS_ERROR,
|
|
252313
|
+
SUBAGENT_MAX_TOKENS_HANDOFF_PROMPT,
|
|
252314
|
+
buildSubagentMaxTokensFailure,
|
|
252315
|
+
shouldRequestSubagentHandoff
|
|
252316
|
+
} = createRequire(import.meta.url)("./bin/subagent-max-tokens-handoff-policy.cjs"));
|
|
252297
252317
|
SUMMARY_MIN_LENGTH = 200;
|
|
252298
252318
|
SUMMARY_CONTINUATION_ATTEMPTS = 1;
|
|
252299
252319
|
HOOK_TEXT_PREVIEW_LENGTH = 500;
|
|
252300
|
-
SUBAGENT_MAX_TOKENS_ERROR = "Subagent turn failed before completing its final summary: reason=max_tokens";
|
|
252301
252320
|
TOOL_CALL_DISABLED_MESSAGE = "Tool calls are disabled for side questions. Answer with text only.";
|
|
252302
252321
|
SUBAGENT_PROMPT_ORIGIN = {
|
|
252303
252322
|
kind: "system_trigger",
|
|
@@ -252561,7 +252580,7 @@ IMPORTANT:
|
|
|
252561
252580
|
return this.waitForChildCompletion(parent, childId, child, profileName, options);
|
|
252562
252581
|
}
|
|
252563
252582
|
async waitForChildCompletion(parent, childId, child, profileName, options) {
|
|
252564
|
-
await
|
|
252583
|
+
await completeChildTurnWithMaxTokensHandoff(child, options.signal);
|
|
252565
252584
|
let result = lastAssistantText(child);
|
|
252566
252585
|
let remainingContinuations = SUMMARY_CONTINUATION_ATTEMPTS;
|
|
252567
252586
|
while (remainingContinuations > 0 && result.length < SUMMARY_MIN_LENGTH) {
|
|
@@ -252571,7 +252590,7 @@ IMPORTANT:
|
|
|
252571
252590
|
type: "text",
|
|
252572
252591
|
text: summary_continuation_default
|
|
252573
252592
|
}], SUBAGENT_PROMPT_ORIGIN);
|
|
252574
|
-
await
|
|
252593
|
+
await completeChildTurnWithMaxTokensHandoff(child, options.signal);
|
|
252575
252594
|
result = lastAssistantText(child);
|
|
252576
252595
|
}
|
|
252577
252596
|
const usage = child.usage.data().total;
|
|
@@ -252709,7 +252728,7 @@ function formatForegroundAgentFailure(handle, message, timedOut) {
|
|
|
252709
252728
|
"",
|
|
252710
252729
|
`subagent error: ${message}`
|
|
252711
252730
|
];
|
|
252712
|
-
if (timedOut) lines.push(`resume_hint: Continue with Agent(resume="${handle.agentId}", prompt="continue"). Use agent_id only; do not set subagent_type. The subagent retains its prior context; redo any unfinished tool call if its result was lost.`);
|
|
252731
|
+
if (timedOut || message.includes(SUBAGENT_MAX_TOKENS_ERROR)) lines.push(`resume_hint: Continue with Agent(resume="${handle.agentId}", prompt="continue"). Use agent_id only; do not set subagent_type. The subagent retains its prior context; redo any unfinished tool call if its result was lost.`);
|
|
252713
252732
|
return lines.join("\n");
|
|
252714
252733
|
}
|
|
252715
252734
|
function launchErrorMessage(error, signal) {
|