@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
package/dist/cli.js
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { CLI_COMMAND } from './branding.js';
|
|
4
|
+
import { approvePending } from './commands/approve.js';
|
|
5
|
+
import { auditProject, formatAuditReport } from './commands/audit.js';
|
|
6
|
+
import { doctorProject, formatDoctorReport } from './commands/doctor.js';
|
|
7
|
+
import { dogfoodProject, formatDogfoodResult } from './commands/dogfood.js';
|
|
8
|
+
import { explainCommand, formatExplainReport } from './commands/explain.js';
|
|
9
|
+
import { formatMetricsReport, metricsProject } from './commands/metrics.js';
|
|
10
|
+
import { formatRecoverReport, recoverProject } from './commands/recover.js';
|
|
11
|
+
import { formatReport, reportProject } from './commands/report.js';
|
|
12
|
+
import { revokeApproval } from './commands/revoke.js';
|
|
13
|
+
import { formatSimulateReport, simulateProject } from './commands/simulate.js';
|
|
14
|
+
import { formatStatusReport, statusProject } from './commands/status.js';
|
|
15
|
+
import { loadConfigFile } from './config-io.js';
|
|
16
|
+
import { initProject, upgradeProject } from './installer.js';
|
|
17
|
+
import { egressEnv, egressStatus, formatEgressStatusReport, startEgressProxy, stopEgressProxy, } from './services/egress-service.js';
|
|
18
|
+
import { formatSandboxStatusReport, sandboxStatus } from './services/sandbox-service.js';
|
|
19
|
+
function parseArgs(argv) {
|
|
20
|
+
const [command, ...rest] = argv;
|
|
21
|
+
const options = {};
|
|
22
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
23
|
+
const token = rest[index];
|
|
24
|
+
if (token === '--with-skill') {
|
|
25
|
+
options.withSkill = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (token === '--dogfood') {
|
|
29
|
+
options.dogfood = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (token === '--enforce') {
|
|
33
|
+
options.enforce = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (token === '--force') {
|
|
37
|
+
options.force = true;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (token === '--adapter') {
|
|
41
|
+
const next = rest[index + 1];
|
|
42
|
+
if (!next || !['cursor', 'claude', 'codex'].includes(next)) {
|
|
43
|
+
throw new Error('--adapter requires cursor, claude, or codex.');
|
|
44
|
+
}
|
|
45
|
+
options.adapter = next;
|
|
46
|
+
index += 1;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (token === '--preset') {
|
|
50
|
+
const next = rest[index + 1];
|
|
51
|
+
const allowed = ['strict', 'standard', 'audit-first', 'l1-full-recommended'];
|
|
52
|
+
if (!next || !allowed.includes(next)) {
|
|
53
|
+
throw new Error('--preset requires strict, standard, audit-first, or l1-full-recommended.');
|
|
54
|
+
}
|
|
55
|
+
options.preset = next;
|
|
56
|
+
index += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (token === '--judge-profile') {
|
|
60
|
+
const next = rest[index + 1];
|
|
61
|
+
if (!next || next !== 'local-ollama') {
|
|
62
|
+
throw new Error('--judge-profile requires local-ollama.');
|
|
63
|
+
}
|
|
64
|
+
options.judgeProfile = 'local-ollama';
|
|
65
|
+
index += 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (token === '--judge-provider') {
|
|
69
|
+
const next = rest[index + 1];
|
|
70
|
+
if (!next || !['ollama', 'openai-compatible', 'cursor'].includes(next)) {
|
|
71
|
+
throw new Error('--judge-provider requires ollama or openai-compatible.');
|
|
72
|
+
}
|
|
73
|
+
options.judgeProvider = next;
|
|
74
|
+
index += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (token === '--judge-endpoint') {
|
|
78
|
+
const next = rest[index + 1];
|
|
79
|
+
if (!next) {
|
|
80
|
+
throw new Error('--judge-endpoint requires a URL.');
|
|
81
|
+
}
|
|
82
|
+
options.judgeEndpoint = next;
|
|
83
|
+
index += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (token === '--judge-model') {
|
|
87
|
+
const next = rest[index + 1];
|
|
88
|
+
if (!next) {
|
|
89
|
+
throw new Error('--judge-model requires a model id or auto.');
|
|
90
|
+
}
|
|
91
|
+
options.judgeModel = next;
|
|
92
|
+
index += 1;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (token === '--accept-cloud-judge') {
|
|
96
|
+
options.acceptCloudJudge = true;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (token === '--json') {
|
|
100
|
+
options.json = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (token === '--since') {
|
|
104
|
+
options.since = rest[index + 1];
|
|
105
|
+
index += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (token === '--until') {
|
|
109
|
+
options.until = rest[index + 1];
|
|
110
|
+
index += 1;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (token === '--verdict') {
|
|
114
|
+
options.verdict = rest[index + 1];
|
|
115
|
+
index += 1;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (token === '--reason') {
|
|
119
|
+
options.reason = rest[index + 1];
|
|
120
|
+
index += 1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (token === '--kind') {
|
|
124
|
+
const next = rest[index + 1];
|
|
125
|
+
if (!next) {
|
|
126
|
+
throw new Error('--kind requires a value.');
|
|
127
|
+
}
|
|
128
|
+
if (command === 'audit') {
|
|
129
|
+
options.kind = next;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (!['shell', 'tool', 'subagent'].includes(next)) {
|
|
133
|
+
throw new Error('--kind requires shell, tool, or subagent.');
|
|
134
|
+
}
|
|
135
|
+
options.explainKind = next;
|
|
136
|
+
}
|
|
137
|
+
index += 1;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (token === '--fingerprint') {
|
|
141
|
+
options.fingerprint = rest[index + 1];
|
|
142
|
+
index += 1;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (token === '--event') {
|
|
146
|
+
options.event = rest[index + 1];
|
|
147
|
+
index += 1;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (token === '--location') {
|
|
151
|
+
options.location = rest[index + 1];
|
|
152
|
+
index += 1;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (token === '--opacity') {
|
|
156
|
+
options.opacity = rest[index + 1];
|
|
157
|
+
index += 1;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (token === '--effect') {
|
|
161
|
+
options.effect = rest[index + 1];
|
|
162
|
+
index += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (token === '--confidence') {
|
|
166
|
+
options.confidence = rest[index + 1];
|
|
167
|
+
index += 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (token === '--limit') {
|
|
171
|
+
const next = Number(rest[index + 1]);
|
|
172
|
+
if (!Number.isFinite(next)) {
|
|
173
|
+
throw new Error('--limit requires a number.');
|
|
174
|
+
}
|
|
175
|
+
options.limit = next;
|
|
176
|
+
index += 1;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (token === '--config') {
|
|
180
|
+
const next = rest[index + 1];
|
|
181
|
+
if (!next) {
|
|
182
|
+
throw new Error('--config requires a path.');
|
|
183
|
+
}
|
|
184
|
+
options.configPath = next;
|
|
185
|
+
index += 1;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (token === '--token') {
|
|
189
|
+
const next = rest[index + 1];
|
|
190
|
+
if (!next) {
|
|
191
|
+
throw new Error('--token requires a signed approval token.');
|
|
192
|
+
}
|
|
193
|
+
options.approvalToken = next;
|
|
194
|
+
index += 1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (token === '--scope') {
|
|
198
|
+
const next = rest[index + 1];
|
|
199
|
+
if (command === 'approve') {
|
|
200
|
+
if (!next || !['once', 'domain', 'path'].includes(next)) {
|
|
201
|
+
throw new Error('--scope requires once, domain, or path.');
|
|
202
|
+
}
|
|
203
|
+
options.approveScope = next;
|
|
204
|
+
}
|
|
205
|
+
else if (command === 'init' || command === 'upgrade') {
|
|
206
|
+
if (!next || !['project', 'global'].includes(next)) {
|
|
207
|
+
throw new Error('--scope requires project or global.');
|
|
208
|
+
}
|
|
209
|
+
options.installScope = next;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
throw new Error('--scope is only valid for init, upgrade, or approve.');
|
|
213
|
+
}
|
|
214
|
+
index += 1;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (token === '--path') {
|
|
218
|
+
const next = rest[index + 1];
|
|
219
|
+
if (!next) {
|
|
220
|
+
throw new Error('--path requires a filesystem path.');
|
|
221
|
+
}
|
|
222
|
+
options.approvePath = next;
|
|
223
|
+
index += 1;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (token === '--fix') {
|
|
227
|
+
options.fix = true;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (token === '--dry-run') {
|
|
231
|
+
options.dryRun = true;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (token === '--target') {
|
|
235
|
+
const next = rest[index + 1];
|
|
236
|
+
if (!next) {
|
|
237
|
+
throw new Error('--target requires a path value.');
|
|
238
|
+
}
|
|
239
|
+
options.targetDir = next;
|
|
240
|
+
index += 1;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (token === '--cwd') {
|
|
244
|
+
const next = rest[index + 1];
|
|
245
|
+
if (!next) {
|
|
246
|
+
throw new Error('--cwd requires a path value.');
|
|
247
|
+
}
|
|
248
|
+
options.explainCwd = next;
|
|
249
|
+
index += 1;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (token === '--command') {
|
|
253
|
+
const next = rest[index + 1];
|
|
254
|
+
if (!next) {
|
|
255
|
+
throw new Error('--command requires a value.');
|
|
256
|
+
}
|
|
257
|
+
if (command === 'recover') {
|
|
258
|
+
options.recoverCommand = next;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
options.explainCommand = next;
|
|
262
|
+
}
|
|
263
|
+
index += 1;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (token === '--tool') {
|
|
267
|
+
const next = rest[index + 1];
|
|
268
|
+
if (!next) {
|
|
269
|
+
throw new Error('--tool requires a tool name.');
|
|
270
|
+
}
|
|
271
|
+
options.explainToolName = next;
|
|
272
|
+
index += 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (token === '--payload-json') {
|
|
276
|
+
const next = rest[index + 1];
|
|
277
|
+
if (!next) {
|
|
278
|
+
throw new Error('--payload-json requires a JSON object.');
|
|
279
|
+
}
|
|
280
|
+
options.explainPayload = JSON.parse(next);
|
|
281
|
+
index += 1;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (token === '--help' || token === '-h') {
|
|
285
|
+
return { command: 'help', options };
|
|
286
|
+
}
|
|
287
|
+
if (token === '--') {
|
|
288
|
+
options.explainCommand = rest.slice(index + 1).join(' ');
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
if (command === 'audit' && !options.auditSubcommand) {
|
|
292
|
+
if (token === 'query' || token === 'summarize' || token === 'replay') {
|
|
293
|
+
options.auditSubcommand = token;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
throw new Error('audit requires subcommand: query, summarize, or replay');
|
|
297
|
+
}
|
|
298
|
+
if (command === 'egress' && !options.egressSubcommand) {
|
|
299
|
+
if (token === 'start' || token === 'stop' || token === 'status' || token === 'env') {
|
|
300
|
+
options.egressSubcommand = token;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
throw new Error('egress requires subcommand: start, stop, status, or env');
|
|
304
|
+
}
|
|
305
|
+
if (command === 'sandbox' && !options.sandboxSubcommand) {
|
|
306
|
+
if (token === 'status') {
|
|
307
|
+
options.sandboxSubcommand = token;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
throw new Error('sandbox requires subcommand: status');
|
|
311
|
+
}
|
|
312
|
+
if ((command === 'revoke' || command === 'approve') && !options.approvalId) {
|
|
313
|
+
options.approvalId = token;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
throw new Error(`Unknown argument: ${token}`);
|
|
317
|
+
}
|
|
318
|
+
return { command: command ?? 'help', options };
|
|
319
|
+
}
|
|
320
|
+
function printHelp() {
|
|
321
|
+
const c = CLI_COMMAND;
|
|
322
|
+
process.stdout.write(`${c}
|
|
323
|
+
|
|
324
|
+
Usage:
|
|
325
|
+
${c} init [--target <dir>] [--adapter cursor|claude|codex] [--scope project|global] [--preset strict|standard|audit-first|l1-full-recommended] [--judge-profile local-ollama] [--judge-provider ollama|openai-compatible] [--judge-model <id|auto>] [--judge-endpoint <url>] [--accept-cloud-judge] [--with-skill] [--dogfood]
|
|
326
|
+
${c} init-wizard [--target <dir>]
|
|
327
|
+
(--dogfood runs after --preset and sets mode: audit, overriding preset enforce mode)
|
|
328
|
+
${c} upgrade [--target <dir>] [--adapter cursor|claude|codex] [--scope project|global] [--with-skill]
|
|
329
|
+
${c} dogfood [--target <dir>] [--adapter cursor|claude|codex] [--enforce] [--force]
|
|
330
|
+
${c} doctor [--target <dir>] [--adapter cursor|claude|codex] [--json] [--fix] [--dry-run]
|
|
331
|
+
${c} metrics [--target <dir>] [--json]
|
|
332
|
+
${c} report [--target <dir>] [--since <iso>] [--until <iso>] [--limit <n>] [--json]
|
|
333
|
+
${c} recover [--target <dir>] [--since <iso>] [--fingerprint <fp>] [--command "<text>"] [--limit <n>] [--json]
|
|
334
|
+
(--limit picks the Nth recover candidate after priority ranking: local_mutation first, then recency; 1 = highest priority, default 1)
|
|
335
|
+
${c} audit <query|summarize|replay> [--target <dir>] [--json] [--since <iso>] [--until <iso>] [--verdict <v>] [--reason <r>] [--kind <k>] [--fingerprint <fp>] [--event <e>] [--location <v>] [--opacity <v>] [--effect <v>] [--confidence <v>] [--limit <n>] [--config <path>]
|
|
336
|
+
${c} simulate --config <path> [--target <dir>] [--json]
|
|
337
|
+
${c} status [--target <dir>] [--json]
|
|
338
|
+
${c} explain [--target <dir>] [--cwd <dir>] [--kind shell|tool|subagent] [--tool <name>] [--payload-json <json>] [--command <text>] [--json] [-- <command>]
|
|
339
|
+
${c} egress <start|stop|status|env> [--target <dir>] [--json]
|
|
340
|
+
${c} sandbox status [--target <dir>] [--json]
|
|
341
|
+
${c} approve <approval-id> [--scope once|domain|path] [--path <path>] [--token <signed-token>] [--target <dir>]
|
|
342
|
+
${c} revoke <approval-id> [--target <dir>]
|
|
343
|
+
`);
|
|
344
|
+
}
|
|
345
|
+
async function main() {
|
|
346
|
+
try {
|
|
347
|
+
const { command, options } = parseArgs(process.argv.slice(2));
|
|
348
|
+
if (command === 'help') {
|
|
349
|
+
printHelp();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (command === 'init-wizard') {
|
|
353
|
+
const { runInitWizard } = await import('./commands/init-wizard.js');
|
|
354
|
+
const result = await runInitWizard({ targetDir: options.targetDir });
|
|
355
|
+
process.stdout.write(`Initialized belay in ${result.repoRoot}${result.withSkill ? ' (with skill)' : ''}.\n`);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (command === 'init') {
|
|
359
|
+
const result = await initProject({
|
|
360
|
+
targetDir: options.targetDir,
|
|
361
|
+
withSkill: options.withSkill,
|
|
362
|
+
dogfood: options.dogfood,
|
|
363
|
+
adapter: options.adapter,
|
|
364
|
+
scope: options.installScope,
|
|
365
|
+
preset: options.preset,
|
|
366
|
+
judgeProfile: options.judgeProfile,
|
|
367
|
+
judgeProvider: options.judgeProvider,
|
|
368
|
+
judgeModel: options.judgeModel,
|
|
369
|
+
judgeEndpoint: options.judgeEndpoint,
|
|
370
|
+
acceptCloudJudge: options.acceptCloudJudge,
|
|
371
|
+
});
|
|
372
|
+
const extras = [
|
|
373
|
+
`adapter=${result.adapter}`,
|
|
374
|
+
result.withSkill ? 'skill extras enabled' : null,
|
|
375
|
+
result.dogfood ? 'dogfood mode enabled' : null,
|
|
376
|
+
].filter(Boolean);
|
|
377
|
+
process.stdout.write(`Initialized belay in ${result.repoRoot} (${extras.join(', ')}).\n`);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (command === 'dogfood') {
|
|
381
|
+
const result = await dogfoodProject({
|
|
382
|
+
targetDir: options.targetDir,
|
|
383
|
+
enforce: options.enforce,
|
|
384
|
+
force: options.force,
|
|
385
|
+
adapter: options.adapter,
|
|
386
|
+
});
|
|
387
|
+
process.stdout.write(formatDogfoodResult(result));
|
|
388
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (command === 'upgrade') {
|
|
392
|
+
const result = await upgradeProject({
|
|
393
|
+
targetDir: options.targetDir,
|
|
394
|
+
withSkill: options.withSkill,
|
|
395
|
+
adapter: options.adapter,
|
|
396
|
+
scope: options.installScope,
|
|
397
|
+
});
|
|
398
|
+
const upgraded = await loadConfigFile(result.repoRoot, result.adapter);
|
|
399
|
+
if (upgraded.policy.modelAssist.enabled) {
|
|
400
|
+
process.stderr.write('Warning: policy.modelAssist is enabled but is not wired to v2 Tier1. Use top-level judge instead.\n');
|
|
401
|
+
}
|
|
402
|
+
process.stdout.write(`Upgraded belay (${result.adapter}) in ${result.repoRoot}.\n`);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (command === 'doctor') {
|
|
406
|
+
const report = await doctorProject({
|
|
407
|
+
targetDir: options.targetDir,
|
|
408
|
+
fix: options.fix,
|
|
409
|
+
dryRun: options.dryRun,
|
|
410
|
+
adapter: options.adapter,
|
|
411
|
+
});
|
|
412
|
+
if (options.json) {
|
|
413
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
process.stdout.write(formatDoctorReport(report));
|
|
417
|
+
}
|
|
418
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (command === 'audit') {
|
|
422
|
+
if (!options.auditSubcommand) {
|
|
423
|
+
throw new Error('audit requires subcommand: query, summarize, or replay');
|
|
424
|
+
}
|
|
425
|
+
const report = await auditProject({
|
|
426
|
+
targetDir: options.targetDir,
|
|
427
|
+
subcommand: options.auditSubcommand,
|
|
428
|
+
json: options.json,
|
|
429
|
+
since: options.since,
|
|
430
|
+
until: options.until,
|
|
431
|
+
verdict: options.verdict,
|
|
432
|
+
reason: options.reason,
|
|
433
|
+
kind: options.kind,
|
|
434
|
+
fingerprint: options.fingerprint,
|
|
435
|
+
event: options.event,
|
|
436
|
+
location: options.location,
|
|
437
|
+
opacity: options.opacity,
|
|
438
|
+
effect: options.effect,
|
|
439
|
+
confidence: options.confidence,
|
|
440
|
+
limit: options.limit,
|
|
441
|
+
configPath: options.configPath,
|
|
442
|
+
});
|
|
443
|
+
if (options.json) {
|
|
444
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
process.stdout.write(formatAuditReport(report));
|
|
448
|
+
}
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (command === 'simulate') {
|
|
452
|
+
if (!options.configPath) {
|
|
453
|
+
throw new Error('simulate requires --config <path>.');
|
|
454
|
+
}
|
|
455
|
+
const report = await simulateProject({
|
|
456
|
+
targetDir: options.targetDir,
|
|
457
|
+
configPath: options.configPath,
|
|
458
|
+
json: options.json,
|
|
459
|
+
});
|
|
460
|
+
if (options.json) {
|
|
461
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
process.stdout.write(formatSimulateReport(report));
|
|
465
|
+
}
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (command === 'metrics') {
|
|
469
|
+
const report = await metricsProject({
|
|
470
|
+
targetDir: options.targetDir,
|
|
471
|
+
json: options.json,
|
|
472
|
+
});
|
|
473
|
+
if (options.json) {
|
|
474
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
process.stdout.write(formatMetricsReport(report));
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (command === 'report') {
|
|
482
|
+
const report = await reportProject({
|
|
483
|
+
targetDir: options.targetDir,
|
|
484
|
+
since: options.since,
|
|
485
|
+
until: options.until,
|
|
486
|
+
limit: options.limit,
|
|
487
|
+
json: options.json,
|
|
488
|
+
});
|
|
489
|
+
if (options.json) {
|
|
490
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
process.stdout.write(formatReport(report));
|
|
494
|
+
}
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (command === 'recover') {
|
|
498
|
+
const report = await recoverProject({
|
|
499
|
+
targetDir: options.targetDir,
|
|
500
|
+
since: options.since,
|
|
501
|
+
fingerprint: options.fingerprint,
|
|
502
|
+
command: options.recoverCommand,
|
|
503
|
+
limit: options.limit,
|
|
504
|
+
json: options.json,
|
|
505
|
+
});
|
|
506
|
+
if (options.json) {
|
|
507
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
process.stdout.write(formatRecoverReport(report));
|
|
511
|
+
}
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (command === 'status') {
|
|
515
|
+
const report = await statusProject({
|
|
516
|
+
targetDir: options.targetDir,
|
|
517
|
+
json: options.json,
|
|
518
|
+
});
|
|
519
|
+
if (options.json) {
|
|
520
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
process.stdout.write(formatStatusReport(report));
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (command === 'explain') {
|
|
528
|
+
const report = await explainCommand({
|
|
529
|
+
targetDir: options.targetDir,
|
|
530
|
+
command: options.explainCommand,
|
|
531
|
+
cwd: options.explainCwd,
|
|
532
|
+
json: options.json,
|
|
533
|
+
kind: options.explainKind,
|
|
534
|
+
toolName: options.explainToolName,
|
|
535
|
+
payload: options.explainPayload,
|
|
536
|
+
explainLastPending: !options.explainCommand && !options.explainPayload,
|
|
537
|
+
});
|
|
538
|
+
if (options.json) {
|
|
539
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
process.stdout.write(formatExplainReport(report));
|
|
543
|
+
}
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (command === 'egress') {
|
|
547
|
+
if (!options.egressSubcommand) {
|
|
548
|
+
throw new Error('egress requires subcommand: start, stop, status, or env');
|
|
549
|
+
}
|
|
550
|
+
if (options.egressSubcommand === 'start') {
|
|
551
|
+
const result = await startEgressProxy({ targetDir: options.targetDir });
|
|
552
|
+
process.stdout.write(`${result.message}\n`);
|
|
553
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (options.egressSubcommand === 'stop') {
|
|
557
|
+
const result = await stopEgressProxy({ targetDir: options.targetDir });
|
|
558
|
+
process.stdout.write(`${result.message}\n`);
|
|
559
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (options.egressSubcommand === 'env') {
|
|
563
|
+
const result = await egressEnv({ targetDir: options.targetDir });
|
|
564
|
+
if (options.json) {
|
|
565
|
+
process.stdout.write(`${JSON.stringify({ ok: result.ok, env: result.env }, null, 2)}\n`);
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
process.stdout.write(`${result.message}\n`);
|
|
569
|
+
}
|
|
570
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const report = await egressStatus({ targetDir: options.targetDir });
|
|
574
|
+
if (options.json) {
|
|
575
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
process.stdout.write(formatEgressStatusReport(report));
|
|
579
|
+
}
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (command === 'sandbox') {
|
|
583
|
+
if (!options.sandboxSubcommand) {
|
|
584
|
+
throw new Error('sandbox requires subcommand: status');
|
|
585
|
+
}
|
|
586
|
+
const report = await sandboxStatus({ targetDir: options.targetDir });
|
|
587
|
+
if (options.json) {
|
|
588
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
process.stdout.write(formatSandboxStatusReport(report));
|
|
592
|
+
}
|
|
593
|
+
process.exitCode = report.issues.length > 0 && report.sandboxEnabled ? 1 : 0;
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (command === 'approve') {
|
|
597
|
+
if (!options.approvalId) {
|
|
598
|
+
throw new Error('approve requires an approval ID.');
|
|
599
|
+
}
|
|
600
|
+
const result = await approvePending({
|
|
601
|
+
targetDir: options.targetDir,
|
|
602
|
+
approvalId: options.approvalId,
|
|
603
|
+
token: options.approvalToken,
|
|
604
|
+
scope: options.approveScope,
|
|
605
|
+
scopePath: options.approvePath,
|
|
606
|
+
});
|
|
607
|
+
process.stdout.write(`${result.message}\n`);
|
|
608
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (command === 'revoke') {
|
|
612
|
+
if (!options.approvalId) {
|
|
613
|
+
throw new Error('revoke requires an approval ID.');
|
|
614
|
+
}
|
|
615
|
+
const result = await revokeApproval({
|
|
616
|
+
targetDir: options.targetDir,
|
|
617
|
+
approvalId: options.approvalId,
|
|
618
|
+
});
|
|
619
|
+
process.stdout.write(`${result.message}\n`);
|
|
620
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
throw new Error(`Unknown command: ${command}`);
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
627
|
+
process.stderr.write(`${message}\n`);
|
|
628
|
+
process.exitCode = 1;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
await main();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CapabilityApprovalScope } from '../core/capability/types.js';
|
|
2
|
+
import type { EgressApprovalScope } from '../core/egress/types.js';
|
|
3
|
+
export type ApproveScope = EgressApprovalScope | CapabilityApprovalScope;
|
|
4
|
+
export interface ApproveOptions {
|
|
5
|
+
targetDir?: string;
|
|
6
|
+
approvalId: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
scope?: ApproveScope;
|
|
9
|
+
scopePath?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function approvePending(options: ApproveOptions): Promise<{
|
|
12
|
+
ok: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|