@fenglimg/fabric-cli 2.0.0-rc.1 → 2.0.0-rc.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.
Files changed (32) hide show
  1. package/README.md +6 -6
  2. package/dist/{chunk-UHNP7T7W.js → chunk-5MQ52F42.js} +347 -86
  3. package/dist/chunk-6ICJICVU.js +10 -0
  4. package/dist/chunk-AW3G7ZH5.js +576 -0
  5. package/dist/chunk-HQLEHH4O.js +321 -0
  6. package/dist/{chunk-5LOYBXWD.js → chunk-OBQU6NHO.js} +2 -52
  7. package/dist/chunk-WPTA74BY.js +184 -0
  8. package/dist/chunk-WWNXR34K.js +49 -0
  9. package/dist/doctor-RILCO5OG.js +282 -0
  10. package/dist/hooks-NX32PPEN.js +13 -0
  11. package/dist/index.js +8 -5
  12. package/dist/{init-DRHUYHYA.js → init-C56PWHID.js} +225 -491
  13. package/dist/plan-context-hint-QMUPAXIB.js +98 -0
  14. package/dist/{scan-HU2EGITF.js → scan-66EKMNAY.js} +6 -2
  15. package/dist/{serve-3LXXSBFR.js → serve-NGLXHDYC.js} +8 -4
  16. package/dist/uninstall-DBAR2JBS.js +1082 -0
  17. package/package.json +3 -3
  18. package/templates/bootstrap/CLAUDE.md +1 -1
  19. package/templates/bootstrap/codex-AGENTS-header.md +1 -1
  20. package/templates/bootstrap/cursor-fabric-bootstrap.mdc +1 -1
  21. package/templates/hooks/configs/README.md +73 -0
  22. package/templates/hooks/configs/claude-code.json +37 -0
  23. package/templates/hooks/configs/codex-hooks.json +20 -0
  24. package/templates/hooks/configs/cursor-hooks.json +20 -0
  25. package/templates/hooks/fabric-hint.cjs +1337 -0
  26. package/templates/hooks/knowledge-hint-broad.cjs +612 -0
  27. package/templates/hooks/knowledge-hint-narrow.cjs +826 -0
  28. package/templates/hooks/lib/session-digest-writer.cjs +172 -0
  29. package/templates/skills/fabric-archive/SKILL.md +640 -0
  30. package/templates/skills/fabric-import/SKILL.md +850 -0
  31. package/templates/skills/fabric-review/SKILL.md +717 -0
  32. package/dist/doctor-DUHWLAYD.js +0 -98
@@ -0,0 +1,640 @@
1
+ ---
2
+ name: fabric-archive
3
+ description: Use this skill when the Stop-hook signals an archive opportunity (events.jsonl shows ≥5 plan_context entries since the last knowledge_proposed event, or ≥24h elapsed since the last archive), OR when the user explicitly invokes archival. The skill classifies recent session candidates into one of five knowledge types (model/decision/guideline/pitfall/process), assigns a layer (team/personal) via the verbatim heuristic, proposes a slug, presents one batch review, and persists confirmed entries through the fab_extract_knowledge MCP tool to .fabric/knowledge/pending/.
4
+ allowed-tools: Read, Glob, Grep, Bash, mcp__fabric__fab_extract_knowledge
5
+ ---
6
+
7
+ > **Surface**: This is a Skill (AI-driven, LLM judgment over session digests). See [`docs/surfaces.md`](https://github.com/fenglimg/fabric/blob/main/docs/surfaces.md) for the CLI / Skill / MCP boundary.
8
+
9
+ ## Precondition
10
+
11
+ This skill is invoked when one of the following holds:
12
+
13
+ - The Stop-hook printed a stdout JSON pointer of shape `{"decision":"block","reason":"..."}` mentioning fabric-archive
14
+ - The user typed an explicit archive request (e.g. "archive what we just did", "fabric archive")
15
+ - A task wrap-up moment where the agent itself判定 a worth-keeping insight has surfaced
16
+
17
+ If none of the above hold, stop the skill immediately and tell the user (UX i18n Policy class 2 — errors/preconditions):
18
+
19
+ - zh-CN: `没有触发归档信号;如需手动归档请显式调用 fabric-archive`
20
+ - en: `No archive signal detected; to manually archive, explicitly invoke fabric-archive`
21
+
22
+ (Render per `knowledge_language` resolved in Phase 0.6 Config Load below.)
23
+
24
+ This skill is `Check-not-Ask`, not a preference interview:
25
+
26
+ - Phase 0 proactively gathers candidate evidence from the session
27
+ - Phase 0.5 viability gate aborts the skill if the session lacks any archive-signal (anti-archive guard)
28
+ - Phase 1 classifies / layers / slugs each candidate and presents one batch review for user correction
29
+ - Phase 1.5 assigns `relevance_scope=narrow|broad` and derives `relevance_paths` from edit history (rc.5 single-signal source)
30
+ - Phase 2 calls `fab_extract_knowledge` once per confirmed candidate
31
+
32
+ ## 执行流程 (5 Phase / 1 User Review Round)
33
+
34
+ ### Phase 0.6 — Config Load
35
+
36
+ Before any candidate-gathering work, the skill MUST read
37
+ `.fabric/fabric-config.json` to resolve the following tunables (with documented
38
+ defaults if absent):
39
+
40
+ | Config field | Default | Used by |
41
+ |---|---|---|
42
+ | `archive_max_candidates_per_batch` | 8 | Phase 0 hard budget on candidates per Phase 1 batch |
43
+ | `archive_max_recent_paths` | 20 | Phase 0 cap on `recent_paths` enumeration |
44
+ | `archive_digest_max_sessions` | 10 | Phase 0.0 cap on cross-session digest load |
45
+
46
+ If `.fabric/fabric-config.json` is missing or unreadable, use defaults silently.
47
+
48
+ ### UX i18n Policy (5-class bilingualization)
49
+
50
+ The skill consults `knowledge_language` from `.fabric/fabric-config.json`
51
+ (固化于 init 时,via `scan.ts:detectExistingLanguage`; default `"en"` when no
52
+ CJK signal is detected in README + docs/). All user-facing text in the
53
+ following 5 categories MUST be rendered in the resolved language:
54
+
55
+ 1. **Roll-up templates** — the `# Archive Review — N candidates` batch
56
+ review block (one per candidate) AND any final session summary the
57
+ skill emits after Phase 2 completes. zh-CN ↔ en mirror.
58
+ 2. **Errors / Preconditions warnings** — abort + gate-fail messages (e.g.
59
+ the "没有触发归档信号…" trigger-miss and the "本次会话为常规执行…"
60
+ viability-gate-FAIL message). zh-CN ↔ en mirror.
61
+ 3. **Confirmation prompts** — the per-candidate `Confirm? (Y to accept,
62
+ edit … inline, N to skip)` line in the batch review template. zh-CN
63
+ ↔ en mirror.
64
+ 4. **Dry-run table headers** — fabric-archive does not currently expose
65
+ a dry-run mode; this slot is reserved for parity with fabric-import.
66
+ IF a future revision adds dry-run, the table header MUST be
67
+ bilingualized per this policy. zh-CN ↔ en mirror.
68
+ 5. **AskUserQuestion** — `header` + `question` fields (NOT `options[]`).
69
+ zh-CN ↔ en mirror. fabric-archive itself does not surface
70
+ AskUserQuestion in the current contract (Phase 1 batch review is a
71
+ single markdown screen, not a structured question), but if a future
72
+ version adds one — e.g. to confirm layer flip — this rule applies.
73
+
74
+ Rendering rule:
75
+
76
+ - `knowledge_language === "zh-CN"` → emit the zh-CN variant.
77
+ - `knowledge_language === "en"` (or any other value) → emit the en variant.
78
+ - The Skill MUST NOT mix languages inside a single user-facing block
79
+ (no "Chinglish" partial translation); each block is either fully zh-CN
80
+ or fully en.
81
+
82
+ Protected tokens (`fab_extract_knowledge`, `relevance_scope`,
83
+ `relevance_paths`, `narrow`, `broad`, `source_sessions`, `proposed_reason`,
84
+ `session_context`, `pending_path`, `layer`, `team`, `personal`,
85
+ `knowledge_scope_degraded`, `MUST`, `NEVER`, `.fabric/knowledge/`, the verbatim
86
+ `强 team` / `强 personal` / `默认 team` heuristic block, etc.) are NEVER
87
+ translated — they appear verbatim in both language variants. The
88
+ bilingualization scope is prose ONLY.
89
+
90
+ ### AskUserQuestion i18n Policy (value vs label)
91
+
92
+ When a skill (this one or any sibling skill the user is composing with)
93
+ issues an `AskUserQuestion`, the `header` and `question` strings are
94
+ user-facing prose → translated per `knowledge_language`. The `options[]`
95
+ array entries (e.g. `["approve", "reject", "modify", "defer", "skip"]` in
96
+ fabric-review, or `["team", "personal"]` for a layer-flip target) are
97
+ **routing keys** consumed by the skill state machine — they MUST remain
98
+ English regardless of `knowledge_language`.
99
+
100
+ ```ts
101
+ // EN (knowledge_language === "en")
102
+ AskUserQuestion({
103
+ header: "Layer-flip target",
104
+ question: "Move '{title}' to which layer? (current: {current_layer})",
105
+ options: ["team", "personal"]
106
+ })
107
+
108
+ // zh-CN (knowledge_language === "zh-CN")
109
+ AskUserQuestion({
110
+ header: "Layer 切换目标",
111
+ question: "将 '{title}' 切换到哪一层?(当前: {current_layer})",
112
+ options: ["team", "personal"] // 不翻译 — routing key
113
+ })
114
+ ```
115
+
116
+ Rationale: localizing routing keys would force every routing branch to
117
+ dual-string match (e.g. `if (choice === "team" || choice === "团队")`),
118
+ which doubles the surface area for protected-token regressions and breaks
119
+ the option-list invariants that downstream tooling depends on. Keeping
120
+ `options[]` English-only is contract-locked across all three skills.
121
+
122
+ ### Phase 0.0 — Collect Cross-Session Digests (v2.0.0-rc.7 T5)
123
+
124
+ Before any single-session collection or viability gating, stitch together
125
+ context from every session that has accumulated since the last
126
+ `knowledge_proposed` event. The rc.7 Stop hook writes a per-session digest to
127
+ `.fabric/.cache/session-digests/<session_id>.md` (≤5KB, contains top 10 user
128
+ messages + edit_paths + 1-line title), so this phase is a tail-scan + read.
129
+
130
+ 1. **Read events.jsonl tail.** Use `Bash` with
131
+ `tail -n 200 .fabric/events.jsonl` (tolerate ENOENT — empty ledger is a
132
+ normal first-run state).
133
+ 2. **Find the anchor.** Walk the tail backwards to locate the most recent
134
+ `knowledge_proposed` event (`event_type === "knowledge_proposed"`). The
135
+ anchor's `ts` becomes the lower bound for digest selection. If NO anchor
136
+ exists, treat all digests in the cache as in-scope.
137
+ 3. **Collect session_ids since anchor.** Scan the tail forward from the
138
+ anchor and collect every distinct `session_id` field that appears on any
139
+ event newer than the anchor. Distinct ordering preserved.
140
+ 4. **Load digests.** For each collected `session_id`, read
141
+ `.fabric/.cache/session-digests/<session_id>.md`. Missing digest files
142
+ degrade silently (the digest write was best-effort, so a Stop hook crash
143
+ can produce a session_id without a digest). Cap the loaded digest set at
144
+ `archive_digest_max_sessions` most-recent sessions (config-resolved, default
145
+ 10) to bound LLM context (~50KB worst-case at default).
146
+ 5. **Build cross-session context.** Concatenate the loaded digests into a
147
+ single `### Cross-session digest` block to carry into Phase 0.5 + Phase 1.
148
+ Use this block to:
149
+ - Detect session-spanning patterns (e.g. a discussion that started in
150
+ session A and continued in session B).
151
+ - Populate the `source_sessions` array on every fab_extract_knowledge
152
+ call — the array form (T5) replaces the legacy `source_session` string.
153
+ - Inform the `session_context` blob written to each pending entry's body
154
+ (3-5 lines summarizing goal + key turning point, per T6).
155
+
156
+ Graceful degradation: if `.fabric/.cache/session-digests/` is missing
157
+ entirely, this phase reports an empty context and Phase 0 falls back to the
158
+ single-session behaviour. Tests that synthesize events.jsonl without
159
+ populating the digest cache continue to work.
160
+
161
+ ### Phase 0 — Collect Candidates
162
+
163
+ Gather raw evidence from the recent session before any classification:
164
+
165
+ 1. Read the tail of `.fabric/events.jsonl` since the last `knowledge_proposed` event.
166
+ - Use `Bash` with `tail -n 200 .fabric/events.jsonl` if the file is large.
167
+ - Tolerate ENOENT — empty ledger is a normal first-run state.
168
+ 2. Enumerate `recent_paths`: workspace files touched by Read/Edit/Write in the current session. Cap at `archive_max_recent_paths` most-recent paths (config-resolved, default 20).
169
+ 3. Distill `user_messages_summary`: a compact (≤500 char) prose summary of what the user asked for and what was decided. NOT a verbatim transcript.
170
+ 4. Build a candidate list: each candidate is one observation that MIGHT be worth archiving.
171
+
172
+ Hard budget: `archive_max_candidates_per_batch` candidates max per Phase 1 batch (config-resolved, default 8). If more surface, keep the configured-N with strongest worth-archiving signals (see Phase 1 type definitions) and drop the rest.
173
+
174
+ ### Phase 0.5 — Viability Gate (Anti-Archive Guard)
175
+
176
+ Before producing any candidate output, run a coarse viability check on the session as a whole. The goal is to short-circuit obvious no-archive sessions (routine execution, typo fixes, narrow renames) so that Phase 1 batch review is never spent on noise.
177
+
178
+ #### Archive signals (≥ 1 hit ⇒ gate PASSES, proceed to Phase 1)
179
+
180
+ Scan `user_messages_summary` + `recent_paths` + the events tail collected in Phase 0:
181
+
182
+ 1. Explicit normative language: user said `always` / `never` / `from now on` / `下次注意` / `记一下` / `以后` / `永远不要`.
183
+ 2. Wrong-turn-and-revert: a path was edited, then reverted (or partially undone) after diagnosis — indicates a pitfall worth recording.
184
+ 3. Long diagnostic loop: an issue took > 15 minutes (or > ~10 tool turns) of debugging before resolution.
185
+ 4. New dependency adoption: a new package / library / external tool was introduced (e.g. `package.json` / `pyproject.toml` / `Cargo.toml` diff adds a dep).
186
+ 5. New pattern emergence: a reusable abstraction or naming convention was named ("the X phase", "the Y pattern", "let's call this Z").
187
+ 6. Decision confirmation: ≥ 2 alternatives were weighed AND a rationale was given before settling.
188
+ 7. Explicit dismissal-with-reason: user rejected an approach AND stated why (the why is the archivable knowledge, not the dismissal itself).
189
+ 8. Process formalization: a multi-step procedure was executed in a specific order AND the order was identified as load-bearing.
190
+
191
+ #### Anti-archive signals (forces gate to FAIL unless an archive signal also fires)
192
+
193
+ 1. Typo-only edits: the entire session is whitespace / spelling / formatting changes.
194
+ 2. Pure refactor: rename / move / extract with no behavior change AND no naming convention being established.
195
+ 3. Narrow rename request: user asked to rename one symbol / file with no rationale.
196
+ 4. Duplicate of existing canonical: the observation is already covered by an existing entry under `.fabric/knowledge/<type>/` (do a quick Glob before deciding).
197
+
198
+ #### Gate decision
199
+
200
+ ```
201
+ archive_signals_hit = count of archive signals fired
202
+ anti_signals_hit = count of anti-archive signals fired
203
+ user_explicit_invoke = user typed "archive what we just did" / "fabric archive" / similar
204
+
205
+ IF user_explicit_invoke:
206
+ gate = PASS # explicit invocation bypasses all gates
207
+ ELIF archive_signals_hit == 0:
208
+ gate = FAIL (reason="no_signal")
209
+ ELIF anti_signals_hit > 0 AND archive_signals_hit == 0:
210
+ gate = FAIL (reason="anti_signal_dominates")
211
+ ELSE:
212
+ gate = PASS
213
+ ```
214
+
215
+ #### On gate FAIL
216
+
217
+ Stop the skill with the gate-FAIL message (UX i18n Policy class 2 — errors/preconditions; render per `knowledge_language`):
218
+
219
+ zh-CN variant:
220
+
221
+ ```
222
+ 本次会话为常规执行,无新知识可归档(gate=<reason>)。如需强制归档,请显式调用 fabric-archive。
223
+ ```
224
+
225
+ en variant:
226
+
227
+ ```
228
+ Current session is routine execution; no new knowledge to archive (gate=<reason>). To force-archive, explicitly invoke fabric-archive.
229
+ ```
230
+
231
+ Optionally append a one-line event to `.fabric/events.jsonl` of shape `{"ts":"...","kind":"knowledge_archive_aborted","reason":"<reason>","session":"<id>"}` if the events ledger is writable; otherwise just log to stderr. Do NOT proceed to Phase 1, do NOT call any MCP tool.
232
+
233
+ ##### events.jsonl Constraint Note
234
+
235
+ Event lines appended to `.fabric/events.jsonl` are subject to POSIX
236
+ single-write atomicity: only writes ≤ 4KB (`PIPE_BUF`) are guaranteed
237
+ atomic via `Bash: echo "..." >> file`. Lines exceeding 4KB risk
238
+ interleaved corruption under concurrent skill + server writes to the
239
+ same ledger.
240
+
241
+ Skills MUST ensure:
242
+
243
+ - Each event JSON line is a **single line** (no embedded newlines;
244
+ escape `\n` in any string value).
245
+ - `session_context` and other free-form text fields **self-truncate** to
246
+ keep the entire serialized line under 4KB. Suggested per-field caps:
247
+ `session_context` first 500 chars; `source_sessions` cap at 5
248
+ entries; `recent_paths` cap at 20 entries; `user_messages_summary`
249
+ first 500 chars.
250
+ - If approaching the 4KB ceiling after the per-field caps, drop optional
251
+ fields (e.g. tags / extra metadata) **before** truncating semantic
252
+ content (the summary / context that carries the actual observation).
253
+ - This constraint applies to any event the skill itself appends (e.g.
254
+ the abort signal above); MCP-server-side appends (via
255
+ `appendEventLedgerEvent`) are already line-length-bounded server-side.
256
+
257
+ #### On gate PASS
258
+
259
+ Proceed to Phase 1 with the candidates carried over from Phase 0.
260
+
261
+ ### Phase 1 — Classify, Layer, Slug, Review
262
+
263
+ For each candidate, the skill proposes:
264
+
265
+ - **type** ∈ {model, decision, guideline, pitfall, process}
266
+ - **layer** ∈ {team, personal} via the verbatim heuristic below
267
+ - **slug** per the 5-rule naming guideline below
268
+ - **summary** (1-2 sentences, will become the entry body's lead paragraph)
269
+
270
+ #### Five Knowledge Types (singular noun = type concept)
271
+
272
+ - **model** — A reusable mental abstraction or domain object schema. Worth-archive signal: the user names something ("the X pattern", "the Y phase"). Skip-it signal: ad-hoc terminology used once. Positive: "Wave-1/Wave-2 task DAG decomposition for parallel-safe planning". Negative: "the thing we did just now" (too thin, no reusable abstraction).
273
+ - **decision** — A choice between alternatives with rationale. Worth-archive signal: ≥2 options were weighed AND a rationale was given. Skip-it signal: the choice was forced by external constraint with no real alternative. Positive: "Single .cjs hook script over three per-client scripts — rationale: identical stdout JSON shape across Claude/Codex". Negative: "Used the existing fab_extract_knowledge schema" (no alternative was considered).
274
+ - **guideline** — A normative rule for future similar situations. Worth-archive signal: the user said "always" / "never" / "from now on". Skip-it signal: a one-off preference that won't generalize. Positive: "Slug naming: kebab-case, 2-5 words, 20-40 chars, semantic core only". Negative: "Use 4-space indent in this one file" (too narrow).
275
+ - **pitfall** — A trap that wasted time and is non-obvious. Worth-archive signal: a bug took >15 min to diagnose AND is repeatable. Skip-it signal: a typo or one-time API quirk. Positive: "deepMerge replaces arrays — hooks.Stop[] needs special-case append-with-dedupe". Negative: "Forgot a comma in JSON" (too obvious).
276
+ - **process** — A multi-step procedure with a stable shape. Worth-archive signal: the steps were executed in a specific order AND the order matters. Skip-it signal: a one-shot script with no reusable structure. Positive: "fab_review approve = counter++ → frontmatter inject → git mv → meta rebuild → event append (5 atomic steps)". Negative: "Ran the tests, then committed" (trivial, no reusable shape).
277
+
278
+ #### Layer Classification Heuristic (强 team 信号 / 强 personal 信号 / 默认 team)
279
+
280
+ > - **强 team**: 引用本项目代码、团队共识用语("we decided")、fabric-import 路径产物、业务领域、绑定本项目代码的 pitfall
281
+ > - **强 personal**: 第一人称偏好、跨项目通用、工具/编辑器偏好、个人工作流
282
+ > - **默认 team**: 安全偏置——错标 team 在 PR review 中会被发现,错标 personal 静默丢失
283
+
284
+ Resolution order: check 强 team signals first; only assign personal if 强 personal signals dominate AND no 强 team signal applies; otherwise default to team.
285
+
286
+ #### Slug Naming Guideline (5 Rules)
287
+
288
+ 1. kebab-case (lowercase letters, digits, hyphens only — no underscores, no CamelCase)
289
+ 2. 2-5 words separated by hyphens
290
+ 3. 20-40 characters total length
291
+ 4. semantic core only (drop articles "the/a", drop generic suffixes "stuff/thing")
292
+ 5. unique within its (type, layer) bucket — if collision, the LLM must add a discriminating word, NOT a counter
293
+
294
+ Examples passing: `wave-1-parallel-task-dag` (4 words, 24 chars), `deepmerge-array-replace-trap` (4 words, 28 chars). Examples failing: `the_solution` (underscore + article), `fix` (1 word, too short), `how-we-decided-to-handle-the-merge-conflict-in-stop-hook-config` (overlong).
295
+
296
+ #### Decision Tree (是否值得归档)
297
+
298
+ ```
299
+ Recent session contains an observation worth keeping?
300
+ ├─ NO → skip (do nothing, no MCP call)
301
+ └─ YES → does it fit one of {model, decision, guideline, pitfall, process}?
302
+ ├─ NO → skip (not classifiable = not yet ripe)
303
+ └─ YES → assign type
304
+
305
+ Apply layer heuristic
306
+
307
+ Propose slug per 5 rules
308
+
309
+ Present in batch review
310
+
311
+ User confirms / corrects / rejects
312
+
313
+ Phase 2: call fab_extract_knowledge once per confirmed candidate
314
+ ```
315
+
316
+ #### Batch Review Template
317
+
318
+ Present all candidates in a single screen. UX i18n Policy classes 1 + 3 — the roll-up structure AND the per-candidate `Confirm?` prompt are bilingualized; protected tokens (`relevance_scope`, `relevance_paths`, `narrow`, `broad`, `layer`, `team`, `personal`, `pending_path`, etc.) appear verbatim in BOTH variants. Field VALUES (slugs, file paths, type/layer enum strings like `decision` / `team`) are data and are NOT translated.
319
+
320
+ en variant (`knowledge_language === "en"`):
321
+
322
+ ```md
323
+ # Archive Review — N candidates
324
+
325
+ ## C1 [type=decision] [layer=team] [relevance_scope=narrow] slug=wave-1-parallel-task-dag
326
+ Summary: <1-2 sentences capturing the observation>
327
+ Layer reasoning: <which 强 team / 强 personal signal applied, or default team>
328
+ Scope reasoning: <why narrow or broad — see Phase 1.5>
329
+ relevance_paths: ["packages/cli/src/commands/plan.ts", "packages/cli/templates/**/*.md"]
330
+ Confirm? (Y to accept, edit type/layer/slug/relevance_scope/relevance_paths inline, N to skip)
331
+
332
+ ## C2 [type=pitfall] [layer=team] [relevance_scope=broad] slug=deepmerge-array-replace-trap
333
+ Summary: ...
334
+ Layer reasoning: ...
335
+ Scope reasoning: ...
336
+ relevance_paths: []
337
+ Confirm? ...
338
+ ```
339
+
340
+ zh-CN variant (`knowledge_language === "zh-CN"`):
341
+
342
+ ```md
343
+ # 归档 Review — N 条候选
344
+
345
+ ## C1 [type=decision] [layer=team] [relevance_scope=narrow] slug=wave-1-parallel-task-dag
346
+ 摘要: <1-2 句捕捉该观察>
347
+ Layer 判定: <命中哪条 强 team / 强 personal 信号,或默认 team>
348
+ Scope 判定: <为什么 narrow 或 broad — 见 Phase 1.5>
349
+ relevance_paths: ["packages/cli/src/commands/plan.ts", "packages/cli/templates/**/*.md"]
350
+ 确认?(Y 接受 / 内联编辑 type/layer/slug/relevance_scope/relevance_paths / N 跳过)
351
+
352
+ ## C2 [type=pitfall] [layer=team] [relevance_scope=broad] slug=deepmerge-array-replace-trap
353
+ 摘要: ...
354
+ Layer 判定: ...
355
+ Scope 判定: ...
356
+ relevance_paths: []
357
+ 确认?...
358
+ ```
359
+
360
+ The user MAY edit type/layer/slug/relevance_scope/relevance_paths inline before confirming. The user MAY skip individual candidates without rejecting the whole batch. Inline-editing `[relevance_scope=...]` triggers a re-derivation of `relevance_paths` per the Phase 1.5 rules (narrow ⇒ recompute from edit_paths; broad ⇒ force `[]`).
361
+
362
+ ### Phase 1.5 — Scope Decision + relevance_paths Derivation
363
+
364
+ After classify/layer/slug but BEFORE batch review output, assign a `relevance_scope` to each candidate and derive its `relevance_paths` array. These two fields drive rc.6 hint injection: narrow knowledge is gated by working in matching paths, broad knowledge is project-wide.
365
+
366
+ #### Scope decision (narrow vs broad)
367
+
368
+ ```
369
+ relevance_scope =
370
+ narrow IF the candidate is tied to a specific module / file / subsystem
371
+ AND there is explicit single-module evidence in edit_paths
372
+ (i.e. all worth-keeping edits in this session concentrated in one
373
+ module tree, OR the candidate explicitly references that module)
374
+
375
+ broad IF the candidate is cross-cutting / methodological / general
376
+ (applies regardless of which path the agent is working in)
377
+
378
+ broad (default, on uncertainty — safe偏置 per Q-1 in handoff)
379
+ ```
380
+
381
+ Special case — Personal layer ALWAYS resolves to `relevance_scope=broad` with `relevance_paths=[]`. Rationale: personal knowledge crosses projects; paths from one project do not generalize. If `layer=personal` and a narrow scope was tentatively chosen, auto-flip to `broad` and clear `relevance_paths`.
382
+
383
+ ##### Examples
384
+
385
+ - `decision: single-cjs-hook-script` → `narrow` (tied to `templates/claude-hooks/` + `packages/cli/src/commands/hooks.ts`)
386
+ - `pitfall: deepmerge-array-replace-trap` → `broad` (cross-cutting JSON merge gotcha, applies anywhere deepMerge is used)
387
+ - `guideline: slug-naming-rules` → `broad` (methodology, no specific module)
388
+ - `model: wave-1-parallel-task-dag` → `narrow` (tied to `packages/cli/src/commands/plan.ts`)
389
+ - `guideline: indent-style-by-language` (personal layer) → `broad + []` (personal forces broad)
390
+
391
+ #### relevance_paths derivation algorithm (rc.5 single-signal: edit_paths only)
392
+
393
+ rc.5 uses ONLY the `edit_paths` signal — list of paths modified by `Edit` / `Write` / `MultiEdit` tool calls in the current session. Multi-signal (read_paths + body regex + symbols) is explicitly deferred to rc.7 per design decision.
394
+
395
+ ```
396
+ Step 1: COLLECT
397
+ edit_paths = []
398
+ Scan session transcript for tool_use entries where
399
+ tool_use.name ∈ {Edit, Write, MultiEdit}
400
+ Extract the file_path argument from each, push into edit_paths.
401
+
402
+ Step 2: DEDUPE
403
+ edit_paths = unique(edit_paths)
404
+
405
+ Step 3: BLACKLIST FILTER
406
+ Drop paths matching any of:
407
+ - **/*.<ext> where <ext> is a single trivial extension on a single file
408
+ (i.e. avoid emitting bare **/*.md as a relevance pattern)
409
+ - Repo-root single files: README.md, package.json, package-lock.json,
410
+ pnpm-lock.yaml, tsconfig.json, .gitignore, LICENSE, CHANGELOG.md
411
+ - Read-only paths (never modified) — those go to ## Evidence, not relevance_paths
412
+
413
+ Step 4: PUBLIC-PREFIX GENERALIZE (depth ≤ 2, minGroupSize = 2)
414
+ Group remaining paths by common prefix.
415
+ For each group of ≥ 2 sibling paths sharing a prefix:
416
+ - Compute longest common directory prefix
417
+ - Limit generalization depth: at most 2 levels below the common prefix
418
+ - Emit glob: <common-prefix>/**/*.<ext> (or <common-prefix>/**/<filename>)
419
+ Singleton paths (group size = 1) are kept as-is (literal path, no glob).
420
+
421
+ Step 5: SCOPE GATE
422
+ IF relevance_scope == broad → relevance_paths = [] (force empty regardless of edit_paths)
423
+ IF relevance_scope == narrow → relevance_paths = result of Step 4
424
+
425
+ Step 6: ATTACH READ-ONLY EVIDENCE
426
+ Read-only paths (filtered in Step 3) are emitted as a ## Evidence markdown
427
+ block in the pending entry body — NOT in relevance_paths. They document
428
+ what the agent consulted without making them part of the activation gate.
429
+ ```
430
+
431
+ ##### Worked generalization example
432
+
433
+ Edit history during session:
434
+
435
+ ```
436
+ packages/server/src/services/extract.ts
437
+ packages/server/src/services/review.ts
438
+ packages/server/src/services/promote.ts
439
+ packages/cli/src/commands/plan.ts
440
+ README.md
441
+ ```
442
+
443
+ Step 1-2 (collect + dedupe): all 5 unique.
444
+ Step 3 (blacklist): drop `README.md` (repo-root single file).
445
+ Step 4 (generalize, depth ≤ 2, minGroupSize = 2):
446
+ - `packages/server/src/services/{extract,review,promote}.ts` → group size 3 ≥ 2, common prefix `packages/server/src/services/`, glob: `packages/server/src/services/**/*.ts`
447
+ - `packages/cli/src/commands/plan.ts` → group size 1, kept literal.
448
+
449
+ Step 5 (assume `relevance_scope=narrow`):
450
+
451
+ ```json
452
+ "relevance_paths": [
453
+ "packages/server/src/services/**/*.ts",
454
+ "packages/cli/src/commands/plan.ts"
455
+ ]
456
+ ```
457
+
458
+ If `relevance_scope=broad` had been chosen instead, `relevance_paths` would be `[]` regardless of the above.
459
+
460
+ #### Inline-edit support during batch review
461
+
462
+ The user MAY inline-edit `[relevance_scope=...]` in the batch review. When this happens:
463
+
464
+ - Edit changes `narrow → broad`: clear `relevance_paths` to `[]`.
465
+ - Edit changes `broad → narrow`: re-run Steps 1-4 of the derivation algorithm to recompute.
466
+ - The user MAY also directly inline-edit `relevance_paths` to a custom array; treat this as authoritative and skip auto-derivation.
467
+
468
+ ### Phase 2 — Persist via MCP
469
+
470
+ For each user-confirmed candidate, call `fab_extract_knowledge` ONCE. Do NOT batch multiple candidates into one call.
471
+
472
+ #### Output Contract (MCP tool call shape)
473
+
474
+ ```ts
475
+ mcp__fabric__fab_extract_knowledge({
476
+ source_sessions: ["<session id1>", "<session id2>", ...], // T5: array form (Phase 0.0)
477
+ recent_paths: ["<path1>", "<path2>", ...], // capped at archive_max_recent_paths (config-resolved, default 20)
478
+ user_messages_summary: "<compact prose ≤500 chars>",
479
+ type: "decisions" | "pitfalls" | "guidelines" | "models" | "processes",
480
+ slug: "<kebab-case-2-to-5-words>",
481
+ layer: "team" | "personal",
482
+ relevance_scope: "narrow" | "broad", // from Phase 1.5
483
+ relevance_paths: ["<glob1>", "<literal2>", ...], // narrow ⇒ derived; broad ⇒ []
484
+ // v2.0.0-rc.7 T6: required fields for future-self reviewability.
485
+ proposed_reason:
486
+ "explicit-user-mark" // user said "always / never / 下次注意" etc.
487
+ | "diagnostic-then-fix" // long debug loop surfaced a new pattern/pitfall
488
+ | "decision-confirmation" // ≥2 options weighed AND rationale stated → decision/model
489
+ | "wrong-turn-revert" // tried path X, reverted → pitfall
490
+ | "new-dependency-or-pattern" // new dep/lib/abstraction introduced
491
+ | "dismissal-with-reason", // user rejected approach AND said why
492
+ session_context: "<3-5 line markdown: session goal + key turning point>",
493
+ // tags? — NOT in current schema; reserved for future
494
+ })
495
+ ```
496
+
497
+ The Skill infers `proposed_reason` from the classification + viability-gate
498
+ signal that fired:
499
+
500
+ | Signal fired (Phase 0.5) | Classification | Default proposed_reason |
501
+ |--------------------------------|----------------|-----------------------------|
502
+ | Explicit normative language | guideline | `explicit-user-mark` |
503
+ | Wrong-turn-and-revert | pitfall | `wrong-turn-revert` |
504
+ | Long diagnostic loop | pitfall/model | `diagnostic-then-fix` |
505
+ | New dependency adoption | decision/model | `new-dependency-or-pattern` |
506
+ | New pattern emergence | model | `new-dependency-or-pattern` |
507
+ | Decision confirmation | decision | `decision-confirmation` |
508
+ | Explicit dismissal-with-reason | decision | `dismissal-with-reason` |
509
+ | Process formalization | process | `new-dependency-or-pattern` |
510
+
511
+ The `session_context` is a 3-5 line summary distilled from the Phase 0.0
512
+ cross-session digest (see Phase 0.0 below for digest source). Format:
513
+
514
+ ```
515
+ Session goal: <one-line of what the user was trying to accomplish>
516
+ Turning point: <one-line of the key moment that produced the worth-archive observation>
517
+ [optional 1-3 more lines of supporting context]
518
+ ```
519
+
520
+ Future-self reviewing the pending entry MUST be able to understand WHY this
521
+ entry was proposed without conversation transcript access — proposed_reason
522
+ is the structured why, session_context is the narrative why.
523
+
524
+ Note on type plurality: the MCP enum uses plural directory-form (decisions / pitfalls / guidelines / models / processes), while the conceptual classification above uses singular nouns (decision / pitfall / guideline / model / process) for natural English. They map 1:1.
525
+
526
+ The server returns `{ pending_path, idempotency_key }`. Display `pending_path` to the user so they can `Read` the persisted entry if they wish.
527
+
528
+ #### Idempotency Note
529
+
530
+ The MCP tool derives `idempotency_key = sha256({source_session, type, slug})`. Calling fab_extract_knowledge twice with the same `(source_session, type, slug)` triple is SAFE: the server appends new evidence to the existing pending file rather than overwriting or producing duplicates. This means the skill MAY be re-invoked on the same session without producing junk.
531
+
532
+ If the skill needs to record a genuinely separate observation in the same session+type, the slug MUST differ.
533
+
534
+ **T5 array-form note (rc.7+)**: when `source_sessions` is passed as an array (the rc.7 T5 contract), only `source_sessions[0]` participates in the server-side idempotency hash. The actual server formula at `packages/server/src/services/extract-knowledge.ts:78` is `sha256(JSON.stringify({source_session: sourceSessions[0], type, slug}))`. Implications:
535
+
536
+ - Same `(type, slug)` but a different **first** session → distinct idempotency key → produces two pending files.
537
+ - Same first session but different tail sessions → evidence-merge into the SAME pending file; tail `session_id`s are NOT recorded as independent evidence keys.
538
+ - The formula is intentionally stable across the rc.5 → rc.7 migration; adding or removing tail entries does NOT change the idempotency key, preserving rc.5 single-session compat.
539
+
540
+ ## Hard Rules (DO NOT TRANSLATE) — DISPLAY / WRITE Split
541
+
542
+ ### DISPLAY Rules
543
+
544
+ - MUST complete Phase 0 AND Phase 0.5 viability gate before any batch-review output.
545
+ - MUST abort with the gate-FAIL message (no MCP call) when the viability gate fails AND the user did not explicitly invoke fabric-archive.
546
+ - MUST present every candidate with explicit `[type=...]`, `[layer=...]`, `[relevance_scope=...]`, and `slug=...` fields plus a `relevance_paths` line.
547
+ - MUST include a one-line `Layer reasoning:` for each candidate citing which 强 team / 强 personal signal applied (or default team).
548
+ - MUST include a one-line `Scope reasoning:` for each candidate citing why narrow or broad was chosen (or that personal forced broad).
549
+ - MUST classify against the canonical singular nouns: model / decision / guideline / pitfall / process. NEVER invent new types.
550
+ - MUST cap the batch at `archive_max_candidates_per_batch` candidates (config-resolved, default 8); drop weaker ones over the cap.
551
+ - MUST display the resolved `pending_path` returned by `fab_extract_knowledge` so the user can verify.
552
+ - MUST treat user inline edits to type/layer/slug/relevance_scope/relevance_paths as authoritative replacements before Phase 2.
553
+ - MUST skip rather than guess when an observation does not fit any of the 5 types.
554
+
555
+ ### WRITE Rules
556
+
557
+ - NEVER write a knowledge entry directly to the filesystem; the only legal write path is `mcp__fabric__fab_extract_knowledge`.
558
+ - NEVER write outside `.fabric/knowledge/pending/` — promotion to `.fabric/knowledge/<type>/` is rc.3 fab_review concern, NOT this skill.
559
+ - NEVER include an `id` field anywhere — pending entries have no id (late-bind on approve).
560
+ - NEVER classify a candidate as `personal` when a 强 team signal applies. Default to team on ambiguity.
561
+ - NEVER emit a non-empty `relevance_paths` when `relevance_scope=broad` — broad MUST always carry `relevance_paths=[]`.
562
+ - NEVER emit a non-empty `relevance_paths` when `layer=personal` — personal forces `relevance_scope=broad` + `relevance_paths=[]`.
563
+ - NEVER use multi-signal sources for relevance_paths in rc.5 — `edit_paths` is the SOLE source. `read_paths`, body regex, and symbol extraction are reserved for rc.7+.
564
+ - NEVER batch multiple candidates into a single fab_extract_knowledge call; one call per candidate.
565
+ - NEVER paraphrase the verbatim layer heuristic block above — the Chinese text is contract-locked.
566
+ - MUST preserve protected tokens exactly: `stable_id`, `knowledge_proposed`, `knowledge_archive_aborted`, `knowledge_scope_degraded`, `.fabric/knowledge/pending/`, `fab_extract_knowledge`, `relevance_paths`, `relevance_scope`, `narrow`, `broad`, `edit_paths`, `source_sessions`, `proposed_reason`, `session_context`, `pending_path`, `layer`, `team`, `personal`, `MUST`, `NEVER`, `强 team`, `强 personal`, `默认 team`.
567
+
568
+ ## Worked Examples
569
+
570
+ ### Example 1 — decision (team)
571
+
572
+ Session: User and agent debated whether the Stop-hook should be one .cjs script or three per-client scripts. Settled on one because stdout JSON shape `{"decision":"block","reason"}` is identical across Claude / Codex.
573
+
574
+ Skill output:
575
+
576
+ ```ts
577
+ mcp__fabric__fab_extract_knowledge({
578
+ source_sessions: ["WFS-2026-05-10-rc2"],
579
+ recent_paths: ["templates/claude-hooks/", "packages/cli/src/commands/hooks.ts"],
580
+ user_messages_summary: "User pushed back on three-script proposal; agreed single .cjs because stdout JSON shape is universal across Claude Code and Codex CLI.",
581
+ type: "decisions",
582
+ slug: "single-cjs-hook-script",
583
+ layer: "team",
584
+ relevance_scope: "narrow",
585
+ relevance_paths: [
586
+ "templates/claude-hooks/**/*.cjs",
587
+ "packages/cli/src/commands/hooks.ts"
588
+ ],
589
+ proposed_reason: "decision-confirmation",
590
+ session_context: "Session goal: ship Stop-hook for v2 release.\nTurning point: user rejected 3-script proposal after seeing identical stdout JSON across Claude / Codex.\nResult: single .cjs path locked in."
591
+ })
592
+ ```
593
+
594
+ Layer = team (引用本项目代码 + fabric-import 路径产物 signals). Scope = narrow (tied to hook templates + hooks command module; single-module evidence in edit_paths).
595
+
596
+ ### Example 2 — pitfall (team)
597
+
598
+ Session: deepMerge silently replaced the existing `hooks.Stop[]` array in `.claude/settings.json` instead of appending. Cost ~30 min to diagnose.
599
+
600
+ Skill output:
601
+
602
+ ```ts
603
+ mcp__fabric__fab_extract_knowledge({
604
+ source_sessions: ["WFS-2026-05-10-rc2"],
605
+ recent_paths: ["packages/cli/src/config/json.ts"],
606
+ user_messages_summary: "deepMerge default behavior REPLACES arrays. hooks.Stop[] needs an array-append-with-dedupe special case keyed on .command string match.",
607
+ type: "pitfalls",
608
+ slug: "deepmerge-array-replace-trap",
609
+ layer: "team",
610
+ relevance_scope: "broad",
611
+ relevance_paths: [],
612
+ proposed_reason: "diagnostic-then-fix",
613
+ session_context: "Session goal: wire hook installer for v2.\nTurning point: spent ~30 min chasing why prior Stop[] entries vanished — root cause was deepMerge replacing arrays silently.\nResult: array-append-with-dedupe special case added."
614
+ })
615
+ ```
616
+
617
+ Layer = team (绑定本项目代码的 pitfall signal). Scope = broad (deepMerge gotcha is cross-cutting — applies anywhere JSON merge is used, not just `json.ts`).
618
+
619
+ ### Example 3 — guideline (personal)
620
+
621
+ Session: User mentioned across three projects that they prefer 2-space indent in TypeScript and 4-space in Python.
622
+
623
+ Skill output:
624
+
625
+ ```ts
626
+ mcp__fabric__fab_extract_knowledge({
627
+ source_sessions: ["WFS-2026-05-10-rc2"],
628
+ recent_paths: [".editorconfig"],
629
+ user_messages_summary: "Personal indent preference: 2-space TS / 4-space Py. Stable across multiple projects, not project-specific.",
630
+ type: "guidelines",
631
+ slug: "indent-style-by-language",
632
+ layer: "personal",
633
+ relevance_scope: "broad",
634
+ relevance_paths: [],
635
+ proposed_reason: "explicit-user-mark",
636
+ session_context: "Session goal: align editor config.\nTurning point: user said '一直 prefer 2-space TS / 4-space Py,across projects'.\nResult: personal-layer guideline; not bound to this project."
637
+ })
638
+ ```
639
+
640
+ Layer = personal (跨项目通用 + 工具/编辑器偏好 signals dominate; no 强 team signal applies). Scope = broad with `relevance_paths=[]` (personal layer ALWAYS forces broad — paths don't generalize across projects per Phase 1.5 special case).