@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "The nifra CLI - zero-config dev/build/start for a nifra app (`nifra dev`, `nifra build`, `nifra start`).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"files": [
|
|
59
59
|
"dist",
|
|
60
60
|
"src",
|
|
61
|
-
"docs"
|
|
61
|
+
"docs",
|
|
62
|
+
"CHANGELOG.md"
|
|
62
63
|
],
|
|
63
64
|
"sideEffects": false,
|
|
64
65
|
"scripts": {
|
|
@@ -69,16 +70,16 @@
|
|
|
69
70
|
"access": "public"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
|
-
"@nifrajs/client": "5.
|
|
73
|
-
"@nifrajs/core": "5.
|
|
74
|
-
"@nifrajs/agent-review": "5.
|
|
75
|
-
"@nifrajs/i18n": "5.
|
|
76
|
-
"@nifrajs/mcp": "5.
|
|
77
|
-
"@nifrajs/mcp-db": "5.
|
|
78
|
-
"@nifrajs/runner": "5.
|
|
79
|
-
"@nifrajs/schema": "5.
|
|
80
|
-
"@nifrajs/testing": "5.
|
|
81
|
-
"@nifrajs/web": "5.
|
|
73
|
+
"@nifrajs/client": "5.2.0",
|
|
74
|
+
"@nifrajs/core": "5.2.0",
|
|
75
|
+
"@nifrajs/agent-review": "5.2.0",
|
|
76
|
+
"@nifrajs/i18n": "5.2.0",
|
|
77
|
+
"@nifrajs/mcp": "5.2.0",
|
|
78
|
+
"@nifrajs/mcp-db": "5.2.0",
|
|
79
|
+
"@nifrajs/runner": "5.2.0",
|
|
80
|
+
"@nifrajs/schema": "5.2.0",
|
|
81
|
+
"@nifrajs/testing": "5.2.0",
|
|
82
|
+
"@nifrajs/web": "5.2.0"
|
|
82
83
|
},
|
|
83
84
|
"repository": {
|
|
84
85
|
"type": "git",
|
package/src/agent-files.ts
CHANGED
|
@@ -40,14 +40,17 @@ export const MCP_SERVER_COMMAND = "bunx" as const
|
|
|
40
40
|
* (`../package.json` → the same root, since `dist/` sits beside the manifest). npm always ships a
|
|
41
41
|
* package's own `package.json`, so the read can't miss at install time.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
43
|
+
* Two launch forms. A project that declares `@nifrajs/cli` gets the unpinned
|
|
44
|
+
* `bunx @nifrajs/cli mcp` ({@link MCP_SERVER_ARGS_INSTALLED}): `bunx` runs the copy the project installs
|
|
45
|
+
* (its `node_modules`, or an ancestor's) whenever there is one, so an upgrade moves the server with it
|
|
46
|
+
* and nothing needs re-pinning. A pinned spec never does that, not even at the installed version: it
|
|
47
|
+
* always runs a registry copy. Every scaffold declares the CLI, so every scaffold is unpinned.
|
|
48
|
+
*
|
|
49
|
+
* A project that does not declare it keeps the pin ({@link MCP_SERVER_ARGS}): with no local install an
|
|
50
|
+
* unpinned spec resolves `latest` once and `bunx` reuses that cached copy on every later spawn without
|
|
51
|
+
* re-checking the registry, so the server would silently run old code. The exact version is part of the
|
|
52
|
+
* cache key, so each release fetches fresh; `nifra init-agents --sync-mcp` moves it to the installed
|
|
53
|
+
* nifra, or unpins it once the project declares the CLI.
|
|
51
54
|
*/
|
|
52
55
|
export const MCP_CLI_VERSION: string = ownVersion()
|
|
53
56
|
|
|
@@ -66,6 +69,9 @@ function ownVersion(): string {
|
|
|
66
69
|
}
|
|
67
70
|
export const MCP_SERVER_ARGS = [`@nifrajs/cli@${MCP_CLI_VERSION}`, "mcp"] as const
|
|
68
71
|
|
|
72
|
+
/** The launch args for a project that declares `@nifrajs/cli`: unpinned, so `bunx` runs its install. */
|
|
73
|
+
export const MCP_SERVER_ARGS_INSTALLED = ["@nifrajs/cli", "mcp"] as const
|
|
74
|
+
|
|
69
75
|
/** The server entry registered under the `nifra` key in both Claude Code's and Cursor's MCP config. */
|
|
70
76
|
export interface McpServerConfig {
|
|
71
77
|
readonly command: string
|
|
@@ -77,17 +83,20 @@ export interface McpConfig {
|
|
|
77
83
|
readonly mcpServers: Readonly<Record<string, McpServerConfig>>
|
|
78
84
|
}
|
|
79
85
|
|
|
80
|
-
/** The one canonical MCP config
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
86
|
+
/** The one canonical MCP config both registries serialize - the anti-drift seam. `pin` is the
|
|
87
|
+
* `@nifrajs/cli` version to pin; without one the launch follows the project's install. */
|
|
88
|
+
export function mcpConfig(pin?: string): McpConfig {
|
|
89
|
+
const args = pin === undefined ? MCP_SERVER_ARGS_INSTALLED : [`@nifrajs/cli@${pin}`, "mcp"]
|
|
90
|
+
return { mcpServers: { nifra: { command: MCP_SERVER_COMMAND, args: [...args] } } }
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
/** The config a scaffold writes: every scaffold declares the CLI, so its launch is unpinned. */
|
|
94
|
+
export const MCP_CONFIG: McpConfig = mcpConfig()
|
|
95
|
+
|
|
87
96
|
/** Serialize the canonical MCP config as the JSON written to `.mcp.json` and `.cursor/mcp.json`.
|
|
88
97
|
* Trailing newline so the file is POSIX-clean and diffs don't flag a missing EOL. */
|
|
89
|
-
export function mcpJson(): string {
|
|
90
|
-
return `${JSON.stringify(
|
|
98
|
+
export function mcpJson(pin?: string): string {
|
|
99
|
+
return `${JSON.stringify(mcpConfig(pin), null, 2)}\n`
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
const POINTER_INTRO =
|
|
@@ -118,10 +127,11 @@ export function copilotInstructions(): string {
|
|
|
118
127
|
* agents (Cursor, and anything that reads `AGENTS.md`) also learn the MCP exists and what to prefer.
|
|
119
128
|
* Mirrors the CLAUDE.md preamble's guidance without the Claude-specific `@import`.
|
|
120
129
|
*/
|
|
121
|
-
export function agentsMcpSection(): string {
|
|
130
|
+
export function agentsMcpSection(pin?: string): string {
|
|
131
|
+
const args = pin === undefined ? MCP_SERVER_ARGS_INSTALLED : [`@nifrajs/cli@${pin}`, "mcp"]
|
|
122
132
|
return `## MCP server
|
|
123
133
|
|
|
124
|
-
This project ships a **nifra MCP server** - launch it with \`${MCP_SERVER_COMMAND} ${
|
|
134
|
+
This project ships a **nifra MCP server** - launch it with \`${MCP_SERVER_COMMAND} ${args.join(" ")}\`. It's registered for
|
|
125
135
|
Claude Code in \`.mcp.json\` and for Cursor in \`.cursor/mcp.json\`; other agents can point their MCP client
|
|
126
136
|
at that command. **Prefer its tools** over writing nifra from memory - they're typechecked against this
|
|
127
137
|
project + the installed version, so they beat training-data recall:
|
package/src/assure-hydration.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { collectDoctorResult } from "./doctor.ts"
|
|
|
13
13
|
import { loadApp, resolvePlugins } from "./load.ts"
|
|
14
14
|
import {
|
|
15
15
|
CHILD_OUTPUT_MAX_BYTES,
|
|
16
|
+
escalatingStop,
|
|
16
17
|
forwardTerminalSignals,
|
|
17
18
|
joinHeadTail,
|
|
18
19
|
OWN_PROCESS_GROUP,
|
|
@@ -215,6 +216,7 @@ async function buildHydrationApp(cwd: string): Promise<BuiltHydrationApp | { ski
|
|
|
215
216
|
manifest: discoverRoutes(loaded.routesDir),
|
|
216
217
|
clientEntry: client.entry,
|
|
217
218
|
...frameworkWebAppOptions(loaded.framework, loaded.backend),
|
|
219
|
+
...(client.copyChunks === undefined ? {} : { copyChunks: client.copyChunks }),
|
|
218
220
|
}) as unknown as AppLike
|
|
219
221
|
return {
|
|
220
222
|
app: webApp,
|
|
@@ -647,10 +649,11 @@ export async function runHydrationAssurance(
|
|
|
647
649
|
detached: OWN_PROCESS_GROUP,
|
|
648
650
|
},
|
|
649
651
|
)
|
|
652
|
+
const stopper = escalatingStop((name) => signalProcessGroup(proc, name))
|
|
650
653
|
let stopped: string | undefined
|
|
651
654
|
const stop = (reason: string): void => {
|
|
652
655
|
stopped ??= reason
|
|
653
|
-
|
|
656
|
+
stopper.stop()
|
|
654
657
|
}
|
|
655
658
|
const onAbort = (): void => stop("cancelled")
|
|
656
659
|
control.signal?.addEventListener("abort", onAbort, { once: true })
|
|
@@ -684,6 +687,7 @@ export async function runHydrationAssurance(
|
|
|
684
687
|
return failed(joinHeadTail(stderr).trim() || "no result")
|
|
685
688
|
} finally {
|
|
686
689
|
clearTimeout(timer)
|
|
690
|
+
stopper.dispose()
|
|
687
691
|
control.signal?.removeEventListener("abort", onAbort)
|
|
688
692
|
releaseSignals()
|
|
689
693
|
}
|
package/src/assure.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
import { existsSync } from "node:fs"
|
|
4
4
|
import { join, resolve } from "node:path"
|
|
5
5
|
import { pathToFileURL } from "node:url"
|
|
6
|
-
import type { AssuranceConfig, AssuranceReport } from "@nifrajs/core/assurance"
|
|
6
|
+
import type { AssuranceConfig, AssuranceReport, AssuredRoute } from "@nifrajs/core/assurance"
|
|
7
7
|
import { CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
|
|
8
8
|
import type { Diagnostic } from "./diagnostics.ts"
|
|
9
|
+
import type { ProjectVerification } from "./verification.ts"
|
|
9
10
|
|
|
10
11
|
export interface AssureSink {
|
|
11
12
|
record(bundle: AssureBundle): Promise<void>
|
|
@@ -14,6 +15,7 @@ export interface AssureSink {
|
|
|
14
15
|
export interface GateResult {
|
|
15
16
|
readonly gate:
|
|
16
17
|
| "check"
|
|
18
|
+
| "assurance"
|
|
17
19
|
| "doctor"
|
|
18
20
|
| "render"
|
|
19
21
|
| "hydration"
|
|
@@ -82,7 +84,17 @@ export async function loadAssuranceConfig(
|
|
|
82
84
|
}
|
|
83
85
|
const specifier = pathToFileURL(path)
|
|
84
86
|
specifier.searchParams.set("nifra-assurance", String(Date.now()))
|
|
85
|
-
|
|
87
|
+
// Core records each route's registering module while this is set, for the capability walk. Scoped to
|
|
88
|
+
// the load: a module already imported in this process keeps what it recorded then.
|
|
89
|
+
const priorSites = process.env.NIFRA_ROUTE_SITES
|
|
90
|
+
process.env.NIFRA_ROUTE_SITES = "1"
|
|
91
|
+
let loaded: { default?: unknown }
|
|
92
|
+
try {
|
|
93
|
+
loaded = (await import(specifier.href)) as { default?: unknown }
|
|
94
|
+
} finally {
|
|
95
|
+
if (priorSites === undefined) delete process.env.NIFRA_ROUTE_SITES
|
|
96
|
+
else process.env.NIFRA_ROUTE_SITES = priorSites
|
|
97
|
+
}
|
|
86
98
|
if (!isConfig(loaded.default)) {
|
|
87
99
|
throw new Error(
|
|
88
100
|
`[nifra] ${displayPath(path)} must default-export defineAssuranceConfig({ source, policy }).`,
|
|
@@ -91,6 +103,45 @@ export async function loadAssuranceConfig(
|
|
|
91
103
|
return loaded.default
|
|
92
104
|
}
|
|
93
105
|
|
|
106
|
+
/** Why declared response/error schemas go unenforced, phrased for the server that has to change. */
|
|
107
|
+
export interface ResponseContractGaps {
|
|
108
|
+
readonly typedOnly: readonly string[]
|
|
109
|
+
readonly warnOnly: readonly string[]
|
|
110
|
+
readonly typedOnlyReason: string | undefined
|
|
111
|
+
readonly warnOnlyReason: string | undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const sample = (routes: readonly string[]): string =>
|
|
115
|
+
routes.length <= 3
|
|
116
|
+
? routes.join(", ")
|
|
117
|
+
: `${routes.slice(0, 3).join(", ")} and ${routes.length - 3} more`
|
|
118
|
+
|
|
119
|
+
export function responseContractGaps(routes: readonly AssuredRoute[]): ResponseContractGaps {
|
|
120
|
+
const key = (route: AssuredRoute): string => `${route.method} ${route.path}`
|
|
121
|
+
const typedOnly = routes.filter((route) => route.responseContract === "unchecked").map(key)
|
|
122
|
+
const warnOnly = routes.filter((route) => route.responseContract === "warn").map(key)
|
|
123
|
+
const covered = routes.filter(
|
|
124
|
+
(route) => route.responseContract === "enforce" || route.responseContract === "warn",
|
|
125
|
+
).length
|
|
126
|
+
// A plugin that covers some routes is installed - just not where these were registered, which is
|
|
127
|
+
// the case "install responseContract" advice used to send people in circles over.
|
|
128
|
+
const typedOnlyReason =
|
|
129
|
+
typedOnly.length === 0
|
|
130
|
+
? undefined
|
|
131
|
+
: covered > 0
|
|
132
|
+
? `${typedOnly.length} declared route(s) are typed-only (${sample(typedOnly)}) although responseContract() covers ${covered} other(s): it covers routes registered after it on the same server, and routes merge()d into that server after it. Install responseContract("enforce") on the server that registers these, before them.`
|
|
133
|
+
: `${typedOnly.length} declared route(s) are typed-only (${sample(typedOnly)}); install responseContract("enforce") on the server that registers them, before them - a parent's also covers servers merge()d into it afterwards.`
|
|
134
|
+
const warnOnlyReason =
|
|
135
|
+
warnOnly.length === 0
|
|
136
|
+
? undefined
|
|
137
|
+
: `${warnOnly.length} declared route(s) are warn-only and still send the original payload (${sample(warnOnly)}); switch responseContract("warn") to "enforce".`
|
|
138
|
+
return { typedOnly, warnOnly, typedOnlyReason, warnOnlyReason }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The policy line that turns an unenforced contract into a route-assurance failure. */
|
|
142
|
+
export const RESPONSE_CONTRACT_BASELINE_HINT =
|
|
143
|
+
'to fail route assurance on these, add baseline: [{ name: "response-contract", match: { hasResponse: true }, require: ["nifra.response-contract"] }] to the policy'
|
|
144
|
+
|
|
94
145
|
export function formatAssuranceReport(report: AssuranceReport): string {
|
|
95
146
|
if (report.ok) {
|
|
96
147
|
const contracted = report.routes.filter((route) => route.responseContract !== undefined)
|
|
@@ -247,20 +298,57 @@ export async function collectAssureBundle(
|
|
|
247
298
|
}
|
|
248
299
|
}
|
|
249
300
|
|
|
301
|
+
// One verification serves both gates that read the app, so the config is evaluated once.
|
|
302
|
+
let verification: Promise<ProjectVerification> | undefined
|
|
303
|
+
const verify = (): Promise<ProjectVerification> =>
|
|
304
|
+
(verification ??= import("./verification.ts").then(({ collectProjectVerification }) =>
|
|
305
|
+
collectProjectVerification(cwd, {
|
|
306
|
+
...(options.config !== undefined ? { config: options.config } : {}),
|
|
307
|
+
preloaded:
|
|
308
|
+
assuranceConfig !== undefined
|
|
309
|
+
? { config: assuranceConfig }
|
|
310
|
+
: { error: assuranceConfigError },
|
|
311
|
+
}),
|
|
312
|
+
))
|
|
313
|
+
|
|
250
314
|
await addGate("check", async () => {
|
|
251
|
-
const
|
|
252
|
-
const verification = await collectProjectVerification(cwd, {
|
|
253
|
-
...(options.config !== undefined ? { config: options.config } : {}),
|
|
254
|
-
preloaded:
|
|
255
|
-
assuranceConfig !== undefined
|
|
256
|
-
? { config: assuranceConfig }
|
|
257
|
-
: { error: assuranceConfigError },
|
|
258
|
-
})
|
|
259
|
-
const result = await verification.check()
|
|
315
|
+
const result = await (await verify()).check()
|
|
260
316
|
const diagnostics = (result.structuredDiagnostics ?? []).map((item) => item)
|
|
261
317
|
return { diagnostics }
|
|
262
318
|
})
|
|
263
319
|
|
|
320
|
+
// Route assurance is the gate the bundle exists to carry: a failing policy fails it, and a declared
|
|
321
|
+
// response the runtime does not enforce is a warning, so `--strict` refuses to call it green.
|
|
322
|
+
await addGate("assurance", async () => {
|
|
323
|
+
const report = assuranceConfig === undefined ? undefined : (await verify()).routeAssurance
|
|
324
|
+
if (report === undefined)
|
|
325
|
+
return {
|
|
326
|
+
diagnostics: [],
|
|
327
|
+
skipReason: existsSync(resolve(cwd, options.config ?? DEFAULT_ASSURANCE_CONFIG))
|
|
328
|
+
? "route assurance could not be evaluated (reported by the check gate)"
|
|
329
|
+
: "no route assurance config",
|
|
330
|
+
}
|
|
331
|
+
const diagnostics = report.findings.map((finding) =>
|
|
332
|
+
diagnosticFromMessage("NF-A001", finding.message, "error"),
|
|
333
|
+
)
|
|
334
|
+
const gaps = responseContractGaps(report.routes)
|
|
335
|
+
for (const [reason, routes] of [
|
|
336
|
+
[gaps.typedOnlyReason, gaps.typedOnly],
|
|
337
|
+
[gaps.warnOnlyReason, gaps.warnOnly],
|
|
338
|
+
] as const) {
|
|
339
|
+
if (reason === undefined) continue
|
|
340
|
+
diagnostics.push(
|
|
341
|
+
Object.freeze({
|
|
342
|
+
code: "NF-A001",
|
|
343
|
+
severity: "warn" as const,
|
|
344
|
+
message: `${reason} (${RESPONSE_CONTRACT_BASELINE_HINT})`,
|
|
345
|
+
evidence: Object.freeze(routes.slice(0, 20)),
|
|
346
|
+
}),
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
return { diagnostics }
|
|
350
|
+
})
|
|
351
|
+
|
|
264
352
|
await addGate("doctor", async () => {
|
|
265
353
|
const { collectDoctorResult } = await import("./doctor.ts")
|
|
266
354
|
const result = await collectDoctorResult(cwd)
|
package/src/capabilities-tool.ts
CHANGED
|
@@ -17,8 +17,20 @@ import {
|
|
|
17
17
|
validCapabilityId,
|
|
18
18
|
} from "@nifrajs/core/capabilities"
|
|
19
19
|
import { expandOptionalParams } from "@nifrajs/core/pattern"
|
|
20
|
-
import {
|
|
21
|
-
|
|
20
|
+
import {
|
|
21
|
+
type ReflectedMount,
|
|
22
|
+
type ReflectedRoute,
|
|
23
|
+
reflectRouteSites,
|
|
24
|
+
reflectRoutes,
|
|
25
|
+
} from "@nifrajs/core/reflection"
|
|
26
|
+
import {
|
|
27
|
+
scanSkippedRouteText,
|
|
28
|
+
scanStaticRouteText,
|
|
29
|
+
scanStaticSocketText,
|
|
30
|
+
stripComments,
|
|
31
|
+
walkSource,
|
|
32
|
+
} from "./check.ts"
|
|
33
|
+
import { projectSite } from "./project-site.ts"
|
|
22
34
|
|
|
23
35
|
// Import and re-export clauses are spelled out (a default binding, then `* as ns` or a `{ … }` list)
|
|
24
36
|
// rather than scanned lazily, which is quadratic on a long semicolon-free module.
|
|
@@ -232,14 +244,113 @@ interface WalkResult {
|
|
|
232
244
|
|
|
233
245
|
const MAX_PROVENANCE_MODULES = 500
|
|
234
246
|
const MAX_PROVENANCE_CHAIN = 16
|
|
247
|
+
/** The budget for one installed package's closure, walked once per run whatever reaches it. */
|
|
248
|
+
const MAX_INSTALLED_MODULES = 5000
|
|
249
|
+
|
|
250
|
+
/** An effect import one module makes, and the policy rules it matches. */
|
|
251
|
+
interface EffectHit {
|
|
252
|
+
readonly specifier: string
|
|
253
|
+
readonly module: string
|
|
254
|
+
/** Specifiers from the walk's entry to this import, the import last. */
|
|
255
|
+
readonly chain: readonly string[]
|
|
256
|
+
readonly approved: readonly CapabilityPolicy["provenance"]["imports"][number][]
|
|
257
|
+
readonly forbidden: readonly CapabilityPolicy["provenance"]["forbiddenImports"][number][]
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** What a walk reads, shared by every route of one run: sources, and installed closures by entry. */
|
|
261
|
+
interface WalkContext {
|
|
262
|
+
readonly cwd: string
|
|
263
|
+
readonly policy: CapabilityPolicy
|
|
264
|
+
readonly sources: Map<string, string>
|
|
265
|
+
readonly installed: Map<string, Promise<InstalledWalk>>
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
interface InstalledWalk {
|
|
269
|
+
readonly hits: readonly EffectHit[]
|
|
270
|
+
readonly truncated: boolean
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** A module under a `node_modules` folder: installed code, the same for every route that reaches it. */
|
|
274
|
+
const isInstalled = (module: string): boolean => module.split("/").includes("node_modules")
|
|
275
|
+
|
|
276
|
+
async function moduleSource(context: WalkContext, module: string): Promise<string | undefined> {
|
|
277
|
+
const cached = context.sources.get(module)
|
|
278
|
+
if (cached !== undefined) return cached
|
|
279
|
+
try {
|
|
280
|
+
const content = await Bun.file(join(context.cwd, module)).text()
|
|
281
|
+
context.sources.set(module, content)
|
|
282
|
+
return content
|
|
283
|
+
} catch {
|
|
284
|
+
return undefined
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The effect imports one module makes, each with the rules it matches, and the modules its other
|
|
290
|
+
* imports load. An approved import is the owned effect seam: its implementation may legitimately
|
|
291
|
+
* import the raw provider, so the walk does not follow it.
|
|
292
|
+
*/
|
|
293
|
+
function scanModule(
|
|
294
|
+
context: WalkContext,
|
|
295
|
+
module: string,
|
|
296
|
+
content: string,
|
|
297
|
+
chain: readonly string[],
|
|
298
|
+
): { readonly hits: EffectHit[]; readonly next: Array<{ module: string; specifier: string }> } {
|
|
299
|
+
const hits: EffectHit[] = []
|
|
300
|
+
const next: Array<{ module: string; specifier: string }> = []
|
|
301
|
+
for (const specifier of scanEffectImports(content)) {
|
|
302
|
+
const approved = context.policy.provenance.imports.filter((rule) =>
|
|
303
|
+
specifierMatches(rule.specifier, specifier),
|
|
304
|
+
)
|
|
305
|
+
const forbidden = context.policy.provenance.forbiddenImports.filter((rule) =>
|
|
306
|
+
specifierMatches(rule.specifier, specifier),
|
|
307
|
+
)
|
|
308
|
+
if (approved.length > 0 || forbidden.length > 0)
|
|
309
|
+
hits.push({ specifier, module, chain: [...chain, specifier], approved, forbidden })
|
|
310
|
+
if (approved.length > 0) continue
|
|
311
|
+
const local = resolveLocalModule(context.cwd, module, specifier, context.sources)
|
|
312
|
+
if (local !== undefined) next.push({ module: local, specifier })
|
|
313
|
+
}
|
|
314
|
+
return { hits, next }
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Every effect import in the closure of the installed module `entry`, walked once per run however many
|
|
319
|
+
* routes reach it. Its chains start after `entry`. A package's own module count stays out of each
|
|
320
|
+
* route's budget: one locale-heavy dependency would otherwise truncate every route that imports it.
|
|
321
|
+
*/
|
|
322
|
+
function walkInstalled(context: WalkContext, entry: string): Promise<InstalledWalk> {
|
|
323
|
+
const cached = context.installed.get(entry)
|
|
324
|
+
if (cached !== undefined) return cached
|
|
325
|
+
const walk = (async (): Promise<InstalledWalk> => {
|
|
326
|
+
const hits: EffectHit[] = []
|
|
327
|
+
const visited = new Set<string>()
|
|
328
|
+
const queue: Array<{ module: string; chain: readonly string[] }> = [
|
|
329
|
+
{ module: entry, chain: [] },
|
|
330
|
+
]
|
|
331
|
+
while (queue.length > 0) {
|
|
332
|
+
if (visited.size >= MAX_INSTALLED_MODULES) return { hits, truncated: true }
|
|
333
|
+
const current = queue.shift()
|
|
334
|
+
if (current === undefined || visited.has(current.module)) continue
|
|
335
|
+
visited.add(current.module)
|
|
336
|
+
const content = await moduleSource(context, current.module)
|
|
337
|
+
if (content === undefined) continue
|
|
338
|
+
const scanned = scanModule(context, current.module, content, current.chain)
|
|
339
|
+
hits.push(...scanned.hits)
|
|
340
|
+
for (const { module, specifier } of scanned.next)
|
|
341
|
+
if (!visited.has(module)) queue.push({ module, chain: [...current.chain, specifier] })
|
|
342
|
+
}
|
|
343
|
+
return { hits, truncated: false }
|
|
344
|
+
})()
|
|
345
|
+
context.installed.set(entry, walk)
|
|
346
|
+
return walk
|
|
347
|
+
}
|
|
235
348
|
|
|
236
349
|
async function walkRouteModules(
|
|
237
|
-
|
|
350
|
+
context: WalkContext,
|
|
238
351
|
modules: readonly string[],
|
|
239
352
|
method: string,
|
|
240
353
|
path: string,
|
|
241
|
-
policy: CapabilityPolicy,
|
|
242
|
-
sources: Map<string, string>,
|
|
243
354
|
): Promise<WalkResult> {
|
|
244
355
|
const queue = modules.map((module) => ({ module, chain: [module] as string[] }))
|
|
245
356
|
const visited = new Set<string>()
|
|
@@ -247,6 +358,25 @@ async function walkRouteModules(
|
|
|
247
358
|
const violations: CapabilityImportViolation[] = []
|
|
248
359
|
const truncations: CapabilityProvenanceTruncation[] = []
|
|
249
360
|
let covered = false
|
|
361
|
+
const record = (hit: EffectHit, chain: readonly string[]): void => {
|
|
362
|
+
for (const rule of hit.approved) {
|
|
363
|
+
for (const id of rule.capabilities) {
|
|
364
|
+
if (!evidence.some((item) => item.id === id && item.source === hit.specifier)) {
|
|
365
|
+
evidence.push({ id, kind: "static", source: hit.specifier })
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
for (const rule of hit.forbidden) {
|
|
370
|
+
violations.push({
|
|
371
|
+
method,
|
|
372
|
+
path,
|
|
373
|
+
module: hit.module,
|
|
374
|
+
specifier: hit.specifier,
|
|
375
|
+
reason: rule.reason,
|
|
376
|
+
chain: Object.freeze([...chain, ...hit.chain]),
|
|
377
|
+
})
|
|
378
|
+
}
|
|
379
|
+
}
|
|
250
380
|
|
|
251
381
|
while (queue.length > 0) {
|
|
252
382
|
if (visited.size >= MAX_PROVENANCE_MODULES) {
|
|
@@ -274,45 +404,30 @@ async function walkRouteModules(
|
|
|
274
404
|
continue
|
|
275
405
|
}
|
|
276
406
|
visited.add(current.module)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
continue
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
covered = true
|
|
287
|
-
for (const specifier of scanEffectImports(content)) {
|
|
288
|
-
let approvedEffectBoundary = false
|
|
289
|
-
for (const rule of policy.provenance.imports) {
|
|
290
|
-
if (!specifierMatches(rule.specifier, specifier)) continue
|
|
291
|
-
approvedEffectBoundary = true
|
|
292
|
-
for (const id of rule.capabilities) {
|
|
293
|
-
if (!evidence.some((item) => item.id === id && item.source === specifier)) {
|
|
294
|
-
evidence.push({ id, kind: "static", source: specifier })
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
for (const rule of policy.provenance.forbiddenImports) {
|
|
299
|
-
if (!specifierMatches(rule.specifier, specifier)) continue
|
|
300
|
-
violations.push({
|
|
407
|
+
if (isInstalled(current.module)) {
|
|
408
|
+
const installed = await walkInstalled(context, current.module)
|
|
409
|
+
covered = true
|
|
410
|
+
for (const hit of installed.hits) record(hit, current.chain)
|
|
411
|
+
if (installed.truncated) {
|
|
412
|
+
truncations.push({
|
|
301
413
|
method,
|
|
302
414
|
path,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
415
|
+
reason: "module-limit",
|
|
416
|
+
chain: Object.freeze([
|
|
417
|
+
...current.chain,
|
|
418
|
+
`<${MAX_INSTALLED_MODULES}-module limit in ${current.module}>`,
|
|
419
|
+
]),
|
|
307
420
|
})
|
|
308
421
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
const content = await moduleSource(context, current.module)
|
|
425
|
+
if (content === undefined) continue
|
|
426
|
+
covered = true
|
|
427
|
+
const scanned = scanModule(context, current.module, content, [])
|
|
428
|
+
for (const hit of scanned.hits) record(hit, current.chain)
|
|
429
|
+
for (const { module, specifier } of scanned.next) {
|
|
430
|
+
if (!visited.has(module)) queue.push({ module, chain: [...current.chain, specifier] })
|
|
316
431
|
}
|
|
317
432
|
}
|
|
318
433
|
return { covered, evidence, violations, truncations }
|
|
@@ -339,7 +454,9 @@ export async function collectCapabilityProjectReport(
|
|
|
339
454
|
): Promise<CapabilityProjectReport> {
|
|
340
455
|
const policy = defineCapabilityPolicy(policyInput)
|
|
341
456
|
const sources = await readSources(cwd)
|
|
457
|
+
const context: WalkContext = { cwd, policy, sources, installed: new Map() }
|
|
342
458
|
const automatic = new Map<string, Set<string>>()
|
|
459
|
+
const skipped = new Map<string, string>()
|
|
343
460
|
for (const [file, content] of sources) {
|
|
344
461
|
for (const route of [
|
|
345
462
|
...scanStaticRouteText(file, content, undefined, sources),
|
|
@@ -352,14 +469,25 @@ export async function collectCapabilityProjectReport(
|
|
|
352
469
|
automatic.set(routeKey(route.method, path), modules)
|
|
353
470
|
}
|
|
354
471
|
}
|
|
472
|
+
for (const route of scanSkippedRouteText(file, content, sources)) {
|
|
473
|
+
for (const path of staticRouteForms(route.path)) {
|
|
474
|
+
if (!skipped.has(routeKey(route.method, path)))
|
|
475
|
+
skipped.set(routeKey(route.method, path), `${file}:${route.line}`)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
355
478
|
}
|
|
356
479
|
|
|
357
480
|
const evidenceRoutes = []
|
|
358
481
|
const violations: CapabilityImportViolation[] = []
|
|
359
482
|
const truncations: CapabilityProvenanceTruncation[] = []
|
|
360
483
|
const reflectedRoutes = options.routes ?? reflectRoutes(source)
|
|
484
|
+
// The module that registered each route, recorded while the app loaded: it covers the paths the
|
|
485
|
+
// text scan cannot read (a template literal, a server a helper builds).
|
|
486
|
+
const registered = reflectRouteSites(source)
|
|
361
487
|
for (const route of reflectedRoutes) {
|
|
362
488
|
const modules = new Set(automatic.get(routeKey(route.method, route.path)) ?? [])
|
|
489
|
+
const site = projectSite(cwd, registered.get(`${route.method} ${route.path}`))?.file
|
|
490
|
+
if (site !== undefined && sources.has(site)) modules.add(site)
|
|
363
491
|
for (const association of policy.provenance.routeModules ?? []) {
|
|
364
492
|
if (
|
|
365
493
|
matchesAssuranceSelector(route, {
|
|
@@ -372,20 +500,27 @@ export async function collectCapabilityProjectReport(
|
|
|
372
500
|
for (const module of association.modules) modules.add(module)
|
|
373
501
|
}
|
|
374
502
|
}
|
|
375
|
-
const walked = await walkRouteModules(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
503
|
+
const walked = await walkRouteModules(context, [...modules], route.method, route.path)
|
|
504
|
+
const skippedAt =
|
|
505
|
+
modules.size === 0 ? skipped.get(routeKey(route.method, route.path)) : undefined
|
|
506
|
+
const uncoveredReason =
|
|
507
|
+
modules.size > 0
|
|
508
|
+
? undefined
|
|
509
|
+
: skippedAt === undefined
|
|
510
|
+
? "no source file registers it with a path the static scan can read; map it with capabilities.provenance.routeModules"
|
|
511
|
+
: `${skippedAt} appears to register it on a server the static scan cannot identify (built by a helper that is neither \`server()\` nor imported from a module that calls it); call server() there, or map the route with capabilities.provenance.routeModules`
|
|
512
|
+
const covered = modules.size > 0 && walked.covered
|
|
513
|
+
evidenceRoutes.push(
|
|
514
|
+
uncoveredReason === undefined
|
|
515
|
+
? { method: route.method, path: route.path, covered, evidence: walked.evidence }
|
|
516
|
+
: {
|
|
517
|
+
method: route.method,
|
|
518
|
+
path: route.path,
|
|
519
|
+
covered,
|
|
520
|
+
evidence: walked.evidence,
|
|
521
|
+
uncoveredReason,
|
|
522
|
+
},
|
|
382
523
|
)
|
|
383
|
-
evidenceRoutes.push({
|
|
384
|
-
method: route.method,
|
|
385
|
-
path: route.path,
|
|
386
|
-
covered: modules.size > 0 && walked.covered,
|
|
387
|
-
evidence: walked.evidence,
|
|
388
|
-
})
|
|
389
524
|
violations.push(...walked.violations)
|
|
390
525
|
truncations.push(...walked.truncations)
|
|
391
526
|
}
|
package/src/check-diagnostics.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { parseRulePacks, runRuleRegistry } from "./rules/index.ts"
|
|
|
28
28
|
import { islandRules } from "./rules/islands.ts"
|
|
29
29
|
import { retiredLayoutRule } from "./rules/layout.ts"
|
|
30
30
|
import { LEGACY_RULE_CODES, LEGACY_RULE_ORDER, legacyRules } from "./rules/legacy.ts"
|
|
31
|
+
import { mergeAuthGapRule } from "./rules/merge-auth.ts"
|
|
31
32
|
import { nanoRules } from "./rules/nano.ts"
|
|
32
33
|
import { pageRules } from "./rules/pages.ts"
|
|
33
34
|
import { routeRules } from "./rules/routes.ts"
|
|
@@ -94,6 +95,8 @@ export interface CheckResult {
|
|
|
94
95
|
* better-auth). Echoed here so `--json` / the MCP tool / the report can show what the typed-client scan
|
|
95
96
|
* deliberately skipped - a suppressed prefix stays auditable instead of silently hiding real drift. */
|
|
96
97
|
readonly externalMounts?: readonly string[]
|
|
98
|
+
/** The tsconfigs `nifra.check.json` names for the typecheck, echoed so a narrowed program is visible. */
|
|
99
|
+
readonly tsconfigs?: readonly string[]
|
|
97
100
|
/** Mounts declared `opaque` - outside capability assurance on purpose, each with its stated reason.
|
|
98
101
|
* Listed on every run so the report states its own boundary; never a failure. */
|
|
99
102
|
readonly knownGaps?: readonly CapabilityGap[]
|
|
@@ -160,6 +163,9 @@ export interface CheckAssuranceContext {
|
|
|
160
163
|
export interface CheckConfig {
|
|
161
164
|
readonly externalMounts: readonly string[]
|
|
162
165
|
readonly rules: Readonly<Record<string, RuleOverride>>
|
|
166
|
+
/** The tsconfigs the typecheck runs, each its own program, project-relative. Unset: `tsconfig.json`
|
|
167
|
+
* and every project it references. */
|
|
168
|
+
readonly tsconfigs?: readonly string[]
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
/**
|
|
@@ -368,6 +374,8 @@ export interface CheckTypecheckResult {
|
|
|
368
374
|
readonly note?: string
|
|
369
375
|
readonly output?: string
|
|
370
376
|
readonly missingTypeScript?: boolean
|
|
377
|
+
/** TypeScript sources found with no tsconfig.json to typecheck them. */
|
|
378
|
+
readonly sourcesWithoutTsconfig?: number
|
|
371
379
|
readonly outsideProgram?: readonly string[]
|
|
372
380
|
}
|
|
373
381
|
|
|
@@ -490,6 +498,7 @@ export async function collectCheckDiagnostics(
|
|
|
490
498
|
...routeRules,
|
|
491
499
|
contractVisibilityRule,
|
|
492
500
|
...pageRules,
|
|
501
|
+
mergeAuthGapRule,
|
|
493
502
|
...zoneRules,
|
|
494
503
|
...dataGuardRules,
|
|
495
504
|
...secretRules,
|
|
@@ -672,6 +681,7 @@ export async function collectCheckDiagnostics(
|
|
|
672
681
|
...(checkConfig.externalMounts.length === 0
|
|
673
682
|
? {}
|
|
674
683
|
: { externalMounts: checkConfig.externalMounts }),
|
|
684
|
+
...(checkConfig.tsconfigs === undefined ? {} : { tsconfigs: checkConfig.tsconfigs }),
|
|
675
685
|
...(knownGaps.length === 0 ? {} : { knownGaps }),
|
|
676
686
|
...(hooks === undefined ? {} : { hooks }),
|
|
677
687
|
...(Object.keys(checkConfig.rules).length === 0 ? {} : { ruleOverrides: checkConfig.rules }),
|