@andorra-labs/code 0.1.18 → 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 +347 -45
- 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/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 +23 -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 +3 -1
- package/dist/src/app-server/workspace.js +39 -8
- package/dist/src/app-server.d.ts +50 -25
- package/dist/src/app-server.js +1008 -400
- 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/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +4 -1
- package/dist/src/bridge/control.js +2 -1
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -0
- package/dist/src/bridge/host-ops.d.ts +2 -2
- package/dist/src/bridge/host-ops.js +4 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +63 -12
- 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/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.js +235 -58
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +43 -7
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +19 -5
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +8 -1
- package/dist/src/commands.js +67 -63
- package/dist/src/completion.js +5 -3
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +54 -16
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +23 -2
- 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/DecisionManager.d.ts +5 -0
- package/dist/src/decision/DecisionManager.js +39 -2
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -4
- 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 +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +17 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +2 -0
- package/dist/src/efficiency.d.ts +75 -1
- package/dist/src/efficiency.js +114 -3
- 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/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/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-runner.js +19 -13
- 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 +45 -10
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +19 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +17 -1
- package/dist/src/graphs.js +51 -5
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +7 -4
- 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-metadata.js +3 -7
- 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 +13 -1
- package/dist/src/model-tiers.js +28 -4
- 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.js +42 -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 +3 -9
- package/dist/src/providers.js +181 -146
- 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 +82 -66
- package/dist/src/pull-requests.js +266 -276
- 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 +147 -56
- 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 +85 -18
- 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 +18 -1
- package/dist/src/runtime.js +25 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +8 -0
- package/dist/src/sessions.js +12 -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/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +2 -2
- 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 +20 -4
- package/dist/src/task-checkout.js +78 -8
- 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/thinking-level-detect.d.ts +3 -1
- package/dist/src/thinking-level-detect.js +8 -3
- package/dist/src/thinking-levels.d.ts +1 -1
- package/dist/src/thinking-levels.js +11 -4
- package/dist/src/timers.d.ts +2 -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/tools.js +67 -22
- package/dist/src/transcript.js +2 -1
- package/dist/src/types.d.ts +14 -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,76 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { publishAtomic, withTelemetryLock } from './identity.js';
|
|
5
|
+
import { isNewerRelease, STABLE_RELEASE_VERSION, telemetrySchemaFor, } from './schema.js';
|
|
6
|
+
function eventId(identity, observation) {
|
|
7
|
+
const hex = createHash('sha256').update(JSON.stringify([
|
|
8
|
+
identity.installId, identity.surface, observation.version, observation.status,
|
|
9
|
+
])).digest('hex');
|
|
10
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
11
|
+
}
|
|
12
|
+
async function readState(path) {
|
|
13
|
+
try {
|
|
14
|
+
const raw = JSON.parse(await readFile(path, 'utf8'));
|
|
15
|
+
return raw && typeof raw === 'object' ? raw : {};
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code === 'ENOENT' || error instanceof SyntaxError)
|
|
19
|
+
return {};
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** A product launch first establishes a baseline. Only a successful installer receipt proves a first install. */
|
|
24
|
+
export async function recordInstallationObservation(directory, identity, location, generation, enqueue, receipt) {
|
|
25
|
+
const version = identity.appVersion;
|
|
26
|
+
if (!identity.releaseTelemetry || (identity.surface !== 'cli' && identity.surface !== 'desktop') ||
|
|
27
|
+
!STABLE_RELEASE_VERSION.test(version))
|
|
28
|
+
return;
|
|
29
|
+
const name = `installation-${identity.surface}.json`;
|
|
30
|
+
const path = join(directory, name);
|
|
31
|
+
const previous = receipt?.version === version ? receipt.previousVersion : undefined;
|
|
32
|
+
const replaces = previous && isNewerRelease(version, previous) ? previous : undefined;
|
|
33
|
+
const canPromote = (state) => state.status === 'baseline' && (replaces !== undefined || previous === null);
|
|
34
|
+
const observed = await readState(path);
|
|
35
|
+
if (observed.latest === version && !observed.pending && !canPromote(observed))
|
|
36
|
+
return;
|
|
37
|
+
await withTelemetryLock(directory, async () => {
|
|
38
|
+
const state = await readState(path);
|
|
39
|
+
const persist = (next) => publishAtomic(directory, name, JSON.stringify(next));
|
|
40
|
+
const emit = (observation) => enqueue({
|
|
41
|
+
...identity,
|
|
42
|
+
schema: telemetrySchemaFor('installation.observed'),
|
|
43
|
+
event: 'installation.observed',
|
|
44
|
+
eventId: eventId(identity, observation),
|
|
45
|
+
ts: observation.ts,
|
|
46
|
+
appVersion: observation.version,
|
|
47
|
+
status: observation.status,
|
|
48
|
+
...(observation.previousVersion ? { previousVersion: observation.previousVersion } : {}),
|
|
49
|
+
});
|
|
50
|
+
if (state.pending) {
|
|
51
|
+
if (state.pending.generation === generation)
|
|
52
|
+
await emit(state.pending);
|
|
53
|
+
state.latest = state.pending.version;
|
|
54
|
+
state.location = state.pending.location;
|
|
55
|
+
state.status = state.pending.status;
|
|
56
|
+
await persist({ latest: state.latest, location: state.location, status: state.status });
|
|
57
|
+
}
|
|
58
|
+
if (state.latest && !isNewerRelease(version, state.latest) && !(state.latest === version && canPromote(state)))
|
|
59
|
+
return;
|
|
60
|
+
// A receipt records the actual version replaced, even for the first observed update.
|
|
61
|
+
const prior = replaces ?? (state.location === location && state.latest !== version ? state.latest : undefined);
|
|
62
|
+
const status = prior ? 'updated' : previous === null ? 'installed' : 'baseline';
|
|
63
|
+
const pending = {
|
|
64
|
+
version,
|
|
65
|
+
ts: status !== 'baseline' && (replaces !== undefined || previous === null) ? receipt?.ts ?? identity.ts : identity.ts,
|
|
66
|
+
status,
|
|
67
|
+
location,
|
|
68
|
+
generation,
|
|
69
|
+
...(prior ? { previousVersion: prior } : {}),
|
|
70
|
+
};
|
|
71
|
+
// Persist the timestamp before enqueue. A retry reaches the same immutable server key after a crash.
|
|
72
|
+
await persist({ latest: state.latest, location: state.location, status: state.status, pending });
|
|
73
|
+
await emit(pending);
|
|
74
|
+
await persist({ latest: version, location, status });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -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
|
+
}
|