@nifrajs/cli 5.8.0 → 5.10.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 +191 -0
- package/dist/agent-files.d.ts +0 -22
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +3 -1
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +2 -10
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +3 -3
- package/dist/assure.js.map +1 -1
- package/dist/check-diagnostics.d.ts +1 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +3 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +62 -87
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +27 -25
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -20
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +1 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -49
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.js +1 -1
- package/dist/config-target.js.map +1 -1
- package/dist/db-child.js +3 -10
- package/dist/db-child.js.map +1 -1
- package/dist/db-config.d.ts +2 -0
- package/dist/db-config.d.ts.map +1 -1
- package/dist/db-config.js +2 -0
- package/dist/db-config.js.map +1 -1
- package/dist/doctor.d.ts +14 -3
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +91 -6
- package/dist/doctor.js.map +1 -1
- package/dist/frontend-guidance.d.ts +19 -0
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +267 -23
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/hand-built-manifest.d.ts.map +1 -1
- package/dist/hand-built-manifest.js +1 -1
- package/dist/hand-built-manifest.js.map +1 -1
- package/dist/internal/control-character.d.ts +3 -0
- package/dist/internal/control-character.d.ts.map +1 -0
- package/dist/internal/control-character.js +10 -0
- package/dist/internal/control-character.js.map +1 -0
- package/dist/internal/escape-regexp.d.ts +3 -0
- package/dist/internal/escape-regexp.d.ts.map +1 -0
- package/dist/internal/escape-regexp.js +5 -0
- package/dist/internal/escape-regexp.js.map +1 -0
- package/dist/internal/line-at.d.ts +3 -0
- package/dist/internal/line-at.d.ts.map +1 -0
- package/dist/internal/line-at.js +5 -0
- package/dist/internal/line-at.js.map +1 -0
- package/dist/internal/nifra-project.d.ts.map +1 -1
- package/dist/internal/nifra-project.js +35 -41
- package/dist/internal/nifra-project.js.map +1 -1
- package/dist/internal/posix-path.d.ts +3 -0
- package/dist/internal/posix-path.d.ts.map +1 -0
- package/dist/internal/posix-path.js +5 -0
- package/dist/internal/posix-path.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +3 -10
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/realpath-or-self.d.ts +3 -0
- package/dist/internal/realpath-or-self.d.ts.map +1 -0
- package/dist/internal/realpath-or-self.js +11 -0
- package/dist/internal/realpath-or-self.js.map +1 -0
- package/dist/internal/record.d.ts +3 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/record.js +5 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/internal/source-facts.d.ts +30 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +155 -25
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.d.ts +0 -22
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +11 -151
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts +2 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +54 -64
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +8 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +5 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +7 -0
- package/dist/local-cli.d.ts.map +1 -1
- package/dist/local-cli.js +13 -0
- package/dist/local-cli.js.map +1 -1
- package/dist/mcp-docs-tools.d.ts +1 -1
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +46 -3
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-http.js +2 -2
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +16 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +63 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.d.ts.map +1 -1
- package/dist/mcp-project-child.js +5 -12
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +9 -51
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +3 -46
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts.map +1 -1
- package/dist/mcp-tool-meta.js +0 -1
- package/dist/mcp-tool-meta.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +2 -18
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +36 -57
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +7 -7
- package/dist/output-schemas.js.map +1 -1
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +1 -2
- package/dist/port.js.map +1 -1
- package/dist/ppr-read-fix.js +2 -2
- package/dist/ppr-read-fix.js.map +1 -1
- package/dist/recipes/5.10.0.d.ts +12 -0
- package/dist/recipes/5.10.0.d.ts.map +1 -0
- package/dist/recipes/5.10.0.js +44 -0
- package/dist/recipes/5.10.0.js.map +1 -0
- package/dist/recipes/5.9.0.d.ts +10 -0
- package/dist/recipes/5.9.0.d.ts.map +1 -0
- package/dist/recipes/5.9.0.js +41 -0
- package/dist/recipes/5.9.0.js.map +1 -0
- package/dist/recipes/index.d.ts +5 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +12 -13
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +3 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +3 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +3 -9
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +3 -10
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +15 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/internal-links.d.ts +5 -0
- package/dist/rules/internal-links.d.ts.map +1 -0
- package/dist/rules/internal-links.js +418 -0
- package/dist/rules/internal-links.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +20 -0
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +41 -58
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +20 -27
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +206 -313
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/server-fn-namespace.d.ts +8 -0
- package/dist/rules/server-fn-namespace.d.ts.map +1 -0
- package/dist/rules/server-fn-namespace.js +43 -0
- package/dist/rules/server-fn-namespace.js.map +1 -0
- package/dist/rules/source-scan.d.ts +29 -0
- package/dist/rules/source-scan.d.ts.map +1 -0
- package/dist/rules/source-scan.js +38 -0
- package/dist/rules/source-scan.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -1
- package/dist/rules/text-slot-boolean.js +21 -43
- package/dist/rules/text-slot-boolean.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -10
- package/dist/rules/zones.js.map +1 -1
- package/dist/runtime-differences.d.ts +62 -0
- package/dist/runtime-differences.d.ts.map +1 -0
- package/dist/runtime-differences.js +222 -0
- package/dist/runtime-differences.js.map +1 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +43 -43
- package/dist/sdk.js.map +1 -1
- package/dist/smoke.d.ts.map +1 -1
- package/dist/smoke.js +4 -12
- package/dist/smoke.js.map +1 -1
- package/dist/source-rewrites.d.ts +27 -0
- package/dist/source-rewrites.d.ts.map +1 -0
- package/dist/source-rewrites.js +517 -0
- package/dist/source-rewrites.js.map +1 -0
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +1 -1
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/symptom-search.d.ts +5 -0
- package/dist/symptom-search.d.ts.map +1 -0
- package/dist/symptom-search.js +21 -0
- package/dist/symptom-search.js.map +1 -0
- package/dist/typecheck-coverage.d.ts +9 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +16 -0
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +28 -3
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +153 -64
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +5 -3
- package/dist/verification-plan.js.map +1 -1
- package/docs/examples.json +51 -9
- package/docs/llms-full.txt +1296 -287
- package/docs/types.json +854 -170
- package/package.json +11 -11
- package/src/agent-files.ts +4 -1
- package/src/assure-hydration.ts +2 -9
- package/src/assure.ts +3 -4
- package/src/check-diagnostics.ts +5 -0
- package/src/check-scan.ts +74 -83
- package/src/check.ts +40 -26
- package/src/cli.ts +76 -20
- package/src/command-catalog.ts +22 -56
- package/src/config-target.ts +1 -1
- package/src/db-child.ts +3 -10
- package/src/db-config.ts +4 -0
- package/src/doctor.ts +128 -12
- package/src/frontend-guidance.ts +344 -25
- package/src/hand-built-manifest.ts +1 -2
- package/src/internal/control-character.ts +8 -0
- package/src/internal/escape-regexp.ts +4 -0
- package/src/internal/line-at.ts +4 -0
- package/src/internal/nifra-project.ts +39 -35
- package/src/internal/posix-path.ts +4 -0
- package/src/internal/project-specifiers.ts +3 -10
- package/src/internal/realpath-or-self.ts +10 -0
- package/src/internal/record.ts +4 -0
- package/src/internal/source-facts.ts +194 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +15 -1
- package/src/local-cli.ts +12 -0
- package/src/mcp-docs-tools.ts +51 -3
- package/src/mcp-http.ts +2 -2
- package/src/mcp-io.ts +77 -0
- package/src/mcp-isolate.ts +2 -3
- package/src/mcp-project-child.ts +5 -14
- package/src/mcp-render.ts +11 -59
- package/src/mcp-root.ts +1 -1
- package/src/mcp-run.ts +5 -54
- package/src/mcp-tool-meta.ts +0 -1
- package/src/mcp-ws.ts +2 -19
- package/src/migrate-layout.ts +52 -72
- package/src/output-schemas.ts +7 -8
- package/src/port.ts +1 -4
- package/src/ppr-read-fix.ts +2 -2
- package/src/recipes/5.10.0.ts +45 -0
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +15 -15
- package/src/rules/codes.ts +3 -0
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/explanations.ts +15 -0
- package/src/rules/internal-links.ts +490 -0
- package/src/rules/legacy.ts +21 -0
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- package/src/rules/server-fn-namespace.ts +47 -0
- package/src/rules/source-scan.ts +66 -0
- package/src/rules/text-slot-boolean.ts +26 -42
- package/src/rules/zones.ts +3 -10
- package/src/runtime-differences.ts +302 -0
- package/src/sdk.ts +55 -58
- package/src/smoke.ts +4 -13
- package/src/source-rewrites.ts +592 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/typecheck-coverage.ts +23 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
- package/dist/sync-routes.d.ts +0 -29
- package/dist/sync-routes.d.ts.map +0 -1
- package/dist/sync-routes.js +0 -56
- package/dist/sync-routes.js.map +0 -1
- package/src/sync-routes.ts +0 -70
package/src/cli.ts
CHANGED
|
@@ -159,6 +159,8 @@ Usage:
|
|
|
159
159
|
_routes.json. The server entry is generated from your
|
|
160
160
|
backend/framework.ts (adapter) + backend/app.ts + routes/.
|
|
161
161
|
--report prints a per-chunk size + gzip table (biggest first).
|
|
162
|
+
Vercel defaults to Edge; export vercelRuntime = "node" from
|
|
163
|
+
nifra.config.ts for ordinary Node.js 22 serverless SSR.
|
|
162
164
|
[--vite | --bun] Force the bundler. Without a flag it follows your config: Bun
|
|
163
165
|
(faster, Bun-native) unless your ONLY transforms are
|
|
164
166
|
\`vitePlugins\`, which the Bun build cannot run - then Vite,
|
|
@@ -215,10 +217,15 @@ Usage:
|
|
|
215
217
|
nifra_explain (structured errors), nifra_inspect (request
|
|
216
218
|
traces), nifra_learn (guided build path).
|
|
217
219
|
nifra docs-mcp [--port <n>] Serve the PUBLIC docs MCP over HTTP (nifra_docs, nifra_example,
|
|
218
|
-
nifra_types, nifra_learn, nifra_frontend, nifra_gallery) -
|
|
220
|
+
nifra_types, nifra_learn, nifra_frontend, nifra_runtime, nifra_gallery) -
|
|
219
221
|
self-host on a VPS so any remote agent can learn nifra. Default :8787.
|
|
220
222
|
nifra learn [<step>] Print the guided build-an-app path (the human view of nifra_learn):
|
|
221
223
|
no arg for the step index, a number for one step's goal/do/verify.
|
|
224
|
+
nifra frontend [<adapter>] [<symptom>] [--json]
|
|
225
|
+
Print the frontend gotcha catalog (the human view of nifra_frontend).
|
|
226
|
+
nifra runtime [<runtime>] [<symptom>] [--json]
|
|
227
|
+
Print where Bun, Node, Deno and Workers differ (the human view of
|
|
228
|
+
nifra_runtime): cause, fix and how to verify, with measured versions.
|
|
222
229
|
nifra check [--json] [--sarif] [--lints-only]
|
|
223
230
|
Gate: typecheck + lints (hand-rolled fetch(), untyped client("…"),
|
|
224
231
|
backend code in browser code). Run as "done"; --json for agents;
|
|
@@ -233,9 +240,6 @@ Usage:
|
|
|
233
240
|
nifra sync-manifest Regenerate a committed web server-manifest.ts from routes/ WITHOUT
|
|
234
241
|
a full build - clears server-manifest drift after a route add/rename
|
|
235
242
|
(a new hydrating component still needs a full build).
|
|
236
|
-
nifra sync-routes Regenerate nifra-routes.d.ts from routes/ so navigate({ to, search })
|
|
237
|
-
is typed against each static route's searchSchema (a stale shape is a
|
|
238
|
-
tsc error). Include the file in your tsconfig. Pure file write.
|
|
239
243
|
nifra snapshot [--out <file>] Write the backend's API contract (routes + schemas) as plain
|
|
240
244
|
JSON - the baseline for \`nifra diff\`. Default api-snapshot.json.
|
|
241
245
|
nifra diff [<baseline>] [--json] Breaking-change gate: re-snapshot the contract and compare
|
|
@@ -305,14 +309,15 @@ Usage:
|
|
|
305
309
|
(--zones keeps them in place and lists them in package.json
|
|
306
310
|
"nifra.zones"). Dry-run by default; --write applies.
|
|
307
311
|
nifra scaffold hole <route> <name> [--shared] [--interactive] [--timeout <ms>] [--server] [--json]
|
|
308
|
-
|
|
312
|
+
Add a partially prerendered hole to a route whose
|
|
309
313
|
backend half exports shellLoader - its definition and <Hole> in
|
|
310
314
|
the page, its loader and output schema in the backend half. A
|
|
311
315
|
Vue or Svelte page gets the code to paste; --server writes a
|
|
312
316
|
React server component for the hole.
|
|
313
317
|
nifra types [--check] [--json] Generate each route's ./+types module under .nifra/types: its
|
|
314
318
|
params, the data its output schemas let through, and api typed
|
|
315
|
-
by backend/app.ts
|
|
319
|
+
by backend/app.ts, plus routes.d.ts, the table href() checks
|
|
320
|
+
links against. dev, build and check refresh them too;
|
|
316
321
|
--check fails when one is stale.
|
|
317
322
|
nifra schemas [--write] [--check] [--json]
|
|
318
323
|
Draft loaderOutput/actionOutput from each loader's and
|
|
@@ -349,7 +354,7 @@ set in the process environment is never overwritten by a file.
|
|
|
349
354
|
${renderCommandCatalogHelp()}`
|
|
350
355
|
|
|
351
356
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
352
|
-
const CLI_VERSION = "5.
|
|
357
|
+
const CLI_VERSION = "5.10.0"
|
|
353
358
|
|
|
354
359
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
355
360
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -825,7 +830,9 @@ async function buildForTarget(
|
|
|
825
830
|
flag: string | undefined,
|
|
826
831
|
flags: Flags,
|
|
827
832
|
): Promise<void> {
|
|
828
|
-
const { parseBuildTarget, renderSizeReport } = await import(
|
|
833
|
+
const { parseBuildTarget, renderSizeReport, validateVercelRuntime } = await import(
|
|
834
|
+
"@nifrajs/web/build"
|
|
835
|
+
)
|
|
829
836
|
const target = parseBuildTarget(
|
|
830
837
|
flag ?? app.framework.target ?? "bun",
|
|
831
838
|
flag === undefined ? "target in nifra.config.ts" : "--target",
|
|
@@ -834,7 +841,13 @@ async function buildForTarget(
|
|
|
834
841
|
throw new Error("[nifra] `nifra build` takes `--vite` or `--bun`, not both.")
|
|
835
842
|
}
|
|
836
843
|
const { framework: fw } = app
|
|
844
|
+
validateVercelRuntime(target, fw.vercelRuntime)
|
|
837
845
|
if (fw.componentPipeline !== undefined) {
|
|
846
|
+
// The component pipeline already owns its Vercel Node handler; this selector is ordinary SSR only.
|
|
847
|
+
if (fw.vercelRuntime !== undefined)
|
|
848
|
+
throw new Error(
|
|
849
|
+
"[nifra/components] vercelRuntime selects ordinary SSR only; omit it for the component pipeline",
|
|
850
|
+
)
|
|
838
851
|
if (flags.bun)
|
|
839
852
|
throw new Error(
|
|
840
853
|
"[nifra/components] Components require the Vite 8 pipeline; Bun remains a server runtime",
|
|
@@ -949,6 +962,8 @@ async function buildForTarget(
|
|
|
949
962
|
...(fw.cssCodeSplit !== undefined ? { cssCodeSplit: fw.cssCodeSplit } : {}),
|
|
950
963
|
...(fw.cssLoading !== undefined ? { cssLoading: fw.cssLoading } : {}),
|
|
951
964
|
...(fw.clientIp !== undefined ? { clientIp: fw.clientIp } : {}),
|
|
965
|
+
...(fw.vercelRuntime !== undefined ? { vercelRuntime: fw.vercelRuntime } : {}),
|
|
966
|
+
...(fw.selfHost !== undefined ? { selfHost: fw.selfHost } : {}),
|
|
952
967
|
live: fw.live?.clientEntry,
|
|
953
968
|
// Prerendering drives a built app: the static target is made of its pages, and a bun or node server
|
|
954
969
|
// answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
|
|
@@ -1144,7 +1159,6 @@ const READ_ONLY_COMMANDS: ReadonlySet<string> = new Set([
|
|
|
1144
1159
|
"openapi",
|
|
1145
1160
|
"routes",
|
|
1146
1161
|
"sync-manifest",
|
|
1147
|
-
"sync-routes",
|
|
1148
1162
|
])
|
|
1149
1163
|
|
|
1150
1164
|
const HELD_OPEN_GRACE_MS = 2_000
|
|
@@ -1170,6 +1184,36 @@ function exitIfHeldOpen(command: string): void {
|
|
|
1170
1184
|
/** Set on the copy of `nifra mcp` that serves without `.env` files, so it does not restart again. */
|
|
1171
1185
|
const MCP_WITHOUT_ENV_FILES = "NIFRA_MCP_WITHOUT_ENV_FILES"
|
|
1172
1186
|
|
|
1187
|
+
/** Parsed arguments for the project-independent `nifra frontend` command. */
|
|
1188
|
+
export interface FrontendCommandInput {
|
|
1189
|
+
readonly adapter?: string | undefined
|
|
1190
|
+
readonly symptom?: string | undefined
|
|
1191
|
+
readonly json: boolean
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/** Parse frontend positionals separately from flags so `--json` never becomes a symptom. */
|
|
1195
|
+
export function frontendCommandInput(
|
|
1196
|
+
argv: readonly string[],
|
|
1197
|
+
parseAdapter: (value: string | undefined) => string | undefined,
|
|
1198
|
+
): FrontendCommandInput {
|
|
1199
|
+
const unknown = argv.find(
|
|
1200
|
+
(arg) => arg.startsWith("-") && arg !== "--json" && arg !== "--help" && arg !== "-h",
|
|
1201
|
+
)
|
|
1202
|
+
if (unknown !== undefined)
|
|
1203
|
+
throw new Error(`[nifra] unknown option: ${unknown} - see \`nifra help\``)
|
|
1204
|
+
const positional = argv.filter((arg) => !arg.startsWith("-"))
|
|
1205
|
+
const first = positional[0]
|
|
1206
|
+
const maybeAdapter = parseAdapter(first)
|
|
1207
|
+
const adapter = maybeAdapter === undefined ? undefined : first
|
|
1208
|
+
const symptom = (maybeAdapter === undefined ? positional : positional.slice(1)).join(" ")
|
|
1209
|
+
return {
|
|
1210
|
+
adapter,
|
|
1211
|
+
symptom: symptom.length > 0 ? symptom : undefined,
|
|
1212
|
+
json: argv.includes("--json"),
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/** Dispatch a CLI invocation, including project-independent agent and documentation commands. */
|
|
1173
1217
|
async function main(): Promise<void> {
|
|
1174
1218
|
const { argv: rawArgv, files: envFiles } = takeEnvFileFlags(cliArgv())
|
|
1175
1219
|
// `nifra mcp` keeps none of the `.env` values Bun loaded at startup. Decided before the
|
|
@@ -1265,18 +1309,30 @@ async function main(): Promise<void> {
|
|
|
1265
1309
|
// Project-independent and static. `nifra frontend` for the index, `nifra frontend vue "lost reactivity"`
|
|
1266
1310
|
// to filter by adapter and/or symptom (either arg may be omitted; an adapter is recognized by name).
|
|
1267
1311
|
if (command === "frontend") {
|
|
1268
|
-
const { renderFrontendResult, parseAdapter } = await import(
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
const symptom = (maybeAdapter === undefined ? argv.slice(1) : argv.slice(2))
|
|
1273
|
-
.filter((a) => !a.startsWith("-"))
|
|
1274
|
-
.join(" ")
|
|
1312
|
+
const { selectFrontendGuidance, renderFrontendResult, parseAdapter } = await import(
|
|
1313
|
+
"./frontend-guidance.ts"
|
|
1314
|
+
)
|
|
1315
|
+
const input = frontendCommandInput(argv.slice(1), parseAdapter)
|
|
1275
1316
|
console.log(
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1317
|
+
input.json
|
|
1318
|
+
? JSON.stringify(selectFrontendGuidance(input), null, 2)
|
|
1319
|
+
: renderFrontendResult(input),
|
|
1320
|
+
)
|
|
1321
|
+
return
|
|
1322
|
+
}
|
|
1323
|
+
// `runtime` prints the Bun/Node/Deno/Workers differences catalog (the human head of `nifra_runtime`).
|
|
1324
|
+
// Project-independent and static. `nifra runtime` for the index, `nifra runtime deno "path guard"` to
|
|
1325
|
+
// filter by runtime and/or symptom (either arg may be omitted; a runtime is recognized by name).
|
|
1326
|
+
if (command === "runtime") {
|
|
1327
|
+
const { selectRuntimeDifferences, renderRuntimeResult, parseRuntime } = await import(
|
|
1328
|
+
"./runtime-differences.ts"
|
|
1329
|
+
)
|
|
1330
|
+
const input = frontendCommandInput(argv.slice(1), parseRuntime)
|
|
1331
|
+
const query = { runtime: input.adapter, symptom: input.symptom }
|
|
1332
|
+
console.log(
|
|
1333
|
+
input.json
|
|
1334
|
+
? JSON.stringify(selectRuntimeDifferences(query), null, 2)
|
|
1335
|
+
: renderRuntimeResult(query),
|
|
1280
1336
|
)
|
|
1281
1337
|
return
|
|
1282
1338
|
}
|
package/src/command-catalog.ts
CHANGED
|
@@ -14,11 +14,11 @@ import type {
|
|
|
14
14
|
CapabilitySnapshotCommandResult,
|
|
15
15
|
} from "./capabilities-tool.ts"
|
|
16
16
|
import { cdnCheckSpec } from "./cdn-check.ts"
|
|
17
|
-
import { type CheckResult, renderCheckReport } from "./check.ts"
|
|
17
|
+
import { type CheckResult, checkDiagnostics, renderCheckReport } from "./check.ts"
|
|
18
18
|
import type { ContractsLock } from "./contracts.ts"
|
|
19
19
|
import { dbAuditSpec, dbQuerySpec, dbRoleSpec, dbSchemaSpec } from "./db-tool.ts"
|
|
20
20
|
import { errorsSpec, explainSpec, logsSpec } from "./dev-feed-tool.ts"
|
|
21
|
-
import {
|
|
21
|
+
import { toSarifLog } from "./diagnostics.ts"
|
|
22
22
|
import type { DoctorResult } from "./doctor.ts"
|
|
23
23
|
import { type I18nCheckOutput, i18nCheckPassed, renderI18nCheck } from "./i18n-check.ts"
|
|
24
24
|
import type { VerificationLevelsResult } from "./levels-tool.ts"
|
|
@@ -533,10 +533,6 @@ interface ContractsCommandOutput {
|
|
|
533
533
|
readonly present?: boolean
|
|
534
534
|
readonly vacuous?: boolean
|
|
535
535
|
}
|
|
536
|
-
interface SyncCommandOutput {
|
|
537
|
-
readonly ok: true
|
|
538
|
-
readonly results: readonly unknown[]
|
|
539
|
-
}
|
|
540
536
|
interface SyncManifestCommandOutput {
|
|
541
537
|
readonly ok: boolean
|
|
542
538
|
readonly results: readonly SyncManifestResult[]
|
|
@@ -936,6 +932,17 @@ const SYNC_SCHEMA = input<SyncInput>(
|
|
|
936
932
|
},
|
|
937
933
|
)
|
|
938
934
|
|
|
935
|
+
/** What both sync commands answer, `{ ok, results }`, and their one flag. */
|
|
936
|
+
const syncOutput = <Output>(): CommandOutputContract<Output> =>
|
|
937
|
+
output({
|
|
938
|
+
type: "object",
|
|
939
|
+
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
940
|
+
required: ["ok", "results"],
|
|
941
|
+
})
|
|
942
|
+
const SYNC_ARGV: CommandArgvBinding<SyncInput> = {
|
|
943
|
+
flags: [{ name: "json", field: "json", type: "boolean" }],
|
|
944
|
+
}
|
|
945
|
+
|
|
939
946
|
const PROVE_SCHEMA = input<ProveInput>(
|
|
940
947
|
objectSchema({
|
|
941
948
|
files: { type: "array", items: { type: "string" } },
|
|
@@ -1043,25 +1050,9 @@ function backendAppFor(ctx: CommandCtx): Promise<IntrospectedApp> {
|
|
|
1043
1050
|
return import("./load.ts").then(({ loadBackendApp }) => loadBackendApp(ctx.cwd))
|
|
1044
1051
|
}
|
|
1045
1052
|
|
|
1046
|
-
function structuredDiagnostics(out: CheckCommandOutput): readonly Diagnostic[] {
|
|
1047
|
-
if (out.structuredDiagnostics !== undefined) return out.structuredDiagnostics
|
|
1048
|
-
return out.diagnostics.map((value) =>
|
|
1049
|
-
diagnostic({
|
|
1050
|
-
code: value.code ?? value.rule,
|
|
1051
|
-
severity: normalizeSeverity(value.severity),
|
|
1052
|
-
message: value.message,
|
|
1053
|
-
...(value.file === undefined ? {} : { file: value.file }),
|
|
1054
|
-
...(value.line === undefined ? {} : { line: value.line }),
|
|
1055
|
-
...(value.evidence === undefined ? {} : { evidence: value.evidence }),
|
|
1056
|
-
...(value.fix === undefined ? {} : { fix: { recipe: value.fix } }),
|
|
1057
|
-
...(value.verify === undefined ? {} : { verify: value.verify }),
|
|
1058
|
-
}),
|
|
1059
|
-
)
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
1053
|
function checkJson(out: CheckCommandOutput, input?: CheckInput): unknown {
|
|
1063
|
-
if (input?.sarif === true) return toSarifLog(
|
|
1064
|
-
return { ...out, diagnostics:
|
|
1054
|
+
if (input?.sarif === true) return toSarifLog(checkDiagnostics(out))
|
|
1055
|
+
return { ...out, diagnostics: checkDiagnostics(out) }
|
|
1065
1056
|
}
|
|
1066
1057
|
|
|
1067
1058
|
const checkSpec: CommandSpec<CheckInput, CheckCommandOutput> = {
|
|
@@ -1179,6 +1170,9 @@ const levelsSpec: CommandSpec<LevelsInput, LevelsCommandOutput> = {
|
|
|
1179
1170
|
...out.levels.flatMap((s) => [
|
|
1180
1171
|
`${s.ok ? "✓" : "✖"} L${s.level} ${s.name}`,
|
|
1181
1172
|
...s.reasons.map((r) => ` - ${r}`),
|
|
1173
|
+
...(s.setupWitnesses === undefined
|
|
1174
|
+
? []
|
|
1175
|
+
: [` witnesses from setup: ${s.setupWitnesses.join(", ")}`]),
|
|
1182
1176
|
]),
|
|
1183
1177
|
out.achieved < 0
|
|
1184
1178
|
? "[nifra] verification level: none (L0 failing)"
|
|
@@ -1676,7 +1670,7 @@ const scaffoldSpec: CommandSpec<ScaffoldInput, HoleScaffoldResult> = {
|
|
|
1676
1670
|
required: ["ok", "page", "backend", "changed", "snippets", "next"],
|
|
1677
1671
|
}),
|
|
1678
1672
|
transports: ["cli"],
|
|
1679
|
-
stability: "
|
|
1673
|
+
stability: "stable",
|
|
1680
1674
|
argv: {
|
|
1681
1675
|
positionals: ["kind", "route", "name"],
|
|
1682
1676
|
flags: [
|
|
@@ -1787,7 +1781,7 @@ const targetSpec: CommandSpec<TargetInput, TargetOutput> = {
|
|
|
1787
1781
|
const typesSpec: CommandSpec<TypesInput, RouteTypesReport> = {
|
|
1788
1782
|
name: "types",
|
|
1789
1783
|
summary:
|
|
1790
|
-
"Generate each route's `./+types` module (params, schema-typed data, typed `api`); `--check` fails when one is stale.",
|
|
1784
|
+
"Generate each route's `./+types` module (params, schema-typed data, typed `api`) and `.nifra/types/routes.d.ts`, the route table `href()` checks links against; `--check` fails when one is stale.",
|
|
1791
1785
|
input: TYPES_SCHEMA,
|
|
1792
1786
|
output: output({
|
|
1793
1787
|
type: "object",
|
|
@@ -2021,14 +2015,10 @@ const syncManifestSpec: CommandSpec<SyncInput, SyncManifestCommandOutput> = {
|
|
|
2021
2015
|
name: "sync-manifest",
|
|
2022
2016
|
summary: "Regenerate generated server-manifest route tables without a full build.",
|
|
2023
2017
|
input: SYNC_SCHEMA,
|
|
2024
|
-
output:
|
|
2025
|
-
type: "object",
|
|
2026
|
-
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
2027
|
-
required: ["ok", "results"],
|
|
2028
|
-
}),
|
|
2018
|
+
output: syncOutput(),
|
|
2029
2019
|
transports: ["cli", "mcp"],
|
|
2030
2020
|
stability: "stable",
|
|
2031
|
-
argv:
|
|
2021
|
+
argv: SYNC_ARGV,
|
|
2032
2022
|
async run(_value, ctx) {
|
|
2033
2023
|
const results = await syncServerManifests(ctx.cwd)
|
|
2034
2024
|
return { ok: syncManifestsOk(results), results }
|
|
@@ -2037,29 +2027,6 @@ const syncManifestSpec: CommandSpec<SyncInput, SyncManifestCommandOutput> = {
|
|
|
2037
2027
|
success: (out) => out.ok,
|
|
2038
2028
|
}
|
|
2039
2029
|
|
|
2040
|
-
const syncRoutesSpec: CommandSpec<SyncInput, SyncCommandOutput> = {
|
|
2041
|
-
name: "sync-routes",
|
|
2042
|
-
summary: "Regenerate nifra-routes.d.ts so typed navigation follows route search schemas.",
|
|
2043
|
-
input: SYNC_SCHEMA,
|
|
2044
|
-
output: output({
|
|
2045
|
-
type: "object",
|
|
2046
|
-
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
2047
|
-
required: ["ok", "results"],
|
|
2048
|
-
}),
|
|
2049
|
-
transports: ["cli", "mcp"],
|
|
2050
|
-
stability: "stable",
|
|
2051
|
-
argv: { flags: [{ name: "json", field: "json", type: "boolean" }] },
|
|
2052
|
-
async run(_value, ctx) {
|
|
2053
|
-
const result = await (await import("./sync-routes.ts")).syncRouteTypes(ctx.cwd)
|
|
2054
|
-
return { ok: true, results: result === null ? [] : [result] }
|
|
2055
|
-
},
|
|
2056
|
-
render: (out) => [
|
|
2057
|
-
out.results.length === 0
|
|
2058
|
-
? "nifra sync-routes: no routes/ directory found. Run from your project root."
|
|
2059
|
-
: `✓ checked ${out.results.length} route type output`,
|
|
2060
|
-
],
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
2030
|
const proveSpec: CommandSpec<ProveInput, ProjectWorkGraphResult> = {
|
|
2064
2031
|
name: "prove",
|
|
2065
2032
|
summary:
|
|
@@ -2219,7 +2186,6 @@ export const commandSpecs = Object.freeze([
|
|
|
2219
2186
|
diffSpec,
|
|
2220
2187
|
contractsSpec,
|
|
2221
2188
|
syncManifestSpec,
|
|
2222
|
-
syncRoutesSpec,
|
|
2223
2189
|
proveSpec,
|
|
2224
2190
|
replaySpec,
|
|
2225
2191
|
smokeSpec,
|
package/src/config-target.ts
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
|
230
|
-
* name of its own. A sign-out there may
|
|
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
|
|
962
|
-
const
|
|
963
|
-
identitySignal || (
|
|
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
|
-
|
|
1070
|
+
keptRoutes.length === 0 || (reachedAuth !== undefined && renamedIn === undefined)
|
|
966
1071
|
? undefined
|
|
967
1072
|
: knownAuth && renamedIn !== undefined
|
|
968
|
-
? { routes:
|
|
969
|
-
: { routes:
|
|
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) {
|