teapot-coding-agent 0.37.178 → 0.37.180
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
|
@@ -921,6 +921,31 @@ export class Agent {
|
|
|
921
921
|
prefix.shift();
|
|
922
922
|
return [...prefix, ...own.filter((e) => e !== header)];
|
|
923
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Attach a re-context message to the live conversation AND to the log.
|
|
926
|
+
*
|
|
927
|
+
* These three (memory, goal/todo, recently-read files) are spliced into `messages` right after a compaction so the model
|
|
928
|
+
* does not lose what drives the work. They used to be spliced ONLY — never logged — which meant a restore rebuilt the
|
|
929
|
+
* conversation from the log and silently omitted them: the prompt the model resumed with differed from the one it last
|
|
930
|
+
* saw, so the prefix cache was dead from that point on and the operator paid for the whole conversation again (#227).
|
|
931
|
+
*/
|
|
932
|
+
async attachContextNote(text) {
|
|
933
|
+
/**
|
|
934
|
+
* APPENDED, not spliced in after the checkpoint.
|
|
935
|
+
*
|
|
936
|
+
* The log records it at the moment it happens, so the rebuilt conversation can only reproduce the same ORDER if the
|
|
937
|
+
* message went to the end too — splicing it at index 1 put it before turns that were logged earlier, and a restore
|
|
938
|
+
* then produced `[checkpoint, note, …]` where the live conversation had `[checkpoint, …, note]`. Same content, different
|
|
939
|
+
* prefix, prefix cache dead (#227). Appending also reads better: the freshest instructions come last, right before the
|
|
940
|
+
* model's next turn.
|
|
941
|
+
*/
|
|
942
|
+
this.messages.push({ role: "user", content: text });
|
|
943
|
+
await this.log.append("prompt", this.currentSession, this.currentBranch, {
|
|
944
|
+
source: "harness",
|
|
945
|
+
text,
|
|
946
|
+
ahead: 0,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
924
949
|
async restoreFromLog() {
|
|
925
950
|
const own = await readEvents(this.log.filePath);
|
|
926
951
|
if (own.length === 0)
|
|
@@ -989,14 +1014,32 @@ export class Agent {
|
|
|
989
1014
|
});
|
|
990
1015
|
}
|
|
991
1016
|
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Compact once, however many times the button is pressed.
|
|
1019
|
+
*
|
|
1020
|
+
* `enqueue` is a SERIAL queue, so every press queued another job and they all ran in turn — MEASURED as "compact を連打
|
|
1021
|
+
* すると compact がキューに溜まって compact された後に compact され続ける": the operator pressed it three times and watched
|
|
1022
|
+
* the agent keep compacting afterwards. `force` does not make a repeat harmless either: the compaction itself appends
|
|
1023
|
+
* the summary exchange, so the next forced pass can find new messages to cut.
|
|
1024
|
+
*
|
|
1025
|
+
* Coalescing is the right shape because the requests are IDENTICAL — nothing is lost by answering "already running".
|
|
1026
|
+
*/
|
|
1027
|
+
compactInFlight = null;
|
|
992
1028
|
async compactNow() {
|
|
993
|
-
|
|
1029
|
+
if (this.compactInFlight)
|
|
1030
|
+
return { ran: false };
|
|
1031
|
+
this.compactInFlight = this.enqueue(async () => {
|
|
994
1032
|
await this.ensureReady();
|
|
995
1033
|
const before = this.stats.compactions;
|
|
996
1034
|
await this.maybeCompact(true);
|
|
997
|
-
return this.stats.compactions > before;
|
|
1035
|
+
return { ran: this.stats.compactions > before };
|
|
998
1036
|
});
|
|
999
|
-
|
|
1037
|
+
try {
|
|
1038
|
+
return await this.compactInFlight;
|
|
1039
|
+
}
|
|
1040
|
+
finally {
|
|
1041
|
+
this.compactInFlight = null;
|
|
1042
|
+
}
|
|
1000
1043
|
}
|
|
1001
1044
|
/**
|
|
1002
1045
|
* Rewrite an earlier prompt and fork from there.
|
|
@@ -3365,11 +3408,8 @@ export class Agent {
|
|
|
3365
3408
|
try {
|
|
3366
3409
|
const notes = (await fs.readFile(this.memoryFile, "utf8")).trim();
|
|
3367
3410
|
if (notes) {
|
|
3368
|
-
this.
|
|
3369
|
-
|
|
3370
|
-
content: `[harness] Your durable notes (memory.md), re-attached after compaction — ` +
|
|
3371
|
-
`this is what earlier you chose to remember:\n\n${notes.slice(0, 8_000)}`,
|
|
3372
|
-
});
|
|
3411
|
+
await this.attachContextNote(`[harness] Your durable notes (memory.md), re-attached after compaction — ` +
|
|
3412
|
+
`this is what earlier you chose to remember:\n\n${notes.slice(0, 8_000)}`);
|
|
3373
3413
|
}
|
|
3374
3414
|
}
|
|
3375
3415
|
catch {
|
|
@@ -3400,15 +3440,12 @@ export class Agent {
|
|
|
3400
3440
|
const todoText = allDone ? "" : this.todo.trim();
|
|
3401
3441
|
const goalText = this.goal.text.trim();
|
|
3402
3442
|
if (goalText || todoText) {
|
|
3403
|
-
this.
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
`
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
`Update the list as you finish work (set_todo), so this list and reality cannot drift.`
|
|
3410
|
-
: `no task is open in todo.md right now — if work remains, write it there`),
|
|
3411
|
-
});
|
|
3443
|
+
await this.attachContextNote(`[harness] Your goal and TODO list, re-attached after compaction:\n` +
|
|
3444
|
+
`goal (${this.goal.status}): ${goalText ? goalText.slice(0, 2_000) : "(none set)"}\n` +
|
|
3445
|
+
(todoText
|
|
3446
|
+
? `todo.md (verbatim):\n${todoText.slice(0, 8_000)}\n` +
|
|
3447
|
+
`Update the list as you finish work (set_todo), so this list and reality cannot drift.`
|
|
3448
|
+
: `no task is open in todo.md right now — if work remains, write it there`));
|
|
3412
3449
|
}
|
|
3413
3450
|
}
|
|
3414
3451
|
if (this.recentReads.length && mode === "summarize") {
|
|
@@ -3426,11 +3463,8 @@ export class Agent {
|
|
|
3426
3463
|
}
|
|
3427
3464
|
}
|
|
3428
3465
|
if (restored.length) {
|
|
3429
|
-
this.
|
|
3430
|
-
|
|
3431
|
-
content: `[harness] These files were recently read and are re-attached for continuity ` +
|
|
3432
|
-
`(they may have changed — re-read if precision matters):\n\n${restored.join("\n\n")}`,
|
|
3433
|
-
});
|
|
3466
|
+
await this.attachContextNote(`[harness] These files were recently read and are re-attached for continuity ` +
|
|
3467
|
+
`(they may have changed — re-read if precision matters):\n\n${restored.join("\n\n")}`);
|
|
3434
3468
|
this.recentReads = this.recentReads.filter((rel) => restoredPaths.has(rel));
|
|
3435
3469
|
}
|
|
3436
3470
|
}
|