@agent-watch-ai/edge 0.2.5 → 0.3.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 +512 -0
- package/README.md +217 -96
- package/SECURITY.md +69 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +50 -4
- package/dist/cli/constants/cli.constants.js +54 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +309 -32
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +439 -98
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +113 -0
- package/dist/cli/types/cli.types.d.ts +37 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +100 -13
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +113 -6
- package/dist/config/constants/config.constants.js +126 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +721 -84
- package/dist/config/schemas/config.schema.js +388 -15
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +111 -0
- package/dist/credentials/constants/credentials.constants.js +112 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +34 -0
- package/dist/credentials/credentials.d.ts +72 -0
- package/dist/credentials/credentials.js +253 -0
- package/dist/credentials/device-api.d.ts +64 -0
- package/dist/credentials/device-api.js +150 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +62 -0
- package/dist/credentials/identity.js +90 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +18 -0
- package/dist/credentials/sign-in.js +86 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +195 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +62 -16
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +103 -15
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +64 -0
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
- package/dist/pipeline/constants/pipeline.constants.js +7 -0
- package/dist/pipeline/hook-pipeline.js +360 -32
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +73 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +24 -2
- package/dist/providers/codex/codex.otel.js +147 -30
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/constants/provider.constants.d.ts +0 -3
- package/dist/providers/constants/provider.constants.js +0 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
- package/dist/providers/cursor/constants/cursor.constants.js +7 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +52 -3
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +19 -20
- package/dist/providers/gemini/gemini.otel.js +121 -17
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
- package/dist/providers/shared/constants/tooling.constants.js +19 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +12 -1
- package/dist/providers/shared/tooling.js +18 -0
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +57 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +7 -0
- package/dist/storage/atomic-file.js +1 -1
- package/dist/storage/constants/storage.constants.d.ts +17 -0
- package/dist/storage/constants/storage.constants.js +17 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +65 -0
- package/dist/turns/work-checkout.js +666 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +648 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
package/dist/core/pipe.d.ts
CHANGED
|
@@ -40,16 +40,3 @@ export declare function step<TState>(name: string, run: Step<TState>['run']): St
|
|
|
40
40
|
* @returns The final state, whether every stage ran, and where it stopped.
|
|
41
41
|
*/
|
|
42
42
|
export declare function runFlow<TState>(steps: readonly Step<TState>[], initial: TState, observe?: FlowObserver): Promise<FlowResult<TState>>;
|
|
43
|
-
/**
|
|
44
|
-
* Left-to-right function composition for plain value transformations, so a
|
|
45
|
-
* derivation reads in the order it happens instead of inside-out.
|
|
46
|
-
*
|
|
47
|
-
* Takes the unary transformations to apply, in order.
|
|
48
|
-
*
|
|
49
|
-
* @returns One function that threads its argument through all of them.
|
|
50
|
-
*/
|
|
51
|
-
export declare function pipe<A, B>(ab: (a: A) => B): (a: A) => B;
|
|
52
|
-
export declare function pipe<A, B, C>(ab: (a: A) => B, bc: (b: B) => C): (a: A) => C;
|
|
53
|
-
export declare function pipe<A, B, C, D>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): (a: A) => D;
|
|
54
|
-
export declare function pipe<A, B, C, D, E>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): (a: A) => E;
|
|
55
|
-
export declare function pipe<A, B, C, D, E, F>(ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): (a: A) => F;
|
package/dist/core/pipe.js
CHANGED
|
@@ -52,7 +52,7 @@ export async function runFlow(steps, initial, observe) {
|
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
54
54
|
observe?.({ step: current.name, outcome: 'threw', reason: errorMessage(error) });
|
|
55
|
-
return { state, completed: false, stoppedAt: current.name, reason: errorMessage(error) };
|
|
55
|
+
return { state, completed: false, stoppedAt: current.name, reason: errorMessage(error), cause: error };
|
|
56
56
|
}
|
|
57
57
|
observe?.({ step: current.name, outcome: outcome.kind, reason: outcome.kind === 'stop' ? outcome.reason : undefined });
|
|
58
58
|
if (outcome.kind === 'stop') {
|
|
@@ -62,14 +62,6 @@ export async function runFlow(steps, initial, observe) {
|
|
|
62
62
|
}
|
|
63
63
|
return { state, completed: true };
|
|
64
64
|
}
|
|
65
|
-
export function pipe(...fns) {
|
|
66
|
-
return (value) => {
|
|
67
|
-
let current = value;
|
|
68
|
-
for (const fn of fns)
|
|
69
|
-
current = fn(current);
|
|
70
|
-
return current;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
65
|
/**
|
|
74
66
|
* Human-readable text for anything that reached a catch block.
|
|
75
67
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProcessTable } from '../../process/types/process.types.js';
|
|
1
2
|
/**
|
|
2
3
|
* Ambient runtime contracts shared by every module.
|
|
3
4
|
*/
|
|
@@ -13,6 +14,12 @@ export interface Env {
|
|
|
13
14
|
/** Mirrors `process.env`, which is mutable ambient state by nature. */
|
|
14
15
|
readonly vars: Record<string, string | undefined>;
|
|
15
16
|
now(): Date;
|
|
17
|
+
/** The process table the ancestor walk reads; the machine's own when absent. Tests inject a tree. */
|
|
18
|
+
readonly processes?: ProcessTable;
|
|
19
|
+
/** Where system tools such as the keychain CLIs are looked up; the OS's own directories when absent. Tests inject a fake bin. */
|
|
20
|
+
readonly systemBinDirs?: readonly string[];
|
|
21
|
+
/** Starts a detached `agentwatch <args>`; the built CLI when absent. Tests inject one that starts nothing. */
|
|
22
|
+
readonly startDetached?: (args: readonly string[]) => void;
|
|
16
23
|
}
|
|
17
24
|
/** Any JSON object decoded from an untrusted source. */
|
|
18
25
|
export type UnknownRecord = Record<string, unknown>;
|
|
@@ -43,6 +50,8 @@ export interface FlowResult<TState> {
|
|
|
43
50
|
readonly state: TState;
|
|
44
51
|
readonly completed: boolean;
|
|
45
52
|
readonly stoppedAt?: string;
|
|
53
|
+
/** Original thrown value retained for callers, never included in observer traces. */
|
|
54
|
+
readonly cause?: unknown;
|
|
46
55
|
readonly reason?: string;
|
|
47
56
|
}
|
|
48
57
|
/** Per-stage trace hook. The flow itself stays pure; I/O lives in the observer. */
|
package/dist/core/which.d.ts
CHANGED
|
@@ -11,3 +11,17 @@ import type { Env } from './types/core.types.js';
|
|
|
11
11
|
* @returns Absolute path of the first match, or undefined when not found.
|
|
12
12
|
*/
|
|
13
13
|
export declare function findExecutable(env: Env, name: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Locate a tool the OS ships, in the OS's own directories only.
|
|
16
|
+
*
|
|
17
|
+
* For a tool that is handed a secret: a hook inherits the agent's PATH, which
|
|
18
|
+
* often lists user-writable or project-relative directories (`node_modules/.bin`,
|
|
19
|
+
* `~/.local/bin`, `.`) ahead of the system ones, and whatever sits there first
|
|
20
|
+
* would receive it. Linux alone falls back to PATH, because distributions do
|
|
21
|
+
* not agree on where `secret-tool` lives.
|
|
22
|
+
*
|
|
23
|
+
* @param env - Environment supplying the platform (and, in tests, the directories).
|
|
24
|
+
* @param name - Executable name without extension.
|
|
25
|
+
* @returns Absolute path, or undefined when the OS does not have it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findSystemExecutable(env: Env, name: string): string | undefined;
|
package/dist/core/which.js
CHANGED
|
@@ -13,12 +13,52 @@ import { POSIX_EXECUTABLE_MASK, WINDOWS_EXECUTABLE_EXTENSIONS } from './constant
|
|
|
13
13
|
* @returns Absolute path of the first match, or undefined when not found.
|
|
14
14
|
*/
|
|
15
15
|
export function findExecutable(env, name) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return findIn((env.vars['PATH'] ?? '').split(path.delimiter).filter(Boolean), env.platform, name);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Locate a tool the OS ships, in the OS's own directories only.
|
|
20
|
+
*
|
|
21
|
+
* For a tool that is handed a secret: a hook inherits the agent's PATH, which
|
|
22
|
+
* often lists user-writable or project-relative directories (`node_modules/.bin`,
|
|
23
|
+
* `~/.local/bin`, `.`) ahead of the system ones, and whatever sits there first
|
|
24
|
+
* would receive it. Linux alone falls back to PATH, because distributions do
|
|
25
|
+
* not agree on where `secret-tool` lives.
|
|
26
|
+
*
|
|
27
|
+
* @param env - Environment supplying the platform (and, in tests, the directories).
|
|
28
|
+
* @param name - Executable name without extension.
|
|
29
|
+
* @returns Absolute path, or undefined when the OS does not have it.
|
|
30
|
+
*/
|
|
31
|
+
export function findSystemExecutable(env, name) {
|
|
32
|
+
const found = findIn(env.systemBinDirs ?? systemBinDirs(env), env.platform, name);
|
|
33
|
+
if (found || env.systemBinDirs || env.platform !== 'linux')
|
|
34
|
+
return found;
|
|
35
|
+
return findExecutable(env, name);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Where each OS keeps the tools it ships.
|
|
39
|
+
*
|
|
40
|
+
* @param env - Environment supplying the platform and, on Windows, `SystemRoot`.
|
|
41
|
+
* @returns Absolute directories, most specific first.
|
|
42
|
+
*/
|
|
43
|
+
function systemBinDirs(env) {
|
|
44
|
+
if (env.platform === 'win32')
|
|
45
|
+
return [path.win32.join(env.vars['SystemRoot'] ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0')];
|
|
46
|
+
return ['/usr/bin', '/bin'];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The first executable match in a list of directories.
|
|
50
|
+
*
|
|
51
|
+
* @param dirs - Directories to search, in order.
|
|
52
|
+
* @param platform - Host platform.
|
|
53
|
+
* @param name - Executable name without extension.
|
|
54
|
+
* @returns Absolute path, or undefined.
|
|
55
|
+
*/
|
|
56
|
+
function findIn(dirs, platform, name) {
|
|
57
|
+
const candidates = executableCandidates(platform, name);
|
|
18
58
|
for (const dir of dirs) {
|
|
19
59
|
for (const candidate of candidates) {
|
|
20
60
|
const full = path.join(dir, candidate);
|
|
21
|
-
if (isExecutableFile(full,
|
|
61
|
+
if (isExecutableFile(full, platform))
|
|
22
62
|
return full;
|
|
23
63
|
}
|
|
24
64
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StoreDeps } from './types/credentials.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The context for one more credential step: its timeout cut to what is left
|
|
4
|
+
* of the deadline.
|
|
5
|
+
*
|
|
6
|
+
* @param deps - Context, with or without a deadline.
|
|
7
|
+
* @returns The context to run the step with, or undefined when nothing is left.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withinBudget<T extends StoreDeps>(deps: T): T | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* The context for one more credential step: its timeout cut to what is left
|
|
4
|
+
* of the deadline.
|
|
5
|
+
*
|
|
6
|
+
* @param deps - Context, with or without a deadline.
|
|
7
|
+
* @returns The context to run the step with, or undefined when nothing is left.
|
|
8
|
+
*/
|
|
9
|
+
export function withinBudget(deps) {
|
|
10
|
+
if (deps.deadline === undefined)
|
|
11
|
+
return deps;
|
|
12
|
+
const left = Math.floor(deps.deadline - performance.now());
|
|
13
|
+
if (left <= 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
return { ...deps, timeoutMs: Math.min(deps.timeoutMs, left) };
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CommandRunner } from './types/credentials.types.js';
|
|
2
|
+
export type { CommandResult, CommandRunner } from './types/credentials.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run a keychain tool with a secret on stdin.
|
|
5
|
+
*
|
|
6
|
+
* No shell, so nothing in `args` is ever interpreted, and the secret is never in
|
|
7
|
+
* `args` or the child's environment, where `ps` or a crash report could read it.
|
|
8
|
+
* Never throws and never hangs past the timeout: a locked keychain that wants a
|
|
9
|
+
* GUI prompt must cost the caller its budget, not its turn.
|
|
10
|
+
*
|
|
11
|
+
* @param file - Absolute path of the tool.
|
|
12
|
+
* @param args - Arguments; never a secret.
|
|
13
|
+
* @param options - What to write to stdin, the timeout and the environment.
|
|
14
|
+
* @returns The exit code (null when killed or not started) and stdout.
|
|
15
|
+
*/
|
|
16
|
+
export declare const runCommand: CommandRunner;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Run a keychain tool with a secret on stdin.
|
|
4
|
+
*
|
|
5
|
+
* No shell, so nothing in `args` is ever interpreted, and the secret is never in
|
|
6
|
+
* `args` or the child's environment, where `ps` or a crash report could read it.
|
|
7
|
+
* Never throws and never hangs past the timeout: a locked keychain that wants a
|
|
8
|
+
* GUI prompt must cost the caller its budget, not its turn.
|
|
9
|
+
*
|
|
10
|
+
* @param file - Absolute path of the tool.
|
|
11
|
+
* @param args - Arguments; never a secret.
|
|
12
|
+
* @param options - What to write to stdin, the timeout and the environment.
|
|
13
|
+
* @returns The exit code (null when killed or not started) and stdout.
|
|
14
|
+
*/
|
|
15
|
+
export const runCommand = (file, args, options) => new Promise((resolve) => {
|
|
16
|
+
const chunks = [];
|
|
17
|
+
let settled = false;
|
|
18
|
+
const finish = (code) => {
|
|
19
|
+
if (settled)
|
|
20
|
+
return;
|
|
21
|
+
settled = true;
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
resolve({ code, stdout: Buffer.concat(chunks).toString('utf8') });
|
|
24
|
+
};
|
|
25
|
+
const child = spawn(file, [...args], { env: options.env, stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true });
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
child.kill();
|
|
28
|
+
finish(null);
|
|
29
|
+
}, options.timeoutMs);
|
|
30
|
+
child.stdout.on('data', (chunk) => chunks.push(chunk));
|
|
31
|
+
child.on('error', () => finish(null));
|
|
32
|
+
child.on('close', (code) => finish(code));
|
|
33
|
+
child.stdin.on('error', () => {
|
|
34
|
+
// The tool exited before reading its input; its exit code says why.
|
|
35
|
+
});
|
|
36
|
+
child.stdin.end(options.input ?? '');
|
|
37
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a device secret can live, most protected first. Recorded in the config
|
|
3
|
+
* beside the device id, so a read goes straight to the backend that holds it
|
|
4
|
+
* instead of probing (a headless Linux box would otherwise wait on D-Bus).
|
|
5
|
+
*/
|
|
6
|
+
export declare const CREDENTIAL_STORE_KINDS: readonly ["macos-keychain", "libsecret", "windows-dpapi", "file"];
|
|
7
|
+
/**
|
|
8
|
+
* Prefix of an identity that is a device credential rather than an install key.
|
|
9
|
+
*
|
|
10
|
+
* The rest is the fingerprint of the install key the credential replaced, which
|
|
11
|
+
* is already the name of that identity's queue partition and state directory,
|
|
12
|
+
* so a migrated install keeps its backlog, loss tally and credential block.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEVICE_IDENTITY_PREFIX = "device:";
|
|
15
|
+
/** A device id is the install key's partition fingerprint: 12 lower-case hex characters. */
|
|
16
|
+
export declare const RE_DEVICE_ID: RegExp;
|
|
17
|
+
/** Keyed in the OS keychain under this service, one account per device id. */
|
|
18
|
+
export declare const KEYCHAIN_SERVICE = "agentwatch-device";
|
|
19
|
+
/** Shown in the macOS Keychain Access / GNOME Seahorse list. */
|
|
20
|
+
export declare const KEYCHAIN_LABEL = "AgentWatch device credential";
|
|
21
|
+
/** Under the config directory: the DPAPI blobs and, without a keychain, the secret files. */
|
|
22
|
+
export declare const CREDENTIALS_DIR_NAME = "credentials";
|
|
23
|
+
export declare const SECRET_FILE_SUFFIX = ".secret";
|
|
24
|
+
export declare const DPAPI_FILE_SUFFIX = ".dpapi";
|
|
25
|
+
/**
|
|
26
|
+
* What a secret may contain before it is handed to a keychain tool. The gateway
|
|
27
|
+
* mints `aw_dsk_` plus base64url, so this costs nothing real, and it keeps a
|
|
28
|
+
* space or a quote from ever becoming an argument of `security -i`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const RE_SECRET_CHARS: RegExp;
|
|
31
|
+
/**
|
|
32
|
+
* A macOS home without this directory has no keychain (a temp HOME in a test,
|
|
33
|
+
* a CI runner, a service account): `security` would pop "Keychain Not Found"
|
|
34
|
+
* on the person's screen for every write, so the secret goes to the file.
|
|
35
|
+
*/
|
|
36
|
+
export declare const MACOS_KEYCHAINS_DIR: string[];
|
|
37
|
+
/** Linux keychain needs a session bus; without one `secret-tool` waits on D-Bus and fails. */
|
|
38
|
+
export declare const DBUS_SESSION_VAR = "DBUS_SESSION_BUS_ADDRESS";
|
|
39
|
+
/** Reads the secret from stdin, prints the DPAPI blob (current user) as base64. */
|
|
40
|
+
export declare const DPAPI_PROTECT_SCRIPT = "$ErrorActionPreference='Stop';Add-Type -AssemblyName System.Security;$scope=[Security.Cryptography.DataProtectionScope]::CurrentUser;$s=[Console]::In.ReadToEnd();[Console]::Out.Write([Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Protect([Text.Encoding]::UTF8.GetBytes($s),$null,$scope)))";
|
|
41
|
+
/** Reads the base64 blob from stdin, prints the secret. */
|
|
42
|
+
export declare const DPAPI_UNPROTECT_SCRIPT = "$ErrorActionPreference='Stop';Add-Type -AssemblyName System.Security;$scope=[Security.Cryptography.DataProtectionScope]::CurrentUser;$b=[Convert]::FromBase64String([Console]::In.ReadToEnd().Trim());[Console]::Out.Write([Text.Encoding]::UTF8.GetString([Security.Cryptography.ProtectedData]::Unprotect($b,$null,$scope)))";
|
|
43
|
+
/** How each store is named to a person reading `status` or `doctor`. */
|
|
44
|
+
export declare const STORE_LABELS: {
|
|
45
|
+
readonly 'macos-keychain': "macOS Keychain";
|
|
46
|
+
readonly libsecret: "the Secret Service keyring (libsecret)";
|
|
47
|
+
readonly 'windows-dpapi': "a Windows DPAPI-protected file";
|
|
48
|
+
readonly file: "a private file (no OS keychain found)";
|
|
49
|
+
};
|
|
50
|
+
/** Gateway routes (AWT-354). Enroll takes the install key as bearer; token takes the device secret in the body. */
|
|
51
|
+
export declare const ENROLL_PATH = "/v1/devices/enroll";
|
|
52
|
+
export declare const TOKEN_PATH = "/v1/devices/token";
|
|
53
|
+
/** AWT-275 browser sign-in (RFC 8628): start a session, then poll it with the device code in the body. */
|
|
54
|
+
export declare const ENROLLMENT_SESSION_PATH = "/v1/devices/enrollment-sessions";
|
|
55
|
+
export declare const ENROLLMENT_SESSION_TOKEN_PATH = "/v1/devices/enrollment-sessions/token";
|
|
56
|
+
/** The RFC 8628 answers of a poll that are not failures: keep waiting. */
|
|
57
|
+
export declare const POLL_PENDING = "authorization_pending";
|
|
58
|
+
export declare const POLL_SLOW_DOWN = "slow_down";
|
|
59
|
+
export declare const POLL_DENIED = "access_denied";
|
|
60
|
+
export declare const POLL_EXPIRED = "expired_token";
|
|
61
|
+
/** RFC 8628 §3.5: a `slow_down` adds this much to the poll interval. */
|
|
62
|
+
export declare const SLOW_DOWN_STEP_MS = 5000;
|
|
63
|
+
/** AWT-275 self-revoke: the device secret in the body; `204` for any well-formed secret, known or not. */
|
|
64
|
+
export declare const REVOKE_PATH = "/v1/devices/revoke";
|
|
65
|
+
/** The `401` reasons the gateway sends on an edge route (AWT-355). */
|
|
66
|
+
export declare const REFUSAL_TOKEN_EXPIRED = "token_expired";
|
|
67
|
+
export declare const REFUSAL_DEVICE_REVOKED = "device_revoked";
|
|
68
|
+
export declare const REFUSAL_INSTALL_KEY_RETIRED = "install_key_retired";
|
|
69
|
+
/** The one refusal any run may answer with a new enrollment: the secret only aged out, nobody revoked it. */
|
|
70
|
+
export declare const REFUSAL_SECRET_EXPIRED = "device_secret_expired";
|
|
71
|
+
/**
|
|
72
|
+
* The refresh route's own refusals (core `DeviceRefusal`): the device secret is
|
|
73
|
+
* no longer good, and nothing but a new enrollment fixes that. Only these are
|
|
74
|
+
* permanent; any other refusal, status or network failure is retried after the
|
|
75
|
+
* backend cooldown.
|
|
76
|
+
*/
|
|
77
|
+
export declare const DEVICE_REFUSALS: ReadonlySet<string>;
|
|
78
|
+
/** Every reason the edge acts on, from any route. */
|
|
79
|
+
export declare const KNOWN_REFUSALS: ReadonlySet<string>;
|
|
80
|
+
/**
|
|
81
|
+
* The share of the hook's delivery budget credential work may spend: a
|
|
82
|
+
* keychain read, a refresh or an exchange together. The send gets the rest, so
|
|
83
|
+
* a slow keychain and a dead gateway never cost the hook more than it waited
|
|
84
|
+
* before device credentials.
|
|
85
|
+
*/
|
|
86
|
+
export declare const CREDENTIAL_BUDGET_SHARE = 0.5;
|
|
87
|
+
/** Plan D3: refresh once less than this share of the access token's life remains. */
|
|
88
|
+
export declare const REFRESH_REMAINING_FRACTION = 0.25;
|
|
89
|
+
/**
|
|
90
|
+
* How long a Windows hook waits before starting another background refresh
|
|
91
|
+
* for a DPAPI device, so a burst of hooks starts one PowerShell, not one each.
|
|
92
|
+
*/
|
|
93
|
+
export declare const BACKGROUND_REFRESH_RETRY_MS = 300000;
|
|
94
|
+
/** The hidden CLI command a Windows hook starts to refresh a DPAPI device's token. */
|
|
95
|
+
export declare const REFRESH_COMMAND = "refresh-credential";
|
|
96
|
+
/** One lock per device: only the current and previous token stay valid, so one refresher per machine. */
|
|
97
|
+
export declare const TOKEN_LOCK_PREFIX = "device-token-";
|
|
98
|
+
/** One exchange at a time per install key on this machine. */
|
|
99
|
+
export declare const ENROLL_LOCK_PREFIX = "device-enroll-";
|
|
100
|
+
/**
|
|
101
|
+
* How long a failed exchange waits before the next try. The gateway allows 20
|
|
102
|
+
* enrollments per address per hour, and an office of machines behind one NAT
|
|
103
|
+
* all retrying on every hook would spend that for everyone.
|
|
104
|
+
*/
|
|
105
|
+
export declare const ENROLL_RETRY_MS = 3600000;
|
|
106
|
+
/**
|
|
107
|
+
* A sign-in approver the edge will print and store: a plain email, no spaces,
|
|
108
|
+
* control or format characters (a bidi override would disguise the identity). Anything else is dropped rather than refusing a sign-in
|
|
109
|
+
* the gateway already approved.
|
|
110
|
+
*/
|
|
111
|
+
export declare const RE_PLAIN_EMAIL: RegExp;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a device secret can live, most protected first. Recorded in the config
|
|
3
|
+
* beside the device id, so a read goes straight to the backend that holds it
|
|
4
|
+
* instead of probing (a headless Linux box would otherwise wait on D-Bus).
|
|
5
|
+
*/
|
|
6
|
+
export const CREDENTIAL_STORE_KINDS = ['macos-keychain', 'libsecret', 'windows-dpapi', 'file'];
|
|
7
|
+
/**
|
|
8
|
+
* Prefix of an identity that is a device credential rather than an install key.
|
|
9
|
+
*
|
|
10
|
+
* The rest is the fingerprint of the install key the credential replaced, which
|
|
11
|
+
* is already the name of that identity's queue partition and state directory,
|
|
12
|
+
* so a migrated install keeps its backlog, loss tally and credential block.
|
|
13
|
+
*/
|
|
14
|
+
export const DEVICE_IDENTITY_PREFIX = 'device:';
|
|
15
|
+
/** A device id is the install key's partition fingerprint: 12 lower-case hex characters. */
|
|
16
|
+
export const RE_DEVICE_ID = /^[0-9a-f]{12}$/;
|
|
17
|
+
/** Keyed in the OS keychain under this service, one account per device id. */
|
|
18
|
+
export const KEYCHAIN_SERVICE = 'agentwatch-device';
|
|
19
|
+
/** Shown in the macOS Keychain Access / GNOME Seahorse list. */
|
|
20
|
+
export const KEYCHAIN_LABEL = 'AgentWatch device credential';
|
|
21
|
+
/** Under the config directory: the DPAPI blobs and, without a keychain, the secret files. */
|
|
22
|
+
export const CREDENTIALS_DIR_NAME = 'credentials';
|
|
23
|
+
export const SECRET_FILE_SUFFIX = '.secret';
|
|
24
|
+
export const DPAPI_FILE_SUFFIX = '.dpapi';
|
|
25
|
+
/**
|
|
26
|
+
* What a secret may contain before it is handed to a keychain tool. The gateway
|
|
27
|
+
* mints `aw_dsk_` plus base64url, so this costs nothing real, and it keeps a
|
|
28
|
+
* space or a quote from ever becoming an argument of `security -i`.
|
|
29
|
+
*/
|
|
30
|
+
export const RE_SECRET_CHARS = /^[A-Za-z0-9_-]{1,200}$/;
|
|
31
|
+
/**
|
|
32
|
+
* A macOS home without this directory has no keychain (a temp HOME in a test,
|
|
33
|
+
* a CI runner, a service account): `security` would pop "Keychain Not Found"
|
|
34
|
+
* on the person's screen for every write, so the secret goes to the file.
|
|
35
|
+
*/
|
|
36
|
+
export const MACOS_KEYCHAINS_DIR = ['Library', 'Keychains'];
|
|
37
|
+
/** Linux keychain needs a session bus; without one `secret-tool` waits on D-Bus and fails. */
|
|
38
|
+
export const DBUS_SESSION_VAR = 'DBUS_SESSION_BUS_ADDRESS';
|
|
39
|
+
const DPAPI_PRELUDE = "$ErrorActionPreference='Stop';Add-Type -AssemblyName System.Security;$scope=[Security.Cryptography.DataProtectionScope]::CurrentUser;";
|
|
40
|
+
/** Reads the secret from stdin, prints the DPAPI blob (current user) as base64. */
|
|
41
|
+
export const DPAPI_PROTECT_SCRIPT = `${DPAPI_PRELUDE}$s=[Console]::In.ReadToEnd();[Console]::Out.Write([Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Protect([Text.Encoding]::UTF8.GetBytes($s),$null,$scope)))`;
|
|
42
|
+
/** Reads the base64 blob from stdin, prints the secret. */
|
|
43
|
+
export const DPAPI_UNPROTECT_SCRIPT = `${DPAPI_PRELUDE}$b=[Convert]::FromBase64String([Console]::In.ReadToEnd().Trim());[Console]::Out.Write([Text.Encoding]::UTF8.GetString([Security.Cryptography.ProtectedData]::Unprotect($b,$null,$scope)))`;
|
|
44
|
+
/** How each store is named to a person reading `status` or `doctor`. */
|
|
45
|
+
export const STORE_LABELS = {
|
|
46
|
+
'macos-keychain': 'macOS Keychain',
|
|
47
|
+
libsecret: 'the Secret Service keyring (libsecret)',
|
|
48
|
+
'windows-dpapi': 'a Windows DPAPI-protected file',
|
|
49
|
+
file: 'a private file (no OS keychain found)'
|
|
50
|
+
};
|
|
51
|
+
/** Gateway routes (AWT-354). Enroll takes the install key as bearer; token takes the device secret in the body. */
|
|
52
|
+
export const ENROLL_PATH = '/v1/devices/enroll';
|
|
53
|
+
export const TOKEN_PATH = '/v1/devices/token';
|
|
54
|
+
/** AWT-275 browser sign-in (RFC 8628): start a session, then poll it with the device code in the body. */
|
|
55
|
+
export const ENROLLMENT_SESSION_PATH = '/v1/devices/enrollment-sessions';
|
|
56
|
+
export const ENROLLMENT_SESSION_TOKEN_PATH = '/v1/devices/enrollment-sessions/token';
|
|
57
|
+
/** The RFC 8628 answers of a poll that are not failures: keep waiting. */
|
|
58
|
+
export const POLL_PENDING = 'authorization_pending';
|
|
59
|
+
export const POLL_SLOW_DOWN = 'slow_down';
|
|
60
|
+
export const POLL_DENIED = 'access_denied';
|
|
61
|
+
export const POLL_EXPIRED = 'expired_token';
|
|
62
|
+
/** RFC 8628 §3.5: a `slow_down` adds this much to the poll interval. */
|
|
63
|
+
export const SLOW_DOWN_STEP_MS = 5000;
|
|
64
|
+
/** AWT-275 self-revoke: the device secret in the body; `204` for any well-formed secret, known or not. */
|
|
65
|
+
export const REVOKE_PATH = '/v1/devices/revoke';
|
|
66
|
+
/** The `401` reasons the gateway sends on an edge route (AWT-355). */
|
|
67
|
+
export const REFUSAL_TOKEN_EXPIRED = 'token_expired';
|
|
68
|
+
export const REFUSAL_DEVICE_REVOKED = 'device_revoked';
|
|
69
|
+
export const REFUSAL_INSTALL_KEY_RETIRED = 'install_key_retired';
|
|
70
|
+
/** The one refusal any run may answer with a new enrollment: the secret only aged out, nobody revoked it. */
|
|
71
|
+
export const REFUSAL_SECRET_EXPIRED = 'device_secret_expired';
|
|
72
|
+
/**
|
|
73
|
+
* The refresh route's own refusals (core `DeviceRefusal`): the device secret is
|
|
74
|
+
* no longer good, and nothing but a new enrollment fixes that. Only these are
|
|
75
|
+
* permanent; any other refusal, status or network failure is retried after the
|
|
76
|
+
* backend cooldown.
|
|
77
|
+
*/
|
|
78
|
+
export const DEVICE_REFUSALS = new Set([REFUSAL_DEVICE_REVOKED, 'device_unknown', REFUSAL_SECRET_EXPIRED]);
|
|
79
|
+
/** Every reason the edge acts on, from any route. */
|
|
80
|
+
export const KNOWN_REFUSALS = new Set([REFUSAL_TOKEN_EXPIRED, REFUSAL_INSTALL_KEY_RETIRED, ...DEVICE_REFUSALS]);
|
|
81
|
+
/**
|
|
82
|
+
* The share of the hook's delivery budget credential work may spend: a
|
|
83
|
+
* keychain read, a refresh or an exchange together. The send gets the rest, so
|
|
84
|
+
* a slow keychain and a dead gateway never cost the hook more than it waited
|
|
85
|
+
* before device credentials.
|
|
86
|
+
*/
|
|
87
|
+
export const CREDENTIAL_BUDGET_SHARE = 0.5;
|
|
88
|
+
/** Plan D3: refresh once less than this share of the access token's life remains. */
|
|
89
|
+
export const REFRESH_REMAINING_FRACTION = 0.25;
|
|
90
|
+
/**
|
|
91
|
+
* How long a Windows hook waits before starting another background refresh
|
|
92
|
+
* for a DPAPI device, so a burst of hooks starts one PowerShell, not one each.
|
|
93
|
+
*/
|
|
94
|
+
export const BACKGROUND_REFRESH_RETRY_MS = 300_000;
|
|
95
|
+
/** The hidden CLI command a Windows hook starts to refresh a DPAPI device's token. */
|
|
96
|
+
export const REFRESH_COMMAND = 'refresh-credential';
|
|
97
|
+
/** One lock per device: only the current and previous token stay valid, so one refresher per machine. */
|
|
98
|
+
export const TOKEN_LOCK_PREFIX = 'device-token-';
|
|
99
|
+
/** One exchange at a time per install key on this machine. */
|
|
100
|
+
export const ENROLL_LOCK_PREFIX = 'device-enroll-';
|
|
101
|
+
/**
|
|
102
|
+
* How long a failed exchange waits before the next try. The gateway allows 20
|
|
103
|
+
* enrollments per address per hour, and an office of machines behind one NAT
|
|
104
|
+
* all retrying on every hook would spend that for everyone.
|
|
105
|
+
*/
|
|
106
|
+
export const ENROLL_RETRY_MS = 3_600_000;
|
|
107
|
+
/**
|
|
108
|
+
* A sign-in approver the edge will print and store: a plain email, no spaces,
|
|
109
|
+
* control or format characters (a bidi override would disguise the identity). Anything else is dropped rather than refusing a sign-in
|
|
110
|
+
* the gateway already approved.
|
|
111
|
+
*/
|
|
112
|
+
export const RE_PLAIN_EMAIL = /^[^\s@\p{Cc}\p{Cf}]{1,64}@[^\s@\p{Cc}\p{Cf}]{1,189}$/u;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentWatchConfig } from '../config/types/config.types.js';
|
|
2
|
+
import type { AgentWatchPaths } from '../storage/types/storage.types.js';
|
|
3
|
+
import type { CredentialReport } from './types/credentials.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* One line on this identity's credential, for `status` and `doctor`: where the
|
|
6
|
+
* device secret lives, or why there is none to use. Never the secret, never the
|
|
7
|
+
* install key.
|
|
8
|
+
*
|
|
9
|
+
* @param paths - Resolved AgentWatch paths.
|
|
10
|
+
* @param config - Effective config.
|
|
11
|
+
* @param scope - Its uninstall-marker scope; the machine's when absent.
|
|
12
|
+
* @returns How serious it is, and what to say.
|
|
13
|
+
*/
|
|
14
|
+
export declare function describeCredential(paths: AgentWatchPaths, config: AgentWatchConfig, scope?: string): Promise<CredentialReport>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isUninstalled } from '../storage/uninstalled.js';
|
|
3
|
+
import { identityPaths } from '../transport/queue-partition.js';
|
|
4
|
+
import { CREDENTIALS_DIR_NAME } from './constants/credentials.constants.js';
|
|
5
|
+
import { readDeviceState } from './device-state.js';
|
|
6
|
+
import { deviceFor, identityOf } from './identity.js';
|
|
7
|
+
import { storeLabel } from './secret-store.js';
|
|
8
|
+
/**
|
|
9
|
+
* One line on this identity's credential, for `status` and `doctor`: where the
|
|
10
|
+
* device secret lives, or why there is none to use. Never the secret, never the
|
|
11
|
+
* install key.
|
|
12
|
+
*
|
|
13
|
+
* @param paths - Resolved AgentWatch paths.
|
|
14
|
+
* @param config - Effective config.
|
|
15
|
+
* @param scope - Its uninstall-marker scope; the machine's when absent.
|
|
16
|
+
* @returns How serious it is, and what to say.
|
|
17
|
+
*/
|
|
18
|
+
export async function describeCredential(paths, config, scope) {
|
|
19
|
+
if (await isUninstalled(paths, scope))
|
|
20
|
+
return { level: 'warn', detail: 'uninstalled — run `agentwatch setup` to enroll this machine again' };
|
|
21
|
+
const device = deviceFor(config);
|
|
22
|
+
if (!device && config.token)
|
|
23
|
+
return { level: 'warn', detail: 'install key, not yet exchanged for a device credential; the next run retries' };
|
|
24
|
+
if (!device)
|
|
25
|
+
return { level: 'warn', detail: 'none configured' };
|
|
26
|
+
const { refusal } = await readDeviceState(identityPaths(paths, identityOf(config)).deviceStateFile);
|
|
27
|
+
if (refusal) {
|
|
28
|
+
return { level: 'fail', detail: `device credential refused by the backend (${refusal.reason}) since ${refusal.since}; events are queued — enroll again with \`agentwatch setup --token <install key>\`` };
|
|
29
|
+
}
|
|
30
|
+
if (device.store === 'file') {
|
|
31
|
+
return { level: 'warn', detail: `device credential in ${storeLabel('file')}: ${path.join(paths.configDir, CREDENTIALS_DIR_NAME)}` };
|
|
32
|
+
}
|
|
33
|
+
return { level: 'ok', detail: `device credential in ${storeLabel(device.store)}` };
|
|
34
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { AgentWatchConfig } from '../config/types/config.types.js';
|
|
2
|
+
import type { CredentialContext, DeviceCredentialRef, DeviceForgetResult } from './types/credentials.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The bearer to send for this config, doing the network work it needs.
|
|
5
|
+
*
|
|
6
|
+
* A config whose device is listed sends that device's access token, refreshed
|
|
7
|
+
* when due, and never its install key (which stays in the file for Codex and
|
|
8
|
+
* Gemini, AWT-357). An install key with no device yet is offered for exchange
|
|
9
|
+
* first and presented itself only while that fails. A device the gateway
|
|
10
|
+
* refused is enrolled again when `migrateInstallKey` allows it, and its install
|
|
11
|
+
* key is never sent in its place. Undefined means "nothing to send with": the
|
|
12
|
+
* caller queues. So is an uninstalled scope: neither its install key nor a
|
|
13
|
+
* token goes out until setup runs for it again.
|
|
14
|
+
*
|
|
15
|
+
* Never throws. A keychain, a token cache or a config file that cannot be
|
|
16
|
+
* written is a reason to queue this run's records, never to lose them or to
|
|
17
|
+
* fail the hook.
|
|
18
|
+
*
|
|
19
|
+
* @param ctx - Paths, clock, timeout, deadline, fetch and keychain runner.
|
|
20
|
+
* @param config - Effective config.
|
|
21
|
+
* @returns The bearer, or undefined.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveBearer(ctx: CredentialContext, config: AgentWatchConfig): Promise<string | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* The bearer to send without any network or keychain work: a cached access
|
|
26
|
+
* token that has not expired, or the install key of an identity not yet
|
|
27
|
+
* exchanged, and nothing for an uninstalled scope. For the prompt path, whose
|
|
28
|
+
* budget is a few hundred milliseconds.
|
|
29
|
+
*
|
|
30
|
+
* @param ctx - Paths and clock.
|
|
31
|
+
* @param config - Effective config.
|
|
32
|
+
* @returns The bearer, or undefined (never a throw).
|
|
33
|
+
*/
|
|
34
|
+
export declare function cachedBearer(ctx: CredentialContext, config: AgentWatchConfig): Promise<string | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Remove a device secret and its cached token, unless the config still names
|
|
37
|
+
* that device anywhere: a root may share it with the machine, or with the
|
|
38
|
+
* entry setup just gave a new key.
|
|
39
|
+
*
|
|
40
|
+
* @param ctx - Paths, environment, timeout and keychain runner.
|
|
41
|
+
* @param device - The device a new key displaced.
|
|
42
|
+
* @returns True when it was removed.
|
|
43
|
+
*/
|
|
44
|
+
export declare function forgetDeviceIfUnused(ctx: CredentialContext, device: DeviceCredentialRef): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Switch a displaced device off on the platform, then forget it here, unless the
|
|
47
|
+
* config still names it. For a sign-in that replaces one: its secret is about to
|
|
48
|
+
* be the last copy, so revoking after forgetting would be impossible.
|
|
49
|
+
*
|
|
50
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
51
|
+
* @param device - The device a new sign-in displaced.
|
|
52
|
+
* @returns True when it was removed from this machine.
|
|
53
|
+
*/
|
|
54
|
+
export declare function revokeDeviceIfUnused(ctx: CredentialContext, device: DeviceCredentialRef): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Switch off every device credential this machine holds, then remove it: the
|
|
57
|
+
* references from the config, and for each device the secret from its store
|
|
58
|
+
* and the cached access token.
|
|
59
|
+
*
|
|
60
|
+
* For uninstall. The marker goes down first, under every install key's enroll
|
|
61
|
+
* lock, so a hook mid-exchange either attached its device before (and it is
|
|
62
|
+
* collected here) or sees the marker before attaching (and revokes it itself).
|
|
63
|
+
* The references then leave the config under the config lock as one write; the
|
|
64
|
+
* gateway is called outside both locks, so a slow platform never holds them.
|
|
65
|
+
* Revocation comes before the secret is deleted, because a deleted secret
|
|
66
|
+
* cannot be revoked from here. A device the config names again by then (a
|
|
67
|
+
* concurrent setup) is left alone. One device's failure never stops another's.
|
|
68
|
+
*
|
|
69
|
+
* @param ctx - Paths, environment, timeout, fetch and keychain runner.
|
|
70
|
+
* @returns Whether the marker and the config were written, and one outcome per device.
|
|
71
|
+
*/
|
|
72
|
+
export declare function forgetDeviceCredentials(ctx: CredentialContext): Promise<DeviceForgetResult>;
|