Skip to content

The book

The book is the part of the Grimoire that Warlock writes. It describes the code as it is: one entry per source file, a summary per module, every route, the pages of each site and the screens of a mobile app. It lives in grimoire/book/, is ignored by git, and is rebuilt when the sources change.

Never edit a book file. Change the code, or the written files under grimoire/features/ and grimoire/apps/, and the book follows.

The book is built from the report Warlock already gives about your project (inspectApp() from @warlock.js/core/tooling). It never parses your source a second time.

Terminal window
npx warlock grimoire build # refresh what changed
npx warlock grimoire build --force # collect everything again and restore edited or deleted entries

Run it after you finish editing. warlock grimoire check and the devtools tab check that the book is fresh first and refresh it when it is not; warlock scry and the MCP read tools only read the stored book and add a note when it is behind the files.

grimoire/book/
manifest.json The freshness fingerprint.
app/
routes.json Every route, by module.
catalog/
index.md Summary of src/app/catalog.
routes.json Entry of src/app/catalog/routes.ts.
services/
new-arrivals.service.json Entry of src/app/catalog/services/new-arrivals.service.ts.
config/
index.md
app.json
web/
index.md Summary of src/web.
client.pages.json Pages of the `client` site.
$sites/client/home.page.json Entry of src/web/$sites/client/home.page.tsx.
mobile/
mobile.screens.json The `mobile` app and its screens.
mobile/app/index.json Entry of mobile/app/index.tsx.
test-results.json Written by the test reporter.
.cache/ Machine use only.

The entry of a source file sits at the same path as the file, with src/ dropped and the extension replaced by .json:

Source fileEntry
src/app/auth/controllers/login.controller.tsgrimoire/book/app/auth/controllers/login.controller.json
src/web/$sites/client/home.page.tsxgrimoire/book/web/$sites/client/home.page.json
mobile/app/products/[id].tsx (mobile app mobile)grimoire/book/mobile/mobile/app/products/[id].json

Files of a mobile app go under mobile/<app id>/. Two cases keep the full file name instead:

  • two files would share an entry (a.ts and a.tsx become a.ts.json and a.tsx.json);
  • the entry would take the place of a list the book writes (src/app/routes.ts becomes app/routes.ts.json, so it does not replace app/routes.json).
grimoire/book/app/catalog/services/new-arrivals.service.json
{
"schemaVersion": 1,
"file": "src/app/catalog/services/new-arrivals.service.ts",
"module": "src/app/catalog",
"type": "service",
"lines": 10,
"about": "Lists the newest products sold in the customer's country.",
"feature": "catalog",
"borrowedBy": [],
"flows": ["catalog/new-arrivals"],
"exports": [{ "name": "listNewArrivals", "about": "Returns up to 20 products, newest first." }],
"packages": [],
"imports": ["src/app/catalog/repositories/products.repository.ts"],
"typeOnlyImports": [],
"importedBy": [
"src/app/catalog/controllers/new-arrivals.controller.ts",
"src/app/catalog/tests/new-arrivals.test.ts",
"src/web/$sites/client/home.setup.ts"
],
"routes": [],
"pages": [],
"screens": []
}
FieldHolds
schemaVersionThe version of the book’s JSON shapes. It changes only for a breaking change.
fileThe source file, project-relative, with /.
modulesrc/app/<module> for application code, otherwise the top folder (src/config, src/web, mobile/app).
typeThe file’s role from its name: controller, service, repository, model, mail, job, page, setup, layout, routes, spec and so on.
linesLine count.
aboutThe first sentence of the comment at the top of the file, or null.
featureThe feature that owns the file, or null. See Features and book maps.
borrowedByFeatures that import the file without owning it. Sorted.
flows<feature>/<flow> of every flow whose steps reach the file. Sorted.
exportsEach export with the first sentence of the comment above it (about, or null). default and * stand for default and star exports.
packagesExternal packages the file imports, by package name (@warlock.js/core, dayjs). Node built-ins are left out. Sorted.
importsProject files it imports. Sorted.
typeOnlyImportsThe project files from imports that the file imports only as types (import type, import { type A }, export type … from). Erased at build time. Sorted.
importedByProject files that import it. Sorted.
routesRoutes the file registers ("via": "registers", a routes file) or handles ("via": "handles", the controller or page that answers). Each has method, path and name.
pagesPages the file is the page, setup or layout file of: site, route, via (page, setup, layout).
screensMobile screens the file is the screen or layout file of: app, route, via (screen, layout).

Absent values are null, never left out. A route that only reaches the file through imports is not listed in routes; warlock scry --impact <file> answers that.

Each module gets an index.md: src/app/catalog is summarised in grimoire/book/app/catalog/index.md.

grimoire/book/app/catalog/index.md
# src/app/catalog
Feature: catalog. 7 files, 73 lines.
## Files
- controllers/new-arrivals.controller.ts controller Answers the new arrivals request.
- services/new-arrivals.service.ts service Lists the newest products sold in the customer's country.
## Routes
- GET /api/products/new-arrivals
## Used by
- src/web (2 files)
- src/app/orders (1 file)
  • The first line names the features that own the module’s files, the one with most files first.
  • Files lists every file by its path inside the module, then its type and its header sentence.
  • Routes lists routes whose routes file (or, for a page, its page file) is in the module.
  • Used by lists other modules that import files of this one, with how many of their files do.

A section with nothing in it is left out.

grimoire/book/app/routes.json lists every route, grouped by the module of the file that registered it, in registration order. Page routes have no routes file and are listed under (none).

grimoire/book/app/routes.json
{
"schemaVersion": 1,
"modules": {
"(none)": [
{
"method": "GET",
"path": "/",
"name": "home",
"handlerFile": "src/web/$sites/client/home.page.tsx"
}
],
"src/app/orders": [
{
"method": "POST",
"path": "/api/orders",
"name": "orders.place",
"handlerFile": "src/app/orders/controllers/place-order.controller.ts"
}
]
}
}

The file is not written until routes have been read once (see The route cache).

Each site gets grimoire/book/web/<site>.pages.json with the site (id, root, basePath) and its pages. A single-site app has one site, default, rooted at src/web.

Page fieldHolds
siteThe site id.
routeThe route path (/products/:id).
nameThe route name, or null.
fileThe *.page.tsx file.
setupFileThe *.setup.ts file that holds the page’s logic, or null.
layoutsLayout files, outermost first.
loadersFiles on the chain that export a loader.
actionsAction names (default for action).
requiresWhat the page needs before it renders (user, middleware names). Empty when nothing.
reachedFromLinks and redirects that point at the page, read as plain values. null means unknown.

Each mobile app in the repository gets grimoire/book/mobile/<app>.screens.json: the app (id, root, routing, routesDir) and its screens (route, file, layouts). When the app uses file-based routing (routing: "files"), screens come from the files under routesDir. When navigation is defined in code (routing: "code"), the list is empty and the screens are the ones agents describe in grimoire/apps/<app>/screens/.

manifest.json is the fingerprint of the sources the book was built from. It records the Grimoire version, the adapter name and version (for Warlock, the framework version), the source roots, and for every code file under the source roots its size, modification time and sha256 hash. It also records the hash of each test file.

Before anything else, every command does this:

  1. Stat every code file under the source roots (images, fonts, certificates and other non-code files are not in the book): src/ and the top-level folders of each mobile app, except its native projects and build output (android/, ios/, build/, dist/, web-build/, coverage/). node_modules and dot folders are skipped. Code files directly in a mobile app’s folder (such as App.tsx and index.ts) are in the book; tool configs (babel.config.js, metro.config.js) and *.d.ts files are not.
  2. Hash only the files whose size or modification time differ from the manifest. A file that was only touched keeps its hash.
  3. If the set of files, every hash, the test file hashes and the versions all match, the book is fresh. Nothing is collected and nothing is written.
  4. Otherwise the file facts, sites, pages, mobile apps and test list are collected again. Entries are rewritten only when their content changed, and the entries of deleted files are removed.

The book never removes test-results.json, the static export under site/, or .cache/.

Writes are atomic: each file is written to a temporary file next to it and renamed into place, so a reader never sees half a file. Nothing is ever written outside grimoire/book/.

Reading routes registers them, and that loads the application. So the routes, together with the names of mails, jobs, events and notifications, are cached and read again only when something they depend on changed. The inputs are:

  • every routes file and every file it imports, directly or not;
  • every config file, warlock.config.ts and package.json;
  • every mail, job, event and notification file.

When one of them changes (or is added or removed), the cached routes are stale. What happens next depends on the command:

CommandStale routes
warlock grimoire build, warlock grimoire checkRead again (the app boots once).
warlock scry, the MCP tools, the devtools tabNot read. The cached routes are used and reported as stale.

So a question about a file never boots the app, and neither does warlock scry --route: with no cached routes it stops with GR9002 and tells you to run warlock grimoire build. When a command answers from stale routes, it says so and tells you to run warlock grimoire build.

A live read (routes: "fresh") that finds fewer than half of the routes the book already holds is not trusted: the book keeps its stored list, writes nothing for it, reports the facts as stale and says a live read found 10 routes against the 277 stored; kept the stored routes; run warlock grimoire build again, or warlock grimoire build --force when the routes were removed (warlock grimoire build prints the same note). A forced build (--force) trusts the read, so a real removal of most routes is accepted that way. The manifest stores the route and page counts of the last read (boot.counts) for this. When the stored routes exist but none names its source file, answers say route facts look incomplete; run warlock grimoire build, and warlock scry --route gives that as the reason for GR9002; --impact carries the same note.

Route freshness is reported as one of:

ValueMeans
freshThe routes match the current sources.
staleCached routes are used, but an input changed since they were read.
missingRoutes were never read (for example, only file questions were asked so far).
cachedRead from disk without checking the sources.
  • Exports, imports, importers, routes, middleware and pages are read from the code. Trust them.
  • After an upgrade from a version that did not record type-only imports, the book scans file facts once more on the next run.
  • Files behind a route are every file the handler can reach through imports that run (type-only imports are listed separately). That is not the exact call path; open the handler to see which ones it really uses.
  • Reached from lists only links and redirects written as plain values. null (shown as “unknown”) means look.
  • Feature, borrowers and flows come from the written files. When the code disagrees with a flow, the written file may be out of date; say which is wrong.
  • Routes may be stale when a command says so. Run warlock grimoire build before relying on them.