maestro-agent-sdk 0.1.27 → 0.1.29
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/core/agent.d.ts +28 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +2 -0
- package/dist/core/agent.js.map +1 -1
- package/dist/core/is-abort-error.d.ts +18 -0
- package/dist/core/is-abort-error.d.ts.map +1 -1
- package/dist/core/is-abort-error.js +34 -0
- package/dist/core/is-abort-error.js.map +1 -1
- package/dist/core/loop.d.ts.map +1 -1
- package/dist/core/loop.js +69 -14
- package/dist/core/loop.js.map +1 -1
- package/dist/core/tool-result-truncation.d.ts +34 -0
- package/dist/core/tool-result-truncation.d.ts.map +1 -0
- package/dist/core/tool-result-truncation.js +162 -0
- package/dist/core/tool-result-truncation.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/memory/active-task-template.d.ts +7 -4
- package/dist/memory/active-task-template.d.ts.map +1 -1
- package/dist/memory/active-task-template.js +19 -4
- package/dist/memory/active-task-template.js.map +1 -1
- package/dist/memory/aux-model-map.d.ts +49 -0
- package/dist/memory/aux-model-map.d.ts.map +1 -0
- package/dist/memory/aux-model-map.js +103 -0
- package/dist/memory/aux-model-map.js.map +1 -0
- package/dist/memory/compressor.d.ts +34 -59
- package/dist/memory/compressor.d.ts.map +1 -1
- package/dist/memory/compressor.js +289 -92
- package/dist/memory/compressor.js.map +1 -1
- package/dist/provider.d.ts +2 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +32 -4
- package/dist/provider.js.map +1 -1
- package/dist/providers/codex-auth.d.ts.map +1 -1
- package/dist/providers/codex-auth.js +20 -0
- package/dist/providers/codex-auth.js.map +1 -1
- package/dist/providers/codex.d.ts +29 -1
- package/dist/providers/codex.d.ts.map +1 -1
- package/dist/providers/codex.js +94 -11
- package/dist/providers/codex.js.map +1 -1
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +14 -4
- package/dist/session-store.js.map +1 -1
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,12 +3,28 @@ import { pruneMessages } from "../memory/prune.js";
|
|
|
3
3
|
import { estimateTokens } from "../memory/token-estimate.js";
|
|
4
4
|
import { logger } from "../platform/logger.js";
|
|
5
5
|
const compactorAntiThrash = new WeakMap();
|
|
6
|
-
/** A compaction that doesn't save at least this fraction of tokens is
|
|
7
|
-
* considered ineffective and counts toward backoff. */
|
|
8
6
|
const COMPACTOR_MIN_SAVINGS_RATIO = 0.1;
|
|
9
|
-
/** Two consecutive ineffective calls on the same array → bail out and just
|
|
10
|
-
* prune. */
|
|
11
7
|
const COMPACTOR_ANTI_THRASH_LIMIT = 2;
|
|
8
|
+
/** Sentinel user message that marks a compaction block pair.
|
|
9
|
+
* Uses NUL-bytes to make accidental user-content collision extremely unlikely. */
|
|
10
|
+
const COMPACTION_MARKER = "\x00maestro-compaction\x00";
|
|
11
|
+
/** Incremental summary update prompt. Restates the schema contract
|
|
12
|
+
* (same sections as ACTIVE_TASK_TEMPLATE) so aux output never drifts. */
|
|
13
|
+
function incrementalPrompt(previousSummary) {
|
|
14
|
+
return [
|
|
15
|
+
ACTIVE_TASK_TEMPLATE,
|
|
16
|
+
"",
|
|
17
|
+
"---",
|
|
18
|
+
"The conversation above has been partially summarized before.",
|
|
19
|
+
"Update the previous summary below by preserving still-true details,",
|
|
20
|
+
"removing stale details, and merging in new facts from the recent",
|
|
21
|
+
"conversation history above.",
|
|
22
|
+
"",
|
|
23
|
+
"<previous-summary>",
|
|
24
|
+
previousSummary,
|
|
25
|
+
"</previous-summary>",
|
|
26
|
+
].join("\n");
|
|
27
|
+
}
|
|
12
28
|
function defaultContextWindow() {
|
|
13
29
|
const env = process.env.MAESTRO_CONTEXT_WINDOW;
|
|
14
30
|
if (env) {
|
|
@@ -18,109 +34,164 @@ function defaultContextWindow() {
|
|
|
18
34
|
}
|
|
19
35
|
return 200_000;
|
|
20
36
|
}
|
|
37
|
+
function extractText(blocks) {
|
|
38
|
+
if (typeof blocks === "string")
|
|
39
|
+
return blocks;
|
|
40
|
+
if (Array.isArray(blocks)) {
|
|
41
|
+
return blocks
|
|
42
|
+
.filter((b) => b.type === "text")
|
|
43
|
+
.map((b) => b.text ?? "")
|
|
44
|
+
.join("\n");
|
|
45
|
+
}
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns true when a ProviderMessage's blocks contain at least one
|
|
50
|
+
* tool_result. Used by snap-helper to avoid cutting the wire at a
|
|
51
|
+
* tool_result user message that would orphan the preceding tool_use.
|
|
52
|
+
*/
|
|
53
|
+
function hasToolResultBlocks(msg) {
|
|
54
|
+
const content = msg.content;
|
|
55
|
+
if (typeof content === "string")
|
|
56
|
+
return false;
|
|
57
|
+
if (!Array.isArray(content))
|
|
58
|
+
return false;
|
|
59
|
+
return content.some((b) => b.type === "tool_result");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find the most recent compaction block pair in messages.
|
|
63
|
+
* Returns indices and the summary text, or undefined.
|
|
64
|
+
*/
|
|
65
|
+
function findLastCompaction(messages) {
|
|
66
|
+
for (let i = messages.length - 1; i >= 1; i--) {
|
|
67
|
+
const assistant = messages[i];
|
|
68
|
+
const user = messages[i - 1];
|
|
69
|
+
if (user.role === "user" &&
|
|
70
|
+
typeof user.content === "string" &&
|
|
71
|
+
user.content === COMPACTION_MARKER &&
|
|
72
|
+
assistant.role === "assistant" &&
|
|
73
|
+
typeof assistant.content === "string" &&
|
|
74
|
+
assistant.content.length > 0) {
|
|
75
|
+
return { userIdx: i - 1, assistantIdx: i, summary: assistant.content };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Collect indices of all compaction block pairs in messages.
|
|
82
|
+
*/
|
|
83
|
+
function compactionBlockIndices(messages) {
|
|
84
|
+
const indices = new Set();
|
|
85
|
+
for (let i = 0; i < messages.length - 1; i++) {
|
|
86
|
+
const user = messages[i];
|
|
87
|
+
const next = messages[i + 1];
|
|
88
|
+
if (user.role === "user" &&
|
|
89
|
+
typeof user.content === "string" &&
|
|
90
|
+
user.content === COMPACTION_MARKER &&
|
|
91
|
+
next.role === "assistant") {
|
|
92
|
+
indices.add(i);
|
|
93
|
+
indices.add(i + 1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return indices;
|
|
97
|
+
}
|
|
98
|
+
// ─── public API ───────────────────────────────────────────────────────────
|
|
21
99
|
/**
|
|
22
100
|
* Run the auto-compaction pipeline.
|
|
23
101
|
*
|
|
24
102
|
* Steps:
|
|
25
|
-
* 1.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
103
|
+
* 1. Prune (cheap: dedup, age-summary, truncate tool output).
|
|
104
|
+
* 2. Re-estimate tokens. If below threshold, return pruned.
|
|
105
|
+
* 3. Snap head/tail boundaries. If no middle, return pruned.
|
|
106
|
+
* 4. Find previous compaction blocks → extract last summary for
|
|
107
|
+
* incremental aux-LLM prompt.
|
|
108
|
+
* 5. Call aux LLM to summarize the middle. When a previous summary
|
|
109
|
+
* exists, only the *delta* after the last compaction
|
|
110
|
+
* (messages[assistantIdx+1 .. tailStart]) is sent to the aux LLM.
|
|
111
|
+
* 6. After the degenerate-savings guard, persist compaction user +
|
|
112
|
+
* summary assistant pair in the canonical `messages` array.
|
|
113
|
+
* 7. Return wire array: [head, wrapped-summary, tail].
|
|
33
114
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
115
|
+
* All wire head/tail boundaries are built from a compaction-stripped
|
|
116
|
+
* view of messages so the wire never leaks internal sentinels.
|
|
36
117
|
*/
|
|
37
118
|
export async function compressIfNeeded(messages, opts = {}) {
|
|
38
119
|
const contextWindow = opts.contextWindow ?? defaultContextWindow();
|
|
39
|
-
const triggerRatio = opts.triggerRatio ?? 0.
|
|
120
|
+
const triggerRatio = opts.triggerRatio ?? 0.6;
|
|
40
121
|
const headProtect = opts.headProtect ?? 2;
|
|
41
122
|
const tailProtect = opts.tailProtect ?? 6;
|
|
42
123
|
const auxModel = opts.auxModel;
|
|
43
|
-
//
|
|
44
|
-
// need at least `headProtect + 1 + tailProtect` messages to even slice a
|
|
45
|
-
// middle), AND at this size dedup/age-summary saves nothing (age threshold
|
|
46
|
-
// is 10 user-turns). Skipping the whole prune pipeline saves ~6 O(n) walks
|
|
47
|
-
// per turn during the first several iterations of every session — the
|
|
48
|
-
// exact window where the loop spends most of its short-conversation life.
|
|
49
|
-
// Trade-off: we forgo the cheap "string-content gets deduped immediately"
|
|
50
|
-
// win on duplicate tool results in the first few turns, but the model
|
|
51
|
-
// rarely re-issues an identical tool call inside a 9-message window.
|
|
124
|
+
// Fast-path: short conversations can't trigger compaction.
|
|
52
125
|
const minSize = headProtect + 1 + tailProtect;
|
|
53
126
|
if (messages.length < minSize) {
|
|
54
127
|
return messages;
|
|
55
128
|
}
|
|
56
|
-
//
|
|
57
|
-
// we're well under the trigger (≤ 50% of threshold) the conversation has
|
|
58
|
-
// nowhere near enough payload to need compaction, and prune's three passes
|
|
59
|
-
// wouldn't do anything an anti-thrash latch wouldn't catch on iteration 2.
|
|
60
|
-
// We skip prune entirely and return the input — same as the anti-thrash
|
|
61
|
-
// short-circuit, just gated on actual size rather than past behavior.
|
|
62
|
-
//
|
|
63
|
-
// 0.5 ratio picked empirically: at 200K window × 0.8 trigger × 0.5 gate =
|
|
64
|
-
// 80K tokens, which lands between "still actively gathering context" and
|
|
65
|
-
// "approaching compaction zone". Above the gate we run the full pipeline
|
|
66
|
-
// so an anti-thrash latch from earlier doesn't strand the loop without
|
|
67
|
-
// any pruning when the conversation actually grows large.
|
|
129
|
+
// Cheap pre-gate: skip prune when well under threshold.
|
|
68
130
|
const threshold = contextWindow * triggerRatio;
|
|
69
131
|
const rawTokens = estimateTokens(messages);
|
|
70
132
|
if (rawTokens < threshold * 0.5) {
|
|
71
133
|
return messages;
|
|
72
134
|
}
|
|
73
|
-
// Step 1: prune
|
|
135
|
+
// Step 1: prune.
|
|
74
136
|
const pruned = pruneMessages(messages);
|
|
75
137
|
const prunedTokens = estimateTokens(pruned);
|
|
76
138
|
if (prunedTokens < threshold) {
|
|
77
139
|
return pruned;
|
|
78
140
|
}
|
|
79
|
-
// Anti-thrash check
|
|
141
|
+
// Anti-thrash check.
|
|
80
142
|
const state = compactorAntiThrash.get(messages);
|
|
81
143
|
if (state && state.failedCompactions >= COMPACTOR_ANTI_THRASH_LIMIT) {
|
|
82
144
|
return pruned;
|
|
83
145
|
}
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
if (tailStart <= headEnd) {
|
|
97
|
-
// Snapping collapsed the middle — nothing left to compress.
|
|
146
|
+
// Step 4: find previous compaction for incremental prompt.
|
|
147
|
+
const prevCompaction = findLastCompaction(messages);
|
|
148
|
+
const previousSummary = prevCompaction?.summary;
|
|
149
|
+
// Build a compaction-free view of canonical messages for all wire
|
|
150
|
+
// boundary calculations (FIX #1: head/tail must never contain
|
|
151
|
+
// sentinel markers).
|
|
152
|
+
const skipIndices = compactionBlockIndices(messages);
|
|
153
|
+
const cleanMessages = messages.filter((_, i) => !skipIndices.has(i));
|
|
154
|
+
// Snap wire boundaries on the clean view.
|
|
155
|
+
const cleanHeadEnd = snapHeadEnd(cleanMessages, Math.min(headProtect, cleanMessages.length));
|
|
156
|
+
const cleanTailStart = snapTailStart(cleanMessages, Math.max(cleanMessages.length - tailProtect, 0));
|
|
157
|
+
if (cleanTailStart <= cleanHeadEnd) {
|
|
98
158
|
return pruned;
|
|
99
159
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
160
|
+
// Build middle for aux LLM.
|
|
161
|
+
// FIX #2: when a previous summary exists, limit the aux input to
|
|
162
|
+
// the *delta* after the last compaction (messages *including* the
|
|
163
|
+
// sentinel pair are canonical; the delta starts right after the
|
|
164
|
+
// summary assistant). Otherwise use the full clean middle.
|
|
165
|
+
let auxMiddle;
|
|
166
|
+
if (prevCompaction) {
|
|
167
|
+
// Delta: everything after the summary assistant up to (but not including) the tail.
|
|
168
|
+
const deltaStart = prevCompaction.assistantIdx + 1;
|
|
169
|
+
const deltaEnd = messages.length - tailProtect;
|
|
170
|
+
auxMiddle = messages.slice(deltaStart, Math.max(deltaStart, deltaEnd));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
auxMiddle = cleanMessages.slice(cleanHeadEnd, cleanTailStart);
|
|
174
|
+
}
|
|
175
|
+
// Step 5: aux LLM call.
|
|
104
176
|
if (!opts.auxProvider) {
|
|
105
|
-
|
|
106
|
-
// (the agent loop passes its own provider). Without one we can't
|
|
107
|
-
// summarize — drop to pruned and log so the operator sees why.
|
|
108
|
-
logger.warn({ prunedTokens, threshold }, "compressIfNeeded: over threshold but no auxProvider supplied — falling back to prune-only");
|
|
177
|
+
logger.warn({ prunedTokens, threshold }, "compressIfNeeded: no auxProvider — prune-only");
|
|
109
178
|
return pruned;
|
|
110
179
|
}
|
|
111
180
|
if (!auxModel) {
|
|
112
|
-
|
|
113
|
-
// by default, so this branch only fires if a host calls compressIfNeeded
|
|
114
|
-
// directly without one. Same fallback as missing provider.
|
|
115
|
-
logger.warn({ prunedTokens, threshold }, "compressIfNeeded: over threshold but no auxModel supplied — falling back to prune-only");
|
|
181
|
+
logger.warn({ prunedTokens, threshold }, "compressIfNeeded: no auxModel — prune-only");
|
|
116
182
|
return pruned;
|
|
117
183
|
}
|
|
184
|
+
// FIX #4: incremental prompt now includes the full ACTIVE_TASK_TEMPLATE
|
|
185
|
+
// so the schema contract is restated every time.
|
|
186
|
+
const systemPrompt = previousSummary
|
|
187
|
+
? incrementalPrompt(previousSummary)
|
|
188
|
+
: ACTIVE_TASK_TEMPLATE;
|
|
118
189
|
let summaryText;
|
|
119
190
|
try {
|
|
120
191
|
const auxResponse = await opts.auxProvider.complete({
|
|
121
192
|
model: auxModel,
|
|
122
|
-
messages:
|
|
123
|
-
system:
|
|
193
|
+
messages: auxMiddle,
|
|
194
|
+
system: systemPrompt,
|
|
124
195
|
maxTokens: 2048,
|
|
125
196
|
...(opts.abortSignal ? { abortSignal: opts.abortSignal } : {}),
|
|
126
197
|
});
|
|
@@ -130,67 +201,193 @@ export async function compressIfNeeded(messages, opts = {}) {
|
|
|
130
201
|
}
|
|
131
202
|
}
|
|
132
203
|
catch (err) {
|
|
133
|
-
logger.warn({ err, prunedTokens, threshold }, "compressIfNeeded: aux LLM
|
|
204
|
+
logger.warn({ err, prunedTokens, threshold }, "compressIfNeeded: aux LLM failed");
|
|
134
205
|
if (opts.disablePruneFallback)
|
|
135
206
|
return messages;
|
|
136
|
-
|
|
207
|
+
const target = opts.emergencyTargetTokens;
|
|
208
|
+
const effectiveTarget = target !== undefined && Number.isFinite(target) && target > 0 ? target : 50_000;
|
|
209
|
+
if (target === 0)
|
|
210
|
+
return pruned;
|
|
211
|
+
const notice = "[메모리 압축 실패로 이전 대화 일부가 잘렸습니다. 최근 대화만 모델에 전달됨.]";
|
|
212
|
+
if (opts.onEmergencyTrim) {
|
|
213
|
+
try {
|
|
214
|
+
opts.onEmergencyTrim(notice);
|
|
215
|
+
}
|
|
216
|
+
catch (cbErr) {
|
|
217
|
+
logger.warn({ err: cbErr }, "onEmergencyTrim threw — swallowed");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return emergencyTail(pruned, effectiveTarget, notice);
|
|
137
221
|
}
|
|
222
|
+
// Build wire from clean messages (FIX #1).
|
|
223
|
+
const head = cleanMessages.slice(0, cleanHeadEnd);
|
|
224
|
+
const tail = cleanMessages.slice(cleanTailStart);
|
|
225
|
+
// H2 defense (2026-05-24): if head ends with a user message and the
|
|
226
|
+
// summary user is prepended directly after it, we create a user-user
|
|
227
|
+
// consecutive pattern that some providers reject. Insert a dummy
|
|
228
|
+
// assistant to restore the alternating-role invariant.
|
|
229
|
+
const headEndsUser = head.length > 0 && head[head.length - 1].role === "user";
|
|
138
230
|
const compacted = [
|
|
139
231
|
...head,
|
|
232
|
+
...(headEndsUser
|
|
233
|
+
? [{ role: "assistant", content: [{ type: "text", text: "" }] }]
|
|
234
|
+
: []),
|
|
140
235
|
{ role: "user", content: wrapCompactedSummary(summaryText) },
|
|
141
236
|
...tail,
|
|
142
237
|
];
|
|
143
238
|
const compactedTokens = estimateTokens(compacted);
|
|
144
|
-
// Degenerate
|
|
145
|
-
// Discard and fall back to prune-only.
|
|
239
|
+
// Degenerate check — MUST run before persisting compaction blocks (FIX #3).
|
|
146
240
|
const savings = prunedTokens - compactedTokens;
|
|
147
241
|
const ratio = savings / prunedTokens;
|
|
148
242
|
if (ratio < COMPACTOR_MIN_SAVINGS_RATIO) {
|
|
149
243
|
const next = state ?? { failedCompactions: 0 };
|
|
150
244
|
next.failedCompactions++;
|
|
151
245
|
compactorAntiThrash.set(messages, next);
|
|
152
|
-
logger.info({
|
|
246
|
+
logger.info({
|
|
247
|
+
prunedTokens,
|
|
248
|
+
compactedTokens,
|
|
249
|
+
ratio,
|
|
250
|
+
failedCompactions: next.failedCompactions,
|
|
251
|
+
}, "compressIfNeeded: low savings — anti-thrash incremented");
|
|
153
252
|
return pruned;
|
|
154
253
|
}
|
|
155
|
-
//
|
|
254
|
+
// Step 6: persist compaction blocks AFTER savings gate (FIX #3).
|
|
255
|
+
if (prevCompaction) {
|
|
256
|
+
messages[prevCompaction.userIdx] = { role: "user", content: COMPACTION_MARKER };
|
|
257
|
+
messages[prevCompaction.assistantIdx] = { role: "assistant", content: summaryText };
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
messages.push({ role: "user", content: COMPACTION_MARKER });
|
|
261
|
+
messages.push({ role: "assistant", content: summaryText });
|
|
262
|
+
}
|
|
156
263
|
if (state)
|
|
157
264
|
compactorAntiThrash.delete(messages);
|
|
158
|
-
logger.info({
|
|
265
|
+
logger.info({
|
|
266
|
+
prunedTokens,
|
|
267
|
+
compactedTokens,
|
|
268
|
+
ratio,
|
|
269
|
+
incremental: !!previousSummary,
|
|
270
|
+
auxMiddleSize: auxMiddle.length,
|
|
271
|
+
}, "compressIfNeeded: applied compaction");
|
|
159
272
|
return compacted;
|
|
160
273
|
}
|
|
274
|
+
// ─── helpers ──────────────────────────────────────────────────────────────
|
|
161
275
|
/**
|
|
162
|
-
* Walk forward from `idealEnd` to land on
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
276
|
+
* Walk forward from `idealEnd` to land on a user message boundary.
|
|
277
|
+
* Skips user messages that are tool_result carriers (to avoid
|
|
278
|
+
* orphaning a preceding tool_use).
|
|
279
|
+
*
|
|
280
|
+
* H1 fix (2026-05-24): the old cap of `idealEnd + 4` could leave an
|
|
281
|
+
* orphan tool_use when the first user prompt triggered 3+ tool_use /
|
|
282
|
+
* tool_result pairs — the final tool_result sat at index > cap and
|
|
283
|
+
* the head ended with an unpaired assistant tool_use, causing both
|
|
284
|
+
* Codex and Anthropic to reject the request (400). The fix tracks
|
|
285
|
+
* open tool_use IDs and only stops at a plain user when every
|
|
286
|
+
* tool_use in the head region has a matching tool_result.
|
|
166
287
|
*/
|
|
167
288
|
function snapHeadEnd(messages, idealEnd) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
289
|
+
// Pre-populate open tool_uses from the prefix we're keeping (0..idealEnd-1).
|
|
290
|
+
const open = new Set();
|
|
291
|
+
const limit = Math.min(idealEnd, messages.length);
|
|
292
|
+
for (let j = 0; j < limit; j++) {
|
|
293
|
+
const msg = messages[j];
|
|
294
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
295
|
+
for (const b of msg.content) {
|
|
296
|
+
if (b.type === "tool_use" && b.id) {
|
|
297
|
+
open.add(b.id);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
302
|
+
for (const b of msg.content) {
|
|
303
|
+
if (b.type === "tool_result" &&
|
|
304
|
+
b.tool_use_id) {
|
|
305
|
+
open.delete(b.tool_use_id);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const safetyCap = Math.min(messages.length, idealEnd + 20);
|
|
311
|
+
let i = limit;
|
|
312
|
+
while (i < safetyCap && messages[i]) {
|
|
313
|
+
const msg = messages[i];
|
|
314
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
315
|
+
for (const b of msg.content) {
|
|
316
|
+
if (b.type === "tool_use" && b.id) {
|
|
317
|
+
open.add(b.id);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
322
|
+
for (const b of msg.content) {
|
|
323
|
+
if (b.type === "tool_result" &&
|
|
324
|
+
b.tool_use_id) {
|
|
325
|
+
open.delete(b.tool_use_id);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const isPlainUser = msg.role === "user" && !hasToolResultBlocks(msg);
|
|
330
|
+
if (isPlainUser && open.size === 0) {
|
|
331
|
+
return i;
|
|
332
|
+
}
|
|
171
333
|
i++;
|
|
172
|
-
|
|
334
|
+
}
|
|
335
|
+
// Safety fallback: find the last plain user anywhere in the array.
|
|
336
|
+
// Better to overshoot the budget than ship an orphan tool_use.
|
|
337
|
+
for (i = messages.length - 1; i >= 0; i--) {
|
|
338
|
+
const msg = messages[i];
|
|
339
|
+
if (msg.role === "user" && !hasToolResultBlocks(msg))
|
|
340
|
+
return i;
|
|
341
|
+
}
|
|
342
|
+
return idealEnd;
|
|
173
343
|
}
|
|
174
344
|
/**
|
|
175
|
-
* Walk backward from `idealStart` until we land on a user
|
|
176
|
-
*
|
|
177
|
-
* `idealStart - 4` so the tail never grows unboundedly.
|
|
345
|
+
* Walk backward from `idealStart` until we land on a user message boundary.
|
|
346
|
+
* Skips user messages that are tool_result carriers (FIX #6).
|
|
178
347
|
*/
|
|
179
348
|
function snapTailStart(messages, idealStart) {
|
|
180
349
|
const floor = Math.max(0, idealStart - 4);
|
|
181
350
|
let i = Math.max(idealStart, 0);
|
|
182
|
-
while (i > floor &&
|
|
351
|
+
while (i > floor &&
|
|
352
|
+
messages[i] &&
|
|
353
|
+
(messages[i].role !== "user" || hasToolResultBlocks(messages[i]))) {
|
|
183
354
|
i--;
|
|
355
|
+
}
|
|
184
356
|
return i;
|
|
185
357
|
}
|
|
186
|
-
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Emergency tail-only trim — FIX #5: does NOT over-trim when the whole
|
|
360
|
+
* history fits inside targetTokens.
|
|
361
|
+
*/
|
|
362
|
+
function emergencyTail(messages, targetTokens, notice) {
|
|
363
|
+
if (messages.length === 0)
|
|
364
|
+
return messages;
|
|
365
|
+
let acc = 0;
|
|
366
|
+
let cut = messages.length; // marker: threshold never reached
|
|
367
|
+
let reachedThreshold = false;
|
|
368
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
369
|
+
acc += estimateTokens([messages[i]]);
|
|
370
|
+
if (acc >= targetTokens) {
|
|
371
|
+
cut = i;
|
|
372
|
+
reachedThreshold = true;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// FIX #5: if history fits entirely within target, return full history.
|
|
377
|
+
if (!reachedThreshold) {
|
|
378
|
+
return [{ role: "user", content: `<emergency-truncation>\n${notice}\n</emergency-truncation>` }, ...messages];
|
|
379
|
+
}
|
|
380
|
+
// Snap cut to a safe user message boundary.
|
|
381
|
+
while (cut < messages.length && messages[cut]?.role !== "user")
|
|
382
|
+
cut++;
|
|
383
|
+
if (cut >= messages.length)
|
|
384
|
+
cut = messages.length - 1;
|
|
385
|
+
while (cut > 0 && messages[cut]?.role !== "user")
|
|
386
|
+
cut--;
|
|
387
|
+
const tail = messages.slice(cut);
|
|
388
|
+
return [{ role: "user", content: `<emergency-truncation>\n${notice}\n</emergency-truncation>` }, ...tail];
|
|
192
389
|
}
|
|
193
|
-
|
|
390
|
+
/** Test-only: reset the compactor anti-thrash WeakMap entry for an array. */
|
|
194
391
|
export function __resetCompactorState(messages) {
|
|
195
392
|
compactorAntiThrash.delete(messages);
|
|
196
393
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compressor.js","sourceRoot":"","sources":["../../src/memory/compressor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAiF3C,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAsC,CAAC;AAE9E;wDACwD;AACxD,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC;aACa;AACb,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC,SAAS,oBAAoB;IAC3B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;IAC/C,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACnC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5C,CAA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@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAbortError } from "./core/is-abort-error.js";
|
|
1
|
+
import { isAbortError, isTimeoutError } from "./core/is-abort-error.js";
|
|
2
2
|
import type { Provider } from "./providers/base.js";
|
|
3
3
|
import type { AgentQueryOptions, UnifiedEvent } from "./types.js";
|
|
4
4
|
/**
|
|
@@ -239,5 +239,5 @@ export declare function pickHigherBudget(a: number | undefined, b: number | unde
|
|
|
239
239
|
* Exported for unit coverage — used internally by `maestroProvider`'s catch
|
|
240
240
|
* branch to distinguish a user-initiated abort from a real provider crash.
|
|
241
241
|
*/
|
|
242
|
-
export { isAbortError };
|
|
242
|
+
export { isAbortError, isTimeoutError };
|
|
243
243
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAsBrE,OAAO,KAAK,EAAE,QAAQ,EAAyC,MAAM,kBAAkB,CAAC;AA0CxF,OAAO,KAAK,EAAE,iBAAiB,EAAc,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,sBAAsB,QAA2B,CAAC;AAE/D,wBAAuB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,CAAC,YAAY,CAAC,CAylB5F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAa1E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI/E;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,EAAG,SAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEjF;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAC5D,MAAM,EAAE,CAAC,EAAE,EACX,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,CAAC,EAAE,CAGL;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,QAAQ,CAQhE;AAwBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAIjG;AAED;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/provider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { AIAgent } from "./core/agent.js";
|
|
4
|
-
import { isAbortError } from "./core/is-abort-error.js";
|
|
4
|
+
import { isAbortError, isTimeoutError } from "./core/is-abort-error.js";
|
|
5
5
|
import { runConversation } from "./core/loop.js";
|
|
6
6
|
import { registerMcpTools, startMcpPool } from "./mcp/pool.js";
|
|
7
7
|
import { buildSystemReminder } from "./memory/reminder.js";
|
|
@@ -25,6 +25,7 @@ import { buildSkillsIndex } from "./skills/index-builder.js";
|
|
|
25
25
|
import { loadSkillsCached } from "./skills/loader.js";
|
|
26
26
|
import { getTaskStore } from "./state/tasks.js";
|
|
27
27
|
import { createAgentTool } from "./tools/builtin/agent.js";
|
|
28
|
+
import { askUserQuestionTool } from "./tools/builtin/ask_user_question.js";
|
|
28
29
|
import { bashTool, createBashTool } from "./tools/builtin/bash.js";
|
|
29
30
|
import { createBackgroundBashRegistry, createBashOutputTool, createKillBashTool, } from "./tools/builtin/bash_background.js";
|
|
30
31
|
import { createEditTool } from "./tools/builtin/edit.js";
|
|
@@ -33,10 +34,9 @@ import { grepTool } from "./tools/builtin/grep.js";
|
|
|
33
34
|
import { createReadTool } from "./tools/builtin/read.js";
|
|
34
35
|
import { createSkillViewTool } from "./tools/builtin/skill_view.js";
|
|
35
36
|
import { createSkillWriteTool } from "./tools/builtin/skill_write.js";
|
|
36
|
-
import {
|
|
37
|
+
import { createTaskCreateTool, createTaskGetTool, createTaskListTool, createTaskOutputTool, createTaskStopTool, createTaskUpdateTool, } from "./tools/builtin/tasks.js";
|
|
37
38
|
import { createToolSearchTool } from "./tools/builtin/tool_search.js";
|
|
38
39
|
import { webFetchTool } from "./tools/builtin/web_fetch.js";
|
|
39
|
-
import { askUserQuestionTool } from "./tools/builtin/ask_user_question.js";
|
|
40
40
|
import { createWriteTool } from "./tools/builtin/write.js";
|
|
41
41
|
import { getFileStateTracker } from "./tools/file-state.js";
|
|
42
42
|
import { ToolRegistry } from "./tools/registry.js";
|
|
@@ -502,6 +502,12 @@ export async function* maestroProvider(opts) {
|
|
|
502
502
|
...(thinkingBudget ? { thinkingBudget } : {}),
|
|
503
503
|
...(resolvedEffort ? { effort: resolvedEffort } : {}),
|
|
504
504
|
...(opts.abortController?.signal ? { abortSignal: opts.abortController.signal } : {}),
|
|
505
|
+
// v0.1.28+: forward the caller's aux-model override into AIAgent so the
|
|
506
|
+
// loop's compressIfNeeded call honors it. When omitted the loop falls
|
|
507
|
+
// back to `resolveAuxModel(resolvedModel)`, which routes heavy tiers
|
|
508
|
+
// (gpt-5.5, opus, deepseek-v4-pro) to their cheapest sibling.
|
|
509
|
+
...(opts.auxModel ? { auxModel: opts.auxModel } : {}),
|
|
510
|
+
...(opts.toolResultTruncation ? { toolResultTruncation: opts.toolResultTruncation } : {}),
|
|
505
511
|
});
|
|
506
512
|
// Wire abort → close MCP pool early. Without this, an aborted turn could
|
|
507
513
|
// leave Playwright / OCR subprocesses spinning until the finally block,
|
|
@@ -549,6 +555,28 @@ export async function* maestroProvider(opts) {
|
|
|
549
555
|
aborted = true;
|
|
550
556
|
}
|
|
551
557
|
else {
|
|
558
|
+
// v0.1.28: dump the full error shape (name/code/cause/stack) so we can
|
|
559
|
+
// tell the difference between a codex OAuth refresh timeout, the
|
|
560
|
+
// `/responses` HTTP fetch timing out mid-roundtrip, an SSE stream
|
|
561
|
+
// abort during chunk parse, and a plain Anthropic/Deepseek crash —
|
|
562
|
+
// all of which previously surfaced as the same opaque "maestroProvider
|
|
563
|
+
// crashed: <message>" event. The lower-level codex hops also log on
|
|
564
|
+
// throw (see `codex.ts`/`codex-auth.ts` v0.1.28 instrumentation), so
|
|
565
|
+
// the combined log trail tells us which leg actually died.
|
|
566
|
+
const errIsTimeout = isTimeoutError(e);
|
|
567
|
+
logger.error({
|
|
568
|
+
sessionId,
|
|
569
|
+
model: resolvedModel,
|
|
570
|
+
effort: resolvedEffort,
|
|
571
|
+
isTimeoutError: errIsTimeout,
|
|
572
|
+
errName: e instanceof Error ? e.name : typeof e,
|
|
573
|
+
errCode: e?.code,
|
|
574
|
+
errMessage: e instanceof Error ? e.message : String(e),
|
|
575
|
+
errCause: e?.cause,
|
|
576
|
+
stack: e instanceof Error ? e.stack : undefined,
|
|
577
|
+
}, errIsTimeout
|
|
578
|
+
? "maestroProvider: upstream timeout caught in provider.ts catch"
|
|
579
|
+
: "maestroProvider: unhandled error caught in provider.ts catch");
|
|
552
580
|
yield {
|
|
553
581
|
type: "error",
|
|
554
582
|
content: `maestroProvider crashed: ${e instanceof Error ? e.message : String(e)}`,
|
|
@@ -866,5 +894,5 @@ export function pickHigherBudget(a, b) {
|
|
|
866
894
|
* Exported for unit coverage — used internally by `maestroProvider`'s catch
|
|
867
895
|
* branch to distinguish a user-initiated abort from a real provider crash.
|
|
868
896
|
*/
|
|
869
|
-
export { isAbortError };
|
|
897
|
+
export { isAbortError, isTimeoutError };
|
|
870
898
|
//# sourceMappingURL=provider.js.map
|