aiterm-mcp 0.63.0 → 0.63.2
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 +5 -1
- package/README.md +5 -1
- package/dist/core.js +27 -17
- package/dist/errors.js +9 -0
- package/dist/index.js +4 -1
- package/dist/process-runtime.js +14 -5
- package/docs/DESIGN.md +3 -0
- package/package.json +7 -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.63.2] - 2026-11-02
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- Accept a resumed Codex turn that is already running only when the saved conversation, a new native turn boundary and the live launch identity agree. Keep uncertain resumes blocked without resending input.
|
|
14
|
+
- Return typed `aiterm.agent-resume-error.v1` failures with the current request's input status, so consumers do not classify resume failures by parsing error text.
|
|
15
|
+
- Preserve safe OS failure details for native process reads, distinguishing timeouts, buffer limits and child exit failures without exposing command arguments or raw output.
|
|
16
|
+
|
|
17
|
+
## [0.63.1] - 2026-11-02
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Add `npm run test:dev` and a Testgate wrapper declaration for development test selection while preserving the Windows test runner and the full `npm test` entry.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Preserve printed output and correlated completion marks when ConPTY emits carriage return followed by cursor visibility controls.
|
|
24
|
+
- Keep native Windows Codex catalog fixtures until the test run ends so per-test cleanup does not race executable handle release after session shutdown.
|
|
25
|
+
|
|
10
26
|
## [0.63.0] - 2026-11-01
|
|
11
27
|
|
|
12
28
|
- Preserve Windows registry protection before native identity checks, batch exact process births, and confirm native shutdown before cleaning a closed seat.
|
|
@@ -2989,7 +3005,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
2989
3005
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
2990
3006
|
provenance.
|
|
2991
3007
|
|
|
2992
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.
|
|
3008
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.2...HEAD
|
|
3009
|
+
[0.63.2]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.1...v0.63.2
|
|
3010
|
+
[0.63.1]: https://github.com/kitepon/aiterm-mcp/compare/v0.63.0...v0.63.1
|
|
2993
3011
|
[0.63.0]: https://github.com/kitepon/aiterm-mcp/compare/v0.62.6...v0.63.0
|
|
2994
3012
|
[0.62.6]: https://github.com/kitepon/aiterm-mcp/compare/v0.62.5...v0.62.6
|
|
2995
3013
|
[0.62.5]: https://github.com/kitepon/aiterm-mcp/compare/v0.62.4...v0.62.5
|
package/README.ja.md
CHANGED
|
@@ -209,7 +209,7 @@ runtime-error store は canonical dotagents config の `collection.enabled: true
|
|
|
209
209
|
場合だけ収集し、既定OFF、network送信は行いません。tag起点CIのnpm provenance(OIDC Trusted
|
|
210
210
|
Publishing)で公開し、GitHub Release が Official MCP Registry を再登録します。
|
|
211
211
|
|
|
212
|
-
**状態:** 開発継続中 · 現行公開版 **v0.63.
|
|
212
|
+
**状態:** 開発継続中 · 現行公開版 **v0.63.2** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
213
213
|
|
|
214
214
|
### 更新と巻き戻し
|
|
215
215
|
|
|
@@ -540,6 +540,7 @@ Windowsで新しく起動するClaude・Codex・Grok・Antigravityは、本人pr
|
|
|
540
540
|
一意な子process group leader、子がなければpaneを指す。identityは`pid`、`process_group_id`、
|
|
541
541
|
`started_identity`、`argv_digest`を持ち、特定不能はnull。WindowsのPIDはnative PIDで、process groupはnull。
|
|
542
542
|
開始識別はPOSIXの`LC_ALL=C ps lstart`、WindowsのUTC ISOミリ秒、argv digestはSHA-256のhexである。
|
|
543
|
+
native process照会の失敗には、照会種別、OS error code、子processの終了code/信号、出力byte数を添える。生出力・引数・資格は含めず、既存の拒否と終了codeは維持する。
|
|
543
544
|
|
|
544
545
|
`activity.cursor`を次の照会へ渡すと、`output_changed`と`cpu_delta_seconds`を返す。初回と再作成後はnull。
|
|
545
546
|
`cpu_seconds`は現在のsubtreeの累積値で、区間中にprocessが消えた場合、増分は観測できた分だけとなり
|
|
@@ -549,6 +550,8 @@ Windowsで新しく起動するClaude・Codex・Grok・Antigravityは、本人pr
|
|
|
549
550
|
|
|
550
551
|
休止を確定した会話席は、同じsession ID・harness・会話ID・明示登録envを`pty_list`に残す。`pty_observe`は`state=hibernated`、`reason=idle_timeout`、`exists=true`を返す。pane/harnessの生存はfalse、process本人性3項目とtoken_hintはnull。未配送数と起動後process数は0、CPU累積は0、cursorと活動差分はnull。停止途中・復帰途中・失敗・native世代の不一致はunknownとする。休止席のcloseはCLIを起こさず論理席を消す。同名を明示した`agent_launch`は保存した会話と設定で再開し、harness・設定・project・明示env名の矛盾は入力前に`AGENT_RESUME_CONFLICT`で断る。`pty_open`で休止会話席を上書きしない。通常の`pty_read`・制御キー・承認操作は、休止中や世代未確定では`AGENT_RESUME_UNCONFIRMED`で断る。履歴は既存のtranscriptオプションで読める。停止ボタンは確定休止席を起こさず閉じずidleで返し、途中や不整合は拒否する。全対応OSのmanaged Claude/Codex初回起動も実端末の作成本人性を保持し、証拠欠測では休止しない。自動採番は論理席の名前も避ける。休止直前には実CLIの現在設定も確認し、不一致や確認不能なら席を保持する。Linux・macOS・Windowsのmanaged Claude/Codex会話席は最後の番の終了から30分で休止し、次の送信で同じ会話へ戻る。正の有限値の`AITERM_IDLE_MINUTES`で分数を変更できる。応答中・承認待ち・attach中・未配送・作業中の子孫・作成証拠欠測・設定未確認の席は保持する。他のharness、通常PTY、mounted execution graphは対象外。`aiterm-idle-check --session <name> --launch <32hex>`で同じ保護付き判定を一度実行できる。
|
|
551
552
|
|
|
553
|
+
Codexは復帰中にnativeの待機入力で番を始める場合がある。通常速度では、保存会話のproof、休止cursor後の新しい`task_started`、同じ生存native起動を確認したbusyだけを復帰完了とする。busy画面だけでは受理しない。この経路では利用者の作業を起動時processへ分類せず、post-startup数は未知、この起動の自動休止は無効のまま保つ。fastの復元には引き続きidleの入力欄が必要。失敗attemptは自動解除しない。復帰失敗は`isError: true`と、schema `aiterm.agent-resume-error.v1`、code `AGENT_RESUME_UNCONFIRMED`又は`AGENT_RESUME_FAILED`、`session_id`、`launch_id`、`input: "not_sent"`、`recovery: "inspect_session"`の`structuredContent`を返す。未送信は今回の本文だけを指し、CLI未起動や他のnative入力の未処理を意味しない。席を確認し、自動再送や再起動をしない。
|
|
554
|
+
|
|
552
555
|
agent sessionを閉じると失うものは、次の2項目で分かる。`activity.post_startup_process_count`は、`agent_launch`の起動準備が
|
|
553
556
|
完了した時点(初手を送る前)に居なかったprocessの数。起動直後の1分に始めた裏の作業も数える。数えないものは2つ。Codex自身の
|
|
554
557
|
補助process(`codex-code-mode-host`)と、中継`mcp-lazy`の直接の子(初めて使う時に起こすMCPの本体と、先行起動の判定)。
|
|
@@ -765,6 +768,7 @@ agent_launch({ "harness": "codex-cli", "remote": { "host": "rabbit" }, "cwd": "/
|
|
|
765
768
|
### トークン削減
|
|
766
769
|
|
|
767
770
|
- `pty_read` は既定で制御文字除去・連続重複圧縮・head+tail 折りたたみ(+復元ヒント・メタ併記)をかける。
|
|
771
|
+
- 復帰文字の後ろにカーソル表示の制御だけが続く場合も、既に印字された出力と完了印を保持する。
|
|
768
772
|
- `pty_read({ rtk: true })` は直前に送ったコマンド別の reducer(`git status`/`git log`/`grep`/`pytest` ほか)で観測出力をさらに縮約する(rtk バイナリ非依存・自前実装)。
|
|
769
773
|
- `pty_send({ rtk: true })` は既知コマンドを `rtk` 形に書き換えて送り、実行先に `rtk` があればソースで削減を効かせる(無ければ素通し)。
|
|
770
774
|
|
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.2** · 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
|
|
|
@@ -574,6 +574,7 @@ for an ordinary terminal, using the pane when no child leader exists. An identit
|
|
|
574
574
|
is null. Start identity uses POSIX `LC_ALL=C ps lstart` or Windows UTC ISO milliseconds; the argv digest is SHA-256 hex.
|
|
575
575
|
New managed Windows launches of Claude, Codex, Grok, and Antigravity keep missing native processes unknown until their launch shell records that the same CLI invocation returned. Pending input uses the existing readiness deadline; it is still checked before paste and Enter. Older launch metadata keeps its previous behavior.
|
|
576
576
|
Input admission uses fresh native ownership and its dedicated readiness screen; an unrelated activity-capture failure does not block it. Public `pty_observe` still requires the full activity observation.
|
|
577
|
+
Native process-read errors include the probe kind, OS error code, child exit status/signal and output byte counts. Raw output, arguments and credentials are excluded; the existing refusal and exit code remain unchanged.
|
|
577
578
|
|
|
578
579
|
Pass `activity.cursor` into the next observation to obtain `output_changed` and `cpu_delta_seconds`; first observations and
|
|
579
580
|
recreated panes return null differences. `cpu_seconds` is the current subtree's cumulative CPU. If a process disappeared
|
|
@@ -584,6 +585,8 @@ displayed token count or null. Callers do not need raw argv or pane-text parsing
|
|
|
584
585
|
|
|
585
586
|
A confirmed hibernation keeps the same logical session in `pty_list`, with the saved harness, conversation ID, and explicitly registered environment values. `pty_observe` returns `state: "hibernated"`, `reason: "idle_timeout"`, and `exists: true`, while both liveness fields are false and process identities and token hint are null. Pending child deliveries and post-startup process count are zero; CPU totals are zero and activity cursors and differences are null. Stopping, resuming, failed, or conflicting native generations remain unknown. Closing a hibernated seat removes it without restarting the CLI. An explicit same-name `agent_launch` resumes the saved conversation and settings; conflicting harness, settings, project, or registered environment names return `AGENT_RESUME_CONFLICT` before input. `pty_open` cannot replace a dormant agent seat. Native `pty_read`, control keys and approval actions refuse dormant or uncertain generations with `AGENT_RESUME_UNCONFIRMED`; transcript reads remain available through the existing transcript option. The stop button returns idle for a confirmed hibernated seat without waking or closing it, and refuses uncertain or conflicting generations. Initial managed Claude/Codex launches on all supported operating systems also retain the actual terminal creation identity; a missing proof prevents automatic hibernation, and automatic naming preserves logical seat names. Idle shutdown also requires confirmation of the running CLI’s settings; mismatched or unknown settings keep the seat alive. Managed Claude and Codex conversations on Linux, macOS and Windows hibernate after 30 minutes from their last completed turn and resume the same conversation on the next send. Set `AITERM_IDLE_MINUTES` to a positive finite duration to change the threshold. Busy or blocked turns, attached terminals, pending child deliveries, active descendants, missing native creation evidence and uncertain settings remain alive. Other harnesses, ordinary PTYs and mounted execution graphs are excluded. `aiterm-idle-check --session <name> --launch <32hex>` runs the same guarded check once.
|
|
586
587
|
|
|
588
|
+
Codex can start a native queued turn during resume. At standard speed, Aiterm accepts that busy state only with the saved conversation proof, a new `task_started` after the hibernation cursor and the same live native launch. A busy screen alone is insufficient. This path does not capture user work as startup scaffolding: its post-startup process count remains unknown and automatic hibernation stays disabled for that launch. Fast restoration still requires an idle composer. Failed attempts remain blocked. Resume failures return `isError: true` and `structuredContent` with schema `aiterm.agent-resume-error.v1`, code `AGENT_RESUME_UNCONFIRMED` or `AGENT_RESUME_FAILED`, `session_id`, `launch_id`, `input: "not_sent"` and `recovery: "inspect_session"`. The input status describes only this request's body; it does not prove that the CLI was never started or that other native input was not processed. Inspect the seat; do not automatically resend or restart it.
|
|
589
|
+
|
|
587
590
|
Two fields tell a caller what closing an agent session would lose. `activity.post_startup_process_count` is the number of
|
|
588
591
|
processes in the session that did not exist when `agent_launch` finished startup (before the first prompt), so background work
|
|
589
592
|
started in the first minute is counted too. Two kinds of process are not counted: Codex's own `codex-code-mode-host` helper, and
|
|
@@ -823,6 +826,7 @@ agent_launch({ "harness": "codex-cli", "remote": { "host": "rabbit" }, "cwd": "/
|
|
|
823
826
|
### Token reduction
|
|
824
827
|
|
|
825
828
|
- `pty_read` by default strips control characters, collapses repeated lines, and folds long output into head+tail (with a restore hint and a meta line).
|
|
829
|
+
- Carriage returns followed only by cursor visibility controls preserve printed output and completion marks.
|
|
826
830
|
- `pty_read({ rtk: true })` further shrinks the observed output with a per-command reducer (`git status`/`git log`/`grep`/`pytest` and more) — a self-contained reimplementation that needs no `rtk` binary.
|
|
827
831
|
- `pty_send({ rtk: true })` rewrites a known command into `rtk` form before sending, so reduction happens at the source if `rtk` exists there (passthrough otherwise).
|
|
828
832
|
|
package/dist/core.js
CHANGED
|
@@ -43,7 +43,7 @@ import { paneTokenHint } from "./harnesses/pane-tokens.js";
|
|
|
43
43
|
import { unfinishedDeliveriesOwnedBy } from "./parent-delivery-owners.js";
|
|
44
44
|
import { readLinuxProcessRegistrationIdentity, readRuntimeProcesses, readProcessIdentities, processSubtree, parentProcess, processIdentity, signalRuntimeProcess, backgroundProcesses, lazyRelayProcess, aitermProcessProbe, windowsConsoleHost, macKeepAwakeProcess, processElapsedSeconds } from "./process-runtime.js";
|
|
45
45
|
import { liveNodeExecutable } from "./live-node.js";
|
|
46
|
-
import { AitermError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
46
|
+
import { AitermError, AgentResumeError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
47
47
|
import { isWin, SOCKDIR, SOCK, tmuxCommand, tmuxCommandWithInput, sendPsmuxPayload, loadPtyBufferChunk, pasteBufferBaseArgs, tmuxNewSession, withNativeSessionCreation, withNativeSessionTarget, hasVerifiedNativeSessionTarget, registeredSessionEnvironment, registerSessionEnvironment, attachCommand, normalizePaneCommand, atomicShellMultiline, appendMarkSentinel, paneShellForSubmission, adaptShellSubmission, settlePaneLog, paneCwdArgument, sessionEnvironmentLaunch, paneCommandArgs, } from "./tmux-runtime.js";
|
|
48
48
|
import { AGENT_DEFAULT_PREFACE, sleep, currentUid, runtimeStateBase, safeStatSize, readFileRange, writeJson0600, createEmpty0600, shq, LAUNCH_ID_RE, AGENT_DONE_POLL_MS, AGENT_RATE_LIMIT_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, assertSessionName, agentsDir, readAgentGeneration, selectAgentMetadataFile, publishAgentGeneration, agentEventPath, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness, subagentInstruction, agentLineageFields, } from "./agent-shared.js";
|
|
49
49
|
import { AuthResponseError, authUi, authPromptDigest, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
@@ -472,15 +472,19 @@ function estimateTokens(s) {
|
|
|
472
472
|
return Math.ceil(s.length / 4.0);
|
|
473
473
|
}
|
|
474
474
|
export function stripControl(text) {
|
|
475
|
+
// OSC/DCS等の本文内のCRを、印字された進捗断片として扱わない。
|
|
476
|
+
text = text.replace(ANSI_RE, sequence => sequence.startsWith("\x1b[") ? sequence : "");
|
|
475
477
|
text = text.replace(/\r\n/g, "\n"); // CRLF 正規化
|
|
476
478
|
const out = [];
|
|
477
|
-
for (
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
for (const line of text.split("\n")) {
|
|
480
|
+
let visibleLine = "";
|
|
481
|
+
for (const part of line.split("\r")) {
|
|
482
|
+
const visible = part.replace(ANSI_RE, "").replace(CTRL_RE, "");
|
|
483
|
+
// CRとcursor表示切替だけでは、既に印字した結果や完了印を消さない。
|
|
484
|
+
if (visible !== "" || /\x1b\[[0-2]?K/.test(part))
|
|
485
|
+
visibleLine = visible;
|
|
481
486
|
}
|
|
482
|
-
|
|
483
|
-
out.push(line.replace(/\s+$/, "")); // rstrip
|
|
487
|
+
out.push(visibleLine.replace(/\s+$/, "")); // rstrip
|
|
484
488
|
}
|
|
485
489
|
return out.join("\n");
|
|
486
490
|
}
|
|
@@ -4673,11 +4677,15 @@ async function waitStartupSelection(name, selected) {
|
|
|
4673
4677
|
}
|
|
4674
4678
|
return false;
|
|
4675
4679
|
}
|
|
4676
|
-
async function prepareAgentInput(name, meta, options) {
|
|
4680
|
+
async function prepareAgentInput(name, meta, options, acceptRunningCodex = false) {
|
|
4677
4681
|
await ensureAgentOwnsPaneInput(name, meta.kind);
|
|
4678
|
-
|
|
4682
|
+
// A resumed Codex can consume its native queue before the composer becomes idle.
|
|
4683
|
+
const running = (screen) => acceptRunningCodex && meta.kind === "codex" && !!meta.resumed_from
|
|
4684
|
+
&& codexPaneObservation(screen).state === "busy" && codexRunningTurn(meta) !== null;
|
|
4685
|
+
const wait = () => waitAgentTuiReady(name, meta, options.ready_timeout ?? AGENT_TUI_READY_TIMEOUT_MS, { selectSteer: running });
|
|
4686
|
+
let ready = await wait();
|
|
4679
4687
|
const handled = new Set();
|
|
4680
|
-
while (!ready.ready) {
|
|
4688
|
+
while (!ready.ready && !ready.steer) {
|
|
4681
4689
|
const action = meta.kind === "codex" ? codexStartupAction(ready.lastScreen, options.trust_project === true)
|
|
4682
4690
|
: meta.kind === "claude" ? claudeStartupAction(ready.lastScreen, options.trust_project === true)
|
|
4683
4691
|
: meta.kind === "grok" ? grokStartupAction(ready.lastScreen, options.trust_project === true)
|
|
@@ -4705,15 +4713,17 @@ async function prepareAgentInput(name, meta, options) {
|
|
|
4705
4713
|
await withExecutionNativeAdmission(name, () => sendKey(name, action.keys.at(-1), { preserveAgentOperation: true }));
|
|
4706
4714
|
await sleep(AGENT_SUBMIT_DELAY_MS);
|
|
4707
4715
|
}
|
|
4708
|
-
ready = await
|
|
4716
|
+
ready = await wait();
|
|
4709
4717
|
}
|
|
4710
|
-
if (!ready.ready)
|
|
4718
|
+
if (!ready.ready && !ready.steer)
|
|
4711
4719
|
return { status: "blocked", reason: agentPaneObservation(meta.kind, ready.lastScreen).reason };
|
|
4712
4720
|
const live = observeNativeSession(name);
|
|
4713
|
-
if (live.harness_alive !== true || live.harness_process === null
|
|
4721
|
+
if (live.harness_alive !== true || live.harness_process === null
|
|
4722
|
+
|| (live.state !== "idle" && !(ready.steer && live.state === "busy" && codexRunningTurn(meta) !== null)))
|
|
4714
4723
|
return { status: "blocked", reason: live.reason };
|
|
4715
4724
|
// ここまでに居るprocessは起動時の足場(harness・MCP・起動時hook)。初手を送る前に控える。
|
|
4716
|
-
|
|
4725
|
+
// shortcut: a native queued turn can already own children, so leave its startup baseline unknown until a future lifecycle can distinguish them.
|
|
4726
|
+
if (live.activity.cursor !== null && !ready.steer) {
|
|
4717
4727
|
meta.startup_processes = Object.keys(decodeActivityCursor(live.activity.cursor, name).processes);
|
|
4718
4728
|
meta.startup_process_shapes = startupProcessShapes(meta.startup_processes, readRuntimeProcesses());
|
|
4719
4729
|
writeAgentMetadata(meta);
|
|
@@ -6855,7 +6865,7 @@ function confirmedAgentResumeRecipe(meta, lifecycle) {
|
|
|
6855
6865
|
}
|
|
6856
6866
|
async function resumeAgentInLock(name, readyTimeout = AGENT_TUI_READY_TIMEOUT_MS) {
|
|
6857
6867
|
const previous = loadAgentMetadata(name), lifecycle = readAgentLifecycle(previous);
|
|
6858
|
-
const uncertain = () => new
|
|
6868
|
+
const uncertain = () => new AgentResumeError("AGENT_RESUME_UNCONFIRMED", "前の復帰処理を確認できません。本文は送信していません。再送せず席の状態を確認してください。", name, previous.launch_id);
|
|
6859
6869
|
const ownAttempt = readAgentResumeAttempt(previous);
|
|
6860
6870
|
if (!lifecycle) {
|
|
6861
6871
|
if (previous.resumed_from) {
|
|
@@ -6962,7 +6972,7 @@ async function resumeAgentInLock(name, readyTimeout = AGENT_TUI_READY_TIMEOUT_MS
|
|
|
6962
6972
|
published = true;
|
|
6963
6973
|
});
|
|
6964
6974
|
const resumed = next;
|
|
6965
|
-
const ready = await prepareAgentInput(name, resumed, { ready_timeout: readyTimeout });
|
|
6975
|
+
const ready = await prepareAgentInput(name, resumed, { ready_timeout: readyTimeout }, !recipe.fast);
|
|
6966
6976
|
if (ready.status !== "ready")
|
|
6967
6977
|
throw uncertain();
|
|
6968
6978
|
// Launch argv pins standard speed; restore fast only after the native composer is ready.
|
|
@@ -6987,7 +6997,7 @@ async function resumeAgentInLock(name, readyTimeout = AGENT_TUI_READY_TIMEOUT_MS
|
|
|
6987
6997
|
writeAgentResumeAttempt(previous, { ...issued, state: "failed", at: new Date().toISOString() });
|
|
6988
6998
|
}
|
|
6989
6999
|
catch { /* resuming also blocks replay */ }
|
|
6990
|
-
throw new
|
|
7000
|
+
throw new AgentResumeError("AGENT_RESUME_FAILED", `同じ会話への復帰を確認できません。本文は送信していません。再送せず席の状態を確認してください。${error instanceof ExecutionError ? ` ${error.code}` : ""}`, name, next?.launch_id ?? previous.launch_id);
|
|
6991
7001
|
}
|
|
6992
7002
|
});
|
|
6993
7003
|
}
|
package/dist/errors.js
CHANGED
|
@@ -19,6 +19,15 @@ export class AgentAuthenticationPreflightError extends AitermError {
|
|
|
19
19
|
this.name = "AgentAuthenticationPreflightError";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
/** Resume failures occur before the caller's body reaches the input path. */
|
|
23
|
+
export class AgentResumeError extends AitermError {
|
|
24
|
+
resumeFailure;
|
|
25
|
+
constructor(code, message, sessionId, launchId) {
|
|
26
|
+
super(`${code}: ${message}`, 2);
|
|
27
|
+
this.resumeFailure = { schema: "aiterm.agent-resume-error.v1", code,
|
|
28
|
+
session_id: sessionId, launch_id: launchId, input: "not_sent", recovery: "inspect_session" };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
22
31
|
export class TelemetryOwnedError extends AitermError {
|
|
23
32
|
telemetryCode;
|
|
24
33
|
constructor(message, code, telemetryCode, cause) {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { AuthResponseError, authUiSchema, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
3
|
-
import { AitermError, AgentAuthenticationPreflightError } from "./errors.js";
|
|
3
|
+
import { AitermError, AgentAuthenticationPreflightError, AgentResumeError } from "./errors.js";
|
|
4
4
|
/**
|
|
5
5
|
* aiterm-mcp — AI が握るローカル永続端末を stdio MCP サーバとして公開する(Node/TS 版)。
|
|
6
6
|
*
|
|
@@ -176,6 +176,9 @@ export function createAitermServer(options = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
function fail(e) {
|
|
178
178
|
const msg = e instanceof Error ? e.message : String(e);
|
|
179
|
+
if (e instanceof AgentResumeError)
|
|
180
|
+
return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
|
181
|
+
structuredContent: { ...e.resumeFailure } };
|
|
179
182
|
const sendFailure = e instanceof AitermError ? e.sendFailure : undefined;
|
|
180
183
|
if (sendFailure)
|
|
181
184
|
return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
package/dist/process-runtime.js
CHANGED
|
@@ -91,13 +91,22 @@ export function windowsConsoleHost(row) {
|
|
|
91
91
|
const name = (row.executable || first?.[1] || first?.[2] || "").replace(/\\/g, "/");
|
|
92
92
|
return path.posix.basename(name).toLowerCase() === "conhost.exe";
|
|
93
93
|
}
|
|
94
|
+
function processReadError(probe, result) {
|
|
95
|
+
const code = result.error?.code;
|
|
96
|
+
// Native error messages and stderr can contain argv and credentials.
|
|
97
|
+
const detail = { probe, code: result.error
|
|
98
|
+
? (code && ["ETIMEDOUT", "ENOBUFS", "EAGAIN", "ENOENT", "EACCES", "ENOMEM", "EMFILE", "ENFILE", "E2BIG", "EPERM"].includes(code) ? code : "UNKNOWN") : null,
|
|
99
|
+
status: result.status ?? null, signal: result.signal ?? null,
|
|
100
|
+
stdout_bytes: Buffer.byteLength(result.stdout ?? ""), stderr_bytes: Buffer.byteLength(result.stderr ?? "") };
|
|
101
|
+
return new AitermError(`${isWin ? "Windowsのnative process" : "OSのprocess"}一覧を取得できません ${JSON.stringify(detail)}`, 2);
|
|
102
|
+
}
|
|
94
103
|
export function readRuntimeProcesses(includeSession = false) {
|
|
95
104
|
if (!isWin) {
|
|
96
105
|
const result = spawnSync(POSIX_PS, includeSession ? POSIX_SESSION_TABLE_ARGS : POSIX_TABLE_ARGS, {
|
|
97
106
|
encoding: "utf8", env: { ...process.env, LC_ALL: "C" }, timeout: 10000, maxBuffer: 16 * 1024 * 1024,
|
|
98
107
|
});
|
|
99
108
|
if (result.error || result.status !== 0)
|
|
100
|
-
throw
|
|
109
|
+
throw processReadError(includeSession ? "session_table" : "table", result);
|
|
101
110
|
return parsePosixProcessTable(result.stdout, includeSession);
|
|
102
111
|
}
|
|
103
112
|
const script = [
|
|
@@ -110,7 +119,7 @@ export function readRuntimeProcesses(includeSession = false) {
|
|
|
110
119
|
encoding: "utf8", timeout: 15000, maxBuffer: 16 * 1024 * 1024, windowsHide: true,
|
|
111
120
|
});
|
|
112
121
|
if (result.error || result.status !== 0)
|
|
113
|
-
throw
|
|
122
|
+
throw processReadError(includeSession ? "session_table" : "table", result);
|
|
114
123
|
let rows;
|
|
115
124
|
try {
|
|
116
125
|
rows = JSON.parse(result.stdout);
|
|
@@ -194,7 +203,7 @@ export function readProcessIdentities(pids) {
|
|
|
194
203
|
});
|
|
195
204
|
// 該当するprocessが一つも無い時、psは何も出さずstatus 1で終わる。
|
|
196
205
|
if (result.error || (result.status !== 0 && !(result.status === 1 && !result.stdout.trim()))) {
|
|
197
|
-
throw
|
|
206
|
+
throw processReadError("identity", result);
|
|
198
207
|
}
|
|
199
208
|
return result.stdout.split("\n").filter(line => line.trim()).map(line => {
|
|
200
209
|
const match = /^\s*(\d+)\s+(\S+\s+\S+\s+\d+\s+\S+\s+\d+)\s*$/.exec(line);
|
|
@@ -230,7 +239,7 @@ export function readProcessIdentities(pids) {
|
|
|
230
239
|
encoding: "utf8", timeout: 15000, windowsHide: true,
|
|
231
240
|
});
|
|
232
241
|
if (result.error || result.status !== 0)
|
|
233
|
-
throw
|
|
242
|
+
throw processReadError("identity", result);
|
|
234
243
|
let rows;
|
|
235
244
|
try {
|
|
236
245
|
rows = JSON.parse(result.stdout);
|
|
@@ -306,7 +315,7 @@ export function processElapsedSeconds(pid) {
|
|
|
306
315
|
const text = (result.stdout ?? "").trim();
|
|
307
316
|
// 該当するprocessが無い時、psは何も出さずstatus 1で終わる。
|
|
308
317
|
if (result.error || (result.status !== 0 && !(result.status === 1 && !text)))
|
|
309
|
-
throw
|
|
318
|
+
throw processReadError("elapsed", result);
|
|
310
319
|
if (!text)
|
|
311
320
|
return null;
|
|
312
321
|
const elapsed = parsePosixElapsed(text);
|
package/docs/DESIGN.md
CHANGED
|
@@ -85,6 +85,7 @@ coreの観測(`pty_observe`)・起動準備・送信口・停止は`kind`を
|
|
|
85
85
|
agent入力欄への`bracketedPaste`は、制御文字の除去後も本文のまま渡す。nativeの前面process名が起動shellを報告していてもshell実行文へ変換しない。shell用のUTF-8初期化・複数行適合はshell送信(利用者のshell送信と、Aiterm自身のbash起動command)だけに適用する。
|
|
86
86
|
|
|
87
87
|
`pty_read`は制御文字除去、反復圧縮、head+tail、command別reducerでcontext量を減らす。
|
|
88
|
+
CR後の表示制御だけの断片は既印字内容を消さず、文字による進捗上書きと明示的な行消去は維持する。同じ整形を使うmark検出でも結果と相関IDを保持する。
|
|
88
89
|
完了はprocess exit、shell sentinel、literal/regex `until`、shell復帰を伴うquiescence、timeoutを区別する。
|
|
89
90
|
新しいmarkは送信IDを完了印と待機fileへ結び、旧commandの印を次の完了へ使わない。旧producerのpending flagは読取り互換を保ち、旧readの完了で新しい待機fileを消さない。ID保存失敗は入力前拒否。
|
|
90
91
|
要求されたsentinel/untilを静止判定より優先し、nested shellで証拠がない状態を完了へ丸めない。
|
|
@@ -189,6 +190,8 @@ Codex v1のactive goalは設定替えの間だけ一時停止する。`configure
|
|
|
189
190
|
|
|
190
191
|
休止判定の部品はagent-idle.ts、木の停止はprocess-tree-stop.tsに置く。前者はruntimeが供給する既存の席admissionで世代/入力/保護条件を再確認し、未確定を成功にしない。後者は本人性を照合したpane木へTERM→5秒→KILLと退出確認を行い、POSIXの別sessionを除外する。OSごとのsignalはprocess-runtime.tsが所有する。本体adapterは既存送信queue/file lockで期待launchと元のnative ID/pane本人性を固定する。最新native完了の保存とprivate resume recipeの一致を確認し、durable stoppingの後も最初のsignal前は保護条件全体を再確認する。効果前だけ準備を取消し、効果後の不明はstoppingに残す。木の退出後に元native IDを閉じ、同世代だけをhibernatedへ進める。時計はper-launchのdetached shell/sleep(WindowsはPowerShell 7)で待ち、起床時だけNodeで同じC判定を行う。owner/tokenを同じ送信排他で記録し、busy等は60秒後の後続確認を持つ。list/launch/Stop/waiterから起動口を通し、元のnative作成proofが無い旧席には時計を登録しない。新規起動templateと設定替えの更新は接続し、既定値欠測や途中設定失敗は休止を許可しない。各世代のmetadataは保持し、active-launch.jsonの原子的切替で現在のlaunchを選ぶ。Codexの停止前には一意な起動marker付きroot/完了境界を検証し、file本人性・prefix hash・旧cursor/turn IDのproofをlifecycleへ束縛する。resumed_fromを持つ読取りは旧metadata/lifecycle/recipe/proofを照合し、保存cursor以前と最後の旧turnの遅れた記録を除外する。通常waiter・番境界・差し込み・合間の言葉と次回停止が同じ相関を使い、復帰後の/newは新markerだけで認める。物理再開候補は同じ送信排他で旧stateを残し、新世代の公式resume→ready/fast確認→本文投入を進める。private resume-attemptの失敗は追加CLIと本文を止め、Claudeの設定rootもper-launchで保持する。通常POSIXのmanaged Claude/Codex初回起動も、実create receiptをその場で取得し、送信/休止と同じfile lockを取ってから旧記録を掃除する。同名置換・休止競合ではCLIを入れず古い記録を残し、自動採番も論理席名を避ける。実create receipt由来のnative IDとserver/paneの開始本人性をprivateに保存し、同じ送信排他でCLI/ready/fast/本文と後続操作を固定する。tmux受信側のnative format条件も同じqueueで確かめ、server再起動によるID再利用を拒否する。既存effect guardを迂回せず、正規resume transitionの無いmounted graphは停止・再開対象外にする。Windowsはqualified paneと固定server認証・native本人性を用いる。既存psmux registry保護を開始本人性取得の前へ置き、server/paneの開始時刻は保存精度を保って一括取得する。Windows closeは元server終了の確認後に記録を片付ける。受信側命令の引用はpsmuxのparserに合わせる。Windowsのnative clockはconsoleを継がないProcessStartInfoとnull標準handleで起こし、一時receiptのPID/開始時刻を保存して起動helperを終了する。同名agent_launchも保存設定を照合して同会話へ戻し、既存の初手/tupleを使う。公開list/observe/seat_turns/closeは論理席を扱い、内部の物理観測と分離する。native読取り/キー/承認は休止・復帰途中・失敗を拒否し、復帰先の実receiptへ固定する。中断は確定休止ならidleで返し、途中や不整合を拒否する。キーと承認応答は送信file lockを共有し、停止ボタンの即時性と既存のキー制限は維持する。登録env名も再現し、復帰中から公開一覧の本人性を保つ。native手動設定とClaude/Codex各3OSの実会話復帰、公開論理席とconsumerを受入済み。元作成証拠を持たない旧席・未受入harnessは対象へ登録しない(ADR 0138)。
|
|
191
192
|
|
|
193
|
+
Codexの通常速度の復帰は、保存会話proofのcursor後の新しいtask_startedと固定nativeの生存が揃うbusyも受理する。既存のsteer判定へ戻し、idle待ちのtimeoutで正常なnative番をfailedへ固定しない。利用者の子をstartup baselineへ分類せず、この場合のbaselineと自動休止可否は未知のまま保持する。fast復元はidleで行い、failed attemptは自動解除しない。復帰失敗は型付きaiterm.agent-resume-error.v1で今回本文の未送信と席確認の必要を返し、他の入力やnative起動の結果と混同しない(ADR 0138)。
|
|
194
|
+
|
|
192
195
|
agent turnは常に非ブロックdispatchであり、receiptの`event_cursor`がturn境界になる。
|
|
193
196
|
Codex親にはAitermのMCP processが完了を観測し、選択設定に応じて公式Steerまたはqueueへ本文を自動配送する。
|
|
194
197
|
Claude Code親は公式の非同期hookで本文を受け取り、待機中も新しいturnへ進める。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.2",
|
|
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": [
|
|
@@ -62,12 +62,18 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=18"
|
|
64
64
|
},
|
|
65
|
+
"testgate": {
|
|
66
|
+
"wrappers": {
|
|
67
|
+
"scripts/run-seat-tests.mjs": {}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
65
70
|
"scripts": {
|
|
66
71
|
"build": "node scripts/clean-build.mjs && tsc",
|
|
67
72
|
"mcpb:build": "npm run build && node scripts/build-mcpb.mjs && npm ci --omit=dev --ignore-scripts --no-audit --no-fund --prefix dist/mcpb-stage/server && npx --yes @anthropic-ai/mcpb@2.1.2 validate dist/mcpb-stage/manifest.json && npx --yes @anthropic-ai/mcpb@2.1.2 pack dist/mcpb-stage dist/aiterm-mcp.mcpb",
|
|
68
73
|
"verify:release-commit": "node scripts/verify-release-commit.mjs",
|
|
69
74
|
"release": "node scripts/release.mjs",
|
|
70
75
|
"test:docs": "node scripts/run-seat-tests.mjs --test test/repository-contract.test.mjs",
|
|
76
|
+
"test:dev": "node scripts/run-seat-tests.mjs --test scripts/verify-release-commit.test.mjs test/*.test.mjs",
|
|
71
77
|
"prepublishOnly": "npm run verify:release-commit && npm run build",
|
|
72
78
|
"start": "node dist/index.js",
|
|
73
79
|
"test": "npm run build && node scripts/run-seat-tests.mjs --test test/seat-env.test.mjs && node scripts/run-seat-tests.mjs --test scripts/verify-release-commit.test.mjs test/*.test.mjs",
|