@agent-watch-ai/edge 0.2.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +558 -0
- package/README.md +222 -97
- package/SECURITY.md +72 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +52 -4
- package/dist/cli/constants/cli.constants.js +56 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +321 -33
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +553 -103
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +117 -0
- package/dist/cli/types/cli.types.d.ts +43 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +110 -12
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +116 -6
- package/dist/config/constants/config.constants.js +131 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +831 -84
- package/dist/config/schemas/config.schema.js +398 -16
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +119 -0
- package/dist/credentials/constants/credentials.constants.js +120 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +38 -0
- package/dist/credentials/credentials.d.ts +86 -0
- package/dist/credentials/credentials.js +278 -0
- package/dist/credentials/device-api.d.ts +73 -0
- package/dist/credentials/device-api.js +161 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +73 -0
- package/dist/credentials/identity.js +101 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +31 -0
- package/dist/credentials/sign-in.js +105 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +206 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +64 -17
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +107 -17
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +66 -2
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +10 -0
- package/dist/pipeline/constants/pipeline.constants.js +10 -0
- package/dist/pipeline/hook-pipeline.js +410 -33
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +75 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +36 -3
- package/dist/providers/codex/codex.otel.js +199 -32
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +10 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
- package/dist/providers/constants/provider.constants.d.ts +8 -3
- package/dist/providers/constants/provider.constants.js +8 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
- package/dist/providers/cursor/constants/cursor.constants.js +9 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +129 -4
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +9 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +30 -21
- package/dist/providers/gemini/gemini.otel.js +166 -22
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
- package/dist/providers/shared/constants/tooling.constants.js +25 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +40 -1
- package/dist/providers/shared/tooling.js +70 -1
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +81 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +21 -0
- package/dist/storage/atomic-file.js +20 -1
- package/dist/storage/constants/storage.constants.d.ts +19 -0
- package/dist/storage/constants/storage.constants.js +19 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +67 -0
- package/dist/turns/work-checkout.js +700 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +655 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import { asRecord, omitKeys } from '../../core/object.js';
|
|
2
|
-
import { enabledSignalNames,
|
|
3
|
-
import {
|
|
2
|
+
import { enabledSignalNames, otlpBaseUrl, toolContentConsented } from '../../config/config.js';
|
|
3
|
+
import { INSTALLATION_HEADER } from '../../transport/constants/transport.constants.js';
|
|
4
|
+
import { backupFile, currentMode, writeIfUnchanged } from '../../storage/atomic-file.js';
|
|
5
|
+
import { SECRET_FILE_MODE } from '../../storage/constants/storage.constants.js';
|
|
4
6
|
import { readJsonFile } from '../../storage/json-file.js';
|
|
5
|
-
import {
|
|
7
|
+
import { parseJsonLine } from '../../turns/transcript.js';
|
|
8
|
+
import { deviceFor, hasCredential } from '../../credentials/identity.js';
|
|
9
|
+
import { BEARER_PLACEHOLDER, HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
|
|
6
10
|
import { writeJsonValidated } from '../shared/hook-config.js';
|
|
7
11
|
import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
|
|
8
12
|
import { geminiSettingsPath } from './gemini.detect.js';
|
|
9
13
|
import { GEMINI_PROVIDER_ID } from './constants/gemini.constants.js';
|
|
10
|
-
import { ENV_BLOCK_KEY, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_TELEMETRY_TARGET_LOCAL, LEGACY_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_HEADERS_KEY, STANDARD_OTLP_PROTOCOL } from './constants/gemini.otel.constants.js';
|
|
14
|
+
import { ENV_BLOCK_KEY, GEMINI_ENDPOINT_KEYS, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_TELEMETRY_TARGET_LOCAL, LEGACY_HELPER_KEY, OTEL_EXPORTER_NONE, OTEL_EXPORTER_OTLP, OTLP_HEADERS_KEY, RE_BEARER_PAIR, STANDARD_OTLP_PROTOCOL } from './constants/gemini.otel.constants.js';
|
|
15
|
+
/**
|
|
16
|
+
* Gemini's own prompt-logging switch, forced off.
|
|
17
|
+
*
|
|
18
|
+
* Never treated as a foreign key: a user who set it to `true` before installing
|
|
19
|
+
* is exactly the case this exists to override, and refusing to configure it
|
|
20
|
+
* would leave prompt logging on *and* drop the llm.call ledger. Overriding a
|
|
21
|
+
* switch that only ever reduces what leaves the machine is not the redirection
|
|
22
|
+
* the conflict check protects against. Mirrors `CONTENT_LOG_OFF` in claude.otel.
|
|
23
|
+
*/
|
|
24
|
+
const CONTENT_LOG_OFF = {
|
|
25
|
+
GEMINI_TELEMETRY_LOG_PROMPTS: 'false'
|
|
26
|
+
};
|
|
11
27
|
/**
|
|
12
28
|
* The environment Gemini CLI actually reads.
|
|
13
29
|
*
|
|
@@ -24,16 +40,18 @@ import { ENV_BLOCK_KEY, GEMINI_LEGACY_OWNED_KEYS, GEMINI_OTLP_PROTOCOL, GEMINI_T
|
|
|
24
40
|
* which is fail-closed, answered 401 to every batch.
|
|
25
41
|
*
|
|
26
42
|
* @param context - Environment, paths and effective config.
|
|
43
|
+
* @param bearer - What to authenticate with; see `SetupContext.bearer`.
|
|
27
44
|
* @returns The desired variables, or undefined when telemetry is off or no
|
|
28
45
|
* backend is configured.
|
|
29
46
|
*/
|
|
30
|
-
|
|
47
|
+
function desiredGeminiOtelEnv(context, bearer) {
|
|
31
48
|
const otlpBase = otlpBaseUrl(context.config);
|
|
32
|
-
|
|
49
|
+
const signals = safeGeminiSignals(context.config);
|
|
50
|
+
if (!otlpBase || !anySignal(signals))
|
|
33
51
|
return undefined;
|
|
34
|
-
const signals = context.config.otel;
|
|
35
52
|
return {
|
|
36
53
|
GEMINI_TELEMETRY_ENABLED: 'true',
|
|
54
|
+
...CONTENT_LOG_OFF,
|
|
37
55
|
GEMINI_TELEMETRY_TARGET: GEMINI_TELEMETRY_TARGET_LOCAL,
|
|
38
56
|
GEMINI_TELEMETRY_OTLP_ENDPOINT: otlpBase,
|
|
39
57
|
GEMINI_TELEMETRY_OTLP_PROTOCOL: GEMINI_OTLP_PROTOCOL,
|
|
@@ -43,9 +61,30 @@ export function desiredGeminiOtelEnv(context) {
|
|
|
43
61
|
OTEL_TRACES_EXPORTER: signals.traces ? OTEL_EXPORTER_OTLP : OTEL_EXPORTER_NONE,
|
|
44
62
|
OTEL_EXPORTER_OTLP_PROTOCOL: STANDARD_OTLP_PROTOCOL,
|
|
45
63
|
OTEL_EXPORTER_OTLP_ENDPOINT: otlpBase,
|
|
46
|
-
...(
|
|
64
|
+
...(bearer ? { [OTLP_HEADERS_KEY]: otlpHeaders(bearer, context.config.installationId) } : {})
|
|
47
65
|
};
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The `OTEL_EXPORTER_OTLP_HEADERS` value: comma-separated `key=value` pairs.
|
|
69
|
+
*
|
|
70
|
+
* Carries the installation id beside the bearer so a Gemini call that no turn
|
|
71
|
+
* summary claimed can still be traced to the machine that made it. Only the id
|
|
72
|
+
* — a locally generated UUID — travels here; no developer identity does.
|
|
73
|
+
*
|
|
74
|
+
* Takes the token rather than the config it came from, like `tomlHeaders` does
|
|
75
|
+
* for Codex: a header builder that reads a config can be handed one with no
|
|
76
|
+
* token and quietly emit `Bearer ` rather than refusing to be called.
|
|
77
|
+
*
|
|
78
|
+
* @param token - The access token; the caller has already checked there is one.
|
|
79
|
+
* @param installationId - This installation's id, when one exists.
|
|
80
|
+
* @returns The header list for the exporter.
|
|
81
|
+
*/
|
|
82
|
+
function otlpHeaders(token, installationId) {
|
|
83
|
+
const pairs = [`Authorization=Bearer ${token}`];
|
|
84
|
+
if (installationId)
|
|
85
|
+
pairs.push(`${INSTALLATION_HEADER}=${installationId}`);
|
|
86
|
+
return pairs.join(',');
|
|
87
|
+
}
|
|
49
88
|
/** Configures Gemini CLI's own OTLP export. */
|
|
50
89
|
export class GeminiOtelConfigurator {
|
|
51
90
|
/**
|
|
@@ -64,7 +103,7 @@ export class GeminiOtelConfigurator {
|
|
|
64
103
|
* @returns The status, naming any foreign configuration in the way.
|
|
65
104
|
*/
|
|
66
105
|
async inspect(context) {
|
|
67
|
-
const disabled = !
|
|
106
|
+
const disabled = !anySignal(safeGeminiSignals(context.config));
|
|
68
107
|
const read = await readJsonFile(geminiSettingsPath(context.env));
|
|
69
108
|
const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
|
|
70
109
|
if (!settings) {
|
|
@@ -76,10 +115,19 @@ export class GeminiOtelConfigurator {
|
|
|
76
115
|
const ownedKeys = ownedKeysOf(context);
|
|
77
116
|
if (disabled)
|
|
78
117
|
return inspectDisabled(settings, envBlock, ownedKeys);
|
|
79
|
-
|
|
118
|
+
// The bearer's value is not compared: it is the access token, which the hook
|
|
119
|
+
// path rotates. Only whether a header is there, when there is a credential.
|
|
120
|
+
const device = deviceFor(context.config);
|
|
121
|
+
const desired = desiredGeminiOtelEnv(context, hasCredential(context.config) ? BEARER_PLACEHOLDER : undefined);
|
|
80
122
|
if (!desired)
|
|
81
123
|
return { supported: true, configured: false, detail: 'no backend endpoint configured' };
|
|
82
|
-
const
|
|
124
|
+
const headers = envBlock[OTLP_HEADERS_KEY];
|
|
125
|
+
// An install key still in the header list once a device exists is stale.
|
|
126
|
+
if (device && context.config.token && typeof headers === 'string' && headers.includes(context.config.token)) {
|
|
127
|
+
return { supported: true, configured: false, detail: 'telemetry headers still hold the install key — run `agentwatch setup`' };
|
|
128
|
+
}
|
|
129
|
+
const actual = typeof headers === 'string' ? { ...envBlock, [OTLP_HEADERS_KEY]: headers.replace(RE_BEARER_PAIR, `$1${BEARER_PLACEHOLDER}`) } : envBlock;
|
|
130
|
+
const matches = Object.entries(desired).every(([key, value]) => actual[key] === value);
|
|
83
131
|
// A helper entry left by an older version is dead weight Gemini ignores;
|
|
84
132
|
// reporting "configured" would hide that setup still has work to do. A
|
|
85
133
|
// helper belonging to another tool is none of our business.
|
|
@@ -87,7 +135,7 @@ export class GeminiOtelConfigurator {
|
|
|
87
135
|
return { supported: true, configured: true };
|
|
88
136
|
if (matches)
|
|
89
137
|
return { supported: true, configured: false, detail: 'stale otelHeadersHelper entry — run `agentwatch setup`' };
|
|
90
|
-
const conflicting = foreignKeys(
|
|
138
|
+
const conflicting = foreignKeys(actual, desired, ownedKeys);
|
|
91
139
|
if (conflicting.length > 0) {
|
|
92
140
|
return { supported: true, configured: false, conflict: `existing telemetry env vars: ${conflicting.join(', ')}` };
|
|
93
141
|
}
|
|
@@ -101,7 +149,7 @@ export class GeminiOtelConfigurator {
|
|
|
101
149
|
* install state.
|
|
102
150
|
*/
|
|
103
151
|
async configure(context) {
|
|
104
|
-
const desired = desiredGeminiOtelEnv(context);
|
|
152
|
+
const desired = desiredGeminiOtelEnv(context, context.bearer);
|
|
105
153
|
if (!desired)
|
|
106
154
|
return this.configureDisabled(context);
|
|
107
155
|
const settingsPath = geminiSettingsPath(context.env);
|
|
@@ -130,20 +178,27 @@ export class GeminiOtelConfigurator {
|
|
|
130
178
|
// Gemini never read this; leaving it behind only confuses the next reader.
|
|
131
179
|
const nextSettings = hasOurLegacyHelper(withEnv) ? omitKeys(withEnv, new Set([LEGACY_HELPER_KEY])) : withEnv;
|
|
132
180
|
const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
|
|
181
|
+
// Only when the block actually carries the bearer. This file is Gemini's,
|
|
182
|
+
// not ours, and `writeFileAtomic` preserves the target's mode by design —
|
|
183
|
+
// so tightening it unconditionally changed another tool's permissions on a
|
|
184
|
+
// shared workstation for no reason, and could never be undone.
|
|
185
|
+
const carriesCredential = desired[OTLP_HEADERS_KEY] !== undefined;
|
|
186
|
+
const priorMode = carriesCredential ? await currentMode(settingsPath) : undefined;
|
|
133
187
|
if (changed) {
|
|
134
188
|
await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
|
|
135
|
-
await writeJsonValidated(settingsPath, nextSettings);
|
|
189
|
+
await writeJsonValidated(settingsPath, nextSettings, carriesCredential ? SECRET_FILE_MODE : undefined);
|
|
136
190
|
}
|
|
137
191
|
return {
|
|
138
192
|
ok: true,
|
|
139
193
|
changed,
|
|
140
194
|
messages: changed
|
|
141
|
-
? [`native OpenTelemetry configured (signals: ${enabledSignalNames(context.config
|
|
195
|
+
? [`native OpenTelemetry configured (signals: ${enabledSignalNames(safeGeminiSignals(context.config)).join(', ')})`, 'restart running Gemini CLI sessions to pick it up']
|
|
142
196
|
: ['native OpenTelemetry already up to date'],
|
|
143
197
|
installState: withOtelInstall(context.installState, GEMINI_PROVIDER_ID, {
|
|
144
198
|
configPath: settingsPath,
|
|
145
199
|
ownedKeys: Object.keys(desired),
|
|
146
|
-
configuredAt: context.env.now()
|
|
200
|
+
configuredAt: context.env.now(),
|
|
201
|
+
...(changed && priorMode !== undefined && priorMode !== SECRET_FILE_MODE ? { priorMode } : {})
|
|
147
202
|
})
|
|
148
203
|
};
|
|
149
204
|
}
|
|
@@ -171,7 +226,10 @@ export class GeminiOtelConfigurator {
|
|
|
171
226
|
const changed = JSON.stringify(nextSettings) !== JSON.stringify(settings);
|
|
172
227
|
if (changed) {
|
|
173
228
|
await backupFile(settingsPath, context.paths.backupsDir, context.env.now());
|
|
174
|
-
|
|
229
|
+
// The mode the file had before AgentWatch tightened it, when it was
|
|
230
|
+
// tightened. `writeJsonValidated` with no mode would otherwise keep our
|
|
231
|
+
// 0600 on a file that no longer holds a token.
|
|
232
|
+
await writeJsonValidated(settingsPath, nextSettings, context.installState.agents[GEMINI_PROVIDER_ID]?.otelPriorMode);
|
|
175
233
|
}
|
|
176
234
|
return {
|
|
177
235
|
ok: true,
|
|
@@ -180,6 +238,26 @@ export class GeminiOtelConfigurator {
|
|
|
180
238
|
installState: withoutOtelInstall(context.installState, GEMINI_PROVIDER_ID)
|
|
181
239
|
};
|
|
182
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Where the exporter keys `uninstall` would remove send.
|
|
243
|
+
*
|
|
244
|
+
* @param context - Environment and install state.
|
|
245
|
+
* @returns The owned endpoints.
|
|
246
|
+
*/
|
|
247
|
+
async exporterEndpoints(context) {
|
|
248
|
+
const read = await readJsonFile(geminiSettingsPath(context.env));
|
|
249
|
+
const envBlock = asRecord(read.state === 'ok' ? asRecord(read.value)?.[ENV_BLOCK_KEY] : undefined);
|
|
250
|
+
// No record owns nothing: unlike an explicit `uninstall`, the sweep runs
|
|
251
|
+
// unasked, and Gemini installed after setup holds only the developer's keys.
|
|
252
|
+
const owned = new Set(context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys ?? []);
|
|
253
|
+
const endpoints = [];
|
|
254
|
+
for (const key of GEMINI_ENDPOINT_KEYS) {
|
|
255
|
+
const value = envBlock?.[key];
|
|
256
|
+
if (owned.has(key) && typeof value === 'string')
|
|
257
|
+
endpoints.push(value);
|
|
258
|
+
}
|
|
259
|
+
return endpoints;
|
|
260
|
+
}
|
|
183
261
|
/**
|
|
184
262
|
* Handle `configure` when telemetry is off or unconfigurable.
|
|
185
263
|
*
|
|
@@ -187,7 +265,7 @@ export class GeminiOtelConfigurator {
|
|
|
187
265
|
* @returns The outcome.
|
|
188
266
|
*/
|
|
189
267
|
async configureDisabled(context) {
|
|
190
|
-
if (
|
|
268
|
+
if (anySignal(safeGeminiSignals(context.config)))
|
|
191
269
|
return { ok: false, changed: false, messages: ['no backend endpoint configured'] };
|
|
192
270
|
const removed = await this.uninstall(context);
|
|
193
271
|
if (!removed.ok)
|
|
@@ -197,12 +275,78 @@ export class GeminiOtelConfigurator {
|
|
|
197
275
|
changed: removed.changed,
|
|
198
276
|
messages: [
|
|
199
277
|
removed.changed
|
|
200
|
-
? 'native OpenTelemetry disabled
|
|
201
|
-
: 'native OpenTelemetry disabled
|
|
278
|
+
? 'native OpenTelemetry disabled by config or content consent; previous configuration removed'
|
|
279
|
+
: 'native OpenTelemetry disabled by config or content consent'
|
|
202
280
|
],
|
|
203
281
|
installState: removed.installState
|
|
204
282
|
};
|
|
205
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Swap the bearer in our `OTEL_EXPORTER_OTLP_HEADERS` for the current one.
|
|
286
|
+
*
|
|
287
|
+
* Only when a setup recorded the key as ours, and only the bearer in it
|
|
288
|
+
* changes. No backup: one per rotation would collect copies of every token.
|
|
289
|
+
*
|
|
290
|
+
* @param context - The recorded file, its contents as read, install state and the current bearer.
|
|
291
|
+
* @returns True when the file was rewritten.
|
|
292
|
+
*/
|
|
293
|
+
async rewriteBearer(context) {
|
|
294
|
+
if (!context.installState.agents[GEMINI_PROVIDER_ID]?.otelOwnedKeys.includes(OTLP_HEADERS_KEY))
|
|
295
|
+
return false;
|
|
296
|
+
const settings = parseJsonLine(context.raw);
|
|
297
|
+
const envBlock = asRecord(settings?.[ENV_BLOCK_KEY]);
|
|
298
|
+
const headers = envBlock?.[OTLP_HEADERS_KEY];
|
|
299
|
+
if (!envBlock || typeof headers !== 'string')
|
|
300
|
+
return false;
|
|
301
|
+
const next = headers.replace(RE_BEARER_PAIR, (_match, head) => head + context.bearer);
|
|
302
|
+
if (next === headers)
|
|
303
|
+
return false;
|
|
304
|
+
// In place when the value appears once as written, so the developer's
|
|
305
|
+
// formatting survives every rotation; re-serialized only when it does not.
|
|
306
|
+
const written = JSON.stringify(headers);
|
|
307
|
+
const at = context.raw.indexOf(written);
|
|
308
|
+
const inPlace = at !== -1 && at === context.raw.lastIndexOf(written) ? context.raw.slice(0, at) + JSON.stringify(next) + context.raw.slice(at + written.length) : '';
|
|
309
|
+
const contents = asRecord(parseJsonLine(inPlace)?.[ENV_BLOCK_KEY])?.[OTLP_HEADERS_KEY] === next
|
|
310
|
+
? inPlace
|
|
311
|
+
: `${JSON.stringify({ ...settings, [ENV_BLOCK_KEY]: { ...envBlock, [OTLP_HEADERS_KEY]: next } }, null, 2)}\n`;
|
|
312
|
+
return writeIfUnchanged(context.configPath, context.raw, contents, SECRET_FILE_MODE);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Signals Gemini was asked for but will not be given under current consent.
|
|
316
|
+
*
|
|
317
|
+
* Its usage logs always carry function arguments, and its detailed traces can
|
|
318
|
+
* carry prompts — so logs wait on tool-content consent and traces are never
|
|
319
|
+
* given, which is why the answer is per signal rather than all-or-nothing.
|
|
320
|
+
*
|
|
321
|
+
* @param config - Effective configuration.
|
|
322
|
+
* @returns The requested signals that are held back; empty when none are.
|
|
323
|
+
*/
|
|
324
|
+
withheldSignals(config) {
|
|
325
|
+
const safe = safeGeminiSignals(config);
|
|
326
|
+
return enabledSignalNames(config.otel).filter((name) => !safe[name]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Gemini logs always carry function arguments, so they need tool-content
|
|
331
|
+
* consent. Detailed traces can carry prompts unbounded and unscrubbed, outside
|
|
332
|
+
* the summary's `promptText` path, so no configuration makes them safe.
|
|
333
|
+
* @param config - Global, consent-gated configuration.
|
|
334
|
+
* @returns The signals safe to materialize in Gemini settings.
|
|
335
|
+
*/
|
|
336
|
+
function safeGeminiSignals(config) {
|
|
337
|
+
return {
|
|
338
|
+
logs: config.otel.logs && toolContentConsented(config),
|
|
339
|
+
traces: false,
|
|
340
|
+
metrics: config.otel.metrics
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Whether Gemini has at least one safe signal to export.
|
|
345
|
+
* @param signals - Consent-filtered signal selection.
|
|
346
|
+
* @returns True when one signal remains.
|
|
347
|
+
*/
|
|
348
|
+
function anySignal(signals) {
|
|
349
|
+
return signals.logs || signals.traces || signals.metrics;
|
|
206
350
|
}
|
|
207
351
|
/**
|
|
208
352
|
* Settings keys a previous AgentWatch setup recorded as its own.
|
|
@@ -224,7 +368,7 @@ function ownedKeysOf(context) {
|
|
|
224
368
|
function inspectDisabled(settings, envBlock, ownedKeys) {
|
|
225
369
|
const leftover = ownedKeys.some((key) => (key === LEGACY_HELPER_KEY ? settings[key] !== undefined : envBlock[key] !== undefined)) || hasOurLegacyHelper(settings);
|
|
226
370
|
if (!leftover)
|
|
227
|
-
return { supported: true, configured: true, detail: 'disabled
|
|
371
|
+
return { supported: true, configured: true, detail: 'disabled by config or content consent' };
|
|
228
372
|
return {
|
|
229
373
|
supported: true,
|
|
230
374
|
configured: false,
|
|
@@ -240,7 +384,7 @@ function inspectDisabled(settings, envBlock, ownedKeys) {
|
|
|
240
384
|
* @returns The conflicting key names.
|
|
241
385
|
*/
|
|
242
386
|
function foreignKeys(envBlock, desired, ownedKeys) {
|
|
243
|
-
const owned = new Set(ownedKeys);
|
|
387
|
+
const owned = new Set([...ownedKeys, ...Object.keys(CONTENT_LOG_OFF)]);
|
|
244
388
|
return Object.keys(desired).filter((key) => envBlock[key] !== undefined && envBlock[key] !== desired[key] && !owned.has(key));
|
|
245
389
|
}
|
|
246
390
|
/**
|
|
@@ -2,7 +2,7 @@ import { hookRefusal } from '../shared/hook-refusal.js';
|
|
|
2
2
|
import { GEMINI_PROMPT_EVENTS } from './constants/gemini.constants.js';
|
|
3
3
|
import { detectGemini } from './gemini.detect.js';
|
|
4
4
|
import { installGeminiHooks, uninstallGeminiHooks } from './gemini.hooks.js';
|
|
5
|
-
import { parseGeminiHookEvent } from './gemini.adapter.js';
|
|
5
|
+
import { geminiShellCall, parseGeminiHookEvent } from './gemini.adapter.js';
|
|
6
6
|
import { GeminiOtelConfigurator } from './gemini.otel.js';
|
|
7
7
|
export const geminiProvider = {
|
|
8
8
|
id: 'gemini',
|
|
@@ -18,5 +18,6 @@ export const geminiProvider = {
|
|
|
18
18
|
* set across both namings — exactly the hooks a refusal may travel on.
|
|
19
19
|
*/
|
|
20
20
|
getBlockResponse: (payload, message) => hookRefusal(payload, GEMINI_PROMPT_EVENTS, { decision: 'deny', reason: message }),
|
|
21
|
+
shellCall: geminiShellCall,
|
|
21
22
|
nativeTelemetry: new GeminiOtelConfigurator()
|
|
22
23
|
};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTelemetryConfigurator, NativeTelemetryStatus, ProviderHookResponse, SetupContext, SetupOutcome, ToolKind, ToolStatus } from './types/provider.types.js';
|
|
7
7
|
export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
|
|
8
8
|
export { isAgentWatchHookCommand } from './provider.js';
|
|
9
|
-
export {
|
|
9
|
+
export { loadProvider, providerIds, providers } from './registry.js';
|
|
10
10
|
export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
|
|
11
11
|
export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
|
|
12
12
|
export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
|
package/dist/providers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { HOOK_COMMAND_MARKER, KNOWN_AGENT_IDS } from './constants/provider.constants.js';
|
|
2
2
|
export { isAgentWatchHookCommand } from './provider.js';
|
|
3
|
-
export {
|
|
3
|
+
export { loadProvider, providerIds, providers } from './registry.js';
|
|
4
4
|
export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMcpToolName, toolCompleteType, toolStartType } from './shared/tooling.js';
|
|
5
5
|
export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
|
|
6
6
|
export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentProvider } from './types/provider.types.js';
|
|
2
|
+
/** Every agent id the CLI accepts, for help and error messages. */
|
|
3
|
+
export declare const providerIds: readonly string[];
|
|
4
|
+
/**
|
|
5
|
+
* The provider for an agent id, loading only that agent's code.
|
|
6
|
+
*
|
|
7
|
+
* @param id - Agent id as passed to `agentwatch hook --agent <id>`.
|
|
8
|
+
* @returns The provider, or undefined for an unknown agent.
|
|
9
|
+
*/
|
|
10
|
+
export declare function loadProvider(id: string): Promise<AgentProvider | undefined>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One dynamic import per agent, so a hook loads the agent it was invoked for
|
|
3
|
+
* and no other.
|
|
4
|
+
*
|
|
5
|
+
* The hook path resolves exactly one provider per invocation, and importing the
|
|
6
|
+
* eager registry pulled in all five with their adapters, schemas and constants
|
|
7
|
+
* — measurably the largest single cost in the hook's own import graph, paid ten
|
|
8
|
+
* to fifteen times per turn on every developer's machine. `cli.ts` already goes
|
|
9
|
+
* to trouble to lazy-import command modules "so the hook path does not pay
|
|
10
|
+
* their startup"; this is the same argument applied to the agents.
|
|
11
|
+
*
|
|
12
|
+
* This literal and `registry.providers` are two hand-maintained lists of the
|
|
13
|
+
* same five agents, and they cannot be derived from one another: the eager list
|
|
14
|
+
* holds the provider objects, and having these loaders produce it would import
|
|
15
|
+
* every agent, which is the cost this file exists to avoid. `tests/providers.test.ts`
|
|
16
|
+
* asserts the two agree, so a sixth agent registered in only one of them fails
|
|
17
|
+
* the suite rather than installing hooks whose every invocation resolves no
|
|
18
|
+
* provider and drops the agent's telemetry in silence.
|
|
19
|
+
*/
|
|
20
|
+
const PROVIDER_LOADERS = {
|
|
21
|
+
claude: async () => (await import('./claude/claude.provider.js')).claudeProvider,
|
|
22
|
+
codex: async () => (await import('./codex/codex.provider.js')).codexProvider,
|
|
23
|
+
cursor: async () => (await import('./cursor/cursor.provider.js')).cursorProvider,
|
|
24
|
+
gemini: async () => (await import('./gemini/gemini.provider.js')).geminiProvider,
|
|
25
|
+
antigravity: async () => (await import('./antigravity/antigravity.provider.js')).antigravityProvider
|
|
26
|
+
};
|
|
27
|
+
/** Every agent id the CLI accepts, for help and error messages. */
|
|
28
|
+
export const providerIds = Object.keys(PROVIDER_LOADERS);
|
|
29
|
+
/**
|
|
30
|
+
* The provider for an agent id, loading only that agent's code.
|
|
31
|
+
*
|
|
32
|
+
* @param id - Agent id as passed to `agentwatch hook --agent <id>`.
|
|
33
|
+
* @returns The provider, or undefined for an unknown agent.
|
|
34
|
+
*/
|
|
35
|
+
export async function loadProvider(id) {
|
|
36
|
+
const load = PROVIDER_LOADERS[id];
|
|
37
|
+
if (!load)
|
|
38
|
+
return undefined;
|
|
39
|
+
return load();
|
|
40
|
+
}
|
|
@@ -14,3 +14,14 @@ export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTe
|
|
|
14
14
|
* @returns True only when AgentWatch wrote it.
|
|
15
15
|
*/
|
|
16
16
|
export declare function isAgentWatchHookCommand(command: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Minimal tokenizer for the exact commands buildHookCommand emits.
|
|
19
|
+
*
|
|
20
|
+
* Supports quoted paths and their escaped quote/backslash forms, and rejects
|
|
21
|
+
* any command containing a shell control operator — a command we cannot fully
|
|
22
|
+
* understand is one we must not claim ownership of.
|
|
23
|
+
*
|
|
24
|
+
* @param command - The command line.
|
|
25
|
+
* @returns Its tokens, or undefined when the command is not one we emit.
|
|
26
|
+
*/
|
|
27
|
+
export declare function tokenizeHookCommand(command: string): string[] | undefined;
|
|
@@ -99,7 +99,7 @@ function pathBase(value) {
|
|
|
99
99
|
* @param command - The command line.
|
|
100
100
|
* @returns Its tokens, or undefined when the command is not one we emit.
|
|
101
101
|
*/
|
|
102
|
-
function tokenizeHookCommand(command) {
|
|
102
|
+
export function tokenizeHookCommand(command) {
|
|
103
103
|
const tokens = [];
|
|
104
104
|
let token = '';
|
|
105
105
|
let started = false;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { AgentProvider } from './types/provider.types.js';
|
|
2
|
-
|
|
3
|
-
export declare const providers: readonly AgentProvider[];
|
|
2
|
+
export { loadProvider, providerIds } from './loaders.js';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Every provider, eagerly.
|
|
5
|
+
*
|
|
6
|
+
* For the commands that genuinely need all five — `setup`, `status`, `doctor`,
|
|
7
|
+
* `uninstall`, `toggle` — each of which asks every agent about itself. The hook
|
|
8
|
+
* path must not import this module: it needs one agent, and `loadProvider` in
|
|
9
|
+
* `loaders.js` is how it gets exactly that one.
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
11
|
+
* Adding an agent = implementing AgentProvider, registering it here, and adding
|
|
12
|
+
* its loader in `loaders.js`. Both, or `tests/providers.test.ts` fails: an agent
|
|
13
|
+
* present here and missing there installs hooks that resolve no provider.
|
|
9
14
|
*/
|
|
10
|
-
export declare
|
|
11
|
-
/** Every agent id the CLI accepts, for help and error messages. */
|
|
12
|
-
export declare const providerIds: readonly string[];
|
|
15
|
+
export declare const providers: readonly AgentProvider[];
|
|
@@ -3,21 +3,17 @@ import { claudeProvider } from './claude/claude.provider.js';
|
|
|
3
3
|
import { codexProvider } from './codex/codex.provider.js';
|
|
4
4
|
import { cursorProvider } from './cursor/cursor.provider.js';
|
|
5
5
|
import { geminiProvider } from './gemini/gemini.provider.js';
|
|
6
|
-
|
|
7
|
-
export const providers = [claudeProvider, codexProvider, cursorProvider, geminiProvider, antigravityProvider];
|
|
8
|
-
/**
|
|
9
|
-
* Index built once at module load: the hook path resolves a provider on every
|
|
10
|
-
* single invocation, and a linear scan there is pure waste (STYLEGUIDE 3.2).
|
|
11
|
-
*/
|
|
12
|
-
const byId = new Map(providers.map((provider) => [provider.id, provider]));
|
|
6
|
+
export { loadProvider, providerIds } from './loaders.js';
|
|
13
7
|
/**
|
|
14
|
-
*
|
|
8
|
+
* Every provider, eagerly.
|
|
15
9
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
10
|
+
* For the commands that genuinely need all five — `setup`, `status`, `doctor`,
|
|
11
|
+
* `uninstall`, `toggle` — each of which asks every agent about itself. The hook
|
|
12
|
+
* path must not import this module: it needs one agent, and `loadProvider` in
|
|
13
|
+
* `loaders.js` is how it gets exactly that one.
|
|
14
|
+
*
|
|
15
|
+
* Adding an agent = implementing AgentProvider, registering it here, and adding
|
|
16
|
+
* its loader in `loaders.js`. Both, or `tests/providers.test.ts` fails: an agent
|
|
17
|
+
* present here and missing there installs hooks that resolve no provider.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
return byId.get(id);
|
|
21
|
-
}
|
|
22
|
-
/** Every agent id the CLI accepts, for help and error messages. */
|
|
23
|
-
export const providerIds = providers.map((provider) => provider.id);
|
|
19
|
+
export const providers = [claudeProvider, codexProvider, cursorProvider, geminiProvider, antigravityProvider];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Put the machine's current access token into every agent config that holds
|
|
4
|
+
* a literal OTLP bearer (Codex, Gemini).
|
|
5
|
+
*
|
|
6
|
+
* They read that header once, when a session starts
|
|
7
|
+
* (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
|
|
8
|
+
* for the next session. An agent is loaded only when its file holds a bearer
|
|
9
|
+
* that is not this one, so the usual hook pays one small read per agent and no
|
|
10
|
+
* import. Each agent changes nothing but its own bearer.
|
|
11
|
+
*
|
|
12
|
+
* Never throws: a file that cannot be read or written is left as it is, and
|
|
13
|
+
* the next hook tries again.
|
|
14
|
+
*
|
|
15
|
+
* @param paths - Resolved AgentWatch paths, for the install state.
|
|
16
|
+
* @param bearer - The machine's current access token.
|
|
17
|
+
* @returns How many files were rewritten.
|
|
18
|
+
*/
|
|
19
|
+
export declare function rewriteNativeBearers(paths: AgentWatchPaths, bearer: string): Promise<number>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { debugLog } from '../../core/logger.js';
|
|
3
|
+
import { loadInstallState } from '../../storage/install-state.js';
|
|
4
|
+
import { BEARER_PREFIX } from '../constants/provider.constants.js';
|
|
5
|
+
import { loadProvider } from '../loaders.js';
|
|
6
|
+
/**
|
|
7
|
+
* Put the machine's current access token into every agent config that holds
|
|
8
|
+
* a literal OTLP bearer (Codex, Gemini).
|
|
9
|
+
*
|
|
10
|
+
* They read that header once, when a session starts
|
|
11
|
+
* (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
|
|
12
|
+
* for the next session. An agent is loaded only when its file holds a bearer
|
|
13
|
+
* that is not this one, so the usual hook pays one small read per agent and no
|
|
14
|
+
* import. Each agent changes nothing but its own bearer.
|
|
15
|
+
*
|
|
16
|
+
* Never throws: a file that cannot be read or written is left as it is, and
|
|
17
|
+
* the next hook tries again.
|
|
18
|
+
*
|
|
19
|
+
* @param paths - Resolved AgentWatch paths, for the install state.
|
|
20
|
+
* @param bearer - The machine's current access token.
|
|
21
|
+
* @returns How many files were rewritten.
|
|
22
|
+
*/
|
|
23
|
+
export async function rewriteNativeBearers(paths, bearer) {
|
|
24
|
+
let rewritten = 0;
|
|
25
|
+
try {
|
|
26
|
+
const installState = await loadInstallState(paths);
|
|
27
|
+
for (const [id, agent] of Object.entries(installState.agents)) {
|
|
28
|
+
const configPath = agent.otelConfigPath;
|
|
29
|
+
const raw = configPath ? await fs.readFile(configPath, 'utf8').catch(() => '') : '';
|
|
30
|
+
if (!configPath || !raw.includes(BEARER_PREFIX) || raw.includes(BEARER_PREFIX + bearer))
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
const configurator = (await loadProvider(id))?.nativeTelemetry;
|
|
34
|
+
if (await configurator?.rewriteBearer?.({ configPath, installState, bearer, raw }))
|
|
35
|
+
rewritten++;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
debugLog(`${id}: rewriting the native exporter bearer failed:`, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
debugLog('rewriting native exporter bearers failed:', error);
|
|
44
|
+
}
|
|
45
|
+
return rewritten;
|
|
46
|
+
}
|
|
@@ -4,3 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Every JSON hook protocol AgentWatch registers names its event under this key. */
|
|
6
6
|
export declare const PAYLOAD_HOOK_EVENT_KEY = "hook_event_name";
|
|
7
|
+
/**
|
|
8
|
+
* The hooks a notice travels on, in both Claude Code and Codex: the untraced
|
|
9
|
+
* notice after a run, the update notice as a session starts. Both protocols
|
|
10
|
+
* take `systemMessage` on each (Codex: `SessionStartCommandOutputWire` flattens
|
|
11
|
+
* `HookUniversalOutputWire`, checked 2026-10-13).
|
|
12
|
+
*/
|
|
13
|
+
export declare const NOTICE_EVENTS: ReadonlySet<string>;
|
|
@@ -4,3 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Every JSON hook protocol AgentWatch registers names its event under this key. */
|
|
6
6
|
export const PAYLOAD_HOOK_EVENT_KEY = 'hook_event_name';
|
|
7
|
+
/**
|
|
8
|
+
* The hooks a notice travels on, in both Claude Code and Codex: the untraced
|
|
9
|
+
* notice after a run, the update notice as a session starts. Both protocols
|
|
10
|
+
* take `systemMessage` on each (Codex: `SessionStartCommandOutputWire` flattens
|
|
11
|
+
* `HookUniversalOutputWire`, checked 2026-10-13).
|
|
12
|
+
*/
|
|
13
|
+
export const NOTICE_EVENTS = new Set(['PostToolUse', 'SessionStart']);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patterns the shell-directory reader uses. Every one of them is applied to a
|
|
3
|
+
* command held in memory inside one pipeline stage; see `shell-directories.ts`.
|
|
4
|
+
*/
|
|
5
|
+
/** A heredoc and its body: file content, not the command. */
|
|
6
|
+
export declare const RE_HEREDOC: RegExp;
|
|
7
|
+
/** What a heredoc is replaced with, so the command around it still reads. */
|
|
8
|
+
export declare const HEREDOC_PLACEHOLDER = "<<HEREDOC";
|
|
9
|
+
/** Command separators: each piece is read on its own, in order. */
|
|
10
|
+
export declare const RE_SHELL_SEPARATORS: RegExp;
|
|
11
|
+
/** `cd X` / `pushd X`: X is a directory, and later relative paths resolve against it. */
|
|
12
|
+
export declare const RE_CHANGE_DIRECTORY: RegExp;
|
|
13
|
+
/** Arguments that name a directory outright, relative or not. */
|
|
14
|
+
export declare const RE_DIRECTORY_ARGUMENTS: readonly RegExp[];
|
|
15
|
+
/** A quoted absolute or home-relative path anywhere in the command. */
|
|
16
|
+
export declare const RE_QUOTED_ABSOLUTE: RegExp;
|
|
17
|
+
/** A bare absolute or home-relative path, not glued to a longer word. */
|
|
18
|
+
export declare const RE_BARE_ABSOLUTE: RegExp;
|
|
19
|
+
/** A bare `./` or `../` path. */
|
|
20
|
+
export declare const RE_DOT_RELATIVE: RegExp;
|
|
21
|
+
/** `./x` or `../x`: relative on purpose, so resolved even outside a directory argument. */
|
|
22
|
+
export declare const RE_DOT_PREFIX: RegExp;
|
|
23
|
+
/** Home spelled the three ways a command spells it. */
|
|
24
|
+
export declare const RE_HOME_PREFIX: RegExp;
|
|
25
|
+
/** Anything the shell would still expand: not a path this reader can know. */
|
|
26
|
+
export declare const RE_UNEXPANDED: RegExp;
|
|
27
|
+
/** Surrounding quotes of one argument. */
|
|
28
|
+
export declare const RE_SURROUNDING_QUOTES: RegExp;
|
|
29
|
+
/** Directories one command may name before the rest are ignored: each one costs a walk of `stat`s. */
|
|
30
|
+
export declare const MAX_SHELL_DIRECTORIES = 32;
|