@nifrajs/cli 2.2.0 → 2.3.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 +25 -25
- package/dist/assure.d.ts +2 -2
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +17 -10
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts +7 -0
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +68 -16
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check.d.ts +61 -22
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +332 -86
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +30 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +132 -36
- package/dist/cli.js.map +1 -1
- package/dist/diff-tool.d.ts +3 -3
- package/dist/diff-tool.js +7 -7
- package/dist/docs-search.d.ts +3 -3
- package/dist/docs-search.js +6 -6
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +8 -8
- package/dist/examples.d.ts +5 -5
- package/dist/examples.js +5 -5
- package/dist/init-agents.d.ts +14 -14
- package/dist/init-agents.js +14 -14
- package/dist/internal/typescript-import.d.ts +24 -0
- package/dist/internal/typescript-import.d.ts.map +1 -0
- package/dist/internal/typescript-import.js +32 -0
- package/dist/internal/typescript-import.js.map +1 -0
- package/dist/introspect.d.ts +12 -12
- package/dist/introspect.js +24 -24
- package/dist/levels-tool.d.ts +8 -8
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +33 -30
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +6 -6
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +15 -7
- package/dist/load.js.map +1 -1
- package/dist/manifest-tool.d.ts +1 -1
- package/dist/manifest-tool.d.ts.map +1 -1
- package/dist/manifest-tool.js +4 -2
- package/dist/manifest-tool.js.map +1 -1
- package/dist/mcp-docs-tools.d.ts +1 -1
- package/dist/mcp-docs-tools.js +9 -9
- package/dist/mcp-http.d.ts +5 -5
- package/dist/mcp-http.js +7 -7
- package/dist/mcp-protocol.d.ts +2 -2
- package/dist/mcp-protocol.js +2 -2
- package/dist/mcp-render.d.ts +3 -3
- package/dist/mcp-render.js +6 -6
- package/dist/mcp-run.d.ts +2 -2
- package/dist/mcp-run.js +2 -2
- package/dist/mcp.d.ts +14 -14
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +75 -45
- package/dist/mcp.js.map +1 -1
- package/dist/openapi-tool.d.ts +1 -1
- package/dist/openapi-tool.js +2 -2
- package/dist/pipeline-guard.d.ts +1 -1
- package/dist/pipeline-guard.js +1 -1
- package/dist/port.d.ts +9 -9
- package/dist/port.js +27 -27
- package/dist/recipes/1.8.0.d.ts +2 -2
- package/dist/recipes/1.8.0.js +5 -5
- package/dist/recipes/index.d.ts +2 -2
- package/dist/recipes/index.js +1 -1
- package/dist/scaffold.d.ts +3 -3
- package/dist/scaffold.js +8 -8
- package/dist/sync-routes.d.ts +28 -0
- package/dist/sync-routes.d.ts.map +1 -0
- package/dist/sync-routes.js +55 -0
- package/dist/sync-routes.js.map +1 -0
- package/dist/types-search.d.ts +5 -5
- package/dist/types-search.js +7 -7
- package/dist/upgrade.d.ts +7 -7
- package/dist/upgrade.js +12 -12
- package/dist/verification.d.ts +51 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +80 -0
- package/dist/verification.js.map +1 -0
- package/docs/examples.json +174 -90
- package/docs/llms-full.txt +1696 -747
- package/docs/types.json +1892 -3105
- package/package.json +22 -11
- package/src/assure.ts +17 -18
- package/src/capabilities-tool.ts +82 -16
- package/src/check.ts +405 -103
- package/src/cli.ts +141 -38
- package/src/diff-tool.ts +8 -8
- package/src/docs-search.ts +6 -6
- package/src/doctor.ts +10 -10
- package/src/examples.ts +7 -7
- package/src/init-agents.ts +17 -17
- package/src/internal/typescript-import.ts +33 -0
- package/src/introspect.ts +28 -28
- package/src/levels-tool.ts +37 -31
- package/src/load.ts +21 -12
- package/src/manifest-tool.ts +4 -2
- package/src/mcp-docs-tools.ts +9 -9
- package/src/mcp-http.ts +7 -7
- package/src/mcp-protocol.ts +2 -2
- package/src/mcp-render.ts +6 -6
- package/src/mcp-run.ts +2 -2
- package/src/mcp.ts +82 -45
- package/src/openapi-tool.ts +2 -2
- package/src/pipeline-guard.ts +1 -1
- package/src/port.ts +31 -31
- package/src/recipes/1.8.0.ts +5 -5
- package/src/recipes/index.ts +2 -2
- package/src/scaffold.ts +8 -8
- package/src/sync-routes.ts +69 -0
- package/src/types-search.ts +8 -8
- package/src/upgrade.ts +12 -12
- package/src/verification.ts +123 -0
package/src/mcp-docs-tools.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The two project-INDEPENDENT MCP tools
|
|
2
|
+
* The two project-INDEPENDENT MCP tools - `nifra_docs` + `nifra_example` - as a single factory shared
|
|
3
3
|
* by every transport: the project stdio server ({@link projectTools}), the CLI HTTP server
|
|
4
4
|
* (`nifra docs-mcp`), and the site's Cloudflare-Pages worker (`/mcp`). The corpus source is injected as
|
|
5
5
|
* loaders, so the SAME tool definitions work whether the corpus comes from disk (`Bun.file`, on the
|
|
@@ -25,7 +25,7 @@ export function docsTools(
|
|
|
25
25
|
{
|
|
26
26
|
name: "nifra_docs",
|
|
27
27
|
description:
|
|
28
|
-
"Search nifra's framework documentation and get back ONLY the matching sections
|
|
28
|
+
"Search nifra's framework documentation and get back ONLY the matching sections - auth, uploads, ISR, WebSockets, loaders, deployment, anything. Call with no query for the cheap section index; pass query (e.g. \"isr revalidate\") for the top matching sections. Use this instead of reading llms-full.txt (~150 KB) whole. For the EXACT TypeScript of a type/interface/function, call nifra_types instead (don't read .d.ts files).",
|
|
29
29
|
inputSchema: {
|
|
30
30
|
type: "object",
|
|
31
31
|
properties: {
|
|
@@ -40,7 +40,7 @@ export function docsTools(
|
|
|
40
40
|
handler: async (args) => {
|
|
41
41
|
const corpus = await loadDocs()
|
|
42
42
|
if (corpus === undefined) {
|
|
43
|
-
return "docs corpus missing
|
|
43
|
+
return "docs corpus missing - run `bun run gen:llms` in the nifra repo (published builds ship it)."
|
|
44
44
|
}
|
|
45
45
|
const { query, limit } = args as { query?: string; limit?: number }
|
|
46
46
|
return renderDocsResult(corpus, query, clamp(limit, 1, 5, 3))
|
|
@@ -49,7 +49,7 @@ export function docsTools(
|
|
|
49
49
|
{
|
|
50
50
|
name: "nifra_example",
|
|
51
51
|
description:
|
|
52
|
-
'Get a VERIFIED, copy-pasteable nifra code example for a task
|
|
52
|
+
'Get a VERIFIED, copy-pasteable nifra code example for a task - auth route, file upload, ISR page, loader/action, typed client, SSE, deployment, etc. Every snippet is typechecked against the installed nifra version, so it compiles as-is. PREFER THIS over writing nifra code from memory (training data drifts). Call with no query for the grouped index; pass query (e.g. "protected route", "upload", "isr revalidate") for matching snippets.',
|
|
53
53
|
inputSchema: {
|
|
54
54
|
type: "object",
|
|
55
55
|
properties: {
|
|
@@ -64,7 +64,7 @@ export function docsTools(
|
|
|
64
64
|
handler: async (args) => {
|
|
65
65
|
const corpus = await loadExamples()
|
|
66
66
|
if (corpus === undefined) {
|
|
67
|
-
return "examples corpus missing
|
|
67
|
+
return "examples corpus missing - run `bun run gen:llms` in the nifra repo (published builds ship it)."
|
|
68
68
|
}
|
|
69
69
|
const { query, limit } = args as { query?: string; limit?: number }
|
|
70
70
|
return renderExamplesResult(corpus, query, clamp(limit, 1, 5, 3))
|
|
@@ -73,14 +73,14 @@ export function docsTools(
|
|
|
73
73
|
{
|
|
74
74
|
name: "nifra_types",
|
|
75
75
|
description:
|
|
76
|
-
'Get the EXACT TypeScript declaration of any exported @nifrajs/* symbol
|
|
76
|
+
'Get the EXACT TypeScript declaration of any exported @nifrajs/* symbol - interface, type, class, function, const. Each signature is generated from the package\'s built .d.ts, so it is the LITERAL declaration: complete, authoritative, never prose and never truncated. THIS IS THE SOURCE OF TRUTH for nifra\'s types - do NOT read node_modules/@nifrajs/**/*.d.ts; call this instead. Pass `name` for an exact symbol (e.g. "RateLimitStore", "RouteSchema", "Context", "rateLimit"); pass `query` to search by keyword; omit both for the per-package index of names. A `name` lookup is always the complete declaration; a `query` returns a one-line summary plus the signature, collapsing an oversized body - pass `full: true` to override.',
|
|
77
77
|
inputSchema: {
|
|
78
78
|
type: "object",
|
|
79
79
|
properties: {
|
|
80
80
|
name: {
|
|
81
81
|
type: "string",
|
|
82
82
|
description:
|
|
83
|
-
"Exact symbol name
|
|
83
|
+
"Exact symbol name - returns its literal declaration (e.g. RateLimitStore).",
|
|
84
84
|
},
|
|
85
85
|
query: {
|
|
86
86
|
type: "string",
|
|
@@ -94,7 +94,7 @@ export function docsTools(
|
|
|
94
94
|
full: {
|
|
95
95
|
type: "boolean",
|
|
96
96
|
description:
|
|
97
|
-
"Query mode only: return whole declarations instead of collapsed ones. Off by default
|
|
97
|
+
"Query mode only: return whole declarations instead of collapsed ones. Off by default - a search is for picking a symbol, and one match can be tens of thousands of characters.",
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
additionalProperties: false,
|
|
@@ -102,7 +102,7 @@ export function docsTools(
|
|
|
102
102
|
handler: async (args) => {
|
|
103
103
|
const corpus = await loadTypes()
|
|
104
104
|
if (corpus === undefined) {
|
|
105
|
-
return "types corpus missing
|
|
105
|
+
return "types corpus missing - run `bun run build && bun run gen:llms` in the nifra repo (published builds ship it)."
|
|
106
106
|
}
|
|
107
107
|
const { name, query, limit, full } = args as {
|
|
108
108
|
name?: string
|
package/src/mcp-http.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The PUBLIC nifra docs MCP
|
|
2
|
+
* The PUBLIC nifra docs MCP - Streamable-HTTP transport exposing the project-INDEPENDENT tools
|
|
3
3
|
* (`nifra_docs` + `nifra_example`) so any remote AI agent can learn nifra without a local checkout.
|
|
4
4
|
* Both tools read the bundled corpus (llms-full.txt / examples.json shipped in this package) and ignore
|
|
5
|
-
* `cwd`, so they reuse the exact definitions from {@link projectTools}
|
|
5
|
+
* `cwd`, so they reuse the exact definitions from {@link projectTools} - one source, no drift.
|
|
6
6
|
*
|
|
7
7
|
* The transport itself (body cap, CORS, JSON-RPC dispatch) lives in `@nifrajs/mcp/http`; this module is
|
|
8
8
|
* the docs-specific layer over it: it supplies the bundled corpus tools and the `nifra-docs` server info.
|
|
9
|
-
* {@link handleMcpHttp} self-hosts ANYWHERE Bun runs
|
|
10
|
-
* same handler runs on Cloudflare/Vercel edge (there inline the corpus as string imports
|
|
9
|
+
* {@link handleMcpHttp} self-hosts ANYWHERE Bun runs - the simplest path is `nifra docs-mcp` on a VPS; the
|
|
10
|
+
* same handler runs on Cloudflare/Vercel edge (there inline the corpus as string imports - a Worker has no
|
|
11
11
|
* filesystem). `export default { port, fetch }` also lets `bun run mcp-http.ts` serve it directly.
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -26,10 +26,10 @@ export { docsTools } from "./mcp-docs-tools.ts"
|
|
|
26
26
|
export type { TypeEntry } from "./types-search.ts"
|
|
27
27
|
|
|
28
28
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
29
|
-
const VERSION = "2.
|
|
29
|
+
const VERSION = "2.3.0"
|
|
30
30
|
const SERVER_INFO = { name: "nifra-docs", version: VERSION }
|
|
31
31
|
const DOCS_HEALTH =
|
|
32
|
-
"nifra docs MCP
|
|
32
|
+
"nifra docs MCP - POST JSON-RPC 2.0 here (methods: initialize, tools/list, tools/call). Tools: nifra_docs, nifra_example."
|
|
33
33
|
|
|
34
34
|
/** The two project-independent tools, reading the package's bundled corpus from disk (CLI use). */
|
|
35
35
|
export function publicDocsTools(): McpTool[] {
|
|
@@ -57,7 +57,7 @@ export function handleMcpHttp(request: Request): Promise<Response> {
|
|
|
57
57
|
/**
|
|
58
58
|
* Worker/edge + local entry. `export default { fetch }` is the universal server shape: Cloudflare /
|
|
59
59
|
* Vercel edge / Deno deploy use `fetch` (and ignore `port`); `bun run mcp-http.ts` auto-serves it on
|
|
60
|
-
* `port` (PORT env, default 8787)
|
|
60
|
+
* `port` (PORT env, default 8787) - Bun serves a module's default-exported server, so NO manual
|
|
61
61
|
* `Bun.serve` here (that would double-bind the port).
|
|
62
62
|
*/
|
|
63
63
|
export default {
|
package/src/mcp-protocol.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The MCP JSON-RPC dispatch now lives in `@nifrajs/mcp` (shared with nifra apps that expose their own
|
|
3
|
-
* MCP server / MCP Apps widgets). This module is a thin re-export so the CLI's existing imports
|
|
4
|
-
* the `@nifrajs/cli/mcp` self-host surface
|
|
3
|
+
* MCP server / MCP Apps widgets). This module is a thin re-export so the CLI's existing imports - and
|
|
4
|
+
* the `@nifrajs/cli/mcp` self-host surface - keep resolving here unchanged.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export * from "@nifrajs/mcp/protocol"
|
package/src/mcp-render.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `nifra_render` engine + its child-process entry
|
|
2
|
+
* The `nifra_render` engine + its child-process entry - the page half of `nifra_run`. Where `nifra_run`
|
|
3
3
|
* runs requests through the BACKEND, this SSRs page routes through the WEB app (`createWebApp`), so an
|
|
4
4
|
* agent can verify a page renders and its loader ran after an edit. Spawned fresh per call (`bun
|
|
5
5
|
* mcp-render.ts <cwd>`) so the project's CURRENT route/loader code is loaded.
|
|
6
6
|
*
|
|
7
|
-
* No build required: a placeholder `clientEntry` is injected (the SSR HTML renders regardless
|
|
7
|
+
* No build required: a placeholder `clientEntry` is injected (the SSR HTML renders regardless - the
|
|
8
8
|
* client bundle only matters for hydration in the browser, not for "did this page render server-side").
|
|
9
|
-
* {@link renderPages} never throws
|
|
9
|
+
* {@link renderPages} never throws - every failure (no config, a loader error, a render throw) becomes
|
|
10
10
|
* `{ error }` so the agent gets the actionable message.
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ import { loadApp, resolvePlugins } from "./load.ts"
|
|
|
19
19
|
const errString = (err: unknown): string =>
|
|
20
20
|
err instanceof Error ? `${err.name}: ${err.message}` : String(err)
|
|
21
21
|
|
|
22
|
-
/** Load the project, register its SSR plugins, and build the SSR `createWebApp` once
|
|
22
|
+
/** Load the project, register its SSR plugins, and build the SSR `createWebApp` once - the cost the warm
|
|
23
23
|
* worker amortizes across calls. Never throws (every failure → `{ error }`). Factored out of
|
|
24
24
|
* {@link renderPages} so the cold path (fresh process per call) and the warm worker share one builder. */
|
|
25
25
|
async function buildWebApp(cwd: string): Promise<{ app: AppLike } | { error: string }> {
|
|
@@ -92,7 +92,7 @@ function redirectConsoleToStderr(): void {
|
|
|
92
92
|
/**
|
|
93
93
|
* Warm-worker loop (`--worker`): build the web app ONCE, then SSR each `{ id, input: { requests } }` line
|
|
94
94
|
* against that hot app and reply `{ id, output }`. The parent (`mcp.ts`'s warm-render handler) spawns this,
|
|
95
|
-
* fingerprints the source tree, and restarts the worker when a file changes
|
|
95
|
+
* fingerprints the source tree, and restarts the worker when a file changes - so warm reuse never serves a
|
|
96
96
|
* stale render. Mirrors `mcp-run.ts`'s worker (single backend entry → no per-call entry key needed here).
|
|
97
97
|
*/
|
|
98
98
|
async function runWorker(cwd: string): Promise<void> {
|
|
@@ -148,7 +148,7 @@ if (import.meta.main) {
|
|
|
148
148
|
// The parent (mcp.ts) spawns `bun mcp-render.ts <cwd>` WITHOUT setting the subprocess `cwd` option, so
|
|
149
149
|
// this process inherits the MCP server's working dir, not the app's. SSR resolves `react-dom/server`
|
|
150
150
|
// from `process.cwd()` to share ONE React core with the app's route components (the dual-React fix in
|
|
151
|
-
// @nifrajs/web-react)
|
|
151
|
+
// @nifrajs/web-react) - so we must chdir to the app root before any render. Best-effort: a bad path
|
|
152
152
|
// surfaces later as a load error rather than crashing the child here.
|
|
153
153
|
if (cwd !== process.cwd()) {
|
|
154
154
|
try {
|
package/src/mcp-run.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `nifra_run` engine + its child-process entry. The MCP server spawns this file fresh on every
|
|
3
|
-
* `nifra_run` call (`bun mcp-run.ts <cwd>`) so the project's CURRENT backend code is loaded
|
|
3
|
+
* `nifra_run` call (`bun mcp-run.ts <cwd>`) so the project's CURRENT backend code is loaded - picking
|
|
4
4
|
* up the agent's latest edits. {@link runBackend} is the pure-ish core (resolve entry → import → run),
|
|
5
5
|
* exported so it's unit-testable in-process; the entry below wires it to stdin/stdout.
|
|
6
6
|
*/
|
|
@@ -48,7 +48,7 @@ export async function loadBackend(
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Resolve the backend entry under `cwd`, import it, and run `requests` through its exported app. Never
|
|
51
|
-
* throws
|
|
51
|
+
* throws - every failure (missing/invalid entry, import/compile/runtime error) becomes `{ error }`, so
|
|
52
52
|
* the caller (and the agent) always gets actionable output. An import error here IS the failure the
|
|
53
53
|
* agent needs to see and fix.
|
|
54
54
|
*/
|
package/src/mcp.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `nifra mcp`
|
|
2
|
+
* `nifra mcp` - a Model Context Protocol server (stdio) that lets a coding agent (Claude, Cursor, …)
|
|
3
3
|
* act on a nifra project, not just read about it:
|
|
4
4
|
*
|
|
5
|
-
* - `nifra_context`
|
|
6
|
-
* - `nifra_run`
|
|
5
|
+
* - `nifra_context` - this project's API routes + page routes + conventions (see {@link describeProject}).
|
|
6
|
+
* - `nifra_run` - run HTTP requests through the project's backend and return structured results
|
|
7
7
|
* (status, body, errors). The write → run → see-the-failure → fix loop, powered by `@nifrajs/runner`.
|
|
8
8
|
* Each call runs the backend in a FRESH subprocess, so it reflects the agent's latest edits.
|
|
9
|
-
* - `nifra_render`
|
|
9
|
+
* - `nifra_render` - SSR a page route through the project's web app; returns the rendered HTML (the
|
|
10
10
|
* page half of `nifra_run`). Fresh subprocess per call; no build needed.
|
|
11
|
-
* - `nifra_ws`
|
|
12
|
-
* - `nifra_docs`
|
|
13
|
-
* - `nifra_example`
|
|
11
|
+
* - `nifra_ws` - verify a WebSocket route with a real Bun WebSocket round-trip.
|
|
12
|
+
* - `nifra_docs` - keyword-search the framework docs; returns only the matching sections.
|
|
13
|
+
* - `nifra_example` - a verified, copy-pasteable snippet for a task (typechecked against the live API,
|
|
14
14
|
* so it can't hallucinate a drifted nifra API).
|
|
15
|
-
* - `nifra_scaffold
|
|
16
|
-
* - `nifra_check`
|
|
17
|
-
* - `nifra_assure`
|
|
15
|
+
* - `nifra_scaffold`- map a URL path to the correct `routes/` file + a contract-correct page stub.
|
|
16
|
+
* - `nifra_check` - the drift gate (typecheck + lints, each with a structured fix), for an agent to fix against.
|
|
17
|
+
* - `nifra_assure` - route classification + enforcement-evidence gate.
|
|
18
18
|
* - `nifra_levels` - the cumulative verification ladder (L0 contract → L4 invariants): what the
|
|
19
19
|
* project actually proves, and why each level it misses does not hold.
|
|
20
|
-
* - `nifra_doctor`
|
|
20
|
+
* - `nifra_doctor` - package.json dependency drift detector, with safe local-version auto-fix.
|
|
21
21
|
*
|
|
22
22
|
* Wire it into a client (e.g. Claude Desktop / Cursor) as: command `nifra`, args `["mcp"]`, run in the
|
|
23
23
|
* project root. The protocol is hand-rolled (newline-delimited JSON-RPC 2.0 over stdio), including
|
|
24
|
-
* standard MCP progress notifications and request cancellation
|
|
24
|
+
* standard MCP progress notifications and request cancellation - no SDK dependency, the same
|
|
25
25
|
* minimal-surface choice as the rest of nifra. The pure dispatch lives in `./mcp-protocol.ts`; this
|
|
26
26
|
* module is the I/O shell (stdin loop, tool wiring, the run subprocess).
|
|
27
27
|
*/
|
|
@@ -159,7 +159,7 @@ type PipeSubprocess = ReturnType<typeof Bun.spawn> & {
|
|
|
159
159
|
|
|
160
160
|
/** A persistent `mcp-run`/`mcp-render` `--worker` subprocess: the backend/web app is loaded ONCE and
|
|
161
161
|
* reused across newline-delimited `{ id, input }` requests, replying `{ id, output }`. The same machinery
|
|
162
|
-
* powers both `nifra_run warm` and `nifra_render warm`
|
|
162
|
+
* powers both `nifra_run warm` and `nifra_render warm` - `child` selects which engine, `label` shapes the
|
|
163
163
|
* cancellation message. The owning handler ({@link createWarmHandler}) fingerprints the source tree and
|
|
164
164
|
* replaces the worker when a file changes, so warm reuse never serves a stale result. Exported for the
|
|
165
165
|
* concurrency test that proves a single per-request cancel doesn't tear down the shared worker. */
|
|
@@ -217,7 +217,7 @@ export class WarmWorker {
|
|
|
217
217
|
// Per-request cancel: drop just THIS id and resolve its cancellation. The worker is shared
|
|
218
218
|
// across concurrent requests (`pending` is id-keyed for exactly this reason), so killing the
|
|
219
219
|
// process here would reject every OTHER in-flight request via the `exited` handler and force a
|
|
220
|
-
// cold rebuild. Leave it hot
|
|
220
|
+
// cold rebuild. Leave it hot - `createWarmHandler` already replaces it on file change.
|
|
221
221
|
this.pending.delete(id)
|
|
222
222
|
clearTimeout(timer)
|
|
223
223
|
const reason = typeof signal?.reason === "string" ? `: ${signal.reason}` : ""
|
|
@@ -297,7 +297,7 @@ export class WarmWorker {
|
|
|
297
297
|
|
|
298
298
|
/** A warm handler that reuses a hot {@link WarmWorker} across calls and falls back to a one-shot fresh
|
|
299
299
|
* subprocess on any worker failure. Shared by `nifra_run` (`child: "mcp-run"`, `label: "run"`) and
|
|
300
|
-
* `nifra_render` (`child: "mcp-render"`, `label: "render"`)
|
|
300
|
+
* `nifra_render` (`child: "mcp-render"`, `label: "render"`) - the only differences are the engine and the
|
|
301
301
|
* message label, so there's a single source for the reuse + auto-restart-on-file-change logic. */
|
|
302
302
|
function createWarmHandler(
|
|
303
303
|
child: "mcp-run" | "mcp-render",
|
|
@@ -616,7 +616,7 @@ export function projectFeatures(
|
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
/**
|
|
619
|
-
* Resolve an optional `dir` tool argument
|
|
619
|
+
* Resolve an optional `dir` tool argument - a subdirectory of the project root the caller wants to scope a
|
|
620
620
|
* check/test to (e.g. `nifra check` on `app/` when the MCP server's root is a monorepo). Returns the
|
|
621
621
|
* absolute target, or `null` if `dir` escapes the root (a path-traversal guard: no `..` out, no absolute
|
|
622
622
|
* path elsewhere). `undefined`/empty → the root itself.
|
|
@@ -630,7 +630,7 @@ export function resolveProjectDir(root: string, dir: string | undefined): string
|
|
|
630
630
|
/** Consistent error string for a `dir` that escapes the project root. */
|
|
631
631
|
function dirError(dir: string | undefined): string {
|
|
632
632
|
return JSON.stringify(
|
|
633
|
-
{ ok: false, error: `dir must be a subdirectory of the project root
|
|
633
|
+
{ ok: false, error: `dir must be a subdirectory of the project root - "${dir}" escapes it.` },
|
|
634
634
|
null,
|
|
635
635
|
2,
|
|
636
636
|
)
|
|
@@ -647,7 +647,7 @@ export function projectTools(
|
|
|
647
647
|
{
|
|
648
648
|
name: "nifra_context",
|
|
649
649
|
description:
|
|
650
|
-
"Get this nifra project's surface. Call it once UNFILTERED for a tight INDEX: the route list (API routes as `METHOD path`, page routes as `pattern → file`) + framework conventions + a pointer
|
|
650
|
+
"Get this nifra project's surface. Call it once UNFILTERED for a tight INDEX: the route list (API routes as `METHOD path`, page routes as `pattern → file`) + framework conventions + a pointer - cheap even on a big app, no per-route schema dump. Then pass `path` (a route prefix like /api/orders) and/or `kind` (api|pages) to fetch the FULL contract for that slice (body/query/response TS shapes + the exact typed-client call form).",
|
|
651
651
|
inputSchema: {
|
|
652
652
|
type: "object",
|
|
653
653
|
properties: {
|
|
@@ -671,7 +671,7 @@ export function projectTools(
|
|
|
671
671
|
{
|
|
672
672
|
name: "nifra_routes",
|
|
673
673
|
description:
|
|
674
|
-
"List this project's API routes as STRUCTURED JSON
|
|
674
|
+
"List this project's API routes as STRUCTURED JSON - each `{ method, path, call, body?, query?, response? }`, where `call` is the exact typed-client call form and the shapes are compact TS-typed contracts. For programmatic use (list_routes / get_route_schema) instead of parsing the nifra_context Markdown. No args = every route; pass `path` (a path or prefix like /api/orders) to narrow to those routes.",
|
|
675
675
|
inputSchema: {
|
|
676
676
|
type: "object",
|
|
677
677
|
properties: {
|
|
@@ -851,7 +851,7 @@ export function projectTools(
|
|
|
851
851
|
{
|
|
852
852
|
name: "nifra_scaffold",
|
|
853
853
|
description:
|
|
854
|
-
'Map a URL path to the CORRECT routes/ file and get a contract-correct page stub. Agents routinely place file routes wrong
|
|
854
|
+
'Map a URL path to the CORRECT routes/ file and get a contract-correct page stub. Agents routinely place file routes wrong - this applies the convention for you: ":id"/"[id]" → [id], "*rest" → [...rest], "/" → index. Pass path (e.g. "/users/:id"). Returns the file to create + the route-module contract (loader/action/meta/default) + a stub (ready-to-write for react/preact/solid; path+contract for vue/svelte/vanilla - use nifra_example for those bodies).',
|
|
855
855
|
inputSchema: {
|
|
856
856
|
type: "object",
|
|
857
857
|
properties: {
|
|
@@ -887,7 +887,7 @@ export function projectTools(
|
|
|
887
887
|
{
|
|
888
888
|
name: "nifra_check",
|
|
889
889
|
description:
|
|
890
|
-
'Run the project\'s drift gate and return a structured result { ok, typecheck, diagnostics[] }: typecheck (the frontend↔backend contract), plus lints for hand-rolled fetch() to your own API, untyped client("…") calls missing <typeof app>, and server-only imports in routes/. Pass lintsOnly:true for a near-instant lint pass while iterating; run the full gate (default) to confirm the work is done
|
|
890
|
+
'Run the project\'s drift gate and return a structured result { ok, typecheck, diagnostics[] }: typecheck (the frontend↔backend contract), plus lints for hand-rolled fetch() to your own API, untyped client("…") calls missing <typeof app>, and server-only imports in routes/. Pass lintsOnly:true for a near-instant lint pass while iterating; run the full gate (default) to confirm the work is done - fix every diagnostic before finishing.',
|
|
891
891
|
inputSchema: {
|
|
892
892
|
type: "object",
|
|
893
893
|
properties: {
|
|
@@ -1086,7 +1086,7 @@ export function projectTools(
|
|
|
1086
1086
|
{
|
|
1087
1087
|
name: "nifra_doctor",
|
|
1088
1088
|
description:
|
|
1089
|
-
"Check this project for packages imported in source but NOT declared in package.json
|
|
1089
|
+
"Check this project for packages imported in source but NOT declared in package.json - the Bun-workspace trap where an import resolves at runtime (hoisting/workspace) so tests pass and `bun install` says no changes, yet tsc fails and a fresh/standalone install can't resolve it. Returns { ok, ran, findings[], fixed?, skippedFixes? }. Pass autoFix:true to update package.json only when the dependency version can be inferred locally from an ancestor package.json or installed package metadata; otherwise the tool returns the exact bun add command to run.",
|
|
1090
1090
|
inputSchema: {
|
|
1091
1091
|
type: "object",
|
|
1092
1092
|
properties: {
|
|
@@ -1259,6 +1259,54 @@ function namespaceForApp(
|
|
|
1259
1259
|
}
|
|
1260
1260
|
}
|
|
1261
1261
|
|
|
1262
|
+
/**
|
|
1263
|
+
* Merge the backend-derived resources/prompts into `base` - and keep a project that cannot be loaded
|
|
1264
|
+
* from deciding whether the server starts at all.
|
|
1265
|
+
*
|
|
1266
|
+
* Resources and prompts are OPTIONAL capabilities extracted from the app's backend, so this load is a
|
|
1267
|
+
* best-effort enrichment. It was awaited unguarded, which made it a hard boot requirement: `loadApp`
|
|
1268
|
+
* needs a web config (`adapter` + `clientModule`) and a `routes/` directory, and a backend-only
|
|
1269
|
+
* project - the shape `create-nifra`'s DEFAULT template produces - has neither. On those projects the
|
|
1270
|
+
* throw escaped before the JSON-RPC loop began, so the server wrote nothing and exited. `nifra
|
|
1271
|
+
* init-agents` would happily register an `.mcp.json` pointing at a server that could never start, and
|
|
1272
|
+
* every tool went with it, including the twelve that never touch the app (docs, examples, types,
|
|
1273
|
+
* check, doctor, levels, test).
|
|
1274
|
+
*
|
|
1275
|
+
* Degrading costs only the backend resources/prompts. Tools that genuinely need the app still fail,
|
|
1276
|
+
* but per call, with their own message - which is a diagnosis instead of a silence.
|
|
1277
|
+
*/
|
|
1278
|
+
async function backendFeatures(
|
|
1279
|
+
loader: () => Promise<LoadedApp>,
|
|
1280
|
+
base: McpServerFeatures,
|
|
1281
|
+
): Promise<McpServerFeatures> {
|
|
1282
|
+
const resources = [...(base.resources ?? [])]
|
|
1283
|
+
const prompts = [...(base.prompts ?? [])]
|
|
1284
|
+
try {
|
|
1285
|
+
const app = await loader()
|
|
1286
|
+
resources.push(...extractBackendResources(app.backend))
|
|
1287
|
+
prompts.push(...extractBackendPrompts(app.backend))
|
|
1288
|
+
} catch {
|
|
1289
|
+
// Not loadable here (no web config, or the config itself throws). The server still serves.
|
|
1290
|
+
}
|
|
1291
|
+
return { resources, prompts }
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* The MCP tools the app itself declares via `app.tool(...)`, or none when the app cannot be loaded.
|
|
1296
|
+
*
|
|
1297
|
+
* Same reasoning as {@link backendFeatures}, on the hotter path: this ran on EVERY JSON-RPC message,
|
|
1298
|
+
* so an unloadable project failed `initialize` itself with a `-32603` and the session never opened.
|
|
1299
|
+
* An app's own tools are an extension of the built-in set, so their absence must not withdraw the
|
|
1300
|
+
* built-ins - a backend-only project still gets docs, examples, types, check, doctor, levels and test.
|
|
1301
|
+
*/
|
|
1302
|
+
async function appDeclaredTools(loader: () => Promise<LoadedApp>): Promise<McpTool[]> {
|
|
1303
|
+
try {
|
|
1304
|
+
return extractBackendTools((await loader()).backend)
|
|
1305
|
+
} catch {
|
|
1306
|
+
return []
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1262
1310
|
/** Run the stdio MCP server: read newline-delimited JSON-RPC from stdin, write responses to stdout. */
|
|
1263
1311
|
export async function runMcpServer(cwd: string, version: string): Promise<void> {
|
|
1264
1312
|
let features: McpServerFeatures
|
|
@@ -1270,24 +1318,18 @@ export async function runMcpServer(cwd: string, version: string): Promise<void>
|
|
|
1270
1318
|
const allPrompts: McpPrompt[] = []
|
|
1271
1319
|
for (const { name, cwd: appCwd } of appEntries) {
|
|
1272
1320
|
const loader = createCachedAppLoader(appCwd)
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
})
|
|
1321
|
+
const ns = namespaceForApp(
|
|
1322
|
+
name,
|
|
1323
|
+
[],
|
|
1324
|
+
await backendFeatures(loader, projectFeatures(appCwd, loader)),
|
|
1325
|
+
)
|
|
1279
1326
|
allResources.push(...(ns.features.resources ?? []))
|
|
1280
1327
|
allPrompts.push(...(ns.features.prompts ?? []))
|
|
1281
1328
|
}
|
|
1282
1329
|
features = { resources: allResources, prompts: allPrompts }
|
|
1283
1330
|
} else {
|
|
1284
1331
|
const loadAppCached = createCachedAppLoader(cwd)
|
|
1285
|
-
|
|
1286
|
-
const app = await loadAppCached()
|
|
1287
|
-
features = {
|
|
1288
|
-
resources: [...(base.resources ?? []), ...extractBackendResources(app.backend)],
|
|
1289
|
-
prompts: [...(base.prompts ?? []), ...extractBackendPrompts(app.backend)],
|
|
1290
|
-
}
|
|
1332
|
+
features = await backendFeatures(loadAppCached, projectFeatures(cwd, loadAppCached))
|
|
1291
1333
|
}
|
|
1292
1334
|
const loadAppCached = createCachedAppLoader(cwd)
|
|
1293
1335
|
const serverInfo = { name: "nifra", version }
|
|
@@ -1302,21 +1344,16 @@ export async function runMcpServer(cwd: string, version: string): Promise<void>
|
|
|
1302
1344
|
const allTools: McpTool[] = []
|
|
1303
1345
|
for (const { name, cwd: appCwd } of appEntries) {
|
|
1304
1346
|
const loader = createCachedAppLoader(appCwd)
|
|
1305
|
-
const
|
|
1306
|
-
const
|
|
1307
|
-
const backendTools = extractBackendTools(app.backend)
|
|
1308
|
-
const ns = namespaceForApp(name, [...baseTools, ...backendTools], {
|
|
1309
|
-
resources: [],
|
|
1310
|
-
prompts: [],
|
|
1311
|
-
})
|
|
1347
|
+
const tools = [...projectTools(appCwd, loader), ...(await appDeclaredTools(loader))]
|
|
1348
|
+
const ns = namespaceForApp(name, tools, { resources: [], prompts: [] })
|
|
1312
1349
|
allTools.push(...ns.tools)
|
|
1313
1350
|
}
|
|
1314
1351
|
activeTools = [...docsTools(loadDocsCorpus, loadExamplesCorpus, loadTypesCorpus), ...allTools]
|
|
1315
1352
|
} else {
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1353
|
+
activeTools = [
|
|
1354
|
+
...projectTools(cwd, loadAppCached),
|
|
1355
|
+
...(await appDeclaredTools(loadAppCached)),
|
|
1356
|
+
]
|
|
1320
1357
|
}
|
|
1321
1358
|
|
|
1322
1359
|
const response = await handleRpc(message, activeTools, serverInfo, features, {
|
package/src/openapi-tool.ts
CHANGED
|
@@ -45,7 +45,7 @@ function toYaml(value: unknown, depth = 0): string {
|
|
|
45
45
|
* Render a project's backend as OpenAPI 3.1. Frontend-only apps get a valid empty document, which is
|
|
46
46
|
* easier for agents and API tooling to handle than a tool error.
|
|
47
47
|
*
|
|
48
|
-
* `pathPrefix` narrows the document to operations whose (OpenAPI-templated) path starts with the prefix
|
|
48
|
+
* `pathPrefix` narrows the document to operations whose (OpenAPI-templated) path starts with the prefix -
|
|
49
49
|
* mirroring `nifra_routes`'s `path` filter so a large backend needn't return the whole document. The keys
|
|
50
50
|
* are templated (`/users/{id}`), so a prefix up to the first param (`/api/orders`) matches `/api/orders`
|
|
51
51
|
* and `/api/orders/{id}` alike. `components.schemas` is left intact: it's keyed by schema name (not path),
|
|
@@ -57,7 +57,7 @@ export function renderOpenApi(app: LoadedApp, format: OpenApiFormat, pathPrefix?
|
|
|
57
57
|
const input = hasRoutesMethod(app.backend) ? app.backend : {}
|
|
58
58
|
const generated = toOpenAPI(input, { title, version: "1.0.0" })
|
|
59
59
|
// Narrow to operations under the prefix, rebuilding the doc (its `paths` is readonly). `components`
|
|
60
|
-
// stays
|
|
60
|
+
// stays - see the doc comment for why the schema set isn't recomputed.
|
|
61
61
|
const document =
|
|
62
62
|
pathPrefix !== undefined && pathPrefix !== ""
|
|
63
63
|
? {
|
package/src/pipeline-guard.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pipeline separation guard
|
|
2
|
+
* Pipeline separation guard - one bundler owns a phase, never two.
|
|
3
3
|
*
|
|
4
4
|
* nifra supports both Vite and Bun, and the config keeps them in separate slots: `vitePlugins` for
|
|
5
5
|
* the Vite pipeline, `clientPlugins`/`serverPlugins` for the Bun one. Nothing enforces the split, so
|