aiterm-mcp 0.70.67 → 0.70.69

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,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.70.69] - 2026-11-15
11
+
12
+ - The EnterPlanMode spec hook (0.70.67) no longer relies on the call's own transcript rows (Kiro's Z41 lab: a seat that wrote a 300-character spec in the same message was turned back at its first call, 3 of 3 runs). In the interactive Claude Code 2.1.325 the rows of the message that holds the call are often not in the transcript while the hook runs, however long the hook waits (measured up to 2.6 s; they appear after the hook returns), so the hook now counts the assistant text since the last real user prompt up to the call: an earlier message of the same prompt with 80+ characters lets the first call through. When the call's own message is not readable and nothing earlier was written, the first call of a prompt is turned back once (the instruction now says that a seat that has just written its spec only needs to call EnterPlanMode again), the second call always enters. The wait for the call's row is 600 ms instead of 1500 ms (harness-contracts.md "EnterPlanModeの前に仕様を書かせる").
13
+
14
+ ## [0.70.68] - 2026-11-15
15
+
16
+ - `agent_configure` now changes the model or the effort (low to max) of a Claude seat whose turn is running, without ending the turn (b8, Kiro's request, Owner's order). Typing `/model` into a busy Claude seat only queues it as a user message (2.1.325), so the picker is opened with Alt+P (tmux/psmux key `M-p`, ESC and p in one write; a lone ESC would stop the turn) and the usual row match, `s` (this session only, never Enter), "Yes, switch" and refusal logic (`configureRefusal`, `aiterm/configure_error`) follow. The same turn's next request runs on the new model. Differences from an idle seat: no Esc is sent except to close the picker or the switch question while one is on screen, the result line is read without the `❯ /model` line above it, and no composer is waited for. Idle seats still use `/model`. `fast`, `opusplan`, `ultracode`, an effort outside low-max and a running Claude goal keep the refusal "入力待ちではありません" (nothing typed). A seat already in a running turn needs no relaunch; the change is on the seat's own session only (model-configuration.md).
17
+
10
18
  ## [0.70.67] - 2026-11-15
11
19
 
12
20
  - A Claude seat can no longer enter plan mode without having written what it will plan (b4, Kiro's request, Owner's order). EnterPlanMode takes no arguments, so a seat that called it blind fell into plan mode's ask-the-user flow and an unattended seat stalled there. Every Claude seat's own settings now carry a `PreToolUse` hook for `EnterPlanMode` only. It waits up to 1.5 s (polling every 50 ms) for the call to appear in the seat's transcript, then counts the assistant text written right before it in the same message. 80 characters or more: the call goes through. Less: the call is turned back once per prompt with an instruction to write the detailed spec in the AI's own words and call again; the second call of the same prompt is never turned back (a small `.claude-plan-spec` state file in the seat's agents folder records the turn-back and is cleaned with the seat). An unreadable transcript, a missing `prompt_id`, an unwritable state file, an unreadable input and a process outside an Aiterm seat all let the call through. A seat already running keeps its old settings until it is resumed or relaunched; an Aiterm below 0.70.67 behaves as before (harness-contracts.md "EnterPlanModeの前に仕様を書かせる").
@@ -3518,7 +3526,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
3518
3526
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
3519
3527
  provenance.
3520
3528
 
3521
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.67...HEAD
3529
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.69...HEAD
3530
+ [0.70.69]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.68...v0.70.69
3531
+ [0.70.68]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.67...v0.70.68
3522
3532
  [0.70.67]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.66...v0.70.67
3523
3533
  [0.70.66]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.65...v0.70.66
3524
3534
  [0.70.65]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.64...v0.70.65
package/README.ja.md CHANGED
@@ -215,7 +215,7 @@ runtime-error store は canonical dotagents config の `collection.enabled: true
215
215
  場合だけ収集し、既定OFF、network送信は行いません。tag起点CIのnpm provenance(OIDC Trusted
216
216
  Publishing)で公開し、GitHub Release が Official MCP Registry を再登録します。
217
217
 
218
- **状態:** 開発継続中 · 現行公開版 **v0.70.67** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
218
+ **状態:** 開発継続中 · 現行公開版 **v0.70.69** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
219
219
 
220
220
  ### 更新と巻き戻し
221
221
 
package/README.md CHANGED
@@ -227,7 +227,7 @@ collection is off by default and performs no network I/O. It ships via
227
227
  tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
228
228
  Release re-registers the Official MCP Registry entry.
229
229
 
230
- **Status:** actively maintained · current public release **v0.70.67** · 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).
230
+ **Status:** actively maintained · current public release **v0.70.69** · 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
 
@@ -9,12 +9,13 @@ import { currentUid, runtimeStateBase } from "./state-root.js";
9
9
  const MAX_STDIN_BYTES = 8 * 1024 * 1024;
10
10
  const TAIL_BYTES = 512 * 1024;
11
11
  const POLL_MS = 50;
12
- const WAIT_MS = 1500;
12
+ const WAIT_MS = 600; // rows that are readable at all show up within ~110 ms (measured); waiting longer never helped
13
13
  // shortcut: a length floor, because the spec is the AI's own words and a tool cannot judge it; raise it if seats pass one-line stubs.
14
14
  const SPEC_MIN_CHARS = 80;
15
15
  const AITERM_ENV = ["AITERM_AGENT_KIND", "AITERM_SESSION_ID", "AITERM_AGENT_SESSION_ID", "AITERM_AGENT_LAUNCH_ID"];
16
16
  const GUIDANCE = "プランモードに入る前に、プランを練りたい内容の詳細な仕様を、あなた自身の言葉で書いてください。"
17
- + "何を作る・直す・調べるのか、範囲、守る条件、終わりの形を書いたうえで、もう一度 EnterPlanMode を呼んでください。";
17
+ + "何を作る・直す・調べるのか、範囲、守る条件、終わりの形を書いたうえで、もう一度 EnterPlanMode を呼んでください。"
18
+ + "(この呼びの直前に書き終えている場合は、書き直さずにもう一度 EnterPlanMode を呼ぶだけで入れます。)";
18
19
  async function readStdin() {
19
20
  const chunks = [];
20
21
  let total = 0;
@@ -51,10 +52,13 @@ function blocksOf(row) {
51
52
  return Array.isArray(row.message?.content) ? row.message.content : [];
52
53
  }
53
54
  /**
54
- * Characters of assistant text written right before the tool_use `toolUseId` in the same assistant message
55
- * (Claude Code writes one transcript line per content block, all with the same message.id); null while the tool_use is not there yet.
55
+ * What the transcript says about the spec of this EnterPlanMode call: the characters of assistant text written since the last
56
+ * real user prompt up to the call (earlier messages of the same prompt count; text in the call's own message counts up to the
57
+ * tool_use), and whether the call's tool_use row is in the file yet. In the interactive CLI (2.1.325) the rows of the message
58
+ * that holds the call are often not in the file while the hook runs, however long it waits (measured 2026-11-15, up to 2.6 s),
59
+ * so `visible: false` means "not readable", not "nothing written".
56
60
  */
57
- export function specChars(transcript, toolUseId) {
61
+ export function specEvidence(transcript, toolUseId) {
58
62
  const rows = [];
59
63
  for (const line of transcript.split("\n")) {
60
64
  try {
@@ -62,23 +66,25 @@ export function specChars(transcript, toolUseId) {
62
66
  }
63
67
  catch { /* a half-written or foreign line */ }
64
68
  }
65
- const at = rows.findIndex(row => blocksOf(row).some(block => block?.type === "tool_use" && block.id === toolUseId));
66
- if (at < 0)
67
- return null;
68
- const own = blocksOf(rows[at]);
69
- const blocks = own.slice(0, own.findIndex(block => block?.type === "tool_use" && block.id === toolUseId));
70
- const messageId = rows[at].message?.id;
71
- if (typeof messageId === "string") {
72
- for (let j = at - 1; j >= 0; j -= 1) {
73
- if (!rows[j].message)
74
- continue; // bookkeeping rows (ai-title, attachment...) can sit between the blocks of one message
75
- if (rows[j].message.id !== messageId)
76
- break;
77
- blocks.push(...blocksOf(rows[j]));
69
+ const isCall = (block) => block?.type === "tool_use" && block.id === toolUseId;
70
+ const at = rows.findIndex(row => blocksOf(row).some(isCall));
71
+ const end = at < 0 ? rows.length : at + 1;
72
+ // A real prompt is a user row that holds text (a tool_result-only user row is the answer to a tool call).
73
+ let prompt = end - 1;
74
+ while (prompt >= 0 && !(rows[prompt].type === "user"
75
+ && (typeof rows[prompt].message?.content === "string" || blocksOf(rows[prompt]).some(block => block?.type === "text"))))
76
+ prompt -= 1;
77
+ let chars = 0;
78
+ for (let i = prompt + 1; i < end; i += 1) {
79
+ if (rows[i].type !== "assistant")
80
+ continue;
81
+ const blocks = blocksOf(rows[i]);
82
+ for (const block of i === at ? blocks.slice(0, blocks.findIndex(isCall)) : blocks) {
83
+ if (block?.type === "text" && typeof block.text === "string")
84
+ chars += block.text.trim().length;
78
85
  }
79
86
  }
80
- const texts = blocks.filter(block => block?.type === "text" && typeof block.text === "string");
81
- return texts.reduce((sum, block) => sum + block.text.trim().length, 0);
87
+ return { visible: at >= 0, chars };
82
88
  }
83
89
  function stateFile(env) {
84
90
  const seat = env.AITERM_SESSION_ID;
@@ -103,17 +109,17 @@ export async function planSpecDecision(payload, env = process.env, timing = { wa
103
109
  return null;
104
110
  }
105
111
  catch { /* nothing recorded yet */ }
106
- let chars = null;
112
+ let evidence = { visible: false, chars: 0 };
107
113
  for (let waited = 0;; waited += timing.pollMs) {
108
114
  const tail = readTail(input.transcript_path);
109
115
  if (tail === null)
110
116
  return null;
111
- chars = specChars(tail, input.tool_use_id);
112
- if (chars !== null || waited >= timing.waitMs)
117
+ evidence = specEvidence(tail, input.tool_use_id);
118
+ if (evidence.chars >= SPEC_MIN_CHARS || evidence.visible || waited >= timing.waitMs)
113
119
  break;
114
120
  await sleep(timing.pollMs);
115
121
  }
116
- if (chars !== null && chars >= SPEC_MIN_CHARS)
122
+ if (evidence.chars >= SPEC_MIN_CHARS)
117
123
  return null;
118
124
  // Record the turn-back first: if it cannot be recorded the second call could not be let through, so allow instead.
119
125
  try {
package/dist/core.js CHANGED
@@ -6723,6 +6723,16 @@ function claudeSeatCatalogEnv(name, meta) {
6723
6723
  env[key] = value;
6724
6724
  return env;
6725
6725
  }
6726
+ /** Whether a Claude goal is running on the seat (inside the send lock). Unreadable counts as no goal: the picker path is harmless either way. */
6727
+ async function claudeGoalActive(name, meta) {
6728
+ try {
6729
+ const result = await agentGoalInContext({ session_id: name, launch_id: meta.launch_id, action: "inspect" }, "automatic", undefined, true);
6730
+ return result.availability === "available" && result.goal?.status === "active";
6731
+ }
6732
+ catch {
6733
+ return false;
6734
+ }
6735
+ }
6726
6736
  /** 返りの null は、席の画面が番の最中を示していて、何も打っていない時。 */
6727
6737
  async function configureAgentInLock(name, model, effort, fast, beforeChange) {
6728
6738
  // 席の控えは、行列の順番が来てから読む(前の送信が書いた分を、古い控えで上書きしない)。
@@ -6731,10 +6741,17 @@ async function configureAgentInLock(name, model, effort, fast, beforeChange) {
6731
6741
  let seatEnv;
6732
6742
  const claudeSeatEnv = () => seatEnv === undefined ? (seatEnv = claudeSeatCatalogEnv(name, meta)) : seatEnv;
6733
6743
  // Codexは回答を流している間、動作中の行を出さない(ADR 0101)。送信と同じく記録の番の開始を見て、動いている席へ命令を打たない。
6744
+ // A running Claude turn is changed in place only for model/effort(low-max), with no goal running (model-configuration.md, b8).
6745
+ let inTurn = false;
6734
6746
  if (isAgentTuiBusy(meta.kind, captureScreen(name, AGENT_TUI_READY_LINES))
6735
- || (meta.kind === "codex" && codexRunningTurn(meta) !== null && observeSession(name).harness_alive === true))
6736
- return null;
6737
- const { ready, codexRateLimitModelSwitch } = await waitAgentTuiReadyAfterCodexRateLimitRecovery(name, meta, AGENT_TUI_READY_TIMEOUT_MS);
6747
+ || (meta.kind === "codex" && codexRunningTurn(meta) !== null && observeSession(name).harness_alive === true)) {
6748
+ inTurn = meta.kind === "claude" && fast === null && (model !== null || effort !== null) && model?.toLowerCase() !== "opusplan"
6749
+ && (effort === null || CLAUDE_EFFORTS.has(effort)) && !(await claudeGoalActive(name, meta));
6750
+ if (!inTurn)
6751
+ return null;
6752
+ }
6753
+ const { ready, codexRateLimitModelSwitch } = inTurn ? { ready: { ready: true, lastScreen: "" }, codexRateLimitModelSwitch: false }
6754
+ : await waitAgentTuiReadyAfterCodexRateLimitRecovery(name, meta, AGENT_TUI_READY_TIMEOUT_MS);
6738
6755
  if (!ready.ready) {
6739
6756
  if (codexRateLimitModelSwitch) {
6740
6757
  throw new AitermError(`CODEX_RATE_LIMIT_MODEL_SWITCH_RECOVERY_FAILED: ${codexPaneObservation(ready.lastScreen).reason}。設定変更は送信していません。`, 2);
@@ -6835,7 +6852,7 @@ async function configureAgentInLock(name, model, effort, fast, beforeChange) {
6835
6852
  if (model?.toLowerCase() === "opusplan")
6836
6853
  await switchClaudeOpusPlan(name, meta, beforeChange);
6837
6854
  if (model || level)
6838
- await configureClaudeForSessionOnly(name, meta, model, level, beforeChange, { ...agentModelUi(name), ready: () => waitAgentTuiReady(name, meta, AGENT_TUI_READY_TIMEOUT_MS) }, claudeSeatEnv() ?? process.env);
6855
+ await configureClaudeForSessionOnly(name, meta, model, level, beforeChange, { ...agentModelUi(name), ready: () => waitAgentTuiReady(name, meta, AGENT_TUI_READY_TIMEOUT_MS) }, claudeSeatEnv() ?? process.env, inTurn);
6839
6856
  if (effort && !level) {
6840
6857
  beforeChange();
6841
6858
  await sendAgentPromptText(name, `/effort ${effort}`);
@@ -1,12 +1,15 @@
1
1
  import { AitermError } from "../errors.js";
2
2
  import { sleep } from "../agent-shared.js";
3
3
  import { resolveAgentBin } from "../agent-resolver.js";
4
- import { claudeModelPicker, claudeModelPickerRow, claudePickerRowByName, claudeModelDisplayName, claudeModelSwitchConfirm, claudeModelSwitchResult, claudePaneObservation, claudeModelChoices } from "./claude.js";
4
+ import { claudeModelPicker, claudeModelPickerRow, claudePickerRowByName, claudeModelDisplayName, claudeModelSwitchConfirm, claudeModelSwitchResult, claudeModelSwitchResults, claudePaneObservation, claudeModelChoices } from "./claude.js";
5
5
  const CLAUDE_MODEL_PICKER_TIMEOUT_MS = 8_000;
6
6
  const CLAUDE_MODEL_PICKER_KEY_TIMEOUT_MS = 1_500;
7
7
  const CLAUDE_MODEL_SWITCH_TIMEOUT_MS = 15_000;
8
8
  const CLAUDE_EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
9
- export async function configureClaudeForSessionOnly(name, meta, model, effort, beforeChange, ui, catalogEnv = process.env) {
9
+ export async function configureClaudeForSessionOnly(name, meta, model, effort, beforeChange, ui, catalogEnv = process.env, // the seat's own root and login (model-configuration.md)
10
+ // The seat's turn is running: `/model` would only queue as a user message, so the picker opens with Alt+P, and no Esc or
11
+ // ready wait is used outside the picker (an Esc in a running turn stops it; the turn goes on after the switch).
12
+ inTurn = false) {
10
13
  let selectionIssued = false;
11
14
  const screen = () => ui.screen();
12
15
  const until = async (read, timeoutMs) => {
@@ -47,12 +50,16 @@ export async function configureClaudeForSessionOnly(name, meta, model, effort, b
47
50
  }
48
51
  return null;
49
52
  };
50
- await ui.command("/model");
53
+ const resultsBefore = inTurn ? claudeModelSwitchResults(screen()) : [];
54
+ if (inTurn)
55
+ ui.key("M-p");
56
+ else
57
+ await ui.command("/model");
51
58
  let now = await until(picker, CLAUDE_MODEL_PICKER_TIMEOUT_MS);
52
59
  if (!now) {
53
60
  // 読めない形の画面が開いたままだと、席が次の文を受け取れない。入力待ちでも動作中でもない時だけ、Escを1度打って閉じる。
54
61
  let state = claudePaneObservation(screen());
55
- if (state.state === "unknown") {
62
+ if (!inTurn && state.state === "unknown") {
56
63
  ui.key("Escape");
57
64
  await sleep(500);
58
65
  state = claudePaneObservation(screen());
@@ -174,7 +181,12 @@ export async function configureClaudeForSessionOnly(name, meta, model, effort, b
174
181
  }
175
182
  if (confirm || claudeModelPicker(text))
176
183
  return null;
177
- return claudeModelSwitchResult(text);
184
+ if (!inTurn)
185
+ return claudeModelSwitchResult(text);
186
+ // In a running turn the result has no `❯ /model` line above it: take the newest result line that was not on screen before.
187
+ const seen = (rows, line) => rows.filter(row => row.line === line).length;
188
+ const rows = claudeModelSwitchResults(text);
189
+ return rows.filter(row => seen(rows, row.line) > seen(resultsBefore, row.line)).at(-1) ?? null;
178
190
  }, CLAUDE_MODEL_SWITCH_TIMEOUT_MS);
179
191
  if (!result)
180
192
  return refuse("CLAUDE_MODEL_SWITCH_UNCONFIRMED", "Claude Codeの切り替えの知らせを確認できません");
@@ -186,6 +198,8 @@ export async function configureClaudeForSessionOnly(name, meta, model, effort, b
186
198
  throw new AitermError(`CLAUDE_MODEL_SWITCH_REFUSED vendor=claude session=${name}\n` +
187
199
  `Claude Codeがmodelを切り替えませんでした(${result.line})。modelとreasoning_effortは変えていません。`, 2);
188
200
  }
201
+ if (inTurn)
202
+ return; // the turn keeps running on the new model; there is no composer to wait for
189
203
  const ready = await ui.ready();
190
204
  if (!ready.ready)
191
205
  throw new AitermError("Claudeのmodel変更完了を確認できません", 2);
@@ -635,14 +635,7 @@ export function claudeModelSwitchConfirm(screen) {
635
635
  return null;
636
636
  return body.some((line) => /^\s*❯\s*1\.\s*Yes, switch\b/u.test(line)) ? "yes_selected" : "other_selected";
637
637
  }
638
- export function claudeModelSwitchResult(screen) {
639
- const lines = screen.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").split(/\r?\n/u);
640
- const command = lastLineIndex(lines, /^\s*❯\s*\/model(?:\s+\S+)?\s*$/u);
641
- if (command < 0)
642
- return null;
643
- const start = lines.findIndex((line, i) => i > command && /^\s*⎿\s+\S/u.test(line));
644
- if (start < 0)
645
- return null;
638
+ function switchResultAt(lines, start) {
646
639
  const parts = [lines[start].replace(/^\s*⎿\s+/u, "").trim()];
647
640
  for (const line of lines.slice(start + 1)) {
648
641
  if (!/^\s{3,}\S/u.test(line) || /^\s*⎿/u.test(line))
@@ -660,6 +653,22 @@ export function claudeModelSwitchResult(screen) {
660
653
  return { scope: "saved_as_default", line };
661
654
  return /\bfor this session only\b/u.test(line) ? { scope: "session_only", line } : null;
662
655
  }
656
+ export function claudeModelSwitchResult(screen) {
657
+ const lines = screen.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").split(/\r?\n/u);
658
+ const command = lastLineIndex(lines, /^\s*❯\s*\/model(?:\s+\S+)?\s*$/u);
659
+ if (command < 0)
660
+ return null;
661
+ const start = lines.findIndex((line, i) => i > command && /^\s*⎿\s+\S/u.test(line));
662
+ return start < 0 ? null : switchResultAt(lines, start);
663
+ }
664
+ /**
665
+ * Every switch result line on the screen, oldest first. A switch made with Alt+P in a running turn prints its result with no
666
+ * `❯ /model` line above it (2.1.325), so the caller compares against the lines present before the picker was opened.
667
+ */
668
+ export function claudeModelSwitchResults(screen) {
669
+ const lines = screen.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").split(/\r?\n/u);
670
+ return lines.flatMap((text, i) => /^\s*⎿\s+\S/u.test(text) ? [switchResultAt(lines, i)] : []).filter(row => row !== null);
671
+ }
663
672
  // Claude Code 2.1.282 は選択肢へ「1.」などの番号を付ける。番号の有無のどちらも受ける。
664
673
  export function claudeLoginMethodMenu(screen) {
665
674
  const tail = screen.split("\n").slice(-32).join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.70.67",
3
+ "version": "0.70.69",
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": [