aiterm-mcp 0.70.50 → 0.70.52
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 +14 -1
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/agent-idle.js +2 -0
- package/dist/background-tasks.js +103 -0
- package/dist/core.js +25 -5
- package/dist/index.js +35 -8
- package/dist/remote-terminal.js +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.70.52] - 2026-11-13
|
|
11
|
+
|
|
12
|
+
- seat-turns: a terminal that answers after the 4 s budget no longer leaves its seats unread poll after poll. Its late answer goes to the next poll (once, up to 60 s old), and every relayed row carries `observed_at` (fox under a build: rows stood still for 85 s).
|
|
13
|
+
- A Claude seat on Windows counts the commands its PowerShell tool runs (`cmd /c chcp 65001 & pwsh … $__claudeCodeScript …`) as own work; they read 0 before, so a seat building in the background read idle (Lumani, a68).
|
|
14
|
+
- Own work now includes the harness's own unfinished background tasks (a68). For Claude seats Aiterm reads the transcript: an Agent launched in the background (in-process, no child process) or a background Bash counts until Claude's task notification for it. seat-turns `own_work` gains `tasks` and `task` ({kind, label, since}), `pty_observe` `activity` gains `background_tasks`; a seat with tasks > 0 is not hibernated by the idle clock and `pty_close {hibernate:true}` answers AGENT_BUSY. Other harnesses report null (no statement read yet).
|
|
15
|
+
|
|
16
|
+
## [0.70.51] - 2026-11-13
|
|
17
|
+
|
|
18
|
+
- A hibernated terminal seat stays bound to its terminal. `pty_close {hibernate:true}` unbound it like a real close, so the body read the seat as missing and `pty_close` of it ran locally (already_closed) while the seat stayed hibernated on the terminal.
|
|
19
|
+
- A hibernated seat whose project folder path goes through a symlink resumes again. Claude saves its cwd as a realpath, but the resume check compared the caller's path unresolved, so every resume failed with AGENT_RESUME_CONFLICT (macOS `/tmp`, a cloud-synced folder). Both sides are now compared by realpath.
|
|
20
|
+
|
|
10
21
|
## [0.70.50] - 2026-11-13
|
|
11
22
|
|
|
12
23
|
- seat-turns no longer returns one unknown (null) turn at every turn end for Claude, Grok, Cursor and Antigravity seats. The first ready frame only started the 250 ms settle clock, so a caller polling every ~10 s saw running → unknown → idle; the read now looks once more past the settle time itself.
|
|
@@ -3427,7 +3438,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3427
3438
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3428
3439
|
provenance.
|
|
3429
3440
|
|
|
3430
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.
|
|
3441
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.52...HEAD
|
|
3442
|
+
[0.70.52]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.51...v0.70.52
|
|
3443
|
+
[0.70.51]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.50...v0.70.51
|
|
3431
3444
|
[0.70.50]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.49...v0.70.50
|
|
3432
3445
|
[0.70.49]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.48...v0.70.49
|
|
3433
3446
|
[0.70.48]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.47...v0.70.48
|
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.52** · 動作対象は 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.52** · 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.js
CHANGED
|
@@ -25,6 +25,8 @@ export function decideIdleSeat(seat, now, minutes = 30, expectedAnchor, immediat
|
|
|
25
25
|
return { ...result, reason: "child_delivery_pending_or_unknown" };
|
|
26
26
|
if (seat.post_startup_process_count !== 0)
|
|
27
27
|
return { ...result, reason: "background_work_or_unknown" };
|
|
28
|
+
if ((seat.background_tasks ?? 0) > 0)
|
|
29
|
+
return { ...result, reason: "background_work_or_unknown" };
|
|
28
30
|
if (!seat.vendor_session_id)
|
|
29
31
|
return { ...result, reason: "conversation_id_unavailable" };
|
|
30
32
|
if (!seat.resume_ready)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { claudeSessionTranscriptPath } from "./harnesses/claude.js";
|
|
3
|
+
// One state per transcript, kept by the long-lived reader (seat-turns worker, server): each read parses only new bytes.
|
|
4
|
+
const states = new Map();
|
|
5
|
+
/** Masked like process descriptors: a value that may carry a secret, or a long one, is shortened. */
|
|
6
|
+
export function taskLabel(value, fallback) {
|
|
7
|
+
const text = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
8
|
+
if (!text)
|
|
9
|
+
return fallback;
|
|
10
|
+
if (/=|:\/\/|@/.test(text))
|
|
11
|
+
return "…";
|
|
12
|
+
return text.length > 40 ? `${text.slice(0, 39)}…` : text;
|
|
13
|
+
}
|
|
14
|
+
/** Apply one Claude transcript row to the open/done sets (pure on its inputs; exported for tests). */
|
|
15
|
+
export function applyClaudeTranscriptLine(line, open, done, inputs) {
|
|
16
|
+
// A completion (completed, failed, killed) is a <task-notification> naming the task, queued or delivered.
|
|
17
|
+
for (const match of line.matchAll(/<task-id>([^<\s]+)<\/task-id>/g)) {
|
|
18
|
+
done.add(match[1]);
|
|
19
|
+
open.delete(match[1]);
|
|
20
|
+
}
|
|
21
|
+
if (!line.includes("\"tool_use") && !line.includes("toolUseResult"))
|
|
22
|
+
return;
|
|
23
|
+
let row;
|
|
24
|
+
try {
|
|
25
|
+
row = JSON.parse(line);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const at = typeof row?.timestamp === "string" && Number.isFinite(Date.parse(row.timestamp)) ? new Date(row.timestamp).toISOString() : null;
|
|
31
|
+
for (const part of Array.isArray(row?.message?.content) ? row.message.content : []) {
|
|
32
|
+
if (part?.type === "tool_use" && typeof part.id === "string" && part.input && typeof part.input === "object") {
|
|
33
|
+
inputs.set(part.id, taskLabel(part.input.description ?? part.input.command, ""));
|
|
34
|
+
if (inputs.size > 256)
|
|
35
|
+
inputs.delete(inputs.keys().next().value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const result = row?.toolUseResult;
|
|
39
|
+
if (!result || typeof result !== "object" || !at)
|
|
40
|
+
return;
|
|
41
|
+
const toolUseId = Array.isArray(row?.message?.content) ? row.message.content.find((part) => typeof part?.tool_use_id === "string")?.tool_use_id : undefined;
|
|
42
|
+
const label = (fallback) => (toolUseId && inputs.get(toolUseId)) || fallback;
|
|
43
|
+
if (result.isAsync === true && typeof result.agentId === "string" && !done.has(result.agentId))
|
|
44
|
+
open.set(result.agentId, { kind: "agent", label: taskLabel(result.description, label("agent")), since: at });
|
|
45
|
+
else if (typeof result.backgroundTaskId === "string" && !done.has(result.backgroundTaskId))
|
|
46
|
+
open.set(result.backgroundTaskId, { kind: "shell", label: label("shell"), since: at });
|
|
47
|
+
// A stop tool's own result also ends the task it names.
|
|
48
|
+
for (const key of ["shell_id", "task_id"])
|
|
49
|
+
if (typeof result[key] === "string") {
|
|
50
|
+
done.add(result[key]);
|
|
51
|
+
open.delete(result[key]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Claude's own count of unfinished background tasks of this seat, from its transcript: an async Agent launch
|
|
56
|
+
* (toolUseResult.isAsync + agentId) or a background Bash (toolUseResult.backgroundTaskId) with no <task-notification>
|
|
57
|
+
* naming it yet. Launches before this launch's metadata was created belong to an earlier process and are not counted.
|
|
58
|
+
* null: not a Claude seat, or the transcript cannot be read.
|
|
59
|
+
*/
|
|
60
|
+
export function claudeBackgroundTasks(meta) {
|
|
61
|
+
const file = meta.kind === "claude" ? claudeSessionTranscriptPath(meta) : null;
|
|
62
|
+
if (!file)
|
|
63
|
+
return null;
|
|
64
|
+
let stat;
|
|
65
|
+
try {
|
|
66
|
+
stat = fs.statSync(file);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let state = states.get(file);
|
|
72
|
+
if (!state || state.ino !== stat.ino || stat.size < state.offset)
|
|
73
|
+
states.set(file, state = { ino: stat.ino, offset: 0, partial: "", open: new Map(), done: new Set(), inputs: new Map() });
|
|
74
|
+
if (stat.size > state.offset) {
|
|
75
|
+
let fd = null;
|
|
76
|
+
try {
|
|
77
|
+
fd = fs.openSync(file, "r");
|
|
78
|
+
const buffer = Buffer.alloc(stat.size - state.offset);
|
|
79
|
+
const read = fs.readSync(fd, buffer, 0, buffer.length, state.offset);
|
|
80
|
+
state.offset += read;
|
|
81
|
+
const lines = (state.partial + buffer.subarray(0, read).toString("utf8")).split("\n");
|
|
82
|
+
state.partial = lines.pop() ?? "";
|
|
83
|
+
for (const line of lines)
|
|
84
|
+
if (line)
|
|
85
|
+
applyClaudeTranscriptLine(line, state.open, state.done, state.inputs);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
if (fd !== null)
|
|
92
|
+
fs.closeSync(fd);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const start = Date.parse(meta.created_at);
|
|
96
|
+
const live = [...state.open.values()].filter(task => !Number.isFinite(start) || Date.parse(task.since) >= start - 1000);
|
|
97
|
+
const oldest = live.reduce((first, task) => !first || task.since < first.since ? task : first, null);
|
|
98
|
+
return { count: live.length, oldest };
|
|
99
|
+
}
|
|
100
|
+
/** The harness's own statement of unfinished background tasks; null where the harness gives none Aiterm reads (a68). */
|
|
101
|
+
export function harnessBackgroundTasks(meta) {
|
|
102
|
+
return meta.kind === "claude" ? claudeBackgroundTasks(meta) : null;
|
|
103
|
+
}
|
package/dist/core.js
CHANGED
|
@@ -11,6 +11,7 @@ import { inspectIdleSettings, inspectCodexResumeSettings, codexRecoveryComposer
|
|
|
11
11
|
import { AGENT_TUI_READY_TIMEOUT_MS, AGENT_TUI_FIRST_DRAW_TIMEOUT_MS, AGENT_TUI_READY_POLL_MS, isAgentTuiReady, isAgentTuiBusy, isAgentTuiIdleReady, agentPaneObservation, parentPaneEvidence, waitAgentTuiReadyImpl, detectAgentSubmitResidueImpl, waitCursorPromptVisibleImpl, settleAgentDoneScreenImpl } from "./agent-screen-observation.js";
|
|
12
12
|
export { launchEchoIsLastOnScreen, __testSetAgentTuiReadyStableSamples } from "./agent-screen-observation.js";
|
|
13
13
|
import { parseClaudeOperationMarker } from "./claude-operation-marker.js";
|
|
14
|
+
import { harnessBackgroundTasks } from "./background-tasks.js";
|
|
14
15
|
import { withManagedSpan, observeManagedSpan, closeManagedSpan, managedSpanSettling, MANAGED_SPAN_SETTLE_MS, SPAN_HELD } from "./managed-seat-turn.js";
|
|
15
16
|
/**
|
|
16
17
|
* core — CLI/MCP が共有する端末操作とharness進行(Node/TS 版)。
|
|
@@ -102,6 +103,17 @@ const PTY_PASTE_CHUNK_PAUSE_MS = 10;
|
|
|
102
103
|
// 同期処理の中の短い間(paste chunkの間、server片付け中の一覧の読み直し)。eventループを進めずに待つ。
|
|
103
104
|
const SYNC_PAUSE_BUFFER = new Int32Array(new SharedArrayBuffer(4));
|
|
104
105
|
function pauseSync(ms) { Atomics.wait(SYNC_PAUSE_BUFFER, 0, 0, ms); }
|
|
106
|
+
// A Claude seat saves its cwd as a realpath, so a caller's path through a symlink (macOS /tmp, a cloud-synced folder) is the same project.
|
|
107
|
+
function sameProjectFolder(given, saved) {
|
|
108
|
+
if (path.resolve(given) === saved)
|
|
109
|
+
return true;
|
|
110
|
+
try {
|
|
111
|
+
return fs.realpathSync(given) === fs.realpathSync(saved);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
105
117
|
const SESSION_SEND_LOCK_WAIT_MS = isWin ? 130_000 : 10_000;
|
|
106
118
|
const SESSION_SEND_LOCK_POLL_MS = 25;
|
|
107
119
|
// 同じagent sessionへの送信が重なった時に、前の1通を待つ上限(ADR 0088)。
|
|
@@ -155,7 +167,8 @@ const AGENT_COMMAND_PATTERNS = {
|
|
|
155
167
|
const AGENT_EXEC_SHELLS = {
|
|
156
168
|
// Bash tool and run_in_background (bash/zsh; Git Bash on Windows): the command ends by writing its cwd to claude-<hex>-cwd.
|
|
157
169
|
// Hooks are `sh -c <hook>`, Git Bash or pwsh without that file.
|
|
158
|
-
|
|
170
|
+
// Windows PowerShell tool (2.1.32x, fox 2026-11-14): cmd /d /s /c "chcp 65001 & pwsh … -Command "$__claudeCodeScript = $env:CLAUDE_CODE_SHELL_LAUNCHER_SCRIPT; …"".
|
|
171
|
+
claude: command => /claude-[0-9a-f]+-cwd\b/.test(command) || command.includes("$__claudeCodeScript = $env:CLAUDE_CODE_SHELL_LAUNCHER_SCRIPT"),
|
|
159
172
|
// exec / unified exec: POSIX [shell, -c|-lc, command]; Windows pwsh -Command starting with its UTF-8 console line.
|
|
160
173
|
// Hooks and MCP servers are spawned with their own argv (Windows hooks: pwsh -NoProfile -Command "& ...").
|
|
161
174
|
codex: command => /^\s*\S+\s+-l?c\s/.test(command)
|
|
@@ -1778,13 +1791,14 @@ export async function seatOwnWork(names, requested) {
|
|
|
1778
1791
|
const entries = list?.entries.filter(entry => entry.sessions.includes(name)) ?? [];
|
|
1779
1792
|
const childExcluded = (child) => entries.some(entry => entry.kind === "child"
|
|
1780
1793
|
&& entry.harness === child.harness && (entry.session === null || entry.session === child.session));
|
|
1781
|
-
const work = { processes: null, excluded: 0, child_results: null, exclusions_digest: list?.digest ?? null, oldest: null };
|
|
1794
|
+
const work = { processes: null, excluded: 0, child_results: null, exclusions_digest: list?.digest ?? null, oldest: null, tasks: null, task: null };
|
|
1782
1795
|
result.set(name, work);
|
|
1783
1796
|
try {
|
|
1784
1797
|
const state = agentDormantState(meta);
|
|
1785
1798
|
if (state === "hibernated") {
|
|
1786
1799
|
work.processes = 0;
|
|
1787
1800
|
work.child_results = 0;
|
|
1801
|
+
work.tasks = 0;
|
|
1788
1802
|
continue;
|
|
1789
1803
|
}
|
|
1790
1804
|
if (state !== null || !rows)
|
|
@@ -1801,6 +1815,9 @@ export async function seatOwnWork(names, requested) {
|
|
|
1801
1815
|
continue;
|
|
1802
1816
|
const activityRows = subtree.some(row => row.pid === agent.pid) ? subtree : [...subtree, ...processSubtree(rows, agent.pid)];
|
|
1803
1817
|
work.child_results = pendingChildResultsFor(name, activityRows, childExcluded);
|
|
1818
|
+
const tasks = harnessBackgroundTasks(meta);
|
|
1819
|
+
work.tasks = tasks?.count ?? null;
|
|
1820
|
+
work.task = tasks?.oldest ?? null;
|
|
1804
1821
|
const counted = ownExecProcesses(meta, agent, rows);
|
|
1805
1822
|
const processEntries = entries.filter(entry => entry.kind === "process");
|
|
1806
1823
|
const descriptors = new Map(counted.map(row => [row.pid, processDescriptor(processArgv(row))]));
|
|
@@ -1839,7 +1856,7 @@ function emptySessionObservation(name, exists) {
|
|
|
1839
1856
|
token_hint: null, pending_child_deliveries: null,
|
|
1840
1857
|
activity: { cursor: null, output_changed: null, cpu_seconds: null, cpu_delta_seconds: null, cpu_delta_complete: null,
|
|
1841
1858
|
background_cpu_seconds: null, background_cpu_delta_seconds: null, background_cpu_delta_complete: null,
|
|
1842
|
-
post_startup_process_count: null },
|
|
1859
|
+
post_startup_process_count: null, background_tasks: null },
|
|
1843
1860
|
};
|
|
1844
1861
|
}
|
|
1845
1862
|
function agentDormantState(meta) {
|
|
@@ -1906,6 +1923,7 @@ export function observeSession(name, cursor) {
|
|
|
1906
1923
|
result.activity.cpu_seconds = 0;
|
|
1907
1924
|
result.activity.background_cpu_seconds = 0;
|
|
1908
1925
|
result.activity.post_startup_process_count = 0;
|
|
1926
|
+
result.activity.background_tasks = 0;
|
|
1909
1927
|
return result;
|
|
1910
1928
|
}
|
|
1911
1929
|
/** Native absence before the owned launcher returns does not prove CLI exit. */
|
|
@@ -1931,7 +1949,7 @@ function observeSessionNative(name) {
|
|
|
1931
1949
|
token_hint: null, pending_child_deliveries: null,
|
|
1932
1950
|
activity: { cursor: null, output_changed: null, cpu_seconds: null, cpu_delta_seconds: null, cpu_delta_complete: null,
|
|
1933
1951
|
background_cpu_seconds: null, background_cpu_delta_seconds: null, background_cpu_delta_complete: null,
|
|
1934
|
-
post_startup_process_count: null },
|
|
1952
|
+
post_startup_process_count: null, background_tasks: null },
|
|
1935
1953
|
};
|
|
1936
1954
|
if (!listed)
|
|
1937
1955
|
return { result, native: null };
|
|
@@ -2028,6 +2046,7 @@ function observeNativeSession(name, cursor) {
|
|
|
2028
2046
|
background_cpu_delta_seconds: comparable ? Object.entries(backgroundCpu).reduce((sum, [identity, cpu]) => sum + cpu - (previous.background_processes[identity] ?? 0), 0) : null,
|
|
2029
2047
|
background_cpu_delta_complete: comparable ? Object.keys(previous.background_processes).every(identity => identity in backgroundCpu) : null,
|
|
2030
2048
|
post_startup_process_count: meta && agent ? ownExecProcesses(meta, agent, rows).length : null,
|
|
2049
|
+
background_tasks: meta && agent ? harnessBackgroundTasks(meta)?.count ?? null : null,
|
|
2031
2050
|
};
|
|
2032
2051
|
return result;
|
|
2033
2052
|
}
|
|
@@ -2139,6 +2158,7 @@ export async function checkAgentIdle(expectedInput, expectedAnchor, immediate =
|
|
|
2139
2158
|
attached: slot?.attached ?? (effectIssued ? false : null), turn_settled: settled,
|
|
2140
2159
|
pending_child_deliveries: live.pending_child_deliveries,
|
|
2141
2160
|
post_startup_process_count: live.activity.post_startup_process_count,
|
|
2161
|
+
background_tasks: live.activity.background_tasks,
|
|
2142
2162
|
window_activity_at: slot?.window_activity_at ?? null,
|
|
2143
2163
|
...(immediate && meta.kind === "claude" ? { rate_limited_at: claudeRateLimitedAt(meta) } : {}) };
|
|
2144
2164
|
};
|
|
@@ -8657,7 +8677,7 @@ export async function openAgentWithInitialPrompt(kind, opts = {}) {
|
|
|
8657
8677
|
|| (opts.model != null && opts.model.trim() !== recipe.model)
|
|
8658
8678
|
|| (opts.reasoning_effort != null && opts.reasoning_effort.trim() !== recipe.reasoning_effort)
|
|
8659
8679
|
|| (opts.fast != null && opts.fast !== recipe.fast)
|
|
8660
|
-
|| (opts.cwd != null &&
|
|
8680
|
+
|| (opts.cwd != null && !sameProjectFolder(opts.cwd, recipe.cwd))
|
|
8661
8681
|
|| (opts.write_scope !== undefined && opts.write_scope !== previous.write_scope)
|
|
8662
8682
|
|| (opts.env_vars !== undefined && !isDeepStrictEqual(resumeEnvNames(kind, opts.env_vars), resumeEnvNames(kind, [...Object.keys(recipe.environment), ...recipeSecretNames(recipe)]))))
|
|
8663
8683
|
throw opts.require_existing_resume ? new AgentResumeUnavailableError(name) : new AitermError("AGENT_RESUME_CONFLICT: 同名の休止席は保存したharness・設定・project・明示envで再開します。変更は再開後に行ってください。", 2);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { loadAgentMetadata } from "./agent-metadata-reader.js";
|
|
3
3
|
import { remoteInputDescription, remoteInputSchema, terminalArgumentDescription, terminalArgumentSchema } from "./remote-contract.js";
|
|
4
|
-
import { boundTerminalTarget, bindTerminalSession, terminalSeatGroups, ensureSeatForward, extractMcpHeaders, maintainSeatForwards, REMOTE_MINIMUM_VERSION, REMOTE_CLI_OPS_VERSION, seatIngressPort, checkTerminalPlatform, rewriteSeatMcpConfig, terminalRemoteTarget, unbindTerminalSession, versionAtLeast } from "./remote-terminal.js";
|
|
4
|
+
import { boundTerminalTarget, bindTerminalSession, terminalSeatGroups, ensureSeatForward, extractMcpHeaders, maintainSeatForwards, REMOTE_MINIMUM_VERSION, REMOTE_CLI_OPS_VERSION, seatIngressPort, checkTerminalPlatform, closeEndsTerminalSeat, rewriteSeatMcpConfig, terminalRemoteTarget, unbindTerminalSession, versionAtLeast } from "./remote-terminal.js";
|
|
5
5
|
import { terminalCwdFits } from "./remote-path.js";
|
|
6
6
|
import { launchEnvValue } from "./private-env.js";
|
|
7
7
|
import { AuthResponseError, authUiSchema, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
@@ -354,7 +354,7 @@ export function createAitermServer(options = {}) {
|
|
|
354
354
|
if (!target)
|
|
355
355
|
return handler(args, extra);
|
|
356
356
|
const result = await remoteHandler(target, args, extra);
|
|
357
|
-
if (name === "pty_close" && !remote &&
|
|
357
|
+
if (name === "pty_close" && !remote && closeEndsTerminalSeat(args, result))
|
|
358
358
|
unbindTerminalSession(args.session_id);
|
|
359
359
|
return remote ? result : withErrorCode(result);
|
|
360
360
|
}
|
|
@@ -866,6 +866,11 @@ export function createAitermServer(options = {}) {
|
|
|
866
866
|
}
|
|
867
867
|
});
|
|
868
868
|
const remoteSeatTurnsInFlight = new Map();
|
|
869
|
+
// A terminal's answer that came after its caller's 4 s (a busy terminal, Lumani's build on fox 11/14): the next poll for
|
|
870
|
+
// that terminal takes it once instead of listing the seats unread again, so rows age by one slow read, not by the whole
|
|
871
|
+
// time the terminal stays slow. Each relayed row carries `observed_at`, when its terminal answered.
|
|
872
|
+
const remoteSeatTurnsLate = new Map();
|
|
873
|
+
const REMOTE_SEAT_TURNS_LATE_MAX_MS = 60_000;
|
|
869
874
|
// Declared controller caller markers opt into current-turn metadata (ADR 0122).
|
|
870
875
|
// 説明と引数には出さない(steer-follow.ts の冒頭)。それ以外の呼び手には何も足さない。
|
|
871
876
|
async function seatTurnsMeta(sessions, requestMeta) {
|
|
@@ -886,15 +891,37 @@ export function createAitermServer(options = {}) {
|
|
|
886
891
|
// The request's own timeout is wall-clock: keep it well above the loop-time budget below.
|
|
887
892
|
call = callRemoteTool(target, "pty_list", {}, 15_000, undefined, requestMeta)
|
|
888
893
|
.then(result => result._meta?.[SEAT_TURNS_RESULT_META_KEY] ?? null, () => null)
|
|
894
|
+
.then(answer => ({ answer, at: Date.now() }))
|
|
889
895
|
.finally(() => remoteSeatTurnsInFlight.delete(key));
|
|
890
896
|
remoteSeatTurnsInFlight.set(key, call);
|
|
897
|
+
void call.then(answered => { if (Array.isArray(answered.answer?.seats))
|
|
898
|
+
remoteSeatTurnsLate.set(key, answered); });
|
|
891
899
|
}
|
|
900
|
+
const rows = ({ answer, at }) => Array.isArray(answer?.seats)
|
|
901
|
+
? { seats: answer.seats.filter((seat) => bound.includes(seat?.session_id)).map((seat) => ({ ...seat, route_since, observed_at: new Date(at).toISOString() })),
|
|
902
|
+
unread: Array.isArray(answer.unread) ? answer.unread.filter((name) => bound.includes(name)) : [] }
|
|
903
|
+
: { seats: [], unread: bound };
|
|
904
|
+
// Only the side that decides this poll touches the late answer: the losing side still runs afterwards.
|
|
905
|
+
let decided = false;
|
|
892
906
|
return Promise.race([
|
|
893
|
-
call.then(
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
907
|
+
call.then(answered => {
|
|
908
|
+
if (decided)
|
|
909
|
+
return null;
|
|
910
|
+
decided = true;
|
|
911
|
+
if (remoteSeatTurnsLate.get(key) === answered)
|
|
912
|
+
remoteSeatTurnsLate.delete(key);
|
|
913
|
+
return rows(answered);
|
|
914
|
+
}),
|
|
915
|
+
loopDeadline(4_000, null).then(() => {
|
|
916
|
+
if (decided)
|
|
917
|
+
return null;
|
|
918
|
+
decided = true;
|
|
919
|
+
const late = remoteSeatTurnsLate.get(key);
|
|
920
|
+
if (!late || Date.now() - late.at > REMOTE_SEAT_TURNS_LATE_MAX_MS)
|
|
921
|
+
return { seats: [], unread: bound };
|
|
922
|
+
remoteSeatTurnsLate.delete(key);
|
|
923
|
+
return rows(late);
|
|
924
|
+
}),
|
|
898
925
|
]);
|
|
899
926
|
}));
|
|
900
927
|
// callRemoteTool spawns its ssh only after an await: let the relays start before the local read.
|
|
@@ -940,7 +967,7 @@ export function createAitermServer(options = {}) {
|
|
|
940
967
|
activity: z.object({ cursor: z.string().nullable(), output_changed: z.boolean().nullable(),
|
|
941
968
|
cpu_seconds: z.number().nullable(), cpu_delta_seconds: z.number().nullable(), cpu_delta_complete: z.boolean().nullable(),
|
|
942
969
|
background_cpu_seconds: z.number().nullable(), background_cpu_delta_seconds: z.number().nullable(), background_cpu_delta_complete: z.boolean().nullable(),
|
|
943
|
-
post_startup_process_count: z.number().nullable().optional() }),
|
|
970
|
+
post_startup_process_count: z.number().nullable().optional(), background_tasks: z.number().nullable().optional() }),
|
|
944
971
|
},
|
|
945
972
|
}, async ({ session_id, cursor }, extra) => {
|
|
946
973
|
try {
|
package/dist/remote-terminal.js
CHANGED
|
@@ -740,6 +740,13 @@ function readSeats() {
|
|
|
740
740
|
}
|
|
741
741
|
function writeSeats(seats) { writeJson0600(seatsFile(), { schema: "aiterm.terminal-seats.v1", seats }); }
|
|
742
742
|
export function bindTerminalSession(session, ref) { writeSeats({ ...readSeats(), [session]: ref }); }
|
|
743
|
+
/** Whether a terminal seat's pty_close ended it: a hibernated seat keeps its binding, so its resume and reads still reach the terminal. */
|
|
744
|
+
export function closeEndsTerminalSeat(args, result) {
|
|
745
|
+
if (!result || result.isError)
|
|
746
|
+
return false;
|
|
747
|
+
const outcome = result.structuredContent?.outcome;
|
|
748
|
+
return typeof outcome === "string" ? outcome !== "hibernated" : args.hibernate !== true;
|
|
749
|
+
}
|
|
743
750
|
export function unbindTerminalSession(session) {
|
|
744
751
|
const seats = readSeats();
|
|
745
752
|
if (!(session in seats))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.52",
|
|
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": [
|