aiterm-mcp 0.70.8 → 0.70.10
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 +16 -1
- package/README.ja.md +3 -1
- package/README.md +3 -1
- package/dist/agent-metadata-reader.js +9 -1
- package/dist/agent-screen-observation.js +2 -0
- package/dist/core.js +49 -15
- package/dist/errors.js +6 -0
- package/dist/harnesses/antigravity.js +48 -3
- package/dist/harnesses/caller-mcp.js +94 -0
- package/dist/harnesses/codex.js +31 -22
- package/dist/harnesses/cursor.js +50 -5
- package/dist/harnesses/grok.js +52 -3
- package/dist/index.js +35 -17
- package/dist/managed-seat-turn.js +6 -3
- package/dist/mcp-http-bridge.js +47 -0
- package/dist/remote-contract.js +1 -1
- package/dist/remote-terminal-cli.js +3 -3
- package/dist/remote-terminal.js +95 -17
- package/dist/terminal-launch-error.js +9 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.70.10] - 2026-11-10
|
|
11
|
+
|
|
12
|
+
- Claude seats that compacted while idle no longer read as `turn: null` until their next turn. Claude's idle compaction shows a busy spinner and sends no Stop; the `⏺ Compacted while idle` notice above the composer now ends the span that spinner opened, and the row settles to `{state: "idle"}`.
|
|
13
|
+
- `pty_list` seat turns (caller opt-in): a seat whose span another live reader holds at that instant is listed in `unread` (the caller keeps its last state) instead of a row with `turn: null`. A terminal's own `unread` is relayed for its bound sessions, and overlapping callers share one in-flight relay per terminal instead of starting one reader on the terminal each.
|
|
14
|
+
- Codex seats whose `~/.codex/config.toml` already has a stdio MCP server with the same name as an `mcp_config` server (for example `call-bridge`) now start instead of `AGENT_LAUNCH_NOT_STARTED: CODEX_MCP_SERVER_CONFLICT`. For that seat only, Aiterm takes over the user's entry with its own stdio relay (`dist/mcp-http-bridge.js`), which forwards every MCP message to the seat's http server with the seat's headers; the tool names keep the server name and the user's config.toml is not written. `CODEX_MCP_SERVER_CONFLICT` is gone.
|
|
15
|
+
|
|
16
|
+
## [0.70.9] - 2026-11-10
|
|
17
|
+
|
|
18
|
+
- All five harnesses can run on a terminal. `agent_launch` (and the per-harness launchers) with `terminal` now accepts `grok-cli`, `cursor-cli` and `antigravity-cli` beside `claude-code` and `codex-cli`, routed to the terminal's `agent_launch` the same way, with the seat-forward URL rewrite and header extraction unchanged. These three need Aiterm 0.70.9 on the terminal (`REMOTE_AITERM_TOO_OLD` before any private value is sent). `TERMINAL_HARNESS_UNSUPPORTED` stays only as a guard for a name outside the five.
|
|
19
|
+
- `remote_terminal_command` gains `cli_version`, `cli_install`, `cli_update` and `cli_auth_status`, each with a required `harness` (`claude-code`, `codex-cli`, `grok-cli`, `cursor-cli`, `antigravity-cli`; a missing or unknown one is `COMMAND_INVALID`; a terminal older than 0.70.9 is `REMOTE_AITERM_TOO_OLD`). The first three answer `{op, harness, exit_code, version, output_tail}` with each CLI's official installer and updater (Windows: PowerShell). `cli_auth_status` answers `{op, harness, logged_in}` and nothing else, from the same status commands Aiterm uses locally; an answer that is not clearly logged in or out is `AUTH_STATUS_UNCONFIRMED`, a missing CLI `CLI_NOT_INSTALLED`. `claude_version`, `claude_install` and `claude_update` stay as aliases for `claude-code` (their version is now also read from `~/.local/bin/claude` when it is not on PATH).
|
|
20
|
+
- A launch of a CLI that is not logged in is `AGENT_LAUNCH_NOT_STARTED` with `_meta["aiterm/launch_error"]` `code: "AGENT_AUTH_REQUIRED"` (`phase: "input"`, `effect: "not_started"`, `session_created: false`, `harness`) for Claude Code, Cursor and Antigravity, locally and on a terminal; Claude keeps its `CLAUDE_AUTH_NOT_AUTHENTICATED` structured answer beside it. Codex and Grok have no launch preflight.
|
|
21
|
+
- `agent_launch` accepts `append_system_prompt` and `mcp_config` for grok-cli, cursor-cli and antigravity-cli too (same shapes as claude-code and codex-cli: http servers `{type?: "http", url, headers}`, headers literal, a whole `${NAME}` or `Bearer ${NAME}`). Nothing is written to the project or to `~/.grok`, `~/.cursor`, `~/.gemini`: the files are 0600 (folders 0700) in Aiterm's launch state and are removed with the seat. Grok: the text is appended to the one `--rules` value after Aiterm's lineage text; the servers are a per-seat agent file passed as `--agent` (frontmatter `mcpServers:` list, empty body, so the default agent stays; Grok does not expand `${VAR}` in headers, so `Bearer ${NAME}` becomes `bearer_token_env_var` and any other `${NAME}` is resolved from the seat env into the 0600 file). Cursor: no system-prompt channel, so the text joins Aiterm's first-prompt block; the servers are a per-seat plugin folder passed as `--plugin-dir` (`${env:NAME}` references; the server runs as `plugin-aiterm-caller-<name>` beside a same-name user server). Antigravity: the servers are `<seat folder>/.agents/mcp_config.json` (values resolved, 0600) passed as `--add-dir`, with `trustedWorkspaces` added to `--settings`; the text prefixes the first prompt, so `append_system_prompt` needs a prompt. A shape a harness cannot say, or a `${NAME}` with no value at launch, is refused before the seat starts (`AGENT_LAUNCH_NOT_STARTED`, phase `input`).
|
|
22
|
+
|
|
10
23
|
## [0.70.8] - 2026-11-10
|
|
11
24
|
|
|
12
25
|
- Windows forks (x64): `agent_launch.fork_from` now starts the fork with every write inside the project folder refused instead of answering `READONLY_UNENFORCEABLE`. A bundled helper (`native/write-ban/win32-x64/aiterm-write-ban.exe`, about 24 KB, built reproducibly with the Linux ones) runs the CLI under a restricted copy of the user's token with no privileges and an Aiterm marker SID. The project folder carries, once, an inheritable Deny ACE for that marker SID (plus OWNER RIGHTS = READ_CONTROL and WRITE_DAC, so the DACL cannot be rewritten). The ACEs affect no other process, so the main seat writes as before and nothing is cleaned up later. npm shims run through `pwsh -File`. Measured on fox: new file, append, delete, rename, attributes, Set-Acl, icacls, takeown, git and cmd redirects inside were refused; writes outside succeeded. `fork_of.write_ban.method` is `restricted-token`.
|
|
@@ -3221,7 +3234,9 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3221
3234
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3222
3235
|
provenance.
|
|
3223
3236
|
|
|
3224
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.
|
|
3237
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.10...HEAD
|
|
3238
|
+
[0.70.10]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.9...v0.70.10
|
|
3239
|
+
[0.70.9]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.8...v0.70.9
|
|
3225
3240
|
[0.70.8]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.7...v0.70.8
|
|
3226
3241
|
[0.70.7]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.6...v0.70.7
|
|
3227
3242
|
[0.70.6]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.5...v0.70.6
|
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.
|
|
218
|
+
**状態:** 開発継続中 · 現行公開版 **v0.70.10** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
219
219
|
|
|
220
220
|
### 更新と巻き戻し
|
|
221
221
|
|
|
@@ -762,6 +762,8 @@ Claudeをリンク経由の`cwd`から起動した場合も、実体パスに対
|
|
|
762
762
|
|
|
763
763
|
Claudeの認証事前確認による起動拒否は従来のエラー文を保ち、`structuredContent`へ`schema:"aiterm.agent-launch-error.v1"`、`harness:"claude-code"`、`phase:"authentication_preflight"`、`effect:"not_issued"`、`session_created:false`を返す。`code`は`CLAUDE_AUTH_NOT_AUTHENTICATED`(公式statusが未認証)、`CLAUDE_AUTH_STATUS_UNCONFIRMED`(確認不能)を区別する。確認が5秒で終わらない時は拒否せず起動へ進み、未ログインならlogin画面で`vendor_onboarding_required`として止まる。`CLAUDE_AUTH_STATUS_TIMEOUT`は0.70.1より前の端末だけが返す。資格情報の故障原因やログイン期限切れは断定せず、公式status本文・stderrは返さない。
|
|
764
764
|
|
|
765
|
+
ログインしていないと確かめられたCLIは、起動前確認のあるClaude Code・Cursor・Antigravityで同じ形で起動を断る。`_meta["aiterm/launch_error"]`が`code:"AGENT_AUTH_REQUIRED"`・`phase:"input"`・`effect:"not_started"`・`session_created:false`・`harness`を持つ(本文は`AGENT_LAUNCH_NOT_STARTED: AGENT_AUTH_REQUIRED: ...`。Claudeは従来の本文と`structuredContent`も残す)。CodexとGrokには起動前確認が無く、各CLIのログイン画面で止まる。状態を読めなかった場合はこのcodeにしない。
|
|
766
|
+
|
|
765
767
|
### 別端末のagentを1回で起動する(`remote`)
|
|
766
768
|
|
|
767
769
|
`agent_launch`に`remote`を付けると、SSHで入った別端末のAitermで同じ起動を行う。端末へ入る操作と現地のagentを起動する操作が1回で済み、親から見た完了の届き方はこの端末の子と同じになる。Linux・macOS・Windowsの端末へ同じ依頼を並行して投げる用途を想定している。
|
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.
|
|
230
|
+
**Status:** actively maintained · current public release **v0.70.10** · 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
|
|
|
@@ -772,6 +772,8 @@ The selected harness CLI must be installed and authenticated. Use each product o
|
|
|
772
772
|
|
|
773
773
|
Claude authentication preflight refusals retain the existing error text and add `structuredContent` with schema `aiterm.agent-launch-error.v1`, `harness:"claude-code"`, `phase:"authentication_preflight"`, `effect:"not_issued"`, and `session_created:false`. `code` distinguishes `CLAUDE_AUTH_NOT_AUTHENTICATED` and `CLAUDE_AUTH_STATUS_UNCONFIRMED`. A status check that does not finish in 5 seconds no longer refuses: the launch goes on, and a logged-out Claude stops at its login screen as `vendor_onboarding_required`. `CLAUDE_AUTH_STATUS_TIMEOUT` comes only from terminals older than 0.70.1. These describe the official status check, not the cause of a credential failure or a confirmed login expiry. Native status bodies and stderr are omitted.
|
|
774
774
|
|
|
775
|
+
A CLI that is positively not logged in refuses the launch the same way for Claude Code, Cursor and Antigravity (the harnesses with a launch preflight): `_meta["aiterm/launch_error"]` carries `code:"AGENT_AUTH_REQUIRED"`, `phase:"input"`, `effect:"not_started"`, `session_created:false` and the `harness`; the text is `AGENT_LAUNCH_NOT_STARTED: AGENT_AUTH_REQUIRED: ...` (Claude keeps its older text and structured answer beside it). Codex and Grok have no launch preflight and stop at their own login screen. A status check that cannot be read is not this code.
|
|
776
|
+
|
|
775
777
|
Set `throughline_source_session` together with a non-empty mission in `prompt` to prepend
|
|
776
778
|
Throughline's read-only handoff context. This optional route requires `throughline >= 0.9.0`,
|
|
777
779
|
cannot be combined with `launch_operation_id`, and leaves the source session's database ownership
|
|
@@ -5,7 +5,9 @@ import { AitermError } from "./errors.js";
|
|
|
5
5
|
import { executionNativeBindingSchema } from "./execution-close.js";
|
|
6
6
|
import { OPERATION_ID_RE, agentManagedClaudeSettingsPath, agentClaudeResultPath, agentClaudeCallerPromptPath, agentClaudeCallerMcpPath } from "./harnesses/claude.js";
|
|
7
7
|
import { agentCodexCallerPromptPath, agentCodexCallerMcpPath } from "./harnesses/codex.js";
|
|
8
|
-
import { resolveAndValidateGrokAuth } from "./harnesses/grok.js";
|
|
8
|
+
import { resolveAndValidateGrokAuth, agentGrokCallerPromptPath, agentGrokCallerAgentPath } from "./harnesses/grok.js";
|
|
9
|
+
import { agentCursorCallerPromptPath, agentCursorCallerPluginDir } from "./harnesses/cursor.js";
|
|
10
|
+
import { agentAntigravityCallerPromptPath, agentAntigravityCallerDir } from "./harnesses/antigravity.js";
|
|
9
11
|
import { assertSessionName, agentsDir, readAgentGeneration, selectAgentMetadataFile, agentEventPath, agentLineageFields, LAUNCH_ID_RE, AGENT_LINEAGE_RE } from "./agent-shared.js";
|
|
10
12
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
11
13
|
function normalizeInitialPromptState(v) {
|
|
@@ -134,6 +136,8 @@ export function loadAgentMetadata(name) {
|
|
|
134
136
|
vendor_session_id: m.vendor_session_id ?? null, initial_prompt: normalizeInitialPromptState(m.initial_prompt),
|
|
135
137
|
hook_route: "shared_antigravity_home", antigravity_home: m.antigravity_home, node_platform: process.platform,
|
|
136
138
|
...(typeof m.write_scope === "string" ? { write_scope: m.write_scope } : {}),
|
|
139
|
+
...(m.antigravity_caller_prompt_file === agentAntigravityCallerPromptPath(name) ? { antigravity_caller_prompt_file: m.antigravity_caller_prompt_file } : {}),
|
|
140
|
+
...(m.antigravity_caller_mcp_dir === agentAntigravityCallerDir(name) ? { antigravity_caller_mcp_dir: m.antigravity_caller_mcp_dir } : {}),
|
|
137
141
|
...deliveryFields, ...executableFields, ...fastFields, ...startupFields, ...loadAgentLineageFields(m, true) };
|
|
138
142
|
}
|
|
139
143
|
if (m.kind === "claude") {
|
|
@@ -242,6 +246,8 @@ export function loadAgentMetadata(name) {
|
|
|
242
246
|
completion_route: "cursor_transcript",
|
|
243
247
|
...loadAgentLineageFields(m, true),
|
|
244
248
|
node_platform: process.platform,
|
|
249
|
+
...(m.cursor_caller_prompt_file === agentCursorCallerPromptPath(name) ? { cursor_caller_prompt_file: m.cursor_caller_prompt_file } : {}),
|
|
250
|
+
...(m.cursor_caller_mcp_dir === agentCursorCallerPluginDir(name) ? { cursor_caller_mcp_dir: m.cursor_caller_mcp_dir } : {}),
|
|
245
251
|
cursor_home: recordedHome,
|
|
246
252
|
};
|
|
247
253
|
}
|
|
@@ -279,6 +285,8 @@ export function loadAgentMetadata(name) {
|
|
|
279
285
|
completion_route: "grok_transcript",
|
|
280
286
|
...loadAgentLineageFields(m, true),
|
|
281
287
|
node_platform: process.platform,
|
|
288
|
+
...(m.grok_caller_prompt_file === agentGrokCallerPromptPath(name) ? { grok_caller_prompt_file: m.grok_caller_prompt_file } : {}),
|
|
289
|
+
...(m.grok_caller_mcp_file === agentGrokCallerAgentPath(name) ? { grok_caller_mcp_file: m.grok_caller_mcp_file } : {}),
|
|
282
290
|
grok_home: recordedGrokHome,
|
|
283
291
|
grok_auth_path: expectedAuthPath,
|
|
284
292
|
};
|
|
@@ -349,6 +349,8 @@ export function parentPaneEvidence(kind, screen) {
|
|
|
349
349
|
const observed = agentPaneObservation(kind, current);
|
|
350
350
|
if (observed.state === "blocked" || observed.state === "unknown")
|
|
351
351
|
return "unknown";
|
|
352
|
+
if (kind === "claude" && observed.state === "idle" && /^⏺ Compacted while idle\b/u.test(current))
|
|
353
|
+
return "ready_compacted";
|
|
352
354
|
if (kind === "claude" && observed.state === "idle"
|
|
353
355
|
&& !/^[·✢✳✶✻✽*∗] [^…\n]+ for \d[^…\n]*$/mu.test(current))
|
|
354
356
|
return "ready_no_completion";
|
package/dist/core.js
CHANGED
|
@@ -11,7 +11,7 @@ import { inspectIdleSettings, inspectCodexResumeSettings, codexRecoveryComposer
|
|
|
11
11
|
import { AGENT_TUI_READY_TIMEOUT_MS, AGENT_TUI_FIRST_DRAW_TIMEOUT_MS, AGENT_TUI_READY_POLL_MS, isAgentTuiReady, isAgentTuiBusy, isAgentTuiIdleReady, agentPaneObservation, parentPaneEvidence, waitAgentTuiReadyImpl, detectAgentSubmitResidueImpl, waitCursorPromptVisibleImpl, settleAgentDoneScreenImpl } from "./agent-screen-observation.js";
|
|
12
12
|
export { launchEchoIsLastOnScreen, __testSetAgentTuiReadyStableSamples } from "./agent-screen-observation.js";
|
|
13
13
|
import { parseClaudeOperationMarker } from "./claude-operation-marker.js";
|
|
14
|
-
import { withManagedSpan, observeManagedSpan } from "./managed-seat-turn.js";
|
|
14
|
+
import { withManagedSpan, observeManagedSpan, SPAN_HELD } from "./managed-seat-turn.js";
|
|
15
15
|
/**
|
|
16
16
|
* core — CLI/MCP が共有する端末操作とharness進行(Node/TS 版)。
|
|
17
17
|
*
|
|
@@ -26,6 +26,7 @@ import * as fs from "node:fs";
|
|
|
26
26
|
import * as path from "node:path";
|
|
27
27
|
import { createHash, randomBytes } from "node:crypto";
|
|
28
28
|
import { launchEnvValue } from "./private-env.js";
|
|
29
|
+
import { assertCallerEnv } from "./harnesses/caller-mcp.js";
|
|
29
30
|
import { fileURLToPath } from "node:url";
|
|
30
31
|
import * as rtk from "./rtk.js";
|
|
31
32
|
import { manageClaudeAgentGoal, manageGrokAgentGoal } from "./agent-goal-native-result.js";
|
|
@@ -47,16 +48,16 @@ import { withExecutionInterruptEffectScope, bindExecutionNativeTarget, beforeExe
|
|
|
47
48
|
import { ExecutionError } from "./execution-wire.js";
|
|
48
49
|
import { readExecutionParentProcess } from "./execution-parent-process.js";
|
|
49
50
|
import { isCursorMcpClient } from "aiterm-steer-delivery";
|
|
50
|
-
import { antigravityBinding, antigravityAuthChoiceKey, antigravityCurrentModel, antigravityStartupAction, antigravityAgentArgv, antigravityModelChoices, antigravityAuthStatus, antigravityAuthPane, antigravityTranscriptText, bindAntigravitySession, createAntigravityAgentMetadata, mergeAntigravityHooks } from "./harnesses/antigravity.js";
|
|
51
|
+
import { antigravityBinding, antigravityAuthChoiceKey, antigravityCurrentModel, antigravityStartupAction, antigravityAgentArgv, writeAntigravityCallerFiles, checkAntigravityCallerInput, antigravityPromptWithCaller, antigravityModelChoices, antigravityAuthStatus, antigravityAuthPane, antigravityTranscriptText, bindAntigravitySession, createAntigravityAgentMetadata, mergeAntigravityHooks } from "./harnesses/antigravity.js";
|
|
51
52
|
import { paneTokenHint } from "./harnesses/pane-tokens.js";
|
|
52
53
|
import { unfinishedDeliveriesOwnedBy } from "./parent-delivery-owners.js";
|
|
53
54
|
import { readLinuxProcessRegistrationIdentity, readRuntimeProcesses, readProcessIdentities, processSubtree, parentProcess, processIdentity, signalRuntimeProcess, backgroundProcesses, lazyRelayProcess, aitermProcessProbe, windowsConsoleHost, macKeepAwakeProcess, processElapsedSeconds } from "./process-runtime.js";
|
|
54
55
|
import { liveNodeExecutable } from "./live-node.js";
|
|
55
56
|
import { resolveClaudeConfigurationRoot, withClaudeConfigRoot } from "./claude-config-root.js";
|
|
56
57
|
import { probeWriteBan, writeBanPrefix, windowsWriteBanArgv } from "./write-ban.js";
|
|
57
|
-
import { AitermError, AgentResumeUnavailableError, AgentResumeError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
58
|
+
import { AitermError, launchAuthRequired, launchInputRefusal, AgentResumeUnavailableError, AgentResumeError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
58
59
|
import { isWin, SOCKDIR, SOCK, tmuxCommand, readOnlyTmuxList, PtyDiagnosticError, tmuxCommandWithInput, sendPsmuxPayload, loadPtyBufferChunk, pasteBufferBaseArgs, tmuxNewSession, withNativeSessionCreation, withNativeSessionTarget, hasVerifiedNativeSessionTarget, withNativeSessionSetupRollback, hasNativeSessionSetupRollback, registeredSessionEnvironment, registerSessionEnvironment, attachCommand, normalizePaneCommand, atomicShellMultiline, appendMarkSentinel, paneShellForSubmission, adaptShellSubmission, settlePaneLog, paneCwdArgument, sessionEnvironmentLaunch, paneCommandArgs, rememberPaneShell, } from "./tmux-runtime.js";
|
|
59
|
-
import { AGENT_DEFAULT_PREFACE, sleep, currentUid, runtimeStateBase, safeStatSize, readFileRange, writeJson0600, writeText0600, createEmpty0600, shq, LAUNCH_ID_RE, AGENT_LINEAGE_RE, AGENT_DONE_POLL_MS, AGENT_RATE_LIMIT_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, assertSessionName, agentsDir, readAgentGeneration, selectAgentMetadataFile, publishAgentGeneration, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness,
|
|
60
|
+
import { AGENT_DEFAULT_PREFACE, sleep, currentUid, runtimeStateBase, safeStatSize, readFileRange, writeJson0600, writeText0600, createEmpty0600, shq, LAUNCH_ID_RE, AGENT_LINEAGE_RE, AGENT_DONE_POLL_MS, AGENT_RATE_LIMIT_POLL_MS, pollGate, AGENT_EVENT_MAX_BYTES, assertSessionName, agentsDir, readAgentGeneration, selectAgentMetadataFile, publishAgentGeneration, agentMetadataPath, writeAgentMetadata, AGENT_EVENT_TAIL_BYTES, agentLabel, agentHarness, } from "./agent-shared.js";
|
|
60
61
|
import { AuthResponseError, authUi, authPromptDigest, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
61
62
|
import { processStartIdentity } from "./runtime-error-os.js";
|
|
62
63
|
import { processStartIdentities } from "./process-start.js";
|
|
@@ -64,10 +65,10 @@ import { catalogUnavailable } from "./model-catalog.js";
|
|
|
64
65
|
import { FastModeError, fastModeFailure } from "./fast-mode.js";
|
|
65
66
|
import { readFileOrNull, restoreJsonSetting, withUserConfigLock, restoreUserDefaults, keepingUserDefaults, USER_DEFAULT_SETTLE_MS } from "./user-config.js";
|
|
66
67
|
import { isDeepStrictEqual } from "node:util";
|
|
67
|
-
import { grokAuthPlan, grokAuthStatus, grokAuthPane, GROK_MODEL_DEFAULTS, realGrokHome, resolveAndValidateGrokAuth, assertGrokModelAvailable, grokModelChoices, grokModelFromFooter, grokFooterModelName, grokModelDefaultsFromBody, restoreGrokModelDefaults, grokEventsTranscript, grokSessionDirectory, latestGrokCompletion, grokTurnSettled, observeGrokDone, buildGrokAgentCmd, grokAgentArgv, grokLaunchNote, grokEnvTokens, grokEnvEntries, grokTuiReady, grokPaneObservation, GROK_INTERRUPT_KEY, grokRateLimitDialog, grokPromptAwaitingAccept, grokUnacceptedPromptRestored, grokStartupAction, grokFooterHasConfiguration, grokTranscriptText, createGrokAgentMetadata, } from "./harnesses/grok.js";
|
|
68
|
+
import { grokAuthPlan, grokAuthStatus, grokAuthPane, GROK_MODEL_DEFAULTS, realGrokHome, resolveAndValidateGrokAuth, assertGrokModelAvailable, grokModelChoices, grokModelFromFooter, grokFooterModelName, grokModelDefaultsFromBody, restoreGrokModelDefaults, grokEventsTranscript, grokSessionDirectory, latestGrokCompletion, grokTurnSettled, observeGrokDone, buildGrokAgentCmd, grokAgentArgv, writeGrokCallerFiles, checkGrokCallerInput, grokLaunchNote, grokEnvTokens, grokEnvEntries, grokTuiReady, grokPaneObservation, GROK_INTERRUPT_KEY, grokRateLimitDialog, grokPromptAwaitingAccept, grokUnacceptedPromptRestored, grokStartupAction, grokFooterHasConfiguration, grokTranscriptText, createGrokAgentMetadata, } from "./harnesses/grok.js";
|
|
68
69
|
import { codexAuthPlan, codexAuthStatus, codexAuthPane, realCodexHome, readCodexConfigPins, bindCodexTranscriptSession, latestCodexCompletion, codexTurnSettled, codexCompletedTurnId, codexWorkingResumeConfiguration, captureCodexRecoveryProof, captureCodexResumeProof, readCodexResumeProof, codexResumeProofDigest, codexRootTranscript, codexRolloutSessionId, codexRunningTurn, codexInterruptionRecord, observeCodexDone, buildCodexAgentCmd, codexAgentArgv, codexResumeArgv, writeCodexCallerFiles, refuseCodexCallerInput, codexLaunchNote, codexPaneObservation, CODEX_INTERRUPT_KEY, codexHelperProcess, codexRateLimitModelSwitchDialog, codexApprovalDialog, codexStartupAction, codexModelChoice, codexEffortChoice, codexMoreReasoningChoice, codexTranscriptText, createCodexAgentMetadata, codexModelChoices, codexFastCommandOffered, codexFooterShowsFast, codexServiceTierNotices, restoreCodexDefaults, restoreCodexDefaultInFile, } from "./harnesses/codex.js";
|
|
69
70
|
import { claudeAuthPlan, claudeAuthStatus, claudeAuthPane, OPERATION_ID_RE, CLAUDE_RESULT_MAX_BYTES, CLAUDE_EFFORTS, agentClaudeOperationPath, agentClaudeApprovalReceiptPath, agentClaudeDispatchReceiptPath, validateOperationId, readClaudeResultText, assertClaudeAuthenticationReady, claudeModelChoices, claudeConfigDir, claudeProjectSlug, claudeFastIndicatorShown, claudeFastResult, buildClaudeAgentCmd, claudeAgentArgv, claudeResumeArgv, claudeLaunchNote, claudePaneObservation, CLAUDE_INTERRUPT_KEY, claudeUsageLimit, claudeLiveSelectMenu, claudeStartupAction, createClaudeAgentMetadata, writeClaudeCallerFiles, claudeSessionTranscriptPath, claudeApiErrorFromLine, claudeApiErrorAfter, claudeApiErrorEndingTurn, claudeFailureCategory, } from "./harnesses/claude.js";
|
|
70
|
-
import { cursorAuthPlan, cursorAuthStatus, cursorAuthPane, bindCursorTranscriptSession, cursorTurnBoundary, latestCursorCompletion, cursorTranscript, cursorTranscriptSessionId, observeCursorDone, cursorTranscriptText, assertCursorAuthenticationReady, assertCursorModelAvailable, cursorModelChoices, cursorModelIsFastVariant, cursorFastParameter, cursorHeaderShowsFast, cursorPickerView, cursorEffortSelected, cursorParameterRows, cursorUserConfigPath, CURSOR_DEFAULT_MODEL_KEYS, realCursorHome, buildCursorAgentCmd, cursorAgentArgv, cursorPromptWithLineage, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
71
|
+
import { cursorAuthPlan, cursorAuthStatus, cursorAuthPane, bindCursorTranscriptSession, cursorTurnBoundary, latestCursorCompletion, cursorTranscript, cursorTranscriptSessionId, observeCursorDone, cursorTranscriptText, assertCursorAuthenticationReady, assertCursorModelAvailable, cursorModelChoices, cursorModelIsFastVariant, cursorFastParameter, cursorHeaderShowsFast, cursorPickerView, cursorEffortSelected, cursorParameterRows, cursorUserConfigPath, CURSOR_DEFAULT_MODEL_KEYS, realCursorHome, buildCursorAgentCmd, cursorAgentArgv, cursorPromptWithLineage, cursorLineagePreface, writeCursorCallerFiles, checkCursorCallerInput, createCursorAgentMetadata, cursorLaunchNote, cursorEffortNavigation, cursorTuiReady, cursorPaneObservation, CURSOR_INTERRUPT_KEY, cursorPromptHooksRunning, cursorUsageLimit, CURSOR_SUBMIT_SEQUENCE, validateCursorModelEffort, } from "./harnesses/cursor.js";
|
|
71
72
|
import { interimFromNow, interimFromToken, readInterimWords, recordInterimBoundary } from "./interim-words.js";
|
|
72
73
|
import { codexSeatTurn, grokSteerAcceptance, observeSteerDone, readSteerEntry, recordSteer } from "./steer-follow.js";
|
|
73
74
|
import { resolveAgentBin, resolveThroughlineBin, runThroughlineHandoffContext, isWindowsNativeExecutable, isUsableAgentExecutableFile, agentBinForPaneShell, resolveWinPaneShell, windowsAgentArgv, windowsAgentLaunchLine, windowsLaunchIndirection } from "./agent-resolver.js";
|
|
@@ -394,6 +395,10 @@ function cleanupAgentState(name) {
|
|
|
394
395
|
f.endsWith(".claude-caller-mcp.json") ||
|
|
395
396
|
f.endsWith(".codex-caller-prompt.md") ||
|
|
396
397
|
f.endsWith(".codex-caller-mcp.json") ||
|
|
398
|
+
f.endsWith(".grok-caller-prompt.md") ||
|
|
399
|
+
f.endsWith(".grok-caller-agent.md") ||
|
|
400
|
+
f.endsWith(".cursor-caller-prompt.md") ||
|
|
401
|
+
f.endsWith(".antigravity-caller-prompt.md") ||
|
|
397
402
|
f.endsWith(".launch-env") ||
|
|
398
403
|
f.endsWith(".claude-result.json") ||
|
|
399
404
|
f.endsWith(".cursor-result.json") ||
|
|
@@ -406,7 +411,7 @@ function cleanupAgentState(name) {
|
|
|
406
411
|
f.endsWith(".steers.jsonl") ||
|
|
407
412
|
f.endsWith(".auth.json"))
|
|
408
413
|
fs.unlinkSync(p);
|
|
409
|
-
else if (f.endsWith(".seat-span.d") || f.endsWith(".codex-home") || f.endsWith(".grok-home") || f.endsWith(".cursor-plugin") || f.endsWith(".home") || f.endsWith(".resume-restore.d")) {
|
|
414
|
+
else if (f.endsWith(".seat-span.d") || f.endsWith(".codex-home") || f.endsWith(".grok-home") || f.endsWith(".cursor-plugin") || f.endsWith(".antigravity-caller") || f.endsWith(".home") || f.endsWith(".resume-restore.d")) {
|
|
410
415
|
fs.rmSync(p, { recursive: true, force: true });
|
|
411
416
|
}
|
|
412
417
|
}
|
|
@@ -3746,7 +3751,7 @@ export function readSessionInterimWords(name, after, from = null) {
|
|
|
3746
3751
|
* read current original-pane activity, with observation identity and no waiter.
|
|
3747
3752
|
*/
|
|
3748
3753
|
export function readSeatTurns(sessionIds) {
|
|
3749
|
-
const seats = [];
|
|
3754
|
+
const seats = [], unread = [];
|
|
3750
3755
|
const observedAt = new Map();
|
|
3751
3756
|
for (const name of sessionIds) {
|
|
3752
3757
|
const meta = tryLoadAgentMetadata(name);
|
|
@@ -3759,6 +3764,10 @@ export function readSeatTurns(sessionIds) {
|
|
|
3759
3764
|
: meta.kind === "codex" ? codexSeatTurn(meta) : readManagedSeatTurn(meta);
|
|
3760
3765
|
}
|
|
3761
3766
|
catch { /* 読めない席は、分からないまま返す */ }
|
|
3767
|
+
if (turn === SPAN_HELD) {
|
|
3768
|
+
unread.push(name);
|
|
3769
|
+
continue;
|
|
3770
|
+
}
|
|
3762
3771
|
if (meta.kind !== "codex")
|
|
3763
3772
|
observedAt.set(name, performance.now());
|
|
3764
3773
|
seats.push({ session_id: name, launch_id: meta.launch_id, harness: agentHarness(meta.kind),
|
|
@@ -3769,7 +3778,7 @@ export function readSeatTurns(sessionIds) {
|
|
|
3769
3778
|
if (seat.harness !== "codex-cli"
|
|
3770
3779
|
&& performance.now() - observedAt.get(seat.session_id) >= 15_000)
|
|
3771
3780
|
seat.turn = null;
|
|
3772
|
-
return { schema: "aiterm.seat-turns.v1", seats };
|
|
3781
|
+
return { schema: "aiterm.seat-turns.v1", seats, unread };
|
|
3773
3782
|
}
|
|
3774
3783
|
function managedSeatConversation(meta) {
|
|
3775
3784
|
if (meta.kind === "antigravity") {
|
|
@@ -4667,7 +4676,7 @@ async function sendInitialAgentPromptInLock(name, text, o) {
|
|
|
4667
4676
|
startupBlockedHint(startup.reason), 2);
|
|
4668
4677
|
}
|
|
4669
4678
|
await o.after_ready?.(name, meta);
|
|
4670
|
-
const promptText = meta.kind === "cursor" ? cursorPromptWithLineage(meta, text) : text;
|
|
4679
|
+
const promptText = meta.kind === "cursor" ? cursorPromptWithLineage(meta, text) : meta.kind === "antigravity" ? antigravityPromptWithCaller(meta, text) : text;
|
|
4671
4680
|
const startOffset = agentCompletionCursor(meta);
|
|
4672
4681
|
const inputId = meta.kind === "claude" ? randomBytes(16).toString("hex") : undefined;
|
|
4673
4682
|
try {
|
|
@@ -7073,7 +7082,7 @@ async function dispatchAgentTurnInLock(name, text, o, pendingSend) {
|
|
|
7073
7082
|
// 画面の確かめを飛ばす送信(force)と、加工なしの送信(raw)には、既定の前置きを打たない(打った文は入力欄がそのまま読む)。
|
|
7074
7083
|
const prefaced = splitAgentPreface(meta.kind, o.preface, text, { defaultForWrapped: !o.force && !o.raw });
|
|
7075
7084
|
const dispatchText = meta.kind === "cursor" && !meta.vendor_session_id
|
|
7076
|
-
? `${
|
|
7085
|
+
? `${cursorLineagePreface(meta)}\n\n${prefaced.body}`
|
|
7077
7086
|
: prefaced.body;
|
|
7078
7087
|
prepareSendText(dispatchText, { raw: o.raw });
|
|
7079
7088
|
const inputId = meta.kind === "claude" ? randomBytes(16).toString("hex") : undefined;
|
|
@@ -7509,7 +7518,7 @@ function buildAgentCmd(kind, bin, model, effort, prompt, meta = null, cursorFast
|
|
|
7509
7518
|
if (kind === "cursor")
|
|
7510
7519
|
return buildCursorAgentCmd(bin, model, effort, prompt, meta, cursorFast);
|
|
7511
7520
|
if (kind === "antigravity")
|
|
7512
|
-
return antigravityAgentArgv(bin, model, effort, prompt).map(shq).join(" ");
|
|
7521
|
+
return antigravityAgentArgv(bin, model, effort, prompt, meta).map(shq).join(" ");
|
|
7513
7522
|
return buildGrokAgentCmd(kind, bin, model, effort, prompt, meta);
|
|
7514
7523
|
}
|
|
7515
7524
|
/**
|
|
@@ -7723,6 +7732,8 @@ function prepareAgentLaunch(kind, opts = {}) {
|
|
|
7723
7732
|
assertCursorAuthenticationReady(bin);
|
|
7724
7733
|
if (kind === "antigravity") {
|
|
7725
7734
|
const auth = antigravityAuthStatus(bin, cwd ?? process.cwd());
|
|
7735
|
+
if (auth.status === "unauthenticated")
|
|
7736
|
+
throw launchAuthRequired("antigravity-cli", `${auth.message}`);
|
|
7726
7737
|
if (auth.status !== "authenticated")
|
|
7727
7738
|
throw new AitermError(`ANTIGRAVITY_AUTH_REQUIRED: ${auth.message}`, 2);
|
|
7728
7739
|
const catalog = antigravityModelChoices(bin, cwd ?? process.cwd());
|
|
@@ -7803,6 +7814,12 @@ function prepareAgentLaunch(kind, opts = {}) {
|
|
|
7803
7814
|
writeClaudeCallerFiles(meta, opts.append_system_prompt ?? null, opts.mcp_config ?? null);
|
|
7804
7815
|
if (meta.kind === "codex")
|
|
7805
7816
|
writeCodexCallerFiles(meta, opts.append_system_prompt ?? null, opts.mcp_config ?? null);
|
|
7817
|
+
if (meta.kind === "grok" || meta.kind === "cursor" || meta.kind === "antigravity") {
|
|
7818
|
+
// The seat's own environment: what ${NAME} in a header resolves to (and what a harness reads at run time).
|
|
7819
|
+
const seatEnv = new Map(agentEnvEntries(meta, sid, envVars));
|
|
7820
|
+
const write = meta.kind === "grok" ? writeGrokCallerFiles : meta.kind === "cursor" ? writeCursorCallerFiles : writeAntigravityCallerFiles;
|
|
7821
|
+
write(meta, opts.append_system_prompt ?? null, opts.mcp_config ?? null, name => seatEnv.get(name));
|
|
7822
|
+
}
|
|
7806
7823
|
if (opts.fork_of)
|
|
7807
7824
|
meta.fork_of = opts.fork_of;
|
|
7808
7825
|
if (isWin && ["claude", "codex", "grok", "antigravity"].includes(kind))
|
|
@@ -7842,7 +7859,7 @@ function prepareAgentLaunch(kind, opts = {}) {
|
|
|
7842
7859
|
const argv = kind === "claude" ? claudeAgentArgv(bin, model, effort, prompt, meta)
|
|
7843
7860
|
: kind === "codex" ? codexAgentArgv(bin, model, effort, prompt, meta)
|
|
7844
7861
|
: kind === "cursor" ? cursorAgentArgv(bin, model, effort, prompt, meta, cursorFast)
|
|
7845
|
-
: kind === "antigravity" ? antigravityAgentArgv(bin, model, effort, prompt)
|
|
7862
|
+
: kind === "antigravity" ? antigravityAgentArgv(bin, model, effort, prompt, meta)
|
|
7846
7863
|
: grokAgentArgv(kind, bin, model, effort, prompt, meta);
|
|
7847
7864
|
full = windowsAgentLaunchLine(cwd, [
|
|
7848
7865
|
...claudeRootEntries, ...(meta?.kind === "grok" ? grokEnvEntries(meta) : []), ...agentEnvEntries(meta, sid, envVars),
|
|
@@ -8035,10 +8052,27 @@ export function resolveForkSource(kind, from, opts, probe = probeWriteBan) {
|
|
|
8035
8052
|
return { fork_of: { session_id: from.session_id, vendor_session_id: mainVendorId, ...(from.fork_id ? { fork_id: from.fork_id } : {}),
|
|
8036
8053
|
write_ban, ...(first_input ? { first_input } : {}) }, cwd: main.cwd, ...(root ? { root } : {}) };
|
|
8037
8054
|
}
|
|
8055
|
+
/** Caller launch fields refused from the arguments alone, before any session or file exists (phase "input"). */
|
|
8056
|
+
function refuseCallerInput(kind, opts) {
|
|
8057
|
+
if (kind === "codex")
|
|
8058
|
+
return refuseCodexCallerInput(opts.append_system_prompt, opts.mcp_config);
|
|
8059
|
+
if (kind !== "grok" && kind !== "cursor" && kind !== "antigravity")
|
|
8060
|
+
return;
|
|
8061
|
+
try {
|
|
8062
|
+
const servers = (kind === "grok" ? checkGrokCallerInput : kind === "cursor" ? checkCursorCallerInput : checkAntigravityCallerInput)(opts.append_system_prompt, opts.mcp_config);
|
|
8063
|
+
// Cursor puts the text in the seat's first dispatch whatever it is; agy's only channel is the launch prompt itself.
|
|
8064
|
+
if (kind === "antigravity" && opts.append_system_prompt != null && opts.prompt == null && opts.throughline_source_session == null)
|
|
8065
|
+
throw new AitermError("append_system_prompt needs a prompt for antigravity-cli (agy has no instruction channel; the text prefixes the first prompt)", 2);
|
|
8066
|
+
const envVars = opts.env_vars ?? [];
|
|
8067
|
+
assertCallerEnv(kind.toUpperCase(), servers, name => envVars.includes(name) ? launchEnvValue(name) : undefined, true);
|
|
8068
|
+
}
|
|
8069
|
+
catch (e) {
|
|
8070
|
+
throw e instanceof AitermError ? launchInputRefusal(agentHarness(kind), e.message) : e;
|
|
8071
|
+
}
|
|
8072
|
+
}
|
|
8038
8073
|
export async function openAgentWithInitialPrompt(kind, opts = {}) {
|
|
8039
8074
|
// Caller launch fields: refused from the arguments alone, before any session or file exists (phase "input").
|
|
8040
|
-
|
|
8041
|
-
refuseCodexCallerInput(opts.append_system_prompt, opts.mcp_config);
|
|
8075
|
+
refuseCallerInput(kind, opts);
|
|
8042
8076
|
const fork = opts.fork_from ? resolveForkSource(kind, opts.fork_from, opts) : null;
|
|
8043
8077
|
if (opts.configuration_root != null && kind !== "claude")
|
|
8044
8078
|
throw new AitermError("AGENT_CONFIGURATION_ROOT_REJECTED: configuration_rootはclaude-code harnessだけで使えます。", 2);
|
package/dist/errors.js
CHANGED
|
@@ -21,6 +21,12 @@ export function launchInputRefusal(harness, reason) {
|
|
|
21
21
|
error.launchNotStarted = { harness, phase: "input" };
|
|
22
22
|
return error;
|
|
23
23
|
}
|
|
24
|
+
/** The harness CLI is not logged in; the launch is refused before any session exists (remote-terminal.md R18, code AGENT_AUTH_REQUIRED). */
|
|
25
|
+
export function launchAuthRequired(harness, reason) {
|
|
26
|
+
const error = new AitermError(`AGENT_LAUNCH_NOT_STARTED: AGENT_AUTH_REQUIRED: ${reason}`, 2);
|
|
27
|
+
error.launchNotStarted = { harness, phase: "input", code: "AGENT_AUTH_REQUIRED" };
|
|
28
|
+
return error;
|
|
29
|
+
}
|
|
24
30
|
/** A harness authentication check refused launch before any session creation.
|
|
25
31
|
* Keep the native CLI's status body and credential diagnostics out of the wire. */
|
|
26
32
|
export class AgentAuthenticationPreflightError extends AitermError {
|
|
@@ -10,7 +10,8 @@ import { checkedCatalog, catalogInvalid, catalogUnavailable } from "../model-cat
|
|
|
10
10
|
import { spawnAgentControlCommand } from "../agent-resolver.js";
|
|
11
11
|
import { liveNodeExecutable } from "../live-node.js";
|
|
12
12
|
import { powershellInvocation } from "../windows-powershell.js";
|
|
13
|
-
import { agentEventPath, agentLineageFields, agentsDir, createEmpty0600, readFileRange, safeStatSize, shq, writeAgentMetadata, writeJson0600 } from "../agent-shared.js";
|
|
13
|
+
import { agentEventPath, agentLineageFields, agentsDir, assertSessionName, createEmpty0600, writeText0600, readFileRange, safeStatSize, shq, writeAgentMetadata, writeJson0600 } from "../agent-shared.js";
|
|
14
|
+
import { assertCallerEnv, checkCallerInput, readCallerText, resolveCallerHeader, writeCallerJson } from "./caller-mcp.js";
|
|
14
15
|
import { authUrl } from "../agent-auth.js";
|
|
15
16
|
// agy 1.4.10 exposes effort-specific IDs; overriding an ID's effort is rejected by the CLI.
|
|
16
17
|
export function antigravityCatalog(stdout, selected) {
|
|
@@ -190,8 +191,52 @@ export function createAntigravityAgentMetadata(name, cwd, initial, writeScope, l
|
|
|
190
191
|
writeAgentMetadata(meta);
|
|
191
192
|
return meta;
|
|
192
193
|
}
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
// ---- Caller launch fields (launch-identity-input.md "Caller launch fields"). agy has no per-run instruction channel Aiterm could
|
|
195
|
+
// prove (the .agents/rules route was not confirmed), so the text prefixes the first prompt; the servers are .agents/mcp_config.json
|
|
196
|
+
// in a per-seat folder passed as --add-dir. Both live in Aiterm state (0600 files), never in ~/.gemini or the project.
|
|
197
|
+
export function agentAntigravityCallerPromptPath(name) {
|
|
198
|
+
assertSessionName(name);
|
|
199
|
+
return path.join(agentsDir(), `${name}.antigravity-caller-prompt.md`);
|
|
200
|
+
}
|
|
201
|
+
export function agentAntigravityCallerDir(name) {
|
|
202
|
+
assertSessionName(name);
|
|
203
|
+
return path.join(agentsDir(), `${name}.antigravity-caller`);
|
|
204
|
+
}
|
|
205
|
+
/** agy does not expand header references, so every ${NAME} is written as the seat's value. */
|
|
206
|
+
export function antigravityCallerMcpJson(servers, valueOf) {
|
|
207
|
+
return { mcpServers: Object.fromEntries(servers.map(server => [server.name, {
|
|
208
|
+
serverUrl: server.url,
|
|
209
|
+
...(server.headers.length ? { headers: Object.fromEntries(server.headers.map(header => [header.name, resolveCallerHeader("ANTIGRAVITY", header, valueOf)])) } : {}),
|
|
210
|
+
}])) };
|
|
211
|
+
}
|
|
212
|
+
export function checkAntigravityCallerInput(prompt, mcp) {
|
|
213
|
+
return checkCallerInput("ANTIGRAVITY", prompt, mcp);
|
|
214
|
+
}
|
|
215
|
+
export function writeAntigravityCallerFiles(meta, prompt, mcp, valueOf) {
|
|
216
|
+
const servers = checkAntigravityCallerInput(prompt, mcp);
|
|
217
|
+
assertCallerEnv("ANTIGRAVITY", servers, valueOf);
|
|
218
|
+
if (prompt !== null) {
|
|
219
|
+
const file = agentAntigravityCallerPromptPath(meta.aiterm_session);
|
|
220
|
+
writeText0600(file, prompt);
|
|
221
|
+
meta.antigravity_caller_prompt_file = file;
|
|
222
|
+
}
|
|
223
|
+
if (mcp !== null) {
|
|
224
|
+
const dir = agentAntigravityCallerDir(meta.aiterm_session);
|
|
225
|
+
writeCallerJson(path.join(dir, ".agents", "mcp_config.json"), antigravityCallerMcpJson(servers, valueOf));
|
|
226
|
+
meta.antigravity_caller_mcp_dir = dir;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** The first prompt with the caller's text in front (the seat's only instruction channel here). */
|
|
230
|
+
export function antigravityPromptWithCaller(meta, prompt) {
|
|
231
|
+
const caller = readCallerText(meta.antigravity_caller_prompt_file);
|
|
232
|
+
return caller === null ? prompt : `${caller}\n\n${prompt}`;
|
|
233
|
+
}
|
|
234
|
+
export function antigravityAgentArgv(bin, model, effort, prompt, meta) {
|
|
235
|
+
// The seat folder and the cwd are trusted by --settings, or agy asks and then writes settings.json in ~/.gemini.
|
|
236
|
+
const folder = meta?.antigravity_caller_mcp_dir;
|
|
237
|
+
const trusted = folder ? [...new Set([meta.cwd, meta.cwd && fs.existsSync(meta.cwd) ? fs.realpathSync(meta.cwd) : null, folder].filter((item) => !!item))] : [];
|
|
238
|
+
const settings = JSON.stringify({ queuedMessages: "send-immediately", ...(folder ? { trustedWorkspaces: trusted } : {}) });
|
|
239
|
+
return [bin, "--dangerously-skip-permissions", "--settings", settings, ...(folder ? ["--add-dir", folder] : []), ...(model ? ["--model", model] : []), ...(effort ? ["--effort", effort] : []), ...(prompt ? ["--prompt-interactive", prompt] : [])];
|
|
195
240
|
}
|
|
196
241
|
export function antigravityBindingFile(meta) {
|
|
197
242
|
return path.join(agentsDir(), `${meta.aiterm_session}.${meta.launch_id}.antigravity-session.json`);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Caller launch fields (launch-identity-input.md "Caller launch fields") shared by grok-cli, cursor-cli and antigravity-cli:
|
|
2
|
+
// one reading of `mcp_config` and the checks that decide, before any seat exists, whether a harness can carry it.
|
|
3
|
+
// Codex keeps its own copy of the same rules (codex.ts codexMcpOverrides) and error codes.
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { AitermError } from "../errors.js";
|
|
7
|
+
import { writeJson0600 } from "../agent-shared.js";
|
|
8
|
+
// The text travels in one argv element (Linux caps one at 128 KiB) or the typed first prompt.
|
|
9
|
+
export const CALLER_PROMPT_MAX = 64 * 1024;
|
|
10
|
+
const MCP_SERVER_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
11
|
+
const HEADER_NAME = /^[A-Za-z0-9-]{1,128}$/;
|
|
12
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
13
|
+
// Names every seat has whatever env_vars says (core.ts agentEnvEntries), known before the seat exists.
|
|
14
|
+
const SEAT_ENV_NAMES = new Set(["AITERM_SESSION_ID", "AITERM_AGENT_SESSION_ID", "AITERM_AGENT_LAUNCH_ID"]);
|
|
15
|
+
/** `mcp_config` -> servers. Refuses (<LABEL>_MCP_CONFIG_UNSUPPORTED) what an http server table with env-named headers cannot say. */
|
|
16
|
+
export function parseCallerMcp(mcp, label) {
|
|
17
|
+
const refuse = (message) => { throw new AitermError(`${label}_MCP_CONFIG_UNSUPPORTED: ${message}`, 2); };
|
|
18
|
+
const servers = mcp?.mcpServers;
|
|
19
|
+
if (!mcp || typeof mcp !== "object" || Object.keys(mcp).some(key => key !== "mcpServers") || !servers || typeof servers !== "object" || Array.isArray(servers))
|
|
20
|
+
return refuse("mcp_config must be {mcpServers: {...}}");
|
|
21
|
+
return Object.entries(servers).map(([name, server]) => {
|
|
22
|
+
if (!MCP_SERVER_NAME.test(name))
|
|
23
|
+
return refuse(`server name '${name}' must be letters, digits, '_' or '-'`);
|
|
24
|
+
const spec = server;
|
|
25
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec))
|
|
26
|
+
return refuse(`server '${name}' must be an object`);
|
|
27
|
+
if (Object.keys(spec).some(key => !["type", "url", "headers"].includes(key)))
|
|
28
|
+
return refuse(`server '${name}' may only have type, url and headers`);
|
|
29
|
+
if (spec.type !== undefined && spec.type !== "http")
|
|
30
|
+
return refuse(`server '${name}': only type 'http' is supported here (got '${String(spec.type)}')`);
|
|
31
|
+
let url = null;
|
|
32
|
+
try {
|
|
33
|
+
url = typeof spec.url === "string" ? new URL(spec.url) : null;
|
|
34
|
+
}
|
|
35
|
+
catch { /* refused below */ }
|
|
36
|
+
if (!url || (url.protocol !== "http:" && url.protocol !== "https:"))
|
|
37
|
+
return refuse(`server '${name}': url must be an http(s) URL`);
|
|
38
|
+
if (spec.headers !== undefined && (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)))
|
|
39
|
+
return refuse(`server '${name}': headers must be an object`);
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
const headers = Object.entries((spec.headers ?? {})).map(([header, value]) => {
|
|
42
|
+
if (!HEADER_NAME.test(header) || typeof value !== "string")
|
|
43
|
+
return refuse(`server '${name}': header '${header}' must be a plain name with a string value`);
|
|
44
|
+
if (seen.has(header.toLowerCase()))
|
|
45
|
+
return refuse(`server '${name}': header '${header}' is given twice`);
|
|
46
|
+
seen.add(header.toLowerCase());
|
|
47
|
+
const bearer = header.toLowerCase() === "authorization" ? /^Bearer \$\{([^}]*)\}$/.exec(value)?.[1] : undefined;
|
|
48
|
+
const whole = /^\$\{([^}]*)\}$/.exec(value)?.[1];
|
|
49
|
+
if (bearer !== undefined || whole !== undefined) {
|
|
50
|
+
const envName = (bearer ?? whole);
|
|
51
|
+
if (!ENV_NAME.test(envName))
|
|
52
|
+
return refuse(`server '${name}': header '${header}' names an invalid environment variable`);
|
|
53
|
+
return { name: header, kind: bearer !== undefined ? "bearer" : "env", value: envName };
|
|
54
|
+
}
|
|
55
|
+
if (value.includes("${"))
|
|
56
|
+
return refuse(`server '${name}': header '${header}' mixes text with \${NAME}; only the whole value or 'Bearer \${NAME}' can be given`);
|
|
57
|
+
return { name: header, kind: "literal", value };
|
|
58
|
+
});
|
|
59
|
+
return { name, url: spec.url, headers };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** The text and servers of a caller input, or the refusal. `null` mcp -> no servers. */
|
|
63
|
+
export function checkCallerInput(label, prompt, mcp) {
|
|
64
|
+
if (prompt != null && (!prompt.trim() || Buffer.byteLength(prompt, "utf8") > CALLER_PROMPT_MAX))
|
|
65
|
+
throw new AitermError(`append_system_prompt must be non-empty and at most 64 KiB for ${label.toLowerCase()}`, 2);
|
|
66
|
+
return mcp == null ? [] : parseCallerMcp(mcp, label);
|
|
67
|
+
}
|
|
68
|
+
/** Every `${NAME}` the servers name must have a value at launch, or the seat would start with an empty secret. */
|
|
69
|
+
export function assertCallerEnv(label, servers, valueOf, preStart = false) {
|
|
70
|
+
for (const server of servers)
|
|
71
|
+
for (const header of server.headers) {
|
|
72
|
+
if (header.kind === "literal")
|
|
73
|
+
continue;
|
|
74
|
+
if (valueOf(header.value) === undefined && !(preStart && SEAT_ENV_NAMES.has(header.value)))
|
|
75
|
+
throw new AitermError(`${label}_MCP_ENV_UNAVAILABLE: header '${header.name}' of server '${server.name}' uses \${${header.value}}, which has no value at launch; list ${header.value} in env_vars`, 2);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** The header value with every `${NAME}` replaced by the seat's value (for a harness that does not expand them). */
|
|
79
|
+
export function resolveCallerHeader(label, header, valueOf) {
|
|
80
|
+
if (header.kind === "literal")
|
|
81
|
+
return header.value;
|
|
82
|
+
const value = valueOf(header.value);
|
|
83
|
+
if (value === undefined || value === "")
|
|
84
|
+
throw new AitermError(`${label}_MCP_ENV_UNAVAILABLE: \${${header.value}} has no value at launch`, 2);
|
|
85
|
+
return header.kind === "bearer" ? `Bearer ${value}` : value;
|
|
86
|
+
}
|
|
87
|
+
/** 0600 file inside a seat folder (created 0700) of Aiterm's launch state. */
|
|
88
|
+
export function writeCallerJson(file, value) {
|
|
89
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
90
|
+
writeJson0600(file, value);
|
|
91
|
+
}
|
|
92
|
+
export function readCallerText(file) {
|
|
93
|
+
return file ? fs.readFileSync(file, "utf8") : null;
|
|
94
|
+
}
|