greprag 5.6.1 → 5.7.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.
@@ -41,12 +41,15 @@ Parse the JSON. The keys to check, in this order:
41
41
 
42
42
  For Claude Code, also check `hooks.session_start_recap`, `hooks.stop_store`, `hooks.post_tool_use_spawn_reminder`. (The legacy `user_prompt_submit_notify` hook was removed in v5.6.1 — live inbox delivery is now the Monitor watcher's job. Don't install it.)
43
43
 
44
- Also check the chip-coordination convention is installed in global CLAUDE.md (Step 3b):
44
+ Also check the chip-spawn pointer is installed in global CLAUDE.md (Step 3b):
45
45
  ```bash
46
- if grep -q "greprag-conventions:start v3" ~/.claude/CLAUDE.md; then echo CONV_V3
46
+ if grep -q "greprag-conventions:start v5" ~/.claude/CLAUDE.md; then echo CONV_V5
47
+ elif grep -q "greprag-conventions:start v4" ~/.claude/CLAUDE.md; then echo CONV_V4_NEEDS_UPGRADE
48
+ elif grep -q "greprag-conventions:start v3" ~/.claude/CLAUDE.md; then echo CONV_V3_NEEDS_UPGRADE
47
49
  elif grep -q "greprag-conventions:start v2" ~/.claude/CLAUDE.md; then echo CONV_V2_NEEDS_UPGRADE
48
50
  elif grep -q "greprag-conventions:start v1" ~/.claude/CLAUDE.md; then echo CONV_V1_NEEDS_UPGRADE
49
51
  else echo CONV_MISSING; fi
52
+ test -f ~/.claude/docs/chip-spawn.md && echo DOC_OK || echo DOC_MISSING
50
53
  ```
51
54
 
52
55
  Also check the permission allowlist (Step 3c):
@@ -95,71 +98,54 @@ Edit `~/.claude/settings.json` to add the missing hook(s):
95
98
  ```json
96
99
  { "matcher": "", "hooks": [{ "type": "command", "command": "greprag-hook store", "timeout": 10000 }] }
97
100
  ```
98
- - **PostToolUse spawn-reminder** (under `hooks.PostToolUse`):
101
+ - **PreToolUse pre-spawn-check** (under `hooks.PreToolUse`):
99
102
  ```json
100
- { "matcher": "mcp__ccd_session__spawn_task", "hooks": [{ "type": "command", "command": "greprag-hook spawn-reminder", "timeout": 3000 }] }
103
+ { "matcher": "mcp__ccd_session__spawn_task", "hooks": [{ "type": "command", "command": "greprag-hook pre-spawn-check", "timeout": 3000 }] }
101
104
  ```
102
- Fires after every `spawn_task` chip dispatch and tells the agent to arm a `Monitor` watcher on its own inbox in the same turn so the chip's report-back doesn't sit invisible until the next user prompt. The convention itself lives in `~/.claude/docs/agent-coordination.md § Block 3`; this hook just makes it reflexive.
105
+ Fires BEFORE every `spawn_task` chip dispatch and validates the call against three machine-checkable rules from `~/.claude/CLAUDE.md § Chip Spawning`: title prefix `Chip: `, Block 1 (`git worktree add` in prompt), Block 2 (`greprag send` in prompt). Returns `permissionDecision: "deny"` with remediation when any rule fails; the agent re-composes the call.
103
106
 
104
107
  Append the missing entries to the existing arrays (create the arrays if absent). Don't overwrite existing hooks from other tools.
105
108
 
109
+ **Removing the legacy PostToolUse spawn-reminder hook** (only on upgrade from v0.x → v0.12+): if `~/.claude/settings.json` `hooks.PostToolUse` contains an entry with `matcher: "mcp__ccd_session__spawn_task"` and `command: "greprag-hook spawn-reminder"`, delete that entry. The behavior it carried (arming a Monitor watcher) is now ambient — SessionStart auto-arms the watcher in every greprag-enabled session, so the PostToolUse reminder is vestigial and the underlying subcommand was removed in v0.12.
110
+
106
111
  ## Step 3b — Convention install (only if marker missing or out-of-date)
107
112
 
108
- The chip-spawning + agent-coordination convention is a one-time install into the user's global CLAUDE.md. Every project session reads it; without it, chips spawn without worktree isolation, inbox report-back, or reply-listening. Detect first:
113
+ Two pieces install together:
114
+
115
+ 1. A single loud pointer line in `~/.claude/CLAUDE.md` — always loaded into every session's context.
116
+ 2. The actual chip-spawn protocol at `~/.claude/docs/chip-spawn.md` — read on demand by the agent when about to call `spawn_task`.
117
+
118
+ The pointer is short by design: the body costs zero tokens per session that never spawns a chip, the agent reads the doc only when about to act. The PreToolUse `pre-spawn-check` hook enforces title + Block 1/2 at the tool boundary, so an agent that skips the doc still can't ship a bad chip.
109
119
 
120
+ Detect first:
110
121
  ```bash
111
- if grep -q "greprag-conventions:start v3" ~/.claude/CLAUDE.md; then echo V3
122
+ if grep -q "greprag-conventions:start v5" ~/.claude/CLAUDE.md; then echo V5
123
+ elif grep -q "greprag-conventions:start v4" ~/.claude/CLAUDE.md; then echo V4_UPGRADE
124
+ elif grep -q "greprag-conventions:start v3" ~/.claude/CLAUDE.md; then echo V3_UPGRADE
112
125
  elif grep -q "greprag-conventions:start v2" ~/.claude/CLAUDE.md; then echo V2_UPGRADE
113
126
  elif grep -q "greprag-conventions:start v1" ~/.claude/CLAUDE.md; then echo V1_UPGRADE
114
127
  else echo MISSING; fi
115
- test -f ~/.claude/docs/agent-coordination.md && echo DOC_OK || echo DOC_MISSING
128
+ test -f ~/.claude/docs/chip-spawn.md && echo DOC_OK || echo DOC_MISSING
116
129
  ```
117
130
 
118
- **If `MISSING`**, insert the v3 block into `~/.claude/CLAUDE.md` immediately after the `## Inbox` section (use the Edit tool, marker comments verbatim):
131
+ **If `MISSING`**, insert the v5 block into `~/.claude/CLAUDE.md` immediately after the `## Inbox` section (use the Edit tool, marker comments verbatim):
119
132
 
120
133
  ```markdown
121
- <!-- greprag-conventions:start v3 -->
122
- ## Chip Spawning & Agent Coordination
123
-
124
- Delegating work — `spawn_task` chip vs `Agent` tool, two chip modes, the worktree-first + inbox-report + reply-listening convention. Full spec: `~/.claude/docs/agent-coordination.md`.
125
-
126
- **Two chip modes** — pick deliberately:
127
- - **Mode A (default) — ship chip.** Lands in a worktree, ships code, user-in-loop optional. The workhorse. A chip that dispatches its own `Agent` sub-tasks mid-work is still Mode A — that's a behavior, not a peer mode.
128
- - **Mode B — discussion chip.** Lands as a context-rich conversation partner. Reads code, proposes, iterates. Ships nothing without explicit go-ahead. Output is a decision or a scoped follow-up chip. Reach for B the moment you notice you're proposing architecture from partial grep reads.
129
-
130
- **Spawn primitives** (not modes — pick by what fits the work):
131
- - `spawn_task` — Mode A or B chip. Worktree, chip UI, persistence, optional cross-project via `cwd:`.
132
- - `Agent` — one-shot delegation, returns once to caller. No chip lifecycle. Pass `subagent_type` (Explore / Plan / general-purpose / code-reviewer) when a specialized shape fits.
133
-
134
- **Non-negotiables for every `spawn_task` chip prompt:** (0.5) project facts pulled from `greprag fact`, (1) worktree-first setup, (2) `greprag send` report-back, (3) `Monitor` on own inbox for follow-ups. Without them the chip pollutes the main checkout, has no return channel, or dies after one report. Copy the boilerplate verbatim from the deep doc.
135
-
136
- **Reply listening (any session, not just chips).** Any time you `greprag send` a message that could draw a directive in response, arm a `Monitor` watcher on your own inbox in the same turn. Use the bash-wrapper form so the watcher auto-restarts if the inner SSE process dies (network blip, supervisor bug, Cygwin fork failure):
137
-
138
- ```bash
139
- while true; do greprag inbox watch --session <own-session-id> --json; echo "[wrapper] watcher exited, restarting in 1s" >&2; sleep 1; done
140
- ```
141
-
142
- Run under `Monitor` with `persistent: true`. Get `<own-session-id>` from this session's SessionStart hook system-reminder ("Your greprag session id: `<8-hex>`") — every session gets one. The `--project <own-project>` form is a legacy backstop for sessions where SessionStart never fired and should fire essentially never; using it as a default broadcasts traffic to every sibling session in the project (observed cross-talk in production). The Stop hook only fires between user prompts; without Monitor, mid-task replies are invisible until the next stop boundary.
143
-
144
- For real-time chip reports, the parent arms the same wrapped watcher with `--session <parent-session-id>` (always available from the orchestrator's own SessionStart hook — substitute it before the chip prompt leaves your turn). The `--project <parent-project>` variant is for genuine multi-chip-campaign cases where you've fanned out N chips in parallel and want all reports on one stream; do not reach for it because you "forgot" your session id. Each stdout line = one notification. Do NOT use `Bash(run_in_background)` — it only fires on process completion, not per line; a watcher never exits, so the parent gets zero events. Do NOT use the bare `greprag inbox watch` without the `while true` wrapper — if the inner watcher dies you go silently deaf with no restart.
145
- <!-- greprag-conventions:end v3 -->
134
+ <!-- greprag-conventions:start v5 -->
135
+ **CHIP SPAWN METHOD** before calling `spawn_task`, read `~/.claude/docs/chip-spawn.md`. Non-negotiable.
136
+ <!-- greprag-conventions:end v5 -->
146
137
  ```
147
138
 
148
- **If `V2_UPGRADE`**, replace the entire `<!-- greprag-conventions:start v2 -->` … `<!-- greprag-conventions:end v2 -->` block (inclusive of markers) with the v3 block above. Tell the user "Upgrading greprag-conventions v2v3 (collapses Mode B mission-commander into Mode A behavior; renames Mode C to Mode B = discussion chip)." Don't preserve any v2 content — v3 supersedes.
149
-
150
- **If `V1_UPGRADE`**, replace the entire `<!-- greprag-conventions:start v1 -->` … `<!-- greprag-conventions:end v1 -->` block (inclusive of markers) with the v3 block above. Tell the user "Upgrading greprag-conventions v1 → v3 (adds Block 3 reply-listening; reframes modes as ship chip + discussion chip)." Don't preserve any v1 content — v3 supersedes.
139
+ **If `V4_UPGRADE`**, replace the entire `<!-- greprag-conventions:start v4 -->` … `<!-- greprag-conventions:end v4 -->` block (inclusive of markers) with the v5 single-line pointer above. Tell the user "Upgrading greprag-conventions v4v5 (moves the inline body to ~/.claude/docs/chip-spawn.md; CLAUDE.md now carries only a loud pointer read on demand)."
151
140
 
152
- **If `DOC_MISSING`**, copy the canonical content from the template shipped with this skill:
153
- ```bash
154
- mkdir -p ~/.claude/docs && cp ~/.claude/skills/greprag/templates/agent-coordination.md ~/.claude/docs/agent-coordination.md
155
- ```
141
+ **If `V3_UPGRADE`, `V2_UPGRADE`, or `V1_UPGRADE`**, same replacement pattern: delete the old block (markers inclusive) and insert the v5 pointer above. Tell the user "Upgrading greprag-conventions v{1|2|3} → v5."
156
142
 
157
- If `DOC_OK` but you just upgraded from v1 or v2, overwrite the doc too (the v3 template carries the new mode framing + operating guidelines + detection signals):
143
+ **Also on any upgrade from v1/v2/v3 v5**, delete the legacy deep doc if it exists (its content lives at the new `chip-spawn.md` path now):
158
144
  ```bash
159
- cp ~/.claude/skills/greprag/templates/agent-coordination.md ~/.claude/docs/agent-coordination.md
145
+ rm -f ~/.claude/docs/agent-coordination.md
160
146
  ```
161
147
 
162
- The deep doc covers Block 0.5 (project-facts pull), Block 1 (worktree-first), Block 2 (inbox report-back), Block 3 (reply-listening), parent-side watcher, Mode A operating guidelines + sub-Agent dispatch (3-layer chain when needed), Mode B detection signals + operating guidelines, and anti-patterns.
148
+ **If `DOC_MISSING`**, the chip-spawn protocol doc must be installed at `~/.claude/docs/chip-spawn.md`. `greprag init` copies it from the npm package on install; if it's missing here, re-run `greprag init` (`init` is idempotent and will re-copy the template). The doc is the body the pointer line references without it the agent has nothing to read.
163
149
 
164
150
  Re-run the grep to confirm install. Markers must stay verbatim — they're how subsequent `/greprag` runs detect "already installed" and skip this step.
165
151
 
@@ -625,9 +611,9 @@ Otherwise present verbatim:
625
611
 
626
612
  Do not rewrite or summarize. Present verbatim — the compactor already shaped it.
627
613
 
628
- ## Step 6b — Seeding learnings (project-facts substrate)
614
+ ## Step 6b — Seeding lore (LEARNINGS substrate)
629
615
 
630
- Whenever you waste tokens *discovering* something a future agent shouldn't have to re-discover, seed it as a project fact. Discovery is fine the first time — the failure mode is repeating it every time a chip spawns or a new session opens.
616
+ Lore = what was learned. Project-specific emergent knowledge — gotchas, discovered constraints, drift-prone observations. Distinct from static project knowledge (which belongs in CLAUDE.md / docs / code structure). Whenever you waste tokens *discovering* something a future agent shouldn't have to re-discover, seed it as project lore. Discovery is fine the first time — the failure mode is repeating it every time a chip spawns or a new session opens.
631
617
 
632
618
  ### When to seed
633
619
 
@@ -640,51 +626,51 @@ Three signatures of discovery waste — if you see one in your own trace, seed t
640
626
  ### How to seed
641
627
 
642
628
  ```bash
643
- greprag fact add "<one-sentence fact, optionally with a file path>" --scope <scope> [--project <name>]
629
+ greprag lore add "<one-sentence learning, optionally with a file path>" --scope <scope> [--project <name>]
644
630
  ```
645
631
 
646
632
  Examples:
647
633
  ```bash
648
- greprag fact add "Migrations live at repo root: migrations/<NNN>_<name>.sql. Apply with node scripts/apply-migration.cjs migrations/<file>.sql." --scope chip-startup
634
+ greprag lore add "Migrations live at repo root: migrations/<NNN>_<name>.sql. Apply with node scripts/apply-migration.cjs migrations/<file>.sql." --scope chip-startup
649
635
 
650
- greprag fact add "Inbox storage uses JSONB metadata on nodes (store kind='inbox'). No inbox_messages table — dropped in migration 035. See packages/core/src/inbox.ts." --scope inbox-touch
636
+ greprag lore add "Inbox storage uses JSONB metadata on nodes (store kind='inbox'). No inbox_messages table — dropped in migration 035. See packages/core/src/inbox.ts." --scope inbox-touch
651
637
 
652
- greprag fact add "Build everything from repo root: npm run build (Turborepo). Forced rebuild: npm run build -- --force." --scope general
638
+ greprag lore add "Build everything from repo root: npm run build (Turborepo). Forced rebuild: npm run build -- --force." --scope general
653
639
  ```
654
640
 
655
641
  **Scope naming.** Free-form strings — there is no enum. Check what's already in use before inventing a new label:
656
642
 
657
643
  ```bash
658
- greprag fact scopes [--project <name>]
644
+ greprag lore scopes [--project <name>]
659
645
  ```
660
646
 
661
647
  Conventional scopes:
662
648
  - `chip-startup` — what a freshly-spawned chip needs in its first 5 turns. Layout, build commands, test runners, key file paths.
663
649
  - `general` — applies to almost any session in this project.
664
- - `<subsystem>-touch` — facts that matter only when editing a specific subsystem (`inbox-touch`, `episodic-touch`, `enrichment-touch`).
650
+ - `<subsystem>-touch` — lore that matters only when editing a specific subsystem (`inbox-touch`, `episodic-touch`, `enrichment-touch`).
665
651
  - `env` — environment / credentials / DB connection gotchas.
666
652
 
667
- Pick the narrowest scope that still applies. A fact about migration paths is `chip-startup` (every chip needs it); a fact about how the hourly compactor's prompt versioning works is `episodic-touch` (only relevant if you're editing that subsystem).
653
+ Pick the narrowest scope that still applies. A lore entry about migration paths is `chip-startup` (every chip needs it); one about how the hourly compactor's prompt versioning works is `episodic-touch` (only relevant if you're editing that subsystem).
668
654
 
669
- ### Reading facts back (pull pattern)
655
+ ### Reading lore back (pull pattern)
670
656
 
671
657
  ```bash
672
- greprag fact query --scope chip-startup --limit 10 --format markdown # for inlining into a chip prompt
673
- greprag fact query --scope inbox-touch --query "session routing" # lexical-rank within a scope
674
- greprag fact query --query "how do migrations apply" --limit 5 # cross-scope, lexical-rank only
675
- greprag fact list # human-review every fact, grouped by scope
676
- greprag fact delete <nodeId> # prune stale fact (nodeId printed in list)
658
+ greprag lore query --scope chip-startup --limit 10 --format markdown # for inlining into a chip prompt
659
+ greprag lore query --scope inbox-touch --query "session routing" # lexical-rank within a scope
660
+ greprag lore query --query "how do migrations apply" --limit 5 # cross-scope, lexical-rank only
661
+ greprag lore list # human-review every entry, grouped by scope
662
+ greprag lore delete <nodeId> # prune stale entry (nodeId printed in list)
677
663
  ```
678
664
 
679
- `--format markdown` returns a numbered list with no decoration — drop it straight into a `**Project Facts**` block when spawning a chip.
665
+ `--format markdown` returns a numbered list with no decoration — drop it straight into a `**Project Lore**` block when spawning a chip.
680
666
 
681
- ### Deliberate review
667
+ ### Deliberate review (via /lore-advisor)
682
668
 
683
- Periodically run `greprag fact list` against a project, especially after a refactor or a major rename. Facts decay as code moves; prune anything stale via `greprag fact delete <nodeId>`. The substrate trusts the seeding agent — there's no auto-dedup or expiry, so the human (or a periodic `/greprag` audit pass) keeps the signal clean.
669
+ Lore decays as code moves paths change, conventions die, "learned that X" stops being true. Run `/lore-advisor` periodically (especially after a refactor or rename) to audit drift, mine episodic memory for newly-emerged learnings, and promote project-agnostic entries to global rules.
684
670
 
685
671
  ### Chip-spawn pull pattern
686
672
 
687
- When you compose a `spawn_task` chip prompt, pull `chip-startup` facts into the prompt before dispatching. Full convention lives in `~/.claude/docs/agent-coordination.md` § Block 0.5; the one-liner is: `greprag fact query --scope chip-startup --project <project> --limit 10 --format markdown`, then wrap the output in a `**Project Facts**` block at the top of the prompt. Skip the block when the output is empty.
673
+ When you compose a `spawn_task` chip prompt, pull `chip-startup` lore into the prompt before dispatching. Full convention lives in `~/.claude/docs/chip-spawn.md`; the one-liner is: `greprag lore query --scope chip-startup --project <project> --limit 10 --format markdown`, then wrap the output in a `**Project Lore**` block at the top of the prompt. Skip the block when the output is empty.
688
674
 
689
675
  ## Step 7 — Cross-project discovery (for advisor agents)
690
676
 
@@ -0,0 +1,183 @@
1
+ ---
2
+ name: lore-advisor
3
+ description: |
4
+ Audit project lore for drift, mine episodic memory for emergent learnings,
5
+ promote project-agnostic lore to global. One-at-a-time conversational
6
+ review — never bulk-prune.
7
+
8
+ Trigger phrases: "/lore-advisor", "/lore", "review my lore", "audit lore",
9
+ "lore is stale", "prune lore", "mine episodic for lore".
10
+ metadata:
11
+ author: travsteward
12
+ version: "1.0.0"
13
+ repository: https://github.com/travsteward/greprag
14
+ license: MIT
15
+ ---
16
+
17
+ # Lore Advisor
18
+
19
+ Project lore = LEARNINGS (emergent, drift-prone observations seeded via `greprag lore add`). Distinct from static project knowledge (CLAUDE.md, docs, code structure). Lore decays — paths change, conventions die, "learned that X" stops being true. This skill keeps the substrate healthy.
20
+
21
+ The skill is **conversational**, not autonomous. Every prune / promote / edit decision goes through the operator one at a time. Bulk actions are forbidden.
22
+
23
+ ## Trigger phrases
24
+
25
+ `/lore-advisor`, `/lore`, "review my lore", "audit lore", "lore is stale", "prune lore", "mine episodic for lore".
26
+
27
+ ## What it does
28
+
29
+ Three phases, run in order. Operator may skip any phase. Each phase walks one entry at a time — never bulk-prune.
30
+
31
+ - **Phase A — Drift check.** Heuristic scan of current lore for stale file paths, references to killed conventions, age-based decay.
32
+ - **Phase B — Episodic mining.** Scan recent daily summaries for sentences signalling new learnings; offer to promote to lore.
33
+ - **Phase C — Global promotion.** Identify project-agnostic lore that belongs in `~/.claude/docs/chip-spawn.md` as a universal rule.
34
+
35
+ ## Forbidden practices (HARD RULES)
36
+
37
+ - **Never delete lore without explicit operator confirmation.** Each delete is its own y/n.
38
+ - **Never edit `~/.claude/docs/chip-spawn.md` without explicit operator confirmation.** Global rules are sticky.
39
+ - **Never bulk-prune.** Walk one at a time. If the operator says "just prune all the obvious ones," confirm the list aloud first ("I'd delete: A, B, C — confirm?") before any action.
40
+ - **Never modify lore from a different project.** The skill only operates on the current project (resolved via `greprag lore list`).
41
+
42
+ ## Phases
43
+
44
+ ### Phase A — Drift check
45
+
46
+ 1. Pull the current project's lore as JSON:
47
+ ```bash
48
+ greprag lore list --format json
49
+ ```
50
+ Parse `lore[]`. Each entry has `nodeId`, `text`, `scope`, `createdAt`.
51
+
52
+ 2. For each entry, run three heuristic checks:
53
+
54
+ - **File-path check.** Extract any path matching `packages/<...>/<file.ext>`, `~/.claude/<...>`, `adr/<...>`, `docs/<...>`, `migrations/<...>`, `scripts/<...>`, `tests/<...>`. For each, verify the file exists relative to the project root:
55
+ ```bash
56
+ test -f <path> && echo OK || echo MISSING
57
+ ```
58
+ If MISSING → flag with `reason: "file-not-found:<path>"`.
59
+
60
+ - **Killed-convention check.** Match the lore text against this drift list:
61
+ - `Block 3` / `Block-3` (the old 3-block chip protocol)
62
+ - `<email>/<project>/<session-id>` or `/<email>/<project>/<session>` (legacy 3-segment address grammar — replaced by 1-segment in v0.11)
63
+ - `spawn-reminder` (PostToolUse hook removed in v0.12)
64
+ - `cp $main_root/.env` or `cp .env` from main into worktree (replaced by inline `set -a; source`)
65
+ - `agent-coordination.md` (deep doc deleted in v5.6.0; replaced by `chip-spawn.md`)
66
+ - `inline-conventions` / `greprag-conventions:start v1`, `v2`, `v3`, `v4` (superseded by v5 pointer)
67
+ - `MEMORY_HOOK_ENABLED` legacy boolean (now ambient)
68
+ - `greprag fact` (renamed to `greprag lore` in v5.7.0 — the alias is removed in v5.8.0)
69
+
70
+ Any match → flag with `reason: "dead-convention:<which>"`.
71
+
72
+ - **Age check.** If `createdAt` is older than 90 days from today AND no other heuristic fired, flag with `reason: "age-90d:<days>"`. Not automatically stale — just worth re-verifying.
73
+
74
+ 3. Surface each flagged entry one at a time. Format:
75
+ ```
76
+ [<nodeId>] scope=<scope> reason=<reason>
77
+ Text: <text>
78
+ Action? (k)eep / (e)dit / (d)elete / (s)kip
79
+ ```
80
+ - **keep** → no-op, move to next entry.
81
+ - **edit** → ask for the new text, then:
82
+ ```bash
83
+ greprag lore delete <nodeId>
84
+ greprag lore add "<new-text>" --scope <scope>
85
+ ```
86
+ - **delete** → `greprag lore delete <nodeId>`. Confirm by printing `Deleted [<nodeId>].`
87
+ - **skip** → no-op, move to next entry.
88
+
89
+ 4. Phase summary: `Phase A: reviewed N. Kept K. Edited E. Deleted D. Skipped S.`
90
+
91
+ ### Phase B — Episodic mining
92
+
93
+ 1. Resolve the current project's `projectId`:
94
+ ```bash
95
+ greprag project-id
96
+ ```
97
+
98
+ 2. Pull the last 30 days of daily summaries:
99
+ ```bash
100
+ FROM=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
101
+ TO=$(date -u +%Y-%m-%dT%H:%M:%SZ)
102
+ curl -sf "https://api.greprag.com/v1/memory/by-period?projectId=<projectId>&type=daily&from=$FROM&to=$TO&limit=30" \
103
+ -H "Authorization: Bearer $GREPRAG_API_KEY"
104
+ ```
105
+ Parse `rows[]`. Each row has `created_at`, `body`.
106
+
107
+ 3. For each daily summary, scan the body for sentences containing any of these marker phrases (case-insensitive):
108
+ - `learned that`
109
+ - `the gotcha is`
110
+ - `won't work because`
111
+ - `had to`
112
+ - `discovered that`
113
+ - `turns out`
114
+ - `surprised that`
115
+
116
+ Extract the full sentence containing the marker (sentence boundary = `. ` / `! ` / `? ` or newline). Skip sentences shorter than 30 chars or longer than 300 chars.
117
+
118
+ 4. Present candidates one at a time:
119
+ ```
120
+ Daily summary from <YYYY-MM-DD> contains:
121
+ "<sentence>"
122
+ Promote to lore? (k)eep / (e)dit / (s)kip
123
+ ```
124
+ - **keep** → ask for the scope (suggest `chip-startup` if the sentence mentions paths/build/test; `general` otherwise; `env` if it mentions env vars / credentials). Then:
125
+ ```bash
126
+ greprag lore add "<sentence>" --scope <scope>
127
+ ```
128
+ - **edit** → ask for the polished text, then add with chosen scope.
129
+ - **skip** → no-op.
130
+
131
+ 5. Phase summary: `Phase B: scanned N daily summaries, found M candidates. Added A to lore. Skipped S.`
132
+
133
+ ### Phase C — Global promotion
134
+
135
+ 1. Re-pull current lore (`greprag lore list --format json`).
136
+
137
+ 2. For each entry, classify as **project-specific** or **project-agnostic** by these heuristics:
138
+ - **Project-specific** (skip): mentions a project-specific path (`packages/`, `migrations/`, `adr/`, project-specific module names), a project-specific table/column, an internal service name.
139
+ - **Project-agnostic** (candidate): mentions only universal concepts — `worktree`, `npm`, `git`, `node_modules`, `Claude Code`, `hook`, `~/.claude/`, `npm link`, `npm publish`, env var names that are obviously generic (`PATH`, `HOME`, `NODE_ENV`).
140
+
141
+ 3. For each agnostic candidate, before showing it, verify `~/.claude/docs/chip-spawn.md` and `packages/cli/skill/templates/chip-spawn.md` (in the current repo if it's the `greprag` repo, otherwise fetch from `npm show greprag` or skip) are in sync:
142
+ ```bash
143
+ diff ~/.claude/docs/chip-spawn.md <(npm exec --package=greprag -- cat ../skill/templates/chip-spawn.md 2>/dev/null || echo MISSING)
144
+ ```
145
+ If they DIFFER, stop Phase C and tell the operator:
146
+ > `chip-spawn.md drift detected between ~/.claude/docs/chip-spawn.md and the template. Resolve manually before promoting any lore.`
147
+
148
+ 4. Present each candidate:
149
+ ```
150
+ [<nodeId>] This lore mentions only universal concepts:
151
+ "<text>"
152
+ Promote to ~/.claude/docs/chip-spawn.md as a global rule? (y)es / (n)o / (e)dit
153
+ ```
154
+ - **yes** →
155
+ 1. Append to BOTH `~/.claude/docs/chip-spawn.md` AND (when in the greprag repo) `packages/cli/skill/templates/chip-spawn.md`. The append goes under the numbered "Every chip prompt:" list as the next item, preserving HARD-RULE styling when appropriate.
156
+ 2. Delete the per-project entry: `greprag lore delete <nodeId>`.
157
+ 3. Confirm: `Promoted [<nodeId>] → global chip-spawn rule.`
158
+ - **edit** → ask for polished text, then yes-path with the new text.
159
+ - **no** → no-op, move to next entry.
160
+
161
+ 5. Phase summary: `Phase C: evaluated N. Promoted P to global. Skipped S.`
162
+
163
+ ## Report
164
+
165
+ After all three phases, print one combined line:
166
+
167
+ ```
168
+ Reviewed N lore. Pruned X. Edited Y. Added Z from episodic. Promoted W to global.
169
+ ```
170
+
171
+ If any phase was skipped (operator pressed q / Ctrl-C / typed "skip phase"), include `(phase <X> skipped)` per skipped phase.
172
+
173
+ ## When this skill should be invoked
174
+
175
+ - Operator types `/lore-advisor` or `/lore`.
176
+ - Operator says "audit my lore," "lore is stale," "prune lore," "mine episodic for lore," "any new learnings worth saving?"
177
+ - Proactively offer the skill at the end of a `/greprag` briefing if `greprag lore list` shows entries older than 90 days OR if the operator just finished a refactor / rename and lore drift is likely.
178
+
179
+ ## Notes
180
+
181
+ - This skill is operator-driven. Each phase pauses for input. Don't batch decisions — that defeats the purpose.
182
+ - For new lore added in Phase B, prefer the original sentence verbatim unless it's awkward. The compactor already polished it.
183
+ - For Phase C promotions, prefer the original phrasing too — but rewrite if the lore embeds a project-specific noun that needs generalizing.
@@ -0,0 +1,15 @@
1
+ # Chip Spawn Method
2
+
3
+ Chips are scoped: ship-code root-cause fix, or design discussion. Same blocks either way. Add `mode: interactive` to the prompt body when the chip should pause for human reply in the chip UI; default is autonomous.
4
+
5
+ **Before composing**: `greprag lore query --scope chip-startup --project <chip-project> --limit 10 --format markdown` — if non-empty, paste at the top of the prompt as `**Project Lore (do not re-discover):**`. Saves the chip 10-20 startup turns of layout rediscovery.
6
+
7
+ **Every chip prompt:**
8
+
9
+ 1. **Title** `Chip: <verb-phrase>`. Distinguishes chip-spawned sessions from IDE/human sessions in FleetView.
10
+ 2. **Worktree**: `git worktree add .claude/worktrees/<slug> -b chip/<slug>` then `cd` in.
11
+ 3. **Report**: `greprag send "<status>: <commit> on chip/<slug>" --to <handle>@greprag.com/<parent-session-id> --from-session <own-session-id> --artifact commit:<hash>` — substitute `<parent-session-id>` from your SessionStart hook ("Your greprag session id: `<8-hex>`").
12
+ 4. **Cleanup discipline (HARD RULE)**: chip prompts forbid `git clean`, `git reset --hard`, `git worktree remove`, `git checkout <other>`, raw `rm -rf` outside worktree's tracked files. Use `git rm` for tracked deletions.
13
+ 5. **Merge before testing globally (HARD RULE)**: chips never `npm link` from the worktree. A worktree-rooted global symlink dangles after `git worktree remove`, silently breaks the CLI everywhere, and chains destruction into shared `node_modules` (the 2026-05-25 wipe). To test a built CLI globally: merge to main first via `/commit`, then `npm i -g <pkg>` from main.
14
+
15
+ A `greprag-hook pre-spawn-check` PreToolUse validator enforces title prefix + Block 1/2 presence at the `spawn_task` boundary — rule violations return `permissionDecision: deny` with a remediation message before the call goes through.