aiterm-mcp 0.70.40 → 0.70.41
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 +9 -1
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/agent-idle.js +2 -0
- package/dist/agent-lifecycle.js +33 -10
- package/dist/core.js +46 -19
- package/dist/errors.js +11 -0
- package/dist/harnesses/antigravity.js +10 -2
- package/dist/index.js +6 -3
- package/dist/remote-terminal.js +15 -3
- package/dist/remote.js +69 -10
- package/dist/resume-checkpoint.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.70.41] - 2026-11-13
|
|
11
|
+
|
|
12
|
+
- Antigravity CLI 1.5.7 seats start again. agy 1.5.7 draws a mode hint in the empty composer (`> Auto mode: edits & safe commands auto-approved (shift+tab to cycle)`, also Accept-edits, Plan and Best-of-N), and Aiterm accepted only a bare `>` line as the empty composer, so every `agent_launch` ended `AGENT_STARTUP_BLOCKED vendor_state_unknown` (Kiro, 2026-11-13; container agy replaced 2026-11-12 23:38 UTC). The empty composer is now the footer plus a bare `>` line or exactly such a hint line (also when it wraps at the pane edge); a typed draft still reads as not empty.
|
|
13
|
+
- Calls to a trusted terminal (`terminal`-bound seats) reuse one warm MCP session per terminal instead of starting `ssh`, the terminal's shell, a fresh `aiterm-mcp` and MCP initialize for every call (a37; Kiro, 2026-11-13: BellTeam `GET /api/goals` 5-9.5 s, waiting on terminal seats). Measured from the container with the terminals' 0.70.40, one seat's `pty_observe` + `agent_goal inspect`: MacBook 3.8 s → about 0.4 s; Windows (fox) 5.3 s → about 2.0 s, of which inspect itself takes 1.5 s on the terminal (three Windows process table reads). A request already sent is never replayed: a session found closed before a send is reopened, one lost after a send fails as before. A session is closed after 2 minutes unused or 10 minutes of age (a terminal's `aiterm-update` takes effect within 10 minutes), and it never keeps an otherwise idle process alive. `agent_launch` with private values still uses its own connection.
|
|
14
|
+
- A Claude or Codex seat whose launch env names a secret (`…TOKEN`, `…KEY`, `…AUTH` and the like, or a terminal seat's `AITERM_MCP_HEADER_n`) can now hibernate and resume into the same conversation (E8; Kiro, 2026-11-13, chart t29). Until 0.70.40 such a seat got no resume template at all, so `pty_close {hibernate:true}` answered `AGENT_HIBERNATE_UNAVAILABLE resume_unavailable` and every BellTeam seat (which names `BELLTEAM_MCP_TOKEN`) could only be started fresh. The template and recipe now keep the secret names only (`secret_environment`); values are never written to disk, and a 0.70.23-0.70.40 recipe that held the Claude login value is rewritten without it. `agent_launch` with `session_name` takes each value from that launch (private env line, then process env) and refuses with `AGENT_RESUME_SECRET_MISSING` (not started, seat stays hibernated) when one is missing; the Claude login keeps its 0.70.23 rule (not named: the seat resumes on the root's login). A send or dispatch that would resume such a seat refuses with `AGENT_RESUME_SECRETS_REQUIRED` and sends nothing; the idle clock leaves such seats running (`resume_needs_launch_values`). A resume that brings `mcp_config` with the same server names rewrites the seat's caller MCP file, so a terminal seat reaches the current forward port.
|
|
15
|
+
- `pty_list` `aiterm/seat_turns` rows of terminal-bound seats carry `route_since` (E9): when the terminal's seat-MCP reverse forward was last established (the forward keeper records `ready_at`), null while it is not ready.
|
|
16
|
+
|
|
10
17
|
## [0.70.40] - 2026-11-12
|
|
11
18
|
|
|
12
19
|
- Parallel `agent_goal` `inspect` calls no longer run one at a time or stall the server. Every binding check (`resolve`, run 2-4 times per call) ran `tmux display-message` and the full `ps` table with `spawnSync`, so N inspects arriving together ran serially and blocked the event loop, delivery to every seat included (Kiro, 2026-11-13: BellTeam `GET /api/goals` took 8-17 s with ~25 live seats). These checks now run asynchronously, and checks that arrive together share one `tmux list-panes -a` read and one process table read (`freshShared`: a check only receives a read that began after its call, so no generation check uses an older table). Measured on the BellTeam container's live state, 27 seats (21 Claude, 6 Codex), inspect only: all in parallel 3.5 s → 0.68 s, longest event-loop block 3.1 s → 0.2 s, results identical to 0.70.39 for every seat. The check right before an input effect (`goalUi`) stays synchronous; inside a native target frame and on Windows the pane is read per session (asynchronously).
|
|
@@ -3376,7 +3383,8 @@ prototype (preserved under `prototype/python/` as the porting source and referen
|
|
|
3376
3383
|
`ubuntu-latest` for Node 18/20/22, publishing to npm on `v*` tags with
|
|
3377
3384
|
provenance.
|
|
3378
3385
|
|
|
3379
|
-
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.
|
|
3386
|
+
[Unreleased]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.41...HEAD
|
|
3387
|
+
[0.70.41]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.40...v0.70.41
|
|
3380
3388
|
[0.70.40]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.39...v0.70.40
|
|
3381
3389
|
[0.70.39]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.38...v0.70.39
|
|
3382
3390
|
[0.70.38]: https://github.com/kitepon/aiterm-mcp/compare/v0.70.37...v0.70.38
|
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.41** · 動作対象は Linux · WSL2 · macOS · Windows ネイティブ · MIT · [変更履歴](CHANGELOG.md)。
|
|
219
219
|
|
|
220
220
|
### 更新と巻き戻し
|
|
221
221
|
|
package/README.md
CHANGED
|
@@ -227,7 +227,7 @@ collection is off by default and performs no network I/O. It ships via
|
|
|
227
227
|
tag-triggered CI with npm provenance (OIDC Trusted Publishing); the GitHub
|
|
228
228
|
Release re-registers the Official MCP Registry entry.
|
|
229
229
|
|
|
230
|
-
**Status:** actively maintained · current public release **v0.70.
|
|
230
|
+
**Status:** actively maintained · current public release **v0.70.41** · 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
|
|
package/dist/agent-idle.js
CHANGED
|
@@ -29,6 +29,8 @@ export function decideIdleSeat(seat, now, minutes = 30, expectedAnchor, immediat
|
|
|
29
29
|
return { ...result, reason: "conversation_id_unavailable" };
|
|
30
30
|
if (!seat.resume_ready)
|
|
31
31
|
return { ...result, reason: "resume_unavailable" };
|
|
32
|
+
if (!immediate && seat.resume_needs_launch_values)
|
|
33
|
+
return { ...result, reason: "resume_needs_launch_values" };
|
|
32
34
|
if (!limited && seat.turn_settled !== true)
|
|
33
35
|
return { ...result, reason: "turn_end_unconfirmed" };
|
|
34
36
|
const anchor = limited ?? seat.activity.last_turn_end_at ?? (!seat.activity.tracked ? seat.created_at : null);
|
package/dist/agent-lifecycle.js
CHANGED
|
@@ -7,11 +7,18 @@ import { agentMetadataPath, writeJson0600 } from "./agent-shared.js";
|
|
|
7
7
|
import { AitermError } from "./errors.js";
|
|
8
8
|
const launchId = z.string().regex(/^[a-f0-9]{32}$/);
|
|
9
9
|
const absolute = z.string().min(1).refine(value => path.isAbsolute(value) && !value.includes("\0"));
|
|
10
|
+
const envName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
|
|
11
|
+
/** A credential-shaped name, or a header value the body moved to the private line for a terminal seat (remote-terminal R5). */
|
|
12
|
+
export function isSecretEnvName(name) {
|
|
13
|
+
return /(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIALS?|AUTH)$/i.test(name) || /^AITERM_MCP_HEADER_\d+$/.test(name);
|
|
14
|
+
}
|
|
10
15
|
export const agentResumeRecipeSchema = z.object({
|
|
11
16
|
schema: z.literal("aiterm.agent-resume.v1"), launch_id: launchId,
|
|
12
17
|
kind: z.enum(["claude", "codex"]), vendor_session_id: z.string().regex(/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i),
|
|
13
18
|
executable: absolute, cwd: absolute, configuration_root: absolute, model: z.string().nullable(), reasoning_effort: z.string().nullable(), reasoning_effort_source: z.literal("vendor_default").optional(), fast: z.boolean(),
|
|
14
|
-
environment: z.record(
|
|
19
|
+
environment: z.record(envName, z.string().refine(value => !value.includes("\0")).nullable()),
|
|
20
|
+
// E8: names whose values a resume takes from its own launch; the values are never stored.
|
|
21
|
+
secret_environment: z.array(envName).optional(),
|
|
15
22
|
}).strict();
|
|
16
23
|
const identity = z.object({ pid: z.number().int().positive(), process_group_id: z.number().int().positive().nullable(),
|
|
17
24
|
started_identity: z.string().min(1), argv_digest: z.string().regex(/^[a-f0-9]{64}$/) }).strict();
|
|
@@ -59,6 +66,16 @@ export function writeAgentResumeRecipe(meta, input) {
|
|
|
59
66
|
throw unavailable();
|
|
60
67
|
writeJson0600(file(meta, ".resume.json"), value);
|
|
61
68
|
}
|
|
69
|
+
/** Secret names of a recipe. A recipe from 0.70.40 or older may hold one in `environment`: its value is never used. */
|
|
70
|
+
export function recipeSecretNames(recipe) {
|
|
71
|
+
return [...new Set([...recipe.secret_environment ?? [], ...Object.keys(recipe.environment).filter(isSecretEnvName)])].sort();
|
|
72
|
+
}
|
|
73
|
+
/** The recipe as stored: secret names only, never their values. */
|
|
74
|
+
export function withoutSecretValues(recipe, secrets = recipeSecretNames(recipe)) {
|
|
75
|
+
const { secret_environment: _, ...rest } = recipe;
|
|
76
|
+
return { ...rest, environment: Object.fromEntries(Object.entries(recipe.environment).filter(([name]) => !isSecretEnvName(name) && !secrets.includes(name))),
|
|
77
|
+
...(secrets.length ? { secret_environment: secrets } : {}) };
|
|
78
|
+
}
|
|
62
79
|
export function agentResumeRecipeDigest(recipe) {
|
|
63
80
|
return createHash("sha256").update(JSON.stringify(agentResumeRecipeSchema.parse(recipe))).digest("hex");
|
|
64
81
|
}
|
|
@@ -151,12 +168,13 @@ export function writeAgentResumeTemplate(meta, input) {
|
|
|
151
168
|
export function captureAgentResumeTemplate(meta, effort, envNames, configurationRoot, env = process.env) {
|
|
152
169
|
if (meta.kind !== "claude" && meta.kind !== "codex")
|
|
153
170
|
return;
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
171
|
+
// Secret names are kept without values (E8): a resume takes them from its own launch.
|
|
172
|
+
const names = [...new Set([...envNames, ...(meta.kind === "claude" ? ["CLAUDE_CONFIG_DIR"] : [])])];
|
|
173
|
+
const secrets = names.filter(isSecretEnvName).sort();
|
|
157
174
|
writeAgentResumeTemplate(meta, { schema: "aiterm.agent-resume-template.v1", launch_id: meta.launch_id, kind: meta.kind,
|
|
158
175
|
executable: meta.agent_executable, cwd: meta.cwd, configuration_root: configurationRoot, model: meta.model ?? null, reasoning_effort: effort,
|
|
159
|
-
environment: Object.fromEntries(
|
|
176
|
+
environment: Object.fromEntries(names.filter(name => !isSecretEnvName(name)).map(name => [name, launchEnvValue(name, env) ?? null])),
|
|
177
|
+
...(secrets.length ? { secret_environment: secrets } : {}), state: "confirmed" });
|
|
160
178
|
}
|
|
161
179
|
export function finishAgentResumeConfiguration(meta, before, model, effort) {
|
|
162
180
|
const complete = !!model && !!effort;
|
|
@@ -168,9 +186,14 @@ export function finishAgentResumeConfiguration(meta, before, model, effort) {
|
|
|
168
186
|
export function refreshAgentResumeRecipe(meta) {
|
|
169
187
|
const template = readAgentResumeTemplate(meta);
|
|
170
188
|
if (!template) {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
const stored = readAgentResumeRecipe(meta);
|
|
190
|
+
if (!stored?.model || !stored.reasoning_effort || (meta.kind === "claude" && !Object.hasOwn(stored.environment, "CLAUDE_CONFIG_DIR")))
|
|
191
|
+
return null;
|
|
192
|
+
// A 0.70.23-0.70.40 recipe may hold the Claude login value: keep its name only (E8).
|
|
193
|
+
const recipe = withoutSecretValues(stored);
|
|
194
|
+
if (agentResumeRecipeDigest(recipe) !== agentResumeRecipeDigest(stored))
|
|
195
|
+
writeAgentResumeRecipe(meta, recipe);
|
|
196
|
+
return recipe;
|
|
174
197
|
}
|
|
175
198
|
if (template.state !== "confirmed" || !template.model || (!template.reasoning_effort && !(meta.kind === "codex" && template.reasoning_effort === null && template.reasoning_effort_source === "vendor_default")) || template.model !== meta.model
|
|
176
199
|
|| template.executable !== meta.agent_executable || template.cwd !== meta.cwd || typeof meta.fast !== "boolean")
|
|
@@ -179,8 +202,8 @@ export function refreshAgentResumeRecipe(meta) {
|
|
|
179
202
|
|| !["low", "medium", "high", "xhigh", "max"].includes(template.reasoning_effort ?? "")))
|
|
180
203
|
return null;
|
|
181
204
|
const { state, ...settings } = template;
|
|
182
|
-
const candidate = agentResumeRecipeSchema.safeParse({ ...settings, schema: "aiterm.agent-resume.v1",
|
|
183
|
-
vendor_session_id: meta.vendor_session_id, fast: meta.fast });
|
|
205
|
+
const candidate = agentResumeRecipeSchema.safeParse(withoutSecretValues({ ...settings, schema: "aiterm.agent-resume.v1",
|
|
206
|
+
vendor_session_id: meta.vendor_session_id, fast: meta.fast }));
|
|
184
207
|
if (!candidate.success)
|
|
185
208
|
return null;
|
|
186
209
|
const previous = readAgentResumeRecipe(meta);
|
package/dist/core.js
CHANGED
|
@@ -40,7 +40,7 @@ import { initializeAgentActivity, recordAgentInput, recordAgentTurnEnd, readAgen
|
|
|
40
40
|
import { checkIdleSeat, decideIdleSeat, idleMinutes } from "./agent-idle.js";
|
|
41
41
|
import { AGENT_IDLE_ENABLED, armAgentIdleClock, endAgentIdleClock, idleClockDeadline, isAgentIdleClockOwner, requestAgentIdleClock, requestAgentIdleClocks } from "./agent-idle-clock.js";
|
|
42
42
|
import { stopProcessTree } from "./process-tree-stop.js";
|
|
43
|
-
import { writeAgentResumeRecoveryOrigin, confirmedAgentResumeRecoveryOrigin, readAgentResumeResolution, writeAgentResumeResolution, agentResumeRecordDigest, captureAgentResumeTemplate, readAgentResumeTemplate, writeAgentResumeTemplate, finishAgentResumeConfiguration, refreshAgentResumeRecipe, readAgentIdleClock, retireAgentIdleClock, readAgentResumeRecipe, writeAgentResumeRecipe, agentResumeRecipeDigest, readAgentLifecycle, writeAgentLifecycle, cancelAgentStopping, readAgentResumeAttempt, writeAgentResumeAttempt, readAgentResumeNative, writeAgentResumeNative } from "./agent-lifecycle.js";
|
|
43
|
+
import { writeAgentResumeRecoveryOrigin, confirmedAgentResumeRecoveryOrigin, readAgentResumeResolution, writeAgentResumeResolution, agentResumeRecordDigest, captureAgentResumeTemplate, readAgentResumeTemplate, writeAgentResumeTemplate, finishAgentResumeConfiguration, refreshAgentResumeRecipe, readAgentIdleClock, retireAgentIdleClock, readAgentResumeRecipe, writeAgentResumeRecipe, agentResumeRecipeDigest, isSecretEnvName, recipeSecretNames, withoutSecretValues, readAgentLifecycle, writeAgentLifecycle, cancelAgentStopping, readAgentResumeAttempt, writeAgentResumeAttempt, readAgentResumeNative, writeAgentResumeNative } from "./agent-lifecycle.js";
|
|
44
44
|
import { createCodexGoalObjective, editCodexGoalObjective, submitCodexGoalCommand } from "./harnesses/codex-goal-editor.js";
|
|
45
45
|
import { closeExpectedExecution, parseExecutionNativeSessions, executionNativeBindingSchema } from "./execution-close.js";
|
|
46
46
|
import { executionLaunchSchema, executionPointSchema } from "./execution-contract.js";
|
|
@@ -55,7 +55,7 @@ import { readLinuxProcessRegistrationIdentity, readClaudeRegistrationIdentity, r
|
|
|
55
55
|
import { liveNodeExecutable } from "./live-node.js";
|
|
56
56
|
import { resolveClaudeConfigurationRoot, withClaudeConfigRoot, withClaudeSlotLogin } from "./claude-config-root.js";
|
|
57
57
|
import { probeWriteBan, writeBanPrefix, windowsWriteBanArgv } from "./write-ban.js";
|
|
58
|
-
import { AitermError, launchAuthRequired, launchInputRefusal, launchStartupBlocked, AgentResumeUnavailableError, AgentResumeError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
58
|
+
import { AitermError, launchAuthRequired, launchInputRefusal, launchStartupBlocked, AgentResumeUnavailableError, AgentResumeError, AgentResumeSecretsError, telemetryOwnedFailure, ownTelemetryFailure } from "./errors.js";
|
|
59
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, sessionPaneAsync, } from "./tmux-runtime.js";
|
|
60
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";
|
|
61
61
|
import { AuthResponseError, authUi, authPromptDigest, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
@@ -1966,7 +1966,7 @@ export async function checkAgentIdle(expectedInput, expectedAnchor, immediate =
|
|
|
1966
1966
|
const settled = meta.kind === "claude" ? done !== null && readClaudeOperationMarker(meta) === null
|
|
1967
1967
|
: meta.kind === "codex" ? done?.turn_id != null && done.turn_id === codexCompletedTurnId(meta) : agentTurnSettled(meta);
|
|
1968
1968
|
return { launch_id: meta.launch_id, created_at: meta.created_at, vendor_session_id: meta.vendor_session_id,
|
|
1969
|
-
resume_ready: resumeReady, native_configuration_confirmed: configurationScreen !== null
|
|
1969
|
+
resume_ready: resumeReady, resume_needs_launch_values: !!recipe && recipeSecretNames(recipe).length > 0, native_configuration_confirmed: configurationScreen !== null
|
|
1970
1970
|
&& (effectIssued || (slot?.last_attached_at != null && slot.last_attached_at < configurationStartedAt
|
|
1971
1971
|
&& configurationScreen === captureScreen(name, AGENT_TUI_READY_LINES))), activity: readAgentActivity(meta), state: live.state, reason: live.reason,
|
|
1972
1972
|
attached: slot?.attached ?? (effectIssued ? false : null), turn_settled: settled,
|
|
@@ -2298,7 +2298,7 @@ export function listSessionsResult(envKeys = [], runTmux = tmux, o = {}) {
|
|
|
2298
2298
|
const recipe = readAgentResumeRecipe(meta);
|
|
2299
2299
|
if (recipe?.kind === meta.kind && recipe.vendor_session_id === meta.vendor_session_id)
|
|
2300
2300
|
for (const key of envKeys)
|
|
2301
|
-
environment[key] = key
|
|
2301
|
+
environment[key] = isSecretEnvName(key) ? null : recipe.environment[key] ?? null;
|
|
2302
2302
|
if (state === "hibernated") {
|
|
2303
2303
|
try {
|
|
2304
2304
|
confirmedAgentResumeRecipe(meta, readAgentLifecycle(meta));
|
|
@@ -7073,7 +7073,11 @@ function adoptVanishedAgentNative(meta) {
|
|
|
7073
7073
|
}
|
|
7074
7074
|
// Claude's login, not a recipe setting (lifecycle-state-ownership 4b): a resume through agent_launch may replace it.
|
|
7075
7075
|
const CLAUDE_LOGIN_ENV = "CLAUDE_CODE_OAUTH_TOKEN";
|
|
7076
|
-
|
|
7076
|
+
/**
|
|
7077
|
+
* `secretValues` (E8, lifecycle-state-ownership 4c): the values agent_launch brought for the recipe's secret names (null = unset,
|
|
7078
|
+
* only the Claude login). Without them (pty_send, dispatch, vanished adopt) a recipe naming a secret is refused before any effect.
|
|
7079
|
+
*/
|
|
7080
|
+
async function resumeAgentInLock(name, readyTimeout, claudeRoot, secretValues) {
|
|
7077
7081
|
const previous = loadAgentMetadata(name);
|
|
7078
7082
|
readyTimeout ??= previous.kind === "codex" ? AGENT_TUI_FIRST_DRAW_TIMEOUT_MS : AGENT_TUI_READY_TIMEOUT_MS;
|
|
7079
7083
|
let lifecycle = readAgentLifecycle(previous);
|
|
@@ -7123,12 +7127,19 @@ async function resumeAgentInLock(name, readyTimeout, claudeRoot, claudeLogin) {
|
|
|
7123
7127
|
try {
|
|
7124
7128
|
assertExecutionResumeSupported();
|
|
7125
7129
|
const confirmed = confirmedAgentResumeRecipe(previous, lifecycle);
|
|
7130
|
+
const secretNames = [...new Set([...recipeSecretNames(confirmed), ...Object.keys(secretValues ?? {})])].sort();
|
|
7131
|
+
if (secretNames.length && !secretValues) {
|
|
7132
|
+
recorded = true; // a refusal before any effect, not a failed resume
|
|
7133
|
+
throw new AgentResumeSecretsError("AGENT_RESUME_SECRETS_REQUIRED", name, secretNames);
|
|
7134
|
+
}
|
|
7135
|
+
const stored = withoutSecretValues(confirmed, secretNames);
|
|
7126
7136
|
// Same vendor session under another Claude root; the caller proved the transcript is there.
|
|
7127
|
-
const rooted = claudeRoot &&
|
|
7128
|
-
environment: { ...
|
|
7129
|
-
// null = unset in the seat: it resumes on the root's own login.
|
|
7130
|
-
const recipe =
|
|
7131
|
-
|
|
7137
|
+
const rooted = claudeRoot && stored.kind === "claude" ? { ...stored, configuration_root: claudeRoot.root,
|
|
7138
|
+
environment: { ...stored.environment, CLAUDE_CONFIG_DIR: claudeRoot.selector } } : stored;
|
|
7139
|
+
// Values of this launch only; null = unset in the seat (the Claude login: it resumes on the root's own login).
|
|
7140
|
+
const recipe = { ...rooted, environment: { ...rooted.environment, ...Object.fromEntries(secretNames.map(key => [key, secretValues[key] ?? null])) } };
|
|
7141
|
+
// What goes to disk: the names still set, never their values.
|
|
7142
|
+
const saved = withoutSecretValues(recipe, secretNames.filter(key => recipe.environment[key] != null));
|
|
7132
7143
|
if (sessionExists(name))
|
|
7133
7144
|
throw uncertain();
|
|
7134
7145
|
const controlEnv = { ...process.env };
|
|
@@ -7208,7 +7219,7 @@ async function resumeAgentInLock(name, readyTimeout, claudeRoot, claudeLogin) {
|
|
|
7208
7219
|
next.fork_of = previous.fork_of;
|
|
7209
7220
|
writeAgentMetadata(next);
|
|
7210
7221
|
initializeAgentActivity(next);
|
|
7211
|
-
writeAgentResumeRecipe(next, { ...
|
|
7222
|
+
writeAgentResumeRecipe(next, { ...saved, launch_id: next.launch_id });
|
|
7212
7223
|
attempt = { schema: "aiterm.agent-resume-attempt.v1", launch_id: previous.launch_id, next_launch_id: next.launch_id,
|
|
7213
7224
|
state: "resuming", at: new Date().toISOString(), recipe_digest: lifecycle.recipe_digest };
|
|
7214
7225
|
phase = "attempt_save";
|
|
@@ -7222,8 +7233,8 @@ async function resumeAgentInLock(name, readyTimeout, claudeRoot, claudeLogin) {
|
|
|
7222
7233
|
const environment = [...Object.entries(recipe.environment),
|
|
7223
7234
|
...(next.kind === "codex" ? [["CODEX_HOME", recipe.configuration_root]] : []), ...agentEnvEntries(next, name)];
|
|
7224
7235
|
for (const [key, value] of environment) {
|
|
7225
|
-
//
|
|
7226
|
-
if (value !== null && key
|
|
7236
|
+
// Secret values never go on a multiplexer argv or into pty_list; the launch reads them from the 0600 file.
|
|
7237
|
+
if (value !== null && secretNames.includes(key))
|
|
7227
7238
|
continue;
|
|
7228
7239
|
const stored = value === null ? tmux("set-environment", isWin ? "-u" : "-r", "-t", name, key) : tmux("set-environment", "-t", name, key, value);
|
|
7229
7240
|
if (stored.code !== 0)
|
|
@@ -7265,9 +7276,10 @@ async function resumeAgentInLock(name, readyTimeout, claudeRoot, claudeLogin) {
|
|
|
7265
7276
|
phase = "ready_save";
|
|
7266
7277
|
writeAgentResumeTemplate(resumed, { schema: "aiterm.agent-resume-template.v1", launch_id: resumed.launch_id, state: "confirmed",
|
|
7267
7278
|
kind: recipe.kind, executable: recipe.executable, cwd: recipe.cwd, configuration_root: recipe.configuration_root,
|
|
7268
|
-
model: recipe.model, reasoning_effort: recipe.reasoning_effort, environment:
|
|
7279
|
+
model: recipe.model, reasoning_effort: recipe.reasoning_effort, environment: saved.environment,
|
|
7280
|
+
...(saved.secret_environment ? { secret_environment: saved.secret_environment } : {}),
|
|
7269
7281
|
...(recipe.reasoning_effort_source ? { reasoning_effort_source: recipe.reasoning_effort_source } : {}) });
|
|
7270
|
-
writeAgentResumeRecipe(resumed, { ...
|
|
7282
|
+
writeAgentResumeRecipe(resumed, { ...saved, launch_id: resumed.launch_id });
|
|
7271
7283
|
writeAgentResumeAttempt(previous, { ...attempt, state: "ready", at: new Date().toISOString() });
|
|
7272
7284
|
return resumed;
|
|
7273
7285
|
}
|
|
@@ -8453,7 +8465,7 @@ export async function openAgentWithInitialPrompt(kind, opts = {}) {
|
|
|
8453
8465
|
|| (opts.fast != null && opts.fast !== recipe.fast)
|
|
8454
8466
|
|| (opts.cwd != null && path.resolve(opts.cwd) !== recipe.cwd)
|
|
8455
8467
|
|| (opts.write_scope !== undefined && opts.write_scope !== previous.write_scope)
|
|
8456
|
-
|| (opts.env_vars !== undefined && !isDeepStrictEqual(resumeEnvNames(kind, opts.env_vars), resumeEnvNames(kind, Object.keys(recipe.environment)))))
|
|
8468
|
+
|| (opts.env_vars !== undefined && !isDeepStrictEqual(resumeEnvNames(kind, opts.env_vars), resumeEnvNames(kind, [...Object.keys(recipe.environment), ...recipeSecretNames(recipe)]))))
|
|
8457
8469
|
throw opts.require_existing_resume ? new AgentResumeUnavailableError(name) : new AitermError("AGENT_RESUME_CONFLICT: 同名の休止席は保存したharness・設定・project・明示envで再開します。変更は再開後に行ってください。", 2);
|
|
8458
8470
|
// The only setting a resume may change: the Claude root, when it holds this conversation's transcript.
|
|
8459
8471
|
const rootChange = claudeRoot && (claudeRoot.root !== recipe.configuration_root
|
|
@@ -8463,11 +8475,26 @@ export async function openAgentWithInitialPrompt(kind, opts = {}) {
|
|
|
8463
8475
|
if (opts.launch_operation_id != null)
|
|
8464
8476
|
requireMatchingClaudeLaunch(name, validateOperationId(opts.launch_operation_id), claudeLaunchRequestDigest({ sessionName: name, model: opts.model ?? null, effort: opts.reasoning_effort ?? null,
|
|
8465
8477
|
cwd: opts.cwd ?? null, agentDone: true }));
|
|
8478
|
+
// E8: every secret name takes this launch's value (private line, then env). The Claude login keeps 4b: named or
|
|
8479
|
+
// env_vars omitted -> this launch's value, else unset (root login); every other name without a value refuses.
|
|
8480
|
+
const isLogin = (key) => kind === "claude" && key === CLAUDE_LOGIN_ENV;
|
|
8481
|
+
const secretNames = [...new Set([...recipeSecretNames(recipe), ...(kind === "claude" && opts.env_vars?.includes(CLAUDE_LOGIN_ENV) ? [CLAUDE_LOGIN_ENV] : [])])];
|
|
8482
|
+
const secretValues = Object.fromEntries(secretNames.map(key => [key,
|
|
8483
|
+
isLogin(key) && opts.env_vars !== undefined && !opts.env_vars.includes(key) ? null : launchEnvValue(key) ?? null]));
|
|
8484
|
+
const missing = secretNames.filter(key => secretValues[key] === null && !isLogin(key));
|
|
8485
|
+
if (missing.length)
|
|
8486
|
+
throw new AgentResumeSecretsError("AGENT_RESUME_SECRET_MISSING", name, missing);
|
|
8487
|
+
// A terminal seat's forward port P may have changed: the caller MCP file takes the new URLs, same servers only.
|
|
8488
|
+
if (opts.mcp_config != null && (kind === "claude" ? previous.claude_caller_mcp_file : previous.codex_caller_mcp_file)) {
|
|
8489
|
+
const file = (kind === "claude" ? previous.claude_caller_mcp_file : previous.codex_caller_mcp_file);
|
|
8490
|
+
const serverNames = (config) => Object.keys((config ?? {}).mcpServers ?? {}).sort();
|
|
8491
|
+
if (!isDeepStrictEqual(serverNames(JSON.parse(fs.readFileSync(file, "utf8"))), serverNames(opts.mcp_config)))
|
|
8492
|
+
throw new AitermError("AGENT_RESUME_CONFLICT: 同名の休止席は保存したMCP serverの名前で再開します。", 2);
|
|
8493
|
+
(kind === "claude" ? writeClaudeCallerFiles : writeCodexCallerFiles)({ ...previous }, null, opts.mcp_config);
|
|
8494
|
+
}
|
|
8466
8495
|
if (preparedLifecycle)
|
|
8467
8496
|
commitWorkingAgentResume(previous, preparedLifecycle);
|
|
8468
|
-
const
|
|
8469
|
-
? { value: opts.env_vars.includes(CLAUDE_LOGIN_ENV) ? launchEnvValue(CLAUDE_LOGIN_ENV) ?? null : null } : undefined;
|
|
8470
|
-
const resumed = await resumeAgentInLock(name, opts.ready_timeout ?? undefined, rootChange, claudeLogin);
|
|
8497
|
+
const resumed = await resumeAgentInLock(name, opts.ready_timeout ?? undefined, rootChange, secretValues);
|
|
8471
8498
|
return withAgentResumeTarget(resumed, async () => {
|
|
8472
8499
|
const hint = `${agentLabel(kind)} を保存した同じ会話へ再開した。\n${attachHint(name)}`;
|
|
8473
8500
|
const fastState = { fast: resumed.fast === true, fast_error: null };
|
package/dist/errors.js
CHANGED
|
@@ -52,6 +52,17 @@ export class AgentResumeError extends AitermError {
|
|
|
52
52
|
session_id: sessionId, launch_id: launchId, input: "not_sent", recovery: "inspect_session" };
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
/** E8: a resume needs secret values only the caller's agent_launch carries; nothing was started or sent, the seat stays hibernated. */
|
|
56
|
+
export class AgentResumeSecretsError extends AitermError {
|
|
57
|
+
resumeSecrets;
|
|
58
|
+
constructor(code, sessionId, names) {
|
|
59
|
+
super(`${code}: ${code === "AGENT_RESUME_SECRET_MISSING"
|
|
60
|
+
? `再開に要る秘密の値がこの起動にありません(${names.join(", ")})。`
|
|
61
|
+
: `この席の再開には秘密の値が要ります(${names.join(", ")})。agent_launch(session_name)で値を渡して再開してください。`}新規起動も本文送信もしていません。`, 2);
|
|
62
|
+
this.resumeSecrets = { schema: "aiterm.agent-resume-secrets.v1", code, session_id: sessionId, names,
|
|
63
|
+
effect: "not_started", input: "not_sent", state: "hibernated" };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
55
66
|
export class TelemetryOwnedError extends AitermError {
|
|
56
67
|
telemetryCode;
|
|
57
68
|
constructor(message, code, telemetryCode, cause) {
|
|
@@ -56,6 +56,14 @@ export function antigravityAuthStatus(bin, cwd, env = process.env) {
|
|
|
56
56
|
return { status: "unauthenticated", message: "Antigravity CLIのGoogleサインインが必要です" };
|
|
57
57
|
return { status: "failed", message: "Antigravity CLIの認証状態を確認できません" };
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The empty composer under the `? for shortcuts` footer: a bare `>` line, or the mode hint agy 1.5.7 draws there until
|
|
61
|
+
* the first key (`> Auto mode: edits & safe commands auto-approved (shift+tab to cycle)`; the hint may wrap at the pane edge).
|
|
62
|
+
*/
|
|
63
|
+
export function antigravityEmptyComposer(screen) {
|
|
64
|
+
return /\? for shortcuts/.test(screen)
|
|
65
|
+
&& /^\s*>\s*(?:[A-Z][\w-]* mode: [^\n]*(?:\n[^\n─>]*)?\(shift\+tab\s+to\s+cycle\)\s*)?$/m.test(screen);
|
|
66
|
+
}
|
|
59
67
|
export function antigravityAuthPane(screen) {
|
|
60
68
|
if (/\binvalid_grant\b/i.test(screen))
|
|
61
69
|
return { url: null, user_code: null, input_required: false,
|
|
@@ -70,7 +78,7 @@ export function antigravityAuthPane(screen) {
|
|
|
70
78
|
}
|
|
71
79
|
const url = authUrl(urlLines.join(""), ["accounts.google.com"]);
|
|
72
80
|
const complete = /Do you trust the contents of this project\?/.test(screen)
|
|
73
|
-
|| (
|
|
81
|
+
|| antigravityEmptyComposer(screen);
|
|
74
82
|
const base = { url, user_code: null, input_required: false, message: null, onboarding_complete: complete };
|
|
75
83
|
if (complete)
|
|
76
84
|
return base;
|
|
@@ -134,7 +142,7 @@ export function antigravityPaneObservation(screen) {
|
|
|
134
142
|
return { state: "blocked", reason: "vendor_action_required" };
|
|
135
143
|
if (/(?:Generating|Working)(?:\.{3}|…)|esc to interrupt/i.test(screen))
|
|
136
144
|
return { state: "busy", reason: "vendor_generating" };
|
|
137
|
-
if (
|
|
145
|
+
if (antigravityEmptyComposer(screen))
|
|
138
146
|
return { state: "idle", reason: "composer_ready" };
|
|
139
147
|
return { state: "unknown", reason: "vendor_state_unknown" };
|
|
140
148
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { terminalCwdFits } from "./remote-path.js";
|
|
|
6
6
|
import { launchEnvValue } from "./private-env.js";
|
|
7
7
|
import { AuthResponseError, authUiSchema, authBindingSchema, authResponseSchema } from "./agent-auth-ui.js";
|
|
8
8
|
import { configurationRequestSchema, configurationToolOutputSchema, applyConfigurationRequest, reconcileConfigurationRequest } from "./configure-request.js";
|
|
9
|
-
import { AitermError, AgentResumeUnavailableError, AgentResumeError, launchInputRefusal } from "./errors.js";
|
|
9
|
+
import { AitermError, AgentResumeUnavailableError, AgentResumeError, AgentResumeSecretsError, launchInputRefusal } from "./errors.js";
|
|
10
10
|
/**
|
|
11
11
|
* aiterm-mcp — AI が握るローカル永続端末を stdio MCP サーバとして公開する(Node/TS 版)。
|
|
12
12
|
*
|
|
@@ -241,6 +241,9 @@ export function createAitermServer(options = {}) {
|
|
|
241
241
|
if (e instanceof AgentResumeUnavailableError)
|
|
242
242
|
return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
|
243
243
|
_meta: { "aiterm/resume_unavailable": { ...e.resumeUnavailable } } };
|
|
244
|
+
if (e instanceof AgentResumeSecretsError)
|
|
245
|
+
return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
|
246
|
+
structuredContent: { ...e.resumeSecrets } };
|
|
244
247
|
if (e instanceof AgentResumeError)
|
|
245
248
|
return { content: [{ type: "text", text: "aiterm: " + msg }], isError: true,
|
|
246
249
|
structuredContent: { ...e.resumeFailure } };
|
|
@@ -874,7 +877,7 @@ export function createAitermServer(options = {}) {
|
|
|
874
877
|
// two readers of one seat at once leave one of them without the span lock (that seat comes back in its `unread`).
|
|
875
878
|
// Relays start before the synchronous local read so the terminal works meanwhile; their 4 s counts only time this
|
|
876
879
|
// process's event loop was free (loopDeadline), since a blocked loop cannot take the answer however soon it came.
|
|
877
|
-
const relays = Promise.all(terminalSeatGroups().map(({ target, sessions: bound }) => {
|
|
880
|
+
const relays = Promise.all(terminalSeatGroups().map(({ target, sessions: bound, route_since }) => {
|
|
878
881
|
const key = JSON.stringify([target, requestMeta]);
|
|
879
882
|
let call = remoteSeatTurnsInFlight.get(key);
|
|
880
883
|
if (!call) {
|
|
@@ -886,7 +889,7 @@ export function createAitermServer(options = {}) {
|
|
|
886
889
|
}
|
|
887
890
|
return Promise.race([
|
|
888
891
|
call.then(answer => Array.isArray(answer?.seats)
|
|
889
|
-
? { seats: answer.seats.filter((seat) => bound.includes(seat?.session_id)),
|
|
892
|
+
? { seats: answer.seats.filter((seat) => bound.includes(seat?.session_id)).map((seat) => ({ ...seat, route_since })),
|
|
890
893
|
unread: Array.isArray(answer.unread) ? answer.unread.filter((name) => bound.includes(name)) : [] }
|
|
891
894
|
: { seats: [], unread: bound }),
|
|
892
895
|
loopDeadline(4_000, { seats: [], unread: bound }),
|
package/dist/remote-terminal.js
CHANGED
|
@@ -266,7 +266,13 @@ export class SshStdioTransport {
|
|
|
266
266
|
child.on("error", error => this.onerror?.(error));
|
|
267
267
|
child.on("close", () => { this.child = null; this.onclose?.(); });
|
|
268
268
|
child.stdin.on("error", error => this.onerror?.(error));
|
|
269
|
-
|
|
269
|
+
if (this.privateLine)
|
|
270
|
+
child.stdin.write(this.privateLine);
|
|
271
|
+
}
|
|
272
|
+
/** A kept session must not keep an idle process alive; it holds the loop only while a request waits on it. */
|
|
273
|
+
hold(on) {
|
|
274
|
+
for (const handle of [this.child, this.child?.stdin, this.child?.stdout, this.child?.stderr])
|
|
275
|
+
on ? handle?.ref?.() : handle?.unref?.();
|
|
270
276
|
}
|
|
271
277
|
async send(message) {
|
|
272
278
|
if (!this.child?.stdin)
|
|
@@ -747,7 +753,7 @@ export function terminalSeatGroups() {
|
|
|
747
753
|
for (const [session, ref] of Object.entries(readSeats()))
|
|
748
754
|
groups.set(ref, [...groups.get(ref) ?? [], session]);
|
|
749
755
|
return [...groups].flatMap(([ref, sessions]) => { try {
|
|
750
|
-
return [{ target: trustedTarget(binding(ref)), sessions }];
|
|
756
|
+
return [{ target: trustedTarget(binding(ref)), sessions, route_since: forwardRouteSince(ref) }];
|
|
751
757
|
}
|
|
752
758
|
catch {
|
|
753
759
|
return [];
|
|
@@ -869,7 +875,8 @@ function markReady(ref, ready) {
|
|
|
869
875
|
return;
|
|
870
876
|
const file = lockFile(ref), staged = `${file}.${process.pid}`;
|
|
871
877
|
try {
|
|
872
|
-
|
|
878
|
+
// ready_at (E9): when this ssh -R became ready; a newer one tells BellTeam the seats' route was rebuilt.
|
|
879
|
+
fs.writeFileSync(staged, JSON.stringify(ready ? { ...lockIdentity(), ready, ready_at: new Date().toISOString() } : lockIdentity()), { mode: 0o600 });
|
|
873
880
|
fs.renameSync(staged, file);
|
|
874
881
|
}
|
|
875
882
|
catch {
|
|
@@ -911,6 +918,11 @@ function forwardReady(ref, port) {
|
|
|
911
918
|
return false;
|
|
912
919
|
return Number(owner.pid) === process.pid ? Boolean(keepers.get(ref)?.child) : ownerAlive(owner);
|
|
913
920
|
}
|
|
921
|
+
/** E9: when the seats' current reverse forward was established; null when it is not ready or the time is unknown. */
|
|
922
|
+
export function forwardRouteSince(ref) {
|
|
923
|
+
const port = binding(ref).seat_forward_port, readyAt = lockOwner(ref)?.ready_at;
|
|
924
|
+
return port && typeof readyAt === "string" && forwardReady(ref, port) ? readyAt : null;
|
|
925
|
+
}
|
|
914
926
|
// T3: a launch in any process keeps the forward needed (the seat is bound only after it), so the owner never stops it meanwhile.
|
|
915
927
|
const launchFile = (ref) => path.join(ensureStateRoot(), `terminal-forward-${ref}.launch`);
|
|
916
928
|
function forwardNeeded(ref) {
|
package/dist/remote.js
CHANGED
|
@@ -223,6 +223,60 @@ export function remoteServerCommand(shell) {
|
|
|
223
223
|
}
|
|
224
224
|
export const REMOTE_CLIENT_NAME = "aiterm-remote";
|
|
225
225
|
/** 現地のaiterm-mcpへ1回だけMCP接続し、指定toolを呼んで閉じる。privateEnvは暗号化されたstdinの先頭行だけで渡す(remote-terminal.md R5)。 */
|
|
226
|
+
// a37: a trusted terminal keeps one warm MCP session (ssh + its aiterm-mcp, initialized) for calls without private values,
|
|
227
|
+
// so a call costs one round trip instead of a shell start, a node start and initialize. A sent request is never replayed.
|
|
228
|
+
const WARM_IDLE_MS = 2 * 60_000, WARM_MAX_AGE_MS = 10 * 60_000;
|
|
229
|
+
const warmSessions = new Map();
|
|
230
|
+
function retireWarm(ref, session) {
|
|
231
|
+
if (warmSessions.get(ref) === session)
|
|
232
|
+
warmSessions.delete(ref);
|
|
233
|
+
if (session.idle)
|
|
234
|
+
clearTimeout(session.idle);
|
|
235
|
+
if (!session.inflight)
|
|
236
|
+
void session.client.close().catch(() => { });
|
|
237
|
+
}
|
|
238
|
+
function warmSession(target, sshArgs) {
|
|
239
|
+
const ref = target.trusted_ref;
|
|
240
|
+
const kept = warmSessions.get(ref);
|
|
241
|
+
if (kept && !kept.dead && Date.now() - kept.born < WARM_MAX_AGE_MS)
|
|
242
|
+
return kept;
|
|
243
|
+
if (kept)
|
|
244
|
+
retireWarm(ref, kept);
|
|
245
|
+
const transport = new SshStdioTransport(sshArgs, ""), client = new Client({ name: REMOTE_CLIENT_NAME, version: pkg.version });
|
|
246
|
+
const session = { client, transport, born: Date.now(), inflight: 0, idle: null, dead: false,
|
|
247
|
+
ready: client.connect(transport, { timeout: 60_000 }).catch(() => {
|
|
248
|
+
retireWarm(ref, session);
|
|
249
|
+
const failure = classifySshFailure(transport.stderr);
|
|
250
|
+
throw new AitermError(`${failure.code}: ${failure.message}${failure.action ? ` (${failure.action})` : ""}`, 2);
|
|
251
|
+
}) };
|
|
252
|
+
client.onclose = () => { session.dead = true; if (warmSessions.get(ref) === session)
|
|
253
|
+
warmSessions.delete(ref); };
|
|
254
|
+
warmSessions.set(ref, session);
|
|
255
|
+
return session;
|
|
256
|
+
}
|
|
257
|
+
async function callWarm(target, sshArgs, request, timeoutMs) {
|
|
258
|
+
const session = warmSession(target, sshArgs);
|
|
259
|
+
session.inflight++;
|
|
260
|
+
if (session.idle) {
|
|
261
|
+
clearTimeout(session.idle);
|
|
262
|
+
session.idle = null;
|
|
263
|
+
}
|
|
264
|
+
session.transport.hold(true);
|
|
265
|
+
try {
|
|
266
|
+
await session.ready;
|
|
267
|
+
const result = await session.client.callTool(request, undefined, { timeout: timeoutMs, resetTimeoutOnProgress: true });
|
|
268
|
+
return { result, version: session.client.getServerVersion()?.version ?? null };
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
if (--session.inflight === 0) {
|
|
272
|
+
session.transport.hold(false);
|
|
273
|
+
if (session.dead || warmSessions.get(target.trusted_ref) !== session)
|
|
274
|
+
void session.client.close().catch(() => { });
|
|
275
|
+
else
|
|
276
|
+
session.idle = setTimeout(() => retireWarm(target.trusted_ref, session), WARM_IDLE_MS).unref();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
226
280
|
export async function callRemoteTool(target, name, args, timeoutMs = 600_000, privateEnv, meta) {
|
|
227
281
|
if (privateEnv && !target.trusted_ref)
|
|
228
282
|
throw new AitermError("REMOTE_PRIVATE_ENV_UNSUPPORTED: private values travel only to a terminal binding", 2);
|
|
@@ -231,6 +285,20 @@ export async function callRemoteTool(target, name, args, timeoutMs = 600_000, pr
|
|
|
231
285
|
const command = target.trusted_ref ? terminalCommand(shell, terminalProgram(privateEnv ? ["aiterm-mcp", "--private-env-stdin"] : ["aiterm-mcp"]))
|
|
232
286
|
: privateEnv ? posixCommand("exec aiterm-mcp --private-env-stdin") : remoteServerCommand(shell);
|
|
233
287
|
const { args: sshArgs, env } = sshInvocation(target, command);
|
|
288
|
+
// Request _meta is opaque to the relay; progressToken belongs to this hop's client, not the caller's.
|
|
289
|
+
const { progressToken: _hop, ...forwarded } = meta ?? {};
|
|
290
|
+
const request = Object.keys(forwarded).length ? { name, arguments: args, _meta: forwarded } : { name, arguments: args };
|
|
291
|
+
const shape = (result, version) => ({
|
|
292
|
+
content: result.content ?? [],
|
|
293
|
+
...(result.structuredContent ? { structuredContent: result.structuredContent } : {}),
|
|
294
|
+
...(result.isError ? { isError: true } : {}),
|
|
295
|
+
...(result._meta ? { _meta: result._meta } : {}),
|
|
296
|
+
remote_version: version,
|
|
297
|
+
});
|
|
298
|
+
if (target.trusted_ref && !privateEnv) {
|
|
299
|
+
const { result, version } = await callWarm(target, sshArgs, request, timeoutMs);
|
|
300
|
+
return shape(result, version);
|
|
301
|
+
}
|
|
234
302
|
const transport = privateEnv
|
|
235
303
|
? new SshStdioTransport(sshArgs, `${JSON.stringify({ schema: PRIVATE_ENV_SCHEMA, env: privateEnv })}\n`)
|
|
236
304
|
: new StdioClientTransport({ command: "ssh", args: sshArgs, env, stderr: "pipe" });
|
|
@@ -252,17 +320,8 @@ export async function callRemoteTool(target, name, args, timeoutMs = 600_000, pr
|
|
|
252
320
|
const detail = stderr.trim().split("\n").slice(-3).join(" / ") || (error instanceof Error ? error.message : String(error));
|
|
253
321
|
throw new AitermError(`REMOTE_CONNECT_FAILED: ${remoteLabel(target)} のAitermへ接続できません(${detail})`, 2);
|
|
254
322
|
}
|
|
255
|
-
// Request _meta is opaque to the relay; progressToken belongs to this hop's client, not the caller's.
|
|
256
|
-
const { progressToken: _hop, ...forwarded } = meta ?? {};
|
|
257
|
-
const request = Object.keys(forwarded).length ? { name, arguments: args, _meta: forwarded } : { name, arguments: args };
|
|
258
323
|
const result = await client.callTool(request, undefined, { timeout: timeoutMs, resetTimeoutOnProgress: true });
|
|
259
|
-
return
|
|
260
|
-
content: result.content ?? [],
|
|
261
|
-
...(result.structuredContent ? { structuredContent: result.structuredContent } : {}),
|
|
262
|
-
...(result.isError ? { isError: true } : {}),
|
|
263
|
-
...(result._meta ? { _meta: result._meta } : {}),
|
|
264
|
-
remote_version: client.getServerVersion()?.version ?? null,
|
|
265
|
-
};
|
|
324
|
+
return shape(result, client.getServerVersion()?.version ?? null);
|
|
266
325
|
}
|
|
267
326
|
finally {
|
|
268
327
|
await client.close().catch(() => { });
|
|
@@ -87,7 +87,7 @@ export function validateResumeCheckpoint(input) {
|
|
|
87
87
|
|| recipe.kind !== 'codex' || recipe.vendor_session_id !== scope.vendor_session_id || recipe.configuration_root !== scope.configuration_root
|
|
88
88
|
|| recipe.fast !== false || recipe.cwd !== m.cwd || recipe.executable !== m.agent_executable || recipe.model !== (m.model ?? null))
|
|
89
89
|
refuse();
|
|
90
|
-
if (Object.keys(recipe.environment).some(key => /(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIALS?|AUTH)$/i.test(key)))
|
|
90
|
+
if (recipe.secret_environment?.length || Object.keys(recipe.environment).some(key => /(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIALS?|AUTH)$/i.test(key)))
|
|
91
91
|
refuse();
|
|
92
92
|
const lineage = ['agent_role', 'parent_session_id', 'delegation_depth', 'lineage', 'delegation_allowed'];
|
|
93
93
|
if (lineage.some(k => m[k] !== undefined) && lineage.some(k => m[k] === undefined))
|
|
@@ -120,7 +120,7 @@ export function validateResumeCheckpoint(input) {
|
|
|
120
120
|
refuse();
|
|
121
121
|
const template = get(id, 'template', false);
|
|
122
122
|
if (template && (template.kind !== 'codex' || template.configuration_root !== scope.configuration_root
|
|
123
|
-
|| Object.keys(template.environment).some(key => /(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIALS?|AUTH)$/i.test(key))))
|
|
123
|
+
|| template.secret_environment?.length || Object.keys(template.environment).some(key => /(?:TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIALS?|AUTH)$/i.test(key))))
|
|
124
124
|
refuse();
|
|
125
125
|
const failure = get(id, 'failure', false);
|
|
126
126
|
if (failure && failure.session_id !== scope.session_id)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-mcp",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.41",
|
|
4
4
|
"mcpName": "io.github.kitepon/aiterm-mcp",
|
|
5
5
|
"description": "Persistent terminal MCP with one harness-based launcher for Claude Code, Codex CLI, Grok CLI, Cursor Agent CLI, and Antigravity CLI, plus durable PTYs for SSH, containers, and REPLs.",
|
|
6
6
|
"keywords": [
|