name: f2s-kb-add description: Parse already implemented capabilities into the knowledge base during work (multi-file aggregation): draft -> final draft -> topics/index/manifest; triggers: f2s-kb-add、已有能力进知识库、多文件生成上下文、add existing capability to knowledge base、multi-file context generation
Execution scope: this skill only maintains
.Knowledge; it does not modify the configuration-rootrules/skills.
Orchestration (main / sub-agent)
- The meaning of
subAgent/switchAgentVerificationuses the unified entry as the only source of truth: Cursor/Claude read the configuration-rootrules/f2s-flow2spec-unified-entry.*; Codex reads.codex/topics/f2s-flow2spec-unified-entry.md(same source, mirrored byflow2spec init). - Do not split by default: the main session completes the full workflow; below the threshold, sub-agent benefit is lower than context-switching cost.
- Split threshold (only when
subAgent=trueand any condition is met): (1) input paths >= 5; (2) a single source file > ~3000 lines; (3) total across paths > ~10000 lines. - Split strategy (enabled only when the split threshold is reached and
subAgent=true):- Mode B (default, single-round parallel): main first produces an "inventory" (source document path list to parse + core capability names, handwritten by main; sub-agents may not add/remove paths) + "scan contract" (which sections/line ranges to read for each source, forbidden scan directories, unified output fields and table headers) -> sub-agents read only and fill the table in parallel -> main merges + dedupes in one round -> writes
.Knowledge/stock-docs/<design-name>_draft.md-> main performs user confirmation and acceptance. Suitable when source boundaries are clear, scale is medium, and a first version is needed quickly. - Mode C (large repository / high risk, multi-round correction): before B or replacing B's first round, main creates the inventory -> sub-agents submit tables -> main performs one dedicated table comparison round (mark overlaps / conflicts / missing dependencies / cross-source boundaries) -> if needed, assign small follow-up tasks for conflicts or main reads key points directly -> main writes / finalizes. Suitable for multi-workspace / monorepo, very deep directories, source paths > 20, first-round sub-agent tables with obvious conflicts or holes, or severe overlap/conflict among sources.
- Switch criteria (switch to C if any is true): multi-workspace / monorepo; very deep directories or source paths > 20; first-round sub-agent tables have obvious conflicts / holes; source narratives overlap / conflict severely.
- Mode B (default, single-round parallel): main first produces an "inventory" (source document path list to parse + core capability names, handwritten by main; sub-agents may not add/remove paths) + "scan contract" (which sections/line ranges to read for each source, forbidden scan directories, unified output fields and table headers) -> sub-agents read only and fill the table in parallel -> main merges + dedupes in one round -> writes
- Sub-agent delivery hard rule: sub-agents may not trim the source path scope on their own; they must follow the handwritten main inventory. Delivery must use the "sub-agent YAML schema" (fields:
source/scope/capabilities/cross_refs/pending); prose replies are forbidden. Sub-agents must not writemanifest-routing.json/.Knowledge/index.md, and must not independently announce "added to knowledge base". - Main agent must control overlap judgment, final-draft finalization,
f2s-kb-builddispatch, and overall acceptance. - Write-authority hard rule:
manifest-routing.jsonand.Knowledge/index.mdare always written by the main agent. - The writing side verifies its own work.
f2s-kb-add: Multi-File Aggregation -> Draft -> Final Draft -> Knowledge Routing Sync
When to Use
- A capability has already been implemented in code, but information is scattered across multiple files and needs to be captured as searchable knowledge.
- Different from
f2s-doc-arch:doc-archproduces an architecture draft;doc-addproduces the knowledge-capture chain for an "already implemented capability".
Input
| Parameter | Required | Description |
|---|---|---|
| File path list | Yes | One or more paths (space/newline/@); supports source code, config, and docs |
| Plan name | No | Used to generate <design-name>_draft.md and <design-name>_final.md |
| Draft/final path | No | Defaults to .Knowledge/stock-docs/ |
Abort and ask the user for valid paths if no valid path is provided.
Step 0: Overlap Check (Important)
Before execution, compare against:
.Knowledge/index.md.Knowledge/topics/*.md.Knowledge/stock-docs/*.md
If the same topic has already been captured, update it in place first to avoid duplicate topics and duplicate index rows.
Step 0.5: Multi-Module Detection (Required when input paths >= 2)
- Directory aggregation: group files by functional-layer directories in paths (for example
src/<module-name>/, top-level directory names). - Judgment rules (any one hit means "multi-module"):
- Files belong to >= 2 different top-level functional directories (for example
auth/,payment/). - The user explicitly mentions "multiple features / different modules / handle separately" or similar.
- Filename prefixes are clearly different and have no common parent directory.
- Files belong to >= 2 different top-level functional directories (for example
- Single module (no trigger): do not interrupt; continue to step 1 and generate
<design-name>_draft.mdusing the existing single-output logic. - Multi-module (triggered): pause, show the grouping result to the user, and ask:
- Option A (recommended): generate knowledge files by module -> each group independently runs steps 1 -> 2 -> 3 -> 4 and outputs
<module-name>_draft.md/<module-name>_final.md. - Option B (merge): ignore module boundaries and generate one
<design-name>_draft.md(original behavior). - It is forbidden to default to option B and continue before the user explicitly chooses.
- Option A (recommended): generate knowledge files by module -> each group independently runs steps 1 -> 2 -> 3 -> 4 and outputs
- Single module but large stock-doc: if one input document or aggregated source exceeds 300-500 lines, or covers more than 3 unrelated responsibility domains, suggest to the user that it can be split into multiple focused stock-docs, each corresponding to an independent topic. If the user confirms continuing, do not block, but record "recommended later split" in the output summary.
Step 1: Moderate-Depth Analysis
- Read small files fully.
- For large files, prioritize structure and key fragments (exports, interfaces, config, flows).
- Mark uncertain content explicitly as "pending confirmation"; do not invent.
- If any split threshold is met (input paths >= 5 / single source > ~3000 lines / total across paths > ~10000 lines) and
subAgent=true, split into parallel read-only scans using Mode B (default) or Mode C (when switch criteria are met); otherwise the main agent performs the full workflow. When sub-agents are enabled, they must follow the main agent's handwritten inventory and scan contract; they must not add/remove source paths on their own.
Step 2: Generate Draft
- Default output:
.Knowledge/stock-docs/<design-name>_draft.md - Recommended draft structure:
- Overview
- Source list (including unreadable files)
- Module-by-module summary
- Cross relationships
- Pending confirmations
Step 3: Generate Final Draft
- Reference
.Knowledge/template/final-overview-template.md - Output:
.Knowledge/stock-docs/<design-name>_final.md - Must fill the
## 来源文件section, listing the original source file paths actually read in step 1. - If the user asks to "review the draft first", stop at the draft and wait for confirmation.
Step 4: Sync Knowledge Routing
Based on the final draft, use the f2s-kb-build approach to update:
.Knowledge/topics/.Knowledge/index.md- Routing manifest (when needed)
manifest-routing.json.topicMetadata(as needed): writeprimary/tags/confidenceonly for topicIds that already exist or are confirmed as created in this run;tagsmay be omitted and must not duplicateprimary. Classification is only for governance, audit, and reading expectations; it does not participate in routing or execution requirements. If evidence is insufficient, do not write metadata and list it as pending confirmation in the summary. Do not create, rename, or split topics solely for classification.
Authoring-side guideline: this step triggers adding/modifying topics and
topicDependencies, so first Read the fullrules/f2s-topic-authoring.*(Cursor/Claude:rules/f2s-topic-authoring.mdc; Codex:.codex/topics/f2s-topic-authoring.md) before invoking thef2s-kb-buildapproach to sync.
Output Summary (Required)
- Draft/final-draft paths.
- Updated topic/index/routing-manifest paths.
- Incomplete items and reasons (for example invalid paths or insufficient information).
Complex Scenario Examples
The user provides 6 files (mixed code, config, old docs), and 2 paths are unreadable.
- Continue processing readable files first, and explicitly list unreadable paths and gaps in the draft. Do not abort the whole flow because of partial failure.
- If an existing
.Knowledge/stock-docs/<capability-name>_final.mdis found, revise that final draft first instead of creating a duplicate final draft. - If the user asks to "review the draft first", stop at the draft, wait for confirmation, then generate the final draft and enter
f2s-kb-buildsync.
The user provides 3 files: src/auth/login.ts, src/payment/checkout.ts, src/notification/email.ts.
- Step 0.5 detects that the files belong to
auth/,payment/, andnotification/, three different top-level functional directories, and classifies this as "multi-module". - Show the grouping to the user:
authgroup 1 file,paymentgroup 1 file,notificationgroup 1 file; ask for option A (separate generation) or option B (merge). - User chooses option A: run steps 1 -> 2 -> 3 -> 4 for the
auth,payment, andnotificationgroups separately, outputtingauth_draft.md,payment_draft.md, andnotification_draft.md. - It is forbidden to directly merge the three modules into
综合_draft.mdbefore the user chooses.
Constraints
- Final-draft
sourceDoconly points to.Knowledge/stock-docs/*. - Do not modify the configuration-root
rules/skills. - Prefer updating the same topic; do not create duplicate parallel knowledge.
manifest-routing.jsonand.Knowledge/index.mdare always written by the main agent (write-authority hard rule); sub-agents must not touch them.
Completion Self-Check
- Draft/final-draft paths are under
.Knowledge/stock-docs/. - Duplicate creation for the same topic was avoided.
- topic/index/manifest semantics are consistent with the final draft.
- If
topicMetadatawas written: it only covers topicIds that already existed or were created in this run;primary/tags/confidenceare valid; type-prefix naming and renaming were avoided. - When input paths >= 2, step 0.5 multi-module detection was performed; if classified as multi-module, grouping was shown to the user and an explicit choice was awaited, with no default merged output.