@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,33 @@
|
|
|
1
|
+
/** Substring identifying AgentWatch-owned hook entries in agent configs. */
|
|
2
|
+
export const HOOK_COMMAND_MARKER = 'agentwatch';
|
|
3
|
+
/**
|
|
4
|
+
* Agent ids a hook command may name.
|
|
5
|
+
*
|
|
6
|
+
* The allowlist is what stops a foreign `my-tool hook --agent x` from being
|
|
7
|
+
* claimed — and then deleted — as AgentWatch's own.
|
|
8
|
+
*/
|
|
9
|
+
export const KNOWN_AGENT_IDS = new Set(['claude', 'codex', 'cursor', 'gemini', 'antigravity']);
|
|
10
|
+
/** An executable named `agentwatch`, with or without a platform suffix. */
|
|
11
|
+
export const RE_AGENTWATCH_BINARY = /^(?:agentwatch)(?:\.(?:exe|cmd|ps1|js|cjs|mjs))?$/;
|
|
12
|
+
/**
|
|
13
|
+
* A Node-compatible runtime.
|
|
14
|
+
*
|
|
15
|
+
* buildHookCommand embeds process.execPath, so hooks written by earlier
|
|
16
|
+
* installs may name any of these — including versioned binaries (node22) and
|
|
17
|
+
* TypeScript runners (tsx, deno). Failing to recognize one would leave the
|
|
18
|
+
* stale hook in place next to a fresh duplicate, and every turn would then be
|
|
19
|
+
* processed — and counted — twice.
|
|
20
|
+
*/
|
|
21
|
+
export const RE_NODE_BINARY = /^(?:node[\d.]*|nodejs|bun|tsx|deno)(?:\.exe)?$/i;
|
|
22
|
+
/** The CLI entry point, in any form the build or a dev run produces. */
|
|
23
|
+
export const RE_CLI_SCRIPT = /^cli\.(?:ts|mts|js|mjs|cjs)$/;
|
|
24
|
+
/** Path separator, either platform's. */
|
|
25
|
+
export const RE_PATH_SEPARATOR = /[\\/]/;
|
|
26
|
+
/** Shell control operators; their presence disqualifies a command outright. */
|
|
27
|
+
export const RE_SHELL_CONTROL = /[|&;<>\r\n]/;
|
|
28
|
+
/** Characters a double quote still escapes inside a quoted argument. */
|
|
29
|
+
export const RE_DOUBLE_QUOTE_ESCAPABLE = /["\\$`]/;
|
|
30
|
+
export const RE_WHITESPACE = /\s/;
|
|
31
|
+
/** Argument shape that forces quoting when a hook command is generated. */
|
|
32
|
+
export const RE_NEEDS_QUOTING = /[\s"'\\$`]/;
|
|
33
|
+
export const RE_QUOTE_ESCAPE = /(["\\$`])/g;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CanonicalEventType } from '../../../events/types/events.types.js';
|
|
2
|
+
import type { ToolKind } from '../../types/provider.types.js';
|
|
3
|
+
export declare const CURSOR_PROVIDER_ID = "cursor";
|
|
4
|
+
export declare const CURSOR_DISPLAY_NAME = "Cursor";
|
|
5
|
+
export declare const CURSOR_HOME_DIR = ".cursor";
|
|
6
|
+
export declare const CURSOR_HOOKS_FILE = "hooks.json";
|
|
7
|
+
export declare const CURSOR_EXECUTABLES: readonly ["cursor", "cursor-agent"];
|
|
8
|
+
/**
|
|
9
|
+
* Cursor lifecycle hooks (verified against cursor.com/docs/hooks, 2026-08).
|
|
10
|
+
*
|
|
11
|
+
* File: `~/.cursor/hooks.json`, format
|
|
12
|
+
* `{ version: 1, hooks: { <event>: [entry] } }` — flat command entries per
|
|
13
|
+
* event, no matcher groups. Hooks need no trust step, unlike Codex. Cursor also
|
|
14
|
+
* reads project, team and enterprise hooks.json files; AgentWatch manages only
|
|
15
|
+
* the user-level one.
|
|
16
|
+
*
|
|
17
|
+
* `beforeTabFileRead` is deliberately NOT registered: it fires on every inline
|
|
18
|
+
* completion and carries the full file content — pure noise with a privacy cost.
|
|
19
|
+
* `afterAgentThought` and `workspaceOpen` carry nothing the data model uses.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CURSOR_HOOK_EVENTS: readonly ["sessionStart", "sessionEnd", "beforeSubmitPrompt", "preToolUse", "postToolUse", "postToolUseFailure", "beforeShellExecution", "afterShellExecution", "beforeMCPExecution", "afterMCPExecution", "beforeReadFile", "afterFileEdit", "subagentStart", "subagentStop", "preCompact", "afterAgentResponse", "stop", "afterTabFileEdit"];
|
|
22
|
+
/** Cursor reads this field as seconds. */
|
|
23
|
+
export declare const CURSOR_HOOK_TIMEOUT_SECONDS = 30;
|
|
24
|
+
/** Cursor's documented hooks.json schema version. */
|
|
25
|
+
export declare const CURSOR_HOOKS_VERSION = 1;
|
|
26
|
+
export declare const CURSOR_VERSION_KEY = "version";
|
|
27
|
+
/** Note surfaced at install time about Cursor's missing token usage. */
|
|
28
|
+
export declare const CURSOR_USAGE_NOTE = "note: Cursor transcripts carry no token usage yet \u2014 Cursor turn summaries stay usage_status=pending until Cursor enriches them.";
|
|
29
|
+
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
30
|
+
export declare const CURSOR_EVENT_TYPE_MAP: Readonly<Record<string, CanonicalEventType>>;
|
|
31
|
+
/**
|
|
32
|
+
* Tool kinds whose completions arrive through Cursor's dedicated hooks.
|
|
33
|
+
*
|
|
34
|
+
* Cursor fires BOTH the generic `postToolUse` and a dedicated hook
|
|
35
|
+
* (afterShellExecution / afterMCPExecution / beforeReadFile / afterFileEdit)
|
|
36
|
+
* for these kinds. The dedicated hooks are the authoritative completion source;
|
|
37
|
+
* mapping the generic duplicate to a completion type as well would count every
|
|
38
|
+
* such call twice in tool_calls and tools_used.
|
|
39
|
+
*/
|
|
40
|
+
export declare const CURSOR_DEDICATED_COMPLETION_KINDS: ReadonlySet<ToolKind>;
|
|
41
|
+
/** Cursor's own generic tool names, on top of the shared vocabularies. */
|
|
42
|
+
export declare const CURSOR_TOOL_KINDS: Readonly<Record<string, ToolKind>>;
|
|
43
|
+
/** Default tool names for the dedicated file hooks, which report none. */
|
|
44
|
+
export declare const CURSOR_READ_TOOL_NAME = "Read";
|
|
45
|
+
export declare const CURSOR_EDIT_TOOL_NAME = "Edit";
|
|
46
|
+
export declare const CURSOR_SHELL_TOOL_NAME = "Shell";
|
|
47
|
+
/** Attachment field carrying a file path. */
|
|
48
|
+
export declare const ATTACHMENT_FILE_PATH_KEY = "file_path";
|
|
49
|
+
/**
|
|
50
|
+
* The one hook a budget refusal may travel on.
|
|
51
|
+
*
|
|
52
|
+
* `beforeSubmitPrompt` is the only Cursor hook whose refusal precedes the turn's
|
|
53
|
+
* first request, and it blocks through `continue: false` rather than the
|
|
54
|
+
* `permission` field the tool and shell hooks use (verified against
|
|
55
|
+
* cursor.com/docs, 2026-08). `user_message` is what Cursor shows the developer.
|
|
56
|
+
*/
|
|
57
|
+
export declare const CURSOR_PROMPT_SUBMIT_EVENTS: ReadonlySet<string>;
|
|
58
|
+
export declare const CURSOR_UNKNOWN_EVENT = "unknown";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const CURSOR_PROVIDER_ID = 'cursor';
|
|
2
|
+
export const CURSOR_DISPLAY_NAME = 'Cursor';
|
|
3
|
+
export const CURSOR_HOME_DIR = '.cursor';
|
|
4
|
+
export const CURSOR_HOOKS_FILE = 'hooks.json';
|
|
5
|
+
export const CURSOR_EXECUTABLES = ['cursor', 'cursor-agent'];
|
|
6
|
+
/**
|
|
7
|
+
* Cursor lifecycle hooks (verified against cursor.com/docs/hooks, 2026-08).
|
|
8
|
+
*
|
|
9
|
+
* File: `~/.cursor/hooks.json`, format
|
|
10
|
+
* `{ version: 1, hooks: { <event>: [entry] } }` — flat command entries per
|
|
11
|
+
* event, no matcher groups. Hooks need no trust step, unlike Codex. Cursor also
|
|
12
|
+
* reads project, team and enterprise hooks.json files; AgentWatch manages only
|
|
13
|
+
* the user-level one.
|
|
14
|
+
*
|
|
15
|
+
* `beforeTabFileRead` is deliberately NOT registered: it fires on every inline
|
|
16
|
+
* completion and carries the full file content — pure noise with a privacy cost.
|
|
17
|
+
* `afterAgentThought` and `workspaceOpen` carry nothing the data model uses.
|
|
18
|
+
*/
|
|
19
|
+
export const CURSOR_HOOK_EVENTS = [
|
|
20
|
+
'sessionStart',
|
|
21
|
+
'sessionEnd',
|
|
22
|
+
'beforeSubmitPrompt',
|
|
23
|
+
'preToolUse',
|
|
24
|
+
'postToolUse',
|
|
25
|
+
'postToolUseFailure',
|
|
26
|
+
'beforeShellExecution',
|
|
27
|
+
'afterShellExecution',
|
|
28
|
+
'beforeMCPExecution',
|
|
29
|
+
'afterMCPExecution',
|
|
30
|
+
'beforeReadFile',
|
|
31
|
+
'afterFileEdit',
|
|
32
|
+
'subagentStart',
|
|
33
|
+
'subagentStop',
|
|
34
|
+
'preCompact',
|
|
35
|
+
'afterAgentResponse',
|
|
36
|
+
'stop',
|
|
37
|
+
'afterTabFileEdit'
|
|
38
|
+
];
|
|
39
|
+
/** Cursor reads this field as seconds. */
|
|
40
|
+
export const CURSOR_HOOK_TIMEOUT_SECONDS = 30;
|
|
41
|
+
/** Cursor's documented hooks.json schema version. */
|
|
42
|
+
export const CURSOR_HOOKS_VERSION = 1;
|
|
43
|
+
export const CURSOR_VERSION_KEY = 'version';
|
|
44
|
+
/** Note surfaced at install time about Cursor's missing token usage. */
|
|
45
|
+
export const CURSOR_USAGE_NOTE = 'note: Cursor transcripts carry no token usage yet — Cursor turn summaries stay usage_status=pending until Cursor enriches them.';
|
|
46
|
+
/** Provider hook name to canonical event type, where the mapping is direct. */
|
|
47
|
+
export const CURSOR_EVENT_TYPE_MAP = {
|
|
48
|
+
sessionStart: 'session.started',
|
|
49
|
+
sessionEnd: 'session.ended',
|
|
50
|
+
beforeSubmitPrompt: 'prompt.submitted',
|
|
51
|
+
beforeShellExecution: 'shell.started',
|
|
52
|
+
afterShellExecution: 'shell.completed',
|
|
53
|
+
beforeMCPExecution: 'mcp.started',
|
|
54
|
+
afterMCPExecution: 'mcp.completed',
|
|
55
|
+
beforeReadFile: 'file.read',
|
|
56
|
+
afterFileEdit: 'file.edited',
|
|
57
|
+
afterTabFileEdit: 'file.edited',
|
|
58
|
+
subagentStart: 'subagent.started',
|
|
59
|
+
subagentStop: 'subagent.completed',
|
|
60
|
+
preCompact: 'compaction.started',
|
|
61
|
+
afterAgentResponse: 'agent.other',
|
|
62
|
+
stop: 'generation.completed'
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Tool kinds whose completions arrive through Cursor's dedicated hooks.
|
|
66
|
+
*
|
|
67
|
+
* Cursor fires BOTH the generic `postToolUse` and a dedicated hook
|
|
68
|
+
* (afterShellExecution / afterMCPExecution / beforeReadFile / afterFileEdit)
|
|
69
|
+
* for these kinds. The dedicated hooks are the authoritative completion source;
|
|
70
|
+
* mapping the generic duplicate to a completion type as well would count every
|
|
71
|
+
* such call twice in tool_calls and tools_used.
|
|
72
|
+
*/
|
|
73
|
+
export const CURSOR_DEDICATED_COMPLETION_KINDS = new Set(['shell', 'mcp', 'file-read', 'file-edit']);
|
|
74
|
+
/** Cursor's own generic tool names, on top of the shared vocabularies. */
|
|
75
|
+
export const CURSOR_TOOL_KINDS = {
|
|
76
|
+
Shell: 'shell',
|
|
77
|
+
MCP: 'mcp',
|
|
78
|
+
Write: 'file-edit'
|
|
79
|
+
};
|
|
80
|
+
/** Default tool names for the dedicated file hooks, which report none. */
|
|
81
|
+
export const CURSOR_READ_TOOL_NAME = 'Read';
|
|
82
|
+
export const CURSOR_EDIT_TOOL_NAME = 'Edit';
|
|
83
|
+
export const CURSOR_SHELL_TOOL_NAME = 'Shell';
|
|
84
|
+
/** Attachment field carrying a file path. */
|
|
85
|
+
export const ATTACHMENT_FILE_PATH_KEY = 'file_path';
|
|
86
|
+
/**
|
|
87
|
+
* The one hook a budget refusal may travel on.
|
|
88
|
+
*
|
|
89
|
+
* `beforeSubmitPrompt` is the only Cursor hook whose refusal precedes the turn's
|
|
90
|
+
* first request, and it blocks through `continue: false` rather than the
|
|
91
|
+
* `permission` field the tool and shell hooks use (verified against
|
|
92
|
+
* cursor.com/docs, 2026-08). `user_message` is what Cursor shows the developer.
|
|
93
|
+
*/
|
|
94
|
+
export const CURSOR_PROMPT_SUBMIT_EVENTS = new Set(['beforeSubmitPrompt']);
|
|
95
|
+
export const CURSOR_UNKNOWN_EVENT = 'unknown';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
+
import type { HookContext } from '../types/provider.types.js';
|
|
3
|
+
export type { CursorPayload } from './types/cursor.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Translate one Cursor hook payload into canonical events.
|
|
6
|
+
*
|
|
7
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
8
|
+
* @param context - Environment and effective config.
|
|
9
|
+
* @returns The canonical events, or an empty list for an unusable payload.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseCursorHookEvent(rawPayload: unknown, context: HookContext): AgentWatchEvent[];
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { asRecord, compact } from '../../core/object.js';
|
|
2
|
+
import { sha256Hex } from '../../events/event-id.js';
|
|
3
|
+
import { baseEvent, filePathPatch, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
|
|
4
|
+
import { classifyTool, contentEvidence, parseMcpToolName, toolCompleteType, toolStartType } from '../shared/tooling.js';
|
|
5
|
+
import { ATTACHMENT_FILE_PATH_KEY, CURSOR_DEDICATED_COMPLETION_KINDS, CURSOR_DISPLAY_NAME, CURSOR_EDIT_TOOL_NAME, CURSOR_EVENT_TYPE_MAP, CURSOR_PROVIDER_ID, CURSOR_READ_TOOL_NAME, CURSOR_SHELL_TOOL_NAME, CURSOR_TOOL_KINDS, CURSOR_UNKNOWN_EVENT } from './constants/cursor.constants.js';
|
|
6
|
+
import { cursorPayloadSchema } from './schemas/cursor.schema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Translate one Cursor hook payload into canonical events.
|
|
9
|
+
*
|
|
10
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
11
|
+
* @param context - Environment and effective config.
|
|
12
|
+
* @returns The canonical events, or an empty list for an unusable payload.
|
|
13
|
+
*/
|
|
14
|
+
export function parseCursorHookEvent(rawPayload, context) {
|
|
15
|
+
const parsed = cursorPayloadSchema.safeParse(rawPayload);
|
|
16
|
+
if (!parsed.success)
|
|
17
|
+
return [];
|
|
18
|
+
const payload = parsed.data;
|
|
19
|
+
const providerEventType = payload.hook_event_name ?? CURSOR_UNKNOWN_EVENT;
|
|
20
|
+
return [withPatch(cursorBaseEvent(payload, providerEventType), hookPatch(payload, providerEventType, context))];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The provider-independent part of the event.
|
|
24
|
+
*
|
|
25
|
+
* @param payload - Parsed hook payload.
|
|
26
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
27
|
+
* @returns The base event.
|
|
28
|
+
*/
|
|
29
|
+
function cursorBaseEvent(payload, providerEventType) {
|
|
30
|
+
const sessionId = payload.conversation_id ?? payload.session_id;
|
|
31
|
+
// model_id is the structured identifier and supersedes the legacy slug.
|
|
32
|
+
const model = (typeof payload.model_id === 'string' && payload.model_id.length > 0 ? payload.model_id : undefined) ?? payload.model;
|
|
33
|
+
return baseEvent({
|
|
34
|
+
provider: CURSOR_PROVIDER_ID,
|
|
35
|
+
displayName: CURSOR_DISPLAY_NAME,
|
|
36
|
+
providerEventType,
|
|
37
|
+
eventType: canonicalType(payload, providerEventType),
|
|
38
|
+
sessionId,
|
|
39
|
+
// generation_id changes per user message and matches the transcript scope —
|
|
40
|
+
// it is the turn correlation key, like Claude's prompt_id.
|
|
41
|
+
turnId: payload.generation_id,
|
|
42
|
+
toolUseId: payload.tool_use_id,
|
|
43
|
+
// Hash only: it disambiguates otherwise-identical events within a turn
|
|
44
|
+
// without any content reaching the id.
|
|
45
|
+
payloadFingerprint: sha256Hex(JSON.stringify(payload)),
|
|
46
|
+
ai: model ? { model } : undefined,
|
|
47
|
+
providerMetadata: {
|
|
48
|
+
generationId: payload.generation_id,
|
|
49
|
+
cursorVersion: payload.cursor_version,
|
|
50
|
+
// Structured inference parameters (thinking/context/effort selections).
|
|
51
|
+
modelParams: modelParams(payload)
|
|
52
|
+
},
|
|
53
|
+
timestamp: new Date().toISOString()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What this particular hook contributes on top of the base event.
|
|
58
|
+
*
|
|
59
|
+
* @param payload - Parsed hook payload.
|
|
60
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
61
|
+
* @param context - Environment and effective config.
|
|
62
|
+
* @returns The patch; empty for a hook we model but read nothing from.
|
|
63
|
+
*/
|
|
64
|
+
function hookPatch(payload, providerEventType, context) {
|
|
65
|
+
const capture = context.config.capture;
|
|
66
|
+
if (providerEventType === 'sessionStart') {
|
|
67
|
+
return { metadata: { sessionSource: payload.composer_mode, isBackgroundAgent: payload.is_background_agent } };
|
|
68
|
+
}
|
|
69
|
+
if (providerEventType === 'sessionEnd')
|
|
70
|
+
return { metadata: { sessionEndReason: payload.reason } };
|
|
71
|
+
if (providerEventType === 'beforeSubmitPrompt')
|
|
72
|
+
return submitPromptPatch(payload, context);
|
|
73
|
+
if (providerEventType === 'preToolUse' || providerEventType === 'postToolUse' || providerEventType === 'postToolUseFailure') {
|
|
74
|
+
return genericToolPatch(payload, providerEventType, context);
|
|
75
|
+
}
|
|
76
|
+
if (providerEventType === 'beforeShellExecution' || providerEventType === 'afterShellExecution') {
|
|
77
|
+
return shellPatch(payload, providerEventType, context);
|
|
78
|
+
}
|
|
79
|
+
if (providerEventType === 'beforeMCPExecution' || providerEventType === 'afterMCPExecution') {
|
|
80
|
+
return mcpPatch(payload, providerEventType, context);
|
|
81
|
+
}
|
|
82
|
+
if (providerEventType === 'beforeReadFile') {
|
|
83
|
+
// The payload carries the full file content; only the path is ever kept.
|
|
84
|
+
return {
|
|
85
|
+
tool: { name: payload.tool_name ?? CURSOR_READ_TOOL_NAME, status: 'started' },
|
|
86
|
+
...filePathPatch(payload.file_path, capture)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (providerEventType === 'afterFileEdit' || providerEventType === 'afterTabFileEdit') {
|
|
90
|
+
return fileEditPatch(payload, providerEventType, context);
|
|
91
|
+
}
|
|
92
|
+
if (providerEventType === 'subagentStart' || providerEventType === 'subagentStop') {
|
|
93
|
+
return subagentPatch(payload, providerEventType);
|
|
94
|
+
}
|
|
95
|
+
if (providerEventType === 'preCompact') {
|
|
96
|
+
return { metadata: { compactionTrigger: payload.trigger, contextUsagePercent: payload.context_usage_percent } };
|
|
97
|
+
}
|
|
98
|
+
if (providerEventType === 'afterAgentResponse')
|
|
99
|
+
return responsePatch(payload.text ?? '', capture);
|
|
100
|
+
if (providerEventType === 'stop')
|
|
101
|
+
return { metadata: { stopStatus: payload.status } };
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Prompt fields, including its attachments.
|
|
106
|
+
*
|
|
107
|
+
* @param payload - Parsed hook payload.
|
|
108
|
+
* @param context - Environment and effective config.
|
|
109
|
+
* @returns The patch.
|
|
110
|
+
*/
|
|
111
|
+
function submitPromptPatch(payload, context) {
|
|
112
|
+
const capture = context.config.capture;
|
|
113
|
+
const patch = promptPatch(payload.prompt ?? '', capture);
|
|
114
|
+
const attachments = payload.attachments ?? [];
|
|
115
|
+
if (attachments.length === 0)
|
|
116
|
+
return patch;
|
|
117
|
+
// Attachment paths are a per-file signal, gated like every other one.
|
|
118
|
+
const paths = capture.files ? attachmentPaths(attachments) : [];
|
|
119
|
+
return {
|
|
120
|
+
metadata: compact({
|
|
121
|
+
...patch.metadata,
|
|
122
|
+
attachmentCount: attachments.length,
|
|
123
|
+
attachments: paths.length > 0 ? paths : undefined
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Tool fields for Cursor's generic tool hooks.
|
|
129
|
+
*
|
|
130
|
+
* @param payload - Parsed hook payload.
|
|
131
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
132
|
+
* @param context - Environment and effective config.
|
|
133
|
+
* @returns The patch.
|
|
134
|
+
*/
|
|
135
|
+
function genericToolPatch(payload, providerEventType, context) {
|
|
136
|
+
const patch = toolPatch({
|
|
137
|
+
name: payload.tool_name,
|
|
138
|
+
status: genericToolStatus(providerEventType),
|
|
139
|
+
kind: cursorToolKind(payload.tool_name),
|
|
140
|
+
durationMs: payload.duration,
|
|
141
|
+
toolUseId: payload.tool_use_id,
|
|
142
|
+
input: payload.tool_input,
|
|
143
|
+
output: payload.tool_output
|
|
144
|
+
}, context.config.capture);
|
|
145
|
+
if (providerEventType !== 'postToolUseFailure' || payload.error_message === undefined)
|
|
146
|
+
return patch;
|
|
147
|
+
return {
|
|
148
|
+
...patch,
|
|
149
|
+
metadata: { ...patch.metadata, error: contentEvidence(payload.error_message), failureType: payload.failure_type }
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Shell fields for Cursor's dedicated shell hooks, which report the command
|
|
154
|
+
* and output at the top level rather than inside a tool-input object.
|
|
155
|
+
*
|
|
156
|
+
* @param payload - Parsed hook payload.
|
|
157
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
158
|
+
* @param context - Environment and effective config.
|
|
159
|
+
* @returns The patch.
|
|
160
|
+
*/
|
|
161
|
+
function shellPatch(payload, providerEventType, context) {
|
|
162
|
+
const capture = context.config.capture;
|
|
163
|
+
const completed = providerEventType === 'afterShellExecution';
|
|
164
|
+
return {
|
|
165
|
+
tool: { name: CURSOR_SHELL_TOOL_NAME, status: completed ? 'completed' : 'started', durationMs: payload.duration },
|
|
166
|
+
metadata: compact({
|
|
167
|
+
command: capture.toolInput && typeof payload.command === 'string' ? payload.command : undefined,
|
|
168
|
+
toolOutput: capture.toolOutput && completed && typeof payload.output === 'string' ? payload.output : undefined
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* MCP fields for Cursor's dedicated MCP hooks.
|
|
174
|
+
*
|
|
175
|
+
* Cursor reports the MCP *endpoint* — a url for remote servers, a command for
|
|
176
|
+
* stdio ones — rather than an `mcp__server__tool` name, so the server is taken
|
|
177
|
+
* from whichever of those is present.
|
|
178
|
+
*
|
|
179
|
+
* @param payload - Parsed hook payload.
|
|
180
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
181
|
+
* @param context - Environment and effective config.
|
|
182
|
+
* @returns The patch.
|
|
183
|
+
*/
|
|
184
|
+
function mcpPatch(payload, providerEventType, context) {
|
|
185
|
+
const capture = context.config.capture;
|
|
186
|
+
const parsed = payload.tool_name ? parseMcpToolName(payload.tool_name) : {};
|
|
187
|
+
return {
|
|
188
|
+
tool: {
|
|
189
|
+
name: payload.tool_name,
|
|
190
|
+
status: providerEventType === 'beforeMCPExecution' ? 'started' : 'completed',
|
|
191
|
+
durationMs: payload.duration
|
|
192
|
+
},
|
|
193
|
+
metadata: compact({
|
|
194
|
+
toolInput: capture.toolInput && payload.tool_input !== undefined ? payload.tool_input : undefined,
|
|
195
|
+
toolOutput: capture.toolOutput && payload.result_json !== undefined ? payload.result_json : undefined,
|
|
196
|
+
provider: compact({
|
|
197
|
+
mcpServer: parsed.server ?? payload.url ?? payload.command,
|
|
198
|
+
mcpTool: parsed.tool ?? payload.tool_name
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* File-edit fields for Cursor's dedicated edit hooks.
|
|
205
|
+
*
|
|
206
|
+
* @param payload - Parsed hook payload.
|
|
207
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
208
|
+
* @param context - Environment and effective config.
|
|
209
|
+
* @returns The patch.
|
|
210
|
+
*/
|
|
211
|
+
function fileEditPatch(payload, providerEventType, context) {
|
|
212
|
+
const capture = context.config.capture;
|
|
213
|
+
const pathPatch = filePathPatch(payload.file_path, capture);
|
|
214
|
+
return {
|
|
215
|
+
tool: { name: payload.tool_name ?? CURSOR_EDIT_TOOL_NAME, status: 'completed' },
|
|
216
|
+
metadata: compact({
|
|
217
|
+
...pathPatch.metadata,
|
|
218
|
+
// Tab edits are the editor's inline completion, not an agent tool call.
|
|
219
|
+
tab: providerEventType === 'afterTabFileEdit' ? true : undefined,
|
|
220
|
+
toolOutput: capture.toolOutput && payload.edits !== undefined ? payload.edits : undefined
|
|
221
|
+
})
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Subagent fields, including the child's own model and outcome.
|
|
226
|
+
*
|
|
227
|
+
* @param payload - Parsed hook payload.
|
|
228
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
229
|
+
* @returns The patch.
|
|
230
|
+
*/
|
|
231
|
+
function subagentPatch(payload, providerEventType) {
|
|
232
|
+
const stopped = providerEventType === 'subagentStop';
|
|
233
|
+
return {
|
|
234
|
+
session: { agentId: payload.subagent_id },
|
|
235
|
+
ai: !stopped && payload.subagent_model ? { model: payload.subagent_model } : undefined,
|
|
236
|
+
metadata: compact({
|
|
237
|
+
agentType: payload.subagent_type,
|
|
238
|
+
subagentStatus: stopped ? payload.status : undefined,
|
|
239
|
+
durationMs: stopped ? payload.duration_ms : undefined
|
|
240
|
+
})
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Whether a generic tool hook reports a start, a failure, or a completion.
|
|
245
|
+
*
|
|
246
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
247
|
+
* @returns The tool status.
|
|
248
|
+
*/
|
|
249
|
+
function genericToolStatus(providerEventType) {
|
|
250
|
+
if (providerEventType === 'preToolUse')
|
|
251
|
+
return 'started';
|
|
252
|
+
if (providerEventType === 'postToolUseFailure')
|
|
253
|
+
return 'failed';
|
|
254
|
+
return 'completed';
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* File paths named by prompt attachments.
|
|
258
|
+
*
|
|
259
|
+
* Anything that is not a well-formed attachment is dropped rather than crashed
|
|
260
|
+
* on: the field is untrusted and its shape is not documented.
|
|
261
|
+
*
|
|
262
|
+
* @param attachments - Raw attachment list.
|
|
263
|
+
* @returns The paths, in order.
|
|
264
|
+
*/
|
|
265
|
+
function attachmentPaths(attachments) {
|
|
266
|
+
const paths = [];
|
|
267
|
+
for (const attachment of attachments) {
|
|
268
|
+
const filePath = asRecord(attachment)?.[ATTACHMENT_FILE_PATH_KEY];
|
|
269
|
+
if (typeof filePath === 'string' && filePath.length > 0)
|
|
270
|
+
paths.push(filePath);
|
|
271
|
+
}
|
|
272
|
+
return paths;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Structured inference parameters as a keyed record.
|
|
276
|
+
*
|
|
277
|
+
* Keeps only well-formed `{id, value}` entries; anything else is dropped, not
|
|
278
|
+
* crashed on.
|
|
279
|
+
*
|
|
280
|
+
* @param payload - Parsed hook payload.
|
|
281
|
+
* @returns The parameters, or undefined when there are none.
|
|
282
|
+
*/
|
|
283
|
+
function modelParams(payload) {
|
|
284
|
+
if (!Array.isArray(payload.model_params))
|
|
285
|
+
return undefined;
|
|
286
|
+
const params = {};
|
|
287
|
+
for (const entry of payload.model_params) {
|
|
288
|
+
const record = asRecord(entry);
|
|
289
|
+
const id = record?.['id'];
|
|
290
|
+
if (typeof id !== 'string' || id.length === 0)
|
|
291
|
+
continue;
|
|
292
|
+
params[id] = record?.['value'];
|
|
293
|
+
}
|
|
294
|
+
return Object.keys(params).length > 0 ? params : undefined;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Cursor's generic tool names on top of the shared vocabularies.
|
|
298
|
+
*
|
|
299
|
+
* @param toolName - Provider-reported tool name.
|
|
300
|
+
* @returns The kind.
|
|
301
|
+
*/
|
|
302
|
+
function cursorToolKind(toolName) {
|
|
303
|
+
if (toolName && CURSOR_TOOL_KINDS[toolName])
|
|
304
|
+
return CURSOR_TOOL_KINDS[toolName];
|
|
305
|
+
return classifyTool(toolName);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Canonical type for a hook, falling back to the tool classification.
|
|
309
|
+
*
|
|
310
|
+
* @param payload - Parsed hook payload.
|
|
311
|
+
* @param providerEventType - Cursor's own name for this hook.
|
|
312
|
+
* @returns The canonical event type.
|
|
313
|
+
*/
|
|
314
|
+
function canonicalType(payload, providerEventType) {
|
|
315
|
+
const direct = CURSOR_EVENT_TYPE_MAP[providerEventType];
|
|
316
|
+
if (direct)
|
|
317
|
+
return direct;
|
|
318
|
+
const kind = cursorToolKind(payload.tool_name);
|
|
319
|
+
if (providerEventType === 'preToolUse')
|
|
320
|
+
return toolStartType(kind);
|
|
321
|
+
if (providerEventType === 'postToolUse') {
|
|
322
|
+
// Kinds with a dedicated completion hook complete there; mapping the
|
|
323
|
+
// generic duplicate too would count the call twice.
|
|
324
|
+
return CURSOR_DEDICATED_COMPLETION_KINDS.has(kind) ? 'agent.other' : toolCompleteType(kind);
|
|
325
|
+
}
|
|
326
|
+
// Dedicated hooks carry no failure signal, so failures always arrive through
|
|
327
|
+
// the generic surface — no duplication risk here.
|
|
328
|
+
if (providerEventType === 'postToolUseFailure')
|
|
329
|
+
return 'tool.failed';
|
|
330
|
+
return 'agent.other';
|
|
331
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
2
|
+
import type { DetectionResult } from '../types/provider.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cursor's configuration root.
|
|
5
|
+
*
|
|
6
|
+
* @param env - Environment supplying HOME.
|
|
7
|
+
* @returns Absolute path of `~/.cursor`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function cursorHome(env: Env): string;
|
|
10
|
+
/**
|
|
11
|
+
* Where Cursor reads user-level hook registrations from.
|
|
12
|
+
*
|
|
13
|
+
* @param env - Environment supplying HOME.
|
|
14
|
+
* @returns Absolute path of `hooks.json`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cursorHooksJsonPath(env: Env): string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether Cursor is installed here, and whether our hooks are registered.
|
|
19
|
+
*
|
|
20
|
+
* @param env - Environment supplying HOME, cwd and PATH.
|
|
21
|
+
* @returns What was found.
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectCursor(env: Env): Promise<DetectionResult>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { findExecutable } from '../../core/which.js';
|
|
4
|
+
import { readJsonFile } from '../../storage/json-file.js';
|
|
5
|
+
import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
|
|
6
|
+
import { CURSOR_EXECUTABLES, CURSOR_HOME_DIR, CURSOR_HOOKS_FILE } from './constants/cursor.constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Cursor's configuration root.
|
|
9
|
+
*
|
|
10
|
+
* @param env - Environment supplying HOME.
|
|
11
|
+
* @returns Absolute path of `~/.cursor`.
|
|
12
|
+
*/
|
|
13
|
+
export function cursorHome(env) {
|
|
14
|
+
return path.join(env.home, CURSOR_HOME_DIR);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Where Cursor reads user-level hook registrations from.
|
|
18
|
+
*
|
|
19
|
+
* @param env - Environment supplying HOME.
|
|
20
|
+
* @returns Absolute path of `hooks.json`.
|
|
21
|
+
*/
|
|
22
|
+
export function cursorHooksJsonPath(env) {
|
|
23
|
+
return path.join(cursorHome(env), CURSOR_HOOKS_FILE);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether Cursor is installed here, and whether our hooks are registered.
|
|
27
|
+
*
|
|
28
|
+
* @param env - Environment supplying HOME, cwd and PATH.
|
|
29
|
+
* @returns What was found.
|
|
30
|
+
*/
|
|
31
|
+
export async function detectCursor(env) {
|
|
32
|
+
const evidence = [];
|
|
33
|
+
if (fs.existsSync(cursorHome(env)))
|
|
34
|
+
evidence.push('~/.cursor directory exists');
|
|
35
|
+
if (fs.existsSync(path.join(env.cwd, CURSOR_HOME_DIR)))
|
|
36
|
+
evidence.push('.cursor directory in working tree');
|
|
37
|
+
const executablePath = findFirstExecutable(env);
|
|
38
|
+
if (executablePath)
|
|
39
|
+
evidence.push(`cursor executable on PATH (${executablePath})`);
|
|
40
|
+
const hookConfigPath = cursorHooksJsonPath(env);
|
|
41
|
+
const hooksFile = await readJsonFile(hookConfigPath);
|
|
42
|
+
return {
|
|
43
|
+
detected: evidence.length > 0,
|
|
44
|
+
evidence,
|
|
45
|
+
executablePath,
|
|
46
|
+
hookConfigPath,
|
|
47
|
+
hooksInstalled: hooksFile.state === 'ok' && JSON.stringify(hooksFile.value).includes(HOOK_COMMAND_MARKER)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The first of Cursor's executable names found on PATH.
|
|
52
|
+
*
|
|
53
|
+
* The editor ships `cursor`; the CLI agent ships `cursor-agent`, and a machine
|
|
54
|
+
* may have either.
|
|
55
|
+
*
|
|
56
|
+
* @param env - Environment supplying PATH.
|
|
57
|
+
* @returns The path, or undefined when neither is installed.
|
|
58
|
+
*/
|
|
59
|
+
function findFirstExecutable(env) {
|
|
60
|
+
for (const name of CURSOR_EXECUTABLES) {
|
|
61
|
+
const found = findExecutable(env, name);
|
|
62
|
+
if (found)
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SetupContext, SetupOutcome } from '../types/provider.types.js';
|
|
2
|
+
export { CURSOR_HOOK_EVENTS } from './constants/cursor.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register AgentWatch's hooks in `~/.cursor/hooks.json`.
|
|
5
|
+
*
|
|
6
|
+
* Cursor's entries are flat command objects rather than matcher groups, so ours
|
|
7
|
+
* is one entry per event. An existing `version` is preserved verbatim — the
|
|
8
|
+
* documented schema is 1, but the user's file is the authority on what Cursor
|
|
9
|
+
* build wrote it.
|
|
10
|
+
*
|
|
11
|
+
* @param context - Environment, paths, config and the hook command to write.
|
|
12
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
13
|
+
* install state.
|
|
14
|
+
*/
|
|
15
|
+
export declare function installCursorHooks(context: SetupContext): Promise<SetupOutcome>;
|
|
16
|
+
/**
|
|
17
|
+
* Remove AgentWatch's hooks from `~/.cursor/hooks.json`.
|
|
18
|
+
*
|
|
19
|
+
* Every other top-level field, `version` included, is preserved.
|
|
20
|
+
*
|
|
21
|
+
* @param context - Environment, paths and current install state.
|
|
22
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
23
|
+
* install state.
|
|
24
|
+
*/
|
|
25
|
+
export declare function uninstallCursorHooks(context: SetupContext): Promise<SetupOutcome>;
|