@andorra-labs/code 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/account-jev-savings.d.ts +4 -0
- package/dist/src/account-jev-savings.js +92 -0
- package/dist/src/acp-agent.js +2 -2
- package/dist/src/agent-execution.js +441 -53
- package/dist/src/agent-mcp.js +7 -1
- package/dist/src/agent-modifiers.js +5 -7
- package/dist/src/analytics.d.ts +19 -1
- package/dist/src/analytics.js +9 -1
- package/dist/src/andorra/entry.js +15 -6
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +8 -0
- package/dist/src/andorra/hosted.js +22 -3
- package/dist/src/andorra/streams.d.ts +49 -0
- package/dist/src/andorra/streams.js +98 -0
- package/dist/src/antigravity-acp.d.ts +28 -0
- package/dist/src/antigravity-acp.js +150 -0
- package/dist/src/antigravity-terminal.d.ts +2 -0
- package/dist/src/antigravity-terminal.js +214 -0
- package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
- package/dist/src/app-server/adaptive-routing-settings.js +69 -0
- package/dist/src/app-server/artifact.d.ts +14 -0
- package/dist/src/app-server/artifact.js +46 -0
- package/dist/src/app-server/legal-protocol.d.ts +33 -0
- package/dist/src/app-server/legal-protocol.js +16 -0
- package/dist/src/app-server/protocol.d.ts +34 -3
- package/dist/src/app-server/protocol.js +3 -1
- package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
- package/dist/src/app-server/telemetry-protocol.js +2 -0
- package/dist/src/app-server/telemetry.d.ts +38 -0
- package/dist/src/app-server/telemetry.js +163 -0
- package/dist/src/app-server/workspace.d.ts +21 -0
- package/dist/src/app-server/workspace.js +192 -10
- package/dist/src/app-server.d.ts +82 -26
- package/dist/src/app-server.js +1573 -417
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/auth/AuthManager.d.ts +11 -2
- package/dist/src/auth/AuthManager.js +56 -13
- package/dist/src/auth/index.d.ts +5 -1
- package/dist/src/auth/index.js +8 -1
- package/dist/src/auth/lifecycle.d.ts +13 -0
- package/dist/src/auth/lifecycle.js +109 -0
- package/dist/src/auth/store.d.ts +1 -0
- package/dist/src/auth/store.js +12 -0
- package/dist/src/auth/types.d.ts +12 -0
- package/dist/src/automation-runner.js +2 -0
- package/dist/src/automation-service.js +7 -2
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +16 -1
- package/dist/src/bridge/control.d.ts +3 -1
- package/dist/src/bridge/control.js +9 -3
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -0
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +3 -3
- package/dist/src/bridge/host-ops.js +14 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +70 -16
- package/dist/src/bridge/protocol.d.ts +1 -0
- package/dist/src/bridge/protocol.js +1 -0
- package/dist/src/browser-panel-tool.d.ts +12 -0
- package/dist/src/browser-panel-tool.js +30 -3
- package/dist/src/browser-runner.js +53 -62
- package/dist/src/browser-server.js +10 -4
- package/dist/src/browser-session.d.ts +14 -0
- package/dist/src/browser-session.js +57 -12
- package/dist/src/browser-view.d.ts +40 -1
- package/dist/src/browser-view.js +163 -9
- package/dist/src/browser-window-style.d.ts +27 -0
- package/dist/src/browser-window-style.js +244 -0
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +245 -62
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +44 -8
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +28 -7
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +9 -2
- package/dist/src/commands.js +69 -64
- package/dist/src/completion.js +13 -7
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +57 -17
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +38 -4
- package/dist/src/context-compaction.d.ts +10 -8
- package/dist/src/context-compaction.js +23 -24
- package/dist/src/deadline.js +1 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +16 -0
- package/dist/src/decision/DecisionManager.js +75 -2
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -3
- package/dist/src/decision/optimizationPolicy.d.ts +10 -0
- package/dist/src/decision/optimizationPolicy.js +23 -3
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +4 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +29 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +3 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +80 -1
- package/dist/src/efficiency.js +119 -4
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/extensions.d.ts +2 -0
- package/dist/src/extensions.js +30 -20
- package/dist/src/github-app/agent-writes.d.ts +1 -1
- package/dist/src/github-app/agent-writes.js +1 -1
- package/dist/src/github-app/client.d.ts +19 -0
- package/dist/src/github-app/client.js +21 -1
- package/dist/src/github-app/event-source.d.ts +0 -5
- package/dist/src/github-app/event-source.js +1 -31
- package/dist/src/github-app/metrics.d.ts +2 -5
- package/dist/src/github-app/metrics.js +2 -14
- package/dist/src/github-app/review-loop.d.ts +5 -5
- package/dist/src/github-app/review-loop.js +1 -1
- package/dist/src/github-app/review-node.d.ts +2 -2
- package/dist/src/github-app/triggers.d.ts +3 -3
- package/dist/src/github-names.d.ts +7 -0
- package/dist/src/github-names.js +7 -0
- package/dist/src/glob-search.d.ts +1 -0
- package/dist/src/glob-search.js +3 -0
- package/dist/src/google-provider.d.ts +5 -28
- package/dist/src/google-provider.js +6 -141
- package/dist/src/graph-editor-session.d.ts +1 -0
- package/dist/src/graph-editor-session.js +2 -0
- package/dist/src/graph-health.js +3 -1
- package/dist/src/graph-preview.d.ts +2 -0
- package/dist/src/graph-preview.js +1 -0
- package/dist/src/graph-runner.js +20 -14
- package/dist/src/graph-selection.d.ts +3 -1
- package/dist/src/graph-selection.js +2 -2
- package/dist/src/graph-server.d.ts +8 -1
- package/dist/src/graph-server.js +49 -12
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +49 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +23 -1
- package/dist/src/graphs.js +58 -7
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +39 -25
- package/dist/src/jev-savings.d.ts +4 -0
- package/dist/src/jev-savings.js +13 -0
- package/dist/src/legal/client.d.ts +25 -0
- package/dist/src/legal/client.js +47 -0
- package/dist/src/legal/command.d.ts +13 -0
- package/dist/src/legal/command.js +98 -0
- package/dist/src/legal/documents.d.ts +2 -0
- package/dist/src/legal/documents.js +14 -0
- package/dist/src/legal/gate.d.ts +13 -0
- package/dist/src/legal/gate.js +96 -0
- package/dist/src/legal/manifest.d.ts +21 -0
- package/dist/src/legal/manifest.js +23 -0
- package/dist/src/legal/receipt.d.ts +13 -0
- package/dist/src/legal/receipt.js +137 -0
- package/dist/src/legal/release.d.ts +27 -0
- package/dist/src/legal/release.js +28 -0
- package/dist/src/managed-sign-in.d.ts +0 -1
- package/dist/src/managed-sign-in.js +0 -13
- package/dist/src/membership.d.ts +27 -1
- package/dist/src/membership.js +139 -7
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.js +3 -7
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-pool.d.ts +99 -0
- package/dist/src/model-pool.js +136 -0
- package/dist/src/model-relay/local.js +5 -0
- package/dist/src/model-relay/remote.d.ts +2 -0
- package/dist/src/model-relay/remote.js +4 -0
- package/dist/src/model-tiers.d.ts +16 -1
- package/dist/src/model-tiers.js +31 -7
- package/dist/src/opencode-cli-provider.js +59 -56
- package/dist/src/opencode-provider.js +16 -13
- package/dist/src/permissions.d.ts +5 -0
- package/dist/src/permissions.js +7 -0
- package/dist/src/plan-pass.js +2 -1
- package/dist/src/pool-scores.d.ts +45 -0
- package/dist/src/pool-scores.js +40 -0
- package/dist/src/provider-connection.js +3 -17
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +116 -12
- package/dist/src/provider-request-error.d.ts +8 -0
- package/dist/src/provider-request-error.js +12 -0
- package/dist/src/provider-settings.d.ts +1 -1
- package/dist/src/provider-settings.js +36 -18
- package/dist/src/provider-turn-deadline.d.ts +39 -0
- package/dist/src/provider-turn-deadline.js +139 -0
- package/dist/src/providers.d.ts +8 -9
- package/dist/src/providers.js +211 -150
- package/dist/src/pull-request-merge.d.ts +1 -8
- package/dist/src/pull-request-merge.js +0 -4
- package/dist/src/pull-requests.d.ts +83 -57
- package/dist/src/pull-requests.js +266 -225
- package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
- package/dist/src/qa/runtime/ProcessManager.js +9 -3
- package/dist/src/react-runtime.js +245 -71
- package/dist/src/reasoning-probe-cloud.d.ts +10 -0
- package/dist/src/reasoning-probe-cloud.js +209 -0
- package/dist/src/remote/engine-pool.d.ts +3 -0
- package/dist/src/remote/engine-pool.js +88 -21
- package/dist/src/remote/recovery.d.ts +6 -0
- package/dist/src/remote/recovery.js +37 -0
- package/dist/src/run-records.d.ts +13 -3
- package/dist/src/run-records.js +59 -34
- package/dist/src/runtime.d.ts +47 -2
- package/dist/src/runtime.js +33 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +32 -0
- package/dist/src/sessions.js +65 -3
- package/dist/src/shell.js +6 -0
- package/dist/src/side-panel.js +36 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +4 -10
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/subagent-run.js +50 -50
- package/dist/src/subscription-usage.d.ts +50 -0
- package/dist/src/subscription-usage.js +92 -0
- package/dist/src/task-checkout.d.ts +157 -0
- package/dist/src/task-checkout.js +628 -0
- package/dist/src/telemetry/access.d.ts +18 -0
- package/dist/src/telemetry/access.js +43 -0
- package/dist/src/telemetry/aggregate.d.ts +18 -2
- package/dist/src/telemetry/aggregate.js +22 -9
- package/dist/src/telemetry/capture-core.d.ts +33 -14
- package/dist/src/telemetry/capture-core.js +124 -25
- package/dist/src/telemetry/capture.d.ts +3 -2
- package/dist/src/telemetry/capture.js +21 -1
- package/dist/src/telemetry/decision-capture.js +4 -0
- package/dist/src/telemetry/emitter.d.ts +6 -7
- package/dist/src/telemetry/emitter.js +124 -29
- package/dist/src/telemetry/gate.d.ts +41 -2
- package/dist/src/telemetry/gate.js +89 -4
- package/dist/src/telemetry/home.d.ts +1 -0
- package/dist/src/telemetry/home.js +20 -0
- package/dist/src/telemetry/identity.d.ts +6 -3
- package/dist/src/telemetry/identity.js +19 -6
- package/dist/src/telemetry/lifecycle.d.ts +8 -0
- package/dist/src/telemetry/lifecycle.js +76 -0
- package/dist/src/telemetry/outbox.d.ts +13 -8
- package/dist/src/telemetry/outbox.js +68 -12
- package/dist/src/telemetry/permission-command.d.ts +38 -0
- package/dist/src/telemetry/permission-command.js +208 -0
- package/dist/src/telemetry/permission.d.ts +168 -0
- package/dist/src/telemetry/permission.js +662 -0
- package/dist/src/telemetry/record-installation.d.ts +1 -0
- package/dist/src/telemetry/record-installation.js +9 -0
- package/dist/src/telemetry/region-data.d.ts +12 -0
- package/dist/src/telemetry/region-data.js +1314 -0
- package/dist/src/telemetry/region.d.ts +34 -0
- package/dist/src/telemetry/region.js +87 -0
- package/dist/src/telemetry/run-privacy.d.ts +11 -0
- package/dist/src/telemetry/run-privacy.js +165 -0
- package/dist/src/telemetry/schema.d.ts +27 -6
- package/dist/src/telemetry/schema.js +109 -14
- package/dist/src/telemetry/state.d.ts +11 -7
- package/dist/src/telemetry/state.js +39 -6
- package/dist/src/telemetry/surface.d.ts +20 -3
- package/dist/src/telemetry/surface.js +71 -15
- package/dist/src/telemetry/uploader.d.ts +6 -11
- package/dist/src/telemetry/uploader.js +72 -46
- package/dist/src/telemetry/uploads.d.ts +5 -1
- package/dist/src/telemetry/uploads.js +25 -6
- package/dist/src/telemetry/version.d.ts +5 -0
- package/dist/src/telemetry/version.js +34 -0
- package/dist/src/telemetry/workspace.d.ts +4 -1
- package/dist/src/telemetry/workspace.js +18 -3
- package/dist/src/terminal-ui.d.ts +3 -0
- package/dist/src/terminal-ui.js +48 -6
- package/dist/src/test-edit-guard.d.ts +30 -0
- package/dist/src/test-edit-guard.js +167 -2
- package/dist/src/thinking-level-detect.d.ts +13 -0
- package/dist/src/thinking-level-detect.js +52 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +131 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/todos.d.ts +2 -1
- package/dist/src/todos.js +24 -4
- package/dist/src/tool-argument-coercion.d.ts +7 -0
- package/dist/src/tool-argument-coercion.js +49 -0
- package/dist/src/tool-catalog.d.ts +2 -2
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +67 -22
- package/dist/src/transcript.js +3 -2
- package/dist/src/types.d.ts +48 -1
- package/dist/src/update.js +4 -0
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +85 -13
- package/dist/telemetry-consent-v1 +1 -0
- package/package.json +97 -96
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProviderConfig, type ReasoningEffort } from './providers.js';
|
|
2
|
+
type ProbeProvider = Pick<ProviderConfig, 'type' | 'baseUrl'>;
|
|
3
|
+
export declare function currentReasoningProbeSubject(signal?: AbortSignal): Promise<string | undefined>;
|
|
4
|
+
/** Undefined means no saved result was available. An empty list is a completed probe that accepted no levels. */
|
|
5
|
+
export declare function readReasoningProbe(provider: ProbeProvider, model: string, signal?: AbortSignal): Promise<ReasoningEffort[] | undefined>;
|
|
6
|
+
/** Persist only the latest result for a portable model, under the account that initiated the probe. */
|
|
7
|
+
export declare function queueReasoningProbe(directory: string, subject: string, provider: ProbeProvider, model: string, supported: readonly ReasoningEffort[]): Promise<void>;
|
|
8
|
+
/** Serialize uploads across engine processes and acknowledge only the exact result sent. */
|
|
9
|
+
export declare function flushReasoningProbes(directory: string, signal?: AbortSignal): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { decodeJwt } from 'jose';
|
|
6
|
+
import { getAccessToken, getAuthConfiguration, getAuthStatus } from './auth/index.js';
|
|
7
|
+
import { REASONING_EFFORTS } from './providers.js';
|
|
8
|
+
import { acquireSaveLock, SaveLockBusyError } from './save-lock.js';
|
|
9
|
+
const CLOUD_BUDGET_MS = 5_000;
|
|
10
|
+
const PROBE_MAX_BYTES = 256;
|
|
11
|
+
const MAX_PENDING_MODELS = 256;
|
|
12
|
+
const DRAIN_BUDGET_MS = 20_000;
|
|
13
|
+
const validSubject = (subject) => /^[a-z0-9-]{1,128}$/i.test(subject);
|
|
14
|
+
const validKey = (key) => /^[a-f0-9]{64}$/.test(key);
|
|
15
|
+
const errorCode = (error) => error.code;
|
|
16
|
+
const accountFolder = (directory, subject) => join(directory, 'reasoning-probes', subject);
|
|
17
|
+
function probeKey(provider, model) {
|
|
18
|
+
if (!URL.canParse(provider.baseUrl))
|
|
19
|
+
return undefined;
|
|
20
|
+
const url = new URL(provider.baseUrl);
|
|
21
|
+
const host = url.hostname.replace(/\.$/, '');
|
|
22
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search)
|
|
23
|
+
return undefined;
|
|
24
|
+
// A loopback endpoint can run an unrelated service with the same model id on another machine.
|
|
25
|
+
if (host === 'localhost' || host.endsWith('.localhost') || host === 'localhost.localdomain'
|
|
26
|
+
|| /^127(?:\.\d{1,3}){3}$/.test(host) || host === '0.0.0.0' || /^\[(?:::1|::|::ffff:7f[\da-f]{2}:[\da-f]{1,4})\]$/i.test(host))
|
|
27
|
+
return undefined;
|
|
28
|
+
const path = url.pathname.replace(/\/+$/, '');
|
|
29
|
+
return createHash('sha256').update(JSON.stringify([1, provider.type, url.origin, path, model])).digest('hex');
|
|
30
|
+
}
|
|
31
|
+
function cloudSignal(signal) {
|
|
32
|
+
const timeout = AbortSignal.timeout(CLOUD_BUDGET_MS);
|
|
33
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
34
|
+
}
|
|
35
|
+
export async function currentReasoningProbeSubject(signal) {
|
|
36
|
+
try {
|
|
37
|
+
const status = await getAuthStatus(cloudSignal(signal));
|
|
38
|
+
return status.signedIn ? status.subject : undefined;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function parseLevels(raw) {
|
|
45
|
+
if (!Array.isArray(raw) || raw.length > REASONING_EFFORTS.length)
|
|
46
|
+
return undefined;
|
|
47
|
+
const ordered = REASONING_EFFORTS.filter(level => raw.includes(level));
|
|
48
|
+
return ordered.length === raw.length ? ordered : undefined;
|
|
49
|
+
}
|
|
50
|
+
async function requestProbe(key, signal, supported, expectedSubject) {
|
|
51
|
+
try {
|
|
52
|
+
const bounded = cloudSignal(signal);
|
|
53
|
+
const subject = expectedSubject ?? await currentReasoningProbeSubject(bounded);
|
|
54
|
+
if (!subject)
|
|
55
|
+
return undefined;
|
|
56
|
+
const token = await getAccessToken(bounded);
|
|
57
|
+
if (!token || decodeJwt(token).sub !== subject)
|
|
58
|
+
return undefined;
|
|
59
|
+
const origin = new URL(getAuthConfiguration().apiBaseUrl);
|
|
60
|
+
if (origin.protocol !== 'https:' || origin.username || origin.password || origin.search || origin.hash)
|
|
61
|
+
return undefined;
|
|
62
|
+
const endpoint = origin.href.replace(/\/+$/, '') + '/reasoning-probes/' + key;
|
|
63
|
+
const response = await fetch(endpoint, {
|
|
64
|
+
method: supported === undefined ? 'GET' : 'PUT',
|
|
65
|
+
headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' },
|
|
66
|
+
body: supported === undefined ? undefined : JSON.stringify({ supported }),
|
|
67
|
+
redirect: 'error',
|
|
68
|
+
signal: bounded,
|
|
69
|
+
});
|
|
70
|
+
const reader = response.body?.getReader();
|
|
71
|
+
if (!reader)
|
|
72
|
+
return undefined;
|
|
73
|
+
const chunks = [];
|
|
74
|
+
let size = 0;
|
|
75
|
+
try {
|
|
76
|
+
if (!response.ok)
|
|
77
|
+
return undefined;
|
|
78
|
+
for (;;) {
|
|
79
|
+
const { done, value } = await reader.read();
|
|
80
|
+
if (done)
|
|
81
|
+
break;
|
|
82
|
+
size += value.length;
|
|
83
|
+
if (size > PROBE_MAX_BYTES)
|
|
84
|
+
return undefined;
|
|
85
|
+
chunks.push(value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await reader.cancel().catch(() => { });
|
|
90
|
+
reader.releaseLock();
|
|
91
|
+
}
|
|
92
|
+
if (await currentReasoningProbeSubject(bounded) !== subject)
|
|
93
|
+
return undefined;
|
|
94
|
+
const result = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
95
|
+
return parseLevels(result?.supported);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Undefined means no saved result was available. An empty list is a completed probe that accepted no levels. */
|
|
102
|
+
export async function readReasoningProbe(provider, model, signal) {
|
|
103
|
+
const key = probeKey(provider, model);
|
|
104
|
+
return key === undefined ? undefined : requestProbe(key, signal);
|
|
105
|
+
}
|
|
106
|
+
async function readPending(path) {
|
|
107
|
+
try {
|
|
108
|
+
const rows = JSON.parse(await readFile(path, 'utf8'));
|
|
109
|
+
if (!Array.isArray(rows) || rows.length > MAX_PENDING_MODELS)
|
|
110
|
+
throw new Error('Invalid pending reasoning probes');
|
|
111
|
+
return rows.map(row => {
|
|
112
|
+
const supported = parseLevels(row?.supported);
|
|
113
|
+
if (typeof row?.id !== 'string' || typeof row.key !== 'string' || !validKey(row.key) || supported === undefined) {
|
|
114
|
+
throw new Error('Invalid pending reasoning probe');
|
|
115
|
+
}
|
|
116
|
+
return { key: row.key, id: row.id, supported };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (errorCode(error) === 'ENOENT')
|
|
121
|
+
return [];
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function changePending(folder, change) {
|
|
126
|
+
let release;
|
|
127
|
+
for (let attempt = 0; !release; attempt++) {
|
|
128
|
+
try {
|
|
129
|
+
release = await acquireSaveLock(folder);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (!(error instanceof SaveLockBusyError) || attempt >= 40)
|
|
133
|
+
throw error;
|
|
134
|
+
await delay(25);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const path = join(folder, 'pending.json');
|
|
138
|
+
const temp = path + '.' + randomUUID() + '.tmp';
|
|
139
|
+
try {
|
|
140
|
+
const rows = await readPending(path);
|
|
141
|
+
const next = change(rows);
|
|
142
|
+
if (next === rows)
|
|
143
|
+
return;
|
|
144
|
+
if (!next.length) {
|
|
145
|
+
await unlink(path).catch(error => { if (errorCode(error) !== 'ENOENT')
|
|
146
|
+
throw error; });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await writeFile(temp, JSON.stringify(next), { flag: 'wx', mode: 0o600 });
|
|
150
|
+
for (let attempt = 0;; attempt++) {
|
|
151
|
+
try {
|
|
152
|
+
await rename(temp, path);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (attempt >= 4 || !['EPERM', 'EACCES', 'EBUSY'].includes(errorCode(error) ?? ''))
|
|
157
|
+
throw error;
|
|
158
|
+
await delay(25 * (attempt + 1));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
await unlink(temp).catch(() => { });
|
|
164
|
+
await release();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Persist only the latest result for a portable model, under the account that initiated the probe. */
|
|
168
|
+
export async function queueReasoningProbe(directory, subject, provider, model, supported) {
|
|
169
|
+
if (!validSubject(subject))
|
|
170
|
+
return;
|
|
171
|
+
const key = probeKey(provider, model);
|
|
172
|
+
const ordered = parseLevels(supported);
|
|
173
|
+
if (!key || !ordered)
|
|
174
|
+
return;
|
|
175
|
+
const entry = { key, id: randomUUID(), supported: ordered };
|
|
176
|
+
await changePending(accountFolder(directory, subject), rows => [...rows.filter(row => row.key !== key), entry].slice(-MAX_PENDING_MODELS));
|
|
177
|
+
}
|
|
178
|
+
/** Serialize uploads across engine processes and acknowledge only the exact result sent. */
|
|
179
|
+
export async function flushReasoningProbes(directory, signal) {
|
|
180
|
+
const subject = await currentReasoningProbeSubject(signal);
|
|
181
|
+
if (!subject || !validSubject(subject))
|
|
182
|
+
return;
|
|
183
|
+
const folder = accountFolder(directory, subject);
|
|
184
|
+
const path = join(folder, 'pending.json');
|
|
185
|
+
const timeout = AbortSignal.timeout(DRAIN_BUDGET_MS);
|
|
186
|
+
const bounded = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
187
|
+
try {
|
|
188
|
+
if (!(await readPending(path)).length)
|
|
189
|
+
return;
|
|
190
|
+
const release = await acquireSaveLock(join(folder, 'upload'));
|
|
191
|
+
try {
|
|
192
|
+
while (!bounded.aborted) {
|
|
193
|
+
const [row] = await readPending(path);
|
|
194
|
+
if (!row)
|
|
195
|
+
return;
|
|
196
|
+
const saved = await requestProbe(row.key, bounded, row.supported, subject);
|
|
197
|
+
if (saved === undefined || saved.length !== row.supported.length
|
|
198
|
+
|| !saved.every((level, index) => level === row.supported[index]))
|
|
199
|
+
return;
|
|
200
|
+
await changePending(folder, rows => rows.some(entry => entry.id === row.id)
|
|
201
|
+
? rows.filter(entry => entry.id !== row.id) : rows);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
await release();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch { /* Keep pending results for the next drain. */ }
|
|
209
|
+
}
|
|
@@ -63,6 +63,8 @@ type EventSink = (payload: {
|
|
|
63
63
|
event: string;
|
|
64
64
|
data: Record<string, unknown>;
|
|
65
65
|
}) => void;
|
|
66
|
+
/** Verify trusted installed build evidence WITHOUT executing a potentially reporting launcher. */
|
|
67
|
+
export declare function verifyConsentEngineCommand(command: string[]): Promise<string[]>;
|
|
66
68
|
export declare function relayEngineCommand(): string[];
|
|
67
69
|
export interface PathTranslation {
|
|
68
70
|
toHost(value: string): string;
|
|
@@ -93,6 +95,7 @@ export declare class RemoteEngineRelay {
|
|
|
93
95
|
private startsInFlight;
|
|
94
96
|
private readonly engines;
|
|
95
97
|
private readonly stopWatching;
|
|
98
|
+
private readonly recoveries;
|
|
96
99
|
constructor(directory: string, timing?: {
|
|
97
100
|
sinklessTtlMs?: number;
|
|
98
101
|
sweepMs?: number;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { legalMethodRequiresAcceptance, LEGAL_ACCEPTANCE_CAPABILITY } from '../app-server/legal-protocol.js';
|
|
1
2
|
import { spawn } from 'node:child_process';
|
|
2
3
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import { loadConfig } from '../config.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { loadFunctionalConfig as loadConfig } from '../config.js';
|
|
5
|
+
import { constants } from 'node:fs';
|
|
6
|
+
import { lstat, open, realpath } from 'node:fs/promises';
|
|
7
|
+
import { dirname, isAbsolute, join, basename } from 'node:path';
|
|
8
|
+
import { recoverRelayedRun } from './recovery.js';
|
|
9
|
+
import { TELEMETRY_CONSENT_CAPABILITY } from '../app-server/telemetry-protocol.js';
|
|
6
10
|
import { authorizedRoots } from './roots.js';
|
|
7
11
|
import { MODEL_RELAY_CONNECTION_PREFIX } from '../model-relay/wire.js';
|
|
8
12
|
import { REMOTE_ENGINE_INSTALL_FAILED_EVENT, REMOTE_ENGINE_INSTALLING_EVENT, REMOTE_ENGINE_READY_EVENT } from '../app-server/protocol.js';
|
|
@@ -38,10 +42,10 @@ const PULL_REQUEST_PHASE4_ANSWERS = ['sessions.pullRequest.comment', 'sessions.p
|
|
|
38
42
|
// The GitHub App (design/specs/github-app.md): its status is a read; connecting and disconnecting change the account's link,
|
|
39
43
|
// and setAgentWrites changes who the agent's PR replies post as on that machine.
|
|
40
44
|
const GITHUB_APP_WRITES = ['github.connect', 'github.disconnect', 'github.setAgentWrites'];
|
|
41
|
-
const LARGE_RESPONSE_METHODS = new Set(['runs.get', 'workspace.files', 'workspace.search', 'sessions.pullRequest.details', 'sessions.pullRequest.files', ...PULL_REQUEST_REVIEW_ANSWERS, ...PULL_REQUEST_MERGE_ANSWERS, ...PULL_REQUEST_PHASE4_ANSWERS, 'workspace.diff', 'workspace.git', 'sessions.trajectory', 'browser.view.selection', 'attachments.read', 'sessions.changes.list', 'sessions.changes.get']);
|
|
45
|
+
const LARGE_RESPONSE_METHODS = new Set(['runs.get', 'workspace.files', 'workspace.search', 'sessions.pullRequest.details', 'sessions.pullRequest.files', ...PULL_REQUEST_REVIEW_ANSWERS, ...PULL_REQUEST_MERGE_ANSWERS, ...PULL_REQUEST_PHASE4_ANSWERS, 'workspace.diff', 'workspace.git', 'sessions.trajectory', 'sessions.artifact.read', 'browser.view.selection', 'attachments.read', 'attachments.text', 'sessions.changes.list', 'sessions.changes.get']);
|
|
42
46
|
const PRIMARY_METHODS = new Set([
|
|
43
|
-
'sessions.list', 'sessions.get', 'sessions.create', 'sessions.rename', 'sessions.setJev', 'sessions.setArchived', 'sessions.setPinned', 'sessions.delete',
|
|
44
|
-
'sessions.trajectory',
|
|
47
|
+
'sessions.list', 'sessions.get', 'sessions.create', 'sessions.rename', 'sessions.setJev', 'sessions.setArchived', 'sessions.setPinned', 'sessions.setReviewed', 'sessions.delete',
|
|
48
|
+
'sessions.trajectory', 'sessions.artifact.read',
|
|
45
49
|
// The run a task engine is serving, with the approval or question it waits on: how a window recovers one whose
|
|
46
50
|
// announcement was too large to cross the relay.
|
|
47
51
|
'run.current',
|
|
@@ -53,10 +57,13 @@ const PRIMARY_METHODS = new Set([
|
|
|
53
57
|
'github.status', ...GITHUB_APP_WRITES,
|
|
54
58
|
'runs.list', 'runs.get', 'timers.list',
|
|
55
59
|
'workspace.tree', 'workspace.read', 'workspace.files', 'workspace.search', 'workspace.linkBase', 'workspace.git', 'workspace.branches', 'workspace.checkout', 'workspace.diff',
|
|
56
|
-
'graphs.list', 'graphs.get', 'graphs.select', 'graphs.visibility.set', 'graphs.visibility.import',
|
|
57
|
-
'attachments.read',
|
|
60
|
+
'graphs.list', 'graphs.get', 'graphs.select', 'graphs.checkModels', 'graphs.visibility.set', 'graphs.visibility.import',
|
|
61
|
+
'attachments.read', 'attachments.text',
|
|
58
62
|
'config.get', 'projects.list', 'projects.add', 'projects.remove', 'projects.relink',
|
|
59
|
-
'
|
|
63
|
+
// Policy acceptance for this machine's own home: a desktop reads the status and documents and records an explicit
|
|
64
|
+
// acceptance here, since a receipt on the desktop is not one on this machine.
|
|
65
|
+
'legal.status', 'legal.documents', 'legal.accept',
|
|
66
|
+
'extensions.list', 'project.extensions', 'workspace.permission',
|
|
60
67
|
'browser.runtime.status', 'browser.runtime.install',
|
|
61
68
|
'browser.view.status', 'browser.view.open', 'browser.view.navigate', 'browser.view.go', 'browser.view.activate',
|
|
62
69
|
'browser.view.closeTab', 'browser.view.show', 'browser.view.hide', 'browser.view.stream', 'browser.view.input', 'browser.view.selection',
|
|
@@ -73,11 +80,11 @@ const MODEL_RELAY_METHODS = new Set(['model.relay.claim', 'model.relay.progress'
|
|
|
73
80
|
const RUN_TARGET_METHODS = new Set(['run.setModel', 'run.setPermissions', 'run.cancel', 'run.steer', 'run.approve', 'run.answer', 'browser.panel.result', ...MODEL_RELAY_METHODS]);
|
|
74
81
|
const TERMINAL_METHODS = new Set(['terminal.open', 'terminal.write', 'terminal.resize', 'terminal.close', 'terminal.closeAll']);
|
|
75
82
|
const ALLOWED_METHODS = new Set([...PRIMARY_METHODS, ...RUN_START_METHODS, ...RUN_TARGET_METHODS, ...TERMINAL_METHODS]);
|
|
76
|
-
const SESSION_MUTATION_METHODS = new Set(['sessions.rename', 'sessions.setJev', 'sessions.setArchived', 'sessions.setPinned', 'sessions.delete']);
|
|
83
|
+
const SESSION_MUTATION_METHODS = new Set(['sessions.rename', 'sessions.setJev', 'sessions.setArchived', 'sessions.setPinned', 'sessions.setReviewed', 'sessions.delete']);
|
|
77
84
|
const MUTATING_METHODS = new Set([
|
|
78
85
|
...RUN_START_METHODS, ...RUN_TARGET_METHODS, ...SESSION_MUTATION_METHODS, ...PULL_REQUEST_REVIEW_WRITES, ...PULL_REQUEST_MERGE_WRITES, ...PULL_REQUEST_PHASE4_WRITES, ...GITHUB_APP_WRITES, 'sessions.skill.update', 'sessions.changes.keep', 'sessions.changes.undo',
|
|
79
86
|
'terminal.open', 'terminal.write', 'terminal.close', 'terminal.closeAll', 'workspace.checkout', 'projects.add', 'projects.remove', 'projects.relink',
|
|
80
|
-
'graphs.visibility.set', 'graphs.visibility.import',
|
|
87
|
+
'graphs.visibility.set', 'graphs.visibility.import', 'legal.accept',
|
|
81
88
|
'browser.runtime.install', 'browser.view.open', 'browser.view.navigate', 'browser.view.go', 'browser.view.activate',
|
|
82
89
|
'browser.view.closeTab', 'browser.view.show', 'browser.view.hide', 'browser.view.stream', 'browser.view.input', 'browser.cookies.import',
|
|
83
90
|
'browser.panel.op', 'browser.panel.cancel',
|
|
@@ -135,10 +142,13 @@ class ChildEngine {
|
|
|
135
142
|
this.id = id;
|
|
136
143
|
this.onEvent = onEvent;
|
|
137
144
|
this.onExit = onExit;
|
|
145
|
+
const environment = { ...engineEnvironment(home), ANDORRA_TELEMETRY_POLICY: 'ask' };
|
|
146
|
+
// Children need only the protective policy, not the controller's raw local hints.
|
|
147
|
+
delete environment.ANDORRA_TELEMETRY_RENDERER_HINTS;
|
|
138
148
|
this.child = spawn(command[0], command.slice(1), {
|
|
139
149
|
windowsHide: true,
|
|
140
150
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
141
|
-
env:
|
|
151
|
+
env: environment,
|
|
142
152
|
});
|
|
143
153
|
this.ready = new Promise((resolve, reject) => {
|
|
144
154
|
this.resolveReady = resolve;
|
|
@@ -180,6 +190,10 @@ class ChildEngine {
|
|
|
180
190
|
if (parsed.event === 'ready') {
|
|
181
191
|
const capabilities = parsed.data?.capabilities;
|
|
182
192
|
this.advertised = Array.isArray(capabilities) ? capabilities.filter((entry) => typeof entry === 'string') : [];
|
|
193
|
+
if (!this.supports(TELEMETRY_CONSENT_CAPABILITY)) {
|
|
194
|
+
this.fail(new Error('Telemetry permission unavailable: a consent-capable live engine is required. Update and deliberately restart older engines.'));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
183
197
|
this.resolveReady?.();
|
|
184
198
|
return;
|
|
185
199
|
}
|
|
@@ -220,6 +234,8 @@ class ChildEngine {
|
|
|
220
234
|
return this.advertised.includes(capability);
|
|
221
235
|
}
|
|
222
236
|
request(method, params, timeoutMs) {
|
|
237
|
+
if ((legalMethodRequiresAcceptance(method) || method.startsWith('legal.')) && !this.supports(LEGAL_ACCEPTANCE_CAPABILITY))
|
|
238
|
+
return Promise.reject(new ChildError('unsupported', 'Update the remote engine for policy acceptance before coding work.'));
|
|
223
239
|
const stdin = this.child.stdin;
|
|
224
240
|
if (this.stopped || !stdin || stdin.destroyed)
|
|
225
241
|
return Promise.reject(new ChildError('closed', `Engine ${this.id} is not running.`));
|
|
@@ -270,6 +286,45 @@ class ChildEngine {
|
|
|
270
286
|
});
|
|
271
287
|
}
|
|
272
288
|
}
|
|
289
|
+
/** Verify trusted installed build evidence WITHOUT executing a potentially reporting launcher. */
|
|
290
|
+
export async function verifyConsentEngineCommand(command) {
|
|
291
|
+
const unavailable = () => new RelayRefusal('remote', 'Telemetry permission unavailable: a consent-capable Andorra Code CLI build is required. Update the CLI and deliberately restart older engines. Existing engines have not been stopped.');
|
|
292
|
+
try {
|
|
293
|
+
const node = command.length === 4 && await realpath(command[0]) === await realpath(process.execPath);
|
|
294
|
+
const entry = node ? command[1] : command.length === 3 ? command[0] : undefined;
|
|
295
|
+
const args = command.slice(node ? 2 : 1);
|
|
296
|
+
if (!entry || !isAbsolute(entry) || args.length !== 2 || args[0] !== 'app-server' || args[1] !== '--stdio')
|
|
297
|
+
throw unavailable();
|
|
298
|
+
const actual = await realpath(entry);
|
|
299
|
+
if (basename(actual) !== 'cli.js' || basename(dirname(actual)) !== 'src' || basename(dirname(dirname(actual))) !== 'dist')
|
|
300
|
+
throw unavailable();
|
|
301
|
+
const info = await lstat(actual);
|
|
302
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
303
|
+
throw unavailable();
|
|
304
|
+
const markerPath = join(dirname(dirname(actual)), 'telemetry-consent-v1');
|
|
305
|
+
const markerInfo = await lstat(markerPath);
|
|
306
|
+
if (!markerInfo.isFile() || markerInfo.isSymbolicLink())
|
|
307
|
+
throw unavailable();
|
|
308
|
+
const marker = await open(markerPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
309
|
+
try {
|
|
310
|
+
const expected = Buffer.from('config.analytics.consent:1\n');
|
|
311
|
+
const stat = await marker.stat();
|
|
312
|
+
if (!stat.isFile() || stat.size !== expected.length)
|
|
313
|
+
throw unavailable();
|
|
314
|
+
const buffer = Buffer.alloc(expected.length + 1);
|
|
315
|
+
const { bytesRead } = await marker.read(buffer, 0, buffer.length, 0);
|
|
316
|
+
if (bytesRead !== expected.length || !buffer.subarray(0, bytesRead).equals(expected))
|
|
317
|
+
throw unavailable();
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
await marker.close();
|
|
321
|
+
}
|
|
322
|
+
return node ? [command[0], actual, ...args] : [actual, ...args];
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
throw unavailable();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
273
328
|
// The launcher's variables are for the host it started: an engine that saw them would act as a host under the launcher.
|
|
274
329
|
const LAUNCHER_VARIABLES = new Set(['ANDORRA_BRIDGE_ENGINES', 'ANDORRA_BRIDGE_LAUNCHER_PID', 'ANDORRA_BRIDGE_NPM']);
|
|
275
330
|
function engineEnvironment(home) {
|
|
@@ -327,6 +382,7 @@ export class RemoteEngineRelay {
|
|
|
327
382
|
startsInFlight = 0;
|
|
328
383
|
engines;
|
|
329
384
|
stopWatching;
|
|
385
|
+
recoveries = new Set();
|
|
330
386
|
constructor(directory, timing = {}, options = {}) {
|
|
331
387
|
this.directory = directory;
|
|
332
388
|
this.timing = timing;
|
|
@@ -413,7 +469,7 @@ export class RemoteEngineRelay {
|
|
|
413
469
|
childDeadline(body) {
|
|
414
470
|
const asked = typeof body.deadlineMs === 'number' && body.deadlineMs > 0 ? body.deadlineMs : 120_000;
|
|
415
471
|
const ceiling = LONG_DEADLINE_METHODS.has(body.method) ? MAX_LONG_CHILD_DEADLINE_MS : MAX_CHILD_DEADLINE_MS;
|
|
416
|
-
const bounded = Math.min(Math.max(asked, 5_000), ceiling);
|
|
472
|
+
const bounded = Math.min(Math.max(asked, MUTATING_METHODS.has(body.method) ? 1 : 5_000), ceiling);
|
|
417
473
|
if (MUTATING_METHODS.has(body.method))
|
|
418
474
|
return bounded;
|
|
419
475
|
return bounded + CHILD_DEADLINE_SLACK_MS;
|
|
@@ -904,9 +960,9 @@ export class RemoteEngineRelay {
|
|
|
904
960
|
onChildExit(engineId) {
|
|
905
961
|
const interrupted = this.activeRuns.get(engineId);
|
|
906
962
|
if (interrupted !== undefined && typeof interrupted.runId === 'string') {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
963
|
+
const recovery = recoverRelayedRun(this.directory, interrupted.runId).catch(() => undefined);
|
|
964
|
+
this.recoveries.add(recovery);
|
|
965
|
+
void recovery.finally(() => this.recoveries.delete(recovery));
|
|
910
966
|
}
|
|
911
967
|
const exited = this.children.get(engineId);
|
|
912
968
|
this.children.delete(engineId);
|
|
@@ -930,25 +986,35 @@ export class RemoteEngineRelay {
|
|
|
930
986
|
}
|
|
931
987
|
async engine(id) {
|
|
932
988
|
const existing = this.children.get(id);
|
|
933
|
-
if (existing)
|
|
989
|
+
if (existing) {
|
|
990
|
+
await existing.ready;
|
|
991
|
+
if (!existing.supports(TELEMETRY_CONSENT_CAPABILITY))
|
|
992
|
+
throw new RelayRefusal('remote', 'Telemetry permission unavailable: update and deliberately restart this older engine. Existing engines have not been stopped.');
|
|
934
993
|
return existing;
|
|
994
|
+
}
|
|
935
995
|
if (id !== REMOTE_PRIMARY_ENGINE)
|
|
936
996
|
throw new RelayRefusal('not-found', `No engine ${id} is serving this machine's remote surface.`);
|
|
937
997
|
return this.spawnChild(REMOTE_PRIMARY_ENGINE);
|
|
938
998
|
}
|
|
939
999
|
async spawnChild(id, version) {
|
|
940
1000
|
const existing = this.children.get(id);
|
|
941
|
-
if (existing)
|
|
1001
|
+
if (existing) {
|
|
1002
|
+
await existing.ready;
|
|
1003
|
+
if (!existing.supports(TELEMETRY_CONSENT_CAPABILITY))
|
|
1004
|
+
throw new RelayRefusal('remote', 'Telemetry permission unavailable: update and deliberately restart this older engine. Existing engines have not been stopped.');
|
|
942
1005
|
return existing;
|
|
1006
|
+
}
|
|
943
1007
|
if (this.closed)
|
|
944
1008
|
throw new RelayRefusal('remote', 'The remote engine relay is shutting down.');
|
|
945
1009
|
this.refuseAtEngineCap(id);
|
|
946
|
-
const command = await this.engineCommand(version);
|
|
1010
|
+
const command = await verifyConsentEngineCommand(await this.engineCommand(version));
|
|
947
1011
|
if (this.closed)
|
|
948
1012
|
throw new RelayRefusal('remote', 'The remote engine relay is shutting down.');
|
|
949
1013
|
const raced = this.children.get(id);
|
|
950
|
-
if (raced)
|
|
1014
|
+
if (raced) {
|
|
1015
|
+
await raced.ready;
|
|
951
1016
|
return raced;
|
|
1017
|
+
}
|
|
952
1018
|
// Checked again: other starts may have spawned while this one waited for its command.
|
|
953
1019
|
this.refuseAtEngineCap(id);
|
|
954
1020
|
const created = new ChildEngine(id, command, this.directory, (engineId, event, data) => this.enqueue(engineId, event, data), engineId => this.onChildExit(engineId));
|
|
@@ -1147,6 +1213,7 @@ export class RemoteEngineRelay {
|
|
|
1147
1213
|
for (const child of children)
|
|
1148
1214
|
this.releaseEngine(child);
|
|
1149
1215
|
await Promise.all(children.map(child => child.stop().catch(() => undefined)));
|
|
1216
|
+
await Promise.all(this.recoveries);
|
|
1150
1217
|
}
|
|
1151
1218
|
}
|
|
1152
1219
|
/** How long an engine that keeps failing to say what wakes it holds is taken to hold one. */
|
|
@@ -1169,5 +1236,5 @@ function rewritePaths(value, paths) {
|
|
|
1169
1236
|
return value;
|
|
1170
1237
|
}
|
|
1171
1238
|
// A claim's answer carries a model request's payload: model input, never a path on this machine, so it is not rewritten.
|
|
1172
|
-
const OPAQUE_RESPONSE_METHODS = new Set(['model.relay.claim', 'browser.view.selection', 'browser.view.cursor', 'sessions.changes.list', 'sessions.changes.get', 'sessions.pullRequest.details', 'sessions.pullRequest.files', ...PULL_REQUEST_REVIEW_ANSWERS, ...PULL_REQUEST_MERGE_ANSWERS, 'sessions.pullRequest.create', ...PULL_REQUEST_PHASE4_ANSWERS]);
|
|
1239
|
+
const OPAQUE_RESPONSE_METHODS = new Set(['sessions.artifact.read', 'model.relay.claim', 'browser.view.selection', 'browser.view.cursor', 'attachments.text', 'sessions.changes.list', 'sessions.changes.get', 'sessions.pullRequest.details', 'sessions.pullRequest.files', ...PULL_REQUEST_REVIEW_ANSWERS, ...PULL_REQUEST_MERGE_ANSWERS, 'sessions.pullRequest.create', ...PULL_REQUEST_PHASE4_ANSWERS]);
|
|
1173
1240
|
export { REMOTE_PROJECT_PREFIX, isRemoteProjectSpelling, rootPartOf };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recovery's nested helpers currently read process-local signals. Isolate this rare path rather
|
|
3
|
+
* than escalating the primary host engine on a viewer's behalf. Use a process, not a thread: if
|
|
4
|
+
* bounded recovery must be killed, interprocess locks must recognize its owner PID as dead.
|
|
5
|
+
*/
|
|
6
|
+
export declare function recoverRelayedRun(home: string, runId: string): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { reconcileInterruptedRuns } from '../run-records.js';
|
|
4
|
+
import { configuredSurface, reportInterruptedRuns } from '../telemetry/surface.js';
|
|
5
|
+
import { readLocalTelemetrySignals } from '../telemetry/region.js';
|
|
6
|
+
/**
|
|
7
|
+
* Recovery's nested helpers currently read process-local signals. Isolate this rare path rather
|
|
8
|
+
* than escalating the primary host engine on a viewer's behalf. Use a process, not a thread: if
|
|
9
|
+
* bounded recovery must be killed, interprocess locks must recognize its owner PID as dead.
|
|
10
|
+
*/
|
|
11
|
+
export function recoverRelayedRun(home, runId) {
|
|
12
|
+
const env = { ...process.env, ANDORRA_TELEMETRY_POLICY: 'ask' };
|
|
13
|
+
delete env.ANDORRA_TELEMETRY_RENDERER_HINTS;
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), home, runId], { env, stdio: 'ignore', windowsHide: true });
|
|
16
|
+
const timeout = setTimeout(() => { child.kill('SIGKILL'); }, 30_000);
|
|
17
|
+
let failure;
|
|
18
|
+
child.once('error', error => { failure = error; });
|
|
19
|
+
child.once('close', code => {
|
|
20
|
+
clearTimeout(timeout);
|
|
21
|
+
if (code === 0 && !failure)
|
|
22
|
+
resolve();
|
|
23
|
+
else
|
|
24
|
+
reject(failure ?? new Error('Remote run recovery did not complete.'));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
29
|
+
if (process.env.ANDORRA_TELEMETRY_POLICY !== 'ask')
|
|
30
|
+
throw new Error('Remote run recovery requires its private ask-only environment.');
|
|
31
|
+
const [home, runId] = process.argv.slice(2);
|
|
32
|
+
if (!home || !runId)
|
|
33
|
+
throw new Error('Remote run recovery requires a home and run id.');
|
|
34
|
+
const signals = () => ({ ...readLocalTelemetrySignals(), policyEnvironment: 'ask' });
|
|
35
|
+
const recovered = await reconcileInterruptedRuns(home, new Set([runId]), { includePending: true });
|
|
36
|
+
await reportInterruptedRuns({ home, signals, surface: configuredSurface('remote') }, recovered.interrupted);
|
|
37
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type SavedSession } from './sessions.js';
|
|
2
2
|
import type { RunCheckpoint } from './run-progress.js';
|
|
3
|
+
import type { TelemetryAccess, TelemetryEpoch } from './telemetry/access.js';
|
|
4
|
+
export { scrubRuns, functionalRunRecord } from './telemetry/run-privacy.js';
|
|
3
5
|
export declare function runRecordsDirectory(directory?: string): string;
|
|
4
6
|
export type RunRecordStatus = 'running' | 'interrupted' | 'succeeded' | 'exhausted' | 'cancelled' | 'infrastructure_error' | 'needs_clarification';
|
|
5
7
|
export interface OpenRunRecord {
|
|
@@ -32,6 +34,8 @@ export interface OpenRunRecord {
|
|
|
32
34
|
runState?: Record<string, unknown>;
|
|
33
35
|
reasoningEffort?: string;
|
|
34
36
|
overrideAllNodes?: boolean;
|
|
37
|
+
/** The run started on Auto: its provider and model were only the starting pair, so adaptive routing could choose. */
|
|
38
|
+
autoModel?: boolean;
|
|
35
39
|
nodeModelOverrides?: Record<string, {
|
|
36
40
|
provider: string;
|
|
37
41
|
model: string;
|
|
@@ -39,6 +43,7 @@ export interface OpenRunRecord {
|
|
|
39
43
|
liveModelChanged?: boolean;
|
|
40
44
|
surface?: 'cli' | 'desktop' | 'remote' | 'subagent';
|
|
41
45
|
telemetry?: {
|
|
46
|
+
epoch?: TelemetryEpoch;
|
|
42
47
|
runId: string;
|
|
43
48
|
nodes: number;
|
|
44
49
|
subagents: boolean;
|
|
@@ -75,7 +80,12 @@ export interface OpenRunClaim {
|
|
|
75
80
|
}
|
|
76
81
|
export declare function clearOpenRunClaim(directory: string, runId: string): Promise<void>;
|
|
77
82
|
export declare function removeOpenRunRecord(directory: string, runId: string): Promise<void>;
|
|
78
|
-
|
|
83
|
+
/** Public persistence boundary; blocked/stale writers can save only functional data. */
|
|
84
|
+
export declare function writeOpenRunRecord(directory: string, record: OpenRunRecord, access?: TelemetryAccess): Promise<void>;
|
|
85
|
+
/** Phase C finalizers must use this instead of raw writeFile/writeSessionSnapshot. */
|
|
86
|
+
export declare function writeFinalRunRecord(directory: string, record: Record<string, unknown> & {
|
|
87
|
+
id: string;
|
|
88
|
+
}, access?: TelemetryAccess): Promise<void>;
|
|
79
89
|
export declare function isPidAlive(pid: number): boolean;
|
|
80
90
|
export declare function processStartedAt(): string;
|
|
81
91
|
export declare function processNonce(): string;
|
|
@@ -152,7 +162,7 @@ export interface CheckpointFailure {
|
|
|
152
162
|
at?: string;
|
|
153
163
|
}
|
|
154
164
|
export declare function checkpointFailure(directory: string, runId: string): Promise<CheckpointFailure | undefined>;
|
|
155
|
-
export declare function writeRunCheckpoint(directory: string, runId: string, checkpoint: RunCheckpoint): Promise<void>;
|
|
165
|
+
export declare function writeRunCheckpoint(directory: string, runId: string, checkpoint: RunCheckpoint, access?: TelemetryAccess): Promise<void>;
|
|
156
166
|
export declare function readRunCheckpoint(directory: string, runId: string, nodeId: string): Promise<RunCheckpoint | undefined>;
|
|
157
167
|
export declare function readRunCheckpoints(directory: string, runId: string): Promise<RunCheckpoint[]>;
|
|
158
168
|
export declare function removeRunCheckpoint(directory: string, runId: string): Promise<void>;
|
|
@@ -165,4 +175,4 @@ export declare function acquireSessionMutationLock(directory: string, sessionId:
|
|
|
165
175
|
waitMs?: number;
|
|
166
176
|
intervalMs?: number;
|
|
167
177
|
}): Promise<() => Promise<void>>;
|
|
168
|
-
export declare function clearInterruptedTelemetry(directory: string, runIds: string[]): Promise<void>;
|
|
178
|
+
export declare function clearInterruptedTelemetry(directory: string, runIds: string[], access?: TelemetryAccess): Promise<void>;
|