teapot-coding-agent 0.37.112 → 0.37.114
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
|
@@ -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, usageLine } from "./context-claim.js";
|
|
12
|
+
import { namesBlocker } from "./blocker.js";
|
|
12
13
|
import { mcp } from "./mcp-registry.js";
|
|
13
14
|
import { flattenToolName } from "./mcp-registry.js";
|
|
14
15
|
import { metaToolSpecs } from "./meta-tools.js";
|
|
@@ -78,6 +79,10 @@ const UPDATE_INSTRUCTION = [
|
|
|
78
79
|
const SUMMARY_OPEN = "<conversation_checkpoint>\n";
|
|
79
80
|
const SUMMARY_CLOSE = "\n</conversation_checkpoint>";
|
|
80
81
|
const AUDIT_READ_ONLY_TOOLS = new Set(["read_file", "list_dir", "grep", "bash"]);
|
|
82
|
+
/** tool calls that decide/announce rather than do — they must not reset the "was that stop justified?" bounds */
|
|
83
|
+
const NON_WORK_TOOLS = new Set([
|
|
84
|
+
"finish", "report_progress", "ask_user", "set_goal", "get_goal", "get_todo", "set_todo",
|
|
85
|
+
]);
|
|
81
86
|
const SYSTEM_TEMPLATE = `You are a coding agent working autonomously inside a workspace.
|
|
82
87
|
|
|
83
88
|
Start any session with three cheap calls, in this order: get_goal() (what am I
|
|
@@ -245,6 +250,8 @@ export class Agent {
|
|
|
245
250
|
lastAssistantText = "";
|
|
246
251
|
/** how many times this stale round has been answered — bounded so the answer cannot become the loop */
|
|
247
252
|
contextClaimNudges = 0;
|
|
253
|
+
/** #200: a finish(false) that names no blocker is questioned once, never twice */
|
|
254
|
+
blockerAsks = 0;
|
|
248
255
|
/**
|
|
249
256
|
* "21:04 · 1h12m into this session · 3m since the last turn".
|
|
250
257
|
*
|
|
@@ -252,6 +259,22 @@ export class Agent {
|
|
|
252
259
|
* clock in there would invalidate the cache on every request. Reported as "AIが時間把握するのが極めて下手"
|
|
253
260
|
* — a five minute exploit and a device reboot read exactly like an instant in the transcript.
|
|
254
261
|
*/
|
|
262
|
+
/**
|
|
263
|
+
* The answer to a "the context window made me stop" claim — the same words whether it arrived as prose
|
|
264
|
+
* (#201) or inside `finish(goalComplete=false)`'s summary, which is how it actually arrived three times in
|
|
265
|
+
* `mediapad-t5-root-attempt-2-2601e254` (#200 is the same event seen as a stopping habit).
|
|
266
|
+
*/
|
|
267
|
+
contextClaimAnswer(where) {
|
|
268
|
+
return (`${this.timeAnchor()}\n[harness] ` +
|
|
269
|
+
(where === "finish"
|
|
270
|
+
? "That finish() was refused: its summary gives the context window as the blocker, and the window is not yours to run out of."
|
|
271
|
+
: "You stopped because of the context window.") +
|
|
272
|
+
` The numbers above are measured, not estimated — the harness compacts automatically and has just done so.` +
|
|
273
|
+
`\nContinue the task. If this is a FALSE POSITIVE (you were quoting that phrase in a report rather than ` +
|
|
274
|
+
`stopping for it), say so and carry on, or call finish() with your summary if the work is actually done. ` +
|
|
275
|
+
`If you are genuinely blocked, finish(goalComplete=false) with a blocker that is NOT the context size — and ` +
|
|
276
|
+
`weigh it against the current goal first: a goal that is met is finish(goalComplete=true), not a stop.`);
|
|
277
|
+
}
|
|
255
278
|
timeAnchor() {
|
|
256
279
|
const clock = turnAnchor({
|
|
257
280
|
now: Date.now(),
|
|
@@ -1443,13 +1466,7 @@ export class Agent {
|
|
|
1443
1466
|
detail: "the agent stopped because of the context window — compaction is the harness's job, so it compacted and told the agent to continue (#201)",
|
|
1444
1467
|
});
|
|
1445
1468
|
await this.maybeCompact(true);
|
|
1446
|
-
const msg =
|
|
1447
|
-
`measured, not estimated: the harness compacts automatically and has just done so, so running out ` +
|
|
1448
|
-
`of window is not something you can decide. Continue the task.\n` +
|
|
1449
|
-
`If this is a FALSE POSITIVE — you were quoting that phrase in a report rather than stopping for it — ` +
|
|
1450
|
-
`say so and carry on, or call finish() with your summary if the work is actually done. If you are ` +
|
|
1451
|
-
`genuinely blocked, finish(goalComplete=false) with a blocker that is NOT the context size, and weigh ` +
|
|
1452
|
-
`it against the current goal first: a goal that is met is finish(goalComplete=true), not a stop.`;
|
|
1469
|
+
const msg = this.contextClaimAnswer("stop");
|
|
1453
1470
|
await this.log.append("prompt", this.currentSession, this.currentBranch, {
|
|
1454
1471
|
source: "harness",
|
|
1455
1472
|
text: msg,
|
|
@@ -1571,6 +1588,73 @@ export class Agent {
|
|
|
1571
1588
|
}
|
|
1572
1589
|
metaHandlers = {
|
|
1573
1590
|
finish: async (call, m) => {
|
|
1591
|
+
/**
|
|
1592
|
+
* A `finish(goalComplete=false)` whose summary blames the context window is not a blocker (#200/#201).
|
|
1593
|
+
*
|
|
1594
|
+
* MEASURED in `mediapad-t5-root-attempt-2-2601e254`: the stopping turns were NOT prose without tool calls —
|
|
1595
|
+
* they were `finish(goalComplete=false)` calls whose summary read "コンテキスト上限のため停止します".
|
|
1596
|
+
* Handling only the prose path would have missed every real occurrence.
|
|
1597
|
+
*/
|
|
1598
|
+
const fin = safeParse(call.function.arguments);
|
|
1599
|
+
if (fin.goalComplete !== true &&
|
|
1600
|
+
!this.awaitingUser &&
|
|
1601
|
+
this.contextClaimNudges < 2 &&
|
|
1602
|
+
claimsContextLimit(String(fin.summary ?? ""))) {
|
|
1603
|
+
this.contextClaimNudges += 1;
|
|
1604
|
+
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1605
|
+
event: "context-claim-answered",
|
|
1606
|
+
attempt: this.contextClaimNudges,
|
|
1607
|
+
via: "finish",
|
|
1608
|
+
detail: "a finish(goalComplete=false) blamed the context window — refused, compacted, and told to continue (#201)",
|
|
1609
|
+
});
|
|
1610
|
+
await this.maybeCompact(true);
|
|
1611
|
+
const msg = this.contextClaimAnswer("finish");
|
|
1612
|
+
/**
|
|
1613
|
+
* Answer the tool call FIRST — in the log as well as in memory.
|
|
1614
|
+
*
|
|
1615
|
+
* The log is what a restarted session is rebuilt from, so writing the harness prompt before the tool
|
|
1616
|
+
* result produced a history a provider rejects: "tool message not directly after its assistant turn"
|
|
1617
|
+
* (#50, measured on the restored-session test).
|
|
1618
|
+
*/
|
|
1619
|
+
await this.answerMeta(call, "(finish refused: the context window is the harness's to manage)");
|
|
1620
|
+
await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
|
|
1621
|
+
this.messages.push({ role: "user", content: msg });
|
|
1622
|
+
return "next";
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* #200: `finish(goalComplete=false)` with nothing named as the blocker.
|
|
1626
|
+
*
|
|
1627
|
+
* "progress reportをしたあとにfinish(goalComplete=false)をしがち" — and also without a progress report,
|
|
1628
|
+
* with the context window fine (auto-compaction is on), time left and nothing in the way. MEASURED: of
|
|
1629
|
+
* 118 `finish(false)` calls on this machine, 13 followed a progress report and 8 of those named no
|
|
1630
|
+
* blocker. Asked once (never twice, and reset only by real work) so a genuinely stuck agent is not
|
|
1631
|
+
* trapped by a phrasing this misses.
|
|
1632
|
+
*/
|
|
1633
|
+
if (fin.goalComplete !== true &&
|
|
1634
|
+
!this.awaitingUser &&
|
|
1635
|
+
this.blockerAsks < 1 &&
|
|
1636
|
+
/**
|
|
1637
|
+
* Waiting on a background job is a LEGITIMATE reason to end the round — the harness resumes the agent
|
|
1638
|
+
* when it exits (`auto-continue-suppressed`), so the summary needs no blocker vocabulary. Asking here
|
|
1639
|
+
* broke that path (measured: "auto-continue is suppressed while a background bash runs").
|
|
1640
|
+
*/
|
|
1641
|
+
!hasRunningBgShells(this.toolCtx.cwd) &&
|
|
1642
|
+
!namesBlocker(String(fin.summary ?? ""))) {
|
|
1643
|
+
this.blockerAsks += 1;
|
|
1644
|
+
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1645
|
+
event: "finish-without-blocker",
|
|
1646
|
+
detail: "finish(goalComplete=false) named no blocker while the harness saw none either — asked for one instead of ending the round (#200)",
|
|
1647
|
+
});
|
|
1648
|
+
const msg = `${this.timeAnchor()}\n[harness] That finish() was refused: its summary names no blocker, and ` +
|
|
1649
|
+
`nothing in the harness agrees with one — the context window above is measured, compaction is ` +
|
|
1650
|
+
`automatic, and your tools have not been failing.\nContinue the task. If you ARE blocked, name it ` +
|
|
1651
|
+
`concretely: what you tried, what exactly failed, and why it cannot be worked around — then ` +
|
|
1652
|
+
`finish(goalComplete=false). If the goal is met, that is finish(goalComplete=true), not a stop.`;
|
|
1653
|
+
await this.answerMeta(call, "(finish refused: no blocker named — say what actually failed)");
|
|
1654
|
+
await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
|
|
1655
|
+
this.messages.push({ role: "user", content: msg });
|
|
1656
|
+
return "next";
|
|
1657
|
+
}
|
|
1574
1658
|
this.pendingSubReport = "";
|
|
1575
1659
|
await this.answerMeta(call, "(completion submitted for audit)");
|
|
1576
1660
|
await this.handleFinish(call.function.arguments);
|
|
@@ -1979,8 +2063,17 @@ export class Agent {
|
|
|
1979
2063
|
reasoning: res.reasoning,
|
|
1980
2064
|
});
|
|
1981
2065
|
this.lastAssistantText = m.content ?? "";
|
|
1982
|
-
|
|
2066
|
+
/**
|
|
2067
|
+
* Reset the "stop was questioned" counters only on REAL work.
|
|
2068
|
+
*
|
|
2069
|
+
* `finish`, `report_progress` and the meta tools are not work — and counting them as such would reset the
|
|
2070
|
+
* bound on the very call being questioned, so a model that keeps calling `finish` would be refused
|
|
2071
|
+
* forever instead of once.
|
|
2072
|
+
*/
|
|
2073
|
+
if (m.tool_calls?.some((c) => !NON_WORK_TOOLS.has(c.function.name))) {
|
|
1983
2074
|
this.contextClaimNudges = 0;
|
|
2075
|
+
this.blockerAsks = 0;
|
|
2076
|
+
}
|
|
1984
2077
|
this.messages.push(m);
|
|
1985
2078
|
this.turnsSinceProgress++;
|
|
1986
2079
|
this.activityChars += m.content?.length ?? 0;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does a `finish(goalComplete=false)` summary name a CONCRETE blocker?
|
|
3
|
+
*
|
|
4
|
+
* #200: "progress reportをしたあとにfinish(goalComplete=false)をしがち" — and per the operator, also without a
|
|
5
|
+
* progress report, with the context window fine (auto-compaction is on), time left and nothing actually in the
|
|
6
|
+
* way. The harness knows those facts, so a claim of being blocked can be checked instead of trusted.
|
|
7
|
+
*
|
|
8
|
+
* MEASURED over the sessions on this machine: of 118 `finish(goalComplete=false)` calls, 13 came within a few
|
|
9
|
+
* events of a progress report and 8 of those named no blocker at all.
|
|
10
|
+
*
|
|
11
|
+
* This is deliberately a VOCABULARY, not a model: it looks for the words people use when something refused to
|
|
12
|
+
* work. A miss costs one polite question ("what failed?"), which is why a broad list is the right shape — the
|
|
13
|
+
* refusal is bounded to one per round, so a phrasing this misses cannot trap the agent.
|
|
14
|
+
*/
|
|
15
|
+
const BLOCKER_WORDS = [
|
|
16
|
+
// english
|
|
17
|
+
"fail", "error", "cannot", "can't", "unable", "not possible", "impossible", "block", "missing",
|
|
18
|
+
"deni", "timeout", "timed out", "unreachable", "no access", "refus", "reject", "crash",
|
|
19
|
+
"not found", "unsupported", "regression", "won't work", "does not work", "doesn't work",
|
|
20
|
+
// japanese
|
|
21
|
+
"失敗", "できません", "できない", "できず", "不可能", "無理", "未達", "未到達", "特定でき", "取れません",
|
|
22
|
+
"取れない", "通らない", "エラー", "拒否", "権限", "見つから", "落ちる", "落ちた", "停止した",
|
|
23
|
+
// chinese
|
|
24
|
+
"失败", "无法", "错误", "未能", "不能",
|
|
25
|
+
];
|
|
26
|
+
export function namesBlocker(summary) {
|
|
27
|
+
const s = String(summary ?? "").toLowerCase();
|
|
28
|
+
if (!s.trim())
|
|
29
|
+
return false;
|
|
30
|
+
return BLOCKER_WORDS.some((w) => s.includes(w));
|
|
31
|
+
}
|