flow-comet 1.5.0 → 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.
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.5.1
@@ -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
 
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.0-blue.svg" alt="Version" /></a>
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 (a bare `fcomet` is equivalent) and `--target <dir>` is optional too (default: the current working directory). Re-running the same command updates an existing install and is idempotent.
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-comet",
3
- "version": "1.5.0",
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": [
@@ -28,7 +28,7 @@
28
28
  // 纯 ESM、零第三方依赖,仅使用 Node.js 内置模块。dsh 官方插件形态:
29
29
  // ESM 模块导出 { name, apply },ctx 由 dsh 注入。
30
30
  //
31
- // BRIDGE_VERSION: 1.5.0
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.0';
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';
@@ -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
- function printUsage() {
396
- console.log('用法: fcomet init [--target <dir>] [--platform <claude-code|codex|dsh|claude-code,dsh|all>] [--purge --yes]');
397
- console.log(' (`fcomet` 与 `flow-comet` 是同一安装器的两个命令名;`init` 词元可省略——裸 `fcomet` 等价)');
398
- console.log(' 仓库内直调: node scripts/prepare-env.mjs [--target <dir>] [--platform <...>] [--purge --yes]');
399
- console.log(' 从权威源 .flow-comet/ 安装/更新 <dir> 环境(含运行时位置迁移与 .gitignore 纳管)');
400
- console.log(' --target 缺省 = 当前工作目录(cwd)');
401
- console.log(' --platform 指定平台(claude-code / codex / dsh;逗号分隔多选或 all 全部平台)');
402
- console.log(' 缺省 = TTY 交互多选(@clack/prompts,未安装回退 readline)> 探测目标项目 > 默认 claude-code');
403
- console.log(' --purge 破坏性:先删除目标平台生成物再重新生成(默认不删除;需 --yes 确认)');
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 预勾选 / 多痕迹判定):