release-skill 0.1.3 → 0.1.4
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +3 -3
- package/CHANGELOG.md +29 -0
- package/INSTALL.md +69 -32
- package/INSTALL.zh-CN.md +64 -26
- package/README.md +101 -37
- package/README.zh-CN.md +87 -28
- package/adapters/claude/.claude-plugin/marketplace.json +1 -1
- package/adapters/claude/.claude-plugin/plugin.json +1 -1
- package/adapters/claude/bin/release-skill.bundle.mjs +79284 -0
- package/adapters/claude/bin/release-skill.mjs +34 -0
- package/adapters/claude/native/safe-write/binding.gyp +40 -0
- package/adapters/claude/native/safe-write/prebuilds/darwin-arm64/safe_write.node +0 -0
- package/adapters/claude/native/safe-write/prebuilds.json +24 -0
- package/adapters/claude/native/safe-write/src/safe_write.cc +2032 -0
- package/adapters/claude/schemas/.render-manifest.json +37 -0
- package/adapters/claude/schemas/approval-record.schema.json +115 -0
- package/adapters/claude/schemas/artifact-lock.schema.json +111 -0
- package/adapters/claude/schemas/artifact-plan.schema.json +52 -0
- package/adapters/claude/schemas/artifact-policy.schema.json +76 -0
- package/adapters/claude/schemas/evidence-event.schema.json +89 -0
- package/adapters/claude/schemas/release-plan.schema.json +860 -0
- package/adapters/claude/schemas/release-project.schema.json +736 -0
- package/adapters/claude/schemas/release-run.schema.json +342 -0
- package/adapters/claude/skills/release-assess/SKILL.md +5 -6
- package/adapters/claude/skills/release-help/SKILL.md +11 -18
- package/adapters/claude/skills/release-prepare/SKILL.md +6 -6
- package/adapters/claude/skills/release-publish/SKILL.md +1 -4
- package/adapters/claude/skills/release-reconcile/SKILL.md +5 -5
- package/adapters/claude/skills/release-setup/SKILL.md +64 -80
- package/adapters/claude/skills/release-verify/SKILL.md +4 -7
- package/adapters/codex/.codex-plugin/plugin.json +2 -2
- package/adapters/codex/bin/release-skill.bundle.mjs +79284 -0
- package/adapters/codex/bin/release-skill.mjs +34 -0
- package/adapters/codex/native/safe-write/binding.gyp +40 -0
- package/adapters/codex/native/safe-write/prebuilds/darwin-arm64/safe_write.node +0 -0
- package/adapters/codex/native/safe-write/prebuilds.json +24 -0
- package/adapters/codex/native/safe-write/src/safe_write.cc +2032 -0
- package/adapters/codex/schemas/.render-manifest.json +37 -0
- package/adapters/codex/schemas/approval-record.schema.json +115 -0
- package/adapters/codex/schemas/artifact-lock.schema.json +111 -0
- package/adapters/codex/schemas/artifact-plan.schema.json +52 -0
- package/adapters/codex/schemas/artifact-policy.schema.json +76 -0
- package/adapters/codex/schemas/evidence-event.schema.json +89 -0
- package/adapters/codex/schemas/release-plan.schema.json +860 -0
- package/adapters/codex/schemas/release-project.schema.json +736 -0
- package/adapters/codex/schemas/release-run.schema.json +342 -0
- package/adapters/codex/skills/release-assess/SKILL.md +12 -6
- package/adapters/codex/skills/release-help/SKILL.md +18 -18
- package/adapters/codex/skills/release-prepare/SKILL.md +13 -6
- package/adapters/codex/skills/release-publish/SKILL.md +8 -4
- package/adapters/codex/skills/release-reconcile/SKILL.md +12 -5
- package/adapters/codex/skills/release-setup/SKILL.md +71 -80
- package/adapters/codex/skills/release-verify/SKILL.md +11 -7
- package/bin/release-skill-cli.mjs +807 -0
- package/bin/release-skill.bundle.mjs +79284 -0
- package/bin/release-skill.mjs +23 -788
- package/package.json +6 -2
- package/references/02-project-config.md +2 -2
- package/schemas/release-plan.schema.json +7 -1
- package/schemas/release-project.schema.json +8 -0
- package/scripts/build-bundle.mjs +133 -0
- package/skills/release-assess/SKILL.md +5 -6
- package/skills/release-help/SKILL.md +11 -18
- package/skills/release-prepare/SKILL.md +6 -6
- package/skills/release-publish/SKILL.md +1 -4
- package/skills/release-reconcile/SKILL.md +5 -5
- package/skills/release-setup/SKILL.md +64 -80
- package/skills/release-verify/SKILL.md +4 -7
- package/skills-src/release-assess/SKILL.md +5 -6
- package/skills-src/release-help/SKILL.md +11 -18
- package/skills-src/release-prepare/SKILL.md +6 -6
- package/skills-src/release-publish/SKILL.md +1 -4
- package/skills-src/release-reconcile/SKILL.md +5 -5
- package/skills-src/release-setup/SKILL.md +64 -80
- package/skills-src/release-verify/SKILL.md +4 -7
- package/src/adapters/npm.mjs +5 -13
- package/src/adapters/plugin-marketplace.mjs +67 -31
- package/src/artifacts/policy.mjs +4 -7
- package/src/artifacts/safe-fs-backend-internal.mjs +69 -21
- package/src/commands/prepare.mjs +22 -1
- package/src/commands/publish.mjs +1 -0
- package/src/commands/setup.mjs +667 -28
- package/src/core/approval.mjs +4 -6
- package/src/core/config.mjs +8 -8
- package/src/core/pkg-root.mjs +22 -0
- package/src/core/plan.mjs +9 -4
- package/src/core/run.mjs +4 -4
- package/src/core/trusted-resource.mjs +96 -0
- package/src/docs/version-gate.mjs +164 -0
- package/src/producers/build-adapters.mjs +512 -55
- package/src/snapshot/frozen.mjs +133 -3
- package/src/snapshot/public-map.mjs +7 -4
- package/src/snapshot/scan.mjs +2 -1
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { execFile as execFileCb } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { parseNodeMajor, meetsMinimum, computeReadinessStatus } from '../src/core/node-version.mjs';
|
|
7
|
+
|
|
8
|
+
const execFile = promisify(execFileCb);
|
|
9
|
+
|
|
10
|
+
const COMMANDS = new Set(['help', 'setup', 'assess', 'prepare', 'approve', 'publish', 'reconcile', 'verify', 'artifacts']);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if a command is available and get its version.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} command - The command to check.
|
|
16
|
+
* @param {string[]} versionArgs - Arguments to get version (e.g., ['--version']).
|
|
17
|
+
* @returns {Promise<{available: boolean, version: string|null, required: boolean, diagnostic: string}>}
|
|
18
|
+
*/
|
|
19
|
+
async function checkDependency(command, versionArgs = ['--version']) {
|
|
20
|
+
try {
|
|
21
|
+
const { stdout } = await execFile(command, versionArgs, {
|
|
22
|
+
shell: false,
|
|
23
|
+
encoding: 'utf8',
|
|
24
|
+
timeout: 5000,
|
|
25
|
+
});
|
|
26
|
+
const version = stdout.trim().split('\n')[0];
|
|
27
|
+
return {
|
|
28
|
+
available: true,
|
|
29
|
+
version,
|
|
30
|
+
required: command === 'node',
|
|
31
|
+
diagnostic: 'ok',
|
|
32
|
+
};
|
|
33
|
+
} catch (err) {
|
|
34
|
+
return {
|
|
35
|
+
available: false,
|
|
36
|
+
version: null,
|
|
37
|
+
required: command === 'node',
|
|
38
|
+
diagnostic: err.code === 'ENOENT' ? 'not found' : err.message,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Perform environment and dependency checks.
|
|
45
|
+
*
|
|
46
|
+
* @returns {Promise<object>} Environment check results.
|
|
47
|
+
*/
|
|
48
|
+
async function performEnvironmentChecks() {
|
|
49
|
+
const checks = {};
|
|
50
|
+
|
|
51
|
+
// Node.js
|
|
52
|
+
const nodeCheck = await checkDependency('node', ['--version']);
|
|
53
|
+
checks.node = {
|
|
54
|
+
...nodeCheck,
|
|
55
|
+
required: true,
|
|
56
|
+
minimumVersion: '22.0.0',
|
|
57
|
+
meetsMinimum: nodeCheck.available ? meetsMinimum(parseNodeMajor(nodeCheck.version), 22) : false,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Git
|
|
61
|
+
const gitCheck = await checkDependency('git', ['--version']);
|
|
62
|
+
checks.git = {
|
|
63
|
+
...gitCheck,
|
|
64
|
+
required: true,
|
|
65
|
+
usage: '版本控制和 baseline 捕获',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// pnpm
|
|
69
|
+
const pnpmCheck = await checkDependency('pnpm', ['--version']);
|
|
70
|
+
checks.pnpm = {
|
|
71
|
+
...pnpmCheck,
|
|
72
|
+
required: false,
|
|
73
|
+
usage: '包管理(推荐)',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// npm
|
|
77
|
+
const npmCheck = await checkDependency('npm', ['--version']);
|
|
78
|
+
checks.npm = {
|
|
79
|
+
...npmCheck,
|
|
80
|
+
required: false,
|
|
81
|
+
usage: '包发布',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// GitHub CLI
|
|
85
|
+
const ghCheck = await checkDependency('gh', ['--version']);
|
|
86
|
+
checks.gh = {
|
|
87
|
+
...ghCheck,
|
|
88
|
+
required: false,
|
|
89
|
+
usage: 'GitHub 操作',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const claudeCheck = await checkDependency('claude', ['--version']);
|
|
93
|
+
checks.claude = {
|
|
94
|
+
...claudeCheck,
|
|
95
|
+
required: false,
|
|
96
|
+
usage: '仅当计划声明 claude-plugin distribution 时用于消费者安装验证',
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const codexCheck = await checkDependency('codex', ['--version']);
|
|
100
|
+
checks.codex = {
|
|
101
|
+
...codexCheck,
|
|
102
|
+
required: false,
|
|
103
|
+
usage: '仅当计划声明 codex-plugin distribution 时用于消费者安装验证',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return checks;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get capability maturity information.
|
|
111
|
+
*
|
|
112
|
+
* @returns {object} Capability maturity information.
|
|
113
|
+
*/
|
|
114
|
+
function getCapabilityMaturity() {
|
|
115
|
+
return {
|
|
116
|
+
setup: {
|
|
117
|
+
available: true,
|
|
118
|
+
mode: 'read-only dry-run / confirmed create-once',
|
|
119
|
+
description: 'Discover first-use facts and create an absent config only after exact setupDigest confirmation',
|
|
120
|
+
},
|
|
121
|
+
assess: {
|
|
122
|
+
available: true,
|
|
123
|
+
mode: 'read-only',
|
|
124
|
+
description: 'Read-only assessment of project release readiness',
|
|
125
|
+
},
|
|
126
|
+
prepare: {
|
|
127
|
+
available: true,
|
|
128
|
+
mode: 'offline local writes',
|
|
129
|
+
description: 'Freeze a release plan with snapshots and gates',
|
|
130
|
+
},
|
|
131
|
+
publish: {
|
|
132
|
+
available: true,
|
|
133
|
+
mode: 'controlled production (protocol-tested; no OS/network sandbox)',
|
|
134
|
+
description: 'Publishes frozen GitHub/npm artifacts and runs configured Claude/Codex consumer checkpoints with approval and exact digest confirmation',
|
|
135
|
+
},
|
|
136
|
+
reconcile: {
|
|
137
|
+
available: true,
|
|
138
|
+
mode: 'evidence-based recovery (protocol-tested; no OS/network sandbox)',
|
|
139
|
+
description: 'Reconcile PARTIAL runs, retry safe missing checkpoints, and stop for human decisions on conflicts',
|
|
140
|
+
},
|
|
141
|
+
verify: {
|
|
142
|
+
available: true,
|
|
143
|
+
mode: 'fresh consumer verification (protocol-tested; no OS/network sandbox)',
|
|
144
|
+
description: 'Recheck remote state, exact npm installation, CLI help, and configured Claude/Codex installs before VERIFIED',
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function printHelp() {
|
|
150
|
+
console.log(`release-skill - Release governance Skill family
|
|
151
|
+
|
|
152
|
+
Usage:
|
|
153
|
+
release-skill <command> [options]
|
|
154
|
+
|
|
155
|
+
Commands:
|
|
156
|
+
help Show this help message and exit
|
|
157
|
+
setup Discover first-use configuration and gate candidates (dry-run by default)
|
|
158
|
+
assess Read-only assessment of project release readiness
|
|
159
|
+
prepare Freeze a release plan (release-skill output to .release-skill/; hooks may do remote ops)
|
|
160
|
+
approve Record local approval for a frozen release plan
|
|
161
|
+
publish Publish frozen GitHub/npm artifacts after approval and digest confirmation
|
|
162
|
+
reconcile Resume PARTIAL state from evidence; conflicts require a human
|
|
163
|
+
verify Fresh remote and consumer verification; only this reaches VERIFIED
|
|
164
|
+
artifacts Artifact status, inspect, update/apply, resolution, and diagnostics
|
|
165
|
+
|
|
166
|
+
Options:
|
|
167
|
+
--root <path> Project root directory (default: cwd)
|
|
168
|
+
--plan <path> Path to the release plan file
|
|
169
|
+
--run <path> Path to the release run file (required for reconcile/verify)
|
|
170
|
+
--approval <path> Path to the approval record
|
|
171
|
+
--production Prepare immutable Git/npm production artifacts
|
|
172
|
+
--confirm-production <digest> Confirm the exact production plan digest
|
|
173
|
+
--output <path> Override prepare/approve output path (non-production only)
|
|
174
|
+
--run-dir <path> Override prepare run directory; production requires one direct child of .release-skill/runs
|
|
175
|
+
--answers <path> Human-reviewed setup answers JSON
|
|
176
|
+
--write Create an absent project.yaml during setup; never overwrites
|
|
177
|
+
--confirm-setup <digest> Confirm exact setup facts and answers before create
|
|
178
|
+
--acknowledge-hook-side-effects Acknowledge unsandboxed legacy hook execution
|
|
179
|
+
--acknowledge-gate-side-effects Acknowledge unsandboxed local verification gate execution
|
|
180
|
+
--json Output results as JSON
|
|
181
|
+
--version Show version and exit
|
|
182
|
+
-h, --help Show this help message and exit
|
|
183
|
+
|
|
184
|
+
Safety:
|
|
185
|
+
Safe default: help -> setup (when config is absent) -> assess -> prepare --offline -> human review.
|
|
186
|
+
Production happy end: prepare --production -> approve -> publish -> verify.
|
|
187
|
+
prepare copies current public files into a local snapshot; it does not rewrite source files.
|
|
188
|
+
- Default mode is offline (release-skill pipeline does no remote writes)
|
|
189
|
+
- prepare output goes to .release-skill/ directory only
|
|
190
|
+
- User-configured hooks may write anywhere and perform remote operations
|
|
191
|
+
- To ensure zero remote writes, disable hooks or audit them separately
|
|
192
|
+
- publish requires explicit approval and an exact plan-digest confirmation
|
|
193
|
+
- publish consumes frozen Git/npm artifacts, never the live workspace
|
|
194
|
+
- existing remote objects and uncertain checks stop for human intervention
|
|
195
|
+
- production-equivalent protocol sandbox is verified; a real remote canary is not
|
|
196
|
+
|
|
197
|
+
First safe command:
|
|
198
|
+
release-skill help --json # Environment check (read-only)
|
|
199
|
+
release-skill setup --root <path> --json # First-use discovery (read-only)
|
|
200
|
+
release-skill assess --root <path> --offline --json # Project assessment`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const args = process.argv.slice(2);
|
|
204
|
+
const hasJson = args.includes('--json');
|
|
205
|
+
const positional = args.filter(a => !a.startsWith('--'));
|
|
206
|
+
const command = positional[0];
|
|
207
|
+
|
|
208
|
+
if (!command && (args.includes('--version') || args.includes('-v'))) {
|
|
209
|
+
const { createRequire } = await import('node:module');
|
|
210
|
+
const require = createRequire(import.meta.url);
|
|
211
|
+
const pkg = require('../package.json');
|
|
212
|
+
if (hasJson) {
|
|
213
|
+
console.log(JSON.stringify({
|
|
214
|
+
command: 'version',
|
|
215
|
+
status: 'READY',
|
|
216
|
+
name: pkg.name,
|
|
217
|
+
version: pkg.version,
|
|
218
|
+
}, null, 2));
|
|
219
|
+
} else {
|
|
220
|
+
console.log(pkg.version);
|
|
221
|
+
}
|
|
222
|
+
process.exit(0);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!command || command === 'help') {
|
|
226
|
+
if (hasJson) {
|
|
227
|
+
// Perform environment checks for --json mode
|
|
228
|
+
const checks = await performEnvironmentChecks();
|
|
229
|
+
const capabilities = getCapabilityMaturity();
|
|
230
|
+
|
|
231
|
+
// Compute readiness: Node >=22 and Git are required; pnpm/npm/gh are optional
|
|
232
|
+
const readiness = computeReadinessStatus({
|
|
233
|
+
nodeAvailable: checks.node.available,
|
|
234
|
+
nodeMeetsMinimum: checks.node.meetsMinimum,
|
|
235
|
+
gitAvailable: checks.git.available,
|
|
236
|
+
});
|
|
237
|
+
const missingRequired = [];
|
|
238
|
+
if (!checks.node.available || !checks.node.meetsMinimum) missingRequired.push('node>=22');
|
|
239
|
+
if (!checks.git.available) missingRequired.push('git');
|
|
240
|
+
const productionMissing = [
|
|
241
|
+
...missingRequired,
|
|
242
|
+
...(!checks.npm.available ? ['npm'] : []),
|
|
243
|
+
...(!checks.gh.available ? ['gh'] : []),
|
|
244
|
+
];
|
|
245
|
+
|
|
246
|
+
const output = {
|
|
247
|
+
command: 'help',
|
|
248
|
+
mode: 'environment-check',
|
|
249
|
+
status: readiness.status,
|
|
250
|
+
missingRequired,
|
|
251
|
+
readiness: {
|
|
252
|
+
localPreparation: {
|
|
253
|
+
status: readiness.status,
|
|
254
|
+
missingRequired,
|
|
255
|
+
},
|
|
256
|
+
productionPublish: {
|
|
257
|
+
status: productionMissing.length > 0 ? 'NOT_READY' : 'AUTH_CHECK_REQUIRED',
|
|
258
|
+
missingRequired: productionMissing,
|
|
259
|
+
authentication: '运行生产发布前还需验证 gh auth、Git HTTPS credential 与 npm auth;help 不发起网络认证检查。',
|
|
260
|
+
conditionalConsumers: {
|
|
261
|
+
claude: '声明 claude-plugin distribution 时必须可用',
|
|
262
|
+
codex: '声明 codex-plugin distribution 时必须可用',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
checks,
|
|
267
|
+
capabilities,
|
|
268
|
+
maturity: {
|
|
269
|
+
setup: 'read-only by default; create-once requires answers plus exact setupDigest confirmation',
|
|
270
|
+
assess: 'read-only (default); --output writes local report',
|
|
271
|
+
prepare: 'offline local writes; configured hooks/gates require their explicit side-effect acknowledgements',
|
|
272
|
+
onlinePrepare: 'previous-public-baseline observation available; production mode freezes publish artifacts and fails closed on drift or unknown state',
|
|
273
|
+
publish: 'GitHub/npm plus configured Claude/Codex consumer checkpoints are protocol-tested without an OS/network sandbox; approval and exact digest confirmation required',
|
|
274
|
+
reconcile: 'PARTIAL recovery is protocol-tested without an OS/network sandbox; remote conflicts require human intervention',
|
|
275
|
+
verify: 'fresh exact npm and Claude/Codex consumer installation checks are protocol-tested without an OS/network sandbox; configured consumer processes require explicit acknowledgement; success reaches VERIFIED',
|
|
276
|
+
},
|
|
277
|
+
recommendations: [],
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// Add recommendations based on checks
|
|
281
|
+
if (!checks.node.available) {
|
|
282
|
+
output.recommendations.push('Install Node.js >= 22.0.0');
|
|
283
|
+
} else if (checks.node.available && !checks.node.meetsMinimum) {
|
|
284
|
+
output.recommendations.push('Upgrade Node.js to version 22 or later');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!checks.git.available) {
|
|
288
|
+
output.recommendations.push('Install Git for version control operations');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!checks.pnpm.available) {
|
|
292
|
+
output.recommendations.push('Install pnpm for package management (optional)');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (!checks.npm.available) {
|
|
296
|
+
output.recommendations.push('Install npm for package publishing (optional)');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!checks.gh.available) {
|
|
300
|
+
output.recommendations.push('Install GitHub CLI for GitHub operations (optional)');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (!checks.claude.available) {
|
|
304
|
+
output.recommendations.push('Install Claude CLI before releasing a configured claude-plugin distribution');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!checks.codex.available) {
|
|
308
|
+
output.recommendations.push('Install Codex CLI before releasing a configured codex-plugin distribution');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
console.log(JSON.stringify(output, null, 2));
|
|
312
|
+
process.exit(readiness.status === 'READY' ? 0 : 1);
|
|
313
|
+
} else {
|
|
314
|
+
printHelp();
|
|
315
|
+
process.exit(0);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!COMMANDS.has(command)) {
|
|
320
|
+
if (hasJson) {
|
|
321
|
+
const output = {
|
|
322
|
+
error: 'UNKNOWN_COMMAND',
|
|
323
|
+
message: `Unknown command: ${command}`,
|
|
324
|
+
exitCode: 2
|
|
325
|
+
};
|
|
326
|
+
console.log(JSON.stringify(output));
|
|
327
|
+
} else {
|
|
328
|
+
console.error(`Error: Unknown command '${command}'`);
|
|
329
|
+
console.error('Run "release-skill help" for available commands.');
|
|
330
|
+
}
|
|
331
|
+
process.exit(2);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// --- Setup command routing ---
|
|
335
|
+
if (command === 'setup') {
|
|
336
|
+
const rootIdx = args.indexOf('--root');
|
|
337
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
338
|
+
const root = resolve(rawRoot);
|
|
339
|
+
const answersIdx = args.indexOf('--answers');
|
|
340
|
+
const answersPath = answersIdx !== -1 && args[answersIdx + 1] ? args[answersIdx + 1] : undefined;
|
|
341
|
+
const confirmationIdx = args.indexOf('--confirm-setup');
|
|
342
|
+
const confirmSetup = confirmationIdx !== -1 && args[confirmationIdx + 1]
|
|
343
|
+
? args[confirmationIdx + 1]
|
|
344
|
+
: undefined;
|
|
345
|
+
const write = args.includes('--write');
|
|
346
|
+
try {
|
|
347
|
+
const { setupProject } = await import('../src/commands/setup.mjs');
|
|
348
|
+
const report = await setupProject({ root, answersPath, write, confirmSetup });
|
|
349
|
+
if (hasJson) {
|
|
350
|
+
console.log(JSON.stringify(report, null, 2));
|
|
351
|
+
} else {
|
|
352
|
+
console.log(`Setup status: ${report.status}`);
|
|
353
|
+
if (report.setupDigest) console.log(`Setup digest: ${report.setupDigest}`);
|
|
354
|
+
if (report.configPath) console.log(`Config: ${report.configPath}`);
|
|
355
|
+
if (report.next) console.log(`Next: ${report.next}`);
|
|
356
|
+
}
|
|
357
|
+
process.exit(['READY_TO_WRITE', 'CONFIG_CREATED', 'ALREADY_CONFIGURED'].includes(report.status) ? 0 : 2);
|
|
358
|
+
} catch (err) {
|
|
359
|
+
if (hasJson) {
|
|
360
|
+
console.log(JSON.stringify({
|
|
361
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
362
|
+
message: err.message,
|
|
363
|
+
details: err.details ?? {},
|
|
364
|
+
exitCode: err.exitCode ?? 1,
|
|
365
|
+
}));
|
|
366
|
+
} else {
|
|
367
|
+
console.error(`Error: ${err.message}`);
|
|
368
|
+
}
|
|
369
|
+
process.exit(err.exitCode ?? 1);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// --- Assess command routing ---
|
|
374
|
+
if (command === 'assess') {
|
|
375
|
+
const rootIdx = args.indexOf('--root');
|
|
376
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
377
|
+
const root = resolve(rawRoot);
|
|
378
|
+
const offline = args.includes('--offline') || !args.includes('--online');
|
|
379
|
+
const outputIdx = args.indexOf('--output');
|
|
380
|
+
const output = outputIdx !== -1 && args[outputIdx + 1] ? args[outputIdx + 1] : undefined;
|
|
381
|
+
|
|
382
|
+
try {
|
|
383
|
+
const { assessProject } = await import('../src/commands/assess.mjs');
|
|
384
|
+
const report = await assessProject({ root, offline, output });
|
|
385
|
+
|
|
386
|
+
if (hasJson) {
|
|
387
|
+
console.log(JSON.stringify(report, null, 2));
|
|
388
|
+
} else {
|
|
389
|
+
console.log(report.summary);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
process.exit(report.status === 'ASSESSED' ? 0 : 1);
|
|
393
|
+
} catch (err) {
|
|
394
|
+
if (hasJson) {
|
|
395
|
+
const errOutput = {
|
|
396
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
397
|
+
message: err.message,
|
|
398
|
+
details: err.details ?? {},
|
|
399
|
+
exitCode: err.exitCode ?? 1,
|
|
400
|
+
};
|
|
401
|
+
console.log(JSON.stringify(errOutput));
|
|
402
|
+
} else {
|
|
403
|
+
console.error(`Error: ${err.message}`);
|
|
404
|
+
}
|
|
405
|
+
process.exit(err.exitCode ?? 1);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// --- Prepare command routing ---
|
|
410
|
+
if (command === 'prepare') {
|
|
411
|
+
const rootIdx = args.indexOf('--root');
|
|
412
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
413
|
+
const root = resolve(rawRoot);
|
|
414
|
+
const offline = args.includes('--offline') || !args.includes('--online');
|
|
415
|
+
|
|
416
|
+
// Resolve target version from --target-version or --version flag
|
|
417
|
+
let targetVersion;
|
|
418
|
+
for (const flag of ['--target-version', '--version']) {
|
|
419
|
+
const idx = args.indexOf(flag);
|
|
420
|
+
if (idx !== -1 && args[idx + 1]) {
|
|
421
|
+
targetVersion = args[idx + 1];
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const hooksAuthorized = args.includes('--acknowledge-hook-side-effects');
|
|
427
|
+
const verificationGatesAuthorized = args.includes('--acknowledge-gate-side-effects');
|
|
428
|
+
const production = args.includes('--production');
|
|
429
|
+
const outputIdx = args.indexOf('--output');
|
|
430
|
+
const output = outputIdx !== -1 && args[outputIdx + 1] ? resolve(args[outputIdx + 1]) : undefined;
|
|
431
|
+
const runDirIdx = args.indexOf('--run-dir');
|
|
432
|
+
const runDir = runDirIdx !== -1 && args[runDirIdx + 1] ? resolve(args[runDirIdx + 1]) : undefined;
|
|
433
|
+
|
|
434
|
+
try {
|
|
435
|
+
const { prepareRelease } = await import('../src/commands/prepare.mjs');
|
|
436
|
+
const { readFile: readFileFs } = await import('node:fs/promises');
|
|
437
|
+
const result = await prepareRelease({
|
|
438
|
+
root,
|
|
439
|
+
version: targetVersion,
|
|
440
|
+
offline,
|
|
441
|
+
hooksAuthorized,
|
|
442
|
+
verificationGatesAuthorized,
|
|
443
|
+
production,
|
|
444
|
+
output,
|
|
445
|
+
runDir,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
if (hasJson) {
|
|
449
|
+
// Output the full plan object plus metadata so consumers
|
|
450
|
+
// can inspect status, units, externalActions, planDigest, etc.
|
|
451
|
+
const planContent = await readFileFs(result.planPath, 'utf8');
|
|
452
|
+
const plan = JSON.parse(planContent);
|
|
453
|
+
console.log(JSON.stringify({
|
|
454
|
+
...plan,
|
|
455
|
+
planPath: result.planPath,
|
|
456
|
+
planDigest: result.planDigest,
|
|
457
|
+
evidenceDir: result.evidenceDir,
|
|
458
|
+
}, null, 2));
|
|
459
|
+
} else {
|
|
460
|
+
console.log(`Plan frozen at: ${result.planPath}`);
|
|
461
|
+
console.log(`Plan digest: ${result.planDigest}`);
|
|
462
|
+
console.log(`Evidence: ${result.evidenceDir}`);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
process.exit(0);
|
|
466
|
+
} catch (err) {
|
|
467
|
+
if (hasJson) {
|
|
468
|
+
const errOutput = {
|
|
469
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
470
|
+
message: err.message,
|
|
471
|
+
details: err.details ?? {},
|
|
472
|
+
exitCode: err.exitCode ?? 1,
|
|
473
|
+
};
|
|
474
|
+
console.log(JSON.stringify(errOutput));
|
|
475
|
+
} else {
|
|
476
|
+
console.error(`Error: ${err.message}`);
|
|
477
|
+
}
|
|
478
|
+
process.exit(err.exitCode ?? 1);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// --- Approve command routing ---
|
|
483
|
+
if (command === 'approve') {
|
|
484
|
+
|
|
485
|
+
const planIdx = args.indexOf('--plan');
|
|
486
|
+
const planPath = planIdx !== -1 && args[planIdx + 1] ? args[planIdx + 1] : undefined;
|
|
487
|
+
const digestIdx = args.indexOf('--digest');
|
|
488
|
+
const expectedDigest = digestIdx !== -1 && args[digestIdx + 1] ? args[digestIdx + 1] : undefined;
|
|
489
|
+
const actorIdx = args.indexOf('--actor');
|
|
490
|
+
const actor = actorIdx !== -1 && args[actorIdx + 1] ? args[actorIdx + 1] : undefined;
|
|
491
|
+
const outputIdx = args.indexOf('--output');
|
|
492
|
+
const outputPath = outputIdx !== -1 && args[outputIdx + 1] ? resolve(args[outputIdx + 1]) : undefined;
|
|
493
|
+
|
|
494
|
+
if (!planPath || !expectedDigest || !actor) {
|
|
495
|
+
const msg = 'approve requires --plan <path>, --digest <sha256>, and --actor <name>';
|
|
496
|
+
if (hasJson) {
|
|
497
|
+
console.log(JSON.stringify({ error: 'MISSING_PARAMETERS', message: msg, exitCode: 1 }));
|
|
498
|
+
} else {
|
|
499
|
+
console.error(`Error: ${msg}`);
|
|
500
|
+
}
|
|
501
|
+
process.exit(1);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
const { approvePlan } = await import('../src/commands/approve.mjs');
|
|
506
|
+
const resolvedPlanPath = resolve(planPath);
|
|
507
|
+
const planDir = dirname(resolvedPlanPath);
|
|
508
|
+
const releaseDir = basename(planDir) === 'plans' && basename(resolvedPlanPath) === `${expectedDigest}.json`
|
|
509
|
+
? dirname(planDir)
|
|
510
|
+
: planDir;
|
|
511
|
+
const approvalPath = outputPath ?? join(releaseDir, 'approval-record.json');
|
|
512
|
+
const record = await approvePlan({ planPath, expectedDigest, actor, outputPath: approvalPath });
|
|
513
|
+
|
|
514
|
+
if (hasJson) {
|
|
515
|
+
console.log(JSON.stringify(record, null, 2));
|
|
516
|
+
} else {
|
|
517
|
+
console.log(`Plan approved by ${record.actor}`);
|
|
518
|
+
console.log(`Approval record: ${record.approvalPath}`);
|
|
519
|
+
console.log(`Expires at: ${record.expiresAt}`);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
process.exit(0);
|
|
523
|
+
} catch (err) {
|
|
524
|
+
if (hasJson) {
|
|
525
|
+
const errOutput = {
|
|
526
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
527
|
+
message: err.message,
|
|
528
|
+
exitCode: err.exitCode ?? 1,
|
|
529
|
+
};
|
|
530
|
+
console.log(JSON.stringify(errOutput));
|
|
531
|
+
} else {
|
|
532
|
+
console.error(`Error: ${err.message}`);
|
|
533
|
+
}
|
|
534
|
+
process.exit(err.exitCode ?? 1);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// --- Reconcile command routing ---
|
|
539
|
+
if (command === 'reconcile') {
|
|
540
|
+
|
|
541
|
+
const rootIdx = args.indexOf('--root');
|
|
542
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
543
|
+
const root = resolve(rawRoot);
|
|
544
|
+
const planIdx = args.indexOf('--plan');
|
|
545
|
+
const planPath = planIdx !== -1 && args[planIdx + 1] ? resolve(args[planIdx + 1]) : undefined;
|
|
546
|
+
const runIdx = args.indexOf('--run');
|
|
547
|
+
const runPath = runIdx !== -1 && args[runIdx + 1] ? resolve(args[runIdx + 1]) : undefined;
|
|
548
|
+
const approvalIdx = args.indexOf('--approval');
|
|
549
|
+
const approvalPath = approvalIdx !== -1 && args[approvalIdx + 1] ? resolve(args[approvalIdx + 1]) : undefined;
|
|
550
|
+
const confirmationIdx = args.indexOf('--confirm-production');
|
|
551
|
+
const productionConfirmation = confirmationIdx !== -1 && args[confirmationIdx + 1]
|
|
552
|
+
? args[confirmationIdx + 1]
|
|
553
|
+
: undefined;
|
|
554
|
+
|
|
555
|
+
if (!planPath || !runPath) {
|
|
556
|
+
const msg = 'reconcile requires --plan <path> and --run <path>';
|
|
557
|
+
if (hasJson) {
|
|
558
|
+
console.log(JSON.stringify({ error: 'MISSING_PARAMETERS', message: msg, exitCode: 1 }));
|
|
559
|
+
} else {
|
|
560
|
+
console.error(`Error: ${msg}`);
|
|
561
|
+
}
|
|
562
|
+
process.exit(1);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
try {
|
|
566
|
+
const { reconcileRelease } = await import('../src/commands/reconcile.mjs');
|
|
567
|
+
const { createGitGithubAdapter } = await import('../src/adapters/git-github.mjs');
|
|
568
|
+
const { createNpmAdapter } = await import('../src/adapters/npm.mjs');
|
|
569
|
+
const { createPluginMarketplaceAdapter } = await import('../src/adapters/plugin-marketplace.mjs');
|
|
570
|
+
const { createPushSnapshotAdapter } = await import('../src/adapters/push-snapshot.mjs');
|
|
571
|
+
const { createAdapterRegistry } = await import('../src/adapters/contract.mjs');
|
|
572
|
+
const registry = createAdapterRegistry([
|
|
573
|
+
createGitGithubAdapter(),
|
|
574
|
+
createNpmAdapter(),
|
|
575
|
+
createPluginMarketplaceAdapter(),
|
|
576
|
+
createPushSnapshotAdapter(),
|
|
577
|
+
]);
|
|
578
|
+
|
|
579
|
+
const result = await reconcileRelease({
|
|
580
|
+
planPath,
|
|
581
|
+
sourceRunPath: runPath,
|
|
582
|
+
approvalPath,
|
|
583
|
+
adapterRegistry: registry,
|
|
584
|
+
root,
|
|
585
|
+
productionConfirmation,
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
if (hasJson) {
|
|
589
|
+
console.log(JSON.stringify(result, null, 2));
|
|
590
|
+
} else {
|
|
591
|
+
console.log(`Reconcile status: ${result.status}`);
|
|
592
|
+
for (const cp of result.checkpoints) {
|
|
593
|
+
console.log(` ${cp.actionId}: ${cp.status}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
process.exit(result.status === 'PUBLISHED' ? 0 : 1);
|
|
598
|
+
} catch (err) {
|
|
599
|
+
if (hasJson) {
|
|
600
|
+
const errOutput = {
|
|
601
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
602
|
+
message: err.message,
|
|
603
|
+
exitCode: err.exitCode ?? 1,
|
|
604
|
+
};
|
|
605
|
+
console.log(JSON.stringify(errOutput));
|
|
606
|
+
} else {
|
|
607
|
+
console.error(`Error: ${err.message}`);
|
|
608
|
+
}
|
|
609
|
+
process.exit(err.exitCode ?? 1);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// --- Verify command routing ---
|
|
614
|
+
if (command === 'verify') {
|
|
615
|
+
|
|
616
|
+
const rootIdx = args.indexOf('--root');
|
|
617
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
618
|
+
const root = resolve(rawRoot);
|
|
619
|
+
const planIdx = args.indexOf('--plan');
|
|
620
|
+
const planPath = planIdx !== -1 && args[planIdx + 1] ? resolve(args[planIdx + 1]) : undefined;
|
|
621
|
+
const runIdx = args.indexOf('--run');
|
|
622
|
+
const runPath = runIdx !== -1 && args[runIdx + 1] ? resolve(args[runIdx + 1]) : undefined;
|
|
623
|
+
const verificationGatesAuthorized = args.includes('--acknowledge-gate-side-effects');
|
|
624
|
+
|
|
625
|
+
if (!planPath || !runPath) {
|
|
626
|
+
const msg = 'verify requires --plan <path> and --run <path>';
|
|
627
|
+
if (hasJson) {
|
|
628
|
+
console.log(JSON.stringify({ error: 'MISSING_PARAMETERS', message: msg, exitCode: 1 }));
|
|
629
|
+
} else {
|
|
630
|
+
console.error(`Error: ${msg}`);
|
|
631
|
+
}
|
|
632
|
+
process.exit(1);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
try {
|
|
636
|
+
const { verifyRelease } = await import('../src/commands/verify.mjs');
|
|
637
|
+
const { createGitGithubAdapter } = await import('../src/adapters/git-github.mjs');
|
|
638
|
+
const { createNpmAdapter } = await import('../src/adapters/npm.mjs');
|
|
639
|
+
const { createPluginMarketplaceAdapter } = await import('../src/adapters/plugin-marketplace.mjs');
|
|
640
|
+
const { createPushSnapshotAdapter } = await import('../src/adapters/push-snapshot.mjs');
|
|
641
|
+
const { createAdapterRegistry } = await import('../src/adapters/contract.mjs');
|
|
642
|
+
const registry = createAdapterRegistry([
|
|
643
|
+
createGitGithubAdapter(),
|
|
644
|
+
createNpmAdapter(),
|
|
645
|
+
createPluginMarketplaceAdapter(),
|
|
646
|
+
createPushSnapshotAdapter(),
|
|
647
|
+
]);
|
|
648
|
+
|
|
649
|
+
const result = await verifyRelease({
|
|
650
|
+
planPath,
|
|
651
|
+
sourceRunPath: runPath,
|
|
652
|
+
adapterRegistry: registry,
|
|
653
|
+
root,
|
|
654
|
+
verificationGatesAuthorized,
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
if (hasJson) {
|
|
658
|
+
console.log(JSON.stringify(result, null, 2));
|
|
659
|
+
} else {
|
|
660
|
+
console.log(`Verify status: ${result.status}`);
|
|
661
|
+
console.log(`Adapter checks: ${result.adapterChecks.length} passed`);
|
|
662
|
+
console.log(`Smoke test: ${result.smokeTest.passed ? 'PASSED' : 'FAILED'}`);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
process.exit(result.status === 'VERIFIED' ? 0 : 1);
|
|
666
|
+
} catch (err) {
|
|
667
|
+
if (hasJson) {
|
|
668
|
+
const errOutput = {
|
|
669
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
670
|
+
message: err.message,
|
|
671
|
+
exitCode: err.exitCode ?? 1,
|
|
672
|
+
};
|
|
673
|
+
console.log(JSON.stringify(errOutput));
|
|
674
|
+
} else {
|
|
675
|
+
console.error(`Error: ${err.message}`);
|
|
676
|
+
}
|
|
677
|
+
process.exit(err.exitCode ?? 1);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// --- Publish command routing ---
|
|
682
|
+
if (command === 'publish') {
|
|
683
|
+
|
|
684
|
+
const rootIdx = args.indexOf('--root');
|
|
685
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
686
|
+
const root = resolve(rawRoot);
|
|
687
|
+
const planIdx = args.indexOf('--plan');
|
|
688
|
+
const planPath = planIdx !== -1 && args[planIdx + 1] ? resolve(args[planIdx + 1]) : undefined;
|
|
689
|
+
const approvalIdx = args.indexOf('--approval');
|
|
690
|
+
const approvalPath = approvalIdx !== -1 && args[approvalIdx + 1] ? resolve(args[approvalIdx + 1]) : undefined;
|
|
691
|
+
const confirmationIdx = args.indexOf('--confirm-production');
|
|
692
|
+
const productionConfirmation = confirmationIdx !== -1 && args[confirmationIdx + 1]
|
|
693
|
+
? args[confirmationIdx + 1]
|
|
694
|
+
: undefined;
|
|
695
|
+
|
|
696
|
+
if (!planPath || !approvalPath || !productionConfirmation) {
|
|
697
|
+
const msg = 'publish requires --plan <path>, --approval <path>, and --confirm-production <plan-digest>';
|
|
698
|
+
if (hasJson) {
|
|
699
|
+
console.log(JSON.stringify({ error: 'MISSING_PARAMETERS', message: msg, exitCode: 1 }));
|
|
700
|
+
} else {
|
|
701
|
+
console.error(`Error: ${msg}`);
|
|
702
|
+
}
|
|
703
|
+
process.exit(1);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
try {
|
|
707
|
+
const { publishRelease } = await import('../src/commands/publish.mjs');
|
|
708
|
+
const { createGitGithubAdapter } = await import('../src/adapters/git-github.mjs');
|
|
709
|
+
const { createNpmAdapter } = await import('../src/adapters/npm.mjs');
|
|
710
|
+
const { createPluginMarketplaceAdapter } = await import('../src/adapters/plugin-marketplace.mjs');
|
|
711
|
+
const { createPushSnapshotAdapter } = await import('../src/adapters/push-snapshot.mjs');
|
|
712
|
+
const { createAdapterRegistry } = await import('../src/adapters/contract.mjs');
|
|
713
|
+
const registry = createAdapterRegistry([
|
|
714
|
+
createGitGithubAdapter(),
|
|
715
|
+
createNpmAdapter(),
|
|
716
|
+
createPluginMarketplaceAdapter(),
|
|
717
|
+
createPushSnapshotAdapter(),
|
|
718
|
+
]);
|
|
719
|
+
|
|
720
|
+
const result = await publishRelease({
|
|
721
|
+
planPath,
|
|
722
|
+
approvalPath,
|
|
723
|
+
adapterRegistry: registry,
|
|
724
|
+
root,
|
|
725
|
+
productionMode: true,
|
|
726
|
+
productionConfirmation,
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
if (hasJson) {
|
|
730
|
+
console.log(JSON.stringify(result, null, 2));
|
|
731
|
+
} else {
|
|
732
|
+
console.log(`Publish status: ${result.status}`);
|
|
733
|
+
for (const cp of result.checkpoints) {
|
|
734
|
+
console.log(` ${cp.actionId}: ${cp.status}`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
process.exit(result.status === 'PUBLISHED' ? 0 : 1);
|
|
739
|
+
} catch (err) {
|
|
740
|
+
if (hasJson) {
|
|
741
|
+
const errOutput = {
|
|
742
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
743
|
+
message: err.message,
|
|
744
|
+
exitCode: err.exitCode ?? 1,
|
|
745
|
+
};
|
|
746
|
+
console.log(JSON.stringify(errOutput));
|
|
747
|
+
} else {
|
|
748
|
+
console.error(`Error: ${err.message}`);
|
|
749
|
+
}
|
|
750
|
+
process.exit(err.exitCode ?? 1);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// --- Artifacts command routing ---
|
|
755
|
+
if (command === 'artifacts') {
|
|
756
|
+
const rootIdx = args.indexOf('--root');
|
|
757
|
+
const rawRoot = rootIdx !== -1 && args[rootIdx + 1] ? args[rootIdx + 1] : process.cwd();
|
|
758
|
+
const root = resolve(rawRoot);
|
|
759
|
+
const outputIdx = args.indexOf('--output');
|
|
760
|
+
const output = outputIdx !== -1 && args[outputIdx + 1] ? resolve(args[outputIdx + 1]) : undefined;
|
|
761
|
+
|
|
762
|
+
const subcommand = positional[1] ?? 'status';
|
|
763
|
+
|
|
764
|
+
try {
|
|
765
|
+
const { runArtifactsCommand } = await import('../src/commands/artifacts.mjs');
|
|
766
|
+
const result = await runArtifactsCommand({ subcommand, args, root });
|
|
767
|
+
|
|
768
|
+
if (hasJson) {
|
|
769
|
+
console.log(JSON.stringify(result, null, 2));
|
|
770
|
+
} else {
|
|
771
|
+
console.log(`Status: ${result.status}`);
|
|
772
|
+
console.log(`Safe to write: ${result.safeToWrite}`);
|
|
773
|
+
console.log(`Target unchanged: ${result.targetUnchanged}`);
|
|
774
|
+
if (result.nextAction) {
|
|
775
|
+
console.log(`Next action: ${result.nextAction.command}`);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Exit code: 0 if clean/safe/drift-detected (dry-run), 1 if blocking
|
|
780
|
+
const blockingStatuses = new Set([
|
|
781
|
+
'BASE_UNAVAILABLE', 'POLICY_INVALID', 'PATH_UNSAFE',
|
|
782
|
+
'CONFLICT', 'DIRTY_SCOPE_CONFLICT',
|
|
783
|
+
]);
|
|
784
|
+
process.exit(blockingStatuses.has(result.status) ? 1 : 0);
|
|
785
|
+
} catch (err) {
|
|
786
|
+
if (hasJson) {
|
|
787
|
+
const errOutput = {
|
|
788
|
+
error: err.code ?? 'UNKNOWN_ERROR',
|
|
789
|
+
message: err.message,
|
|
790
|
+
status: err.code ?? 'UNKNOWN_ERROR',
|
|
791
|
+
safeToWrite: false,
|
|
792
|
+
targetUnchanged: true,
|
|
793
|
+
evidenceDir: null,
|
|
794
|
+
nextAction: { command: 'artifacts inspect --root <path>' },
|
|
795
|
+
exitCode: err.exitCode ?? 1,
|
|
796
|
+
};
|
|
797
|
+
console.log(JSON.stringify(errOutput));
|
|
798
|
+
} else {
|
|
799
|
+
console.error(`Error: ${err.message}`);
|
|
800
|
+
}
|
|
801
|
+
process.exit(err.exitCode ?? 1);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// Placeholder: remaining commands will be wired in later tasks
|
|
806
|
+
console.error(`Command '${command}' is not yet implemented.`);
|
|
807
|
+
process.exit(1);
|