@herbertgao/pi-extensions 2026.9.5 → 2026.9.7

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 (276) hide show
  1. package/README.md +5 -22
  2. package/THIRD_PARTY_NOTICES.md +0 -4
  3. package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +1 -1
  4. package/node_modules/@herbertgao/sol-pi/package.json +1 -1
  5. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/action-fusion/index.ts +0 -5
  6. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/state.ts +3 -1
  7. package/node_modules/@narumitw/pi-btw/README.md +2 -0
  8. package/node_modules/@narumitw/pi-btw/dist/index.ts +284 -365
  9. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +3 -3
  10. package/node_modules/@narumitw/pi-btw/package.json +52 -53
  11. package/node_modules/@narumitw/pi-btw/src/bring-to-main.ts +494 -547
  12. package/node_modules/@narumitw/pi-btw/src/btw.ts +814 -856
  13. package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +673 -674
  14. package/node_modules/@narumitw/pi-btw/src/keybindings.ts +228 -270
  15. package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +309 -318
  16. package/node_modules/@narumitw/pi-btw/src/menu.ts +416 -454
  17. package/node_modules/@narumitw/pi-btw/src/settings.ts +203 -219
  18. package/node_modules/@narumitw/pi-btw/src/side-thread.ts +173 -201
  19. package/node_modules/@narumitw/pi-btw/src/text.ts +21 -23
  20. package/node_modules/@narumitw/pi-btw/src/transcript-markdown.ts +65 -0
  21. package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +611 -662
  22. package/node_modules/pi-lens/CHANGELOG.md +239 -0
  23. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +3 -0
  24. package/node_modules/pi-lens/dist/clients/actionable-warnings.js +30 -4
  25. package/node_modules/pi-lens/dist/clients/agent-behavior-client.js +2 -0
  26. package/node_modules/pi-lens/dist/clients/bash-file-access.js +26 -0
  27. package/node_modules/pi-lens/dist/clients/biome-client.js +1 -1
  28. package/node_modules/pi-lens/dist/clients/blocker-freshness.js +403 -35
  29. package/node_modules/pi-lens/dist/clients/bootstrap.js +6 -1
  30. package/node_modules/pi-lens/dist/clients/cascade-format.js +200 -4
  31. package/node_modules/pi-lens/dist/clients/code-quality-warnings.js +10 -2
  32. package/node_modules/pi-lens/dist/clients/degradation-ledger.js +16 -1
  33. package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +12 -1
  34. package/node_modules/pi-lens/dist/clients/dispatch/ast-grep-catalog.js +65 -0
  35. package/node_modules/pi-lens/dist/clients/dispatch/auxiliary-lsp.js +28 -0
  36. package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +9 -2
  37. package/node_modules/pi-lens/dist/clients/dispatch/finding-policy.js +222 -0
  38. package/node_modules/pi-lens/dist/clients/dispatch/indent-detect.js +389 -13
  39. package/node_modules/pi-lens/dist/clients/dispatch/integration.js +175 -25
  40. package/node_modules/pi-lens/dist/clients/dispatch/rule-ignores.js +62 -0
  41. package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +21 -41
  42. package/node_modules/pi-lens/dist/clients/dispatch/runners/biome-check.js +6 -1
  43. package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +7 -7
  44. package/node_modules/pi-lens/dist/clients/dispatch/runners/shfmt.js +2 -12
  45. package/node_modules/pi-lens/dist/clients/dispatch/runners/tree-sitter.js +2 -21
  46. package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1 -1
  47. package/node_modules/pi-lens/dist/clients/dispatch/types.js +4 -1
  48. package/node_modules/pi-lens/dist/clients/disposition-publish.js +1 -0
  49. package/node_modules/pi-lens/dist/clients/effective-config.js +1 -1
  50. package/node_modules/pi-lens/dist/clients/file-kinds.js +26 -1
  51. package/node_modules/pi-lens/dist/clients/file-role.js +21 -21
  52. package/node_modules/pi-lens/dist/clients/file-utils.js +156 -10
  53. package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +56 -9
  54. package/node_modules/pi-lens/dist/clients/format-service.js +39 -21
  55. package/node_modules/pi-lens/dist/clients/formatters.js +60 -13
  56. package/node_modules/pi-lens/dist/clients/generation-guard.js +2 -2
  57. package/node_modules/pi-lens/dist/clients/git-guard.js +11 -3
  58. package/node_modules/pi-lens/dist/clients/indent-retarget.js +78 -8
  59. package/node_modules/pi-lens/dist/clients/installer/index.js +333 -114
  60. package/node_modules/pi-lens/dist/clients/instance-reaper-state.js +7 -0
  61. package/node_modules/pi-lens/dist/clients/instance-reaper.js +20 -10
  62. package/node_modules/pi-lens/dist/clients/language-profile.js +23 -1
  63. package/node_modules/pi-lens/dist/clients/language-registry.js +5 -1
  64. package/node_modules/pi-lens/dist/clients/latency-logger.js +4 -1
  65. package/node_modules/pi-lens/dist/clients/lens-engine.js +12 -3
  66. package/node_modules/pi-lens/dist/clients/lens-events.js +2 -1
  67. package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +79 -0
  68. package/node_modules/pi-lens/dist/clients/live-bus-emitter.js +2 -1
  69. package/node_modules/pi-lens/dist/clients/lsp/client.js +25 -21
  70. package/node_modules/pi-lens/dist/clients/lsp/config.js +2 -2
  71. package/node_modules/pi-lens/dist/clients/lsp/index.js +7 -0
  72. package/node_modules/pi-lens/dist/clients/lsp/launch.js +16 -4
  73. package/node_modules/pi-lens/dist/clients/lsp/server.js +19 -2
  74. package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +2 -1
  75. package/node_modules/pi-lens/dist/clients/lsp-mutation.js +5 -3
  76. package/node_modules/pi-lens/dist/clients/map-with-concurrency.js +12 -8
  77. package/node_modules/pi-lens/dist/clients/mcp/session.js +36 -4
  78. package/node_modules/pi-lens/dist/clients/ndjson-logger.js +24 -7
  79. package/node_modules/pi-lens/dist/clients/observed-mutation.js +40 -2
  80. package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +23 -3
  81. package/node_modules/pi-lens/dist/clients/opengrep-client.js +110 -15
  82. package/node_modules/pi-lens/dist/clients/path-utils.js +123 -3
  83. package/node_modules/pi-lens/dist/clients/performance-report.js +5 -1
  84. package/node_modules/pi-lens/dist/clients/php-cs-fixer-config.js +1 -1
  85. package/node_modules/pi-lens/dist/clients/pipeline.js +74 -5
  86. package/node_modules/pi-lens/dist/clients/project-diagnostics/cache.js +37 -5
  87. package/node_modules/pi-lens/dist/clients/project-diagnostics/fresh-fetch.js +145 -18
  88. package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +4 -1
  89. package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +59 -3
  90. package/node_modules/pi-lens/dist/clients/project-lens-config.js +45 -2
  91. package/node_modules/pi-lens/dist/clients/read-guard.js +70 -11
  92. package/node_modules/pi-lens/dist/clients/resource-sampler.js +147 -9
  93. package/node_modules/pi-lens/dist/clients/ruff-client.js +1 -1
  94. package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +33 -5
  95. package/node_modules/pi-lens/dist/clients/runtime-context.js +6 -2
  96. package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +77 -7
  97. package/node_modules/pi-lens/dist/clients/runtime-session.js +21 -2
  98. package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +43 -12
  99. package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +330 -85
  100. package/node_modules/pi-lens/dist/clients/runtime-turn.js +147 -17
  101. package/node_modules/pi-lens/dist/clients/safe-spawn.js +258 -5
  102. package/node_modules/pi-lens/dist/clients/scratch-tree-policy.js +6 -0
  103. package/node_modules/pi-lens/dist/clients/session-event-guard.js +50 -5
  104. package/node_modules/pi-lens/dist/clients/sg-runner.js +23 -11
  105. package/node_modules/pi-lens/dist/clients/sgconfig.js +79 -2
  106. package/node_modules/pi-lens/dist/clients/test-runner-client.js +6 -41
  107. package/node_modules/pi-lens/dist/clients/test-runner-delivery.js +43 -0
  108. package/node_modules/pi-lens/dist/clients/tool-agreement.js +423 -0
  109. package/node_modules/pi-lens/dist/clients/tool-config.js +50 -0
  110. package/node_modules/pi-lens/dist/clients/tool-cwd.js +47 -76
  111. package/node_modules/pi-lens/dist/clients/tool-policy.js +163 -7
  112. package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +120 -0
  113. package/node_modules/pi-lens/dist/clients/tree-sitter-query-loader.js +127 -189
  114. package/node_modules/pi-lens/dist/clients/widget-state.js +98 -0
  115. package/node_modules/pi-lens/dist/clients/word-index.js +5 -2
  116. package/node_modules/pi-lens/dist/clients/write-ordering-guard.js +7 -0
  117. package/node_modules/pi-lens/dist/index.js +27416 -24153
  118. package/node_modules/pi-lens/dist/mcp/server.js +5 -2
  119. package/node_modules/pi-lens/dist/tools/lens-diagnostic-mark.js +7 -1
  120. package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +168 -53
  121. package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +244 -72
  122. package/node_modules/pi-lens/docs/audit1.md +5 -5
  123. package/node_modules/pi-lens/docs/dependencies.md +11 -0
  124. package/node_modules/pi-lens/docs/dispositions.md +52 -0
  125. package/node_modules/pi-lens/docs/environment-variables.md +2 -2
  126. package/node_modules/pi-lens/docs/features.md +4 -4
  127. package/node_modules/pi-lens/docs/globalconfig.md +3 -1
  128. package/node_modules/pi-lens/docs/language-coverage.md +1 -0
  129. package/node_modules/pi-lens/docs/pi-lens-fixer.md +53 -94
  130. package/node_modules/pi-lens/docs/pi-lens-investigator.md +43 -38
  131. package/node_modules/pi-lens/docs/pi-lens-retro.md +97 -0
  132. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +53 -66
  133. package/node_modules/pi-lens/docs/release-qa-baseline.md +22 -0
  134. package/node_modules/pi-lens/docs/settings.md +7 -4
  135. package/node_modules/pi-lens/docs/tree-sitter_rules_catalog.md +1 -1
  136. package/node_modules/pi-lens/docs/usage.md +2 -0
  137. package/node_modules/pi-lens/package.json +1 -1
  138. package/node_modules/pi-lens/rules/tree-sitter-queries/typescript/sql-injection.yml +24 -12
  139. package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +40 -0
  140. package/node_modules/pi-lens/skills/pi-lens-ast-grep/SKILL.md +15 -0
  141. package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +7 -0
  142. package/package.json +6 -17
  143. package/examples/pi-footer.json +0 -275
  144. package/node_modules/@czottmann/pi-automode/CHANGELOG.md +0 -70
  145. package/node_modules/@czottmann/pi-automode/LICENSE.md +0 -21
  146. package/node_modules/@czottmann/pi-automode/README.md +0 -215
  147. package/node_modules/@czottmann/pi-automode/docs/GLOSSARY.md +0 -39
  148. package/node_modules/@czottmann/pi-automode/docs/adr/ADR-001-permission-precedence-and-trust-boundaries.md +0 -46
  149. package/node_modules/@czottmann/pi-automode/docs/adr/ADR-002-global-config-in-extension-data-directory.md +0 -60
  150. package/node_modules/@czottmann/pi-automode/docs/adr/INDEX.md +0 -6
  151. package/node_modules/@czottmann/pi-automode/docs/automode-classifier-flow.md +0 -428
  152. package/node_modules/@czottmann/pi-automode/docs/configuration.md +0 -171
  153. package/node_modules/@czottmann/pi-automode/docs/defaults.md +0 -178
  154. package/node_modules/@czottmann/pi-automode/docs/diagnostics.md +0 -90
  155. package/node_modules/@czottmann/pi-automode/docs/observability-logging.md +0 -160
  156. package/node_modules/@czottmann/pi-automode/examples/automode.local.json +0 -44
  157. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/bash.ts +0 -692
  158. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/classifier.ts +0 -852
  159. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/config.ts +0 -904
  160. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/constants.ts +0 -228
  161. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/extension.ts +0 -954
  162. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/hard-deny.ts +0 -429
  163. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/log.ts +0 -173
  164. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/model-selector.ts +0 -113
  165. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/model.ts +0 -13
  166. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/paths.ts +0 -297
  167. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/permissions.ts +0 -623
  168. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/state.ts +0 -102
  169. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/transcript.ts +0 -236
  170. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/types.ts +0 -205
  171. package/node_modules/@czottmann/pi-automode/extensions/auto-mode/utils.ts +0 -54
  172. package/node_modules/@czottmann/pi-automode/extensions/auto-mode.ts +0 -26
  173. package/node_modules/@czottmann/pi-automode/package.json +0 -61
  174. package/node_modules/@czottmann/pi-automode/skills/automode-diagnostics/SKILL.md +0 -63
  175. package/node_modules/@luxusai/pi-hindsight/CHANGELOG.md +0 -376
  176. package/node_modules/@luxusai/pi-hindsight/README.md +0 -92
  177. package/node_modules/@luxusai/pi-hindsight/docs/adr/001-memory-lifecycle-and-scope.md +0 -56
  178. package/node_modules/@luxusai/pi-hindsight/docs/adr/002-explicit-routing-strategy-seam.md +0 -169
  179. package/node_modules/@luxusai/pi-hindsight/docs/adr/003-tui-memory-mode-vocabulary.md +0 -107
  180. package/node_modules/@luxusai/pi-hindsight/docs/adr/004-lifeos-dual-bank-design.md +0 -89
  181. package/node_modules/@luxusai/pi-hindsight/docs/adr/005-domain-banks-and-agent-first-surface.md +0 -189
  182. package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark.webp +0 -0
  183. package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark@2x.webp +0 -0
  184. package/node_modules/@luxusai/pi-hindsight/docs/coding-memory-evaluation.md +0 -54
  185. package/node_modules/@luxusai/pi-hindsight/docs/compatibility.md +0 -75
  186. package/node_modules/@luxusai/pi-hindsight/docs/hindsight-core-functions.md +0 -300
  187. package/node_modules/@luxusai/pi-hindsight/docs/mission-and-mental-model-quality.md +0 -158
  188. package/node_modules/@luxusai/pi-hindsight/docs/next-opt-out-design.md +0 -164
  189. package/node_modules/@luxusai/pi-hindsight/docs/risky-memory-modes.md +0 -139
  190. package/node_modules/@luxusai/pi-hindsight/docs/starter-mental-model-suggestions.md +0 -74
  191. package/node_modules/@luxusai/pi-hindsight/docs/surface-reference.md +0 -261
  192. package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-operations.ts +0 -151
  193. package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-selection.ts +0 -18
  194. package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-settings-presenter.ts +0 -46
  195. package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-templates.ts +0 -383
  196. package/node_modules/@luxusai/pi-hindsight/extensions/banks/banking.ts +0 -240
  197. package/node_modules/@luxusai/pi-hindsight/extensions/banks/knowledge-page-seed.ts +0 -176
  198. package/node_modules/@luxusai/pi-hindsight/extensions/banks/retain-strategies.ts +0 -178
  199. package/node_modules/@luxusai/pi-hindsight/extensions/client/client-retry.ts +0 -41
  200. package/node_modules/@luxusai/pi-hindsight/extensions/client/client.ts +0 -386
  201. package/node_modules/@luxusai/pi-hindsight/extensions/client/fetch-compat.ts +0 -39
  202. package/node_modules/@luxusai/pi-hindsight/extensions/client/timeout.ts +0 -34
  203. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-defaults.ts +0 -140
  204. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-model.ts +0 -61
  205. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-registry.ts +0 -925
  206. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-field-paths.ts +0 -247
  207. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-normalize.ts +0 -547
  208. package/node_modules/@luxusai/pi-hindsight/extensions/config/config-writer.ts +0 -480
  209. package/node_modules/@luxusai/pi-hindsight/extensions/config/config.ts +0 -182
  210. package/node_modules/@luxusai/pi-hindsight/extensions/config/setup-gate.ts +0 -86
  211. package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-execute.ts +0 -1010
  212. package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-parse.ts +0 -175
  213. package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-plan.ts +0 -425
  214. package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-presentation.ts +0 -210
  215. package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-sessions.ts +0 -817
  216. package/node_modules/@luxusai/pi-hindsight/extensions/index.ts +0 -25
  217. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/git-seed.ts +0 -319
  218. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-recall.ts +0 -196
  219. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-retain.ts +0 -189
  220. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-runtime.ts +0 -65
  221. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle.ts +0 -260
  222. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/mental-models.ts +0 -244
  223. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/observation-scopes.ts +0 -59
  224. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-cleanup.ts +0 -82
  225. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-visibility.ts +0 -45
  226. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall.ts +0 -331
  227. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-cursor.ts +0 -354
  228. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-job-builder.ts +0 -66
  229. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-receipts.ts +0 -132
  230. package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain.ts +0 -228
  231. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-bank-template-operations.ts +0 -74
  232. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-config-operations.ts +0 -16
  233. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-control-operations.ts +0 -648
  234. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-diagnostics-operations.ts +0 -105
  235. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-identity.ts +0 -68
  236. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-service.ts +0 -71
  237. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-types.ts +0 -13
  238. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-recall-operations.ts +0 -162
  239. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-retain-operations.ts +0 -131
  240. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-scope.ts +0 -104
  241. package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-session-operations.ts +0 -37
  242. package/node_modules/@luxusai/pi-hindsight/extensions/operations/operation-catalog.ts +0 -893
  243. package/node_modules/@luxusai/pi-hindsight/extensions/operations/reflect-presenter.ts +0 -35
  244. package/node_modules/@luxusai/pi-hindsight/extensions/operations/scope-migrate.ts +0 -177
  245. package/node_modules/@luxusai/pi-hindsight/extensions/operations/tools.ts +0 -7
  246. package/node_modules/@luxusai/pi-hindsight/extensions/queue/flush-presenter.ts +0 -21
  247. package/node_modules/@luxusai/pi-hindsight/extensions/queue/jsonl-queue-store.ts +0 -112
  248. package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-delivery.ts +0 -111
  249. package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-lock.ts +0 -214
  250. package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-operations.ts +0 -70
  251. package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue.ts +0 -392
  252. package/node_modules/@luxusai/pi-hindsight/extensions/tui/bank-template-presentation.ts +0 -45
  253. package/node_modules/@luxusai/pi-hindsight/extensions/tui/commands.ts +0 -9
  254. package/node_modules/@luxusai/pi-hindsight/extensions/tui/guided-setup.ts +0 -860
  255. package/node_modules/@luxusai/pi-hindsight/extensions/tui/prefill-input.ts +0 -105
  256. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-flow.ts +0 -189
  257. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-server-probe.ts +0 -299
  258. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-actions.ts +0 -201
  259. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-facts.ts +0 -47
  260. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-render.ts +0 -239
  261. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-types.ts +0 -50
  262. package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui.ts +0 -259
  263. package/node_modules/@luxusai/pi-hindsight/extensions/tui/tool-presenters.ts +0 -77
  264. package/node_modules/@luxusai/pi-hindsight/extensions/types.ts +0 -534
  265. package/node_modules/@luxusai/pi-hindsight/extensions/utils/diagnostics.ts +0 -319
  266. package/node_modules/@luxusai/pi-hindsight/extensions/utils/messages.ts +0 -325
  267. package/node_modules/@luxusai/pi-hindsight/extensions/utils/sanitize.ts +0 -42
  268. package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-memory-meta.ts +0 -244
  269. package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-operations.ts +0 -56
  270. package/node_modules/@luxusai/pi-hindsight/extensions/utils/session.ts +0 -50
  271. package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-fields.ts +0 -167
  272. package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-health.ts +0 -207
  273. package/node_modules/@luxusai/pi-hindsight/extensions/utils/status.ts +0 -120
  274. package/node_modules/@luxusai/pi-hindsight/extensions/version.ts +0 -8
  275. package/node_modules/@luxusai/pi-hindsight/package.json +0 -118
  276. package/node_modules/@luxusai/pi-hindsight/skills/hindsight-memory-doctor/SKILL.md +0 -75
@@ -1,509 +1,471 @@
1
- import type {
2
- ExtensionCommandContext,
3
- KeybindingsManager,
4
- Theme,
5
- } from "@earendil-works/pi-coding-agent";
1
+ import type { ExtensionCommandContext, KeybindingsManager, Theme } from "@earendil-works/pi-coding-agent";
6
2
  import type { Component, TUI } from "@earendil-works/pi-tui";
7
3
  import type { MenuContext, RunMenuResult } from "@narumitw/pi-tui-kit";
8
4
  import {
9
- BTW_SHORTCUT_ACTIONS,
10
- type BtwShortcutAction,
11
- normalizeBtwKey,
12
- resolveBtwShortcuts,
13
- validateBtwShortcutEdit,
5
+ BTW_SHORTCUT_ACTIONS,
6
+ type BtwShortcutAction,
7
+ normalizeBtwKey,
8
+ resolveBtwShortcuts,
9
+ validateBtwShortcutEdit,
14
10
  } from "./keybindings.js";
15
11
  import {
16
- type BtwSettings,
17
- type BtwSettingsPatch,
18
- btwSettingsPath,
19
- effectiveFullscreenCopyOnSelect,
20
- effectiveRememberThinkingLevelChanges,
21
- readBtwSettings,
22
- type UpdateBtwSettingsOptions,
23
- updateBtwSettings,
12
+ type BtwSettings,
13
+ type BtwSettingsPatch,
14
+ btwSettingsPath,
15
+ effectiveFullscreenCopyOnSelect,
16
+ effectiveRememberThinkingLevelChanges,
17
+ readBtwSettings,
18
+ type UpdateBtwSettingsOptions,
19
+ updateBtwSettings,
24
20
  } from "./settings.js";
25
21
  import { BTW_THINKING_LEVELS, type BtwThinkingLevel } from "./side-thread.js";
26
22
  import { formatKeyLabel, sanitizeSingleLine } from "./text.js";
27
23
 
28
24
  interface BtwMenuState {
29
- kind: "valid" | "invalid";
30
- settings: BtwSettings;
31
- reason?: string;
25
+ kind: "valid" | "invalid";
26
+ settings: BtwSettings;
27
+ reason?: string;
32
28
  }
33
29
 
34
30
  export interface BtwResumeThreadSummary {
35
- id: string;
36
- title: string;
37
- questionCount: number;
31
+ id: string;
32
+ title: string;
33
+ questionCount: number;
38
34
  }
39
35
 
40
36
  export interface ShowBtwCommandMenuOptions {
41
- currentThinkingLevel: BtwThinkingLevel;
42
- availableThinkingLevels: readonly BtwThinkingLevel[];
43
- resumeThreads?: readonly BtwResumeThreadSummary[];
44
- settingsPath?: string;
45
- readSettings?: typeof readBtwSettings;
46
- updateSettings?: (
47
- patch: BtwSettingsPatch,
48
- options: UpdateBtwSettingsOptions,
49
- ) => Promise<BtwSettings>;
37
+ currentThinkingLevel: BtwThinkingLevel;
38
+ availableThinkingLevels: readonly BtwThinkingLevel[];
39
+ resumeThreads?: readonly BtwResumeThreadSummary[];
40
+ settingsPath?: string;
41
+ readSettings?: typeof readBtwSettings;
42
+ updateSettings?: (patch: BtwSettingsPatch, options: UpdateBtwSettingsOptions) => Promise<BtwSettings>;
50
43
  }
51
44
 
52
- export type BtwCommandMenuResult =
53
- | "start"
54
- | "tree"
55
- | "closed"
56
- | { kind: "resume"; threadId: string };
45
+ export type BtwCommandMenuResult = "start" | "tree" | "closed" | { kind: "resume"; threadId: string };
57
46
 
58
47
  type BtwMenuScreen = "main" | "resume" | "settings" | "invalid" | "shortcut" | "shortcut-input";
59
48
  type BtwMenuAction =
60
- | "start"
61
- | "start-tree"
62
- | "resume"
63
- | "set-thinking"
64
- | "set-remember"
65
- | "set-fullscreen-copy"
66
- | "edit-shortcut"
67
- | "save-shortcut"
68
- | "reset-shortcut";
49
+ | "start"
50
+ | "start-tree"
51
+ | "resume"
52
+ | "set-thinking"
53
+ | "set-remember"
54
+ | "set-fullscreen-copy"
55
+ | "edit-shortcut"
56
+ | "save-shortcut"
57
+ | "reset-shortcut";
69
58
  const SAME_AS_MAIN_THREAD = "Same as main thread";
70
59
  type BtwCustomOptions = Parameters<ExtensionCommandContext["ui"]["custom"]>[1];
71
60
 
72
61
  type BtwCustomFactory<T> = (
73
- tui: TUI,
74
- theme: Theme,
75
- keybindings: KeybindingsManager,
76
- done: (result: T) => void,
62
+ tui: TUI,
63
+ theme: Theme,
64
+ keybindings: KeybindingsManager,
65
+ done: (result: T) => void,
77
66
  ) => Component;
78
67
 
79
68
  export async function showBtwCommandMenu(
80
- ctx: ExtensionCommandContext,
81
- options: ShowBtwCommandMenuOptions,
69
+ ctx: ExtensionCommandContext,
70
+ options: ShowBtwCommandMenuOptions,
82
71
  ): Promise<BtwCommandMenuResult> {
83
- if (ctx.mode !== "tui") return "closed";
84
- const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
85
- if (ctx.signal?.aborted) return "closed";
86
- const settingsPath = options.settingsPath ?? btwSettingsPath();
87
- const readSettings = options.readSettings ?? readBtwSettings;
88
- const updateSettings = options.updateSettings ?? updateBtwSettings;
89
- const levels =
90
- options.availableThinkingLevels.length > 0
91
- ? [...options.availableThinkingLevels]
92
- : (["off"] satisfies BtwThinkingLevel[]);
93
- const displaySettingsPath = sanitizeSingleLine(settingsPath);
94
- const resumeThreads = options.resumeThreads ?? [];
95
- let startSelected = false;
96
- let treeSelected = false;
97
- let resumedThreadId: string | undefined;
98
- let keybindings: KeybindingsManager | undefined;
99
- let shortcut: BtwShortcutAction = "exit";
100
- const shortcutLabels: Record<BtwShortcutAction, string> = {
101
- exit: "Exit shortcut",
102
- cycleThinkingLevel: "Cycle thinking level shortcut",
103
- bringToMain: "Bring to main shortcut",
104
- };
105
- const shortcutValue = (settings: BtwSettings, action: BtwShortcutAction): string => {
106
- if (!keybindings) return "Default";
107
- const effective = resolveBtwShortcuts(
108
- settings.keybindings,
109
- keybindings,
110
- effectiveFullscreenCopyOnSelect(settings),
111
- );
112
- const configured = settings.keybindings?.[action];
113
- if (configured !== undefined && !effective.keys[action].includes(configured)) {
114
- return `Fallback (${effective.label(action)}; saved ${formatKeyLabel(configured)})`;
115
- }
116
- const source =
117
- configured === undefined
118
- ? action === "cycleThinkingLevel"
119
- ? "Inherit Pi"
120
- : "Default"
121
- : "Custom";
122
- return `${source} (${effective.label(action)})`;
123
- };
124
- const saveShortcut = async (
125
- state: BtwMenuState,
126
- value: string | undefined,
127
- signal: AbortSignal,
128
- ) => {
129
- if (!keybindings || state.kind !== "valid" || signal.aborted)
130
- return { kind: "rejected" } as const;
131
- const action = shortcut;
132
- const manager = keybindings;
133
- const validate = (settings: BtwSettings) =>
134
- validateBtwShortcutEdit(
135
- action,
136
- value,
137
- settings.keybindings ?? {},
138
- manager,
139
- effectiveFullscreenCopyOnSelect(settings),
140
- );
141
- const error = validate(state.settings);
142
- if (error) {
143
- notifySafely(ctx, error, "error");
144
- return { kind: "rejected" } as const;
145
- }
146
- try {
147
- await updateSettings(
148
- { keybindings: { [action]: value === undefined ? undefined : normalizeBtwKey(value) } },
149
- {
150
- settingsPath,
151
- signal,
152
- validateCurrent: (settings) => {
153
- const conflict = validate(settings);
154
- if (conflict) throw new Error(conflict);
155
- },
156
- },
157
- );
158
- if (signal.aborted) return { kind: "rejected" } as const;
159
- notifySafely(ctx, "Pi BTW shortcut saved; applies when opening or resuming BTW.", "info");
160
- return { kind: "back" } as const;
161
- } catch (error) {
162
- if (!signal.aborted) notifySaveFailure(ctx, error);
163
- return { kind: "rejected" } as const;
164
- }
165
- };
72
+ if (ctx.mode !== "tui") return "closed";
73
+ const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
74
+ if (ctx.signal?.aborted) return "closed";
75
+ const settingsPath = options.settingsPath ?? btwSettingsPath();
76
+ const readSettings = options.readSettings ?? readBtwSettings;
77
+ const updateSettings = options.updateSettings ?? updateBtwSettings;
78
+ const levels =
79
+ options.availableThinkingLevels.length > 0
80
+ ? [...options.availableThinkingLevels]
81
+ : (["off"] satisfies BtwThinkingLevel[]);
82
+ const displaySettingsPath = sanitizeSingleLine(settingsPath);
83
+ const resumeThreads = options.resumeThreads ?? [];
84
+ let startSelected = false;
85
+ let treeSelected = false;
86
+ let resumedThreadId: string | undefined;
87
+ let keybindings: KeybindingsManager | undefined;
88
+ let shortcut: BtwShortcutAction = "exit";
89
+ const shortcutLabels: Record<BtwShortcutAction, string> = {
90
+ exit: "Exit shortcut",
91
+ cycleThinkingLevel: "Cycle thinking level shortcut",
92
+ bringToMain: "Bring to main shortcut",
93
+ };
94
+ const shortcutValue = (settings: BtwSettings, action: BtwShortcutAction): string => {
95
+ if (!keybindings) return "Default";
96
+ const effective = resolveBtwShortcuts(settings.keybindings, keybindings, effectiveFullscreenCopyOnSelect(settings));
97
+ const configured = settings.keybindings?.[action];
98
+ if (configured !== undefined && !effective.keys[action].includes(configured)) {
99
+ return `Fallback (${effective.label(action)}; saved ${formatKeyLabel(configured)})`;
100
+ }
101
+ const source = configured === undefined ? (action === "cycleThinkingLevel" ? "Inherit Pi" : "Default") : "Custom";
102
+ return `${source} (${effective.label(action)})`;
103
+ };
104
+ const saveShortcut = async (state: BtwMenuState, value: string | undefined, signal: AbortSignal) => {
105
+ if (!keybindings || state.kind !== "valid" || signal.aborted) return { kind: "rejected" } as const;
106
+ const action = shortcut;
107
+ const manager = keybindings;
108
+ const validate = (settings: BtwSettings) =>
109
+ validateBtwShortcutEdit(
110
+ action,
111
+ value,
112
+ settings.keybindings ?? {},
113
+ manager,
114
+ effectiveFullscreenCopyOnSelect(settings),
115
+ );
116
+ const error = validate(state.settings);
117
+ if (error) {
118
+ notifySafely(ctx, error, "error");
119
+ return { kind: "rejected" } as const;
120
+ }
121
+ try {
122
+ await updateSettings(
123
+ { keybindings: { [action]: value === undefined ? undefined : normalizeBtwKey(value) } },
124
+ {
125
+ settingsPath,
126
+ signal,
127
+ validateCurrent: (settings) => {
128
+ const conflict = validate(settings);
129
+ if (conflict) throw new Error(conflict);
130
+ },
131
+ },
132
+ );
133
+ if (signal.aborted) return { kind: "rejected" } as const;
134
+ notifySafely(ctx, "Pi BTW shortcut saved; applies when opening or resuming BTW.", "info");
135
+ return { kind: "back" } as const;
136
+ } catch (error) {
137
+ if (!signal.aborted) notifySaveFailure(ctx, error);
138
+ return { kind: "rejected" } as const;
139
+ }
140
+ };
166
141
 
167
- const loadState = async (): Promise<BtwMenuState> => {
168
- const loaded = await readSettings(settingsPath);
169
- if (loaded.kind === "invalid") {
170
- return { kind: "invalid", settings: {}, reason: loaded.reason };
171
- }
172
- return { kind: "valid", settings: loaded.kind === "loaded" ? loaded.settings : {} };
173
- };
174
- const currentMainThinkingLevel = clampToAvailableThinkingLevel(
175
- options.currentThinkingLevel,
176
- levels,
177
- );
178
- const displayThinkingLevel = (settings: BtwSettings): string =>
179
- settings.thinkingLevel === undefined
180
- ? SAME_AS_MAIN_THREAD
181
- : clampToAvailableThinkingLevel(settings.thinkingLevel, levels);
182
- const displayThinkingSummary = (settings: BtwSettings): string =>
183
- settings.thinkingLevel === undefined
184
- ? `${SAME_AS_MAIN_THREAD} (currently ${currentMainThinkingLevel})`
185
- : displayThinkingLevel(settings);
186
- const displayRememberSummary = (settings: BtwSettings): string => {
187
- const value = effectiveRememberThinkingLevelChanges(settings) ? "On" : "Off";
188
- return settings.thinkingLevel === undefined ? `${value} (fixed levels only)` : value;
189
- };
142
+ const loadState = async (): Promise<BtwMenuState> => {
143
+ const loaded = await readSettings(settingsPath);
144
+ if (loaded.kind === "invalid") {
145
+ return { kind: "invalid", settings: {}, reason: loaded.reason };
146
+ }
147
+ return { kind: "valid", settings: loaded.kind === "loaded" ? loaded.settings : {} };
148
+ };
149
+ const currentMainThinkingLevel = clampToAvailableThinkingLevel(options.currentThinkingLevel, levels);
150
+ const displayThinkingLevel = (settings: BtwSettings): string =>
151
+ settings.thinkingLevel === undefined
152
+ ? SAME_AS_MAIN_THREAD
153
+ : clampToAvailableThinkingLevel(settings.thinkingLevel, levels);
154
+ const displayThinkingSummary = (settings: BtwSettings): string =>
155
+ settings.thinkingLevel === undefined
156
+ ? `${SAME_AS_MAIN_THREAD} (currently ${currentMainThinkingLevel})`
157
+ : displayThinkingLevel(settings);
158
+ const displayRememberSummary = (settings: BtwSettings): string => {
159
+ const value = effectiveRememberThinkingLevelChanges(settings) ? "On" : "Off";
160
+ return settings.thinkingLevel === undefined ? `${value} (fixed levels only)` : value;
161
+ };
190
162
 
191
- const menu = defineMenu<BtwMenuState, BtwMenuScreen, BtwMenuAction, MenuContext>({
192
- start: "main",
193
- screens: {
194
- main: ({ state }) => ({
195
- kind: "actions",
196
- title: "Pi BTW",
197
- lines: [
198
- `Thinking: ${displayThinkingSummary(state.settings)} · Remember changes: ${displayRememberSummary(state.settings)}`,
199
- `Copy on select: ${effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off"}`,
200
- ],
201
- items: [
202
- {
203
- id: "start",
204
- label: "Start side thread",
205
- description: "Open an empty side thread",
206
- action: "start",
207
- },
208
- {
209
- id: "start-tree",
210
- label: "Start from main thread tree…",
211
- description: "Choose context without switching the main branch",
212
- action: "start-tree",
213
- },
214
- ...(resumeThreads.length > 0
215
- ? [
216
- {
217
- id: "resume" as const,
218
- label: "Resume side thread",
219
- description: "Continue an in-memory side thread",
220
- to: "resume" as const,
221
- },
222
- ]
223
- : []),
224
- {
225
- id: "settings",
226
- label: "Settings",
227
- description: "Choose thinking, keybindings, and selection copying",
228
- to: state.kind === "invalid" ? "invalid" : "settings",
229
- },
230
- ],
231
- hint: "close",
232
- }),
233
- resume: () => ({
234
- kind: "choice",
235
- title: "Resume BTW side thread",
236
- enableSearch: true,
237
- items: resumeThreads.map((thread) => ({
238
- id: thread.id,
239
- label: thread.title,
240
- description: `${thread.questionCount} ${thread.questionCount === 1 ? "question" : "questions"}`,
241
- })),
242
- action: "resume",
243
- viewportSize: 10,
244
- hint: "back",
245
- }),
246
- settings: ({ state }) => ({
247
- kind: "settings",
248
- title: "Pi BTW Settings",
249
- lines: [`User settings · ${displaySettingsPath}`],
250
- items: [
251
- {
252
- id: "thinkingLevel",
253
- label: "Thinking level",
254
- description: `Set the starting level for future pi-btw side threads. Currently ${currentMainThinkingLevel}.`,
255
- currentValue: displayThinkingLevel(state.settings),
256
- values: [SAME_AS_MAIN_THREAD, ...levels],
257
- action: "set-thinking",
258
- },
259
- {
260
- id: "rememberThinkingLevelChanges",
261
- label: "Remember thinking level changes",
262
- description: "Save shortcut changes for fixed thinking levels to pi-btw.json.",
263
- currentValue: effectiveRememberThinkingLevelChanges(state.settings) ? "On" : "Off",
264
- values: ["On", "Off"],
265
- action: "set-remember",
266
- },
267
- {
268
- id: "fullscreenCopyOnSelect",
269
- label: "Copy selection automatically",
270
- description:
271
- "Copy mouse selections immediately instead of with the configured copy key.",
272
- currentValue: effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off",
273
- values: ["On", "Off"],
274
- action: "set-fullscreen-copy",
275
- },
276
- ...BTW_SHORTCUT_ACTIONS.map((action) => ({
277
- id: action,
278
- label: shortcutLabels[action],
279
- description:
280
- "Edit a BTW-only key combination or restore its default. Ctrl+C always hard-cancels.",
281
- currentValue: shortcutValue(state.settings, action),
282
- action: "edit-shortcut" as const,
283
- })),
284
- ],
285
- }),
286
- shortcut: ({ state }) => ({
287
- kind: "actions",
288
- title: shortcutLabels[shortcut],
289
- lines: [shortcutValue(state.settings, shortcut), "Ctrl+C always hard-cancels BTW."],
290
- items: [
291
- { id: "edit", label: "Edit key combination…", to: "shortcut-input" },
292
- { id: "reset", label: "Restore default", action: "reset-shortcut" },
293
- ],
294
- hint: "back",
295
- }),
296
- "shortcut-input": () => ({
297
- kind: "input",
298
- title: shortcutLabels[shortcut],
299
- lines: ["Type a key name, not the shortcut itself. For example: ctrl+q or f6."],
300
- placeholder: "Key combination",
301
- action: "save-shortcut",
302
- hint: "back",
303
- }),
304
- invalid: ({ state }) => ({
305
- kind: "detail",
306
- title: "Pi BTW Settings · Read only",
307
- lines: [
308
- `Invalid settings file. Fix ${displaySettingsPath} before saving.`,
309
- sanitizeSingleLine(state.reason ?? "The settings file is invalid."),
310
- ],
311
- hint: "back",
312
- }),
313
- },
314
- actions: {
315
- "edit-shortcut": ({ itemId }) => {
316
- if (!BTW_SHORTCUT_ACTIONS.includes(itemId as BtwShortcutAction))
317
- return { kind: "rejected" };
318
- shortcut = itemId as BtwShortcutAction;
319
- return { kind: "to", screen: "shortcut" };
320
- },
321
- "save-shortcut": ({ state, value, signal }) =>
322
- saveShortcut(state, value?.trim() ?? "", signal),
323
- "reset-shortcut": ({ state, signal }) => saveShortcut(state, undefined, signal),
324
- start: async () => {
325
- startSelected = true;
326
- return { kind: "close" };
327
- },
328
- "start-tree": async () => {
329
- treeSelected = true;
330
- return { kind: "close" };
331
- },
332
- resume: async ({ itemId }: { itemId: string }) => {
333
- if (!resumeThreads.some((thread) => thread.id === itemId)) {
334
- return { kind: "rejected" } as const;
335
- }
336
- resumedThreadId = itemId;
337
- return { kind: "close" } as const;
338
- },
339
- "set-thinking": async ({ value, signal }) => {
340
- if (!value) return { kind: "rejected" };
341
- const patch =
342
- value === SAME_AS_MAIN_THREAD
343
- ? ({ thinkingLevel: undefined } satisfies BtwSettingsPatch)
344
- : levels.includes(value as BtwThinkingLevel)
345
- ? ({ thinkingLevel: value as BtwThinkingLevel } satisfies BtwSettingsPatch)
346
- : undefined;
347
- if (!patch) return { kind: "rejected" };
348
- try {
349
- await updateSettings(patch, { settingsPath, signal });
350
- if (signal.aborted) return { kind: "rejected" };
351
- notifySafely(ctx, `Pi BTW thinking level: ${value}.`, "info");
352
- return { kind: "stay" };
353
- } catch (error) {
354
- if (!signal.aborted) notifySaveFailure(ctx, error);
355
- return { kind: "rejected" };
356
- }
357
- },
358
- "set-remember": async ({ value, signal }) => {
359
- if (value !== "On" && value !== "Off") return { kind: "rejected" };
360
- try {
361
- await updateSettings(
362
- { rememberThinkingLevelChanges: value === "On" },
363
- { settingsPath, signal },
364
- );
365
- if (signal.aborted) return { kind: "rejected" };
366
- notifySafely(ctx, `Remember thinking level changes: ${value}.`, "info");
367
- return { kind: "stay" };
368
- } catch (error) {
369
- if (!signal.aborted) notifySaveFailure(ctx, error);
370
- return { kind: "rejected" };
371
- }
372
- },
373
- "set-fullscreen-copy": async ({ value, signal }) => {
374
- if (value !== "On" && value !== "Off") return { kind: "rejected" };
375
- try {
376
- await updateSettings(
377
- { fullscreenCopyOnSelect: value === "On" },
378
- { settingsPath, signal },
379
- );
380
- if (signal.aborted) return { kind: "rejected" };
381
- notifySafely(ctx, `Copy selection automatically: ${value}.`, "info");
382
- return { kind: "stay" };
383
- } catch (error) {
384
- if (!signal.aborted) notifySaveFailure(ctx, error);
385
- return { kind: "rejected" };
386
- }
387
- },
388
- },
389
- });
163
+ const menu = defineMenu<BtwMenuState, BtwMenuScreen, BtwMenuAction, MenuContext>({
164
+ start: "main",
165
+ screens: {
166
+ main: ({ state }) => ({
167
+ kind: "actions",
168
+ title: "Pi BTW",
169
+ lines: [
170
+ `Thinking: ${displayThinkingSummary(state.settings)} · Remember changes: ${displayRememberSummary(state.settings)}`,
171
+ `Copy on select: ${effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off"}`,
172
+ ],
173
+ items: [
174
+ {
175
+ id: "start",
176
+ label: "Start side thread",
177
+ description: "Open an empty side thread",
178
+ action: "start",
179
+ },
180
+ {
181
+ id: "start-tree",
182
+ label: "Start from main thread tree…",
183
+ description: "Choose context without switching the main branch",
184
+ action: "start-tree",
185
+ },
186
+ ...(resumeThreads.length > 0
187
+ ? [
188
+ {
189
+ id: "resume" as const,
190
+ label: "Resume side thread",
191
+ description: "Continue an in-memory side thread",
192
+ to: "resume" as const,
193
+ },
194
+ ]
195
+ : []),
196
+ {
197
+ id: "settings",
198
+ label: "Settings",
199
+ description: "Choose thinking, keybindings, and selection copying",
200
+ to: state.kind === "invalid" ? "invalid" : "settings",
201
+ },
202
+ ],
203
+ hint: "close",
204
+ }),
205
+ resume: () => ({
206
+ kind: "choice",
207
+ title: "Resume BTW side thread",
208
+ enableSearch: true,
209
+ items: resumeThreads.map((thread) => ({
210
+ id: thread.id,
211
+ label: thread.title,
212
+ description: `${thread.questionCount} ${thread.questionCount === 1 ? "question" : "questions"}`,
213
+ })),
214
+ action: "resume",
215
+ viewportSize: 10,
216
+ hint: "back",
217
+ }),
218
+ settings: ({ state }) => ({
219
+ kind: "settings",
220
+ title: "Pi BTW Settings",
221
+ lines: [`User settings · ${displaySettingsPath}`],
222
+ items: [
223
+ {
224
+ id: "thinkingLevel",
225
+ label: "Thinking level",
226
+ description: `Set the starting level for future pi-btw side threads. Currently ${currentMainThinkingLevel}.`,
227
+ currentValue: displayThinkingLevel(state.settings),
228
+ values: [SAME_AS_MAIN_THREAD, ...levels],
229
+ action: "set-thinking",
230
+ },
231
+ {
232
+ id: "rememberThinkingLevelChanges",
233
+ label: "Remember thinking level changes",
234
+ description: "Save shortcut changes for fixed thinking levels to pi-btw.json.",
235
+ currentValue: effectiveRememberThinkingLevelChanges(state.settings) ? "On" : "Off",
236
+ values: ["On", "Off"],
237
+ action: "set-remember",
238
+ },
239
+ {
240
+ id: "fullscreenCopyOnSelect",
241
+ label: "Copy selection automatically",
242
+ description: "Copy mouse selections immediately instead of with the configured copy key.",
243
+ currentValue: effectiveFullscreenCopyOnSelect(state.settings) ? "On" : "Off",
244
+ values: ["On", "Off"],
245
+ action: "set-fullscreen-copy",
246
+ },
247
+ ...BTW_SHORTCUT_ACTIONS.map((action) => ({
248
+ id: action,
249
+ label: shortcutLabels[action],
250
+ description: "Edit a BTW-only key combination or restore its default. Ctrl+C always hard-cancels.",
251
+ currentValue: shortcutValue(state.settings, action),
252
+ action: "edit-shortcut" as const,
253
+ })),
254
+ ],
255
+ }),
256
+ shortcut: ({ state }) => ({
257
+ kind: "actions",
258
+ title: shortcutLabels[shortcut],
259
+ lines: [shortcutValue(state.settings, shortcut), "Ctrl+C always hard-cancels BTW."],
260
+ items: [
261
+ { id: "edit", label: "Edit key combination…", to: "shortcut-input" },
262
+ { id: "reset", label: "Restore default", action: "reset-shortcut" },
263
+ ],
264
+ hint: "back",
265
+ }),
266
+ "shortcut-input": () => ({
267
+ kind: "input",
268
+ title: shortcutLabels[shortcut],
269
+ lines: ["Type a key name, not the shortcut itself. For example: ctrl+q or f6."],
270
+ placeholder: "Key combination",
271
+ action: "save-shortcut",
272
+ hint: "back",
273
+ }),
274
+ invalid: ({ state }) => ({
275
+ kind: "detail",
276
+ title: "Pi BTW Settings · Read only",
277
+ lines: [
278
+ `Invalid settings file. Fix ${displaySettingsPath} before saving.`,
279
+ sanitizeSingleLine(state.reason ?? "The settings file is invalid."),
280
+ ],
281
+ hint: "back",
282
+ }),
283
+ },
284
+ actions: {
285
+ "edit-shortcut": ({ itemId }) => {
286
+ if (!BTW_SHORTCUT_ACTIONS.includes(itemId as BtwShortcutAction)) return { kind: "rejected" };
287
+ shortcut = itemId as BtwShortcutAction;
288
+ return { kind: "to", screen: "shortcut" };
289
+ },
290
+ "save-shortcut": ({ state, value, signal }) => saveShortcut(state, value?.trim() ?? "", signal),
291
+ "reset-shortcut": ({ state, signal }) => saveShortcut(state, undefined, signal),
292
+ start: async () => {
293
+ startSelected = true;
294
+ return { kind: "close" };
295
+ },
296
+ "start-tree": async () => {
297
+ treeSelected = true;
298
+ return { kind: "close" };
299
+ },
300
+ resume: async ({ itemId }: { itemId: string }) => {
301
+ if (!resumeThreads.some((thread) => thread.id === itemId)) {
302
+ return { kind: "rejected" } as const;
303
+ }
304
+ resumedThreadId = itemId;
305
+ return { kind: "close" } as const;
306
+ },
307
+ "set-thinking": async ({ value, signal }) => {
308
+ if (!value) return { kind: "rejected" };
309
+ const patch =
310
+ value === SAME_AS_MAIN_THREAD
311
+ ? ({ thinkingLevel: undefined } satisfies BtwSettingsPatch)
312
+ : levels.includes(value as BtwThinkingLevel)
313
+ ? ({ thinkingLevel: value as BtwThinkingLevel } satisfies BtwSettingsPatch)
314
+ : undefined;
315
+ if (!patch) return { kind: "rejected" };
316
+ try {
317
+ await updateSettings(patch, { settingsPath, signal });
318
+ if (signal.aborted) return { kind: "rejected" };
319
+ notifySafely(ctx, `Pi BTW thinking level: ${value}.`, "info");
320
+ return { kind: "stay" };
321
+ } catch (error) {
322
+ if (!signal.aborted) notifySaveFailure(ctx, error);
323
+ return { kind: "rejected" };
324
+ }
325
+ },
326
+ "set-remember": async ({ value, signal }) => {
327
+ if (value !== "On" && value !== "Off") return { kind: "rejected" };
328
+ try {
329
+ await updateSettings({ rememberThinkingLevelChanges: value === "On" }, { settingsPath, signal });
330
+ if (signal.aborted) return { kind: "rejected" };
331
+ notifySafely(ctx, `Remember thinking level changes: ${value}.`, "info");
332
+ return { kind: "stay" };
333
+ } catch (error) {
334
+ if (!signal.aborted) notifySaveFailure(ctx, error);
335
+ return { kind: "rejected" };
336
+ }
337
+ },
338
+ "set-fullscreen-copy": async ({ value, signal }) => {
339
+ if (value !== "On" && value !== "Off") return { kind: "rejected" };
340
+ try {
341
+ await updateSettings({ fullscreenCopyOnSelect: value === "On" }, { settingsPath, signal });
342
+ if (signal.aborted) return { kind: "rejected" };
343
+ notifySafely(ctx, `Copy selection automatically: ${value}.`, "info");
344
+ return { kind: "stay" };
345
+ } catch (error) {
346
+ if (!signal.aborted) notifySaveFailure(ctx, error);
347
+ return { kind: "rejected" };
348
+ }
349
+ },
350
+ },
351
+ });
390
352
 
391
- const result = await runBtwMenuPreservingEditor(
392
- ctx,
393
- (menuContext) => runMenu(menuContext, menu, { getState: loadState }),
394
- (manager) => {
395
- keybindings = manager;
396
- },
397
- );
398
- if (result.kind !== "closed" || result.reason !== "close") return "closed";
399
- if (resumedThreadId) return { kind: "resume", threadId: resumedThreadId };
400
- if (treeSelected) return "tree";
401
- return startSelected ? "start" : "closed";
353
+ const result = await runBtwMenuPreservingEditor(
354
+ ctx,
355
+ (menuContext) => runMenu(menuContext, menu, { getState: loadState }),
356
+ (manager) => {
357
+ keybindings = manager;
358
+ },
359
+ );
360
+ if (result.kind !== "closed" || result.reason !== "close") return "closed";
361
+ if (resumedThreadId) return { kind: "resume", threadId: resumedThreadId };
362
+ if (treeSelected) return "tree";
363
+ return startSelected ? "start" : "closed";
402
364
  }
403
365
 
404
366
  export async function showBtwCustomPreservingEditor<T>(
405
- ctx: ExtensionCommandContext,
406
- factory: BtwCustomFactory<T>,
367
+ ctx: ExtensionCommandContext,
368
+ factory: BtwCustomFactory<T>,
407
369
  ): Promise<T | undefined> {
408
- let liveEditorText = ctx.ui.getEditorText();
409
- let completed = false;
410
- const result = await ctx.ui.custom<T>((tui, theme, keybindings, done) =>
411
- factory(tui, theme, keybindings, (value) => {
412
- try {
413
- liveEditorText = ctx.ui.getEditorText();
414
- } catch {
415
- // Keep completion finite if session replacement invalidates the editor context.
416
- }
417
- completed = true;
418
- done(value);
419
- }),
420
- );
421
- if (completed) {
422
- try {
423
- if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
424
- } catch {
425
- // A replaced context owns a different editor and must not receive stale restoration.
426
- }
427
- }
428
- return result;
370
+ let liveEditorText = ctx.ui.getEditorText();
371
+ let completed = false;
372
+ const result = await ctx.ui.custom<T>((tui, theme, keybindings, done) =>
373
+ factory(tui, theme, keybindings, (value) => {
374
+ try {
375
+ liveEditorText = ctx.ui.getEditorText();
376
+ } catch {
377
+ // Keep completion finite if session replacement invalidates the editor context.
378
+ }
379
+ completed = true;
380
+ done(value);
381
+ }),
382
+ );
383
+ if (completed) {
384
+ try {
385
+ if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
386
+ } catch {
387
+ // A replaced context owns a different editor and must not receive stale restoration.
388
+ }
389
+ }
390
+ return result;
429
391
  }
430
392
 
431
393
  export async function runBtwMenuPreservingEditor(
432
- ctx: ExtensionCommandContext,
433
- run: (menuContext: MenuContext) => Promise<RunMenuResult>,
434
- onKeybindings?: (keybindings: KeybindingsManager) => void,
394
+ ctx: ExtensionCommandContext,
395
+ run: (menuContext: MenuContext) => Promise<RunMenuResult>,
396
+ onKeybindings?: (keybindings: KeybindingsManager) => void,
435
397
  ): Promise<RunMenuResult> {
436
- let liveEditorText = ctx.ui.getEditorText();
437
- let completed = false;
438
- const ui = new Proxy(ctx.ui, {
439
- get(target, property) {
440
- if (property === "custom") {
441
- return <Value>(factory: BtwCustomFactory<Value>, customOptions?: BtwCustomOptions) =>
442
- target.custom<Value>((tui, theme, keybindings, done) => {
443
- onKeybindings?.(keybindings);
444
- return factory(tui, theme, keybindings, (value) => {
445
- try {
446
- liveEditorText = target.getEditorText();
447
- } catch {
448
- // Keep completion finite if session replacement invalidates the editor context.
449
- }
450
- completed = true;
451
- done(value);
452
- });
453
- }, customOptions);
454
- }
455
- const value = Reflect.get(target, property, target) as unknown;
456
- return typeof value === "function" ? value.bind(target) : value;
457
- },
458
- });
459
- const result = await run({ mode: ctx.mode, hasUI: ctx.hasUI, ui });
460
- if (result.kind !== "stale" && completed) {
461
- try {
462
- if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
463
- } catch {
464
- // A replaced context owns a different editor and must not receive stale restoration.
465
- }
466
- }
467
- return result;
398
+ let liveEditorText = ctx.ui.getEditorText();
399
+ let completed = false;
400
+ const ui = new Proxy(ctx.ui, {
401
+ get(target, property) {
402
+ if (property === "custom") {
403
+ return <Value>(factory: BtwCustomFactory<Value>, customOptions?: BtwCustomOptions) =>
404
+ target.custom<Value>((tui, theme, keybindings, done) => {
405
+ onKeybindings?.(keybindings);
406
+ return factory(tui, theme, keybindings, (value) => {
407
+ try {
408
+ liveEditorText = target.getEditorText();
409
+ } catch {
410
+ // Keep completion finite if session replacement invalidates the editor context.
411
+ }
412
+ completed = true;
413
+ done(value);
414
+ });
415
+ }, customOptions);
416
+ }
417
+ const value = Reflect.get(target, property, target) as unknown;
418
+ return typeof value === "function" ? value.bind(target) : value;
419
+ },
420
+ });
421
+ const result = await run({ mode: ctx.mode, hasUI: ctx.hasUI, ui });
422
+ if (result.kind !== "stale" && completed) {
423
+ try {
424
+ if (ctx.ui.getEditorText() !== liveEditorText) ctx.ui.setEditorText(liveEditorText);
425
+ } catch {
426
+ // A replaced context owns a different editor and must not receive stale restoration.
427
+ }
428
+ }
429
+ return result;
468
430
  }
469
431
 
470
432
  function clampToAvailableThinkingLevel(
471
- requested: BtwThinkingLevel,
472
- available: readonly BtwThinkingLevel[],
433
+ requested: BtwThinkingLevel,
434
+ available: readonly BtwThinkingLevel[],
473
435
  ): BtwThinkingLevel {
474
- if (available.includes(requested)) return requested;
475
- const requestedIndex = BTW_THINKING_LEVELS.indexOf(requested);
476
- for (let index = requestedIndex; index < BTW_THINKING_LEVELS.length; index += 1) {
477
- const candidate = BTW_THINKING_LEVELS[index];
478
- if (candidate && available.includes(candidate)) return candidate;
479
- }
480
- for (let index = requestedIndex - 1; index >= 0; index -= 1) {
481
- const candidate = BTW_THINKING_LEVELS[index];
482
- if (candidate && available.includes(candidate)) return candidate;
483
- }
484
- return available[0] ?? "off";
436
+ if (available.includes(requested)) return requested;
437
+ const requestedIndex = BTW_THINKING_LEVELS.indexOf(requested);
438
+ for (let index = requestedIndex; index < BTW_THINKING_LEVELS.length; index += 1) {
439
+ const candidate = BTW_THINKING_LEVELS[index];
440
+ if (candidate && available.includes(candidate)) return candidate;
441
+ }
442
+ for (let index = requestedIndex - 1; index >= 0; index -= 1) {
443
+ const candidate = BTW_THINKING_LEVELS[index];
444
+ if (candidate && available.includes(candidate)) return candidate;
445
+ }
446
+ return available[0] ?? "off";
485
447
  }
486
448
 
487
449
  function notifySaveFailure(ctx: ExtensionCommandContext, error: unknown): void {
488
- notifySafely(
489
- ctx,
490
- `Pi BTW settings were not saved; the previous value remains active: ${formatError(error)}`,
491
- "error",
492
- );
450
+ notifySafely(
451
+ ctx,
452
+ `Pi BTW settings were not saved; the previous value remains active: ${formatError(error)}`,
453
+ "error",
454
+ );
493
455
  }
494
456
 
495
457
  function notifySafely(
496
- ctx: ExtensionCommandContext,
497
- message: string,
498
- level: Parameters<ExtensionCommandContext["ui"]["notify"]>[1],
458
+ ctx: ExtensionCommandContext,
459
+ message: string,
460
+ level: Parameters<ExtensionCommandContext["ui"]["notify"]>[1],
499
461
  ): void {
500
- try {
501
- ctx.ui.notify(sanitizeSingleLine(message), level);
502
- } catch {
503
- // A completed save remains valid if its command context was replaced before notification.
504
- }
462
+ try {
463
+ ctx.ui.notify(sanitizeSingleLine(message), level);
464
+ } catch {
465
+ // A completed save remains valid if its command context was replaced before notification.
466
+ }
505
467
  }
506
468
 
507
469
  function formatError(error: unknown): string {
508
- return error instanceof Error ? error.message : String(error);
470
+ return error instanceof Error ? error.message : String(error);
509
471
  }