teapot-coding-agent 0.37.108 → 0.37.110

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.
@@ -5,7 +5,7 @@ import { storeImage, resolveImages } from "../log/image-store.js";
5
5
  import { chat, chatStream } from "./llm.js";
6
6
  import { auditPrompt, parseAuditVerdict } from "./goal-audit.js";
7
7
  import { createCatalog } from "./tool-catalog.js";
8
- import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShells, hasRunningBgShellsFor, killBgShells } from "./tools.js";
8
+ import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShells, hasRunningBgShellsFor, killBgShells, runningBgShellCount } from "./tools.js";
9
9
  import { effortChoosable } from "./llm.js";
10
10
  import { mcp } from "./mcp-registry.js";
11
11
  import { flattenToolName } from "./mcp-registry.js";
@@ -304,6 +304,7 @@ export class Agent {
304
304
  onIdleUnpark: () => this.unparkFromTool(),
305
305
  hasPendingPrompts: () => this.pendingPrompts.length > 0,
306
306
  onBackgroundExit: (info) => void this.onBackgroundJobExit(info),
307
+ onBackgroundStart: () => this.emitSnapshotUpdate(),
307
308
  onFileRead: (p) => this.trackFileRead(p),
308
309
  };
309
310
  this.mainSession = path.basename(opts.sessionDir);
@@ -475,7 +476,17 @@ export class Agent {
475
476
  trackFileRead(p) {
476
477
  this.recentReads = [p, ...this.recentReads.filter((x) => x !== p)].slice(0, 5);
477
478
  }
479
+ /**
480
+ * Push a fresh snapshot to the UI.
481
+ *
482
+ * `agent-update` is the only carrier of `bgRunning`, and it previously came from session-title writes only.
483
+ * Cheap: the snapshot is what the browser replaces on the other end anyway.
484
+ */
485
+ emitSnapshotUpdate() {
486
+ bus.emit("update", { kind: "agent-update", agentId: this.opts.id });
487
+ }
478
488
  onBackgroundJobExit(info) {
489
+ this.emitSnapshotUpdate();
479
490
  const ok = info.code === 0;
480
491
  const one = info.cmd.replace(/\s+/g, " ").slice(0, 80);
481
492
  void this.log.append("system_note", this.currentSession, this.currentBranch, {
@@ -1085,6 +1096,8 @@ export class Agent {
1085
1096
  live: this.isLive(),
1086
1097
  workspace: this.workspace,
1087
1098
  workspaceMissing: this.isGhost,
1099
+ // live count for the header badge — see runningBgShellCount (#197)
1100
+ bgRunning: runningBgShellCount(this.workspace),
1088
1101
  session: this.currentSession,
1089
1102
  ...(title ? { sessionTitle: title } : {}),
1090
1103
  branch: this.currentBranch,
@@ -296,6 +296,14 @@ function startBackgroundShell(cmd, ctx) {
296
296
  child.on("exit", (code) => notify(code));
297
297
  child.on("close", (code) => notify(code));
298
298
  map.set(id, sh);
299
+ /**
300
+ * Tell the UI the count changed.
301
+ *
302
+ * The header badge reads `bgRunning` off the agent snapshot, and a snapshot only reaches the browser on an
303
+ * `agent-update` — which nothing emitted when a job started or finished, so the badge was right only after
304
+ * an unrelated update happened to arrive (#197 "クリックしないと値更新されなかった").
305
+ */
306
+ ctx.onBackgroundStart?.(id);
299
307
  return id;
300
308
  }
301
309
  export function isContextOverflow(err) {
@@ -376,6 +384,28 @@ export function killBgShell(cwd, id, stateDir) {
376
384
  }
377
385
  return false;
378
386
  }
387
+ /**
388
+ * How many background shells are running in this workspace right now.
389
+ *
390
+ * The header badge used to be fetched only when it was CLICKED, so the count was whatever it had been at the
391
+ * last click — "クリックしないと値更新されなかった" (#197). It now rides on the agent snapshot, which is pushed
392
+ * on every update, so there is nothing to fetch and nothing to go stale.
393
+ */
394
+ export function runningBgShellCount(cwd) {
395
+ const m = bgShellsByWs.get(cwd);
396
+ if (!m)
397
+ return 0;
398
+ let n = 0;
399
+ for (const sh of m.values()) {
400
+ if (sh.exited && Date.now() - sh.startedAt > 30 * 60_000) {
401
+ m.delete(sh.id);
402
+ continue;
403
+ }
404
+ if (!sh.exited)
405
+ n++;
406
+ }
407
+ return n;
408
+ }
379
409
  export function hasRunningBgShells(cwd) {
380
410
  const m = bgShellsByWs.get(cwd);
381
411
  if (!m)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.108",
3
+ "version": "0.37.110",
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",