@agent-watch-ai/edge 0.2.5 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +512 -0
- package/README.md +217 -96
- package/SECURITY.md +69 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +50 -4
- package/dist/cli/constants/cli.constants.js +54 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +309 -32
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +439 -98
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +113 -0
- package/dist/cli/types/cli.types.d.ts +37 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +100 -13
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +113 -6
- package/dist/config/constants/config.constants.js +126 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +721 -84
- package/dist/config/schemas/config.schema.js +388 -15
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +111 -0
- package/dist/credentials/constants/credentials.constants.js +112 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +34 -0
- package/dist/credentials/credentials.d.ts +72 -0
- package/dist/credentials/credentials.js +253 -0
- package/dist/credentials/device-api.d.ts +64 -0
- package/dist/credentials/device-api.js +150 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +62 -0
- package/dist/credentials/identity.js +90 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +18 -0
- package/dist/credentials/sign-in.js +86 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +195 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +62 -16
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +103 -15
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +64 -0
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
- package/dist/pipeline/constants/pipeline.constants.js +7 -0
- package/dist/pipeline/hook-pipeline.js +360 -32
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +73 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +24 -2
- package/dist/providers/codex/codex.otel.js +147 -30
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/constants/provider.constants.d.ts +0 -3
- package/dist/providers/constants/provider.constants.js +0 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
- package/dist/providers/cursor/constants/cursor.constants.js +7 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +52 -3
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +19 -20
- package/dist/providers/gemini/gemini.otel.js +121 -17
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
- package/dist/providers/shared/constants/tooling.constants.js +19 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +12 -1
- package/dist/providers/shared/tooling.js +18 -0
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +57 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +7 -0
- package/dist/storage/atomic-file.js +1 -1
- package/dist/storage/constants/storage.constants.d.ts +17 -0
- package/dist/storage/constants/storage.constants.js +17 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +65 -0
- package/dist/turns/work-checkout.js +666 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +648 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
package/dist/cli/status.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { eventsUrl } from '../config/config.js';
|
|
2
|
+
import { describeCredential } from '../credentials/credential-status.js';
|
|
2
3
|
import { collectGitContext } from '../git/git-context.js';
|
|
3
4
|
import { providers } from '../providers/registry.js';
|
|
4
|
-
import {
|
|
5
|
+
import { AUTH_BLOCK_REPROBE_MS } from '../transport/constants/transport.constants.js';
|
|
6
|
+
import { unattributedCount, unattributedQueue } from '../transport/queue-partition.js';
|
|
7
|
+
import { buildAuthBlock, buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, resolveContextBearer } from './context.js';
|
|
5
8
|
import { STATUS_SEND_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
6
|
-
import { bold, dim, println, symbols } from './ui.js';
|
|
9
|
+
import { bold, customEndpointOverride, dim, println, symbols } from './ui.js';
|
|
7
10
|
/**
|
|
8
11
|
* `agentwatch status` — is telemetry actually flowing, and if not, why.
|
|
9
12
|
*
|
|
@@ -16,8 +19,12 @@ import { bold, dim, println, symbols } from './ui.js';
|
|
|
16
19
|
export async function runStatus(env) {
|
|
17
20
|
const context = await buildCliContext(env);
|
|
18
21
|
println(bold('AgentWatch Edge'));
|
|
22
|
+
println(context.disabled ? 'DISABLED — restart running agents to stop native exporters.' : 'enabled');
|
|
23
|
+
println(`Content capture consent: ${context.config.contentCaptureConsent ? 'granted (global)' : 'absent — metadata only'}`);
|
|
24
|
+
println(`Effective global capture: ${JSON.stringify(context.config.capture)}`);
|
|
25
|
+
println('Native provider exporters may require broader consent than hook summaries; see doctor and docs/DATA_HANDLING.md.');
|
|
19
26
|
println();
|
|
20
|
-
reportBackend(context);
|
|
27
|
+
await reportBackend(context);
|
|
21
28
|
println();
|
|
22
29
|
reportRepository(await collectGitContext({ cwd: env.cwd, includeChangedFiles: false }));
|
|
23
30
|
println();
|
|
@@ -34,14 +41,29 @@ export async function runStatus(env) {
|
|
|
34
41
|
*
|
|
35
42
|
* @param context - Resolved CLI context.
|
|
36
43
|
*/
|
|
37
|
-
function reportBackend(context) {
|
|
44
|
+
async function reportBackend(context) {
|
|
38
45
|
println(bold('Backend'));
|
|
39
46
|
if (context.configState === 'invalid') {
|
|
40
47
|
println(`${symbols.fail} config invalid: ${context.configError}`);
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
// Named before the endpoint, because this is why an endpoint someone wrote
|
|
51
|
+
// into the file is not the one printed below.
|
|
52
|
+
for (const warning of context.configWarnings)
|
|
53
|
+
println(`${symbols.fail} config ${warning}`);
|
|
54
|
+
// Whatever the endpoint below: the trust is machine-wide, and an auditor
|
|
55
|
+
// reading this output is owed it on every run (SPEC R9).
|
|
56
|
+
if (context.config.customEndpoints.length > 0)
|
|
57
|
+
println(`${symbols.warn} ${customEndpointOverride(context.config.customEndpoints)}`);
|
|
58
|
+
if (context.identityConfig.endpoint) {
|
|
59
|
+
println(`${symbols.ok} ${context.identityConfig.endpoint}`);
|
|
60
|
+
// The identity is per directory, so the report has to say when this one is
|
|
61
|
+
// not the machine's: everything below — the backlog, the losses, the
|
|
62
|
+
// credential block — belongs to the root's partition, not the global one.
|
|
63
|
+
if (context.identityRoot !== undefined)
|
|
64
|
+
println(dim(` identity from root ${context.identityRoot}`));
|
|
65
|
+
const credential = await describeCredential(context.paths, context.identityConfig, context.credentialScope);
|
|
66
|
+
println(`${symbols[credential.level]} credential: ${credential.detail}`);
|
|
45
67
|
reportEnforcement(context);
|
|
46
68
|
return;
|
|
47
69
|
}
|
|
@@ -94,7 +116,7 @@ async function reportAgent(provider, context) {
|
|
|
94
116
|
}
|
|
95
117
|
println(`${symbols.ok} detected ${dim(`(${detection.evidence[0] ?? ''})`)}`);
|
|
96
118
|
println(detection.hooksInstalled ? `${symbols.ok} hooks installed` : `${symbols.off} hooks not installed`);
|
|
97
|
-
if (!provider.nativeTelemetry)
|
|
119
|
+
if (!provider.nativeTelemetry || context.disabled)
|
|
98
120
|
return;
|
|
99
121
|
const setupContext = {
|
|
100
122
|
env: context.env,
|
|
@@ -120,29 +142,76 @@ async function reportAgent(provider, context) {
|
|
|
120
142
|
*/
|
|
121
143
|
async function reportDelivery(context) {
|
|
122
144
|
println(bold('Delivery'));
|
|
123
|
-
const queue = buildQueue(context);
|
|
145
|
+
const queue = await buildQueue(context);
|
|
124
146
|
const deliveryStats = buildDeliveryStats(context);
|
|
125
|
-
const
|
|
147
|
+
const authBlock = buildAuthBlock(context);
|
|
148
|
+
const pending = await retryBacklog(context, queue, deliveryStats, authBlock);
|
|
126
149
|
println(pending === 0 ? `${symbols.ok} healthy` : `${symbols.warn} backlog`);
|
|
127
150
|
println(`${pending} pending event(s)`);
|
|
151
|
+
await reportAuthBlock(context, authBlock, pending);
|
|
152
|
+
await reportUnattributed(context);
|
|
128
153
|
reportLosses(context, await deliveryStats.read());
|
|
129
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* The credential the backend is refusing, and what is waiting behind it.
|
|
157
|
+
*
|
|
158
|
+
* Without this line a rejected token looks exactly like a backend outage: a
|
|
159
|
+
* backlog that grows and then empties itself when the entries age out. The
|
|
160
|
+
* remedy is a new credential unless the backend starts accepting the old one —
|
|
161
|
+
* the block is lifted by a changed fingerprint, or by any 2xx or `doctor`
|
|
162
|
+
* proving the credential good; hooks ask again after the re-probe interval.
|
|
163
|
+
*
|
|
164
|
+
* @param context - Resolved CLI context.
|
|
165
|
+
* @param authBlock - The persisted block.
|
|
166
|
+
* @param pending - Entries in this identity's backlog.
|
|
167
|
+
*/
|
|
168
|
+
async function reportAuthBlock(context, authBlock, pending) {
|
|
169
|
+
const url = eventsUrl(context.identityConfig);
|
|
170
|
+
if (!url)
|
|
171
|
+
return;
|
|
172
|
+
const block = await authBlock.active(url);
|
|
173
|
+
if (!block)
|
|
174
|
+
return;
|
|
175
|
+
println(`${symbols.warn} backend refused this machine's credential with HTTP ${block.status}, first at ${block.since}`);
|
|
176
|
+
println(dim(` ${pending} event(s) are held for it; hooks ask the backend again every ${AUTH_BLOCK_REPROBE_MS / 60_000} minutes, and resume on the first acceptance`));
|
|
177
|
+
println(dim(' if the token was revoked, configure a new one with `agentwatch setup`, then run `agentwatch doctor` to confirm and resume'));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The backlog nobody can claim, and how to claim it.
|
|
181
|
+
*
|
|
182
|
+
* Reported rather than delivered: these entries predate per-identity queues and
|
|
183
|
+
* name no tenant, so on a machine serving several the bridge refuses to pick one
|
|
184
|
+
* for them. Saying where they are is the whole remedy — the operator knows which
|
|
185
|
+
* tenant was running, and a move is all it takes.
|
|
186
|
+
*
|
|
187
|
+
* @param context - Resolved CLI context.
|
|
188
|
+
*/
|
|
189
|
+
async function reportUnattributed(context) {
|
|
190
|
+
const unattributed = await unattributedCount(context.paths.queueDir);
|
|
191
|
+
if (unattributed === 0)
|
|
192
|
+
return;
|
|
193
|
+
println(`${symbols.warn} ${unattributed} event(s) queued before this machine served more than one tenant`);
|
|
194
|
+
println(dim(` they name no tenant, so nothing delivers them: ${unattributedQueue(context.paths.queueDir)}`));
|
|
195
|
+
println(dim(' move them into the right tenant\'s partition to deliver, or delete the directory to discard'));
|
|
196
|
+
}
|
|
130
197
|
/**
|
|
131
198
|
* Drain what can be drained, and report the backlog that remains.
|
|
132
199
|
*
|
|
133
200
|
* @param context - Resolved CLI context.
|
|
134
201
|
* @param queue - The offline queue.
|
|
135
202
|
* @param deliveryStats - Sink for anything the drain loses.
|
|
203
|
+
* @param authBlock - Sink for a refused credential, so this retry cannot spend
|
|
204
|
+
* the backlog's attempts on a token the backend has already rejected.
|
|
136
205
|
* @returns The remaining entry count.
|
|
137
206
|
*/
|
|
138
|
-
async function retryBacklog(context, queue, deliveryStats) {
|
|
207
|
+
async function retryBacklog(context, queue, deliveryStats, authBlock) {
|
|
139
208
|
const pending = await queue.pendingCount();
|
|
140
|
-
if (pending === 0 || !eventsUrl(context.
|
|
209
|
+
if (pending === 0 || !eventsUrl(context.identityConfig))
|
|
141
210
|
return pending;
|
|
142
|
-
const transport = buildTransport(context, STATUS_SEND_TIMEOUT_MS);
|
|
211
|
+
const transport = buildTransport(context, STATUS_SEND_TIMEOUT_MS, await resolveContextBearer(context, STATUS_SEND_TIMEOUT_MS));
|
|
143
212
|
if (!transport)
|
|
144
213
|
return pending;
|
|
145
|
-
const drained = await queue.drain(transport, context.
|
|
214
|
+
const drained = await queue.drain(transport, context.identityConfig.delivery.drainBatchSize, deliveryStats, authBlock);
|
|
146
215
|
if (drained.sent > 0)
|
|
147
216
|
println(dim(` retried: ${drained.sent} event(s) delivered`));
|
|
148
217
|
return queue.pendingCount();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Env } from '../core/types/core.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Stop hooks first, then remove or restore only managed native exporters.
|
|
4
|
+
* The marker survives partial failures so a retry cannot silently resume hooks.
|
|
5
|
+
* @param env - User environment.
|
|
6
|
+
* @param enabled - Whether operation should resume.
|
|
7
|
+
* @returns Nonzero when manual repair or a retry is required.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runToggle(env: Env, enabled: boolean): Promise<number>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { providers } from '../providers/registry.js';
|
|
4
|
+
import { writeFileAtomic } from '../storage/atomic-file.js';
|
|
5
|
+
import { SECRET_FILE_MODE } from '../storage/constants/storage.constants.js';
|
|
6
|
+
import { disabledFile, isDisabled } from '../storage/disabled.js';
|
|
7
|
+
import { saveInstallState } from '../storage/install-state.js';
|
|
8
|
+
import { readJsonFile } from '../storage/json-file.js';
|
|
9
|
+
import { buildCliContext, buildHookCommand } from './context.js';
|
|
10
|
+
import { println } from './ui.js';
|
|
11
|
+
const suspendedSchema = z.object({ providers: z.array(z.string()) });
|
|
12
|
+
/**
|
|
13
|
+
* Stop hooks first, then remove or restore only managed native exporters.
|
|
14
|
+
* The marker survives partial failures so a retry cannot silently resume hooks.
|
|
15
|
+
* @param env - User environment.
|
|
16
|
+
* @param enabled - Whether operation should resume.
|
|
17
|
+
* @returns Nonzero when manual repair or a retry is required.
|
|
18
|
+
*/
|
|
19
|
+
export async function runToggle(env, enabled) {
|
|
20
|
+
const context = await buildCliContext(env);
|
|
21
|
+
const file = disabledFile(context.paths);
|
|
22
|
+
const disabled = await isDisabled(context.paths);
|
|
23
|
+
if (enabled && !disabled) {
|
|
24
|
+
println('AgentWatch is already enabled.');
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
// No early return: `off` is the retry the failure path asks for, and the
|
|
28
|
+
// marker is already written by then. The uninstall loop below is idempotent,
|
|
29
|
+
// so re-running it is how leftover exporters finally come out.
|
|
30
|
+
if (!enabled && disabled)
|
|
31
|
+
println('AgentWatch is already disabled; re-checking native exporters. Restart running coding agents if they were not restarted after the first call.');
|
|
32
|
+
if (enabled && context.configState !== 'ok') {
|
|
33
|
+
// A machine stopped before it was ever enrolled has nothing to restore, and
|
|
34
|
+
// `setup` refuses while the marker is there — so refusing here too is a
|
|
35
|
+
// deadlock with no exit. Clearing the marker costs nothing: with no config
|
|
36
|
+
// there is no endpoint, no token and no exporter that was ever written.
|
|
37
|
+
if (context.configState === 'missing') {
|
|
38
|
+
await fs.rm(file, { force: true });
|
|
39
|
+
println('AgentWatch enabled. No configuration found — run agentwatch setup to enroll.');
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
println(`AgentWatch remains disabled. Repair ${context.paths.configFile} before running agentwatch on, or delete ${file} to clear the off switch by hand.`);
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
const read = await readJsonFile(file);
|
|
46
|
+
const saved = read.state === 'ok' ? suspendedSchema.safeParse(read.value) : undefined;
|
|
47
|
+
const everyExporter = providers.filter((provider) => provider.nativeTelemetry).map((provider) => provider.id);
|
|
48
|
+
// `off` never narrows its work from a record it might not have. Install state
|
|
49
|
+
// degrades to `{agents:{}}` on a missing or corrupt file, and a marker can be
|
|
50
|
+
// empty or hand-edited — either would have made this a no-op that reports
|
|
51
|
+
// success while the Codex and Gemini exporters keep shipping with their bearer
|
|
52
|
+
// token. Uninstall is ownership-scoped and idempotent, so asking a provider
|
|
53
|
+
// that has nothing of ours costs one read and says so.
|
|
54
|
+
//
|
|
55
|
+
// `on` prefers the recorded list, so a provider the machine never had is not
|
|
56
|
+
// configured by a restore; anything unreadable falls back to the same full
|
|
57
|
+
// set, where the hooks-installed check below is the guard.
|
|
58
|
+
const targets = enabled && saved?.success ? saved.data.providers : everyExporter;
|
|
59
|
+
if (!enabled && !saved?.success && read.state === 'ok') {
|
|
60
|
+
println('disabled.json could not be read; re-checking every managed exporter rather than trusting it.');
|
|
61
|
+
}
|
|
62
|
+
if (!enabled)
|
|
63
|
+
await writeFileAtomic(file, JSON.stringify({ providers: targets }), SECRET_FILE_MODE);
|
|
64
|
+
let installState = context.installState;
|
|
65
|
+
let failures = 0;
|
|
66
|
+
const restored = [];
|
|
67
|
+
for (const provider of providers) {
|
|
68
|
+
if (!targets.includes(provider.id) || !provider.nativeTelemetry)
|
|
69
|
+
continue;
|
|
70
|
+
// An uninstall performed while stopped must not be undone by `on`.
|
|
71
|
+
if (enabled && !(await provider.detect(env)).hooksInstalled)
|
|
72
|
+
continue;
|
|
73
|
+
const setupContext = { ...context, installState, hookCommand: buildHookCommand(env, provider.id) };
|
|
74
|
+
try {
|
|
75
|
+
const outcome = enabled
|
|
76
|
+
? await provider.nativeTelemetry.configure(setupContext)
|
|
77
|
+
: await provider.nativeTelemetry.uninstall(setupContext);
|
|
78
|
+
installState = outcome.installState ?? installState;
|
|
79
|
+
await saveInstallState(context.paths, installState);
|
|
80
|
+
if (enabled && outcome.ok)
|
|
81
|
+
restored.push(provider);
|
|
82
|
+
for (const message of outcome.messages)
|
|
83
|
+
println(`${provider.displayName}: ${message}`);
|
|
84
|
+
if (!outcome.ok)
|
|
85
|
+
failures++;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
failures++;
|
|
89
|
+
println(`${provider.displayName}: telemetry configuration could not be updated; repair permissions/configuration and retry.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (enabled && failures > 0) {
|
|
93
|
+
for (const provider of restored) {
|
|
94
|
+
if (!provider.nativeTelemetry)
|
|
95
|
+
continue;
|
|
96
|
+
try {
|
|
97
|
+
const outcome = await provider.nativeTelemetry.uninstall({ ...context, installState, hookCommand: buildHookCommand(env, provider.id) });
|
|
98
|
+
installState = outcome.installState ?? installState;
|
|
99
|
+
await saveInstallState(context.paths, installState);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
println(`${provider.displayName}: failed to roll back restored telemetry; close agents and run agentwatch off again.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (enabled && failures === 0)
|
|
107
|
+
await fs.rm(file);
|
|
108
|
+
println(enabled && failures === 0 ? 'AgentWatch enabled.' : 'AgentWatch disabled for hooks and otel-headers.');
|
|
109
|
+
println('Restart all running coding agents to apply native telemetry changes; existing processes may retain exporters and credentials.');
|
|
110
|
+
if (failures > 0)
|
|
111
|
+
println('Native telemetry changes are incomplete. Close running agents and retry this command after repair.');
|
|
112
|
+
return failures === 0 ? 0 : 1;
|
|
113
|
+
}
|
|
@@ -10,11 +10,34 @@ export interface ParsedArgs {
|
|
|
10
10
|
}
|
|
11
11
|
/** Everything a command needs, resolved once at its start. */
|
|
12
12
|
export interface CliContext {
|
|
13
|
+
readonly disabled: boolean;
|
|
13
14
|
readonly env: Env;
|
|
14
15
|
readonly paths: AgentWatchPaths;
|
|
16
|
+
/**
|
|
17
|
+
* The machine's global config, `roots` included. What `setup`, `uninstall`
|
|
18
|
+
* and `toggle` read and write: the file on disk is machine-wide.
|
|
19
|
+
*/
|
|
15
20
|
readonly config: AgentWatchConfig;
|
|
21
|
+
/**
|
|
22
|
+
* The same config with the matching `roots[]` entry applied for `env.cwd` —
|
|
23
|
+
* the identity the hooks in this directory actually send as.
|
|
24
|
+
*
|
|
25
|
+
* Everything partitioned by identity is built from this and never from
|
|
26
|
+
* `config`: the queue, the loss tally, the credential block and the
|
|
27
|
+
* transport. The hook path resolves its identity through `applyRootOverride`,
|
|
28
|
+
* so a command reading the global token would look at another partition's
|
|
29
|
+
* files — reporting an empty backlog for a root that has one, and probing,
|
|
30
|
+
* blocking and unblocking a credential that is not the one being refused.
|
|
31
|
+
*/
|
|
32
|
+
readonly identityConfig: AgentWatchConfig;
|
|
33
|
+
/** The `roots[]` path that produced `identityConfig`, when one matched. */
|
|
34
|
+
readonly identityRoot?: string;
|
|
35
|
+
/** The uninstall-marker scope of `identityConfig`'s credential; absent for the machine's. */
|
|
36
|
+
readonly credentialScope?: string;
|
|
16
37
|
readonly configState: ConfigLoadResult['state'];
|
|
17
38
|
readonly configError?: string;
|
|
39
|
+
/** Fields the load accepted the file without — a URL nothing may be sent to. */
|
|
40
|
+
readonly configWarnings: readonly string[];
|
|
18
41
|
readonly installState: InstallState;
|
|
19
42
|
}
|
|
20
43
|
export interface HookRunOptions {
|
|
@@ -28,17 +51,28 @@ export interface SetupOptions {
|
|
|
28
51
|
readonly env: Env;
|
|
29
52
|
readonly setupUrl?: string;
|
|
30
53
|
readonly endpoint?: string;
|
|
54
|
+
/** `--allow-custom-endpoint`: trust an `endpoint` outside the Agent Watch hosts. */
|
|
55
|
+
readonly allowCustomEndpoint?: boolean;
|
|
31
56
|
readonly token?: string;
|
|
32
57
|
/** Developer identity for turn summaries; falls back to `git config user.email`. */
|
|
33
58
|
readonly developerEmail?: string;
|
|
59
|
+
readonly developerName?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Absolute project root to file this identity under, instead of making it the
|
|
62
|
+
* machine's default. This is what lets one machine report to two tenants.
|
|
63
|
+
*/
|
|
64
|
+
readonly root?: string;
|
|
34
65
|
/** OTLP signal selection: "all", "none" or a comma list of logs,traces,metrics. */
|
|
35
66
|
readonly otel?: string;
|
|
36
|
-
/** Non-interactive: fail instead of prompting. */
|
|
37
|
-
readonly yes?: boolean;
|
|
38
|
-
readonly ask?: (question: string) => Promise<string>;
|
|
39
67
|
readonly hookCommandFor?: (providerId: string) => string;
|
|
40
68
|
/** Git runner override; tests resolve the identity without a real git. */
|
|
41
69
|
readonly gitRun?: GitRunner;
|
|
70
|
+
/** `--no-browser`: print the sign-in link without opening it. */
|
|
71
|
+
readonly noBrowser?: boolean;
|
|
72
|
+
/** Browser sign-in seams for tests: the gateway, the poll timer and the browser opener. */
|
|
73
|
+
readonly openUrl?: (url: string) => void;
|
|
74
|
+
readonly fetchFn?: typeof fetch;
|
|
75
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
42
76
|
}
|
|
43
77
|
/** What `agentwatch doctor` was asked to report. */
|
|
44
78
|
export interface DoctorOptions {
|
package/dist/cli/ui.d.ts
CHANGED
|
@@ -39,3 +39,10 @@ export declare function println(line?: string): void;
|
|
|
39
39
|
* @param line - The line, without its newline.
|
|
40
40
|
*/
|
|
41
41
|
export declare function printErrln(line?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* The custom endpoint override line, naming every trusted origin.
|
|
44
|
+
*
|
|
45
|
+
* @param origins - The machine's `customEndpoints`.
|
|
46
|
+
* @returns The line, without a level symbol.
|
|
47
|
+
*/
|
|
48
|
+
export declare function customEndpointOverride(origins: readonly string[]): string;
|
package/dist/cli/ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import { COLOR_BOLD, COLOR_GREEN, COLOR_GREY, COLOR_RED, COLOR_RESET, COLOR_YELLOW, ESC, NO_COLOR_VAR } from './constants/cli.constants.js';
|
|
2
|
+
import { COLOR_BOLD, COLOR_GREEN, COLOR_GREY, COLOR_RED, COLOR_RESET, COLOR_YELLOW, CUSTOM_ENDPOINT_OVERRIDE, ESC, NO_COLOR_VAR } from './constants/cli.constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Human-facing output helpers.
|
|
5
5
|
*
|
|
@@ -76,3 +76,12 @@ export function printErrln(line = '') {
|
|
|
76
76
|
function paint(text, code) {
|
|
77
77
|
return useColor ? `${ESC}[${code}m${text}${ESC}[${COLOR_RESET}m` : text;
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The custom endpoint override line, naming every trusted origin.
|
|
81
|
+
*
|
|
82
|
+
* @param origins - The machine's `customEndpoints`.
|
|
83
|
+
* @returns The line, without a level symbol.
|
|
84
|
+
*/
|
|
85
|
+
export function customEndpointOverride(origins) {
|
|
86
|
+
return `custom endpoint override: ${origins.join(', ')} ${CUSTOM_ENDPOINT_OVERRIDE}`;
|
|
87
|
+
}
|
package/dist/cli/uninstall.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { providerIds, providers } from '../providers/registry.js';
|
|
3
3
|
import { saveInstallState } from '../storage/install-state.js';
|
|
4
|
+
import { uninstalledFile } from '../storage/uninstalled.js';
|
|
5
|
+
import { forgetDeviceCredentials } from '../credentials/credentials.js';
|
|
4
6
|
import { buildCliContext, buildHookCommand } from './context.js';
|
|
7
|
+
import { SETUP_EXCHANGE_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
5
8
|
import { bold, println, symbols } from './ui.js';
|
|
6
9
|
/**
|
|
7
10
|
* `agentwatch uninstall` — remove AgentWatch's own entries from agent configs.
|
|
@@ -46,6 +49,23 @@ export async function runUninstall(options) {
|
|
|
46
49
|
println();
|
|
47
50
|
}
|
|
48
51
|
await saveInstallState(context.paths, installState);
|
|
52
|
+
// The whole install, not one agent: the device is switched off on the
|
|
53
|
+
// platform and its secret goes with it, so a reinstall enrolls again rather
|
|
54
|
+
// than finding a credential nobody chose to keep. The network never fails
|
|
55
|
+
// uninstall; a credential left live is said, with who can switch it off. A
|
|
56
|
+
// config that could not be updated is a failure: nothing was revoked.
|
|
57
|
+
if (!options.agent) {
|
|
58
|
+
const forgotten = await forgetDeviceCredentials({ env: options.env, paths: context.paths, timeoutMs: SETUP_EXCHANGE_TIMEOUT_MS });
|
|
59
|
+
if (!forgotten.marked)
|
|
60
|
+
println(`${symbols.warn} could not record the uninstall in ${uninstalledFile(context.paths)}; a later run may enroll this machine again`);
|
|
61
|
+
if (forgotten.config !== 'ok') {
|
|
62
|
+
println(`${symbols.fail} could not update config — credential may still be live; re-run uninstall`);
|
|
63
|
+
failures++;
|
|
64
|
+
}
|
|
65
|
+
for (const revocation of forgotten.revocations) {
|
|
66
|
+
println(revocationLine(revocation));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
49
69
|
if (options.purge && !options.agent) {
|
|
50
70
|
await fs.rm(context.paths.dataDir, { recursive: true, force: true });
|
|
51
71
|
await fs.rm(context.paths.configDir, { recursive: true, force: true });
|
|
@@ -65,7 +85,9 @@ export async function runUninstall(options) {
|
|
|
65
85
|
function resolveTargets(agent) {
|
|
66
86
|
if (!agent)
|
|
67
87
|
return providers;
|
|
68
|
-
|
|
88
|
+
// This command already holds the eager list, so it names the one it wants
|
|
89
|
+
// rather than loading a sixth copy of it.
|
|
90
|
+
const provider = providers.find((candidate) => candidate.id === agent);
|
|
69
91
|
return provider ? [provider] : undefined;
|
|
70
92
|
}
|
|
71
93
|
/**
|
|
@@ -81,3 +103,18 @@ function report(outcome, current) {
|
|
|
81
103
|
}
|
|
82
104
|
return outcome.installState ?? current;
|
|
83
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* What uninstall says about one device credential.
|
|
108
|
+
*
|
|
109
|
+
* @param revocation - What the platform did.
|
|
110
|
+
* @returns The line to print.
|
|
111
|
+
*/
|
|
112
|
+
function revocationLine(revocation) {
|
|
113
|
+
if (revocation.revoked && revocation.removed)
|
|
114
|
+
return `${symbols.ok} device credential revoked on the platform and removed from this machine; setup with an install key enrolls it again`;
|
|
115
|
+
const leftover = revocation.leftover ? `; remove it by hand from ${revocation.leftover}` : '';
|
|
116
|
+
if (revocation.revoked)
|
|
117
|
+
return `${symbols.warn} device credential revoked on the platform but not removed from this machine (${revocation.reason})${leftover}`;
|
|
118
|
+
const where = revocation.removed ? 'removed from this machine but still active on the platform' : 'still active on the platform and still on this machine';
|
|
119
|
+
return `${symbols.warn} device credential ${where} (${revocation.reason}); an admin can revoke this machine in Settings → Install${leftover}`;
|
|
120
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Env } from '../core/env.js';
|
|
2
|
+
/**
|
|
3
|
+
* `agentwatch update [--check]` — install the latest release from npm.
|
|
4
|
+
*
|
|
5
|
+
* `--check` only asks the registry and refreshes the cache the session-start
|
|
6
|
+
* notice reads; the session-start hook runs it detached once a day.
|
|
7
|
+
*
|
|
8
|
+
* Only the copy npm itself installed globally is updated: one behind `npm link`
|
|
9
|
+
* (a source checkout) would be replaced by a release, and one from another
|
|
10
|
+
* package manager or a project's `node_modules` would stay what runs while npm
|
|
11
|
+
* installed a copy nobody uses. Both are refused with what to do instead.
|
|
12
|
+
*
|
|
13
|
+
* @param env - Ambient environment.
|
|
14
|
+
* @param checkOnly - Ask, do not install.
|
|
15
|
+
* @returns The exit code.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runUpdate(env: Env, checkOnly: boolean): Promise<number>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { resolvePaths } from '../storage/paths.js';
|
|
7
|
+
import { installedPackage, isNewer, refreshLatest } from '../update/update-check.js';
|
|
8
|
+
import { printErrln, println, symbols } from './ui.js';
|
|
9
|
+
/**
|
|
10
|
+
* `agentwatch update [--check]` — install the latest release from npm.
|
|
11
|
+
*
|
|
12
|
+
* `--check` only asks the registry and refreshes the cache the session-start
|
|
13
|
+
* notice reads; the session-start hook runs it detached once a day.
|
|
14
|
+
*
|
|
15
|
+
* Only the copy npm itself installed globally is updated: one behind `npm link`
|
|
16
|
+
* (a source checkout) would be replaced by a release, and one from another
|
|
17
|
+
* package manager or a project's `node_modules` would stay what runs while npm
|
|
18
|
+
* installed a copy nobody uses. Both are refused with what to do instead.
|
|
19
|
+
*
|
|
20
|
+
* @param env - Ambient environment.
|
|
21
|
+
* @param checkOnly - Ask, do not install.
|
|
22
|
+
* @returns The exit code.
|
|
23
|
+
*/
|
|
24
|
+
export async function runUpdate(env, checkOnly) {
|
|
25
|
+
const pkg = installedPackage();
|
|
26
|
+
const latest = await refreshLatest(resolvePaths(env).dataDir, env.now());
|
|
27
|
+
if (!latest) {
|
|
28
|
+
printErrln(`${symbols.fail} could not reach the npm registry; try again later`);
|
|
29
|
+
return 1;
|
|
30
|
+
}
|
|
31
|
+
if (!isNewer(latest, pkg.version)) {
|
|
32
|
+
println(`${symbols.ok} agentwatch ${pkg.version} is up to date`);
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
if (checkOnly) {
|
|
36
|
+
println(`${symbols.warn} agentwatch ${latest} is available (you have ${pkg.version}); run \`agentwatch update\``);
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
const root = realpathSync(fileURLToPath(new URL('../..', import.meta.url)));
|
|
40
|
+
const spec = `${pkg.name}@${latest}`;
|
|
41
|
+
// npm is `npm.cmd` on Windows, which only a shell resolves.
|
|
42
|
+
const shell = process.platform === 'win32';
|
|
43
|
+
if (!root.split(path.sep).includes('node_modules')) {
|
|
44
|
+
printErrln(`${symbols.fail} this agentwatch runs from a source checkout (${root}); update it there with git`);
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
if (root !== npmGlobalCopy(pkg.name, shell)) {
|
|
48
|
+
printErrln(`${symbols.fail} this agentwatch (${root}) was not installed with \`npm install -g\`; update ${spec} with the tool that installed it`);
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
const install = spawnSync('npm', ['install', '-g', spec], { stdio: 'inherit', shell });
|
|
52
|
+
if (install.status !== 0) {
|
|
53
|
+
printErrln(`${symbols.fail} could not install ${spec}; run \`npm install -g ${spec}\` yourself`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
println(`${symbols.ok} updated agentwatch ${pkg.version} → ${latest}; new sessions use it`);
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Where npm's own global install of this package really lives.
|
|
61
|
+
*
|
|
62
|
+
* @param name - The package name.
|
|
63
|
+
* @param shell - Whether npm needs a shell to resolve (Windows).
|
|
64
|
+
* @returns The real path, or undefined when npm has none or cannot say.
|
|
65
|
+
*/
|
|
66
|
+
function npmGlobalCopy(name, shell) {
|
|
67
|
+
const globalRoot = spawnSync('npm', ['root', '-g'], { encoding: 'utf8', shell }).stdout?.trim();
|
|
68
|
+
if (!globalRoot || !path.isAbsolute(globalRoot))
|
|
69
|
+
return undefined;
|
|
70
|
+
try {
|
|
71
|
+
return realpathSync(path.join(globalRoot, name));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|