agentdock-cli 0.4.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 +150 -0
- package/dist/package.json +60 -0
- package/dist/schemas/agentdock.schema.json +121 -0
- package/dist/src/cli.js +129 -0
- package/dist/src/commands/doctor.js +49 -0
- package/dist/src/commands/export.js +133 -0
- package/dist/src/commands/init.js +65 -0
- package/dist/src/commands/install.js +76 -0
- package/dist/src/commands/list.js +70 -0
- package/dist/src/commands/scan.js +61 -0
- package/dist/src/commands/upgrade.js +243 -0
- package/dist/src/commands/validate.js +58 -0
- package/dist/src/constants/command-error-codes.js +20 -0
- package/dist/src/constants/upgrade-warning-codes.js +9 -0
- package/dist/src/core/doctor.js +501 -0
- package/dist/src/core/exporter.js +81 -0
- package/dist/src/core/installer.js +125 -0
- package/dist/src/core/list.js +204 -0
- package/dist/src/core/scan-export.js +208 -0
- package/dist/src/core/scan.js +129 -0
- package/dist/src/core/source-destination.js +16 -0
- package/dist/src/core/template-renderer.js +30 -0
- package/dist/src/manifest/load.js +19 -0
- package/dist/src/manifest/types.js +2 -0
- package/dist/src/manifest/validate.js +53 -0
- package/dist/src/scanners/claude-scanner.js +196 -0
- package/dist/src/scanners/codex-scanner.js +140 -0
- package/dist/src/scanners/sensitive.js +178 -0
- package/dist/src/types/command-report.js +2 -0
- package/dist/src/types/upgrade-report.js +2 -0
- package/dist/src/utils/command-json.js +23 -0
- package/dist/src/utils/fs.js +160 -0
- package/package.json +60 -0
|
@@ -0,0 +1,65 @@
|
|
|
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.runInitCommand = runInitCommand;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
|
+
const command_json_1 = require("../utils/command-json");
|
|
11
|
+
async function runInitCommand(targetDirectory, options = {}) {
|
|
12
|
+
const projectRoot = node_path_1.default.resolve(targetDirectory ?? process.cwd());
|
|
13
|
+
const manifestPath = node_path_1.default.join(projectRoot, 'agentdock.yml');
|
|
14
|
+
const examplePath = node_path_1.default.resolve(__dirname, '../../examples/agentdock.example.yml');
|
|
15
|
+
try {
|
|
16
|
+
await promises_1.default.access(manifestPath);
|
|
17
|
+
if (options.json === true) {
|
|
18
|
+
return {
|
|
19
|
+
exitCode: 1,
|
|
20
|
+
stdout: [(0, command_json_1.toJsonLine)('init', false, { targetDirectory: projectRoot, manifestPath }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_ALREADY_EXISTS, `Manifest already exists: ${manifestPath}`)])],
|
|
21
|
+
stderr: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
exitCode: 1,
|
|
26
|
+
stdout: [],
|
|
27
|
+
stderr: [`Manifest already exists: ${manifestPath}`],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// continue
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const template = await promises_1.default.readFile(examplePath, 'utf8');
|
|
35
|
+
await promises_1.default.mkdir(projectRoot, { recursive: true });
|
|
36
|
+
await promises_1.default.writeFile(manifestPath, template, 'utf8');
|
|
37
|
+
if (options.json === true) {
|
|
38
|
+
return {
|
|
39
|
+
exitCode: 0,
|
|
40
|
+
stdout: [(0, command_json_1.toJsonLine)('init', true, { targetDirectory: projectRoot, manifestPath }, [])],
|
|
41
|
+
stderr: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
exitCode: 0,
|
|
46
|
+
stdout: [`Created manifest: ${manifestPath}`],
|
|
47
|
+
stderr: [],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
if (options.json === true) {
|
|
53
|
+
return {
|
|
54
|
+
exitCode: 1,
|
|
55
|
+
stdout: [(0, command_json_1.toJsonLine)('init', false, { targetDirectory: projectRoot, manifestPath }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, message)])],
|
|
56
|
+
stderr: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
exitCode: 1,
|
|
61
|
+
stdout: [],
|
|
62
|
+
stderr: [message],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInstallCommand = runInstallCommand;
|
|
4
|
+
const installer_1 = require("../core/installer");
|
|
5
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
6
|
+
const command_json_1 = require("../utils/command-json");
|
|
7
|
+
async function runInstallCommand(packagePath, targetPath, options = {}) {
|
|
8
|
+
if (!packagePath) {
|
|
9
|
+
if (options.json === true) {
|
|
10
|
+
return {
|
|
11
|
+
exitCode: 1,
|
|
12
|
+
stdout: [(0, command_json_1.toJsonLine)('install', false, { packagePath, targetPath: targetPath ?? null, overwrite: options.overwrite === true }, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR, 'Usage: agentdock install <packagePath> [targetPath] [--overwrite]')])],
|
|
13
|
+
stderr: [],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
exitCode: 1,
|
|
18
|
+
stdout: [],
|
|
19
|
+
stderr: ['Usage: agentdock install <packagePath> [targetPath] [--overwrite]'],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const result = await (0, installer_1.installPackage)(packagePath, targetPath, options.overwrite === true);
|
|
24
|
+
if (options.json === true) {
|
|
25
|
+
return {
|
|
26
|
+
exitCode: 0,
|
|
27
|
+
stdout: [(0, command_json_1.toJsonLine)('install', true, {
|
|
28
|
+
packagePath,
|
|
29
|
+
targetPath: result.targetPath,
|
|
30
|
+
overwrite: options.overwrite === true,
|
|
31
|
+
}, [])],
|
|
32
|
+
stderr: [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
exitCode: 0,
|
|
37
|
+
stdout: [`Install completed: ${result.targetPath}`],
|
|
38
|
+
stderr: [],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
if (options.json === true) {
|
|
44
|
+
let code = command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
45
|
+
if (message.includes('Missing package manifest snapshot')) {
|
|
46
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_PACKAGE_MANIFEST;
|
|
47
|
+
}
|
|
48
|
+
else if (message.includes('Missing install plan')) {
|
|
49
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MISSING_INSTALL_PLAN;
|
|
50
|
+
}
|
|
51
|
+
else if (message.includes('Install conflict detected')) {
|
|
52
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.INSTALL_CONFLICT;
|
|
53
|
+
}
|
|
54
|
+
else if (message.includes('PATH_ESCAPE')) {
|
|
55
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.PATH_ESCAPE;
|
|
56
|
+
}
|
|
57
|
+
else if (message.includes('LOCK_TIMEOUT')) {
|
|
58
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.LOCK_TIMEOUT;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
exitCode: 1,
|
|
62
|
+
stdout: [(0, command_json_1.toJsonLine)('install', false, {
|
|
63
|
+
packagePath,
|
|
64
|
+
targetPath: targetPath ?? null,
|
|
65
|
+
overwrite: options.overwrite === true,
|
|
66
|
+
}, [(0, command_json_1.toJsonError)(code, message)])],
|
|
67
|
+
stderr: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
exitCode: 1,
|
|
72
|
+
stdout: [],
|
|
73
|
+
stderr: [message],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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.runListCommand = runListCommand;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const list_1 = require("../core/list");
|
|
9
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
|
+
const command_json_1 = require("../utils/command-json");
|
|
11
|
+
async function runListCommand(options = {}) {
|
|
12
|
+
const out = options.out ? node_path_1.default.resolve(options.out) : undefined;
|
|
13
|
+
try {
|
|
14
|
+
const report = await (0, list_1.runList)({
|
|
15
|
+
fromScan: options.fromScan,
|
|
16
|
+
package: options.package,
|
|
17
|
+
agent: options.agent,
|
|
18
|
+
out,
|
|
19
|
+
});
|
|
20
|
+
if (options.json === true) {
|
|
21
|
+
return {
|
|
22
|
+
exitCode: 0,
|
|
23
|
+
stdout: [(0, command_json_1.toJsonLine)('list', true, report, [])],
|
|
24
|
+
stderr: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const lines = [];
|
|
28
|
+
lines.push(`List (${report.mode}) — ${report.project.name || 'untitled'}`);
|
|
29
|
+
lines.push(report.summary);
|
|
30
|
+
for (const info of report.agents) {
|
|
31
|
+
const title = info.agent === 'claude' ? 'Claude Code' : 'Codex';
|
|
32
|
+
lines.push(` ${title}: ${info.totals.all} 项`);
|
|
33
|
+
lines.push(` MCP: ${info.totals.mcp ? info.mcp.join(', ') : '—'}`);
|
|
34
|
+
lines.push(` Skills: ${info.totals.skills ? info.skills.join(', ') : '—'}`);
|
|
35
|
+
lines.push(` Agents: ${info.totals.agents ? info.agents.join(', ') : '—'}`);
|
|
36
|
+
lines.push(` Plugins: ${info.totals.plugins ? info.plugins.join(', ') : '—'}`);
|
|
37
|
+
lines.push(` Hooks: ${info.totals.hooks ? info.hooks.join(', ') : '—'}`);
|
|
38
|
+
lines.push(` Memory: ${info.totals.memory ? info.memory.join(', ') : '—'}`);
|
|
39
|
+
lines.push(` Settings: ${info.totals.settings ? info.settings.join(', ') : '—'}`);
|
|
40
|
+
}
|
|
41
|
+
lines.push(` 机密隔离: ${report.secretsCount} 个`);
|
|
42
|
+
if (report.installPlan && report.installPlan.length > 0) {
|
|
43
|
+
lines.push(` 安装计划: ${report.installPlan.length} 条文件映射`);
|
|
44
|
+
}
|
|
45
|
+
if (report.reportPath) {
|
|
46
|
+
lines.push(`report: ${report.reportPath}`);
|
|
47
|
+
}
|
|
48
|
+
return { exitCode: 0, stdout: lines, stderr: [] };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
if (options.json === true) {
|
|
53
|
+
const data = {
|
|
54
|
+
mode: 'scan',
|
|
55
|
+
manifestPath: '',
|
|
56
|
+
project: { name: '' },
|
|
57
|
+
agents: [],
|
|
58
|
+
secretsCount: 0,
|
|
59
|
+
secrets: [],
|
|
60
|
+
summary: message,
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
exitCode: 1,
|
|
64
|
+
stdout: [(0, command_json_1.toJsonLine)('list', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.LIST_FAILED, message)])],
|
|
65
|
+
stderr: [],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { exitCode: 1, stdout: [], stderr: [message] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.runScanCommand = runScanCommand;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const scan_1 = require("../core/scan");
|
|
9
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
|
+
const command_json_1 = require("../utils/command-json");
|
|
11
|
+
async function runScanCommand(options = {}) {
|
|
12
|
+
const agent = options.agent ?? 'all';
|
|
13
|
+
const root = options.root ?? (0, scan_1.defaultScanRoot)();
|
|
14
|
+
const out = options.out ? node_path_1.default.resolve(options.out) : node_path_1.default.resolve('agentdock-scan');
|
|
15
|
+
try {
|
|
16
|
+
const { report } = await (0, scan_1.runScan)({ agent, root, out });
|
|
17
|
+
if (options.json === true) {
|
|
18
|
+
return {
|
|
19
|
+
exitCode: 0,
|
|
20
|
+
stdout: [(0, command_json_1.toJsonLine)('scan', true, report, [])],
|
|
21
|
+
stderr: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
exitCode: 0,
|
|
26
|
+
stdout: [
|
|
27
|
+
`Scan complete (agent=${agent})`,
|
|
28
|
+
`manifest: ${report.manifestPath}`,
|
|
29
|
+
`env.example: ${report.envExamplePath}`,
|
|
30
|
+
`report: ${report.reportPath}`,
|
|
31
|
+
`secrets isolated: ${report.secretsCount}`,
|
|
32
|
+
],
|
|
33
|
+
stderr: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
if (options.json === true) {
|
|
39
|
+
const data = {
|
|
40
|
+
agent,
|
|
41
|
+
manifestPath: '',
|
|
42
|
+
envExamplePath: '',
|
|
43
|
+
reportPath: '',
|
|
44
|
+
counts: {},
|
|
45
|
+
secretsCount: 0,
|
|
46
|
+
skipped: [],
|
|
47
|
+
notes: [message],
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
exitCode: 1,
|
|
51
|
+
stdout: [(0, command_json_1.toJsonLine)('scan', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.SCAN_FAILED, message)])],
|
|
52
|
+
stderr: [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
exitCode: 1,
|
|
57
|
+
stdout: [],
|
|
58
|
+
stderr: [message],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
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.runUpgradeCommand = runUpgradeCommand;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const diff_1 = require("diff");
|
|
10
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
11
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
12
|
+
const upgrade_warning_codes_1 = require("../constants/upgrade-warning-codes");
|
|
13
|
+
const source_destination_1 = require("../core/source-destination");
|
|
14
|
+
const fs_1 = require("../utils/fs");
|
|
15
|
+
const command_json_1 = require("../utils/command-json");
|
|
16
|
+
function renderDiff(beforeText, afterText) {
|
|
17
|
+
const lines = [];
|
|
18
|
+
for (const part of (0, diff_1.diffLines)(beforeText, afterText)) {
|
|
19
|
+
const prefix = part.added ? '+' : part.removed ? '-' : ' ';
|
|
20
|
+
for (const line of part.value.split('\n')) {
|
|
21
|
+
if (line.length === 0) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
lines.push(`${prefix}${line}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
function countAddedDestinations(diffOutput) {
|
|
30
|
+
return diffOutput.filter((line) => line.startsWith('+') && line.includes('destination: ')).length;
|
|
31
|
+
}
|
|
32
|
+
function buildWarnings(changed, addedDestinationCount) {
|
|
33
|
+
if (!changed) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (addedDestinationCount === 0) {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
code: upgrade_warning_codes_1.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE,
|
|
40
|
+
message: upgrade_warning_codes_1.UPGRADE_WARNING_MESSAGES[upgrade_warning_codes_1.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
function toUpgradeData(manifestPath, fromVersion, toVersion, changed, dryRun, diffOutput, sourceCount, templateCount, outputPath) {
|
|
47
|
+
const changedLineCount = diffOutput.filter((line) => line.startsWith('+') || line.startsWith('-')).length;
|
|
48
|
+
const addedDestinationCount = countAddedDestinations(diffOutput);
|
|
49
|
+
const warnings = buildWarnings(changed, addedDestinationCount);
|
|
50
|
+
return {
|
|
51
|
+
manifestPath,
|
|
52
|
+
outputPath,
|
|
53
|
+
fromVersion,
|
|
54
|
+
toVersion,
|
|
55
|
+
changed,
|
|
56
|
+
dryRun,
|
|
57
|
+
diff: diffOutput,
|
|
58
|
+
summary: {
|
|
59
|
+
addedDestinationCount,
|
|
60
|
+
changedLineCount,
|
|
61
|
+
sourceCount,
|
|
62
|
+
templateCount,
|
|
63
|
+
warningCount: warnings.length,
|
|
64
|
+
warnings,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function toTextLines(data, verbose) {
|
|
69
|
+
const lines = [
|
|
70
|
+
'Upgrade summary:',
|
|
71
|
+
`manifest: ${data.manifestPath}`,
|
|
72
|
+
`output: ${data.outputPath ?? data.manifestPath}`,
|
|
73
|
+
`version: ${data.fromVersion} -> ${data.toVersion}`,
|
|
74
|
+
`mode: ${data.dryRun ? 'dry-run' : 'write'}`,
|
|
75
|
+
`changed: ${data.changed ? 'yes' : 'no'}`,
|
|
76
|
+
`sources: ${data.summary.sourceCount}`,
|
|
77
|
+
`templates: ${data.summary.templateCount}`,
|
|
78
|
+
`changedLines: ${data.summary.changedLineCount}`,
|
|
79
|
+
`addedDestinations: ${data.summary.addedDestinationCount}`,
|
|
80
|
+
`warnings: ${data.summary.warningCount}`,
|
|
81
|
+
];
|
|
82
|
+
for (const warning of data.summary.warnings) {
|
|
83
|
+
lines.push(`warning.${warning.code}: ${warning.message}`);
|
|
84
|
+
}
|
|
85
|
+
if (verbose) {
|
|
86
|
+
lines.push('diff:');
|
|
87
|
+
if (data.diff.length === 0) {
|
|
88
|
+
lines.push('(no diff)');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
lines.push(...data.diff);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return lines;
|
|
95
|
+
}
|
|
96
|
+
async function runUpgradeCommand(manifestPath, options = {}) {
|
|
97
|
+
const usage = 'Usage: agentdock upgrade <manifestPath> [--dry-run] [--json] [--verbose] [--write <path>] [--backup] [--force]';
|
|
98
|
+
if (!manifestPath) {
|
|
99
|
+
if (options.json === true) {
|
|
100
|
+
return {
|
|
101
|
+
exitCode: 1,
|
|
102
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, {
|
|
103
|
+
manifestPath: '',
|
|
104
|
+
fromVersion: 0,
|
|
105
|
+
toVersion: 0,
|
|
106
|
+
changed: false,
|
|
107
|
+
dryRun: options.dryRun === true,
|
|
108
|
+
diff: [],
|
|
109
|
+
summary: {
|
|
110
|
+
addedDestinationCount: 0,
|
|
111
|
+
changedLineCount: 0,
|
|
112
|
+
sourceCount: 0,
|
|
113
|
+
templateCount: 0,
|
|
114
|
+
warningCount: 0,
|
|
115
|
+
warnings: [],
|
|
116
|
+
},
|
|
117
|
+
}, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MISSING_ARGUMENT, usage)])],
|
|
118
|
+
stderr: [],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
exitCode: 1,
|
|
123
|
+
stdout: [],
|
|
124
|
+
stderr: [usage],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const absolutePath = node_path_1.default.resolve(manifestPath);
|
|
129
|
+
const requestedOutputPath = options.writePath ? node_path_1.default.resolve(options.writePath) : undefined;
|
|
130
|
+
const raw = await promises_1.default.readFile(absolutePath, 'utf8');
|
|
131
|
+
const manifest = yaml_1.default.parse(raw);
|
|
132
|
+
const fromVersion = manifest.version;
|
|
133
|
+
if (manifest.version === 2 && options.force !== true) {
|
|
134
|
+
const data = toUpgradeData(absolutePath, 2, 2, false, options.dryRun === true, [], manifest.sources.length, manifest.templates?.length ?? 0, requestedOutputPath);
|
|
135
|
+
if (options.json === true) {
|
|
136
|
+
return {
|
|
137
|
+
exitCode: 0,
|
|
138
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
139
|
+
stderr: [],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
exitCode: 0,
|
|
144
|
+
stdout: toTextLines(data, options.verbose === true),
|
|
145
|
+
stderr: [],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (manifest.version !== 1 && manifest.version !== 2) {
|
|
149
|
+
if (options.json === true) {
|
|
150
|
+
const data = toUpgradeData(absolutePath, fromVersion, 2, false, options.dryRun === true, [], manifest.sources?.length ?? 0, manifest.templates?.length ?? 0, requestedOutputPath);
|
|
151
|
+
return {
|
|
152
|
+
exitCode: 1,
|
|
153
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.UNSUPPORTED_MANIFEST_VERSION, `Unsupported manifest version: ${manifest.version}`)])],
|
|
154
|
+
stderr: [],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
exitCode: 1,
|
|
159
|
+
stdout: [],
|
|
160
|
+
stderr: [`Unsupported manifest version: ${manifest.version}`],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const upgraded = {
|
|
164
|
+
...manifest,
|
|
165
|
+
version: 2,
|
|
166
|
+
sources: manifest.sources.map((source) => ({
|
|
167
|
+
...source,
|
|
168
|
+
destination: (0, source_destination_1.resolveSourceDestination)(source),
|
|
169
|
+
})),
|
|
170
|
+
};
|
|
171
|
+
const output = yaml_1.default.stringify(upgraded);
|
|
172
|
+
const diffOutput = renderDiff(raw, output);
|
|
173
|
+
if (options.dryRun === true) {
|
|
174
|
+
const data = toUpgradeData(absolutePath, fromVersion, 2, diffOutput.length > 0, true, diffOutput, upgraded.sources.length, upgraded.templates?.length ?? 0, requestedOutputPath);
|
|
175
|
+
if (options.json === true) {
|
|
176
|
+
return {
|
|
177
|
+
exitCode: 0,
|
|
178
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
179
|
+
stderr: [],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
exitCode: 0,
|
|
184
|
+
stdout: toTextLines(data, options.verbose === true),
|
|
185
|
+
stderr: [],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const outputPath = requestedOutputPath ?? absolutePath;
|
|
189
|
+
if (options.backup === true && outputPath === absolutePath) {
|
|
190
|
+
const timestamp = new Date().toISOString().replace(/[-:.TZ]/g, '');
|
|
191
|
+
const backupPath = `${absolutePath}.bak.${timestamp}`;
|
|
192
|
+
await promises_1.default.copyFile(absolutePath, backupPath);
|
|
193
|
+
}
|
|
194
|
+
await promises_1.default.mkdir(node_path_1.default.dirname(outputPath), { recursive: true });
|
|
195
|
+
await (0, fs_1.writeTextFile)(outputPath, output);
|
|
196
|
+
const data = toUpgradeData(absolutePath, fromVersion, 2, diffOutput.length > 0, false, diffOutput, upgraded.sources.length, upgraded.templates?.length ?? 0, outputPath);
|
|
197
|
+
if (options.json === true) {
|
|
198
|
+
return {
|
|
199
|
+
exitCode: 0,
|
|
200
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', true, data, [])],
|
|
201
|
+
stderr: [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
exitCode: 0,
|
|
206
|
+
stdout: toTextLines(data, options.verbose === true),
|
|
207
|
+
stderr: [],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
212
|
+
if (options.json === true) {
|
|
213
|
+
const code = message.includes('ENOENT')
|
|
214
|
+
? command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_NOT_FOUND
|
|
215
|
+
: command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
216
|
+
return {
|
|
217
|
+
exitCode: 1,
|
|
218
|
+
stdout: [(0, command_json_1.toJsonLine)('upgrade', false, {
|
|
219
|
+
manifestPath: node_path_1.default.resolve(manifestPath),
|
|
220
|
+
fromVersion: 0,
|
|
221
|
+
toVersion: 2,
|
|
222
|
+
changed: false,
|
|
223
|
+
dryRun: options.dryRun === true,
|
|
224
|
+
diff: [],
|
|
225
|
+
summary: {
|
|
226
|
+
addedDestinationCount: 0,
|
|
227
|
+
changedLineCount: 0,
|
|
228
|
+
sourceCount: 0,
|
|
229
|
+
templateCount: 0,
|
|
230
|
+
warningCount: 0,
|
|
231
|
+
warnings: [],
|
|
232
|
+
},
|
|
233
|
+
}, [(0, command_json_1.toJsonError)(code, message)])],
|
|
234
|
+
stderr: [],
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
exitCode: 1,
|
|
239
|
+
stdout: [],
|
|
240
|
+
stderr: [message],
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runValidateCommand = runValidateCommand;
|
|
4
|
+
const load_1 = require("../manifest/load");
|
|
5
|
+
const validate_1 = require("../manifest/validate");
|
|
6
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
7
|
+
const command_json_1 = require("../utils/command-json");
|
|
8
|
+
async function runValidateCommand(manifestPath, options = {}) {
|
|
9
|
+
const effectiveManifestPath = manifestPath ?? 'agentdock.yml';
|
|
10
|
+
try {
|
|
11
|
+
const loaded = await (0, load_1.loadManifest)(effectiveManifestPath);
|
|
12
|
+
const result = (0, validate_1.validateManifest)(loaded.data);
|
|
13
|
+
if (!result.valid) {
|
|
14
|
+
if (options.json === true) {
|
|
15
|
+
return {
|
|
16
|
+
exitCode: 1,
|
|
17
|
+
stdout: [(0, command_json_1.toJsonLine)('validate', false, { manifestPath: loaded.path, valid: false }, result.errors.map((message) => (0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_INVALID, message)))],
|
|
18
|
+
stderr: [],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
exitCode: 1,
|
|
23
|
+
stdout: [],
|
|
24
|
+
stderr: result.errors,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (options.json === true) {
|
|
28
|
+
return {
|
|
29
|
+
exitCode: 0,
|
|
30
|
+
stdout: [(0, command_json_1.toJsonLine)('validate', true, { manifestPath: loaded.path, valid: true }, [])],
|
|
31
|
+
stderr: [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
exitCode: 0,
|
|
36
|
+
stdout: [`Manifest is valid: ${loaded.path}`],
|
|
37
|
+
stderr: [],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
42
|
+
if (options.json === true) {
|
|
43
|
+
const code = message.includes('ENOENT')
|
|
44
|
+
? command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_NOT_FOUND
|
|
45
|
+
: command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
46
|
+
return {
|
|
47
|
+
exitCode: 1,
|
|
48
|
+
stdout: [(0, command_json_1.toJsonLine)('validate', false, { manifestPath: effectiveManifestPath, valid: false }, [(0, command_json_1.toJsonError)(code, message)])],
|
|
49
|
+
stderr: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
exitCode: 1,
|
|
54
|
+
stdout: [],
|
|
55
|
+
stderr: [message],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMAND_ERROR_CODES = void 0;
|
|
4
|
+
exports.COMMAND_ERROR_CODES = {
|
|
5
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
6
|
+
MISSING_ARGUMENT: 'MISSING_ARGUMENT',
|
|
7
|
+
MANIFEST_NOT_FOUND: 'MANIFEST_NOT_FOUND',
|
|
8
|
+
MANIFEST_INVALID: 'MANIFEST_INVALID',
|
|
9
|
+
MANIFEST_ALREADY_EXISTS: 'MANIFEST_ALREADY_EXISTS',
|
|
10
|
+
UNSUPPORTED_MANIFEST_VERSION: 'UNSUPPORTED_MANIFEST_VERSION',
|
|
11
|
+
TEMPLATE_VARIABLE_MISSING: 'TEMPLATE_VARIABLE_MISSING',
|
|
12
|
+
MISSING_PACKAGE_MANIFEST: 'MISSING_PACKAGE_MANIFEST',
|
|
13
|
+
MISSING_INSTALL_PLAN: 'MISSING_INSTALL_PLAN',
|
|
14
|
+
INSTALL_CONFLICT: 'INSTALL_CONFLICT',
|
|
15
|
+
PATH_ESCAPE: 'PATH_ESCAPE',
|
|
16
|
+
LOCK_TIMEOUT: 'LOCK_TIMEOUT',
|
|
17
|
+
SCAN_FAILED: 'SCAN_FAILED',
|
|
18
|
+
DOCTOR_FAILED: 'DOCTOR_FAILED',
|
|
19
|
+
LIST_FAILED: 'LIST_FAILED',
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UPGRADE_WARNING_MESSAGES = exports.UPGRADE_WARNING_CODES = void 0;
|
|
4
|
+
exports.UPGRADE_WARNING_CODES = {
|
|
5
|
+
FORMAT_ONLY_CHANGE: 'FORMAT_ONLY_CHANGE',
|
|
6
|
+
};
|
|
7
|
+
exports.UPGRADE_WARNING_MESSAGES = {
|
|
8
|
+
[exports.UPGRADE_WARNING_CODES.FORMAT_ONLY_CHANGE]: 'Upgrade only changed formatting or normalization, no new destinations were introduced.',
|
|
9
|
+
};
|