aiterm-mcp 0.52.0 → 0.52.1
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 +16 -1
- package/README.ja.md +3 -1
- package/README.md +3 -1
- package/dist/core.js +185 -4
- package/docs/DESIGN.md +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.52.1] - 2026-10-05
|
|
11
|
+
|
|
12
|
+
### 修正
|
|
13
|
+
|
|
14
|
+
- 同じagent sessionへの`pty_send`が重なると、後の1通が断られる事があった(ADR 0088)。Aitermは送る時点の子の状態を見て
|
|
15
|
+
差し込みか新しいturnかを決めるが、見てから送り終えるまでの間に起動直後の入力受付待ち(最長30秒)が挟まり、
|
|
16
|
+
その区間を守るものが無かった。Claude Codeでは2通ともturnの印が無いと読み、後の1通が
|
|
17
|
+
「operation_idなしのClaude turn が未解決です」で断られた(文は打たれない)。Codex・Grok・Cursorでは断りにならず、
|
|
18
|
+
同じ入力欄へ2通が続けて貼られ、1行につながって届いた。同じsessionへの送信(`pty_send`、`claude_turn issue`、起動時prompt)を
|
|
19
|
+
1本ずつ通し、後の1通は前の1通が終わってから振り分け直す。順に送った時と同じ結果になり、Claude Codeへ重なった後の1通は
|
|
20
|
+
`mode=agent_steer`で返る。前の1通を待つ分だけ返りが遅れる。待つ上限(POSIX 60秒、Windows 180秒)を越えたら、
|
|
21
|
+
打鍵前に`AGENT_SEND_BUSY`と「文字列は送信していません」を返す。送信の途中で終了したprocessのlockは、次の送信が片付ける。
|
|
22
|
+
公開toolの返却形式とstate schemaは変えていない。旧版へ戻す時の手当ては要らない。
|
|
23
|
+
|
|
10
24
|
## [0.52.0] - 2026-10-04
|
|
11
25
|
|
|
12
26
|
### 修正
|
|
@@ -2103,7 +2117,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
2103
2117
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
2104
2118
|
provenance.
|
|
2105
2119
|
|
|
2106
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.52.
|
|
2120
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.52.1...HEAD
|
|
2121
|
+
[0.52.1]: https://github.com/kitepon/aiterm-mcp/compare/v0.52.0...v0.52.1
|
|
2107
2122
|
[0.52.0]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.3...v0.52.0
|
|
2108
2123
|
[0.51.3]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.2...v0.51.3
|
|
2109
2124
|
[0.51.2]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.1...v0.51.2
|
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.52.
|
|
212
|
+
**状態:** 開発継続中 · 現行公開版 **v0.52.1** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
213
213
|
|
|
214
214
|
### 更新と巻き戻し
|
|
215
215
|
|
|
@@ -261,6 +261,8 @@ ClaudeがAPIエラーや安全判定の拒否で終了した時は、Stop hook
|
|
|
261
261
|
|
|
262
262
|
agent配送だけを期待する連携では、`pty_send`に`require_agent:true`を指定する。agent登録が無ければ、打鍵前に`AGENT_SESSION_REQUIRED`と「文字列は送信していません」を返す。省略時は通常PTY送信を維持する。`force:true`との併用は未送信で拒否する。
|
|
263
263
|
|
|
264
|
+
同じagent sessionへの`pty_send`が重なった時は、1本ずつ通す。後の1通は、前の1通を送り終えてから振り分け直すので、順に送った時と同じ結果になる(起動直後のClaude Codeへ重なった後の1通は`mode=agent_steer`で返る)。前の1通が起動直後の入力受付待ちなら、その分だけ返りが遅れる。待つ上限(POSIX 60秒、Windows 180秒)を越えた時は、打鍵前に`AGENT_SEND_BUSY`と「文字列は送信していません」を返す。送信の途中で終了したprocessのlockは、次の送信が片付けて進む。
|
|
265
|
+
|
|
264
266
|
`agent_launch`・`pty_send`(agent session宛て)は任意の`image`(画像ファイルの絶対パスの配列。png/jpg/jpeg/gif/webp)を受ける。aitermが本文末尾へ添付行を付け、どのharnessも自分のfile読取toolでそのpathを画像として開く。呼出し側はharness別の添付手順を覚えない。不正なpathは送信前に拒否する。
|
|
265
267
|
|
|
266
268
|
`agent_launch`は任意の`write_scope`も受ける。Codex/Grokのread-onlyは`--sandbox read-only`、Cursorは公式`--mode ask`で実効化する。path説明は同等CLI引数がないためdeclaration-only。
|
package/README.md
CHANGED
|
@@ -223,7 +223,7 @@ collection is off by default and performs no network I/O. It ships via
|
|
|
223
223
|
tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
|
|
224
224
|
Release re-registers the Official MCP Registry entry.
|
|
225
225
|
|
|
226
|
-
**Status:** actively maintained · current public release **v0.52.
|
|
226
|
+
**Status:** actively maintained · current public release **v0.52.1** · 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).
|
|
227
227
|
|
|
228
228
|
### Update and rollback
|
|
229
229
|
|
|
@@ -282,6 +282,8 @@ The same primitive hosts another agent's TUI. `agent_launch` starts a selected e
|
|
|
282
282
|
|
|
283
283
|
Set `require_agent:true` on `pty_send` when the integration requires agent delivery. If the agent registration is missing, Aiterm refuses before sending any text and returns `AGENT_SESSION_REQUIRED` with an explicit unsent message. The default preserves ordinary PTY sends; combining it with `force:true` is rejected before sending.
|
|
284
284
|
|
|
285
|
+
Overlapping `pty_send` calls to the same agent session are handled one at a time. A later call picks its route only after the earlier one has been sent, so the result matches calls made in sequence (a call that overlaps the first send to a freshly started Claude Code session returns `mode=agent_steer`). It returns later by however long the earlier call waits for the session to accept input. If its turn does not come within the limit (60 seconds on POSIX, 180 seconds on Windows), Aiterm refuses before sending any text and returns `AGENT_SEND_BUSY` with an explicit unsent message. A lock left by a process that exited mid-send is cleared by the next send.
|
|
286
|
+
|
|
285
287
|
`agent_launch` and `pty_send` (to an agent session) accept an optional `image`: an array of absolute paths to image files (png/jpg/jpeg/gif/webp). Aiterm appends an attachment block to the prompt, and every harness opens the path with its own file-reading tool and sees the image; the caller never learns harness-specific attachment tricks. Invalid paths are rejected before anything is sent.
|
|
286
288
|
|
|
287
289
|
`agent_launch` accepts an optional `write_scope`: either `"read-only"` or a human-readable description of writable paths. Codex/Grok use `--sandbox read-only`; Cursor uses its official read-only `--mode ask`. A path description remains declaration-only because these CLI launch surfaces provide no equivalent path allowlist flag.
|
package/dist/core.js
CHANGED
|
@@ -86,6 +86,10 @@ const PTY_PASTE_CHUNK_PAUSE_MS = 10;
|
|
|
86
86
|
const PTY_PASTE_PAUSE_BUFFER = new Int32Array(new SharedArrayBuffer(4));
|
|
87
87
|
const SESSION_SEND_LOCK_WAIT_MS = isWin ? 130_000 : 10_000;
|
|
88
88
|
const SESSION_SEND_LOCK_POLL_MS = 25;
|
|
89
|
+
// 同じagent sessionへの送信が重なった時に、前の1通を待つ上限(ADR 0088)。
|
|
90
|
+
// 起動から最初の描画を待つ上限と、貼り付けの上限の和。前の1通が正常に進んでいる間は待ち切れる長さにする。
|
|
91
|
+
const AGENT_SEND_LOCK_WAIT_MS = AGENT_TUI_FIRST_DRAW_TIMEOUT_MS + SESSION_SEND_LOCK_WAIT_MS;
|
|
92
|
+
const AGENT_SEND_LOCK_POLL_MS = 50;
|
|
89
93
|
// CSI/OSC/ESC エスケープ・制御文字
|
|
90
94
|
// CSI / OSC(BEL or ST 終端) / DCS・PM・APC・SOS(ESC P/^/_/X … BEL or ST 終端。ペイロード本文ごと除去=B10) / 残る2文字エスケープ
|
|
91
95
|
const ANSI_RE = /\x1b\[[0-9;?]*[ -\/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[P^_X][\s\S]*?(?:\x07|\x1b\\)|\x1b[@-_]/g;
|
|
@@ -349,6 +353,15 @@ function sendLockPath(name) {
|
|
|
349
353
|
assertSessionName(name);
|
|
350
354
|
return path.join(SOCKDIR, name + ".send.lock");
|
|
351
355
|
}
|
|
356
|
+
// agent sessionへの送信1本(振り分け〜Enterの確認)を守るlock。貼り付け1回ぶんの`.send.lock`とは別に持つ。
|
|
357
|
+
function agentSendLockPath(name) {
|
|
358
|
+
assertSessionName(name);
|
|
359
|
+
return path.join(SOCKDIR, name + ".agent-send.lock");
|
|
360
|
+
}
|
|
361
|
+
// 持ち主が終了した`.agent-send.lock`を片付ける役の印。
|
|
362
|
+
function agentSendReapPath(name) {
|
|
363
|
+
return agentSendLockPath(name) + ".reap";
|
|
364
|
+
}
|
|
352
365
|
function readOffset(name) {
|
|
353
366
|
try {
|
|
354
367
|
const n = parseInt(fs.readFileSync(offsetpath(name), "utf8").trim(), 10);
|
|
@@ -1345,6 +1358,7 @@ function closeSessionInternal(name, observeDependency = true) {
|
|
|
1345
1358
|
/* noop */
|
|
1346
1359
|
}
|
|
1347
1360
|
}
|
|
1361
|
+
cleanupAgentSendLock(name);
|
|
1348
1362
|
cleanupAgentState(name);
|
|
1349
1363
|
agentLaunchLines.delete(name);
|
|
1350
1364
|
return `closed ${name}`;
|
|
@@ -1390,7 +1404,7 @@ export function killAll() {
|
|
|
1390
1404
|
/* socketの置き場が無い */
|
|
1391
1405
|
}
|
|
1392
1406
|
for (const file of socketFiles) {
|
|
1393
|
-
const name = file.replace(/\.(?:log|offset|lastcmd|mark|send\.lock)$/, "");
|
|
1407
|
+
const name = file.replace(/\.(?:log|offset|lastcmd|mark|send\.lock|agent-send\.lock(?:\.reap)?)$/, "");
|
|
1394
1408
|
if (name !== file && /^[A-Za-z0-9_-]{1,64}$/.test(name))
|
|
1395
1409
|
sessions.add(name);
|
|
1396
1410
|
}
|
|
@@ -1413,10 +1427,10 @@ export function killAll() {
|
|
|
1413
1427
|
if (killed.code !== 0 && !/no server running|No such file or directory|failed to connect/i.test(killed.stderr)) {
|
|
1414
1428
|
throw new AitermError("このsocketのserverを終了できません: " + killed.stderr.trim(), 2);
|
|
1415
1429
|
}
|
|
1416
|
-
// B9: SOCKDIR 内の .log/.offset/.lastcmd/.mark/.send.lock 残骸も掃除する。
|
|
1430
|
+
// B9: SOCKDIR 内の .log/.offset/.lastcmd/.mark/.send.lock/.agent-send.lock 残骸も掃除する。
|
|
1417
1431
|
try {
|
|
1418
1432
|
for (const f of fs.readdirSync(SOCKDIR)) {
|
|
1419
|
-
if (/\.(log|offset|lastcmd|mark)$/.test(f) || f.endsWith(".send.lock")) {
|
|
1433
|
+
if (/\.(log|offset|lastcmd|mark)$/.test(f) || f.endsWith(".send.lock") || /\.agent-send\.lock(?:\.reap)?$/.test(f)) {
|
|
1420
1434
|
try {
|
|
1421
1435
|
fs.unlinkSync(path.join(SOCKDIR, f));
|
|
1422
1436
|
}
|
|
@@ -1965,6 +1979,159 @@ function acquireSessionSendFileLock(name) {
|
|
|
1965
1979
|
}
|
|
1966
1980
|
};
|
|
1967
1981
|
}
|
|
1982
|
+
// ── 同じagent sessionへの送信を1本ずつ通す(ADR 0088) ────
|
|
1983
|
+
// 振り分け(差し込みか新しいturnか)から送り終えるまでの間に、入力受付待ちなどの待ちが挟まる。
|
|
1984
|
+
// その間に次の1通が同じ状態を読むと、Claudeはturnの印の取り合いで後の1通が断られ、他のharnessは同じ入力欄へ2回貼る。
|
|
1985
|
+
// 同じprocessの中は着いた順の待ち行列、別のprocessの間はfileで排他し、後の1通は前の1通が終わってから振り分け直す。
|
|
1986
|
+
const agentSendQueues = new Map();
|
|
1987
|
+
const agentSendHeld = new Set();
|
|
1988
|
+
let agentSendLockWaitMs = AGENT_SEND_LOCK_WAIT_MS;
|
|
1989
|
+
export function __testSetAgentSendLockWaitMs(value) {
|
|
1990
|
+
if (value !== null && (!Number.isSafeInteger(value) || value < 0))
|
|
1991
|
+
throw new Error("wait must be a non-negative integer");
|
|
1992
|
+
agentSendLockWaitMs = value ?? AGENT_SEND_LOCK_WAIT_MS;
|
|
1993
|
+
}
|
|
1994
|
+
// `O_EXCL`で作れた時だけ持ち主になる。既に在れば null。
|
|
1995
|
+
function tryCreateOwnedLock(p) {
|
|
1996
|
+
const nofollow = fs.constants.O_NOFOLLOW ?? 0;
|
|
1997
|
+
let fd;
|
|
1998
|
+
try {
|
|
1999
|
+
fd = fs.openSync(p, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY | nofollow, 0o600);
|
|
2000
|
+
}
|
|
2001
|
+
catch (e) {
|
|
2002
|
+
const code = e.code;
|
|
2003
|
+
// Windowsは、消している途中のfile(他のprocessがまだ開いている)と同じ名前を作るとEPERM/EACCESになる。
|
|
2004
|
+
if (code === "EEXIST" || (isWin && (code === "EPERM" || code === "EACCES")))
|
|
2005
|
+
return null;
|
|
2006
|
+
throw e;
|
|
2007
|
+
}
|
|
2008
|
+
const token = randomBytes(16).toString("hex");
|
|
2009
|
+
try {
|
|
2010
|
+
// 書けなかったlockは中身が読めないまま残り、鮮度猶予の後に持ち主なしとして片付く。
|
|
2011
|
+
fs.writeFileSync(fd, JSON.stringify({ pid: process.pid, at: new Date().toISOString(), token }) + "\n", "utf8");
|
|
2012
|
+
}
|
|
2013
|
+
finally {
|
|
2014
|
+
fs.closeSync(fd);
|
|
2015
|
+
}
|
|
2016
|
+
return token;
|
|
2017
|
+
}
|
|
2018
|
+
function releaseOwnedLock(p, token) {
|
|
2019
|
+
try {
|
|
2020
|
+
const st = fs.lstatSync(p);
|
|
2021
|
+
if (!st.isFile() || st.isSymbolicLink())
|
|
2022
|
+
return;
|
|
2023
|
+
const current = JSON.parse(fs.readFileSync(p, "utf8").split("\n", 1)[0]);
|
|
2024
|
+
if (current.token === token)
|
|
2025
|
+
fs.unlinkSync(p);
|
|
2026
|
+
}
|
|
2027
|
+
catch {
|
|
2028
|
+
/* 別の持ち主のlockや置換済みpathは消さない */
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
// 同じprocessの送信は待ち行列で1本になっているので、自分のpidのlockは外し損ねた残骸と読める(probeWaitLock)。
|
|
2032
|
+
// このprocessが持っている最中のlockだけは、その読みから外す。
|
|
2033
|
+
function probeAgentSendLock(name) {
|
|
2034
|
+
const probe = probeWaitLock(agentSendLockPath(name));
|
|
2035
|
+
return probe.pid === process.pid && agentSendHeld.has(name) ? { ...probe, live: true } : probe;
|
|
2036
|
+
}
|
|
2037
|
+
// 持ち主が終了したlockを片付ける。確かめてから消すまでの間に別のprocessが新しいlockを作ると生きたlockを消すので、
|
|
2038
|
+
// 消す役を`.reap`の`O_EXCL`で1つに絞り、その中でもう一度確かめてから消す。lockが在る間は誰も新しいlockを作れない。
|
|
2039
|
+
// done=片付けた(または片付ける物が無かった)/busy=別のprocessが片付け中/stuck=片付けの印が持ち主なしで残っている
|
|
2040
|
+
function reapDeadAgentSendLock(name) {
|
|
2041
|
+
const guard = agentSendReapPath(name);
|
|
2042
|
+
const token = tryCreateOwnedLock(guard);
|
|
2043
|
+
if (token === null)
|
|
2044
|
+
return probeWaitLock(guard).live ? "busy" : "stuck";
|
|
2045
|
+
try {
|
|
2046
|
+
if (!probeAgentSendLock(name).live) {
|
|
2047
|
+
try {
|
|
2048
|
+
fs.unlinkSync(agentSendLockPath(name));
|
|
2049
|
+
}
|
|
2050
|
+
catch {
|
|
2051
|
+
/* 既に無い */
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
finally {
|
|
2056
|
+
releaseOwnedLock(guard, token);
|
|
2057
|
+
}
|
|
2058
|
+
return "done";
|
|
2059
|
+
}
|
|
2060
|
+
function agentSendBusyError(name, pid, waitMs) {
|
|
2061
|
+
return new AitermError(`AGENT_SEND_BUSY: agent session '${name}' は${pid != null ? `別プロセス(pid ${pid})` : "先に受け付けた送信"}の処理中です。` +
|
|
2062
|
+
`${waitMs}ms待っても順番が来ませんでした。文字列は送信していません。少し後で再度 pty_send してください。`, 2);
|
|
2063
|
+
}
|
|
2064
|
+
async function acquireAgentSendFileLock(name, deadline, waitMs) {
|
|
2065
|
+
const p = agentSendLockPath(name);
|
|
2066
|
+
for (;;) {
|
|
2067
|
+
const token = tryCreateOwnedLock(p);
|
|
2068
|
+
if (token !== null)
|
|
2069
|
+
return () => releaseOwnedLock(p, token);
|
|
2070
|
+
const probe = probeAgentSendLock(name);
|
|
2071
|
+
if (!probe.live && reapDeadAgentSendLock(name) === "stuck") {
|
|
2072
|
+
throw new AitermError(`agent session '${name}' に、終了した送信のlockを片付ける途中で残った印があります。` +
|
|
2073
|
+
`自動回収は並行送信の混線を招くため行いません。文字列は送信していません。` +
|
|
2074
|
+
`pty_listで対象を確認し、pty_closeでsessionを閉じてから同じIDで再作成してください`, 2);
|
|
2075
|
+
}
|
|
2076
|
+
if (performance.now() >= deadline)
|
|
2077
|
+
throw agentSendBusyError(name, probe.live ? probe.pid : null, waitMs);
|
|
2078
|
+
await sleep(AGENT_SEND_LOCK_POLL_MS);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
async function withAgentSendLock(name, run) {
|
|
2082
|
+
const waitMs = agentSendLockWaitMs;
|
|
2083
|
+
const deadline = performance.now() + waitMs;
|
|
2084
|
+
const previous = agentSendQueues.get(name) ?? Promise.resolve();
|
|
2085
|
+
let leave;
|
|
2086
|
+
const mine = new Promise((resolve) => {
|
|
2087
|
+
leave = resolve;
|
|
2088
|
+
});
|
|
2089
|
+
// 待ち切れずに抜けた送信の後ろも、前の送信が終わるまで待つ。行列の控えは、ここまでの送信が全部終わってから消す。
|
|
2090
|
+
const tail = previous.then(() => mine);
|
|
2091
|
+
agentSendQueues.set(name, tail);
|
|
2092
|
+
void tail.then(() => {
|
|
2093
|
+
if (agentSendQueues.get(name) === tail)
|
|
2094
|
+
agentSendQueues.delete(name);
|
|
2095
|
+
});
|
|
2096
|
+
let timer;
|
|
2097
|
+
try {
|
|
2098
|
+
const myTurn = await Promise.race([
|
|
2099
|
+
previous.then(() => true),
|
|
2100
|
+
new Promise((resolve) => {
|
|
2101
|
+
timer = setTimeout(() => resolve(false), waitMs);
|
|
2102
|
+
}),
|
|
2103
|
+
]);
|
|
2104
|
+
clearTimeout(timer);
|
|
2105
|
+
if (!myTurn)
|
|
2106
|
+
throw agentSendBusyError(name, null, waitMs);
|
|
2107
|
+
const release = await acquireAgentSendFileLock(name, deadline, waitMs);
|
|
2108
|
+
agentSendHeld.add(name);
|
|
2109
|
+
try {
|
|
2110
|
+
return await run();
|
|
2111
|
+
}
|
|
2112
|
+
finally {
|
|
2113
|
+
agentSendHeld.delete(name);
|
|
2114
|
+
release();
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
finally {
|
|
2118
|
+
clearTimeout(timer);
|
|
2119
|
+
leave();
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
// pty_closeの掃除。生きた持ち主のlockは残す(その送信はsessionが無くなった所で失敗し、自分のlockを外す)。
|
|
2123
|
+
function cleanupAgentSendLock(name) {
|
|
2124
|
+
const guard = agentSendReapPath(name);
|
|
2125
|
+
try {
|
|
2126
|
+
if (fs.existsSync(guard) && !probeWaitLock(guard).live)
|
|
2127
|
+
fs.unlinkSync(guard);
|
|
2128
|
+
if (fs.existsSync(agentSendLockPath(name)))
|
|
2129
|
+
reapDeadAgentSendLock(name);
|
|
2130
|
+
}
|
|
2131
|
+
catch {
|
|
2132
|
+
/* 掃除の失敗で閉じる処理を止めない */
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
1968
2135
|
// close/killAll 用: 生きた別プロセス待機の wait lock を列挙する(stale 残骸は数えない)。
|
|
1969
2136
|
function liveWaitLocks(name) {
|
|
1970
2137
|
const dir = existingAgentsDir();
|
|
@@ -3291,6 +3458,11 @@ async function prepareAgentInput(name, meta, options) {
|
|
|
3291
3458
|
}
|
|
3292
3459
|
export async function sendInitialAgentPrompt(name, text, o = {}) {
|
|
3293
3460
|
assertSessionName(name);
|
|
3461
|
+
loadAgentMetadata(name);
|
|
3462
|
+
// 起動時promptの準備中に届いたpty_sendは、起動時promptを送り終えてから振り分ける(ADR 0088)。
|
|
3463
|
+
return withAgentSendLock(name, () => sendInitialAgentPromptInLock(name, text, o));
|
|
3464
|
+
}
|
|
3465
|
+
async function sendInitialAgentPromptInLock(name, text, o) {
|
|
3294
3466
|
const meta = loadAgentMetadata(name);
|
|
3295
3467
|
if (meta.initial_prompt === "done") {
|
|
3296
3468
|
throw new AitermError(`agent session '${name}' の起動時 prompt は既に完了しています`, 2);
|
|
@@ -3893,6 +4065,10 @@ async function assertCursorPromptNotHookBlocked(name) {
|
|
|
3893
4065
|
}
|
|
3894
4066
|
export async function dispatchAgentTurn(name, text, o = {}) {
|
|
3895
4067
|
assertSessionName(name);
|
|
4068
|
+
loadAgentMetadata(name);
|
|
4069
|
+
return withAgentSendLock(name, () => dispatchAgentTurnInLock(name, text, o));
|
|
4070
|
+
}
|
|
4071
|
+
async function dispatchAgentTurnInLock(name, text, o) {
|
|
3896
4072
|
const meta = loadAgentMetadata(name);
|
|
3897
4073
|
const operationId = o.operation_id == null ? null : validateOperationId(o.operation_id);
|
|
3898
4074
|
if (operationId && meta.kind !== "claude") {
|
|
@@ -4040,9 +4216,14 @@ export function __testSteerQueued(kind, screen) {
|
|
|
4040
4216
|
* agent sessionへの唯一の送信口。呼び出し側は子の状態を知らないまま呼び、Aitermがこの時点の画面で振り分ける。
|
|
4041
4217
|
* 実行中なら現在のturnへ差し込み(steer)、そうでなければ新しいturnとしてdispatchする。
|
|
4042
4218
|
* 振り分けを呼び出し側へ任せると、状態を見てから呼ぶまでの間に子のturnが変わり、選んだ入口が外れる。
|
|
4219
|
+
* 同じsessionへの送信は1本ずつ通し、重なった後の1通は前の1通が終わってから振り分け直す(ADR 0088)。
|
|
4043
4220
|
*/
|
|
4044
4221
|
export async function sendAgentMessage(name, text, o = {}) {
|
|
4045
4222
|
assertSessionName(name);
|
|
4223
|
+
loadAgentMetadata(name);
|
|
4224
|
+
return withAgentSendLock(name, () => sendAgentMessageInLock(name, text, o));
|
|
4225
|
+
}
|
|
4226
|
+
async function sendAgentMessageInLock(name, text, o) {
|
|
4046
4227
|
const meta = loadAgentMetadata(name);
|
|
4047
4228
|
// 前面回復は busy 判定より先(bash 前面のままだと画面の実行中マーカーを読んでも打鍵が届かない)。
|
|
4048
4229
|
const paneInputRecovery = await ensureAgentOwnsPaneInput(name, meta.kind);
|
|
@@ -4062,7 +4243,7 @@ export async function sendAgentMessage(name, text, o = {}) {
|
|
|
4062
4243
|
if (running) {
|
|
4063
4244
|
return steerRunningTurn(name, meta, text, { raw: o.raw, pane_input_recovery: paneInputRecovery });
|
|
4064
4245
|
}
|
|
4065
|
-
return
|
|
4246
|
+
return dispatchAgentTurnInLock(name, text, { raw: o.raw, before_send: o.before_send, pane_input_recovery: paneInputRecovery });
|
|
4066
4247
|
}
|
|
4067
4248
|
/**
|
|
4068
4249
|
* 実行中turnへ追加の指示を渡す。各harnessの標準操作だけを使い、完了境界は1つに保つ。
|
package/docs/DESIGN.md
CHANGED
|
@@ -95,6 +95,9 @@ agent sessionへの送信口は`pty_send`だけとする。子の状態は呼び
|
|
|
95
95
|
実行中なら現在のturnへ追加textを差し込み、新しい完了境界と配送は作らない。完了境界は差し込み後も1つに保つ。
|
|
96
96
|
Claude Codeはtool処理中に画面の実行中表示が消え、Stop hookの実行中には表示が残る。turnの印を実行中判定の正本とする。Stopが発火しないAPIエラー終了では、次の送信時に印の作成後の会話記録にある`isApiErrorMessage`を確認し、終了したturnの印だけを解除する。過去のエラーで新しい印を解除しない。waiterは印を変更せず、読取専用のままエラーを返す。
|
|
97
97
|
それ以外は新しいturnとしてdispatchする。
|
|
98
|
+
振り分けから送り終えるまでの間には、起動直後の入力受付待ちなどの待ちが挟まる。同じsessionへの送信(`pty_send`、`claude_turn issue`、起動時prompt)は1本ずつ通し、
|
|
99
|
+
重なった後の1通は前の1通が終わってから振り分け直す。同じprocessの中は着いた順の待ち行列、別のprocessの間はsocketの置き場の`<name>.agent-send.lock`で排他する。
|
|
100
|
+
待つ上限は、起動から最初の描画を待つ上限と貼り付けの上限の和で、越えたら`AGENT_SEND_BUSY`で未送信を返す。判断の記録はADR 0088(`docs/adr/0088-one-agent-send-per-session.md`)。
|
|
98
101
|
CodexとClaude Codeは次のtool境界で同じturnへ取り込む。Cursorは「follow-ups」枠へ入った文を「enter steer」で現在turnへ移し、`turn_ended`は最後に1回書く。
|
|
99
102
|
待ち行列の表示は5秒待ち、子のturnが続いている間だけ30秒まで延ばす(表示が遅い端末がある。turnが終わっていれば、文は新しいturnとして始まっている)。
|
|
100
103
|
Grokは待ち行列へ入れた後に「send now」を押す。旧turnは`cancelled`(`cancellation_context.trigger=send_now`)で閉じ、
|
|
@@ -309,6 +312,8 @@ ADR 0074(repositoryの`docs/adr/0074-agent-model-catalog.md`)。
|
|
|
309
312
|
境界失敗は明示errorにする。retry、別model、別harness、別backendへ自動fallbackしない。
|
|
310
313
|
stale send lockは並行processとのABAを避けるため自動削除せず、公開APIでは対象sessionを`pty_close`して
|
|
311
314
|
同じIDで再作成する。全session一括停止は公開しない。
|
|
315
|
+
agent sessionへの送信1本を守る`<name>.agent-send.lock`は持つ時間が長いので、持ち主が終了した残骸を次の送信が片付ける。消す役を`<name>.agent-send.lock.reap`の排他作成で1つに絞り、
|
|
316
|
+
その中でもう一度確かめてから消すので、確かめた後で別のlockに入れ替わらない。消す役の印そのものが残った時だけは自動で消さず、`pty_close`を案内する。
|
|
312
317
|
|
|
313
318
|
Grokのread-only sandbox起動拒否は、`src/harnesses/grok.ts`の
|
|
314
319
|
`assertGrokSandboxNotRejected`がCLIのエラー表示から検出する。`src/core.ts`の共通入力受付待機は
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.52.
|
|
3
|
+
"version": "0.52.1",
|
|
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, and Cursor Agent CLI, plus durable PTYs for SSH, containers, and REPLs.",
|
|
6
6
|
"keywords": [
|