aiterm-mcp 0.51.2 → 0.51.3

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 CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.51.3] - 2026-10-04
11
+
12
+ ### 修正
13
+
14
+ - 完了待ちが、子の答えを待つ間ずっと、100msごとに`tmux capture-pane`を起動していた(ADR 0085)。利用上限の知らせを、完了の見回りの
15
+ たびに画面から確かめていたため。待ち1本で8秒に76回、4本重なった時はBellTeamのコンテナのCPUが148%だった。画面を読むのは、
16
+ Claude・Grokが2秒に1回、Cursorが1秒に1回(1回の画面で利用上限とhook拒否の両方を見る)にした。直した版は、待ち1本・8秒で
17
+ Claude Codeの子が4回、Cursorの子が8回。完了の見回り(100ms)は変えていない。子が利用上限で止まった時に`rate_limited`を返すのが、
18
+ 最長で2秒(Cursorは1秒)遅れる。
19
+ - 親配送の回収で、pidは居ると出るがOSのprocess表に無い持ち主を、終了として閉じる(ADR 0086)。Windowsでは、終了したprocessの
20
+ pidが、誰かがhandleを握っている間は空かずに残る。0.51.2はこの持ち主を閉じず、この版より前のMCP processが5秒おきに照会し続けていた
21
+ (実物で、3つのMCP processが各々1分に22〜24回)。process表にはあるが開始時刻を読めない持ち主だけ、今までどおり60秒に1回問い合わせる。
22
+ pidが無い持ち主も、この版より前のMCP processが生きていて保存場所を消せない間は、`closed`を書いておく。
23
+ `owner.json`の`closed_reason`に`process_gone`が増える。0.51.2へ戻しても、そのまま動く。
24
+
10
25
  ## [0.51.2] - 2026-10-04
11
26
 
12
27
  ### 修正
@@ -2075,7 +2090,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
2075
2090
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
2076
2091
  provenance.
2077
2092
 
2078
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.2...HEAD
2093
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.3...HEAD
2094
+ [0.51.3]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.2...v0.51.3
2079
2095
  [0.51.2]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.1...v0.51.2
2080
2096
  [0.51.1]: https://github.com/kitepon/aiterm-mcp/compare/v0.51.0...v0.51.1
2081
2097
  [0.51.0]: https://github.com/kitepon/aiterm-mcp/compare/v0.50.0...v0.51.0
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.51.2** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
212
+ **状態:** 開発継続中 · 現行公開版 **v0.51.3** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
213
213
 
214
214
  ### 更新と巻き戻し
215
215
 
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.51.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).
226
+ **Status:** actively maintained · current public release **v0.51.3** · 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
 
@@ -85,6 +85,22 @@ export function shq(s) {
85
85
  }
86
86
  export const LAUNCH_ID_RE = /^[0-9a-f]{32}$/;
87
87
  export const AGENT_DONE_POLL_MS = 100;
88
+ // 完了待ちの中で画面を読む間隔。画面を読むたびにtmux(capture-pane)を1回起動するので、完了の見回りとは別に持つ。
89
+ // 画面でしか分からないのは利用上限の知らせとCursorのhook拒否の表示で、どちらも数秒は画面に残る。
90
+ export const AGENT_RATE_LIMIT_POLL_MS = 2_000;
91
+ // Cursorのhook拒否の表示は数秒で消える。見えている間に1回は読む。
92
+ export const CURSOR_SCREEN_POLL_MS = 1_000;
93
+ /** 最初の呼び出しと、前にtrueを返してから間隔が空いた呼び出しだけtrueを返す。 */
94
+ export function pollGate(intervalMs, now = () => performance.now()) {
95
+ let last = -Infinity;
96
+ return () => {
97
+ const at = now();
98
+ if (at - last < intervalMs)
99
+ return false;
100
+ last = at;
101
+ return true;
102
+ };
103
+ }
88
104
  export const AGENT_EVENT_MAX_BYTES = 1024 * 1024;
89
105
  export const AGENT_EVENT_TAIL_BYTES = 64 * 1024;
90
106
  export const CODEX_TRANSCRIPT_INCREMENT_MAX_BYTES = 16 * 1024 * 1024;
package/dist/core.js CHANGED
@@ -19,7 +19,7 @@ import { unfinishedDeliveriesOwnedBy } from "./parent-delivery-owners.js";
19
19
  import { readRuntimeProcesses, processSubtree, parentProcess, processIdentity, backgroundProcesses, lazyRelayProcess, aitermProcessProbe, windowsConsoleHost } from "./process-runtime.js";
20
20
  import { AitermError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
21
21
  import { isWin, SOCKDIR, tmuxCommand, sendPsmuxPayload, loadPtyBufferChunk, pasteBufferBaseArgs, tmuxNewSession, registeredSessionEnvironment, attachCommand, normalizePaneCommand, atomicShellMultiline, appendMarkSentinel, markShellCommand, settlePaneLog, paneCwdArgument, sessionEnvironmentLaunch, } from "./tmux-runtime.js";
22
- import { sleep, currentUid, runtimeStateBase, safeStatSize, readFileRange, writeJson0600, createEmpty0600, shq, LAUNCH_ID_RE, AGENT_DONE_POLL_MS, AGENT_EVENT_MAX_BYTES, assertSessionName, agentsDir, agentEventPath, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness, subagentInstruction, agentLineageFields, } from "./agent-shared.js";
22
+ import { 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, agentEventPath, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness, subagentInstruction, agentLineageFields, } from "./agent-shared.js";
23
23
  import { catalogUnavailable } from "./model-catalog.js";
24
24
  import { grokAuthPlan, grokAuthStatus, grokAuthPane, realGrokHome, resolveAndValidateGrokAuth, assertGrokModelAvailable, grokModelChoices, grokEventsTranscript, latestGrokCompletion, observeGrokDone, buildGrokAgentCmd, grokLaunchNote, grokEnvTokens, grokTuiReady, grokTuiBusy, grokPaneObservation, grokRateLimitDialog, grokStartupAction, grokLaunchBlockingDialog, assertGrokSandboxNotRejected, GROK_COMPOSER_MARKER_RE, grokFooterHasConfiguration, grokTranscriptText, createGrokAgentMetadata, } from "./harnesses/grok.js";
25
25
  import { codexAuthPlan, codexAuthStatus, codexAuthPane, bindCodexTranscriptSession, latestCodexCompletion, observeCodexDone, buildCodexAgentCmd, codexLaunchNote, codexTuiReady, codexPaneObservation, codexHelperProcess, codexRateLimitModelSwitchDialog, codexApprovalDialog, codexStartupAction, CODEX_COMPOSER_MARKER_RE, codexModelChoice, codexEffortChoice, codexMoreReasoningChoice, codexTranscriptText, createCodexAgentMetadata, codexModelChoices, } from "./harnesses/codex.js";
@@ -2762,7 +2762,7 @@ export async function observeAgentDone(name, o = {}) {
2762
2762
  return observeCodexDone(meta, timeout, o.cursor, o.signal);
2763
2763
  }
2764
2764
  if (meta.kind === "cursor" && meta.completion_route === "cursor_transcript") {
2765
- return observeCursorDone(meta, timeout, o.cursor, detectAgentRateLimit, (session) => captureScreen(session, 0), o.signal);
2765
+ return observeCursorDone(meta, timeout, o.cursor, (session) => captureScreen(session, 0), o.signal);
2766
2766
  }
2767
2767
  if (meta.kind === "grok" && meta.completion_route === "grok_transcript") {
2768
2768
  return observeGrokDone(meta, timeout, o.cursor, detectAgentRateLimit, o.signal);
@@ -2780,6 +2780,9 @@ export async function observeAgentDone(name, o = {}) {
2780
2780
  const transcriptFile = claudeSessionTranscriptPath(meta);
2781
2781
  let transcriptCursor = transcriptFile ? safeStatSize(transcriptFile) : 0;
2782
2782
  let transcriptCarry = "";
2783
+ // 利用上限の知らせは画面でしか分からない。画面を読むとtmuxを起動するので、完了の見回りより間隔を空ける。
2784
+ // 実被弾: 完了の見回り(100ms)のたびに読んでいて、待ち1本が1秒に約10回tmuxを起動していた(4本でコンテナのCPUが148%)。
2785
+ const rateLimitDue = pollGate(AGENT_RATE_LIMIT_POLL_MS);
2783
2786
  const observation = (outcome, ev = null, rateLimit = null, apiError = null) => ({
2784
2787
  schema: "aiterm.agent-wait-result.v1",
2785
2788
  session_id: meta.aiterm_session,
@@ -2840,7 +2843,8 @@ export async function observeAgentDone(name, o = {}) {
2840
2843
  }
2841
2844
  // timeout=0 は「待たずに一度だけ見る」照会=未完了は失敗ではなく running。
2842
2845
  // 1秒以上を指定した待機の未完了は従来どおり timeout で、待ち方の意味は変えない。
2843
- {
2846
+ // 最初の周回では必ず見る(timeout=0の照会も1回は見る)。
2847
+ if (rateLimitDue()) {
2844
2848
  const limited = detectAgentRateLimit(meta.kind, meta.aiterm_session);
2845
2849
  if (limited)
2846
2850
  return observation("rate_limited", null, limited);
@@ -8,7 +8,7 @@ import { randomBytes } from "node:crypto";
8
8
  import { AitermError } from "../errors.js";
9
9
  import { spawnAgentControlCommand } from "../agent-resolver.js";
10
10
  import { checkedCatalog } from "../model-catalog.js";
11
- import { AGENT_DONE_POLL_MS, AGENT_EVENT_MAX_BYTES, agentEventPath, agentHarness, agentLineageFields, agentMetadataPath, createEmpty0600, readFileRange, safeStatSize, shq, sleep, subagentInstruction, writeAgentMetadata, writeScopeLaunchNote, } from "../agent-shared.js";
11
+ import { AGENT_DONE_POLL_MS, CURSOR_SCREEN_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, agentEventPath, agentHarness, agentLineageFields, agentMetadataPath, createEmpty0600, readFileRange, safeStatSize, shq, sleep, subagentInstruction, writeAgentMetadata, writeScopeLaunchNote, } from "../agent-shared.js";
12
12
  const CURSOR_TRANSCRIPT_MATCH_MAX_BYTES = 1024 * 1024;
13
13
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
14
14
  // Cursor Agentはextended keyboard protocolを有効にするため、通常のtmux Enterではなく
@@ -185,12 +185,14 @@ export function latestCursorCompletion(meta, readTranscriptLines) {
185
185
  ? cursorCompletionEvent(meta, harnessSessionId, state.terminalRecord, `cursor:${state.userTurns}`)
186
186
  : null;
187
187
  }
188
- export async function observeCursorDone(meta, timeout, requestedCursor, detectRateLimit, readScreen, signal) {
188
+ export async function observeCursorDone(meta, timeout, requestedCursor, readScreen, signal) {
189
189
  const metadataFile = agentMetadataPath(meta.aiterm_session, meta.launch_id);
190
190
  let transcript = cursorTranscript(meta);
191
191
  const startBoundary = requestedCursor ?? (transcript ? cursorTranscriptState(transcript).userTurns : 0);
192
192
  let malformedEvents = 0;
193
193
  const deadline = performance.now() + timeout * 1000;
194
+ // 画面を読むたびにtmuxを1回起動する。完了の見回りより間隔を空け、1回読んだ画面で利用上限とhook拒否の両方を見る。
195
+ const screenDue = pollGate(CURSOR_SCREEN_POLL_MS);
194
196
  const observation = (outcome, ev = null, rateLimit = null, error = null) => ({
195
197
  schema: "aiterm.agent-wait-result.v1",
196
198
  session_id: meta.aiterm_session,
@@ -221,13 +223,17 @@ export async function observeCursorDone(meta, timeout, requestedCursor, detectRa
221
223
  return observation("done", done);
222
224
  }
223
225
  }
224
- const limited = detectRateLimit(meta.kind, meta.aiterm_session);
225
- if (limited)
226
- return observation("rate_limited", null, limited);
227
- // 拒否されたpromptのturnは始まらず、完了も来ない。拒否の表示は数秒で消えるので、見えている間に終わらせる。
228
- const hookBlocked = cursorHookBlocked(readScreen(meta.aiterm_session));
229
- if (hookBlocked)
230
- return observation("error", null, null, `USER_HOOK_BLOCKED: ${hookBlocked.message}`);
226
+ // 最初の周回では必ず読む(timeout=0の照会も1回は読む)。
227
+ if (screenDue()) {
228
+ const screen = readScreen(meta.aiterm_session);
229
+ const limited = cursorUsageLimit(screen)?.message ?? null;
230
+ if (limited)
231
+ return observation("rate_limited", null, limited);
232
+ // 拒否されたpromptのturnは始まらず、完了も来ない。拒否の表示は数秒で消えるので、見えている間に終わらせる。
233
+ const hookBlocked = cursorHookBlocked(screen);
234
+ if (hookBlocked)
235
+ return observation("error", null, null, `USER_HOOK_BLOCKED: ${hookBlocked.message}`);
236
+ }
231
237
  if (performance.now() >= deadline)
232
238
  return observation(timeout === 0 ? "running" : "timeout");
233
239
  await sleep(AGENT_DONE_POLL_MS);
@@ -10,7 +10,7 @@ import { randomBytes, randomUUID } from "node:crypto";
10
10
  import { AitermError } from "../errors.js";
11
11
  import { runAgentProtocolCommand, spawnAgentControlCommand } from "../agent-resolver.js";
12
12
  import { catalogInvalid, catalogUnavailable, checkedCatalog, findJsonLine, processSummary } from "../model-catalog.js";
13
- import { shq, subagentInstruction, writeScopeLaunchNote, safeStatSize, readFileRange, sleep, agentMetadataPath, writeAgentMetadata, agentEventPath, createEmpty0600, agentLineageFields, AGENT_DONE_POLL_MS, AGENT_EVENT_MAX_BYTES, GROK_TRANSCRIPT_INCREMENT_MAX_BYTES, agentHarness, } from "../agent-shared.js";
13
+ import { shq, subagentInstruction, writeScopeLaunchNote, safeStatSize, readFileRange, sleep, agentMetadataPath, writeAgentMetadata, agentEventPath, createEmpty0600, agentLineageFields, AGENT_DONE_POLL_MS, AGENT_RATE_LIMIT_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, GROK_TRANSCRIPT_INCREMENT_MAX_BYTES, agentHarness, } from "../agent-shared.js";
14
14
  const GROK_MODELS_MAX_BYTES = 1024 * 1024;
15
15
  const GROK_MODELS_TIMEOUT_MS = 15_000;
16
16
  // grok CLI はモデル未指定だと端末側 default に従うため、ツール契約として既定 slug を固定する。
@@ -229,6 +229,7 @@ export async function observeGrokDone(meta, timeout, requestedCursor, detectRate
229
229
  let discardLeadingFragment = false;
230
230
  let initializedBoundary = false;
231
231
  const deadline = performance.now() + timeout * 1000;
232
+ const rateLimitDue = pollGate(AGENT_RATE_LIMIT_POLL_MS);
232
233
  const observation = (outcome, ev = null, rateLimit = null) => ({
233
234
  schema: "aiterm.agent-wait-result.v1",
234
235
  session_id: meta.aiterm_session,
@@ -293,7 +294,8 @@ export async function observeGrokDone(meta, timeout, requestedCursor, detectRate
293
294
  }
294
295
  }
295
296
  }
296
- {
297
+ // 質問カードの確認は画面を読む(tmuxを起動する)。完了の見回りより間隔を空け、最初の周回では必ず見る。
298
+ if (rateLimitDue()) {
297
299
  const limited = detectRateLimit(meta.kind, meta.aiterm_session);
298
300
  if (limited)
299
301
  return observation("rate_limited", null, limited);
@@ -149,7 +149,7 @@ export class ParentDeliveryManager {
149
149
  this.results = path.join(this.root, "results");
150
150
  this.claims = path.join(options.root ?? path.join(stateRoot, prefix + "parent-deliveries"), "claims");
151
151
  const ownProcess = this.deps.processes([process.pid]).find((entry) => entry.pid === process.pid);
152
- if (!ownProcess)
152
+ if (!ownProcess || ownProcess.started_identity === null)
153
153
  throw new AitermError("PARENT_DELIVERY_OWNER_UNKNOWN: 配送processを識別できません", 2);
154
154
  this.owner = { pid: process.pid, started_identity: ownProcess.started_identity, closed: false, removal_safe: true };
155
155
  this.ownerDir = path.join(this.active, `${deliveryOwnerPrefix(this.owner)}${randomUUID()}`);
@@ -447,11 +447,15 @@ export class ParentDeliveryManager {
447
447
  const processes = this.deps.processes([...new Set(unverified.map((entry) => entry.pid))]);
448
448
  for (const entry of unverified) {
449
449
  const row = processes.find((candidate) => candidate.pid === entry.pid);
450
- const state = !row ? "unverified" : row.started_identity === entry.started_identity ? "alive" : "reused";
450
+ // pidは居ると出たのにprocess表に無いのは、照会の直前に終了したか、終了したprocessの名残
451
+ // (Windowsでは、誰かがhandleを握っている間、終了したprocessのpidが空かず、権限の低いprocessからは「居るが開けない」と見える)。
452
+ const state = !row ? "vanished" : row.started_identity === null ? "unverified"
453
+ : row.started_identity === entry.started_identity ? "alive" : "reused";
451
454
  fate.set(entry.name, state);
452
- // 別のprocessと分かった持ち主は下で閉じるので、照合の結果を覚えない。
453
- if (state !== "reused")
455
+ // 終了と分かった持ち主は下で閉じるので、照合の結果を覚えない。
456
+ if (state === "alive" || state === "unverified") {
454
457
  this.verifiedOwners.set(entry.name, { pid: entry.pid, started_identity: entry.started_identity, at: now, alive: state === "alive" });
458
+ }
455
459
  }
456
460
  }
457
461
  for (const name of this.verifiedOwners.keys()) {
@@ -461,6 +465,8 @@ export class ParentDeliveryManager {
461
465
  }
462
466
  // 記録を引き取り終えた、終了した持ち主の保存場所。残すと、回収のたびに全部を読み直す。
463
467
  const finished = [];
468
+ // pidが無いと分かった、closeしていない持ち主。保存場所を消せない回は、閉じた事だけを書く。
469
+ const goneOwners = [];
464
470
  // owner.jsonの無い、古い保存場所。
465
471
  const abandoned = [];
466
472
  // 旧版は、読んでいる最中に他の持ち主の保存場所が消えると回収が止まる。印の無い持ち主が生きている間は消さない。
@@ -541,23 +547,35 @@ export class ParentDeliveryManager {
541
547
  else
542
548
  this.finish(job);
543
549
  }
544
- if (!owner.closed && state === "reused") {
550
+ if (!owner.closed && (state === "reused" || state === "vanished")) {
545
551
  // 同じpidと開始時刻の組は二度と現れない。閉じた事にして、どの版の回収にも照合を繰り返させない。
546
552
  // 書けなかった時は次の回でもう一度照合する。配送には影響しない。
553
+ const reason = state === "reused" ? "pid_reused" : "process_gone";
547
554
  try {
548
- writeJson0600(ownerFile, { ...owner, closed: true, closed_reason: "pid_reused" });
555
+ writeJson0600(ownerFile, { ...owner, closed: true, closed_reason: reason });
549
556
  }
550
557
  catch { /* 次の回 */ }
551
558
  continue;
552
559
  }
553
560
  // 持ち主が自分で閉じた保存場所と、pidがもう無い持ち主の保存場所だけを消す。
554
- // 開始時刻の違いで閉じた保存場所は、そのpidが空くまで残す。
561
+ // 回収側が閉じた保存場所は、そのpidが空くまで残す。
555
562
  const ended = owner.closed ? owner.closed_reason === undefined || !this.deps.exists(owner.pid) : state === "gone";
556
563
  if (ended)
557
564
  finished.push(oldDir);
565
+ if (!owner.closed && state === "gone")
566
+ goneOwners.push({ file: ownerFile, owner });
558
567
  }
559
- if (removalBlocked)
568
+ if (removalBlocked) {
569
+ // 消せない間も、終了した持ち主は閉じておく。pidの有無は見る側の権限で変わる事があり(ADR 0086)、
570
+ // 閉じていない持ち主は、前の版の回収が照会の相手にし続ける。
571
+ for (const { file, owner } of goneOwners) {
572
+ try {
573
+ writeJson0600(file, { ...owner, closed: true, closed_reason: "process_gone" });
574
+ }
575
+ catch { /* 次の回 */ }
576
+ }
560
577
  return;
578
+ }
561
579
  // 片付けの失敗は配送に影響しない。残った保存場所は次の回でもう一度消す。
562
580
  for (const directory of finished) {
563
581
  try {
@@ -100,6 +100,7 @@ export function readRuntimeProcesses() {
100
100
  }
101
101
  /**
102
102
  * 指定したpidの開始時刻だけを引く。readRuntimeProcessesと同じ開始時刻を返し、存在しないpidは結果に含めない。
103
+ * process表にpidはあるが開始時刻を読めない時は、started_identityをnullで返す(pidが無いのとは区別する)。
103
104
  * 全processのargvを読む一覧取得は、processの多い端末で重い(定期実行から呼ばない)。
104
105
  */
105
106
  export function readProcessIdentities(pids) {
@@ -124,10 +125,11 @@ export function readProcessIdentities(pids) {
124
125
  });
125
126
  }
126
127
  // CommandLineの読めないprocess(別の権限のserviceなど)も返す。pidが使い回された先を「別のprocess」と確かめるのに要る。
128
+ // 開始時刻を読めない行も、pidがprocess表にある印として返す。
127
129
  const script = [
128
130
  ...WINDOWS_PROBE_HEADER,
129
- `$rows=@(Get-CimInstance Win32_Process -Filter "${wanted.map(pid => `ProcessId=${pid}`).join(" OR ")}" | Where-Object { $null -ne $_.CreationDate } | ForEach-Object {`,
130
- "[ordered]@{ pid=[int]$_.ProcessId; started_identity=$_.CreationDate.ToUniversalTime().ToString('o') }",
131
+ `$rows=@(Get-CimInstance Win32_Process -Filter "${wanted.map(pid => `ProcessId=${pid}`).join(" OR ")}" | ForEach-Object {`,
132
+ "[ordered]@{ pid=[int]$_.ProcessId; started_identity=$(if ($null -ne $_.CreationDate) { $_.CreationDate.ToUniversalTime().ToString('o') } else { $null }) }",
131
133
  "})",
132
134
  "ConvertTo-Json -Compress -InputObject $rows",
133
135
  ].join("\n");
@@ -146,8 +148,11 @@ export function readProcessIdentities(pids) {
146
148
  if (!Array.isArray(rows))
147
149
  throw new AitermError("Windows process一覧が配列ではありません", 2);
148
150
  return rows.map(row => {
149
- if (!row || !Number.isSafeInteger(row.pid) || typeof row.started_identity !== "string"
150
- || !Number.isFinite(Date.parse(row.started_identity)))
151
+ if (!row || !Number.isSafeInteger(row.pid))
152
+ throw new AitermError("Windows process一覧のfieldが不正です", 2);
153
+ if (row.started_identity === null)
154
+ return { pid: row.pid, started_identity: null };
155
+ if (typeof row.started_identity !== "string" || !Number.isFinite(Date.parse(row.started_identity)))
151
156
  throw new AitermError("Windows process一覧のfieldが不正です", 2);
152
157
  return { pid: row.pid, started_identity: new Date(row.started_identity).toISOString() };
153
158
  });
package/docs/DESIGN.md CHANGED
@@ -152,7 +152,8 @@ Codexの配送記録と本文はAiterm stateの`parent-deliveries`へ保存す
152
152
  受信口が明示拒否した場合は`failed`、子の異常終了はそのoutcomeを配送する。
153
153
  生存の確認は5秒おきにpidの存在だけをOSへ聞き、開始識別子の照合は初めて見たownerと60秒に1回だけ行う。
154
154
  全processの一覧は取らない。終了直後に同じpidが再利用された時だけ、引き継ぎが最長60秒遅れる(ADR 0078)。
155
- pidが別のprocessへ使い回されたownerは、回収側が`owner.json`を`closed`へ書き換え、照合を繰り返さない。照合できないownerは60秒に1回だけ問い合わせる。
155
+ pidが別のprocessへ使い回されたownerと、pidは居ると出るがprocess表に無いownerは、回収側が`owner.json`を`closed`へ書き換え、照合を繰り返さない。
156
+ process表にはあるが開始時刻を読めないownerだけ、60秒に1回問い合わせる(ADR 0086)。
156
157
  記録を引き継ぎ終えた保存場所は、自分で閉じたownerとpidの無いownerのものを消す。保存場所が消えても読める印(`removal_safe`)の無いownerが
157
158
  同じ置き場で生きている間は消さない(ADR 0084)。
158
159
  このstateは既存のPTY/harness stateと独立し、旧版は配送を再開しない。
@@ -324,6 +325,8 @@ Grokの終了済みerrorターンにweekly-limit質問カードが残る場合
324
325
  `grokRateLimitDialog`が見出しと操作footerの組を所有し、過去logや後続UIのあるカードは採用しない。
325
326
  privacy案内は現在の枠付きcomposerとmodel footerが見える場合だけ入力受付を妨げない。
326
327
  完了観測は成功eventを優先し、今回のerror eventと現在のカードが揃えばturn情報付きの`rate_limited`を返す。
328
+ 完了の見回りは100msで、画面を読む確認(利用上限の知らせ、Cursorのhook拒否の表示)は別の間隔で行う。画面を読むたびにtmuxを1回起動するため。
329
+ Claude・Grokは2秒、Cursorは1秒に1回で、待ちに入った最初の周回では必ず読む(ADR 0085)。
327
330
  新turnの完了前に古いlogだけで上限を返さない。購入・再認証・過去prompt再送・定期再試行は行わない。
328
331
  画面判定と模擬CLIの実PTY試験は`test/grok-rate-limit.test.mjs`に置く。
329
332
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.51.2",
3
+ "version": "0.51.3",
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": [