teapot-coding-agent 0.37.153 → 0.37.154
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 +38 -21
- package/dist/agent/compaction-notice.js +8 -0
- package/package.json +1 -1
- package/public/assets/{index-DJ2Y8Vu2.js → index-Bz6tg1D3.js} +41 -41
- package/public/assets/index-Bz6tg1D3.js.map +1 -0
- package/public/index.html +1 -1
- package/public/assets/index-DJ2Y8Vu2.js.map +0 -1
package/dist/agent/agent.js
CHANGED
|
@@ -9,6 +9,7 @@ import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isCo
|
|
|
9
9
|
import { effortChoosable } from "./llm.js";
|
|
10
10
|
import { turnAnchor } from "./timing.js";
|
|
11
11
|
import { claimsContextLimit, claimsOwnLimit, usageLine } from "./context-claim.js";
|
|
12
|
+
import { compactionNotice } from "./compaction-notice.js";
|
|
12
13
|
import { isDegenerateRepeat } from "./loop-guard.js";
|
|
13
14
|
import { namesBlocker } from "./blocker.js";
|
|
14
15
|
import { mcp } from "./mcp-registry.js";
|
|
@@ -3003,6 +3004,8 @@ export class Agent {
|
|
|
3003
3004
|
const oldChars = old.reduce((n, m) => n + (m.content?.length ?? 0), 0);
|
|
3004
3005
|
const oldShareOfBefore = totalChars > 0 ? Math.round((before * oldChars) / totalChars) : 0;
|
|
3005
3006
|
let summary = "";
|
|
3007
|
+
/** the usage line the notice carries, recorded with the compaction so a restore reproduces the same bytes */
|
|
3008
|
+
let noticeLine = "";
|
|
3006
3009
|
let mode = "summarize";
|
|
3007
3010
|
let summarizedCount = oldCount;
|
|
3008
3011
|
let droppedCount = 0;
|
|
@@ -3136,13 +3139,18 @@ export class Agent {
|
|
|
3136
3139
|
];
|
|
3137
3140
|
}
|
|
3138
3141
|
else {
|
|
3142
|
+
noticeLine = usageLine(this.estimateTokens(this.messages.slice(cut)), this.opts.contextTokenBudget);
|
|
3143
|
+
/**
|
|
3144
|
+
* The usage line is computed ONCE, from the kept tail, and then WRITTEN INTO the compaction event.
|
|
3145
|
+
*
|
|
3146
|
+
* It cannot be recomputed at restore time: the restored notice must be byte-identical to the one the model saw,
|
|
3147
|
+
* or the front of every request changes after a restart and the provider's prefix cache misses for the whole
|
|
3148
|
+
* session. The line is therefore a recorded fact, and `compactionNotice()` is the single builder both paths use.
|
|
3149
|
+
*/
|
|
3139
3150
|
this.messages = [
|
|
3140
3151
|
{
|
|
3141
3152
|
role: "user",
|
|
3142
|
-
content:
|
|
3143
|
-
"AGENTS.md is embedded in your system prompt; memory.md, todo.md and decisions.md are NOT — "
|
|
3144
|
-
+ "call read_memory / get_todo / get_decisions if you need them.\n\n" +
|
|
3145
|
-
`## Summary of earlier conversation\n${summary}`,
|
|
3153
|
+
content: compactionNotice({ summarized: oldCount, summary, contextLine: noticeLine }),
|
|
3146
3154
|
},
|
|
3147
3155
|
...this.messages.slice(cut),
|
|
3148
3156
|
];
|
|
@@ -3157,10 +3165,6 @@ export class Agent {
|
|
|
3157
3165
|
* computed from the messages as they are NOW (`after`), which is the only value that answers "how much do I
|
|
3158
3166
|
* still have?", and it is appended rather than prepended so the checkpoint text stays first.
|
|
3159
3167
|
*/
|
|
3160
|
-
const notice = this.messages[0];
|
|
3161
|
-
if (notice?.role === "user" && /^\[harness\] (Context was compacted|[\d,]+ earlier messages were DROPPED)/.test(String(notice.content))) {
|
|
3162
|
-
notice.content = `${String(notice.content)}\n\n${usageLine(after, this.opts.contextTokenBudget)} — the window is roomy again, not nearly exhausted.`;
|
|
3163
|
-
}
|
|
3164
3168
|
this.stats.compactions++;
|
|
3165
3169
|
if (mode === "summarize")
|
|
3166
3170
|
this.consecutiveCompactFailures = 0;
|
|
@@ -3252,6 +3256,15 @@ export class Agent {
|
|
|
3252
3256
|
dropped: droppedCount,
|
|
3253
3257
|
mode,
|
|
3254
3258
|
...(summary ? { summary: String(summary).slice(0, 20_000) } : {}),
|
|
3259
|
+
/**
|
|
3260
|
+
* The usage line the notice carries, recorded HERE because this is the event `restoreFromLog` replays.
|
|
3261
|
+
*
|
|
3262
|
+
* The notice sits at the front of every request, so the restored text must be byte-identical to the live one or
|
|
3263
|
+
* the prefix cache misses for the whole session. Recomputing the line at restore would be a second owner of a
|
|
3264
|
+
* fact about a moment in time; recording it here makes the notice reproducible, and an older log without it gets
|
|
3265
|
+
* exactly the notice it always had.
|
|
3266
|
+
*/
|
|
3267
|
+
contextLine: noticeLine,
|
|
3255
3268
|
});
|
|
3256
3269
|
if (summary)
|
|
3257
3270
|
this.lastCompactSummary = summary;
|
|
@@ -3262,14 +3275,6 @@ export class Agent {
|
|
|
3262
3275
|
summarized: summarizedCount,
|
|
3263
3276
|
dropped: droppedCount,
|
|
3264
3277
|
mode,
|
|
3265
|
-
/**
|
|
3266
|
-
* The same line the checkpoint message carries, here so it is VERIFIABLE.
|
|
3267
|
-
*
|
|
3268
|
-
* The notice is a message in the agent's list and is never logged, so "did the model get the remaining budget
|
|
3269
|
-
* after the compaction?" could not be answered from a session log at all — which is exactly the question that
|
|
3270
|
-
* came back after a model stopped claiming "残コンテキストが僅少" at 3.5% used.
|
|
3271
|
-
*/
|
|
3272
|
-
contextLine: usageLine(after, this.opts.contextTokenBudget),
|
|
3273
3278
|
});
|
|
3274
3279
|
}
|
|
3275
3280
|
finally {
|
|
@@ -3653,17 +3658,29 @@ async function rebuildMessagesFrom(list, imagesDir) {
|
|
|
3653
3658
|
}
|
|
3654
3659
|
else {
|
|
3655
3660
|
const sum = typeof d.summary === "string" ? d.summary.trim() : "";
|
|
3656
|
-
|
|
3661
|
+
/**
|
|
3662
|
+
* The COUNT in the notice is the recorded one; only the SPLICE is clamped.
|
|
3663
|
+
*
|
|
3664
|
+
* It used to be `Math.min(msgs.length, recorded)`, which is right for the splice and wrong for the text: while
|
|
3665
|
+
* replaying, `msgs.length` is the number of messages restored SO FAR, so the rebuilt notice said "0 earlier
|
|
3666
|
+
* messages were summarized" where the model had been told 59. That is a different byte at the FRONT of every
|
|
3667
|
+
* request after a restart — the prefix-cache miss the operator warned about, and it was already there before the
|
|
3668
|
+
* usage line was added.
|
|
3669
|
+
*/
|
|
3670
|
+
const recorded = Number(d.summarized ?? 0) || msgs.length;
|
|
3671
|
+
const summarized = Math.min(msgs.length, recorded);
|
|
3657
3672
|
if (!sum) {
|
|
3658
3673
|
console.warn(`[teapot] compaction at seq ${e.seq} has no summary text — keeping the full history rather than discarding it`);
|
|
3659
3674
|
}
|
|
3660
3675
|
else {
|
|
3661
3676
|
msgs.splice(0, summarized, {
|
|
3662
3677
|
role: "user",
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3678
|
+
// the SAME builder as the compaction itself, with the line as it was recorded then
|
|
3679
|
+
content: compactionNotice({
|
|
3680
|
+
summarized: recorded,
|
|
3681
|
+
summary: sum,
|
|
3682
|
+
contextLine: typeof d.contextLine === "string" ? d.contextLine : undefined,
|
|
3683
|
+
}),
|
|
3667
3684
|
});
|
|
3668
3685
|
}
|
|
3669
3686
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function compactionNotice(input) {
|
|
2
|
+
const base = `[harness] Context was compacted: ${input.summarized} earlier messages were summarized. ` +
|
|
3
|
+
"AGENTS.md is embedded in your system prompt; memory.md, todo.md and decisions.md are NOT — " +
|
|
4
|
+
"call read_memory / get_todo / get_decisions if you need them.\n\n" +
|
|
5
|
+
`## Summary of earlier conversation\n${input.summary}`;
|
|
6
|
+
const line = (input.contextLine ?? "").trim();
|
|
7
|
+
return line ? `${base}\n\n${line} — the window is roomy again, not nearly exhausted.` : base;
|
|
8
|
+
}
|