@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,860 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join } from "node:path";
3
- import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
4
- import { ensureGlobalBank, ensureProjectBank } from "../banks/bank-operations.js";
5
- import {
6
- createMemoryOperations,
7
- type MemoryOperations,
8
- type MemoryOperationsDeps,
9
- } from "../operations/memory-operation-service.js";
10
- import { importDocumentSummary } from "../imports/import-presentation.js";
11
- import type { ImportProgressEvent } from "../imports/import-sessions.js";
12
- import type { MemoryProfile, ProjectConfigPatchInput } from "../config/config-writer.js";
13
- import type { SetupProfileChoice } from "./setup-tui-types.js";
14
- import type { AgentUseProfile, HindsightLikeClient, ResolvedConfig } from "../types.js";
15
- import { defaultTemplateIdFor, expectedStarterMentalModelIds } from "../banks/bank-templates.js";
16
- import { resolveProjectIdentity } from "../banks/banking.js";
17
- import {
18
- renderBankTemplateApplyResult,
19
- renderBankTemplateMentalModelDetails,
20
- } from "./bank-template-presentation.js";
21
- import { inputWithPrefill } from "./prefill-input.js";
22
- import { ensureServerConnectionForSetup } from "./setup-server-probe.js";
23
-
24
- export function hasProjectHindsightConfig(cwd: string): boolean {
25
- return (
26
- existsSync(join(cwd, ".pi", "hindsight.json")) ||
27
- existsSync(join(cwd, ".pi", "hindsight.jsonc"))
28
- );
29
- }
30
-
31
- export function setupProfileChoiceToMemoryProfile(choice: SetupProfileChoice): MemoryProfile {
32
- if (choice === "project-user") return "project+global";
33
- if (choice === "user-only") return "global-only";
34
- if (choice === "isolated-only") return "project-only";
35
- return choice;
36
- }
37
-
38
- /** Guided-setup profile menu (first entry is the recommended default). */
39
- export const GUIDED_SETUP_PROFILE_LABELS = {
40
- coding: "Coding — recommended (shared bank; repos separated by tags)",
41
- codingLife: "Coding + Life (coding bank + personal/life bank)",
42
- isolated: "Isolated project (hard wall bank for this repo only)",
43
- lifeOnly: "Life only (personal bank; no coding bank)",
44
- recallOnly: "Recall only (inject memory; do not auto-save)",
45
- } as const;
46
-
47
- const SETUP_PROFILE_BY_LABEL: Record<string, SetupProfileChoice> = {
48
- [GUIDED_SETUP_PROFILE_LABELS.coding]: "project-only",
49
- [GUIDED_SETUP_PROFILE_LABELS.codingLife]: "project-user",
50
- [GUIDED_SETUP_PROFILE_LABELS.isolated]: "isolated-only",
51
- [GUIDED_SETUP_PROFILE_LABELS.lifeOnly]: "user-only",
52
- [GUIDED_SETUP_PROFILE_LABELS.recallOnly]: "recall-only",
53
- };
54
-
55
- function profileUsesProject(profile: SetupProfileChoice): boolean {
56
- return (
57
- profile === "project-user" ||
58
- profile === "project-only" ||
59
- profile === "isolated-only" ||
60
- profile === "recall-only"
61
- );
62
- }
63
-
64
- function profileUsesUser(profile: SetupProfileChoice): boolean {
65
- return profile === "project-user" || profile === "user-only";
66
- }
67
-
68
- /** Shared coding bank (domain-tagged) — not isolated hard-wall. */
69
- function usesSharedCodingBank(profile: SetupProfileChoice): boolean {
70
- return profileUsesProject(profile) && profile !== "isolated-only";
71
- }
72
-
73
- export function buildGuidedSetupPatch(args: {
74
- profile: SetupProfileChoice;
75
- projectBankId?: string;
76
- globalBankId?: string;
77
- config: ResolvedConfig;
78
- }): ProjectConfigPatchInput {
79
- const memoryProfile = setupProfileChoiceToMemoryProfile(args.profile);
80
- // Isolated bank is per-repo; shared coding bank is written to global config.
81
- const isolatedBankId =
82
- args.profile === "isolated-only" && args.projectBankId?.trim()
83
- ? args.projectBankId.trim()
84
- : undefined;
85
- return {
86
- memoryProfile,
87
- setupComplete: true,
88
- // Domain-tagged shares one coding bank + project tags; isolated keeps a hard wall.
89
- scopeMode: args.profile === "isolated-only" ? "isolated-bank" : "domain-tagged",
90
- ...(isolatedBankId ? { projectBankId: isolatedBankId } : {}),
91
- ...(profileUsesUser(args.profile) ? { resetDefaults: ["banks.global.bankId" as const] } : {}),
92
- };
93
- }
94
-
95
- export function buildGuidedSetupGlobalPatch(args: {
96
- profile: SetupProfileChoice;
97
- globalBankId?: string;
98
- projectBankId?: string;
99
- config: ResolvedConfig;
100
- }): ProjectConfigPatchInput | undefined {
101
- const wantsUser = profileUsesUser(args.profile);
102
- const sharedCodingBankId =
103
- usesSharedCodingBank(args.profile) && args.projectBankId?.trim()
104
- ? args.projectBankId.trim()
105
- : undefined;
106
- if (!wantsUser && !sharedCodingBankId) return undefined;
107
- const globalBankId = args.globalBankId?.trim() || args.config.banks.user.bankId;
108
- return {
109
- scope: "global",
110
- ...(wantsUser ? { enableGlobalBank: true } : {}),
111
- ...(wantsUser && globalBankId ? { globalBankId } : {}),
112
- ...(sharedCodingBankId ? { projectBankId: sharedCodingBankId } : {}),
113
- };
114
- }
115
-
116
- /**
117
- * Durable per-repo opt-out: automatic memory stays off, setup gate is satisfied
118
- * so `/hindsight` stops re-prompting, status bar is cleared (style off), and tools
119
- * refuse execution until re-enabled. Hub commands remain available to re-enable.
120
- */
121
- export function buildIgnoreRepoPatch(): ProjectConfigPatchInput {
122
- return { enabled: false, setupComplete: true, statusStyle: "off" };
123
- }
124
-
125
- async function askBankId(args: {
126
- ctx: ExtensionCommandContext;
127
- title: string;
128
- fallback: string;
129
- }): Promise<string | undefined> {
130
- const value = await inputWithPrefill(args.ctx.ui, args.title, args.fallback);
131
- if (value === undefined) return undefined;
132
- return value.trim() || args.fallback;
133
- }
134
-
135
- export type BankExistence =
136
- | { status: "exists" }
137
- | { status: "missing" }
138
- | { status: "unknown"; error?: string };
139
-
140
- /** Check whether a bank ID already exists in Hindsight (typo protection for setup). */
141
- export async function probeBankExistence(
142
- client: HindsightLikeClient,
143
- bankId: string,
144
- ): Promise<BankExistence> {
145
- const id = bankId.trim();
146
- if (!id) return { status: "unknown", error: "missing bank id" };
147
- if (!client.getBankProfile) {
148
- return { status: "unknown", error: "getBankProfile unavailable" };
149
- }
150
- try {
151
- await client.getBankProfile(id);
152
- return { status: "exists" };
153
- } catch (error) {
154
- if (isNotFoundError(error)) return { status: "missing" };
155
- return {
156
- status: "unknown",
157
- error: error instanceof Error ? error.message : String(error),
158
- };
159
- }
160
- }
161
-
162
- export type SetupBankResolveState = "existing" | "created" | "unverified";
163
-
164
- export type ResolvedSetupBank = {
165
- bankId: string;
166
- state: SetupBankResolveState;
167
- };
168
-
169
- /** One-line status after server + bank resolution. */
170
- export function formatSetupBankStatusLine(args: {
171
- serverReachable: boolean;
172
- banks: Array<{ kind: "project" | "user"; bankId: string; state: SetupBankResolveState }>;
173
- }): string {
174
- const server = args.serverReachable ? "Server: reachable" : "Server: offline";
175
- if (args.banks.length === 0) return server;
176
- const bankParts = args.banks.map((bank) => `${bank.kind} bank ${bank.bankId}: ${bank.state}`);
177
- return `${server} · ${bankParts.join(" · ")}`;
178
- }
179
-
180
- /**
181
- * Collect a bank ID, verify it against Hindsight, and confirm create when missing
182
- * so typos do not silently mint a new bank.
183
- * Returns undefined when the user cancels input.
184
- * When offline, skips network probe/create and accepts the ID as unverified.
185
- */
186
- export async function resolveSetupBankId(args: {
187
- ctx: ExtensionCommandContext;
188
- client: HindsightLikeClient;
189
- config: ResolvedConfig;
190
- kind: "project" | "user";
191
- title: string;
192
- fallback: string;
193
- offline?: boolean;
194
- }): Promise<ResolvedSetupBank | undefined> {
195
- while (true) {
196
- const bankId = await askBankId({
197
- ctx: args.ctx,
198
- title: args.title,
199
- fallback: args.fallback,
200
- });
201
- if (bankId === undefined) return undefined;
202
- const trimmed = bankId.trim();
203
- if (!trimmed) {
204
- // Empty IDs are never valid config values (askBankId already falls back when possible).
205
- args.ctx.ui.notify(
206
- args.kind === "user"
207
- ? "User bank ID is required."
208
- : "Project bank ID is required (cannot be empty).",
209
- "warning",
210
- );
211
- continue;
212
- }
213
-
214
- if (args.offline) {
215
- args.ctx.ui.notify(
216
- `Offline: accepting ${args.kind} bank ${trimmed} without server verification.`,
217
- "info",
218
- );
219
- return { bankId: trimmed, state: "unverified" };
220
- }
221
-
222
- const existence = await probeBankExistence(args.client, trimmed);
223
- if (existence.status === "exists") {
224
- args.ctx.ui.notify(`Using existing ${args.kind} bank ${trimmed}.`, "info");
225
- return { bankId: trimmed, state: "existing" };
226
- }
227
-
228
- if (existence.status === "missing") {
229
- const create = await args.ctx.ui.confirm(
230
- `Create ${args.kind} bank "${trimmed}"?`,
231
- `No bank with this ID was found in Hindsight. Confirm create, or cancel to re-enter the ID (typo protection).`,
232
- );
233
- if (!create) {
234
- args.ctx.ui.notify("Bank ID not created. Re-enter the correct bank ID.", "info");
235
- continue;
236
- }
237
- if (!args.client.createBank) {
238
- args.ctx.ui.notify(
239
- "Hindsight client cannot create banks. Re-enter an existing bank ID or fix client support.",
240
- "error",
241
- );
242
- continue;
243
- }
244
- try {
245
- if (args.kind === "project") {
246
- await ensureProjectBank(args.client, trimmed, {
247
- ...args.config.banks.project,
248
- enableObservations: args.config.observations.enabled,
249
- });
250
- } else {
251
- await ensureGlobalBank(args.client, trimmed, {
252
- ...args.config.banks.user,
253
- enableObservations: args.config.observations.enabled,
254
- agentUse: args.config.agentUse,
255
- });
256
- }
257
- args.ctx.ui.notify(`Created ${args.kind} bank ${trimmed}.`, "info");
258
- return { bankId: trimmed, state: "created" };
259
- } catch (error) {
260
- args.ctx.ui.notify(
261
- `Failed to create ${args.kind} bank ${trimmed}: ${error instanceof Error ? error.message : String(error)}`,
262
- "error",
263
- );
264
- continue;
265
- }
266
- }
267
-
268
- // Profile API missing: cannot verify; keep prior behavior.
269
- if (existence.error === "getBankProfile unavailable") {
270
- return { bankId: trimmed, state: "unverified" };
271
- }
272
-
273
- const proceed = await args.ctx.ui.confirm(
274
- `Could not verify ${args.kind} bank "${trimmed}"`,
275
- `${existence.error ?? "Unknown error"}. Continue with this ID anyway, or cancel to re-enter?`,
276
- );
277
- if (proceed) return { bankId: trimmed, state: "unverified" };
278
- }
279
- }
280
-
281
- export function importChoicesForSetup(args: {
282
- setupProfile: SetupProfileChoice;
283
- projectBankId?: string;
284
- globalBankId?: string;
285
- }): string[] {
286
- const choices = ["Skip import"];
287
- if (profileUsesProject(args.setupProfile) && args.projectBankId) {
288
- choices.push("Preview repo Pi sessions");
289
- }
290
- if (profileUsesUser(args.setupProfile) && args.globalBankId) {
291
- choices.push("Preview chat transcript");
292
- }
293
- return choices;
294
- }
295
-
296
- const DOCS_BASE_URL = "https://luxus.github.io/pi-hindsight";
297
-
298
- function setupDocsHint(topic: string, path: string): string {
299
- return `${topic} docs: ${DOCS_BASE_URL}${path}`;
300
- }
301
-
302
- function setupImportProgressMessage(event: ImportProgressEvent): string {
303
- return `Hindsight import progress: ${event.message}`;
304
- }
305
-
306
- function isNotFoundError(error: unknown): boolean {
307
- if (typeof error !== "object" || !error) return false;
308
- const fields = error as {
309
- status?: unknown;
310
- statusCode?: unknown;
311
- code?: unknown;
312
- message?: unknown;
313
- };
314
- return (
315
- fields.status === 404 ||
316
- fields.statusCode === 404 ||
317
- fields.code === 404 ||
318
- fields.code === "404" ||
319
- (typeof fields.message === "string" && /\b404\b|not found/i.test(fields.message))
320
- );
321
- }
322
-
323
- /** Setup-time snapshot of a bank's mental-model catalog from the API. */
324
- export interface SetupBankMentalModelProbe {
325
- target: "project" | "user";
326
- bankId: string;
327
- /** False when getBankProfile reports not found (or no profile API). */
328
- bankExists: boolean;
329
- modelNames: string[];
330
- /** Present mental-model ids from listMentalModels (preferred for ensure checks). */
331
- modelIds: string[];
332
- /** Expected starter ids for this setup target (resolved template + projectId). */
333
- expectedModelIds?: string[];
334
- /** Subset of expectedModelIds not present on the bank. */
335
- missingModelIds?: string[];
336
- error?: string;
337
- }
338
-
339
- function mentalModelListRows(response: unknown): Array<Record<string, unknown>> {
340
- if (!response || typeof response !== "object") return [];
341
- const body = response as { items?: unknown; mental_models?: unknown };
342
- const rows = Array.isArray(body.items)
343
- ? body.items
344
- : Array.isArray(body.mental_models)
345
- ? body.mental_models
346
- : [];
347
- return rows.filter((entry): entry is Record<string, unknown> =>
348
- Boolean(entry && typeof entry === "object"),
349
- );
350
- }
351
-
352
- /** Extract mental-model names from a listMentalModels response body. */
353
- export function extractMentalModelNames(response: unknown): string[] {
354
- const names: string[] = [];
355
- for (const row of mentalModelListRows(response)) {
356
- if (typeof row.name === "string" && row.name.trim()) names.push(row.name.trim());
357
- else if (typeof row.id === "string" && row.id.trim()) names.push(row.id.trim());
358
- }
359
- return names;
360
- }
361
-
362
- /** Extract mental-model ids from a listMentalModels response body. */
363
- function extractMentalModelIds(response: unknown): string[] {
364
- const ids: string[] = [];
365
- for (const row of mentalModelListRows(response)) {
366
- if (typeof row.id === "string" && row.id.trim()) ids.push(row.id.trim());
367
- }
368
- return ids;
369
- }
370
-
371
- /**
372
- * Decide which setup targets should be offered starter mental models.
373
- * When expectedModelIds is set, skip only if every expected id is already present
374
- * (domain-tagged multi-project: other projects' models must not skip this project).
375
- * Without expected ids, fall back to empty-catalog offer.
376
- * Probe failures are not auto-offered (hub remains the intentional path).
377
- */
378
- export function selectMentalModelTargetsToOffer(probes: SetupBankMentalModelProbe[]): {
379
- toOffer: SetupBankMentalModelProbe[];
380
- alreadyProvisioned: SetupBankMentalModelProbe[];
381
- unknown: SetupBankMentalModelProbe[];
382
- } {
383
- const toOffer: SetupBankMentalModelProbe[] = [];
384
- const alreadyProvisioned: SetupBankMentalModelProbe[] = [];
385
- const unknown: SetupBankMentalModelProbe[] = [];
386
- for (const probe of probes) {
387
- if (probe.error) {
388
- unknown.push(probe);
389
- continue;
390
- }
391
- const expected = probe.expectedModelIds ?? [];
392
- if (expected.length > 0) {
393
- const have = new Set(probe.modelIds);
394
- const missing = expected.filter((id) => !have.has(id));
395
- const next = { ...probe, missingModelIds: missing };
396
- if (missing.length === 0) alreadyProvisioned.push(next);
397
- else toOffer.push(next);
398
- continue;
399
- }
400
- if (probe.bankExists && (probe.modelIds.length > 0 || probe.modelNames.length > 0)) {
401
- alreadyProvisioned.push(probe);
402
- continue;
403
- }
404
- // New bank or existing empty catalog → offer starter provision.
405
- toOffer.push(probe);
406
- }
407
- return { toOffer, alreadyProvisioned, unknown };
408
- }
409
-
410
- export async function probeBankMentalModels(args: {
411
- client: HindsightLikeClient;
412
- target: "project" | "user";
413
- bankId: string;
414
- }): Promise<SetupBankMentalModelProbe> {
415
- const bankId = args.bankId.trim();
416
- if (!bankId) {
417
- return {
418
- target: args.target,
419
- bankId: "",
420
- bankExists: false,
421
- modelNames: [],
422
- modelIds: [],
423
- error: "missing bank id",
424
- };
425
- }
426
-
427
- let bankExists = false;
428
- if (args.client.getBankProfile) {
429
- try {
430
- await args.client.getBankProfile(bankId);
431
- bankExists = true;
432
- } catch (error) {
433
- if (isNotFoundError(error)) {
434
- return { target: args.target, bankId, bankExists: false, modelNames: [], modelIds: [] };
435
- }
436
- return {
437
- target: args.target,
438
- bankId,
439
- bankExists: false,
440
- modelNames: [],
441
- modelIds: [],
442
- error: error instanceof Error ? error.message : String(error),
443
- };
444
- }
445
- } else {
446
- // Without profile API, assume the bank may exist and still list models.
447
- bankExists = true;
448
- }
449
-
450
- if (!args.client.listMentalModels) {
451
- return {
452
- target: args.target,
453
- bankId,
454
- bankExists,
455
- modelNames: [],
456
- modelIds: [],
457
- ...(bankExists ? { error: "listMentalModels unavailable" } : {}),
458
- };
459
- }
460
-
461
- try {
462
- const response = await args.client.listMentalModels(bankId);
463
- return {
464
- target: args.target,
465
- bankId,
466
- bankExists,
467
- modelNames: extractMentalModelNames(response),
468
- modelIds: extractMentalModelIds(response),
469
- };
470
- } catch (error) {
471
- if (isNotFoundError(error)) {
472
- return { target: args.target, bankId, bankExists: false, modelNames: [], modelIds: [] };
473
- }
474
- return {
475
- target: args.target,
476
- bankId,
477
- bankExists,
478
- modelNames: [],
479
- modelIds: [],
480
- error: error instanceof Error ? error.message : String(error),
481
- };
482
- }
483
- }
484
-
485
- function formatExistingMentalModelsSummary(probe: SetupBankMentalModelProbe): string {
486
- const expected = probe.expectedModelIds?.length ?? 0;
487
- if (expected > 0) {
488
- return `${probe.target} bank ${probe.bankId}: all ${expected} starter mental model(s) already present. Skipping starter provision; use hub (t) to re-apply intentionally.`;
489
- }
490
- const preview = probe.modelNames.slice(0, 6).join(", ");
491
- const more = probe.modelNames.length > 6 ? ` (+${probe.modelNames.length - 6} more)` : "";
492
- return `${probe.target} bank ${probe.bankId}: ${probe.modelNames.length} mental model(s) already present (${preview}${more}). Skipping starter provision; use hub (t) to re-apply intentionally.`;
493
- }
494
-
495
- function formatOfferTargetSummary(probe: SetupBankMentalModelProbe): string {
496
- const expected = probe.expectedModelIds?.length ?? 0;
497
- const missing = probe.missingModelIds?.length ?? 0;
498
- if (expected > 0) {
499
- const present = expected - missing;
500
- return `${probe.target}=${probe.bankId} (${present}/${expected} starters present; missing ${missing})`;
501
- }
502
- return probe.bankExists
503
- ? `${probe.target}=${probe.bankId} (exists, empty catalog)`
504
- : `${probe.target}=${probe.bankId} (new or missing)`;
505
- }
506
-
507
- async function maybeOfferMentalModelsForSetup(args: {
508
- ctx: ExtensionCommandContext;
509
- operations: MemoryOperations;
510
- client: HindsightLikeClient;
511
- agentUse: AgentUseProfile;
512
- setupProfile: SetupProfileChoice;
513
- projectBankId?: string;
514
- globalBankId?: string;
515
- cwd?: string;
516
- config?: ResolvedConfig;
517
- }): Promise<void> {
518
- const targets: Array<{ target: "project" | "user"; bankId: string }> = [];
519
- if (profileUsesProject(args.setupProfile) && args.projectBankId?.trim()) {
520
- targets.push({ target: "project", bankId: args.projectBankId.trim() });
521
- }
522
- if (profileUsesUser(args.setupProfile) && args.globalBankId?.trim()) {
523
- targets.push({ target: "user", bankId: args.globalBankId.trim() });
524
- }
525
- if (targets.length === 0) return;
526
-
527
- const cwd = args.cwd ?? process.cwd();
528
- const projectId = args.config ? resolveProjectIdentity(cwd, args.config).projectId : undefined;
529
-
530
- const probes: SetupBankMentalModelProbe[] = [];
531
- for (const entry of targets) {
532
- const probe = await probeBankMentalModels({
533
- client: args.client,
534
- target: entry.target,
535
- bankId: entry.bankId,
536
- });
537
- const expectedModelIds = expectedStarterMentalModelIds({
538
- target: entry.target,
539
- agentUse: args.agentUse,
540
- ...(entry.target === "project" && projectId ? { projectId } : {}),
541
- ...(args.config
542
- ? {
543
- bankMissionSettings:
544
- entry.target === "user" ? args.config.banks.user : args.config.banks.project,
545
- }
546
- : {}),
547
- });
548
- probes.push({
549
- ...probe,
550
- ...(expectedModelIds.length > 0 ? { expectedModelIds } : {}),
551
- });
552
- }
553
-
554
- const { toOffer, alreadyProvisioned, unknown } = selectMentalModelTargetsToOffer(probes);
555
-
556
- for (const probe of alreadyProvisioned) {
557
- args.ctx.ui.notify(formatExistingMentalModelsSummary(probe), "info");
558
- }
559
- for (const probe of unknown) {
560
- args.ctx.ui.notify(
561
- `Could not inspect ${probe.target} bank ${probe.bankId || "(missing id)"} for mental models: ${probe.error}. Skipping automatic starter provision; use hub (t) if needed.`,
562
- "warning",
563
- );
564
- }
565
-
566
- if (toOffer.length === 0) return;
567
-
568
- const bankSummary = toOffer.map(formatOfferTargetSummary).join("; ");
569
- const proceed = await args.ctx.ui.confirm(
570
- "Provision starter mental models?",
571
- `Agent use: ${args.agentUse}. Targets: ${bankSummary}. Ensures bank-global + this project's starters when missing. Dry-run preview first; nothing is written without confirmation. Mental models become part of automatic context when present.`,
572
- );
573
- if (!proceed) return;
574
-
575
- for (const probe of toOffer) {
576
- const templateId = defaultTemplateIdFor(probe.target, args.agentUse);
577
- try {
578
- const dryRun = await args.operations.applyBankTemplate({ templateId, dryRun: true });
579
- const details = renderBankTemplateMentalModelDetails(dryRun.template);
580
- const confirmed = await args.ctx.ui.confirm(
581
- `Apply ${templateId} to ${dryRun.bankId}?`,
582
- `${details ? `${details}\n\n` : ""}${renderBankTemplateApplyResult(dryRun)}`,
583
- );
584
- if (!confirmed) continue;
585
- const applied = await args.operations.applyBankTemplate({ templateId, dryRun: false });
586
- args.ctx.ui.notify(renderBankTemplateApplyResult(applied), "info");
587
- } catch (error) {
588
- args.ctx.ui.notify(
589
- `Mental model template ${templateId} skipped: ${error instanceof Error ? error.message : String(error)}`,
590
- "warning",
591
- );
592
- }
593
- }
594
- }
595
-
596
- function setupImportProgressReporter(ctx: ExtensionCommandContext) {
597
- return (event: ImportProgressEvent) => ctx.ui.notify(setupImportProgressMessage(event), "info");
598
- }
599
-
600
- export async function maybeOfferHistoricalImportForSetup(args: {
601
- ctx: ExtensionCommandContext;
602
- operations: MemoryOperations;
603
- setupProfile: SetupProfileChoice;
604
- cwd: string;
605
- projectBankId?: string;
606
- globalBankId?: string;
607
- }): Promise<void> {
608
- const proceed = await args.ctx.ui.confirm(
609
- "Preview historical import now?",
610
- "Imports always dry-run first. Project profiles use repo Pi sessions; user profiles can import chat transcripts.",
611
- );
612
- if (!proceed) return;
613
- args.ctx.ui.notify(setupDocsHint("Import", "/guides/importing-sessions/"), "info");
614
- const choice = await args.ctx.ui.select(
615
- "Choose import source",
616
- importChoicesForSetup({
617
- setupProfile: args.setupProfile,
618
- ...(args.projectBankId ? { projectBankId: args.projectBankId } : {}),
619
- ...(args.globalBankId ? { globalBankId: args.globalBankId } : {}),
620
- }),
621
- );
622
- if (!choice || choice === "Skip import") return;
623
-
624
- if (choice === "Preview repo Pi sessions") {
625
- const currentSessionFile = args.ctx.sessionManager?.getSessionFile?.();
626
- const onProgress = setupImportProgressReporter(args.ctx);
627
- args.ctx.ui.notify("Preparing repo Pi session import preview...", "info");
628
- const dryRun = await args.operations.importProjectSessions({
629
- cwd: args.cwd,
630
- ...(currentSessionFile ? { currentSessionFile } : {}),
631
- ...(args.projectBankId ? { bank: args.projectBankId } : {}),
632
- dryRun: true,
633
- onProgress,
634
- });
635
- const summary = importDocumentSummary({
636
- documents: dryRun.imported.flatMap((result) => result.documents),
637
- malformedLineCount: dryRun.malformedLineCount,
638
- });
639
- const confirmed = await args.ctx.ui.confirm(
640
- `Import repo Pi sessions into ${dryRun.bankId}?`,
641
- `Dry run: sessions=${dryRun.sessionFiles.length}; documents=${dryRun.documentCount}; messages=${dryRun.messageCount}; ${summary}`,
642
- );
643
- if (!confirmed) return;
644
- args.ctx.ui.notify("Starting repo Pi session import write...", "info");
645
- const result = await args.operations.importProjectSessions({
646
- cwd: args.cwd,
647
- ...(currentSessionFile ? { currentSessionFile } : {}),
648
- ...(args.projectBankId ? { bank: args.projectBankId } : {}),
649
- dryRun: false,
650
- onProgress,
651
- });
652
- args.ctx.ui.notify(
653
- `Imported repo Pi sessions into ${result.bankId}: sessions=${result.sessionFiles.length}; documents=${result.documentCount}; messages=${result.messageCount}`,
654
- "info",
655
- );
656
- return;
657
- }
658
-
659
- const sourceFile = await args.ctx.ui.input("Chat transcript JSONL path", "");
660
- if (!sourceFile?.trim()) return;
661
- const onProgress = setupImportProgressReporter(args.ctx);
662
- args.ctx.ui.notify("Preparing chat transcript import preview...", "info");
663
- const dryRun = await args.operations.importChatTranscript({
664
- sourceFile: sourceFile.trim(),
665
- cwd: args.cwd,
666
- ...(args.globalBankId ? { bank: args.globalBankId } : {}),
667
- dryRun: true,
668
- onProgress,
669
- });
670
- const confirmed = await args.ctx.ui.confirm(
671
- `Import chat transcript into ${dryRun.bankId}?`,
672
- `Dry run: kept=${dryRun.keptEventCount}; turns=${dryRun.retainedTurnCount}; dropped=${dryRun.droppedEventCount}; malformed=${dryRun.malformedLineCount}; document=${dryRun.documentId}`,
673
- );
674
- if (!confirmed) return;
675
- args.ctx.ui.notify("Starting chat transcript import write...", "info");
676
- const result = await args.operations.importChatTranscript({
677
- sourceFile: sourceFile.trim(),
678
- cwd: args.cwd,
679
- ...(args.globalBankId ? { bank: args.globalBankId } : {}),
680
- dryRun: false,
681
- onProgress,
682
- });
683
- args.ctx.ui.notify(
684
- result.skipped
685
- ? `Chat transcript import skipped: ${result.skipReason}`
686
- : `Imported chat transcript into ${result.bankId} as ${result.documentId}`,
687
- "info",
688
- );
689
- }
690
-
691
- export async function runGuidedSetup(args: {
692
- ctx: ExtensionCommandContext;
693
- deps: MemoryOperationsDeps;
694
- cwd: string;
695
- }): Promise<boolean> {
696
- args.ctx.ui.notify(setupDocsHint("Guided setup", "/start/setup-tui/"), "info");
697
- args.ctx.ui.notify(setupDocsHint("Memory profiles", "/start/memory-profiles/"), "info");
698
-
699
- // Health-check Hindsight before profile/banks so missing server/key fails early.
700
- const connection = await ensureServerConnectionForSetup({
701
- ctx: args.ctx,
702
- deps: args.deps,
703
- cwd: args.cwd,
704
- });
705
- if (!connection.continue) return false;
706
- const offline = connection.offline;
707
-
708
- const profile = await args.ctx.ui.select("Choose memory profile", [
709
- GUIDED_SETUP_PROFILE_LABELS.coding,
710
- GUIDED_SETUP_PROFILE_LABELS.codingLife,
711
- GUIDED_SETUP_PROFILE_LABELS.isolated,
712
- GUIDED_SETUP_PROFILE_LABELS.lifeOnly,
713
- GUIDED_SETUP_PROFILE_LABELS.recallOnly,
714
- ]);
715
- if (!profile) return false;
716
-
717
- const setupProfile = SETUP_PROFILE_BY_LABEL[profile];
718
- if (!setupProfile) return false;
719
-
720
- const agentUseLabel = await args.ctx.ui.select("How do you use this Pi agent?", [
721
- "Coding (architecture, conventions, decisions)",
722
- "Conversation / real-life tasks (goals, people, commitments)",
723
- ]);
724
- if (!agentUseLabel) return false;
725
- const agentUse = agentUseLabel.startsWith("Conversation")
726
- ? ("conversation" as const)
727
- : ("coding" as const);
728
-
729
- const config = args.deps.getConfig();
730
- const client = args.deps.getClient();
731
- const resolvedBanks: Array<{
732
- kind: "project" | "user";
733
- bankId: string;
734
- state: SetupBankResolveState;
735
- }> = [];
736
-
737
- const projectBank = profileUsesProject(setupProfile)
738
- ? await resolveSetupBankId({
739
- ctx: args.ctx,
740
- client,
741
- config,
742
- kind: "project",
743
- title:
744
- setupProfile === "isolated-only"
745
- ? "Isolated project bank ID (optional; leave default for path-derived)"
746
- : "Coding bank ID (recommended shared bank; saved globally for new repos)",
747
- fallback:
748
- config.banks.project.bankId ??
749
- (setupProfile === "isolated-only" ? args.deps.getProjectBankId() : "pi-coding"),
750
- offline,
751
- })
752
- : undefined;
753
- if (profileUsesProject(setupProfile) && projectBank === undefined) return false;
754
- if (projectBank?.bankId) {
755
- resolvedBanks.push({ kind: "project", bankId: projectBank.bankId, state: projectBank.state });
756
- }
757
-
758
- const globalBank = profileUsesUser(setupProfile)
759
- ? await resolveSetupBankId({
760
- ctx: args.ctx,
761
- client,
762
- config,
763
- kind: "user",
764
- title: "User bank ID",
765
- fallback: config.banks.user.bankId ?? "",
766
- offline,
767
- })
768
- : undefined;
769
- if (profileUsesUser(setupProfile) && !globalBank) {
770
- args.ctx.ui.notify("User bank ID required for user memory profiles.", "warning");
771
- return false;
772
- }
773
- if (globalBank?.bankId) {
774
- resolvedBanks.push({ kind: "user", bankId: globalBank.bankId, state: globalBank.state });
775
- }
776
-
777
- args.ctx.ui.notify(
778
- formatSetupBankStatusLine({
779
- serverReachable: connection.serverReachable,
780
- banks: resolvedBanks,
781
- }),
782
- "info",
783
- );
784
-
785
- const projectBankId = projectBank?.bankId;
786
- const globalBankId = globalBank?.bankId;
787
-
788
- const patch = {
789
- ...buildGuidedSetupPatch({
790
- profile: setupProfile,
791
- ...(projectBankId !== undefined ? { projectBankId } : {}),
792
- ...(globalBankId !== undefined ? { globalBankId } : {}),
793
- config,
794
- }),
795
- agentUse,
796
- };
797
- const globalPatch = buildGuidedSetupGlobalPatch({
798
- profile: setupProfile,
799
- ...(globalBankId !== undefined ? { globalBankId } : {}),
800
- ...(projectBankId !== undefined ? { projectBankId } : {}),
801
- config,
802
- });
803
- const summary = [
804
- `Profile: ${setupProfileChoiceToMemoryProfile(setupProfile)}`,
805
- `Agent use: ${agentUse}`,
806
- `Server: ${connection.serverReachable ? "reachable" : "offline"}`,
807
- ...(projectBankId
808
- ? [
809
- setupProfile === "isolated-only"
810
- ? `Project config: isolated bank ${projectBankId}`
811
- : `Global config: coding bank ${projectBankId}`,
812
- ]
813
- : []),
814
- ...(globalBankId ? [`Global config: user bank ${globalBankId}`] : []),
815
- ...(setupProfile === "recall-only"
816
- ? ["Automatic retain: disabled; automatic recall: enabled"]
817
- : []),
818
- ...(offline ? ["Offline: mental models and import will be skipped"] : []),
819
- ].join("\n");
820
- const confirmed = await args.ctx.ui.confirm("Write Pi Hindsight config?", summary);
821
- if (!confirmed) return false;
822
-
823
- const operations = createMemoryOperations(args.deps);
824
- if (globalPatch) {
825
- const globalResult = await operations.configure(args.cwd, globalPatch);
826
- args.ctx.ui.notify(`Wrote ${globalResult.path}`, "info");
827
- }
828
- const result = await operations.configure(args.cwd, patch);
829
- args.ctx.ui.notify(`Wrote ${result.path}`, "info");
830
-
831
- if (offline) {
832
- args.ctx.ui.notify(
833
- "Offline setup complete. Re-run guided setup or use hub (t / i) when the server is reachable for mental models and import.",
834
- "info",
835
- );
836
- return true;
837
- }
838
-
839
- await maybeOfferMentalModelsForSetup({
840
- ctx: args.ctx,
841
- operations,
842
- client,
843
- agentUse,
844
- setupProfile,
845
- cwd: args.cwd,
846
- config,
847
- ...(projectBankId !== undefined ? { projectBankId } : {}),
848
- ...(globalBankId !== undefined ? { globalBankId } : {}),
849
- });
850
-
851
- await maybeOfferHistoricalImportForSetup({
852
- ctx: args.ctx,
853
- operations,
854
- setupProfile,
855
- cwd: args.cwd,
856
- ...(projectBankId !== undefined ? { projectBankId } : {}),
857
- ...(globalBankId !== undefined ? { globalBankId } : {}),
858
- });
859
- return true;
860
- }