@agent-watch-ai/edge 0.2.5
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 +251 -0
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/billing/billing-mode.d.ts +16 -0
- package/dist/billing/billing-mode.js +139 -0
- package/dist/billing/constants/billing.constants.d.ts +37 -0
- package/dist/billing/constants/billing.constants.js +38 -0
- package/dist/billing/index.d.ts +6 -0
- package/dist/billing/index.js +6 -0
- package/dist/cli/args.d.ts +29 -0
- package/dist/cli/args.js +61 -0
- package/dist/cli/constants/cli.constants.d.ts +60 -0
- package/dist/cli/constants/cli.constants.js +60 -0
- package/dist/cli/context.d.ts +51 -0
- package/dist/cli/context.js +108 -0
- package/dist/cli/doctor.d.ts +15 -0
- package/dist/cli/doctor.js +416 -0
- package/dist/cli/hook.d.ts +20 -0
- package/dist/cli/hook.js +166 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/misc.d.ts +31 -0
- package/dist/cli/misc.js +63 -0
- package/dist/cli/setup.d.ts +32 -0
- package/dist/cli/setup.js +298 -0
- package/dist/cli/status.d.ts +11 -0
- package/dist/cli/status.js +174 -0
- package/dist/cli/types/cli.types.d.ts +69 -0
- package/dist/cli/types/cli.types.js +1 -0
- package/dist/cli/ui.d.ts +41 -0
- package/dist/cli/ui.js +78 -0
- package/dist/cli/uninstall.d.ts +13 -0
- package/dist/cli/uninstall.js +83 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +124 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +75 -0
- package/dist/config/config.d.ts +73 -0
- package/dist/config/config.js +115 -0
- package/dist/config/constants/config.constants.d.ts +62 -0
- package/dist/config/constants/config.constants.js +70 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +5 -0
- package/dist/config/repo-config.d.ts +37 -0
- package/dist/config/repo-config.js +178 -0
- package/dist/config/schemas/config.schema.d.ts +409 -0
- package/dist/config/schemas/config.schema.js +97 -0
- package/dist/config/types/config.types.d.ts +33 -0
- package/dist/config/types/config.types.js +1 -0
- package/dist/core/async.d.ts +20 -0
- package/dist/core/async.js +32 -0
- package/dist/core/constants/core.constants.d.ts +18 -0
- package/dist/core/constants/core.constants.js +18 -0
- package/dist/core/env.d.ts +12 -0
- package/dist/core/env.js +20 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/logger.d.ts +27 -0
- package/dist/core/logger.js +82 -0
- package/dist/core/number.d.ts +33 -0
- package/dist/core/number.js +47 -0
- package/dist/core/object.d.ts +78 -0
- package/dist/core/object.js +127 -0
- package/dist/core/pipe.d.ts +55 -0
- package/dist/core/pipe.js +81 -0
- package/dist/core/types/core.types.d.ts +54 -0
- package/dist/core/types/core.types.js +4 -0
- package/dist/core/version.d.ts +19 -0
- package/dist/core/version.js +35 -0
- package/dist/core/which.d.ts +13 -0
- package/dist/core/which.js +57 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +23 -0
- package/dist/enforcement/constants/enforcement.constants.js +22 -0
- package/dist/enforcement/decision-cache.d.ts +57 -0
- package/dist/enforcement/decision-cache.js +138 -0
- package/dist/enforcement/decision-client.d.ts +14 -0
- package/dist/enforcement/decision-client.js +84 -0
- package/dist/enforcement/enforcement.d.ts +17 -0
- package/dist/enforcement/enforcement.js +90 -0
- package/dist/enforcement/index.d.ts +11 -0
- package/dist/enforcement/index.js +10 -0
- package/dist/enforcement/schemas/enforcement.schema.d.ts +30 -0
- package/dist/enforcement/schemas/enforcement.schema.js +36 -0
- package/dist/enforcement/types/enforcement.types.d.ts +59 -0
- package/dist/enforcement/types/enforcement.types.js +1 -0
- package/dist/enrollment/constants/enrollment.constants.d.ts +6 -0
- package/dist/enrollment/constants/enrollment.constants.js +6 -0
- package/dist/enrollment/enrollment-provider.d.ts +5 -0
- package/dist/enrollment/enrollment-provider.js +1 -0
- package/dist/enrollment/index.d.ts +7 -0
- package/dist/enrollment/index.js +1 -0
- package/dist/enrollment/manual-enrollment.d.ts +32 -0
- package/dist/enrollment/manual-enrollment.js +72 -0
- package/dist/enrollment/types/enrollment.types.d.ts +25 -0
- package/dist/enrollment/types/enrollment.types.js +1 -0
- package/dist/events/canonical-event.d.ts +10 -0
- package/dist/events/canonical-event.js +9 -0
- package/dist/events/constants/enrich.constants.d.ts +14 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +35 -0
- package/dist/events/constants/events.constants.js +57 -0
- package/dist/events/enrich.d.ts +16 -0
- package/dist/events/enrich.js +226 -0
- package/dist/events/event-id.d.ts +32 -0
- package/dist/events/event-id.js +49 -0
- package/dist/events/index.d.ts +14 -0
- package/dist/events/index.js +5 -0
- package/dist/events/llm-call.d.ts +14 -0
- package/dist/events/llm-call.js +84 -0
- package/dist/events/product-event.d.ts +39 -0
- package/dist/events/product-event.js +19 -0
- package/dist/events/types/enrich.types.d.ts +25 -0
- package/dist/events/types/enrich.types.js +1 -0
- package/dist/events/types/events.types.d.ts +112 -0
- package/dist/events/types/events.types.js +1 -0
- package/dist/events/types/llm-call.types.d.ts +79 -0
- package/dist/events/types/llm-call.types.js +1 -0
- package/dist/events/types/repo-snapshot.types.d.ts +32 -0
- package/dist/events/types/repo-snapshot.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +10 -0
- package/dist/feature/constants/feature.constants.js +10 -0
- package/dist/feature/index.d.ts +6 -0
- package/dist/feature/index.js +6 -0
- package/dist/feature/ticket-candidates.d.ts +13 -0
- package/dist/feature/ticket-candidates.js +26 -0
- package/dist/git/constants/git.constants.d.ts +84 -0
- package/dist/git/constants/git.constants.js +113 -0
- package/dist/git/git-context.d.ts +52 -0
- package/dist/git/git-context.js +226 -0
- package/dist/git/index.d.ts +9 -0
- package/dist/git/index.js +3 -0
- package/dist/git/remote-sanitize.d.ts +26 -0
- package/dist/git/remote-sanitize.js +92 -0
- package/dist/git/repo-snapshot.d.ts +40 -0
- package/dist/git/repo-snapshot.js +95 -0
- package/dist/git/types/git.types.d.ts +36 -0
- package/dist/git/types/git.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +25 -0
- package/dist/git/types/snapshot.types.js +1 -0
- package/dist/otlp/constants/otlp.constants.d.ts +84 -0
- package/dist/otlp/constants/otlp.constants.js +99 -0
- package/dist/otlp/http.d.ts +24 -0
- package/dist/otlp/http.js +37 -0
- package/dist/otlp/index.d.ts +9 -0
- package/dist/otlp/index.js +3 -0
- package/dist/otlp/normalize.d.ts +14 -0
- package/dist/otlp/normalize.js +404 -0
- package/dist/otlp/types/otlp.types.d.ts +69 -0
- package/dist/otlp/types/otlp.types.js +1 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +23 -0
- package/dist/pipeline/constants/pipeline.constants.js +22 -0
- package/dist/pipeline/hook-pipeline.d.ts +14 -0
- package/dist/pipeline/hook-pipeline.js +297 -0
- package/dist/pipeline/index.d.ts +6 -0
- package/dist/pipeline/index.js +1 -0
- package/dist/pipeline/types/pipeline.types.d.ts +48 -0
- package/dist/pipeline/types/pipeline.types.js +1 -0
- package/dist/privacy/constants/privacy.constants.d.ts +23 -0
- package/dist/privacy/constants/privacy.constants.js +38 -0
- package/dist/privacy/index.d.ts +7 -0
- package/dist/privacy/index.js +2 -0
- package/dist/privacy/sanitizer.d.ts +20 -0
- package/dist/privacy/sanitizer.js +52 -0
- package/dist/privacy/types/privacy.types.d.ts +13 -0
- package/dist/privacy/types/privacy.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +54 -0
- package/dist/providers/antigravity/antigravity.adapter.js +311 -0
- package/dist/providers/antigravity/antigravity.detect.d.ts +25 -0
- package/dist/providers/antigravity/antigravity.detect.js +64 -0
- package/dist/providers/antigravity/antigravity.hooks.d.ts +24 -0
- package/dist/providers/antigravity/antigravity.hooks.js +126 -0
- package/dist/providers/antigravity/antigravity.provider.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.provider.js +22 -0
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +72 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +75 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +521 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.js +64 -0
- package/dist/providers/antigravity/types/antigravity.types.d.ts +13 -0
- package/dist/providers/antigravity/types/antigravity.types.js +1 -0
- package/dist/providers/claude/claude.adapter.d.ts +15 -0
- package/dist/providers/claude/claude.adapter.js +141 -0
- package/dist/providers/claude/claude.detect.d.ts +20 -0
- package/dist/providers/claude/claude.detect.js +57 -0
- package/dist/providers/claude/claude.hooks.d.ts +23 -0
- package/dist/providers/claude/claude.hooks.js +94 -0
- package/dist/providers/claude/claude.otel.d.ts +95 -0
- package/dist/providers/claude/claude.otel.js +331 -0
- package/dist/providers/claude/claude.provider.d.ts +2 -0
- package/dist/providers/claude/claude.provider.js +26 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +34 -0
- package/dist/providers/claude/constants/claude.constants.js +54 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +17 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +17 -0
- package/dist/providers/claude/schemas/claude.schema.d.ts +72 -0
- package/dist/providers/claude/schemas/claude.schema.js +32 -0
- package/dist/providers/claude/types/claude.types.d.ts +3 -0
- package/dist/providers/claude/types/claude.types.js +1 -0
- package/dist/providers/codex/codex.adapter.d.ts +11 -0
- package/dist/providers/codex/codex.adapter.js +106 -0
- package/dist/providers/codex/codex.detect.d.ts +30 -0
- package/dist/providers/codex/codex.detect.js +58 -0
- package/dist/providers/codex/codex.hooks.d.ts +27 -0
- package/dist/providers/codex/codex.hooks.js +129 -0
- package/dist/providers/codex/codex.otel.d.ts +51 -0
- package/dist/providers/codex/codex.otel.js +325 -0
- package/dist/providers/codex/codex.provider.d.ts +2 -0
- package/dist/providers/codex/codex.provider.js +25 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +41 -0
- package/dist/providers/codex/constants/codex.constants.js +62 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +22 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +22 -0
- package/dist/providers/codex/schemas/codex.schema.d.ts +70 -0
- package/dist/providers/codex/schemas/codex.schema.js +32 -0
- package/dist/providers/codex/types/codex.types.d.ts +3 -0
- package/dist/providers/codex/types/codex.types.js +1 -0
- package/dist/providers/constants/provider.constants.d.ts +33 -0
- package/dist/providers/constants/provider.constants.js +33 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +58 -0
- package/dist/providers/cursor/constants/cursor.constants.js +95 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +11 -0
- package/dist/providers/cursor/cursor.adapter.js +331 -0
- package/dist/providers/cursor/cursor.detect.d.ts +23 -0
- package/dist/providers/cursor/cursor.detect.js +66 -0
- package/dist/providers/cursor/cursor.hooks.d.ts +25 -0
- package/dist/providers/cursor/cursor.hooks.js +95 -0
- package/dist/providers/cursor/cursor.provider.d.ts +2 -0
- package/dist/providers/cursor/cursor.provider.js +27 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +130 -0
- package/dist/providers/cursor/schemas/cursor.schema.js +62 -0
- package/dist/providers/cursor/types/cursor.types.d.ts +3 -0
- package/dist/providers/cursor/types/cursor.types.js +1 -0
- package/dist/providers/gemini/constants/gemini.constants.d.ts +36 -0
- package/dist/providers/gemini/constants/gemini.constants.js +58 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +34 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.js +48 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +15 -0
- package/dist/providers/gemini/gemini.adapter.js +146 -0
- package/dist/providers/gemini/gemini.detect.d.ts +23 -0
- package/dist/providers/gemini/gemini.detect.js +78 -0
- package/dist/providers/gemini/gemini.hooks.d.ts +22 -0
- package/dist/providers/gemini/gemini.hooks.js +93 -0
- package/dist/providers/gemini/gemini.otel.d.ts +62 -0
- package/dist/providers/gemini/gemini.otel.js +274 -0
- package/dist/providers/gemini/gemini.provider.d.ts +2 -0
- package/dist/providers/gemini/gemini.provider.js +22 -0
- package/dist/providers/gemini/schemas/gemini.schema.d.ts +81 -0
- package/dist/providers/gemini/schemas/gemini.schema.js +35 -0
- package/dist/providers/gemini/types/gemini.types.d.ts +3 -0
- package/dist/providers/gemini/types/gemini.types.js +1 -0
- package/dist/providers/index.d.ts +14 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/provider.d.ts +16 -0
- package/dist/providers/provider.js +149 -0
- package/dist/providers/registry.d.ts +12 -0
- package/dist/providers/registry.js +23 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +6 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +6 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +25 -0
- package/dist/providers/shared/constants/tooling.constants.js +25 -0
- package/dist/providers/shared/event-builder.d.ts +85 -0
- package/dist/providers/shared/event-builder.js +166 -0
- package/dist/providers/shared/hook-config.d.ts +80 -0
- package/dist/providers/shared/hook-config.js +164 -0
- package/dist/providers/shared/hook-refusal.d.ts +16 -0
- package/dist/providers/shared/hook-refusal.js +33 -0
- package/dist/providers/shared/install-record.d.ts +75 -0
- package/dist/providers/shared/install-record.js +113 -0
- package/dist/providers/shared/tooling.d.ts +58 -0
- package/dist/providers/shared/tooling.js +103 -0
- package/dist/providers/shared/types/adapter.types.d.ts +54 -0
- package/dist/providers/shared/types/adapter.types.js +1 -0
- package/dist/providers/shared/types/hook-config.types.d.ts +32 -0
- package/dist/providers/shared/types/hook-config.types.js +1 -0
- package/dist/providers/types/provider.types.d.ts +98 -0
- package/dist/providers/types/provider.types.js +1 -0
- package/dist/snapshot/branch-selection.d.ts +37 -0
- package/dist/snapshot/branch-selection.js +69 -0
- package/dist/snapshot/budget.d.ts +41 -0
- package/dist/snapshot/budget.js +67 -0
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +11 -0
- package/dist/snapshot/constants/snapshot-stages.constants.js +11 -0
- package/dist/snapshot/constants/snapshot.constants.d.ts +56 -0
- package/dist/snapshot/constants/snapshot.constants.js +56 -0
- package/dist/snapshot/index.d.ts +16 -0
- package/dist/snapshot/index.js +6 -0
- package/dist/snapshot/snapshot-event.d.ts +17 -0
- package/dist/snapshot/snapshot-event.js +66 -0
- package/dist/snapshot/snapshot-pipeline.d.ts +14 -0
- package/dist/snapshot/snapshot-pipeline.js +163 -0
- package/dist/snapshot/snapshot-state.d.ts +55 -0
- package/dist/snapshot/snapshot-state.js +100 -0
- package/dist/snapshot/types/snapshot.types.d.ts +86 -0
- package/dist/snapshot/types/snapshot.types.js +1 -0
- package/dist/storage/atomic-file.d.ts +25 -0
- package/dist/storage/atomic-file.js +76 -0
- package/dist/storage/constants/storage.constants.d.ts +34 -0
- package/dist/storage/constants/storage.constants.js +35 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/install-state.d.ts +20 -0
- package/dist/storage/install-state.js +40 -0
- package/dist/storage/json-file.d.ts +13 -0
- package/dist/storage/json-file.js +31 -0
- package/dist/storage/lock.d.ts +15 -0
- package/dist/storage/lock.js +70 -0
- package/dist/storage/paths.d.ts +14 -0
- package/dist/storage/paths.js +42 -0
- package/dist/storage/schemas/storage.schema.d.ts +128 -0
- package/dist/storage/schemas/storage.schema.js +27 -0
- package/dist/storage/types/storage.types.d.ts +36 -0
- package/dist/storage/types/storage.types.js +1 -0
- package/dist/transport/constants/transport.constants.d.ts +47 -0
- package/dist/transport/constants/transport.constants.js +47 -0
- package/dist/transport/cooldown.d.ts +35 -0
- package/dist/transport/cooldown.js +62 -0
- package/dist/transport/delivery-stats.d.ts +65 -0
- package/dist/transport/delivery-stats.js +186 -0
- package/dist/transport/delivery.d.ts +26 -0
- package/dist/transport/delivery.js +80 -0
- package/dist/transport/headers.d.ts +12 -0
- package/dist/transport/headers.js +19 -0
- package/dist/transport/http-transport.d.ts +39 -0
- package/dist/transport/http-transport.js +106 -0
- package/dist/transport/index.d.ts +13 -0
- package/dist/transport/index.js +7 -0
- package/dist/transport/queue.d.ts +177 -0
- package/dist/transport/queue.js +474 -0
- package/dist/transport/schemas/queue.schema.d.ts +30 -0
- package/dist/transport/schemas/queue.schema.js +18 -0
- package/dist/transport/transport.d.ts +6 -0
- package/dist/transport/transport.js +1 -0
- package/dist/transport/types/transport.types.d.ts +102 -0
- package/dist/transport/types/transport.types.js +1 -0
- package/dist/turns/aggregate-usage.d.ts +20 -0
- package/dist/turns/aggregate-usage.js +269 -0
- package/dist/turns/claude-transcript.d.ts +18 -0
- package/dist/turns/claude-transcript.js +80 -0
- package/dist/turns/constants/turns.constants.d.ts +69 -0
- package/dist/turns/constants/turns.constants.js +86 -0
- package/dist/turns/cursor-transcript.d.ts +21 -0
- package/dist/turns/cursor-transcript.js +66 -0
- package/dist/turns/index.d.ts +17 -0
- package/dist/turns/index.js +7 -0
- package/dist/turns/transcript.d.ts +74 -0
- package/dist/turns/transcript.js +188 -0
- package/dist/turns/turn-state.d.ts +94 -0
- package/dist/turns/turn-state.js +234 -0
- package/dist/turns/turn-summary.d.ts +27 -0
- package/dist/turns/turn-summary.js +164 -0
- package/dist/turns/turn-tracker.d.ts +14 -0
- package/dist/turns/turn-tracker.js +521 -0
- package/dist/turns/types/aggregate-usage.types.d.ts +26 -0
- package/dist/turns/types/aggregate-usage.types.js +1 -0
- package/dist/turns/types/transcript.types.d.ts +41 -0
- package/dist/turns/types/transcript.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +37 -0
- package/dist/turns/types/turn-state.types.js +1 -0
- package/dist/turns/types/turn-summary.types.d.ts +106 -0
- package/dist/turns/types/turn-summary.types.js +1 -0
- package/dist/turns/types/turn-tracker.types.d.ts +27 -0
- package/dist/turns/types/turn-tracker.types.js +1 -0
- package/example/README.md +43 -0
- package/example/server.mjs +240 -0
- package/package.json +89 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { asRecord } from '../../core/object.js';
|
|
2
|
+
import { backupFile } from '../../storage/atomic-file.js';
|
|
3
|
+
import { readJsonFile } from '../../storage/json-file.js';
|
|
4
|
+
import { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, writeJsonValidated } from '../shared/hook-config.js';
|
|
5
|
+
import { withHookInstall, withoutHookInstall } from '../shared/install-record.js';
|
|
6
|
+
import { cursorHooksJsonPath } from './cursor.detect.js';
|
|
7
|
+
import { CURSOR_HOOKS_VERSION, CURSOR_HOOK_EVENTS, CURSOR_HOOK_TIMEOUT_SECONDS, CURSOR_PROVIDER_ID, CURSOR_USAGE_NOTE, CURSOR_VERSION_KEY } from './constants/cursor.constants.js';
|
|
8
|
+
export { CURSOR_HOOK_EVENTS } from './constants/cursor.constants.js';
|
|
9
|
+
/**
|
|
10
|
+
* Register AgentWatch's hooks in `~/.cursor/hooks.json`.
|
|
11
|
+
*
|
|
12
|
+
* Cursor's entries are flat command objects rather than matcher groups, so ours
|
|
13
|
+
* is one entry per event. An existing `version` is preserved verbatim — the
|
|
14
|
+
* documented schema is 1, but the user's file is the authority on what Cursor
|
|
15
|
+
* build wrote it.
|
|
16
|
+
*
|
|
17
|
+
* @param context - Environment, paths, config and the hook command to write.
|
|
18
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
19
|
+
* install state.
|
|
20
|
+
*/
|
|
21
|
+
export async function installCursorHooks(context) {
|
|
22
|
+
const hooksPath = cursorHooksJsonPath(context.env);
|
|
23
|
+
const read = await readJsonFile(hooksPath);
|
|
24
|
+
if (read.state === 'invalid') {
|
|
25
|
+
return { ok: false, changed: false, messages: [`refusing to modify unparseable ${hooksPath} (${read.error})`] };
|
|
26
|
+
}
|
|
27
|
+
if (read.state === 'ok' && !asRecord(read.value)) {
|
|
28
|
+
return { ok: false, changed: false, messages: [`refusing to modify ${hooksPath}: top level is not an object`] };
|
|
29
|
+
}
|
|
30
|
+
const file = (read.state === 'ok' ? asRecord(read.value) : undefined) ?? {};
|
|
31
|
+
const hooks = asRecord(file['hooks']) ?? {};
|
|
32
|
+
const registered = registerOurHandlers(hooks, CURSOR_HOOK_EVENTS, () => ourEntry(context.hookCommand), { allowBareHandlers: true });
|
|
33
|
+
const nextFile = {
|
|
34
|
+
...file,
|
|
35
|
+
[CURSOR_VERSION_KEY]: typeof file[CURSOR_VERSION_KEY] === 'number' ? file[CURSOR_VERSION_KEY] : CURSOR_HOOKS_VERSION,
|
|
36
|
+
hooks: sweepUnregisteredEvents(registered, CURSOR_HOOK_EVENTS, { allowBareHandlers: true })
|
|
37
|
+
};
|
|
38
|
+
const changed = JSON.stringify(nextFile) !== JSON.stringify(file);
|
|
39
|
+
if (changed) {
|
|
40
|
+
await backupFile(hooksPath, context.paths.backupsDir, context.env.now());
|
|
41
|
+
await writeJsonValidated(hooksPath, nextFile);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
changed,
|
|
46
|
+
messages: [changed ? `hooks registered in ${hooksPath}` : 'hooks already registered', CURSOR_USAGE_NOTE],
|
|
47
|
+
installState: withHookInstall(context.installState, CURSOR_PROVIDER_ID, {
|
|
48
|
+
hookConfigPath: hooksPath,
|
|
49
|
+
hookEvents: CURSOR_HOOK_EVENTS,
|
|
50
|
+
hookCommand: context.hookCommand,
|
|
51
|
+
installedAt: context.env.now()
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Remove AgentWatch's hooks from `~/.cursor/hooks.json`.
|
|
57
|
+
*
|
|
58
|
+
* Every other top-level field, `version` included, is preserved.
|
|
59
|
+
*
|
|
60
|
+
* @param context - Environment, paths and current install state.
|
|
61
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
62
|
+
* install state.
|
|
63
|
+
*/
|
|
64
|
+
export async function uninstallCursorHooks(context) {
|
|
65
|
+
const hooksPath = cursorHooksJsonPath(context.env);
|
|
66
|
+
const read = await readJsonFile(hooksPath);
|
|
67
|
+
if (read.state === 'missing')
|
|
68
|
+
return { ok: true, changed: false, messages: ['no Cursor hooks file'] };
|
|
69
|
+
const file = read.state === 'ok' ? asRecord(read.value) : undefined;
|
|
70
|
+
if (!file)
|
|
71
|
+
return { ok: false, changed: false, messages: [`cannot parse ${hooksPath}; not modified`] };
|
|
72
|
+
const hooks = asRecord(file['hooks']);
|
|
73
|
+
if (!hooks)
|
|
74
|
+
return { ok: true, changed: false, messages: ['no hooks configured'] };
|
|
75
|
+
const stripped = stripOurHandlers(hooks, { allowBareHandlers: true });
|
|
76
|
+
if (stripped.changed) {
|
|
77
|
+
await backupFile(hooksPath, context.paths.backupsDir, context.env.now());
|
|
78
|
+
await writeJsonValidated(hooksPath, { ...file, hooks: stripped.hooks });
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
ok: true,
|
|
82
|
+
changed: stripped.changed,
|
|
83
|
+
messages: stripped.changed ? ['AgentWatch hooks removed'] : ['no AgentWatch hooks found'],
|
|
84
|
+
installState: withoutHookInstall(context.installState, CURSOR_PROVIDER_ID)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Our entry: a flat command object, which is the only shape Cursor accepts.
|
|
89
|
+
*
|
|
90
|
+
* @param hookCommand - Command line agents will invoke.
|
|
91
|
+
* @returns The entry.
|
|
92
|
+
*/
|
|
93
|
+
function ourEntry(hookCommand) {
|
|
94
|
+
return { command: hookCommand, timeout: CURSOR_HOOK_TIMEOUT_SECONDS };
|
|
95
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { hookRefusal } from '../shared/hook-refusal.js';
|
|
2
|
+
import { CURSOR_PROMPT_SUBMIT_EVENTS } from './constants/cursor.constants.js';
|
|
3
|
+
import { detectCursor } from './cursor.detect.js';
|
|
4
|
+
import { installCursorHooks, uninstallCursorHooks } from './cursor.hooks.js';
|
|
5
|
+
import { parseCursorHookEvent } from './cursor.adapter.js';
|
|
6
|
+
export const cursorProvider = {
|
|
7
|
+
id: 'cursor',
|
|
8
|
+
displayName: 'Cursor',
|
|
9
|
+
detect: detectCursor,
|
|
10
|
+
installHooks: installCursorHooks,
|
|
11
|
+
uninstallHooks: uninstallCursorHooks,
|
|
12
|
+
parseHookEvent: async (payload, context) => parseCursorHookEvent(payload, context),
|
|
13
|
+
/**
|
|
14
|
+
* Cursor's before* hooks fail open and treat an absent `permission` field
|
|
15
|
+
* as allow; exit 0 with empty stdout is the observation-only response that
|
|
16
|
+
* never blocks the agent.
|
|
17
|
+
*/
|
|
18
|
+
getHookResponse: (_payload) => ({ exitCode: 0 }),
|
|
19
|
+
/**
|
|
20
|
+
* A budget refusal on `beforeSubmitPrompt`: the prompt is not submitted and
|
|
21
|
+
* `user_message` explains why.
|
|
22
|
+
*/
|
|
23
|
+
getBlockResponse: (payload, message) => hookRefusal(payload, CURSOR_PROMPT_SUBMIT_EVENTS, { continue: false, user_message: message })
|
|
24
|
+
// No nativeTelemetry: Cursor has no OTel export, so there is no llm.call
|
|
25
|
+
// ledger source. Turn summaries stay usage_status=pending until Cursor
|
|
26
|
+
// enriches its transcripts with usage (see cursor-transcript.ts).
|
|
27
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Cursor hook payload (verified against cursor.com/docs/hooks, 2026-08).
|
|
4
|
+
*
|
|
5
|
+
* Everything optional and passthrough: payloads are untrusted and a new field
|
|
6
|
+
* must never crash the agent's hook. Universal fields: conversation_id (stable
|
|
7
|
+
* per conversation), generation_id (changes per user message), model,
|
|
8
|
+
* workspace_roots, user_email, transcript_path.
|
|
9
|
+
*/
|
|
10
|
+
export declare const cursorPayloadSchema: z.ZodObject<{
|
|
11
|
+
hook_event_name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
conversation_id: z.ZodOptional<z.ZodString>;
|
|
13
|
+
generation_id: z.ZodOptional<z.ZodString>;
|
|
14
|
+
model: z.ZodOptional<z.ZodString>;
|
|
15
|
+
model_id: z.ZodOptional<z.ZodUnknown>;
|
|
16
|
+
model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
17
|
+
cursor_version: z.ZodOptional<z.ZodString>;
|
|
18
|
+
workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
+
transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
21
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
22
|
+
is_background_agent: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
composer_mode: z.ZodOptional<z.ZodString>;
|
|
24
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
25
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
26
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
27
|
+
tool_name: z.ZodOptional<z.ZodString>;
|
|
28
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
29
|
+
tool_input: z.ZodOptional<z.ZodUnknown>;
|
|
30
|
+
tool_output: z.ZodOptional<z.ZodUnknown>;
|
|
31
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
32
|
+
failure_type: z.ZodOptional<z.ZodString>;
|
|
33
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
command: z.ZodOptional<z.ZodString>;
|
|
36
|
+
output: z.ZodOptional<z.ZodString>;
|
|
37
|
+
url: z.ZodOptional<z.ZodString>;
|
|
38
|
+
result_json: z.ZodOptional<z.ZodString>;
|
|
39
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
40
|
+
edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
41
|
+
subagent_id: z.ZodOptional<z.ZodString>;
|
|
42
|
+
subagent_type: z.ZodOptional<z.ZodString>;
|
|
43
|
+
subagent_model: z.ZodOptional<z.ZodString>;
|
|
44
|
+
parent_conversation_id: z.ZodOptional<z.ZodString>;
|
|
45
|
+
task: z.ZodOptional<z.ZodString>;
|
|
46
|
+
status: z.ZodOptional<z.ZodString>;
|
|
47
|
+
text: z.ZodOptional<z.ZodString>;
|
|
48
|
+
trigger: z.ZodOptional<z.ZodString>;
|
|
49
|
+
context_usage_percent: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
51
|
+
hook_event_name: z.ZodOptional<z.ZodString>;
|
|
52
|
+
conversation_id: z.ZodOptional<z.ZodString>;
|
|
53
|
+
generation_id: z.ZodOptional<z.ZodString>;
|
|
54
|
+
model: z.ZodOptional<z.ZodString>;
|
|
55
|
+
model_id: z.ZodOptional<z.ZodUnknown>;
|
|
56
|
+
model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
57
|
+
cursor_version: z.ZodOptional<z.ZodString>;
|
|
58
|
+
workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
59
|
+
transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
61
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
62
|
+
is_background_agent: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
composer_mode: z.ZodOptional<z.ZodString>;
|
|
64
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
65
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
66
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
67
|
+
tool_name: z.ZodOptional<z.ZodString>;
|
|
68
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
69
|
+
tool_input: z.ZodOptional<z.ZodUnknown>;
|
|
70
|
+
tool_output: z.ZodOptional<z.ZodUnknown>;
|
|
71
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
72
|
+
failure_type: z.ZodOptional<z.ZodString>;
|
|
73
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
74
|
+
duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
command: z.ZodOptional<z.ZodString>;
|
|
76
|
+
output: z.ZodOptional<z.ZodString>;
|
|
77
|
+
url: z.ZodOptional<z.ZodString>;
|
|
78
|
+
result_json: z.ZodOptional<z.ZodString>;
|
|
79
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
80
|
+
edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
81
|
+
subagent_id: z.ZodOptional<z.ZodString>;
|
|
82
|
+
subagent_type: z.ZodOptional<z.ZodString>;
|
|
83
|
+
subagent_model: z.ZodOptional<z.ZodString>;
|
|
84
|
+
parent_conversation_id: z.ZodOptional<z.ZodString>;
|
|
85
|
+
task: z.ZodOptional<z.ZodString>;
|
|
86
|
+
status: z.ZodOptional<z.ZodString>;
|
|
87
|
+
text: z.ZodOptional<z.ZodString>;
|
|
88
|
+
trigger: z.ZodOptional<z.ZodString>;
|
|
89
|
+
context_usage_percent: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
91
|
+
hook_event_name: z.ZodOptional<z.ZodString>;
|
|
92
|
+
conversation_id: z.ZodOptional<z.ZodString>;
|
|
93
|
+
generation_id: z.ZodOptional<z.ZodString>;
|
|
94
|
+
model: z.ZodOptional<z.ZodString>;
|
|
95
|
+
model_id: z.ZodOptional<z.ZodUnknown>;
|
|
96
|
+
model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
97
|
+
cursor_version: z.ZodOptional<z.ZodString>;
|
|
98
|
+
workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
99
|
+
transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
100
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
101
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
102
|
+
is_background_agent: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
composer_mode: z.ZodOptional<z.ZodString>;
|
|
104
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
105
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
106
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
107
|
+
tool_name: z.ZodOptional<z.ZodString>;
|
|
108
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
109
|
+
tool_input: z.ZodOptional<z.ZodUnknown>;
|
|
110
|
+
tool_output: z.ZodOptional<z.ZodUnknown>;
|
|
111
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
112
|
+
failure_type: z.ZodOptional<z.ZodString>;
|
|
113
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
114
|
+
duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
115
|
+
command: z.ZodOptional<z.ZodString>;
|
|
116
|
+
output: z.ZodOptional<z.ZodString>;
|
|
117
|
+
url: z.ZodOptional<z.ZodString>;
|
|
118
|
+
result_json: z.ZodOptional<z.ZodString>;
|
|
119
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
120
|
+
edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
|
|
121
|
+
subagent_id: z.ZodOptional<z.ZodString>;
|
|
122
|
+
subagent_type: z.ZodOptional<z.ZodString>;
|
|
123
|
+
subagent_model: z.ZodOptional<z.ZodString>;
|
|
124
|
+
parent_conversation_id: z.ZodOptional<z.ZodString>;
|
|
125
|
+
task: z.ZodOptional<z.ZodString>;
|
|
126
|
+
status: z.ZodOptional<z.ZodString>;
|
|
127
|
+
text: z.ZodOptional<z.ZodString>;
|
|
128
|
+
trigger: z.ZodOptional<z.ZodString>;
|
|
129
|
+
context_usage_percent: z.ZodOptional<z.ZodNumber>;
|
|
130
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Cursor hook payload (verified against cursor.com/docs/hooks, 2026-08).
|
|
4
|
+
*
|
|
5
|
+
* Everything optional and passthrough: payloads are untrusted and a new field
|
|
6
|
+
* must never crash the agent's hook. Universal fields: conversation_id (stable
|
|
7
|
+
* per conversation), generation_id (changes per user message), model,
|
|
8
|
+
* workspace_roots, user_email, transcript_path.
|
|
9
|
+
*/
|
|
10
|
+
export const cursorPayloadSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
hook_event_name: z.string().optional(),
|
|
13
|
+
conversation_id: z.string().optional(),
|
|
14
|
+
generation_id: z.string().optional(),
|
|
15
|
+
model: z.string().optional(),
|
|
16
|
+
// Structured successors of the legacy `model` slug. Their exact shapes may
|
|
17
|
+
// evolve, so the types stay lenient: a change must never drop the event.
|
|
18
|
+
model_id: z.unknown().optional(),
|
|
19
|
+
model_params: z.array(z.unknown()).optional(),
|
|
20
|
+
cursor_version: z.string().optional(),
|
|
21
|
+
workspace_roots: z.array(z.string()).optional(),
|
|
22
|
+
transcript_path: z.string().nullable().optional(),
|
|
23
|
+
cwd: z.string().optional(),
|
|
24
|
+
// sessionStart / sessionEnd
|
|
25
|
+
session_id: z.string().optional(),
|
|
26
|
+
is_background_agent: z.boolean().optional(),
|
|
27
|
+
composer_mode: z.string().optional(),
|
|
28
|
+
reason: z.string().optional(),
|
|
29
|
+
// beforeSubmitPrompt
|
|
30
|
+
prompt: z.string().optional(),
|
|
31
|
+
attachments: z.array(z.unknown()).optional(),
|
|
32
|
+
// tool hooks
|
|
33
|
+
tool_name: z.string().optional(),
|
|
34
|
+
tool_use_id: z.string().optional(),
|
|
35
|
+
tool_input: z.unknown().optional(),
|
|
36
|
+
tool_output: z.unknown().optional(),
|
|
37
|
+
error_message: z.string().optional(),
|
|
38
|
+
failure_type: z.string().optional(),
|
|
39
|
+
duration: z.number().optional(),
|
|
40
|
+
duration_ms: z.number().optional(),
|
|
41
|
+
// shell / MCP hooks
|
|
42
|
+
command: z.string().optional(),
|
|
43
|
+
output: z.string().optional(),
|
|
44
|
+
url: z.string().optional(),
|
|
45
|
+
result_json: z.string().optional(),
|
|
46
|
+
// file hooks
|
|
47
|
+
file_path: z.string().optional(),
|
|
48
|
+
edits: z.array(z.unknown()).optional(),
|
|
49
|
+
// subagent hooks
|
|
50
|
+
subagent_id: z.string().optional(),
|
|
51
|
+
subagent_type: z.string().optional(),
|
|
52
|
+
subagent_model: z.string().optional(),
|
|
53
|
+
parent_conversation_id: z.string().optional(),
|
|
54
|
+
task: z.string().optional(),
|
|
55
|
+
status: z.string().optional(),
|
|
56
|
+
// afterAgentResponse
|
|
57
|
+
text: z.string().optional(),
|
|
58
|
+
// preCompact
|
|
59
|
+
trigger: z.string().optional(),
|
|
60
|
+
context_usage_percent: z.number().optional()
|
|
61
|
+
})
|
|
62
|
+
.passthrough();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CanonicalEventType } from '../../../events/types/events.types.js';
|
|
2
|
+
export declare const GEMINI_PROVIDER_ID = "gemini";
|
|
3
|
+
export declare const GEMINI_DISPLAY_NAME = "Gemini CLI";
|
|
4
|
+
export declare const GEMINI_HOME_VAR = "GEMINI_HOME";
|
|
5
|
+
export declare const GEMINI_CLI_VAR = "GEMINI_CLI";
|
|
6
|
+
export declare const GEMINI_HOME_DIR = ".gemini";
|
|
7
|
+
export declare const GEMINI_SETTINGS_FILE = "settings.json";
|
|
8
|
+
export declare const GEMINI_EXECUTABLES: readonly ["gemini", "gemini-cli"];
|
|
9
|
+
/** Hook events AgentWatch registers in Gemini CLI. */
|
|
10
|
+
export declare const GEMINI_HOOK_EVENTS: readonly ["SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeTool", "AfterTool", "Notification", "PreCompress"];
|
|
11
|
+
/** Events that take a matcher; "*" observes everything. */
|
|
12
|
+
export declare const GEMINI_MATCHED_EVENTS: ReadonlySet<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Gemini CLI reads this field as MILLISECONDS (its own default is 60,000).
|
|
15
|
+
*
|
|
16
|
+
* A bare `30` here made every AgentWatch hook time out before node could
|
|
17
|
+
* start. The same unit applies in antigravity.hooks.ts — it is the same Google
|
|
18
|
+
* hook runner.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GEMINI_HOOK_TIMEOUT_MILLISECONDS = 30000;
|
|
21
|
+
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
22
|
+
export declare const GEMINI_EVENT_TYPE_MAP: Readonly<Record<string, CanonicalEventType>>;
|
|
23
|
+
/**
|
|
24
|
+
* Hooks reporting a prompt, across old and new naming. Also the gate a budget
|
|
25
|
+
* refusal travels on — see the provider's `getBlockResponse`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GEMINI_PROMPT_EVENTS: ReadonlySet<string>;
|
|
28
|
+
/** Hooks reporting a completed generation, across old and new naming. */
|
|
29
|
+
export declare const GEMINI_STOP_EVENTS: ReadonlySet<string>;
|
|
30
|
+
/** Hooks whose canonical type depends on which tool ran. */
|
|
31
|
+
export declare const GEMINI_TOOL_EVENTS: ReadonlySet<string>;
|
|
32
|
+
/** Tool hooks that report a start rather than a completion. */
|
|
33
|
+
export declare const GEMINI_TOOL_START_EVENTS: ReadonlySet<string>;
|
|
34
|
+
/** Tool hooks that report a completion. */
|
|
35
|
+
export declare const GEMINI_TOOL_COMPLETE_EVENTS: ReadonlySet<string>;
|
|
36
|
+
export declare const GEMINI_UNKNOWN_EVENT = "unknown";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const GEMINI_PROVIDER_ID = 'gemini';
|
|
2
|
+
export const GEMINI_DISPLAY_NAME = 'Gemini CLI';
|
|
3
|
+
export const GEMINI_HOME_VAR = 'GEMINI_HOME';
|
|
4
|
+
export const GEMINI_CLI_VAR = 'GEMINI_CLI';
|
|
5
|
+
export const GEMINI_HOME_DIR = '.gemini';
|
|
6
|
+
export const GEMINI_SETTINGS_FILE = 'settings.json';
|
|
7
|
+
export const GEMINI_EXECUTABLES = ['gemini', 'gemini-cli'];
|
|
8
|
+
/** Hook events AgentWatch registers in Gemini CLI. */
|
|
9
|
+
export const GEMINI_HOOK_EVENTS = ['SessionStart', 'SessionEnd', 'BeforeAgent', 'AfterAgent', 'BeforeTool', 'AfterTool', 'Notification', 'PreCompress'];
|
|
10
|
+
/** Events that take a matcher; "*" observes everything. */
|
|
11
|
+
export const GEMINI_MATCHED_EVENTS = new Set(['BeforeAgent', 'AfterAgent', 'BeforeTool', 'AfterTool', 'Notification', 'PreCompress']);
|
|
12
|
+
/**
|
|
13
|
+
* Gemini CLI reads this field as MILLISECONDS (its own default is 60,000).
|
|
14
|
+
*
|
|
15
|
+
* A bare `30` here made every AgentWatch hook time out before node could
|
|
16
|
+
* start. The same unit applies in antigravity.hooks.ts — it is the same Google
|
|
17
|
+
* hook runner.
|
|
18
|
+
*/
|
|
19
|
+
export const GEMINI_HOOK_TIMEOUT_MILLISECONDS = 30_000;
|
|
20
|
+
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
21
|
+
export const GEMINI_EVENT_TYPE_MAP = {
|
|
22
|
+
SessionStart: 'session.started',
|
|
23
|
+
SessionEnd: 'session.ended',
|
|
24
|
+
// Current Gemini CLI hook names.
|
|
25
|
+
BeforeAgent: 'prompt.submitted',
|
|
26
|
+
AfterAgent: 'generation.completed',
|
|
27
|
+
PreCompress: 'compaction.started',
|
|
28
|
+
// Kept for payload compatibility with old installations; new registrations
|
|
29
|
+
// use the names above.
|
|
30
|
+
UserPromptSubmit: 'prompt.submitted',
|
|
31
|
+
PermissionRequest: 'permission.requested',
|
|
32
|
+
Stop: 'generation.completed',
|
|
33
|
+
SubagentStart: 'subagent.started',
|
|
34
|
+
SubagentStop: 'subagent.completed',
|
|
35
|
+
PreCompact: 'compaction.started',
|
|
36
|
+
PostCompact: 'compaction.completed'
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Hooks reporting a prompt, across old and new naming. Also the gate a budget
|
|
40
|
+
* refusal travels on — see the provider's `getBlockResponse`.
|
|
41
|
+
*/
|
|
42
|
+
export const GEMINI_PROMPT_EVENTS = new Set(['BeforeAgent', 'UserPromptSubmit']);
|
|
43
|
+
/** Hooks reporting a completed generation, across old and new naming. */
|
|
44
|
+
export const GEMINI_STOP_EVENTS = new Set(['AfterAgent', 'Stop']);
|
|
45
|
+
/** Hooks whose canonical type depends on which tool ran. */
|
|
46
|
+
export const GEMINI_TOOL_EVENTS = new Set([
|
|
47
|
+
'BeforeTool',
|
|
48
|
+
'AfterTool',
|
|
49
|
+
'PreToolUse',
|
|
50
|
+
'PostToolUse',
|
|
51
|
+
'PostToolUseFailure',
|
|
52
|
+
'PermissionRequest'
|
|
53
|
+
]);
|
|
54
|
+
/** Tool hooks that report a start rather than a completion. */
|
|
55
|
+
export const GEMINI_TOOL_START_EVENTS = new Set(['BeforeTool', 'PreToolUse', 'PermissionRequest']);
|
|
56
|
+
/** Tool hooks that report a completion. */
|
|
57
|
+
export const GEMINI_TOOL_COMPLETE_EVENTS = new Set(['AfterTool', 'PostToolUse', 'PostToolUseFailure']);
|
|
58
|
+
export const GEMINI_UNKNOWN_EVENT = 'unknown';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Settings key holding the environment block telemetry is configured through. */
|
|
2
|
+
export declare const ENV_BLOCK_KEY = "env";
|
|
3
|
+
/** Where Gemini reads OTLP auth from; it has no header-helper mechanism. */
|
|
4
|
+
export declare const OTLP_HEADERS_KEY = "OTEL_EXPORTER_OTLP_HEADERS";
|
|
5
|
+
/**
|
|
6
|
+
* A setting an older AgentWatch wrote here in the belief that Gemini read it.
|
|
7
|
+
*
|
|
8
|
+
* It does not — `otelHeadersHelper` is a Claude Code setting — so the entry is
|
|
9
|
+
* cleaned up on the next `configure`. Only when it is ours, though: another
|
|
10
|
+
* tool may legitimately own the same key.
|
|
11
|
+
*/
|
|
12
|
+
export declare const LEGACY_HELPER_KEY = "otelHeadersHelper";
|
|
13
|
+
/**
|
|
14
|
+
* Keys uninstall falls back to without a recorded list.
|
|
15
|
+
*
|
|
16
|
+
* Covers settings written before install state existed, and keeps the names an
|
|
17
|
+
* older version wrote (GEMINI_ENABLE_TELEMETRY) so those are cleaned up too.
|
|
18
|
+
*/
|
|
19
|
+
export declare const GEMINI_LEGACY_OWNED_KEYS: readonly ["GEMINI_TELEMETRY_ENABLED", "GEMINI_TELEMETRY_TARGET", "GEMINI_TELEMETRY_OTLP_ENDPOINT", "GEMINI_TELEMETRY_OTLP_PROTOCOL", "GEMINI_TELEMETRY_TRACES_ENABLED", "GEMINI_ENABLE_TELEMETRY", "OTEL_METRICS_EXPORTER", "OTEL_LOGS_EXPORTER", "OTEL_TRACES_EXPORTER", "OTEL_EXPORTER_OTLP_PROTOCOL", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_HEADERS", "otelHeadersHelper"];
|
|
20
|
+
export declare const OTEL_EXPORTER_NONE = "none";
|
|
21
|
+
export declare const OTEL_EXPORTER_OTLP = "otlp";
|
|
22
|
+
/**
|
|
23
|
+
* Gemini's own protocol setting accepts `grpc` or `http` and *throws*
|
|
24
|
+
* FatalConfigError on anything else — notably on `http/json`, which is valid
|
|
25
|
+
* only for the standard OTEL_EXPORTER_OTLP_PROTOCOL.
|
|
26
|
+
*/
|
|
27
|
+
export declare const GEMINI_OTLP_PROTOCOL = "http";
|
|
28
|
+
export declare const STANDARD_OTLP_PROTOCOL = "http/json";
|
|
29
|
+
/**
|
|
30
|
+
* Ship the batch to the local endpoint, not to Google Cloud. The default is
|
|
31
|
+
* local today, but `gcp` would send this telemetry somewhere else entirely, and
|
|
32
|
+
* that is not a default worth inheriting.
|
|
33
|
+
*/
|
|
34
|
+
export declare const GEMINI_TELEMETRY_TARGET_LOCAL = "local";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Settings key holding the environment block telemetry is configured through. */
|
|
2
|
+
export const ENV_BLOCK_KEY = 'env';
|
|
3
|
+
/** Where Gemini reads OTLP auth from; it has no header-helper mechanism. */
|
|
4
|
+
export const OTLP_HEADERS_KEY = 'OTEL_EXPORTER_OTLP_HEADERS';
|
|
5
|
+
/**
|
|
6
|
+
* A setting an older AgentWatch wrote here in the belief that Gemini read it.
|
|
7
|
+
*
|
|
8
|
+
* It does not — `otelHeadersHelper` is a Claude Code setting — so the entry is
|
|
9
|
+
* cleaned up on the next `configure`. Only when it is ours, though: another
|
|
10
|
+
* tool may legitimately own the same key.
|
|
11
|
+
*/
|
|
12
|
+
export const LEGACY_HELPER_KEY = 'otelHeadersHelper';
|
|
13
|
+
/**
|
|
14
|
+
* Keys uninstall falls back to without a recorded list.
|
|
15
|
+
*
|
|
16
|
+
* Covers settings written before install state existed, and keeps the names an
|
|
17
|
+
* older version wrote (GEMINI_ENABLE_TELEMETRY) so those are cleaned up too.
|
|
18
|
+
*/
|
|
19
|
+
export const GEMINI_LEGACY_OWNED_KEYS = [
|
|
20
|
+
'GEMINI_TELEMETRY_ENABLED',
|
|
21
|
+
'GEMINI_TELEMETRY_TARGET',
|
|
22
|
+
'GEMINI_TELEMETRY_OTLP_ENDPOINT',
|
|
23
|
+
'GEMINI_TELEMETRY_OTLP_PROTOCOL',
|
|
24
|
+
'GEMINI_TELEMETRY_TRACES_ENABLED',
|
|
25
|
+
'GEMINI_ENABLE_TELEMETRY',
|
|
26
|
+
'OTEL_METRICS_EXPORTER',
|
|
27
|
+
'OTEL_LOGS_EXPORTER',
|
|
28
|
+
'OTEL_TRACES_EXPORTER',
|
|
29
|
+
'OTEL_EXPORTER_OTLP_PROTOCOL',
|
|
30
|
+
'OTEL_EXPORTER_OTLP_ENDPOINT',
|
|
31
|
+
OTLP_HEADERS_KEY,
|
|
32
|
+
LEGACY_HELPER_KEY
|
|
33
|
+
];
|
|
34
|
+
export const OTEL_EXPORTER_NONE = 'none';
|
|
35
|
+
export const OTEL_EXPORTER_OTLP = 'otlp';
|
|
36
|
+
/**
|
|
37
|
+
* Gemini's own protocol setting accepts `grpc` or `http` and *throws*
|
|
38
|
+
* FatalConfigError on anything else — notably on `http/json`, which is valid
|
|
39
|
+
* only for the standard OTEL_EXPORTER_OTLP_PROTOCOL.
|
|
40
|
+
*/
|
|
41
|
+
export const GEMINI_OTLP_PROTOCOL = 'http';
|
|
42
|
+
export const STANDARD_OTLP_PROTOCOL = 'http/json';
|
|
43
|
+
/**
|
|
44
|
+
* Ship the batch to the local endpoint, not to Google Cloud. The default is
|
|
45
|
+
* local today, but `gcp` would send this telemetry somewhere else entirely, and
|
|
46
|
+
* that is not a default worth inheriting.
|
|
47
|
+
*/
|
|
48
|
+
export const GEMINI_TELEMETRY_TARGET_LOCAL = 'local';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
+
import type { HookContext } from '../types/provider.types.js';
|
|
3
|
+
export type { GeminiPayload } from './types/gemini.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Translate one Gemini CLI hook payload into canonical events.
|
|
6
|
+
*
|
|
7
|
+
* Both the current hook names and the ones earlier installations registered are
|
|
8
|
+
* accepted: a user who has not re-run setup still sends the old shape, and
|
|
9
|
+
* dropping it would silently stop their telemetry.
|
|
10
|
+
*
|
|
11
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
12
|
+
* @param context - Environment and effective config.
|
|
13
|
+
* @returns The canonical events, or an empty list for an unusable payload.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseGeminiHookEvent(rawPayload: unknown, context: HookContext): AgentWatchEvent[];
|