@jahanxu/code-flow 0.1.0 → 0.2.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,71 @@
1
+ # cf-validate
2
+
3
+ 根据变更文件自动匹配并执行验证规则(测试、类型检查、lint),失败时自动尝试修复。
4
+
5
+ ## 输入
6
+
7
+ - `/project:cf-validate` — 基于 git diff 自动获取变更文件
8
+ - `/project:cf-validate src/Foo.tsx` — 验证指定文件
9
+ - `/project:cf-validate --files=src/a.ts,src/b.ts` — 验证多个文件
10
+
11
+ ## 执行步骤
12
+
13
+ ### 1. 获取变更文件列表
14
+
15
+ 用 Bash 执行:
16
+
17
+ ```bash
18
+ git diff --name-only HEAD
19
+ ```
20
+
21
+ 如果用户指定了文件路径,使用用户指定的文件。如果无变更文件,输出"无变更需要验证"。
22
+
23
+ ### 2. 读取验证规则
24
+
25
+ 用 Read 读取 `.code-flow/validation.yml`。如果不存在,尝试读取 `package.json` 中的 `scripts.test` 和 `scripts.lint` 作为回退。
26
+
27
+ validation.yml 格式:
28
+
29
+ ```yaml
30
+ validators:
31
+ - name: "验证器名称"
32
+ trigger: "**/*.{ts,tsx}"
33
+ command: "npx tsc --noEmit"
34
+ timeout: 30000
35
+ on_fail: "修复建议"
36
+ ```
37
+
38
+ ### 3. 匹配并执行验证
39
+
40
+ 对每条验证规则:
41
+ - 将 `trigger` glob 与变更文件列表做匹配
42
+ - 匹配到 → 用 Bash 执行 `command`(将 `{files}` 替换为匹配到的文件路径,**每个路径用单引号包裹防止注入**)
43
+ - 未匹配 → 跳过该规则
44
+
45
+ 每条命令使用对应的 `timeout` 值(毫秒)。
46
+
47
+ ### 4. 汇总结果
48
+
49
+ - **全部通过** → 输出确认信息
50
+ - **有失败** → 展示每个失败项的:
51
+ - 验证器名称
52
+ - 执行的命令
53
+ - 错误输出(截取关键部分)
54
+ - `on_fail` 修复建议
55
+
56
+ ### 5. 自动修复
57
+
58
+ 对于失败的验证项,根据错误输出分析问题根因,自动尝试修复代码。修复后提示用户再次运行 `/project:cf-validate` 确认。
59
+
60
+ ## 安全设计
61
+
62
+ - 对 `{files}` 中的每个文件路径用单引号包裹,防止 shell 注入
63
+ - 仅接受 `git diff` 输出的文件路径或用户显式指定的路径
64
+ - 用户指定的路径必须位于项目根目录内
65
+
66
+ ## 异常处理
67
+
68
+ - validation.yml 不存在 → 尝试检测 package.json scripts 中的 test/lint 命令
69
+ - 命令执行超时 → 输出超时提示,建议增大 timeout 或缩小验证范围
70
+ - 命令不存在 → 提示安装依赖(如 `pip install mypy`)
71
+ - 无变更文件 → 输出"无变更需要验证"
package/src/cli.js CHANGED
@@ -66,21 +66,18 @@ function runInit() {
66
66
  const adaptersDir = path.join(baseDir, 'adapters');
67
67
 
68
68
  copyDirRecursive(path.join(coreDir, 'code-flow'), path.join(cwd, '.code-flow'));
69
- copyFileIfMissing(path.join(coreDir, 'claude.md'), path.join(cwd, 'CLAUDE.md'));
69
+ copyFileIfMissing(path.join(adaptersDir, 'claude', 'CLAUDE.md'), path.join(cwd, 'CLAUDE.md'));
70
70
  copyDirRecursive(path.join(adaptersDir, 'claude'), path.join(cwd, '.claude'));
71
71
 
72
- const result = spawnSync(
73
- 'python3',
74
- ['.code-flow/scripts/cf_init.py'],
75
- { stdio: 'inherit', cwd }
76
- );
77
-
78
- if (result.error) {
79
- process.stderr.write(`Error: ${result.error.message}\n`);
80
- process.exit(1);
72
+ // Clean up legacy .claude/skills/ if it exists
73
+ const legacySkills = path.join(cwd, '.claude', 'skills');
74
+ if (fs.existsSync(legacySkills)) {
75
+ fs.rmSync(legacySkills, { recursive: true });
81
76
  }
82
77
 
83
- process.exit(result.status ?? 0);
78
+ process.stdout.write('code-flow initialized.\n');
79
+ process.stdout.write('Run /project:cf-init in Claude Code to complete setup.\n');
80
+ process.exit(0);
84
81
  }
85
82
 
86
83
  const args = process.argv.slice(2);
@@ -1,13 +0,0 @@
1
- # cf-init
2
-
3
- 初始化 code-flow 规范体系(目录、配置、spec、skill、hooks)。
4
-
5
- ## Usage
6
- - `/cf-init`
7
- - `/cf-init frontend|backend|fullstack`
8
-
9
- ## Command
10
- - `python3 .code-flow/scripts/cf_init.py [frontend|backend|fullstack]`
11
-
12
- ## Notes
13
- - 依赖 Python 3.9+ 与 pyyaml(脚本会尝试自动安装)。
@@ -1,12 +0,0 @@
1
- # cf-inject
2
-
3
- 手动注入指定领域或文件路径对应的规范(Hook 失败时回退)。
4
-
5
- ## Usage
6
- - `/cf-inject frontend|backend`
7
- - `/cf-inject path/to/file.ext`
8
- - `/cf-inject --list-specs --domain=frontend`
9
-
10
- ## Command
11
- - `python3 .code-flow/scripts/cf_inject.py [domain|file_path]`
12
- - `python3 .code-flow/scripts/cf_inject.py --list-specs --domain=frontend`
@@ -1,11 +0,0 @@
1
- # cf-learn
2
-
3
- 将经验沉淀到对应规范的 Learnings 段落。
4
-
5
- ## Usage
6
- - `/cf-learn --scope=global --content="..." `
7
- - `/cf-learn --scope=frontend --content="..." --file=frontend/component-specs.md`
8
- - `/cf-learn --scope=backend --content="..." --file=backend/logging.md`
9
-
10
- ## Command
11
- - `python3 .code-flow/scripts/cf_learn.py --scope=global|frontend|backend --content=\"...\" [--file=spec] [--dry-run]`
@@ -1,12 +0,0 @@
1
- # cf-scan
2
-
3
- 审计规范文件的 token 分布与问题提示。
4
-
5
- ## Usage
6
- - `/cf-scan`
7
- - `/cf-scan --json`
8
- - `/cf-scan --only-issues`
9
- - `/cf-scan --limit=10`
10
-
11
- ## Command
12
- - `python3 .code-flow/scripts/cf_scan.py [--json] [--only-issues] [--limit=N]`
@@ -1,11 +0,0 @@
1
- # cf-stats
2
-
3
- 统计 L0/L1 规范 token 使用情况。
4
-
5
- ## Usage
6
- - `/cf-stats`
7
- - `/cf-stats --human`
8
- - `/cf-stats --domain=frontend`
9
-
10
- ## Command
11
- - `python3 .code-flow/scripts/cf_stats.py [--human] [--domain=frontend]`
@@ -1,12 +0,0 @@
1
- # cf-validate
2
-
3
- 基于变更文件执行验证规则(类型检查/测试/lint)。
4
-
5
- ## Usage
6
- - `/cf-validate`
7
- - `/cf-validate path/to/file.py`
8
- - `/cf-validate --files=src/a.ts,src/b.ts`
9
- - `/cf-validate --only-failed`
10
-
11
- ## Command
12
- - `python3 .code-flow/scripts/cf_validate.py [file_path] [--files=...] [--only-failed] [--json-short] [--output=table]`