@agent-watch-ai/edge 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +219 -9
- package/README.md +303 -4
- 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 +3 -2
- package/dist/billing/session-billing.js +8 -8
- 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 +479 -0
- package/dist/capture/constants/capture.constants.d.ts +70 -0
- package/dist/capture/constants/capture.constants.js +72 -0
- package/dist/capture/launched-runs.d.ts +16 -0
- package/dist/capture/launched-runs.js +151 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +823 -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/cli/constants/cli.constants.d.ts +2 -6
- package/dist/cli/constants/cli.constants.js +3 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +13 -0
- package/dist/cli/doctor-run-capture.js +19 -0
- package/dist/cli/doctor.js +16 -67
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +40 -0
- 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/replay.d.ts +33 -0
- package/dist/cli/replay.js +193 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +154 -26
- 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 +8 -22
- package/dist/cli.js +104 -17
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.js +2 -0
- 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 +13 -0
- package/dist/config/schemas/config.schema.js +42 -6
- 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 +32 -0
- package/dist/credentials/cloud-claim.js +42 -0
- package/dist/credentials/constants/credentials.constants.d.ts +8 -1
- package/dist/credentials/constants/credentials.constants.js +9 -2
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -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/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -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 +31 -11
- package/dist/git/constants/git.constants.js +36 -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 +47 -9
- package/dist/git/types/snapshot.types.d.ts +2 -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 +81 -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 +17 -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 +29 -0
- package/dist/replay/checkout-resolver.js +69 -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 +58 -0
- package/dist/replay/replay-runner.js +529 -0
- package/dist/replay/replay-scan.d.ts +83 -0
- package/dist/replay/replay-scan.js +170 -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 +35 -0
- package/dist/replay/throttle.js +41 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +215 -0
- package/dist/replay/turn-event.d.ts +38 -0
- package/dist/replay/turn-event.js +116 -0
- package/dist/replay/types/replay.types.d.ts +162 -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/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 +89 -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 +20 -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 +13 -12
- package/dist/turns/constants/turns.constants.js +15 -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 +49 -7
- package/dist/turns/turn-state.js +78 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +162 -86
- 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 +193 -7
- package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
- 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
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { copiedShims, inspectCaptureEnv, installedCaptureEnv, removeCaptureCopy, shimPaths, withoutCaptureEnv } from '../../capture/capture-env.js';
|
|
2
3
|
import { asRecord, omitKeys } from '../../core/object.js';
|
|
3
4
|
import { enabledSignalNames, otelEnabled, otlpBaseUrl } from '../../config/config.js';
|
|
5
|
+
import { isAgentWatchEndpoint } from '../../config/schemas/config.schema.js';
|
|
4
6
|
import { backupFile } from '../../storage/atomic-file.js';
|
|
5
7
|
import { hasCredential } from '../../credentials/identity.js';
|
|
6
8
|
import { readJsonFile } from '../../storage/json-file.js';
|
|
7
9
|
import { writeJsonValidated } from '../shared/hook-config.js';
|
|
8
|
-
import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
|
|
10
|
+
import { foldPriorValues, otelPriorValuesOf, parsePriorValue, withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
|
|
9
11
|
import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
|
|
10
12
|
import { claudeSettingsPath } from './claude.detect.js';
|
|
11
13
|
import { CLAUDE_PROVIDER_ID } from './constants/claude.constants.js';
|
|
12
|
-
import { ENV_BLOCK_KEY, HEADERS_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_ENDPOINT_KEY, OTLP_PROTOCOL, OTLP_SIGNAL_ENDPOINT_KEYS, RE_HOOK_SUFFIX } from './constants/claude.otel.constants.js';
|
|
13
|
-
/**
|
|
14
|
-
* Claude's own content-logging switches, forced off.
|
|
15
|
-
*
|
|
16
|
-
* Never treated as a foreign key: a user who set `OTEL_LOG_USER_PROMPTS=1`
|
|
17
|
-
* before installing is exactly the case this exists to override, and refusing
|
|
18
|
-
* to configure them would leave prompt logging on *and* drop the llm.call
|
|
19
|
-
* ledger. Overriding a switch that only ever reduces what leaves the machine
|
|
20
|
-
* is not the redirection the conflict check protects against.
|
|
21
|
-
*/
|
|
22
|
-
const CONTENT_LOG_OFF = {
|
|
23
|
-
OTEL_LOG_USER_PROMPTS: '0',
|
|
24
|
-
OTEL_LOG_TOOL_DETAILS: '0',
|
|
25
|
-
OTEL_LOG_TOOL_CONTENT: '0'
|
|
26
|
-
};
|
|
14
|
+
import { AGENTWATCH_ENV_VALUES, CONTENT_LOG_OFF, ENV_BLOCK_KEY, HEADERS_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_ENDPOINT_KEY, OTLP_PROTOCOL, OTEL_SHARED_KEYS, OTLP_SIGNAL_ENDPOINT_KEYS, OTLP_SIGNAL_EXPORTER_KEYS, KEPT_REASON_MESSAGES, RE_HOOK_SUFFIX, SIGNAL_EXPORTER_EXTRA_KEYS, TRACES_BETA_KEY } from './constants/claude.otel.constants.js';
|
|
27
15
|
/**
|
|
28
16
|
* The telemetry environment AgentWatch wants in Claude Code's settings.
|
|
29
17
|
*
|
|
@@ -53,7 +41,7 @@ function desiredClaudeOtelEnv(context) {
|
|
|
53
41
|
OTEL_EXPORTER_OTLP_PROTOCOL: OTLP_PROTOCOL,
|
|
54
42
|
[OTLP_ENDPOINT_KEY]: otlpBase,
|
|
55
43
|
// The beta flag only adds the llm_request spans; it stays tied to traces.
|
|
56
|
-
...(signals.traces ? {
|
|
44
|
+
...(signals.traces ? { [TRACES_BETA_KEY]: '1' } : {})
|
|
57
45
|
};
|
|
58
46
|
}
|
|
59
47
|
/**
|
|
@@ -119,6 +107,24 @@ function headersHelperCommand(hookCommand) {
|
|
|
119
107
|
* ledger comes from.
|
|
120
108
|
*/
|
|
121
109
|
export class ClaudeOtelConfigurator {
|
|
110
|
+
captureSource;
|
|
111
|
+
/**
|
|
112
|
+
* Bind to the shims setup copies.
|
|
113
|
+
*
|
|
114
|
+
* @param captureSource - The package's shims; tests name their own.
|
|
115
|
+
*/
|
|
116
|
+
constructor(captureSource = shimPaths()) {
|
|
117
|
+
this.captureSource = captureSource;
|
|
118
|
+
}
|
|
119
|
+
/** Run capture rides in the same env block, and comes and goes with the exporters. */
|
|
120
|
+
runCapture = {
|
|
121
|
+
configPath: claudeSettingsPath,
|
|
122
|
+
inspect: async (context) => {
|
|
123
|
+
const read = await readJsonFile(claudeSettingsPath(context.env));
|
|
124
|
+
const block = asRecord(read.state === 'ok' ? asRecord(read.value)?.[ENV_BLOCK_KEY] : undefined) ?? {};
|
|
125
|
+
return inspectCaptureEnv(block, context.config, otelEnabled(context.config), context.paths.dataDir, this.captureSource);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
122
128
|
/**
|
|
123
129
|
* Whether this agent can export native telemetry at all.
|
|
124
130
|
*
|
|
@@ -154,7 +160,7 @@ export class ClaudeOtelConfigurator {
|
|
|
154
160
|
if (Object.entries(desired).every(([key, value]) => envBlock[key] === value)) {
|
|
155
161
|
return { supported: true, configured: true };
|
|
156
162
|
}
|
|
157
|
-
const conflicting = foreignKeys(envBlock, desired, ownedKeys);
|
|
163
|
+
const conflicting = foreignKeys(envBlock, desired, ownedKeys, context);
|
|
158
164
|
if (conflicting.length > 0) {
|
|
159
165
|
return { supported: true, configured: false, conflict: `existing telemetry env vars: ${conflicting.join(', ')}` };
|
|
160
166
|
}
|
|
@@ -187,21 +193,25 @@ export class ClaudeOtelConfigurator {
|
|
|
187
193
|
const settings = (read.state === 'ok' ? asRecord(read.value) : undefined) ?? {};
|
|
188
194
|
const envBlock = asRecord(settings[ENV_BLOCK_KEY]) ?? {};
|
|
189
195
|
const ownedKeys = this.ownedKeys(context);
|
|
190
|
-
const conflicting = foreignKeys(envBlock, desired, ownedKeys);
|
|
196
|
+
const conflicting = foreignKeys(envBlock, desired, ownedKeys, context);
|
|
191
197
|
if (conflicting.length > 0) {
|
|
192
198
|
return {
|
|
193
199
|
ok: false,
|
|
194
200
|
changed: false,
|
|
201
|
+
conflict: true,
|
|
195
202
|
messages: [`skipping native OpenTelemetry: ${conflicting.join(', ')} already set in ${settingsPath} (not AgentWatch-owned)`]
|
|
196
203
|
};
|
|
197
204
|
}
|
|
198
205
|
// Signals disabled since the previous run leave stale AgentWatch-owned keys
|
|
199
|
-
// behind — the enhanced-telemetry flag, once traces go off.
|
|
206
|
+
// behind — the enhanced-telemetry flag, once traces go off. A value the
|
|
207
|
+
// developer had there before goes back.
|
|
208
|
+
const previous = otelPriorValuesOf(context.installState, CLAUDE_PROVIDER_ID);
|
|
200
209
|
const stale = new Set(ownedKeys.filter((key) => key !== HEADERS_HELPER_KEY && desired[key] === undefined));
|
|
201
|
-
|
|
210
|
+
// Merged, never recorded as owned: uninstall takes our part of these two, not the keys.
|
|
211
|
+
const withEnv = { ...settings, [ENV_BLOCK_KEY]: { ...withRestored(await installedCaptureEnv(envBlock, context.env.vars, context.paths.dataDir, this.captureSource), stale, restoredEnv(previous, stale)), ...desired } };
|
|
202
212
|
const helper = this.applyHeadersHelper(withEnv, context);
|
|
203
213
|
if ('conflict' in helper) {
|
|
204
|
-
return { ok: false, changed: false, messages: [helper.conflict] };
|
|
214
|
+
return { ok: false, changed: false, conflict: true, messages: [helper.conflict] };
|
|
205
215
|
}
|
|
206
216
|
const changed = JSON.stringify(helper.settings) !== JSON.stringify(settings);
|
|
207
217
|
if (changed) {
|
|
@@ -217,6 +227,7 @@ export class ClaudeOtelConfigurator {
|
|
|
217
227
|
installState: withOtelInstall(context.installState, CLAUDE_PROVIDER_ID, {
|
|
218
228
|
configPath: settingsPath,
|
|
219
229
|
ownedKeys: [...Object.keys(desired), ...helper.ownedExtra],
|
|
230
|
+
priorValues: priorEnvValues(envBlock, desired, ownedKeys, previous, context),
|
|
220
231
|
configuredAt: context.env.now()
|
|
221
232
|
})
|
|
222
233
|
};
|
|
@@ -224,9 +235,11 @@ export class ClaudeOtelConfigurator {
|
|
|
224
235
|
/**
|
|
225
236
|
* Remove the telemetry configuration AgentWatch wrote.
|
|
226
237
|
*
|
|
227
|
-
* Only our own keys go
|
|
228
|
-
*
|
|
229
|
-
*
|
|
238
|
+
* Only our own keys go, and a key the developer had before setup gets its
|
|
239
|
+
* value back. Without a recorded key list, keys holding values AgentWatch
|
|
240
|
+
* writes go only while the base endpoint is an Agent Watch one, and a signal
|
|
241
|
+
* the developer sends to their own collector keeps what it needs. Whatever is
|
|
242
|
+
* left in place for want of proof is named, never dropped silently.
|
|
230
243
|
*
|
|
231
244
|
* @param context - Environment, paths, config and install state.
|
|
232
245
|
* @returns Whether the file changed, what to tell the user, and the next
|
|
@@ -235,25 +248,28 @@ export class ClaudeOtelConfigurator {
|
|
|
235
248
|
async uninstall(context) {
|
|
236
249
|
const settingsPath = claudeSettingsPath(context.env);
|
|
237
250
|
const read = await readJsonFile(settingsPath);
|
|
238
|
-
if (read.state === 'missing')
|
|
251
|
+
if (read.state === 'missing') {
|
|
252
|
+
await removeCaptureCopy(context.paths.dataDir, context.env);
|
|
239
253
|
return { ok: true, changed: false, messages: ['no Claude settings file'] };
|
|
254
|
+
}
|
|
240
255
|
const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
|
|
241
256
|
if (!settings)
|
|
242
257
|
return { ok: false, changed: false, messages: [`cannot parse ${settingsPath}; not modified`] };
|
|
243
|
-
const desired = desiredClaudeOtelEnv(context) ?? {};
|
|
244
|
-
const recorded = this.ownedKeys(context);
|
|
245
258
|
const envBlock = asRecord(settings[ENV_BLOCK_KEY]);
|
|
246
|
-
const removable = removableEnvKeys(envBlock,
|
|
247
|
-
const
|
|
248
|
-
const
|
|
259
|
+
const { removable, kept, reason } = removableEnvKeys(envBlock ?? {}, this.ownedKeys(context), context);
|
|
260
|
+
const restored = restoredEnv(otelPriorValuesOf(context.installState, CLAUDE_PROVIDER_ID), removable);
|
|
261
|
+
const next = strippedSettings(settings, envBlock && withoutCaptureEnv(envBlock, copiedShims(context.paths.dataDir)), restored, removable, isOurHelper(settings[HEADERS_HELPER_KEY]));
|
|
262
|
+
const changed = JSON.stringify(next) !== JSON.stringify(settings);
|
|
263
|
+
const left = keptMessages(kept, reason, settingsPath);
|
|
249
264
|
if (changed) {
|
|
250
265
|
await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
|
|
251
|
-
await writeJsonValidated(settingsPath,
|
|
266
|
+
await writeJsonValidated(settingsPath, next);
|
|
252
267
|
}
|
|
268
|
+
await removeCaptureCopy(context.paths.dataDir, context.env);
|
|
253
269
|
return {
|
|
254
270
|
ok: true,
|
|
255
271
|
changed,
|
|
256
|
-
messages: changed ?
|
|
272
|
+
messages: [changed ? 'native OpenTelemetry configuration removed' : 'no AgentWatch telemetry configuration found', ...left],
|
|
257
273
|
installState: withoutOtelInstall(context.installState, CLAUDE_PROVIDER_ID)
|
|
258
274
|
};
|
|
259
275
|
}
|
|
@@ -290,7 +306,9 @@ export class ClaudeOtelConfigurator {
|
|
|
290
306
|
messages: [
|
|
291
307
|
removed.changed
|
|
292
308
|
? 'native OpenTelemetry disabled in config; previous configuration removed'
|
|
293
|
-
: 'native OpenTelemetry disabled in config (otel: none)'
|
|
309
|
+
: 'native OpenTelemetry disabled in config (otel: none)',
|
|
310
|
+
// Past uninstall's own headline: the keys it left and why.
|
|
311
|
+
...removed.messages.slice(1)
|
|
294
312
|
],
|
|
295
313
|
installState: removed.installState
|
|
296
314
|
};
|
|
@@ -346,55 +364,192 @@ function inspectDisabled(settings, envBlock, ownedKeys) {
|
|
|
346
364
|
* @param envBlock - Current env block.
|
|
347
365
|
* @param desired - What we want to write.
|
|
348
366
|
* @param ownedKeys - Keys a previous setup recorded as ours.
|
|
367
|
+
* @param context - Config, for which endpoints are ours.
|
|
349
368
|
* @returns The conflicting key names.
|
|
350
369
|
*/
|
|
351
|
-
function foreignKeys(envBlock, desired, ownedKeys) {
|
|
370
|
+
function foreignKeys(envBlock, desired, ownedKeys, context) {
|
|
352
371
|
const owned = new Set([...ownedKeys, ...Object.keys(CONTENT_LOG_OFF)]);
|
|
353
|
-
|
|
372
|
+
// An endpoint uninstall would call ours is ours here too, so the two never disagree.
|
|
373
|
+
return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key) && !(key === OTLP_ENDPOINT_KEY && isOurEndpoint(envBlock[key], context)));
|
|
354
374
|
}
|
|
355
375
|
/**
|
|
356
376
|
* Env keys uninstall is allowed to remove.
|
|
357
377
|
*
|
|
358
|
-
*
|
|
378
|
+
* Recorded keys go whatever their value (absent ones too, so their prior value
|
|
379
|
+
* comes back). Without a record we are guessing: a key counts as ours only when
|
|
380
|
+
* it holds a value AgentWatch writes and the base endpoint is an Agent Watch
|
|
381
|
+
* one. A signal sent to the developer's own per-signal endpoint keeps its
|
|
382
|
+
* exporter and the switches every signal needs.
|
|
383
|
+
*
|
|
384
|
+
* @param envBlock - Current env block.
|
|
359
385
|
* @param recorded - Keys a previous setup recorded as ours.
|
|
360
|
-
* @param
|
|
361
|
-
* @returns The keys to drop.
|
|
386
|
+
* @param context - Config, for which endpoints are ours.
|
|
387
|
+
* @returns The keys to drop and the AgentWatch-looking keys left in place.
|
|
362
388
|
*/
|
|
363
|
-
function removableEnvKeys(envBlock, recorded,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
389
|
+
function removableEnvKeys(envBlock, recorded, context) {
|
|
390
|
+
if (recorded.length > 0)
|
|
391
|
+
return { removable: new Set(recorded.filter((key) => key !== HEADERS_HELPER_KEY)), kept: [] };
|
|
392
|
+
const ownEndpoint = isOurEndpoint(envBlock[OTLP_ENDPOINT_KEY], context);
|
|
393
|
+
const ours = Object.keys(envBlock).filter((key) => isAgentWatchValue(key, envBlock[key], context));
|
|
394
|
+
if (!ownEndpoint)
|
|
395
|
+
return { removable: new Set(), kept: ours, reason: isNamedEndpoint(envBlock[OTLP_ENDPOINT_KEY]) ? 'foreignEndpoint' : 'noEndpoint' };
|
|
396
|
+
const developers = developerSignalKeys(envBlock, context);
|
|
397
|
+
return { removable: new Set(ours.filter((key) => !developers.has(key))), kept: ours.filter((key) => developers.has(key)), reason: 'ownSignal' };
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Whether a key holds a value some AgentWatch setup writes; for the endpoint,
|
|
401
|
+
* one of ours.
|
|
402
|
+
*
|
|
403
|
+
* @param key - Env key.
|
|
404
|
+
* @param value - Its value.
|
|
405
|
+
* @param context - Config, for which endpoints are ours.
|
|
406
|
+
* @returns True for one of our values.
|
|
407
|
+
*/
|
|
408
|
+
function isAgentWatchValue(key, value, context) {
|
|
409
|
+
if (key === OTLP_ENDPOINT_KEY)
|
|
410
|
+
return isOurEndpoint(value, context);
|
|
411
|
+
return AGENTWATCH_ENV_VALUES.get(key)?.has(value) === true;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Keys a signal needs while it exports to the developer's own per-signal
|
|
415
|
+
* endpoint: its exporter switch and what that exporter needs (the traces beta
|
|
416
|
+
* flag), plus the switches every signal shares. An empty or Agent Watch
|
|
417
|
+
* endpoint is not the developer's.
|
|
418
|
+
*
|
|
419
|
+
* @param envBlock - Current env block.
|
|
420
|
+
* @param context - Config, for which endpoints are ours.
|
|
421
|
+
* @returns The keys to leave in place.
|
|
422
|
+
*/
|
|
423
|
+
function developerSignalKeys(envBlock, context) {
|
|
424
|
+
// Only an exporter switched to `otlp` sends there; `none` or no switch sends nothing, so it is not kept.
|
|
425
|
+
const exporters = [...OTLP_SIGNAL_EXPORTER_KEYS].flatMap(([endpoint, exporter]) => !isDeveloperEndpoint(envBlock[endpoint], context) || envBlock[exporter] !== OTEL_EXPORTER_OTLP
|
|
426
|
+
? []
|
|
427
|
+
: [exporter, ...(SIGNAL_EXPORTER_EXTRA_KEYS.get(exporter) ?? [])]);
|
|
428
|
+
return new Set(exporters.length === 0 ? [] : [...exporters, ...OTEL_SHARED_KEYS]);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Whether a per-signal endpoint is the developer's own collector.
|
|
432
|
+
*
|
|
433
|
+
* @param value - The endpoint as the settings hold it.
|
|
434
|
+
* @param context - Config, for which endpoints are ours.
|
|
435
|
+
* @returns True for a non-empty endpoint that is not ours.
|
|
436
|
+
*/
|
|
437
|
+
function isDeveloperEndpoint(value, context) {
|
|
438
|
+
return isNamedEndpoint(value) && !isOurEndpoint(value, context);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Whether an endpoint value names anywhere at all.
|
|
442
|
+
*
|
|
443
|
+
* @param value - The endpoint as the settings hold it.
|
|
444
|
+
* @returns True for a non-empty string.
|
|
445
|
+
*/
|
|
446
|
+
function isNamedEndpoint(value) {
|
|
447
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Whether an endpoint is one AgentWatch sends to: the one this config names,
|
|
451
|
+
* an Agent Watch host, or an origin this machine trusts. A changed config URL
|
|
452
|
+
* must not turn an exporter setup wrote into the developer's.
|
|
453
|
+
*
|
|
454
|
+
* @param value - The endpoint as the settings hold it.
|
|
455
|
+
* @param context - Config, for its endpoint and trusted origins.
|
|
456
|
+
* @returns True when the endpoint is ours.
|
|
457
|
+
*/
|
|
458
|
+
function isOurEndpoint(value, context) {
|
|
459
|
+
if (typeof value !== 'string')
|
|
460
|
+
return false;
|
|
461
|
+
return value === otlpBaseUrl(context.config) || isAgentWatchEndpoint(value, new Set(context.config.customEndpoints));
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* What each desired key held before AgentWatch took it, as JSON text so
|
|
465
|
+
* uninstall puts back the same value and type. With no record, a file already
|
|
466
|
+
* sending to our endpoint was written by an AgentWatch setup whose record is
|
|
467
|
+
* gone, so nothing in it is the developer's.
|
|
468
|
+
*
|
|
469
|
+
* @param envBlock - Current env block.
|
|
470
|
+
* @param desired - What we are about to write.
|
|
471
|
+
* @param ownedKeys - Keys a previous setup recorded as ours.
|
|
472
|
+
* @param previous - Prior values that setup recorded.
|
|
473
|
+
* @param context - Config, for which endpoints are ours.
|
|
474
|
+
* @returns Prior values by key.
|
|
475
|
+
*/
|
|
476
|
+
function priorEnvValues(envBlock, desired, ownedKeys, previous, context) {
|
|
477
|
+
const leftover = ownedKeys.length === 0 && isOurEndpoint(envBlock[OTLP_ENDPOINT_KEY], context);
|
|
478
|
+
// Even in a leftover file, a value AgentWatch never writes, or a key a
|
|
479
|
+
// developer's own per-signal export needs, is the developer's.
|
|
480
|
+
const developers = leftover ? developerSignalKeys(envBlock, context) : new Set();
|
|
481
|
+
const keys = Object.keys(desired);
|
|
482
|
+
const before = Object.fromEntries(keys.flatMap((key) => {
|
|
483
|
+
const value = envBlock[key];
|
|
484
|
+
const theirs = !leftover || developers.has(key) || !isAgentWatchValue(key, value, context);
|
|
485
|
+
return value === undefined || !theirs ? [] : [[key, JSON.stringify(value)]];
|
|
486
|
+
}));
|
|
487
|
+
return foldPriorValues(keys, ownedKeys, previous, before);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The recorded prior values of the given keys, decoded.
|
|
491
|
+
*
|
|
492
|
+
* @param priors - Prior values by key, as JSON text.
|
|
493
|
+
* @param keys - Keys being dropped.
|
|
494
|
+
* @returns The values to put back.
|
|
495
|
+
*/
|
|
496
|
+
function restoredEnv(priors, keys) {
|
|
497
|
+
return Object.fromEntries([...keys].flatMap((key) => {
|
|
498
|
+
const value = parsePriorValue(priors[key]);
|
|
499
|
+
return value === undefined ? [] : [[key, value]];
|
|
500
|
+
}));
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* An env block with keys dropped and prior values put back.
|
|
504
|
+
*
|
|
505
|
+
* A restored key keeps its place, so a restore that changes nothing rewrites
|
|
506
|
+
* nothing.
|
|
507
|
+
*
|
|
508
|
+
* @param envBlock - Current env block.
|
|
509
|
+
* @param dropped - Keys we give up.
|
|
510
|
+
* @param restored - The developer's own values among them.
|
|
511
|
+
* @returns The next env block.
|
|
512
|
+
*/
|
|
513
|
+
function withRestored(envBlock, dropped, restored) {
|
|
514
|
+
return { ...omitKeys(envBlock, new Set([...dropped].filter((key) => !Object.hasOwn(restored, key)))), ...restored };
|
|
378
515
|
}
|
|
379
516
|
/**
|
|
380
517
|
* Settings with our telemetry keys removed.
|
|
381
518
|
*
|
|
382
519
|
* @param settings - The whole settings object.
|
|
383
|
-
* @param
|
|
520
|
+
* @param withoutCapture - The env block with our part of the capture variables gone.
|
|
521
|
+
* @param restored - The developer's own values to put back.
|
|
384
522
|
* @param removable - Env keys to drop.
|
|
385
523
|
* @param helperRemoved - Whether the header helper is ours to drop.
|
|
386
524
|
* @returns The next settings object.
|
|
387
525
|
*/
|
|
388
|
-
function strippedSettings(settings,
|
|
526
|
+
function strippedSettings(settings, withoutCapture, restored, removable, helperRemoved) {
|
|
389
527
|
const withoutHelper = helperRemoved ? omitKeys(settings, new Set([HEADERS_HELPER_KEY])) : settings;
|
|
390
|
-
|
|
528
|
+
const envBlock = asRecord(settings[ENV_BLOCK_KEY]);
|
|
529
|
+
// An env value that is not an object is not ours to replace.
|
|
530
|
+
if (!envBlock && settings[ENV_BLOCK_KEY] !== undefined)
|
|
391
531
|
return withoutHelper;
|
|
392
|
-
const nextEnv =
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
|
|
532
|
+
const nextEnv = withRestored(withoutCapture ?? {}, removable, restored);
|
|
533
|
+
// A block this run emptied is dropped rather than left as `"env": {}`; one
|
|
534
|
+
// that was already empty is the developer's and stays.
|
|
535
|
+
if (Object.keys(nextEnv).length === 0) {
|
|
536
|
+
return Object.keys(envBlock ?? {}).length > 0 ? omitKeys(withoutHelper, new Set([ENV_BLOCK_KEY])) : withoutHelper;
|
|
537
|
+
}
|
|
396
538
|
return { ...withoutHelper, [ENV_BLOCK_KEY]: nextEnv };
|
|
397
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* What uninstall says about keys it left for want of an install record.
|
|
542
|
+
*
|
|
543
|
+
* @param kept - The keys left in place.
|
|
544
|
+
* @param reason - Why they were left.
|
|
545
|
+
* @param settingsPath - The settings file, to name.
|
|
546
|
+
* @returns The messages; none when nothing was left.
|
|
547
|
+
*/
|
|
548
|
+
function keptMessages(kept, reason, settingsPath) {
|
|
549
|
+
if (kept.length === 0 || !reason)
|
|
550
|
+
return [];
|
|
551
|
+
return [`left ${kept.join(', ')} in ${settingsPath}: ${KEPT_REASON_MESSAGES[reason]}`];
|
|
552
|
+
}
|
|
398
553
|
/**
|
|
399
554
|
* Whether the configured header helper is one we wrote.
|
|
400
555
|
*
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { claudeBillingMode } from '../../billing/billing-mode.js';
|
|
2
|
+
import { asRecord } from '../../core/object.js';
|
|
1
3
|
import { hookNotice, hookRefusal } from '../shared/hook-refusal.js';
|
|
2
|
-
import {
|
|
4
|
+
import { readClaudeSessionTitles, readTurnUsage } from '../../turns/claude-transcript.js';
|
|
5
|
+
import { CLAUDE_DETACHED_EVENTS, CLAUDE_ENTRYPOINT_VAR, CLAUDE_INTERACTIVE_ENTRYPOINTS, CLAUDE_PROMPT_SUBMIT_EVENTS } from './constants/claude.constants.js';
|
|
3
6
|
import { detectClaude } from './claude.detect.js';
|
|
4
7
|
import { installClaudeHooks, uninstallClaudeHooks } from './claude.hooks.js';
|
|
5
8
|
import { claudeShellCall, parseClaudeHookEvent } from './claude.adapter.js';
|
|
@@ -7,6 +10,8 @@ import { ClaudeOtelConfigurator } from './claude.otel.js';
|
|
|
7
10
|
export const claudeProvider = {
|
|
8
11
|
id: 'claude',
|
|
9
12
|
displayName: 'Claude Code',
|
|
13
|
+
/** Doctor only, so the hook path never loads the version probe. */
|
|
14
|
+
checks: async (env) => (await import('./claude.version.js')).claudeVersionChecks(env),
|
|
10
15
|
detect: detectClaude,
|
|
11
16
|
installHooks: installClaudeHooks,
|
|
12
17
|
uninstallHooks: uninstallClaudeHooks,
|
|
@@ -24,6 +29,17 @@ export const claudeProvider = {
|
|
|
24
29
|
getBlockResponse: (payload, message) => hookRefusal(payload, CLAUDE_PROMPT_SUBMIT_EVENTS, { decision: 'block', reason: message }),
|
|
25
30
|
/** A line for the developer after a shell run, as `systemMessage`; never plain stdout. */
|
|
26
31
|
getNoticeResponse: (payload, message) => hookNotice(payload, message),
|
|
32
|
+
/**
|
|
33
|
+
* Stop and SubagentStop of a terminal session; anywhere else the session may end at once and its `SessionEnd` would race the close.
|
|
34
|
+
* ponytail: an interactive `/exit` or `/clear` within the ~0.3 s the detached close takes can still race
|
|
35
|
+
* its `SessionEnd`; upgrade path is a pending-close marker that `SessionEnd` waits on.
|
|
36
|
+
*/
|
|
37
|
+
runsDetached: (payload, env) => CLAUDE_DETACHED_EVENTS.has(String(asRecord(payload)?.['hook_event_name'])) && CLAUDE_INTERACTIVE_ENTRYPOINTS.has(env.vars[CLAUDE_ENTRYPOINT_VAR] ?? ''),
|
|
27
38
|
shellCall: claudeShellCall,
|
|
39
|
+
readTurnUsage,
|
|
40
|
+
billingMode: claudeBillingMode,
|
|
41
|
+
readTranscriptTitles: readClaudeSessionTitles,
|
|
42
|
+
/** Claude Code names its own entrypoint (`cli`, `claude-vscode`, `sdk-ts`, ...). */
|
|
43
|
+
surface: async (env) => env.vars[CLAUDE_ENTRYPOINT_VAR] || undefined,
|
|
28
44
|
nativeTelemetry: new ClaudeOtelConfigurator()
|
|
29
45
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
2
|
+
import type { ProviderCheck } from '../types/provider.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether Claude Code is new enough for prompt-id turn correlation.
|
|
5
|
+
*
|
|
6
|
+
* @param env - Ambient environment.
|
|
7
|
+
* @returns The one check, for doctor.
|
|
8
|
+
*/
|
|
9
|
+
export declare function claudeVersionChecks(env: Env): Promise<readonly ProviderCheck[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { execVersion, meetsMinVersion, parseVersion } from '../../core/version.js';
|
|
2
|
+
import { findExecutable } from '../../core/which.js';
|
|
3
|
+
import { CLAUDE_MIN_VERSION_FOR_PROMPT_ID, CLAUDE_VERSION_TIMEOUT_MS } from './constants/claude.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether Claude Code is new enough for prompt-id turn correlation.
|
|
6
|
+
*
|
|
7
|
+
* @param env - Ambient environment.
|
|
8
|
+
* @returns The one check, for doctor.
|
|
9
|
+
*/
|
|
10
|
+
export async function claudeVersionChecks(env) {
|
|
11
|
+
const name = 'Claude Code version';
|
|
12
|
+
const bin = findExecutable(env, 'claude');
|
|
13
|
+
if (!bin) {
|
|
14
|
+
return [{ name, level: 'warn', detail: `claude not on PATH; cannot verify >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} (needed for turn correlation)` }];
|
|
15
|
+
}
|
|
16
|
+
const output = await execVersion(bin, ['--version'], CLAUDE_VERSION_TIMEOUT_MS);
|
|
17
|
+
const version = output ? parseVersion(output) : undefined;
|
|
18
|
+
if (!version) {
|
|
19
|
+
return [{ name, level: 'warn', detail: `could not determine version (need >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID} for turn correlation)` }];
|
|
20
|
+
}
|
|
21
|
+
if (meetsMinVersion(version, CLAUDE_MIN_VERSION_FOR_PROMPT_ID))
|
|
22
|
+
return [{ name, level: 'ok', detail: version }];
|
|
23
|
+
return [{
|
|
24
|
+
name,
|
|
25
|
+
level: 'warn',
|
|
26
|
+
detail: `${version} — prompt_id turn correlation needs >= ${CLAUDE_MIN_VERSION_FOR_PROMPT_ID}; turn_id will be empty`
|
|
27
|
+
}];
|
|
28
|
+
}
|
|
@@ -14,10 +14,30 @@ export declare const CLAUDE_EXECUTABLE = "claude";
|
|
|
14
14
|
export declare const CLAUDE_HOOK_EVENTS: readonly ["SessionStart", "SessionEnd", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PermissionRequest", "Stop", "SubagentStart", "SubagentStop"];
|
|
15
15
|
/** Tool-scoped events take a tool-name matcher; "*" observes every tool. */
|
|
16
16
|
export declare const CLAUDE_MATCHED_EVENTS: ReadonlySet<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Hooks whose work a detached `agentwatch hook` does, so the end of a turn does
|
|
19
|
+
* not wait on the send (p50 1 s, p99 6 s, measured 2026-11; the hand-off takes
|
|
20
|
+
* about 0.1 s). Not `async: true` in settings: under `claude -p` Claude kills an
|
|
21
|
+
* async hook within milliseconds of its Stop, before Node has even started.
|
|
22
|
+
* Only hooks that answer nothing qualify: `UserPromptSubmit` carries the budget
|
|
23
|
+
* refusal, and `SessionEnd` clears the session's state.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CLAUDE_DETACHED_EVENTS: ReadonlySet<string>;
|
|
26
|
+
/**
|
|
27
|
+
* `CLAUDE_CODE_ENTRYPOINT` values of a session a person keeps open (`cli`, the
|
|
28
|
+
* terminal; verified 2026-11). Only these hand a Stop off. Any other entrypoint
|
|
29
|
+
* (`sdk-cli` for `claude -p`, the SDKs, the GitHub Action, or none at all) may end
|
|
30
|
+
* the session right after its last Stop, and that `SessionEnd` clears the turn
|
|
31
|
+
* state a detached close still has to read, so those Stops run in place.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CLAUDE_ENTRYPOINT_VAR = "CLAUDE_CODE_ENTRYPOINT";
|
|
34
|
+
export declare const CLAUDE_INTERACTIVE_ENTRYPOINTS: ReadonlySet<string>;
|
|
17
35
|
/** Claude Code reads this field as seconds. */
|
|
18
36
|
export declare const CLAUDE_HOOK_TIMEOUT_SECONDS = 30;
|
|
19
37
|
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
20
38
|
export declare const CLAUDE_EVENT_TYPE_MAP: Readonly<Record<string, CanonicalEventType>>;
|
|
39
|
+
/** The tool that runs a skill; its input names it as `skill` (AWT-711). */
|
|
40
|
+
export declare const CLAUDE_SKILL_TOOL = "Skill";
|
|
21
41
|
/** Hooks whose canonical type depends on which tool ran. */
|
|
22
42
|
export declare const CLAUDE_TOOL_EVENTS: ReadonlySet<string>;
|
|
23
43
|
/** Hooks that report a tool call as starting rather than finishing. */
|
|
@@ -40,3 +60,10 @@ export declare const CLAUDE_UNKNOWN_EVENT = "unknown";
|
|
|
40
60
|
* the error is read for the number in memory, never kept.
|
|
41
61
|
*/
|
|
42
62
|
export declare const RE_CLAUDE_EXIT_CODE: RegExp;
|
|
63
|
+
/**
|
|
64
|
+
* prompt_id (== OTel prompt.id) appeared in this Claude Code release; older
|
|
65
|
+
* versions fall back to session-scoped turn tracking with an empty turn_id.
|
|
66
|
+
*/
|
|
67
|
+
export declare const CLAUDE_MIN_VERSION_FOR_PROMPT_ID = "2.1.196";
|
|
68
|
+
/** How long doctor waits for `claude --version`. */
|
|
69
|
+
export declare const CLAUDE_VERSION_TIMEOUT_MS = 5000;
|
|
@@ -24,6 +24,24 @@ export const CLAUDE_HOOK_EVENTS = [
|
|
|
24
24
|
];
|
|
25
25
|
/** Tool-scoped events take a tool-name matcher; "*" observes every tool. */
|
|
26
26
|
export const CLAUDE_MATCHED_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionRequest']);
|
|
27
|
+
/**
|
|
28
|
+
* Hooks whose work a detached `agentwatch hook` does, so the end of a turn does
|
|
29
|
+
* not wait on the send (p50 1 s, p99 6 s, measured 2026-11; the hand-off takes
|
|
30
|
+
* about 0.1 s). Not `async: true` in settings: under `claude -p` Claude kills an
|
|
31
|
+
* async hook within milliseconds of its Stop, before Node has even started.
|
|
32
|
+
* Only hooks that answer nothing qualify: `UserPromptSubmit` carries the budget
|
|
33
|
+
* refusal, and `SessionEnd` clears the session's state.
|
|
34
|
+
*/
|
|
35
|
+
export const CLAUDE_DETACHED_EVENTS = new Set(['Stop', 'SubagentStop']);
|
|
36
|
+
/**
|
|
37
|
+
* `CLAUDE_CODE_ENTRYPOINT` values of a session a person keeps open (`cli`, the
|
|
38
|
+
* terminal; verified 2026-11). Only these hand a Stop off. Any other entrypoint
|
|
39
|
+
* (`sdk-cli` for `claude -p`, the SDKs, the GitHub Action, or none at all) may end
|
|
40
|
+
* the session right after its last Stop, and that `SessionEnd` clears the turn
|
|
41
|
+
* state a detached close still has to read, so those Stops run in place.
|
|
42
|
+
*/
|
|
43
|
+
export const CLAUDE_ENTRYPOINT_VAR = 'CLAUDE_CODE_ENTRYPOINT';
|
|
44
|
+
export const CLAUDE_INTERACTIVE_ENTRYPOINTS = new Set(['cli']);
|
|
27
45
|
/** Claude Code reads this field as seconds. */
|
|
28
46
|
export const CLAUDE_HOOK_TIMEOUT_SECONDS = 30;
|
|
29
47
|
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
@@ -38,6 +56,8 @@ export const CLAUDE_EVENT_TYPE_MAP = {
|
|
|
38
56
|
PreCompact: 'compaction.started',
|
|
39
57
|
PostCompact: 'compaction.completed'
|
|
40
58
|
};
|
|
59
|
+
/** The tool that runs a skill; its input names it as `skill` (AWT-711). */
|
|
60
|
+
export const CLAUDE_SKILL_TOOL = 'Skill';
|
|
41
61
|
/** Hooks whose canonical type depends on which tool ran. */
|
|
42
62
|
export const CLAUDE_TOOL_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'PostToolUseFailure', 'PermissionRequest']);
|
|
43
63
|
/** Hooks that report a tool call as starting rather than finishing. */
|
|
@@ -60,3 +80,10 @@ export const CLAUDE_UNKNOWN_EVENT = 'unknown';
|
|
|
60
80
|
* the error is read for the number in memory, never kept.
|
|
61
81
|
*/
|
|
62
82
|
export const RE_CLAUDE_EXIT_CODE = /\bexit code (-?\d+)\b/i;
|
|
83
|
+
/**
|
|
84
|
+
* prompt_id (== OTel prompt.id) appeared in this Claude Code release; older
|
|
85
|
+
* versions fall back to session-scoped turn tracking with an empty turn_id.
|
|
86
|
+
*/
|
|
87
|
+
export const CLAUDE_MIN_VERSION_FOR_PROMPT_ID = '2.1.196';
|
|
88
|
+
/** How long doctor waits for `claude --version`. */
|
|
89
|
+
export const CLAUDE_VERSION_TIMEOUT_MS = 5_000;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeptReason } from '../types/claude.types.js';
|
|
1
2
|
/** Settings key Claude Code reads the OTLP header helper command from. */
|
|
2
3
|
export declare const HEADERS_HELPER_KEY = "otelHeadersHelper";
|
|
3
4
|
/** Settings key holding the environment block telemetry is configured through. */
|
|
@@ -17,5 +18,31 @@ export declare const OTLP_PROTOCOL = "http/json";
|
|
|
17
18
|
export declare const RE_HOOK_SUFFIX: RegExp;
|
|
18
19
|
/** Where Claude Code's exporters send: the OTLP base every signal derives from. */
|
|
19
20
|
export declare const OTLP_ENDPOINT_KEY = "OTEL_EXPORTER_OTLP_ENDPOINT";
|
|
21
|
+
/** Each signal's own endpoint key, mapped to the exporter switch that signal reads. */
|
|
22
|
+
export declare const OTLP_SIGNAL_EXPORTER_KEYS: ReadonlyMap<string, string>;
|
|
20
23
|
/** Per-signal endpoints, which override the base for that one signal. */
|
|
21
24
|
export declare const OTLP_SIGNAL_ENDPOINT_KEYS: readonly string[];
|
|
25
|
+
/** Claude's enhanced-traces beta switch, which only adds the llm_request spans. */
|
|
26
|
+
export declare const TRACES_BETA_KEY = "CLAUDE_CODE_ENHANCED_TELEMETRY_BETA";
|
|
27
|
+
/** Keys a signal's exporter needs beside itself, by exporter switch. */
|
|
28
|
+
export declare const SIGNAL_EXPORTER_EXTRA_KEYS: ReadonlyMap<string, readonly string[]>;
|
|
29
|
+
/** Keys every exporting signal needs, whoever's collector it sends to. */
|
|
30
|
+
export declare const OTEL_SHARED_KEYS: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Claude's own content-logging switches, forced off.
|
|
33
|
+
*
|
|
34
|
+
* Never treated as a foreign key: a user who set `OTEL_LOG_USER_PROMPTS=1`
|
|
35
|
+
* before installing is exactly the case this exists to override, and refusing
|
|
36
|
+
* to configure them would leave prompt logging on *and* drop the llm.call
|
|
37
|
+
* ledger. Overriding a switch that only ever reduces what leaves the machine
|
|
38
|
+
* is not the redirection the conflict check protects against.
|
|
39
|
+
*/
|
|
40
|
+
export declare const CONTENT_LOG_OFF: Readonly<Record<string, string>>;
|
|
41
|
+
/**
|
|
42
|
+
* Every value any AgentWatch setup writes for an env key, whatever the signals
|
|
43
|
+
* were then. Without an install record, a key counts as ours only when it holds
|
|
44
|
+
* one of these. The endpoint is judged on its own (an Agent Watch host).
|
|
45
|
+
*/
|
|
46
|
+
export declare const AGENTWATCH_ENV_VALUES: ReadonlyMap<string, ReadonlySet<unknown>>;
|
|
47
|
+
/** What uninstall says about keys it left, by why it left them. */
|
|
48
|
+
export declare const KEPT_REASON_MESSAGES: Readonly<Record<KeptReason, string>>;
|