@pugi/cli 0.1.0-beta.98 → 1.0.0-alpha.1

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 -192
  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,892 +0,0 @@
1
- /**
2
- * server-tools - Phase 1 runtime evidence primitives (PUGI Phase 1).
3
- *
4
- * These tools give the model a way to spin up a service, probe its
5
- * health endpoint, harvest log tails, and tear it down - turning
6
- * "server is running" prose into pid + health 200 evidence.
7
- *
8
- * Surfaced as four tools:
9
- * - server_start: spawn `command` in `cwd`, poll `healthUrl` until
10
- * status === expectStatus (default 200) OR timeout elapses OR
11
- * the process exits. Persist {pid, port, logPath, command} to
12
- * `.pugi/runs/<runId>/server.json` for later inspection.
13
- * - server_stop: SIGTERM → graceMs → SIGKILL the pid, returning the
14
- * exit code + signal. No-op-safe when the process is already dead.
15
- * - server_health: one-shot HTTP GET against an arbitrary url with a
16
- * timeout. Distinct from `server_start`'s built-in health probe
17
- * because the model frequently needs to re-check liveness after
18
- * migrations / restarts.
19
- * - server_logs: read the trailing N lines of a `runId` (or pid)'s
20
- * log file so the model can diagnose a failure without re-running
21
- * the server.
22
- *
23
- * The async + sync entry points mirror the bash-tool split so the
24
- * engine-loop tool-bridge can dispatch from spawnSync paths too.
25
- *
26
- * Security posture:
27
- * - server_start / server_stop use the bash permission class via the
28
- * registry so the existing mode-aware permission gate applies. The
29
- * tool itself does NOT call evaluateBashPermission - the bash-class
30
- * entry in registry.ts pins risk=high and concurrencySafe=false.
31
- * - server_logs is read-only against `.pugi/runs/<runId>/server.log`.
32
- * Path traversal is gated by `resolveWorkspacePath` to keep the
33
- * read inside the workspace.
34
- * - env is filtered through the same SAFE_ENV_ALLOW set as bash.ts so
35
- * PUGI_API_KEY / PUGI_LOGIN_TOKEN never leak to the spawned child.
36
- *
37
- * Brand voice: English only, no emoji, no banned words.
38
- */
39
- import { spawn } from 'node:child_process';
40
- import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
41
- import { isAbsolute, join, resolve } from 'node:path';
42
- import { randomUUID } from 'node:crypto';
43
- /** Default health-poll cadence. */
44
- export const SERVER_START_DEFAULT_POLL_MS = 500;
45
- /** Default health-probe timeout - generous because dev servers warm up. */
46
- export const SERVER_START_DEFAULT_TIMEOUT_MS = 30_000;
47
- /** Upper bound on the health-probe timeout. */
48
- export const SERVER_START_MAX_TIMEOUT_MS = 5 * 60 * 1_000;
49
- /** Default grace window between SIGTERM and SIGKILL. Mirrors bash.ts. */
50
- export const SERVER_STOP_DEFAULT_GRACE_MS = 5_000;
51
- /** Upper bound on the stop grace window. */
52
- export const SERVER_STOP_MAX_GRACE_MS = 60_000;
53
- /** Default tail size for server_logs. */
54
- export const SERVER_LOGS_DEFAULT_TAIL = 200;
55
- /** Upper bound on log tail size to keep the response envelope sized. */
56
- export const SERVER_LOGS_MAX_TAIL = 2_000;
57
- /** Sentinel returned when an argument shape fails validation. */
58
- export const SERVER_INVALID_ARGS = 'SERVER_INVALID_ARGS';
59
- /**
60
- * Subset of process.env we forward to the spawned server. Mirrors the
61
- * SAFE_ENV_ALLOW set in bash.ts so PUGI credentials never leak across
62
- * the boundary even when an operator passes them via `env`.
63
- */
64
- const SAFE_ENV_ALLOW = new Set([
65
- 'PATH',
66
- 'HOME',
67
- 'USER',
68
- 'LOGNAME',
69
- 'SHELL',
70
- 'LANG',
71
- 'TZ',
72
- 'TERM',
73
- 'PWD',
74
- 'NODE_ENV',
75
- 'NODE_OPTIONS',
76
- 'NODE_VERSION',
77
- ]);
78
- function buildChildEnv(extra) {
79
- const env = {};
80
- for (const [key, value] of Object.entries(process.env)) {
81
- if (value === undefined)
82
- continue;
83
- if (SAFE_ENV_ALLOW.has(key) || key.startsWith('LC_')) {
84
- env[key] = value;
85
- }
86
- }
87
- // Caller-supplied env overrides system inheritance. We do NOT filter
88
- // the caller set - the model is expected to supply concrete keys
89
- // (NODE_ENV=development, PORT=3000) and should not be silently
90
- // dropped just because the key falls outside the allowlist.
91
- if (extra) {
92
- for (const [key, value] of Object.entries(extra)) {
93
- if (typeof value === 'string')
94
- env[key] = value;
95
- }
96
- }
97
- return env;
98
- }
99
- /**
100
- * Resolve `cwd` against the workspace root. Relative paths root at
101
- * workspaceRoot; absolute paths are accepted ONLY when they fall under
102
- * workspaceRoot. Anything else collapses to workspaceRoot - defense in
103
- * depth so a stale path argument cannot spawn a server outside the
104
- * operator's workspace.
105
- */
106
- function resolveCwd(workspaceRoot, requested) {
107
- if (!requested)
108
- return workspaceRoot;
109
- const absolute = isAbsolute(requested) ? requested : resolve(workspaceRoot, requested);
110
- const rootAnchor = workspaceRoot.endsWith('/') ? workspaceRoot.slice(0, -1) : workspaceRoot;
111
- if (absolute === rootAnchor || absolute.startsWith(`${rootAnchor}/`)) {
112
- return absolute;
113
- }
114
- return workspaceRoot;
115
- }
116
- /**
117
- * Validate `server_start` arguments. Returns the typed payload on
118
- * success or a sentinel string on failure (consistent with the
119
- * sleep/brief tool convention).
120
- */
121
- export function parseServerStartArgs(raw) {
122
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
123
- return `${SERVER_INVALID_ARGS}: arguments must be a JSON object`;
124
- }
125
- const obj = raw;
126
- const command = obj['command'];
127
- const port = obj['port'];
128
- if (typeof command !== 'string' || command.trim() === '') {
129
- return `${SERVER_INVALID_ARGS}: command must be a non-empty string`;
130
- }
131
- if (typeof port !== 'number' || !Number.isInteger(port) || port < 1 || port > 65535) {
132
- return `${SERVER_INVALID_ARGS}: port must be an integer in [1, 65535]`;
133
- }
134
- const cwd = obj['cwd'];
135
- if (cwd !== undefined && typeof cwd !== 'string') {
136
- return `${SERVER_INVALID_ARGS}: cwd must be a string when provided`;
137
- }
138
- const healthUrl = obj['healthUrl'];
139
- if (healthUrl !== undefined && typeof healthUrl !== 'string') {
140
- return `${SERVER_INVALID_ARGS}: healthUrl must be a string when provided`;
141
- }
142
- const timeoutMs = obj['timeoutMs'];
143
- if (timeoutMs !== undefined) {
144
- if (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
145
- return `${SERVER_INVALID_ARGS}: timeoutMs must be a positive number when provided`;
146
- }
147
- }
148
- const expectStatus = obj['expectStatus'];
149
- if (expectStatus !== undefined) {
150
- if (typeof expectStatus !== 'number' || !Number.isInteger(expectStatus) || expectStatus < 100 || expectStatus > 599) {
151
- return `${SERVER_INVALID_ARGS}: expectStatus must be an integer in [100, 599]`;
152
- }
153
- }
154
- const env = obj['env'];
155
- if (env !== undefined) {
156
- if (typeof env !== 'object' || env === null || Array.isArray(env)) {
157
- return `${SERVER_INVALID_ARGS}: env must be a JSON object of string values`;
158
- }
159
- for (const [k, v] of Object.entries(env)) {
160
- if (typeof v !== 'string') {
161
- return `${SERVER_INVALID_ARGS}: env["${k}"] must be a string`;
162
- }
163
- }
164
- }
165
- const args = {
166
- command,
167
- port,
168
- ...(typeof cwd === 'string' ? { cwd } : {}),
169
- ...(typeof healthUrl === 'string' ? { healthUrl } : {}),
170
- ...(typeof timeoutMs === 'number' ? { timeoutMs } : {}),
171
- ...(typeof expectStatus === 'number' ? { expectStatus } : {}),
172
- ...(env !== undefined ? { env: env } : {}),
173
- };
174
- return args;
175
- }
176
- function clampTimeout(value) {
177
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
178
- return SERVER_START_DEFAULT_TIMEOUT_MS;
179
- }
180
- return Math.min(value, SERVER_START_MAX_TIMEOUT_MS);
181
- }
182
- function clampGrace(value) {
183
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
184
- return SERVER_STOP_DEFAULT_GRACE_MS;
185
- }
186
- return Math.min(value, SERVER_STOP_MAX_GRACE_MS);
187
- }
188
- function clampTail(value) {
189
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
190
- return SERVER_LOGS_DEFAULT_TAIL;
191
- }
192
- return Math.min(Math.floor(value), SERVER_LOGS_MAX_TAIL);
193
- }
194
- function ensureRunsDir(workspaceRoot, runId) {
195
- const dir = join(workspaceRoot, '.pugi', 'runs', runId);
196
- mkdirSync(dir, { recursive: true });
197
- return { dir, logPath: join(dir, 'server.log'), metaPath: join(dir, 'server.json') };
198
- }
199
- function writeMeta(metaPath, meta) {
200
- try {
201
- const body = JSON.stringify(meta, null, 2);
202
- writeFileSync(metaPath, `${body}\n`, { encoding: 'utf8', mode: 0o600 });
203
- }
204
- catch {
205
- // best-effort - the in-memory return envelope still carries the data
206
- }
207
- }
208
- /**
209
- * Open a write stream to the log file. Uses appendFileSync from the
210
- * spawned child's stdout/stderr handlers because spawn's stdio file
211
- * descriptor inheritance is fiddly across platforms and we want the
212
- * loop to honour the cancel/timeout windows above all else.
213
- */
214
- function openLogWriter(logPath) {
215
- // Truncate existing file so reruns of the same runId start fresh.
216
- try {
217
- writeFileSync(logPath, '', { encoding: 'utf8', mode: 0o600 });
218
- }
219
- catch {
220
- // ignore - appends below will retry through writeFileSync
221
- }
222
- return (chunk) => {
223
- try {
224
- const data = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
225
- // appendFileSync via writeFileSync + flag 'a' is simpler than
226
- // requiring fs/promises in a sync path. We use the node fs append
227
- // mode via an opt-in `flag: 'a'` on writeFileSync.
228
- writeFileSync(logPath, data, { encoding: 'utf8', flag: 'a' });
229
- }
230
- catch {
231
- // log capture is best-effort - never crash the server tool
232
- }
233
- };
234
- }
235
- /**
236
- * Poll the health URL until either:
237
- * - the HTTP call returns the expected status code → ok=true
238
- * - the timeout elapses → ok=false with reason=timeout_waiting_health
239
- * - the spawned child exits before the probe succeeds → ok=false with
240
- * reason=process_exited (the close-watcher flips this flag)
241
- */
242
- async function pollHealth(input) {
243
- const start = input.now();
244
- const deadline = start + input.timeoutMs;
245
- let lastStatus;
246
- while (input.now() < deadline) {
247
- if (input.hasExited()) {
248
- return {
249
- ok: false,
250
- durationMs: input.now() - start,
251
- reason: 'process_exited',
252
- ...(lastStatus !== undefined ? { status: lastStatus } : {}),
253
- };
254
- }
255
- try {
256
- const ac = new AbortController();
257
- const probeTimeout = setTimeout(() => ac.abort(), Math.min(2_000, input.timeoutMs));
258
- try {
259
- const res = await input.fetchImpl(input.url, { signal: ac.signal });
260
- lastStatus = res.status;
261
- if (res.status === input.expectStatus) {
262
- return { ok: true, status: res.status, durationMs: input.now() - start };
263
- }
264
- }
265
- finally {
266
- clearTimeout(probeTimeout);
267
- }
268
- }
269
- catch {
270
- // network refused / dns / abort - keep polling, the server is
271
- // probably still warming up
272
- }
273
- await input.sleeper(SERVER_START_DEFAULT_POLL_MS);
274
- }
275
- return {
276
- ok: false,
277
- durationMs: input.now() - start,
278
- reason: 'timeout_waiting_health',
279
- ...(lastStatus !== undefined ? { status: lastStatus } : {}),
280
- };
281
- }
282
- /**
283
- * Dispatch entry: parse args, spawn the server, poll its health, and
284
- * return a structured envelope. The pid is persisted to
285
- * `.pugi/runs/<runId>/server.json` so a later `server_stop` / operator
286
- * cleanup script can find it.
287
- */
288
- export async function dispatchServerStart(ctx, raw) {
289
- const parsed = parseServerStartArgs(raw);
290
- if (typeof parsed === 'string')
291
- return parsed;
292
- const args = parsed;
293
- const now = ctx.now ?? (() => Date.now());
294
- const sleeper = ctx.sleeper ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
295
- const fetchImpl = ctx.fetch ?? globalThis.fetch;
296
- const spawnImpl = ctx.spawnImpl ?? spawn;
297
- if (typeof fetchImpl !== 'function') {
298
- const result = {
299
- ok: false,
300
- runId: '',
301
- logPath: '',
302
- metaPath: '',
303
- durationMs: 0,
304
- error: 'no_fetch_available',
305
- };
306
- return JSON.stringify(result);
307
- }
308
- const runId = `srv-${randomUUID()}`;
309
- const { logPath, metaPath } = ensureRunsDir(ctx.workspaceRoot, runId);
310
- const writer = openLogWriter(logPath);
311
- const cwd = resolveCwd(ctx.workspaceRoot, args.cwd);
312
- const env = buildChildEnv(args.env);
313
- const timeoutMs = clampTimeout(args.timeoutMs);
314
- const healthUrl = args.healthUrl ?? `http://localhost:${args.port}/health`;
315
- const expectStatus = args.expectStatus ?? 200;
316
- const startedAt = now();
317
- let child;
318
- try {
319
- child = spawnImpl('/bin/sh', ['-c', args.command], {
320
- cwd,
321
- env,
322
- stdio: ['ignore', 'pipe', 'pipe'],
323
- detached: false,
324
- });
325
- }
326
- catch (error) {
327
- const message = error.message;
328
- writer(`[server_start] spawn failed: ${message}\n`);
329
- const result = {
330
- ok: false,
331
- runId,
332
- logPath,
333
- metaPath,
334
- durationMs: now() - startedAt,
335
- error: `spawn_failed: ${message}`,
336
- };
337
- writeMeta(metaPath, {
338
- ok: false,
339
- command: args.command,
340
- cwd,
341
- port: args.port,
342
- healthUrl,
343
- error: result.error,
344
- startedAt: new Date(startedAt).toISOString(),
345
- });
346
- return JSON.stringify(result);
347
- }
348
- let exited = false;
349
- let exitCode;
350
- let exitSignal;
351
- child.on('exit', (code, signal) => {
352
- exited = true;
353
- exitCode = code ?? undefined;
354
- exitSignal = signal ?? undefined;
355
- });
356
- child.stdout?.on('data', (chunk) => writer(chunk));
357
- child.stderr?.on('data', (chunk) => writer(chunk));
358
- child.on('error', (error) => {
359
- writer(`[server_start] child error: ${error.message}\n`);
360
- });
361
- const pid = child.pid;
362
- const meta = {
363
- runId,
364
- pid: pid ?? -1,
365
- command: args.command,
366
- cwd,
367
- port: args.port,
368
- healthUrl,
369
- expectStatus,
370
- startedAt: new Date(startedAt).toISOString(),
371
- logPath,
372
- };
373
- writeMeta(metaPath, meta);
374
- const probe = await pollHealth({
375
- url: healthUrl,
376
- expectStatus,
377
- timeoutMs,
378
- fetchImpl,
379
- sleeper,
380
- now,
381
- hasExited: () => exited,
382
- });
383
- if (probe.ok) {
384
- const result = {
385
- ok: true,
386
- runId,
387
- pid,
388
- port: args.port,
389
- healthStatus: probe.status,
390
- logPath,
391
- metaPath,
392
- durationMs: probe.durationMs,
393
- };
394
- writeMeta(metaPath, { ...meta, status: 'healthy', healthStatus: probe.status });
395
- return JSON.stringify(result);
396
- }
397
- // Failure path - surface the reason. The child may still be running
398
- // (timeout) or already dead (process_exited). The caller decides what
399
- // to do with the pid; we do NOT auto-kill so the operator can inspect
400
- // a hung process via `pugi jobs` / `ps`.
401
- const result = {
402
- ok: false,
403
- runId,
404
- ...(pid !== undefined ? { pid } : {}),
405
- port: args.port,
406
- logPath,
407
- metaPath,
408
- durationMs: probe.durationMs,
409
- error: probe.reason ?? 'unknown_failure',
410
- ...(exitCode !== undefined ? { exitCode } : {}),
411
- };
412
- writeMeta(metaPath, {
413
- ...meta,
414
- status: probe.reason ?? 'failed',
415
- ...(exitCode !== undefined ? { exitCode } : {}),
416
- ...(exitSignal !== undefined ? { exitSignal } : {}),
417
- });
418
- return JSON.stringify(result);
419
- }
420
- export function parseServerStopArgs(raw) {
421
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
422
- return `${SERVER_INVALID_ARGS}: arguments must be a JSON object`;
423
- }
424
- const obj = raw;
425
- const pid = obj['pid'];
426
- if (typeof pid !== 'number' || !Number.isInteger(pid) || pid <= 0) {
427
- return `${SERVER_INVALID_ARGS}: pid must be a positive integer`;
428
- }
429
- const graceMs = obj['graceMs'];
430
- if (graceMs !== undefined) {
431
- if (typeof graceMs !== 'number' || !Number.isFinite(graceMs) || graceMs < 0) {
432
- return `${SERVER_INVALID_ARGS}: graceMs must be a non-negative number when provided`;
433
- }
434
- }
435
- return {
436
- pid,
437
- ...(typeof graceMs === 'number' ? { graceMs } : {}),
438
- };
439
- }
440
- /**
441
- * SIGTERM the pid, wait up to graceMs for natural exit, then SIGKILL.
442
- * Returns `ok: true` when the kill chain ran without error - both
443
- * "already exited" and "killed by SIGKILL" count as success because
444
- * the desired outcome (pid no longer running) was achieved.
445
- */
446
- export async function dispatchServerStop(ctx, raw) {
447
- const parsed = parseServerStopArgs(raw);
448
- if (typeof parsed === 'string')
449
- return parsed;
450
- const args = parsed;
451
- const now = ctx.now ?? (() => Date.now());
452
- const sleeper = ctx.sleeper ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
453
- const killImpl = ctx.killImpl ??
454
- ((pid, signal) => {
455
- process.kill(pid, signal);
456
- });
457
- const graceMs = clampGrace(args.graceMs);
458
- const start = now();
459
- const isAlive = (pid) => {
460
- try {
461
- killImpl(pid, 0);
462
- return true;
463
- }
464
- catch {
465
- return false;
466
- }
467
- };
468
- if (!isAlive(args.pid)) {
469
- const result = {
470
- ok: true,
471
- pid: args.pid,
472
- durationMs: now() - start,
473
- signal: undefined,
474
- };
475
- return JSON.stringify(result);
476
- }
477
- try {
478
- killImpl(args.pid, 'SIGTERM');
479
- }
480
- catch (error) {
481
- const message = error.message;
482
- const result = {
483
- ok: false,
484
- pid: args.pid,
485
- durationMs: now() - start,
486
- error: `sigterm_failed: ${message}`,
487
- };
488
- return JSON.stringify(result);
489
- }
490
- // Poll for exit during the grace window.
491
- const deadline = now() + graceMs;
492
- let killedSignal = 'SIGTERM';
493
- while (now() < deadline) {
494
- if (!isAlive(args.pid)) {
495
- const result = {
496
- ok: true,
497
- pid: args.pid,
498
- signal: killedSignal,
499
- durationMs: now() - start,
500
- };
501
- return JSON.stringify(result);
502
- }
503
- await sleeper(50);
504
- }
505
- // Grace expired - escalate to SIGKILL.
506
- try {
507
- killImpl(args.pid, 'SIGKILL');
508
- killedSignal = 'SIGKILL';
509
- }
510
- catch (error) {
511
- const message = error.message;
512
- const result = {
513
- ok: false,
514
- pid: args.pid,
515
- durationMs: now() - start,
516
- error: `sigkill_failed: ${message}`,
517
- };
518
- return JSON.stringify(result);
519
- }
520
- // Brief poll after SIGKILL - kernel should clean up promptly.
521
- const killDeadline = now() + 1_000;
522
- while (now() < killDeadline) {
523
- if (!isAlive(args.pid)) {
524
- const result = {
525
- ok: true,
526
- pid: args.pid,
527
- signal: killedSignal,
528
- durationMs: now() - start,
529
- };
530
- return JSON.stringify(result);
531
- }
532
- await sleeper(50);
533
- }
534
- const result = {
535
- ok: false,
536
- pid: args.pid,
537
- durationMs: now() - start,
538
- error: 'process_still_alive_after_sigkill',
539
- };
540
- return JSON.stringify(result);
541
- }
542
- export function parseServerHealthArgs(raw) {
543
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
544
- return `${SERVER_INVALID_ARGS}: arguments must be a JSON object`;
545
- }
546
- const obj = raw;
547
- const url = obj['url'];
548
- if (typeof url !== 'string' || url.trim() === '') {
549
- return `${SERVER_INVALID_ARGS}: url must be a non-empty string`;
550
- }
551
- const timeoutMs = obj['timeoutMs'];
552
- if (timeoutMs !== undefined) {
553
- if (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
554
- return `${SERVER_INVALID_ARGS}: timeoutMs must be a positive number when provided`;
555
- }
556
- }
557
- const expectStatus = obj['expectStatus'];
558
- if (expectStatus !== undefined) {
559
- if (typeof expectStatus !== 'number' || !Number.isInteger(expectStatus) || expectStatus < 100 || expectStatus > 599) {
560
- return `${SERVER_INVALID_ARGS}: expectStatus must be an integer in [100, 599]`;
561
- }
562
- }
563
- return {
564
- url,
565
- ...(typeof timeoutMs === 'number' ? { timeoutMs } : {}),
566
- ...(typeof expectStatus === 'number' ? { expectStatus } : {}),
567
- };
568
- }
569
- /** Cap on the body we return to the model - keeps the envelope small. */
570
- export const SERVER_HEALTH_BODY_CAP_BYTES = 1024;
571
- /** Default health-probe timeout. */
572
- export const SERVER_HEALTH_DEFAULT_TIMEOUT_MS = 5_000;
573
- /** Upper bound on a single one-shot health-probe timeout. */
574
- export const SERVER_HEALTH_MAX_TIMEOUT_MS = 60_000;
575
- function clampHealthTimeout(value) {
576
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
577
- return SERVER_HEALTH_DEFAULT_TIMEOUT_MS;
578
- }
579
- return Math.min(value, SERVER_HEALTH_MAX_TIMEOUT_MS);
580
- }
581
- /**
582
- * One-shot HTTP GET against the supplied URL. Caller can pin the
583
- * expected status (default 200); anything else surfaces as ok=false
584
- * with the actual status preserved so the model can branch on it.
585
- */
586
- export async function dispatchServerHealth(ctx, raw) {
587
- const parsed = parseServerHealthArgs(raw);
588
- if (typeof parsed === 'string')
589
- return parsed;
590
- const args = parsed;
591
- const now = ctx.now ?? (() => Date.now());
592
- const fetchImpl = ctx.fetch ?? globalThis.fetch;
593
- const expectStatus = args.expectStatus ?? 200;
594
- const timeoutMs = clampHealthTimeout(args.timeoutMs);
595
- if (typeof fetchImpl !== 'function') {
596
- const result = {
597
- ok: false,
598
- status: 0,
599
- durationMs: 0,
600
- error: 'no_fetch_available',
601
- };
602
- return JSON.stringify(result);
603
- }
604
- const start = now();
605
- const ac = new AbortController();
606
- const timer = setTimeout(() => ac.abort(), timeoutMs);
607
- try {
608
- const res = await fetchImpl(args.url, { signal: ac.signal });
609
- const text = await res.text();
610
- const body = text.length > SERVER_HEALTH_BODY_CAP_BYTES ? text.slice(0, SERVER_HEALTH_BODY_CAP_BYTES) : text;
611
- const result = {
612
- ok: res.status === expectStatus,
613
- status: res.status,
614
- durationMs: now() - start,
615
- body,
616
- };
617
- return JSON.stringify(result);
618
- }
619
- catch (error) {
620
- const message = error.message;
621
- const aborted = error.name === 'AbortError' || ac.signal.aborted;
622
- const result = {
623
- ok: false,
624
- status: 0,
625
- durationMs: now() - start,
626
- error: aborted
627
- ? `timeout_after_${timeoutMs}ms`
628
- : message === '' ? 'health_request_failed' : `health_request_failed: ${message}`,
629
- };
630
- return JSON.stringify(result);
631
- }
632
- finally {
633
- clearTimeout(timer);
634
- }
635
- }
636
- export function parseServerLogsArgs(raw) {
637
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
638
- return `${SERVER_INVALID_ARGS}: arguments must be a JSON object`;
639
- }
640
- const obj = raw;
641
- const runId = obj['runId'];
642
- const pid = obj['pid'];
643
- const tail = obj['tail'];
644
- if (runId !== undefined && typeof runId !== 'string') {
645
- return `${SERVER_INVALID_ARGS}: runId must be a string when provided`;
646
- }
647
- // /triple-review P1 (Claude reviewer): runId flows
648
- // unchecked into `join(workspaceRoot, '.pugi', 'runs', runId, 'server.log')`.
649
- // A runId of `../../etc/passwd` (or other `..` traversal) escapes
650
- // the workspace and reads arbitrary files via the surfaced `lines[]`.
651
- // Pin к the `srv-<uuid>` shape that `dispatchServerStart` mints
652
- // (`srv-` + `randomUUID()` = lowercase hex + dashes).
653
- if (typeof runId === 'string' && !/^srv-[a-f0-9-]{36}$/.test(runId)) {
654
- return `${SERVER_INVALID_ARGS}: runId must match srv-<uuid> shape`;
655
- }
656
- if (pid !== undefined) {
657
- if (typeof pid !== 'number' || !Number.isInteger(pid) || pid <= 0) {
658
- return `${SERVER_INVALID_ARGS}: pid must be a positive integer when provided`;
659
- }
660
- }
661
- if (tail !== undefined) {
662
- if (typeof tail !== 'number' || !Number.isFinite(tail) || tail <= 0) {
663
- return `${SERVER_INVALID_ARGS}: tail must be a positive number when provided`;
664
- }
665
- }
666
- if (runId === undefined && pid === undefined) {
667
- // Allow "latest" by resolving the most recent runs dir at dispatch
668
- // time; nothing to validate here.
669
- }
670
- return {
671
- ...(typeof runId === 'string' ? { runId } : {}),
672
- ...(typeof pid === 'number' ? { pid } : {}),
673
- ...(typeof tail === 'number' ? { tail } : {}),
674
- };
675
- }
676
- function resolveLatestRunId(workspaceRoot) {
677
- const dir = join(workspaceRoot, '.pugi', 'runs');
678
- if (!existsSync(dir))
679
- return undefined;
680
- try {
681
- // We avoid statSync per-entry to keep the tool cheap; the runId
682
- // includes a uuid so lexicographic sort is stable enough for the
683
- // "latest run" answer when the operator does not pin one.
684
- const entries = readdirSync(dir, { withFileTypes: true })
685
- .filter((e) => e.isDirectory() && e.name.startsWith('srv-'))
686
- .map((e) => e.name)
687
- .sort();
688
- return entries[entries.length - 1];
689
- }
690
- catch {
691
- return undefined;
692
- }
693
- }
694
- function resolveRunIdByPid(workspaceRoot, pid) {
695
- const dir = join(workspaceRoot, '.pugi', 'runs');
696
- if (!existsSync(dir))
697
- return undefined;
698
- try {
699
- const entries = readdirSync(dir, { withFileTypes: true })
700
- .filter((e) => e.isDirectory() && e.name.startsWith('srv-'))
701
- .map((e) => e.name);
702
- for (const id of entries) {
703
- try {
704
- const metaPath = join(dir, id, 'server.json');
705
- if (!existsSync(metaPath))
706
- continue;
707
- const raw = readFileSync(metaPath, 'utf8');
708
- const meta = JSON.parse(raw);
709
- if (meta && meta['pid'] === pid)
710
- return id;
711
- }
712
- catch {
713
- // skip unreadable meta files
714
- }
715
- }
716
- }
717
- catch {
718
- // ignore
719
- }
720
- return undefined;
721
- }
722
- /**
723
- * Read the trailing N lines of `<runId>/server.log`. When neither
724
- * runId nor pid is supplied, the dispatcher falls back to the latest
725
- * run dir (sorted lexicographically by runId). When pid is supplied,
726
- * the dispatcher walks every run dir looking for a meta.json whose
727
- * pid matches.
728
- */
729
- export async function dispatchServerLogs(ctx, raw) {
730
- const parsed = parseServerLogsArgs(raw);
731
- if (typeof parsed === 'string')
732
- return parsed;
733
- const args = parsed;
734
- const tail = clampTail(args.tail);
735
- let runId = args.runId;
736
- if (!runId && typeof args.pid === 'number') {
737
- runId = resolveRunIdByPid(ctx.workspaceRoot, args.pid);
738
- }
739
- if (!runId) {
740
- runId = resolveLatestRunId(ctx.workspaceRoot);
741
- }
742
- if (!runId) {
743
- const result = {
744
- ok: false,
745
- logPath: '',
746
- lines: [],
747
- totalLines: 0,
748
- error: 'no_run_found',
749
- };
750
- return JSON.stringify(result);
751
- }
752
- const logPath = join(ctx.workspaceRoot, '.pugi', 'runs', runId, 'server.log');
753
- if (!existsSync(logPath)) {
754
- const result = {
755
- ok: false,
756
- logPath,
757
- lines: [],
758
- totalLines: 0,
759
- error: 'log_not_found',
760
- };
761
- return JSON.stringify(result);
762
- }
763
- let body = '';
764
- try {
765
- body = readFileSync(logPath, 'utf8');
766
- }
767
- catch (error) {
768
- const message = error.message;
769
- const result = {
770
- ok: false,
771
- logPath,
772
- lines: [],
773
- totalLines: 0,
774
- error: `read_failed: ${message}`,
775
- };
776
- return JSON.stringify(result);
777
- }
778
- const allLines = body.split('\n');
779
- // Trim trailing empty produced by a final newline so the line count
780
- // reflects "actual log lines" not "lines + trailing blank".
781
- if (allLines.length > 0 && allLines[allLines.length - 1] === '') {
782
- allLines.pop();
783
- }
784
- const lines = allLines.length > tail ? allLines.slice(allLines.length - tail) : allLines;
785
- const result = {
786
- ok: true,
787
- logPath,
788
- lines,
789
- totalLines: allLines.length,
790
- };
791
- return JSON.stringify(result);
792
- }
793
- /* ----------------------- JSON schema fragments ----------------------- */
794
- export const serverStartJsonSchema = {
795
- type: 'object',
796
- additionalProperties: false,
797
- required: ['command', 'port'],
798
- properties: {
799
- command: {
800
- type: 'string',
801
- description: 'Shell command to spawn, e.g. "npm run dev" or "node server.js".',
802
- },
803
- cwd: {
804
- type: 'string',
805
- description: 'Workspace-relative cwd for the spawn. Absolute paths must fall inside the workspace.',
806
- },
807
- port: {
808
- type: 'integer',
809
- minimum: 1,
810
- maximum: 65535,
811
- description: 'Expected listening port. Used in the default healthUrl when no healthUrl is supplied.',
812
- },
813
- healthUrl: {
814
- type: 'string',
815
- description: 'Optional HTTP health URL. Defaults to http://localhost:<port>/health.',
816
- },
817
- timeoutMs: {
818
- type: 'number',
819
- description: `Health-probe timeout in ms. Default ${SERVER_START_DEFAULT_TIMEOUT_MS}, max ${SERVER_START_MAX_TIMEOUT_MS}.`,
820
- },
821
- expectStatus: {
822
- type: 'integer',
823
- minimum: 100,
824
- maximum: 599,
825
- description: 'Expected HTTP status. Default 200.',
826
- },
827
- env: {
828
- type: 'object',
829
- description: 'Optional env override map. Values must be strings.',
830
- additionalProperties: { type: 'string' },
831
- },
832
- },
833
- };
834
- export const serverStopJsonSchema = {
835
- type: 'object',
836
- additionalProperties: false,
837
- required: ['pid'],
838
- properties: {
839
- pid: {
840
- type: 'integer',
841
- minimum: 1,
842
- description: 'Process id of a server started via `server_start`.',
843
- },
844
- graceMs: {
845
- type: 'number',
846
- minimum: 0,
847
- description: `SIGTERM → SIGKILL grace window in ms. Default ${SERVER_STOP_DEFAULT_GRACE_MS}, max ${SERVER_STOP_MAX_GRACE_MS}.`,
848
- },
849
- },
850
- };
851
- export const serverHealthJsonSchema = {
852
- type: 'object',
853
- additionalProperties: false,
854
- required: ['url'],
855
- properties: {
856
- url: {
857
- type: 'string',
858
- description: 'Fully-qualified HTTP/HTTPS URL to probe.',
859
- },
860
- timeoutMs: {
861
- type: 'number',
862
- description: `Single-shot probe timeout in ms. Default ${SERVER_HEALTH_DEFAULT_TIMEOUT_MS}, max ${SERVER_HEALTH_MAX_TIMEOUT_MS}.`,
863
- },
864
- expectStatus: {
865
- type: 'integer',
866
- minimum: 100,
867
- maximum: 599,
868
- description: 'Expected HTTP status. Default 200.',
869
- },
870
- },
871
- };
872
- export const serverLogsJsonSchema = {
873
- type: 'object',
874
- additionalProperties: false,
875
- properties: {
876
- runId: {
877
- type: 'string',
878
- description: 'Run identifier returned by `server_start`. Falls back to the latest run when omitted.',
879
- },
880
- pid: {
881
- type: 'integer',
882
- minimum: 1,
883
- description: 'Optional process id; the dispatcher finds the matching run dir.',
884
- },
885
- tail: {
886
- type: 'number',
887
- minimum: 1,
888
- description: `Trailing lines to return. Default ${SERVER_LOGS_DEFAULT_TAIL}, max ${SERVER_LOGS_MAX_TAIL}.`,
889
- },
890
- },
891
- };
892
- //# sourceMappingURL=server-tools.js.map