@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,480 +0,0 @@
1
- import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
4
- import { request } from 'undici';
5
- import { validateHostnameForFetch } from '../../tools/web-fetch.js';
6
- /**
7
- * Skill / Agent source resolver.
8
- *
9
- * Translates a `<source>` argument from `pugi skills install <source>`
10
- * into a temp directory containing the canonical layout we install
11
- * from (`SKILL.md` for skills, `<name>.md` for agents).
12
- *
13
- * Supported source schemes:
14
- *
15
- * 1. `gh:owner/repo[/subdir][@ref]`
16
- * → `gh:anthropics/skills/python-coding-standards@main`
17
- * Fetches the GitHub tarball via the public codeload endpoint,
18
- * extracts the requested subtree.
19
- *
20
- * 2. `https://github.com/<owner>/<repo>/tree/<ref>/<subdir>` (or `/blob/`)
21
- * Normalised to the gh: form above.
22
- *
23
- * 3. `anthropic:<slug>` — convenience alias for
24
- * `gh:anthropics/skills/<slug>@main`. Hard-coded base; the only
25
- * reason this exists is so operators can copy a slug from the
26
- * Anthropic docs without remembering the org name.
27
- *
28
- * 4. `npm:<package>` — fetches a tarball from the npm registry,
29
- * extracts, looks for `SKILL.md` at the package root.
30
- *
31
- * 5. Local path — `./relative` or `/abs/path`. Copied to tmp so the
32
- * caller can mutate the original without affecting install.
33
- *
34
- * 6. Catalog name — bare slug, queried against
35
- * `https://catalog.pugi.dev/api/skills/<name>`. Returns a 404 →
36
- * we surface a hint pointing at the `gh:anthropics/skills/<name>`
37
- * form rather than crashing.
38
- *
39
- * Every resolver writes the payload into a fresh temp dir under
40
- * `/tmp/pugi-skill-XXXXXX/` (caller cleans up after install completes).
41
- * Network failures bubble up as `SOURCE_NETWORK` errors with the host
42
- * + status code so the operator can diagnose firewall / proxy issues.
43
- */
44
- const ANTHROPIC_REPO = 'gh:anthropics/skills';
45
- const CATALOG_BASE = process.env.PUGI_CATALOG_URL ?? 'https://catalog.pugi.dev';
46
- const FETCH_TIMEOUT_MS = 30_000;
47
- const MAX_PAYLOAD_BYTES = 50 * 1024 * 1024; // 50 MB cap on any single download
48
- export async function fetchSource(source) {
49
- if (source.startsWith('gh:')) {
50
- return fetchGitHub(source.slice(3));
51
- }
52
- if (source.startsWith('https://github.com/') || source.startsWith('http://github.com/')) {
53
- return fetchGitHub(normalizeGithubUrl(source));
54
- }
55
- if (source.startsWith('anthropic:')) {
56
- const slug = source.slice('anthropic:'.length);
57
- if (!slug || slug.includes('/')) {
58
- throw new Error(`SOURCE_PARSE: anthropic: source needs a bare slug (got "${source}"). Example: anthropic:algorithmic-art`);
59
- }
60
- // Real layout is `anthropics/skills` repo → `skills/<slug>/SKILL.md`.
61
- // Verified against the live repo tarball.
62
- return fetchGitHub(`${ANTHROPIC_REPO}/skills/${slug}@main`.slice(3));
63
- }
64
- if (source.startsWith('npm:')) {
65
- return fetchNpm(source.slice('npm:'.length));
66
- }
67
- if (source.startsWith('./') || source.startsWith('../') || isAbsolute(source)) {
68
- return fetchLocal(source);
69
- }
70
- // Bare slug — try the catalog. Catalog might be down or the slug
71
- // might not exist; fall through with a clear hint instead of crashing.
72
- return fetchCatalog(source);
73
- }
74
- function normalizeGithubUrl(url) {
75
- // https://github.com/<owner>/<repo>/tree/<ref>/<path...>
76
- // https://github.com/<owner>/<repo>/blob/<ref>/<path...>
77
- // https://github.com/<owner>/<repo>
78
- const match = url.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\/(?:tree|blob)\/([^/]+)(?:\/(.+?))?)?(?:\.git)?\/?$/);
79
- if (!match) {
80
- throw new Error(`SOURCE_PARSE: cannot parse GitHub URL "${url}"`);
81
- }
82
- const [, owner, repo, ref, subdir] = match;
83
- const ownerRepo = `${owner}/${repo}`;
84
- const subPart = subdir ? `/${subdir}` : '';
85
- const refPart = ref ? `@${ref}` : '';
86
- return `${ownerRepo}${subPart}${refPart}`;
87
- }
88
- function parseGithubSpec(raw) {
89
- // <owner>/<repo>[/<subdir>][@<ref>]
90
- let ref = 'main';
91
- let pathPart = raw;
92
- const atIdx = raw.lastIndexOf('@');
93
- if (atIdx > 0) {
94
- ref = raw.slice(atIdx + 1);
95
- pathPart = raw.slice(0, atIdx);
96
- }
97
- const segments = pathPart.split('/').filter((s) => s.length > 0);
98
- if (segments.length < 2) {
99
- throw new Error(`SOURCE_PARSE: gh: source needs owner/repo (got "${raw}"). Example: gh:anthropics/skills/python-coding-standards@main`);
100
- }
101
- const [owner, repo, ...subdirParts] = segments;
102
- if (!owner || !repo) {
103
- throw new Error(`SOURCE_PARSE: gh: source needs owner/repo (got "${raw}"). Example: gh:anthropics/skills/python-coding-standards@main`);
104
- }
105
- return {
106
- owner,
107
- repo,
108
- subdir: subdirParts.join('/'),
109
- ref,
110
- };
111
- }
112
- async function fetchGitHub(raw) {
113
- const spec = parseGithubSpec(raw);
114
- // Use codeload.github.com — the public tarball endpoint requires no
115
- // auth for public repos and returns a single .tar.gz of the requested
116
- // ref's tree. Private repos are out of scope for .
117
- const tarUrl = `https://codeload.github.com/${spec.owner}/${spec.repo}/tar.gz/${spec.ref}`;
118
- const tmpRoot = mkdtempSync(join(tmpdir(), 'pugi-skill-gh-'));
119
- const tarPath = join(tmpRoot, 'payload.tar.gz');
120
- await downloadToFile(tarUrl, tarPath, `GitHub ${spec.owner}/${spec.repo}@${spec.ref}`);
121
- const extractDir = join(tmpRoot, 'extract');
122
- mkdirSync(extractDir, { recursive: true });
123
- await extractTarball(tarPath, extractDir);
124
- // GitHub tarballs unpack into `<repo>-<sanitised-ref>/` at the root.
125
- const topLevel = readdirSync(extractDir);
126
- if (topLevel.length !== 1) {
127
- throw new Error(`SOURCE_TAR: expected a single root directory in tarball, got ${topLevel.length}`);
128
- }
129
- const rootName = topLevel[0];
130
- if (!rootName) {
131
- throw new Error('SOURCE_TAR: tarball root directory missing');
132
- }
133
- const repoRoot = join(extractDir, rootName);
134
- const payloadRoot = spec.subdir ? join(repoRoot, spec.subdir) : repoRoot;
135
- if (!existsSync(payloadRoot)) {
136
- throw new Error(`SOURCE_PATH: subdirectory "${spec.subdir}" not found in ${spec.owner}/${spec.repo}@${spec.ref}`);
137
- }
138
- const sourceUrl = spec.subdir
139
- ? `https://github.com/${spec.owner}/${spec.repo}/tree/${spec.ref}/${spec.subdir}`
140
- : `https://github.com/${spec.owner}/${spec.repo}/tree/${spec.ref}`;
141
- const inferredKind = inferKind(payloadRoot);
142
- // Move payload into a stable directory inside tmpRoot for cleanup
143
- // simplicity. The caller deletes tmpRoot when install completes.
144
- // verbatimSymlinks: belt-and-braces with the extractTarball filter —
145
- // if a symlink somehow survived (shouldn't), don't auto-follow it
146
- // into secrets on this hop either.
147
- const finalDir = join(tmpRoot, 'payload');
148
- cpSync(payloadRoot, finalDir, { recursive: true, verbatimSymlinks: true });
149
- return { tmpDir: finalDir, sourceUrl, inferredKind };
150
- }
151
- async function fetchNpm(pkg) {
152
- // Resolve registry metadata to find the tarball URL of the latest
153
- // dist-tag. Honour `npm:<pkg>@<version>` for pinning.
154
- let name = pkg;
155
- let version = 'latest';
156
- const atIdx = pkg.lastIndexOf('@');
157
- if (atIdx > 0) {
158
- // Watch out for scoped packages — leading '@' is the scope marker.
159
- name = pkg.slice(0, atIdx);
160
- version = pkg.slice(atIdx + 1);
161
- }
162
- const registryBase = process.env.NPM_REGISTRY ?? 'https://registry.npmjs.org';
163
- const metaUrl = `${registryBase}/${encodeURIComponent(name).replace(/^%40/, '@')}`;
164
- const meta = await fetchJson(metaUrl, `npm registry ${name}`);
165
- const distTags = meta['dist-tags'];
166
- let targetVersion = version;
167
- if (distTags && typeof distTags === 'object' && version in distTags) {
168
- targetVersion = distTags[version] ?? version;
169
- }
170
- const versions = meta.versions;
171
- const versionMeta = versions?.[targetVersion];
172
- const tarballUrl = versionMeta?.dist?.tarball;
173
- if (!tarballUrl) {
174
- throw new Error(`SOURCE_NPM: no tarball for ${name}@${targetVersion}`);
175
- }
176
- const tmpRoot = mkdtempSync(join(tmpdir(), 'pugi-skill-npm-'));
177
- const tarPath = join(tmpRoot, 'payload.tgz');
178
- await downloadToFile(tarballUrl, tarPath, `npm ${name}@${targetVersion}`);
179
- const extractDir = join(tmpRoot, 'extract');
180
- mkdirSync(extractDir, { recursive: true });
181
- await extractTarball(tarPath, extractDir);
182
- // npm tarballs unpack as `package/` at the root.
183
- const packageRoot = join(extractDir, 'package');
184
- if (!existsSync(packageRoot)) {
185
- throw new Error('SOURCE_NPM: expected "package/" root in npm tarball');
186
- }
187
- const inferredKind = inferKind(packageRoot);
188
- const finalDir = join(tmpRoot, 'payload');
189
- cpSync(packageRoot, finalDir, { recursive: true, verbatimSymlinks: true });
190
- return { tmpDir: finalDir, sourceUrl: tarballUrl, inferredKind };
191
- }
192
- async function fetchLocal(rawPath) {
193
- const abs = isAbsolute(rawPath) ? rawPath : resolve(process.cwd(), rawPath);
194
- if (!existsSync(abs)) {
195
- throw new Error(`SOURCE_LOCAL: path does not exist: ${abs}`);
196
- }
197
- const tmpRoot = mkdtempSync(join(tmpdir(), 'pugi-skill-local-'));
198
- const finalDir = join(tmpRoot, 'payload');
199
- const stat = statSync(abs);
200
- if (stat.isFile()) {
201
- // Single-file agent install: copy as-is into the tmp dir.
202
- mkdirSync(finalDir, { recursive: true });
203
- cpSync(abs, join(finalDir, abs.split(sep).pop() ?? 'agent.md'), { verbatimSymlinks: true });
204
- }
205
- else {
206
- cpSync(abs, finalDir, { recursive: true, verbatimSymlinks: true });
207
- }
208
- const inferredKind = inferKind(finalDir);
209
- return { tmpDir: finalDir, sourceUrl: `file://${abs}`, inferredKind };
210
- }
211
- async function fetchCatalog(name) {
212
- const url = `${CATALOG_BASE}/api/skills/${encodeURIComponent(name)}`;
213
- let meta = null;
214
- try {
215
- meta = await fetchJson(url, `catalog ${name}`);
216
- }
217
- catch (error) {
218
- const message = error instanceof Error ? error.message : String(error);
219
- throw new Error(`CATALOG_UNREACHABLE: could not query ${CATALOG_BASE} for "${name}" (${message}). Try a direct source like "gh:anthropics/skills/${name}@main".`);
220
- }
221
- if (!meta || typeof meta !== 'object') {
222
- throw new Error(`CATALOG_NOT_FOUND: skill "${name}" not found in ${CATALOG_BASE}. Did you mean "gh:anthropics/skills/${name}@main"?`);
223
- }
224
- const upstream = meta.source;
225
- if (typeof upstream !== 'string') {
226
- throw new Error(`CATALOG_INVALID: catalog entry for "${name}" missing "source" field`);
227
- }
228
- // Catalog payload tells us which canonical source to fetch. Recurse.
229
- return fetchSource(upstream);
230
- }
231
- /**
232
- * Probe the payload root and decide whether it looks like a skill
233
- * (`SKILL.md` at root) or an agent (single `.md` at root).
234
- * Tie-breaker: SKILL.md wins because Skills are the dominant format.
235
- */
236
- function inferKind(dir) {
237
- const entries = readdirSync(dir);
238
- if (entries.some((name) => name === 'SKILL.md')) {
239
- return 'skill';
240
- }
241
- const mdFiles = entries.filter((name) => name.toLowerCase().endsWith('.md'));
242
- if (mdFiles.length === 1) {
243
- return 'agent';
244
- }
245
- if (mdFiles.length > 1) {
246
- // Multiple markdowns without a SKILL.md — assume skill, the loader
247
- // will throw a clear "missing SKILL.md" error.
248
- return 'skill';
249
- }
250
- return 'skill';
251
- }
252
- const MAX_REDIRECTS = 5;
253
- /**
254
- * Internal redirect-following GET. undici@8 does not honour
255
- * `maxRedirections` on the top-level `request` call (it lives on the
256
- * Agent), so we walk redirects manually. Hop cap prevents loops.
257
- */
258
- async function requestFollow(url) {
259
- let currentUrl = url;
260
- // SSRF guard: every hop (initial + each redirect target) must resolve
261
- // to a public address. The redirect-following loop below re-runs the
262
- // guard on the post-redirect URL so a 302 → http://169.254.169.254/
263
- // (AWS metadata service) cannot smuggle a private fetch.
264
- //
265
- // We reuse the shared `validateHostnameForFetch` from web-fetch.ts so
266
- // there is one canonical IPv4/IPv6 blocklist + DNS-resolution check
267
- // across every Pugi outbound surface (web_fetch tool, skills installer,
268
- // future: webhook delivery). Drift between two copies of that block
269
- // list would be a real footgun — the SSRF cheat-sheet covers ~10
270
- // ranges and missing one (e.g. SIIT/NAT64) is exactly the class of
271
- // bug Codex caught in PR.
272
- // Initial scheme — locked for entire redirect chain. Codex P2 review
273
- // (PR v2): an HTTPS source that 302s к public http:// URL would
274
- // otherwise be fetched cleartext, MITM tampers payload. Stay TLS.
275
- const initialScheme = new URL(currentUrl).protocol;
276
- await guardOutboundUrl(currentUrl, 'initial request', initialScheme);
277
- for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
278
- const response = await request(currentUrl, {
279
- method: 'GET',
280
- headersTimeout: FETCH_TIMEOUT_MS,
281
- bodyTimeout: FETCH_TIMEOUT_MS,
282
- });
283
- if (response.statusCode >= 300 && response.statusCode < 400) {
284
- const loc = response.headers['location'];
285
- const locStr = Array.isArray(loc) ? loc[0] : loc;
286
- if (typeof locStr !== 'string' || locStr.length === 0) {
287
- return response;
288
- }
289
- // Drain body so socket reusable.
290
- await response.body.dump();
291
- const nextUrl = new URL(locStr, currentUrl).toString();
292
- await guardOutboundUrl(nextUrl, `redirect from ${currentUrl}`, initialScheme);
293
- currentUrl = nextUrl;
294
- continue;
295
- }
296
- return response;
297
- }
298
- throw new Error(`SOURCE_NETWORK: redirect limit (${MAX_REDIRECTS}) exceeded`);
299
- }
300
- // P2 DNS rebinding follow-up: pinned-address Dispatcher с undici lookup
301
- // hook. Filed task — TOCTOU window microseconds + needs attacker DNS
302
- // control. Acceptable v1 trade-off; not blocking initial ship.
303
- /**
304
- * SSRF gate for one outbound URL hop. Throws `SOURCE_SSRF` when the
305
- * URL is malformed, uses a non-http(s) scheme, or resolves to any
306
- * private/loopback/link-local/CGNAT/metadata range.
307
- *
308
- * Called from `requestFollow` on the initial URL and every redirect
309
- * target so a 302 → http://10.0.0.5/ (or → http://169.254.169.254/)
310
- * cannot bypass the gate. Also rejects scheme downgrades (https → http)
311
- * so a redirect that takes us off TLS aborts loudly instead of silently.
312
- */
313
- async function guardOutboundUrl(rawUrl, label, initialScheme) {
314
- let parsed;
315
- try {
316
- parsed = new URL(rawUrl);
317
- }
318
- catch {
319
- throw new Error(`SOURCE_SSRF: ${label} URL is malformed: ${rawUrl}`);
320
- }
321
- if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
322
- throw new Error(`SOURCE_SSRF: ${label} uses unsupported scheme ${parsed.protocol} (only http/https).`);
323
- }
324
- // Codex P2 PR v2: HTTPS source MUST NOT downgrade к HTTP across
325
- // redirect chain — would let MITM tamper с payload after the initial
326
- // TLS hop. Once we started TLS, stay TLS.
327
- if (initialScheme === 'https:' && parsed.protocol === 'http:') {
328
- throw new Error(`SOURCE_SSRF: ${label} attempts HTTPS→HTTP downgrade — refused (payload integrity required).`);
329
- }
330
- const verdict = await validateHostnameForFetch(parsed.hostname);
331
- if (verdict !== null) {
332
- throw new Error(`SOURCE_SSRF: ${label} refused — ${verdict}`);
333
- }
334
- }
335
- async function downloadToFile(url, outPath, label) {
336
- try {
337
- const response = await requestFollow(url);
338
- if (response.statusCode < 200 || response.statusCode >= 300) {
339
- const body = await response.body.text();
340
- const err = new Error(`SOURCE_NETWORK: ${label} returned HTTP ${response.statusCode}. ${body.slice(0, 200)}`);
341
- err.status = response.statusCode;
342
- throw err;
343
- }
344
- mkdirSync(dirname(outPath), { recursive: true });
345
- const chunks = [];
346
- let total = 0;
347
- for await (const chunk of response.body) {
348
- const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
349
- total += buf.byteLength;
350
- if (total > MAX_PAYLOAD_BYTES) {
351
- throw new Error(`SOURCE_SIZE: ${label} payload exceeded ${Math.round(MAX_PAYLOAD_BYTES / (1024 * 1024))}MB cap`);
352
- }
353
- chunks.push(buf);
354
- }
355
- writeFileSync(outPath, Buffer.concat(chunks));
356
- }
357
- catch (error) {
358
- if (error instanceof Error && error.message.startsWith('SOURCE_')) {
359
- throw error;
360
- }
361
- const message = error instanceof Error ? error.message : String(error);
362
- throw new Error(`SOURCE_NETWORK: ${label} fetch failed (${message})`);
363
- }
364
- }
365
- async function fetchJson(url, label) {
366
- const response = await requestFollow(url);
367
- if (response.statusCode === 404) {
368
- throw new Error(`SOURCE_NOT_FOUND: ${label} returned HTTP 404`);
369
- }
370
- if (response.statusCode < 200 || response.statusCode >= 300) {
371
- throw new Error(`SOURCE_NETWORK: ${label} returned HTTP ${response.statusCode}`);
372
- }
373
- const text = await response.body.text();
374
- try {
375
- return JSON.parse(text);
376
- }
377
- catch {
378
- throw new Error(`SOURCE_PARSE: ${label} returned invalid JSON`);
379
- }
380
- }
381
- async function extractTarball(tarPath, destDir) {
382
- // Use the `tar` package (already on disk via transitive hoisting) so
383
- // we get streaming gunzip + extraction without a custom parser.
384
- // Dynamic import keeps the dependency lazy: operators who never
385
- // install a skill never load tar.
386
- //
387
- // Security model: we collect filter violations in `violations`
388
- // rather than throwing inside the filter callback. node-tar v6
389
- // dispatches the filter from inside the streaming parser; a sync
390
- // throw there surfaces as an uncaughtException because the parser's
391
- // internal event chain is not awaited by tar.x's promise. Skipping
392
- // (return false) keeps the stream healthy; we abort after extraction
393
- // completes so no hostile entry is ever materialised to disk AND
394
- // the operator sees a precise error.
395
- const tarModule = await loadTarModule();
396
- const violations = [];
397
- await tarModule.x({
398
- file: tarPath,
399
- cwd: destDir,
400
- // strict: true rejects bad records (bad checksums, truncated
401
- // headers, mtime-newer-than-now). Required for defense-in-depth
402
- // even though our filter below catches the high-value cases.
403
- strict: true,
404
- // Filter returns false to skip the entry. We accumulate the
405
- // violations and throw AFTER extraction completes (see below).
406
- filter: (path, entry) => {
407
- // 1. Block any symlink or hardlink — these are the tar-slip
408
- // vectors. A symlink to ../../home/user/.ssh + a follow-up
409
- // write to that symlink would exfil secrets.
410
- if (entry.type === 'SymbolicLink' || entry.type === 'Link') {
411
- violations.push(`SOURCE_TAR_SYMLINK: tarball contains ${entry.type} entry (${path} → ${entry.linkpath ?? '?'}). Refusing extraction.`);
412
- return false;
413
- }
414
- // 2. Block absolute paths — `tar` strips the leading "/" in
415
- // permissive mode and writes anyway. We refuse such entries.
416
- if (path.startsWith('/')) {
417
- violations.push(`SOURCE_TAR_ABSOLUTE: tarball entry has absolute path: ${path}`);
418
- return false;
419
- }
420
- // 3. Block parent-traversal segments. `..` as a path segment
421
- // cannot be present in any legitimate skill/agent payload.
422
- const segments = path.split(/[\\/]+/);
423
- if (segments.includes('..')) {
424
- violations.push(`SOURCE_TAR_TRAVERSAL: tarball entry has parent-traversal segment: ${path}`);
425
- return false;
426
- }
427
- // 4. Block null-byte truncation attempts.
428
- if (path.includes('\0')) {
429
- violations.push(`SOURCE_TAR_NULLBYTE: tarball entry contains null byte: ${JSON.stringify(path)}`);
430
- return false;
431
- }
432
- return true;
433
- },
434
- });
435
- if (violations.length > 0) {
436
- // Throw the FIRST violation verbatim so callers can pattern-match
437
- // on the specific code (SOURCE_TAR_SYMLINK / _ABSOLUTE / _TRAVERSAL
438
- // / _NULLBYTE). Append a count summary when there are multiple.
439
- const head = violations[0] ?? 'SOURCE_TAR: unspecified violation';
440
- if (violations.length === 1)
441
- throw new Error(head);
442
- throw new Error(`${head} (and ${violations.length - 1} more refused entries)`);
443
- }
444
- }
445
- /**
446
- * Lazy-loaded `tar` module reference. Decoupled so tests can stub it.
447
- */
448
- let cachedTarModule = null;
449
- async function loadTarModule() {
450
- if (cachedTarModule)
451
- return cachedTarModule;
452
- // `tar` is a CJS module exporting `x`/`c`/`u`/`t`. We type it loosely
453
- // because we only need the extract entry-point.
454
- const imported = (await import('tar'));
455
- cachedTarModule = imported;
456
- return imported;
457
- }
458
- /**
459
- * Best-effort tmp cleanup. Never throws — install path must succeed
460
- * even when the OS refuses to delete a tmp dir (rare but possible on
461
- * Windows under tests).
462
- */
463
- export function cleanupTmp(tmpDir) {
464
- try {
465
- // Walk up to the mkdtemp parent: tmpDir was created by either
466
- // moving into `<root>/payload` or by reading `<root>/payload`. We
467
- // delete the parent so the tarball + extract dir also go away.
468
- const parent = dirname(tmpDir);
469
- if (parent.includes('pugi-skill-')) {
470
- rmSync(parent, { recursive: true, force: true });
471
- }
472
- else {
473
- rmSync(tmpDir, { recursive: true, force: true });
474
- }
475
- }
476
- catch {
477
- /* swallow */
478
- }
479
- }
480
- //# sourceMappingURL=sources.js.map
@@ -1,172 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, } from 'node:fs';
3
- import { homedir } from 'node:os';
4
- import { dirname, join, resolve } from 'node:path';
5
- import { z } from 'zod';
6
- const trustEntrySchema = z.object({
7
- kind: z.enum(['skill', 'agent']),
8
- scope: z.enum(['global', 'workspace']),
9
- name: z.string().min(1),
10
- sha256: z.string().regex(/^[0-9a-f]{64}$/),
11
- source: z.string().min(1),
12
- signedAt: z.string().datetime(),
13
- signedBy: z.string().min(1),
14
- });
15
- const trustRegistrySchema = z.object({
16
- schema: z.number().int().positive().default(1),
17
- entries: z.array(trustEntrySchema).default([]),
18
- });
19
- const TRUST_REGISTRY_FILENAME = 'trust.json';
20
- function registryPath() {
21
- const home = process.env.PUGI_HOME ?? resolve(homedir(), '.pugi');
22
- return resolve(home, TRUST_REGISTRY_FILENAME);
23
- }
24
- function readRegistry() {
25
- const path = registryPath();
26
- if (!existsSync(path)) {
27
- return { schema: 1, entries: [] };
28
- }
29
- const raw = readFileSync(path, 'utf8');
30
- if (raw.trim() === '') {
31
- return { schema: 1, entries: [] };
32
- }
33
- // Recovery path for a corrupt trust.json. Without this, a single
34
- // malformed entry (truncated write on power loss, partial disk
35
- // corruption, manual edit gone wrong) would brick every skill +
36
- // agent surface: every command calls readRegistry. We back up the
37
- // bad file (preserving forensic evidence) and reset to an empty
38
- // registry. The operator must re-trust on next install — strictly
39
- // safer than auto-trusting on-disk payloads.
40
- let parsedJson;
41
- try {
42
- parsedJson = JSON.parse(raw);
43
- }
44
- catch (error) {
45
- const message = error instanceof Error ? error.message : String(error);
46
- const backup = `${path}.corrupt-${Date.now()}`;
47
- try {
48
- renameSync(path, backup);
49
- }
50
- catch {
51
- /* swallow — best-effort backup */
52
- }
53
- process.stderr.write(`[pugi] trust.json invalid JSON: ${message}. Backed up to ${backup}. Resetting to empty registry.\n`);
54
- return { schema: 1, entries: [] };
55
- }
56
- try {
57
- return trustRegistrySchema.parse(parsedJson);
58
- }
59
- catch (error) {
60
- const message = error instanceof Error ? error.message : String(error);
61
- const backup = `${path}.corrupt-${Date.now()}`;
62
- try {
63
- renameSync(path, backup);
64
- }
65
- catch {
66
- /* swallow */
67
- }
68
- process.stderr.write(`[pugi] trust.json failed schema validation: ${message}. Backed up to ${backup}. Resetting to empty registry.\n`);
69
- return { schema: 1, entries: [] };
70
- }
71
- }
72
- function writeRegistry(registry) {
73
- const path = registryPath();
74
- mkdirSync(dirname(path), { recursive: true });
75
- // Atomic write: write to a unique temp file, fsync via writeFileSync's
76
- // default behaviour, then rename(2) over the live path. POSIX rename
77
- // is atomic on the same filesystem, so a crash between write+rename
78
- // leaves trust.json EITHER pre-state OR post-state — never a
79
- // half-written file that would trip the schema parser on the next
80
- // read. Mode 0o600 — registry reveals which third-party skills the
81
- // operator has approved. Parity with the other Pugi trust ledgers.
82
- const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
83
- writeFileSync(tmp, `${JSON.stringify(registry, null, 2)}\n`, {
84
- encoding: 'utf8',
85
- mode: 0o600,
86
- });
87
- renameSync(tmp, path);
88
- }
89
- function entryKey(kind, scope, name) {
90
- return `${kind}:${scope}:${name}`;
91
- }
92
- /**
93
- * Walk a directory tree and produce a stable sha256 over its contents.
94
- * Sorting filenames gives reproducible hashes across filesystems with
95
- * different `readdir` orderings (ext4 vs apfs).
96
- *
97
- * Files are hashed as `<relative-path>\0<bytes>\0` segments so a file
98
- * rename inside the tree is detectable even when total bytes are equal.
99
- */
100
- export function hashSkillDir(rootDir) {
101
- const hasher = createHash('sha256');
102
- const walk = (dir, prefix) => {
103
- const names = readdirSync(dir).sort((a, b) => a.localeCompare(b));
104
- for (const name of names) {
105
- const full = join(dir, name);
106
- const rel = prefix ? `${prefix}/${name}` : name;
107
- const stat = statSync(full);
108
- if (stat.isDirectory()) {
109
- walk(full, rel);
110
- }
111
- else if (stat.isFile()) {
112
- hasher.update(rel);
113
- hasher.update('\0');
114
- hasher.update(readFileSync(full));
115
- hasher.update('\0');
116
- }
117
- }
118
- };
119
- walk(rootDir, '');
120
- return hasher.digest('hex');
121
- }
122
- /**
123
- * sha256 of a single file — used for agent payloads (single .md file
124
- * at `~/.pugi/agents/<slug>.md`).
125
- */
126
- export function hashAgentFile(filePath) {
127
- const hasher = createHash('sha256');
128
- hasher.update(readFileSync(filePath));
129
- return hasher.digest('hex');
130
- }
131
- export async function recordTrust(input) {
132
- const registry = readRegistry();
133
- const key = entryKey(input.kind, input.scope, input.name);
134
- const filtered = registry.entries.filter((entry) => entryKey(entry.kind, entry.scope, entry.name) !== key);
135
- filtered.push({
136
- kind: input.kind,
137
- scope: input.scope,
138
- name: input.name,
139
- sha256: input.sha256,
140
- source: input.source,
141
- signedAt: new Date().toISOString(),
142
- signedBy: input.signedBy,
143
- });
144
- writeRegistry({ schema: registry.schema, entries: filtered });
145
- }
146
- export async function getTrust(kind, scope, name) {
147
- const registry = readRegistry();
148
- const key = entryKey(kind, scope, name);
149
- return (registry.entries.find((entry) => entryKey(entry.kind, entry.scope, entry.name) === key) ??
150
- null);
151
- }
152
- export async function revokeTrust(kind, scope, name) {
153
- const registry = readRegistry();
154
- const key = entryKey(kind, scope, name);
155
- const filtered = registry.entries.filter((entry) => entryKey(entry.kind, entry.scope, entry.name) !== key);
156
- writeRegistry({ schema: registry.schema, entries: filtered });
157
- }
158
- export async function listTrust() {
159
- const registry = readRegistry();
160
- return [...registry.entries];
161
- }
162
- export async function verifyTrust(kind, scope, name, actualSha256) {
163
- const entry = await getTrust(kind, scope, name);
164
- if (!entry) {
165
- return { status: 'unsigned' };
166
- }
167
- if (entry.sha256 !== actualSha256) {
168
- return { status: 'mismatch', recorded: entry.sha256, actual: actualSha256 };
169
- }
170
- return { status: 'trusted', signedAt: entry.signedAt, signedBy: entry.signedBy };
171
- }
172
- //# sourceMappingURL=trust.js.map