teapot-coding-agent 0.31.0 → 0.31.2

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.
@@ -10,7 +10,7 @@ import { promises as fs, existsSync, readFileSync, readdirSync, statSync } from
10
10
  import path from "node:path";
11
11
  import { EventLog, readEvents } from "../log/events.js";
12
12
  import { chat, chatStream } from "./llm.js";
13
- import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, hasRunningBgShells, killBgShells } from "./tools.js";
13
+ import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, hasRunningBgShells, hasRunningBgShellsFor, killBgShells } from "./tools.js";
14
14
  import { effortChoosable } from "./llm.js";
15
15
  import { sessionTitleFrom } from "../session-title.js";
16
16
  import { mcp } from "./mcp-registry.js";
@@ -542,6 +542,9 @@ export class Agent {
542
542
  ];
543
543
  this.toolCtx = {
544
544
  cwd: opts.workspace,
545
+ // so a background job records WHICH agent started it: sibling agents share a workspace,
546
+ // and `isLive()` must not count their jobs as this one's work in flight
547
+ agentId: opts.id,
545
548
  defaultTimeoutMs: 120_000,
546
549
  maxOutputBytes: 60_000,
547
550
  skillRoots: this.skillRoots,
@@ -799,7 +802,15 @@ export class Agent {
799
802
  // the operator most needs to stop. Note this is checked AFTER stopRequested:
800
803
  // once stopped, the jobs are already dead, so `live` must go false or the
801
804
  // button would offer stop forever (#133).
802
- hasRunningBgShells(this.toolCtx.cwd) ||
805
+ // OWNER-SCOPED, not directory-scoped. Sub-agents inherit their parent's workspace, so
806
+ // asking "does this DIRECTORY have background shells?" made every stopped sibling of a
807
+ // busy agent report `live: true`. MEASURED: four STOPPED sub-agents in one workspace
808
+ // showed `· ▶4` in the sidebar because the parent had background jobs, and their stop
809
+ // buttons offered to stop work that was already gone.
810
+ //
811
+ // `hasRunningBgShells(cwd)` is still the right question where the caller wants the
812
+ // DIRECTORY (parking a round, killing a workspace's jobs) — just not for `isLive()`.
813
+ hasRunningBgShellsFor(this.toolCtx.cwd, this.opts.id) ||
803
814
  // ask_user: the loop is parked on the operator's answer — stoppable work
804
815
  // in flight, not idleness. Without this the UI offered "start", and
805
816
  // pressing it cleared awaitingUser, silently discarding the open question
@@ -239,6 +239,7 @@ function startBackgroundShell(cmd, ctx) {
239
239
  id, cmd, child,
240
240
  out: "", truncated: false,
241
241
  startedAt: Date.now(), exited: false, code: null,
242
+ owner: ctx.agentId ?? "",
242
243
  };
243
244
  const collect = (chunk) => {
244
245
  if (sh.out.length < 200_000)
@@ -319,6 +320,30 @@ export function hasRunningBgShells(cwd) {
319
320
  }
320
321
  return false;
321
322
  }
323
+ /**
324
+ * Does THIS agent have a background job still running?
325
+ *
326
+ * `hasRunningBgShells(cwd)` answers for a DIRECTORY, which is the right question for
327
+ * `killBgShells` and the wrong one for "is this agent busy". Sub-agents inherit their parent's
328
+ * workspace, so a shared directory made every sibling of a busy agent report `live: true` —
329
+ * MEASURED: four STOPPED sub-agents showed `· ▶4` because the parent had background jobs, and
330
+ * their stop buttons offered to stop work that was already gone.
331
+ *
332
+ * An empty owner means a job started before owners were recorded; those are treated as
333
+ * belonging to nobody, so they cannot make an unrelated agent look busy.
334
+ */
335
+ export function hasRunningBgShellsFor(cwd, owner) {
336
+ const m = bgShellsByWs.get(cwd);
337
+ if (!m || !owner)
338
+ return false;
339
+ for (const sh of m.values()) {
340
+ if (sh.exited)
341
+ continue;
342
+ if (sh.owner === owner)
343
+ return true;
344
+ }
345
+ return false;
346
+ }
322
347
  /**
323
348
  * Kill every background shell for one workspace and forget the jobs (#158).
324
349
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
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",