@warlock.js/grimoire 0.0.0-stage → 5.55.0
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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/esm/apps/check-apps.mjs +207 -0
- package/esm/apps/check-apps.mjs.map +1 -0
- package/esm/apps/index.mjs +4 -0
- package/esm/apps/match-apps.d.mts +12 -0
- package/esm/apps/match-apps.d.mts.map +1 -0
- package/esm/apps/match-apps.mjs +30 -0
- package/esm/apps/match-apps.mjs.map +1 -0
- package/esm/book/build.d.mts +14 -0
- package/esm/book/build.d.mts.map +1 -0
- package/esm/book/build.mjs +300 -0
- package/esm/book/build.mjs.map +1 -0
- package/esm/book/index.mjs +5 -0
- package/esm/book/io.mjs +162 -0
- package/esm/book/io.mjs.map +1 -0
- package/esm/book/normalize.mjs +71 -0
- package/esm/book/normalize.mjs.map +1 -0
- package/esm/book/render.mjs +262 -0
- package/esm/book/render.mjs.map +1 -0
- package/esm/book/write.d.mts +12 -0
- package/esm/book/write.d.mts.map +1 -0
- package/esm/book/write.mjs +90 -0
- package/esm/book/write.mjs.map +1 -0
- package/esm/bookmap/build.d.mts +21 -0
- package/esm/bookmap/build.d.mts.map +1 -0
- package/esm/bookmap/build.mjs +272 -0
- package/esm/bookmap/build.mjs.map +1 -0
- package/esm/bookmap/index.mjs +5 -0
- package/esm/bookmap/steps.mjs +137 -0
- package/esm/bookmap/steps.mjs.map +1 -0
- package/esm/bookmap/write.d.mts +19 -0
- package/esm/bookmap/write.d.mts.map +1 -0
- package/esm/bookmap/write.mjs +118 -0
- package/esm/bookmap/write.mjs.map +1 -0
- package/esm/check/check-grimoire.d.mts +7 -0
- package/esm/check/check-grimoire.d.mts.map +1 -0
- package/esm/check/check-grimoire.mjs +98 -0
- package/esm/check/check-grimoire.mjs.map +1 -0
- package/esm/check/format-check-report.d.mts +20 -0
- package/esm/check/format-check-report.d.mts.map +1 -0
- package/esm/check/format-check-report.mjs +55 -0
- package/esm/check/format-check-report.mjs.map +1 -0
- package/esm/check/index.mjs +4 -0
- package/esm/check/rules/book-notes.mjs +18 -0
- package/esm/check/rules/book-notes.mjs.map +1 -0
- package/esm/check/rules/criteria.mjs +48 -0
- package/esm/check/rules/criteria.mjs.map +1 -0
- package/esm/check/rules/links.mjs +196 -0
- package/esm/check/rules/links.mjs.map +1 -0
- package/esm/check/rules/lookup.mjs +41 -0
- package/esm/check/rules/lookup.mjs.map +1 -0
- package/esm/check/rules/source-files.mjs +119 -0
- package/esm/check/rules/source-files.mjs.map +1 -0
- package/esm/check/rules/versions.mjs +92 -0
- package/esm/check/rules/versions.mjs.map +1 -0
- package/esm/codes/codes.d.mts +182 -0
- package/esm/codes/codes.d.mts.map +1 -0
- package/esm/codes/codes.mjs +111 -0
- package/esm/codes/codes.mjs.map +1 -0
- package/esm/codes/index.d.mts +33 -0
- package/esm/codes/index.d.mts.map +1 -0
- package/esm/codes/index.mjs +63 -0
- package/esm/codes/index.mjs.map +1 -0
- package/esm/contracts/adapter.d.mts +209 -0
- package/esm/contracts/adapter.d.mts.map +1 -0
- package/esm/contracts/book.d.mts +233 -0
- package/esm/contracts/book.d.mts.map +1 -0
- package/esm/contracts/book.mjs +7 -0
- package/esm/contracts/book.mjs.map +1 -0
- package/esm/contracts/bookmap.d.mts +175 -0
- package/esm/contracts/bookmap.d.mts.map +1 -0
- package/esm/contracts/findings.d.mts +79 -0
- package/esm/contracts/findings.d.mts.map +1 -0
- package/esm/contracts/location.d.mts +22 -0
- package/esm/contracts/location.d.mts.map +1 -0
- package/esm/contracts/releases.d.mts +53 -0
- package/esm/contracts/releases.d.mts.map +1 -0
- package/esm/contracts/scry.d.mts +143 -0
- package/esm/contracts/scry.d.mts.map +1 -0
- package/esm/contracts/snapshot.d.mts +52 -0
- package/esm/contracts/snapshot.d.mts.map +1 -0
- package/esm/contracts/test-results.d.mts +63 -0
- package/esm/contracts/test-results.d.mts.map +1 -0
- package/esm/contracts/written.d.mts +363 -0
- package/esm/contracts/written.d.mts.map +1 -0
- package/esm/contracts/written.mjs +19 -0
- package/esm/contracts/written.mjs.map +1 -0
- package/esm/devtools/data.mjs +171 -0
- package/esm/devtools/data.mjs.map +1 -0
- package/esm/devtools/graphs.mjs +142 -0
- package/esm/devtools/graphs.mjs.map +1 -0
- package/esm/devtools/index.d.mts +35 -0
- package/esm/devtools/index.d.mts.map +1 -0
- package/esm/devtools/index.mjs +102 -0
- package/esm/devtools/index.mjs.map +1 -0
- package/esm/devtools/site.d.mts +26 -0
- package/esm/devtools/site.d.mts.map +1 -0
- package/esm/devtools/site.mjs +190 -0
- package/esm/devtools/site.mjs.map +1 -0
- package/esm/devtools/snapshot-source.mjs +70 -0
- package/esm/devtools/snapshot-source.mjs.map +1 -0
- package/esm/front-matter/index.d.mts +33 -0
- package/esm/front-matter/index.d.mts.map +1 -0
- package/esm/front-matter/index.mjs +130 -0
- package/esm/front-matter/index.mjs.map +1 -0
- package/esm/graph/index.d.mts +15 -0
- package/esm/graph/index.d.mts.map +1 -0
- package/esm/graph/index.mjs +42 -0
- package/esm/graph/index.mjs.map +1 -0
- package/esm/index.d.mts +33 -0
- package/esm/index.mjs +33 -0
- package/esm/ownership/index.d.mts +8 -0
- package/esm/ownership/index.d.mts.map +1 -0
- package/esm/ownership/index.mjs +137 -0
- package/esm/ownership/index.mjs.map +1 -0
- package/esm/paths/index.d.mts +58 -0
- package/esm/paths/index.d.mts.map +1 -0
- package/esm/paths/index.mjs +137 -0
- package/esm/paths/index.mjs.map +1 -0
- package/esm/proves/index.mjs +3 -0
- package/esm/proves/scan-proofs.d.mts +22 -0
- package/esm/proves/scan-proofs.d.mts.map +1 -0
- package/esm/proves/scan-proofs.mjs +214 -0
- package/esm/proves/scan-proofs.mjs.map +1 -0
- package/esm/releases/index.d.mts +29 -0
- package/esm/releases/index.d.mts.map +1 -0
- package/esm/releases/index.mjs +157 -0
- package/esm/releases/index.mjs.map +1 -0
- package/esm/scry/format.d.mts +14 -0
- package/esm/scry/format.d.mts.map +1 -0
- package/esm/scry/format.mjs +193 -0
- package/esm/scry/format.mjs.map +1 -0
- package/esm/scry/index.mjs +5 -0
- package/esm/scry/parse.d.mts +10 -0
- package/esm/scry/parse.d.mts.map +1 -0
- package/esm/scry/parse.mjs +108 -0
- package/esm/scry/parse.mjs.map +1 -0
- package/esm/scry/query.d.mts +11 -0
- package/esm/scry/query.d.mts.map +1 -0
- package/esm/scry/query.mjs +457 -0
- package/esm/scry/query.mjs.map +1 -0
- package/esm/tasks/index.mjs +116 -0
- package/esm/tasks/index.mjs.map +1 -0
- package/esm/test-results/criterion-status.d.mts +15 -0
- package/esm/test-results/criterion-status.d.mts.map +1 -0
- package/esm/test-results/criterion-status.mjs +17 -0
- package/esm/test-results/criterion-status.mjs.map +1 -0
- package/esm/test-results/index.d.mts +8 -0
- package/esm/test-results/index.d.mts.map +1 -0
- package/esm/test-results/index.mjs +124 -0
- package/esm/test-results/index.mjs.map +1 -0
- package/esm/vitest/index.d.mts +15 -0
- package/esm/vitest/index.d.mts.map +1 -0
- package/esm/vitest/index.mjs +146 -0
- package/esm/vitest/index.mjs.map +1 -0
- package/esm/warlock/actions.mjs +265 -0
- package/esm/warlock/actions.mjs.map +1 -0
- package/esm/warlock/adapter.d.mts +28 -0
- package/esm/warlock/adapter.d.mts.map +1 -0
- package/esm/warlock/adapter.mjs +377 -0
- package/esm/warlock/adapter.mjs.map +1 -0
- package/esm/warlock/commands.d.mts +15 -0
- package/esm/warlock/commands.d.mts.map +1 -0
- package/esm/warlock/commands.mjs +199 -0
- package/esm/warlock/commands.mjs.map +1 -0
- package/esm/warlock/index.d.mts +4 -0
- package/esm/warlock/index.mjs +5 -0
- package/esm/warlock/mcp-tools.mjs +247 -0
- package/esm/warlock/mcp-tools.mjs.map +1 -0
- package/esm/warlock/mobile-facts.d.mts +32 -0
- package/esm/warlock/mobile-facts.d.mts.map +1 -0
- package/esm/warlock/mobile-facts.mjs +185 -0
- package/esm/warlock/mobile-facts.mjs.map +1 -0
- package/esm/workspace/index.d.mts +11 -0
- package/esm/workspace/index.d.mts.map +1 -0
- package/esm/workspace/index.mjs +122 -0
- package/esm/workspace/index.mjs.map +1 -0
- package/esm/written/apps.mjs +227 -0
- package/esm/written/apps.mjs.map +1 -0
- package/esm/written/features.mjs +400 -0
- package/esm/written/features.mjs.map +1 -0
- package/esm/written/fields.mjs +173 -0
- package/esm/written/fields.mjs.map +1 -0
- package/esm/written/index.mjs +3 -0
- package/esm/written/lists.mjs +68 -0
- package/esm/written/lists.mjs.map +1 -0
- package/esm/written/markdown.mjs +173 -0
- package/esm/written/markdown.mjs.map +1 -0
- package/esm/written/parse-grimoire.d.mts +20 -0
- package/esm/written/parse-grimoire.d.mts.map +1 -0
- package/esm/written/parse-grimoire.mjs +552 -0
- package/esm/written/parse-grimoire.mjs.map +1 -0
- package/esm/written/sink.mjs +65 -0
- package/esm/written/sink.mjs.map +1 -0
- package/esm/written/tasks-releases.mjs +166 -0
- package/esm/written/tasks-releases.mjs.map +1 -0
- package/llms-full.txt +869 -0
- package/llms.txt +15 -0
- package/package.json +66 -4
- package/skills/backfill-a-grimoire/SKILL.md +128 -0
- package/skills/describe-an-app/SKILL.md +162 -0
- package/skills/document-a-file/SKILL.md +75 -0
- package/skills/index.md +26 -0
- package/skills/record-a-change/SKILL.md +139 -0
- package/skills/use-the-grimoire/SKILL.md +137 -0
- package/skills/write-a-feature/SKILL.md +168 -0
- package/ui/grimoire-static.js +136 -0
- package/ui/grimoire-view.js +1005 -0
- package/ui/grimoire.css +88 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: use-the-grimoire
|
|
3
|
+
description: "Find the right files before changing a Warlock.js project by asking the Grimoire (experimental): `warlock scry` for a file, a route, a feature, a flow or the impact of a change, and the `grimoire/` folder for what the product does. Use at the start of every task, before searching the code."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Use the Grimoire
|
|
7
|
+
|
|
8
|
+
The Grimoire is experimental: its file structure and commands may still change.
|
|
9
|
+
|
|
10
|
+
`grimoire/` is the map of this project. Read it before you search the code: it tells you where
|
|
11
|
+
things are, what a feature is meant to do, and what a change will touch.
|
|
12
|
+
|
|
13
|
+
| Folder | Holds | Written by |
|
|
14
|
+
| -------------------- | ------------------------------------------------------- | ---------------------------------------------- |
|
|
15
|
+
| `grimoire/book/` | One entry per source file, plus routes and pages | Warlock (never edit) |
|
|
16
|
+
| `grimoire/features/` | What the product does: features, flows, cases, criteria | You and other agents |
|
|
17
|
+
| `grimoire/apps/` | Where users meet it: sites, mobile apps, pages, blocks | You and other agents |
|
|
18
|
+
| `grimoire/tasks/` | Open and finished work | You and other agents |
|
|
19
|
+
| `grimoire/releases/` | What each release shipped | You write the brief, Warlock collects the list |
|
|
20
|
+
|
|
21
|
+
Files named `index.json`, `bookmap.json` or ending in `.bookmap.json` are Warlock's. A feature's
|
|
22
|
+
`bookmap.json` says what the feature owns and borrows, and each flow's `*.bookmap.json` says which
|
|
23
|
+
files sit behind each step and which tests prove each criterion. They are rebuilt on demand and are
|
|
24
|
+
not in git. Never edit them; change the code or the written files and they follow. Warlock never
|
|
25
|
+
edits a file you wrote either.
|
|
26
|
+
|
|
27
|
+
## Start of every task
|
|
28
|
+
|
|
29
|
+
1. Find the feature and flow the task is about.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx warlock scry --search "new arrivals"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
flow catalog/new-arrivals New arrivals
|
|
37
|
+
block web-client/home/new-arrivals catalog/new-arrivals
|
|
38
|
+
route GET /api/products/new-arrivals
|
|
39
|
+
file src/app/catalog/services/new-arrivals.service.ts Lists the newest products sold in the customer's country.
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. Read the feature's `README.md`, then the flow file. They say what the behaviour should be.
|
|
43
|
+
3. Ask for the flow's book map. It lists the files behind each step, the tests that prove each
|
|
44
|
+
criterion and the pages that show the flow.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx warlock scry --flow catalog/new-arrivals
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
4. Read only those files. Do not read a whole module to find one function.
|
|
51
|
+
|
|
52
|
+
## Questions the book answers
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx warlock scry src/app/catalog/services/new-arrivals.service.ts # what is this file?
|
|
56
|
+
npx warlock scry --impact src/app/catalog/models/product.model.ts # what breaks if I change it?
|
|
57
|
+
npx warlock scry --route "POST /api/orders" # what is behind this URL?
|
|
58
|
+
npx warlock scry --feature catalog # the whole feature
|
|
59
|
+
npx warlock scry --flow catalog/new-arrivals # one flow, step by step
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Add `--json` for machine-readable output. `--impact` lists API routes, pages, flows and features,
|
|
63
|
+
including features that only borrow the file; each list has a count and stops at 20 lines, and `--all`
|
|
64
|
+
prints every line. `--search` ranks exact matches first. Read the flows it names and run their tests after
|
|
65
|
+
your change.
|
|
66
|
+
|
|
67
|
+
A file's entry is also at a fixed path: `src/app/auth/controllers/login.controller.ts` is described
|
|
68
|
+
in `grimoire/book/app/auth/controllers/login.controller.json`.
|
|
69
|
+
|
|
70
|
+
## Commands
|
|
71
|
+
|
|
72
|
+
| Command | Does |
|
|
73
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
74
|
+
| `warlock grimoire build` | Builds or refreshes the book. `scry` and `check` do it when it is stale |
|
|
75
|
+
| `warlock grimoire build --site [--out dir]` | Also writes the book as a static site (default `grimoire/book/site`) |
|
|
76
|
+
| `warlock grimoire check` | Reports broken names, untested criteria, files with no owner. Exit 1 on an error; `--all` lists every warning |
|
|
77
|
+
| `warlock grimoire release <release>` | Writes the collected list into `grimoire/releases/<release>.md` |
|
|
78
|
+
| `warlock explain GR2001` | Explains a finding code |
|
|
79
|
+
|
|
80
|
+
Every finding has a code (`GR2001`) and a fix hint. A finding marked `(expected)` belongs to work
|
|
81
|
+
that is still `proposed`; it does not fail the check.
|
|
82
|
+
|
|
83
|
+
## What to trust
|
|
84
|
+
|
|
85
|
+
- **Exports, imports, importers, routes, middleware, pages:** read from the code. Trust them.
|
|
86
|
+
- **Files behind a route:** every file the handler can reach through imports. It is not the exact
|
|
87
|
+
call path; open the handler to see which ones it really uses.
|
|
88
|
+
- **Reached from:** only links and redirects written as plain values. `unknown` means look.
|
|
89
|
+
- **Written files:** they say what should happen. When the code disagrees with a flow, do not
|
|
90
|
+
pick one silently. Say which is wrong, and fix it or ask the owner.
|
|
91
|
+
|
|
92
|
+
## When there is nothing to find
|
|
93
|
+
|
|
94
|
+
- No flow matches the task: the behaviour is undescribed. Describe it first with
|
|
95
|
+
`write-a-feature`, then change the code.
|
|
96
|
+
- The command says the book is missing or stale: it rebuilds on its own. If it reports problems,
|
|
97
|
+
read them; `npx warlock grimoire check` prints the same list.
|
|
98
|
+
- The project has code but no `grimoire/` folder: use `backfill-a-grimoire`.
|
|
99
|
+
|
|
100
|
+
## See also
|
|
101
|
+
|
|
102
|
+
`write-a-feature`, `record-a-change`, `describe-an-app`, `document-a-file`, `backfill-a-grimoire`.
|
|
103
|
+
|
|
104
|
+
## From code
|
|
105
|
+
|
|
106
|
+
The same answers are available as functions, for tools that build on the Grimoire.
|
|
107
|
+
|
|
108
|
+
From `@warlock.js/grimoire` (no dependency on core or web):
|
|
109
|
+
|
|
110
|
+
- `openGrimoire` loads everything once (it runs `parseGrimoire`, `buildBook`, `matchApps`,
|
|
111
|
+
`resolveOwnership`, `scanProofs`, `readTestResults`, `buildCollectedFiles`, then `writeBook`
|
|
112
|
+
and `writeCollectedFiles`), and returns a snapshot.
|
|
113
|
+
- `scry` answers a query from the snapshot; `formatScryResult` prints it; `parseScryQuery` reads
|
|
114
|
+
CLI arguments into a query.
|
|
115
|
+
- `checkGrimoire` runs every rule; `formatCheckReport` prints the report. Each finding has a code
|
|
116
|
+
from `GRIMOIRE_CODES` (also `GRIMOIRE_CODE_LIST`); `explainGrimoireCode`, `isGrimoireCode` and
|
|
117
|
+
`grimoireCodeDocsUrl` (based on `GRIMOIRE_CODES_DOCS_URL`) describe it, and rules build
|
|
118
|
+
findings with `createFinding`. Commands throw `GrimoireError` with a code.
|
|
119
|
+
- `collectRelease`, `renderCollectedList` and `writeRelease` gather the changelog entries of a
|
|
120
|
+
release between `COLLECTED_START_MARKER` and `COLLECTED_END_MARKER`.
|
|
121
|
+
- `scanProofs` and `scanProofsInText` read `// @proves` lines; `criterionStatus` turns test
|
|
122
|
+
results into a criterion's status; `CASE_QUESTIONS` lists the questions every flow answers.
|
|
123
|
+
- Helpers: `loadBook`, `readFrontMatter`, `fileGraph`, `importClosure`, `importerClosure`,
|
|
124
|
+
`bookEntryPath`, `bookEntryPaths`, `toPosixPath`, `GRIMOIRE_DIR`, `GRIMOIRE_PATHS`,
|
|
125
|
+
`GRIMOIRE_IGNORE_RULES` (the `.gitignore` lines) and `BOOK_SCHEMA_VERSION`.
|
|
126
|
+
|
|
127
|
+
From `@warlock.js/grimoire/warlock` (needs `@warlock.js/core`): `registerGrimoireCommands` returns
|
|
128
|
+
the `grimoire` and `scry` commands for `cli.commands` in `warlock.config.ts`;
|
|
129
|
+
`createWarlockAdapter` builds the adapter that feeds the book from the inspect report;
|
|
130
|
+
`collectMobileFacts` lists mobile screens from Expo Router file names.
|
|
131
|
+
|
|
132
|
+
From `@warlock.js/grimoire/vitest`: `grimoireReporter` records the last result of every test marked
|
|
133
|
+
`// @proves` into `grimoire/book/test-results.json`. Add it to the Vitest `reporters` list.
|
|
134
|
+
|
|
135
|
+
From `@warlock.js/grimoire/devtools`: `grimoireDevtoolsPanel` (the default export) is the Grimoire
|
|
136
|
+
tab for `@warlock.js/devtools`, listed in `panels` of `src/config/devtools.ts`;
|
|
137
|
+
`exportGrimoireSite` writes the same view as a static site.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: write-a-feature
|
|
3
|
+
description: "Describe a new feature, or a new version of one, in `grimoire/features/` before writing code: the task, the brief, the README front matter, each flow with its steps, cases and acceptance criteria. Use when the owner asks for something the product does not do yet."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Write a feature
|
|
7
|
+
|
|
8
|
+
The Grimoire is experimental: its file structure and commands may still change.
|
|
9
|
+
|
|
10
|
+
Describe the behaviour first, then build it. The description is the brief the owner approves and
|
|
11
|
+
the thing your tests will prove.
|
|
12
|
+
|
|
13
|
+
## Is it a feature, a flow, or a change?
|
|
14
|
+
|
|
15
|
+
- **A feature** is something a user or another system can do, named from their side (`auth`,
|
|
16
|
+
`catalog`, `orders`). It has roughly two to ten flows.
|
|
17
|
+
- **A flow** is one path through it (`sign-up`, `google-login`, `new-arrivals`).
|
|
18
|
+
- **A new capability** in an existing feature is a new whole-number version (`2.0`) with its
|
|
19
|
+
own brief. **A small change or a fix** is a decimal (`2.1`) and needs no brief: go to
|
|
20
|
+
`record-a-change`.
|
|
21
|
+
- A notification, mail or job belongs to the feature whose business reason creates it. "Your
|
|
22
|
+
order shipped" belongs to `orders`, not to `notifications`.
|
|
23
|
+
|
|
24
|
+
## 1. Open a task
|
|
25
|
+
|
|
26
|
+
`grimoire/tasks/open/T-014-wishlist.md`:
|
|
27
|
+
|
|
28
|
+
```md
|
|
29
|
+
---
|
|
30
|
+
id: T-014
|
|
31
|
+
type: feature
|
|
32
|
+
feature: catalog
|
|
33
|
+
apps: [web-client, mobile]
|
|
34
|
+
status: waiting for approval
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
# Let customers save products to a wishlist
|
|
38
|
+
|
|
39
|
+
- Asked by: the owner, 2026-11-16
|
|
40
|
+
- Why: customers ask to keep products for later
|
|
41
|
+
- Brief: features/catalog/versions/v3.md
|
|
42
|
+
- Decision needed: one wishlist per customer, or several named lists?
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A task that waits for the owner's answer has `status: waiting for approval` and a `Decision needed:` line.
|
|
46
|
+
The other statuses are `open`, `approved`, `in progress`, `blocked`, `done` and `dropped`; any other
|
|
47
|
+
word is an error (`GR1004`).
|
|
48
|
+
|
|
49
|
+
## 2. Write the brief
|
|
50
|
+
|
|
51
|
+
`grimoire/features/catalog/versions/v3.md`: why, what changes (which flows are new or changed),
|
|
52
|
+
and what is out of scope. Keep it to one screen.
|
|
53
|
+
|
|
54
|
+
## 3. Write or update the feature README
|
|
55
|
+
|
|
56
|
+
```md
|
|
57
|
+
---
|
|
58
|
+
id: catalog
|
|
59
|
+
title: Product catalog
|
|
60
|
+
status: proposed
|
|
61
|
+
version: 3.0
|
|
62
|
+
updated: 2026-11-16
|
|
63
|
+
apps: [web-client, mobile]
|
|
64
|
+
folders: [src/app/catalog, src/web/$sites/client/products]
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
# Product catalog
|
|
68
|
+
|
|
69
|
+
Customers browse products, search them and see what is new.
|
|
70
|
+
|
|
71
|
+
## Flows
|
|
72
|
+
|
|
73
|
+
- browse-products list and filter products
|
|
74
|
+
- new-arrivals the newest products sold in the customer's country
|
|
75
|
+
- wishlist save a product for later
|
|
76
|
+
|
|
77
|
+
## Affects and affected by
|
|
78
|
+
|
|
79
|
+
- affected by orders/place-order (lowers stock)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`id` never changes. `folders` are the folders whose files belong to this feature. An entry with a
|
|
83
|
+
code-file extension names one file (`src/web/components/client/home/pricing-table.tsx`), for a
|
|
84
|
+
feature that owns a few files in a folder shared with others. A file entry wins over the folder
|
|
85
|
+
of another feature; each file has one owner. `apps` must
|
|
86
|
+
exist under `grimoire/apps/`. A feature whose folders hold no file yet is fine while it is
|
|
87
|
+
`proposed`.
|
|
88
|
+
|
|
89
|
+
## 4. Write each flow
|
|
90
|
+
|
|
91
|
+
`grimoire/features/catalog/flows/wishlist.md`:
|
|
92
|
+
|
|
93
|
+
```md
|
|
94
|
+
---
|
|
95
|
+
id: wishlist
|
|
96
|
+
since: 3.0
|
|
97
|
+
status: proposed
|
|
98
|
+
who: customer
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
# Save a product to the wishlist
|
|
102
|
+
|
|
103
|
+
## Steps
|
|
104
|
+
|
|
105
|
+
1. page /products/:id
|
|
106
|
+
2. route POST /wishlist
|
|
107
|
+
3. notification wishlist-price-drop
|
|
108
|
+
4. page /wishlist
|
|
109
|
+
|
|
110
|
+
## Differs by app
|
|
111
|
+
|
|
112
|
+
- mobile the save button is also on the product card in lists
|
|
113
|
+
|
|
114
|
+
## Cases
|
|
115
|
+
|
|
116
|
+
- invalid input a product id that is not an id → 422
|
|
117
|
+
- not allowed guest → sent to sign in, then back to the product
|
|
118
|
+
- not found the product does not exist → 404
|
|
119
|
+
- duplicate already saved → stays saved, no error
|
|
120
|
+
- limits at most 200 products
|
|
121
|
+
- expiry does not apply: saved products do not expire
|
|
122
|
+
- double submit two taps save once
|
|
123
|
+
- outside service down does not apply: no outside service is called
|
|
124
|
+
|
|
125
|
+
## Acceptance criteria
|
|
126
|
+
|
|
127
|
+
- AC-1 a saved product appears on /wishlist
|
|
128
|
+
- AC-2 saving twice keeps one entry
|
|
129
|
+
- AC-3 a guest is sent to sign in and returns to the product
|
|
130
|
+
- AC-4 [mobile] the product card has a save button
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Steps.** Each step has a kind and the name used in code: `page`, `route`, `mail`,
|
|
134
|
+
`notification`, `job`, `event`, `outside service`. Use `affects` for an effect on another
|
|
135
|
+
feature (`affects catalog/stock`). Warlock checks every name exists. A mail is a `*.mail.ts` or
|
|
136
|
+
`*.email.ts` file, or a file in a `mails/` or `emails/` folder; a job is a queue job
|
|
137
|
+
(`defineJob()`) or a scheduled task, by its name in code.
|
|
138
|
+
|
|
139
|
+
When two sites, or a site and the mobile app, have a page with the same path, name the app after
|
|
140
|
+
the path in brackets: `page /support [web-admin]`. The step then looks in that app only (its
|
|
141
|
+
pages, or its screens for a mobile app). Without brackets it looks in the apps the feature lists.
|
|
142
|
+
|
|
143
|
+
**Cases.** Answer all eight questions (invalid input, not allowed, not found, duplicate, limits,
|
|
144
|
+
expiry, double submit, outside service down), each with a case or "does not apply" and the
|
|
145
|
+
reason. A flow that skips one gets a finding. Do not invent cases beyond the questions unless the owner described one.
|
|
146
|
+
|
|
147
|
+
**Criteria.** One per case that changes what the user gets. Number them `AC-1`, `AC-2`, … and
|
|
148
|
+
never renumber. Scope one to an app with `[app-id]`.
|
|
149
|
+
|
|
150
|
+
**App differences.** What the user gets differs → here, under the app's name. How it looks or
|
|
151
|
+
where it sits → the app's block file (`describe-an-app`).
|
|
152
|
+
|
|
153
|
+
## 5. Stop for approval
|
|
154
|
+
|
|
155
|
+
For a new feature or a whole-number version, stop here. Tell the owner the task id and the brief
|
|
156
|
+
path, list the decisions you need, and wait. Do not write code first.
|
|
157
|
+
|
|
158
|
+
## 6. Check
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npx warlock grimoire check
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Until the code exists it reports the routes and pages you named as missing. Findings on a flow or
|
|
165
|
+
feature with `status: proposed` print with `(expected)` and do not fail the check; everything else
|
|
166
|
+
it reports must be fixed.
|
|
167
|
+
|
|
168
|
+
Then build, and follow `record-a-change`.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static export's loader: it gives the Grimoire view a context whose
|
|
3
|
+
* `api()` reads the data embedded in the page instead of fetching, and mounts
|
|
4
|
+
* the view into one element. The exporter inlines this file after the view
|
|
5
|
+
* module, so `renderGrimoire` is in scope. There are no imports or exports.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const GRIMOIRE_STATIC_SVG = "http://www.w3.org/2000/svg";
|
|
9
|
+
const GRIMOIRE_STATIC_NEEDS_APP =
|
|
10
|
+
"This answer needs the running app. Open the Grimoire tab in devtools.";
|
|
11
|
+
|
|
12
|
+
/** The `api()` of the static page: `data.routes` by name, `data.files` by path, search over `data.search`. */
|
|
13
|
+
function grimoireStaticApi(data) {
|
|
14
|
+
const decode = (text) => {
|
|
15
|
+
try {
|
|
16
|
+
return decodeURIComponent(text);
|
|
17
|
+
} catch {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return async (path = "") => {
|
|
23
|
+
const [pathname = "", query = ""] = path.split("?");
|
|
24
|
+
const params = new URLSearchParams(query);
|
|
25
|
+
let name = pathname.replace(/^\//, "").split("/").map(decode).join("/");
|
|
26
|
+
|
|
27
|
+
if (name === "search") {
|
|
28
|
+
const text = (params.get("q") ?? "").trim().toLowerCase();
|
|
29
|
+
const limit = Number(params.get("limit")) || 20;
|
|
30
|
+
const hits = [];
|
|
31
|
+
for (const item of data.search) {
|
|
32
|
+
const id = item.id.toLowerCase();
|
|
33
|
+
const detail = (item.detail ?? "").toLowerCase();
|
|
34
|
+
const score =
|
|
35
|
+
id === text
|
|
36
|
+
? 4
|
|
37
|
+
: id.startsWith(text)
|
|
38
|
+
? 3
|
|
39
|
+
: id.includes(text)
|
|
40
|
+
? 2
|
|
41
|
+
: detail.includes(text)
|
|
42
|
+
? 1
|
|
43
|
+
: 0;
|
|
44
|
+
if (text && score) hits.push({ ...item, score });
|
|
45
|
+
}
|
|
46
|
+
hits.sort((left, right) => right.score - left.score || left.id.localeCompare(right.id));
|
|
47
|
+
return {
|
|
48
|
+
type: "search",
|
|
49
|
+
text,
|
|
50
|
+
hits: hits.slice(0, limit),
|
|
51
|
+
routes: data.routes.summary?.routes ?? "cached",
|
|
52
|
+
notes: [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (name === "file" || name === "graph/file") {
|
|
57
|
+
const file = params.get("path") ?? "";
|
|
58
|
+
const found = Object.prototype.hasOwnProperty.call(data.files, file)
|
|
59
|
+
? data.files[file]
|
|
60
|
+
: undefined;
|
|
61
|
+
if (!found) throw new Error(`"${params.get("path")}" is not in the exported book.`);
|
|
62
|
+
return name === "file" ? found.result : found.graph;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (name === "graph/page") {
|
|
66
|
+
name = `graph/page/${params.get("app")}/${params.get("page")}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (Object.prototype.hasOwnProperty.call(data.routes, name)) return data.routes[name];
|
|
70
|
+
throw new Error(GRIMOIRE_STATIC_NEEDS_APP);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The context the view gets in the static page. `route` is the hash after `#grimoire/`. */
|
|
75
|
+
function grimoireStaticContext(data, root, rerender) {
|
|
76
|
+
const hash = location.hash.slice(1);
|
|
77
|
+
const route = hash.startsWith("grimoire/") ? hash.slice("grimoire/".length) : "";
|
|
78
|
+
const apply = (node, attrs) => {
|
|
79
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
80
|
+
if (value == null) continue;
|
|
81
|
+
if (key === "class") node.setAttribute("class", value);
|
|
82
|
+
else if (key === "text") node.textContent = value;
|
|
83
|
+
else if (key.startsWith("on")) node.addEventListener(key.slice(2), value);
|
|
84
|
+
else node.setAttribute(key, value);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const build = (node, attrs, children) => {
|
|
88
|
+
apply(node, attrs);
|
|
89
|
+
for (const child of Array.isArray(children) ? children : [children]) node.append(child);
|
|
90
|
+
return node;
|
|
91
|
+
};
|
|
92
|
+
const el = (tag, attrs = {}, children = []) =>
|
|
93
|
+
build(document.createElement(tag), attrs, children);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
id: "grimoire",
|
|
97
|
+
root,
|
|
98
|
+
route,
|
|
99
|
+
api: grimoireStaticApi(data),
|
|
100
|
+
href: (target = "") => `#grimoire${target ? `/${target}` : ""}`,
|
|
101
|
+
navigate(target) {
|
|
102
|
+
const next = `#grimoire${target ? `/${target}` : ""}`;
|
|
103
|
+
if (location.hash === next) rerender();
|
|
104
|
+
else location.hash = next;
|
|
105
|
+
},
|
|
106
|
+
refresh: rerender,
|
|
107
|
+
el,
|
|
108
|
+
svg: (tag, attrs = {}, children = []) =>
|
|
109
|
+
build(document.createElementNS(GRIMOIRE_STATIC_SVG, tag), attrs, children),
|
|
110
|
+
empty: (message) => el("p", { class: "empty", text: message }),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Render the view into `container` now and again when the hash changes. Called from the exported page, which inlines this file. */
|
|
115
|
+
// oxlint-disable-next-line eslint/no-unused-vars -- called by the inlined bootstrap line of the static export.
|
|
116
|
+
function grimoireStaticMount(data, container, render) {
|
|
117
|
+
let version = 0;
|
|
118
|
+
async function show() {
|
|
119
|
+
const mine = ++version;
|
|
120
|
+
const root = document.createElement("section");
|
|
121
|
+
root.setAttribute("class", "panel");
|
|
122
|
+
root.setAttribute("data-panel", "grimoire");
|
|
123
|
+
try {
|
|
124
|
+
const view = await render(grimoireStaticContext(data, root, show));
|
|
125
|
+
if (mine !== version) return;
|
|
126
|
+
container.replaceChildren(view ?? root);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const message = document.createElement("p");
|
|
129
|
+
message.setAttribute("class", "error");
|
|
130
|
+
message.textContent = `Could not load this view: ${error.message}`;
|
|
131
|
+
container.replaceChildren(message);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
window.addEventListener("hashchange", show);
|
|
135
|
+
return show();
|
|
136
|
+
}
|