@guilz-dev/belay 0.1.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/LICENSE +21 -0
- package/README.md +268 -0
- package/agent-belay-logo.png +0 -0
- package/dist/adapters/claude/adapter.d.ts +7 -0
- package/dist/adapters/claude/adapter.js +114 -0
- package/dist/adapters/claude/hooks.d.ts +13 -0
- package/dist/adapters/claude/hooks.js +49 -0
- package/dist/adapters/claude/runtime-entry.d.ts +4 -0
- package/dist/adapters/claude/runtime-entry.js +260 -0
- package/dist/adapters/codex/adapter.d.ts +7 -0
- package/dist/adapters/codex/adapter.js +73 -0
- package/dist/adapters/codex/hooks.d.ts +21 -0
- package/dist/adapters/codex/hooks.js +78 -0
- package/dist/adapters/codex/runtime-entry.d.ts +4 -0
- package/dist/adapters/codex/runtime-entry.js +237 -0
- package/dist/adapters/cursor/adapter.d.ts +7 -0
- package/dist/adapters/cursor/adapter.js +29 -0
- package/dist/adapters/cursor/hooks.d.ts +2 -0
- package/dist/adapters/cursor/hooks.js +26 -0
- package/dist/adapters/cursor/runtime-entry.d.ts +4 -0
- package/dist/adapters/cursor/runtime-entry.js +143 -0
- package/dist/adapters/layouts/claude.d.ts +2 -0
- package/dist/adapters/layouts/claude.js +40 -0
- package/dist/adapters/layouts/codex.d.ts +2 -0
- package/dist/adapters/layouts/codex.js +43 -0
- package/dist/adapters/layouts/cursor.d.ts +2 -0
- package/dist/adapters/layouts/cursor.js +40 -0
- package/dist/adapters/layouts/index.d.ts +7 -0
- package/dist/adapters/layouts/index.js +23 -0
- package/dist/adapters/layouts/protected-paths.d.ts +3 -0
- package/dist/adapters/layouts/protected-paths.js +15 -0
- package/dist/adapters/layouts/scope.d.ts +19 -0
- package/dist/adapters/layouts/scope.js +86 -0
- package/dist/adapters/layouts/types.d.ts +14 -0
- package/dist/adapters/layouts/types.js +1 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +14 -0
- package/dist/adapters/shared/gate-runtime.d.ts +51 -0
- package/dist/adapters/shared/gate-runtime.js +518 -0
- package/dist/adapters/shared/repo-root.d.ts +2 -0
- package/dist/adapters/shared/repo-root.js +17 -0
- package/dist/adapters/types.d.ts +19 -0
- package/dist/adapters/types.js +1 -0
- package/dist/branding.d.ts +3 -0
- package/dist/branding.js +3 -0
- package/dist/bundle/claude-runtime.mjs +5323 -0
- package/dist/bundle/codex-runtime.mjs +5310 -0
- package/dist/bundle/cursor-runtime.mjs +5208 -0
- package/dist/cleanup-orphans.d.ts +7 -0
- package/dist/cleanup-orphans.js +59 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +631 -0
- package/dist/commands/approve.d.ts +14 -0
- package/dist/commands/approve.js +65 -0
- package/dist/commands/audit.d.ts +59 -0
- package/dist/commands/audit.js +132 -0
- package/dist/commands/classify-for-report.d.ts +9 -0
- package/dist/commands/classify-for-report.js +85 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +366 -0
- package/dist/commands/dogfood.d.ts +5 -0
- package/dist/commands/dogfood.js +71 -0
- package/dist/commands/explain.d.ts +3 -0
- package/dist/commands/explain.js +133 -0
- package/dist/commands/health-snapshot.d.ts +2 -0
- package/dist/commands/health-snapshot.js +166 -0
- package/dist/commands/init-wizard.d.ts +16 -0
- package/dist/commands/init-wizard.js +50 -0
- package/dist/commands/metrics.d.ts +7 -0
- package/dist/commands/metrics.js +89 -0
- package/dist/commands/recover.d.ts +3 -0
- package/dist/commands/recover.js +105 -0
- package/dist/commands/report.d.ts +3 -0
- package/dist/commands/report.js +65 -0
- package/dist/commands/revoke.d.ts +5 -0
- package/dist/commands/revoke.js +22 -0
- package/dist/commands/simulate.d.ts +14 -0
- package/dist/commands/simulate.js +55 -0
- package/dist/commands/status.d.ts +5 -0
- package/dist/commands/status.js +107 -0
- package/dist/config-io.d.ts +23 -0
- package/dist/config-io.js +180 -0
- package/dist/conformance/guarantee-table.d.ts +14 -0
- package/dist/conformance/guarantee-table.js +95 -0
- package/dist/conformance/types.d.ts +6 -0
- package/dist/conformance/types.js +1 -0
- package/dist/core/approval-service.d.ts +26 -0
- package/dist/core/approval-service.js +41 -0
- package/dist/core/approval-token.d.ts +11 -0
- package/dist/core/approval-token.js +61 -0
- package/dist/core/approval.d.ts +19 -0
- package/dist/core/approval.js +58 -0
- package/dist/core/audit-analysis.d.ts +10 -0
- package/dist/core/audit-analysis.js +147 -0
- package/dist/core/audit-metrics.d.ts +51 -0
- package/dist/core/audit-metrics.js +155 -0
- package/dist/core/audit-query.d.ts +11 -0
- package/dist/core/audit-query.js +142 -0
- package/dist/core/audit-summary.d.ts +33 -0
- package/dist/core/audit-summary.js +111 -0
- package/dist/core/audit-types.d.ts +65 -0
- package/dist/core/audit-types.js +2 -0
- package/dist/core/capability/allowlist.d.ts +10 -0
- package/dist/core/capability/allowlist.js +53 -0
- package/dist/core/capability/broker.d.ts +17 -0
- package/dist/core/capability/broker.js +29 -0
- package/dist/core/capability/index.d.ts +5 -0
- package/dist/core/capability/index.js +4 -0
- package/dist/core/capability/paths.d.ts +1 -0
- package/dist/core/capability/paths.js +20 -0
- package/dist/core/capability/reasons.d.ts +2 -0
- package/dist/core/capability/reasons.js +4 -0
- package/dist/core/capability/types.d.ts +10 -0
- package/dist/core/capability/types.js +1 -0
- package/dist/core/capability-approval.d.ts +28 -0
- package/dist/core/capability-approval.js +43 -0
- package/dist/core/classify-subagent.d.ts +2 -0
- package/dist/core/classify-subagent.js +69 -0
- package/dist/core/classify-tool.d.ts +3 -0
- package/dist/core/classify-tool.js +311 -0
- package/dist/core/config-layers.d.ts +23 -0
- package/dist/core/config-layers.js +59 -0
- package/dist/core/config.d.ts +219 -0
- package/dist/core/config.js +720 -0
- package/dist/core/control-plane-isolation.d.ts +10 -0
- package/dist/core/control-plane-isolation.js +83 -0
- package/dist/core/custom-command-match.d.ts +2 -0
- package/dist/core/custom-command-match.js +8 -0
- package/dist/core/egress/allowlist.d.ts +7 -0
- package/dist/core/egress/allowlist.js +33 -0
- package/dist/core/egress/env.d.ts +3 -0
- package/dist/core/egress/env.js +17 -0
- package/dist/core/egress/fingerprint.d.ts +3 -0
- package/dist/core/egress/fingerprint.js +35 -0
- package/dist/core/egress/policy.d.ts +8 -0
- package/dist/core/egress/policy.js +47 -0
- package/dist/core/egress/proxy-server.d.ts +21 -0
- package/dist/core/egress/proxy-server.js +263 -0
- package/dist/core/egress/types.d.ts +25 -0
- package/dist/core/egress/types.js +1 -0
- package/dist/core/egress-approval.d.ts +48 -0
- package/dist/core/egress-approval.js +129 -0
- package/dist/core/fingerprint.d.ts +6 -0
- package/dist/core/fingerprint.js +24 -0
- package/dist/core/gate-contract.d.ts +48 -0
- package/dist/core/gate-contract.js +50 -0
- package/dist/core/gate-engine.d.ts +20 -0
- package/dist/core/gate-engine.js +172 -0
- package/dist/core/glob.d.ts +1 -0
- package/dist/core/glob.js +39 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.js +15 -0
- package/dist/core/integrity.d.ts +15 -0
- package/dist/core/integrity.js +68 -0
- package/dist/core/judge-api-key.d.ts +4 -0
- package/dist/core/judge-api-key.js +11 -0
- package/dist/core/judge-config.d.ts +29 -0
- package/dist/core/judge-config.js +85 -0
- package/dist/core/judge-doctor.d.ts +7 -0
- package/dist/core/judge-doctor.js +124 -0
- package/dist/core/judgment.d.ts +6 -0
- package/dist/core/judgment.js +38 -0
- package/dist/core/notify.d.ts +13 -0
- package/dist/core/notify.js +44 -0
- package/dist/core/path-utils.d.ts +12 -0
- package/dist/core/path-utils.js +107 -0
- package/dist/core/reclassify.d.ts +15 -0
- package/dist/core/reclassify.js +82 -0
- package/dist/core/recover-advice.d.ts +30 -0
- package/dist/core/recover-advice.js +177 -0
- package/dist/core/recover-git-probe.d.ts +8 -0
- package/dist/core/recover-git-probe.js +50 -0
- package/dist/core/recover-select.d.ts +10 -0
- package/dist/core/recover-select.js +60 -0
- package/dist/core/scrub.d.ts +3 -0
- package/dist/core/scrub.js +87 -0
- package/dist/core/shell-substitution.d.ts +6 -0
- package/dist/core/shell-substitution.js +130 -0
- package/dist/core/shell-tokenizer.d.ts +5 -0
- package/dist/core/shell-tokenizer.js +129 -0
- package/dist/core/shell-unparseable.d.ts +4 -0
- package/dist/core/shell-unparseable.js +96 -0
- package/dist/core/transactional/diff-evaluator.d.ts +2 -0
- package/dist/core/transactional/diff-evaluator.js +84 -0
- package/dist/core/transactional/eligibility.d.ts +4 -0
- package/dist/core/transactional/eligibility.js +44 -0
- package/dist/core/transactional/git-worktree.d.ts +13 -0
- package/dist/core/transactional/git-worktree.js +189 -0
- package/dist/core/transactional/index.d.ts +5 -0
- package/dist/core/transactional/index.js +4 -0
- package/dist/core/transactional/reasons.d.ts +4 -0
- package/dist/core/transactional/reasons.js +8 -0
- package/dist/core/transactional/runner.d.ts +2 -0
- package/dist/core/transactional/runner.js +113 -0
- package/dist/core/transactional/types.d.ts +46 -0
- package/dist/core/transactional/types.js +1 -0
- package/dist/core/types.d.ts +90 -0
- package/dist/core/types.js +1 -0
- package/dist/core/v2/adapter.d.ts +14 -0
- package/dist/core/v2/adapter.js +118 -0
- package/dist/core/v2/containment.d.ts +19 -0
- package/dist/core/v2/containment.js +91 -0
- package/dist/core/v2/egress-classify.d.ts +7 -0
- package/dist/core/v2/egress-classify.js +216 -0
- package/dist/core/v2/fingerprint.d.ts +1 -0
- package/dist/core/v2/fingerprint.js +4 -0
- package/dist/core/v2/index.d.ts +12 -0
- package/dist/core/v2/index.js +10 -0
- package/dist/core/v2/judge-audit.d.ts +2 -0
- package/dist/core/v2/judge-audit.js +15 -0
- package/dist/core/v2/judge-factory.d.ts +25 -0
- package/dist/core/v2/judge-factory.js +75 -0
- package/dist/core/v2/judge-outbound.d.ts +12 -0
- package/dist/core/v2/judge-outbound.js +73 -0
- package/dist/core/v2/judge.d.ts +47 -0
- package/dist/core/v2/judge.js +264 -0
- package/dist/core/v2/launcher-resolve.d.ts +12 -0
- package/dist/core/v2/launcher-resolve.js +190 -0
- package/dist/core/v2/overrides.d.ts +7 -0
- package/dist/core/v2/overrides.js +37 -0
- package/dist/core/v2/parser.d.ts +21 -0
- package/dist/core/v2/parser.js +213 -0
- package/dist/core/v2/types.d.ts +67 -0
- package/dist/core/v2/types.js +1 -0
- package/dist/core/v2/verdict.d.ts +2 -0
- package/dist/core/v2/verdict.js +699 -0
- package/dist/corpus/evaluate.d.ts +24 -0
- package/dist/corpus/evaluate.js +69 -0
- package/dist/defaults.d.ts +18 -0
- package/dist/defaults.js +155 -0
- package/dist/egress-daemon.d.ts +1 -0
- package/dist/egress-daemon.js +52 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +15 -0
- package/dist/installer/bootstrap.d.ts +5 -0
- package/dist/installer/bootstrap.js +61 -0
- package/dist/installer/runtime-artifacts.d.ts +3 -0
- package/dist/installer/runtime-artifacts.js +23 -0
- package/dist/installer/scope-config.d.ts +8 -0
- package/dist/installer/scope-config.js +25 -0
- package/dist/installer.d.ts +22 -0
- package/dist/installer.js +169 -0
- package/dist/node-resolution.d.ts +8 -0
- package/dist/node-resolution.js +237 -0
- package/dist/operational-insights.d.ts +19 -0
- package/dist/operational-insights.js +24 -0
- package/dist/presets.d.ts +4 -0
- package/dist/presets.js +95 -0
- package/dist/services/egress-service.d.ts +57 -0
- package/dist/services/egress-service.js +334 -0
- package/dist/services/sandbox-service.d.ts +38 -0
- package/dist/services/sandbox-service.js +95 -0
- package/dist/templates.d.ts +7 -0
- package/dist/templates.js +56 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +65 -0
- package/skills/belay/SKILL.md +52 -0
- package/skills/belay/belay-approve.md +7 -0
- package/skills/belay/belay-explain.md +11 -0
- package/skills/belay/belay-recover.md +13 -0
- package/skills/belay/belay-report.md +7 -0
- package/skills/belay/belay-status.md +9 -0
- package/skills/belay/belay-why.md +11 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
export const DEFAULT_JUDGE_LOCAL_OLLAMA = {
|
|
3
|
+
provider: 'ollama',
|
|
4
|
+
model: 'gemma4:e2b',
|
|
5
|
+
endpoint: 'http://localhost:11434',
|
|
6
|
+
timeoutMs: 25000,
|
|
7
|
+
keepAlive: '30m',
|
|
8
|
+
};
|
|
9
|
+
export const DEFAULT_JUDGE_OPENAI_COMPATIBLE_TEMPLATE = {
|
|
10
|
+
provider: 'openai-compatible',
|
|
11
|
+
model: 'auto',
|
|
12
|
+
timeoutMs: 8000,
|
|
13
|
+
endpoint: null,
|
|
14
|
+
keepAlive: null,
|
|
15
|
+
};
|
|
16
|
+
/** @deprecated Use DEFAULT_JUDGE_OPENAI_COMPATIBLE_TEMPLATE */
|
|
17
|
+
export const DEFAULT_JUDGE_CURSOR_COMPOSER = DEFAULT_JUDGE_OPENAI_COMPATIBLE_TEMPLATE;
|
|
18
|
+
/** Pre-v0.4 defaults preserved when migrating existing v1/v2/v3 configs. */
|
|
19
|
+
import { DEFAULT_SILENT_PASS_THRESHOLD } from './audit-summary.js';
|
|
20
|
+
/** @deprecated Use DEFAULT_SILENT_PASS_THRESHOLD from audit-summary.js */
|
|
21
|
+
export const DEFAULT_FENCE_WARN_THRESHOLD = DEFAULT_SILENT_PASS_THRESHOLD;
|
|
22
|
+
export const DEFAULT_CONFIDENCE_THRESHOLDS = {
|
|
23
|
+
allow: 0.88,
|
|
24
|
+
flag: 0.72,
|
|
25
|
+
};
|
|
26
|
+
export const DEFAULT_MODEL_ASSIST = {
|
|
27
|
+
enabled: false,
|
|
28
|
+
timeoutMs: 3000,
|
|
29
|
+
};
|
|
30
|
+
export const DEFAULT_TRANSACTIONAL_V3 = {
|
|
31
|
+
enabled: false,
|
|
32
|
+
minConfidence: DEFAULT_CONFIDENCE_THRESHOLDS.flag,
|
|
33
|
+
maxConfidence: DEFAULT_CONFIDENCE_THRESHOLDS.allow,
|
|
34
|
+
timeoutMs: 30_000,
|
|
35
|
+
maxDeletionCount: 10,
|
|
36
|
+
gates: {
|
|
37
|
+
shell: true,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const LEGACY_POLICY_V3 = {
|
|
41
|
+
unknownLocalEffect: 'allow_flagged',
|
|
42
|
+
unparseableShell: 'allow_flagged',
|
|
43
|
+
confidenceThresholds: { ...DEFAULT_CONFIDENCE_THRESHOLDS },
|
|
44
|
+
modelAssist: { ...DEFAULT_MODEL_ASSIST },
|
|
45
|
+
transactional: { ...DEFAULT_TRANSACTIONAL_V3 },
|
|
46
|
+
fenceWarnThreshold: DEFAULT_FENCE_WARN_THRESHOLD,
|
|
47
|
+
};
|
|
48
|
+
/** Fresh v0.4+ install defaults (fail-closed). */
|
|
49
|
+
export const DEFAULT_POLICY_V3 = {
|
|
50
|
+
unknownLocalEffect: 'deny',
|
|
51
|
+
unparseableShell: 'deny',
|
|
52
|
+
codexUnmappedTool: 'deny',
|
|
53
|
+
confidenceThresholds: { ...DEFAULT_CONFIDENCE_THRESHOLDS },
|
|
54
|
+
modelAssist: { ...DEFAULT_MODEL_ASSIST },
|
|
55
|
+
transactional: { ...DEFAULT_TRANSACTIONAL_V3 },
|
|
56
|
+
fenceWarnThreshold: DEFAULT_FENCE_WARN_THRESHOLD,
|
|
57
|
+
};
|
|
58
|
+
export const DEFAULT_OVERRIDES_V3 = {
|
|
59
|
+
allow: [],
|
|
60
|
+
external: [],
|
|
61
|
+
};
|
|
62
|
+
export const DEFAULT_REDACTION_V3 = {
|
|
63
|
+
maskApprovalIds: true,
|
|
64
|
+
maskBearerTokens: true,
|
|
65
|
+
maskAuthHeaders: true,
|
|
66
|
+
maskKeyValueSecrets: true,
|
|
67
|
+
maskHighEntropyStrings: true,
|
|
68
|
+
};
|
|
69
|
+
export const DEFAULT_CONTROL_PLANE_ISOLATION_V3 = {
|
|
70
|
+
mode: 'none',
|
|
71
|
+
verifyAgentWritable: true,
|
|
72
|
+
};
|
|
73
|
+
export const LEGACY_CONTROL_PLANE_V3 = {
|
|
74
|
+
enabled: false,
|
|
75
|
+
configDir: null,
|
|
76
|
+
integrity: 'none',
|
|
77
|
+
isolation: { ...DEFAULT_CONTROL_PLANE_ISOLATION_V3 },
|
|
78
|
+
};
|
|
79
|
+
export const DEFAULT_CONTROL_PLANE_V3 = {
|
|
80
|
+
enabled: true,
|
|
81
|
+
configDir: null,
|
|
82
|
+
integrity: 'hash-pinned',
|
|
83
|
+
isolation: { ...DEFAULT_CONTROL_PLANE_ISOLATION_V3 },
|
|
84
|
+
};
|
|
85
|
+
export const DEFAULT_SANDBOX_V3 = {
|
|
86
|
+
enabled: false,
|
|
87
|
+
runtime: 'none',
|
|
88
|
+
denyNetworkByDefault: true,
|
|
89
|
+
};
|
|
90
|
+
export const DEFAULT_NOTIFICATIONS_V3 = {};
|
|
91
|
+
export const DEFAULT_APPROVAL_SIGNING_V3 = {
|
|
92
|
+
required: false,
|
|
93
|
+
};
|
|
94
|
+
export const DEFAULT_EGRESS_V3 = {
|
|
95
|
+
enabled: false,
|
|
96
|
+
listenHost: '127.0.0.1',
|
|
97
|
+
listenPort: 17831,
|
|
98
|
+
demoteL3External: true,
|
|
99
|
+
};
|
|
100
|
+
const LOOPBACK_EGRESS_HOSTS = new Set(['127.0.0.1', 'localhost', '::1']);
|
|
101
|
+
export function normalizeEgressListenHost(host) {
|
|
102
|
+
const trimmed = host.trim();
|
|
103
|
+
const lowered = trimmed.toLowerCase();
|
|
104
|
+
if (LOOPBACK_EGRESS_HOSTS.has(lowered)) {
|
|
105
|
+
return lowered === 'localhost' ? '127.0.0.1' : trimmed;
|
|
106
|
+
}
|
|
107
|
+
return DEFAULT_EGRESS_V3.listenHost;
|
|
108
|
+
}
|
|
109
|
+
export const DEFAULT_CONFIG_V2 = {
|
|
110
|
+
version: 2,
|
|
111
|
+
mode: 'enforce',
|
|
112
|
+
approvalTtlMinutes: 15,
|
|
113
|
+
tokenPrefix: '/belay-approve',
|
|
114
|
+
gates: {
|
|
115
|
+
shell: true,
|
|
116
|
+
subagent: true,
|
|
117
|
+
fileMutation: true,
|
|
118
|
+
toolShell: true,
|
|
119
|
+
},
|
|
120
|
+
classifier: {
|
|
121
|
+
strictChains: true,
|
|
122
|
+
customExternalCommands: [],
|
|
123
|
+
customAllowCommands: [],
|
|
124
|
+
sensitivePaths: ['.env', '.env.*', '**/credentials/**'],
|
|
125
|
+
},
|
|
126
|
+
audit: {
|
|
127
|
+
logPath: 'belay/audit.ndjson',
|
|
128
|
+
includeAssessment: true,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
export const DEFAULT_CONFIG_V4 = {
|
|
132
|
+
version: 4,
|
|
133
|
+
mode: DEFAULT_CONFIG_V2.mode,
|
|
134
|
+
approvalTtlMinutes: DEFAULT_CONFIG_V2.approvalTtlMinutes,
|
|
135
|
+
tokenPrefix: DEFAULT_CONFIG_V2.tokenPrefix,
|
|
136
|
+
gates: { ...DEFAULT_CONFIG_V2.gates },
|
|
137
|
+
classifier: {
|
|
138
|
+
strictChains: DEFAULT_CONFIG_V2.classifier.strictChains,
|
|
139
|
+
sensitivePaths: [...DEFAULT_CONFIG_V2.classifier.sensitivePaths],
|
|
140
|
+
},
|
|
141
|
+
policy: { ...DEFAULT_POLICY_V3 },
|
|
142
|
+
overrides: { ...DEFAULT_OVERRIDES_V3 },
|
|
143
|
+
redaction: { ...DEFAULT_REDACTION_V3 },
|
|
144
|
+
controlPlane: { ...DEFAULT_CONTROL_PLANE_V3 },
|
|
145
|
+
notifications: { ...DEFAULT_NOTIFICATIONS_V3 },
|
|
146
|
+
approvalSigning: { ...DEFAULT_APPROVAL_SIGNING_V3 },
|
|
147
|
+
egress: { ...DEFAULT_EGRESS_V3 },
|
|
148
|
+
sandbox: { ...DEFAULT_SANDBOX_V3 },
|
|
149
|
+
audit: { ...DEFAULT_CONFIG_V2.audit },
|
|
150
|
+
judge: { ...DEFAULT_JUDGE_LOCAL_OLLAMA },
|
|
151
|
+
};
|
|
152
|
+
/** @deprecated Use DEFAULT_CONFIG_V4 */
|
|
153
|
+
export const DEFAULT_CONFIG_V3 = DEFAULT_CONFIG_V4;
|
|
154
|
+
function uniqueStrings(values) {
|
|
155
|
+
return [...new Set(values)];
|
|
156
|
+
}
|
|
157
|
+
function mergeOverrideLists(primary, secondary) {
|
|
158
|
+
return uniqueStrings([...primary, ...secondary]);
|
|
159
|
+
}
|
|
160
|
+
export function mapLegacyClassifierToOverrides(classifier) {
|
|
161
|
+
return {
|
|
162
|
+
allow: Array.isArray(classifier.customAllowCommands) ? classifier.customAllowCommands : [],
|
|
163
|
+
external: Array.isArray(classifier.customExternalCommands)
|
|
164
|
+
? classifier.customExternalCommands
|
|
165
|
+
: [],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export function migrateV2ToV3(v2, rawOverrides) {
|
|
169
|
+
const legacyOverrides = mapLegacyClassifierToOverrides(v2.classifier);
|
|
170
|
+
return normalizeConfig({
|
|
171
|
+
version: 4,
|
|
172
|
+
mode: v2.mode,
|
|
173
|
+
approvalTtlMinutes: v2.approvalTtlMinutes,
|
|
174
|
+
tokenPrefix: v2.tokenPrefix,
|
|
175
|
+
gates: v2.gates,
|
|
176
|
+
classifier: {
|
|
177
|
+
strictChains: v2.classifier.strictChains,
|
|
178
|
+
sensitivePaths: v2.classifier.sensitivePaths,
|
|
179
|
+
},
|
|
180
|
+
policy: { ...LEGACY_POLICY_V3 },
|
|
181
|
+
overrides: {
|
|
182
|
+
allow: mergeOverrideLists(rawOverrides?.allow ?? [], legacyOverrides.allow),
|
|
183
|
+
external: mergeOverrideLists(rawOverrides?.external ?? [], legacyOverrides.external),
|
|
184
|
+
},
|
|
185
|
+
redaction: { ...DEFAULT_REDACTION_V3 },
|
|
186
|
+
controlPlane: { ...LEGACY_CONTROL_PLANE_V3 },
|
|
187
|
+
notifications: { ...DEFAULT_NOTIFICATIONS_V3 },
|
|
188
|
+
approvalSigning: { ...DEFAULT_APPROVAL_SIGNING_V3 },
|
|
189
|
+
egress: { ...DEFAULT_EGRESS_V3 },
|
|
190
|
+
sandbox: { ...DEFAULT_SANDBOX_V3 },
|
|
191
|
+
audit: v2.audit,
|
|
192
|
+
judge: { ...DEFAULT_JUDGE_LOCAL_OLLAMA },
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export function isConfigV1(value) {
|
|
196
|
+
return typeof value === 'object' && value !== null && value.version === 1;
|
|
197
|
+
}
|
|
198
|
+
export function isConfigV2(value) {
|
|
199
|
+
return typeof value === 'object' && value !== null && value.version === 2;
|
|
200
|
+
}
|
|
201
|
+
export function isConfigV3(value) {
|
|
202
|
+
if (typeof value !== 'object' || value === null) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const version = value.version;
|
|
206
|
+
return version === 3 || version === 4;
|
|
207
|
+
}
|
|
208
|
+
export function isConfigV4(value) {
|
|
209
|
+
return typeof value === 'object' && value !== null && value.version === 4;
|
|
210
|
+
}
|
|
211
|
+
export function normalizeJudgeProvider(provider) {
|
|
212
|
+
if (provider === 'openai-compatible' || provider === 'cursor') {
|
|
213
|
+
return 'openai-compatible';
|
|
214
|
+
}
|
|
215
|
+
return 'ollama';
|
|
216
|
+
}
|
|
217
|
+
function synthesizeJudgeFromRaw(raw) {
|
|
218
|
+
const judge = raw.judge;
|
|
219
|
+
if (judge?.provider) {
|
|
220
|
+
const provider = normalizeJudgeProvider(judge.provider);
|
|
221
|
+
const base = provider === 'openai-compatible'
|
|
222
|
+
? DEFAULT_JUDGE_OPENAI_COMPATIBLE_TEMPLATE
|
|
223
|
+
: DEFAULT_JUDGE_LOCAL_OLLAMA;
|
|
224
|
+
return normalizeJudgeConfig({
|
|
225
|
+
...base,
|
|
226
|
+
...judge,
|
|
227
|
+
provider,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return { ...DEFAULT_JUDGE_LOCAL_OLLAMA };
|
|
231
|
+
}
|
|
232
|
+
export function normalizeJudgeConfig(judge) {
|
|
233
|
+
const provider = normalizeJudgeProvider(judge.provider);
|
|
234
|
+
const base = provider === 'openai-compatible'
|
|
235
|
+
? DEFAULT_JUDGE_OPENAI_COMPATIBLE_TEMPLATE
|
|
236
|
+
: DEFAULT_JUDGE_LOCAL_OLLAMA;
|
|
237
|
+
const model = typeof judge.model === 'string' && judge.model.trim() ? judge.model.trim() : base.model;
|
|
238
|
+
const timeoutMs = typeof judge.timeoutMs === 'number' && judge.timeoutMs > 0 ? judge.timeoutMs : base.timeoutMs;
|
|
239
|
+
return {
|
|
240
|
+
provider,
|
|
241
|
+
model,
|
|
242
|
+
timeoutMs,
|
|
243
|
+
endpoint: typeof judge.endpoint === 'string' && judge.endpoint.trim() ? judge.endpoint.trim() : null,
|
|
244
|
+
keepAlive: provider === 'ollama' && typeof judge.keepAlive === 'string' && judge.keepAlive.trim()
|
|
245
|
+
? judge.keepAlive.trim()
|
|
246
|
+
: provider === 'ollama'
|
|
247
|
+
? DEFAULT_JUDGE_LOCAL_OLLAMA.keepAlive
|
|
248
|
+
: null,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
export function migrateV3ToV4(v3, raw) {
|
|
252
|
+
return normalizeConfig({
|
|
253
|
+
...v3,
|
|
254
|
+
version: 4,
|
|
255
|
+
judge: synthesizeJudgeFromRaw({ ...(raw ?? {}), judge: raw?.judge ?? v3.judge }),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function hasV3Sections(raw) {
|
|
259
|
+
return (raw.policy !== undefined ||
|
|
260
|
+
raw.overrides !== undefined ||
|
|
261
|
+
raw.redaction !== undefined ||
|
|
262
|
+
raw.controlPlane !== undefined);
|
|
263
|
+
}
|
|
264
|
+
function looksLikeV2Config(raw) {
|
|
265
|
+
return (raw.gates?.fileMutation !== undefined ||
|
|
266
|
+
raw.gates?.toolShell !== undefined ||
|
|
267
|
+
raw.classifier?.customAllowCommands !== undefined ||
|
|
268
|
+
raw.classifier?.customExternalCommands !== undefined ||
|
|
269
|
+
raw.audit?.includeAssessment !== undefined);
|
|
270
|
+
}
|
|
271
|
+
function mergeV3FromRaw(base, raw) {
|
|
272
|
+
return normalizeConfig({
|
|
273
|
+
...base,
|
|
274
|
+
judge: raw.judge ? { ...base.judge, ...raw.judge } : base.judge,
|
|
275
|
+
policy: {
|
|
276
|
+
...base.policy,
|
|
277
|
+
...(raw.policy ?? {}),
|
|
278
|
+
},
|
|
279
|
+
overrides: {
|
|
280
|
+
allow: mergeOverrideLists(base.overrides.allow, raw.overrides?.allow ?? []),
|
|
281
|
+
external: mergeOverrideLists(base.overrides.external, raw.overrides?.external ?? []),
|
|
282
|
+
},
|
|
283
|
+
redaction: {
|
|
284
|
+
...base.redaction,
|
|
285
|
+
...(raw.redaction ?? {}),
|
|
286
|
+
},
|
|
287
|
+
controlPlane: {
|
|
288
|
+
...base.controlPlane,
|
|
289
|
+
...(raw.controlPlane ?? {}),
|
|
290
|
+
},
|
|
291
|
+
notifications: {
|
|
292
|
+
...base.notifications,
|
|
293
|
+
...(raw.notifications ?? {}),
|
|
294
|
+
},
|
|
295
|
+
approvalSigning: {
|
|
296
|
+
...base.approvalSigning,
|
|
297
|
+
...(raw.approvalSigning ?? {}),
|
|
298
|
+
},
|
|
299
|
+
egress: {
|
|
300
|
+
...base.egress,
|
|
301
|
+
...(raw.egress ?? {}),
|
|
302
|
+
},
|
|
303
|
+
sandbox: {
|
|
304
|
+
...base.sandbox,
|
|
305
|
+
...(raw.sandbox ?? {}),
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function normalizeV3Raw(raw) {
|
|
310
|
+
return normalizeConfig({
|
|
311
|
+
...DEFAULT_CONFIG_V4,
|
|
312
|
+
...raw,
|
|
313
|
+
version: 4,
|
|
314
|
+
judge: synthesizeJudgeFromRaw(raw),
|
|
315
|
+
gates: {
|
|
316
|
+
...DEFAULT_CONFIG_V3.gates,
|
|
317
|
+
...(raw.gates ?? {}),
|
|
318
|
+
},
|
|
319
|
+
classifier: {
|
|
320
|
+
...DEFAULT_CONFIG_V3.classifier,
|
|
321
|
+
...(raw.classifier ?? {}),
|
|
322
|
+
},
|
|
323
|
+
policy: {
|
|
324
|
+
...LEGACY_POLICY_V3,
|
|
325
|
+
...(raw.policy ?? {}),
|
|
326
|
+
},
|
|
327
|
+
overrides: {
|
|
328
|
+
...DEFAULT_CONFIG_V3.overrides,
|
|
329
|
+
...(raw.overrides ?? {}),
|
|
330
|
+
},
|
|
331
|
+
redaction: {
|
|
332
|
+
...DEFAULT_CONFIG_V3.redaction,
|
|
333
|
+
...(raw.redaction ?? {}),
|
|
334
|
+
},
|
|
335
|
+
controlPlane: {
|
|
336
|
+
...LEGACY_CONTROL_PLANE_V3,
|
|
337
|
+
...(raw.controlPlane ?? {}),
|
|
338
|
+
isolation: {
|
|
339
|
+
...LEGACY_CONTROL_PLANE_V3.isolation,
|
|
340
|
+
...(raw.controlPlane?.isolation ?? {}),
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
notifications: {
|
|
344
|
+
...DEFAULT_NOTIFICATIONS_V3,
|
|
345
|
+
...(raw.notifications ?? {}),
|
|
346
|
+
},
|
|
347
|
+
approvalSigning: {
|
|
348
|
+
required: raw.approvalSigning?.required === true,
|
|
349
|
+
},
|
|
350
|
+
egress: {
|
|
351
|
+
...DEFAULT_EGRESS_V3,
|
|
352
|
+
...(raw.egress ?? {}),
|
|
353
|
+
},
|
|
354
|
+
sandbox: {
|
|
355
|
+
...DEFAULT_SANDBOX_V3,
|
|
356
|
+
...(raw.sandbox ?? {}),
|
|
357
|
+
},
|
|
358
|
+
audit: {
|
|
359
|
+
...DEFAULT_CONFIG_V3.audit,
|
|
360
|
+
...(raw.audit ?? {}),
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
export function migrateConfig(loaded) {
|
|
365
|
+
if (typeof loaded !== 'object' || loaded === null) {
|
|
366
|
+
return { ...DEFAULT_CONFIG_V4 };
|
|
367
|
+
}
|
|
368
|
+
const raw = loaded;
|
|
369
|
+
if (raw.version === 4) {
|
|
370
|
+
return normalizeV3Raw(raw);
|
|
371
|
+
}
|
|
372
|
+
if (raw.version === 3 || (raw.version === undefined && hasV3Sections(raw))) {
|
|
373
|
+
return normalizeV3Raw(raw);
|
|
374
|
+
}
|
|
375
|
+
const baseV2 = { ...DEFAULT_CONFIG_V2 };
|
|
376
|
+
if (raw.version === 1 || (raw.version === undefined && !looksLikeV2Config(raw))) {
|
|
377
|
+
const migratedV2 = normalizeConfigV2({
|
|
378
|
+
...baseV2,
|
|
379
|
+
mode: raw.mode ?? baseV2.mode,
|
|
380
|
+
approvalTtlMinutes: raw.approvalTtlMinutes ?? baseV2.approvalTtlMinutes,
|
|
381
|
+
tokenPrefix: raw.tokenPrefix ?? baseV2.tokenPrefix,
|
|
382
|
+
gates: {
|
|
383
|
+
...baseV2.gates,
|
|
384
|
+
shell: raw.gates?.shell ?? baseV2.gates.shell,
|
|
385
|
+
subagent: raw.gates?.subagent ?? baseV2.gates.subagent,
|
|
386
|
+
},
|
|
387
|
+
audit: {
|
|
388
|
+
...baseV2.audit,
|
|
389
|
+
logPath: raw.audit?.logPath ?? baseV2.audit.logPath,
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
return mergeV3FromRaw(migrateV2ToV3(migratedV2, raw.overrides), raw);
|
|
393
|
+
}
|
|
394
|
+
const migratedV2 = normalizeConfigV2({
|
|
395
|
+
...baseV2,
|
|
396
|
+
...raw,
|
|
397
|
+
version: 2,
|
|
398
|
+
gates: {
|
|
399
|
+
...baseV2.gates,
|
|
400
|
+
...(raw.gates ?? {}),
|
|
401
|
+
},
|
|
402
|
+
classifier: {
|
|
403
|
+
...baseV2.classifier,
|
|
404
|
+
...(raw.classifier ?? {}),
|
|
405
|
+
},
|
|
406
|
+
audit: {
|
|
407
|
+
...baseV2.audit,
|
|
408
|
+
...(raw.audit ?? {}),
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
return mergeV3FromRaw(migrateV2ToV3(migratedV2, raw.overrides), raw);
|
|
412
|
+
}
|
|
413
|
+
export function normalizeConfigV2(config) {
|
|
414
|
+
return {
|
|
415
|
+
version: 2,
|
|
416
|
+
mode: config.mode === 'audit' ? 'audit' : 'enforce',
|
|
417
|
+
approvalTtlMinutes: typeof config.approvalTtlMinutes === 'number' && config.approvalTtlMinutes > 0
|
|
418
|
+
? config.approvalTtlMinutes
|
|
419
|
+
: DEFAULT_CONFIG_V2.approvalTtlMinutes,
|
|
420
|
+
tokenPrefix: config.tokenPrefix || DEFAULT_CONFIG_V2.tokenPrefix,
|
|
421
|
+
gates: {
|
|
422
|
+
shell: config.gates.shell !== false,
|
|
423
|
+
subagent: config.gates.subagent !== false,
|
|
424
|
+
fileMutation: config.gates.fileMutation !== false,
|
|
425
|
+
toolShell: config.gates.toolShell !== false,
|
|
426
|
+
},
|
|
427
|
+
classifier: {
|
|
428
|
+
strictChains: config.classifier?.strictChains !== false,
|
|
429
|
+
customExternalCommands: Array.isArray(config.classifier?.customExternalCommands)
|
|
430
|
+
? config.classifier.customExternalCommands
|
|
431
|
+
: [],
|
|
432
|
+
customAllowCommands: Array.isArray(config.classifier?.customAllowCommands)
|
|
433
|
+
? config.classifier.customAllowCommands
|
|
434
|
+
: [],
|
|
435
|
+
sensitivePaths: Array.isArray(config.classifier?.sensitivePaths)
|
|
436
|
+
? config.classifier.sensitivePaths
|
|
437
|
+
: DEFAULT_CONFIG_V2.classifier.sensitivePaths,
|
|
438
|
+
},
|
|
439
|
+
audit: {
|
|
440
|
+
logPath: config.audit?.logPath || DEFAULT_CONFIG_V2.audit.logPath,
|
|
441
|
+
includeAssessment: config.audit?.includeAssessment !== false,
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
export function normalizeConfig(config) {
|
|
446
|
+
if (config.version === 2) {
|
|
447
|
+
return normalizeConfigV2(config);
|
|
448
|
+
}
|
|
449
|
+
const v4 = config;
|
|
450
|
+
return {
|
|
451
|
+
version: 4,
|
|
452
|
+
...(v4.installScope === 'global' || v4.installScope === 'project'
|
|
453
|
+
? { installScope: v4.installScope }
|
|
454
|
+
: {}),
|
|
455
|
+
mode: v4.mode === 'audit' ? 'audit' : 'enforce',
|
|
456
|
+
approvalTtlMinutes: typeof v4.approvalTtlMinutes === 'number' && v4.approvalTtlMinutes > 0
|
|
457
|
+
? v4.approvalTtlMinutes
|
|
458
|
+
: DEFAULT_CONFIG_V4.approvalTtlMinutes,
|
|
459
|
+
tokenPrefix: v4.tokenPrefix || DEFAULT_CONFIG_V4.tokenPrefix,
|
|
460
|
+
gates: {
|
|
461
|
+
shell: v4.gates.shell !== false,
|
|
462
|
+
subagent: v4.gates.subagent !== false,
|
|
463
|
+
fileMutation: v4.gates.fileMutation !== false,
|
|
464
|
+
toolShell: v4.gates.toolShell !== false,
|
|
465
|
+
},
|
|
466
|
+
classifier: {
|
|
467
|
+
strictChains: v4.classifier?.strictChains !== false,
|
|
468
|
+
sensitivePaths: Array.isArray(v4.classifier?.sensitivePaths)
|
|
469
|
+
? v4.classifier.sensitivePaths
|
|
470
|
+
: DEFAULT_CONFIG_V4.classifier.sensitivePaths,
|
|
471
|
+
},
|
|
472
|
+
policy: {
|
|
473
|
+
unknownLocalEffect: v4.policy?.unknownLocalEffect === 'deny'
|
|
474
|
+
? 'deny'
|
|
475
|
+
: v4.policy?.unknownLocalEffect === 'allow_flagged'
|
|
476
|
+
? 'allow_flagged'
|
|
477
|
+
: DEFAULT_POLICY_V3.unknownLocalEffect,
|
|
478
|
+
unparseableShell: v4.policy?.unparseableShell === 'deny'
|
|
479
|
+
? 'deny'
|
|
480
|
+
: v4.policy?.unparseableShell === 'allow_flagged'
|
|
481
|
+
? 'allow_flagged'
|
|
482
|
+
: DEFAULT_POLICY_V3.unparseableShell,
|
|
483
|
+
codexUnmappedTool: v4.policy?.codexUnmappedTool === 'allow' ? 'allow' : 'deny',
|
|
484
|
+
fenceWarnThreshold: typeof v4.policy?.fenceWarnThreshold === 'number' &&
|
|
485
|
+
v4.policy.fenceWarnThreshold > 0 &&
|
|
486
|
+
v4.policy.fenceWarnThreshold <= 1
|
|
487
|
+
? v4.policy.fenceWarnThreshold
|
|
488
|
+
: DEFAULT_FENCE_WARN_THRESHOLD,
|
|
489
|
+
confidenceThresholds: {
|
|
490
|
+
allow: typeof v4.policy?.confidenceThresholds?.allow === 'number'
|
|
491
|
+
? v4.policy.confidenceThresholds.allow
|
|
492
|
+
: DEFAULT_CONFIDENCE_THRESHOLDS.allow,
|
|
493
|
+
flag: typeof v4.policy?.confidenceThresholds?.flag === 'number'
|
|
494
|
+
? v4.policy.confidenceThresholds.flag
|
|
495
|
+
: DEFAULT_CONFIDENCE_THRESHOLDS.flag,
|
|
496
|
+
},
|
|
497
|
+
modelAssist: {
|
|
498
|
+
enabled: v4.policy?.modelAssist?.enabled === true,
|
|
499
|
+
model: v4.policy?.modelAssist?.model,
|
|
500
|
+
timeoutMs: typeof v4.policy?.modelAssist?.timeoutMs === 'number'
|
|
501
|
+
? v4.policy.modelAssist.timeoutMs
|
|
502
|
+
: DEFAULT_MODEL_ASSIST.timeoutMs,
|
|
503
|
+
},
|
|
504
|
+
transactional: (() => {
|
|
505
|
+
let minConfidence = typeof v4.policy?.transactional?.minConfidence === 'number'
|
|
506
|
+
? v4.policy.transactional.minConfidence
|
|
507
|
+
: DEFAULT_TRANSACTIONAL_V3.minConfidence;
|
|
508
|
+
let maxConfidence = typeof v4.policy?.transactional?.maxConfidence === 'number'
|
|
509
|
+
? v4.policy.transactional.maxConfidence
|
|
510
|
+
: DEFAULT_TRANSACTIONAL_V3.maxConfidence;
|
|
511
|
+
if (minConfidence >= maxConfidence) {
|
|
512
|
+
minConfidence = DEFAULT_TRANSACTIONAL_V3.minConfidence;
|
|
513
|
+
maxConfidence = DEFAULT_TRANSACTIONAL_V3.maxConfidence;
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
enabled: v4.policy?.transactional?.enabled === true,
|
|
517
|
+
minConfidence,
|
|
518
|
+
maxConfidence,
|
|
519
|
+
timeoutMs: typeof v4.policy?.transactional?.timeoutMs === 'number' &&
|
|
520
|
+
v4.policy.transactional.timeoutMs > 0
|
|
521
|
+
? v4.policy.transactional.timeoutMs
|
|
522
|
+
: DEFAULT_TRANSACTIONAL_V3.timeoutMs,
|
|
523
|
+
maxDeletionCount: typeof v4.policy?.transactional?.maxDeletionCount === 'number' &&
|
|
524
|
+
v4.policy.transactional.maxDeletionCount >= 0
|
|
525
|
+
? v4.policy.transactional.maxDeletionCount
|
|
526
|
+
: DEFAULT_TRANSACTIONAL_V3.maxDeletionCount,
|
|
527
|
+
gates: {
|
|
528
|
+
shell: v4.policy?.transactional?.gates?.shell !== false,
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
})(),
|
|
532
|
+
},
|
|
533
|
+
overrides: {
|
|
534
|
+
allow: Array.isArray(v4.overrides?.allow) ? uniqueStrings(v4.overrides.allow) : [],
|
|
535
|
+
external: Array.isArray(v4.overrides?.external) ? uniqueStrings(v4.overrides.external) : [],
|
|
536
|
+
},
|
|
537
|
+
redaction: {
|
|
538
|
+
maskApprovalIds: v4.redaction?.maskApprovalIds !== false,
|
|
539
|
+
maskBearerTokens: v4.redaction?.maskBearerTokens !== false,
|
|
540
|
+
maskAuthHeaders: v4.redaction?.maskAuthHeaders !== false,
|
|
541
|
+
maskKeyValueSecrets: v4.redaction?.maskKeyValueSecrets !== false,
|
|
542
|
+
maskHighEntropyStrings: v4.redaction?.maskHighEntropyStrings !== false,
|
|
543
|
+
},
|
|
544
|
+
controlPlane: {
|
|
545
|
+
enabled: v4.controlPlane?.enabled === true
|
|
546
|
+
? true
|
|
547
|
+
: v4.controlPlane?.enabled === false
|
|
548
|
+
? false
|
|
549
|
+
: DEFAULT_CONTROL_PLANE_V3.enabled,
|
|
550
|
+
configDir: typeof v4.controlPlane?.configDir === 'string' && v4.controlPlane.configDir.trim()
|
|
551
|
+
? v4.controlPlane.configDir.trim()
|
|
552
|
+
: null,
|
|
553
|
+
integrity: v4.controlPlane?.integrity === 'hash-pinned'
|
|
554
|
+
? 'hash-pinned'
|
|
555
|
+
: v4.controlPlane?.integrity === 'none'
|
|
556
|
+
? 'none'
|
|
557
|
+
: DEFAULT_CONTROL_PLANE_V3.integrity,
|
|
558
|
+
isolation: {
|
|
559
|
+
mode: v4.controlPlane?.isolation?.mode === 'read-only-mount' ||
|
|
560
|
+
v4.controlPlane?.isolation?.mode === 'separate-user'
|
|
561
|
+
? v4.controlPlane.isolation.mode
|
|
562
|
+
: DEFAULT_CONTROL_PLANE_ISOLATION_V3.mode,
|
|
563
|
+
expectedOwnerUid: typeof v4.controlPlane?.isolation?.expectedOwnerUid === 'number'
|
|
564
|
+
? v4.controlPlane.isolation.expectedOwnerUid
|
|
565
|
+
: undefined,
|
|
566
|
+
verifyAgentWritable: v4.controlPlane?.isolation?.verifyAgentWritable !== false,
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
notifications: {
|
|
570
|
+
webhookUrl: typeof v4.notifications?.webhookUrl === 'string' && v4.notifications.webhookUrl.trim()
|
|
571
|
+
? v4.notifications.webhookUrl.trim()
|
|
572
|
+
: undefined,
|
|
573
|
+
commandHook: typeof v4.notifications?.commandHook === 'string' && v4.notifications.commandHook.trim()
|
|
574
|
+
? v4.notifications.commandHook.trim()
|
|
575
|
+
: undefined,
|
|
576
|
+
},
|
|
577
|
+
approvalSigning: {
|
|
578
|
+
required: v4.approvalSigning?.required === true,
|
|
579
|
+
},
|
|
580
|
+
egress: {
|
|
581
|
+
enabled: v4.egress?.enabled === true,
|
|
582
|
+
listenHost: normalizeEgressListenHost(typeof v4.egress?.listenHost === 'string' && v4.egress.listenHost.trim()
|
|
583
|
+
? v4.egress.listenHost.trim()
|
|
584
|
+
: DEFAULT_EGRESS_V3.listenHost),
|
|
585
|
+
listenPort: typeof v4.egress?.listenPort === 'number' && v4.egress.listenPort > 0
|
|
586
|
+
? v4.egress.listenPort
|
|
587
|
+
: DEFAULT_EGRESS_V3.listenPort,
|
|
588
|
+
demoteL3External: v4.egress?.demoteL3External !== false,
|
|
589
|
+
},
|
|
590
|
+
sandbox: {
|
|
591
|
+
enabled: v4.sandbox?.enabled === true,
|
|
592
|
+
runtime: v4.sandbox?.runtime === 'cursor-sandbox' ||
|
|
593
|
+
v4.sandbox?.runtime === 'container' ||
|
|
594
|
+
v4.sandbox?.runtime === 'seatbelt' ||
|
|
595
|
+
v4.sandbox?.runtime === 'landlock'
|
|
596
|
+
? v4.sandbox.runtime
|
|
597
|
+
: DEFAULT_SANDBOX_V3.runtime,
|
|
598
|
+
denyNetworkByDefault: v4.sandbox?.denyNetworkByDefault !== false,
|
|
599
|
+
},
|
|
600
|
+
audit: {
|
|
601
|
+
logPath: v4.audit?.logPath || DEFAULT_CONFIG_V4.audit.logPath,
|
|
602
|
+
includeAssessment: v4.audit?.includeAssessment !== false,
|
|
603
|
+
},
|
|
604
|
+
judge: normalizeJudgeConfig(v4.judge ?? DEFAULT_JUDGE_LOCAL_OLLAMA),
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
export function isFreshConfigInput(loaded) {
|
|
608
|
+
if (loaded === null || loaded === undefined) {
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
if (typeof loaded !== 'object') {
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
return Object.keys(loaded).length === 0;
|
|
615
|
+
}
|
|
616
|
+
export function mergeConfig(existing, defaults = DEFAULT_CONFIG_V4) {
|
|
617
|
+
const migrated = isFreshConfigInput(existing)
|
|
618
|
+
? normalizeConfig({ ...defaults, version: 4 })
|
|
619
|
+
: migrateConfig(existing);
|
|
620
|
+
return normalizeConfig({
|
|
621
|
+
...defaults,
|
|
622
|
+
...migrated,
|
|
623
|
+
judge: migrated.judge ?? defaults.judge,
|
|
624
|
+
gates: {
|
|
625
|
+
...defaults.gates,
|
|
626
|
+
...migrated.gates,
|
|
627
|
+
},
|
|
628
|
+
classifier: {
|
|
629
|
+
...defaults.classifier,
|
|
630
|
+
...migrated.classifier,
|
|
631
|
+
},
|
|
632
|
+
policy: {
|
|
633
|
+
...defaults.policy,
|
|
634
|
+
...migrated.policy,
|
|
635
|
+
},
|
|
636
|
+
overrides: {
|
|
637
|
+
allow: mergeOverrideLists(defaults.overrides.allow, migrated.overrides.allow),
|
|
638
|
+
external: mergeOverrideLists(defaults.overrides.external, migrated.overrides.external),
|
|
639
|
+
},
|
|
640
|
+
redaction: {
|
|
641
|
+
...defaults.redaction,
|
|
642
|
+
...migrated.redaction,
|
|
643
|
+
},
|
|
644
|
+
controlPlane: {
|
|
645
|
+
...defaults.controlPlane,
|
|
646
|
+
...migrated.controlPlane,
|
|
647
|
+
},
|
|
648
|
+
notifications: {
|
|
649
|
+
...defaults.notifications,
|
|
650
|
+
...migrated.notifications,
|
|
651
|
+
},
|
|
652
|
+
approvalSigning: {
|
|
653
|
+
...defaults.approvalSigning,
|
|
654
|
+
...migrated.approvalSigning,
|
|
655
|
+
},
|
|
656
|
+
egress: {
|
|
657
|
+
...defaults.egress,
|
|
658
|
+
...migrated.egress,
|
|
659
|
+
},
|
|
660
|
+
sandbox: {
|
|
661
|
+
...defaults.sandbox,
|
|
662
|
+
...migrated.sandbox,
|
|
663
|
+
},
|
|
664
|
+
audit: {
|
|
665
|
+
...defaults.audit,
|
|
666
|
+
...migrated.audit,
|
|
667
|
+
},
|
|
668
|
+
...(migrated.installScope ? { installScope: migrated.installScope } : {}),
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
export function scrubOptionsFromConfig(config) {
|
|
672
|
+
return { ...config.redaction };
|
|
673
|
+
}
|
|
674
|
+
export function classifierOptionsFromConfig(config) {
|
|
675
|
+
return {
|
|
676
|
+
strictChains: config.classifier.strictChains,
|
|
677
|
+
customExternalCommands: config.overrides.external,
|
|
678
|
+
customAllowCommands: config.overrides.allow,
|
|
679
|
+
sensitivePaths: config.classifier.sensitivePaths,
|
|
680
|
+
unknownLocalEffect: config.policy.unknownLocalEffect,
|
|
681
|
+
unparseableShell: config.policy.unparseableShell,
|
|
682
|
+
confidenceThresholds: { ...config.policy.confidenceThresholds },
|
|
683
|
+
controlPlaneDir: config.controlPlane.enabled ? resolveControlPlaneDir(config) : null,
|
|
684
|
+
scrubOptions: scrubOptionsFromConfig(config),
|
|
685
|
+
egressEnabled: config.egress.enabled,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
export function defaultControlPlaneDir(env = process.env, homedir = () => env.HOME ?? env.USERPROFILE ?? '') {
|
|
689
|
+
if (process.platform === 'win32') {
|
|
690
|
+
const appData = env.APPDATA?.trim();
|
|
691
|
+
if (appData) {
|
|
692
|
+
return path.join(appData, 'agent-belay');
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const xdgConfigHome = env.XDG_CONFIG_HOME?.trim();
|
|
696
|
+
const base = xdgConfigHome || path.join(homedir(), '.config');
|
|
697
|
+
return path.join(base, 'agent-belay');
|
|
698
|
+
}
|
|
699
|
+
export function resolveControlPlaneDir(config) {
|
|
700
|
+
if (config.controlPlane.configDir) {
|
|
701
|
+
return config.controlPlane.configDir;
|
|
702
|
+
}
|
|
703
|
+
return defaultControlPlaneDir();
|
|
704
|
+
}
|
|
705
|
+
/** Control-plane directory regardless of enabled flag (for orphan migration). */
|
|
706
|
+
export function configuredControlPlaneDir(config) {
|
|
707
|
+
return resolveControlPlaneDir(config);
|
|
708
|
+
}
|
|
709
|
+
export function belayStateDir(config, repoLocalStateDir) {
|
|
710
|
+
if (config.controlPlane.enabled) {
|
|
711
|
+
return resolveControlPlaneDir(config);
|
|
712
|
+
}
|
|
713
|
+
return repoLocalStateDir;
|
|
714
|
+
}
|
|
715
|
+
export function pendingApprovalsFile(config, repoLocalStateDir) {
|
|
716
|
+
return path.join(belayStateDir(config, repoLocalStateDir), 'pending-approvals.json');
|
|
717
|
+
}
|
|
718
|
+
export function approvedApprovalsFile(config, repoLocalStateDir) {
|
|
719
|
+
return path.join(belayStateDir(config, repoLocalStateDir), 'approved-approvals.json');
|
|
720
|
+
}
|