@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/cli/hook.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import process from 'node:process';
|
|
2
3
|
import { loadConfig } from '../config/config-store.js';
|
|
4
|
+
import { notLongerThan } from '../core/async.js';
|
|
3
5
|
import { debugLog, warnLog } from '../core/logger.js';
|
|
4
6
|
import { runHookPipeline } from '../pipeline/hook-pipeline.js';
|
|
5
|
-
import {
|
|
7
|
+
import { loadProvider } from '../providers/loaders.js';
|
|
8
|
+
import { removeRefusedExporters } from '../providers/shared/exporter-allowlist.js';
|
|
9
|
+
import { isDisabled } from '../storage/disabled.js';
|
|
10
|
+
import { loadInstallState, saveInstallState } from '../storage/install-state.js';
|
|
6
11
|
import { resolvePaths } from '../storage/paths.js';
|
|
7
|
-
import {
|
|
12
|
+
import { claimSweep } from '../storage/sweep-marker.js';
|
|
13
|
+
import { EXPORTER_SWEEP_BUDGET_MS, EXPORTER_SWEEP_INTERVAL_MS, EXPORTER_SWEEP_MARKER_FILE, MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
8
14
|
/**
|
|
9
15
|
* The `hook` command: read stdin, run the flow, answer the agent.
|
|
10
16
|
*
|
|
@@ -23,13 +29,29 @@ import { MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js'
|
|
|
23
29
|
* @returns The process exit code; always one the agent tolerates.
|
|
24
30
|
*/
|
|
25
31
|
export async function runHook(agentId, options) {
|
|
26
|
-
const provider =
|
|
32
|
+
const provider = await loadProvider(agentId);
|
|
27
33
|
if (!provider) {
|
|
28
34
|
warnLog(`unknown agent "${agentId}"; passing through`);
|
|
29
35
|
return 0;
|
|
30
36
|
}
|
|
37
|
+
const disabled = await isDisabled(resolvePaths(options.env));
|
|
31
38
|
const payload = await readPayload(options);
|
|
32
39
|
try {
|
|
40
|
+
// Disabled: answer the agent and do nothing else. The payload is read but
|
|
41
|
+
// never parsed, enriched, queued or sent — it is read because the answer
|
|
42
|
+
// depends on which hook fired. Antigravity's Stop wants `stop`, its PreToolUse
|
|
43
|
+
// wants `allow`, and its post-tool hooks want silence; the payload-less
|
|
44
|
+
// fallback would send `allow` to all three.
|
|
45
|
+
//
|
|
46
|
+
// Inside the try with everything else: a provider that throws here would
|
|
47
|
+
// exit 0 through cli.ts having written nothing, and an Antigravity hook
|
|
48
|
+
// reads that empty stdout as no decision at all.
|
|
49
|
+
if (disabled) {
|
|
50
|
+
const idle = provider.getHookResponse(payload);
|
|
51
|
+
if (idle.stdout)
|
|
52
|
+
writeStdout(options, idle.stdout);
|
|
53
|
+
return idle.exitCode;
|
|
54
|
+
}
|
|
33
55
|
const result = payload === undefined ? undefined : await processPayload(provider, payload, options);
|
|
34
56
|
const response = respondToDecision(provider, payload, result);
|
|
35
57
|
if (response.stdout)
|
|
@@ -37,8 +59,31 @@ export async function runHook(agentId, options) {
|
|
|
37
59
|
return response.exitCode;
|
|
38
60
|
}
|
|
39
61
|
catch (error) {
|
|
40
|
-
// Telemetry must never break the coding agent
|
|
62
|
+
// Telemetry must never break the coding agent — but exit 0 alone is not an
|
|
63
|
+
// answer. Antigravity's PreToolUse and Stop hooks read stdout for the
|
|
64
|
+
// decision, and silence is not the passive one; try the provider's safe
|
|
65
|
+
// response before giving up on saying anything at all.
|
|
41
66
|
debugLog('hook processing failed:', error);
|
|
67
|
+
return answerSafely(provider, payload, options);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Last-resort answer after something in the flow threw.
|
|
72
|
+
*
|
|
73
|
+
* @param provider - The agent's provider.
|
|
74
|
+
* @param payload - Decoded hook payload.
|
|
75
|
+
* @param options - Environment and the stdout sink.
|
|
76
|
+
* @returns The provider's passive exit code, or 0 when even that cannot be built.
|
|
77
|
+
*/
|
|
78
|
+
function answerSafely(provider, payload, options) {
|
|
79
|
+
try {
|
|
80
|
+
const response = provider.getHookResponse(payload);
|
|
81
|
+
if (response.stdout)
|
|
82
|
+
writeStdout(options, response.stdout);
|
|
83
|
+
return response.exitCode;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
debugLog('hook fallback response failed:', error);
|
|
42
87
|
return 0;
|
|
43
88
|
}
|
|
44
89
|
}
|
|
@@ -57,8 +102,10 @@ export async function runHook(agentId, options) {
|
|
|
57
102
|
*/
|
|
58
103
|
function respondToDecision(provider, payload, result) {
|
|
59
104
|
const message = result?.blockMessage;
|
|
60
|
-
if (message === undefined)
|
|
61
|
-
|
|
105
|
+
if (message === undefined) {
|
|
106
|
+
const notice = result?.notice === undefined ? undefined : provider.getNoticeResponse?.(payload, result.notice);
|
|
107
|
+
return notice ?? provider.getHookResponse(payload);
|
|
108
|
+
}
|
|
62
109
|
const refusal = provider.getBlockResponse?.(payload, message);
|
|
63
110
|
if (!refusal)
|
|
64
111
|
return provider.getHookResponse(payload);
|
|
@@ -79,18 +126,82 @@ function respondToDecision(provider, payload, result) {
|
|
|
79
126
|
async function processPayload(provider, payload, options) {
|
|
80
127
|
const paths = resolvePaths(options.env);
|
|
81
128
|
const loaded = await loadConfig(paths);
|
|
129
|
+
// On stderr, on every hook, because this is the only place a developer ever
|
|
130
|
+
// sees it. A config the schema refuses degrades the runtime to `fallbackConfig`
|
|
131
|
+
// — no endpoint, no token — and nothing else on this path says a word, so an
|
|
132
|
+
// install that stopped delivering the moment someone hand-edited the file
|
|
133
|
+
// looked healthy until somebody thought to run `status`. `missing` is not
|
|
134
|
+
// warned: that is a machine before `setup`, which is not a fault.
|
|
135
|
+
if (loaded.state === 'invalid')
|
|
136
|
+
warnLog(`config ${paths.configFile} is invalid (${loaded.error}); running metadata-only with nothing configured`);
|
|
137
|
+
for (const warning of loaded.warnings)
|
|
138
|
+
warnLog(`config ${paths.configFile}: ${warning}`);
|
|
82
139
|
const result = await runHookPipeline({
|
|
83
140
|
provider,
|
|
84
141
|
env: options.env,
|
|
85
142
|
paths,
|
|
86
|
-
globalConfig: loaded
|
|
143
|
+
globalConfig: loaded,
|
|
87
144
|
payload,
|
|
88
145
|
dryRun: options.dryRun === true
|
|
89
146
|
});
|
|
90
147
|
if (options.dryRun)
|
|
91
148
|
writeStdout(options, JSON.stringify({ events: result.state.outbound }, null, 2) + '\n');
|
|
149
|
+
// Only on a config that loaded: a missing or invalid one runs on
|
|
150
|
+
// `fallbackConfig`, which trusts no custom origin, so every trusted
|
|
151
|
+
// self-hosted exporter would read as refused and be deleted for good.
|
|
152
|
+
if (!options.dryRun && loaded.state === 'ok')
|
|
153
|
+
await sweepRefusedExporters(options.env, paths, loaded.config);
|
|
92
154
|
return result.state;
|
|
93
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Remove AgentWatch-owned native exporters that send outside the allowlist, at
|
|
158
|
+
* most once a day per machine.
|
|
159
|
+
*
|
|
160
|
+
* Here because a machine whose config refused a host may never see `setup` or
|
|
161
|
+
* `doctor` again, while its agents' exporters keep sending to that host with
|
|
162
|
+
* the bearer setup wrote. Bounded by a budget and never throws: the agent's
|
|
163
|
+
* turn is worth more than this check, which the next day retries. Past the
|
|
164
|
+
* budget it is left to die with the process, not counted as abandoned work:
|
|
165
|
+
* that would make the CLI exit by SIGKILL, a failed hook, over housekeeping.
|
|
166
|
+
* Stopping it at any point is safe: each file is replaced atomically, and an
|
|
167
|
+
* exporter removed before the install state is saved is simply not found again.
|
|
168
|
+
*
|
|
169
|
+
* @param env - Ambient environment.
|
|
170
|
+
* @param paths - Resolved AgentWatch paths.
|
|
171
|
+
* @param config - The machine config whose trust applies.
|
|
172
|
+
*/
|
|
173
|
+
async function sweepRefusedExporters(env, paths, config) {
|
|
174
|
+
try {
|
|
175
|
+
if (!(await claimSweep(path.join(paths.dataDir, EXPORTER_SWEEP_MARKER_FILE), EXPORTER_SWEEP_INTERVAL_MS, Date.now())))
|
|
176
|
+
return;
|
|
177
|
+
await notLongerThan(sweepAllExporters(env, paths, config), EXPORTER_SWEEP_BUDGET_MS);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
debugLog('native exporter allowlist check failed:', error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* One pass over every agent, persisting the install state it changed.
|
|
185
|
+
*
|
|
186
|
+
* @param env - Ambient environment.
|
|
187
|
+
* @param paths - Resolved AgentWatch paths.
|
|
188
|
+
* @param config - The machine config.
|
|
189
|
+
*/
|
|
190
|
+
async function sweepAllExporters(env, paths, config) {
|
|
191
|
+
try {
|
|
192
|
+
// Loaded here, not at the top: the hook path loads only its own provider.
|
|
193
|
+
const { providers } = await import('../providers/registry.js');
|
|
194
|
+
const installState = await loadInstallState(paths);
|
|
195
|
+
const swept = await removeRefusedExporters({ env, paths, config, hookCommand: '', installState }, providers);
|
|
196
|
+
for (const refused of swept.refused)
|
|
197
|
+
warnLog(refused.message);
|
|
198
|
+
if (swept.installState !== installState)
|
|
199
|
+
await saveInstallState(paths, swept.installState);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
debugLog('native exporter allowlist check failed:', error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
94
205
|
/**
|
|
95
206
|
* Decode the hook payload.
|
|
96
207
|
*
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export type { Check, CheckLevel, CliContext, HookRunOptions, ParsedArgs, SetupOptions, UninstallOptions } from './types/cli.types.js';
|
|
6
6
|
export { boolFlag, parseArgs, stringFlag } from './args.js';
|
|
7
|
-
export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport } from './context.js';
|
|
7
|
+
export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, openIdentityQueue } from './context.js';
|
|
8
8
|
export { runHook } from './hook.js';
|
|
9
9
|
export { runSetup } from './setup.js';
|
|
10
10
|
export { runStatus } from './status.js';
|
|
11
11
|
export { runDoctor } from './doctor.js';
|
|
12
|
+
export { runToggle } from './toggle.js';
|
|
13
|
+
export { checkHookCommand, installedHookChecks } from './hook-check.js';
|
|
12
14
|
export { runUninstall } from './uninstall.js';
|
|
13
15
|
export { runAgents, runConfig, runOtelHeaders } from './misc.js';
|
package/dist/cli/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { boolFlag, parseArgs, stringFlag } from './args.js';
|
|
2
|
-
export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport } from './context.js';
|
|
2
|
+
export { buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, openIdentityQueue } from './context.js';
|
|
3
3
|
export { runHook } from './hook.js';
|
|
4
4
|
export { runSetup } from './setup.js';
|
|
5
5
|
export { runStatus } from './status.js';
|
|
6
6
|
export { runDoctor } from './doctor.js';
|
|
7
|
+
export { runToggle } from './toggle.js';
|
|
8
|
+
export { checkHookCommand, installedHookChecks } from './hook-check.js';
|
|
7
9
|
export { runUninstall } from './uninstall.js';
|
|
8
10
|
export { runAgents, runConfig, runOtelHeaders } from './misc.js';
|
package/dist/cli/misc.d.ts
CHANGED
|
@@ -29,3 +29,14 @@ export declare function runConfig(env: Env): Promise<number>;
|
|
|
29
29
|
* @returns Exit code 0.
|
|
30
30
|
*/
|
|
31
31
|
export declare function runOtelHeaders(env: Env): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* `agentwatch refresh-credential` — started detached by a Windows hook whose
|
|
34
|
+
* DPAPI-held device token is due. Not for people: it prints nothing.
|
|
35
|
+
*
|
|
36
|
+
* Refreshes (or exchanges) this directory's credential the way any CLI run
|
|
37
|
+
* does, PowerShell included, under the same token lock as every other refresher.
|
|
38
|
+
*
|
|
39
|
+
* @param env - Ambient environment.
|
|
40
|
+
* @returns Exit code 0, whatever happened: the next hook reads the result from the cache.
|
|
41
|
+
*/
|
|
42
|
+
export declare function runRefreshCredential(env: Env): Promise<number>;
|
package/dist/cli/misc.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
+
import { eventsUrl, otlpBaseUrl, sharesOtlpCollector } from '../config/config.js';
|
|
2
3
|
import { loadEffectiveConfig } from '../config/repo-config.js';
|
|
4
|
+
import { applyRootOverride, credentialScope } from '../config/root-config.js';
|
|
5
|
+
import { isAllowedHost } from '../config/schemas/config.schema.js';
|
|
6
|
+
import { resolveBearer } from '../credentials/credentials.js';
|
|
7
|
+
import { claudeExporterTargets, claudeOverrideTargets } from '../providers/claude/claude.otel.js';
|
|
3
8
|
import { providers } from '../providers/registry.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
9
|
+
import { INSTALLATION_HEADER } from '../transport/constants/transport.constants.js';
|
|
10
|
+
import { buildCliContext, resolveContextBearer } from './context.js';
|
|
11
|
+
import { OTEL_HEADERS_MIN_TOKEN_LIFE_MS, REDACTED_TOKEN } from './constants/cli.constants.js';
|
|
6
12
|
import { bold, dim, println, symbols } from './ui.js';
|
|
7
13
|
/**
|
|
8
14
|
* `agentwatch agents` — detection details for debugging.
|
|
@@ -37,14 +43,36 @@ export async function runAgents(env) {
|
|
|
37
43
|
export async function runConfig(env) {
|
|
38
44
|
const context = await buildCliContext(env);
|
|
39
45
|
println(dim(`# global: ${context.paths.configFile} (${context.configState})`));
|
|
46
|
+
println(`# AgentWatch ${context.disabled ? 'DISABLED' : 'enabled'}`);
|
|
40
47
|
const effective = await loadEffectiveConfig(context.paths, env.cwd);
|
|
48
|
+
if (effective.rootPath)
|
|
49
|
+
println(dim(`# project root: ${effective.rootPath}`));
|
|
41
50
|
if (effective.repoConfigFile)
|
|
42
51
|
println(dim(`# repo overrides: ${effective.repoConfigFile}`));
|
|
43
|
-
|
|
52
|
+
if (effective.rootPath && !eventsUrl(effective.config))
|
|
53
|
+
println(dim('# warning: this project root has no usable events route; events stay queued — configure its endpoint/eventsUrl or fix the refused URL'));
|
|
54
|
+
if (effective.rootPath && !otlpBaseUrl(effective.config))
|
|
55
|
+
println(dim('# warning: this project root has no usable OTLP route; the machine collector is not inherited'));
|
|
56
|
+
for (const warning of [...context.configWarnings, ...effective.warnings])
|
|
44
57
|
println(dim(`# warning: ${warning}`));
|
|
45
58
|
println(JSON.stringify({ ...effective.config, token: effective.config.token ? REDACTED_TOKEN : undefined }, null, 2));
|
|
46
59
|
return context.configState === 'invalid' ? 1 : 0;
|
|
47
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether Claude Code's exporters send to the machine's OTLP base and nowhere
|
|
63
|
+
* the allowlist would refuse.
|
|
64
|
+
*
|
|
65
|
+
* @param env - Ambient environment.
|
|
66
|
+
* @param config - The machine config.
|
|
67
|
+
* @returns True when the bearer may go to the exporter.
|
|
68
|
+
*/
|
|
69
|
+
async function exportsWhereConfigured(env, config) {
|
|
70
|
+
const targets = await claudeExporterTargets(env);
|
|
71
|
+
const trusted = new Set(config.customEndpoints);
|
|
72
|
+
if (targets.base === undefined || targets.base !== otlpBaseUrl(config))
|
|
73
|
+
return false;
|
|
74
|
+
return [targets.base, ...targets.signals, ...(await claudeOverrideTargets(env))].every((url) => isAllowedHost(url, trusted));
|
|
75
|
+
}
|
|
48
76
|
/**
|
|
49
77
|
* `agentwatch otel-headers` — Claude Code's otelHeadersHelper contract.
|
|
50
78
|
*
|
|
@@ -57,7 +85,55 @@ export async function runConfig(env) {
|
|
|
57
85
|
*/
|
|
58
86
|
export async function runOtelHeaders(env) {
|
|
59
87
|
const context = await buildCliContext(env);
|
|
60
|
-
|
|
88
|
+
// Per directory, not machine-wide: with two tenants on one machine the token
|
|
89
|
+
// that signs this export is decided by where the agent is running. Roots are
|
|
90
|
+
// all that can move identity (a repo file cannot), so the global config
|
|
91
|
+
// already in hand is enough. But the agent exports to the machine-wide
|
|
92
|
+
// collector, so a root enrolled against a different backend gets no bearer
|
|
93
|
+
// at all rather than presenting its credential to the other tenant's collector.
|
|
94
|
+
//
|
|
95
|
+
// And only when the exporter sends where the config says, to a host the edge
|
|
96
|
+
// itself would send to: the endpoint lives in Claude's settings file, which
|
|
97
|
+
// is not ours and can be edited to point anywhere.
|
|
98
|
+
const { config: rooted, root } = applyRootOverride(context.config, env.cwd);
|
|
99
|
+
// The current access token, refreshed here whenever it would not outlast
|
|
100
|
+
// Claude Code's debounce on this helper: what it prints is reused until then.
|
|
101
|
+
// An install key still in the config is exchanged first.
|
|
102
|
+
const shared = !context.disabled && sharesOtlpCollector(context.config, rooted) && (await exportsWhereConfigured(env, context.config));
|
|
103
|
+
const token = shared ? await resolveBearer({ env, paths: context.paths, timeoutMs: rooted.delivery.timeoutMs, scope: credentialScope(root), minRemainingMs: OTEL_HEADERS_MIN_TOKEN_LIFE_MS }, rooted) : undefined;
|
|
104
|
+
// The installation id rides with the bearer and on the same condition: an
|
|
105
|
+
// export that carries no credential names no machine either. It is what lets
|
|
106
|
+
// measured per-call usage be traced back to a sender at all — the exporter is
|
|
107
|
+
// the agent's own, so this header is the only thing on that route we set.
|
|
108
|
+
//
|
|
109
|
+
// Not `edgeHeaders()`, though the header list belongs there: that builder also
|
|
110
|
+
// sets User-Agent, and what it would override here is the exporting agent's
|
|
111
|
+
// own, not ours to replace.
|
|
112
|
+
const headers = token
|
|
113
|
+
? {
|
|
114
|
+
// Spelled out, not `AUTHORIZATION_HEADER`: that constant is lower
|
|
115
|
+
// case for the transport's own requests, and this map is handed to
|
|
116
|
+
// Claude Code rather than to fetch. Its output is what the exporter
|
|
117
|
+
// sends, so the spelling stays the one that has always gone out.
|
|
118
|
+
Authorization: `Bearer ${token}`,
|
|
119
|
+
...(rooted.installationId ? { [INSTALLATION_HEADER]: rooted.installationId } : {})
|
|
120
|
+
}
|
|
121
|
+
: {};
|
|
61
122
|
process.stdout.write(JSON.stringify(headers));
|
|
62
123
|
return 0;
|
|
63
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* `agentwatch refresh-credential` — started detached by a Windows hook whose
|
|
127
|
+
* DPAPI-held device token is due. Not for people: it prints nothing.
|
|
128
|
+
*
|
|
129
|
+
* Refreshes (or exchanges) this directory's credential the way any CLI run
|
|
130
|
+
* does, PowerShell included, under the same token lock as every other refresher.
|
|
131
|
+
*
|
|
132
|
+
* @param env - Ambient environment.
|
|
133
|
+
* @returns Exit code 0, whatever happened: the next hook reads the result from the cache.
|
|
134
|
+
*/
|
|
135
|
+
export async function runRefreshCredential(env) {
|
|
136
|
+
const context = await buildCliContext(env);
|
|
137
|
+
await resolveContextBearer(context, context.identityConfig.delivery.timeoutMs);
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this process runs from npx's download cache, and has not already
|
|
3
|
+
* been handed off once.
|
|
4
|
+
*
|
|
5
|
+
* That cache is temporary: npm may clear it at any time, so hooks registered
|
|
6
|
+
* against it would point at a file that later disappears. The handoff marker
|
|
7
|
+
* stops a global install that happens to live under an `_npx` directory from
|
|
8
|
+
* handing off to itself forever.
|
|
9
|
+
*
|
|
10
|
+
* @param scriptPath - The running script, `process.argv[1]`.
|
|
11
|
+
* @param vars - The environment.
|
|
12
|
+
* @returns True when the script lives under an `_npx` directory.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isNpxRun(scriptPath: string | undefined, vars: NodeJS.ProcessEnv): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* PATH for the handed-off setup: the global install's bin first, npx's cache
|
|
17
|
+
* directories gone.
|
|
18
|
+
*
|
|
19
|
+
* First, because setup registers whichever `agentwatch` PATH resolves to, and
|
|
20
|
+
* an older global or a project's `node_modules/.bin` must not win over the copy
|
|
21
|
+
* just installed.
|
|
22
|
+
*
|
|
23
|
+
* @param pathVar - The PATH value.
|
|
24
|
+
* @param globalBin - Directory holding the global `agentwatch`.
|
|
25
|
+
* @returns The PATH to hand off with.
|
|
26
|
+
*/
|
|
27
|
+
export declare function handoffPath(pathVar: string, globalBin: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Install this exact version globally, then run setup again from there.
|
|
30
|
+
*
|
|
31
|
+
* Lets the whole install be `npx -y @agent-watch-ai/edge setup --token …`:
|
|
32
|
+
* one line, and the hooks it registers point at the permanent install.
|
|
33
|
+
*
|
|
34
|
+
* @param setupArgs - Arguments after `agentwatch`, starting with `setup`.
|
|
35
|
+
* @returns The handed-off setup's exit code.
|
|
36
|
+
*/
|
|
37
|
+
export declare function installGloballyAndHandOff(setupArgs: readonly string[]): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { NPX_CACHE_SEGMENT, NPX_HANDOFF_VAR } from './constants/cli.constants.js';
|
|
5
|
+
import { printErrln, symbols } from './ui.js';
|
|
6
|
+
/**
|
|
7
|
+
* Whether this process runs from npx's download cache, and has not already
|
|
8
|
+
* been handed off once.
|
|
9
|
+
*
|
|
10
|
+
* That cache is temporary: npm may clear it at any time, so hooks registered
|
|
11
|
+
* against it would point at a file that later disappears. The handoff marker
|
|
12
|
+
* stops a global install that happens to live under an `_npx` directory from
|
|
13
|
+
* handing off to itself forever.
|
|
14
|
+
*
|
|
15
|
+
* @param scriptPath - The running script, `process.argv[1]`.
|
|
16
|
+
* @param vars - The environment.
|
|
17
|
+
* @returns True when the script lives under an `_npx` directory.
|
|
18
|
+
*/
|
|
19
|
+
export function isNpxRun(scriptPath, vars) {
|
|
20
|
+
if (vars[NPX_HANDOFF_VAR])
|
|
21
|
+
return false;
|
|
22
|
+
return scriptPath !== undefined && scriptPath.split(path.sep).includes(NPX_CACHE_SEGMENT);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* PATH for the handed-off setup: the global install's bin first, npx's cache
|
|
26
|
+
* directories gone.
|
|
27
|
+
*
|
|
28
|
+
* First, because setup registers whichever `agentwatch` PATH resolves to, and
|
|
29
|
+
* an older global or a project's `node_modules/.bin` must not win over the copy
|
|
30
|
+
* just installed.
|
|
31
|
+
*
|
|
32
|
+
* @param pathVar - The PATH value.
|
|
33
|
+
* @param globalBin - Directory holding the global `agentwatch`.
|
|
34
|
+
* @returns The PATH to hand off with.
|
|
35
|
+
*/
|
|
36
|
+
export function handoffPath(pathVar, globalBin) {
|
|
37
|
+
const kept = pathVar.split(path.delimiter).filter((dir) => dir && dir !== globalBin && !dir.split(path.sep).includes(NPX_CACHE_SEGMENT));
|
|
38
|
+
return [globalBin, ...kept].join(path.delimiter);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Install this exact version globally, then run setup again from there.
|
|
42
|
+
*
|
|
43
|
+
* Lets the whole install be `npx -y @agent-watch-ai/edge setup --token …`:
|
|
44
|
+
* one line, and the hooks it registers point at the permanent install.
|
|
45
|
+
*
|
|
46
|
+
* @param setupArgs - Arguments after `agentwatch`, starting with `setup`.
|
|
47
|
+
* @returns The handed-off setup's exit code.
|
|
48
|
+
*/
|
|
49
|
+
export function installGloballyAndHandOff(setupArgs) {
|
|
50
|
+
const pkg = createRequire(import.meta.url)('../../package.json');
|
|
51
|
+
const spec = `${pkg.name}@${pkg.version}`;
|
|
52
|
+
// Not the arguments: they carry the token.
|
|
53
|
+
const manual = `run \`npm install -g ${spec}\` yourself, then your setup command again with \`agentwatch\` in place of \`npx -y ${pkg.name}\``;
|
|
54
|
+
// npm is `npm.cmd` on Windows, which only a shell resolves.
|
|
55
|
+
const shell = process.platform === 'win32';
|
|
56
|
+
const install = spawnSync('npm', ['install', '-g', spec], { stdio: 'inherit', shell });
|
|
57
|
+
if (install.status !== 0) {
|
|
58
|
+
printErrln(`${symbols.fail} could not install ${spec} globally; ${manual}`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const prefix = spawnSync('npm', ['prefix', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
|
|
62
|
+
const root = spawnSync('npm', ['root', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
|
|
63
|
+
if (!prefix || !root || !path.isAbsolute(prefix) || !path.isAbsolute(root)) {
|
|
64
|
+
printErrln(`${symbols.fail} could not find npm's global folder; ${manual}`);
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
// Windows puts the global shims in the prefix itself; everything else in prefix/bin.
|
|
68
|
+
const globalBin = shell ? prefix : path.join(prefix, 'bin');
|
|
69
|
+
const env = { ...process.env, PATH: handoffPath(process.env['PATH'] ?? '', globalBin), [NPX_HANDOFF_VAR]: '1' };
|
|
70
|
+
// The installed entry point under node, never a shim through a shell: the
|
|
71
|
+
// arguments carry the token, and cmd.exe would interpret them.
|
|
72
|
+
const cli = path.join(root, pkg.name, 'dist', 'cli.js');
|
|
73
|
+
const setup = spawnSync(process.execPath, [cli, ...setupArgs], { stdio: 'inherit', env });
|
|
74
|
+
if (setup.error || setup.status === null) {
|
|
75
|
+
printErrln(`${symbols.fail} installed ${spec} but could not start it; ${manual}`);
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
return setup.status;
|
|
79
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SetupOptions } from './types/cli.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether setup should open the sign-in link itself. Only for a developer at
|
|
4
|
+
* an interactive terminal on this machine: under CI, or over SSH (where the
|
|
5
|
+
* browser would open on the far side, if anywhere), the printed link is the way.
|
|
6
|
+
*
|
|
7
|
+
* @param vars - The process environment.
|
|
8
|
+
* @param isTTY - Whether stdout is a terminal.
|
|
9
|
+
* @returns True when a browser may be opened.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canOpenBrowser(vars: Record<string, string | undefined>, isTTY: boolean): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* How setup opens the sign-in link: the test seam, the real browser, or not at all.
|
|
14
|
+
*
|
|
15
|
+
* @param options - `--no-browser`, the test seam and the environment.
|
|
16
|
+
* @param options.noBrowser - `--no-browser`.
|
|
17
|
+
* @param options.openUrl - The test seam.
|
|
18
|
+
* @param options.env - Where the vars and platform come from.
|
|
19
|
+
* @param isTTY - Whether stdout is a terminal.
|
|
20
|
+
* @returns The opener, or undefined to only print the link.
|
|
21
|
+
*/
|
|
22
|
+
export declare function signInOpener(options: Pick<SetupOptions, 'noBrowser' | 'openUrl' | 'env'>, isTTY: boolean): ((url: string) => void) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a link may be handed to a browser opener: http(s) only, since the
|
|
25
|
+
* gateway chose it and a `file:` or custom-scheme link would run something local.
|
|
26
|
+
*
|
|
27
|
+
* @param url - The link from the gateway.
|
|
28
|
+
* @returns True for a parseable http(s) link.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isOpenableUrl(url: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Open a link in the default browser, fire-and-forget. Any failure is ignored:
|
|
33
|
+
* the link is printed beside it. No shell is involved, and only an http(s)
|
|
34
|
+
* link is opened, since the gateway chose it.
|
|
35
|
+
*
|
|
36
|
+
* @param url - The link to open.
|
|
37
|
+
* @param platform - Which opener to use.
|
|
38
|
+
*/
|
|
39
|
+
export declare function openBrowser(url: string, platform: NodeJS.Platform): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { BROWSER_OPENERS, DEFAULT_BROWSER_OPENER, OPENABLE_PROTOCOLS } from './constants/cli.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether setup should open the sign-in link itself. Only for a developer at
|
|
5
|
+
* an interactive terminal on this machine: under CI, or over SSH (where the
|
|
6
|
+
* browser would open on the far side, if anywhere), the printed link is the way.
|
|
7
|
+
*
|
|
8
|
+
* @param vars - The process environment.
|
|
9
|
+
* @param isTTY - Whether stdout is a terminal.
|
|
10
|
+
* @returns True when a browser may be opened.
|
|
11
|
+
*/
|
|
12
|
+
export function canOpenBrowser(vars, isTTY) {
|
|
13
|
+
return isTTY && !vars['CI'] && !vars['SSH_CONNECTION'] && !vars['SSH_TTY'];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* How setup opens the sign-in link: the test seam, the real browser, or not at all.
|
|
17
|
+
*
|
|
18
|
+
* @param options - `--no-browser`, the test seam and the environment.
|
|
19
|
+
* @param options.noBrowser - `--no-browser`.
|
|
20
|
+
* @param options.openUrl - The test seam.
|
|
21
|
+
* @param options.env - Where the vars and platform come from.
|
|
22
|
+
* @param isTTY - Whether stdout is a terminal.
|
|
23
|
+
* @returns The opener, or undefined to only print the link.
|
|
24
|
+
*/
|
|
25
|
+
export function signInOpener(options, isTTY) {
|
|
26
|
+
if (options.noBrowser)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (options.openUrl)
|
|
29
|
+
return options.openUrl;
|
|
30
|
+
return canOpenBrowser(options.env.vars, isTTY) ? (url) => openBrowser(url, options.env.platform) : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether a link may be handed to a browser opener: http(s) only, since the
|
|
34
|
+
* gateway chose it and a `file:` or custom-scheme link would run something local.
|
|
35
|
+
*
|
|
36
|
+
* @param url - The link from the gateway.
|
|
37
|
+
* @returns True for a parseable http(s) link.
|
|
38
|
+
*/
|
|
39
|
+
export function isOpenableUrl(url) {
|
|
40
|
+
return URL.canParse(url) && OPENABLE_PROTOCOLS.has(new URL(url).protocol);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Open a link in the default browser, fire-and-forget. Any failure is ignored:
|
|
44
|
+
* the link is printed beside it. No shell is involved, and only an http(s)
|
|
45
|
+
* link is opened, since the gateway chose it.
|
|
46
|
+
*
|
|
47
|
+
* @param url - The link to open.
|
|
48
|
+
* @param platform - Which opener to use.
|
|
49
|
+
*/
|
|
50
|
+
export function openBrowser(url, platform) {
|
|
51
|
+
if (!isOpenableUrl(url))
|
|
52
|
+
return;
|
|
53
|
+
const [file, ...args] = [...(BROWSER_OPENERS[platform] ?? DEFAULT_BROWSER_OPENER), url];
|
|
54
|
+
try {
|
|
55
|
+
const child = spawn(file, args, { detached: true, stdio: 'ignore' });
|
|
56
|
+
child.on('error', () => undefined);
|
|
57
|
+
child.unref();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// The printed link still works.
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/cli/setup.d.ts
CHANGED
|
@@ -6,13 +6,26 @@ export type { SetupOptions } from './types/cli.types.js';
|
|
|
6
6
|
* telemetry in every detected agent.
|
|
7
7
|
*
|
|
8
8
|
* Ordered so nothing is written until everything that can be validated has
|
|
9
|
-
* been: a `--otel` typo, an unparseable existing config
|
|
10
|
-
* fails the run before the first file is touched.
|
|
9
|
+
* been: a `--otel` typo, an unparseable existing config, a refused endpoint or
|
|
10
|
+
* a missing token fails the run before the first file is touched. No endpoint
|
|
11
|
+
* at all means the production Agent Watch backend.
|
|
11
12
|
*
|
|
12
|
-
* @param options - Environment
|
|
13
|
+
* @param options - Environment and flags.
|
|
13
14
|
* @returns 0 when every step succeeded, else 1.
|
|
14
15
|
*/
|
|
15
16
|
export declare function runSetup(options: SetupOptions): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* What to call this developer: the flag, then the config, then `git config
|
|
19
|
+
* user.name`.
|
|
20
|
+
*
|
|
21
|
+
* An install whose developer cannot be named is still a working install — the
|
|
22
|
+
* platform falls back to the address.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Setup options, including the flag and injected git runner.
|
|
25
|
+
* @param baseConfig - Config the run starts from.
|
|
26
|
+
* @returns The name, or undefined when nothing knows one.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveDeveloperName(options: SetupOptions, baseConfig: AgentWatchConfig): Promise<string | undefined>;
|
|
16
29
|
/**
|
|
17
30
|
* The developer identity this install will be attributed to.
|
|
18
31
|
*
|
|
@@ -21,12 +34,8 @@ export declare function runSetup(options: SetupOptions): Promise<number>;
|
|
|
21
34
|
* the gate will later ask the platform about. The flag is the only override,
|
|
22
35
|
* for a machine whose git identity is someone else's.
|
|
23
36
|
*
|
|
24
|
-
* Nothing is asked when the identity is already known: the prompt exists for
|
|
25
|
-
* the machine that has no answer, not to re-confirm one we already trust.
|
|
26
|
-
*
|
|
27
37
|
* @param options - Flags, environment and the git runner override.
|
|
28
38
|
* @param baseConfig - Config the run starts from.
|
|
29
|
-
* @param ask - The prompt, when the run is interactive.
|
|
30
39
|
* @returns The identity, or undefined when nothing names the developer.
|
|
31
40
|
*/
|
|
32
|
-
export declare function resolveDeveloperEmail(options: SetupOptions, baseConfig: AgentWatchConfig
|
|
41
|
+
export declare function resolveDeveloperEmail(options: SetupOptions, baseConfig: AgentWatchConfig): Promise<string | undefined>;
|