@nifrajs/cli 5.5.1 → 5.7.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 +314 -0
- package/dist/cdn-check.d.ts +7 -6
- package/dist/cdn-check.d.ts.map +1 -1
- package/dist/cdn-check.js +13 -1
- package/dist/cdn-check.js.map +1 -1
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +9 -3
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +6 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +30 -32
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +35 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +66 -9
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +19 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +111 -6
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +42 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +288 -9
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +12 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +67 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +27 -0
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.d.ts +1 -1
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +17 -8
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/internal/git-ignored.d.ts +12 -0
- package/dist/internal/git-ignored.d.ts.map +1 -0
- package/dist/internal/git-ignored.js +49 -0
- package/dist/internal/git-ignored.js.map +1 -0
- package/dist/internal/source-facts.d.ts +29 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +160 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.js +1 -1
- package/dist/introspect.js.map +1 -1
- package/dist/load.d.ts +7 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +18 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +15 -0
- package/dist/local-cli.d.ts.map +1 -0
- package/dist/local-cli.js +74 -0
- package/dist/local-cli.js.map +1 -0
- package/dist/lock-links.d.ts +0 -7
- package/dist/lock-links.d.ts.map +1 -1
- package/dist/lock-links.js +5 -44
- package/dist/lock-links.js.map +1 -1
- package/dist/mcp-delegate.d.ts +13 -5
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -8
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +57 -3
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts +2 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +3 -2
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts +21 -0
- package/dist/mcp-tool-meta.d.ts.map +1 -0
- package/dist/mcp-tool-meta.js +246 -0
- package/dist/mcp-tool-meta.js.map +1 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +36 -98
- package/dist/mcp.js.map +1 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +45 -2
- package/dist/openapi-types.js.map +1 -1
- package/dist/output-schemas.d.ts +8 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +14 -0
- package/dist/output-schemas.js.map +1 -1
- package/dist/ppr-read-fix.d.ts +8 -0
- package/dist/ppr-read-fix.d.ts.map +1 -0
- package/dist/ppr-read-fix.js +356 -0
- package/dist/ppr-read-fix.js.map +1 -0
- package/dist/recipes/5.6.0.d.ts +10 -0
- package/dist/recipes/5.6.0.d.ts.map +1 -0
- package/dist/recipes/5.6.0.js +68 -0
- package/dist/recipes/5.6.0.js.map +1 -0
- package/dist/recipes/5.7.0.d.ts +12 -0
- package/dist/recipes/5.7.0.d.ts.map +1 -0
- package/dist/recipes/5.7.0.js +70 -0
- package/dist/recipes/5.7.0.js.map +1 -0
- package/dist/recipes/index.d.ts +13 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +9 -2
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +10 -3
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +11 -4
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +52 -16
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/islands.d.ts +91 -0
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +757 -3
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/ppr.d.ts +16 -0
- package/dist/rules/ppr.d.ts.map +1 -0
- package/dist/rules/ppr.js +114 -0
- package/dist/rules/ppr.js.map +1 -0
- package/dist/rules/swap.d.ts +7 -0
- package/dist/rules/swap.d.ts.map +1 -0
- package/dist/rules/swap.js +338 -0
- package/dist/rules/swap.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts +8 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -0
- package/dist/rules/text-slot-boolean.js +57 -0
- package/dist/rules/text-slot-boolean.js.map +1 -0
- package/dist/rules/undeclared-response.d.ts +9 -0
- package/dist/rules/undeclared-response.d.ts.map +1 -0
- package/dist/rules/undeclared-response.js +93 -0
- package/dist/rules/undeclared-response.js.map +1 -0
- package/dist/scaffold-hole.d.ts +105 -0
- package/dist/scaffold-hole.d.ts.map +1 -0
- package/dist/scaffold-hole.js +688 -0
- package/dist/scaffold-hole.js.map +1 -0
- package/dist/scaffold.d.ts +5 -3
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +56 -46
- package/dist/scaffold.js.map +1 -1
- package/dist/upgrade.d.ts +34 -8
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +197 -25
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +12 -1
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.js +1 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +70 -10
- package/docs/llms-full.txt +3162 -1196
- package/docs/types.json +1473 -322
- package/package.json +11 -11
- package/src/cdn-check.ts +21 -7
- package/src/check-diagnostics.ts +9 -3
- package/src/check-scan.ts +35 -32
- package/src/check.ts +32 -10
- package/src/cli.ts +71 -9
- package/src/command-catalog.ts +149 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +62 -3
- package/src/fix-recipes.ts +28 -0
- package/src/frontend-guidance.ts +20 -8
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/introspect.ts +1 -1
- package/src/load.ts +29 -0
- package/src/local-cli.ts +83 -0
- package/src/lock-links.ts +5 -43
- package/src/mcp-delegate.ts +30 -9
- package/src/mcp-exec.ts +74 -3
- package/src/mcp-http.ts +3 -2
- package/src/mcp-tool-meta.ts +268 -0
- package/src/mcp.ts +35 -99
- package/src/openapi-types.ts +43 -2
- package/src/output-schemas.ts +28 -0
- package/src/ppr-read-fix.ts +426 -0
- package/src/recipes/5.6.0.ts +69 -0
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/index.ts +18 -0
- package/src/review.ts +9 -2
- package/src/rules/codes.ts +11 -4
- package/src/rules/explanations.ts +52 -16
- package/src/rules/islands.ts +875 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/ppr.ts +143 -0
- package/src/rules/swap.ts +402 -0
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/scaffold-hole.ts +880 -0
- package/src/scaffold.ts +60 -49
- package/src/upgrade.ts +229 -33
- package/src/verification-plan.ts +20 -1
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +2 -0
- package/dist/rules/nano.d.ts +0 -6
- package/dist/rules/nano.d.ts.map +0 -1
- package/dist/rules/nano.js +0 -273
- package/dist/rules/nano.js.map +0 -1
- package/src/rules/nano.ts +0 -307
package/src/lock-links.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* A `file:` dependency's own dependencies, as bun.lock records them. Bun records them when it first
|
|
3
3
|
* installs the linked package and does not read its package.json again, so once the linked package
|
|
4
4
|
* moves to another version of a dependency the lock still names the old one and Bun installs a second
|
|
5
|
-
* copy under the linked package. Checked on Bun 1.4.2: `bun install --force` keeps the stale entry
|
|
6
|
-
* `bun update <name
|
|
5
|
+
* copy under the linked package. Checked on Bun 1.4.2: `bun install --force` keeps the stale entry, and
|
|
6
|
+
* `bun update <name>` refreshes it alone; Bun 1.4.4 refreshes it on any install. Deleting the entry
|
|
7
|
+
* instead makes either re-resolve every package in the lock, and 1.4.4 rewrites lockfileVersion 1 as 2.
|
|
7
8
|
*/
|
|
8
9
|
import { existsSync, readFileSync } from "node:fs"
|
|
9
10
|
import { dirname, join, resolve } from "node:path"
|
|
@@ -113,45 +114,6 @@ export function staleLinkLocks(
|
|
|
113
114
|
export const describeChange = (change: LinkLockChange): string =>
|
|
114
115
|
`${change.name} ${change.recorded ?? "(none)"} -> ${change.declared ?? "(none)"}`
|
|
115
116
|
|
|
116
|
-
const ENTRY_KEY = /^ {4}("(?:[^"\\]|\\.)*"): \[/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* bun.lock text without the `packages` entries of `names` and the dependencies scoped under them,
|
|
120
|
-
* so the next `bun install` reads each linked package.json again. `undefined` unless the text is laid
|
|
121
|
-
* out one entry per line, as Bun writes it, and the result parses to the same lock less those
|
|
122
|
-
* entries: the caller names `bun update` instead.
|
|
123
|
-
*/
|
|
124
|
-
export function pruneLinkLocks(text: string, names: readonly string[]): string | undefined {
|
|
125
|
-
const lines = text.split("\n")
|
|
126
|
-
const start = lines.findIndex((line) => /^ {2}"packages": \{\s*$/.test(line))
|
|
127
|
-
if (start === -1) return undefined
|
|
128
|
-
const end = lines.findIndex((line, index) => index > start && /^ {2}\}/.test(line))
|
|
129
|
-
if (end === -1) return undefined
|
|
130
|
-
const dropped = (key: string): boolean =>
|
|
131
|
-
names.some((name) => key === name || key.startsWith(`${name}/`))
|
|
132
|
-
const kept = lines.filter((line, index) => {
|
|
133
|
-
if (index <= start || index >= end) return true
|
|
134
|
-
const key = ENTRY_KEY.exec(line)?.[1]
|
|
135
|
-
return key === undefined || !dropped(String(JSON.parse(key)))
|
|
136
|
-
})
|
|
137
|
-
const pruned = kept.join("\n")
|
|
138
|
-
try {
|
|
139
|
-
const before = recordOf(parseJsonc(text))
|
|
140
|
-
const after = recordOf(parseJsonc(pruned))
|
|
141
|
-
const expected = Object.fromEntries(
|
|
142
|
-
Object.entries(recordOf(before.packages)).filter(([key]) => !dropped(key)),
|
|
143
|
-
)
|
|
144
|
-
const same = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b)
|
|
145
|
-
if (!same(recordOf(after.packages), expected)) return undefined
|
|
146
|
-
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
147
|
-
if (key !== "packages" && !same(before[key], after[key])) return undefined
|
|
148
|
-
}
|
|
149
|
-
} catch {
|
|
150
|
-
return undefined
|
|
151
|
-
}
|
|
152
|
-
return pruned
|
|
153
|
-
}
|
|
154
|
-
|
|
155
117
|
/** The `bun update` that makes Bun read each linked package.json again. */
|
|
156
118
|
export const linkLockUpdate = (entries: readonly StaleLinkLock[]): string =>
|
|
157
119
|
`bun update ${entries.map((entry) => entry.package).join(" ")}`
|
|
@@ -169,7 +131,7 @@ export function staleLinkLockMessage(stale: {
|
|
|
169
131
|
})
|
|
170
132
|
.join("; ")
|
|
171
133
|
return (
|
|
172
|
-
`${stale.lock} records dependencies its file: packages no longer declare, and Bun never reads a linked package.json again, so it installs those versions beside the declared ones: ${listed}. ` +
|
|
173
|
-
`Run \`${linkLockUpdate(stale.entries)}
|
|
134
|
+
`${stale.lock} records dependencies its file: packages no longer declare, and Bun 1.4.2 never reads a linked package.json again, so it installs those versions beside the declared ones: ${listed}. ` +
|
|
135
|
+
`Run \`${linkLockUpdate(stale.entries)}\`: it refreshes those entries and keeps every other pin, where deleting them makes the next install re-resolve the whole lock. Review the bun.lock diff: Bun records each linked package.json as it is on disk, uncommitted edits included.`
|
|
174
136
|
)
|
|
175
137
|
}
|
package/src/mcp-delegate.ts
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
* instead of answering for the wrong release.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { existsSync } from "node:fs"
|
|
15
|
+
import { existsSync, realpathSync } from "node:fs"
|
|
16
16
|
import { readFile } from "node:fs/promises"
|
|
17
17
|
import { dirname, join } from "node:path"
|
|
18
|
+
import { fileURLToPath } from "node:url"
|
|
18
19
|
import type { McpTool, McpToolResult } from "./mcp-protocol.ts"
|
|
19
20
|
import type { ToolingDrift } from "./mcp-root.ts"
|
|
20
21
|
|
|
@@ -31,9 +32,11 @@ export const VERSION_SENSITIVE_TOOLS: ReadonlySet<string> = new Set([
|
|
|
31
32
|
"nifra_contracts",
|
|
32
33
|
])
|
|
33
34
|
|
|
34
|
-
/** The project's own CLI: its version and, when it is on disk, the script
|
|
35
|
+
/** The project's own CLI: its version, its package directory, and, when it is on disk, the script
|
|
36
|
+
* its `bin` names. */
|
|
35
37
|
export interface ProjectCli {
|
|
36
38
|
readonly version: string
|
|
39
|
+
readonly dir: string
|
|
37
40
|
readonly bin?: string
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -60,8 +63,8 @@ export async function findProjectCli(root: string): Promise<ProjectCli | undefin
|
|
|
60
63
|
const script = binScript(meta.bin)
|
|
61
64
|
const bin = script === undefined ? undefined : join(pkg, script)
|
|
62
65
|
return bin !== undefined && existsSync(bin)
|
|
63
|
-
? { version: meta.version, bin }
|
|
64
|
-
: { version: meta.version }
|
|
66
|
+
? { version: meta.version, dir: pkg, bin }
|
|
67
|
+
: { version: meta.version, dir: pkg }
|
|
65
68
|
}
|
|
66
69
|
} catch {
|
|
67
70
|
// Not installed at this level - keep walking up.
|
|
@@ -73,11 +76,25 @@ export async function findProjectCli(root: string): Promise<ProjectCli | undefin
|
|
|
73
76
|
return undefined
|
|
74
77
|
}
|
|
75
78
|
|
|
79
|
+
/** This CLI's package directory: the parent of `src/` or `dist/`, where this module sits. */
|
|
80
|
+
export const OWN_CLI_DIR = fileURLToPath(new URL("..", import.meta.url))
|
|
81
|
+
|
|
82
|
+
/** Whether `dir` is another install than this CLI's own: a version can match while the copy, and the
|
|
83
|
+
* `@nifrajs/core` beside it, does not. */
|
|
84
|
+
export function isOtherInstall(dir: string): boolean {
|
|
85
|
+
try {
|
|
86
|
+
return realpathSync(dir) !== realpathSync(OWN_CLI_DIR)
|
|
87
|
+
} catch {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
76
92
|
/**
|
|
77
|
-
* Hand this stdio session to the project's own CLI when it installs a different version
|
|
78
|
-
* the child's exit code once the session ends, or
|
|
79
|
-
*
|
|
80
|
-
*
|
|
93
|
+
* Hand this stdio session to the project's own CLI when it installs a different version, or the same
|
|
94
|
+
* version from another directory. Resolves to the child's exit code once the session ends, or
|
|
95
|
+
* `undefined` when this process should serve itself (this is the project's CLI, no project CLI or
|
|
96
|
+
* bin, already a hand-off, or the spawn failed). Must run before anything reads stdin: the child
|
|
97
|
+
* inherits the descriptor and owns the whole conversation.
|
|
81
98
|
*/
|
|
82
99
|
export async function delegateToProjectCli(options: {
|
|
83
100
|
readonly cwd: string
|
|
@@ -87,7 +104,11 @@ export async function delegateToProjectCli(options: {
|
|
|
87
104
|
}): Promise<number | undefined> {
|
|
88
105
|
if (process.env[MCP_DELEGATED_ENV] === "1") return undefined
|
|
89
106
|
const cli = await findProjectCli(options.root)
|
|
90
|
-
if (
|
|
107
|
+
if (
|
|
108
|
+
cli === undefined ||
|
|
109
|
+
cli.bin === undefined ||
|
|
110
|
+
(cli.version === options.version && !isOtherInstall(cli.dir))
|
|
111
|
+
)
|
|
91
112
|
return undefined
|
|
92
113
|
// Not the `.bin` shim: its `bun` would load the project's `.env`, and the inherited
|
|
93
114
|
// NIFRA_MCP_WITHOUT_ENV_FILES then tells that CLI the values are already gone.
|
package/src/mcp-exec.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
} from "./mcp-io.ts"
|
|
50
50
|
import { mcpProjectPathError, resolveMcpProjectPath } from "./mcp-path.ts"
|
|
51
51
|
import type { McpTool, McpToolContext } from "./mcp-protocol.ts"
|
|
52
|
+
import { withToolMeta } from "./mcp-tool-meta.ts"
|
|
52
53
|
import { loadTypesCorpus } from "./types-search.ts"
|
|
53
54
|
|
|
54
55
|
const CODEFRAME_SOURCE = /\.(?:[cm]?[jt]sx?|vue|svelte|astro|mdx)$/i
|
|
@@ -617,23 +618,93 @@ export function projectTools(
|
|
|
617
618
|
description:
|
|
618
619
|
"When true, create both files if a verified ready-to-write page stub exists. Refuses overwrite.",
|
|
619
620
|
},
|
|
621
|
+
hole: {
|
|
622
|
+
type: "object",
|
|
623
|
+
description:
|
|
624
|
+
"Add a partially prerendered hole to the existing route at `path` instead of a new page: its definition and <Hole> in the page, its loader in the backend half. The route's backend half must export shellLoader. A Vue or Svelte page gets the snippet to paste.",
|
|
625
|
+
properties: {
|
|
626
|
+
name: {
|
|
627
|
+
type: "string",
|
|
628
|
+
description:
|
|
629
|
+
"1 to 32 lowercase letters, digits and single hyphens, starting with a letter.",
|
|
630
|
+
},
|
|
631
|
+
shared: {
|
|
632
|
+
type: "boolean",
|
|
633
|
+
description: "The same for every visitor, cached on its own revalidate.",
|
|
634
|
+
},
|
|
635
|
+
interactive: {
|
|
636
|
+
type: "boolean",
|
|
637
|
+
description: "Ships its props and hydrates as its own root.",
|
|
638
|
+
},
|
|
639
|
+
timeout: {
|
|
640
|
+
type: "integer",
|
|
641
|
+
description: "The hole's deadline in milliseconds, 1 to 30000.",
|
|
642
|
+
},
|
|
643
|
+
server: {
|
|
644
|
+
type: "boolean",
|
|
645
|
+
description: "Show a React server component, built by the coordinated compiler.",
|
|
646
|
+
},
|
|
647
|
+
},
|
|
648
|
+
required: ["name"],
|
|
649
|
+
additionalProperties: false,
|
|
650
|
+
},
|
|
620
651
|
variant: {
|
|
621
652
|
type: "string",
|
|
622
653
|
enum: ["default", "stateful"],
|
|
623
654
|
description:
|
|
624
|
-
'Stub flavour. "default" is the plain page stub. "stateful" (vanilla only) emits
|
|
655
|
+
'Stub flavour. "default" is the plain page stub. "stateful" (vanilla only) emits a reactive island - bindIsland state, data-bind-* markup and a keyed bindList - whose binding names, binding hosts and list keys NF-C047/C048/C022 check statically. Use it for a small app with local state (a list a human edits) instead of reaching for a framework.',
|
|
625
656
|
},
|
|
626
657
|
},
|
|
627
658
|
required: ["path"],
|
|
628
659
|
additionalProperties: false,
|
|
629
660
|
},
|
|
630
661
|
handler: async (args) => {
|
|
631
|
-
const { path, write, variant } = args as {
|
|
662
|
+
const { path, write, variant, hole } = args as {
|
|
632
663
|
path?: string
|
|
633
664
|
write?: boolean
|
|
665
|
+
hole?: {
|
|
666
|
+
name?: string
|
|
667
|
+
shared?: boolean
|
|
668
|
+
interactive?: boolean
|
|
669
|
+
timeout?: number
|
|
670
|
+
server?: boolean
|
|
671
|
+
}
|
|
634
672
|
variant?: "default" | "stateful"
|
|
635
673
|
}
|
|
636
674
|
if (typeof path !== "string" || path.length === 0) return "scaffold: `path` is required."
|
|
675
|
+
if (hole !== undefined) {
|
|
676
|
+
if (typeof hole.name !== "string") return "scaffold: `hole.name` is required."
|
|
677
|
+
const { frameworkFromClientModule } = await import("./scaffold.ts")
|
|
678
|
+
const { holeRouteFiles, renderHoleScaffold, routeTypeScript, scaffoldHole } =
|
|
679
|
+
await import("./scaffold-hole.ts")
|
|
680
|
+
const framework = frameworkFromClientModule(
|
|
681
|
+
(await loadAppCached()).framework.clientModule,
|
|
682
|
+
)
|
|
683
|
+
const { page, backend } = holeRouteFiles(path, framework)
|
|
684
|
+
const loaded = await routeTypeScript(cwd, [page, backend])
|
|
685
|
+
if (loaded.unsupported !== undefined) return loaded.unsupported.message
|
|
686
|
+
if (loaded.compiler === undefined)
|
|
687
|
+
return "scaffold: a hole is placed through the route's syntax tree, so it needs TypeScript (`bun add -d typescript`)."
|
|
688
|
+
try {
|
|
689
|
+
const result = await scaffoldHole(
|
|
690
|
+
cwd,
|
|
691
|
+
path,
|
|
692
|
+
hole.name,
|
|
693
|
+
framework,
|
|
694
|
+
{
|
|
695
|
+
shared: hole.shared,
|
|
696
|
+
interactive: hole.interactive,
|
|
697
|
+
timeout: hole.timeout,
|
|
698
|
+
server: hole.server,
|
|
699
|
+
},
|
|
700
|
+
loaded.compiler,
|
|
701
|
+
write === true,
|
|
702
|
+
)
|
|
703
|
+
return renderHoleScaffold(hole.name, framework, result)
|
|
704
|
+
} finally {
|
|
705
|
+
await loaded.session?.close()
|
|
706
|
+
}
|
|
707
|
+
}
|
|
637
708
|
const flavour = variant === "stateful" ? "stateful" : "default"
|
|
638
709
|
const { frameworkFromClientModule, renderScaffold, writeScaffoldRoute } = await import(
|
|
639
710
|
"./scaffold.ts"
|
|
@@ -676,7 +747,7 @@ export function projectTools(
|
|
|
676
747
|
},
|
|
677
748
|
},
|
|
678
749
|
]
|
|
679
|
-
return [...catalogTools, ...legacyTools]
|
|
750
|
+
return [...catalogTools, ...legacyTools].map(withToolMeta)
|
|
680
751
|
}
|
|
681
752
|
|
|
682
753
|
function childPath(name: "mcp-run" | "mcp-render" | "mcp-ws"): string {
|
package/src/mcp-http.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The PUBLIC nifra docs MCP - Streamable-HTTP transport exposing the project-INDEPENDENT tools
|
|
3
|
-
* (`nifra_docs`, `nifra_example`, `nifra_types`, `nifra_learn` + the `nifra_gallery`
|
|
3
|
+
* (`nifra_docs`, `nifra_example`, `nifra_types`, `nifra_learn`, `nifra_frontend` + the `nifra_gallery`
|
|
4
|
+
* MCP Apps widget)
|
|
4
5
|
* so any remote AI agent can learn nifra without a local checkout. They read the bundled corpus
|
|
5
6
|
* (llms-full.txt / examples.json / types.json shipped in this package) and ignore `cwd`, so they reuse the
|
|
6
7
|
* exact definitions from {@link projectTools} - one source, no drift.
|
|
@@ -29,7 +30,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
|
|
|
29
30
|
export type { TypeEntry } from "./types-search.ts"
|
|
30
31
|
|
|
31
32
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
32
|
-
const VERSION = "5.
|
|
33
|
+
const VERSION = "5.7.0"
|
|
33
34
|
const SERVER_INFO = { name: "nifra-docs", version: VERSION }
|
|
34
35
|
// Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
|
|
35
36
|
const docsHealth = (tools: McpTool[]): string =>
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each `nifra mcp` project tool may do, as MCP tool annotations, and a description for each
|
|
3
|
+
* input field its definition leaves bare. A host reads the annotations to decide which calls need
|
|
4
|
+
* the user's confirmation, so a tool that can write a file or run project code must never look
|
|
5
|
+
* read-only. Importing the project's config or backend runs its top-level code, so a tool that
|
|
6
|
+
* imports either runs project code. The hints describe the tool for any input: a tool that writes
|
|
7
|
+
* only under a flag is a writer. mcp-tool-meta.test.ts fails on a tool or a field missing here, and
|
|
8
|
+
* on a read-only tool that imports the project.
|
|
9
|
+
*/
|
|
10
|
+
import type { McpTool, McpToolAnnotations } from "./mcp-protocol.ts"
|
|
11
|
+
|
|
12
|
+
const READ: McpToolAnnotations = {
|
|
13
|
+
readOnlyHint: true,
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
}
|
|
18
|
+
// Writes or overwrites project files, at least for some inputs.
|
|
19
|
+
const WRITE: McpToolAnnotations = {
|
|
20
|
+
readOnlyHint: false,
|
|
21
|
+
destructiveHint: true,
|
|
22
|
+
idempotentHint: true,
|
|
23
|
+
openWorldHint: false,
|
|
24
|
+
}
|
|
25
|
+
// Runs project code, tests, builds or scripts, which can do anything that code does.
|
|
26
|
+
const EXECUTE: McpToolAnnotations = {
|
|
27
|
+
readOnlyHint: false,
|
|
28
|
+
destructiveHint: true,
|
|
29
|
+
idempotentHint: false,
|
|
30
|
+
openWorldHint: true,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DIR = "Project subdirectory to run in, relative to the project root this server serves."
|
|
34
|
+
const JSON_RESULT = "Return the structured JSON result instead of the human-readable report."
|
|
35
|
+
const CONFIG = "Config file to read instead of the project's default nifra.config.ts."
|
|
36
|
+
const TARGET = "Deploy target to judge against (bun, node, deno, cloudflare, vercel)."
|
|
37
|
+
|
|
38
|
+
interface ToolMeta {
|
|
39
|
+
readonly annotations: McpToolAnnotations
|
|
40
|
+
readonly fields?: Readonly<Record<string, string>>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Every project tool by name. The docs tools set their own annotations and are not repeated. */
|
|
44
|
+
export const PROJECT_TOOL_META: Readonly<Record<string, ToolMeta>> = {
|
|
45
|
+
nifra_check: {
|
|
46
|
+
annotations: READ,
|
|
47
|
+
fields: {
|
|
48
|
+
lintsOnly: "Skip tsc and run only the source lints, a near-instant pass.",
|
|
49
|
+
json: JSON_RESULT,
|
|
50
|
+
sarif: "Return the diagnostics as a SARIF 2.1.0 log.",
|
|
51
|
+
maxDiagnostics: "Return at most this many diagnostics.",
|
|
52
|
+
dir: DIR,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
nifra_review: {
|
|
56
|
+
annotations: WRITE,
|
|
57
|
+
fields: {
|
|
58
|
+
strict: "Treat warnings as blocking.",
|
|
59
|
+
diff: "Review only the files changed since this git ref, instead of the whole project.",
|
|
60
|
+
sarif: "Also write the findings as SARIF 2.1.0 to this project-relative file.",
|
|
61
|
+
fix: "Plan the registered recipes for the findings.",
|
|
62
|
+
dryRun: "With fix: show the planned edits without writing them.",
|
|
63
|
+
write: "With fix: apply the planned edits to the project's files.",
|
|
64
|
+
json: JSON_RESULT,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
nifra_assure: {
|
|
68
|
+
annotations: EXECUTE,
|
|
69
|
+
fields: {
|
|
70
|
+
config: CONFIG,
|
|
71
|
+
bundle: "Build the deploy bundle and verify the routes it serves, not only the source.",
|
|
72
|
+
strict: "Fail on a route whose evidence is a skip (implies bundle).",
|
|
73
|
+
hydration: "Also check that every page hydrates without errors (implies bundle).",
|
|
74
|
+
interact: "Also click through each page in a browser (implies bundle).",
|
|
75
|
+
out: "Write the assurance bundle to this project-relative file (implies bundle).",
|
|
76
|
+
json: JSON_RESULT,
|
|
77
|
+
dir: DIR,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
nifra_levels: {
|
|
81
|
+
annotations: EXECUTE,
|
|
82
|
+
fields: {
|
|
83
|
+
config: CONFIG,
|
|
84
|
+
seed: "Deterministic seed for the L4 invariant run. Default 1.",
|
|
85
|
+
min: "Fail when the project is below this level (0 to 4).",
|
|
86
|
+
json: JSON_RESULT,
|
|
87
|
+
dir: DIR,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
nifra_capabilities: {
|
|
91
|
+
annotations: WRITE,
|
|
92
|
+
fields: {
|
|
93
|
+
action:
|
|
94
|
+
"snapshot writes the capability lockfile, check compares the project with it, explain describes one route.",
|
|
95
|
+
config: CONFIG,
|
|
96
|
+
out: "snapshot: the project-relative lockfile to write.",
|
|
97
|
+
lockfile: "check: the project-relative lockfile to compare against.",
|
|
98
|
+
method: "explain: the route's HTTP method.",
|
|
99
|
+
path: "explain: the route's path.",
|
|
100
|
+
json: JSON_RESULT,
|
|
101
|
+
dir: DIR,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
nifra_manifest: {
|
|
105
|
+
annotations: WRITE,
|
|
106
|
+
fields: {
|
|
107
|
+
action: "emit writes the route trust manifest, diff compares two manifests.",
|
|
108
|
+
config: CONFIG,
|
|
109
|
+
out: "emit: the project-relative file to write.",
|
|
110
|
+
before: "diff: the project-relative manifest to compare from.",
|
|
111
|
+
after: "diff: the project-relative manifest to compare to.",
|
|
112
|
+
json: JSON_RESULT,
|
|
113
|
+
dir: DIR,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
nifra_routes: {
|
|
117
|
+
annotations: EXECUTE,
|
|
118
|
+
fields: {
|
|
119
|
+
json: JSON_RESULT,
|
|
120
|
+
graph: "Render the public route surface as a Mermaid graph.",
|
|
121
|
+
modes: "Show each page route's render mode (static, isr, ssr), hydration and cache policy.",
|
|
122
|
+
hooks: "List the hooks each backend route and each prefix's unmatched paths run.",
|
|
123
|
+
since: "hooks: a project-relative saved hooks report to diff against.",
|
|
124
|
+
target: `modes: ${TARGET}`,
|
|
125
|
+
dir: DIR,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
nifra_context: {
|
|
129
|
+
annotations: EXECUTE,
|
|
130
|
+
fields: {
|
|
131
|
+
path: "Only the routes whose path starts with this.",
|
|
132
|
+
kind: "Only the API routes or only the page routes.",
|
|
133
|
+
dir: DIR,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
nifra_doctor: {
|
|
137
|
+
annotations: WRITE,
|
|
138
|
+
fields: {
|
|
139
|
+
json: JSON_RESULT,
|
|
140
|
+
autoFix: "Write the safe local-version dependency fixes to package.json.",
|
|
141
|
+
strict: "Fail when an applicable production-readiness guarantee is absent.",
|
|
142
|
+
target: TARGET,
|
|
143
|
+
dir: DIR,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
nifra_fix: {
|
|
147
|
+
annotations: WRITE,
|
|
148
|
+
fields: {
|
|
149
|
+
code: "Apply only the recipe for this diagnostic code (for example NF-C007).",
|
|
150
|
+
json: JSON_RESULT,
|
|
151
|
+
dir: DIR,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
nifra_snapshot: {
|
|
155
|
+
annotations: WRITE,
|
|
156
|
+
fields: {
|
|
157
|
+
out: "The project-relative file to write. Default api-snapshot.json.",
|
|
158
|
+
json: JSON_RESULT,
|
|
159
|
+
dir: DIR,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
nifra_diff: {
|
|
163
|
+
annotations: EXECUTE,
|
|
164
|
+
fields: {
|
|
165
|
+
baseline: "The project-relative snapshot to compare with. Default api-snapshot.json.",
|
|
166
|
+
json: JSON_RESULT,
|
|
167
|
+
dir: DIR,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
nifra_contracts: {
|
|
171
|
+
annotations: WRITE,
|
|
172
|
+
fields: {
|
|
173
|
+
action: "snapshot writes contracts.lock.json, check compares the routes with it.",
|
|
174
|
+
out: "snapshot: the project-relative lock file to write.",
|
|
175
|
+
json: JSON_RESULT,
|
|
176
|
+
dir: DIR,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
nifra_sync_manifest: { annotations: WRITE, fields: { json: JSON_RESULT, dir: DIR } },
|
|
180
|
+
nifra_sync_routes: { annotations: WRITE, fields: { json: JSON_RESULT, dir: DIR } },
|
|
181
|
+
nifra_prove: {
|
|
182
|
+
annotations: EXECUTE,
|
|
183
|
+
fields: {
|
|
184
|
+
files: "The changed files to plan proofs for, project-relative.",
|
|
185
|
+
minLevel: "The verification level (0 to 4) the stop condition requires.",
|
|
186
|
+
json: JSON_RESULT,
|
|
187
|
+
dir: DIR,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
nifra_replay: {
|
|
191
|
+
annotations: EXECUTE,
|
|
192
|
+
fields: { file: "The project-relative verification metadata file to replay.", dir: DIR },
|
|
193
|
+
},
|
|
194
|
+
nifra_smoke: {
|
|
195
|
+
annotations: EXECUTE,
|
|
196
|
+
fields: {
|
|
197
|
+
fixture: "The project-relative smoke fixture. Default nifra.smoke.ts.",
|
|
198
|
+
inProcess: "Run against the app in this process instead of a started production server.",
|
|
199
|
+
json: JSON_RESULT,
|
|
200
|
+
dir: DIR,
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
nifra_port: {
|
|
204
|
+
annotations: READ,
|
|
205
|
+
fields: {
|
|
206
|
+
target: `${TARGET} Fails when a used feature is unsupported there.`,
|
|
207
|
+
json: JSON_RESULT,
|
|
208
|
+
ci: "Fail when a used feature is unsupported on the target.",
|
|
209
|
+
strict: "Also fail on a feature the target supports only with a caveat.",
|
|
210
|
+
dir: DIR,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
nifra_errors: { annotations: READ, fields: { json: JSON_RESULT } },
|
|
214
|
+
nifra_logs: {
|
|
215
|
+
annotations: READ,
|
|
216
|
+
fields: {
|
|
217
|
+
json: JSON_RESULT,
|
|
218
|
+
level: "Only lines at these levels.",
|
|
219
|
+
source: "Only the server's or only the browser's lines.",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
nifra_db_schema: { annotations: EXECUTE, fields: { json: JSON_RESULT } },
|
|
223
|
+
nifra_db_query: { annotations: EXECUTE, fields: { json: JSON_RESULT } },
|
|
224
|
+
nifra_db_role: { annotations: EXECUTE, fields: { json: JSON_RESULT } },
|
|
225
|
+
nifra_verify: { annotations: EXECUTE },
|
|
226
|
+
nifra_contract_proof: { annotations: READ },
|
|
227
|
+
nifra_explain: { annotations: READ },
|
|
228
|
+
nifra_inspect: { annotations: READ },
|
|
229
|
+
nifra_openapi: { annotations: EXECUTE },
|
|
230
|
+
nifra_run: {
|
|
231
|
+
annotations: EXECUTE,
|
|
232
|
+
fields: {
|
|
233
|
+
requests:
|
|
234
|
+
"The requests to run, in order: each a path, with an optional method, headers and JSON body.",
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
nifra_render: {
|
|
238
|
+
annotations: EXECUTE,
|
|
239
|
+
fields: { requests: "The pages to render, in order: each a path, with optional headers." },
|
|
240
|
+
},
|
|
241
|
+
nifra_ws: { annotations: EXECUTE },
|
|
242
|
+
nifra_test: { annotations: EXECUTE },
|
|
243
|
+
nifra_scaffold: { annotations: WRITE },
|
|
244
|
+
nifra_hydrate: { annotations: EXECUTE },
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** `tool` with its annotations and field descriptions from {@link PROJECT_TOOL_META}. A tool that
|
|
248
|
+
* sets annotations itself keeps them, and so does a field that has a description. */
|
|
249
|
+
export function withToolMeta(tool: McpTool): McpTool {
|
|
250
|
+
const meta = PROJECT_TOOL_META[tool.name]
|
|
251
|
+
if (meta === undefined) return tool
|
|
252
|
+
const annotated = { ...tool, annotations: tool.annotations ?? meta.annotations }
|
|
253
|
+
const fields = meta.fields
|
|
254
|
+
const properties = tool.inputSchema.properties
|
|
255
|
+
if (fields === undefined || !isRecord(properties)) return annotated
|
|
256
|
+
const described = Object.fromEntries(
|
|
257
|
+
Object.entries(properties).map(([name, property]) => {
|
|
258
|
+
const description = fields[name]
|
|
259
|
+
return description === undefined || !isRecord(property) || "description" in property
|
|
260
|
+
? [name, property]
|
|
261
|
+
: [name, { ...property, description }]
|
|
262
|
+
}),
|
|
263
|
+
)
|
|
264
|
+
return { ...annotated, inputSchema: { ...tool.inputSchema, properties: described } }
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
|
268
|
+
typeof value === "object" && value !== null
|