agentdock-cli 0.4.0 → 0.4.2
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/README.md +119 -116
- package/dist/package.json +1 -1
- package/dist/src/cli.js +1 -7
- package/dist/src/constants/command-error-codes.js +0 -2
- package/package.json +1 -1
- package/dist/src/commands/init.js +0 -65
- package/dist/src/commands/upgrade.js +0 -243
- package/dist/src/constants/upgrade-warning-codes.js +0 -9
- package/dist/src/types/upgrade-report.js +0 -2
package/README.md
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
# AgentDock
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> 你的 AI 编码助手(Claude Code / Codex)的 dotfiles 工具。
|
|
4
|
+
> 把 MCP Server、Skill、Agent、Plugin、Hook、记忆**原样、安全、可复现**地搬到哪里都行 —— **而且绝不把 token 一起带走。**
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
[](https://www.npmjs.com/package/agentdock-cli)
|
|
7
|
+
[](./LICENSE)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## 为什么需要 AgentDock
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
你花几周调好的 AI 编码环境,换台机器就归零。现有办法都不靠谱:
|
|
12
|
+
|
|
13
|
+
- **chezmoi / dotbot / yadm** —— 只搬文件、做模板,**不懂** Claude 的 `settings.json` 与 `.claude.json` 区别,不知道 `settings.env` 里混着 token,更不会自动跳过 `auth.json`。
|
|
14
|
+
- **git + 手动提交** —— 容易把 `auth.json`、真实 token 一起提交;跨机器绝对路径失效。
|
|
15
|
+
- **rsync / 云盘** —— 全量复制,`sqlite`/`cache` 也跟着走,机密与定义混在一起无法审计。
|
|
16
|
+
|
|
17
|
+
AgentDock 要做的:让「重建一套顺手的 AI 编码环境」从「半天手工拷贝 + 祈祷别漏别泄密」,变成「一条命令 + 一份填好的 `.env`」。
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
> 产品定位、边界与路线图见 **[PRD](./docs/PRD.md)**,本文档对外口径一律以 PRD 为准。
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
12
22
|
|
|
13
23
|
```bash
|
|
14
24
|
# 全局安装,获得 agentdock 命令
|
|
@@ -18,133 +28,126 @@ npm install -g agentdock-cli
|
|
|
18
28
|
npx agentdock-cli --help
|
|
19
29
|
```
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
(仓库贡献者仍可用开发模式 `npm run cli -- <command>`。)
|
|
31
|
+
要求 Node.js >= 18。安装后所有命令以 `agentdock` 调用,例如 `agentdock scan --agent claude`。
|
|
23
32
|
|
|
24
|
-
##
|
|
33
|
+
## 30 秒上手
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
- `install`:从导出包恢复到目标目录
|
|
30
|
-
- `upgrade`:将旧版 manifest 升级到新版结构
|
|
31
|
-
- `scan`:自动发现并提取 Claude Code / Codex 的 AI 助手环境(MCP / Skill / Agent / Plugin / Hook / 记忆),隔离敏感信息,产出领域化 manifest v3(预览中)
|
|
32
|
-
- `list`:列出已扫描捕获(或安装包包含)的助手环境定义清单,纯展示、不读取源机、不改动任何文件
|
|
35
|
+
```bash
|
|
36
|
+
# 1. 扫描当前机器的 AI 助手环境(自动隔离敏感信息)
|
|
37
|
+
agentdock scan --agent all --root ~ --out ./my-env
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
# 2. 打包成可迁移包(敏感值替换为占位符,绝不写入真实 token)
|
|
40
|
+
agentdock export --from-scan ./my-env/agentdock.scan.yml --out ./my-env-pkg
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
npm run cli -- validate agentdock.yml --json
|
|
39
|
-
npm run cli -- init ./my-project --json
|
|
40
|
-
npm run cli -- export agentdock.yml
|
|
41
|
-
npm run cli -- export agentdock.yml --json
|
|
42
|
-
npm run cli -- install ./dist/exported ./dist/restored
|
|
43
|
-
npm run cli -- install ./dist/exported ./dist/restored --json
|
|
44
|
-
npm run cli -- upgrade agentdock.yml
|
|
45
|
-
npm run cli -- upgrade agentdock.yml --dry-run
|
|
46
|
-
npm run cli -- upgrade agentdock.yml --dry-run --verbose
|
|
47
|
-
npm run cli -- upgrade agentdock.yml --dry-run --json
|
|
48
|
-
npm run cli -- upgrade agentdock.yml --write ./agentdock.v2.yml
|
|
49
|
-
npm run cli -- upgrade agentdock.yml --backup
|
|
50
|
-
npm run cli -- upgrade agentdock.yml --force --dry-run
|
|
51
|
-
npm run cli -- scan
|
|
52
|
-
npm run cli -- scan --agent claude --json
|
|
53
|
-
npm run cli -- scan --agent claude --root ~ --out ./scan-out
|
|
54
|
-
npm run cli -- scan --agent codex --root ~ --out ./scan-codex
|
|
55
|
-
npm run cli -- export --from-scan ./scan-out/agentdock.scan.yml --out ./pkg
|
|
56
|
-
npm run cli -- export --from-scan ./scan-out/agentdock.scan.yml --out ./pkg --env ./scan-out/.env
|
|
57
|
-
npm run cli -- install ./pkg ./restored
|
|
58
|
-
npm run cli -- doctor --agent claude --root ~
|
|
59
|
-
npm run cli -- doctor --from-scan ./scan-out/agentdock.scan.yml
|
|
60
|
-
npm run cli -- doctor --package ./pkg
|
|
61
|
-
npm run cli -- doctor --agent claude --root ~ --out ./doctor-out
|
|
62
|
-
npm run cli -- list --from-scan ./scan-out/agentdock.scan.yml
|
|
63
|
-
npm run cli -- list --from-scan ./scan-out/agentdock.scan.yml --agent codex
|
|
64
|
-
npm run cli -- list --package ./pkg
|
|
65
|
-
npm run cli -- list --from-scan ./scan-out/agentdock.scan.yml --out ./list-out
|
|
42
|
+
# 3. 还原到目标机(填好 .env 后可用 --env 回注真实值)
|
|
43
|
+
agentdock install ./my-env-pkg ~
|
|
66
44
|
```
|
|
67
45
|
|
|
68
|
-
##
|
|
69
|
-
|
|
70
|
-
假设要把旧机的 Claude Code / Codex 环境整体迁移到新机(含 MCP、Skill、记忆、设置,且**绝不带真实 token**):
|
|
46
|
+
## 完整迁移:旧机 → 新机
|
|
71
47
|
|
|
72
48
|
```bash
|
|
73
|
-
#
|
|
49
|
+
# 在旧机:扫描并隔离敏感信息(产出 agentdock.scan.yml + .env.example + scan-report.md)
|
|
74
50
|
agentdock scan --agent all --root ~ --out ./scan-out
|
|
75
51
|
|
|
76
|
-
#
|
|
52
|
+
# 打包成可迁移包
|
|
77
53
|
agentdock export --from-scan ./scan-out/agentdock.scan.yml --out ./pkg
|
|
78
54
|
|
|
79
|
-
#
|
|
55
|
+
# 把 ./pkg 拷到新机后,先体检:无真实令牌泄露、无运行态文件混入
|
|
80
56
|
agentdock doctor --package ./pkg
|
|
81
57
|
|
|
82
|
-
#
|
|
58
|
+
# 还原到新机
|
|
83
59
|
agentdock install ./pkg ~
|
|
84
60
|
|
|
85
|
-
#
|
|
61
|
+
# 查看本次捕获了什么
|
|
86
62
|
agentdock list --package ./pkg
|
|
87
63
|
```
|
|
88
64
|
|
|
89
|
-
`scan` 永不读取 `auth.json` / `logs.sqlite`
|
|
90
|
-
|
|
91
|
-
##
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
65
|
+
`scan` 永不读取 `auth.json` / `logs.sqlite` 等运行态文件;真实 token 值不会写入任何产物。`doctor --package` 会二次校验包内无真实令牌泄露。
|
|
66
|
+
|
|
67
|
+
## 真实示例:一次迁移到底发生了什么
|
|
68
|
+
|
|
69
|
+
下面是用 AgentDock 迁移**一台真实 Windows 机器**的记录(Claude Code + Codex 双助手环境),数字均为实测:
|
|
70
|
+
|
|
71
|
+
**第 1 步 · `scan` 捕获了什么**
|
|
72
|
+
|
|
73
|
+
| 助手 | 类型 | 数量 |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| Claude Code | MCP Server | 9 |
|
|
76
|
+
| | Skill | 95 |
|
|
77
|
+
| | Agent | 4 |
|
|
78
|
+
| | Plugin | 2 |
|
|
79
|
+
| | Hook | 5 |
|
|
80
|
+
| | 记忆文件 / `settings.json` | 1 / 1 |
|
|
81
|
+
| Codex | `config.toml` / `AGENTS.md` | 1 / 1 |
|
|
82
|
+
| | MCP(含在 `config.toml` 内)| 9 |
|
|
83
|
+
|
|
84
|
+
同时自动隔离出 **7 个密钥**;运行态文件(`.codex/auth.json`、`cache`、`sessions`)被强制跳过,连读都不读。
|
|
85
|
+
|
|
86
|
+
**第 2 步 · 密钥是怎么被保护的(真实片段)**
|
|
87
|
+
|
|
88
|
+
扫描前 `.claude.json` 里长这样(真实 token 已打码显示):
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
"jimeng": {
|
|
92
|
+
"env": { "JIMENG_API_KEY": "cded****77b2" }
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`export` 打包后,落盘的只有占位符 —— **真实值从未写入任何产物**:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
"jimeng": {
|
|
100
|
+
"env": { "JIMENG_API_KEY": "{{AGENTDOCK_CLAUDE_JIMENG_API_KEY}}" }
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
原值进了 `.env.example`,等你在新机填好 `.env` 后,再 `export --from-scan <scan> --env <你的.env>` 回注即可。
|
|
105
|
+
|
|
106
|
+
**第 3 步 · `install` 还原出了什么**
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
restore/
|
|
110
|
+
├── .claude/
|
|
111
|
+
│ ├── skills/ (95 个,原样还原)
|
|
112
|
+
│ ├── agents/ (4 个)
|
|
113
|
+
│ ├── plugins/ (2 个)
|
|
114
|
+
│ └── settings.json
|
|
115
|
+
├── .claude.json (9 个 MCP 合并写入,token 为占位符)
|
|
116
|
+
└── .codex/
|
|
117
|
+
└── config.toml
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
7 个密钥在还原产物里全部以 `{{占位符}}` 形式存在,**真实值 0 落盘**。
|
|
121
|
+
|
|
122
|
+
> 一句话:你的整套环境(9 MCP / 95 Skill / 4 Agent / 2 Plugin / 5 Hook + Codex 配置)完整搬到了新目录,而 7 把钥匙始终攥在你自己手里的 `.env` 中。
|
|
123
|
+
|
|
124
|
+
## 命令速查
|
|
125
|
+
|
|
126
|
+
| 命令 | 作用 | 典型用法 |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `scan` | 发现并提取 AI 助手环境,隔离敏感信息,产出 v3 manifest | `agentdock scan --agent all --root ~ --out ./out` |
|
|
129
|
+
| `export` | 把扫描产物打包成可迁移包(默认打码,`--env` 回注) | `agentdock export --from-scan ./out/agentdock.scan.yml --out ./pkg` |
|
|
130
|
+
| `install` | 从包安全还原到目标机(越界校验 / 锁 / 原子写 / 幂等) | `agentdock install ./pkg ~` |
|
|
131
|
+
| `validate` | 校验 manifest 合法性 | `agentdock validate ./pkg/manifest.resolved.json` |
|
|
132
|
+
| `doctor` | 体检环境 / 包:配置健康度、可迁移性、是否泄密 | `agentdock doctor --agent all --root ~` |
|
|
133
|
+
| `list` | 列出已捕获的 MCP / Skill / Agent 等定义清单 | `agentdock list --package ./pkg` |
|
|
134
|
+
|
|
135
|
+
支持的双助手:**Claude Code**(JSON:`settings.json` + `.claude.json`)与 **Codex**(TOML:`config.toml` + `AGENTS.md`)。
|
|
136
|
+
|
|
137
|
+
## 安全承诺
|
|
138
|
+
|
|
139
|
+
- **敏感三层隔离**:字段名 + 值形态双重识别,命中即替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}`,原值进 `.env.example`,绝不下盘。
|
|
140
|
+
- **运行态强制跳过**:`auth.json` / `.credentials.json` / `logs.sqlite` / `cache/` 等纯凭据 / 运行产物,即使用户强制也拦下(连读都不读)。
|
|
141
|
+
- **引擎防御**:`install` 对每目标路径做越界校验(阻止 `../../` 穿越);输出 / 目标目录持排他锁防并发交错;所有写为 tmp+rename 原子写;已存在且内容相同的文件自动跳过(幂等)。
|
|
142
|
+
|
|
143
|
+
> 安全 KPI:敏感泄露事故数 = 0(硬性目标)。
|
|
144
|
+
|
|
145
|
+
## 文档
|
|
146
|
+
|
|
147
|
+
- [产品需求文档 PRD](./docs/PRD.md) —— 定位、用户、场景、边界、路线图
|
|
148
|
+
- [Changelog](./CHANGELOG.md) —— 版本变更
|
|
149
|
+
- [Release Guide](./docs/release.md) —— 发布与版本维护
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
[MIT](./LICENSE)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
package/dist/src/cli.js
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.runCli = runCli;
|
|
5
5
|
const export_1 = require("./commands/export");
|
|
6
|
-
const init_1 = require("./commands/init");
|
|
7
6
|
const install_1 = require("./commands/install");
|
|
8
7
|
const scan_1 = require("./commands/scan");
|
|
9
8
|
const doctor_1 = require("./commands/doctor");
|
|
10
9
|
const list_1 = require("./commands/list");
|
|
11
|
-
const upgrade_1 = require("./commands/upgrade");
|
|
12
10
|
const validate_1 = require("./commands/validate");
|
|
13
11
|
function parseCliOptions(args) {
|
|
14
12
|
const positionals = [];
|
|
@@ -94,12 +92,8 @@ async function runCli(args) {
|
|
|
94
92
|
return (0, validate_1.runValidateCommand)(positionals[0], options);
|
|
95
93
|
case 'export':
|
|
96
94
|
return (0, export_1.runExportCommand)(positionals[0], options);
|
|
97
|
-
case 'init':
|
|
98
|
-
return (0, init_1.runInitCommand)(positionals[0], options);
|
|
99
95
|
case 'install':
|
|
100
96
|
return (0, install_1.runInstallCommand)(positionals[0], positionals[1], options);
|
|
101
|
-
case 'upgrade':
|
|
102
|
-
return (0, upgrade_1.runUpgradeCommand)(positionals[0], options);
|
|
103
97
|
case 'scan':
|
|
104
98
|
return (0, scan_1.runScanCommand)(options);
|
|
105
99
|
case 'doctor':
|
|
@@ -110,7 +104,7 @@ async function runCli(args) {
|
|
|
110
104
|
return {
|
|
111
105
|
exitCode: 1,
|
|
112
106
|
stdout: [],
|
|
113
|
-
stderr: ['Usage: agentdock <
|
|
107
|
+
stderr: ['Usage: agentdock <scan|export|install|validate|doctor|list> [path]'],
|
|
114
108
|
};
|
|
115
109
|
}
|
|
116
110
|
}
|
|
@@ -6,8 +6,6 @@ exports.COMMAND_ERROR_CODES = {
|
|
|
6
6
|
MISSING_ARGUMENT: 'MISSING_ARGUMENT',
|
|
7
7
|
MANIFEST_NOT_FOUND: 'MANIFEST_NOT_FOUND',
|
|
8
8
|
MANIFEST_INVALID: 'MANIFEST_INVALID',
|
|
9
|
-
MANIFEST_ALREADY_EXISTS: 'MANIFEST_ALREADY_EXISTS',
|
|
10
|
-
UNSUPPORTED_MANIFEST_VERSION: 'UNSUPPORTED_MANIFEST_VERSION',
|
|
11
9
|
TEMPLATE_VARIABLE_MISSING: 'TEMPLATE_VARIABLE_MISSING',
|
|
12
10
|
MISSING_PACKAGE_MANIFEST: 'MISSING_PACKAGE_MANIFEST',
|
|
13
11
|
MISSING_INSTALL_PLAN: 'MISSING_INSTALL_PLAN',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
};
|