teapot-coding-agent 0.37.203 → 0.37.205
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/agent/agent.js
CHANGED
|
@@ -1064,7 +1064,30 @@ export class Agent {
|
|
|
1064
1064
|
async compactNow() {
|
|
1065
1065
|
if (this.compactInFlight || this.compactRequested)
|
|
1066
1066
|
return { ran: false, queued: true };
|
|
1067
|
-
|
|
1067
|
+
/**
|
|
1068
|
+
* A compaction already running is not a turn in flight — nothing to defer to.
|
|
1069
|
+
*/
|
|
1070
|
+
if (this.compactPhase !== "")
|
|
1071
|
+
return { ran: false, queued: true };
|
|
1072
|
+
/**
|
|
1073
|
+
* PARKED on a tool (`wait_children`, a background bash) — run it NOW.
|
|
1074
|
+
*
|
|
1075
|
+
* The flag-and-wait path below is for a turn that is GENERATING: the compaction has to wait for a boundary because
|
|
1076
|
+
* rewriting `this.messages` mid-request would corrupt the call in flight. A parked tool is the opposite situation — the
|
|
1077
|
+
* run loop is suspended inside `executeTool`, no request is open, and the next boundary may be minutes away (a
|
|
1078
|
+
* `wait_children` timeout is 5 minutes by default, an hour at most). Reported as "wait_children 中に /compact をしても
|
|
1079
|
+
* 発火しない". Nothing else may be compacting here (checked above), and the tool's own result is appended to the tail
|
|
1080
|
+
* afterwards, so `safeCut`'s "never cut before a tool result" rule still holds.
|
|
1081
|
+
*
|
|
1082
|
+
* `parkedByTool` is the signal, NOT `status === "waiting"`: that status also covers a compaction in progress and the
|
|
1083
|
+
* display translation of an idle-but-live agent, and neither of those is a suspended run.
|
|
1084
|
+
*/
|
|
1085
|
+
if (this.parkedByTool) {
|
|
1086
|
+
const before = this.stats.compactions;
|
|
1087
|
+
await this.maybeCompact(true);
|
|
1088
|
+
return { ran: this.stats.compactions > before, queued: false };
|
|
1089
|
+
}
|
|
1090
|
+
if (this.status === "running") {
|
|
1068
1091
|
this.compactRequested = true;
|
|
1069
1092
|
await this.log.append("prompt", this.currentSession, this.currentBranch, {
|
|
1070
1093
|
source: "harness",
|
|
@@ -3256,8 +3279,32 @@ export class Agent {
|
|
|
3256
3279
|
}
|
|
3257
3280
|
return Math.ceil(ascii / 4 + wide * 1.2 + msgs.length * 8);
|
|
3258
3281
|
}
|
|
3282
|
+
/**
|
|
3283
|
+
* Never cut a call away from its result.
|
|
3284
|
+
*
|
|
3285
|
+
* A compaction keeps `messages[cut..]`, so a call whose RESULT has not arrived yet must not be summarised away: the tool
|
|
3286
|
+
* result is appended afterwards by the running loop, and an orphan `role:"tool"` message makes the next request invalid
|
|
3287
|
+
* ("tool message not directly after its assistant turn"). That used to be impossible — a compaction only ran at a turn
|
|
3288
|
+
* boundary — but `/compact` now runs WHILE the agent is parked on a tool (`wait_children`), so the pending call is exactly
|
|
3289
|
+
* the last assistant message at that moment.
|
|
3290
|
+
*/
|
|
3259
3291
|
safeCut(maxCut) {
|
|
3260
|
-
|
|
3292
|
+
const answered = new Set();
|
|
3293
|
+
for (const m of this.messages)
|
|
3294
|
+
if (m.role === "tool" && m.tool_call_id)
|
|
3295
|
+
answered.add(m.tool_call_id);
|
|
3296
|
+
let pendingAt = Number.POSITIVE_INFINITY;
|
|
3297
|
+
for (let i = 0; i < this.messages.length; i++) {
|
|
3298
|
+
const calls = this.messages[i].tool_calls;
|
|
3299
|
+
if (!calls?.length)
|
|
3300
|
+
continue;
|
|
3301
|
+
if (calls.some((c) => c.id && !answered.has(c.id))) {
|
|
3302
|
+
pendingAt = i;
|
|
3303
|
+
break;
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
const limit = Math.min(maxCut, this.messages.length - 1, pendingAt);
|
|
3307
|
+
for (let i = limit; i >= 1; i--) {
|
|
3261
3308
|
if (this.messages[i].role !== "tool")
|
|
3262
3309
|
return i;
|
|
3263
3310
|
}
|