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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 spsz831
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# AgentDock
|
|
2
|
+
|
|
3
|
+
AgentDock 是 **AI 编码助手(Claude Code / Codex)环境的迁移、备份与版本化工具**——你的 AI 编程助手的 dotfiles 工具。底层仍以单文件 `agentdock.yml` 承载通用打包能力。
|
|
4
|
+
|
|
5
|
+
> 产品定位、目标用户、边界与路线图见 **[产品需求文档 (PRD)](./docs/PRD.md)**,本文档对外口径一律以 PRD 为准。
|
|
6
|
+
|
|
7
|
+
发布与版本维护请参考:[Release Guide](./docs/release.md) 与 [Changelog](./CHANGELOG.md).
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
AgentDock 以 npm 包发布(包名 `agentdock-cli`,命令为 `agentdock`),要求 Node.js >= 18:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 全局安装,获得 agentdock 命令
|
|
15
|
+
npm install -g agentdock-cli
|
|
16
|
+
|
|
17
|
+
# 或免安装直接运行(npx 会临时拉取)
|
|
18
|
+
npx agentdock-cli --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
安装后所有命令以 `agentdock` 调用,例如 `agentdock scan --agent claude`。
|
|
22
|
+
(仓库贡献者仍可用开发模式 `npm run cli -- <command>`。)
|
|
23
|
+
|
|
24
|
+
## 功能范围(按层)
|
|
25
|
+
|
|
26
|
+
- `init`:初始化项目清单
|
|
27
|
+
- `validate`:校验清单
|
|
28
|
+
- `export`:按清单导出目录内容为稳定包结构
|
|
29
|
+
- `install`:从导出包恢复到目标目录
|
|
30
|
+
- `upgrade`:将旧版 manifest 升级到新版结构
|
|
31
|
+
- `scan`:自动发现并提取 Claude Code / Codex 的 AI 助手环境(MCP / Skill / Agent / Plugin / Hook / 记忆),隔离敏感信息,产出领域化 manifest v3(预览中)
|
|
32
|
+
- `list`:列出已扫描捕获(或安装包包含)的助手环境定义清单,纯展示、不读取源机、不改动任何文件
|
|
33
|
+
|
|
34
|
+
## Quickstart
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run cli -- validate agentdock.yml
|
|
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
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 端到端:把 AI 助手环境搬到新机器
|
|
69
|
+
|
|
70
|
+
假设要把旧机的 Claude Code / Codex 环境整体迁移到新机(含 MCP、Skill、记忆、设置,且**绝不带真实 token**):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# 1) 在旧机扫描,隔离敏感信息(产出 agentdock.scan.yml + .env.example)
|
|
74
|
+
agentdock scan --agent all --root ~ --out ./scan-out
|
|
75
|
+
|
|
76
|
+
# 2) 把扫描产物打包成可迁移包(敏感值替换为 {{占位符}},绝不写入真实 token)
|
|
77
|
+
agentdock export --from-scan ./scan-out/agentdock.scan.yml --out ./pkg
|
|
78
|
+
|
|
79
|
+
# 3) 拷到新机后,体检包:无真实令牌泄露、无运行态文件混入
|
|
80
|
+
agentdock doctor --package ./pkg
|
|
81
|
+
|
|
82
|
+
# 4) 还原到新机(目标机填写 .env 后可用 --env 回注真实值)
|
|
83
|
+
agentdock install ./pkg ~
|
|
84
|
+
|
|
85
|
+
# 5) 查看本次捕获了什么
|
|
86
|
+
agentdock list --package ./pkg
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`scan` 永不读取 `auth.json` / `logs.sqlite` 等运行态文件,真实 token 值不会写入任何产物;`doctor --package` 会二次校验包内无真实令牌泄露。
|
|
90
|
+
|
|
91
|
+
## Current behavior
|
|
92
|
+
|
|
93
|
+
- manifest v2 支持 `sources[*].destination`
|
|
94
|
+
- v1 manifest 仍可读取并校验
|
|
95
|
+
- `upgrade` 可将 v1 升级为 v2
|
|
96
|
+
- `upgrade --dry-run` 可先查看 diff 预览,不写回文件
|
|
97
|
+
- `upgrade --dry-run --json` 输出机器可读 diff 结果(单行 JSON)
|
|
98
|
+
- `upgrade --dry-run --json` 还包含 `summary`(`addedDestinationCount`、`changedLineCount`、`sourceCount`、`templateCount`、`warningCount`、`warnings`)
|
|
99
|
+
- `init/validate/export/install/upgrade --json` 现已统一为版本化协议(`schemaVersion`、`generatedAt`、`toolVersion`、`command`、`success`、`data`、`errors`)
|
|
100
|
+
- `upgrade --json` 的升级专用字段(如 `diff`、`summary`)已统一放入 `data`
|
|
101
|
+
- `upgrade` 文本模式默认输出稳定摘要;仅在 `--verbose` 时附加 diff 详情
|
|
102
|
+
- 所有 `--json` 的 `errors` 为结构化数组:`[{ code, message }]`
|
|
103
|
+
- `scan` 自动发现 AI 助手环境并隔离敏感信息,生成 `agentdock.scan.yml` + `.env.example` + `scan-report.md`:
|
|
104
|
+
- **Claude Code**:MCP(来自 `.claude.json`)、skills、agents、plugins、hooks、记忆文件与 `settings.json`
|
|
105
|
+
- **Codex (OpenAI)**:`config.toml`(含 `mcp_servers` 与 provider 配置)、`AGENTS.md` 记忆文件
|
|
106
|
+
- `scan` 永不包含运行态文件:`auth.json` / `.credentials.json` / `logs.sqlite` / `history.sqlite` / `cache` 等,真实 token 值不会写入任何产出;Codex 的 `auth.json` / `logs.sqlite` 同样被强制跳过
|
|
107
|
+
- `scan --agent codex` 现已实现:解析 `~/.codex/config.toml`(TOML),将 `mcp_servers` 中的 env 令牌与 provider 令牌隔离为 `{{AGENTDOCK_CODEX_<KEY>}}` 占位符
|
|
108
|
+
- `scan` 与 `export`/`install` 已闭环:`export --from-scan <scan>/agentdock.scan.yml` 把 v3 扫描产物打包成 `install` 可直接消费的包(manifest.resolved.json + meta/install-plan.json + payload/sources/*),引擎层 `install` 零改动即可还原
|
|
109
|
+
- `--from-scan` 默认把敏感值替换为 `{{AGENTDOCK_<AGENT>_<KEY>}}` 占位符,绝不写入真实 token;传入 `--env <file>` 可在打包时回注真实值(占位符名与 `scan` 产出的 `.env.example` 完全一致)
|
|
110
|
+
- `--from-scan` 默认输出到扫描目录的同级 `package/` 子目录(可用 `--out` 覆盖)
|
|
111
|
+
- MCP server:Claude 的 MCP 在打包时被聚合写入单一 `.claude.json`(仅 mcpServers 段),适配"还原到全新/目标机";Codex 的 `mcp_servers` 内嵌在 `config.toml` 中,作为 `settings` 条目整体捕获并在导出时按 TOML 打码还原,绝不生成 `.claude.json`;其它定义(skills/agents/plugins/hooks/记忆/settings)按相对路径原样拷入 `payload/sources/`
|
|
112
|
+
- `export --from-scan` 在输出目录持排他锁,错误码复用 `MANIFEST_INVALID`(v3 以外版本)与 `LOCK_TIMEOUT`
|
|
113
|
+
- `doctor` 体检当前 AI 助手环境(默认 `--agent all`,复用 scan 的扫描与敏感识别):配置合法性、可迁移内容清点、敏感泄露风险(自由文本文件中的真实令牌会被标红,因 scan 不对 skill/agent/memory/hook/plugin 打码)、运行态隔离确认
|
|
114
|
+
- `doctor --from-scan <yml>` 审计扫描产物:源文件引用完整性、产物无真实令牌泄露、产物无运行态文件、隔离机密数量与 `.env.example` 占位符数量一致
|
|
115
|
+
- `doctor --package <dir>` 审计安装包(`payload/sources`):同样检查无真实令牌泄露、无运行态文件混入
|
|
116
|
+
- `doctor --out <dir>` 把体检报告写入 `doctor-report.md`;`--json` 输出机器可读报告(沿用统一协议),发现失败项时退出码非 0
|
|
117
|
+
- 错误码新增 `DOCTOR_FAILED`(doctor 运行期异常兜底)
|
|
118
|
+
- `list` 列出扫描产物(或安装包)的捕获清单:按助手(Claude Code / Codex)分组展示 MCP / Skill / Agent / Plugin / Hook / Memory / Settings 的名称与计数,并汇总隔离机密数量;`--agent codex` 可仅看 Codex
|
|
119
|
+
- `list --from-scan <yml>` 读取 v3 扫描 manifest(`agentdock.scan.yml`);`list --package <dir>` 读取安装包的 `manifest.resolved.json` 并额外展示 `meta/install-plan.json` 的文件→目标映射
|
|
120
|
+
- `list --out <dir>` 把清单写入 `list-report.md`;`--json` 输出机器可读清单(沿用统一协议)
|
|
121
|
+
- 错误码新增 `LIST_FAILED`(list 运行期异常兜底)
|
|
122
|
+
- `upgrade --write <path>` 将升级结果写到新文件,保留原文件不变
|
|
123
|
+
- `upgrade --backup` 原位升级前生成备份文件(`<manifest>.bak.<timestamp>`)
|
|
124
|
+
- `upgrade --force` 即使已是 v2 也会按当前规则重新处理并输出 diff
|
|
125
|
+
- templates 在 `export` 阶段完成 `{{VAR_NAME}}` 渲染
|
|
126
|
+
- `options.followSymlinks` 默认是 `true`,导出目录时会跟随并复制链接目标内容
|
|
127
|
+
- 设置 `options.followSymlinks: false` 可在导出时跳过链接目录/文件
|
|
128
|
+
- `install` 默认会先做冲突预检查:已存在且内容相同的文件自动跳过(幂等),仅内容真冲突才报错
|
|
129
|
+
- `install --overwrite` 允许覆盖已存在文件
|
|
130
|
+
- `install` 对每个目标路径做越界校验,阻止 `destination: ../../../` 形式的路径穿越
|
|
131
|
+
- `install` / `export` 在目标/输出目录上持有排他锁,并发执行会被串行化(避免交错损坏)
|
|
132
|
+
- 所有写操作(manifest / 包 / 升级结果)均为 tmp + rename 原子写,崩溃不残留半截文件
|
|
133
|
+
|
|
134
|
+
## JSON Error Codes
|
|
135
|
+
|
|
136
|
+
- `MISSING_ARGUMENT`
|
|
137
|
+
- `MANIFEST_NOT_FOUND`
|
|
138
|
+
- `MANIFEST_INVALID`
|
|
139
|
+
- `MANIFEST_ALREADY_EXISTS`
|
|
140
|
+
- `UNSUPPORTED_MANIFEST_VERSION`
|
|
141
|
+
- `TEMPLATE_VARIABLE_MISSING`
|
|
142
|
+
- `MISSING_PACKAGE_MANIFEST`
|
|
143
|
+
- `MISSING_INSTALL_PLAN`
|
|
144
|
+
- `INSTALL_CONFLICT`
|
|
145
|
+
- `PATH_ESCAPE`
|
|
146
|
+
- `LOCK_TIMEOUT`
|
|
147
|
+
- `SCAN_FAILED`
|
|
148
|
+
- `DOCTOR_FAILED`
|
|
149
|
+
- `LIST_FAILED`
|
|
150
|
+
- `UNKNOWN_ERROR`
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentdock-cli",
|
|
3
|
+
"version": "0.4.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"codex",
|
|
8
|
+
"ai-coding-assistant",
|
|
9
|
+
"dotfiles",
|
|
10
|
+
"environment-migration",
|
|
11
|
+
"backup",
|
|
12
|
+
"versioning",
|
|
13
|
+
"mcp",
|
|
14
|
+
"skills",
|
|
15
|
+
"cli"
|
|
16
|
+
],
|
|
17
|
+
"type": "commonjs",
|
|
18
|
+
"bin": {
|
|
19
|
+
"agentdock": "dist/src/cli.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"require('fs').copyFileSync('package.json','dist/package.json')\"",
|
|
31
|
+
"dev": "tsx src/cli.ts",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"cli": "tsx src/cli.ts",
|
|
34
|
+
"prepublishOnly": "npm run build",
|
|
35
|
+
"release:commits": "node scripts/generate-commit-groups.js"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"ajv": "^8.17.1",
|
|
39
|
+
"diff": "^8.0.4",
|
|
40
|
+
"minimatch": "^10.2.5",
|
|
41
|
+
"smol-toml": "^1.7.0",
|
|
42
|
+
"yaml": "^2.8.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^24.6.0",
|
|
46
|
+
"tsx": "^4.20.6",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^3.2.4"
|
|
49
|
+
},
|
|
50
|
+
"author": "spsz831",
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/spsz831/AgentDock.git"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/spsz831/AgentDock#readme",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/spsz831/AgentDock/issues"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://agentdock.local/schemas/agentdock.schema.json",
|
|
4
|
+
"oneOf": [
|
|
5
|
+
{ "$ref": "#/$defs/manifestV1" },
|
|
6
|
+
{ "$ref": "#/$defs/manifestV2" }
|
|
7
|
+
],
|
|
8
|
+
"$defs": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"required": ["name"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"name": { "type": "string", "minLength": 1 },
|
|
15
|
+
"description": { "type": "string" }
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"sourceBase": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"required": ["id", "type", "path"],
|
|
22
|
+
"properties": {
|
|
23
|
+
"id": { "type": "string", "minLength": 1 },
|
|
24
|
+
"type": { "type": "string", "enum": ["file", "directory"] },
|
|
25
|
+
"path": { "type": "string", "minLength": 1 },
|
|
26
|
+
"include": {
|
|
27
|
+
"type": "array",
|
|
28
|
+
"items": { "type": "string", "minLength": 1 }
|
|
29
|
+
},
|
|
30
|
+
"exclude": {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"items": { "type": "string", "minLength": 1 }
|
|
33
|
+
},
|
|
34
|
+
"destination": { "type": "string", "minLength": 1 }
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"template": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": false,
|
|
40
|
+
"required": ["id", "source", "destination"],
|
|
41
|
+
"properties": {
|
|
42
|
+
"id": { "type": "string", "minLength": 1 },
|
|
43
|
+
"source": { "type": "string", "minLength": 1 },
|
|
44
|
+
"destination": { "type": "string", "minLength": 1 },
|
|
45
|
+
"variables": {
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": { "type": "string" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"outputs": {
|
|
52
|
+
"type": "object",
|
|
53
|
+
"additionalProperties": false,
|
|
54
|
+
"required": ["type", "path"],
|
|
55
|
+
"properties": {
|
|
56
|
+
"type": { "type": "string", "const": "directory" },
|
|
57
|
+
"path": { "type": "string", "minLength": 1 }
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"install": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"additionalProperties": false,
|
|
63
|
+
"properties": {
|
|
64
|
+
"mode": { "type": "string", "enum": ["package", "direct"] },
|
|
65
|
+
"targetPath": { "type": "string", "minLength": 1 },
|
|
66
|
+
"overwrite": { "type": "boolean" }
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"options": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"additionalProperties": false,
|
|
72
|
+
"properties": {
|
|
73
|
+
"includeHidden": { "type": "boolean" },
|
|
74
|
+
"overwrite": { "type": "boolean" },
|
|
75
|
+
"followSymlinks": { "type": "boolean" }
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"manifestV1": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"required": ["version", "project", "sources", "outputs"],
|
|
82
|
+
"properties": {
|
|
83
|
+
"version": { "type": "integer", "const": 1 },
|
|
84
|
+
"project": { "$ref": "#/$defs/project" },
|
|
85
|
+
"sources": {
|
|
86
|
+
"type": "array",
|
|
87
|
+
"minItems": 1,
|
|
88
|
+
"items": { "$ref": "#/$defs/sourceBase" }
|
|
89
|
+
},
|
|
90
|
+
"templates": {
|
|
91
|
+
"type": "array",
|
|
92
|
+
"items": { "$ref": "#/$defs/template" }
|
|
93
|
+
},
|
|
94
|
+
"outputs": { "$ref": "#/$defs/outputs" },
|
|
95
|
+
"install": { "$ref": "#/$defs/install" },
|
|
96
|
+
"options": { "$ref": "#/$defs/options" }
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"manifestV2": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"additionalProperties": false,
|
|
102
|
+
"required": ["version", "project", "sources", "outputs"],
|
|
103
|
+
"properties": {
|
|
104
|
+
"version": { "type": "integer", "const": 2 },
|
|
105
|
+
"project": { "$ref": "#/$defs/project" },
|
|
106
|
+
"sources": {
|
|
107
|
+
"type": "array",
|
|
108
|
+
"minItems": 1,
|
|
109
|
+
"items": { "$ref": "#/$defs/sourceBase" }
|
|
110
|
+
},
|
|
111
|
+
"templates": {
|
|
112
|
+
"type": "array",
|
|
113
|
+
"items": { "$ref": "#/$defs/template" }
|
|
114
|
+
},
|
|
115
|
+
"outputs": { "$ref": "#/$defs/outputs" },
|
|
116
|
+
"install": { "$ref": "#/$defs/install" },
|
|
117
|
+
"options": { "$ref": "#/$defs/options" }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.runCli = runCli;
|
|
5
|
+
const export_1 = require("./commands/export");
|
|
6
|
+
const init_1 = require("./commands/init");
|
|
7
|
+
const install_1 = require("./commands/install");
|
|
8
|
+
const scan_1 = require("./commands/scan");
|
|
9
|
+
const doctor_1 = require("./commands/doctor");
|
|
10
|
+
const list_1 = require("./commands/list");
|
|
11
|
+
const upgrade_1 = require("./commands/upgrade");
|
|
12
|
+
const validate_1 = require("./commands/validate");
|
|
13
|
+
function parseCliOptions(args) {
|
|
14
|
+
const positionals = [];
|
|
15
|
+
const options = {};
|
|
16
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
17
|
+
const arg = args[index];
|
|
18
|
+
if (arg === '--overwrite') {
|
|
19
|
+
options.overwrite = true;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (arg === '--dry-run') {
|
|
23
|
+
options.dryRun = true;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (arg === '--json') {
|
|
27
|
+
options.json = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (arg === '--verbose') {
|
|
31
|
+
options.verbose = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (arg === '--backup') {
|
|
35
|
+
options.backup = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (arg === '--force') {
|
|
39
|
+
options.force = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (arg === '--write') {
|
|
43
|
+
const nextArg = args[index + 1];
|
|
44
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
45
|
+
options.writePath = nextArg;
|
|
46
|
+
index += 1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
positionals.push(arg);
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (arg === '--agent' || arg === '--root' || arg === '--out') {
|
|
54
|
+
const nextArg = args[index + 1];
|
|
55
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
56
|
+
if (arg === '--agent')
|
|
57
|
+
options.agent = nextArg;
|
|
58
|
+
if (arg === '--root')
|
|
59
|
+
options.root = nextArg;
|
|
60
|
+
if (arg === '--out')
|
|
61
|
+
options.out = nextArg;
|
|
62
|
+
index += 1;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
positionals.push(arg);
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (arg === '--from-scan' || arg === '--env' || arg === '--package') {
|
|
70
|
+
const nextArg = args[index + 1];
|
|
71
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
72
|
+
if (arg === '--from-scan')
|
|
73
|
+
options.fromScan = nextArg;
|
|
74
|
+
if (arg === '--env')
|
|
75
|
+
options.env = nextArg;
|
|
76
|
+
if (arg === '--package')
|
|
77
|
+
options.package = nextArg;
|
|
78
|
+
index += 1;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
positionals.push(arg);
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
positionals.push(arg);
|
|
86
|
+
}
|
|
87
|
+
return { positionals, options };
|
|
88
|
+
}
|
|
89
|
+
async function runCli(args) {
|
|
90
|
+
const [command, ...rest] = args;
|
|
91
|
+
const { positionals, options } = parseCliOptions(rest);
|
|
92
|
+
switch (command) {
|
|
93
|
+
case 'validate':
|
|
94
|
+
return (0, validate_1.runValidateCommand)(positionals[0], options);
|
|
95
|
+
case 'export':
|
|
96
|
+
return (0, export_1.runExportCommand)(positionals[0], options);
|
|
97
|
+
case 'init':
|
|
98
|
+
return (0, init_1.runInitCommand)(positionals[0], options);
|
|
99
|
+
case 'install':
|
|
100
|
+
return (0, install_1.runInstallCommand)(positionals[0], positionals[1], options);
|
|
101
|
+
case 'upgrade':
|
|
102
|
+
return (0, upgrade_1.runUpgradeCommand)(positionals[0], options);
|
|
103
|
+
case 'scan':
|
|
104
|
+
return (0, scan_1.runScanCommand)(options);
|
|
105
|
+
case 'doctor':
|
|
106
|
+
return (0, doctor_1.runDoctorCommand)(options);
|
|
107
|
+
case 'list':
|
|
108
|
+
return (0, list_1.runListCommand)(options);
|
|
109
|
+
default:
|
|
110
|
+
return {
|
|
111
|
+
exitCode: 1,
|
|
112
|
+
stdout: [],
|
|
113
|
+
stderr: ['Usage: agentdock <init|validate|export|install|upgrade|scan|doctor|list> [path]'],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function main() {
|
|
118
|
+
const result = await runCli(process.argv.slice(2));
|
|
119
|
+
for (const line of result.stdout) {
|
|
120
|
+
console.log(line);
|
|
121
|
+
}
|
|
122
|
+
for (const line of result.stderr) {
|
|
123
|
+
console.error(line);
|
|
124
|
+
}
|
|
125
|
+
process.exitCode = result.exitCode;
|
|
126
|
+
}
|
|
127
|
+
if (require.main === module) {
|
|
128
|
+
void main();
|
|
129
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.runDoctorCommand = runDoctorCommand;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const doctor_1 = require("../core/doctor");
|
|
9
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
10
|
+
const command_json_1 = require("../utils/command-json");
|
|
11
|
+
async function runDoctorCommand(options = {}) {
|
|
12
|
+
const agent = options.agent ?? 'all';
|
|
13
|
+
const out = options.out ? node_path_1.default.resolve(options.out) : undefined;
|
|
14
|
+
try {
|
|
15
|
+
const report = await (0, doctor_1.runDoctor)({
|
|
16
|
+
agent,
|
|
17
|
+
root: options.root,
|
|
18
|
+
fromScan: options.fromScan,
|
|
19
|
+
package: options.package,
|
|
20
|
+
out,
|
|
21
|
+
});
|
|
22
|
+
if (options.json === true) {
|
|
23
|
+
return {
|
|
24
|
+
exitCode: report.healthy ? 0 : 1,
|
|
25
|
+
stdout: [(0, command_json_1.toJsonLine)('doctor', report.healthy, report, [])],
|
|
26
|
+
stderr: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const lines = [
|
|
30
|
+
`Doctor (${report.mode})${report.agent ? ` agent=${report.agent}` : ''}`,
|
|
31
|
+
report.summary,
|
|
32
|
+
...report.checks.map((check) => ` [${check.status.toUpperCase()}] ${check.label} — ${check.detail}`),
|
|
33
|
+
...(report.reportPath ? [`report: ${report.reportPath}`] : []),
|
|
34
|
+
];
|
|
35
|
+
return { exitCode: report.healthy ? 0 : 1, stdout: lines, stderr: [] };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
if (options.json === true) {
|
|
40
|
+
const data = { mode: 'live', agent, target: '', healthy: false, checks: [], summary: message };
|
|
41
|
+
return {
|
|
42
|
+
exitCode: 1,
|
|
43
|
+
stdout: [(0, command_json_1.toJsonLine)('doctor', false, data, [(0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.DOCTOR_FAILED, message)])],
|
|
44
|
+
stderr: [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return { exitCode: 1, stdout: [], stderr: [message] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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.runExportCommand = runExportCommand;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const exporter_1 = require("../core/exporter");
|
|
9
|
+
const scan_export_1 = require("../core/scan-export");
|
|
10
|
+
const command_error_codes_1 = require("../constants/command-error-codes");
|
|
11
|
+
const load_1 = require("../manifest/load");
|
|
12
|
+
const validate_1 = require("../manifest/validate");
|
|
13
|
+
const command_json_1 = require("../utils/command-json");
|
|
14
|
+
async function runExportCommand(manifestPath, options = {}) {
|
|
15
|
+
// `scan` → package bridge: build an installable package from a v3 scan manifest.
|
|
16
|
+
if (options.fromScan) {
|
|
17
|
+
const out = options.out
|
|
18
|
+
? node_path_1.default.resolve(options.out)
|
|
19
|
+
: node_path_1.default.resolve(node_path_1.default.join(node_path_1.default.dirname(node_path_1.default.resolve(options.fromScan)), 'package'));
|
|
20
|
+
try {
|
|
21
|
+
const exportResult = await (0, scan_export_1.exportFromScan)({
|
|
22
|
+
scanManifestPath: options.fromScan,
|
|
23
|
+
out,
|
|
24
|
+
env: options.env ? node_path_1.default.resolve(options.env) : undefined,
|
|
25
|
+
overwrite: options.overwrite,
|
|
26
|
+
});
|
|
27
|
+
if (options.json === true) {
|
|
28
|
+
return {
|
|
29
|
+
exitCode: 0,
|
|
30
|
+
stdout: [(0, command_json_1.toJsonLine)('export', true, {
|
|
31
|
+
manifestPath: node_path_1.default.resolve(options.fromScan),
|
|
32
|
+
outputPath: exportResult.outputPath,
|
|
33
|
+
snapshotPath: exportResult.snapshotPath,
|
|
34
|
+
installPlanPath: exportResult.installPlanPath,
|
|
35
|
+
}, [])],
|
|
36
|
+
stderr: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
exitCode: 0,
|
|
41
|
+
stdout: [`Export (from scan) completed: ${exportResult.outputPath}`],
|
|
42
|
+
stderr: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return scanExportError(error, options, node_path_1.default.resolve(options.fromScan));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const effectiveManifestPath = manifestPath ?? 'agentdock.yml';
|
|
50
|
+
try {
|
|
51
|
+
const loaded = await (0, load_1.loadManifest)(effectiveManifestPath);
|
|
52
|
+
const result = (0, validate_1.validateManifest)(loaded.data);
|
|
53
|
+
if (!result.valid) {
|
|
54
|
+
if (options.json === true) {
|
|
55
|
+
return {
|
|
56
|
+
exitCode: 1,
|
|
57
|
+
stdout: [(0, command_json_1.toJsonLine)('export', false, { manifestPath: loaded.path }, result.errors.map((message) => (0, command_json_1.toJsonError)(command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_INVALID, message)))],
|
|
58
|
+
stderr: [],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
exitCode: 1,
|
|
63
|
+
stdout: [],
|
|
64
|
+
stderr: result.errors,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const exportResult = await (0, exporter_1.exportManifest)(loaded.data, loaded.directory);
|
|
68
|
+
if (options.json === true) {
|
|
69
|
+
return {
|
|
70
|
+
exitCode: 0,
|
|
71
|
+
stdout: [(0, command_json_1.toJsonLine)('export', true, {
|
|
72
|
+
manifestPath: loaded.path,
|
|
73
|
+
outputPath: exportResult.outputPath,
|
|
74
|
+
snapshotPath: exportResult.snapshotPath,
|
|
75
|
+
installPlanPath: exportResult.installPlanPath,
|
|
76
|
+
}, [])],
|
|
77
|
+
stderr: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
exitCode: 0,
|
|
82
|
+
stdout: [`Export completed: ${exportResult.outputPath}`],
|
|
83
|
+
stderr: [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
88
|
+
if (options.json === true) {
|
|
89
|
+
let code = command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
90
|
+
if (message.includes('ENOENT')) {
|
|
91
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_NOT_FOUND;
|
|
92
|
+
}
|
|
93
|
+
if (message.includes('Missing template variable(s)')) {
|
|
94
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.TEMPLATE_VARIABLE_MISSING;
|
|
95
|
+
}
|
|
96
|
+
if (message.includes('LOCK_TIMEOUT')) {
|
|
97
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.LOCK_TIMEOUT;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
exitCode: 1,
|
|
101
|
+
stdout: [(0, command_json_1.toJsonLine)('export', false, { manifestPath: effectiveManifestPath }, [(0, command_json_1.toJsonError)(code, message)])],
|
|
102
|
+
stderr: [],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
exitCode: 1,
|
|
107
|
+
stdout: [],
|
|
108
|
+
stderr: [message],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function scanExportError(error, options, manifestPath) {
|
|
113
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
114
|
+
if (options.json === true) {
|
|
115
|
+
let code = command_error_codes_1.COMMAND_ERROR_CODES.UNKNOWN_ERROR;
|
|
116
|
+
if (message.includes('SCAN_EXPORT_UNSUPPORTED')) {
|
|
117
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.MANIFEST_INVALID;
|
|
118
|
+
}
|
|
119
|
+
if (message.includes('LOCK_TIMEOUT')) {
|
|
120
|
+
code = command_error_codes_1.COMMAND_ERROR_CODES.LOCK_TIMEOUT;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
exitCode: 1,
|
|
124
|
+
stdout: [(0, command_json_1.toJsonLine)('export', false, { manifestPath }, [(0, command_json_1.toJsonError)(code, message)])],
|
|
125
|
+
stderr: [],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
exitCode: 1,
|
|
130
|
+
stdout: [],
|
|
131
|
+
stderr: [message],
|
|
132
|
+
};
|
|
133
|
+
}
|