@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
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { type TelemetryEpoch, type TelemetryAccess } from './access.js';
|
|
1
2
|
import type { TelemetryEvent } from './schema.js';
|
|
2
3
|
export declare const OUTBOX_EVENT_LIMIT = 5000;
|
|
3
4
|
export declare const OUTBOX_BYTE_LIMIT: number;
|
|
4
5
|
export declare const OUTBOX_MAX_AGE_MS: number;
|
|
5
6
|
export interface OutboxEntry {
|
|
7
|
+
/** Protected-only local epoch. Never part of e / the wire schema. */
|
|
8
|
+
epoch?: TelemetryEpoch;
|
|
6
9
|
g: number;
|
|
7
10
|
run: string | null;
|
|
8
11
|
e: TelemetryEvent;
|
|
@@ -11,17 +14,19 @@ export declare function outboxDirectory(telemetry: string): string;
|
|
|
11
14
|
export declare function sanitizeEngineId(engineId: string): string;
|
|
12
15
|
export declare function spoolPath(telemetry: string, engineId: string): string;
|
|
13
16
|
export declare function serialize(entry: OutboxEntry): string;
|
|
14
|
-
export declare function readSpool(path: string): Promise<OutboxEntry[]>;
|
|
15
17
|
export declare function enforceLimits(entries: OutboxEntry[], now?: number): OutboxEntry[];
|
|
16
18
|
export declare function pruneOld(entries: OutboxEntry[], now?: number): OutboxEntry[];
|
|
17
19
|
export declare function pruneGeneration(entries: OutboxEntry[], generation: number): OutboxEntry[];
|
|
18
|
-
|
|
20
|
+
/** Public boundaries all enter privacy BEFORE even creating a telemetry/spool lock. */
|
|
21
|
+
export declare function readSpool(path: string, access?: TelemetryAccess): Promise<OutboxEntry[]>;
|
|
22
|
+
export declare function enqueue(telemetry: string, engineId: string, entry: OutboxEntry, access?: TelemetryAccess): Promise<boolean>;
|
|
19
23
|
export declare function sweepOutbox(telemetry: string, ownName?: string, limits?: {
|
|
20
24
|
events?: number;
|
|
21
25
|
bytes?: number;
|
|
22
|
-
}): Promise<void>;
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
26
|
+
}, access?: TelemetryAccess): Promise<void>;
|
|
27
|
+
/** Legacy outside opt-out only. Protected cleanup uses known-path detachment, never queue parsing. */
|
|
28
|
+
export declare function purgeOutbox(telemetry: string, access?: TelemetryAccess): Promise<void>;
|
|
29
|
+
export declare function withSpoolLock<T>(telemetry: string, name: string, run: () => Promise<T>, access?: TelemetryAccess): Promise<T | undefined>;
|
|
30
|
+
export declare function withSpoolLockWait<T>(telemetry: string, name: string, run: () => Promise<T>, access?: TelemetryAccess): Promise<T | undefined>;
|
|
31
|
+
export declare function spoolNames(telemetry: string, access?: TelemetryAccess): Promise<string[]>;
|
|
32
|
+
export declare function rewriteSpool(telemetry: string, name: string, entries: OutboxEntry[], access?: TelemetryAccess): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { appendFile, mkdir, readFile, rename, rm, readdir, stat, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { admitTelemetryDirectory, spoolTelemetryDirectory, epochMatches, epochLease, telemetryEpoch, telemetryDirectoryHome } from './access.js';
|
|
5
|
+
import { currentTelemetryAdmission, telemetryChoiceRequested } from './permission.js';
|
|
4
6
|
import { acquireSaveLock, SaveLockBusyError } from '../save-lock.js';
|
|
5
7
|
import { isPidAlive } from '../run-records.js';
|
|
6
8
|
import { cancelActiveUploads } from './uploads.js';
|
|
@@ -30,7 +32,7 @@ function parse(lines) {
|
|
|
30
32
|
return entries;
|
|
31
33
|
}
|
|
32
34
|
export function serialize(entry) { return JSON.stringify(entry) + '\n'; }
|
|
33
|
-
|
|
35
|
+
async function readSpoolAdmitted(path) {
|
|
34
36
|
try {
|
|
35
37
|
return parse(await readFile(path, 'utf8'));
|
|
36
38
|
}
|
|
@@ -81,7 +83,8 @@ export function pruneOld(entries, now = Date.now()) {
|
|
|
81
83
|
export function pruneGeneration(entries, generation) {
|
|
82
84
|
return entries.filter(entry => entry.g >= generation);
|
|
83
85
|
}
|
|
84
|
-
|
|
86
|
+
/** False when nothing was written: the admission ended, or another process asked to change the choice. */
|
|
87
|
+
async function enqueueAdmitted(telemetry, engineId, entry) {
|
|
85
88
|
const directory = outboxDirectory(telemetry);
|
|
86
89
|
await mkdir(directory, { recursive: true });
|
|
87
90
|
const path = spoolPath(telemetry, engineId);
|
|
@@ -92,24 +95,33 @@ export async function enqueue(telemetry, engineId, entry) {
|
|
|
92
95
|
if (bounded.length !== entries.length)
|
|
93
96
|
await write(path, bounded);
|
|
94
97
|
};
|
|
98
|
+
const admission = currentTelemetryAdmission();
|
|
95
99
|
let delay = 25;
|
|
96
|
-
for (;;) {
|
|
100
|
+
for (let attempt = 0;; attempt++) {
|
|
101
|
+
// A choice another process is waiting to save wins over a queued report: give the admission up instead of retrying.
|
|
102
|
+
if (admission?.signal.aborted || (admission && telemetryChoiceRequested(admission.lease.home)))
|
|
103
|
+
return false;
|
|
104
|
+
if (admission?.lease.mode === 'consent' && attempt >= 24)
|
|
105
|
+
throw new SaveLockBusyError();
|
|
97
106
|
const name = `${sanitizeEngineId(engineId)}.jsonl`;
|
|
98
107
|
const done = await withSpoolLock(telemetry, name, async () => { await append(); return true; });
|
|
99
108
|
if (done) {
|
|
100
109
|
await sweepOutbox(telemetry, name).catch(() => { });
|
|
101
|
-
return;
|
|
110
|
+
return true;
|
|
102
111
|
}
|
|
103
112
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
104
113
|
delay = Math.min(250, delay * 2);
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
|
-
|
|
116
|
+
async function sweepOutboxAdmitted(telemetry, ownName, limits = {}) {
|
|
117
|
+
const admission = currentTelemetryAdmission();
|
|
108
118
|
const eventLimit = limits.events ?? OUTBOX_EVENT_LIMIT;
|
|
109
119
|
const byteLimit = limits.bytes ?? OUTBOX_BYTE_LIMIT;
|
|
110
120
|
const names = await spoolNames(telemetry);
|
|
111
121
|
const files = [];
|
|
112
122
|
for (const name of names) {
|
|
123
|
+
if (admission?.signal.aborted)
|
|
124
|
+
return;
|
|
113
125
|
const path = join(outboxDirectory(telemetry), name);
|
|
114
126
|
const info = await stat(path).catch(() => undefined);
|
|
115
127
|
if (info === undefined)
|
|
@@ -131,6 +143,8 @@ export async function sweepOutbox(telemetry, ownName, limits = {}) {
|
|
|
131
143
|
return;
|
|
132
144
|
const runs = new Map();
|
|
133
145
|
for (const name of names) {
|
|
146
|
+
if (admission?.signal.aborted)
|
|
147
|
+
return;
|
|
134
148
|
const path = join(outboxDirectory(telemetry), name);
|
|
135
149
|
const entries = await withSpoolLock(telemetry, name, async () => readSpool(path)).catch(() => undefined);
|
|
136
150
|
if (entries === undefined)
|
|
@@ -187,8 +201,8 @@ function spoolOwnerAlive(name) {
|
|
|
187
201
|
const match = /^[a-z]+-(\d+)-/.exec(name);
|
|
188
202
|
return match ? isPidAlive(Number(match[1])) : undefined;
|
|
189
203
|
}
|
|
190
|
-
|
|
191
|
-
cancelActiveUploads();
|
|
204
|
+
async function purgeOutboxAdmitted(telemetry) {
|
|
205
|
+
cancelActiveUploads(telemetryDirectoryHome(telemetry));
|
|
192
206
|
const directory = outboxDirectory(telemetry);
|
|
193
207
|
let names;
|
|
194
208
|
try {
|
|
@@ -203,7 +217,7 @@ export async function purgeOutbox(telemetry) {
|
|
|
203
217
|
await rm(join(directory, name), { force: true });
|
|
204
218
|
})));
|
|
205
219
|
}
|
|
206
|
-
|
|
220
|
+
async function withSpoolLockAdmitted(telemetry, name, run) {
|
|
207
221
|
try {
|
|
208
222
|
const release = await acquireSaveLock(join(outboxDirectory(telemetry), '.locks', name));
|
|
209
223
|
try {
|
|
@@ -219,9 +233,14 @@ export async function withSpoolLock(telemetry, name, run) {
|
|
|
219
233
|
throw error;
|
|
220
234
|
}
|
|
221
235
|
}
|
|
222
|
-
|
|
236
|
+
async function withSpoolLockWaitAdmitted(telemetry, name, run) {
|
|
237
|
+
const admission = currentTelemetryAdmission();
|
|
223
238
|
let delay = 25;
|
|
224
|
-
for (;;) {
|
|
239
|
+
for (let attempt = 0;; attempt++) {
|
|
240
|
+
if (admission?.signal.aborted || (admission && telemetryChoiceRequested(admission.lease.home)))
|
|
241
|
+
return undefined;
|
|
242
|
+
if (admission?.lease.mode === 'consent' && attempt >= 24)
|
|
243
|
+
throw new SaveLockBusyError();
|
|
225
244
|
const held = await withSpoolLock(telemetry, name, async () => ({ value: await run() }));
|
|
226
245
|
if (held !== undefined)
|
|
227
246
|
return held.value;
|
|
@@ -229,7 +248,7 @@ export async function withSpoolLockWait(telemetry, name, run) {
|
|
|
229
248
|
delay = Math.min(250, delay * 2);
|
|
230
249
|
}
|
|
231
250
|
}
|
|
232
|
-
|
|
251
|
+
async function spoolNamesAdmitted(telemetry) {
|
|
233
252
|
try {
|
|
234
253
|
return (await readdir(outboxDirectory(telemetry))).filter(name => name.endsWith('.jsonl'));
|
|
235
254
|
}
|
|
@@ -239,7 +258,7 @@ export async function spoolNames(telemetry) {
|
|
|
239
258
|
throw error;
|
|
240
259
|
}
|
|
241
260
|
}
|
|
242
|
-
|
|
261
|
+
async function rewriteSpoolAdmitted(telemetry, name, entries) {
|
|
243
262
|
const path = join(outboxDirectory(telemetry), name);
|
|
244
263
|
if (entries.length === 0)
|
|
245
264
|
await unlink(path).catch(error => { if (error.code !== 'ENOENT')
|
|
@@ -247,3 +266,40 @@ export async function rewriteSpool(telemetry, name, entries) {
|
|
|
247
266
|
else
|
|
248
267
|
await write(path, entries);
|
|
249
268
|
}
|
|
269
|
+
/** Public boundaries all enter privacy BEFORE even creating a telemetry/spool lock. */
|
|
270
|
+
export async function readSpool(path, access) {
|
|
271
|
+
return await admitTelemetryDirectory(spoolTelemetryDirectory(path), async (admission) => (await readSpoolAdmitted(path)).filter(entry => epochMatches(entry.epoch, admission.lease)), access) ?? [];
|
|
272
|
+
}
|
|
273
|
+
export async function enqueue(telemetry, engineId, entry, access = {}) {
|
|
274
|
+
const lease = access.lease ?? epochLease(telemetryDirectoryHome(telemetry), entry.epoch);
|
|
275
|
+
return await admitTelemetryDirectory(telemetry, async (admission) => {
|
|
276
|
+
// A missing start lease is NEVER upgraded into authority by a later Yes.
|
|
277
|
+
if (admission.lease.mode === 'consent' && !lease)
|
|
278
|
+
return;
|
|
279
|
+
if (entry.epoch !== undefined && !epochMatches(entry.epoch, admission.lease))
|
|
280
|
+
return;
|
|
281
|
+
const epoch = telemetryEpoch(admission.lease);
|
|
282
|
+
const written = await enqueueAdmitted(telemetry, engineId, epoch ? { ...entry, epoch } : entry);
|
|
283
|
+
return written && !admission.signal.aborted;
|
|
284
|
+
}, { ...access, lease }) ?? false;
|
|
285
|
+
}
|
|
286
|
+
export async function sweepOutbox(telemetry, ownName, limits = {}, access) {
|
|
287
|
+
await admitTelemetryDirectory(telemetry, () => sweepOutboxAdmitted(telemetry, ownName, limits), access);
|
|
288
|
+
}
|
|
289
|
+
/** Legacy outside opt-out only. Protected cleanup uses known-path detachment, never queue parsing. */
|
|
290
|
+
export async function purgeOutbox(telemetry, access) {
|
|
291
|
+
cancelActiveUploads(telemetryDirectoryHome(telemetry));
|
|
292
|
+
await admitTelemetryDirectory(telemetry, () => purgeOutboxAdmitted(telemetry), access);
|
|
293
|
+
}
|
|
294
|
+
export function withSpoolLock(telemetry, name, run, access) {
|
|
295
|
+
return admitTelemetryDirectory(telemetry, () => withSpoolLockAdmitted(telemetry, name, run), access);
|
|
296
|
+
}
|
|
297
|
+
export function withSpoolLockWait(telemetry, name, run, access) {
|
|
298
|
+
return admitTelemetryDirectory(telemetry, () => withSpoolLockWaitAdmitted(telemetry, name, run), access);
|
|
299
|
+
}
|
|
300
|
+
export async function spoolNames(telemetry, access) {
|
|
301
|
+
return await admitTelemetryDirectory(telemetry, () => spoolNamesAdmitted(telemetry), access) ?? [];
|
|
302
|
+
}
|
|
303
|
+
export async function rewriteSpool(telemetry, name, entries, access) {
|
|
304
|
+
await admitTelemetryDirectory(telemetry, admission => rewriteSpoolAdmitted(telemetry, name, entries.filter(entry => epochMatches(entry.epoch, admission.lease))), access);
|
|
305
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Provider/auth-free privacy commands. No prompt, status or refusal is an analytics event. */
|
|
2
|
+
import { type Config } from '../config.js';
|
|
3
|
+
import { type LegacyTelemetryGateResult } from './gate.js';
|
|
4
|
+
import { TELEMETRY_NOTICE, type TelemetryLease, type TelemetryPermissionInput, type TelemetryPermissionStatus } from './permission.js';
|
|
5
|
+
export declare const TELEMETRY_AUTO_WARNING = "Auto uses this installation's time zone and locale. Outside the EEA, UK and Switzerland, Free, Legacy and unconfirmed plans include reporting and cannot turn it off. Your saved permission answer will be retained; this action does not grant permission.";
|
|
6
|
+
export declare const TELEMETRY_HELP = "Usage: andorra telemetry status|allow|deny | andorra telemetry --help\n status Read product usage status without prompting or saving\n allow Show the notice and equal choices in a terminal\n deny Turn reports off where permitted; no terminal needed\n policy ask-first Region correction: require permission here; save No and clean up\n policy auto Use time zone and locale again; retain the saved answer";
|
|
7
|
+
export interface TelemetryCommandInput extends TelemetryPermissionInput {
|
|
8
|
+
subject?: () => Promise<string | undefined>;
|
|
9
|
+
}
|
|
10
|
+
export interface TelemetryChoiceIO {
|
|
11
|
+
interactive?: boolean;
|
|
12
|
+
/** Must render this current notice before accepting a deliberate answer. Never used headlessly. */
|
|
13
|
+
ask?: (notice: typeof TELEMETRY_NOTICE) => Promise<string | undefined>;
|
|
14
|
+
print?: (text: string) => void;
|
|
15
|
+
surface?: 'cli' | 'feedback';
|
|
16
|
+
}
|
|
17
|
+
export interface TelemetryCommandResult {
|
|
18
|
+
text: string;
|
|
19
|
+
code?: number;
|
|
20
|
+
saved?: boolean;
|
|
21
|
+
conflict?: boolean;
|
|
22
|
+
config?: Config;
|
|
23
|
+
}
|
|
24
|
+
export declare function protectedTelemetryStatus(status: TelemetryPermissionStatus, surface?: 'cli' | 'feedback'): string;
|
|
25
|
+
export declare function outsideTelemetryStatus(gate: Pick<LegacyTelemetryGateResult, 'plan' | 'report'>): string;
|
|
26
|
+
export declare function outsideOptOutRefused(plan: LegacyTelemetryGateResult['plan']): string;
|
|
27
|
+
/** No unattended affirmative argument/environment exists. Invalid input is cancellation, not No. */
|
|
28
|
+
export declare function executeTelemetryCommand(args: readonly string[], input?: TelemetryCommandInput, io?: TelemetryChoiceIO): Promise<TelemetryCommandResult>;
|
|
29
|
+
export declare function telemetryNoticeText(notice: typeof TELEMETRY_NOTICE): string;
|
|
30
|
+
/** Plain startup/management TTY reader with no default answer or persisted prompt marker. */
|
|
31
|
+
export declare function terminalTelemetryChoice(): TelemetryChoiceIO;
|
|
32
|
+
/** Only the actual human CLI entry calls this; embedded/headless callers never read stdin. */
|
|
33
|
+
export declare function offerTelemetryPermission(input: TelemetryCommandInput, io: TelemetryChoiceIO): Promise<TelemetryCommandResult | undefined>;
|
|
34
|
+
/** Project machine/browser/embedded outputs too; disk writers are not the only finalizers. */
|
|
35
|
+
export declare function cliTelemetryResult<T extends object>(home: string, value: T, lease?: TelemetryLease): T;
|
|
36
|
+
/** Functional operations never interpret legacy analytics on protected/blocked paths. */
|
|
37
|
+
export declare function loadCliConfig(home?: string): Promise<Config>;
|
|
38
|
+
export declare function saveCliConfig(config: Config, home?: string): Promise<void>;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/** Provider/auth-free privacy commands. No prompt, status or refusal is an analytics event. */
|
|
2
|
+
import { configDirectory, changeConfigFile, loadConfig, loadFunctionalConfig, loadSavedAnalytics, saveFunctionalConfig } from '../config.js';
|
|
3
|
+
import { analyticsGenerationFor, resolveAnalyticsConfig } from '../analytics.js';
|
|
4
|
+
import { currentGraphSubject } from '../graph-selection.js';
|
|
5
|
+
import { scrubRuns } from '../run-records.js';
|
|
6
|
+
import { legacyTelemetryGate, telemetryStatusGate } from './gate.js';
|
|
7
|
+
import { telemetryDirectory } from './identity.js';
|
|
8
|
+
import { purgeOutbox } from './outbox.js';
|
|
9
|
+
import { recordPreference } from './state.js';
|
|
10
|
+
import { admittedRunRecord, functionalRunRecord } from './run-privacy.js';
|
|
11
|
+
import { TELEMETRY_NOTICE, setTelemetryConsent, telemetryPermission, withTelemetryAdmission, telemetryLeaseSnapshot, sameTelemetryLease } from './permission.js';
|
|
12
|
+
export const TELEMETRY_AUTO_WARNING = "Auto uses this installation's time zone and locale. Outside the EEA, UK and Switzerland, Free, Legacy and unconfirmed plans include reporting and cannot turn it off. Your saved permission answer will be retained; this action does not grant permission.";
|
|
13
|
+
const USAGE = 'Usage: andorra telemetry status|allow|deny | andorra telemetry --help';
|
|
14
|
+
export const TELEMETRY_HELP = `${USAGE}\n status Read product usage status without prompting or saving\n allow Show the notice and equal choices in a terminal\n deny Turn reports off where permitted; no terminal needed\n policy ask-first Region correction: require permission here; save No and clean up\n policy auto Use time zone and locale again; retain the saved answer`;
|
|
15
|
+
export function protectedTelemetryStatus(status, surface = 'cli') {
|
|
16
|
+
if (status.answer === 'invalid' || status.reason === 'privacy-state-unavailable')
|
|
17
|
+
return 'Product usage reports: off — privacy settings unavailable. Retry or save your choice again.';
|
|
18
|
+
if (status.answer === 'no')
|
|
19
|
+
return 'Product usage reports: off — your choice. You can change this on any plan.' + (status.activation === 'cleanup-pending' ? '\nPrivacy cleanup needs to finish. Retry cleanup; reports remain off.' : '');
|
|
20
|
+
if (status.activation === 'cleanup-pending')
|
|
21
|
+
return 'Product usage reports: off — privacy cleanup needs to finish. Retry to enable reports.';
|
|
22
|
+
if (status.answer === 'yes' && status.permitted)
|
|
23
|
+
return `Product usage reports: on — with your permission. Use ${surface === 'cli' ? 'andorra telemetry deny' : '/feedback off'} to stop.`;
|
|
24
|
+
return `Product usage reports: off — permission not given. Use ${surface === 'cli' ? 'andorra telemetry allow or andorra telemetry deny' : '/feedback on or /feedback off'}.`;
|
|
25
|
+
}
|
|
26
|
+
export function outsideTelemetryStatus(gate) {
|
|
27
|
+
if (gate.plan === 'paid')
|
|
28
|
+
return `Product usage reports: ${gate.report ? 'on' : 'off'} (saved preference). It never includes your code, prompts, or API keys.`;
|
|
29
|
+
const plan = gate.plan === 'unknown' ? "your plan until this account's plan is confirmed" : `the ${gate.plan === 'free' ? 'Free' : 'Legacy'} plan`;
|
|
30
|
+
return `Product usage reports: on (included with ${plan}). Outside the EEA, UK and Switzerland, reporting is included with this plan. A confirmed Paid plan can turn it off.`;
|
|
31
|
+
}
|
|
32
|
+
export function outsideOptOutRefused(plan) {
|
|
33
|
+
return `Product usage reports stay on: collection is included with the ${plan === 'free' ? 'Free' : plan === 'legacy' ? 'Legacy' : 'current'} plan outside the EEA, UK and Switzerland. Upgrade to Paid to turn it off.`;
|
|
34
|
+
}
|
|
35
|
+
const privacyInput = (input) => ({ home: input.home, signals: input.signals, ...(input.io ? { io: input.io } : {}) });
|
|
36
|
+
async function outsideGate(input) {
|
|
37
|
+
return legacyTelemetryGate({ home: input.home, signals: input.signals,
|
|
38
|
+
config: { analytics: await loadSavedAnalytics(input.home) }, subject: await (input.subject ?? currentGraphSubject)().catch(() => undefined) });
|
|
39
|
+
}
|
|
40
|
+
async function statusText(input, surface) {
|
|
41
|
+
const gate = await telemetryStatusGate({ ...input, subject: input.subject ?? (() => currentGraphSubject({ readOnly: true })) });
|
|
42
|
+
return gate.permission.permissionRequired ? protectedTelemetryStatus(gate.permission, surface) : outsideTelemetryStatus(gate);
|
|
43
|
+
}
|
|
44
|
+
async function updateResult(input, result, surface) {
|
|
45
|
+
const warning = result.cleanupWarnings?.length ? '\nPrivacy cleanup skipped unusable run records: ' + result.cleanupWarnings.map(name => JSON.stringify(name)).join(', ') + '. Repair or remove these files locally.' : '';
|
|
46
|
+
return { saved: result.saved, conflict: result.conflict,
|
|
47
|
+
text: (result.conflict ? 'Your choice changed in another window or the CLI. Review the current status and choose again.\n' : '') + await statusText(input, surface) + warning };
|
|
48
|
+
}
|
|
49
|
+
/** All outside preference/generation/cache/purge work is privacy → config → spool, never inverse. */
|
|
50
|
+
async function outsideChange(input, enabled, surface) {
|
|
51
|
+
const result = await withTelemetryAdmission(input, async (admission) => {
|
|
52
|
+
if (admission.lease.mode !== 'out')
|
|
53
|
+
return undefined;
|
|
54
|
+
const gate = await outsideGate(input);
|
|
55
|
+
if (!enabled && !gate.canOptOut)
|
|
56
|
+
return { text: outsideOptOutRefused(gate.plan) };
|
|
57
|
+
let turnedOff = false;
|
|
58
|
+
const config = await changeConfigFile(input.home, current => {
|
|
59
|
+
turnedOff = resolveAnalyticsConfig(current).enabled && !enabled;
|
|
60
|
+
return { ...current, analytics: { ...current.analytics, enabled, generation: analyticsGenerationFor(current.analytics, enabled) } };
|
|
61
|
+
});
|
|
62
|
+
if (turnedOff)
|
|
63
|
+
await purgeOutbox(telemetryDirectory(input.home), { lease: admission.lease, signals: input.signals });
|
|
64
|
+
await recordPreference({ directory: telemetryDirectory(input.home), subject: await (input.subject ?? currentGraphSubject)().catch(() => undefined),
|
|
65
|
+
preference: enabled ? 'on' : 'off', lease: admission.lease, signals: input.signals }).catch(() => { });
|
|
66
|
+
return { saved: true, config, text: outsideTelemetryStatus(await outsideGate(input)) };
|
|
67
|
+
});
|
|
68
|
+
return result ?? { saved: false, conflict: true, text: 'Your choice changed. Review the current status and choose again.\n' + await statusText(input, surface) };
|
|
69
|
+
}
|
|
70
|
+
/** No unattended affirmative argument/environment exists. Invalid input is cancellation, not No. */
|
|
71
|
+
export async function executeTelemetryCommand(args, input = { home: configDirectory() }, io = {}) {
|
|
72
|
+
const surface = io.surface ?? 'cli';
|
|
73
|
+
if (args.length === 1 && ['--help', '-h'].includes(args[0]))
|
|
74
|
+
return { text: TELEMETRY_HELP };
|
|
75
|
+
const command = args.join(' ');
|
|
76
|
+
if (!['status', 'allow', 'deny', 'policy ask-first', 'policy auto'].includes(command))
|
|
77
|
+
return { text: USAGE, code: 1 };
|
|
78
|
+
if (command === 'status')
|
|
79
|
+
return { text: await statusText(input, surface) };
|
|
80
|
+
const displayed = await telemetryPermission(input);
|
|
81
|
+
if (command === 'policy auto') {
|
|
82
|
+
// The warning is observable before the first write, even for callers not using the CLI printer.
|
|
83
|
+
io.print?.(TELEMETRY_AUTO_WARNING);
|
|
84
|
+
const result = await setTelemetryConsent(privacyInput(input), { action: 'auto', expectedRevision: displayed.revision, noticeVersion: TELEMETRY_NOTICE.version }, scrubRuns);
|
|
85
|
+
const reply = await updateResult(input, result, surface);
|
|
86
|
+
if (!io.print)
|
|
87
|
+
reply.text = TELEMETRY_AUTO_WARNING + '\n' + reply.text;
|
|
88
|
+
return reply;
|
|
89
|
+
}
|
|
90
|
+
if (command === 'policy ask-first')
|
|
91
|
+
return updateResult(input, await setTelemetryConsent(privacyInput(input), { action: 'ask-first', expectedRevision: displayed.revision, noticeVersion: TELEMETRY_NOTICE.version }, scrubRuns), surface);
|
|
92
|
+
let enabled = command === 'allow';
|
|
93
|
+
if (enabled && !(surface === 'feedback' && !displayed.permissionRequired)) {
|
|
94
|
+
if (!io.interactive || !io.ask)
|
|
95
|
+
return { text: 'A terminal is required to review the notice and choose. Run andorra telemetry allow in a terminal.', code: 1 };
|
|
96
|
+
let answer;
|
|
97
|
+
try {
|
|
98
|
+
answer = await io.ask(TELEMETRY_NOTICE);
|
|
99
|
+
}
|
|
100
|
+
catch { /* EOF, Escape and aborted terminal questions are not answers. */ }
|
|
101
|
+
if (answer === undefined || !/^(y|yes|n|no)$/i.test(answer.trim()))
|
|
102
|
+
return { text: await statusText(input, surface) };
|
|
103
|
+
enabled = /^(y|yes)$/i.test(answer.trim());
|
|
104
|
+
}
|
|
105
|
+
if (!displayed.permissionRequired)
|
|
106
|
+
return outsideChange(input, enabled, surface);
|
|
107
|
+
return updateResult(input, await setTelemetryConsent(privacyInput(input), { action: enabled ? 'allow' : 'deny', expectedRevision: displayed.revision, noticeVersion: TELEMETRY_NOTICE.version }, scrubRuns), surface);
|
|
108
|
+
}
|
|
109
|
+
export function telemetryNoticeText(notice) {
|
|
110
|
+
return `${notice.title}\n${notice.body}\n${notice.scope}\nPrivacy Policy: ${notice.privacyUrl}`;
|
|
111
|
+
}
|
|
112
|
+
/** Plain startup/management TTY reader with no default answer or persisted prompt marker. */
|
|
113
|
+
export function terminalTelemetryChoice() {
|
|
114
|
+
const interactive = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
115
|
+
return { interactive, print: text => { process.stdout.write(text + '\n'); }, ask: async (notice) => {
|
|
116
|
+
if (!interactive || process.stdin.readableEnded || process.stdin.destroyed)
|
|
117
|
+
return undefined;
|
|
118
|
+
const input = process.stdin;
|
|
119
|
+
const raw = input.isRaw, flowing = input.readableFlowing;
|
|
120
|
+
return new Promise(resolve => {
|
|
121
|
+
let value = '', settled = false, armed = false;
|
|
122
|
+
let ready;
|
|
123
|
+
const done = (answer) => {
|
|
124
|
+
if (settled)
|
|
125
|
+
return;
|
|
126
|
+
settled = true;
|
|
127
|
+
clearTimeout(ready);
|
|
128
|
+
input.removeListener('data', data);
|
|
129
|
+
input.removeListener('end', end);
|
|
130
|
+
input.removeListener('error', end);
|
|
131
|
+
process.removeListener('SIGINT', end);
|
|
132
|
+
process.removeListener('SIGTERM', end);
|
|
133
|
+
input.setRawMode(raw);
|
|
134
|
+
if (flowing !== true)
|
|
135
|
+
input.pause();
|
|
136
|
+
process.stdout.write('\n');
|
|
137
|
+
resolve(answer);
|
|
138
|
+
};
|
|
139
|
+
const end = () => done();
|
|
140
|
+
const data = (chunk) => {
|
|
141
|
+
for (const char of chunk.toString()) {
|
|
142
|
+
if (['\u001b', '\u0003', '\u0004'].includes(char)) {
|
|
143
|
+
done();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (!armed)
|
|
147
|
+
continue; // queued/type-ahead bytes are not a deliberate answer to this notice
|
|
148
|
+
if (char === '\r' || char === '\n') {
|
|
149
|
+
done(value);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (char === '\u007f' || char === '\b') {
|
|
153
|
+
value = value.slice(0, -1);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (value.length >= 64 || char < ' ') {
|
|
157
|
+
done();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
value += char;
|
|
161
|
+
process.stdout.write(char);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
input.on('data', data);
|
|
165
|
+
input.once('end', end);
|
|
166
|
+
input.once('error', end);
|
|
167
|
+
process.once('SIGINT', end);
|
|
168
|
+
process.once('SIGTERM', end);
|
|
169
|
+
input.setRawMode(true);
|
|
170
|
+
while (input.read() !== null) { /* discard Node's pre-notice buffer */ }
|
|
171
|
+
input.resume();
|
|
172
|
+
process.stdout.write(telemetryNoticeText(notice) + '\n');
|
|
173
|
+
// Give the TTY a read cycle to drain OS type-ahead too. Only THEN show/arm the action line;
|
|
174
|
+
// a reader responding immediately to that line is accepted without losing a fresh keypress.
|
|
175
|
+
ready = setTimeout(() => {
|
|
176
|
+
if (settled)
|
|
177
|
+
return;
|
|
178
|
+
while (input.read() !== null) { /* discard the last unarmed bytes */ }
|
|
179
|
+
armed = true;
|
|
180
|
+
process.stdout.write(`[y] ${notice.allowLabel} / [n] ${notice.denyLabel}: `);
|
|
181
|
+
}, 100);
|
|
182
|
+
});
|
|
183
|
+
} };
|
|
184
|
+
}
|
|
185
|
+
/** Only the actual human CLI entry calls this; embedded/headless callers never read stdin. */
|
|
186
|
+
export async function offerTelemetryPermission(input, io) {
|
|
187
|
+
if (!io.interactive)
|
|
188
|
+
return undefined;
|
|
189
|
+
const status = await telemetryPermission(input);
|
|
190
|
+
if (!status.permissionRequired || status.answer !== 'pending')
|
|
191
|
+
return undefined;
|
|
192
|
+
return executeTelemetryCommand(['allow'], input, io);
|
|
193
|
+
}
|
|
194
|
+
/** Project machine/browser/embedded outputs too; disk writers are not the only finalizers. */
|
|
195
|
+
export function cliTelemetryResult(home, value, lease) {
|
|
196
|
+
return lease && sameTelemetryLease(lease, telemetryLeaseSnapshot({ home }))
|
|
197
|
+
? admittedRunRecord(value, lease, true) : functionalRunRecord(value);
|
|
198
|
+
}
|
|
199
|
+
/** Functional operations never interpret legacy analytics on protected/blocked paths. */
|
|
200
|
+
export async function loadCliConfig(home = configDirectory()) {
|
|
201
|
+
const config = await withTelemetryAdmission({ home }, admission => admission.lease.mode === 'out' ? loadConfig(home) : loadFunctionalConfig(home));
|
|
202
|
+
return config ?? loadFunctionalConfig(home);
|
|
203
|
+
}
|
|
204
|
+
export async function saveCliConfig(config, home = configDirectory()) {
|
|
205
|
+
// This API saves functional settings, never an analytics preference. Even a snapshot loaded
|
|
206
|
+
// outside may be stale after another window opts out. Explicit changes use changeConfigFile.
|
|
207
|
+
await saveFunctionalConfig(config, home);
|
|
208
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Necessary home-wide privacy authority. Never imports analytics, identity, plan state or config.
|
|
3
|
+
* Lock states (all files below the checked private privacy/ directory):
|
|
4
|
+
* idle -> shared: register a unique reader under the short .save-lock mutex, then release mutex.
|
|
5
|
+
* shared + shared: producers/POSTs overlap; only their existing state/spool locks serialize them.
|
|
6
|
+
* any -> requested: a choice publishes its intent BEFORE waiting. New admissions stop immediately.
|
|
7
|
+
* requested -> exclusive: take mutex, wait for registered readers, commit choice/cleanup, release.
|
|
8
|
+
* exclusive -> idle: remove our intent only after commit/cleanup and release. No POST can follow ACK.
|
|
9
|
+
* Refusals (.telemetry-withdrawal-*) outrank Allow/Auto: a waiting affirmative writer yields its mutex
|
|
10
|
+
* to them and then rechecks CAS. Every POST gets fresh admission and checks intent again before fetch.
|
|
11
|
+
* Dead local owners (readers, intents, mutex) are recovered, never live/foreign owners; torn owner
|
|
12
|
+
* records need a grace period. Reader registration/recovery is mutex-serialized; release owns a UUID.
|
|
13
|
+
* A crashed writer's durable cleanup-pending choice remains off and execution startup resumes it.
|
|
14
|
+
* Functional run writes take ONLY their per-file lock and check the necessary choice inside it;
|
|
15
|
+
* cleanup takes the same file lock, so they never wait on a network/privacy lock or restore old data.
|
|
16
|
+
* Lock order: privacy admission -> config/telemetry state/spool. Never invert it. Status never writes.
|
|
17
|
+
*/
|
|
18
|
+
import fs from 'node:fs/promises';
|
|
19
|
+
import { acquireSaveLock } from '../save-lock.js';
|
|
20
|
+
import { type TelemetryPolicy, type TelemetryRegion, type TelemetryRegionSignals } from './region.js';
|
|
21
|
+
export declare const TELEMETRY_NOTICE_VERSION = 1;
|
|
22
|
+
export declare const TELEMETRY_CONSENT_VERSION = 1;
|
|
23
|
+
export declare const TELEMETRY_NOTICE: Readonly<{
|
|
24
|
+
version: 1;
|
|
25
|
+
title: "Send product usage reports?";
|
|
26
|
+
body: "Help improve Andorra Code by sending feature-use counts, run outcomes, timings, model and tool usage totals, app/device details, and broad project language/framework categories. Reports use a random installation ID and are not linked to your account. They do not include code, prompts, responses, paths or keys.";
|
|
27
|
+
scope: "This choice applies to this installation's CLI and desktop app. You can change it at any time in Settings → Analytics or with /feedback, on any plan.";
|
|
28
|
+
allowLabel: "Allow reports";
|
|
29
|
+
denyLabel: "Don't allow reports";
|
|
30
|
+
privacyUrl: "https://andorracode.com/privacy";
|
|
31
|
+
}>;
|
|
32
|
+
export interface TelemetryConsent {
|
|
33
|
+
version: 1;
|
|
34
|
+
noticeVersion: 1;
|
|
35
|
+
answer: 'yes' | 'no';
|
|
36
|
+
policy: TelemetryPolicy;
|
|
37
|
+
revision: number;
|
|
38
|
+
/** Local revocation token, never an install identifier or event field. Present only for Yes. */
|
|
39
|
+
activationId?: string;
|
|
40
|
+
decidedAt: string;
|
|
41
|
+
activation: 'cleanup-pending' | 'ready';
|
|
42
|
+
}
|
|
43
|
+
export type ConsentRead = {
|
|
44
|
+
kind: 'valid';
|
|
45
|
+
record: TelemetryConsent;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'missing' | 'invalid' | 'unavailable';
|
|
48
|
+
};
|
|
49
|
+
export type TelemetryPermissionReason = 'permission-needed' | 'permission-declined' | 'permission-granted' | 'outside-policy' | 'privacy-state-unavailable' | 'cleanup-pending';
|
|
50
|
+
export interface TelemetryPermissionStatus {
|
|
51
|
+
region: TelemetryRegion;
|
|
52
|
+
permissionRequired: boolean;
|
|
53
|
+
policy: TelemetryPolicy;
|
|
54
|
+
answer: 'pending' | 'yes' | 'no' | 'invalid';
|
|
55
|
+
/** Privacy authority only. Outside callers must ALSO apply the legacy plan/preference gate. */
|
|
56
|
+
permitted: boolean;
|
|
57
|
+
canChange: boolean;
|
|
58
|
+
reason: TelemetryPermissionReason;
|
|
59
|
+
/** 0 means missing/invalid; use as expectedRevision, never as a consent epoch. */
|
|
60
|
+
revision: number;
|
|
61
|
+
noticeVersion: typeof TELEMETRY_NOTICE_VERSION;
|
|
62
|
+
activation: 'cleanup-pending' | 'ready' | 'none';
|
|
63
|
+
}
|
|
64
|
+
export type TelemetryLease = Readonly<{
|
|
65
|
+
home: string;
|
|
66
|
+
mode: 'out';
|
|
67
|
+
revision: number;
|
|
68
|
+
activationId?: string;
|
|
69
|
+
} | {
|
|
70
|
+
home: string;
|
|
71
|
+
mode: 'consent';
|
|
72
|
+
revision: number;
|
|
73
|
+
activationId: string;
|
|
74
|
+
}>;
|
|
75
|
+
export interface TelemetryPermissionInput {
|
|
76
|
+
home: string;
|
|
77
|
+
/** A function is reread for admission after awaits; omit for live local signals. */
|
|
78
|
+
signals?: TelemetryRegionSignals | (() => TelemetryRegionSignals);
|
|
79
|
+
io?: PermissionIO;
|
|
80
|
+
}
|
|
81
|
+
/** Injectable fault seams; production callers normally omit this. */
|
|
82
|
+
export interface PermissionIO {
|
|
83
|
+
fs: typeof fs;
|
|
84
|
+
acquireLock: typeof acquireSaveLock;
|
|
85
|
+
activationId(): string;
|
|
86
|
+
now(): string;
|
|
87
|
+
}
|
|
88
|
+
export declare function telemetryConsentPath(home: string): string;
|
|
89
|
+
export declare function validTelemetryConsent(value: unknown): value is TelemetryConsent;
|
|
90
|
+
/** Missing/failed reads have no authority and perform no writes, mkdir, locks or telemetry I/O. */
|
|
91
|
+
export declare function readTelemetryConsent(input: TelemetryPermissionInput): Promise<ConsentRead>;
|
|
92
|
+
/** Weak registrations avoid retaining completed runs or installing polling/listener handles. */
|
|
93
|
+
export declare function trackTelemetryRevocation(home: string, target: {
|
|
94
|
+
revoke(): void;
|
|
95
|
+
}): void;
|
|
96
|
+
/** Immediate process-local suppression/cancellation; not a claim of cross-process signalling. */
|
|
97
|
+
export declare function suppressTelemetry(home: string): void;
|
|
98
|
+
export declare function telemetryPermission(input: TelemetryPermissionInput): Promise<TelemetryPermissionStatus>;
|
|
99
|
+
export declare function telemetryLease(input: TelemetryPermissionInput): Promise<TelemetryLease | undefined>;
|
|
100
|
+
export declare function sameTelemetryLease(a: TelemetryLease | undefined, b: TelemetryLease | undefined): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Read-only necessary-choice check for synchronous in-memory sinks. Does NOT authorize disk I/O:
|
|
103
|
+
* serialization/enqueue still require withTelemetryAdmission. Bounded and symlink-safe like async
|
|
104
|
+
* status; checking after every await/callback notices another process's durable withdrawal.
|
|
105
|
+
*/
|
|
106
|
+
export declare function telemetryLeaseSnapshot(input: TelemetryPermissionInput): TelemetryLease | undefined;
|
|
107
|
+
export declare function telemetryLeaseIsCurrent(input: TelemetryPermissionInput, lease: TelemetryLease | undefined): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Display-only optimistic control read. Never creates a directory/lock or installs an admission
|
|
110
|
+
* context. Only effective outside status may inspect the old preference/cache; check current()
|
|
111
|
+
* before each read and discard everything if policy/epoch changes across an await. This is NOT
|
|
112
|
+
* authority for collection, persistence, hashing for producers or sending, and returns no lease.
|
|
113
|
+
* An already-started read may overlap withdrawal; it cannot publish the old answer afterwards.
|
|
114
|
+
* All producer I/O still holds withTelemetryAdmission through the operation and withdrawal ACK.
|
|
115
|
+
*/
|
|
116
|
+
export interface TelemetryControlRead {
|
|
117
|
+
readonly home: string;
|
|
118
|
+
readonly status: TelemetryPermissionStatus;
|
|
119
|
+
current(): boolean;
|
|
120
|
+
}
|
|
121
|
+
export declare function telemetryControlReadIsCurrent(read: TelemetryControlRead, home: string): boolean;
|
|
122
|
+
export declare function readTelemetryControl<T>(input: TelemetryPermissionInput, work: (read: TelemetryControlRead) => Promise<T>): Promise<T | undefined>;
|
|
123
|
+
export interface TelemetryAdmission {
|
|
124
|
+
readonly lease: TelemetryLease;
|
|
125
|
+
readonly signal: AbortSignal;
|
|
126
|
+
readonly status: TelemetryPermissionStatus;
|
|
127
|
+
}
|
|
128
|
+
/** Escaped async callbacks must reacquire admission, never reuse an already-released barrier. */
|
|
129
|
+
export declare function currentTelemetryAdmission(): TelemetryAdmission | undefined;
|
|
130
|
+
/** Read-only, fail-closed intent check, also used by synchronous captures and each POST. */
|
|
131
|
+
export declare function telemetryChoiceRequested(home: string): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Guard EVERY analytics operation, including outside mode, and hold through disk work / bounded POST.
|
|
134
|
+
* A lease from the START of a run is required as expectedLease for later capture/finalization/replay.
|
|
135
|
+
* Nested guarded helpers reuse the admission (never take a spool lock then acquire privacy).
|
|
136
|
+
* undefined means blocked/failure: do not fall back to an unguarded operation.
|
|
137
|
+
*/
|
|
138
|
+
export declare function withTelemetryAdmission<T>(input: TelemetryPermissionInput, work: (admission: TelemetryAdmission) => Promise<T>, expectedLease?: TelemetryLease): Promise<T | undefined>;
|
|
139
|
+
export declare class TelemetryPrivacyError extends Error {
|
|
140
|
+
readonly code: 'invalid-params' | 'storage' | 'busy';
|
|
141
|
+
constructor(code: 'invalid-params' | 'storage' | 'busy', message: string);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Fixed known-path deletion, without reading/parsing analytics. Called ONLY under the privacy barrier
|
|
145
|
+
* after an explicit choice (or its durable cleanup-pending retry). rm never follows detached symlinks.
|
|
146
|
+
* A fixed detachment path lets a restart finish removal without storing random path/history metadata.
|
|
147
|
+
*/
|
|
148
|
+
export declare function cleanupTelemetryStorage(input: TelemetryPermissionInput): Promise<void>;
|
|
149
|
+
export declare function assertTelemetryCleanupAuthority(home: string): Promise<void>;
|
|
150
|
+
/** Package B must provide schema-aware removal from runs/checkpoints; no default no-op can activate Yes. */
|
|
151
|
+
export type TelemetryRunMetadataCleanup = (home: string) => Promise<void | readonly string[]>;
|
|
152
|
+
export interface TelemetryConsentAction {
|
|
153
|
+
expectedRevision: number;
|
|
154
|
+
noticeVersion: number;
|
|
155
|
+
/** ask-first is a deliberate No + ask. auto retains the answer and cannot grant Yes. */
|
|
156
|
+
action: 'allow' | 'deny' | 'ask-first' | 'auto';
|
|
157
|
+
}
|
|
158
|
+
export interface TelemetryConsentUpdate {
|
|
159
|
+
saved: boolean;
|
|
160
|
+
conflict: boolean;
|
|
161
|
+
status: TelemetryPermissionStatus;
|
|
162
|
+
cleanupError?: 'cleanup-failed';
|
|
163
|
+
cleanupWarnings?: readonly string[];
|
|
164
|
+
}
|
|
165
|
+
/** Compare-and-set against the prompt's revision. A stale Allow can NEVER overwrite a later No. */
|
|
166
|
+
export declare function setTelemetryConsent(input: TelemetryPermissionInput, action: TelemetryConsentAction, scrubRuns: TelemetryRunMetadataCleanup): Promise<TelemetryConsentUpdate>;
|
|
167
|
+
/** Resume only durable cleanup intent at execution startup. Display-only status never invokes this. */
|
|
168
|
+
export declare function resumeTelemetryCleanup(input: TelemetryPermissionInput, scrubRuns: TelemetryRunMetadataCleanup): Promise<TelemetryConsentUpdate>;
|