@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,297 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { asRecord } from '../core/object.js';
|
|
3
|
+
import { debugLog } from '../core/logger.js';
|
|
4
|
+
import { next, runFlow, step, stop } from '../core/pipe.js';
|
|
5
|
+
import { loadEffectiveConfig } from '../config/repo-config.js';
|
|
6
|
+
import { DECISION_BLOCK } from '../enforcement/constants/enforcement.constants.js';
|
|
7
|
+
import { resolveEnforcement } from '../enforcement/enforcement.js';
|
|
8
|
+
import { enrichEvents } from '../events/enrich.js';
|
|
9
|
+
import { developerIdentity, runGit } from '../git/git-context.js';
|
|
10
|
+
import { runSnapshotPipeline } from '../snapshot/snapshot-pipeline.js';
|
|
11
|
+
import { SnapshotStateStore } from '../snapshot/snapshot-state.js';
|
|
12
|
+
import { SNAPSHOT_BUDGET_MS } from '../snapshot/constants/snapshot.constants.js';
|
|
13
|
+
import { BackendCooldown } from '../transport/cooldown.js';
|
|
14
|
+
import { DeliveryStats } from '../transport/delivery-stats.js';
|
|
15
|
+
import { deliverEvents } from '../transport/delivery.js';
|
|
16
|
+
import { HttpTransport } from '../transport/http-transport.js';
|
|
17
|
+
import { EventQueue } from '../transport/queue.js';
|
|
18
|
+
import { COOLDOWN_FILE_NAME, DELIVERY_STATS_FILE_NAME } from '../transport/constants/transport.constants.js';
|
|
19
|
+
import { eventsUrl } from '../config/config.js';
|
|
20
|
+
import { trackTurn } from '../turns/turn-tracker.js';
|
|
21
|
+
import { PAYLOAD_CWD_KEY, PROMPT_SUBMITTED_TYPE, STAGE_DELIVER, STAGE_ENFORCE, STAGE_ENRICH, STAGE_PARSE_EVENTS, STAGE_RESOLVE_CONTEXT, STAGE_SNAPSHOT, STAGE_TRACK_TURN, STOP_DRY_RUN, STOP_NO_EVENTS, STOP_NO_SNAPSHOT } from './constants/pipeline.constants.js';
|
|
22
|
+
/**
|
|
23
|
+
* The hook flow, as the list of stages it is.
|
|
24
|
+
*
|
|
25
|
+
* Read top to bottom, this is the whole contract of the hook path: work out
|
|
26
|
+
* where we are and what the effective config says, turn the payload into
|
|
27
|
+
* canonical events, ask whether this turn may start at all, attach development
|
|
28
|
+
* context, assemble the turn, deliver, and — when a turn has just closed — tell
|
|
29
|
+
* the platform what this repository's recent branches look like.
|
|
30
|
+
* Every stage takes the whole state and returns the next one, so adding or
|
|
31
|
+
* reordering a step is a change to this array rather than to a call graph.
|
|
32
|
+
*/
|
|
33
|
+
const HOOK_STAGES = [
|
|
34
|
+
step(STAGE_RESOLVE_CONTEXT, resolveContext),
|
|
35
|
+
step(STAGE_PARSE_EVENTS, parseEvents),
|
|
36
|
+
step(STAGE_ENFORCE, enforce),
|
|
37
|
+
step(STAGE_ENRICH, enrich),
|
|
38
|
+
step(STAGE_TRACK_TURN, trackTurnStage),
|
|
39
|
+
step(STAGE_DELIVER, deliver),
|
|
40
|
+
step(STAGE_SNAPSHOT, snapshot)
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Run one hook payload through the flow.
|
|
44
|
+
*
|
|
45
|
+
* Never throws: a stage that fails ends the flow with whatever the last
|
|
46
|
+
* successful stage produced, because the caller is a hook that must answer the
|
|
47
|
+
* coding agent either way.
|
|
48
|
+
*
|
|
49
|
+
* @param input - Provider, environment, payload and dry-run flag.
|
|
50
|
+
* @returns The final state and where the flow stopped.
|
|
51
|
+
*/
|
|
52
|
+
export function runHookPipeline(input) {
|
|
53
|
+
const initial = {
|
|
54
|
+
...input,
|
|
55
|
+
cwd: resolvePayloadCwd(input),
|
|
56
|
+
config: input.globalConfig,
|
|
57
|
+
events: [],
|
|
58
|
+
outbound: []
|
|
59
|
+
};
|
|
60
|
+
return runFlow(HOOK_STAGES, initial, (trace) => {
|
|
61
|
+
if (trace.outcome === 'next')
|
|
62
|
+
return;
|
|
63
|
+
debugLog(`hook flow ${trace.outcome} at ${trace.step}${trace.reason ? `: ${trace.reason}` : ''}`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Apply the repository's `.agentwatch.json` on top of the global config.
|
|
68
|
+
*
|
|
69
|
+
* Repository overrides govern content capture derived from *this* payload;
|
|
70
|
+
* identity, endpoints, emission toggles and delivery tuning stay global-only.
|
|
71
|
+
*
|
|
72
|
+
* @param state - Current flow state.
|
|
73
|
+
* @returns The state with its effective config resolved.
|
|
74
|
+
*/
|
|
75
|
+
async function resolveContext(state) {
|
|
76
|
+
const effective = await loadEffectiveConfig(state.paths, state.cwd);
|
|
77
|
+
return next({ ...state, config: effective.config });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Turn the payload into canonical events.
|
|
81
|
+
*
|
|
82
|
+
* @param state - Current flow state.
|
|
83
|
+
* @returns The state with its events, or a stop when the payload carried none.
|
|
84
|
+
*/
|
|
85
|
+
async function parseEvents(state) {
|
|
86
|
+
const events = await state.provider.parseHookEvent(state.payload, { env: state.env, config: state.config });
|
|
87
|
+
if (events.length === 0)
|
|
88
|
+
return stop(state, STOP_NO_EVENTS);
|
|
89
|
+
return next({ ...state, events });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ask the platform whether this turn may start.
|
|
93
|
+
*
|
|
94
|
+
* Only the prompt hook is a gate, and only a provider that knows how to refuse
|
|
95
|
+
* one is asked about: everything else skips the check entirely, so no tool hook
|
|
96
|
+
* pays for it. A refusal lands in the state as a sentence to show; every failure
|
|
97
|
+
* of the check leaves the state untouched, which is what makes an unreachable
|
|
98
|
+
* platform a no-op rather than an outage.
|
|
99
|
+
*
|
|
100
|
+
* A dry run never asks. It previews what would be sent, and rehearsing a refusal
|
|
101
|
+
* would block a developer for a command that promised to change nothing.
|
|
102
|
+
*
|
|
103
|
+
* @param state - Current flow state.
|
|
104
|
+
* @returns The state, carrying the refusal when there is one.
|
|
105
|
+
*/
|
|
106
|
+
async function enforce(state) {
|
|
107
|
+
if (state.dryRun || !state.provider.getBlockResponse || !isTurnGate(state))
|
|
108
|
+
return next(state);
|
|
109
|
+
const decision = await resolveEnforcement({
|
|
110
|
+
config: state.config,
|
|
111
|
+
paths: state.paths,
|
|
112
|
+
developerId: await developerIdentity(state.config.developerEmail, state.cwd, { home: state.env.home }),
|
|
113
|
+
now: state.env.now
|
|
114
|
+
});
|
|
115
|
+
if (decision.decision !== DECISION_BLOCK)
|
|
116
|
+
return next(state);
|
|
117
|
+
return next({ ...state, blockMessage: decision.message });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Whether this payload is the moment before the turn's first LLM call.
|
|
121
|
+
*
|
|
122
|
+
* @param state - Current flow state.
|
|
123
|
+
* @returns True when the provider reported a submitted prompt.
|
|
124
|
+
*/
|
|
125
|
+
function isTurnGate(state) {
|
|
126
|
+
for (const event of state.events) {
|
|
127
|
+
if (event.event.type === PROMPT_SUBMITTED_TYPE)
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Attach development context and scrub the events.
|
|
134
|
+
*
|
|
135
|
+
* @param state - Current flow state.
|
|
136
|
+
* @returns The state with enriched events.
|
|
137
|
+
*/
|
|
138
|
+
async function enrich(state) {
|
|
139
|
+
const events = await enrichEvents(state.events, { config: state.config, cwd: state.cwd, home: state.env.home });
|
|
140
|
+
return next({ ...state, events });
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Assemble the turn and decide what leaves this machine.
|
|
144
|
+
*
|
|
145
|
+
* Turn tracking always runs, even when summaries are not emitted: besides
|
|
146
|
+
* producing the summary it resolves token usage for the turn. Only
|
|
147
|
+
* `turn.summary` leaves the hook path — lifecycle events are internal assembly
|
|
148
|
+
* state, and `llm.call` records arrive through the native OTLP path.
|
|
149
|
+
*
|
|
150
|
+
* @param state - Current flow state.
|
|
151
|
+
* @returns The state with its summary and outbound records.
|
|
152
|
+
*/
|
|
153
|
+
async function trackTurnStage(state) {
|
|
154
|
+
// A refused prompt never reached a model. Recording it would leave a prompt
|
|
155
|
+
// with no turn behind it, to be folded into whichever turn came next and
|
|
156
|
+
// inflate its prompt; the flow continues so the offline queue still drains.
|
|
157
|
+
if (state.blockMessage)
|
|
158
|
+
return next(state);
|
|
159
|
+
// Assembly failing must not cost the *queue* its drain: a hook that produced
|
|
160
|
+
// no summary still has a backlog to move, so this stage degrades to "no
|
|
161
|
+
// summary" instead of ending the flow.
|
|
162
|
+
const summary = await trackTurnSafely(state);
|
|
163
|
+
const outbound = summary && state.config.emit.turnSummaries ? [summary] : [];
|
|
164
|
+
return next({ ...state, summary, outbound });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Assemble the turn, degrading to no summary on any failure.
|
|
168
|
+
*
|
|
169
|
+
* @param state - Current flow state.
|
|
170
|
+
* @returns The summary, or undefined.
|
|
171
|
+
*/
|
|
172
|
+
async function trackTurnSafely(state) {
|
|
173
|
+
try {
|
|
174
|
+
return await trackTurn({
|
|
175
|
+
agentId: state.provider.id,
|
|
176
|
+
rawPayload: state.payload,
|
|
177
|
+
events: state.events,
|
|
178
|
+
config: state.config,
|
|
179
|
+
turnsDir: state.paths.turnsDir,
|
|
180
|
+
locksDir: state.paths.locksDir,
|
|
181
|
+
env: state.env,
|
|
182
|
+
cwd: state.cwd,
|
|
183
|
+
readOnly: state.dryRun
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
debugLog('turn summary failed:', error);
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Send what this run produced, or queue it.
|
|
193
|
+
*
|
|
194
|
+
* @param state - Current flow state.
|
|
195
|
+
* @returns The state with the delivery outcome, or a stop on a dry run.
|
|
196
|
+
*/
|
|
197
|
+
async function deliver(state) {
|
|
198
|
+
if (state.dryRun)
|
|
199
|
+
return stop(state, STOP_DRY_RUN);
|
|
200
|
+
const queue = buildQueue(state);
|
|
201
|
+
const delivery = await deliverEvents(state.outbound, buildTransport(state), queue, state.config.delivery.drainBatchSize, new BackendCooldown(path.join(state.paths.dataDir, COOLDOWN_FILE_NAME), state.env.now), new DeliveryStats(path.join(state.paths.dataDir, DELIVERY_STATS_FILE_NAME), state.env.now, state.paths.locksDir));
|
|
202
|
+
debugLog(`delivery: sent=${delivery.delivered} queued=${delivery.queued} drained=${delivery.drained} rejected=${delivery.rejected}`);
|
|
203
|
+
return next({ ...state, delivery });
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Describe the repository's recent branches, after the turn has been delivered.
|
|
207
|
+
*
|
|
208
|
+
* Last, and awaited. Last because it must never delay the spend records, which
|
|
209
|
+
* are the reason the hook exists; awaited because the process exits the moment
|
|
210
|
+
* this returns, and a dangling promise would be killed somewhere between
|
|
211
|
+
* building the event and writing it to the queue.
|
|
212
|
+
*
|
|
213
|
+
* It runs only on a closed turn — the one hook per turn that already pays for
|
|
214
|
+
* full git context — and only when git capture is on: branch names and commit
|
|
215
|
+
* subjects are git metadata, and a developer who turned that off has said no to
|
|
216
|
+
* exactly this.
|
|
217
|
+
*
|
|
218
|
+
* @param state - Current flow state.
|
|
219
|
+
* @returns The state, unchanged. A snapshot never affects the hook's answer.
|
|
220
|
+
*/
|
|
221
|
+
async function snapshot(state) {
|
|
222
|
+
const repository = state.summary?.repository;
|
|
223
|
+
if (!repository || !state.config.capture.git)
|
|
224
|
+
return stop(state, STOP_NO_SNAPSHOT);
|
|
225
|
+
await runSnapshotPipeline({
|
|
226
|
+
input: {
|
|
227
|
+
cwd: state.cwd,
|
|
228
|
+
repository,
|
|
229
|
+
provider: state.summary?.provider ?? state.provider.id,
|
|
230
|
+
surface: state.summary?.surface ?? state.provider.id,
|
|
231
|
+
agentName: state.summary?.agent.name ?? state.provider.id,
|
|
232
|
+
developerId: state.summary?.developer_id,
|
|
233
|
+
installationId: state.config.installationId,
|
|
234
|
+
sessionId: state.summary?.session_id,
|
|
235
|
+
capturedAt: state.env.now().toISOString(),
|
|
236
|
+
// Real time, deliberately, where the line above uses the injected clock:
|
|
237
|
+
// this bounds subprocess timeouts, which are measured against the wall.
|
|
238
|
+
deadline: Date.now() + SNAPSHOT_BUDGET_MS,
|
|
239
|
+
run: runGit
|
|
240
|
+
},
|
|
241
|
+
store: new SnapshotStateStore(state.paths.snapshotsDir),
|
|
242
|
+
queue: buildQueue(state)
|
|
243
|
+
});
|
|
244
|
+
return next(state);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The offline queue for this run.
|
|
248
|
+
*
|
|
249
|
+
* @param state - Current flow state.
|
|
250
|
+
* @returns A queue bound to this run's paths and delivery limits.
|
|
251
|
+
*/
|
|
252
|
+
function buildQueue(state) {
|
|
253
|
+
return new EventQueue({
|
|
254
|
+
queueDir: state.paths.queueDir,
|
|
255
|
+
locksDir: state.paths.locksDir,
|
|
256
|
+
maxEvents: state.config.delivery.maxQueueEvents,
|
|
257
|
+
maxAttempts: state.config.delivery.maxAttempts,
|
|
258
|
+
maxEventAgeDays: state.config.delivery.maxEventAgeDays,
|
|
259
|
+
now: state.env.now
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The transport for this run, when a backend is configured.
|
|
264
|
+
*
|
|
265
|
+
* @param state - Current flow state.
|
|
266
|
+
* @returns The transport, or undefined before setup has run.
|
|
267
|
+
*/
|
|
268
|
+
function buildTransport(state) {
|
|
269
|
+
const url = eventsUrl(state.config);
|
|
270
|
+
if (!url)
|
|
271
|
+
return undefined;
|
|
272
|
+
return new HttpTransport({
|
|
273
|
+
eventsUrl: url,
|
|
274
|
+
token: state.config.token,
|
|
275
|
+
installationId: state.config.installationId,
|
|
276
|
+
timeoutMs: state.config.delivery.timeoutMs
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Where this payload happened.
|
|
281
|
+
*
|
|
282
|
+
* Most agents report a top-level `cwd`; a provider that nests it (Antigravity
|
|
283
|
+
* carries `common.workspacePaths`) supplies `resolveCwd`. Without this the git
|
|
284
|
+
* context, the repository `.agentwatch.json` and every branch-derived ticket key
|
|
285
|
+
* would be resolved against whatever directory the hook process happened to
|
|
286
|
+
* start in.
|
|
287
|
+
*
|
|
288
|
+
* @param input - The flow's input.
|
|
289
|
+
* @returns The working directory to use.
|
|
290
|
+
*/
|
|
291
|
+
function resolvePayloadCwd(input) {
|
|
292
|
+
const reported = asRecord(input.payload)?.[PAYLOAD_CWD_KEY];
|
|
293
|
+
if (typeof reported === 'string' && reported !== '')
|
|
294
|
+
return reported;
|
|
295
|
+
const resolved = input.provider.resolveCwd?.(input.payload);
|
|
296
|
+
return typeof resolved === 'string' && resolved !== '' ? resolved : input.env.cwd;
|
|
297
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package's flows, expressed as ordered lists of named stages rather than
|
|
3
|
+
* as call graphs. The hook path is the one that runs inside the coding agent.
|
|
4
|
+
*/
|
|
5
|
+
export type { HookPipelineInput, HookPipelineState } from './types/pipeline.types.js';
|
|
6
|
+
export { runHookPipeline } from './hook-pipeline.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runHookPipeline } from './hook-pipeline.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AgentWatchConfig } from '../../config/types/config.types.js';
|
|
2
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
3
|
+
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
4
|
+
import type { AgentProvider } from '../../providers/types/provider.types.js';
|
|
5
|
+
import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
|
|
6
|
+
import type { TurnSummaryEvent } from '../../turns/types/turn-summary.types.js';
|
|
7
|
+
import type { DeliveryOutcome } from '../../transport/types/transport.types.js';
|
|
8
|
+
/** Everything the hook flow needs to start. */
|
|
9
|
+
export interface HookPipelineInput {
|
|
10
|
+
readonly provider: AgentProvider;
|
|
11
|
+
readonly env: Env;
|
|
12
|
+
readonly paths: AgentWatchPaths;
|
|
13
|
+
/** The machine-global configuration, before the repository overlay. */
|
|
14
|
+
readonly globalConfig: AgentWatchConfig;
|
|
15
|
+
/** Decoded hook payload. */
|
|
16
|
+
readonly payload: unknown;
|
|
17
|
+
/** Preview only: append nothing, consume nothing, send nothing. */
|
|
18
|
+
readonly dryRun: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The state every stage of the hook flow reads and extends.
|
|
22
|
+
*
|
|
23
|
+
* One immutable value threaded through the stages, so each stage is a pure
|
|
24
|
+
* function of what came before it and the flow reads top to bottom.
|
|
25
|
+
*/
|
|
26
|
+
export interface HookPipelineState extends HookPipelineInput {
|
|
27
|
+
/** Where the payload happened; resolved in the first stage. */
|
|
28
|
+
readonly cwd: string;
|
|
29
|
+
/** Global config with the repository overlay applied. */
|
|
30
|
+
readonly config: AgentWatchConfig;
|
|
31
|
+
/** Canonical events the provider adapter produced. */
|
|
32
|
+
readonly events: readonly AgentWatchEvent[];
|
|
33
|
+
/**
|
|
34
|
+
* The sentence the platform refused this turn with, when it refused it.
|
|
35
|
+
*
|
|
36
|
+
* Set only by the `enforce` stage and only for an explicit `block`; every
|
|
37
|
+
* failure of that check leaves it absent, which is what makes the turn
|
|
38
|
+
* proceed. Always non-empty when present — the decision schema will not parse
|
|
39
|
+
* a refusal without a message — so its presence *is* the refusal.
|
|
40
|
+
*/
|
|
41
|
+
readonly blockMessage?: string;
|
|
42
|
+
/** The turn summary, when this payload closed a turn. */
|
|
43
|
+
readonly summary?: TurnSummaryEvent;
|
|
44
|
+
/** Records this run intends to send; empty on a dry run. */
|
|
45
|
+
readonly outbound: readonly TurnSummaryEvent[];
|
|
46
|
+
/** What delivery did, when it ran. */
|
|
47
|
+
readonly delivery?: DeliveryOutcome;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SecretPattern } from '../types/privacy.types.js';
|
|
2
|
+
/** Text substituted for anything recognized as a credential. */
|
|
3
|
+
export declare const REDACTED = "[REDACTED]";
|
|
4
|
+
/** Marker for a value nested deeper than the sanitizer will walk. */
|
|
5
|
+
export declare const TRUNCATED = "[TRUNCATED]";
|
|
6
|
+
/**
|
|
7
|
+
* Nesting depth the sanitizer walks before giving up. Untrusted payloads can
|
|
8
|
+
* be arbitrarily deep (or cyclic through structured clones), and the walk runs
|
|
9
|
+
* on the agent's critical path.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_DEPTH = 12;
|
|
12
|
+
/** Longest string transmitted; the tail of anything longer is dropped. */
|
|
13
|
+
export declare const MAX_STRING_LENGTH = 8192;
|
|
14
|
+
/** Key names whose values are always redacted regardless of content. */
|
|
15
|
+
export declare const SENSITIVE_KEY_PATTERN: RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Content patterns for common credentials, applied to every outgoing string.
|
|
18
|
+
*
|
|
19
|
+
* Pre-compiled once at module load: the sanitizer runs over every captured
|
|
20
|
+
* prompt, response and tool payload, so building these inside the function
|
|
21
|
+
* would recompile the whole set per string (STYLEGUIDE 3.1).
|
|
22
|
+
*/
|
|
23
|
+
export declare const SECRET_PATTERNS: readonly SecretPattern[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Text substituted for anything recognized as a credential. */
|
|
2
|
+
export const REDACTED = '[REDACTED]';
|
|
3
|
+
/** Marker for a value nested deeper than the sanitizer will walk. */
|
|
4
|
+
export const TRUNCATED = '[TRUNCATED]';
|
|
5
|
+
/**
|
|
6
|
+
* Nesting depth the sanitizer walks before giving up. Untrusted payloads can
|
|
7
|
+
* be arbitrarily deep (or cyclic through structured clones), and the walk runs
|
|
8
|
+
* on the agent's critical path.
|
|
9
|
+
*/
|
|
10
|
+
export const MAX_DEPTH = 12;
|
|
11
|
+
/** Longest string transmitted; the tail of anything longer is dropped. */
|
|
12
|
+
export const MAX_STRING_LENGTH = 8192;
|
|
13
|
+
/** Key names whose values are always redacted regardless of content. */
|
|
14
|
+
export const SENSITIVE_KEY_PATTERN = /(^|[_.-])(authorization|auth|token|secret|password|passwd|pwd|credential|credentials|api[_-]?key|apikey|access[_-]?key|private[_-]?key|session[_-]?key|cookie|bearer)([_.-]|$)/i;
|
|
15
|
+
/**
|
|
16
|
+
* Content patterns for common credentials, applied to every outgoing string.
|
|
17
|
+
*
|
|
18
|
+
* Pre-compiled once at module load: the sanitizer runs over every captured
|
|
19
|
+
* prompt, response and tool payload, so building these inside the function
|
|
20
|
+
* would recompile the whole set per string (STYLEGUIDE 3.1).
|
|
21
|
+
*/
|
|
22
|
+
export const SECRET_PATTERNS = [
|
|
23
|
+
{ name: 'private-key-block', pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g },
|
|
24
|
+
{ name: 'url-credentials', pattern: /(\w+:\/\/)([^/\s:@]+)(?::([^/\s@]+))?@/g, replacement: `$1${REDACTED}@` },
|
|
25
|
+
{ name: 'aws-access-key', pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g },
|
|
26
|
+
{ name: 'github-token', pattern: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g },
|
|
27
|
+
{ name: 'github-fine-grained', pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g },
|
|
28
|
+
{ name: 'slack-token', pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g },
|
|
29
|
+
{ name: 'openai-anthropic-key', pattern: /\bsk-[A-Za-z0-9_-]{16,}\b/g },
|
|
30
|
+
{ name: 'google-api-key', pattern: /\bAIza[0-9A-Za-z_-]{30,}\b/g },
|
|
31
|
+
{ name: 'jwt', pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}\b/g },
|
|
32
|
+
{ name: 'auth-scheme', pattern: /\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, replacement: `$1 ${REDACTED}` },
|
|
33
|
+
{
|
|
34
|
+
name: 'assignment',
|
|
35
|
+
pattern: /\b(password|passwd|pwd|secret|token|api[_-]?key|apikey|access[_-]?key|client[_-]?secret)(\s*[=:]\s*)(["']?)[^\s"'&;]{6,}\3/gi,
|
|
36
|
+
replacement: `$1$2$3${REDACTED}$3`
|
|
37
|
+
}
|
|
38
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last gate before anything leaves the machine: known credential shapes
|
|
3
|
+
* are removed from every outgoing value, whatever the capture settings.
|
|
4
|
+
*/
|
|
5
|
+
export type { SecretPattern } from './types/privacy.types.js';
|
|
6
|
+
export { REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN } from './constants/privacy.constants.js';
|
|
7
|
+
export { sanitizeText, sanitizeValue } from './sanitizer.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redact known credential shapes inside a string, and cap its length.
|
|
3
|
+
*
|
|
4
|
+
* @param text - Text about to leave the machine.
|
|
5
|
+
* @returns The scrubbed text.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sanitizeText(text: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Recursively sanitize any value before it leaves the machine.
|
|
10
|
+
*
|
|
11
|
+
* Two independent defences, because either alone leaks: a value under a
|
|
12
|
+
* sensitive *key* is dropped whole whatever it looks like, and every string is
|
|
13
|
+
* pattern-scrubbed whatever key it sits under. Both run regardless of the
|
|
14
|
+
* user's capture settings — those decide what we collect, not whether secrets
|
|
15
|
+
* are removed from it.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Value to sanitize; left untouched.
|
|
18
|
+
* @returns A sanitized copy of the same shape.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sanitizeValue<T>(value: T): T;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isRecord } from '../core/object.js';
|
|
2
|
+
import { MAX_DEPTH, MAX_STRING_LENGTH, REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN, TRUNCATED } from './constants/privacy.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Redact known credential shapes inside a string, and cap its length.
|
|
5
|
+
*
|
|
6
|
+
* @param text - Text about to leave the machine.
|
|
7
|
+
* @returns The scrubbed text.
|
|
8
|
+
*/
|
|
9
|
+
export function sanitizeText(text) {
|
|
10
|
+
let out = text.length > MAX_STRING_LENGTH ? text.slice(0, MAX_STRING_LENGTH) : text;
|
|
11
|
+
for (const { pattern, replacement } of SECRET_PATTERNS) {
|
|
12
|
+
out = out.replace(pattern, replacement ?? REDACTED);
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Recursively sanitize any value before it leaves the machine.
|
|
18
|
+
*
|
|
19
|
+
* Two independent defences, because either alone leaks: a value under a
|
|
20
|
+
* sensitive *key* is dropped whole whatever it looks like, and every string is
|
|
21
|
+
* pattern-scrubbed whatever key it sits under. Both run regardless of the
|
|
22
|
+
* user's capture settings — those decide what we collect, not whether secrets
|
|
23
|
+
* are removed from it.
|
|
24
|
+
*
|
|
25
|
+
* @param value - Value to sanitize; left untouched.
|
|
26
|
+
* @returns A sanitized copy of the same shape.
|
|
27
|
+
*/
|
|
28
|
+
export function sanitizeValue(value) {
|
|
29
|
+
return walk(value, 0);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Depth-bounded copy with redaction applied at every level.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Current node.
|
|
35
|
+
* @param depth - Depth of this node.
|
|
36
|
+
* @returns The sanitized node.
|
|
37
|
+
*/
|
|
38
|
+
function walk(value, depth) {
|
|
39
|
+
if (depth > MAX_DEPTH)
|
|
40
|
+
return TRUNCATED;
|
|
41
|
+
if (typeof value === 'string')
|
|
42
|
+
return sanitizeText(value);
|
|
43
|
+
if (Array.isArray(value))
|
|
44
|
+
return value.map((item) => walk(item, depth + 1));
|
|
45
|
+
if (!isRecord(value))
|
|
46
|
+
return value;
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
49
|
+
out[key] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : walk(entry, depth + 1);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** One credential shape recognized in outgoing text. */
|
|
2
|
+
export interface SecretPattern {
|
|
3
|
+
/** Diagnostic name; never emitted. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Global pattern, applied with String.prototype.replace. */
|
|
6
|
+
readonly pattern: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Replacement template. Omit to blank the whole match; supply one to keep
|
|
9
|
+
* the harmless part (the scheme, the key name) so the redaction stays
|
|
10
|
+
* readable to whoever is debugging.
|
|
11
|
+
*/
|
|
12
|
+
readonly replacement?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
+
import type { HookContext } from '../types/provider.types.js';
|
|
3
|
+
import type { AntigravityHookEvent } from './types/antigravity.types.js';
|
|
4
|
+
export type { AntigravityHookEvent, AntigravityPayload } from './types/antigravity.types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Which hook this payload is.
|
|
7
|
+
*
|
|
8
|
+
* `HookArgs` carries no event-name field: the event is whichever member of its
|
|
9
|
+
* oneof is set. Anything that is not a recognizable `HookArgs` returns
|
|
10
|
+
* undefined, so a schema change shows up as no telemetry rather than as
|
|
11
|
+
* mis-attributed telemetry.
|
|
12
|
+
*
|
|
13
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
14
|
+
* @returns The hook name, or undefined.
|
|
15
|
+
*/
|
|
16
|
+
export declare function antigravityHookEvent(rawPayload: unknown): AntigravityHookEvent | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Working directory for git and repo-config lookups.
|
|
19
|
+
*
|
|
20
|
+
* Antigravity reports a workspace list rather than a single `cwd`; the first
|
|
21
|
+
* entry is the primary workspace root.
|
|
22
|
+
*
|
|
23
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
24
|
+
* @returns The primary workspace path, or undefined.
|
|
25
|
+
*/
|
|
26
|
+
export declare function antigravityCwd(rawPayload: unknown): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Translate one Antigravity hook payload into canonical events.
|
|
29
|
+
*
|
|
30
|
+
* The two-level execution model matters for attribution: an *execution* is one
|
|
31
|
+
* agent run — the turn — and PreInvocation/PostInvocation bracket the individual
|
|
32
|
+
* model calls inside it. Treating an invocation as a turn boundary would emit
|
|
33
|
+
* one turn summary per model call and inflate every per-turn aggregate, so only
|
|
34
|
+
* `Stop` closes a turn here.
|
|
35
|
+
*
|
|
36
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
37
|
+
* @param context - Environment and effective config.
|
|
38
|
+
* @returns The canonical events, or an empty list for an unusable payload.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseAntigravityHookEvent(rawPayload: unknown, context: HookContext): AgentWatchEvent[];
|
|
41
|
+
/**
|
|
42
|
+
* The model id behind Antigravity's display name.
|
|
43
|
+
*
|
|
44
|
+
* Exported for the same reason it exists: `Claude Opus 4.6 (Thinking)` is not a
|
|
45
|
+
* model any price list, any other provider's records, or any group-by-model
|
|
46
|
+
* report can match, and the turn it describes is the only place the name
|
|
47
|
+
* appears. This translates the picker's label into the id every other agent
|
|
48
|
+
* reports — and leaves an id that already looks like one untouched, so it is
|
|
49
|
+
* safe to apply to whatever the payload happens to carry.
|
|
50
|
+
*
|
|
51
|
+
* @param displayName - `common.modelName`, as Antigravity wrote it.
|
|
52
|
+
* @returns The canonical id, or undefined when no model was named.
|
|
53
|
+
*/
|
|
54
|
+
export declare function canonicalModelName(displayName: string | undefined): string | undefined;
|