teapot-coding-agent 0.37.157 → 0.37.159

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.
@@ -82,7 +82,7 @@ const SUMMARY_CLOSE = "\n</conversation_checkpoint>";
82
82
  const AUDIT_READ_ONLY_TOOLS = new Set(["read_file", "list_dir", "grep", "bash"]);
83
83
  /** tool calls that decide/announce rather than do — they must not reset the "was that stop justified?" bounds */
84
84
  const NON_WORK_TOOLS = new Set([
85
- "finish", "report_progress", "ask_user", "set_goal", "get_goal", "get_todo", "set_todo",
85
+ "finish", "report_progress", "ask_operator", "ask_user", "set_goal", "get_goal", "get_todo", "set_todo",
86
86
  ]);
87
87
  const SYSTEM_TEMPLATE = `You are a coding agent working autonomously inside a workspace.
88
88
 
@@ -96,9 +96,9 @@ Most session state is not injected into prompts — fetch it with tools instead:
96
96
  compaction notice, or whenever you lose the thread.
97
97
  - set_goal(text) → change the objective itself (not routine updates).
98
98
  - finish(goalComplete=true, summary) → goal fully achieved.
99
- - ask_user(question, options?) → park the loop and wait for the operator's
99
+ - ask_operator(question, options?) → park the loop and wait for the operator's
100
100
  decision (plan confirmation, ambiguity). One concrete question at a time.
101
- Which one ends the turn: finish() closes the round, ask_user() parks it until
101
+ Which one ends the turn: finish() closes the round, ask_operator() parks it until
102
102
  the operator answers, and report_progress() does NOT end it — that output goes
103
103
  to the operator's progress panel and you carry on working.
104
104
  - read_memory(query?) / add_memory(text) / forget_memory(query) / set_memory(content)
@@ -169,7 +169,7 @@ Most session state is not injected into prompts — fetch it with tools instead:
169
169
  - Be frugal: prefer small precise edits, avoid runaway loops.
170
170
  - **Two failures on the same cause is the signal to change approach, not to try
171
171
  a third time.** Reread the error, list what you have already ruled out, and
172
- then either fix the actual cause or ask_user with what you know: two concrete
172
+ then either fix the actual cause or ask_operator with what you know: two concrete
173
173
  options and the evidence for each. Grinding a third variation of a failing idea
174
174
  is the costliest loop there is, because it looks like progress.
175
175
  - When the operator asks you to remember something, WRITE it with add_memory.
@@ -290,7 +290,7 @@ export class Agent {
290
290
  `would land you here again in a few turns. Change the perspective instead:\n` +
291
291
  `1. Write down what you have LEARNED (add_memory) and what is LEFT (set_todo), so nothing depends on ` +
292
292
  `holding this conversation in your head.\n` +
293
- `2. Name the exact question you cannot answer ("I cannot tell whether X, because Y") and call ask_user with ` +
293
+ `2. Name the exact question you cannot answer ("I cannot tell whether X, because Y") and call ask_operator with ` +
294
294
  `it — or list what you have already ruled out and pick a different mechanism that produces the same evidence.\n` +
295
295
  `3. Choose the SMALLEST next step that produces evidence — one experiment, not a longer version of the same ` +
296
296
  `attempt.\n` +
@@ -321,7 +321,7 @@ export class Agent {
321
321
  * time and task size. Telling it the real percentage each turn costs nothing (this line is already
322
322
  * per-message) and removes the inference.
323
323
  */
324
- return `${clock} · ${usageLine(this.contextSizeForBudgeting(), this.opts.contextTokenBudget)}`;
324
+ return `${clock} · ${usageLine(this.contextSizeForBudgeting(), this.opts.contextTokenBudget, this.opts.contextWindowTokens)}`;
325
325
  }
326
326
  activityChars = 0;
327
327
  turnsSinceProgress = 0;
@@ -1450,8 +1450,10 @@ export class Agent {
1450
1450
  progressRequestedThisRound = false;
1451
1451
  /** the agent called report_progress in this round — a report is not a stop (#215) */
1452
1452
  reportedThisRound = false;
1453
- /** bounded: the forced continue after a report may happen once per round */
1453
+ /** how many forced continues this round has issued (diagnostics only — the bound is on PROGRESS, not on reports) */
1454
1454
  reportedNudges = 0;
1455
+ /** consecutive forced continues that produced no work at all: the model is repeating, not progressing */
1456
+ stalledReportContinues = 0;
1455
1457
  /** the stream was aborted because the model looped on the same characters (#209) */
1456
1458
  degenerateOutput = false;
1457
1459
  degenerateStops = 0;
@@ -1550,19 +1552,35 @@ export class Agent {
1550
1552
  * a running background shell, an audit cap) either logs its own note or leaves no trace. This note makes the
1551
1553
  * decision observable the next time it goes the wrong way.
1552
1554
  */
1553
- if (!finished && this.reportedThisRound && this.reportedNudges >= 1) {
1554
- await this.log.append("system_note", this.currentSession, this.currentBranch, {
1555
- event: "auto-continue-after-progress-skipped",
1556
- reason: "the nudge budget for this round was already spent",
1557
- nudges: this.reportedNudges,
1558
- });
1559
- }
1560
- if (!finished &&
1561
- this.reportedThisRound &&
1562
- this.reportedNudges < 1 &&
1555
+ /**
1556
+ * EVERY report-then-stop is answered — there is no budget.
1557
+ *
1558
+ * "まず上限を設定すべきではなくない? インターバルで発火するprogress要求に対してそれぞれ答えてからちゃんと進んで
1559
+ * いるかっていうのが重要". The interval asks for a report; each answer must be followed by work, and a cap turns
1560
+ * that into "the third interval is ignored". What actually needs guarding is the case where the model answers
1561
+ * and does NOTHING — that is the stall counter below, which measures progress instead of counting reports.
1562
+ */
1563
+ if (!finished && this.reportedThisRound &&
1563
1564
  // a PAUSED goal means the operator parked this agent; forcing another turn would fight that
1564
1565
  this.goal.status !== "paused") {
1565
1566
  this.reportedNudges += 1;
1567
+ this.stalledReportContinues += 1;
1568
+ /**
1569
+ * …, but a model that answers "reported." and does NOTHING must not be pinged for ever.
1570
+ *
1571
+ * This is the guard that belongs here: measure PROGRESS, not reports. Any round that calls a work tool resets
1572
+ * the counter, so a session that reports on each interval and keeps working never trips it; a model repeating
1573
+ * "reported." ends the round with a note instead of spinning (measured without it: 1430 nudges in one round).
1574
+ */
1575
+ if (this.stalledReportContinues > 3) {
1576
+ await this.log.append("system_note", this.currentSession, this.currentBranch, {
1577
+ event: "auto-continue-after-progress-stalled",
1578
+ continues: this.stalledReportContinues,
1579
+ detail: "the model kept reporting progress without doing any work — stopping instead of pinging it again",
1580
+ });
1581
+ this.stalledReportContinues = 0;
1582
+ break;
1583
+ }
1566
1584
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
1567
1585
  event: "auto-continue-after-progress",
1568
1586
  detail: "the round filed a progress report and then stopped — a report is not a stop, so the loop continues",
@@ -1872,7 +1890,7 @@ export class Agent {
1872
1890
  }, null, 1));
1873
1891
  return "next";
1874
1892
  },
1875
- ask_user: async (call, m) => {
1893
+ ask_operator: async (call, m) => {
1876
1894
  const a = safeParse(call.function.arguments);
1877
1895
  const question = String(a.question ?? "").slice(0, 2000);
1878
1896
  const options = Array.isArray(a.options)
@@ -2298,6 +2316,7 @@ export class Agent {
2298
2316
  this.contextClaimNudges = 0;
2299
2317
  this.blockerAsks = 0;
2300
2318
  this.reportedNudges = 0;
2319
+ this.stalledReportContinues = 0;
2301
2320
  /**
2302
2321
  * `reportedThisRound` deliberately SURVIVES work done after the report.
2303
2322
  *
@@ -2334,7 +2353,14 @@ export class Agent {
2334
2353
  await this.answerUnansweredToolCalls(m);
2335
2354
  return finished;
2336
2355
  }
2337
- const meta = this.metaHandlers[call.function.name];
2356
+ /**
2357
+ * `ask_user` is the pre-rename name of `ask_operator` and stays dispatchable.
2358
+ *
2359
+ * One normalization point: a prompt written before the rename, a session resumed mid-call, or an operator's own
2360
+ * note that still says `ask_user` all keep working. The spec advertises only `ask_operator`.
2361
+ */
2362
+ const toolName = call.function.name === "ask_user" ? "ask_operator" : call.function.name;
2363
+ const meta = this.metaHandlers[toolName];
2338
2364
  if (meta) {
2339
2365
  if ((await meta(call, m)) === "end") {
2340
2366
  finished = true;
@@ -3154,7 +3180,7 @@ export class Agent {
3154
3180
  ];
3155
3181
  }
3156
3182
  else {
3157
- noticeLine = usageLine(this.estimateTokens(this.messages.slice(cut)), this.opts.contextTokenBudget);
3183
+ noticeLine = usageLine(this.estimateTokens(this.messages.slice(cut)), this.opts.contextTokenBudget, this.opts.contextWindowTokens);
3158
3184
  /**
3159
3185
  * The usage line is computed ONCE, from the kept tail, and then WRITTEN INTO the compaction event.
3160
3186
  *
@@ -87,13 +87,30 @@ export function claimsContextLimit(text) {
87
87
  * that comment is just "解釈が逆". A number with no direction is a coin flip, so the direction is now a word, and the
88
88
  * remaining room is spelled out in the unit the model actually spends.
89
89
  */
90
- export function usageLine(used, budget) {
90
+ export function usageLine(used, budget, window) {
91
91
  const fmt = (n) => (n >= 1_000 ? `${Math.round(n / 1_000)}k` : String(Math.max(0, Math.round(n))));
92
- if (!Number.isFinite(budget) || budget <= 0)
92
+ /**
93
+ * The percentage is of the WINDOW, and the compaction threshold is stated separately.
94
+ *
95
+ * It used to be `used / budget`, where `budget` is the compaction threshold — so a 900k window that compacts at 750k
96
+ * read as "82% used" at 615k and the denominator was a number the model could not see anywhere else. Reported as
97
+ * "生のサイズじゃなくてcompactボーダーまでにしたのはなぜ? 消費/フルサイズ とcompactまでの残り値にすべきでは?".
98
+ *
99
+ * context 68% used (615k/900k tokens, 135k until compaction)
100
+ *
101
+ * When the window is unknown the budget is the only denominator available, and the line says so by omitting the
102
+ * window entirely rather than pretending they are the same thing.
103
+ */
104
+ const full = Number.isFinite(window) && (window ?? 0) > 0 ? window : 0;
105
+ const denom = full || (Number.isFinite(budget) && budget > 0 ? budget : 0);
106
+ if (!denom)
93
107
  return `context ${fmt(used)} tokens used`;
94
- const pct = Math.max(0, Math.min(100, Math.round((used / budget) * 100)));
95
- const left = Math.max(0, budget - used);
96
- return `context ${pct}% used (${fmt(used)}/${fmt(budget)} tokens, ${fmt(left)} until compaction)`;
108
+ const pct = Math.max(0, Math.min(100, Math.round((used / denom) * 100)));
109
+ const until = Number.isFinite(budget) && budget > 0 ? Math.max(0, budget - used) : null;
110
+ const size = full ? `${fmt(used)}/${fmt(full)} tokens` : `${fmt(used)}/${fmt(budget)} tokens (compaction threshold; full window unknown)`;
111
+ return until === null
112
+ ? `context ${pct}% used (${size})`
113
+ : `context ${pct}% used (${size}, ${fmt(until)} until compaction)`;
97
114
  }
98
115
  /**
99
116
  * …and the OTHER thing that gets reported as "context is exhausted": the model has run out of its own ideas.
@@ -101,7 +118,7 @@ export function usageLine(used, budget) {
101
118
  * "コンテキストが尽きたっていうのがコンテキストウィンドウが尽きたと勘違いしてるパターンと、自力の推論の限界に達した
102
119
  * 場合がありそう" — two different problems with different answers. The window case is false and gets corrected with
103
120
  * numbers; being STUCK is real, and telling the model to continue would just spin. What a stuck agent needs is to
104
- * name the question it cannot answer and hand it over (ask_user) or change angle — not another turn of the same.
121
+ * name the question it cannot answer and hand it over (ask_operator) or change angle — not another turn of the same.
105
122
  */
106
123
  const OWN_LIMIT_PATTERNS = [
107
124
  /(?:reasoning|analysis|own) (?:limit|limits|capacity)s?\b/i,
@@ -62,11 +62,19 @@ export const META_TOOLS = [
62
62
  },
63
63
  },
64
64
  {
65
- name: "ask_user",
65
+ /**
66
+ * `ask_operator`, not `ask_user`.
67
+ *
68
+ * "モデルがreasoningでoperatorってよく使うから多分そっちのほうがいい" — and the whole system prompt already says
69
+ * "operator" everywhere, so the tool name disagreed with the vocabulary the model is reading. The old name stays
70
+ * DISPATCHABLE (see `TOOL_ALIASES`) so a prompt written before the rename, or a session resumed mid-call, still
71
+ * works; it is simply no longer advertised.
72
+ */
73
+ name: "ask_operator",
66
74
  spec: {
67
75
  type: "function",
68
76
  function: {
69
- name: "ask_user",
77
+ name: "ask_operator",
70
78
  description: "Pause and ask the operator a question — plan confirmation, ambiguous requirements, " +
71
79
  "a decision only they can make. The loop parks until they reply; their message arrives " +
72
80
  "as your next user turn. Use sparingly: do your homework first, then ask once, concretely.",
@@ -1778,7 +1778,7 @@ export const TOOLS = [
1778
1778
  {
1779
1779
  name: "message_agent",
1780
1780
  description: "Send a message to another agent. Use it to steer a sub-agent mid-flight, to answer its " +
1781
- "ask_user question, or to message your OWN PARENT (pass its id) — a sub-agent may ask its " +
1781
+ "ask_operator question, or to message your OWN PARENT (pass its id) — a sub-agent may ask its " +
1782
1782
  "parent a question or hand back a partial result, which is how you report progress without " +
1783
1783
  "ending your turn. You may NOT message a sibling or an unrelated agent.",
1784
1784
  parameters: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.157",
3
+ "version": "0.37.159",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",