@nifrajs/cli 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3211 -0
- package/README.md +10 -2
- 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 +5 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts +12 -2
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +73 -9
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +152 -49
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +7 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +8 -2
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +49 -13
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +91 -45
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +128 -59
- package/dist/cli.js.map +1 -1
- package/dist/client-module.d.ts +5 -3
- package/dist/client-module.d.ts.map +1 -1
- package/dist/client-module.js +34 -10
- package/dist/client-module.js.map +1 -1
- package/dist/command-catalog.d.ts +9 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +75 -26
- package/dist/command-catalog.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 +19 -1
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +114 -0
- 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/fix-recipes.d.ts +2 -0
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +93 -12
- package/dist/fix-recipes.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 +60 -4
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +196 -33
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/config-paths.d.ts +16 -0
- package/dist/internal/config-paths.d.ts.map +1 -0
- package/dist/internal/config-paths.js +124 -0
- package/dist/internal/config-paths.js.map +1 -0
- package/dist/internal/installed-package.d.ts +4 -0
- package/dist/internal/installed-package.d.ts.map +1 -0
- package/dist/internal/installed-package.js +17 -0
- package/dist/internal/installed-package.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts +14 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +63 -16
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +12 -1
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +117 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +5 -3
- package/dist/internal/typescript-import.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/introspect.d.ts +9 -0
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +32 -1
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +5 -8
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +9 -4
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +32 -3
- 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-context.d.ts.map +1 -1
- package/dist/mcp-context.js +6 -21
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +2 -2
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +19 -7
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +13 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +13 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +23 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-path.d.ts +2 -1
- package/dist/mcp-path.d.ts.map +1 -1
- package/dist/mcp-path.js +9 -24
- package/dist/mcp-path.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/mcp.d.ts.map +1 -1
- package/dist/mcp.js +40 -17
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +41 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1729 -236
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts +34 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +132 -21
- package/dist/output-schemas.js.map +1 -1
- package/dist/project-path.d.ts +6 -0
- package/dist/project-path.d.ts.map +1 -1
- package/dist/project-path.js +48 -14
- package/dist/project-path.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/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/release-verification.d.ts +5 -0
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +14 -0
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +7 -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 +5 -1
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +5 -1
- 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/data-guard.d.ts +6 -0
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +37 -0
- package/dist/rules/data-guard.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 +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +44 -2
- 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 +56 -3
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +412 -23
- package/dist/rules/pages.js.map +1 -1
- 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/security.d.ts +3 -2
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +42 -11
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +34 -11
- package/dist/rules/zones.js.map +1 -1
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +127 -17
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +3 -9
- package/dist/test-tool.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 +57 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +247 -19
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +7 -2
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +66 -3
- 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 +21 -3
- package/docs/llms-full.txt +1083 -168
- package/docs/types.json +535 -112
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +5 -1
- package/src/assure.ts +99 -11
- package/src/capabilities-tool.ts +188 -53
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +65 -12
- package/src/check.ts +122 -51
- package/src/cli.ts +127 -45
- package/src/client-module.ts +45 -9
- package/src/command-catalog.ts +92 -28
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +146 -1
- package/src/doctor.ts +102 -66
- package/src/fix-recipes.ts +101 -10
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +225 -44
- package/src/internal/config-paths.ts +154 -0
- package/src/internal/installed-package.ts +15 -0
- package/src/internal/project-specifiers.ts +78 -17
- package/src/internal/source-facts.ts +147 -5
- package/src/internal/typescript-import.ts +5 -3
- package/src/internal/workspace-packages.ts +218 -0
- package/src/introspect.ts +39 -1
- package/src/levels-tool.ts +7 -9
- package/src/load.ts +46 -4
- package/src/lock-links.ts +173 -0
- package/src/mcp-context.ts +5 -18
- package/src/mcp-delegate.ts +22 -10
- package/src/mcp-exec.ts +14 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +33 -0
- package/src/mcp-path.ts +8 -22
- package/src/mcp-root.ts +14 -8
- package/src/mcp.ts +48 -19
- package/src/migrate-layout.ts +1968 -245
- package/src/output-schemas.ts +179 -23
- package/src/project-path.ts +44 -13
- 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/index.ts +7 -0
- package/src/release-verification.ts +20 -0
- package/src/review.ts +7 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +5 -1
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/data-guard.ts +40 -0
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +46 -2
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +486 -25
- package/src/rules/routes.ts +4 -3
- package/src/rules/security.ts +49 -11
- package/src/rules/zones.ts +33 -9
- package/src/stylex-migrate.ts +117 -17
- package/src/test-tool.ts +3 -9
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +312 -19
- package/src/verification-plan.ts +15 -2
- package/src/version-drift.ts +68 -2
- package/src/web-app-options.ts +9 -1
package/src/doctor.ts
CHANGED
|
@@ -39,6 +39,12 @@ import {
|
|
|
39
39
|
import { collectStaleMcpPins, type StaleMcpPin } from "./init-agents.ts"
|
|
40
40
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
41
41
|
import { createSpecifierResolver } from "./internal/project-specifiers.ts"
|
|
42
|
+
import {
|
|
43
|
+
bunLockDir,
|
|
44
|
+
type StaleLinkLock,
|
|
45
|
+
staleLinkLockMessage,
|
|
46
|
+
staleLinkLocks,
|
|
47
|
+
} from "./lock-links.ts"
|
|
42
48
|
import { detectToolingDrift, syncMcpCommand, type ToolingDrift } from "./mcp-root.ts"
|
|
43
49
|
import { collectPipelineReport, type PipelineReport } from "./pipeline-report.ts"
|
|
44
50
|
import { type ResolvedTarget, resolveTarget } from "./port.ts"
|
|
@@ -203,7 +209,18 @@ export interface DoctorResult {
|
|
|
203
209
|
* the agent's server answers for a release the code no longer builds with. Advisory (never folded
|
|
204
210
|
* into `ok`). Present only when at least one file is stale. Computed by {@link collectStaleMcpPins}.
|
|
205
211
|
*/
|
|
206
|
-
readonly staleMcpPins?: {
|
|
212
|
+
readonly staleMcpPins?: {
|
|
213
|
+
/** The installed version a pin moves to, or `null` when the project declares `@nifrajs/cli` and
|
|
214
|
+
* the launch should drop its pin. */
|
|
215
|
+
readonly target: string | null
|
|
216
|
+
readonly files: readonly StaleMcpPin[]
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* `file:` entries of the project's bun.lock whose recorded dependencies the linked package.json no
|
|
220
|
+
* longer declares: Bun never refreshes them, so it installs a second copy under the linked package.
|
|
221
|
+
* Advisory (never folded into `ok`). `lock` is the lockfile, relative to the project.
|
|
222
|
+
*/
|
|
223
|
+
readonly staleLinkLocks?: { readonly lock: string; readonly entries: readonly StaleLinkLock[] }
|
|
207
224
|
/** Static production-readiness evidence for the selected deploy target. */
|
|
208
225
|
readonly readiness?: DoctorReadiness
|
|
209
226
|
/** The explicit source boundary used by the dependency scan. */
|
|
@@ -842,6 +859,8 @@ export async function collectDoctorResult(
|
|
|
842
859
|
opts.cliVersion !== undefined ? await detectToolingDrift(cwd, opts.cliVersion) : undefined
|
|
843
860
|
const staleMcpPins = await collectStaleMcpPins(cwd).catch(() => undefined)
|
|
844
861
|
const versionDrift = collectVersionDrift(cwd, opts.cliVersion)
|
|
862
|
+
const lockDir = bunLockDir(cwd)
|
|
863
|
+
const linkLocks = lockDir === undefined ? [] : staleLinkLocks(lockDir)
|
|
845
864
|
const handBuilt = handBuiltManifests(cwd, manifestLists)
|
|
846
865
|
// `staleDists`, `toolingDrift` and `staleMcpPins` are advisory (see DoctorResult): they never fail `ok`.
|
|
847
866
|
return {
|
|
@@ -863,6 +882,14 @@ export async function collectDoctorResult(
|
|
|
863
882
|
...(versionDrift !== undefined ? { versionDrift } : {}),
|
|
864
883
|
...(handBuilt.length > 0 ? { handBuiltManifests: handBuilt } : {}),
|
|
865
884
|
...(staleMcpPins !== undefined && staleMcpPins.files.length > 0 ? { staleMcpPins } : {}),
|
|
885
|
+
...(lockDir !== undefined && linkLocks.length > 0
|
|
886
|
+
? {
|
|
887
|
+
staleLinkLocks: {
|
|
888
|
+
lock: relative(cwd, join(lockDir, "bun.lock")).split(sep).join("/"),
|
|
889
|
+
entries: linkLocks,
|
|
890
|
+
},
|
|
891
|
+
}
|
|
892
|
+
: {}),
|
|
866
893
|
...(pipeline.ran ? { pipeline } : {}),
|
|
867
894
|
}
|
|
868
895
|
}
|
|
@@ -956,133 +983,142 @@ export async function runDoctor(
|
|
|
956
983
|
const result = opts.autoFix
|
|
957
984
|
? await applyDoctorAutoFix(cwd, opts)
|
|
958
985
|
: await collectDoctorResult(cwd, opts)
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
986
|
+
console.log(
|
|
987
|
+
opts.json ? JSON.stringify(result, null, 2) : doctorReport(result, opts.cliVersion).join("\n"),
|
|
988
|
+
)
|
|
989
|
+
return result.ok
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/** The human report of a doctor run, one printed line per entry. */
|
|
993
|
+
export function doctorReport(result: DoctorResult, cliVersion?: string): string[] {
|
|
994
|
+
const lines: string[] = []
|
|
995
|
+
lines.push("nifra doctor\n")
|
|
964
996
|
if (!result.ran) {
|
|
965
|
-
|
|
966
|
-
return
|
|
997
|
+
lines.push("• no package.json at this directory - nothing to check")
|
|
998
|
+
return lines
|
|
967
999
|
}
|
|
968
1000
|
if (result.fixed && result.fixed.length > 0) {
|
|
969
|
-
|
|
1001
|
+
lines.push("✓ updated package.json dependencies:")
|
|
970
1002
|
for (const f of result.fixed) {
|
|
971
|
-
|
|
1003
|
+
lines.push(` ${f.package}@${f.version} (${f.source})`)
|
|
972
1004
|
}
|
|
973
|
-
|
|
1005
|
+
lines.push("")
|
|
974
1006
|
}
|
|
975
1007
|
if (result.skippedFixes && result.skippedFixes.length > 0) {
|
|
976
|
-
|
|
1008
|
+
lines.push("• not auto-fixed:")
|
|
977
1009
|
for (const f of result.skippedFixes) {
|
|
978
|
-
|
|
1010
|
+
lines.push(` ${f.package} - ${f.reason}; run \`${f.command.join(" ")}\``)
|
|
979
1011
|
}
|
|
980
|
-
|
|
1012
|
+
lines.push("")
|
|
981
1013
|
}
|
|
982
1014
|
// Printed before the findings and regardless of ok: which bundler owns this app is the frame the
|
|
983
1015
|
// rest of the report is read in, not a footnote to it.
|
|
984
1016
|
if (result.pipeline !== undefined) {
|
|
985
1017
|
const p = result.pipeline
|
|
986
|
-
|
|
1018
|
+
lines.push(
|
|
987
1019
|
p.pipeline === "unknown"
|
|
988
1020
|
? `• bundler: could not be read from ${p.configFile} - ${p.reason}\n`
|
|
989
1021
|
: `• bundler: ${p.pipeline} (${p.reason})\n`,
|
|
990
1022
|
)
|
|
991
1023
|
for (const f of p.findings) {
|
|
992
|
-
|
|
993
|
-
|
|
1024
|
+
lines.push(`${f.severity === "error" ? "✗" : "⚠"} ${f.file}:${f.line ?? 0} ${f.message}`)
|
|
1025
|
+
lines.push(` fix: ${f.fix}\n`)
|
|
994
1026
|
}
|
|
995
1027
|
}
|
|
996
1028
|
if (result.scanScope !== undefined) {
|
|
997
|
-
|
|
1029
|
+
lines.push(
|
|
998
1030
|
`• dependency scan scope: ${result.scanScope.kind} (${result.scanScope.includeTests ? "includes tests" : "production package source only"})`,
|
|
999
1031
|
)
|
|
1000
1032
|
if (result.scanScope.excluded.length > 0)
|
|
1001
|
-
|
|
1002
|
-
|
|
1033
|
+
lines.push(` excluded: ${result.scanScope.excluded.join(", ")}`)
|
|
1034
|
+
lines.push("")
|
|
1003
1035
|
}
|
|
1004
1036
|
// Advisory, printed regardless of ok: a stale linked dist doesn't fail doctor, but silently eating
|
|
1005
1037
|
// it costs an hour of misdiagnosis when the dev server 500s inside the package.
|
|
1006
1038
|
if (result.staleDists.length > 0) {
|
|
1007
|
-
|
|
1039
|
+
lines.push(
|
|
1008
1040
|
`⚠ ${result.staleDists.length} workspace-linked package(s) with a build artifact older than their source (Bun reads src, Vite SSR/node consumers read dist):\n`,
|
|
1009
1041
|
)
|
|
1010
1042
|
for (const f of result.staleDists) {
|
|
1011
|
-
|
|
1043
|
+
lines.push(
|
|
1012
1044
|
f.missing
|
|
1013
1045
|
? ` ${f.package} - ${f.distFile} was never built`
|
|
1014
1046
|
: ` ${f.package} - ${f.distFile} is ${f.behindSeconds}s behind ${f.sourceFile}`,
|
|
1015
1047
|
)
|
|
1016
|
-
|
|
1048
|
+
lines.push(` rebuild ${f.package}`)
|
|
1017
1049
|
}
|
|
1018
|
-
|
|
1050
|
+
lines.push("")
|
|
1019
1051
|
}
|
|
1020
1052
|
if (result.readiness !== undefined) {
|
|
1021
1053
|
const readiness = result.readiness
|
|
1022
|
-
|
|
1054
|
+
lines.push(
|
|
1023
1055
|
`production readiness (${readiness.target}${readiness.targetSource === null ? "" : `, detected from ${readiness.targetSource}`}):\n`,
|
|
1024
1056
|
)
|
|
1025
1057
|
for (const item of readiness.items) {
|
|
1026
1058
|
const marker =
|
|
1027
1059
|
item.status === "configured" ? "✓" : item.status === "not-applicable" ? "-" : "✗"
|
|
1028
1060
|
const evidence = item.evidence === undefined ? "" : ` (${item.evidence})`
|
|
1029
|
-
|
|
1061
|
+
lines.push(` ${marker} ${item.label}: ${item.status}${evidence}`)
|
|
1030
1062
|
}
|
|
1031
1063
|
if (readiness.strict && !readiness.ok) {
|
|
1032
|
-
|
|
1064
|
+
lines.push("\n --strict: every applicable readiness rule must be configured")
|
|
1033
1065
|
}
|
|
1034
|
-
|
|
1066
|
+
lines.push("")
|
|
1035
1067
|
}
|
|
1036
1068
|
// Advisory, printed regardless of ok: the binary answering is a different feature version than the
|
|
1037
1069
|
// one the project builds with, so its types/checks/docs describe a surface the code does not have.
|
|
1038
1070
|
if (result.toolingDrift !== undefined) {
|
|
1039
1071
|
const drift = result.toolingDrift
|
|
1040
|
-
|
|
1072
|
+
lines.push(
|
|
1041
1073
|
`⚠ this CLI is nifra ${drift.cli}, but the project installs ${drift.package} ${drift.project} - ` +
|
|
1042
1074
|
"its types, checks, and docs may describe a different version than your code builds with.",
|
|
1043
1075
|
)
|
|
1044
|
-
|
|
1045
|
-
` fix: \`${syncMcpCommand(drift.cli)}\`
|
|
1076
|
+
lines.push(
|
|
1077
|
+
` fix: \`${syncMcpCommand(drift.cli)}\` points the project's MCP launch at the nifra it installs; ` +
|
|
1046
1078
|
"for the CLI itself, run the project's own (`bunx --bun nifra doctor` from the project directory, " +
|
|
1047
1079
|
"or ./node_modules/.bin/nifra)\n",
|
|
1048
1080
|
)
|
|
1049
1081
|
}
|
|
1050
1082
|
if (result.versionDrift !== undefined) {
|
|
1051
|
-
|
|
1083
|
+
lines.push(`⚠ ${versionDriftMessage(result.versionDrift)}\n`)
|
|
1084
|
+
}
|
|
1085
|
+
if (result.staleLinkLocks !== undefined) {
|
|
1086
|
+
lines.push(`⚠ ${staleLinkLockMessage(result.staleLinkLocks)}\n`)
|
|
1052
1087
|
}
|
|
1053
1088
|
for (const finding of result.handBuiltManifests ?? []) {
|
|
1054
|
-
|
|
1089
|
+
lines.push(`⚠ ${handBuiltManifestMessage(finding)}\n`)
|
|
1055
1090
|
}
|
|
1056
1091
|
// Advisory: the agent's MCP server is launched from these pins, so a stale one answers for an old
|
|
1057
1092
|
// release even when the CLI running doctor matches the project.
|
|
1058
1093
|
if (result.staleMcpPins !== undefined) {
|
|
1059
1094
|
const { target, files } = result.staleMcpPins
|
|
1060
|
-
|
|
1061
|
-
|
|
1095
|
+
lines.push(
|
|
1096
|
+
target === null
|
|
1097
|
+
? "⚠ the MCP launch pins a nifra release while the project installs its own CLI - an agent's nifra server answers for the pinned release:"
|
|
1098
|
+
: `⚠ the MCP launch pins a nifra other than the project's ${target} - an agent's nifra server answers for that release:`,
|
|
1062
1099
|
)
|
|
1063
|
-
for (const file of files)
|
|
1064
|
-
console.log(` ${file.path}: @nifrajs/cli@${file.pinned.join(", ")}`)
|
|
1100
|
+
for (const file of files) lines.push(` ${file.path}: @nifrajs/cli@${file.pinned.join(", ")}`)
|
|
1065
1101
|
const command =
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1102
|
+
cliVersion !== undefined ? syncMcpCommand(cliVersion) : "nifra init-agents --sync-mcp"
|
|
1103
|
+
lines.push(
|
|
1104
|
+
target === null
|
|
1105
|
+
? ` fix: \`${command}\` drops the pin so the launch runs the installed CLI from then on, then restart the agent\n`
|
|
1106
|
+
: ` fix: \`${command}\` rewrites only the pinned version, then restart the agent\n`,
|
|
1071
1107
|
)
|
|
1072
1108
|
}
|
|
1073
1109
|
if (result.ok) {
|
|
1074
|
-
|
|
1110
|
+
lines.push(
|
|
1075
1111
|
"✓ every imported package is declared and identity-sensitive installs are deduplicated",
|
|
1076
1112
|
)
|
|
1077
|
-
if (result.identityBasis !== undefined)
|
|
1113
|
+
if (result.identityBasis !== undefined) lines.push(` identity scan: ${result.identityBasis}`)
|
|
1078
1114
|
// A partial scan that prints a bare ✓ is a lie by omission - the packages past the cap were never
|
|
1079
1115
|
// looked at, and the reader has no way to know that from the tick alone.
|
|
1080
1116
|
if (result.identityScanTruncated === true) {
|
|
1081
|
-
|
|
1117
|
+
lines.push(
|
|
1082
1118
|
" ! the identity scan was truncated, so this is not a clean bill for the whole workspace",
|
|
1083
1119
|
)
|
|
1084
1120
|
}
|
|
1085
|
-
return
|
|
1121
|
+
return lines
|
|
1086
1122
|
}
|
|
1087
1123
|
// Group by package so the fix ("add X to dependencies") is stated once with its import sites.
|
|
1088
1124
|
const byPkg = new Map<string, DoctorFinding[]>()
|
|
@@ -1092,52 +1128,52 @@ export async function runDoctor(
|
|
|
1092
1128
|
byPkg.set(f.package, list)
|
|
1093
1129
|
}
|
|
1094
1130
|
if (byPkg.size > 0) {
|
|
1095
|
-
|
|
1131
|
+
lines.push(`✗ ${byPkg.size} package(s) imported but not declared in package.json:\n`)
|
|
1096
1132
|
for (const [pkg, sites] of [...byPkg.entries()].sort()) {
|
|
1097
|
-
|
|
1098
|
-
for (const s of sites)
|
|
1133
|
+
lines.push(` ${pkg} - add to dependencies (\`bun add ${pkg}\`)`)
|
|
1134
|
+
for (const s of sites) lines.push(` ${s.file}:${s.line}`)
|
|
1099
1135
|
}
|
|
1100
1136
|
}
|
|
1101
1137
|
if (result.duplicateInstalls.length > 0) {
|
|
1102
|
-
|
|
1138
|
+
lines.push(
|
|
1103
1139
|
`${byPkg.size > 0 ? "\n" : ""}✗ identity-sensitive packages resolve to multiple physical copies:\n`,
|
|
1104
1140
|
)
|
|
1105
|
-
if (result.identityBasis !== undefined)
|
|
1141
|
+
if (result.identityBasis !== undefined) lines.push(` scan: ${result.identityBasis}\n`)
|
|
1106
1142
|
for (const finding of result.duplicateInstalls) {
|
|
1107
|
-
|
|
1108
|
-
|
|
1143
|
+
lines.push(` ${finding.package} [${finding.cause}]`)
|
|
1144
|
+
lines.push(` versions: ${finding.versions.join(", ")}`)
|
|
1109
1145
|
for (const copy of finding.copies) {
|
|
1110
|
-
|
|
1146
|
+
lines.push(` ${copy.version} at ${copy.path} ← ${copy.importers.join(", ")}`)
|
|
1111
1147
|
}
|
|
1112
|
-
|
|
1148
|
+
lines.push(` ${finding.explanation}`)
|
|
1113
1149
|
// A planted symlink is the cause no reinstall here can see, so it is named before the fix.
|
|
1114
|
-
if (finding.provenance !== undefined)
|
|
1150
|
+
if (finding.provenance !== undefined) lines.push(` links: ${finding.provenance}`)
|
|
1115
1151
|
// The shape of the split decides which fix can work, so it is printed above the fix itself.
|
|
1116
|
-
if (finding.topology !== undefined)
|
|
1152
|
+
if (finding.topology !== undefined) lines.push(` topology: ${finding.topology}`)
|
|
1117
1153
|
// Why a copy this directory never imports still counts. Without it, a workspace-wide answer
|
|
1118
1154
|
// read from inside one app looks like the tool checking the wrong project.
|
|
1119
|
-
if (finding.scope !== undefined)
|
|
1120
|
-
|
|
1155
|
+
if (finding.scope !== undefined) lines.push(` scope: ${finding.scope}`)
|
|
1156
|
+
lines.push(` fix: ${finding.remediation}`)
|
|
1121
1157
|
}
|
|
1122
1158
|
}
|
|
1123
1159
|
// Not a failure and not silence: the copies are real, and whoever reads this report needs to know
|
|
1124
1160
|
// the graph is held together by a declaration rather than by the install.
|
|
1125
1161
|
if (result.deduplicatedInstalls !== undefined && result.deduplicatedInstalls.length > 0) {
|
|
1126
|
-
|
|
1162
|
+
lines.push("\n• identity-sensitive packages deduplicated by declaration:\n")
|
|
1127
1163
|
for (const finding of result.deduplicatedInstalls) {
|
|
1128
|
-
|
|
1164
|
+
lines.push(` ${finding.package} @ ${finding.versions.join(", ")}`)
|
|
1129
1165
|
for (const copy of finding.copies) {
|
|
1130
|
-
|
|
1166
|
+
lines.push(` ${copy.path} ← ${copy.importers.join(", ")}`)
|
|
1131
1167
|
}
|
|
1132
|
-
|
|
1168
|
+
lines.push(` ${finding.remediation}`)
|
|
1133
1169
|
}
|
|
1134
1170
|
}
|
|
1135
1171
|
if (result.readiness?.strict === true && result.readiness.ok === false) {
|
|
1136
|
-
|
|
1172
|
+
lines.push("\n✗ production readiness is incomplete under --strict")
|
|
1137
1173
|
}
|
|
1138
1174
|
if (byPkg.size > 0)
|
|
1139
|
-
|
|
1175
|
+
lines.push(
|
|
1140
1176
|
"\nThese resolve at Bun runtime via hoisting/workspace but break `tsc` and a standalone install.",
|
|
1141
1177
|
)
|
|
1142
|
-
return
|
|
1178
|
+
return lines
|
|
1143
1179
|
}
|
package/src/fix-recipes.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { resolveWorkspaceLinkedPackage } from "./workspace-link.ts"
|
|
|
7
7
|
export interface FixRecipe {
|
|
8
8
|
readonly id: string
|
|
9
9
|
readonly description: string
|
|
10
|
+
/** Run only by `nifra fix --code <code>`: the change it makes is a decision a person reviews first. */
|
|
11
|
+
readonly onlyWhenNamed?: true
|
|
10
12
|
apply(root: string, diagnostic: Diagnostic): Promise<readonly string[]>
|
|
11
13
|
readonly verify: string
|
|
12
14
|
}
|
|
@@ -84,22 +86,39 @@ registerFixRecipe({
|
|
|
84
86
|
description:
|
|
85
87
|
"Serve the backend over HTTP at /api by exporting apiPrefix from the framework config.",
|
|
86
88
|
verify: "nifra check",
|
|
87
|
-
async apply(root
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
async apply(root) {
|
|
90
|
+
const { CONFIG_FILE, FRAMEWORK_FILE } = await import("./app-files.ts")
|
|
91
|
+
const { apiPrefixFix } = await import("./rules/pages.ts")
|
|
92
|
+
const frameworkPath = await resolveInsideProject(root, FRAMEWORK_FILE)
|
|
93
|
+
const configPath = await resolveInsideProject(root, CONFIG_FILE)
|
|
94
|
+
if (frameworkPath === undefined || configPath === undefined) return []
|
|
95
|
+
const source = async (path: string): Promise<string | undefined> => {
|
|
96
|
+
const file = Bun.file(path)
|
|
97
|
+
return (await file.exists()) ? await file.text() : undefined
|
|
98
|
+
}
|
|
99
|
+
const next = apiPrefixFix({
|
|
100
|
+
framework: await source(frameworkPath),
|
|
101
|
+
config: await source(configPath),
|
|
102
|
+
})
|
|
103
|
+
const edits: readonly (readonly [string, string, string | undefined])[] = [
|
|
104
|
+
[FRAMEWORK_FILE, frameworkPath, next.framework],
|
|
105
|
+
[CONFIG_FILE, configPath, next.config],
|
|
106
|
+
]
|
|
107
|
+
const changed: string[] = []
|
|
108
|
+
for (const [file, path, text] of edits) {
|
|
109
|
+
if (text === undefined) continue
|
|
110
|
+
await writeFile(path, text, "utf8")
|
|
111
|
+
changed.push(file)
|
|
112
|
+
}
|
|
113
|
+
return changed
|
|
97
114
|
},
|
|
98
115
|
})
|
|
99
116
|
|
|
100
117
|
registerFixRecipe({
|
|
101
118
|
id: "contracts.snapshot",
|
|
102
119
|
description: "Refresh the opt-in contract lock after reviewing an intentional route change.",
|
|
120
|
+
// Rewriting the lock accepts whatever the routes changed to, which is the review the lock exists for.
|
|
121
|
+
onlyWhenNamed: true,
|
|
103
122
|
verify: "nifra contracts check",
|
|
104
123
|
async apply(root) {
|
|
105
124
|
const { snapshotContracts } = await import("./contracts.ts")
|
|
@@ -158,6 +177,78 @@ registerFixRecipe({
|
|
|
158
177
|
},
|
|
159
178
|
})
|
|
160
179
|
|
|
180
|
+
registerFixRecipe({
|
|
181
|
+
id: "route.split",
|
|
182
|
+
description:
|
|
183
|
+
"Move a route frontend file's server-only exports, and the code only they use, into its x.backend.ts.",
|
|
184
|
+
verify: "nifra check",
|
|
185
|
+
async apply(root, diagnostic) {
|
|
186
|
+
const file = diagnostic.file
|
|
187
|
+
if (file === undefined || (await resolveInsideProject(root, file)) === undefined) return []
|
|
188
|
+
const { splitRouteFile } = await import("./migrate-layout.ts")
|
|
189
|
+
return splitRouteFile(root, file)
|
|
190
|
+
},
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
registerFixRecipe({
|
|
194
|
+
id: "layout.migrate",
|
|
195
|
+
description:
|
|
196
|
+
"Move the app onto the frontend/backend layout, as `nifra migrate layout --write` does.",
|
|
197
|
+
onlyWhenNamed: true,
|
|
198
|
+
verify: "nifra check --lints-only",
|
|
199
|
+
async apply(root) {
|
|
200
|
+
const { migrateLayout } = await import("./migrate-layout.ts")
|
|
201
|
+
const result = await migrateLayout(root, { write: true })
|
|
202
|
+
return [
|
|
203
|
+
...new Set([
|
|
204
|
+
...result.moves.map((move) => move.to),
|
|
205
|
+
...result.splits.flatMap((split) => [split.file, split.backend]),
|
|
206
|
+
...result.rewritten,
|
|
207
|
+
...result.tooling.map((edit) => edit.file),
|
|
208
|
+
]),
|
|
209
|
+
].sort()
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
registerFixRecipe({
|
|
214
|
+
id: "schemas.draft",
|
|
215
|
+
description:
|
|
216
|
+
"Draft the missing loader or action output schema from the function's return type, for the author to review.",
|
|
217
|
+
verify: "nifra check --lints-only",
|
|
218
|
+
async apply(root, diagnostic) {
|
|
219
|
+
const file = diagnostic.file
|
|
220
|
+
if (file === undefined) return []
|
|
221
|
+
const path = await resolveInsideProject(root, file)
|
|
222
|
+
if (path === undefined) return []
|
|
223
|
+
const schema = diagnostic.evidence
|
|
224
|
+
?.find((line) => line.startsWith("missing: "))
|
|
225
|
+
?.slice("missing: ".length)
|
|
226
|
+
if (schema !== "loaderOutput" && schema !== "actionOutput") return []
|
|
227
|
+
const { planOutputSchemas } = await import("./output-schemas.ts")
|
|
228
|
+
const source = await readFile(path, "utf8")
|
|
229
|
+
// Only this declaration: other schemas in the file, generated or hand-written, stay as they are.
|
|
230
|
+
const plan = await planOutputSchemas(
|
|
231
|
+
root,
|
|
232
|
+
[file],
|
|
233
|
+
(read) => (read === file ? source : undefined),
|
|
234
|
+
{
|
|
235
|
+
draft: (at, name) => at === file && name === schema,
|
|
236
|
+
},
|
|
237
|
+
)
|
|
238
|
+
const blocked =
|
|
239
|
+
plan.warnings.length > 0
|
|
240
|
+
? plan.warnings.join("; ")
|
|
241
|
+
: plan.entries.find((entry) => entry.schema === schema && entry.reason !== undefined)
|
|
242
|
+
?.reason
|
|
243
|
+
if (blocked !== undefined)
|
|
244
|
+
throw new Error(`[nifra] no ${schema} was drafted in ${file}: ${blocked}`)
|
|
245
|
+
const drafted = plan.edits.get(file)
|
|
246
|
+
if (drafted === undefined) return []
|
|
247
|
+
await writeFile(path, drafted, "utf8")
|
|
248
|
+
return [file]
|
|
249
|
+
},
|
|
250
|
+
})
|
|
251
|
+
|
|
161
252
|
/**
|
|
162
253
|
* How many typecheck passes the reserved-segment codemod will run. A nested collision
|
|
163
254
|
* (`/api/delete/then`) only reveals its second site once the first is rewritten, so one pass is not
|