@nifrajs/cli 5.1.0 → 5.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/CHANGELOG.md +3313 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +7 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +5 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -3
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +61 -21
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +55 -15
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +37 -18
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +2 -1
- package/dist/db-tool.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +41 -8
- package/dist/env-file.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +22 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +322 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +16 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +23 -3
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +59 -12
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +435 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/5.3.0.d.ts +11 -0
- package/dist/recipes/5.3.0.d.ts.map +1 -0
- package/dist/recipes/5.3.0.js +35 -0
- package/dist/recipes/5.3.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +9 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +4 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +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/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +326 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +51 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +293 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/route-statement.d.ts +10 -0
- package/dist/rules/route-statement.d.ts.map +1 -0
- package/dist/rules/route-statement.js +150 -0
- package/dist/rules/route-statement.js.map +1 -0
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +80 -11
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +332 -65
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -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 +19 -1
- package/docs/llms-full.txt +716 -138
- package/docs/types.json +516 -74
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +8 -1
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +64 -19
- package/src/check.ts +75 -15
- package/src/cli.ts +38 -17
- package/src/command-catalog.ts +16 -8
- package/src/db-tool.ts +2 -0
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/env-file.ts +42 -7
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +397 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +18 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +72 -12
- package/src/mcp-isolate.ts +2 -0
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +496 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/5.3.0.ts +36 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +4 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +4 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +339 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +381 -2
- package/src/rules/route-statement.ts +170 -0
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +430 -70
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
package/src/load.ts
CHANGED
|
@@ -85,7 +85,8 @@ export interface NifraFramework {
|
|
|
85
85
|
readonly dev?: { readonly indicator?: boolean; readonly allowedHosts?: readonly string[] }
|
|
86
86
|
/** Static files directory. Defaults to `<app>/public`; `false` disables it. */
|
|
87
87
|
readonly publicDir?: string | false
|
|
88
|
-
/** Client-visible environment prefix (default `"PUBLIC_"`; empty disables exposure).
|
|
88
|
+
/** Client-visible environment prefix (default `"PUBLIC_"`; empty disables exposure). With both
|
|
89
|
+
* configs, `nifra.config.ts` wins and `backend/framework.ts` fills it in when left unset. */
|
|
89
90
|
readonly publicEnvPrefix?: string
|
|
90
91
|
/** Reviewed false positives of `nifra build`'s secret scan, each `{ rule, file, reason }` (or
|
|
91
92
|
* `{ rule: "private-env-value", env, reason }`). There is no exemption by value. */
|
|
@@ -111,6 +112,10 @@ export interface NifraFramework {
|
|
|
111
112
|
readonly csp?: CreateWebAppOptions["csp"]
|
|
112
113
|
/** A per-request CSP nonce resolver. Exclusive with {@link csp}. */
|
|
113
114
|
readonly nonce?: CreateWebAppOptions["nonce"]
|
|
115
|
+
/** The app's locale routing, `defineI18nRouting()` from `@nifrajs/i18n/routing`: every document
|
|
116
|
+
* takes its `<html lang dir>`, `Content-Language` and adapter locale from it. See `createWebApp`'s
|
|
117
|
+
* `i18n`. */
|
|
118
|
+
readonly i18n?: CreateWebAppOptions["i18n"]
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
/** The {@link NifraFramework} fields forwarded to `createWebApp` and imported by the generated server
|
|
@@ -122,6 +127,7 @@ export const FRAMEWORK_WEB_OPTIONS = [
|
|
|
122
127
|
"csp",
|
|
123
128
|
"nonce",
|
|
124
129
|
"serverComponents",
|
|
130
|
+
"i18n",
|
|
125
131
|
] as const
|
|
126
132
|
export type FrameworkWebOption = (typeof FRAMEWORK_WEB_OPTIONS)[number]
|
|
127
133
|
|
|
@@ -162,6 +168,15 @@ function assertFrameworkWebOptions(fw: Partial<NifraFramework>, configFile: stri
|
|
|
162
168
|
if (fw.nonce !== undefined && typeof fw.nonce !== "function") {
|
|
163
169
|
wrong("nonce", "a nonce resolver function, such as createNonceResolver() returns")
|
|
164
170
|
}
|
|
171
|
+
if (
|
|
172
|
+
fw.i18n !== undefined &&
|
|
173
|
+
(typeof fw.i18n !== "object" || fw.i18n === null || typeof fw.i18n.localeOf !== "function")
|
|
174
|
+
) {
|
|
175
|
+
wrong("i18n", "the router defineI18nRouting() from @nifrajs/i18n/routing returns")
|
|
176
|
+
}
|
|
177
|
+
if (fw.publicEnvPrefix !== undefined && typeof fw.publicEnvPrefix !== "string") {
|
|
178
|
+
wrong("publicEnvPrefix", 'a string such as "PUBLIC_", or "" to expose no environment variable')
|
|
179
|
+
}
|
|
165
180
|
if (fw.secretExemptions !== undefined && !Array.isArray(fw.secretExemptions)) {
|
|
166
181
|
wrong("secretExemptions", "an array of { rule, file, reason } entries")
|
|
167
182
|
}
|
|
@@ -342,8 +357,9 @@ export async function loadBackendApp(
|
|
|
342
357
|
return { cwd, backend }
|
|
343
358
|
}
|
|
344
359
|
|
|
345
|
-
/** The fields the generated server entry imports from backend/framework.ts
|
|
346
|
-
|
|
360
|
+
/** The fields the generated server entry imports from backend/framework.ts, and `publicEnvPrefix`,
|
|
361
|
+
* which `nifra check` reads there too: each command must draw the browser-env line in one place. */
|
|
362
|
+
const SERVER_OPTIONS = [...FRAMEWORK_WEB_OPTIONS, "use", "publicEnvPrefix"] as const
|
|
347
363
|
|
|
348
364
|
/**
|
|
349
365
|
* `config` with each server option it leaves unset taken from backend/framework.ts, so `nifra dev` and
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `file:` dependency's own dependencies, as bun.lock records them. Bun records them when it first
|
|
3
|
+
* installs the linked package and does not read its package.json again, so once the linked package
|
|
4
|
+
* moves to another version of a dependency the lock still names the old one and Bun installs a second
|
|
5
|
+
* copy under the linked package. Checked on Bun 1.4.2: `bun install --force` keeps the stale entry;
|
|
6
|
+
* `bun update <name>`, or dropping the entry and its scoped entries before `bun install`, clears it.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
9
|
+
import { dirname, join, resolve } from "node:path"
|
|
10
|
+
import { parseJsonc } from "./internal/project-specifiers.ts"
|
|
11
|
+
|
|
12
|
+
export const BUN_LOCK = "bun.lock"
|
|
13
|
+
|
|
14
|
+
/** The fields Bun installs from a linked package's manifest. */
|
|
15
|
+
const INSTALLED_FIELDS: readonly string[] = [
|
|
16
|
+
"dependencies",
|
|
17
|
+
"optionalDependencies",
|
|
18
|
+
"peerDependencies",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
/** One dependency whose recorded spec is not the one the linked package.json declares now. */
|
|
22
|
+
export interface LinkLockChange {
|
|
23
|
+
readonly name: string
|
|
24
|
+
/** As bun.lock recorded it; absent when the linked package added it since. */
|
|
25
|
+
readonly recorded?: string
|
|
26
|
+
/** As the linked package.json declares it; absent when it was removed since. */
|
|
27
|
+
readonly declared?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A `file:` entry of bun.lock whose recorded dependencies the linked package.json no longer declares. */
|
|
31
|
+
export interface StaleLinkLock {
|
|
32
|
+
/** The package, as the lock keys it. */
|
|
33
|
+
readonly package: string
|
|
34
|
+
/** The linked directory, as the lock names it relative to the lockfile. */
|
|
35
|
+
readonly path: string
|
|
36
|
+
readonly changes: readonly LinkLockChange[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const recordOf = (value: unknown): Readonly<Record<string, unknown>> =>
|
|
40
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
41
|
+
? Object.fromEntries(Object.entries(value))
|
|
42
|
+
: {}
|
|
43
|
+
|
|
44
|
+
const textOf = (value: unknown): string | undefined =>
|
|
45
|
+
typeof value === "string" ? value : undefined
|
|
46
|
+
|
|
47
|
+
/** A top-level lock key (`name`, `@scope/name`), not a dependency scoped under one (`name/dep`). */
|
|
48
|
+
const topLevel = (key: string): boolean =>
|
|
49
|
+
key.startsWith("@") ? key.split("/").length === 2 : !key.includes("/")
|
|
50
|
+
|
|
51
|
+
/** The directory of the nearest bun.lock at or above `cwd`, up to the repository root. */
|
|
52
|
+
export function bunLockDir(cwd: string): string | undefined {
|
|
53
|
+
for (let dir = resolve(cwd); ; ) {
|
|
54
|
+
if (existsSync(join(dir, BUN_LOCK))) return dir
|
|
55
|
+
const parent = dirname(dir)
|
|
56
|
+
if (parent === dir || existsSync(join(dir, ".git"))) return undefined
|
|
57
|
+
dir = parent
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Each `file:` entry of the bun.lock in `dir` whose recorded dependencies differ from what the linked
|
|
63
|
+
* package.json declares. `manifests` (absolute path -> text) stands in for package.json files an edit
|
|
64
|
+
* has planned but not written yet. A lock or manifest that cannot be read reports nothing.
|
|
65
|
+
*/
|
|
66
|
+
export function staleLinkLocks(
|
|
67
|
+
dir: string,
|
|
68
|
+
manifests: ReadonlyMap<string, string> = new Map(),
|
|
69
|
+
): StaleLinkLock[] {
|
|
70
|
+
let lock: unknown
|
|
71
|
+
try {
|
|
72
|
+
lock = parseJsonc(readFileSync(join(dir, BUN_LOCK), "utf8"))
|
|
73
|
+
} catch {
|
|
74
|
+
return []
|
|
75
|
+
}
|
|
76
|
+
const stale: StaleLinkLock[] = []
|
|
77
|
+
for (const [key, entry] of Object.entries(recordOf(Reflect.get(Object(lock), "packages")))) {
|
|
78
|
+
if (!topLevel(key) || !Array.isArray(entry)) continue
|
|
79
|
+
const spec = textOf(entry[0])
|
|
80
|
+
const at = spec?.indexOf("@file:", 1) ?? -1
|
|
81
|
+
if (spec === undefined || at === -1) continue
|
|
82
|
+
const path = spec.slice(at + "@file:".length)
|
|
83
|
+
const manifestPath = resolve(dir, path, "package.json")
|
|
84
|
+
let declared: unknown
|
|
85
|
+
try {
|
|
86
|
+
declared = JSON.parse(manifests.get(manifestPath) ?? readFileSync(manifestPath, "utf8"))
|
|
87
|
+
} catch {
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
const recorded = recordOf(entry[1])
|
|
91
|
+
const changes: LinkLockChange[] = []
|
|
92
|
+
for (const field of INSTALLED_FIELDS) {
|
|
93
|
+
const was = recordOf(recorded[field])
|
|
94
|
+
const now = recordOf(Reflect.get(Object(declared), field))
|
|
95
|
+
for (const name of new Set([...Object.keys(was), ...Object.keys(now)])) {
|
|
96
|
+
const before = textOf(was[name])
|
|
97
|
+
const after = textOf(now[name])
|
|
98
|
+
if (before === after) continue
|
|
99
|
+
const change: { name: string; recorded?: string; declared?: string } = { name }
|
|
100
|
+
if (before !== undefined) change.recorded = before
|
|
101
|
+
if (after !== undefined) change.declared = after
|
|
102
|
+
changes.push(change)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (changes.length > 0) stale.push({ package: key, path, changes })
|
|
106
|
+
}
|
|
107
|
+
return stale
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `name 1.0.0 -> 2.0.0`, with `(none)` for a side that does not have it. */
|
|
111
|
+
export const describeChange = (change: LinkLockChange): string =>
|
|
112
|
+
`${change.name} ${change.recorded ?? "(none)"} -> ${change.declared ?? "(none)"}`
|
|
113
|
+
|
|
114
|
+
const ENTRY_KEY = /^ {4}("(?:[^"\\]|\\.)*"): \[/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* bun.lock text without the `packages` entries of `names` and the dependencies scoped under them,
|
|
118
|
+
* so the next `bun install` reads each linked package.json again. `undefined` unless the text is laid
|
|
119
|
+
* out one entry per line, as Bun writes it, and the result parses to the same lock less those
|
|
120
|
+
* entries: the caller names `bun update` instead.
|
|
121
|
+
*/
|
|
122
|
+
export function pruneLinkLocks(text: string, names: readonly string[]): string | undefined {
|
|
123
|
+
const lines = text.split("\n")
|
|
124
|
+
const start = lines.findIndex((line) => /^ {2}"packages": \{\s*$/.test(line))
|
|
125
|
+
if (start === -1) return undefined
|
|
126
|
+
const end = lines.findIndex((line, index) => index > start && /^ {2}\}/.test(line))
|
|
127
|
+
if (end === -1) return undefined
|
|
128
|
+
const dropped = (key: string): boolean =>
|
|
129
|
+
names.some((name) => key === name || key.startsWith(`${name}/`))
|
|
130
|
+
const kept = lines.filter((line, index) => {
|
|
131
|
+
if (index <= start || index >= end) return true
|
|
132
|
+
const key = ENTRY_KEY.exec(line)?.[1]
|
|
133
|
+
return key === undefined || !dropped(String(JSON.parse(key)))
|
|
134
|
+
})
|
|
135
|
+
const pruned = kept.join("\n")
|
|
136
|
+
try {
|
|
137
|
+
const before = recordOf(parseJsonc(text))
|
|
138
|
+
const after = recordOf(parseJsonc(pruned))
|
|
139
|
+
const expected = Object.fromEntries(
|
|
140
|
+
Object.entries(recordOf(before.packages)).filter(([key]) => !dropped(key)),
|
|
141
|
+
)
|
|
142
|
+
const same = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b)
|
|
143
|
+
if (!same(recordOf(after.packages), expected)) return undefined
|
|
144
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
145
|
+
if (key !== "packages" && !same(before[key], after[key])) return undefined
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
return undefined
|
|
149
|
+
}
|
|
150
|
+
return pruned
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The `bun update` that makes Bun read each linked package.json again. */
|
|
154
|
+
export const linkLockUpdate = (entries: readonly StaleLinkLock[]): string =>
|
|
155
|
+
`bun update ${entries.map((entry) => entry.package).join(" ")}`
|
|
156
|
+
|
|
157
|
+
/** The advisory both `nifra doctor` and `nifra check` print. */
|
|
158
|
+
export function staleLinkLockMessage(stale: {
|
|
159
|
+
readonly lock: string
|
|
160
|
+
readonly entries: readonly StaleLinkLock[]
|
|
161
|
+
}): string {
|
|
162
|
+
const listed = stale.entries
|
|
163
|
+
.map((entry) => {
|
|
164
|
+
const shown = entry.changes.slice(0, 3).map(describeChange).join(", ")
|
|
165
|
+
const more = entry.changes.length > 3 ? ` and ${entry.changes.length - 3} more` : ""
|
|
166
|
+
return `${entry.package} (file:${entry.path}): ${shown}${more}`
|
|
167
|
+
})
|
|
168
|
+
.join("; ")
|
|
169
|
+
return (
|
|
170
|
+
`${stale.lock} records dependencies its file: packages no longer declare, and Bun never reads a linked package.json again, so it installs those versions beside the declared ones: ${listed}. ` +
|
|
171
|
+
`Run \`${linkLockUpdate(stale.entries)}\`, or \`nifra upgrade --write\` to drop the entries, then \`bun install\`.`
|
|
172
|
+
)
|
|
173
|
+
}
|
package/src/mcp-exec.ts
CHANGED
|
@@ -38,9 +38,12 @@ import {
|
|
|
38
38
|
CHILD_TIMEOUT_MS,
|
|
39
39
|
type EscalatingStop,
|
|
40
40
|
escalatingStop,
|
|
41
|
+
forwardTerminalSignals,
|
|
41
42
|
OWN_PROCESS_GROUP,
|
|
42
43
|
readBoundedStream,
|
|
43
44
|
signalProcessGroup,
|
|
45
|
+
stopGroupAndWait,
|
|
46
|
+
stopGroupOnExit,
|
|
44
47
|
timeoutMessage,
|
|
45
48
|
validateLocalPort,
|
|
46
49
|
} from "./mcp-io.ts"
|
|
@@ -292,14 +295,14 @@ export function projectTools(
|
|
|
292
295
|
{
|
|
293
296
|
name: "nifra_explain",
|
|
294
297
|
description:
|
|
295
|
-
"Turn a nifra error into a STRUCTURED diagnostic instead of eyeballing a stack trace: a stable `code`, the top frame in YOUR source, a codeframe around the offending line, and - when nifra recognises the failure - the plain-language `cause` + `fix` + docs anchor. Pass `error` (and `stack` if you have it, e.g. from nifra_run/nifra_test output or a failing build) to explain a specific failure. With no `error`, returns the running dev server's most recent error of any kind (SSR, loader, API, build, browser, hydration) with its request id - the server is found automatically; `port`/`dir` pick one when several run. nifra_errors lists them all. Returns the same JSON the dev overlay renders.",
|
|
298
|
+
"Turn a nifra error into a STRUCTURED diagnostic instead of eyeballing a stack trace: a stable `code`, the top frame in YOUR source, a codeframe around the offending line, and - when nifra recognises the failure - the plain-language `cause` + `fix` + docs anchor. Pass `error` (and `stack` if you have it, e.g. from nifra_run/nifra_test output or a failing build) to explain a specific failure. With no `error`, returns the running dev server's most recent error of any kind (SSR, loader, API, build, browser, hydration) with its request id - the server is found automatically; `port`/`dir` pick one when several run. nifra_errors lists them all. Returns the same JSON the dev overlay renders. Pass a rule code such as `NF-C007` as `error` (no `stack`) to get that `nifra check` rule's title, why it matters, its fix and its docs page.",
|
|
296
299
|
inputSchema: {
|
|
297
300
|
type: "object",
|
|
298
301
|
properties: {
|
|
299
302
|
error: {
|
|
300
303
|
type: "string",
|
|
301
304
|
description:
|
|
302
|
-
"The error message to explain (copy it from nifra_run/nifra_test output or a failing build).",
|
|
305
|
+
"The error message to explain (copy it from nifra_run/nifra_test output or a failing build), or a rule code such as NF-C007.",
|
|
303
306
|
},
|
|
304
307
|
stack: {
|
|
305
308
|
type: "string",
|
|
@@ -331,6 +334,9 @@ export function projectTools(
|
|
|
331
334
|
port?: number
|
|
332
335
|
dir?: string
|
|
333
336
|
}
|
|
337
|
+
const { explainRule, RULE_CODE_SHAPE } = await import("./rule-explain.ts")
|
|
338
|
+
if (stack === undefined && error !== undefined && RULE_CODE_SHAPE.test(error.trim()))
|
|
339
|
+
return JSON.stringify(await explainRule(error.trim()), null, 2)
|
|
334
340
|
if (error !== undefined || stack !== undefined) {
|
|
335
341
|
const { buildDiagnostic } = await import("@nifrajs/web/diagnostic")
|
|
336
342
|
const e = new Error(error ?? "")
|
|
@@ -716,6 +722,7 @@ export async function spawnChild(
|
|
|
716
722
|
stderr: "pipe",
|
|
717
723
|
detached: OWN_PROCESS_GROUP,
|
|
718
724
|
})
|
|
725
|
+
stopGroupOnExit(proc)
|
|
719
726
|
const stopper = escalatingStop((name) => signalProcessGroup(proc, name))
|
|
720
727
|
let killed = false
|
|
721
728
|
const kill = (): void => {
|
|
@@ -843,6 +850,7 @@ export class WarmWorker {
|
|
|
843
850
|
}
|
|
844
851
|
>()
|
|
845
852
|
private readonly stopper: EscalatingStop
|
|
853
|
+
private readonly releaseSignals: () => void
|
|
846
854
|
private stdoutBuffer = ""
|
|
847
855
|
private stdoutBufferBytes = 0
|
|
848
856
|
private stderrBuffer = ""
|
|
@@ -862,14 +870,20 @@ export class WarmWorker {
|
|
|
862
870
|
stdin: "pipe",
|
|
863
871
|
stdout: "pipe",
|
|
864
872
|
stderr: "pipe",
|
|
873
|
+
// Its own process group, stopped as a group: a process the app started dies with the worker.
|
|
874
|
+
detached: OWN_PROCESS_GROUP,
|
|
865
875
|
}) as PipeSubprocess
|
|
866
|
-
this.stopper = escalatingStop((name) => this.proc
|
|
876
|
+
this.stopper = escalatingStop((name) => signalProcessGroup(this.proc, name))
|
|
877
|
+
this.releaseSignals = forwardTerminalSignals(() => stopGroupAndWait(this.proc))
|
|
867
878
|
liveWarmWorkers.add(this)
|
|
868
879
|
void this.readStdout()
|
|
869
880
|
void this.readStderr()
|
|
870
881
|
void this.proc.exited.then((code) => {
|
|
871
882
|
this.closed = true
|
|
872
|
-
this.
|
|
883
|
+
this.releaseSignals()
|
|
884
|
+
// The worker is gone but the group may not be: whatever it started still gets SIGTERM, then
|
|
885
|
+
// SIGKILL after the grace period.
|
|
886
|
+
this.stopper.stop()
|
|
873
887
|
liveWarmWorkers.delete(this)
|
|
874
888
|
const err = new Error(
|
|
875
889
|
`warm ${this.label} worker exited (${code})${this.stderrBuffer ? `:\n${this.stderrBuffer}` : ""}`,
|
package/src/mcp-http.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { docsTools } from "./mcp-docs-tools.ts"
|
|
|
29
29
|
export type { TypeEntry } from "./types-search.ts"
|
|
30
30
|
|
|
31
31
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
32
|
-
const VERSION = "5.
|
|
32
|
+
const VERSION = "5.3.0"
|
|
33
33
|
const SERVER_INFO = { name: "nifra-docs", version: VERSION }
|
|
34
34
|
// Derive the GET/health tool list from the tools actually served, so the line can never drift from them.
|
|
35
35
|
const docsHealth = (tools: McpTool[]): string =>
|
package/src/mcp-io.ts
CHANGED
|
@@ -69,25 +69,85 @@ export function escalatingStop(
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Once a child spawned with `detached: OWN_PROCESS_GROUP` exits, stop what is left of its group:
|
|
74
|
+
* SIGTERM, then SIGKILL after the grace period. A process the project's code started (a dev proxy, a
|
|
75
|
+
* watcher, an embedded database) outlives the child otherwise, and one that inherited the child's
|
|
76
|
+
* stdout or stderr keeps the caller's read, and the call, open until its deadline.
|
|
77
|
+
*/
|
|
78
|
+
export function stopGroupOnExit(proc: {
|
|
79
|
+
readonly pid: number
|
|
80
|
+
readonly exited: Promise<unknown>
|
|
81
|
+
kill(signal?: NodeJS.Signals): void
|
|
82
|
+
}): void {
|
|
83
|
+
if (!OWN_PROCESS_GROUP) return
|
|
84
|
+
void proc.exited.then(() => escalatingStop((name) => signalProcessGroup(proc, name)).stop())
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"] as const
|
|
73
88
|
|
|
89
|
+
/**
|
|
90
|
+
* SIGTERM to a child's group, then wait for the whole group to exit, SIGKILL whatever is left once
|
|
91
|
+
* `graceMs` passes. Resolves when the group is gone or killed.
|
|
92
|
+
*/
|
|
93
|
+
export async function stopGroupAndWait(
|
|
94
|
+
proc: {
|
|
95
|
+
readonly pid: number
|
|
96
|
+
readonly exited: Promise<unknown>
|
|
97
|
+
kill(signal?: NodeJS.Signals): void
|
|
98
|
+
},
|
|
99
|
+
graceMs: number = KILL_GRACE_MS,
|
|
100
|
+
): Promise<void> {
|
|
101
|
+
const deadline = Date.now() + graceMs
|
|
102
|
+
signalProcessGroup(proc, "SIGTERM")
|
|
103
|
+
await Promise.race([proc.exited, Bun.sleep(graceMs)])
|
|
104
|
+
// The leader is reaped once `exited` settles; a member that survived it keeps the group alive.
|
|
105
|
+
while (OWN_PROCESS_GROUP && Date.now() < deadline && groupAlive(proc.pid)) await Bun.sleep(25)
|
|
106
|
+
signalProcessGroup(proc, "SIGKILL")
|
|
107
|
+
// Reap the leader before this process takes the signal: a killed child it never waited for stays in
|
|
108
|
+
// the process table until its new parent gets to it.
|
|
109
|
+
await Promise.race([proc.exited, Bun.sleep(graceMs)])
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function groupAlive(pid: number): boolean {
|
|
113
|
+
try {
|
|
114
|
+
process.kill(-pid, 0)
|
|
115
|
+
return true
|
|
116
|
+
} catch {
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Every registered stop runs on one signal, together, and the signal is raised again only once all
|
|
122
|
+
// of them have finished: re-raising at once ended this process before a child that catches SIGTERM
|
|
123
|
+
// could be sent SIGKILL.
|
|
124
|
+
const terminalStops = new Set<{ readonly stop: () => void | Promise<void> }>()
|
|
125
|
+
|
|
126
|
+
function onTerminalSignal(signal: NodeJS.Signals): void {
|
|
127
|
+
const stops = [...terminalStops]
|
|
128
|
+
terminalStops.clear()
|
|
129
|
+
// A second Ctrl+C while the children stop ends this process at once.
|
|
130
|
+
for (const name of FORWARDED_SIGNALS) process.off(name, onTerminalSignal)
|
|
131
|
+
void Promise.allSettled(stops.map(async ({ stop }) => stop())).then(() =>
|
|
132
|
+
process.kill(process.pid, signal),
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
74
136
|
/**
|
|
75
137
|
* A child in its own group no longer gets the Ctrl+C the terminal sends its parent: on SIGINT,
|
|
76
|
-
* SIGTERM or SIGHUP run `stop
|
|
77
|
-
*
|
|
138
|
+
* SIGTERM or SIGHUP run `stop` (with every other registered one), wait for what it returns, then let
|
|
139
|
+
* this process take the signal as it would have. Returns the function that unregisters `stop`.
|
|
78
140
|
*/
|
|
79
|
-
export function forwardTerminalSignals(stop: () => void): () => void {
|
|
141
|
+
export function forwardTerminalSignals(stop: () => void | Promise<void>): () => void {
|
|
80
142
|
if (!OWN_PROCESS_GROUP) return () => {}
|
|
81
|
-
|
|
82
|
-
for (const name of FORWARDED_SIGNALS) process.
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
process.
|
|
143
|
+
if (terminalStops.size === 0)
|
|
144
|
+
for (const name of FORWARDED_SIGNALS) process.on(name, onTerminalSignal)
|
|
145
|
+
const entry = { stop }
|
|
146
|
+
terminalStops.add(entry)
|
|
147
|
+
return () => {
|
|
148
|
+
if (!terminalStops.delete(entry) || terminalStops.size > 0) return
|
|
149
|
+
for (const name of FORWARDED_SIGNALS) process.off(name, onTerminalSignal)
|
|
88
150
|
}
|
|
89
|
-
for (const name of FORWARDED_SIGNALS) process.on(name, forward)
|
|
90
|
-
return remove
|
|
91
151
|
}
|
|
92
152
|
|
|
93
153
|
/** Accept only a concrete TCP port. Port 0 (bind-any-free-port) is not a valid read target. */
|
package/src/mcp-isolate.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
readBoundedLines,
|
|
20
20
|
readBoundedStream,
|
|
21
21
|
signalProcessGroup,
|
|
22
|
+
stopGroupOnExit,
|
|
22
23
|
} from "./mcp-io.ts"
|
|
23
24
|
import type {
|
|
24
25
|
AppSurface,
|
|
@@ -134,6 +135,7 @@ export async function askProjectChild(
|
|
|
134
135
|
`cannot start a process in ${cwd}: ${error instanceof Error ? error.message : String(error)}`,
|
|
135
136
|
)
|
|
136
137
|
}
|
|
138
|
+
stopGroupOnExit(proc)
|
|
137
139
|
let stopped: "timeout" | "cancel" | undefined
|
|
138
140
|
const stop = (reason: "timeout" | "cancel"): void => {
|
|
139
141
|
if (stopped !== undefined) return
|
package/src/mcp-root.ts
CHANGED
|
@@ -156,13 +156,13 @@ const isFile = (path: string): Promise<boolean> =>
|
|
|
156
156
|
.catch(() => false)
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
|
-
*
|
|
160
|
-
* `
|
|
161
|
-
*
|
|
159
|
+
* `dir`'s package-manager workspace members, in declaration order; `null` when `dir` declares no
|
|
160
|
+
* `workspaces`. A member is a directory a pattern matches that holds a `package.json`; `node_modules`
|
|
161
|
+
* is never a member.
|
|
162
162
|
*/
|
|
163
|
-
export async function
|
|
163
|
+
export async function workspaceMemberDirs(dir: string): Promise<string[] | null> {
|
|
164
164
|
const patterns = await workspacePatterns(dir)
|
|
165
|
-
if (patterns === null) return
|
|
165
|
+
if (patterns === null) return null
|
|
166
166
|
const members = new Set<string>()
|
|
167
167
|
const budget = { directories: MAX_WORKSPACE_DIRECTORIES }
|
|
168
168
|
for (const pattern of patterns) {
|
|
@@ -171,8 +171,14 @@ export async function workspaceProjects(dir: string): Promise<string[]> {
|
|
|
171
171
|
members.add(join(dir, member))
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
return [...members]
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The nifra projects among `dir`'s workspace members, in declaration order. */
|
|
178
|
+
export async function workspaceProjects(dir: string): Promise<string[]> {
|
|
174
179
|
const projects: string[] = []
|
|
175
|
-
for (const member of
|
|
180
|
+
for (const member of (await workspaceMemberDirs(dir)) ?? [])
|
|
181
|
+
if (await isNifraProjectDir(member)) projects.push(member)
|
|
176
182
|
return projects
|
|
177
183
|
}
|
|
178
184
|
|
|
@@ -376,7 +382,7 @@ export interface ToolingDrift {
|
|
|
376
382
|
export const driftNote = (drift: ToolingDrift): string =>
|
|
377
383
|
`WARNING: this server runs nifra CLI ${drift.cli}, but the project installs ${drift.package} ${drift.project}. ` +
|
|
378
384
|
"Types, checks, and docs may describe a different version than your code builds with. " +
|
|
379
|
-
`Fix:
|
|
385
|
+
`Fix: point the project's MCP launch at the nifra it installs with \`${syncMcpCommand(drift.cli)}\` (run in the project directory), then restart the agent. ` +
|
|
380
386
|
"If this server is not launched from the project's .mcp.json, run the project's own CLI instead (`bunx --bun nifra mcp` from the project directory, or point the client at ./node_modules/.bin/nifra)."
|
|
381
387
|
|
|
382
388
|
/** Feature-level agreement. Patch drift is not reported: it never changes the surface being described. */
|
|
@@ -434,7 +440,7 @@ export async function installedNifraVersion(
|
|
|
434
440
|
return undefined
|
|
435
441
|
}
|
|
436
442
|
|
|
437
|
-
/** The command that
|
|
443
|
+
/** The command that points a project's MCP launch at the nifra it installs. Named with the running
|
|
438
444
|
* CLI's own exact version: the binary printing this is the one known to have `--sync-mcp`, and it pins
|
|
439
445
|
* to the project's version, not its own. */
|
|
440
446
|
export const syncMcpCommand = (cliVersion: string): string =>
|