@nifrajs/cli 2.14.1 → 3.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/README.md +10 -0
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +6 -1
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +3 -2
- package/dist/assure.js.map +1 -1
- package/dist/check-diagnostics.d.ts +165 -0
- package/dist/check-diagnostics.d.ts.map +1 -0
- package/dist/check-diagnostics.js +1009 -0
- package/dist/check-diagnostics.js.map +1 -0
- package/dist/check-scan.d.ts +245 -0
- package/dist/check-scan.d.ts.map +1 -0
- package/dist/check-scan.js +1599 -0
- package/dist/check-scan.js.map +1 -0
- package/dist/check.d.ts +4 -324
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +8 -2346
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +285 -10
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +27 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +142 -2
- package/dist/command-catalog.js.map +1 -1
- package/dist/doctor.d.ts +42 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +64 -7
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts +17 -0
- package/dist/env-file.d.ts.map +1 -0
- package/dist/env-file.js +113 -0
- package/dist/env-file.js.map +1 -0
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +91 -15
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.d.ts +57 -0
- package/dist/frontend-guidance.d.ts.map +1 -0
- package/dist/frontend-guidance.js +195 -0
- package/dist/frontend-guidance.js.map +1 -0
- package/dist/internal/reserved-segment-codemod.d.ts +36 -0
- package/dist/internal/reserved-segment-codemod.d.ts.map +1 -0
- package/dist/internal/reserved-segment-codemod.js +134 -0
- package/dist/internal/reserved-segment-codemod.js.map +1 -0
- package/dist/internal/typescript-import.d.ts +1 -1
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +62 -11
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/introspect.d.ts +26 -1
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +74 -24
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +6 -0
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +4 -1
- package/dist/load.js.map +1 -1
- package/dist/mcp-context.d.ts +48 -0
- package/dist/mcp-context.d.ts.map +1 -0
- package/dist/mcp-context.js +215 -0
- package/dist/mcp-context.js.map +1 -0
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +31 -0
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-exec.d.ts +74 -0
- package/dist/mcp-exec.d.ts.map +1 -0
- package/dist/mcp-exec.js +844 -0
- package/dist/mcp-exec.js.map +1 -0
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +26 -0
- package/dist/mcp-io.d.ts.map +1 -0
- package/dist/mcp-io.js +100 -0
- package/dist/mcp-io.js.map +1 -0
- package/dist/mcp-reflect.d.ts +16 -0
- package/dist/mcp-reflect.d.ts.map +1 -0
- package/dist/mcp-reflect.js +101 -0
- package/dist/mcp-reflect.js.map +1 -0
- package/dist/mcp-root.d.ts +7 -0
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +51 -3
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp.d.ts +10 -84
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +13 -1170
- package/dist/mcp.js.map +1 -1
- package/dist/openapi-tool.d.ts +5 -10
- package/dist/openapi-tool.d.ts.map +1 -1
- package/dist/openapi-tool.js +21 -2
- package/dist/openapi-tool.js.map +1 -1
- package/dist/openapi-types.d.ts +21 -0
- package/dist/openapi-types.d.ts.map +1 -0
- package/dist/openapi-types.js +214 -0
- package/dist/openapi-types.js.map +1 -0
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +2 -1
- package/dist/port.js.map +1 -1
- package/dist/project-facts.d.ts +2 -1
- package/dist/project-facts.d.ts.map +1 -1
- package/dist/project-facts.js.map +1 -1
- package/dist/recipes/3.0.0.d.ts +10 -0
- package/dist/recipes/3.0.0.d.ts.map +1 -0
- package/dist/recipes/3.0.0.js +23 -0
- package/dist/recipes/3.0.0.js.map +1 -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/release-verification.d.ts +4 -1
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +6 -123
- package/dist/release-verification.js.map +1 -1
- package/dist/rules/codes.d.ts +4 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +4 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/islands.d.ts +4 -0
- package/dist/rules/islands.d.ts.map +1 -0
- package/dist/rules/islands.js +155 -0
- package/dist/rules/islands.js.map +1 -0
- package/dist/rules/nano.d.ts +6 -0
- package/dist/rules/nano.d.ts.map +1 -0
- package/dist/rules/nano.js +264 -0
- package/dist/rules/nano.js.map +1 -0
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +17 -30
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +38 -4
- package/dist/rules/security.js.map +1 -1
- package/dist/scaffold.d.ts +12 -6
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +149 -10
- package/dist/scaffold.js.map +1 -1
- package/dist/search-terms.d.ts.map +1 -1
- package/dist/search-terms.js +5 -3
- package/dist/search-terms.js.map +1 -1
- package/dist/stylex-migrate.d.ts +38 -0
- package/dist/stylex-migrate.d.ts.map +1 -0
- package/dist/stylex-migrate.js +1052 -0
- package/dist/stylex-migrate.js.map +1 -0
- package/dist/sync-manifest.d.ts.map +1 -1
- package/dist/sync-manifest.js +2 -1
- package/dist/sync-manifest.js.map +1 -1
- package/dist/verification-plan.d.ts +24 -0
- package/dist/verification-plan.d.ts.map +1 -0
- package/dist/verification-plan.js +116 -0
- package/dist/verification-plan.js.map +1 -0
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +6 -3
- package/dist/work-graph.js.map +1 -1
- package/dist/workspace-link.d.ts +37 -0
- package/dist/workspace-link.d.ts.map +1 -0
- package/dist/workspace-link.js +72 -0
- package/dist/workspace-link.js.map +1 -0
- package/docs/examples.json +37 -1
- package/docs/llms-full.txt +1598 -44
- package/docs/types.json +5157 -172
- package/package.json +9 -9
- package/src/assure-hydration.ts +6 -1
- package/src/assure.ts +4 -2
- package/src/check-diagnostics.ts +1219 -0
- package/src/check-scan.ts +1825 -0
- package/src/check.ts +47 -2731
- package/src/cli.ts +291 -10
- package/src/command-catalog.ts +177 -2
- package/src/doctor.ts +99 -8
- package/src/env-file.ts +121 -0
- package/src/fix-recipes.ts +101 -15
- package/src/frontend-guidance.ts +259 -0
- package/src/internal/reserved-segment-codemod.ts +150 -0
- package/src/internal/typescript-import.ts +61 -11
- package/src/introspect.ts +82 -21
- package/src/levels-tool.ts +6 -0
- package/src/load.ts +4 -1
- package/src/mcp-context.ts +266 -0
- package/src/mcp-docs-tools.ts +37 -0
- package/src/mcp-exec.ts +1040 -0
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +118 -0
- package/src/mcp-reflect.ts +140 -0
- package/src/mcp-root.ts +62 -4
- package/src/mcp.ts +61 -1436
- package/src/openapi-tool.ts +32 -2
- package/src/openapi-types.ts +261 -0
- package/src/port.ts +2 -1
- package/src/project-facts.ts +2 -4
- package/src/recipes/3.0.0.ts +24 -0
- package/src/recipes/index.ts +2 -0
- package/src/release-verification.ts +22 -147
- package/src/rules/codes.ts +4 -0
- package/src/rules/islands.ts +171 -0
- package/src/rules/nano.ts +295 -0
- package/src/rules/routes.ts +17 -30
- package/src/rules/security.ts +40 -4
- package/src/scaffold.ts +169 -9
- package/src/search-terms.ts +7 -3
- package/src/stylex-migrate.ts +1139 -0
- package/src/sync-manifest.ts +2 -1
- package/src/verification-plan.ts +242 -0
- package/src/work-graph.ts +6 -3
- package/src/workspace-link.ts +80 -0
package/src/levels-tool.ts
CHANGED
|
@@ -132,6 +132,12 @@ export async function collectVerificationLevels(
|
|
|
132
132
|
if (assurance.ok && (capabilityReport === undefined || capabilityReport.ok)) {
|
|
133
133
|
const current = await buildNifraManifest({
|
|
134
134
|
source: config.source,
|
|
135
|
+
// `evidence` is NOT optional detail here - it is what `nifra manifest emit` and the
|
|
136
|
+
// `versioned trust manifest drift` check in `nifra check` both hash. Omitting it made
|
|
137
|
+
// this recompute a manifest nothing else ever emits, so every app that publishes
|
|
138
|
+
// assurance evidence from outside its `.use()` chain (the `assure()` seam) reported a
|
|
139
|
+
// freshly emitted manifest as stale and could never reach L3.
|
|
140
|
+
...(verification.evidence !== undefined ? { evidence: verification.evidence } : {}),
|
|
135
141
|
assurance,
|
|
136
142
|
...(capabilityReport !== undefined ? { capabilities: capabilityReport } : {}),
|
|
137
143
|
})
|
package/src/load.ts
CHANGED
|
@@ -214,7 +214,10 @@ export async function loadApp(
|
|
|
214
214
|
// and passes through unchanged.
|
|
215
215
|
let clientModule: string
|
|
216
216
|
if (fw.clientModule.startsWith("./") || fw.clientModule.startsWith("../")) {
|
|
217
|
-
|
|
217
|
+
// The value is embedded in generated import source, not passed directly to a filesystem API.
|
|
218
|
+
// Keep it absolute but slash-normalized so the generated module is identical on POSIX and
|
|
219
|
+
// Windows (Bun accepts an absolute drive path with forward slashes).
|
|
220
|
+
clientModule = resolve(cwd, fw.clientModule).replaceAll("\\", "/")
|
|
218
221
|
} else {
|
|
219
222
|
// A specifier that is neither `./`-relative, scoped (`@…`), nor absolute is read as a BARE PACKAGE
|
|
220
223
|
// specifier - resolved against `node_modules`, not `cwd`. If a real local file sits at that path
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project context and trust-local utilities for the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Resources, prompts, path scoping, and monorepo namespacing are independent of the JSON-RPC loop and
|
|
5
|
+
* of backend reflection. App loading is injected through the shared cached loader seam.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { realpathSync } from "node:fs"
|
|
9
|
+
import { readFile } from "node:fs/promises"
|
|
10
|
+
import { basename, isAbsolute, relative, resolve, sep } from "node:path"
|
|
11
|
+
import type { LoadedApp } from "./load.ts"
|
|
12
|
+
import { createCachedAppLoader } from "./mcp-exec.ts"
|
|
13
|
+
import type { McpPrompt, McpResource, McpServerFeatures, McpTool } from "./mcp-protocol.ts"
|
|
14
|
+
|
|
15
|
+
function openApiFormat(args: Record<string, unknown>): "json" | "yaml" {
|
|
16
|
+
const format = args.format
|
|
17
|
+
return format === "yaml" ? "yaml" : "json"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function openApiHandler(
|
|
21
|
+
args: Record<string, unknown>,
|
|
22
|
+
loadAppCached: (outDirName?: string) => Promise<LoadedApp>,
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
const { renderOpenApiWithTypes } = await import("./openapi-tool.ts")
|
|
25
|
+
const pathPrefix = typeof args.path === "string" ? args.path : undefined
|
|
26
|
+
return renderOpenApiWithTypes(await loadAppCached(), openApiFormat(args), pathPrefix)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function readProjectFile(
|
|
30
|
+
cwd: string,
|
|
31
|
+
relativeFile: string,
|
|
32
|
+
maxChars: number,
|
|
33
|
+
): Promise<string> {
|
|
34
|
+
const target = resolve(cwd, relativeFile)
|
|
35
|
+
const root = resolve(cwd)
|
|
36
|
+
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
37
|
+
throw new Error(`refusing to read outside project root: ${relativeFile}`)
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const text = await readFile(target, "utf8")
|
|
41
|
+
return text.length <= maxChars
|
|
42
|
+
? text
|
|
43
|
+
: `${text.slice(0, maxChars)}\n…(trimmed; read ${relativeFile} directly for the rest)`
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (err && typeof err === "object" && (err as { code?: string }).code === "ENOENT") {
|
|
46
|
+
return `No ${relativeFile} found in ${basename(cwd)}.`
|
|
47
|
+
}
|
|
48
|
+
throw err
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function promptText(
|
|
53
|
+
text: string,
|
|
54
|
+
): readonly [
|
|
55
|
+
{ readonly role: "user"; readonly content: { readonly type: "text"; readonly text: string } },
|
|
56
|
+
] {
|
|
57
|
+
return [{ role: "user", content: { type: "text", text } }]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function projectResources(
|
|
61
|
+
cwd: string,
|
|
62
|
+
loadAppCached: (outDirName?: string) => Promise<LoadedApp> = createCachedAppLoader(cwd),
|
|
63
|
+
): McpResource[] {
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
uri: "nifra://routes",
|
|
67
|
+
name: "API routes",
|
|
68
|
+
description:
|
|
69
|
+
"Structured API routes with typed-client calls and compact request/response shapes.",
|
|
70
|
+
mimeType: "application/json",
|
|
71
|
+
read: async () => {
|
|
72
|
+
const { routesToJson } = await import("./introspect.ts")
|
|
73
|
+
return { text: JSON.stringify(routesToJson(await loadAppCached()), null, 2) }
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
uri: "nifra://openapi",
|
|
78
|
+
name: "OpenAPI 3.1",
|
|
79
|
+
description: "OpenAPI document generated from backend.ts using @nifrajs/schema.",
|
|
80
|
+
mimeType: "application/json",
|
|
81
|
+
read: async () => ({ text: await openApiHandler({ format: "json" }, loadAppCached) }),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
uri: "nifra://package-json",
|
|
85
|
+
name: "package.json",
|
|
86
|
+
description: "Project package metadata and scripts.",
|
|
87
|
+
mimeType: "application/json",
|
|
88
|
+
read: async () => ({ text: await readProjectFile(cwd, "package.json", 40_000) }),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
uri: "nifra://agents-md",
|
|
92
|
+
name: "AGENTS.md",
|
|
93
|
+
description: "Repository-specific agent instructions if the project has them.",
|
|
94
|
+
mimeType: "text/markdown",
|
|
95
|
+
read: async () => ({ text: await readProjectFile(cwd, "AGENTS.md", 40_000) }),
|
|
96
|
+
},
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function projectPrompts(): McpPrompt[] {
|
|
101
|
+
return [
|
|
102
|
+
{
|
|
103
|
+
name: "nifra_new_route",
|
|
104
|
+
description:
|
|
105
|
+
"Implement a new file route with the right routes/ filename, examples, and checks.",
|
|
106
|
+
arguments: [
|
|
107
|
+
{ name: "path", description: 'URL path, e.g. "/users/:id".', required: true },
|
|
108
|
+
{ name: "goal", description: "What the page should do.", required: false },
|
|
109
|
+
],
|
|
110
|
+
handler: async (args) =>
|
|
111
|
+
promptText(
|
|
112
|
+
[
|
|
113
|
+
`Create a nifra page route for ${JSON.stringify(args.path ?? "/new-route")}.`,
|
|
114
|
+
args.goal ? `Goal: ${String(args.goal)}` : undefined,
|
|
115
|
+
'Use `nifra_context` with `{ kind: "pages" }`, then `nifra_scaffold` for the exact file path.',
|
|
116
|
+
"If the stub is not writable for this framework, call `nifra_example` for a verified page/loader example before editing.",
|
|
117
|
+
"Verify with `nifra_render` for the route and finish with `nifra_check`.",
|
|
118
|
+
]
|
|
119
|
+
.filter(Boolean)
|
|
120
|
+
.join("\n"),
|
|
121
|
+
),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "nifra_add_endpoint",
|
|
125
|
+
description:
|
|
126
|
+
"Add or update a backend endpoint with schemas, typed-client usage, and verification.",
|
|
127
|
+
arguments: [
|
|
128
|
+
{ name: "method", description: "HTTP method.", required: true },
|
|
129
|
+
{ name: "path", description: 'API path, e.g. "/users/:id".', required: true },
|
|
130
|
+
{ name: "goal", description: "What the endpoint should do.", required: false },
|
|
131
|
+
],
|
|
132
|
+
handler: async (args) =>
|
|
133
|
+
promptText(
|
|
134
|
+
[
|
|
135
|
+
`Add a nifra backend endpoint: ${String(args.method ?? "GET").toUpperCase()} ${String(args.path ?? "/api")}.`,
|
|
136
|
+
args.goal ? `Goal: ${String(args.goal)}` : undefined,
|
|
137
|
+
"Read `nifra://routes` or call `nifra_routes` first so the new route fits the existing API shape.",
|
|
138
|
+
"Use route schemas for untrusted body/query input and declare `response` when the frontend consumes the shape.",
|
|
139
|
+
"Verify behavior with `nifra_run`, then run `nifra_check` and `nifra_test` for the touched area.",
|
|
140
|
+
]
|
|
141
|
+
.filter(Boolean)
|
|
142
|
+
.join("\n"),
|
|
143
|
+
),
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "nifra_debug_drift",
|
|
147
|
+
description:
|
|
148
|
+
"Debug frontend/backend contract drift using the typed client and checker output.",
|
|
149
|
+
arguments: [
|
|
150
|
+
{ name: "symptom", description: "The error or behavior to investigate.", required: false },
|
|
151
|
+
],
|
|
152
|
+
handler: async (args) =>
|
|
153
|
+
promptText(
|
|
154
|
+
[
|
|
155
|
+
"Debug nifra contract drift.",
|
|
156
|
+
args.symptom ? `Symptom: ${String(args.symptom)}` : undefined,
|
|
157
|
+
"Start with `nifra_check`; use each diagnostic as the source of truth.",
|
|
158
|
+
"Read `nifra://routes` for the exact typed-client calls and compact body/query/response shapes.",
|
|
159
|
+
"Prefer `client<typeof app>` over hand-rolled internal `fetch`. Verify fixed endpoints with `nifra_run`.",
|
|
160
|
+
]
|
|
161
|
+
.filter(Boolean)
|
|
162
|
+
.join("\n"),
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function projectFeatures(
|
|
169
|
+
cwd: string,
|
|
170
|
+
loadAppCached: (outDirName?: string) => Promise<LoadedApp> = createCachedAppLoader(cwd),
|
|
171
|
+
): McpServerFeatures {
|
|
172
|
+
return { resources: projectResources(cwd, loadAppCached), prompts: projectPrompts() }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Resolve an optional `dir` tool argument - a subdirectory of the project root the caller wants to scope a
|
|
177
|
+
* check/test to (e.g. `nifra check` on `app/` when the MCP server's root is a monorepo). Returns the
|
|
178
|
+
* absolute target, or `null` if `dir` escapes the root (a path-traversal guard: no `..` out, no absolute
|
|
179
|
+
* path elsewhere). `undefined`/empty → the root itself.
|
|
180
|
+
*/
|
|
181
|
+
export function resolveProjectDir(root: string, dir: string | undefined): string | null {
|
|
182
|
+
if (dir === undefined || dir === "") return root
|
|
183
|
+
const target = resolve(root, dir)
|
|
184
|
+
let canonicalRoot: string
|
|
185
|
+
try {
|
|
186
|
+
canonicalRoot = realpathSync(root)
|
|
187
|
+
} catch {
|
|
188
|
+
const lexical = relative(root, target)
|
|
189
|
+
return lexical === "" || (!lexical.startsWith("..") && !isAbsolute(lexical)) ? target : null
|
|
190
|
+
}
|
|
191
|
+
let probe = target
|
|
192
|
+
const missing: string[] = []
|
|
193
|
+
while (true) {
|
|
194
|
+
try {
|
|
195
|
+
const canonicalProbe = realpathSync(probe)
|
|
196
|
+
const rel = relative(canonicalRoot, canonicalProbe)
|
|
197
|
+
if (rel.startsWith("..") || isAbsolute(rel)) return null
|
|
198
|
+
return missing.length === 0 ? canonicalProbe : resolve(canonicalProbe, ...missing.reverse())
|
|
199
|
+
} catch {
|
|
200
|
+
const parent = resolve(probe, "..")
|
|
201
|
+
if (parent === probe) return null
|
|
202
|
+
// `basename`, not a slice past `parent`: when `parent` is the filesystem root its trailing
|
|
203
|
+
// separator is part of it, so `parent.length + 1` eats the first character of the segment and
|
|
204
|
+
// the path gets rebuilt wrong.
|
|
205
|
+
missing.push(basename(probe))
|
|
206
|
+
probe = parent
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Consistent error string for a `dir` that escapes the project root. */
|
|
212
|
+
export function dirError(dir: string | undefined): string {
|
|
213
|
+
return JSON.stringify(
|
|
214
|
+
{ ok: false, error: `dir must be a subdirectory of the project root - "${dir}" escapes it.` },
|
|
215
|
+
null,
|
|
216
|
+
2,
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Build the project-scoped tools for `cwd`. */
|
|
221
|
+
export interface CommandMcpToolOptions {
|
|
222
|
+
readonly cwd: string
|
|
223
|
+
readonly loadAppCached?: () => Promise<LoadedApp>
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Adapt one executable catalog spec to its MCP descriptor and project-scoped handler. */
|
|
227
|
+
export function namespaceForApp(
|
|
228
|
+
name: string,
|
|
229
|
+
tools: McpTool[],
|
|
230
|
+
features: McpServerFeatures,
|
|
231
|
+
): { tools: McpTool[]; features: McpServerFeatures } {
|
|
232
|
+
const prefix = `nifra_${name}_`
|
|
233
|
+
const namespacedTools = tools.map((t) => ({
|
|
234
|
+
...t,
|
|
235
|
+
name: t.name.startsWith("nifra_") ? t.name.replace(/^nifra_/, prefix) : `${name}_${t.name}`,
|
|
236
|
+
}))
|
|
237
|
+
const namespacedResources = (features.resources ?? []).map((r) => ({
|
|
238
|
+
...r,
|
|
239
|
+
uri: r.uri.replace(/^nifra:\/\//, `nifra://${name}/`),
|
|
240
|
+
}))
|
|
241
|
+
const namespacedPrompts = (features.prompts ?? []).map((p) => ({
|
|
242
|
+
...p,
|
|
243
|
+
name: p.name.replace(/^nifra_/, prefix),
|
|
244
|
+
}))
|
|
245
|
+
return {
|
|
246
|
+
tools: namespacedTools,
|
|
247
|
+
features: { resources: namespacedResources, prompts: namespacedPrompts },
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Merge the backend-derived resources/prompts into `base` - and keep a project that cannot be loaded
|
|
253
|
+
* from deciding whether the server starts at all.
|
|
254
|
+
*
|
|
255
|
+
* Resources and prompts are OPTIONAL capabilities extracted from the app's backend, so this load is a
|
|
256
|
+
* best-effort enrichment. It was awaited unguarded, which made it a hard boot requirement: `loadApp`
|
|
257
|
+
* needs a web config (`adapter` + `clientModule`) and a `routes/` directory, and a backend-only
|
|
258
|
+
* project - the shape `create-nifra`'s DEFAULT template produces - has neither. On those projects the
|
|
259
|
+
* throw escaped before the JSON-RPC loop began, so the server wrote nothing and exited. `nifra
|
|
260
|
+
* init-agents` would happily register an `.mcp.json` pointing at a server that could never start, and
|
|
261
|
+
* every tool went with it, including the twelve that never touch the app (docs, examples, types,
|
|
262
|
+
* check, doctor, levels, test).
|
|
263
|
+
*
|
|
264
|
+
* Degrading costs only the backend resources/prompts. Tools that genuinely need the app still fail,
|
|
265
|
+
* but per call, with their own message - which is a diagnosis instead of a silence.
|
|
266
|
+
*/
|
package/src/mcp-docs-tools.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
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
13
|
import { renderLearnResult } from "./learn.ts"
|
|
13
14
|
import type { McpTool } from "./mcp-protocol.ts"
|
|
14
15
|
import { renderTypesResult, type TypeEntry } from "./types-search.ts"
|
|
@@ -147,5 +148,41 @@ export function docsTools(
|
|
|
147
148
|
},
|
|
148
149
|
handler: async (args) => renderLearnResult((args as { step?: number }).step),
|
|
149
150
|
},
|
|
151
|
+
{
|
|
152
|
+
name: "nifra_frontend",
|
|
153
|
+
annotations: {
|
|
154
|
+
title: "Frontend footgun guidance",
|
|
155
|
+
readOnlyHint: true,
|
|
156
|
+
openWorldHint: false,
|
|
157
|
+
},
|
|
158
|
+
description:
|
|
159
|
+
'Diagnose a CLIENT-SIDE nifra problem by symptom, across every adapter (React/Preact/Solid/Vue/Svelte/vanilla). Returns the cause, the concrete fix, and how to verify it. Covers the nifra SEAM (a server-only import leaking into a client component, a hydration mismatch, a duplicated framework runtime, loader-data typing) - where it points at the nifra_* tool that fixes and checks it - and the per-framework reactivity-loss idioms (Vue ref, Solid props, Svelte runes, React effect deps), where it points at that framework\'s own ESLint plugin. Call with no args for the index; pass `symptom` (e.g. "hydration mismatch", "value stopped updating") and/or `adapter` to filter. Use this when a rendered page misbehaves and nifra_check is green (check owns the static seam; this owns the rest).',
|
|
160
|
+
inputSchema: {
|
|
161
|
+
type: "object",
|
|
162
|
+
properties: {
|
|
163
|
+
symptom: {
|
|
164
|
+
type: "string",
|
|
165
|
+
maxLength: 256,
|
|
166
|
+
description: "What you observe (omit for the index).",
|
|
167
|
+
},
|
|
168
|
+
adapter: {
|
|
169
|
+
type: "string",
|
|
170
|
+
enum: ["react", "preact", "solid", "vue", "svelte", "vanilla"],
|
|
171
|
+
description:
|
|
172
|
+
"Filter to one adapter's entries (plus the adapter-independent seam entries).",
|
|
173
|
+
},
|
|
174
|
+
limit: { type: "number", description: "Max entries to return (default 3, max 5)." },
|
|
175
|
+
},
|
|
176
|
+
additionalProperties: false,
|
|
177
|
+
},
|
|
178
|
+
handler: async (args) => {
|
|
179
|
+
const { symptom, adapter, limit } = args as {
|
|
180
|
+
symptom?: string
|
|
181
|
+
adapter?: string
|
|
182
|
+
limit?: number
|
|
183
|
+
}
|
|
184
|
+
return renderFrontendResult({ symptom, adapter, limit: clamp(limit, 1, 5, 3) })
|
|
185
|
+
},
|
|
186
|
+
},
|
|
150
187
|
]
|
|
151
188
|
}
|