teapot-coding-agent 0.37.138 → 0.37.141
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 +24 -5
- package/dist/agent/editorconfig.js +5 -0
- package/dist/agent/tools.js +16 -1
- package/dist/log/events.js +21 -3
- package/dist/server/api.js +38 -4
- package/package.json +1 -1
- package/public/assets/index-BaBLdf3E.js +190 -0
- package/public/assets/index-BaBLdf3E.js.map +1 -0
- package/public/assets/{index-BO6NnwE7.css → index-DOQ5Euj6.css} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-D04oKpAm.js +0 -190
- package/public/assets/index-D04oKpAm.js.map +0 -1
package/dist/agent/agent.js
CHANGED
|
@@ -5,7 +5,7 @@ import { storeImage, resolveImages } from "../log/image-store.js";
|
|
|
5
5
|
import { chat, chatStream } from "./llm.js";
|
|
6
6
|
import { auditPrompt, parseAuditVerdict } from "./goal-audit.js";
|
|
7
7
|
import { createCatalog } from "./tool-catalog.js";
|
|
8
|
-
import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit,
|
|
8
|
+
import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShellsFor, killBgShells, runningBgShellCount } from "./tools.js";
|
|
9
9
|
import { effortChoosable } from "./llm.js";
|
|
10
10
|
import { turnAnchor } from "./timing.js";
|
|
11
11
|
import { claimsContextLimit, claimsOwnLimit, usageLine } from "./context-claim.js";
|
|
@@ -1122,7 +1122,15 @@ export class Agent {
|
|
|
1122
1122
|
parts.push(`NOT FOUND in todo.md: ${unmatched.map((s) => `"${s}"`).join(", ")} — check get_todo and retry with the exact wording, or use action:"add" to create it`);
|
|
1123
1123
|
return parts.join(". ");
|
|
1124
1124
|
}
|
|
1125
|
-
|
|
1125
|
+
/**
|
|
1126
|
+
* `by` is REQUIRED: the default was "operator", and the agent's own `finish(goalComplete=true)` was logged with it.
|
|
1127
|
+
*
|
|
1128
|
+
* The timeline then rendered "you marked this goal done — no audit runs for a manual completion" for a completion the
|
|
1129
|
+
* AGENT had claimed and that was supposed to be audited ("finish(goalComplete=true) なのに … が発行される"). A
|
|
1130
|
+
* default that guesses the actor is exactly the kind of thing that is right until somebody forgets an argument, so the
|
|
1131
|
+
* compiler asks now.
|
|
1132
|
+
*/
|
|
1133
|
+
async setGoalStatus(status, by) {
|
|
1126
1134
|
this.goal = { ...this.goal, status, updatedAt: new Date().toISOString() };
|
|
1127
1135
|
await this.writeGoalFile();
|
|
1128
1136
|
await this.log.append("goal", this.currentSession, this.currentBranch, {
|
|
@@ -1462,7 +1470,17 @@ export class Agent {
|
|
|
1462
1470
|
}
|
|
1463
1471
|
if (this.pendingPrompts.length)
|
|
1464
1472
|
continue;
|
|
1465
|
-
|
|
1473
|
+
/**
|
|
1474
|
+
* Suppress the continue only for a job THIS agent started.
|
|
1475
|
+
*
|
|
1476
|
+
* The check used to be workspace-wide (`hasRunningBgShells(cwd)`), and the resume is owner-scoped: the exit
|
|
1477
|
+
* notification goes to `ctx.onBackgroundExit`, i.e. to the agent that launched the job. Sub-agents share their
|
|
1478
|
+
* parent's workspace, so a child's `sleep 300` suppressed the PARENT's auto-continue while the parent's own
|
|
1479
|
+
* path back (`auto-continue-suppressed` → resume on exit) could never fire — the parent simply stopped.
|
|
1480
|
+
* `isLive()` has always asked the owner-scoped question (`hasRunningBgShellsFor`); these two sites now agree
|
|
1481
|
+
* with it.
|
|
1482
|
+
*/
|
|
1483
|
+
if (hasRunningBgShellsFor(this.toolCtx.cwd, this.opts.id)) {
|
|
1466
1484
|
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1467
1485
|
event: "auto-continue-suppressed",
|
|
1468
1486
|
reason: "background job still running — the agent resumes when it exits",
|
|
@@ -1744,7 +1762,8 @@ export class Agent {
|
|
|
1744
1762
|
* when it exits (`auto-continue-suppressed`), so the summary needs no blocker vocabulary. Asking here
|
|
1745
1763
|
* broke that path (measured: "auto-continue is suppressed while a background bash runs").
|
|
1746
1764
|
*/
|
|
1747
|
-
|
|
1765
|
+
// owner-scoped for the same reason as the suppression above: a sibling's job is not this agent's excuse
|
|
1766
|
+
!hasRunningBgShellsFor(this.toolCtx.cwd, this.opts.id) &&
|
|
1748
1767
|
!namesBlocker(String(fin.summary ?? ""))) {
|
|
1749
1768
|
this.blockerAsks += 1;
|
|
1750
1769
|
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
@@ -2693,7 +2712,7 @@ export class Agent {
|
|
|
2693
2712
|
}
|
|
2694
2713
|
}
|
|
2695
2714
|
else {
|
|
2696
|
-
await this.setGoalStatus("done");
|
|
2715
|
+
await this.setGoalStatus("done", "agent");
|
|
2697
2716
|
}
|
|
2698
2717
|
}
|
|
2699
2718
|
await this.appendFinalMessage(args);
|
|
@@ -45,6 +45,11 @@ export function editorConfigFor(targetPath) {
|
|
|
45
45
|
out = { ...out, finalNewline: true };
|
|
46
46
|
else if (fn === "false")
|
|
47
47
|
out = { ...out, finalNewline: false };
|
|
48
|
+
const tt = section.props.get("trim_trailing_whitespace");
|
|
49
|
+
if (tt === "true")
|
|
50
|
+
out = { ...out, trimTrailingWhitespace: true };
|
|
51
|
+
else if (tt === "false")
|
|
52
|
+
out = { ...out, trimTrailingWhitespace: false };
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
return out;
|
package/dist/agent/tools.js
CHANGED
|
@@ -90,6 +90,21 @@ export function detectEol(text) {
|
|
|
90
90
|
export function splitEolLines(text) {
|
|
91
91
|
return text.split(/\r\n|\r|\n/);
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Strip trailing whitespace from every line, as `.editorconfig`'s `trim_trailing_whitespace = true` asks.
|
|
95
|
+
*
|
|
96
|
+
* A file written by the agent should look like a file written by a person in that repository; leaving trailing spaces
|
|
97
|
+
* behind is what makes `git diff --check` complain on somebody else's commit. Line endings are untouched here — that is
|
|
98
|
+
* `applyEol`'s job, and the two compose in ONE place (`applyEditorConfig`) so a caller cannot apply one and forget the
|
|
99
|
+
* other.
|
|
100
|
+
*/
|
|
101
|
+
export function trimTrailingWhitespace(content) {
|
|
102
|
+
return content.replace(/[ \t]+(?=\r?\n|$)/g, "");
|
|
103
|
+
}
|
|
104
|
+
export function applyEditorConfig(content, ec) {
|
|
105
|
+
const trimmed = ec.trimTrailingWhitespace === true ? trimTrailingWhitespace(content) : content;
|
|
106
|
+
return applyEol(trimmed, ec.eol);
|
|
107
|
+
}
|
|
93
108
|
export function applyEol(content, eol) {
|
|
94
109
|
if (!eol || eol === "\n")
|
|
95
110
|
return content;
|
|
@@ -1262,7 +1277,7 @@ export const TOOLS = [
|
|
|
1262
1277
|
if (detected !== null)
|
|
1263
1278
|
return finishWrite(p, applyEol(args.content, detected), detected, args.content);
|
|
1264
1279
|
const ec = editorConfigFor(p);
|
|
1265
|
-
const out =
|
|
1280
|
+
const out = applyEditorConfig(args.content, ec);
|
|
1266
1281
|
const final = ec.finalNewline === true && out !== "" && !out.endsWith("\n") ? `${out}\n` : out;
|
|
1267
1282
|
return finishWrite(p, final, ec.eol, args.content);
|
|
1268
1283
|
},
|
package/dist/log/events.js
CHANGED
|
@@ -201,11 +201,29 @@ export class EventLog {
|
|
|
201
201
|
await new Promise((res) => s.end(res));
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Parse a whole log file, STREAMING it.
|
|
206
|
+
*
|
|
207
|
+
* It used to `readFile()` the entire file into one string and `.split("\n")` it, so a large session paid for three
|
|
208
|
+
* copies at once: the file's bytes, one string per line, and the parsed objects. MEASURED on the operator's server:
|
|
209
|
+
* `master rss 1034.4MB · heap 599.1MB` at the moment of a burst, back to `heap 248.2MB` a moment later — a transient
|
|
210
|
+
* allocation that GC could reclaim, not a leak.
|
|
211
|
+
*
|
|
212
|
+
* Reading line-by-line through a stream removes the first two copies: the only thing retained is the events, and the
|
|
213
|
+
* peak no longer scales with (file bytes × 3).
|
|
214
|
+
*/
|
|
204
215
|
export async function readEvents(filePath) {
|
|
216
|
+
const out = [];
|
|
205
217
|
try {
|
|
206
|
-
const {
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
const [{ createReadStream }, { createInterface }] = await Promise.all([
|
|
219
|
+
import("node:fs"),
|
|
220
|
+
import("node:readline"),
|
|
221
|
+
]);
|
|
222
|
+
const rl = createInterface({
|
|
223
|
+
input: createReadStream(filePath, { encoding: "utf8" }),
|
|
224
|
+
crlfDelay: Infinity,
|
|
225
|
+
});
|
|
226
|
+
for await (const line of rl) {
|
|
209
227
|
if (!line.trim())
|
|
210
228
|
continue;
|
|
211
229
|
try {
|
package/dist/server/api.js
CHANGED
|
@@ -992,7 +992,7 @@ export function buildApp(master) {
|
|
|
992
992
|
}
|
|
993
993
|
}
|
|
994
994
|
else if (body.status)
|
|
995
|
-
await a.setGoalStatus(body.status);
|
|
995
|
+
await a.setGoalStatus(body.status, "operator");
|
|
996
996
|
else
|
|
997
997
|
return c.json({ error: "text or status required" }, 400);
|
|
998
998
|
return c.json({ ok: true });
|
|
@@ -1195,16 +1195,38 @@ export function buildApp(master) {
|
|
|
1195
1195
|
return c.json({ ok: true, ...r });
|
|
1196
1196
|
});
|
|
1197
1197
|
const eventsCache = new Map();
|
|
1198
|
+
/**
|
|
1199
|
+
* The whole-file cache is bounded by EVENTS, not by file count.
|
|
1200
|
+
*
|
|
1201
|
+
* `if (eventsCache.size > 64) eventsCache.clear()` counted FILES, so eight sessions with 90k events each were all
|
|
1202
|
+
* retained — hundreds of MB the process never gives back, since nothing evicts them until the 65th file appears.
|
|
1203
|
+
* A parsed event is roughly a few hundred bytes, so the budget below is a few tens of MB.
|
|
1204
|
+
*/
|
|
1205
|
+
const EVENTS_CACHE_BUDGET = 250_000;
|
|
1206
|
+
let eventsCached = 0;
|
|
1198
1207
|
async function readEventsCached(filePath) {
|
|
1199
1208
|
try {
|
|
1200
1209
|
const st = await fs.stat(filePath);
|
|
1201
1210
|
const hit = eventsCache.get(filePath);
|
|
1202
|
-
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size)
|
|
1211
|
+
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) {
|
|
1212
|
+
// refresh insertion order so the eviction below stays LRU
|
|
1213
|
+
eventsCache.delete(filePath);
|
|
1214
|
+
eventsCache.set(filePath, hit);
|
|
1203
1215
|
return hit.events;
|
|
1216
|
+
}
|
|
1204
1217
|
const events = await readEvents(filePath);
|
|
1205
|
-
if (
|
|
1206
|
-
|
|
1218
|
+
if (hit)
|
|
1219
|
+
eventsCached -= hit.events.length;
|
|
1207
1220
|
eventsCache.set(filePath, { mtimeMs: st.mtimeMs, size: st.size, events });
|
|
1221
|
+
eventsCached += events.length;
|
|
1222
|
+
for (const [key, entry] of eventsCache) {
|
|
1223
|
+
if (eventsCached <= EVENTS_CACHE_BUDGET && eventsCache.size <= 8)
|
|
1224
|
+
break;
|
|
1225
|
+
eventsCache.delete(key);
|
|
1226
|
+
eventsCached -= entry.events.length;
|
|
1227
|
+
}
|
|
1228
|
+
if (eventsCached < 0)
|
|
1229
|
+
eventsCached = 0;
|
|
1208
1230
|
return events;
|
|
1209
1231
|
}
|
|
1210
1232
|
catch {
|
|
@@ -1245,6 +1267,18 @@ export function buildApp(master) {
|
|
|
1245
1267
|
const before = c.req.query("before");
|
|
1246
1268
|
const after = c.req.query("after");
|
|
1247
1269
|
if (after && !before && !branch) {
|
|
1270
|
+
/**
|
|
1271
|
+
* The incremental case must not read the whole file.
|
|
1272
|
+
*
|
|
1273
|
+
* `after=` is what a client sends to catch up after a reconnect, and it is almost always near the END of the log,
|
|
1274
|
+
* so the tail window answers it — reading 90k events to find one id was the burst path.
|
|
1275
|
+
*/
|
|
1276
|
+
const tailFirst = await readEventsTail(filePath, Math.max(limit, 4_000));
|
|
1277
|
+
const inTail = tailFirst.events.findIndex((e) => e.id === after);
|
|
1278
|
+
if (inTail !== -1) {
|
|
1279
|
+
const events = tailFirst.events.slice(inTail + 1);
|
|
1280
|
+
return c.json({ events, total: tailFirst.total, appended: events.length > 0 });
|
|
1281
|
+
}
|
|
1248
1282
|
const all = await readEventsCached(filePath);
|
|
1249
1283
|
const idx = all.findIndex((e) => e.id === after);
|
|
1250
1284
|
if (idx === -1) {
|