teapot-coding-agent 0.37.130 → 0.37.132
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 +105 -0
- package/dist/agent/loop-guard.js +31 -0
- package/dist/server/terminals.js +17 -2
- package/package.json +1 -1
- package/public/assets/index-BclX36O1.js +190 -0
- package/public/assets/index-BclX36O1.js.map +1 -0
- package/public/assets/index-CvnF6SM6.css +1 -0
- package/public/index.html +2 -2
- package/public/assets/index-BoYb04A3.css +0 -1
- package/public/assets/index-DSwPybdZ.js +0 -190
- package/public/assets/index-DSwPybdZ.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 { isDegenerateRepeat } from "./loop-guard.js";
|
|
12
13
|
import { namesBlocker } from "./blocker.js";
|
|
13
14
|
import { mcp } from "./mcp-registry.js";
|
|
14
15
|
import { flattenToolName } from "./mcp-registry.js";
|
|
@@ -1403,6 +1404,13 @@ export class Agent {
|
|
|
1403
1404
|
}
|
|
1404
1405
|
stopSeq = 0;
|
|
1405
1406
|
progressRequestedThisRound = false;
|
|
1407
|
+
/** the agent called report_progress in this round — a report is not a stop (#215) */
|
|
1408
|
+
reportedThisRound = false;
|
|
1409
|
+
/** bounded: the forced continue after a report may happen once per round */
|
|
1410
|
+
reportedNudges = 0;
|
|
1411
|
+
/** the stream was aborted because the model looped on the same characters (#209) */
|
|
1412
|
+
degenerateOutput = false;
|
|
1413
|
+
degenerateStops = 0;
|
|
1406
1414
|
nudgedAtTurn = -1;
|
|
1407
1415
|
onControlStatusChange = null;
|
|
1408
1416
|
setStatus(s, reason = "") {
|
|
@@ -1471,6 +1479,44 @@ export class Agent {
|
|
|
1471
1479
|
}
|
|
1472
1480
|
if (finished)
|
|
1473
1481
|
this.consecutiveIdleRounds = 0;
|
|
1482
|
+
/**
|
|
1483
|
+
* A progress report is not a stopping point (#215 "progress report後は強制的にauto-continueする /
|
|
1484
|
+
* `reported.` で止まるケースが多すぎる").
|
|
1485
|
+
*
|
|
1486
|
+
* The prompt asks for a report and says "end the turn right after the call", so the model files the report,
|
|
1487
|
+
* answers "reported." and stops — while the work is unfinished. The loop continues here even with
|
|
1488
|
+
* auto-continue off or no goal set, because filing a report is not a decision to stop. Once per round, and
|
|
1489
|
+
* reset by any round that does actual work.
|
|
1490
|
+
*/
|
|
1491
|
+
if (!finished &&
|
|
1492
|
+
this.reportedThisRound &&
|
|
1493
|
+
this.reportedNudges < 1 &&
|
|
1494
|
+
// a PAUSED goal means the operator parked this agent; forcing another turn would fight that
|
|
1495
|
+
this.goal.status !== "paused") {
|
|
1496
|
+
this.reportedNudges += 1;
|
|
1497
|
+
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1498
|
+
event: "auto-continue-after-progress",
|
|
1499
|
+
detail: "the round filed a progress report and then stopped — a report is not a stop, so the loop continues",
|
|
1500
|
+
});
|
|
1501
|
+
/**
|
|
1502
|
+
* Worded for a session WITHOUT a goal too, because this branch runs before the goal check.
|
|
1503
|
+
*
|
|
1504
|
+
* A progress report can be filed by an agent that has no goal — the harness asks for one after real
|
|
1505
|
+
* activity, and the operator's own message is what defines the task then. Saying "the goal is genuinely
|
|
1506
|
+
* met" to an agent that has no goal is noise.
|
|
1507
|
+
*/
|
|
1508
|
+
const msg = this.harnessMessage(this.goal.text.trim()
|
|
1509
|
+
? `[harness] You filed a progress report and then stopped. A report is not a stopping point: ` +
|
|
1510
|
+
`keep working on the goal above and call finish() only when it is genuinely met or you are ` +
|
|
1511
|
+
`concretely blocked.`
|
|
1512
|
+
: `[harness] You filed a progress report and then stopped. A report is not a stopping point: ` +
|
|
1513
|
+
`continue what the operator asked for, and call finish() when it is done or you are concretely ` +
|
|
1514
|
+
`blocked.`);
|
|
1515
|
+
await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
|
|
1516
|
+
this.messages.push({ role: "user", content: msg });
|
|
1517
|
+
this.consecutiveIdleRounds = 0;
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1474
1520
|
if (finished ||
|
|
1475
1521
|
!this.opts.autoContinue ||
|
|
1476
1522
|
this.goal.status !== "active" ||
|
|
@@ -1549,6 +1595,26 @@ export class Agent {
|
|
|
1549
1595
|
}
|
|
1550
1596
|
catch (err) {
|
|
1551
1597
|
const name = err.name;
|
|
1598
|
+
/**
|
|
1599
|
+
* A loop we cut off is ASSISTED, not fatal: tell the model what happened and let it continue.
|
|
1600
|
+
*
|
|
1601
|
+
* Stopping the agent would make the operator restart it; leaving it to spin costs the budget. Bounded to
|
|
1602
|
+
* three per round so a model that can only loop still ends.
|
|
1603
|
+
*/
|
|
1604
|
+
if (this.degenerateOutput) {
|
|
1605
|
+
this.degenerateOutput = false;
|
|
1606
|
+
if (this.degenerateStops < 3 && !this.stopRequested) {
|
|
1607
|
+
this.degenerateStops += 1;
|
|
1608
|
+
const msg = this.harnessMessage(`[harness] Your last output began repeating the same characters, so the stream was cut off. ` +
|
|
1609
|
+
`That wastes the context and tells nobody anything. Restate the next step in one short ` +
|
|
1610
|
+
`paragraph and then continue the task.`);
|
|
1611
|
+
await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
|
|
1612
|
+
this.messages.push({ role: "user", content: msg });
|
|
1613
|
+
this.consecutiveIdleRounds = 0;
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
break;
|
|
1617
|
+
}
|
|
1552
1618
|
if (this.stopRequested || name === "AbortError" || name === "StopRequested" || name === "WaitForUser")
|
|
1553
1619
|
break;
|
|
1554
1620
|
const msg = err.message ?? String(err);
|
|
@@ -1713,6 +1779,7 @@ export class Agent {
|
|
|
1713
1779
|
},
|
|
1714
1780
|
report_progress: async (call, m) => {
|
|
1715
1781
|
await this.recordProgress(call.function.arguments);
|
|
1782
|
+
this.reportedThisRound = true;
|
|
1716
1783
|
await this.answerMeta(call, "progress recorded");
|
|
1717
1784
|
return "next";
|
|
1718
1785
|
},
|
|
@@ -1990,6 +2057,14 @@ export class Agent {
|
|
|
1990
2057
|
};
|
|
1991
2058
|
async runTurnsUntilIdle() {
|
|
1992
2059
|
let finished = false;
|
|
2060
|
+
/**
|
|
2061
|
+
* Once per ROUND, not once per LLM turn.
|
|
2062
|
+
*
|
|
2063
|
+
* Clearing it each turn made the flag useless: the model files the report in one turn, the loop resets it before
|
|
2064
|
+
* the next, and the "reported." that ends the round is seen with the flag already false — so the forced continue
|
|
2065
|
+
* never fired (MEASURED: the #215 test failed with the per-turn reset).
|
|
2066
|
+
*/
|
|
2067
|
+
this.reportedThisRound = false;
|
|
1993
2068
|
const cap = Math.max(0, this.opts.maxTurnsPerRound ?? 200);
|
|
1994
2069
|
for (let guard = 0; cap === 0 || guard < cap; guard++) {
|
|
1995
2070
|
if (this.stopRequested)
|
|
@@ -2015,6 +2090,26 @@ export class Agent {
|
|
|
2015
2090
|
text: s.text,
|
|
2016
2091
|
reasoning: s.reasoning,
|
|
2017
2092
|
});
|
|
2093
|
+
/**
|
|
2094
|
+
* Cut a degenerate stream off as it happens (#209).
|
|
2095
|
+
*
|
|
2096
|
+
* "DeepSeekが ` ********` を一生吐いたりするので無駄にトークン食って困る". Every chunk is a valid token, so
|
|
2097
|
+
* nothing downstream notices — the only place that can stop it is the accumulator. Aborting here is what
|
|
2098
|
+
* the abort controller is for; the catch below turns it into a nudge rather than a stop.
|
|
2099
|
+
*/
|
|
2100
|
+
if (!this.degenerateOutput && isDegenerateRepeat(`${s.text}${s.reasoning}`)) {
|
|
2101
|
+
this.degenerateOutput = true;
|
|
2102
|
+
void this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
2103
|
+
event: "degenerate-output-stopped",
|
|
2104
|
+
chars: s.text.length + s.reasoning.length,
|
|
2105
|
+
detail: "the model began repeating the same characters; the stream was aborted before it could burn the context",
|
|
2106
|
+
});
|
|
2107
|
+
try {
|
|
2108
|
+
this.abort?.abort();
|
|
2109
|
+
}
|
|
2110
|
+
catch {
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2018
2113
|
});
|
|
2019
2114
|
}
|
|
2020
2115
|
catch (err) {
|
|
@@ -2092,6 +2187,15 @@ export class Agent {
|
|
|
2092
2187
|
cached: res.usage.cachedInputTokens,
|
|
2093
2188
|
};
|
|
2094
2189
|
await this.log.append("usage", this.currentSession, this.currentBranch, res.usage);
|
|
2190
|
+
/**
|
|
2191
|
+
* Push the new usage so the context meter moves while the agent works.
|
|
2192
|
+
*
|
|
2193
|
+
* `ctx.usedTokens` rides on the agent snapshot, which only went out on a session-title write — so the meter sat
|
|
2194
|
+
* still for an entire turn and jumped at the end. Reported as "コンテキストウィンドウ消費がリアルタイムで
|
|
2195
|
+
* 更新されてない? ターンごとにWSに乗せれば良いはず": once per LLM call is exactly that, and it is already the
|
|
2196
|
+
* moment the number changes.
|
|
2197
|
+
*/
|
|
2198
|
+
this.emitSnapshotUpdate();
|
|
2095
2199
|
}
|
|
2096
2200
|
// `assistantTurn` carries the thinking, which is what `reasoning_content` is sent from (#187)
|
|
2097
2201
|
const m = assistantTurn(res.message, res.reasoning);
|
|
@@ -2114,6 +2218,7 @@ export class Agent {
|
|
|
2114
2218
|
if (m.tool_calls?.some((c) => !NON_WORK_TOOLS.has(c.function.name))) {
|
|
2115
2219
|
this.contextClaimNudges = 0;
|
|
2116
2220
|
this.blockerAsks = 0;
|
|
2221
|
+
this.reportedNudges = 0;
|
|
2117
2222
|
}
|
|
2118
2223
|
this.messages.push(m);
|
|
2119
2224
|
this.turnsSinceProgress++;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is the model stuck repeating itself?
|
|
3
|
+
*
|
|
4
|
+
* "DeepSeekが ` ********` を一生吐いたりするので無駄にトークン食って困る" (#209). A degenerate stream is not just ugly — it
|
|
5
|
+
* burns the context budget and the operator's money, and nothing downstream notices because every chunk is a valid
|
|
6
|
+
* token.
|
|
7
|
+
*
|
|
8
|
+
* The rule is deliberately crude and deliberately LOUD: a unit of 1–12 characters repeated at least 40 times in a
|
|
9
|
+
* row at the end of the output. Legitimate text contains short runs of `-`, `=`, `*` and spaces (a markdown rule is
|
|
10
|
+
* a dozen characters; a code fence is three), so the threshold has to be far above them — 40 repetitions of a
|
|
11
|
+
* multi-character unit is not something a model writes on purpose.
|
|
12
|
+
*/
|
|
13
|
+
export function isDegenerateRepeat(text, minRepeats = 40) {
|
|
14
|
+
const t = String(text ?? "");
|
|
15
|
+
if (t.length < minRepeats)
|
|
16
|
+
return false;
|
|
17
|
+
// only the tail matters, and it keeps the check O(1) per chunk
|
|
18
|
+
const tail = t.slice(-Math.min(t.length, minRepeats * 12 + 24));
|
|
19
|
+
for (let unit = 1; unit <= 12; unit++) {
|
|
20
|
+
// how many times does the last `unit` characters repeat backwards without a break?
|
|
21
|
+
let repeats = 1;
|
|
22
|
+
for (let i = tail.length - unit * 2; i >= 0; i -= unit) {
|
|
23
|
+
if (tail.slice(i, i + unit) !== tail.slice(i + unit, i + unit * 2))
|
|
24
|
+
break;
|
|
25
|
+
repeats++;
|
|
26
|
+
if (repeats >= minRepeats)
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
package/dist/server/terminals.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { existsSync, readFileSync, readlinkSync } from "node:fs";
|
|
3
3
|
import { toolShellFor } from "../agent/tools.js";
|
|
4
|
+
import { bus } from "../bus.js";
|
|
4
5
|
export function terminalShellFor(platform, env, exists = existsSync) {
|
|
5
6
|
return toolShellFor(platform, env, exists).file;
|
|
6
7
|
}
|
|
@@ -204,9 +205,23 @@ export function reapIdleTerminals(now = Date.now()) {
|
|
|
204
205
|
const attached = (sinks.get(t.id)?.size ?? 0) > 0;
|
|
205
206
|
if (attached)
|
|
206
207
|
continue;
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
const idle = now - t.createdAt > IDLE_REAP_MS;
|
|
209
|
+
if (t.exited || idle) {
|
|
210
|
+
if (closeTerminal(t.id)) {
|
|
209
211
|
n++;
|
|
212
|
+
/**
|
|
213
|
+
* Tell the UI, so the tab does not dangle.
|
|
214
|
+
*
|
|
215
|
+
* Reported as "長時間放置すると開いてたターミナルが消失する": the pty is reaped when nothing is attached (a
|
|
216
|
+
* sleeping browser drops its socket), and the tab stayed in the strip pointing at an id that no longer
|
|
217
|
+
* exists — the shell "disappeared" with no explanation. The client now removes the tab and says why.
|
|
218
|
+
*/
|
|
219
|
+
bus.emit("update", {
|
|
220
|
+
kind: "terminal-closed",
|
|
221
|
+
terminalId: t.id,
|
|
222
|
+
reason: t.exited ? "exited" : "idle",
|
|
223
|
+
});
|
|
224
|
+
}
|
|
210
225
|
}
|
|
211
226
|
}
|
|
212
227
|
return n;
|