aiterm-mcp 0.70.15 → 0.70.17
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 +17 -1
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/agent-idle-clock.js +24 -7
- package/dist/core.js +33 -4
- package/dist/index.js +2 -0
- package/dist/remote-terminal.js +85 -39
- package/dist/remote.js +6 -5
- package/dist/steer-follow.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.70.17] - 2026-11-11
|
|
11
|
+
|
|
12
|
+
- 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`.
|
|
13
|
+
- An Aiterm program missing on the terminal (exit 127) now ends as `REMOTE_AITERM_UNAVAILABLE` with an action (install Aiterm with its programs on the login PATH, or provision the terminal), instead of `COMMAND_FAILED`.
|
|
14
|
+
|
|
15
|
+
- After a restart of the controlling host (for example a container restart, which starts a new pid namespace), a terminal's seat MCP forward is started again. The forward lock kept only the old keeper's pid. The new host reused that number at once, here for a thread of a long-lived process, and `kill(pid, 0)` succeeds on a Linux thread id too, so the lock read as held and no process started the forward. Every seat on that terminal lost its BellTeam MCP tools. The lock now also records the boot time and, on Linux, the process start time; a pid that differs in either, or a thread id in an older lock, is not the owner. macOS and Windows have no thread ids in the pid space; a lock from an earlier boot is now also ignored there.
|
|
16
|
+
- A terminal launch no longer receives the stored seat forward port when no keeper is running. Before, the port kept from the previous host was returned at once and the seat started with an MCP URL that reached nothing. Now the launch waits for the new keeper's ssh, or ends with `SEAT_FORWARD_UNAVAILABLE`.
|
|
17
|
+
|
|
18
|
+
## [0.70.16] - 2026-11-11
|
|
19
|
+
|
|
20
|
+
- `pty_list` no longer starts an idle-clock checker process for every hibernated, closed or dead seat on every call. A seat without a live session retires its clock at once, so each list re-spawned a checker for it (about 30 per call on a BellTeam host with 50 saved seats and 18 live). The sweep now covers only seats with a live terminal session, and confirms all clock owners with one process read instead of one per seat. On that host this load kept the serving process busy 95 % of the time, with stretches up to 7 s, so a terminal relay's answer often arrived after the 4 s budget and the terminal's seats came back `unread`.
|
|
21
|
+
- The terminal relays of `pty_list` seat turns now really start before the local read. `callRemoteTool` spawns its ssh only after an `await`, so every relay used to start after the synchronous local read.
|
|
22
|
+
- A freshly launched Codex seat that has taken no input reads `idle` in seat turns, instead of `null` until its first turn. Codex writes no rollout before the first input. Aiterm now answers idle when it recorded no input for the launch and the pane is a ready composer.
|
|
23
|
+
|
|
10
24
|
## [0.70.15] - 2026-11-11
|
|
11
25
|
|
|
12
26
|
- An antigravity-cli turn stopped by the account quota now ends as `rate_limited` with the limit line in `rate_limit` (for example "Individual quota reached. ... Resets in 73h4m30s."), as Claude Code, Codex, Grok and Cursor already did. agy ends such a turn with `terminationReason: ERROR` and names the limit only in its Stop hook `error` (`RESOURCE_EXHAUSTED (code 429)`). Aiterm's hook now keeps that text in the turn's record. Before, the caller saw a generic turn error ("Antigravity execution ended: ERROR") and the reason was on the pane only. Other agy turn errors now carry agy's error text after the reason.
|
|
@@ -3255,7 +3269,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3255
3269
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3256
3270
|
provenance.
|
|
3257
3271
|
|
|
3258
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.
|
|
3272
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.17...HEAD
|
|
3273
|
+
[0.70.17]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.16...v0.70.17
|
|
3274
|
+
[0.70.16]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.15...v0.70.16
|
|
3259
3275
|
[0.70.15]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.14...v0.70.15
|
|
3260
3276
|
[0.70.14]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.13...v0.70.14
|
|
3261
3277
|
[0.70.13]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.12...v0.70.13
|
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.
|
|
218
|
+
**状態:** 開発継続中 · 現行公開版 **v0.70.17** · 動作対象は 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.
|
|
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).
|
|
231
231
|
|
|
232
232
|
### Update and rollback
|
|
233
233
|
|
package/dist/agent-idle-clock.js
CHANGED
|
@@ -82,19 +82,36 @@ export async function armAgentIdleClock(meta, anchor, wakeAt, replaceToken) {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
export function requestAgentIdleClock(session, launchId) {
|
|
85
|
+
requestAgentIdleClocks([{ session, launchId }]);
|
|
86
|
+
}
|
|
87
|
+
/** Starts a checker for each seat whose clock owner is gone; every owner is confirmed with one process read. */
|
|
88
|
+
export function requestAgentIdleClocks(seats) {
|
|
85
89
|
if (!AGENT_IDLE_ENABLED)
|
|
86
90
|
return;
|
|
91
|
+
const wanted = [];
|
|
92
|
+
for (const { session, launchId } of seats) {
|
|
93
|
+
try {
|
|
94
|
+
if (!readAgentResumeNative({ aiterm_session: session, launch_id: launchId }))
|
|
95
|
+
continue;
|
|
96
|
+
wanted.push({ session, launchId, clock: readAgentIdleClock({ aiterm_session: session, launch_id: launchId }) });
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
process.stderr.write("aiterm: idle_clock_state_unconfirmed\n");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const owners = wanted.flatMap(seat => seat.clock ? [seat.clock.owner.pid] : []);
|
|
103
|
+
let alive;
|
|
87
104
|
try {
|
|
88
|
-
|
|
89
|
-
return;
|
|
90
|
-
const clock = readAgentIdleClock({ aiterm_session: session, launch_id: launchId });
|
|
91
|
-
if (clock && readProcessIdentities([clock.owner.pid]).some(row => row.started_identity === clock.owner.started_identity))
|
|
92
|
-
return;
|
|
105
|
+
alive = new Set(owners.length ? readProcessIdentities(owners).map(row => `${row.pid}:${row.started_identity}`) : []);
|
|
93
106
|
}
|
|
94
107
|
catch {
|
|
95
108
|
process.stderr.write("aiterm: idle_clock_state_unconfirmed\n");
|
|
96
109
|
return;
|
|
97
110
|
}
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
for (const { session, launchId, clock } of wanted) {
|
|
112
|
+
if (clock && alive.has(`${clock.owner.pid}:${clock.owner.started_identity}`))
|
|
113
|
+
continue;
|
|
114
|
+
void detached(idleClockCommand(0, liveNodeExecutable(), [CLI, "--session", session, "--launch", launchId]))
|
|
115
|
+
.catch(() => { process.stderr.write("aiterm: idle_clock_start_failed\n"); });
|
|
116
|
+
}
|
|
100
117
|
}
|
package/dist/core.js
CHANGED
|
@@ -38,7 +38,7 @@ import { withCodexGoal } from "./harnesses/codex-goal.js";
|
|
|
38
38
|
import { configureWithPausedGoal } from "./configure-goal.js";
|
|
39
39
|
import { initializeAgentActivity, recordAgentInput, recordAgentTurnEnd, readAgentActivity } from "./agent-activity.js";
|
|
40
40
|
import { checkIdleSeat, decideIdleSeat, idleMinutes } from "./agent-idle.js";
|
|
41
|
-
import { AGENT_IDLE_ENABLED, armAgentIdleClock, idleClockDeadline, isAgentIdleClockOwner, requestAgentIdleClock } from "./agent-idle-clock.js";
|
|
41
|
+
import { AGENT_IDLE_ENABLED, armAgentIdleClock, idleClockDeadline, isAgentIdleClockOwner, requestAgentIdleClock, requestAgentIdleClocks } from "./agent-idle-clock.js";
|
|
42
42
|
import { stopProcessTree } from "./process-tree-stop.js";
|
|
43
43
|
import { writeAgentResumeRecoveryOrigin, confirmedAgentResumeRecoveryOrigin, readAgentResumeResolution, writeAgentResumeResolution, agentResumeRecordDigest, captureAgentResumeTemplate, readAgentResumeTemplate, writeAgentResumeTemplate, finishAgentResumeConfiguration, refreshAgentResumeRecipe, readAgentIdleClock, retireAgentIdleClock, readAgentResumeRecipe, writeAgentResumeRecipe, agentResumeRecipeDigest, readAgentLifecycle, writeAgentLifecycle, cancelAgentStopping, readAgentResumeAttempt, writeAgentResumeAttempt, readAgentResumeNative, writeAgentResumeNative } from "./agent-lifecycle.js";
|
|
44
44
|
import { createCodexGoalObjective, editCodexGoalObjective, submitCodexGoalCommand } from "./harnesses/codex-goal-editor.js";
|
|
@@ -70,7 +70,7 @@ import { codexAuthPlan, codexAuthStatus, codexAuthPane, realCodexHome, readCodex
|
|
|
70
70
|
import { claudeAuthPlan, claudeAuthStatus, claudeAuthPane, OPERATION_ID_RE, CLAUDE_RESULT_MAX_BYTES, CLAUDE_EFFORTS, agentClaudeOperationPath, agentClaudeApprovalReceiptPath, agentClaudeDispatchReceiptPath, validateOperationId, readClaudeResultText, assertClaudeAuthenticationReady, claudeModelChoices, claudeConfigDir, claudeProjectSlug, claudeFastIndicatorShown, claudeFastResult, buildClaudeAgentCmd, claudeAgentArgv, claudeResumeArgv, claudeLaunchNote, claudePaneObservation, CLAUDE_INTERRUPT_KEY, claudeUsageLimit, claudeLiveSelectMenu, claudeStartupAction, createClaudeAgentMetadata, writeClaudeCallerFiles, claudeSessionTranscriptPath, claudeApiErrorFromLine, claudeApiErrorAfter, claudeApiErrorEndingTurn, claudeFailureCategory, } from "./harnesses/claude.js";
|
|
71
71
|
import { cursorAuthPlan, cursorAuthStatus, cursorAuthPane, bindCursorTranscriptSession, cursorTurnBoundary, latestCursorCompletion, cursorTranscript, cursorTranscriptSessionId, observeCursorDone, cursorTranscriptText, assertCursorAuthenticationReady, assertCursorModelAvailable, cursorModelChoices, cursorModelIsFastVariant, cursorFastParameter, cursorHeaderShowsFast, cursorPickerView, cursorEffortSelected, cursorParameterRows, cursorUserConfigPath, CURSOR_DEFAULT_MODEL_KEYS, realCursorHome, buildCursorAgentCmd, cursorAgentArgv, cursorPromptWithLineage, cursorLineagePreface, writeCursorCallerFiles, checkCursorCallerInput, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
72
72
|
import { interimFromNow, interimFromToken, readInterimWords, recordInterimBoundary } from "./interim-words.js";
|
|
73
|
-
import { codexSeatTurn, grokSteerAcceptance, observeSteerDone, readSteerEntry, recordSteer } from "./steer-follow.js";
|
|
73
|
+
import { codexSeatAwaitingRollout, codexSeatTurn, grokSteerAcceptance, observeSteerDone, readSteerEntry, recordSteer } from "./steer-follow.js";
|
|
74
74
|
import { resolveAgentBin, resolveThroughlineBin, runThroughlineHandoffContext, isWindowsNativeExecutable, isUsableAgentExecutableFile, agentBinForPaneShell, resolveWinPaneShell, windowsAgentArgv, windowsAgentLaunchLine, windowsLaunchIndirection } from "./agent-resolver.js";
|
|
75
75
|
export { AitermError } from "./errors.js";
|
|
76
76
|
export { tmuxSpawnEnv } from "./tmux-runtime.js";
|
|
@@ -2031,16 +2031,32 @@ export async function serviceAgentIdleClock(expectedInput, token) {
|
|
|
2031
2031
|
export async function maintainAgentIdleClocks() {
|
|
2032
2032
|
if (!AGENT_IDLE_ENABLED)
|
|
2033
2033
|
return;
|
|
2034
|
+
// Only seats with a live terminal session: a hibernated, closed or dead seat retires its clock at once, so requesting
|
|
2035
|
+
// one on every list started a checker process per such seat per call (2026-11-11: ~30 per pty_list on the BellTeam host).
|
|
2036
|
+
let live;
|
|
2037
|
+
try {
|
|
2038
|
+
const listed = tmux("list-sessions", "-F", "#{session_name}");
|
|
2039
|
+
if (listed.code !== 0)
|
|
2040
|
+
return;
|
|
2041
|
+
live = new Set(listed.stdout.split(/\r?\n/).filter(Boolean));
|
|
2042
|
+
}
|
|
2043
|
+
catch {
|
|
2044
|
+
return;
|
|
2045
|
+
} // no usable tmux here: no live seat to time, and the list call itself must not fail
|
|
2046
|
+
const seats = [];
|
|
2034
2047
|
for (const name of savedAgentSessionNames()) {
|
|
2048
|
+
if (!live.has(name))
|
|
2049
|
+
continue;
|
|
2035
2050
|
try {
|
|
2036
2051
|
const meta = loadAgentMetadata(name);
|
|
2037
2052
|
if (["claude", "codex"].includes(meta.kind))
|
|
2038
|
-
|
|
2053
|
+
seats.push({ session: name, launchId: meta.launch_id });
|
|
2039
2054
|
}
|
|
2040
2055
|
catch {
|
|
2041
2056
|
process.stderr.write("aiterm: idle_clock_sweep_unconfirmed\n");
|
|
2042
2057
|
}
|
|
2043
2058
|
}
|
|
2059
|
+
requestAgentIdleClocks(seats);
|
|
2044
2060
|
}
|
|
2045
2061
|
/** Private guarded-runtime read. Legacy metadata without an original native
|
|
2046
2062
|
* creator stamp remains a present but unverified generation, never enrolled
|
|
@@ -3762,7 +3778,7 @@ export function readSeatTurns(sessionIds) {
|
|
|
3762
3778
|
try {
|
|
3763
3779
|
const state = agentDormantState(meta);
|
|
3764
3780
|
turn = state ? (state === "hibernated" && observeSession(name).state === "hibernated" ? { state: "idle" } : null)
|
|
3765
|
-
: meta.kind === "codex" ? codexSeatTurn(meta) : readManagedSeatTurn(meta);
|
|
3781
|
+
: meta.kind === "codex" ? codexSeatTurn(meta) ?? freshCodexSeatTurn(meta) : readManagedSeatTurn(meta);
|
|
3766
3782
|
}
|
|
3767
3783
|
catch { /* 読めない席は、分からないまま返す */ }
|
|
3768
3784
|
if (turn === SPAN_HELD) {
|
|
@@ -3781,6 +3797,19 @@ export function readSeatTurns(sessionIds) {
|
|
|
3781
3797
|
seat.turn = null;
|
|
3782
3798
|
return { schema: "aiterm.seat-turns.v1", seats, unread };
|
|
3783
3799
|
}
|
|
3800
|
+
/**
|
|
3801
|
+
* Codex writes no rollout before its first input, so codexSeatTurn has nothing to read for a fresh launch. A launch that
|
|
3802
|
+
* never took input (Aiterm records every input it types) and whose pane is a ready composer has no turn to hide: idle,
|
|
3803
|
+
* the rule the other harnesses got in 0.64.1 / 0.68.1. Any recorded input keeps the rollout as the only source.
|
|
3804
|
+
*/
|
|
3805
|
+
export function freshCodexSeatTurn(meta, paneState = () => observeSession(meta.aiterm_session).state) {
|
|
3806
|
+
if (!codexSeatAwaitingRollout(meta))
|
|
3807
|
+
return null;
|
|
3808
|
+
const activity = readAgentActivity(meta);
|
|
3809
|
+
if (!activity.tracked || activity.last_input_at !== null)
|
|
3810
|
+
return null;
|
|
3811
|
+
return paneState() === "idle" ? { state: "idle" } : null;
|
|
3812
|
+
}
|
|
3784
3813
|
function managedSeatConversation(meta) {
|
|
3785
3814
|
if (meta.kind === "antigravity") {
|
|
3786
3815
|
const bound = antigravityBinding(meta);
|
package/dist/index.js
CHANGED
|
@@ -867,6 +867,8 @@ export function createAitermServer(options = {}) {
|
|
|
867
867
|
loopDeadline(4_000, { seats: [], unread: bound }),
|
|
868
868
|
]);
|
|
869
869
|
}));
|
|
870
|
+
// callRemoteTool spawns its ssh only after an await: let the relays start before this process blocks on the local read.
|
|
871
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
870
872
|
const local = core.readSeatTurns(sessions.filter(session => session.harness !== null).map(session => session.session_id));
|
|
871
873
|
const remote = await relays;
|
|
872
874
|
return { _meta: { [SEAT_TURNS_RESULT_META_KEY]: { ...local, seats: [...local.seats, ...remote.flatMap(r => r.seats)], unread: [...local.unread, ...remote.flatMap(r => r.unread)] } } };
|
package/dist/remote-terminal.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createRequire } from "node:module";
|
|
|
10
10
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
11
11
|
import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
|
|
12
12
|
import { ensureStateRoot, writeJson0600 } from "./agent-shared.js";
|
|
13
|
-
import {
|
|
13
|
+
import { powershellForShell, remotePlatform, remoteShell, terminalCommand, terminalProgram } from "./remote.js";
|
|
14
14
|
import { PRIVATE_ENV_SCHEMA } from "./private-env.js";
|
|
15
15
|
import { checkRemotePath } from "./remote-path.js";
|
|
16
16
|
const pkg = createRequire(import.meta.url)("../package.json");
|
|
@@ -167,6 +167,16 @@ export function confirmHostKey(ref, fingerprint) {
|
|
|
167
167
|
return bindingStatus(ref);
|
|
168
168
|
}
|
|
169
169
|
// ---- connection ----
|
|
170
|
+
const AITERM_MISSING_ACTION = "install Aiterm on the terminal with its programs on the login PATH (npm install -g aiterm-mcp), or provision the terminal";
|
|
171
|
+
/** 255 = ssh failed; 127 = an Aiterm program is missing on the terminal (terminalProgram exits so on every shell). */
|
|
172
|
+
function failedRun(result) {
|
|
173
|
+
if (result.code === 127)
|
|
174
|
+
return new RemoteTerminalError("REMOTE_AITERM_UNAVAILABLE", "an Aiterm program is missing on the terminal (Aiterm is incomplete there)", AITERM_MISSING_ACTION);
|
|
175
|
+
if (result.code !== 255)
|
|
176
|
+
return null;
|
|
177
|
+
const f = classifySshFailure(result.stderr);
|
|
178
|
+
return new RemoteTerminalError(f.code, f.message, f.action);
|
|
179
|
+
}
|
|
170
180
|
export function classifySshFailure(stderr) {
|
|
171
181
|
if (/REMOTE HOST IDENTIFICATION HAS CHANGED|Host key for .* has changed/i.test(stderr))
|
|
172
182
|
return { code: "HOST_KEY_MISMATCH", message: "the terminal presented a different host key", action: "confirm the new host key" };
|
|
@@ -176,7 +186,7 @@ export function classifySshFailure(stderr) {
|
|
|
176
186
|
return { code: "AUTH_FAILED", message: "the terminal refused the key" };
|
|
177
187
|
// POSIX, our own Windows guard (any language), and the English cmd / PowerShell wording when it names an Aiterm program.
|
|
178
188
|
if (/aiterm-[\w-]+: (command )?not found|aiterm-[\w-]+: No such file|aiterm-[\w-]+['"]? is not recognized as (an internal or external command|(the|a) name of a cmdlet)/i.test(stderr))
|
|
179
|
-
return { code: "REMOTE_AITERM_UNAVAILABLE", message: "Aiterm is not installed on the terminal" };
|
|
189
|
+
return { code: "REMOTE_AITERM_UNAVAILABLE", message: "Aiterm is not installed on the terminal", action: AITERM_MISSING_ACTION };
|
|
180
190
|
if (/Connection refused/i.test(stderr))
|
|
181
191
|
return { code: "CONNECTION_REFUSED", message: "the terminal refused the SSH connection" };
|
|
182
192
|
if (/timed out|No route to host|Network is unreachable|Could not resolve|Connection closed|Connection reset/i.test(stderr))
|
|
@@ -505,17 +515,17 @@ export class RemoteTerminalConnection extends EventEmitter {
|
|
|
505
515
|
return parsed;
|
|
506
516
|
if (parsed?.code)
|
|
507
517
|
throw new RemoteTerminalError(parsed.code, parsed.message ?? "transcript read failed");
|
|
508
|
-
|
|
509
|
-
const f =
|
|
510
|
-
|
|
518
|
+
{
|
|
519
|
+
const f = failedRun(result);
|
|
520
|
+
if (f)
|
|
521
|
+
throw f;
|
|
511
522
|
}
|
|
512
523
|
throw new RemoteTerminalError("COMMAND_FAILED", "the transcript reader failed on the terminal");
|
|
513
524
|
}
|
|
514
525
|
/** Run the terminal's aiterm-wait with the flags of a receipt's wait_process; its one-line JSON comes back unchanged. */
|
|
515
526
|
async wait(waitProcess, signal) {
|
|
516
527
|
const flags = waitArguments(waitProcess?.args);
|
|
517
|
-
|
|
518
|
-
const result = await this.exec({ posix: `${WAIT_RESOLVE}; exec "$w" ${flags.join(" ")}`, windows: terminalProgram(["aiterm-wait", ...flags]).windows }, 90_000_000, signal);
|
|
528
|
+
const result = await this.exec(terminalProgram(["aiterm-wait", ...flags]), 90_000_000, signal);
|
|
519
529
|
if (signal?.aborted)
|
|
520
530
|
throw new RemoteTerminalError("WAIT_CANCELLED", "the wait was cancelled");
|
|
521
531
|
const line = result.stdout.trim().split("\n").pop() ?? "";
|
|
@@ -523,11 +533,7 @@ export class RemoteTerminalConnection extends EventEmitter {
|
|
|
523
533
|
return JSON.parse(line);
|
|
524
534
|
}
|
|
525
535
|
catch {
|
|
526
|
-
|
|
527
|
-
const f = classifySshFailure(result.stderr);
|
|
528
|
-
throw new RemoteTerminalError(f.code, f.message, f.action);
|
|
529
|
-
}
|
|
530
|
-
throw new RemoteTerminalError("COMMAND_FAILED", "aiterm-wait returned no receipt");
|
|
536
|
+
throw failedRun(result) ?? new RemoteTerminalError("COMMAND_FAILED", "aiterm-wait returned no receipt");
|
|
531
537
|
}
|
|
532
538
|
}
|
|
533
539
|
async command(op, targetPath, harness) {
|
|
@@ -596,9 +602,10 @@ export class RemoteTerminalConnection extends EventEmitter {
|
|
|
596
602
|
throw new RemoteTerminalError("REMOTE_AITERM_TOO_OLD", `the terminal runs Aiterm ${this.remoteVersion}; ${minimum} or later is required (provision the terminal)`);
|
|
597
603
|
const sub = op === "path_status" ? "path-status" : "make-dir";
|
|
598
604
|
const result = await this.exec(terminalProgram(["aiterm-remote-terminal", sub, "--path-base64", Buffer.from(targetPath, "utf8").toString("base64")]), 60_000);
|
|
599
|
-
|
|
600
|
-
const f =
|
|
601
|
-
|
|
605
|
+
{
|
|
606
|
+
const f = failedRun(result);
|
|
607
|
+
if (f)
|
|
608
|
+
throw f;
|
|
602
609
|
}
|
|
603
610
|
let parsed = null;
|
|
604
611
|
try {
|
|
@@ -620,9 +627,10 @@ export class RemoteTerminalConnection extends EventEmitter {
|
|
|
620
627
|
throw new RemoteTerminalError("REMOTE_AITERM_TOO_OLD", `the terminal runs Aiterm ${this.remoteVersion}; ${minimum} or later is required (update or provision the terminal)`);
|
|
621
628
|
const flag = targetPath === undefined ? [] : ["--path-base64", Buffer.from(targetPath, "utf8").toString("base64")];
|
|
622
629
|
const result = await this.exec(terminalProgram(["aiterm-remote-terminal", "list-dirs", ...flag]), 60_000);
|
|
623
|
-
|
|
624
|
-
const f =
|
|
625
|
-
|
|
630
|
+
{
|
|
631
|
+
const f = failedRun(result);
|
|
632
|
+
if (f)
|
|
633
|
+
throw f;
|
|
626
634
|
}
|
|
627
635
|
let parsed = null;
|
|
628
636
|
try {
|
|
@@ -807,43 +815,80 @@ function writeBinding(ref, change) {
|
|
|
807
815
|
writeJson0600(storePath(), { schema: "aiterm.remote-bindings.v1", bindings });
|
|
808
816
|
}
|
|
809
817
|
function lockFile(ref) { return path.join(ensureStateRoot(), `terminal-forward-${ref}.lock`); }
|
|
818
|
+
function lockOwner(ref) {
|
|
819
|
+
try {
|
|
820
|
+
return JSON.parse(fs.readFileSync(lockFile(ref), "utf8"));
|
|
821
|
+
}
|
|
822
|
+
catch {
|
|
823
|
+
return null; /* absent or unreadable: no owner */
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
const bootTime = () => Math.round(Date.now() / 1000 - os.uptime());
|
|
827
|
+
/** Linux: the start time (field 22 of /proc/<pid>/stat, counted after the comm's last ") "); null elsewhere. */
|
|
828
|
+
function procStart(pid) {
|
|
829
|
+
try {
|
|
830
|
+
return fs.readFileSync(`/proc/${pid}/stat`, "utf8").split(") ").pop().split(" ")[19] ?? null;
|
|
831
|
+
}
|
|
832
|
+
catch {
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
/** T3: the recorded owner is this same process still running, not a later process or a thread given the same number. */
|
|
837
|
+
function ownerAlive(owner) {
|
|
838
|
+
const pid = Number(owner.pid);
|
|
839
|
+
if (!(pid > 0))
|
|
840
|
+
return false;
|
|
841
|
+
try {
|
|
842
|
+
process.kill(pid, 0);
|
|
843
|
+
}
|
|
844
|
+
catch {
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
if (typeof owner.boot === "number" && Math.abs(owner.boot - bootTime()) > 60)
|
|
848
|
+
return false; // from an earlier boot
|
|
849
|
+
if (process.platform !== "linux")
|
|
850
|
+
return true; // shortcut: a pid reused within one boot looks alive until that process exits
|
|
851
|
+
// A container restart reuses pids at once, and kill(pid, 0) also succeeds on a thread id (0.70.16 stayed down).
|
|
852
|
+
if (typeof owner.start === "string")
|
|
853
|
+
return procStart(pid) === owner.start;
|
|
854
|
+
try {
|
|
855
|
+
return /^Tgid:\s*(\d+)$/m.exec(fs.readFileSync(`/proc/${pid}/status`, "utf8"))?.[1] === String(pid);
|
|
856
|
+
}
|
|
857
|
+
catch {
|
|
858
|
+
return true;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
810
861
|
/** T3: true when this process holds the keeper lock for ref (taking it from a dead owner). */
|
|
811
862
|
function holdLock(ref) {
|
|
812
863
|
const file = lockFile(ref);
|
|
813
864
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
814
865
|
try {
|
|
815
|
-
fs.writeFileSync(file, JSON.stringify({ pid: process.pid }), { flag: "wx", mode: 0o600 });
|
|
866
|
+
fs.writeFileSync(file, JSON.stringify({ pid: process.pid, boot: bootTime(), start: procStart(process.pid) }), { flag: "wx", mode: 0o600 });
|
|
816
867
|
return true;
|
|
817
868
|
}
|
|
818
869
|
catch (error) {
|
|
819
870
|
if (error.code !== "EEXIST")
|
|
820
871
|
return false;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
pid = Number(JSON.parse(fs.readFileSync(file, "utf8")).pid);
|
|
824
|
-
}
|
|
825
|
-
catch { /* unreadable: treat as dead */ }
|
|
826
|
-
if (pid === process.pid)
|
|
872
|
+
const owner = lockOwner(ref);
|
|
873
|
+
if (Number(owner?.pid) === process.pid)
|
|
827
874
|
return true;
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
if (pid > 0) {
|
|
831
|
-
process.kill(pid, 0);
|
|
832
|
-
return false;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
catch { /* owner gone */ }
|
|
875
|
+
if (owner && ownerAlive(owner))
|
|
876
|
+
return false;
|
|
836
877
|
fs.rmSync(file, { force: true });
|
|
837
878
|
}
|
|
838
879
|
}
|
|
839
880
|
return false;
|
|
840
881
|
}
|
|
841
882
|
function releaseLock(ref) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
883
|
+
if (Number(lockOwner(ref)?.pid) === process.pid)
|
|
884
|
+
fs.rmSync(lockFile(ref), { force: true });
|
|
885
|
+
}
|
|
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) {
|
|
888
|
+
const owner = lockOwner(ref);
|
|
889
|
+
if (!owner)
|
|
890
|
+
return false;
|
|
891
|
+
return Number(owner.pid) === process.pid ? Boolean(keepers.get(ref)?.child) : ownerAlive(owner);
|
|
847
892
|
}
|
|
848
893
|
function forwardNeeded(ref) {
|
|
849
894
|
return (keepers.get(ref)?.launchUntil ?? 0) > Date.now() || Object.values(readSeats()).includes(ref);
|
|
@@ -971,8 +1016,9 @@ export async function ensureSeatForward(ref, ingress, timeoutMs = 30_000) {
|
|
|
971
1016
|
maintainSeatForwards();
|
|
972
1017
|
const deadline = Date.now() + timeoutMs;
|
|
973
1018
|
for (;;) {
|
|
1019
|
+
// A P stored by an earlier process (before a restart) without a running keeper reaches nothing.
|
|
974
1020
|
const port = binding(ref).seat_forward_port;
|
|
975
|
-
if (port)
|
|
1021
|
+
if (port && forwardLive(ref))
|
|
976
1022
|
return port;
|
|
977
1023
|
if (Date.now() > deadline)
|
|
978
1024
|
throw new RemoteTerminalError("SEAT_FORWARD_UNAVAILABLE", "the seat's MCP route back to this computer is not ready; launch again later");
|
package/dist/remote.js
CHANGED
|
@@ -193,8 +193,11 @@ export const powershellInvoke = (argv) => `& ${argv.map(powershellQuote).join("
|
|
|
193
193
|
/** 固定のプログラム呼び出し。windowsのaiterm-*は、無い時に言語によらず読める`command not found`を出す。 */
|
|
194
194
|
export function terminalProgram(argv) {
|
|
195
195
|
const [program] = argv;
|
|
196
|
+
const file = program.startsWith("aiterm-") ? pkg.bin[program]?.replace(/^dist\//, "") : undefined;
|
|
196
197
|
return {
|
|
197
|
-
|
|
198
|
+
// npm may link only aiterm-mcp onto PATH: then the program runs from the same package; else the shell's exit 127.
|
|
199
|
+
posix: file ? `p=$(command -v ${program}) || p="$(dirname "$(readlink -f "$(command -v aiterm-mcp)")")/${file}"; [ -x "$p" ] || p=${program}; exec "$p" ${argv.slice(1).join(" ")}`.trimEnd()
|
|
200
|
+
: `exec ${argv.join(" ")}`,
|
|
198
201
|
windows: `${program.startsWith("aiterm-") ? `if (-not (Get-Command ${powershellQuote(program)} -ErrorAction SilentlyContinue)) { [Console]::Error.WriteLine(${powershellQuote(`${program}: command not found`)}); exit 127 }; ` : ""}${powershellInvoke(argv)}`,
|
|
199
202
|
};
|
|
200
203
|
}
|
|
@@ -264,8 +267,6 @@ export async function callRemoteTool(target, name, args, timeoutMs = 600_000, pr
|
|
|
264
267
|
await client.close().catch(() => { });
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
|
-
// npmのbinをPATHへ通さず aiterm-mcp だけリンクしている端末がある。見つからなければ同じpackageのCLIを使う。
|
|
268
|
-
export const WAIT_RESOLVE = 'w=$(command -v aiterm-wait) || w="$(dirname "$(readlink -f "$(command -v aiterm-mcp)")")/aiterm-wait-cli.js"';
|
|
269
270
|
const SESSION_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
270
271
|
const OPERATION_RE = /^sha256:[0-9a-f]{64}$/;
|
|
271
272
|
export function remoteWaitCommand(shell, session, cursor, operationId, timeout, inputId, trusted = false) {
|
|
@@ -283,10 +284,10 @@ export function remoteWaitCommand(shell, session, cursor, operationId, timeout,
|
|
|
283
284
|
if (inputId !== undefined)
|
|
284
285
|
parts.push("--input", inputId);
|
|
285
286
|
if (trusted)
|
|
286
|
-
return terminalCommand(shell,
|
|
287
|
+
return terminalCommand(shell, terminalProgram(["aiterm-wait", ...parts]));
|
|
287
288
|
if (shell !== "posix")
|
|
288
289
|
return `aiterm-wait ${parts.join(" ")}`;
|
|
289
|
-
return posixCommand(
|
|
290
|
+
return posixCommand(terminalProgram(["aiterm-wait", ...parts]).posix);
|
|
290
291
|
}
|
|
291
292
|
/** 親が別processで起動する完了待ち。ssh越しのaiterm-waitで、exit codeは現地のaiterm-waitをそのまま返す。 */
|
|
292
293
|
export async function remoteWaitProcess(target, session, cursor, inputId) {
|
package/dist/steer-follow.js
CHANGED
|
@@ -611,6 +611,10 @@ function codexSeatTranscript(meta) {
|
|
|
611
611
|
* (実物 2026-10-13: 最初の番の間も、終わった後も、会話のIDは席の登録に入っていなかった)。
|
|
612
612
|
* harnessが落ちた席は、終わりの印が書かれないので、動いていると読んだままになる(呼び手は、席が閉じた事を待ちのclosedで知る)。
|
|
613
613
|
*/
|
|
614
|
+
/** codexSeatTurn's last look found no rollout for this unbound launch (Codex writes none before the first input). */
|
|
615
|
+
export function codexSeatAwaitingRollout(meta) {
|
|
616
|
+
return meta.kind === "codex" && !meta.vendor_session_id && codexSeatUnresolved.get(meta.aiterm_session)?.key === `${meta.launch_id}:`;
|
|
617
|
+
}
|
|
614
618
|
export function codexSeatTurn(meta, now = performance.now()) {
|
|
615
619
|
if (meta.kind !== "codex")
|
|
616
620
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.17",
|
|
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": [
|