@double-codeing/flow2spec 3.0.7 → 3.0.9

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,165 @@
1
+ [中文](./Flow2Spec使用说明.md) | [English](./usage-guide.en.md)
2
+
3
+ # Flow2Spec Usage Guide
4
+
5
+ ## 1. What `init` Does
6
+
7
+ Execute in the project root:
8
+
9
+ ```bash
10
+ flow2spec init [cursor|claude|codex ...]
11
+ # To force reset .Knowledge from template:
12
+ flow2spec init [cursor|claude|codex ...] --reset-knowledge
13
+ ```
14
+
15
+ | What `init` does | What `init` does NOT do |
16
+ |---------|----------|
17
+ | Fills in missing directories and template files | Write or update business document content |
18
+ | Writes agent config root `rules/` `skills/` | Update `includeAny` business terms |
19
+ | Aligns `manifest-routing` + `matchers/` package-level structure | Replace `f2s-*` skills for writing business semantics |
20
+ | Overwrites `.Knowledge` template files with `--reset-knowledge` | Override existing `.Knowledge` content (without this flag) |
21
+
22
+ > **`init` and "knowledge base upgrade" are two different things**: `init` only handles structural alignment — business semantics (topics content, routing terms, stock-docs/req-docs) are maintained by skills like `f2s-doc-add`, `f2s-kb-fix`, `f2s-kb-feat`, `f2s-kb-sync`, `f2s-ctx-build`, etc. For cross-version upgrades, use `f2s-kb-upgrade`. **Do not treat a standalone `init` as an upgrade command.**
23
+
24
+ ### `f2s-*` and `flow2spec.config.json`: Multi-Client, Multi-Layered Reminders (Authority Remains the Disk JSON)
25
+
26
+ Before executing any **`f2s-*` skill**, the Agent needs to obtain the actual values of **`subAgent` / `switchAgentVerification` / `changeTracking`**, etc. Flow2Spec enforces this via **different mechanisms** on **different clients**; they **complement** each other and do **not** replace one another. **Authority always** resides in the project root **`flow2spec.config.json`** (call **Read** to verify against disk before proceeding into skill body).
27
+
28
+ | Client | `init` Output & Behavior | Description |
29
+ | --- | --- | --- |
30
+ | **Cursor** | `.cursor/rules/f2s-config-check.mdc` (`alwaysApply`) | Rule requires: **Read(`flow2spec.config.json`)** before entering skill body. |
31
+ | **Claude Code** | `.claude/hooks/f2s-config-inject.js` + `.claude/settings.json` (PreToolUse, `Skill` matching) | Injects a config summary when invoking **`f2s-*` Skill**; when **file is missing, JSON is invalid, or hook throws an unexpected exception**, it also injects a **notice + default semantics consistent with "file not found"** to avoid silent failure; it is still recommended to **Read** for confirmation when in doubt or after config changes. |
32
+ | **Codex** | `.codex/AGENTS.md` top-level mandatory step + `{{FLOW2SPEC_PROJECT_CONFIG}}` expansion table | **Read** is a hard requirement; the config table is a **snapshot from the last `flow2spec init`** — when it differs from disk, **Read** takes precedence. The adjacent **`.codex/topics/f2s-config-check.md`** shares its origin with the Cursor rule (including the **changeTracking** detail table); open it **as needed** — it does not need to be grouped with the three "topic long-form" examples as required reading. |
33
+ | **Knowledge Base (optional)** | When `.Knowledge/manifest-routing` hits **`config-precheck`** | `.Knowledge/topics/f2s-config-precheck.md` is a **routing summary** that links to the Codex long-form article; Flow2Spec does **not** maintain a second full copy in `.Knowledge`, nor does it replace a `Read` of the JSON. |
34
+
35
+ For field semantics and default value rules, see [Commands Reference § 6) Sub-Agent Configuration](./commands-reference.en.md). For the design perspective, see [Design Principles § 4.5.1](./design-principles.en.md).
36
+
37
+ ---
38
+
39
+ ## 2. Directory Conventions
40
+
41
+ Core distinction: `stock-docs/` holds solidified documents (driving knowledge routing), `req-docs/` holds technical designs (driving coding implementation); they are not interchangeable.
42
+
43
+ See [Directory Conventions](./directory-conventions.en.md) for the full directory description.
44
+
45
+ ---
46
+
47
+ ## 3. Typical Workflows
48
+
49
+ ### Requirements Planning and Implementation
50
+
51
+ ```
52
+ f2s-req-plan
53
+ ```
54
+
55
+ Provide a path to the technical design document or a requirements description. A draft task checklist is produced first and awaits confirmation. After confirmation, implementation proceeds according to the checklist. A `.task/` task checklist is always created — no `changeTracking` configuration is needed. Suitable for scenarios where you want to see the full picture before starting, or need cross-session progress tracking.
56
+
57
+ ### Change Tracking and Cross-Session Continuation
58
+
59
+ ```
60
+ # Automatic mode: enabled by config (independent per skill)
61
+ flow2spec.config.json → changeTracking.feat / fix / implement: true
62
+
63
+ # Explicit mode: call f2s-req-plan (planning + implementation, no config dependency)
64
+ f2s-req-plan
65
+ ```
66
+
67
+ **Automatic mode**: When enabled, `f2s-kb-feat` / `f2s-kb-fix` / `f2s-implement-tech-design` automatically create a task checklist under `.task/active/`, check off steps progressively, and archive upon completion. In subsequent sessions, when describing related content, the `f2s-task` rule automatically matches and loads the remaining checklist — no need to re-explain the context.
68
+
69
+ **Explicit mode**: Call `f2s-req-plan` directly — regardless of the `changeTracking` configuration, a task checklist is always created and code is implemented against it. Suitable for scenarios where you want to confirm the full picture before taking action.
70
+
71
+ ### New Feature Development
72
+
73
+ ```
74
+ f2s-req-clarify → f2s-req-backend → implement-tech-design → f2s-kb-feat
75
+ ```
76
+
77
+ When requirements are already clear, `f2s-req-clarify` can be skipped, starting directly from `f2s-req-backend`. After the technical design is written into `req-docs/`, the `implement-tech-design` rule drives coding.
78
+
79
+ ### Document Ingestion
80
+
81
+ ```
82
+ New architecture document ingestion: f2s-doc-arch → f2s-doc-final → f2s-ctx-build
83
+ PDF document ingestion: f2s-doc-pdf → f2s-doc-final → f2s-ctx-build
84
+ ```
85
+
86
+ Integrate architecture descriptions or PDF technical designs into the knowledge routing (generates topics/matchers/manifest-routing).
87
+
88
+ ### PDF-Based Implementation
89
+
90
+ ```
91
+ f2s-doc-pdf → implement-tech-design
92
+ ```
93
+
94
+ Convert a PDF technical design to Markdown and place it in `req-docs/`, then let the `implement-tech-design` rule drive coding.
95
+
96
+ ### Backfilling Existing Capabilities
97
+
98
+ ```
99
+ f2s-doc-add # Aggregate multiple files, extract from source code / documents
100
+ f2s-kb-sync # Infer already-implemented capabilities from current session
101
+ ```
102
+
103
+ Use these when code has already been shipped but the knowledge base has no record. `f2s-doc-add` is suitable for batch imports; `f2s-kb-sync` is suitable for real-time consolidation at the end of a session.
104
+
105
+ ### Routine Maintenance
106
+
107
+ ```
108
+ f2s-kb-fix # Fix implementation or rule errors, auto-sync knowledge base
109
+ f2s-kb-feat # Add new capabilities, auto-sync knowledge base
110
+ f2s-kb-sync # Periodic sync or backfill
111
+ f2s-kb-merge # Resolve context conflicts after Git merges
112
+ ```
113
+
114
+ ### Cross-Version Knowledge Base Upgrade
115
+
116
+ ```
117
+ f2s-kb-migrate (Legacy V1: old knowledge base) → f2s-kb-upgrade
118
+ f2s-kb-upgrade (Current V2+: already has .Knowledge; includes npm v3.x projects, etc.; see skill step 0)
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 4. Agent Execution Configuration
124
+
125
+ Controlled via the project root `flow2spec.config.json`. For complete field rules, see [Commands Reference § 6) Sub-Agent Configuration](./commands-reference.en.md). **How each client is reminded to read the config, and why `Read` remains authoritative** — see **§ 1** (this § only explains **when** to toggle each switch).
126
+
127
+ **When to enable `subAgent: true`**: When the task is large (multi-module parallel implementation, batch document ingestion, large-scale migration). When enabled, each skill decides whether to actually split based on its own size threshold; tasks below the threshold are still completed within the main agent.
128
+
129
+ **When to enable `switchAgentVerification: true`**: When higher write consistency is needed (large-scale migration, critical design implementation). The trade-off is increased execution rounds; for routine maintenance, the default `false` is sufficient. Requires `subAgent: true` to trigger the "main-writes, sub-verifies" cross-check direction.
130
+
131
+ **When to enable `changeTracking.*`**: When you want each skill execution to automatically leave a resumable task checklist. Each skill sub-item is independently configurable without mutual interference:
132
+
133
+ ```json
134
+ {
135
+ "changeTracking": {
136
+ "feat": true,
137
+ "fix": false,
138
+ "implement": true
139
+ }
140
+ }
141
+ ```
142
+
143
+ If you prefer not to rely on configuration and want to explicitly plan tasks on demand, use `f2s-req-plan` directly.
144
+
145
+ ---
146
+
147
+ ## 5. Customization Suggestions
148
+
149
+ - When customizing the "implement from technical design" logic for your project, prioritize adjusting **`f2s-implement-tech-design`**: Cursor `.cursor/rules/f2s-implement-tech-design.mdc`, Claude `.claude/rules/f2s-implement-tech-design.md`; Codex uses `.codex/AGENTS.md` and associated `skills/` as the source of truth.
150
+ - Running `init` again by default only fills in missing templates and performs package-level structural alignment — it does **not** replace `f2s-*` skills for maintaining business content. To reset `.Knowledge` from the template, add `--reset-knowledge`.
151
+
152
+ ---
153
+
154
+ ## 6. Skill Identification
155
+
156
+ Skills are triggered by matching `name` and `description`. Files are located under `config-root/skills/*/SKILL.md`.
157
+
158
+ ---
159
+
160
+ ## 7. Related Documents
161
+
162
+ - [Commands Reference](./commands-reference.en.md)
163
+ - [Directory Conventions](./directory-conventions.en.md)
164
+ - [Architecture](./architecture.en.md)
165
+ - [Usage Scenarios](./usage-scenarios.en.md)
@@ -0,0 +1,222 @@
1
+ [中文](./Flow2Spec-使用案例-模拟对话.md) | [English](./usage-scenarios.en.md)
2
+
3
+ # Flow2Spec Usage Scenarios (Simulated Dialogues)
4
+
5
+ The following examples revolve around the same e-commerce project, covering the full pipeline from requirements clarification through post-launch maintenance.
6
+
7
+ **Prerequisite**: The project has executed `flow2spec init`, and `flow2spec.config.json` uses the default configuration (`subAgent: false`). `f2s-*` skills do not modify the configuration root `rules/` or `skills/` files.
8
+
9
+ ---
10
+
11
+ ## Scenario 1: New Requirement -> Clarification -> Technical Design
12
+
13
+ **You**
14
+
15
+ > /f2s-req-clarify The product team provided a refund requirement doc, but it does not specify whether partial refunds and full refunds go through the same API, or whether points should be reversed after a successful refund. The document is at `.Knowledge/req-docs/refund-requirements-v1.md`.
16
+
17
+ **Agent**
18
+
19
+ > I have read the requirements document. There are a few points that need clarification:
20
+ >
21
+ > 1. Do partial refunds and full refunds reuse the same endpoint, differentiated by the `amount` field, or should they be two separate endpoints?
22
+ > 2. Should points be reversed after a successful refund? If the reversal fails, should it block the refund flow?
23
+ > 3. Is the refund processed synchronously or asynchronously (T+1)?
24
+ > 4. Is there a seller-side review step?
25
+
26
+ **You**
27
+
28
+ > 1. Same endpoint, differentiated by amount; 2. Points are reversed; failure does not block the flow, retry asynchronously; 3. Asynchronous T+1; 4. No review needed.
29
+
30
+ **Agent**
31
+
32
+ > Clarification complete. Run `/f2s-req-backend` to produce the technical design.
33
+
34
+ **You**
35
+
36
+ > /f2s-req-backend
37
+
38
+ **Agent**
39
+
40
+ > Generated `.Knowledge/req-docs/refund-tech-design.md`, which includes:
41
+ > - API design: `POST /refunds`, `amount` field distinguishes full / partial refunds
42
+ > - State machine: `PENDING -> SUCCESS / FAILED`
43
+ > - Points reversal: asynchronous queue, failures go to dead letter queue, alert for manual handling
44
+ > - Error code list
45
+ >
46
+ > Next step: say "implement according to `.Knowledge/req-docs/refund-tech-design.md`" to trigger coding.
47
+
48
+ ---
49
+
50
+ ## Scenario 2: Architectural Documentation into Knowledge Base
51
+
52
+ **You**
53
+
54
+ > /f2s-doc-arch Help me draft an order service architecture document, focusing on the creation flow, payment callback, idempotency, and message delivery. The code is in `src/order` and `src/payment`.
55
+
56
+ **Agent**
57
+
58
+ > Scanned the relevant directories. Generated `.Knowledge/stock-docs/order-service-architecture-draft.md`, which includes:
59
+ > - Module boundaries and dependencies
60
+ > - Creation flow sequence diagram
61
+ > - Payment callback idempotency mechanism (based on the `payment_callback_log` table)
62
+ > - Message delivery retry strategy
63
+ >
64
+ > Confirm it looks good, then run `/f2s-doc-final` to normalize the format.
65
+
66
+ **You**
67
+
68
+ > /f2s-doc-final .Knowledge/stock-docs/order-service-architecture-draft.md
69
+
70
+ **Agent**
71
+
72
+ > Generated `.Knowledge/stock-docs/order-service-architecture-final.md`, formatted according to the final-draft template, with placeholders for items still to be filled in.
73
+
74
+ **You**
75
+
76
+ > f2s-ctx-build .Knowledge/stock-docs/order-service-architecture-final.md
77
+
78
+ **Agent**
79
+
80
+ > Knowledge base sync complete:
81
+ > - Added `.Knowledge/topics/order-service.md`
82
+ > - Updated `.Knowledge/manifest-routing.json` (added routing rule)
83
+ > - Generated `.Knowledge/matchers/order-service.json` (keywords: order creation, payment callback, idempotency, message delivery)
84
+ > - Updated `.Knowledge/index.md`
85
+ >
86
+ > Future tasks related to the order service will automatically hit this topic.
87
+
88
+ ---
89
+
90
+ ## Scenario 3: Implementation from Technical Design
91
+
92
+ **You**
93
+
94
+ > Implement according to `.Knowledge/req-docs/refund-tech-design.md`. Only modify `src/refund/`; do not touch the payment module.
95
+
96
+ **Agent**
97
+
98
+ > I have read the design document. Task list for implementation:
99
+ >
100
+ > 1. Create `RefundController` with `POST /refunds`
101
+ > 2. Create `RefundService` with state machine transition logic
102
+ > 3. Create `RefundRepository` for the `refund` table
103
+ > 4. Create `PointRollbackProducer` to send rollback messages to the points queue
104
+ > 5. Unit tests covering state machine transitions
105
+ >
106
+ > Before proceeding, I need to confirm:
107
+ > - Does the `refund` table already exist, or do I need to generate a migration?
108
+ > - What is the points queue topic name?
109
+
110
+ **You**
111
+
112
+ > The table already exists; no migration needed. The topic is `point-rollback-events`.
113
+
114
+ **Agent**
115
+
116
+ > Completed all 5 tasks above, all within `src/refund/`. Did not touch `src/payment/`.
117
+ >
118
+ > **Requires manual action**:
119
+ > - Consumer side for `point-rollback-events` (on the points service side)
120
+ > - Dead letter monitoring and alerting rule configuration
121
+ >
122
+ > Recommend running `/f2s-kb-feat` to sync this new capability into the knowledge base.
123
+
124
+ ---
125
+
126
+ ## Scenario 4: PDF Design -> Implementation
127
+
128
+ **You**
129
+
130
+ > /f2s-doc-pdf /Users/me/Downloads/marketing-coupon-v2.pdf
131
+
132
+ **Agent**
133
+
134
+ > Converted and saved as `.Knowledge/req-docs/marketing-coupon-v2.md`. Filled in the idempotency handling flow description and error code explanations that were missing in the PDF.
135
+
136
+ **You**
137
+
138
+ > Implement according to `.Knowledge/req-docs/marketing-coupon-v2.md`
139
+
140
+ **Agent**
141
+
142
+ > I have read the design document. Task list for implementation:
143
+ >
144
+ > 1. Create `CouponController` (coupon claim, redemption, and return endpoints)
145
+ > 2. Create `CouponService` with inventory deduction and idempotency checks
146
+ > 3. ...
147
+ >
148
+ > Before proceeding, I need to confirm: is the coupon inventory managed via Redis or database row locks?
149
+
150
+ ---
151
+
152
+ ## Scenario 5: Post-Implementation Knowledge Base Recording
153
+
154
+ **You**
155
+
156
+ > /f2s-kb-sync The refund feature has gone live. Help me record the payment failure retry queue naming, dead letter table fields, and monitoring alerting criteria into the knowledge base. Give me an outline first so I can confirm before you write.
157
+
158
+ **Agent**
159
+
160
+ > Knowledge base update outline (pending confirmation):
161
+ >
162
+ > **Update topic**: `order-service` (already exists)
163
+ >
164
+ > - Add "Payment Failure Retry Mechanism": queue name `payment-retry-queue`, max retries 3, intervals 30s / 120s / 300s
165
+ > - Add "Dead Letter Table": table name `payment_dead_letter`, fields `order_id / error_code / retry_count / created_at`
166
+ > - Add "Monitoring Criteria": alert threshold `retry_count >= 3`, notification channel DingTalk
167
+ >
168
+ > Confirm to write, or let me know what needs to be changed.
169
+
170
+ **You**
171
+
172
+ > Confirm, go ahead and write.
173
+
174
+ **Agent**
175
+
176
+ > Updated `.Knowledge/topics/order-service.md`. `manifest-routing` unchanged (topic already exists).
177
+
178
+ ---
179
+
180
+ ## Scenario 6: Non-compliant Implementation Found, Fix and Sync Knowledge Base
181
+
182
+ **You**
183
+
184
+ > /f2s-kb-fix `RefundService` directly calls `new RestTemplate()`, which violates the Spring Bean injection convention.
185
+
186
+ **Agent**
187
+
188
+ > Fixed: Line 34 of `RefundService.java` changed to constructor injection; `RefundConfig` supplemented with `@Bean` declaration.
189
+ >
190
+ > Knowledge base synced: the "HTTP Client Conventions" section in `.Knowledge/stock-docs/` has been updated, noting that `RestTemplate` must be injected as a Bean, and direct instantiation is prohibited.
191
+
192
+ ---
193
+
194
+ ## Scenario 7: Knowledge Base Conflicts After Git Merge
195
+
196
+ **You**
197
+
198
+ > /f2s-kb-merge `.Knowledge/index.md` and `.Knowledge/stock-docs/order-service-architecture-final.md` have conflict markers after the merge. I have already resolved the conflicts in the business code manually.
199
+
200
+ **Agent**
201
+
202
+ > Scanned the conflict markers in both files:
203
+ >
204
+ > - `index.md`: 2 conflicts, both in topic description fields. Took the HEAD version (newer content). Resolved automatically.
205
+ > - `order-service-architecture-final.md`: 1 conflict. The "monitoring alert threshold" differs between branches (3 vs. 5). Please confirm which one to keep.
206
+
207
+ **You**
208
+
209
+ > Use 3.
210
+
211
+ **Agent**
212
+
213
+ > All conflict markers have been cleaned up per your confirmation. The files are ready to commit.
214
+
215
+ ---
216
+
217
+ ## Related Documentation
218
+
219
+ - [Usage Guide](./usage-guide.en.md)
220
+ - [Commands Reference](./commands-reference.en.md)
221
+ - [Directory Conventions](./directory-conventions.en.md)
222
+ - [Architecture](./architecture.en.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@double-codeing/flow2spec",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
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": {
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: f2s-ctx-build
3
3
  description: 根据 .Knowledge/stock-docs 文档生成知识路由主题与索引;触发:生成项目上下文、f2s-ctx-build、终稿生成上下文
4
+ ---
4
5
 
5
6
  > 执行口径:本技能只维护 `.Knowledge`(`topics/index/manifest-routing/matchers` 分片),不改配置根 `rules/skills`。不再维护 `.Knowledge/manifest-matchers.json`(已废弃聚合文件;`flow2spec init` 会删除遗留副本)。
6
7