@andyqiu/codeforge 0.6.4 → 0.6.5
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/dist/index.js +1 -1
- package/install.mjs +96 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19760,7 +19760,7 @@ import * as zlib from "node:zlib";
|
|
|
19760
19760
|
// lib/version-injected.ts
|
|
19761
19761
|
function getInjectedVersion() {
|
|
19762
19762
|
try {
|
|
19763
|
-
const v = "0.6.
|
|
19763
|
+
const v = "0.6.5";
|
|
19764
19764
|
if (typeof v === "string" && /^\d+\.\d+\.\d+/.test(v)) {
|
|
19765
19765
|
return v;
|
|
19766
19766
|
}
|
package/install.mjs
CHANGED
|
@@ -176,8 +176,15 @@ const MANAGED_DIRS = ["codeforge", "agents", "commands", "workflows", "context-t
|
|
|
176
176
|
// 细粒度卸载:只删 CodeForge 自己的 skill
|
|
177
177
|
const OWNED_SKILLS = ["ambiguity-gate", "devils-advocate", "ears-zh", "example-mapping", "success-criteria", "weighted-dimensions"]
|
|
178
178
|
|
|
179
|
-
// 文件级 copy(.md,排除 README/_*/.bak
|
|
179
|
+
// 文件级 copy(.md,排除 README/_*/.bak/隐藏)— per-file upsert + manifest 差集清理,不 rmrf 整目录
|
|
180
|
+
// ADR:install-whitelist-md-files
|
|
180
181
|
const MD_COPY_DIRS = [["agents", "agents"], ["commands", "commands"]]
|
|
182
|
+
|
|
183
|
+
// codeforge 自维护的 .md 安装清单:记录"上一版 codeforge 在各目标目录装了哪些 .md"。
|
|
184
|
+
// 用途:install 时算差集(manifest − 本次源)精准清理本版已删除的旧 codeforge 文件,
|
|
185
|
+
// 第三方 .md(如 teamkit-git.md)从不写入 manifest → 永不被清理(零副作用)。
|
|
186
|
+
// 位置在 codeforge/ 子目录下,uninstall 的 rmrf(codeforge/) 会自然清掉,无需额外卸载逻辑。
|
|
187
|
+
const MD_MANIFEST_REL = "codeforge/installed-md-manifest.json"
|
|
181
188
|
// 整目录拷贝
|
|
182
189
|
const COPY_DIRS = [
|
|
183
190
|
["workflows", "workflows"],
|
|
@@ -450,31 +457,57 @@ function installBundle({ targetRoot, bundleSrc }) {
|
|
|
450
457
|
vok(`VERSION → ${versionFile} (${version})`)
|
|
451
458
|
}
|
|
452
459
|
|
|
460
|
+
// ADR:install-whitelist-md-files —— manifest 自维护:不再 rmrf 整目录,
|
|
461
|
+
// 读 manifest 算差集精准清理旧 codeforge .md,第三方 .md 零副作用。
|
|
453
462
|
function installMdDirs({ targetRoot }) {
|
|
463
|
+
// 步骤 1:读上一版 manifest(不存在 → 各目录空列表 = 首次安装)
|
|
464
|
+
const prevManifest = readMdManifest(targetRoot)
|
|
465
|
+
const nextManifest = {}
|
|
466
|
+
|
|
454
467
|
for (const [srcName, dstName] of MD_COPY_DIRS) {
|
|
455
468
|
const srcPath = path.join(SOURCE_ROOT, srcName)
|
|
456
469
|
const dstPath = path.join(targetRoot, dstName)
|
|
457
470
|
if (!fs.existsSync(srcPath) || !fs.statSync(srcPath).isDirectory()) {
|
|
458
471
|
vlog(`源目录不存在,跳过: ${srcPath}`)
|
|
472
|
+
// 源目录缺失:本版该目录装 0 个文件,manifest 记空(差集会清掉上一版全部该目录文件)
|
|
473
|
+
nextManifest[dstName] = []
|
|
474
|
+
const prevList = prevManifest[dstName] ?? []
|
|
475
|
+
pruneStale({ dstPath, prevList, sourceSet: new Set() })
|
|
459
476
|
continue
|
|
460
477
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
478
|
+
ensureDir(dstPath) // 不再 rmrf;幂等建目录
|
|
479
|
+
|
|
480
|
+
// 步骤 2:扫源目录 → sourceSet(本版要装的文件名集合)
|
|
481
|
+
const sourceFiles = []
|
|
482
|
+
const srcEntries = fs.readdirSync(srcPath)
|
|
483
|
+
for (const base of srcEntries) {
|
|
466
484
|
if (!shouldCopyMd(base)) continue
|
|
485
|
+
try { if (!fs.statSync(path.join(srcPath, base)).isFile()) continue } catch { continue }
|
|
486
|
+
sourceFiles.push(base)
|
|
487
|
+
}
|
|
488
|
+
const sourceSet = new Set(sourceFiles)
|
|
489
|
+
|
|
490
|
+
// 步骤 3:差集清理 prevManifest[dir] − sourceSet(仅删确实存在的)
|
|
491
|
+
const prevList = prevManifest[dstName] ?? []
|
|
492
|
+
const pruned = pruneStale({ dstPath, prevList, sourceSet })
|
|
493
|
+
|
|
494
|
+
// 步骤 4:upsert —— 把 sourceSet 文件复制到目标(覆盖同名,不动其他文件)
|
|
495
|
+
let count = 0
|
|
496
|
+
for (const base of sourceFiles) {
|
|
467
497
|
const f = path.join(srcPath, base)
|
|
468
|
-
try {
|
|
469
|
-
if (!fs.statSync(f).isFile()) continue
|
|
470
|
-
} catch {
|
|
471
|
-
continue
|
|
472
|
-
}
|
|
473
498
|
run(`cp ${f} ${dstPath}/`, () => fs.copyFileSync(f, path.join(dstPath, base)))
|
|
474
499
|
count++
|
|
475
500
|
}
|
|
476
|
-
|
|
501
|
+
|
|
502
|
+
// 步骤 5:新 manifest = sourceSet(本版实际安装的文件名)
|
|
503
|
+
nextManifest[dstName] = [...sourceFiles]
|
|
504
|
+
|
|
505
|
+
vok(`${srcName}/ → ${dstPath} (${count} 个 .md upsert, ${pruned} 个过期清理, 第三方文件保留)`)
|
|
477
506
|
}
|
|
507
|
+
|
|
508
|
+
// 步骤 5(落盘):写新 manifest
|
|
509
|
+
ensureDir(path.join(targetRoot, "codeforge")) // 幂等,保证父目录存在
|
|
510
|
+
run(`write md manifest → ${MD_MANIFEST_REL}`, () => writeMdManifest(targetRoot, nextManifest))
|
|
478
511
|
}
|
|
479
512
|
|
|
480
513
|
function safeReaddir(p) {
|
|
@@ -485,6 +518,54 @@ function safeReaddir(p) {
|
|
|
485
518
|
}
|
|
486
519
|
}
|
|
487
520
|
|
|
521
|
+
// 读 manifest:不存在 / 解析失败 → 返回各目录空列表(首次安装走此分支)。
|
|
522
|
+
// 返回结构:{ [dstName]: string[] },含 MD_COPY_DIRS 的所有 dstName 键。
|
|
523
|
+
// 损坏 JSON 保守降级为"首次安装"(差集空 → 不误删)。
|
|
524
|
+
function readMdManifest(targetRoot) {
|
|
525
|
+
const empty = {}
|
|
526
|
+
for (const [, dstName] of MD_COPY_DIRS) empty[dstName] = []
|
|
527
|
+
const p = path.join(targetRoot, MD_MANIFEST_REL)
|
|
528
|
+
let raw
|
|
529
|
+
try {
|
|
530
|
+
raw = fs.readFileSync(p, "utf8")
|
|
531
|
+
} catch {
|
|
532
|
+
return empty // 文件不存在 → 首次安装
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
const parsed = JSON.parse(raw)
|
|
536
|
+
const out = {}
|
|
537
|
+
for (const [, dstName] of MD_COPY_DIRS) {
|
|
538
|
+
const v = parsed?.[dstName]
|
|
539
|
+
out[dstName] = Array.isArray(v) ? v.filter((x) => typeof x === "string") : []
|
|
540
|
+
}
|
|
541
|
+
return out
|
|
542
|
+
} catch {
|
|
543
|
+
return empty // 损坏的 manifest → 视为首次安装(保守:差集为空,不误删)
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// 写 manifest:atomicWriteJson(同目录 tmp + rename)。data 形如 { agents: [...], commands: [...] }。
|
|
548
|
+
// 调用方需保证 codeforge/ 目录已存在(installBundle 先于 installMdDirs 跑,已建 codeforge/)。
|
|
549
|
+
function writeMdManifest(targetRoot, data) {
|
|
550
|
+
const p = path.join(targetRoot, MD_MANIFEST_REL)
|
|
551
|
+
atomicWriteJson(p, data)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// 差集清理:prevList − sourceSet,仅删目标目录里确实存在的文件。返回清理计数。
|
|
555
|
+
// 第三方文件(如 teamkit-git.md)从不写入 manifest → 不在 prevList → 永不被删。
|
|
556
|
+
function pruneStale({ dstPath, prevList, sourceSet }) {
|
|
557
|
+
let pruned = 0
|
|
558
|
+
const actual = new Set(safeReaddir(dstPath))
|
|
559
|
+
for (const base of prevList) {
|
|
560
|
+
if (sourceSet.has(base)) continue // 本版仍发布 → 保留
|
|
561
|
+
if (!actual.has(base)) continue // 目标里已不存在 → 无需删
|
|
562
|
+
const stale = path.join(dstPath, base)
|
|
563
|
+
run(`rm ${stale}(过期 codeforge .md)`, () => fs.rmSync(stale, { force: true }))
|
|
564
|
+
pruned++
|
|
565
|
+
}
|
|
566
|
+
return pruned
|
|
567
|
+
}
|
|
568
|
+
|
|
488
569
|
function installCopyDirs({ targetRoot }) {
|
|
489
570
|
for (const [srcName, dstName] of COPY_DIRS) {
|
|
490
571
|
const srcPath = path.join(SOURCE_ROOT, srcName)
|
|
@@ -742,6 +823,9 @@ export {
|
|
|
742
823
|
LEGACY_DIRS,
|
|
743
824
|
MANAGED_DIRS,
|
|
744
825
|
OWNED_SKILLS,
|
|
826
|
+
readMdManifest,
|
|
827
|
+
writeMdManifest,
|
|
828
|
+
MD_MANIFEST_REL,
|
|
745
829
|
}
|
|
746
830
|
|
|
747
831
|
// main 守卫:仅作为脚本直接运行时执行
|