codealmanac 0.1.1 → 0.1.3

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/guides/mini.md ADDED
@@ -0,0 +1,223 @@
1
+ # codealmanac — a wiki for this codebase, maintained for you
2
+
3
+ This repo has a `.almanac/` directory. It's a **living wiki** written for AI agents, documenting the things the code can't say: **why** it's shaped this way, **what was tried and failed**, **what must not be violated**, **how things flow end-to-end**, and **known gotchas** discovered through real debugging.
4
+
5
+ You are the primary reader. When the user asks you to do something, **check the wiki before you touch related code** — it will often answer the question the user didn't think to ask ("we tried that in March, here's why it broke").
6
+
7
+ You don't write the wiki during normal work. A separate agent ("capture") runs automatically at session end via a Claude Code hook, reads the session transcript, and writes or updates pages. Your job during the session is: **read, use, occasionally fix obvious errors.**
8
+
9
+ ---
10
+
11
+ ## The mental model in 60 seconds
12
+
13
+ - **Pages** are markdown files in `.almanac/pages/` with YAML frontmatter. One page per stable concept: a technology we depend on (`supabase`), a multi-file flow (`checkout-flow`), a decision (`jwt-vs-sessions`), a gotcha (`stripe-webhook-deadlock`).
14
+ - **Topics** organize pages. They form a **DAG** — each page has multiple topics, each topic can have multiple parents. Topics live in `.almanac/topics.yaml`.
15
+ - **Links** use one syntax: `[[...]]`. The classifier looks at content:
16
+ - `[[checkout-flow]]` → page slug (no slash)
17
+ - `[[src/checkout/handler.ts]]` → file reference (has slash)
18
+ - `[[src/checkout/]]` → folder reference (trailing slash)
19
+ - `[[openalmanac:supabase]]` → cross-wiki reference (colon prefix)
20
+ - **Frontmatter carries `topics:` and `files:`.** The `files:` list is load-bearing: it's how `almanac search --mentions src/foo.ts` finds pages about `src/foo.ts` even when the path isn't in the prose.
21
+ - **The wiki evolves.** When facts change, existing pages get edited in place — git history is the archive. Fundamental reversals use a separate "archive" mechanism; you rarely need to worry about it.
22
+
23
+ Read `.almanac/README.md` at the start of any session where the wiki is likely to be relevant. It carries this repo's **notability bar** (what deserves a page here) and topic taxonomy.
24
+
25
+ ---
26
+
27
+ ## When to reach for it
28
+
29
+ **At the start of a task that touches real subsystems**, before you do anything else:
30
+
31
+ ```bash
32
+ almanac search --mentions src/checkout/handler.ts
33
+ almanac search --mentions src/checkout/
34
+ almanac search "checkout timeout"
35
+ almanac search --topic checkout
36
+ ```
37
+
38
+ The output is page slugs. Pick 1-3 that look relevant, `almanac show <slug>`, follow `[[wikilinks]]` the way you'd follow imports. Do this *before* grepping the codebase for unfamiliar behavior — the wiki tells you *why*, the code tells you *what*.
39
+
40
+ **Skip the wiki when**: the task is a pure typo fix, styling tweak, scoped refactor inside one file you already understand, or anything where the user's request is literally "read this file and tell me X."
41
+
42
+ **Trust the code over the wiki when they disagree.** Code is truth. If the wiki is wrong, fix the wiki — but don't propagate the wiki's error into code.
43
+
44
+ ---
45
+
46
+ ## The commands you'll use
47
+
48
+ Other commands exist (`list`, `tag`, `untag`, `hook`, `uninstall`, `doctor`, etc.) — most are administrative. See `almanac --help` or `@~/.claude/codealmanac-reference.md` for the full surface. In normal sessions you'll live in the four commands below.
49
+
50
+ ### 1. `almanac search` — the starting point
51
+
52
+ ```bash
53
+ almanac search "<query>" # FTS
54
+ almanac search --mentions src/path/to/file.ts # pages referencing this file
55
+ almanac search --mentions src/path/to/folder/ # pages referencing anything in this folder
56
+ almanac search --topic auth # active pages in a topic
57
+ almanac search --topic auth --topic decisions # intersection
58
+ ```
59
+
60
+ Useful when you need them:
61
+ - `--since 2w` / `--stale 30d` — freshness filters
62
+ - `--orphan` — pages with no topics (usually a bug to fix)
63
+ - `--include-archive` — include historical pages when active wiki feels sparse
64
+ - `--limit N`, `--json` — output control
65
+
66
+ Returns slugs, one per line. Pipe-friendly. Filters AND-intersect.
67
+
68
+ ### 2. `almanac show <slug>` — read a page
69
+
70
+ ```bash
71
+ almanac show checkout-flow # metadata header + body (default)
72
+ almanac show checkout-flow --raw # body only
73
+ almanac show checkout-flow --meta # metadata only
74
+ almanac show checkout-flow --lead # first paragraph (cheap preview)
75
+ almanac show checkout-flow --backlinks # pages linking TO this one
76
+ almanac show checkout-flow --links # pages this links out to
77
+ ```
78
+
79
+ `--lead` to triage long result lists. `--backlinks` before editing a load-bearing page — you want to know who depends on its current shape.
80
+
81
+ ### 3. `almanac topics` — understand structure
82
+
83
+ ```bash
84
+ almanac topics # list all with page counts
85
+ almanac topics show auth # description, parents, children, pages
86
+ almanac topics show auth --descendants # walks the DAG subtree
87
+ ```
88
+
89
+ `--descendants` is the right call for "everything tagged auth or under it" — subtopics like `jwt`, `sessions`, `oauth` get walked automatically.
90
+
91
+ ### 4. Read the file directly
92
+
93
+ `.almanac/pages/<slug>.md` is just markdown. The Read tool works fine. The CLI is faster when you want composed metadata; Read is fine for scanning prose or editing.
94
+
95
+ ### 5. `almanac health` — when something feels off
96
+
97
+ ```bash
98
+ almanac health # 8-category graph integrity report
99
+ almanac health --topic auth # scope
100
+ ```
101
+
102
+ Run when cleaning up the wiki, when the user reports broken links, or after you deleted/moved code and want to know which pages now reference dead files.
103
+
104
+ Categories: `orphans`, `stale` (90+ days), `dead-refs`, `broken-links`, `broken-xwiki`, `empty-topics`, `empty-pages`, `slug-collisions`.
105
+
106
+ ---
107
+
108
+ ## Decisions you'll face
109
+
110
+ ### "Search the wiki or just grep?"
111
+ Search when the task is named: subsystem (checkout, auth, search), external service (Stripe, Supabase), cross-cutting concern (caching, sessions). Grep for mechanical tasks.
112
+
113
+ ### "The wiki says X. The code does Y. Which is right?"
114
+ The code. Then fix the wiki — small fixes edit the page directly. Substantial changes: mention clearly in your response so capture has context to update at session end.
115
+
116
+ ### "Should I create a new page mid-session?"
117
+ Usually no. Capture writes pages from the session transcript with full context. Exceptions: user explicitly asks, or you're doing deliberate wiki maintenance.
118
+
119
+ When you do write: read `.almanac/README.md` for the notability bar, use `[[...]]` syntax, include `files:` frontmatter, keep every sentence factual, no speculation.
120
+
121
+ ### "New topic or existing?"
122
+ Almost always existing. Skim `almanac topics` before creating. New topic is justified when multiple pages share a concept no current topic captures.
123
+
124
+ ### "Can I just `almanac tag`?"
125
+ Yes — safe, idempotent, preserves body bytes. Use `almanac tag` / `untag` rather than hand-editing frontmatter.
126
+
127
+ ### "The wiki returned nothing. Now what?"
128
+ Trust the silence. Empty stdout with `# 0 results` on stderr means the query ran cleanly and matched nothing — the wiki doesn't have a page on that yet, or the query needs to be broader. That is the answer, not a bug. Don't fall back to guessing; fall back to the code, and trust that capture will surface the knowledge the next time a session naturally discovers it.
129
+
130
+ If stderr shows a real error (an `almanac:` prefix or a commander parse failure), the invocation is broken — re-read `almanac --help` for the right flags.
131
+
132
+ ---
133
+
134
+ ## A concrete example
135
+
136
+ User: *"the indexer isn't picking up my new page, what's going on?"*
137
+
138
+ ```bash
139
+ # 1. Find pages touching the indexer
140
+ $ almanac search --mentions src/indexer/
141
+ sqlite-indexer
142
+ wikilink-syntax
143
+
144
+ # 2. Triage with --lead
145
+ $ almanac show sqlite-indexer --lead
146
+ The indexer (`src/indexer/`) builds and maintains `.almanac/index.db` — a
147
+ SQLite database that powers all query commands (`search`, `info`, `health`,
148
+ `topics show`). It runs silently before every query command, comparing page
149
+ file mtimes against the stored `content_hash`; only changed or new pages are
150
+ re-parsed.
151
+
152
+ # 3. Read the most relevant
153
+ $ almanac show sqlite-indexer
154
+ # ...covers the schema, freshness rules, and where new pages get picked up
155
+
156
+ # 4. Before you touch anything, check backlinks
157
+ $ almanac show sqlite-indexer --backlinks
158
+ ```
159
+
160
+ You now know: the indexer only re-parses pages whose mtime is newer than the stored `content_hash`, runs on every query command, and backing it is a schema you can read at `src/indexer/schema.ts`. The lead alone ruled out two entire hypotheses ("maybe it only indexes on startup", "maybe I need to restart something") before you read any source code.
161
+
162
+ You don't write anything. At session end the capture agent reads the transcript, sees your discovery, writes or updates pages. Next session, a different agent running a related task sees it surface in `--mentions`.
163
+
164
+ ---
165
+
166
+ ## What runs automatically (don't invoke these)
167
+
168
+ - **`almanac capture`** — runs in the background after every Claude Code session via the `SessionEnd` hook.
169
+ - **`almanac reindex`** — runs implicitly before every query when pages changed.
170
+ - **`almanac bootstrap`** — one-shot scaffolding. You almost certainly don't run this.
171
+
172
+ ---
173
+
174
+ ## Cross-wiki references
175
+
176
+ If the user has multiple repos with `.almanac/`, they're globally registered. Pages can reference other wikis with `[[wiki-name:slug]]`. `--wiki <name>` or `--all` span registered wikis. You rarely need this mid-session.
177
+
178
+ ---
179
+
180
+ ## Writing conventions (if you do write)
181
+
182
+ - **Every sentence contains a specific fact.** If the sentence could describe any codebase, cut it.
183
+ - **Neutral tone.** "is", not "serves as". No promotional language, no "plays a pivotal role", no interpretive "-ing" clauses.
184
+ - **No speculation.** If you don't know why, don't guess in prose.
185
+ - **Prose first.** Bullets for genuine lists. Tables for structured comparison only.
186
+ - **Reference code with `[[...]]`.** Inline mentions are fine but only `[[...]]` gets indexed.
187
+ - **List files in frontmatter.** Pages about specific code need `files: [...]` to surface in `--mentions` queries.
188
+
189
+ The reviewer subagent (run by capture at session end) enforces these. Stricter with yourself = less rework.
190
+
191
+ ---
192
+
193
+ ## Troubleshooting
194
+
195
+ ### `almanac doctor` is the catchall
196
+ When anything feels off and you don't know where to start, run `almanac doctor`. It reports the install (binary, native SQLite binding, Claude auth, hook, guides, CLAUDE.md import) and the current wiki (registered, page/topic counts, index freshness, last capture age, health problems). Every ✗ comes with a one-line `run: …` fix. Add `--json` for scripting.
197
+
198
+ ### "better-sqlite3 bindings failed"
199
+ Node version or arch mismatch with the prebuilt native binding. `almanac doctor` reports this under `install.sqlite` with the raw error. Fix by rebuilding the native binding:
200
+ ```bash
201
+ npm rebuild better-sqlite3 # in the install directory
202
+ ```
203
+
204
+ ### "search returned nothing"
205
+ Empty stdout plus `# 0 results` on stderr means the query ran and genuinely matched nothing. Don't retry with random flag permutations — either broaden the query, or accept the wiki hasn't covered that area yet. A real error would have come with an `almanac:`-prefixed stderr line.
206
+
207
+ `--json` is silent on stderr — the `[]` array is the empty signal there.
208
+
209
+ ### "capture didn't fire after my last session"
210
+ ```bash
211
+ almanac doctor # install.hook: ok/problem, wiki.capture: last capture age
212
+ almanac hook status # just the hook entry
213
+ ls -lah .almanac/.capture-*.log
214
+ ```
215
+ No logs at all → the hook isn't installed, or bailed before backgrounding, or `cwd` was outside any wiki (silent correct no-op). Capture ran but wrote nothing → the reviewer rejected the draft for notability, or the session was pure-read. Check the `.capture-<id>.log` for the writer/reviewer transcript.
216
+
217
+ ---
218
+
219
+ ## When in doubt
220
+
221
+ - `.almanac/README.md` — repo-specific conventions + notability bar
222
+ - `@~/.claude/codealmanac-reference.md` — full command reference with every flag
223
+ - `almanac --help`, `almanac <command> --help` — built-in