agentdock-cli 1.1.0 → 1.2.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.
@@ -0,0 +1,535 @@
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.SNAPSHOT_BUNDLE_DIR = void 0;
7
+ exports.configFilesFor = configFilesFor;
8
+ exports.snapshotsDir = snapshotsDir;
9
+ exports.hashBuffer = hashBuffer;
10
+ exports.redactConfigText = redactConfigText;
11
+ exports.createSnapshot = createSnapshot;
12
+ exports.listSnapshots = listSnapshots;
13
+ exports.latestSnapshot = latestSnapshot;
14
+ exports.loadSnapshot = loadSnapshot;
15
+ exports.readSnapshotContents = readSnapshotContents;
16
+ exports.readLiveConfig = readLiveConfig;
17
+ exports.findUnchangedSnapshot = findUnchangedSnapshot;
18
+ exports.exportSnapshot = exportSnapshot;
19
+ exports.importSnapshots = importSnapshots;
20
+ exports.planRestore = planRestore;
21
+ exports.applyRestore = applyRestore;
22
+ exports.prepareUndo = prepareUndo;
23
+ exports.applyUndo = applyUndo;
24
+ const node_crypto_1 = __importDefault(require("node:crypto"));
25
+ const promises_1 = __importDefault(require("node:fs/promises"));
26
+ const node_path_1 = __importDefault(require("node:path"));
27
+ const package_json_1 = __importDefault(require("../../package.json"));
28
+ const snapshot_diff_1 = require("./snapshot-diff");
29
+ const fs_1 = require("../utils/fs");
30
+ /**
31
+ * 配置快照(v1.2)。
32
+ * 只采集关键配置文件(不复制 skills / memory 全量),默认明文保存,
33
+ * `--redact` 时对疑似令牌值打码。所有写入都限制在 `<root>/.agentdock` 内。
34
+ */
35
+ /** 每个 agent 需要纳入快照的配置文件(相对用户主目录)。 */
36
+ const CONFIG_FILES = {
37
+ claude: ['.claude.json', '.claude/settings.json', '.claude/settings.local.json'],
38
+ codex: ['.codex/config.toml'],
39
+ };
40
+ const SECRET_KEY_PATTERN = /(token|secret|passw|api[_-]?key|auth|credential|cookie)/i;
41
+ const REDACTED = '***REDACTED***';
42
+ /** 只保留最近这么多个快照的索引条目,避免 index.json 无限增长。 */
43
+ const MAX_INDEX_ENTRIES = 200;
44
+ function configFilesFor(agent) {
45
+ if (agent === 'claude')
46
+ return [...CONFIG_FILES.claude];
47
+ if (agent === 'codex')
48
+ return [...CONFIG_FILES.codex];
49
+ return [...CONFIG_FILES.claude, ...CONFIG_FILES.codex];
50
+ }
51
+ function snapshotsDir(root) {
52
+ return node_path_1.default.join(root, '.agentdock', 'snapshots');
53
+ }
54
+ function indexPath(root) {
55
+ return node_path_1.default.join(snapshotsDir(root), 'index.json');
56
+ }
57
+ function restoreRecordPath(root) {
58
+ return node_path_1.default.join(root, '.agentdock', 'last-restore.json');
59
+ }
60
+ function hashBuffer(data) {
61
+ return node_crypto_1.default.createHash('sha256').update(data).digest('hex');
62
+ }
63
+ function fileKind(relPath) {
64
+ if (relPath.endsWith('.json'))
65
+ return 'json';
66
+ if (relPath.endsWith('.toml'))
67
+ return 'toml';
68
+ return 'text';
69
+ }
70
+ function redactTextByLine(text) {
71
+ return text
72
+ .split(/\r?\n/)
73
+ .map((line) => {
74
+ const match = /^(\s*[A-Za-z0-9_.-]*(?:token|secret|passw|api[_-]?key|auth|credential)[A-Za-z0-9_.-]*\s*=\s*).*/i.exec(line);
75
+ return match ? `${match[1]}"${REDACTED}"` : line;
76
+ })
77
+ .join('\n');
78
+ }
79
+ function redactJsonValue(value) {
80
+ if (Array.isArray(value)) {
81
+ return value.map(redactJsonValue);
82
+ }
83
+ if (value && typeof value === 'object') {
84
+ const out = {};
85
+ for (const [key, value2] of Object.entries(value)) {
86
+ out[key] = SECRET_KEY_PATTERN.test(key) ? REDACTED : redactJsonValue(value2);
87
+ }
88
+ return out;
89
+ }
90
+ return value;
91
+ }
92
+ /** 对单个配置文件内容做脱敏;解析失败时退回按行正则。 */
93
+ function redactConfigText(relPath, text) {
94
+ if (fileKind(relPath) === 'json') {
95
+ try {
96
+ return `${JSON.stringify(redactJsonValue(JSON.parse(text)), null, 2)}\n`;
97
+ }
98
+ catch {
99
+ return redactTextByLine(text);
100
+ }
101
+ }
102
+ return redactTextByLine(text);
103
+ }
104
+ function computeCounts(files) {
105
+ let topLevelKeys = 0;
106
+ let envKeys = 0;
107
+ let mcpCount = 0;
108
+ for (const [relPath, buffer] of files) {
109
+ const parsed = (0, snapshot_diff_1.parseConfigObject)(relPath, buffer.toString('utf8'));
110
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
111
+ continue;
112
+ }
113
+ const obj = parsed;
114
+ topLevelKeys += Object.keys(obj).length;
115
+ if (relPath.endsWith('settings.json') || relPath.endsWith('settings.local.json')) {
116
+ const env = obj.env;
117
+ if (env && typeof env === 'object' && !Array.isArray(env)) {
118
+ envKeys += Object.keys(env).length;
119
+ }
120
+ }
121
+ const mcp = obj.mcpServers ?? obj.mcp_servers;
122
+ if (mcp && typeof mcp === 'object' && !Array.isArray(mcp)) {
123
+ mcpCount += Object.keys(mcp).length;
124
+ }
125
+ }
126
+ return { topLevelKeys, envKeys, mcpCount };
127
+ }
128
+ function newSnapshotId(now = new Date()) {
129
+ return now.toISOString().replace(/[:.]/g, '-');
130
+ }
131
+ async function readIndex(root) {
132
+ try {
133
+ const parsed = await (0, fs_1.readJsonFile)(indexPath(root));
134
+ if (Array.isArray(parsed)) {
135
+ return parsed;
136
+ }
137
+ }
138
+ catch {
139
+ // 索引缺失或损坏时按目录重建
140
+ }
141
+ return rebuildIndex(root);
142
+ }
143
+ async function rebuildIndex(root) {
144
+ const dir = snapshotsDir(root);
145
+ if (!(await (0, fs_1.pathExists)(dir))) {
146
+ return [];
147
+ }
148
+ const entries = [];
149
+ const names = await promises_1.default.readdir(dir);
150
+ for (const name of names) {
151
+ if (name === 'index.json') {
152
+ continue;
153
+ }
154
+ try {
155
+ const meta = await (0, fs_1.readJsonFile)(node_path_1.default.join(dir, name, 'snapshot.json'));
156
+ entries.push({
157
+ id: meta.id,
158
+ createdAt: meta.createdAt,
159
+ agent: meta.agent,
160
+ files: meta.files.length,
161
+ redacted: meta.redacted,
162
+ });
163
+ }
164
+ catch {
165
+ // 不是快照目录,跳过
166
+ }
167
+ }
168
+ return entries.sort((a, b) => b.id.localeCompare(a.id));
169
+ }
170
+ async function writeIndex(root, entries) {
171
+ // 快照 id 以 ISO 时间戳开头,按 id 倒序即时间倒序;同毫秒时 `-1` 后缀排在更前。
172
+ const sorted = [...entries].sort((a, b) => b.id.localeCompare(a.id));
173
+ await (0, fs_1.writeJsonFile)(indexPath(root), sorted.slice(0, MAX_INDEX_ENTRIES));
174
+ }
175
+ /** 采集当前配置并写入快照,返回快照元数据。 */
176
+ async function createSnapshot(options) {
177
+ const files = new Map();
178
+ for (const relPath of configFilesFor(options.agent)) {
179
+ const abs = (0, fs_1.safeResolveWithin)(options.root, relPath);
180
+ if (!(await (0, fs_1.pathExists)(abs))) {
181
+ continue;
182
+ }
183
+ const raw = await promises_1.default.readFile(abs);
184
+ const content = options.redact
185
+ ? Buffer.from(redactConfigText(relPath, raw.toString('utf8')), 'utf8')
186
+ : raw;
187
+ files.set(relPath, content);
188
+ }
189
+ if (files.size === 0) {
190
+ throw new Error(`SNAPSHOT_EMPTY: 在 ${options.root} 下未找到可快照的配置文件`);
191
+ }
192
+ const createdAt = new Date();
193
+ const baseId = newSnapshotId(createdAt);
194
+ let id = baseId;
195
+ let dir = node_path_1.default.join(snapshotsDir(options.root), id);
196
+ let suffix = 0;
197
+ while (await (0, fs_1.pathExists)(dir)) {
198
+ suffix += 1;
199
+ id = `${baseId}-${suffix}`;
200
+ dir = node_path_1.default.join(snapshotsDir(options.root), id);
201
+ }
202
+ await (0, fs_1.ensureDirectory)(node_path_1.default.join(dir, 'files'));
203
+ const entries = [];
204
+ for (const [relPath, content] of files) {
205
+ const target = (0, fs_1.safeResolveWithin)(node_path_1.default.join(dir, 'files'), relPath, 'snapshot file');
206
+ await (0, fs_1.ensureDirectory)(node_path_1.default.dirname(target));
207
+ await (0, fs_1.writeBinaryFile)(target, content, 0o600);
208
+ entries.push({
209
+ relPath,
210
+ sha256: hashBuffer(content),
211
+ size: content.length,
212
+ kind: fileKind(relPath),
213
+ });
214
+ }
215
+ const meta = {
216
+ id,
217
+ createdAt: createdAt.toISOString(),
218
+ agent: options.agent,
219
+ root: options.root,
220
+ toolVersion: package_json_1.default.version,
221
+ redacted: options.redact,
222
+ files: entries,
223
+ counts: computeCounts(files),
224
+ };
225
+ const metaPath = node_path_1.default.join(dir, 'snapshot.json');
226
+ await (0, fs_1.writeJsonFile)(metaPath, meta);
227
+ await chmodQuiet(metaPath, 0o600);
228
+ const index = await readIndex(options.root);
229
+ await writeIndex(options.root, [
230
+ { id: meta.id, createdAt: meta.createdAt, agent: meta.agent, files: meta.files.length, redacted: meta.redacted },
231
+ ...index.filter((item) => item.id !== meta.id),
232
+ ]);
233
+ return meta;
234
+ }
235
+ async function chmodQuiet(target, mode) {
236
+ try {
237
+ await promises_1.default.chmod(target, mode);
238
+ }
239
+ catch {
240
+ // Windows 上权限位语义有限,忽略
241
+ }
242
+ }
243
+ async function listSnapshots(root) {
244
+ return readIndex(root);
245
+ }
246
+ /** 最近一次快照;agent 指定时匹配该 agent 或 `all` 采集的快照。 */
247
+ async function latestSnapshot(root, agent) {
248
+ const index = await readIndex(root);
249
+ const matches = agent
250
+ ? index.filter((item) => item.agent === agent || item.agent === 'all')
251
+ : index;
252
+ if (matches.length === 0) {
253
+ return null;
254
+ }
255
+ const newest = [...matches].sort((a, b) => b.id.localeCompare(a.id))[0];
256
+ return loadSnapshot(root, newest.id);
257
+ }
258
+ /** 解析快照 id:支持完整 id、唯一前缀、快照目录路径与 `latest`。 */
259
+ async function loadSnapshot(root, idOrPath) {
260
+ const dir = await resolveSnapshotDir(root, idOrPath);
261
+ try {
262
+ const meta = await (0, fs_1.readJsonFile)(node_path_1.default.join(dir, 'snapshot.json'));
263
+ return { meta, dir };
264
+ }
265
+ catch {
266
+ throw new Error(`SNAPSHOT_NOT_FOUND: 无法读取快照 ${idOrPath}`);
267
+ }
268
+ }
269
+ async function resolveSnapshotDir(root, idOrPath) {
270
+ const looksLikePath = idOrPath.includes('/') || idOrPath.includes('\\') || node_path_1.default.isAbsolute(idOrPath);
271
+ if (looksLikePath) {
272
+ const resolved = node_path_1.default.resolve(idOrPath);
273
+ if (await (0, fs_1.pathExists)(resolved)) {
274
+ return resolved;
275
+ }
276
+ throw new Error(`SNAPSHOT_NOT_FOUND: ${idOrPath}`);
277
+ }
278
+ const base = snapshotsDir(root);
279
+ if (idOrPath === 'latest') {
280
+ const latest = await latestSnapshot(root);
281
+ if (!latest) {
282
+ throw new Error('SNAPSHOT_NOT_FOUND: 尚无任何快照');
283
+ }
284
+ return latest.dir;
285
+ }
286
+ const direct = node_path_1.default.join(base, idOrPath);
287
+ if (await (0, fs_1.pathExists)(node_path_1.default.join(direct, 'snapshot.json'))) {
288
+ return direct;
289
+ }
290
+ if (await (0, fs_1.pathExists)(base)) {
291
+ const names = (await promises_1.default.readdir(base)).filter((name) => name !== 'index.json' && name.startsWith(idOrPath));
292
+ if (names.length === 1) {
293
+ return node_path_1.default.join(base, names[0]);
294
+ }
295
+ if (names.length > 1) {
296
+ throw new Error(`SNAPSHOT_NOT_FOUND: 前缀 ${idOrPath} 匹配到多个快照,请提供完整 id`);
297
+ }
298
+ }
299
+ throw new Error(`SNAPSHOT_NOT_FOUND: ${idOrPath}`);
300
+ }
301
+ /** 读取快照中保存的配置内容(relPath → 原始字节)。 */
302
+ async function readSnapshotContents(snapshot) {
303
+ const contents = new Map();
304
+ for (const file of snapshot.meta.files) {
305
+ const source = (0, fs_1.safeResolveWithin)(node_path_1.default.join(snapshot.dir, 'files'), file.relPath, 'snapshot file');
306
+ try {
307
+ contents.set(file.relPath, await promises_1.default.readFile(source));
308
+ }
309
+ catch {
310
+ // 快照内容缺失时跳过,由调用方按"文件不存在"处理
311
+ }
312
+ }
313
+ return contents;
314
+ }
315
+ /** 读取本机当前的关键配置文件。 */
316
+ async function readLiveConfig(root, agent) {
317
+ const contents = new Map();
318
+ for (const relPath of configFilesFor(agent)) {
319
+ const abs = (0, fs_1.safeResolveWithin)(root, relPath);
320
+ try {
321
+ contents.set(relPath, await promises_1.default.readFile(abs));
322
+ }
323
+ catch {
324
+ // 文件不存在
325
+ }
326
+ }
327
+ return contents;
328
+ }
329
+ /**
330
+ * 当前配置与最近快照完全一致时返回该快照元数据,否则返回 null。
331
+ * 用于 `snapshot --if-changed`:定时任务里没变化就不重复落盘。
332
+ */
333
+ async function findUnchangedSnapshot(root, agent) {
334
+ const latest = await latestSnapshot(root, agent);
335
+ // agent 范围不同(如已有 all 快照、本次只采 claude)时视为有变化,避免漏采
336
+ if (!latest || latest.meta.agent !== agent) {
337
+ return null;
338
+ }
339
+ const stored = await readSnapshotContents(latest);
340
+ const live = await readLiveConfig(root, agent);
341
+ if (stored.size !== live.size) {
342
+ return null;
343
+ }
344
+ for (const [relPath, current] of live) {
345
+ const before = stored.get(relPath);
346
+ if (!before) {
347
+ return null;
348
+ }
349
+ // 快照若已脱敏,比对前同样对当前内容脱敏,避免每次都判定为变化
350
+ const comparable = latest.meta.redacted
351
+ ? Buffer.from(redactConfigText(relPath, current.toString('utf8')), 'utf8')
352
+ : current;
353
+ if (hashBuffer(before) !== hashBuffer(comparable)) {
354
+ return null;
355
+ }
356
+ }
357
+ return latest.meta;
358
+ }
359
+ // ===== 快照分享(push / pull) =====
360
+ /** 分享目录名:目标目录下按 `<target>/.agentdock-snapshots/<id>/` 存放快照。 */
361
+ exports.SNAPSHOT_BUNDLE_DIR = '.agentdock-snapshots';
362
+ /**
363
+ * 把一份快照复制到目标目录(如 Git 工作副本)。
364
+ * 明文快照含真实密钥,默认拒绝导出,必须先 `snapshot --redact` 或显式 `--force`。
365
+ */
366
+ async function exportSnapshot(root, targetDir, id, force) {
367
+ const list = await listSnapshots(root);
368
+ const chosenId = id ?? list[0]?.id;
369
+ if (!chosenId) {
370
+ throw new Error('SNAPSHOT_NOT_FOUND: 还没有可导出的快照');
371
+ }
372
+ const loaded = await loadSnapshot(root, chosenId);
373
+ if (!loaded.meta.redacted && !force) {
374
+ throw new Error('SNAPSHOT_NOT_REDACTED: 快照含明文敏感值,分享前请用 `agentdock snapshot --redact` 重新采集,或加 --force 强制导出');
375
+ }
376
+ const dest = node_path_1.default.join(targetDir, exports.SNAPSHOT_BUNDLE_DIR, loaded.meta.id);
377
+ if (await (0, fs_1.pathExists)(dest)) {
378
+ if (!force) {
379
+ throw new Error(`SNAPSHOT_EXISTS: 目标已存在:${dest}(加 --force 覆盖)`);
380
+ }
381
+ await promises_1.default.rm(dest, { recursive: true, force: true });
382
+ }
383
+ await (0, fs_1.copyDirectorySafe)(loaded.dir, dest);
384
+ return { id: loaded.meta.id, dest, redacted: loaded.meta.redacted };
385
+ }
386
+ async function findSnapshotDirs(base) {
387
+ if (await (0, fs_1.pathExists)(node_path_1.default.join(base, 'snapshot.json'))) {
388
+ return [base];
389
+ }
390
+ let names;
391
+ try {
392
+ names = await promises_1.default.readdir(base);
393
+ }
394
+ catch {
395
+ return [];
396
+ }
397
+ const dirs = [];
398
+ for (const name of names) {
399
+ const candidate = node_path_1.default.join(base, name);
400
+ if (await (0, fs_1.pathExists)(node_path_1.default.join(candidate, 'snapshot.json'))) {
401
+ dirs.push(candidate);
402
+ }
403
+ }
404
+ return dirs;
405
+ }
406
+ /**
407
+ * 从目标目录导入快照:支持直接指向某份快照目录,或指向包含
408
+ * `.agentdock-snapshots/<id>/` 的目录(如 Git 工作副本)。
409
+ */
410
+ async function importSnapshots(root, sourceDir, force) {
411
+ const dirs = new Set([
412
+ ...(await findSnapshotDirs(sourceDir)),
413
+ ...(await findSnapshotDirs(node_path_1.default.join(sourceDir, exports.SNAPSHOT_BUNDLE_DIR))),
414
+ ]);
415
+ if (dirs.size === 0) {
416
+ throw new Error(`SNAPSHOT_NOT_FOUND: 在 ${sourceDir} 下未找到快照`);
417
+ }
418
+ const imported = [];
419
+ const skipped = [];
420
+ await (0, fs_1.ensureDirectory)(snapshotsDir(root));
421
+ for (const dir of dirs) {
422
+ let meta;
423
+ try {
424
+ meta = await (0, fs_1.readJsonFile)(node_path_1.default.join(dir, 'snapshot.json'));
425
+ }
426
+ catch {
427
+ continue;
428
+ }
429
+ // id 会被拼进本地路径,只接受安全字符,避免路径穿越
430
+ if (!meta.id || !/^[0-9A-Za-z._-]+$/.test(meta.id)) {
431
+ continue;
432
+ }
433
+ const dest = node_path_1.default.join(snapshotsDir(root), meta.id);
434
+ if (await (0, fs_1.pathExists)(dest)) {
435
+ if (!force) {
436
+ skipped.push(meta.id);
437
+ continue;
438
+ }
439
+ await promises_1.default.rm(dest, { recursive: true, force: true });
440
+ }
441
+ await (0, fs_1.copyDirectorySafe)(dir, dest);
442
+ imported.push(meta.id);
443
+ }
444
+ await writeIndex(root, await rebuildIndex(root));
445
+ return { imported, skipped };
446
+ }
447
+ /** 生成恢复计划(不写盘)。 */
448
+ async function planRestore(root, snapshot) {
449
+ const contents = await readSnapshotContents(snapshot);
450
+ const entries = [];
451
+ for (const [relPath, content] of contents) {
452
+ const target = (0, fs_1.safeResolveWithin)(root, relPath);
453
+ let action = 'create';
454
+ if (await (0, fs_1.pathExists)(target)) {
455
+ try {
456
+ const current = await promises_1.default.readFile(target);
457
+ action = hashBuffer(current) === hashBuffer(content) ? 'skip' : 'overwrite';
458
+ }
459
+ catch {
460
+ action = 'overwrite';
461
+ }
462
+ }
463
+ entries.push({ relPath, target, action });
464
+ }
465
+ return entries;
466
+ }
467
+ /** 执行恢复;调用前必须已确认 apply。写前自动生成一份 before-restore 快照。 */
468
+ async function applyRestore(root, snapshot, entries) {
469
+ const actionable = entries.filter((entry) => entry.action !== 'skip');
470
+ if (actionable.length === 0) {
471
+ return {
472
+ snapshotId: snapshot.meta.id,
473
+ applied: true,
474
+ entries,
475
+ undo: false,
476
+ };
477
+ }
478
+ const backup = await createSnapshot({ root, agent: snapshot.meta.agent, redact: snapshot.meta.redacted });
479
+ const sourceRoot = node_path_1.default.join(snapshot.dir, 'files');
480
+ for (const entry of entries) {
481
+ if (entry.action === 'skip') {
482
+ continue;
483
+ }
484
+ const source = (0, fs_1.safeResolveWithin)(sourceRoot, entry.relPath, 'snapshot file');
485
+ await (0, fs_1.copyFileSafe)(source, entry.target);
486
+ await chmodQuiet(entry.target, 0o600);
487
+ }
488
+ const record = {
489
+ snapshotId: snapshot.meta.id,
490
+ backupSnapshotId: backup.id,
491
+ restoredAt: new Date().toISOString(),
492
+ };
493
+ await (0, fs_1.writeJsonFile)(restoreRecordPath(root), record);
494
+ return {
495
+ snapshotId: snapshot.meta.id,
496
+ applied: true,
497
+ entries,
498
+ backupSnapshotId: backup.id,
499
+ undo: false,
500
+ };
501
+ }
502
+ /** 恢复最近一次恢复前快照所需的上下文。 */
503
+ async function readRestoreRecord(root) {
504
+ try {
505
+ return await (0, fs_1.readJsonFile)(restoreRecordPath(root));
506
+ }
507
+ catch {
508
+ throw new Error('RESTORE_NO_UNDO: 没有可撤销的恢复记录(或已完成撤销)');
509
+ }
510
+ }
511
+ /** 撤销最近一次恢复:把写前快照重新写回。 */
512
+ async function prepareUndo(root) {
513
+ const record = await readRestoreRecord(root);
514
+ const snapshot = await loadSnapshot(root, record.backupSnapshotId);
515
+ const entries = await planRestore(root, snapshot);
516
+ return { snapshot, entries };
517
+ }
518
+ async function applyUndo(root, snapshot, entries) {
519
+ const sourceRoot = node_path_1.default.join(snapshot.dir, 'files');
520
+ for (const entry of entries) {
521
+ if (entry.action === 'skip') {
522
+ continue;
523
+ }
524
+ const source = (0, fs_1.safeResolveWithin)(sourceRoot, entry.relPath, 'snapshot file');
525
+ await (0, fs_1.copyFileSafe)(source, entry.target);
526
+ await chmodQuiet(entry.target, 0o600);
527
+ }
528
+ await promises_1.default.rm(restoreRecordPath(root), { force: true });
529
+ return {
530
+ snapshotId: snapshot.meta.id,
531
+ applied: true,
532
+ entries,
533
+ undo: true,
534
+ };
535
+ }
@@ -10,8 +10,8 @@ const FALLBACK = 'en';
10
10
  /** User-facing strings. Machines read `--json` output, which is never localized. */
11
11
  const DICTIONARIES = {
12
12
  en: {
13
- 'cli.usage': 'Usage: agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync> [path]',
14
- 'cli.help.commands': 'Commands: scan, export, pack, install, verify, attest, keygen, sign, validate, doctor, report, list, diff, config, uninstall, sync',
13
+ 'cli.usage': 'Usage: agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync|snapshot|history|recover|restore> [path]',
14
+ 'cli.help.commands': 'Commands: scan, export, pack, install, verify, attest, keygen, sign, validate, doctor, report, list, diff, config, uninstall, sync, snapshot, history, recover, restore',
15
15
  'cli.help.docs': 'Docs: https://github.com/spsz831/AgentDock#readme',
16
16
  'cli.version': 'agentdock {version}',
17
17
  'pack.usage': 'Usage: agentdock pack --from-scan <scan.yml> --out <dir> [--zip] [--env <file>] [--overwrite]',
@@ -47,6 +47,52 @@ const DICTIONARIES = {
47
47
  'sync.statusLocalOnly': 'local only ({count}):',
48
48
  'sync.statusRemoteOnly': 'bundle only ({count}):',
49
49
  'sync.undoSkipped': 'modified since sync — left untouched',
50
+ 'snapshot.usage': 'Usage: agentdock snapshot [create|list] [--agent claude|codex|all] [--root <dir>] [--redact] [--if-changed]\n agentdock snapshot push <target-dir> [--snapshot <id>] [--force]\n agentdock snapshot pull <source-dir> [--force]',
51
+ 'snapshot.pushUsage': 'Usage: agentdock snapshot push <target-dir> [--snapshot <id>] [--force]',
52
+ 'snapshot.pullUsage': 'Usage: agentdock snapshot pull <source-dir> [--force]',
53
+ 'snapshot.pushed': 'Snapshot {id} exported to {dest}',
54
+ 'snapshot.pulled': 'Imported {count} snapshot(s): {ids}',
55
+ 'snapshot.pullSkipped': ' skipped (already exists, use --force to overwrite): {ids}',
56
+ 'snapshot.pullNone': 'No snapshots imported',
57
+ 'snapshot.created': 'Snapshot created: {id}',
58
+ 'snapshot.location': ' location: {path}',
59
+ 'snapshot.files': ' files ({count}): {files}',
60
+ 'snapshot.counts': ' top-level keys: {top} / env keys: {env} / MCP: {mcp}',
61
+ 'snapshot.redacted': ' secrets: redacted',
62
+ 'snapshot.plaintext': ' secrets: stored in plaintext (local only — do not commit)',
63
+ 'snapshot.empty': 'No snapshots yet — run `agentdock snapshot` to create a baseline',
64
+ 'snapshot.unchanged': 'Configuration unchanged since snapshot {id} — skipped',
65
+ 'snapshot.listHeader': 'Snapshots ({count}) in {dir}:',
66
+ 'snapshot.listItem': ' {id} {agent} {files} file(s){redacted}',
67
+ 'history.usage': 'Usage: agentdock history [--agent claude|codex|all] [--root <dir>]',
68
+ 'history.header': 'Snapshot history ({count}) in {dir}:',
69
+ 'history.entry': ' {id} {agent} {files} file(s) {summary}',
70
+ 'history.baseline': 'baseline',
71
+ 'history.changes': '{added} added / {removed} removed / {modified} modified',
72
+ 'history.highlight': ' {path}',
73
+ 'history.empty': 'No snapshots yet — run `agentdock snapshot` to create a baseline',
74
+ 'recover.usage': 'Usage: agentdock recover [--snapshot <id>] [--apply] [--undo] [--root <dir>]',
75
+ 'recover.header': 'Recovery candidates ({count}) in {dir} (highest score first):',
76
+ 'recover.candidate': ' {score}/100 {id} {agent} {files} file(s){redacted}',
77
+ 'recover.missing': ' missing: {files}',
78
+ 'recover.recommended': ' recommended: {id}',
79
+ 'recover.hint': 'Run `agentdock recover --apply` to restore the recommended snapshot, or `agentdock recover --snapshot <id> --apply` to choose another.',
80
+ 'recover.empty': 'No snapshots to recover from — run `agentdock snapshot` first',
81
+ 'recover.planLine': 'Recovery plan from snapshot {id} ({score}/100, {mode}):',
82
+ 'recover.applied': 'Recovered {count} file(s) from snapshot {id}',
83
+ 'recover.backup': ' pre-recovery snapshot: {id} (rollback: agentdock recover --undo --apply)',
84
+ 'recover.undone': 'Undo complete: restored {count} file(s) from snapshot {id}',
85
+ 'diff.snapshotHeader': 'Config diff: snapshot {from} → {to}',
86
+ 'diff.noSnapshot': 'No snapshot found — run `agentdock snapshot` first',
87
+ 'diff.noChanges': 'No configuration changes',
88
+ 'restore.usage': 'Usage: agentdock restore --snapshot <id> [--apply]; rollback: agentdock restore --undo [--apply]',
89
+ 'restore.planHeader': 'Restore plan from snapshot {id} ({mode}):',
90
+ 'restore.undoPlanHeader': 'Undo plan — restore pre-restore snapshot {id} ({mode}):',
91
+ 'restore.modeDryRun': 'dry-run — no changes written, use --apply to execute',
92
+ 'restore.modeApply': 'applied',
93
+ 'restore.applied': 'Restored {count} file(s) from snapshot {id}',
94
+ 'restore.backup': ' pre-restore snapshot: {id} (rollback: agentdock restore --undo --apply)',
95
+ 'restore.undone': 'Undo complete: restored {count} file(s) from snapshot {id}',
50
96
  'install.complete': 'Install completed: {path}',
51
97
  'uninstall.complete': 'Uninstall complete: {path}',
52
98
  'uninstall.dryRunHeader': 'Uninstall plan (dry-run — no changes made): {path}',
@@ -67,8 +113,8 @@ const DICTIONARIES = {
67
113
  'config.unsetValue': '(unset)',
68
114
  },
69
115
  'zh-CN': {
70
- 'cli.usage': '用法:agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync> [path]',
71
- 'cli.help.commands': '命令:scan、export、pack、install、verify、attest、keygen、sign、validate、doctor、report、list、diff、config、uninstall、sync',
116
+ 'cli.usage': '用法:agentdock <scan|export|pack|install|verify|attest|keygen|sign|validate|doctor|report|list|diff|config|uninstall|sync|snapshot|history|recover|restore> [path]',
117
+ 'cli.help.commands': '命令:scan、export、pack、install、verify、attest、keygen、sign、validate、doctor、report、list、diff、config、uninstall、sync、snapshot、history、recover、restore',
72
118
  'cli.help.docs': '文档:https://github.com/spsz831/AgentDock#readme',
73
119
  'cli.version': 'agentdock {version}',
74
120
  'pack.usage': '用法:agentdock pack --from-scan <scan.yml> --out <目录> [--zip] [--env <文件>] [--overwrite]',
@@ -104,6 +150,52 @@ const DICTIONARIES = {
104
150
  'sync.statusLocalOnly': '仅本机有({count}):',
105
151
  'sync.statusRemoteOnly': '仅 bundle 有({count}):',
106
152
  'sync.undoSkipped': '同步后被修改过,保持不动',
153
+ 'snapshot.usage': '用法:agentdock snapshot [create|list] [--agent claude|codex|all] [--root <目录>] [--redact] [--if-changed]\n agentdock snapshot push <目标目录> [--snapshot <id>] [--force]\n agentdock snapshot pull <来源目录> [--force]',
154
+ 'snapshot.pushUsage': '用法:agentdock snapshot push <目标目录> [--snapshot <id>] [--force]',
155
+ 'snapshot.pullUsage': '用法:agentdock snapshot pull <来源目录> [--force]',
156
+ 'snapshot.pushed': '快照 {id} 已导出到 {dest}',
157
+ 'snapshot.pulled': '已导入 {count} 份快照:{ids}',
158
+ 'snapshot.pullSkipped': ' 已跳过(本地已存在,--force 可覆盖):{ids}',
159
+ 'snapshot.pullNone': '没有导入任何快照',
160
+ 'snapshot.created': '快照已创建:{id}',
161
+ 'snapshot.location': ' 位置:{path}',
162
+ 'snapshot.files': ' 文件({count}):{files}',
163
+ 'snapshot.counts': ' 顶层键:{top} / env 键:{env} / MCP:{mcp}',
164
+ 'snapshot.redacted': ' 敏感值:已打码',
165
+ 'snapshot.plaintext': ' 敏感值:明文保存(仅本机,请勿提交)',
166
+ 'snapshot.empty': '尚无快照 —— 先运行 `agentdock snapshot` 建立基线',
167
+ 'snapshot.unchanged': '配置自快照 {id} 以来没有变化 —— 已跳过',
168
+ 'snapshot.listHeader': '快照({count})位于 {dir}:',
169
+ 'snapshot.listItem': ' {id} {agent} {files} 个文件{redacted}',
170
+ 'history.usage': '用法:agentdock history [--agent claude|codex|all] [--root <目录>]',
171
+ 'history.header': '快照时间线({count})位于 {dir}:',
172
+ 'history.entry': ' {id} {agent} {files} 个文件 {summary}',
173
+ 'history.baseline': '基线',
174
+ 'history.changes': '{added} 新增 / {removed} 删除 / {modified} 修改',
175
+ 'history.highlight': ' {path}',
176
+ 'history.empty': '尚无快照 —— 先运行 `agentdock snapshot` 建立基线',
177
+ 'recover.usage': '用法:agentdock recover [--snapshot <id>] [--apply] [--undo] [--root <目录>]',
178
+ 'recover.header': '恢复候选({count})位于 {dir}(按完整度评分排序):',
179
+ 'recover.candidate': ' {score}/100 {id} {agent} {files} 个文件{redacted}',
180
+ 'recover.missing': ' 缺失:{files}',
181
+ 'recover.recommended': ' 推荐:{id}',
182
+ 'recover.hint': '运行 `agentdock recover --apply` 恢复推荐快照,或 `agentdock recover --snapshot <id> --apply` 选择其他快照。',
183
+ 'recover.empty': '没有可恢复的快照 —— 先运行 `agentdock snapshot` 建立基线',
184
+ 'recover.planLine': '恢复计划(快照 {id},评分 {score}/100,{mode}):',
185
+ 'recover.applied': '已从快照 {id} 恢复 {count} 个文件',
186
+ 'recover.backup': ' 写前快照:{id}(回滚:agentdock recover --undo --apply)',
187
+ 'recover.undone': '撤销完成:已从快照 {id} 恢复 {count} 个文件',
188
+ 'diff.snapshotHeader': '配置差异:快照 {from} → {to}',
189
+ 'diff.noSnapshot': '尚未找到快照 —— 先运行 `agentdock snapshot`',
190
+ 'diff.noChanges': '配置没有变化',
191
+ 'restore.usage': '用法:agentdock restore --snapshot <id> [--apply];回滚:agentdock restore --undo [--apply]',
192
+ 'restore.planHeader': '恢复计划(快照 {id},{mode}):',
193
+ 'restore.undoPlanHeader': '撤销计划 —— 还原写前快照 {id}({mode}):',
194
+ 'restore.modeDryRun': 'dry-run — 未写入任何改动,--apply 才会执行',
195
+ 'restore.modeApply': '已执行',
196
+ 'restore.applied': '已从快照 {id} 恢复 {count} 个文件',
197
+ 'restore.backup': ' 写前快照:{id}(回滚:agentdock restore --undo --apply)',
198
+ 'restore.undone': '撤销完成:已从快照 {id} 恢复 {count} 个文件',
107
199
  'install.complete': '安装完成:{path}',
108
200
  'uninstall.complete': '卸载完成:{path}',
109
201
  'uninstall.dryRunHeader': '卸载计划(dry-run — 未做任何改动):{path}',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentdock-cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Diagnose, migrate, and back up your AI coding assistant environment (Claude Code / Codex) — Chinese health reports, MCP servers, Skills, Agents, Plugins, Hooks, and memory, with secret isolation.",
5
5
  "keywords": [
6
6
  "claude-code",