@pi-unipi/unipi 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (359) hide show
  1. package/CHANGELOG.md +292 -0
  2. package/README.md +8 -11
  3. package/docs/prefix-cache-architecture.md +14 -0
  4. package/package.json +22 -24
  5. package/packages/ask-user/README.md +55 -107
  6. package/packages/ask-user/ask-ui.ts +306 -732
  7. package/packages/ask-user/clipboard.ts +50 -0
  8. package/packages/ask-user/config.ts +74 -78
  9. package/packages/ask-user/package.json +2 -2
  10. package/packages/ask-user/questions.ts +151 -0
  11. package/packages/ask-user/skills/ask-user/SKILL.md +59 -133
  12. package/packages/ask-user/tools.ts +198 -432
  13. package/packages/autocomplete/package.json +1 -1
  14. package/packages/autocomplete/src/constants.ts +38 -43
  15. package/packages/autocomplete/src/sorting.ts +8 -0
  16. package/packages/background-tasks/package.json +2 -2
  17. package/packages/background-tasks/src/config.ts +0 -73
  18. package/packages/background-tasks/src/index.ts +20 -16
  19. package/packages/background-tasks/src/registry.ts +1 -171
  20. package/packages/background-tasks/src/types.ts +0 -32
  21. package/packages/btw/README.md +13 -56
  22. package/packages/btw/extensions/btw.ts +403 -1796
  23. package/packages/btw/package.json +5 -2
  24. package/packages/btw/skills/btw/SKILL.md +7 -143
  25. package/packages/compactor/README.md +56 -287
  26. package/packages/compactor/package.json +5 -9
  27. package/packages/compactor/skills/compactor/SKILL.md +13 -20
  28. package/packages/compactor/src/card.ts +90 -0
  29. package/packages/compactor/src/commands/index.ts +73 -130
  30. package/packages/compactor/src/compaction/compact-args.ts +5 -3
  31. package/packages/compactor/src/compaction/filter-noise.ts +1 -1
  32. package/packages/compactor/src/compaction/hooks.ts +487 -311
  33. package/packages/compactor/src/compaction/source.ts +178 -0
  34. package/packages/compactor/src/compaction/summarize.ts +586 -52
  35. package/packages/compactor/src/config/manager.ts +130 -127
  36. package/packages/compactor/src/config/schema.ts +32 -48
  37. package/packages/compactor/src/index.ts +40 -431
  38. package/packages/compactor/src/info-screen.ts +44 -190
  39. package/packages/compactor/src/session/recall-blocks.ts +1 -1
  40. package/packages/compactor/src/stats.ts +76 -0
  41. package/packages/compactor/src/tools/context-budget.ts +17 -34
  42. package/packages/compactor/src/tools/ctx-doctor.ts +45 -36
  43. package/packages/compactor/src/tools/register.ts +29 -269
  44. package/packages/compactor/src/types.ts +47 -186
  45. package/packages/core/README.md +25 -0
  46. package/packages/core/child-agent.ts +1 -0
  47. package/packages/core/command-echo.ts +63 -0
  48. package/packages/core/compaction-context.ts +41 -0
  49. package/packages/core/constants.ts +8 -38
  50. package/packages/core/events.ts +0 -53
  51. package/packages/core/fusion-status.ts +4 -0
  52. package/packages/core/global.d.ts +10 -0
  53. package/packages/core/harness-messages.ts +392 -0
  54. package/packages/core/index.ts +14 -0
  55. package/packages/core/kanboard-status.ts +49 -0
  56. package/packages/core/long-horizon-owner-status.ts +46 -0
  57. package/packages/core/model-cache.ts +81 -7
  58. package/packages/core/package.json +6 -3
  59. package/packages/core/src/attach/detect.ts +163 -0
  60. package/packages/core/src/child-agent/child-args.ts +31 -0
  61. package/packages/core/src/child-agent/delivery.ts +41 -0
  62. package/packages/core/src/child-agent/index.ts +5 -0
  63. package/packages/core/src/child-agent/readers.ts +203 -0
  64. package/packages/core/src/child-agent/runtime.ts +584 -0
  65. package/packages/core/src/evidence.ts +78 -0
  66. package/packages/core/src/hints/browser.ts +278 -0
  67. package/packages/core/src/hints/crab-data.ts +19 -0
  68. package/packages/core/src/hints/index.ts +865 -0
  69. package/packages/core/src/hints/lines.ts +607 -0
  70. package/packages/core/src/hints/store.ts +120 -0
  71. package/packages/core/src/jev/chatter.ts +24 -0
  72. package/packages/core/src/jev/settings.ts +177 -14
  73. package/packages/core/src/package-colors.ts +2 -0
  74. package/packages/core/src/settings/catalog.ts +39 -15
  75. package/packages/core/src/settings/engine.ts +48 -2
  76. package/packages/core/src/settings/hub.ts +83 -20
  77. package/packages/core/src/settings/open.ts +49 -0
  78. package/packages/core/src/settings/schema.ts +27 -7
  79. package/packages/core/src/tui/hub-kit.ts +18 -5
  80. package/packages/core/src/tui/kit.ts +198 -0
  81. package/packages/core/src/tui/progress.ts +73 -0
  82. package/packages/core/src/turn/arbiter.ts +290 -0
  83. package/packages/footer/README.md +4 -6
  84. package/packages/footer/package.json +3 -3
  85. package/packages/footer/src/glance-editor.ts +19 -11
  86. package/packages/footer/src/help.ts +1 -1
  87. package/packages/footer/src/index.ts +36 -3
  88. package/packages/footer/src/presets.ts +3 -4
  89. package/packages/footer/src/rendering/icons.ts +0 -20
  90. package/packages/footer/src/segments/compactor.ts +52 -142
  91. package/packages/footer/src/segments/status-ext.ts +0 -1
  92. package/packages/fusion/README.md +14 -4
  93. package/packages/fusion/package.json +4 -3
  94. package/packages/fusion/src/child-args.ts +1 -0
  95. package/packages/fusion/src/index.ts +161 -8
  96. package/packages/fusion/src/pi-settings.ts +57 -0
  97. package/packages/fusion/src/picker.ts +186 -51
  98. package/packages/fusion/src/preset.ts +56 -2
  99. package/packages/fusion/src/prompts.ts +1 -1
  100. package/packages/fusion/src/sidekick-runtime.ts +1 -420
  101. package/packages/fusion/src/tools.ts +107 -128
  102. package/packages/fusion/src/transcript.ts +27 -85
  103. package/packages/info-screen/package.json +2 -2
  104. package/packages/input-shortcuts/README.md +18 -30
  105. package/packages/input-shortcuts/package.json +2 -2
  106. package/packages/input-shortcuts/src/burst.ts +88 -0
  107. package/packages/input-shortcuts/src/chord-overlay.ts +20 -70
  108. package/packages/input-shortcuts/src/cleared-input.ts +97 -0
  109. package/packages/input-shortcuts/src/index.ts +99 -193
  110. package/packages/input-shortcuts/src/last-response.ts +40 -0
  111. package/packages/input-shortcuts/src/registers.ts +8 -23
  112. package/packages/input-shortcuts/src/types.ts +4 -16
  113. package/packages/input-shortcuts/src/undo-redo.ts +59 -47
  114. package/packages/kanboard/README.md +51 -47
  115. package/packages/kanboard/index.ts +293 -55
  116. package/packages/kanboard/package.json +8 -8
  117. package/packages/kanboard/skills/kanboard/SKILL.md +61 -27
  118. package/packages/kanboard/src/badges.ts +93 -0
  119. package/packages/kanboard/src/bin.ts +4 -2
  120. package/packages/kanboard/src/commands.ts +218 -84
  121. package/packages/kanboard/src/debug.ts +20 -0
  122. package/packages/kanboard/src/guard.ts +267 -109
  123. package/packages/kanboard/src/monitor.ts +330 -0
  124. package/packages/kanboard/src/notice-buffer.ts +74 -0
  125. package/packages/kanboard/src/progress.ts +27 -0
  126. package/packages/kanboard/src/reminders.ts +234 -0
  127. package/packages/kanboard/src/settings.ts +69 -15
  128. package/packages/kanboard/src/shapes.ts +5 -0
  129. package/packages/long-horizon/index.ts +190 -13
  130. package/packages/long-horizon/package.json +3 -3
  131. package/packages/long-horizon/src/commands.ts +103 -7
  132. package/packages/long-horizon/src/compaction-brief.ts +35 -0
  133. package/packages/long-horizon/src/engine/continuation.ts +84 -15
  134. package/packages/long-horizon/src/engine/goal-state.ts +64 -13
  135. package/packages/long-horizon/src/engine/nudge-stash.ts +71 -0
  136. package/packages/long-horizon/src/engine/ralph.ts +3 -2
  137. package/packages/long-horizon/src/engine/runaway.ts +68 -11
  138. package/packages/long-horizon/src/engine/verifier.ts +19 -0
  139. package/packages/long-horizon/src/gate.ts +37 -12
  140. package/packages/long-horizon/src/judge/resolve.ts +1 -0
  141. package/packages/long-horizon/src/owner.ts +35 -2
  142. package/packages/long-horizon/src/progress.ts +87 -0
  143. package/packages/long-horizon/src/prompts/goal.ts +1 -1
  144. package/packages/long-horizon/src/runtime.ts +172 -18
  145. package/packages/long-horizon/src/settings.ts +54 -39
  146. package/packages/long-horizon/src/tools/goal.ts +6 -0
  147. package/packages/long-horizon/src/tools/graph.ts +1 -1
  148. package/packages/long-horizon/src/tools/swarm.ts +3 -3
  149. package/packages/mcp/package.json +2 -2
  150. package/packages/memory/commands.ts +7 -2
  151. package/packages/memory/index.ts +210 -32
  152. package/packages/memory/package.json +3 -3
  153. package/packages/memory/save-session.ts +264 -0
  154. package/packages/memory/settings.ts +17 -0
  155. package/packages/memory/tools.ts +253 -203
  156. package/packages/notify/package.json +2 -2
  157. package/packages/skill-registry/README.md +53 -16
  158. package/packages/skill-registry/index.ts +230 -0
  159. package/packages/skill-registry/package.json +19 -8
  160. package/packages/skill-registry/src/editor.ts +206 -0
  161. package/packages/skill-registry/src/judge.ts +289 -0
  162. package/packages/skill-registry/src/registry.ts +87 -0
  163. package/packages/skill-registry/src/settings.ts +259 -0
  164. package/packages/skill-registry/src/vault.ts +80 -0
  165. package/packages/subagents/README.md +39 -119
  166. package/packages/subagents/package.json +6 -13
  167. package/packages/subagents/skills/subagents/SKILL.md +18 -42
  168. package/packages/subagents/src/agents.ts +213 -0
  169. package/packages/subagents/src/cards.ts +182 -0
  170. package/packages/subagents/src/index.ts +609 -1084
  171. package/packages/subagents/src/manager.ts +429 -0
  172. package/packages/subagents/src/profiles.ts +130 -0
  173. package/packages/subagents/src/transcript.ts +154 -0
  174. package/packages/subagents/src/ui.ts +389 -0
  175. package/packages/unipi/bundled.js +39756 -45569
  176. package/packages/unipi/index.ts +55 -10
  177. package/packages/updater/package.json +2 -2
  178. package/packages/utility/README.md +76 -69
  179. package/packages/utility/package.json +2 -2
  180. package/packages/utility/skills/image/SKILL.md +37 -0
  181. package/packages/utility/skills/utility/SKILL.md +17 -60
  182. package/packages/utility/src/answer/extract.ts +128 -0
  183. package/packages/utility/src/answer/index.ts +213 -0
  184. package/packages/utility/src/answer/reply.ts +133 -0
  185. package/packages/utility/src/answer/web.ts +167 -0
  186. package/packages/utility/src/attach/index.ts +205 -0
  187. package/packages/utility/src/commands.ts +38 -142
  188. package/packages/utility/src/diagnostics/engine.ts +50 -5
  189. package/packages/utility/src/image/index.ts +33 -0
  190. package/packages/utility/src/image/models.ts +221 -0
  191. package/packages/{image/src → utility/src/image}/recognize.ts +2 -2
  192. package/packages/utility/src/image/settings.ts +178 -0
  193. package/packages/{image/src/image-source.ts → utility/src/image/source.ts} +1 -1
  194. package/packages/utility/src/image/tools.ts +168 -0
  195. package/packages/utility/src/image/transports.ts +186 -0
  196. package/packages/utility/src/index.ts +68 -389
  197. package/packages/utility/src/lifecycle/cleanup.ts +116 -311
  198. package/packages/utility/src/rename/gate.ts +102 -0
  199. package/packages/utility/src/rename/index.ts +191 -0
  200. package/packages/utility/src/rename/session.ts +170 -0
  201. package/packages/utility/src/render/delegated.ts +285 -0
  202. package/packages/utility/src/render/harness.ts +683 -0
  203. package/packages/utility/src/render/parse.ts +156 -0
  204. package/packages/utility/src/render/pi-settings.ts +38 -0
  205. package/packages/utility/src/render/reply-bg.ts +307 -0
  206. package/packages/utility/src/render/simple.ts +724 -0
  207. package/packages/utility/src/render/spacing.ts +235 -0
  208. package/packages/utility/src/render/styled.ts +251 -0
  209. package/packages/utility/src/render/tools.ts +353 -0
  210. package/packages/utility/src/settings.ts +166 -233
  211. package/packages/utility/src/types.ts +1 -222
  212. package/packages/watchdog/index.ts +17 -6
  213. package/packages/watchdog/package.json +3 -3
  214. package/packages/watchdog/src/config.ts +3 -2
  215. package/packages/web-api/package.json +2 -2
  216. package/packages/workflow/README.md +3 -0
  217. package/packages/workflow/index.ts +0 -2
  218. package/packages/workflow/package.json +2 -2
  219. package/packages/workflow/src/permission/decide.ts +6 -4
  220. package/packages/workflow/src/permission/index.ts +17 -7
  221. package/packages/workflow/src/permission/settings.ts +39 -4
  222. package/packages/workflow/src/plan/index.ts +19 -4
  223. package/packages/background-tasks/extensions/delegate-child.ts +0 -1
  224. package/packages/background-tasks/src/context-parent-snapshot.ts +0 -142
  225. package/packages/background-tasks/src/context-token-budget.ts +0 -903
  226. package/packages/background-tasks/src/context-visible-conversation-v2.ts +0 -551
  227. package/packages/background-tasks/src/delegate/artifacts.ts +0 -487
  228. package/packages/background-tasks/src/delegate/budget.ts +0 -415
  229. package/packages/background-tasks/src/delegate/hook-contract-evidence.json +0 -18
  230. package/packages/background-tasks/src/delegate/hook-contract.ts +0 -154
  231. package/packages/background-tasks/src/delegate/launch.ts +0 -484
  232. package/packages/background-tasks/src/delegate/result-package.ts +0 -459
  233. package/packages/background-tasks/src/delegate/runner.ts +0 -430
  234. package/packages/background-tasks/src/delegate/seed.ts +0 -423
  235. package/packages/background-tasks/src/delegate/types.ts +0 -323
  236. package/packages/background-tasks/src/delegate-child-extension.ts +0 -978
  237. package/packages/background-tasks/src/delegate-extension.ts +0 -654
  238. package/packages/background-tasks/src/fixtures/delegate-context-incident.json +0 -17
  239. package/packages/compactor/skills/compactor-detail/SKILL.md +0 -116
  240. package/packages/compactor/skills/compactor-doctor/SKILL.md +0 -71
  241. package/packages/compactor/skills/compactor-stats/SKILL.md +0 -51
  242. package/packages/compactor/src/compaction/build-sections.ts +0 -76
  243. package/packages/compactor/src/compaction/extract/goals.ts +0 -36
  244. package/packages/compactor/src/compaction/extract/preferences.ts +0 -40
  245. package/packages/compactor/src/compaction/format.ts +0 -53
  246. package/packages/compactor/src/compaction/merge.ts +0 -143
  247. package/packages/compactor/src/config/presets.ts +0 -160
  248. package/packages/compactor/src/executor/executor.ts +0 -233
  249. package/packages/compactor/src/executor/runtime.ts +0 -115
  250. package/packages/compactor/src/security/evaluator.ts +0 -89
  251. package/packages/compactor/src/security/policy.ts +0 -96
  252. package/packages/compactor/src/security/scanner.ts +0 -65
  253. package/packages/compactor/src/session/auto-inject.ts +0 -60
  254. package/packages/compactor/src/session/db.ts +0 -325
  255. package/packages/compactor/src/session/extract.ts +0 -144
  256. package/packages/compactor/src/session/resume-inject.ts +0 -64
  257. package/packages/compactor/src/session/snapshot.ts +0 -327
  258. package/packages/compactor/src/tools/ctx-batch-execute.ts +0 -41
  259. package/packages/compactor/src/tools/ctx-execute-file.ts +0 -23
  260. package/packages/compactor/src/tools/ctx-execute.ts +0 -23
  261. package/packages/compactor/src/tools/ctx-stats.ts +0 -96
  262. package/packages/image/README.md +0 -99
  263. package/packages/image/package.json +0 -61
  264. package/packages/image/skills/image/SKILL.md +0 -76
  265. package/packages/image/src/generate.ts +0 -256
  266. package/packages/image/src/index.ts +0 -135
  267. package/packages/image/src/models.ts +0 -519
  268. package/packages/image/src/openai-images-api.ts +0 -282
  269. package/packages/image/src/register-providers.ts +0 -209
  270. package/packages/image/src/settings.ts +0 -173
  271. package/packages/image/src/tools.ts +0 -326
  272. package/packages/input-shortcuts/src/clipboard.ts +0 -119
  273. package/packages/kanboard/src/runner.ts +0 -817
  274. package/packages/skill-registry/skills/auto/SKILL.md +0 -465
  275. package/packages/skill-registry/skills/brainstorm/SKILL.md +0 -219
  276. package/packages/skill-registry/skills/chore-create/SKILL.md +0 -315
  277. package/packages/skill-registry/skills/chore-execute/SKILL.md +0 -314
  278. package/packages/skill-registry/skills/consolidate/SKILL.md +0 -142
  279. package/packages/skill-registry/skills/consultant/SKILL.md +0 -97
  280. package/packages/skill-registry/skills/debug/SKILL.md +0 -228
  281. package/packages/skill-registry/skills/document/SKILL.md +0 -120
  282. package/packages/skill-registry/skills/fix/SKILL.md +0 -212
  283. package/packages/skill-registry/skills/gather-context/SKILL.md +0 -145
  284. package/packages/skill-registry/skills/plan/SKILL.md +0 -231
  285. package/packages/skill-registry/skills/quick-fix/SKILL.md +0 -135
  286. package/packages/skill-registry/skills/quick-work/SKILL.md +0 -110
  287. package/packages/skill-registry/skills/research/SKILL.md +0 -251
  288. package/packages/skill-registry/skills/review-work/SKILL.md +0 -187
  289. package/packages/skill-registry/skills/scan-issues/SKILL.md +0 -195
  290. package/packages/skill-registry/skills/work/SKILL.md +0 -218
  291. package/packages/skill-registry/skills/worktree-create/SKILL.md +0 -69
  292. package/packages/skill-registry/skills/worktree-list/SKILL.md +0 -78
  293. package/packages/skill-registry/skills/worktree-merge/SKILL.md +0 -89
  294. package/packages/subagents/agents/delegate.md +0 -14
  295. package/packages/subagents/agents/oracle.md +0 -78
  296. package/packages/subagents/agents/researcher.md +0 -52
  297. package/packages/subagents/agents/reviewer.md +0 -80
  298. package/packages/subagents/agents/scout.md +0 -50
  299. package/packages/subagents/agents/worker.md +0 -59
  300. package/packages/subagents/prompts/council.md +0 -48
  301. package/packages/subagents/prompts/gather-context-and-clarify.md +0 -13
  302. package/packages/subagents/prompts/parallel-cleanup.md +0 -59
  303. package/packages/subagents/prompts/parallel-research.md +0 -50
  304. package/packages/subagents/prompts/parallel-review.md +0 -54
  305. package/packages/subagents/prompts/review-loop.md +0 -43
  306. package/packages/subagents/skills/council-mode/SKILL.md +0 -230
  307. package/packages/subagents/skills/subagents/references/constraints-and-recipes.md +0 -259
  308. package/packages/subagents/skills/subagents/references/execution-controls.md +0 -454
  309. package/packages/subagents/skills/subagents/references/management-authoring-rpc.md +0 -161
  310. package/packages/subagents/skills/subagents/references/multi-lane-orchestration.md +0 -39
  311. package/packages/subagents/skills/subagents/references/prompting-and-roles.md +0 -267
  312. package/packages/subagents/src/acceptance.ts +0 -331
  313. package/packages/subagents/src/agent-manager.ts +0 -405
  314. package/packages/subagents/src/agent-memory.ts +0 -300
  315. package/packages/subagents/src/agent-overrides.ts +0 -183
  316. package/packages/subagents/src/agent-runner.ts +0 -271
  317. package/packages/subagents/src/async-runner.ts +0 -422
  318. package/packages/subagents/src/authority-policy.ts +0 -47
  319. package/packages/subagents/src/budgets.ts +0 -285
  320. package/packages/subagents/src/child-safety.ts +0 -140
  321. package/packages/subagents/src/config.ts +0 -249
  322. package/packages/subagents/src/conversation-viewer.ts +0 -281
  323. package/packages/subagents/src/core-compat.ts +0 -94
  324. package/packages/subagents/src/custom-agents.ts +0 -343
  325. package/packages/subagents/src/file-system-retry.ts +0 -50
  326. package/packages/subagents/src/fleet-data.ts +0 -105
  327. package/packages/subagents/src/fleet-view.ts +0 -322
  328. package/packages/subagents/src/foreground-detach.ts +0 -59
  329. package/packages/subagents/src/fork-context.ts +0 -285
  330. package/packages/subagents/src/global.d.ts +0 -7
  331. package/packages/subagents/src/guide.ts +0 -129
  332. package/packages/subagents/src/mission-state.ts +0 -133
  333. package/packages/subagents/src/mission-store.ts +0 -436
  334. package/packages/subagents/src/output-limits.ts +0 -142
  335. package/packages/subagents/src/parity-types.ts +0 -315
  336. package/packages/subagents/src/pi-args.ts +0 -167
  337. package/packages/subagents/src/result-files.ts +0 -232
  338. package/packages/subagents/src/result-watcher.ts +0 -221
  339. package/packages/subagents/src/retained-children.ts +0 -176
  340. package/packages/subagents/src/run-fanout-budget.ts +0 -356
  341. package/packages/subagents/src/scheduled-runs.ts +0 -349
  342. package/packages/subagents/src/schemas.ts +0 -263
  343. package/packages/subagents/src/slash-commands.ts +0 -80
  344. package/packages/subagents/src/supervisor-channel.ts +0 -249
  345. package/packages/subagents/src/tool-handler.ts +0 -1144
  346. package/packages/subagents/src/types.ts +0 -238
  347. package/packages/subagents/src/widget.ts +0 -457
  348. package/packages/subagents/src/workflow-script.ts +0 -737
  349. package/packages/subagents/src/workflow-worker.ts +0 -384
  350. package/packages/subagents/src/worktree.ts +0 -614
  351. package/packages/utility/src/analytics/collector.ts +0 -293
  352. package/packages/utility/src/info-screen.ts +0 -80
  353. package/packages/utility/src/lifecycle/process.ts +0 -162
  354. package/packages/utility/src/prefix-cache.ts +0 -263
  355. package/packages/utility/src/skill-discovery.ts +0 -542
  356. package/packages/utility/src/tools/env.ts +0 -113
  357. package/packages/utility/src/tui/name-badge-state.ts +0 -315
  358. package/packages/utility/src/tui/name-badge.ts +0 -109
  359. /package/packages/{subagents/src → core/src/child-agent}/pi-spawn.ts +0 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Hint store — ~/.unipi/global/hints/hints.json, write-through JSON.
3
+ *
4
+ * Persists show counts, learned hints, and last seen unipi version:
5
+ * {
6
+ * "counts": { "<hintId>": { "count": 2, "last": 1730000000000 } },
7
+ * "learned": ["utility.settings-hub"],
8
+ * "lastSeenVersion": "3.0.0-alpha.20"
9
+ * }
10
+ */
11
+
12
+ import { readFileSync, writeFileSync, unlinkSync } from "node:fs";
13
+ import { statePath } from "../workspace/paths.js";
14
+
15
+ export interface HintRecord {
16
+ count: number;
17
+ last: number;
18
+ }
19
+
20
+ export interface HintStoreData {
21
+ counts: Record<string, HintRecord>;
22
+ learned: string[];
23
+ lastSeenVersion?: string;
24
+ }
25
+
26
+ let cache: HintStoreData | null = null;
27
+
28
+ function emptyStore(): HintStoreData {
29
+ return {
30
+ counts: {},
31
+ learned: [],
32
+ lastSeenVersion: undefined,
33
+ };
34
+ }
35
+
36
+ export function loadHintStore(): HintStoreData {
37
+ if (cache) return cache;
38
+ try {
39
+ const raw = readFileSync(statePath("hints", "hints.json", "global"), "utf-8");
40
+ const parsed = JSON.parse(raw);
41
+ if (typeof parsed === "object" && parsed !== null) {
42
+ cache = {
43
+ counts: (typeof parsed.counts === "object" && parsed.counts !== null ? parsed.counts : {}) as Record<string, HintRecord>,
44
+ learned: Array.isArray(parsed.learned) ? parsed.learned : [],
45
+ lastSeenVersion: typeof parsed.lastSeenVersion === "string" ? parsed.lastSeenVersion : undefined,
46
+ };
47
+ } else {
48
+ cache = emptyStore();
49
+ }
50
+ } catch {
51
+ cache = emptyStore();
52
+ }
53
+ return cache;
54
+ }
55
+
56
+ function saveStore(): void {
57
+ if (!cache) return;
58
+ try {
59
+ writeFileSync(statePath("hints", "hints.json", "global"), JSON.stringify(cache, null, 2));
60
+ } catch {
61
+ // best-effort
62
+ }
63
+ }
64
+
65
+ export function recordHintShow(id: string): void {
66
+ const store = loadHintStore();
67
+ const prev = store.counts[id];
68
+ store.counts[id] = { count: (prev?.count ?? 0) + 1, last: Date.now() };
69
+ saveStore();
70
+ }
71
+
72
+ export function recordHintLearned(id: string): void {
73
+ const store = loadHintStore();
74
+ if (!store.learned.includes(id)) {
75
+ store.learned.push(id);
76
+ saveStore();
77
+ }
78
+ }
79
+
80
+ export function isHintLearned(id: string): boolean {
81
+ const store = loadHintStore();
82
+ return store.learned.includes(id);
83
+ }
84
+
85
+ export function setLastSeenVersion(version: string): void {
86
+ const store = loadHintStore();
87
+ store.lastSeenVersion = version;
88
+ saveStore();
89
+ }
90
+
91
+ export function getLastSeenVersion(): string | undefined {
92
+ const store = loadHintStore();
93
+ return store.lastSeenVersion;
94
+ }
95
+
96
+ export function resetHintHistory(): void {
97
+ const store = loadHintStore();
98
+ store.counts = {};
99
+ store.learned = [];
100
+ try {
101
+ writeFileSync(statePath("hints", "hints.json", "global"), JSON.stringify(store, null, 2));
102
+ } catch {
103
+ // best effort
104
+ }
105
+ }
106
+
107
+ /** Clear disk file and cached store completely (e.g. for testing clean slate). */
108
+ export function clearHintStoreFile(): void {
109
+ cache = null;
110
+ try {
111
+ unlinkSync(statePath("hints", "hints.json", "global"));
112
+ } catch {
113
+ // absent file is already clear
114
+ }
115
+ }
116
+
117
+ /** Test hook: drop memoized store so next call re-reads disk. */
118
+ export function resetHintStoreCache(): void {
119
+ cache = null;
120
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Chatter detection shared by jev consumers (auto-rename, skill judging):
3
+ * greetings, thanks, acknowledgements and bare "continue"-style nudges carry
4
+ * no subject, so no decision should be made from them.
5
+ */
6
+
7
+ const CHATTER = new RegExp(
8
+ "^(?:" + [
9
+ "h(?:i|ello|ey|owdy)(?: there)?", "yo", "sup", "good (?:morning|afternoon|evening)",
10
+ "thanks?(?: you)?(?: so much)?", "thx", "ty", "cheers", "nice", "great", "cool", "perfect", "awesome",
11
+ "ok(?:ay)?", "k", "yes", "yep", "yeah", "no", "nope", "sure", "lgtm", "sounds good", "go(?: on| ahead)?",
12
+ "continue", "proceed", "retry", "again", "do it", "next", "done",
13
+ ].join("|") + ")[\\s.!?,]*$",
14
+ "i",
15
+ );
16
+
17
+ /** True for messages with no subject of their own (no jev call needed). */
18
+ export function isChatter(text: string): boolean {
19
+ const t = text.trim();
20
+ if (t.length < 3) return true;
21
+ if (t.startsWith("/")) return true;
22
+ return CHATTER.test(t);
23
+ }
24
+
@@ -1,23 +1,186 @@
1
1
  /**
2
- * Jev settings source — reads the long-horizon Decision-model settings from
3
- * the engine so every jev consumer (mode router, skill exposure, watchdog)
4
- * shares one provider/model/key/baseUrl configuration.
2
+ * Decision Model — one shared setting for the fast calibrated classifier
3
+ * (TypeSafe jev today) that several modules consult: long-horizon mode
4
+ * routing, permission auto-judging, skill exposure, the watchdog, kanboard
5
+ * strategy choice and compactor pruning.
6
+ *
7
+ * The model lives in its own settings namespace ("decision-model"), not in
8
+ * any consumer, so a different decision model can be adopted in one place.
9
+ * Each consumer carries a `decisionModel` block: `source: "inherit"` (the
10
+ * default) uses the shared model; `source: "custom"` overrides provider,
11
+ * model, base URL, key or timeout for that consumer only (empty fields fall
12
+ * back to the shared value).
5
13
  */
6
14
 
7
- import { getSettings } from "../settings/engine.js";
15
+ import { getSettings, getSettingsScoped, registerSettings, setSettings } from "../settings/engine.js";
16
+ import type { SettingsField, SettingsSection } from "../settings/schema.js";
17
+ import { globalSettingsPath } from "../settings/paths.js";
8
18
  import type { JevSettings } from "./client.js";
9
19
 
10
- /** Read the Decision-model settings (long-horizon judge) as JevSettings. */
11
- export function readJudgeJevSettings(cwd: string): JevSettings {
12
- const raw = getSettings("long-horizon", cwd) as {
13
- judge?: Record<string, unknown>;
20
+ export const DECISION_MODEL_NAMESPACE = "decision-model";
21
+
22
+ export type DecisionProvider = JevSettings["provider"];
23
+
24
+ export interface DecisionModelSettings {
25
+ provider: DecisionProvider;
26
+ model: string;
27
+ baseUrl: string;
28
+ apiKey: string;
29
+ timeoutMs: number;
30
+ }
31
+
32
+ export interface DecisionModelOverride extends DecisionModelSettings {
33
+ source: "inherit" | "custom";
34
+ }
35
+
36
+ export const DEFAULT_DECISION_MODEL: DecisionModelSettings = {
37
+ provider: "openrouter",
38
+ model: "typesafe/jev-1.13",
39
+ baseUrl: "",
40
+ apiKey: "",
41
+ timeoutMs: 0,
42
+ };
43
+
44
+ /** The per-consumer block's defaults: inherit, custom fields empty. */
45
+ export const DEFAULT_DECISION_OVERRIDE: DecisionModelOverride = {
46
+ source: "inherit",
47
+ provider: "openrouter",
48
+ model: "",
49
+ baseUrl: "",
50
+ apiKey: "",
51
+ timeoutMs: 0,
52
+ };
53
+
54
+ const PROVIDER_OPTIONS = [
55
+ { value: "openrouter", label: "openrouter (decisions endpoint)" },
56
+ { value: "typesafe", label: "typesafe (native systemone)" },
57
+ { value: "custom", label: "custom (Base URL + API key)" },
58
+ ] as const;
59
+
60
+ const MODEL_PRESETS = {
61
+ typesafe: ["jev-latest"],
62
+ openrouter: ["typesafe/jev-1.13"],
63
+ custom: ["typesafe/jev-1.13"],
64
+ } as const;
65
+
66
+ /** Provider / model / base URL / key / timeout fields under a key prefix. */
67
+ function modelFields(prefix: string, emptyModel?: string): SettingsField[] {
68
+ const k = (name: string) => (prefix ? `${prefix}.${name}` : name);
69
+ return [
70
+ { key: k("provider"), type: "enum", label: "Provider", options: PROVIDER_OPTIONS, description: "openrouter = decisions endpoint · typesafe = native systemone · custom = your own gateway" },
71
+ {
72
+ key: k("model"),
73
+ type: "model",
74
+ label: "Model",
75
+ description: "A decision (classifier) model — jev; custom… for others",
76
+ providerKey: k("provider"),
77
+ presetsByProvider: MODEL_PRESETS,
78
+ ...(emptyModel ? { emptyLabel: emptyModel, emptyOption: emptyModel } : {}),
79
+ },
80
+ { key: k("baseUrl"), type: "string", label: "Base URL", description: "Required when provider = custom", emptyLabel: "provider default" },
81
+ { key: k("apiKey"), type: "secret", label: "API key", description: "A stored key wins over the environment (OPENROUTER_API_KEY / TYPESAFE_API_KEY)", emptyLabel: "environment" },
82
+ { key: k("timeoutMs"), type: "number", label: "Timeout ms", min: 0, zeroLabel: "auto (1s native / 6s decisions)" },
83
+ ];
84
+ }
85
+
86
+ registerSettings({
87
+ namespace: DECISION_MODEL_NAMESPACE,
88
+ label: "Decision Model",
89
+ defaults: DEFAULT_DECISION_MODEL as unknown as Record<string, unknown>,
90
+ schema: [
91
+ {
92
+ title: "Decision model",
93
+ description:
94
+ "A fast calibrated classifier used for mode routing, permission judging, skill exposure, the watchdog, kanboard strategy and compaction pruning. Each of those can inherit this or use its own.",
95
+ fields: modelFields(""),
96
+ },
97
+ ],
98
+ });
99
+
100
+ /**
101
+ * The hub section a consumer adds to its own settings: inherit the shared
102
+ * Decision Model, or use a custom one (fields empty = shared value).
103
+ */
104
+ export function decisionModelSection(opts: { title?: string; advanced?: boolean } = {}): SettingsSection {
105
+ return {
106
+ title: opts.title ?? "Decision model",
107
+ description: "inherit = the shared Decision Model settings · custom = override below for this module only (empty = shared value)",
108
+ advanced: opts.advanced ?? true,
109
+ fields: [
110
+ {
111
+ key: "decisionModel.source",
112
+ type: "enum",
113
+ label: "Decision model",
114
+ options: [
115
+ { value: "inherit", label: "inherit (Decision Model settings)" },
116
+ { value: "custom", label: "custom" },
117
+ ],
118
+ },
119
+ ...modelFields("decisionModel", "shared model"),
120
+ ],
14
121
  };
15
- const j = raw?.judge ?? {};
122
+ }
123
+
124
+ const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
125
+
126
+ function normalize(raw: Record<string, unknown>, fallback: DecisionModelSettings): DecisionModelSettings {
127
+ const provider: DecisionProvider =
128
+ raw.provider === "typesafe" || raw.provider === "custom" || raw.provider === "openrouter" ? raw.provider : fallback.provider;
129
+ const str = (v: unknown, dflt: string) => (typeof v === "string" && v.trim() ? v.trim() : dflt);
130
+ const model = str(raw.model, provider === fallback.provider ? fallback.model : provider === "typesafe" ? "jev-latest" : "typesafe/jev-1.13");
16
131
  return {
17
- provider: j.provider === "typesafe" ? "typesafe" : "openrouter",
18
- model: typeof j.model === "string" ? j.model : "",
19
- baseUrl: typeof j.baseUrl === "string" ? j.baseUrl : "",
20
- apiKey: typeof j.apiKey === "string" ? j.apiKey : "",
21
- timeoutMs: typeof j.timeoutMs === "number" ? j.timeoutMs : 0,
132
+ provider,
133
+ model,
134
+ baseUrl: str(raw.baseUrl, fallback.baseUrl),
135
+ apiKey: str(raw.apiKey, fallback.apiKey),
136
+ timeoutMs: typeof raw.timeoutMs === "number" && raw.timeoutMs > 0 ? raw.timeoutMs : fallback.timeoutMs,
22
137
  };
23
138
  }
139
+
140
+ /** Latched per global settings file (one per HOME), not per process. */
141
+ const migrated = new Set<string>();
142
+
143
+ /**
144
+ * One-time move of the pre-namespace settings (long-horizon `judge.*`
145
+ * transport fields) into "decision-model". Additive: long-horizon keeps its
146
+ * copy; runs only while the decision-model global file does not exist.
147
+ */
148
+ export function migrateLegacyDecisionModel(cwd: string): void {
149
+ const target = globalSettingsPath(DECISION_MODEL_NAMESPACE);
150
+ if (migrated.has(target)) return;
151
+ migrated.add(target);
152
+ try {
153
+ if (getSettingsScoped(DECISION_MODEL_NAMESPACE, "global", cwd)) return;
154
+ const judge = getSettingsScoped("long-horizon", "global", cwd)?.judge;
155
+ if (!isRecord(judge)) return;
156
+ const patch: Record<string, unknown> = {};
157
+ for (const key of ["provider", "model", "baseUrl", "apiKey", "timeoutMs"]) {
158
+ if (judge[key] !== undefined && judge[key] !== "") patch[key] = judge[key];
159
+ }
160
+ if (patch.provider === "auto") patch.provider = "openrouter";
161
+ if (Object.keys(patch).length > 0) setSettings(DECISION_MODEL_NAMESPACE, patch, "global", cwd);
162
+ } catch {
163
+ // Unreadable legacy settings: defaults apply.
164
+ }
165
+ }
166
+
167
+ /** The shared Decision Model. */
168
+ export function readDecisionModel(cwd: string): DecisionModelSettings {
169
+ migrateLegacyDecisionModel(cwd);
170
+ return normalize(getSettings(DECISION_MODEL_NAMESPACE, cwd), DEFAULT_DECISION_MODEL);
171
+ }
172
+
173
+ /**
174
+ * The Decision Model a consumer should use: its own `decisionModel` block
175
+ * when `source: "custom"`, otherwise the shared one.
176
+ */
177
+ export function resolveDecisionModel(cwd: string, namespace?: string): DecisionModelSettings {
178
+ const shared = readDecisionModel(cwd);
179
+ if (!namespace) return shared;
180
+ const block = getSettings(namespace, cwd)?.decisionModel;
181
+ if (!isRecord(block) || block.source !== "custom") return shared;
182
+ return normalize(block, shared);
183
+ }
184
+
185
+ /** @deprecated Use resolveDecisionModel(cwd, namespace). */
186
+ export const readJudgeJevSettings = (cwd: string): DecisionModelSettings => readDecisionModel(cwd);
@@ -41,6 +41,7 @@ export const PACKAGE_COLORS: Record<string, string> = {
41
41
  "background-tasks": `${ESC}[91m`, // Bright Red
42
42
  fusion: `${ESC}[96m`, // Bright Cyan
43
43
  watchdog: `${ESC}[90m`, // Bright Black (gray)
44
+ "skill-registry": `${ESC}[92m`, // Bright Green
44
45
  };
45
46
 
46
47
  /** Hub namespace → PACKAGE_COLORS key (others use the namespace identity). */
@@ -48,6 +49,7 @@ const NAMESPACE_COLOR_KEYS: Record<string, string> = {
48
49
  "command-enchantment": "autocomplete",
49
50
  "info-screen": "info",
50
51
  compactor: "compact",
52
+ skills: "skill-registry",
51
53
  };
52
54
 
53
55
  /** ANSI color for a settings namespace ("" when unknown — no color). */
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Model catalog for `model`-type settings fields — the searchable picker's data.
3
3
  *
4
- * Source: pi's own model registry (~/.pi/agent/models.json), the same catalog
5
- * `pi --list-models` renders. The omniroute bridge keeps it current. Shape:
6
- * { providers: { <provider>: { models: [{ id, ... }] } } }
7
- * → flattened ["provider/model-id", …] ids.
4
+ * Primary source: the unipi model cache (~/.unipi/config/models-cache.json),
5
+ * written by utility from pi's live registry every session — it covers
6
+ * built-in providers with credentials and the image-generation collection,
7
+ * with input/output modalities. Pi's models.json (custom providers, shape
8
+ * { providers: { <provider>: { models: [{ id, ... }] } } })
9
+ * fills in anything the cache has not seen yet (first run, no session yet).
8
10
  *
9
11
  * The loader is sync + cached + never throws (empty catalog on any error), and
10
12
  * the path is injectable so tests feed a fixture instead of the real registry.
@@ -13,6 +15,7 @@
13
15
  import { readFileSync } from "node:fs";
14
16
  import { homedir } from "node:os";
15
17
  import { join } from "node:path";
18
+ import { readModelCache, modelInputs, modelOutputs, modelRef } from "../../model-cache.js";
16
19
 
17
20
  export function defaultModelCatalogPath(): string {
18
21
  return join(homedir(), ".pi", "agent", "models.json");
@@ -23,21 +26,44 @@ export interface ModelCatalogEntry {
23
26
  readonly id: string;
24
27
  /** Declared input modalities, e.g. ["text"] or ["text", "image"]. */
25
28
  readonly input: string[];
29
+ /** Declared output modalities; absent → ["text"]. */
30
+ readonly output?: string[];
26
31
  }
27
32
 
28
- let entryCache: ModelCatalogEntry[] | undefined;
33
+ export type ModelCapability = "text" | "image-input" | "image-output" | "image-edit";
29
34
 
30
- /** Load and cache the full "provider/model" id list. Empty on any failure. */
35
+ /** Capability filter shared by every model picker. */
36
+ export function matchesCapability(entry: ModelCatalogEntry, capability: ModelCapability): boolean {
37
+ // No declared input = unknown → hidden from capability pickers (custom… still
38
+ // accepts any id). Output defaults to text: chat catalogs rarely declare it.
39
+ const input = entry.input;
40
+ const output = entry.output?.length ? entry.output : ["text"];
41
+ switch (capability) {
42
+ case "text": return input.includes("text") && output.includes("text");
43
+ case "image-input": return input.includes("image") && output.includes("text");
44
+ case "image-output": return output.includes("image");
45
+ case "image-edit": return input.includes("image") && output.includes("image");
46
+ }
47
+ }
48
+
49
+ /** Load the full "provider/model" id list. Empty on any failure. */
31
50
  export function loadModelCatalog(path: string = defaultModelCatalogPath()): string[] {
32
51
  return loadModelCatalogEntries(path).map((e) => e.id);
33
52
  }
34
53
 
35
- /** Load and cache catalog entries (ids + metadata). Empty on any failure. */
54
+ /** Load catalog entries (ids + modalities). Read per call (picker open), so a
55
+ * cache rewritten mid-session is seen. Empty on any failure. */
36
56
  export function loadModelCatalogEntries(path: string = defaultModelCatalogPath()): ModelCatalogEntry[] {
37
- if (entryCache && path === defaultModelCatalogPath()) return entryCache;
38
- const entries = parseModelCatalogEntries(() => readFileSync(path, "utf8"));
39
- if (path === defaultModelCatalogPath()) entryCache = entries;
40
- return entries;
57
+ const isDefault = path === defaultModelCatalogPath();
58
+ const fromFile = parseModelCatalogEntries(() => readFileSync(path, "utf8"));
59
+ if (!isDefault) return fromFile;
60
+ const cached: ModelCatalogEntry[] = readModelCache().map((m) => ({
61
+ id: modelRef(m),
62
+ input: modelInputs(m),
63
+ output: modelOutputs(m),
64
+ }));
65
+ const seen = new Set(cached.map((e) => e.id));
66
+ return [...cached, ...fromFile.filter((e) => !seen.has(e.id))];
41
67
  }
42
68
 
43
69
  /** Pure parser — testable without the filesystem. */
@@ -78,10 +104,8 @@ export function parseModelCatalogEntries(read: () => string): ModelCatalogEntry[
78
104
  }
79
105
  }
80
106
 
81
- /** Test hook. */
82
- export function resetModelCatalogCache(): void {
83
- entryCache = undefined;
84
- }
107
+ /** Test hook (the catalog is no longer cached in memory; kept for callers). */
108
+ export function resetModelCatalogCache(): void {}
85
109
 
86
110
  /** Pure id-only parser (back-compat shim over parseModelCatalogEntries). */
87
111
  export function parseModelCatalog(read: () => string): string[] {
@@ -27,6 +27,20 @@ export interface SettingsDefinition {
27
27
  readonly projectOverrides?: boolean;
28
28
  /** Field schema — sections/fields the hub renders automatically. */
29
29
  readonly schema?: readonly SettingsSection[];
30
+ /**
31
+ * Called after every write to one layer (set or unset) with that layer's
32
+ * new content — for settings that mirror into another program's config
33
+ * (e.g. fusion's startup model → pi's settings.json). Errors are swallowed.
34
+ */
35
+ readonly onSet?: (layer: Record<string, unknown>, scope: SettingsScope, cwd: string) => void;
36
+ }
37
+
38
+ function notifySet(definition: SettingsDefinition, layer: Record<string, unknown>, scope: SettingsScope, cwd: string): void {
39
+ try {
40
+ definition.onSet?.(layer, scope, cwd);
41
+ } catch {
42
+ /* a mirror failure must not fail the settings write */
43
+ }
30
44
  }
31
45
 
32
46
  const registry = new Map<string, SettingsDefinition>();
@@ -139,8 +153,40 @@ export function setSettings(
139
153
  }
140
154
  const target =
141
155
  scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
142
- const current = readJson(target) ?? {};
143
- writeJson(target, deepMerge(current, patch));
156
+ const next = deepMerge(readJson(target) ?? {}, patch);
157
+ writeJson(target, next);
158
+ notifySet(definition, next, scope, cwd);
159
+ }
160
+
161
+ /** Delete a dot-path key from ONE scope — the "use default" / clear write. */
162
+ export function unsetSettings(namespace: string, key: string, scope: SettingsScope, cwd: string): void {
163
+ runGates(cwd);
164
+ const definition = registry.get(namespace);
165
+ if (!definition) throw new Error(`unknown settings namespace: ${namespace}`);
166
+ const target = scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
167
+ const current = readJson(target);
168
+ if (!current) return;
169
+ const segments = key.split(".");
170
+ let cursor: Record<string, unknown> = current;
171
+ for (let i = 0; i < segments.length - 1; i++) {
172
+ const next = cursor[segments[i]!];
173
+ if (typeof next !== "object" || next === null) return;
174
+ cursor = next as Record<string, unknown>;
175
+ }
176
+ delete cursor[segments[segments.length - 1]!];
177
+ writeJson(target, current);
178
+ notifySet(definition, current, scope, cwd);
179
+ }
180
+
181
+ /** One layer only (no defaults, no merge) — for layered fallback chains. */
182
+ export function getSettingsScoped(
183
+ namespace: string,
184
+ scope: SettingsScope,
185
+ cwd: string,
186
+ ): Record<string, unknown> | undefined {
187
+ runGates(cwd);
188
+ const path = scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
189
+ return readJson(path) ?? undefined;
144
190
  }
145
191
 
146
192
  /** Which layers currently exist for a namespace (hub status display). */