aiterm-mcp 0.70.51 → 0.70.53
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 +19 -1
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/agent-idle.js +2 -0
- package/dist/background-tasks.js +290 -0
- package/dist/core.js +13 -4
- package/dist/index.js +33 -6
- package/dist/remote.js +10 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.70.53] - 2026-11-13
|
|
11
|
+
|
|
12
|
+
- A call that hangs on a terminal no longer freezes that terminal's seat reads. The warm connection per terminal is split into a read lane (`pty_list`, the seat-turns relay) and one for everything else; the terminal answers each connection in one process, so a close stuck there (fox, 11/14 01:33 JST, ~2 min) held every read behind it.
|
|
13
|
+
|
|
14
|
+
- `own_work.task` names the oldest open agent when a seat has both agents and shells (before: the oldest of either, so a subagent's background `sleep` could stand for the subagent on the card).
|
|
15
|
+
|
|
16
|
+
- Codex seats state their working subagents too (a68): each subagent thread's rollout (session_meta thread_source subagent, session_id = the seat's root thread) counts while it has more task_started than task_complete/turn_aborted.
|
|
17
|
+
|
|
18
|
+
- Grok seats now state their own unfinished background tasks too (a68): background subagents and backgrounded commands, read from the session's updates.jsonl (subagent_spawned/finished, task_backgrounded/completed, background_tasks). `own_work.tasks`/`task` and `activity.background_tasks` are no longer null for Grok, and tasks > 0 holds the idle clock and explicit hibernate.
|
|
19
|
+
|
|
20
|
+
## [0.70.52] - 2026-11-13
|
|
21
|
+
|
|
22
|
+
- 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).
|
|
23
|
+
- 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).
|
|
24
|
+
- 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).
|
|
25
|
+
|
|
10
26
|
## [0.70.51] - 2026-11-13
|
|
11
27
|
|
|
12
28
|
- 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.
|
|
@@ -3432,7 +3448,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3432
3448
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3433
3449
|
provenance.
|
|
3434
3450
|
|
|
3435
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.
|
|
3451
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.53...HEAD
|
|
3452
|
+
[0.70.53]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.52...v0.70.53
|
|
3453
|
+
[0.70.52]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.51...v0.70.52
|
|
3436
3454
|
[0.70.51]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.50...v0.70.51
|
|
3437
3455
|
[0.70.50]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.49...v0.70.50
|
|
3438
3456
|
[0.70.49]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.48...v0.70.49
|
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.53** · 動作対象は 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.53** · 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,290 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { claudeSessionTranscriptPath } from "./harnesses/claude.js";
|
|
4
|
+
import { grokSessionDirectory } from "./harnesses/grok.js";
|
|
5
|
+
import { codexRootTranscript, codexRolloutSessionId } from "./harnesses/codex.js";
|
|
6
|
+
// One state per transcript, kept by the long-lived reader (seat-turns worker, server): each read parses only new bytes.
|
|
7
|
+
const states = new Map();
|
|
8
|
+
/** Masked like process descriptors: a value that may carry a secret, or a long one, is shortened. */
|
|
9
|
+
export function taskLabel(value, fallback) {
|
|
10
|
+
const text = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
11
|
+
if (!text)
|
|
12
|
+
return fallback;
|
|
13
|
+
if (/=|:\/\/|@/.test(text))
|
|
14
|
+
return "…";
|
|
15
|
+
return text.length > 40 ? `${text.slice(0, 39)}…` : text;
|
|
16
|
+
}
|
|
17
|
+
/** Apply one Claude transcript row to the open/done sets (pure on its inputs; exported for tests). */
|
|
18
|
+
export function applyClaudeTranscriptLine(line, open, done, inputs) {
|
|
19
|
+
// A completion (completed, failed, killed) is a <task-notification> naming the task, queued or delivered.
|
|
20
|
+
for (const match of line.matchAll(/<task-id>([^<\s]+)<\/task-id>/g)) {
|
|
21
|
+
done.add(match[1]);
|
|
22
|
+
open.delete(match[1]);
|
|
23
|
+
}
|
|
24
|
+
if (!line.includes("\"tool_use") && !line.includes("toolUseResult"))
|
|
25
|
+
return;
|
|
26
|
+
let row;
|
|
27
|
+
try {
|
|
28
|
+
row = JSON.parse(line);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const at = typeof row?.timestamp === "string" && Number.isFinite(Date.parse(row.timestamp)) ? new Date(row.timestamp).toISOString() : null;
|
|
34
|
+
for (const part of Array.isArray(row?.message?.content) ? row.message.content : []) {
|
|
35
|
+
if (part?.type === "tool_use" && typeof part.id === "string" && part.input && typeof part.input === "object") {
|
|
36
|
+
inputs.set(part.id, taskLabel(part.input.description ?? part.input.command, ""));
|
|
37
|
+
if (inputs.size > 256)
|
|
38
|
+
inputs.delete(inputs.keys().next().value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const result = row?.toolUseResult;
|
|
42
|
+
if (!result || typeof result !== "object" || !at)
|
|
43
|
+
return;
|
|
44
|
+
const toolUseId = Array.isArray(row?.message?.content) ? row.message.content.find((part) => typeof part?.tool_use_id === "string")?.tool_use_id : undefined;
|
|
45
|
+
const label = (fallback) => (toolUseId && inputs.get(toolUseId)) || fallback;
|
|
46
|
+
if (result.isAsync === true && typeof result.agentId === "string" && !done.has(result.agentId))
|
|
47
|
+
open.set(result.agentId, { kind: "agent", label: taskLabel(result.description, label("agent")), since: at });
|
|
48
|
+
else if (typeof result.backgroundTaskId === "string" && !done.has(result.backgroundTaskId))
|
|
49
|
+
open.set(result.backgroundTaskId, { kind: "shell", label: label("shell"), since: at });
|
|
50
|
+
// A stop tool's own result also ends the task it names.
|
|
51
|
+
for (const key of ["shell_id", "task_id"])
|
|
52
|
+
if (typeof result[key] === "string") {
|
|
53
|
+
done.add(result[key]);
|
|
54
|
+
open.delete(result[key]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** The task a caller names: the oldest unfinished agent, or with no agent the oldest shell/other (Kiro, a68 card order). */
|
|
58
|
+
export function representativeTask(tasks) {
|
|
59
|
+
const pool = tasks.some(task => task.kind === "agent") ? tasks.filter(task => task.kind === "agent") : tasks;
|
|
60
|
+
return pool.reduce((first, task) => !first || task.since < first.since ? task : first, null);
|
|
61
|
+
}
|
|
62
|
+
/** Apply new complete lines of a harness record to its kept state; null when the file cannot be read. */
|
|
63
|
+
function readRecord(file, apply) {
|
|
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
|
+
apply(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
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
/** Tasks opened since this launch's metadata was created (earlier ones belonged to an earlier process), and the oldest. */
|
|
98
|
+
function liveTasks(meta, state) {
|
|
99
|
+
const start = Date.parse(meta.created_at);
|
|
100
|
+
const live = [...state.open.values()].filter(task => !Number.isFinite(start) || Date.parse(task.since) >= start - 1000);
|
|
101
|
+
const oldest = representativeTask(live);
|
|
102
|
+
return { count: live.length, oldest };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Claude's own count of unfinished background tasks of this seat, from its transcript: an async Agent launch
|
|
106
|
+
* (toolUseResult.isAsync + agentId) or a background Bash (toolUseResult.backgroundTaskId) with no <task-notification>
|
|
107
|
+
* naming it yet. null: not a Claude seat, or the transcript cannot be read.
|
|
108
|
+
*/
|
|
109
|
+
export function claudeBackgroundTasks(meta) {
|
|
110
|
+
const file = meta.kind === "claude" ? claudeSessionTranscriptPath(meta) : null;
|
|
111
|
+
const state = file ? readRecord(file, applyClaudeTranscriptLine) : null;
|
|
112
|
+
return state ? liveTasks(meta, state) : null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Apply one Grok updates.jsonl row (1.0.77, captured 2026-11-14): subagent_spawned / subagent_finished,
|
|
116
|
+
* task_backgrounded / task_completed, and the background_tasks snapshot (each task's status and kind).
|
|
117
|
+
*/
|
|
118
|
+
export function applyGrokUpdateLine(line, open, done) {
|
|
119
|
+
if (!/"sessionUpdate":"(?:subagent_|task_|background_tasks)/.test(line))
|
|
120
|
+
return;
|
|
121
|
+
let row;
|
|
122
|
+
try {
|
|
123
|
+
row = JSON.parse(line);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const update = row?.params?.update;
|
|
129
|
+
const at = Number.isFinite(row?.timestamp) ? new Date(row.timestamp * 1000).toISOString() : null;
|
|
130
|
+
const close = (id) => { if (typeof id === "string") {
|
|
131
|
+
done.add(id);
|
|
132
|
+
open.delete(id);
|
|
133
|
+
} };
|
|
134
|
+
const add = (id, task) => { if (typeof id === "string" && task && !done.has(id) && !open.has(id))
|
|
135
|
+
open.set(id, task); };
|
|
136
|
+
switch (update?.sessionUpdate) {
|
|
137
|
+
case "subagent_spawned":
|
|
138
|
+
if (at)
|
|
139
|
+
add(update.subagent_id, { kind: "agent", label: taskLabel(update.description, "agent"), since: at });
|
|
140
|
+
break;
|
|
141
|
+
case "subagent_finished":
|
|
142
|
+
close(update.subagent_id);
|
|
143
|
+
break;
|
|
144
|
+
case "task_backgrounded":
|
|
145
|
+
if (at)
|
|
146
|
+
add(update.task_id, { kind: "shell", label: taskLabel(update.command, "shell"), since: at });
|
|
147
|
+
break;
|
|
148
|
+
case "task_completed":
|
|
149
|
+
close(update.task_snapshot?.task_id ?? update.task_id);
|
|
150
|
+
break;
|
|
151
|
+
case "background_tasks":
|
|
152
|
+
for (const task of Array.isArray(update.tasks) ? update.tasks : []) {
|
|
153
|
+
if (task?.status !== "running") {
|
|
154
|
+
close(task?.task_id);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const since = typeof task.started_at === "string" && Number.isFinite(Date.parse(task.started_at)) ? new Date(task.started_at).toISOString() : at;
|
|
158
|
+
const kind = task.kind === "bash" ? "shell" : task.kind === "subagent" ? "agent" : "other";
|
|
159
|
+
if (since)
|
|
160
|
+
add(task.task_id, { kind, label: taskLabel(task.description ?? task.command, kind), since });
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Grok's own count of unfinished background tasks of this seat, from its session's updates.jsonl; null if unreadable. */
|
|
166
|
+
export function grokBackgroundTasks(meta) {
|
|
167
|
+
const dir = meta.kind === "grok" ? grokSessionDirectory(meta) : null;
|
|
168
|
+
const state = dir ? readRecord(path.join(dir, "updates.jsonl"), applyGrokUpdateLine) : null;
|
|
169
|
+
return state ? liveTasks(meta, state) : null;
|
|
170
|
+
}
|
|
171
|
+
const codexChildren = new Map();
|
|
172
|
+
/** Apply one rollout row of a possible Codex subagent: its session_meta head, then task_started / task_complete / turn_aborted. */
|
|
173
|
+
export function applyCodexChildLine(line, child) {
|
|
174
|
+
let row;
|
|
175
|
+
if (child.head === undefined) {
|
|
176
|
+
try {
|
|
177
|
+
row = JSON.parse(line);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
child.head = null;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const meta = row?.type === "session_meta" ? row.payload : null;
|
|
184
|
+
child.head = meta?.thread_source === "subagent" && typeof meta.session_id === "string"
|
|
185
|
+
? { root: meta.session_id, label: taskLabel(String(meta.agent_path ?? "").split("/").pop() || meta.agent_nickname, "agent") } : null;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!child.head || !/"type":"(?:task_started|task_complete|turn_aborted)"/.test(line))
|
|
189
|
+
return;
|
|
190
|
+
try {
|
|
191
|
+
row = JSON.parse(line);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const type = row?.type === "event_msg" ? row.payload?.type : null;
|
|
197
|
+
if (type === "task_started") {
|
|
198
|
+
child.running++;
|
|
199
|
+
if (typeof row.timestamp === "string")
|
|
200
|
+
child.since = row.timestamp;
|
|
201
|
+
}
|
|
202
|
+
else if (type === "task_complete" || type === "turn_aborted")
|
|
203
|
+
child.running = Math.max(0, child.running - 1);
|
|
204
|
+
}
|
|
205
|
+
/** Rollout files under CODEX_HOME/sessions/YYYY/MM/DD created (UUIDv7 in the name) at or after `start`. */
|
|
206
|
+
function codexRolloutsSince(home, start) {
|
|
207
|
+
const files = [];
|
|
208
|
+
for (let day = start - 86_400_000; day <= Date.now() + 86_400_000; day += 86_400_000) {
|
|
209
|
+
const date = new Date(day), dir = path.join(home, "sessions", String(date.getUTCFullYear()), String(date.getUTCMonth() + 1).padStart(2, "0"), String(date.getUTCDate()).padStart(2, "0"));
|
|
210
|
+
let names;
|
|
211
|
+
try {
|
|
212
|
+
names = fs.readdirSync(dir);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
for (const name of names) {
|
|
218
|
+
const id = /-([0-9a-f]{8})-([0-9a-f]{4})-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.jsonl$/.exec(name);
|
|
219
|
+
if (id && Number.parseInt(id[1] + id[2], 16) >= start - 1000)
|
|
220
|
+
files.push(path.join(dir, name));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return files;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Codex's own count of its working subagents for this seat (0.169): each subagent thread writes its own rollout whose
|
|
227
|
+
* session_meta names the root thread (`session_id`) and `thread_source: "subagent"`; it is working while it has more
|
|
228
|
+
* task_started than task_complete/turn_aborted. Rollouts created before this launch are not read. null when the seat's
|
|
229
|
+
* root thread is not known yet.
|
|
230
|
+
*/
|
|
231
|
+
export function codexBackgroundTasks(meta) {
|
|
232
|
+
if (meta.kind !== "codex" || !meta.codex_home)
|
|
233
|
+
return null;
|
|
234
|
+
let root;
|
|
235
|
+
try {
|
|
236
|
+
const transcript = codexRootTranscript(meta);
|
|
237
|
+
root = transcript ? codexRolloutSessionId(meta, transcript) : null;
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
if (!root)
|
|
243
|
+
return null;
|
|
244
|
+
const start = Date.parse(meta.created_at);
|
|
245
|
+
if (!Number.isFinite(start))
|
|
246
|
+
return null;
|
|
247
|
+
const live = [];
|
|
248
|
+
for (const file of codexRolloutsSince(meta.codex_home, start)) {
|
|
249
|
+
let stat;
|
|
250
|
+
try {
|
|
251
|
+
stat = fs.statSync(file);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
let child = codexChildren.get(file);
|
|
257
|
+
if (!child || child.ino !== stat.ino || stat.size < child.offset)
|
|
258
|
+
codexChildren.set(file, child = { ino: stat.ino, offset: 0, partial: "", head: undefined, running: 0, since: null });
|
|
259
|
+
if (child.head !== null && stat.size > child.offset) {
|
|
260
|
+
let fd = null;
|
|
261
|
+
try {
|
|
262
|
+
fd = fs.openSync(file, "r");
|
|
263
|
+
const buffer = Buffer.alloc(stat.size - child.offset);
|
|
264
|
+
const read = fs.readSync(fd, buffer, 0, buffer.length, child.offset);
|
|
265
|
+
child.offset += read;
|
|
266
|
+
const lines = (child.partial + buffer.subarray(0, read).toString("utf8")).split("\n");
|
|
267
|
+
child.partial = lines.pop() ?? "";
|
|
268
|
+
for (const line of lines)
|
|
269
|
+
if (line)
|
|
270
|
+
applyCodexChildLine(line, child);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
if (fd !== null)
|
|
277
|
+
fs.closeSync(fd);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (child.head?.root === root && child.running > 0 && child.since)
|
|
281
|
+
live.push({ kind: "agent", label: child.head.label, since: child.since });
|
|
282
|
+
}
|
|
283
|
+
const oldest = representativeTask(live);
|
|
284
|
+
return { count: live.length, oldest };
|
|
285
|
+
}
|
|
286
|
+
/** The harness's own statement of unfinished background tasks; null where the harness gives none Aiterm reads (a68). */
|
|
287
|
+
export function harnessBackgroundTasks(meta) {
|
|
288
|
+
return meta.kind === "claude" ? claudeBackgroundTasks(meta) : meta.kind === "grok" ? grokBackgroundTasks(meta)
|
|
289
|
+
: meta.kind === "codex" ? codexBackgroundTasks(meta) : null;
|
|
290
|
+
}
|
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 版)。
|
|
@@ -166,7 +167,8 @@ const AGENT_COMMAND_PATTERNS = {
|
|
|
166
167
|
const AGENT_EXEC_SHELLS = {
|
|
167
168
|
// Bash tool and run_in_background (bash/zsh; Git Bash on Windows): the command ends by writing its cwd to claude-<hex>-cwd.
|
|
168
169
|
// Hooks are `sh -c <hook>`, Git Bash or pwsh without that file.
|
|
169
|
-
|
|
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"),
|
|
170
172
|
// exec / unified exec: POSIX [shell, -c|-lc, command]; Windows pwsh -Command starting with its UTF-8 console line.
|
|
171
173
|
// Hooks and MCP servers are spawned with their own argv (Windows hooks: pwsh -NoProfile -Command "& ...").
|
|
172
174
|
codex: command => /^\s*\S+\s+-l?c\s/.test(command)
|
|
@@ -1789,13 +1791,14 @@ export async function seatOwnWork(names, requested) {
|
|
|
1789
1791
|
const entries = list?.entries.filter(entry => entry.sessions.includes(name)) ?? [];
|
|
1790
1792
|
const childExcluded = (child) => entries.some(entry => entry.kind === "child"
|
|
1791
1793
|
&& entry.harness === child.harness && (entry.session === null || entry.session === child.session));
|
|
1792
|
-
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 };
|
|
1793
1795
|
result.set(name, work);
|
|
1794
1796
|
try {
|
|
1795
1797
|
const state = agentDormantState(meta);
|
|
1796
1798
|
if (state === "hibernated") {
|
|
1797
1799
|
work.processes = 0;
|
|
1798
1800
|
work.child_results = 0;
|
|
1801
|
+
work.tasks = 0;
|
|
1799
1802
|
continue;
|
|
1800
1803
|
}
|
|
1801
1804
|
if (state !== null || !rows)
|
|
@@ -1812,6 +1815,9 @@ export async function seatOwnWork(names, requested) {
|
|
|
1812
1815
|
continue;
|
|
1813
1816
|
const activityRows = subtree.some(row => row.pid === agent.pid) ? subtree : [...subtree, ...processSubtree(rows, agent.pid)];
|
|
1814
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;
|
|
1815
1821
|
const counted = ownExecProcesses(meta, agent, rows);
|
|
1816
1822
|
const processEntries = entries.filter(entry => entry.kind === "process");
|
|
1817
1823
|
const descriptors = new Map(counted.map(row => [row.pid, processDescriptor(processArgv(row))]));
|
|
@@ -1850,7 +1856,7 @@ function emptySessionObservation(name, exists) {
|
|
|
1850
1856
|
token_hint: null, pending_child_deliveries: null,
|
|
1851
1857
|
activity: { cursor: null, output_changed: null, cpu_seconds: null, cpu_delta_seconds: null, cpu_delta_complete: null,
|
|
1852
1858
|
background_cpu_seconds: null, background_cpu_delta_seconds: null, background_cpu_delta_complete: null,
|
|
1853
|
-
post_startup_process_count: null },
|
|
1859
|
+
post_startup_process_count: null, background_tasks: null },
|
|
1854
1860
|
};
|
|
1855
1861
|
}
|
|
1856
1862
|
function agentDormantState(meta) {
|
|
@@ -1917,6 +1923,7 @@ export function observeSession(name, cursor) {
|
|
|
1917
1923
|
result.activity.cpu_seconds = 0;
|
|
1918
1924
|
result.activity.background_cpu_seconds = 0;
|
|
1919
1925
|
result.activity.post_startup_process_count = 0;
|
|
1926
|
+
result.activity.background_tasks = 0;
|
|
1920
1927
|
return result;
|
|
1921
1928
|
}
|
|
1922
1929
|
/** Native absence before the owned launcher returns does not prove CLI exit. */
|
|
@@ -1942,7 +1949,7 @@ function observeSessionNative(name) {
|
|
|
1942
1949
|
token_hint: null, pending_child_deliveries: null,
|
|
1943
1950
|
activity: { cursor: null, output_changed: null, cpu_seconds: null, cpu_delta_seconds: null, cpu_delta_complete: null,
|
|
1944
1951
|
background_cpu_seconds: null, background_cpu_delta_seconds: null, background_cpu_delta_complete: null,
|
|
1945
|
-
post_startup_process_count: null },
|
|
1952
|
+
post_startup_process_count: null, background_tasks: null },
|
|
1946
1953
|
};
|
|
1947
1954
|
if (!listed)
|
|
1948
1955
|
return { result, native: null };
|
|
@@ -2039,6 +2046,7 @@ function observeNativeSession(name, cursor) {
|
|
|
2039
2046
|
background_cpu_delta_seconds: comparable ? Object.entries(backgroundCpu).reduce((sum, [identity, cpu]) => sum + cpu - (previous.background_processes[identity] ?? 0), 0) : null,
|
|
2040
2047
|
background_cpu_delta_complete: comparable ? Object.keys(previous.background_processes).every(identity => identity in backgroundCpu) : null,
|
|
2041
2048
|
post_startup_process_count: meta && agent ? ownExecProcesses(meta, agent, rows).length : null,
|
|
2049
|
+
background_tasks: meta && agent ? harnessBackgroundTasks(meta)?.count ?? null : null,
|
|
2042
2050
|
};
|
|
2043
2051
|
return result;
|
|
2044
2052
|
}
|
|
@@ -2150,6 +2158,7 @@ export async function checkAgentIdle(expectedInput, expectedAnchor, immediate =
|
|
|
2150
2158
|
attached: slot?.attached ?? (effectIssued ? false : null), turn_settled: settled,
|
|
2151
2159
|
pending_child_deliveries: live.pending_child_deliveries,
|
|
2152
2160
|
post_startup_process_count: live.activity.post_startup_process_count,
|
|
2161
|
+
background_tasks: live.activity.background_tasks,
|
|
2153
2162
|
window_activity_at: slot?.window_activity_at ?? null,
|
|
2154
2163
|
...(immediate && meta.kind === "claude" ? { rate_limited_at: claudeRateLimitedAt(meta) } : {}) };
|
|
2155
2164
|
};
|
package/dist/index.js
CHANGED
|
@@ -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.js
CHANGED
|
@@ -235,8 +235,12 @@ function retireWarm(ref, session) {
|
|
|
235
235
|
if (!session.inflight)
|
|
236
236
|
void session.client.close().catch(() => { });
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
// One warm session per terminal and lane. pty_list (the seat-turns reads) has its own lane: the terminal answers each warm
|
|
239
|
+
// session in one process, so a call that blocks there (a close waiting ~2 min on fox, 11/14 01:33 JST) would freeze every
|
|
240
|
+
// read of that terminal behind it.
|
|
241
|
+
function warmLane(name) { return name === "pty_list" ? "list" : "main"; }
|
|
242
|
+
function warmSession(target, sshArgs, lane) {
|
|
243
|
+
const ref = `${target.trusted_ref}\0${lane}`;
|
|
240
244
|
const kept = warmSessions.get(ref);
|
|
241
245
|
if (kept && !kept.dead && Date.now() - kept.born < WARM_MAX_AGE_MS)
|
|
242
246
|
return kept;
|
|
@@ -255,7 +259,8 @@ function warmSession(target, sshArgs) {
|
|
|
255
259
|
return session;
|
|
256
260
|
}
|
|
257
261
|
async function callWarm(target, sshArgs, request, timeoutMs) {
|
|
258
|
-
const
|
|
262
|
+
const lane = warmLane(request.name), key = `${target.trusted_ref}\0${lane}`;
|
|
263
|
+
const session = warmSession(target, sshArgs, lane);
|
|
259
264
|
session.inflight++;
|
|
260
265
|
if (session.idle) {
|
|
261
266
|
clearTimeout(session.idle);
|
|
@@ -270,10 +275,10 @@ async function callWarm(target, sshArgs, request, timeoutMs) {
|
|
|
270
275
|
finally {
|
|
271
276
|
if (--session.inflight === 0) {
|
|
272
277
|
session.transport.hold(false);
|
|
273
|
-
if (session.dead || warmSessions.get(
|
|
278
|
+
if (session.dead || warmSessions.get(key) !== session)
|
|
274
279
|
void session.client.close().catch(() => { });
|
|
275
280
|
else
|
|
276
|
-
session.idle = setTimeout(() => retireWarm(
|
|
281
|
+
session.idle = setTimeout(() => retireWarm(key, session), WARM_IDLE_MS).unref();
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.53",
|
|
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": [
|