@nifrajs/cli 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/agent-files.d.ts +107 -0
- package/dist/agent-files.d.ts.map +1 -0
- package/dist/agent-files.js +162 -0
- package/dist/agent-files.js.map +1 -0
- package/dist/app-files.d.ts +6 -0
- package/dist/app-files.d.ts.map +1 -1
- package/dist/app-files.js +27 -2
- package/dist/app-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/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +13 -3
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +20 -2
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +54 -7
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +75 -22
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +1475 -310
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +2 -2
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +192 -65
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +112 -5
- package/dist/cli.js.map +1 -1
- package/dist/client-module.d.ts +18 -0
- package/dist/client-module.d.ts.map +1 -0
- package/dist/client-module.js +49 -0
- package/dist/client-module.js.map +1 -0
- package/dist/command-catalog.d.ts +21 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +138 -38
- package/dist/command-catalog.js.map +1 -1
- package/dist/component-check.d.ts +13 -0
- package/dist/component-check.d.ts.map +1 -0
- package/dist/component-check.js +59 -0
- package/dist/component-check.js.map +1 -0
- package/dist/contract-proof.d.ts +1 -1
- package/dist/contract-proof.d.ts.map +1 -1
- package/dist/contract-proof.js +2 -24
- package/dist/contract-proof.js.map +1 -1
- package/dist/contracts.d.ts +19 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +50 -3
- package/dist/contracts.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +4 -3
- package/dist/db-tool.js.map +1 -1
- package/dist/dev-bun-config.d.ts +5 -1
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +44 -11
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/diagnostics.d.ts +3 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/diff-tool.d.ts +9 -8
- package/dist/diff-tool.d.ts.map +1 -1
- package/dist/diff-tool.js +28 -24
- package/dist/diff-tool.js.map +1 -1
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +23 -15
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts +6 -0
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +6 -0
- package/dist/env-file.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +28 -3
- package/dist/fix-recipes.js.map +1 -1
- package/dist/hand-built-manifest.d.ts +27 -0
- package/dist/hand-built-manifest.d.ts.map +1 -0
- package/dist/hand-built-manifest.js +124 -0
- package/dist/hand-built-manifest.js.map +1 -0
- package/dist/hooks-report.d.ts +23 -0
- package/dist/hooks-report.d.ts.map +1 -0
- package/dist/hooks-report.js +104 -0
- package/dist/hooks-report.js.map +1 -0
- package/dist/init-agents.d.ts +2 -2
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +17 -11
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/nifra-project.d.ts +41 -0
- package/dist/internal/nifra-project.d.ts.map +1 -0
- package/dist/internal/nifra-project.js +183 -0
- package/dist/internal/nifra-project.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts +16 -0
- package/dist/internal/project-specifiers.d.ts.map +1 -0
- package/dist/internal/project-specifiers.js +396 -0
- package/dist/internal/project-specifiers.js.map +1 -0
- package/dist/internal/script-kind.d.ts.map +1 -1
- package/dist/internal/script-kind.js +2 -1
- package/dist/internal/script-kind.js.map +1 -1
- package/dist/internal/source-facts.d.ts +2 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +11 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts +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/introspect.d.ts +6 -6
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +55 -24
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +93 -15
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +31 -8
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +37 -7
- package/dist/load.js.map +1 -1
- package/dist/mcp-context.d.ts +5 -5
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +2 -2
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-exec.d.ts +12 -4
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +50 -13
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +17 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +40 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +3 -2
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.js +1 -1
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +50 -10
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +3 -1
- package/dist/mcp-ws.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +8 -2
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +7 -0
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +958 -71
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts +94 -0
- package/dist/output-schemas.d.ts.map +1 -0
- package/dist/output-schemas.js +864 -0
- package/dist/output-schemas.js.map +1 -0
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +3 -2
- package/dist/port.js.map +1 -1
- package/dist/project-facts.d.ts +15 -4
- package/dist/project-facts.d.ts.map +1 -1
- package/dist/project-facts.js +1 -0
- package/dist/project-facts.js.map +1 -1
- 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.0.0.d.ts +11 -0
- package/dist/recipes/5.0.0.d.ts.map +1 -0
- package/dist/recipes/5.0.0.js +34 -0
- package/dist/recipes/5.0.0.js.map +1 -0
- package/dist/recipes/index.d.ts +7 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/replay.d.ts.map +1 -1
- package/dist/replay.js +12 -3
- package/dist/replay.js.map +1 -1
- package/dist/review.d.ts +3 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +38 -7
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +10 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +10 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/comment-markers.d.ts +16 -7
- package/dist/rules/comment-markers.d.ts.map +1 -1
- package/dist/rules/comment-markers.js +58 -19
- package/dist/rules/comment-markers.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts +3 -0
- package/dist/rules/contract-visibility.d.ts.map +1 -0
- package/dist/rules/contract-visibility.js +337 -0
- package/dist/rules/contract-visibility.js.map +1 -0
- package/dist/rules/data-guard.d.ts +7 -0
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +319 -37
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/layout.d.ts +4 -0
- package/dist/rules/layout.d.ts.map +1 -0
- package/dist/rules/layout.js +19 -0
- package/dist/rules/layout.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +158 -43
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/pages.d.ts +24 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +221 -3
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +6 -0
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +111 -16
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/secrets.js +2 -2
- package/dist/rules/secrets.js.map +1 -1
- package/dist/rules/security.d.ts +12 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +281 -68
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts +13 -0
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +192 -40
- package/dist/rules/zones.js.map +1 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +6 -4
- package/dist/scaffold.js.map +1 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +14 -5
- package/dist/sdk.js.map +1 -1
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +163 -7
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/sync-manifest.d.ts +10 -2
- package/dist/sync-manifest.d.ts.map +1 -1
- package/dist/sync-manifest.js +42 -18
- package/dist/sync-manifest.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +12 -3
- package/dist/test-tool.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +20 -0
- package/dist/typecheck-coverage.d.ts.map +1 -0
- package/dist/typecheck-coverage.js +129 -0
- package/dist/typecheck-coverage.js.map +1 -0
- package/dist/upgrade.d.ts +69 -0
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +420 -77
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +11 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts +22 -0
- package/dist/version-drift.d.ts.map +1 -0
- package/dist/version-drift.js +42 -0
- package/dist/version-drift.js.map +1 -0
- 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 +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +20 -8
- package/dist/work-graph.js.map +1 -1
- package/docs/examples.json +54 -6
- package/docs/llms-full.txt +1539 -138
- package/docs/types.json +1456 -206
- package/package.json +11 -12
- package/src/agent-files.ts +203 -0
- package/src/app-files.ts +34 -4
- package/src/assure-hydration.ts +15 -2
- package/src/capabilities-tool.ts +15 -3
- package/src/check-diagnostics.ts +73 -9
- package/src/check-scan.ts +1773 -381
- package/src/check.ts +237 -76
- package/src/cli.ts +141 -5
- package/src/client-module.ts +61 -0
- package/src/command-catalog.ts +181 -47
- package/src/component-check.ts +79 -0
- package/src/contract-proof.ts +3 -25
- package/src/contracts.ts +60 -3
- package/src/db-tool.ts +5 -2
- package/src/dev-bun-config.ts +51 -10
- package/src/diagnostics.ts +3 -0
- package/src/diff-tool.ts +33 -26
- package/src/doctor.ts +43 -21
- package/src/env-file.ts +7 -0
- package/src/fix-recipes.ts +34 -3
- package/src/hand-built-manifest.ts +144 -0
- package/src/hooks-report.ts +135 -0
- package/src/init-agents.ts +17 -11
- package/src/internal/nifra-project.ts +191 -0
- package/src/internal/project-specifiers.ts +424 -0
- package/src/internal/script-kind.ts +2 -1
- package/src/internal/source-facts.ts +25 -0
- package/src/internal/typescript-import.ts +10 -3
- package/src/introspect.ts +65 -27
- package/src/levels-tool.ts +117 -20
- package/src/load.ts +78 -14
- package/src/mcp-context.ts +7 -7
- package/src/mcp-exec.ts +60 -17
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +41 -0
- package/src/mcp-isolate.ts +9 -2
- package/src/mcp-project-child.ts +1 -1
- package/src/mcp-root.ts +58 -8
- package/src/mcp-ws.ts +4 -2
- package/src/mcp.ts +8 -3
- package/src/migrate-layout.ts +1109 -70
- package/src/output-schemas.ts +1084 -0
- package/src/port.ts +3 -2
- package/src/project-facts.ts +17 -3
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.0.0.ts +35 -0
- package/src/recipes/index.ts +10 -0
- package/src/replay.ts +14 -3
- package/src/review.ts +39 -10
- package/src/rules/codes.ts +10 -0
- package/src/rules/comment-markers.ts +57 -21
- package/src/rules/contract-visibility.ts +383 -0
- package/src/rules/data-guard.ts +351 -42
- package/src/rules/layout.ts +22 -0
- package/src/rules/legacy.ts +184 -51
- package/src/rules/pages.ts +238 -3
- package/src/rules/routes.ts +124 -16
- package/src/rules/secrets.ts +2 -2
- package/src/rules/security.ts +352 -71
- package/src/rules/zones.ts +205 -38
- package/src/scaffold.ts +6 -4
- package/src/sdk.ts +14 -5
- package/src/stylex-migrate.ts +134 -7
- package/src/sync-manifest.ts +48 -18
- package/src/test-tool.ts +18 -3
- package/src/typecheck-coverage.ts +134 -0
- package/src/upgrade.ts +487 -71
- package/src/verification-plan.ts +24 -0
- package/src/version-drift.ts +67 -0
- package/src/web-app-options.ts +2 -2
- package/src/work-graph.ts +17 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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",
|
|
@@ -69,17 +69,16 @@
|
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@nifrajs/client": "
|
|
73
|
-
"@nifrajs/core": "
|
|
74
|
-
"@nifrajs/agent-review": "
|
|
75
|
-
"@nifrajs/i18n": "
|
|
76
|
-
"@nifrajs/mcp": "
|
|
77
|
-
"@nifrajs/mcp-db": "
|
|
78
|
-
"@nifrajs/runner": "
|
|
79
|
-
"@nifrajs/schema": "
|
|
80
|
-
"@nifrajs/testing": "
|
|
81
|
-
"@nifrajs/web": "
|
|
82
|
-
"create-nifra": "4.0.0"
|
|
72
|
+
"@nifrajs/client": "5.0.0",
|
|
73
|
+
"@nifrajs/core": "5.0.0",
|
|
74
|
+
"@nifrajs/agent-review": "5.0.0",
|
|
75
|
+
"@nifrajs/i18n": "5.0.0",
|
|
76
|
+
"@nifrajs/mcp": "5.0.0",
|
|
77
|
+
"@nifrajs/mcp-db": "5.0.0",
|
|
78
|
+
"@nifrajs/runner": "5.0.0",
|
|
79
|
+
"@nifrajs/schema": "5.0.0",
|
|
80
|
+
"@nifrajs/testing": "5.0.0",
|
|
81
|
+
"@nifrajs/web": "5.0.0"
|
|
83
82
|
},
|
|
84
83
|
"repository": {
|
|
85
84
|
"type": "git",
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical generators for the agent files an app ships. `AGENTS.md` is the single source of agent
|
|
3
|
+
* guidance; every other agent's file is a thin pointer to it, so no two copies can drift:
|
|
4
|
+
*
|
|
5
|
+
* AGENTS.md - the guidance (read natively by Codex, Cursor, Copilot and others)
|
|
6
|
+
* CLAUDE.md - Claude Code: `@AGENTS.md` import
|
|
7
|
+
* GEMINI.md - Gemini CLI: `@./AGENTS.md` import
|
|
8
|
+
* .cursor/rules/nifra.mdc - Cursor: an always-applied rule pointing at AGENTS.md
|
|
9
|
+
* .github/copilot-instructions.md - GitHub Copilot: points at AGENTS.md
|
|
10
|
+
* .mcp.json, .cursor/mcp.json - the nifra MCP server, registered for Claude Code and Cursor
|
|
11
|
+
*
|
|
12
|
+
* `create-nifra` (scaffold time) and `@nifrajs/cli`'s `nifra init-agents` (retrofit an existing app) each
|
|
13
|
+
* ship this file byte-identical - `packages/cli/test/init-agents.test.ts` holds the two copies equal - so
|
|
14
|
+
* the generated files can never drift apart and neither package needs the other at runtime. It stays
|
|
15
|
+
* dependency-free (pure string + object generation) on purpose: `create-nifra` ships with no runtime deps.
|
|
16
|
+
*
|
|
17
|
+
* Why `bunx @nifrajs/cli mcp` (not `bunx nifra mcp`): the `nifra` binary is provided by the
|
|
18
|
+
* `@nifrajs/cli` package, and the bare npm package literally named `nifra` (this monorepo's
|
|
19
|
+
* `@nifrajs/web` shim) exposes NO `nifra` bin, so `bunx nifra mcp` would fetch the wrong package in an
|
|
20
|
+
* app that does not carry `@nifrajs/cli`. Naming the bin-owning package resolves the locally-installed
|
|
21
|
+
* bin when present and otherwise fetches the package that actually provides the `nifra` command.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { readFileSync } from "node:fs"
|
|
25
|
+
|
|
26
|
+
/** The MCP launch command, shared by `.mcp.json` and `.cursor/mcp.json`. See the module header for why
|
|
27
|
+
* the package is named explicitly rather than relying on the bare `nifra` bin. */
|
|
28
|
+
export const MCP_SERVER_COMMAND = "bunx" as const
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The `@nifrajs/cli` version the launch command pins to - DERIVED at load time from this package's own
|
|
32
|
+
* `version`, never hardcoded. `fixed` changeset versioning ([["@nifrajs/*", "create-nifra", "nifra"]] in
|
|
33
|
+
* `.changeset/config.json`) bumps `create-nifra` and `@nifrajs/cli` in lockstep, so `create-nifra@x`
|
|
34
|
+
* always means `@nifrajs/cli@x`. Deriving it here means a release bump has nothing to forget to update -
|
|
35
|
+
* there is no stale literal to drift (the 1.0.0 cut shipped a beta pin exactly this way). `check:publish`
|
|
36
|
+
* still asserts it equals `@nifrajs/cli`'s version as a belt-and-suspenders guard on the `fixed` link.
|
|
37
|
+
*
|
|
38
|
+
* Resolves correctly under BOTH export conditions: the `bun` export runs `src/agent-files.ts`
|
|
39
|
+
* (`../package.json` → the package root) and the tsc `default` export runs `dist/agent-files.js`
|
|
40
|
+
* (`../package.json` → the same root, since `dist/` sits beside the manifest). npm always ships a
|
|
41
|
+
* package's own `package.json`, so the read can't miss at install time.
|
|
42
|
+
*
|
|
43
|
+
* Why pin at all instead of `bunx @nifrajs/cli mcp`: `bunx` keys its cache on the exact version spec.
|
|
44
|
+
* An UNPINNED spec resolves to the `latest` tag once, then `bunx` reuses that cached copy on every
|
|
45
|
+
* later spawn WITHOUT re-checking the registry - so an editor that once launched an older `@nifrajs/cli`
|
|
46
|
+
* keeps respawning the stale binary even after a newer one is published (the MCP server silently runs
|
|
47
|
+
* old code). Pinning the exact version makes the version part of the cache key, so each release fetches
|
|
48
|
+
* fresh and a stale cache can never shadow it. The cost: an already-scaffolded app's `.mcp.json` freezes
|
|
49
|
+
* at its scaffold-time version until `nifra init-agents --sync-mcp` re-pins it to the nifra the project
|
|
50
|
+
* installs - an acceptable, deterministic trade.
|
|
51
|
+
*/
|
|
52
|
+
export const MCP_CLI_VERSION: string = ownVersion()
|
|
53
|
+
|
|
54
|
+
function ownVersion(): string {
|
|
55
|
+
const manifest: unknown = JSON.parse(
|
|
56
|
+
readFileSync(new URL("../package.json", import.meta.url), "utf8"),
|
|
57
|
+
)
|
|
58
|
+
if (
|
|
59
|
+
typeof manifest === "object" &&
|
|
60
|
+
manifest !== null &&
|
|
61
|
+
"version" in manifest &&
|
|
62
|
+
typeof manifest.version === "string"
|
|
63
|
+
)
|
|
64
|
+
return manifest.version
|
|
65
|
+
throw new Error("[nifra] agent-files: this package's package.json has no version")
|
|
66
|
+
}
|
|
67
|
+
export const MCP_SERVER_ARGS = [`@nifrajs/cli@${MCP_CLI_VERSION}`, "mcp"] as const
|
|
68
|
+
|
|
69
|
+
/** The server entry registered under the `nifra` key in both Claude Code's and Cursor's MCP config. */
|
|
70
|
+
export interface McpServerConfig {
|
|
71
|
+
readonly command: string
|
|
72
|
+
readonly args: readonly string[]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Claude Code / Cursor MCP config shape: a map of server name → launch config. */
|
|
76
|
+
export interface McpConfig {
|
|
77
|
+
readonly mcpServers: Readonly<Record<string, McpServerConfig>>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The one canonical MCP config object both registries serialize - the anti-drift seam. */
|
|
81
|
+
export const MCP_CONFIG: McpConfig = {
|
|
82
|
+
mcpServers: {
|
|
83
|
+
nifra: { command: MCP_SERVER_COMMAND, args: [...MCP_SERVER_ARGS] },
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Serialize the canonical MCP config as the JSON written to `.mcp.json` and `.cursor/mcp.json`.
|
|
88
|
+
* 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(MCP_CONFIG, null, 2)}\n`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const POINTER_INTRO =
|
|
94
|
+
"This project's agent guidance - commands, the project structure, the rules, and the nifra MCP server - lives in AGENTS.md, the single source every agent reads."
|
|
95
|
+
|
|
96
|
+
/** `CLAUDE.md`: Claude Code expands the `@AGENTS.md` import in place. */
|
|
97
|
+
export function claudeMd(): string {
|
|
98
|
+
return `# CLAUDE.md\n\n${POINTER_INTRO}\n\n@AGENTS.md\n`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `GEMINI.md`: Gemini CLI expands `@./AGENTS.md` imports in its context files. */
|
|
102
|
+
export function geminiMd(): string {
|
|
103
|
+
return `# GEMINI.md\n\n${POINTER_INTRO}\n\n@./AGENTS.md\n`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** `.cursor/rules/nifra.mdc`: an always-applied Cursor rule; `@AGENTS.md` attaches the file. */
|
|
107
|
+
export function cursorRule(): string {
|
|
108
|
+
return `---\ndescription: nifra project guidance\nalwaysApply: true\n---\n\n${POINTER_INTRO} Read it before changing code:\n\n@AGENTS.md\n`
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** `.github/copilot-instructions.md`: Copilot has no import syntax, so this names the file. */
|
|
112
|
+
export function copilotInstructions(): string {
|
|
113
|
+
return `${POINTER_INTRO} Read AGENTS.md at the repository root before changing code, and follow it.\n`
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The "## MCP server" section appended to a scaffolded (or retrofitted) `AGENTS.md`, so non-Claude
|
|
118
|
+
* agents (Cursor, and anything that reads `AGENTS.md`) also learn the MCP exists and what to prefer.
|
|
119
|
+
* Mirrors the CLAUDE.md preamble's guidance without the Claude-specific `@import`.
|
|
120
|
+
*/
|
|
121
|
+
export function agentsMcpSection(): string {
|
|
122
|
+
return `## MCP server
|
|
123
|
+
|
|
124
|
+
This project ships a **nifra MCP server** - launch it with \`${MCP_SERVER_COMMAND} ${MCP_SERVER_ARGS.join(" ")}\`. It's registered for
|
|
125
|
+
Claude Code in \`.mcp.json\` and for Cursor in \`.cursor/mcp.json\`; other agents can point their MCP client
|
|
126
|
+
at that command. **Prefer its tools** over writing nifra from memory - they're typechecked against this
|
|
127
|
+
project + the installed version, so they beat training-data recall:
|
|
128
|
+
|
|
129
|
+
- \`nifra_docs\` / \`nifra_example\` - exact signatures + verified, compiling snippets.
|
|
130
|
+
- \`nifra_context\` / \`nifra_routes\` - this project's route index + per-route schemas.
|
|
131
|
+
- \`nifra_types\` - the EXACT TypeScript of any \`@nifrajs/*\` symbol (interface/type/function). Call it for a
|
|
132
|
+
precise type; **never read \`@nifrajs\` \`.d.ts\` files** - this is the authoritative, complete source.
|
|
133
|
+
- \`nifra_check\` - the done-gate (typecheck + drift lints). Run it before calling work complete; a
|
|
134
|
+
failing check means it isn't done. (\`nifra check --json\` in a terminal does the same.)`
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The "## Project structure" section of a web app's `AGENTS.md`: the zones the build enforces. Shared so
|
|
139
|
+
* a scaffolded app and one `nifra init-agents` retrofits teach the same rules.
|
|
140
|
+
*/
|
|
141
|
+
export function agentsStructureSection(): string {
|
|
142
|
+
return `${STRUCTURE_HEADING}
|
|
143
|
+
|
|
144
|
+
Every file a build loads belongs to one side, and the build refuses an import that crosses the wrong
|
|
145
|
+
way - it fails naming the import chain rather than shipping server code to the browser.
|
|
146
|
+
|
|
147
|
+
| Where | Holds | Reaches the browser |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| \`routes/x.tsx\` (\`.svelte\`, \`.vue\`, \`.mdx\`) | a page: the component, \`meta\` | yes |
|
|
150
|
+
| \`routes/x.backend.ts\` | that page's \`loader\`, \`action\`, \`loaderOutput\`, \`actionOutput\`, \`middleware\` | never |
|
|
151
|
+
| \`frontend/\` | components, hooks, browser-only code | yes |
|
|
152
|
+
| \`backend/\` | \`app.ts\` (the API), \`framework.ts\`, the database, auth, secrets | never |
|
|
153
|
+
| \`shared/\` | schemas, types and pure helpers both sides import | yes |
|
|
154
|
+
| \`public/\` | static files served as they are | yes |
|
|
155
|
+
|
|
156
|
+
A file outside those folders joins a side with a \`.frontend.ts\`, \`.backend.ts\` or \`.shared.ts\` suffix.
|
|
157
|
+
|
|
158
|
+
- **A route is two files.** \`routes/blog/[slug].tsx\` renders; \`routes/blog/[slug].backend.ts\` loads.
|
|
159
|
+
A server-only export (\`loader\`, \`action\`, ...) in the \`.tsx\` file is a build error.
|
|
160
|
+
- **Frontend code never imports backend code** - not \`backend/\`, not a \`.backend.ts\` file, not a
|
|
161
|
+
database driver or \`node:\` built-in. Data reaches a page only as its loader's return value.
|
|
162
|
+
- **Every loader and action declares what it sends**: \`export const loaderOutput = t.object({ ... })\`
|
|
163
|
+
(and \`actionOutput\`). Only what the schema declares reaches the browser, and a loader without one
|
|
164
|
+
is refused.
|
|
165
|
+
- **Type a route with its generated \`./+types/<name>\`**: \`import type { Route } from "./+types/[slug]"\`
|
|
166
|
+
gives \`Route.Loader\` and \`Route.Action\` in the backend half (\`export const loader: Route.Loader =
|
|
167
|
+
async ({ api, params }) => ...\` checks what it returns against \`loaderOutput\`) and
|
|
168
|
+
\`Route.ComponentProps\` in the page. \`nifra dev\`, \`nifra build\`, \`nifra check\` and
|
|
169
|
+
\`nifra types\` write them.
|
|
170
|
+
- **Secrets stay in \`backend/\`.** A value only the server may see is read there (\`process.env\`), never
|
|
171
|
+
in a frontend file; a build that finds what looks like a credential in browser output fails.`
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The heading `nifra init-agents` looks for before appending {@link agentsStructureSection}. */
|
|
175
|
+
export const STRUCTURE_HEADING = "## Project structure"
|
|
176
|
+
|
|
177
|
+
/** Identifies a generated agent-discovery file: where it goes (relative to the project root) and how to
|
|
178
|
+
* produce its content. `merge` is for files that augment an existing one (AGENTS.md) rather than own it. */
|
|
179
|
+
export interface AgentFileSpec {
|
|
180
|
+
/** Path relative to the project root (POSIX-style; the caller joins onto the cwd). */
|
|
181
|
+
readonly path: string
|
|
182
|
+
/** A human label for the "wrote/skipped" report. */
|
|
183
|
+
readonly label: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The standalone files this module fully owns (whole-file generators). AGENTS.md is handled separately
|
|
187
|
+
* because create-nifra builds it from `agents.ts` and the retrofit command appends sections to it. */
|
|
188
|
+
export const MCP_JSON_PATH = ".mcp.json"
|
|
189
|
+
export const CURSOR_MCP_JSON_PATH = ".cursor/mcp.json"
|
|
190
|
+
export const CLAUDE_MD_PATH = "CLAUDE.md"
|
|
191
|
+
export const GEMINI_MD_PATH = "GEMINI.md"
|
|
192
|
+
export const CURSOR_RULE_PATH = ".cursor/rules/nifra.mdc"
|
|
193
|
+
export const COPILOT_INSTRUCTIONS_PATH = ".github/copilot-instructions.md"
|
|
194
|
+
export const AGENTS_MD_PATH = "AGENTS.md"
|
|
195
|
+
|
|
196
|
+
/** Every agent's pointer to `AGENTS.md`, in the order they are written and reported. */
|
|
197
|
+
export const AGENT_POINTERS: readonly { readonly path: string; readonly content: () => string }[] =
|
|
198
|
+
[
|
|
199
|
+
{ path: CLAUDE_MD_PATH, content: claudeMd },
|
|
200
|
+
{ path: GEMINI_MD_PATH, content: geminiMd },
|
|
201
|
+
{ path: CURSOR_RULE_PATH, content: cursorRule },
|
|
202
|
+
{ path: COPILOT_INSTRUCTIONS_PATH, content: copilotInstructions },
|
|
203
|
+
]
|
package/src/app-files.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* kept free of build tooling because it is bundled into every server build.
|
|
7
7
|
* - `backend/app.ts` - exports `backend`, the app's API (a `@nifrajs/core` server). Optional.
|
|
8
8
|
*/
|
|
9
|
-
import { existsSync } from "node:fs"
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
10
10
|
import { resolve } from "node:path"
|
|
11
11
|
|
|
12
12
|
export const CONFIG_FILE = "nifra.config.ts"
|
|
@@ -19,11 +19,41 @@ export const RETIRED_ROOT_FILES: Readonly<Record<string, string>> = {
|
|
|
19
19
|
"framework.ts": FRAMEWORK_FILE,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** Outside a routed app, what made each retired root file the app's: else it is just a module. */
|
|
23
|
+
const RETIRED_EXPORTS: Readonly<Record<string, RegExp>> = {
|
|
24
|
+
"backend.ts":
|
|
25
|
+
/\bexport\s+(?:const|let|var|(?:async\s+)?function|class)\s+backend\b|\bexport\s*\{[^}]*\bbackend\b/,
|
|
26
|
+
"framework.ts":
|
|
27
|
+
/\bexport\s+(?:const|let|var|(?:async\s+)?function|class)\s+adapter\b|\bexport\s*\{[^}]*\badapter\b/,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function exportsRetiredName(path: string, pattern: RegExp | undefined): boolean {
|
|
31
|
+
if (!existsSync(path)) return false
|
|
32
|
+
try {
|
|
33
|
+
return pattern === undefined || pattern.test(readFileSync(path, "utf8"))
|
|
34
|
+
} catch {
|
|
35
|
+
// Unreadable: the commands that would load it fail too, so report it rather than skip it.
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The retired root files present in `cwd`, each with where it lives now. The old loader imported them
|
|
42
|
+
* whatever they exported, so in an app with `routes/` or a config each one counts; elsewhere only one
|
|
43
|
+
* that exports what the loader read does, and a library's `backend.ts` module does not.
|
|
44
|
+
*/
|
|
45
|
+
export function retiredRootFiles(cwd: string): ReadonlyArray<readonly [string, string]> {
|
|
46
|
+
const routed = ["routes", CONFIG_FILE, FRAMEWORK_FILE].some((entry) =>
|
|
47
|
+
existsSync(resolve(cwd, entry)),
|
|
48
|
+
)
|
|
49
|
+
return Object.entries(RETIRED_ROOT_FILES).filter(([file]) =>
|
|
50
|
+
exportsRetiredName(resolve(cwd, file), routed ? undefined : RETIRED_EXPORTS[file]),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
22
54
|
/** Refuse an app still on the retired root files: run against it, a command would silently miss them. */
|
|
23
55
|
export function assertCurrentLayout(cwd: string): void {
|
|
24
|
-
const retired =
|
|
25
|
-
existsSync(resolve(cwd, file)),
|
|
26
|
-
)
|
|
56
|
+
const retired = retiredRootFiles(cwd)
|
|
27
57
|
if (retired.length === 0) return
|
|
28
58
|
const moves = retired.map(([from, to]) => `${from} -> ${to}`).join(", ")
|
|
29
59
|
throw new Error(
|
package/src/assure-hydration.ts
CHANGED
|
@@ -11,7 +11,15 @@ import { discoverRoutes } from "@nifrajs/web/fs"
|
|
|
11
11
|
import type { BunPlugin } from "bun"
|
|
12
12
|
import { collectDoctorResult } from "./doctor.ts"
|
|
13
13
|
import { loadApp, resolvePlugins } from "./load.ts"
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
CHILD_OUTPUT_MAX_BYTES,
|
|
16
|
+
forwardTerminalSignals,
|
|
17
|
+
joinHeadTail,
|
|
18
|
+
OWN_PROCESS_GROUP,
|
|
19
|
+
readBoundedStream,
|
|
20
|
+
readHeadTail,
|
|
21
|
+
signalProcessGroup,
|
|
22
|
+
} from "./mcp-io.ts"
|
|
15
23
|
import { frameworkWebAppOptions } from "./web-app-options.ts"
|
|
16
24
|
|
|
17
25
|
const HYDRATION_ASSURANCE = Symbol.for("nifra.hydration.assurance")
|
|
@@ -634,15 +642,19 @@ export async function runHydrationAssurance(
|
|
|
634
642
|
stdin: "pipe",
|
|
635
643
|
stdout: "pipe",
|
|
636
644
|
stderr: "pipe",
|
|
645
|
+
// Its own group, so a stop reaches whatever the project's code started too; a process left
|
|
646
|
+
// holding the pipes would otherwise keep this run waiting past its timeout.
|
|
647
|
+
detached: OWN_PROCESS_GROUP,
|
|
637
648
|
},
|
|
638
649
|
)
|
|
639
650
|
let stopped: string | undefined
|
|
640
651
|
const stop = (reason: string): void => {
|
|
641
652
|
stopped ??= reason
|
|
642
|
-
proc
|
|
653
|
+
signalProcessGroup(proc, "SIGTERM")
|
|
643
654
|
}
|
|
644
655
|
const onAbort = (): void => stop("cancelled")
|
|
645
656
|
control.signal?.addEventListener("abort", onAbort, { once: true })
|
|
657
|
+
const releaseSignals = forwardTerminalSignals(() => stop("interrupted"))
|
|
646
658
|
const timeoutMs = control.timeoutMs ?? HYDRATION_RUN_TIMEOUT_MS
|
|
647
659
|
const timer = setTimeout(() => stop(`timed out after ${timeoutMs} ms`), timeoutMs)
|
|
648
660
|
try {
|
|
@@ -673,6 +685,7 @@ export async function runHydrationAssurance(
|
|
|
673
685
|
} finally {
|
|
674
686
|
clearTimeout(timer)
|
|
675
687
|
control.signal?.removeEventListener("abort", onAbort)
|
|
688
|
+
releaseSignals()
|
|
676
689
|
}
|
|
677
690
|
}
|
|
678
691
|
|
package/src/capabilities-tool.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "@nifrajs/core/capabilities"
|
|
19
19
|
import { expandOptionalParams } from "@nifrajs/core/pattern"
|
|
20
20
|
import { type ReflectedMount, type ReflectedRoute, reflectRoutes } from "@nifrajs/core/reflection"
|
|
21
|
-
import { scanStaticRouteText, stripComments, walkSource } from "./check.ts"
|
|
21
|
+
import { scanStaticRouteText, scanStaticSocketText, stripComments, walkSource } from "./check.ts"
|
|
22
22
|
|
|
23
23
|
// Import and re-export clauses are spelled out (a default binding, then `* as ns` or a `{ … }` list)
|
|
24
24
|
// rather than scanned lazily, which is quadratic on a long semicolon-free module.
|
|
@@ -200,7 +200,10 @@ function resolveLocalModule(
|
|
|
200
200
|
const fromAbsolute = join(cwd, from)
|
|
201
201
|
const resolved = Bun.resolveSync(specifier, dirname(fromAbsolute))
|
|
202
202
|
const rel = relative(cwd, resolved).replaceAll("\\", "/")
|
|
203
|
-
|
|
203
|
+
// Outside the app is still the app's code: a workspace package resolves through its node_modules
|
|
204
|
+
// link to its source beside the app (`../../packages/db`), and an installed package may be hoisted
|
|
205
|
+
// above it. Both are walked, as a package in the app's own node_modules is.
|
|
206
|
+
if (isAbsolute(rel)) return undefined
|
|
204
207
|
if (!sources.has(rel) && existsSync(resolved)) {
|
|
205
208
|
try {
|
|
206
209
|
sources.set(rel, readFileSync(resolved, "utf8"))
|
|
@@ -338,7 +341,10 @@ export async function collectCapabilityProjectReport(
|
|
|
338
341
|
const sources = await readSources(cwd)
|
|
339
342
|
const automatic = new Map<string, Set<string>>()
|
|
340
343
|
for (const [file, content] of sources) {
|
|
341
|
-
for (const route of
|
|
344
|
+
for (const route of [
|
|
345
|
+
...scanStaticRouteText(file, content, undefined, sources),
|
|
346
|
+
...scanStaticSocketText(file, content, undefined, sources),
|
|
347
|
+
]) {
|
|
342
348
|
// A path ending in optional params is reflected as one route per form it serves.
|
|
343
349
|
for (const path of staticRouteForms(route.path)) {
|
|
344
350
|
const modules = automatic.get(routeKey(route.method, path)) ?? new Set<string>()
|
|
@@ -703,6 +709,12 @@ export async function runCapabilityCheck(
|
|
|
703
709
|
// Stated on every run, passing or not: a gap is the report's own boundary, not a failure.
|
|
704
710
|
for (const gap of result.report.gaps ?? [])
|
|
705
711
|
console.log(`• known gap, not analyzed: ${gap.path} - ${gap.reason}`)
|
|
712
|
+
for (const route of result.report.routes) {
|
|
713
|
+
if (route.analysis === "declared")
|
|
714
|
+
console.log(
|
|
715
|
+
`• declared by an opaque mount, not analyzed: ${route.method} ${route.path} [${route.declared.join(", ")}]`,
|
|
716
|
+
)
|
|
717
|
+
}
|
|
706
718
|
for (const finding of result.report.findings) console.log(`✖ ${finding.message}`)
|
|
707
719
|
for (const violation of result.violations)
|
|
708
720
|
console.log(
|
package/src/check-diagnostics.ts
CHANGED
|
@@ -10,7 +10,9 @@ import { join } from "node:path"
|
|
|
10
10
|
import type { AssuranceConfig, AssuranceReport } from "@nifrajs/core/assurance"
|
|
11
11
|
import type { CapabilityGap } from "@nifrajs/core/capabilities"
|
|
12
12
|
import type { ProjectEvidenceSnapshot } from "@nifrajs/core/evidence"
|
|
13
|
+
import type { ReflectedHookReport } from "@nifrajs/core/reflection"
|
|
13
14
|
import type { CapabilityProjectReport } from "./capabilities-tool.ts"
|
|
15
|
+
import { scanFetchText, scanStreamText } from "./check-scan.ts"
|
|
14
16
|
import {
|
|
15
17
|
type Diagnostic,
|
|
16
18
|
type DiagnosticSuggestion,
|
|
@@ -20,9 +22,11 @@ import {
|
|
|
20
22
|
import type { DuplicateInstallFinding } from "./doctor.ts"
|
|
21
23
|
import type { PipelineReport } from "./pipeline-report.ts"
|
|
22
24
|
import { freezeProjectFacts, type ProjectFactsSeed } from "./project-facts.ts"
|
|
25
|
+
import { contractVisibilityRule } from "./rules/contract-visibility.ts"
|
|
23
26
|
import { dataGuardRules } from "./rules/data-guard.ts"
|
|
24
27
|
import { parseRulePacks, runRuleRegistry } from "./rules/index.ts"
|
|
25
28
|
import { islandRules } from "./rules/islands.ts"
|
|
29
|
+
import { retiredLayoutRule } from "./rules/layout.ts"
|
|
26
30
|
import { LEGACY_RULE_CODES, LEGACY_RULE_ORDER, legacyRules } from "./rules/legacy.ts"
|
|
27
31
|
import { nanoRules } from "./rules/nano.ts"
|
|
28
32
|
import { pageRules } from "./rules/pages.ts"
|
|
@@ -72,8 +76,9 @@ export type CheckSuggestion = DiagnosticSuggestion
|
|
|
72
76
|
export interface CheckResult {
|
|
73
77
|
readonly ok: boolean
|
|
74
78
|
readonly typecheck: "pass" | "fail" | "skipped"
|
|
75
|
-
/** Why `typecheck` is `"skipped"` (no tsconfig.json, typescript not installed, lints-only mode)
|
|
76
|
-
*
|
|
79
|
+
/** Why `typecheck` is `"skipped"` (no tsconfig.json, typescript not installed, lints-only mode), or
|
|
80
|
+
* why it failed when the compiler itself passed (zoned files outside its program). Echoed in the
|
|
81
|
+
* human report so a skip is never a dim mystery. */
|
|
77
82
|
readonly typecheckNote?: string
|
|
78
83
|
readonly diagnostics: readonly CheckDiagnostic[]
|
|
79
84
|
/** Normalized diagnostics with stable codes for agents and external renderers. */
|
|
@@ -108,6 +113,13 @@ export interface CheckResult {
|
|
|
108
113
|
* the `duplicate-install` diagnostics; this field is what `--json` consumers parse instead.
|
|
109
114
|
*/
|
|
110
115
|
readonly identityPreflight?: IdentityPreflightResult
|
|
116
|
+
/**
|
|
117
|
+
* The hooks each backend route and each prefix's unmatched paths run (`nifra routes --hooks`), read
|
|
118
|
+
* from the `source` of `nifra.assurance.ts`, which check already loads - check runs no other app
|
|
119
|
+
* code. Omitted without that config, and when `maxDiagnostics` caps the output for the MCP transport,
|
|
120
|
+
* where `nifra_routes` with `hooks` returns it.
|
|
121
|
+
*/
|
|
122
|
+
readonly hooks?: ReflectedHookReport
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/** The `identityPreflight` slice of {@link CheckResult}. */
|
|
@@ -172,7 +184,7 @@ const MAX_IGNORE_GLOB_ALTERNATIVES = 64
|
|
|
172
184
|
* The matcher supports the portable glob forms users expect here: `*`, `?`, `**`, character
|
|
173
185
|
* classes, and brace alternatives.
|
|
174
186
|
*/
|
|
175
|
-
function safeIgnoreGlobMatch(pattern: string, file: string): boolean {
|
|
187
|
+
export function safeIgnoreGlobMatch(pattern: string, file: string): boolean {
|
|
176
188
|
if (pattern.length === 0 || pattern.length > MAX_IGNORE_GLOB_LENGTH) return false
|
|
177
189
|
for (const alternative of expandIgnoreGlobBraces(pattern)) {
|
|
178
190
|
if (matchIgnoreGlobPath(alternative, file)) return true
|
|
@@ -356,6 +368,7 @@ export interface CheckTypecheckResult {
|
|
|
356
368
|
readonly note?: string
|
|
357
369
|
readonly output?: string
|
|
358
370
|
readonly missingTypeScript?: boolean
|
|
371
|
+
readonly outsideProgram?: readonly string[]
|
|
359
372
|
}
|
|
360
373
|
|
|
361
374
|
export interface CheckAnalysisInput {
|
|
@@ -367,6 +380,19 @@ export interface CheckDiagnosticsOptions {
|
|
|
367
380
|
readonly assurance?: CheckAssuranceContext
|
|
368
381
|
}
|
|
369
382
|
|
|
383
|
+
/**
|
|
384
|
+
* The prefixes of the mounts the assurance source declares `opaque` (a better-auth handler nifra
|
|
385
|
+
* cannot read): no typed client covers them, so a hand-written fetch into one is deliberate, exactly
|
|
386
|
+
* like a `nifra.check.json` `externalMounts` entry. A mount without that declaration stays checked.
|
|
387
|
+
*/
|
|
388
|
+
async function mountPrefixes(source: unknown): Promise<readonly string[]> {
|
|
389
|
+
if (source === undefined) return []
|
|
390
|
+
const { reflectMounts } = await import("@nifrajs/core/reflection")
|
|
391
|
+
return reflectMounts(source).flatMap((mount) =>
|
|
392
|
+
mount.opaque === undefined || mount.path === "/*" ? [] : [mount.path.slice(0, -"/*".length)],
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
|
|
370
396
|
export async function collectCheckDiagnostics(
|
|
371
397
|
cwd: string,
|
|
372
398
|
scan: CheckAnalysisInput,
|
|
@@ -422,6 +448,31 @@ export async function collectCheckDiagnostics(
|
|
|
422
448
|
rulePacks: applicationRulePacks,
|
|
423
449
|
},
|
|
424
450
|
}
|
|
451
|
+
const configuredMounts = factsSeed.policies.checkConfig.externalMounts
|
|
452
|
+
const appMounts = (await mountPrefixes(loadedPolicy?.config?.source)).filter(
|
|
453
|
+
(prefix) => !configuredMounts.includes(prefix),
|
|
454
|
+
)
|
|
455
|
+
if (appMounts.length > 0) {
|
|
456
|
+
const externalMounts = [...configuredMounts, ...appMounts]
|
|
457
|
+
const files = factsSeed.source.files.map((file) => ({
|
|
458
|
+
file,
|
|
459
|
+
content: factsSeed.source.read(file) ?? "",
|
|
460
|
+
}))
|
|
461
|
+
factsSeed = {
|
|
462
|
+
...factsSeed,
|
|
463
|
+
policies: {
|
|
464
|
+
...factsSeed.policies,
|
|
465
|
+
checkConfig: { ...factsSeed.policies.checkConfig, externalMounts },
|
|
466
|
+
},
|
|
467
|
+
sourceFindings: {
|
|
468
|
+
...factsSeed.sourceFindings,
|
|
469
|
+
fetches: files.flatMap(({ file, content }) => scanFetchText(file, content, externalMounts)),
|
|
470
|
+
streams: files.flatMap(({ file, content }) =>
|
|
471
|
+
scanStreamText(file, content, externalMounts),
|
|
472
|
+
),
|
|
473
|
+
},
|
|
474
|
+
}
|
|
475
|
+
}
|
|
425
476
|
const projectFacts = freezeProjectFacts(factsSeed)
|
|
426
477
|
const ruleContext = {
|
|
427
478
|
root: cwd,
|
|
@@ -433,9 +484,11 @@ export async function collectCheckDiagnostics(
|
|
|
433
484
|
}
|
|
434
485
|
|
|
435
486
|
const builtInRules = [
|
|
487
|
+
retiredLayoutRule,
|
|
436
488
|
...legacyRules,
|
|
437
489
|
...securityRules,
|
|
438
490
|
...routeRules,
|
|
491
|
+
contractVisibilityRule,
|
|
439
492
|
...pageRules,
|
|
440
493
|
...zoneRules,
|
|
441
494
|
...dataGuardRules,
|
|
@@ -514,7 +567,7 @@ export async function collectCheckDiagnostics(
|
|
|
514
567
|
if (knownLegacyCodes.has(item.code)) continue
|
|
515
568
|
compatibilityRows.push({
|
|
516
569
|
rule: item.code,
|
|
517
|
-
severity: item.severity === "
|
|
570
|
+
severity: item.severity === "warn" ? "warning" : item.severity,
|
|
518
571
|
code: item.code,
|
|
519
572
|
...(item.file === undefined ? {} : { file: item.file }),
|
|
520
573
|
...(item.line === undefined ? {} : { line: item.line }),
|
|
@@ -583,17 +636,27 @@ export async function collectCheckDiagnostics(
|
|
|
583
636
|
shown.length < total ? shown.length + nonLegacyStructuredCount : finalStructured.length
|
|
584
637
|
|
|
585
638
|
const doctor = projectFacts.packages.doctor
|
|
639
|
+
const outsideProgram = projectFacts.check.typecheck.outsideProgram?.length ?? 0
|
|
586
640
|
const knownGaps = projectFacts.policies.capability?.report.gaps ?? []
|
|
641
|
+
const hookSource = projectFacts.policies.assurance?.config?.source
|
|
642
|
+
const hooks =
|
|
643
|
+
hookSource === undefined || opts.maxDiagnostics !== undefined
|
|
644
|
+
? undefined
|
|
645
|
+
: (await import("@nifrajs/core/reflection")).reflectHooks(hookSource)
|
|
587
646
|
const result: CheckResult = {
|
|
588
647
|
ok: !finalDiagnostics.some((value) => value.severity === "error"),
|
|
589
|
-
typecheck: projectFacts.check.typecheck.ran
|
|
590
|
-
?
|
|
648
|
+
typecheck: !projectFacts.check.typecheck.ran
|
|
649
|
+
? "skipped"
|
|
650
|
+
: projectFacts.check.typecheck.ok && outsideProgram === 0
|
|
591
651
|
? "pass"
|
|
592
|
-
: "fail"
|
|
593
|
-
: "skipped",
|
|
652
|
+
: "fail",
|
|
594
653
|
...(!projectFacts.check.typecheck.ran && projectFacts.check.typecheck.note !== undefined
|
|
595
654
|
? { typecheckNote: projectFacts.check.typecheck.note }
|
|
596
|
-
:
|
|
655
|
+
: outsideProgram > 0
|
|
656
|
+
? {
|
|
657
|
+
typecheckNote: `${outsideProgram} file(s) in zone folders are outside tsc's program, so the typecheck never read them`,
|
|
658
|
+
}
|
|
659
|
+
: {}),
|
|
597
660
|
diagnostics: shown,
|
|
598
661
|
...(projectFacts.pipeline !== undefined ? { pipeline: projectFacts.pipeline } : {}),
|
|
599
662
|
...(doctor.ran
|
|
@@ -610,6 +673,7 @@ export async function collectCheckDiagnostics(
|
|
|
610
673
|
? {}
|
|
611
674
|
: { externalMounts: checkConfig.externalMounts }),
|
|
612
675
|
...(knownGaps.length === 0 ? {} : { knownGaps }),
|
|
676
|
+
...(hooks === undefined ? {} : { hooks }),
|
|
613
677
|
...(Object.keys(checkConfig.rules).length === 0 ? {} : { ruleOverrides: checkConfig.rules }),
|
|
614
678
|
...(shown.length < total ? { truncated: { shown: shown.length, total } } : {}),
|
|
615
679
|
}
|