@selesai/code 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (461) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/core/agent-session.d.ts +1 -1
  3. package/dist/core/agent-session.js +1 -1
  4. package/dist/core/sdk.d.ts +2 -2
  5. package/dist/core/sdk.js +1 -1
  6. package/dist/core/system-prompt.d.ts +1 -1
  7. package/dist/core/system-prompt.js +1 -1
  8. package/dist/extensions/ascii.txt +9 -0
  9. package/dist/extensions/package.json +1 -2
  10. package/dist/extensions/pi-hermes-memory/CHANGELOG.md +371 -0
  11. package/dist/extensions/pi-hermes-memory/LICENSE +21 -0
  12. package/dist/extensions/pi-hermes-memory/README.md +643 -0
  13. package/dist/extensions/pi-hermes-memory/docs/0.1/TASKS.md +197 -0
  14. package/dist/extensions/pi-hermes-memory/docs/0.2/PLAN.md +290 -0
  15. package/dist/extensions/pi-hermes-memory/docs/0.2/TASKS.md +134 -0
  16. package/dist/extensions/pi-hermes-memory/docs/0.2/TEST-PLAN.md +216 -0
  17. package/dist/extensions/pi-hermes-memory/docs/0.3/PLAN.md +330 -0
  18. package/dist/extensions/pi-hermes-memory/docs/0.3/TASKS.md +125 -0
  19. package/dist/extensions/pi-hermes-memory/docs/0.4/PLAN.md +160 -0
  20. package/dist/extensions/pi-hermes-memory/docs/0.4/TASKS.md +113 -0
  21. package/dist/extensions/pi-hermes-memory/docs/0.6/CHANGELOG.md +57 -0
  22. package/dist/extensions/pi-hermes-memory/docs/0.6/PLAN.md +202 -0
  23. package/dist/extensions/pi-hermes-memory/docs/0.6/TASKS.md +144 -0
  24. package/dist/extensions/pi-hermes-memory/docs/0.7/PLAN.md +349 -0
  25. package/dist/extensions/pi-hermes-memory/docs/0.7/TASKS.md +110 -0
  26. package/dist/extensions/pi-hermes-memory/docs/PUBLISHING.md +149 -0
  27. package/dist/extensions/pi-hermes-memory/docs/ROADMAP.md +468 -0
  28. package/dist/extensions/pi-hermes-memory/docs/images/memory-architecture.svg +1 -0
  29. package/dist/extensions/pi-hermes-memory/docs/images/pi-logo.svg +22 -0
  30. package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.png +0 -0
  31. package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.svg +19 -0
  32. package/dist/extensions/pi-hermes-memory/docs/images/security-flow.svg +1 -0
  33. package/dist/extensions/pi-hermes-memory/docs/images/session-lifecycle.svg +1 -0
  34. package/dist/extensions/pi-hermes-memory/docs/images/source-architecture.svg +1 -0
  35. package/dist/extensions/pi-hermes-memory/docs/mermaid/memory-architecture.mmd +49 -0
  36. package/dist/extensions/pi-hermes-memory/docs/mermaid/security-flow.mmd +40 -0
  37. package/dist/extensions/pi-hermes-memory/docs/mermaid/session-lifecycle.mmd +56 -0
  38. package/dist/extensions/pi-hermes-memory/docs/mermaid/source-architecture.mmd +54 -0
  39. package/dist/extensions/pi-hermes-memory/package-lock.json +3799 -0
  40. package/dist/extensions/pi-hermes-memory/package.json +66 -0
  41. package/dist/extensions/pi-hermes-memory/scripts/check-min-sdk.mjs +99 -0
  42. package/dist/extensions/pi-hermes-memory/scripts/ensure-dev.mjs +57 -0
  43. package/dist/extensions/pi-hermes-memory/src/auto-consolidation-warning.ts +6 -0
  44. package/dist/extensions/pi-hermes-memory/src/config.ts +178 -0
  45. package/dist/extensions/pi-hermes-memory/src/constants.ts +424 -0
  46. package/dist/extensions/pi-hermes-memory/src/extension-root-migration.ts +639 -0
  47. package/dist/extensions/pi-hermes-memory/src/handlers/auto-consolidate.ts +401 -0
  48. package/dist/extensions/pi-hermes-memory/src/handlers/background-review.ts +297 -0
  49. package/dist/extensions/pi-hermes-memory/src/handlers/child-process-watchdog.mjs +90 -0
  50. package/dist/extensions/pi-hermes-memory/src/handlers/correction-detector.ts +300 -0
  51. package/dist/extensions/pi-hermes-memory/src/handlers/index-sessions.ts +86 -0
  52. package/dist/extensions/pi-hermes-memory/src/handlers/insights.ts +78 -0
  53. package/dist/extensions/pi-hermes-memory/src/handlers/interview.ts +37 -0
  54. package/dist/extensions/pi-hermes-memory/src/handlers/learn-memory.ts +186 -0
  55. package/dist/extensions/pi-hermes-memory/src/handlers/message-parts.ts +27 -0
  56. package/dist/extensions/pi-hermes-memory/src/handlers/pi-child-process.ts +485 -0
  57. package/dist/extensions/pi-hermes-memory/src/handlers/preview-context.ts +105 -0
  58. package/dist/extensions/pi-hermes-memory/src/handlers/review-memory-ops.ts +506 -0
  59. package/dist/extensions/pi-hermes-memory/src/handlers/session-backfill.ts +145 -0
  60. package/dist/extensions/pi-hermes-memory/src/handlers/session-flush.ts +151 -0
  61. package/dist/extensions/pi-hermes-memory/src/handlers/session-live-index.ts +94 -0
  62. package/dist/extensions/pi-hermes-memory/src/handlers/skills-command.ts +1334 -0
  63. package/dist/extensions/pi-hermes-memory/src/handlers/standing-pin.ts +111 -0
  64. package/dist/extensions/pi-hermes-memory/src/handlers/switch-project.ts +75 -0
  65. package/dist/extensions/pi-hermes-memory/src/handlers/sync-markdown-memories.ts +266 -0
  66. package/dist/extensions/pi-hermes-memory/src/index.ts +378 -0
  67. package/dist/extensions/pi-hermes-memory/src/lifecycle-timing.ts +54 -0
  68. package/dist/extensions/pi-hermes-memory/src/paths.ts +61 -0
  69. package/dist/extensions/pi-hermes-memory/src/project-context.ts +13 -0
  70. package/dist/extensions/pi-hermes-memory/src/project-memory-migration.ts +93 -0
  71. package/dist/extensions/pi-hermes-memory/src/project.ts +157 -0
  72. package/dist/extensions/pi-hermes-memory/src/prompt-context.ts +55 -0
  73. package/dist/extensions/pi-hermes-memory/src/store/atomic-lock-coordinator.ts +375 -0
  74. package/dist/extensions/pi-hermes-memory/src/store/canonical-storage-path.ts +54 -0
  75. package/dist/extensions/pi-hermes-memory/src/store/content-scanner.ts +101 -0
  76. package/dist/extensions/pi-hermes-memory/src/store/db.ts +1180 -0
  77. package/dist/extensions/pi-hermes-memory/src/store/fts-query.ts +101 -0
  78. package/dist/extensions/pi-hermes-memory/src/store/markdown-mutation-lock.ts +38 -0
  79. package/dist/extensions/pi-hermes-memory/src/store/memory-lookup.ts +24 -0
  80. package/dist/extensions/pi-hermes-memory/src/store/memory-store.ts +1191 -0
  81. package/dist/extensions/pi-hermes-memory/src/store/recovery-maintenance.ts +66 -0
  82. package/dist/extensions/pi-hermes-memory/src/store/schema.ts +118 -0
  83. package/dist/extensions/pi-hermes-memory/src/store/session-anchor-search.ts +472 -0
  84. package/dist/extensions/pi-hermes-memory/src/store/session-indexer.ts +511 -0
  85. package/dist/extensions/pi-hermes-memory/src/store/session-parser.ts +213 -0
  86. package/dist/extensions/pi-hermes-memory/src/store/session-search.ts +234 -0
  87. package/dist/extensions/pi-hermes-memory/src/store/skill-store.ts +950 -0
  88. package/dist/extensions/pi-hermes-memory/src/store/skill-utils.ts +133 -0
  89. package/dist/extensions/pi-hermes-memory/src/store/sqlite-memory-store.ts +1002 -0
  90. package/dist/extensions/pi-hermes-memory/src/store/sqlite-native.ts +241 -0
  91. package/dist/extensions/pi-hermes-memory/src/store/standing-instructions.ts +247 -0
  92. package/dist/extensions/pi-hermes-memory/src/tools/memory-search-tool.ts +95 -0
  93. package/dist/extensions/pi-hermes-memory/src/tools/memory-tool.ts +469 -0
  94. package/dist/extensions/pi-hermes-memory/src/tools/session-search-tool.ts +246 -0
  95. package/dist/extensions/pi-hermes-memory/src/tools/shared-output-view.ts +170 -0
  96. package/dist/extensions/pi-hermes-memory/src/tools/skill-tool.ts +333 -0
  97. package/dist/extensions/pi-hermes-memory/src/tools/tool-result-views.ts +105 -0
  98. package/dist/extensions/pi-hermes-memory/src/types.ts +214 -0
  99. package/dist/extensions/pi-hermes-memory/tests/config.test.ts +434 -0
  100. package/dist/extensions/pi-hermes-memory/tests/extension-root-migration.test.ts +368 -0
  101. package/dist/extensions/pi-hermes-memory/tests/handlers/auto-consolidate.test.ts +984 -0
  102. package/dist/extensions/pi-hermes-memory/tests/handlers/background-review.test.ts +950 -0
  103. package/dist/extensions/pi-hermes-memory/tests/handlers/correction-detector.test.ts +671 -0
  104. package/dist/extensions/pi-hermes-memory/tests/handlers/insights.test.ts +157 -0
  105. package/dist/extensions/pi-hermes-memory/tests/handlers/interview.test.ts +127 -0
  106. package/dist/extensions/pi-hermes-memory/tests/handlers/pi-child-process.test.ts +905 -0
  107. package/dist/extensions/pi-hermes-memory/tests/handlers/preview-context.test.ts +152 -0
  108. package/dist/extensions/pi-hermes-memory/tests/handlers/prompt-context.test.ts +166 -0
  109. package/dist/extensions/pi-hermes-memory/tests/handlers/resources-discover.test.ts +71 -0
  110. package/dist/extensions/pi-hermes-memory/tests/handlers/review-memory-ops.test.ts +614 -0
  111. package/dist/extensions/pi-hermes-memory/tests/handlers/session-backfill.test.ts +192 -0
  112. package/dist/extensions/pi-hermes-memory/tests/handlers/session-flush.test.ts +677 -0
  113. package/dist/extensions/pi-hermes-memory/tests/handlers/session-live-index.test.ts +225 -0
  114. package/dist/extensions/pi-hermes-memory/tests/handlers/skills-command.test.ts +827 -0
  115. package/dist/extensions/pi-hermes-memory/tests/handlers/standing-pin.test.ts +134 -0
  116. package/dist/extensions/pi-hermes-memory/tests/handlers/sync-markdown-memories.test.ts +491 -0
  117. package/dist/extensions/pi-hermes-memory/tests/handlers/system-prompt.test.ts +199 -0
  118. package/dist/extensions/pi-hermes-memory/tests/handlers/thinking-max.test.ts +64 -0
  119. package/dist/extensions/pi-hermes-memory/tests/index.test.ts +30 -0
  120. package/dist/extensions/pi-hermes-memory/tests/integration/flow.test.ts +126 -0
  121. package/dist/extensions/pi-hermes-memory/tests/lifecycle-timing.test.ts +76 -0
  122. package/dist/extensions/pi-hermes-memory/tests/paths.test.ts +23 -0
  123. package/dist/extensions/pi-hermes-memory/tests/project-memory-migration.test.ts +80 -0
  124. package/dist/extensions/pi-hermes-memory/tests/project-rebinding.test.ts +115 -0
  125. package/dist/extensions/pi-hermes-memory/tests/project.test.ts +120 -0
  126. package/dist/extensions/pi-hermes-memory/tests/run-all-timeout.test.ts +107 -0
  127. package/dist/extensions/pi-hermes-memory/tests/run-all.sh +45 -0
  128. package/dist/extensions/pi-hermes-memory/tests/store/atomic-lock-coordinator.test.ts +381 -0
  129. package/dist/extensions/pi-hermes-memory/tests/store/content-scanner.test.ts +388 -0
  130. package/dist/extensions/pi-hermes-memory/tests/store/db.test.ts +1046 -0
  131. package/dist/extensions/pi-hermes-memory/tests/store/markdown-mutation-lock.test.ts +34 -0
  132. package/dist/extensions/pi-hermes-memory/tests/store/memory-store.test.ts +2150 -0
  133. package/dist/extensions/pi-hermes-memory/tests/store/recovery-maintenance.test.ts +170 -0
  134. package/dist/extensions/pi-hermes-memory/tests/store/session-anchor-search.test.ts +210 -0
  135. package/dist/extensions/pi-hermes-memory/tests/store/session-indexer.test.ts +643 -0
  136. package/dist/extensions/pi-hermes-memory/tests/store/session-parser.test.ts +282 -0
  137. package/dist/extensions/pi-hermes-memory/tests/store/session-search.test.ts +287 -0
  138. package/dist/extensions/pi-hermes-memory/tests/store/skill-store.test.ts +678 -0
  139. package/dist/extensions/pi-hermes-memory/tests/store/skill-utils.test.ts +21 -0
  140. package/dist/extensions/pi-hermes-memory/tests/store/sqlite-lazy-load.test.ts +78 -0
  141. package/dist/extensions/pi-hermes-memory/tests/store/sqlite-memory-store.test.ts +543 -0
  142. package/dist/extensions/pi-hermes-memory/tests/store/sqlite-native.test.ts +164 -0
  143. package/dist/extensions/pi-hermes-memory/tests/store/standing-instructions.test.ts +171 -0
  144. package/dist/extensions/pi-hermes-memory/tests/tools/memory-search-tool.test.ts +84 -0
  145. package/dist/extensions/pi-hermes-memory/tests/tools/memory-tool.test.ts +709 -0
  146. package/dist/extensions/pi-hermes-memory/tests/tools/session-search-tool.test.ts +345 -0
  147. package/dist/extensions/pi-hermes-memory/tests/tools/shared-output-view.test.ts +362 -0
  148. package/dist/extensions/pi-hermes-memory/tests/tools/skill-tool.test.ts +478 -0
  149. package/dist/extensions/pi-hermes-memory/tests/tools/tool-result-renderer-wiring.test.ts +40 -0
  150. package/dist/extensions/pi-hermes-memory/tsconfig.json +19 -0
  151. package/dist/extensions/pi-subagents/.oxlintrc.json +43 -0
  152. package/dist/extensions/pi-subagents/AGENTS.md +5 -0
  153. package/dist/extensions/pi-subagents/CHANGELOG.md +157 -0
  154. package/dist/extensions/pi-subagents/README.md +12 -6
  155. package/dist/extensions/pi-subagents/VISION.md +81 -0
  156. package/dist/extensions/pi-subagents/agents/claude-code-writer.md +15 -0
  157. package/dist/extensions/pi-subagents/agents/claude-code.md +15 -0
  158. package/dist/extensions/pi-subagents/agents/codex-exec-writer.md +15 -0
  159. package/dist/extensions/pi-subagents/agents/codex-exec.md +15 -0
  160. package/dist/extensions/pi-subagents/agents/cursor-agent-writer.md +14 -0
  161. package/dist/extensions/pi-subagents/agents/cursor-agent.md +14 -0
  162. package/dist/extensions/pi-subagents/agents/reviewer.md +1 -3
  163. package/dist/extensions/pi-subagents/docs/agents.md +488 -0
  164. package/dist/extensions/pi-subagents/docs/configuration.md +46 -9
  165. package/dist/extensions/pi-subagents/docs/extension-api.md +42 -3
  166. package/dist/extensions/pi-subagents/docs/models.md +27 -4
  167. package/dist/extensions/pi-subagents/docs/observability.md +10 -9
  168. package/dist/extensions/pi-subagents/docs/tool-reference.md +102 -6
  169. package/dist/extensions/pi-subagents/docs/workflows.md +135 -0
  170. package/dist/extensions/pi-subagents/package-lock.json +389 -2
  171. package/dist/extensions/pi-subagents/package.json +3 -1
  172. package/dist/extensions/pi-subagents/prompts/review-loop.md +2 -2
  173. package/dist/extensions/pi-subagents/skills/council-mode/SKILL.md +1 -1
  174. package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +3 -1
  175. package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +7 -3
  176. package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  177. package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +26 -5
  178. package/dist/extensions/pi-subagents/src/agents/agent-management.ts +41 -22
  179. package/dist/extensions/pi-subagents/src/agents/agent-refinements.ts +4 -4
  180. package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +9 -2
  181. package/dist/extensions/pi-subagents/src/agents/agents.ts +322 -75
  182. package/dist/extensions/pi-subagents/src/agents/builtin-names.ts +6 -0
  183. package/dist/extensions/pi-subagents/src/agents/runtime-agent-events.ts +70 -0
  184. package/dist/extensions/pi-subagents/src/agents/runtime-agent-registry.ts +27 -20
  185. package/dist/extensions/pi-subagents/src/api/agents.ts +10 -5
  186. package/dist/extensions/pi-subagents/src/api/background-work.ts +5 -1
  187. package/dist/extensions/pi-subagents/src/api/delegation.ts +0 -7
  188. package/dist/extensions/pi-subagents/src/api/preflight.ts +34 -12
  189. package/dist/extensions/pi-subagents/src/extension/config.ts +70 -0
  190. package/dist/extensions/pi-subagents/src/extension/doctor.ts +3 -3
  191. package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +5 -3
  192. package/dist/extensions/pi-subagents/src/extension/index.ts +83 -30
  193. package/dist/extensions/pi-subagents/src/extension/public-execution.ts +44 -15
  194. package/dist/extensions/pi-subagents/src/extension/rpc.ts +55 -19
  195. package/dist/extensions/pi-subagents/src/extension/schemas.ts +41 -15
  196. package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -31
  197. package/dist/extensions/pi-subagents/src/inspectors/herdr/actions.ts +2 -1
  198. package/dist/extensions/pi-subagents/src/inspectors/herdr/inspector-runner.ts +2 -10
  199. package/dist/extensions/pi-subagents/src/inspectors/herdr/session-roots-codec.ts +42 -0
  200. package/dist/extensions/pi-subagents/src/integrations/herdr-status.ts +51 -3
  201. package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +2 -0
  202. package/dist/extensions/pi-subagents/src/profiles/profiles.ts +5 -6
  203. package/dist/extensions/pi-subagents/src/runs/background/active-async-capacity.ts +77 -10
  204. package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +176 -53
  205. package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +19 -12
  206. package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +29 -27
  207. package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +20 -3
  208. package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +23 -261
  209. package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +73 -7
  210. package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +8 -3
  211. package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +74 -8
  212. package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +37 -21
  213. package/dist/extensions/pi-subagents/src/runs/background/inspect-rpc.ts +8 -8
  214. package/dist/extensions/pi-subagents/src/runs/background/notify.ts +184 -9
  215. package/dist/extensions/pi-subagents/src/runs/background/result-delivery-ownership.ts +45 -0
  216. package/dist/extensions/pi-subagents/src/runs/background/result-files.ts +28 -14
  217. package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +38 -15
  218. package/dist/extensions/pi-subagents/src/runs/background/resume-guidance.ts +1 -1
  219. package/dist/extensions/pi-subagents/src/runs/background/retained-children.ts +1 -1
  220. package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +50 -13
  221. package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +93 -8
  222. package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +10 -4
  223. package/dist/extensions/pi-subagents/src/runs/background/steering.ts +4 -14
  224. package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +549 -377
  225. package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +58 -10
  226. package/dist/extensions/pi-subagents/src/runs/background/terminal-run-index.ts +1 -1
  227. package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +26 -1
  228. package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +23 -9
  229. package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +9 -2
  230. package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +2 -2
  231. package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +204 -129
  232. package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +9 -0
  233. package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +23 -1
  234. package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +773 -311
  235. package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
  236. package/dist/extensions/pi-subagents/src/runs/shared/abort-recovery.ts +119 -0
  237. package/dist/extensions/pi-subagents/src/runs/shared/async-status-projection.ts +463 -0
  238. package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +19 -4
  239. package/dist/extensions/pi-subagents/src/runs/shared/child-launch-plan.ts +151 -0
  240. package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +21 -7
  241. package/dist/extensions/pi-subagents/src/runs/shared/claude-code-adapter.ts +129 -0
  242. package/dist/extensions/pi-subagents/src/runs/shared/codex-exec-adapter.ts +129 -0
  243. package/dist/extensions/pi-subagents/src/runs/shared/completion-evidence.ts +89 -0
  244. package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +5 -4
  245. package/dist/extensions/pi-subagents/src/runs/shared/cursor-agent-adapter.ts +114 -0
  246. package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +3 -3
  247. package/dist/extensions/pi-subagents/src/runs/shared/external-cli-contract.ts +167 -0
  248. package/dist/extensions/pi-subagents/src/runs/shared/external-cli-preflight.ts +122 -0
  249. package/dist/extensions/pi-subagents/src/runs/shared/external-cli-runner.ts +348 -55
  250. package/dist/extensions/pi-subagents/src/runs/shared/fast-mode-extension.ts +5 -5
  251. package/dist/extensions/pi-subagents/src/runs/shared/host-step-status.ts +230 -0
  252. package/dist/extensions/pi-subagents/src/runs/shared/lane-metadata.ts +105 -0
  253. package/dist/extensions/pi-subagents/src/runs/shared/launch-cwd.ts +16 -0
  254. package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +2 -1
  255. package/dist/extensions/pi-subagents/src/runs/shared/mcp-config-sources.ts +422 -0
  256. package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +221 -158
  257. package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-grant.ts +197 -0
  258. package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +69 -7
  259. package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +47 -6
  260. package/dist/extensions/pi-subagents/src/runs/shared/mutation-evidence.ts +7 -2
  261. package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +9 -3
  262. package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +9 -5
  263. package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +419 -7
  264. package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +15 -1
  265. package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +81 -8
  266. package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +13 -0
  267. package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +21 -1
  268. package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +44 -4
  269. package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +98 -13
  270. package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +1 -1
  271. package/dist/extensions/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +847 -0
  272. package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +18 -0
  273. package/dist/extensions/pi-subagents/src/shared/child-session-name.ts +46 -0
  274. package/dist/extensions/pi-subagents/src/shared/extension-context.ts +24 -0
  275. package/dist/extensions/pi-subagents/src/shared/fork-context.ts +21 -0
  276. package/dist/extensions/pi-subagents/src/shared/formatters.ts +18 -3
  277. package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +5 -1
  278. package/dist/extensions/pi-subagents/src/shared/pruned-fork.ts +450 -0
  279. package/dist/extensions/pi-subagents/src/shared/session-file-trust.ts +19 -0
  280. package/dist/extensions/pi-subagents/src/shared/session-tokens.ts +14 -3
  281. package/dist/extensions/pi-subagents/src/shared/settings.ts +19 -105
  282. package/dist/extensions/pi-subagents/src/shared/shortcuts.ts +17 -0
  283. package/dist/extensions/pi-subagents/src/shared/types.ts +359 -40
  284. package/dist/extensions/pi-subagents/src/shared/utils.ts +41 -84
  285. package/dist/extensions/pi-subagents/src/shared/workflow-child-permit.ts +116 -0
  286. package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +1 -9
  287. package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +0 -4
  288. package/dist/extensions/pi-subagents/src/slash/slash-bridge.ts +1 -2
  289. package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +378 -88
  290. package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +22 -11
  291. package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +3 -0
  292. package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +147 -79
  293. package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +11 -5
  294. package/dist/extensions/pi-subagents/src/tui/fleet.ts +39 -18
  295. package/dist/extensions/pi-subagents/src/tui/render.ts +369 -46
  296. package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +1 -1
  297. package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +6 -3
  298. package/dist/extensions/pi-subagents/src/workflows/host-command.ts +230 -0
  299. package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +740 -58
  300. package/dist/extensions/pi-subagents/src/workflows/workflow-child-summary.ts +121 -0
  301. package/dist/extensions/pi-subagents/src/workflows/workflow-preflight.ts +270 -0
  302. package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +195 -6
  303. package/dist/extensions/pi-subagents/src/workflows/workflow-settlement.ts +246 -0
  304. package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +2 -2
  305. package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1114 -260
  306. package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +34 -0
  307. package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +150 -3
  308. package/dist/extensions/pi-subagents/test/integration/claude-code-smoke.test.ts +52 -0
  309. package/dist/extensions/pi-subagents/test/integration/claude-code-writer-smoke.test.ts +55 -0
  310. package/dist/extensions/pi-subagents/test/integration/codex-exec-smoke.test.ts +53 -0
  311. package/dist/extensions/pi-subagents/test/integration/codex-exec-writer-smoke.test.ts +57 -0
  312. package/dist/extensions/pi-subagents/test/integration/cursor-agent-smoke.test.ts +59 -0
  313. package/dist/extensions/pi-subagents/test/integration/cursor-agent-writer-smoke.test.ts +62 -0
  314. package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +57 -1
  315. package/dist/extensions/pi-subagents/test/integration/external-cli-runner.test.ts +1 -0
  316. package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +20 -0
  317. package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +4 -3
  318. package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +2 -2
  319. package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +54 -4
  320. package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +482 -4
  321. package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +157 -9
  322. package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +5 -5
  323. package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1508 -291
  324. package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +423 -1
  325. package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +8 -0
  326. package/dist/extensions/pi-subagents/test/support/cursor-smoke-inputs.ts +51 -0
  327. package/dist/extensions/pi-subagents/test/support/helpers.ts +2 -0
  328. package/dist/extensions/pi-subagents/test/support/mock-pi.ts +5 -5
  329. package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +6 -6
  330. package/dist/extensions/pi-subagents/test/unit/abort-recovery.test.ts +152 -0
  331. package/dist/extensions/pi-subagents/test/unit/active-async-capacity.test.ts +48 -0
  332. package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +184 -6
  333. package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +66 -6
  334. package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +77 -0
  335. package/dist/extensions/pi-subagents/test/unit/agent-refinements.test.ts +18 -0
  336. package/dist/extensions/pi-subagents/test/unit/anti-slop-oxlint.test.ts +86 -0
  337. package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +1 -1
  338. package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +101 -1
  339. package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +121 -0
  340. package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +28 -0
  341. package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +14 -7
  342. package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +53 -0
  343. package/dist/extensions/pi-subagents/test/unit/async-status-projection.test.ts +190 -0
  344. package/dist/extensions/pi-subagents/test/unit/async-status-snapshot.test.ts +42 -0
  345. package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +8 -4
  346. package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +23 -0
  347. package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +78 -1
  348. package/dist/extensions/pi-subagents/test/unit/child-launch-plan.test.ts +94 -0
  349. package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +21 -0
  350. package/dist/extensions/pi-subagents/test/unit/child-session-name.test.ts +50 -0
  351. package/dist/extensions/pi-subagents/test/unit/claude-code-adapter.test.ts +245 -0
  352. package/dist/extensions/pi-subagents/test/unit/codex-exec-adapter.test.ts +192 -0
  353. package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +27 -0
  354. package/dist/extensions/pi-subagents/test/unit/completion-evidence.test.ts +150 -0
  355. package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +21 -0
  356. package/dist/extensions/pi-subagents/test/unit/cursor-agent-adapter.test.ts +259 -0
  357. package/dist/extensions/pi-subagents/test/unit/cursor-smoke-inputs.test.ts +77 -0
  358. package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +1 -4
  359. package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +1 -1
  360. package/dist/extensions/pi-subagents/test/unit/extension-context.test.ts +27 -0
  361. package/dist/extensions/pi-subagents/test/unit/external-cli-runner.test.ts +223 -0
  362. package/dist/extensions/pi-subagents/test/unit/fast-mode-extension.test.ts +27 -0
  363. package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +208 -2
  364. package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +29 -1
  365. package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +110 -1
  366. package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +10 -0
  367. package/dist/extensions/pi-subagents/test/unit/formatters.test.ts +14 -0
  368. package/dist/extensions/pi-subagents/test/unit/herdr-inspector.test.ts +18 -9
  369. package/dist/extensions/pi-subagents/test/unit/herdr-session-roots-codec.test.ts +63 -0
  370. package/dist/extensions/pi-subagents/test/unit/herdr-shell-command.test.ts +2 -2
  371. package/dist/extensions/pi-subagents/test/unit/herdr-status-bridge.test.ts +132 -0
  372. package/dist/extensions/pi-subagents/test/unit/host-command.test.ts +156 -0
  373. package/dist/extensions/pi-subagents/test/unit/host-step-status.test.ts +98 -0
  374. package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +178 -26
  375. package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +2 -1
  376. package/dist/extensions/pi-subagents/test/unit/inspect-rpc.test.ts +21 -0
  377. package/dist/extensions/pi-subagents/test/unit/mcp-direct-tool-grant.test.ts +138 -0
  378. package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +1 -1
  379. package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +91 -0
  380. package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +72 -7
  381. package/dist/extensions/pi-subagents/test/unit/mutation-evidence.test.ts +21 -0
  382. package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +1 -0
  383. package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +20 -2
  384. package/dist/extensions/pi-subagents/test/unit/notify.test.ts +129 -1
  385. package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +2 -2
  386. package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +4 -0
  387. package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +358 -0
  388. package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +574 -21
  389. package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +109 -1
  390. package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +71 -1
  391. package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +7 -7
  392. package/dist/extensions/pi-subagents/test/unit/pruned-fork.test.ts +214 -0
  393. package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +29 -8
  394. package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +53 -0
  395. package/dist/extensions/pi-subagents/test/unit/result-delivery-ownership.test.ts +34 -0
  396. package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +101 -3
  397. package/dist/extensions/pi-subagents/test/unit/retained-children.test.ts +1 -0
  398. package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +10 -8
  399. package/dist/extensions/pi-subagents/test/unit/run-fanout-budget.test.ts +71 -1
  400. package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +41 -7
  401. package/dist/extensions/pi-subagents/test/unit/runtime-agent-registration.test.ts +136 -2
  402. package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +137 -0
  403. package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +33 -12
  404. package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +504 -1
  405. package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +8 -0
  406. package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
  407. package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +12 -1
  408. package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +3 -5
  409. package/dist/extensions/pi-subagents/test/unit/steering.test.ts +5 -6
  410. package/dist/extensions/pi-subagents/test/unit/subagent-action-recovery.test.ts +0 -8
  411. package/dist/extensions/pi-subagents/test/unit/subagent-guide.test.ts +5 -0
  412. package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +157 -2
  413. package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +1 -1
  414. package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +63 -4
  415. package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +27 -23
  416. package/dist/extensions/pi-subagents/test/unit/wait-completions.test.ts +44 -0
  417. package/dist/extensions/pi-subagents/test/unit/wait-subscriptions.test.ts +1 -0
  418. package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +7 -5
  419. package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +106 -0
  420. package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +484 -9
  421. package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +38 -4
  422. package/dist/extensions/pi-subagents/test/unit/workflow-preflight.test.ts +155 -0
  423. package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +318 -0
  424. package/dist/extensions/pi-subagents/test/unit/workflow-resume-hint.test.ts +365 -0
  425. package/dist/extensions/pi-subagents/test/unit/worktree-cleanup-plan.test.ts +349 -0
  426. package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +21 -0
  427. package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +2 -7
  428. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/index.ts +13 -0
  429. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/rules/no-service-constructor-imports.ts +52 -0
  430. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/index.ts +41 -0
  431. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts +77 -0
  432. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
  433. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-known-value-widening.ts +247 -0
  434. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-module-mocking.ts +91 -0
  435. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-object-parameters.ts +126 -0
  436. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-apply.ts +28 -0
  437. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-get.ts +28 -0
  438. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-runtime-typeof.ts +67 -0
  439. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-shape-in-symbol-names.ts +39 -0
  440. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-parameters.ts +83 -0
  441. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-returns.ts +115 -0
  442. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-type-aliases.ts +72 -0
  443. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unsafe-dictionary-type.ts +134 -0
  444. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-widen-then-assert.ts +366 -0
  445. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/require-safety-comment-for-type-assertion.ts +62 -0
  446. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/dictionary-types.ts +502 -0
  447. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/lexical-type-parameters.ts +60 -0
  448. package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/reflect-method.ts +35 -0
  449. package/dist/extensions/pi-tool-display/tests/capabilities.test.ts +1 -1
  450. package/dist/extensions/pi-tool-display/tests/settings-inspector.test.ts +2 -2
  451. package/dist/extensions/pi-tool-display/tests/tool-overrides-mcp.test.ts +1 -1
  452. package/dist/modes/interactive/interactive-mode.js +7 -7
  453. package/dist/skills/workflow/SKILL.md +65 -50
  454. package/package.json +112 -110
  455. package/dist/extensions/enable-readonly-tools.test.ts +0 -63
  456. package/dist/extensions/enable-readonly-tools.ts +0 -24
  457. package/dist/extensions/model-prompt-injector/config.json +0 -16
  458. package/dist/extensions/model-prompt-injector/index.test.ts +0 -102
  459. package/dist/extensions/model-prompt-injector/index.ts +0 -148
  460. package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +0 -98
  461. package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +0 -250
@@ -0,0 +1,1334 @@
1
+ /**
2
+ * Skills command — /memory-skills opens an interactive skills manager.
3
+ */
4
+
5
+ import { createHash } from "node:crypto";
6
+ import * as os from "node:os";
7
+ import * as path from "node:path";
8
+ import type { ExtensionAPI, ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
9
+ import { SkillStore } from "../store/skill-store.js";
10
+ import type { SkillIndex, SkillResult, SkillScope } from "../types.js";
11
+ import {
12
+ Input,
13
+ Key,
14
+ fuzzyFilter,
15
+ matchesKey,
16
+ truncateToWidth,
17
+ visibleWidth,
18
+ wrapTextWithAnsi,
19
+ type Focusable,
20
+ type TUI,
21
+ } from "@earendil-works/pi-tui";
22
+
23
+ export const MEMORY_SKILLS_KEYMAP = {
24
+ moveGlobal: "g",
25
+ moveProject: "p",
26
+ deleteSelected: "d",
27
+ cycleSort: "s",
28
+ selectAllFiltered: "a",
29
+ clearSelection: "n",
30
+ focusSearch: "/",
31
+ openFilters: "f",
32
+ toggleSelection: "space",
33
+ switchFocus: "tab",
34
+ close: "esc",
35
+ } as const;
36
+
37
+ export type SkillRowCategory = "G" | "P" | "E";
38
+ export type SkillSortMode = "updated" | "created" | "name";
39
+
40
+ export interface SkillModalRow {
41
+ skillId: string;
42
+ scope?: SkillScope;
43
+ category: SkillRowCategory;
44
+ mutable: boolean;
45
+ name: string;
46
+ displayName: string;
47
+ description: string;
48
+ path: string;
49
+ displayPath: string;
50
+ created?: string;
51
+ updated?: string;
52
+ projectName?: string;
53
+ selected: boolean;
54
+ searchText: string;
55
+ }
56
+
57
+ interface LoadedSkillRow {
58
+ name: string;
59
+ displayName: string;
60
+ description: string;
61
+ path: string;
62
+ displayPath: string;
63
+ sourceScope?: string;
64
+ sourceOrigin?: string;
65
+ sourceLabel?: string;
66
+ }
67
+
68
+ interface SkillCommandInfo {
69
+ name: string;
70
+ description?: string;
71
+ source?: string;
72
+ sourceInfo?: {
73
+ path?: string;
74
+ scope?: string;
75
+ source?: string;
76
+ origin?: string;
77
+ baseDir?: string;
78
+ };
79
+ }
80
+
81
+ interface SkillCategoryFilters {
82
+ global: boolean;
83
+ project: boolean;
84
+ external: boolean;
85
+ }
86
+
87
+ function isRecord(value: unknown): value is Record<string, unknown> {
88
+ return typeof value === "object" && value !== null;
89
+ }
90
+
91
+ function getStringField(value: unknown): string | undefined {
92
+ return typeof value === "string" ? value : undefined;
93
+ }
94
+
95
+ const DEFAULT_SKILL_FILTERS: SkillCategoryFilters = {
96
+ global: true,
97
+ project: true,
98
+ external: true,
99
+ };
100
+
101
+ function cloneFilters(filters: SkillCategoryFilters): SkillCategoryFilters {
102
+ return {
103
+ global: filters.global,
104
+ project: filters.project,
105
+ external: filters.external,
106
+ };
107
+ }
108
+
109
+ function ensureValidFilters(filters: SkillCategoryFilters): SkillCategoryFilters {
110
+ if (filters.global || filters.project || filters.external) return filters;
111
+ return { ...DEFAULT_SKILL_FILTERS };
112
+ }
113
+
114
+ function filtersLabel(filters: SkillCategoryFilters): string {
115
+ const active: string[] = [];
116
+ if (filters.global) active.push("[G]");
117
+ if (filters.project) active.push("[P]");
118
+ if (filters.external) active.push("[E]");
119
+ return active.length > 0 ? active.join(" ") : "(none)";
120
+ }
121
+
122
+ function normalizePathForKey(inputPath: string): string {
123
+ const resolved = path.resolve(inputPath);
124
+ const normalized = resolved.replace(/\\/g, "/");
125
+ return process.platform === "win32" ? normalized.toLowerCase() : normalized;
126
+ }
127
+
128
+ export function formatSkillPath(inputPath: string): string {
129
+ const absolutePath = path.resolve(inputPath);
130
+ const home = os.homedir();
131
+ const relative = path.relative(home, absolutePath);
132
+ const underHome = relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
133
+
134
+ if (!underHome) return absolutePath;
135
+ if (relative === "") return "~";
136
+ return `~${path.sep}${relative}`;
137
+ }
138
+
139
+ function categoryForScope(scope: SkillScope): SkillRowCategory {
140
+ return scope === "global" ? "G" : "P";
141
+ }
142
+
143
+ function createExternalSkillId(name: string, filePath: string): string {
144
+ const safeName = (name || "skill")
145
+ .toLowerCase()
146
+ .replace(/[^a-z0-9-]+/g, "-")
147
+ .replace(/^-+|-+$/g, "") || "skill";
148
+ const hash = createHash("sha1").update(`${name}|${filePath}`).digest("hex").slice(0, 10);
149
+ return `external:${safeName}:${hash}`;
150
+ }
151
+
152
+ function matchesCategoryFilter(row: SkillModalRow, filters: SkillCategoryFilters): boolean {
153
+ if (row.category === "G") return filters.global;
154
+ if (row.category === "P") return filters.project;
155
+ return filters.external;
156
+ }
157
+
158
+ function categoryOrder(category: SkillRowCategory): number {
159
+ switch (category) {
160
+ case "G":
161
+ return 0;
162
+ case "P":
163
+ return 1;
164
+ case "E":
165
+ return 2;
166
+ }
167
+ }
168
+
169
+ function recencyValue(row: Pick<SkillModalRow, "updated" | "created">): string {
170
+ return row.updated || row.created || "";
171
+ }
172
+
173
+ function sortModeLabel(sortMode: SkillSortMode): string {
174
+ switch (sortMode) {
175
+ case "updated":
176
+ return "Updated";
177
+ case "created":
178
+ return "Created";
179
+ case "name":
180
+ return "Name";
181
+ }
182
+ }
183
+
184
+ function nextSortMode(sortMode: SkillSortMode): SkillSortMode {
185
+ switch (sortMode) {
186
+ case "updated":
187
+ return "created";
188
+ case "created":
189
+ return "name";
190
+ case "name":
191
+ return "updated";
192
+ }
193
+ }
194
+
195
+ function compareSkillRows(a: SkillModalRow, b: SkillModalRow, sortMode: SkillSortMode): number {
196
+ if (sortMode === "name") {
197
+ const byName = a.displayName.localeCompare(b.displayName);
198
+ if (byName !== 0) return byName;
199
+ return categoryOrder(a.category) - categoryOrder(b.category);
200
+ }
201
+
202
+ const primaryA = sortMode === "updated" ? recencyValue(a) : (a.created || "");
203
+ const primaryB = sortMode === "updated" ? recencyValue(b) : (b.created || "");
204
+ if (primaryA || primaryB) {
205
+ if (!primaryA) return 1;
206
+ if (!primaryB) return -1;
207
+ if (primaryA !== primaryB) return primaryB.localeCompare(primaryA);
208
+ }
209
+
210
+ if (sortMode === "updated") {
211
+ const createdA = a.created || "";
212
+ const createdB = b.created || "";
213
+ if (createdA || createdB) {
214
+ if (!createdA) return 1;
215
+ if (!createdB) return -1;
216
+ if (createdA !== createdB) return createdB.localeCompare(createdA);
217
+ }
218
+ } else {
219
+ const updatedA = recencyValue(a);
220
+ const updatedB = recencyValue(b);
221
+ if (updatedA || updatedB) {
222
+ if (!updatedA) return 1;
223
+ if (!updatedB) return -1;
224
+ if (updatedA !== updatedB) return updatedB.localeCompare(updatedA);
225
+ }
226
+ }
227
+
228
+ const byCategory = categoryOrder(a.category) - categoryOrder(b.category);
229
+ if (byCategory !== 0) return byCategory;
230
+ return a.displayName.localeCompare(b.displayName);
231
+ }
232
+
233
+ export function collectLoadedSkillsFromCommands(commands: SkillCommandInfo[]): LoadedSkillRow[] {
234
+ const loaded: LoadedSkillRow[] = [];
235
+
236
+ for (const command of commands) {
237
+ if (!isRecord(command)) continue;
238
+ const source = getStringField(command.source);
239
+ if (source !== "skill") continue;
240
+
241
+ const commandName = getStringField(command.name)?.trim();
242
+ if (!commandName) continue;
243
+
244
+ const sourceInfo = isRecord(command.sourceInfo) ? command.sourceInfo : undefined;
245
+ const sourcePath = sourceInfo ? getStringField(sourceInfo.path)?.trim() : undefined;
246
+ if (!sourcePath) continue;
247
+
248
+ const rawName = commandName.startsWith("skill:")
249
+ ? commandName.slice("skill:".length)
250
+ : commandName;
251
+ const displayName = rawName || commandName;
252
+ const filePath = path.resolve(sourcePath);
253
+
254
+ loaded.push({
255
+ name: rawName || commandName,
256
+ displayName,
257
+ description: getStringField(command.description) || "",
258
+ path: filePath,
259
+ displayPath: formatSkillPath(filePath),
260
+ sourceScope: sourceInfo ? getStringField(sourceInfo.scope) : undefined,
261
+ sourceOrigin: sourceInfo ? getStringField(sourceInfo.origin) : undefined,
262
+ sourceLabel: sourceInfo ? getStringField(sourceInfo.source) : undefined,
263
+ });
264
+ }
265
+
266
+ return loaded.sort((a, b) => a.displayName.localeCompare(b.displayName));
267
+ }
268
+
269
+ export function formatSkillsList(rows: SkillModalRow[], projectName: string | null): string {
270
+ const globalSkills = rows.filter((row) => row.category === "G");
271
+ const projectSkills = rows.filter((row) => row.category === "P");
272
+ const externalSkills = rows.filter((row) => row.category === "E");
273
+
274
+ const lines: string[] = [];
275
+ lines.push("");
276
+ lines.push(" ╔═══════════════════════════════════════════════════════════╗");
277
+ lines.push(" ║ 🧠 Procedural Skills ║");
278
+ lines.push(" ╚═══════════════════════════════════════════════════════════╝");
279
+ lines.push(" Legend: [G] global · [P] project · [E] external (read-only)");
280
+ lines.push("");
281
+
282
+ if (rows.length === 0) {
283
+ lines.push(" (no skills found in this session)");
284
+ lines.push("");
285
+ lines.push(" Ask the agent to save a reusable procedure");
286
+ lines.push(" with the skill_manage tool when it is worth keeping.");
287
+ return lines.join("\n");
288
+ }
289
+
290
+ if (globalSkills.length > 0) {
291
+ lines.push(" [G] Global Skills");
292
+ lines.push(" ─────────────────");
293
+ for (const row of globalSkills) {
294
+ lines.push(` 📄 ${row.displayName} (${row.displayPath})`);
295
+ lines.push(` ${row.description || "(no description)"}`);
296
+ lines.push(` id: ${row.skillId}`);
297
+ lines.push("");
298
+ }
299
+ }
300
+
301
+ if (projectSkills.length > 0) {
302
+ lines.push(` [P] Project Skills${projectName ? ` (${projectName})` : ""}`);
303
+ lines.push(" ─────────────────────────────────");
304
+ for (const row of projectSkills) {
305
+ lines.push(` 📄 ${row.displayName} (${row.displayPath})`);
306
+ lines.push(` ${row.description || "(no description)"}`);
307
+ lines.push(` id: ${row.skillId}`);
308
+ lines.push("");
309
+ }
310
+ }
311
+
312
+ if (externalSkills.length > 0) {
313
+ lines.push(" [E] External Skills (read-only)");
314
+ lines.push(" ───────────────────────────────");
315
+ for (const row of externalSkills) {
316
+ lines.push(` 📄 ${row.displayName} (${row.displayPath})`);
317
+ lines.push(` ${row.description || "(no description)"}`);
318
+ lines.push(` id: ${row.skillId}`);
319
+ lines.push("");
320
+ }
321
+ }
322
+
323
+ return lines.join("\n");
324
+ }
325
+
326
+ export function buildSkillRows(skills: SkillIndex[], selectedSkillIds = new Set<string>()): SkillModalRow[] {
327
+ return skills.map((skill) => {
328
+ const displayName = skill.displayName || skill.name;
329
+ const displayPath = formatSkillPath(skill.path);
330
+ return {
331
+ skillId: skill.skillId,
332
+ scope: skill.scope,
333
+ category: categoryForScope(skill.scope),
334
+ mutable: true,
335
+ name: skill.name,
336
+ displayName,
337
+ description: skill.description,
338
+ path: skill.path,
339
+ displayPath,
340
+ created: skill.created,
341
+ updated: skill.updated,
342
+ projectName: skill.projectName,
343
+ selected: selectedSkillIds.has(skill.skillId),
344
+ searchText: `${displayName} ${skill.name} ${skill.description || ""} ${skill.path} ${displayPath}`.trim(),
345
+ };
346
+ });
347
+ }
348
+
349
+ export function buildUnifiedSkillRows(
350
+ managedSkills: SkillIndex[],
351
+ loadedSkills: LoadedSkillRow[],
352
+ selectedSkillIds = new Set<string>(),
353
+ sortMode: SkillSortMode = "updated",
354
+ ): SkillModalRow[] {
355
+ const managedRows = buildSkillRows(managedSkills, selectedSkillIds);
356
+ const managedPathKeys = new Set(managedRows.map((row) => normalizePathForKey(row.path)));
357
+ const externalPathKeys = new Set<string>();
358
+
359
+ const externalRows: SkillModalRow[] = [];
360
+ for (const loaded of loadedSkills) {
361
+ const loadedKey = normalizePathForKey(loaded.path);
362
+ if (managedPathKeys.has(loadedKey)) continue;
363
+ if (externalPathKeys.has(loadedKey)) continue;
364
+ externalPathKeys.add(loadedKey);
365
+
366
+ const externalSkillId = createExternalSkillId(loaded.name, loaded.path);
367
+ externalRows.push({
368
+ skillId: externalSkillId,
369
+ scope: undefined,
370
+ category: "E",
371
+ mutable: false,
372
+ name: loaded.name,
373
+ displayName: loaded.displayName,
374
+ description: loaded.description,
375
+ path: loaded.path,
376
+ displayPath: loaded.displayPath,
377
+ selected: selectedSkillIds.has(externalSkillId),
378
+ searchText: `${loaded.displayName} ${loaded.name} ${loaded.description || ""} ${loaded.path} ${loaded.displayPath}`.trim(),
379
+ });
380
+ }
381
+
382
+ return [...managedRows, ...externalRows].sort((a, b) => compareSkillRows(a, b, sortMode));
383
+ }
384
+
385
+ export function filterSkillRows(rows: SkillModalRow[], query: string): SkillModalRow[] {
386
+ const trimmed = query.trim();
387
+ if (!trimmed) return rows;
388
+ return fuzzyFilter(rows, trimmed, (row) => row.searchText);
389
+ }
390
+
391
+ export function getSelectedSkillIds(rows: SkillModalRow[]): string[] {
392
+ return rows.filter((row) => row.selected).map((row) => row.skillId);
393
+ }
394
+
395
+ function summarizeAction(
396
+ actionVerb: string,
397
+ targetLabel: string,
398
+ successes: SkillResult[],
399
+ unchanged: SkillResult[],
400
+ blocked: Array<{ skillId: string; error: string }>,
401
+ ): string[] {
402
+ const lines: string[] = [];
403
+ const changed = successes.filter((result) => result.message?.includes(actionVerb) || result.skillId);
404
+
405
+ if (actionVerb === "moved") {
406
+ lines.push(`Moved ${successes.length} skill${successes.length === 1 ? "" : "s"} to ${targetLabel}.`);
407
+ } else if (actionVerb === "deleted") {
408
+ lines.push(`Deleted ${successes.length} skill${successes.length === 1 ? "" : "s"}.`);
409
+ } else {
410
+ lines.push(`${changed.length} skill action(s) completed.`);
411
+ }
412
+
413
+ if (unchanged.length > 0) {
414
+ lines.push(`${unchanged.length} already matched the target scope.`);
415
+ }
416
+
417
+ if (blocked.length > 0) {
418
+ lines.push(`Blocked ${blocked.length} skill${blocked.length === 1 ? "" : "s"}:`);
419
+ for (const item of blocked.slice(0, 4)) {
420
+ lines.push(`- ${item.skillId}: ${item.error}`);
421
+ }
422
+ if (blocked.length > 4) {
423
+ lines.push(`- …and ${blocked.length - 4} more`);
424
+ }
425
+ }
426
+
427
+ return lines;
428
+ }
429
+
430
+ type SkillMoveStore = Pick<SkillStore, "move" | "loadIndex" | "getProjectName">;
431
+ type SkillDeleteStore = Pick<SkillStore, "delete" | "loadIndex">;
432
+ export type ConfirmDialog = (title: string, message: string) => Promise<boolean>;
433
+
434
+ export interface SkillBatchActionResult {
435
+ skills: SkillIndex[];
436
+ summaryLines: string[];
437
+ retainSelectedSkillIds?: string[];
438
+ focusSkillId?: string;
439
+ }
440
+
441
+ export async function moveSelectedSkills(
442
+ store: SkillMoveStore,
443
+ skillIds: string[],
444
+ targetScope: SkillScope,
445
+ ): Promise<SkillBatchActionResult> {
446
+ const dedupedSkillIds = Array.from(new Set(skillIds));
447
+ const currentSkills = await store.loadIndex();
448
+
449
+ if (dedupedSkillIds.length === 0) {
450
+ return {
451
+ skills: currentSkills,
452
+ summaryLines: ["Select one or more skills first."],
453
+ };
454
+ }
455
+
456
+ if (targetScope === "project" && !store.getProjectName()) {
457
+ return {
458
+ skills: currentSkills,
459
+ summaryLines: ["Move to project is unavailable: no active project detected."],
460
+ retainSelectedSkillIds: dedupedSkillIds,
461
+ };
462
+ }
463
+
464
+ const successes: SkillResult[] = [];
465
+ const unchanged: SkillResult[] = [];
466
+ const blocked: Array<{ skillId: string; error: string }> = [];
467
+
468
+ for (const skillId of dedupedSkillIds) {
469
+ try {
470
+ const result = await store.move(skillId, targetScope);
471
+ if (result.success) {
472
+ if (result.skillId === skillId && result.scope === targetScope) {
473
+ unchanged.push(result);
474
+ } else {
475
+ successes.push(result);
476
+ }
477
+ } else {
478
+ blocked.push({ skillId, error: result.error || "Unknown move failure." });
479
+ }
480
+ } catch (error) {
481
+ blocked.push({
482
+ skillId,
483
+ error: error instanceof Error ? error.message : String(error),
484
+ });
485
+ }
486
+ }
487
+
488
+ const refreshedSkills = await store.loadIndex();
489
+ const focusSkillId = blocked[0]?.skillId
490
+ ?? successes[0]?.skillId
491
+ ?? unchanged[0]?.skillId;
492
+
493
+ return {
494
+ skills: refreshedSkills,
495
+ summaryLines: summarizeAction("moved", targetScope, successes, unchanged, blocked),
496
+ retainSelectedSkillIds: blocked.map((item) => item.skillId),
497
+ focusSkillId,
498
+ };
499
+ }
500
+
501
+ export async function deleteSelectedSkills(
502
+ store: SkillDeleteStore,
503
+ skillIds: string[],
504
+ ): Promise<SkillBatchActionResult> {
505
+ const dedupedSkillIds = Array.from(new Set(skillIds));
506
+ const currentSkills = await store.loadIndex();
507
+
508
+ if (dedupedSkillIds.length === 0) {
509
+ return {
510
+ skills: currentSkills,
511
+ summaryLines: ["Select one or more skills first."],
512
+ };
513
+ }
514
+
515
+ const successes: SkillResult[] = [];
516
+ const blocked: Array<{ skillId: string; error: string }> = [];
517
+
518
+ for (const skillId of dedupedSkillIds) {
519
+ try {
520
+ const result = await store.delete(skillId);
521
+ if (result.success) {
522
+ successes.push(result);
523
+ } else {
524
+ blocked.push({ skillId, error: result.error || "Unknown delete failure." });
525
+ }
526
+ } catch (error) {
527
+ blocked.push({
528
+ skillId,
529
+ error: error instanceof Error ? error.message : String(error),
530
+ });
531
+ }
532
+ }
533
+
534
+ const refreshedSkills = await store.loadIndex();
535
+
536
+ return {
537
+ skills: refreshedSkills,
538
+ summaryLines: summarizeAction("deleted", "delete", successes, [], blocked),
539
+ retainSelectedSkillIds: blocked.map((item) => item.skillId),
540
+ focusSkillId: blocked[0]?.skillId,
541
+ };
542
+ }
543
+
544
+ export async function confirmDeleteSelectedSkills(
545
+ confirm: ConfirmDialog,
546
+ store: SkillDeleteStore,
547
+ skillIds: string[],
548
+ ): Promise<SkillBatchActionResult> {
549
+ const currentSkills = await store.loadIndex();
550
+ if (skillIds.length === 0) {
551
+ return { skills: currentSkills, summaryLines: ["Select one or more skills first."] };
552
+ }
553
+
554
+ const confirmed = await confirm(
555
+ "Delete selected skills?",
556
+ `Delete ${skillIds.length} selected skill${skillIds.length === 1 ? "" : "s"}? This cannot be undone.`,
557
+ );
558
+
559
+ if (!confirmed) {
560
+ return {
561
+ skills: currentSkills,
562
+ summaryLines: ["Delete cancelled."],
563
+ retainSelectedSkillIds: skillIds,
564
+ focusSkillId: skillIds[0],
565
+ };
566
+ }
567
+
568
+ return deleteSelectedSkills(store, skillIds);
569
+ }
570
+
571
+ interface SkillsManagerCallbacks {
572
+ moveSelected: (scope: SkillScope, skillIds: string[]) => Promise<SkillBatchActionResult>;
573
+ deleteSelected: (skillIds: string[]) => Promise<SkillBatchActionResult>;
574
+ close: () => void;
575
+ projectName: string | null;
576
+ }
577
+
578
+ export class SkillsManagerModal implements Focusable {
579
+ private _focused = false;
580
+
581
+ get focused(): boolean {
582
+ return this._focused;
583
+ }
584
+
585
+ set focused(value: boolean) {
586
+ this._focused = value;
587
+ this.syncSearchFocus();
588
+ }
589
+
590
+ private readonly searchInput = new Input();
591
+ private managedSkills: SkillIndex[];
592
+ private readonly loadedSkills: LoadedSkillRow[];
593
+ private rows: SkillModalRow[];
594
+ private selectedIndex = 0;
595
+ private query = "";
596
+ private focusArea: "search" | "list" | "filters" = "list";
597
+ private busy = false;
598
+ private closed = false;
599
+ private pendingDeleteConfirm: { skillIds: string[] } | null = null;
600
+ private activeFilters: SkillCategoryFilters = { ...DEFAULT_SKILL_FILTERS };
601
+ private pendingFilters: SkillCategoryFilters | null = null;
602
+ private filterCursor = 0;
603
+ private sortMode: SkillSortMode = "updated";
604
+ private summaryLines: string[] = [
605
+ "Select skills with space, then move with g/p or delete with d. Press s to change sort and f for filters.",
606
+ ];
607
+
608
+ constructor(
609
+ private readonly tui: TUI,
610
+ private readonly theme: Theme,
611
+ initialRows: SkillModalRow[],
612
+ private readonly callbacks: SkillsManagerCallbacks,
613
+ options?: {
614
+ managedSkills?: SkillIndex[];
615
+ loadedSkills?: LoadedSkillRow[];
616
+ },
617
+ ) {
618
+ const selectedSkillIds = new Set(initialRows.filter((row) => row.selected).map((row) => row.skillId));
619
+
620
+ this.loadedSkills = options?.loadedSkills
621
+ ?? initialRows
622
+ .filter((row) => row.category === "E")
623
+ .map((row) => ({
624
+ name: row.name,
625
+ displayName: row.displayName,
626
+ description: row.description,
627
+ path: row.path,
628
+ displayPath: row.displayPath,
629
+ }));
630
+
631
+ this.managedSkills = options?.managedSkills
632
+ ?? initialRows
633
+ .filter((row) => row.category !== "E" && row.scope)
634
+ .map((row) => ({
635
+ skillId: row.skillId,
636
+ scope: row.scope!,
637
+ fileName: path.basename(row.path),
638
+ path: row.path,
639
+ projectName: row.projectName,
640
+ name: row.name,
641
+ displayName: row.displayName,
642
+ description: row.description,
643
+ created: row.created ?? "",
644
+ updated: row.updated ?? "",
645
+ }));
646
+
647
+ this.rows = buildUnifiedSkillRows(this.managedSkills, this.loadedSkills, selectedSkillIds, this.sortMode);
648
+ this.syncSearchFocus();
649
+ }
650
+
651
+ invalidate(): void {
652
+ this.searchInput.invalidate();
653
+ }
654
+
655
+ private get filteredRows(): SkillModalRow[] {
656
+ const categoryFiltered = this.rows.filter((row) => matchesCategoryFilter(row, this.activeFilters));
657
+ return filterSkillRows(categoryFiltered, this.query);
658
+ }
659
+
660
+ private getCurrentRow(): SkillModalRow | null {
661
+ const rows = this.filteredRows;
662
+ if (rows.length === 0) return null;
663
+ return rows[Math.min(this.selectedIndex, rows.length - 1)] ?? null;
664
+ }
665
+
666
+ private getSelectedRows(): SkillModalRow[] {
667
+ return this.rows.filter((row) => row.selected);
668
+ }
669
+
670
+ private getSelectedIds(): string[] {
671
+ return getSelectedSkillIds(this.rows);
672
+ }
673
+
674
+ private getFilterOptions(): Array<{ key: keyof SkillCategoryFilters; label: string }> {
675
+ return [
676
+ { key: "global", label: "Global [G]" },
677
+ { key: "project", label: "Project [P]" },
678
+ { key: "external", label: "External [E] (read-only)" },
679
+ ];
680
+ }
681
+
682
+ private syncSearchFocus(): void {
683
+ this.searchInput.focused = this.focused && this.focusArea === "search";
684
+ }
685
+
686
+ private syncQueryFromInput(): void {
687
+ this.query = this.searchInput.getValue();
688
+ const rows = this.filteredRows;
689
+ if (rows.length === 0) {
690
+ this.selectedIndex = 0;
691
+ } else {
692
+ this.selectedIndex = Math.min(this.selectedIndex, rows.length - 1);
693
+ }
694
+ }
695
+
696
+ private setFocusArea(area: "search" | "list" | "filters"): void {
697
+ this.focusArea = area;
698
+ this.syncSearchFocus();
699
+ this.tui.requestRender();
700
+ }
701
+
702
+ private setRows(managedSkills: SkillIndex[], retainSelectedSkillIds: string[] = [], focusSkillId?: string): void {
703
+ this.managedSkills = managedSkills;
704
+ this.rows = buildUnifiedSkillRows(this.managedSkills, this.loadedSkills, new Set(retainSelectedSkillIds), this.sortMode);
705
+ this.syncQueryFromInput();
706
+
707
+ const rows = this.filteredRows;
708
+ if (rows.length === 0) {
709
+ this.selectedIndex = 0;
710
+ return;
711
+ }
712
+
713
+ if (focusSkillId) {
714
+ const focusIndex = rows.findIndex((row) => row.skillId === focusSkillId);
715
+ if (focusIndex >= 0) {
716
+ this.selectedIndex = focusIndex;
717
+ return;
718
+ }
719
+ }
720
+
721
+ this.selectedIndex = Math.min(this.selectedIndex, rows.length - 1);
722
+ }
723
+
724
+ private toggleSelected(skillId: string): void {
725
+ const row = this.rows.find((entry) => entry.skillId === skillId);
726
+ if (!row) return;
727
+ row.selected = !row.selected;
728
+ }
729
+
730
+ private toggleCurrentSelection(): void {
731
+ const row = this.getCurrentRow();
732
+ if (!row) return;
733
+ this.toggleSelected(row.skillId);
734
+ this.summaryLines = [
735
+ `${row.selected ? "Selected" : "Cleared"} ${row.displayName}.`,
736
+ ];
737
+ this.tui.requestRender();
738
+ }
739
+
740
+ private selectAllFiltered(): void {
741
+ const rows = this.filteredRows;
742
+ for (const row of rows) {
743
+ row.selected = true;
744
+ }
745
+ this.summaryLines = [
746
+ `Selected ${rows.length} visible skill${rows.length === 1 ? "" : "s"}.`,
747
+ ];
748
+ this.tui.requestRender();
749
+ }
750
+
751
+ private clearSelection(): void {
752
+ for (const row of this.rows) {
753
+ row.selected = false;
754
+ }
755
+ this.summaryLines = ["Cleared all selections."];
756
+ this.tui.requestRender();
757
+ }
758
+
759
+ private cycleSortMode(): void {
760
+ this.sortMode = nextSortMode(this.sortMode);
761
+ const selectedIds = this.getSelectedIds();
762
+ const currentRow = this.getCurrentRow();
763
+ this.rows = buildUnifiedSkillRows(
764
+ this.managedSkills,
765
+ this.loadedSkills,
766
+ new Set(selectedIds),
767
+ this.sortMode,
768
+ );
769
+ this.syncQueryFromInput();
770
+
771
+ const rows = this.filteredRows;
772
+ if (rows.length === 0) {
773
+ this.selectedIndex = 0;
774
+ } else if (currentRow) {
775
+ const focusIndex = rows.findIndex((row) => row.skillId === currentRow.skillId);
776
+ this.selectedIndex = focusIndex >= 0
777
+ ? focusIndex
778
+ : Math.min(this.selectedIndex, rows.length - 1);
779
+ } else {
780
+ this.selectedIndex = Math.min(this.selectedIndex, rows.length - 1);
781
+ }
782
+
783
+ this.summaryLines = [`Sort mode: ${sortModeLabel(this.sortMode)}.`];
784
+ this.tui.requestRender();
785
+ }
786
+
787
+ private appendExternalReadOnlySummary(
788
+ result: SkillBatchActionResult,
789
+ blockedExternalRows: SkillModalRow[],
790
+ verb: "move" | "delete",
791
+ ): SkillBatchActionResult {
792
+ if (blockedExternalRows.length === 0) return result;
793
+
794
+ const blockedIds = blockedExternalRows.map((row) => row.skillId);
795
+ const retainSet = new Set([...(result.retainSelectedSkillIds || []), ...blockedIds]);
796
+ const focusSkillId = result.focusSkillId || blockedIds[0];
797
+ const blockedLabel = blockedExternalRows.length === 1
798
+ ? `Blocked 1 external skill: ${blockedExternalRows[0]!.displayName} is read-only.`
799
+ : `Blocked ${blockedExternalRows.length} external skills: read-only (${verb} unavailable).`;
800
+
801
+ return {
802
+ ...result,
803
+ summaryLines: [...result.summaryLines, blockedLabel],
804
+ retainSelectedSkillIds: Array.from(retainSet),
805
+ focusSkillId,
806
+ };
807
+ }
808
+
809
+ private prepareMutableSelection(verb: "move" | "delete"):
810
+ | { proceed: false }
811
+ | { proceed: true; mutableIds: string[]; blockedExternalRows: SkillModalRow[] } {
812
+ const selectedRows = this.getSelectedRows();
813
+ if (selectedRows.length === 0) {
814
+ this.summaryLines = ["Select one or more skills first."];
815
+ this.tui.requestRender();
816
+ return { proceed: false };
817
+ }
818
+
819
+ const mutableRows = selectedRows.filter((row) => row.mutable);
820
+ const blockedExternalRows = selectedRows.filter((row) => !row.mutable);
821
+
822
+ if (mutableRows.length === 0 && blockedExternalRows.length > 0) {
823
+ this.summaryLines = [
824
+ `Blocked ${blockedExternalRows.length} external skill${blockedExternalRows.length === 1 ? "" : "s"}: read-only (${verb} unavailable).`,
825
+ ];
826
+ this.tui.requestRender();
827
+ return { proceed: false };
828
+ }
829
+
830
+ return {
831
+ proceed: true,
832
+ mutableIds: mutableRows.map((row) => row.skillId),
833
+ blockedExternalRows,
834
+ };
835
+ }
836
+
837
+ private async runMove(targetScope: SkillScope): Promise<void> {
838
+ const selection = this.prepareMutableSelection("move");
839
+ if (!selection.proceed) return;
840
+
841
+ const action = this.callbacks.moveSelected(targetScope, selection.mutableIds)
842
+ .then((result) => this.appendExternalReadOnlySummary(result, selection.blockedExternalRows, "move"));
843
+
844
+ await this.runAsyncAction(action);
845
+ }
846
+
847
+ private promptDelete(): void {
848
+ const selection = this.prepareMutableSelection("delete");
849
+ if (!selection.proceed) return;
850
+
851
+ this.pendingDeleteConfirm = { skillIds: selection.mutableIds };
852
+ const blockedCount = selection.blockedExternalRows.length;
853
+ this.summaryLines = [
854
+ `Delete ${selection.mutableIds.length} selected skill${selection.mutableIds.length === 1 ? "" : "s"}? Press y to confirm or n to cancel.${blockedCount > 0 ? ` (${blockedCount} external read-only item${blockedCount === 1 ? "" : "s"} will be skipped)` : ""}`,
855
+ ];
856
+ this.tui.requestRender();
857
+ }
858
+
859
+ private async runDeleteConfirmed(skillIds: string[]): Promise<void> {
860
+ const blockedExternalRows = this.rows.filter((row) => row.selected && !row.mutable);
861
+ const action = this.callbacks.deleteSelected(skillIds)
862
+ .then((result) => this.appendExternalReadOnlySummary(result, blockedExternalRows, "delete"));
863
+
864
+ await this.runAsyncAction(action);
865
+ }
866
+
867
+ private closeModal(): void {
868
+ if (this.closed) return;
869
+ this.closed = true;
870
+ this.callbacks.close();
871
+ }
872
+
873
+ private openFilterPanel(): void {
874
+ this.pendingFilters = cloneFilters(this.activeFilters);
875
+ this.filterCursor = 0;
876
+ this.setFocusArea("filters");
877
+ this.summaryLines = ["Filter panel open: space toggle · enter apply · esc cancel."];
878
+ this.tui.requestRender();
879
+ }
880
+
881
+ private applyFilterPanel(): void {
882
+ const candidate = ensureValidFilters(this.pendingFilters ? cloneFilters(this.pendingFilters) : cloneFilters(this.activeFilters));
883
+ const wasAllOff = this.pendingFilters
884
+ && !this.pendingFilters.global
885
+ && !this.pendingFilters.project
886
+ && !this.pendingFilters.external;
887
+
888
+ this.activeFilters = candidate;
889
+ this.pendingFilters = null;
890
+ this.syncQueryFromInput();
891
+ this.setFocusArea("list");
892
+ this.summaryLines = [
893
+ wasAllOff
894
+ ? "All categories were disabled; restored filters to [G] [P] [E]."
895
+ : `Applied filters: ${filtersLabel(this.activeFilters)}`,
896
+ ];
897
+ this.tui.requestRender();
898
+ }
899
+
900
+ private cancelFilterPanel(): void {
901
+ this.pendingFilters = null;
902
+ this.setFocusArea("list");
903
+ this.summaryLines = ["Filter changes cancelled."];
904
+ this.tui.requestRender();
905
+ }
906
+
907
+ private handleFilterInput(data: string): void {
908
+ const options = this.getFilterOptions();
909
+ const draft = this.pendingFilters ?? cloneFilters(this.activeFilters);
910
+ this.pendingFilters = draft;
911
+
912
+ if (matchesKey(data, Key.escape)) {
913
+ this.cancelFilterPanel();
914
+ return;
915
+ }
916
+ if (matchesKey(data, Key.up)) {
917
+ this.filterCursor = Math.max(0, this.filterCursor - 1);
918
+ this.tui.requestRender();
919
+ return;
920
+ }
921
+ if (matchesKey(data, Key.down)) {
922
+ this.filterCursor = Math.min(options.length - 1, this.filterCursor + 1);
923
+ this.tui.requestRender();
924
+ return;
925
+ }
926
+ if (matchesKey(data, Key.space)) {
927
+ const option = options[this.filterCursor];
928
+ if (option) {
929
+ draft[option.key] = !draft[option.key];
930
+ }
931
+ this.tui.requestRender();
932
+ return;
933
+ }
934
+ if (matchesKey(data, Key.enter)) {
935
+ this.applyFilterPanel();
936
+ }
937
+ }
938
+
939
+ private async runAsyncAction(action: Promise<SkillBatchActionResult>): Promise<void> {
940
+ if (this.closed) return;
941
+
942
+ this.busy = true;
943
+ this.summaryLines = ["Applying skill changes…"];
944
+ this.tui.requestRender();
945
+
946
+ try {
947
+ const result = await action;
948
+ if (this.closed) return;
949
+ this.setRows(result.skills, result.retainSelectedSkillIds, result.focusSkillId);
950
+ this.summaryLines = result.summaryLines;
951
+ } catch (error) {
952
+ if (!this.closed) {
953
+ this.summaryLines = [error instanceof Error ? error.message : String(error)];
954
+ }
955
+ } finally {
956
+ this.busy = false;
957
+ if (!this.closed) {
958
+ this.tui.requestRender();
959
+ }
960
+ }
961
+ }
962
+
963
+ private moveSelection(delta: number): void {
964
+ const rows = this.filteredRows;
965
+ if (rows.length === 0) return;
966
+ const next = this.selectedIndex + delta;
967
+ this.selectedIndex = Math.max(0, Math.min(next, rows.length - 1));
968
+ this.tui.requestRender();
969
+ }
970
+
971
+ private pageSelection(delta: number): void {
972
+ const pageSize = Math.max(5, this.getMaxVisibleRows() - 1);
973
+ this.moveSelection(delta * pageSize);
974
+ }
975
+
976
+ private getMaxVisibleRows(): number {
977
+ return Math.max(6, Math.min(14, this.tui.terminal.rows - 22));
978
+ }
979
+
980
+ private focusSearchWithOptionalInput(data?: string): void {
981
+ this.setFocusArea("search");
982
+ if (data) {
983
+ this.searchInput.handleInput(data);
984
+ this.syncQueryFromInput();
985
+ this.tui.requestRender();
986
+ }
987
+ }
988
+
989
+ private isPrintableInput(data: string): boolean {
990
+ return data.length === 1 && data >= " " && data !== "\x7f";
991
+ }
992
+
993
+ handleInput(data: string): void {
994
+ if (this.closed) return;
995
+
996
+ if (this.busy) {
997
+ if (matchesKey(data, Key.escape)) this.closeModal();
998
+ return;
999
+ }
1000
+
1001
+ if (this.pendingDeleteConfirm) {
1002
+ if (data === "y" || data === "Y") {
1003
+ const pending = this.pendingDeleteConfirm;
1004
+ this.pendingDeleteConfirm = null;
1005
+ void this.runDeleteConfirmed(pending.skillIds);
1006
+ return;
1007
+ }
1008
+
1009
+ if (data === "n" || data === "N" || matchesKey(data, Key.escape)) {
1010
+ this.pendingDeleteConfirm = null;
1011
+ this.summaryLines = ["Delete cancelled."];
1012
+ this.tui.requestRender();
1013
+ }
1014
+ return;
1015
+ }
1016
+
1017
+ if (this.focusArea === "filters") {
1018
+ this.handleFilterInput(data);
1019
+ return;
1020
+ }
1021
+
1022
+ if (matchesKey(data, Key.escape)) {
1023
+ this.closeModal();
1024
+ return;
1025
+ }
1026
+
1027
+ if (this.focusArea === "search") {
1028
+ if (matchesKey(data, Key.tab) || matchesKey(data, Key.down)) {
1029
+ this.setFocusArea("list");
1030
+ return;
1031
+ }
1032
+
1033
+ this.searchInput.handleInput(data);
1034
+ this.syncQueryFromInput();
1035
+ this.tui.requestRender();
1036
+ return;
1037
+ }
1038
+
1039
+ if (data === MEMORY_SKILLS_KEYMAP.openFilters) {
1040
+ this.openFilterPanel();
1041
+ return;
1042
+ }
1043
+ if (data === MEMORY_SKILLS_KEYMAP.cycleSort) {
1044
+ this.cycleSortMode();
1045
+ return;
1046
+ }
1047
+
1048
+ if (matchesKey(data, Key.tab) || matchesKey(data, Key.slash)) {
1049
+ this.focusSearchWithOptionalInput();
1050
+ return;
1051
+ }
1052
+ if (matchesKey(data, Key.up)) {
1053
+ this.moveSelection(-1);
1054
+ return;
1055
+ }
1056
+ if (matchesKey(data, Key.down)) {
1057
+ this.moveSelection(1);
1058
+ return;
1059
+ }
1060
+ if (matchesKey(data, Key.pageUp)) {
1061
+ this.pageSelection(-1);
1062
+ return;
1063
+ }
1064
+ if (matchesKey(data, Key.pageDown)) {
1065
+ this.pageSelection(1);
1066
+ return;
1067
+ }
1068
+ if (matchesKey(data, Key.home)) {
1069
+ this.selectedIndex = 0;
1070
+ this.tui.requestRender();
1071
+ return;
1072
+ }
1073
+ if (matchesKey(data, Key.end)) {
1074
+ this.selectedIndex = Math.max(0, this.filteredRows.length - 1);
1075
+ this.tui.requestRender();
1076
+ return;
1077
+ }
1078
+ if (matchesKey(data, Key.space)) {
1079
+ this.toggleCurrentSelection();
1080
+ return;
1081
+ }
1082
+ if (data === MEMORY_SKILLS_KEYMAP.selectAllFiltered) {
1083
+ this.selectAllFiltered();
1084
+ return;
1085
+ }
1086
+ if (data === MEMORY_SKILLS_KEYMAP.clearSelection) {
1087
+ this.clearSelection();
1088
+ return;
1089
+ }
1090
+ if (data === MEMORY_SKILLS_KEYMAP.moveGlobal) {
1091
+ void this.runMove("global");
1092
+ return;
1093
+ }
1094
+ if (data === MEMORY_SKILLS_KEYMAP.moveProject) {
1095
+ void this.runMove("project");
1096
+ return;
1097
+ }
1098
+ if (data === MEMORY_SKILLS_KEYMAP.deleteSelected) {
1099
+ this.promptDelete();
1100
+ return;
1101
+ }
1102
+ if (this.isPrintableInput(data) && !["g", "p", "d", "a", "n", "f", "s"].includes(data)) {
1103
+ this.focusSearchWithOptionalInput(data);
1104
+ }
1105
+ }
1106
+
1107
+ private renderFramedLine(content: string, width: number): string {
1108
+ const innerWidth = Math.max(10, width - 4);
1109
+ const padded = truncateToWidth(content, innerWidth, "");
1110
+ const spaces = Math.max(0, innerWidth - visibleWidth(padded));
1111
+ return `${this.theme.fg("borderAccent", "│")} ${padded}${" ".repeat(spaces)} ${this.theme.fg("borderAccent", "│")}`;
1112
+ }
1113
+
1114
+ private renderWrappedSection(lines: string[], width: number): string[] {
1115
+ const rendered: string[] = [];
1116
+ const innerWidth = Math.max(10, width - 4);
1117
+ for (const line of lines) {
1118
+ const wrapped = wrapTextWithAnsi(line, innerWidth);
1119
+ if (wrapped.length === 0) {
1120
+ rendered.push(this.renderFramedLine("", width));
1121
+ continue;
1122
+ }
1123
+ for (const part of wrapped) {
1124
+ rendered.push(this.renderFramedLine(part, width));
1125
+ }
1126
+ }
1127
+ return rendered;
1128
+ }
1129
+
1130
+ private renderFilterPanel(width: number): string[] {
1131
+ const panelWidth = Math.max(34, Math.min(width - 10, 58));
1132
+ const top = this.theme.fg("borderAccent", `┌${"─".repeat(Math.max(1, panelWidth - 2))}┐`);
1133
+ const bottom = this.theme.fg("borderAccent", `└${"─".repeat(Math.max(1, panelWidth - 2))}┘`);
1134
+ const lines: string[] = [top];
1135
+
1136
+ lines.push(this.renderFramedLine(this.theme.fg("accent", this.theme.bold("Filters")), panelWidth));
1137
+ lines.push(this.renderFramedLine(this.theme.fg("dim", "Space toggle · Enter apply · Esc cancel"), panelWidth));
1138
+ lines.push(this.renderFramedLine("", panelWidth));
1139
+
1140
+ const draft = this.pendingFilters ?? this.activeFilters;
1141
+ const options = this.getFilterOptions();
1142
+ for (let i = 0; i < options.length; i++) {
1143
+ const option = options[i]!;
1144
+ const checked = draft[option.key] ? "[x]" : "[ ]";
1145
+ const cursor = i === this.filterCursor ? this.theme.fg("accent", "›") : " ";
1146
+ const text = `${cursor} ${checked} ${option.label}`;
1147
+ const rendered = i === this.filterCursor
1148
+ ? this.theme.bg("selectedBg", truncateToWidth(text, Math.max(10, panelWidth - 4), ""))
1149
+ : truncateToWidth(text, Math.max(10, panelWidth - 4), "");
1150
+ lines.push(this.renderFramedLine(rendered, panelWidth));
1151
+ }
1152
+
1153
+ lines.push(this.renderFramedLine("", panelWidth));
1154
+ lines.push(this.renderFramedLine(this.theme.fg("dim", `Draft: ${filtersLabel(draft)}`), panelWidth));
1155
+ lines.push(bottom);
1156
+ return lines;
1157
+ }
1158
+
1159
+ render(width: number): string[] {
1160
+ const safeWidth = Math.max(60, width);
1161
+ const top = this.theme.fg("borderAccent", `┌${"─".repeat(Math.max(1, safeWidth - 2))}┐`);
1162
+ const bottom = this.theme.fg("borderAccent", `└${"─".repeat(Math.max(1, safeWidth - 2))}┘`);
1163
+ const lines: string[] = [top];
1164
+
1165
+ const projectName = this.callbacks.projectName ? ` · project: ${this.callbacks.projectName}` : "";
1166
+ const title = this.theme.fg("accent", this.theme.bold(`🧠 Procedural Skills${projectName}`));
1167
+ lines.push(this.renderFramedLine(title, safeWidth));
1168
+
1169
+ const searchHint = this.focusArea === "search"
1170
+ ? this.theme.fg("accent", "search")
1171
+ : this.theme.fg("dim", "search");
1172
+ const searchLine = this.searchInput.render(Math.max(10, safeWidth - 17))[0] ?? "";
1173
+ lines.push(this.renderFramedLine(`${searchHint}: ${searchLine}`, safeWidth));
1174
+
1175
+ const filteredRows = this.filteredRows;
1176
+ const selectedCount = this.getSelectedIds().length;
1177
+ lines.push(this.renderFramedLine(
1178
+ this.theme.fg(
1179
+ "dim",
1180
+ `${filteredRows.length} visible · ${this.rows.length} total · ${selectedCount} selected · sort: ${sortModeLabel(this.sortMode)}${this.busy ? " · working…" : ""}`,
1181
+ ),
1182
+ safeWidth,
1183
+ ));
1184
+
1185
+ lines.push(this.renderFramedLine(this.theme.fg("dim", `Legend: [G] global · [P] project · [E] external (read-only) · filters: ${filtersLabel(this.activeFilters)}`), safeWidth));
1186
+ lines.push(this.renderFramedLine("", safeWidth));
1187
+
1188
+ if (filteredRows.length === 0) {
1189
+ const emptyMessage = this.rows.length === 0 ? "No skills found yet." : "No skills match the current filters/search.";
1190
+ lines.push(this.renderFramedLine(this.theme.fg("warning", emptyMessage), safeWidth));
1191
+ lines.push(this.renderFramedLine("", safeWidth));
1192
+ } else {
1193
+ const maxVisible = this.getMaxVisibleRows();
1194
+ const start = Math.max(0, Math.min(this.selectedIndex - Math.floor(maxVisible / 2), filteredRows.length - maxVisible));
1195
+ const end = Math.min(filteredRows.length, start + maxVisible);
1196
+ const visibleRows = filteredRows.slice(start, end);
1197
+
1198
+ for (let i = 0; i < visibleRows.length; i++) {
1199
+ const row = visibleRows[i]!;
1200
+ const absoluteIndex = start + i;
1201
+ const cursor = absoluteIndex === this.selectedIndex ? this.theme.fg("accent", "›") : " ";
1202
+ const check = row.selected ? this.theme.fg("accent", "[x]") : this.theme.fg("dim", "[ ]");
1203
+ const category = row.category === "G"
1204
+ ? this.theme.fg("accent", "[G]")
1205
+ : row.category === "P"
1206
+ ? this.theme.fg("warning", "[P]")
1207
+ : this.theme.fg("dim", "[E]");
1208
+
1209
+ const baseText = `${cursor} ${check} ${category} ${row.displayName} (${row.displayPath})`;
1210
+ const lineText = absoluteIndex === this.selectedIndex
1211
+ ? this.theme.bg("selectedBg", truncateToWidth(baseText, Math.max(10, safeWidth - 4), ""))
1212
+ : truncateToWidth(baseText, Math.max(10, safeWidth - 4), "");
1213
+ lines.push(this.renderFramedLine(lineText, safeWidth));
1214
+ }
1215
+
1216
+ if (start > 0 || end < filteredRows.length) {
1217
+ lines.push(this.renderFramedLine(this.theme.fg("dim", `Showing ${start + 1}-${end} of ${filteredRows.length}`), safeWidth));
1218
+ }
1219
+
1220
+ lines.push(this.renderFramedLine("", safeWidth));
1221
+ const currentRow = this.getCurrentRow();
1222
+ if (currentRow) {
1223
+ const scopeLabel = currentRow.category === "E"
1224
+ ? "external (read-only)"
1225
+ : currentRow.scope === "project"
1226
+ ? "project"
1227
+ : "global";
1228
+ lines.push(this.renderFramedLine(this.theme.fg("accent", `Focused: ${currentRow.displayName} · ${scopeLabel}`), safeWidth));
1229
+ lines.push(...this.renderWrappedSection([
1230
+ currentRow.description || "(no description)",
1231
+ this.theme.fg("dim", currentRow.skillId),
1232
+ this.theme.fg("dim", currentRow.displayPath),
1233
+ ], safeWidth));
1234
+ }
1235
+ }
1236
+
1237
+ lines.push(this.renderFramedLine("", safeWidth));
1238
+ lines.push(this.renderFramedLine(this.theme.fg("accent", "Last action"), safeWidth));
1239
+ lines.push(...this.renderWrappedSection(this.summaryLines, safeWidth));
1240
+ lines.push(this.renderFramedLine("", safeWidth));
1241
+
1242
+ const help = this.pendingDeleteConfirm
1243
+ ? "Confirm delete: y yes · n no · esc cancel"
1244
+ : this.callbacks.projectName
1245
+ ? "↑↓ move · space select · / search · s sort · f filters · tab switch · g global · p project · d delete · a all · n none · esc close"
1246
+ : "↑↓ move · space select · / search · s sort · f filters · tab switch · g global · p project (disabled) · d delete · a all · n none · esc close";
1247
+ lines.push(this.renderFramedLine(this.theme.fg("dim", help), safeWidth));
1248
+
1249
+ if (this.focusArea === "filters") {
1250
+ lines.push(this.renderFramedLine("", safeWidth));
1251
+ for (const panelLine of this.renderFilterPanel(Math.min(64, safeWidth - 6))) {
1252
+ lines.push(this.renderFramedLine(panelLine, safeWidth));
1253
+ }
1254
+ }
1255
+
1256
+ lines.push(bottom);
1257
+ return lines;
1258
+ }
1259
+ }
1260
+
1261
+ export function registerSkillsCommand(pi: ExtensionAPI, store: SkillStore): void {
1262
+ pi.registerCommand("memory-skills", {
1263
+ description: "Manage global, active-project, and loaded external procedural skills",
1264
+ handler: async (_args, ctx: ExtensionCommandContext) => {
1265
+ const getSkillCommands = (): SkillCommandInfo[] => {
1266
+ const readCommands = (owner: unknown): SkillCommandInfo[] | null => {
1267
+ try {
1268
+ const getter = (owner as { getCommands?: () => unknown })?.getCommands;
1269
+ if (typeof getter !== "function") return null;
1270
+ const commands = getter.call(owner);
1271
+ return Array.isArray(commands) ? commands as SkillCommandInfo[] : [];
1272
+ } catch {
1273
+ return null;
1274
+ }
1275
+ };
1276
+
1277
+ return readCommands(pi)
1278
+ ?? readCommands(ctx)
1279
+ ?? [];
1280
+ };
1281
+
1282
+ const managedSkills = await store.loadIndex();
1283
+ const loadedSkills = collectLoadedSkillsFromCommands(getSkillCommands());
1284
+ const initialRows = buildUnifiedSkillRows(managedSkills, loadedSkills);
1285
+ const projectName = store.getProjectName();
1286
+
1287
+ if (!ctx.hasUI || typeof ctx.ui.custom !== "function") {
1288
+ ctx.ui.notify(formatSkillsList(initialRows, projectName), "info");
1289
+ return;
1290
+ }
1291
+
1292
+ try {
1293
+ await ctx.ui.custom<void>(
1294
+ (tui, theme, _keybindings, done) => new SkillsManagerModal(
1295
+ tui,
1296
+ theme,
1297
+ initialRows,
1298
+ {
1299
+ moveSelected: (scope, skillIds) => moveSelectedSkills(store, skillIds, scope),
1300
+ deleteSelected: (skillIds) => deleteSelectedSkills(store, skillIds),
1301
+ close: () => done(undefined),
1302
+ projectName,
1303
+ },
1304
+ {
1305
+ managedSkills,
1306
+ loadedSkills,
1307
+ },
1308
+ ),
1309
+ {
1310
+ overlay: true,
1311
+ overlayOptions: {
1312
+ anchor: "center",
1313
+ width: "92%",
1314
+ minWidth: 76,
1315
+ maxHeight: "88%",
1316
+ margin: 1,
1317
+ },
1318
+ },
1319
+ );
1320
+ } catch {
1321
+ const latestManagedSkills = await store.loadIndex();
1322
+ const latestRows = buildUnifiedSkillRows(
1323
+ latestManagedSkills,
1324
+ collectLoadedSkillsFromCommands(getSkillCommands()),
1325
+ );
1326
+ ctx.ui.notify(
1327
+ "Interactive skills manager unavailable in this runtime; showing read-only list fallback.",
1328
+ "warning",
1329
+ );
1330
+ ctx.ui.notify(formatSkillsList(latestRows, projectName), "info");
1331
+ }
1332
+ },
1333
+ });
1334
+ }