@beignet/cli 0.0.40 → 0.0.42

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +139 -17
  3. package/dist/analysis/source-index.d.ts +38 -0
  4. package/dist/analysis/source-index.d.ts.map +1 -0
  5. package/dist/analysis/source-index.js +271 -0
  6. package/dist/analysis/source-index.js.map +1 -0
  7. package/dist/analysis/workspace.d.ts +16 -0
  8. package/dist/analysis/workspace.d.ts.map +1 -0
  9. package/dist/analysis/workspace.js +134 -0
  10. package/dist/analysis/workspace.js.map +1 -0
  11. package/dist/app-map-schema.d.ts +5 -0
  12. package/dist/app-map-schema.d.ts.map +1 -0
  13. package/dist/app-map-schema.js +26 -0
  14. package/dist/app-map-schema.js.map +1 -0
  15. package/dist/app-map.d.ts +96 -0
  16. package/dist/app-map.d.ts.map +1 -0
  17. package/dist/app-map.js +1141 -0
  18. package/dist/app-map.js.map +1 -0
  19. package/dist/check.d.ts +7 -0
  20. package/dist/check.d.ts.map +1 -1
  21. package/dist/check.js +20 -5
  22. package/dist/check.js.map +1 -1
  23. package/dist/choices.d.ts +18 -0
  24. package/dist/choices.d.ts.map +1 -1
  25. package/dist/choices.js +35 -0
  26. package/dist/choices.js.map +1 -1
  27. package/dist/db.d.ts +49 -13
  28. package/dist/db.d.ts.map +1 -1
  29. package/dist/db.js +202 -21
  30. package/dist/db.js.map +1 -1
  31. package/dist/doctor-fixes.d.ts +64 -0
  32. package/dist/doctor-fixes.d.ts.map +1 -0
  33. package/dist/doctor-fixes.js +142 -0
  34. package/dist/doctor-fixes.js.map +1 -0
  35. package/dist/explain.d.ts +100 -0
  36. package/dist/explain.d.ts.map +1 -0
  37. package/dist/explain.js +606 -0
  38. package/dist/explain.js.map +1 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +165 -21
  41. package/dist/index.js.map +1 -1
  42. package/dist/inspect.d.ts +33 -9
  43. package/dist/inspect.d.ts.map +1 -1
  44. package/dist/inspect.js +406 -119
  45. package/dist/inspect.js.map +1 -1
  46. package/dist/lib.d.ts +10 -2
  47. package/dist/lib.d.ts.map +1 -1
  48. package/dist/lib.js +5 -2
  49. package/dist/lib.js.map +1 -1
  50. package/dist/make/shared.js +3 -3
  51. package/dist/make/shared.js.map +1 -1
  52. package/dist/make.d.ts.map +1 -1
  53. package/dist/make.js +63 -2
  54. package/dist/make.js.map +1 -1
  55. package/dist/mcp.d.ts +1 -1
  56. package/dist/mcp.d.ts.map +1 -1
  57. package/dist/mcp.js +188 -12
  58. package/dist/mcp.js.map +1 -1
  59. package/dist/preflight.d.ts.map +1 -1
  60. package/dist/preflight.js +10 -0
  61. package/dist/preflight.js.map +1 -1
  62. package/dist/provider-add.d.ts.map +1 -1
  63. package/dist/provider-add.js +167 -13
  64. package/dist/provider-add.js.map +1 -1
  65. package/dist/provider-audit.d.ts +6 -0
  66. package/dist/provider-audit.d.ts.map +1 -1
  67. package/dist/provider-audit.js +63 -15
  68. package/dist/provider-audit.js.map +1 -1
  69. package/dist/templates/agents.d.ts.map +1 -1
  70. package/dist/templates/agents.js +35 -6
  71. package/dist/templates/agents.js.map +1 -1
  72. package/dist/templates/base.d.ts.map +1 -1
  73. package/dist/templates/base.js +13 -7
  74. package/dist/templates/base.js.map +1 -1
  75. package/dist/templates/index.d.ts +1 -1
  76. package/dist/templates/index.d.ts.map +1 -1
  77. package/dist/templates/index.js +8 -1
  78. package/dist/templates/index.js.map +1 -1
  79. package/dist/templates/server.d.ts +3 -0
  80. package/dist/templates/server.d.ts.map +1 -1
  81. package/dist/templates/server.js +55 -1
  82. package/dist/templates/server.js.map +1 -1
  83. package/dist/templates/shared.d.ts +2 -1
  84. package/dist/templates/shared.d.ts.map +1 -1
  85. package/dist/templates/shared.js +8 -5
  86. package/dist/templates/shared.js.map +1 -1
  87. package/package.json +3 -2
  88. package/skills/app-structure/SKILL.md +48 -6
  89. package/src/analysis/source-index.ts +395 -0
  90. package/src/analysis/workspace.ts +180 -0
  91. package/src/app-map-schema.ts +28 -0
  92. package/src/app-map.ts +1705 -0
  93. package/src/check.ts +27 -4
  94. package/src/choices.ts +57 -0
  95. package/src/db.ts +276 -28
  96. package/src/doctor-fixes.ts +252 -0
  97. package/src/explain.ts +894 -0
  98. package/src/index.ts +237 -31
  99. package/src/inspect.ts +567 -147
  100. package/src/lib.ts +64 -1
  101. package/src/make/shared.ts +3 -3
  102. package/src/make.ts +90 -2
  103. package/src/mcp.ts +292 -12
  104. package/src/preflight.ts +14 -0
  105. package/src/provider-add.ts +211 -12
  106. package/src/provider-audit.ts +127 -22
  107. package/src/templates/agents.ts +35 -6
  108. package/src/templates/base.ts +25 -6
  109. package/src/templates/index.ts +18 -1
  110. package/src/templates/server.ts +58 -1
  111. package/src/templates/shared.ts +15 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @beignet/cli
2
2
 
3
+ ## 0.0.42
4
+
5
+ ### Patch Changes
6
+
7
+ - 879ae2b: Explain every mapped app concept through matching CLI, library, and MCP surfaces with source-backed aliases, conventions, and inspection actions.
8
+ - c9e6971: Add read-only doctor fix plans with exact patches and diagnostics, stable operation IDs, guarded selective application, co-located workflow repair, and matching CLI and MCP results.
9
+ - d199ee3: Add MCP tools for database lifecycle commands and provider-table schema sync with dry runs, bounded output, cancellation, timeouts, and matching CLI/library reports.
10
+ - 20bec79: Run generated test suites through an explicit Node and tsx entrypoint so they work when package scripts are started with Bun, npm, pnpm, or Yarn.
11
+ - @beignet/core@0.0.42
12
+
13
+ ## 0.0.41
14
+
15
+ ### Patch Changes
16
+
17
+ - 4516b4a: Expose source-backed app explanations and the full validation loop through new CLI APIs and MCP tools with provider-registration evidence, working-directory-aware actions, bounded output, request cancellation, and honest execution safety annotations.
18
+ - bdda67d: Add a deterministic app architecture map through `beignet map`, the public CLI library API, and a token-bounded `app_map` MCP tool.
19
+ - 5d4bb96: Add a generated Inngest v4 production path with shared clients, runtime-aware registries, Next.js serve routes, registry drift checks, production credential preflight, and explicit single-attempt retry semantics.
20
+ - @beignet/core@0.0.41
21
+
3
22
  ## 0.0.40
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -171,6 +171,7 @@ Inspect the app, then generate the next feature:
171
171
  ```bash
172
172
  # in another terminal, from my-app
173
173
  bun beignet routes
174
+ bun beignet map
174
175
  bun run lint
175
176
  bun beignet lint
176
177
  bun beignet doctor
@@ -223,9 +224,11 @@ beignet db seed [--dry-run] [--json] [--cwd <dir>]
223
224
  beignet db reset [--dry-run] [--json] [--cwd <dir>]
224
225
  beignet db schema sync [--dialect sqlite|postgres|mysql] [--tables audit,idempotency,outbox] [--output <path>] [--dry-run] [--json] [--cwd <dir>]
225
226
  beignet routes [--json] [--cwd <dir>]
226
- beignet check [--json] [--fix] [--cwd <dir>]
227
+ beignet map [--json] [--feature <name>] [--kind <kinds>] [--cwd <dir>]
228
+ beignet explain <kind> <target> [--json] [--cwd <dir>]
229
+ beignet check [--json] [--fix] [--preflight] [--cwd <dir>]
227
230
  beignet lint [--json] [--cwd <dir>] [--format human|json|github]
228
- beignet doctor [--json] [--strict] [--fix] [--cwd <dir>] [--format human|json|github]
231
+ beignet doctor [--json] [--strict] [--fix] [--dry-run] [--plan <id>] [--only <operation-ids>] [--cwd <dir>] [--format human|json|github]
229
232
  beignet provider add <preset> [--dry-run] [--json] [--cwd <dir>]
230
233
  beignet provider audit [--json] [--cwd <dir>]
231
234
  beignet mcp
@@ -272,6 +275,9 @@ Options:
272
275
  provider add cache-redis Add dependencies, provider wiring, env examples, and setup notes for a supported provider preset.
273
276
  --strict Include CI-oriented doctor warnings and fail on warnings.
274
277
  --fix Apply low-risk doctor fixes before reporting.
278
+ --dry-run Preview an exact doctor fix plan without writing files.
279
+ --plan id Apply only when the current repair plan matches this id.
280
+ --only routes.register-missing Apply selected comma-separated repair operations. Requires --plan.
275
281
  --shell zsh Shell for `completion install`/`uninstall`. Defaults to $SHELL.
276
282
  -h, --help Show help.
277
283
  -v, --version Print the CLI version.
@@ -333,7 +339,7 @@ partial command line; it exists for the shell integration and is safe to
333
339
  ignore otherwise. Completions complete whatever `beignet` resolves to on your
334
340
  `PATH`, such as the app-local bin installed by generated apps.
335
341
 
336
- Beignet CLI commands are convention-aware. `routes`, `lint`, `doctor`, and
342
+ Beignet CLI commands are convention-aware. `routes`, `map`, `lint`, `doctor`, and
337
343
  generators work best in the Next.js layout created by `beignet create`:
338
344
 
339
345
  ```txt
@@ -429,7 +435,12 @@ writing. The `create` command also remains a Next.js scaffold.
429
435
 
430
436
  The generated `lib/beignet-test-runner.ts` also resolves all four supported
431
437
  config formats and includes configured test, feature, route, server, port,
432
- infra-port, route-builder, and use-case-builder roots in test discovery.
438
+ infra-port, route-builder, and use-case-builder roots in test discovery. The
439
+ generated `test` script invokes this runner with `node --import tsx`, so the
440
+ Node test suite uses the same runtime even when the package script is started
441
+ with Bun, npm, pnpm, or Yarn. `beignet doctor --fix` upgrades older generated
442
+ `bun test` and `tsx lib/beignet-test-runner.ts` scripts without replacing
443
+ custom test commands.
433
444
 
434
445
  The same config can declare app-owned names for Beignet operational database
435
446
  tables when an app uses names other than the provider defaults:
@@ -834,8 +845,11 @@ messages. Both support bounded `--limit` runs and `--dry-run` previews.
834
845
  There is intentionally no separate `beignet jobs drain` command. Outbox-backed
835
846
  jobs drain through the outbox beside durable events. Direct provider jobs should
836
847
  use provider-owned worker entrypoints, such as a BullMQ worker built with
837
- `createBullMQJobWorker(...)` or an Inngest route built with
838
- `createInngestJobFunction(...)`.
848
+ `createBullMQJobWorker(...)` or the generated Inngest `server/inngest.ts`
849
+ registry. Next apps receive `app/api/inngest/route.ts`; non-Next apps receive a
850
+ `createAppInngestFunctions(...)` factory for their runtime adapter. When the
851
+ Inngest provider is installed, `beignet make job` maintains the central
852
+ registry.
839
853
 
840
854
  Use `beignet schedule run` when you need to run a schedule explicitly from a
841
855
  local shell, CI job, or worker entrypoint:
@@ -892,6 +906,10 @@ script is missing, Drizzle Kit has no `drizzle.config.*`, or the standard
892
906
  seed/reset entrypoint was removed, the error points to the exact file or
893
907
  package script to restore.
894
908
 
909
+ `beignet db <command> --json` retains the final 64 KiB from each output stream
910
+ and sets `outputTruncated: true` when earlier output was discarded. Human
911
+ terminal output remains streamed directly by the app-owned script.
912
+
895
913
  `db reset` is intentionally app-owned because destructive behavior depends on
896
914
  the environment. The standard starter refuses to reset non-local database URLs
897
915
  unless `BEIGNET_ALLOW_DATABASE_RESET=true` is set. Drizzle starters also include
@@ -900,6 +918,15 @@ repository and persistence tests: an in-memory libSQL database for SQLite, an
900
918
  in-process PGlite database for Postgres, or a real server via `MYSQL_TEST_URL`
901
919
  for MySQL.
902
920
 
921
+ Coding agents can run the same lifecycle without leaving MCP. Call `db` with
922
+ `{ command: "generate" | "migrate" | "seed" | "reset", dryRun?, timeoutMs? }`
923
+ for the exact versioned CLI/library report. Output is tail-bounded, requests
924
+ cancel the active process tree, and commands default to a ten-minute timeout.
925
+ Call `db_schema_sync` with `{ dialect?, tables?, output?, dryRun? }` for the
926
+ same report as `beignet db schema sync --json`. For lifecycle commands,
927
+ `dryRun` validates prerequisites and reports the app-owned script without
928
+ executing it; it does not simulate the script's SQL or data changes.
929
+
903
930
  Generate feature-owned test factories and local/demo seeds with:
904
931
 
905
932
  ```bash
@@ -944,6 +971,62 @@ Use JSON output when you want to feed the route catalog into another tool:
944
971
  beignet routes --json
945
972
  ```
946
973
 
974
+ ## Map app architecture
975
+
976
+ Build a deterministic, source-backed graph of the app:
977
+
978
+ ```bash
979
+ beignet map
980
+ beignet map --feature issues
981
+ beignet map --json --kind route,use-case,event,listener
982
+ ```
983
+
984
+ The human view summarizes contracts, use cases, workflows, ports, UI, and tests
985
+ per feature. JSON is a versioned `schemaVersion: 1` payload with features,
986
+ contracts, route groups, use cases, policies and abilities, workflow
987
+ definitions and registries, agent capabilities, ports, app/package providers,
988
+ tables, OpenAPI exposure, tests, cross-feature dependencies, doctor/lint
989
+ findings, and unresolved references. Every node has a stable ID and source;
990
+ every edge carries source evidence and confidence.
991
+
992
+ `--feature` keeps that feature plus its direct relationships, while `--kind`
993
+ accepts one or a comma-separated list of node kinds. These projections make
994
+ the same full graph practical for coding-agent context windows. The command is
995
+ report-only and does not fail because doctor or lint findings are present.
996
+
997
+ ## Explain mapped app concepts
998
+
999
+ Resolve one app-map target into deterministic, source-backed context:
1000
+
1001
+ ```bash
1002
+ beignet explain feature issues
1003
+ beignet explain route "POST /api/issues"
1004
+ beignet explain use-case issues.create
1005
+ beignet explain task issues.backfill-search
1006
+ beignet explain port storage
1007
+ beignet explain registry issueTasks
1008
+ beignet explain table issues
1009
+ beignet explain diagnostic BEIGNET_ROUTE_GROUP_UNREGISTERED
1010
+ ```
1011
+
1012
+ `<kind>` accepts every app-map node kind plus `diagnostic`: features,
1013
+ contracts, routes and route groups, use cases, policies and abilities,
1014
+ workflow artifacts, agent capabilities, registries, ports and providers,
1015
+ tables, OpenAPI documents, entrypoints, and tests. Targets accept stable IDs,
1016
+ runtime or declaration names, source selectors such as `file#export`, and
1017
+ applicable aliases such as an HTTP method/path or provider port.
1018
+
1019
+ Human output summarizes relevant relationships, conventions, findings,
1020
+ suggested files, and follow-up commands. `--json` returns the versioned
1021
+ `schemaVersion: 1` payload used by the MCP `explain` tool. Feature explanations
1022
+ bound their relationship list and report full and returned counts; use
1023
+ `beignet map --feature <name> --json` or explain a directly related concept for
1024
+ the omitted detail. Provider explanations include the matching entry in the
1025
+ configured provider registry when static provider audit proves it. Human
1026
+ output names the app root, and command actions in JSON carry their own `cwd`,
1027
+ so an explanation requested with `--cwd` stays copy-pasteable. Explain is
1028
+ report-only and never changes the app.
1029
+
947
1030
  ## Run the validation loop
948
1031
 
949
1032
  Run `check` when you want the whole validation loop as one command:
@@ -957,12 +1040,14 @@ It runs `beignet lint`, `beignet doctor --strict`, and the app's own `lint`,
957
1040
  in that order. Every step runs even when an earlier one fails, so a single
958
1041
  run reports everything that needs fixing; the command exits non-zero when any
959
1042
  step fails. Missing package scripts are reported as skipped, never as
960
- failures.
1043
+ failures. Failed package-script output retains at most the last 64 KiB of each
1044
+ stream.
961
1045
 
962
1046
  Use `beignet check --fix` to apply doctor's low-risk registration fixes
963
1047
  before checking, and `beignet check --json` for a versioned payload
964
1048
  (`schemaVersion: 1`) with the step list, statuses, captured failure output,
965
- and applied fixes. The individual commands below still work when you need one
1049
+ and applied fixes. Add `--preflight` to run the runtime environment gate after
1050
+ strict doctor. The individual commands below still work when you need one
966
1051
  check alone or its `--format github` output.
967
1052
 
968
1053
  ## Gate the deploy environment
@@ -1135,8 +1220,8 @@ Use `beignet provider audit` when you want a report-only inventory of the
1135
1220
  provider packages installed in an app. The human audit prints provider
1136
1221
  metadata validity, registration status, required env, required tables, and
1137
1222
  declared app ports. `beignet provider audit --json` returns a versioned
1138
- `schemaVersion: 1` payload with active variants and watchers for scripts and
1139
- coding agents. The command does not fail CI for missing setup; stable,
1223
+ `schemaVersion: 1` payload with active variants, watchers, and source locations
1224
+ for matching provider-registry entries. The command does not fail CI for missing setup; stable,
1140
1225
  actionable findings belong in `doctor`.
1141
1226
 
1142
1227
  Use `beignet doctor --strict` for CI-oriented checks that may be noisy locally,
@@ -1161,7 +1246,25 @@ central file is missing, an anchor is customized beyond recognition, or some
1161
1246
  artifacts are already registered individually, the fix bails out and the
1162
1247
  diagnostic stays. The listener fix additionally bails when the app has no
1163
1248
  `eventBus` port or the providers array is customized, because apps own their
1164
- event-bus wiring.
1249
+ event-bus wiring. When configured schedule and task registries share one file,
1250
+ doctor combines both edits into the selectable `workflows.register-missing`
1251
+ operation so apply-all remains atomic.
1252
+
1253
+ Preview the exact changes before applying them with:
1254
+
1255
+ ```bash
1256
+ beignet doctor --fix --dry-run
1257
+ ```
1258
+
1259
+ The plan contains stable repair operation IDs, SHA-256 before/after hashes,
1260
+ unified patches, a `planId`, and the current doctor diagnostics. Human and
1261
+ GitHub output render those diagnostics so every non-zero exit is explained.
1262
+ Apply the complete guarded plan with
1263
+ `beignet doctor --fix --plan <planId>`, or select operations with
1264
+ `--only routes.register-missing,outbox.register-missing`. Guarded application
1265
+ fails before writing when any fixable file or available repair changed after
1266
+ planning. Plain `doctor --fix` and `check --fix` retain their apply-all
1267
+ behavior for scripts that already use them.
1165
1268
 
1166
1269
  ## MCP server for coding agents
1167
1270
 
@@ -1172,20 +1275,39 @@ call the CLI as tools:
1172
1275
  beignet mcp
1173
1276
  ```
1174
1277
 
1175
- The server exposes six tools:
1176
-
1278
+ The server exposes twelve tools:
1279
+
1280
+ - `app_map` - project the source-backed app graph by optional `feature`,
1281
+ `kinds`, and `includeDiagnostics` inputs (read-only)
1282
+ - `explain` - explain any source-backed mapped concept or diagnostic with
1283
+ `{ kind, target }`, returning relationships, conventions, findings,
1284
+ suggested files, and follow-up commands (read-only)
1285
+ - `check` - run the complete validation loop and return versioned step
1286
+ results, bounded failure output, durations, and overall `ok`; accepts
1287
+ `{ preflight?: boolean, timeoutMs?: number }`, cancels the active script with
1288
+ the MCP request, and does not apply Beignet fixes. App scripts retain their
1289
+ normal side effects, so this is an execution tool rather than a read-only tool
1290
+ - `db` - run `generate`, `migrate`, `seed`, or `reset` with
1291
+ `{ command, dryRun?, timeoutMs? }`; returns the matching versioned CLI report
1292
+ with bounded output, request cancellation, and a command timeout
1293
+ - `db_schema_sync` - sync app-owned Beignet provider-table schema re-exports
1294
+ with `{ dialect?, tables?, output?, dryRun? }`; idempotent but writes source
1295
+ unless `dryRun` is true
1177
1296
  - `routes` - list app routes and contracts (read-only)
1178
1297
  - `doctor` - drift diagnostics as JSON, `{ strict?: boolean }` defaults to
1179
1298
  `true` (read-only)
1180
- - `doctor_fix` - apply doctor's low-risk fixes; repairs route-group,
1181
- schedule, task, outbox, and fully unregistered listener registry drift when
1182
- the central registry/provider anchors are recognizable
1299
+ - `doctor_fix_plan` - return stable repair operation IDs, exact patches, file
1300
+ hashes, and a plan ID without changing files
1301
+ - `doctor_fix` - apply doctor's low-risk fixes; accepts
1302
+ `{ planId?, fixIds?, strict? }`. Omitting `planId` preserves apply-all;
1303
+ `fixIds` requires the plan ID returned by `doctor_fix_plan`
1183
1304
  - `lint` - architecture dependency-direction diagnostics (read-only)
1184
1305
  - `make` - run a generator with `{ artifact, name, ...options }`, the same
1185
1306
  artifact kinds as `beignet make`
1186
1307
  - `provider_add` - add a provider setup preset with `{ preset, dryRun? }`
1187
1308
 
1188
- Tool outputs match the JSON the matching `--json` flags print. Generated apps
1309
+ The `db`, `db_schema_sync`, `doctor_fix_plan`, and `doctor_fix` tool outputs
1310
+ match the corresponding CLI/library JSON payloads. Generated apps
1189
1311
  ship a `.mcp.json` that runs `./node_modules/.bin/beignet mcp`, so Claude
1190
1312
  Code picks up the app-local CLI version with no configuration; Cursor and VS
1191
1313
  Code users add the same command to `.cursor/mcp.json` or `.vscode/mcp.json`.
@@ -0,0 +1,38 @@
1
+ import ts from "typescript";
2
+ import { type AnalysisWorkspace } from "./workspace.js";
3
+ export type AnalysisSourceLocation = {
4
+ file: string;
5
+ exportName?: string;
6
+ line?: number;
7
+ column?: number;
8
+ };
9
+ export type ResolvedSourceReference = {
10
+ file: string;
11
+ exportName: string;
12
+ declaration?: ts.Declaration;
13
+ };
14
+ export type LocalImportReference = {
15
+ file: string;
16
+ importPath: string;
17
+ resolvedFile: string;
18
+ kind: "type" | "value";
19
+ line: number;
20
+ column: number;
21
+ };
22
+ export type SourceIndex = {
23
+ resolveName(file: string, name: string): Promise<ResolvedSourceReference | undefined>;
24
+ resolveExpression(file: string, expression: ts.Expression): Promise<ResolvedSourceReference | undefined>;
25
+ resolveExport(file: string, exportName: string): Promise<ResolvedSourceReference | undefined>;
26
+ sourceLocation(file: string, node: ts.Node, exportName?: string): Promise<AnalysisSourceLocation>;
27
+ };
28
+ export declare function createSourceIndex(workspace: AnalysisWorkspace): SourceIndex;
29
+ export declare function exportedVariableDeclarations(sourceFile: ts.SourceFile): Array<{
30
+ exportName: string;
31
+ declaration: ts.VariableDeclaration;
32
+ }>;
33
+ export declare function literalText(node: ts.Node | undefined): string | undefined;
34
+ export declare function propertyAssignment(object: ts.ObjectLiteralExpression, name: string): ts.PropertyAssignment | undefined;
35
+ export declare function propertyName(node: ts.PropertyName): string | undefined;
36
+ export declare function visitCalls(node: ts.Node, visit: (call: ts.CallExpression) => void): void;
37
+ export declare function localImportReferences(workspace: AnalysisWorkspace, file: string): Promise<LocalImportReference[]>;
38
+ //# sourceMappingURL=source-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-index.d.ts","sourceRoot":"","sources":["../../src/analysis/source-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,KAAK,iBAAiB,EAA0B,MAAM,gBAAgB,CAAC;AAEhF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAaF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC;IAChD,iBAAiB,CACf,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,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workspace) {
4
+ const indexes = new Map();
5
+ const readIndex = async (file) => {
6
+ const cached = indexes.get(file);
7
+ if (cached)
8
+ return cached;
9
+ const sourceFile = await workspace.readSourceFile(file);
10
+ const index = {
11
+ declarations: new Map(),
12
+ imports: new Map(),
13
+ reexports: new Map(),
14
+ exportStars: [],
15
+ };
16
+ indexes.set(file, index);
17
+ for (const statement of sourceFile.statements) {
18
+ if (ts.isImportDeclaration(statement)) {
19
+ const source = moduleText(statement.moduleSpecifier);
20
+ const target = source
21
+ ? resolveLocalSourceFile(workspace, file, source)
22
+ : undefined;
23
+ if (!target || !statement.importClause)
24
+ continue;
25
+ if (statement.importClause.name) {
26
+ index.imports.set(statement.importClause.name.text, {
27
+ kind: "named",
28
+ file: target,
29
+ exportName: "default",
30
+ });
31
+ }
32
+ const bindings = statement.importClause.namedBindings;
33
+ if (bindings && ts.isNamespaceImport(bindings)) {
34
+ index.imports.set(bindings.name.text, {
35
+ kind: "namespace",
36
+ file: target,
37
+ });
38
+ }
39
+ else if (bindings && ts.isNamedImports(bindings)) {
40
+ for (const element of bindings.elements) {
41
+ index.imports.set(element.name.text, {
42
+ kind: "named",
43
+ file: target,
44
+ exportName: element.propertyName?.text ?? element.name.text,
45
+ });
46
+ }
47
+ }
48
+ continue;
49
+ }
50
+ if (ts.isExportDeclaration(statement)) {
51
+ const source = statement.moduleSpecifier
52
+ ? moduleText(statement.moduleSpecifier)
53
+ : undefined;
54
+ const target = source
55
+ ? resolveLocalSourceFile(workspace, file, source)
56
+ : undefined;
57
+ if (!target)
58
+ continue;
59
+ if (!statement.exportClause) {
60
+ index.exportStars.push(target);
61
+ continue;
62
+ }
63
+ if (ts.isNamedExports(statement.exportClause)) {
64
+ for (const element of statement.exportClause.elements) {
65
+ index.reexports.set(element.name.text, {
66
+ file: target,
67
+ exportName: element.propertyName?.text ?? element.name.text,
68
+ });
69
+ }
70
+ }
71
+ continue;
72
+ }
73
+ if (ts.isVariableStatement(statement) && hasExportModifier(statement)) {
74
+ for (const declaration of statement.declarationList.declarations) {
75
+ if (ts.isIdentifier(declaration.name)) {
76
+ index.declarations.set(declaration.name.text, declaration);
77
+ }
78
+ }
79
+ continue;
80
+ }
81
+ if ((ts.isFunctionDeclaration(statement) ||
82
+ ts.isClassDeclaration(statement) ||
83
+ ts.isInterfaceDeclaration(statement) ||
84
+ ts.isTypeAliasDeclaration(statement) ||
85
+ ts.isEnumDeclaration(statement)) &&
86
+ hasExportModifier(statement) &&
87
+ statement.name) {
88
+ index.declarations.set(statement.name.text, statement);
89
+ }
90
+ }
91
+ return index;
92
+ };
93
+ const resolveExport = async (file, exportName, visited = new Set()) => {
94
+ const key = `${file}#${exportName}`;
95
+ if (visited.has(key))
96
+ return undefined;
97
+ visited.add(key);
98
+ const index = await readIndex(file);
99
+ const declaration = index.declarations.get(exportName);
100
+ if (declaration)
101
+ return { file, exportName, declaration };
102
+ const reexport = index.reexports.get(exportName);
103
+ if (reexport) {
104
+ return ((await resolveExport(reexport.file, reexport.exportName, visited)) ?? {
105
+ file: reexport.file,
106
+ exportName: reexport.exportName,
107
+ });
108
+ }
109
+ for (const target of index.exportStars) {
110
+ const resolved = await resolveExport(target, exportName, visited);
111
+ if (resolved)
112
+ return resolved;
113
+ }
114
+ return undefined;
115
+ };
116
+ return {
117
+ async resolveName(file, name) {
118
+ const index = await readIndex(file);
119
+ const local = index.declarations.get(name);
120
+ if (local) {
121
+ return { file, exportName: name, declaration: local };
122
+ }
123
+ const binding = index.imports.get(name);
124
+ if (binding?.kind !== "named")
125
+ return undefined;
126
+ return ((await resolveExport(binding.file, binding.exportName)) ?? {
127
+ file: binding.file,
128
+ exportName: binding.exportName,
129
+ });
130
+ },
131
+ async resolveExpression(file, rawExpression) {
132
+ const expression = unwrapExpression(rawExpression);
133
+ const index = await readIndex(file);
134
+ if (ts.isIdentifier(expression)) {
135
+ const local = index.declarations.get(expression.text);
136
+ if (local) {
137
+ return { file, exportName: expression.text, declaration: local };
138
+ }
139
+ const binding = index.imports.get(expression.text);
140
+ if (binding?.kind !== "named")
141
+ return undefined;
142
+ return ((await resolveExport(binding.file, binding.exportName)) ?? {
143
+ file: binding.file,
144
+ exportName: binding.exportName,
145
+ });
146
+ }
147
+ if (ts.isPropertyAccessExpression(expression) &&
148
+ ts.isIdentifier(expression.expression)) {
149
+ const binding = index.imports.get(expression.expression.text);
150
+ if (binding?.kind !== "namespace")
151
+ return undefined;
152
+ return ((await resolveExport(binding.file, expression.name.text)) ?? {
153
+ file: binding.file,
154
+ exportName: expression.name.text,
155
+ });
156
+ }
157
+ return undefined;
158
+ },
159
+ resolveExport(file, exportName) {
160
+ return resolveExport(file, exportName);
161
+ },
162
+ async sourceLocation(file, node, exportName) {
163
+ const sourceFile = await workspace.readSourceFile(file);
164
+ const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
165
+ return {
166
+ file,
167
+ ...(exportName ? { exportName } : {}),
168
+ line: position.line + 1,
169
+ column: position.character + 1,
170
+ };
171
+ },
172
+ };
173
+ }
174
+ export function exportedVariableDeclarations(sourceFile) {
175
+ const declarations = [];
176
+ for (const statement of sourceFile.statements) {
177
+ if (!ts.isVariableStatement(statement) || !hasExportModifier(statement)) {
178
+ continue;
179
+ }
180
+ for (const declaration of statement.declarationList.declarations) {
181
+ if (ts.isIdentifier(declaration.name)) {
182
+ declarations.push({
183
+ exportName: declaration.name.text,
184
+ declaration,
185
+ });
186
+ }
187
+ }
188
+ }
189
+ return declarations;
190
+ }
191
+ export function literalText(node) {
192
+ return node &&
193
+ (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
194
+ ? node.text
195
+ : undefined;
196
+ }
197
+ export function propertyAssignment(object, name) {
198
+ return object.properties.find((property) => ts.isPropertyAssignment(property) && propertyName(property.name) === name);
199
+ }
200
+ export function propertyName(node) {
201
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node))
202
+ return node.text;
203
+ return undefined;
204
+ }
205
+ export function visitCalls(node, visit) {
206
+ const walk = (current) => {
207
+ if (ts.isCallExpression(current))
208
+ visit(current);
209
+ current.forEachChild(walk);
210
+ };
211
+ walk(node);
212
+ }
213
+ export async function localImportReferences(workspace, file) {
214
+ const sourceFile = await workspace.readSourceFile(file);
215
+ const references = [];
216
+ for (const statement of sourceFile.statements) {
217
+ if (!ts.isImportDeclaration(statement) &&
218
+ !ts.isExportDeclaration(statement)) {
219
+ continue;
220
+ }
221
+ if (!statement.moduleSpecifier)
222
+ continue;
223
+ const importPath = moduleText(statement.moduleSpecifier);
224
+ const resolvedFile = importPath
225
+ ? resolveLocalSourceFile(workspace, file, importPath)
226
+ : undefined;
227
+ if (!importPath || !resolvedFile)
228
+ continue;
229
+ const position = sourceFile.getLineAndCharacterOfPosition(statement.getStart(sourceFile));
230
+ const typeOnly = ts.isImportDeclaration(statement)
231
+ ? Boolean(statement.importClause?.isTypeOnly ||
232
+ (statement.importClause?.namedBindings &&
233
+ ts.isNamedImports(statement.importClause.namedBindings) &&
234
+ statement.importClause.namedBindings.elements.length > 0 &&
235
+ statement.importClause.namedBindings.elements.every((element) => element.isTypeOnly)))
236
+ : statement.isTypeOnly ||
237
+ (statement.exportClause &&
238
+ ts.isNamedExports(statement.exportClause) &&
239
+ statement.exportClause.elements.length > 0 &&
240
+ statement.exportClause.elements.every((element) => element.isTypeOnly));
241
+ references.push({
242
+ file,
243
+ importPath,
244
+ resolvedFile,
245
+ kind: typeOnly ? "type" : "value",
246
+ line: position.line + 1,
247
+ column: position.character + 1,
248
+ });
249
+ }
250
+ return references;
251
+ }
252
+ function moduleText(node) {
253
+ return ts.isStringLiteral(node) ? node.text : undefined;
254
+ }
255
+ function hasExportModifier(node) {
256
+ return Boolean(ts.canHaveModifiers(node) &&
257
+ ts
258
+ .getModifiers(node)
259
+ ?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword));
260
+ }
261
+ function unwrapExpression(expression) {
262
+ let current = expression;
263
+ while (ts.isAsExpression(current) ||
264
+ ts.isSatisfiesExpression(current) ||
265
+ ts.isParenthesizedExpression(current) ||
266
+ ts.isNonNullExpression(current)) {
267
+ current = current.expression;
268
+ }
269
+ return current;
270
+ }
271
+ //# sourceMappingURL=source-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-index.js","sourceRoot":"","sources":["../../src/analysis/source-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAA0B,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAuDhF,MAAM,UAAU,iBAAiB,CAAC,SAA4B;IAC5D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE7C,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAAsB,EAAE;QAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,KAAK,GAAc;YACvB,YAAY,EAAE,IAAI,GAAG,EAAE;YACvB,OAAO,EAAE,IAAI,GAAG,EAAE;YAClB,SAAS,EAAE,IAAI,GAAG,EAAE;YACpB,WAAW,EAAE,EAAE;SAChB,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEzB,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YAC9C,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACtC,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;gBACrD,MAAM,MAAM,GAAG,MAAM;oBACnB,CAAC,CAAC,sBAAsB,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC;oBACjD,CAAC,CAAC,SAAS,CAAC;gBACd,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY;oBAAE,SAA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SAAS,UAAU,CAAC,IAAmB;IACrC,OAAO,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAa;IACtC,OAAO,OAAO,CACZ,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC;QACvB,EAAE;aACC,YAAY,CAAC,IAAI,CAAC;YACnB,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAyB;IACjD,IAAI,OAAO,GAAG,UAAU,CAAC;IACzB,OACE,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC;QAC1B,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC;QACjC,EAAE,CAAC,yBAAyB,CAAC,OAAO,CAAC;QACrC,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAC/B,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import ts from "typescript";
2
+ import { type ResolvedBeignetConfig } from "../config.js";
3
+ export type AnalysisWorkspace = {
4
+ targetDir: string;
5
+ files: string[];
6
+ fileSet: Set<string>;
7
+ config: ResolvedBeignetConfig;
8
+ atAliasRoot: string;
9
+ readSource(file: string): Promise<string>;
10
+ readSourceFile(file: string): Promise<ts.SourceFile>;
11
+ };
12
+ export declare function createAnalysisWorkspace(cwd?: string): Promise<AnalysisWorkspace>;
13
+ export declare function assertDirectory(targetDir: string): Promise<void>;
14
+ export declare function listProjectFiles(targetDir: string): Promise<string[]>;
15
+ export declare function resolveLocalSourceFile(workspace: Pick<AnalysisWorkspace, "atAliasRoot" | "fileSet">, importerFile: string, importPath: string): string | undefined;
16
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/analysis/workspace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,cAAc,CAAC;AAWtB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;CACtD,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,GAAG,SAAgB,GAClB,OAAO,CAAC,iBAAiB,CAAC,CAyC5B;AAED,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAYtE;AAED,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqB3E;AAED,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,SAAS,CAAC,EAC7D,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CA6BpB"}