@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,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-name vocabularies, as O(1) sets.
|
|
3
|
+
*
|
|
4
|
+
* `run_command`, `edit_file` and `write_to_file` are Antigravity's names, read
|
|
5
|
+
* off the tool schemas in the `agy` binary. A name no set lists falls through
|
|
6
|
+
* to 'other' -> tool.completed, which is accurate rather than guessed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SHELL_TOOLS: ReadonlySet<string>;
|
|
9
|
+
export declare const FILE_READ_TOOLS: ReadonlySet<string>;
|
|
10
|
+
export declare const FILE_EDIT_TOOLS: ReadonlySet<string>;
|
|
11
|
+
/** Prefix and separator of an MCP tool name. */
|
|
12
|
+
export declare const MCP_TOOL_PREFIX = "mcp__";
|
|
13
|
+
export declare const MCP_TOOL_SEPARATOR = "__";
|
|
14
|
+
/**
|
|
15
|
+
* Keys a file path may arrive under, in priority order.
|
|
16
|
+
*
|
|
17
|
+
* Antigravity's tool arguments are PascalCase (`TargetFile`); every other
|
|
18
|
+
* provider uses snake_case or camelCase.
|
|
19
|
+
*/
|
|
20
|
+
export declare const FILE_PATH_KEYS: readonly ["file_path", "path", "notebook_path", "filePath", "TargetFile", "AbsolutePath"];
|
|
21
|
+
/**
|
|
22
|
+
* Keys a shell command may arrive under, in priority order. `CommandLine` is
|
|
23
|
+
* Antigravity's name for it (`run_command`); everything else uses `command`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const COMMAND_KEYS: readonly ["CommandLine", "command"];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-name vocabularies, as O(1) sets.
|
|
3
|
+
*
|
|
4
|
+
* `run_command`, `edit_file` and `write_to_file` are Antigravity's names, read
|
|
5
|
+
* off the tool schemas in the `agy` binary. A name no set lists falls through
|
|
6
|
+
* to 'other' -> tool.completed, which is accurate rather than guessed.
|
|
7
|
+
*/
|
|
8
|
+
export const SHELL_TOOLS = new Set(['Bash', 'shell', 'local_shell', 'exec_command', 'run_command']);
|
|
9
|
+
export const FILE_READ_TOOLS = new Set(['Read', 'read_file', 'view_image']);
|
|
10
|
+
export const FILE_EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'apply_patch', 'edit_file', 'write_to_file']);
|
|
11
|
+
/** Prefix and separator of an MCP tool name. */
|
|
12
|
+
export const MCP_TOOL_PREFIX = 'mcp__';
|
|
13
|
+
export const MCP_TOOL_SEPARATOR = '__';
|
|
14
|
+
/**
|
|
15
|
+
* Keys a file path may arrive under, in priority order.
|
|
16
|
+
*
|
|
17
|
+
* Antigravity's tool arguments are PascalCase (`TargetFile`); every other
|
|
18
|
+
* provider uses snake_case or camelCase.
|
|
19
|
+
*/
|
|
20
|
+
export const FILE_PATH_KEYS = ['file_path', 'path', 'notebook_path', 'filePath', 'TargetFile', 'AbsolutePath'];
|
|
21
|
+
/**
|
|
22
|
+
* Keys a shell command may arrive under, in priority order. `CommandLine` is
|
|
23
|
+
* Antigravity's name for it (`run_command`); everything else uses `command`.
|
|
24
|
+
*/
|
|
25
|
+
export const COMMAND_KEYS = ['CommandLine', 'command'];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { UnknownRecord } from '../../core/types/core.types.js';
|
|
2
|
+
import type { AgentWatchEvent, EventPatch } from '../../events/types/events.types.js';
|
|
3
|
+
import type { BaseEventInput, CapturePolicy, ToolCallInput } from './types/adapter.types.js';
|
|
4
|
+
export type { BaseEventInput, CapturePolicy, ToolCallInput } from './types/adapter.types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The part of a canonical event every provider fills in the same way.
|
|
7
|
+
*
|
|
8
|
+
* Adapters build this once and then describe what is *specific* to the hook as
|
|
9
|
+
* a patch, instead of creating an event and editing it field by field. That is
|
|
10
|
+
* what keeps an adapter readable as a mapping table rather than a procedure.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Identity, session scope and provider metadata.
|
|
13
|
+
* @returns The base event.
|
|
14
|
+
*/
|
|
15
|
+
export declare function baseEvent(input: BaseEventInput): AgentWatchEvent;
|
|
16
|
+
/**
|
|
17
|
+
* Combine a base event with what one hook contributed.
|
|
18
|
+
*
|
|
19
|
+
* The nested blocks merge rather than replace — `session`, `ai` and `tool` per
|
|
20
|
+
* field, `metadata` (including its `provider` block) per key — so a patch can
|
|
21
|
+
* add the one field its hook knows about without having to restate the session
|
|
22
|
+
* scope the base already resolved.
|
|
23
|
+
*
|
|
24
|
+
* @param event - The base event.
|
|
25
|
+
* @param patch - Hook-specific fields.
|
|
26
|
+
* @returns A new event carrying both.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withPatch(event: AgentWatchEvent, patch: EventPatch): AgentWatchEvent;
|
|
29
|
+
/**
|
|
30
|
+
* Merge two metadata bags, merging their `provider` blocks too.
|
|
31
|
+
*
|
|
32
|
+
* @param base - Metadata from the base event.
|
|
33
|
+
* @param extra - Metadata from the patch.
|
|
34
|
+
* @returns The merged bag, or undefined when both were empty.
|
|
35
|
+
*/
|
|
36
|
+
export declare function mergeMetadata(base: AgentWatchEvent['metadata'], extra: AgentWatchEvent['metadata']): AgentWatchEvent['metadata'];
|
|
37
|
+
/**
|
|
38
|
+
* Patch carrying provider-specific metadata only.
|
|
39
|
+
*
|
|
40
|
+
* @param fields - Provider fields; undefined entries are dropped.
|
|
41
|
+
* @returns The patch.
|
|
42
|
+
*/
|
|
43
|
+
export declare function providerPatch(fields: UnknownRecord): EventPatch;
|
|
44
|
+
/**
|
|
45
|
+
* Patch for a captured prompt: always its evidence, the text only when the
|
|
46
|
+
* effective config permits it.
|
|
47
|
+
*
|
|
48
|
+
* @param prompt - The prompt text as the agent reported it.
|
|
49
|
+
* @param capture - What the effective config allows.
|
|
50
|
+
* @returns The patch.
|
|
51
|
+
*/
|
|
52
|
+
export declare function promptPatch(prompt: string, capture: CapturePolicy): EventPatch;
|
|
53
|
+
/**
|
|
54
|
+
* Patch for a captured response: always its evidence, the text only when the
|
|
55
|
+
* effective config permits it.
|
|
56
|
+
*
|
|
57
|
+
* @param response - The response text as the agent reported it.
|
|
58
|
+
* @param capture - What the effective config allows.
|
|
59
|
+
* @returns The patch.
|
|
60
|
+
*/
|
|
61
|
+
export declare function responsePatch(response: string, capture: CapturePolicy): EventPatch;
|
|
62
|
+
/**
|
|
63
|
+
* Patch for a tool call: the canonical `tool` block plus whatever of its
|
|
64
|
+
* input, output and file path the effective config permits.
|
|
65
|
+
*
|
|
66
|
+
* `capture.files` gates every per-file signal, not just Git's changed-file
|
|
67
|
+
* list. The file path is kept absolute here; the enrichment stage relativizes
|
|
68
|
+
* it against the repository root, which is the only place that knows the root.
|
|
69
|
+
*
|
|
70
|
+
* @param call - The tool call.
|
|
71
|
+
* @param capture - What the effective config allows.
|
|
72
|
+
* @returns The patch.
|
|
73
|
+
*/
|
|
74
|
+
export declare function toolPatch(call: ToolCallInput, capture: CapturePolicy): EventPatch;
|
|
75
|
+
/**
|
|
76
|
+
* Patch carrying a file path, when one is known and permitted.
|
|
77
|
+
*
|
|
78
|
+
* For providers whose dedicated file hooks report the path directly instead of
|
|
79
|
+
* inside a tool-input object.
|
|
80
|
+
*
|
|
81
|
+
* @param filePath - The reported path.
|
|
82
|
+
* @param capture - What the effective config allows.
|
|
83
|
+
* @returns The patch, empty when the path is absent or not permitted.
|
|
84
|
+
*/
|
|
85
|
+
export declare function filePathPatch(filePath: string | undefined, capture: CapturePolicy): EventPatch;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { compact } from '../../core/object.js';
|
|
2
|
+
import { EVENT_SCHEMA_VERSION } from '../../events/constants/events.constants.js';
|
|
3
|
+
import { deriveEventId } from '../../events/event-id.js';
|
|
4
|
+
import { contentEvidence, extractCommand, extractFilePath } from './tooling.js';
|
|
5
|
+
/** Metadata key holding the provider's own, non-canonical fields. */
|
|
6
|
+
const PROVIDER_METADATA_KEY = 'provider';
|
|
7
|
+
/**
|
|
8
|
+
* The part of a canonical event every provider fills in the same way.
|
|
9
|
+
*
|
|
10
|
+
* Adapters build this once and then describe what is *specific* to the hook as
|
|
11
|
+
* a patch, instead of creating an event and editing it field by field. That is
|
|
12
|
+
* what keeps an adapter readable as a mapping table rather than a procedure.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Identity, session scope and provider metadata.
|
|
15
|
+
* @returns The base event.
|
|
16
|
+
*/
|
|
17
|
+
export function baseEvent(input) {
|
|
18
|
+
return {
|
|
19
|
+
schemaVersion: EVENT_SCHEMA_VERSION,
|
|
20
|
+
id: deriveEventId({
|
|
21
|
+
provider: input.provider,
|
|
22
|
+
providerEventType: input.providerEventType,
|
|
23
|
+
sessionId: input.sessionId,
|
|
24
|
+
turnId: input.turnId,
|
|
25
|
+
toolUseId: input.toolUseId,
|
|
26
|
+
promptId: input.promptId,
|
|
27
|
+
payloadFingerprint: input.payloadFingerprint
|
|
28
|
+
}),
|
|
29
|
+
timestamp: input.timestamp,
|
|
30
|
+
event: { type: input.eventType, providerEventType: input.providerEventType },
|
|
31
|
+
agent: { provider: input.provider, name: input.displayName },
|
|
32
|
+
session: {
|
|
33
|
+
id: input.sessionId,
|
|
34
|
+
providerId: input.sessionId,
|
|
35
|
+
turnId: input.turnId,
|
|
36
|
+
agentId: input.agentId
|
|
37
|
+
},
|
|
38
|
+
ai: input.ai,
|
|
39
|
+
metadata: { [PROVIDER_METADATA_KEY]: compact(input.providerMetadata ?? {}) }
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Combine a base event with what one hook contributed.
|
|
44
|
+
*
|
|
45
|
+
* The nested blocks merge rather than replace — `session`, `ai` and `tool` per
|
|
46
|
+
* field, `metadata` (including its `provider` block) per key — so a patch can
|
|
47
|
+
* add the one field its hook knows about without having to restate the session
|
|
48
|
+
* scope the base already resolved.
|
|
49
|
+
*
|
|
50
|
+
* @param event - The base event.
|
|
51
|
+
* @param patch - Hook-specific fields.
|
|
52
|
+
* @returns A new event carrying both.
|
|
53
|
+
*/
|
|
54
|
+
export function withPatch(event, patch) {
|
|
55
|
+
return compact({
|
|
56
|
+
...event,
|
|
57
|
+
...patch,
|
|
58
|
+
session: patch.session ? { ...event.session, ...patch.session } : event.session,
|
|
59
|
+
ai: patch.ai ? compact({ ...event.ai, ...patch.ai }) : event.ai,
|
|
60
|
+
tool: patch.tool ? compact({ ...event.tool, ...patch.tool }) : event.tool,
|
|
61
|
+
metadata: mergeMetadata(event.metadata, patch.metadata)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Merge two metadata bags, merging their `provider` blocks too.
|
|
66
|
+
*
|
|
67
|
+
* @param base - Metadata from the base event.
|
|
68
|
+
* @param extra - Metadata from the patch.
|
|
69
|
+
* @returns The merged bag, or undefined when both were empty.
|
|
70
|
+
*/
|
|
71
|
+
export function mergeMetadata(base, extra) {
|
|
72
|
+
if (!extra)
|
|
73
|
+
return base;
|
|
74
|
+
if (!base)
|
|
75
|
+
return compact(extra);
|
|
76
|
+
const baseProvider = base[PROVIDER_METADATA_KEY];
|
|
77
|
+
const extraProvider = extra[PROVIDER_METADATA_KEY];
|
|
78
|
+
const merged = compact({ ...base, ...extra });
|
|
79
|
+
if (baseProvider || extraProvider) {
|
|
80
|
+
merged[PROVIDER_METADATA_KEY] = compact({ ...baseProvider, ...extraProvider });
|
|
81
|
+
}
|
|
82
|
+
return merged;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Patch carrying provider-specific metadata only.
|
|
86
|
+
*
|
|
87
|
+
* @param fields - Provider fields; undefined entries are dropped.
|
|
88
|
+
* @returns The patch.
|
|
89
|
+
*/
|
|
90
|
+
export function providerPatch(fields) {
|
|
91
|
+
return { metadata: { [PROVIDER_METADATA_KEY]: compact(fields) } };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Patch for a captured prompt: always its evidence, the text only when the
|
|
95
|
+
* effective config permits it.
|
|
96
|
+
*
|
|
97
|
+
* @param prompt - The prompt text as the agent reported it.
|
|
98
|
+
* @param capture - What the effective config allows.
|
|
99
|
+
* @returns The patch.
|
|
100
|
+
*/
|
|
101
|
+
export function promptPatch(prompt, capture) {
|
|
102
|
+
return {
|
|
103
|
+
metadata: compact({
|
|
104
|
+
prompt: contentEvidence(prompt),
|
|
105
|
+
promptText: capture.prompts && prompt ? prompt : undefined
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Patch for a captured response: always its evidence, the text only when the
|
|
111
|
+
* effective config permits it.
|
|
112
|
+
*
|
|
113
|
+
* @param response - The response text as the agent reported it.
|
|
114
|
+
* @param capture - What the effective config allows.
|
|
115
|
+
* @returns The patch.
|
|
116
|
+
*/
|
|
117
|
+
export function responsePatch(response, capture) {
|
|
118
|
+
return {
|
|
119
|
+
metadata: compact({
|
|
120
|
+
response: response ? contentEvidence(response) : undefined,
|
|
121
|
+
responseText: capture.responses && response ? response : undefined
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Patch for a tool call: the canonical `tool` block plus whatever of its
|
|
127
|
+
* input, output and file path the effective config permits.
|
|
128
|
+
*
|
|
129
|
+
* `capture.files` gates every per-file signal, not just Git's changed-file
|
|
130
|
+
* list. The file path is kept absolute here; the enrichment stage relativizes
|
|
131
|
+
* it against the repository root, which is the only place that knows the root.
|
|
132
|
+
*
|
|
133
|
+
* @param call - The tool call.
|
|
134
|
+
* @param capture - What the effective config allows.
|
|
135
|
+
* @returns The patch.
|
|
136
|
+
*/
|
|
137
|
+
export function toolPatch(call, capture) {
|
|
138
|
+
const isFileTool = call.kind === 'file-read' || call.kind === 'file-edit';
|
|
139
|
+
const filePath = isFileTool ? extractFilePath(call.input) : undefined;
|
|
140
|
+
return {
|
|
141
|
+
tool: compact({ name: call.name, status: call.status, durationMs: call.durationMs }),
|
|
142
|
+
metadata: compact({
|
|
143
|
+
command: call.kind === 'shell' && capture.toolInput ? extractCommand(call.input) : undefined,
|
|
144
|
+
filePath: filePath && capture.files ? filePath : undefined,
|
|
145
|
+
toolInput: capture.toolInput && call.input !== undefined ? call.input : undefined,
|
|
146
|
+
toolOutput: capture.toolOutput && call.output !== undefined ? call.output : undefined,
|
|
147
|
+
error: call.error !== undefined ? contentEvidence(JSON.stringify(call.error)) : undefined,
|
|
148
|
+
[PROVIDER_METADATA_KEY]: compact({ toolUseId: call.toolUseId, ...call.providerFields })
|
|
149
|
+
})
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Patch carrying a file path, when one is known and permitted.
|
|
154
|
+
*
|
|
155
|
+
* For providers whose dedicated file hooks report the path directly instead of
|
|
156
|
+
* inside a tool-input object.
|
|
157
|
+
*
|
|
158
|
+
* @param filePath - The reported path.
|
|
159
|
+
* @param capture - What the effective config allows.
|
|
160
|
+
* @returns The patch, empty when the path is absent or not permitted.
|
|
161
|
+
*/
|
|
162
|
+
export function filePathPatch(filePath, capture) {
|
|
163
|
+
if (!filePath || !capture.files)
|
|
164
|
+
return {};
|
|
165
|
+
return { metadata: { filePath } };
|
|
166
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { UnknownRecord } from '../../core/types/core.types.js';
|
|
2
|
+
import type { StripOptions, StripResult } from './types/hook-config.types.js';
|
|
3
|
+
export type { HookHandler, HookMatcherGroup, StripOptions, StripResult } from './types/hook-config.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether one handler is an AgentWatch command.
|
|
6
|
+
*
|
|
7
|
+
* @param handler - Entry from an agent's hook list.
|
|
8
|
+
* @returns True when we own it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isOurHandler(handler: unknown): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Remove AgentWatch handlers from one event's entry list.
|
|
13
|
+
*
|
|
14
|
+
* Handlers, not whole groups: a user may have added their own handler into the
|
|
15
|
+
* group we created, and uninstalling AgentWatch must not take it with us. A
|
|
16
|
+
* group left with no handlers is dropped; anything we do not recognize is
|
|
17
|
+
* passed through untouched.
|
|
18
|
+
*
|
|
19
|
+
* @param entries - The event's entry list.
|
|
20
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
21
|
+
* @returns The entries to keep.
|
|
22
|
+
*/
|
|
23
|
+
export declare function withoutOurHandlers(entries: readonly unknown[], options?: StripOptions): unknown[];
|
|
24
|
+
/**
|
|
25
|
+
* Remove AgentWatch handlers from every event of a hook map.
|
|
26
|
+
*
|
|
27
|
+
* @param hooks - Event name to entry list.
|
|
28
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
29
|
+
* @returns The cleaned map and whether anything was removed.
|
|
30
|
+
*/
|
|
31
|
+
export declare function stripOurHandlers(hooks: UnknownRecord, options?: StripOptions): StripResult;
|
|
32
|
+
/**
|
|
33
|
+
* Register AgentWatch's entry on each event, replacing our previous one.
|
|
34
|
+
*
|
|
35
|
+
* Existing user handlers on those events are preserved; ours are stripped
|
|
36
|
+
* first so a re-run cannot accumulate duplicates — two registrations would
|
|
37
|
+
* make every turn be processed, and counted, twice.
|
|
38
|
+
*
|
|
39
|
+
* @param hooks - Event name to entry list.
|
|
40
|
+
* @param events - Events to register on.
|
|
41
|
+
* @param entryFor - Builds our entry for one event.
|
|
42
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
43
|
+
* @returns The updated map.
|
|
44
|
+
*/
|
|
45
|
+
export declare function registerOurHandlers(hooks: UnknownRecord, events: readonly string[], entryFor: (eventName: string) => unknown, options?: StripOptions): UnknownRecord;
|
|
46
|
+
/**
|
|
47
|
+
* Drop AgentWatch registrations from events we no longer subscribe to.
|
|
48
|
+
*
|
|
49
|
+
* Without this, an event registered by an earlier version keeps firing a hook
|
|
50
|
+
* nothing reads.
|
|
51
|
+
*
|
|
52
|
+
* @param hooks - Event name to entry list.
|
|
53
|
+
* @param registered - Events this version registers.
|
|
54
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
55
|
+
* @returns The updated map.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sweepUnregisteredEvents(hooks: UnknownRecord, registered: readonly string[], options?: StripOptions): UnknownRecord;
|
|
58
|
+
/**
|
|
59
|
+
* A config with its hooks block replaced, dropping the block when it is empty.
|
|
60
|
+
*
|
|
61
|
+
* An empty `hooks: {}` left behind is indistinguishable from a deliberate
|
|
62
|
+
* empty configuration, so the key goes rather than being emptied.
|
|
63
|
+
*
|
|
64
|
+
* @param config - The whole config object.
|
|
65
|
+
* @param hooks - The new hooks block.
|
|
66
|
+
* @param key - Name of the block; agents differ ('hooks' everywhere so far).
|
|
67
|
+
* @returns The next config object.
|
|
68
|
+
*/
|
|
69
|
+
export declare function withHooksBlock(config: UnknownRecord, hooks: UnknownRecord, key?: string): UnknownRecord;
|
|
70
|
+
/**
|
|
71
|
+
* Serialize and write an agent config, verifying it parses first.
|
|
72
|
+
*
|
|
73
|
+
* Agents reject an invalid config file wholesale — Claude stops honouring
|
|
74
|
+
* every setting in it, not just the hooks — so a serialization bug must fail
|
|
75
|
+
* before the file is touched, not after.
|
|
76
|
+
*
|
|
77
|
+
* @param targetPath - File to write.
|
|
78
|
+
* @param value - The whole config object.
|
|
79
|
+
*/
|
|
80
|
+
export declare function writeJsonValidated(targetPath: string, value: UnknownRecord): Promise<void>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { isRecord, omitKeys } from '../../core/object.js';
|
|
2
|
+
import { writeFileAtomic } from '../../storage/atomic-file.js';
|
|
3
|
+
import { isAgentWatchHookCommand } from '../provider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether one handler is an AgentWatch command.
|
|
6
|
+
*
|
|
7
|
+
* @param handler - Entry from an agent's hook list.
|
|
8
|
+
* @returns True when we own it.
|
|
9
|
+
*/
|
|
10
|
+
export function isOurHandler(handler) {
|
|
11
|
+
const record = handler;
|
|
12
|
+
if (!isRecord(record) || typeof record.command !== 'string')
|
|
13
|
+
return false;
|
|
14
|
+
return isAgentWatchHookCommand(record.command);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Remove AgentWatch handlers from one event's entry list.
|
|
18
|
+
*
|
|
19
|
+
* Handlers, not whole groups: a user may have added their own handler into the
|
|
20
|
+
* group we created, and uninstalling AgentWatch must not take it with us. A
|
|
21
|
+
* group left with no handlers is dropped; anything we do not recognize is
|
|
22
|
+
* passed through untouched.
|
|
23
|
+
*
|
|
24
|
+
* @param entries - The event's entry list.
|
|
25
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
26
|
+
* @returns The entries to keep.
|
|
27
|
+
*/
|
|
28
|
+
export function withoutOurHandlers(entries, options = {}) {
|
|
29
|
+
const kept = [];
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
if (options.allowBareHandlers && isOurHandler(entry))
|
|
32
|
+
continue;
|
|
33
|
+
const group = isRecord(entry) ? entry : undefined;
|
|
34
|
+
const handlers = group?.['hooks'];
|
|
35
|
+
if (!Array.isArray(handlers)) {
|
|
36
|
+
kept.push(entry);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const remaining = handlers.filter((handler) => !isOurHandler(handler));
|
|
40
|
+
if (remaining.length === handlers.length) {
|
|
41
|
+
kept.push(entry);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// A group that was purely ours disappears with its last handler.
|
|
45
|
+
if (remaining.length > 0)
|
|
46
|
+
kept.push({ ...group, hooks: remaining });
|
|
47
|
+
}
|
|
48
|
+
return kept;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove AgentWatch handlers from every event of a hook map.
|
|
52
|
+
*
|
|
53
|
+
* @param hooks - Event name to entry list.
|
|
54
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
55
|
+
* @returns The cleaned map and whether anything was removed.
|
|
56
|
+
*/
|
|
57
|
+
export function stripOurHandlers(hooks, options = {}) {
|
|
58
|
+
const out = {};
|
|
59
|
+
let changed = false;
|
|
60
|
+
for (const [eventName, value] of Object.entries(hooks)) {
|
|
61
|
+
if (!Array.isArray(value)) {
|
|
62
|
+
out[eventName] = value;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const kept = withoutOurHandlers(value, options);
|
|
66
|
+
if (sameEntries(kept, value)) {
|
|
67
|
+
out[eventName] = value;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
changed = true;
|
|
71
|
+
// An event whose only handlers were ours is removed rather than left as an
|
|
72
|
+
// empty list, which is how the agent's own config would express "none".
|
|
73
|
+
if (kept.length > 0)
|
|
74
|
+
out[eventName] = kept;
|
|
75
|
+
}
|
|
76
|
+
return { hooks: out, changed };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register AgentWatch's entry on each event, replacing our previous one.
|
|
80
|
+
*
|
|
81
|
+
* Existing user handlers on those events are preserved; ours are stripped
|
|
82
|
+
* first so a re-run cannot accumulate duplicates — two registrations would
|
|
83
|
+
* make every turn be processed, and counted, twice.
|
|
84
|
+
*
|
|
85
|
+
* @param hooks - Event name to entry list.
|
|
86
|
+
* @param events - Events to register on.
|
|
87
|
+
* @param entryFor - Builds our entry for one event.
|
|
88
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
89
|
+
* @returns The updated map.
|
|
90
|
+
*/
|
|
91
|
+
export function registerOurHandlers(hooks, events, entryFor, options = {}) {
|
|
92
|
+
const out = { ...hooks };
|
|
93
|
+
for (const eventName of events) {
|
|
94
|
+
const existing = Array.isArray(out[eventName]) ? out[eventName] : [];
|
|
95
|
+
out[eventName] = [...withoutOurHandlers(existing, options), entryFor(eventName)];
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Drop AgentWatch registrations from events we no longer subscribe to.
|
|
101
|
+
*
|
|
102
|
+
* Without this, an event registered by an earlier version keeps firing a hook
|
|
103
|
+
* nothing reads.
|
|
104
|
+
*
|
|
105
|
+
* @param hooks - Event name to entry list.
|
|
106
|
+
* @param registered - Events this version registers.
|
|
107
|
+
* @param options - Whether bare handlers are accepted alongside groups.
|
|
108
|
+
* @returns The updated map.
|
|
109
|
+
*/
|
|
110
|
+
export function sweepUnregisteredEvents(hooks, registered, options = {}) {
|
|
111
|
+
const keep = new Set(registered);
|
|
112
|
+
const out = {};
|
|
113
|
+
for (const [eventName, value] of Object.entries(hooks)) {
|
|
114
|
+
if (keep.has(eventName) || !Array.isArray(value)) {
|
|
115
|
+
out[eventName] = value;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const kept = withoutOurHandlers(value, options);
|
|
119
|
+
if (kept.length > 0)
|
|
120
|
+
out[eventName] = kept;
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A config with its hooks block replaced, dropping the block when it is empty.
|
|
126
|
+
*
|
|
127
|
+
* An empty `hooks: {}` left behind is indistinguishable from a deliberate
|
|
128
|
+
* empty configuration, so the key goes rather than being emptied.
|
|
129
|
+
*
|
|
130
|
+
* @param config - The whole config object.
|
|
131
|
+
* @param hooks - The new hooks block.
|
|
132
|
+
* @param key - Name of the block; agents differ ('hooks' everywhere so far).
|
|
133
|
+
* @returns The next config object.
|
|
134
|
+
*/
|
|
135
|
+
export function withHooksBlock(config, hooks, key = 'hooks') {
|
|
136
|
+
if (Object.keys(hooks).length === 0)
|
|
137
|
+
return omitKeys(config, new Set([key]));
|
|
138
|
+
return { ...config, [key]: hooks };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Serialize and write an agent config, verifying it parses first.
|
|
142
|
+
*
|
|
143
|
+
* Agents reject an invalid config file wholesale — Claude stops honouring
|
|
144
|
+
* every setting in it, not just the hooks — so a serialization bug must fail
|
|
145
|
+
* before the file is touched, not after.
|
|
146
|
+
*
|
|
147
|
+
* @param targetPath - File to write.
|
|
148
|
+
* @param value - The whole config object.
|
|
149
|
+
*/
|
|
150
|
+
export async function writeJsonValidated(targetPath, value) {
|
|
151
|
+
const serialized = `${JSON.stringify(value, null, 2)}\n`;
|
|
152
|
+
JSON.parse(serialized);
|
|
153
|
+
await writeFileAtomic(targetPath, serialized);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether two entry lists are equivalent.
|
|
157
|
+
*
|
|
158
|
+
* @param left - One list.
|
|
159
|
+
* @param right - The other.
|
|
160
|
+
* @returns True when they describe the same registrations.
|
|
161
|
+
*/
|
|
162
|
+
function sameEntries(left, right) {
|
|
163
|
+
return left.length === right.length && JSON.stringify(left) === JSON.stringify(right);
|
|
164
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UnknownRecord } from '../../core/types/core.types.js';
|
|
2
|
+
import type { ProviderHookResponse } from '../types/provider.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A refusal for the hooks an agent lets a hook refuse, and nothing for the rest.
|
|
5
|
+
*
|
|
6
|
+
* The exit code stays 0 even here: the refusal travels in the protocol's own
|
|
7
|
+
* field, which is what makes it a decision the agent understands rather than a
|
|
8
|
+
* crashed hook. A non-zero exit from a telemetry hook is what invariant 4.1
|
|
9
|
+
* forbids, and it would refuse the turn for the wrong reason.
|
|
10
|
+
*
|
|
11
|
+
* @param payload - Raw hook payload.
|
|
12
|
+
* @param gateEvents - Hooks of this agent that carry a refusal.
|
|
13
|
+
* @param body - The agent's refusal, in its own protocol's fields.
|
|
14
|
+
* @returns The response, or undefined when this hook cannot refuse anything.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hookRefusal(payload: unknown, gateEvents: ReadonlySet<string>, body: UnknownRecord): ProviderHookResponse | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { asRecord } from '../../core/object.js';
|
|
2
|
+
import { PAYLOAD_HOOK_EVENT_KEY } from './constants/hook-refusal.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* A refusal for the hooks an agent lets a hook refuse, and nothing for the rest.
|
|
5
|
+
*
|
|
6
|
+
* The exit code stays 0 even here: the refusal travels in the protocol's own
|
|
7
|
+
* field, which is what makes it a decision the agent understands rather than a
|
|
8
|
+
* crashed hook. A non-zero exit from a telemetry hook is what invariant 4.1
|
|
9
|
+
* forbids, and it would refuse the turn for the wrong reason.
|
|
10
|
+
*
|
|
11
|
+
* @param payload - Raw hook payload.
|
|
12
|
+
* @param gateEvents - Hooks of this agent that carry a refusal.
|
|
13
|
+
* @param body - The agent's refusal, in its own protocol's fields.
|
|
14
|
+
* @returns The response, or undefined when this hook cannot refuse anything.
|
|
15
|
+
*/
|
|
16
|
+
export function hookRefusal(payload, gateEvents, body) {
|
|
17
|
+
if (!gateEvents.has(hookEventName(payload) ?? ''))
|
|
18
|
+
return undefined;
|
|
19
|
+
return { stdout: JSON.stringify(body), exitCode: 0 };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The hook the agent fired, as the agent names it.
|
|
23
|
+
*
|
|
24
|
+
* Every provider with a JSON hook protocol reports it under the same key; a
|
|
25
|
+
* payload that does not is one no gate applies to.
|
|
26
|
+
*
|
|
27
|
+
* @param payload - Raw hook payload.
|
|
28
|
+
* @returns The provider's own event name, or undefined.
|
|
29
|
+
*/
|
|
30
|
+
function hookEventName(payload) {
|
|
31
|
+
const reported = asRecord(payload)?.[PAYLOAD_HOOK_EVENT_KEY];
|
|
32
|
+
return typeof reported === 'string' && reported !== '' ? reported : undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { InstallState } from '../../storage/types/storage.types.js';
|
|
2
|
+
/** What one hook installation recorded about itself. */
|
|
3
|
+
export interface HookInstallRecord {
|
|
4
|
+
readonly hookConfigPath: string;
|
|
5
|
+
readonly hookEvents: readonly string[];
|
|
6
|
+
readonly hookCommand: string;
|
|
7
|
+
readonly installedAt: Date;
|
|
8
|
+
/** Manual follow-up steps the user has to take, e.g. Codex's trust prompt. */
|
|
9
|
+
readonly notes?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Install state with one agent's hook registration recorded.
|
|
13
|
+
*
|
|
14
|
+
* Returns a new state rather than editing the one it was given: setup runs
|
|
15
|
+
* several operations per agent and persists once at the end, and an operation
|
|
16
|
+
* that edited shared state would make the order of those calls part of the
|
|
17
|
+
* result.
|
|
18
|
+
*
|
|
19
|
+
* @param state - Current install state.
|
|
20
|
+
* @param agentId - Agent that was just installed.
|
|
21
|
+
* @param record - What was written, and where.
|
|
22
|
+
* @returns The next install state.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withHookInstall(state: InstallState, agentId: string, record: HookInstallRecord): InstallState;
|
|
25
|
+
/**
|
|
26
|
+
* Install state with one agent's hook registration forgotten.
|
|
27
|
+
*
|
|
28
|
+
* The agent's entry survives so any native-telemetry record on it stays
|
|
29
|
+
* intact; only the hook fields are cleared.
|
|
30
|
+
*
|
|
31
|
+
* @param state - Current install state.
|
|
32
|
+
* @param agentId - Agent whose hooks were removed.
|
|
33
|
+
* @returns The next install state.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withoutHookInstall(state: InstallState, agentId: string): InstallState;
|
|
36
|
+
/**
|
|
37
|
+
* Install state with one agent dropped entirely.
|
|
38
|
+
*
|
|
39
|
+
* For an agent whose config file is gone: there is nothing left to describe,
|
|
40
|
+
* and a stale entry would make `status` claim an installation that no longer
|
|
41
|
+
* exists.
|
|
42
|
+
*
|
|
43
|
+
* @param state - Current install state.
|
|
44
|
+
* @param agentId - Agent to forget.
|
|
45
|
+
* @returns The next install state.
|
|
46
|
+
*/
|
|
47
|
+
export declare function withoutAgent(state: InstallState, agentId: string): InstallState;
|
|
48
|
+
/** What one native-telemetry configuration recorded about itself. */
|
|
49
|
+
export interface OtelInstallRecord {
|
|
50
|
+
readonly configPath: string;
|
|
51
|
+
/** Config keys AgentWatch now owns, and may therefore remove later. */
|
|
52
|
+
readonly ownedKeys: readonly string[];
|
|
53
|
+
readonly configuredAt: Date;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Install state with one agent's native-telemetry configuration recorded.
|
|
57
|
+
*
|
|
58
|
+
* The owned-key list is the whole point of persisting this: without it,
|
|
59
|
+
* uninstall cannot tell the variables we wrote from the ones the developer set
|
|
60
|
+
* for their own collector.
|
|
61
|
+
*
|
|
62
|
+
* @param state - Current install state.
|
|
63
|
+
* @param agentId - Agent that was just configured.
|
|
64
|
+
* @param record - What was written, and where.
|
|
65
|
+
* @returns The next install state.
|
|
66
|
+
*/
|
|
67
|
+
export declare function withOtelInstall(state: InstallState, agentId: string, record: OtelInstallRecord): InstallState;
|
|
68
|
+
/**
|
|
69
|
+
* Install state with one agent's native-telemetry record cleared.
|
|
70
|
+
*
|
|
71
|
+
* @param state - Current install state.
|
|
72
|
+
* @param agentId - Agent whose configuration was removed.
|
|
73
|
+
* @returns The next install state.
|
|
74
|
+
*/
|
|
75
|
+
export declare function withoutOtelInstall(state: InstallState, agentId: string): InstallState;
|