@agent-watch-ai/edge 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +288 -9
- package/README.md +307 -5
- package/dist/billing/billing-mode.d.ts +37 -5
- package/dist/billing/billing-mode.js +28 -19
- package/dist/billing/constants/billing.constants.d.ts +0 -2
- package/dist/billing/constants/billing.constants.js +0 -2
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.js +1 -1
- package/dist/billing/session-billing.d.ts +7 -3
- package/dist/billing/session-billing.js +34 -13
- package/dist/billing/types/billing.types.d.ts +7 -0
- package/dist/capture/capture-env.d.ts +147 -0
- package/dist/capture/capture-env.js +301 -0
- package/dist/capture/captured-step.d.ts +88 -0
- package/dist/capture/captured-step.js +503 -0
- package/dist/capture/constants/capture.constants.d.ts +85 -0
- package/dist/capture/constants/capture.constants.js +87 -0
- package/dist/capture/launched-runs.d.ts +43 -0
- package/dist/capture/launched-runs.js +157 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +832 -0
- package/dist/capture/schemas/capture.schema.d.ts +35 -0
- package/dist/capture/schemas/capture.schema.js +31 -0
- package/dist/capture/types/capture.types.d.ts +20 -0
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +23 -6
- package/dist/cli/constants/cli.constants.js +24 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +21 -0
- package/dist/cli/doctor-run-capture.js +33 -0
- package/dist/cli/doctor.js +21 -68
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +82 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/misc.js +10 -2
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.d.ts +33 -0
- package/dist/cli/replay.js +228 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +200 -31
- package/dist/cli/status.js +45 -5
- package/dist/cli/toggle.js +10 -0
- package/dist/cli/types/cli.types.d.ts +15 -1
- package/dist/cli/uninstall.js +42 -23
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +104 -17
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +10 -1
- package/dist/config/events-transport.d.ts +15 -0
- package/dist/config/events-transport.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/root-config.d.ts +12 -0
- package/dist/config/root-config.js +24 -0
- package/dist/config/schemas/config.schema.d.ts +15 -2
- package/dist/config/schemas/config.schema.js +52 -8
- package/dist/config/types/config.types.d.ts +7 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/version.d.ts +9 -0
- package/dist/core/version.js +14 -0
- package/dist/core/which.d.ts +11 -0
- package/dist/core/which.js +18 -0
- package/dist/credentials/cloud-claim.d.ts +34 -0
- package/dist/credentials/cloud-claim.js +61 -0
- package/dist/credentials/constants/credentials.constants.d.ts +16 -1
- package/dist/credentials/constants/credentials.constants.js +17 -2
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/credentials/sign-in.d.ts +27 -0
- package/dist/credentials/sign-in.js +31 -1
- package/dist/credentials/token-refresher.d.ts +5 -1
- package/dist/credentials/token-refresher.js +10 -2
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +6 -3
- package/dist/events/types/events.types.d.ts +6 -0
- package/dist/events/types/replay-progress.types.d.ts +26 -0
- package/dist/events/types/replay-progress.types.js +1 -0
- package/dist/events/types/repo-tree.types.d.ts +2 -1
- package/dist/feature/ticket-candidates.d.ts +1 -1
- package/dist/git/checkout-root.d.ts +15 -0
- package/dist/git/checkout-root.js +18 -0
- package/dist/git/code-state.d.ts +2 -16
- package/dist/git/code-state.js +11 -12
- package/dist/git/constants/git.constants.d.ts +33 -11
- package/dist/git/constants/git.constants.js +45 -12
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.js +5 -1
- package/dist/git/index.d.ts +1 -2
- package/dist/git/index.js +1 -1
- package/dist/git/repo-snapshot.d.ts +13 -4
- package/dist/git/repo-snapshot.js +53 -9
- package/dist/git/types/snapshot.types.d.ts +6 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +82 -57
- package/dist/privacy/product-capture.js +2 -0
- package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.capture.js +5 -0
- package/dist/providers/antigravity/antigravity.detect.js +8 -22
- package/dist/providers/antigravity/antigravity.provider.js +10 -3
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
- package/dist/providers/claude/claude.adapter.js +9 -6
- package/dist/providers/claude/claude.detect.js +2 -17
- package/dist/providers/claude/claude.otel.d.ts +21 -3
- package/dist/providers/claude/claude.otel.js +216 -61
- package/dist/providers/claude/claude.provider.js +21 -1
- package/dist/providers/claude/claude.version.d.ts +9 -0
- package/dist/providers/claude/claude.version.js +28 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.constants.js +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
- package/dist/providers/claude/types/claude.types.d.ts +13 -0
- package/dist/providers/codex/codex.capture.d.ts +76 -0
- package/dist/providers/codex/codex.capture.js +454 -0
- package/dist/providers/codex/codex.detect.js +2 -4
- package/dist/providers/codex/codex.otel.d.ts +38 -2
- package/dist/providers/codex/codex.otel.js +50 -6
- package/dist/providers/codex/codex.provider.js +8 -0
- package/dist/providers/codex/codex.surface.d.ts +9 -0
- package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
- package/dist/providers/codex/codex.titles.d.ts +14 -0
- package/dist/providers/codex/codex.titles.js +35 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
- package/dist/providers/codex/constants/codex.constants.js +4 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
- package/dist/providers/cursor/constants/cursor.constants.js +25 -5
- package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
- package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
- package/dist/providers/cursor/cursor.adapter.js +20 -82
- package/dist/providers/cursor/cursor.capture.d.ts +1 -0
- package/dist/providers/cursor/cursor.capture.js +4 -0
- package/dist/providers/cursor/cursor.detect.d.ts +5 -1
- package/dist/providers/cursor/cursor.detect.js +11 -26
- package/dist/providers/cursor/cursor.hooks.js +2 -2
- package/dist/providers/cursor/cursor.provider.js +16 -7
- package/dist/providers/cursor/cursor.titles.d.ts +14 -0
- package/dist/providers/cursor/cursor.titles.js +20 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
- package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
- package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
- package/dist/providers/gemini/constants/gemini.constants.js +17 -0
- package/dist/providers/gemini/gemini.capture.d.ts +81 -0
- package/dist/providers/gemini/gemini.capture.js +210 -0
- package/dist/providers/gemini/gemini.detect.js +57 -24
- package/dist/providers/gemini/gemini.otel.d.ts +38 -2
- package/dist/providers/gemini/gemini.otel.js +56 -125
- package/dist/providers/gemini/gemini.provider.js +5 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/provider.d.ts +8 -0
- package/dist/providers/provider.js +9 -0
- package/dist/providers/registry.d.ts +14 -0
- package/dist/providers/registry.js +14 -0
- package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
- package/dist/providers/shared/constants/hook-config.constants.js +2 -0
- package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
- package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
- package/dist/providers/shared/editor-paths.d.ts +8 -0
- package/dist/providers/shared/editor-paths.js +18 -0
- package/dist/providers/shared/hook-config.d.ts +5 -0
- package/dist/providers/shared/hook-config.js +39 -1
- package/dist/providers/shared/hooks-marker.d.ts +14 -0
- package/dist/providers/shared/hooks-marker.js +23 -0
- package/dist/providers/shared/install-record.d.ts +29 -0
- package/dist/providers/shared/install-record.js +52 -0
- package/dist/providers/shared/session-title-store.d.ts +23 -0
- package/dist/providers/shared/session-title-store.js +50 -0
- package/dist/providers/shared/terminal-capture.d.ts +41 -0
- package/dist/providers/shared/terminal-capture.js +109 -0
- package/dist/providers/shared/tooling.d.ts +21 -0
- package/dist/providers/shared/tooling.js +36 -1
- package/dist/providers/types/provider.types.d.ts +57 -4
- package/dist/replay/checkout-resolver.d.ts +56 -0
- package/dist/replay/checkout-resolver.js +173 -0
- package/dist/replay/codex-turns.d.ts +24 -0
- package/dist/replay/codex-turns.js +221 -0
- package/dist/replay/constants/replay.constants.d.ts +99 -0
- package/dist/replay/constants/replay.constants.js +102 -0
- package/dist/replay/describe.d.ts +10 -0
- package/dist/replay/describe.js +31 -0
- package/dist/replay/gemini-turns.d.ts +36 -0
- package/dist/replay/gemini-turns.js +192 -0
- package/dist/replay/machine.d.ts +34 -0
- package/dist/replay/machine.js +68 -0
- package/dist/replay/progress-event.d.ts +21 -0
- package/dist/replay/progress-event.js +45 -0
- package/dist/replay/replay-runner.d.ts +60 -0
- package/dist/replay/replay-runner.js +581 -0
- package/dist/replay/replay-scan.d.ts +84 -0
- package/dist/replay/replay-scan.js +182 -0
- package/dist/replay/replay-state.d.ts +108 -0
- package/dist/replay/replay-state.js +199 -0
- package/dist/replay/resume.d.ts +18 -0
- package/dist/replay/resume.js +34 -0
- package/dist/replay/start.d.ts +23 -0
- package/dist/replay/start.js +39 -0
- package/dist/replay/throttle.d.ts +36 -0
- package/dist/replay/throttle.js +44 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +241 -0
- package/dist/replay/turn-event.d.ts +40 -0
- package/dist/replay/turn-event.js +127 -0
- package/dist/replay/types/replay.types.d.ts +198 -0
- package/dist/replay/types/replay.types.js +1 -0
- package/dist/replay/window.d.ts +28 -0
- package/dist/replay/window.js +41 -0
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +71 -41
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
- package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
- package/dist/snapshot/constants/snapshot.constants.js +34 -7
- package/dist/snapshot/index.d.ts +2 -2
- package/dist/snapshot/index.js +1 -1
- package/dist/snapshot/snapshot-pipeline.js +100 -26
- package/dist/snapshot/snapshot-state.js +6 -2
- package/dist/snapshot/tree-pipeline.d.ts +1 -1
- package/dist/snapshot/tree-pipeline.js +34 -15
- package/dist/snapshot/types/snapshot.types.d.ts +22 -3
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/transport/delivery-stats.d.ts +13 -1
- package/dist/transport/delivery-stats.js +18 -2
- package/dist/transport/delivery.d.ts +4 -3
- package/dist/transport/delivery.js +21 -7
- package/dist/transport/identity-delivery.d.ts +20 -0
- package/dist/transport/identity-delivery.js +41 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/types/delivery-flow.types.d.ts +7 -0
- package/dist/turns/claude-transcript.js +4 -12
- package/dist/turns/codex-transcript.d.ts +9 -0
- package/dist/turns/codex-transcript.js +27 -19
- package/dist/turns/constants/turns.constants.d.ts +29 -12
- package/dist/turns/constants/turns.constants.js +31 -19
- package/dist/turns/gemini-transcript.d.ts +19 -1
- package/dist/turns/gemini-transcript.js +29 -18
- package/dist/turns/index.d.ts +3 -4
- package/dist/turns/index.js +2 -3
- package/dist/turns/run-state.d.ts +71 -0
- package/dist/turns/run-state.js +114 -0
- package/dist/turns/tool-events.d.ts +11 -1
- package/dist/turns/tool-events.js +32 -9
- package/dist/turns/transcript.d.ts +15 -14
- package/dist/turns/transcript.js +23 -4
- package/dist/turns/turn-state.d.ts +82 -7
- package/dist/turns/turn-state.js +157 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +163 -87
- package/dist/turns/types/transcript.types.d.ts +11 -1
- package/dist/turns/types/turn-provider.types.d.ts +33 -0
- package/dist/turns/types/turn-provider.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +9 -0
- package/dist/turns/types/turn-summary.types.d.ts +17 -1
- package/dist/turns/types/turn-tracker.types.d.ts +3 -1
- package/dist/turns/work-checkout.js +1 -2
- package/docs/AUDIT_PROMPT.md +10 -0
- package/docs/DATA_HANDLING.md +201 -13
- package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
- package/docs/PERFORMANCE.md +10 -0
- package/package.json +3 -2
- package/dist/events/canonical-event.d.ts +0 -10
- package/dist/events/canonical-event.js +0 -9
- package/dist/git/repository-root.d.ts +0 -39
- package/dist/git/repository-root.js +0 -131
- package/dist/git/types/repository-root.types.d.ts +0 -11
- package/dist/transport/transport.d.ts +0 -6
- package/dist/turns/codex-originator.d.ts +0 -11
- package/dist/turns/cursor-transcript.d.ts +0 -21
- package/dist/turns/cursor-transcript.js +0 -66
- package/dist/turns/native-session-titles.d.ts +0 -26
- package/dist/turns/native-session-titles.js +0 -102
- /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
- /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
package/dist/cli/setup.js
CHANGED
|
@@ -9,23 +9,29 @@ import { deliverableOrigin, needsTrust } from '../config/schemas/config.schema.j
|
|
|
9
9
|
import { applyRootOverride, canonicalRoot } from '../config/root-config.js';
|
|
10
10
|
import { transitionDestination } from '../config/destination.js';
|
|
11
11
|
import { asRecord, compact } from '../core/object.js';
|
|
12
|
-
import {
|
|
12
|
+
import { cloudIdentity } from '../credentials/cloud-claim.js';
|
|
13
|
+
import { CLAUDE_CODE_REMOTE_VAR, CREDENTIALS_DIR_NAME, DEVICE_SOURCE_BATCH_CODE } from '../credentials/constants/credentials.constants.js';
|
|
13
14
|
import { forgetDeviceIfUnused, nativeExporterBearer, revokeDeviceIfUnused } from '../credentials/credentials.js';
|
|
14
|
-
import { awaitingSignIn, credentialId, deviceFor, hasCredential, identityOf } from '../credentials/identity.js';
|
|
15
|
+
import { awaitingSignIn, credentialId, deviceFor, hasCredential, identityFingerprint, identityOf } from '../credentials/identity.js';
|
|
15
16
|
import { abandonDevice, migrateInstallKey } from '../credentials/migration.js';
|
|
16
|
-
import {
|
|
17
|
+
import { readDeviceState } from '../credentials/device-state.js';
|
|
18
|
+
import { enrollWithCloudClaim, enrollWithCode, signInDevice } from '../credentials/sign-in.js';
|
|
17
19
|
import { identityPaths } from '../transport/queue-partition.js';
|
|
18
20
|
import { clearUninstalled, configScopes, uninstallScope } from '../storage/uninstalled.js';
|
|
19
21
|
import { storeLabel } from '../credentials/secret-store.js';
|
|
20
22
|
import { collectGitContext, developerDisplayName, developerIdentity } from '../git/git-context.js';
|
|
21
23
|
import { resolveEnrollment } from '../enrollment/enrollment.js';
|
|
22
24
|
import { providers } from '../providers/registry.js';
|
|
25
|
+
import { REPLAY_AGENTS } from '../replay/constants/replay.constants.js';
|
|
26
|
+
import { automaticReplayAttempted, readReplayRecord, replayStateFile } from '../replay/replay-state.js';
|
|
23
27
|
import { removeRefusedExporters } from '../providers/shared/exporter-allowlist.js';
|
|
24
28
|
import { saveInstallState } from '../storage/install-state.js';
|
|
25
29
|
import { readJsonFile } from '../storage/json-file.js';
|
|
26
30
|
import { ENROLLMENT_CODE_VAR, MACHINE_SCOPE, TOKEN_VAR } from '../storage/constants/storage.constants.js';
|
|
31
|
+
import { startReplayDetached } from '../replay/start.js';
|
|
32
|
+
import { parseReplayDays } from '../replay/window.js';
|
|
27
33
|
import { signInOpener } from './open-browser.js';
|
|
28
|
-
import { buildCliContext, buildHookCommand,
|
|
34
|
+
import { buildCliContext, buildHookCommand, openIdentityDelivery, quoteArg } from './context.js';
|
|
29
35
|
import { DEVELOPER_IDENTITY_REMEDIES, ENROLLMENT_CODE_STDIN, NO_CONFIG_WRITTEN, NO_DEVELOPER_IDENTITY, SETUP_EXCHANGE_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
30
36
|
import { bold, customEndpointOverride, dim, printErrln, println, symbols } from './ui.js';
|
|
31
37
|
/**
|
|
@@ -37,11 +43,53 @@ import { bold, customEndpointOverride, dim, printErrln, println, symbols } from
|
|
|
37
43
|
* a missing token fails the run before the first file is touched. No endpoint
|
|
38
44
|
* at all means the production Agent Watch backend.
|
|
39
45
|
*
|
|
46
|
+
* `--cloud` is the managed SessionStart hook of a Claude Code cloud VM: it
|
|
47
|
+
* claims a device from the organization's managed settings and then runs the
|
|
48
|
+
* same config write and agent install. It returns 0 on every path, so a cloud
|
|
49
|
+
* session never fails over Agent Watch; a VM that already has a credential,
|
|
50
|
+
* or is no cloud session, returns at once.
|
|
51
|
+
*
|
|
40
52
|
* @param options - Environment and flags.
|
|
41
|
-
* @returns 0 when every step succeeded, else 1.
|
|
53
|
+
* @returns 0 when every step succeeded, else 1 (always 0 with `cloud`).
|
|
42
54
|
*/
|
|
43
55
|
export async function runSetup(options) {
|
|
44
56
|
const context = await buildCliContext(options.env);
|
|
57
|
+
if (options.cloud !== true)
|
|
58
|
+
return setup(options, context);
|
|
59
|
+
try {
|
|
60
|
+
if (options.env.vars[CLAUDE_CODE_REMOTE_VAR] !== 'true') {
|
|
61
|
+
println(`agentwatch setup --cloud: not a Claude Code cloud session (${CLAUDE_CODE_REMOTE_VAR} is not true); nothing to do`);
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
// Resume, or a VM set up another way: never a second device.
|
|
65
|
+
if (context.configState === 'ok' && hasCredential(context.config))
|
|
66
|
+
return 0;
|
|
67
|
+
const identity = await cloudIdentity(options.env);
|
|
68
|
+
if ('skip' in identity) {
|
|
69
|
+
println(`agentwatch setup --cloud: ${identity.skip}`);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
// The flag path of resolveDeveloperEmail: git (noreply@anthropic.com here) is never asked.
|
|
73
|
+
// A fresh VM has no earlier sessions to replay.
|
|
74
|
+
// The block names its backend only in its OTLP endpoint: claim there, not at
|
|
75
|
+
// the production default, unless --endpoint says otherwise.
|
|
76
|
+
await setup({ ...options, endpoint: options.endpoint ?? identity.gateway, developerEmail: identity.email, noReplay: true }, context, identity);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Never the error: it can come from a device route.
|
|
80
|
+
println('agentwatch setup --cloud: setup stopped unexpectedly; Agent Watch not installed this session, records stay queued');
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The setup run itself, once `runSetup` has built the context.
|
|
86
|
+
*
|
|
87
|
+
* @param options - Environment and flags.
|
|
88
|
+
* @param context - Resolved CLI context.
|
|
89
|
+
* @param cloud - The managed-settings identity of a `--cloud` run.
|
|
90
|
+
* @returns 0 when every step succeeded, else 1.
|
|
91
|
+
*/
|
|
92
|
+
async function setup(options, context, cloud) {
|
|
45
93
|
println(bold('AgentWatch Setup'));
|
|
46
94
|
println();
|
|
47
95
|
if (context.disabled) {
|
|
@@ -75,11 +123,16 @@ export async function runSetup(options) {
|
|
|
75
123
|
println(`${symbols.fail} invalid --otel value "${options.otel}" (expected "all", "none" or a comma list of logs,traces,metrics)`);
|
|
76
124
|
return 1;
|
|
77
125
|
}
|
|
126
|
+
const replayDays = parseReplayDays(options.replayDays);
|
|
127
|
+
if (replayDays === undefined) {
|
|
128
|
+
println(`${symbols.fail} invalid --replay-days "${options.replayDays}" (expected a whole number of days, 1 to 366)`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
78
131
|
reportRepository(await collectGitContext({ cwd: options.env.cwd, includeChangedFiles: false }));
|
|
79
132
|
println();
|
|
80
133
|
const detected = await reportDetection(options);
|
|
81
134
|
if (detected.length === 0) {
|
|
82
|
-
println('No supported agents found. Install Claude Code or Codex and re-run `agentwatch setup`.');
|
|
135
|
+
println(options.agents === undefined ? 'No supported agents found. Install Claude Code or Codex and re-run `agentwatch setup`.' : `${options.agents.map((provider) => provider.displayName).join(', ')} is not detected here. Install it, or run setup without --agent.`);
|
|
83
136
|
return 1;
|
|
84
137
|
}
|
|
85
138
|
const resolved = await resolveRoot(options, baseConfig);
|
|
@@ -97,12 +150,14 @@ export async function runSetup(options) {
|
|
|
97
150
|
println(`${symbols.fail} --defer-sign-in takes the organization enrollment URL and configures the machine, not a project root; nothing was written`);
|
|
98
151
|
return 1;
|
|
99
152
|
}
|
|
100
|
-
const
|
|
101
|
-
if ('error' in
|
|
102
|
-
println(`${symbols.fail} ${
|
|
153
|
+
const resolvedEnrollment = enroll({ ...options, setupUrl: options.setupUrl ?? pendingSignInUrl(options, baseConfig, rootPath) }, inherited, baseConfig.customEndpoints);
|
|
154
|
+
if ('error' in resolvedEnrollment) {
|
|
155
|
+
println(`${symbols.fail} ${resolvedEnrollment.error}`);
|
|
103
156
|
return 1;
|
|
104
157
|
}
|
|
105
|
-
|
|
158
|
+
// A cloud claim goes through the sign-in path: the endpoint as judged, never a key.
|
|
159
|
+
const enrolled = cloud ? { endpoint: resolvedEnrollment.endpoint, signIn: { organizationId: cloud.organizationId } } : resolvedEnrollment;
|
|
160
|
+
const code = await readEnrollmentCode(options, enrolled.signIn !== undefined && !cloud);
|
|
106
161
|
if ('error' in code) {
|
|
107
162
|
println(`${symbols.fail} ${code.error}`);
|
|
108
163
|
return 1;
|
|
@@ -128,7 +183,8 @@ export async function runSetup(options) {
|
|
|
128
183
|
println(`${symbols.fail} no token: pass --token or $${TOKEN_VAR}`);
|
|
129
184
|
return 1;
|
|
130
185
|
}
|
|
131
|
-
|
|
186
|
+
// A cloud VM's config may be a copy of another's: its installation is always its own.
|
|
187
|
+
const installationId = (cloud ? undefined : baseConfig.installationId) ?? crypto.randomUUID();
|
|
132
188
|
const developerEmail = await resolveDeveloperEmail(options, baseConfig);
|
|
133
189
|
// A sign-in or a code names the developer itself (checked once it has), and a deferred install names nobody yet.
|
|
134
190
|
if (!developerEmail && !enrolled.signIn) {
|
|
@@ -138,13 +194,14 @@ export async function runSetup(options) {
|
|
|
138
194
|
// Absent is a real answer and must stay absent: writing an empty name would
|
|
139
195
|
// hand the platform a value to store, and the backend coalesces — it keeps the
|
|
140
196
|
// name it already has only for as long as nobody sends a worse one.
|
|
141
|
-
|
|
197
|
+
// A cloud VM's git name is the agent's, not the developer's.
|
|
198
|
+
const developerName = cloud ? undefined : await resolveDeveloperName(options, baseConfig);
|
|
142
199
|
if (spent)
|
|
143
200
|
println(`${symbols.ok} already enrolled with this enrollment code; it was not redeemed again`);
|
|
144
201
|
// After every check that can refuse the run, so a developer never signs in
|
|
145
202
|
// for a setup that was going to fail anyway. A spent code signs nobody in.
|
|
146
203
|
// Deferred: no sign-in here. A device its developer already enrolled is kept below.
|
|
147
|
-
const signedIn = enrolled.signIn && !deferred && !spent ? await signIn(options, context, { ...enrolled.signIn, endpoint: enrolled.endpoint, installationId, code: redeem }) : undefined;
|
|
204
|
+
const signedIn = enrolled.signIn && !deferred && !spent ? await signIn(options, context, { ...enrolled.signIn, endpoint: enrolled.endpoint, installationId, code: redeem, cloud }) : undefined;
|
|
148
205
|
if (signedIn && 'error' in signedIn) {
|
|
149
206
|
println(`${symbols.fail} ${signedIn.error}`);
|
|
150
207
|
return 1;
|
|
@@ -157,8 +214,8 @@ export async function runSetup(options) {
|
|
|
157
214
|
reportMissingIdentity();
|
|
158
215
|
return 1;
|
|
159
216
|
}
|
|
160
|
-
// A root re-run without --token keeps the key
|
|
161
|
-
// the
|
|
217
|
+
// A root re-run without --token keeps its device, and the key while one is
|
|
218
|
+
// still in the file (an older edge left it beside the device). A sign-in has no key at all.
|
|
162
219
|
// A deferred re-run keeps a legacy machine's key for the same backend: it keeps sending through the migration window.
|
|
163
220
|
const token = signedIn ? undefined : (enrolled.token ?? (heldDevice ? existingRoot?.token : undefined) ?? (deferred && (baseConfig.endpoint ?? DEFAULT_ENDPOINT) === enrolled.endpoint ? baseConfig.token : undefined));
|
|
164
221
|
// The same key again (an MDM re-push, a re-run) keeps its device; a new key
|
|
@@ -172,7 +229,8 @@ export async function runSetup(options) {
|
|
|
172
229
|
device,
|
|
173
230
|
// A sign-in's device belongs to whoever approved it, not to this checkout's git email.
|
|
174
231
|
developerEmail: signedIn?.developerEmail ?? developerEmail,
|
|
175
|
-
|
|
232
|
+
// A cloud VM never keeps a name a copied config carried in.
|
|
233
|
+
...(developerName || cloud ? { developerName } : {})
|
|
176
234
|
};
|
|
177
235
|
const stored = rootPath === undefined ? baseConfig : baseConfig.roots?.[rootPath];
|
|
178
236
|
const previous = rootPath === undefined ? baseConfig.endpoint : previousEndpoint(stored, baseConfig);
|
|
@@ -247,6 +305,40 @@ export async function runSetup(options) {
|
|
|
247
305
|
if (detected.some(({ provider }) => provider.id === 'codex'))
|
|
248
306
|
println(dim(' Codex: approve the hooks with /hooks; until you do, no hook runs'));
|
|
249
307
|
println(dim(' run `agentwatch status` anytime, `agentwatch doctor` to diagnose'));
|
|
308
|
+
// Only a credential can send, and only these agents leave transcripts with token counts.
|
|
309
|
+
const replayed = detected.filter(({ provider }) => REPLAY_AGENTS.has(provider.id)).map(({ provider }) => provider.displayName);
|
|
310
|
+
const replayCommand = rootPath === undefined ? 'agentwatch replay --machine' : `agentwatch replay --root ${quoteArg(rootPath)}`;
|
|
311
|
+
const replayable = options.noReplay !== true && !deferred && !awaitingSignIn(config) && replayed.length > 0;
|
|
312
|
+
// A replay reads every agent's transcripts, so with --agent it would send the sessions of agents left out.
|
|
313
|
+
if (options.agents !== undefined && replayable)
|
|
314
|
+
println(dim(` to send earlier sessions of every agent, run \`${replayCommand}${options.replayDays === undefined ? '' : ` --replay-days ${replayDays}`}\``));
|
|
315
|
+
if (options.agents === undefined && replayable) {
|
|
316
|
+
const loaded = await loadConfig(context.paths);
|
|
317
|
+
const currentIdentity = rootPath === undefined ? loaded.config : applyRootOverride(loaded.config, rootPath).config;
|
|
318
|
+
const currentToken = identityOf(currentIdentity);
|
|
319
|
+
const currentFile = replayStateFile(identityPaths(context.paths, currentToken).statsFile);
|
|
320
|
+
const replay = currentToken ? await readReplayRecord(currentFile) : undefined;
|
|
321
|
+
const replaySelector = rootPath === undefined ? ['--machine'] : ['--root', rootPath];
|
|
322
|
+
let attempted = true;
|
|
323
|
+
let checkFailed = false;
|
|
324
|
+
try {
|
|
325
|
+
attempted = await automaticReplayAttempted(context.paths.configDir, context.paths.dataDir);
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
checkFailed = true;
|
|
329
|
+
println(`${symbols.warn} automatic historical replay was not started because its one-time marker could not be checked; run \`${replayCommand}\` explicitly if you want it`);
|
|
330
|
+
}
|
|
331
|
+
if (replay) {
|
|
332
|
+
println(`${symbols.warn} historical replay already exists (${replay.state}); setup did not start another. Use \`${replayCommand} --resume\` to continue it, \`${replayCommand} --stop\` to abandon it, or run \`${replayCommand}\` explicitly to repeat a finished replay.`);
|
|
333
|
+
}
|
|
334
|
+
if (!replay && attempted && !checkFailed) {
|
|
335
|
+
println(`${symbols.warn} automatic historical replay was already attempted on this machine; setup did not start another. Run \`${replayCommand}\` explicitly to repeat it.`);
|
|
336
|
+
}
|
|
337
|
+
if (!replay && !attempted && !checkFailed) {
|
|
338
|
+
println(`Replaying the last ${replayDays} days of ${replayed.join(', ')} sessions in the background; \`${replayCommand} --stop\` to cancel; \`--no-replay\` skips`);
|
|
339
|
+
startReplayDetached(options.env, ['replay', ...replaySelector, '--replay-days', String(replayDays), '--claim-automatic', '--skip-if-existing'], rootPath ?? options.env.home);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
250
342
|
return failures === 0 ? 0 : 1;
|
|
251
343
|
}
|
|
252
344
|
/**
|
|
@@ -329,10 +421,19 @@ async function readPipedStdin() {
|
|
|
329
421
|
* @param target.organizationId - The organization's public id.
|
|
330
422
|
* @param target.installationId - The installation the credential is bound to.
|
|
331
423
|
* @param target.code - The admin-issued code; the browser sign-in runs without one.
|
|
424
|
+
* @param target.cloud - The managed-settings identity a cloud VM claims its device with.
|
|
332
425
|
* @returns The device, or the message to show.
|
|
333
426
|
*/
|
|
334
427
|
async function signIn(options, context, target) {
|
|
335
428
|
const ctx = { env: options.env, paths: context.paths, timeoutMs: SETUP_EXCHANGE_TIMEOUT_MS, fetchFn: options.fetchFn };
|
|
429
|
+
if (target.cloud) {
|
|
430
|
+
// Said before the claim leaves, so a VM that claims at the wrong backend shows where in its log.
|
|
431
|
+
println(`agentwatch setup --cloud: claiming a cloud device at ${target.endpoint}`);
|
|
432
|
+
const claimed = await enrollWithCloudClaim(ctx, { endpoint: target.endpoint, identity: target.cloud, installationId: target.installationId, name: os.hostname() });
|
|
433
|
+
if (!('error' in claimed))
|
|
434
|
+
println(`${symbols.ok} claimed a cloud device; device credential kept in ${storeLabel(claimed.device.store)}`);
|
|
435
|
+
return claimed;
|
|
436
|
+
}
|
|
336
437
|
if (target.code) {
|
|
337
438
|
const redeemed = await enrollWithCode(ctx, { endpoint: target.endpoint, code: target.code, installationId: target.installationId, name: os.hostname() });
|
|
338
439
|
if (!('error' in redeemed))
|
|
@@ -495,14 +596,14 @@ function reportRepository(git) {
|
|
|
495
596
|
println(`${symbols.ok} repository: ${git.repository ?? git.repositoryRoot}${git.branch ? dim(` (branch: ${git.branch})`) : ''}`);
|
|
496
597
|
}
|
|
497
598
|
/**
|
|
498
|
-
* Detect
|
|
599
|
+
* Detect the agents this run targets and report what was found.
|
|
499
600
|
*
|
|
500
|
-
* @param options - Environment.
|
|
601
|
+
* @param options - Environment and the agents `--agent` selected.
|
|
501
602
|
* @returns The agents that were detected.
|
|
502
603
|
*/
|
|
503
604
|
async function reportDetection(options) {
|
|
504
605
|
println(bold('Detected coding agents:'));
|
|
505
|
-
const results = await Promise.all(providers.map(async (provider) => ({ provider, detection: await provider.detect(options.env) })));
|
|
606
|
+
const results = await Promise.all((options.agents ?? providers).map(async (provider) => ({ provider, detection: await provider.detect(options.env) })));
|
|
506
607
|
for (const { provider, detection } of results) {
|
|
507
608
|
println(detection.detected ? `${symbols.ok} ${provider.displayName}` : `${symbols.off} ${provider.displayName} not detected`);
|
|
508
609
|
}
|
|
@@ -645,19 +746,55 @@ async function exchangeInstallKey(context, identity, replaced, scope) {
|
|
|
645
746
|
const ctx = { env: context.env, paths: context.paths, timeoutMs: SETUP_EXCHANGE_TIMEOUT_MS, ...(scope === undefined ? {} : { scope }) };
|
|
646
747
|
if (replaced)
|
|
647
748
|
await forgetDeviceIfUnused(ctx, replaced);
|
|
648
|
-
if (!identity.token)
|
|
749
|
+
if (!identity.token) {
|
|
750
|
+
await reenrollFromStoredKey(ctx, identity);
|
|
649
751
|
return;
|
|
752
|
+
}
|
|
650
753
|
const device = await migrateInstallKey(ctx, identity, { ignoreBackoff: true });
|
|
651
754
|
if (!device) {
|
|
652
755
|
println(`${symbols.warn} install key not yet exchanged for a device credential; it stays in the config and the next run retries`);
|
|
653
756
|
return;
|
|
654
757
|
}
|
|
758
|
+
const { config } = await loadConfig(context.paths);
|
|
759
|
+
if ([config, ...Object.values(config.roots ?? {})].some((entry) => entry.token === identity.token && entry.device?.id === device.id)) {
|
|
760
|
+
println(`${symbols.warn} the install key is still in ${context.paths.configFile}; re-run setup to move it to ${storeLabel(device.store)}`);
|
|
761
|
+
}
|
|
655
762
|
if (device.store === 'file') {
|
|
656
763
|
println(`${symbols.warn} device credential stored in ${storeLabel(device.store)}: ${path.join(context.paths.configDir, CREDENTIALS_DIR_NAME)}`);
|
|
657
764
|
return;
|
|
658
765
|
}
|
|
659
766
|
println(`${symbols.ok} install key exchanged for a device credential, kept in ${storeLabel(device.store)}`);
|
|
660
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* Enroll a refused device again with the install key kept in its store, as a
|
|
770
|
+
* setup with the key in the config would. A device with no refusal, or one
|
|
771
|
+
* signed in through the browser (no key), is left as it is, silently.
|
|
772
|
+
*
|
|
773
|
+
* @param ctx - Credential context for this run.
|
|
774
|
+
* @param identity - The effective config this run configured.
|
|
775
|
+
*/
|
|
776
|
+
async function reenrollFromStoredKey(ctx, identity) {
|
|
777
|
+
if (!deviceFor(identity) || !(await readDeviceState(identityPaths(ctx.paths, identityOf(identity)).deviceStateFile)).refusal)
|
|
778
|
+
return;
|
|
779
|
+
if (await migrateInstallKey(ctx, identity, { ignoreBackoff: true })) {
|
|
780
|
+
println(`${symbols.ok} device enrolled again with the install key kept in its store`);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
println(`${symbols.warn} the device credential is refused and could not be enrolled again; pass --token <install key> or sign in again`);
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Whether two identities share a queue partition: a key and the device it was
|
|
787
|
+
* exchanged for (the key moved to the store) are one identity.
|
|
788
|
+
*
|
|
789
|
+
* @param a - One identity.
|
|
790
|
+
* @param b - The other.
|
|
791
|
+
* @returns True when they name the same partition.
|
|
792
|
+
*/
|
|
793
|
+
function sameIdentity(a, b) {
|
|
794
|
+
if (a === undefined || b === undefined)
|
|
795
|
+
return a === b;
|
|
796
|
+
return identityFingerprint(a) === identityFingerprint(b);
|
|
797
|
+
}
|
|
661
798
|
/**
|
|
662
799
|
* Say what happens to a backlog queued for the previous backend or token.
|
|
663
800
|
*
|
|
@@ -675,16 +812,16 @@ async function reportStrandedBacklog(context, previousConfig, config, owner) {
|
|
|
675
812
|
const configuredUrl = eventsUrl(config);
|
|
676
813
|
if (!previousUrl || !configuredUrl)
|
|
677
814
|
return;
|
|
678
|
-
if (previousUrl === configuredUrl && identityOf(previousConfig)
|
|
815
|
+
if (previousUrl === configuredUrl && sameIdentity(identityOf(previousConfig), identityOf(config)))
|
|
679
816
|
return;
|
|
680
|
-
const queue =
|
|
817
|
+
const queue = openIdentityDelivery({ ...context, identityConfig: previousConfig }).queue;
|
|
681
818
|
const stranded = await queue.pendingFor(previousUrl);
|
|
682
819
|
if (stranded === 0)
|
|
683
820
|
return;
|
|
684
821
|
println(`${symbols.warn} keeping ${stranded} offline event(s) captured under ${owner} under the previous identity; they expire after ${config.delivery.maxEventAgeDays} day(s)`);
|
|
685
822
|
}
|
|
686
823
|
/**
|
|
687
|
-
* Register hooks and native telemetry in every
|
|
824
|
+
* Register hooks in every detected agent, and native telemetry in those and every agent installed before.
|
|
688
825
|
*
|
|
689
826
|
* Install state is threaded from one operation to the next and persisted once at
|
|
690
827
|
* the end, so a failure part-way through cannot leave a record claiming
|
|
@@ -693,14 +830,20 @@ async function reportStrandedBacklog(context, previousConfig, config, owner) {
|
|
|
693
830
|
* @param options - Environment and the hook-command override.
|
|
694
831
|
* @param context - Resolved CLI context.
|
|
695
832
|
* @param config - The configuration just written.
|
|
696
|
-
* @param detected - Agents to install into.
|
|
833
|
+
* @param detected - Agents to install hooks into.
|
|
697
834
|
* @param bearer - What native exporters authenticate with; see `SetupContext.bearer`.
|
|
698
835
|
* @returns How many steps were skipped or failed.
|
|
699
836
|
*/
|
|
700
837
|
async function installAgents(options, context, config, detected, bearer) {
|
|
701
838
|
let installState = context.installState;
|
|
702
839
|
let failures = 0;
|
|
703
|
-
|
|
840
|
+
const hooked = new Set(detected.map(({ provider }) => provider.id));
|
|
841
|
+
for (const provider of installTargets(options, context.installState, hooked)) {
|
|
842
|
+
// No exporter before a sign-in: it would send with no credential at all.
|
|
843
|
+
const exports = provider.nativeTelemetry !== undefined && !awaitingSignIn(config) && (await provider.nativeTelemetry.supported(options.env));
|
|
844
|
+
// An agent visited only for its exporter has nothing to say when there is none to write.
|
|
845
|
+
if (!hooked.has(provider.id) && !exports)
|
|
846
|
+
continue;
|
|
704
847
|
println(bold(provider.displayName));
|
|
705
848
|
const setupContext = {
|
|
706
849
|
env: options.env,
|
|
@@ -710,12 +853,17 @@ async function installAgents(options, context, config, detected, bearer) {
|
|
|
710
853
|
installState,
|
|
711
854
|
...(bearer ? { bearer } : {})
|
|
712
855
|
};
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
856
|
+
if (hooked.has(provider.id)) {
|
|
857
|
+
const hooks = await provider.installHooks(setupContext);
|
|
858
|
+
installState = printOutcome(hooks, installState);
|
|
859
|
+
// About hooks that are in: a refused install has nothing to qualify.
|
|
860
|
+
if (hooks.ok)
|
|
861
|
+
for (const caveat of provider.caveats ?? [])
|
|
862
|
+
println(`${symbols.warn} note: ${caveat.detail}`);
|
|
863
|
+
if (!hooks.ok)
|
|
864
|
+
failures++;
|
|
865
|
+
}
|
|
866
|
+
if (exports && provider.nativeTelemetry) {
|
|
719
867
|
// First, so an exporter left pointing at a host this config refuses is
|
|
720
868
|
// gone even when there is no allowed route to write in its place.
|
|
721
869
|
const swept = await removeRefusedExporters({ ...setupContext, installState }, [provider]);
|
|
@@ -733,6 +881,27 @@ async function installAgents(options, context, config, detected, bearer) {
|
|
|
733
881
|
await saveInstallState(context.paths, installState);
|
|
734
882
|
return failures;
|
|
735
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* The agents this run visits: those it hooks, and with `--agent` every agent
|
|
886
|
+
* Agent Watch installed before.
|
|
887
|
+
*
|
|
888
|
+
* Signals, endpoint and identity are machine-wide, so `--agent` narrows the
|
|
889
|
+
* hooks only: an installed agent left out keeps exporting to an old endpoint,
|
|
890
|
+
* or not at all after a deferred sign-in. Installed is what install state
|
|
891
|
+
* records, never a hooks file that merely mentions Agent Watch: only what we
|
|
892
|
+
* installed is ours to point at a backend.
|
|
893
|
+
*
|
|
894
|
+
* @param options - The agents `--agent` selected, if any.
|
|
895
|
+
* @param installState - What earlier runs installed.
|
|
896
|
+
* @param hooked - Ids of the agents this run installs hooks into.
|
|
897
|
+
* @returns The providers in registry order.
|
|
898
|
+
*/
|
|
899
|
+
function installTargets(options, installState, hooked) {
|
|
900
|
+
return providers.filter((provider) => {
|
|
901
|
+
const installed = installState.agents[provider.id];
|
|
902
|
+
return hooked.has(provider.id) || (options.agents !== undefined && (installed?.hooksInstalledAt !== undefined || installed?.otelConfiguredAt !== undefined));
|
|
903
|
+
});
|
|
904
|
+
}
|
|
736
905
|
/**
|
|
737
906
|
* Print an outcome and carry its install state forward.
|
|
738
907
|
*
|
package/dist/cli/status.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { eventsUrl } from '../config/config.js';
|
|
2
2
|
import { describeCredential } from '../credentials/credential-status.js';
|
|
3
|
+
import { identityOf } from '../credentials/identity.js';
|
|
4
|
+
import { describeReplay } from '../replay/describe.js';
|
|
5
|
+
import { readReplayRecord, replayStateFile } from '../replay/replay-state.js';
|
|
6
|
+
import { identityPaths, unattributedCount, unattributedQueue } from '../transport/queue-partition.js';
|
|
3
7
|
import { collectGitContext } from '../git/git-context.js';
|
|
8
|
+
import { runCaptureRoute } from '../providers/provider.js';
|
|
4
9
|
import { providers } from '../providers/registry.js';
|
|
5
10
|
import { AUTH_BLOCK_REPROBE_MS } from '../transport/constants/transport.constants.js';
|
|
6
|
-
import {
|
|
7
|
-
import { buildAuthBlock, buildCliContext, buildDeliveryStats, buildHookCommand, buildQueue, buildTransport, resolveContextBearer } from './context.js';
|
|
11
|
+
import { buildCliContext, buildHookCommand, buildQueue, buildTransport, openIdentityDelivery, resolveContextBearer } from './context.js';
|
|
8
12
|
import { STATUS_SEND_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
9
13
|
import { bold, customEndpointOverride, dim, println, symbols } from './ui.js';
|
|
10
14
|
/**
|
|
@@ -34,8 +38,22 @@ export async function runStatus(env) {
|
|
|
34
38
|
}
|
|
35
39
|
println();
|
|
36
40
|
await reportDelivery(context);
|
|
41
|
+
await reportReplay(context);
|
|
37
42
|
return 0;
|
|
38
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Where the replay of earlier sessions stands, when there has been one.
|
|
46
|
+
*
|
|
47
|
+
* @param context - Resolved CLI context.
|
|
48
|
+
*/
|
|
49
|
+
async function reportReplay(context) {
|
|
50
|
+
const record = await readReplayRecord(replayStateFile(identityPaths(context.paths, identityOf(context.identityConfig)).statsFile));
|
|
51
|
+
if (!record)
|
|
52
|
+
return;
|
|
53
|
+
println();
|
|
54
|
+
println(bold('Replay'));
|
|
55
|
+
println(`${symbols.ok} ${describeReplay(record, context.env.now().getTime())}`);
|
|
56
|
+
}
|
|
39
57
|
/**
|
|
40
58
|
* Whether a backend is configured.
|
|
41
59
|
*
|
|
@@ -116,8 +134,12 @@ async function reportAgent(provider, context) {
|
|
|
116
134
|
}
|
|
117
135
|
println(`${symbols.ok} detected ${dim(`(${detection.evidence[0] ?? ''})`)}`);
|
|
118
136
|
println(detection.hooksInstalled ? `${symbols.ok} hooks installed` : `${symbols.off} hooks not installed`);
|
|
119
|
-
if (
|
|
137
|
+
if (context.disabled)
|
|
120
138
|
return;
|
|
139
|
+
// The caveats describe what capture misses, so they are said only where capture runs.
|
|
140
|
+
if (detection.hooksInstalled)
|
|
141
|
+
for (const caveat of provider.caveats ?? [])
|
|
142
|
+
println(`${symbols.warn} ${caveat.detail}`);
|
|
121
143
|
const setupContext = {
|
|
122
144
|
env: context.env,
|
|
123
145
|
paths: context.paths,
|
|
@@ -125,6 +147,9 @@ async function reportAgent(provider, context) {
|
|
|
125
147
|
hookCommand: buildHookCommand(context.env, provider.id),
|
|
126
148
|
installState: context.installState
|
|
127
149
|
};
|
|
150
|
+
await reportRunCapture(provider, { ...setupContext, config: context.identityConfig });
|
|
151
|
+
if (!provider.nativeTelemetry)
|
|
152
|
+
return;
|
|
128
153
|
const otel = await provider.nativeTelemetry.inspect(setupContext);
|
|
129
154
|
if (otel.configured) {
|
|
130
155
|
println(`${symbols.ok} native OpenTelemetry ${otel.detail ?? 'configured'}`);
|
|
@@ -132,6 +157,19 @@ async function reportAgent(provider, context) {
|
|
|
132
157
|
}
|
|
133
158
|
println(otel.conflict ? `${symbols.warn} native OpenTelemetry: ${otel.conflict}` : `${symbols.off} native OpenTelemetry not configured`);
|
|
134
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Whether what this agent's shell tool starts has its provider calls captured.
|
|
162
|
+
*
|
|
163
|
+
* @param provider - The agent's provider.
|
|
164
|
+
* @param context - The agent's setup context, under the identity of this directory.
|
|
165
|
+
*/
|
|
166
|
+
async function reportRunCapture(provider, context) {
|
|
167
|
+
const route = runCaptureRoute(provider);
|
|
168
|
+
const capture = route ? await route.inspect(context) : { on: false, reason: 'not available for this agent yet' };
|
|
169
|
+
println(capture.on ? `${symbols.ok} run capture on` : `${symbols.off} run capture off: ${capture.reason ?? 'unknown'}`);
|
|
170
|
+
if (capture.warning)
|
|
171
|
+
println(`${symbols.warn} run capture: ${capture.warning}`);
|
|
172
|
+
}
|
|
135
173
|
/**
|
|
136
174
|
* The backlog, and everything the queue has lost.
|
|
137
175
|
*
|
|
@@ -143,8 +181,7 @@ async function reportAgent(provider, context) {
|
|
|
143
181
|
async function reportDelivery(context) {
|
|
144
182
|
println(bold('Delivery'));
|
|
145
183
|
const queue = await buildQueue(context);
|
|
146
|
-
const deliveryStats =
|
|
147
|
-
const authBlock = buildAuthBlock(context);
|
|
184
|
+
const { stats: deliveryStats, authBlock } = openIdentityDelivery(context);
|
|
148
185
|
const pending = await retryBacklog(context, queue, deliveryStats, authBlock);
|
|
149
186
|
println(pending === 0 ? `${symbols.ok} healthy` : `${symbols.warn} backlog`);
|
|
150
187
|
println(`${pending} pending event(s)`);
|
|
@@ -225,6 +262,9 @@ async function retryBacklog(context, queue, deliveryStats, authBlock) {
|
|
|
225
262
|
function reportLosses(context, stats) {
|
|
226
263
|
if (!stats)
|
|
227
264
|
return;
|
|
265
|
+
if (stats.totalCapturedDropped > 0) {
|
|
266
|
+
println(`${symbols.warn} ${stats.totalCapturedDropped} captured call(s) dropped (no session or run to attach them to, or over the spool's limit)`);
|
|
267
|
+
}
|
|
228
268
|
if (stats.totalRejected > 0) {
|
|
229
269
|
const last = stats.lastRejectedAt ? ` (last ${stats.lastRejectedCount} at ${stats.lastRejectedAt})` : '';
|
|
230
270
|
println(`${symbols.warn} ${stats.totalRejected} event(s) permanently rejected by the backend${last}`);
|
package/dist/cli/toggle.js
CHANGED
|
@@ -65,6 +65,7 @@ export async function runToggle(env, enabled) {
|
|
|
65
65
|
await writeFileAtomic(file, JSON.stringify({ providers: targets }), SECRET_FILE_MODE);
|
|
66
66
|
let installState = context.installState;
|
|
67
67
|
let failures = 0;
|
|
68
|
+
let skipped = 0;
|
|
68
69
|
const restored = [];
|
|
69
70
|
// As setup writes it: the machine's access token, or its install key while it has no device.
|
|
70
71
|
const bearer = enabled ? await nativeExporterBearer({ env, paths: context.paths, timeoutMs: SETUP_EXCHANGE_TIMEOUT_MS }, context.config) : undefined;
|
|
@@ -85,6 +86,13 @@ export async function runToggle(env, enabled) {
|
|
|
85
86
|
restored.push(provider);
|
|
86
87
|
for (const message of outcome.messages)
|
|
87
88
|
println(`${provider.displayName}: ${message}`);
|
|
89
|
+
// The developer's own telemetry config in the way is a skipped step, as
|
|
90
|
+
// in setup. Counting it would keep the marker forever, and setup refuses
|
|
91
|
+
// while it is there.
|
|
92
|
+
if (enabled && outcome.conflict) {
|
|
93
|
+
skipped++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
88
96
|
if (!outcome.ok)
|
|
89
97
|
failures++;
|
|
90
98
|
}
|
|
@@ -110,6 +118,8 @@ export async function runToggle(env, enabled) {
|
|
|
110
118
|
if (enabled && failures === 0)
|
|
111
119
|
await fs.rm(file);
|
|
112
120
|
println(enabled && failures === 0 ? 'AgentWatch enabled.' : 'AgentWatch disabled for hooks and otel-headers.');
|
|
121
|
+
if (enabled && failures === 0 && skipped > 0)
|
|
122
|
+
println(`Native telemetry skipped for ${skipped} agent(s) with their own telemetry config; see above.`);
|
|
113
123
|
println('Restart all running coding agents to apply native telemetry changes; existing processes may retain exporters and credentials.');
|
|
114
124
|
if (failures > 0)
|
|
115
125
|
println('Native telemetry changes are incomplete. Close running agents and retry this command after repair.');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentWatchConfig, ConfigLoadResult } from '../../config/types/config.types.js';
|
|
2
2
|
import type { Env } from '../../core/types/core.types.js';
|
|
3
3
|
import type { GitRunner } from '../../git/types/git.types.js';
|
|
4
|
+
import type { AgentProvider } from '../../providers/types/provider.types.js';
|
|
4
5
|
import type { AgentWatchPaths, InstallState } from '../../storage/types/storage.types.js';
|
|
5
6
|
/** Parsed argv. */
|
|
6
7
|
export interface ParsedArgs {
|
|
@@ -46,6 +47,12 @@ export interface HookRunOptions {
|
|
|
46
47
|
readonly input?: string;
|
|
47
48
|
readonly dryRun?: boolean;
|
|
48
49
|
readonly writeStdout?: (text: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Hands a turn close's payload to a detached `agentwatch hook`; true when
|
|
52
|
+
* it was handed over. Set only by the CLI entry, so tests and the detached
|
|
53
|
+
* child process the payload in place.
|
|
54
|
+
*/
|
|
55
|
+
readonly handOff?: (agentId: string, input: string) => Promise<boolean>;
|
|
49
56
|
}
|
|
50
57
|
export interface SetupOptions {
|
|
51
58
|
readonly env: Env;
|
|
@@ -68,6 +75,8 @@ export interface SetupOptions {
|
|
|
68
75
|
readonly root?: string;
|
|
69
76
|
/** OTLP signal selection: "all", "none" or a comma list of logs,traces,metrics. */
|
|
70
77
|
readonly otel?: string;
|
|
78
|
+
/** The agents `--agent` selected; every registered agent when absent. */
|
|
79
|
+
readonly agents?: readonly AgentProvider[];
|
|
71
80
|
readonly hookCommandFor?: (providerId: string) => string;
|
|
72
81
|
/** Git runner override; tests resolve the identity without a real git. */
|
|
73
82
|
readonly gitRun?: GitRunner;
|
|
@@ -75,6 +84,10 @@ export interface SetupOptions {
|
|
|
75
84
|
readonly noBrowser?: boolean;
|
|
76
85
|
/** `--defer-sign-in`: an MDM run saves the organization and stops; the developer signs in later with `agentwatch setup`. */
|
|
77
86
|
readonly deferSignIn?: boolean;
|
|
87
|
+
/** `--replay-days`, as typed: how far back the background replay of earlier Claude Code sessions reaches. */
|
|
88
|
+
readonly replayDays?: string;
|
|
89
|
+
/** `--no-replay`: do not replay earlier sessions. */
|
|
90
|
+
readonly noReplay?: boolean;
|
|
78
91
|
/** Browser sign-in seams for tests: the gateway, the poll timer and the browser opener. */
|
|
79
92
|
readonly openUrl?: (url: string) => void;
|
|
80
93
|
readonly fetchFn?: typeof fetch;
|
|
@@ -89,7 +102,8 @@ export interface DoctorOptions {
|
|
|
89
102
|
}
|
|
90
103
|
export interface UninstallOptions {
|
|
91
104
|
readonly env: Env;
|
|
92
|
-
|
|
105
|
+
/** The agents `--agent` selected; absent means the whole install, device credential included. */
|
|
106
|
+
readonly agents?: readonly AgentProvider[];
|
|
93
107
|
/** Also delete local config, queue and state. Off by default. */
|
|
94
108
|
readonly purge?: boolean;
|
|
95
109
|
}
|