@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,106 @@
|
|
|
1
|
+
import { sha256Hex } from '../../events/event-id.js';
|
|
2
|
+
import { baseEvent, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
|
|
3
|
+
import { classifyTool, toolCompleteType, toolStartType } from '../shared/tooling.js';
|
|
4
|
+
import { CODEX_DISPLAY_NAME, CODEX_EVENT_TYPE_MAP, CODEX_PROVIDER_ID, CODEX_TOOL_EVENTS, CODEX_UNKNOWN_EVENT } from './constants/codex.constants.js';
|
|
5
|
+
import { codexPayloadSchema } from './schemas/codex.schema.js';
|
|
6
|
+
/**
|
|
7
|
+
* Translate one Codex hook payload into canonical events.
|
|
8
|
+
*
|
|
9
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
10
|
+
* @param context - Environment and effective config.
|
|
11
|
+
* @returns The canonical events, or an empty list for an unusable payload.
|
|
12
|
+
*/
|
|
13
|
+
export function parseCodexHookEvent(rawPayload, context) {
|
|
14
|
+
const parsed = codexPayloadSchema.safeParse(rawPayload);
|
|
15
|
+
if (!parsed.success)
|
|
16
|
+
return [];
|
|
17
|
+
const payload = parsed.data;
|
|
18
|
+
const providerEventType = payload.hook_event_name ?? CODEX_UNKNOWN_EVENT;
|
|
19
|
+
return [withPatch(codexBaseEvent(payload, providerEventType), hookPatch(payload, providerEventType, context))];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The provider-independent part of the event.
|
|
23
|
+
*
|
|
24
|
+
* @param payload - Parsed hook payload.
|
|
25
|
+
* @param providerEventType - Codex's own name for this hook.
|
|
26
|
+
* @returns The base event.
|
|
27
|
+
*/
|
|
28
|
+
function codexBaseEvent(payload, providerEventType) {
|
|
29
|
+
// Codex has called the same value both `session_id` and `thread_id` across
|
|
30
|
+
// releases; either is the session as far as correlation is concerned.
|
|
31
|
+
const sessionId = payload.session_id ?? payload.thread_id;
|
|
32
|
+
return baseEvent({
|
|
33
|
+
provider: CODEX_PROVIDER_ID,
|
|
34
|
+
displayName: CODEX_DISPLAY_NAME,
|
|
35
|
+
providerEventType,
|
|
36
|
+
eventType: canonicalType(payload, providerEventType),
|
|
37
|
+
sessionId,
|
|
38
|
+
turnId: payload.turn_id,
|
|
39
|
+
agentId: payload.agent_id,
|
|
40
|
+
toolUseId: payload.tool_use_id,
|
|
41
|
+
payloadFingerprint: sha256Hex(JSON.stringify(payload)),
|
|
42
|
+
ai: payload.model ? { model: payload.model, billingMode: 'unknown' } : undefined,
|
|
43
|
+
providerMetadata: {
|
|
44
|
+
permissionMode: payload.permission_mode,
|
|
45
|
+
agentType: payload.agent_type,
|
|
46
|
+
toolUseId: payload.tool_use_id
|
|
47
|
+
},
|
|
48
|
+
timestamp: new Date().toISOString()
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* What this particular hook contributes on top of the base event.
|
|
53
|
+
*
|
|
54
|
+
* @param payload - Parsed hook payload.
|
|
55
|
+
* @param providerEventType - Codex's own name for this hook.
|
|
56
|
+
* @param context - Environment and effective config.
|
|
57
|
+
* @returns The patch; empty for a hook we model but read nothing from.
|
|
58
|
+
*/
|
|
59
|
+
function hookPatch(payload, providerEventType, context) {
|
|
60
|
+
const capture = context.config.capture;
|
|
61
|
+
if (providerEventType === 'SessionStart')
|
|
62
|
+
return { metadata: { sessionSource: payload.source } };
|
|
63
|
+
if (providerEventType === 'SessionEnd')
|
|
64
|
+
return { metadata: { sessionEndReason: payload.reason } };
|
|
65
|
+
if (providerEventType === 'UserPromptSubmit')
|
|
66
|
+
return promptPatch(payload.prompt ?? '', capture);
|
|
67
|
+
if (CODEX_TOOL_EVENTS.has(providerEventType)) {
|
|
68
|
+
return toolPatch({
|
|
69
|
+
name: payload.tool_name,
|
|
70
|
+
status: providerEventType === 'PostToolUse' ? 'completed' : 'started',
|
|
71
|
+
kind: classifyTool(payload.tool_name),
|
|
72
|
+
toolUseId: payload.tool_use_id,
|
|
73
|
+
input: payload.tool_input,
|
|
74
|
+
output: payload.tool_response
|
|
75
|
+
}, capture);
|
|
76
|
+
}
|
|
77
|
+
if (providerEventType === 'Stop') {
|
|
78
|
+
const response = responsePatch(payload.last_assistant_message ?? '', capture);
|
|
79
|
+
return { ...response, metadata: { stopHookActive: payload.stop_hook_active, ...response.metadata } };
|
|
80
|
+
}
|
|
81
|
+
if (providerEventType === 'SubagentStart' || providerEventType === 'SubagentStop') {
|
|
82
|
+
return { metadata: { agentType: payload.agent_type } };
|
|
83
|
+
}
|
|
84
|
+
if (providerEventType === 'PreCompact' || providerEventType === 'PostCompact') {
|
|
85
|
+
return { metadata: { trigger: payload.trigger } };
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Canonical type for a hook, falling back to the tool classification.
|
|
91
|
+
*
|
|
92
|
+
* @param payload - Parsed hook payload.
|
|
93
|
+
* @param providerEventType - Codex's own name for this hook.
|
|
94
|
+
* @returns The canonical event type.
|
|
95
|
+
*/
|
|
96
|
+
function canonicalType(payload, providerEventType) {
|
|
97
|
+
const direct = CODEX_EVENT_TYPE_MAP[providerEventType];
|
|
98
|
+
if (direct)
|
|
99
|
+
return direct;
|
|
100
|
+
const kind = classifyTool(payload.tool_name);
|
|
101
|
+
if (providerEventType === 'PreToolUse')
|
|
102
|
+
return toolStartType(kind);
|
|
103
|
+
if (providerEventType === 'PostToolUse')
|
|
104
|
+
return toolCompleteType(kind);
|
|
105
|
+
return 'agent.other';
|
|
106
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
2
|
+
import type { DetectionResult } from '../types/provider.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Codex's configuration root.
|
|
5
|
+
*
|
|
6
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
7
|
+
* @returns `$CODEX_HOME`, or `~/.codex`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function codexHome(env: Env): string;
|
|
10
|
+
/**
|
|
11
|
+
* Where Codex reads hook registrations from.
|
|
12
|
+
*
|
|
13
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
14
|
+
* @returns Absolute path of `hooks.json`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function codexHooksJsonPath(env: Env): string;
|
|
17
|
+
/**
|
|
18
|
+
* Where Codex reads its feature flags from.
|
|
19
|
+
*
|
|
20
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
21
|
+
* @returns Absolute path of `config.toml`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function codexConfigTomlPath(env: Env): string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether Codex is installed here, and whether our hooks are registered.
|
|
26
|
+
*
|
|
27
|
+
* @param env - Environment supplying HOME, cwd and PATH.
|
|
28
|
+
* @returns What was found.
|
|
29
|
+
*/
|
|
30
|
+
export declare function detectCodex(env: Env): Promise<DetectionResult>;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { CODEX_CONFIG_FILE, CODEX_EXECUTABLE, CODEX_HOME_DIR, CODEX_HOME_VAR, CODEX_HOOKS_FILE } from './constants/codex.constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Codex's configuration root.
|
|
9
|
+
*
|
|
10
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
11
|
+
* @returns `$CODEX_HOME`, or `~/.codex`.
|
|
12
|
+
*/
|
|
13
|
+
export function codexHome(env) {
|
|
14
|
+
return env.vars[CODEX_HOME_VAR] ?? path.join(env.home, CODEX_HOME_DIR);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Where Codex reads hook registrations from.
|
|
18
|
+
*
|
|
19
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
20
|
+
* @returns Absolute path of `hooks.json`.
|
|
21
|
+
*/
|
|
22
|
+
export function codexHooksJsonPath(env) {
|
|
23
|
+
return path.join(codexHome(env), CODEX_HOOKS_FILE);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where Codex reads its feature flags from.
|
|
27
|
+
*
|
|
28
|
+
* @param env - Environment supplying HOME and CODEX_HOME.
|
|
29
|
+
* @returns Absolute path of `config.toml`.
|
|
30
|
+
*/
|
|
31
|
+
export function codexConfigTomlPath(env) {
|
|
32
|
+
return path.join(codexHome(env), CODEX_CONFIG_FILE);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether Codex is installed here, and whether our hooks are registered.
|
|
36
|
+
*
|
|
37
|
+
* @param env - Environment supplying HOME, cwd and PATH.
|
|
38
|
+
* @returns What was found.
|
|
39
|
+
*/
|
|
40
|
+
export async function detectCodex(env) {
|
|
41
|
+
const evidence = [];
|
|
42
|
+
if (fs.existsSync(codexHome(env)))
|
|
43
|
+
evidence.push('~/.codex directory exists');
|
|
44
|
+
if (fs.existsSync(path.join(env.cwd, CODEX_HOME_DIR)))
|
|
45
|
+
evidence.push('.codex directory in working tree');
|
|
46
|
+
const executablePath = findExecutable(env, CODEX_EXECUTABLE);
|
|
47
|
+
if (executablePath)
|
|
48
|
+
evidence.push(`codex executable on PATH (${executablePath})`);
|
|
49
|
+
const hookConfigPath = codexHooksJsonPath(env);
|
|
50
|
+
const hooksFile = await readJsonFile(hookConfigPath);
|
|
51
|
+
return {
|
|
52
|
+
detected: evidence.length > 0,
|
|
53
|
+
evidence,
|
|
54
|
+
executablePath,
|
|
55
|
+
hookConfigPath,
|
|
56
|
+
hooksInstalled: hooksFile.state === 'ok' && JSON.stringify(hooksFile.value).includes(HOOK_COMMAND_MARKER)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SetupContext, SetupOutcome } from '../types/provider.types.js';
|
|
2
|
+
export { CODEX_HOOK_EVENTS } from './constants/codex.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register AgentWatch's hooks in `~/.codex/hooks.json`.
|
|
5
|
+
*
|
|
6
|
+
* Codex parses that file with `deny_unknown_fields`, so an unknown top-level
|
|
7
|
+
* key makes it skip the whole file. We therefore write nothing but
|
|
8
|
+
* description/hooks — and refuse to proceed when foreign keys are already
|
|
9
|
+
* present, because the file is already broken for Codex and overwriting it
|
|
10
|
+
* would hide the user's problem instead of surfacing it.
|
|
11
|
+
*
|
|
12
|
+
* @param context - Environment, paths, config and the hook command to write.
|
|
13
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
14
|
+
* install state.
|
|
15
|
+
*/
|
|
16
|
+
export declare function installCodexHooks(context: SetupContext): Promise<SetupOutcome>;
|
|
17
|
+
/**
|
|
18
|
+
* Remove AgentWatch's hooks from `~/.codex/hooks.json`.
|
|
19
|
+
*
|
|
20
|
+
* Every top-level field Codex accepts is preserved; only the hook entries we
|
|
21
|
+
* own are gone.
|
|
22
|
+
*
|
|
23
|
+
* @param context - Environment, paths and current install state.
|
|
24
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
25
|
+
* install state.
|
|
26
|
+
*/
|
|
27
|
+
export declare function uninstallCodexHooks(context: SetupContext): Promise<SetupOutcome>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { parse as parseToml } from 'smol-toml';
|
|
3
|
+
import { asRecord } from '../../core/object.js';
|
|
4
|
+
import { backupFile } from '../../storage/atomic-file.js';
|
|
5
|
+
import { readJsonFile } from '../../storage/json-file.js';
|
|
6
|
+
import { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, writeJsonValidated } from '../shared/hook-config.js';
|
|
7
|
+
import { withHookInstall, withoutHookInstall } from '../shared/install-record.js';
|
|
8
|
+
import { codexConfigTomlPath, codexHooksJsonPath } from './codex.detect.js';
|
|
9
|
+
import { CODEX_ALLOWED_TOP_LEVEL_KEYS, CODEX_HOOKS_DISABLED_WARNING, CODEX_HOOK_EVENTS, CODEX_HOOK_TIMEOUT_SECONDS, CODEX_PROVIDER_ID, CODEX_TRUST_NOTE } from './constants/codex.constants.js';
|
|
10
|
+
export { CODEX_HOOK_EVENTS } from './constants/codex.constants.js';
|
|
11
|
+
/**
|
|
12
|
+
* Register AgentWatch's hooks in `~/.codex/hooks.json`.
|
|
13
|
+
*
|
|
14
|
+
* Codex parses that file with `deny_unknown_fields`, so an unknown top-level
|
|
15
|
+
* key makes it skip the whole file. We therefore write nothing but
|
|
16
|
+
* description/hooks — and refuse to proceed when foreign keys are already
|
|
17
|
+
* present, because the file is already broken for Codex and overwriting it
|
|
18
|
+
* would hide the user's problem instead of surfacing it.
|
|
19
|
+
*
|
|
20
|
+
* @param context - Environment, paths, config and the hook command to write.
|
|
21
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
22
|
+
* install state.
|
|
23
|
+
*/
|
|
24
|
+
export async function installCodexHooks(context) {
|
|
25
|
+
const hooksPath = codexHooksJsonPath(context.env);
|
|
26
|
+
const read = await readJsonFile(hooksPath);
|
|
27
|
+
if (read.state === 'invalid') {
|
|
28
|
+
return { ok: false, changed: false, messages: [`refusing to modify unparseable ${hooksPath} (${read.error})`] };
|
|
29
|
+
}
|
|
30
|
+
if (read.state === 'ok' && !asRecord(read.value)) {
|
|
31
|
+
return { ok: false, changed: false, messages: [`refusing to modify ${hooksPath}: top level is not an object`] };
|
|
32
|
+
}
|
|
33
|
+
const file = (read.state === 'ok' ? asRecord(read.value) : undefined) ?? {};
|
|
34
|
+
const foreignKeys = Object.keys(file).filter((key) => !CODEX_ALLOWED_TOP_LEVEL_KEYS.has(key));
|
|
35
|
+
if (foreignKeys.length > 0) {
|
|
36
|
+
return { ok: false, changed: false, messages: [`${hooksPath} has keys Codex rejects (${foreignKeys.join(', ')}); fix it first`] };
|
|
37
|
+
}
|
|
38
|
+
const hooks = asRecord(file['hooks']) ?? {};
|
|
39
|
+
const registered = registerOurHandlers(hooks, CODEX_HOOK_EVENTS, () => ourEntry(context.hookCommand));
|
|
40
|
+
const nextFile = { ...file, hooks: sweepUnregisteredEvents(registered, CODEX_HOOK_EVENTS) };
|
|
41
|
+
const changed = JSON.stringify(nextFile) !== JSON.stringify(file);
|
|
42
|
+
if (changed) {
|
|
43
|
+
await backupFile(hooksPath, context.paths.backupsDir, context.env.now());
|
|
44
|
+
await writeJsonValidated(hooksPath, nextFile);
|
|
45
|
+
}
|
|
46
|
+
const messages = [changed ? `hooks registered in ${hooksPath}` : 'hooks already registered'];
|
|
47
|
+
if (changed)
|
|
48
|
+
messages.push(CODEX_TRUST_NOTE);
|
|
49
|
+
const featureWarning = await hooksFeatureDisabledWarning(context);
|
|
50
|
+
if (featureWarning)
|
|
51
|
+
messages.push(featureWarning);
|
|
52
|
+
return {
|
|
53
|
+
ok: true,
|
|
54
|
+
changed,
|
|
55
|
+
messages,
|
|
56
|
+
installState: withHookInstall(context.installState, CODEX_PROVIDER_ID, {
|
|
57
|
+
hookConfigPath: hooksPath,
|
|
58
|
+
hookEvents: CODEX_HOOK_EVENTS,
|
|
59
|
+
hookCommand: context.hookCommand,
|
|
60
|
+
installedAt: context.env.now(),
|
|
61
|
+
// The trust step is the one thing setup cannot do for the user, so it is
|
|
62
|
+
// remembered rather than just printed once.
|
|
63
|
+
notes: changed ? [CODEX_TRUST_NOTE] : undefined
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Remove AgentWatch's hooks from `~/.codex/hooks.json`.
|
|
69
|
+
*
|
|
70
|
+
* Every top-level field Codex accepts is preserved; only the hook entries we
|
|
71
|
+
* own are gone.
|
|
72
|
+
*
|
|
73
|
+
* @param context - Environment, paths and current install state.
|
|
74
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
75
|
+
* install state.
|
|
76
|
+
*/
|
|
77
|
+
export async function uninstallCodexHooks(context) {
|
|
78
|
+
const hooksPath = codexHooksJsonPath(context.env);
|
|
79
|
+
const read = await readJsonFile(hooksPath);
|
|
80
|
+
if (read.state === 'missing')
|
|
81
|
+
return { ok: true, changed: false, messages: ['no Codex hooks file'] };
|
|
82
|
+
const file = read.state === 'ok' ? asRecord(read.value) : undefined;
|
|
83
|
+
if (!file)
|
|
84
|
+
return { ok: false, changed: false, messages: [`cannot parse ${hooksPath}; not modified`] };
|
|
85
|
+
const hooks = asRecord(file['hooks']);
|
|
86
|
+
if (!hooks)
|
|
87
|
+
return { ok: true, changed: false, messages: ['no hooks configured'] };
|
|
88
|
+
const stripped = stripOurHandlers(hooks);
|
|
89
|
+
if (stripped.changed) {
|
|
90
|
+
await backupFile(hooksPath, context.paths.backupsDir, context.env.now());
|
|
91
|
+
await writeJsonValidated(hooksPath, { ...file, hooks: stripped.hooks });
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
changed: stripped.changed,
|
|
96
|
+
messages: stripped.changed ? ['AgentWatch hooks removed'] : ['no AgentWatch hooks found'],
|
|
97
|
+
installState: withoutHookInstall(context.installState, CODEX_PROVIDER_ID)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Our entry: a matcher-less group, which Codex reads as "match everything".
|
|
102
|
+
*
|
|
103
|
+
* @param hookCommand - Command line agents will invoke.
|
|
104
|
+
* @returns The entry.
|
|
105
|
+
*/
|
|
106
|
+
function ourEntry(hookCommand) {
|
|
107
|
+
return { hooks: [{ type: 'command', command: hookCommand, timeout: CODEX_HOOK_TIMEOUT_SECONDS }] };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Warn when the user has turned the whole hooks feature off.
|
|
111
|
+
*
|
|
112
|
+
* Hooks are on by default, so this is a rare but completely silent failure:
|
|
113
|
+
* registration succeeds and nothing ever fires.
|
|
114
|
+
*
|
|
115
|
+
* @param context - Environment supplying the config path.
|
|
116
|
+
* @returns The warning, or undefined when the feature is on.
|
|
117
|
+
*/
|
|
118
|
+
async function hooksFeatureDisabledWarning(context) {
|
|
119
|
+
try {
|
|
120
|
+
const parsed = asRecord(parseToml(await fs.readFile(codexConfigTomlPath(context.env), 'utf8')));
|
|
121
|
+
const features = asRecord(parsed?.['features']);
|
|
122
|
+
if (features?.['hooks'] === false)
|
|
123
|
+
return CODEX_HOOKS_DISABLED_WARNING;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Missing or unparseable config.toml: nothing to warn about here.
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
2
|
+
import type { NativeTelemetryConfigurator, NativeTelemetryStatus, SetupContext, SetupOutcome } from '../types/provider.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configures Codex's own OTLP export.
|
|
5
|
+
*
|
|
6
|
+
* Logs give one `response.completed` / `codex.api_request` usage record per
|
|
7
|
+
* provider request; traces carry thread.id, turn.id and multi-agent linkage.
|
|
8
|
+
* The backend normalizes both into llm.call.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CodexOtelConfigurator implements NativeTelemetryConfigurator {
|
|
11
|
+
/**
|
|
12
|
+
* Whether this agent can export native telemetry at all.
|
|
13
|
+
*
|
|
14
|
+
* @param _env - Unused; Codex always supports it.
|
|
15
|
+
* @returns Always true.
|
|
16
|
+
*/
|
|
17
|
+
supported(_env: Env): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Report whether the machine's telemetry configuration matches what we want.
|
|
20
|
+
*
|
|
21
|
+
* @param context - Environment, paths and config.
|
|
22
|
+
* @returns The status, naming any foreign configuration in the way.
|
|
23
|
+
*/
|
|
24
|
+
inspect(context: SetupContext): Promise<NativeTelemetryStatus>;
|
|
25
|
+
/**
|
|
26
|
+
* Write the managed `[otel]` block into Codex's config.toml.
|
|
27
|
+
*
|
|
28
|
+
* @param context - Environment, paths, config and install state.
|
|
29
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
30
|
+
* install state.
|
|
31
|
+
*/
|
|
32
|
+
configure(context: SetupContext): Promise<SetupOutcome>;
|
|
33
|
+
/**
|
|
34
|
+
* Remove the managed block from Codex's config.toml.
|
|
35
|
+
*
|
|
36
|
+
* Only the marker-delimited region goes; everything the developer wrote
|
|
37
|
+
* around it — comments included — is preserved byte for byte.
|
|
38
|
+
*
|
|
39
|
+
* @param context - Environment, paths and install state.
|
|
40
|
+
* @returns Whether the file changed, what to tell the user, and the next
|
|
41
|
+
* install state.
|
|
42
|
+
*/
|
|
43
|
+
uninstall(context: SetupContext): Promise<SetupOutcome>;
|
|
44
|
+
/**
|
|
45
|
+
* Handle `configure` when Codex telemetry is deliberately off.
|
|
46
|
+
*
|
|
47
|
+
* @param context - Environment, paths and install state.
|
|
48
|
+
* @returns The outcome.
|
|
49
|
+
*/
|
|
50
|
+
private configureDisabled;
|
|
51
|
+
}
|