aiterm-mcp 0.70.66 → 0.70.67

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,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.70.67] - 2026-11-15
11
+
12
+ - 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の前に仕様を書かせる").
13
+
10
14
  ## [0.70.66] - 2026-11-15
11
15
 
12
16
  - A Claude seat on plan mode no longer waits for a person at the ExitPlanMode dialog "Ready to code?" (a141, Kiro's request). Every Claude seat's own settings now carry a `PermissionRequest` hook for `ExitPlanMode` only. The hook answers as option 1 ("Yes, and switch to BYPASS PERMISSIONS"): it allows the call with the call's own input and sets the session mode to `bypassPermissions`, which the seat already ran in. Claude Code 2.1.325 ignores an allow without the input for this tool, so the input is part of the answer. Any other tool, any other dialog (AskUserQuestion included), an unreadable input and a process outside an Aiterm seat get no decision and keep their screen. A seat already running keeps its old settings until it is resumed or relaunched; an Aiterm below 0.70.66 behaves as before (harness-contracts.md "ExitPlanModeの承認").
@@ -3514,7 +3518,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
3514
3518
  `ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
3515
3519
  provenance.
3516
3520
 
3517
- [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.66...HEAD
3521
+ [Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.67...HEAD
3522
+ [0.70.67]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.66...v0.70.67
3518
3523
  [0.70.66]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.65...v0.70.66
3519
3524
  [0.70.65]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.64...v0.70.65
3520
3525
  [0.70.64]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.63...v0.70.64
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.66** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
218
+ **状態:** 開発継続中 · 現行公開版 **v0.70.67** · 動作対象は 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.66** · 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.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).
231
231
 
232
232
  ### Update and rollback
233
233
 
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env node
2
+ // Claude PreToolUse hook for EnterPlanMode only (harness-contracts.md "EnterPlanModeの前に仕様を書かせる").
3
+ // EnterPlanMode takes no arguments, so a seat that calls it without having written what it will plan falls into plan mode's
4
+ // "ask the user" flow and an unattended seat stalls there. This turns the first such call back, once per prompt, telling the
5
+ // AI to write the spec in its own words. Anything unexpected prints nothing and exits 0 (allow).
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ import { currentUid, runtimeStateBase } from "./state-root.js";
9
+ const MAX_STDIN_BYTES = 8 * 1024 * 1024;
10
+ const TAIL_BYTES = 512 * 1024;
11
+ const POLL_MS = 50;
12
+ const WAIT_MS = 1500;
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
+ const SPEC_MIN_CHARS = 80;
15
+ const AITERM_ENV = ["AITERM_AGENT_KIND", "AITERM_SESSION_ID", "AITERM_AGENT_SESSION_ID", "AITERM_AGENT_LAUNCH_ID"];
16
+ const GUIDANCE = "プランモードに入る前に、プランを練りたい内容の詳細な仕様を、あなた自身の言葉で書いてください。"
17
+ + "何を作る・直す・調べるのか、範囲、守る条件、終わりの形を書いたうえで、もう一度 EnterPlanMode を呼んでください。";
18
+ async function readStdin() {
19
+ const chunks = [];
20
+ let total = 0;
21
+ for await (const chunk of process.stdin) {
22
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
23
+ total += bytes.length;
24
+ if (total > MAX_STDIN_BYTES)
25
+ return "";
26
+ chunks.push(bytes);
27
+ }
28
+ return Buffer.concat(chunks).toString("utf8");
29
+ }
30
+ /** The transcript's tail as text (a cut first line is dropped), or null when it cannot be read. */
31
+ function readTail(file) {
32
+ try {
33
+ const fd = fs.openSync(file, "r");
34
+ try {
35
+ const size = fs.fstatSync(fd).size;
36
+ const start = Math.max(0, size - TAIL_BYTES);
37
+ const buffer = Buffer.alloc(size - start);
38
+ fs.readSync(fd, buffer, 0, buffer.length, start);
39
+ const text = buffer.toString("utf8");
40
+ return start > 0 ? text.slice(text.indexOf("\n") + 1) : text;
41
+ }
42
+ finally {
43
+ fs.closeSync(fd);
44
+ }
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ function blocksOf(row) {
51
+ return Array.isArray(row.message?.content) ? row.message.content : [];
52
+ }
53
+ /**
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.
56
+ */
57
+ export function specChars(transcript, toolUseId) {
58
+ const rows = [];
59
+ for (const line of transcript.split("\n")) {
60
+ try {
61
+ rows.push(JSON.parse(line));
62
+ }
63
+ catch { /* a half-written or foreign line */ }
64
+ }
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]));
78
+ }
79
+ }
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);
82
+ }
83
+ function stateFile(env) {
84
+ const seat = env.AITERM_SESSION_ID;
85
+ const launch = env.AITERM_AGENT_LAUNCH_ID;
86
+ if (!seat || !launch)
87
+ return null;
88
+ return path.join(runtimeStateBase(), `aiterm-mcp-${currentUid()}`, "agents", `${seat}.${launch}.claude-plan-spec`);
89
+ }
90
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
91
+ export async function planSpecDecision(payload, env = process.env, timing = { waitMs: WAIT_MS, pollMs: POLL_MS }) {
92
+ const input = payload;
93
+ if (!input || typeof input !== "object" || input.hook_event_name !== "PreToolUse" || input.tool_name !== "EnterPlanMode"
94
+ || !AITERM_ENV.some(name => env[name]))
95
+ return null;
96
+ const file = stateFile(env);
97
+ if (!file || typeof input.session_id !== "string" || typeof input.prompt_id !== "string" || typeof input.tool_use_id !== "string"
98
+ || typeof input.transcript_path !== "string" || !path.isAbsolute(input.transcript_path))
99
+ return null;
100
+ const key = `${input.session_id}\n${input.prompt_id}`;
101
+ try {
102
+ if (fs.readFileSync(file, "utf8") === key)
103
+ return null;
104
+ }
105
+ catch { /* nothing recorded yet */ }
106
+ let chars = null;
107
+ for (let waited = 0;; waited += timing.pollMs) {
108
+ const tail = readTail(input.transcript_path);
109
+ if (tail === null)
110
+ return null;
111
+ chars = specChars(tail, input.tool_use_id);
112
+ if (chars !== null || waited >= timing.waitMs)
113
+ break;
114
+ await sleep(timing.pollMs);
115
+ }
116
+ if (chars !== null && chars >= SPEC_MIN_CHARS)
117
+ return null;
118
+ // Record the turn-back first: if it cannot be recorded the second call could not be let through, so allow instead.
119
+ try {
120
+ fs.writeFileSync(file, key, { mode: 0o600 });
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ return { hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: GUIDANCE } };
126
+ }
127
+ async function main() {
128
+ let payload = null;
129
+ try {
130
+ payload = JSON.parse(await readStdin());
131
+ }
132
+ catch { /* not JSON: no decision */ }
133
+ const decision = await planSpecDecision(payload);
134
+ if (decision)
135
+ process.stdout.write(JSON.stringify(decision) + "\n");
136
+ }
137
+ // Run only as the hook entry; importing it (tests) has no effect.
138
+ if (process.argv[1] && /claude-plan-spec-hook\.js$/.test(process.argv[1]))
139
+ await main();
package/dist/core.js CHANGED
@@ -504,6 +504,7 @@ function cleanupAgentState(name) {
504
504
  /\.antigravity-result-\d+-\d+\.json$/.test(f) ||
505
505
  f.endsWith(".claude-operation.json") ||
506
506
  f.endsWith(".claude-approval.json") ||
507
+ f.endsWith(".claude-plan-spec") ||
507
508
  f.endsWith(".claude-dispatch") ||
508
509
  f.endsWith(".interim.json") ||
509
510
  f.endsWith(".steers.jsonl") ||
@@ -79,6 +79,9 @@ export function agentClaudeDispatchReceiptPath(name, launchId, operationId) {
79
79
  function claudePlanApproveScriptPath() {
80
80
  return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "claude-plan-approve-hook.js");
81
81
  }
82
+ function claudePlanSpecScriptPath() {
83
+ return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "claude-plan-spec-hook.js");
84
+ }
82
85
  function claudeHookScriptPath() {
83
86
  // この module は dist/harnesses/ に置かれるが、stop hook 実体は dist/ 直下に build される。
84
87
  return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "claude-stop-hook.js");
@@ -105,6 +108,10 @@ export function createClaudeCorrelationSettings(name, launchId, model, effort) {
105
108
  if (!fs.existsSync(planScript)) {
106
109
  throw new AitermError(`Claude plan approve hook が見つかりません。npm run build を実行してください: ${planScript}`, 2);
107
110
  }
111
+ const specScript = claudePlanSpecScriptPath();
112
+ if (!fs.existsSync(specScript)) {
113
+ throw new AitermError(`Claude plan spec hook が見つかりません。npm run build を実行してください: ${specScript}`, 2);
114
+ }
108
115
  const settings = agentManagedClaudeSettingsPath(name, launchId);
109
116
  writeJson0600(settings, {
110
117
  ...(model ? { model } : {}),
@@ -128,6 +135,10 @@ export function createClaudeCorrelationSettings(name, launchId, model, effort) {
128
135
  PermissionRequest: [
129
136
  { matcher: "ExitPlanMode", hooks: [{ type: "command", command: nodeHookCommand(planScript), timeout: 10 }] },
130
137
  ],
138
+ // EnterPlanMode without a written spec drops an unattended seat into plan mode's ask-the-user flow; turn it back once (harness-contracts.md).
139
+ PreToolUse: [
140
+ { matcher: "EnterPlanMode", hooks: [{ type: "command", command: nodeHookCommand(specScript), timeout: 10 }] },
141
+ ],
131
142
  },
132
143
  });
133
144
  return settings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-mcp",
3
- "version": "0.70.66",
3
+ "version": "0.70.67",
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": [