aiterm-mcp 0.63.12 → 0.63.13
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 +6 -1
- package/README.ja.md +3 -1
- package/README.md +3 -1
- package/dist/agent-screen-observation.js +62 -2
- package/dist/core.js +96 -9
- package/dist/managed-seat-turn.js +106 -0
- package/docs/DESIGN.md +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.63.13] - 2026-11-07
|
|
11
|
+
|
|
12
|
+
- Report current parent activity for Claude Code, Grok, Cursor and Antigravity through existing seat-turn metadata. Live original-pane observations retain opaque managed span identity/start through unchanged waits and absorbed input; unsupported tracking fields remain null. Settled native parent completion returns idle, ambiguous evidence remains unavailable. Codex tracking and waiters are unchanged.
|
|
13
|
+
|
|
10
14
|
## [0.63.12] - 2026-11-07
|
|
11
15
|
|
|
12
16
|
- Remove filesystem input locks and the legacy socket/log-directory readiness predicate from managed-agent send and fresh-launch admission. Keep process-local order, current launch/native identity and stable TUI readiness checks. Independent local MCP and remote callers now serialize the same agent seat themselves; ordinary PTY/shell and standalone auth/approval file exclusion remain unchanged.
|
|
@@ -3063,7 +3067,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3063
3067
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3064
3068
|
provenance.
|
|
3065
3069
|
|
|
3066
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.
|
|
3070
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.13...HEAD
|
|
3071
|
+
[0.63.13]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.12...v0.63.13
|
|
3067
3072
|
[0.63.12]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.11...v0.63.12
|
|
3068
3073
|
[0.63.11]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.10...v0.63.11
|
|
3069
3074
|
[0.63.10]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.9...v0.63.10
|
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.63.
|
|
218
|
+
**状態:** 開発継続中 · 現行公開版 **v0.63.13** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
219
219
|
|
|
220
220
|
### 更新と巻き戻し
|
|
221
221
|
|
|
@@ -893,4 +893,6 @@ Grok 1.0.70のLinux読取は公式active_sessions.jsonのPID・開始tick・cwd
|
|
|
893
893
|
|
|
894
894
|
### Host-controller clients
|
|
895
895
|
|
|
896
|
+
Controller-only `pty_list` metadata `aiterm/seat_turns` reports all five harnesses. Codex retains real turn tracking; the other four use an opaque Aiterm-managed observed parent-work-span ID and first captured live-work time, with `event_cursor`, `interim_from` and `wait_process` explicitly null. Each read observes the original live parent pane. Positive settled parent terminal is `{state:"idle"}`; missing/ambiguous evidence is `null`. Observation-only rows provide neither non-Codex wait/interim support nor historical native UUID certification.
|
|
897
|
+
|
|
896
898
|
Any MCP client can opt into the existing host-orchestration routing by declaring `capabilities.experimental["io.github.kitepon/aiterm-mcp/host-controller"] = {}` during initialize. This is routing identity, not authentication; source, generation, native identity and effect guards still apply. Clients without that declaration stay on the ordinary direct path. The exact client name `bellteam` remains a backward-compatible alias. A declared controller requests interim/follow metadata with `_meta["aiterm/caller"]` equal to its initialized client name (blank/missing name: `MCP client`); the old `BellTeam` marker is also preserved for compatibility. See [function map and data flow](https://github.com/kitepon/aiterm-mcp/blob/main/docs/architecture/host-controller.md). BellTeam's own caller can adopt the capability later; that migration is separate from this release.
|
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.63.
|
|
230
|
+
**Status:** actively maintained · current public release **v0.63.13** · 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
|
|
|
@@ -960,4 +960,6 @@ The Linux Grok 1.0.70 inspector binds the native current-session registry to the
|
|
|
960
960
|
|
|
961
961
|
### Host-controller clients
|
|
962
962
|
|
|
963
|
+
Controller-only `pty_list` metadata `aiterm/seat_turns` reports all five harnesses. Codex retains its real turn tracking; the other four use an opaque Aiterm-managed observed parent-work-span ID, first captured live-work time, and explicit null `event_cursor`, `interim_from`, `wait_process`. Each observation reads the original live parent pane; long unchanged waits keep identity when native occupancy remains visible. A positive settled parent terminal is `{state:"idle"}`; missing or ambiguous evidence is `null`. These observation-only rows do not provide non-Codex wait/interim support or certify historical native turn UUIDs.
|
|
964
|
+
|
|
963
965
|
Any MCP client can opt into the existing host-orchestration routing by declaring `capabilities.experimental["io.github.kitepon/aiterm-mcp/host-controller"] = {}` during initialize. This is routing identity, not authentication; source, generation, native identity and effect guards still apply. Clients without that declaration stay on the ordinary direct path. The exact client name `bellteam` remains a backward-compatible alias. A declared controller requests interim/follow metadata with `_meta["aiterm/caller"]` equal to its initialized client name (blank/missing name: `MCP client`); the old `BellTeam` marker is also preserved for compatibility. See [function map and data flow](https://github.com/kitepon/aiterm-mcp/blob/main/docs/architecture/host-controller.md). BellTeam's own caller can adopt the capability later; that migration is separate from this release.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { antigravityPaneObservation } from "./harnesses/antigravity.js";
|
|
2
2
|
import { AitermError } from "./errors.js";
|
|
3
|
-
import { grokTuiReady, grokTuiBusy, grokPaneObservation, grokLaunchBlockingDialog, assertGrokSandboxNotRejected, GROK_COMPOSER_MARKER_RE } from "./harnesses/grok.js";
|
|
3
|
+
import { grokPromptAwaitingAccept, grokTuiReady, grokTuiBusy, grokPaneObservation, grokLaunchBlockingDialog, assertGrokSandboxNotRejected, GROK_COMPOSER_MARKER_RE } from "./harnesses/grok.js";
|
|
4
4
|
import { codexTuiReady, codexTuiBusy, codexPaneObservation, codexRateLimitModelSwitchDialog, CODEX_COMPOSER_MARKER_RE } from "./harnesses/codex.js";
|
|
5
5
|
import { claudeTuiReady, claudeTuiBusy, claudePaneObservation, claudeLoginMethodMenu, claudeStartupAction, CLAUDE_COMPOSER_MARKER_RE } from "./harnesses/claude.js";
|
|
6
|
-
import { cursorTuiReady, cursorTuiBusy, cursorPaneObservation, CURSOR_COMPOSER_CONTENT_MARKER_RE } from "./harnesses/cursor.js";
|
|
6
|
+
import { cursorPromptHooksRunning, cursorTuiReady, cursorTuiBusy, cursorPaneObservation, CURSOR_COMPOSER_CONTENT_MARKER_RE } from "./harnesses/cursor.js";
|
|
7
7
|
const AGENT_DONE_SETTLE_MIN_MS = 250;
|
|
8
8
|
const AGENT_DONE_SCREEN_SETTLE_POLL_MS = 100;
|
|
9
9
|
const AGENT_DONE_SCREEN_SETTLE_MAX_POLLS = 5;
|
|
@@ -298,3 +298,63 @@ export function __testSetAgentTuiReadyStableSamples(value) {
|
|
|
298
298
|
}
|
|
299
299
|
agentTuiReadyStableSamplesTestOverride = value;
|
|
300
300
|
}
|
|
301
|
+
/** Only the current native composer/progress/footer can establish occupancy. */
|
|
302
|
+
// shortcut: pane snapshots cannot certify hidden native turn boundaries, use a continuous native lifecycle when that distinction is required.
|
|
303
|
+
export function parentPaneEvidence(kind, screen) {
|
|
304
|
+
const lines = screen.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").trimEnd().split(/\r?\n/);
|
|
305
|
+
if (kind === "codex")
|
|
306
|
+
return "unknown";
|
|
307
|
+
if (agentPaneObservation(kind, lines.slice(-32).join("\n")).state === "blocked")
|
|
308
|
+
return "unknown";
|
|
309
|
+
let marker = -1;
|
|
310
|
+
const composer = kind === "claude" ? /^\s*❯(?:\s|$)/u
|
|
311
|
+
: kind === "grok" ? /^\s*│\s*[❯>](?:\s|$)/u
|
|
312
|
+
: kind === "cursor" ? /^\s*(?:→|->|>)(?:\s|$)/u : /^\s*>\s*$/u;
|
|
313
|
+
for (let i = lines.length - 1; i >= 0; i--)
|
|
314
|
+
if (composer.test(lines[i])) {
|
|
315
|
+
marker = i;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (marker < 0)
|
|
319
|
+
return "unknown";
|
|
320
|
+
let start = marker;
|
|
321
|
+
if (kind === "claude") {
|
|
322
|
+
if (marker < 1 || !/^\s*─{8,}\s*$/u.test(lines[marker - 1]))
|
|
323
|
+
return "unknown";
|
|
324
|
+
start = marker - 2;
|
|
325
|
+
while (start > 0 && (!lines[start].trim() || /^\s/u.test(lines[start])))
|
|
326
|
+
start--;
|
|
327
|
+
}
|
|
328
|
+
else if (kind === "grok" || kind === "antigravity") {
|
|
329
|
+
start = marker - 1;
|
|
330
|
+
while (start > 0 && (!lines[start].trim() || /^[╭─\s]+$/u.test(lines[start])))
|
|
331
|
+
start--;
|
|
332
|
+
}
|
|
333
|
+
const current = lines.slice(Math.max(0, start)).join("\n");
|
|
334
|
+
if (kind === "grok" && grokPromptAwaitingAccept(current))
|
|
335
|
+
return "unknown";
|
|
336
|
+
if (kind === "cursor" && cursorPromptHooksRunning(screen))
|
|
337
|
+
return "unknown";
|
|
338
|
+
if (kind === "claude" && /running UserPromptSubmit hook/u.test(current))
|
|
339
|
+
return "unknown";
|
|
340
|
+
const observed = agentPaneObservation(kind, current);
|
|
341
|
+
if (observed.state === "blocked" || observed.state === "unknown")
|
|
342
|
+
return "unknown";
|
|
343
|
+
if (kind === "claude" && observed.state === "idle"
|
|
344
|
+
&& !/^[·✢✳✶✻✽*∗] [^…\n]+ for \d[^…\n]*$/mu.test(current))
|
|
345
|
+
return "unknown";
|
|
346
|
+
if (kind === "cursor") {
|
|
347
|
+
if (/^\s*ctrl\+c to stop\s*$/imu.test(lines.slice(marker + 1).join("\n")))
|
|
348
|
+
return "busy";
|
|
349
|
+
if (observed.state === "busy")
|
|
350
|
+
return "unknown";
|
|
351
|
+
}
|
|
352
|
+
if (kind === "grok" && observed.state === "busy"
|
|
353
|
+
&& !/^\s*(?:[│┃]\s*)?(?:Waiting for response|Responding(?:…|\.\.\.)).*$/mu.test(current))
|
|
354
|
+
return "unknown";
|
|
355
|
+
if (kind === "antigravity" && observed.state === "busy"
|
|
356
|
+
&& !/^\s*(?:[^\p{L}\p{N}\s]{1,3}\s+)?(?:Generating|Working)(?:…|\.\.\.).*$/mu.test(current)
|
|
357
|
+
&& !/^\s*esc to interrupt\s*$/imu.test(lines.slice(marker + 1).join("\n")))
|
|
358
|
+
return "unknown";
|
|
359
|
+
return observed.state === "busy" ? "busy" : "ready";
|
|
360
|
+
}
|
package/dist/core.js
CHANGED
|
@@ -8,9 +8,10 @@ import { loadAgentMetadata, tryLoadAgentMetadata } from "./agent-metadata-reader
|
|
|
8
8
|
import { nativePaneTarget } from "./native-session.js";
|
|
9
9
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
10
|
import { inspectIdleSettings, inspectCodexResumeSettings, codexRecoveryComposer } from "./harnesses/idle-settings.js";
|
|
11
|
-
import { AGENT_TUI_READY_TIMEOUT_MS, AGENT_TUI_FIRST_DRAW_TIMEOUT_MS, AGENT_TUI_READY_POLL_MS, isAgentTuiReady, isAgentTuiBusy, isAgentTuiIdleReady, agentPaneObservation, waitAgentTuiReadyImpl, detectAgentSubmitResidueImpl, waitCursorPromptVisibleImpl, settleAgentDoneScreenImpl } from "./agent-screen-observation.js";
|
|
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 { withManagedSpan, observeManagedSpan } from "./managed-seat-turn.js";
|
|
14
15
|
/**
|
|
15
16
|
* core — CLI/MCP が共有する端末操作とharness進行(Node/TS 版)。
|
|
16
17
|
*
|
|
@@ -45,7 +46,7 @@ import { withExecutionInterruptEffectScope, bindExecutionNativeTarget, beforeExe
|
|
|
45
46
|
import { ExecutionError } from "./execution-wire.js";
|
|
46
47
|
import { readExecutionParentProcess } from "./execution-parent-process.js";
|
|
47
48
|
import { isCursorMcpClient } from "aiterm-steer-delivery";
|
|
48
|
-
import { antigravityAuthChoiceKey, antigravityCurrentModel, antigravityStartupAction, antigravityAgentArgv, antigravityModelChoices, antigravityAuthStatus, antigravityAuthPane, antigravityTranscriptText, bindAntigravitySession, createAntigravityAgentMetadata, mergeAntigravityHooks } from "./harnesses/antigravity.js";
|
|
49
|
+
import { antigravityBinding, antigravityAuthChoiceKey, antigravityCurrentModel, antigravityStartupAction, antigravityAgentArgv, antigravityModelChoices, antigravityAuthStatus, antigravityAuthPane, antigravityTranscriptText, bindAntigravitySession, createAntigravityAgentMetadata, mergeAntigravityHooks } from "./harnesses/antigravity.js";
|
|
49
50
|
import { paneTokenHint } from "./harnesses/pane-tokens.js";
|
|
50
51
|
import { unfinishedDeliveriesOwnedBy } from "./parent-delivery-owners.js";
|
|
51
52
|
import { readLinuxProcessRegistrationIdentity, readRuntimeProcesses, readProcessIdentities, processSubtree, parentProcess, processIdentity, signalRuntimeProcess, backgroundProcesses, lazyRelayProcess, aitermProcessProbe, windowsConsoleHost, macKeepAwakeProcess, processElapsedSeconds } from "./process-runtime.js";
|
|
@@ -63,7 +64,7 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
63
64
|
import { grokAuthPlan, grokAuthStatus, grokAuthPane, GROK_MODEL_DEFAULTS, realGrokHome, resolveAndValidateGrokAuth, assertGrokModelAvailable, grokModelChoices, grokModelFromFooter, grokFooterModelName, grokModelDefaultsFromBody, restoreGrokModelDefaults, grokEventsTranscript, grokSessionDirectory, latestGrokCompletion, grokTurnSettled, observeGrokDone, buildGrokAgentCmd, grokAgentArgv, grokLaunchNote, grokEnvTokens, grokEnvEntries, grokTuiReady, grokPaneObservation, GROK_INTERRUPT_KEY, grokRateLimitDialog, grokPromptAwaitingAccept, grokUnacceptedPromptRestored, grokStartupAction, grokFooterHasConfiguration, grokTranscriptText, createGrokAgentMetadata, } from "./harnesses/grok.js";
|
|
64
65
|
import { codexAuthPlan, codexAuthStatus, codexAuthPane, realCodexHome, readCodexConfigPins, bindCodexTranscriptSession, latestCodexCompletion, codexTurnSettled, codexCompletedTurnId, codexWorkingResumeConfiguration, captureCodexRecoveryProof, captureCodexResumeProof, readCodexResumeProof, codexResumeProofDigest, codexRootTranscript, codexRunningTurn, codexInterruptionRecord, observeCodexDone, buildCodexAgentCmd, codexAgentArgv, codexResumeArgv, codexLaunchNote, codexPaneObservation, CODEX_INTERRUPT_KEY, codexHelperProcess, codexRateLimitModelSwitchDialog, codexApprovalDialog, codexStartupAction, codexModelChoice, codexEffortChoice, codexMoreReasoningChoice, codexTranscriptText, createCodexAgentMetadata, codexModelChoices, codexFastCommandOffered, codexFooterShowsFast, codexServiceTierNotices, restoreCodexDefaults, restoreCodexDefaultInFile, } from "./harnesses/codex.js";
|
|
65
66
|
import { claudeAuthPlan, claudeAuthStatus, claudeAuthPane, OPERATION_ID_RE, CLAUDE_RESULT_MAX_BYTES, CLAUDE_EFFORTS, agentClaudeOperationPath, agentClaudeApprovalReceiptPath, agentClaudeDispatchReceiptPath, validateOperationId, readClaudeResultText, assertClaudeAuthenticationReady, claudeModelChoices, claudeConfigDir, claudeFastIndicatorShown, claudeFastResult, buildClaudeAgentCmd, claudeAgentArgv, claudeResumeArgv, claudeLaunchNote, claudePaneObservation, CLAUDE_INTERRUPT_KEY, claudeUsageLimit, claudeLiveSelectMenu, claudeStartupAction, createClaudeAgentMetadata, claudeSessionTranscriptPath, claudeApiErrorFromLine, claudeApiErrorAfter, claudeFailureCategory, } from "./harnesses/claude.js";
|
|
66
|
-
import { cursorAuthPlan, cursorAuthStatus, cursorAuthPane, bindCursorTranscriptSession, cursorTurnBoundary, latestCursorCompletion, observeCursorDone, cursorTranscriptText, assertCursorAuthenticationReady, assertCursorModelAvailable, cursorModelChoices, cursorModelIsFastVariant, cursorFastParameter, cursorHeaderShowsFast, cursorPickerView, cursorEffortSelected, cursorParameterRows, cursorUserConfigPath, CURSOR_DEFAULT_MODEL_KEYS, realCursorHome, buildCursorAgentCmd, cursorAgentArgv, cursorPromptWithLineage, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
67
|
+
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, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
67
68
|
import { interimFromNow, readInterimWords, recordInterimBoundary } from "./interim-words.js";
|
|
68
69
|
import { codexSeatTurn, grokSteerAcceptance, observeSteerDone, readSteerEntry, recordSteer } from "./steer-follow.js";
|
|
69
70
|
import { resolveAgentBin, resolveThroughlineBin, runThroughlineHandoffContext, isWindowsNativeExecutable, isUsableAgentExecutableFile, agentBinForPaneShell, resolveWinPaneShell, windowsAgentArgv, windowsAgentLaunchLine } from "./agent-resolver.js";
|
|
@@ -390,7 +391,7 @@ function cleanupAgentState(name) {
|
|
|
390
391
|
f.endsWith(".steers.jsonl") ||
|
|
391
392
|
f.endsWith(".auth.json"))
|
|
392
393
|
fs.unlinkSync(p);
|
|
393
|
-
else if (f.endsWith(".codex-home") || f.endsWith(".grok-home") || f.endsWith(".cursor-plugin") || f.endsWith(".home") || f.endsWith(".resume-restore.d")) {
|
|
394
|
+
else if (f.endsWith(".seat-span.d") || f.endsWith(".codex-home") || f.endsWith(".grok-home") || f.endsWith(".cursor-plugin") || f.endsWith(".home") || f.endsWith(".resume-restore.d")) {
|
|
394
395
|
fs.rmSync(p, { recursive: true, force: true });
|
|
395
396
|
}
|
|
396
397
|
}
|
|
@@ -3678,12 +3679,12 @@ export function readSessionInterimWords(name, after, from = null) {
|
|
|
3678
3679
|
return readInterimWords(loadAgentMetadata(name), after, from);
|
|
3679
3680
|
}
|
|
3680
3681
|
/**
|
|
3681
|
-
*
|
|
3682
|
-
*
|
|
3683
|
-
* 動いている番のwait_processは、その番の終わりで返る。
|
|
3682
|
+
* Existing caller-only seat metadata. Codex keeps native tracking; other four
|
|
3683
|
+
* read current original-pane activity, with observation identity and no waiter.
|
|
3684
3684
|
*/
|
|
3685
3685
|
export function readSeatTurns(sessionIds) {
|
|
3686
3686
|
const seats = [];
|
|
3687
|
+
const observedAt = new Map();
|
|
3687
3688
|
for (const name of sessionIds) {
|
|
3688
3689
|
const meta = tryLoadAgentMetadata(name);
|
|
3689
3690
|
if (!meta)
|
|
@@ -3691,14 +3692,100 @@ export function readSeatTurns(sessionIds) {
|
|
|
3691
3692
|
let turn = null;
|
|
3692
3693
|
try {
|
|
3693
3694
|
const state = agentDormantState(meta);
|
|
3694
|
-
turn = state ? (state === "hibernated" && observeSession(name).state === "hibernated" ? { state: "idle" } : null)
|
|
3695
|
+
turn = state ? (state === "hibernated" && observeSession(name).state === "hibernated" ? { state: "idle" } : null)
|
|
3696
|
+
: meta.kind === "codex" ? codexSeatTurn(meta) : readManagedSeatTurn(meta);
|
|
3695
3697
|
}
|
|
3696
3698
|
catch { /* 読めない席は、分からないまま返す */ }
|
|
3699
|
+
if (meta.kind !== "codex")
|
|
3700
|
+
observedAt.set(name, performance.now());
|
|
3697
3701
|
seats.push({ session_id: name, launch_id: meta.launch_id, harness: agentHarness(meta.kind),
|
|
3698
|
-
turn: turn?.state === "running"
|
|
3702
|
+
turn: turn?.state === "running" && turn.event_cursor !== null
|
|
3703
|
+
? { ...turn, wait_process: agentWaitProcess(name, turn.event_cursor) } : turn });
|
|
3699
3704
|
}
|
|
3705
|
+
for (const seat of seats)
|
|
3706
|
+
if (seat.harness !== "codex-cli"
|
|
3707
|
+
&& performance.now() - observedAt.get(seat.session_id) >= 15_000)
|
|
3708
|
+
seat.turn = null;
|
|
3700
3709
|
return { schema: "aiterm.seat-turns.v1", seats };
|
|
3701
3710
|
}
|
|
3711
|
+
function managedSeatConversation(meta) {
|
|
3712
|
+
if (meta.kind === "antigravity") {
|
|
3713
|
+
const bound = antigravityBinding(meta);
|
|
3714
|
+
return bound && (!meta.vendor_session_id || meta.vendor_session_id === bound.conversation_id) ? bound.conversation_id : null;
|
|
3715
|
+
}
|
|
3716
|
+
if (meta.kind === "cursor") {
|
|
3717
|
+
const file = cursorTranscript(meta);
|
|
3718
|
+
const id = file ? cursorTranscriptSessionId(file) : null;
|
|
3719
|
+
return id && (!meta.vendor_session_id || meta.vendor_session_id === id) ? id : null;
|
|
3720
|
+
}
|
|
3721
|
+
return meta.vendor_session_id;
|
|
3722
|
+
}
|
|
3723
|
+
function managedSeatTerminal(meta) {
|
|
3724
|
+
const file = meta.kind === "cursor" ? cursorTranscript(meta) : meta.kind === "grok" ? grokEventsTranscript(meta) : meta.event_file;
|
|
3725
|
+
if (!file)
|
|
3726
|
+
return null;
|
|
3727
|
+
try {
|
|
3728
|
+
const before = fs.statSync(file);
|
|
3729
|
+
if (!before.isFile() || before.size === 0 || readFileRange(file, before.size - 1, before.size).toString() !== "\n")
|
|
3730
|
+
return null;
|
|
3731
|
+
const done = latestAgentDoneEvent(meta);
|
|
3732
|
+
let identity = done ? { ...done, at: null } : null;
|
|
3733
|
+
if (done && (meta.kind === "claude" || meta.kind === "antigravity")) {
|
|
3734
|
+
identity = null;
|
|
3735
|
+
const tail = readFileRange(file, Math.max(0, before.size - AGENT_EVENT_TAIL_BYTES), before.size).toString("utf8");
|
|
3736
|
+
for (const line of tail.split("\n")) {
|
|
3737
|
+
try {
|
|
3738
|
+
const raw = JSON.parse(line), parsed = parseAgentDoneEvent(line, meta);
|
|
3739
|
+
if (parsed.event && typeof raw.at === "string" && Number.isFinite(Date.parse(raw.at)))
|
|
3740
|
+
identity = line;
|
|
3741
|
+
}
|
|
3742
|
+
catch { /* An incomplete/unrelated record is not a positive terminal. */ }
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
const after = fs.statSync(file);
|
|
3746
|
+
if (!done || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size
|
|
3747
|
+
|| before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs)
|
|
3748
|
+
return null;
|
|
3749
|
+
// Cursor/Grok adapters supply read-time `at`; it is not a lifecycle boundary.
|
|
3750
|
+
return identity ? createHash("sha256").update(JSON.stringify(identity)).digest("hex") : null;
|
|
3751
|
+
}
|
|
3752
|
+
catch {
|
|
3753
|
+
return null;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
function readManagedSeatTurn(meta) {
|
|
3757
|
+
const started = performance.now();
|
|
3758
|
+
const result = withManagedSpan(meta, file => {
|
|
3759
|
+
const conversation = managedSeatConversation(meta);
|
|
3760
|
+
if (!conversation)
|
|
3761
|
+
return null;
|
|
3762
|
+
const proof = readAgentResumeNative(meta);
|
|
3763
|
+
if (proof)
|
|
3764
|
+
verifyAgentResumeNative(meta, proof);
|
|
3765
|
+
const before = observeSessionNative(meta.aiterm_session);
|
|
3766
|
+
const live = before.result;
|
|
3767
|
+
if (live.pane_alive !== true || live.harness_alive !== true || !live.pane_process || !live.harness_process
|
|
3768
|
+
|| before.native?.agent?.stopped === true || live.launch_id !== meta.launch_id)
|
|
3769
|
+
return null;
|
|
3770
|
+
const captured = tmux("capture-pane", "-p", "-J", "-t", proof ? nativePaneTarget(proof) : meta.aiterm_session);
|
|
3771
|
+
if (captured.code !== 0)
|
|
3772
|
+
return null;
|
|
3773
|
+
const evidence = parentPaneEvidence(meta.kind, captured.stdout);
|
|
3774
|
+
const terminal = managedSeatTerminal(meta);
|
|
3775
|
+
const observedAfter = observeSessionNative(meta.aiterm_session), after = observedAfter.result;
|
|
3776
|
+
if (proof)
|
|
3777
|
+
verifyAgentResumeNative(meta, proof);
|
|
3778
|
+
if (after.pane_alive !== true || after.harness_alive !== true || observedAfter.native?.agent?.stopped === true
|
|
3779
|
+
|| !isDeepStrictEqual(after.pane_process, live.pane_process) || !isDeepStrictEqual(after.harness_process, live.harness_process)
|
|
3780
|
+
|| !isDeepStrictEqual(loadAgentMetadata(meta.aiterm_session), meta)
|
|
3781
|
+
|| managedSeatConversation(meta) !== conversation || agentDormantState(meta) !== null
|
|
3782
|
+
|| performance.now() - started >= 15_000)
|
|
3783
|
+
return null;
|
|
3784
|
+
const binding = JSON.stringify([meta.aiterm_session, meta.launch_id, meta.kind, conversation, proof, live.pane_process, live.harness_process]);
|
|
3785
|
+
return observeManagedSpan(file, binding, evidence, terminal, new Date().toISOString());
|
|
3786
|
+
});
|
|
3787
|
+
return performance.now() - started < 15_000 ? result : null;
|
|
3788
|
+
}
|
|
3702
3789
|
/** agent harness の構造化 transcript から直近完了ターンの最終回答と相関情報を読む。 */
|
|
3703
3790
|
export async function readAgentTranscriptResult(name, o = {}) {
|
|
3704
3791
|
const meta = loadAgentMetadata(name);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { agentMetadataPath, writeJson0600 } from "./agent-shared.js";
|
|
6
|
+
import { readProcessIdentities, observeExecutionActor } from "./process-runtime.js";
|
|
7
|
+
const stamp = z.string().refine(value => Number.isFinite(Date.parse(value)));
|
|
8
|
+
const spanSchema = z.object({ turn_id: z.string().regex(/^managed:[a-f0-9]{32}$/), started_at: stamp }).strict();
|
|
9
|
+
const recordSchema = z.object({ binding: z.string().min(1), span: spanSchema.nullable(), terminal: z.string().nullable(),
|
|
10
|
+
ready: z.object({ since: stamp, terminal: z.string() }).strict().nullable() }).strict();
|
|
11
|
+
const ownerSchema = z.object({ pid: z.number().int().positive(), started_identity: stamp, token: z.string() }).strict();
|
|
12
|
+
export const managedSpanDirectory = (meta) => agentMetadataPath(meta.aiterm_session, meta.launch_id).replace(/\.agent\.json$/, ".seat-span.d");
|
|
13
|
+
/** Same callback owns live capture and the short identity transaction. Never waits or sends input. */
|
|
14
|
+
export function withManagedSpan(meta, capture) {
|
|
15
|
+
const directory = managedSpanDirectory(meta);
|
|
16
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
17
|
+
const actor = readProcessIdentities([process.pid]).find(row => row.pid === process.pid);
|
|
18
|
+
if (!actor?.started_identity)
|
|
19
|
+
return null;
|
|
20
|
+
const owner = ownerSchema.parse({ ...actor, token: randomBytes(16).toString("hex") });
|
|
21
|
+
const lock = path.join(directory, "lock"), candidate = path.join(directory, `claim-${owner.token}`);
|
|
22
|
+
fs.mkdirSync(candidate, { mode: 0o700 });
|
|
23
|
+
let acquired = false;
|
|
24
|
+
try {
|
|
25
|
+
writeJson0600(path.join(candidate, "owner.json"), owner);
|
|
26
|
+
try {
|
|
27
|
+
fs.renameSync(candidate, lock);
|
|
28
|
+
acquired = true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!["EEXIST", "ENOTEMPTY", "EPERM", "EACCES"].includes(error.code ?? ""))
|
|
32
|
+
throw error;
|
|
33
|
+
const before = fs.lstatSync(lock, { bigint: true });
|
|
34
|
+
const prior = ownerSchema.parse(JSON.parse(fs.readFileSync(path.join(lock, "owner.json"), "utf8")));
|
|
35
|
+
const dead = () => {
|
|
36
|
+
const observed = observeExecutionActor(prior.pid);
|
|
37
|
+
return observed.state === "absent" || observed.state === "present" && observed.actor.started_identity !== prior.started_identity;
|
|
38
|
+
};
|
|
39
|
+
if (!dead())
|
|
40
|
+
return null;
|
|
41
|
+
const after = fs.lstatSync(lock, { bigint: true });
|
|
42
|
+
if (before.dev !== after.dev || before.ino !== after.ino || !dead())
|
|
43
|
+
return null;
|
|
44
|
+
// Retain this nonempty destination: a competing reap cannot move a later owner's lock over it.
|
|
45
|
+
fs.renameSync(lock, path.join(directory, `retired-${before.dev}-${before.ino}`));
|
|
46
|
+
fs.renameSync(candidate, lock);
|
|
47
|
+
acquired = true;
|
|
48
|
+
}
|
|
49
|
+
return capture(path.join(directory, "span.json"));
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
if (acquired) {
|
|
53
|
+
const current = ownerSchema.parse(JSON.parse(fs.readFileSync(path.join(lock, "owner.json"), "utf8")));
|
|
54
|
+
if (current.token === owner.token) {
|
|
55
|
+
fs.unlinkSync(path.join(lock, "owner.json"));
|
|
56
|
+
fs.rmdirSync(lock);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
fs.rmSync(candidate, { recursive: true, force: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Persistence keeps identity only; evidence must come from a new validated native read. */
|
|
64
|
+
export function observeManagedSpan(file, binding, evidence, terminal, at) {
|
|
65
|
+
stamp.parse(at);
|
|
66
|
+
let record = null;
|
|
67
|
+
try {
|
|
68
|
+
record = recordSchema.parse(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error.code !== "ENOENT" && (evidence !== "ready" || !terminal))
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (record?.binding !== binding)
|
|
75
|
+
record = null;
|
|
76
|
+
if (evidence === "unknown")
|
|
77
|
+
return null;
|
|
78
|
+
if (evidence === "busy") {
|
|
79
|
+
if (!record?.span) {
|
|
80
|
+
record = { binding, span: { turn_id: `managed:${randomBytes(16).toString("hex")}`, started_at: at }, terminal, ready: null };
|
|
81
|
+
writeJson0600(file, record);
|
|
82
|
+
}
|
|
83
|
+
else if (record.ready) {
|
|
84
|
+
record.ready = null;
|
|
85
|
+
writeJson0600(file, record);
|
|
86
|
+
}
|
|
87
|
+
return { state: "running", ...record.span, event_cursor: null, interim_from: null, wait_process: null };
|
|
88
|
+
}
|
|
89
|
+
if (!terminal || record?.span && terminal === record.terminal)
|
|
90
|
+
return null;
|
|
91
|
+
if (!record)
|
|
92
|
+
record = { binding, span: null, terminal, ready: null };
|
|
93
|
+
if (!record.ready || record.ready.terminal !== terminal || Date.parse(at) < Date.parse(record.ready.since)) {
|
|
94
|
+
record.ready = { since: at, terminal };
|
|
95
|
+
writeJson0600(file, record);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (Date.parse(at) - Date.parse(record.ready.since) < 250)
|
|
99
|
+
return null;
|
|
100
|
+
if (record.span) {
|
|
101
|
+
record.span = null;
|
|
102
|
+
record.terminal = terminal;
|
|
103
|
+
writeJson0600(file, record);
|
|
104
|
+
}
|
|
105
|
+
return { state: "idle" };
|
|
106
|
+
}
|
package/docs/DESIGN.md
CHANGED
|
@@ -589,3 +589,6 @@ Grok clear uses the existing host-origin contract and only a fresh UserPaused/Id
|
|
|
589
589
|
Claude resume preserves the original CLAUDE_CONFIG_DIR selector (including unset) separately from its resolved path; incomplete old selectors remain unavailable. Security notes block startup even when an older shell marker remains above them.
|
|
590
590
|
|
|
591
591
|
Factory diagnostics keep the v1 default projection and the separate parent-hook text. Optional format v2 adds fixed PTY reason codes and the 5000ms subprocess budget. Native resolution and the single scoped listing consume one deadline; unknown/permission/timeout failures do not prove absence. This uses ordinary native reads and no execution graph, PTY creation or credentials. The subprocess budget is not a hard real-time bound on OS filesystem calls or the complete diagnostics response.
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
A-1 all-five managed current activity: [function/DFD and state ownership](https://github.com/kitepon/aiterm-mcp/blob/main/docs/architecture/observation-results.md). Current original-pane evidence authorizes every non-Codex read; saved span identity is not freshness. Codex tracking remains unchanged.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.13",
|
|
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": [
|