@pugi/cli 0.1.0-beta.99 → 1.0.0-alpha.10

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 (448) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +11 -191
  3. package/bin/pugi +8 -0
  4. package/package.json +15 -71
  5. package/postinstall.mjs +31 -0
  6. package/CHANGELOG.md +0 -132
  7. package/THIRD_PARTY_NOTICES.md +0 -40
  8. package/assets/pugi-mascot.ansi +0 -16
  9. package/assets/pugi-prozr2-mascot.ansi +0 -9
  10. package/bin/run.js +0 -34
  11. package/dist/commands/deploy.js +0 -439
  12. package/dist/commands/flatten.js +0 -191
  13. package/dist/commands/jobs-watch.js +0 -201
  14. package/dist/commands/jobs.js +0 -260
  15. package/dist/commands/retro.js +0 -210
  16. package/dist/commands/smoke.js +0 -133
  17. package/dist/core/agent-progress/cleanup.js +0 -134
  18. package/dist/core/agent-progress/schema.js +0 -144
  19. package/dist/core/agent-progress/writer.js +0 -101
  20. package/dist/core/agents/adaptive-router.js +0 -330
  21. package/dist/core/agents/loader.js +0 -104
  22. package/dist/core/agents/query-decomposer.js +0 -297
  23. package/dist/core/agents/registry.js +0 -69
  24. package/dist/core/approvals/shortcut-resolver.js +0 -98
  25. package/dist/core/artifact-chain/dispatcher.js +0 -148
  26. package/dist/core/artifact-chain/exporter.js +0 -164
  27. package/dist/core/artifact-chain/state.js +0 -243
  28. package/dist/core/artifact-chain/steps.js +0 -169
  29. package/dist/core/ask-user/question.js +0 -92
  30. package/dist/core/audit/audit-trail.js +0 -275
  31. package/dist/core/auth/ensure-authenticated.js +0 -129
  32. package/dist/core/auth/env-provider.js +0 -238
  33. package/dist/core/auto-open-browser.js +0 -128
  34. package/dist/core/auto-update/channels.js +0 -122
  35. package/dist/core/auto-update/checker.js +0 -241
  36. package/dist/core/auto-update/state.js +0 -235
  37. package/dist/core/bare-mode/index.js +0 -107
  38. package/dist/core/bash/redirect.js +0 -281
  39. package/dist/core/bash-classifier.js +0 -1397
  40. package/dist/core/checkpoint/resumer.js +0 -149
  41. package/dist/core/checkpoint/rewinder.js +0 -291
  42. package/dist/core/checkpoints/shadow-git.js +0 -670
  43. package/dist/core/citations/parser.js +0 -109
  44. package/dist/core/classifier/yolo-classifier.js +0 -88
  45. package/dist/core/clipboard.js +0 -70
  46. package/dist/core/codegraph/decision-store.js +0 -248
  47. package/dist/core/codegraph/detect-repo.js +0 -459
  48. package/dist/core/codegraph/install.js +0 -134
  49. package/dist/core/codegraph/offer-hook.js +0 -220
  50. package/dist/core/compact/auto-trigger.js +0 -96
  51. package/dist/core/compact/buffer-rewriter.js +0 -115
  52. package/dist/core/compact/summarizer.js +0 -208
  53. package/dist/core/compact/token-counter.js +0 -108
  54. package/dist/core/consensus/anvil-fanout.js +0 -276
  55. package/dist/core/consensus/diff-capture.js +0 -491
  56. package/dist/core/consensus/rubric.js +0 -233
  57. package/dist/core/context/builder.js +0 -114
  58. package/dist/core/context/compaction-events.js +0 -99
  59. package/dist/core/context/compaction.js +0 -602
  60. package/dist/core/context/index.js +0 -28
  61. package/dist/core/context/invariants.js +0 -250
  62. package/dist/core/context/markdown-loader.js +0 -288
  63. package/dist/core/context/markdown-traverse.js +0 -255
  64. package/dist/core/context/pugiignore.js +0 -316
  65. package/dist/core/context/repo-skeleton.js +0 -533
  66. package/dist/core/context/tool-eviction.js +0 -55
  67. package/dist/core/context/watcher.js +0 -342
  68. package/dist/core/context/working-set.js +0 -165
  69. package/dist/core/coordinator/agent-tools.js +0 -77
  70. package/dist/core/coordinator/agent-toolset.js +0 -65
  71. package/dist/core/coordinator/fsm.js +0 -73
  72. package/dist/core/coordinator/mode-fsm.js +0 -70
  73. package/dist/core/cost/rate-card.js +0 -129
  74. package/dist/core/cost/tracker.js +0 -221
  75. package/dist/core/credentials.js +0 -355
  76. package/dist/core/cron/scheduler.js +0 -138
  77. package/dist/core/denial-tracking/index.js +0 -8
  78. package/dist/core/denial-tracking/state.js +0 -264
  79. package/dist/core/diagnostics/probe-runner.js +0 -93
  80. package/dist/core/diagnostics/probes/api.js +0 -46
  81. package/dist/core/diagnostics/probes/auth.js +0 -93
  82. package/dist/core/diagnostics/probes/bare-mode.js +0 -42
  83. package/dist/core/diagnostics/probes/cli-version.js +0 -127
  84. package/dist/core/diagnostics/probes/config.js +0 -72
  85. package/dist/core/diagnostics/probes/denial-tracking.js +0 -57
  86. package/dist/core/diagnostics/probes/disk.js +0 -81
  87. package/dist/core/diagnostics/probes/engine-live.js +0 -46
  88. package/dist/core/diagnostics/probes/git.js +0 -65
  89. package/dist/core/diagnostics/probes/hooks.js +0 -118
  90. package/dist/core/diagnostics/probes/mcp.js +0 -75
  91. package/dist/core/diagnostics/probes/node.js +0 -59
  92. package/dist/core/diagnostics/probes/pnpm.js +0 -36
  93. package/dist/core/diagnostics/probes/pugi-md.js +0 -89
  94. package/dist/core/diagnostics/probes/sandbox.js +0 -72
  95. package/dist/core/diagnostics/probes/session.js +0 -74
  96. package/dist/core/diagnostics/probes/status-snapshot.js +0 -488
  97. package/dist/core/diagnostics/probes/workspace.js +0 -63
  98. package/dist/core/diagnostics/types.js +0 -70
  99. package/dist/core/dispatch/cache-cleanup.js +0 -197
  100. package/dist/core/dispatch/cache-handoff.js +0 -295
  101. package/dist/core/edits/apply-patch-layer-e.js +0 -189
  102. package/dist/core/edits/dispatch.js +0 -511
  103. package/dist/core/edits/format-detector.js +0 -260
  104. package/dist/core/edits/format-matrix.js +0 -26
  105. package/dist/core/edits/fuzzy-ladder.js +0 -650
  106. package/dist/core/edits/index.js +0 -19
  107. package/dist/core/edits/journal.js +0 -199
  108. package/dist/core/edits/layer-a-apply.js +0 -217
  109. package/dist/core/edits/layer-a-fuzzy-apply.js +0 -198
  110. package/dist/core/edits/layer-b-apply.js +0 -211
  111. package/dist/core/edits/layer-c-apply.js +0 -160
  112. package/dist/core/edits/layer-d-ast.js +0 -572
  113. package/dist/core/edits/marker-parser.js +0 -401
  114. package/dist/core/edits/security-gate.js +0 -223
  115. package/dist/core/edits/verify-hook.js +0 -273
  116. package/dist/core/edits/worktree.js +0 -322
  117. package/dist/core/engine/adapter-runner.js +0 -8
  118. package/dist/core/engine/anvil-client.js +0 -344
  119. package/dist/core/engine/auto-compact.js +0 -179
  120. package/dist/core/engine/budgets.js +0 -195
  121. package/dist/core/engine/context-prefix.js +0 -155
  122. package/dist/core/engine/index.js +0 -12
  123. package/dist/core/engine/intensity.js +0 -163
  124. package/dist/core/engine/intent.js +0 -260
  125. package/dist/core/engine/native-pugi.js +0 -1616
  126. package/dist/core/engine/noop.js +0 -27
  127. package/dist/core/engine/prompts.js +0 -236
  128. package/dist/core/engine/strip-internal-fields.js +0 -124
  129. package/dist/core/engine/tool-bridge.js +0 -2173
  130. package/dist/core/engine/verification-patterns.js +0 -195
  131. package/dist/core/evaluation/golden-dataset.js +0 -293
  132. package/dist/core/feedback/queue.js +0 -177
  133. package/dist/core/feedback/submitter.js +0 -145
  134. package/dist/core/file-cache.js +0 -141
  135. package/dist/core/flatten/flatten-repo.js +0 -439
  136. package/dist/core/format/osc8-link.js +0 -28
  137. package/dist/core/hook-chains.js +0 -392
  138. package/dist/core/hooks/citation-verify-hook.js +0 -138
  139. package/dist/core/hooks/citation-verify.js +0 -112
  140. package/dist/core/hooks/events.js +0 -46
  141. package/dist/core/hooks/index.js +0 -15
  142. package/dist/core/hooks/registry.js +0 -216
  143. package/dist/core/hooks/runner.js +0 -236
  144. package/dist/core/hooks/v2/event-emitter.js +0 -115
  145. package/dist/core/hooks/v2/executor.js +0 -282
  146. package/dist/core/hooks/v2/index.js +0 -25
  147. package/dist/core/hooks/v2/lifecycle.js +0 -104
  148. package/dist/core/hooks/v2/loader.js +0 -216
  149. package/dist/core/hooks/v2/matcher.js +0 -125
  150. package/dist/core/hooks/v2/trust.js +0 -143
  151. package/dist/core/hooks/v2/types.js +0 -86
  152. package/dist/core/hooks/worktree-events.js +0 -158
  153. package/dist/core/hooks.js +0 -415
  154. package/dist/core/image/renderer.js +0 -71
  155. package/dist/core/index-store.js +0 -260
  156. package/dist/core/init/detector.js +0 -582
  157. package/dist/core/init/template-renderer.js +0 -242
  158. package/dist/core/jobs/registry.js +0 -462
  159. package/dist/core/ledger/results-tsv.js +0 -142
  160. package/dist/core/log-discipline/stdout-redirect.js +0 -51
  161. package/dist/core/lsp/cache.js +0 -105
  162. package/dist/core/lsp/client.js +0 -1229
  163. package/dist/core/lsp/language-detect.js +0 -66
  164. package/dist/core/lsp/post-edit-diagnostics.js +0 -171
  165. package/dist/core/lsp/server-detect.js +0 -173
  166. package/dist/core/lsp/symbol-cache.js +0 -162
  167. package/dist/core/lsp/symbol-tools.js +0 -664
  168. package/dist/core/mcp/client.js +0 -385
  169. package/dist/core/mcp/http-server.js +0 -553
  170. package/dist/core/mcp/orchestrator-config.js +0 -192
  171. package/dist/core/mcp/orchestrator-tools.js +0 -806
  172. package/dist/core/mcp/permission.js +0 -190
  173. package/dist/core/mcp/registry.js +0 -193
  174. package/dist/core/mcp/server-tools.js +0 -219
  175. package/dist/core/mcp/server.js +0 -397
  176. package/dist/core/mcp/trust.js +0 -91
  177. package/dist/core/memory/dual-write.js +0 -416
  178. package/dist/core/memory/passive-extract.js +0 -130
  179. package/dist/core/memory/phase1-kinds.js +0 -20
  180. package/dist/core/memory/secret-scanner.js +0 -304
  181. package/dist/core/memory-sync/queue.js +0 -170
  182. package/dist/core/metrics/extract.js +0 -113
  183. package/dist/core/modes/roo-modes.js +0 -68
  184. package/dist/core/onboarding/ensure-initialized.js +0 -133
  185. package/dist/core/onboarding/marker.js +0 -111
  186. package/dist/core/onboarding/telemetry-state.js +0 -108
  187. package/dist/core/output-style/presets.js +0 -176
  188. package/dist/core/output-style/state.js +0 -185
  189. package/dist/core/path-security.js +0 -345
  190. package/dist/core/permission.js +0 -369
  191. package/dist/core/permissions/auto-classifier.js +0 -124
  192. package/dist/core/permissions/bash-parser.js +0 -371
  193. package/dist/core/permissions/circuit-breaker.js +0 -83
  194. package/dist/core/permissions/constrained-edit.js +0 -91
  195. package/dist/core/permissions/gate.js +0 -278
  196. package/dist/core/permissions/index.js +0 -20
  197. package/dist/core/permissions/mode.js +0 -174
  198. package/dist/core/permissions/network-egress.js +0 -137
  199. package/dist/core/permissions/state.js +0 -241
  200. package/dist/core/permissions/tool-class.js +0 -107
  201. package/dist/core/plan-mode/ui-state.js +0 -51
  202. package/dist/core/plans/plan-artifact.js +0 -721
  203. package/dist/core/policy-limits/etag-store.js +0 -122
  204. package/dist/core/prd-check/parser.js +0 -215
  205. package/dist/core/prd-check/reporter.js +0 -127
  206. package/dist/core/prd-check/session-review.js +0 -557
  207. package/dist/core/prd-check/verifiers.js +0 -223
  208. package/dist/core/prompt-cache/client-cache.js +0 -99
  209. package/dist/core/prompts/assembly.js +0 -29
  210. package/dist/core/prompts/registry.js +0 -364
  211. package/dist/core/pugi-gitignore.js +0 -52
  212. package/dist/core/pugi-md/cc-compat-rules.js +0 -735
  213. package/dist/core/pugi-md/context-injector.js +0 -76
  214. package/dist/core/pugi-md/walk-up.js +0 -207
  215. package/dist/core/python/uv-installer.js +0 -270
  216. package/dist/core/python/uv-resolver.js +0 -83
  217. package/dist/core/rate-limit/narrator.js +0 -146
  218. package/dist/core/recipes/cli-types.js +0 -20
  219. package/dist/core/recipes/loader.js +0 -103
  220. package/dist/core/recipes/runner.js +0 -345
  221. package/dist/core/recipes/schema.js +0 -587
  222. package/dist/core/release-notes/parser.js +0 -241
  223. package/dist/core/release-notes/state.js +0 -116
  224. package/dist/core/repl/ask.js +0 -512
  225. package/dist/core/repl/cancellation.js +0 -98
  226. package/dist/core/repl/cap-warning.js +0 -91
  227. package/dist/core/repl/clipboard-read.js +0 -174
  228. package/dist/core/repl/dispatch-fsm.js +0 -220
  229. package/dist/core/repl/engine-bridge.js +0 -303
  230. package/dist/core/repl/history-search.js +0 -175
  231. package/dist/core/repl/history.js +0 -182
  232. package/dist/core/repl/kill-ring.js +0 -138
  233. package/dist/core/repl/model-pricing.js +0 -135
  234. package/dist/core/repl/privacy-banner.js +0 -71
  235. package/dist/core/repl/session.js +0 -4962
  236. package/dist/core/repl/slash-commands.js +0 -747
  237. package/dist/core/repl/store/index.js +0 -12
  238. package/dist/core/repl/store/jsonl-log.js +0 -321
  239. package/dist/core/repl/store/lockfile.js +0 -155
  240. package/dist/core/repl/store/session-store.js +0 -821
  241. package/dist/core/repl/store/types.js +0 -44
  242. package/dist/core/repl/store/uuid-v7.js +0 -68
  243. package/dist/core/repl/tool-route.js +0 -382
  244. package/dist/core/repl/workspace-context.js +0 -206
  245. package/dist/core/repo-map/build.js +0 -125
  246. package/dist/core/repo-map/cache.js +0 -185
  247. package/dist/core/repo-map/extractor.js +0 -254
  248. package/dist/core/repo-map/formatter.js +0 -145
  249. package/dist/core/repo-map/page-rank.js +0 -105
  250. package/dist/core/repo-map/scanner.js +0 -211
  251. package/dist/core/retro/git-collector.js +0 -251
  252. package/dist/core/retro/health-card.js +0 -25
  253. package/dist/core/retro/metrics.js +0 -342
  254. package/dist/core/retro/narrative.js +0 -249
  255. package/dist/core/retro/plane-collector.js +0 -274
  256. package/dist/core/retro/pr-issue-link.js +0 -65
  257. package/dist/core/retro/types.js +0 -16
  258. package/dist/core/retry-budget/budget.js +0 -284
  259. package/dist/core/retry-budget/index.js +0 -5
  260. package/dist/core/retry-budget/retry-cap.js +0 -74
  261. package/dist/core/routing/lead-worker.js +0 -43
  262. package/dist/core/routing/pre-flight-estimator.js +0 -108
  263. package/dist/core/runs/run-tree.js +0 -103
  264. package/dist/core/sandboxing/adapter.js +0 -29
  265. package/dist/core/sandboxing/index.js +0 -49
  266. package/dist/core/sandboxing/none.js +0 -19
  267. package/dist/core/sandboxing/seatbelt.js +0 -183
  268. package/dist/core/security/injection-scanner.js +0 -367
  269. package/dist/core/security/output-filter.js +0 -418
  270. package/dist/core/session/env-file.js +0 -105
  271. package/dist/core/session/section-budgets.js +0 -140
  272. package/dist/core/session.js +0 -377
  273. package/dist/core/settings.js +0 -400
  274. package/dist/core/share/formatter.js +0 -271
  275. package/dist/core/share/redactor.js +0 -221
  276. package/dist/core/share/uploader.js +0 -267
  277. package/dist/core/skills/defaults.js +0 -457
  278. package/dist/core/skills/loader.js +0 -454
  279. package/dist/core/skills/sources.js +0 -480
  280. package/dist/core/skills/trust.js +0 -172
  281. package/dist/core/smoke/headless-driver.js +0 -174
  282. package/dist/core/smoke/orchestrator.js +0 -194
  283. package/dist/core/smoke/runner.js +0 -238
  284. package/dist/core/smoke/scenario-parser.js +0 -316
  285. package/dist/core/statusline.js +0 -99
  286. package/dist/core/subagents/dispatcher-real.js +0 -600
  287. package/dist/core/subagents/dispatcher.js +0 -352
  288. package/dist/core/subagents/index.js +0 -39
  289. package/dist/core/subagents/isolation-matrix.js +0 -213
  290. package/dist/core/subagents/spawn.js +0 -101
  291. package/dist/core/telemetry/emitter.js +0 -229
  292. package/dist/core/telemetry/queue.js +0 -251
  293. package/dist/core/theme/context.js +0 -91
  294. package/dist/core/theme/presets.js +0 -228
  295. package/dist/core/theme/state.js +0 -181
  296. package/dist/core/todos/invariant.js +0 -10
  297. package/dist/core/todos/state.js +0 -177
  298. package/dist/core/tool-schema/compressor.js +0 -89
  299. package/dist/core/transport/version-interceptor.js +0 -166
  300. package/dist/core/trust.js +0 -109
  301. package/dist/core/tui/thinking-block.js +0 -64
  302. package/dist/core/vim/keymap.js +0 -288
  303. package/dist/core/vim/state.js +0 -92
  304. package/dist/core/watch-markers/marker-watcher.js +0 -133
  305. package/dist/core/worktree/include-parser.js +0 -249
  306. package/dist/core/worktree-manager/cleanup.js +0 -123
  307. package/dist/core/worktree-manager/manager.js +0 -303
  308. package/dist/index.js +0 -44
  309. package/dist/runtime/bootstrap.js +0 -190
  310. package/dist/runtime/cli.js +0 -8121
  311. package/dist/runtime/commands/agents.js +0 -385
  312. package/dist/runtime/commands/budget.js +0 -192
  313. package/dist/runtime/commands/cancel.js +0 -231
  314. package/dist/runtime/commands/chain.js +0 -489
  315. package/dist/runtime/commands/codegraph-status.js +0 -227
  316. package/dist/runtime/commands/compact.js +0 -297
  317. package/dist/runtime/commands/config.js +0 -595
  318. package/dist/runtime/commands/cost.js +0 -199
  319. package/dist/runtime/commands/delegate.js +0 -312
  320. package/dist/runtime/commands/dispatch.js +0 -126
  321. package/dist/runtime/commands/doctor.js +0 -579
  322. package/dist/runtime/commands/feedback.js +0 -184
  323. package/dist/runtime/commands/hooks.js +0 -187
  324. package/dist/runtime/commands/init.js +0 -254
  325. package/dist/runtime/commands/lsp.js +0 -368
  326. package/dist/runtime/commands/mcp.js +0 -935
  327. package/dist/runtime/commands/memory.js +0 -582
  328. package/dist/runtime/commands/model.js +0 -237
  329. package/dist/runtime/commands/onboarding.js +0 -275
  330. package/dist/runtime/commands/patch.js +0 -128
  331. package/dist/runtime/commands/permissions.js +0 -112
  332. package/dist/runtime/commands/plan.js +0 -143
  333. package/dist/runtime/commands/prd-check.js +0 -285
  334. package/dist/runtime/commands/privacy.js +0 -107
  335. package/dist/runtime/commands/recipe.js +0 -325
  336. package/dist/runtime/commands/redo-blob-store.js +0 -92
  337. package/dist/runtime/commands/redo.js +0 -361
  338. package/dist/runtime/commands/release-notes.js +0 -229
  339. package/dist/runtime/commands/repo-map.js +0 -95
  340. package/dist/runtime/commands/report.js +0 -299
  341. package/dist/runtime/commands/resume.js +0 -118
  342. package/dist/runtime/commands/review-consensus.js +0 -414
  343. package/dist/runtime/commands/rewind.js +0 -333
  344. package/dist/runtime/commands/roster.js +0 -117
  345. package/dist/runtime/commands/sessions.js +0 -163
  346. package/dist/runtime/commands/share.js +0 -316
  347. package/dist/runtime/commands/skills.js +0 -401
  348. package/dist/runtime/commands/status.js +0 -186
  349. package/dist/runtime/commands/stickers.js +0 -82
  350. package/dist/runtime/commands/style.js +0 -194
  351. package/dist/runtime/commands/theme.js +0 -196
  352. package/dist/runtime/commands/undo.js +0 -361
  353. package/dist/runtime/commands/update.js +0 -289
  354. package/dist/runtime/commands/vim.js +0 -140
  355. package/dist/runtime/commands/worktree.js +0 -177
  356. package/dist/runtime/commands/worktrees.js +0 -155
  357. package/dist/runtime/deprecation-warning.js +0 -69
  358. package/dist/runtime/engine-exit-code.js +0 -50
  359. package/dist/runtime/headless-repl.js +0 -195
  360. package/dist/runtime/headless.js +0 -548
  361. package/dist/runtime/load-hooks-or-exit.js +0 -71
  362. package/dist/runtime/plan-decompose.js +0 -531
  363. package/dist/runtime/sigint-guard.js +0 -272
  364. package/dist/runtime/stream-renderer.js +0 -195
  365. package/dist/runtime/update-check.js +0 -294
  366. package/dist/runtime/version.js +0 -65
  367. package/dist/runtime/worktree-bootstrap.js +0 -579
  368. package/dist/skills/bundled/batch.js +0 -617
  369. package/dist/skills/bundled/index.js +0 -45
  370. package/dist/skills/bundled/loop.js +0 -358
  371. package/dist/skills/bundled/remember.js +0 -383
  372. package/dist/skills/bundled/simplify.js +0 -289
  373. package/dist/skills/bundled/skillify.js +0 -373
  374. package/dist/skills/bundled/stuck.js +0 -558
  375. package/dist/skills/bundled/verify.js +0 -439
  376. package/dist/testing/vcr.js +0 -486
  377. package/dist/tools/agent-tool.js +0 -229
  378. package/dist/tools/apply-patch.js +0 -556
  379. package/dist/tools/ask-user-question.js +0 -337
  380. package/dist/tools/ask-user.js +0 -115
  381. package/dist/tools/bash.js +0 -1238
  382. package/dist/tools/brief.js +0 -224
  383. package/dist/tools/cron.js +0 -433
  384. package/dist/tools/enter-worktree.js +0 -250
  385. package/dist/tools/exit-worktree.js +0 -147
  386. package/dist/tools/file-tools.js +0 -553
  387. package/dist/tools/http-request.js +0 -336
  388. package/dist/tools/lsp-tools.js +0 -565
  389. package/dist/tools/mcp-tool.js +0 -260
  390. package/dist/tools/multi-edit.js +0 -361
  391. package/dist/tools/powershell.js +0 -268
  392. package/dist/tools/registry.js +0 -166
  393. package/dist/tools/server-tools.js +0 -892
  394. package/dist/tools/skill-tool.js +0 -96
  395. package/dist/tools/sleep.js +0 -99
  396. package/dist/tools/synthetic-output.js +0 -133
  397. package/dist/tools/tasks.js +0 -208
  398. package/dist/tools/todo-write.js +0 -184
  399. package/dist/tools/verify-plan-execution.js +0 -295
  400. package/dist/tools/web-fetch-injection-scanner.js +0 -207
  401. package/dist/tools/web-fetch.js +0 -720
  402. package/dist/tools/web-search.js +0 -458
  403. package/dist/tui/agent-progress-card.js +0 -111
  404. package/dist/tui/agent-tree-pane.js +0 -9
  405. package/dist/tui/agent-tree.js +0 -87
  406. package/dist/tui/ask-cli.js +0 -52
  407. package/dist/tui/ask-modal.js +0 -211
  408. package/dist/tui/ask-user-question-chips.js +0 -315
  409. package/dist/tui/ask-user-question-prompt.js +0 -203
  410. package/dist/tui/compact-banner.js +0 -81
  411. package/dist/tui/conversation-pane.js +0 -164
  412. package/dist/tui/cost-table.js +0 -111
  413. package/dist/tui/device-flow.js +0 -142
  414. package/dist/tui/doctor-table.js +0 -46
  415. package/dist/tui/feedback-prompt.js +0 -156
  416. package/dist/tui/input-box.js +0 -732
  417. package/dist/tui/login-picker.js +0 -69
  418. package/dist/tui/markdown-render.js +0 -266
  419. package/dist/tui/multi-file-diff-approval.js +0 -375
  420. package/dist/tui/onboarding-wizard.js +0 -240
  421. package/dist/tui/permissions-picker.js +0 -86
  422. package/dist/tui/render.js +0 -160
  423. package/dist/tui/repl-render.js +0 -770
  424. package/dist/tui/repl-splash-art.js +0 -64
  425. package/dist/tui/repl-splash-mascot.js +0 -154
  426. package/dist/tui/repl-splash.js +0 -117
  427. package/dist/tui/repl.js +0 -378
  428. package/dist/tui/slash-palette.js +0 -106
  429. package/dist/tui/splash-data.js +0 -61
  430. package/dist/tui/splash.js +0 -31
  431. package/dist/tui/status-bar.js +0 -209
  432. package/dist/tui/status-table.js +0 -7
  433. package/dist/tui/stickers-art.js +0 -136
  434. package/dist/tui/style-table.js +0 -28
  435. package/dist/tui/theme-table.js +0 -29
  436. package/dist/tui/thinking-spinner.js +0 -123
  437. package/dist/tui/tool-stream-pane.js +0 -140
  438. package/dist/tui/update-banner.js +0 -33
  439. package/dist/tui/vim-input.js +0 -267
  440. package/dist/tui/welcome-banner.js +0 -107
  441. package/dist/tui/welcome-data.js +0 -293
  442. package/dist/tui/workspace-context.js +0 -105
  443. package/docs/examples/codegraph.mcp.json +0 -10
  444. package/test/scenarios/codegen-create-file.scenario.txt +0 -13
  445. package/test/scenarios/compact-force.scenario.txt +0 -12
  446. package/test/scenarios/identity.scenario.txt +0 -11
  447. package/test/scenarios/persona-handoff.scenario.txt +0 -12
  448. package/test/scenarios/walkback.scenario.txt +0 -12
@@ -1,1229 +0,0 @@
1
- /**
2
- * LSP client wrapper — Phase 1 (LSP tool + worktree + apply_patch).
3
- *
4
- * Wraps a Language Server Protocol server process (started locally via
5
- * stdio) behind a small async surface used by the LSP tools:
6
- *
7
- * - hover(file, line, col)
8
- * - definition(file, line, col)
9
- * - references(file, line, col)
10
- * - diagnostics(file)
11
- *
12
- * Why no `vscode-languageserver-protocol` dep:
13
- *
14
- * The + posture for `apps/pugi-cli` keeps the dep tree intentionally
15
- * lean (zod, ink, react, undici, tar — that's most of it). Pulling
16
- * `vscode-languageserver-protocol` + transitive `vscode-jsonrpc` for
17
- * four operations would expand the install footprint disproportionately.
18
- * The LSP framing protocol (Content-Length headers + JSON-RPC bodies)
19
- * is documented in the LSP spec §3 and stable since 2017; we implement
20
- * the framer ourselves in ~80 LOC. Pulling in the official packages
21
- * later (when we add 20+ operations) stays an open option — every
22
- * public surface here mirrors the official type names so a future swap
23
- * is mechanical.
24
- *
25
- * Why we spawn `npx <server>` for stock languages:
26
- *
27
- * - typescript-language-server: `npx typescript-language-server --stdio`
28
- * - pyright: `pyright-langserver --stdio` (operator-installed)
29
- * - gopls: `gopls` (operator-installed via `go install`)
30
- * - rust-analyzer: `rust-analyzer` (operator-installed via `rustup`)
31
- *
32
- * `npx typescript-language-server` resolves the binary from the
33
- * workspace's `node_modules/.bin` first, then falls back to the global
34
- * npm cache. The other servers are operator-installed system binaries
35
- * (we run `which <name>` once at start and fail loud with
36
- * `lsp_unavailable` if absent — see `detectServer` below). This keeps
37
- * `pugi` install-time zero-deps for non-TS workspaces.
38
- *
39
- * Lifecycle contract:
40
- *
41
- * 1. `startLspClient(lang, opts)` spawns the server, performs the LSP
42
- * `initialize` handshake, sends `initialized`, and returns a client.
43
- * 2. Each operation auto-opens the target file via `textDocument/didOpen`
44
- * on first touch (we keep a `Set<string>` of opened URIs). Files are
45
- * never closed mid-session — the server is per-CLI-invocation and
46
- * the process exit cleans up.
47
- * 3. `stop()` sends `shutdown` + `exit` (best-effort) and SIGKILLs the
48
- * child after a 1s grace window so the CLI never hangs on a
49
- * misbehaving server.
50
- *
51
- * Cancellation: every async operation accepts an optional CancellationToken
52
- * . On abort, we send LSP `$/cancelRequest` for the in-flight ID and
53
- * reject the promise with `OperatorAbortedError`.
54
- *
55
- * Privacy: requests stay client-side. There is no Anvil round-trip; the
56
- * server process reads ONLY the files the operator's code actually opens.
57
- * The `pugi privacy airgapped` mode does not need to gate this surface
58
- * because the LSP server is local; we still honor the mode by skipping
59
- * the optional update-check banner inside the CLI command surface.
60
- *
61
- * Brand voice: ASCII only, no emoji, no banned words.
62
- */
63
- import { spawn, spawnSync } from 'node:child_process';
64
- import { pathToFileURL } from 'node:url';
65
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
66
- import { resolve, sep } from 'node:path';
67
- import { OperatorAbortedError } from '../../tools/file-tools.js';
68
- const LANGUAGE_SERVERS = {
69
- ts: {
70
- command: 'npx',
71
- args: ['--yes', 'typescript-language-server', '--stdio'],
72
- languageId: 'typescript',
73
- probe: 'npx',
74
- },
75
- js: {
76
- command: 'npx',
77
- args: ['--yes', 'typescript-language-server', '--stdio'],
78
- languageId: 'javascript',
79
- probe: 'npx',
80
- },
81
- py: {
82
- command: 'pyright-langserver',
83
- args: ['--stdio'],
84
- languageId: 'python',
85
- probe: 'pyright-langserver',
86
- },
87
- go: {
88
- command: 'gopls',
89
- args: [],
90
- languageId: 'go',
91
- probe: 'gopls',
92
- },
93
- rust: {
94
- command: 'rust-analyzer',
95
- args: [],
96
- languageId: 'rust',
97
- probe: 'rust-analyzer',
98
- },
99
- };
100
- const DEFAULT_REQUEST_TIMEOUT_MS = 5_000;
101
- /**
102
- * Returned by `startLspClient`. Methods are async; every method honors
103
- * the optional `CancellationToken` parameter.
104
- */
105
- export class LspClient {
106
- cwd;
107
- child;
108
- server;
109
- openedFiles = new Set();
110
- pending = new Map();
111
- diagnosticsByUri = new Map();
112
- requestTimeoutMs;
113
- nextId = 1;
114
- buffer = Buffer.alloc(0);
115
- stopped = false;
116
- constructor(child, server, opts) {
117
- this.child = child;
118
- this.server = server;
119
- this.cwd = opts.cwd;
120
- this.requestTimeoutMs = opts.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
121
- child.stdout.on('data', (chunk) => this.onStdout(chunk));
122
- // Stderr is the server's diagnostic channel; we swallow it so a
123
- // chatty server (e.g. tsserver `debug:` lines) does not leak into
124
- // the operator-facing CLI stream. Operators can re-run with
125
- // `PUGI_LSP_DEBUG=1` to surface stderr.
126
- if (process.env.PUGI_LSP_DEBUG === '1') {
127
- child.stderr.on('data', (chunk) => process.stderr.write(chunk));
128
- }
129
- else {
130
- child.stderr.on('data', () => { });
131
- }
132
- child.on('exit', () => this.onExit());
133
- // R1 fix (2026-05-26, PR r1, P2 #11): mirror onExit for the
134
- // 'error' event. A late-fired spawn error (EIO, ENOMEM, etc.) or
135
- // any unhandled child-process error would otherwise leave
136
- // in-flight pending requests dangling until their per-request
137
- // timer fired, which can be up to `requestTimeoutMs` later.
138
- // Failing fast here matches the exit-time semantics.
139
- child.on('error', () => this.onExit());
140
- }
141
- /**
142
- * Send `shutdown` + `exit`, then SIGKILL after a 1s grace window so
143
- * a hung server never blocks CLI termination. Idempotent.
144
- */
145
- async stop() {
146
- if (this.stopped)
147
- return;
148
- this.stopped = true;
149
- try {
150
- await this.sendRequest('shutdown', null, undefined);
151
- this.sendNotification('exit', null);
152
- }
153
- catch {
154
- // Best-effort. A server that ignored shutdown gets the SIGKILL
155
- // path below.
156
- }
157
- const killTimer = setTimeout(() => {
158
- try {
159
- this.child.kill('SIGKILL');
160
- }
161
- catch {
162
- // already exited
163
- }
164
- }, 1_000);
165
- killTimer.unref();
166
- // Reject any in-flight requests so callers do not hang on the
167
- // shutdown path. We drain the map first to avoid the reject
168
- // callback re-entering and mutating the map mid-iteration.
169
- const snapshot = Array.from(this.pending.entries());
170
- this.pending.clear();
171
- for (const [, entry] of snapshot) {
172
- clearTimeout(entry.timer);
173
- entry.reject(new Error('lsp_stopped'));
174
- }
175
- }
176
- async hover(file, pos, token) {
177
- return this.withDocument(file, async (uri) => {
178
- const raw = await this.sendRequest('textDocument/hover', {
179
- textDocument: { uri },
180
- position: pos,
181
- }, token);
182
- if (raw === null || raw === undefined)
183
- return { ok: true, value: null };
184
- const value = normalizeHover(raw);
185
- return { ok: true, value };
186
- });
187
- }
188
- async definition(file, pos, token) {
189
- return this.withDocument(file, async (uri) => {
190
- const raw = await this.sendRequest('textDocument/definition', {
191
- textDocument: { uri },
192
- position: pos,
193
- }, token);
194
- const locations = normalizeLocations(raw, this.cwd);
195
- return { ok: true, value: locations };
196
- });
197
- }
198
- async references(file, pos, token) {
199
- return this.withDocument(file, async (uri) => {
200
- const raw = await this.sendRequest('textDocument/references', {
201
- textDocument: { uri },
202
- position: pos,
203
- context: { includeDeclaration: true },
204
- }, token);
205
- const locations = normalizeLocations(raw, this.cwd);
206
- return { ok: true, value: locations };
207
- });
208
- }
209
- /**
210
- * PUGI-78 Phase 1: document outline. Returns the LSP raw shape (either
211
- * `DocumentSymbol[]` hierarchical or `SymbolInformation[]` flat); the
212
- * symbol-tools layer normalizes both to the agent-facing flat form.
213
- */
214
- async documentSymbols(file, token) {
215
- return this.withDocument(file, async (uri) => {
216
- const raw = await this.sendRequest('textDocument/documentSymbol', { textDocument: { uri } }, token);
217
- if (!Array.isArray(raw))
218
- return { ok: true, value: [] };
219
- return { ok: true, value: raw };
220
- });
221
- }
222
- /**
223
- * PUGI-78 Phase 1: workspace-wide symbol fuzzy search. The query is
224
- * server-defined (substring / fuzzy / prefix); we forward verbatim.
225
- * Files outside the workspace are kept as raw URIs — the symbol-tools
226
- * layer surfaces them to the operator as-is.
227
- */
228
- async workspaceSymbols(query, token) {
229
- // workspace/symbol does not need a document open, but we still
230
- // honor the cancellation token. We call sendRequest directly via
231
- // the typed internal accessor used by the handshake.
232
- try {
233
- const internal = this;
234
- const raw = await internal.sendRequest('workspace/symbol', { query }, token);
235
- if (!Array.isArray(raw))
236
- return { ok: true, value: [] };
237
- return { ok: true, value: raw };
238
- }
239
- catch (error) {
240
- if (error instanceof OperatorAbortedError) {
241
- return { ok: false, reason: 'operator_aborted', detail: error.message };
242
- }
243
- if (error instanceof Error && error.message === 'request_timeout') {
244
- return { ok: false, reason: 'request_timeout', detail: 'workspace/symbol timed out' };
245
- }
246
- return {
247
- ok: false,
248
- reason: 'lsp_error',
249
- detail: error instanceof Error ? error.message : String(error),
250
- };
251
- }
252
- }
253
- /**
254
- * PUGI-78 Phase 1: implementations of an interface / abstract method.
255
- * LSP `textDocument/implementation` returns the same `Location[]` shape
256
- * as `definition`, so we re-use `normalizeLocations`.
257
- */
258
- async implementations(file, pos, token) {
259
- return this.withDocument(file, async (uri) => {
260
- const raw = await this.sendRequest('textDocument/implementation', { textDocument: { uri }, position: pos }, token);
261
- const locations = normalizeLocations(raw, this.cwd);
262
- return { ok: true, value: locations };
263
- });
264
- }
265
- /**
266
- * PUGI-78 Phase 1: type-definition (vs value-definition). Same wire
267
- * shape as `definition` — server reports the location of the symbol's
268
- * type declaration, not its instantiation site.
269
- */
270
- async typeDefinition(file, pos, token) {
271
- return this.withDocument(file, async (uri) => {
272
- const raw = await this.sendRequest('textDocument/typeDefinition', { textDocument: { uri }, position: pos }, token);
273
- const locations = normalizeLocations(raw, this.cwd);
274
- return { ok: true, value: locations };
275
- });
276
- }
277
- /**
278
- * PUGI-78 Phase 1: signature help at a call site. Returns the active
279
- * overload's label, parameters, and active-parameter index. Null when
280
- * the server reports no signature (cursor is not inside a call).
281
- */
282
- async signatureHelp(file, pos, token) {
283
- return this.withDocument(file, async (uri) => {
284
- const raw = await this.sendRequest('textDocument/signatureHelp', { textDocument: { uri }, position: pos }, token);
285
- return { ok: true, value: normalizeSignatureHelp(raw) };
286
- });
287
- }
288
- /**
289
- * PUGI-78 Phase 1: prepare a rename. Returns the range LSP says the
290
- * symbol occupies; the dispatcher uses this to confirm the cursor is
291
- * actually on a renameable token before issuing the full rename.
292
- */
293
- async prepareRename(file, pos, token) {
294
- return this.withDocument(file, async (uri) => {
295
- try {
296
- const raw = await this.sendRequest('textDocument/prepareRename', { textDocument: { uri }, position: pos }, token);
297
- if (!raw)
298
- return { ok: true, value: null };
299
- // LSP allows { range, placeholder } OR a raw Range; surface
300
- // either as a flat Range.
301
- if (typeof raw === 'object' && raw && 'start' in raw && 'end' in raw) {
302
- const range = parseRange(raw);
303
- return { ok: true, value: range ?? null };
304
- }
305
- if (typeof raw === 'object' && raw && 'range' in raw) {
306
- const range = parseRange(raw.range);
307
- return { ok: true, value: range ?? null };
308
- }
309
- return { ok: true, value: null };
310
- }
311
- catch (error) {
312
- // Some servers (pyright pre-1.1) lack prepareRename support and
313
- // return a JSON-RPC error. The dispatcher should still be able
314
- // to attempt the rename — surface null instead of bubbling the
315
- // failure as the agent surface treats null as "skip prepare".
316
- if (error instanceof Error && /method not (found|supported)/i.test(error.message)) {
317
- return { ok: true, value: null };
318
- }
319
- throw error;
320
- }
321
- });
322
- }
323
- /**
324
- * PUGI-78 Phase 1: atomic rename refactor. Returns the workspace edit
325
- * the server proposes; the dispatcher previews + applies in a future
326
- * ticket (Phase 2). For Phase 1 the agent surface lists affected files
327
- * + line:character of each edit so the model can summarize the impact.
328
- */
329
- async rename(file, pos, newName, token) {
330
- return this.withDocument(file, async (uri) => {
331
- const raw = await this.sendRequest('textDocument/rename', { textDocument: { uri }, position: pos, newName }, token);
332
- return { ok: true, value: normalizeWorkspaceEdit(raw, this.cwd) };
333
- });
334
- }
335
- /**
336
- * PUGI-78 Phase 1: quick-fix list at a range. The server returns either
337
- * `Command[]` (legacy) or `CodeAction[]` (modern); we normalize to the
338
- * union shape so the surface stays stable.
339
- */
340
- async codeActions(file, range, token) {
341
- return this.withDocument(file, async (uri) => {
342
- const raw = await this.sendRequest('textDocument/codeAction', {
343
- textDocument: { uri },
344
- range,
345
- context: { diagnostics: [] },
346
- }, token);
347
- return { ok: true, value: normalizeCodeActions(raw) };
348
- });
349
- }
350
- /**
351
- * PUGI-78 Phase 1: formatter. Returns the text edits the server would
352
- * apply for `textDocument/formatting`. The dispatcher composes them
353
- * into a single rewrite in a future ticket; Phase 1 surfaces the edits
354
- * for inspection.
355
- */
356
- async formatting(file, token, options) {
357
- return this.withDocument(file, async (uri) => {
358
- const raw = await this.sendRequest('textDocument/formatting', {
359
- textDocument: { uri },
360
- options: {
361
- tabSize: options?.tabSize ?? 2,
362
- insertSpaces: options?.insertSpaces ?? true,
363
- },
364
- }, token);
365
- return { ok: true, value: normalizeTextEdits(raw) };
366
- });
367
- }
368
- /**
369
- * PUGI-78 Phase 1: call hierarchy at a symbol position. The LSP wire
370
- * is a two-step protocol — first `prepareCallHierarchy` to get the
371
- * item handle, then `incomingCalls` and `outgoingCalls`. We surface
372
- * both edges in a single call.
373
- */
374
- async callHierarchy(file, pos, token) {
375
- return this.withDocument(file, async (uri) => {
376
- const prepared = await this.sendRequest('textDocument/prepareCallHierarchy', { textDocument: { uri }, position: pos }, token);
377
- if (!Array.isArray(prepared) || prepared.length === 0) {
378
- return { ok: true, value: { incoming: [], outgoing: [] } };
379
- }
380
- const item = prepared[0];
381
- const incomingRaw = await this.sendRequest('callHierarchy/incomingCalls', { item }, token);
382
- const outgoingRaw = await this.sendRequest('callHierarchy/outgoingCalls', { item }, token);
383
- return {
384
- ok: true,
385
- value: {
386
- incoming: normalizeCallHierarchyEdges(incomingRaw, 'from', this.cwd),
387
- outgoing: normalizeCallHierarchyEdges(outgoingRaw, 'to', this.cwd),
388
- },
389
- };
390
- });
391
- }
392
- /**
393
- * Diagnostics in LSP arrive as PUSH (`textDocument/publishDiagnostics`)
394
- * not pull. We open the document, wait one short tick for the server
395
- * to drain its first analysis pass, and return what is cached.
396
- * Servers that emit diagnostics asynchronously (gopls, rust-analyzer)
397
- * may take longer; the caller can extend `requestTimeoutMs` to allow
398
- * for the cold start.
399
- */
400
- async diagnostics(file, token) {
401
- return this.withDocument(file, async (uri) => {
402
- // Give the server one analysis cycle before reading the cache.
403
- // 200ms is enough for a warm tsserver; a cold server returns the
404
- // empty array and the caller can re-poll.
405
- await new Promise((res) => {
406
- const wait = setTimeout(res, 200);
407
- wait.unref();
408
- if (token) {
409
- token.onAbort(() => {
410
- clearTimeout(wait);
411
- res();
412
- });
413
- }
414
- });
415
- if (token && token.isAborted) {
416
- return { ok: false, reason: 'operator_aborted', detail: 'lspDiagnostics aborted' };
417
- }
418
- const cached = this.diagnosticsByUri.get(uri) ?? [];
419
- return { ok: true, value: cached };
420
- });
421
- }
422
- /**
423
- * Ensure the file is open server-side, then run `op`. The first call
424
- * for a path sends `textDocument/didOpen` with the on-disk content;
425
- * subsequent calls skip the open.
426
- */
427
- async withDocument(file, op) {
428
- let absPath;
429
- try {
430
- absPath = resolve(this.cwd, file);
431
- if (!absPath.startsWith(this.cwd + sep) && absPath !== this.cwd) {
432
- return {
433
- ok: false,
434
- reason: 'lsp_error',
435
- detail: `path escapes workspace: ${file}`,
436
- };
437
- }
438
- }
439
- catch (error) {
440
- return {
441
- ok: false,
442
- reason: 'lsp_error',
443
- detail: error instanceof Error ? error.message : String(error),
444
- };
445
- }
446
- // R1 fix (2026-05-26, PR r1, Fix 8): realpath containment.
447
- // Without this gate, a workspace-local symlink (e.g. `alias` ->
448
- // `/etc/passwd`) passed the lexical `absPath.startsWith(cwd)`
449
- // check, then `readFileSync(absPath, 'utf8')` happily followed the
450
- // symlink and shipped `/etc/passwd` into the LSP `textDocument/didOpen`
451
- // payload. Parity with `applySecurityGate`'s symlink-escape rule:
452
- // when the file exists, the realpath MUST stay inside the workspace
453
- // realpath. Missing files (newly-typed paths the operator is
454
- // querying) skip the check — there's no symlink target to escape.
455
- if (existsSync(absPath)) {
456
- try {
457
- const realRoot = realpathSync.native(this.cwd);
458
- const realTarget = realpathSync.native(absPath);
459
- if (realTarget !== realRoot && !realTarget.startsWith(realRoot + sep)) {
460
- return {
461
- ok: false,
462
- reason: 'lsp_error',
463
- detail: `symlink escapes workspace: ${file} -> ${realTarget}`,
464
- };
465
- }
466
- }
467
- catch (error) {
468
- return {
469
- ok: false,
470
- reason: 'lsp_error',
471
- detail: `cannot realpath ${file}: ${error instanceof Error ? error.message : String(error)}`,
472
- };
473
- }
474
- }
475
- const uri = pathToFileURL(absPath).toString();
476
- if (!this.openedFiles.has(uri)) {
477
- try {
478
- const text = readFileSync(absPath, 'utf8');
479
- this.sendNotification('textDocument/didOpen', {
480
- textDocument: {
481
- uri,
482
- languageId: this.server.languageId,
483
- version: 1,
484
- text,
485
- },
486
- });
487
- this.openedFiles.add(uri);
488
- }
489
- catch (error) {
490
- return {
491
- ok: false,
492
- reason: 'lsp_error',
493
- detail: `cannot read ${file}: ${error instanceof Error ? error.message : String(error)}`,
494
- };
495
- }
496
- }
497
- try {
498
- return await op(uri);
499
- }
500
- catch (error) {
501
- if (error instanceof OperatorAbortedError) {
502
- return { ok: false, reason: 'operator_aborted', detail: error.message };
503
- }
504
- if (error instanceof Error && error.message === 'request_timeout') {
505
- return { ok: false, reason: 'request_timeout', detail: 'lsp request timed out' };
506
- }
507
- return {
508
- ok: false,
509
- reason: 'lsp_error',
510
- detail: error instanceof Error ? error.message : String(error),
511
- };
512
- }
513
- }
514
- sendRequest(method, params, token) {
515
- const id = this.nextId++;
516
- const payload = { jsonrpc: '2.0', id, method, params };
517
- return new Promise((resolveFn, rejectFn) => {
518
- const timer = setTimeout(() => {
519
- if (this.pending.has(id)) {
520
- this.pending.delete(id);
521
- rejectFn(new Error('request_timeout'));
522
- }
523
- }, this.requestTimeoutMs);
524
- timer.unref();
525
- this.pending.set(id, { resolve: resolveFn, reject: rejectFn, timer });
526
- if (token) {
527
- token.onAbort(() => {
528
- if (this.pending.has(id)) {
529
- this.pending.delete(id);
530
- clearTimeout(timer);
531
- // Best-effort cancel notification to the server. Some
532
- // servers ignore $/cancelRequest; the local reject below
533
- // is what frees the caller.
534
- try {
535
- this.sendNotification('$/cancelRequest', { id });
536
- }
537
- catch {
538
- // server may already be gone
539
- }
540
- rejectFn(new OperatorAbortedError('lsp_request'));
541
- }
542
- });
543
- }
544
- try {
545
- this.writeMessage(payload);
546
- }
547
- catch (error) {
548
- this.pending.delete(id);
549
- clearTimeout(timer);
550
- rejectFn(error instanceof Error ? error : new Error(String(error)));
551
- }
552
- });
553
- }
554
- sendNotification(method, params) {
555
- this.writeMessage({ jsonrpc: '2.0', method, params });
556
- }
557
- writeMessage(payload) {
558
- const body = JSON.stringify(payload);
559
- const message = `Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`;
560
- this.child.stdin.write(message, 'utf8');
561
- }
562
- onStdout(chunk) {
563
- this.buffer = Buffer.concat([this.buffer, chunk]);
564
- while (true) {
565
- const headerEnd = this.buffer.indexOf('\r\n\r\n');
566
- if (headerEnd < 0)
567
- return;
568
- const headerText = this.buffer.subarray(0, headerEnd).toString('ascii');
569
- const lengthMatch = headerText.match(/Content-Length:\s*(\d+)/i);
570
- if (!lengthMatch || lengthMatch[1] === undefined) {
571
- // R1 fix (2026-05-26, PR r1, Fix 7): malformed header —
572
- // instead of nuking the entire buffer (which would discard ANY
573
- // subsequent valid messages already queued in `this.buffer`),
574
- // scan forward for the next `Content-Length:` marker and resync
575
- // from there. A misbehaving server that emits one bad header
576
- // followed by a normal stream of responses must not freeze the
577
- // client. When no recoverable next marker is in the buffer, we
578
- // keep the buffer as-is and wait for more data — the broken
579
- // bytes will be re-evaluated on the next chunk.
580
- const nextHeaderIdx = this.buffer.indexOf(Buffer.from('Content-Length:'), 1);
581
- if (nextHeaderIdx > 0) {
582
- this.buffer = this.buffer.subarray(nextHeaderIdx);
583
- continue;
584
- }
585
- // No next marker visible — wait for more data, do not nuke the
586
- // buffer. A subsequent chunk may complete a valid header.
587
- return;
588
- }
589
- const length = Number.parseInt(lengthMatch[1], 10);
590
- const bodyStart = headerEnd + 4;
591
- if (this.buffer.length < bodyStart + length)
592
- return;
593
- const bodyText = this.buffer.subarray(bodyStart, bodyStart + length).toString('utf8');
594
- this.buffer = this.buffer.subarray(bodyStart + length);
595
- try {
596
- const message = JSON.parse(bodyText);
597
- this.handleMessage(message);
598
- }
599
- catch {
600
- // Garbage body — drop and continue parsing the next message.
601
- }
602
- }
603
- }
604
- handleMessage(message) {
605
- // Response — has `id` and either `result` or `error`.
606
- if (typeof message['id'] === 'number') {
607
- const id = message['id'];
608
- const entry = this.pending.get(id);
609
- if (!entry)
610
- return;
611
- this.pending.delete(id);
612
- clearTimeout(entry.timer);
613
- if ('error' in message && message['error']) {
614
- const err = message['error'];
615
- entry.reject(new Error(`lsp_error code=${err.code ?? 'unknown'}: ${err.message ?? 'no message'}`));
616
- return;
617
- }
618
- entry.resolve(message['result'] ?? null);
619
- return;
620
- }
621
- // Notification from server.
622
- if (message['method'] === 'textDocument/publishDiagnostics') {
623
- const params = message['params'];
624
- if (!params)
625
- return;
626
- const uri = typeof params.uri === 'string' ? params.uri : null;
627
- if (!uri)
628
- return;
629
- const raw = Array.isArray(params.diagnostics) ? params.diagnostics : [];
630
- const normalized = [];
631
- for (const item of raw) {
632
- const parsed = normalizeDiagnostic(item);
633
- if (parsed)
634
- normalized.push(parsed);
635
- }
636
- this.diagnosticsByUri.set(uri, normalized);
637
- }
638
- }
639
- onExit() {
640
- if (this.stopped)
641
- return;
642
- this.stopped = true;
643
- const snapshot = Array.from(this.pending.entries());
644
- this.pending.clear();
645
- for (const [, entry] of snapshot) {
646
- clearTimeout(entry.timer);
647
- entry.reject(new Error('lsp_server_exited'));
648
- }
649
- }
650
- }
651
- /**
652
- * Map a short LSP language slug to the settings.json key. β7 L9 — the
653
- * settings schema spells out the full language name (`typescript`,
654
- * `python`, ...) for human readability; the short slug (`ts`, `py`) is
655
- * what every internal call site uses. Keep this map narrow and explicit.
656
- */
657
- const SETTINGS_KEY_BY_LANG = {
658
- ts: 'typescript',
659
- js: 'javascript',
660
- py: 'python',
661
- go: 'go',
662
- rust: 'rust',
663
- };
664
- /**
665
- * Report whether the operator has explicitly disabled this language via
666
- * `.pugi/settings.json::lsp.<language> = false`. Absent section or
667
- * absent key means "enabled by default" — backwards-compatible with the
668
- * surface that ignored settings entirely. Returns true ONLY when
669
- * the operator explicitly set the value to false.
670
- */
671
- export function isLspLanguageDisabled(lang, lspSettings) {
672
- if (!lspSettings)
673
- return false;
674
- const key = SETTINGS_KEY_BY_LANG[lang];
675
- return lspSettings[key] === false;
676
- }
677
- /**
678
- * Probe every registered language server. Operator-facing helper for
679
- * `pugi lsp servers` — returns one row per language with the binary
680
- * name, whether it was found on PATH, and whether the settings toggle
681
- * has explicitly disabled it.
682
- */
683
- export function inspectLspServers(lspSettings) {
684
- const out = [];
685
- for (const lang of Object.keys(LANGUAGE_SERVERS)) {
686
- const server = LANGUAGE_SERVERS[lang];
687
- out.push({
688
- language: lang,
689
- command: server.command + (server.args.length > 0 ? ` ${server.args.join(' ')}` : ''),
690
- available: detectBinary(server.probe),
691
- enabled: !isLspLanguageDisabled(lang, lspSettings),
692
- });
693
- }
694
- return out;
695
- }
696
- /**
697
- * Start an LSP client for the given language. Returns either an `LspClient`
698
- * ready to use, or a structured failure (`lsp_unavailable`,
699
- * `language_unsupported`).
700
- *
701
- * β7 L9: respects `.pugi/settings.json::lsp.<language> = false` —
702
- * a disabled language reports `lsp_disabled` so the caller surface can
703
- * tell the operator the binary IS available but settings says no.
704
- */
705
- export async function startLspClient(lang, opts) {
706
- const server = opts.serverOverride ?? LANGUAGE_SERVERS[lang];
707
- if (!server) {
708
- return {
709
- ok: false,
710
- reason: 'language_unsupported',
711
- detail: `no LSP server registered for language: ${lang}`,
712
- };
713
- }
714
- if (!opts.serverOverride && isLspLanguageDisabled(lang, opts.lspSettings)) {
715
- return {
716
- ok: false,
717
- reason: 'lsp_disabled',
718
- detail: `${lang} is disabled in .pugi/settings.json::lsp.${SETTINGS_KEY_BY_LANG[lang]}. ` +
719
- `Remove the override (or set it to true) to enable.`,
720
- };
721
- }
722
- if (!opts.serverOverride) {
723
- const available = detectBinary(server.probe);
724
- if (!available) {
725
- return {
726
- ok: false,
727
- reason: 'lsp_unavailable',
728
- detail: `${server.probe} not found on PATH. ` +
729
- `Install the language server first ` +
730
- `(see https://pugi.io/docs/cli/lsp for per-language commands).`,
731
- };
732
- }
733
- }
734
- let child;
735
- try {
736
- child = spawn(server.command, [...server.args], {
737
- cwd: opts.cwd,
738
- stdio: ['pipe', 'pipe', 'pipe'],
739
- });
740
- }
741
- catch (error) {
742
- return {
743
- ok: false,
744
- reason: 'lsp_unavailable',
745
- detail: `failed to spawn ${server.command}: ${error instanceof Error ? error.message : String(error)}`,
746
- };
747
- }
748
- // `child_process.spawn` reports a missing binary asynchronously via
749
- // the 'error' event, NOT via a synchronous throw — the synchronous
750
- // spawn returns a ChildProcess object even when the binary does not
751
- // exist. Attach an error listener immediately so the missing-binary
752
- // case never becomes an uncaught exception. Wait one microtask tick
753
- // for the event-loop to fire the 'error' event before we attempt
754
- // the handshake; if the spawn failed, return early with
755
- // `lsp_unavailable`.
756
- let spawnError = null;
757
- child.on('error', (err) => {
758
- spawnError = err;
759
- });
760
- // Yield one tick so Node's spawn-error path lands before we
761
- // proceed. The error event lives on the same nextTick queue as the
762
- // initial spawn handshake, so a single setImmediate-equivalent
763
- // delay is enough to observe it.
764
- await new Promise((resolveFn) => {
765
- setImmediate(resolveFn);
766
- });
767
- if (spawnError) {
768
- try {
769
- child.kill('SIGKILL');
770
- }
771
- catch {
772
- // ignore — process never started
773
- }
774
- return {
775
- ok: false,
776
- reason: 'lsp_unavailable',
777
- detail: `failed to spawn ${server.command}: ${spawnError.message}`,
778
- };
779
- }
780
- const client = new LspClient(child, server, opts);
781
- try {
782
- await initializeHandshake(client, opts.cwd);
783
- }
784
- catch (error) {
785
- await client.stop();
786
- if (spawnError) {
787
- return {
788
- ok: false,
789
- reason: 'lsp_unavailable',
790
- detail: `failed to spawn ${server.command}: ${spawnError.message}`,
791
- };
792
- }
793
- return {
794
- ok: false,
795
- reason: 'lsp_error',
796
- detail: `initialize failed: ${error instanceof Error ? error.message : String(error)}`,
797
- };
798
- }
799
- return { ok: true, value: client };
800
- }
801
- async function initializeHandshake(client, cwd) {
802
- const rootUri = pathToFileURL(cwd).toString();
803
- // Reach the private send-request / send-notification surface through
804
- // a typed accessor cast. The two methods are intentionally not part
805
- // of the public class surface (callers should use `hover`/`definition`
806
- // etc.), but the handshake is a single-shot bootstrap and exposing
807
- // the raw methods would weaken the type story.
808
- const internal = client;
809
- await internal.sendRequest('initialize', {
810
- processId: process.pid,
811
- rootUri,
812
- capabilities: {
813
- textDocument: {
814
- hover: { contentFormat: ['plaintext', 'markdown'] },
815
- definition: { linkSupport: false },
816
- references: {},
817
- publishDiagnostics: { relatedInformation: false },
818
- // PUGI-78 Phase 1: full 13-tool symbol surface. Each block
819
- // mirrors the LSP §3.17 dynamic capability advertisement so
820
- // the server enables the corresponding feature (e.g. pyright
821
- // gates `workspace/symbol` on this flag). `dynamicRegistration`
822
- // stays false for every entry — we never register a capability
823
- // post-initialize; the static block is the only handshake.
824
- documentSymbol: {
825
- hierarchicalDocumentSymbolSupport: true,
826
- symbolKind: { valueSet: Array.from({ length: 26 }, (_, i) => i + 1) },
827
- },
828
- signatureHelp: { signatureInformation: { documentationFormat: ['plaintext', 'markdown'] } },
829
- implementation: { linkSupport: false },
830
- typeDefinition: { linkSupport: false },
831
- rename: { prepareSupport: true },
832
- codeAction: { codeActionLiteralSupport: { codeActionKind: { valueSet: ['', 'quickfix', 'refactor', 'source'] } } },
833
- formatting: {},
834
- callHierarchy: {},
835
- },
836
- workspace: {
837
- symbol: { symbolKind: { valueSet: Array.from({ length: 26 }, (_, i) => i + 1) } },
838
- workspaceEdit: { documentChanges: true },
839
- },
840
- },
841
- workspaceFolders: [{ uri: rootUri, name: 'pugi-workspace' }],
842
- }, undefined);
843
- internal.sendNotification('initialized', {});
844
- }
845
- function detectBinary(name) {
846
- // Cross-platform `which` — spawnSync of the binary with --version is
847
- // too aggressive (some servers don't honor --version). Use `which`
848
- // on POSIX and `where` on Windows. Failures are non-fatal — we just
849
- // report unavailable.
850
- const probe = process.platform === 'win32' ? 'where' : 'which';
851
- try {
852
- const result = spawnSync(probe, [name], { stdio: 'ignore' });
853
- return result.status === 0;
854
- }
855
- catch {
856
- return false;
857
- }
858
- }
859
- function normalizeHover(raw) {
860
- // LSP `Hover.contents` can be:
861
- // - string
862
- // - { kind: 'markdown' | 'plaintext', value: string }
863
- // - Array<string | { language: string, value: string }>
864
- if (!raw || typeof raw !== 'object') {
865
- return { content: String(raw ?? ''), raw };
866
- }
867
- const obj = raw;
868
- const range = parseRange(obj.range);
869
- const body = obj.contents;
870
- const result = (() => {
871
- if (typeof body === 'string')
872
- return { content: body, raw, ...(range ? { range } : {}) };
873
- if (Array.isArray(body)) {
874
- const parts = [];
875
- for (const item of body) {
876
- if (typeof item === 'string')
877
- parts.push(item);
878
- else if (item && typeof item === 'object' && 'value' in item) {
879
- const value = item.value;
880
- if (typeof value === 'string')
881
- parts.push(value);
882
- }
883
- }
884
- return { content: parts.join('\n'), raw, ...(range ? { range } : {}) };
885
- }
886
- if (body && typeof body === 'object' && 'value' in body) {
887
- const value = body.value;
888
- return { content: typeof value === 'string' ? value : '', raw, ...(range ? { range } : {}) };
889
- }
890
- return { content: '', raw, ...(range ? { range } : {}) };
891
- })();
892
- return result;
893
- }
894
- function normalizeLocations(raw, cwd) {
895
- if (!raw)
896
- return [];
897
- const items = Array.isArray(raw) ? raw : [raw];
898
- const out = [];
899
- for (const item of items) {
900
- if (!item || typeof item !== 'object')
901
- continue;
902
- const obj = item;
903
- const uri = typeof obj.uri === 'string' ? obj.uri : typeof obj.targetUri === 'string' ? obj.targetUri : null;
904
- const range = parseRange(obj.range ?? obj.targetRange);
905
- if (!uri || !range)
906
- continue;
907
- let path = '';
908
- try {
909
- const url = new URL(uri);
910
- if (url.protocol === 'file:') {
911
- const abs = decodeURIComponent(url.pathname);
912
- if (abs.startsWith(cwd + sep) || abs === cwd) {
913
- path = abs.slice(cwd.length + 1);
914
- }
915
- }
916
- }
917
- catch {
918
- path = '';
919
- }
920
- out.push({ uri, path, range });
921
- }
922
- return out;
923
- }
924
- function parseRange(raw) {
925
- if (!raw || typeof raw !== 'object')
926
- return undefined;
927
- const obj = raw;
928
- const start = parsePosition(obj.start);
929
- const end = parsePosition(obj.end);
930
- if (!start || !end)
931
- return undefined;
932
- return { start, end };
933
- }
934
- function parsePosition(raw) {
935
- if (!raw || typeof raw !== 'object')
936
- return undefined;
937
- const obj = raw;
938
- if (typeof obj.line !== 'number' || typeof obj.character !== 'number')
939
- return undefined;
940
- return { line: obj.line, character: obj.character };
941
- }
942
- function normalizeDiagnostic(raw) {
943
- if (!raw || typeof raw !== 'object')
944
- return null;
945
- const obj = raw;
946
- const range = parseRange(obj.range);
947
- if (!range)
948
- return null;
949
- if (typeof obj.message !== 'string')
950
- return null;
951
- const severityRaw = typeof obj.severity === 'number' ? obj.severity : 1;
952
- const severity = (severityRaw >= 1 && severityRaw <= 4 ? severityRaw : 1);
953
- const labels = {
954
- 1: 'error',
955
- 2: 'warning',
956
- 3: 'info',
957
- 4: 'hint',
958
- };
959
- const out = {
960
- severity,
961
- severityLabel: labels[severity],
962
- message: obj.message,
963
- range,
964
- ...(typeof obj.source === 'string' ? { source: obj.source } : {}),
965
- ...(typeof obj.code === 'string' || typeof obj.code === 'number' ? { code: obj.code } : {}),
966
- };
967
- return out;
968
- }
969
- /**
970
- * PUGI-78 Phase 1: collapse a `textDocument/signatureHelp` response to
971
- * one active overload. LSP returns `{ signatures, activeSignature,
972
- * activeParameter }`; we surface the active overload's label, params,
973
- * and the active-param index. Returns null when the server reports no
974
- * signatures (cursor not at a call site).
975
- */
976
- function normalizeSignatureHelp(raw) {
977
- if (!raw || typeof raw !== 'object')
978
- return null;
979
- const obj = raw;
980
- if (!Array.isArray(obj.signatures) || obj.signatures.length === 0)
981
- return null;
982
- const idx = typeof obj.activeSignature === 'number' && obj.activeSignature >= 0
983
- ? Math.min(obj.activeSignature, obj.signatures.length - 1)
984
- : 0;
985
- const sig = obj.signatures[idx];
986
- if (!sig || typeof sig !== 'object')
987
- return null;
988
- const sigObj = sig;
989
- if (typeof sigObj.label !== 'string')
990
- return null;
991
- const params = [];
992
- if (Array.isArray(sigObj.parameters)) {
993
- for (const p of sigObj.parameters) {
994
- if (!p || typeof p !== 'object')
995
- continue;
996
- const po = p;
997
- // LSP allows `label` as string OR [start,end] tuple of offsets;
998
- // we surface the string form, and for tuple form we slice the
999
- // signature label.
1000
- let label = '';
1001
- if (typeof po.label === 'string')
1002
- label = po.label;
1003
- else if (Array.isArray(po.label) && po.label.length === 2 && typeof po.label[0] === 'number' && typeof po.label[1] === 'number') {
1004
- label = sigObj.label.slice(po.label[0], po.label[1]);
1005
- }
1006
- if (!label)
1007
- continue;
1008
- const doc = extractMarkupString(po.documentation);
1009
- params.push({ label, ...(doc ? { documentation: doc } : {}) });
1010
- }
1011
- }
1012
- const docTop = extractMarkupString(sigObj.documentation);
1013
- const out = {
1014
- label: sigObj.label,
1015
- parameters: params,
1016
- raw,
1017
- ...(docTop ? { documentation: docTop } : {}),
1018
- ...(typeof obj.activeParameter === 'number' ? { activeParameter: obj.activeParameter } : {}),
1019
- };
1020
- return out;
1021
- }
1022
- /**
1023
- * LSP `MarkupContent | string` -> string. Used by both signature help
1024
- * (top-level docs + per-param docs) and hover normalization.
1025
- */
1026
- function extractMarkupString(raw) {
1027
- if (typeof raw === 'string')
1028
- return raw.length > 0 ? raw : undefined;
1029
- if (raw && typeof raw === 'object' && 'value' in raw) {
1030
- const value = raw.value;
1031
- if (typeof value === 'string' && value.length > 0)
1032
- return value;
1033
- }
1034
- return undefined;
1035
- }
1036
- /**
1037
- * PUGI-78 Phase 1: collapse a `textDocument/rename` `WorkspaceEdit` to
1038
- * the agent-facing flat list. Handles BOTH shapes:
1039
- * - legacy `changes: { [uri]: TextEdit[] }`
1040
- * - modern `documentChanges: (TextDocumentEdit | FileOp)[]`
1041
- *
1042
- * File-op entries (`CreateFile`, `RenameFile`, `DeleteFile`) are NOT
1043
- * surfaced in Phase 1 — the only renames Pugi enables out of the box
1044
- * are symbol-level. Phase 2 wires the file-op variants.
1045
- */
1046
- function normalizeWorkspaceEdit(raw, cwd) {
1047
- if (!raw || typeof raw !== 'object')
1048
- return null;
1049
- const obj = raw;
1050
- const edits = [];
1051
- const fileSet = new Set();
1052
- const pushEdit = (uri, edit) => {
1053
- if (!edit || typeof edit !== 'object')
1054
- return;
1055
- const editObj = edit;
1056
- const range = parseRange(editObj.range);
1057
- if (!range)
1058
- return;
1059
- const newText = typeof editObj.newText === 'string' ? editObj.newText : '';
1060
- const file = uriToWorkspacePath(uri, cwd);
1061
- if (!file)
1062
- return;
1063
- fileSet.add(file);
1064
- edits.push({ file, line: range.start.line, character: range.start.character, newText });
1065
- };
1066
- if (obj.changes && typeof obj.changes === 'object') {
1067
- for (const [uri, list] of Object.entries(obj.changes)) {
1068
- if (!Array.isArray(list))
1069
- continue;
1070
- for (const edit of list)
1071
- pushEdit(uri, edit);
1072
- }
1073
- }
1074
- if (Array.isArray(obj.documentChanges)) {
1075
- for (const docChange of obj.documentChanges) {
1076
- if (!docChange || typeof docChange !== 'object')
1077
- continue;
1078
- const dc = docChange;
1079
- // Skip file-op entries — they have a `kind` discriminator.
1080
- if (typeof dc.kind === 'string' && dc.kind !== '')
1081
- continue;
1082
- const td = dc.textDocument;
1083
- if (!td || typeof td !== 'object')
1084
- continue;
1085
- const uri = td.uri;
1086
- if (typeof uri !== 'string')
1087
- continue;
1088
- if (Array.isArray(dc.edits)) {
1089
- for (const edit of dc.edits)
1090
- pushEdit(uri, edit);
1091
- }
1092
- }
1093
- }
1094
- if (fileSet.size === 0)
1095
- return null;
1096
- return { files: Array.from(fileSet).sort(), edits, raw };
1097
- }
1098
- /**
1099
- * Convert an LSP `file://` URI to a workspace-relative path. Empty
1100
- * string when the URI escapes the workspace; the caller decides whether
1101
- * to drop the edit or surface the raw URI.
1102
- */
1103
- function uriToWorkspacePath(uri, cwd) {
1104
- try {
1105
- const url = new URL(uri);
1106
- if (url.protocol !== 'file:')
1107
- return uri;
1108
- const abs = decodeURIComponent(url.pathname);
1109
- if (abs === cwd)
1110
- return '.';
1111
- if (abs.startsWith(cwd + sep))
1112
- return abs.slice(cwd.length + 1);
1113
- return uri;
1114
- }
1115
- catch {
1116
- return '';
1117
- }
1118
- }
1119
- /**
1120
- * PUGI-78 Phase 1: parse `textDocument/codeAction` response. Server
1121
- * returns either `Command[]` or `CodeAction[]`. Both have `title`;
1122
- * `CodeAction` additionally carries `kind` + `isPreferred` + `edit`.
1123
- */
1124
- function normalizeCodeActions(raw) {
1125
- if (!Array.isArray(raw))
1126
- return [];
1127
- const out = [];
1128
- for (const item of raw) {
1129
- if (!item || typeof item !== 'object')
1130
- continue;
1131
- const obj = item;
1132
- if (typeof obj.title !== 'string' || obj.title.length === 0)
1133
- continue;
1134
- out.push({
1135
- title: obj.title,
1136
- ...(typeof obj.kind === 'string' ? { kind: obj.kind } : {}),
1137
- ...(typeof obj.isPreferred === 'boolean' ? { isPreferred: obj.isPreferred } : {}),
1138
- });
1139
- }
1140
- return out;
1141
- }
1142
- /**
1143
- * PUGI-78 Phase 1: parse a `TextEdit[]` payload returned by the
1144
- * formatter. Skips rows with missing range or non-string newText.
1145
- */
1146
- function normalizeTextEdits(raw) {
1147
- if (!Array.isArray(raw))
1148
- return [];
1149
- const out = [];
1150
- for (const item of raw) {
1151
- if (!item || typeof item !== 'object')
1152
- continue;
1153
- const obj = item;
1154
- const range = parseRange(obj.range);
1155
- if (!range)
1156
- continue;
1157
- const newText = typeof obj.newText === 'string' ? obj.newText : '';
1158
- out.push({ range, newText });
1159
- }
1160
- return out;
1161
- }
1162
- /**
1163
- * PUGI-78 Phase 1: collapse `callHierarchy/{incoming,outgoing}Calls`.
1164
- * The two response shapes share the same `from`/`to` field for the
1165
- * counterpart item; `fromRanges`/`toRanges` flatten to `callRanges`.
1166
- */
1167
- function normalizeCallHierarchyEdges(raw, itemKey, cwd) {
1168
- if (!Array.isArray(raw))
1169
- return [];
1170
- const out = [];
1171
- const rangeKey = itemKey === 'from' ? 'fromRanges' : 'toRanges';
1172
- for (const row of raw) {
1173
- if (!row || typeof row !== 'object')
1174
- continue;
1175
- const rowObj = row;
1176
- const item = rowObj[itemKey];
1177
- if (!item || typeof item !== 'object')
1178
- continue;
1179
- const itemObj = item;
1180
- if (typeof itemObj.name !== 'string' || itemObj.name.length === 0)
1181
- continue;
1182
- const kind = typeof itemObj.kind === 'number' ? itemObj.kind : 0;
1183
- if (!kind)
1184
- continue;
1185
- const uri = typeof itemObj.uri === 'string' ? itemObj.uri : '';
1186
- if (!uri)
1187
- continue;
1188
- const file = uriToWorkspacePath(uri, cwd);
1189
- const selRange = parseRange(itemObj.selectionRange) ?? parseRange(itemObj.range);
1190
- if (!selRange)
1191
- continue;
1192
- const rangesRaw = rowObj[rangeKey];
1193
- const callRanges = [];
1194
- if (Array.isArray(rangesRaw)) {
1195
- for (const r of rangesRaw) {
1196
- const parsed = parseRange(r);
1197
- if (parsed)
1198
- callRanges.push(parsed);
1199
- }
1200
- }
1201
- out.push({
1202
- name: itemObj.name,
1203
- kind,
1204
- file,
1205
- line: selRange.start.line,
1206
- character: selRange.start.character,
1207
- callRanges,
1208
- });
1209
- }
1210
- return out;
1211
- }
1212
- /**
1213
- * Test-only surface so specs can hand-craft an `LspClient` over a mock
1214
- * stdio pipe without paying for the real `startLspClient` spawn cost.
1215
- * The exported shape mirrors what the constructor needs.
1216
- */
1217
- export const __test__ = {
1218
- LANGUAGE_SERVERS,
1219
- normalizeHover,
1220
- normalizeLocations,
1221
- normalizeDiagnostic,
1222
- normalizeSignatureHelp,
1223
- normalizeWorkspaceEdit,
1224
- normalizeCodeActions,
1225
- normalizeTextEdits,
1226
- normalizeCallHierarchyEdges,
1227
- uriToWorkspacePath,
1228
- };
1229
- //# sourceMappingURL=client.js.map