teapot-coding-agent 0.37.113 → 0.37.115
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
|
*
|
|
@@ -1602,9 +1609,50 @@ export class Agent {
|
|
|
1602
1609
|
});
|
|
1603
1610
|
await this.maybeCompact(true);
|
|
1604
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)");
|
|
1605
1654
|
await this.log.append("prompt", this.currentSession, this.currentBranch, { source: "harness", text: msg });
|
|
1606
1655
|
this.messages.push({ role: "user", content: msg });
|
|
1607
|
-
await this.answerMeta(call, "(finish refused: the context window is the harness's to manage)");
|
|
1608
1656
|
return "next";
|
|
1609
1657
|
}
|
|
1610
1658
|
this.pendingSubReport = "";
|
|
@@ -2015,8 +2063,17 @@ export class Agent {
|
|
|
2015
2063
|
reasoning: res.reasoning,
|
|
2016
2064
|
});
|
|
2017
2065
|
this.lastAssistantText = m.content ?? "";
|
|
2018
|
-
|
|
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))) {
|
|
2019
2074
|
this.contextClaimNudges = 0;
|
|
2075
|
+
this.blockerAsks = 0;
|
|
2076
|
+
}
|
|
2020
2077
|
this.messages.push(m);
|
|
2021
2078
|
this.turnsSinceProgress++;
|
|
2022
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
|
+
}
|