agentdock-cli 0.7.0 → 1.0.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/dist/src/cli.js CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.runCli = runCli;
5
8
  const export_1 = require("./commands/export");
@@ -12,7 +15,14 @@ const validate_1 = require("./commands/validate");
12
15
  const diff_1 = require("./commands/diff");
13
16
  const config_1 = require("./commands/config");
14
17
  const uninstall_1 = require("./commands/uninstall");
18
+ const sync_1 = require("./commands/sync");
19
+ const pack_1 = require("./commands/pack");
20
+ const verify_1 = require("./commands/verify");
21
+ const attest_1 = require("./commands/attest");
22
+ const keygen_1 = require("./commands/keygen");
23
+ const sign_1 = require("./commands/sign");
15
24
  const i18n_1 = require("./i18n");
25
+ const package_json_1 = __importDefault(require("../package.json"));
16
26
  function parseCliOptions(args) {
17
27
  const positionals = [];
18
28
  const options = {};
@@ -42,6 +52,44 @@ function parseCliOptions(args) {
42
52
  options.force = true;
43
53
  continue;
44
54
  }
55
+ if (arg === '--apply') {
56
+ options.apply = true;
57
+ continue;
58
+ }
59
+ if (arg === '--with-env') {
60
+ options.withEnv = true;
61
+ continue;
62
+ }
63
+ if (arg === '--undo') {
64
+ options.undo = true;
65
+ continue;
66
+ }
67
+ if (arg === '--zip') {
68
+ options.zip = true;
69
+ continue;
70
+ }
71
+ if (arg === '--strict') {
72
+ options.strict = true;
73
+ continue;
74
+ }
75
+ if (arg === '--mode' || arg === '--include' || arg === '--exclude' || arg === '--config') {
76
+ const nextArg = args[index + 1];
77
+ if (nextArg && !nextArg.startsWith('--')) {
78
+ if (arg === '--mode')
79
+ options.mode = nextArg === 'selective' ? 'selective' : 'full';
80
+ if (arg === '--include')
81
+ (options.include ??= []).push(nextArg);
82
+ if (arg === '--exclude')
83
+ (options.exclude ??= []).push(nextArg);
84
+ if (arg === '--config')
85
+ options.config = nextArg;
86
+ index += 1;
87
+ }
88
+ else {
89
+ positionals.push(arg);
90
+ }
91
+ continue;
92
+ }
45
93
  if (arg === '--write') {
46
94
  const nextArg = args[index + 1];
47
95
  if (nextArg && !nextArg.startsWith('--')) {
@@ -96,6 +144,20 @@ function parseCliOptions(args) {
96
144
  }
97
145
  continue;
98
146
  }
147
+ if (arg === '--key' || arg === '--signature') {
148
+ const nextArg = args[index + 1];
149
+ if (nextArg && !nextArg.startsWith('--')) {
150
+ if (arg === '--key')
151
+ options.key = nextArg;
152
+ if (arg === '--signature')
153
+ options.signature = nextArg;
154
+ index += 1;
155
+ }
156
+ else {
157
+ positionals.push(arg);
158
+ }
159
+ continue;
160
+ }
99
161
  positionals.push(arg);
100
162
  }
101
163
  return { positionals, options };
@@ -103,14 +165,38 @@ function parseCliOptions(args) {
103
165
  async function runCli(args) {
104
166
  await (0, i18n_1.initI18n)();
105
167
  const [command, ...rest] = args;
168
+ if (command === '--help' || command === '-h' || command === 'help') {
169
+ return {
170
+ exitCode: 0,
171
+ stdout: [(0, i18n_1.t)('cli.usage'), (0, i18n_1.t)('cli.help.commands'), (0, i18n_1.t)('cli.help.docs')],
172
+ stderr: [],
173
+ };
174
+ }
175
+ if (command === '--version' || command === '-v' || command === 'version') {
176
+ return {
177
+ exitCode: 0,
178
+ stdout: [(0, i18n_1.t)('cli.version', { version: package_json_1.default.version })],
179
+ stderr: [],
180
+ };
181
+ }
106
182
  const { positionals, options } = parseCliOptions(rest);
107
183
  switch (command) {
108
184
  case 'validate':
109
185
  return (0, validate_1.runValidateCommand)(positionals[0], options);
110
186
  case 'export':
111
187
  return (0, export_1.runExportCommand)(positionals[0], options);
188
+ case 'pack':
189
+ return (0, pack_1.runPackCommand)(options);
112
190
  case 'install':
113
191
  return (0, install_1.runInstallCommand)(positionals[0], positionals[1], options);
192
+ case 'verify':
193
+ return (0, verify_1.runVerifyCommand)(positionals[0], options);
194
+ case 'attest':
195
+ return (0, attest_1.runAttestCommand)(positionals[0], options);
196
+ case 'keygen':
197
+ return (0, keygen_1.runKeygenCommand)(options);
198
+ case 'sign':
199
+ return (0, sign_1.runSignCommand)(positionals[0], options);
114
200
  case 'scan':
115
201
  return (0, scan_1.runScanCommand)(options);
116
202
  case 'doctor':
@@ -125,6 +211,8 @@ async function runCli(args) {
125
211
  return (0, config_1.runConfigCommand)(positionals, options);
126
212
  case 'uninstall':
127
213
  return (0, uninstall_1.runUninstallCommand)(positionals[0], positionals[1], options);
214
+ case 'sync':
215
+ return (0, sync_1.runSyncCommand)(positionals[0], positionals[1], options);
128
216
  default:
129
217
  return {
130
218
  exitCode: 1,
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runAttestCommand = runAttestCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const attest_1 = require("../core/attest");
9
+ const command_error_codes_1 = require("../constants/command-error-codes");
10
+ const i18n_1 = require("../i18n");
11
+ const command_json_1 = require("../utils/command-json");
12
+ const fs_1 = require("../utils/fs");
13
+ async function runAttestCommand(packagePath, options = {}) {
14
+ if (!packagePath) {
15
+ if (options.json === true) {
16
+ return {
17
+ exitCode: 1,
18
+ stdout: [(0, command_json_1.toJsonLine)('attest', false, { packagePath: null }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, (0, i18n_1.t)('attest.usage'))])],
19
+ stderr: [],
20
+ };
21
+ }
22
+ return { exitCode: 1, stdout: [], stderr: [(0, i18n_1.t)('attest.usage')] };
23
+ }
24
+ try {
25
+ const result = await (0, attest_1.attestPackage)(packagePath);
26
+ // 默认非阻塞;--strict 时高风险退出码 2(与 doctor 的“发现严重问题”约定一致)。
27
+ const exitCode = options.strict === true && result.summary.high > 0 ? 2 : 0;
28
+ if (options.json === true) {
29
+ const line = (0, command_json_1.toJsonLine)('attest', true, result, []);
30
+ if (options.out) {
31
+ const outPath = node_path_1.default.resolve(options.out);
32
+ await (0, fs_1.writeTextFile)(outPath, `${line}\n`);
33
+ return { exitCode, stdout: [(0, i18n_1.t)('attest.written', { path: outPath })], stderr: [] };
34
+ }
35
+ return { exitCode, stdout: [line], stderr: [] };
36
+ }
37
+ const markdown = (0, attest_1.renderAttestMarkdown)(result);
38
+ if (options.out) {
39
+ const outPath = node_path_1.default.resolve(options.out);
40
+ await (0, fs_1.writeTextFile)(outPath, markdown);
41
+ return { exitCode, stdout: [(0, i18n_1.t)('attest.written', { path: outPath })], stderr: [] };
42
+ }
43
+ return {
44
+ exitCode,
45
+ stdout: markdown.replace(/\n$/, '').split('\n'),
46
+ stderr: [],
47
+ };
48
+ }
49
+ catch (error) {
50
+ const message = error instanceof Error ? error.message : String(error);
51
+ if (options.json === true) {
52
+ return {
53
+ exitCode: 1,
54
+ stdout: [(0, command_json_1.toJsonLine)('attest', false, { packagePath }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.ATTEST_FAILED, message)])],
55
+ stderr: [],
56
+ };
57
+ }
58
+ return { exitCode: 1, stdout: [], stderr: [message] };
59
+ }
60
+ }
@@ -72,6 +72,9 @@ async function runInstallCommand(packagePath, targetPath, options = {}) {
72
72
  else if (message.includes('Missing install plan')) {
73
73
  code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_INSTALL_PLAN;
74
74
  }
75
+ else if (message.includes('PACKAGE_FORMAT_UNSUPPORTED')) {
76
+ code = command_error_codes_1.COMMAND_ERROR_CODES.PACKAGE_FORMAT_UNSUPPORTED;
77
+ }
75
78
  else if (message.includes('Install conflict detected')) {
76
79
  code = command_error_codes_1.COMMAND_ERROR_CODES.INSTALL_CONFLICT;
77
80
  }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runKeygenCommand = runKeygenCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const signature_1 = require("../core/signature");
9
+ const command_error_codes_1 = require("../constants/command-error-codes");
10
+ const i18n_1 = require("../i18n");
11
+ const command_json_1 = require("../utils/command-json");
12
+ async function runKeygenCommand(options = {}) {
13
+ const keyPath = options.out ? node_path_1.default.resolve(options.out) : signature_1.DEFAULT_KEY_PATH;
14
+ try {
15
+ const result = await (0, signature_1.generateSigningKey)(keyPath, options.force === true);
16
+ if (options.json === true) {
17
+ return {
18
+ exitCode: 0,
19
+ stdout: [(0, command_json_1.toJsonLine)('keygen', true, result, [])],
20
+ stderr: [],
21
+ };
22
+ }
23
+ return {
24
+ exitCode: 0,
25
+ stdout: [
26
+ (0, i18n_1.t)('keygen.complete', { path: result.keyPath }),
27
+ (0, i18n_1.t)('keygen.fingerprint', { fingerprint: result.fingerprint }),
28
+ (0, i18n_1.t)('keygen.publicKey', { key: result.publicKey }),
29
+ (0, i18n_1.t)('keygen.hint'),
30
+ ],
31
+ stderr: [],
32
+ };
33
+ }
34
+ catch (error) {
35
+ const message = error instanceof Error ? error.message : String(error);
36
+ if (options.json === true) {
37
+ const code = message.includes('SIGN_KEY_EXISTS')
38
+ ? command_error_codes_1.COMMAND_ERROR_CODES.SIGN_KEY_EXISTS
39
+ : command_error_codes_1.COMMAND_ERROR_CODES.SIGN_FAILED;
40
+ return {
41
+ exitCode: 1,
42
+ stdout: [(0, command_json_1.toJsonLine)('keygen', false, { keyPath }, [(0, command_json_1.toJsonError)(code, message)])],
43
+ stderr: [],
44
+ };
45
+ }
46
+ return { exitCode: 1, stdout: [], stderr: [message] };
47
+ }
48
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runPackCommand = runPackCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const config_1 = require("../core/config");
9
+ const pack_1 = require("../core/pack");
10
+ const command_error_codes_1 = require("../constants/command-error-codes");
11
+ const i18n_1 = require("../i18n");
12
+ const command_json_1 = require("../utils/command-json");
13
+ async function runPackCommand(options = {}) {
14
+ if (!options.fromScan) {
15
+ if (options.json === true) {
16
+ return {
17
+ exitCode: 1,
18
+ stdout: [(0, command_json_1.toJsonLine)('pack', false, { fromScan: null }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, (0, i18n_1.t)('pack.usage'))])],
19
+ stderr: [],
20
+ };
21
+ }
22
+ return { exitCode: 1, stdout: [], stderr: [(0, i18n_1.t)('pack.usage')] };
23
+ }
24
+ const scanPath = node_path_1.default.resolve(options.fromScan);
25
+ const out = options.out
26
+ ? node_path_1.default.resolve(options.out)
27
+ : node_path_1.default.resolve(node_path_1.default.join(node_path_1.default.dirname(scanPath), 'package'));
28
+ const config = await (0, config_1.loadConfig)();
29
+ try {
30
+ const result = await (0, pack_1.packFromScan)({
31
+ scanManifestPath: scanPath,
32
+ out,
33
+ env: options.env ? node_path_1.default.resolve(options.env) : (config.env ? node_path_1.default.resolve(config.env) : undefined),
34
+ overwrite: options.overwrite,
35
+ zip: options.zip === true,
36
+ });
37
+ if (options.json === true) {
38
+ return {
39
+ exitCode: 0,
40
+ stdout: [(0, command_json_1.toJsonLine)('pack', true, {
41
+ manifestPath: scanPath,
42
+ outputPath: result.outputPath,
43
+ lockPath: result.lockPath,
44
+ zipPath: result.zipPath ?? null,
45
+ fileCount: result.fileCount,
46
+ zipEntryCount: result.zipEntryCount ?? null,
47
+ }, [])],
48
+ stderr: [],
49
+ };
50
+ }
51
+ const stdout = [
52
+ (0, i18n_1.t)('pack.complete', { path: result.outputPath }),
53
+ (0, i18n_1.t)('pack.lock', { path: result.lockPath, count: result.fileCount }),
54
+ ];
55
+ if (result.zipPath) {
56
+ stdout.push((0, i18n_1.t)('pack.zip', { path: result.zipPath }));
57
+ }
58
+ return { exitCode: 0, stdout, stderr: [] };
59
+ }
60
+ catch (error) {
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ if (options.json === true) {
63
+ let code = command_error_codes_1.COMMAND_ERROR_CODES.PACK_FAILED;
64
+ if (message.includes('LOCK_TIMEOUT')) {
65
+ code = command_error_codes_1.COMMAND_ERROR_CODES.LOCK_TIMEOUT;
66
+ }
67
+ else if (message.includes('SCAN_EXPORT_UNSUPPORTED')) {
68
+ code = command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_INVALID;
69
+ }
70
+ return {
71
+ exitCode: 1,
72
+ stdout: [(0, command_json_1.toJsonLine)('pack', false, { manifestPath: scanPath, outputPath: out }, [(0, command_json_1.toJsonError)(code, message)])],
73
+ stderr: [],
74
+ };
75
+ }
76
+ return { exitCode: 1, stdout: [], stderr: [message] };
77
+ }
78
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runSignCommand = runSignCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const package_sign_1 = require("../core/package-sign");
9
+ const command_error_codes_1 = require("../constants/command-error-codes");
10
+ const i18n_1 = require("../i18n");
11
+ const command_json_1 = require("../utils/command-json");
12
+ async function runSignCommand(packagePath, options = {}) {
13
+ if (!packagePath) {
14
+ if (options.json === true) {
15
+ return {
16
+ exitCode: 1,
17
+ stdout: [(0, command_json_1.toJsonLine)('sign', false, { packagePath: null }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, (0, i18n_1.t)('sign.usage'))])],
18
+ stderr: [],
19
+ };
20
+ }
21
+ return { exitCode: 1, stdout: [], stderr: [(0, i18n_1.t)('sign.usage')] };
22
+ }
23
+ try {
24
+ const result = await (0, package_sign_1.signPackage)(packagePath, {
25
+ keyPath: options.key ? node_path_1.default.resolve(options.key) : undefined,
26
+ signaturePath: options.out ? node_path_1.default.resolve(options.out) : undefined,
27
+ });
28
+ if (options.json === true) {
29
+ return {
30
+ exitCode: 0,
31
+ stdout: [(0, command_json_1.toJsonLine)('sign', true, { packagePath, ...result }, [])],
32
+ stderr: [],
33
+ };
34
+ }
35
+ return {
36
+ exitCode: 0,
37
+ stdout: [
38
+ (0, i18n_1.t)('sign.complete', { path: result.signaturePath }),
39
+ (0, i18n_1.t)('sign.fingerprint', { fingerprint: result.fingerprint }),
40
+ ],
41
+ stderr: [],
42
+ };
43
+ }
44
+ catch (error) {
45
+ const message = error instanceof Error ? error.message : String(error);
46
+ if (options.json === true) {
47
+ let code = command_error_codes_1.COMMAND_ERROR_CODES.SIGN_FAILED;
48
+ if (message.includes('SIGN_KEY_MISSING')) {
49
+ code = command_error_codes_1.COMMAND_ERROR_CODES.SIGN_KEY_MISSING;
50
+ }
51
+ else if (message.includes('VERIFY_LOCK_MISSING')) {
52
+ code = command_error_codes_1.COMMAND_ERROR_CODES.VERIFY_LOCK_MISSING;
53
+ }
54
+ return {
55
+ exitCode: 1,
56
+ stdout: [(0, command_json_1.toJsonLine)('sign', false, { packagePath }, [(0, command_json_1.toJsonError)(code, message)])],
57
+ stderr: [],
58
+ };
59
+ }
60
+ return { exitCode: 1, stdout: [], stderr: [message] };
61
+ }
62
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runSyncCommand = runSyncCommand;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const yaml_1 = __importDefault(require("yaml"));
10
+ const scan_1 = require("../core/scan");
11
+ const config_1 = require("../core/config");
12
+ const sync_1 = require("../core/sync");
13
+ const command_error_codes_1 = require("../constants/command-error-codes");
14
+ const command_json_1 = require("../utils/command-json");
15
+ const plan_render_1 = require("../utils/plan-render");
16
+ const fs_1 = require("../utils/fs");
17
+ const i18n_1 = require("../i18n");
18
+ /** 读取 sync.yaml(--config 指定或 ./sync.yaml),CLI flag 优先于文件。 */
19
+ async function loadSyncFile(configPath) {
20
+ const p = configPath ? node_path_1.default.resolve(configPath) : node_path_1.default.resolve('sync.yaml');
21
+ if (!(await (0, fs_1.pathExists)(p))) {
22
+ if (configPath) {
23
+ throw new Error(`SYNC_CONFIG_MISSING: ${p}`);
24
+ }
25
+ return {};
26
+ }
27
+ const parsed = yaml_1.default.parse(await promises_1.default.readFile(p, 'utf8'));
28
+ return parsed ?? {};
29
+ }
30
+ const PUSH_LABELS = {
31
+ create: 'CREATE ',
32
+ overwrite: 'OVERWRITE',
33
+ skip: 'SKIP ',
34
+ conflict: 'CONFLICT ',
35
+ stale: 'STALE ',
36
+ };
37
+ function renderPush(result) {
38
+ const lines = [
39
+ `sync push → ${result.target} (${result.applied ? (0, i18n_1.t)('sync.applied') : (0, i18n_1.t)('sync.dryRun')})`,
40
+ ];
41
+ for (const entry of result.entries) {
42
+ lines.push(` ${PUSH_LABELS[entry.action]} ${entry.path}`);
43
+ }
44
+ if (result.conflicts.length > 0) {
45
+ lines.push(` ${(0, i18n_1.t)('sync.conflictHint')}`);
46
+ }
47
+ if (result.stale.length > 0) {
48
+ lines.push(` ${(0, i18n_1.t)('sync.stale')}`);
49
+ }
50
+ if (result.backupPath) {
51
+ lines.push(` ${(0, i18n_1.t)('sync.backup', { path: result.backupPath })}`);
52
+ }
53
+ return lines;
54
+ }
55
+ function renderPull(result) {
56
+ const lines = [
57
+ `sync pull → ${result.plan.targetPath} (${result.applied ? (0, i18n_1.t)('sync.applied') : (0, i18n_1.t)('sync.dryRun')})`,
58
+ ...(0, plan_render_1.renderPlan)(result.plan, 'dry-run', ` bundle: ${result.target}`),
59
+ ];
60
+ if (result.plan.conflicts.length > 0) {
61
+ lines.push(` ${(0, i18n_1.t)('sync.conflictHint')}`);
62
+ }
63
+ if (result.envWritten) {
64
+ lines.push(` ${(0, i18n_1.t)('sync.envWritten')}`);
65
+ }
66
+ if (result.snapshotPath) {
67
+ lines.push(` ${(0, i18n_1.t)('sync.snapshot', { path: result.snapshotPath })}`);
68
+ }
69
+ return lines;
70
+ }
71
+ function renderStatus(result) {
72
+ const lines = [`sync status → ${result.target}`];
73
+ if (result.bundleCreatedAt) {
74
+ lines.push(` ${(0, i18n_1.t)('sync.bundleTime', { time: result.bundleCreatedAt })}`);
75
+ }
76
+ lines.push(` ${(0, i18n_1.t)('sync.statusPlan', result.plan)}`);
77
+ lines.push(` ${(0, i18n_1.t)('sync.statusLocalOnly', { count: result.localOnly.length })}`);
78
+ for (const id of result.localOnly) {
79
+ lines.push(` + ${id}`);
80
+ }
81
+ lines.push(` ${(0, i18n_1.t)('sync.statusRemoteOnly', { count: result.remoteOnly.length })}`);
82
+ for (const id of result.remoteOnly) {
83
+ lines.push(` - ${id}`);
84
+ }
85
+ return lines;
86
+ }
87
+ async function runSyncCommand(action, target, options = {}) {
88
+ const root = options.root ?? (0, scan_1.defaultScanRoot)();
89
+ try {
90
+ if (action === '--help' || action === '-h' || action === 'help') {
91
+ return { exitCode: 0, stdout: [(0, i18n_1.t)('sync.usage')], stderr: [] };
92
+ }
93
+ if (options.undo === true) {
94
+ const result = await (0, sync_1.syncUndo)(root);
95
+ if (options.json === true) {
96
+ return { exitCode: 0, stdout: [(0, command_json_1.toJsonLine)('sync', true, result, [])], stderr: [] };
97
+ }
98
+ const lines = [`sync undo ← ${result.snapshotPath}`];
99
+ for (const rel of result.restored) {
100
+ lines.push(` RESTORED ${rel}`);
101
+ }
102
+ for (const rel of result.removed) {
103
+ lines.push(` REMOVED ${rel}`);
104
+ }
105
+ for (const rel of result.skippedModified) {
106
+ lines.push(` MODIFIED ${rel} (${(0, i18n_1.t)('sync.undoSkipped')})`);
107
+ }
108
+ return { exitCode: 0, stdout: lines, stderr: [] };
109
+ }
110
+ if (!action || !['pull', 'push', 'status'].includes(action) || !target) {
111
+ const message = (0, i18n_1.t)('sync.usage');
112
+ if (options.json === true) {
113
+ return {
114
+ exitCode: 1,
115
+ stdout: [(0, command_json_1.toJsonLine)('sync', false, { action: action ?? null, target: target ?? null }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, message)])],
116
+ stderr: [],
117
+ };
118
+ }
119
+ return { exitCode: 1, stdout: [], stderr: [message] };
120
+ }
121
+ const file = await loadSyncFile(options.config);
122
+ const config = await (0, config_1.loadConfig)();
123
+ const opts = {
124
+ target,
125
+ root,
126
+ agent: options.agent ?? file.agent ?? config.agent ?? 'all',
127
+ mode: options.mode ?? file.mode ?? 'full',
128
+ include: options.include ?? file.include ?? [],
129
+ exclude: options.exclude ?? file.exclude ?? [],
130
+ apply: options.apply === true && options.dryRun !== true,
131
+ overwrite: options.overwrite === true,
132
+ backup: options.backup === true,
133
+ withEnv: options.withEnv ?? file.withEnv ?? false,
134
+ envPath: options.env,
135
+ };
136
+ if (action === 'push') {
137
+ const result = await (0, sync_1.syncPush)(opts);
138
+ if (options.json === true) {
139
+ return { exitCode: 0, stdout: [(0, command_json_1.toJsonLine)('sync', true, result, [])], stderr: [] };
140
+ }
141
+ return { exitCode: 0, stdout: renderPush(result), stderr: [] };
142
+ }
143
+ if (action === 'pull') {
144
+ const result = await (0, sync_1.syncPull)(opts);
145
+ if (options.json === true) {
146
+ return { exitCode: 0, stdout: [(0, command_json_1.toJsonLine)('sync', true, result, [])], stderr: [] };
147
+ }
148
+ return { exitCode: 0, stdout: renderPull(result), stderr: [] };
149
+ }
150
+ const result = await (0, sync_1.syncStatus)(opts);
151
+ if (options.json === true) {
152
+ return { exitCode: 0, stdout: [(0, command_json_1.toJsonLine)('sync', true, result, [])], stderr: [] };
153
+ }
154
+ return { exitCode: 0, stdout: renderStatus(result), stderr: [] };
155
+ }
156
+ catch (error) {
157
+ const message = error instanceof Error ? error.message : String(error);
158
+ if (options.json === true) {
159
+ const code = message.startsWith('SYNC_ENV') || message.startsWith('SYNC_PASSPHRASE')
160
+ ? command_error_codes_1.COMMAND_ERROR_CODES.SYNC_ENV_FAILED
161
+ : command_error_codes_1.COMMAND_ERROR_CODES.SYNC_FAILED;
162
+ return {
163
+ exitCode: 1,
164
+ stdout: [(0, command_json_1.toJsonLine)('sync', false, { action: action ?? null, target: target ?? null }, [(0, command_json_1.toJsonError)(code, message)])],
165
+ stderr: [],
166
+ };
167
+ }
168
+ return { exitCode: 1, stdout: [], stderr: [message] };
169
+ }
170
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runVerifyCommand = runVerifyCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const package_lock_1 = require("../core/package-lock");
9
+ const command_error_codes_1 = require("../constants/command-error-codes");
10
+ const i18n_1 = require("../i18n");
11
+ const command_json_1 = require("../utils/command-json");
12
+ async function runVerifyCommand(packagePath, options = {}) {
13
+ if (!packagePath) {
14
+ if (options.json === true) {
15
+ return {
16
+ exitCode: 1,
17
+ stdout: [(0, command_json_1.toJsonLine)('verify', false, { packagePath: null }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, (0, i18n_1.t)('verify.usage'))])],
18
+ stderr: [],
19
+ };
20
+ }
21
+ return { exitCode: 1, stdout: [], stderr: [(0, i18n_1.t)('verify.usage')] };
22
+ }
23
+ try {
24
+ const result = await (0, package_lock_1.verifyPackage)(packagePath, options.strict === true, options.signature ? node_path_1.default.resolve(options.signature) : undefined);
25
+ if (options.json === true) {
26
+ return {
27
+ exitCode: result.ok ? 0 : 1,
28
+ stdout: [(0, command_json_1.toJsonLine)('verify', result.ok, result, [])],
29
+ stderr: [],
30
+ };
31
+ }
32
+ if (result.ok) {
33
+ const stdout = [(0, i18n_1.t)('verify.pass', { count: result.checked })];
34
+ if (result.signature.present && result.signature.valid) {
35
+ stdout.push((0, i18n_1.t)('verify.signaturePass', { fingerprint: result.signature.fingerprint ?? 'unknown' }));
36
+ }
37
+ if (result.extra.length > 0) {
38
+ stdout.push((0, i18n_1.t)('verify.extra', { count: result.extra.length }));
39
+ }
40
+ return { exitCode: 0, stdout, stderr: [] };
41
+ }
42
+ const stderr = [
43
+ (0, i18n_1.t)('verify.fail', { missing: result.missing.length, modified: result.modified.length }),
44
+ ];
45
+ if (result.lockCorrupt) {
46
+ stderr.push((0, i18n_1.t)('verify.lockCorrupt'));
47
+ }
48
+ if (result.signature.present && !result.signature.valid) {
49
+ stderr.push((0, i18n_1.t)('verify.signatureFail', { reason: result.signature.error ?? 'invalid signature' }));
50
+ }
51
+ for (const file of result.missing) {
52
+ stderr.push(` missing: ${file}`);
53
+ }
54
+ for (const file of result.modified) {
55
+ stderr.push(` modified: ${file}`);
56
+ }
57
+ if (result.extra.length > 0) {
58
+ stderr.push((0, i18n_1.t)('verify.extra', { count: result.extra.length }));
59
+ }
60
+ return { exitCode: 1, stdout: [], stderr };
61
+ }
62
+ catch (error) {
63
+ const message = error instanceof Error ? error.message : String(error);
64
+ if (options.json === true) {
65
+ let code = command_error_codes_1.COMMAND_ERROR_CODES.VERIFY_FAILED;
66
+ if (message.includes('VERIFY_LOCK_MISSING')) {
67
+ code = command_error_codes_1.COMMAND_ERROR_CODES.VERIFY_LOCK_MISSING;
68
+ }
69
+ else if (message.includes('SIGNATURE_INVALID')) {
70
+ code = command_error_codes_1.COMMAND_ERROR_CODES.SIGNATURE_INVALID;
71
+ }
72
+ return {
73
+ exitCode: 1,
74
+ stdout: [(0, command_json_1.toJsonLine)('verify', false, { packagePath }, [(0, command_json_1.toJsonError)(code, message)])],
75
+ stderr: [],
76
+ };
77
+ }
78
+ return { exitCode: 1, stdout: [], stderr: [message] };
79
+ }
80
+ }
@@ -9,6 +9,7 @@ exports.COMMAND_ERROR_CODES = {
9
9
  TEMPLATE_VARIABLE_MISSING: 'TEMPLATE_VARIABLE_MISSING',
10
10
  MISSING_PACKAGE_MANIFEST: 'MISSING_PACKAGE_MANIFEST',
11
11
  MISSING_INSTALL_PLAN: 'MISSING_INSTALL_PLAN',
12
+ PACKAGE_FORMAT_UNSUPPORTED: 'PACKAGE_FORMAT_UNSUPPORTED',
12
13
  INSTALL_CONFLICT: 'INSTALL_CONFLICT',
13
14
  PATH_ESCAPE: 'PATH_ESCAPE',
14
15
  LOCK_TIMEOUT: 'LOCK_TIMEOUT',
@@ -16,4 +17,14 @@ exports.COMMAND_ERROR_CODES = {
16
17
  DOCTOR_FAILED: 'DOCTOR_FAILED',
17
18
  LIST_FAILED: 'LIST_FAILED',
18
19
  REPORT_FAILED: 'REPORT_FAILED',
20
+ SYNC_FAILED: 'SYNC_FAILED',
21
+ SYNC_ENV_FAILED: 'SYNC_ENV_FAILED',
22
+ PACK_FAILED: 'PACK_FAILED',
23
+ VERIFY_FAILED: 'VERIFY_FAILED',
24
+ VERIFY_LOCK_MISSING: 'VERIFY_LOCK_MISSING',
25
+ ATTEST_FAILED: 'ATTEST_FAILED',
26
+ SIGN_KEY_MISSING: 'SIGN_KEY_MISSING',
27
+ SIGN_KEY_EXISTS: 'SIGN_KEY_EXISTS',
28
+ SIGN_FAILED: 'SIGN_FAILED',
29
+ SIGNATURE_INVALID: 'SIGNATURE_INVALID',
19
30
  };