aiterm-mcp 0.70.57 → 0.70.59

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,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.70.59] - 2026-11-14
11
+
12
+ - A fresh launch on a loaded Mac no longer fails with `native_condition_refused` while the seat is fine (Lapi's seat, macbook 19:47). tmux 3.7+ blanks a format that runs past its 100 ms budget, so the identity check took the refusal branch. A refusal is now classified from `has-session` plus one pane read: `native_pane_gone`, `native_identity_changed` (with the field), `native_pane_exited`, `native_creation_marker_changed`, or unevaluated. Only an unevaluated condition re-issues the same command, at most 4 tries, then `native_condition_unevaluated`.
13
+ - Blank or partial `list-sessions` rows read as an unavailable listing, not an absent session; a blank pane read after creation is unreadable, not a replaced native.
14
+ - The Mac GUI LaunchAgent sets `ProcessType=Interactive`, so a new tmux server and its seats leave launchd's background priority.
15
+
16
+ ## [0.70.58] - 2026-11-14
17
+
18
+ - `aiterm-setup harness-entries --json` (bd14, BellTeam E1 v1.1): prints the hooks Aiterm needs for Claude, Cursor and Codex as `bellteam.harness-entries.v1` (native groups as the CLI files hold them, `owns.commandIncludes`), for a caller that is the one writer of those files. It writes no CLI file and no Codex trust; it writes only Aiterm's own `codex-parent-hooks/config.json`. The entries are produced by the same Steer writers on an empty file, so they equal what `configureNativeExecutionHooks` writes today.
19
+
20
+ - Public package entry points (`package.json` `exports`, bd04): `aiterm-mcp/setup-node` (new `mcpRegistration()` = node + this package's `dist/index.js`, no npm call), `setup-integrations`, `execution-parent-worker`, `execution-native-setup`, `execution-native-server`, `child-result` (new `CHILD_RESULT_PREFACE`), `resume-state-cli` (run with node: `restore` / `checkpoint` argv, stdin, one-line `aiterm.resume-state-result.v1`, exit 0 or 2), `state-compat.json`, `package.json`. The exports map itself is the promise (string targets inside the package root), so a caller that selects its own package root reads the targets from that root. Absolute-path imports keep working. Contract: docs/architecture/bellteam-boundary.md.
21
+
10
22
  ## [0.70.57] - 2026-11-14
11
23
 
12
24
  - Withdrawn at the requester's ask (Kiro 2026-11-14): the `refusal` field of `aiterm.agent-configure-request-result.v1` and the `AGENT_CONFIGURE_NOT_READY` code added in 0.70.56. A not-ready (turn running) configure refusal again carries no `_meta["aiterm/configure_error"]`; only Claude picker refusals do, which is how a caller tells them apart.
@@ -3474,7 +3486,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
3474
3486
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
3475
3487
  provenance.
3476
3488
 
3477
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.57...HEAD
3489
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.59...HEAD
3490
+ [0.70.59]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.58...v0.70.59
3491
+ [0.70.58]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.57...v0.70.58
3478
3492
  [0.70.57]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.56...v0.70.57
3479
3493
  [0.70.56]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.55...v0.70.56
3480
3494
  [0.70.55]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.54...v0.70.55
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.57** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
218
+ **状態:** 開発継続中 · 現行公開版 **v0.70.59** · 動作対象は 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.57** · 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.59** · 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
@@ -58,7 +58,7 @@ import { liveNodeExecutable } from "./live-node.js";
58
58
  import { resolveClaudeConfigurationRoot, withClaudeConfigRoot, withClaudeSlotLogin } from "./claude-config-root.js";
59
59
  import { probeWriteBan, writeBanPrefix, windowsWriteBanArgv } from "./write-ban.js";
60
60
  import { AitermError, launchAuthRequired, launchInputRefusal, launchStartupBlocked, AgentResumeUnavailableError, AgentResumeError, AgentResumeSecretsError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
61
- import { isWin, SOCKDIR, SOCK, tmuxCommand, readOnlyTmuxList, PtyDiagnosticError, tmuxCommandWithInput, sendPsmuxPayload, loadPtyBufferChunk, pasteBufferBaseArgs, tmuxNewSession, withNativeSessionCreation, withNativeSessionTarget, hasVerifiedNativeSessionTarget, withNativeSessionSetupRollback, hasNativeSessionSetupRollback, registeredSessionEnvironment, registerSessionEnvironment, attachCommand, normalizePaneCommand, atomicShellMultiline, appendMarkSentinel, paneShellForSubmission, adaptShellSubmission, settlePaneLog, paneCwdArgument, sessionEnvironmentLaunch, paneCommandArgs, rememberPaneShell, sessionPaneAsync, } from "./tmux-runtime.js";
61
+ import { isWin, SOCKDIR, SOCK, tmuxCommand, readOnlyTmuxList, PtyDiagnosticError, tmuxCommandWithInput, sendPsmuxPayload, loadPtyBufferChunk, pasteBufferBaseArgs, tmuxNewSession, withNativeSessionCreation, withNativeSessionTarget, hasVerifiedNativeSessionTarget, withNativeSessionSetupRollback, hasNativeSessionSetupRollback, registeredSessionEnvironment, registerSessionEnvironment, attachCommand, normalizePaneCommand, atomicShellMultiline, appendMarkSentinel, paneShellForSubmission, adaptShellSubmission, settlePaneLog, paneCwdArgument, sessionEnvironmentLaunch, paneCommandArgs, rememberPaneShell, sessionPaneAsync, NATIVE_PANE_FORMAT, } from "./tmux-runtime.js";
62
62
  import { AGENT_DEFAULT_PREFACE, sleep, currentUid, runtimeStateBase, safeStatSize, readFileRange, writeJson0600, writeText0600, createEmpty0600, shq, LAUNCH_ID_RE, AGENT_LINEAGE_RE, AGENT_DONE_POLL_MS, AGENT_RATE_LIMIT_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, assertSessionName, agentsDir, readAgentGeneration, selectAgentMetadataFile, publishAgentGeneration, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness, } from "./agent-shared.js";
63
63
  import { AuthResponseError, authUi, authPromptDigest, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
64
64
  import { processStartIdentity } from "./runtime-error-os.js";
@@ -6989,7 +6989,19 @@ function verifyCreatedNative(native, allowExitedPane = false) {
6989
6989
  const sessions = observeExecutionNativeSessions();
6990
6990
  if (sessions.state !== "known" || !sessions.sessions.some(row => row.session_id === native.session_id && row.native_id === native.native_id))
6991
6991
  throw unavailable();
6992
- const pane = tmux("display-message", "-p", "-t", nativePaneTarget(native), "#{session_id}\t#{session_name}\t#{pid}\t#{pane_id}\t#{pane_pid}\t#{pane_dead}");
6992
+ const read = () => tmux("display-message", "-p", "-t", nativePaneTarget(native), NATIVE_PANE_FORMAT);
6993
+ // tmux 3.7+ blanks a format past its 100 ms budget: an incomplete read is unknown, not a replaced native.
6994
+ const incomplete = (r) => {
6995
+ const f = r.stdout.replace(/\r?\n$/, "").split("\t");
6996
+ return r.code === 0 && (f.length !== 6 || f.slice(0, 4).some(field => !field) || !["0", "1"].includes(f[5]) || (f[4] === "" && f[5] === "0"));
6997
+ };
6998
+ let pane = read();
6999
+ for (let attempt = 1; incomplete(pane) && attempt < 4; attempt++) {
7000
+ pauseSync(50);
7001
+ pane = read();
7002
+ }
7003
+ if (incomplete(pane))
7004
+ throw new AitermError("AGENT_RESUME_UNCONFIRMED: 作成したnative本人性を取得できません。", 2);
6993
7005
  const fields = pane.stdout.trim().split("\t");
6994
7006
  const exited = allowExitedPane && fields[5] === "1";
6995
7007
  // macOS tmux clears pane_pid after exit; only the explicit dead-pane close admits that absence.
@@ -5,7 +5,11 @@ export { executionNativeBindingSchema } from "./execution-contract.js";
5
5
  import { ExecutionError } from "./execution-wire.js";
6
6
  export function parseExecutionNativeSessions(text) {
7
7
  const sessions = [];
8
- for (const line of text.split(/\r?\n/).filter(Boolean)) {
8
+ const lines = text.split(/\r?\n/);
9
+ if (lines.at(-1) === "")
10
+ lines.pop();
11
+ // A blank row is a format tmux 3.7+ cut at its 100 ms budget, not an absent session.
12
+ for (const line of lines) {
9
13
  const parts = line.split("\t");
10
14
  if (parts.length !== 2 || !/^\$\d+$/.test(parts[0])
11
15
  || !executionLaunchSchema.shape.session_id.safeParse(parts[1]).success
@@ -1,11 +1,14 @@
1
1
  // Native entry registration, owned by Aiterm. Writes only the supplied home;
2
2
  // callers retain approval/deployment responsibility. No Bot/member API exists here.
3
+ import fs from "node:fs";
4
+ import os from "node:os";
3
5
  import path from "node:path";
4
- import { pathToFileURL } from "node:url";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
7
  import { parseNativeExecutionArguments } from "./execution-native-server.js";
6
8
  import { AITERM_PROFILE } from "./steer-profile.js";
7
9
  import { ExecutionError } from "./execution-wire.js";
8
10
  import { codexHookCommand } from "./setup-codex-hooks.js";
11
+ import { setupNodeExecutable } from "./setup-node.js";
9
12
  export async function configureNativeExecutionHooks(home, options) {
10
13
  if (process.platform === "win32" || !path.isAbsolute(home) || !path.isAbsolute(options.registration.command)
11
14
  || !path.isAbsolute(options.registration.args[0] ?? "") || path.basename(options.registration.args[0]) !== "execution-native-server.js")
@@ -57,3 +60,48 @@ export async function configureNativeExecutionHooks(home, options) {
57
60
  }
58
61
  return { results: result, commands, registration, relation_scope: "untracked" };
59
62
  }
63
+ /**
64
+ * bd14 (setup-update.md "CLIのhookの項目を返す"): the hooks Aiterm needs, as bellteam.harness-entries.v1, for a caller that is
65
+ * the one writer of the CLI files. The entries are what Steer's own writers put into an empty file (no copy of their shapes);
66
+ * the only file written is Aiterm's codex-parent-hooks/config.json that the Codex hook reads. Codex trust is the caller's.
67
+ */
68
+ export async function nativeExecutionHarnessEntries(home, options) {
69
+ const dist = path.dirname(fileURLToPath(import.meta.url));
70
+ const parsed = parseNativeExecutionArguments(["--execution-interrupt", "--state-root", options.stateRoot, "--socket", options.socket,
71
+ "--steer-provider", options.providerFile]);
72
+ const clients = [...new Set(options.clients ?? ["claude", "cursor", "codex"])];
73
+ if (process.platform === "win32" || !path.isAbsolute(home) || parsed.mode !== "mcp"
74
+ || clients.some(client => !["claude", "cursor", "codex"].includes(client))
75
+ || (clients.includes("codex") && (!options.codexBinary || !path.isAbsolute(options.codexBinary))))
76
+ throw new ExecutionError("EXECUTION_INVALID");
77
+ const provider = options.provider ?? await import(pathToFileURL(parsed.providerFile).href);
78
+ const node = setupNodeExecutable();
79
+ const profile = { ...AITERM_PROFILE, state_root: () => parsed.expectedScope.state_root, config_root: () => path.join(home, ".config", "aiterm-mcp") };
80
+ const hook = (file) => ({ command: node, script: path.join(dist, file) });
81
+ const hooks = {};
82
+ const scratch = fs.mkdtempSync(path.join(os.tmpdir(), "aiterm-harness-entries-"));
83
+ try {
84
+ const read = (file) => JSON.parse(fs.readFileSync(file, "utf8")).hooks;
85
+ if (clients.includes("claude")) {
86
+ provider.mergeClaudeParentHooks(profile, path.join(scratch, "settings.json"), hook(profile.hooks.claude));
87
+ hooks.claude = read(path.join(scratch, "settings.json"));
88
+ }
89
+ if (clients.includes("cursor")) {
90
+ provider.mergeCursorParentHooks(profile, path.join(scratch, "hooks.json"), hook(profile.hooks.cursor));
91
+ hooks.cursor = read(path.join(scratch, "hooks.json"));
92
+ }
93
+ if (clients.includes("codex")) {
94
+ const directory = path.join(home, ".config", "aiterm-mcp", "codex-parent-hooks"), script = path.join(dist, profile.hooks.codex);
95
+ const command = provider.codexHookCommand(node, script, directory);
96
+ hooks.codex = provider.planCodexParentHooks(path.join(scratch, "codex-hooks.json"), command).next.hooks;
97
+ provider.writeHookJson(path.join(directory, "config.json"), provider.codexHookConfigSchema(profile).parse({ schema: profile.codex_hook_schema,
98
+ enabled: true, codex_home: path.join(home, ".codex"), binary: options.codexBinary, command, node, hook: script, stale_processes: [] }));
99
+ }
100
+ }
101
+ finally {
102
+ fs.rmSync(scratch, { recursive: true, force: true });
103
+ }
104
+ const version = JSON.parse(fs.readFileSync(path.join(dist, "..", "package.json"), "utf8")).version;
105
+ return { schema: "bellteam.harness-entries.v1", product: "aiterm", version, mcpServers: {}, settings: {},
106
+ owns: { commandIncludes: [profile.hooks.claude, profile.hooks.cursor, profile.hooks.codex, "execution-native-server.js"] }, hooks };
107
+ }
@@ -72,8 +72,10 @@ export function readRecord(file) {
72
72
  throw new AitermError("PARENT_DELIVERY_STATE_INVALID: 配送記録を読めません", 2);
73
73
  }
74
74
  }
75
+ /** Public (bellteam-boundary.md): the start of every child result Aiterm hands a parent. Only this start is promised. */
76
+ export const CHILD_RESULT_PREFACE = "Aitermの子エージェントからの実行結果です。";
75
77
  export function answerMessage(record) {
76
- return "Aitermの子エージェントからの実行結果です。子の回答として扱ってください。\n" +
78
+ return CHILD_RESULT_PREFACE + "子の回答として扱ってください。\n" +
77
79
  `delivery_id=${record.delivery_id}\nsession=${record.boundary.session_id}\nharness=${record.boundary.harness}\n` +
78
80
  `launch_id=${record.boundary.launch_id}\nturn_id=${record.child_turn_id ?? "unknown"}\n` +
79
81
  `outcome=${record.child_outcome}\n` +
package/dist/setup-cli.js CHANGED
@@ -26,6 +26,33 @@ else if (args.length === 1 && args[0] === "--remove-cursor-parent-hooks") {
26
26
  process.exitCode = 2;
27
27
  }
28
28
  }
29
+ else if (args[0] === "harness-entries") {
30
+ // bd14 (setup-update.md): print the hooks Aiterm needs; the caller writes the CLI files. Errors: exit 2, nothing on stdout.
31
+ try {
32
+ const flags = new Map();
33
+ let json = false;
34
+ for (let i = 1; i < args.length; i++) {
35
+ if (args[i] === "--json" && !json)
36
+ json = true;
37
+ else if (["--home", "--state-root", "--socket", "--steer-provider", "--codex-binary", "--clients"].includes(args[i])
38
+ && !flags.has(args[i]) && args[i + 1] !== undefined)
39
+ flags.set(args[i], args[++i]);
40
+ else
41
+ throw new Error("使い方: aiterm-setup harness-entries --json --home <p> --state-root <p> --socket <p> --steer-provider <p> [--codex-binary <p>] [--clients claude,cursor,codex]");
42
+ }
43
+ if (!json || !flags.has("--home") || !flags.has("--state-root") || !flags.has("--socket") || !flags.has("--steer-provider"))
44
+ throw new Error("--json --home --state-root --socket --steer-provider が要ります");
45
+ const { nativeExecutionHarnessEntries } = await import("./execution-native-setup.js");
46
+ const entries = await nativeExecutionHarnessEntries(flags.get("--home"), { stateRoot: flags.get("--state-root"), socket: flags.get("--socket"),
47
+ providerFile: flags.get("--steer-provider"), codexBinary: flags.get("--codex-binary"),
48
+ clients: flags.get("--clients")?.split(",") });
49
+ process.stdout.write(`${JSON.stringify(entries)}\n`);
50
+ }
51
+ catch (error) {
52
+ process.stderr.write(`aiterm-setup: ${error instanceof Error ? error.message : String(error)}\n`);
53
+ process.exitCode = 2;
54
+ }
55
+ }
29
56
  else if (args.includes("--hooks-only")) {
30
57
  // 利用者や他製品がMCP登録を所有する環境向け。hookの登録だけを行い、stdoutへは結果のJSONだけを出す。
31
58
  if (args.some(arg => !["--hooks-only", "--json"].includes(arg)) || new Set(args).size !== args.length) {
@@ -39,7 +66,7 @@ else if (args.includes("--hooks-only")) {
39
66
  }
40
67
  }
41
68
  else if (args.length === 1 && ["--help", "-h"].includes(args[0])) {
42
- process.stdout.write("使い方: aiterm-setup [--json] [--codex-steer enable|disable|status]\n依存準備、AIへの登録、MCPと端末の実動作確認を行います。対話実行ではAiterm単品かCodex Desktop Steer付きかを選べます。SteerはmacOS・Windows対応で、初回はCodexの再起動が必要です。disableは専用hookを解除し、statusは公式hookの登録・承認と再起動の必要性を確認します。旧中継はhook導入後に解除します。--jsonは対話せず、Steerの選択を維持します。\nClaude Code・Cursorの親配送hookだけの登録(MCP登録・依存準備・Codex Steerには触れない): --hooks-only\n旧版へ戻す前のClaude専用hook解除: --remove-claude-parent-hooks\n旧版へ戻す前のCursor専用hook解除: --remove-cursor-parent-hooks\n");
69
+ process.stdout.write("使い方: aiterm-setup [--json] [--codex-steer enable|disable|status]\n依存準備、AIへの登録、MCPと端末の実動作確認を行います。対話実行ではAiterm単品かCodex Desktop Steer付きかを選べます。SteerはmacOS・Windows対応で、初回はCodexの再起動が必要です。disableは専用hookを解除し、statusは公式hookの登録・承認と再起動の必要性を確認します。旧中継はhook導入後に解除します。--jsonは対話せず、Steerの選択を維持します。\nClaude Code・Cursorの親配送hookだけの登録(MCP登録・依存準備・Codex Steerには触れない): --hooks-only\n旧版へ戻す前のClaude専用hook解除: --remove-claude-parent-hooks\n旧版へ戻す前のCursor専用hook解除: --remove-cursor-parent-hooks\nCLIの設定ファイルを1人で書く呼び手へ、Aitermのhookの項目だけを返す(CLIのファイルは書かない): harness-entries --json --home <p> --state-root <p> --socket <p> --steer-provider <p> [--codex-binary <p>] [--clients claude,cursor,codex]\n");
43
70
  }
44
71
  else {
45
72
  try {
@@ -1,4 +1,5 @@
1
1
  import { accessSync, constants } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
2
3
  import { SetupError } from "./setup-platform.js";
3
4
  // HomebrewのCellar実体は更新で消える。保存する起動先には同じformulaのoptを使う。
4
5
  export function setupNodeExecutable(executable = process.execPath) {
@@ -14,3 +15,7 @@ export function setupNodeExecutable(executable = process.execPath) {
14
15
  }
15
16
  return node;
16
17
  }
18
+ /** Public (bellteam-boundary.md): how to start this package's MCP server, the shape aiterm-setup writes. No npm call. */
19
+ export function mcpRegistration() {
20
+ return { command: setupNodeExecutable(), args: [fileURLToPath(new URL("./index.js", import.meta.url))] };
21
+ }
@@ -96,8 +96,14 @@ function nativeSessionRows() {
96
96
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
97
97
  listed = list();
98
98
  }
99
- if (listed.code === 0)
100
- return listed.stdout.split(/\r?\n/).filter(Boolean).map(row => row.split(/[\t ]/));
99
+ if (listed.code === 0) {
100
+ const rows = listed.stdout.split(/\r?\n/);
101
+ if (rows.at(-1) === "")
102
+ rows.pop();
103
+ const split = rows.map(row => row.split(/[\t ]/));
104
+ // tmux 3.7+ blanks the rest of a format that ran past its 100 ms budget: a blank row is unread, never absent.
105
+ return split.some(row => row.length < 2 || !/^\$\d+$/.test(row[0]) || !row[1]) ? null : split;
106
+ }
101
107
  return /no server running|No such file or directory/i.test(listed.stderr) ? [] : null;
102
108
  }
103
109
  // This scope is private to marker transfer and rollback; ordinary effects still require OS birth identity.
@@ -187,6 +193,38 @@ function nativeSessionArgs(input) {
187
193
  return args;
188
194
  }
189
195
  const NATIVE_REFUSED = "__AITERM_NATIVE_GENERATION_REFUSED__";
196
+ export const NATIVE_PANE_FORMAT = "#{session_id}\t#{session_name}\t#{pid}\t#{pane_id}\t#{pane_pid}\t#{pane_dead}";
197
+ const NATIVE_UNEVALUATED_TRIES = 4, NATIVE_UNEVALUATED_PAUSE_MS = 50;
198
+ /**
199
+ * Why the receiving server took the refusal branch, read back from the pane. if-shell -t accepts a missing pane and
200
+ * expands the condition empty; tmux 3.7+ also blanks a format that runs past 100 ms (a stalled server). null: every field
201
+ * still matches (or the read itself was blanked), so tmux did not evaluate the condition and the effect did not run.
202
+ */
203
+ export function classifyNativeRefusal(target, read, allowExitedPane = false, creation) {
204
+ if (read.code !== 0)
205
+ return `native_pane_gone(${tmuxFailure(read)})`;
206
+ const fields = read.stdout.replace(/\r?\n$/, "").split(/\t/);
207
+ if (fields.length !== (creation === undefined ? 6 : 7) || fields.slice(0, 4).some(field => !field))
208
+ return null;
209
+ const [native, session, server, pane, panePid, dead] = fields;
210
+ if (dead !== "0" && dead !== "1")
211
+ return null;
212
+ if (dead === "1" && !allowExitedPane)
213
+ return "native_pane_exited";
214
+ // macOS tmux clears pane_pid after exit; a live pane's blank pid is an unfinished expansion.
215
+ if (!panePid && dead === "0")
216
+ return null;
217
+ const expected = [["session_id", native, target.native_id], ["session_name", session, target.session_id],
218
+ ["pid", server, String(target.server_pid)], ["pane_id", pane, target.pane_id]];
219
+ if (panePid)
220
+ expected.push(["pane_pid", panePid, String(target.pane_pid)]);
221
+ const changed = expected.find(([, actual, wanted]) => actual !== wanted);
222
+ if (changed)
223
+ return `native_identity_changed(${changed[0]})`;
224
+ if (creation !== undefined && fields[6] === "0")
225
+ return "native_creation_marker_changed";
226
+ return null;
227
+ }
190
228
  /** Check on the receiving server too: a new server may recycle session and pane IDs. */
191
229
  function nativeConditionalArgs(args) {
192
230
  const target = nativeTargets.getStore()?.target;
@@ -484,22 +522,46 @@ function runTmux(observe, input, args, session, deadline) {
484
522
  // maxBuffer は既定 1MiB。capture-pane(大きなスクロールバック)や多セッションの list-sessions で
485
523
  // 頭打ちになり stdout が切れる/空になる。Python の subprocess.run は無制限だったので 64MiB へ広げる。
486
524
  // Windows は tmux CLI 互換の native psmux を -L namespace 隔離で叩く(WSL 非依存)。
487
- let r;
488
525
  const spawnOpts = () => ({ encoding: "utf8", maxBuffer: 64 * 1024 * 1024, input, env: session ?? tmuxSpawnEnv(), ...diagnosticSpawnOptions(deadline) });
489
- if (isWin) {
490
- ensureWinPsmux(observe, deadline);
491
- r = spawnSync(psmuxBin(), ["-L", WIN_NS, ...args], spawnOpts());
492
- }
493
- else {
494
- // resolveTmux() は tmux を解決できなければ明確な AitermError を投げる(POSIX 版の事前確認)。
495
- const bin = resolveTmux(observe, deadline);
496
- // -f は tmux 本体の引数で、server を起こす時にだけ読まれる(new-session の -f は別物で、config を指さない)。
497
- const argv = session ? ["-f", TMUX_EMPTY_CONFIG, "-S", SOCK, ...args] : ["-S", SOCK, ...args];
498
- r = (session && macGuiServerWanted(bin) && startTmuxInMacGui(bin, argv, session))
499
- || spawnSync(bin, argv, spawnOpts());
526
+ const spawnOnce = () => {
527
+ let r;
528
+ if (isWin) {
529
+ ensureWinPsmux(observe, deadline);
530
+ r = spawnSync(psmuxBin(), ["-L", WIN_NS, ...args], spawnOpts());
531
+ }
532
+ else {
533
+ // resolveTmux() は tmux を解決できなければ明確な AitermError を投げる(POSIX 版の事前確認)。
534
+ const bin = resolveTmux(observe, deadline);
535
+ // -f は tmux 本体の引数で、server を起こす時にだけ読まれる(new-session の -f は別物で、config を指さない)。
536
+ const argv = session ? ["-f", TMUX_EMPTY_CONFIG, "-S", SOCK, ...args] : ["-S", SOCK, ...args];
537
+ r = (session && macGuiServerWanted(bin) && startTmuxInMacGui(bin, argv, session))
538
+ || spawnSync(bin, argv, spawnOpts());
539
+ }
540
+ diagnosticSpawnFailure(r, deadline);
541
+ return r;
542
+ };
543
+ const frame = nativeTargets.getStore();
544
+ for (let attempt = 1;; attempt++) {
545
+ const r = spawnOnce();
546
+ if (!frame?.target || args[0] !== "if-shell" || (r.stdout ?? "").trim() !== NATIVE_REFUSED)
547
+ return finishTmux(r, args, observe);
548
+ // The refusal branch ran, so the effect did not: issuing the same conditional command again is not a second effect.
549
+ const target = frame.target;
550
+ // display-message -t, like if-shell -t, answers a missing pane with blank fields and rc=0; has-session fails instead.
551
+ const present = nativeTargets.exit(() => runTmux(false, undefined, ["has-session", "-t", nativeSessionTarget(target)]));
552
+ const read = present.code !== 0 ? present : nativeTargets.exit(() => runTmux(false, undefined, ["display-message", "-p", "-t",
553
+ nativePaneTarget(target), NATIVE_PANE_FORMAT + (frame.creationCondition ? `\t${frame.creationCondition}` : "")]));
554
+ const reason = classifyNativeRefusal(target, read, frame.allowExitedPane, frame.creationCondition);
555
+ if (reason === null && attempt < NATIVE_UNEVALUATED_TRIES) {
556
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, NATIVE_UNEVALUATED_PAUSE_MS);
557
+ continue;
558
+ }
559
+ if (frame.allowRefusal)
560
+ return finishTmux(r, args, observe);
561
+ throw reason === null ? new AitermError("AGENT_RESUME_UNCONFIRMED: tmuxがnative端末の照合条件を評価しませんでした(server側の書式の時間切れ)。"
562
+ + "端末の本人性は読み取りで一致しています。操作していません。native_reason=native_condition_unevaluated", 2)
563
+ : nativeTargetUnavailable(reason);
500
564
  }
501
- diagnosticSpawnFailure(r, deadline);
502
- return finishTmux(r, args, observe);
503
565
  }
504
566
  /** A read-only tmux command (display-message and the like) that does not block the event loop. Same routing, guards and failures as tmux(). */
505
567
  export async function tmuxReadAsync(...input) {
@@ -546,8 +608,6 @@ function finishTmux(r, args, observe) {
546
608
  ptyDependencyError(tmuxMissingMessage(), observe);
547
609
  }
548
610
  const native = nativeTargets.getStore();
549
- if (native?.target && !native.allowRefusal && args[0] === "if-shell" && (r.stdout ?? "").trim() === NATIVE_REFUSED)
550
- throw nativeTargetUnavailable("native_condition_refused");
551
611
  if (native?.target && r.status !== 0)
552
612
  verifyNativeTarget(native);
553
613
  return { code: r.status ?? 1, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
@@ -596,6 +656,9 @@ export function macGuiTmuxPlist(label, dir, argv, env, cwd) {
596
656
  // 直接起動と同じく、呼んだ側の作業フォルダを最初の pane の開始位置にする。
597
657
  `<key>WorkingDirectory</key><string>${xmlText(cwd)}</string>`,
598
658
  "<key>RunAtLoad</key><true/>",
659
+ // launchd's default limits run the job (and the tmux server it starts, with every seat under it) at background priority; a stalled server
660
+ // overruns tmux's 100 ms format budget and blanks identity checks (macbook 2026-11-14).
661
+ "<key>ProcessType</key><string>Interactive</string>",
599
662
  "<key>AbandonProcessGroup</key><true/>",
600
663
  "</dict></plist>",
601
664
  "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.70.57",
3
+ "version": "0.70.59",
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": [
@@ -52,6 +52,17 @@
52
52
  "aiterm-remote-terminal": "dist/remote-terminal-cli.js",
53
53
  "aiterm-transcript-read": "dist/transcript-read-cli.js"
54
54
  },
55
+ "exports": {
56
+ "./package.json": "./package.json",
57
+ "./state-compat.json": "./state-compat.json",
58
+ "./setup-node": "./dist/setup-node.js",
59
+ "./setup-integrations": "./dist/setup-integrations.js",
60
+ "./execution-parent-worker": "./dist/execution-parent-worker.js",
61
+ "./execution-native-setup": "./dist/execution-native-setup.js",
62
+ "./execution-native-server": "./dist/execution-native-server.js",
63
+ "./child-result": "./dist/parent-delivery-record.js",
64
+ "./resume-state-cli": "./dist/resume-state-cli.js"
65
+ },
55
66
  "files": [
56
67
  "dist/*.js",
57
68
  "dist/harnesses/*.js",