teapot-coding-agent 0.37.186 → 0.37.188

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.
@@ -256,13 +256,17 @@ export class Agent {
256
256
  return 0;
257
257
  const queuedAhead = idx;
258
258
  /**
259
- * What BLOCKS dispatch, not just "is a turn running".
259
+ * "Queued" means ONE thing: the agent is generating a turn right now.
260
260
  *
261
- * MEASURED: during a compaction the status is `waiting`, and a compaction runs on the same chain, so a prompt
262
- * enqueued then cannot start — but `ahead` said 0 (nothing ahead, no turn running) and the row showed a timestamp:
263
- * "queuedのメッセージの1つ目が queued じゃなくて時刻が表示される". A parked tool call blocks the same way.
261
+ * The operator's contract, stated after the third round of this bug: `idle`, `waiting`, `error`, `needs_operator`,
262
+ * `stopped` — and `running` while it is NOT between LLM calls — all take the prompt immediately and must render as
263
+ * SETTLED; only `running` with a turn in flight makes it wait, and only then does the row say "queued…" and the badge
264
+ * count it.
265
+ *
266
+ * An earlier version also treated `waiting` (a compaction) and a parked tool as blocking, which made those states show
267
+ * "queued…" — and the operator's answer to that was the list above.
264
268
  */
265
- const blocked = this.status === "running" || this.status === "waiting" || this.parkedByTool;
269
+ const blocked = this.status === "running";
266
270
  return queuedAhead + (queuedAhead === 0 && blocked ? 1 : 0);
267
271
  }
268
272
  stopRequested = false;
@@ -1125,23 +1129,56 @@ export class Agent {
1125
1129
  this.bgExits = [];
1126
1130
  }
1127
1131
  }
1132
+ /**
1133
+ * goal.md is `body` + a metadata block, and the block is found by POSITION-INDEPENDENT parsing.
1134
+ *
1135
+ * The reader used to strip `status:`/`updated:` only when they sat at the very END. The writer appends `verify:` AFTER
1136
+ * them, so on any goal with a verification contract the strip loop could not remove anything and the metadata lines
1137
+ * became part of the goal TEXT — reported as "セッションリストアするとgoalが汚染される" with a goal that ended in
1138
+ * `status: paused / updated: …` (#253).
1139
+ *
1140
+ * The block is the LAST run of metadata lines in the file: find the last `status:` line and keep it only if everything
1141
+ * after it is metadata (`updated:`, `verify:` and the contract's own lines). A goal whose prose mentions "status:" stays
1142
+ * intact, because prose is not followed by an `updated:` line.
1143
+ */
1128
1144
  parseGoalFile(text) {
1129
- const all = [...text.matchAll(/status:\s*(\w+)/gi)];
1130
- const last = all[all.length - 1]?.[1];
1131
- const status = last === "done" ? "done" : last === "paused" ? "paused" : "active";
1132
- let body = text.trim();
1133
- for (let i = 0; i < 4; i++) {
1134
- const stripped = body.replace(/\n+(?:status|updated):[^\n]*$/i, "").trimEnd();
1135
- if (stripped === body)
1145
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
1146
+ let blockAt = -1;
1147
+ for (let i = lines.length - 1; i >= 0; i--) {
1148
+ if (/^status:\s*\w+\s*$/i.test(lines[i])) {
1149
+ // everything below must be metadata, or this "status:" belongs to the prose
1150
+ let ok = true;
1151
+ let inVerify = false;
1152
+ for (let j = i + 1; j < lines.length; j++) {
1153
+ const l = lines[j];
1154
+ if (!l.trim())
1155
+ continue;
1156
+ if (/^verify:/i.test(l)) {
1157
+ inVerify = true; // the contract's own lines are arbitrary text
1158
+ continue;
1159
+ }
1160
+ if (inVerify)
1161
+ continue;
1162
+ if (/^(updated|status):/i.test(l))
1163
+ continue;
1164
+ ok = false;
1165
+ break;
1166
+ }
1167
+ if (ok)
1168
+ blockAt = i;
1136
1169
  break;
1137
- body = stripped;
1170
+ }
1138
1171
  }
1172
+ const bodyLines = blockAt === -1 ? lines : lines.slice(0, blockAt);
1173
+ const meta = blockAt === -1 ? [] : lines.slice(blockAt);
1174
+ const metaText = meta.join("\n");
1175
+ const statusWord = /status:\s*(\w+)/i.exec(metaText)?.[1]?.toLowerCase();
1176
+ const status = statusWord === "done" ? "done" : statusWord === "paused" ? "paused" : "active";
1177
+ let body = bodyLines.join("\n").trimEnd();
1139
1178
  let verify = "";
1140
- const vm = body.match(/\nverify:\s*\n([\s\S]+)$/i) ?? body.match(/^verify:\s*(.+)$/im);
1141
- if (vm) {
1179
+ const vm = /\nverify:\s*\n([\s\S]+)$/i.exec(metaText) ?? /^verify:\s*(.+)$/im.exec(metaText);
1180
+ if (vm)
1142
1181
  verify = vm[1].trim();
1143
- body = (body.slice(0, vm.index).trimEnd());
1144
- }
1145
1182
  const out = { text: body, status, updatedAt: new Date().toISOString() };
1146
1183
  if (verify)
1147
1184
  out.verify = verify;
@@ -116,29 +116,32 @@ export function claimsContextLimit(text) {
116
116
  export function usageLine(used, budget, window) {
117
117
  const fmt = (n) => (n >= 1_000 ? `${Math.round(n / 1_000)}k` : String(Math.max(0, Math.round(n))));
118
118
  /**
119
- * The percentage is of the WINDOW, and the compaction threshold is stated separately.
119
+ * EVERY number, named once.
120
120
  *
121
- * It used to be `used / budget`, where `budget` is the compaction threshold — so a 900k window that compacts at 750k
122
- * read as "82% used" at 615k and the denominator was a number the model could not see anywhere else. Reported as
123
- * "生のサイズじゃなくてcompactボーダーまでにしたのはなぜ? 消費/フルサイズ とcompactまでの残り値にすべきでは?".
121
+ * The line used to mix two denominators without naming either: the percentage was of the WINDOW while "until
122
+ * auto-compaction" was measured from the BUDGET (the compaction threshold). A model reading
123
+ * "context 1% used (15k/1000k tokens, 735k until compaction)" had three different numbers in front of it and concluded it
124
+ * could not tell what they meant — "compact後のコンテキストウィンドウ残量報告が間違っている?" (#249). So the line states the
125
+ * percentage with its window, the threshold as its own figure, and the room left before that threshold:
124
126
  *
125
- * context 68% used (615k/900k tokens, 135k until auto-compaction)
126
- *
127
- * When the window is unknown the budget is the only denominator available, and the line says so by omitting the
128
- * window entirely rather than pretending they are the same thing.
127
+ * context 1% used (15k/1000k tokens) · auto-compacts at 750k · 735k until auto-compaction
128
+ *
129
+ * When the window is unknown the budget is the only denominator there is, and the line says so rather than pretending.
129
130
  */
130
131
  const full = Number.isFinite(window) && (window ?? 0) > 0 ? window : 0;
131
- const denom = full || (Number.isFinite(budget) && budget > 0 ? budget : 0);
132
+ const hasBudget = Number.isFinite(budget) && budget > 0;
133
+ const denom = full || (hasBudget ? budget : 0);
132
134
  if (!denom)
133
135
  return `context ${fmt(used)} tokens used`;
134
136
  const pct = Math.max(0, Math.min(100, Math.round((used / denom) * 100)));
135
- const until = Number.isFinite(budget) && budget > 0 ? Math.max(0, budget - used) : null;
136
- const size = full ? `${fmt(used)}/${fmt(full)} tokens` : `${fmt(used)}/${fmt(budget)} tokens (compaction threshold; full window unknown)`;
137
- return until === null
138
- ? `context ${pct}% used (${size})`
139
- // "until auto-compaction" — the mechanism that acts on this number is automatic; plain "compaction" read as
140
- // something the model had to trigger itself
141
- : `context ${pct}% used (${size}, ${fmt(until)} until auto-compaction)`;
137
+ const size = full
138
+ ? `${fmt(used)}/${fmt(full)} tokens`
139
+ : `${fmt(used)}/${fmt(budget)} tokens — the compaction threshold; full window unknown`;
140
+ if (!hasBudget)
141
+ return `context ${pct}% used (${size})`;
142
+ const until = Math.max(0, budget - used);
143
+ const threshold = full ? ` · auto-compacts at ${fmt(budget)}` : "";
144
+ return `context ${pct}% used (${size})${threshold} · ${fmt(until)} until auto-compaction`;
142
145
  }
143
146
  /**
144
147
  * …and the OTHER thing that gets reported as "context is exhausted": the model has run out of its own ideas.
@@ -19,10 +19,27 @@ export class McpRegistry {
19
19
  auths = new Map();
20
20
  store = null;
21
21
  flows = new Map();
22
+ /**
23
+ * A counter that changes whenever the tool set can have changed.
24
+ *
25
+ * The deferred catalogue (`search_tools`/`run_tool`) is cached per ToolContext, and a cache keyed only by that context
26
+ * cannot see the registry change underneath it: after re-authorising a server the tools were populated here but
27
+ * `search_tools` kept serving the catalogue built before the grant — "MCP再認証してもsearch_toolsで出てこない、叩けない"
28
+ * (#243). A version is the smallest thing the cache can compare.
29
+ */
30
+ version = 0;
31
+ /** the current tool-set version; see `version` */
32
+ stateVersion() {
33
+ return this.version;
34
+ }
35
+ bump() {
36
+ this.version++;
37
+ }
22
38
  init(dataDir) {
23
39
  this.store = new McpAuthStore(dataDir);
24
40
  }
25
41
  apply(configs) {
42
+ this.bump();
26
43
  const wanted = new Set(configs.map((c) => c.name));
27
44
  for (const [name, st] of this.servers) {
28
45
  if (!wanted.has(name)) {
@@ -59,6 +76,7 @@ export class McpRegistry {
59
76
  return this.servers.get(name);
60
77
  }
61
78
  recordSuccess(name, tools) {
79
+ this.bump();
62
80
  const st = this.servers.get(name);
63
81
  if (!st)
64
82
  return;
@@ -226,6 +244,7 @@ export class McpRegistry {
226
244
  const conn = await connectMcp(st.config, { provider: auth });
227
245
  st.connection = conn;
228
246
  st.tools = await conn.tools();
247
+ this.bump();
229
248
  st.status = "connected";
230
249
  st.oauthRequired = false;
231
250
  await this.finishFlow(name, pending);
@@ -251,6 +270,7 @@ export class McpRegistry {
251
270
  await conn.close().catch(() => { });
252
271
  st.connection = live;
253
272
  st.tools = await live.tools();
273
+ this.bump();
254
274
  st.status = "connected";
255
275
  st.oauthRequired = false;
256
276
  st.lastError = undefined;
@@ -2236,20 +2236,21 @@ export function repairToolInput(name, rawArgs) {
2236
2236
  */
2237
2237
  const catalogs = new WeakMap();
2238
2238
  function catalogFor(ctx) {
2239
- let c = catalogs.get(ctx);
2240
- if (!c) {
2241
- c = createCatalog(mcp.states().map((st) => ({
2242
- id: st.config.name,
2243
- name: st.config.name,
2244
- description: st.config.description,
2245
- enabled: st.status !== "disabled",
2246
- status: st.status,
2247
- tools: st.tools ?? [],
2248
- })),
2249
- // the built-ins are already in the request, so the catalog must know how much room is left
2250
- { builtInCount: TOOLS.length });
2251
- catalogs.set(ctx, c);
2252
- }
2239
+ const version = mcp.stateVersion();
2240
+ const hit = catalogs.get(ctx);
2241
+ if (hit && hit.version === version)
2242
+ return hit.catalog;
2243
+ const c = createCatalog(mcp.states().map((st) => ({
2244
+ id: st.config.name,
2245
+ name: st.config.name,
2246
+ description: st.config.description,
2247
+ enabled: st.status !== "disabled",
2248
+ status: st.status,
2249
+ tools: st.tools ?? [],
2250
+ })),
2251
+ // the built-ins are already in the request, so the catalog must know how much room is left
2252
+ { builtInCount: TOOLS.length });
2253
+ catalogs.set(ctx, { version, catalog: c });
2253
2254
  return c;
2254
2255
  }
2255
2256
  /** called at a turn boundary so each turn starts with nothing discovered */
package/dist/master.js CHANGED
@@ -750,13 +750,19 @@ export class Master {
750
750
  if (!parent)
751
751
  return;
752
752
  this.wakeAncestorWaiters(ac.parent);
753
- if (this.reportedRunning.has(agentId) && SETTLED.has(status))
753
+ /**
754
+ * An `error` child is NOT announced twice.
755
+ *
756
+ * The child's own `error` event already reaches the parent as "Sub-agent X hit an error: …" (see `onChildEvent`),
757
+ * so the generic "settled without having called finish()" note only repeated it with weaker wording — reported as
758
+ * "サブエージェントがエラー落ちしたときの親への通知がびみょい" (#245). The generic note exists for statuses that have
759
+ * no event of their own (`idle`, `stopped`, `waiting`).
760
+ */
761
+ if (this.reportedRunning.has(agentId) && SETTLED.has(status) && status !== "error")
754
762
  parent.enqueuePrompt(`[harness] Sub-agent @${agentId} is now ${status} without having called finish(), so it has not reported a result.` +
755
- (status === "error"
756
- ? ` Check its last output before deciding whether to re-spawn it.`
757
- : status === "stopped"
758
- ? ` It may have been stopped mid-task; message it to resume, or re-spawn it.`
759
- : ` If you expected a result, message it or re-spawn it.`), "harness");
763
+ (status === "stopped"
764
+ ? ` It may have been stopped mid-task; message it to resume, or re-spawn it.`
765
+ : ` If you expected a result, message it or re-spawn it.`), "harness");
760
766
  if (status === "running")
761
767
  this.reportedRunning.add(agentId);
762
768
  else if (SETTLED.has(status))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.186",
3
+ "version": "0.37.188",
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",