@double-codeing/flow2spec 3.0.8 → 3.0.11

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,651 @@
1
+ [中文](./README-命令说明.md) | [English](./commands-reference.en.md)
2
+
3
+ # Workflow and Skill Reference
4
+
5
+ ## 1) Document Curation (stock-docs Pipeline)
6
+
7
+ ### `f2s-doc-arch`
8
+
9
+ **Purpose**: Generates an architecture overview draft based on user descriptions or code scanning. No fixed format required; it should clearly describe the system structure, module relationships, and key decisions.
10
+
11
+ **How It Works**: Centered on inventory-driven scanning: the main agent first produces a module inventory and a scan contract (which entry points to read, which dimensions to focus on), then performs read-only code scanning according to that inventory, and finally aggregates the results into a human-readable architecture draft persisted under `stock-docs/`. The flow does not change code; it is one-way "code → document" extraction only.
12
+
13
+ **Use Cases**:
14
+ - A new project needs architecture documentation
15
+ - An existing project needs architecture descriptions supplemented
16
+ - Architecture descriptions need updating after a system refactor
17
+
18
+ **Relationships**:
19
+ - **Prerequisite**: None
20
+ - **Next Step**: `f2s-doc-final` (normalized final draft) or direct use with `f2s-ctx-build`
21
+ - **Output**: `.Knowledge/stock-docs/<Architecture Overview>_draft.md`
22
+
23
+ **Sub-Agent Invocation**:
24
+ - `subAgent: false` (default): The main agent scans the code and generates the output
25
+ - `subAgent: true`: Defaults to **B Mode** (main agent produces inventory + scan contract, sub-agents do parallel read-only table scans, main agent merges and persists); upgraded to **C Mode** (multi-round correction) when any of the following conditions are met: multi-workspace / monorepo, more than 20 source paths, first-round sub-tables have conflicts or gaps, or multi-source narratives have severe contradictions
26
+
27
+ **Responsibility Matrix**:
28
+ | Role | Responsibilities |
29
+ |------|-----------------|
30
+ | Main Agent | Produces inventory (entry points + core module names) and scan contract, aggregates sub-agent deliverables, persists stock-docs draft |
31
+ | Sub-Agent (B/C Mode) | Performs parallel read-only scans per the main agent's written inventory, delivers in a unified YAML schema (`source / scope / cross_refs / pending`), must not self-crop the scope |
32
+
33
+ ---
34
+
35
+ ### `f2s-doc-final`
36
+
37
+ **Purpose**: Converts PDF technical proposals or draft documents into the standardized "Final Draft Template" format, unifying the document structure for subsequent knowledge base ingestion.
38
+
39
+ **How It Works**: Unstructured or heterogeneous documents (PDF/drafts) are normalized against the built-in final-draft template: core concept tables, business rules, key flows, configuration, error handling, and other standard sections are extracted; missing section markers are filled in; the output is a consistently structured `_final.md`. The final draft is the standard input for `f2s-ctx-build`, keeping knowledge-base entry structure uniform.
40
+
41
+ **Use Cases**:
42
+ - PDF technical proposals need conversion to Markdown
43
+ - Draft documents need normalization for long-term storage
44
+ - External documents need to be incorporated into Flow2Spec management
45
+
46
+ **Relationships**:
47
+ - **Prerequisite**: PDF document or draft document
48
+ - **Next Step**: `f2s-ctx-build` (final draft imported into the knowledge base)
49
+ - **Output**: `.Knowledge/stock-docs/<Document>_final.md`
50
+
51
+ **Sub-Agent Invocation**:
52
+ - `subAgent: false` (default): The main agent completes the full workflow
53
+ - `subAgent: true`: When the PDF exceeds 50 pages or 5MB, sub-agents may be used for template application and layout drafting; sub-agents must not ask the user questions, write process descriptions, or claim final-draft compliance; the main agent identifies format gaps and accepts the finalized draft
54
+
55
+ **Responsibility Matrix**:
56
+ | Role | Responsibilities |
57
+ |------|-----------------|
58
+ | Main Agent | Identifies format gaps, accepts the finalized draft against the template and clarification document |
59
+ | Sub-Agent | Applies templates and produces layout drafts; does not ask users questions or write process descriptions |
60
+
61
+ ---
62
+
63
+ ### `f2s-ctx-build`
64
+
65
+ **Purpose**: Synchronizes documents from `stock-docs/` (architecture, final drafts) into the knowledge base routing system, generating/updating topic files, the index, manifest-routing, and matchers.
66
+
67
+ **How It Works**: Starting from a final-draft document, it runs a three-step "document → routing" mapping: (1) extract capability topics and keywords from the draft; (2) generate `topics/<topic>.md` (routing summary with execution boundaries and next-step pointers) and `matchers/<id>.json` (machine-readable `includeAny` terms); (3) register task→topic rules in `manifest-routing.json` and update the human-readable `index.md`. After that, the task routing engine can hit the topic via keywords.
68
+
69
+ **Use Cases**:
70
+ - After a final draft is complete, the knowledge base needs to "know about" these documents
71
+ - A new business domain needs routing mappings established
72
+ - Document content has been updated and the knowledge base index needs to be synced
73
+
74
+ **Relationships**:
75
+ - **Prerequisite**: `f2s-doc-arch`, `f2s-doc-final`, or a directly authored final draft
76
+ - **Next Step**: None (ready for use once imported into the knowledge base)
77
+ - **Input**: `.Knowledge/stock-docs/*.md`
78
+ - **Output**:
79
+ - `.Knowledge/topics/<topic>.md`
80
+ - `.Knowledge/index.md`
81
+ - `.Knowledge/manifest-routing.json`
82
+ - `.Knowledge/matchers/*.json`
83
+
84
+ **Sub-Agent Invocation**:
85
+ - `subAgent: false` (default): The main agent processes each document sequentially
86
+ - `subAgent: true`: Enabled when changes exceed thresholds (more than 2 topics added/modified OR more than 1 matcher added OR cross-topic bulk reference adjustments); sub-agent A writes only to `topics/`, sub-agent B writes only to `matchers/`; the main agent handles single-point edits to `manifest-routing.json` and `index.md`; sub-agents must not cross boundaries
87
+
88
+ **Responsibility Matrix**:
89
+ | Role | Responsibilities |
90
+ |------|-----------------|
91
+ | Main Agent | Single-point persist of `manifest-routing.json` and `index.md`, overall acceptance |
92
+ | Sub-Agent (topics) | Writes only topic files under `topics/`, does not touch manifest or index |
93
+ | Sub-Agent (matchers) | Writes only shard files under `matchers/`, does not touch manifest or index |
94
+
95
+ ---
96
+
97
+ ### `f2s-doc-add`
98
+
99
+ **Purpose**: Parses already-implemented capabilities (aggregated from multiple files) into the knowledge base. Suitable when code already exists but lacks documentation, or when multiple documents need to be imported into the knowledge base in a unified manner.
100
+
101
+ **How It Works**: Aggregates capability descriptions from multiple scattered sources (code, config, loose docs) and runs the full "draft → final draft → topics/index/manifest" pipeline. Unlike `f2s-ctx-build`, the input differs: `ctx-build` is driven from a single existing final draft; `doc-add` aggregates many scattered sources first, then follows the same pipeline. It closes the gap of "implementation exists but documentation does not."
102
+
103
+ **Use Cases**:
104
+ - Existing code needs knowledge base documentation
105
+ - Multiple related documents need aggregated import
106
+ - Bulk import of third-party documents
107
+
108
+ **Relationships**:
109
+ - **Prerequisite**: None (can be triggered directly)
110
+ - **Next Step**: None (ends once imported into the knowledge base)
111
+ - **Flow**: Draft -> Final Draft -> topics/index/manifest
112
+
113
+ **Sub-Agent Invocation**:
114
+ - `subAgent: false` (default): The main agent processes sequentially
115
+ - `subAgent: true`: Enabled when any of the following thresholds are met; defaults to **B Mode** (main agent produces inventory, sub-agents do parallel read-only schema-based table fills, main agent merges and persists); upgraded to **C Mode** (multi-round correction) for multi-workspace / monorepo, first-round sub-table conflicts or gaps, or severe multi-source contradictions
116
+ - Thresholds: 5 or more input paths OR single source exceeds 3000 lines OR total across multiple paths exceeds 10000 lines
117
+
118
+ **Responsibility Matrix**:
119
+ | Role | Responsibilities |
120
+ |------|-----------------|
121
+ | Main Agent | Produces inventory and scan contract, aggregates sub-tables, persists topics/index/manifest |
122
+ | Sub-Agent (B/C Mode) | Performs read-only scans per the main agent's written inventory, delivers tables in schema format (`source / scope / capabilities / cross_refs / pending`); must not self-crop the scope, write manifest or index, or claim "already in the knowledge base" |
123
+
124
+ **Cross-Verification (when `switchAgentVerification: true`)**:
125
+ - Topic files persisted by sub-agents -> Main agent verifies routing mapping completeness and keyword coverage
126
+ - Only effective when `subAgent: true` and sub-tasks are actually dispatched; otherwise all verification happens within the main agent
127
+
128
+ ---
129
+
130
+ ### `f2s-ctx-rm`
131
+
132
+ **Purpose**: Deletes corresponding knowledge topics and index mappings based on `stock-docs` documents. Only removes reference relationships in the knowledge base, not the source documents themselves.
133
+
134
+ **How It Works**: The inverse of `f2s-ctx-build` — given a `stock-docs` document path, locate its task→topic rules in `manifest-routing.json`, the corresponding `matchers/<id>.json` shard, `topics/<topic>.md`, and entries in `index.md`, and remove those references one by one. If a topic has no remaining task references after deletion, remove that topic file. Source documents are left in place; the user may delete them physically if desired.
135
+
136
+ **Use Cases**:
137
+ - A document is deprecated and needs removal from the knowledge routing
138
+ - A document was imported by mistake and its routing mapping needs revocation
139
+ - Cleaning up old mappings after document consolidation
140
+
141
+ **Relationships**:
142
+ - **Prerequisite**: A stock-docs document that has already been imported
143
+ - **Next Step**: None
144
+ - **Note**: Only deletes routing mappings, not source documents
145
+
146
+ **Sub-Agent Invocation**:
147
+ - `subAgent: false` (default): The main agent handles the full workflow (single-point deletion has low sub-agent ROI)
148
+ - `subAgent: true`: Sub-agents are used only for **batch deletion of 5 or more topics**; the main agent must control scope confirmation and `fallbackTopic` re-pointing; `manifest-routing.json` and `index.md` are always persisted by the main agent
149
+
150
+ ---
151
+
152
+ ### `f2s-doc-pdf`
153
+
154
+ **Purpose**: Converts PDF technical proposals to Markdown format, saves to `req-docs/`, and can supplement the process description.
155
+
156
+ **How It Works**: Targets the step before "implement from a proposal" — extracts structured content from the PDF (API definitions, data models, sequence flows, etc.) into Markdown under `req-docs/`. Unlike `f2s-doc-final`, the destination and use differ: `doc-pdf` writes to `req-docs/` for consumption by the `implement-tech-design` rule to drive coding; `doc-final` writes to `stock-docs/` for ingestion via `ctx-build`.
157
+
158
+ **Use Cases**:
159
+ - A PDF technical proposal needs to be implemented
160
+ - Historical PDF documents need to be managed
161
+ - Cross-team deliverables are in PDF format and need conversion
162
+
163
+ **Relationships**:
164
+ - **Prerequisite**: PDF document
165
+ - **Output**: `.Knowledge/req-docs/<Proposal>.md`
166
+ - **Next Step**:
167
+ - 1. If it is a requirement to implement: provide the converted proposal path with instructions "implement according to the technical proposal", driven by the `implement-tech-design` rule
168
+ - 2. If it is for knowledge base archival: follow the final-draft conversion flow `f2s-doc-final` -> `f2s-ctx-build`
169
+
170
+ **Sub-Agent Invocation**:
171
+ - `subAgent: false` (default): The main agent completes the full workflow
172
+ - `subAgent: true`: When the PDF exceeds 50 pages or 5MB, sub-agents may be used for the PDF -> MD first draft and persist to `req-docs`; sub-agents must not ask the user questions or supplement process description sections; the main agent handles follow-up questions and process description supplementation
173
+
174
+ **Responsibility Matrix**:
175
+ | Role | Responsibilities |
176
+ |------|-----------------|
177
+ | Main Agent | Asks the user for process description supplements, completes `req-docs` deposition acceptance |
178
+ | Sub-Agent | Only performs PDF -> MD first draft and persists to `req-docs`, does not ask the user questions |
179
+
180
+ ---
181
+
182
+ ## 2) Requirements and Proposals
183
+
184
+ ### `f2s-req-clarify`
185
+
186
+ **Purpose**: Asks clarifying questions against PRDs/requirement documents, using multi-round Q&A to define requirement boundaries, non-goals, and key flows, until the requirements are clear enough for a technical proposal.
187
+
188
+ **How It Works**: Uses a "structured questioning" strategy — decomposes the requirement document along six dimensions (roles, scenarios, flows, boundaries, exceptions, non-goals), checks each for vague wording, undefined concepts, or contradictions, and generates targeted questions for each gap. Dialogue continues until all dimensions are unambiguous, then outputs a clarification record as input for `f2s-req-backend`. It turns unstructured PRDs into structured, actionable requirement constraints.
189
+
190
+ **Use Cases**:
191
+ - First step after receiving a PRD, ensuring correct understanding
192
+ - When requirement boundaries are fuzzy or acceptance criteria are missing
193
+ - Cross-team collaboration requirements that need clear interface contracts
194
+
195
+ **Relationships**:
196
+ - **Prerequisite**: None (can be triggered directly)
197
+ - **Next Step**: `f2s-req-backend` (generates a technical proposal after clarification)
198
+ - **Output**: Requirement clarification record (optionally saved to `.Knowledge/req-docs/`)
199
+
200
+ **Sub-Agent Invocation**: None (clarification relies on continuous dialogue and immediate user feedback throughout; no sub-agent splitting)
201
+
202
+ ---
203
+
204
+ ### `f2s-req-backend`
205
+
206
+ **Purpose**: Based on clarified requirements and the project knowledge base, generates a backend technical proposal document including API design, data models, flow descriptions, error codes, etc.
207
+
208
+ **How It Works**: Centered on "knowledge base constraints + template-driven" authoring — first pull a constraint summary for the current project from `topics/stock-docs` (architecture conventions, API style, data model norms, etc.), then fill the backend technical proposal template (APIs / models / flows / errors / config / migrations) chapter by chapter against the clarified requirements so the proposal matches the existing architecture. Output is persisted under `req-docs/` as the coding contract for `implement-tech-design`.
209
+
210
+ **Use Cases**:
211
+ - After `f2s-req-clarify` completes, output a proposal based on clarification results
212
+ - When clear requirement documents already exist, directly generate a technical proposal
213
+
214
+ **Relationships**:
215
+ - **Prerequisite**: `f2s-req-clarify` (recommended) or a clear requirement document
216
+ - **Output**: `.Knowledge/req-docs/<Technical Proposal>.md`
217
+ - **Next Step**: Provide the technical proposal path with instructions "implement according to the technical proposal", driven by the `implement-tech-design` rule
218
+
219
+ **Sub-Agent Invocation**:
220
+ - `subAgent: false` (default): The main agent completes the proposal within the session
221
+ - `subAgent: true`: The main agent must first extract a project convention summary (under 80 lines) from topics/stock-docs (covering architecture conventions, API style, data model standards, etc. across 6 categories) as the mandatory sub-agent context, then dispatch sub-agents to write the `req-docs` draft in parallel; the main agent handles contract finalization and acceptance
222
+
223
+ **Responsibility Matrix**:
224
+ | Role | Responsibilities |
225
+ |------|-----------------|
226
+ | Main Agent | Extracts project convention summary, assigns writing tasks, finalizes the draft against the template, and writes to `req-docs` |
227
+ | Sub-Agent | Read-only access to multiple sources (topics / stock-docs / clarified req-docs / templates), writes `req-docs` draft per template; must not expand the read scope on its own |
228
+
229
+ **Cross-Verification (when `switchAgentVerification: true`)**:
230
+ - API/model/flow documents persisted by sub-agents -> Main agent verifies cross-chapter consistency (API signatures align with data models, flows and error handling coverage)
231
+ - Only effective when `subAgent: true` and sub-tasks are actually dispatched; otherwise all verification happens within the main agent
232
+
233
+ ---
234
+
235
+ ### `f2s-req-plan`
236
+
237
+ **Purpose**: Starting from a technical proposal or requirement description, **always creates a task checklist**, then implements the code accordingly. Does not depend on the `changeTracking` configuration; represents the user's explicit need for traceable task management.
238
+
239
+ **How It Works**: Runs a five-phase closed loop: parse → plan → confirm → implement → archive. (1) Parse the technical proposal for implementation points; (2) split into executable tasks at module/feature granularity and write to `.task/`; (3) show the draft to the user, lock the checklist after confirmation; (4) implement item by item, checking off `task.md` immediately when each item completes; (5) archive when all are done. Unlike the `implement-tech-design` rule, `req-plan` always carries task tracking and can parallelize implementation with sub-agents for large work; the rule path is lightweight, single-threaded coding.
240
+
241
+ **Use Cases**:
242
+ - A technical proposal document exists and needs to be broken down into a task list before implementation
243
+ - The requirement description is complex and the user wants to confirm the checklist before starting work
244
+ - The user wants to track implementation progress across sessions
245
+
246
+ **Relationships**:
247
+ - **Prerequisite**: Technical proposal document path (`.Knowledge/req-docs/*.md` or PDF) or requirement/change description
248
+ - **Output**: `.task/active/<task-name>/task.md` + `context.md`; implementation code
249
+ - **Next Step**: Optionally invoke `f2s-kb-sync` to supplement the knowledge base
250
+
251
+ **Sub-Agent Invocation**:
252
+ - `subAgent: false` (default): The main agent completes parsing, confirmation, and implementation in full
253
+ - `subAgent: true`: Step 1 (document parsing) can dispatch sub-agents for parallel read-only; Step 2 (draft confirmation) must be done by the main agent; Step 4 (code implementation) can dispatch sub-agents per module; `todo.json` is always written by the main agent
254
+
255
+ **Responsibility Matrix**:
256
+ | Role | Responsibilities |
257
+ |------|-----------------|
258
+ | Main Agent | Outputs draft, gets user confirmation, writes `todo.json`, aggregates implementation summary |
259
+ | Sub-Agent (parsing) | Read-only document parsing, outputs parsing result summary, does not persist |
260
+ | Sub-Agent (implementation) | Implements code per module, does not touch `.task/` or `.Knowledge/` |
261
+
262
+ ---
263
+
264
+ ## 3) Git Commit
265
+
266
+ ### `f2s-git-commit`
267
+
268
+ **Purpose**: Executes a Git commit after code is written. Automatically checks changed files, compares knowledge base coverage, prompts the user about capabilities not yet imported, and performs the commit after the commit message is confirmed.
269
+
270
+ **How It Works**: Layers a "knowledge base coverage gate" on top of `git commit` — infer touched capability areas from `git diff`, cross-check against `.Knowledge/topics/` and `stock-docs/`, and decide whether changed capabilities are documented in the knowledge base. If not covered, block and offer three choices (document first / skip / cancel) to avoid silent drift where "code exists but the knowledge base does not know." Commit messages use emoji + Conventional Commits for consistent, machine-friendly `git log`.
271
+
272
+ **Use Cases**:
273
+ - Committing code after each feature implementation or bug fix
274
+ - Wanting reminders about knowledge base coverage at commit time
275
+ - Needing AI help to generate meaningful commit messages
276
+
277
+ **Relationships**:
278
+ - **Prerequisite**: Code has been written (after `implement-tech-design`, `f2s-kb-fix`, `f2s-kb-feat`, etc.)
279
+ - **Next Step**: None (ends when commit completes; does not auto-push)
280
+ - **Bridging**: If the knowledge base is not yet covered, you can first run `f2s-kb-sync` or `f2s-kb-feat` to supplement before committing
281
+
282
+ **Execution Flow**:
283
+ 1. `git status --short` + `git diff HEAD` to classify files into staged / unstaged / untracked; immediately terminates if merge conflict markers are found
284
+ 2. Compare `.Knowledge/topics/` and `stock-docs/` to determine whether the changed capabilities have been imported; skips and notifies if `.Knowledge` does not exist
285
+ 3. If not covered, prompt the user to choose: A) Import first, then commit / B) Commit now, import later / C) Cancel
286
+ 4. Generate a commit message draft based on `git diff` content, wait for user confirmation or changes
287
+ 5. `git add <specific files>` + `git commit`; if a hook fails, prompt for fix, do not skip
288
+ 6. Output the commit hash; if option B was selected, include a reminder about capabilities not yet imported
289
+
290
+ **Constraints**:
291
+ - `git add -A` / `git add .` is forbidden; only add confirmed changed files
292
+ - `--no-verify` is forbidden; hook failures must be fixed and retried
293
+ - Auto-push is forbidden
294
+ - The commit message must be confirmed by the user; silent commits are not allowed
295
+
296
+ **Sub-Agent Invocation**: None (full interactive confirmation, handled within the main agent)
297
+
298
+ ---
299
+
300
+ ## 4) Knowledge Base Maintenance
301
+
302
+ ### `f2s-kb-fix`
303
+
304
+ **Purpose**: Fixes code based on implementation or rule errors reported by the user, and **by default automatically syncs** the knowledge base documents and index.
305
+
306
+ **How It Works**: Three steps: locate → fix → sync. From the user's description, locate context and code via the knowledge routing path (manifest → topic → stock-docs) and confirm root cause; after fixing code, automatically check whether related descriptions in `topics/stock-docs/matchers` need updates and revise in place if so (current truth only, no stacked historical negation). "Fix code, sync docs" is the core principle to prevent knowledge drift.
307
+
308
+ **Use Cases**:
309
+ - Code implementation does not match the technical proposal
310
+ - Rule understanding errors need correction
311
+ - Documentation needs to be synced after bug fixes
312
+
313
+ **Change Tracking**: If `changeTracking.fix: true`, automatically checks `.task/todo.json` before execution, creates a task checklist, and automatically archives upon completion; cross-session continuation via keywords is supported (see `f2s-task` rules).
314
+
315
+ **Relationships**:
316
+ - **Prerequisite**: Problem discovered (code implementation error or rule deviation)
317
+ - **Next Step**: None (ends when fixes and sync are complete)
318
+ - **Feature**: No need for the user to explicitly request "please sync the knowledge base"; it is done automatically
319
+
320
+ **Sub-Agent Invocation**:
321
+ - `subAgent: false` (default): The main agent completes fixes and knowledge base sync
322
+ - `subAgent: true`: Code sub-packages (bug fixes) can be outsourced to sub-agents; documentation sub-packages (rules/skills/topics style-related) default to the main agent writing directly; if sub-agents are used, they only output before/after diff snippets, not full-file rewrites; manifest and index are always persisted by the main agent
323
+
324
+ **Responsibility Matrix**:
325
+ | Role | Responsibilities |
326
+ |------|-----------------|
327
+ | Main Agent | Locates root cause, devises fix plan, persists style-compliant content, verifies knowledge base consistency |
328
+ | Sub-Agent (code) | Responsible for bug fixes in designated modules, outputs changes and reports impact scope |
329
+ | Sub-Agent (documentation, optional) | Only outputs before/after diff snippets, no full-file rewrites, does not touch manifest or index |
330
+
331
+ **Cross-Verification (when `switchAgentVerification: true`)**:
332
+ - Code changes persisted by sub-agents -> Main agent verifies fix correctness and knowledge base consistency
333
+ - Knowledge base sync persisted by the main agent -> Sub-agent reviews topic/manifest consistency (requires `subAgent: true` and sub-tasks actually dispatched; otherwise self-verification within the main agent)
334
+ - The reviewer and the persister must be different agent instances
335
+
336
+ ---
337
+
338
+ ### `f2s-kb-feat`
339
+
340
+ **Purpose**: When adding a new capability, completes both the implementation and the knowledge base; if the capability is already implemented, only syncs the knowledge base.
341
+
342
+ **How It Works**: Three phases: assess → implement → ingest. First assess whether the described capability is not implemented, partially implemented, or already implemented in code; if not or partial, complete the code first; then sync the knowledge base: write a capability description in `stock-docs`, generate or update `topics` summaries, register routing in `manifest-routing` and `matchers`. Unlike `f2s-kb-fix`, `kb-feat` targets **new** work; `kb-fix` targets **correcting existing** work.
343
+
344
+ **Use Cases**:
345
+ - New feature development
346
+ - Adding knowledge base documentation for an existing feature
347
+
348
+ **Change Tracking**: If `changeTracking.feat: true`, automatically checks `.task/todo.json` before execution, creates a task checklist, and automatically archives upon completion; cross-session continuation via keywords is supported (see `f2s-task` rules).
349
+
350
+ **Relationships**:
351
+ - **Prerequisite**: None (can be triggered directly)
352
+ - **Next Step**: None (ends when implementation + sync are complete)
353
+ - **Feature**: Knowledge base sync is automatic; no additional user request needed
354
+
355
+ **Sub-Agent Invocation**:
356
+ - `subAgent: false` (default): The main agent completes everything
357
+ - `subAgent: true`: Code sub-packages (new implementation) can be outsourced to sub-agents; documentation sub-packages (rules/skills/topics style-related) default to the main agent writing directly; if sub-agents are used, they only output before/after diff snippets; manifest and index are always persisted by the main agent
358
+
359
+ **Responsibility Matrix**:
360
+ | Role | Responsibilities |
361
+ |------|-----------------|
362
+ | Main Agent | Defines capability boundaries and implementation scope, persists style-compliant content, performs final verification of knowledge base consistency |
363
+ | Sub-Agent (code) | Responsible for code implementation (APIs, logic, data layer), outputs implementation checklist |
364
+ | Sub-Agent (documentation, optional) | Only outputs before/after diff snippets, no full-file rewrites, does not touch manifest or index |
365
+
366
+ **Cross-Verification (when `switchAgentVerification: true`)**:
367
+ - Topics persisted by documentation sub-agents -> Main agent verifies consistency between the capability description and the implementation code
368
+ - Only effective when `subAgent: true` and sub-tasks are actually dispatched; otherwise all verification happens within the main agent
369
+
370
+ ---
371
+
372
+ ### `f2s-kb-sync`
373
+
374
+ **Purpose**: Sinks already-implemented capabilities from the conversation back into the knowledge base. Can accept an explicit capability description or infer with zero input.
375
+
376
+ **Use Cases**:
377
+ - Implementation is complete within the conversation and needs knowledge base documentation
378
+ - Reverse-documenting knowledge from code
379
+ - Periodic knowledge base organization
380
+
381
+ **Relationships**:
382
+ - **Prerequisite**: None (can be triggered directly, or with zero-input inference)
383
+ - **Next Step**: None
384
+ - **Feature**: First outputs a knowledge base update outline, then writes only after user confirmation
385
+ - **Difference from `f2s-ctx-build`**: `ctx-build` is driven from `stock-docs`; `kb-sync` infers from the conversation/code
386
+
387
+ **Sub-Agent Invocation**:
388
+ - `subAgent: false` (default): The main agent completes inference and sync
389
+ - `subAgent: true`: Steps are split -- **Step 1** (aggregation and inference) can dispatch sub-agents for parallel read-only access to conversation history; **Step 2** (user confirmation of the outline) must be done by the main agent; **Step 3** (persist sync) can dispatch sub-agents to write topic/matcher files, but sub-agents must read 2-3 neighboring topic summaries for style alignment before persisting; manifest and index are always persisted by the main agent
390
+
391
+ **Responsibility Matrix**:
392
+ | Role | Responsibilities |
393
+ |------|-----------------|
394
+ | Main Agent | Outputs outline and gets confirmation, single-point persists manifest and index, final acceptance |
395
+ | Sub-Agent (aggregation) | Read-only access to conversation history, infers capability points, generates structured update outline fragments |
396
+ | Sub-Agent (sync) | Writes topic/matcher per outline, loads neighboring topic summaries for style alignment before persisting, does not touch manifest or index |
397
+
398
+ **Cross-Verification (when `switchAgentVerification: true`)**:
399
+ - Topics/matchers persisted by sync sub-agents -> Main agent verifies cross-topic routing completeness and `includeAny` keyword coverage
400
+ - Only effective when `subAgent: true` and sub-tasks are actually dispatched; otherwise all verification happens within the main agent
401
+
402
+ ---
403
+
404
+ ### `f2s-kb-merge`
405
+
406
+ **Purpose**: Resolves editor context conflicts after Git merges. An optional conflict file path can be provided.
407
+
408
+ **How It Works**: Layered by file kind — split conflict files into "safe to auto-merge" (structured files such as index, manifest, matchers, using union or latest) vs "needs user judgment" (implementation code, business rules, and other semantic files). Auto-resolve the former; for the latter, produce a comparison table (ours/theirs summary + recommendation) and list differences for the user to decide item by item. Design idea: knowledge-base metadata can be automated; business semantics must not be decided unilaterally.
409
+
410
+ **Use Cases**:
411
+ - Context conflicts arise after a Git merge/rebase
412
+ - Knowledge base file conflicts caused by multi-person collaboration
413
+ - Need to unify knowledge base state after branch merging
414
+
415
+ **Relationships**:
416
+ - **Prerequisite**: Conflicts generated by a Git merge
417
+ - **Next Step**: None (ends when conflicts are resolved)
418
+ - **Feature**: Implementation-side conflicts are only listed for the user to confirm
419
+
420
+ **Sub-Agent Invocation**:
421
+ - `subAgent: false` (default): The main agent analyzes and resolves conflicts
422
+ - `subAgent: true`: Sub-agents can be dispatched for conflict scanning and classification into a comparison table (`file / category / ours_summary / theirs_summary / recommendation`); sub-agents must not merge files on their own; the main agent persists per strategy, handles implementation-side decisions, and completes acceptance
423
+
424
+ **Responsibility Matrix**:
425
+ | Role | Responsibilities |
426
+ |------|-----------------|
427
+ | Main Agent | Persists merge results per strategy, handles implementation-side conflict decisions, acceptance |
428
+ | Sub-Agent | Only performs conflict scanning and classification, delivers comparison table in the five-field schema, does not merge files on its own |
429
+
430
+ ---
431
+
432
+ ### `f2s-kb-migrate`
433
+
434
+ **Purpose**: Migrates an old-format knowledge base (`docs-index.md` + `rules/` pattern) into the `.Knowledge/` structure organized by topic.
435
+
436
+ **How It Works**: Uses the legacy `docs-index.md` and `rules/main.md(c)` as index clues, recursively finds all referenced business rules and skill files, and reorganizes by topic into `.Knowledge/` (`topics` / `stock-docs` / `req-docs`). After migration, persist `migration-report.md` (mapping table + proposed deletion paths), then clean up old files after user confirmation. A one-time structural merge of scattered rules/docs into one knowledge base.
437
+
438
+ **Use Cases**:
439
+ - Upgrading an old project to the new Flow2Spec version
440
+ - An existing knowledge base needs structured reorganization
441
+
442
+ **Relationships**:
443
+ - **Prerequisite**: Old-format knowledge base (`docs-index.md`, `rules/`, `skills/`)
444
+ - **Next Step**: `f2s-kb-upgrade` (**Flow V1**: old knowledge base must migrate first, then upgrade; **Current V2+ knowledge base** (including npm v3.x): see the upgrade skill Step 0)
445
+ - **Flow**:
446
+ 1. Use `docs-index.md` + `rules/main.md(c)` as the primary index
447
+ 2. Process all business `rules/` and business `skills/` in full (excluding `f2s-*` package skills)
448
+ 3. Migrate all `stock-docs`/`req-docs`
449
+ 4. Persist `.Knowledge/migration-report.md`
450
+ 5. Delete migrated old files after user confirmation
451
+
452
+ **Sub-Agent Invocation**:
453
+ - `subAgent: false` (default): The main agent migrates topic by topic
454
+ - `subAgent: true`: Sub-agents only handle migration + draft migration-report fragments (delivered as patches); status files (migration-report.md, deletion execution records) are exclusively persisted by the main agent; the main agent leads the deletion confirmation and closure
455
+
456
+ **Responsibility Matrix**:
457
+ | Role | Responsibilities |
458
+ |------|-----------------|
459
+ | Main Agent | Creates migration plan, consolidates migration results, persists migration-report, leads deletion confirmation and execution closure |
460
+ | Sub-Agent | Handles topic migration and draft fragment generation (patch format) for designated topics; does not write status files or deletion execution records |
461
+
462
+ **Cross-Verification (when `switchAgentVerification: true`)**:
463
+ - Topics migrated and persisted by sub-agents -> Main agent verifies migration completeness (whether old paths are fully covered, whether topic boundaries overlap)
464
+ - Only effective when `subAgent: true` and sub-tasks are actually dispatched; otherwise all verification happens within the main agent
465
+
466
+ ---
467
+
468
+ ### `f2s-kb-upgrade`
469
+
470
+ **Purpose**: Knowledge base template upgrade. Aligns manifest-routing and matchers shards.
471
+
472
+ **How It Works**: Uses "version branching + delegated init" — detect whether the current knowledge base is V1 (legacy structure, migrate first) or V2+ (already has `.Knowledge`): V1 runs migrate then init; V2+ runs `flow2spec init` directly for incremental package alignment (new templates, manifest schema upgrades, matcher shard format alignment). After upgrade, re-read SKILL.md to see if certain steps must be re-run. Unlike a standalone `init`, `kb-upgrade` includes version routing and re-run logic; `init` alone is a one-shot structural fill-in.
473
+
474
+ **Use Cases**:
475
+ - After a `flow2spec` package version upgrade, upgrade the project knowledge base template
476
+ - Upgrade an old project to the latest structure
477
+
478
+ **Relationships**:
479
+ - **Prerequisite**: `f2s-kb-migrate` (V1 flow) or an existing `.Knowledge/`
480
+ - **Includes**: Internally invokes `flow2spec init` for structural alignment
481
+ - **Note**: A standalone `flow2spec init` is **not** an upgrade command
482
+
483
+ **Flow Differences (in-skill routing codes, **not** equivalent to npm major versions)**:
484
+ - **V1**: First `f2s-kb-migrate`, then runs `flow2spec init`
485
+ - **Current Knowledge Base (V2+)**: When `.Knowledge` + `manifest-routing` are already stable, runs `flow2spec init` to align manifest-routing + matchers shards (**includes Flow2Spec npm v3.x, etc.**; see `skills/f2s-kb-upgrade/SKILL.md` Step 0 for details)
486
+
487
+ **Sub-Agent Invocation**:
488
+ - `subAgent: false` (default): The main agent completes the upgrade
489
+ - `subAgent: true`: Sub-agents only handle shell command execution (running `flow2spec init`), not knowledge base content persistence; the following steps must not be delegated by the main agent: version routing (V1 / Current V2+), re-reading SKILL.md after init and determining a full skill re-run, Step 3b index.md consolidation, verification summary output
490
+
491
+ **Responsibility Matrix**:
492
+ | Role | Responsibilities |
493
+ |------|-----------------|
494
+ | Main Agent | Version routing, re-reading and determining re-run after init, Step 3b index.md consolidation, verification summary; persists `manifest-routing.json` and `index.md` |
495
+ | Sub-Agent | Only runs shell commands like `flow2spec init`, does not persist knowledge base content |
496
+
497
+ **Cross-Verification**: This skill is not bound to cross-verification; self-verification by the persisting side.
498
+
499
+ ---
500
+
501
+ ## 5) Rule Descriptions
502
+
503
+ The following are not skill commands but rules activated by trigger words to guide Agent behavior.
504
+
505
+ ### `f2s-karpathy-guidelines`
506
+
507
+ **Trigger Words**: `alwaysApply` (always on; no explicit trigger needed)
508
+
509
+ **Purpose**: Flow2Spec's built-in Karpathy-style coding discipline to improve the quality of agent coding decisions.
510
+
511
+ **How It Works**: Four behavioral constraints distilled from Andrej Karpathy's observations on common LLM coding mistakes, applied as an `alwaysApply` rule that implicitly governs all `f2s-*` skill runs: (1) think before coding (state assumptions; ask when unsure); (2) simplicity first (minimum code to solve the problem); (3) surgical edits (touch only what must change; match existing style); (4) goal-driven execution (define verifiable success criteria, then iterate). When these guidelines conflict with mandatory `f2s-*` steps, the `f2s-*` steps win.
512
+
513
+ ---
514
+
515
+ ### `f2s-task`
516
+
517
+ **Trigger Words**: changeTracking, change tracking, task tracking, continuation, continue last task
518
+
519
+ **Purpose**: Change tracking rules (`alwaysApply`). When the corresponding skill's `changeTracking.*` is set to `true`, automatically creates, progressively updates, and finally archives task checklists under `.task/` before and after skill execution, supporting cross-session continuation.
520
+
521
+ **How It Works**: Cross-session persistence via "disk checkpoints + keyword matching" — each active task records progress with checkboxes (`[ ]` / `[x]`) in `.task/active/<name>/task.md`, with `todo.json` as the active-task index. At the start of a new session, the rule fuzzy-matches the user's first message to each task's `keywords`; on a match, it loads the remaining steps in `task.md` and the skill file for `linkedSkill`, restoring full execution context. Completed tasks move to `completed/`. Design: the file system, not chat memory, is the source of truth so interrupted sessions do not lose progress.
522
+
523
+ **Scope**:
524
+
525
+ | Config Item | Corresponding Skill |
526
+ |-------------|-------------------|
527
+ | `changeTracking.feat` | `f2s-kb-feat` |
528
+ | `changeTracking.fix` | `f2s-kb-fix` |
529
+ | `changeTracking.implement` | `f2s-implement-tech-design` |
530
+
531
+ **Cross-Session Continuation**: When a new session starts and `.task/todo.json` exists, automatically matches the user's first message against each task's `keywords`; on a match, loads the corresponding `task.md` and `linkedSkill` skill file, displays the remaining checklist, and asks whether to continue; if there is no match, proceeds without interruption.
532
+
533
+ **Rule Location**: `Config Root/rules/f2s-task.*`
534
+
535
+ ---
536
+
537
+ ### `stock-docs-vs-req-docs`
538
+
539
+ **Trigger Words**: stock-docs, req-docs, implemented capability, where to put the technical proposal, PDF final draft
540
+
541
+ **Purpose**: Distinguishes the boundary between the knowledge archival directory and the requirements implementation directory.
542
+
543
+ **How It Works**: "Purpose isolation" to avoid mixing folders — `stock-docs/` holds archived existing knowledge (architecture, final drafts), consumed by `ctx-build` for ingestion into the knowledge base and **must not** be used directly as coding input; `req-docs/` holds implementation-facing requirements and technical proposals, consumed by the `implement-tech-design` rule to drive coding. Writers and readers are fully separated so "stock descriptions are not mistaken for coding contracts" and "implementation proposals are not mistaken for capability archival."
544
+
545
+ **Directory Division**:
546
+
547
+ | Directory | Purpose | When It Is Written |
548
+ |-----------|---------|-------------------|
549
+ | `stock-docs/` | Archival of existing knowledge (architecture, final drafts) | `f2s-doc-arch`, `f2s-doc-final`, `f2s-ctx-build` |
550
+ | `req-docs/` | Requirements and technical proposals (driving implementation) | `f2s-req-backend`, `f2s-doc-pdf`, manual placement |
551
+
552
+ **Use Cases**:
553
+ - Unsure where a document should go
554
+ - Need to clarify the division of labor between stock-docs and req-docs
555
+
556
+ ---
557
+
558
+ ### `implement-tech-design`
559
+
560
+ **Trigger Words**: implement according to technical proposal, implement-tech-design, implement per proposal
561
+
562
+ **Purpose**: Implements runnable code based on technical proposal documents in `req-docs/`.
563
+
564
+ **How It Works**: "Proposal as contract" — the agent treats the technical proposal in `req-docs/` as the sole coding contract and must follow the mandatory six-step pipeline: understand proposal → output task list → ask clarifying questions before coding → implement step by step → output remaining work and post-implementation reminders. The task list and pre-implementation Q&A are non-skippable gates so coding does not start on a misunderstood spec. Unlike `f2s-req-plan`, this rule is lightweight single-threaded coding and does not force `.task/` tracking unless `changeTracking.implement: true`.
565
+
566
+ **Change Tracking**: If `changeTracking.implement: true`, after outputting the task list in Step 2.5, synchronously writes to `.task/active/<task-name>/task.md`; archives the task in Step 5 during wrap-up.
567
+
568
+ **Use Cases**:
569
+ - Technical proposal is ready and needs to be coded per the proposal
570
+ - After a proposal change, code needs to be updated accordingly
571
+
572
+ **Relationships**:
573
+ - **Prerequisite**: `.Knowledge/req-docs/<Technical Proposal>.md` (via `f2s-req-backend` or manual placement)
574
+ - **Rule Location**:
575
+ - Cursor: `.cursor/rules/f2s-implement-tech-design.mdc`
576
+ - Claude: `.claude/rules/f2s-implement-tech-design.md`
577
+ - Codex: `.codex/AGENTS.md` + `.codex/topics/f2s-implement-tech-design.md`
578
+
579
+ **Execution Flow (mandatory by rules)**:
580
+ 1. Input normalization
581
+ 2. Understand the proposal and context
582
+ 3. **Output the implementation task list** (required, cannot be skipped)
583
+ 4. **Ask questions before implementing** (required, cannot be skipped)
584
+ 5. Implement per task list
585
+ 6. **Output the remaining checklist and post-implementation reminders** (required)
586
+
587
+ **Sub-Agent Invocation**: None (rule-driven coding; the main agent completes the full workflow)
588
+
589
+ ---
590
+
591
+ ## 6) Sub-Agent Configuration
592
+
593
+ Controlled via `flow2spec.config.json` at the project root (all fields default to `false`).
594
+
595
+ ### How Different Products "See" the Configuration (use with the field table below)
596
+
597
+ `subAgent` and similar fields are written to the **on-disk JSON**; products do not guarantee automatic file opening. Therefore, multi-layered hints are provided via **Cursor rules / Claude hooks / Codex AGENTS snapshot table / knowledge base `config-precheck` summary**, but **the authoritative source remains `Read("flow2spec.config.json")`** (design rationale in [design-principles.en.md — Agent Orchestration § 5.1](./design-principles.en.md); talk / deck pacing in [intro deck HTML](../presentations/flow2spec-intro-public-en/index.html), config section). **The full path and table are maintained in one place**: [usage-guide.en.md Sec. 1, `f2s-*` and `flow2spec.config.json`](./usage-guide.en.md).
598
+
599
+ ### `subAgent` Field
600
+
601
+ | Value | Behavior |
602
+ |-------|----------|
603
+ | `false` (default) | All `f2s-*` skills complete within the main agent |
604
+ | `true` | Certain skills may use sub-agents per their documentation (large-scale parallel processing scenarios) |
605
+
606
+ ### `switchAgentVerification` Field
607
+
608
+ | Value | Behavior |
609
+ |-------|----------|
610
+ | `false` (default) | Self-verification on the persisting side: whoever persists verifies |
611
+ | `true` | When a skill explicitly states this step, enables cross-verification: sub-agent persists -> main agent verifies; main agent persists -> sub-agent verifies (requires `subAgent: true` and sub-tasks actually dispatched) |
612
+
613
+ ### `changeTracking` Field
614
+
615
+ A nested object, with each skill independently controlled:
616
+
617
+ ```json
618
+ {
619
+ "changeTracking": {
620
+ "feat": false,
621
+ "fix": false,
622
+ "implement": false
623
+ }
624
+ }
625
+ ```
626
+
627
+ | Sub-field | Corresponding Skill | Effect |
628
+ |-----------|---------------------|--------|
629
+ | `feat` | `f2s-kb-feat` | Creates a task checklist before execution, archives on completion, supports cross-session continuation |
630
+ | `fix` | `f2s-kb-fix` | Same as above |
631
+ | `implement` | `f2s-implement-tech-design` | Same as above |
632
+
633
+ > `f2s-req-plan` is not constrained by this configuration; it always creates a task checklist. Legacy boolean values (`"changeTracking": true/false`) are backward-compatible and automatically expand to all three sub-fields on/off.
634
+
635
+ For full principles and design intent, see [architecture.en.md Sec. 4. Agent Execution Model](./architecture.en.md).
636
+
637
+ ---
638
+
639
+ ## 7) Quick Reference
640
+
641
+ For typical work scenarios and full workflows, see [Usage Guide § 3. Typical Workflows](./usage-guide.en.md).
642
+
643
+ For a complete directory description, see [Directory Conventions](./directory-conventions.en.md).
644
+
645
+ ---
646
+
647
+ Related Documents:
648
+ - [Usage Guide](./usage-guide.en.md)
649
+ - [Directory Conventions](./directory-conventions.en.md)
650
+ - [Architecture](./architecture.en.md)
651
+ - [Usage Scenarios](./usage-scenarios.en.md)