@double-codeing/flow2spec 2.2.2 → 3.0.7

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.
Files changed (63) hide show
  1. package/README.md +73 -54
  2. package/cli.js +254 -14
  3. package/docs/Flow2Spec-/344/275/277/347/224/250/346/241/210/344/276/213-/346/250/241/346/213/237/345/257/271/350/257/235.md +123 -134
  4. package/docs/Flow2Spec-/346/274/224/350/256/262/347/250/277.md +411 -0
  5. package/docs/Flow2Spec-/350/256/276/350/256/241/350/257/264/346/230/216.md +574 -0
  6. package/docs/Flow2Spec/344/275/277/347/224/250/350/257/264/346/230/216.md +116 -76
  7. package/docs/README-/344/275/223/347/263/273/344/270/216/345/216/237/347/220/206.md +85 -44
  8. package/docs/README-/345/221/275/344/273/244/350/257/264/346/230/216.md +548 -79
  9. package/docs/README-/347/233/256/345/275/225/344/270/216/350/267/257/345/276/204/347/272/246/345/256/232.md +33 -62
  10. package/docs/images//346/212/200/350/203/275/351/227/255/347/216/257/345/233/276.png +0 -0
  11. package/lib/agents.js +15 -3
  12. package/lib/claudeSettingsAdapter.js +114 -0
  13. package/lib/codexAgentsAdapter.js +70 -0
  14. package/lib/flow2specConfig.js +229 -0
  15. package/lib/init.js +698 -25
  16. package/package.json +2 -2
  17. package/templates/AGENTS.md +98 -0
  18. package/templates/flow2spec.config.json +9 -0
  19. package/templates/hooks/f2s-config-inject.js +181 -0
  20. package/templates/knowledge/index.md +68 -0
  21. package/templates/knowledge/manifest-matchers.json +35 -0
  22. package/templates/knowledge/manifest-routing.json +45 -0
  23. package/templates/knowledge/matchers/m-doc-routing.json +11 -0
  24. package/templates/knowledge/matchers/m-f2s-config-precheck.json +15 -0
  25. package/templates/knowledge/matchers/m-implement-from-spec.json +10 -0
  26. package/templates/{template → knowledge/template}//345/220/216/347/253/257/346/212/200/346/234/257/346/250/241/347/211/210.md +3 -2
  27. package/templates/{template → knowledge/template}//347/273/210/347/250/277/346/250/241/347/211/210.md +5 -4
  28. package/templates/knowledge/topics/f2s-config-precheck.md +24 -0
  29. package/templates/knowledge/topics/f2s-fallback-triage.md +60 -0
  30. package/templates/knowledge/topics/f2s-implement-tech-design.md +21 -0
  31. package/templates/knowledge/topics/f2s-stock-docs-vs-req-docs.md +25 -0
  32. package/templates/rules/f2s-config-check.mdc +35 -0
  33. package/templates/rules/f2s-flow2spec-unified-entry.mdc +88 -0
  34. package/templates/rules/f2s-implement-tech-design.mdc +144 -0
  35. package/templates/rules/f2s-karpathy-guidelines.mdc +77 -0
  36. package/templates/rules/f2s-knowledge-preflight.mdc +70 -0
  37. package/templates/rules/f2s-stock-docs-vs-req-docs.mdc +16 -0
  38. package/templates/rules/f2s-task.mdc +202 -0
  39. package/templates/skills/f2s-ctx-build/SKILL.md +74 -173
  40. package/templates/skills/f2s-ctx-rm/SKILL.md +39 -43
  41. package/templates/skills/f2s-doc-add/SKILL.md +69 -106
  42. package/templates/skills/f2s-doc-arch/SKILL.md +20 -9
  43. package/templates/skills/f2s-doc-final/SKILL.md +29 -21
  44. package/templates/skills/f2s-doc-pdf/SKILL.md +17 -10
  45. package/templates/skills/f2s-git-commit/SKILL.md +189 -0
  46. package/templates/skills/f2s-karpathy-guidelines/SKILL.md +20 -0
  47. package/templates/skills/f2s-kb-feat/SKILL.md +72 -50
  48. package/templates/skills/f2s-kb-fix/SKILL.md +77 -46
  49. package/templates/skills/f2s-kb-merge/SKILL.md +9 -0
  50. package/templates/skills/f2s-kb-migrate/SKILL.md +356 -0
  51. package/templates/skills/f2s-kb-sync/SKILL.md +80 -59
  52. package/templates/skills/f2s-kb-upgrade/SKILL.md +225 -0
  53. package/templates/skills/f2s-req-backend/SKILL.md +35 -12
  54. package/templates/skills/f2s-req-clarify/SKILL.md +10 -2
  55. package/templates/skills/f2s-req-plan/SKILL.md +110 -0
  56. package/templates/skills/stock-docs-vs-req-docs/SKILL.md +10 -4
  57. package/docs/images//345/216/237/347/220/206/345/233/2761.png +0 -0
  58. package/docs/images//345/216/237/347/220/206/345/233/2762.png +0 -0
  59. package/docs/images//345/221/275/344/273/244/346/230/216/347/273/206/345/233/276.png +0 -0
  60. package/docs/images//346/227/245/345/270/270/346/223/215/344/275/234/346/265/201/347/250/213/345/233/276.png +0 -0
  61. package/docs/images//347/256/200/350/277/260/345/233/276.png +0 -0
  62. package/templates/rules/implement-tech-design.mdc +0 -177
  63. package/templates/rules/stock-docs-vs-req-docs.mdc +0 -14
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@double-codeing/flow2spec",
3
- "version": "2.2.2",
4
- "description": "flow2spec init:落盘 .cursor/.claude/.codex 等配置根的 rules、skills、stock-docs/req-docs,文档驱动、f2s 可写回知识库工作流。",
3
+ "version": "3.0.7",
4
+ "description": "在业务仓库初始化「文档驱动、可写回知识库」的 AI 协作骨架:项目根 .Knowledge 承载 stock-docs/req-docs 与机读路由,.cursor/.claude/.codex 写入 f2s-* 规则与技能(含 Karpathy 式编码行为准则 f2s-karpathy-guidelines,init 同步 rules / Codex topics / skills);init 只落结构与模板,业务内容由各 f2s-* 技能在对话中维护。",
5
5
  "homepage": "https://github.com/Lands-1203/Flow2Spec#readme",
6
6
  "repository": {
7
7
  "type": "git",
@@ -0,0 +1,98 @@
1
+ # Flow2Spec 项目入口
2
+
3
+ 本文件由 `flow2spec init` 写入 **`./.codex/AGENTS.md`**(相对仓库根)。你正在使用 Flow2Spec 的项目中工作;知识库在 **`./.Knowledge/`**,请渐进式读取,避免一次性加载大量无关文档。
4
+
5
+ ## ⚠️ f2s-* 技能前置强制步骤
6
+
7
+ **执行任何 `f2s-*` 技能的第一个动作,必须先用 Read 工具读取仓库根目录文件 `./flow2spec.config.json`**,获取 `subAgent` 与 `switchAgentVerification` 的实际值,再决定后续编排方式。
8
+
9
+ ```
10
+ 必须执行:Read("flow2spec.config.json") ← 相对仓库根;技能正文任何步骤之前
11
+ ```
12
+
13
+ **禁止在未读该文件的情况下进入技能正文的任何执行步骤。**
14
+
15
+ ## Flow2Spec 项目开关(`./flow2spec.config.json`;缺失时由 `flow2spec init` 从 npm 包模板补齐)
16
+
17
+ **`flow2spec init` 的定位**:把 Flow2Spec **包内模板**落到当前仓库——包括 **`./.Knowledge/`**(含路由结构、快照等)与 **`./.codex/`**(本文件 **`./.codex/AGENTS.md`**、**`./.codex/skills/`**、经 init 写入的 **`./.codex/topics/*.md`**),**不负责**撰写业务 **`./.Knowledge/stock-docs/`**、**`./.Knowledge/topics/`** 正文或替代 **`f2s-*` 技能**;即 **模板与目录落盘 / 形态对齐**,不是「知识库升级命令」(升级见 **`f2s-kb-upgrade`** 技能)。
18
+
19
+ 执行任意 **`f2s-*` 技能**前,必须读取 `./flow2spec.config.json` 中的布尔字段(缺省或文件不存在均视为 `false`)。下表由 **最近一次 `flow2spec init`** 根据当时配置写入,**以磁盘上的文件为准**。
20
+
21
+ {{FLOW2SPEC_PROJECT_CONFIG}}
22
+
23
+ ### `subAgent` 与 `switchAgentVerification`(语义与上表一致;以磁盘配置为准)
24
+
25
+ - **`subAgent`**:`f2s-*` 技能若写明某步「用子 agent 执行」,**`true`** 时按技能使用子 agent,**`false`** 时在主会话内完成。用户可说明「**仅当** `subAgent` 为 **`true`** 时,由主 agent **动态判断**哪些子任务适合交给子 agent」——**仅当配置为 `true` 时该说明有效**;为 **`false`** 时该段要求**自动失效**,不得拆子 agent。**各技能在何阶段用子 agent** 由技能正文约定,包模板**尚未**给出统一阶段清单。
26
+ - **`switchAgentVerification`(切换 agent 校验)**:**不是**「校验一律在主会话」;**`false` 或未启用交叉规则时**:谁在会话里**落盘**,验证与复核(对照清单、diff、自检)**就在该 agent 会话内**完成(子写子验、主写主验)。**`true` 且** 当前 **`f2s-*` 技能正文**写明依赖本项时,启用**交叉校验**:**子 agent 落盘的 → 主 agent 验**;**主 agent 落盘的 → 子 agent 验**(无子 agent 时,如 **`subAgent` 为 `false`**,则「主落盘→子验」不发生,**全在主会话**验)。
27
+
28
+ ## 全局约束
29
+
30
+ 1. **必须先读机器索引**:优先读取 **`./.Knowledge/manifest-routing.json`** 做主题路由;按需依据 `taskToTopicRules[].matcherPath` 读取对应 matcher 分片(单文件,路径形如 **`./.Knowledge/matchers/<id>.json`**)取匹配词;无法命中时进入补召回阶段。
31
+ - 若存在 `taskToTopicRules`,优先按任务规则路由主题。
32
+ - 若命中主题含 `topicDependencies`,先读依赖主题再读主主题。
33
+ - `manifest` 仅通过 `f2s-*` 技能流程维护,不假设存在额外 CLI 命令。
34
+ 2. **人工索引按需读取**:仅在需要校验主题语义与边界时读取 **`./.Knowledge/index.md`**。
35
+ - `index.md` 不是机读事实源,仅承担人读导航与语义边界说明。
36
+ 3. **专题优先**:根据任务从 **`./.Knowledge/topics/*.md`** 读取**路由摘要**(主题 id、路径、下一步指针)。Flow2Spec **包级执行条令**由 **`flow2spec init`** 写入 **`./.codex/topics/f2s-*.md`**(见下文 **「专题长文」**);需要完整条令时**按需**打开对应文件。
37
+ 4. **长文按需**:仅在需要背景时再读 **`./.Knowledge/stock-docs/*.md`**。
38
+ 5. **需求文档路径**:默认使用 **`./.Knowledge/req-docs/*.md`**。
39
+ 6. 下钻代码前先对齐知识库:若索引已覆盖,优先遵循知识库约定。
40
+ 7. **命中后补全(必须)**:执行 `match -> expand -> verify -> act`。
41
+ - `match`:先基于 routing + matcherPath 得到主候选。
42
+ - `expand`:展开 `topicDependencies`,并保留次高候选(建议 top-2/top-3)做补充校验。
43
+ - `verify`:执行前做缺口检查(是否缺关键主题、边界条件、上下文文档)。
44
+ - `act`:仅在置信度足够时执行;低置信度必须先澄清再执行。
45
+ 8. **全量补检索触发门槛(必须)**:仅在以下条件之一成立时允许做跨 matcher 全量补检索(top-k):
46
+ - `taskToTopicRules` 无命中;
47
+ - 主候选与次候选分差过小(低置信度);
48
+ - 缺口检查失败(关键主题/依赖/上下文缺失);
49
+ - 用户明确要求“全量检查/不要遗漏”。
50
+ 9. **禁止项**:
51
+ - 禁止跳过 **`./.Knowledge/manifest-routing.json`**、按需 `matcherPath` 分片与 **`./.Knowledge/topics/`** 直接全仓检索或直接编码;**`./.Knowledge/index.md`** 按需读取,不可替代上述机读链。
52
+ - 同一任务线内避免重复全文读取 **`./.Knowledge/manifest-routing.json`**(除非用户说明已通过 `f2s-ctx-build` / `f2s-kb-sync` / `f2s-doc-add` 等更新路由或知识、或手动改了 manifest;**勿将**仅执行 `flow2spec init` 当作业务知识库已更新);禁止为枚举而遍历整个 **`./.Knowledge/matchers/`**;禁止 **`./.Knowledge/index.md`** 与 routing 交替「刷清单」。
53
+ - 禁止把 **`./.Knowledge/stock-docs/`** 作为“按方案实现代码”的直接输入文档。
54
+ - Flow2Spec 执行条令仅以 **`./.codex/AGENTS.md`**(本文件)、**`./.codex/topics/f2s-*.md`** 与 **`./.codex/skills/`** 为准;勿使用仓库内 **非上述路径** 的同名条令文件作为执行依据,以免口径分叉。
55
+ - 禁止把 `fallbackTopic` 当作最终命中直接实施改动;`fallbackTopic` 仅作安全兜底与澄清前置上下文。
56
+ - 禁止在不满足触发门槛时做跨 matcher 全量补检索。
57
+ 10. **检索与作答节奏**:在 KB 已形成可答结论时,控制 `grep`/读盘范围与轮次;优先按 topic 给出的目录做单点 `Read`。用户未要求「全仓 / 通读依赖」时,允许**先短答再按需下钻**。细则见 **`./.codex/topics/f2s-knowledge-preflight.md`** 中 **「检索体积与作答节奏」**。
58
+
59
+ ## 渐进式读取顺序
60
+
61
+ 1. `./.Knowledge/manifest-routing.json`
62
+ 2. `./.Knowledge/matchers/<matcher>.json`(按需:通过 `taskToTopicRules[].matcherPath` 定位具体文件)
63
+ 3. `./.Knowledge/index.md`(按需,用于语义校验)
64
+ 4. `./.Knowledge/topics/<topic>.md`(摘要;涉及统一入口、路由细则、`implement-tech-design` / `stock-docs-vs-req-docs` 等时,按需续读下文 **「专题长文」** 所列 `./.codex/topics/f2s-*.md`)
65
+ 5. `./.Knowledge/stock-docs/<doc>.md`(按需)
66
+ 6. 业务代码(按需;路径以仓库内实际目录为准)
67
+
68
+ ## 机读事实源口径(必须遵循)
69
+
70
+ - 机读路由主事实以 **`./.Knowledge/manifest-routing.json`** 为准;匹配词以 `taskToTopicRules[].matcherPath` 指向的 matcher 分片文件为准。
71
+ - **`./.Knowledge/index.md`** 仅作人读导航与语义边界校验,不承担机读字段定义。
72
+ - `fallbackTopic` 仅用于低置信度兜底,不作为最终执行依据;进入 fallback 后必须先补召回或澄清。
73
+
74
+ ## 可用主题
75
+
76
+ - 不在此处维护静态主题列表,避免与知识库演进漂移。
77
+ - 每次任务均以 **`./.Knowledge/manifest-routing.json`** 的 `topicPaths`、`taskToTopicRules`、`fallbackTopic` 为唯一路由事实,并按每条规则的 `matcherPath` 读取 matcher 分片。
78
+ - 若路由清单与 **`./.Knowledge/index.md`** 语义不一致,以路由清单为准并提示用户同步修正。
79
+
80
+ ## 专题长文(`./.codex/topics/`)
81
+
82
+ 由 **`flow2spec init`** 将 npm 包内 **`templates/rules/*.mdc`** 去 frontmatter 后写入 **`./.codex/topics/*.md`**,与本文件、**`./.codex/skills/`** 一起构成 Flow2Spec 的可执行依据。**当前包模板**对应文件(运行时路径均在仓库根下 `.codex/topics/`):
83
+
84
+ - **统一入口**:`./.codex/topics/f2s-flow2spec-unified-entry.md`
85
+ - **implement-tech-design**:`./.codex/topics/f2s-implement-tech-design.md`
86
+ - **stock-docs-vs-req-docs**:`./.codex/topics/f2s-stock-docs-vs-req-docs.md`
87
+
88
+ 同目录下另有:
89
+
90
+ - **`./.codex/topics/f2s-knowledge-preflight.md`**:**普通提问**也须先 `Read` **`./.Knowledge/manifest-routing.json`** 再下钻代码;与统一入口并行时以本条「首工具调用」为准。
91
+ - **`./.codex/topics/f2s-config-check.md`**:内容与上文「先 Read **`./flow2spec.config.json`**」一致并含 **changeTracking** 细表;**仅**在需核对细表时按需打开,不必与上列三条并列必读。
92
+ - **`./.codex/topics/f2s-karpathy-guidelines.md`**:通用编码行为准则(先澄清、极简、手术式修改、可验证目标);与 f2s 路由/任务条令**并行**,硬冲突时以 **f2s 条令**为准。
93
+
94
+ 执行 Flow2Spec 相关任务时,先读本 **`./.codex/AGENTS.md`** 与 **`./.Knowledge/manifest-routing.json`**,再按需打开上列 **`./.codex/topics/*.md`** 文件。
95
+
96
+ ## 可用 Flow2Spec 技能(自动生成)
97
+
98
+ {{FLOW2SPEC_CODEX_SKILLS_SUMMARY}}
@@ -0,0 +1,9 @@
1
+ {
2
+ "subAgent": false,
3
+ "switchAgentVerification": false,
4
+ "changeTracking": {
5
+ "feat": false,
6
+ "fix": false,
7
+ "implement": false
8
+ }
9
+ }
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /**
4
+ * flow2spec PreToolUse hook — 在任何 f2s-* Skill 执行前自动注入 flow2spec.config.json。
5
+ * 由 flow2spec init --claude 写入 .claude/hooks/f2s-config-inject.js。
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ const DEFAULT_CFG = {
11
+ subAgent: false,
12
+ switchAgentVerification: false,
13
+ changeTracking: { feat: false, fix: false, implement: false },
14
+ };
15
+
16
+ /** 与 lib/flow2specConfig.js 一致,避免 hook 依赖包内路径 */
17
+ function normalizeBool(value, fallback) {
18
+ if (value === true || value === 'true' || value === 1 || value === '1')
19
+ return true;
20
+ if (value === false || value === 'false' || value === 0 || value === '0')
21
+ return false;
22
+ return fallback;
23
+ }
24
+
25
+ function emitAdditionalContext(lines) {
26
+ process.stdout.write(
27
+ JSON.stringify({
28
+ hookSpecificOutput: {
29
+ hookEventName: 'PreToolUse',
30
+ additionalContext: lines.join('\n'),
31
+ },
32
+ }),
33
+ );
34
+ }
35
+
36
+ function normalizeCfg(raw) {
37
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
38
+ return { ...DEFAULT_CFG, changeTracking: { ...DEFAULT_CFG.changeTracking } };
39
+ }
40
+ const ct = raw.changeTracking;
41
+ let changeTracking = { ...DEFAULT_CFG.changeTracking };
42
+ if (typeof ct === 'boolean') {
43
+ changeTracking = {
44
+ feat: normalizeBool(ct, DEFAULT_CFG.changeTracking.feat),
45
+ fix: normalizeBool(ct, DEFAULT_CFG.changeTracking.fix),
46
+ implement: normalizeBool(ct, DEFAULT_CFG.changeTracking.implement),
47
+ };
48
+ } else if (ct && typeof ct === 'object' && !Array.isArray(ct)) {
49
+ changeTracking = {
50
+ feat: normalizeBool(ct.feat, DEFAULT_CFG.changeTracking.feat),
51
+ fix: normalizeBool(ct.fix, DEFAULT_CFG.changeTracking.fix),
52
+ implement: normalizeBool(ct.implement, DEFAULT_CFG.changeTracking.implement),
53
+ };
54
+ }
55
+ const switchRaw = Object.prototype.hasOwnProperty.call(raw, 'switchAgentVerification')
56
+ ? raw.switchAgentVerification
57
+ : raw.subAgentVerification;
58
+ return {
59
+ subAgent: normalizeBool(raw.subAgent, DEFAULT_CFG.subAgent),
60
+ switchAgentVerification: normalizeBool(
61
+ switchRaw,
62
+ DEFAULT_CFG.switchAgentVerification,
63
+ ),
64
+ changeTracking,
65
+ };
66
+ }
67
+
68
+ function buildChangeTrackingLines(skillName, cfg) {
69
+ const lines = [];
70
+ const ctKeyMap = {
71
+ 'f2s-kb-feat': 'feat',
72
+ 'f2s-kb-fix': 'fix',
73
+ 'f2s-implement-tech-design': 'implement',
74
+ };
75
+ const ctKey = ctKeyMap[skillName];
76
+ if (ctKey === undefined) return lines;
77
+ const ctValue = normalizeBool(
78
+ (cfg.changeTracking ?? {})[ctKey],
79
+ DEFAULT_CFG.changeTracking[ctKey],
80
+ );
81
+ lines.push('');
82
+ if (ctValue) {
83
+ const stepMap = {
84
+ feat: '步骤 0',
85
+ fix: '步骤 0',
86
+ implement: '步骤 2.5(写入任务清单)、2.6(随步打钩 task.md)、步骤 5(归档门禁后归档)',
87
+ };
88
+ lines.push(
89
+ `changeTracking.${ctKey}=true → 本技能变更追踪【必须执行】:在 ${stepMap[ctKey]} 创建或续作 .task/active/ 任务,禁止跳过。`,
90
+ );
91
+ } else {
92
+ lines.push(
93
+ `changeTracking.${ctKey}=false → 本技能变更追踪步骤跳过,不得创建 .task/ 目录。`,
94
+ );
95
+ }
96
+ return lines;
97
+ }
98
+
99
+ function buildCoreLines(cfg, sourceLabel) {
100
+ const lines = [
101
+ `[flow2spec] ${sourceLabel}`,
102
+ ` subAgent = ${cfg.subAgent}`,
103
+ ` switchAgentVerification = ${cfg.switchAgentVerification}`,
104
+ ` changeTracking = ${JSON.stringify(cfg.changeTracking)}`,
105
+ '',
106
+ 'subAgent=true → 按技能 SKILL.md 中 B/C 模式派子 agent 并行扫描,主 agent 合并落盘。',
107
+ 'subAgent=false → 全部在主 agent 内完成,不派子 agent。',
108
+ 'switchAgentVerification=true → 子 agent 落盘的由主 agent 校验;主 agent 落盘的由子 agent 校验(须 subAgent=true 且实际拆出子任务)。',
109
+ ];
110
+ return lines;
111
+ }
112
+
113
+ const chunks = [];
114
+ process.stdin.on('data', (d) => chunks.push(d));
115
+ process.stdin.on('end', () => {
116
+ let skillName = '';
117
+ try {
118
+ const input = JSON.parse(Buffer.concat(chunks).toString('utf8'));
119
+ skillName = String(input?.tool_input?.skill || '');
120
+ } catch (_err) {
121
+ process.exit(0);
122
+ return;
123
+ }
124
+
125
+ if (!/^f2s-/.test(skillName)) {
126
+ process.exit(0);
127
+ return;
128
+ }
129
+
130
+ const configPath = path.resolve(process.cwd(), 'flow2spec.config.json');
131
+
132
+ try {
133
+ if (!fs.existsSync(configPath)) {
134
+ const cfg = { ...DEFAULT_CFG, changeTracking: { ...DEFAULT_CFG.changeTracking } };
135
+ const lines = [
136
+ '[flow2spec] 项目根不存在 flow2spec.config.json;按统一入口约定,缺失字段均视为 false。',
137
+ '',
138
+ ...buildCoreLines(cfg, '等价配置预览(建议随后 Read 或 flow2spec init 补齐该文件):'),
139
+ '',
140
+ '可执行:flow2spec init(或从包模板复制 flow2spec.config.json 到项目根)。',
141
+ ...buildChangeTrackingLines(skillName, cfg),
142
+ ];
143
+ emitAdditionalContext(lines);
144
+ process.exit(0);
145
+ return;
146
+ }
147
+
148
+ let raw;
149
+ try {
150
+ raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));
151
+ } catch (parseErr) {
152
+ const cfg = { ...DEFAULT_CFG, changeTracking: { ...DEFAULT_CFG.changeTracking } };
153
+ const lines = [
154
+ `[flow2spec] flow2spec.config.json 存在但 JSON 解析失败:${parseErr.message || String(parseErr)}`,
155
+ '在修复文件前,请按以下默认安全语义执行本技能(与「文件不存在」一致):',
156
+ '',
157
+ ...buildCoreLines(cfg, '等价配置(解析失败回退)'),
158
+ ...buildChangeTrackingLines(skillName, cfg),
159
+ ];
160
+ emitAdditionalContext(lines);
161
+ process.exit(0);
162
+ return;
163
+ }
164
+
165
+ const cfg = normalizeCfg(raw);
166
+ const lines = [
167
+ ...buildCoreLines(cfg, 'flow2spec.config.json 已自动注入,执行本 f2s-* 技能前必须遵守以下配置:'),
168
+ '',
169
+ '仍建议用 Read(flow2spec.config.json) 与磁盘核对,尤其在刚编辑过该文件时。',
170
+ ...buildChangeTrackingLines(skillName, cfg),
171
+ ];
172
+ emitAdditionalContext(lines);
173
+ } catch (err) {
174
+ const msg = err && err.message ? err.message : String(err);
175
+ emitAdditionalContext([
176
+ `[flow2spec] f2s-config-inject hook 未预期异常:${msg}`,
177
+ '请手动 Read("flow2spec.config.json") 后再执行本技能;若持续失败请检查 hook 脚本与项目根路径。',
178
+ ]);
179
+ }
180
+ process.exit(0);
181
+ });
@@ -0,0 +1,68 @@
1
+ # Flow2Spec Knowledge Index
2
+
3
+ > **路径约定**:下文 **`.Knowledge/`**、**`manifest-routing.json`** 等路径均相对于**本仓库根目录**(即已运行 `flow2spec init` 的当前项目)。
4
+
5
+ 本文件是 **人读导航**:主题说明、关联文档摘要、语义边界。
6
+ **机读事实源** 以 `.Knowledge/manifest-routing.json` + `taskToTopicRules[].matcherPath` 指向的 `.Knowledge/matchers/*.json` 分片为准(不再使用 `.Knowledge/manifest-matchers.json`)。
7
+
8
+ ---
9
+
10
+ ## 推荐阅读顺序
11
+
12
+ 1. `.Knowledge/manifest-routing.json`(任务路由、`topicPaths`、`topicDependencies`、`fallbackTopic`)
13
+ 2. 按需:由 `matcherPath` 读取 `.Knowledge/matchers/<id>.json`(`includeAny` 关键词)
14
+ 3. 按需:本 `index.md`(主题语义与边界)
15
+ 4. `.Knowledge/topics/<topic>.md`(执行约束与流程)
16
+ 5. 按需:`.Knowledge/stock-docs/`、`.Knowledge/req-docs/`
17
+ 6. 仍不足再下钻业务代码
18
+
19
+ ---
20
+
21
+ ## 主题一览
22
+
23
+ | 主题 | 路径 | 适用场景 | 关联文档(摘要) |
24
+ | --- | --- | --- | --- |
25
+ | implement-tech-design | `.Knowledge/topics/f2s-implement-tech-design.md` | 按技术方案实现代码 | req:[技术方案](.Knowledge/req-docs/<技术方案>.md)(必填) |
26
+ | stock-docs-vs-req-docs | `.Knowledge/topics/f2s-stock-docs-vs-req-docs.md` | stock-docs / req-docs 目录分工 | stock:[目录边界说明](.Knowledge/stock-docs/<目录边界说明>.md)(可选) |
27
+ | fallback-triage | `.Knowledge/topics/f2s-fallback-triage.md` | 未命中或低置信度:分诊与澄清 | stock:[路由分诊说明](.Knowledge/stock-docs/<分诊说明>.md)(可选) |
28
+ | config-precheck | `.Knowledge/topics/f2s-config-precheck.md` | 执行 `f2s-*` 前读 `flow2spec.config.json` / 编排开关 | Codex 长文:仓库根 `.codex/topics/f2s-config-check.md`;[路由摘要](topics/f2s-config-precheck.md) |
29
+
30
+ 每主题保留 **1–3 条** 可点击摘要链接;全量路径对照写入 `.Knowledge/migration-report.md`(迁移场景)。
31
+ 其中 **`implement-tech-design`**、**`stock-docs-vs-req-docs`**、**`config-precheck`** 在 `topics/` 内为**路由摘要**;执行长文见配置根 **`rules/f2s-*.md(c)`**;使用 Codex 时见 **`.codex/AGENTS.md`**、**`.codex/topics/f2s-*.md`**(`f2s-config-check` 与 `AGENTS` 前置同源,按需打开)。
32
+
33
+ ---
34
+
35
+ ## 命中与执行(与统一入口一致)
36
+
37
+ - **路由**:`taskToTopicRules` 给出任务 → 主题集合;**关键词**在 matcher 分片的 `includeAny`。
38
+ - **依赖**:命中主主题前,按 `topicDependencies` 先读依赖主题。
39
+ - **兜底**:`fallbackTopic` 指向分诊主题(如 `fallback-triage`),仅低置信度上下文,**不得**当作最终命中直接改代码。
40
+ - **执行链**:`match → expand → verify → act`;`expand` 须含依赖展开,并保留次高候选做校验。
41
+ - **全量补检索**:仅当无命中、候选分差过小、缺口检查失败,或用户明确要求「全量检查」时允许跨 matcher 补检索。
42
+
43
+ ---
44
+
45
+ ## 目录职责
46
+
47
+ | 目录 | 职责 |
48
+ | --- | --- |
49
+ | `topics/` | 专题规则与执行流程 |
50
+ | `matchers/` | matcher 分片(`matcherPath` 指向) |
51
+ | `stock-docs/` | 存量沉淀(架构、终稿等) |
52
+ | `req-docs/` | 需求与技术方案(驱动实现) |
53
+ | `template/` | 终稿与方案模版 |
54
+
55
+ 路由清单由 `f2s-*` 技能链路维护,不依赖额外 CLI 子命令。
56
+
57
+ ---
58
+
59
+ ## 常见缺口怎么处理(与统一入口一致)
60
+
61
+ | 情况 | 你怎么做 |
62
+ | --- | --- |
63
+ | 有文档但没配到(1a) | 维护侧:`f2s-ctx-build` / `f2s-kb-sync` / `f2s-doc-add` 补路由与 `includeAny`。执行侧:分诊主题澄清任务类型,**不**用全仓扫替代 manifest。 |
64
+ | 配到了但不够(1b) | 走依赖与次高候选 → `verify` 点名缺哪篇文档;仍缺则向用户要路径或补 `req-docs`。 |
65
+ | 库里没有(2) | 承认缺口 → 代码下钻或请用户补需求/方案文档。 |
66
+ | 反复读 manifest 费 token(2a) | 同一任务线内 routing 只当快照;只读命中项的单个 matcher;不遍历整个 `matchers/` 目录枚举;`index.md` 勿与 routing 循环互刷。 |
67
+
68
+ **说明**:「路由/知识已更新」指 `f2s-*`(如 `f2s-ctx-build`、`f2s-kb-sync`、`f2s-doc-add`、`f2s-kb-fix` 等)产出或手改 `manifest-routing` / `matchers` 分片;**`flow2spec init` 不撰写业务文档**,以模板补齐与配置根落盘为主,勿与知识库内容更新混为一谈。
@@ -0,0 +1,35 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "generatedFrom": ".Knowledge/manifest-routing.json",
4
+ "matcherKey": "matcherId",
5
+ "sourceOfTruth": ".Knowledge/manifest-routing.json",
6
+ "matchers": {
7
+ "m-implement-from-spec": {
8
+ "includeAny": [
9
+ "按技术方案实现",
10
+ "实现接口",
11
+ "需求文档开发"
12
+ ]
13
+ },
14
+ "m-doc-routing": {
15
+ "includeAny": [
16
+ "文档放哪",
17
+ "stock-docs",
18
+ "req-docs",
19
+ "目录约定"
20
+ ]
21
+ },
22
+ "m-f2s-config-precheck": {
23
+ "includeAny": [
24
+ "flow2spec.config.json",
25
+ "subAgent",
26
+ "switchAgentVerification",
27
+ "切换 agent 校验",
28
+ "技能前置",
29
+ "f2s-config-check",
30
+ "f2s-config-inject",
31
+ "changeTracking"
32
+ ]
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "knowledgeRoot": ".Knowledge",
4
+ "matcherKey": "matcherId",
5
+ "sourceOfTruth": ".Knowledge/manifest-routing.json",
6
+ "fallbackTopic": "fallback-triage",
7
+ "topicDependencies": {
8
+ "implement-tech-design": [
9
+ "stock-docs-vs-req-docs"
10
+ ]
11
+ },
12
+ "topicPaths": {
13
+ "implement-tech-design": ".Knowledge/topics/f2s-implement-tech-design.md",
14
+ "stock-docs-vs-req-docs": ".Knowledge/topics/f2s-stock-docs-vs-req-docs.md",
15
+ "fallback-triage": ".Knowledge/topics/f2s-fallback-triage.md",
16
+ "config-precheck": ".Knowledge/topics/f2s-config-precheck.md"
17
+ },
18
+ "taskToTopicRules": [
19
+ {
20
+ "task": "f2s-config-precheck",
21
+ "matcherId": "m-f2s-config-precheck",
22
+ "matcherPath": ".Knowledge/matchers/m-f2s-config-precheck.json",
23
+ "topics": [
24
+ "config-precheck"
25
+ ]
26
+ },
27
+ {
28
+ "task": "implement-from-spec",
29
+ "matcherId": "m-implement-from-spec",
30
+ "matcherPath": ".Knowledge/matchers/m-implement-from-spec.json",
31
+ "topics": [
32
+ "stock-docs-vs-req-docs",
33
+ "implement-tech-design"
34
+ ]
35
+ },
36
+ {
37
+ "task": "doc-routing",
38
+ "matcherId": "m-doc-routing",
39
+ "matcherPath": ".Knowledge/matchers/m-doc-routing.json",
40
+ "topics": [
41
+ "stock-docs-vs-req-docs"
42
+ ]
43
+ }
44
+ ]
45
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "m-doc-routing",
3
+ "version": "1.0.0",
4
+ "schema": "flow2spec.matcher.v1",
5
+ "includeAny": [
6
+ "文档放哪",
7
+ "stock-docs",
8
+ "req-docs",
9
+ "目录约定"
10
+ ]
11
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "includeAny": [
3
+ "flow2spec.config.json",
4
+ "subAgent",
5
+ "switchAgentVerification",
6
+ "切换 agent 校验",
7
+ "技能前置",
8
+ "f2s-config-check",
9
+ "f2s-config-inject",
10
+ "changeTracking"
11
+ ],
12
+ "id": "m-f2s-config-precheck",
13
+ "version": "1.0.0",
14
+ "schema": "flow2spec.matcher.v1"
15
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "m-implement-from-spec",
3
+ "version": "1.0.0",
4
+ "schema": "flow2spec.matcher.v1",
5
+ "includeAny": [
6
+ "按技术方案实现",
7
+ "实现接口",
8
+ "需求文档开发"
9
+ ]
10
+ }
@@ -1,8 +1,9 @@
1
- > **「配置根」**:当前 agent 对应的 AI 工具配置目录(`flow2spec init` 写入,常见 **`.cursor/`**、**`.claude/`**、**`.codex/`**)。下文 **`配置根/...`** 指该目录下的相对路径。
1
+ > **主口径(统一知识库)**:技术方案模板与产物统一维护在 `/.Knowledge/template/` `/.Knowledge/req-docs/`。
2
+ > 本模板唯一来源为 `templates/knowledge/template/后端技术模版.md`。
2
3
 
3
4
  # 后端技术方案模版
4
5
 
5
- > 供 **f2s-req-backend** 技能使用。本模版在 Flow2Spec 中位于 **templates/template/**(与 docs 同级),init 时会将整目录复制到项目的 **`配置根/template/`**,本文件即 `配置根/template/后端技术模版.md`。生成 Markdown 时一级、二级标题顺序固定如下,与需求无关的整节可省略。**接口与处理流程写在同一处**,不拆章重复。
6
+ > 供 **f2s-req-backend** 技能使用。主模板路径为 `.Knowledge/template/后端技术模版.md`;配置根不再写入 `template/` 副本。生成 Markdown 时一级、二级标题顺序固定如下,与需求无关的整节可省略。**接口与处理流程写在同一处**,不拆章重复。
6
7
 
7
8
  ---
8
9
 
@@ -1,10 +1,11 @@
1
- > **「配置根」**:当前 agent 对应的 AI 工具配置目录(`flow2spec init` 写入,常见 **`.cursor/`**、**`.claude/`**、**`.codex/`**)。下文 **`配置根/...`** 指该目录下的相对路径。
1
+ > **主口径(统一知识库)**:终稿模板与终稿文档统一维护在 `/.Knowledge/template/` `/.Knowledge/stock-docs/`。
2
+ > 本模板唯一来源为 `templates/knowledge/template/终稿模版.md`。
2
3
 
3
4
  # 终稿概述模版
4
5
 
5
- > 本模板用于将「架构说明」「功能/技术方案」等文档整理为**终稿**形态,便于 **f2s-ctx-build** 技能生成 Rules、Skills 与文档索引。
6
+ > 本模板用于将「架构说明」「功能/技术方案」等文档整理为**终稿**形态,便于 **f2s-ctx-build** 技能更新 `.Knowledge/topics`、`.Knowledge/index.md` 与(按需)路由清单(`manifest-routing` + `matchers/*.json`)。
6
7
  > 适用:后端服务、前端/客户端、全栈、产品与设计说明等,按需保留或省略章节。
7
- > **在 Flow2Spec 中**:本模版位于 **templates/template/**(与 docs 同级),init 时会将整目录复制到项目的 **`配置根/template/`**,本文件即 `配置根/template/终稿模版.md`。
8
+ > **在 Flow2Spec 中**:主模板路径为 `.Knowledge/template/终稿模版.md`;配置根不再写入 `template/` 副本。
8
9
  > **执行 f2s-doc-final 技能时**:本模版仅作为**结构参考与写作提示**,不强制套用;转换以原文内容与逻辑为主,按需采纳章节建议。
9
10
 
10
11
  ---
@@ -90,4 +91,4 @@
90
91
 
91
92
  - 将上述括号内的占位替换为实际内容;与文档类型无关的章节可整节删除或标「(不适用)」。
92
93
  - 至少保留 **核心概念、业务规则、关键流程** 三个二级标题,其余按需增删。
93
- - 保存为 `配置根/stock-docs/<方案名>_终稿.md` 后,按 **f2s-ctx-build** 技能、以该路径为入参即可生成 Rules、Skills、文档索引。
94
+ - 保存为 `.Knowledge/stock-docs/<方案名>_终稿.md` 后,按 **f2s-ctx-build** 技能、以该路径为入参即可更新 `.Knowledge/topics`、`.Knowledge/index.md`,并在需要时更新路由清单。
@@ -0,0 +1,24 @@
1
+ # config-precheck(路由摘要)
2
+
3
+ ## 本主题作用
4
+
5
+ - 供 `manifest-routing.topicPaths` 锚定主题 id **`config-precheck`**。
6
+ - 与执行任意 **`f2s-*` 技能**前读取项目根 **`flow2spec.config.json`**(`subAgent`、`switchAgentVerification`、`changeTracking`)相关;语义与 **`.codex/AGENTS.md`** 顶部、「统一入口」一致。
7
+
8
+ ## 完整条令(按需,勿在 `.Knowledge` 再维护第二份正文)
9
+
10
+ | 侧 | 路径 |
11
+ | --- | --- |
12
+ | Codex(init 镜像,与模板同源) | [f2s-config-check.md](../../.codex/topics/f2s-config-check.md) |
13
+ | Cursor | 仓库根 `.cursor/rules/f2s-config-check.mdc`(`flow2spec init cursor`) |
14
+ | Claude | `.claude/rules/f2s-config-check.md`;PreToolUse:`templates/hooks/f2s-config-inject.js` |
15
+ | 包模板 | `templates/rules/f2s-config-check.mdc` |
16
+
17
+ ## 必备步骤
18
+
19
+ 1. 用 **Read** 打开项目根 **`flow2spec.config.json`**(须在 `f2s-*` 技能正文任何步骤之前)。
20
+ 2. **`.codex/AGENTS.md`** 中 `{{FLOW2SPEC_PROJECT_CONFIG}}` 表为 **init 时刻快照**;与磁盘不一致时以 **Read** 结果为准。
21
+
22
+ ## 禁止项
23
+
24
+ - 禁止在未读 **`flow2spec.config.json`** 的情况下进入 **`f2s-*`** 技能正文步骤(与 `AGENTS`、`.codex/topics/f2s-config-check.md` 一致)。
@@ -0,0 +1,60 @@
1
+ # fallback-triage
2
+
3
+ ## 触发条件
4
+
5
+ 以下任一成立时进入本主题:
6
+
7
+ - `taskToTopicRules` 无命中
8
+ - 无法确定路由到哪个主题(多个候选相近,关键词均为通用词,无领域词命中)
9
+ - 缺口检查失败(依赖主题或上下文文档缺失)
10
+
11
+ > **进入本主题时**:`manifest-routing.json` 已在本任务线读取过,视为稳定快照,不再重读。直接基于已有路由结果分诊。
12
+ >
13
+ > **本主题仅用于分诊,不作为最终命中依据,不直接实施业务改动。**
14
+
15
+ ---
16
+
17
+ ## 分诊流程
18
+
19
+ ### 第一步:判断路由是否命中
20
+
21
+ **已命中主题,但上下文不足**:
22
+
23
+ 1. 读取 `topicDependencies` 中的依赖主题,保留次高候选做补充校验
24
+ 2. 点名缺少哪份文档或哪段 topic
25
+ 3. 向用户要具体文档路径,补齐后继续执行
26
+ 4. **不进行无门槛的跨 matcher 全量检索**
27
+
28
+ **未命中任何主题**:进入第二步。
29
+
30
+ ---
31
+
32
+ ### 第二步:向用户确认领域覆盖情况
33
+
34
+ 不由 Agent 自行推断,直接问用户:
35
+
36
+ > 当前任务未命中路由。请确认:**这个领域的文档是否已录入知识库?**
37
+ > - 是 → 可能是路由词条缺失,建议执行 `f2s-ctx-build` / `f2s-kb-sync` 补充路由后重试
38
+ > - 否 → 知识库当前无此覆盖,可选择:下钻业务源码 / 补充 `req-docs` 后按方案实现
39
+ > - 不确定 → 请检查 `.Knowledge/stock-docs/` 是否有相关文档,再告知
40
+
41
+ 根据用户回答走对应出口,**不在无答案时自行猜测**。
42
+
43
+ ---
44
+
45
+ ## 出口路径
46
+
47
+ | 分诊结论 | 下一步 |
48
+ |----------|--------|
49
+ | 已命中主题,补齐上下文后 | 跳转至该 topic,按 `match → expand → verify → act` 执行 |
50
+ | 用户确认文档已录入,路由词条缺失 | 提示执行 `f2s-ctx-build` / `f2s-kb-sync` 补路由,本次暂停或下钻源码 |
51
+ | 用户确认库中无覆盖 | 提供两条路:下钻源码 / 补充 `req-docs` 后实现 |
52
+ | 用户不确定,仍无法定位 | 停止执行,向用户说明原因,等待明确指令 |
53
+
54
+ ---
55
+
56
+ ## 禁止项
57
+
58
+ - 禁止将本主题作为最终命中依据直接实施改动
59
+ - 禁止跳过向用户确认,自行推断领域覆盖情况
60
+ - 禁止在上下文不足时进行跨 matcher 全量补检索
@@ -0,0 +1,21 @@
1
+ # implement-tech-design(路由摘要)
2
+
3
+ > **唯一长文**:Cursor / Claude 以配置根 **`rules/f2s-implement-tech-design.md(c)`** 为准。
4
+ > **Codex**:不读 `rules/`,须执行 **`.codex/topics/f2s-implement-tech-design.md`**(由 `flow2spec init` 从模板 `rules` 自动镜像)中的等效约束。
5
+
6
+ ## 本文件作用
7
+
8
+ - 供 `manifest-routing.topicPaths` 与 `index.md` 锚定主题 id **`implement-tech-design`**。
9
+ - 仅保留**路径与角色**记忆点,避免与 `rules/` 双份维护长文。
10
+
11
+ ## 路径与角色(须与规则一致)
12
+
13
+ - 技术方案输入:`.Knowledge/req-docs/*.md`(及 PDF 经 `f2s-doc-pdf` 落入同目录的 MD)。
14
+ - 存量沉淀:`.Knowledge/stock-docs/` — **不**作为「按方案写代码」的直接输入。
15
+
16
+ ## 下一步读什么
17
+
18
+ | 环境 | 下一步 |
19
+ | --- | --- |
20
+ | Cursor / Claude | 打开或 @ **`rules/f2s-implement-tech-design`**,按其中步骤执行。 |
21
+ | Codex | 读 **`.codex/topics/f2s-implement-tech-design.md`**。 |