@sssb/tools 0.0.0 → 0.3.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/bin/sssb.js +116 -0
  3. package/package.json +89 -5
  4. package/src/app-port.js +77 -0
  5. package/src/app.js +142 -0
  6. package/src/assembly-checks.d.ts +57 -0
  7. package/src/assembly-checks.js +259 -0
  8. package/src/commands/add-app.js +344 -0
  9. package/src/commands/check-demo-size.js +80 -0
  10. package/src/commands/check-doc-paths.js +48 -0
  11. package/src/commands/check-e2e.js +611 -0
  12. package/src/commands/check-fences.js +51 -0
  13. package/src/commands/check-real-env.js +165 -0
  14. package/src/commands/check-tmpdir-leak.js +78 -0
  15. package/src/commands/ci.js +350 -0
  16. package/src/commands/dev-tick.js +25 -0
  17. package/src/commands/doctor-checks.js +1396 -0
  18. package/src/commands/doctor-settings.js +583 -0
  19. package/src/commands/doctor-vitest.js +262 -0
  20. package/src/commands/doctor.js +1033 -0
  21. package/src/commands/e2e-profile.js +94 -0
  22. package/src/commands/guide.js +108 -0
  23. package/src/commands/launch-json.js +55 -0
  24. package/src/commands/pin.js +411 -0
  25. package/src/commands/port.js +22 -0
  26. package/src/commands/remove-items.js +191 -0
  27. package/src/commands/serve-standalone.js +78 -0
  28. package/src/commands/tick.js +27 -0
  29. package/src/doc-paths.d.ts +106 -0
  30. package/src/doc-paths.js +328 -0
  31. package/src/framework-guard.js +35 -0
  32. package/src/kit.d.ts +49 -0
  33. package/src/kit.js +216 -0
  34. package/src/next.d.ts +16 -0
  35. package/src/next.js +55 -0
  36. package/src/ports.d.ts +72 -0
  37. package/src/ports.js +307 -0
  38. package/src/prune-mantine-css.js +171 -0
  39. package/src/remove-items/code.patch +798 -0
  40. package/src/remove-items/database.patch +218 -0
  41. package/src/remove-items/exact-patch.js +122 -0
  42. package/src/testing/tmp-dir-marker.js +9 -0
  43. package/src/testing/tmp-dir-setup.d.ts +2 -0
  44. package/src/testing/tmp-dir-setup.js +9 -0
  45. package/src/testing/tmp-dir.d.ts +20 -0
  46. package/src/testing/tmp-dir.js +174 -0
  47. package/src/tick/dev-tick.js +128 -0
  48. package/src/tick/tick.js +317 -0
  49. package/src/tick/ticker-marker.d.ts +17 -0
  50. package/src/tick/ticker-marker.js +83 -0
  51. package/src/tick/ticker.d.ts +36 -0
  52. package/src/tick/ticker.js +142 -0
  53. package/src/vite.d.ts +38 -0
  54. package/src/vite.js +64 -0
  55. package/src/vitest.d.ts +38 -0
  56. package/src/vitest.js +82 -0
  57. package/tsconfig.base.json +33 -0
  58. package/README.md +0 -3
@@ -0,0 +1,22 @@
1
+ // @ts-check
2
+ // `sssb port [service]`: prints one port, so package scripts can say `next dev --port "$(sssb port)"`.
3
+ import { appPortService, serviceNamed, servicesKnownTo } from '../app-port.js'
4
+ import { takeAppDir, UsageError } from '../app.js'
5
+ import { portFor } from '../ports.js'
6
+
7
+ /** @param {string[]} args */
8
+ export async function run(args) {
9
+ const appDir = takeAppDir(args)
10
+ if (args.length > 1) throw new UsageError(`usage: sssb port [${servicesKnownTo(appDir).join('|')}]`)
11
+ const service = args[0] === undefined ? appPortService(appDir) : serviceNamed(appDir, args[0])
12
+ if (service === undefined) {
13
+ throw new UsageError(`sssb port: unknown service "${args[0]}" (known: ${servicesKnownTo(appDir).join(', ')})`)
14
+ }
15
+ // `process.stdout.write` of a STRING, never `console.log` of a number. Playwright injects FORCE_COLOR=1 into
16
+ // every webServer process it spawns, and `console.log` of a NUMBER goes through util.inspect, which then colours
17
+ // it: the bytes become `\e[33m3240\e[39m`. That renders as a clean "3240" in a terminal and in a log file, so the
18
+ // corruption is invisible; but `$(...)` captures the escape codes too, and `next dev --port` then fails with
19
+ // "'3240' is not a non-negative number". Strings are never coloured, so this cannot recur.
20
+ process.stdout.write(`${portFor(service)}\n`)
21
+ return 0
22
+ }
@@ -0,0 +1,191 @@
1
+ // @ts-check
2
+ // `sssb remove-items [--app <dir>] [--drop-migrations] [--dry-run]`: takes the starter's example Items slice out of an app
3
+ // in one step, and leaves the app green. The first thing every adopter does is this sweep by hand over about fifteen
4
+ // files (SSSB's docs/adopting-reference.md, "To remove the Items slice"); this is that sweep as a patch the starter's own
5
+ // test keeps true.
6
+ //
7
+ // WHAT IT DOES. Two patches, `remove-items/code.patch` and `remove-items/database.patch` (a unified diff of the starter
8
+ // against the starter without Items, applied EXACTLY by ./exact-patch.js). The code half removes everything an app's
9
+ // code says about Items: the card, the route, the query, the ability, the catalog namespace, the dashboard's glue, the
10
+ // static demo's card, the specs that name Items, and the proofs of paging. It writes nothing of its own: the starter's
11
+ // other e2e spec (the Simulator's) stays, so the app still has one for `sssb check-e2e`. The database half removes the migrations, the table's type and its
12
+ // RLS proofs, and only runs with `--drop-migrations`.
13
+ //
14
+ // THE RULE FOR MIGRATIONS. A database that ran `1001_items` records it, and the migrator refuses to start when a migration
15
+ // it recorded is gone from the code (Kysely: "previously executed migration ... is missing"). So this command never
16
+ // deletes a migration unless it is told to: `--drop-migrations` is for an app whose database has never run them (a
17
+ // workspace just generated: delete the local `.data` too), and without it the migrations, `ItemsTable` and the RLS proofs
18
+ // of `items` stay, registered, which keeps every gate green and every recorded migration in place. Both halves are
19
+ // one choice, made once: the second half is not available after the first ran on its own.
20
+ //
21
+ // KEEPING THE PATCHES TRUE. They are diffs of the starter, so a change to a starter file they touch (or to the Items
22
+ // slice's own) fails tests/tooling/remove-items.test.ts, which names the file. Regenerate on a scratch branch off the change:
23
+ // edit the starter into its Items-less form in two commits (the code half, then the database half), and write
24
+ // `git diff --no-renames -U3 --relative=apps/starter <before> <after> -- apps/starter` for each into code.patch and
25
+ // database.patch. The starter is untouched by the change itself: the scratch branch is thrown away.
26
+ //
27
+ // WHEN IT REFUSES. It computes every edit in memory first and writes only if every one applies. A file the starter wrote
28
+ // and the adopter has not touched inside a hunk applies, wherever the hunk has moved to; one they edited, deleted, or
29
+ // that is not there is named, with what is wrong, and NOTHING is written. Adopter-written code is never deleted silently.
30
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, writeFileSync } from 'node:fs'
31
+ import path from 'node:path'
32
+ import { takeAppDir, takeFlag, UsageError } from '../app.js'
33
+ import { applyFilePatch, parsePatch } from '../remove-items/exact-patch.js'
34
+
35
+ const USAGE = 'usage: sssb remove-items [--app <dir>] [--drop-migrations] [--dry-run]'
36
+
37
+ /** @param {string} name */
38
+ const patchFile = (name) => readFileSync(new URL(`../remove-items/${name}.patch`, import.meta.url), 'utf8')
39
+
40
+ /**
41
+ * @param {string[]} args
42
+ * @returns {Promise<number>}
43
+ */
44
+ export async function run(args) {
45
+ if (args.includes('--help') || args.includes('-h')) {
46
+ console.log(
47
+ [
48
+ USAGE,
49
+ '',
50
+ "Takes the starter's example Items slice out of the app (the card, the route, the query, the ability, the catalog",
51
+ "namespace, the dashboard's and the static demo's card, the specs that name Items).",
52
+ '',
53
+ ' --drop-migrations also remove 1001_items, 1002_items_keyset_index, the table type and its RLS proofs. For an app whose',
54
+ ' database has never run them: delete the local `.data` after. A database that ran a migration',
55
+ ' records it, and the migrator refuses to start when it is gone from the code, so without this flag',
56
+ ' they stay, registered, and the app stays green.',
57
+ ' --dry-run say what would change, and change nothing.',
58
+ '',
59
+ 'It refuses, naming each file, when the slice is not what the starter wrote, and writes nothing.',
60
+ ].join('\n'),
61
+ )
62
+ return 0
63
+ }
64
+ const appDir = takeAppDir(args)
65
+ const drop = takeFlag(args, '--drop-migrations')
66
+ const dry = takeFlag(args, '--dry-run')
67
+ if (args.length > 0) throw new UsageError(`sssb remove-items: unexpected ${args.join(' ')}\n${USAGE}`)
68
+ if (!existsSync(path.join(appDir, 'src/app-config'))) {
69
+ throw new UsageError(`sssb remove-items: ${appDir} has no src/app-config, so it is not an SSSB app\n${USAGE}`)
70
+ }
71
+
72
+ /** What each file holds now, as the plan builds on it: null is "not there". @type {Map<string, string | null>} */
73
+ const state = new Map()
74
+ /** @type {Map<string, 'add' | 'edit' | 'delete'>} */
75
+ const actions = new Map()
76
+ /** @param {string} file */
77
+ const current = (file) => {
78
+ if (!state.has(file)) {
79
+ const full = path.join(appDir, file)
80
+ state.set(file, existsSync(full) ? readFileSync(full, 'utf8') : null)
81
+ }
82
+ return /** @type {string | null} */ (state.get(file))
83
+ }
84
+
85
+ /** @type {string[]} */
86
+ const problems = []
87
+ for (const half of drop ? ['code', 'database'] : ['code']) {
88
+ for (const patch of parsePatch(patchFile(half))) {
89
+ const before = current(patch.path)
90
+ const result = applyFilePatch(before, patch)
91
+ if (!result.ok) {
92
+ problems.push(`${patch.path}: ${result.reason}`)
93
+ continue
94
+ }
95
+ state.set(patch.path, result.content)
96
+ const was = actions.get(patch.path)
97
+ actions.set(
98
+ patch.path,
99
+ result.content === null ? 'delete' : was === 'add' || before === null ? 'add' : 'edit',
100
+ )
101
+ }
102
+ // The database half is a patch on what the code half leaves; after a refusal that state is a guess.
103
+ if (problems.length > 0) break
104
+ }
105
+
106
+ if (problems.length > 0) {
107
+ console.error(
108
+ [
109
+ `sssb remove-items: nothing was changed. ${problems.length === 1 ? 'One file is' : `${problems.length} files are`} not what the starter wrote, so removing the Items slice would mean guessing:`,
110
+ ...problems.map((problem) => ` ${problem}`),
111
+ '',
112
+ 'Restore each file and run this again, or take the slice out by hand: SSSB\'s docs/adopting-reference.md, "To remove the Items slice".',
113
+ 'If the slice is already gone, there is nothing to do.',
114
+ ].join('\n'),
115
+ )
116
+ return 1
117
+ }
118
+
119
+ const where = path.relative(process.cwd(), appDir) || '.'
120
+ const listing = [...actions].map(([file, action]) => ` ${action.padEnd(6)} ${file}`)
121
+ if (dry) {
122
+ console.log(
123
+ [
124
+ `sssb remove-items --dry-run, in ${where}${drop ? ' (--drop-migrations)' : ''}: this would`,
125
+ ...listing,
126
+ '',
127
+ 'Nothing was written.',
128
+ ].join('\n'),
129
+ )
130
+ return 0
131
+ }
132
+
133
+ let written = 0
134
+ try {
135
+ for (const [file, action] of actions) {
136
+ const full = path.join(appDir, file)
137
+ if (action === 'delete') {
138
+ rmSync(full)
139
+ pruneEmptyDirectories(path.dirname(full), appDir)
140
+ } else {
141
+ mkdirSync(path.dirname(full), { recursive: true })
142
+ writeFileSync(full, /** @type {string} */ (state.get(file)))
143
+ }
144
+ written++
145
+ }
146
+ } catch (error) {
147
+ // Every refusal is decided before the first write; this is the disk failing part-way, which no plan can rule out.
148
+ throw new UsageError(
149
+ `sssb remove-items: the disk failed after ${written} of ${actions.size} files (${/** @type {Error} */ (error).message}). The app is half changed: \`git status\` shows which, and \`git restore .\` puts it back before you run this again.`,
150
+ )
151
+ }
152
+ // Next's dev server writes a type validator that names every route file (`.next/dev/types/validator.ts`), and the app's
153
+ // tsconfig includes it. `next typegen`, which `pnpm typecheck` runs, rewrites only `.next/types`, so after the route
154
+ // is gone a leftover validator fails typecheck on a module that no longer exists. It is generated, ignored by git, and
155
+ // written again by the next `pnpm dev`.
156
+ rmSync(path.join(appDir, '.next/dev/types'), { recursive: true, force: true })
157
+ console.log(
158
+ [
159
+ `sssb remove-items: took the Items slice out of ${where}.`,
160
+ ...listing,
161
+ '',
162
+ ...(drop
163
+ ? [
164
+ 'The migrations and the table are gone too. This is only safe for a database that never ran 1001_items: delete the',
165
+ `local data directory (${path.join(where, '.data')}) so the dev database starts from the new migration list, and number your`,
166
+ 'first table 1001, as an app with no migrations does.',
167
+ ]
168
+ : [
169
+ 'The database half stayed: 1001_items, 1002_items_keyset_index, the `items` table type and its RLS proofs. A database',
170
+ 'that ran them records them, and the migrator refuses a recorded migration that is gone. If no database ever did,',
171
+ 'restore the app and run `sssb remove-items --drop-migrations` instead: the two halves are one choice, made once.',
172
+ ]),
173
+ '',
174
+ 'Then run `pnpm verify`.',
175
+ ].join('\n'),
176
+ )
177
+ return 0
178
+ }
179
+
180
+ /**
181
+ * Removes `dir` and its parents while they are empty, stopping before `stop`.
182
+ * @param {string} dir
183
+ * @param {string} stop
184
+ */
185
+ function pruneEmptyDirectories(dir, stop) {
186
+ let at = dir
187
+ while (path.resolve(at) !== path.resolve(stop) && existsSync(at) && readdirSync(at).length === 0) {
188
+ rmdirSync(at)
189
+ at = path.dirname(at)
190
+ }
191
+ }
@@ -0,0 +1,78 @@
1
+ // @ts-check
2
+ // `sssb serve-standalone [service]`: runs the app's standalone production build locally (`next start` does not
3
+ // serve `output: 'standalone'`). Copies the static assets the way the Lambda packaging step does, then boots
4
+ // server.js.
5
+ //
6
+ // In a monorepo Next nests the standalone output under the app's path relative to the inferred workspace root, so
7
+ // the server is at `.next/standalone/<…>/apps/<app>/server.js`, not at the top, and static assets must sit beside
8
+ // THAT file. The exact prefix depends on where Next infers the root, so it is discovered rather than assumed.
9
+ //
10
+ // The port: PORT when set, else the named port service, else the app's declared one (`"sssb": { "port": … }`).
11
+ import { spawn } from 'node:child_process'
12
+ import { cpSync, existsSync, readdirSync } from 'node:fs'
13
+ import path from 'node:path'
14
+ import { appPortService, serviceNamed, servicesKnownTo } from '../app-port.js'
15
+ import { takeAppDir, UsageError } from '../app.js'
16
+ import { portFor } from '../ports.js'
17
+
18
+ /**
19
+ * The single server.js Next emitted, wherever it nested it.
20
+ * @param {string} dir
21
+ * @returns {string | null}
22
+ */
23
+ function findServer(dir) {
24
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
25
+ if (entry.isFile() && entry.name === 'server.js') return path.join(dir, entry.name)
26
+ if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== '.next') {
27
+ const found = findServer(path.join(dir, entry.name))
28
+ if (found) return found
29
+ }
30
+ }
31
+ return null
32
+ }
33
+
34
+ /** @param {string[]} args */
35
+ export async function run(args) {
36
+ const root = takeAppDir(args)
37
+ if (args.length > 1) throw new UsageError(`usage: sssb serve-standalone [${servicesKnownTo(root).join('|')}]`)
38
+ const service =
39
+ args[0] === undefined ? (process.env['PORT'] ? undefined : appPortService(root)) : serviceNamed(root, args[0])
40
+ if (args[0] !== undefined && service === undefined)
41
+ throw new UsageError(`sssb serve-standalone: unknown port service "${args[0]}"`)
42
+
43
+ const standalone = path.join(root, '.next', 'standalone')
44
+ if (!existsSync(standalone)) {
45
+ throw new UsageError('No standalone build found: build the app first (its `build:demo` or `build` script).')
46
+ }
47
+ const server = findServer(standalone)
48
+ if (!server) throw new UsageError(`No server.js under ${standalone}: the standalone build looks incomplete.`)
49
+ const serverDir = path.dirname(server)
50
+
51
+ cpSync(path.join(root, '.next', 'static'), path.join(serverDir, '.next', 'static'), { recursive: true })
52
+ if (existsSync(path.join(root, 'public'))) {
53
+ cpSync(path.join(root, 'public'), path.join(serverDir, 'public'), { recursive: true })
54
+ }
55
+
56
+ const port = process.env['PORT'] ?? String(portFor(service))
57
+
58
+ // PIN THE WORLD TO THE APP, not to the build output. The fake adapters resolve `.data` relative to the working
59
+ // directory, and this child's is `serverDir`, somewhere inside `.next/standalone/…`. Left alone it writes its
60
+ // world THERE, which is invisible from the app directory: `rm -rf .data` looks like it reset everything and
61
+ // resets nothing, so state leaks between runs. That cost two e2e failures that looked like product bugs before
62
+ // the cause was found. An explicit APP_DATA_DIR still wins, which is how the shard runner gives each shard its own.
63
+ const dataDir = process.env['APP_DATA_DIR'] ?? path.join(root, '.data')
64
+
65
+ console.log(`serving standalone build on http://localhost:${port} (world: ${dataDir})`)
66
+ const child = spawn(process.execPath, [server], {
67
+ stdio: 'inherit',
68
+ env: { ...process.env, PORT: port, HOSTNAME: '127.0.0.1', APP_DATA_DIR: dataDir },
69
+ cwd: serverDir,
70
+ })
71
+ return await new Promise((resolve) => {
72
+ child.on('error', (error) => {
73
+ console.error(`Could not start the standalone server: ${error.message}`)
74
+ resolve(1)
75
+ })
76
+ child.on('exit', (code) => resolve(code ?? 0))
77
+ })
78
+ }
@@ -0,0 +1,27 @@
1
+ // @ts-check
2
+ // `sssb tick [<app>] [--url <origin>] [--timeout <seconds>] [--app <dir>]`: calls the running dev server's
3
+ // scheduled-tick route once and says what ran. The logic is ../tick/tick.js. It runs in the app's directory (`--app`,
4
+ // else the working directory), where the server keeps `.data`, and `<app>` (the port slot) defaults to the one the
5
+ // app declares (`"sssb": { "port": … }`).
6
+ import { declaredPortService, portNameOf } from '../app-port.js'
7
+ import { existsSync } from 'node:fs'
8
+ import path from 'node:path'
9
+ import { takeAppDir } from '../app.js'
10
+ import { main } from '../tick/tick.js'
11
+
12
+ /** @param {string[]} args */
13
+ export async function run(args) {
14
+ // With `--app`, or from a package's directory, the slot defaults to the app's declaration; from anywhere else the
15
+ // command takes its slot as an argument and the working directory as it is, as it always has.
16
+ const hasApp = args.includes('--app') || existsSync(path.join(process.cwd(), 'package.json'))
17
+ const appDir = hasApp ? takeAppDir(args) : process.cwd()
18
+ process.chdir(appDir)
19
+ const declared = hasApp ? declaredPortService(appDir) : undefined
20
+ const first = args[0]
21
+ return await main(
22
+ declared !== undefined && (first === undefined || first.startsWith('-'))
23
+ ? [portNameOf(declared), ...args]
24
+ : args,
25
+ declared,
26
+ )
27
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The gate that fails the build when a doctrine doc cites a path that does not exist, and the parser the adoption
3
+ * rewriter shares with it. Everything about WHICH repository this is lives in the adopter's own root package.json
4
+ * under `sssb.docPaths`, so the gate survives the day `packages/kit` leaves the tree.
5
+ */
6
+
7
+ export interface DocPathsConfig {
8
+ /** Prefixes that make a backticked token unambiguously a path in this repo (`docs/`, `apps/`, ...). */
9
+ roots: string[]
10
+ /**
11
+ * Directories walked for `.md` files, and individual files, relative to the workspace root. Root-level files are
12
+ * listed rather than globbed because a repo root accumulates markdown that is NOT doctrine: a stray NOTES.md
13
+ * should not become a build gate.
14
+ */
15
+ include: string[]
16
+ /**
17
+ * Path prefixes (root-relative, forward slashes) never gated, each an append-only dated record or not this
18
+ * checkout's content. Rewriting a record to match today's tree would be revisionist, so such files are corrected
19
+ * opportunistically but never gated. SSSB's own, with the reason for each:
20
+ *
21
+ * - `docs/adr/`: dated decisions, amended by appending a dated addendum, never by editing the body.
22
+ * - `docs/build-notes.md`: a running log of dated lessons.
23
+ * - `docs/decision-log.md`: a running log of dated decisions.
24
+ * - `.claude/future-tasks/resolved/`: finished tasks; the work that resolved one routinely moved what it cites.
25
+ * - `.claude/worktrees/`: linked worktrees from agent sessions, not this checkout's content.
26
+ */
27
+ exempt: string[]
28
+ /**
29
+ * Apps a citation may name while absent from the tree (SSSB: `showcase`, `starter`). Optional, default none, in
30
+ * which case every citation is checked strictly. See `resolves` for the rule.
31
+ */
32
+ referenceApps?: string[]
33
+ /**
34
+ * Path segments that are build outputs, never checked. A doc may legitimately name one, but whether it exists on
35
+ * disk depends on whether you happened to run a build, which would make the gate pass locally and fail on a clean
36
+ * checkout: a gate whose verdict depends on build state is not a gate. Default: `dist-demo`, `.next`, `coverage`,
37
+ * `playwright-report`, `test-results`, `node_modules`, `.data`.
38
+ */
39
+ buildOutputs?: string[]
40
+ /**
41
+ * Docs whose citations are relative to a directory rather than to the root: doc path (root-relative, as `include`
42
+ * finds it) to that directory. SSSB maps the app guide `@sssb/kit` ships, `packages/kit/src/guide.md`, to
43
+ * `apps/starter`; an adopter maps its copy, `.claude/sssb-guide.md`, to its own app. Every citation in such a doc
44
+ * is joined onto the directory before it is resolved, and the reference-app rule then applies to the result.
45
+ * Optional, default none. A doc is gated only if `include` reaches it; this says only how to read it.
46
+ */
47
+ relativeTo?: Record<string, string>
48
+ }
49
+
50
+ /** One path a doc cites. */
51
+ export interface Citation {
52
+ /** The path as the gate reads it: globs and `<metavariables>` truncated to their static prefix. */
53
+ path: string
54
+ /**
55
+ * The full backticked span the path was read out of, which for a command citation is the whole command and can
56
+ * be SHARED by several citations. `generalizeAppCitations` is the only sanctioned way to rewrite on it.
57
+ */
58
+ raw: string
59
+ line: number
60
+ }
61
+
62
+ /**
63
+ * Reads `sssb.docPaths` from `<root>/package.json` and validates its shape. Throws an `Error` naming the key when
64
+ * the block is absent or malformed.
65
+ */
66
+ export declare function readDocPathsConfig(root: string): DocPathsConfig
67
+
68
+ /**
69
+ * Every gated markdown file, as root-relative forward-slash paths in a stable (sorted) order. Resolved against
70
+ * `root`, never the process's working directory. An `include` entry that does not exist is skipped: an adopter may
71
+ * have no `.claude/`.
72
+ */
73
+ export declare function docFiles(root: string, config: DocPathsConfig): string[]
74
+
75
+ /** The path citations in a markdown text, one per path token inside each backticked span. */
76
+ export declare function citationsIn(text: string, config: DocPathsConfig): Citation[]
77
+
78
+ /**
79
+ * `citationsIn` over a file; `file` is resolved against `root`. When `relativeTo` maps the file to a directory, each
80
+ * citation's `path` is joined onto that directory (its `raw` span is unchanged).
81
+ */
82
+ export declare function citedPaths(file: string, config: DocPathsConfig, root: string): Citation[]
83
+
84
+ /**
85
+ * Whether a cited path resolves under `root`. A directory citation must resolve outright; a FILE citation may also
86
+ * pass on its parent directory existing, because a doc may legitimately name a file you are meant to create. A
87
+ * citation under a reference app that is not in the tree (no `apps/<app>/package.json`) resolves, because it names
88
+ * the template's own app and is not the adopter's to fix.
89
+ */
90
+ export declare function resolves(path: string, root: string, config: DocPathsConfig): boolean
91
+
92
+ /**
93
+ * Generalizes every citation of an `apps/<name>/` path that `isMissing` reports as gone into `apps/<app>/...`,
94
+ * which the gate reads as asserting only that `apps/` exists. A span carrying several citations is rewritten once.
95
+ */
96
+ export declare function generalizeAppCitations(
97
+ text: string,
98
+ isMissing: (path: string) => boolean,
99
+ config: DocPathsConfig,
100
+ ): string
101
+
102
+ /** Every broken citation under `root`, as `<file>:<line> cites \`<path>\``. */
103
+ export declare function docPathProblems(root: string, config: DocPathsConfig): string[]
104
+
105
+ /** The `include` entries that name nothing in the tree; `docPathProblems` and `sssb check-doc-paths` fail on each. */
106
+ export declare function missingIncludes(root: string, config: DocPathsConfig): string[]