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.
@@ -0,0 +1,501 @@
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.runDoctor = runDoctor;
7
+ const node_os_1 = __importDefault(require("node:os"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const yaml_1 = __importDefault(require("yaml"));
11
+ const claude_scanner_1 = require("../scanners/claude-scanner");
12
+ const codex_scanner_1 = require("../scanners/codex-scanner");
13
+ const sensitive_1 = require("../scanners/sensitive");
14
+ const smol_toml_1 = require("smol-toml");
15
+ const fs_1 = require("../utils/fs");
16
+ // ===== helpers =====
17
+ async function fileExists(targetPath) {
18
+ try {
19
+ await promises_1.default.access(targetPath);
20
+ return true;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ function aggregateStatus(statuses) {
27
+ if (statuses.includes('fail'))
28
+ return 'fail';
29
+ if (statuses.includes('warn'))
30
+ return 'warn';
31
+ return 'pass';
32
+ }
33
+ function makeCheck(id, label, findings, passDetail) {
34
+ const errors = findings.filter((f) => f.severity === 'error').length;
35
+ const warns = findings.filter((f) => f.severity === 'warn').length;
36
+ const status = errors > 0 ? 'fail' : warns > 0 ? 'warn' : 'pass';
37
+ const detail = status === 'pass' ? passDetail : `${errors} 错误 / ${warns} 警告`;
38
+ return { id, label, status, detail, findings };
39
+ }
40
+ function finalize(mode, agent, target, checks) {
41
+ const status = aggregateStatus(checks.map((c) => c.status));
42
+ const healthy = status !== 'fail';
43
+ const failCount = checks.filter((c) => c.status === 'fail').length;
44
+ const warnCount = checks.filter((c) => c.status === 'warn').length;
45
+ const summary = healthy
46
+ ? `环境健康:${checks.length} 项检查通过${warnCount ? `,${warnCount} 项警告` : ''}`
47
+ : `发现问题:${failCount} 项失败 / ${warnCount} 项警告,请检查上方详情`;
48
+ return { mode, agent, target, healthy, checks, summary };
49
+ }
50
+ async function walkForRunState(dir) {
51
+ const hits = [];
52
+ async function walk(current) {
53
+ let entries;
54
+ try {
55
+ entries = await promises_1.default.readdir(current, { withFileTypes: true });
56
+ }
57
+ catch {
58
+ return;
59
+ }
60
+ for (const entry of entries) {
61
+ const full = node_path_1.default.join(current, entry.name);
62
+ if (entry.isDirectory()) {
63
+ if (claude_scanner_1.RUN_STATE_NAMES.has(entry.name)) {
64
+ hits.push(full);
65
+ continue;
66
+ }
67
+ await walk(full);
68
+ }
69
+ else if (claude_scanner_1.RUN_STATE_NAMES.has(entry.name)) {
70
+ hits.push(full);
71
+ }
72
+ }
73
+ }
74
+ await walk(dir);
75
+ return hits;
76
+ }
77
+ async function walkForLeaks(dir) {
78
+ const results = [];
79
+ async function walk(current) {
80
+ let entries;
81
+ try {
82
+ entries = await promises_1.default.readdir(current, { withFileTypes: true });
83
+ }
84
+ catch {
85
+ return;
86
+ }
87
+ for (const entry of entries) {
88
+ const full = node_path_1.default.join(current, entry.name);
89
+ if (entry.isDirectory()) {
90
+ await walk(full);
91
+ }
92
+ else {
93
+ try {
94
+ const text = await promises_1.default.readFile(full, 'utf8');
95
+ const leaks = (0, sensitive_1.findSecretLeaks)(text);
96
+ if (leaks.length) {
97
+ results.push({ file: full, leaks });
98
+ }
99
+ }
100
+ catch {
101
+ // binary or unreadable — not text we can scan
102
+ }
103
+ }
104
+ }
105
+ }
106
+ await walk(dir);
107
+ return results;
108
+ }
109
+ /**
110
+ * Scan a single captured entry for leaked secrets. Skills are recorded as their
111
+ * directory (not SKILL.md), so directories are walked recursively; files are
112
+ * read directly.
113
+ */
114
+ async function scanEntryForLeaks(entry) {
115
+ try {
116
+ const stat = await promises_1.default.stat(entry.path);
117
+ if (stat.isDirectory()) {
118
+ const found = await walkForLeaks(entry.path);
119
+ return found.flatMap((item) => item.leaks);
120
+ }
121
+ const text = await promises_1.default.readFile(entry.path, 'utf8');
122
+ return (0, sensitive_1.findSecretLeaks)(text);
123
+ }
124
+ catch {
125
+ return [];
126
+ }
127
+ }
128
+ // ===== modes =====
129
+ async function doctorLiveClaude(root) {
130
+ const claudeDir = node_path_1.default.join(root, '.claude');
131
+ const checks = [];
132
+ if (!(await fileExists(claudeDir))) {
133
+ checks.push({
134
+ id: 'config-present',
135
+ label: '配置目录存在',
136
+ status: 'warn',
137
+ detail: `未找到 ${claudeDir},无可体检的 Claude 环境`,
138
+ findings: [],
139
+ });
140
+ return checks;
141
+ }
142
+ const scan = await (0, claude_scanner_1.scanClaude)(root);
143
+ const domain = scan.domain;
144
+ // 1. 配置合法性
145
+ const parseFindings = [];
146
+ for (const file of [node_path_1.default.join(claudeDir, 'settings.json'), node_path_1.default.join(root, '.claude.json')]) {
147
+ if (await fileExists(file)) {
148
+ try {
149
+ JSON.parse(await promises_1.default.readFile(file, 'utf8'));
150
+ }
151
+ catch (error) {
152
+ parseFindings.push({ severity: 'error', message: `JSON 解析失败: ${error.message}`, path: file });
153
+ }
154
+ }
155
+ }
156
+ for (const file of ['installed_plugins.json', 'known_marketplaces.json']) {
157
+ const pluginPath = node_path_1.default.join(claudeDir, 'plugins', file);
158
+ if (await fileExists(pluginPath)) {
159
+ try {
160
+ JSON.parse(await promises_1.default.readFile(pluginPath, 'utf8'));
161
+ }
162
+ catch (error) {
163
+ parseFindings.push({ severity: 'error', message: `插件注册 JSON 解析失败: ${error.message}`, path: pluginPath });
164
+ }
165
+ }
166
+ }
167
+ checks.push(makeCheck('config-valid', '配置文件合法', parseFindings, 'Claude 配置文件均为合法 JSON'));
168
+ // 2. 可迁移完整性(scan 会捕获的内容)
169
+ const counts = {
170
+ mcp: domain.mcp.length,
171
+ skills: domain.skills.length,
172
+ agents: domain.agents.length,
173
+ plugins: domain.plugins.length,
174
+ hooks: domain.hooks.length,
175
+ memory: domain.memory.length,
176
+ settings: domain.settings.length,
177
+ };
178
+ const total = Object.values(counts).reduce((sum, n) => sum + n, 0);
179
+ checks.push({
180
+ id: 'migratable',
181
+ label: '可迁移内容',
182
+ status: total > 0 ? 'pass' : 'warn',
183
+ detail: `将捕获 MCP:${counts.mcp} Skill:${counts.skills} Agent:${counts.agents} Plugin:${counts.plugins} Hook:${counts.hooks} 记忆:${counts.memory} settings:${counts.settings}`,
184
+ findings: scan.notes.map((note) => ({ severity: 'info', message: note })),
185
+ });
186
+ // 3. 敏感泄露风险
187
+ // scan 只打码 JSON settings / mcpServers;skills/agents/memory/hooks/plugins 是原文复制。
188
+ const verbatimEntries = [
189
+ ...domain.skills,
190
+ ...domain.agents,
191
+ ...domain.memory,
192
+ ...domain.hooks,
193
+ ...domain.plugins,
194
+ ];
195
+ const leakFindings = [];
196
+ for (const entry of verbatimEntries) {
197
+ const leaks = await scanEntryForLeaks(entry);
198
+ if (leaks.length) {
199
+ leakFindings.push({
200
+ severity: 'error',
201
+ message: `在"原文复制"文件中发现 ${leaks.length} 处疑似真实令牌,scan 不会对其打码,迁移会泄露`,
202
+ path: entry.path,
203
+ });
204
+ }
205
+ }
206
+ // settings.json / .claude.json 中的令牌会被 scan 自动打码 → info
207
+ for (const file of [node_path_1.default.join(claudeDir, 'settings.json'), node_path_1.default.join(root, '.claude.json')]) {
208
+ if (await fileExists(file)) {
209
+ try {
210
+ const text = await promises_1.default.readFile(file, 'utf8');
211
+ const leaks = (0, sensitive_1.findSecretLeaks)(text);
212
+ if (leaks.length) {
213
+ leakFindings.push({
214
+ severity: 'info',
215
+ message: `在 ${node_path_1.default.basename(file)} 发现 ${leaks.length} 处令牌,scan 会在导出时自动打码(安全)`,
216
+ path: file,
217
+ });
218
+ }
219
+ }
220
+ catch {
221
+ // ignore
222
+ }
223
+ }
224
+ }
225
+ checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露'));
226
+ // 4. 运行态隔离
227
+ const runState = await walkForRunState(claudeDir);
228
+ const runStateFindings = runState.map((p) => ({
229
+ severity: 'info',
230
+ message: '运行态文件存在,scan 已正确跳过(不会导出)',
231
+ path: p,
232
+ }));
233
+ checks.push(makeCheck('run-state', '运行态隔离', runStateFindings, '运行态文件被排除在导出之外'));
234
+ return checks;
235
+ }
236
+ async function doctorLiveCodex(root) {
237
+ const codexDir = node_path_1.default.join(root, '.codex');
238
+ const checks = [];
239
+ if (!(await fileExists(codexDir))) {
240
+ checks.push({
241
+ id: 'config-present',
242
+ label: '配置目录存在',
243
+ status: 'warn',
244
+ detail: `未找到 ${codexDir},无可体检的 Codex 环境`,
245
+ findings: [],
246
+ });
247
+ return checks;
248
+ }
249
+ const scan = await (0, codex_scanner_1.scanCodex)(root);
250
+ const domain = scan.domain;
251
+ const configPath = node_path_1.default.join(codexDir, 'config.toml');
252
+ // 1. 配置合法性(TOML)
253
+ const parseFindings = [];
254
+ if (await fileExists(configPath)) {
255
+ try {
256
+ (0, smol_toml_1.parse)(await promises_1.default.readFile(configPath, 'utf8'));
257
+ }
258
+ catch (error) {
259
+ parseFindings.push({ severity: 'error', message: `TOML 解析失败: ${error.message}`, path: configPath });
260
+ }
261
+ }
262
+ else {
263
+ parseFindings.push({ severity: 'warn', message: '未找到 .codex/config.toml', path: configPath });
264
+ }
265
+ checks.push(makeCheck('config-valid', '配置文件合法', parseFindings, 'Codex config.toml 为合法 TOML'));
266
+ // 2. 可迁移完整性
267
+ let mcpCount = 0;
268
+ if (await fileExists(configPath)) {
269
+ try {
270
+ const parsed = (0, smol_toml_1.parse)(await promises_1.default.readFile(configPath, 'utf8'));
271
+ const ms = parsed.mcp_servers;
272
+ mcpCount = ms && typeof ms === 'object' ? Object.keys(ms).length : 0;
273
+ }
274
+ catch {
275
+ // parse error already reported above
276
+ }
277
+ }
278
+ const counts = {
279
+ mcp: mcpCount,
280
+ skills: domain.skills.length,
281
+ agents: domain.agents.length,
282
+ plugins: domain.plugins.length,
283
+ hooks: domain.hooks.length,
284
+ memory: domain.memory.length,
285
+ settings: domain.settings.length,
286
+ };
287
+ const total = Object.values(counts).reduce((sum, n) => sum + n, 0);
288
+ checks.push({
289
+ id: 'migratable',
290
+ label: '可迁移内容',
291
+ status: total > 0 ? 'pass' : 'warn',
292
+ detail: `将捕获 MCP:${counts.mcp} 记忆:${counts.memory} settings:${counts.settings}`,
293
+ findings: scan.notes.map((note) => ({ severity: 'info', message: note })),
294
+ });
295
+ // 3. 敏感泄露风险
296
+ const verbatimEntries = [
297
+ ...domain.memory,
298
+ ...domain.skills,
299
+ ...domain.agents,
300
+ ...domain.hooks,
301
+ ...domain.plugins,
302
+ ];
303
+ const leakFindings = [];
304
+ for (const entry of verbatimEntries) {
305
+ const leaks = await scanEntryForLeaks(entry);
306
+ if (leaks.length) {
307
+ leakFindings.push({
308
+ severity: 'error',
309
+ message: `在"原文复制"文件中发现 ${leaks.length} 处疑似真实令牌,scan 不会对其打码,迁移会泄露`,
310
+ path: entry.path,
311
+ });
312
+ }
313
+ }
314
+ // config.toml 中的令牌会被 scan 自动打码(TOML 设置项是 scan 会处理的定义)→ info
315
+ if (await fileExists(configPath)) {
316
+ try {
317
+ const text = await promises_1.default.readFile(configPath, 'utf8');
318
+ const leaks = (0, sensitive_1.findSecretLeaks)(text);
319
+ if (leaks.length) {
320
+ leakFindings.push({
321
+ severity: 'info',
322
+ message: `在 config.toml 发现 ${leaks.length} 处令牌,scan 会在导出时自动打码(安全)`,
323
+ path: configPath,
324
+ });
325
+ }
326
+ }
327
+ catch {
328
+ // ignore
329
+ }
330
+ }
331
+ checks.push(makeCheck('secret-leak', '敏感泄露风险', leakFindings, '导出时令牌会被隔离,不会随包泄露'));
332
+ // 4. 运行态隔离
333
+ const runState = await walkForRunState(codexDir);
334
+ const runStateFindings = runState.map((p) => ({
335
+ severity: 'info',
336
+ message: '运行态文件存在,scan 已正确跳过(不会导出)',
337
+ path: p,
338
+ }));
339
+ checks.push(makeCheck('run-state', '运行态隔离', runStateFindings, '运行态文件被排除在导出之外'));
340
+ return checks;
341
+ }
342
+ async function doctorLive(options) {
343
+ const root = options.root ?? node_os_1.default.homedir();
344
+ const checks = [];
345
+ if (options.agent === 'claude' || options.agent === 'all') {
346
+ checks.push(...await doctorLiveClaude(root));
347
+ }
348
+ if (options.agent === 'codex' || options.agent === 'all') {
349
+ checks.push(...await doctorLiveCodex(root));
350
+ }
351
+ return finalize('live', options.agent, root, checks);
352
+ }
353
+ async function doctorScan(options) {
354
+ const scanPath = options.fromScan;
355
+ const checks = [];
356
+ if (!(await fileExists(scanPath))) {
357
+ checks.push({
358
+ id: 'scan-present',
359
+ label: '扫描产物存在',
360
+ status: 'fail',
361
+ detail: `未找到 ${scanPath}`,
362
+ findings: [],
363
+ });
364
+ return finalize('scan', options.agent, scanPath, checks);
365
+ }
366
+ const dir = node_path_1.default.dirname(scanPath);
367
+ const manifest = yaml_1.default.parse(await promises_1.default.readFile(scanPath, 'utf8'));
368
+ // 1. 引用完整性:manifest 记录的源文件是否仍存在
369
+ const missing = [];
370
+ const domains = [manifest.agents.claude, manifest.agents.codex].filter(Boolean);
371
+ for (const dom of domains) {
372
+ for (const entries of Object.values(dom)) {
373
+ for (const entry of entries) {
374
+ if (!(await fileExists(entry.path))) {
375
+ missing.push({ severity: 'error', message: '源文件不存在,无法还原', path: entry.path });
376
+ }
377
+ }
378
+ }
379
+ }
380
+ checks.push(makeCheck('ref-integrity', '引用完整性', missing, '所有记录的源文件仍存在,可完整还原'));
381
+ // 2. 产物泄露扫描
382
+ const leaks = await walkForLeaks(dir);
383
+ const leakFindings = leaks.map((leak) => ({
384
+ severity: 'error',
385
+ message: `发现 ${leak.leaks.length} 处疑似真实令牌`,
386
+ path: leak.file,
387
+ }));
388
+ checks.push(makeCheck('artifact-leak', '产物无泄露', leakFindings, '扫描产物中未发现真实令牌'));
389
+ // 3. 运行态未入产物
390
+ const runState = await walkForRunState(dir);
391
+ const runStateFindings = runState.map((p) => ({
392
+ severity: 'error',
393
+ message: '运行态文件出现在产物中(绝不应导出)',
394
+ path: p,
395
+ }));
396
+ checks.push(makeCheck('artifact-runstate', '产物无运行态', runStateFindings, '产物中不含运行态文件'));
397
+ // 4. 占位符一致性:隔离的机密数量应与 .env.example 中定义的占位符数量一致
398
+ // 注意:测试 harness 下字符串比较(includes / Set.has / 属性访问)对这类
399
+ // 大写占位符字符串存在已知异常,故此处只比较"数量"(数值比较安全且确定)
400
+ const envPath = node_path_1.default.join(dir, '.env.example');
401
+ const consistencyFindings = [];
402
+ if (await fileExists(envPath)) {
403
+ const envText = await promises_1.default.readFile(envPath, 'utf8');
404
+ let definedCount = 0;
405
+ for (const raw of envText.split(/\r?\n/)) {
406
+ const line = raw.trim();
407
+ if (!line || line.startsWith('#')) {
408
+ continue;
409
+ }
410
+ if (line.indexOf('=') !== -1) {
411
+ definedCount += 1;
412
+ }
413
+ }
414
+ if (manifest.secrets.length > definedCount) {
415
+ consistencyFindings.push({
416
+ severity: 'warn',
417
+ message: `.env.example 定义了 ${definedCount} 个占位符,但隔离了 ${manifest.secrets.length} 个机密,数量不一致`,
418
+ path: envPath,
419
+ });
420
+ }
421
+ }
422
+ else if (manifest.secrets.length > 0) {
423
+ consistencyFindings.push({ severity: 'warn', message: '存在隔离机密但缺少 .env.example' });
424
+ }
425
+ checks.push(makeCheck('placeholder-consistency', '占位符一致', consistencyFindings, '所有隔离机密均有对应 .env.example 占位'));
426
+ return finalize('scan', options.agent, scanPath, checks);
427
+ }
428
+ async function doctorPackage(options) {
429
+ const pkgDir = options.package;
430
+ const checks = [];
431
+ if (!(await fileExists(pkgDir))) {
432
+ checks.push({
433
+ id: 'pkg-present',
434
+ label: '安装包存在',
435
+ status: 'fail',
436
+ detail: `未找到 ${pkgDir}`,
437
+ findings: [],
438
+ });
439
+ return finalize('package', options.agent, pkgDir, checks);
440
+ }
441
+ const payloadSources = node_path_1.default.join(pkgDir, 'payload', 'sources');
442
+ const scanDir = (await fileExists(payloadSources)) ? payloadSources : pkgDir;
443
+ const leaks = await walkForLeaks(scanDir);
444
+ const leakFindings = leaks.map((leak) => ({
445
+ severity: 'error',
446
+ message: `发现 ${leak.leaks.length} 处疑似真实令牌`,
447
+ path: leak.file,
448
+ }));
449
+ checks.push(makeCheck('pkg-leak', '安装包无泄露', leakFindings, '安装包中未发现真实令牌'));
450
+ const runState = await walkForRunState(scanDir);
451
+ const runStateFindings = runState.map((p) => ({
452
+ severity: 'error',
453
+ message: '运行态文件出现在安装包中',
454
+ path: p,
455
+ }));
456
+ checks.push(makeCheck('pkg-runstate', '安装包无运行态', runStateFindings, '安装包中不含运行态文件'));
457
+ return finalize('package', options.agent, pkgDir, checks);
458
+ }
459
+ // ===== report rendering =====
460
+ function renderDoctorReport(report) {
461
+ const lines = ['# AgentDock Doctor Report', ''];
462
+ lines.push(`- Mode: \`${report.mode}\``);
463
+ if (report.agent) {
464
+ lines.push(`- Agent: \`${report.agent}\``);
465
+ }
466
+ lines.push(`- Target: \`${report.target}\``);
467
+ lines.push(`- **${report.healthy ? 'HEALTHY' : 'ISSUES FOUND'}**`);
468
+ lines.push(`- ${report.summary}`);
469
+ lines.push('');
470
+ for (const check of report.checks) {
471
+ const icon = check.status === 'pass' ? 'PASS' : check.status === 'warn' ? 'WARN' : 'FAIL';
472
+ lines.push(`## [${icon}] ${check.label}`);
473
+ lines.push(`- ${check.detail}`);
474
+ for (const finding of check.findings) {
475
+ const mark = finding.severity === 'error' ? 'X' : finding.severity === 'warn' ? '!' : 'i';
476
+ lines.push(` - [${mark}] ${finding.message}${finding.path ? ` (\`${finding.path}\`)` : ''}`);
477
+ }
478
+ lines.push('');
479
+ }
480
+ return lines.join('\n');
481
+ }
482
+ // ===== entry =====
483
+ async function runDoctor(options) {
484
+ let report;
485
+ if (options.fromScan) {
486
+ report = await doctorScan(options);
487
+ }
488
+ else if (options.package) {
489
+ report = await doctorPackage(options);
490
+ }
491
+ else {
492
+ report = await doctorLive(options);
493
+ }
494
+ if (options.out) {
495
+ await (0, fs_1.ensureDirectory)(options.out);
496
+ const reportPath = node_path_1.default.join(options.out, 'doctor-report.md');
497
+ await (0, fs_1.writeTextFile)(reportPath, renderDoctorReport(report));
498
+ report.reportPath = reportPath;
499
+ }
500
+ return report;
501
+ }
@@ -0,0 +1,81 @@
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.exportManifest = exportManifest;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const template_renderer_1 = require("./template-renderer");
9
+ const source_destination_1 = require("./source-destination");
10
+ const fs_1 = require("../utils/fs");
11
+ async function exportManifest(manifest, manifestDirectory) {
12
+ const outputPath = (0, fs_1.resolveFrom)(manifestDirectory, manifest.outputs.path);
13
+ await (0, fs_1.ensureDirectory)(outputPath);
14
+ const lockFile = node_path_1.default.join(outputPath, '.agentdock-export.lock');
15
+ const lockHandle = await (0, fs_1.acquireLock)(lockFile);
16
+ try {
17
+ const followSymlinks = manifest.options?.followSymlinks !== false;
18
+ const payloadSourcesRoot = node_path_1.default.join(outputPath, 'payload', 'sources');
19
+ const payloadTemplatesRoot = node_path_1.default.join(outputPath, 'payload', 'templates');
20
+ const installPlan = {
21
+ targetPath: manifest.install?.targetPath,
22
+ overwrite: manifest.install?.overwrite ?? false,
23
+ sources: [],
24
+ templates: [],
25
+ };
26
+ await (0, fs_1.ensureDirectory)(payloadSourcesRoot);
27
+ await (0, fs_1.ensureDirectory)(payloadTemplatesRoot);
28
+ for (const source of manifest.sources) {
29
+ const sourcePath = (0, fs_1.resolveFrom)(manifestDirectory, source.path);
30
+ const sourceRoot = node_path_1.default.join(payloadSourcesRoot, source.id);
31
+ const destination = (0, source_destination_1.resolveSourceDestination)(source);
32
+ if (source.type === 'directory') {
33
+ if ((source.include?.length ?? 0) > 0 || (source.exclude?.length ?? 0) > 0) {
34
+ await (0, fs_1.copyDirectoryFiltered)(sourcePath, sourceRoot, source.include, source.exclude, followSymlinks);
35
+ }
36
+ else {
37
+ await (0, fs_1.copyDirectorySafe)(sourcePath, sourceRoot, followSymlinks);
38
+ }
39
+ installPlan.sources.push({
40
+ id: source.id,
41
+ kind: 'directory',
42
+ from: node_path_1.default.join('payload', 'sources', source.id),
43
+ to: destination,
44
+ });
45
+ continue;
46
+ }
47
+ const fileName = node_path_1.default.basename(source.path);
48
+ await (0, fs_1.copyFileSafe)(sourcePath, node_path_1.default.join(sourceRoot, fileName));
49
+ installPlan.sources.push({
50
+ id: source.id,
51
+ kind: 'file',
52
+ from: node_path_1.default.join('payload', 'sources', source.id, fileName),
53
+ to: destination,
54
+ });
55
+ }
56
+ for (const template of manifest.templates ?? []) {
57
+ const rendered = await (0, template_renderer_1.renderTemplateFile)(template, manifestDirectory);
58
+ await (0, fs_1.writeTextFile)(node_path_1.default.join(payloadTemplatesRoot, template.id, rendered.fileName), rendered.content);
59
+ installPlan.templates.push({
60
+ id: template.id,
61
+ from: node_path_1.default.join('payload', 'templates', template.id, rendered.fileName),
62
+ to: template.destination,
63
+ });
64
+ }
65
+ const snapshotPath = node_path_1.default.join(outputPath, 'manifest.resolved.json');
66
+ const installPlanPath = node_path_1.default.join(outputPath, 'meta', 'install-plan.json');
67
+ const packageMetadataPath = node_path_1.default.join(outputPath, 'package.json');
68
+ await (0, fs_1.writeJsonFile)(snapshotPath, manifest);
69
+ await (0, fs_1.writeJsonFile)(installPlanPath, installPlan);
70
+ await (0, fs_1.writeJsonFile)(packageMetadataPath, {
71
+ name: 'agentdock-package',
72
+ version: '1.0.0',
73
+ project: manifest.project.name,
74
+ manifestVersion: manifest.version,
75
+ });
76
+ return { outputPath, snapshotPath, installPlanPath };
77
+ }
78
+ finally {
79
+ await (0, fs_1.releaseLock)(lockHandle, lockFile);
80
+ }
81
+ }