Orchestrate FAQ extraction from project knowledge docs AND pi-hermes memory
stores into docs/faq.md.
Two source classes:
- Docs — README.md + evergreen
docs/*.md. How-to / what-is questions.
- Hermes memory — accumulated runtime problems (tool-quirks, failures,
insights, corrections) that never reach the docs. These carry the "why does X
fail / how do I fix Y" answers a future agent keeps re-discovering.
Inputs:
- Optional
--docs <a.md>,<b.md> — explicit doc list. Default = README.md + every evergreen docs/*.md. --docs skip = memory-only run (disables doc mining; the ship-change harvest path).
- Optional
--memory <off|project|failures|all> — hermes stores to mine. Default failures = project store + global failures.md (relevance-filtered). off = docs only. all = also global MEMORY.md.
- Optional
--max <N> — entry cap per source (default ~10).
Non-interactive: passing BOTH --docs (incl. --docs skip) and --memory skips the Phase 1 prompt — the headless invocation faq-mine --docs skip --memory failures runs memory-only with no ask_user.
Phase 0 — Pre-flight
- Read
docs/faq.md if it exists. Extract every ## <Question> heading into a dedupe list.
- Enumerate candidate source docs (SKIP this whole step when
--docs skip — memory-only run):ls README.md docs/*.md 2>/dev/null
Exclude:
docs/faq.md itself
docs/faq.agent.md (condensed index derived FROM faq.md — refreshed in Phase 4, never mined)
docs/AGENTS.md and any AGENTS.md (index, not narrative)
docs/session-knowledge-*.md (point-in-time notes)
docs/spec-gap-analysis.md and any *-resolved.md (transient analyses)
- Anything matching
docs/.faq-draft-*.md (in-flight draft)
- For each remaining doc, capture
wc -l to surface size.
- Enumerate hermes memory stores (unless
--memory off):PROJ=$(basename "$(git rev-parse --show-toplevel)")
ls -l "$HOME/.pi/agent/projects-memory/$PROJ/MEMORY.md" \
"$HOME/.pi/agent/pi-hermes-memory/failures.md" \
"$HOME/.pi/agent/pi-hermes-memory/MEMORY.md" 2>/dev/null
- Project store
projects-memory/$PROJ/MEMORY.md — all entries repo-scoped, no filter. If $PROJ dir absent (e.g. worktree name differs), ls ~/.pi/agent/projects-memory/ and pick the matching dir; skip if none.
- Global
pi-hermes-memory/failures.md — mixed across projects, needs a repo-relevance filter (subagent applies it).
- Global
pi-hermes-memory/MEMORY.md — mixed, only when --memory all.
- Any store path that does not exist: skip silently (fresh machine).
Phase 1 — Confirm scope
Use ask_user (multiselect) to let the user pick which sources to mine — list the docs AND the resolved hermes stores as options. Pre-select the evergreen docs + the project store + failures.md. Skip the prompt only when the user already passed both --docs and --memory.
Phase 2 — Parallel extraction (@fast subagents)
Dispatch ONE general-purpose subagent with model: @fast, run_in_background: true per selected source (docs AND stores). All agents run in parallel — each writes to its OWN draft file to avoid write conflicts:
- Docs →
docs/.faq-draft-<basename>.md
- Stores →
docs/.faq-draft-mem-<label>.md (label = project | failures | memory)
Phase 2A — Doc mining
Subagent prompt template (substitute <DOC> with the source doc path):
Mine FAQ-worthy entries from <DOC> and write them to a NEW file docs/.faq-draft-<basename>.md. Do NOT touch any other file.
STEP 1 — read existing docs/faq.md. Extract every ## <Question> heading. DEDUPE: skip questions already covered (or trivially equivalent).
STEP 2 — read <DOC> fully. Identify recurring how-to / what-is questions a user or future agent would actually ask. Aim for 4–10 entries. Quality > quantity. Skip implementation trivia.
STEP 3 — write the draft using the EXACT format of existing faq.md entries:
## <Question>?
<one-line terse answer>
Command: `<cmd>` (when applicable; omit for what-is questions).
<optional bullets / sub-sections with concrete tokens>
Cross-refs:
- <DOC>:<line>
- <other source file:line>
CAVEMAN STYLE (verbatim, all docs/ prose obeys):
- Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.
- Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".
- One fact per line/row. No restating context the file already establishes.
- Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.
- Keep symbols/identifiers verbatim; only connective tissue compresses.
Verify every command + path against the source doc. No invented flags, no speculation. Confirm completion in your final reply with the entry count.
Phase 2B — Hermes memory mining
Runtime problems live in the hermes stores as §-separated terse entries, each stamped <!-- created=…, last=… -->. Convert each FAQ-worthy problem into a symptom-first Q&A entry. One subagent per store.
Subagent prompt template (substitute <STORE> = absolute store path, <LABEL> = project|failures|memory, <FILTER> = the relevance rule below):
Mine FAQ-worthy runtime problems from the pi-hermes memory store <STORE> and write them to a NEW file docs/.faq-draft-mem-<LABEL>.md. Do NOT touch any other file.
STEP 1 — read existing docs/faq.md. Extract every ## <Question> heading. DEDUPE: skip any problem already covered (or trivially equivalent — e.g. RPC-keeper, ctx-stats, session-stuck entries already exist).
STEP 2 — read <STORE> fully. Entries are separated by lines containing only §. Each entry may be prefixed [failure]/[correction]/[insight]/[convention]/[tool-quirk] and ends with an HTML <!-- created=… --> comment. IGNORE the comment metadata.
STEP 3 — for each KEPT entry, write a symptom-first FAQ entry in the EXACT faq.md format:
## Why does <symptom>? (or: How do I fix <symptom>?)
<one-line root cause — terse>
Fix: `<cmd>` (or the concrete file/edit; omit when not a command).
<optional bullets: concrete tokens — paths, env vars, flags, exit codes>
Cross-refs:
- <STORE>
- <every file path / package named inside the entry>
- Question = the OBSERVABLE symptom a user/agent would search (the error string, the wrong behaviour), NOT the internal cause. A reader who hits the problem must recognise their symptom in the heading.
- Keep the wrong-way → right-way fix intact; that is the whole value of the entry.
- Merge near-duplicate store entries (same problem, consolidated across dates) into ONE FAQ entry.
CAVEMAN STYLE (verbatim, all docs/ prose obeys):
- Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.
- Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".
- One fact per line. No restating context the file already establishes.
- Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.
- Keep symbols/identifiers verbatim; only connective tissue compresses.
Verify every command + path against the source entry. No invented flags, no speculation — if an entry lacks a concrete fix, skip it. Confirm completion in your final reply with the kept/skipped counts.
<FILTER> value by store:
- Project store (
<LABEL>=project): STEP 2b — no filter. Every entry is scoped to this repo; consider all of them.
- Global
failures.md / MEMORY.md (<LABEL>=failures|memory): STEP 2b — RELEVANCE FILTER. This store mixes many projects. KEEP only entries about THIS project specifically, its paths (packages/, docs/, openspec/, src/), or a dev-in-this-repo tooling quirk (test runner, linter, build tool, git worktree, etc.). DROP everything else (unrelated product decks, OAuth-license research, Drive/rclone uploads, other repos). When unsure, DROP.
Wait for all agents (2A + 2B) to finish.
Phase 3 — Cross-draft dedupe
- Run:
grep -n '^## ' docs/.faq-draft-*.md
- Cluster near-duplicate questions across drafts (same topic, different phrasing). Keep the entry with more concrete tokens / detail; remove the weaker one with a targeted
Edit.
- Cross-store dup: the same runtime problem can appear in BOTH the project store and
failures.md. Keep the one carrying the concrete fix; drop the other.
- Doc-vs-memory dup: when a memory draft restates a problem a doc draft already covers, keep whichever has the actionable fix + cross-refs.
- Detect false-positive headings inside fenced code blocks and ignore (e.g.
## [Unreleased] example inside ```markdown blocks is content, not a heading).
Phase 4 — Merge & cleanup
cat docs/.faq-draft-*.md >> docs/faq.md && rm docs/.faq-draft-*.md
grep -c '^## ' docs/faq.md
wc -l docs/faq.md
Then refresh the condensed index docs/faq.agent.md so new entries appear in the pull-only map. Delegate to ONE general-purpose subagent (docs/ write → subagent per Rule 6):
Append condensed one-liners for these NEW faq.md entries to docs/faq.agent.md. For each, add a line - <short question stem> — <key answer / fix in ≤12 words> under a ## Runtime problems & quirks section (create the section if absent, at the end). Keep the existing sections untouched. Caveman style. New questions + answers: <paste the merged headings + one-line answers>.
Report to user:
- Total entries before / after (faq.md).
- Entries added per source (table: doc/store → count).
- For memory stores: kept vs skipped-by-relevance-filter counts.
- Any duplicates dropped during Phase 3 (cross-store + doc-vs-memory).
- faq.agent.md lines appended.
- One-line note on false-positive
## headings inside code fences (if any).
Rules — Documentation Update Protocol compliance
This skill writes under docs/ (faq.md + faq.agent.md). Per AGENTS.md:
- All
docs/ writes go through subagents (general-purpose). Main orchestrator only cat/rm/Edits for merge + targeted dedupe.
- Caveman style is mandatory and passed verbatim to every subagent prompt.
- Every command/path/flag in a generated entry must be verified against the source doc / store entry; no speculation.
- Hermes stores are READ-ONLY inputs — never edit
~/.pi/agent/**. Extraction copies knowledge into faq.md; it does not move or prune the memory.
- Do NOT rename or delete existing faq.md
## headings — packages/shared/src/tool-registry/__tests__/install-hints.test.ts asserts each tool docsAnchor maps to a heading. Append only.
Anti-patterns (do not)
- Do NOT have multiple subagents write to the same file in parallel — race condition.
- Do NOT mine
AGENTS.md (incl. docs/AGENTS.md) or docs/faq.agent.md — indexes, not narrative knowledge.
- Do NOT mine
session-knowledge-*.md or spec-gap-analysis.md — point-in-time notes; entries would rot fast.
- Do NOT skip the global-store relevance filter —
failures.md/MEMORY.md mix projects; unfiltered mining leaks other repos' quirks into this FAQ.
- Do NOT phrase a runtime-problem heading by its internal cause — use the observable symptom (error string / wrong behaviour) so a reader recognises it.
- Do NOT skip Phase 0 dedupe — re-running the skill must not double-add the same questions.
- Do NOT drop the per-entry
Cross-refs: block — agents lose the source trail otherwise (memory entries cross-ref the store path).
1---2name: faq-mine3description: Mine docs/faq.md from README.md, docs/*.md, and the pi-hermes memory stores. Dispatches @fast subagents per source, dedupes against the existing FAQ, and merges entries in caveman style. Use when asked to "build / regenerate / extend the FAQ", "mine docs into FAQ", "mine hermes memory into FAQ", "surface runtime problems in the FAQ", or "create FAQ from README + docs".4license: MIT5---67Orchestrate FAQ extraction from project knowledge docs AND pi-hermes memory8stores into `docs/faq.md`.910Two source classes:11- **Docs** — README.md + evergreen `docs/*.md`. How-to / what-is questions.12- **Hermes memory** — accumulated runtime problems (tool-quirks, failures,13 insights, corrections) that never reach the docs. These carry the "why does X14 fail / how do I fix Y" answers a future agent keeps re-discovering.1516**Inputs**:17- Optional `--docs <a.md>,<b.md>` — explicit doc list. Default = README.md + every evergreen `docs/*.md`. `--docs skip` = memory-only run (disables doc mining; the ship-change harvest path).18- Optional `--memory <off|project|failures|all>` — hermes stores to mine. Default `failures` = project store + global `failures.md` (relevance-filtered). `off` = docs only. `all` = also global `MEMORY.md`.19- Optional `--max <N>` — entry cap per source (default ~10).2021Non-interactive: passing BOTH `--docs` (incl. `--docs skip`) and `--memory` skips the Phase 1 prompt — the headless invocation `faq-mine --docs skip --memory failures` runs memory-only with no `ask_user`.2223---2425## Phase 0 — Pre-flight26271. Read `docs/faq.md` if it exists. Extract every `## <Question>` heading into a dedupe list.28 - If file missing, create with header:29 ```30 # FAQ3132 FAQ. How-to answers that already live in README.md + docs/. New entries here when same question recurs.33 ```342. Enumerate candidate source docs (SKIP this whole step when `--docs skip` — memory-only run):35 ```bash36 ls README.md docs/*.md 2>/dev/null37 ```38 Exclude:39 - `docs/faq.md` itself40 - `docs/faq.agent.md` (condensed index derived FROM faq.md — refreshed in Phase 4, never mined)41 - `docs/AGENTS.md` and any `AGENTS.md` (index, not narrative)42 - `docs/session-knowledge-*.md` (point-in-time notes)43 - `docs/spec-gap-analysis.md` and any `*-resolved.md` (transient analyses)44 - Anything matching `docs/.faq-draft-*.md` (in-flight draft)453. For each remaining doc, capture `wc -l` to surface size.464. Enumerate hermes memory stores (unless `--memory off`):47 ```bash48 PROJ=$(basename "$(git rev-parse --show-toplevel)")49 ls -l "$HOME/.pi/agent/projects-memory/$PROJ/MEMORY.md" \50 "$HOME/.pi/agent/pi-hermes-memory/failures.md" \51 "$HOME/.pi/agent/pi-hermes-memory/MEMORY.md" 2>/dev/null52 ```53 - Project store `projects-memory/$PROJ/MEMORY.md` — all entries repo-scoped, **no filter**. If `$PROJ` dir absent (e.g. worktree name differs), `ls ~/.pi/agent/projects-memory/` and pick the matching dir; skip if none.54 - Global `pi-hermes-memory/failures.md` — **mixed across projects**, needs a repo-relevance filter (subagent applies it).55 - Global `pi-hermes-memory/MEMORY.md` — mixed, only when `--memory all`.56 - Any store path that does not exist: skip silently (fresh machine).5758## Phase 1 — Confirm scope5960Use `ask_user` (`multiselect`) to let the user pick which sources to mine — list the docs AND the resolved hermes stores as options. Pre-select the evergreen docs + the project store + `failures.md`. Skip the prompt only when the user already passed both `--docs` and `--memory`.6162## Phase 2 — Parallel extraction (@fast subagents)6364Dispatch ONE `general-purpose` subagent with `model: @fast`, `run_in_background: true` per selected source (docs AND stores). All agents run in parallel — each writes to its OWN draft file to avoid write conflicts:65- Docs → `docs/.faq-draft-<basename>.md`66- Stores → `docs/.faq-draft-mem-<label>.md` (`label` = `project` | `failures` | `memory`)6768### Phase 2A — Doc mining6970**Subagent prompt template** (substitute `<DOC>` with the source doc path):7172> Mine FAQ-worthy entries from `<DOC>` and write them to a NEW file `docs/.faq-draft-<basename>.md`. Do NOT touch any other file.73>74> STEP 1 — read existing `docs/faq.md`. Extract every `## <Question>` heading. DEDUPE: skip questions already covered (or trivially equivalent).75>76> STEP 2 — read `<DOC>` fully. Identify recurring how-to / what-is questions a user or future agent would actually ask. Aim for 4–10 entries. Quality > quantity. Skip implementation trivia.77>78> STEP 3 — write the draft using the EXACT format of existing faq.md entries:79>80> ```81> ## <Question>?82>83> <one-line terse answer>84>85> Command: `<cmd>` (when applicable; omit for what-is questions).86>87> <optional bullets / sub-sections with concrete tokens>88>89> Cross-refs:90> - <DOC>:<line>91> - <other source file:line>92> ```93>94> CAVEMAN STYLE (verbatim, all docs/ prose obeys):95> - Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.96> - Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".97> - One fact per line/row. No restating context the file already establishes.98> - Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.99> - Keep symbols/identifiers verbatim; only connective tissue compresses.100>101> Verify every command + path against the source doc. No invented flags, no speculation. Confirm completion in your final reply with the entry count.102103### Phase 2B — Hermes memory mining104105Runtime problems live in the hermes stores as `§`-separated terse entries, each stamped `<!-- created=…, last=… -->`. Convert each FAQ-worthy problem into a symptom-first Q&A entry. One subagent per store.106107**Subagent prompt template** (substitute `<STORE>` = absolute store path, `<LABEL>` = `project`|`failures`|`memory`, `<FILTER>` = the relevance rule below):108109> Mine FAQ-worthy runtime problems from the pi-hermes memory store `<STORE>` and write them to a NEW file `docs/.faq-draft-mem-<LABEL>.md`. Do NOT touch any other file.110>111> STEP 1 — read existing `docs/faq.md`. Extract every `## <Question>` heading. DEDUPE: skip any problem already covered (or trivially equivalent — e.g. RPC-keeper, ctx-stats, session-stuck entries already exist).112>113> STEP 2 — read `<STORE>` fully. Entries are separated by lines containing only `§`. Each entry may be prefixed `[failure]`/`[correction]`/`[insight]`/`[convention]`/`[tool-quirk]` and ends with an HTML `<!-- created=… -->` comment. IGNORE the comment metadata.114>115> <FILTER>116>117> STEP 3 — for each KEPT entry, write a symptom-first FAQ entry in the EXACT faq.md format:118>119> ```120> ## Why does <symptom>? (or: How do I fix <symptom>?)121>122> <one-line root cause — terse>123>124> Fix: `<cmd>` (or the concrete file/edit; omit when not a command).125>126> <optional bullets: concrete tokens — paths, env vars, flags, exit codes>127>128> Cross-refs:129> - <STORE>130> - <every file path / package named inside the entry>131> ```132>133> - Question = the OBSERVABLE symptom a user/agent would search (the error string, the wrong behaviour), NOT the internal cause. A reader who hits the problem must recognise their symptom in the heading.134> - Keep the wrong-way → right-way fix intact; that is the whole value of the entry.135> - Merge near-duplicate store entries (same problem, consolidated across dates) into ONE FAQ entry.136>137> CAVEMAN STYLE (verbatim, all docs/ prose obeys):138> - Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.139> - Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".140> - One fact per line. No restating context the file already establishes.141> - Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.142> - Keep symbols/identifiers verbatim; only connective tissue compresses.143>144> Verify every command + path against the source entry. No invented flags, no speculation — if an entry lacks a concrete fix, skip it. Confirm completion in your final reply with the kept/skipped counts.145146**`<FILTER>` value by store:**147- Project store (`<LABEL>=project`): `STEP 2b — no filter. Every entry is scoped to this repo; consider all of them.`148- Global `failures.md` / `MEMORY.md` (`<LABEL>=failures`|`memory`): `STEP 2b — RELEVANCE FILTER. This store mixes many projects. KEEP only entries about THIS project specifically, its paths (packages/, docs/, openspec/, src/), or a dev-in-this-repo tooling quirk (test runner, linter, build tool, git worktree, etc.). DROP everything else (unrelated product decks, OAuth-license research, Drive/rclone uploads, other repos). When unsure, DROP.`149150Wait for all agents (2A + 2B) to finish.151152## Phase 3 — Cross-draft dedupe1531541. Run:155 ```bash156 grep -n '^## ' docs/.faq-draft-*.md157 ```1582. Cluster near-duplicate questions across drafts (same topic, different phrasing). Keep the entry with more concrete tokens / detail; remove the weaker one with a targeted `Edit`.159 - **Cross-store dup**: the same runtime problem can appear in BOTH the project store and `failures.md`. Keep the one carrying the concrete fix; drop the other.160 - **Doc-vs-memory dup**: when a memory draft restates a problem a doc draft already covers, keep whichever has the actionable fix + cross-refs.1613. Detect false-positive headings inside fenced code blocks and ignore (e.g. `## [Unreleased]` example inside ```` ```markdown ```` blocks is content, not a heading).162163## Phase 4 — Merge & cleanup164165```bash166cat docs/.faq-draft-*.md >> docs/faq.md && rm docs/.faq-draft-*.md167grep -c '^## ' docs/faq.md168wc -l docs/faq.md169```170171Then refresh the condensed index `docs/faq.agent.md` so new entries appear in the pull-only map. Delegate to ONE `general-purpose` subagent (docs/ write → subagent per Rule 6):172173> Append condensed one-liners for these NEW faq.md entries to `docs/faq.agent.md`. For each, add a line `- <short question stem> — <key answer / fix in ≤12 words>` under a `## Runtime problems & quirks` section (create the section if absent, at the end). Keep the existing sections untouched. Caveman style. New questions + answers: <paste the merged headings + one-line answers>.174175Report to user:176- Total entries before / after (faq.md).177- Entries added per source (table: doc/store → count).178- For memory stores: kept vs skipped-by-relevance-filter counts.179- Any duplicates dropped during Phase 3 (cross-store + doc-vs-memory).180- faq.agent.md lines appended.181- One-line note on false-positive `## ` headings inside code fences (if any).182183---184185## Rules — Documentation Update Protocol compliance186187This skill writes under `docs/` (faq.md + faq.agent.md). Per AGENTS.md:188- All `docs/` writes go through subagents (general-purpose). Main orchestrator only `cat`/`rm`/`Edit`s for merge + targeted dedupe.189- Caveman style is mandatory and passed verbatim to every subagent prompt.190- Every command/path/flag in a generated entry must be verified against the source doc / store entry; no speculation.191- Hermes stores are READ-ONLY inputs — never edit `~/.pi/agent/**`. Extraction copies knowledge into faq.md; it does not move or prune the memory.192- Do NOT rename or delete existing faq.md `## ` headings — `packages/shared/src/tool-registry/__tests__/install-hints.test.ts` asserts each tool `docsAnchor` maps to a heading. Append only.193194## Anti-patterns (do not)195196- Do NOT have multiple subagents write to the same file in parallel — race condition.197- Do NOT mine `AGENTS.md` (incl. `docs/AGENTS.md`) or `docs/faq.agent.md` — indexes, not narrative knowledge.198- Do NOT mine `session-knowledge-*.md` or `spec-gap-analysis.md` — point-in-time notes; entries would rot fast.199- Do NOT skip the global-store relevance filter — `failures.md`/`MEMORY.md` mix projects; unfiltered mining leaks other repos' quirks into this FAQ.200- Do NOT phrase a runtime-problem heading by its internal cause — use the observable symptom (error string / wrong behaviour) so a reader recognises it.201- Do NOT skip Phase 0 dedupe — re-running the skill must not double-add the same questions.202- Do NOT drop the per-entry `Cross-refs:` block — agents lose the source trail otherwise (memory entries cross-ref the store path).