aiterm-mcp 0.70.5 → 0.70.7

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/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ import { loadAgentMetadata } from "./agent-metadata-reader.js";
2
3
  import { remoteInputDescription, remoteInputSchema, terminalArgumentDescription, terminalArgumentSchema } from "./remote-contract.js";
3
- import { boundTerminalTarget, bindTerminalSession, terminalSeatGroups, ensureSeatForward, extractMcpHeaders, maintainSeatForwards, REMOTE_MINIMUM_VERSION, seatIngressPort, rewriteSeatMcpConfig, terminalRemoteTarget, unbindTerminalSession, versionAtLeast } from "./remote-terminal.js";
4
+ import { boundTerminalTarget, bindTerminalSession, terminalSeatGroups, ensureSeatForward, extractMcpHeaders, maintainSeatForwards, REMOTE_MINIMUM_VERSION, seatIngressPort, checkTerminalPlatform, rewriteSeatMcpConfig, terminalRemoteTarget, unbindTerminalSession, versionAtLeast } from "./remote-terminal.js";
4
5
  import { launchEnvValue } from "./private-env.js";
5
6
  import { AuthResponseError, authUiSchema, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
6
7
  import { configurationRequestSchema, configurationToolOutputSchema, applyConfigurationRequest, reconcileConfigurationRequest } from "./configure-request.js";
7
- import { AitermError, AgentAuthenticationPreflightError, AgentResumeUnavailableError, AgentResumeError } from "./errors.js";
8
+ import { AitermError, AgentAuthenticationPreflightError, AgentResumeUnavailableError, AgentResumeError, launchInputRefusal } from "./errors.js";
8
9
  /**
9
10
  * aiterm-mcp — AI が握るローカル永続端末を stdio MCP サーバとして公開する(Node/TS 版)。
10
11
  *
@@ -19,6 +20,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
19
20
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
20
21
  import { readPrivateEnvLine, setPrivateEnv } from "./private-env.js";
21
22
  import { withTerminalLaunchAction, withErrorCode, launchNotStartedMeta } from "./terminal-launch-error.js";
23
+ import { codexMcpOverrides } from "./harnesses/codex.js";
22
24
  import { CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
23
25
  import { z } from "zod";
24
26
  import { agentModelsResult } from "./model-catalog.js";
@@ -260,7 +262,7 @@ export function createAitermServer(options = {}) {
260
262
  };
261
263
  if (e instanceof AitermError && e.launchNotStarted)
262
264
  return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
263
- _meta: launchNotStartedMeta(e.launchNotStarted.harness) };
265
+ _meta: launchNotStartedMeta(e.launchNotStarted.harness, e.launchNotStarted.phase) };
264
266
  return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true };
265
267
  }
266
268
  /**
@@ -839,15 +841,16 @@ export function createAitermServer(options = {}) {
839
841
  try {
840
842
  const local = core.readSeatTurns(sessions.filter(session => session.harness !== null).map(session => session.session_id));
841
843
  // Terminal seats: the same call relayed with the same _meta; each terminal answers only for its own bound sessions.
842
- // Inside the caller's 5 s pty_list budget (tool catalog timeout_ms): a slow or unreachable terminal contributes no rows.
844
+ // Inside the caller's 5 s pty_list budget (tool catalog timeout_ms): a terminal that fails or is slow contributes
845
+ // no rows, and its sessions are listed in `unread` so the caller keeps their last state instead of reading them as gone.
843
846
  const remote = await Promise.all(terminalSeatGroups().map(({ target, sessions: bound }) => Promise.race([
844
847
  callRemoteTool(target, "pty_list", {}, 4_000, undefined, requestMeta).then(result => {
845
848
  const seats = result._meta?.[SEAT_TURNS_RESULT_META_KEY]?.seats;
846
- return Array.isArray(seats) ? seats.filter((seat) => bound.includes(seat?.session_id)) : [];
847
- }, () => []),
848
- new Promise(resolve => setTimeout(resolve, 4_000, []).unref()),
849
+ return Array.isArray(seats) ? { seats: seats.filter((seat) => bound.includes(seat?.session_id)), unread: [] } : { seats: [], unread: bound };
850
+ }, () => ({ seats: [], unread: bound })),
851
+ new Promise(resolve => setTimeout(resolve, 4_000, { seats: [], unread: bound }).unref()),
849
852
  ])));
850
- return { _meta: { [SEAT_TURNS_RESULT_META_KEY]: { ...local, seats: [...local.seats, ...remote.flat()] } } };
853
+ return { _meta: { [SEAT_TURNS_RESULT_META_KEY]: { ...local, seats: [...local.seats, ...remote.flatMap(r => r.seats)], unread: remote.flatMap(r => r.unread) } } };
851
854
  }
852
855
  catch (e) {
853
856
  return { _meta: { [SEAT_TURNS_RESULT_META_KEY]: { schema: "aiterm.seat-turns.v1", error: e instanceof Error ? e.message : String(e) } } };
@@ -1218,9 +1221,20 @@ export function createAitermServer(options = {}) {
1218
1221
  async function launchRemoteAgent(target, harness, args, extra, privateEnv) {
1219
1222
  if (args.image && args.image.length > 0)
1220
1223
  throw new core.AitermError("REMOTE_IMAGE_UNSUPPORTED: 別端末への画像添付には未対応です", 2);
1224
+ // An Aiterm without fork_from would drop it and start a writable seat (ADR 0140), and one without Codex caller fields
1225
+ // would drop or refuse them: check the version first.
1226
+ const needs = args.fork_from ? { minimum: FORK_MINIMUM_VERSION, what: "fork_from" }
1227
+ : harness === "codex-cli" && (args.append_system_prompt !== undefined || args.mcp_config !== undefined)
1228
+ ? { minimum: CODEX_REMOTE_MINIMUM_VERSION, what: "append_system_prompt / mcp_config for codex-cli" } : null;
1229
+ if (needs) {
1230
+ const version = (await callRemoteTool(target, "pty_list", {}, 60_000)).remote_version ?? "0.0.0";
1231
+ if (!versionAtLeast(version, needs.minimum))
1232
+ throw new AitermError(`REMOTE_AITERM_TOO_OLD: the remote runs Aiterm ${version}; ${needs.what} needs ${needs.minimum} or later`, 2);
1233
+ }
1221
1234
  const delivery = args.prompt || args.throughline_source_session ? await deliveryForRequest(extra, true) : null;
1222
1235
  // A terminal's claude_agent takes append_system_prompt / mcp_config since 0.65.0; its agent_launch drops them until this release.
1223
- const result = target.trusted_ref && harness === "claude-code"
1236
+ // claude_agent has no fork_from, so a fork always goes through agent_launch.
1237
+ const result = target.trusted_ref && harness === "claude-code" && !args.fork_from
1224
1238
  ? await callRemoteTool(target, "claude_agent", args, 600_000, privateEnv)
1225
1239
  : await callRemoteTool(target, "agent_launch", { harness, ...args }, 600_000, privateEnv);
1226
1240
  const structured = result.structuredContent;
@@ -1249,27 +1263,34 @@ export function createAitermServer(options = {}) {
1249
1263
  ...(result.isError && !unconfirmed ? { isError: true } : {}),
1250
1264
  };
1251
1265
  }
1266
+ /** First release whose agent_launch knows fork_from (ADR 0140). */
1267
+ const FORK_MINIMUM_VERSION = "0.70.6";
1268
+ /** First release whose agent_launch takes append_system_prompt / mcp_config for codex-cli, and the first a terminal may run a Codex seat on. */
1269
+ const CODEX_REMOTE_MINIMUM_VERSION = "0.70.7";
1252
1270
  const terminalVersions = new Map();
1253
1271
  /** A seat on a BellTeam terminal (remote-terminal.md "One launch path"). Same launch arguments plus terminal + cwd. */
1254
1272
  async function launchTerminalAgent(harness, terminal, args, extra) {
1255
1273
  try {
1256
1274
  if (args.remote)
1257
1275
  throw new AitermError("TERMINAL_INVALID: use terminal or remote, not both; for a registered terminal pass only terminal", 2);
1258
- if (harness !== "claude-code")
1259
- throw new AitermError(`TERMINAL_HARNESS_UNSUPPORTED: terminal seats support harness claude-code first; ${harness} is not available on a terminal yet`, 2);
1260
- if (typeof args.cwd !== "string" || !args.cwd.startsWith("/"))
1261
- throw new AitermError("TERMINAL_INVALID: cwd is required with terminal: the absolute project folder on that terminal (never launch locally and cd)", 2);
1276
+ if (harness !== "claude-code" && harness !== "codex-cli")
1277
+ throw new AitermError(`TERMINAL_HARNESS_UNSUPPORTED: terminal seats support harnesses claude-code and codex-cli; ${harness} is not available on a terminal yet`, 2);
1278
+ // A declared Windows terminal is refused by the platform check below (0.70.8 brings its path form).
1279
+ if (typeof args.cwd !== "string" || (terminal.os !== "windows" && !args.cwd.startsWith("/")))
1280
+ throw new AitermError("TERMINAL_INVALID: cwd is required with terminal: the absolute POSIX project folder on that terminal, starting with / (never launch locally and cd)", 2);
1262
1281
  if (args.require_existing_resume)
1263
1282
  throw new AitermError("TERMINAL_INVALID: require_existing_resume is local-only", 2);
1264
1283
  const target = terminalRemoteTarget(terminal);
1284
+ await checkTerminalPlatform(target, terminal.os);
1265
1285
  // The private line is sent before the server answers; check its version first so an old one never sees it.
1266
1286
  let version = terminalVersions.get(target.trusted_ref);
1267
1287
  if (!version) {
1268
1288
  version = (await callRemoteTool(target, "pty_list", {}, 60_000)).remote_version ?? "0.0.0";
1269
1289
  terminalVersions.set(target.trusted_ref, version);
1270
1290
  }
1271
- if (!versionAtLeast(version, REMOTE_MINIMUM_VERSION))
1272
- throw new AitermError(`REMOTE_AITERM_TOO_OLD: the terminal runs Aiterm ${version}; ${REMOTE_MINIMUM_VERSION} or later is required (update Aiterm on the terminal)`, 2);
1291
+ const minimum = harness === "codex-cli" ? CODEX_REMOTE_MINIMUM_VERSION : REMOTE_MINIMUM_VERSION;
1292
+ if (!versionAtLeast(version, minimum))
1293
+ throw new AitermError(`REMOTE_AITERM_TOO_OLD: the terminal runs Aiterm ${version}; ${minimum} or later is required (update Aiterm on the terminal)`, 2);
1273
1294
  const privateEnv = {};
1274
1295
  for (const name of args.env_vars ?? []) {
1275
1296
  const value = launchEnvValue(name);
@@ -1281,6 +1302,14 @@ export function createAitermServer(options = {}) {
1281
1302
  const extracted = extractMcpHeaders(mcpConfig);
1282
1303
  Object.assign(privateEnv, extracted.env);
1283
1304
  mcpConfig = extracted.config;
1305
+ // Codex cannot say every header shape: refuse here, not on the terminal after the private line was sent.
1306
+ if (harness === "codex-cli")
1307
+ try {
1308
+ codexMcpOverrides(mcpConfig);
1309
+ }
1310
+ catch (e) {
1311
+ throw launchInputRefusal(harness, e.message);
1312
+ }
1284
1313
  const ingress = seatIngressPort(mcpConfig);
1285
1314
  if (ingress)
1286
1315
  mcpConfig = rewriteSeatMcpConfig(mcpConfig, await ensureSeatForward(target.trusted_ref, ingress));
@@ -1290,22 +1319,22 @@ export function createAitermServer(options = {}) {
1290
1319
  const session = result?.structuredContent?.session_id;
1291
1320
  if (typeof session === "string")
1292
1321
  bindTerminalSession(session, target.trusted_ref);
1293
- return withErrorCode(withTerminalLaunchAction(result));
1322
+ return withErrorCode(withTerminalLaunchAction(result, harness));
1294
1323
  }
1295
1324
  catch (e) {
1296
- return withErrorCode(withTerminalLaunchAction(fail(e)));
1325
+ return withErrorCode(withTerminalLaunchAction(fail(e), harness));
1297
1326
  }
1298
1327
  }
1299
1328
  async function launchAgent(kind, args, extra) {
1329
+ const { prompt, image, throughline_source_session, throughline_supplement_file, model, reasoning_effort, fast, env_vars, cwd, session_name, launch_operation_id, write_scope, trust_project, require_existing_resume, configuration_root, append_system_prompt, mcp_config, fork_from } = args;
1300
1330
  const supportsWriteScope = kind !== "claude";
1301
- const { prompt, image, throughline_source_session, throughline_supplement_file, model, reasoning_effort, fast, env_vars, cwd, session_name, launch_operation_id, write_scope, trust_project, require_existing_resume, configuration_root, append_system_prompt, mcp_config } = args;
1302
1331
  let delivery = null;
1303
1332
  try {
1304
1333
  if (!supportsWriteScope && write_scope !== undefined) {
1305
- throw new core.AitermError("claude-code harnessはwrite_scopeに対応していません。指定を外してください", 2);
1334
+ throw launchInputRefusal(core.agentHarness(kind), "claude-code harnessはwrite_scopeに対応していません。指定を外してください");
1306
1335
  }
1307
1336
  if (require_existing_resume && ((image?.length ?? 0) > 0 || prompt != null || throughline_source_session != null || throughline_supplement_file != null))
1308
- throw new core.AitermError("require_existing_resume is promptless", 2);
1337
+ throw launchInputRefusal(core.agentHarness(kind), "require_existing_resume is promptless");
1309
1338
  if (!require_existing_resume)
1310
1339
  await core.maintainAgentIdleClocks();
1311
1340
  const initialPrompt = image && image.length > 0 ? core.attachImages(prompt ?? "", image) : prompt ?? undefined;
@@ -1330,7 +1359,9 @@ export function createAitermServer(options = {}) {
1330
1359
  mcp_config,
1331
1360
  launch_operation_id: launch_operation_id ?? undefined,
1332
1361
  ...(supportsWriteScope ? { write_scope } : {}),
1362
+ ...(fork_from ? { fork_from } : {}),
1333
1363
  });
1364
+ const forkOf = fork_from ? loadAgentMetadata(sid).fork_of : undefined;
1334
1365
  const structured = {
1335
1366
  schema: "aiterm.agent-launch-result.v1",
1336
1367
  provider: kind,
@@ -1354,6 +1385,7 @@ export function createAitermServer(options = {}) {
1354
1385
  : "declaration_only_unsupported",
1355
1386
  }
1356
1387
  : {}),
1388
+ ...(forkOf ? { fork_of: { session_id: forkOf.session_id, vendor_session_id: forkOf.vendor_session_id, write_ban: forkOf.write_ban } } : {}),
1357
1389
  };
1358
1390
  // 開始未確認(submitted_unconfirmed)は誤りにしない。sessionは立ち、promptは入力欄を離れ、配送も登録済み。
1359
1391
  // 誤りで返すとClaude Code親は受け口のhookを走らせず、子の回答が届かない(ADR 0093)。状態はinitial_promptと本文で伝える。
@@ -1484,8 +1516,12 @@ export function createAitermServer(options = {}) {
1484
1516
  launch_operation_id: z.string().regex(/^sha256:[0-9a-f]{64}$/).optional().describe("Claude Codeのpromptなしexact replay相関だけで使用"),
1485
1517
  remote: remoteInputField,
1486
1518
  terminal: terminalArgumentSchema.optional().describe(terminalArgumentDescription),
1487
- append_system_prompt: z.string().min(1).optional().describe("claude-code only. Launch instructions added to the system prompt; kept in Aiterm state, not in the project or home. Never put secrets here"),
1488
- mcp_config: z.object({ mcpServers: z.record(z.string(), z.unknown()) }).strict().optional().describe("claude-code only. Extra MCP servers for this seat. Secret header values: write ${NAME} and list NAME in env_vars"),
1519
+ append_system_prompt: z.string().min(1).optional().describe("claude-code and codex-cli only. Launch instructions added to the system prompt (Codex: appended to developer_instructions after Aiterm's marker, at most 64 KiB); kept in Aiterm state, not in the project or home. Never put secrets here"),
1520
+ mcp_config: z.object({ mcpServers: z.record(z.string(), z.unknown()) }).strict().optional().describe("claude-code and codex-cli only. Extra MCP servers for this seat. Secret header values: write ${NAME} and list NAME in env_vars. Codex takes only http servers {type?: \"http\", url, headers}: 'Authorization: Bearer ${NAME}' or a header whose whole value is ${NAME}; other shapes are refused before the seat starts"),
1521
+ fork_from: z.object({
1522
+ session_id: z.string().regex(/^[A-Za-z0-9_-]{1,64}$/).describe("The main Aiterm seat on the same machine (the terminal or remote when given)"),
1523
+ fork_id: z.string().min(1).max(200).optional().describe("Caller's fork ID, passed to the seat as THROUGHLINE_FORK_ID"),
1524
+ }).strict().optional().describe("claude-code and codex-cli. Start a disposable fork of that seat's latest saved conversation, in its cwd, with the main's tools and MCP. Every write inside that cwd (the project folder) is refused below the tools for the whole process tree (Linux Landlock, macOS sandbox-exec); everything else is allowed. Windows answers READONLY_UNENFORCEABLE. Requires a prompt; no write_scope. Close it after its answer"),
1489
1525
  },
1490
1526
  outputSchema: {
1491
1527
  schema: z.literal("aiterm.agent-launch-result.v1"),
@@ -1507,16 +1543,18 @@ export function createAitermServer(options = {}) {
1507
1543
  fast_error: fastModeFailureSchema.nullable().optional().describe("fastを頼まれたが、通常の速度で起こした時の訳"),
1508
1544
  write_scope: z.string().optional(),
1509
1545
  write_scope_enforcement: z.enum(["enforced_read_only", "declaration_only_unsupported"]).optional(),
1546
+ fork_of: z.object({ session_id: z.string(), vendor_session_id: z.string(),
1547
+ write_ban: z.object({ path: z.string(), method: z.enum(["landlock", "seatbelt"]) }) }).optional().describe("The seat this fork copies and the folder it cannot write"),
1510
1548
  },
1511
1549
  }, async ({ harness, remote, terminal, ...args }, extra) => {
1512
- if (harness !== "claude-code" && (args.append_system_prompt !== undefined || args.mcp_config !== undefined))
1513
- return fail(new AitermError("append_system_prompt and mcp_config are claude-code only", 2));
1550
+ if (harness !== "claude-code" && harness !== "codex-cli" && (args.append_system_prompt !== undefined || args.mcp_config !== undefined))
1551
+ return fail(launchInputRefusal(harness, `append_system_prompt and mcp_config are claude-code and codex-cli only; ${harness} cannot take them`));
1514
1552
  if (terminal)
1515
1553
  return launchTerminalAgent(harness, terminal, { ...args, ...(remote ? { remote } : {}) }, extra);
1516
1554
  if (remote && args.require_existing_resume)
1517
1555
  return fail(typeof args.session_name === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(args.session_name)
1518
1556
  ? new AgentResumeUnavailableError(args.session_name)
1519
- : new AitermError("require_existing_resume requires session_name", 2));
1557
+ : launchInputRefusal(harness, "require_existing_resume requires session_name"));
1520
1558
  if (!remote)
1521
1559
  return launchAgent(kindForHarness(harness), args, extra);
1522
1560
  try {
@@ -171,7 +171,7 @@ export function signalRuntimeProcess(target, signal, group) {
171
171
  "try {",
172
172
  "[void]$target.Handle",
173
173
  `if(([DateTimeOffset]$target.StartTime.ToUniversalTime()).ToUnixTimeMilliseconds() -ne ${Date.parse(target.started_identity)}) { exit 4 }`,
174
- signal === "SIGTERM" ? "[void]$target.CloseMainWindow()" : "$target.Kill()",
174
+ signal === "SIGKILL" ? "$target.Kill()" : "[void]$target.CloseMainWindow()",
175
175
  "} finally { $target.Dispose() }",
176
176
  ].join("\n");
177
177
  const result = spawnSync(resolveWindowsPowerShell7(), ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand",
@@ -5,7 +5,9 @@ const nativeRuntime = {
5
5
  read: () => readRuntimeProcesses(true), signal: signalRuntimeProcess,
6
6
  pause: ms => new Promise(resolve => setTimeout(resolve, ms)), now: () => performance.now(),
7
7
  };
8
- /** TERM, a five-second grace, then KILL; only the original pane tree and verified groups are selected. */
8
+ /** TERM, a five-second grace, then KILL; only the original pane tree and verified groups are selected.
9
+ * An interactive shell ignores TERM, so once its children are gone and only the pane root is left it is hung up,
10
+ * as a closing terminal would. A root that started alone keeps the full grace. */
9
11
  export async function stopProcessTree(root, verify, runtime = nativeRuntime) {
10
12
  if (!Number.isSafeInteger(root.pid) || root.pid <= 1 || root.pid === process.pid)
11
13
  throw new Error("invalid_process_tree_root");
@@ -67,7 +69,7 @@ export async function stopProcessTree(root, verify, runtime = nativeRuntime) {
67
69
  terminated.add(key(member));
68
70
  }
69
71
  });
70
- let until = null;
72
+ let until = null, hungUp = false;
71
73
  for (;;) {
72
74
  const alive = refresh();
73
75
  if (alive.length === 0)
@@ -77,6 +79,10 @@ export async function stopProcessTree(root, verify, runtime = nativeRuntime) {
77
79
  for (const row of childrenFirst(alive))
78
80
  if (!terminated.has(key(row)))
79
81
  signal(row, "SIGTERM");
82
+ if (until !== null && !hungUp && tree.length > 1 && alive.length === 1 && alive[0].pid === root.pid) {
83
+ signal(alive[0], "SIGHUP");
84
+ hungUp = true;
85
+ }
80
86
  until ??= runtime.now() + 5000;
81
87
  await runtime.pause(Math.min(100, Math.max(0, until - runtime.now())));
82
88
  }
@@ -27,6 +27,8 @@ export const credentialHandleSchema = z.object({
27
27
  handle: z.string().uuid("credential.handle must be the handle (UUID) the terminal registry gave, unchanged"),
28
28
  revision: z.number().int().positive("credential.revision must be the handle's positive integer revision, unchanged").max(Number.MAX_SAFE_INTEGER),
29
29
  }).strict();
30
+ /** The terminal's operating system as BellTeam registers it; Aiterm compares it with what the terminal really is (R20). */
31
+ export const terminalOsSchema = z.enum(["macos", "linux", "windows"]);
30
32
  /** The launch tools' terminal target (remote-terminal.md "One launch path"). Copied unchanged from BellTeam terminals. */
31
33
  export const terminalArgumentSchema = z.object({
32
34
  ref: z.string().uuid("terminal.ref must be the binding ref (UUID) the terminal registry gave for this terminal"),
@@ -35,6 +37,7 @@ export const terminalArgumentSchema = z.object({
35
37
  user: z.string().min(1, "terminal.target.user is required"),
36
38
  port: z.number().int().min(1).max(65535),
37
39
  }).strict(),
40
+ os: terminalOsSchema.optional(),
38
41
  trustRevision: revision("trustRevision"),
39
42
  credentialRevision: revision("credentialRevision").optional(),
40
43
  credential: credentialHandleSchema.optional(),
@@ -45,8 +48,8 @@ export const terminalArgumentSchema = z.object({
45
48
  message: "terminal needs exactly one key source: credential {handle, revision} from the registry, or credentialRevision for a native key" });
46
49
  });
47
50
  export const terminalArgumentDescription = "Run this seat on another computer (a registered terminal) over SSH. Value: exactly the terminal value your host system's terminal registry hands over, " +
48
- "{ref, target:{host,user,port}, trustRevision, and credentialRevision or credential {handle, revision}}; copy it unchanged, never invent or edit it, never use a host name or ssh command instead. " +
49
- "Omit it to launch on this computer. Give cwd in the same call: the absolute project folder on that terminal. Never launch locally and then cd or ssh. " +
51
+ "{ref, target:{host,user,port}, os?, trustRevision, and credentialRevision or credential {handle, revision}}; copy it unchanged, never invent or edit it, never use a host name or ssh command instead. " +
52
+ "Omit it to launch on this computer. Give cwd in the same call: the absolute project folder on that terminal (a POSIX path starting with /). Never launch locally and then cd or ssh. " +
50
53
  "Never put tokens, passwords or other secrets in any argument, prompt or typed text; pass secret values only by name in env_vars. " +
51
54
  "After launch, use session_id alone for pty_send, pty_observe, pty_read, pty_key, claude_turn, agent_stop and pty_close; Aiterm routes them to the terminal. " +
52
55
  "Errors and next step: TERMINAL_INVALID = malformed value, missing/relative cwd, or combined with remote: pass the registry's value unchanged with cwd. " +
@@ -56,4 +59,6 @@ export const terminalArgumentDescription = "Run this seat on another computer (a
56
59
  "CREDENTIAL_REQUIRED / CREDENTIAL_NOT_LOADED = this terminal's key comes from a credential handle that the registry must load first; never paste a key anywhere. " +
57
60
  "AUTH_FAILED = the terminal refused the key. UNREACHABLE = the terminal is offline; try later. CONNECTION_REFUSED = the terminal refused the SSH connection (SSH may be off there); try later. " +
58
61
  "REMOTE_AITERM_TOO_OLD = update Aiterm on the terminal. CWD_UNAVAILABLE = the folder does not exist there; do not pick another folder. " +
59
- "SEAT_FORWARD_UNAVAILABLE = the seat's MCP route back to this computer is not ready (launch again later), or the seat MCP URLs are not http://127.0.0.1:<one port>/api/seat-mcp. TERMINAL_HARNESS_UNSUPPORTED = use harness claude-code.";
62
+ "SEAT_FORWARD_UNAVAILABLE = the seat's MCP route back to this computer is not ready (launch again later), or the seat MCP URLs are not http://127.0.0.1:<one port>/api/seat-mcp. TERMINAL_HARNESS_UNSUPPORTED = use harness claude-code or codex-cli (codex-cli needs Aiterm 0.70.7 on the terminal). " +
63
+ "TERMINAL_OS_MISMATCH = the terminal is not the operating system os says: the registry's os is wrong or the binding points at another machine; ask the terminal registry, do not retry. " +
64
+ "TERMINAL_PLATFORM_UNSUPPORTED = Windows (and any system that is not macOS or Linux) cannot run seats yet.";
@@ -1,4 +1,4 @@
1
- // provision (remote-terminal.md R16): install this Aiterm version as a product-owned runtime on a macOS terminal,
1
+ // provision (remote-terminal.md R16): install this Aiterm version as a product-owned runtime on a macOS or Linux terminal,
2
2
  // before any terminal MCP exists. Runs over the binding's trusted key SSH; the terminal fetches the release assets.
3
3
  import { spawn, spawnSync } from "node:child_process";
4
4
  import { createRequire } from "node:module";
@@ -11,13 +11,28 @@ export const RUNTIME_RELEASE_BASE = "https://github.com/kitepon/aiterm-mcp/relea
11
11
  export const PROVISION_SCRIPT = String.raw `set -u
12
12
  V="$1"; BASE="$2"
13
13
  fail() { echo "AITERM_PROVISION_ERROR $1"; exit 3; }
14
- [ "$(uname -s)" = Darwin ] || fail PROVISION_PLATFORM_UNSUPPORTED
15
- case "$(uname -m)" in
16
- arm64) A=arm64 ;;
17
- x86_64) if [ "$(sysctl -in hw.optional.arm64 2>/dev/null)" = 1 ]; then A=arm64; else A=x64; fi ;;
14
+ case "$(uname -s)" in
15
+ Darwin)
16
+ OS=darwin
17
+ case "$(uname -m)" in
18
+ arm64) A=arm64 ;;
19
+ x86_64) if [ "$(sysctl -in hw.optional.arm64 2>/dev/null)" = 1 ]; then A=arm64; else A=x64; fi ;;
20
+ *) fail PROVISION_PLATFORM_UNSUPPORTED ;;
21
+ esac ;;
22
+ Linux)
23
+ OS=linux
24
+ case "$(uname -m)" in
25
+ x86_64) A=x64 ;;
26
+ aarch64|arm64) A=arm64 ;;
27
+ *) fail PROVISION_PLATFORM_UNSUPPORTED ;;
28
+ esac
29
+ # The Linux runtime has no tmux: seats use the user's own. Look on the login PATH, as the later remote commands do.
30
+ s=$(printenv SHELL); [ -x "$s" ] || s=/bin/sh
31
+ p=$("$s" -lc env </dev/null 2>/dev/null | sed -n 's/^PATH=//p' | tail -n 1); [ -n "$p" ] && PATH=$p; export PATH
32
+ command -v tmux >/dev/null 2>&1 || fail PROVISION_TMUX_MISSING ;;
18
33
  *) fail PROVISION_PLATFORM_UNSUPPORTED ;;
19
34
  esac
20
- NAME="aiterm-runtime-$V-darwin-$A"
35
+ NAME="aiterm-runtime-$V-$OS-$A"
21
36
  ROOT="$HOME/.aiterm/runtime"
22
37
  mkdir -p "$ROOT" 2>/dev/null && chmod 700 "$HOME/.aiterm" "$ROOT" 2>/dev/null || fail RUNTIME_DIR_UNAVAILABLE
23
38
  smoke() { "$1/bin/aiterm-remote-terminal" runtime-smoke --expect-version "$V" >/dev/null 2>&1 </dev/null; }
@@ -86,7 +101,7 @@ export async function provision(ref, version = pkg.version) {
86
101
  if (parsed && "result" in parsed && run.code === 0)
87
102
  return { schema: "aiterm.remote-provision.v1", ref, result: parsed.result, version: parsed.version };
88
103
  if (parsed && "code" in parsed)
89
- throw new RemoteTerminalError(parsed.code, `provisioning the terminal failed (${parsed.code})`);
104
+ throw new RemoteTerminalError(parsed.code, `provisioning the terminal failed (${parsed.code})`, parsed.code === "PROVISION_TMUX_MISSING" ? "install tmux with the terminal's package manager (for example apt install tmux), then provision again" : undefined);
90
105
  if (run.code === 255) {
91
106
  const f = classifySshFailure(run.stderr);
92
107
  throw new RemoteTerminalError(f.code, f.message, f.action);
@@ -98,6 +113,9 @@ export async function runtimeSmoke(expectVersion) {
98
113
  if (pkg.version !== expectVersion)
99
114
  throw new RemoteTerminalError("RUNTIME_SMOKE_FAILED", `runtime is ${pkg.version}, expected ${expectVersion}`);
100
115
  const tmux = spawnSync("tmux", ["-V"], { encoding: "utf8", timeout: 10_000 });
116
+ // The Linux runtime carries no tmux; its absence is the user's to fix.
117
+ if (process.platform === "linux" && tmux.error?.code === "ENOENT")
118
+ throw new RemoteTerminalError("PROVISION_TMUX_MISSING", "tmux is not installed on the terminal", "install tmux with the terminal's package manager, then provision again");
101
119
  if (tmux.status !== 0)
102
120
  throw new RemoteTerminalError("RUNTIME_SMOKE_FAILED", "tmux does not run");
103
121
  await verifySetupRuntime({ command: process.execPath, args: [fileURLToPath(new URL("./index.js", import.meta.url))] });
@@ -4,7 +4,7 @@
4
4
  // serve stdio MCP for one bound connection, spawned by BellTeam terminals
5
5
  // credential-load --ref R --terminal-id ID --handle UUID --revision N --purpose ssh-key (key bytes on stdin; one JSON receipt line)
6
6
  // transcript-read --session S [--cursor-session ID --offset N] [--max-bytes N] (runs on the terminal)
7
- // authorize-key --ref R (login password on stdin until EOF; R14) provision --ref R (macOS runtime; R16)
7
+ // authorize-key --ref R (login password on stdin until EOF; R14) provision --ref R (macOS/Linux runtime; R16)
8
8
  // path-status|make-dir --path P | --path-base64 B, list-dirs [--path P | --path-base64 B] (on the terminal; R15) runtime-smoke --expect-version V (on the terminal)
9
9
  import { realpathSync } from "node:fs";
10
10
  import { fileURLToPath } from "node:url";
@@ -14,7 +14,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
14
14
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
15
15
  import { REMOTE_COMMAND_OPS, RemoteTerminalConnection, RemoteTerminalError, bindingStatus, confirmHostKey, loadCredential, registerBinding } from "./remote-terminal.js";
16
16
  import { readCompletedTranscript } from "./transcript-read.js";
17
- import { credentialHandleSchema } from "./remote-contract.js";
17
+ import { credentialHandleSchema, terminalOsSchema } from "./remote-contract.js";
18
18
  import { inspectPath, listDirectories, makeDirectory } from "./remote-path.js";
19
19
  import { ASKPASS_SOCKET_ENV, askpass, authorizeKey, prepareAuthorization } from "./remote-authorize.js";
20
20
  import { provision, runtimeSmoke } from "./remote-provision.js";
@@ -67,7 +67,7 @@ function serve() {
67
67
  server.registerTool("remote_terminal_status", { description: "Public status of a terminal binding", inputSchema: { ref: z.string() } }, guarded(({ ref }) => bindingStatus(ref)));
68
68
  server.registerTool("remote_terminal_open", {
69
69
  description: "Open the bound connection for this process",
70
- inputSchema: { ref: z.string(), target: z.object({ host: z.string(), user: z.string(), port: z.number().int() }).strict(),
70
+ inputSchema: { ref: z.string(), target: z.object({ host: z.string(), user: z.string(), port: z.number().int() }).strict(), os: terminalOsSchema.optional(),
71
71
  trustRevision: z.string(), credentialRevision: z.string().optional(), credential: credentialHandleSchema.optional(),
72
72
  sudoCredential: credentialHandleSchema.optional(), privateEnv: z.record(z.string(), z.string()).optional() },
73
73
  }, guarded(async (args) => {
@@ -77,7 +77,7 @@ function serve() {
77
77
  connection.on("event", event => {
78
78
  server.server.notification({ method: "aiterm/remote-terminal-event", params: event }).catch(() => { });
79
79
  });
80
- return { opened: true, remoteVersion: connection.remoteVersion };
80
+ return { opened: true, remoteVersion: connection.remoteVersion, platform: connection.platform };
81
81
  }));
82
82
  server.registerTool("remote_terminal_call", {
83
83
  description: "Call a seat tool on the terminal's Aiterm",
@@ -10,7 +10,7 @@ import { createRequire } from "node:module";
10
10
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
11
11
  import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
12
12
  import { ensureStateRoot, writeJson0600 } from "./agent-shared.js";
13
- import { posixCommand } from "./remote.js";
13
+ import { posixCommand, remotePlatform } from "./remote.js";
14
14
  import { PRIVATE_ENV_SCHEMA } from "./private-env.js";
15
15
  import { checkRemotePath } from "./remote-path.js";
16
16
  const pkg = createRequire(import.meta.url)("../package.json");
@@ -305,8 +305,9 @@ export class RemoteTerminalConnection extends EventEmitter {
305
305
  identity;
306
306
  client;
307
307
  remoteVersion;
308
+ platform;
308
309
  closing = false;
309
- constructor(b, dir, agent, socket, identity, client, remoteVersion) {
310
+ constructor(b, dir, agent, socket, identity, client, remoteVersion, platform) {
310
311
  super();
311
312
  this.b = b;
312
313
  this.dir = dir;
@@ -315,6 +316,7 @@ export class RemoteTerminalConnection extends EventEmitter {
315
316
  this.identity = identity;
316
317
  this.client = client;
317
318
  this.remoteVersion = remoteVersion;
319
+ this.platform = platform;
318
320
  }
319
321
  static async open(input) {
320
322
  const target = validTarget(input.target);
@@ -330,6 +332,8 @@ export class RemoteTerminalConnection extends EventEmitter {
330
332
  for (const [name, value] of Object.entries(input.privateEnv ?? {}))
331
333
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || typeof value !== "string")
332
334
  throw new RemoteTerminalError("PRIVATE_ENV_INVALID", "invalid private env entry");
335
+ // R20: the connect command is shell-specific, so the platform is known (and the declared os checked) before any MCP connection.
336
+ const platform = await checkTerminalPlatform(trustedTarget(b), input.os);
333
337
  // Short path: the agent socket must fit macOS's 104-byte sun_path.
334
338
  const dir = fs.mkdtempSync(path.join(os.platform() === "win32" ? os.tmpdir() : "/tmp", "aiterm-rt-"));
335
339
  fs.chmodSync(dir, 0o700);
@@ -375,7 +379,7 @@ export class RemoteTerminalConnection extends EventEmitter {
375
379
  await client.close().catch(() => { });
376
380
  throw new RemoteTerminalError("REMOTE_AITERM_TOO_OLD", `the terminal runs Aiterm ${remoteVersion}; ${REMOTE_MINIMUM_VERSION} or later is required`);
377
381
  }
378
- const connection = new RemoteTerminalConnection(b, dir, agent, agentSocket, identity, client, remoteVersion);
382
+ const connection = new RemoteTerminalConnection(b, dir, agent, agentSocket, identity, client, remoteVersion, platform);
379
383
  client.onclose = () => connection.ended();
380
384
  // After the caller has attached its listener to the returned connection.
381
385
  setImmediate(() => connection.emit("event", { type: "ready", at: new Date().toISOString(), remoteVersion }));
@@ -486,7 +490,8 @@ export class RemoteTerminalConnection extends EventEmitter {
486
490
  const f = classifySshFailure(run.stderr);
487
491
  throw new RemoteTerminalError(f.code, f.message, f.action);
488
492
  }
489
- const probe = op === "claude_version" ? run : await this.exec("claude --version 2>&1", 60_000);
493
+ // The official installer puts claude in ~/.local/bin, which a login shell may not have on PATH yet (Linux).
494
+ const probe = op === "claude_version" ? run : await this.exec('claude --version 2>&1 || "$HOME/.local/bin/claude" --version 2>&1', 60_000);
490
495
  const version = probe.code === 0 ? (/\d+\.\d+\.\d+\S*/.exec(probe.stdout)?.[0] ?? null) : null;
491
496
  return { op, exit_code: run.code, version, output_tail: run.stdout.slice(-2000) };
492
497
  }
@@ -565,6 +570,17 @@ function checkKeySource(ref, status, input) {
565
570
  throw new RemoteTerminalError("CREDENTIAL_REVISION_STALE", "the key changed; get the current value from the terminal registry and launch again");
566
571
  }
567
572
  const trustedTarget = (b) => ({ host: b.target.host, user: b.target.user, port: b.target.port, trusted_ref: b.ref });
573
+ /** R20/T4: the terminal's real platform; macOS and Linux pass. A declared os that differs is a wrong target, Windows comes in 0.70.8. */
574
+ export async function checkTerminalPlatform(target, declared) {
575
+ const actual = await remotePlatform(target);
576
+ if (actual === null)
577
+ throw new RemoteTerminalError("TERMINAL_PLATFORM_UNSUPPORTED", "the terminal is not a macOS, Linux or Windows system (the platform probe printed nothing recognisable)");
578
+ if (declared !== undefined && declared !== actual)
579
+ throw new RemoteTerminalError("TERMINAL_OS_MISMATCH", `the terminal is registered as ${declared} but runs ${actual}; correct the terminal's os or register the right machine`);
580
+ if (actual === "windows")
581
+ throw new RemoteTerminalError("TERMINAL_PLATFORM_UNSUPPORTED", "Windows terminals are not supported before Aiterm 0.70.8");
582
+ return actual;
583
+ }
568
584
  /** T1: the binding exists, the target is the binding's, both revisions are current. */
569
585
  export function terminalRemoteTarget(input) {
570
586
  const b = binding(input.ref);
package/dist/remote.js CHANGED
@@ -11,7 +11,7 @@ import { AitermError, observeAgentDone, readAgentTranscriptResult, windowsStartP
11
11
  import { ensureStateRoot, stateRoot } from "./agent-shared.js";
12
12
  import { currentUid } from "./state-root.js";
13
13
  import { PRIVATE_ENV_SCHEMA } from "./private-env.js";
14
- import { SshStdioTransport, classifySshFailure, trustedSshArguments } from "./remote-terminal.js";
14
+ import { RemoteTerminalError, SshStdioTransport, classifySshFailure, trustedSshArguments } from "./remote-terminal.js";
15
15
  const pkg = createRequire(import.meta.url)("../package.json");
16
16
  export { remoteTargetSchema, remoteInputSchema, remoteInputDescription } from "./remote-contract.js";
17
17
  // 平文で受け取ったパスフレーズは、このMCP processのメモリにだけ置く。ControlMasterが落ちた後の再接続に使う。
@@ -132,6 +132,43 @@ export function remoteShell(target) {
132
132
  }
133
133
  return shell;
134
134
  }
135
+ // 上のshell判定に続けて`uname -s`を流す。POSIX系は最後の行がDarwin/Linux。cmdは行全体が1つのechoになり、PowerShellでは`uname`が無く何も出ない。
136
+ export const REMOTE_PLATFORM_PROBE = `${REMOTE_SHELL_PROBE}; uname -s`;
137
+ /** probeの出力からOSを決める。Windows・macOS・Linuxのどれとも言えない出力はnull(推測しない)。 */
138
+ export function classifyRemotePlatform(output) {
139
+ const shell = classifyRemoteShell(output);
140
+ if (shell === "cmd")
141
+ return "windows";
142
+ const last = output.trim().split(/\r?\n/).pop()?.trim();
143
+ if (last === "Darwin")
144
+ return "macos";
145
+ if (last === "Linux")
146
+ return "linux";
147
+ // POSIX系のprobe行は`aiterm-probe %OS%`で1行目が終わる(unameの行が付くので、classifyRemoteShellはPowerShellと数える)。それ以外のDarwin/Linuxでない出力は未知のOS。
148
+ return shell === "powershell" && output.trim().split(/\r?\n/)[0].trim() !== "aiterm-probe %OS%" ? "windows" : null;
149
+ }
150
+ const platforms = new Map();
151
+ /** 端末のOSを1回だけ調べて、このprocessの間 接続先ごとに覚える。 */
152
+ export function remotePlatform(target) {
153
+ const key = remoteKey(target);
154
+ let platform = platforms.get(key);
155
+ if (!platform) {
156
+ platform = runSsh(target, REMOTE_PLATFORM_PROBE).then(({ code, stdout, stderr }) => {
157
+ if (code === 255) {
158
+ if (target.trusted_ref) {
159
+ const failure = classifySshFailure(stderr);
160
+ throw new RemoteTerminalError(failure.code, failure.message, failure.action);
161
+ }
162
+ const detail = stderr.trim().split("\n").slice(-3).join(" / ") || "exit 255";
163
+ throw new AitermError(`REMOTE_CONNECT_FAILED: ${remoteLabel(target)} へ接続できません(${detail})`, 2);
164
+ }
165
+ return classifyRemotePlatform(stdout);
166
+ });
167
+ platform.catch(() => platforms.delete(key));
168
+ platforms.set(key, platform);
169
+ }
170
+ return platform;
171
+ }
135
172
  // POSIX系の非ログイン実行では、~/.local/bin、Homebrew、nvmなどのPATHが入らない端末がある。
136
173
  // 利用者のログインshellからPATHだけを受け取り、処理は/bin/shで行う。profileの出力やfish等の文法差を
137
174
  // MCPのstdoutと処理へ持ち込まない。scriptは呼び出し側で検証済みの値だけで組み、単引用符を含めない。
@@ -3,7 +3,9 @@
3
3
  const ACTIONS = {
4
4
  TERMINAL_INVALID: "起動の指定(端末の情報か作業フォルダ)が正しくありません。BellTeamの不具合の恐れがあります。",
5
5
  TARGET_INVALID: "起動の指定(端末の情報)が正しくありません。BellTeamの不具合の恐れがあります。",
6
- TERMINAL_HARNESS_UNSUPPORTED: "この端末で起こせるAIは、今はClaude Codeだけです。メンバーのAIをClaude Codeにしてください。",
6
+ TERMINAL_OS_MISMATCH: "端末のOSが、登録されているOSと違います。別の機械を指している恐れがあり止めました。端末の登録(OS)を確かめてください。",
7
+ TERMINAL_PLATFORM_UNSUPPORTED: "この端末のOS(Windowsなど)では、まだ席を起こせません。MacかLinuxの端末を使ってください。",
8
+ TERMINAL_HARNESS_UNSUPPORTED: "この端末で起こせるAIは、今はClaude CodeとCodexだけです。メンバーのAIをClaude CodeかCodexにしてください。",
7
9
  REF_INVALID: "端末の登録が見つかりません。端末の登録を確かめてください。",
8
10
  BINDING_UNKNOWN: "端末の登録が見つかりません。端末の登録を確かめてください。",
9
11
  BINDING_STORE_UNREADABLE: "端末の登録を読めませんでした。端末の登録をやり直してください。",
@@ -17,7 +19,7 @@ const ACTIONS = {
17
19
  CREDENTIAL_REVISION_STALE: "端末へ入る鍵が新しくなりました。新しい鍵で起こし直します。",
18
20
  CREDENTIAL_UNAVAILABLE: "端末へ入る鍵を使えません。端末の登録で鍵を確かめてください。",
19
21
  AUTH_FAILED: "端末が鍵を受け付けませんでした。端末の登録から、パスワードで鍵を許可し直してください。",
20
- CONNECTION_REFUSED: "端末がSSHの接続を断りました。Macなら「リモートログイン」が入になっているか確かめてください。",
22
+ CONNECTION_REFUSED: "端末がSSHの接続を断りました。端末のSSHサーバーが入になっているか確かめてください(Macは「リモートログイン」、Linuxはsshdの起動)。",
21
23
  UNREACHABLE: "端末につながりません。電源とネットワークを確かめてください。つながれば起こし直します。",
22
24
  CONNECTION_FAILED: "端末へのSSH接続に失敗しました。端末の電源とSSHの設定を確かめてください。",
23
25
  REMOTE_AITERM_UNAVAILABLE: "端末にAitermが入っていません。端末の準備(Aitermの導入)をやり直してください。",
@@ -39,11 +41,13 @@ export function terminalLaunchAction(code) {
39
41
  export const LAUNCH_ERROR_META = "aiterm/launch_error";
40
42
  export const ERROR_CODE_META = "aiterm/error_code";
41
43
  /** R18 for a local launch: the fresh native creation left no seat (core.freshLaunchFailure). */
42
- export function launchNotStartedMeta(harness) {
44
+ export function launchNotStartedMeta(harness, phase = "native_create") {
43
45
  const code = "AGENT_LAUNCH_NOT_STARTED";
44
- return { [LAUNCH_ERROR_META]: { schema: "aiterm.agent-launch-error.v1", harness, code, phase: "native_create",
45
- effect: "not_started", session_created: false, action: ACTIONS[code] } };
46
+ return { [LAUNCH_ERROR_META]: { schema: "aiterm.agent-launch-error.v1", harness, code, phase,
47
+ effect: "not_started", session_created: false, action: phase === "input" ? INPUT_ACTION : ACTIONS[code] } };
46
48
  }
49
+ // phase "input": refused from the arguments alone; nothing was started, so launching again unchanged fails the same way.
50
+ const INPUT_ACTION = "起動の指定(追加の指示かMCPの設定)をこのAIでは使えません。席は作られていません。指定を見直してください。";
47
51
  /** R19: the leading symbolic code of a refused call, so the caller does not parse text. It claims no effect. */
48
52
  export function withErrorCode(result) {
49
53
  if (!result?.isError)
@@ -54,8 +58,8 @@ export function withErrorCode(result) {
54
58
  /** Adds R18's `_meta` to a failed terminal launch result; a result whose code is not listed is returned unchanged.
55
59
  * `_meta`, not structuredContent: SDK clients that listed the tools validate structuredContent against the
56
60
  * success outputSchema even on isError, and would turn this refusal into a protocol error. */
57
- export function withTerminalLaunchAction(result) {
58
- if (!result?.isError)
61
+ export function withTerminalLaunchAction(result, harness = "claude-code") {
62
+ if (!result?.isError || result._meta?.[LAUNCH_ERROR_META])
59
63
  return result;
60
64
  const structured = result.structuredContent;
61
65
  const preflight = structured?.schema === "aiterm.agent-launch-error.v1";
@@ -67,6 +71,6 @@ export function withTerminalLaunchAction(result) {
67
71
  return result;
68
72
  const failure = preflight
69
73
  ? { schema: structured.schema, harness: structured.harness, code, phase: structured.phase, effect: structured.effect, session_created: false, action }
70
- : { schema: "aiterm.agent-launch-error.v1", harness: "claude-code", code, phase: "terminal", effect: "not_started", session_created: false, action };
74
+ : { schema: "aiterm.agent-launch-error.v1", harness, code, phase: "terminal", effect: "not_started", session_created: false, action };
71
75
  return { ...result, _meta: { ...result._meta, [LAUNCH_ERROR_META]: failure } };
72
76
  }