greprag 5.6.2 → 5.8.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.
- package/dist/commands/lore.d.ts +28 -0
- package/dist/commands/lore.js +357 -0
- package/dist/commands/lore.js.map +1 -0
- package/dist/hook.d.ts +17 -1
- package/dist/hook.js +151 -17
- package/dist/hook.js.map +1 -1
- package/dist/index.js +19 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skill/greprag/SKILL.md +19 -19
- package/skill/lore-advisor/SKILL.md +183 -0
- package/skill/templates/chip-spawn.md +16 -8
|
@@ -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.
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
# Chip Spawn Method
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hook-augmented spawn: the agent writes the minimal chip, the `pre-spawn-check` PreToolUse hook fills in the rest.
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Agent writes:**
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
1. **Title** `Chip: <verb-phrase>` (e.g. `Chip: Fix synthesis loop`). The `Chip: ` prefix is enforced.
|
|
8
|
+
2. **Task body** — what the chip should do. Optional first line `mode: interactive` pauses for human reply in the chip UI; default is autonomous.
|
|
9
|
+
3. **Optional** `cwd:` argument to land the chip in a different project root.
|
|
8
10
|
|
|
9
|
-
|
|
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.
|
|
11
|
+
**Hook auto-injects** (when the body contains neither `git worktree add` nor `greprag send` — "new-style"):
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
- **Block 1** — escape-to-root (`main_root=$(git rev-parse --git-common-dir | xargs dirname)`) + `git worktree add .claude/worktrees/<slug>` + `cd` in. Slug derives from the title.
|
|
14
|
+
- **Block 2** — `greprag send` report-back template with `<handle>` and `<parent-session-id>` substituted from the local identity cache and the parent's `session_id`. Cleanup discipline (no `git clean`, `git reset --hard`, `git worktree remove`, `git checkout <other>`, raw `rm -rf`) appended as a HARD RULE.
|
|
15
|
+
|
|
16
|
+
**Pass-through:** if the prompt already includes `git worktree add` or `greprag send`, the hook leaves it alone — back-compat for hand-crafted prompts that want full control. Tier 1 placeholder substitution (`<parent-session-id>`, `<handle>`) still applies.
|
|
17
|
+
|
|
18
|
+
**Before composing**: `greprag lore query --scope chip-startup --project <chip-project> --limit 10 --format markdown` — if non-empty, paste at the top of the task body as `**Project Lore (do not re-discover):**`. Saves 10-20 startup turns.
|
|
19
|
+
|
|
20
|
+
**Example.** Agent calls `spawn_task` with `title: "Chip: Fix synthesis loop"` and `prompt: "Investigate src/foo.ts, fix the loop, ship it."`. The hook rewrites the prompt to: Block 1 (worktree setup with slug `fix-synthesis-loop`) → agent's body → Block 2 (greprag send with `travis@greprag.com/<parent-8hex>` substituted) + cleanup discipline.
|
|
21
|
+
|
|
22
|
+
**Merge before testing globally (HARD RULE):** chips never `npm link` from the worktree. Worktree-rooted global symlinks dangle after `git worktree remove`, silently break the CLI everywhere, and chained the 2026-05-25 wipe. To test a built CLI globally: merge to main first via `/commit`, then `npm i -g <pkg>` from main.
|