teapot-coding-agent 0.37.158 → 0.37.160

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.
@@ -245,6 +245,15 @@ export class Agent {
245
245
  pendingSubReport = "";
246
246
  compactPhase = "";
247
247
  awaitingUser = false;
248
+ /**
249
+ * The event id of the question the loop is parked on.
250
+ *
251
+ * The status says `needs_operator`, but the ROW lives in the log and the client only holds the last page of events — so
252
+ * a question that was asked before that window was invisible until the operator scrolled far enough:
253
+ * "タイムラインにask_userが出てないのにneeds_operatorが出てる / しばらくいじいじしてたら出てきた". The id lets the client
254
+ * fetch the page that contains it.
255
+ */
256
+ pendingQuestionId = "";
248
257
  /** when the previous round finished, for the time anchor in harness messages (#194) */
249
258
  lastTurnEndedAt = null;
250
259
  /** the last assistant text, so the loop can tell a context-limit stop from a real one (#201) */
@@ -290,7 +299,7 @@ export class Agent {
290
299
  `would land you here again in a few turns. Change the perspective instead:\n` +
291
300
  `1. Write down what you have LEARNED (add_memory) and what is LEFT (set_todo), so nothing depends on ` +
292
301
  `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 ` +
302
+ `2. Name the exact question you cannot answer ("I cannot tell whether X, because Y") and call ask_operator with ` +
294
303
  `it — or list what you have already ruled out and pick a different mechanism that produces the same evidence.\n` +
295
304
  `3. Choose the SMALLEST next step that produces evidence — one experiment, not a longer version of the same ` +
296
305
  `attempt.\n` +
@@ -321,7 +330,7 @@ export class Agent {
321
330
  * time and task size. Telling it the real percentage each turn costs nothing (this line is already
322
331
  * per-message) and removes the inference.
323
332
  */
324
- return `${clock} · ${usageLine(this.contextSizeForBudgeting(), this.opts.contextTokenBudget)}`;
333
+ return `${clock} · ${usageLine(this.contextSizeForBudgeting(), this.opts.contextTokenBudget, this.opts.contextWindowTokens)}`;
325
334
  }
326
335
  activityChars = 0;
327
336
  turnsSinceProgress = 0;
@@ -1260,6 +1269,7 @@ export class Agent {
1260
1269
  todo: this.todo.slice(0, 32_000),
1261
1270
  parent: this.opts.parent,
1262
1271
  awaiting: this.awaitingUser,
1272
+ ...(this.awaitingUser && this.pendingQuestionId ? { pendingQuestionId: this.pendingQuestionId } : {}),
1263
1273
  autoContinue: this.opts.autoContinue,
1264
1274
  autoCompact: this.opts.autoCompact,
1265
1275
  };
@@ -1890,7 +1900,7 @@ export class Agent {
1890
1900
  }, null, 1));
1891
1901
  return "next";
1892
1902
  },
1893
- ask_user: async (call, m) => {
1903
+ ask_operator: async (call, m) => {
1894
1904
  const a = safeParse(call.function.arguments);
1895
1905
  const question = String(a.question ?? "").slice(0, 2000);
1896
1906
  const options = Array.isArray(a.options)
@@ -1909,11 +1919,12 @@ export class Agent {
1909
1919
  })
1910
1920
  .filter((o) => o.trim())
1911
1921
  : [];
1912
- await this.log.append("question", this.currentSession, this.currentBranch, {
1922
+ const questionEvent = await this.log.append("question", this.currentSession, this.currentBranch, {
1913
1923
  question,
1914
1924
  options,
1915
1925
  callId: call.id,
1916
1926
  });
1927
+ this.pendingQuestionId = questionEvent?.id ?? "";
1917
1928
  await this.answerMeta(call, "question shown to the operator — the loop is parked until they reply. " +
1918
1929
  "Their reply (possibly free text, not one of the options) arrives as your next user message.");
1919
1930
  this.awaitingUser = true;
@@ -2353,7 +2364,14 @@ export class Agent {
2353
2364
  await this.answerUnansweredToolCalls(m);
2354
2365
  return finished;
2355
2366
  }
2356
- const meta = this.metaHandlers[call.function.name];
2367
+ /**
2368
+ * `ask_user` is the pre-rename name of `ask_operator` and stays dispatchable.
2369
+ *
2370
+ * One normalization point: a prompt written before the rename, a session resumed mid-call, or an operator's own
2371
+ * note that still says `ask_user` all keep working. The spec advertises only `ask_operator`.
2372
+ */
2373
+ const toolName = call.function.name === "ask_user" ? "ask_operator" : call.function.name;
2374
+ const meta = this.metaHandlers[toolName];
2357
2375
  if (meta) {
2358
2376
  if ((await meta(call, m)) === "end") {
2359
2377
  finished = true;
@@ -3173,7 +3191,7 @@ export class Agent {
3173
3191
  ];
3174
3192
  }
3175
3193
  else {
3176
- noticeLine = usageLine(this.estimateTokens(this.messages.slice(cut)), this.opts.contextTokenBudget);
3194
+ noticeLine = usageLine(this.estimateTokens(this.messages.slice(cut)), this.opts.contextTokenBudget, this.opts.contextWindowTokens);
3177
3195
  /**
3178
3196
  * The usage line is computed ONCE, from the kept tail, and then WRITTEN INTO the compaction event.
3179
3197
  *
@@ -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.158",
3
+ "version": "0.37.160",
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",