aiterm-mcp 0.70.41 → 0.70.42

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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.70.42] - 2026-11-13
11
+
12
+ - `pty_list` `aiterm/seat_turns` rows carry `own_work` when the caller sends `_meta["aiterm/own_work_exclusions"]` (a41; Kiro, Owner-approved design 2026-11-13): `{processes, excluded, child_results, exclusions_digest, oldest}` beside `turn`. `processes` are the processes the seat's CLI started after startup and still runs (the same set as `post_startup_process_count`), minus those a process entry of the caller's list names for this seat (exe + leading args, with the match's descendants and post-startup ancestors); `oldest` is the oldest one's descriptor and start time. Descriptors are built where the process runs and never carry raw argv: program basename, first two non-flag arguments as basenames, and any token over 40 characters or containing `=`, `://` or `@` becomes `…` (on macOS arguments are split on whitespace). One process-table read per call; terminals compute their own rows inside the relayed read.
13
+ - A seat no longer waits forever for child results it does not own. `pending_child_deliveries` (and `own_work.child_results`) count an unfinished delivery for the parent seat the child names, not for whichever process adopted the dead owner's records (Kiro, 2026-11-13: a seat running the execution server read 4 adopted deliveries of another seat and could never hibernate or close). A delivery whose local child was replaced, removed, hibernated or vanished now ends after two readings 30 s apart with `AGENT_RESULT_UNAVAILABLE: PARENT_DELIVERY_CHILD_GONE: <reason>`, delivered to its parent; before, the wait never ended.
14
+
10
15
  ## [0.70.41] - 2026-11-13
11
16
 
12
17
  - Antigravity CLI 1.5.7 seats start again. agy 1.5.7 draws a mode hint in the empty composer (`> Auto mode: edits & safe commands auto-approved (shift+tab to cycle)`, also Accept-edits, Plan and Best-of-N), and Aiterm accepted only a bare `>` line as the empty composer, so every `agent_launch` ended `AGENT_STARTUP_BLOCKED vendor_state_unknown` (Kiro, 2026-11-13; container agy replaced 2026-11-12 23:38 UTC). The empty composer is now the footer plus a bare `>` line or exactly such a hint line (also when it wraps at the pane edge); a typed draft still reads as not empty.
@@ -3383,7 +3388,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
3383
3388
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
3384
3389
  provenance.
3385
3390
 
3386
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.41...HEAD
3391
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.42...HEAD
3392
+ [0.70.42]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.41...v0.70.42
3387
3393
  [0.70.41]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.40...v0.70.41
3388
3394
  [0.70.40]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.39...v0.70.40
3389
3395
  [0.70.39]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.38...v0.70.39
package/README.ja.md CHANGED
@@ -215,7 +215,7 @@ runtime-error store は canonical dotagents config の `collection.enabled: true
215
215
  場合だけ収集し、既定OFF、network送信は行いません。tag起点CIのnpm provenance(OIDC Trusted
216
216
  Publishing)で公開し、GitHub Release が Official MCP Registry を再登録します。
217
217
 
218
- **状態:** 開発継続中 · 現行公開版 **v0.70.41** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
218
+ **状態:** 開発継続中 · 現行公開版 **v0.70.42** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
219
219
 
220
220
  ### 更新と巻き戻し
221
221
 
package/README.md CHANGED
@@ -227,7 +227,7 @@ collection is off by default and performs no network I/O. It ships via
227
227
  tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
228
228
  Release re-registers the Official MCP Registry entry.
229
229
 
230
- **Status:** actively maintained · current public release **v0.70.41** · runs on Linux · WSL2 · macOS · native Windows (tmux on POSIX, the tmux-CLI-compatible [psmux](https://github.com/psmux/psmux) on native Windows — no WSL required) · MIT · see the [CHANGELOG](CHANGELOG.md).
230
+ **Status:** actively maintained · current public release **v0.70.42** · runs on Linux · WSL2 · macOS · native Windows (tmux on POSIX, the tmux-CLI-compatible [psmux](https://github.com/psmux/psmux) on native Windows — no WSL required) · MIT · see the [CHANGELOG](CHANGELOG.md).
231
231
 
232
232
  ### Update and rollback
233
233
 
package/dist/core.js CHANGED
@@ -23,6 +23,7 @@ import { withManagedSpan, observeManagedSpan, closeManagedSpan, SPAN_HELD } from
23
23
  */
24
24
  import { spawnSync } from "node:child_process";
25
25
  import * as fs from "node:fs";
26
+ import { z } from "zod";
26
27
  import * as path from "node:path";
27
28
  import { createHash, randomBytes } from "node:crypto";
28
29
  import { launchEnvValue } from "./private-env.js";
@@ -50,7 +51,7 @@ import { readExecutionParentProcess } from "./execution-parent-process.js";
50
51
  import { isCursorMcpClient } from "aiterm-steer-delivery";
51
52
  import { antigravityBinding, antigravityAuthChoiceKey, antigravityCurrentModel, antigravityStartupAction, antigravityAgentArgv, writeAntigravityCallerFiles, checkAntigravityCallerInput, antigravityPromptWithCaller, antigravityQuotaLimit, antigravityModelChoices, antigravityAuthStatus, antigravityAuthPane, antigravityTranscriptText, bindAntigravitySession, createAntigravityAgentMetadata, mergeAntigravityHooks } from "./harnesses/antigravity.js";
52
53
  import { paneTokenHint } from "./harnesses/pane-tokens.js";
53
- import { unfinishedDeliveriesOwnedBy } from "./parent-delivery-owners.js";
54
+ import { pendingChildResultsFor } from "./parent-delivery-owners.js";
54
55
  import { readLinuxProcessRegistrationIdentity, readClaudeRegistrationIdentity, readProcessEnvironment, readRuntimeProcesses, readRuntimeProcessesShared, readProcessIdentities, processSubtree, parentProcess, processIdentity, signalRuntimeProcess, backgroundProcesses, lazyRelayProcess, aitermProcessProbe, windowsConsoleHost, macKeepAwakeProcess, processElapsedSeconds } from "./process-runtime.js";
55
56
  import { liveNodeExecutable } from "./live-node.js";
56
57
  import { resolveClaudeConfigurationRoot, withClaudeConfigRoot, withClaudeSlotLogin } from "./claude-config-root.js";
@@ -1625,6 +1626,10 @@ export function startupProcessShapes(identities, rows) {
1625
1626
  // 控えの物が終了していて、同じ親の下に同じargvで立ったprocessは、その立て直しとして数えない。
1626
1627
  // 親も立て直されている時は、立て直された親の下を見る。終了した控え1つにつき、数えないのは1つまで。
1627
1628
  export function postStartupProcessCount(kind, activityRows, rows, startup, shapes = [], harness) {
1629
+ return postStartupProcesses(kind, activityRows, rows, startup, shapes, harness).length;
1630
+ }
1631
+ /** The processes postStartupProcessCount counts (own_work, a41). */
1632
+ export function postStartupProcesses(kind, activityRows, rows, startup, shapes = [], harness) {
1628
1633
  const byPid = new Map(rows.map(row => [row.pid, row]));
1629
1634
  const relayChild = (row) => {
1630
1635
  const parent = parentProcess(row, byPid);
@@ -1661,7 +1666,167 @@ export function postStartupProcessCount(kind, activityRows, rows, startup, shape
1661
1666
  changed = true;
1662
1667
  }
1663
1668
  }
1664
- return added.size;
1669
+ return [...added.values()];
1670
+ }
1671
+ // ---- own_work (a41, observation-results.md): what a seat started itself and has not finished ----
1672
+ const ownWorkExclusionsSchema = z.object({
1673
+ digest: z.string().min(1).max(128),
1674
+ entries: z.array(z.union([
1675
+ z.object({ id: z.string(), kind: z.literal("process"), exe: z.string().min(1), args: z.array(z.string()), sessions: z.array(z.string()) }),
1676
+ z.object({ id: z.string(), kind: z.literal("child"), harness: z.string().min(1), session: z.string().nullable(), sessions: z.array(z.string()) }),
1677
+ ])).max(256),
1678
+ });
1679
+ /** Windows argv from one command line (CommandLineToArgvW rules: backslashes before a quote, doubled quotes). */
1680
+ export function windowsCommandLineArgv(line) {
1681
+ const argv = [];
1682
+ let at = 0;
1683
+ while (at < line.length) {
1684
+ while (line[at] === " " || line[at] === "\t")
1685
+ at++;
1686
+ if (at >= line.length)
1687
+ break;
1688
+ let token = "", quoted = false, first = argv.length === 0;
1689
+ for (; at < line.length; at++) {
1690
+ const char = line[at];
1691
+ if (!quoted && (char === " " || char === "\t"))
1692
+ break;
1693
+ if (first) {
1694
+ if (char === '"')
1695
+ quoted = !quoted;
1696
+ else
1697
+ token += char;
1698
+ continue;
1699
+ } // argv[0]: quotes only, no escapes
1700
+ if (char === "\\") {
1701
+ let slashes = 0;
1702
+ while (line[at] === "\\") {
1703
+ slashes++;
1704
+ at++;
1705
+ }
1706
+ if (line[at] === '"') {
1707
+ token += "\\".repeat(slashes >> 1);
1708
+ if (slashes % 2)
1709
+ token += '"';
1710
+ else {
1711
+ at--;
1712
+ }
1713
+ }
1714
+ else {
1715
+ token += "\\".repeat(slashes);
1716
+ at--;
1717
+ }
1718
+ continue;
1719
+ }
1720
+ if (char === '"') {
1721
+ if (quoted && line[at + 1] === '"') {
1722
+ token += '"';
1723
+ at++;
1724
+ }
1725
+ else
1726
+ quoted = !quoted;
1727
+ continue;
1728
+ }
1729
+ token += char;
1730
+ }
1731
+ argv.push(token);
1732
+ }
1733
+ return argv;
1734
+ }
1735
+ function processArgv(row) {
1736
+ if (process.platform === "linux") {
1737
+ try {
1738
+ const parts = fs.readFileSync(`/proc/${row.pid}/cmdline`, "utf8").split("\0");
1739
+ if (parts.at(-1) === "")
1740
+ parts.pop();
1741
+ if (parts.length)
1742
+ return parts;
1743
+ }
1744
+ catch { /* gone or unreadable: the table's command line */ }
1745
+ }
1746
+ if (isWin)
1747
+ return windowsCommandLineArgv(row.command);
1748
+ // shortcut: macOS ps gives only the joined command line, so an argument containing a space splits; exact argv needs a native call.
1749
+ return row.command.trim().split(/\s+/);
1750
+ }
1751
+ /** The descriptor an exclusion entry matches (raw argv never leaves this machine). */
1752
+ export function processDescriptor(argv, windows = isWin) {
1753
+ const base = (value) => value.replace(/^["']+|["']+$/g, "").split(/[\\/]/).filter(Boolean).pop() ?? "";
1754
+ // Judged on the whole token before it is shortened: a URL or user@host must not survive as its last path part.
1755
+ const secret = (value) => /=|:\/\/|@/.test(value);
1756
+ const token = (value) => { const short = base(value); return secret(value) || short.length > 40 ? "…" : short; };
1757
+ let exe = token(argv[0] ?? "").replace(/\.(?:exe|cmd)$/i, "");
1758
+ if (windows)
1759
+ exe = exe.toLowerCase();
1760
+ return { exe, args: argv.slice(1).filter(arg => !arg.startsWith("-")).slice(0, 2).map(token) };
1761
+ }
1762
+ /** own_work for each local agent seat, from one shared process table (seat_turns rows of an opted-in caller). */
1763
+ export async function seatOwnWork(names, requested) {
1764
+ const parsed = ownWorkExclusionsSchema.safeParse(requested);
1765
+ const list = parsed.success ? parsed.data : null;
1766
+ const result = new Map();
1767
+ let rows = null;
1768
+ try {
1769
+ rows = await readRuntimeProcessesShared();
1770
+ }
1771
+ catch { /* table unreadable: processes null */ }
1772
+ for (const name of names) {
1773
+ const meta = tryLoadAgentMetadata(name);
1774
+ if (!meta)
1775
+ continue;
1776
+ const entries = list?.entries.filter(entry => entry.sessions.includes(name)) ?? [];
1777
+ const childExcluded = (child) => entries.some(entry => entry.kind === "child"
1778
+ && entry.harness === child.harness && (entry.session === null || entry.session === child.session));
1779
+ const work = { processes: null, excluded: 0, child_results: null, exclusions_digest: list?.digest ?? null, oldest: null };
1780
+ result.set(name, work);
1781
+ try {
1782
+ const state = agentDormantState(meta);
1783
+ if (state === "hibernated") {
1784
+ work.processes = 0;
1785
+ work.child_results = 0;
1786
+ continue;
1787
+ }
1788
+ if (state !== null || !rows)
1789
+ continue;
1790
+ const pane = await sessionPaneAsync(name);
1791
+ const [pidText, dead] = pane.code === 0 ? pane.stdout.trim().split("\t") : [];
1792
+ const root = dead === "0" ? rows.find(row => row.pid === Number(pidText)) : undefined;
1793
+ if (!root)
1794
+ continue;
1795
+ const subtree = processSubtree(rows, root.pid);
1796
+ const candidates = selectHarnessProcesses(meta, rows, subtree);
1797
+ const agent = candidates.length === 1 ? candidates[0] : null;
1798
+ if (!agent)
1799
+ continue;
1800
+ const activityRows = subtree.some(row => row.pid === agent.pid) ? subtree : [...subtree, ...processSubtree(rows, agent.pid)];
1801
+ work.child_results = pendingChildResultsFor(name, activityRows, childExcluded);
1802
+ if (!Array.isArray(meta.startup_processes))
1803
+ continue;
1804
+ const counted = postStartupProcesses(meta.kind, activityRows, rows, new Set(meta.startup_processes), meta.startup_process_shapes, agent);
1805
+ const processEntries = entries.filter(entry => entry.kind === "process");
1806
+ const descriptors = new Map(counted.map(row => [row.pid, processDescriptor(processArgv(row))]));
1807
+ const byPid = new Map(rows.map(row => [row.pid, row]));
1808
+ const countedPids = new Set(counted.map(row => row.pid));
1809
+ const excluded = new Set();
1810
+ for (const row of counted) {
1811
+ const descriptor = descriptors.get(row.pid);
1812
+ if (!processEntries.some(entry => entry.exe === descriptor.exe && entry.args.every((arg, at) => descriptor.args[at] === arg)))
1813
+ continue;
1814
+ // The match, its descendants and its post-startup ancestors (the bash -c wrappers CLIs put around commands).
1815
+ for (const below of processSubtree(rows, row.pid))
1816
+ if (countedPids.has(below.pid))
1817
+ excluded.add(below.pid);
1818
+ for (let up = parentProcess(row, byPid); up && countedPids.has(up.pid); up = parentProcess(up, byPid))
1819
+ excluded.add(up.pid);
1820
+ }
1821
+ const remaining = counted.filter(row => !excluded.has(row.pid));
1822
+ work.processes = remaining.length;
1823
+ work.excluded = excluded.size;
1824
+ const oldest = remaining.reduce((first, row) => !first || Date.parse(row.started_identity) < Date.parse(first.started_identity) ? row : first, null);
1825
+ work.oldest = oldest ? { ...descriptors.get(oldest.pid), since: new Date(oldest.started_identity).toISOString() } : null;
1826
+ }
1827
+ catch { /* this seat could not be read: nulls */ }
1828
+ }
1829
+ return result;
1665
1830
  }
1666
1831
  function emptySessionObservation(name, exists) {
1667
1832
  return {
@@ -1848,8 +2013,8 @@ function observeNativeSession(name, cursor) {
1848
2013
  const comparable = previous?.pane_identity === sample.pane_identity;
1849
2014
  // 起動完了の控えが無いsession(通常PTY、控える前の版で起動したagent)とharnessを特定できない時は数えない。
1850
2015
  const startup = agent && Array.isArray(meta?.startup_processes) ? new Set(meta.startup_processes) : null;
1851
- // このsessionが親として待っている子の結果。持ち主はharnessの下で動くAitermのMCP process。
1852
- result.pending_child_deliveries = agent ? unfinishedDeliveriesOwnedBy(activityRows) : null;
2016
+ // このsessionが親として待っている子の結果。子の記録が名指す親の席に数える(名指しが無ければ持ち主processで)。
2017
+ result.pending_child_deliveries = agent ? pendingChildResultsFor(name, activityRows) : null;
1853
2018
  result.activity = {
1854
2019
  cursor: Buffer.from(JSON.stringify(sample)).toString("base64url"),
1855
2020
  output_changed: comparable ? previous.screen_digest !== sample.screen_digest : null,
@@ -2246,6 +2411,28 @@ function listNativeSessionRows(runTmux = tmux) {
2246
2411
  }
2247
2412
  /** Same listing and failure as pty_list, without loading every seat's metadata: one seat's existence check stays one
2248
2413
  * tmux call (2026-11-11: per-seat full lists made a CurrentWork pty_list take 10-27 s for ~140 members). */
2414
+ /**
2415
+ * Why a parent delivery's local child can no longer complete its boundary (parent-delivery.md), or null while it still can
2416
+ * or when this cannot be told (tmux unreadable). Replaced launch, missing record, hibernated, or vanished native.
2417
+ */
2418
+ export function deliveryChildGone(boundary) {
2419
+ if (boundary.remote)
2420
+ return null;
2421
+ try {
2422
+ const meta = tryLoadAgentMetadata(boundary.session_id);
2423
+ if (!meta)
2424
+ return "child_missing";
2425
+ if (meta.launch_id !== boundary.launch_id)
2426
+ return "child_replaced";
2427
+ const state = agentDormantState(meta);
2428
+ if (state === "hibernated")
2429
+ return "child_hibernated";
2430
+ return state === null && !nativeSessionExists(boundary.session_id) ? "child_vanished" : null;
2431
+ }
2432
+ catch {
2433
+ return null;
2434
+ }
2435
+ }
2249
2436
  function nativeSessionExists(name) {
2250
2437
  return listNativeSessionRows().some(([listed]) => listed === name);
2251
2438
  }
@@ -147,7 +147,8 @@ function nativeParentDependencies(provider, profile) {
147
147
  else
148
148
  await provider.verifyCodexParent(profile, parent);
149
149
  },
150
- processes: readProcessIdentities, exists: nativeProcessExists, now: () => performance.now(), wall: () => Date.now() };
150
+ processes: readProcessIdentities, exists: nativeProcessExists, childGone: core.deliveryChildGone, childCheckMs: 30_000,
151
+ now: () => performance.now(), wall: () => Date.now() };
151
152
  }
152
153
  /** Historical injected worker; normal parent-hook CLI no longer uses it. */
153
154
  export function createNativeExecutionWorker(input) {
package/dist/index.js CHANGED
@@ -898,6 +898,16 @@ export function createAitermServer(options = {}) {
898
898
  // callRemoteTool spawns its ssh only after an await: let the relays start before this process blocks on the local read.
899
899
  await new Promise(resolve => setImmediate(resolve));
900
900
  const local = core.readSeatTurns(sessions.filter(session => session.harness !== null).map(session => session.session_id));
901
+ // a41: own_work only for a caller that sends its exclusion list (observation-results.md); terminals compute their own rows.
902
+ const ownWork = requestMeta && typeof requestMeta === "object" ? requestMeta["aiterm/own_work_exclusions"] : undefined;
903
+ if (ownWork !== undefined) {
904
+ const work = await core.seatOwnWork(local.seats.map(seat => seat.session_id), ownWork);
905
+ for (const seat of local.seats) {
906
+ const value = work.get(seat.session_id);
907
+ if (value)
908
+ Object.assign(seat, { own_work: value });
909
+ }
910
+ }
901
911
  const remote = await relays;
902
912
  return { _meta: { [SEAT_TURNS_RESULT_META_KEY]: { ...local, seats: [...local.seats, ...remote.flatMap(r => r.seats)], unread: [...local.unread, ...remote.flatMap(r => r.unread)] } } };
903
913
  }
@@ -3,15 +3,29 @@
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import { createHash } from "node:crypto";
6
- import { ensureStateRoot } from "./agent-shared.js";
6
+ import { agentHarness, agentMetadataPath, agentsDir, ensureStateRoot } from "./agent-shared.js";
7
7
  const DELIVERY_DIRECTORIES = ["parent-deliveries", "claude-parent-deliveries", "cursor-parent-deliveries"];
8
8
  /** 持ち主の保存場所の名前の先頭。pidの使い回しと取り違えないよう、開始時刻も入れる。 */
9
9
  export function deliveryOwnerPrefix(owner) {
10
10
  return `${owner.pid}-${createHash("sha256").update(owner.started_identity).digest("hex").slice(0, 16)}-`;
11
11
  }
12
- /** 渡したprocessのどれかが持ち主で、まだ親へ届け終えていない配送の数。届け終えた記録はactiveから出ている。 */
13
- export function unfinishedDeliveriesOwnedBy(processes, stateRoot = ensureStateRoot()) {
12
+ /**
13
+ * The unfinished deliveries that `seat` waits for (parent-delivery.md "親の席への数え方"): a local child's metadata names its
14
+ * parent seat (`parent_session_id`). Only when that names no Aiterm seat here, the child is on another terminal, or its metadata
15
+ * cannot be read, the owner process in the seat's subtree decides, as before 0.70.42. A manager that adopted a dead owner's
16
+ * records is not charged for them.
17
+ */
18
+ export function pendingChildResultsFor(seat, processes, excluded = () => false, stateRoot = ensureStateRoot()) {
14
19
  const prefixes = processes.map(deliveryOwnerPrefix);
20
+ // A parent named by a child is a seat here when Aiterm holds an agent record for that name (host-root and the like are not).
21
+ let listing = null;
22
+ const isSeat = (name) => (listing ??= (() => { try {
23
+ return fs.readdirSync(agentsDir());
24
+ }
25
+ catch {
26
+ return [];
27
+ } })())
28
+ .some(file => file.startsWith(`${name}.`) && file.endsWith(".agent.json"));
15
29
  let count = 0;
16
30
  for (const prefix of ["", "remote-"]) {
17
31
  for (const directory of DELIVERY_DIRECTORIES) {
@@ -26,14 +40,37 @@ export function unfinishedDeliveriesOwnedBy(processes, stateRoot = ensureStateRo
26
40
  throw error;
27
41
  }
28
42
  for (const owner of owners) {
29
- if (!owner.isDirectory() || !prefixes.some(candidate => owner.name.startsWith(candidate)))
43
+ if (!owner.isDirectory())
30
44
  continue;
45
+ const ownedHere = prefixes.some(candidate => owner.name.startsWith(candidate));
46
+ let names;
31
47
  try {
32
- count += fs.readdirSync(path.join(active, owner.name)).filter(name => name !== "owner.json" && name.endsWith(".json")).length;
48
+ names = fs.readdirSync(path.join(active, owner.name)).filter(name => name !== "owner.json" && name.endsWith(".json"));
33
49
  }
34
50
  catch (error) {
35
- if (error.code !== "ENOENT")
36
- throw error;
51
+ if (error.code === "ENOENT")
52
+ continue;
53
+ throw error;
54
+ }
55
+ for (const name of names) {
56
+ let child = null, parent = null;
57
+ try {
58
+ const boundary = JSON.parse(fs.readFileSync(path.join(active, owner.name, name), "utf8"))?.boundary;
59
+ if (typeof boundary?.session_id === "string")
60
+ child = { session: boundary.session_id, harness: null };
61
+ if (child && !boundary.remote && typeof boundary.launch_id === "string") {
62
+ const meta = JSON.parse(fs.readFileSync(agentMetadataPath(child.session, boundary.launch_id), "utf8"));
63
+ child.harness = typeof meta?.kind === "string" ? agentHarness(meta.kind) : null;
64
+ if (typeof meta?.parent_session_id === "string" && isSeat(meta.parent_session_id))
65
+ parent = meta.parent_session_id;
66
+ }
67
+ }
68
+ catch { /* unreadable record or child: the owner decides */ }
69
+ if (!(parent === null ? ownedHere : parent === seat))
70
+ continue;
71
+ if (child && excluded(child))
72
+ continue;
73
+ count++;
37
74
  }
38
75
  }
39
76
  }
@@ -4,6 +4,7 @@ import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import { randomUUID } from "node:crypto";
6
6
  import { z } from "zod";
7
+ import { deliveryChildGone } from "./core.js";
7
8
  import { ensureStateRoot, writeJson0600 } from "./agent-shared.js";
8
9
  import { readProcessIdentities } from "./process-runtime.js";
9
10
  import { deliveryOwnerPrefix } from "./parent-delivery-owners.js";
@@ -118,7 +119,7 @@ export class ParentDeliveryManager {
118
119
  constructor(options = {}) {
119
120
  this.execution = options.execution;
120
121
  this.deps = { observe: observeAnywhere, answer: answerAnywhere, submit: submitParentAnswer,
121
- verify: verifyParent, processes: readProcessIdentities, exists: processExists,
122
+ verify: verifyParent, processes: readProcessIdentities, exists: processExists, childGone: deliveryChildGone, childCheckMs: 30_000,
122
123
  now: () => performance.now(), wall: () => Date.now(), ...options.dependencies,
123
124
  ...(options.execution ? { submit: options.execution.submit } : {}) };
124
125
  if (options.state_root !== undefined && !path.isAbsolute(options.state_root))
@@ -414,19 +415,34 @@ export class ParentDeliveryManager {
414
415
  }
415
416
  watch(job) {
416
417
  const boundary = job.record.boundary;
418
+ // A child that can no longer complete this boundary (replaced, gone, hibernated) ends the wait: before 0.70.42 it never did.
419
+ const childStop = new AbortController();
420
+ let gone = null, seen = null;
421
+ const check = setInterval(() => {
422
+ const reason = this.deps.childGone(boundary);
423
+ if (reason && reason === seen) {
424
+ gone = reason;
425
+ childStop.abort();
426
+ }
427
+ seen = reason;
428
+ }, this.deps.childCheckMs);
429
+ check.unref?.();
417
430
  job.task = (async () => {
418
431
  try {
419
432
  const completion = await this.deps.observe(boundary.session_id, {
420
433
  cursor: boundary.event_cursor, operation_id: boundary.operation_id,
421
434
  ...(boundary.input_id ? { input_id: boundary.input_id } : {}),
422
- timeout: Infinity, signal: job.controller.signal, ...(boundary.remote ? { remote: boundary.remote } : {}),
435
+ timeout: Infinity, signal: AbortSignal.any([job.controller.signal, childStop.signal]), ...(boundary.remote ? { remote: boundary.remote } : {}),
423
436
  });
424
437
  await this.capture(job, completion);
425
438
  }
426
439
  catch (error) {
427
440
  if (job.controller.signal.aborted)
428
441
  return;
429
- await this.captureFailure(job, error);
442
+ await this.captureFailure(job, gone ? new AitermError(`PARENT_DELIVERY_CHILD_GONE: ${gone}`, 2) : error);
443
+ }
444
+ finally {
445
+ clearInterval(check);
430
446
  }
431
447
  })().catch((error) => this.reportServiceError(error));
432
448
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.70.41",
3
+ "version": "0.70.42",
4
4
  "mcpName": "io.github.kitepon/aiterm-mcp",
5
5
  "description": "Persistent terminal MCP with one harness-based launcher for Claude Code, Codex CLI, Grok CLI, Cursor Agent CLI, and Antigravity CLI, plus durable PTYs for SSH, containers, and REPLs.",
6
6
  "keywords": [