@agent-watch-ai/edge 0.2.5 → 0.3.1
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 +512 -0
- package/README.md +217 -96
- package/SECURITY.md +69 -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 +50 -4
- package/dist/cli/constants/cli.constants.js +54 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +309 -32
- 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 +439 -98
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +113 -0
- package/dist/cli/types/cli.types.d.ts +37 -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 +100 -13
- 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 +113 -6
- package/dist/config/constants/config.constants.js +126 -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 +721 -84
- package/dist/config/schemas/config.schema.js +388 -15
- 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 +111 -0
- package/dist/credentials/constants/credentials.constants.js +112 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +34 -0
- package/dist/credentials/credentials.d.ts +72 -0
- package/dist/credentials/credentials.js +253 -0
- package/dist/credentials/device-api.d.ts +64 -0
- package/dist/credentials/device-api.js +150 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +62 -0
- package/dist/credentials/identity.js +90 -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 +18 -0
- package/dist/credentials/sign-in.js +86 -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 +195 -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 +62 -16
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +103 -15
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +64 -0
- 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 +7 -0
- package/dist/pipeline/constants/pipeline.constants.js +7 -0
- package/dist/pipeline/hook-pipeline.js +360 -32
- 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 +73 -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 +24 -2
- package/dist/providers/codex/codex.otel.js +147 -30
- 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 +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/constants/provider.constants.d.ts +0 -3
- package/dist/providers/constants/provider.constants.js +0 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
- package/dist/providers/cursor/constants/cursor.constants.js +7 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +52 -3
- 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 +3 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -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 +19 -20
- package/dist/providers/gemini/gemini.otel.js +121 -17
- 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/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 +18 -2
- package/dist/providers/shared/constants/tooling.constants.js +19 -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 +12 -1
- package/dist/providers/shared/tooling.js +18 -0
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +57 -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 +7 -0
- package/dist/storage/atomic-file.js +1 -1
- package/dist/storage/constants/storage.constants.d.ts +17 -0
- package/dist/storage/constants/storage.constants.js +17 -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 +65 -0
- package/dist/turns/work-checkout.js +666 -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 +648 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +179 -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
|
@@ -4,7 +4,8 @@ import { asRecord, omitKeys } from '../core/object.js';
|
|
|
4
4
|
import { debugLog } from '../core/logger.js';
|
|
5
5
|
import { readJsonFile } from '../storage/json-file.js';
|
|
6
6
|
import { loadConfig } from './config-store.js';
|
|
7
|
-
import {
|
|
7
|
+
import { applyRootOverride } from './root-config.js';
|
|
8
|
+
import { CAPTURE_KEY, GLOBAL_ONLY_BLOCKS, GLOBAL_ONLY_EMIT_KEYS, GLOBAL_ONLY_KEYS, MAX_WALK_DEPTH, MERGE_BLOCKS, REPO_CONFIG_NAME } from './constants/config.constants.js';
|
|
8
9
|
import { configSchema } from './schemas/config.schema.js';
|
|
9
10
|
export { REPO_CONFIG_NAME } from './constants/config.constants.js';
|
|
10
11
|
/**
|
|
@@ -30,11 +31,11 @@ export async function findRepoConfigFile(startDir) {
|
|
|
30
31
|
* Overlay repository overrides on the global config.
|
|
31
32
|
*
|
|
32
33
|
* A repo file is committed and shared, which is what every rule here follows
|
|
33
|
-
* from: it may narrow what is captured, and it may not touch
|
|
34
|
-
* credentials, delivery destinations or the usage ledger. Anything
|
|
35
|
-
* reported rather than silently dropped, and an invalid *result*
|
|
36
|
-
* the global config — a broken repo file must never disable
|
|
37
|
-
* a hook.
|
|
34
|
+
* from: it may only ever narrow what is captured, and it may not touch
|
|
35
|
+
* identity, credentials, delivery destinations or the usage ledger. Anything
|
|
36
|
+
* refused is reported rather than silently dropped, and an invalid *result*
|
|
37
|
+
* degrades to the global config — a broken repo file must never disable
|
|
38
|
+
* telemetry or break a hook.
|
|
38
39
|
*
|
|
39
40
|
* @param global - The machine's global config.
|
|
40
41
|
* @param repoValue - Raw decoded contents of the repo file.
|
|
@@ -45,13 +46,15 @@ export function mergeRepoConfig(global, repoValue) {
|
|
|
45
46
|
if (!repo)
|
|
46
47
|
return { config: global, warnings: [`${REPO_CONFIG_NAME}: expected a JSON object`] };
|
|
47
48
|
const permitted = withoutGlobalOnly(repo);
|
|
48
|
-
const
|
|
49
|
+
const narrowed = withoutWidenedCapture(global, permitted.value);
|
|
50
|
+
const warnings = [...permitted.warnings, ...narrowed.warnings];
|
|
51
|
+
const merged = overlay(global, narrowed.value);
|
|
49
52
|
const parsed = configSchema.safeParse(merged);
|
|
50
53
|
if (!parsed.success) {
|
|
51
54
|
const detail = parsed.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ');
|
|
52
|
-
return { config: global, warnings: [...
|
|
55
|
+
return { config: global, warnings: [...warnings, `${REPO_CONFIG_NAME}: invalid overrides ignored (${detail})`] };
|
|
53
56
|
}
|
|
54
|
-
return { config: parsed.data, warnings
|
|
57
|
+
return { config: parsed.data, warnings };
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* Global config plus the nearest repo overrides for a directory.
|
|
@@ -61,10 +64,14 @@ export function mergeRepoConfig(global, repoValue) {
|
|
|
61
64
|
*
|
|
62
65
|
* @param paths - Resolved AgentWatch paths.
|
|
63
66
|
* @param cwd - Directory the payload came from.
|
|
67
|
+
* @param preloaded - The global config if the caller already read it. The hook
|
|
68
|
+
* path has it in hand before the first stage runs, and re-reading the file
|
|
69
|
+
* there was one more open, read and parse on every one of the ten-odd hooks a
|
|
70
|
+
* turn fires.
|
|
64
71
|
* @returns The effective config, its warnings, and the file that produced it.
|
|
65
72
|
*/
|
|
66
|
-
export async function loadEffectiveConfig(paths, cwd) {
|
|
67
|
-
const loaded = await loadConfig(paths);
|
|
73
|
+
export async function loadEffectiveConfig(paths, cwd, preloaded) {
|
|
74
|
+
const loaded = preloaded ?? (await loadConfig(paths));
|
|
68
75
|
const global = loaded.config;
|
|
69
76
|
// The fail-safe stays closed: with the global config missing or corrupt the
|
|
70
77
|
// runtime is already metadata-only, and a committed repo file must not be
|
|
@@ -74,20 +81,25 @@ export async function loadEffectiveConfig(paths, cwd) {
|
|
|
74
81
|
debugLog(warning);
|
|
75
82
|
return { config: global, warnings: [warning] };
|
|
76
83
|
}
|
|
84
|
+
// Which tenant this directory reports to, before any repo file is read: a
|
|
85
|
+
// committed file may narrow what is captured, never who it belongs to.
|
|
86
|
+
const rooted = applyRootOverride(global, cwd);
|
|
87
|
+
const base = rooted.config;
|
|
88
|
+
const rootPath = rooted.root?.path;
|
|
77
89
|
const repoConfigFile = await findRepoConfigFileSafely(cwd);
|
|
78
90
|
if (!repoConfigFile)
|
|
79
|
-
return { config:
|
|
91
|
+
return { config: base, warnings: [], rootPath };
|
|
80
92
|
const read = await readJsonFile(repoConfigFile);
|
|
81
93
|
if (read.state !== 'ok') {
|
|
82
94
|
const warnings = read.state === 'invalid' ? [`${repoConfigFile}: ${read.error}`] : [];
|
|
83
95
|
for (const warning of warnings)
|
|
84
96
|
debugLog(warning);
|
|
85
|
-
return { config:
|
|
97
|
+
return { config: base, warnings, repoConfigFile, rootPath };
|
|
86
98
|
}
|
|
87
|
-
const merged = mergeRepoConfig(
|
|
99
|
+
const merged = mergeRepoConfig(base, read.value);
|
|
88
100
|
for (const warning of merged.warnings)
|
|
89
101
|
debugLog(warning);
|
|
90
|
-
return { ...merged, repoConfigFile };
|
|
102
|
+
return { ...merged, repoConfigFile, rootPath };
|
|
91
103
|
}
|
|
92
104
|
/**
|
|
93
105
|
* Strip every override a committed file is not allowed to set.
|
|
@@ -126,6 +138,43 @@ function withoutGlobalOnly(repo) {
|
|
|
126
138
|
}
|
|
127
139
|
return { value: { ...value, emit: omitKeys(emit, refusedEmitKeys) }, warnings };
|
|
128
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Drop repo capture flags that would turn collection *on*.
|
|
143
|
+
*
|
|
144
|
+
* The other half of "a committed file may only narrow": `withoutGlobalOnly`
|
|
145
|
+
* decides which keys a repo file may set at all, this decides which direction
|
|
146
|
+
* it may move the ones it may. Without it, one line in a checked-in
|
|
147
|
+
* `.agentwatch.json` starts shipping prompts and tool I/O for everyone who
|
|
148
|
+
* clones the repository, on machines whose owners opted out.
|
|
149
|
+
*
|
|
150
|
+
* Compared against the base config rather than the schema defaults, so a
|
|
151
|
+
* developer who did opt in globally still gets what they asked for, and a repo
|
|
152
|
+
* file setting the same flag is a permitted no-op. Iterating the repo block's
|
|
153
|
+
* keys and requiring an explicit `false` on the base means unknown keys are
|
|
154
|
+
* left to the schema, which strips them.
|
|
155
|
+
*
|
|
156
|
+
* @param global - The base config the overlay applies to.
|
|
157
|
+
* @param repo - Repo overrides with the global-only keys already removed.
|
|
158
|
+
* @returns The overrides with every widening removed, and one warning each.
|
|
159
|
+
*/
|
|
160
|
+
function withoutWidenedCapture(global, repo) {
|
|
161
|
+
const capture = asRecord(repo[CAPTURE_KEY]);
|
|
162
|
+
if (!capture)
|
|
163
|
+
return { value: repo, warnings: [] };
|
|
164
|
+
const warnings = [];
|
|
165
|
+
const refused = new Set();
|
|
166
|
+
for (const key of Object.keys(capture)) {
|
|
167
|
+
if (capture[key] !== true)
|
|
168
|
+
continue;
|
|
169
|
+
if (global.capture[key] !== false)
|
|
170
|
+
continue;
|
|
171
|
+
warnings.push(`${REPO_CONFIG_NAME}: "capture.${key}" may only be narrowed by a repository file and was ignored`);
|
|
172
|
+
refused.add(key);
|
|
173
|
+
}
|
|
174
|
+
if (refused.size === 0)
|
|
175
|
+
return { value: repo, warnings };
|
|
176
|
+
return { value: { ...repo, [CAPTURE_KEY]: omitKeys(capture, refused) }, warnings };
|
|
177
|
+
}
|
|
129
178
|
/**
|
|
130
179
|
* Combine global and repo values, merging the per-field blocks.
|
|
131
180
|
*
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { AgentWatchConfig, RootedConfig, RootOverride } from './types/config.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pick the project root governing a directory.
|
|
4
|
+
*
|
|
5
|
+
* Longest match wins: a checkout nested inside a workspace overrides the
|
|
6
|
+
* workspace, which is the only ordering that lets one machine hold both.
|
|
7
|
+
* Matching is on path segments, never on the raw string, so `/dev/trip` does
|
|
8
|
+
* not claim `/dev/tripPlanner`; and on real paths, so a checkout reached
|
|
9
|
+
* through a symlink (`~/work` -> `/Volumes/dev/work`, `/tmp` -> `/private/tmp`)
|
|
10
|
+
* still lands in its tenant rather than falling through to the machine default.
|
|
11
|
+
*
|
|
12
|
+
* @param roots - Configured roots, keyed by absolute path.
|
|
13
|
+
* @param cwd - Directory the payload came from.
|
|
14
|
+
* @returns The winning root path and its overrides, or undefined.
|
|
15
|
+
*/
|
|
16
|
+
export declare function selectRoot(roots: Readonly<Record<string, RootOverride>> | undefined, cwd: string): RootedConfig['root'];
|
|
17
|
+
/**
|
|
18
|
+
* Whether this machine sends as more than one identity.
|
|
19
|
+
*
|
|
20
|
+
* The offline queue asks this before it adopts a backlog that records no
|
|
21
|
+
* identity: with a second bearer configured, an unattributed entry may belong to
|
|
22
|
+
* the other tenant, and adopting it would deliver that tenant's usage under the
|
|
23
|
+
* wrong token. Counted by distinct identities, not by the presence of a `roots`
|
|
24
|
+
* block: a root that only changes the developer email is the same identity, and
|
|
25
|
+
* so is a device credential and the install key it was exchanged for.
|
|
26
|
+
*
|
|
27
|
+
* @param config - The machine's global config, before roots are stripped.
|
|
28
|
+
* @returns True when two different identities are configured here.
|
|
29
|
+
*/
|
|
30
|
+
export declare function servesMultipleIdentities(config: AgentWatchConfig): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Apply the matching project root's identity to the global config.
|
|
33
|
+
*
|
|
34
|
+
* The `roots` block itself is stripped from the result: every consumer
|
|
35
|
+
* downstream wants one identity, and `agentwatch config` would otherwise print
|
|
36
|
+
* every other tenant's token next to the one it redacts.
|
|
37
|
+
*
|
|
38
|
+
* @param config - The machine's global config.
|
|
39
|
+
* @param cwd - Directory the payload came from.
|
|
40
|
+
* @returns The config for this directory, and the root that produced it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function applyRootOverride(config: AgentWatchConfig, cwd: string): RootedConfig;
|
|
43
|
+
/**
|
|
44
|
+
* The uninstall-marker scope of a rooted config's credential: the root's when
|
|
45
|
+
* it names a credential of its own, else the machine's, which it inherits.
|
|
46
|
+
*
|
|
47
|
+
* @param root - The root `applyRootOverride` or `selectRoot` chose, if any.
|
|
48
|
+
* @returns The root path, or undefined for the machine's.
|
|
49
|
+
*/
|
|
50
|
+
export declare function credentialScope(root: RootedConfig['root']): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The project root's config for a turn that reported an inherited checkout.
|
|
53
|
+
*
|
|
54
|
+
* A session started in no root sends as the root that claims the checkout it
|
|
55
|
+
* inherited (SPEC §3): `admission()` has already refused every checkout no root
|
|
56
|
+
* claims, and with no roots there is one tenant, so this answers undefined and
|
|
57
|
+
* the hook folder's own config stands. Never the machine default for a root.
|
|
58
|
+
*
|
|
59
|
+
* @param config - The machine's global config, roots included.
|
|
60
|
+
* @param evidence - How the turn's checkout was chosen.
|
|
61
|
+
* @param root - The reported checkout's local root.
|
|
62
|
+
* @returns The root's config, or undefined when the turn does not re-route.
|
|
63
|
+
*/
|
|
64
|
+
export declare function inheritedRootConfig(config: AgentWatchConfig, evidence: string | undefined, root: string | undefined): AgentWatchConfig | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The real, absolute form of a path — or its resolved form when it does not
|
|
67
|
+
* exist yet, which is still comparable to another path that does not exist.
|
|
68
|
+
*
|
|
69
|
+
* @param value - Path as configured or as reported by the agent.
|
|
70
|
+
* @returns The canonical path.
|
|
71
|
+
*/
|
|
72
|
+
export declare function canonicalRoot(value: string): string;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { compact, omitKeys } from '../core/object.js';
|
|
4
|
+
import { identityFingerprint, identityOf } from '../credentials/identity.js';
|
|
5
|
+
import { sameEndpoint } from './destination.js';
|
|
6
|
+
import { CREDENTIAL_KEYS, ROOT_URL_FIELDS } from './constants/config.constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pick the project root governing a directory.
|
|
9
|
+
*
|
|
10
|
+
* Longest match wins: a checkout nested inside a workspace overrides the
|
|
11
|
+
* workspace, which is the only ordering that lets one machine hold both.
|
|
12
|
+
* Matching is on path segments, never on the raw string, so `/dev/trip` does
|
|
13
|
+
* not claim `/dev/tripPlanner`; and on real paths, so a checkout reached
|
|
14
|
+
* through a symlink (`~/work` -> `/Volumes/dev/work`, `/tmp` -> `/private/tmp`)
|
|
15
|
+
* still lands in its tenant rather than falling through to the machine default.
|
|
16
|
+
*
|
|
17
|
+
* @param roots - Configured roots, keyed by absolute path.
|
|
18
|
+
* @param cwd - Directory the payload came from.
|
|
19
|
+
* @returns The winning root path and its overrides, or undefined.
|
|
20
|
+
*/
|
|
21
|
+
export function selectRoot(roots, cwd) {
|
|
22
|
+
if (!roots)
|
|
23
|
+
return undefined;
|
|
24
|
+
const target = canonicalRoot(cwd);
|
|
25
|
+
let bestKey;
|
|
26
|
+
let bestLength = -1;
|
|
27
|
+
for (const key of Object.keys(roots)) {
|
|
28
|
+
// A relative root would resolve against whatever directory the hook
|
|
29
|
+
// happened to start in, which is not a decision anyone can predict.
|
|
30
|
+
if (!path.isAbsolute(key))
|
|
31
|
+
continue;
|
|
32
|
+
const candidate = canonicalRoot(key);
|
|
33
|
+
if (!contains(candidate, target) || candidate.length <= bestLength)
|
|
34
|
+
continue;
|
|
35
|
+
bestKey = key;
|
|
36
|
+
bestLength = candidate.length;
|
|
37
|
+
}
|
|
38
|
+
if (bestKey === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
// Named as configured, so `agentwatch config` shows the root the user wrote.
|
|
41
|
+
return { path: path.resolve(bestKey), override: roots[bestKey] };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Whether this machine sends as more than one identity.
|
|
45
|
+
*
|
|
46
|
+
* The offline queue asks this before it adopts a backlog that records no
|
|
47
|
+
* identity: with a second bearer configured, an unattributed entry may belong to
|
|
48
|
+
* the other tenant, and adopting it would deliver that tenant's usage under the
|
|
49
|
+
* wrong token. Counted by distinct identities, not by the presence of a `roots`
|
|
50
|
+
* block: a root that only changes the developer email is the same identity, and
|
|
51
|
+
* so is a device credential and the install key it was exchanged for.
|
|
52
|
+
*
|
|
53
|
+
* @param config - The machine's global config, before roots are stripped.
|
|
54
|
+
* @returns True when two different identities are configured here.
|
|
55
|
+
*/
|
|
56
|
+
export function servesMultipleIdentities(config) {
|
|
57
|
+
const identities = new Set();
|
|
58
|
+
for (const entry of [config, ...Object.values(config.roots ?? {})]) {
|
|
59
|
+
const identity = identityOf(entry);
|
|
60
|
+
if (identity)
|
|
61
|
+
identities.add(identityFingerprint(identity));
|
|
62
|
+
}
|
|
63
|
+
return identities.size > 1;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Apply the matching project root's identity to the global config.
|
|
67
|
+
*
|
|
68
|
+
* The `roots` block itself is stripped from the result: every consumer
|
|
69
|
+
* downstream wants one identity, and `agentwatch config` would otherwise print
|
|
70
|
+
* every other tenant's token next to the one it redacts.
|
|
71
|
+
*
|
|
72
|
+
* @param config - The machine's global config.
|
|
73
|
+
* @param cwd - Directory the payload came from.
|
|
74
|
+
* @returns The config for this directory, and the root that produced it.
|
|
75
|
+
*/
|
|
76
|
+
export function applyRootOverride(config, cwd) {
|
|
77
|
+
const selected = selectRoot(config.roots, cwd);
|
|
78
|
+
const { roots: _roots, ...withoutRoots } = config;
|
|
79
|
+
if (!selected)
|
|
80
|
+
return { config: withoutRoots };
|
|
81
|
+
// Undefined-valued keys in the override would erase the global value, so
|
|
82
|
+
// only the keys actually present are laid over it. A root naming a credential
|
|
83
|
+
// of either kind replaces the machine's of both kinds: an install key next to
|
|
84
|
+
// the machine's device reference would otherwise leave two identities in one
|
|
85
|
+
// config, and the wrong one could win.
|
|
86
|
+
const ownCredential = selected.override.token !== undefined || selected.override.device !== undefined;
|
|
87
|
+
const base = ownCredential ? omitKeys(withoutRoots, CREDENTIAL_KEYS) : withoutRoots;
|
|
88
|
+
return { config: { ...withoutDestination(base, selected.override), ...compact(selected.override) }, root: selected };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The uninstall-marker scope of a rooted config's credential: the root's when
|
|
92
|
+
* it names a credential of its own, else the machine's, which it inherits.
|
|
93
|
+
*
|
|
94
|
+
* @param root - The root `applyRootOverride` or `selectRoot` chose, if any.
|
|
95
|
+
* @returns The root path, or undefined for the machine's.
|
|
96
|
+
*/
|
|
97
|
+
export function credentialScope(root) {
|
|
98
|
+
if (!root || (root.override.token === undefined && root.override.device === undefined))
|
|
99
|
+
return undefined;
|
|
100
|
+
return root.path;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The project root's config for a turn that reported an inherited checkout.
|
|
104
|
+
*
|
|
105
|
+
* A session started in no root sends as the root that claims the checkout it
|
|
106
|
+
* inherited (SPEC §3): `admission()` has already refused every checkout no root
|
|
107
|
+
* claims, and with no roots there is one tenant, so this answers undefined and
|
|
108
|
+
* the hook folder's own config stands. Never the machine default for a root.
|
|
109
|
+
*
|
|
110
|
+
* @param config - The machine's global config, roots included.
|
|
111
|
+
* @param evidence - How the turn's checkout was chosen.
|
|
112
|
+
* @param root - The reported checkout's local root.
|
|
113
|
+
* @returns The root's config, or undefined when the turn does not re-route.
|
|
114
|
+
*/
|
|
115
|
+
export function inheritedRootConfig(config, evidence, root) {
|
|
116
|
+
if (evidence !== 'inherited' || root === undefined || selectRoot(config.roots, root) === undefined)
|
|
117
|
+
return undefined;
|
|
118
|
+
return applyRootOverride(config, root).config;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A root shares telemetry routes only when it names no different destination.
|
|
122
|
+
* Refusal never establishes sharing. Route-only roots retain the machine base
|
|
123
|
+
* for enforcement, but cannot derive an unnamed telemetry route from it.
|
|
124
|
+
* A root with its own base derives enforcement there instead of leaking its
|
|
125
|
+
* bearer to an explicit machine enforcement service.
|
|
126
|
+
*/
|
|
127
|
+
function withoutDestination(config, override) {
|
|
128
|
+
const named = ROOT_URL_FIELDS.some((field) => {
|
|
129
|
+
const key = field;
|
|
130
|
+
const value = override[key];
|
|
131
|
+
if (value === undefined)
|
|
132
|
+
return false;
|
|
133
|
+
if (key === 'endpoint')
|
|
134
|
+
return !sameEndpoint(override.endpoint, config.endpoint);
|
|
135
|
+
return value === null || value !== config[key];
|
|
136
|
+
});
|
|
137
|
+
if (!named)
|
|
138
|
+
return config;
|
|
139
|
+
const ownBase = override.endpoint !== undefined;
|
|
140
|
+
const route = ownBase ? undefined : null;
|
|
141
|
+
return { ...config, eventsUrl: route, otlpUrl: route, enforcementUrl: ownBase && !sameEndpoint(override.endpoint, config.endpoint) ? undefined : config.enforcementUrl };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The real, absolute form of a path — or its resolved form when it does not
|
|
145
|
+
* exist yet, which is still comparable to another path that does not exist.
|
|
146
|
+
*
|
|
147
|
+
* @param value - Path as configured or as reported by the agent.
|
|
148
|
+
* @returns The canonical path.
|
|
149
|
+
*/
|
|
150
|
+
export function canonicalRoot(value) {
|
|
151
|
+
try {
|
|
152
|
+
return fs.realpathSync.native(value);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return path.resolve(value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether a directory is at or beneath a root.
|
|
160
|
+
*
|
|
161
|
+
* @param root - Resolved candidate root.
|
|
162
|
+
* @param target - Resolved directory under test.
|
|
163
|
+
* @returns True when target is the root or inside it.
|
|
164
|
+
*/
|
|
165
|
+
function contains(root, target) {
|
|
166
|
+
if (target === root)
|
|
167
|
+
return true;
|
|
168
|
+
const prefix = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
|
|
169
|
+
return target.startsWith(prefix);
|
|
170
|
+
}
|