@mindstudio-ai/remy 0.1.273 → 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 +101 -24
- package/dist/index.js +108 -31
- package/package.json +1 -1
package/dist/headless.js
CHANGED
|
@@ -497,6 +497,7 @@ var ALLOWED_MODELS_BY_TYPE = {
|
|
|
497
497
|
"kimi-k3",
|
|
498
498
|
"deepseek-v4-flash-0731",
|
|
499
499
|
"qwen3.8-2.4t-a95b-deepinfra",
|
|
500
|
+
"qwen3.8-27b-deepinfra",
|
|
500
501
|
"minimax-m3"
|
|
501
502
|
]
|
|
502
503
|
// vision: undefined — unconstrained
|
|
@@ -3300,18 +3301,70 @@ ${partial}` : "[INTERRUPTED] Tool execution was stopped.";
|
|
|
3300
3301
|
}
|
|
3301
3302
|
};
|
|
3302
3303
|
|
|
3303
|
-
// src/
|
|
3304
|
+
// src/historyLimits.ts
|
|
3304
3305
|
var MAX_TOOL_RESULT_BYTES = 256 * 1024;
|
|
3305
|
-
function capToolResult(result) {
|
|
3306
|
+
function capToolResult(result, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
3306
3307
|
const total = Buffer.byteLength(result, "utf-8");
|
|
3307
|
-
if (total <=
|
|
3308
|
+
if (total <= maxBytes) {
|
|
3308
3309
|
return result;
|
|
3309
3310
|
}
|
|
3310
|
-
const head = Buffer.from(result, "utf-8").subarray(0,
|
|
3311
|
+
const head = Buffer.from(result, "utf-8").subarray(0, maxBytes).toString("utf-8");
|
|
3311
3312
|
return head + `
|
|
3312
3313
|
|
|
3313
|
-
(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.)`;
|
|
3314
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;
|
|
3315
3368
|
|
|
3316
3369
|
// src/statusWatcher.ts
|
|
3317
3370
|
var INTERNAL_PAYLOAD_MARKERS = [
|
|
@@ -3943,7 +3996,7 @@ ${partial}` : "[INTERRUPTED] Agent was interrupted before producing output.",
|
|
|
3943
3996
|
block.completedAt = Date.now();
|
|
3944
3997
|
const innerMsgs = subAgentMessages.get(r.id);
|
|
3945
3998
|
if (innerMsgs) {
|
|
3946
|
-
block.subAgentMessages = innerMsgs;
|
|
3999
|
+
block.subAgentMessages = capSubAgentTranscript(innerMsgs);
|
|
3947
4000
|
}
|
|
3948
4001
|
if (captureArtifacts?.includes(block.name) && !r.isError) {
|
|
3949
4002
|
try {
|
|
@@ -6676,14 +6729,9 @@ import path11 from "path";
|
|
|
6676
6729
|
var log10 = createLogger("session");
|
|
6677
6730
|
var SESSION_FILE = ".remy-session.json";
|
|
6678
6731
|
var ARCHIVE_DIR = ".logs/sessions";
|
|
6679
|
-
var ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
6680
|
-
var RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
6681
|
-
var ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
6682
6732
|
var ARCHIVE_NAME_RE = /^(cleared|rotated)-.*\.json$/;
|
|
6683
6733
|
var archiveSortKey = (name) => name.replace(/^(cleared|rotated)-/, "");
|
|
6684
6734
|
var ARCHIVE_COUNT_RE = /\.c(\d+)\.json$/;
|
|
6685
|
-
var HISTORY_DEFAULT_LIMIT = 500;
|
|
6686
|
-
var HISTORY_MAX_LIMIT = 2e3;
|
|
6687
6735
|
var archiveCountCache = /* @__PURE__ */ new Map();
|
|
6688
6736
|
var archiveMsgCache = /* @__PURE__ */ new Map();
|
|
6689
6737
|
var ARCHIVE_MSG_CACHE_MAX = 3;
|
|
@@ -6713,22 +6761,11 @@ function loadSession(state) {
|
|
|
6713
6761
|
}
|
|
6714
6762
|
return false;
|
|
6715
6763
|
}
|
|
6716
|
-
function capOversizedResults(msg) {
|
|
6717
|
-
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
6718
|
-
for (const block of msg.content) {
|
|
6719
|
-
if (block.type === "tool" && typeof block.result === "string") {
|
|
6720
|
-
block.result = capToolResult(block.result);
|
|
6721
|
-
}
|
|
6722
|
-
}
|
|
6723
|
-
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
6724
|
-
msg.content = capToolResult(msg.content);
|
|
6725
|
-
}
|
|
6726
|
-
}
|
|
6727
6764
|
function sanitizeMessages(messages) {
|
|
6728
6765
|
const result = [];
|
|
6729
6766
|
for (let i = 0; i < messages.length; i++) {
|
|
6730
6767
|
const msg = messages[i];
|
|
6731
|
-
|
|
6768
|
+
capMessageForHistory(msg);
|
|
6732
6769
|
result.push(msg);
|
|
6733
6770
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
6734
6771
|
continue;
|
|
@@ -6840,6 +6877,9 @@ function parseArchive(name) {
|
|
|
6840
6877
|
const raw = fs21.readFileSync(path11.join(ARCHIVE_DIR, name), "utf-8");
|
|
6841
6878
|
const data = JSON.parse(raw);
|
|
6842
6879
|
const messages = Array.isArray(data?.messages) ? data.messages : [];
|
|
6880
|
+
for (const msg of messages) {
|
|
6881
|
+
capMessageForHistory(msg);
|
|
6882
|
+
}
|
|
6843
6883
|
archiveCountCache.set(name, messages.length);
|
|
6844
6884
|
archiveMsgCache.set(name, messages);
|
|
6845
6885
|
while (archiveMsgCache.size > ARCHIVE_MSG_CACHE_MAX) {
|
|
@@ -6950,6 +6990,29 @@ function getHistoryPage(state, opts) {
|
|
|
6950
6990
|
messages.push(state.messages[i]);
|
|
6951
6991
|
}
|
|
6952
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
|
+
}
|
|
6953
7016
|
return { messages, startIndex, endIndex, totalMessageCount: total };
|
|
6954
7017
|
}
|
|
6955
7018
|
function rotate(state) {
|
|
@@ -7844,6 +7907,8 @@ async function runTurn(params) {
|
|
|
7844
7907
|
let lastCallInputTokens = 0;
|
|
7845
7908
|
let lastCallCacheCreation = 0;
|
|
7846
7909
|
let lastCallCacheRead = 0;
|
|
7910
|
+
let abnormalStopRecoveries = 0;
|
|
7911
|
+
const MAX_ABNORMAL_STOP_RECOVERIES = 2;
|
|
7847
7912
|
const statusWatcher = isFirstMessage ? { stop() {
|
|
7848
7913
|
}, pause() {
|
|
7849
7914
|
}, resume() {
|
|
@@ -8187,6 +8252,18 @@ async function runTurn(params) {
|
|
|
8187
8252
|
});
|
|
8188
8253
|
}
|
|
8189
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
|
+
}
|
|
8190
8267
|
if (stopReason !== "tool_use" || toolCalls.length === 0) {
|
|
8191
8268
|
statusWatcher.stop();
|
|
8192
8269
|
saveSession(state);
|
|
@@ -8353,7 +8430,7 @@ async function runTurn(params) {
|
|
|
8353
8430
|
block.completedAt = Date.now();
|
|
8354
8431
|
const msgs = subAgentMessages.get(r.id);
|
|
8355
8432
|
if (msgs) {
|
|
8356
|
-
block.subAgentMessages = msgs;
|
|
8433
|
+
block.subAgentMessages = capSubAgentTranscript(msgs);
|
|
8357
8434
|
}
|
|
8358
8435
|
}
|
|
8359
8436
|
}
|
package/dist/index.js
CHANGED
|
@@ -2237,6 +2237,7 @@ var init_surfaces = __esm({
|
|
|
2237
2237
|
"kimi-k3",
|
|
2238
2238
|
"deepseek-v4-flash-0731",
|
|
2239
2239
|
"qwen3.8-2.4t-a95b-deepinfra",
|
|
2240
|
+
"qwen3.8-27b-deepinfra",
|
|
2240
2241
|
"minimax-m3"
|
|
2241
2242
|
]
|
|
2242
2243
|
// vision: undefined — unconstrained
|
|
@@ -2408,22 +2409,74 @@ var init_cleanMessages = __esm({
|
|
|
2408
2409
|
}
|
|
2409
2410
|
});
|
|
2410
2411
|
|
|
2411
|
-
// src/
|
|
2412
|
-
function capToolResult(result) {
|
|
2412
|
+
// src/historyLimits.ts
|
|
2413
|
+
function capToolResult(result, maxBytes = MAX_TOOL_RESULT_BYTES) {
|
|
2413
2414
|
const total = Buffer.byteLength(result, "utf-8");
|
|
2414
|
-
if (total <=
|
|
2415
|
+
if (total <= maxBytes) {
|
|
2415
2416
|
return result;
|
|
2416
2417
|
}
|
|
2417
|
-
const head = Buffer.from(result, "utf-8").subarray(0,
|
|
2418
|
+
const head = Buffer.from(result, "utf-8").subarray(0, maxBytes).toString("utf-8");
|
|
2418
2419
|
return head + `
|
|
2419
2420
|
|
|
2420
|
-
(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.)`;
|
|
2421
2422
|
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
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"() {
|
|
2425
2470
|
"use strict";
|
|
2426
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;
|
|
2427
2480
|
}
|
|
2428
2481
|
});
|
|
2429
2482
|
|
|
@@ -2456,22 +2509,11 @@ function loadSession(state) {
|
|
|
2456
2509
|
}
|
|
2457
2510
|
return false;
|
|
2458
2511
|
}
|
|
2459
|
-
function capOversizedResults(msg) {
|
|
2460
|
-
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
2461
|
-
for (const block of msg.content) {
|
|
2462
|
-
if (block.type === "tool" && typeof block.result === "string") {
|
|
2463
|
-
block.result = capToolResult(block.result);
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
} else if (msg.role === "user" && msg.toolCallId && typeof msg.content === "string") {
|
|
2467
|
-
msg.content = capToolResult(msg.content);
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
2512
|
function sanitizeMessages(messages) {
|
|
2471
2513
|
const result = [];
|
|
2472
2514
|
for (let i = 0; i < messages.length; i++) {
|
|
2473
2515
|
const msg = messages[i];
|
|
2474
|
-
|
|
2516
|
+
capMessageForHistory(msg);
|
|
2475
2517
|
result.push(msg);
|
|
2476
2518
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
2477
2519
|
continue;
|
|
@@ -2583,6 +2625,9 @@ function parseArchive(name) {
|
|
|
2583
2625
|
const raw = fs10.readFileSync(path4.join(ARCHIVE_DIR, name), "utf-8");
|
|
2584
2626
|
const data = JSON.parse(raw);
|
|
2585
2627
|
const messages = Array.isArray(data?.messages) ? data.messages : [];
|
|
2628
|
+
for (const msg of messages) {
|
|
2629
|
+
capMessageForHistory(msg);
|
|
2630
|
+
}
|
|
2586
2631
|
archiveCountCache.set(name, messages.length);
|
|
2587
2632
|
archiveMsgCache.set(name, messages);
|
|
2588
2633
|
while (archiveMsgCache.size > ARCHIVE_MSG_CACHE_MAX) {
|
|
@@ -2693,6 +2738,29 @@ function getHistoryPage(state, opts) {
|
|
|
2693
2738
|
messages.push(state.messages[i]);
|
|
2694
2739
|
}
|
|
2695
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
|
+
}
|
|
2696
2764
|
return { messages, startIndex, endIndex, totalMessageCount: total };
|
|
2697
2765
|
}
|
|
2698
2766
|
function rotate(state) {
|
|
@@ -2754,7 +2822,7 @@ function clearSession(state) {
|
|
|
2754
2822
|
});
|
|
2755
2823
|
}
|
|
2756
2824
|
}
|
|
2757
|
-
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;
|
|
2758
2826
|
var init_session = __esm({
|
|
2759
2827
|
"src/session.ts"() {
|
|
2760
2828
|
"use strict";
|
|
@@ -2762,18 +2830,13 @@ var init_session = __esm({
|
|
|
2762
2830
|
init_logger();
|
|
2763
2831
|
init_compaction();
|
|
2764
2832
|
init_cleanMessages();
|
|
2765
|
-
|
|
2833
|
+
init_historyLimits();
|
|
2766
2834
|
log3 = createLogger("session");
|
|
2767
2835
|
SESSION_FILE = ".remy-session.json";
|
|
2768
2836
|
ARCHIVE_DIR = ".logs/sessions";
|
|
2769
|
-
ROTATE_THRESHOLD_BYTES = 32 * 1024 * 1024;
|
|
2770
|
-
RETAIN_TAIL_BYTES = 16 * 1024 * 1024;
|
|
2771
|
-
ARCHIVE_RETENTION_BYTES = 64 * 1024 * 1024;
|
|
2772
2837
|
ARCHIVE_NAME_RE = /^(cleared|rotated)-.*\.json$/;
|
|
2773
2838
|
archiveSortKey = (name) => name.replace(/^(cleared|rotated)-/, "");
|
|
2774
2839
|
ARCHIVE_COUNT_RE = /\.c(\d+)\.json$/;
|
|
2775
|
-
HISTORY_DEFAULT_LIMIT = 500;
|
|
2776
|
-
HISTORY_MAX_LIMIT = 2e3;
|
|
2777
2840
|
archiveCountCache = /* @__PURE__ */ new Map();
|
|
2778
2841
|
archiveMsgCache = /* @__PURE__ */ new Map();
|
|
2779
2842
|
ARCHIVE_MSG_CACHE_MAX = 3;
|
|
@@ -4919,7 +4982,7 @@ ${partial}` : "[INTERRUPTED] Agent was interrupted before producing output.",
|
|
|
4919
4982
|
block.completedAt = Date.now();
|
|
4920
4983
|
const innerMsgs = subAgentMessages.get(r.id);
|
|
4921
4984
|
if (innerMsgs) {
|
|
4922
|
-
block.subAgentMessages = innerMsgs;
|
|
4985
|
+
block.subAgentMessages = capSubAgentTranscript(innerMsgs);
|
|
4923
4986
|
}
|
|
4924
4987
|
if (captureArtifacts?.includes(block.name) && !r.isError) {
|
|
4925
4988
|
try {
|
|
@@ -5007,7 +5070,7 @@ var init_runner = __esm({
|
|
|
5007
5070
|
init_logger();
|
|
5008
5071
|
init_usageLedger();
|
|
5009
5072
|
init_toolRegistry();
|
|
5010
|
-
|
|
5073
|
+
init_historyLimits();
|
|
5011
5074
|
init_statusWatcher();
|
|
5012
5075
|
init_cleanMessages();
|
|
5013
5076
|
log8 = createLogger("sub-agent");
|
|
@@ -8438,6 +8501,8 @@ async function runTurn(params) {
|
|
|
8438
8501
|
let lastCallInputTokens = 0;
|
|
8439
8502
|
let lastCallCacheCreation = 0;
|
|
8440
8503
|
let lastCallCacheRead = 0;
|
|
8504
|
+
let abnormalStopRecoveries = 0;
|
|
8505
|
+
const MAX_ABNORMAL_STOP_RECOVERIES = 2;
|
|
8441
8506
|
const statusWatcher = isFirstMessage ? { stop() {
|
|
8442
8507
|
}, pause() {
|
|
8443
8508
|
}, resume() {
|
|
@@ -8781,6 +8846,18 @@ async function runTurn(params) {
|
|
|
8781
8846
|
});
|
|
8782
8847
|
}
|
|
8783
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
|
+
}
|
|
8784
8861
|
if (stopReason !== "tool_use" || toolCalls.length === 0) {
|
|
8785
8862
|
statusWatcher.stop();
|
|
8786
8863
|
saveSession(state);
|
|
@@ -8947,7 +9024,7 @@ async function runTurn(params) {
|
|
|
8947
9024
|
block.completedAt = Date.now();
|
|
8948
9025
|
const msgs = subAgentMessages.get(r.id);
|
|
8949
9026
|
if (msgs) {
|
|
8950
|
-
block.subAgentMessages = msgs;
|
|
9027
|
+
block.subAgentMessages = capSubAgentTranscript(msgs);
|
|
8951
9028
|
}
|
|
8952
9029
|
}
|
|
8953
9030
|
}
|
|
@@ -9006,7 +9083,7 @@ var init_agent = __esm({
|
|
|
9006
9083
|
init_trigger2();
|
|
9007
9084
|
init_surfaces();
|
|
9008
9085
|
init_toolRegistry();
|
|
9009
|
-
|
|
9086
|
+
init_historyLimits();
|
|
9010
9087
|
log13 = createLogger("agent");
|
|
9011
9088
|
BRAND_TRIGGERING_TOOLS = /* @__PURE__ */ new Set([
|
|
9012
9089
|
"writeSpec",
|