flow-comet 1.5.0-rc.3 → 1.5.1
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/reference/decision-points.md +2 -2
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +2 -2
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +8 -201
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +10 -1
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +98 -2
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +7 -4
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +3 -2
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +62 -0
- package/.flow-comet/skills/flow-comet-evolve/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +1 -1
- package/README.md +3 -3
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/prepare-env.mjs +49 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
1.5.
|
|
1
|
+
1.5.1
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|------|------|------|
|
|
9
9
|
| 用户决策 | ≥2 个会改变范围/行为/风险/不可逆结果的合法选项 | 用交互确认问(Claude Code 用 AskUserQuestion 优先;Codex 用文本提问+内联确认)或文本回退;相邻选择合并为一个问题,不重问已持久化选择 |
|
|
10
10
|
| 自动处理 | 唯一安全下一步 | 直接执行并汇报,不许制造确认 |
|
|
11
|
-
| 停止条件 | guard 失败 / 缺依赖 / 状态损坏 |
|
|
11
|
+
| 停止条件 | guard 失败 / 缺依赖 / 状态损坏 | 报告阻塞与恢复条件;存在多个会改变范围或风险的合法恢复动作时才升级为用户决策 |
|
|
12
12
|
| 手动交接 | `NEXT: manual`(若有) | 不是用户决策,直接继续 |
|
|
13
13
|
|
|
14
14
|
## 作者化决策点清单(按节点)
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
|
|
42
42
|
| 触发 | 处理 |
|
|
43
43
|
|------|------|
|
|
44
|
-
| Node guard 失败 |
|
|
44
|
+
| Node guard 失败 | 先自动诊断并执行唯一安全修复;无合法动作时报告停止条件;存在多个会改变范围或风险的合法恢复动作时才升级为用户决策 |
|
|
45
45
|
| 缺依赖 / 状态损坏无法继续 | 报告停止条件与恢复条件;恢复方式存在多个会改变范围或风险的合法选项时才升级为用户决策 |
|
|
46
46
|
|
|
47
47
|
### 手动交接(非用户决策)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
| 认证 dsh 版本 | `0.1.5-rc.1`(2026-09-10 全接缝运行时认证;历史锚 `0.1.0-rc.6` → `0.1.1-rc.2` 实测线) |
|
|
12
12
|
| 安装入口 | `node scripts/prepare-env.mjs --target <项目> --platform dsh`(或交互终端多选勾选 dsh)——唯一入口(D1) |
|
|
13
13
|
| 重置/重新生成(purge——删除后重建到完整安装态,**不是卸载**) | `node scripts/prepare-env.mjs --target <项目> --purge --platform dsh --yes` |
|
|
14
|
-
| npm 包 |
|
|
14
|
+
| npm 包 | **自 `1.5.0-rc.3` 起已发布**(`npm i -g flow-comet` → `fcomet init`,dist-tag `latest`)——分发的为**安装器**,非 dsh 插件包;旧 npm 插件包安装形态已废弃(verify 阶段推翻,见 ADR-005) |
|
|
15
15
|
| 破坏性变更 | dev-preview 中 `tools/pre-execute` 签名 / skill 发现 rank / `DSH_HOME` 语义可能变化;低于锚定版本时拦截/发现可能失效 |
|
|
16
16
|
|
|
17
17
|
> 版本不匹配时拦截可能失效——必须文档警示 + 级 3 实测兜底(D9)。
|
|
@@ -81,7 +81,7 @@ ctx.on('tools/pre-execute', async (exec, next) => {
|
|
|
81
81
|
### 激活(天然项目级)
|
|
82
82
|
|
|
83
83
|
- 目录物理存在即激活——dsh 启动自动发现 `/flow-comet`(rank 100,chokidar 热发现免重启);未安装该目录的项目不可见(无痕迹判定、无 chicken-and-egg)。
|
|
84
|
-
- dsh 对项目 AGENTS.md
|
|
84
|
+
- dsh 对项目 AGENTS.md 的注入行为**已认证**(0.1.5-rc.1 headless 会话:项目根 AGENTS.md 作为上下文注入,托管区内容被会话逐字引用——见下方认证记录);**边界**:认证面向 headless profile,dsh-tui / web 运行时未验。
|
|
85
85
|
|
|
86
86
|
### 重置/重新生成(prepare-env --purge --yes——删除后重建,**不是卸载**)
|
|
87
87
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { promises as fs, existsSync as fsExistsSync } from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import {
|
|
6
|
+
inspectWorkflowProtectedPath,
|
|
6
7
|
parseProtocolWriteWhitelist,
|
|
7
8
|
readProtocolFile,
|
|
9
|
+
readWorkflowProtectedFile,
|
|
8
10
|
resolveProtocol,
|
|
9
11
|
validateProtocolSchema,
|
|
12
|
+
workflowPathInside,
|
|
10
13
|
} from './protocol-utils.mjs';
|
|
11
14
|
// 运行时路径常量(单一来源:state-schema.mjs)——本脚本每次工具调用都会执行,故此处只 import
|
|
12
15
|
// 同包内的本地 ESM 模块(与已存在的 protocol-utils.mjs import 同型,实测无可感知开销);
|
|
@@ -397,206 +400,10 @@ const WORKFLOW_PROJECT_FILE_MAX_BYTES = 2 * 1024 * 1024;
|
|
|
397
400
|
// execute 的名单由 state.executionMode 动态收窄(subagent=协调者 .specs/;direct=逃生口允许主代理直写源码),
|
|
398
401
|
// 收窄规则对缺省/声明表同样生效,见 resolvePhaseWriteWhitelist()
|
|
399
402
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
(!path.isAbsolute(relative) &&
|
|
405
|
-
relative !== '..' &&
|
|
406
|
-
!relative.startsWith('..' + path.sep))
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
async function inspectWorkflowProtectedPath(
|
|
411
|
-
projectRoot,
|
|
412
|
-
target,
|
|
413
|
-
label,
|
|
414
|
-
expected = 'any',
|
|
415
|
-
) {
|
|
416
|
-
const lexicalRoot = path.resolve(projectRoot);
|
|
417
|
-
const lexicalTarget = path.resolve(target);
|
|
418
|
-
if (!workflowPathInside(lexicalRoot, lexicalTarget)) {
|
|
419
|
-
throw new Error(label + ' must stay inside the project root');
|
|
420
|
-
}
|
|
421
|
-
const rootStat = await fs.lstat(lexicalRoot);
|
|
422
|
-
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
423
|
-
throw new Error(label + ' project root must be a real directory');
|
|
424
|
-
}
|
|
425
|
-
const realRoot = await fs.realpath(lexicalRoot);
|
|
426
|
-
const relative = path.relative(lexicalRoot, lexicalTarget);
|
|
427
|
-
const segments = relative === '' ? [] : relative.split(path.sep);
|
|
428
|
-
let cursor = lexicalRoot;
|
|
429
|
-
for (let index = 0; index < segments.length; index++) {
|
|
430
|
-
cursor = path.join(cursor, segments[index]);
|
|
431
|
-
let stat;
|
|
432
|
-
try {
|
|
433
|
-
stat = await fs.lstat(cursor);
|
|
434
|
-
} catch (error) {
|
|
435
|
-
if (
|
|
436
|
-
error &&
|
|
437
|
-
typeof error === 'object' &&
|
|
438
|
-
(error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
439
|
-
) {
|
|
440
|
-
return { target: lexicalTarget, exists: false };
|
|
441
|
-
}
|
|
442
|
-
throw error;
|
|
443
|
-
}
|
|
444
|
-
const display = path.relative(lexicalRoot, cursor).replaceAll('\\', '/');
|
|
445
|
-
if (stat.isSymbolicLink()) {
|
|
446
|
-
throw new Error(label + ' crosses a symbolic link or junction at ' + display);
|
|
447
|
-
}
|
|
448
|
-
const final = index === segments.length - 1;
|
|
449
|
-
if (!final && !stat.isDirectory()) {
|
|
450
|
-
throw new Error(label + ' ancestor ' + display + ' must be a real directory');
|
|
451
|
-
}
|
|
452
|
-
if (
|
|
453
|
-
final &&
|
|
454
|
-
((expected === 'file' && !stat.isFile()) ||
|
|
455
|
-
(expected === 'directory' && !stat.isDirectory()) ||
|
|
456
|
-
(expected === 'any' && !stat.isFile() && !stat.isDirectory()))
|
|
457
|
-
) {
|
|
458
|
-
throw new Error(label + ' must be a real ' + expected);
|
|
459
|
-
}
|
|
460
|
-
const physical = await fs.realpath(cursor);
|
|
461
|
-
if (!workflowPathInside(realRoot, physical)) {
|
|
462
|
-
throw new Error(label + ' resolves outside the project root');
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return { target: lexicalTarget, exists: true };
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function workflowFileObjectIdentity(stat) {
|
|
469
|
-
return {
|
|
470
|
-
dev: stat.dev,
|
|
471
|
-
ino: stat.ino,
|
|
472
|
-
birthtime: typeof stat.birthtimeNs === 'bigint' ? stat.birthtimeNs : stat.birthtimeMs,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function workflowHasIdentity(value) {
|
|
477
|
-
return value !== 0 && value !== 0n && value !== '0';
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function workflowSameFileObject(left, right) {
|
|
481
|
-
const comparableDevice = workflowHasIdentity(left.dev) && workflowHasIdentity(right.dev);
|
|
482
|
-
const comparableInode = workflowHasIdentity(left.ino) && workflowHasIdentity(right.ino);
|
|
483
|
-
if (comparableDevice && left.dev !== right.dev) return false;
|
|
484
|
-
if (comparableInode && left.ino !== right.ino) return false;
|
|
485
|
-
if (comparableDevice && comparableInode) return true;
|
|
486
|
-
return left.birthtime === right.birthtime;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function workflowSameFileStat(left, right) {
|
|
490
|
-
return (
|
|
491
|
-
workflowSameFileObject(
|
|
492
|
-
workflowFileObjectIdentity(left),
|
|
493
|
-
workflowFileObjectIdentity(right),
|
|
494
|
-
) &&
|
|
495
|
-
left.size === right.size &&
|
|
496
|
-
left.ctimeNs === right.ctimeNs
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
async function readWorkflowProtectedFile(
|
|
501
|
-
projectRoot,
|
|
502
|
-
file,
|
|
503
|
-
label,
|
|
504
|
-
maxBytes,
|
|
505
|
-
hooks = {},
|
|
506
|
-
) {
|
|
507
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {
|
|
508
|
-
throw new Error(label + ' byte limit must be a positive integer');
|
|
509
|
-
}
|
|
510
|
-
const inspection = await inspectWorkflowProtectedPath(
|
|
511
|
-
projectRoot,
|
|
512
|
-
file,
|
|
513
|
-
label,
|
|
514
|
-
'file',
|
|
515
|
-
);
|
|
516
|
-
if (!inspection.exists) {
|
|
517
|
-
const error = new Error(label + ' does not exist');
|
|
518
|
-
error.code = 'ENOENT';
|
|
519
|
-
throw error;
|
|
520
|
-
}
|
|
521
|
-
const before = await fs.lstat(file, { bigint: true });
|
|
522
|
-
if (!before.isFile() || before.isSymbolicLink()) {
|
|
523
|
-
throw new Error(label + ' must be a real file');
|
|
524
|
-
}
|
|
525
|
-
if (before.size > BigInt(maxBytes)) {
|
|
526
|
-
throw new Error(label + ' exceeds ' + String(maxBytes) + ' bytes');
|
|
527
|
-
}
|
|
528
|
-
const beforeRealPath = await fs.realpath(file);
|
|
529
|
-
await hooks.afterLstat?.();
|
|
530
|
-
const flags =
|
|
531
|
-
process.platform === 'win32'
|
|
532
|
-
? fsConstants.O_RDONLY
|
|
533
|
-
: fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK;
|
|
534
|
-
let handle;
|
|
535
|
-
try {
|
|
536
|
-
handle = await fs.open(file, flags);
|
|
537
|
-
} catch (error) {
|
|
538
|
-
if (error && typeof error === 'object' && error.code === 'ELOOP') {
|
|
539
|
-
throw new Error(label + ' must be a real file');
|
|
540
|
-
}
|
|
541
|
-
throw error;
|
|
542
|
-
}
|
|
543
|
-
try {
|
|
544
|
-
const [opened, afterOpen, afterOpenRealPath] = await Promise.all([
|
|
545
|
-
handle.stat({ bigint: true }),
|
|
546
|
-
fs.lstat(file, { bigint: true }),
|
|
547
|
-
fs.realpath(file),
|
|
548
|
-
]);
|
|
549
|
-
if (
|
|
550
|
-
!opened.isFile() ||
|
|
551
|
-
!afterOpen.isFile() ||
|
|
552
|
-
afterOpen.isSymbolicLink() ||
|
|
553
|
-
afterOpenRealPath !== beforeRealPath ||
|
|
554
|
-
!workflowSameFileStat(before, opened) ||
|
|
555
|
-
!workflowSameFileStat(before, afterOpen)
|
|
556
|
-
) {
|
|
557
|
-
throw new Error(label + ' changed while opening');
|
|
558
|
-
}
|
|
559
|
-
await inspectWorkflowProtectedPath(projectRoot, file, label, 'file');
|
|
560
|
-
await hooks.afterOpen?.();
|
|
561
|
-
const chunks = [];
|
|
562
|
-
let total = 0;
|
|
563
|
-
const buffer = Buffer.allocUnsafe(Math.min(64 * 1024, maxBytes + 1));
|
|
564
|
-
for (;;) {
|
|
565
|
-
const remaining = maxBytes + 1 - total;
|
|
566
|
-
const { bytesRead } = await handle.read(
|
|
567
|
-
buffer,
|
|
568
|
-
0,
|
|
569
|
-
Math.min(buffer.length, remaining),
|
|
570
|
-
null,
|
|
571
|
-
);
|
|
572
|
-
if (bytesRead === 0) break;
|
|
573
|
-
total += bytesRead;
|
|
574
|
-
if (total > maxBytes) {
|
|
575
|
-
throw new Error(label + ' exceeds ' + String(maxBytes) + ' bytes');
|
|
576
|
-
}
|
|
577
|
-
chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
|
|
578
|
-
}
|
|
579
|
-
await hooks.beforeFinalCheck?.();
|
|
580
|
-
const [afterHandle, afterPath, afterRealPath] = await Promise.all([
|
|
581
|
-
handle.stat({ bigint: true }),
|
|
582
|
-
fs.lstat(file, { bigint: true }),
|
|
583
|
-
fs.realpath(file),
|
|
584
|
-
]);
|
|
585
|
-
if (
|
|
586
|
-
!afterPath.isFile() ||
|
|
587
|
-
afterPath.isSymbolicLink() ||
|
|
588
|
-
afterRealPath !== beforeRealPath ||
|
|
589
|
-
!workflowSameFileStat(before, afterHandle) ||
|
|
590
|
-
!workflowSameFileStat(before, afterPath)
|
|
591
|
-
) {
|
|
592
|
-
throw new Error(label + ' changed while reading');
|
|
593
|
-
}
|
|
594
|
-
await inspectWorkflowProtectedPath(projectRoot, file, label, 'file');
|
|
595
|
-
return Buffer.concat(chunks, total);
|
|
596
|
-
} finally {
|
|
597
|
-
await handle.close();
|
|
598
|
-
}
|
|
599
|
-
}
|
|
403
|
+
// 受保护路径三判据(workflowPathInside / inspectWorkflowProtectedPath /
|
|
404
|
+
// readWorkflowProtectedFile)与私有身份比较函数是 protocol-utils.mjs 的**单一来源**——
|
|
405
|
+
// 本文件此前各持一份逐字节相同的副本,两侧注释互指「同源」;副本已删除,改为 import
|
|
406
|
+
// (见文件头 import 列表)。改判据只需改 protocol-utils.mjs 一处。
|
|
600
407
|
|
|
601
408
|
function workflowRelativeSegments(value, label, allowWildcards = false) {
|
|
602
409
|
if (typeof value !== 'string') throw new Error(label + ' must be a string');
|
|
@@ -203,8 +203,17 @@ const CONTEXT_FORMAT_CHECKS = [
|
|
|
203
203
|
|
|
204
204
|
// 段名规范化:兼容「带 `## ` 前缀」(内置 fallback)与「不带前缀」(模板派生)两种来源,
|
|
205
205
|
// 并剥离模板标题的括注后缀(`已锁决策(ADR 摘要)` → `已锁决策`,与 deriveSections 同口径)。
|
|
206
|
+
// 第三项剥离 **ATX 闭合标记**(`## 名称 ##` 的尾部 `##`):它是合法 Markdown 语法,
|
|
207
|
+
// 不剥离时段名归一成 `名称 ##`,与模板段名不等 → 七段被整片判成缺失
|
|
208
|
+
// (INIT-VALIDATE-FAILED),依赖 CONTEXT 结构校验的正常路径被误阻断。
|
|
209
|
+
// 闭合标记按 CommonMark 收口:必须**前置空白**(故 `C#` 这类以井号结尾的段名不被误剥),
|
|
210
|
+
// 其后可跟空白。
|
|
206
211
|
function normalizeSectionName(name) {
|
|
207
|
-
return String(name ?? '')
|
|
212
|
+
return String(name ?? '')
|
|
213
|
+
.replace(/^#{1,6}\s*/, '')
|
|
214
|
+
.replace(/[((].*$/, '')
|
|
215
|
+
.replace(/[ \t]+#+[ \t]*$/, '')
|
|
216
|
+
.trim();
|
|
208
217
|
}
|
|
209
218
|
|
|
210
219
|
// 围栏代码块剥离:标题/格式判定的输入必须是「文档结构」,而代码示例里的 `## 段名` 只是示例文本。
|
|
@@ -3072,10 +3072,12 @@ const SCENARIOS = [
|
|
|
3072
3072
|
],
|
|
3073
3073
|
}, null, 2));
|
|
3074
3074
|
assertExit(runState(['init', CHANGE_ID, '--protocol', custom, '--init-skip'], dir), 0);
|
|
3075
|
-
// status:classic/native pathBase → fail-fast
|
|
3075
|
+
// status:classic/native pathBase → fail-fast 显式报错(不静默兜底)。
|
|
3076
|
+
// 措辞订正:guard 侧同样拒绝这三类 pathBase,故消息不再说「由 guard 校验支持」
|
|
3077
|
+
// (旧措辞会让人以为只有状态机推导缺支持)——断言随之锁新措辞。
|
|
3076
3078
|
const st = runState(['status', '--protocol', custom], dir);
|
|
3077
3079
|
assertExit(st, 1);
|
|
3078
|
-
assertOut(st, '
|
|
3080
|
+
assertOut(st, '已不受 guard 与状态机支持');
|
|
3079
3081
|
assertOut(st, 'specs-root');
|
|
3080
3082
|
},
|
|
3081
3083
|
},
|
|
@@ -7236,6 +7238,100 @@ const SCENARIOS = [
|
|
|
7236
7238
|
assertOut(notCommand, 'workflow-hook-guard-ok');
|
|
7237
7239
|
},
|
|
7238
7240
|
},
|
|
7241
|
+
|
|
7242
|
+
// 242: ATX 标题的**闭合标记**(`## 名称 ##`——合法 Markdown)须在段名归一中被剥离。
|
|
7243
|
+
// 不剥离时段名归一为 `名称 ##`,与模板段名不等 → 七段全判缺失 → INIT-VALIDATE-FAILED,
|
|
7244
|
+
// 依赖 CONTEXT 结构校验的流程被误阻断(记录扫描时间的正常路径走不通)。
|
|
7245
|
+
// 与场景 90(同夹具、无闭合标记)成对:唯一变量就是闭合标记本身。
|
|
7246
|
+
{
|
|
7247
|
+
name: '242 CONTEXT 段标题带 ATX 闭合标记 → 段存在判定通过(INIT-DONE)',
|
|
7248
|
+
run: (dir) => {
|
|
7249
|
+
writeFile(dir, '.specs/CONTEXT.md', [
|
|
7250
|
+
'# CONTEXT',
|
|
7251
|
+
'## 项目概要 ##', 'x',
|
|
7252
|
+
'## 技术栈 ##', 'x',
|
|
7253
|
+
'## 域语言 ##', '| 术语 | 定义 |', '|---|---|', '| 例 | 定义 |',
|
|
7254
|
+
'## 已锁决策 ##', '- [2026-08-01] 决策一',
|
|
7255
|
+
'## 默认偏好 ##', 'x',
|
|
7256
|
+
'## 既有抽象索引 ##', 'x',
|
|
7257
|
+
'## intel-scan 元数据 ##', '- **last_intel_scan**: x', '- **scanner**: x', '- **下次重扫建议**: x',
|
|
7258
|
+
'',
|
|
7259
|
+
].join('\n'));
|
|
7260
|
+
writeFile(dir, 'package.json', '{"name":"x"}');
|
|
7261
|
+
const res = runState(['init', CHANGE_ID, '--init-context'], dir, { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') });
|
|
7262
|
+
assertExit(res, 0);
|
|
7263
|
+
assertOut(res, 'INIT-DONE');
|
|
7264
|
+
const st = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
7265
|
+
if (!st.last_intel_scan) throw new Error('闭合标记形态应通过段存在判定并写 last_intel_scan');
|
|
7266
|
+
// ② 闭合标记须**前置空白**(CommonMark 语义):`## 项目概要#` 不是闭合形态,段名即
|
|
7267
|
+
// `项目概要#`——它不得被剥成 `项目概要`(否则缺段被假判为存在)。这条边界锁住剥离
|
|
7268
|
+
// 范围:将来把前置空白放宽成「任意位置」,此处即变红。
|
|
7269
|
+
writeFile(dir, '.specs/CONTEXT.md', [
|
|
7270
|
+
'# CONTEXT',
|
|
7271
|
+
'## 项目概要#', 'x',
|
|
7272
|
+
'## 技术栈 ##', 'x',
|
|
7273
|
+
'## 域语言 ##', '| 术语 | 定义 |', '|---|---|', '| 例 | 定义 |',
|
|
7274
|
+
'## 已锁决策 ##', '- [2026-08-01] 决策一',
|
|
7275
|
+
'## 默认偏好 ##', 'x',
|
|
7276
|
+
'## 既有抽象索引 ##', 'x',
|
|
7277
|
+
'## intel-scan 元数据 ##', '- **last_intel_scan**: x', '- **scanner**: x', '- **下次重扫建议**: x',
|
|
7278
|
+
'',
|
|
7279
|
+
].join('\n'));
|
|
7280
|
+
const boundary = runState(['init', CHANGE_ID + '-2', '--init-context'], dir, { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') });
|
|
7281
|
+
assertExit(boundary, 0);
|
|
7282
|
+
assertOut(boundary, 'INIT-VALIDATE-FAILED');
|
|
7283
|
+
assertOut(boundary, '项目概要');
|
|
7284
|
+
},
|
|
7285
|
+
},
|
|
7286
|
+
|
|
7287
|
+
// 243: `.gitignore` 读取的**访问类故障**(非「确实不存在」)不得当作「文件缺失」。
|
|
7288
|
+
// 当作缺失时 existing='' 且 fileExists=false → 后续 writeFileSync 用默认 flag 'w' 把用户既有
|
|
7289
|
+
// .gitignore **截断**为仅含受管条目(数据破坏);而该调用的自述契约是「失败即中止,可重跑自愈」。
|
|
7290
|
+
// 修复后访问类故障原样抛出 → 安装中止且用户文件逐字节不变(与 lstatIfExists 同语义)。
|
|
7291
|
+
// 故障注入用 `--require` 预加载(同场景 233 手法),只命中该项目的 .gitignore,其余读取走真实实现。
|
|
7292
|
+
{
|
|
7293
|
+
name: '243 .gitignore 读取访问类故障 → 中止安装且用户文件不被改写',
|
|
7294
|
+
run: (dir) => {
|
|
7295
|
+
if (!fs.existsSync(PREPARE_ENV)) return;
|
|
7296
|
+
const proj = path.join(dir, 'proj-gitignore-fault');
|
|
7297
|
+
fs.mkdirSync(proj, { recursive: true });
|
|
7298
|
+
const initial = '# 用户既有内容\nnode_modules/\ndist/\n';
|
|
7299
|
+
fs.writeFileSync(path.join(proj, '.gitignore'), initial, 'utf8');
|
|
7300
|
+
const preloadName = 'gitignore-read-fault-preload.cjs';
|
|
7301
|
+
writeFile(dir, preloadName, [
|
|
7302
|
+
"const fs = require('node:fs');",
|
|
7303
|
+
"const path = require('node:path');",
|
|
7304
|
+
"const target = path.resolve(String(process.env.GITIGNORE_FAULT_TARGET || ''));",
|
|
7305
|
+
'const realReadFileSync = fs.readFileSync;',
|
|
7306
|
+
'fs.readFileSync = function (file, ...rest) {',
|
|
7307
|
+
" if (target !== '' && path.resolve(String(file)) === target) {",
|
|
7308
|
+
" const error = new Error('EACCES: permission denied, open ' + JSON.stringify(String(file)));",
|
|
7309
|
+
" error.code = 'EACCES';",
|
|
7310
|
+
' throw error;',
|
|
7311
|
+
' }',
|
|
7312
|
+
' return realReadFileSync.call(fs, file, ...rest);',
|
|
7313
|
+
'};',
|
|
7314
|
+
'',
|
|
7315
|
+
].join('\n'));
|
|
7316
|
+
const spawned = spawnSync(
|
|
7317
|
+
process.execPath,
|
|
7318
|
+
['--require', path.join(dir, preloadName), PREPARE_ENV, '--target', proj, '--platform', 'claude-code'],
|
|
7319
|
+
{
|
|
7320
|
+
cwd: dir,
|
|
7321
|
+
env: { ...process.env, GITIGNORE_FAULT_TARGET: path.join(proj, '.gitignore') },
|
|
7322
|
+
encoding: 'utf8',
|
|
7323
|
+
timeout: 120000,
|
|
7324
|
+
},
|
|
7325
|
+
);
|
|
7326
|
+
const res = { status: spawned.status ?? 1, output: String(spawned.stdout || '') + String(spawned.stderr || '') };
|
|
7327
|
+
const after = fs.readFileSync(path.join(proj, '.gitignore'), 'utf8');
|
|
7328
|
+
if (after !== initial) {
|
|
7329
|
+
throw new Error('访问类故障下用户 .gitignore 被改写(应原样保留):\n' + JSON.stringify({ initial, after }, null, 2));
|
|
7330
|
+
}
|
|
7331
|
+
if (res.status === 0) throw new Error('读取访问类故障应中止安装(exit 非 0),实际 exit 0\n' + res.output);
|
|
7332
|
+
assertOut(res, 'EACCES');
|
|
7333
|
+
},
|
|
7334
|
+
},
|
|
7239
7335
|
];
|
|
7240
7336
|
|
|
7241
7337
|
// ---------- 运行 ----------
|
|
@@ -20,9 +20,12 @@ import path from 'path';
|
|
|
20
20
|
|
|
21
21
|
export const WORKFLOW_PROTOCOL_MAX_BYTES = 2 * 1024 * 1024;
|
|
22
22
|
|
|
23
|
-
// ----------
|
|
23
|
+
// ---------- 受保护文件读取(单一来源:写入守卫 import 本模块,全包共用同一份实现) ----------
|
|
24
|
+
// 这三个判据曾以逐字节相同的副本存在于 comet-hook-guard.mjs,两侧注释互指「同源」——
|
|
25
|
+
// 注释不是同步机制,副本必然分叉。现由本模块导出、守卫 import:
|
|
26
|
+
// 改一处即全改,消除「修了这份、漏了那份」的缺陷面。
|
|
24
27
|
|
|
25
|
-
function workflowPathInside(root, target) {
|
|
28
|
+
export function workflowPathInside(root, target) {
|
|
26
29
|
const relative = path.relative(root, target);
|
|
27
30
|
return (
|
|
28
31
|
relative === '' ||
|
|
@@ -32,7 +35,7 @@ function workflowPathInside(root, target) {
|
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
async function inspectWorkflowProtectedPath(
|
|
38
|
+
export async function inspectWorkflowProtectedPath(
|
|
36
39
|
projectRoot,
|
|
37
40
|
target,
|
|
38
41
|
label,
|
|
@@ -122,7 +125,7 @@ function workflowSameFileStat(left, right) {
|
|
|
122
125
|
);
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
async function readWorkflowProtectedFile(
|
|
128
|
+
export async function readWorkflowProtectedFile(
|
|
126
129
|
projectRoot,
|
|
127
130
|
file,
|
|
128
131
|
label,
|
|
@@ -39,7 +39,7 @@ function buildNodeCompletionFlags(protocol, changeName) {
|
|
|
39
39
|
|| artifact.pathBase === 'classic-superpowers-root'
|
|
40
40
|
|| artifact.pathBase === 'native-root') {
|
|
41
41
|
throw new Error('产物根 pathBase "' + artifact.pathBase
|
|
42
|
-
+ '"
|
|
42
|
+
+ '" 已不受 guard 与状态机支持——请改用 specs-root/project + 完整路径(如 project + openspec/changes/xxx.md)');
|
|
43
43
|
}
|
|
44
44
|
artifacts.push({
|
|
45
45
|
id: schemaId + '.' + (artifact.id ?? 'artifact'),
|
|
@@ -86,7 +86,8 @@ async function pathPatternExists(root, relativePattern) {
|
|
|
86
86
|
// 产物推导 pathBase 感知: 产物根按 artifact.pathBase 解析——'specs-root' → specsRoot;'project'/缺省 → runRoot
|
|
87
87
|
// (与 workflow-guard.mjs 的 workflowPathBaseRoot 对齐:内置协议 10 个 artifacts 全部显式
|
|
88
88
|
// 声明 specs-root;compose 自定义协议可声明 project 根工件如 README.md)。
|
|
89
|
-
// classic/native
|
|
89
|
+
// classic/native 三类不属于二分——标志构建阶段即 fail-fast 拒绝(见上方 artifact 循环),
|
|
90
|
+
// 走不到这里,故此处无需为它们兜底。
|
|
90
91
|
async function nodeFlagsComplete(nodeFlags, nodeId, specsRoot, runRoot) {
|
|
91
92
|
for (const artifact of nodeFlags.get(nodeId) ?? []) {
|
|
92
93
|
let present = false;
|
|
@@ -569,6 +569,68 @@ function assertInitTokenContract(installer, cwd) {
|
|
|
569
569
|
throw new Error('变形/重复词元 `' + bad + '` 的 stderr 应含「未知参数」,实际:\n' + res.stderr);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
|
+
// ⑤ 版本查询:`--version` / `-v` 退 0 且输出本工具的版本标识(同一个解析来源,不另设常量)。
|
|
573
|
+
// 断言做成**状态无关**,因为「版本面已 bump、tag 尚未打」是发布准备的常态:此时随包标记
|
|
574
|
+
// 领先于 git describe(标记 = 待发版本,describe = 旧 tag + 提交数)。两条合法来源:
|
|
575
|
+
// ① 随包分发的权威源标记(包形态 / 发布后命中);② 当前 tag 的开发态后缀 `<tag>-N-g<hash>`。
|
|
576
|
+
// 等值断言会在发布准备期误红——那不是缺陷,是顺序(先改版本面、后打 tag)。
|
|
577
|
+
const versionShape = /^\d+\.\d+\.\d+(-[0-9A-Za-z][0-9A-Za-z.-]*)?$/;
|
|
578
|
+
const installedVersion = fs.readFileSync(path.join(__dirname, '..', 'INSTALLED_VERSION'), 'utf8').trim();
|
|
579
|
+
let headTag = '';
|
|
580
|
+
try {
|
|
581
|
+
const repoRoot = path.resolve(__dirname, '..', '..', '..', '..');
|
|
582
|
+
headTag = execFileSync('git', ['describe', '--tags', '--abbrev=0'], { cwd: repoRoot, encoding: 'utf8', timeout: 30000 }).trim().replace(/^v/, '');
|
|
583
|
+
} catch { /* 无 git 或无 tag:只按随包标记比对 */ }
|
|
584
|
+
for (const flag of ['--version', '-v']) {
|
|
585
|
+
const res = runInstaller([flag]);
|
|
586
|
+
if (res.status !== 0) {
|
|
587
|
+
throw new Error('`' + flag + '` 应退 0(版本查询不是错误),实际 ' + res.status + '\n' + res.stderr);
|
|
588
|
+
}
|
|
589
|
+
const printed = res.stdout.trim();
|
|
590
|
+
if (!versionShape.test(printed)) {
|
|
591
|
+
throw new Error('`' + flag + '` 的输出不是版本标识形态: ' + JSON.stringify(printed));
|
|
592
|
+
}
|
|
593
|
+
// 等值、或**以「版本 + `-`」为界**的开发态后缀——不能裸用前缀匹配:`1.5.10` 会被
|
|
594
|
+
// `startsWith('1.5.1')` 收下,把「族外的更长版本号」误判为一致(实测:注入 1.5.10 时
|
|
595
|
+
// 裸前缀谓词全绿通过)。边界字符取 `-`,正合 git describe 的后缀形态 `<tag>-N-g<hash>`。
|
|
596
|
+
const matchesMarker = printed === installedVersion || printed.startsWith(installedVersion + '-');
|
|
597
|
+
const matchesHeadTag = headTag !== '' && (printed === headTag || printed.startsWith(headTag + '-'));
|
|
598
|
+
if (!matchesMarker && !matchesHeadTag) {
|
|
599
|
+
throw new Error('`' + flag + '` 的输出与「随包标记 / 当前 tag」都不一致(标记=' + installedVersion + ' tag=' + headTag + '): ' + JSON.stringify(printed));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
console.log(' 版本查询: `--version` / `-v` 退 0 且输出为版本标识形态(标记=' + installedVersion + ' / 当前 tag=' + headTag + ')✓');
|
|
603
|
+
// ⑥ 零参数裸调用不得安装到当前目录(本轮修正):无参数 = 没说要做什么,
|
|
604
|
+
// 应当在当前目录留下零产物并给出用法与非零退出码。修复前它会做一次完整安装
|
|
605
|
+
// (.claude/ + flow-kit/ + 改写 .gitignore)→ 误敲即在当前目录铺开一套环境。
|
|
606
|
+
const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'no-action-'));
|
|
607
|
+
try {
|
|
608
|
+
seedForeignFlowKit(emptyDir); // 预置同名非上游目录:走「已跳过」路径,零网络接触
|
|
609
|
+
const bareRun = spawnSync(process.execPath, [installer], { cwd: emptyDir, encoding: 'utf8', timeout: 60000 });
|
|
610
|
+
const status = bareRun.status ?? 1;
|
|
611
|
+
const stderr = String(bareRun.stderr || '');
|
|
612
|
+
if (status === 0) {
|
|
613
|
+
throw new Error('零参数裸调用不得退 0(它做了/声称做了一次安装);实际退 0\n' + String(bareRun.stdout || '').slice(-300));
|
|
614
|
+
}
|
|
615
|
+
if (!stderr.includes('用法')) {
|
|
616
|
+
throw new Error('零参数裸调用的 stderr 应给出用法,实际:\n' + stderr);
|
|
617
|
+
}
|
|
618
|
+
// 用法必须**整段**在 stderr:只断言「stderr 含用法」会漏掉「部分行仍写 stdout」的实现
|
|
619
|
+
// (首行在 stderr 即满足该断言,其余行可能被劈到 stdout——实测出现过)。故此处两侧同判:
|
|
620
|
+
// stderr 末尾行在场,且 stdout 为空。
|
|
621
|
+
if (!/--version 打印版本标识/.test(stderr)) {
|
|
622
|
+
throw new Error('用法末行不在 stderr(用法输出被劈到 stdout):stderr 实际:\n' + stderr);
|
|
623
|
+
}
|
|
624
|
+
if (String(bareRun.stdout || '').trim() !== '') {
|
|
625
|
+
throw new Error('零参数裸调用的 stdout 应为空(用法整段走 stderr),实际:\n' + String(bareRun.stdout));
|
|
626
|
+
}
|
|
627
|
+
if (fs.existsSync(path.join(emptyDir, '.claude'))) {
|
|
628
|
+
throw new Error('零参数裸调用不得在当前目录留下安装产物(.claude/ 被创建)');
|
|
629
|
+
}
|
|
630
|
+
console.log(' 零参数裸调用: 非零退出 + 用法整段在 stderr + stdout 空 + 当前目录零产物 ✓');
|
|
631
|
+
} finally {
|
|
632
|
+
fs.rmSync(emptyDir, { recursive: true, force: true });
|
|
633
|
+
}
|
|
572
634
|
console.log(' init 词元: `init --help` 退 0 且含 fcomet init / 裸形态行为不变 / 变形·重复词元 4 例退 1 且报未知参数 ✓');
|
|
573
635
|
}
|
|
574
636
|
|
|
@@ -7,7 +7,7 @@ description: "Use only when explicitly invoked as /flow-comet-evolve; scan archi
|
|
|
7
7
|
|
|
8
8
|
## 触发
|
|
9
9
|
|
|
10
|
-
用户说「同步架构 / 整理沉淀 / evolve / 同步 CONTEXT
|
|
10
|
+
用户说「同步架构 / 整理沉淀 / evolve / 同步 CONTEXT」;若 STATE.md 的 last_evolve_at 已超过 60 天,则**提示用户显式调用 `/flow-comet-evolve`**,不自动加载本 Skill(时间戳是提醒,不是与用户意图并列的触发条件——本命令只按显式调用与用户意图触发)。
|
|
11
11
|
|
|
12
12
|
> **载体说明(沿用 flow-kit 约定)**:`STATE.md` 与 `last_evolve_at` 是 flow-kit 的约定(A-evolve.md 定义:GO.md 按 last_evolve_at 提示、evolve 读/写该字段)——项目需有按 flow-kit 维护的 STATE.md;flow-comet 引擎不自动创建/维护该字段,无 STATE.md 的项目触发本命令时按「无 last_evolve_at 基线」处理(扫描全部未沉淀的归档 change 并人工确认)。
|
|
13
13
|
|
|
@@ -96,7 +96,7 @@ guard 校验见 workflow-guard.mjs NODE_TRANSITION_GATES / W1-B;「填得好
|
|
|
96
96
|
- `[已修]` — fixed via a fix task (linked in the entry)
|
|
97
97
|
- `[升级]` — escalated to the user for a decision (accept + reason recorded)
|
|
98
98
|
- `[转待办]` — deferred to `.specs/<change-id>/KNOWN-ISSUES.md` at archive time
|
|
99
|
-
The exit guard structurally checks these markers on the findings area
|
|
99
|
+
The exit guard structurally checks these markers on the findings area: a missing marker **blocks** the exit for a new change, and is a non-blocking warning for a legacy change (to avoid deadlocking legacy reviews). Add markers to clear it.
|
|
100
100
|
|
|
101
101
|
The full review protocol, templates, and checklists are in:
|
|
102
102
|
- `flow-kit/prompts/6-review.md` (REVIEW phase)
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
<p align="center">
|
|
29
29
|
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node.js_%E2%89%A518-339933?style=flat&logo=node.js&logoColor=white" alt="Node.js 18+" /></a>
|
|
30
30
|
<a href="https://github.com/baobaolaodie/flow-comet/actions"><img src="https://img.shields.io/github/actions/workflow/status/baobaolaodie/flow-comet/ci.yml?style=flat" alt="CI" /></a>
|
|
31
|
-
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/version-1.5.
|
|
31
|
+
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/version-1.5.1-blue.svg" alt="Version" /></a>
|
|
32
32
|
</p>
|
|
33
33
|
|
|
34
34
|
---
|
|
@@ -56,7 +56,7 @@ cd <your project>
|
|
|
56
56
|
fcomet init
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
The package ships two command names pointing at the same installer — `fcomet` (primary) and `flow-comet` (alias). The `init` token is optional
|
|
59
|
+
The package ships two command names pointing at the same installer — `fcomet` (primary) and `flow-comet` (alias). The `init` token is optional whenever another argument expresses the intent (`fcomet --target <dir>` is equivalent to `fcomet init --target <dir>`), and `--target <dir>` is optional too (default: the current working directory); run with no arguments at all, the command prints its usage and exits non-zero instead of installing. `fcomet --version` prints the version of the installed CLI. Re-running the same command updates an existing install and is idempotent.
|
|
60
60
|
|
|
61
61
|
On an interactive terminal, the first run prompts for the platform with a direction-key multi-select (arrow keys + space to toggle, Enter to confirm; the default is Claude Code) — `@clack/prompts` is the primary path, with an automatic readline number/comma multi-select fallback when the dependency is not installed, offline, or stdin has no raw mode (`FLOW_COMET_FORCE_READLINE=1` forces the fallback for testing); for a non-interactive pick, add `--platform codex` / `--platform dsh` / `--platform claude-code,dsh` (comma-separated) / `--platform all`.
|
|
62
62
|
|
|
@@ -243,7 +243,7 @@ Full guide in [CONTRIBUTING.md](CONTRIBUTING.md) — branch model (`feature →
|
|
|
243
243
|
|
|
244
244
|
1. Branch from `dev`: `git checkout dev && git checkout -b feat/<description>`
|
|
245
245
|
2. Edit skills/scripts under `.flow-comet/skills/` (authoritative source); TDD with RED scenario first
|
|
246
|
-
3. Run regression: `node .flow-comet/skills/flow-comet/scripts/guard-self-test.mjs` → `ALL
|
|
246
|
+
3. Run regression: `node .flow-comet/skills/flow-comet/scripts/guard-self-test.mjs` → `ALL 243 SCENARIOS PASSED`
|
|
247
247
|
4. Open a PR into `dev` (squash — one change-level commit); release PR `dev → main` (merge — dev's change-level commits enter main, and dev stops leading after each release)
|
|
248
248
|
|
|
249
249
|
CI enforces the repository conventions automatically on every PR and push (regression, PR discipline, version consistency, dead links). Local hooks (commit/push message checks) install with `node scripts/install-commit-hook.mjs` — see [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-comet",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "An automated execution engine that turns AI coding discipline into a verifiable state machine for the flow-kit 9-stage workflow, built for Claude Code, Codex, and DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
package/scripts/dsh-bridge.mjs
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// 纯 ESM、零第三方依赖,仅使用 Node.js 内置模块。dsh 官方插件形态:
|
|
29
29
|
// ESM 模块导出 { name, apply },ctx 由 dsh 注入。
|
|
30
30
|
//
|
|
31
|
-
// BRIDGE_VERSION: 1.5.
|
|
31
|
+
// BRIDGE_VERSION: 1.5.1
|
|
32
32
|
|
|
33
33
|
import { spawn } from 'node:child_process';
|
|
34
34
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
@@ -40,7 +40,7 @@ import path from 'node:path';
|
|
|
40
40
|
// 值语义 = 当前发布版本(随发布同步更新,与技能包 INSTALLED_VERSION 同值——
|
|
41
41
|
// bridge-check 的版本一致性检查据此判定 loader 与项目副本同版)。
|
|
42
42
|
export const name = 'dsh-flow-comet-bridge';
|
|
43
|
-
export const version = '1.5.
|
|
43
|
+
export const version = '1.5.1';
|
|
44
44
|
|
|
45
45
|
// guard 在项目内的相对路径常量(随 skill 包分发)。
|
|
46
46
|
const HOOK_GUARD_REL = '.dsh/skills/flow-comet/scripts/comet-hook-guard.mjs';
|
package/scripts/prepare-env.mjs
CHANGED
|
@@ -355,6 +355,15 @@ function parseArgs(argv) {
|
|
|
355
355
|
let purge = false;
|
|
356
356
|
let yes = false;
|
|
357
357
|
let platform = null;
|
|
358
|
+
// 零参数 = 没说要做什么:**不安装**,打印用法并非零退出。
|
|
359
|
+
// 修复前它等价于 `fcomet init`(在 cwd 做一次完整安装:建 .claude/、拉 flow-kit/、改写 .gitignore)
|
|
360
|
+
// ——误敲或试探性执行会在当前目录铺开一套环境。`init` 词元仍可选:`fcomet --target X`
|
|
361
|
+
// 与 `fcomet init --target X` 等价(有参数即表达了意图)。
|
|
362
|
+
if (args.length === 0) {
|
|
363
|
+
console.error('[prepare-env] 未指定任何参数——裸执行不安装。');
|
|
364
|
+
printUsage((line) => console.error(line));
|
|
365
|
+
process.exit(1);
|
|
366
|
+
}
|
|
358
367
|
// 命令形态容忍(npm bin 形态 `fcomet init`):包管理器垫片把 `init` 当位置词元传给脚本。
|
|
359
368
|
// 只吃掉**一个**精确等于 `init` 且位于位置参数首位的词元(其前只允许选项词元);
|
|
360
369
|
// 其它非 `--` 开头词元仍按既有语义报「未知参数」——变形词元(如 `int`/`inti`)
|
|
@@ -385,6 +394,11 @@ function parseArgs(argv) {
|
|
|
385
394
|
} else if (a === '--help' || a === '-h') {
|
|
386
395
|
printUsage();
|
|
387
396
|
process.exit(0);
|
|
397
|
+
} else if (a === '--version' || a === '-v') {
|
|
398
|
+
// 版本查询:输出本工具的版本标识(与随包分发、写入目标项目的是同一来源——
|
|
399
|
+
// 见 resolveInstalledVersion;单一来源,不另设版本常量)。
|
|
400
|
+
console.log(resolveInstalledVersion() || 'unknown');
|
|
401
|
+
process.exit(0);
|
|
388
402
|
} else {
|
|
389
403
|
throw new Error(`未知参数: ${a}`);
|
|
390
404
|
}
|
|
@@ -392,15 +406,18 @@ function parseArgs(argv) {
|
|
|
392
406
|
return { target: target ? path.resolve(target) : process.cwd(), purge, yes, platform };
|
|
393
407
|
}
|
|
394
408
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
409
|
+
// 用法输出:默认写 stdout(--help);出错时由调用方传入 stderr 写入函数(用法错误走 stderr)。
|
|
410
|
+
function printUsage(write = console.log) {
|
|
411
|
+
write('用法: fcomet init [--target <dir>] [--platform <claude-code|codex|dsh|claude-code,dsh|all>] [--purge --yes]');
|
|
412
|
+
write(' (`fcomet` 与 `flow-comet` 是同一安装器的两个命令名;`init` 词元可省略——`fcomet --target X`');
|
|
413
|
+
write(' 等价于 `fcomet init --target X`;不带任何参数时不安装,只打印本用法)');
|
|
414
|
+
write(' 仓库内直调: node scripts/prepare-env.mjs [--target <dir>] [--platform <...>] [--purge --yes]');
|
|
415
|
+
write(' 从权威源 .flow-comet/ 安装/更新 <dir> 环境(含运行时位置迁移与 .gitignore 纳管)');
|
|
416
|
+
write(' --target 缺省 = 当前工作目录(cwd)');
|
|
417
|
+
write(' --platform 指定平台(claude-code / codex / dsh;逗号分隔多选或 all 全部平台)');
|
|
418
|
+
write(' 缺省 = TTY 交互多选(@clack/prompts,未安装回退 readline)> 探测目标项目 > 默认 claude-code');
|
|
419
|
+
write(' --purge 破坏性:先删除目标平台生成物再重新生成(默认不删除;需 --yes 确认)');
|
|
420
|
+
write(' --version 打印版本标识(等价 -v);--help 打印本用法');
|
|
404
421
|
}
|
|
405
422
|
|
|
406
423
|
// 探测目标项目既有平台痕迹(三痕迹,一次计算复用于探测 / TTY 预勾选 / 多痕迹判定):
|
|
@@ -607,20 +624,30 @@ function applyPathReplacements(root, replacements) {
|
|
|
607
624
|
// ---------- 运行时文件位置迁移(旧命名空间 .comet/ → 新命名空间 .flow-comet/) ----------
|
|
608
625
|
|
|
609
626
|
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
627
|
+
* 「该路径确实不存在」一类错误的单一判定(迁移探测与 gitignore 纳管共用同一判据——
|
|
628
|
+
* 同一语义只有一处实现,改一处即全改,不会分叉):
|
|
612
629
|
* - ENOENT:路径缺失;
|
|
613
630
|
* - ENOTDIR:路径中某一段不是目录——该路径不可能存在为文件(跨平台等价于「不存在」:
|
|
614
631
|
* 同一形态在 Windows 报 ENOENT、在 POSIX 报 ENOTDIR)。
|
|
615
|
-
* 其余错误(EACCES / EPERM / EIO
|
|
616
|
-
*
|
|
617
|
-
*
|
|
632
|
+
* 其余错误(EACCES / EPERM / EIO 等访问类故障)**不算**「不存在」——把访问故障当成
|
|
633
|
+
* 「文件不存在」会让调用方按空内容继续(迁移静默跳过 / gitignore 被截断覆盖),
|
|
634
|
+
* 都是静默的数据丢失风险,必须原样抛出并中止。
|
|
635
|
+
*/
|
|
636
|
+
function isMissingPathError(err) {
|
|
637
|
+
return Boolean(err) && typeof err === 'object' && (err.code === 'ENOENT' || err.code === 'ENOTDIR');
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* lstat 探测:返回 stat 或 null(**不跟随符号链接**——isSymbolicLink() 判定依赖 lstat)。
|
|
642
|
+
* 只有「该路径确实不存在」一类错误返回 null(判定见 isMissingPathError);其余错误原样抛出——
|
|
643
|
+
* 迁移静默跳过会让安装照常继续并报告「已跳过:旧位置不存在」,用户的旧状态却永远留在旧位置
|
|
644
|
+
* (用户以为已迁移)。
|
|
618
645
|
*/
|
|
619
646
|
function lstatIfExists(target) {
|
|
620
647
|
try {
|
|
621
648
|
return fs.lstatSync(target);
|
|
622
649
|
} catch (err) {
|
|
623
|
-
if (
|
|
650
|
+
if (isMissingPathError(err)) {
|
|
624
651
|
return null;
|
|
625
652
|
}
|
|
626
653
|
throw err;
|
|
@@ -807,8 +834,13 @@ function manageGitignore(target) {
|
|
|
807
834
|
try {
|
|
808
835
|
existing = fs.readFileSync(gitignorePath, 'utf8');
|
|
809
836
|
fileExists = true;
|
|
810
|
-
} catch {
|
|
811
|
-
|
|
837
|
+
} catch (err) {
|
|
838
|
+
// 只有「确实不存在」才是首次纳管;访问类故障(EACCES/EPERM/EIO…)必须原样抛出中止——
|
|
839
|
+
// 按空内容继续会让下面的写回把用户既有 .gitignore **截断**为仅含受管条目
|
|
840
|
+
// (判定语义见 isMissingPathError;调用点契约即「失败即中止,可重跑自愈」)。
|
|
841
|
+
if (!isMissingPathError(err)) {
|
|
842
|
+
throw err;
|
|
843
|
+
}
|
|
812
844
|
}
|
|
813
845
|
if (existing.split(/\r?\n/).some(isRuntimeDirIgnoreLine)) {
|
|
814
846
|
console.log(`[prepare-env] .gitignore 已含 ${RUNTIME_DIR}/ 条目——保持原样(幂等)`);
|