@nifrajs/cli 5.8.0 → 5.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +134 -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-scan.d.ts +2 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +54 -86
- 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 +20 -23
- 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 +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -30
- 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.map +1 -1
- package/dist/internal/source-facts.js +28 -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 +6 -1
- package/dist/load.d.ts.map +1 -1
- 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-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-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.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 +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +9 -13
- package/dist/review.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/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/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 +402 -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/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 +32 -2
- package/docs/llms-full.txt +749 -95
- package/docs/types.json +300 -61
- 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-scan.ts +65 -82
- package/src/check.ts +25 -23
- package/src/cli.ts +61 -13
- package/src/command-catalog.ts +22 -32
- 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 +39 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +6 -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-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.9.0.ts +42 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +12 -15
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- 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 +463 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
|
@@ -151,6 +151,27 @@ const REGISTRATION_METHODS: ReadonlySet<string> = new Set([
|
|
|
151
151
|
"all",
|
|
152
152
|
])
|
|
153
153
|
|
|
154
|
+
/** A route registration such as `app.get("/path", handler)`: its method name, path, and the arguments after the path. */
|
|
155
|
+
function routeRegistration(
|
|
156
|
+
ts: TypeScriptApi,
|
|
157
|
+
node: TSApi.Node,
|
|
158
|
+
):
|
|
159
|
+
| {
|
|
160
|
+
readonly name: TSApi.MemberName
|
|
161
|
+
readonly method: string
|
|
162
|
+
readonly path: string
|
|
163
|
+
readonly rest: readonly TSApi.Expression[]
|
|
164
|
+
}
|
|
165
|
+
| undefined {
|
|
166
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
167
|
+
return undefined
|
|
168
|
+
const method = node.expression.name.text
|
|
169
|
+
const [first, ...rest] = node.arguments
|
|
170
|
+
if (!REGISTRATION_METHODS.has(method) || first === undefined || !ts.isStringLiteralLike(first))
|
|
171
|
+
return undefined
|
|
172
|
+
return { name: node.expression.name, method, path: first.text, rest }
|
|
173
|
+
}
|
|
174
|
+
|
|
154
175
|
const ZOD_MODULES: ReadonlySet<string> = new Set(["zod", "zod/v4", "zod/mini", "zod/v4/mini"])
|
|
155
176
|
|
|
156
177
|
/** The names `source` binds zod's namespace to (`z`), and those it binds zod's `coerce` to. */
|
|
@@ -707,15 +728,9 @@ export function createSourceFacts(
|
|
|
707
728
|
const routes: UndeclaredResponseRoute[] = []
|
|
708
729
|
const visit = (node: TSApi.Node): void => {
|
|
709
730
|
ts.forEachChild(node, visit)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
const
|
|
713
|
-
if (
|
|
714
|
-
!REGISTRATION_METHODS.has(method) ||
|
|
715
|
-
first === undefined ||
|
|
716
|
-
!ts.isStringLiteralLike(first)
|
|
717
|
-
)
|
|
718
|
-
return
|
|
731
|
+
const registration = routeRegistration(ts, node)
|
|
732
|
+
if (registration === undefined) return
|
|
733
|
+
const { name, method, path, rest } = registration
|
|
719
734
|
const handlers: FunctionNode[] = []
|
|
720
735
|
for (const argument of rest.map((value) => unwrapExpression(ts, value))) {
|
|
721
736
|
const local = ts.isIdentifier(argument) ? locals.get(argument.text) : undefined
|
|
@@ -723,13 +738,10 @@ export function createSourceFacts(
|
|
|
723
738
|
else if (local !== undefined) handlers.push(...local)
|
|
724
739
|
else if (!ts.isObjectLiteralExpression(argument) || declaresResponse(ts, argument)) return
|
|
725
740
|
}
|
|
726
|
-
|
|
741
|
+
// Every registration takes a handler: `headers.get("etag")` and `map.get("/")` are reads.
|
|
742
|
+
if (handlers.length === 0 || handlers.every((fn) => raw.isUntypedAt(fn.getStart(source))))
|
|
727
743
|
return
|
|
728
|
-
routes.push({
|
|
729
|
-
position: node.expression.name.getStart(source),
|
|
730
|
-
method: method.toUpperCase(),
|
|
731
|
-
path: first.text,
|
|
732
|
-
})
|
|
744
|
+
routes.push({ position: name.getStart(source), method: method.toUpperCase(), path })
|
|
733
745
|
}
|
|
734
746
|
visit(source)
|
|
735
747
|
return routes.sort((a, b) => a.position - b.position)
|
|
@@ -783,19 +795,17 @@ export function createSourceFacts(
|
|
|
783
795
|
}
|
|
784
796
|
const visit = (node: TSApi.Node): void => {
|
|
785
797
|
ts.forEachChild(node, visit)
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
)
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
const named = ts.isIdentifier(options) ? consts.get(options.text) : undefined
|
|
798
|
-
if (named !== undefined) options = unwrapExpression(ts, named)
|
|
798
|
+
const registration = routeRegistration(ts, node)
|
|
799
|
+
if (registration === undefined) return
|
|
800
|
+
const { method, path, rest } = registration
|
|
801
|
+
const arguments_ = rest.map((argument) => {
|
|
802
|
+
const value = unwrapExpression(ts, argument)
|
|
803
|
+
const named = ts.isIdentifier(value) ? consts.get(value.text) : undefined
|
|
804
|
+
return named === undefined ? value : unwrapExpression(ts, named)
|
|
805
|
+
})
|
|
806
|
+
// Every registration takes a handler: `config.get("key", { query })` is not a route.
|
|
807
|
+
if (arguments_.every((value) => ts.isObjectLiteralExpression(value))) return
|
|
808
|
+
for (const options of arguments_) {
|
|
799
809
|
if (!ts.isObjectLiteralExpression(options)) continue
|
|
800
810
|
for (const property of options.properties) {
|
|
801
811
|
if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property))
|
|
@@ -806,7 +816,7 @@ export function createSourceFacts(
|
|
|
806
816
|
: undefined
|
|
807
817
|
if (slot !== "query" && slot !== "headers" && slot !== "cookies") continue
|
|
808
818
|
const value = ts.isPropertyAssignment(property) ? property.initializer : property.name
|
|
809
|
-
reach(value, new Set(), { slot, method: method.toUpperCase(), path
|
|
819
|
+
reach(value, new Set(), { slot, method: method.toUpperCase(), path })
|
|
810
820
|
}
|
|
811
821
|
}
|
|
812
822
|
}
|
package/src/introspect.ts
CHANGED
|
@@ -12,10 +12,15 @@ import {
|
|
|
12
12
|
reflectedRoutesFromEvidence,
|
|
13
13
|
snapshotProjectEvidence,
|
|
14
14
|
} from "@nifrajs/core/evidence"
|
|
15
|
-
import { compileRoutePattern, type RoutePatternSegment } from "@nifrajs/core/pattern"
|
|
16
15
|
import type { ReflectedMount, ReflectedRoute } from "@nifrajs/core/reflection"
|
|
17
16
|
import type { Manifest } from "@nifrajs/web"
|
|
18
17
|
import { discoverRoutes } from "@nifrajs/web/fs"
|
|
18
|
+
import {
|
|
19
|
+
clientCall,
|
|
20
|
+
clientChain,
|
|
21
|
+
tsTypeOf,
|
|
22
|
+
typedClientKey,
|
|
23
|
+
} from "@nifrajs/web/internal/client-call"
|
|
19
24
|
import { normalizeMountPath } from "@nifrajs/web/route-manifest"
|
|
20
25
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
21
26
|
import type { IntrospectedApp } from "./load.ts"
|
|
@@ -26,64 +31,6 @@ export function backendRoutes(backend: unknown): readonly ReflectedRoute[] {
|
|
|
26
31
|
return reflectedRoutesFromEvidence(snapshotProjectEvidence(backend))
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
interface JsonSchemaNode {
|
|
30
|
-
readonly type?: unknown
|
|
31
|
-
readonly properties?: Record<string, unknown>
|
|
32
|
-
readonly required?: unknown
|
|
33
|
-
readonly items?: unknown
|
|
34
|
-
readonly additionalProperties?: unknown
|
|
35
|
-
readonly anyOf?: unknown
|
|
36
|
-
readonly oneOf?: unknown
|
|
37
|
-
readonly enum?: unknown
|
|
38
|
-
readonly const?: unknown
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Render a JSON Schema as a compact TypeScript-like type (`{ id: string, name?: string }`) - the
|
|
43
|
-
* shape agents already think in, at a fraction of the raw JSON Schema's tokens (~70-80% smaller).
|
|
44
|
-
* Anything the renderer doesn't model falls back to the raw JSON for that subtree, so the output
|
|
45
|
-
* is always faithful, just not always minimal.
|
|
46
|
-
*/
|
|
47
|
-
export function tsTypeOf(schema: unknown, depth = 0): string {
|
|
48
|
-
if (typeof schema !== "object" || schema === null || depth > 6) return JSON.stringify(schema)
|
|
49
|
-
const node = schema as JsonSchemaNode
|
|
50
|
-
const union = (node.anyOf ?? node.oneOf) as unknown[] | undefined
|
|
51
|
-
if (Array.isArray(union)) return union.map((u) => tsTypeOf(u, depth + 1)).join(" | ")
|
|
52
|
-
if (Array.isArray(node.enum)) return node.enum.map((v) => JSON.stringify(v)).join(" | ")
|
|
53
|
-
if (node.const !== undefined) return JSON.stringify(node.const)
|
|
54
|
-
switch (node.type) {
|
|
55
|
-
case "string":
|
|
56
|
-
return "string"
|
|
57
|
-
case "number":
|
|
58
|
-
case "integer":
|
|
59
|
-
return "number"
|
|
60
|
-
case "boolean":
|
|
61
|
-
return "boolean"
|
|
62
|
-
case "null":
|
|
63
|
-
return "null"
|
|
64
|
-
case "array": {
|
|
65
|
-
const item = tsTypeOf(node.items, depth + 1)
|
|
66
|
-
// Parenthesize unions so `(A | B)[]` reads as the array it is.
|
|
67
|
-
return item.includes(" | ") ? `(${item})[]` : `${item}[]`
|
|
68
|
-
}
|
|
69
|
-
case "object": {
|
|
70
|
-
const props = node.properties
|
|
71
|
-
if (props === undefined) {
|
|
72
|
-
return node.additionalProperties === undefined || node.additionalProperties === false
|
|
73
|
-
? "{}"
|
|
74
|
-
: `Record<string, ${node.additionalProperties === true ? "unknown" : tsTypeOf(node.additionalProperties, depth + 1)}>`
|
|
75
|
-
}
|
|
76
|
-
const required = new Set(Array.isArray(node.required) ? (node.required as string[]) : [])
|
|
77
|
-
const fields = Object.entries(props).map(
|
|
78
|
-
([key, value]) => `${key}${required.has(key) ? "" : "?"}: ${tsTypeOf(value, depth + 1)}`,
|
|
79
|
-
)
|
|
80
|
-
return `{ ${fields.join(", ")} }`
|
|
81
|
-
}
|
|
82
|
-
default:
|
|
83
|
-
return JSON.stringify(schema)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
34
|
/** One route's request/response field shapes, indented under its line. Reads the declared schemas off the
|
|
88
35
|
* descriptor so an agent gets the exact input + output contract - not just "this route is validated". */
|
|
89
36
|
function schemaLines(schema: ReflectedRoute["schema"]): string[] {
|
|
@@ -103,95 +50,14 @@ function schemaLines(schema: ReflectedRoute["schema"]): string[] {
|
|
|
103
50
|
return out
|
|
104
51
|
}
|
|
105
52
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"delete",
|
|
115
|
-
"head",
|
|
116
|
-
"options",
|
|
117
|
-
])
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* The call a non-static segment adds to the chain, or `undefined` for a static one. The segment is
|
|
121
|
-
* read by the router's own grammar, so the spelling matches what the typed client accepts:
|
|
122
|
-
* - a whole param or a wildcard is called by its name - `:id` and `:id{[0-9]+}` are `({ id })`;
|
|
123
|
-
* - a segment that is part literal, part parameter is called with the segment text -
|
|
124
|
-
* `:name.json` is ``(`${name}.json`)``.
|
|
125
|
-
*/
|
|
126
|
-
function paramCall(seg: string): string | undefined {
|
|
127
|
-
let segment: RoutePatternSegment | undefined
|
|
128
|
-
try {
|
|
129
|
-
segment = compileRoutePattern(`/${seg}`).segments[0]
|
|
130
|
-
} catch {
|
|
131
|
-
return undefined
|
|
132
|
-
}
|
|
133
|
-
if (segment === undefined || segment.kind === "static") return undefined
|
|
134
|
-
if (segment.kind === "param") return `({ ${segment.name} })`
|
|
135
|
-
if (segment.kind === "wildcard") {
|
|
136
|
-
return segment.name === "*" ? '({ "*": rest })' : `({ ${segment.name} })`
|
|
137
|
-
}
|
|
138
|
-
const [only] = segment.parts
|
|
139
|
-
if (segment.parts.length === 1 && only?.t === "param") return `({ ${only.name} })`
|
|
140
|
-
const text = segment.parts
|
|
141
|
-
.map((part) => (part.t === "lit" ? part.v.replace(/[`\\]|\$\{/g, "\\$&") : `\${${part.name}}`))
|
|
142
|
-
.join("")
|
|
143
|
-
return `(\`${text}\`)`
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* The typed-client proxy chain for a path, without the terminal verb call. Shared by `clientCall`
|
|
148
|
-
* and the `nifra routes` collision annotation so both teach exactly one spelling.
|
|
149
|
-
*/
|
|
150
|
-
function clientChain(path: string): string {
|
|
151
|
-
const segs = path.split("/").filter((seg) => seg !== "")
|
|
152
|
-
if (segs.length === 0) return "api.index"
|
|
153
|
-
let chain = "api"
|
|
154
|
-
for (const seg of segs) {
|
|
155
|
-
const call = paramCall(seg)
|
|
156
|
-
if (call !== undefined) chain += call
|
|
157
|
-
else if (reservedKeyFor(seg) !== undefined) chain += `(${JSON.stringify(seg)})`
|
|
158
|
-
else chain += IDENT.test(seg) ? `.${seg}` : `[${JSON.stringify(seg)}]`
|
|
159
|
-
}
|
|
160
|
-
return chain
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* The typed-client call form for a route - the exact `client<typeof app>` proxy chain an agent should
|
|
165
|
-
* write, derived from the same convention `@nifrajs/client` implements (so it never has to read the
|
|
166
|
-
* client tests to learn it): a static segment is a property (`.users`), a path param/wildcard is a call
|
|
167
|
-
* that appends the value (`({ id })`), a segment that is part literal, part parameter is a call with
|
|
168
|
-
* the segment text (``(`${name}.json`)``), the root path is `.index`, and the HTTP verb is the terminal call.
|
|
169
|
-
* Body verbs (POST/PUT/PATCH) take the body first then call-options; other verbs take call-options first -
|
|
170
|
-
* so the `{ query }` argument lands in the right slot for each.
|
|
171
|
-
*
|
|
172
|
-
* A segment spelling a reserved proxy key (`delete`, `subscribe`, `then`, ...) is emitted as a call on
|
|
173
|
-
* the parent node instead - and NOT as bracket access, which does not help: the proxy intercepts the
|
|
174
|
-
* key however it is spelled. Emitting `.delete` here would hand an agent a chain that resolves the
|
|
175
|
-
* DELETE verb and silently requests the wrong path.
|
|
176
|
-
*/
|
|
177
|
-
export function clientCall(method: string, path: string, schema: unknown): string {
|
|
178
|
-
const s = schema as { body?: unknown; query?: unknown } | undefined
|
|
179
|
-
const verb = method.toLowerCase()
|
|
180
|
-
// The typed client has a call for the standard methods only; any other method goes out through
|
|
181
|
-
// `fetch`, against the route's own path.
|
|
182
|
-
if (!TYPED_VERBS.has(verb)) return `await fetch(url, { method: ${JSON.stringify(method)} })`
|
|
183
|
-
const chain = clientChain(path)
|
|
184
|
-
const isBodyVerb = verb === "post" || verb === "put" || verb === "patch"
|
|
185
|
-
let call: string
|
|
186
|
-
if (isBodyVerb) {
|
|
187
|
-
// body is the 1st arg; if a route has a query but no body, the body slot must still be filled.
|
|
188
|
-
const bodyArg = s?.body ? "body" : s?.query ? "undefined" : ""
|
|
189
|
-
const opts = s?.query ? (bodyArg ? ", { query }" : "{ query }") : ""
|
|
190
|
-
call = `.${verb}(${bodyArg}${opts})`
|
|
191
|
-
} else {
|
|
192
|
-
call = `.${verb}(${s?.query ? "{ query }" : ""})`
|
|
193
|
-
}
|
|
194
|
-
return `await ${chain}${call}`
|
|
53
|
+
/** A route's `call` line, with what the call returns, or why there is no typed call. */
|
|
54
|
+
function callLine(route: ReflectedRoute): string {
|
|
55
|
+
const call = ` - call: \`${clientCall(route.method, route.path, route.schema)}\``
|
|
56
|
+
if (route.method === "WS")
|
|
57
|
+
return `${call} → a WebSocket handle (\`send\`, \`messages()\`, \`close\`)`
|
|
58
|
+
return typedClientKey(route.method) !== undefined
|
|
59
|
+
? `${call} → \`{ ok, status, data, error }\``
|
|
60
|
+
: `${call} (no typed-client call for this method; \`url\` is the path above)`
|
|
195
61
|
}
|
|
196
62
|
|
|
197
63
|
/** Markdown section listing the backend's API routes with their request + response field shapes. */
|
|
@@ -201,14 +67,8 @@ export function apiRoutesSection(routes: readonly ReflectedRoute[]): string {
|
|
|
201
67
|
}
|
|
202
68
|
const lines = [...routes]
|
|
203
69
|
.sort((a, b) => codeUnitOrder(a.path, b.path) || codeUnitOrder(a.method, b.method))
|
|
204
|
-
.flatMap((r) => [
|
|
205
|
-
|
|
206
|
-
...schemaLines(r.schema),
|
|
207
|
-
TYPED_VERBS.has(r.method.toLowerCase())
|
|
208
|
-
? ` - call: \`${clientCall(r.method, r.path, r.schema)}\` → \`{ ok, status, data, error }\``
|
|
209
|
-
: ` - call: \`${clientCall(r.method, r.path, r.schema)}\` (no typed-client call for this method; \`url\` is the path above)`,
|
|
210
|
-
])
|
|
211
|
-
return `## API routes (backend/app.ts)\n\nEach route's \`body\`/\`query\`/\`response\` shape is its contract - the typed client derives request inputs and \`res.data\` from these, so a screen built on \`client<typeof app>\` stays in sync automatically. The \`call\` line is the exact \`client<typeof app>\` form: static path segments are properties, a path param is a call (\`({ id })\`), the verb is the terminal call (body first for POST/PUT/PATCH), and every call returns the never-throwing \`{ ok, status, data, error }\` Result.\n\n${lines.join("\n")}`
|
|
70
|
+
.flatMap((r) => [`- \`${r.method} ${r.path}\``, ...schemaLines(r.schema), callLine(r)])
|
|
71
|
+
return `## API routes (backend/app.ts)\n\nEach route's \`body\`/\`query\`/\`response\` shape is its contract - the typed client derives request inputs and \`res.data\` from these, so a screen built on \`client<typeof app>\` stays in sync automatically. The \`call\` line is the exact \`client<typeof app>\` form: static path segments are properties, a path param is a call (\`({ id })\`), the verb is the terminal call (body first for POST/PUT/PATCH), and every HTTP call returns the never-throwing \`{ ok, status, data, error }\` Result.\n\n${lines.join("\n")}`
|
|
212
72
|
}
|
|
213
73
|
|
|
214
74
|
/** Compact API-routes INDEX for the no-arg `nifra_context` call - `METHOD path` per route, WITHOUT the
|
package/src/levels-tool.ts
CHANGED
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
|
|
14
14
|
import { existsSync } from "node:fs"
|
|
15
15
|
import { resolve } from "node:path"
|
|
16
|
-
import
|
|
17
|
-
AssuranceReport,
|
|
18
|
-
AssuredRoute,
|
|
19
|
-
|
|
20
|
-
InvariantSetupResult,
|
|
21
|
-
InvariantsConfig,
|
|
16
|
+
import {
|
|
17
|
+
type AssuranceReport,
|
|
18
|
+
type AssuredRoute,
|
|
19
|
+
applyInvariantSetup,
|
|
20
|
+
type InvariantSetupResult,
|
|
21
|
+
type InvariantsConfig,
|
|
22
22
|
} from "@nifrajs/core/assurance"
|
|
23
23
|
import { snapshotCapabilities } from "@nifrajs/core/capabilities"
|
|
24
24
|
import { buildNifraManifest, parseNifraManifest } from "@nifrajs/core/manifest"
|
|
@@ -41,6 +41,8 @@ export interface VerificationLevelStatus {
|
|
|
41
41
|
readonly ok: boolean
|
|
42
42
|
/** Why the level does not hold - a gate failure or a missing prerequisite. Empty when ok. */
|
|
43
43
|
readonly reasons: readonly string[]
|
|
44
|
+
/** L4 only: the `"METHOD /path"` witnesses `invariants.setup` returned, when it returned any. */
|
|
45
|
+
readonly setupWitnesses?: readonly string[]
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export interface VerificationLevelsResult {
|
|
@@ -79,7 +81,7 @@ export async function collectVerificationLevels(
|
|
|
79
81
|
...(options.config !== undefined ? { config: options.config } : {}),
|
|
80
82
|
maxDiagnostics: 5,
|
|
81
83
|
})
|
|
82
|
-
const statuses:
|
|
84
|
+
const statuses: LevelStatusDraft[] = []
|
|
83
85
|
|
|
84
86
|
// L0 - typed contract (`nifra check`).
|
|
85
87
|
const check = await verification.check()
|
|
@@ -181,75 +183,81 @@ export async function collectVerificationLevels(
|
|
|
181
183
|
})
|
|
182
184
|
|
|
183
185
|
// L4 - contract-generated invariants against an explicitly isolated executor.
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
186
|
+
const l4 =
|
|
187
|
+
config.invariants === undefined
|
|
188
|
+
? {
|
|
189
|
+
reasons: [
|
|
190
|
+
"no isolated invariant executor configured - add `invariants.executor` in nifra.assurance.ts",
|
|
191
|
+
],
|
|
192
|
+
setupWitnesses: [],
|
|
193
|
+
}
|
|
194
|
+
: await runInvariants(config.source, config.invariants, options.seed ?? 1)
|
|
195
|
+
const l4Status: LevelStatusDraft = {
|
|
193
196
|
level: 4,
|
|
194
197
|
name: "invariant-tested",
|
|
195
|
-
ok:
|
|
196
|
-
reasons:
|
|
197
|
-
}
|
|
198
|
+
ok: l4.reasons.length === 0,
|
|
199
|
+
reasons: l4.reasons,
|
|
200
|
+
}
|
|
201
|
+
if (l4.setupWitnesses.length > 0) l4Status.setupWitnesses = l4.setupWitnesses
|
|
202
|
+
statuses.push(l4Status)
|
|
198
203
|
|
|
199
204
|
return finalize(statuses, assurance.routes)
|
|
200
205
|
}
|
|
201
206
|
|
|
207
|
+
interface LevelStatusDraft {
|
|
208
|
+
level: number
|
|
209
|
+
name: string
|
|
210
|
+
ok: boolean
|
|
211
|
+
reasons: string[]
|
|
212
|
+
setupWitnesses?: readonly string[]
|
|
213
|
+
}
|
|
214
|
+
|
|
202
215
|
/**
|
|
203
|
-
* Run L4 against the configured target. `setup` runs
|
|
204
|
-
*
|
|
205
|
-
*
|
|
216
|
+
* Run L4 against the configured target. `setup` runs once, before the runner generates its first
|
|
217
|
+
* case, so the witnesses and prepareRequest it returns reach every case; its `teardown` runs once the
|
|
218
|
+
* run ends - after a failure too, a malformed setup result included.
|
|
206
219
|
*/
|
|
207
220
|
async function runInvariants(
|
|
208
221
|
source: unknown,
|
|
209
222
|
invariants: InvariantsConfig,
|
|
210
223
|
seed: number,
|
|
211
|
-
): Promise<string[]> {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
): Promise<{ reasons: string[]; setupWitnesses: readonly string[] }> {
|
|
225
|
+
const reasons: string[] = []
|
|
226
|
+
let provisioned: InvariantSetupResult | undefined
|
|
227
|
+
let setupWitnesses: readonly string[] = []
|
|
228
|
+
try {
|
|
229
|
+
let run = invariants
|
|
230
|
+
if (invariants.setup !== undefined) {
|
|
231
|
+
try {
|
|
232
|
+
provisioned = (await invariants.setup()) ?? undefined
|
|
233
|
+
} catch (error) {
|
|
234
|
+
throw new Error(`invariants.setup failed: ${messageOf(error)}`)
|
|
235
|
+
}
|
|
236
|
+
const applied = applyInvariantSetup(invariants, provisioned)
|
|
237
|
+
run = applied.invariants
|
|
238
|
+
setupWitnesses = applied.setupWitnesses
|
|
239
|
+
}
|
|
240
|
+
const executor = run.executor
|
|
227
241
|
if (executor === undefined) {
|
|
228
242
|
throw new Error(
|
|
229
243
|
"no invariant executor: invariants.setup returned none and invariants.executor is not set",
|
|
230
244
|
)
|
|
231
245
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (invariants[name] !== undefined) runOptions[name] = invariants[name]
|
|
243
|
-
}
|
|
244
|
-
const reasons: string[] = []
|
|
245
|
-
try {
|
|
246
|
+
const runOptions: Record<string, unknown> = {}
|
|
247
|
+
for (const name of INVARIANT_RUN_OPTIONS) {
|
|
248
|
+
if (run[name] !== undefined) runOptions[name] = run[name]
|
|
249
|
+
}
|
|
250
|
+
const options: AdversarialContractOptions = {
|
|
251
|
+
seed,
|
|
252
|
+
runtimes: [{ name: "isolated", fetch: executor }],
|
|
253
|
+
expectedValidationStatuses: [400, 422],
|
|
254
|
+
requireCoverage: true,
|
|
255
|
+
}
|
|
246
256
|
const report = await runAdversarialContract(source as ContractTestApp, {
|
|
247
257
|
...options,
|
|
248
258
|
...runOptions,
|
|
249
259
|
})
|
|
250
|
-
|
|
251
|
-
if (target !== undefined) reasons.push(target)
|
|
252
|
-
else if (!report.ok) {
|
|
260
|
+
if (!report.ok) {
|
|
253
261
|
reasons.push(
|
|
254
262
|
...report.failures
|
|
255
263
|
.slice(0, 5)
|
|
@@ -268,18 +276,17 @@ async function runInvariants(
|
|
|
268
276
|
)
|
|
269
277
|
}
|
|
270
278
|
} catch (error) {
|
|
271
|
-
reasons.push(
|
|
279
|
+
reasons.push(messageOf(error))
|
|
272
280
|
} finally {
|
|
273
|
-
|
|
274
|
-
if (ready?.teardown !== undefined) {
|
|
281
|
+
if (typeof provisioned?.teardown === "function") {
|
|
275
282
|
try {
|
|
276
|
-
await
|
|
283
|
+
await provisioned.teardown()
|
|
277
284
|
} catch (error) {
|
|
278
285
|
reasons.push(`invariants teardown failed: ${messageOf(error)}`)
|
|
279
286
|
}
|
|
280
287
|
}
|
|
281
288
|
}
|
|
282
|
-
return reasons
|
|
289
|
+
return { reasons, setupWitnesses }
|
|
283
290
|
}
|
|
284
291
|
|
|
285
292
|
const INVARIANT_RUN_OPTIONS = [
|
|
@@ -290,28 +297,11 @@ const INVARIANT_RUN_OPTIONS = [
|
|
|
290
297
|
"maxMutationsPerInput",
|
|
291
298
|
] as const
|
|
292
299
|
|
|
293
|
-
/** The setup or missing-executor failure every case hit, if the target never came up. */
|
|
294
|
-
async function targetFailure(
|
|
295
|
-
provisioned: Promise<InvariantSetupResult | undefined> | undefined,
|
|
296
|
-
invariants: InvariantsConfig,
|
|
297
|
-
): Promise<string | undefined> {
|
|
298
|
-
if (provisioned === undefined) return undefined
|
|
299
|
-
try {
|
|
300
|
-
const ready = await provisioned
|
|
301
|
-
if (ready?.executor === undefined && invariants.executor === undefined) {
|
|
302
|
-
return "no invariant executor: invariants.setup returned none and invariants.executor is not set"
|
|
303
|
-
}
|
|
304
|
-
return undefined
|
|
305
|
-
} catch (error) {
|
|
306
|
-
return messageOf(error)
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
300
|
const messageOf = (error: unknown): string =>
|
|
311
301
|
error instanceof Error ? error.message : String(error)
|
|
312
302
|
|
|
313
303
|
function finalize(
|
|
314
|
-
statuses: readonly
|
|
304
|
+
statuses: readonly LevelStatusDraft[],
|
|
315
305
|
routes: readonly AssuredRoute[],
|
|
316
306
|
): VerificationLevelsResult {
|
|
317
307
|
// Cumulative: the achieved level is the last rung with every rung below it also holding.
|
|
@@ -368,6 +358,9 @@ export async function runLevels(
|
|
|
368
358
|
const mark = status.ok ? "✓" : "✗"
|
|
369
359
|
console.log(`${mark} L${status.level} ${status.name}`)
|
|
370
360
|
for (const reason of status.reasons) console.log(` - ${reason}`)
|
|
361
|
+
if (status.setupWitnesses !== undefined) {
|
|
362
|
+
console.log(` witnesses from setup: ${status.setupWitnesses.join(", ")}`)
|
|
363
|
+
}
|
|
371
364
|
}
|
|
372
365
|
console.log(
|
|
373
366
|
`[nifra] response contracts: ${result.responseContracts.status} (${result.responseContracts.enforced} enforced, ${result.responseContracts.warnOnly} warn-only, ${result.responseContracts.typedOnly} typed-only)`,
|
package/src/load.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { existsSync } from "node:fs"
|
|
17
17
|
import { isAbsolute, resolve } from "node:path"
|
|
18
18
|
import type { CreateWebAppOptions, CssLoadingMode } from "@nifrajs/web"
|
|
19
|
-
import type { SecretExemption } from "@nifrajs/web/build"
|
|
19
|
+
import type { SecretExemption, ServerEntrySelfHost } from "@nifrajs/web/build"
|
|
20
20
|
import { assertCurrentLayout, BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
|
|
21
21
|
import { checkPipelineSeparation } from "./pipeline-guard.ts"
|
|
22
22
|
|
|
@@ -77,6 +77,11 @@ export interface NifraFramework {
|
|
|
77
77
|
* is the sole way in: served any other way the header is whatever the client sent. Self-hosting
|
|
78
78
|
* targets use the socket peer either way. */
|
|
79
79
|
readonly clientIp?: "platform"
|
|
80
|
+
/** How the server a `bun`, `node` or `deno` build emits stops and keeps idle connections, `nifra start`
|
|
81
|
+
* included: `gracefulSignals` drains it on SIGTERM and SIGINT, `idleTimeoutSec` is Bun's idle
|
|
82
|
+
* connection timeout. `nifra build` checks it before building; an edge build ignores it. See
|
|
83
|
+
* `ServerEntrySelfHost` in `@nifrajs/web/build`. */
|
|
84
|
+
readonly selfHost?: ServerEntrySelfHost
|
|
80
85
|
/** `nifra dev` settings. `indicator: false` turns the in-page issues badge off for every run
|
|
81
86
|
* (`nifra dev --no-indicator` does it for one); browser errors still reach `nifra errors`.
|
|
82
87
|
* `allowedHosts` lists host names the Bun dev server answers besides loopback ones; it refuses
|
package/src/local-cli.ts
CHANGED
|
@@ -51,6 +51,18 @@ function ownCore(): string | undefined {
|
|
|
51
51
|
return undefined
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The project's `@nifrajs/core` when this CLI runs another copy - a `bunx` of a new release before the
|
|
56
|
+
* project installs it, say - else `undefined`. Not installed in the project counts as another copy.
|
|
57
|
+
*/
|
|
58
|
+
export function otherProjectCore(cwd: string): { readonly project?: string } | undefined {
|
|
59
|
+
const own = ownCore()
|
|
60
|
+
if (own === undefined) return undefined
|
|
61
|
+
const project = projectCore(cwd)
|
|
62
|
+
if (project === own) return undefined
|
|
63
|
+
return project === undefined ? {} : { project }
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
/**
|
|
55
67
|
* Run `command` through the project's own CLI when this one is another install. Resolves to the
|
|
56
68
|
* child's exit code, or `undefined` when this process should run the command itself: then, if the
|
package/src/mcp-docs-tools.ts
CHANGED
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
|
|
10
10
|
import { renderDocsResult } from "./docs-search.ts"
|
|
11
11
|
import { type Example, renderExamplesResult } from "./examples.ts"
|
|
12
|
-
import { renderFrontendResult } from "./frontend-guidance.ts"
|
|
12
|
+
import { renderFrontendResult, selectFrontendGuidance } from "./frontend-guidance.ts"
|
|
13
13
|
import { renderLearnResult } from "./learn.ts"
|
|
14
14
|
import type { McpTool } from "./mcp-protocol.ts"
|
|
15
|
+
import { renderRuntimeResult, selectRuntimeDifferences } from "./runtime-differences.ts"
|
|
15
16
|
import { renderTypesResult, type TypeEntry } from "./types-search.ts"
|
|
16
17
|
|
|
18
|
+
/** Clamp optional MCP pagination input to a safe, deterministic range. */
|
|
17
19
|
const clamp = (n: number | undefined, lo: number, hi: number, dflt: number): number =>
|
|
18
20
|
Math.min(Math.max(typeof n === "number" ? n : dflt, lo), hi)
|
|
19
21
|
|
|
20
|
-
/** Build
|
|
22
|
+
/** Build the read-only docs, examples, types, learning, and frontend tools over injected loaders. */
|
|
21
23
|
export function docsTools(
|
|
22
24
|
loadDocs: () => Promise<string | undefined>,
|
|
23
25
|
loadExamples: () => Promise<Example[] | undefined>,
|
|
@@ -199,7 +201,53 @@ export function docsTools(
|
|
|
199
201
|
adapter?: string
|
|
200
202
|
limit?: number
|
|
201
203
|
}
|
|
202
|
-
|
|
204
|
+
const input = { symptom, adapter, limit: clamp(limit, 1, 5, 3) }
|
|
205
|
+
return {
|
|
206
|
+
content: [{ type: "text", text: renderFrontendResult(input) }],
|
|
207
|
+
structuredContent: { ...selectFrontendGuidance(input) },
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "nifra_runtime",
|
|
213
|
+
annotations: {
|
|
214
|
+
title: "Runtime differences",
|
|
215
|
+
readOnlyHint: true,
|
|
216
|
+
destructiveHint: false,
|
|
217
|
+
idempotentHint: true,
|
|
218
|
+
openWorldHint: false,
|
|
219
|
+
},
|
|
220
|
+
description:
|
|
221
|
+
'Explain a behavior that differs between Bun, Node, Deno and Cloudflare Workers by symptom. These are runtime behaviors, not Nifra\'s: request-target and Host handling, pipelining, JSON content-type, engine error messages, recursion depth, .env loading, and runtime-specific APIs. Returns what each runtime does, the fix (and the Nifra option that decides it when there is one), how to verify it, and the versions it was measured on. Call with no args for the index; pass `symptom` (e.g. "path guard skipped", "env var undefined") and/or `runtime` to filter.',
|
|
222
|
+
inputSchema: {
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: {
|
|
225
|
+
symptom: {
|
|
226
|
+
type: "string",
|
|
227
|
+
maxLength: 256,
|
|
228
|
+
description: "What you observe (omit for the index).",
|
|
229
|
+
},
|
|
230
|
+
runtime: {
|
|
231
|
+
type: "string",
|
|
232
|
+
enum: ["bun", "node", "deno", "workerd"],
|
|
233
|
+
description: "Filter to one runtime's entries.",
|
|
234
|
+
},
|
|
235
|
+
limit: { type: "number", description: "Max entries to return (default 3, max 5)." },
|
|
236
|
+
},
|
|
237
|
+
additionalProperties: false,
|
|
238
|
+
},
|
|
239
|
+
handler: async (args) => {
|
|
240
|
+
// biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: the MCP layer validated args against inputSchema
|
|
241
|
+
const { symptom, runtime, limit } = args as {
|
|
242
|
+
symptom?: string
|
|
243
|
+
runtime?: string
|
|
244
|
+
limit?: number
|
|
245
|
+
}
|
|
246
|
+
const input = { symptom, runtime, limit: clamp(limit, 1, 5, 3) }
|
|
247
|
+
return {
|
|
248
|
+
content: [{ type: "text", text: renderRuntimeResult(input) }],
|
|
249
|
+
structuredContent: { ...selectRuntimeDifferences(input) },
|
|
250
|
+
}
|
|
203
251
|
},
|
|
204
252
|
},
|
|
205
253
|
]
|