@blackbelt-technology/pi-dashboard-authoring-toolkit 0.5.4 → 0.6.1

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,213 @@
1
+ ---
2
+ name: faq-mine
3
+ description: >-
4
+ Mine docs/faq.md from README.md, docs/*.md, AND the pi-hermes memory stores
5
+ (project MEMORY.md + global failures.md). Dispatches @fast subagents per source
6
+ to extract recurring how-to / what-is questions and runtime-problem fixes,
7
+ dedupes against existing FAQ, and merges entries in caveman style. Use when the
8
+ user asks to "build / regenerate / extend the FAQ", "mine docs into FAQ", "mine
9
+ hermes memory into FAQ", "surface runtime problems in the FAQ", "create FAQ from
10
+ README + docs", or "process knowledge into faq.md".
11
+ license: MIT
12
+ compatibility: Requires @fast subagents (general-purpose) + write access to docs/ + read access to ~/.pi/agent hermes stores.
13
+ metadata:
14
+ author: robson
15
+ version: "2.0"
16
+ ---
17
+
18
+ Orchestrate FAQ extraction from project knowledge docs AND pi-hermes memory
19
+ stores into `docs/faq.md`.
20
+
21
+ Two source classes:
22
+ - **Docs** — README.md + evergreen `docs/*.md`. How-to / what-is questions.
23
+ - **Hermes memory** — accumulated runtime problems (tool-quirks, failures,
24
+ insights, corrections) that never reach the docs. These carry the "why does X
25
+ fail / how do I fix Y" answers a future agent keeps re-discovering.
26
+
27
+ **Inputs**:
28
+ - 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).
29
+ - 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`.
30
+ - Optional `--max <N>` — entry cap per source (default ~10).
31
+
32
+ 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`.
33
+
34
+ ---
35
+
36
+ ## Phase 0 — Pre-flight
37
+
38
+ 1. Read `docs/faq.md` if it exists. Extract every `## <Question>` heading into a dedupe list.
39
+ - If file missing, create with header:
40
+ ```
41
+ # FAQ
42
+
43
+ FAQ. How-to answers that already live in README.md + docs/. New entries here when same question recurs.
44
+ ```
45
+ 2. Enumerate candidate source docs (SKIP this whole step when `--docs skip` — memory-only run):
46
+ ```bash
47
+ ls README.md docs/*.md 2>/dev/null
48
+ ```
49
+ Exclude:
50
+ - `docs/faq.md` itself
51
+ - `docs/faq.agent.md` (condensed index derived FROM faq.md — refreshed in Phase 4, never mined)
52
+ - `docs/AGENTS.md` and any `AGENTS.md` (index, not narrative)
53
+ - `docs/session-knowledge-*.md` (point-in-time notes)
54
+ - `docs/spec-gap-analysis.md` and any `*-resolved.md` (transient analyses)
55
+ - Anything matching `docs/.faq-draft-*.md` (in-flight draft)
56
+ 3. For each remaining doc, capture `wc -l` to surface size.
57
+ 4. Enumerate hermes memory stores (unless `--memory off`):
58
+ ```bash
59
+ PROJ=$(basename "$(git rev-parse --show-toplevel)")
60
+ ls -l "$HOME/.pi/agent/projects-memory/$PROJ/MEMORY.md" \
61
+ "$HOME/.pi/agent/pi-hermes-memory/failures.md" \
62
+ "$HOME/.pi/agent/pi-hermes-memory/MEMORY.md" 2>/dev/null
63
+ ```
64
+ - 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.
65
+ - Global `pi-hermes-memory/failures.md` — **mixed across projects**, needs a repo-relevance filter (subagent applies it).
66
+ - Global `pi-hermes-memory/MEMORY.md` — mixed, only when `--memory all`.
67
+ - Any store path that does not exist: skip silently (fresh machine).
68
+
69
+ ## Phase 1 — Confirm scope
70
+
71
+ 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`.
72
+
73
+ ## Phase 2 — Parallel extraction (@fast subagents)
74
+
75
+ 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:
76
+ - Docs → `docs/.faq-draft-<basename>.md`
77
+ - Stores → `docs/.faq-draft-mem-<label>.md` (`label` = `project` | `failures` | `memory`)
78
+
79
+ ### Phase 2A — Doc mining
80
+
81
+ **Subagent prompt template** (substitute `<DOC>` with the source doc path):
82
+
83
+ > Mine FAQ-worthy entries from `<DOC>` and write them to a NEW file `docs/.faq-draft-<basename>.md`. Do NOT touch any other file.
84
+ >
85
+ > STEP 1 — read existing `docs/faq.md`. Extract every `## <Question>` heading. DEDUPE: skip questions already covered (or trivially equivalent).
86
+ >
87
+ > 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.
88
+ >
89
+ > STEP 3 — write the draft using the EXACT format of existing faq.md entries:
90
+ >
91
+ > ```
92
+ > ## <Question>?
93
+ >
94
+ > <one-line terse answer>
95
+ >
96
+ > Command: `<cmd>` (when applicable; omit for what-is questions).
97
+ >
98
+ > <optional bullets / sub-sections with concrete tokens>
99
+ >
100
+ > Cross-refs:
101
+ > - <DOC>:<line>
102
+ > - <other source file:line>
103
+ > ```
104
+ >
105
+ > CAVEMAN STYLE (verbatim, all docs/ prose obeys):
106
+ > - Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.
107
+ > - Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".
108
+ > - One fact per line/row. No restating context the file already establishes.
109
+ > - Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.
110
+ > - Keep symbols/identifiers verbatim; only connective tissue compresses.
111
+ >
112
+ > Verify every command + path against the source doc. No invented flags, no speculation. Confirm completion in your final reply with the entry count.
113
+
114
+ ### Phase 2B — Hermes memory mining
115
+
116
+ 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.
117
+
118
+ **Subagent prompt template** (substitute `<STORE>` = absolute store path, `<LABEL>` = `project`|`failures`|`memory`, `<FILTER>` = the relevance rule below):
119
+
120
+ > 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.
121
+ >
122
+ > 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).
123
+ >
124
+ > 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.
125
+ >
126
+ > <FILTER>
127
+ >
128
+ > STEP 3 — for each KEPT entry, write a symptom-first FAQ entry in the EXACT faq.md format:
129
+ >
130
+ > ```
131
+ > ## Why does <symptom>? (or: How do I fix <symptom>?)
132
+ >
133
+ > <one-line root cause — terse>
134
+ >
135
+ > Fix: `<cmd>` (or the concrete file/edit; omit when not a command).
136
+ >
137
+ > <optional bullets: concrete tokens — paths, env vars, flags, exit codes>
138
+ >
139
+ > Cross-refs:
140
+ > - <STORE>
141
+ > - <every file path / package named inside the entry>
142
+ > ```
143
+ >
144
+ > - 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.
145
+ > - Keep the wrong-way → right-way fix intact; that is the whole value of the entry.
146
+ > - Merge near-duplicate store entries (same problem, consolidated across dates) into ONE FAQ entry.
147
+ >
148
+ > CAVEMAN STYLE (verbatim, all docs/ prose obeys):
149
+ > - Short declarative fragments. Drop articles (a/an/the) and most copulas (is/are/was) when meaning survives.
150
+ > - Subject → verb → object, present tense. No hedging, no marketing voice, no "we", no "you".
151
+ > - One fact per line. No restating context the file already establishes.
152
+ > - Prefer concrete tokens (paths, function names, env vars, ports, exit codes) over prose.
153
+ > - Keep symbols/identifiers verbatim; only connective tissue compresses.
154
+ >
155
+ > 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.
156
+
157
+ **`<FILTER>` value by store:**
158
+ - Project store (`<LABEL>=project`): `STEP 2b — no filter. Every entry is scoped to this repo; consider all of them.`
159
+ - 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.`
160
+
161
+ Wait for all agents (2A + 2B) to finish.
162
+
163
+ ## Phase 3 — Cross-draft dedupe
164
+
165
+ 1. Run:
166
+ ```bash
167
+ grep -n '^## ' docs/.faq-draft-*.md
168
+ ```
169
+ 2. 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`.
170
+ - **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.
171
+ - **Doc-vs-memory dup**: when a memory draft restates a problem a doc draft already covers, keep whichever has the actionable fix + cross-refs.
172
+ 3. Detect false-positive headings inside fenced code blocks and ignore (e.g. `## [Unreleased]` example inside ```` ```markdown ```` blocks is content, not a heading).
173
+
174
+ ## Phase 4 — Merge & cleanup
175
+
176
+ ```bash
177
+ cat docs/.faq-draft-*.md >> docs/faq.md && rm docs/.faq-draft-*.md
178
+ grep -c '^## ' docs/faq.md
179
+ wc -l docs/faq.md
180
+ ```
181
+
182
+ 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):
183
+
184
+ > 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>.
185
+
186
+ Report to user:
187
+ - Total entries before / after (faq.md).
188
+ - Entries added per source (table: doc/store → count).
189
+ - For memory stores: kept vs skipped-by-relevance-filter counts.
190
+ - Any duplicates dropped during Phase 3 (cross-store + doc-vs-memory).
191
+ - faq.agent.md lines appended.
192
+ - One-line note on false-positive `## ` headings inside code fences (if any).
193
+
194
+ ---
195
+
196
+ ## Rules — Documentation Update Protocol compliance
197
+
198
+ This skill writes under `docs/` (faq.md + faq.agent.md). Per AGENTS.md:
199
+ - All `docs/` writes go through subagents (general-purpose). Main orchestrator only `cat`/`rm`/`Edit`s for merge + targeted dedupe.
200
+ - Caveman style is mandatory and passed verbatim to every subagent prompt.
201
+ - Every command/path/flag in a generated entry must be verified against the source doc / store entry; no speculation.
202
+ - Hermes stores are READ-ONLY inputs — never edit `~/.pi/agent/**`. Extraction copies knowledge into faq.md; it does not move or prune the memory.
203
+ - 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.
204
+
205
+ ## Anti-patterns (do not)
206
+
207
+ - Do NOT have multiple subagents write to the same file in parallel — race condition.
208
+ - Do NOT mine `AGENTS.md` (incl. `docs/AGENTS.md`) or `docs/faq.agent.md` — indexes, not narrative knowledge.
209
+ - Do NOT mine `session-knowledge-*.md` or `spec-gap-analysis.md` — point-in-time notes; entries would rot fast.
210
+ - Do NOT skip the global-store relevance filter — `failures.md`/`MEMORY.md` mix projects; unfiltered mining leaks other repos' quirks into this FAQ.
211
+ - Do NOT phrase a runtime-problem heading by its internal cause — use the observable symptom (error string / wrong behaviour) so a reader recognises it.
212
+ - Do NOT skip Phase 0 dedupe — re-running the skill must not double-add the same questions.
213
+ - Do NOT drop the per-entry `Cross-refs:` block — agents lose the source trail otherwise (memory entries cross-ref the store path).
@@ -0,0 +1,3 @@
1
+ # faq-mine/SKILL.md — index
2
+
3
+ Skill (v2.0): mine `docs/faq.md` from TWO source classes — docs (README.md + evergreen `docs/*.md`) AND pi-hermes memory stores (project `~/.pi/agent/projects-memory/<proj>/MEMORY.md` + global `~/.pi/agent/pi-hermes-memory/failures.md`, `MEMORY.md`). Memory source surfaces runtime problems (tool-quirks/failures/insights) that never reach docs. Inputs `--memory <off|project|failures|all>` (default `failures`), `--docs <list|skip>` (`skip` = memory-only). Passing both `--docs` + `--memory` skips Phase 1 prompt (headless `--docs skip --memory failures` = the ship-change step-10.5 harvest). Phase 0 dedupe existing `## ` headings + enumerate stores; Phase 1 `ask_user` multiselect (docs + stores); Phase 2A doc-mining subagents, Phase 2B memory-mining subagents (symptom-first Q&A, global stores get repo-relevance filter), each writes own `docs/.faq-draft-*.md`; Phase 3 cross-draft + cross-store + doc-vs-memory dedupe; Phase 4 `cat >> faq.md` + rm drafts + refresh condensed `docs/faq.agent.md` via subagent. Caveman style, `Cross-refs:` blocks (memory entries cross-ref store path). READ-ONLY on `~/.pi/agent/**`. Never rename existing faq.md headings (install-hints.test.ts asserts `docsAnchor`→heading). Excludes `AGENTS.md`, `docs/faq.agent.md`, `session-knowledge-*.md`, `spec-gap-analysis.md`.
@@ -24,9 +24,11 @@ Two layers:
24
24
  the active branch and emits a structured **facts sheet** (prompts in order, tool usage,
25
25
  files written/edited, searches, skills/memories created, failed commands, cost). This is
26
26
  raw material, not the deliverable. TypeScript, run with `npx tsx` (repo convention).
27
- 2. **Synthesis (you, the agent)** — read the facts sheet and write the guideline using
27
+ 2. **Synthesis** — read the facts sheet and write the guideline using
28
28
  `references/guideline-template.md`. The *why it's effective* and *what to steer* parts
29
- require judgment; that's your job.
29
+ require judgment. Run it inline for a single session, or delegate to the
30
+ **`SessionGuideline` subagent** for batch / past-session application (see below) — the
31
+ synthesis is self-contained (facts sheet in, one guideline out), so it isolates cleanly.
30
32
 
31
33
  ## Where sessions live
32
34
 
@@ -45,16 +47,20 @@ Two layers:
45
47
  session is usually #0/`latest`; documenting a finished prior session gives a complete
46
48
  picture (the live one won't include the not-yet-written tail).
47
49
 
48
- 2. **Extract the facts sheet** (cheap, deterministic):
50
+ 2. **Extract the facts sheet** (cheap, deterministic). Use a UNIQUE output path per run —
51
+ the fixed `/tmp/session_facts.md` is **NOT parallel-safe**: concurrent runs (e.g. a batch
52
+ of `SessionGuideline` spawns) clobber the same file and every reader gets the last
53
+ writer's sheet. Always `mktemp`:
49
54
  ```bash
50
- npx tsx scripts/extract_session.ts <id-or-'latest'> --cwd "$(pwd)" \
51
- --out-md /tmp/session_facts.md --out-json /tmp/session_facts.json
55
+ FACTS=$(mktemp /tmp/session_facts.XXXXXX.md)
56
+ npx tsx scripts/extract_session.ts <selector> --cwd "$(pwd)" --out-md "$FACTS"
52
57
  ```
53
58
  - `<selector>` may be an 8-char id, a full path, or `latest` (use `--index N` for the
54
- Nth most recent).
59
+ Nth most recent). In BATCH runs prefer the **explicit JSONL path** — the extract's
60
+ parent-chain walk can drift to a parent file on forked sessions.
55
61
  - Use `--max-text` / `--max-cmd` to widen truncation if you need more prompt/command text.
56
62
 
57
- 3. **Read the facts sheet** (`/tmp/session_facts.md`). Pay attention to:
63
+ 3. **Read the facts sheet** (`$FACTS`). Pay attention to:
58
64
  - **Prompt 1 = the goal**; **prompts 2..N = steering** (corrections, scope additions,
59
65
  quality bars, yes/all-three style unlocks).
60
66
  - **Skills created / Memories saved** — these are the reusable assets; explain *why*.
@@ -78,6 +84,39 @@ Two layers:
78
84
  relative to `Prompt stories/` (e.g. `../Projektek/<Project>/.../shot_01.png`) and verify
79
85
  each resolves. Tell the user the path.
80
86
 
87
+ ## Batch / past-session application (via the `SessionGuideline` subagent)
88
+
89
+ The synthesis is self-contained — facts sheet in, one guideline out, no coherence with any
90
+ ongoing work — so it is a clean subagent job. For a SINGLE interactive session, running it
91
+ inline (above) is fine. For applying to MANY past sessions, delegate each to the
92
+ **`SessionGuideline`** subagent so the facts sheet and the reasoning stay out of the main
93
+ context and sessions don't accumulate there:
94
+
95
+ 1. List the target sessions once:
96
+ ```bash
97
+ npx tsx scripts/list_sessions.ts --cwd "$(pwd)" --limit 50 # or --all
98
+ ```
99
+ 2. For each session, spawn `SessionGuideline` (explicit `Agent` call), passing the
100
+ **explicit JSONL path** (not a partial id — the extract's parent-chain walk can drift to
101
+ a parent file on forked sessions) + an explicit output path. Each spawn runs BOTH layers
102
+ in isolation (extract → synthesise) and returns only the written path + a short abstract:
103
+ ```
104
+ Agent(subagent_type="SessionGuideline",
105
+ prompt="session JSONL <abs-path>; cwd <dir>; write to Prompt stories/<Topic>.md")
106
+ ```
107
+ 3. Collect the returned paths. Parallel batches are safe ONLY because step 2 uses a
108
+ `mktemp` facts sheet per run — the old fixed `/tmp/session_facts.md` raced (concurrent
109
+ spawns overwrote it, so every playbook got the same sheet). Verify no two outputs share
110
+ an H1 title before trusting a batch.
111
+
112
+ **Model role.** The synthesis is judgment-heavy WRITING on a SMALL, pre-condensed input
113
+ (the extract script shrinks the JSONL first — it is NOT a long-context job). Quality lives
114
+ in the insight sections (goal-vs-steering, steering→guardrails, why-skills-effective),
115
+ where a weak model produces generic slop. Use **`@research`** (the subagent's default) for
116
+ quality. For bulk backfill where cost dominates, **`@compact`** is the budget fallback
117
+ (mechanical sections stay fine; insight degrades) — pass `model` on the `Agent` call to
118
+ override per run.
119
+
81
120
  ## Selector cheatsheet
82
121
 
83
122
  | Goal | Command |
@@ -310,6 +310,7 @@ Write the YAML frontmatter with `name` and `description`:
310
310
  - Include both what the Skill does and specific triggers/contexts for when to use it.
311
311
  - Include all "when to use" information here - Not in the body. The body is only loaded after triggering, so "When to Use This Skill" sections in the body are not helpful to Claude.
312
312
  - Example description for a `docx` skill: "Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. Use when Claude needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks"
313
+ - **Quote the value if it contains a `colon-space` (e.g. `Triggers: "..."`).** An unquoted description with an inner `: ` parses as a nested YAML mapping and the loader silently drops the skill (`Nested mappings are not allowed in compact mappings`). Wrap the whole value in double quotes and escape inner `"`. Enforced by `scripts/__tests__/skill-frontmatter.test.mjs`. See change: fix-skill-frontmatter-yaml.
313
314
 
314
315
  Do not include any other fields in YAML frontmatter.
315
316
 
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: skill-to-subagent
3
+ description: "Turn an existing pi skill into an isolated subagent and wire it into a project's implementation pipeline. Use on triggers like \"wrap this skill as a subagent\", \"turn X into a subagent\", \"create a subagent from a skill\", \"should this be a subagent or a skill\", \"subagentize this\", \"isolate this into its own context\", \"add a subagent to the pipeline\". Tech-stack independent (works for any target project) but pi-platform-specific: relies on pi's .pi/agents/*.md, the Agent tool, role aliases, and inherit_context. Decides fitness first (coherence-critical work stays an inline skill), then writes the bridge agent, routes the model by function, tunes context inheritance, and wires a spawn checkpoint. Not a skill-authoring workflow (that's skill-creator) and not a feature-build workflow."
4
+ related_skills: skill-creator
5
+ ---
6
+
7
+ # Skill → Subagent
8
+
9
+ ## Overview
10
+
11
+ A **skill** is instructions loaded *into* the main agent's context (progressive disclosure: name+description always present, body on trigger). A **subagent** is a worker spawned *beside* the main agent in an **isolated** context window that returns a distilled report, then burns its context. They are orthogonal.
12
+
13
+ Converting a skill to a subagent is worth it when the skill's work is **read-heavy or write-light, self-contained, and returns a distilled artifact** — because running it inline would bloat the parent's context and degrade its reasoning. It is **harmful** when the work is coherence-critical (decisions later steps depend on), because a subagent only sees a compressed snapshot and can make conflicting assumptions.
14
+
15
+ This skill is the repeatable procedure for that conversion, plus wiring the result into a project's implementation loop. It is tech-stack independent (the target project can be any language) but pi-platform-specific.
16
+
17
+ ## When to Use
18
+
19
+ - You have a skill whose work would bloat the main context if run inline
20
+ - A phase of an implementation loop is read-heavy (audit, lookup, summarize) or write-light (docs) and self-contained
21
+ - You are designing which parts of a pipeline should run isolated vs inline
22
+ - Triggers: "wrap this skill as a subagent", "subagentize this", "should this be a subagent"
23
+
24
+ **When NOT to use:**
25
+
26
+ - Authoring a brand-new skill from scratch → `skill-creator`
27
+ - The work is coherence-critical (the builder/decider, review+fix, anything whose choices later steps depend on) → keep it an inline skill
28
+ - A one-shot trivial task where spawn overhead > benefit
29
+
30
+ ## Step 1 — DECIDE: subagent or inline skill?
31
+
32
+ Apply the **discriminator** first. It is the whole game.
33
+
34
+ ```text
35
+ Does the phase need shared coherence with the surrounding work?
36
+ (i.e. do later steps depend on decisions made here?)
37
+
38
+ YES ──▶ INLINE SKILL (full context; review, fix, decide, mutate)
39
+ NO, and it is read-heavy / write-light and returns a distilled
40
+ artifact ──▶ SUBAGENT (isolated, ≤2KB report)
41
+ ```
42
+
43
+ Then confirm fitness — a subagent must clear **all** of these, or it is negative value:
44
+
45
+ - **Context-cost-if-inline is high** — running it inline would meaningfully bloat the parent.
46
+ - **Clear input→distilled-output contract** — you can name the inputs and the ≤2KB output shape.
47
+ - **Low interactivity** — it does not need `ask_user` loops mid-task (those belong in the parent).
48
+ - **Self-contained** — it does not mutate shared state the parent must then reconcile.
49
+ - **Clears the token bar** — multi-agent runs burn ~15× the tokens of a single chat; the context it saves must exceed the tokens it spends.
50
+
51
+ If it fails any, keep it an inline skill. Most "writer" and "reviewer" phases fail the coherence test and should stay inline.
52
+
53
+ ## Step 2 — BRIDGE: write the thin agent `.md`
54
+
55
+ The skill stays the single source of truth. The agent is a thin spawn shell that loads it. Write to `<project>/.pi/agents/<Name>.md` (project tier) or a package's `agents/` dir (shipped tier).
56
+
57
+ ```yaml
58
+ ---
59
+ description: <when the parent should spawn this>. Wraps /skill:<name>. Returns a distilled report, never raw dumps.
60
+ model: "@research" # role ALIAS, resolved at spawn (see Step 3)
61
+ inherit_context: false # see Step 4
62
+ tools: [read, grep, find, ls, bash] # least-privilege; add write/edit only if it emits files
63
+ ---
64
+
65
+ You are the <Name> subagent. Load and follow `/skill:<name>`.
66
+
67
+ Your single job: <one scoped task>, return a short structured report, then burn
68
+ this context so the parent stays sharp.
69
+
70
+ INPUTS the parent MUST supply in the spawn prompt (inherit_context is false —
71
+ you get no parent chatter; work only from these):
72
+ • <input 1 — e.g. the diff scope / file paths>
73
+ • <input 2 — the intent, 1-2 lines>
74
+
75
+ OUTPUT CONTRACT (≤ 2000 tokens):
76
+ ## <Result heading>
77
+ <distilled findings — cite path + line ranges, quoted code ≤ 10 lines>
78
+ ## Notes (what you did not check)
79
+
80
+ Do NOT paste whole files. Cite path + heading. Then stop.
81
+ ```
82
+
83
+ ## Step 3 — ROUTE: pick the model by FUNCTION, via role alias
84
+
85
+ Use **role aliases**, never literal model ids — the agent then tracks the operator's role config and stays portable across machines.
86
+
87
+ | Function | Role | Why |
88
+ |---|---|---|
89
+ | Deterministic pipeline / glue / lookup / exploration | `@fast` | Cheap, fast; cost dominates |
90
+ | Long-context synthesis (transcripts, big docs) | `@research` | Strong synthesis / long window |
91
+ | Reasoning-heavy analysis (security audit, root-cause) | `@research` (or a reasoning model role) | Careful step-by-step over code |
92
+ | Map-reduce | chunk workers `@fast`, merge `@compact`/`@research` | Cheap per chunk, strong merge |
93
+ | Mechanical writing (doc rows, merges) | `@compact` | Cheap-but-capable |
94
+ | Visual / screenshot review | `@vision` | Multimodal |
95
+
96
+ ## Step 4 — TUNE: `inherit_context`
97
+
98
+ - **`false` + explicit inputs (default, most reliable).** The child starts clean; the parent passes every input in the spawn prompt. Dodges the compression-drop trap. Use for self-contained batch/analysis jobs.
99
+ - **`true`** only when the child's judgement genuinely needs the surrounding decision context — and **even then, still pass exact paths + intent in the prompt**, because the inherited snapshot is *compressed* and can drop the one detail the specialist needs.
100
+
101
+ ## Step 5 — WIRE: spawn checkpoint into the pipeline
102
+
103
+ **pi has no automatic delegation** — a subagent runs only on an explicit `Agent` tool call. Make delegation mechanical by adding a **checkpoint table** to the project's implementation skill (and/or `AGENTS.md`): map an *observable signal in the diff/task* to a spawn, so the main agent reaches for it without needing to remember.
104
+
105
+ ```markdown
106
+ | Signal in the task / diff | Spawn |
107
+ |---|---|
108
+ | touches auth / secrets / PII / untrusted input / perf budget | `Audit` (fix inline) |
109
+ | a change landed and docs/ prose needs updating | `DocScribe` |
110
+ ```
111
+
112
+ Keep the builder/decider inline in that table's preamble — only read/write-light phases get spawned.
113
+
114
+ ## Step 6 — VERIFY
115
+
116
+ Spawn on a real task and check the output, do not trust it blind.
117
+
118
+ ## Pitfalls
119
+
120
+ - **YAML `": "` trap** — an unquoted `description` containing an inner `": "` (colon-space) parses as a nested mapping and the loader **silently drops the agent**. Quote the whole value, or reword to remove the `": "`.
121
+ - **Compression-drop** — `inherit_context: true` gives a *lossy* snapshot; never rely on it to carry a specific path/snippet. Pass inputs explicitly.
122
+ - **Fresh ResourceLoader** — a spawned subagent re-discovers skills from disk (its own loader), so the wrapped skill must be discoverable on disk, not just loaded in the parent.
123
+ - **Telephone game** — cap output at ≤2KB and cite paths; a subagent that dumps raw files defeats its own purpose.
124
+ - **Over-privilege** — least-privilege `tools`; add `write`/`edit` only if the subagent legitimately emits files.
125
+ - **Isolating coherence** — never subagent the builder, the review+fix loop, or any decider; that is the documented multi-agent failure mode.
126
+
127
+ ## Verification
128
+
129
+ - [ ] The discriminator was applied — the phase is genuinely non-coherence-critical
130
+ - [ ] The agent `.md` frontmatter parses (no `": "` trap); `model` is a role alias
131
+ - [ ] `tools` are least-privilege; `inherit_context` matches the input strategy
132
+ - [ ] The prompt names every required input and a ≤2KB output contract
133
+ - [ ] A spawn checkpoint (signal → spawn) exists in the pipeline so it is reached mechanically
134
+ - [ ] A real spawn returned a distilled report, not raw dumps
package/README.md CHANGED
@@ -9,6 +9,7 @@ trigger from their frontmatter `description`; no manual invocation.
9
9
  | Skill | What it does | Fires on |
10
10
  |-------|--------------|----------|
11
11
  | `skill-creator` | Guide for authoring or updating a skill — structure, frontmatter, scripts/references layout, progressive disclosure. | "create a skill", "write a new skill", "update this skill", "how do I author a skill" |
12
+ | `skill-to-subagent` | Turn an existing skill into an isolated subagent and wire it into a project's pipeline — fitness discriminator, bridge-agent template, model-by-function routing, `inherit_context` tuning, spawn checkpoint. Tech-stack independent, pi-platform-specific. | "wrap this skill as a subagent", "subagentize this", "should this be a subagent", "add a subagent to the pipeline" |
12
13
  | `session-to-guideline` | Turns a pi session JSONL transcript into a reusable "how-we-did-it" Markdown playbook: goal vs. steering, tools/files/searches used, skills/memories created, reproduce-it checklist. | "document this session", "write up how we did X with the AI", "make a guideline/playbook from this session", "turn this session into a tutorial" |
13
14
 
14
15
  `session-to-guideline` ships `scripts/` (deterministic facts-sheet extractor +
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-authoring-toolkit",
3
- "version": "0.5.4",
4
- "description": "General-purpose authoring skills for pi sessions — skill-creator (author/update skills) and session-to-guideline (turn a pi session JSONL transcript into a how-we-did-it Markdown playbook). Pure-skill package, no extension.ts. skill-creator adapted from Anthropic's skill-creator (MIT).",
3
+ "version": "0.6.1",
4
+ "description": "General-purpose authoring skills for pi sessions — skill-creator (author/update skills), skill-to-subagent (wrap a skill as a subagent), session-to-guideline (turn a pi session JSONL transcript into a how-we-did-it Markdown playbook), and faq-mine (mine docs + memory stores into a FAQ). Pure-skill package, no extension.ts. skill-creator adapted from Anthropic's skill-creator (MIT).",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -15,7 +15,9 @@
15
15
  "pi": {
16
16
  "skills": [
17
17
  ".pi/skills/skill-creator",
18
- ".pi/skills/session-to-guideline"
18
+ ".pi/skills/skill-to-subagent",
19
+ ".pi/skills/session-to-guideline",
20
+ ".pi/skills/faq-mine"
19
21
  ]
20
22
  },
21
23
  "files": [