flow-comet 1.6.2 → 1.6.4
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/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +64 -46
- package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +32 -0
- package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
- package/.flow-comet/skills/flow-comet/{GUIDANCE.md → reference/entry-detail.md} +18 -28
- package/.flow-comet/skills/flow-comet/reference/fix-loop.md +57 -0
- package/.flow-comet/skills/flow-comet/reference/platform-facts.md +58 -0
- package/.flow-comet/skills/flow-comet/reference/replan.md +23 -0
- package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +5 -4
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +266 -25
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -16325
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +73 -1077
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +14 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -6692
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2428
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +116 -9
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +29 -2086
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
- package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -3
- package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +6 -6
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +8 -5
- package/.flow-comet/skills/flow-comet-open/SKILL.md +5 -1
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
- package/.flow-comet/skills/flow-comet-review/SKILL.md +9 -12
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +59 -16
- package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +3 -3
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
- package/README.md +53 -70
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +59 -26
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +119 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +36 -1164
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +0 -116
- package/.flow-comet/skills/flow-comet/reference/composition-report.md +0 -65
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +0 -184
- package/.flow-comet/skills/flow-comet/reference/resolved-skills.json +0 -661
- package/.flow-comet/skills/flow-comet/reference/skill-review.md +0 -13
- package/.flow-comet/skills/flow-comet/reference/subagents/script-author.md +0 -7
- package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +0 -70
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* installer-migrate.mjs — 运行时文件位置迁移 + 路径存在性探测原语(prepare-env 的逻辑层模块)
|
|
3
|
+
*
|
|
4
|
+
* 为什么这两件事同处一个模块:迁移的白名单枚举与三处调用方(迁移自身 / .gitignore 纳管 /
|
|
5
|
+
* 生成物镜像的定向清理)共用同一条「该路径确实不存在」判定——ENOENT 与 ENOTDIR 算不存在,
|
|
6
|
+
* 访问类故障(EACCES / EPERM / EIO)必须原样抛出。这条语义若在调用方各写一份必然分叉:
|
|
7
|
+
* 一旦把访问故障当成「文件不存在」,迁移会静默跳过(用户以为已迁移)、.gitignore 会被按
|
|
8
|
+
* 空内容截断覆盖——都是静默的数据丢失。故它只有一份实现(本模块导出,调用方一律 import)。
|
|
9
|
+
*
|
|
10
|
+
* 依赖方向:本模块是叶子(只依赖 node 内置模块);installer-cleanup 与 installer-hooks 依赖它。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
// ---------- 运行时文件位置迁移(旧命名空间 .comet/ → 新命名空间 .flow-comet/) ----------
|
|
16
|
+
//
|
|
17
|
+
// 【过渡性模块——有明确退役条件,不是永久耦合】
|
|
18
|
+
// 本模块存在的唯一理由:让已安装项目把状态文件从旧命名空间搬到新命名空间,避免破坏性变更
|
|
19
|
+
// 导致用户进行中的流程状态丢失。它**只在安装/升级时执行一次**,从不进入任何日常运行路径
|
|
20
|
+
// (写入守卫、工作流脚本、协议解析均已完全不含对旧命名空间的感知)。
|
|
21
|
+
//
|
|
22
|
+
// 因此这里的 `.comet` 字面量是**迁移源**,不是 flow-comet 的命名归属——它标记的是"要从哪里
|
|
23
|
+
// 搬走",而非"我们是谁"。这是任何破坏性变更都需要的过渡桥(同"改名迁移脚本必须知道旧表名")。
|
|
24
|
+
//
|
|
25
|
+
// **退役条件**(满足任一即可整体删除本模块及其常量):
|
|
26
|
+
// ① 下一个破坏性版本发布时——迁移公告期结束(建议至少覆盖一个完整的 minor 周期,让下游
|
|
27
|
+
// 项目有时间升级);
|
|
28
|
+
// ② 或:连续多次安装运行中迁移报告**全部为「已跳过」**(说明已知项目均已迁移完毕)。
|
|
29
|
+
// 判据取证:每次安装都会打印迁移明细(已迁移 / 已跳过);长期全为「已跳过」即为退役信号。
|
|
30
|
+
//
|
|
31
|
+
// 位置迁移白名单(单一来源):目标项目的 `.comet/` 是三方共占目录——flow-comet 运行时文件
|
|
32
|
+
// + Comet 资产(`runs/`、`config.yaml` 等)+ 用户自有文件(`*.bak-*` 等)。只有下表列出的
|
|
33
|
+
// 文件属 flow-comet 运行时域,其余一律原位不动(不搬迁、不删除、不改写)——整目录搬迁或
|
|
34
|
+
// 前缀正则匹配都会越界处置非 flow-comet 资产。新增运行时文件时必须同步本表。
|
|
35
|
+
const LEGACY_RUNTIME_DIR = '.comet';
|
|
36
|
+
export const RUNTIME_DIR = '.flow-comet';
|
|
37
|
+
const RUNTIME_FILE_MIGRATIONS = [
|
|
38
|
+
{ name: 'flow-comet-state.json', validateJson: true },
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* readdir(withFileTypes):仅「该路径确实不存在」返回 null——判定与 lstatIfExists 同口径
|
|
42
|
+
* (见 isMissingPathError:只有 ENOENT / ENOTDIR 算不存在,访问类故障原样抛出)。
|
|
43
|
+
* 供镜像清理复用:把「目录不可枚举」与「目录为空」两个分支分开,避免清理判定深嵌 try/catch。
|
|
44
|
+
*/
|
|
45
|
+
export function readdirIfExists(dir) {
|
|
46
|
+
try {
|
|
47
|
+
return fs.readdirSync(dir, { withFileTypes: true });
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (isMissingPathError(err)) return null;
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 「该路径确实不存在」一类错误的单一判定(迁移探测与 gitignore 纳管共用同一判据——
|
|
55
|
+
* 同一语义只有一处实现,改一处即全改,不会分叉):
|
|
56
|
+
* - ENOENT:路径缺失;
|
|
57
|
+
* - ENOTDIR:路径中某一段不是目录——该路径不可能存在为文件(跨平台等价于「不存在」:
|
|
58
|
+
* 同一形态在 Windows 报 ENOENT、在 POSIX 报 ENOTDIR)。
|
|
59
|
+
* 其余错误(EACCES / EPERM / EIO 等访问类故障)**不算**「不存在」——把访问故障当成
|
|
60
|
+
* 「文件不存在」会让调用方按空内容继续(迁移静默跳过 / gitignore 被截断覆盖),
|
|
61
|
+
* 都是静默的数据丢失风险,必须原样抛出并中止。
|
|
62
|
+
*/
|
|
63
|
+
export function isMissingPathError(err) {
|
|
64
|
+
return Boolean(err) && typeof err === 'object' && (err.code === 'ENOENT' || err.code === 'ENOTDIR');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* lstat 探测:返回 stat 或 null(**不跟随符号链接**——isSymbolicLink() 判定依赖 lstat)。
|
|
69
|
+
* 只有「该路径确实不存在」一类错误返回 null(判定见 isMissingPathError);其余错误原样抛出——
|
|
70
|
+
* 迁移静默跳过会让安装照常继续并报告「已跳过:旧位置不存在」,用户的旧状态却永远留在旧位置
|
|
71
|
+
* (用户以为已迁移)。
|
|
72
|
+
*/
|
|
73
|
+
export function lstatIfExists(target) {
|
|
74
|
+
try {
|
|
75
|
+
return fs.lstatSync(target);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (isMissingPathError(err)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** 迁移备份文件名时间戳(ISO 串里的 `:` 与 `.` 在 Windows 文件名中非法——统一替换为 `-`)。 */
|
|
84
|
+
function migrationTimestamp() {
|
|
85
|
+
return new Date().toISOString().replace(/[:.]/g, '-');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 逐字节读回并比较;读取失败一律视为不一致(调用方按校验失败处置)。 */
|
|
89
|
+
function fileEqualsBytes(filePath, bytes) {
|
|
90
|
+
try {
|
|
91
|
+
return fs.readFileSync(filePath).equals(bytes);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 迁移前置校验:旧件不存在 → 返回 null(无需迁移);命中边界情形 → 抛错中止(不返回字节)。
|
|
99
|
+
* 三种边界一律不静默覆盖或丢弃:
|
|
100
|
+
* - 旧件是符号链接 → 不跟随(防穿越到项目外),报错并给人工处置指引
|
|
101
|
+
* - 新旧位置并存 → 不覆盖任何一方,报错并列出两处路径供人工判断
|
|
102
|
+
* - 内容损坏(validateJson 条目)→ 保留原件未改动,报错并给修复指引
|
|
103
|
+
*/
|
|
104
|
+
function readMigratableRuntimeFile(oldPath, newPath, entry) {
|
|
105
|
+
const oldStat = lstatIfExists(oldPath);
|
|
106
|
+
if (!oldStat) return null;
|
|
107
|
+
if (oldStat.isSymbolicLink()) {
|
|
108
|
+
let linkTarget = '(读取失败)';
|
|
109
|
+
try {
|
|
110
|
+
linkTarget = fs.readlinkSync(oldPath);
|
|
111
|
+
} catch {
|
|
112
|
+
/* 链接目标读取失败不改变处置(同样中止) */
|
|
113
|
+
}
|
|
114
|
+
throw new Error(
|
|
115
|
+
`${oldPath} 是符号链接(指向 ${linkTarget})——不跟随链接搬移(避免穿越到项目外)。` +
|
|
116
|
+
`请人工确认后处理:把真实文件复制到 ${newPath}(保留本链接),或删除该链接后重跑安装器。`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (lstatIfExists(newPath)) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`新旧位置同时存在该运行时文件,不覆盖任何一方:\n - 旧位置: ${oldPath}\n - 新位置: ${newPath}\n` +
|
|
122
|
+
`请人工比对两处内容,保留正确的一份(删除或改名另一份)后重跑安装器。`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
let bytes;
|
|
126
|
+
try {
|
|
127
|
+
bytes = fs.readFileSync(oldPath);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
throw new Error(`${oldPath} 读取失败(${err.message})——未做任何改动,中止迁移。请检查文件权限后重跑安装器。`);
|
|
130
|
+
}
|
|
131
|
+
if (entry.validateJson) {
|
|
132
|
+
let parsed = null;
|
|
133
|
+
try {
|
|
134
|
+
// 校验容忍 UTF-8 BOM(与运行时判定一致:workflow-state.mjs 的 readJson 明确容忍 BOM,
|
|
135
|
+
// 外部写入如会话 Write 可能带 BOM)——否则运行时读得动的状态文件会被迁移判为损坏而
|
|
136
|
+
// 中止安装(同一份数据两处判定不一致)。strip 只作用于校验:备份与落盘始终写原始字节
|
|
137
|
+
// bytes,绝不改写用户数据(BOM strip 用字面形态——与 workflow-state.mjs 的 readJson 同形,
|
|
138
|
+
// 行为由场景 234 端到端锚定:若该字符被剥离会立即变红)。
|
|
139
|
+
parsed = JSON.parse(bytes.toString('utf8').replace(/^/, ''));
|
|
140
|
+
} catch (err) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`${oldPath} 内容不是合法 JSON(${err.message})——保留原件未改动,中止迁移。` +
|
|
143
|
+
`请修复该文件(或从备份恢复)后重跑安装器。`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
147
|
+
throw new Error(`${oldPath} 顶层不是 JSON 对象——保留原件未改动,中止迁移。请修复该文件后重跑安装器。`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return bytes;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 搬移落盘(写成功才删旧件):建目标目录 → 复制备份 → 逐字节校验备份 → 写新位置 →
|
|
155
|
+
* 回读校验新位置 → 删旧件。任一环节失败都抛错,且**旧件与备份至少保留一份**(不丢数据)。
|
|
156
|
+
*/
|
|
157
|
+
function writeRuntimeFileWithBackup(oldPath, newPath, backupPath, bytes) {
|
|
158
|
+
const targetDir = path.dirname(newPath);
|
|
159
|
+
const keepNote = `旧文件完整保留于 ${oldPath}`;
|
|
160
|
+
try {
|
|
161
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
162
|
+
} catch (err) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`无法建立迁移目标目录 ${targetDir}(${err.message})——${keepNote},未做任何改动。` +
|
|
165
|
+
`请确认该路径未被普通文件占用且可写后重跑安装器。`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
fs.copyFileSync(oldPath, backupPath);
|
|
170
|
+
} catch (err) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`生成迁移前备份失败(${backupPath}:${err.message})——${keepNote},未做任何改动。` +
|
|
173
|
+
`请解除目标目录的写入限制后重跑安装器。`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (!fileEqualsBytes(backupPath, bytes)) {
|
|
177
|
+
throw new Error(`备份逐字节校验失败(${backupPath} 与源文件不一致)——${keepNote},中止迁移。请重跑安装器。`);
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
fs.writeFileSync(newPath, bytes);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`写入新位置失败(${newPath}:${err.message})——${keepNote},备份保留于 ${backupPath}。` +
|
|
184
|
+
`请解除该路径的写入限制后重跑安装器。`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (!fileEqualsBytes(newPath, bytes)) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`新位置回读校验失败(${newPath} 与源文件不一致)——${keepNote},备份保留于 ${backupPath},中止迁移。请人工检查后重跑安装器。`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
fs.rmSync(oldPath, { force: true });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 编排单个白名单文件的位置迁移(前置校验 → 备份 → 写 → 回读校验 → 删旧件);
|
|
197
|
+
* 无需迁移时把跳过说明记入 report(调用方统一打印)。
|
|
198
|
+
*/
|
|
199
|
+
function migrateRuntimeFile(target, entry, report) {
|
|
200
|
+
const oldRel = path.join(LEGACY_RUNTIME_DIR, entry.name);
|
|
201
|
+
const newRel = path.join(RUNTIME_DIR, entry.name);
|
|
202
|
+
const oldPath = path.join(target, oldRel);
|
|
203
|
+
const newPath = path.join(target, newRel);
|
|
204
|
+
const bytes = readMigratableRuntimeFile(oldPath, newPath, entry);
|
|
205
|
+
if (!bytes) {
|
|
206
|
+
report.skipped.push(`${oldRel} 不存在——无需迁移`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const backupRel = path.join(RUNTIME_DIR, `${entry.name}.bak-${migrationTimestamp()}`);
|
|
210
|
+
writeRuntimeFileWithBackup(oldPath, newPath, path.join(target, backupRel), bytes);
|
|
211
|
+
report.migrated.push(`${oldRel} → ${newRel}(迁移前备份: ${backupRel})`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 运行时文件位置迁移总入口:按 RUNTIME_FILE_MIGRATIONS 白名单逐个执行(白名单之外的内容
|
|
216
|
+
* 一律原位不动——目标项目 `.comet/` 三方共占),打印迁移/跳过报告;任一文件失败即抛错中止
|
|
217
|
+
* (旧件与备份保留,可重跑自愈)。
|
|
218
|
+
*/
|
|
219
|
+
export function migrateRuntimeFiles(target) {
|
|
220
|
+
const report = { migrated: [], skipped: [] };
|
|
221
|
+
for (const entry of RUNTIME_FILE_MIGRATIONS) {
|
|
222
|
+
migrateRuntimeFile(target, entry, report);
|
|
223
|
+
}
|
|
224
|
+
console.log(`[flow-comet] 运行时文件迁移(${LEGACY_RUNTIME_DIR}/ → ${RUNTIME_DIR}/;白名单 ${RUNTIME_FILE_MIGRATIONS.length} 项):`);
|
|
225
|
+
for (const line of report.migrated) {
|
|
226
|
+
console.log(` - 已迁移: ${line}`);
|
|
227
|
+
}
|
|
228
|
+
for (const line of report.skipped) {
|
|
229
|
+
console.log(` - 已跳过: ${line}`);
|
|
230
|
+
}
|
|
231
|
+
if (report.migrated.length > 0) {
|
|
232
|
+
console.log(' (迁移前备份保留在新位置,确认无误后可自行清理)');
|
|
233
|
+
} else {
|
|
234
|
+
console.log(' (全部跳过 = 本项目的状态已在当前命名空间,安装器不再需要触碰旧目录)');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* installer-platforms.mjs — 平台描述符表 + 生成物部署原语(prepare-env 的逻辑层模块)
|
|
3
|
+
*
|
|
4
|
+
* 为什么这三段同处一个模块:平台描述符(各平台的安装位置、路径替换、hook/rules 注入、purge
|
|
5
|
+
* 与覆盖清单)与「整树复制 / 平台路径替换」是同一件事的两半——描述符的 installRules 直接调用
|
|
6
|
+
* 复制原语,入口主流程也用它铺技能树。放在一处既避免「描述符 → 入口 → 描述符」的循环 import,
|
|
7
|
+
* 也让「复制语义只有一份实现」成为结构事实。
|
|
8
|
+
*
|
|
9
|
+
* 仓库根与权威源常量(REPO_ROOT / BUNDLE_DRAFTS)也定在这里:描述符表在模块加载期就需要它们
|
|
10
|
+
* (dsh 的桥接 loader 源路径、各平台 rules 源目录),而依赖方向是单向的(入口 → lib),常量
|
|
11
|
+
* 只能落在 lib 一侧——入口与其余模块一律 import 本模块,不各自推导(同一事实不写两份)。
|
|
12
|
+
*
|
|
13
|
+
* 依赖方向:本模块依赖 installer-hooks(配置注入)与 installer-loader(loader 版本比对 /
|
|
14
|
+
* cordis patch);反向依赖不存在。
|
|
15
|
+
*/
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
MANAGED_AGENTS_END,
|
|
22
|
+
MANAGED_AGENTS_START,
|
|
23
|
+
injectCodexConfig,
|
|
24
|
+
injectCodexHook,
|
|
25
|
+
injectManagedRules,
|
|
26
|
+
injectSettingsHook,
|
|
27
|
+
removeManagedCodexHooks,
|
|
28
|
+
resolveDshHome,
|
|
29
|
+
} from './installer-hooks.mjs';
|
|
30
|
+
import {
|
|
31
|
+
injectDshCordisPatch,
|
|
32
|
+
removeDshCordisPatch,
|
|
33
|
+
reportLoaderVersionTransition,
|
|
34
|
+
stripManagedBlock,
|
|
35
|
+
} from './installer-loader.mjs';
|
|
36
|
+
|
|
37
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
38
|
+
export const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
|
39
|
+
// 权威源根(含 skills/ 与 rules/——目录结构与安装副本 .claude/ 对称:<根>/skills/flow-comet/)
|
|
40
|
+
export const BUNDLE_DRAFTS = path.join(REPO_ROOT, '.flow-comet');
|
|
41
|
+
// rules 源目录:三个平台的 rules 注入(.claude/rules 整树复制 / AGENTS.md 托管区内联)共用同一取值
|
|
42
|
+
const RULES_SRC = path.join(BUNDLE_DRAFTS, 'rules');
|
|
43
|
+
// ---------- 平台描述符表(单一来源——新增平台 = 描述符条目 + 安装/清理函数,main 零改动) ----------
|
|
44
|
+
// D6:flow-kit 永不纳入清理域——下述各平台 purge 清单均不含 <target>/flow-kit/(含 --purge --yes);
|
|
45
|
+
// 它不是本安装器的生成物域(ADR-008),由安装器首次创建的 flow-kit 残留属预期。
|
|
46
|
+
|
|
47
|
+
export const PLATFORMS = {
|
|
48
|
+
'claude-code': {
|
|
49
|
+
label: 'Claude Code',
|
|
50
|
+
// 技能安装根(相对 target;与权威源 .claude 形态一致——零路径替换)
|
|
51
|
+
skillRoot: (target) => path.join(target, '.claude', 'skills'),
|
|
52
|
+
// 平台路径替换表(from 正则 → to):claude-code 为空 = 权威源即目标形态
|
|
53
|
+
pathReplacements: [],
|
|
54
|
+
// hook 注入:settings.local.json 读-合并-写(保留既有字段;matcher Write|Edit)
|
|
55
|
+
installHooks(target, stats) {
|
|
56
|
+
const claudeDir = path.join(target, '.claude');
|
|
57
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
58
|
+
stats.dirs++;
|
|
59
|
+
const settings = injectSettingsHook(claudeDir);
|
|
60
|
+
const injected = !!(settings.hooks && settings.hooks.PreToolUse);
|
|
61
|
+
stats.files++;
|
|
62
|
+
console.log(`[flow-comet] settings.local.json ${injected ? '注入完成(保留既有字段)' : '已生成'}`);
|
|
63
|
+
},
|
|
64
|
+
// rules 注入:.claude/rules/ 整树复制(自动加载 markdown 指令)
|
|
65
|
+
installRules(target, stats) {
|
|
66
|
+
if (fs.existsSync(RULES_SRC)) {
|
|
67
|
+
copyTree(RULES_SRC, path.join(target, '.claude', 'rules'), stats);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
// purge 清理:整删 .claude/(CC 的 .claude 即 flow-comet 生成物域);返回删除清单供打印
|
|
71
|
+
purge(target) {
|
|
72
|
+
const claudeDir = path.join(target, '.claude');
|
|
73
|
+
const removed = [];
|
|
74
|
+
if (fs.existsSync(claudeDir)) {
|
|
75
|
+
for (const entry of fs.readdirSync(claudeDir)) {
|
|
76
|
+
removed.push(path.join(claudeDir, entry));
|
|
77
|
+
}
|
|
78
|
+
fs.rmSync(claudeDir, { recursive: true, force: true });
|
|
79
|
+
}
|
|
80
|
+
return removed;
|
|
81
|
+
},
|
|
82
|
+
// 覆盖清单描述(默认非破坏:只覆盖生成物)
|
|
83
|
+
overwriteDescription(target) {
|
|
84
|
+
return [
|
|
85
|
+
path.join(target, '.claude', 'rules'),
|
|
86
|
+
path.join(target, '.claude', 'settings.local.json') + '(注入方式:保留既有字段,仅更新 hooks.PreToolUse)',
|
|
87
|
+
];
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
'codex': {
|
|
91
|
+
label: 'Codex',
|
|
92
|
+
// 技能安装根:Codex 自动发现位置($CWD/.agents/skills/ 最高优先)
|
|
93
|
+
skillRoot: (target) => path.join(target, '.agents', 'skills'),
|
|
94
|
+
// SKILL/GUIDANCE 命令路径平台化替换(权威源保持 .claude 形态,安装时替换)
|
|
95
|
+
pathReplacements: [
|
|
96
|
+
{ from: /\.claude\/skills\/flow-comet\/scripts\//g, to: '.agents/skills/flow-comet/scripts/' },
|
|
97
|
+
],
|
|
98
|
+
// hook 注入:.codex/hooks.json(顶层 hooks 包裹层 + matcher *)+ config.toml features 启用
|
|
99
|
+
installHooks(target, stats) {
|
|
100
|
+
const codexDir = path.join(target, '.codex');
|
|
101
|
+
injectCodexHook(codexDir, target);
|
|
102
|
+
injectCodexConfig(codexDir);
|
|
103
|
+
stats.files += 2;
|
|
104
|
+
console.log('[flow-comet] .codex/hooks.json + config.toml 注入完成(hooks 启用,保留既有字段)');
|
|
105
|
+
},
|
|
106
|
+
// rules 注入:AGENTS.md 托管区内联(Codex 指令唯一自动加载路径;.codex/rules/ 是命令批准规则目录,不混用;
|
|
107
|
+
// 注入函数与托管区标记 codex/dsh 共用——任一平台卸载可清,另一平台重装恢复)
|
|
108
|
+
installRules(target, stats) {
|
|
109
|
+
if (injectManagedRules(target, stats, RULES_SRC)) {
|
|
110
|
+
console.log('[flow-comet] AGENTS.md 托管区注入完成(保留托管区外用户内容)');
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
// purge 清理:只清 flow-comet 技能(.agents/ 为多工具共享位置——非 flow-comet 条目保留)
|
|
114
|
+
// + .codex/hooks.json 托管条目(保留用户条目)+ AGENTS.md 托管区(保留文件本身)
|
|
115
|
+
purge(target) {
|
|
116
|
+
const removed = [];
|
|
117
|
+
const agentsSkillsDir = path.join(target, '.agents', 'skills');
|
|
118
|
+
if (fs.existsSync(agentsSkillsDir)) {
|
|
119
|
+
for (const entry of fs.readdirSync(agentsSkillsDir)) {
|
|
120
|
+
if (!/^flow-comet/.test(entry)) continue;
|
|
121
|
+
const managed = path.join(agentsSkillsDir, entry);
|
|
122
|
+
removed.push(managed);
|
|
123
|
+
fs.rmSync(managed, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const hooksPath = path.join(target, '.codex', 'hooks.json');
|
|
127
|
+
if (fs.existsSync(hooksPath)) {
|
|
128
|
+
removed.push(hooksPath + '(移除托管 hook 条目,保留用户条目)');
|
|
129
|
+
// 移除托管条目(重建流程随后重新注入新托管条目——purge = 移除旧生成物后重建)
|
|
130
|
+
removeManagedCodexHooks(path.join(target, '.codex'));
|
|
131
|
+
}
|
|
132
|
+
const agentsPath = path.join(target, 'AGENTS.md');
|
|
133
|
+
if (fs.existsSync(agentsPath)) {
|
|
134
|
+
const content = fs.readFileSync(agentsPath, 'utf8');
|
|
135
|
+
if (content.includes(MANAGED_AGENTS_START)) {
|
|
136
|
+
removed.push(agentsPath + '(托管区)');
|
|
137
|
+
const stripped = stripManagedBlock(content, MANAGED_AGENTS_START, MANAGED_AGENTS_END);
|
|
138
|
+
fs.writeFileSync(agentsPath, stripped.trim() + '\n', 'utf8');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return removed;
|
|
142
|
+
},
|
|
143
|
+
// 覆盖清单描述(默认非破坏:只覆盖生成物)
|
|
144
|
+
overwriteDescription(target) {
|
|
145
|
+
return [
|
|
146
|
+
path.join(target, 'AGENTS.md') + '(托管区注入:保留托管区外用户内容)',
|
|
147
|
+
path.join(target, '.codex', 'hooks.json') + '(注入方式:保留既有字段,仅更新托管 hook 条目)',
|
|
148
|
+
path.join(target, '.codex', 'config.toml') + '(注入方式:补 [features] hooks 启用键)',
|
|
149
|
+
];
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
'dsh': {
|
|
153
|
+
label: 'DeepSeek Harness',
|
|
154
|
+
// 技能安装根:dsh 项目级 skill 发现(rank 100 自动发现,免重启;未安装该目录的项目不可见该 skill)
|
|
155
|
+
skillRoot: (target) => path.join(target, '.dsh', 'skills'),
|
|
156
|
+
// SKILL/GUIDANCE 命令路径平台化替换(权威源保持 .claude 形态,安装时替换)
|
|
157
|
+
pathReplacements: [
|
|
158
|
+
{ from: /\.claude\/skills\/flow-comet\/scripts\//g, to: '.dsh/skills/flow-comet/scripts/' },
|
|
159
|
+
],
|
|
160
|
+
// hook 注入:全局挂载桥接 loader($DSH_HOME/plugins/ 复制 + cordis.patch.yml 托管块——
|
|
161
|
+
// 所有 profile 生效;$DSH_HOME 解析 = 显式 DSH_HOME > ~/.dsh)
|
|
162
|
+
installHooks(target, stats) {
|
|
163
|
+
const dshHome = resolveDshHome();
|
|
164
|
+
const pluginsDir = path.join(dshHome, 'plugins');
|
|
165
|
+
const loaderSrc = path.join(REPO_ROOT, 'scripts', 'dsh-bridge.mjs');
|
|
166
|
+
const loaderDst = path.join(pluginsDir, 'dsh-flow-comet-bridge.mjs');
|
|
167
|
+
if (fs.existsSync(loaderSrc)) {
|
|
168
|
+
fs.mkdirSync(pluginsDir, { recursive: true });
|
|
169
|
+
// 覆盖前版本比对明示(版本戳标记契约):输出首次安装/升级/降级/版本一致之一;
|
|
170
|
+
// 任一侧提取失败只告警不中断——覆盖照常执行(幂等语义不变)
|
|
171
|
+
reportLoaderVersionTransition(loaderSrc, loaderDst);
|
|
172
|
+
fs.copyFileSync(loaderSrc, loaderDst);
|
|
173
|
+
stats.files++;
|
|
174
|
+
console.log('[flow-comet] 桥接 loader 已复制到 $DSH_HOME/plugins/dsh-flow-comet-bridge.mjs');
|
|
175
|
+
injectDshCordisPatch(dshHome, loaderDst);
|
|
176
|
+
stats.files++;
|
|
177
|
+
console.log('[flow-comet] $DSH_HOME/cordis.patch.yml 托管块注入完成(读-合并-写,保留既有块)');
|
|
178
|
+
} else {
|
|
179
|
+
// 容错:scripts/dsh-bridge.mjs 由并行任务新建——源缺失时 WARN 跳过 loader 复制
|
|
180
|
+
// **并跳过 cordis.patch.yml 托管块注入**(避免注入指向不存在文件的 file:// 引用,
|
|
181
|
+
// 导致 dsh 每次启动尝试加载不存在的插件);仍完成其余安装
|
|
182
|
+
// (AGENTS.md 托管区 / skills 复制照常)
|
|
183
|
+
console.warn(
|
|
184
|
+
'[flow-comet] 警告: scripts/dsh-bridge.mjs 不存在——跳过 loader 复制与 cordis.patch.yml 托管块注入' +
|
|
185
|
+
'(dsh 桥接拦截暂不生效,待源文件就位后重跑 prepare-env)'
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
// rules 注入:AGENTS.md 托管区(与 codex 共用注入函数与托管区标记——任一平台卸载可清)
|
|
190
|
+
installRules(target, stats) {
|
|
191
|
+
if (injectManagedRules(target, stats, RULES_SRC)) {
|
|
192
|
+
console.log('[flow-comet] AGENTS.md 托管区注入完成(保留托管区外用户内容)');
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
// purge 清理:项目级 .dsh/skills 下全部 flow-comet* 技能(.dsh/skills 为 dsh 技能位置——
|
|
196
|
+
// 非 flow-comet 条目保留,与 codex purge 同语义)+ 空 .dsh 目录 + AGENTS.md 托管区
|
|
197
|
+
// (保留文件与用户内容)+ $DSH_HOME/cordis.patch.yml 托管块 + plugins/ loader
|
|
198
|
+
// (写 home 的敏感面——purge 需 --yes 显式确认)
|
|
199
|
+
purge(target) {
|
|
200
|
+
const removed = [];
|
|
201
|
+
const dshSkillsDir = path.join(target, '.dsh', 'skills');
|
|
202
|
+
if (fs.existsSync(dshSkillsDir)) {
|
|
203
|
+
for (const entry of fs.readdirSync(dshSkillsDir)) {
|
|
204
|
+
if (!/^flow-comet/.test(entry)) continue;
|
|
205
|
+
const managed = path.join(dshSkillsDir, entry);
|
|
206
|
+
removed.push(managed);
|
|
207
|
+
fs.rmSync(managed, { recursive: true, force: true });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 空目录清理:仅删空目录(skills 下无剩余条目 / .dsh 下无其它内容时)——有内容则保留
|
|
211
|
+
if (fs.existsSync(dshSkillsDir) && fs.readdirSync(dshSkillsDir).length === 0) {
|
|
212
|
+
fs.rmdirSync(dshSkillsDir);
|
|
213
|
+
removed.push(dshSkillsDir);
|
|
214
|
+
}
|
|
215
|
+
const dshDir = path.join(target, '.dsh');
|
|
216
|
+
if (fs.existsSync(dshDir) && fs.readdirSync(dshDir).length === 0) {
|
|
217
|
+
fs.rmdirSync(dshDir);
|
|
218
|
+
removed.push(dshDir);
|
|
219
|
+
}
|
|
220
|
+
const agentsPath = path.join(target, 'AGENTS.md');
|
|
221
|
+
if (fs.existsSync(agentsPath)) {
|
|
222
|
+
const content = fs.readFileSync(agentsPath, 'utf8');
|
|
223
|
+
if (content.includes(MANAGED_AGENTS_START)) {
|
|
224
|
+
removed.push(agentsPath + '(托管区)');
|
|
225
|
+
const stripped = stripManagedBlock(content, MANAGED_AGENTS_START, MANAGED_AGENTS_END);
|
|
226
|
+
fs.writeFileSync(agentsPath, stripped.trim() + '\n', 'utf8');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// home patch 托管块移除 + loader 删除($DSH_HOME——写 home 的敏感面)
|
|
230
|
+
const dshHome = resolveDshHome();
|
|
231
|
+
for (const entry of removeDshCordisPatch(dshHome)) {
|
|
232
|
+
removed.push(entry);
|
|
233
|
+
}
|
|
234
|
+
const loaderPath = path.join(dshHome, 'plugins', 'dsh-flow-comet-bridge.mjs');
|
|
235
|
+
if (fs.existsSync(loaderPath)) {
|
|
236
|
+
removed.push(loaderPath + '($DSH_HOME/plugins/ loader)');
|
|
237
|
+
fs.rmSync(loaderPath, { force: true });
|
|
238
|
+
// 全局挂载语义警示:loader 位于 $DSH_HOME(所有 profile / 所有项目共享)——
|
|
239
|
+
// 任一项目 purge 都会连带移除,其它已安装 flow-comet 的项目将静默失去拦截
|
|
240
|
+
console.warn(
|
|
241
|
+
'[flow-comet] 全局桥接 loader 被移除,其它已安装 flow-comet 的项目将停止拦截' +
|
|
242
|
+
'($DSH_HOME 全局挂载——如需恢复请重跑 prepare-env --platform dsh)'
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
return removed;
|
|
246
|
+
},
|
|
247
|
+
// 覆盖清单描述(默认非破坏:只覆盖生成物;声明写 home 的敏感面)
|
|
248
|
+
overwriteDescription(target) {
|
|
249
|
+
return [
|
|
250
|
+
path.join(target, 'AGENTS.md') + '(托管区注入:保留托管区外用户内容)',
|
|
251
|
+
path.join(resolveDshHome(), 'cordis.patch.yml') + '(托管块注入:保留 dsh-skin 等既有块)',
|
|
252
|
+
path.join(resolveDshHome(), 'plugins', 'dsh-flow-comet-bridge.mjs') + '($DSH_HOME 全局挂载——安装器写 home 目录的敏感面)',
|
|
253
|
+
];
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
// ---------- 文件工具 ----------
|
|
258
|
+
|
|
259
|
+
/** 递归收集 srcDir 下所有目录与文件的绝对路径 */
|
|
260
|
+
function collect(srcDir) {
|
|
261
|
+
const dirs = [];
|
|
262
|
+
const files = [];
|
|
263
|
+
(function walk(dir) {
|
|
264
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
265
|
+
const abs = path.join(dir, entry.name);
|
|
266
|
+
if (entry.isDirectory()) {
|
|
267
|
+
dirs.push(abs);
|
|
268
|
+
walk(abs);
|
|
269
|
+
} else if (entry.isFile()) {
|
|
270
|
+
files.push(abs);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
})(srcDir);
|
|
274
|
+
return { dirs, files };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** 整树复制 srcDir → dstRoot(保持相对结构),计数写入 stats */
|
|
278
|
+
export function copyTree(srcDir, dstRoot, stats) {
|
|
279
|
+
fs.mkdirSync(dstRoot, { recursive: true });
|
|
280
|
+
stats.dirs++;
|
|
281
|
+
const { dirs, files } = collect(srcDir);
|
|
282
|
+
for (const d of dirs) {
|
|
283
|
+
fs.mkdirSync(path.join(dstRoot, path.relative(srcDir, d)), { recursive: true });
|
|
284
|
+
stats.dirs++;
|
|
285
|
+
}
|
|
286
|
+
for (const f of files) {
|
|
287
|
+
fs.copyFileSync(f, path.join(dstRoot, path.relative(srcDir, f)));
|
|
288
|
+
stats.files++;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 平台路径替换:对复制后的技能包内全部 .md 文件(SKILL/GUIDANCE/reference)做命令路径替换。
|
|
294
|
+
* 权威源保持 .claude 形态;claude-code 平台替换表为空(零改动,可复现性 diff 不变)。
|
|
295
|
+
* 幂等:同平台重复安装替换结果一致。
|
|
296
|
+
*/
|
|
297
|
+
export function applyPathReplacements(root, replacements) {
|
|
298
|
+
if (!replacements || replacements.length === 0) return 0;
|
|
299
|
+
let replaced = 0;
|
|
300
|
+
const { files } = collect(root);
|
|
301
|
+
for (const f of files) {
|
|
302
|
+
if (!f.endsWith('.md')) continue;
|
|
303
|
+
let content = fs.readFileSync(f, 'utf8');
|
|
304
|
+
const original = content;
|
|
305
|
+
for (const { from, to } of replacements) {
|
|
306
|
+
content = content.replace(from, to);
|
|
307
|
+
}
|
|
308
|
+
if (content !== original) {
|
|
309
|
+
fs.writeFileSync(f, content, 'utf8');
|
|
310
|
+
replaced++;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return replaced;
|
|
314
|
+
}
|