aiterm-mcp 0.70.7 → 0.70.9
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 +24 -1
- package/README.ja.md +3 -1
- package/README.md +3 -1
- package/dist/agent-metadata-reader.js +10 -2
- package/dist/agent-resolver.js +10 -0
- package/dist/core.js +60 -19
- package/dist/errors.js +6 -0
- package/dist/harnesses/antigravity.js +48 -3
- package/dist/harnesses/caller-mcp.js +94 -0
- package/dist/harnesses/cursor.js +50 -5
- package/dist/harnesses/grok.js +52 -3
- package/dist/index.js +23 -15
- package/dist/remote-authorize.js +51 -6
- package/dist/remote-contract.js +4 -4
- package/dist/remote-path.js +29 -5
- package/dist/remote-provision.js +94 -14
- package/dist/remote-terminal-cli.js +8 -5
- package/dist/remote-terminal.js +164 -63
- package/dist/remote.js +48 -8
- package/dist/terminal-launch-error.js +12 -9
- package/dist/transcript-read-cli.js +5 -10
- package/dist/write-ban.js +22 -7
- package/native/write-ban/win32-x64/aiterm-write-ban.exe +0 -0
- package/package.json +2 -1
package/dist/remote.js
CHANGED
|
@@ -122,6 +122,10 @@ export function remoteShell(target) {
|
|
|
122
122
|
if (!shell) {
|
|
123
123
|
shell = runSsh(target, REMOTE_SHELL_PROBE).then(({ code, stdout, stderr }) => {
|
|
124
124
|
if (code === 255) {
|
|
125
|
+
if (target.trusted_ref) {
|
|
126
|
+
const failure = classifySshFailure(stderr);
|
|
127
|
+
throw new RemoteTerminalError(failure.code, failure.message, failure.action);
|
|
128
|
+
}
|
|
125
129
|
const detail = stderr.trim().split("\n").slice(-3).join(" / ") || "exit 255";
|
|
126
130
|
throw new AitermError(`REMOTE_CONNECT_FAILED: ${remoteLabel(target)} へ接続できません(${detail})`, 2);
|
|
127
131
|
}
|
|
@@ -162,7 +166,11 @@ export function remotePlatform(target) {
|
|
|
162
166
|
const detail = stderr.trim().split("\n").slice(-3).join(" / ") || "exit 255";
|
|
163
167
|
throw new AitermError(`REMOTE_CONNECT_FAILED: ${remoteLabel(target)} へ接続できません(${detail})`, 2);
|
|
164
168
|
}
|
|
165
|
-
|
|
169
|
+
const found = classifyRemotePlatform(stdout);
|
|
170
|
+
// The same run tells which shell sshd starts, so a command build needs no second probe (T4).
|
|
171
|
+
if (found && !shells.has(key))
|
|
172
|
+
shells.set(key, Promise.resolve(found !== "windows" ? "posix" : classifyRemoteShell(stdout) === "cmd" ? "cmd" : "powershell"));
|
|
173
|
+
return found;
|
|
166
174
|
});
|
|
167
175
|
platform.catch(() => platforms.delete(key));
|
|
168
176
|
platforms.set(key, platform);
|
|
@@ -178,6 +186,34 @@ export function posixCommand(script) {
|
|
|
178
186
|
'r="$HOME/.aiterm/runtime/current/bin"; [ -x "$r/aiterm-mcp" ] && PATH="$r:$PATH"; export PATH';
|
|
179
187
|
return `/bin/sh -c '${importPath}; ${script}'`;
|
|
180
188
|
}
|
|
189
|
+
/** PowerShellの単引用符literal。`'`だけが特別で、`$`・空白・二重引用符・非ASCIIはそのまま文字になる。 */
|
|
190
|
+
export const powershellQuote = (value) => `'${value.replace(/'/g, "''")}'`;
|
|
191
|
+
/** `& 'prog' 'arg'...`。引数は全て単引用符で包む。 */
|
|
192
|
+
export const powershellInvoke = (argv) => `& ${argv.map(powershellQuote).join(" ")}`;
|
|
193
|
+
/** 固定のプログラム呼び出し。windowsのaiterm-*は、無い時に言語によらず読める`command not found`を出す。 */
|
|
194
|
+
export function terminalProgram(argv) {
|
|
195
|
+
const [program] = argv;
|
|
196
|
+
return {
|
|
197
|
+
posix: `exec ${argv.join(" ")}`,
|
|
198
|
+
windows: `${program.startsWith("aiterm-") ? `if (-not (Get-Command ${powershellQuote(program)} -ErrorAction SilentlyContinue)) { [Console]::Error.WriteLine(${powershellQuote(`${program}: command not found`)}); exit 127 }; ` : ""}${powershellInvoke(argv)}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// 製品のruntime(remote-terminal.md R16)があれば、利用者のPATH上の別のaiterm-mcpより先に使う。
|
|
202
|
+
// npm's .ps1 shims win over .cmd in PowerShell, and Windows PowerShell 5.1 is Restricted by default: allow scripts for this process only.
|
|
203
|
+
const WINDOWS_PREAMBLE = "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force -ErrorAction SilentlyContinue; $r = Join-Path $env:USERPROFILE '.aiterm\\runtime\\current\\bin'; if (Test-Path -LiteralPath (Join-Path $r 'aiterm-mcp.cmd')) { $env:PATH = $r + ';' + $env:PATH }; ";
|
|
204
|
+
// `pwsh -c`は最後のnative commandの失敗を全て1にする。ここで本物の終了codeを返す。
|
|
205
|
+
const WINDOWS_EPILOGUE = "; $ok = $?; $code = $LASTEXITCODE; if ($code) { exit $code }; if ($ok) { exit 0 }; exit 1";
|
|
206
|
+
/** PowerShell本文を、shellが`cmd`の時だけ`powershell -EncodedCommand`で包む(引用符の書式がcmdとPowerShellで違うため)。 */
|
|
207
|
+
export function powershellForShell(shell, body) {
|
|
208
|
+
return shell === "powershell" ? body
|
|
209
|
+
: `powershell -NoProfile -NonInteractive -OutputFormat Text -EncodedCommand ${Buffer.from(body, "utf16le").toString("base64")}`;
|
|
210
|
+
}
|
|
211
|
+
/** 端末のshellに合う1つのコマンド文字列。userの文字列はここへ入れない(固定文・検証済みtoken・base64だけ)。 */
|
|
212
|
+
export function terminalCommand(shell, script) {
|
|
213
|
+
return shell === "posix" ? posixCommand(script.posix) : powershellForShell(shell, `${WINDOWS_PREAMBLE}${script.windows}${WINDOWS_EPILOGUE}`);
|
|
214
|
+
}
|
|
215
|
+
/** stdinに載せたPowerShell scriptを丸ごと実行する入口(authorize-key・Windows provision)。scriptは多行・ASCIIだけ。 */
|
|
216
|
+
export const WINDOWS_STDIN_SCRIPT_COMMAND = powershellForShell("cmd", "Invoke-Expression ([Console]::In.ReadToEnd())");
|
|
181
217
|
/** 現地のaiterm-mcpを起動するコマンド。Windowsはユーザー環境からPATHが入るので、そのまま呼ぶ。 */
|
|
182
218
|
export function remoteServerCommand(shell) {
|
|
183
219
|
return shell === "posix" ? posixCommand("exec aiterm-mcp") : "aiterm-mcp";
|
|
@@ -187,7 +223,9 @@ export async function callRemoteTool(target, name, args, timeoutMs = 600_000, pr
|
|
|
187
223
|
if (privateEnv && !target.trusted_ref)
|
|
188
224
|
throw new AitermError("REMOTE_PRIVATE_ENV_UNSUPPORTED: private values travel only to a terminal binding", 2);
|
|
189
225
|
const shell = await remoteShell(target);
|
|
190
|
-
|
|
226
|
+
// 信頼済み端末はshellごとの正規のコマンド(runtimeの優先と終了codeを含む)。個別指定のremoteは従来のまま。
|
|
227
|
+
const command = target.trusted_ref ? terminalCommand(shell, terminalProgram(privateEnv ? ["aiterm-mcp", "--private-env-stdin"] : ["aiterm-mcp"]))
|
|
228
|
+
: privateEnv ? posixCommand("exec aiterm-mcp --private-env-stdin") : remoteServerCommand(shell);
|
|
191
229
|
const { args: sshArgs, env } = sshInvocation(target, command);
|
|
192
230
|
const transport = privateEnv
|
|
193
231
|
? new SshStdioTransport(sshArgs, `${JSON.stringify({ schema: PRIVATE_ENV_SCHEMA, env: privateEnv })}\n`)
|
|
@@ -226,9 +264,11 @@ export async function callRemoteTool(target, name, args, timeoutMs = 600_000, pr
|
|
|
226
264
|
await client.close().catch(() => { });
|
|
227
265
|
}
|
|
228
266
|
}
|
|
267
|
+
// npmのbinをPATHへ通さず aiterm-mcp だけリンクしている端末がある。見つからなければ同じpackageのCLIを使う。
|
|
268
|
+
export const WAIT_RESOLVE = 'w=$(command -v aiterm-wait) || w="$(dirname "$(readlink -f "$(command -v aiterm-mcp)")")/aiterm-wait-cli.js"';
|
|
229
269
|
const SESSION_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
230
270
|
const OPERATION_RE = /^sha256:[0-9a-f]{64}$/;
|
|
231
|
-
export function remoteWaitCommand(shell, session, cursor, operationId, timeout, inputId) {
|
|
271
|
+
export function remoteWaitCommand(shell, session, cursor, operationId, timeout, inputId, trusted = false) {
|
|
232
272
|
if (!SESSION_RE.test(session))
|
|
233
273
|
throw new AitermError("REMOTE_SESSION_INVALID: session名が不正です", 2);
|
|
234
274
|
if (operationId !== null && !OPERATION_RE.test(operationId))
|
|
@@ -242,16 +282,16 @@ export function remoteWaitCommand(shell, session, cursor, operationId, timeout,
|
|
|
242
282
|
parts.push("--operation", operationId);
|
|
243
283
|
if (inputId !== undefined)
|
|
244
284
|
parts.push("--input", inputId);
|
|
285
|
+
if (trusted)
|
|
286
|
+
return terminalCommand(shell, { posix: `${WAIT_RESOLVE}; exec "$w" ${parts.join(" ")}`, windows: terminalProgram(["aiterm-wait", ...parts]).windows });
|
|
245
287
|
if (shell !== "posix")
|
|
246
288
|
return `aiterm-wait ${parts.join(" ")}`;
|
|
247
|
-
|
|
248
|
-
const resolve = 'w=$(command -v aiterm-wait) || w="$(dirname "$(readlink -f "$(command -v aiterm-mcp)")")/aiterm-wait-cli.js"';
|
|
249
|
-
return posixCommand(`${resolve}; exec "$w" ${parts.join(" ")}`);
|
|
289
|
+
return posixCommand(`${WAIT_RESOLVE}; exec "$w" ${parts.join(" ")}`);
|
|
250
290
|
}
|
|
251
291
|
/** 親が別processで起動する完了待ち。ssh越しのaiterm-waitで、exit codeは現地のaiterm-waitをそのまま返す。 */
|
|
252
292
|
export async function remoteWaitProcess(target, session, cursor, inputId) {
|
|
253
293
|
// 別processには鍵のパスフレーズを渡せない。ssh-agentか、張ってあるControlMasterの接続に相乗りする。
|
|
254
|
-
const { args } = sshInvocation(target, remoteWaitCommand(await remoteShell(target), session, cursor, null, 600, inputId), { passphrase: false });
|
|
294
|
+
const { args } = sshInvocation(target, remoteWaitCommand(await remoteShell(target), session, cursor, null, 600, inputId, !!target.trusted_ref), { passphrase: false });
|
|
255
295
|
return { executable: "ssh", args, windows_start_process_argument_list: process.platform === "win32" ? windowsStartProcessArgumentList(args) : null };
|
|
256
296
|
}
|
|
257
297
|
function runSsh(target, command, signal) {
|
|
@@ -277,7 +317,7 @@ export async function observeRemoteAgentDone(target, session, options) {
|
|
|
277
317
|
if (options.signal?.aborted)
|
|
278
318
|
throw new AitermError("REMOTE_OBSERVE_ABORTED: 観測を停止しました", 2);
|
|
279
319
|
const remaining = infinite ? 86_400 : Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
|
280
|
-
const command = remoteWaitCommand(await remoteShell(target), session, options.cursor ?? null, options.operation_id ?? null, Math.min(remaining, 86_400), options.input_id);
|
|
320
|
+
const command = remoteWaitCommand(await remoteShell(target), session, options.cursor ?? null, options.operation_id ?? null, Math.min(remaining, 86_400), options.input_id, !!target.trusted_ref);
|
|
281
321
|
const { code, stdout, stderr } = await runSsh(target, command, options.signal);
|
|
282
322
|
if (options.signal?.aborted)
|
|
283
323
|
throw new AitermError("REMOTE_OBSERVE_ABORTED: 観測を停止しました", 2);
|
|
@@ -4,8 +4,9 @@ const ACTIONS = {
|
|
|
4
4
|
TERMINAL_INVALID: "起動の指定(端末の情報か作業フォルダ)が正しくありません。BellTeamの不具合の恐れがあります。",
|
|
5
5
|
TARGET_INVALID: "起動の指定(端末の情報)が正しくありません。BellTeamの不具合の恐れがあります。",
|
|
6
6
|
TERMINAL_OS_MISMATCH: "端末のOSが、登録されているOSと違います。別の機械を指している恐れがあり止めました。端末の登録(OS)を確かめてください。",
|
|
7
|
-
TERMINAL_PLATFORM_UNSUPPORTED: "この端末のOS
|
|
8
|
-
TERMINAL_HARNESS_UNSUPPORTED: "
|
|
7
|
+
TERMINAL_PLATFORM_UNSUPPORTED: "この端末のOSは、Mac・Linux・Windowsのどれとも確かめられず、席を起こせません。Mac、Linux、Windowsのどれかの端末を使ってください。",
|
|
8
|
+
TERMINAL_HARNESS_UNSUPPORTED: "このAIの種類は、端末では起こせません。BellTeamの不具合の恐れがあります。",
|
|
9
|
+
AGENT_AUTH_REQUIRED: "端末のこのAIにログインしていません。席は作られていません。端末でこのAIにログインしてから、起こし直してください。",
|
|
9
10
|
REF_INVALID: "端末の登録が見つかりません。端末の登録を確かめてください。",
|
|
10
11
|
BINDING_UNKNOWN: "端末の登録が見つかりません。端末の登録を確かめてください。",
|
|
11
12
|
BINDING_STORE_UNREADABLE: "端末の登録を読めませんでした。端末の登録をやり直してください。",
|
|
@@ -19,15 +20,14 @@ const ACTIONS = {
|
|
|
19
20
|
CREDENTIAL_REVISION_STALE: "端末へ入る鍵が新しくなりました。新しい鍵で起こし直します。",
|
|
20
21
|
CREDENTIAL_UNAVAILABLE: "端末へ入る鍵を使えません。端末の登録で鍵を確かめてください。",
|
|
21
22
|
AUTH_FAILED: "端末が鍵を受け付けませんでした。端末の登録から、パスワードで鍵を許可し直してください。",
|
|
22
|
-
CONNECTION_REFUSED: "端末がSSHの接続を断りました。端末のSSHサーバーが入になっているか確かめてください(Macは「リモートログイン」、Linuxはsshd
|
|
23
|
+
CONNECTION_REFUSED: "端末がSSHの接続を断りました。端末のSSHサーバーが入になっているか確かめてください(Macは「リモートログイン」、Linuxはsshdの起動、WindowsはオプションのOpenSSHサーバーの追加とsshdサービスの起動)。",
|
|
23
24
|
UNREACHABLE: "端末につながりません。電源とネットワークを確かめてください。つながれば起こし直します。",
|
|
24
25
|
CONNECTION_FAILED: "端末へのSSH接続に失敗しました。端末の電源とSSHの設定を確かめてください。",
|
|
25
|
-
REMOTE_AITERM_UNAVAILABLE: "端末にAiterm
|
|
26
|
+
REMOTE_AITERM_UNAVAILABLE: "端末にAitermが入っていません(またはsshで入った時のPATHにありません)。端末の準備(Aitermの導入)をやり直してください。",
|
|
26
27
|
REMOTE_AITERM_TOO_OLD: "端末のAitermが古いため起こせません。端末のAitermを更新してください。",
|
|
27
28
|
SEAT_FORWARD_UNAVAILABLE: "端末からBellTeamへ戻る通り道がまだ用意できていません。少し待ってから起こし直してください。",
|
|
28
29
|
CWD_UNAVAILABLE: "端末に作業フォルダがありません。メンバーの作業フォルダを選び直すか、そのフォルダを作ってください。",
|
|
29
30
|
AGENT_LAUNCH_NOT_STARTED: "席を作る途中で失敗しました。席は残っていません。もう一度起こし直します。",
|
|
30
|
-
CLAUDE_AUTH_NOT_AUTHENTICATED: "端末のClaude Codeにログインしていません。端末でClaude Codeにログインしてください。",
|
|
31
31
|
CLAUDE_AUTH_STATUS_UNCONFIRMED: "端末のClaude Codeのログイン状態を確かめられませんでした。少し待ってから起こし直してください。",
|
|
32
32
|
CLAUDE_AUTH_STATUS_TIMEOUT: "端末のClaude Codeのログイン状態を時間内に確かめられませんでした。少し待ってから起こし直してください。",
|
|
33
33
|
};
|
|
@@ -41,10 +41,9 @@ export function terminalLaunchAction(code) {
|
|
|
41
41
|
export const LAUNCH_ERROR_META = "aiterm/launch_error";
|
|
42
42
|
export const ERROR_CODE_META = "aiterm/error_code";
|
|
43
43
|
/** R18 for a local launch: the fresh native creation left no seat (core.freshLaunchFailure). */
|
|
44
|
-
export function launchNotStartedMeta(harness, phase = "native_create") {
|
|
45
|
-
const code = "AGENT_LAUNCH_NOT_STARTED";
|
|
44
|
+
export function launchNotStartedMeta(harness, phase = "native_create", code = "AGENT_LAUNCH_NOT_STARTED") {
|
|
46
45
|
return { [LAUNCH_ERROR_META]: { schema: "aiterm.agent-launch-error.v1", harness, code, phase,
|
|
47
|
-
effect: "not_started", session_created: false, action:
|
|
46
|
+
effect: "not_started", session_created: false, action: code === "AGENT_AUTH_REQUIRED" || phase !== "input" ? ACTIONS[code] : INPUT_ACTION } };
|
|
48
47
|
}
|
|
49
48
|
// phase "input": refused from the arguments alone; nothing was started, so launching again unchanged fails the same way.
|
|
50
49
|
const INPUT_ACTION = "起動の指定(追加の指示かMCPの設定)をこのAIでは使えません。席は作られていません。指定を見直してください。";
|
|
@@ -65,7 +64,11 @@ export function withTerminalLaunchAction(result, harness = "claude-code") {
|
|
|
65
64
|
const preflight = structured?.schema === "aiterm.agent-launch-error.v1";
|
|
66
65
|
if (structured && !preflight)
|
|
67
66
|
return result;
|
|
68
|
-
const
|
|
67
|
+
const text = result.content?.find((item) => item.type === "text")?.text ?? "";
|
|
68
|
+
// "Not logged in" is one code for every harness (0.70.9). A terminal on 0.70.1-0.70.8 answers Claude's only as the structured preflight code.
|
|
69
|
+
if (preflight ? structured.code === "CLAUDE_AUTH_NOT_AUTHENTICATED" : /^(?:aiterm: )?AGENT_LAUNCH_NOT_STARTED: AGENT_AUTH_REQUIRED:/.test(text))
|
|
70
|
+
return { ...result, _meta: { ...result._meta, ...launchNotStartedMeta(preflight ? structured.harness : harness, "input", "AGENT_AUTH_REQUIRED") } };
|
|
71
|
+
const code = preflight ? structured.code : errorCode(text);
|
|
69
72
|
const action = terminalLaunchAction(code);
|
|
70
73
|
if (!action)
|
|
71
74
|
return result;
|
|
@@ -6,7 +6,7 @@ import { spawnSync } from "node:child_process";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { readCompletedTranscript } from "./transcript-read.js";
|
|
8
8
|
import { boundTerminalTarget, classifySshFailure, trustedSshArguments } from "./remote-terminal.js";
|
|
9
|
-
import {
|
|
9
|
+
import { remoteShell, terminalCommand, terminalProgram } from "./remote.js";
|
|
10
10
|
const ERROR = "aiterm.transcript-read-error.v1";
|
|
11
11
|
function option(args, name) {
|
|
12
12
|
const at = args.indexOf(name);
|
|
@@ -30,14 +30,14 @@ export function transcriptFlags(args) {
|
|
|
30
30
|
}
|
|
31
31
|
return flags;
|
|
32
32
|
}
|
|
33
|
-
function run(args) {
|
|
33
|
+
async function run(args) {
|
|
34
34
|
const flags = transcriptFlags(args);
|
|
35
35
|
const target = boundTerminalTarget(flags[1]);
|
|
36
36
|
if (!target) {
|
|
37
37
|
const id = option(flags, "--cursor-session"), max = option(flags, "--max-bytes");
|
|
38
38
|
return { line: JSON.stringify(readCompletedTranscript(flags[1], id ? { claudeSessionId: id, offset: Number(option(flags, "--offset")) } : null, max ? Number(max) : undefined)), code: 0 };
|
|
39
39
|
}
|
|
40
|
-
const ssh = spawnSync("ssh", trustedSshArguments(target.trusted_ref,
|
|
40
|
+
const ssh = spawnSync("ssh", trustedSshArguments(target.trusted_ref, terminalCommand(await remoteShell(target), terminalProgram(["aiterm-remote-terminal", "transcript-read", ...flags])), null), { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 120_000, maxBuffer: 64 * 1024 * 1024 });
|
|
41
41
|
const line = (ssh.stdout ?? "").trim().split("\n").pop() ?? "";
|
|
42
42
|
let parsed = null;
|
|
43
43
|
try {
|
|
@@ -57,14 +57,9 @@ try {
|
|
|
57
57
|
}
|
|
58
58
|
catch { /* imported */ }
|
|
59
59
|
if (entry) {
|
|
60
|
-
|
|
61
|
-
const { line, code } = run(process.argv.slice(2));
|
|
62
|
-
process.stdout.write(`${line}\n`);
|
|
63
|
-
process.exit(code);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
60
|
+
run(process.argv.slice(2)).then(({ line, code }) => { process.stdout.write(`${line}\n`); process.exit(code); }, (error) => {
|
|
66
61
|
const message = error instanceof Error ? error.message : String(error);
|
|
67
62
|
process.stdout.write(`${JSON.stringify({ schema: ERROR, code: /^([A-Z][A-Z0-9_]+):/.exec(message)?.[1] ?? "AITERM_FAILED", message })}\n`);
|
|
68
63
|
process.exit(2);
|
|
69
|
-
}
|
|
64
|
+
});
|
|
70
65
|
}
|
package/dist/write-ban.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as fs from "node:fs";
|
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { AitermError } from "./errors.js";
|
|
8
|
+
import { resolveWindowsPowerShell7 } from "./windows-powershell.js";
|
|
8
9
|
// Linux: Landlock via the bundled static helper (native/write-ban/aiterm-write-ban.c), so nothing has to be
|
|
9
10
|
// installed on the machine. Unprivileged (works in standard Docker, where bwrap cannot create a namespace).
|
|
10
11
|
// Fails closed: exit 126 before the CLI starts.
|
|
@@ -13,31 +14,45 @@ function landlockHelper() {
|
|
|
13
14
|
throw unenforceable(`no write-ban helper for CPU ${process.arch}`);
|
|
14
15
|
return fileURLToPath(new URL(`../native/write-ban/linux-${process.arch}/aiterm-write-ban`, import.meta.url));
|
|
15
16
|
}
|
|
17
|
+
// Windows: the bundled helper (native/write-ban/aiterm-write-ban-win.c) runs the CLI under a restricted token whose
|
|
18
|
+
// marker SID is denied writes by an inert inheritable ACE on the folder (ADR 0140).
|
|
19
|
+
function windowsHelper() {
|
|
20
|
+
if (process.arch !== "x64")
|
|
21
|
+
throw unenforceable(`no write-ban helper for CPU ${process.arch}`);
|
|
22
|
+
return fileURLToPath(new URL("../native/write-ban/win32-x64/aiterm-write-ban.exe", import.meta.url));
|
|
23
|
+
}
|
|
16
24
|
const unenforceable = (why) => new AitermError(`READONLY_UNENFORCEABLE: the project write-ban cannot be applied here: ${why}`, 2);
|
|
17
25
|
function seatbeltProfile(folder) {
|
|
18
26
|
return `(version 1)(allow default)(deny file-write* (subpath "${folder.replace(/[\\"]/g, "\\$&")}"))`;
|
|
19
27
|
}
|
|
20
28
|
/** argv placed before the CLI's own argv. The CLI is exec'd, so its PID and process name stay the seat's. */
|
|
21
29
|
export function writeBanPrefix(ban) {
|
|
22
|
-
return ban.method === "landlock"
|
|
23
|
-
? [
|
|
24
|
-
|
|
30
|
+
return ban.method === "landlock" ? [landlockHelper(), ban.path, "--"]
|
|
31
|
+
: ban.method === "restricted-token" ? [windowsHelper(), ban.path, "--"]
|
|
32
|
+
: ["/usr/bin/sandbox-exec", "-p", seatbeltProfile(ban.path)];
|
|
33
|
+
}
|
|
34
|
+
/** Windows: the helper starts the CLI with CreateProcess, which runs only real executables; npm shims go through pwsh. */
|
|
35
|
+
export function windowsWriteBanArgv(ban, argv) {
|
|
36
|
+
const [bin, ...rest] = argv;
|
|
37
|
+
const ps1 = /\.ps1$/i.test(bin) ? bin : /\.(?:cmd|bat)$/i.test(bin) ? bin.replace(/\.(?:cmd|bat)$/i, ".ps1") : null;
|
|
38
|
+
const cli = ps1 && fs.existsSync(ps1)
|
|
39
|
+
? [resolveWindowsPowerShell7(), "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ps1, ...rest]
|
|
40
|
+
: /\.(?:cmd|bat)$/i.test(bin) ? [process.env.ComSpec ?? "cmd.exe", "/d", "/c", ...argv] : argv;
|
|
41
|
+
return [...writeBanPrefix(ban), ...cli];
|
|
25
42
|
}
|
|
26
43
|
/**
|
|
27
44
|
* Prove on this machine that the ban can be applied before any seat starts. Without proof the fork is refused:
|
|
28
45
|
* starting it would let it write the project (the one thing the Owner forbade).
|
|
29
46
|
*/
|
|
30
47
|
export function probeWriteBan(folder, platform = process.platform) {
|
|
31
|
-
if (platform === "win32")
|
|
32
|
-
throw unenforceable("Windows has no same-user folder write-ban yet");
|
|
33
48
|
if (!path.isAbsolute(folder) || !fs.existsSync(folder))
|
|
34
49
|
throw unenforceable(`folder ${folder} does not exist`);
|
|
35
50
|
const real = fs.realpathSync(folder);
|
|
36
51
|
if (real === path.parse(real).root)
|
|
37
52
|
throw unenforceable("the folder is the filesystem root");
|
|
38
|
-
const ban = { path: real, method: platform === "darwin" ? "seatbelt" : "landlock" };
|
|
53
|
+
const ban = { path: real, method: platform === "darwin" ? "seatbelt" : platform === "win32" ? "restricted-token" : "landlock" };
|
|
39
54
|
const [bin, ...args] = writeBanPrefix(ban);
|
|
40
|
-
const probe = ban.method === "
|
|
55
|
+
const probe = ban.method === "seatbelt" ? [...args, "/usr/bin/true"] : ["--probe", real];
|
|
41
56
|
const r = spawnSync(bin, probe, { encoding: "utf8", timeout: 10_000 });
|
|
42
57
|
if (r.status !== 0)
|
|
43
58
|
throw unenforceable((r.stderr || r.error?.message || `exit ${r.status}`).trim().split("\n").pop() ?? "probe failed");
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.9",
|
|
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": [
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"dist/*.js",
|
|
57
57
|
"dist/harnesses/*.js",
|
|
58
58
|
"native/write-ban/linux-*/aiterm-write-ban",
|
|
59
|
+
"native/write-ban/win32-x64/aiterm-write-ban.exe",
|
|
59
60
|
"runtime-overlap.json",
|
|
60
61
|
"state-compat.json",
|
|
61
62
|
"README.md",
|