@nifrajs/cli 5.0.0 → 5.2.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 +3211 -0
- package/README.md +10 -2
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +5 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts +12 -2
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +73 -9
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +152 -49
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +7 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +8 -2
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +49 -13
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +91 -45
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +128 -59
- package/dist/cli.js.map +1 -1
- package/dist/client-module.d.ts +5 -3
- package/dist/client-module.d.ts.map +1 -1
- package/dist/client-module.js +34 -10
- package/dist/client-module.js.map +1 -1
- package/dist/command-catalog.d.ts +9 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +75 -26
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +19 -1
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +114 -0
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/fix-recipes.d.ts +2 -0
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +93 -12
- package/dist/fix-recipes.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +60 -4
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +196 -33
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/config-paths.d.ts +16 -0
- package/dist/internal/config-paths.d.ts.map +1 -0
- package/dist/internal/config-paths.js +124 -0
- package/dist/internal/config-paths.js.map +1 -0
- package/dist/internal/installed-package.d.ts +4 -0
- package/dist/internal/installed-package.d.ts.map +1 -0
- package/dist/internal/installed-package.js +17 -0
- package/dist/internal/installed-package.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts +14 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +63 -16
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +12 -1
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +117 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +5 -3
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/introspect.d.ts +9 -0
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +32 -1
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +5 -8
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +9 -4
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +32 -3
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +6 -21
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +2 -2
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +19 -7
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +13 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +13 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +23 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-path.d.ts +2 -1
- package/dist/mcp-path.d.ts.map +1 -1
- package/dist/mcp-path.js +9 -24
- package/dist/mcp-path.js.map +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +40 -17
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +41 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1729 -236
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts +34 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +132 -21
- package/dist/output-schemas.js.map +1 -1
- package/dist/project-path.d.ts +6 -0
- package/dist/project-path.d.ts.map +1 -1
- package/dist/project-path.js +48 -14
- package/dist/project-path.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/release-verification.d.ts +5 -0
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +14 -0
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +7 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +5 -1
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +5 -1
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts +6 -0
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +37 -0
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +44 -2
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +56 -3
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +412 -23
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts +3 -2
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +42 -11
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +34 -11
- package/dist/rules/zones.js.map +1 -1
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +127 -17
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +3 -9
- package/dist/test-tool.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +57 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +247 -19
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +7 -2
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +66 -3
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +21 -3
- package/docs/llms-full.txt +1083 -168
- package/docs/types.json +535 -112
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +5 -1
- package/src/assure.ts +99 -11
- package/src/capabilities-tool.ts +188 -53
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +65 -12
- package/src/check.ts +122 -51
- package/src/cli.ts +127 -45
- package/src/client-module.ts +45 -9
- package/src/command-catalog.ts +92 -28
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +146 -1
- package/src/doctor.ts +102 -66
- package/src/fix-recipes.ts +101 -10
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +225 -44
- package/src/internal/config-paths.ts +154 -0
- package/src/internal/installed-package.ts +15 -0
- package/src/internal/project-specifiers.ts +78 -17
- package/src/internal/source-facts.ts +147 -5
- package/src/internal/typescript-import.ts +5 -3
- package/src/internal/workspace-packages.ts +218 -0
- package/src/introspect.ts +39 -1
- package/src/levels-tool.ts +7 -9
- package/src/load.ts +46 -4
- package/src/lock-links.ts +173 -0
- package/src/mcp-context.ts +5 -18
- package/src/mcp-delegate.ts +22 -10
- package/src/mcp-exec.ts +14 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +33 -0
- package/src/mcp-path.ts +8 -22
- package/src/mcp-root.ts +14 -8
- package/src/mcp.ts +48 -19
- package/src/migrate-layout.ts +1968 -245
- package/src/output-schemas.ts +179 -23
- package/src/project-path.ts +44 -13
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/index.ts +7 -0
- package/src/release-verification.ts +20 -0
- package/src/review.ts +7 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +5 -1
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/data-guard.ts +40 -0
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +46 -2
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +486 -25
- package/src/rules/routes.ts +4 -3
- package/src/rules/security.ts +49 -11
- package/src/rules/zones.ts +33 -9
- package/src/stylex-migrate.ts +117 -17
- package/src/test-tool.ts +3 -9
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +312 -19
- package/src/verification-plan.ts +15 -2
- package/src/version-drift.ts +68 -2
- package/src/web-app-options.ts +9 -1
package/src/introspect.ts
CHANGED
|
@@ -438,6 +438,9 @@ export interface RouteTableEntry {
|
|
|
438
438
|
* through the same web app, no hand-wired `if (pathname.startsWith("/api/"))`). Pages are never
|
|
439
439
|
* auto-mounted (they ARE the page router); only API routes carry this flag. */
|
|
440
440
|
readonly autoMounted?: boolean
|
|
441
|
+
/** True for an API route outside a set `apiPrefix` while `apiStrip` is off: the mount passes the
|
|
442
|
+
* request's full path, so no HTTP request reaches it; loaders still call it in-process. */
|
|
443
|
+
readonly inProcessOnly?: boolean
|
|
441
444
|
}
|
|
442
445
|
|
|
443
446
|
/** A page route + whether its module exports an `action` (→ it also serves POST). The caller resolves
|
|
@@ -506,6 +509,8 @@ export function buildRouteTable(input: RouteTableInput): RouteTableEntry[] {
|
|
|
506
509
|
path,
|
|
507
510
|
methods: [...info.methods].sort(),
|
|
508
511
|
autoMounted: info.autoMounted,
|
|
512
|
+
// biome-ignore lint/plugin/noConditionalEmptyObjectSpread: only a route outside apiPrefix carries the flag, so every other row keeps its shape.
|
|
513
|
+
...(apiPrefix !== "" && !info.autoMounted ? { inProcessOnly: true } : {}),
|
|
509
514
|
})
|
|
510
515
|
}
|
|
511
516
|
return rows.sort(
|
|
@@ -544,7 +549,12 @@ export function renderRouteTable(rows: readonly RouteTableEntry[]): string {
|
|
|
544
549
|
const display = rows.map((r) => ({
|
|
545
550
|
methods: r.methods.join(", "),
|
|
546
551
|
kind: r.kind,
|
|
547
|
-
path:
|
|
552
|
+
path:
|
|
553
|
+
r.kind === "api" && r.autoMounted
|
|
554
|
+
? `${r.path} (auto-mounted)`
|
|
555
|
+
: r.inProcessOnly === true
|
|
556
|
+
? `${r.path} (in-process only: outside apiPrefix)`
|
|
557
|
+
: r.path,
|
|
548
558
|
client: clientSpellingFor(r.path),
|
|
549
559
|
}))
|
|
550
560
|
const methodW = Math.max("METHOD".length, ...display.map((d) => d.methods.length))
|
|
@@ -577,6 +587,7 @@ export interface RouteJsonRow {
|
|
|
577
587
|
readonly methods: readonly string[]
|
|
578
588
|
readonly file?: string
|
|
579
589
|
readonly autoMounted?: boolean
|
|
590
|
+
readonly inProcessOnly?: boolean
|
|
580
591
|
/** The reserved typed-client key a static segment of this path collides with, when one does. */
|
|
581
592
|
readonly reservedKey?: string
|
|
582
593
|
/** The typed-client call spelling that reaches this route, present only alongside `reservedKey`. */
|
|
@@ -599,6 +610,8 @@ export function routeTableToJson(rows: readonly RouteTableEntry[]): {
|
|
|
599
610
|
methods: r.methods,
|
|
600
611
|
...(r.file !== undefined ? { file: r.file } : {}),
|
|
601
612
|
...(r.kind === "api" ? { autoMounted: r.autoMounted === true } : {}),
|
|
613
|
+
// biome-ignore lint/plugin/noConditionalEmptyObjectSpread: `--json` rows gain the key only where it is true, so existing consumers see no change.
|
|
614
|
+
...(r.inProcessOnly === true ? { inProcessOnly: true } : {}),
|
|
602
615
|
...(client === undefined
|
|
603
616
|
? {}
|
|
604
617
|
: { reservedKey: client.reserved, clientSpelling: client.spelling }),
|
|
@@ -748,6 +761,31 @@ async function collectRouteTable(app: IntrospectedApp): Promise<RouteTableEntry[
|
|
|
748
761
|
return rows
|
|
749
762
|
}
|
|
750
763
|
|
|
764
|
+
/**
|
|
765
|
+
* The warning `nifra dev` and `nifra build` print for backend routes no HTTP request reaches, read from
|
|
766
|
+
* the routes the backend registers, prefixes and mounts resolved; `undefined` when there are none.
|
|
767
|
+
*/
|
|
768
|
+
export function unservedRoutesWarning(
|
|
769
|
+
app: Pick<IntrospectedApp, "framework" | "backend">,
|
|
770
|
+
): string | undefined {
|
|
771
|
+
const apiPrefix = app.framework?.apiPrefix ?? ""
|
|
772
|
+
if (apiPrefix === "" || app.backend === undefined) return undefined
|
|
773
|
+
const rows = buildRouteTable({
|
|
774
|
+
pages: [],
|
|
775
|
+
api: backendRoutes(app.backend),
|
|
776
|
+
apiPrefix,
|
|
777
|
+
apiStrip: app.framework?.apiStrip === true,
|
|
778
|
+
}).filter((row) => row.inProcessOnly === true)
|
|
779
|
+
if (rows.length === 0) return undefined
|
|
780
|
+
const listed = rows.map((row) => `${row.methods.join(",")} ${row.path}`)
|
|
781
|
+
const named =
|
|
782
|
+
listed.length > 3
|
|
783
|
+
? `${listed.slice(0, 3).join(", ")} and ${listed.length - 3} more`
|
|
784
|
+
: listed.join(", ")
|
|
785
|
+
const one = rows.length === 1
|
|
786
|
+
return `[nifra] ${one ? "a backend route is" : `${rows.length} backend routes are`} served over HTTP nowhere: ${named}. backend/app.ts is mounted at apiPrefix ${apiPrefix} with apiStrip off, so it sees each request's full path, and ${one ? "this route sits" : "these sit"} outside it; loaders still call ${one ? "it" : "them"} in-process. Register ${one ? "it" : "them"} under ${apiPrefix}, or export \`apiStrip = true\` to serve every backend route at ${apiPrefix} plus its path.`
|
|
787
|
+
}
|
|
788
|
+
|
|
751
789
|
export async function describeRoutes(
|
|
752
790
|
app: IntrospectedApp,
|
|
753
791
|
opts: { readonly json?: boolean } = {},
|
package/src/levels-tool.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { existsSync } from "node:fs"
|
|
|
15
15
|
import { resolve } from "node:path"
|
|
16
16
|
import type {
|
|
17
17
|
AssuranceReport,
|
|
18
|
+
AssuredRoute,
|
|
18
19
|
InvariantSetup,
|
|
19
20
|
InvariantSetupResult,
|
|
20
21
|
InvariantsConfig,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
type ContractTestApp,
|
|
27
28
|
runAdversarialContract,
|
|
28
29
|
} from "@nifrajs/testing"
|
|
30
|
+
import { RESPONSE_CONTRACT_BASELINE_HINT, responseContractGaps } from "./assure.ts"
|
|
29
31
|
import {
|
|
30
32
|
type CapabilityProjectReport,
|
|
31
33
|
diffCapabilitySnapshots,
|
|
@@ -310,7 +312,7 @@ const messageOf = (error: unknown): string =>
|
|
|
310
312
|
|
|
311
313
|
function finalize(
|
|
312
314
|
statuses: readonly { level: number; name: string; ok: boolean; reasons: string[] }[],
|
|
313
|
-
routes: readonly
|
|
315
|
+
routes: readonly AssuredRoute[],
|
|
314
316
|
): VerificationLevelsResult {
|
|
315
317
|
// Cumulative: the achieved level is the last rung with every rung below it also holding.
|
|
316
318
|
let achieved = -1
|
|
@@ -322,6 +324,7 @@ function finalize(
|
|
|
322
324
|
const enforced = declared.filter((route) => route.responseContract === "enforce").length
|
|
323
325
|
const warnOnly = declared.filter((route) => route.responseContract === "warn").length
|
|
324
326
|
const typedOnly = declared.filter((route) => route.responseContract === "unchecked").length
|
|
327
|
+
const gaps = responseContractGaps(routes)
|
|
325
328
|
const responseContracts: ResponseContractStatus = {
|
|
326
329
|
declared: declared.length,
|
|
327
330
|
enforced,
|
|
@@ -333,14 +336,9 @@ function finalize(
|
|
|
333
336
|
declared.length === 0
|
|
334
337
|
? ["no response/error schemas declared"]
|
|
335
338
|
: [
|
|
336
|
-
...(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
]
|
|
340
|
-
: []),
|
|
341
|
-
...(warnOnly > 0
|
|
342
|
-
? [`${warnOnly} declared route(s) are warn-only and still send the original payload`]
|
|
343
|
-
: []),
|
|
339
|
+
...(gaps.typedOnlyReason === undefined ? [] : [gaps.typedOnlyReason]),
|
|
340
|
+
...(gaps.warnOnlyReason === undefined ? [] : [gaps.warnOnlyReason]),
|
|
341
|
+
...(typedOnly + warnOnly > 0 ? [RESPONSE_CONTRACT_BASELINE_HINT] : []),
|
|
344
342
|
],
|
|
345
343
|
}
|
|
346
344
|
return Object.freeze({
|
package/src/load.ts
CHANGED
|
@@ -85,7 +85,8 @@ export interface NifraFramework {
|
|
|
85
85
|
readonly dev?: { readonly indicator?: boolean; readonly allowedHosts?: readonly string[] }
|
|
86
86
|
/** Static files directory. Defaults to `<app>/public`; `false` disables it. */
|
|
87
87
|
readonly publicDir?: string | false
|
|
88
|
-
/** Client-visible environment prefix (default `"PUBLIC_"`; empty disables exposure).
|
|
88
|
+
/** Client-visible environment prefix (default `"PUBLIC_"`; empty disables exposure). With both
|
|
89
|
+
* configs, `nifra.config.ts` wins and `backend/framework.ts` fills it in when left unset. */
|
|
89
90
|
readonly publicEnvPrefix?: string
|
|
90
91
|
/** Reviewed false positives of `nifra build`'s secret scan, each `{ rule, file, reason }` (or
|
|
91
92
|
* `{ rule: "private-env-value", env, reason }`). There is no exemption by value. */
|
|
@@ -111,6 +112,10 @@ export interface NifraFramework {
|
|
|
111
112
|
readonly csp?: CreateWebAppOptions["csp"]
|
|
112
113
|
/** A per-request CSP nonce resolver. Exclusive with {@link csp}. */
|
|
113
114
|
readonly nonce?: CreateWebAppOptions["nonce"]
|
|
115
|
+
/** The app's locale routing, `defineI18nRouting()` from `@nifrajs/i18n/routing`: every document
|
|
116
|
+
* takes its `<html lang dir>`, `Content-Language` and adapter locale from it. See `createWebApp`'s
|
|
117
|
+
* `i18n`. */
|
|
118
|
+
readonly i18n?: CreateWebAppOptions["i18n"]
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
/** The {@link NifraFramework} fields forwarded to `createWebApp` and imported by the generated server
|
|
@@ -122,6 +127,7 @@ export const FRAMEWORK_WEB_OPTIONS = [
|
|
|
122
127
|
"csp",
|
|
123
128
|
"nonce",
|
|
124
129
|
"serverComponents",
|
|
130
|
+
"i18n",
|
|
125
131
|
] as const
|
|
126
132
|
export type FrameworkWebOption = (typeof FRAMEWORK_WEB_OPTIONS)[number]
|
|
127
133
|
|
|
@@ -162,6 +168,15 @@ function assertFrameworkWebOptions(fw: Partial<NifraFramework>, configFile: stri
|
|
|
162
168
|
if (fw.nonce !== undefined && typeof fw.nonce !== "function") {
|
|
163
169
|
wrong("nonce", "a nonce resolver function, such as createNonceResolver() returns")
|
|
164
170
|
}
|
|
171
|
+
if (
|
|
172
|
+
fw.i18n !== undefined &&
|
|
173
|
+
(typeof fw.i18n !== "object" || fw.i18n === null || typeof fw.i18n.localeOf !== "function")
|
|
174
|
+
) {
|
|
175
|
+
wrong("i18n", "the router defineI18nRouting() from @nifrajs/i18n/routing returns")
|
|
176
|
+
}
|
|
177
|
+
if (fw.publicEnvPrefix !== undefined && typeof fw.publicEnvPrefix !== "string") {
|
|
178
|
+
wrong("publicEnvPrefix", 'a string such as "PUBLIC_", or "" to expose no environment variable')
|
|
179
|
+
}
|
|
165
180
|
if (fw.secretExemptions !== undefined && !Array.isArray(fw.secretExemptions)) {
|
|
166
181
|
wrong("secretExemptions", "an array of { rule, file, reason } entries")
|
|
167
182
|
}
|
|
@@ -342,9 +357,32 @@ export async function loadBackendApp(
|
|
|
342
357
|
return { cwd, backend }
|
|
343
358
|
}
|
|
344
359
|
|
|
360
|
+
/** The fields the generated server entry imports from backend/framework.ts, and `publicEnvPrefix`,
|
|
361
|
+
* which `nifra check` reads there too: each command must draw the browser-env line in one place. */
|
|
362
|
+
const SERVER_OPTIONS = [...FRAMEWORK_WEB_OPTIONS, "use", "publicEnvPrefix"] as const
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* `config` with each server option it leaves unset taken from backend/framework.ts, so `nifra dev` and
|
|
366
|
+
* the server entry `nifra build` generates read one value without nifra.config.ts re-exporting it.
|
|
367
|
+
*/
|
|
368
|
+
async function withServerOptions(
|
|
369
|
+
config: Partial<NifraFramework>,
|
|
370
|
+
frameworkPath: string,
|
|
371
|
+
importQuery: string | undefined,
|
|
372
|
+
): Promise<Partial<NifraFramework>> {
|
|
373
|
+
// biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: a config module, read like nifra.config.ts; every web option taken from it is validated below.
|
|
374
|
+
const framework = (await importWithQuery(frameworkPath, importQuery)) as Partial<NifraFramework>
|
|
375
|
+
const taken: Record<string, unknown> = {}
|
|
376
|
+
for (const name of SERVER_OPTIONS) {
|
|
377
|
+
if (config[name] === undefined && framework[name] !== undefined) taken[name] = framework[name]
|
|
378
|
+
}
|
|
379
|
+
assertFrameworkWebOptions(taken, FRAMEWORK_FILE)
|
|
380
|
+
return { ...config, ...taken }
|
|
381
|
+
}
|
|
382
|
+
|
|
345
383
|
/** Discover + validate the app conventions rooted at `cwd`. Prefers `nifra.config.ts`, falls back
|
|
346
|
-
* to
|
|
347
|
-
*
|
|
384
|
+
* to `backend/framework.ts`; with both, a server option nifra.config.ts leaves unset comes from
|
|
385
|
+
* backend/framework.ts. Throws a clear, actionable error if neither exists or the config is
|
|
348
386
|
* malformed. */
|
|
349
387
|
export async function loadApp(
|
|
350
388
|
cwd: string,
|
|
@@ -375,7 +413,11 @@ export async function loadApp(
|
|
|
375
413
|
`[nifra] no routes/ directory in ${cwd} - nifra apps are file-routed under routes/.`,
|
|
376
414
|
)
|
|
377
415
|
}
|
|
378
|
-
const
|
|
416
|
+
const loaded = (await importWithQuery(configPath, options.importQuery)) as Partial<NifraFramework>
|
|
417
|
+
const fw =
|
|
418
|
+
configFile === CONFIG_FILE && existsSync(resolve(cwd, FRAMEWORK_FILE))
|
|
419
|
+
? await withServerOptions(loaded, resolve(cwd, FRAMEWORK_FILE), options.importQuery)
|
|
420
|
+
: loaded
|
|
379
421
|
if (!isAdapter(fw.adapter) || typeof fw.clientModule !== "string") {
|
|
380
422
|
throw new Error(
|
|
381
423
|
`[nifra] ${configFile} must export \`adapter\` (a render adapter object) and \`clientModule\` (a string).`,
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `file:` dependency's own dependencies, as bun.lock records them. Bun records them when it first
|
|
3
|
+
* installs the linked package and does not read its package.json again, so once the linked package
|
|
4
|
+
* moves to another version of a dependency the lock still names the old one and Bun installs a second
|
|
5
|
+
* copy under the linked package. Checked on Bun 1.4.2: `bun install --force` keeps the stale entry;
|
|
6
|
+
* `bun update <name>`, or dropping the entry and its scoped entries before `bun install`, clears it.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
9
|
+
import { dirname, join, resolve } from "node:path"
|
|
10
|
+
import { parseJsonc } from "./internal/project-specifiers.ts"
|
|
11
|
+
|
|
12
|
+
export const BUN_LOCK = "bun.lock"
|
|
13
|
+
|
|
14
|
+
/** The fields Bun installs from a linked package's manifest. */
|
|
15
|
+
const INSTALLED_FIELDS: readonly string[] = [
|
|
16
|
+
"dependencies",
|
|
17
|
+
"optionalDependencies",
|
|
18
|
+
"peerDependencies",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
/** One dependency whose recorded spec is not the one the linked package.json declares now. */
|
|
22
|
+
export interface LinkLockChange {
|
|
23
|
+
readonly name: string
|
|
24
|
+
/** As bun.lock recorded it; absent when the linked package added it since. */
|
|
25
|
+
readonly recorded?: string
|
|
26
|
+
/** As the linked package.json declares it; absent when it was removed since. */
|
|
27
|
+
readonly declared?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A `file:` entry of bun.lock whose recorded dependencies the linked package.json no longer declares. */
|
|
31
|
+
export interface StaleLinkLock {
|
|
32
|
+
/** The package, as the lock keys it. */
|
|
33
|
+
readonly package: string
|
|
34
|
+
/** The linked directory, as the lock names it relative to the lockfile. */
|
|
35
|
+
readonly path: string
|
|
36
|
+
readonly changes: readonly LinkLockChange[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const recordOf = (value: unknown): Readonly<Record<string, unknown>> =>
|
|
40
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
41
|
+
? Object.fromEntries(Object.entries(value))
|
|
42
|
+
: {}
|
|
43
|
+
|
|
44
|
+
const textOf = (value: unknown): string | undefined =>
|
|
45
|
+
typeof value === "string" ? value : undefined
|
|
46
|
+
|
|
47
|
+
/** A top-level lock key (`name`, `@scope/name`), not a dependency scoped under one (`name/dep`). */
|
|
48
|
+
const topLevel = (key: string): boolean =>
|
|
49
|
+
key.startsWith("@") ? key.split("/").length === 2 : !key.includes("/")
|
|
50
|
+
|
|
51
|
+
/** The directory of the nearest bun.lock at or above `cwd`, up to the repository root. */
|
|
52
|
+
export function bunLockDir(cwd: string): string | undefined {
|
|
53
|
+
for (let dir = resolve(cwd); ; ) {
|
|
54
|
+
if (existsSync(join(dir, BUN_LOCK))) return dir
|
|
55
|
+
const parent = dirname(dir)
|
|
56
|
+
if (parent === dir || existsSync(join(dir, ".git"))) return undefined
|
|
57
|
+
dir = parent
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Each `file:` entry of the bun.lock in `dir` whose recorded dependencies differ from what the linked
|
|
63
|
+
* package.json declares. `manifests` (absolute path -> text) stands in for package.json files an edit
|
|
64
|
+
* has planned but not written yet. A lock or manifest that cannot be read reports nothing.
|
|
65
|
+
*/
|
|
66
|
+
export function staleLinkLocks(
|
|
67
|
+
dir: string,
|
|
68
|
+
manifests: ReadonlyMap<string, string> = new Map(),
|
|
69
|
+
): StaleLinkLock[] {
|
|
70
|
+
let lock: unknown
|
|
71
|
+
try {
|
|
72
|
+
lock = parseJsonc(readFileSync(join(dir, BUN_LOCK), "utf8"))
|
|
73
|
+
} catch {
|
|
74
|
+
return []
|
|
75
|
+
}
|
|
76
|
+
const stale: StaleLinkLock[] = []
|
|
77
|
+
for (const [key, entry] of Object.entries(recordOf(Reflect.get(Object(lock), "packages")))) {
|
|
78
|
+
if (!topLevel(key) || !Array.isArray(entry)) continue
|
|
79
|
+
const spec = textOf(entry[0])
|
|
80
|
+
const at = spec?.indexOf("@file:", 1) ?? -1
|
|
81
|
+
if (spec === undefined || at === -1) continue
|
|
82
|
+
const path = spec.slice(at + "@file:".length)
|
|
83
|
+
const manifestPath = resolve(dir, path, "package.json")
|
|
84
|
+
let declared: unknown
|
|
85
|
+
try {
|
|
86
|
+
declared = JSON.parse(manifests.get(manifestPath) ?? readFileSync(manifestPath, "utf8"))
|
|
87
|
+
} catch {
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
const recorded = recordOf(entry[1])
|
|
91
|
+
const changes: LinkLockChange[] = []
|
|
92
|
+
for (const field of INSTALLED_FIELDS) {
|
|
93
|
+
const was = recordOf(recorded[field])
|
|
94
|
+
const now = recordOf(Reflect.get(Object(declared), field))
|
|
95
|
+
for (const name of new Set([...Object.keys(was), ...Object.keys(now)])) {
|
|
96
|
+
const before = textOf(was[name])
|
|
97
|
+
const after = textOf(now[name])
|
|
98
|
+
if (before === after) continue
|
|
99
|
+
const change: { name: string; recorded?: string; declared?: string } = { name }
|
|
100
|
+
if (before !== undefined) change.recorded = before
|
|
101
|
+
if (after !== undefined) change.declared = after
|
|
102
|
+
changes.push(change)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (changes.length > 0) stale.push({ package: key, path, changes })
|
|
106
|
+
}
|
|
107
|
+
return stale
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `name 1.0.0 -> 2.0.0`, with `(none)` for a side that does not have it. */
|
|
111
|
+
export const describeChange = (change: LinkLockChange): string =>
|
|
112
|
+
`${change.name} ${change.recorded ?? "(none)"} -> ${change.declared ?? "(none)"}`
|
|
113
|
+
|
|
114
|
+
const ENTRY_KEY = /^ {4}("(?:[^"\\]|\\.)*"): \[/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* bun.lock text without the `packages` entries of `names` and the dependencies scoped under them,
|
|
118
|
+
* so the next `bun install` reads each linked package.json again. `undefined` unless the text is laid
|
|
119
|
+
* out one entry per line, as Bun writes it, and the result parses to the same lock less those
|
|
120
|
+
* entries: the caller names `bun update` instead.
|
|
121
|
+
*/
|
|
122
|
+
export function pruneLinkLocks(text: string, names: readonly string[]): string | undefined {
|
|
123
|
+
const lines = text.split("\n")
|
|
124
|
+
const start = lines.findIndex((line) => /^ {2}"packages": \{\s*$/.test(line))
|
|
125
|
+
if (start === -1) return undefined
|
|
126
|
+
const end = lines.findIndex((line, index) => index > start && /^ {2}\}/.test(line))
|
|
127
|
+
if (end === -1) return undefined
|
|
128
|
+
const dropped = (key: string): boolean =>
|
|
129
|
+
names.some((name) => key === name || key.startsWith(`${name}/`))
|
|
130
|
+
const kept = lines.filter((line, index) => {
|
|
131
|
+
if (index <= start || index >= end) return true
|
|
132
|
+
const key = ENTRY_KEY.exec(line)?.[1]
|
|
133
|
+
return key === undefined || !dropped(String(JSON.parse(key)))
|
|
134
|
+
})
|
|
135
|
+
const pruned = kept.join("\n")
|
|
136
|
+
try {
|
|
137
|
+
const before = recordOf(parseJsonc(text))
|
|
138
|
+
const after = recordOf(parseJsonc(pruned))
|
|
139
|
+
const expected = Object.fromEntries(
|
|
140
|
+
Object.entries(recordOf(before.packages)).filter(([key]) => !dropped(key)),
|
|
141
|
+
)
|
|
142
|
+
const same = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b)
|
|
143
|
+
if (!same(recordOf(after.packages), expected)) return undefined
|
|
144
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
145
|
+
if (key !== "packages" && !same(before[key], after[key])) return undefined
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
return undefined
|
|
149
|
+
}
|
|
150
|
+
return pruned
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The `bun update` that makes Bun read each linked package.json again. */
|
|
154
|
+
export const linkLockUpdate = (entries: readonly StaleLinkLock[]): string =>
|
|
155
|
+
`bun update ${entries.map((entry) => entry.package).join(" ")}`
|
|
156
|
+
|
|
157
|
+
/** The advisory both `nifra doctor` and `nifra check` print. */
|
|
158
|
+
export function staleLinkLockMessage(stale: {
|
|
159
|
+
readonly lock: string
|
|
160
|
+
readonly entries: readonly StaleLinkLock[]
|
|
161
|
+
}): string {
|
|
162
|
+
const listed = stale.entries
|
|
163
|
+
.map((entry) => {
|
|
164
|
+
const shown = entry.changes.slice(0, 3).map(describeChange).join(", ")
|
|
165
|
+
const more = entry.changes.length > 3 ? ` and ${entry.changes.length - 3} more` : ""
|
|
166
|
+
return `${entry.package} (file:${entry.path}): ${shown}${more}`
|
|
167
|
+
})
|
|
168
|
+
.join("; ")
|
|
169
|
+
return (
|
|
170
|
+
`${stale.lock} records dependencies its file: packages no longer declare, and Bun never reads a linked package.json again, so it installs those versions beside the declared ones: ${listed}. ` +
|
|
171
|
+
`Run \`${linkLockUpdate(stale.entries)}\`, or \`nifra upgrade --write\` to drop the entries, then \`bun install\`.`
|
|
172
|
+
)
|
|
173
|
+
}
|
package/src/mcp-context.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { AppLoader } from "./load.ts"
|
|
|
12
12
|
import { createCachedAppLoader } from "./mcp-exec.ts"
|
|
13
13
|
import { resolveMcpProjectPath } from "./mcp-path.ts"
|
|
14
14
|
import type { McpPrompt, McpResource, McpServerFeatures, McpTool } from "./mcp-protocol.ts"
|
|
15
|
+
import { writeTargetOf } from "./project-path.ts"
|
|
15
16
|
|
|
16
17
|
function openApiFormat(args: Record<string, unknown>): "json" | "yaml" {
|
|
17
18
|
const format = args.format
|
|
@@ -186,24 +187,10 @@ export function resolveProjectDir(root: string, dir: string | undefined): string
|
|
|
186
187
|
const lexical = relative(root, target)
|
|
187
188
|
return lexical === "" || (!lexical.startsWith("..") && !isAbsolute(lexical)) ? target : null
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const canonicalProbe = realpathSync(probe)
|
|
194
|
-
const rel = relative(canonicalRoot, canonicalProbe)
|
|
195
|
-
if (rel.startsWith("..") || isAbsolute(rel)) return null
|
|
196
|
-
return missing.length === 0 ? canonicalProbe : resolve(canonicalProbe, ...missing.reverse())
|
|
197
|
-
} catch {
|
|
198
|
-
const parent = resolve(probe, "..")
|
|
199
|
-
if (parent === probe) return null
|
|
200
|
-
// `basename`, not a slice past `parent`: when `parent` is the filesystem root its trailing
|
|
201
|
-
// separator is part of it, so `parent.length + 1` eats the first character of the segment and
|
|
202
|
-
// the path gets rebuilt wrong.
|
|
203
|
-
missing.push(basename(probe))
|
|
204
|
-
probe = parent
|
|
205
|
-
}
|
|
206
|
-
}
|
|
190
|
+
const canonical = writeTargetOf(target)
|
|
191
|
+
if (canonical === undefined) return null
|
|
192
|
+
const rel = relative(canonicalRoot, canonical)
|
|
193
|
+
return rel.startsWith("..") || isAbsolute(rel) ? null : canonical
|
|
207
194
|
}
|
|
208
195
|
|
|
209
196
|
/** Consistent error string for a `dir` that escapes the project root. */
|
package/src/mcp-delegate.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* answer still reads as authoritative. So the server settles the version before it serves:
|
|
7
7
|
*
|
|
8
8
|
* 1. The project installs its own `@nifrajs/cli` at a different version: hand the whole session to
|
|
9
|
-
* that CLI (`
|
|
9
|
+
* that CLI (its `bin` script, run by this Bun with `--no-env-file`, stdio inherited) and step aside.
|
|
10
10
|
* 2. Handing off is impossible (no project CLI, a missing bin, or this process IS the hand-off and
|
|
11
11
|
* the versions still disagree): serve, but the version-sensitive tools refuse with the fix
|
|
12
12
|
* instead of answering for the wrong release.
|
|
@@ -31,27 +31,37 @@ export const VERSION_SENSITIVE_TOOLS: ReadonlySet<string> = new Set([
|
|
|
31
31
|
"nifra_contracts",
|
|
32
32
|
])
|
|
33
33
|
|
|
34
|
-
/** The project's own CLI: its version and, when
|
|
34
|
+
/** The project's own CLI: its version and, when it is on disk, the script its `bin` names. */
|
|
35
35
|
export interface ProjectCli {
|
|
36
36
|
readonly version: string
|
|
37
37
|
readonly bin?: string
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const BIN_NAME = process.platform === "win32" ? "nifra.exe" : "nifra"
|
|
41
40
|
const MAX_ANCESTOR_DIRS = 8
|
|
42
41
|
|
|
42
|
+
function binScript(bin: unknown): string | undefined {
|
|
43
|
+
if (typeof bin === "string") return bin
|
|
44
|
+
if (typeof bin !== "object" || bin === null) return undefined
|
|
45
|
+
const named: unknown = Reflect.get(bin, "nifra")
|
|
46
|
+
return typeof named === "string" ? named : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
/** The nearest `@nifrajs/cli` install at or above `root` (a monorepo app hoists to the repo root). */
|
|
44
50
|
export async function findProjectCli(root: string): Promise<ProjectCli | undefined> {
|
|
45
51
|
let dir = root
|
|
46
52
|
for (let depth = 0; depth < MAX_ANCESTOR_DIRS; depth++) {
|
|
47
|
-
const
|
|
53
|
+
const pkg = join(dir, "node_modules", "@nifrajs", "cli")
|
|
48
54
|
try {
|
|
49
|
-
const meta = JSON.parse(
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const meta = JSON.parse(await readFile(join(pkg, "package.json"), "utf8")) as {
|
|
56
|
+
version?: unknown
|
|
57
|
+
bin?: unknown
|
|
58
|
+
}
|
|
52
59
|
if (typeof meta.version === "string" && meta.version.length > 0) {
|
|
53
|
-
const
|
|
54
|
-
|
|
60
|
+
const script = binScript(meta.bin)
|
|
61
|
+
const bin = script === undefined ? undefined : join(pkg, script)
|
|
62
|
+
return bin !== undefined && existsSync(bin)
|
|
63
|
+
? { version: meta.version, bin }
|
|
64
|
+
: { version: meta.version }
|
|
55
65
|
}
|
|
56
66
|
} catch {
|
|
57
67
|
// Not installed at this level - keep walking up.
|
|
@@ -79,7 +89,9 @@ export async function delegateToProjectCli(options: {
|
|
|
79
89
|
const cli = await findProjectCli(options.root)
|
|
80
90
|
if (cli === undefined || cli.version === options.version || cli.bin === undefined)
|
|
81
91
|
return undefined
|
|
82
|
-
|
|
92
|
+
// Not the `.bin` shim: its `bun` would load the project's `.env`, and the inherited
|
|
93
|
+
// NIFRA_MCP_WITHOUT_ENV_FILES then tells that CLI the values are already gone.
|
|
94
|
+
return handOffSession([process.execPath, "--no-env-file", cli.bin, "mcp", ...options.args], {
|
|
83
95
|
cwd: options.cwd,
|
|
84
96
|
env: { ...process.env, [MCP_DELEGATED_ENV]: "1" },
|
|
85
97
|
announce: `[nifra] mcp: this CLI is ${options.version}; the project installs @nifrajs/cli ${cli.version} - serving this session from ${cli.bin}`,
|
package/src/mcp-exec.ts
CHANGED
|
@@ -36,6 +36,8 @@ import {
|
|
|
36
36
|
CHILD_INPUT_MAX_BYTES,
|
|
37
37
|
CHILD_OUTPUT_MAX_BYTES,
|
|
38
38
|
CHILD_TIMEOUT_MS,
|
|
39
|
+
type EscalatingStop,
|
|
40
|
+
escalatingStop,
|
|
39
41
|
OWN_PROCESS_GROUP,
|
|
40
42
|
readBoundedStream,
|
|
41
43
|
signalProcessGroup,
|
|
@@ -290,14 +292,14 @@ export function projectTools(
|
|
|
290
292
|
{
|
|
291
293
|
name: "nifra_explain",
|
|
292
294
|
description:
|
|
293
|
-
"Turn a nifra error into a STRUCTURED diagnostic instead of eyeballing a stack trace: a stable `code`, the top frame in YOUR source, a codeframe around the offending line, and - when nifra recognises the failure - the plain-language `cause` + `fix` + docs anchor. Pass `error` (and `stack` if you have it, e.g. from nifra_run/nifra_test output or a failing build) to explain a specific failure. With no `error`, returns the running dev server's most recent error of any kind (SSR, loader, API, build, browser, hydration) with its request id - the server is found automatically; `port`/`dir` pick one when several run. nifra_errors lists them all. Returns the same JSON the dev overlay renders.",
|
|
295
|
+
"Turn a nifra error into a STRUCTURED diagnostic instead of eyeballing a stack trace: a stable `code`, the top frame in YOUR source, a codeframe around the offending line, and - when nifra recognises the failure - the plain-language `cause` + `fix` + docs anchor. Pass `error` (and `stack` if you have it, e.g. from nifra_run/nifra_test output or a failing build) to explain a specific failure. With no `error`, returns the running dev server's most recent error of any kind (SSR, loader, API, build, browser, hydration) with its request id - the server is found automatically; `port`/`dir` pick one when several run. nifra_errors lists them all. Returns the same JSON the dev overlay renders. Pass a rule code such as `NF-C007` as `error` (no `stack`) to get that `nifra check` rule's title, why it matters, its fix and its docs page.",
|
|
294
296
|
inputSchema: {
|
|
295
297
|
type: "object",
|
|
296
298
|
properties: {
|
|
297
299
|
error: {
|
|
298
300
|
type: "string",
|
|
299
301
|
description:
|
|
300
|
-
"The error message to explain (copy it from nifra_run/nifra_test output or a failing build).",
|
|
302
|
+
"The error message to explain (copy it from nifra_run/nifra_test output or a failing build), or a rule code such as NF-C007.",
|
|
301
303
|
},
|
|
302
304
|
stack: {
|
|
303
305
|
type: "string",
|
|
@@ -329,6 +331,9 @@ export function projectTools(
|
|
|
329
331
|
port?: number
|
|
330
332
|
dir?: string
|
|
331
333
|
}
|
|
334
|
+
const { explainRule, RULE_CODE_SHAPE } = await import("./rule-explain.ts")
|
|
335
|
+
if (stack === undefined && error !== undefined && RULE_CODE_SHAPE.test(error.trim()))
|
|
336
|
+
return JSON.stringify(await explainRule(error.trim()), null, 2)
|
|
332
337
|
if (error !== undefined || stack !== undefined) {
|
|
333
338
|
const { buildDiagnostic } = await import("@nifrajs/web/diagnostic")
|
|
334
339
|
const e = new Error(error ?? "")
|
|
@@ -714,11 +719,12 @@ export async function spawnChild(
|
|
|
714
719
|
stderr: "pipe",
|
|
715
720
|
detached: OWN_PROCESS_GROUP,
|
|
716
721
|
})
|
|
722
|
+
const stopper = escalatingStop((name) => signalProcessGroup(proc, name))
|
|
717
723
|
let killed = false
|
|
718
724
|
const kill = (): void => {
|
|
719
725
|
if (killed) return
|
|
720
726
|
killed = true
|
|
721
|
-
|
|
727
|
+
stopper.stop()
|
|
722
728
|
}
|
|
723
729
|
const abort = (): void => kill()
|
|
724
730
|
signal?.addEventListener("abort", abort, { once: true })
|
|
@@ -759,6 +765,7 @@ export async function spawnChild(
|
|
|
759
765
|
return text || `${label} failed:\n${err.text.trim() || "(no output)"}`
|
|
760
766
|
} finally {
|
|
761
767
|
clearTimeout(timer)
|
|
768
|
+
stopper.dispose()
|
|
762
769
|
signal?.removeEventListener("abort", abort)
|
|
763
770
|
}
|
|
764
771
|
}
|
|
@@ -838,6 +845,7 @@ export class WarmWorker {
|
|
|
838
845
|
readonly cleanup: () => void
|
|
839
846
|
}
|
|
840
847
|
>()
|
|
848
|
+
private readonly stopper: EscalatingStop
|
|
841
849
|
private stdoutBuffer = ""
|
|
842
850
|
private stdoutBufferBytes = 0
|
|
843
851
|
private stderrBuffer = ""
|
|
@@ -858,11 +866,13 @@ export class WarmWorker {
|
|
|
858
866
|
stdout: "pipe",
|
|
859
867
|
stderr: "pipe",
|
|
860
868
|
}) as PipeSubprocess
|
|
869
|
+
this.stopper = escalatingStop((name) => this.proc.kill(name))
|
|
861
870
|
liveWarmWorkers.add(this)
|
|
862
871
|
void this.readStdout()
|
|
863
872
|
void this.readStderr()
|
|
864
873
|
void this.proc.exited.then((code) => {
|
|
865
874
|
this.closed = true
|
|
875
|
+
this.stopper.dispose()
|
|
866
876
|
liveWarmWorkers.delete(this)
|
|
867
877
|
const err = new Error(
|
|
868
878
|
`warm ${this.label} worker exited (${code})${this.stderrBuffer ? `:\n${this.stderrBuffer}` : ""}`,
|
|
@@ -876,7 +886,7 @@ export class WarmWorker {
|
|
|
876
886
|
}
|
|
877
887
|
|
|
878
888
|
stop(): void {
|
|
879
|
-
if (!this.closed) this.
|
|
889
|
+
if (!this.closed) this.stopper.stop()
|
|
880
890
|
}
|
|
881
891
|
|
|
882
892
|
async request(input: unknown, signal?: AbortSignal): Promise<string> {
|
package/src/mcp-http.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
|
|
|
29
29
|
export type { TypeEntry } from "./types-search.ts"
|
|
30
30
|
|
|
31
31
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
32
|
-
const VERSION = "5.
|
|
32
|
+
const VERSION = "5.2.0"
|
|
33
33
|
const SERVER_INFO = { name: "nifra-docs", version: VERSION }
|
|
34
34
|
// Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
|
|
35
35
|
const docsHealth = (tools: McpTool[]): string =>
|
package/src/mcp-io.ts
CHANGED
|
@@ -36,6 +36,39 @@ export function signalProcessGroup(
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** How long a stopped child gets to exit after SIGTERM before it is sent SIGKILL. */
|
|
40
|
+
export const KILL_GRACE_MS = 2_000
|
|
41
|
+
|
|
42
|
+
/** Stopping a child: `stop` sends SIGTERM, `dispose` drops the SIGKILL still pending once it is done. */
|
|
43
|
+
export interface EscalatingStop {
|
|
44
|
+
readonly stop: () => void
|
|
45
|
+
readonly dispose: () => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Stop a child with SIGTERM, then SIGKILL once `graceMs` passes. Project code can catch SIGTERM
|
|
50
|
+
* (a graceful-shutdown hook waiting on a hung request), and a child that never exits keeps its
|
|
51
|
+
* caller waiting and outlives it. `send` delivers one signal to the child or its group.
|
|
52
|
+
*/
|
|
53
|
+
export function escalatingStop(
|
|
54
|
+
send: (signal: NodeJS.Signals) => void,
|
|
55
|
+
graceMs: number = KILL_GRACE_MS,
|
|
56
|
+
): EscalatingStop {
|
|
57
|
+
let escalation: ReturnType<typeof setTimeout> | undefined
|
|
58
|
+
let disposed = false
|
|
59
|
+
return {
|
|
60
|
+
stop: () => {
|
|
61
|
+
if (disposed) return
|
|
62
|
+
send("SIGTERM")
|
|
63
|
+
escalation ??= setTimeout(() => send("SIGKILL"), graceMs)
|
|
64
|
+
},
|
|
65
|
+
dispose: () => {
|
|
66
|
+
disposed = true
|
|
67
|
+
clearTimeout(escalation)
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
39
72
|
const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"] as const
|
|
40
73
|
|
|
41
74
|
/**
|