@mindstudio-ai/remy 0.1.274 → 0.1.275
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/headless.js +100 -24
- package/dist/index.js +107 -31
- package/package.json +1 -1
package/dist/headless.js
CHANGED
|
@@ -3301,18 +3301,70 @@ ${partial}` : "[INTERRUPTED] Tool execution was stopped.";
|
|
|
3301
3301
|
}
|
|
3302
3302
|
};
|
|
3303
3303
|
|
|
3304
|
-
// src/
|
|
3304
|
+
// src/historyLimits.ts
|
|
3305
3305
|
var MAX_TOOL_RESULT_BYTES = 256 * 1024;
|
|
3306
|
-
function capToolResult(result) {
|
|
3306
|
+
function capToolResult(result, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
3307
3307
|
const total = Buffer.byteLength(result, "utf-8");
|
|
3308
|
-
if (total <=
|
|
3308
|
+
if (total <= maxBytes) {
|
|
3309
3309
|
return result;
|
|
3310
3310
|
}
|
|
3311
|
-
const head = Buffer.from(result, "utf-8").subarray(0,
|
|
3311
|
+
const head = Buffer.from(result, "utf-8").subarray(0, maxBytes).toString("utf-8");
|
|
3312
3312
|
return head + `
|
|
3313
3313
|
|
|
3314
|
-
(tool result truncated at ${(
|
|
3314
|
+
(tool result truncated at ${(maxBytes / 1024).toFixed(0)}KB of ${(total / 1024).toFixed(0)}KB \u2014 too large to keep in context. Narrow the call (select fewer fields, paginate, or query a subset) instead of fetching everything.)`;
|
|
3315
3315
|
}
|
|
3316
|
+
var MAX_SUBAGENT_RESULT_BYTES = 32 * 1024;
|
|
3317
|
+
var MAX_SUBAGENT_TRANSCRIPT_BYTES = 512 * 1024;
|
|
3318
|
+
function capSubAgentTranscript(messages) {
|
|
3319
|
+
for (const msg of messages) {
|
|
3320
|
+
capMessageForHistory(msg, MAX_SUBAGENT_RESULT_BYTES);
|
|
3321
|
+
}
|
|
3322
|
+
const sizes = messages.map(
|
|
3323
|
+
(m) => Buffer.byteLength(JSON.stringify(m), "utf-8") + 1
|
|
3324
|
+
);
|
|
3325
|
+
let total = sizes.reduce((a, b) => a + b, 0);
|
|
3326
|
+
if (total <= MAX_SUBAGENT_TRANSCRIPT_BYTES) {
|
|
3327
|
+
return messages;
|
|
3328
|
+
}
|
|
3329
|
+
let start = 0;
|
|
3330
|
+
while (start < messages.length - 1 && total > MAX_SUBAGENT_TRANSCRIPT_BYTES) {
|
|
3331
|
+
total -= sizes[start];
|
|
3332
|
+
start++;
|
|
3333
|
+
}
|
|
3334
|
+
while (start < messages.length - 1 && messages[start].role === "user" && messages[start].toolCallId) {
|
|
3335
|
+
start++;
|
|
3336
|
+
}
|
|
3337
|
+
return messages.slice(start);
|
|
3338
|
+
}
|
|
3339
|
+
function capMessageForHistory(msg, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
3340
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
3341
|
+
for (const block of msg.content) {
|
|
3342
|
+
if (block.type !== "tool") {
|
|
3343
|
+
continue;
|
|
3344
|
+
}
|
|
3345
|
+
if (typeof block.result === "string") {
|
|
3346
|
+
block.result = capToolResult(block.result, maxBytes);
|
|
3347
|
+
}
|
|
3348
|
+
if (typeof block.backgroundResult === "string") {
|
|
3349
|
+
block.backgroundResult = capToolResult(
|
|
3350
|
+
block.backgroundResult,
|
|
3351
|
+
maxBytes
|
|
3352
|
+
);
|
|
3353
|
+
}
|
|
3354
|
+
if (Array.isArray(block.subAgentMessages)) {
|
|
3355
|
+
block.subAgentMessages = capSubAgentTranscript(block.subAgentMessages);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
3359
|
+
msg.content = capToolResult(msg.content, maxBytes);
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
var HISTORY_PAGE_MAX_BYTES = 2 * 1024 * 1024;
|
|
3363
|
+
var HISTORY_DEFAULT_LIMIT = 500;
|
|
3364
|
+
var HISTORY_MAX_LIMIT = 2e3;
|
|
3365
|
+
var ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
3366
|
+
var RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
3367
|
+
var ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
3316
3368
|
|
|
3317
3369
|
// src/statusWatcher.ts
|
|
3318
3370
|
var INTERNAL_PAYLOAD_MARKERS = [
|
|
@@ -3944,7 +3996,7 @@ ${partial}` : "[INTERRUPTED] Agent was interrupted before producing output.",
|
|
|
3944
3996
|
block.completedAt = Date.now();
|
|
3945
3997
|
const innerMsgs = subAgentMessages.get(r.id);
|
|
3946
3998
|
if (innerMsgs) {
|
|
3947
|
-
block.subAgentMessages = innerMsgs;
|
|
3999
|
+
block.subAgentMessages = capSubAgentTranscript(innerMsgs);
|
|
3948
4000
|
}
|
|
3949
4001
|
if (captureArtifacts?.includes(block.name) && !r.isError) {
|
|
3950
4002
|
try {
|
|
@@ -6677,14 +6729,9 @@ import path11 from "path";
|
|
|
6677
6729
|
var log10 = createLogger("session");
|
|
6678
6730
|
var SESSION_FILE = ".remy-session.json";
|
|
6679
6731
|
var ARCHIVE_DIR = ".logs/sessions";
|
|
6680
|
-
var ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
6681
|
-
var RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
6682
|
-
var ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
6683
6732
|
var ARCHIVE_NAME_RE = /^(cleared|rotated)-.*\.json$/;
|
|
6684
6733
|
var archiveSortKey = (name) => name.replace(/^(cleared|rotated)-/, "");
|
|
6685
6734
|
var ARCHIVE_COUNT_RE = /\.c(\d+)\.json$/;
|
|
6686
|
-
var HISTORY_DEFAULT_LIMIT = 500;
|
|
6687
|
-
var HISTORY_MAX_LIMIT = 2e3;
|
|
6688
6735
|
var archiveCountCache = /* @__PURE__ */ new Map();
|
|
6689
6736
|
var archiveMsgCache = /* @__PURE__ */ new Map();
|
|
6690
6737
|
var ARCHIVE_MSG_CACHE_MAX = 3;
|
|
@@ -6714,22 +6761,11 @@ function loadSession(state) {
|
|
|
6714
6761
|
}
|
|
6715
6762
|
return false;
|
|
6716
6763
|
}
|
|
6717
|
-
function capOversizedResults(msg) {
|
|
6718
|
-
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
6719
|
-
for (const block of msg.content) {
|
|
6720
|
-
if (block.type === "tool" && typeof block.result === "string") {
|
|
6721
|
-
block.result = capToolResult(block.result);
|
|
6722
|
-
}
|
|
6723
|
-
}
|
|
6724
|
-
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
6725
|
-
msg.content = capToolResult(msg.content);
|
|
6726
|
-
}
|
|
6727
|
-
}
|
|
6728
6764
|
function sanitizeMessages(messages) {
|
|
6729
6765
|
const result = [];
|
|
6730
6766
|
for (let i = 0; i < messages.length; i++) {
|
|
6731
6767
|
const msg = messages[i];
|
|
6732
|
-
|
|
6768
|
+
capMessageForHistory(msg);
|
|
6733
6769
|
result.push(msg);
|
|
6734
6770
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
6735
6771
|
continue;
|
|
@@ -6841,6 +6877,9 @@ function parseArchive(name) {
|
|
|
6841
6877
|
const raw = fs21.readFileSync(path11.join(ARCHIVE_DIR, name), "utf-8");
|
|
6842
6878
|
const data = JSON.parse(raw);
|
|
6843
6879
|
const messages = Array.isArray(data?.messages) ? data.messages : [];
|
|
6880
|
+
for (const msg of messages) {
|
|
6881
|
+
capMessageForHistory(msg);
|
|
6882
|
+
}
|
|
6844
6883
|
archiveCountCache.set(name, messages.length);
|
|
6845
6884
|
archiveMsgCache.set(name, messages);
|
|
6846
6885
|
while (archiveMsgCache.size > ARCHIVE_MSG_CACHE_MAX) {
|
|
@@ -6951,6 +6990,29 @@ function getHistoryPage(state, opts) {
|
|
|
6951
6990
|
messages.push(state.messages[i]);
|
|
6952
6991
|
}
|
|
6953
6992
|
}
|
|
6993
|
+
if (messages.length > 1) {
|
|
6994
|
+
let bytes = 0;
|
|
6995
|
+
let cut = 0;
|
|
6996
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6997
|
+
bytes += Buffer.byteLength(JSON.stringify(messages[i]), "utf-8") + 1;
|
|
6998
|
+
if (bytes > HISTORY_PAGE_MAX_BYTES && i < messages.length - 1) {
|
|
6999
|
+
cut = i + 1;
|
|
7000
|
+
break;
|
|
7001
|
+
}
|
|
7002
|
+
}
|
|
7003
|
+
if (cut > 0) {
|
|
7004
|
+
while (cut < messages.length - 1 && messages[cut]?.role === "user" && messages[cut]?.toolCallId) {
|
|
7005
|
+
cut++;
|
|
7006
|
+
}
|
|
7007
|
+
messages.splice(0, cut);
|
|
7008
|
+
startIndex += cut;
|
|
7009
|
+
log10.info("History page trimmed to byte budget", {
|
|
7010
|
+
dropped: cut,
|
|
7011
|
+
kept: messages.length,
|
|
7012
|
+
startIndex
|
|
7013
|
+
});
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
6954
7016
|
return { messages, startIndex, endIndex, totalMessageCount: total };
|
|
6955
7017
|
}
|
|
6956
7018
|
function rotate(state) {
|
|
@@ -7845,6 +7907,8 @@ async function runTurn(params) {
|
|
|
7845
7907
|
let lastCallInputTokens = 0;
|
|
7846
7908
|
let lastCallCacheCreation = 0;
|
|
7847
7909
|
let lastCallCacheRead = 0;
|
|
7910
|
+
let abnormalStopRecoveries = 0;
|
|
7911
|
+
const MAX_ABNORMAL_STOP_RECOVERIES = 2;
|
|
7848
7912
|
const statusWatcher = isFirstMessage ? { stop() {
|
|
7849
7913
|
}, pause() {
|
|
7850
7914
|
}, resume() {
|
|
@@ -8188,6 +8252,18 @@ async function runTurn(params) {
|
|
|
8188
8252
|
});
|
|
8189
8253
|
}
|
|
8190
8254
|
const toolCalls = getToolCalls(contentBlocks);
|
|
8255
|
+
if (toolCalls.length === 0 && (stopReason === "repetition" || stopReason === "max_tokens") && abnormalStopRecoveries < MAX_ABNORMAL_STOP_RECOVERIES && !signal?.aborted) {
|
|
8256
|
+
abnormalStopRecoveries++;
|
|
8257
|
+
log14.warn("Abnormal stop \u2014 nudging model to continue", {
|
|
8258
|
+
requestId,
|
|
8259
|
+
stopReason,
|
|
8260
|
+
attempt: abnormalStopRecoveries
|
|
8261
|
+
});
|
|
8262
|
+
const nudge = "Your previous response was cut off \u2014 it degenerated into repeated text or hit the output limit, and the repeated portion was removed. Reassess where you are in the task and continue from where you left off. Prefer a tool call over restating what you were about to do.";
|
|
8263
|
+
state.messages.push({ role: "user", content: nudge, hidden: true });
|
|
8264
|
+
onEvent({ type: "user_message", text: nudge, hidden: true });
|
|
8265
|
+
continue;
|
|
8266
|
+
}
|
|
8191
8267
|
if (stopReason !== "tool_use" || toolCalls.length === 0) {
|
|
8192
8268
|
statusWatcher.stop();
|
|
8193
8269
|
saveSession(state);
|
|
@@ -8354,7 +8430,7 @@ async function runTurn(params) {
|
|
|
8354
8430
|
block.completedAt = Date.now();
|
|
8355
8431
|
const msgs = subAgentMessages.get(r.id);
|
|
8356
8432
|
if (msgs) {
|
|
8357
|
-
block.subAgentMessages = msgs;
|
|
8433
|
+
block.subAgentMessages = capSubAgentTranscript(msgs);
|
|
8358
8434
|
}
|
|
8359
8435
|
}
|
|
8360
8436
|
}
|
package/dist/index.js
CHANGED
|
@@ -2409,22 +2409,74 @@ var init_cleanMessages = __esm({
|
|
|
2409
2409
|
}
|
|
2410
2410
|
});
|
|
2411
2411
|
|
|
2412
|
-
// src/
|
|
2413
|
-
function capToolResult(result) {
|
|
2412
|
+
// src/historyLimits.ts
|
|
2413
|
+
function capToolResult(result, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
2414
2414
|
const total = Buffer.byteLength(result, "utf-8");
|
|
2415
|
-
if (total <=
|
|
2415
|
+
if (total <= maxBytes) {
|
|
2416
2416
|
return result;
|
|
2417
2417
|
}
|
|
2418
|
-
const head = Buffer.from(result, "utf-8").subarray(0,
|
|
2418
|
+
const head = Buffer.from(result, "utf-8").subarray(0, maxBytes).toString("utf-8");
|
|
2419
2419
|
return head + `
|
|
2420
2420
|
|
|
2421
|
-
(tool result truncated at ${(
|
|
2421
|
+
(tool result truncated at ${(maxBytes / 1024).toFixed(0)}KB of ${(total / 1024).toFixed(0)}KB \u2014 too large to keep in context. Narrow the call (select fewer fields, paginate, or query a subset) instead of fetching everything.)`;
|
|
2422
2422
|
}
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2423
|
+
function capSubAgentTranscript(messages) {
|
|
2424
|
+
for (const msg of messages) {
|
|
2425
|
+
capMessageForHistory(msg, MAX_SUBAGENT_RESULT_BYTES);
|
|
2426
|
+
}
|
|
2427
|
+
const sizes = messages.map(
|
|
2428
|
+
(m) => Buffer.byteLength(JSON.stringify(m), "utf-8") + 1
|
|
2429
|
+
);
|
|
2430
|
+
let total = sizes.reduce((a, b) => a + b, 0);
|
|
2431
|
+
if (total <= MAX_SUBAGENT_TRANSCRIPT_BYTES) {
|
|
2432
|
+
return messages;
|
|
2433
|
+
}
|
|
2434
|
+
let start = 0;
|
|
2435
|
+
while (start < messages.length - 1 && total > MAX_SUBAGENT_TRANSCRIPT_BYTES) {
|
|
2436
|
+
total -= sizes[start];
|
|
2437
|
+
start++;
|
|
2438
|
+
}
|
|
2439
|
+
while (start < messages.length - 1 && messages[start].role === "user" && messages[start].toolCallId) {
|
|
2440
|
+
start++;
|
|
2441
|
+
}
|
|
2442
|
+
return messages.slice(start);
|
|
2443
|
+
}
|
|
2444
|
+
function capMessageForHistory(msg, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
2445
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
2446
|
+
for (const block of msg.content) {
|
|
2447
|
+
if (block.type !== "tool") {
|
|
2448
|
+
continue;
|
|
2449
|
+
}
|
|
2450
|
+
if (typeof block.result === "string") {
|
|
2451
|
+
block.result = capToolResult(block.result, maxBytes);
|
|
2452
|
+
}
|
|
2453
|
+
if (typeof block.backgroundResult === "string") {
|
|
2454
|
+
block.backgroundResult = capToolResult(
|
|
2455
|
+
block.backgroundResult,
|
|
2456
|
+
maxBytes
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2459
|
+
if (Array.isArray(block.subAgentMessages)) {
|
|
2460
|
+
block.subAgentMessages = capSubAgentTranscript(block.subAgentMessages);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
2464
|
+
msg.content = capToolResult(msg.content, maxBytes);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
var MAX_TOOL_RESULT_BYTES, MAX_SUBAGENT_RESULT_BYTES, MAX_SUBAGENT_TRANSCRIPT_BYTES, HISTORY_PAGE_MAX_BYTES, HISTORY_DEFAULT_LIMIT, HISTORY_MAX_LIMIT, ROTATE_THRESHOLD_BYTES, RETAIN_TAIL_BYTES, ARCHIVE_RETENTION_BYTES;
|
|
2468
|
+
var init_historyLimits = __esm({
|
|
2469
|
+
"src/historyLimits.ts"() {
|
|
2426
2470
|
"use strict";
|
|
2427
2471
|
MAX_TOOL_RESULT_BYTES = 256 * 1024;
|
|
2472
|
+
MAX_SUBAGENT_RESULT_BYTES = 32 * 1024;
|
|
2473
|
+
MAX_SUBAGENT_TRANSCRIPT_BYTES = 512 * 1024;
|
|
2474
|
+
HISTORY_PAGE_MAX_BYTES = 2 * 1024 * 1024;
|
|
2475
|
+
HISTORY_DEFAULT_LIMIT = 500;
|
|
2476
|
+
HISTORY_MAX_LIMIT = 2e3;
|
|
2477
|
+
ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
2478
|
+
RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
2479
|
+
ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
2428
2480
|
}
|
|
2429
2481
|
});
|
|
2430
2482
|
|
|
@@ -2457,22 +2509,11 @@ function loadSession(state) {
|
|
|
2457
2509
|
}
|
|
2458
2510
|
return false;
|
|
2459
2511
|
}
|
|
2460
|
-
function capOversizedResults(msg) {
|
|
2461
|
-
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
2462
|
-
for (const block of msg.content) {
|
|
2463
|
-
if (block.type === "tool" && typeof block.result === "string") {
|
|
2464
|
-
block.result = capToolResult(block.result);
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
2468
|
-
msg.content = capToolResult(msg.content);
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
2512
|
function sanitizeMessages(messages) {
|
|
2472
2513
|
const result = [];
|
|
2473
2514
|
for (let i = 0; i < messages.length; i++) {
|
|
2474
2515
|
const msg = messages[i];
|
|
2475
|
-
|
|
2516
|
+
capMessageForHistory(msg);
|
|
2476
2517
|
result.push(msg);
|
|
2477
2518
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
2478
2519
|
continue;
|
|
@@ -2584,6 +2625,9 @@ function parseArchive(name) {
|
|
|
2584
2625
|
const raw = fs10.readFileSync(path4.join(ARCHIVE_DIR, name), "utf-8");
|
|
2585
2626
|
const data = JSON.parse(raw);
|
|
2586
2627
|
const messages = Array.isArray(data?.messages) ? data.messages : [];
|
|
2628
|
+
for (const msg of messages) {
|
|
2629
|
+
capMessageForHistory(msg);
|
|
2630
|
+
}
|
|
2587
2631
|
archiveCountCache.set(name, messages.length);
|
|
2588
2632
|
archiveMsgCache.set(name, messages);
|
|
2589
2633
|
while (archiveMsgCache.size > ARCHIVE_MSG_CACHE_MAX) {
|
|
@@ -2694,6 +2738,29 @@ function getHistoryPage(state, opts) {
|
|
|
2694
2738
|
messages.push(state.messages[i]);
|
|
2695
2739
|
}
|
|
2696
2740
|
}
|
|
2741
|
+
if (messages.length > 1) {
|
|
2742
|
+
let bytes = 0;
|
|
2743
|
+
let cut = 0;
|
|
2744
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2745
|
+
bytes += Buffer.byteLength(JSON.stringify(messages[i]), "utf-8") + 1;
|
|
2746
|
+
if (bytes > HISTORY_PAGE_MAX_BYTES && i < messages.length - 1) {
|
|
2747
|
+
cut = i + 1;
|
|
2748
|
+
break;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
if (cut > 0) {
|
|
2752
|
+
while (cut < messages.length - 1 && messages[cut]?.role === "user" && messages[cut]?.toolCallId) {
|
|
2753
|
+
cut++;
|
|
2754
|
+
}
|
|
2755
|
+
messages.splice(0, cut);
|
|
2756
|
+
startIndex += cut;
|
|
2757
|
+
log3.info("History page trimmed to byte budget", {
|
|
2758
|
+
dropped: cut,
|
|
2759
|
+
kept: messages.length,
|
|
2760
|
+
startIndex
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2697
2764
|
return { messages, startIndex, endIndex, totalMessageCount: total };
|
|
2698
2765
|
}
|
|
2699
2766
|
function rotate(state) {
|
|
@@ -2755,7 +2822,7 @@ function clearSession(state) {
|
|
|
2755
2822
|
});
|
|
2756
2823
|
}
|
|
2757
2824
|
}
|
|
2758
|
-
var log3, SESSION_FILE, ARCHIVE_DIR,
|
|
2825
|
+
var log3, SESSION_FILE, ARCHIVE_DIR, ARCHIVE_NAME_RE, archiveSortKey, ARCHIVE_COUNT_RE, archiveCountCache, archiveMsgCache, ARCHIVE_MSG_CACHE_MAX;
|
|
2759
2826
|
var init_session = __esm({
|
|
2760
2827
|
"src/session.ts"() {
|
|
2761
2828
|
"use strict";
|
|
@@ -2763,18 +2830,13 @@ var init_session = __esm({
|
|
|
2763
2830
|
init_logger();
|
|
2764
2831
|
init_compaction();
|
|
2765
2832
|
init_cleanMessages();
|
|
2766
|
-
|
|
2833
|
+
init_historyLimits();
|
|
2767
2834
|
log3 = createLogger("session");
|
|
2768
2835
|
SESSION_FILE = ".remy-session.json";
|
|
2769
2836
|
ARCHIVE_DIR = ".logs/sessions";
|
|
2770
|
-
ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
2771
|
-
RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
2772
|
-
ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
2773
2837
|
ARCHIVE_NAME_RE = /^(cleared|rotated)-.*\.json$/;
|
|
2774
2838
|
archiveSortKey = (name) => name.replace(/^(cleared|rotated)-/, "");
|
|
2775
2839
|
ARCHIVE_COUNT_RE = /\.c(\d+)\.json$/;
|
|
2776
|
-
HISTORY_DEFAULT_LIMIT = 500;
|
|
2777
|
-
HISTORY_MAX_LIMIT = 2e3;
|
|
2778
2840
|
archiveCountCache = /* @__PURE__ */ new Map();
|
|
2779
2841
|
archiveMsgCache = /* @__PURE__ */ new Map();
|
|
2780
2842
|
ARCHIVE_MSG_CACHE_MAX = 3;
|
|
@@ -4920,7 +4982,7 @@ ${partial}` : "[INTERRUPTED] Agent was interrupted before producing output.",
|
|
|
4920
4982
|
block.completedAt = Date.now();
|
|
4921
4983
|
const innerMsgs = subAgentMessages.get(r.id);
|
|
4922
4984
|
if (innerMsgs) {
|
|
4923
|
-
block.subAgentMessages = innerMsgs;
|
|
4985
|
+
block.subAgentMessages = capSubAgentTranscript(innerMsgs);
|
|
4924
4986
|
}
|
|
4925
4987
|
if (captureArtifacts?.includes(block.name) && !r.isError) {
|
|
4926
4988
|
try {
|
|
@@ -5008,7 +5070,7 @@ var init_runner = __esm({
|
|
|
5008
5070
|
init_logger();
|
|
5009
5071
|
init_usageLedger();
|
|
5010
5072
|
init_toolRegistry();
|
|
5011
|
-
|
|
5073
|
+
init_historyLimits();
|
|
5012
5074
|
init_statusWatcher();
|
|
5013
5075
|
init_cleanMessages();
|
|
5014
5076
|
log8 = createLogger("sub-agent");
|
|
@@ -8439,6 +8501,8 @@ async function runTurn(params) {
|
|
|
8439
8501
|
let lastCallInputTokens = 0;
|
|
8440
8502
|
let lastCallCacheCreation = 0;
|
|
8441
8503
|
let lastCallCacheRead = 0;
|
|
8504
|
+
let abnormalStopRecoveries = 0;
|
|
8505
|
+
const MAX_ABNORMAL_STOP_RECOVERIES = 2;
|
|
8442
8506
|
const statusWatcher = isFirstMessage ? { stop() {
|
|
8443
8507
|
}, pause() {
|
|
8444
8508
|
}, resume() {
|
|
@@ -8782,6 +8846,18 @@ async function runTurn(params) {
|
|
|
8782
8846
|
});
|
|
8783
8847
|
}
|
|
8784
8848
|
const toolCalls = getToolCalls(contentBlocks);
|
|
8849
|
+
if (toolCalls.length === 0 && (stopReason === "repetition" || stopReason === "max_tokens") && abnormalStopRecoveries < MAX_ABNORMAL_STOP_RECOVERIES && !signal?.aborted) {
|
|
8850
|
+
abnormalStopRecoveries++;
|
|
8851
|
+
log13.warn("Abnormal stop \u2014 nudging model to continue", {
|
|
8852
|
+
requestId,
|
|
8853
|
+
stopReason,
|
|
8854
|
+
attempt: abnormalStopRecoveries
|
|
8855
|
+
});
|
|
8856
|
+
const nudge = "Your previous response was cut off \u2014 it degenerated into repeated text or hit the output limit, and the repeated portion was removed. Reassess where you are in the task and continue from where you left off. Prefer a tool call over restating what you were about to do.";
|
|
8857
|
+
state.messages.push({ role: "user", content: nudge, hidden: true });
|
|
8858
|
+
onEvent({ type: "user_message", text: nudge, hidden: true });
|
|
8859
|
+
continue;
|
|
8860
|
+
}
|
|
8785
8861
|
if (stopReason !== "tool_use" || toolCalls.length === 0) {
|
|
8786
8862
|
statusWatcher.stop();
|
|
8787
8863
|
saveSession(state);
|
|
@@ -8948,7 +9024,7 @@ async function runTurn(params) {
|
|
|
8948
9024
|
block.completedAt = Date.now();
|
|
8949
9025
|
const msgs = subAgentMessages.get(r.id);
|
|
8950
9026
|
if (msgs) {
|
|
8951
|
-
block.subAgentMessages = msgs;
|
|
9027
|
+
block.subAgentMessages = capSubAgentTranscript(msgs);
|
|
8952
9028
|
}
|
|
8953
9029
|
}
|
|
8954
9030
|
}
|
|
@@ -9007,7 +9083,7 @@ var init_agent = __esm({
|
|
|
9007
9083
|
init_trigger2();
|
|
9008
9084
|
init_surfaces();
|
|
9009
9085
|
init_toolRegistry();
|
|
9010
|
-
|
|
9086
|
+
init_historyLimits();
|
|
9011
9087
|
log13 = createLogger("agent");
|
|
9012
9088
|
BRAND_TRIGGERING_TOOLS = /* @__PURE__ */ new Set([
|
|
9013
9089
|
"writeSpec",
|