@nifrajs/cli 5.8.0 → 5.9.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 (248) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/agent-files.d.ts +0 -22
  3. package/dist/agent-files.d.ts.map +1 -1
  4. package/dist/agent-files.js +3 -1
  5. package/dist/agent-files.js.map +1 -1
  6. package/dist/assure-hydration.d.ts.map +1 -1
  7. package/dist/assure-hydration.js +2 -10
  8. package/dist/assure-hydration.js.map +1 -1
  9. package/dist/assure.d.ts.map +1 -1
  10. package/dist/assure.js +3 -3
  11. package/dist/assure.js.map +1 -1
  12. package/dist/check-scan.d.ts +2 -0
  13. package/dist/check-scan.d.ts.map +1 -1
  14. package/dist/check-scan.js +54 -86
  15. package/dist/check-scan.js.map +1 -1
  16. package/dist/check.d.ts +3 -0
  17. package/dist/check.d.ts.map +1 -1
  18. package/dist/check.js +20 -23
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +8 -0
  21. package/dist/cli.d.ts.map +1 -1
  22. package/dist/cli.js +42 -13
  23. package/dist/cli.js.map +1 -1
  24. package/dist/command-catalog.d.ts.map +1 -1
  25. package/dist/command-catalog.js +20 -30
  26. package/dist/command-catalog.js.map +1 -1
  27. package/dist/config-target.js +1 -1
  28. package/dist/config-target.js.map +1 -1
  29. package/dist/db-child.js +3 -10
  30. package/dist/db-child.js.map +1 -1
  31. package/dist/db-config.d.ts +2 -0
  32. package/dist/db-config.d.ts.map +1 -1
  33. package/dist/db-config.js +2 -0
  34. package/dist/db-config.js.map +1 -1
  35. package/dist/doctor.d.ts +14 -3
  36. package/dist/doctor.d.ts.map +1 -1
  37. package/dist/doctor.js +91 -6
  38. package/dist/doctor.js.map +1 -1
  39. package/dist/frontend-guidance.d.ts +19 -0
  40. package/dist/frontend-guidance.d.ts.map +1 -1
  41. package/dist/frontend-guidance.js +267 -23
  42. package/dist/frontend-guidance.js.map +1 -1
  43. package/dist/hand-built-manifest.d.ts.map +1 -1
  44. package/dist/hand-built-manifest.js +1 -1
  45. package/dist/hand-built-manifest.js.map +1 -1
  46. package/dist/internal/control-character.d.ts +3 -0
  47. package/dist/internal/control-character.d.ts.map +1 -0
  48. package/dist/internal/control-character.js +10 -0
  49. package/dist/internal/control-character.js.map +1 -0
  50. package/dist/internal/escape-regexp.d.ts +3 -0
  51. package/dist/internal/escape-regexp.d.ts.map +1 -0
  52. package/dist/internal/escape-regexp.js +5 -0
  53. package/dist/internal/escape-regexp.js.map +1 -0
  54. package/dist/internal/line-at.d.ts +3 -0
  55. package/dist/internal/line-at.d.ts.map +1 -0
  56. package/dist/internal/line-at.js +5 -0
  57. package/dist/internal/line-at.js.map +1 -0
  58. package/dist/internal/nifra-project.d.ts.map +1 -1
  59. package/dist/internal/nifra-project.js +35 -41
  60. package/dist/internal/nifra-project.js.map +1 -1
  61. package/dist/internal/posix-path.d.ts +3 -0
  62. package/dist/internal/posix-path.d.ts.map +1 -0
  63. package/dist/internal/posix-path.js +5 -0
  64. package/dist/internal/posix-path.js.map +1 -0
  65. package/dist/internal/project-specifiers.d.ts.map +1 -1
  66. package/dist/internal/project-specifiers.js +3 -10
  67. package/dist/internal/project-specifiers.js.map +1 -1
  68. package/dist/internal/realpath-or-self.d.ts +3 -0
  69. package/dist/internal/realpath-or-self.d.ts.map +1 -0
  70. package/dist/internal/realpath-or-self.js +11 -0
  71. package/dist/internal/realpath-or-self.js.map +1 -0
  72. package/dist/internal/record.d.ts +3 -0
  73. package/dist/internal/record.d.ts.map +1 -0
  74. package/dist/internal/record.js +5 -0
  75. package/dist/internal/record.js.map +1 -0
  76. package/dist/internal/source-facts.d.ts.map +1 -1
  77. package/dist/internal/source-facts.js +28 -25
  78. package/dist/internal/source-facts.js.map +1 -1
  79. package/dist/introspect.d.ts +0 -22
  80. package/dist/introspect.d.ts.map +1 -1
  81. package/dist/introspect.js +11 -151
  82. package/dist/introspect.js.map +1 -1
  83. package/dist/levels-tool.d.ts +2 -0
  84. package/dist/levels-tool.d.ts.map +1 -1
  85. package/dist/levels-tool.js +54 -64
  86. package/dist/levels-tool.js.map +1 -1
  87. package/dist/load.d.ts +6 -1
  88. package/dist/load.d.ts.map +1 -1
  89. package/dist/load.js.map +1 -1
  90. package/dist/local-cli.d.ts +7 -0
  91. package/dist/local-cli.d.ts.map +1 -1
  92. package/dist/local-cli.js +13 -0
  93. package/dist/local-cli.js.map +1 -1
  94. package/dist/mcp-docs-tools.d.ts +1 -1
  95. package/dist/mcp-docs-tools.d.ts.map +1 -1
  96. package/dist/mcp-docs-tools.js +46 -3
  97. package/dist/mcp-docs-tools.js.map +1 -1
  98. package/dist/mcp-http.d.ts +1 -1
  99. package/dist/mcp-http.js +2 -2
  100. package/dist/mcp-io.d.ts +16 -0
  101. package/dist/mcp-io.d.ts.map +1 -1
  102. package/dist/mcp-io.js +63 -0
  103. package/dist/mcp-io.js.map +1 -1
  104. package/dist/mcp-isolate.d.ts.map +1 -1
  105. package/dist/mcp-isolate.js +2 -1
  106. package/dist/mcp-isolate.js.map +1 -1
  107. package/dist/mcp-project-child.d.ts.map +1 -1
  108. package/dist/mcp-project-child.js +5 -12
  109. package/dist/mcp-project-child.js.map +1 -1
  110. package/dist/mcp-render.d.ts.map +1 -1
  111. package/dist/mcp-render.js +9 -51
  112. package/dist/mcp-render.js.map +1 -1
  113. package/dist/mcp-root.js +1 -1
  114. package/dist/mcp-root.js.map +1 -1
  115. package/dist/mcp-run.d.ts.map +1 -1
  116. package/dist/mcp-run.js +3 -46
  117. package/dist/mcp-run.js.map +1 -1
  118. package/dist/mcp-ws.d.ts.map +1 -1
  119. package/dist/mcp-ws.js +2 -18
  120. package/dist/mcp-ws.js.map +1 -1
  121. package/dist/migrate-layout.d.ts.map +1 -1
  122. package/dist/migrate-layout.js +36 -57
  123. package/dist/migrate-layout.js.map +1 -1
  124. package/dist/output-schemas.d.ts.map +1 -1
  125. package/dist/output-schemas.js +7 -7
  126. package/dist/output-schemas.js.map +1 -1
  127. package/dist/port.d.ts.map +1 -1
  128. package/dist/port.js +1 -2
  129. package/dist/port.js.map +1 -1
  130. package/dist/ppr-read-fix.js +2 -2
  131. package/dist/ppr-read-fix.js.map +1 -1
  132. package/dist/recipes/5.9.0.d.ts +10 -0
  133. package/dist/recipes/5.9.0.d.ts.map +1 -0
  134. package/dist/recipes/5.9.0.js +41 -0
  135. package/dist/recipes/5.9.0.js.map +1 -0
  136. package/dist/recipes/index.d.ts +5 -0
  137. package/dist/recipes/index.d.ts.map +1 -1
  138. package/dist/recipes/index.js +2 -0
  139. package/dist/recipes/index.js.map +1 -1
  140. package/dist/review.d.ts.map +1 -1
  141. package/dist/review.js +9 -13
  142. package/dist/review.js.map +1 -1
  143. package/dist/rules/contract-visibility.d.ts.map +1 -1
  144. package/dist/rules/contract-visibility.js +3 -9
  145. package/dist/rules/contract-visibility.js.map +1 -1
  146. package/dist/rules/data-guard.d.ts.map +1 -1
  147. package/dist/rules/data-guard.js +3 -10
  148. package/dist/rules/data-guard.js.map +1 -1
  149. package/dist/rules/pages.d.ts.map +1 -1
  150. package/dist/rules/pages.js +41 -58
  151. package/dist/rules/pages.js.map +1 -1
  152. package/dist/rules/routes.d.ts.map +1 -1
  153. package/dist/rules/routes.js +20 -27
  154. package/dist/rules/routes.js.map +1 -1
  155. package/dist/rules/security.d.ts.map +1 -1
  156. package/dist/rules/security.js +206 -313
  157. package/dist/rules/security.js.map +1 -1
  158. package/dist/rules/zones.d.ts.map +1 -1
  159. package/dist/rules/zones.js +3 -10
  160. package/dist/rules/zones.js.map +1 -1
  161. package/dist/runtime-differences.d.ts +62 -0
  162. package/dist/runtime-differences.d.ts.map +1 -0
  163. package/dist/runtime-differences.js +222 -0
  164. package/dist/runtime-differences.js.map +1 -0
  165. package/dist/sdk.d.ts.map +1 -1
  166. package/dist/sdk.js +43 -43
  167. package/dist/sdk.js.map +1 -1
  168. package/dist/smoke.d.ts.map +1 -1
  169. package/dist/smoke.js +4 -12
  170. package/dist/smoke.js.map +1 -1
  171. package/dist/source-rewrites.d.ts +27 -0
  172. package/dist/source-rewrites.d.ts.map +1 -0
  173. package/dist/source-rewrites.js +402 -0
  174. package/dist/source-rewrites.js.map +1 -0
  175. package/dist/stylex-migrate.d.ts.map +1 -1
  176. package/dist/stylex-migrate.js +1 -1
  177. package/dist/stylex-migrate.js.map +1 -1
  178. package/dist/symptom-search.d.ts +5 -0
  179. package/dist/symptom-search.d.ts.map +1 -0
  180. package/dist/symptom-search.js +21 -0
  181. package/dist/symptom-search.js.map +1 -0
  182. package/dist/upgrade.d.ts +28 -3
  183. package/dist/upgrade.d.ts.map +1 -1
  184. package/dist/upgrade.js +153 -64
  185. package/dist/upgrade.js.map +1 -1
  186. package/dist/verification-plan.d.ts.map +1 -1
  187. package/dist/verification-plan.js +5 -3
  188. package/dist/verification-plan.js.map +1 -1
  189. package/docs/examples.json +32 -2
  190. package/docs/llms-full.txt +749 -95
  191. package/docs/types.json +300 -61
  192. package/package.json +11 -11
  193. package/src/agent-files.ts +4 -1
  194. package/src/assure-hydration.ts +2 -9
  195. package/src/assure.ts +3 -4
  196. package/src/check-scan.ts +65 -82
  197. package/src/check.ts +25 -23
  198. package/src/cli.ts +61 -13
  199. package/src/command-catalog.ts +22 -32
  200. package/src/config-target.ts +1 -1
  201. package/src/db-child.ts +3 -10
  202. package/src/db-config.ts +4 -0
  203. package/src/doctor.ts +128 -12
  204. package/src/frontend-guidance.ts +344 -25
  205. package/src/hand-built-manifest.ts +1 -2
  206. package/src/internal/control-character.ts +8 -0
  207. package/src/internal/escape-regexp.ts +4 -0
  208. package/src/internal/line-at.ts +4 -0
  209. package/src/internal/nifra-project.ts +39 -35
  210. package/src/internal/posix-path.ts +4 -0
  211. package/src/internal/project-specifiers.ts +3 -10
  212. package/src/internal/realpath-or-self.ts +10 -0
  213. package/src/internal/record.ts +4 -0
  214. package/src/internal/source-facts.ts +39 -29
  215. package/src/introspect.ts +16 -156
  216. package/src/levels-tool.ts +71 -78
  217. package/src/load.ts +6 -1
  218. package/src/local-cli.ts +12 -0
  219. package/src/mcp-docs-tools.ts +51 -3
  220. package/src/mcp-http.ts +2 -2
  221. package/src/mcp-io.ts +77 -0
  222. package/src/mcp-isolate.ts +2 -3
  223. package/src/mcp-project-child.ts +5 -14
  224. package/src/mcp-render.ts +11 -59
  225. package/src/mcp-root.ts +1 -1
  226. package/src/mcp-run.ts +5 -54
  227. package/src/mcp-ws.ts +2 -19
  228. package/src/migrate-layout.ts +52 -72
  229. package/src/output-schemas.ts +7 -8
  230. package/src/port.ts +1 -4
  231. package/src/ppr-read-fix.ts +2 -2
  232. package/src/recipes/5.9.0.ts +42 -0
  233. package/src/recipes/index.ts +7 -0
  234. package/src/review.ts +12 -15
  235. package/src/rules/contract-visibility.ts +3 -8
  236. package/src/rules/data-guard.ts +3 -10
  237. package/src/rules/pages.ts +47 -58
  238. package/src/rules/routes.ts +21 -27
  239. package/src/rules/security.ts +224 -255
  240. package/src/rules/zones.ts +3 -10
  241. package/src/runtime-differences.ts +302 -0
  242. package/src/sdk.ts +55 -58
  243. package/src/smoke.ts +4 -13
  244. package/src/source-rewrites.ts +463 -0
  245. package/src/stylex-migrate.ts +1 -3
  246. package/src/symptom-search.ts +27 -0
  247. package/src/upgrade.ts +194 -74
  248. package/src/verification-plan.ts +10 -4
@@ -35,7 +35,7 @@ export function writeConfigTarget(appRoot: string, target: string): string | und
35
35
  const previous = found?.[2]
36
36
  let next: string
37
37
  if (found === null) {
38
- next = `${text.replace(/\n*$/, "\n")}\n// The deploy target \`nifra build\` emits; \`nifra target <t>\` switches it.\nexport const target = "${target}"\n`
38
+ next = `${text.replace(/(?<!\n)\n*$/, "\n")}\n// The deploy target \`nifra build\` emits; \`nifra target <t>\` switches it.\nexport const target = "${target}"\n`
39
39
  } else {
40
40
  // Only the quoted value changes, so a type annotation on the export survives.
41
41
  const end = found.index + found[0].length
package/src/db-child.ts CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  import { createDevFeed } from "@nifrajs/web/dev-feed"
35
35
  import { isSensitiveFieldName } from "@nifrajs/web/zones"
36
36
  import { type DevDatabase, loadDevDatabase } from "./db-config.ts"
37
- import { CHILD_INPUT_MAX_BYTES, readBoundedStream } from "./mcp-io.ts"
37
+ import { CHILD_INPUT_MAX_BYTES, protocolStdout, readBoundedStream } from "./mcp-io.ts"
38
38
 
39
39
  /** The one operation a subprocess runs. */
40
40
  export interface DbChildRequest {
@@ -154,7 +154,7 @@ async function runPostgres(
154
154
  return isDbRefusal(schema) ? schema : { ...base, schema }
155
155
  }
156
156
  if (request.op === "role") {
157
- const role = await postgresRoleSql(client, db)
157
+ const role = await postgresRoleSql(client, { ...db, redaction })
158
158
  if (isDbRefusal(role)) return role
159
159
  return {
160
160
  ...base,
@@ -267,14 +267,7 @@ export async function serveDbChild(
267
267
  }
268
268
 
269
269
  if (import.meta.main) {
270
- // Bound before the config loads, so nothing it patches can reach the protocol channel.
271
- const stdout = process.stdout.write.bind(process.stdout)
272
- const toStderr = (...args: unknown[]): void => {
273
- process.stderr.write(`${args.map((arg) => String(arg)).join(" ")}\n`)
274
- }
275
- console.log = toStderr
276
- console.info = toStderr
277
- console.debug = toStderr
270
+ const stdout = protocolStdout()
278
271
  const served = await serveDbChild(
279
272
  process.argv[2] ?? process.cwd(),
280
273
  Bun.stdin.stream(),
package/src/db-config.ts CHANGED
@@ -49,6 +49,8 @@ export interface DevPostgresDatabase extends DevDatabaseCommon {
49
49
  readonly allowHosts: readonly string[]
50
50
  /** Extensions or untrusted languages the role may use without the query being refused. */
51
51
  readonly allowExtensions: readonly string[]
52
+ /** Functions (`name` or `schema.name`) a query may call although the function allowlist refuses them. */
53
+ readonly allowFunctions: readonly string[]
52
54
  /** Schemas a query may read (default `["public"]`). */
53
55
  readonly schemas: readonly string[]
54
56
  }
@@ -71,6 +73,7 @@ const POSTGRES_FIELDS = new Set<string>([
71
73
  "url",
72
74
  "allowHosts",
73
75
  "allowExtensions",
76
+ "allowFunctions",
74
77
  "schemas",
75
78
  ])
76
79
 
@@ -173,6 +176,7 @@ export function parseDevDatabase(value: unknown): DevDatabase | DbRefusal {
173
176
  url,
174
177
  allowHosts: strings(fields, "allowHosts"),
175
178
  allowExtensions: strings(fields, "allowExtensions"),
179
+ allowFunctions: strings(fields, "allowFunctions"),
176
180
  schemas: fields("schemas") === undefined ? ["public"] : strings(fields, "schemas"),
177
181
  }
178
182
  } catch (error) {
package/src/doctor.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  import { collectStaleMcpPins, type StaleMcpPin } from "./init-agents.ts"
41
41
  import { codeUnitOrder } from "./internal/code-unit-order.ts"
42
42
  import { createSpecifierResolver } from "./internal/project-specifiers.ts"
43
+ import { isRecord } from "./internal/record.ts"
43
44
  import {
44
45
  bunLockDir,
45
46
  type StaleLinkLock,
@@ -226,11 +227,22 @@ export interface DoctorResult {
226
227
  /**
227
228
  * Route files that export `keepAlive` in an app where nothing names its sign-in cookie: no
228
229
  * `identityCookies`, `rotateIdentityEpoch()` or `identityChanged()`, and either no `@nifrajs/auth`,
229
- * Better Auth or Auth.js dependency or a source file (`renamedIn`) that gives the session cookie a
230
- * name of its own. A sign-out there may leave the previous visitor's kept pages. Advisory (never
231
- * folded into `ok`).
230
+ * Better Auth or Auth.js dependency or a source file (`renamedIn`: the app's, or one in a wrapper
231
+ * package the app owns) that gives the session cookie a name of its own. A sign-out there may
232
+ * leave the previous visitor's kept pages. Advisory (never folded into `ok`).
232
233
  */
233
234
  readonly keepAliveIdentity?: { readonly routes: readonly string[]; readonly renamedIn?: string }
235
+ /**
236
+ * Route files that export `keepAlive` in an app that reaches a known auth library only through a
237
+ * package of its own, such as a workspace wrapper (`via`, from the app's dependency down). The
238
+ * runtime still recognizes that library's session cookie by its default name or, for Better Auth,
239
+ * by the `<prefix>.session_token` suffix, so this is information, not a warning.
240
+ */
241
+ readonly keepAliveIdentityCovered?: {
242
+ readonly routes: readonly string[]
243
+ readonly package: string
244
+ readonly via: readonly string[]
245
+ }
234
246
  /** Static production-readiness evidence for the selected deploy target. */
235
247
  readonly readiness?: DoctorReadiness
236
248
  /** The explicit source boundary used by the dependency scan. */
@@ -318,9 +330,6 @@ const depNames = (pkg: Record<string, unknown>, field: string): string[] => {
318
330
  : []
319
331
  }
320
332
 
321
- const isRecord = (value: unknown): value is Record<string, unknown> =>
322
- typeof value === "object" && value !== null && !Array.isArray(value)
323
-
324
333
  const MAX_WORKSPACE_IMPORTERS = 2_048
325
334
  function workspacePatterns(pkg: Record<string, unknown>): string[] {
326
335
  const raw = pkg.workspaces
@@ -879,6 +888,97 @@ const IDENTITY_SIGNAL = /\b(?:identityCookies\s*:|rotateIdentityEpoch\s*\(|ident
879
888
  const RENAMED_SESSION =
880
889
  /\b(?:session_token|sessionToken)\s*:\s*\{[^}]*\bname\s*:|\bcookieName\s*:\s*["'`]/
881
890
 
891
+ // Below the app itself, only what a package loads at runtime is followed.
892
+ const AUTH_RUNTIME_FIELDS = ["dependencies", "peerDependencies", "optionalDependencies"] as const
893
+ // Bounds the walk over a large install; a wrapper sits a step or two from the app.
894
+ const MAX_AUTH_WALK = 2000
895
+
896
+ /**
897
+ * The known auth package nearest the app among the packages it depends on, followed through the
898
+ * installed and linked graph (real paths, so a workspace package and its own install count once),
899
+ * with the dependency chain that reaches it. The app's own dependencies are checked by the caller.
900
+ * A package declared but not installed - an unmet peer or optional dependency - is not reached.
901
+ * `renamedIn` is the first file of a source package on that chain outside the app's tree (a workspace
902
+ * sibling, a `file:` or `link:` package) that renames the session cookie: the app's own scan never
903
+ * reads it.
904
+ */
905
+ async function reachableAuthPackage(
906
+ cwd: string,
907
+ pkg: Record<string, unknown>,
908
+ ): Promise<
909
+ | {
910
+ readonly package: string
911
+ readonly via: readonly string[]
912
+ readonly renamedIn: string | undefined
913
+ }
914
+ | undefined
915
+ > {
916
+ let root: string
917
+ try {
918
+ root = await realpath(cwd)
919
+ } catch {
920
+ root = resolve(cwd)
921
+ }
922
+ const visited = new Set<string>([root])
923
+ const queue: {
924
+ readonly dir: string
925
+ readonly via: readonly string[]
926
+ readonly dirs: readonly string[]
927
+ readonly pkg: Record<string, unknown>
928
+ }[] = [{ dir: root, via: [], dirs: [], pkg }]
929
+ for (let next = 0; next < queue.length && visited.size < MAX_AUTH_WALK; next++) {
930
+ const current = queue[next]
931
+ if (current === undefined) break
932
+ const names = new Set<string>()
933
+ for (const field of next === 0 ? DEPENDENCY_FIELDS : AUTH_RUNTIME_FIELDS) {
934
+ for (const name of Object.keys(depRecord(current.pkg, field) ?? {})) names.add(name)
935
+ }
936
+ for (const name of [...names].sort(codeUnitOrder)) {
937
+ const path = resolvePackageFrom(current.dir, name)
938
+ if (path === undefined) continue
939
+ if (next > 0 && KNOWN_AUTH_PACKAGES.includes(name)) {
940
+ const renamedIn = await renamedInSources(root, current.dirs)
941
+ return { package: name, via: current.via, renamedIn }
942
+ }
943
+ if (visited.has(path)) continue
944
+ visited.add(path)
945
+ const meta = await readJson(join(path, "package.json"))
946
+ if (meta !== undefined) {
947
+ queue.push({
948
+ dir: path,
949
+ via: [...current.via, name],
950
+ dirs: [...current.dirs, path],
951
+ pkg: meta,
952
+ })
953
+ }
954
+ }
955
+ }
956
+ return undefined
957
+ }
958
+
959
+ async function renamedInSources(
960
+ root: string,
961
+ dirs: readonly string[],
962
+ ): Promise<string | undefined> {
963
+ for (const resolved of dirs) {
964
+ // root is a realpath; a resolved dir can still hold a Windows 8.3 name such as RUNNER~1.
965
+ const dir = await realpath(resolved).catch(() => resolved)
966
+ if (dir.startsWith(root + sep) || dir.split(sep).includes("node_modules")) continue
967
+ let found: string | undefined
968
+ await walkSource(
969
+ dir,
970
+ (rel, content) => {
971
+ if (found === undefined && RENAMED_SESSION.test(content)) {
972
+ found = displayPath(root, join(dir, rel))
973
+ }
974
+ },
975
+ { scripts: true, library: true },
976
+ )
977
+ if (found !== undefined) return found
978
+ }
979
+ return undefined
980
+ }
981
+
882
982
  function keepAliveRoutes(cwd: string): readonly string[] {
883
983
  const routesDir = join(cwd, "routes")
884
984
  if (!existsSync(routesDir)) return []
@@ -958,15 +1058,24 @@ export async function collectDoctorResult(
958
1058
  const lockDir = bunLockDir(cwd)
959
1059
  const linkLocks = lockDir === undefined ? [] : staleLinkLocks(lockDir)
960
1060
  const handBuilt = handBuiltManifests(cwd, manifestLists)
961
- const knownAuth = KNOWN_AUTH_PACKAGES.some((name) => dependencySpec(pkg, name) !== undefined)
962
- const unnamedIdentity =
963
- identitySignal || (knownAuth && renamedIn === undefined) ? [] : keepAliveRoutes(cwd)
1061
+ const directAuth = KNOWN_AUTH_PACKAGES.some((name) => dependencySpec(pkg, name) !== undefined)
1062
+ const keptRoutes =
1063
+ identitySignal || (directAuth && renamedIn === undefined) ? [] : keepAliveRoutes(cwd)
1064
+ // A wrapper package the app owns may be what brings the auth library in.
1065
+ const reachedAuth =
1066
+ keptRoutes.length === 0 || directAuth ? undefined : await reachableAuthPackage(cwd, pkg)
1067
+ renamedIn ??= reachedAuth?.renamedIn
1068
+ const knownAuth = directAuth || reachedAuth !== undefined
964
1069
  const keepAliveIdentity =
965
- unnamedIdentity.length === 0
1070
+ keptRoutes.length === 0 || (reachedAuth !== undefined && renamedIn === undefined)
966
1071
  ? undefined
967
1072
  : knownAuth && renamedIn !== undefined
968
- ? { routes: unnamedIdentity, renamedIn }
969
- : { routes: unnamedIdentity }
1073
+ ? { routes: keptRoutes, renamedIn }
1074
+ : { routes: keptRoutes }
1075
+ const keepAliveIdentityCovered =
1076
+ reachedAuth !== undefined && renamedIn === undefined
1077
+ ? { routes: keptRoutes, package: reachedAuth.package, via: reachedAuth.via }
1078
+ : undefined
970
1079
  // `staleDists`, `toolingDrift` and `staleMcpPins` are advisory (see DoctorResult): they never fail `ok`.
971
1080
  return {
972
1081
  ok:
@@ -987,6 +1096,7 @@ export async function collectDoctorResult(
987
1096
  ...(versionDrift !== undefined ? { versionDrift } : {}),
988
1097
  ...(handBuilt.length > 0 ? { handBuiltManifests: handBuilt } : {}),
989
1098
  ...(keepAliveIdentity !== undefined ? { keepAliveIdentity } : {}),
1099
+ ...(keepAliveIdentityCovered !== undefined ? { keepAliveIdentityCovered } : {}),
990
1100
  ...(staleMcpPins !== undefined && staleMcpPins.files.length > 0 ? { staleMcpPins } : {}),
991
1101
  ...(lockDir !== undefined && linkLocks.length > 0
992
1102
  ? {
@@ -1203,6 +1313,12 @@ export function doctorReport(result: DoctorResult, cliVersion?: string): string[
1203
1313
  " fix: name the session cookie in keepAlive.identityCookies - exported from backend/framework.ts, or passed to createWebApp in a server you write - or call identityChanged() from @nifrajs/web/client for token auth - /docs/keep-alive#sign-in\n",
1204
1314
  )
1205
1315
  }
1316
+ if (result.keepAliveIdentityCovered !== undefined) {
1317
+ const { routes, package: library, via } = result.keepAliveIdentityCovered
1318
+ lines.push(
1319
+ `ℹ ${routes.join(", ")} keep pages alive, and this app reaches ${library} through ${via.join(" > ")}: nifra knows its session cookie by the default name${library === "better-auth" ? " or the <prefix>.session_token suffix" : ""}, so a sign-out drops the kept pages unless that package renames the cookie outright (then name it in keepAlive.identityCookies)\n`,
1320
+ )
1321
+ }
1206
1322
  // Advisory: the agent's MCP server is launched from these pins, so a stale one answers for an old
1207
1323
  // release even when the CLI running doctor matches the project.
1208
1324
  if (result.staleMcpPins !== undefined) {