@agent-watch-ai/edge 0.2.5 → 0.4.0
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 +558 -0
- package/README.md +222 -97
- package/SECURITY.md +72 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +52 -4
- package/dist/cli/constants/cli.constants.js +56 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +321 -33
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +553 -103
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +117 -0
- package/dist/cli/types/cli.types.d.ts +43 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +110 -12
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +116 -6
- package/dist/config/constants/config.constants.js +131 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +831 -84
- package/dist/config/schemas/config.schema.js +398 -16
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +119 -0
- package/dist/credentials/constants/credentials.constants.js +120 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +38 -0
- package/dist/credentials/credentials.d.ts +86 -0
- package/dist/credentials/credentials.js +278 -0
- package/dist/credentials/device-api.d.ts +73 -0
- package/dist/credentials/device-api.js +161 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +73 -0
- package/dist/credentials/identity.js +101 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +31 -0
- package/dist/credentials/sign-in.js +105 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +206 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +64 -17
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +107 -17
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +66 -2
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +10 -0
- package/dist/pipeline/constants/pipeline.constants.js +10 -0
- package/dist/pipeline/hook-pipeline.js +410 -33
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +75 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +36 -3
- package/dist/providers/codex/codex.otel.js +199 -32
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +10 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
- package/dist/providers/constants/provider.constants.d.ts +8 -3
- package/dist/providers/constants/provider.constants.js +8 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
- package/dist/providers/cursor/constants/cursor.constants.js +9 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +129 -4
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +9 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +30 -21
- package/dist/providers/gemini/gemini.otel.js +166 -22
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
- package/dist/providers/shared/constants/tooling.constants.js +25 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +40 -1
- package/dist/providers/shared/tooling.js +70 -1
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +81 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +21 -0
- package/dist/storage/atomic-file.js +20 -1
- package/dist/storage/constants/storage.constants.d.ts +19 -0
- package/dist/storage/constants/storage.constants.js +19 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +67 -0
- package/dist/turns/work-checkout.js +700 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +655 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
|
@@ -1,24 +1,64 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { asRecord } from '../../core/object.js';
|
|
3
|
+
import { CREDENTIAL_STORE_KINDS, DEVICE_SOURCE_BATCH_CODE, RE_DEVICE_ID } from '../../credentials/constants/credentials.constants.js';
|
|
4
|
+
import { AGENT_WATCH_HOSTS, CUSTOM_ENDPOINT_MESSAGE, CUSTOM_ENDPOINTS_KEY, DELIVERABLE_URL_MESSAGE, DEVICE_URL_FIELDS, ROOTS_KEY, ROOT_URL_FIELDS, URL_FIELDS, LOOPBACK_HOSTS, DEFAULT_DRAIN_BATCH_SIZE, DEFAULT_ENFORCEMENT_CACHE_TTL_MS, DEFAULT_ENFORCEMENT_TIMEOUT_MS, DEFAULT_MAX_ATTEMPTS, DEFAULT_MAX_EVENT_AGE_DAYS, DEFAULT_MAX_QUEUE_EVENTS, DEFAULT_SEND_TIMEOUT_MS } from '../constants/config.constants.js';
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The content flags, off.
|
|
7
|
+
*
|
|
8
|
+
* Keyed on `CONTENT_CAPTURE_KEYS` rather than spelled loose, so a content flag
|
|
9
|
+
* added there fails to compile here instead of quietly escaping the gate.
|
|
10
|
+
* At module scope because it is a constant, not a per-parse allocation
|
|
11
|
+
* (STYLEGUIDE 3.1).
|
|
12
|
+
*/
|
|
13
|
+
const CONTENT_OFF = {
|
|
14
|
+
promptText: false,
|
|
15
|
+
toolInput: false,
|
|
16
|
+
toolOutput: false,
|
|
17
|
+
sessionTitle: false
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Content is opt-IN; metadata stays on.
|
|
21
|
+
*
|
|
22
|
+
* `promptText` carries what the developer typed, bounded and scrubbed, so the
|
|
23
|
+
* backend can tell what a session with no repository was about. `toolInput` and
|
|
24
|
+
* `toolOutput` carry what went into and came out of a tool. `sessionTitle`
|
|
25
|
+
* carries the session's name and generated title. All four are
|
|
26
|
+
* material an IT review will not wave through, so nothing ships them unless
|
|
27
|
+
* someone deliberately turned them on. The agent's response text has no flag:
|
|
28
|
+
* it never leaves the machine. An older config's `prompts` / `responses` keys
|
|
29
|
+
* are stripped here, and the next `setup` removes them from the file.
|
|
30
|
+
*
|
|
31
|
+
* `git` and `files` are a different kind of thing: they gate the
|
|
32
|
+
* repo/branch/SHA and the per-file *path*, which is metadata about where work
|
|
33
|
+
* happened, not the work itself — and it is what feature and project
|
|
34
|
+
* attribution is made of, so it stays on by default.
|
|
35
|
+
*
|
|
36
|
+
* Independent of all of them: `contentEvidence()` still records a length and a
|
|
37
|
+
* SHA-256 of prompts and responses, and the sanitizer scrubs secrets from
|
|
38
|
+
* whatever does get sent.
|
|
39
|
+
*
|
|
40
|
+
* The content flags are gated a second time by the global
|
|
41
|
+
* `contentCaptureConsent` marker below: a config carrying `promptText: true`
|
|
42
|
+
* without it collects nothing, which is what keeps an upgrade of an older
|
|
43
|
+
* install from silently starting to ship content.
|
|
7
44
|
*/
|
|
8
45
|
export const captureSchema = z
|
|
9
46
|
.object({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
47
|
+
promptText: z.boolean().default(false),
|
|
48
|
+
toolInput: z.boolean().default(false),
|
|
49
|
+
toolOutput: z.boolean().default(false),
|
|
50
|
+
/** The provider's native session name/title, scrubbed and bounded. A generated title can paraphrase the first prompt; the edge never derives one from the prompt. */
|
|
51
|
+
sessionTitle: z.boolean().default(false),
|
|
14
52
|
git: z.boolean().default(true),
|
|
15
|
-
files: z.boolean().default(true)
|
|
53
|
+
files: z.boolean().default(true),
|
|
54
|
+
/** MCP server and tool names in `tools_used`; false folds them into `mcp`. Metadata, not content. */
|
|
55
|
+
mcpNames: z.boolean().default(true)
|
|
16
56
|
})
|
|
17
|
-
.
|
|
57
|
+
.strip();
|
|
18
58
|
/** Tuning for the in-hook send and the machine-global offline queue. */
|
|
19
59
|
export const deliverySchema = z
|
|
20
60
|
.object({
|
|
21
|
-
/**
|
|
61
|
+
/** Shared network budget for direct send and backlog retries in one delivery pass. */
|
|
22
62
|
timeoutMs: z.number().int().positive().default(DEFAULT_SEND_TIMEOUT_MS),
|
|
23
63
|
/** How many queued events one drain pass may send. */
|
|
24
64
|
drainBatchSize: z.number().int().positive().default(DEFAULT_DRAIN_BATCH_SIZE),
|
|
@@ -74,24 +114,366 @@ export const emitSchema = z
|
|
|
74
114
|
.transform(() => true)
|
|
75
115
|
})
|
|
76
116
|
.strip();
|
|
117
|
+
/**
|
|
118
|
+
* Judge one URL: deliverable at all, and then allowed to receive a bearer.
|
|
119
|
+
*
|
|
120
|
+
* Deliverable first. `z.string().url()` alone accepts `file:`, `javascript:`,
|
|
121
|
+
* `data:`, `ftp:` and plain `http:` to anywhere, and hand-editing the config is
|
|
122
|
+
* the documented way to enable content capture, so one slipped character would
|
|
123
|
+
* otherwise ship `Authorization: Bearer <token>` plus every captured prompt in
|
|
124
|
+
* cleartext. `http:` survives for loopback only.
|
|
125
|
+
*
|
|
126
|
+
* Then allowed. A setup line is copied from a web page or a chat, so anyone who
|
|
127
|
+
* can forge one could otherwise point a machine, and its credential, at their
|
|
128
|
+
* own server (SPEC R9). Only the compiled Agent Watch hosts on the default https
|
|
129
|
+
* port, loopback, and the origins this machine trusts pass. Host only, never a
|
|
130
|
+
* certificate: TLS is verified against the system trust store with no pinning
|
|
131
|
+
* (SPEC R10), so a corporate TLS-inspecting proxy keeps working.
|
|
132
|
+
*
|
|
133
|
+
* @param value - The URL as written.
|
|
134
|
+
* @param trusted - Origins this machine trusts, as `originOf` spells them.
|
|
135
|
+
* @returns The verdict, carrying the origin to name in a report.
|
|
136
|
+
*/
|
|
137
|
+
function judgeUrl(value, trusted) {
|
|
138
|
+
const url = parseUrl(value);
|
|
139
|
+
if (!url)
|
|
140
|
+
return { kind: 'undeliverable' };
|
|
141
|
+
const origin = originOf(url);
|
|
142
|
+
// Without the trailing dot: `host.` is the same DNS name as `host`.
|
|
143
|
+
const host = url.hostname.endsWith('.') ? url.hostname.slice(0, -1) : url.hostname;
|
|
144
|
+
const loopback = LOOPBACK_HOSTS.has(host);
|
|
145
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) {
|
|
146
|
+
return { kind: 'undeliverable', ...(url.protocol === 'http:' ? { origin } : {}) };
|
|
147
|
+
}
|
|
148
|
+
if (loopback || trusted.has(origin))
|
|
149
|
+
return { kind: 'allowed', origin };
|
|
150
|
+
// A port other than the default needs trust: a different port on the right
|
|
151
|
+
// name is a different service.
|
|
152
|
+
if (url.protocol === 'https:' && url.port === '' && AGENT_WATCH_HOSTS.has(host))
|
|
153
|
+
return { kind: 'allowed', origin };
|
|
154
|
+
return { kind: 'untrusted', origin };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A URL's origin as trust is recorded: scheme, lower-case host without a
|
|
158
|
+
* trailing dot, and a non-default port. Never the path, the query or any
|
|
159
|
+
* credential, so it is safe to print.
|
|
160
|
+
*
|
|
161
|
+
* @param url - A parsed URL.
|
|
162
|
+
* @returns The origin.
|
|
163
|
+
*/
|
|
164
|
+
function originOf(url) {
|
|
165
|
+
const host = url.hostname.endsWith('.') ? url.hostname.slice(0, -1) : url.hostname;
|
|
166
|
+
return `${url.protocol}//${host}${url.port ? `:${url.port}` : ''}`;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Whether the edge may send a bearer and records to this URL. See `judgeUrl`.
|
|
170
|
+
*
|
|
171
|
+
* @param value - The URL as written.
|
|
172
|
+
* @param trusted - Origins this machine trusts (`customEndpoints`).
|
|
173
|
+
* @returns True when the edge may send there.
|
|
174
|
+
*/
|
|
175
|
+
export function isAllowedHost(value, trusted) {
|
|
176
|
+
return judgeUrl(value, trusted).kind === 'allowed';
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The origin of a URL the edge could deliver to, for recording trust in it.
|
|
180
|
+
*
|
|
181
|
+
* @param value - The URL as written.
|
|
182
|
+
* @returns The origin, or undefined when the URL is not deliverable.
|
|
183
|
+
*/
|
|
184
|
+
export function deliverableOrigin(value) {
|
|
185
|
+
const verdict = judgeUrl(value, new Set());
|
|
186
|
+
return verdict.kind === 'undeliverable' ? undefined : verdict.origin;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Whether only a trusted origin would let this URL through: deliverable, but
|
|
190
|
+
* neither an Agent Watch host nor loopback.
|
|
191
|
+
*
|
|
192
|
+
* @param value - The URL as written.
|
|
193
|
+
* @returns True when sending there needs `--allow-custom-endpoint`.
|
|
194
|
+
*/
|
|
195
|
+
export function needsTrust(value) {
|
|
196
|
+
return judgeUrl(value, new Set()).kind === 'untrusted';
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Parse a URL without throwing.
|
|
200
|
+
*
|
|
201
|
+
* @param value - Candidate URL.
|
|
202
|
+
* @returns The parsed URL, or undefined when it is not one.
|
|
203
|
+
*/
|
|
204
|
+
function parseUrl(value) {
|
|
205
|
+
try {
|
|
206
|
+
return new URL(value);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Every backend URL in a raw config file, judged once, before the schema reads it.
|
|
214
|
+
*
|
|
215
|
+
* The one place both the refusal and its report come from: one walk over the
|
|
216
|
+
* machine fields and every `roots[]` entry, one parse per URL. A refused value
|
|
217
|
+
* becomes `null` — "a URL was written here and refused" — rather than fatal.
|
|
218
|
+
* Failing the parse instead took the whole file down with it, and `loadConfig`
|
|
219
|
+
* answers a failed parse with `fallbackConfig()` — no endpoint, no token, no
|
|
220
|
+
* installation id:
|
|
221
|
+
*
|
|
222
|
+
* - An upgrade of a fleet pointed at an internal `http://collector.corp:4318`
|
|
223
|
+
* lost its *token* along with its endpoint, so every hook queued into
|
|
224
|
+
* `unconfigured/` while the existing backlog stayed pinned to
|
|
225
|
+
* `sha256(token)` — a partition nothing would ever drain again.
|
|
226
|
+
* - `roots` is a record of these same fields, so one typo in one project's
|
|
227
|
+
* entry stopped delivery for every other project on the machine.
|
|
228
|
+
*
|
|
229
|
+
* `null` and not absent, and that distinction is the whole point for a `roots[]`
|
|
230
|
+
* entry. `applyRootOverride` lays the override over the global config through
|
|
231
|
+
* `compact`, which skips undefined-valued keys so an override cannot erase a
|
|
232
|
+
* global — so an *absent* endpoint made the root inherit the machine's, and a
|
|
233
|
+
* consultant's `roots["/work/clientA"]` would have had every prompt in that
|
|
234
|
+
* directory POSTed to the *other* tenant's backend under clientA's own bearer.
|
|
235
|
+
* `null` survives `compact`, so the root's events queue under its own token
|
|
236
|
+
* instead of leaving.
|
|
237
|
+
*
|
|
238
|
+
* Anything present that is not a deliverable *string* counts: a number, an array
|
|
239
|
+
* or a `null` a templating tool emitted for a missing value is refused and
|
|
240
|
+
* reported, not waved through as absent.
|
|
241
|
+
*
|
|
242
|
+
* With `grandfather`, a URL only trust would let through is trusted instead of
|
|
243
|
+
* refused: the file predates the allowlist, and that backend was the
|
|
244
|
+
* developer's choice before there was a flag to say so.
|
|
245
|
+
*
|
|
246
|
+
* @param raw - The parsed JSON of the config file, whatever shape it has.
|
|
247
|
+
* @param grandfather - The file predates the allowlist.
|
|
248
|
+
* @returns The value to hand the schema, the warnings, and the origins grandfathered.
|
|
249
|
+
*/
|
|
250
|
+
export function screenConfigUrls(raw, grandfather) {
|
|
251
|
+
const record = asRecord(raw);
|
|
252
|
+
if (!record)
|
|
253
|
+
return { value: raw, warnings: [], grandfathered: [] };
|
|
254
|
+
const listed = trustedOrigins(record[CUSTOM_ENDPOINTS_KEY]);
|
|
255
|
+
const trusted = new Set(listed);
|
|
256
|
+
const grandfathered = [];
|
|
257
|
+
const refusals = [];
|
|
258
|
+
const judge = (value, field, root, device = false) => {
|
|
259
|
+
if (value === undefined)
|
|
260
|
+
return;
|
|
261
|
+
const verdict = typeof value === 'string' ? judgeUrl(value, trusted) : { kind: 'undeliverable' };
|
|
262
|
+
if (verdict.kind === 'allowed')
|
|
263
|
+
return;
|
|
264
|
+
if (verdict.kind === 'untrusted' && grandfather && verdict.origin) {
|
|
265
|
+
trusted.add(verdict.origin);
|
|
266
|
+
grandfathered.push(verdict.origin);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
refusals.push({ root, device, field, warning: refusalWarning(verdict, device ? `device.${field}` : field, root, typeof value === 'string' && hasPath(value)) });
|
|
270
|
+
};
|
|
271
|
+
// Where uninstall POSTs the device secret: the same rule as every other URL.
|
|
272
|
+
const judgeDevice = (entry, root) => {
|
|
273
|
+
const device = asRecord(entry['device']);
|
|
274
|
+
if (device)
|
|
275
|
+
for (const field of DEVICE_URL_FIELDS)
|
|
276
|
+
judge(device[field], field, root, true);
|
|
277
|
+
};
|
|
278
|
+
for (const field of URL_FIELDS)
|
|
279
|
+
judge(record[field], field, undefined);
|
|
280
|
+
judgeDevice(record, undefined);
|
|
281
|
+
const roots = asRecord(record[ROOTS_KEY]);
|
|
282
|
+
for (const [root, entry] of Object.entries(roots ?? {})) {
|
|
283
|
+
const fields = asRecord(entry);
|
|
284
|
+
if (!fields)
|
|
285
|
+
continue;
|
|
286
|
+
for (const field of ROOT_URL_FIELDS)
|
|
287
|
+
judge(fields[field], field, root);
|
|
288
|
+
judgeDevice(fields, root);
|
|
289
|
+
}
|
|
290
|
+
const value = grandfathered.length > 0 ? { ...record, [CUSTOM_ENDPOINTS_KEY]: [...listed, ...grandfathered] } : record;
|
|
291
|
+
return { value: withRefusalsNulled(value, roots, refusals), warnings: refusals.map((refusal) => refusal.warning), grandfathered };
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The `customEndpoints` entries that are strings. Anything else reads as no
|
|
295
|
+
* trust, without failing the file: a templated `"yes"` must not be consent.
|
|
296
|
+
*
|
|
297
|
+
* @param value - The raw `customEndpoints` value.
|
|
298
|
+
* @returns The origins.
|
|
299
|
+
*/
|
|
300
|
+
function trustedOrigins(value) {
|
|
301
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === 'string') : [];
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Whether a URL names more than its origin.
|
|
305
|
+
*
|
|
306
|
+
* @param value - The configured URL.
|
|
307
|
+
* @returns True when its path is not just `/`.
|
|
308
|
+
*/
|
|
309
|
+
function hasPath(value) {
|
|
310
|
+
try {
|
|
311
|
+
return new URL(value).pathname.replace(/\/+$/, '') !== '';
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The line a refused field is reported with: its path, its origin, and what to do.
|
|
319
|
+
*
|
|
320
|
+
* Origin only, so no path, query or userinfo credential reaches a terminal or a
|
|
321
|
+
* fleet log. The remedy is the command that fixes this field: `setup` for an
|
|
322
|
+
* endpoint, since that is the field it writes; the trust list for a route,
|
|
323
|
+
* which setup never writes on its own.
|
|
324
|
+
*
|
|
325
|
+
* @param verdict - Why it was refused.
|
|
326
|
+
* @param field - The field name.
|
|
327
|
+
* @param root - The `roots[]` key, for a root's field.
|
|
328
|
+
* @param pathed - The URL carries a path, which the origin alone would drop: the
|
|
329
|
+
* setup command then names a placeholder rather than a URL that would point
|
|
330
|
+
* events at the wrong place.
|
|
331
|
+
* @returns The warning.
|
|
332
|
+
*/
|
|
333
|
+
function refusalWarning(verdict, field, root, pathed) {
|
|
334
|
+
const path = root === undefined ? field : `roots.${root}.${field}`;
|
|
335
|
+
if (verdict.kind !== 'untrusted' || !verdict.origin)
|
|
336
|
+
return `${path}: ${verdict.origin ? `${verdict.origin} ` : ''}${DELIVERABLE_URL_MESSAGE} — ignored, nothing is sent there`;
|
|
337
|
+
const setup = `agentwatch setup${root === undefined ? '' : ` --root ${root} --token <token>`} --endpoint ${pathed ? '<endpoint URL>' : verdict.origin} --allow-custom-endpoint`;
|
|
338
|
+
const remedy = field === 'endpoint' ? `run \`${setup}\`` : `add "${verdict.origin}" to ${CUSTOM_ENDPOINTS_KEY} in the config file`;
|
|
339
|
+
return `${path}: ${verdict.origin} ${CUSTOM_ENDPOINT_MESSAGE}; if you trust it, ${remedy}`;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The record with every refused field set to `null`, and every refused
|
|
343
|
+
* `device` URL dropped to absent (revocation then falls back to the identity's
|
|
344
|
+
* own checked endpoint). Returns the input itself when nothing was refused,
|
|
345
|
+
* which is every load of a healthy install.
|
|
346
|
+
*
|
|
347
|
+
* @param record - The raw config.
|
|
348
|
+
* @param roots - Its raw `roots` block.
|
|
349
|
+
* @param refusals - What the screen refused.
|
|
350
|
+
* @returns The record to parse.
|
|
351
|
+
*/
|
|
352
|
+
function withRefusalsNulled(record, roots, refusals) {
|
|
353
|
+
if (refusals.length === 0)
|
|
354
|
+
return record;
|
|
355
|
+
const refuse = (entry, refusal) => {
|
|
356
|
+
if (!refusal.device)
|
|
357
|
+
return { ...entry, [refusal.field]: null };
|
|
358
|
+
const { [refusal.field]: _refused, ...device } = asRecord(entry['device']) ?? {};
|
|
359
|
+
return { ...entry, device };
|
|
360
|
+
};
|
|
361
|
+
let machine = record;
|
|
362
|
+
let rootEntries;
|
|
363
|
+
for (const refusal of refusals) {
|
|
364
|
+
if (refusal.root === undefined) {
|
|
365
|
+
machine = refuse(machine, refusal);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const entries = rootEntries ?? { ...roots };
|
|
369
|
+
rootEntries = { ...entries, [refusal.root]: refuse(asRecord(entries[refusal.root]) ?? {}, refusal) };
|
|
370
|
+
}
|
|
371
|
+
return { ...machine, ...(rootEntries ? { [ROOTS_KEY]: rootEntries } : {}) };
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Where this identity's device secret lives, once its install key has been
|
|
375
|
+
* exchanged (AWT-356). Never the secret itself.
|
|
376
|
+
*
|
|
377
|
+
* `.catch(undefined)` for the reason `deliverableUrl` catches: a hand-edited or
|
|
378
|
+
* templated value must cost this field, not the whole file and with it every
|
|
379
|
+
* other identity on the machine.
|
|
380
|
+
*
|
|
381
|
+
* `endpoint` is where uninstall POSTs the device secret, so `screenConfigUrls`
|
|
382
|
+
* judges it like every other URL. A refused one is dropped to absent, not null:
|
|
383
|
+
* revocation then falls back to the identity's own checked endpoint.
|
|
384
|
+
*/
|
|
385
|
+
const deviceCredential = z
|
|
386
|
+
.object({
|
|
387
|
+
id: z.string().regex(RE_DEVICE_ID),
|
|
388
|
+
store: z.enum(CREDENTIAL_STORE_KINDS),
|
|
389
|
+
endpoint: z.string().optional().catch(undefined),
|
|
390
|
+
source: z.literal(DEVICE_SOURCE_BATCH_CODE).optional().catch(undefined),
|
|
391
|
+
codeId: z.string().optional().catch(undefined)
|
|
392
|
+
})
|
|
393
|
+
.strip()
|
|
394
|
+
.optional()
|
|
395
|
+
.catch(undefined);
|
|
396
|
+
/**
|
|
397
|
+
* A backend URL field. `screenConfigUrls` has already refused what the edge
|
|
398
|
+
* must not send to, so here a value is a string, `null` for refused, or absent.
|
|
399
|
+
* `.catch(null)` keeps a direct parse of an unscreened value from failing the
|
|
400
|
+
* whole file over one field.
|
|
401
|
+
*/
|
|
402
|
+
const deliverableUrl = z.string().nullish().catch(null);
|
|
403
|
+
/**
|
|
404
|
+
* One project root's identity. Only the fields that decide *who* the events
|
|
405
|
+
* belong to and *where* they go: capture and emission stay machine-wide, so a
|
|
406
|
+
* second tenant cannot quietly widen what is collected under it.
|
|
407
|
+
*
|
|
408
|
+
* `.strip()` rather than passthrough, so a nested `roots` key cannot recurse
|
|
409
|
+
* and a mistyped block cannot smuggle in delivery tuning.
|
|
410
|
+
*/
|
|
411
|
+
export const rootOverrideSchema = z
|
|
412
|
+
.object({
|
|
413
|
+
endpoint: deliverableUrl,
|
|
414
|
+
eventsUrl: deliverableUrl,
|
|
415
|
+
otlpUrl: deliverableUrl,
|
|
416
|
+
token: z.string().optional(),
|
|
417
|
+
device: deviceCredential,
|
|
418
|
+
installationId: z.string().optional(),
|
|
419
|
+
developerEmail: z.string().optional(),
|
|
420
|
+
developerName: z.string().optional()
|
|
421
|
+
})
|
|
422
|
+
.strip();
|
|
77
423
|
/** The whole configuration file. Passthrough: forward compatibility. */
|
|
78
424
|
export const configSchema = z
|
|
79
425
|
.object({
|
|
80
426
|
schemaVersion: z.literal(1).default(1),
|
|
81
427
|
/** Backend base URL, e.g. https://backend.example.com */
|
|
82
|
-
endpoint:
|
|
428
|
+
endpoint: deliverableUrl,
|
|
83
429
|
/** Overrides; derived from endpoint when absent. */
|
|
84
|
-
eventsUrl:
|
|
85
|
-
otlpUrl:
|
|
86
|
-
enforcementUrl:
|
|
430
|
+
eventsUrl: deliverableUrl,
|
|
431
|
+
otlpUrl: deliverableUrl,
|
|
432
|
+
enforcementUrl: deliverableUrl,
|
|
433
|
+
/** The install key, until it is exchanged for `device` (AWT-356). */
|
|
87
434
|
token: z.string().optional(),
|
|
435
|
+
device: deviceCredential,
|
|
436
|
+
/**
|
|
437
|
+
* The organization an enrollment URL named. Beside no credential it marks an
|
|
438
|
+
* MDM install whose developer has not signed in yet: it sends nothing.
|
|
439
|
+
*/
|
|
440
|
+
organizationId: z.string().optional(),
|
|
88
441
|
installationId: z.string().optional(),
|
|
89
442
|
/** Developer identity attached to turn summaries; falls back to `git config user.email`. */
|
|
90
443
|
developerEmail: z.string().optional(),
|
|
444
|
+
/**
|
|
445
|
+
* What to call this developer in the platform's views; falls back to
|
|
446
|
+
* `git config user.name`. Never an identity: nothing is keyed on it, and a
|
|
447
|
+
* turn is still reported under `developerEmail`.
|
|
448
|
+
*/
|
|
449
|
+
developerName: z.string().optional(),
|
|
450
|
+
/**
|
|
451
|
+
* Absolute project root -> the identity to use beneath it. Longest match
|
|
452
|
+
* wins, so a nested checkout can override the workspace above it.
|
|
453
|
+
*/
|
|
454
|
+
roots: z.record(z.string(), rootOverrideSchema).optional(),
|
|
455
|
+
contentCaptureConsent: z.boolean().default(false),
|
|
456
|
+
/**
|
|
457
|
+
* Origins this machine sends to outside the Agent Watch hosts. Written by
|
|
458
|
+
* `setup --allow-custom-endpoint` (exactly the origin that run named) or
|
|
459
|
+
* grandfathered from a file older than the allowlist; shown by `status` and
|
|
460
|
+
* `doctor`. A malformed value reads as no trust without failing the file.
|
|
461
|
+
*/
|
|
462
|
+
customEndpoints: z.array(z.string()).catch([]).default([]),
|
|
463
|
+
/** Present on a file written after the allowlist; see `ALLOWLIST_VERSION_KEY`. */
|
|
464
|
+
allowlistVersion: z.number().optional(),
|
|
465
|
+
/** Tell the developer, once per repository per session, that a run called an LLM with no tracing (AWT-310). */
|
|
466
|
+
untracedNotices: z.boolean().default(true),
|
|
467
|
+
/** At session start, say when npm has a newer release; checked at most once a day, in the background. */
|
|
468
|
+
updateNotices: z.boolean().default(true),
|
|
91
469
|
capture: captureSchema.default({}),
|
|
92
470
|
emit: emitSchema.default({}),
|
|
93
471
|
otel: otelSchema.default({}),
|
|
94
472
|
delivery: deliverySchema.default({}),
|
|
95
473
|
enforcement: enforcementSchema.default({})
|
|
96
474
|
})
|
|
97
|
-
.passthrough()
|
|
475
|
+
.passthrough()
|
|
476
|
+
.transform((config) => ({
|
|
477
|
+
...config,
|
|
478
|
+
capture: config.contentCaptureConsent ? config.capture : { ...config.capture, ...CONTENT_OFF }
|
|
479
|
+
}));
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
import type { captureSchema, configSchema, enforcementSchema, otelSchema } from '../schemas/config.schema.js';
|
|
2
|
+
import type { captureSchema, configSchema, enforcementSchema, otelSchema, rootOverrideSchema } from '../schemas/config.schema.js';
|
|
3
3
|
export type CaptureConfig = z.infer<typeof captureSchema>;
|
|
4
4
|
export type OtelConfig = z.infer<typeof otelSchema>;
|
|
5
5
|
export type EnforcementConfig = z.infer<typeof enforcementSchema>;
|
|
6
6
|
export type AgentWatchConfig = z.infer<typeof configSchema>;
|
|
7
|
+
export type RootOverride = z.infer<typeof rootOverrideSchema>;
|
|
8
|
+
/** A config with one project root's identity applied, and which root won. */
|
|
9
|
+
export interface RootedConfig {
|
|
10
|
+
readonly config: AgentWatchConfig;
|
|
11
|
+
readonly root?: {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly override: RootOverride;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
7
16
|
/** Name of one native OTLP signal. */
|
|
8
17
|
export type OtelSignalName = keyof OtelConfig;
|
|
9
18
|
/**
|
|
@@ -14,13 +23,16 @@ export type OtelSignalName = keyof OtelConfig;
|
|
|
14
23
|
export type ConfigLoadResult = {
|
|
15
24
|
readonly state: 'ok';
|
|
16
25
|
readonly config: AgentWatchConfig;
|
|
26
|
+
readonly warnings: readonly string[];
|
|
17
27
|
} | {
|
|
18
28
|
readonly state: 'missing';
|
|
19
29
|
readonly config: AgentWatchConfig;
|
|
30
|
+
readonly warnings: readonly string[];
|
|
20
31
|
} | {
|
|
21
32
|
readonly state: 'invalid';
|
|
22
33
|
readonly error: string;
|
|
23
34
|
readonly config: AgentWatchConfig;
|
|
35
|
+
readonly warnings: readonly string[];
|
|
24
36
|
};
|
|
25
37
|
/** A config with the repository overlay applied, and what was refused. */
|
|
26
38
|
export interface MergedConfig {
|
|
@@ -30,4 +42,6 @@ export interface MergedConfig {
|
|
|
30
42
|
export interface EffectiveConfig extends MergedConfig {
|
|
31
43
|
/** Path of the applied repo overrides file, when one was found. */
|
|
32
44
|
readonly repoConfigFile?: string;
|
|
45
|
+
/** Project root whose identity was applied, when one matched. */
|
|
46
|
+
readonly rootPath?: string;
|
|
33
47
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentWatchConfig } from './config.types.js';
|
|
2
|
+
/** Backend identity and explicit routes, independent of machine/root storage. */
|
|
3
|
+
export type Destination = Readonly<Pick<AgentWatchConfig, 'endpoint' | 'eventsUrl' | 'otlpUrl' | 'enforcementUrl'>>;
|
|
4
|
+
/** A write plan also records route removals so setup cannot erase them silently. */
|
|
5
|
+
export type DestinationTransition = {
|
|
6
|
+
readonly routes: Readonly<Omit<Destination, 'endpoint'>>;
|
|
7
|
+
readonly cleared: readonly ('eventsUrl' | 'otlpUrl' | 'enforcementUrl')[];
|
|
8
|
+
};
|
package/dist/core/async.d.ts
CHANGED
|
@@ -18,3 +18,39 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
18
18
|
* @returns The resource, or undefined when the budget ran out.
|
|
19
19
|
*/
|
|
20
20
|
export declare function pollUntil<T>(acquire: () => Promise<T | undefined>, maxWaitMs: number, pollMs: number): Promise<T | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Wait for some work, but no longer than a budget.
|
|
23
|
+
*
|
|
24
|
+
* Past the budget the caller moves on and the work keeps running. Work that
|
|
25
|
+
* is still running is counted until it settles, because Node cannot cancel a
|
|
26
|
+
* file read already handed to the thread pool, and while one is pending
|
|
27
|
+
* `process.exit` does not return: a read hung on a stuck mount would hold the
|
|
28
|
+
* process for as long as the mount does. `hasAbandonedWork` lets the CLI tell,
|
|
29
|
+
* and a hook that has it exits by signal, which the agent sees as a failed hook.
|
|
30
|
+
* So only work the answer depends on belongs here; optional work that may simply
|
|
31
|
+
* die with the process goes through `notLongerThan`.
|
|
32
|
+
*
|
|
33
|
+
* @param work - The work, already started.
|
|
34
|
+
* @param budgetMs - Time allowed.
|
|
35
|
+
* @returns The work's value, or undefined when the budget ran out first.
|
|
36
|
+
*/
|
|
37
|
+
export declare function withinBudget<T>(work: Promise<T>, budgetMs: number): Promise<T | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Wait for optional work, but no longer than a budget, and leave it behind.
|
|
40
|
+
*
|
|
41
|
+
* Unlike `withinBudget`, work still running past the budget is not counted as
|
|
42
|
+
* abandoned, so it never turns the process's exit into a kill: it is simply cut
|
|
43
|
+
* off when the process exits. Only for work that is safe to stop at any await
|
|
44
|
+
* and that a later run redoes.
|
|
45
|
+
*
|
|
46
|
+
* @param work - The work, already started.
|
|
47
|
+
* @param budgetMs - Time allowed.
|
|
48
|
+
* @returns The work's value, or undefined when the budget ran out first.
|
|
49
|
+
*/
|
|
50
|
+
export declare function notLongerThan<T>(work: Promise<T>, budgetMs: number): Promise<T | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether budgeted work was abandoned and has not finished yet.
|
|
53
|
+
*
|
|
54
|
+
* @returns True while any `withinBudget` work outlived its budget and is still running.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasAbandonedWork(): boolean;
|
package/dist/core/async.js
CHANGED
|
@@ -30,3 +30,71 @@ export async function pollUntil(acquire, maxWaitMs, pollMs) {
|
|
|
30
30
|
await sleep(pollMs);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/** Budgeted work that ran out of time and is still running; see `hasAbandonedWork`. */
|
|
34
|
+
let abandoned = 0;
|
|
35
|
+
/**
|
|
36
|
+
* Wait for some work, but no longer than a budget.
|
|
37
|
+
*
|
|
38
|
+
* Past the budget the caller moves on and the work keeps running. Work that
|
|
39
|
+
* is still running is counted until it settles, because Node cannot cancel a
|
|
40
|
+
* file read already handed to the thread pool, and while one is pending
|
|
41
|
+
* `process.exit` does not return: a read hung on a stuck mount would hold the
|
|
42
|
+
* process for as long as the mount does. `hasAbandonedWork` lets the CLI tell,
|
|
43
|
+
* and a hook that has it exits by signal, which the agent sees as a failed hook.
|
|
44
|
+
* So only work the answer depends on belongs here; optional work that may simply
|
|
45
|
+
* die with the process goes through `notLongerThan`.
|
|
46
|
+
*
|
|
47
|
+
* @param work - The work, already started.
|
|
48
|
+
* @param budgetMs - Time allowed.
|
|
49
|
+
* @returns The work's value, or undefined when the budget ran out first.
|
|
50
|
+
*/
|
|
51
|
+
export async function withinBudget(work, budgetMs) {
|
|
52
|
+
let settled = false;
|
|
53
|
+
const watched = work.finally(() => {
|
|
54
|
+
settled = true;
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
return await notLongerThan(watched, budgetMs);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
if (!settled) {
|
|
61
|
+
abandoned += 1;
|
|
62
|
+
const release = () => {
|
|
63
|
+
abandoned -= 1;
|
|
64
|
+
};
|
|
65
|
+
watched.then(release, release);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Wait for optional work, but no longer than a budget, and leave it behind.
|
|
71
|
+
*
|
|
72
|
+
* Unlike `withinBudget`, work still running past the budget is not counted as
|
|
73
|
+
* abandoned, so it never turns the process's exit into a kill: it is simply cut
|
|
74
|
+
* off when the process exits. Only for work that is safe to stop at any await
|
|
75
|
+
* and that a later run redoes.
|
|
76
|
+
*
|
|
77
|
+
* @param work - The work, already started.
|
|
78
|
+
* @param budgetMs - Time allowed.
|
|
79
|
+
* @returns The work's value, or undefined when the budget ran out first.
|
|
80
|
+
*/
|
|
81
|
+
export async function notLongerThan(work, budgetMs) {
|
|
82
|
+
let timer;
|
|
83
|
+
const late = new Promise((resolve) => {
|
|
84
|
+
timer = setTimeout(() => resolve(undefined), budgetMs);
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
return await Promise.race([work, late]);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether budgeted work was abandoned and has not finished yet.
|
|
95
|
+
*
|
|
96
|
+
* @returns True while any `withinBudget` work outlived its budget and is still running.
|
|
97
|
+
*/
|
|
98
|
+
export function hasAbandonedWork() {
|
|
99
|
+
return abandoned > 0;
|
|
100
|
+
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export { findExecutable } from './which.js';
|
|
|
10
10
|
export { asArray, asRecord, compact, firstNumber, firstString, firstStringOf, isRecord, omitKeys } from './object.js';
|
|
11
11
|
export { add, finiteOrZero, sumPresent } from './number.js';
|
|
12
12
|
export { pollUntil, sleep } from './async.js';
|
|
13
|
-
export { next,
|
|
13
|
+
export { next, runFlow, step, stop } from './pipe.js';
|
package/dist/core/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export { findExecutable } from './which.js';
|
|
|
5
5
|
export { asArray, asRecord, compact, firstNumber, firstString, firstStringOf, isRecord, omitKeys } from './object.js';
|
|
6
6
|
export { add, finiteOrZero, sumPresent } from './number.js';
|
|
7
7
|
export { pollUntil, sleep } from './async.js';
|
|
8
|
-
export { next,
|
|
8
|
+
export { next, runFlow, step, stop } from './pipe.js';
|
package/dist/core/object.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export type { UnknownRecord } from './types/core.types.js';
|
|
|
8
8
|
* absent instead. Building a fresh object (rather than deleting keys) also
|
|
9
9
|
* keeps the result monomorphic for V8 (STYLEGUIDE 3.4).
|
|
10
10
|
*
|
|
11
|
+
* Built on a null prototype and spread into a plain object at the end: on a
|
|
12
|
+
* plain literal an own `__proto__` key (which is what `JSON.parse` produces)
|
|
13
|
+
* would be swallowed by the setter, so the copy would silently lose the one
|
|
14
|
+
* key most likely to be present for a bad reason.
|
|
15
|
+
*
|
|
11
16
|
* @param value - Object to compact; left untouched.
|
|
12
17
|
* @returns A copy holding only the defined entries.
|
|
13
18
|
*/
|