aiterm-mcp 0.70.17 → 0.70.18

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,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.70.18] - 2026-11-11
11
+
12
+ - A seat relaunched on a terminal right after its last seat closed (for example `restart_session`) no longer gets a seat MCP port with no forward behind it (`ECONNREFUSED` at Claude start, and Claude Code never retries a failed MCP). The forward keeper stopped once no seat was bound, but the binding kept its port, and the next launch received that port at once. A launch in another Aiterm process was also invisible to the keeper. Now the keeper's remote command prints a mark once the forward's listener is up; a launch receives the port only when a live keeper reported that mark for it. A launch in any process keeps the forward needed until its seat is bound, and a stopped keeper hands over its lock at once, so the relaunch's process starts a new forward without the 15 s restart delay.
13
+
10
14
  ## [0.70.17] - 2026-11-11
11
15
 
12
16
  - On a POSIX terminal where npm linked only `aiterm-mcp` onto the login PATH, Aiterm's other programs on the terminal (`aiterm-remote-terminal` for `path_status` / `make_dir` / `list_dirs` and transcript reads) now run from the same package, as `aiterm-wait` already did. Before, the folder picker failed there with `/bin/sh: aiterm-remote-terminal: not found`.
@@ -3269,7 +3273,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
3269
3273
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
3270
3274
  provenance.
3271
3275
 
3272
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.17...HEAD
3276
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.18...HEAD
3277
+ [0.70.18]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.17...v0.70.18
3273
3278
  [0.70.17]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.16...v0.70.17
3274
3279
  [0.70.16]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.15...v0.70.16
3275
3280
  [0.70.15]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.14...v0.70.15
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.17** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
218
+ **状態:** 開発継続中 · 現行公開版 **v0.70.18** · 動作対象は 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.17** · 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.18** · 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
 
@@ -324,8 +324,10 @@ const cliAuthScript = (c) => ({
324
324
  windows: `$p = (Get-Command ${c.bin} -ErrorAction SilentlyContinue).Source; if (-not $p) { $p = ${c.winPath}; if (-not (Test-Path -LiteralPath $p)) { exit 127 } }; & $p ${c.auth.join(" ")}`,
325
325
  });
326
326
  /** The remote command the forward keeper holds: it ends exactly when ssh's stdin closes. */
327
+ export const FORWARD_READY_MARK = "AITERM_FORWARD_READY";
327
328
  export function keeperCommand(shell) {
328
- return shell === "posix" ? "cat >/dev/null" : powershellForShell(shell, "[Console]::In.ReadToEnd() | Out-Null");
329
+ return shell === "posix" ? `echo ${FORWARD_READY_MARK}; exec cat >/dev/null`
330
+ : powershellForShell(shell, `[Console]::Out.WriteLine('${FORWARD_READY_MARK}'); [Console]::In.ReadToEnd() | Out-Null`);
329
331
  }
330
332
  const WAIT_FLAGS = new Set(["--session", "--operation", "--timeout", "--cursor", "--steer", "--launch", "--input"]);
331
333
  const WAIT_VALUE = /^[A-Za-z0-9_.:-]{1,128}$/;
@@ -858,12 +860,26 @@ function ownerAlive(owner) {
858
860
  return true;
859
861
  }
860
862
  }
863
+ const lockIdentity = () => ({ pid: process.pid, boot: bootTime(), start: procStart(process.pid) });
864
+ /** T3: only the owner rewrites its lock (rename, so no reader sees half a file): `ready` = the P its running ssh -R holds. */
865
+ function markReady(ref, ready) {
866
+ if (Number(lockOwner(ref)?.pid) !== process.pid)
867
+ return;
868
+ const file = lockFile(ref), staged = `${file}.${process.pid}`;
869
+ try {
870
+ fs.writeFileSync(staged, JSON.stringify(ready ? { ...lockIdentity(), ready } : lockIdentity()), { mode: 0o600 });
871
+ fs.renameSync(staged, file);
872
+ }
873
+ catch {
874
+ fs.rmSync(staged, { force: true });
875
+ }
876
+ }
861
877
  /** T3: true when this process holds the keeper lock for ref (taking it from a dead owner). */
862
878
  function holdLock(ref) {
863
879
  const file = lockFile(ref);
864
880
  for (let attempt = 0; attempt < 2; attempt++) {
865
881
  try {
866
- fs.writeFileSync(file, JSON.stringify({ pid: process.pid, boot: bootTime(), start: procStart(process.pid) }), { flag: "wx", mode: 0o600 });
882
+ fs.writeFileSync(file, JSON.stringify(lockIdentity()), { flag: "wx", mode: 0o600 });
867
883
  return true;
868
884
  }
869
885
  catch (error) {
@@ -883,15 +899,25 @@ function releaseLock(ref) {
883
899
  if (Number(lockOwner(ref)?.pid) === process.pid)
884
900
  fs.rmSync(lockFile(ref), { force: true });
885
901
  }
886
- /** A stored P is usable only while a keeper runs: this process's ssh -R, or another live lock owner's. */
887
- function forwardLive(ref) {
902
+ /** P is usable only when a live owner's running ssh -R has reported it ready (its remote command started after the listener). */
903
+ function forwardReady(ref, port) {
888
904
  const owner = lockOwner(ref);
889
- if (!owner)
905
+ // shortcut: a keeper of Aiterm 0.70.16 or older (lock without boot) never reports ready; trust it while alive, until it exits.
906
+ if (owner && owner.boot === undefined)
907
+ return ownerAlive(owner);
908
+ if (!owner || owner.ready !== port)
890
909
  return false;
891
910
  return Number(owner.pid) === process.pid ? Boolean(keepers.get(ref)?.child) : ownerAlive(owner);
892
911
  }
912
+ // T3: a launch in any process keeps the forward needed (the seat is bound only after it), so the owner never stops it meanwhile.
913
+ const launchFile = (ref) => path.join(ensureStateRoot(), `terminal-forward-${ref}.launch`);
893
914
  function forwardNeeded(ref) {
894
- return (keepers.get(ref)?.launchUntil ?? 0) > Date.now() || Object.values(readSeats()).includes(ref);
915
+ let until = 0;
916
+ try {
917
+ until = Number(fs.readFileSync(launchFile(ref), "utf8"));
918
+ }
919
+ catch { /* no launch */ }
920
+ return until > Date.now() || Object.values(readSeats()).includes(ref);
895
921
  }
896
922
  function storedIngress(ref) {
897
923
  try {
@@ -902,7 +928,7 @@ function storedIngress(ref) {
902
928
  }
903
929
  }
904
930
  function keep(ref) {
905
- const keeper = keepers.get(ref) ?? { child: null, ingress: 0, refusals: 0, timer: null, launchUntil: 0 };
931
+ const keeper = keepers.get(ref) ?? { child: null, ingress: 0, refusals: 0, timer: null };
906
932
  keepers.set(ref, keeper);
907
933
  if (keeper.child) {
908
934
  if (!forwardNeeded(ref) || storedIngress(ref) !== keeper.ingress)
@@ -961,9 +987,18 @@ function keep(ref) {
961
987
  releaseLock(ref);
962
988
  return;
963
989
  }
964
- const child = spawn("ssh", args, { env: sshEnvironment(), stdio: ["pipe", "ignore", "pipe"] });
990
+ const child = spawn("ssh", args, { env: sshEnvironment(), stdio: ["pipe", "pipe", "pipe"] });
965
991
  keeper.child = child;
966
- let stderr = "";
992
+ let stderr = "", stdout = "", ready = false;
993
+ // Ready = the remote command printed its mark (sshd binds the -R listener before it runs the session) and P is known.
994
+ const report = () => {
995
+ const forward = parseSeatForward(stderr), port = typeof forward === "number" ? forward : requested;
996
+ if (!ready && port && stdout.includes(FORWARD_READY_MARK)) {
997
+ ready = true;
998
+ markReady(ref, port);
999
+ }
1000
+ };
1001
+ child.stdout.on("data", (chunk) => { stdout = (stdout + chunk.toString("utf8")).slice(-200); report(); });
967
1002
  child.stderr.on("data", (chunk) => {
968
1003
  stderr = (stderr + chunk.toString("utf8")).slice(-4000);
969
1004
  const forward = parseSeatForward(stderr);
@@ -971,16 +1006,22 @@ function keep(ref) {
971
1006
  writeBinding(ref, { seat_forward_port: forward });
972
1007
  keeper.refusals = 0;
973
1008
  }
1009
+ report();
974
1010
  });
975
1011
  child.on("error", () => { });
976
1012
  child.on("close", () => {
977
1013
  keeper.child = null;
1014
+ markReady(ref, null);
978
1015
  if (parseSeatForward(stderr) === "refused" && requested !== 0 && ++keeper.refusals >= FORWARD_REFUSALS_BEFORE_NEW_PORT) {
979
1016
  // The old P stays taken on the terminal: let sshd pick a new one (seats launched with the old P need a relaunch).
980
1017
  writeBinding(ref, { seat_forward_port: undefined });
981
1018
  keeper.refusals = 0;
982
1019
  }
983
- again();
1020
+ // Stopped because no seat needs it: hand the lock over at once, so a launch in another process starts its own.
1021
+ if (forwardNeeded(ref))
1022
+ again();
1023
+ else
1024
+ keep(ref);
984
1025
  });
985
1026
  }, () => { keeper.starting = false; again(); });
986
1027
  }
@@ -1010,16 +1051,15 @@ export async function ensureSeatForward(ref, ingress, timeoutMs = 30_000) {
1010
1051
  // A new D makes the old P (forwarding to the old D) useless: clear it so the wait below sees only a forward to D.
1011
1052
  if (binding(ref).seat_ingress_port !== ingress)
1012
1053
  writeBinding(ref, { seat_ingress_port: ingress, seat_forward_port: undefined });
1013
- const keeper = keepers.get(ref) ?? { child: null, ingress: 0, refusals: 0, timer: null, launchUntil: 0 };
1014
- keeper.launchUntil = Date.now() + LAUNCH_GRACE_MS;
1015
- keepers.set(ref, keeper);
1054
+ fs.writeFileSync(launchFile(ref), String(Date.now() + LAUNCH_GRACE_MS), { mode: 0o600 });
1016
1055
  maintainSeatForwards();
1017
1056
  const deadline = Date.now() + timeoutMs;
1018
1057
  for (;;) {
1019
- // A P stored by an earlier process (before a restart) without a running keeper reaches nothing.
1058
+ // A stored P without a ready forward (after a restart, or a keeper just stopped) reaches nothing: wait for one.
1020
1059
  const port = binding(ref).seat_forward_port;
1021
- if (port && forwardLive(ref))
1060
+ if (port && forwardReady(ref, port))
1022
1061
  return port;
1062
+ keep(ref); // takes over at once when the owner stopped and released the lock
1023
1063
  if (Date.now() > deadline)
1024
1064
  throw new RemoteTerminalError("SEAT_FORWARD_UNAVAILABLE", "the seat's MCP route back to this computer is not ready; launch again later");
1025
1065
  await new Promise(resolve => setTimeout(resolve, 250));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.70.17",
3
+ "version": "0.70.18",
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": [