@nifrajs/cli 5.0.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/CHANGELOG.md +3211 -0
  2. package/README.md +10 -2
  3. package/dist/agent-files.d.ts +19 -11
  4. package/dist/agent-files.d.ts.map +1 -1
  5. package/dist/agent-files.js +26 -18
  6. package/dist/agent-files.js.map +1 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +5 -2
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts +12 -2
  11. package/dist/assure.d.ts.map +1 -1
  12. package/dist/assure.js +73 -9
  13. package/dist/assure.js.map +1 -1
  14. package/dist/capabilities-tool.d.ts.map +1 -1
  15. package/dist/capabilities-tool.js +152 -49
  16. package/dist/capabilities-tool.js.map +1 -1
  17. package/dist/check-diagnostics.d.ts +7 -0
  18. package/dist/check-diagnostics.d.ts.map +1 -1
  19. package/dist/check-diagnostics.js +3 -0
  20. package/dist/check-diagnostics.js.map +1 -1
  21. package/dist/check-scan.d.ts +8 -2
  22. package/dist/check-scan.d.ts.map +1 -1
  23. package/dist/check-scan.js +49 -13
  24. package/dist/check-scan.js.map +1 -1
  25. package/dist/check.d.ts.map +1 -1
  26. package/dist/check.js +91 -45
  27. package/dist/check.js.map +1 -1
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.d.ts.map +1 -1
  30. package/dist/cli.js +128 -59
  31. package/dist/cli.js.map +1 -1
  32. package/dist/client-module.d.ts +5 -3
  33. package/dist/client-module.d.ts.map +1 -1
  34. package/dist/client-module.js +34 -10
  35. package/dist/client-module.js.map +1 -1
  36. package/dist/command-catalog.d.ts +9 -1
  37. package/dist/command-catalog.d.ts.map +1 -1
  38. package/dist/command-catalog.js +75 -26
  39. package/dist/command-catalog.js.map +1 -1
  40. package/dist/dev-bun-config.d.ts +6 -3
  41. package/dist/dev-bun-config.d.ts.map +1 -1
  42. package/dist/dev-bun-config.js +13 -10
  43. package/dist/dev-bun-config.js.map +1 -1
  44. package/dist/dev-feed-tool.d.ts +19 -1
  45. package/dist/dev-feed-tool.d.ts.map +1 -1
  46. package/dist/dev-feed-tool.js +114 -0
  47. package/dist/dev-feed-tool.js.map +1 -1
  48. package/dist/doctor.d.ts +15 -1
  49. package/dist/doctor.d.ts.map +1 -1
  50. package/dist/doctor.js +79 -61
  51. package/dist/doctor.js.map +1 -1
  52. package/dist/fix-recipes.d.ts +2 -0
  53. package/dist/fix-recipes.d.ts.map +1 -1
  54. package/dist/fix-recipes.js +93 -12
  55. package/dist/fix-recipes.js.map +1 -1
  56. package/dist/i18n-check.d.ts +11 -1
  57. package/dist/i18n-check.d.ts.map +1 -1
  58. package/dist/i18n-check.js +170 -17
  59. package/dist/i18n-check.js.map +1 -1
  60. package/dist/init-agents.d.ts +60 -4
  61. package/dist/init-agents.d.ts.map +1 -1
  62. package/dist/init-agents.js +196 -33
  63. package/dist/init-agents.js.map +1 -1
  64. package/dist/internal/config-paths.d.ts +16 -0
  65. package/dist/internal/config-paths.d.ts.map +1 -0
  66. package/dist/internal/config-paths.js +124 -0
  67. package/dist/internal/config-paths.js.map +1 -0
  68. package/dist/internal/installed-package.d.ts +4 -0
  69. package/dist/internal/installed-package.d.ts.map +1 -0
  70. package/dist/internal/installed-package.js +17 -0
  71. package/dist/internal/installed-package.js.map +1 -0
  72. package/dist/internal/project-specifiers.d.ts +14 -1
  73. package/dist/internal/project-specifiers.d.ts.map +1 -1
  74. package/dist/internal/project-specifiers.js +63 -16
  75. package/dist/internal/project-specifiers.js.map +1 -1
  76. package/dist/internal/source-facts.d.ts +12 -1
  77. package/dist/internal/source-facts.d.ts.map +1 -1
  78. package/dist/internal/source-facts.js +117 -5
  79. package/dist/internal/source-facts.js.map +1 -1
  80. package/dist/internal/typescript-import.d.ts.map +1 -1
  81. package/dist/internal/typescript-import.js +5 -3
  82. package/dist/internal/typescript-import.js.map +1 -1
  83. package/dist/internal/workspace-packages.d.ts +22 -0
  84. package/dist/internal/workspace-packages.d.ts.map +1 -0
  85. package/dist/internal/workspace-packages.js +215 -0
  86. package/dist/internal/workspace-packages.js.map +1 -0
  87. package/dist/introspect.d.ts +9 -0
  88. package/dist/introspect.d.ts.map +1 -1
  89. package/dist/introspect.js +32 -1
  90. package/dist/introspect.js.map +1 -1
  91. package/dist/levels-tool.d.ts.map +1 -1
  92. package/dist/levels-tool.js +5 -8
  93. package/dist/levels-tool.js.map +1 -1
  94. package/dist/load.d.ts +9 -4
  95. package/dist/load.d.ts.map +1 -1
  96. package/dist/load.js +32 -3
  97. package/dist/load.js.map +1 -1
  98. package/dist/lock-links.d.ts +42 -0
  99. package/dist/lock-links.d.ts.map +1 -0
  100. package/dist/lock-links.js +144 -0
  101. package/dist/lock-links.js.map +1 -0
  102. package/dist/mcp-context.d.ts.map +1 -1
  103. package/dist/mcp-context.js +6 -21
  104. package/dist/mcp-context.js.map +1 -1
  105. package/dist/mcp-delegate.d.ts +2 -2
  106. package/dist/mcp-delegate.d.ts.map +1 -1
  107. package/dist/mcp-delegate.js +19 -7
  108. package/dist/mcp-delegate.js.map +1 -1
  109. package/dist/mcp-exec.d.ts +1 -0
  110. package/dist/mcp-exec.d.ts.map +1 -1
  111. package/dist/mcp-exec.js +13 -5
  112. package/dist/mcp-exec.js.map +1 -1
  113. package/dist/mcp-http.js +1 -1
  114. package/dist/mcp-io.d.ts +13 -0
  115. package/dist/mcp-io.d.ts.map +1 -1
  116. package/dist/mcp-io.js +23 -0
  117. package/dist/mcp-io.js.map +1 -1
  118. package/dist/mcp-path.d.ts +2 -1
  119. package/dist/mcp-path.d.ts.map +1 -1
  120. package/dist/mcp-path.js +9 -24
  121. package/dist/mcp-path.js.map +1 -1
  122. package/dist/mcp-root.d.ts +6 -4
  123. package/dist/mcp-root.d.ts.map +1 -1
  124. package/dist/mcp-root.js +12 -8
  125. package/dist/mcp-root.js.map +1 -1
  126. package/dist/mcp.d.ts.map +1 -1
  127. package/dist/mcp.js +40 -17
  128. package/dist/mcp.js.map +1 -1
  129. package/dist/migrate-layout.d.ts +41 -1
  130. package/dist/migrate-layout.d.ts.map +1 -1
  131. package/dist/migrate-layout.js +1729 -236
  132. package/dist/migrate-layout.js.map +1 -1
  133. package/dist/output-schemas.d.ts +34 -0
  134. package/dist/output-schemas.d.ts.map +1 -1
  135. package/dist/output-schemas.js +132 -21
  136. package/dist/output-schemas.js.map +1 -1
  137. package/dist/project-path.d.ts +6 -0
  138. package/dist/project-path.d.ts.map +1 -1
  139. package/dist/project-path.js +48 -14
  140. package/dist/project-path.js.map +1 -1
  141. package/dist/project-site.d.ts +7 -0
  142. package/dist/project-site.d.ts.map +1 -0
  143. package/dist/project-site.js +19 -0
  144. package/dist/project-site.js.map +1 -0
  145. package/dist/recipes/4.0.0.d.ts.map +1 -1
  146. package/dist/recipes/4.0.0.js +2 -0
  147. package/dist/recipes/4.0.0.js.map +1 -1
  148. package/dist/recipes/5.1.0.d.ts +9 -0
  149. package/dist/recipes/5.1.0.d.ts.map +1 -0
  150. package/dist/recipes/5.1.0.js +22 -0
  151. package/dist/recipes/5.1.0.js.map +1 -0
  152. package/dist/recipes/5.2.0.d.ts +10 -0
  153. package/dist/recipes/5.2.0.d.ts.map +1 -0
  154. package/dist/recipes/5.2.0.js +32 -0
  155. package/dist/recipes/5.2.0.js.map +1 -0
  156. package/dist/recipes/index.d.ts +3 -0
  157. package/dist/recipes/index.d.ts.map +1 -1
  158. package/dist/recipes/index.js +7 -0
  159. package/dist/recipes/index.js.map +1 -1
  160. package/dist/release-verification.d.ts +5 -0
  161. package/dist/release-verification.d.ts.map +1 -1
  162. package/dist/release-verification.js +14 -0
  163. package/dist/release-verification.js.map +1 -1
  164. package/dist/review.d.ts.map +1 -1
  165. package/dist/review.js +7 -0
  166. package/dist/review.js.map +1 -1
  167. package/dist/rule-explain.d.ts +26 -0
  168. package/dist/rule-explain.d.ts.map +1 -0
  169. package/dist/rule-explain.js +49 -0
  170. package/dist/rule-explain.js.map +1 -0
  171. package/dist/rules/codes.d.ts +5 -1
  172. package/dist/rules/codes.d.ts.map +1 -1
  173. package/dist/rules/codes.js +5 -1
  174. package/dist/rules/codes.js.map +1 -1
  175. package/dist/rules/contract-visibility.d.ts.map +1 -1
  176. package/dist/rules/contract-visibility.js +93 -21
  177. package/dist/rules/contract-visibility.js.map +1 -1
  178. package/dist/rules/data-guard.d.ts +6 -0
  179. package/dist/rules/data-guard.d.ts.map +1 -1
  180. package/dist/rules/data-guard.js +37 -0
  181. package/dist/rules/data-guard.js.map +1 -1
  182. package/dist/rules/explanations.d.ts +14 -0
  183. package/dist/rules/explanations.d.ts.map +1 -0
  184. package/dist/rules/explanations.js +316 -0
  185. package/dist/rules/explanations.js.map +1 -0
  186. package/dist/rules/legacy.d.ts.map +1 -1
  187. package/dist/rules/legacy.js +44 -2
  188. package/dist/rules/legacy.js.map +1 -1
  189. package/dist/rules/merge-auth.d.ts +12 -0
  190. package/dist/rules/merge-auth.d.ts.map +1 -0
  191. package/dist/rules/merge-auth.js +52 -0
  192. package/dist/rules/merge-auth.js.map +1 -0
  193. package/dist/rules/pages.d.ts +56 -3
  194. package/dist/rules/pages.d.ts.map +1 -1
  195. package/dist/rules/pages.js +412 -23
  196. package/dist/rules/pages.js.map +1 -1
  197. package/dist/rules/routes.d.ts +3 -2
  198. package/dist/rules/routes.d.ts.map +1 -1
  199. package/dist/rules/routes.js +4 -3
  200. package/dist/rules/routes.js.map +1 -1
  201. package/dist/rules/security.d.ts +3 -2
  202. package/dist/rules/security.d.ts.map +1 -1
  203. package/dist/rules/security.js +42 -11
  204. package/dist/rules/security.js.map +1 -1
  205. package/dist/rules/zones.d.ts.map +1 -1
  206. package/dist/rules/zones.js +34 -11
  207. package/dist/rules/zones.js.map +1 -1
  208. package/dist/stylex-migrate.d.ts.map +1 -1
  209. package/dist/stylex-migrate.js +127 -17
  210. package/dist/stylex-migrate.js.map +1 -1
  211. package/dist/test-tool.d.ts.map +1 -1
  212. package/dist/test-tool.js +3 -9
  213. package/dist/test-tool.js.map +1 -1
  214. package/dist/typecheck-coverage.d.ts +11 -0
  215. package/dist/typecheck-coverage.d.ts.map +1 -1
  216. package/dist/typecheck-coverage.js +50 -7
  217. package/dist/typecheck-coverage.js.map +1 -1
  218. package/dist/upgrade.d.ts +57 -6
  219. package/dist/upgrade.d.ts.map +1 -1
  220. package/dist/upgrade.js +247 -19
  221. package/dist/upgrade.js.map +1 -1
  222. package/dist/verification-plan.d.ts.map +1 -1
  223. package/dist/verification-plan.js +7 -2
  224. package/dist/verification-plan.js.map +1 -1
  225. package/dist/version-drift.d.ts.map +1 -1
  226. package/dist/version-drift.js +66 -3
  227. package/dist/version-drift.js.map +1 -1
  228. package/dist/web-app-options.d.ts +1 -1
  229. package/dist/web-app-options.d.ts.map +1 -1
  230. package/dist/web-app-options.js.map +1 -1
  231. package/docs/examples.json +21 -3
  232. package/docs/llms-full.txt +1083 -168
  233. package/docs/types.json +535 -112
  234. package/package.json +13 -12
  235. package/src/agent-files.ts +27 -17
  236. package/src/assure-hydration.ts +5 -1
  237. package/src/assure.ts +99 -11
  238. package/src/capabilities-tool.ts +188 -53
  239. package/src/check-diagnostics.ts +10 -0
  240. package/src/check-scan.ts +65 -12
  241. package/src/check.ts +122 -51
  242. package/src/cli.ts +127 -45
  243. package/src/client-module.ts +45 -9
  244. package/src/command-catalog.ts +92 -28
  245. package/src/dev-bun-config.ts +13 -9
  246. package/src/dev-feed-tool.ts +146 -1
  247. package/src/doctor.ts +102 -66
  248. package/src/fix-recipes.ts +101 -10
  249. package/src/i18n-check.ts +254 -18
  250. package/src/init-agents.ts +225 -44
  251. package/src/internal/config-paths.ts +154 -0
  252. package/src/internal/installed-package.ts +15 -0
  253. package/src/internal/project-specifiers.ts +78 -17
  254. package/src/internal/source-facts.ts +147 -5
  255. package/src/internal/typescript-import.ts +5 -3
  256. package/src/internal/workspace-packages.ts +218 -0
  257. package/src/introspect.ts +39 -1
  258. package/src/levels-tool.ts +7 -9
  259. package/src/load.ts +46 -4
  260. package/src/lock-links.ts +173 -0
  261. package/src/mcp-context.ts +5 -18
  262. package/src/mcp-delegate.ts +22 -10
  263. package/src/mcp-exec.ts +14 -4
  264. package/src/mcp-http.ts +1 -1
  265. package/src/mcp-io.ts +33 -0
  266. package/src/mcp-path.ts +8 -22
  267. package/src/mcp-root.ts +14 -8
  268. package/src/mcp.ts +48 -19
  269. package/src/migrate-layout.ts +1968 -245
  270. package/src/output-schemas.ts +179 -23
  271. package/src/project-path.ts +44 -13
  272. package/src/project-site.ts +18 -0
  273. package/src/recipes/4.0.0.ts +2 -0
  274. package/src/recipes/5.1.0.ts +23 -0
  275. package/src/recipes/5.2.0.ts +33 -0
  276. package/src/recipes/index.ts +7 -0
  277. package/src/release-verification.ts +20 -0
  278. package/src/review.ts +7 -0
  279. package/src/rule-explain.ts +75 -0
  280. package/src/rules/codes.ts +5 -1
  281. package/src/rules/contract-visibility.ts +118 -20
  282. package/src/rules/data-guard.ts +40 -0
  283. package/src/rules/explanations.ts +329 -0
  284. package/src/rules/legacy.ts +46 -2
  285. package/src/rules/merge-auth.ts +55 -0
  286. package/src/rules/pages.ts +486 -25
  287. package/src/rules/routes.ts +4 -3
  288. package/src/rules/security.ts +49 -11
  289. package/src/rules/zones.ts +33 -9
  290. package/src/stylex-migrate.ts +117 -17
  291. package/src/test-tool.ts +3 -9
  292. package/src/typecheck-coverage.ts +51 -6
  293. package/src/upgrade.ts +312 -19
  294. package/src/verification-plan.ts +15 -2
  295. package/src/version-drift.ts +68 -2
  296. package/src/web-app-options.ts +9 -1
package/src/mcp-path.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { realpathSync } from "node:fs"
2
- import { basename, isAbsolute, relative, resolve } from "node:path"
2
+ import { isAbsolute, relative, resolve } from "node:path"
3
+ import { writeTargetOf } from "./project-path.ts"
3
4
 
4
5
  /**
5
6
  * Resolve an MCP path without allowing lexical or symlink escapes from the selected project.
6
7
  *
7
8
  * MCP callers are not equivalent to a local CLI user: the selected checkout is their filesystem
8
9
  * capability boundary. The nearest-existing-ancestor walk also supports output files that do not
9
- * exist yet while still canonicalizing every existing path component.
10
+ * exist yet while still canonicalizing every existing path component, and a dangling symlink is
11
+ * judged by where it points.
10
12
  */
11
13
  export function resolveMcpProjectPath(root: string, value: string): string | null {
12
14
  if (value.length === 0 || isAbsolute(value)) return null
@@ -23,26 +25,10 @@ export function resolveMcpProjectPath(root: string, value: string): string | nul
23
25
  return null
24
26
  }
25
27
 
26
- let probe = target
27
- const missing: string[] = []
28
- while (true) {
29
- try {
30
- const canonicalProbe = realpathSync(probe)
31
- const canonicalRelative = relative(canonicalRoot, canonicalProbe)
32
- if (canonicalRelative.startsWith("..") || isAbsolute(canonicalRelative)) return null
33
-
34
- const candidate = resolve(canonicalProbe, ...missing.reverse())
35
- const candidateRelative = relative(canonicalRoot, candidate)
36
- return candidateRelative.startsWith("..") || isAbsolute(candidateRelative) ? null : candidate
37
- } catch (error) {
38
- if (!(error && typeof error === "object" && (error as { code?: string }).code === "ENOENT"))
39
- return null
40
- const parent = resolve(probe, "..")
41
- if (parent === probe) return null
42
- missing.push(basename(probe))
43
- probe = parent
44
- }
45
- }
28
+ const candidate = writeTargetOf(target)
29
+ if (candidate === undefined) return null
30
+ const candidateRelative = relative(canonicalRoot, candidate)
31
+ return candidateRelative.startsWith("..") || isAbsolute(candidateRelative) ? null : candidate
46
32
  }
47
33
 
48
34
  export function mcpProjectPathError(label: string, value: string): string {
package/src/mcp-root.ts CHANGED
@@ -156,13 +156,13 @@ const isFile = (path: string): Promise<boolean> =>
156
156
  .catch(() => false)
157
157
 
158
158
  /**
159
- * The nifra projects among `dir`'s package-manager workspace members, in declaration order. Empty when
160
- * `dir` declares no `workspaces`. A member is a directory a pattern matches that holds a `package.json`;
161
- * `node_modules` is never a member.
159
+ * `dir`'s package-manager workspace members, in declaration order; `null` when `dir` declares no
160
+ * `workspaces`. A member is a directory a pattern matches that holds a `package.json`; `node_modules`
161
+ * is never a member.
162
162
  */
163
- export async function workspaceProjects(dir: string): Promise<string[]> {
163
+ export async function workspaceMemberDirs(dir: string): Promise<string[] | null> {
164
164
  const patterns = await workspacePatterns(dir)
165
- if (patterns === null) return []
165
+ if (patterns === null) return null
166
166
  const members = new Set<string>()
167
167
  const budget = { directories: MAX_WORKSPACE_DIRECTORIES }
168
168
  for (const pattern of patterns) {
@@ -171,8 +171,14 @@ export async function workspaceProjects(dir: string): Promise<string[]> {
171
171
  members.add(join(dir, member))
172
172
  }
173
173
  }
174
+ return [...members]
175
+ }
176
+
177
+ /** The nifra projects among `dir`'s workspace members, in declaration order. */
178
+ export async function workspaceProjects(dir: string): Promise<string[]> {
174
179
  const projects: string[] = []
175
- for (const member of members) if (await isNifraProjectDir(member)) projects.push(member)
180
+ for (const member of (await workspaceMemberDirs(dir)) ?? [])
181
+ if (await isNifraProjectDir(member)) projects.push(member)
176
182
  return projects
177
183
  }
178
184
 
@@ -376,7 +382,7 @@ export interface ToolingDrift {
376
382
  export const driftNote = (drift: ToolingDrift): string =>
377
383
  `WARNING: this server runs nifra CLI ${drift.cli}, but the project installs ${drift.package} ${drift.project}. ` +
378
384
  "Types, checks, and docs may describe a different version than your code builds with. " +
379
- `Fix: re-pin the project's MCP launch to the nifra it installs with \`${syncMcpCommand(drift.cli)}\` (run in the project directory), then restart the agent. ` +
385
+ `Fix: point the project's MCP launch at the nifra it installs with \`${syncMcpCommand(drift.cli)}\` (run in the project directory), then restart the agent. ` +
380
386
  "If this server is not launched from the project's .mcp.json, run the project's own CLI instead (`bunx --bun nifra mcp` from the project directory, or point the client at ./node_modules/.bin/nifra)."
381
387
 
382
388
  /** Feature-level agreement. Patch drift is not reported: it never changes the surface being described. */
@@ -434,7 +440,7 @@ export async function installedNifraVersion(
434
440
  return undefined
435
441
  }
436
442
 
437
- /** The command that re-pins a project's MCP launch to the nifra it installs. Named with the running
443
+ /** The command that points a project's MCP launch at the nifra it installs. Named with the running
438
444
  * CLI's own exact version: the binary printing this is the one known to have `--sync-mcp`, and it pins
439
445
  * to the project's version, not its own. */
440
446
  export const syncMcpCommand = (cliVersion: string): string =>
package/src/mcp.ts CHANGED
@@ -181,6 +181,13 @@ function appFeatures(cwd: string, surface: IsolatedSurface): McpServerFeatures {
181
181
  }
182
182
 
183
183
  const ROOTS_REQUEST_ID = "nifra:roots/list"
184
+ /** Messages whose answer reads nothing the app declares: the handshake is never held up by its import. */
185
+ const ANSWERED_WITHOUT_THE_APP: ReadonlySet<string> = new Set([
186
+ "initialize",
187
+ "ping",
188
+ "notifications/initialized",
189
+ "notifications/roots/list_changed",
190
+ ])
184
191
  const MAX_STDIO_MESSAGE_BYTES = 8 * 1024 * 1024
185
192
  const STDIO_ENCODER = new TextEncoder()
186
193
 
@@ -207,8 +214,12 @@ async function createProjectContext(root: string): Promise<ProjectContext> {
207
214
  )
208
215
  const allResources: McpResource[] = []
209
216
  const allPrompts: McpPrompt[] = []
210
- for (const { name, cwd: appCwd, surface } of apps) {
211
- const ns = namespaceForApp(name, [], appFeatures(appCwd, await surface()))
217
+ // Each app loads in its own subprocess, so they load side by side.
218
+ const loaded = await Promise.all(
219
+ apps.map(async (app) => ({ app, surface: await app.surface() })),
220
+ )
221
+ for (const { app, surface } of loaded) {
222
+ const ns = namespaceForApp(app.name, [], appFeatures(app.cwd, surface))
212
223
  allResources.push(...(ns.features.resources ?? []))
213
224
  allPrompts.push(...(ns.features.prompts ?? []))
214
225
  }
@@ -251,7 +262,9 @@ export async function runMcpServer(
251
262
  return
252
263
  }
253
264
  }
254
- let ctx = await createProjectContext(rootState.root)
265
+ // Loaded in the background: the app's import can take seconds, and the handshake needs none of it.
266
+ let ctx = createProjectContext(rootState.root)
267
+ ctx.catch(() => {})
255
268
  let drift: ToolingDrift | undefined = await detectToolingDrift(rootState.root, version)
256
269
  const serverInfo = { name: "nifra", version }
257
270
  const state = createMcpProtocolState()
@@ -286,7 +299,8 @@ export async function runMcpServer(
286
299
  if (result === undefined) return
287
300
  const next = await applyClientRoots(rootState, pathsFromRootsResult(result))
288
301
  if (next.root !== rootState.root) {
289
- ctx = await createProjectContext(next.root)
302
+ ctx = createProjectContext(next.root)
303
+ ctx.catch(() => {})
290
304
  drift = await detectToolingDrift(next.root, version)
291
305
  }
292
306
  rootState = next
@@ -313,15 +327,38 @@ export async function runMcpServer(
313
327
  // the code it started with: re-read the installed version per call so no answer is for a stale one.
314
328
  if (message.method === "tools/call") drift = await detectToolingDrift(rootState.root, version)
315
329
 
330
+ const method = message.method ?? ""
331
+ if (ANSWERED_WITHOUT_THE_APP.has(method)) {
332
+ const response = await handleRpc(
333
+ message,
334
+ [],
335
+ serverInfo,
336
+ {
337
+ resources: projectResources(rootState.root, noAppInServer),
338
+ prompts: projectPrompts(),
339
+ instructions: rootInstructions(rootState, drift),
340
+ },
341
+ { state, sendNotification: send, exposeToolErrors: true },
342
+ )
343
+ if (response) send(response)
344
+ // Ask for the client's workspace roots once the handshake completes, and again whenever the
345
+ // client says they changed. The answer comes back through the interception above.
346
+ if (method.startsWith("notifications/")) requestRoots()
347
+ return
348
+ }
349
+ const project = await ctx
316
350
  let activeTools: McpTool[]
317
- if (ctx.apps) {
351
+ if (project.apps) {
352
+ const loaded = await Promise.all(
353
+ project.apps.map(async (app) => ({ app, surface: await app.surface() })),
354
+ )
318
355
  const allTools: McpTool[] = []
319
- for (const { name, cwd: appCwd, surface } of ctx.apps) {
356
+ for (const { app, surface } of loaded) {
320
357
  const tools = [
321
- ...refuseVersionSensitive(isolatedProjectTools(appCwd), drift),
322
- ...(await surface()).tools,
358
+ ...refuseVersionSensitive(isolatedProjectTools(app.cwd), drift),
359
+ ...surface.tools,
323
360
  ]
324
- const ns = namespaceForApp(name, tools, { resources: [], prompts: [] })
361
+ const ns = namespaceForApp(app.name, tools, { resources: [], prompts: [] })
325
362
  allTools.push(...ns.tools)
326
363
  }
327
364
  activeTools = [
@@ -334,7 +371,7 @@ export async function runMcpServer(
334
371
  } else {
335
372
  activeTools = [
336
373
  ...refuseVersionSensitive(isolatedProjectTools(rootState.root), drift),
337
- ...(await ctx.surface()).tools,
374
+ ...(await project.surface()).tools,
338
375
  ]
339
376
  }
340
377
  const verdict = await rootVerdict(rootState)
@@ -346,7 +383,7 @@ export async function runMcpServer(
346
383
  )
347
384
 
348
385
  const features: McpServerFeatures = {
349
- ...ctx.features,
386
+ ...project.features,
350
387
  instructions: rootInstructions(rootState, drift),
351
388
  }
352
389
  const response = await handleRpc(message, activeTools, serverInfo, features, {
@@ -356,14 +393,6 @@ export async function runMcpServer(
356
393
  exposeToolErrors: true,
357
394
  })
358
395
  if (response) send(response)
359
- // Ask for the client's workspace roots once the handshake completes, and again whenever the
360
- // client says they changed. The answer comes back through the interception above.
361
- if (
362
- message.method === "notifications/initialized" ||
363
- message.method === "notifications/roots/list_changed"
364
- ) {
365
- requestRoots()
366
- }
367
396
  }
368
397
 
369
398
  const decoder = new TextDecoder()