@nifrajs/cli 3.3.0 → 4.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 +42 -3
- package/dist/app-files.d.ts +11 -0
- package/dist/app-files.d.ts.map +1 -0
- package/dist/app-files.js +34 -0
- package/dist/app-files.js.map +1 -0
- package/dist/assure-hydration.d.ts +7 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +128 -43
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +16 -2
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts +5 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +32 -10
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/cdn-check.d.ts +41 -0
- package/dist/cdn-check.d.ts.map +1 -0
- package/dist/cdn-check.js +207 -0
- package/dist/cdn-check.js.map +1 -0
- package/dist/check-diagnostics.d.ts +7 -15
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +162 -713
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +58 -7
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +323 -62
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +1 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +145 -54
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +42 -16
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +306 -87
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +60 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +298 -33
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.d.ts +8 -0
- package/dist/config-target.d.ts.map +1 -0
- package/dist/config-target.js +45 -0
- package/dist/config-target.js.map +1 -0
- package/dist/contracts.d.ts +3 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +56 -16
- package/dist/contracts.js.map +1 -1
- package/dist/db-audit.d.ts +37 -0
- package/dist/db-audit.d.ts.map +1 -0
- package/dist/db-audit.js +99 -0
- package/dist/db-audit.js.map +1 -0
- package/dist/db-child.d.ts +64 -0
- package/dist/db-child.d.ts.map +1 -0
- package/dist/db-child.js +213 -0
- package/dist/db-child.js.map +1 -0
- package/dist/db-config.d.ts +60 -0
- package/dist/db-config.d.ts.map +1 -0
- package/dist/db-config.js +176 -0
- package/dist/db-config.js.map +1 -0
- package/dist/db-tool.d.ts +84 -0
- package/dist/db-tool.d.ts.map +1 -0
- package/dist/db-tool.js +537 -0
- package/dist/db-tool.js.map +1 -0
- package/dist/dev-bun-config.d.ts +20 -13
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +98 -41
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +106 -0
- package/dist/dev-feed-tool.d.ts.map +1 -0
- package/dist/dev-feed-tool.js +713 -0
- package/dist/dev-feed-tool.js.map +1 -0
- package/dist/dev-server-client.d.ts +67 -0
- package/dist/dev-server-client.d.ts.map +1 -0
- package/dist/dev-server-client.js +195 -0
- package/dist/dev-server-client.js.map +1 -0
- package/dist/diagnostics.d.ts +86 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +85 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/diff-tool.d.ts +3 -3
- package/dist/diff-tool.d.ts.map +1 -1
- package/dist/diff-tool.js +6 -5
- package/dist/diff-tool.js.map +1 -1
- package/dist/docs-search.d.ts.map +1 -1
- package/dist/docs-search.js +12 -4
- package/dist/docs-search.js.map +1 -1
- package/dist/doctor.d.ts +17 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +76 -15
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts +15 -0
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +73 -1
- package/dist/env-file.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +41 -21
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.js +5 -5
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/i18n-check.d.ts +16 -0
- package/dist/i18n-check.d.ts.map +1 -0
- package/dist/i18n-check.js +154 -0
- package/dist/i18n-check.js.map +1 -0
- package/dist/init-agents.d.ts +49 -13
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +239 -34
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/code-unit-order.d.ts +4 -0
- package/dist/internal/code-unit-order.d.ts.map +1 -0
- package/dist/internal/code-unit-order.js +6 -0
- package/dist/internal/code-unit-order.js.map +1 -0
- package/dist/internal/script-kind.d.ts +7 -0
- package/dist/internal/script-kind.d.ts.map +1 -0
- package/dist/internal/script-kind.js +12 -0
- package/dist/internal/script-kind.js.map +1 -0
- package/dist/internal/source-facts.d.ts +5 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +61 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts +49 -24
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +507 -67
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/introspect.d.ts +6 -4
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +93 -74
- package/dist/introspect.js.map +1 -1
- package/dist/learn.js +3 -3
- package/dist/learn.js.map +1 -1
- package/dist/levels-tool.d.ts +10 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +33 -3
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +71 -16
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +78 -18
- package/dist/load.js.map +1 -1
- package/dist/manifest-tool.d.ts.map +1 -1
- package/dist/manifest-tool.js +3 -2
- package/dist/manifest-tool.js.map +1 -1
- package/dist/mcp-app-tool.d.ts.map +1 -1
- package/dist/mcp-app-tool.js +2 -0
- package/dist/mcp-app-tool.js.map +1 -1
- package/dist/mcp-context.d.ts.map +1 -1
- package/dist/mcp-context.js +5 -6
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +57 -0
- package/dist/mcp-delegate.d.ts.map +1 -0
- package/dist/mcp-delegate.js +130 -0
- package/dist/mcp-delegate.js.map +1 -0
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +23 -5
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-exec.d.ts +3 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +263 -131
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +20 -5
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-io.d.ts +26 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +113 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts +48 -0
- package/dist/mcp-isolate.d.ts.map +1 -0
- package/dist/mcp-isolate.js +222 -0
- package/dist/mcp-isolate.js.map +1 -0
- package/dist/mcp-path.d.ts +10 -0
- package/dist/mcp-path.d.ts.map +1 -0
- package/dist/mcp-path.js +51 -0
- package/dist/mcp-path.js.map +1 -0
- package/dist/mcp-project-child.d.ts +74 -0
- package/dist/mcp-project-child.d.ts.map +1 -0
- package/dist/mcp-project-child.js +130 -0
- package/dist/mcp-project-child.js.map +1 -0
- package/dist/mcp-reflect.d.ts.map +1 -1
- package/dist/mcp-reflect.js +2 -2
- package/dist/mcp-reflect.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +64 -45
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.d.ts +37 -9
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +124 -25
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts +18 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +159 -55
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-ws.js +4 -1
- package/dist/mcp-ws.js.map +1 -1
- package/dist/mcp.d.ts +18 -5
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +165 -82
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +44 -0
- package/dist/migrate-layout.d.ts.map +1 -0
- package/dist/migrate-layout.js +982 -0
- package/dist/migrate-layout.js.map +1 -0
- package/dist/openapi-tool.d.ts +2 -2
- package/dist/openapi-tool.d.ts.map +1 -1
- package/dist/openapi-tool.js.map +1 -1
- package/dist/openapi-types.d.ts +2 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +240 -12
- package/dist/openapi-types.js.map +1 -1
- package/dist/pipeline-report.d.ts +3 -2
- package/dist/pipeline-report.d.ts.map +1 -1
- package/dist/pipeline-report.js +19 -16
- package/dist/pipeline-report.js.map +1 -1
- package/dist/port.d.ts +5 -4
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +46 -29
- package/dist/port.js.map +1 -1
- package/dist/project-facts.d.ts +28 -4
- package/dist/project-facts.d.ts.map +1 -1
- package/dist/project-facts.js +12 -2
- package/dist/project-facts.js.map +1 -1
- package/dist/recipes/4.0.0.d.ts +9 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -0
- package/dist/recipes/4.0.0.js +34 -0
- package/dist/recipes/4.0.0.js.map +1 -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/release-verification.d.ts +11 -1
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +47 -4
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts +21 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +823 -0
- package/dist/review.js.map +1 -0
- package/dist/route-types.d.ts +28 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +106 -0
- package/dist/route-types.js.map +1 -0
- package/dist/rules/codes.d.ts +9 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +9 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/data-guard.d.ts +12 -0
- package/dist/rules/data-guard.d.ts.map +1 -0
- package/dist/rules/data-guard.js +213 -0
- package/dist/rules/data-guard.js.map +1 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +17 -5
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +7 -4
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/legacy.d.ts +3 -1
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +829 -34
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/nano.d.ts.map +1 -1
- package/dist/rules/nano.js +15 -6
- package/dist/rules/nano.js.map +1 -1
- package/dist/rules/pages.d.ts +15 -0
- package/dist/rules/pages.d.ts.map +1 -0
- package/dist/rules/pages.js +88 -0
- package/dist/rules/pages.js.map +1 -0
- package/dist/rules/routes.d.ts +11 -0
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +180 -2
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/secrets.d.ts +10 -0
- package/dist/rules/secrets.d.ts.map +1 -0
- package/dist/rules/secrets.js +169 -0
- package/dist/rules/secrets.js.map +1 -0
- package/dist/rules/security.d.ts +7 -0
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +171 -65
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/typescript.d.ts +16 -0
- package/dist/rules/typescript.d.ts.map +1 -0
- package/dist/rules/typescript.js +59 -0
- package/dist/rules/typescript.js.map +1 -0
- package/dist/rules/zones.d.ts +17 -0
- package/dist/rules/zones.d.ts.map +1 -0
- package/dist/rules/zones.js +174 -0
- package/dist/rules/zones.js.map +1 -0
- package/dist/scaffold.d.ts +25 -12
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +154 -90
- package/dist/scaffold.js.map +1 -1
- package/dist/sdk.d.ts +17 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +941 -153
- package/dist/sdk.js.map +1 -1
- package/dist/search-terms.d.ts +2 -0
- package/dist/search-terms.d.ts.map +1 -1
- package/dist/search-terms.js +23 -8
- package/dist/search-terms.js.map +1 -1
- package/dist/smoke.d.ts +79 -0
- package/dist/smoke.d.ts.map +1 -0
- package/dist/smoke.js +494 -0
- package/dist/smoke.js.map +1 -0
- package/dist/sync-manifest.d.ts.map +1 -1
- package/dist/sync-manifest.js +2 -1
- package/dist/sync-manifest.js.map +1 -1
- package/dist/sync-routes.d.ts +4 -3
- package/dist/sync-routes.d.ts.map +1 -1
- package/dist/sync-routes.js +4 -3
- package/dist/sync-routes.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +30 -11
- package/dist/test-tool.js.map +1 -1
- package/dist/types-search.d.ts.map +1 -1
- package/dist/types-search.js +11 -5
- package/dist/types-search.js.map +1 -1
- package/dist/upgrade.d.ts +36 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +167 -29
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +8 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/verification.d.ts.map +1 -1
- package/dist/verification.js +45 -12
- package/dist/verification.js.map +1 -1
- package/dist/web-app-options.d.ts +19 -0
- package/dist/web-app-options.d.ts.map +1 -0
- package/dist/web-app-options.js +49 -0
- package/dist/web-app-options.js.map +1 -0
- package/dist/work-graph.d.ts +3 -0
- package/dist/work-graph.d.ts.map +1 -1
- package/dist/work-graph.js +33 -16
- package/dist/work-graph.js.map +1 -1
- package/docs/examples.json +185 -29
- package/docs/llms-full.txt +4123 -548
- package/docs/types.json +14391 -10060
- package/package.json +19 -11
- package/src/app-files.ts +40 -0
- package/src/assure-hydration.ts +139 -46
- package/src/assure.ts +17 -2
- package/src/capabilities-tool.ts +35 -9
- package/src/cdn-check.ts +268 -0
- package/src/check-diagnostics.ts +199 -797
- package/src/check-scan.ts +394 -63
- package/src/check.ts +146 -58
- package/src/cli.ts +347 -92
- package/src/command-catalog.ts +407 -45
- package/src/config-target.ts +47 -0
- package/src/contracts.ts +66 -15
- package/src/db-audit.ts +128 -0
- package/src/db-child.ts +285 -0
- package/src/db-config.ts +224 -0
- package/src/db-tool.ts +690 -0
- package/src/dev-bun-config.ts +116 -40
- package/src/dev-feed-tool.ts +912 -0
- package/src/dev-server-client.ts +267 -0
- package/src/diagnostics.ts +179 -0
- package/src/diff-tool.ts +6 -5
- package/src/docs-search.ts +10 -3
- package/src/doctor.ts +98 -15
- package/src/env-file.ts +78 -1
- package/src/fix-recipes.ts +44 -31
- package/src/frontend-guidance.ts +5 -5
- package/src/i18n-check.ts +179 -0
- package/src/init-agents.ts +301 -38
- package/src/internal/code-unit-order.ts +5 -0
- package/src/internal/script-kind.ts +11 -0
- package/src/internal/source-facts.ts +96 -22
- package/src/internal/typescript-import.ts +663 -68
- package/src/introspect.ts +93 -82
- package/src/learn.ts +3 -3
- package/src/levels-tool.ts +47 -2
- package/src/load.ts +144 -32
- package/src/manifest-tool.ts +3 -2
- package/src/mcp-app-tool.ts +2 -0
- package/src/mcp-context.ts +5 -7
- package/src/mcp-delegate.ts +162 -0
- package/src/mcp-docs-tools.ts +23 -5
- package/src/mcp-exec.ts +301 -161
- package/src/mcp-http.ts +22 -5
- package/src/mcp-io.ts +130 -0
- package/src/mcp-isolate.ts +287 -0
- package/src/mcp-path.ts +50 -0
- package/src/mcp-project-child.ts +182 -0
- package/src/mcp-reflect.ts +3 -2
- package/src/mcp-render.ts +72 -42
- package/src/mcp-root.ts +130 -24
- package/src/mcp-run.ts +190 -56
- package/src/mcp-ws.ts +4 -1
- package/src/mcp.ts +193 -91
- package/src/migrate-layout.ts +1121 -0
- package/src/openapi-tool.ts +7 -3
- package/src/openapi-types.ts +315 -13
- package/src/pipeline-report.ts +22 -18
- package/src/port.ts +53 -30
- package/src/project-facts.ts +42 -8
- package/src/recipes/4.0.0.ts +35 -0
- package/src/recipes/index.ts +2 -0
- package/src/release-verification.ts +74 -5
- package/src/review.ts +988 -0
- package/src/route-types.ts +133 -0
- package/src/rules/codes.ts +9 -0
- package/src/rules/data-guard.ts +230 -0
- package/src/rules/index.ts +18 -5
- package/src/rules/islands.ts +12 -4
- package/src/rules/legacy.ts +947 -35
- package/src/rules/nano.ts +18 -6
- package/src/rules/pages.ts +99 -0
- package/src/rules/routes.ts +181 -2
- package/src/rules/secrets.ts +174 -0
- package/src/rules/security.ts +198 -70
- package/src/rules/typescript.ts +77 -0
- package/src/rules/zones.ts +195 -0
- package/src/scaffold.ts +175 -98
- package/src/sdk.ts +1215 -158
- package/src/search-terms.ts +24 -7
- package/src/smoke.ts +607 -0
- package/src/sync-manifest.ts +2 -1
- package/src/sync-routes.ts +4 -3
- package/src/test-tool.ts +32 -11
- package/src/types-search.ts +11 -4
- package/src/upgrade.ts +205 -25
- package/src/verification-plan.ts +27 -0
- package/src/verification.ts +50 -12
- package/src/web-app-options.ts +57 -0
- package/src/work-graph.ts +40 -16
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the running `nifra dev` server a tool should read, and reads its agent feed.
|
|
3
|
+
*
|
|
4
|
+
* A dev server writes `.nifra/dev-server.json` (owner-only) with its port and a per-run token. A
|
|
5
|
+
* record alone proves nothing - the process may have died and the port been reused - so a server
|
|
6
|
+
* counts as live only after it answers the identity endpoint with the record's own pid and root.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, readdirSync } from "node:fs"
|
|
10
|
+
import { join, resolve } from "node:path"
|
|
11
|
+
import {
|
|
12
|
+
DEV_FEED_HEADER,
|
|
13
|
+
DEV_FEED_PATHS,
|
|
14
|
+
DEV_SERVER_LOG_FILE,
|
|
15
|
+
DEV_SERVER_RECORD_FILE,
|
|
16
|
+
DEV_TOKEN_HEADER,
|
|
17
|
+
type DevPipeline,
|
|
18
|
+
type DevServerIdentity,
|
|
19
|
+
type DevServerRecord,
|
|
20
|
+
isProcessAlive,
|
|
21
|
+
readDevServerRecord,
|
|
22
|
+
} from "@nifrajs/web/dev-feed"
|
|
23
|
+
import { LOCAL_TOOL_FETCH_TIMEOUT_MS, readBoundedResponse, validateLocalPort } from "./mcp-io.ts"
|
|
24
|
+
|
|
25
|
+
export interface LiveDevServer {
|
|
26
|
+
readonly root: string
|
|
27
|
+
readonly port: number
|
|
28
|
+
readonly origin: string
|
|
29
|
+
readonly pipeline: DevPipeline
|
|
30
|
+
readonly pid: number
|
|
31
|
+
readonly startedAt: string
|
|
32
|
+
readonly token: string
|
|
33
|
+
readonly identity: DevServerIdentity
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A dev server whose record survived it: it crashed or was killed before it could clean up. */
|
|
37
|
+
export interface DeadDevServer {
|
|
38
|
+
readonly root: string
|
|
39
|
+
readonly port: number
|
|
40
|
+
readonly pid: number
|
|
41
|
+
readonly startedAt: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type DevServerLookup =
|
|
45
|
+
| { readonly status: "live"; readonly server: LiveDevServer }
|
|
46
|
+
/** An explicit port no record under the project names: reachable only through token-free paths. */
|
|
47
|
+
| { readonly status: "unverified"; readonly port: number; readonly origin: string }
|
|
48
|
+
| {
|
|
49
|
+
readonly status: "ambiguous"
|
|
50
|
+
readonly servers: readonly Pick<LiveDevServer, "root" | "port" | "pipeline">[]
|
|
51
|
+
}
|
|
52
|
+
| {
|
|
53
|
+
readonly status: "down"
|
|
54
|
+
/** Project roots holding a persisted feed from an earlier run, nearest first. */
|
|
55
|
+
readonly persisted: readonly string[]
|
|
56
|
+
readonly dead: readonly DeadDevServer[]
|
|
57
|
+
/** Servers whose record and process exist but which did not answer as themselves. */
|
|
58
|
+
readonly unreachable: readonly {
|
|
59
|
+
readonly root: string
|
|
60
|
+
readonly port: number
|
|
61
|
+
readonly reason: string
|
|
62
|
+
}[]
|
|
63
|
+
}
|
|
64
|
+
| { readonly status: "invalid-port" }
|
|
65
|
+
|
|
66
|
+
export interface FindDevServerOptions {
|
|
67
|
+
readonly port?: number | undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Where a workspace keeps its apps. One level only: the scan runs on every tool call.
|
|
71
|
+
const SCAN_PARENTS = [".", "apps", "packages", "examples"] as const
|
|
72
|
+
const MAX_SCANNED_ROOTS = 512
|
|
73
|
+
|
|
74
|
+
function candidateRoots(cwd: string): string[] {
|
|
75
|
+
const roots = [cwd]
|
|
76
|
+
for (const parent of SCAN_PARENTS) {
|
|
77
|
+
const base = join(cwd, parent)
|
|
78
|
+
let names: string[]
|
|
79
|
+
try {
|
|
80
|
+
names = readdirSync(base, { withFileTypes: true })
|
|
81
|
+
.filter((entry) => entry.isDirectory())
|
|
82
|
+
.map((entry) => entry.name)
|
|
83
|
+
.filter((name) => !name.startsWith(".") && name !== "node_modules")
|
|
84
|
+
.sort()
|
|
85
|
+
} catch {
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
for (const name of names) {
|
|
89
|
+
if (roots.length >= MAX_SCANNED_ROOTS) return roots
|
|
90
|
+
const root = join(base, name)
|
|
91
|
+
if (!roots.includes(root)) roots.push(root)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return roots
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const originOf = (port: number): string => `http://127.0.0.1:${port}`
|
|
98
|
+
|
|
99
|
+
function isIdentity(value: unknown): value is DevServerIdentity {
|
|
100
|
+
if (typeof value !== "object" || value === null) return false
|
|
101
|
+
return (
|
|
102
|
+
"pid" in value &&
|
|
103
|
+
typeof value.pid === "number" &&
|
|
104
|
+
"root" in value &&
|
|
105
|
+
typeof value.root === "string" &&
|
|
106
|
+
"port" in value &&
|
|
107
|
+
typeof value.port === "number" &&
|
|
108
|
+
"cursor" in value &&
|
|
109
|
+
typeof value.cursor === "number"
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
type Verified =
|
|
114
|
+
| { readonly ok: true; readonly server: LiveDevServer }
|
|
115
|
+
| { readonly ok: false; readonly reason: string }
|
|
116
|
+
|
|
117
|
+
async function verify(record: DevServerRecord, signal?: AbortSignal): Promise<Verified> {
|
|
118
|
+
const origin = originOf(record.port)
|
|
119
|
+
let body: unknown
|
|
120
|
+
try {
|
|
121
|
+
const response = await fetch(`${origin}${DEV_FEED_PATHS.identity}`, {
|
|
122
|
+
headers: { [DEV_TOKEN_HEADER]: record.token },
|
|
123
|
+
signal: anySignal(signal),
|
|
124
|
+
})
|
|
125
|
+
if (response.headers.get(DEV_FEED_HEADER) !== "true")
|
|
126
|
+
return { ok: false, reason: `port ${record.port} is not a nifra dev server` }
|
|
127
|
+
if (!response.ok) return { ok: false, reason: `identity check returned ${response.status}` }
|
|
128
|
+
body = JSON.parse(await readBoundedResponse(response))
|
|
129
|
+
} catch (cause) {
|
|
130
|
+
return { ok: false, reason: cause instanceof Error ? cause.message : String(cause) }
|
|
131
|
+
}
|
|
132
|
+
// A recycled port can host a different nifra server; its pid and root give it away.
|
|
133
|
+
if (!isIdentity(body) || body.pid !== record.pid || resolve(body.root) !== resolve(record.root))
|
|
134
|
+
return { ok: false, reason: `port ${record.port} now belongs to another server` }
|
|
135
|
+
return {
|
|
136
|
+
ok: true,
|
|
137
|
+
server: {
|
|
138
|
+
root: record.root,
|
|
139
|
+
port: record.port,
|
|
140
|
+
origin,
|
|
141
|
+
pipeline: record.pipeline,
|
|
142
|
+
pid: record.pid,
|
|
143
|
+
startedAt: record.startedAt,
|
|
144
|
+
token: record.token,
|
|
145
|
+
identity: body,
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function anySignal(signal: AbortSignal | undefined): AbortSignal {
|
|
151
|
+
const timeout = AbortSignal.timeout(LOCAL_TOOL_FETCH_TIMEOUT_MS)
|
|
152
|
+
return signal === undefined ? timeout : AbortSignal.any([signal, timeout])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The dev server for the project at `cwd`: its own record first, else the one live server among the
|
|
157
|
+
* workspace's apps. An explicit `port` picks among them, and still works when no record names it.
|
|
158
|
+
*/
|
|
159
|
+
export async function findDevServer(
|
|
160
|
+
cwd: string,
|
|
161
|
+
options: FindDevServerOptions = {},
|
|
162
|
+
signal?: AbortSignal,
|
|
163
|
+
): Promise<DevServerLookup> {
|
|
164
|
+
let port: number | undefined
|
|
165
|
+
if (options.port !== undefined) {
|
|
166
|
+
port = validateLocalPort(options.port)
|
|
167
|
+
if (port === undefined) return { status: "invalid-port" }
|
|
168
|
+
}
|
|
169
|
+
// The project's own live server wins outright, whatever else the workspace runs.
|
|
170
|
+
const own = readDevServerRecord(cwd)
|
|
171
|
+
if (own !== undefined && (port === undefined || own.port === port) && isProcessAlive(own.pid)) {
|
|
172
|
+
const result = await verify(own, signal)
|
|
173
|
+
if (result.ok) return { status: "live", server: result.server }
|
|
174
|
+
}
|
|
175
|
+
const roots = candidateRoots(cwd)
|
|
176
|
+
const records: DevServerRecord[] = []
|
|
177
|
+
const dead: DeadDevServer[] = []
|
|
178
|
+
for (const root of roots) {
|
|
179
|
+
if (!existsSync(join(root, DEV_SERVER_RECORD_FILE))) continue
|
|
180
|
+
const record = readDevServerRecord(root)
|
|
181
|
+
if (record === undefined) continue
|
|
182
|
+
if (port !== undefined && record.port !== port) continue
|
|
183
|
+
if (isProcessAlive(record.pid)) records.push(record)
|
|
184
|
+
else dead.push({ root, port: record.port, pid: record.pid, startedAt: record.startedAt })
|
|
185
|
+
}
|
|
186
|
+
const checked = await Promise.all(records.map((record) => verify(record, signal)))
|
|
187
|
+
const live: LiveDevServer[] = []
|
|
188
|
+
const unreachable: { root: string; port: number; reason: string }[] = []
|
|
189
|
+
checked.forEach((result, index) => {
|
|
190
|
+
const record = records[index]
|
|
191
|
+
if (record === undefined) return
|
|
192
|
+
if (result.ok) live.push(result.server)
|
|
193
|
+
else unreachable.push({ root: record.root, port: record.port, reason: result.reason })
|
|
194
|
+
})
|
|
195
|
+
const [first] = live
|
|
196
|
+
if (first !== undefined && live.length === 1) return { status: "live", server: first }
|
|
197
|
+
if (live.length > 1) {
|
|
198
|
+
return {
|
|
199
|
+
status: "ambiguous",
|
|
200
|
+
servers: live.map(({ root, port: livePort, pipeline }) => ({
|
|
201
|
+
root,
|
|
202
|
+
port: livePort,
|
|
203
|
+
pipeline,
|
|
204
|
+
})),
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (port !== undefined && unreachable.length === 0)
|
|
208
|
+
return { status: "unverified", port, origin: originOf(port) }
|
|
209
|
+
const persisted = roots.filter((root) => existsSync(join(root, DEV_SERVER_LOG_FILE)))
|
|
210
|
+
return { status: "down", persisted, dead, unreachable }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export type FeedQuery = Readonly<
|
|
214
|
+
Record<string, string | number | boolean | readonly string[] | undefined>
|
|
215
|
+
>
|
|
216
|
+
|
|
217
|
+
/** GET one feed endpoint as the authenticated agent. Throws when the server does not answer with JSON. */
|
|
218
|
+
export async function readDevFeed(
|
|
219
|
+
server: LiveDevServer,
|
|
220
|
+
path: string,
|
|
221
|
+
query: FeedQuery = {},
|
|
222
|
+
signal?: AbortSignal,
|
|
223
|
+
): Promise<unknown> {
|
|
224
|
+
const url = new URL(path, server.origin)
|
|
225
|
+
for (const [name, value] of Object.entries(query)) {
|
|
226
|
+
if (value === undefined) continue
|
|
227
|
+
url.searchParams.set(name, Array.isArray(value) ? value.join(",") : String(value))
|
|
228
|
+
}
|
|
229
|
+
const response = await fetch(url, {
|
|
230
|
+
headers: { [DEV_TOKEN_HEADER]: server.token },
|
|
231
|
+
signal: anySignal(signal),
|
|
232
|
+
})
|
|
233
|
+
if (response.headers.get(DEV_FEED_HEADER) !== "true")
|
|
234
|
+
throw new Error(`${server.origin} did not answer as a nifra dev server`)
|
|
235
|
+
const text = await readBoundedResponse(response)
|
|
236
|
+
if (!response.ok) throw new Error(`${path} returned ${response.status}: ${text.slice(0, 200)}`)
|
|
237
|
+
return JSON.parse(text)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** One line telling a caller how to get past a lookup that did not yield a single live server. */
|
|
241
|
+
export function describeLookup(
|
|
242
|
+
lookup: Exclude<DevServerLookup, { status: "live" }>,
|
|
243
|
+
cwd: string,
|
|
244
|
+
): string {
|
|
245
|
+
switch (lookup.status) {
|
|
246
|
+
case "invalid-port":
|
|
247
|
+
return "port must be an integer from 1 to 65535."
|
|
248
|
+
case "unverified":
|
|
249
|
+
return `No ${DEV_SERVER_RECORD_FILE} under ${cwd} names port ${lookup.port}. Pass \`dir\` (the project that server runs) so its token can be read.`
|
|
250
|
+
case "ambiguous":
|
|
251
|
+
return `${lookup.servers.length} dev servers are running: ${lookup.servers.map((s) => `${s.root} (:${s.port})`).join(", ")}. Pass \`dir\` or \`port\` to pick one.`
|
|
252
|
+
case "down": {
|
|
253
|
+
const parts: string[] = []
|
|
254
|
+
for (const server of lookup.dead)
|
|
255
|
+
parts.push(
|
|
256
|
+
`the dev server for ${server.root} (:${server.port}, pid ${server.pid}) is gone without cleaning up - it crashed or was killed`,
|
|
257
|
+
)
|
|
258
|
+
for (const server of lookup.unreachable)
|
|
259
|
+
parts.push(
|
|
260
|
+
`the dev server for ${server.root} (:${server.port}) did not answer: ${server.reason}`,
|
|
261
|
+
)
|
|
262
|
+
if (parts.length === 0)
|
|
263
|
+
parts.push(`no nifra dev server is running for ${cwd}; start one with \`nifra dev\``)
|
|
264
|
+
return `${parts.join("; ")}.`
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
package/src/diagnostics.ts
CHANGED
|
@@ -7,6 +7,32 @@ export interface DiagnosticFix {
|
|
|
7
7
|
readonly command?: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The richer compatibility view used by the original `nifra check` renderer. It is deliberately
|
|
12
|
+
* kept out of the enumerable diagnostic shape: SARIF, MCP structured output, and JSON consumers get
|
|
13
|
+
* the small stable diagnostic contract, while the legacy text view can still explain an exact edit.
|
|
14
|
+
*/
|
|
15
|
+
export interface DiagnosticCompatibility {
|
|
16
|
+
/** The pre-registry rule name used by the human/legacy check result. */
|
|
17
|
+
readonly rule: string
|
|
18
|
+
/** The old human-facing fix text, when the rule had one. */
|
|
19
|
+
readonly fix?: string
|
|
20
|
+
/** A richer legacy suggestion (diff, command, or manual steps). */
|
|
21
|
+
readonly suggestion?: DiagnosticSuggestion
|
|
22
|
+
/** The import path evidence used by the legacy server-only-import view. */
|
|
23
|
+
readonly chain?: readonly string[]
|
|
24
|
+
/** Preserve the old optional `CheckDiagnostic.code` field exactly where it existed. */
|
|
25
|
+
readonly includeCode?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DiagnosticSuggestion {
|
|
29
|
+
readonly kind: "edit" | "command" | "manual"
|
|
30
|
+
readonly title: string
|
|
31
|
+
readonly diff?: string
|
|
32
|
+
readonly command?: readonly string[]
|
|
33
|
+
readonly steps?: readonly string[]
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
export interface Diagnostic {
|
|
11
37
|
/** Stable forever. Never renumber or reuse. */
|
|
12
38
|
readonly code: string
|
|
@@ -21,6 +47,159 @@ export interface Diagnostic {
|
|
|
21
47
|
readonly verify?: string
|
|
22
48
|
}
|
|
23
49
|
|
|
50
|
+
const DIAGNOSTIC_COMPATIBILITY = Symbol("nifra.diagnosticCompatibility")
|
|
51
|
+
|
|
52
|
+
/** Attach legacy-only rendering metadata without widening the serialized diagnostic protocol. */
|
|
53
|
+
export function diagnosticWithCompatibility(
|
|
54
|
+
value: Diagnostic,
|
|
55
|
+
compatibility: DiagnosticCompatibility,
|
|
56
|
+
): Diagnostic {
|
|
57
|
+
const result = { ...value }
|
|
58
|
+
Object.defineProperty(result, DIAGNOSTIC_COMPATIBILITY, {
|
|
59
|
+
value: Object.freeze({
|
|
60
|
+
...compatibility,
|
|
61
|
+
...(compatibility.chain === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: { chain: Object.freeze([...compatibility.chain]) }),
|
|
64
|
+
}),
|
|
65
|
+
enumerable: false,
|
|
66
|
+
})
|
|
67
|
+
return Object.freeze(result)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Read legacy-only rendering metadata. Undefined means the diagnostic has no compatibility view. */
|
|
71
|
+
export function diagnosticCompatibilityOf(value: Diagnostic): DiagnosticCompatibility | undefined {
|
|
72
|
+
return (
|
|
73
|
+
value as Diagnostic & {
|
|
74
|
+
readonly [DIAGNOSTIC_COMPATIBILITY]?: DiagnosticCompatibility
|
|
75
|
+
}
|
|
76
|
+
)[DIAGNOSTIC_COMPATIBILITY]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The subset of SARIF 2.1.0 emitted by {@link toSarifLog}. */
|
|
80
|
+
export interface SarifLog {
|
|
81
|
+
readonly $schema: "https://json.schemastore.org/sarif-2.1.0.json"
|
|
82
|
+
readonly version: "2.1.0"
|
|
83
|
+
readonly runs: readonly SarifRun[]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface SarifRun {
|
|
87
|
+
readonly tool: {
|
|
88
|
+
readonly driver: {
|
|
89
|
+
readonly name: string
|
|
90
|
+
readonly version?: string
|
|
91
|
+
readonly rules: readonly SarifRule[]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
readonly results: readonly SarifResult[]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface SarifRule {
|
|
98
|
+
readonly id: string
|
|
99
|
+
readonly shortDescription: { readonly text: string }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface SarifResult {
|
|
103
|
+
readonly ruleId: string
|
|
104
|
+
readonly level: "error" | "warning" | "note"
|
|
105
|
+
readonly message: { readonly text: string }
|
|
106
|
+
readonly locations?: readonly SarifLocation[]
|
|
107
|
+
readonly properties?: Readonly<Record<string, string | readonly string[]>>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface SarifLocation {
|
|
111
|
+
readonly physicalLocation: {
|
|
112
|
+
readonly artifactLocation: {
|
|
113
|
+
readonly uri: string
|
|
114
|
+
readonly uriBaseId?: string
|
|
115
|
+
}
|
|
116
|
+
readonly region?: { readonly startLine: number }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface SarifProjectionOptions {
|
|
121
|
+
/** Name shown by external review tools in the SARIF run metadata. Defaults to `nifra`. */
|
|
122
|
+
readonly toolName?: string
|
|
123
|
+
/** Optional CLI/framework version shown by external review tools. */
|
|
124
|
+
readonly toolVersion?: string
|
|
125
|
+
/** Base URI identifier for relative diagnostic file paths. */
|
|
126
|
+
readonly uriBaseId?: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function sarifLevel(severity: Severity): SarifResult["level"] {
|
|
130
|
+
return severity === "error" ? "error" : severity === "warn" ? "warning" : "note"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function sarifProperties(
|
|
134
|
+
value: Diagnostic,
|
|
135
|
+
): Readonly<Record<string, string | readonly string[]>> | undefined {
|
|
136
|
+
const properties: Record<string, string | readonly string[]> = {}
|
|
137
|
+
if (value.evidence !== undefined && value.evidence.length > 0)
|
|
138
|
+
properties["nifra.evidence"] = [...value.evidence]
|
|
139
|
+
if (value.verify !== undefined) properties["nifra.verify"] = value.verify
|
|
140
|
+
if (value.fix !== undefined) {
|
|
141
|
+
properties["nifra.fix.recipe"] = value.fix.recipe
|
|
142
|
+
if (value.fix.command !== undefined) properties["nifra.fix.command"] = value.fix.command
|
|
143
|
+
}
|
|
144
|
+
return Object.keys(properties).length === 0 ? undefined : properties
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Project stable Nifra diagnostics into SARIF for code-host and external review surfaces.
|
|
149
|
+
*
|
|
150
|
+
* This is deliberately a pure projection: it does not run checks, read files, or reinterpret policy.
|
|
151
|
+
* Relative file names remain relative so callers can choose the review tool's checkout base through
|
|
152
|
+
* {@link SarifProjectionOptions.uriBaseId}.
|
|
153
|
+
*/
|
|
154
|
+
export function toSarifLog(
|
|
155
|
+
diagnostics: readonly Diagnostic[],
|
|
156
|
+
options: SarifProjectionOptions = {},
|
|
157
|
+
): SarifLog {
|
|
158
|
+
const rules = new Map<string, SarifRule>()
|
|
159
|
+
const results: SarifResult[] = []
|
|
160
|
+
for (const value of diagnostics) {
|
|
161
|
+
if (!rules.has(value.code)) {
|
|
162
|
+
rules.set(value.code, {
|
|
163
|
+
id: value.code,
|
|
164
|
+
shortDescription: { text: value.message },
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
const location =
|
|
168
|
+
value.file === undefined
|
|
169
|
+
? undefined
|
|
170
|
+
: {
|
|
171
|
+
physicalLocation: {
|
|
172
|
+
artifactLocation: {
|
|
173
|
+
uri: value.file.replaceAll("\\", "/"),
|
|
174
|
+
...(options.uriBaseId === undefined ? {} : { uriBaseId: options.uriBaseId }),
|
|
175
|
+
},
|
|
176
|
+
...(value.line !== undefined && Number.isInteger(value.line) && value.line >= 1
|
|
177
|
+
? { region: { startLine: value.line } }
|
|
178
|
+
: {}),
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
const properties = sarifProperties(value)
|
|
182
|
+
results.push({
|
|
183
|
+
ruleId: value.code,
|
|
184
|
+
level: sarifLevel(value.severity),
|
|
185
|
+
message: { text: value.message },
|
|
186
|
+
...(location === undefined ? {} : { locations: [location] }),
|
|
187
|
+
...(properties === undefined ? {} : { properties }),
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const driver = {
|
|
192
|
+
name: options.toolName ?? "nifra",
|
|
193
|
+
...(options.toolVersion === undefined ? {} : { version: options.toolVersion }),
|
|
194
|
+
rules: [...rules.values()],
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
198
|
+
version: "2.1.0",
|
|
199
|
+
runs: [{ tool: { driver }, results }],
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
24
203
|
export const diagnostic = (value: Diagnostic): Diagnostic => Object.freeze(value)
|
|
25
204
|
|
|
26
205
|
export function severityFails(severity: Severity, strict = false): boolean {
|
package/src/diff-tool.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* The CI loop: commit a snapshot on main, run `nifra diff api-snapshot.json` on every PR, and an
|
|
9
9
|
* accidental contract break (removed route, new required field, retyped response) fails the build
|
|
10
10
|
* before it ships. Classification lives in `@nifrajs/core/diff` (direction-aware, fails closed);
|
|
11
|
-
* this module only loads `backend.ts` and renders the result.
|
|
11
|
+
* this module only loads `backend/app.ts` and renders the result.
|
|
12
12
|
*
|
|
13
|
-
* Loads ONLY `backend.ts` - the API contract - so it works on an API-only project with no
|
|
13
|
+
* Loads ONLY `backend/app.ts` - the API contract - so it works on an API-only project with no
|
|
14
14
|
* framework config or routes/ directory (unlike the eager `loadApp`).
|
|
15
15
|
*/
|
|
16
16
|
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type RoutesDiff,
|
|
24
24
|
snapshotRoutes,
|
|
25
25
|
} from "@nifrajs/core/diff"
|
|
26
|
+
import { BACKEND_APP_FILE } from "./app-files.ts"
|
|
26
27
|
|
|
27
28
|
/** Snapshot file envelope - versioned so a future format change can migrate instead of misparse. */
|
|
28
29
|
export interface SnapshotFile {
|
|
@@ -81,12 +82,12 @@ export function formatDiff(diff: RoutesDiff): string {
|
|
|
81
82
|
return `${lines.join("\n")}\n\n${summary}`
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/** Import `backend.ts` from `cwd` and snapshot its routes. */
|
|
85
|
+
/** Import `backend/app.ts` from `cwd` and snapshot its routes. */
|
|
85
86
|
export async function snapshotBackend(cwd: string): Promise<readonly RouteSnapshot[]> {
|
|
86
|
-
const backendPath = resolve(cwd,
|
|
87
|
+
const backendPath = resolve(cwd, BACKEND_APP_FILE)
|
|
87
88
|
if (!existsSync(backendPath)) {
|
|
88
89
|
throw new Error(
|
|
89
|
-
`[nifra] no backend.ts in ${cwd} - \`nifra snapshot\`/\`nifra diff\` compare the API contract, which lives in backend.ts.`,
|
|
90
|
+
`[nifra] no backend/app.ts in ${cwd} - \`nifra snapshot\`/\`nifra diff\` compare the API contract, which lives in backend/app.ts.`,
|
|
90
91
|
)
|
|
91
92
|
}
|
|
92
93
|
const backend = ((await import(backendPath)) as { backend?: unknown }).backend
|
package/src/docs-search.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* embedding infra would be complexity without a payoff.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { countBodyHits, queryTermGroups, tokenize,
|
|
13
|
+
import { countBodyHits, queryTermGroups, tokenize, tokenSetScore } from "./search-terms.ts"
|
|
14
14
|
|
|
15
15
|
export interface DocSection {
|
|
16
16
|
readonly heading: string
|
|
@@ -83,10 +83,17 @@ export function searchSections(
|
|
|
83
83
|
const prepared =
|
|
84
84
|
"headingTokens" in section && "bodyLower" in section ? section : prepareSection(section)
|
|
85
85
|
let score = 0
|
|
86
|
+
let matchedTerms = 0
|
|
86
87
|
for (const term of terms) {
|
|
87
|
-
|
|
88
|
-
score +=
|
|
88
|
+
const headingScore = tokenSetScore(prepared.headingTokens, term)
|
|
89
|
+
if (headingScore > 0) score += 8 + headingScore * 12
|
|
90
|
+
const bodyHits = countBodyHits(prepared.bodyLower, term, 5)
|
|
91
|
+
if (headingScore > 0 || bodyHits > 0) matchedTerms += 1
|
|
92
|
+
score += bodyHits
|
|
89
93
|
}
|
|
94
|
+
// A result that matches every query concept should beat a section that only happens to repeat
|
|
95
|
+
// one highly frequent word, even when that single word appears in a curated heading.
|
|
96
|
+
score += matchedTerms * 26
|
|
90
97
|
if (score > 0) scored.push({ heading: section.heading, body: section.body, score })
|
|
91
98
|
}
|
|
92
99
|
return scored.sort((a, b) => b.score - a.score).slice(0, limit)
|