@agent-watch-ai/edge 0.2.5 → 0.4.0
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 +558 -0
- package/README.md +222 -97
- package/SECURITY.md +72 -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 +52 -4
- package/dist/cli/constants/cli.constants.js +56 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +321 -33
- 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 +553 -103
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +117 -0
- package/dist/cli/types/cli.types.d.ts +43 -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 +110 -12
- 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 +116 -6
- package/dist/config/constants/config.constants.js +131 -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 +831 -84
- package/dist/config/schemas/config.schema.js +398 -16
- 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 +119 -0
- package/dist/credentials/constants/credentials.constants.js +120 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +38 -0
- package/dist/credentials/credentials.d.ts +86 -0
- package/dist/credentials/credentials.js +278 -0
- package/dist/credentials/device-api.d.ts +73 -0
- package/dist/credentials/device-api.js +161 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +73 -0
- package/dist/credentials/identity.js +101 -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 +31 -0
- package/dist/credentials/sign-in.js +105 -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 +206 -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 +64 -17
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +107 -17
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +66 -2
- 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 +10 -0
- package/dist/pipeline/constants/pipeline.constants.js +10 -0
- package/dist/pipeline/hook-pipeline.js +410 -33
- 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 +75 -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 +36 -3
- package/dist/providers/codex/codex.otel.js +199 -32
- 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 +10 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
- package/dist/providers/constants/provider.constants.d.ts +8 -3
- package/dist/providers/constants/provider.constants.js +8 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
- package/dist/providers/cursor/constants/cursor.constants.js +9 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +129 -4
- 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 +9 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -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 +30 -21
- package/dist/providers/gemini/gemini.otel.js +166 -22
- 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/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- 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 +24 -2
- package/dist/providers/shared/constants/tooling.constants.js +25 -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 +40 -1
- package/dist/providers/shared/tooling.js +70 -1
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +81 -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 +21 -0
- package/dist/storage/atomic-file.js +20 -1
- package/dist/storage/constants/storage.constants.d.ts +19 -0
- package/dist/storage/constants/storage.constants.js +19 -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 +67 -0
- package/dist/turns/work-checkout.js +700 -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 +655 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +194 -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/object.js
CHANGED
|
@@ -6,17 +6,22 @@
|
|
|
6
6
|
* absent instead. Building a fresh object (rather than deleting keys) also
|
|
7
7
|
* keeps the result monomorphic for V8 (STYLEGUIDE 3.4).
|
|
8
8
|
*
|
|
9
|
+
* Built on a null prototype and spread into a plain object at the end: on a
|
|
10
|
+
* plain literal an own `__proto__` key (which is what `JSON.parse` produces)
|
|
11
|
+
* would be swallowed by the setter, so the copy would silently lose the one
|
|
12
|
+
* key most likely to be present for a bad reason.
|
|
13
|
+
*
|
|
9
14
|
* @param value - Object to compact; left untouched.
|
|
10
15
|
* @returns A copy holding only the defined entries.
|
|
11
16
|
*/
|
|
12
17
|
export function compact(value) {
|
|
13
|
-
const out =
|
|
18
|
+
const out = Object.create(null);
|
|
14
19
|
for (const [key, entry] of Object.entries(value)) {
|
|
15
20
|
if (entry === undefined)
|
|
16
21
|
continue;
|
|
17
22
|
out[key] = entry;
|
|
18
23
|
}
|
|
19
|
-
return out;
|
|
24
|
+
return { ...out };
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* Copy an object without the given keys.
|
|
@@ -29,13 +34,13 @@ export function compact(value) {
|
|
|
29
34
|
* @returns A copy without those keys.
|
|
30
35
|
*/
|
|
31
36
|
export function omitKeys(value, keys) {
|
|
32
|
-
const out =
|
|
37
|
+
const out = Object.create(null);
|
|
33
38
|
for (const [key, entry] of Object.entries(value)) {
|
|
34
39
|
if (keys.has(key))
|
|
35
40
|
continue;
|
|
36
41
|
out[key] = entry;
|
|
37
42
|
}
|
|
38
|
-
return out;
|
|
43
|
+
return { ...out };
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
46
|
* Narrow an untrusted value to a plain JSON object.
|
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,119 @@
|
|
|
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
|
+
/** AWT-275 unattended enrollment: an admin-issued, single-use code in the body. */
|
|
57
|
+
export declare const ENROLL_CODE_PATH = "/v1/devices/enroll-code";
|
|
58
|
+
/** Recorded on a device enrolled with an admin-issued code, so `status` can say so (core `DeviceCredentialSource.BatchCode`). */
|
|
59
|
+
export declare const DEVICE_SOURCE_BATCH_CODE = "batch-code";
|
|
60
|
+
/** The RFC 8628 answers of a poll that are not failures: keep waiting. */
|
|
61
|
+
export declare const POLL_PENDING = "authorization_pending";
|
|
62
|
+
export declare const POLL_SLOW_DOWN = "slow_down";
|
|
63
|
+
export declare const POLL_DENIED = "access_denied";
|
|
64
|
+
export declare const POLL_EXPIRED = "expired_token";
|
|
65
|
+
/** RFC 8628 §3.5: a `slow_down` adds this much to the poll interval. */
|
|
66
|
+
export declare const SLOW_DOWN_STEP_MS = 5000;
|
|
67
|
+
/** AWT-275 self-revoke: the device secret in the body; `204` for any well-formed secret, known or not. */
|
|
68
|
+
export declare const REVOKE_PATH = "/v1/devices/revoke";
|
|
69
|
+
/** The `401` reasons the gateway sends on an edge route (AWT-355). */
|
|
70
|
+
export declare const REFUSAL_TOKEN_EXPIRED = "token_expired";
|
|
71
|
+
export declare const REFUSAL_DEVICE_REVOKED = "device_revoked";
|
|
72
|
+
export declare const REFUSAL_INSTALL_KEY_RETIRED = "install_key_retired";
|
|
73
|
+
/** The one answer to any code that cannot be redeemed: unknown, used, expired or revoked alike. */
|
|
74
|
+
export declare const REFUSAL_ENROLLMENT_CODE_INVALID = "enrollment_code_invalid";
|
|
75
|
+
/** The one refusal any run may answer with a new enrollment: the secret only aged out, nobody revoked it. */
|
|
76
|
+
export declare const REFUSAL_SECRET_EXPIRED = "device_secret_expired";
|
|
77
|
+
/**
|
|
78
|
+
* The refresh route's own refusals (core `DeviceRefusal`): the device secret is
|
|
79
|
+
* no longer good, and nothing but a new enrollment fixes that. Only these are
|
|
80
|
+
* permanent; any other refusal, status or network failure is retried after the
|
|
81
|
+
* backend cooldown.
|
|
82
|
+
*/
|
|
83
|
+
export declare const DEVICE_REFUSALS: ReadonlySet<string>;
|
|
84
|
+
/** Every reason the edge acts on, from any route. */
|
|
85
|
+
export declare const KNOWN_REFUSALS: ReadonlySet<string>;
|
|
86
|
+
/**
|
|
87
|
+
* The share of the hook's delivery budget credential work may spend: a
|
|
88
|
+
* keychain read, a refresh or an exchange together. The send gets the rest, so
|
|
89
|
+
* a slow keychain and a dead gateway never cost the hook more than it waited
|
|
90
|
+
* before device credentials.
|
|
91
|
+
*/
|
|
92
|
+
export declare const CREDENTIAL_BUDGET_SHARE = 0.5;
|
|
93
|
+
/** Plan D3: refresh once less than this share of the access token's life remains. */
|
|
94
|
+
export declare const REFRESH_REMAINING_FRACTION = 0.25;
|
|
95
|
+
/**
|
|
96
|
+
* How long a Windows hook waits before starting another background refresh
|
|
97
|
+
* for a DPAPI device, so a burst of hooks starts one PowerShell, not one each.
|
|
98
|
+
*/
|
|
99
|
+
export declare const BACKGROUND_REFRESH_RETRY_MS = 300000;
|
|
100
|
+
/** The hidden CLI command a Windows hook starts to refresh a DPAPI device's token. */
|
|
101
|
+
export declare const REFRESH_COMMAND = "refresh-credential";
|
|
102
|
+
/** One lock per device: only the current and previous token stay valid, so one refresher per machine. */
|
|
103
|
+
export declare const TOKEN_LOCK_PREFIX = "device-token-";
|
|
104
|
+
/** One exchange at a time per install key on this machine. */
|
|
105
|
+
export declare const ENROLL_LOCK_PREFIX = "device-enroll-";
|
|
106
|
+
/**
|
|
107
|
+
* How long a failed exchange waits before the next try. The gateway allows 20
|
|
108
|
+
* enrollments per address per hour, and an office of machines behind one NAT
|
|
109
|
+
* all retrying on every hook would spend that for everyone.
|
|
110
|
+
*/
|
|
111
|
+
export declare const ENROLL_RETRY_MS = 3600000;
|
|
112
|
+
/**
|
|
113
|
+
* A sign-in approver the edge will print and store: a plain email, no spaces,
|
|
114
|
+
* control or format characters (a bidi override would disguise the identity). Anything else is dropped rather than refusing a sign-in
|
|
115
|
+
* the gateway already approved.
|
|
116
|
+
*/
|
|
117
|
+
export declare const RE_PLAIN_EMAIL: RegExp;
|
|
118
|
+
/** What an MDM install that has not signed in yet tells its developer, wherever it speaks. */
|
|
119
|
+
export declare const NOT_SIGNED_IN = "AgentWatch is set up for your organization but not signed in: run `agentwatch setup` to sign in. Nothing is recorded until then";
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
/** AWT-275 unattended enrollment: an admin-issued, single-use code in the body. */
|
|
58
|
+
export const ENROLL_CODE_PATH = '/v1/devices/enroll-code';
|
|
59
|
+
/** Recorded on a device enrolled with an admin-issued code, so `status` can say so (core `DeviceCredentialSource.BatchCode`). */
|
|
60
|
+
export const DEVICE_SOURCE_BATCH_CODE = 'batch-code';
|
|
61
|
+
/** The RFC 8628 answers of a poll that are not failures: keep waiting. */
|
|
62
|
+
export const POLL_PENDING = 'authorization_pending';
|
|
63
|
+
export const POLL_SLOW_DOWN = 'slow_down';
|
|
64
|
+
export const POLL_DENIED = 'access_denied';
|
|
65
|
+
export const POLL_EXPIRED = 'expired_token';
|
|
66
|
+
/** RFC 8628 §3.5: a `slow_down` adds this much to the poll interval. */
|
|
67
|
+
export const SLOW_DOWN_STEP_MS = 5000;
|
|
68
|
+
/** AWT-275 self-revoke: the device secret in the body; `204` for any well-formed secret, known or not. */
|
|
69
|
+
export const REVOKE_PATH = '/v1/devices/revoke';
|
|
70
|
+
/** The `401` reasons the gateway sends on an edge route (AWT-355). */
|
|
71
|
+
export const REFUSAL_TOKEN_EXPIRED = 'token_expired';
|
|
72
|
+
export const REFUSAL_DEVICE_REVOKED = 'device_revoked';
|
|
73
|
+
export const REFUSAL_INSTALL_KEY_RETIRED = 'install_key_retired';
|
|
74
|
+
/** The one answer to any code that cannot be redeemed: unknown, used, expired or revoked alike. */
|
|
75
|
+
export const REFUSAL_ENROLLMENT_CODE_INVALID = 'enrollment_code_invalid';
|
|
76
|
+
/** The one refusal any run may answer with a new enrollment: the secret only aged out, nobody revoked it. */
|
|
77
|
+
export const REFUSAL_SECRET_EXPIRED = 'device_secret_expired';
|
|
78
|
+
/**
|
|
79
|
+
* The refresh route's own refusals (core `DeviceRefusal`): the device secret is
|
|
80
|
+
* no longer good, and nothing but a new enrollment fixes that. Only these are
|
|
81
|
+
* permanent; any other refusal, status or network failure is retried after the
|
|
82
|
+
* backend cooldown.
|
|
83
|
+
*/
|
|
84
|
+
export const DEVICE_REFUSALS = new Set([REFUSAL_DEVICE_REVOKED, 'device_unknown', REFUSAL_SECRET_EXPIRED]);
|
|
85
|
+
/** Every reason the edge acts on, from any route. */
|
|
86
|
+
export const KNOWN_REFUSALS = new Set([REFUSAL_TOKEN_EXPIRED, REFUSAL_INSTALL_KEY_RETIRED, REFUSAL_ENROLLMENT_CODE_INVALID, ...DEVICE_REFUSALS]);
|
|
87
|
+
/**
|
|
88
|
+
* The share of the hook's delivery budget credential work may spend: a
|
|
89
|
+
* keychain read, a refresh or an exchange together. The send gets the rest, so
|
|
90
|
+
* a slow keychain and a dead gateway never cost the hook more than it waited
|
|
91
|
+
* before device credentials.
|
|
92
|
+
*/
|
|
93
|
+
export const CREDENTIAL_BUDGET_SHARE = 0.5;
|
|
94
|
+
/** Plan D3: refresh once less than this share of the access token's life remains. */
|
|
95
|
+
export const REFRESH_REMAINING_FRACTION = 0.25;
|
|
96
|
+
/**
|
|
97
|
+
* How long a Windows hook waits before starting another background refresh
|
|
98
|
+
* for a DPAPI device, so a burst of hooks starts one PowerShell, not one each.
|
|
99
|
+
*/
|
|
100
|
+
export const BACKGROUND_REFRESH_RETRY_MS = 300_000;
|
|
101
|
+
/** The hidden CLI command a Windows hook starts to refresh a DPAPI device's token. */
|
|
102
|
+
export const REFRESH_COMMAND = 'refresh-credential';
|
|
103
|
+
/** One lock per device: only the current and previous token stay valid, so one refresher per machine. */
|
|
104
|
+
export const TOKEN_LOCK_PREFIX = 'device-token-';
|
|
105
|
+
/** One exchange at a time per install key on this machine. */
|
|
106
|
+
export const ENROLL_LOCK_PREFIX = 'device-enroll-';
|
|
107
|
+
/**
|
|
108
|
+
* How long a failed exchange waits before the next try. The gateway allows 20
|
|
109
|
+
* enrollments per address per hour, and an office of machines behind one NAT
|
|
110
|
+
* all retrying on every hook would spend that for everyone.
|
|
111
|
+
*/
|
|
112
|
+
export const ENROLL_RETRY_MS = 3_600_000;
|
|
113
|
+
/**
|
|
114
|
+
* A sign-in approver the edge will print and store: a plain email, no spaces,
|
|
115
|
+
* control or format characters (a bidi override would disguise the identity). Anything else is dropped rather than refusing a sign-in
|
|
116
|
+
* the gateway already approved.
|
|
117
|
+
*/
|
|
118
|
+
export const RE_PLAIN_EMAIL = /^[^\s@\p{Cc}\p{Cf}]{1,64}@[^\s@\p{Cc}\p{Cf}]{1,189}$/u;
|
|
119
|
+
/** What an MDM install that has not signed in yet tells its developer, wherever it speaks. */
|
|
120
|
+
export const NOT_SIGNED_IN = 'AgentWatch is set up for your organization but not signed in: run `agentwatch setup` to sign in. Nothing is recorded until then';
|
|
@@ -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,38 @@
|
|
|
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, DEVICE_SOURCE_BATCH_CODE, NOT_SIGNED_IN } from './constants/credentials.constants.js';
|
|
5
|
+
import { readDeviceState } from './device-state.js';
|
|
6
|
+
import { awaitingSignIn, 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
|
+
if (awaitingSignIn(config))
|
|
22
|
+
return { level: 'warn', detail: NOT_SIGNED_IN };
|
|
23
|
+
const device = deviceFor(config);
|
|
24
|
+
if (!device && config.token)
|
|
25
|
+
return { level: 'warn', detail: 'install key, not yet exchanged for a device credential; the next run retries' };
|
|
26
|
+
if (!device)
|
|
27
|
+
return { level: 'warn', detail: 'none configured' };
|
|
28
|
+
const { refusal } = await readDeviceState(identityPaths(paths, identityOf(config)).deviceStateFile);
|
|
29
|
+
if (refusal) {
|
|
30
|
+
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>\`` };
|
|
31
|
+
}
|
|
32
|
+
// SPEC R4: an admin-assigned identity is marked as such wherever it shows.
|
|
33
|
+
const how = device.source === DEVICE_SOURCE_BATCH_CODE ? ', enrolled with an admin-issued code' : '';
|
|
34
|
+
if (device.store === 'file') {
|
|
35
|
+
return { level: 'warn', detail: `device credential in ${storeLabel('file')}: ${path.join(paths.configDir, CREDENTIALS_DIR_NAME)}${how}` };
|
|
36
|
+
}
|
|
37
|
+
return { level: 'ok', detail: `device credential in ${storeLabel(device.store)}${how}` };
|
|
38
|
+
}
|