@agent-watch-ai/edge 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +288 -9
- package/README.md +307 -5
- package/dist/billing/billing-mode.d.ts +37 -5
- package/dist/billing/billing-mode.js +28 -19
- package/dist/billing/constants/billing.constants.d.ts +0 -2
- package/dist/billing/constants/billing.constants.js +0 -2
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.js +1 -1
- package/dist/billing/session-billing.d.ts +7 -3
- package/dist/billing/session-billing.js +34 -13
- package/dist/billing/types/billing.types.d.ts +7 -0
- package/dist/capture/capture-env.d.ts +147 -0
- package/dist/capture/capture-env.js +301 -0
- package/dist/capture/captured-step.d.ts +88 -0
- package/dist/capture/captured-step.js +503 -0
- package/dist/capture/constants/capture.constants.d.ts +85 -0
- package/dist/capture/constants/capture.constants.js +87 -0
- package/dist/capture/launched-runs.d.ts +43 -0
- package/dist/capture/launched-runs.js +157 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +832 -0
- package/dist/capture/schemas/capture.schema.d.ts +35 -0
- package/dist/capture/schemas/capture.schema.js +31 -0
- package/dist/capture/types/capture.types.d.ts +20 -0
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +23 -6
- package/dist/cli/constants/cli.constants.js +24 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +21 -0
- package/dist/cli/doctor-run-capture.js +33 -0
- package/dist/cli/doctor.js +21 -68
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +82 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/misc.js +10 -2
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.d.ts +33 -0
- package/dist/cli/replay.js +228 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +200 -31
- package/dist/cli/status.js +45 -5
- package/dist/cli/toggle.js +10 -0
- package/dist/cli/types/cli.types.d.ts +15 -1
- package/dist/cli/uninstall.js +42 -23
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +104 -17
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +10 -1
- package/dist/config/events-transport.d.ts +15 -0
- package/dist/config/events-transport.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/root-config.d.ts +12 -0
- package/dist/config/root-config.js +24 -0
- package/dist/config/schemas/config.schema.d.ts +15 -2
- package/dist/config/schemas/config.schema.js +52 -8
- package/dist/config/types/config.types.d.ts +7 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/version.d.ts +9 -0
- package/dist/core/version.js +14 -0
- package/dist/core/which.d.ts +11 -0
- package/dist/core/which.js +18 -0
- package/dist/credentials/cloud-claim.d.ts +34 -0
- package/dist/credentials/cloud-claim.js +61 -0
- package/dist/credentials/constants/credentials.constants.d.ts +16 -1
- package/dist/credentials/constants/credentials.constants.js +17 -2
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/credentials/sign-in.d.ts +27 -0
- package/dist/credentials/sign-in.js +31 -1
- package/dist/credentials/token-refresher.d.ts +5 -1
- package/dist/credentials/token-refresher.js +10 -2
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +6 -3
- package/dist/events/types/events.types.d.ts +6 -0
- package/dist/events/types/replay-progress.types.d.ts +26 -0
- package/dist/events/types/replay-progress.types.js +1 -0
- package/dist/events/types/repo-tree.types.d.ts +2 -1
- package/dist/feature/ticket-candidates.d.ts +1 -1
- package/dist/git/checkout-root.d.ts +15 -0
- package/dist/git/checkout-root.js +18 -0
- package/dist/git/code-state.d.ts +2 -16
- package/dist/git/code-state.js +11 -12
- package/dist/git/constants/git.constants.d.ts +33 -11
- package/dist/git/constants/git.constants.js +45 -12
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.js +5 -1
- package/dist/git/index.d.ts +1 -2
- package/dist/git/index.js +1 -1
- package/dist/git/repo-snapshot.d.ts +13 -4
- package/dist/git/repo-snapshot.js +53 -9
- package/dist/git/types/snapshot.types.d.ts +6 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +82 -57
- package/dist/privacy/product-capture.js +2 -0
- package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.capture.js +5 -0
- package/dist/providers/antigravity/antigravity.detect.js +8 -22
- package/dist/providers/antigravity/antigravity.provider.js +10 -3
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
- package/dist/providers/claude/claude.adapter.js +9 -6
- package/dist/providers/claude/claude.detect.js +2 -17
- package/dist/providers/claude/claude.otel.d.ts +21 -3
- package/dist/providers/claude/claude.otel.js +216 -61
- package/dist/providers/claude/claude.provider.js +21 -1
- package/dist/providers/claude/claude.version.d.ts +9 -0
- package/dist/providers/claude/claude.version.js +28 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.constants.js +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
- package/dist/providers/claude/types/claude.types.d.ts +13 -0
- package/dist/providers/codex/codex.capture.d.ts +76 -0
- package/dist/providers/codex/codex.capture.js +454 -0
- package/dist/providers/codex/codex.detect.js +2 -4
- package/dist/providers/codex/codex.otel.d.ts +38 -2
- package/dist/providers/codex/codex.otel.js +50 -6
- package/dist/providers/codex/codex.provider.js +8 -0
- package/dist/providers/codex/codex.surface.d.ts +9 -0
- package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
- package/dist/providers/codex/codex.titles.d.ts +14 -0
- package/dist/providers/codex/codex.titles.js +35 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
- package/dist/providers/codex/constants/codex.constants.js +4 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
- package/dist/providers/cursor/constants/cursor.constants.js +25 -5
- package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
- package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
- package/dist/providers/cursor/cursor.adapter.js +20 -82
- package/dist/providers/cursor/cursor.capture.d.ts +1 -0
- package/dist/providers/cursor/cursor.capture.js +4 -0
- package/dist/providers/cursor/cursor.detect.d.ts +5 -1
- package/dist/providers/cursor/cursor.detect.js +11 -26
- package/dist/providers/cursor/cursor.hooks.js +2 -2
- package/dist/providers/cursor/cursor.provider.js +16 -7
- package/dist/providers/cursor/cursor.titles.d.ts +14 -0
- package/dist/providers/cursor/cursor.titles.js +20 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
- package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
- package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
- package/dist/providers/gemini/constants/gemini.constants.js +17 -0
- package/dist/providers/gemini/gemini.capture.d.ts +81 -0
- package/dist/providers/gemini/gemini.capture.js +210 -0
- package/dist/providers/gemini/gemini.detect.js +57 -24
- package/dist/providers/gemini/gemini.otel.d.ts +38 -2
- package/dist/providers/gemini/gemini.otel.js +56 -125
- package/dist/providers/gemini/gemini.provider.js +5 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/provider.d.ts +8 -0
- package/dist/providers/provider.js +9 -0
- package/dist/providers/registry.d.ts +14 -0
- package/dist/providers/registry.js +14 -0
- package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
- package/dist/providers/shared/constants/hook-config.constants.js +2 -0
- package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
- package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
- package/dist/providers/shared/editor-paths.d.ts +8 -0
- package/dist/providers/shared/editor-paths.js +18 -0
- package/dist/providers/shared/hook-config.d.ts +5 -0
- package/dist/providers/shared/hook-config.js +39 -1
- package/dist/providers/shared/hooks-marker.d.ts +14 -0
- package/dist/providers/shared/hooks-marker.js +23 -0
- package/dist/providers/shared/install-record.d.ts +29 -0
- package/dist/providers/shared/install-record.js +52 -0
- package/dist/providers/shared/session-title-store.d.ts +23 -0
- package/dist/providers/shared/session-title-store.js +50 -0
- package/dist/providers/shared/terminal-capture.d.ts +41 -0
- package/dist/providers/shared/terminal-capture.js +109 -0
- package/dist/providers/shared/tooling.d.ts +21 -0
- package/dist/providers/shared/tooling.js +36 -1
- package/dist/providers/types/provider.types.d.ts +57 -4
- package/dist/replay/checkout-resolver.d.ts +56 -0
- package/dist/replay/checkout-resolver.js +173 -0
- package/dist/replay/codex-turns.d.ts +24 -0
- package/dist/replay/codex-turns.js +221 -0
- package/dist/replay/constants/replay.constants.d.ts +99 -0
- package/dist/replay/constants/replay.constants.js +102 -0
- package/dist/replay/describe.d.ts +10 -0
- package/dist/replay/describe.js +31 -0
- package/dist/replay/gemini-turns.d.ts +36 -0
- package/dist/replay/gemini-turns.js +192 -0
- package/dist/replay/machine.d.ts +34 -0
- package/dist/replay/machine.js +68 -0
- package/dist/replay/progress-event.d.ts +21 -0
- package/dist/replay/progress-event.js +45 -0
- package/dist/replay/replay-runner.d.ts +60 -0
- package/dist/replay/replay-runner.js +581 -0
- package/dist/replay/replay-scan.d.ts +84 -0
- package/dist/replay/replay-scan.js +182 -0
- package/dist/replay/replay-state.d.ts +108 -0
- package/dist/replay/replay-state.js +199 -0
- package/dist/replay/resume.d.ts +18 -0
- package/dist/replay/resume.js +34 -0
- package/dist/replay/start.d.ts +23 -0
- package/dist/replay/start.js +39 -0
- package/dist/replay/throttle.d.ts +36 -0
- package/dist/replay/throttle.js +44 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +241 -0
- package/dist/replay/turn-event.d.ts +40 -0
- package/dist/replay/turn-event.js +127 -0
- package/dist/replay/types/replay.types.d.ts +198 -0
- package/dist/replay/types/replay.types.js +1 -0
- package/dist/replay/window.d.ts +28 -0
- package/dist/replay/window.js +41 -0
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +71 -41
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
- package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
- package/dist/snapshot/constants/snapshot.constants.js +34 -7
- package/dist/snapshot/index.d.ts +2 -2
- package/dist/snapshot/index.js +1 -1
- package/dist/snapshot/snapshot-pipeline.js +100 -26
- package/dist/snapshot/snapshot-state.js +6 -2
- package/dist/snapshot/tree-pipeline.d.ts +1 -1
- package/dist/snapshot/tree-pipeline.js +34 -15
- package/dist/snapshot/types/snapshot.types.d.ts +22 -3
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/transport/delivery-stats.d.ts +13 -1
- package/dist/transport/delivery-stats.js +18 -2
- package/dist/transport/delivery.d.ts +4 -3
- package/dist/transport/delivery.js +21 -7
- package/dist/transport/identity-delivery.d.ts +20 -0
- package/dist/transport/identity-delivery.js +41 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/types/delivery-flow.types.d.ts +7 -0
- package/dist/turns/claude-transcript.js +4 -12
- package/dist/turns/codex-transcript.d.ts +9 -0
- package/dist/turns/codex-transcript.js +27 -19
- package/dist/turns/constants/turns.constants.d.ts +29 -12
- package/dist/turns/constants/turns.constants.js +31 -19
- package/dist/turns/gemini-transcript.d.ts +19 -1
- package/dist/turns/gemini-transcript.js +29 -18
- package/dist/turns/index.d.ts +3 -4
- package/dist/turns/index.js +2 -3
- package/dist/turns/run-state.d.ts +71 -0
- package/dist/turns/run-state.js +114 -0
- package/dist/turns/tool-events.d.ts +11 -1
- package/dist/turns/tool-events.js +32 -9
- package/dist/turns/transcript.d.ts +15 -14
- package/dist/turns/transcript.js +23 -4
- package/dist/turns/turn-state.d.ts +82 -7
- package/dist/turns/turn-state.js +157 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +163 -87
- package/dist/turns/types/transcript.types.d.ts +11 -1
- package/dist/turns/types/turn-provider.types.d.ts +33 -0
- package/dist/turns/types/turn-provider.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +9 -0
- package/dist/turns/types/turn-summary.types.d.ts +17 -1
- package/dist/turns/types/turn-tracker.types.d.ts +3 -1
- package/dist/turns/work-checkout.js +1 -2
- package/docs/AUDIT_PROMPT.md +10 -0
- package/docs/DATA_HANDLING.md +201 -13
- package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
- package/docs/PERFORMANCE.md +10 -0
- package/package.json +3 -2
- package/dist/events/canonical-event.d.ts +0 -10
- package/dist/events/canonical-event.js +0 -9
- package/dist/git/repository-root.d.ts +0 -39
- package/dist/git/repository-root.js +0 -131
- package/dist/git/types/repository-root.types.d.ts +0 -11
- package/dist/transport/transport.d.ts +0 -6
- package/dist/turns/codex-originator.d.ts +0 -11
- package/dist/turns/cursor-transcript.d.ts +0 -21
- package/dist/turns/cursor-transcript.js +0 -66
- package/dist/turns/native-session-titles.d.ts +0 -26
- package/dist/turns/native-session-titles.js +0 -102
- /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
- /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
|
@@ -49,8 +49,8 @@ export declare function identityFingerprint(identity: string): string;
|
|
|
49
49
|
/**
|
|
50
50
|
* The device credential that stands for this config's identity, if any.
|
|
51
51
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
52
|
+
* A key and a device side by side are one identity until the exchange moves
|
|
53
|
+
* the key to the store (or an older edge left it there). A device whose
|
|
54
54
|
* id is not that key's is a leftover from an earlier key and stands for
|
|
55
55
|
* nothing.
|
|
56
56
|
*
|
|
@@ -63,8 +63,8 @@ export function identityFingerprint(identity) {
|
|
|
63
63
|
/**
|
|
64
64
|
* The device credential that stands for this config's identity, if any.
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
66
|
+
* A key and a device side by side are one identity until the exchange moves
|
|
67
|
+
* the key to the store (or an older edge left it there). A device whose
|
|
68
68
|
* id is not that key's is a leftover from an earlier key and stands for
|
|
69
69
|
* nothing.
|
|
70
70
|
*
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CredentialContext, DeviceCredentialRef } from './types/credentials.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Move an install key from the config into its device's secret store.
|
|
4
|
+
*
|
|
5
|
+
* The key is needed again only when the device secret expires, so it lives
|
|
6
|
+
* where the secret does, not in plain text in `config.json`. The config entry
|
|
7
|
+
* keeps it until the store has proven it holds the key, so a failed write never
|
|
8
|
+
* loses it. Never throws.
|
|
9
|
+
*
|
|
10
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
11
|
+
* @param installKey - The key that was exchanged.
|
|
12
|
+
* @param device - The device it was exchanged for.
|
|
13
|
+
* @param waitMs - How long to wait for the config lock.
|
|
14
|
+
* @returns True when the store holds the key and the config was updated.
|
|
15
|
+
*/
|
|
16
|
+
export declare function retireInstallKey(ctx: CredentialContext, installKey: string, device: DeviceCredentialRef, waitMs: number): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* The install key a device was exchanged for, from its secret store.
|
|
19
|
+
*
|
|
20
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
21
|
+
* @param device - The device.
|
|
22
|
+
* @returns The key, or undefined (a sign-in device has none).
|
|
23
|
+
*/
|
|
24
|
+
export declare function storedInstallKey(ctx: CredentialContext, device: DeviceCredentialRef): Promise<string | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Remove the install key kept for a device, if any.
|
|
27
|
+
*
|
|
28
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
29
|
+
* @param device - The device being forgotten.
|
|
30
|
+
*/
|
|
31
|
+
export declare function forgetInstallKey(ctx: CredentialContext, device: DeviceCredentialRef): Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { detachInstallKey } from '../config/config-store.js';
|
|
2
|
+
import { debugLog } from '../core/logger.js';
|
|
3
|
+
import { INSTALL_KEY_ACCOUNT_SUFFIX } from './constants/credentials.constants.js';
|
|
4
|
+
import { secretStoreFor, storeVerified } from './secret-store.js';
|
|
5
|
+
/**
|
|
6
|
+
* The account (or file name) a device's install key is kept under, beside its secret.
|
|
7
|
+
*
|
|
8
|
+
* @param device - The device.
|
|
9
|
+
* @returns The account name.
|
|
10
|
+
*/
|
|
11
|
+
function installKeyAccount(device) {
|
|
12
|
+
return device.id + INSTALL_KEY_ACCOUNT_SUFFIX;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Move an install key from the config into its device's secret store.
|
|
16
|
+
*
|
|
17
|
+
* The key is needed again only when the device secret expires, so it lives
|
|
18
|
+
* where the secret does, not in plain text in `config.json`. The config entry
|
|
19
|
+
* keeps it until the store has proven it holds the key, so a failed write never
|
|
20
|
+
* loses it. Never throws.
|
|
21
|
+
*
|
|
22
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
23
|
+
* @param installKey - The key that was exchanged.
|
|
24
|
+
* @param device - The device it was exchanged for.
|
|
25
|
+
* @param waitMs - How long to wait for the config lock.
|
|
26
|
+
* @returns True when the store holds the key and the config was updated.
|
|
27
|
+
*/
|
|
28
|
+
export async function retireInstallKey(ctx, installKey, device, waitMs) {
|
|
29
|
+
try {
|
|
30
|
+
if (!(await storeVerified(ctx, device.store, installKeyAccount(device), installKey)))
|
|
31
|
+
return false;
|
|
32
|
+
return (await detachInstallKey(ctx.paths, installKey, device.id, waitMs)) !== 'busy';
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
debugLog('credentials: moving the install key out of the config failed; it stays there:', error);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The install key a device was exchanged for, from its secret store.
|
|
41
|
+
*
|
|
42
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
43
|
+
* @param device - The device.
|
|
44
|
+
* @returns The key, or undefined (a sign-in device has none).
|
|
45
|
+
*/
|
|
46
|
+
export async function storedInstallKey(ctx, device) {
|
|
47
|
+
// Outside a hook's deadline: a read cut short would look like "no key" and back the re-enrollment off for an hour.
|
|
48
|
+
return secretStoreFor(device.store, { ...ctx, deadline: undefined }).get(installKeyAccount(device)).catch(() => undefined);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove the install key kept for a device, if any.
|
|
52
|
+
*
|
|
53
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
54
|
+
* @param device - The device being forgotten.
|
|
55
|
+
*/
|
|
56
|
+
export async function forgetInstallKey(ctx, device) {
|
|
57
|
+
await secretStoreFor(device.store, ctx).remove(installKeyAccount(device));
|
|
58
|
+
}
|
|
@@ -8,17 +8,19 @@ import type { CredentialContext, DeviceCredentialRef } from './types/credentials
|
|
|
8
8
|
* run — written by an older setup, by `setup --token` or from
|
|
9
9
|
* `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
|
|
10
10
|
* cached before the config names the device, so a crash in between costs one
|
|
11
|
-
* more exchange, never the credential.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* more exchange, never the credential. Once the device is named, the install
|
|
12
|
+
* key moves from the config into the device's secret store, to enroll again
|
|
13
|
+
* when the secret expires (`retireInstallKey`); a config written before that
|
|
14
|
+
* loses its key the next time this runs. A failure keeps the key in the config
|
|
15
|
+
* and in use, and the next try waits an hour.
|
|
14
16
|
*
|
|
15
17
|
* A device the gateway refused counts as no device: an expired secret is
|
|
16
18
|
* enrolled again by any run, a revoked or unknown one only when setup asks
|
|
17
19
|
* (`ignoreBackoff`), so a hook never undoes an admin's revocation.
|
|
18
20
|
*
|
|
19
|
-
* Never for a scope `uninstall` marked, until setup runs for it again:
|
|
20
|
-
*
|
|
21
|
-
* revoked. Asked before the lock, under it, and once more before the device is
|
|
21
|
+
* Never for a scope `uninstall` marked, until setup runs for it again: a key
|
|
22
|
+
* still in the config is there for a reinstall, not for re-enrolling a device
|
|
23
|
+
* just revoked. Asked before the lock, under it, and once more before the device is
|
|
22
24
|
* attached; a device enrolled while uninstall marked the scope is revoked and
|
|
23
25
|
* forgotten here, since uninstall can no longer see it.
|
|
24
26
|
*
|
|
@@ -26,7 +28,7 @@ import type { CredentialContext, DeviceCredentialRef } from './types/credentials
|
|
|
26
28
|
* fit a hook's budget. Setup makes the exchange there.
|
|
27
29
|
*
|
|
28
30
|
* @param ctx - Paths, clock, timeout, fetch and keychain runner.
|
|
29
|
-
* @param config - Effective config whose `token` is the install key.
|
|
31
|
+
* @param config - Effective config whose `token` is the install key, or whose device has its key in the store.
|
|
30
32
|
* @param options - `ignoreBackoff` for setup, where someone asked for it now.
|
|
31
33
|
* @param options.ignoreBackoff - Try even within an hour of a failed attempt.
|
|
32
34
|
* @returns The device credential now standing for the key, or undefined.
|
|
@@ -7,11 +7,12 @@ import { acquireLock } from '../storage/lock.js';
|
|
|
7
7
|
import { isUninstalled } from '../storage/uninstalled.js';
|
|
8
8
|
import { BackendAuthBlock } from '../transport/auth-block.js';
|
|
9
9
|
import { identityPaths } from '../transport/queue-partition.js';
|
|
10
|
-
import { ENROLL_LOCK_PREFIX, ENROLL_RETRY_MS, REFUSAL_SECRET_EXPIRED } from './constants/credentials.constants.js';
|
|
10
|
+
import { DEVICE_IDENTITY_PREFIX, ENROLL_LOCK_PREFIX, ENROLL_RETRY_MS, REFUSAL_SECRET_EXPIRED } from './constants/credentials.constants.js';
|
|
11
11
|
import { enrollDevice, revokeDevice } from './device-api.js';
|
|
12
12
|
import { readDeviceState, writeAccessToken, writeDeviceState } from './device-state.js';
|
|
13
13
|
import { withinBudget } from './budget.js';
|
|
14
|
-
import {
|
|
14
|
+
import { deviceRefs, identityFingerprint, identityOf } from './identity.js';
|
|
15
|
+
import { forgetInstallKey, retireInstallKey, storedInstallKey } from './install-key.js';
|
|
15
16
|
import { saveSecret, secretStoreFor } from './secret-store.js';
|
|
16
17
|
/**
|
|
17
18
|
* Exchange the install key this config holds for a device credential, once.
|
|
@@ -21,17 +22,19 @@ import { saveSecret, secretStoreFor } from './secret-store.js';
|
|
|
21
22
|
* run — written by an older setup, by `setup --token` or from
|
|
22
23
|
* `$AGENTWATCH_TOKEN`. Order matters: the secret is stored and the first token
|
|
23
24
|
* cached before the config names the device, so a crash in between costs one
|
|
24
|
-
* more exchange, never the credential.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* more exchange, never the credential. Once the device is named, the install
|
|
26
|
+
* key moves from the config into the device's secret store, to enroll again
|
|
27
|
+
* when the secret expires (`retireInstallKey`); a config written before that
|
|
28
|
+
* loses its key the next time this runs. A failure keeps the key in the config
|
|
29
|
+
* and in use, and the next try waits an hour.
|
|
27
30
|
*
|
|
28
31
|
* A device the gateway refused counts as no device: an expired secret is
|
|
29
32
|
* enrolled again by any run, a revoked or unknown one only when setup asks
|
|
30
33
|
* (`ignoreBackoff`), so a hook never undoes an admin's revocation.
|
|
31
34
|
*
|
|
32
|
-
* Never for a scope `uninstall` marked, until setup runs for it again:
|
|
33
|
-
*
|
|
34
|
-
* revoked. Asked before the lock, under it, and once more before the device is
|
|
35
|
+
* Never for a scope `uninstall` marked, until setup runs for it again: a key
|
|
36
|
+
* still in the config is there for a reinstall, not for re-enrolling a device
|
|
37
|
+
* just revoked. Asked before the lock, under it, and once more before the device is
|
|
35
38
|
* attached; a device enrolled while uninstall marked the scope is revoked and
|
|
36
39
|
* forgotten here, since uninstall can no longer see it.
|
|
37
40
|
*
|
|
@@ -39,14 +42,15 @@ import { saveSecret, secretStoreFor } from './secret-store.js';
|
|
|
39
42
|
* fit a hook's budget. Setup makes the exchange there.
|
|
40
43
|
*
|
|
41
44
|
* @param ctx - Paths, clock, timeout, fetch and keychain runner.
|
|
42
|
-
* @param config - Effective config whose `token` is the install key.
|
|
45
|
+
* @param config - Effective config whose `token` is the install key, or whose device has its key in the store.
|
|
43
46
|
* @param options - `ignoreBackoff` for setup, where someone asked for it now.
|
|
44
47
|
* @param options.ignoreBackoff - Try even within an hour of a failed attempt.
|
|
45
48
|
* @returns The device credential now standing for the key, or undefined.
|
|
46
49
|
*/
|
|
47
50
|
export async function migrateInstallKey(ctx, config, options = {}) {
|
|
48
|
-
const
|
|
49
|
-
|
|
51
|
+
const identity = identityOf(config);
|
|
52
|
+
const id = identity === undefined ? undefined : identityFingerprint(identity);
|
|
53
|
+
if (!id || !config.endpoint)
|
|
50
54
|
return undefined;
|
|
51
55
|
if (ctx.hookPath && ctx.env.platform === 'win32')
|
|
52
56
|
return undefined;
|
|
@@ -54,22 +58,36 @@ export async function migrateInstallKey(ctx, config, options = {}) {
|
|
|
54
58
|
// enroll: only setup, which lifts the marker first, may.
|
|
55
59
|
if (await isUninstalled(ctx.paths, ctx.scope))
|
|
56
60
|
return undefined;
|
|
57
|
-
const
|
|
58
|
-
const
|
|
61
|
+
const files = identityPaths(ctx.paths, DEVICE_IDENTITY_PREFIX + id);
|
|
62
|
+
const waitMs = ctx.hookPath ? CONFIG_LOCK_HOOK_WAIT_MS : CONFIG_LOCK_WAIT_MS;
|
|
59
63
|
// Cheap checks first, so a backed-off key costs a hook no lock; both are
|
|
60
64
|
// asked again under the lock, where the answer can no longer change.
|
|
61
65
|
const settled = await settledExchange(ctx, id, files.deviceStateFile, options);
|
|
62
|
-
|
|
66
|
+
// A config written before the key left it (an older edge) still holds it beside its device.
|
|
67
|
+
// Only the entry that names the device beside it, which is what `detachInstallKey` clears.
|
|
68
|
+
const leftKey = settled.done && settled.device !== undefined && config.token !== undefined && config.device?.id === id;
|
|
69
|
+
if (settled.done && !leftKey)
|
|
63
70
|
return settled.device;
|
|
64
71
|
const release = await acquireLock(ctx.paths.locksDir, ENROLL_LOCK_PREFIX + id, ctx.env.now).catch(() => undefined);
|
|
72
|
+
// The device stands either way; moving the key waits for the next run.
|
|
65
73
|
if (!release)
|
|
66
|
-
return undefined;
|
|
74
|
+
return leftKey ? settled.device : undefined;
|
|
67
75
|
try {
|
|
68
76
|
const recheck = await settledExchange(ctx, id, files.deviceStateFile, options);
|
|
69
|
-
|
|
70
|
-
return recheck.device;
|
|
77
|
+
// Under the lock, so uninstall (which takes it) cannot remove the key from the store in between.
|
|
71
78
|
if (await isUninstalled(ctx.paths, ctx.scope))
|
|
72
79
|
return undefined;
|
|
80
|
+
if (recheck.done) {
|
|
81
|
+
if (recheck.device && config.token && config.device?.id === id)
|
|
82
|
+
await retireInstallKey(ctx, config.token, recheck.device, waitMs);
|
|
83
|
+
return recheck.device;
|
|
84
|
+
}
|
|
85
|
+
const installKey = config.token ?? (config.device ? await storedInstallKey(ctx, config.device) : undefined);
|
|
86
|
+
// A device signed in through the browser has no key: back off, so a hook does not ask the keychain every turn.
|
|
87
|
+
if (!installKey) {
|
|
88
|
+
await writeDeviceState(files.deviceStateFile, { ...recheck.state, enrollAttemptAt: ctx.env.now().toISOString() });
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
73
91
|
const now = ctx.env.now();
|
|
74
92
|
const budget = withinBudget(ctx);
|
|
75
93
|
if (!budget)
|
|
@@ -93,17 +111,38 @@ export async function migrateInstallKey(ctx, config, options = {}) {
|
|
|
93
111
|
await abandonDevice(ctx, device, result.value.deviceSecret, files.accessTokenFile);
|
|
94
112
|
return undefined;
|
|
95
113
|
}
|
|
96
|
-
const attached = await attachDevice(ctx.paths, installKey, device,
|
|
114
|
+
const attached = await attachDevice(ctx.paths, installKey, device, waitMs);
|
|
97
115
|
// Unnamed in the config (the lock was busy), the device is invisible to the
|
|
98
116
|
// next run: keep the backoff, or every hook would enroll yet another one.
|
|
99
117
|
await writeDeviceState(files.deviceStateFile, (await namesDevice(ctx, attached, device)) ? {} : { enrollAttemptAt: now.toISOString() });
|
|
100
118
|
await new BackendAuthBlock(files.authBlockFile, ctx.env.now).clear();
|
|
119
|
+
// Uninstall may have overtaken the exchange since the last look: it removes the key, so it must not come back.
|
|
120
|
+
if (await isUninstalled(ctx.paths, ctx.scope))
|
|
121
|
+
return device;
|
|
122
|
+
await keepInstallKey(ctx, installKey, config.token === undefined ? config.device : undefined, device, waitMs);
|
|
101
123
|
return device;
|
|
102
124
|
}
|
|
103
125
|
finally {
|
|
104
126
|
await release();
|
|
105
127
|
}
|
|
106
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* After an exchange, keep the key in the new device's store only. A key read
|
|
131
|
+
* from the store is written again only when the secret moved to another store
|
|
132
|
+
* (a keychain that works now), and the old copy goes once the new one is proven.
|
|
133
|
+
*
|
|
134
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
135
|
+
* @param installKey - The key just exchanged.
|
|
136
|
+
* @param previous - The device whose store the key was read from, when it was.
|
|
137
|
+
* @param device - The device it was exchanged for.
|
|
138
|
+
* @param waitMs - How long to wait for the config lock.
|
|
139
|
+
*/
|
|
140
|
+
async function keepInstallKey(ctx, installKey, previous, device, waitMs) {
|
|
141
|
+
if (previous?.store === device.store)
|
|
142
|
+
return;
|
|
143
|
+
if ((await retireInstallKey(ctx, installKey, device, waitMs)) && previous)
|
|
144
|
+
await forgetInstallKey(ctx, previous).catch(() => undefined);
|
|
145
|
+
}
|
|
107
146
|
/**
|
|
108
147
|
* Undo an exchange uninstall overtook: revoke the device on the platform and
|
|
109
148
|
* forget it here, best effort. Its secret is in hand, so no keychain read.
|
|
@@ -120,6 +159,7 @@ export async function abandonDevice(ctx, device, secret, tokenFile) {
|
|
|
120
159
|
if (!revoked)
|
|
121
160
|
warnLog('a device that was enrolled but not kept (uninstall overtook it, or setup could not save it) could not be revoked; it may still be active on the platform. An admin can revoke this machine in Settings → Install.');
|
|
122
161
|
await secretStoreFor(device.store, ctx).remove(device.id).catch(() => undefined);
|
|
162
|
+
await forgetInstallKey(ctx, device).catch(() => undefined);
|
|
123
163
|
await fs.rm(tokenFile, { force: true }).catch(() => undefined);
|
|
124
164
|
debugLog('device enrollment overtaken by uninstall; revoked and forgotten');
|
|
125
165
|
}
|
|
@@ -19,6 +19,18 @@ export type { SecretStore, StoreDeps } from './types/credentials.types.js';
|
|
|
19
19
|
* @returns The store that holds it now.
|
|
20
20
|
*/
|
|
21
21
|
export declare function saveSecret(deps: StoreDeps, id: string, secret: string): Promise<CredentialStoreKind>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a value to one store and read it back, outside a hook's credential
|
|
24
|
+
* deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
|
|
25
|
+
* the read proves the write.
|
|
26
|
+
*
|
|
27
|
+
* @param deps - Environment, paths, timeout and runner.
|
|
28
|
+
* @param kind - The store to write to.
|
|
29
|
+
* @param id - The account name.
|
|
30
|
+
* @param value - What to keep.
|
|
31
|
+
* @returns True when the store gives the value back.
|
|
32
|
+
*/
|
|
33
|
+
export declare function storeVerified(deps: StoreDeps, kind: CredentialStoreKind, id: string, value: string): Promise<boolean>;
|
|
22
34
|
/**
|
|
23
35
|
* The OS keychain this machine offers, or the private file when it offers none.
|
|
24
36
|
*
|
|
@@ -28,11 +28,28 @@ import { CREDENTIALS_DIR_NAME, DBUS_SESSION_VAR, DPAPI_FILE_SUFFIX, DPAPI_PROTEC
|
|
|
28
28
|
export async function saveSecret(deps, id, secret) {
|
|
29
29
|
const unhurried = { ...deps, deadline: undefined };
|
|
30
30
|
const preferred = preferredStore(unhurried);
|
|
31
|
-
if (preferred.kind !== 'file' && (await preferred
|
|
31
|
+
if (preferred.kind !== 'file' && (await setVerified(preferred, id, secret)))
|
|
32
32
|
return preferred.kind;
|
|
33
33
|
await fileStore(unhurried).set(id, secret);
|
|
34
34
|
return 'file';
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Write a value to one store and read it back, outside a hook's credential
|
|
38
|
+
* deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
|
|
39
|
+
* the read proves the write.
|
|
40
|
+
*
|
|
41
|
+
* @param deps - Environment, paths, timeout and runner.
|
|
42
|
+
* @param kind - The store to write to.
|
|
43
|
+
* @param id - The account name.
|
|
44
|
+
* @param value - What to keep.
|
|
45
|
+
* @returns True when the store gives the value back.
|
|
46
|
+
*/
|
|
47
|
+
export async function storeVerified(deps, kind, id, value) {
|
|
48
|
+
return setVerified(secretStoreFor(kind, { ...deps, deadline: undefined }), id, value);
|
|
49
|
+
}
|
|
50
|
+
async function setVerified(store, id, value) {
|
|
51
|
+
return (await store.set(id, value)) && (await store.get(id)) === value;
|
|
52
|
+
}
|
|
36
53
|
/**
|
|
37
54
|
* The OS keychain this machine offers, or the private file when it offers none.
|
|
38
55
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CloudIdentity } from './cloud-claim.js';
|
|
1
2
|
import type { CredentialContext, RedeemCodeInput, SignedIn, SignInInput } from './types/credentials.types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Enroll this machine through the browser: show the verification code, wait
|
|
@@ -29,3 +30,29 @@ export declare function signInDevice(ctx: CredentialContext, input: SignInInput)
|
|
|
29
30
|
export declare function enrollWithCode(ctx: CredentialContext, input: Omit<RedeemCodeInput, 'timeoutMs' | 'fetchFn'>): Promise<SignedIn | {
|
|
30
31
|
readonly error: string;
|
|
31
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Enroll a Claude Code cloud VM with a claim signed by its organization's
|
|
35
|
+
* cloud session key. No install key, no prompt, no code: the signature names
|
|
36
|
+
* the organization and the claim the developer. The credential is kept
|
|
37
|
+
* exactly as a sign-in's is. Never prints the key or the signature.
|
|
38
|
+
*
|
|
39
|
+
* ponytail: the device is stored with no `source` (like a sign-in's), because
|
|
40
|
+
* the config schema only knows `batch-code`; recording `cloud` there is a
|
|
41
|
+
* config.schema.ts change.
|
|
42
|
+
*
|
|
43
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
44
|
+
* @param input - Gateway, the managed-settings identity, installation and label.
|
|
45
|
+
* @param input.endpoint - The gateway to claim from.
|
|
46
|
+
* @param input.identity - Organization, key and Claude account email.
|
|
47
|
+
* @param input.installationId - This VM's own installation.
|
|
48
|
+
* @param input.name - The machine label.
|
|
49
|
+
* @returns The device to name in the config and its secret, or the reason there is none.
|
|
50
|
+
*/
|
|
51
|
+
export declare function enrollWithCloudClaim(ctx: CredentialContext, input: {
|
|
52
|
+
readonly endpoint: string;
|
|
53
|
+
readonly identity: CloudIdentity;
|
|
54
|
+
readonly installationId: string;
|
|
55
|
+
readonly name: string;
|
|
56
|
+
}): Promise<SignedIn | {
|
|
57
|
+
readonly error: string;
|
|
58
|
+
}>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { sleep } from '../core/async.js';
|
|
2
2
|
import { identityPaths } from '../transport/queue-partition.js';
|
|
3
3
|
import { DEVICE_SOURCE_BATCH_CODE, POLL_DENIED, POLL_EXPIRED, POLL_PENDING, POLL_SLOW_DOWN, RE_PLAIN_EMAIL, SLOW_DOWN_STEP_MS } from './constants/credentials.constants.js';
|
|
4
|
-
import {
|
|
4
|
+
import { signCloudClaim } from './cloud-claim.js';
|
|
5
|
+
import { claimCloudDevice, pollEnrollmentSession, redeemEnrollmentCode, revokeDevice, startEnrollmentSession } from './device-api.js';
|
|
5
6
|
import { writeAccessToken } from './device-state.js';
|
|
6
7
|
import { credentialId } from './identity.js';
|
|
7
8
|
import { saveSecret } from './secret-store.js';
|
|
@@ -79,6 +80,35 @@ export async function enrollWithCode(ctx, input) {
|
|
|
79
80
|
return { error: `the enrollment code was refused (${redeemed.refusal}): it is unknown, used, expired or revoked; ask your admin for a new one. Nothing was written` };
|
|
80
81
|
return { error: `could not redeem the enrollment code with ${input.endpoint} (${redeemed.status ?? 'no response'}); nothing was written` };
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Enroll a Claude Code cloud VM with a claim signed by its organization's
|
|
85
|
+
* cloud session key. No install key, no prompt, no code: the signature names
|
|
86
|
+
* the organization and the claim the developer. The credential is kept
|
|
87
|
+
* exactly as a sign-in's is. Never prints the key or the signature.
|
|
88
|
+
*
|
|
89
|
+
* ponytail: the device is stored with no `source` (like a sign-in's), because
|
|
90
|
+
* the config schema only knows `batch-code`; recording `cloud` there is a
|
|
91
|
+
* config.schema.ts change.
|
|
92
|
+
*
|
|
93
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
94
|
+
* @param input - Gateway, the managed-settings identity, installation and label.
|
|
95
|
+
* @param input.endpoint - The gateway to claim from.
|
|
96
|
+
* @param input.identity - Organization, key and Claude account email.
|
|
97
|
+
* @param input.installationId - This VM's own installation.
|
|
98
|
+
* @param input.name - The machine label.
|
|
99
|
+
* @returns The device to name in the config and its secret, or the reason there is none.
|
|
100
|
+
*/
|
|
101
|
+
export async function enrollWithCloudClaim(ctx, input) {
|
|
102
|
+
const signed = signCloudClaim(input.identity, ctx.env.now());
|
|
103
|
+
if (!signed)
|
|
104
|
+
return { error: 'AGENTWATCH_CLOUD_KEY is not an Ed25519 private key (base64url PKCS8 DER); copy the block from Settings again. Nothing was written' };
|
|
105
|
+
const claimed = await claimCloudDevice({ endpoint: input.endpoint, ...signed, installationId: input.installationId, name: input.name, timeoutMs: ctx.timeoutMs, fetchFn: ctx.fetchFn });
|
|
106
|
+
if (claimed.ok)
|
|
107
|
+
return keep(ctx, input.endpoint, claimed.value);
|
|
108
|
+
if (claimed.status === 401)
|
|
109
|
+
return { error: 'the cloud claim was refused: check the organization id and key in the managed settings, and that the Claude account email is at the organization\'s verified domain. Nothing was written' };
|
|
110
|
+
return { error: `could not claim a cloud device from ${input.endpoint} (${claimed.status ?? 'no response'}); nothing was written, the next session start tries again` };
|
|
111
|
+
}
|
|
82
112
|
/**
|
|
83
113
|
* Store an approved credential. The gateway has issued it by now, so a store
|
|
84
114
|
* that fails is undone on the platform too: nothing would name the device, and
|
|
@@ -34,6 +34,10 @@ export declare function cachedAccessToken(ctx: CredentialContext, config: AgentW
|
|
|
34
34
|
*
|
|
35
35
|
* @param ctx - Paths, clock, timeout, deadline, fetch and keychain runner.
|
|
36
36
|
* @param config - Effective config holding a device credential.
|
|
37
|
+
* @param options - Refresh options.
|
|
38
|
+
* @param options.force - Refresh whatever the cache holds (after a plain 401).
|
|
37
39
|
* @returns The token, or undefined when there is none to send.
|
|
38
40
|
*/
|
|
39
|
-
export declare function currentAccessToken(ctx: CredentialContext, config: AgentWatchConfig
|
|
41
|
+
export declare function currentAccessToken(ctx: CredentialContext, config: AgentWatchConfig, options?: {
|
|
42
|
+
readonly force?: boolean;
|
|
43
|
+
}): Promise<string | undefined>;
|
|
@@ -58,9 +58,11 @@ export async function cachedAccessToken(ctx, config) {
|
|
|
58
58
|
*
|
|
59
59
|
* @param ctx - Paths, clock, timeout, deadline, fetch and keychain runner.
|
|
60
60
|
* @param config - Effective config holding a device credential.
|
|
61
|
+
* @param options - Refresh options.
|
|
62
|
+
* @param options.force - Refresh whatever the cache holds (after a plain 401).
|
|
61
63
|
* @returns The token, or undefined when there is none to send.
|
|
62
64
|
*/
|
|
63
|
-
export async function currentAccessToken(ctx, config) {
|
|
65
|
+
export async function currentAccessToken(ctx, config, options = {}) {
|
|
64
66
|
const device = config.device;
|
|
65
67
|
if (!device)
|
|
66
68
|
return undefined;
|
|
@@ -70,7 +72,8 @@ export async function currentAccessToken(ctx, config) {
|
|
|
70
72
|
destination ? new BackendAuthBlock(files.authBlockFile, ctx.env.now).active(destination) : undefined,
|
|
71
73
|
readAccessToken(files.accessTokenFile)
|
|
72
74
|
]);
|
|
73
|
-
|
|
75
|
+
// `force` (a plain 401) is handled as an expired token: same lock, cooldown and refusal rules.
|
|
76
|
+
const expired = options.force === true || block?.reason === REFUSAL_TOKEN_EXPIRED;
|
|
74
77
|
if (cached && !expired && !needsRefresh(cached, ctx.env.now(), ctx.minRemainingMs))
|
|
75
78
|
return cached.accessToken;
|
|
76
79
|
const fallback = expired ? undefined : usable(cached, ctx.env.now());
|
|
@@ -83,6 +86,11 @@ export async function currentAccessToken(ctx, config) {
|
|
|
83
86
|
// `agentwatch refresh-credential` refreshes under the same lock, and this
|
|
84
87
|
// hook sends what it has (or queues).
|
|
85
88
|
if (ctx.hookPath && device.store === 'windows-dpapi') {
|
|
89
|
+
// The refresher only refreshes what is due, so a forced refresh drops the
|
|
90
|
+
// cache to make it due. This hook cannot resend: the next send after the
|
|
91
|
+
// block's re-probe goes on the new token.
|
|
92
|
+
if (options.force === true)
|
|
93
|
+
await fs.promises.rm(files.accessTokenFile, { force: true }).catch(() => undefined);
|
|
86
94
|
await startBackgroundRefresh(ctx, files.deviceStateFile);
|
|
87
95
|
return fallback;
|
|
88
96
|
}
|
|
@@ -31,7 +31,7 @@ import { requestDecision } from './decision-client.js';
|
|
|
31
31
|
*/
|
|
32
32
|
export async function resolveEnforcement(options) {
|
|
33
33
|
const url = enforcementUrl(options.config);
|
|
34
|
-
//
|
|
34
|
+
// An install key an older edge left beside its device is not sent: this
|
|
35
35
|
// identity sends as the device: only the caller's cached access token will do.
|
|
36
36
|
const token = options.bearer ?? (deviceFor(options.config) ? undefined : options.config.token);
|
|
37
37
|
const developerId = options.developerId;
|
|
@@ -23,9 +23,12 @@ export declare const INTERNAL_HOOK_EVENT_TYPES: readonly ["session.started", "se
|
|
|
23
23
|
*
|
|
24
24
|
* `repo.tree` is the default branch's source paths and declaration names, once
|
|
25
25
|
* per repository and identity: what a tenant with no GitHub App gets its feature catalog named from.
|
|
26
|
+
*
|
|
27
|
+
* `replay.progress` counts how far a replay of the developer's earlier sessions
|
|
28
|
+
* has got, so the platform can say a history is still arriving. Counts only.
|
|
26
29
|
*/
|
|
27
|
-
export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree"];
|
|
28
|
-
export declare const CANONICAL_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other", "llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree"];
|
|
30
|
+
export declare const PRODUCT_EVENT_TYPES: readonly ["llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree", "replay.progress"];
|
|
31
|
+
export declare const CANONICAL_EVENT_TYPES: readonly ["session.started", "session.ended", "prompt.submitted", "tool.started", "tool.completed", "tool.failed", "permission.requested", "file.read", "file.edited", "shell.started", "shell.completed", "mcp.started", "mcp.completed", "subagent.started", "subagent.completed", "generation.completed", "compaction.started", "compaction.completed", "agent.error", "agent.other", "llm.call", "turn.summary", "repo.snapshot", "session.billing", "repo.tree", "replay.progress"];
|
|
29
32
|
/** O(1) membership for the hot path: queue drain checks this per entry. */
|
|
30
33
|
export declare const PRODUCT_EVENT_TYPE_SET: ReadonlySet<string>;
|
|
31
34
|
/** Canonical event types that close a turn. */
|
|
@@ -45,8 +45,11 @@ export const INTERNAL_HOOK_EVENT_TYPES = [
|
|
|
45
45
|
*
|
|
46
46
|
* `repo.tree` is the default branch's source paths and declaration names, once
|
|
47
47
|
* per repository and identity: what a tenant with no GitHub App gets its feature catalog named from.
|
|
48
|
+
*
|
|
49
|
+
* `replay.progress` counts how far a replay of the developer's earlier sessions
|
|
50
|
+
* has got, so the platform can say a history is still arriving. Counts only.
|
|
48
51
|
*/
|
|
49
|
-
export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot', 'session.billing', 'repo.tree'];
|
|
52
|
+
export const PRODUCT_EVENT_TYPES = ['llm.call', 'turn.summary', 'repo.snapshot', 'session.billing', 'repo.tree', 'replay.progress'];
|
|
50
53
|
export const CANONICAL_EVENT_TYPES = [...INTERNAL_HOOK_EVENT_TYPES, ...PRODUCT_EVENT_TYPES];
|
|
51
54
|
/** O(1) membership for the hot path: queue drain checks this per entry. */
|
|
52
55
|
export const PRODUCT_EVENT_TYPE_SET = new Set(PRODUCT_EVENT_TYPES);
|
package/dist/events/enrich.d.ts
CHANGED
|
@@ -14,3 +14,17 @@ export type { EnrichOptions, PathRewriter } from './types/enrich.types.js';
|
|
|
14
14
|
* @returns Enriched, sanitized events in the same order.
|
|
15
15
|
*/
|
|
16
16
|
export declare function enrichEvents(events: readonly AgentWatchEvent[], options: EnrichOptions): Promise<AgentWatchEvent[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Where a file outside every checkout lies, without the home directory's name.
|
|
19
|
+
*
|
|
20
|
+
* A spreadsheet in `~/Documents` is the target of a session with no repository,
|
|
21
|
+
* so it is kept — but as `~/Documents/a.xlsx`: the home directory names the
|
|
22
|
+
* person. A path outside home is kept as it is; with no home to compare against
|
|
23
|
+
* nothing is kept, since the path could be the home itself.
|
|
24
|
+
*
|
|
25
|
+
* @param filePath - Path from a tool payload.
|
|
26
|
+
* @param repositoryRoot - The hook's repository root, when inside one.
|
|
27
|
+
* @param home - Developer home directory, when known.
|
|
28
|
+
* @returns The path to send, or undefined when the file is in the repository or unplaceable.
|
|
29
|
+
*/
|
|
30
|
+
export declare function externalPath(filePath: string, repositoryRoot: string | undefined, home: string | undefined): string | undefined;
|
package/dist/events/enrich.js
CHANGED
|
@@ -278,7 +278,7 @@ function relativize(root, target) {
|
|
|
278
278
|
* @param home - Developer home directory, when known.
|
|
279
279
|
* @returns The path to send, or undefined when the file is in the repository or unplaceable.
|
|
280
280
|
*/
|
|
281
|
-
function externalPath(filePath, repositoryRoot, home) {
|
|
281
|
+
export function externalPath(filePath, repositoryRoot, home) {
|
|
282
282
|
if (!home || !path.isAbsolute(filePath) || (repositoryRoot && isInside(repositoryRoot, filePath)))
|
|
283
283
|
return undefined;
|
|
284
284
|
return isInside(home, filePath) ? HOME_PLACEHOLDER_PREFIX + path.relative(home, filePath) : filePath;
|
package/dist/events/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { AgentWatchEvent, CanonicalEventType, ContentEvidence, EventAi, Eve
|
|
|
6
6
|
export type { BuildLlmCallInput, LlmCallCorrelation, LlmCallEvent, LlmCallStatus, LlmCallUsage } from './types/llm-call.types.js';
|
|
7
7
|
export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotCommitFile, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
|
|
8
8
|
export type { RepoTreeEvent, RepoTreeFile } from './types/repo-tree.types.js';
|
|
9
|
+
export type { ReplayProgressEvent, ReplayProgressState } from './types/replay-progress.types.js';
|
|
9
10
|
export type { EnrichOptions, PathRewriter, PathRule } from './types/enrich.types.js';
|
|
10
11
|
export type { ProductEvent } from './product-event.js';
|
|
11
12
|
export { CANONICAL_EVENT_TYPES, EVENT_SCHEMA_VERSION, INTERNAL_HOOK_EVENT_TYPES, PRODUCT_EVENT_TYPES, PRODUCT_EVENT_TYPE_SET, TURN_CLOSING_EVENT_TYPE } from './constants/events.constants.js';
|
|
@@ -2,26 +2,29 @@ import type { TurnSummaryEvent } from '../turns/types/turn-summary.types.js';
|
|
|
2
2
|
import type { LlmCallEvent } from './types/llm-call.types.js';
|
|
3
3
|
import type { RepoSnapshotEvent } from './types/repo-snapshot.types.js';
|
|
4
4
|
import type { RepoTreeEvent } from './types/repo-tree.types.js';
|
|
5
|
+
import type { ReplayProgressEvent, ReplayProgressState } from './types/replay-progress.types.js';
|
|
5
6
|
import type { SessionBillingEvent } from './types/session-billing.types.js';
|
|
6
7
|
export { PRODUCT_EVENT_TYPES } from './constants/events.constants.js';
|
|
7
8
|
export type { ProductEventType } from './types/events.types.js';
|
|
8
9
|
export type { LlmCallEvent, LlmCallCorrelation, LlmCallStatus } from './types/llm-call.types.js';
|
|
9
10
|
export type { RepoSnapshotBranch, RepoSnapshotCommit, RepoSnapshotCommitFile, RepoSnapshotEvent } from './types/repo-snapshot.types.js';
|
|
10
11
|
export type { RepoTreeEvent, RepoTreeFile } from './types/repo-tree.types.js';
|
|
12
|
+
export type { ReplayProgressEvent, ReplayProgressState };
|
|
11
13
|
export type { SessionBillingEvent } from './types/session-billing.types.js';
|
|
12
14
|
export type { AgentUsageSummary, TurnSummaryEvent, TurnUsageStatus } from '../turns/types/turn-summary.types.js';
|
|
13
15
|
/**
|
|
14
16
|
* The complete public AgentWatch domain contract.
|
|
15
17
|
*
|
|
16
|
-
*
|
|
18
|
+
* Six record types, deliberately: `llm.call` is the lossless per-request
|
|
17
19
|
* usage ledger, `turn.summary` is the human unit of work, `repo.snapshot`
|
|
18
20
|
* is what the working copy says the work *is* when no tracker can be asked,
|
|
19
21
|
* `session.billing` is how the session's developer pays, and `repo.tree` is
|
|
20
|
-
* what the trunk's code is called when nothing can clone it.
|
|
22
|
+
* what the trunk's code is called when nothing can clone it, and `replay.progress`
|
|
23
|
+
* counts how far a replay of earlier sessions has got. No
|
|
21
24
|
* lifecycle or tool event is public — those exist only to assemble a summary
|
|
22
25
|
* locally.
|
|
23
26
|
*/
|
|
24
|
-
export type ProductEvent = LlmCallEvent | TurnSummaryEvent | RepoSnapshotEvent | SessionBillingEvent | RepoTreeEvent;
|
|
27
|
+
export type ProductEvent = LlmCallEvent | TurnSummaryEvent | RepoSnapshotEvent | SessionBillingEvent | RepoTreeEvent | ReplayProgressEvent;
|
|
25
28
|
/** The least a value must look like for {@link isProductEvent} to judge it. */
|
|
26
29
|
export interface EventTypeCarrier {
|
|
27
30
|
readonly event?: {
|
|
@@ -32,6 +32,10 @@ export interface EventSession {
|
|
|
32
32
|
readonly turnId?: string;
|
|
33
33
|
readonly generationId?: string;
|
|
34
34
|
readonly agentId?: string;
|
|
35
|
+
/** The agent's mode when the session started, where its start hook names one (Cursor `composer_mode`). */
|
|
36
|
+
readonly mode?: string;
|
|
37
|
+
/** Whether the agent runs the session in the vendor's cloud (Cursor `is_background_agent`). */
|
|
38
|
+
readonly isCloudAgent?: boolean;
|
|
35
39
|
}
|
|
36
40
|
export interface EventGit {
|
|
37
41
|
readonly repository?: string;
|
|
@@ -78,6 +82,8 @@ export interface AgentWatchEvent<TType extends CanonicalEventType = CanonicalEve
|
|
|
78
82
|
readonly session: EventSession;
|
|
79
83
|
readonly developer?: {
|
|
80
84
|
readonly installationId?: string;
|
|
85
|
+
/** The email the agent's own account is signed in as, where its hook names one (Cursor `user_email`). */
|
|
86
|
+
readonly accountEmail?: string;
|
|
81
87
|
};
|
|
82
88
|
readonly git?: EventGit;
|
|
83
89
|
readonly feature?: {
|