@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/context.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
-
import { eventsUrl } from '../config/config.js';
|
|
4
3
|
import { loadConfig } from '../config/config-store.js';
|
|
5
4
|
import { resolveBearer } from '../credentials/credentials.js';
|
|
6
|
-
import {
|
|
5
|
+
import { identityOf } from '../credentials/identity.js';
|
|
7
6
|
import { findExecutable } from '../core/which.js';
|
|
8
7
|
import { isDisabled } from '../storage/disabled.js';
|
|
9
8
|
import { loadInstallState } from '../storage/install-state.js';
|
|
10
9
|
import { resolvePaths } from '../storage/paths.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { EventQueue } from '../transport/queue.js';
|
|
15
|
-
import { identityPaths, settleLegacyQueue } from '../transport/queue-partition.js';
|
|
10
|
+
import { transportFor } from '../config/events-transport.js';
|
|
11
|
+
import { identityDelivery } from '../transport/identity-delivery.js';
|
|
12
|
+
import { settleLegacyQueue } from '../transport/queue-partition.js';
|
|
16
13
|
import { applyRootOverride, credentialScope, servesMultipleIdentities } from '../config/root-config.js';
|
|
17
14
|
import { RE_NEEDS_QUOTING, RE_QUOTE_ESCAPE } from './constants/cli.constants.js';
|
|
18
15
|
/**
|
|
@@ -22,20 +19,22 @@ import { RE_NEEDS_QUOTING, RE_QUOTE_ESCAPE } from './constants/cli.constants.js'
|
|
|
22
19
|
* commands then work from this value instead of each reaching for the disk.
|
|
23
20
|
*
|
|
24
21
|
* @param env - Ambient environment.
|
|
22
|
+
* @param identityAt - A root to select explicitly, null for the machine, or the command cwd when omitted.
|
|
25
23
|
* @returns The context.
|
|
26
24
|
*/
|
|
27
|
-
export async function buildCliContext(env) {
|
|
25
|
+
export async function buildCliContext(env, identityAt) {
|
|
28
26
|
const paths = resolvePaths(env);
|
|
29
27
|
const configResult = await loadConfig(paths);
|
|
30
28
|
// Resolved once, here, because every identity-scoped file a command touches is
|
|
31
|
-
// named after the token the *hooks in this directory* use.
|
|
32
|
-
//
|
|
29
|
+
// named after the token the *hooks in this directory* use. An auth block opened
|
|
30
|
+
// under the global token was a per-root block nothing could see or lift: a
|
|
33
31
|
// 401 under a root's own token wrote a block file under that token's
|
|
34
32
|
// fingerprint, `status` read the global one and printed nothing, and `doctor`
|
|
35
33
|
// proved the global credential good and cleared a block that was never the
|
|
36
34
|
// one standing. That root's telemetry stayed suspended with no diagnostic and
|
|
37
35
|
// no remedy, and a block only ends when a re-probe is accepted.
|
|
38
|
-
const
|
|
36
|
+
const { roots: _roots, ...machineConfig } = configResult.config;
|
|
37
|
+
const rooted = identityAt === null ? { config: machineConfig } : applyRootOverride(configResult.config, identityAt ?? env.cwd);
|
|
39
38
|
const scope = credentialScope(rooted.root);
|
|
40
39
|
return {
|
|
41
40
|
env,
|
|
@@ -68,48 +67,26 @@ export async function buildQueue(context) {
|
|
|
68
67
|
// bearers is a fact about the whole file, and which partition this command
|
|
69
68
|
// owns is a fact about where it was run.
|
|
70
69
|
await settleLegacyQueue(context.paths.queueDir, identityOf(context.identityConfig), servesMultipleIdentities(context.config));
|
|
71
|
-
return
|
|
70
|
+
return openIdentityDelivery(context).queue;
|
|
72
71
|
}
|
|
73
72
|
/**
|
|
74
|
-
* Open
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @returns A queue handle; construction performs no filesystem writes.
|
|
78
|
-
*/
|
|
79
|
-
export function openIdentityQueue(context) {
|
|
80
|
-
return new EventQueue({
|
|
81
|
-
queueDir: identityPaths(context.paths, identityOf(context.identityConfig)).queueDir,
|
|
82
|
-
locksDir: context.paths.locksDir,
|
|
83
|
-
maxEvents: context.identityConfig.delivery.maxQueueEvents,
|
|
84
|
-
maxAttempts: context.identityConfig.delivery.maxAttempts,
|
|
85
|
-
maxEventAgeDays: context.identityConfig.delivery.maxEventAgeDays,
|
|
86
|
-
now: context.env.now,
|
|
87
|
-
stats: buildDeliveryStats(context)
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* The delivery-loss tally for this context.
|
|
92
|
-
*
|
|
93
|
-
* @param context - Resolved CLI context.
|
|
94
|
-
* @returns The tally.
|
|
95
|
-
*/
|
|
96
|
-
export function buildDeliveryStats(context) {
|
|
97
|
-
return new DeliveryStats(identityPaths(context.paths, identityOf(context.identityConfig)).statsFile, context.env.now, context.paths.locksDir);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The standing credential refusal for this context.
|
|
73
|
+
* Open this context's identity delivery state (queue partition, loss tally,
|
|
74
|
+
* cooldown, auth block) without adopting or moving legacy records. Setup can
|
|
75
|
+
* inspect ownership and ask for consent without changing the queue.
|
|
101
76
|
*
|
|
102
|
-
* @param context - Resolved
|
|
103
|
-
* @returns The
|
|
77
|
+
* @param context - Resolved identity and storage paths.
|
|
78
|
+
* @returns The handles; construction performs no filesystem writes.
|
|
104
79
|
*/
|
|
105
|
-
export function
|
|
106
|
-
return
|
|
80
|
+
export function openIdentityDelivery(context) {
|
|
81
|
+
return identityDelivery(context.paths, identityOf(context.identityConfig), context.identityConfig.delivery, context.env.now);
|
|
107
82
|
}
|
|
108
83
|
/**
|
|
109
84
|
* The transport for this context, when a backend is configured.
|
|
110
85
|
*
|
|
111
86
|
* @param context - Resolved CLI context.
|
|
112
87
|
* @param timeoutMs - Override for the configured send timeout.
|
|
88
|
+
* @param bearer - What to authenticate with, from `resolveContextBearer`; none
|
|
89
|
+
* while a credential exists makes the transport defer every send.
|
|
113
90
|
* @returns The transport, or undefined before setup has run.
|
|
114
91
|
*/
|
|
115
92
|
export function buildTransport(context, timeoutMs, bearer) {
|
|
@@ -117,17 +94,9 @@ export function buildTransport(context, timeoutMs, bearer) {
|
|
|
117
94
|
// in this directory present and `status` drains the partition they fill. Only
|
|
118
95
|
// that credential can prove itself good, and only that proof may lift the
|
|
119
96
|
// block standing against it.
|
|
120
|
-
|
|
121
|
-
if (!url || context.disabled)
|
|
97
|
+
if (context.disabled)
|
|
122
98
|
return undefined;
|
|
123
|
-
return
|
|
124
|
-
eventsUrl: url,
|
|
125
|
-
capture: context.identityConfig.capture,
|
|
126
|
-
token: bearer,
|
|
127
|
-
credentialPending: hasCredential(context.identityConfig) && !bearer,
|
|
128
|
-
installationId: context.identityConfig.installationId,
|
|
129
|
-
timeoutMs: timeoutMs ?? context.identityConfig.delivery.timeoutMs
|
|
130
|
-
});
|
|
99
|
+
return transportFor(context.identityConfig, bearer, { timeoutMs });
|
|
131
100
|
}
|
|
132
101
|
/**
|
|
133
102
|
* The bearer this directory's hooks send, refreshed or exchanged when due.
|
|
@@ -171,7 +140,7 @@ export function buildHookCommand(env, providerId, scriptPath = process.argv[1])
|
|
|
171
140
|
* @param value - The path.
|
|
172
141
|
* @returns The value, quoted only when it needs to be.
|
|
173
142
|
*/
|
|
174
|
-
function quoteArg(value) {
|
|
143
|
+
export function quoteArg(value) {
|
|
175
144
|
if (!RE_NEEDS_QUOTING.test(value))
|
|
176
145
|
return value;
|
|
177
146
|
return `"${value.replace(RE_QUOTE_ESCAPE, '\\$1')}"`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentProvider, SetupContext } from '../providers/types/provider.types.js';
|
|
2
|
+
import type { Check } from './types/cli.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether one agent's environment route is in place, and what is missing when not.
|
|
5
|
+
*
|
|
6
|
+
* `warn`, never `fail`: unlike the native ledger, the agent's own usage does not depend on
|
|
7
|
+
* it, and an agent with no route yet is not something the developer can fix.
|
|
8
|
+
*
|
|
9
|
+
* @param provider - The agent's provider.
|
|
10
|
+
* @param context - The agent's setup context.
|
|
11
|
+
* @returns The check.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runCaptureCheck(provider: AgentProvider, context: SetupContext): Promise<Check>;
|
|
14
|
+
/**
|
|
15
|
+
* The virtual environments holding Edge's loader for `python -I` runs, so a developer who
|
|
16
|
+
* finds the `.pth` in their venv can see where it came from and that uninstall takes it.
|
|
17
|
+
*
|
|
18
|
+
* @param dataDir - The data dir.
|
|
19
|
+
* @returns The check, or undefined when no venv holds one.
|
|
20
|
+
*/
|
|
21
|
+
export declare function venvLoaderCheck(dataDir: string): Promise<Check | undefined>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { recordedVenvs } from '../capture/venv-loader.js';
|
|
2
|
+
import { runCaptureRoute } from '../providers/provider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether one agent's environment route is in place, and what is missing when not.
|
|
5
|
+
*
|
|
6
|
+
* `warn`, never `fail`: unlike the native ledger, the agent's own usage does not depend on
|
|
7
|
+
* it, and an agent with no route yet is not something the developer can fix.
|
|
8
|
+
*
|
|
9
|
+
* @param provider - The agent's provider.
|
|
10
|
+
* @param context - The agent's setup context.
|
|
11
|
+
* @returns The check.
|
|
12
|
+
*/
|
|
13
|
+
export async function runCaptureCheck(provider, context) {
|
|
14
|
+
const name = `${provider.displayName} run capture`;
|
|
15
|
+
const route = runCaptureRoute(provider);
|
|
16
|
+
const status = route ? await route.inspect(context) : { on: false, reason: 'not available for this agent yet' };
|
|
17
|
+
if (!status.on)
|
|
18
|
+
return { name, level: 'warn', detail: `off: ${status.reason ?? 'unknown'}` };
|
|
19
|
+
return status.warning ? { name, level: 'warn', detail: `on: ${status.warning}` } : { name, level: 'ok', detail: 'on' };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The virtual environments holding Edge's loader for `python -I` runs, so a developer who
|
|
23
|
+
* finds the `.pth` in their venv can see where it came from and that uninstall takes it.
|
|
24
|
+
*
|
|
25
|
+
* @param dataDir - The data dir.
|
|
26
|
+
* @returns The check, or undefined when no venv holds one.
|
|
27
|
+
*/
|
|
28
|
+
export async function venvLoaderCheck(dataDir) {
|
|
29
|
+
const folders = await recordedVenvs(dataDir);
|
|
30
|
+
if (folders.length === 0)
|
|
31
|
+
return undefined;
|
|
32
|
+
return { name: 'Python run capture loaders', level: 'ok', detail: `${folders.length} venv(s), removed by \`agentwatch uninstall\`: ${folders.join(', ')}` };
|
|
33
|
+
}
|
package/dist/cli/doctor.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
2
1
|
import fs from 'node:fs/promises';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import process from 'node:process';
|
|
@@ -10,8 +9,7 @@ import { enabledSignalNames, enforcementUrl, eventsUrl, otlpBaseUrl } from '../c
|
|
|
10
9
|
import { loadEffectiveConfig } from '../config/repo-config.js';
|
|
11
10
|
import { storedRetiredCapture } from '../config/config-store.js';
|
|
12
11
|
import { CONTENT_CAPTURE_KEYS } from '../config/constants/config.constants.js';
|
|
13
|
-
import {
|
|
14
|
-
import { findExecutable } from '../core/which.js';
|
|
12
|
+
import { execVersion } from '../core/version.js';
|
|
15
13
|
import { developerDisplayName, developerIdentity } from '../git/git-context.js';
|
|
16
14
|
import { providers } from '../providers/registry.js';
|
|
17
15
|
import { removeRefusedExporters } from '../providers/shared/exporter-allowlist.js';
|
|
@@ -22,9 +20,10 @@ import { AUTH_REJECTED_STATUSES, CONTENT_TYPE_HEADER, JSON_CONTENT_TYPE } from '
|
|
|
22
20
|
import { discardResponseBody } from '../transport/response-body.js';
|
|
23
21
|
import { edgeHeaders } from '../transport/headers.js';
|
|
24
22
|
import { DEVICE_SOURCE_BATCH_CODE } from '../credentials/constants/credentials.constants.js';
|
|
25
|
-
import {
|
|
23
|
+
import { buildCliContext, buildHookCommand, buildQueue, openIdentityDelivery, resolveContextBearer } from './context.js';
|
|
24
|
+
import { runCaptureCheck, venvLoaderCheck } from './doctor-run-capture.js';
|
|
26
25
|
import { installedHookChecks } from './hook-check.js';
|
|
27
|
-
import { BACKEND_CONNECTIVITY_CHECK, BACKEND_PROBE_TIMEOUT_MS, EMPTY_BATCH_REFUSED_STATUS,
|
|
26
|
+
import { BACKEND_CONNECTIVITY_CHECK, BACKEND_PROBE_TIMEOUT_MS, EMPTY_BATCH_REFUSED_STATUS, DEVELOPER_IDENTITY_CHECK, DEVELOPER_IDENTITY_REMEDIES, DEVELOPER_NAME_REMEDIES, GIT_VERSION_TIMEOUT_MS, MIN_NODE_MAJOR, NO_DEVELOPER_IDENTITY, NO_DEVELOPER_NAME, STALE_QUEUE_AGE_MS } from './constants/cli.constants.js';
|
|
28
27
|
import { bold, customEndpointOverride, dim, levelSymbol, println } from './ui.js';
|
|
29
28
|
/**
|
|
30
29
|
* `agentwatch doctor` — every reason telemetry might not be arriving, in one
|
|
@@ -385,13 +384,13 @@ async function probeBackend(url, context) {
|
|
|
385
384
|
});
|
|
386
385
|
discardResponseBody(response);
|
|
387
386
|
if (response.ok) {
|
|
388
|
-
await
|
|
387
|
+
await openIdentityDelivery(context).authBlock.clear();
|
|
389
388
|
return { name, level: 'ok', detail: `${url} -> HTTP ${response.status}` };
|
|
390
389
|
}
|
|
391
390
|
// The gateway authenticates before it validates the body, and answers an
|
|
392
391
|
// empty batch 422: the credential passed, only the probe's payload did not.
|
|
393
392
|
if (response.status === EMPTY_BATCH_REFUSED_STATUS) {
|
|
394
|
-
await
|
|
393
|
+
await openIdentityDelivery(context).authBlock.clear();
|
|
395
394
|
return { name, level: 'ok', detail: `${url} -> HTTP ${response.status}: credential accepted (the empty probe batch is refused by design)` };
|
|
396
395
|
}
|
|
397
396
|
if (AUTH_REJECTED_STATUSES.has(response.status)) {
|
|
@@ -413,7 +412,7 @@ async function gitCheck() {
|
|
|
413
412
|
return { name: 'git available', level: version ? 'ok' : 'warn', detail: version?.trim() ?? 'git not found on PATH' };
|
|
414
413
|
}
|
|
415
414
|
/**
|
|
416
|
-
* Per-agent checks: detected, hooked, and
|
|
415
|
+
* Per-agent checks: detected, hooked, exporting telemetry, and loading run capture.
|
|
417
416
|
*
|
|
418
417
|
* @param env - Ambient environment.
|
|
419
418
|
* @param context - Resolved CLI context.
|
|
@@ -421,15 +420,16 @@ async function gitCheck() {
|
|
|
421
420
|
*/
|
|
422
421
|
async function agentChecks(env, context) {
|
|
423
422
|
const checks = [];
|
|
423
|
+
const probes = new Map();
|
|
424
424
|
for (const provider of providers) {
|
|
425
425
|
const detection = await provider.detect(env);
|
|
426
|
-
checks.push(...(await installedHookChecks(detection.hookConfigPath, env)).map((check) => ({ ...check, name: `${provider.displayName} ${check.name}` })));
|
|
426
|
+
checks.push(...(await installedHookChecks(detection.hookConfigPath, env, probes)).map((check) => ({ ...check, name: `${provider.displayName} ${check.name}` })));
|
|
427
427
|
if (!detection.detected) {
|
|
428
428
|
checks.push({ name: provider.displayName, level: 'warn', detail: 'not detected' });
|
|
429
429
|
continue;
|
|
430
430
|
}
|
|
431
431
|
checks.push({ name: `${provider.displayName} detected`, level: 'ok', detail: detection.evidence.join('; ') });
|
|
432
|
-
checks.push(...(await
|
|
432
|
+
checks.push(...(await providerChecks(provider, env)));
|
|
433
433
|
checks.push({
|
|
434
434
|
name: `${provider.displayName} hooks`,
|
|
435
435
|
level: detection.hooksInstalled ? 'ok' : 'warn',
|
|
@@ -437,61 +437,27 @@ async function agentChecks(env, context) {
|
|
|
437
437
|
});
|
|
438
438
|
if (provider.nativeTelemetry && !context.disabled)
|
|
439
439
|
checks.push(await otelCheck(provider, env, context));
|
|
440
|
+
if (!context.disabled)
|
|
441
|
+
checks.push(await runCaptureCheck(provider, { env, paths: context.paths, config: context.identityConfig, hookCommand: buildHookCommand(env, provider.id), installState: context.installState }));
|
|
440
442
|
}
|
|
443
|
+
const loaders = await venvLoaderCheck(context.paths.dataDir);
|
|
444
|
+
if (loaders)
|
|
445
|
+
checks.push(loaders);
|
|
441
446
|
return checks;
|
|
442
447
|
}
|
|
443
448
|
/**
|
|
444
|
-
*
|
|
449
|
+
* What the agent checks about itself, then its known limitations as warnings.
|
|
445
450
|
*
|
|
446
|
-
*
|
|
451
|
+
* Caveats are not misconfigurations the developer can fix; they exist so an
|
|
447
452
|
* absent number is explained rather than mistaken for a bug in the edge.
|
|
448
453
|
*
|
|
449
454
|
* @param provider - The agent's provider.
|
|
450
455
|
* @param env - Ambient environment.
|
|
451
|
-
* @returns The checks, empty for
|
|
456
|
+
* @returns The checks, empty for an agent with neither.
|
|
452
457
|
*/
|
|
453
|
-
async function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (provider.id !== 'cursor')
|
|
457
|
-
return [];
|
|
458
|
-
return [
|
|
459
|
-
{
|
|
460
|
-
name: 'Cursor token usage',
|
|
461
|
-
level: 'warn',
|
|
462
|
-
detail: 'Cursor transcripts carry no token usage yet — Cursor turn summaries stay usage_status=pending until Cursor enriches them'
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
name: 'Cursor CLI hooks',
|
|
466
|
-
level: 'warn',
|
|
467
|
-
detail: 'cursor-agent (CLI) currently emits only shell hook events (known Cursor issue); IDE sessions are fully covered'
|
|
468
|
-
}
|
|
469
|
-
];
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Whether Claude Code is new enough for prompt-id turn correlation.
|
|
473
|
-
*
|
|
474
|
-
* @param env - Ambient environment.
|
|
475
|
-
* @returns The check.
|
|
476
|
-
*/
|
|
477
|
-
async function claudeVersionCheck(env) {
|
|
478
|
-
const name = 'Claude Code version';
|
|
479
|
-
const bin = findExecutable(env, 'claude');
|
|
480
|
-
if (!bin) {
|
|
481
|
-
return { name, level: 'warn', detail: `claude not on PATH; cannot verify >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} (needed for turn correlation)` };
|
|
482
|
-
}
|
|
483
|
-
const output = await execVersion(bin, ['--version'], CLAUDE_VERSION_TIMEOUT_MS);
|
|
484
|
-
const version = output ? parseVersion(output) : undefined;
|
|
485
|
-
if (!version) {
|
|
486
|
-
return { name, level: 'warn', detail: `could not determine version (need >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} for turn correlation)` };
|
|
487
|
-
}
|
|
488
|
-
if (meetsMinVersion(version, CLAUDE_MIN_VERSION_FOR_PROMPT_ID))
|
|
489
|
-
return { name, level: 'ok', detail: version };
|
|
490
|
-
return {
|
|
491
|
-
name,
|
|
492
|
-
level: 'warn',
|
|
493
|
-
detail: `${version} — prompt_id turn correlation needs >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID}; turn_id will be empty`
|
|
494
|
-
};
|
|
458
|
+
async function providerChecks(provider, env) {
|
|
459
|
+
const caveats = (provider.caveats ?? []).map(({ name, detail }) => ({ name, level: 'warn', detail }));
|
|
460
|
+
return [...((await provider.checks?.(env)) ?? []), ...caveats];
|
|
495
461
|
}
|
|
496
462
|
/**
|
|
497
463
|
* Whether one agent's native telemetry is configured.
|
|
@@ -680,19 +646,6 @@ async function newestMtime(dir) {
|
|
|
680
646
|
}
|
|
681
647
|
return newest;
|
|
682
648
|
}
|
|
683
|
-
/**
|
|
684
|
-
* Run a `--version`-style command, treating any failure as no answer.
|
|
685
|
-
*
|
|
686
|
-
* @param command - Executable.
|
|
687
|
-
* @param args - Its arguments.
|
|
688
|
-
* @param timeoutMs - Kill budget.
|
|
689
|
-
* @returns Its stdout, or undefined.
|
|
690
|
-
*/
|
|
691
|
-
function execVersion(command, args, timeoutMs) {
|
|
692
|
-
return new Promise((resolve) => {
|
|
693
|
-
execFile(command, [...args], { timeout: timeoutMs }, (error, stdout) => resolve(error ? undefined : stdout));
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
649
|
/**
|
|
697
650
|
* The process exit code for a set of checks.
|
|
698
651
|
*
|
package/dist/cli/hook-check.d.ts
CHANGED
|
@@ -9,15 +9,20 @@ import type { Check } from './types/cli.types.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @param file - User hook configuration path.
|
|
11
11
|
* @param env - Launch environment to validate.
|
|
12
|
+
* @param probes - Version probes already run, shared across one doctor run:
|
|
13
|
+
* every agent's hook runs the same CLI, so it is probed once.
|
|
12
14
|
* @returns A finding for every distinct managed command.
|
|
13
15
|
*/
|
|
14
|
-
export declare function installedHookChecks(file: string, env: Env): Promise<Check[]>;
|
|
16
|
+
export declare function installedHookChecks(file: string, env: Env, probes?: Map<string, Promise<ProbeResult>>): Promise<Check[]>;
|
|
15
17
|
/**
|
|
16
18
|
* Validate a recognized hook without invoking a shell or an unknown installation.
|
|
17
19
|
* @param command - Command from a user-scoped hook file.
|
|
18
20
|
* @param env - Coding agent launch environment.
|
|
19
21
|
* @param currentCli - Trusted running CLI, injectable for isolated tests.
|
|
20
22
|
* @param timeoutMs - Maximum version probe duration.
|
|
23
|
+
* @param probes - Version probes already run, by runtime and CLI.
|
|
21
24
|
* @returns A diagnostic without command output or credential values.
|
|
22
25
|
*/
|
|
23
|
-
export declare function checkHookCommand(command: string, env: Env, currentCli?: string, timeoutMs?: number): Promise<Check>;
|
|
26
|
+
export declare function checkHookCommand(command: string, env: Env, currentCli?: string, timeoutMs?: number, probes?: Map<string, Promise<ProbeResult>>): Promise<Check>;
|
|
27
|
+
/** What a `--version` probe of the installed CLI came back with. */
|
|
28
|
+
export type ProbeResult = 'ok' | 'failed' | 'timeout';
|
package/dist/cli/hook-check.js
CHANGED
|
@@ -6,8 +6,8 @@ import { asRecord } from '../core/object.js';
|
|
|
6
6
|
import { findExecutable } from '../core/which.js';
|
|
7
7
|
import { isAgentWatchHookCommand, tokenizeHookCommand } from '../providers/provider.js';
|
|
8
8
|
import { readJsonFile } from '../storage/json-file.js';
|
|
9
|
+
import { HOOK_VERSION_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
9
10
|
const CLI_PATH = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
10
|
-
const VERSION_TIMEOUT_MS = 1500;
|
|
11
11
|
const VERSION_MANAGER_PATH = /(?:\.nvm|\.fnm|fnm_multishells|\.asdf|\.volta)[/\\]/;
|
|
12
12
|
const NODE_NAME = /^node(?:[\d.]*|js)?(?:\.exe)?$/;
|
|
13
13
|
const VERSION_OUTPUT = /^\d+\.\d+\.\d+(?:[-+][\w.-]+)?\s*$/;
|
|
@@ -21,14 +21,16 @@ const REMEDY = 'Install Node.js 20+ on the coding agent launch PATH, reinstall @
|
|
|
21
21
|
*
|
|
22
22
|
* @param file - User hook configuration path.
|
|
23
23
|
* @param env - Launch environment to validate.
|
|
24
|
+
* @param probes - Version probes already run, shared across one doctor run:
|
|
25
|
+
* every agent's hook runs the same CLI, so it is probed once.
|
|
24
26
|
* @returns A finding for every distinct managed command.
|
|
25
27
|
*/
|
|
26
|
-
export async function installedHookChecks(file, env) {
|
|
28
|
+
export async function installedHookChecks(file, env, probes = new Map()) {
|
|
27
29
|
const read = await readJsonFile(file);
|
|
28
30
|
if (read.state !== 'ok')
|
|
29
31
|
return [];
|
|
30
32
|
const commands = new Set(collectCommands(read.value));
|
|
31
|
-
return Promise.all([...commands].map((command) => checkHookCommand(command, env)));
|
|
33
|
+
return Promise.all([...commands].map((command) => checkHookCommand(command, env, CLI_PATH, HOOK_VERSION_TIMEOUT_MS, probes)));
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Validate a recognized hook without invoking a shell or an unknown installation.
|
|
@@ -36,9 +38,10 @@ export async function installedHookChecks(file, env) {
|
|
|
36
38
|
* @param env - Coding agent launch environment.
|
|
37
39
|
* @param currentCli - Trusted running CLI, injectable for isolated tests.
|
|
38
40
|
* @param timeoutMs - Maximum version probe duration.
|
|
41
|
+
* @param probes - Version probes already run, by runtime and CLI.
|
|
39
42
|
* @returns A diagnostic without command output or credential values.
|
|
40
43
|
*/
|
|
41
|
-
export async function checkHookCommand(command, env, currentCli = CLI_PATH, timeoutMs =
|
|
44
|
+
export async function checkHookCommand(command, env, currentCli = CLI_PATH, timeoutMs = HOOK_VERSION_TIMEOUT_MS, probes = new Map()) {
|
|
42
45
|
const name = 'installed hook command';
|
|
43
46
|
const fail = (detail) => ({ name, level: 'fail', detail: `${detail}. ${REMEDY}` });
|
|
44
47
|
if (!isAgentWatchHookCommand(command))
|
|
@@ -67,17 +70,14 @@ export async function checkHookCommand(command, env, currentCli = CLI_PATH, time
|
|
|
67
70
|
if (prefix.length === 2 && !NODE_NAME.test(path.basename(runtime)))
|
|
68
71
|
return fail('Unsupported runtime; version probe skipped');
|
|
69
72
|
// Only our verified CLI runs; the original shell command is never executed.
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
if (!ok)
|
|
80
|
-
return fail('Hook --version failed or timed out');
|
|
73
|
+
const key = `${runtime}\0${actual}`;
|
|
74
|
+
const probe = probes.get(key) ?? probeVersion(runtime, actual, env, timeoutMs);
|
|
75
|
+
probes.set(key, probe);
|
|
76
|
+
const result = await probe;
|
|
77
|
+
if (result === 'timeout')
|
|
78
|
+
return fail(`Hook --version did not answer within ${timeoutMs / 1000} s`);
|
|
79
|
+
if (result === 'failed')
|
|
80
|
+
return fail('Hook --version failed');
|
|
81
81
|
const versionManaged = VERSION_MANAGER_PATH.test(executable);
|
|
82
82
|
return {
|
|
83
83
|
name,
|
|
@@ -87,6 +87,21 @@ export async function checkHookCommand(command, env, currentCli = CLI_PATH, time
|
|
|
87
87
|
: 'CLI and Node.js resolve; bounded --version passed. Repeat doctor with the GUI agent launch PATH if it differs.'
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
function probeVersion(runtime, cli, env, timeoutMs) {
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
execFile(runtime, [cli, '--version'], {
|
|
93
|
+
timeout: timeoutMs,
|
|
94
|
+
killSignal: 'SIGKILL',
|
|
95
|
+
maxBuffer: 4096,
|
|
96
|
+
cwd: env.home,
|
|
97
|
+
env: { PATH: env.vars['PATH'] ?? '', HOME: env.home }
|
|
98
|
+
}, (error, stdout) => {
|
|
99
|
+
if (error?.killed)
|
|
100
|
+
return resolve('timeout');
|
|
101
|
+
resolve(!error && VERSION_OUTPUT.test(stdout) ? 'ok' : 'failed');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
90
105
|
function collectCommands(value) {
|
|
91
106
|
if (Array.isArray(value))
|
|
92
107
|
return value.flatMap(collectCommands);
|
package/dist/cli/hook.d.ts
CHANGED
|
@@ -18,3 +18,17 @@ export type { HookRunOptions } from './types/cli.types.js';
|
|
|
18
18
|
* @returns The process exit code; always one the agent tolerates.
|
|
19
19
|
*/
|
|
20
20
|
export declare function runHook(agentId: string, options: HookRunOptions): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Start `agentwatch hook --agent <id> --attached` detached, with the payload on
|
|
23
|
+
* its stdin, so it outlives this process and the agent that started it.
|
|
24
|
+
*
|
|
25
|
+
* Only from the built CLI: run from source there is nothing to start, and the
|
|
26
|
+
* caller processes the payload in place. A spawn or pipe that fails does the
|
|
27
|
+
* same; at worst the turn is processed twice, and its summary id is derived
|
|
28
|
+
* from its inputs, so the second copy is a duplicate the backend drops.
|
|
29
|
+
*
|
|
30
|
+
* @param agentId - Value of `--agent`.
|
|
31
|
+
* @param input - The payload, as JSON text.
|
|
32
|
+
* @returns True when the child took the payload.
|
|
33
|
+
*/
|
|
34
|
+
export declare function handOffDetached(agentId: string, input: string): Promise<boolean>;
|
package/dist/cli/hook.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
1
3
|
import path from 'node:path';
|
|
2
4
|
import process from 'node:process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
3
6
|
import { loadConfig } from '../config/config-store.js';
|
|
4
7
|
import { notLongerThan } from '../core/async.js';
|
|
5
8
|
import { debugLog, warnLog } from '../core/logger.js';
|
|
@@ -10,6 +13,7 @@ import { isDisabled } from '../storage/disabled.js';
|
|
|
10
13
|
import { loadInstallState, saveInstallState } from '../storage/install-state.js';
|
|
11
14
|
import { resolvePaths } from '../storage/paths.js';
|
|
12
15
|
import { claimSweep } from '../storage/sweep-marker.js';
|
|
16
|
+
import { TurnStateStore } from '../turns/turn-state.js';
|
|
13
17
|
import { EXPORTER_SWEEP_BUDGET_MS, EXPORTER_SWEEP_INTERVAL_MS, EXPORTER_SWEEP_MARKER_FILE, MAX_STDIN_BYTES, STDIN_TIMEOUT_MS } from './constants/cli.constants.js';
|
|
14
18
|
/**
|
|
15
19
|
* The `hook` command: read stdin, run the flow, answer the agent.
|
|
@@ -34,9 +38,15 @@ export async function runHook(agentId, options) {
|
|
|
34
38
|
warnLog(`unknown agent "${agentId}"; passing through`);
|
|
35
39
|
return 0;
|
|
36
40
|
}
|
|
37
|
-
const
|
|
41
|
+
const paths = resolvePaths(options.env);
|
|
42
|
+
const disabled = await isDisabled(paths);
|
|
38
43
|
const payload = await readPayload(options);
|
|
44
|
+
const store = new TurnStateStore(paths.turnsDir);
|
|
45
|
+
// The session whose turn close this payload makes, when a detached process does it.
|
|
46
|
+
let closing;
|
|
47
|
+
let handedOff = false;
|
|
39
48
|
try {
|
|
49
|
+
closing = payload === undefined ? undefined : provider.detachedSession?.(payload, options.env);
|
|
40
50
|
// Disabled: answer the agent and do nothing else. The payload is read but
|
|
41
51
|
// never parsed, enriched, queued or sent — it is read because the answer
|
|
42
52
|
// depends on which hook fired. Antigravity's Stop wants `stop`, its PreToolUse
|
|
@@ -52,6 +62,11 @@ export async function runHook(agentId, options) {
|
|
|
52
62
|
writeStdout(options, idle.stdout);
|
|
53
63
|
return idle.exitCode;
|
|
54
64
|
}
|
|
65
|
+
// A turn's close answers nothing, so the agent need not wait for its send:
|
|
66
|
+
// a detached process does the work and outlives this one.
|
|
67
|
+
handedOff = closing !== undefined && options.handOff !== undefined && (await handOffClose(agentId, store, closing, payload, options.handOff));
|
|
68
|
+
if (handedOff)
|
|
69
|
+
return provider.getHookResponse(payload).exitCode;
|
|
55
70
|
const result = payload === undefined ? undefined : await processPayload(provider, payload, options);
|
|
56
71
|
const response = respondToDecision(provider, payload, result);
|
|
57
72
|
if (response.stdout)
|
|
@@ -66,6 +81,72 @@ export async function runHook(agentId, options) {
|
|
|
66
81
|
debugLog('hook processing failed:', error);
|
|
67
82
|
return answerSafely(provider, payload, options);
|
|
68
83
|
}
|
|
84
|
+
finally {
|
|
85
|
+
// Whoever runs a close (the detached child, or this process when the hand-off
|
|
86
|
+
// failed) finishes it on every path, a disabled machine and a failed flow
|
|
87
|
+
// included: takes its marker away, and clears the session when its
|
|
88
|
+
// `SessionEnd` came meanwhile. A dry run touches no state.
|
|
89
|
+
if (closing !== undefined && !handedOff && !options.dryRun)
|
|
90
|
+
await store.finishClosing(closing, JSON.stringify(payload)).catch((error) => debugLog('could not finish the turn close:', error));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Mark a turn close pending, then hand it to a detached process.
|
|
95
|
+
*
|
|
96
|
+
* The mark comes first: a `SessionEnd` right behind the Stop (`/exit`, a
|
|
97
|
+
* scripted run) would otherwise clear the records the close still has to read,
|
|
98
|
+
* and the turn would be lost. Unmarked, nothing is handed off.
|
|
99
|
+
*
|
|
100
|
+
* @param agentId - Value of `--agent`, for the detached child.
|
|
101
|
+
* @param store - Turn state of this machine.
|
|
102
|
+
* @param sessionId - The session whose turn closes.
|
|
103
|
+
* @param payload - Decoded hook payload.
|
|
104
|
+
* @param handOff - Starts the detached child.
|
|
105
|
+
* @returns True when the child took the payload.
|
|
106
|
+
*/
|
|
107
|
+
async function handOffClose(agentId, store, sessionId, payload, handOff) {
|
|
108
|
+
const input = JSON.stringify(payload);
|
|
109
|
+
try {
|
|
110
|
+
await store.markClosing(sessionId, input);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
debugLog('could not mark the turn close pending; processing in place:', error);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
// A hand-off that throws took nothing: the close runs here, and finishes its marker.
|
|
117
|
+
return handOff(agentId, input).catch(() => false);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Start `agentwatch hook --agent <id> --attached` detached, with the payload on
|
|
121
|
+
* its stdin, so it outlives this process and the agent that started it.
|
|
122
|
+
*
|
|
123
|
+
* Only from the built CLI: run from source there is nothing to start, and the
|
|
124
|
+
* caller processes the payload in place. A spawn or pipe that fails does the
|
|
125
|
+
* same; at worst the turn is processed twice, and its summary id is derived
|
|
126
|
+
* from its inputs, so the second copy is a duplicate the backend drops.
|
|
127
|
+
*
|
|
128
|
+
* @param agentId - Value of `--agent`.
|
|
129
|
+
* @param input - The payload, as JSON text.
|
|
130
|
+
* @returns True when the child took the payload.
|
|
131
|
+
*/
|
|
132
|
+
export function handOffDetached(agentId, input) {
|
|
133
|
+
const cli = fileURLToPath(new URL('../cli.js', import.meta.url));
|
|
134
|
+
if (!fs.existsSync(cli))
|
|
135
|
+
return Promise.resolve(false);
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
try {
|
|
138
|
+
const child = spawn(process.execPath, [cli, 'hook', '--agent', agentId, '--attached'], { detached: true, stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true });
|
|
139
|
+
child.on('error', () => resolve(false));
|
|
140
|
+
child.stdin.on('error', () => resolve(false));
|
|
141
|
+
// The callback carries a pipe error (EPIPE from a child that died at start): then it did not take the payload.
|
|
142
|
+
child.stdin.end(input, (error) => resolve(!error));
|
|
143
|
+
child.unref();
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
debugLog('hook hand-off failed; processing in place:', error);
|
|
147
|
+
resolve(false);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
69
150
|
}
|
|
70
151
|
/**
|
|
71
152
|
* Last-resort answer after something in the flow threw.
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export type { Check, CheckLevel, CliContext, HookRunOptions, ParsedArgs, SetupOptions, UninstallOptions } from './types/cli.types.js';
|
|
6
6
|
export { boolFlag, parseArgs, stringFlag } from './args.js';
|
|
7
|
-
export { buildCliContext,
|
|
7
|
+
export { buildCliContext, buildHookCommand, buildQueue, buildTransport, openIdentityDelivery } from './context.js';
|
|
8
8
|
export { runHook } from './hook.js';
|
|
9
9
|
export { runSetup } from './setup.js';
|
|
10
10
|
export { runStatus } from './status.js';
|
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { boolFlag, parseArgs, stringFlag } from './args.js';
|
|
2
|
-
export { buildCliContext,
|
|
2
|
+
export { buildCliContext, buildHookCommand, buildQueue, buildTransport, openIdentityDelivery } from './context.js';
|
|
3
3
|
export { runHook } from './hook.js';
|
|
4
4
|
export { runSetup } from './setup.js';
|
|
5
5
|
export { runStatus } from './status.js';
|