@phren/cli 0.2.15 → 0.3.0

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 (392) hide show
  1. package/README.md +2 -2
  2. package/dist/agent-instructions.d.ts +12 -0
  3. package/dist/agent-instructions.js +52 -0
  4. package/dist/bridge/agent-hook-stores.d.ts +32 -0
  5. package/dist/bridge/agent-hook-stores.js +67 -0
  6. package/dist/bridge/agent-hooks.d.ts +195 -2
  7. package/dist/bridge/agent-hooks.js +1049 -38
  8. package/dist/bridge/canary.d.ts +27 -0
  9. package/dist/bridge/canary.js +189 -0
  10. package/dist/bridge/changes.d.ts +57 -0
  11. package/dist/bridge/changes.js +403 -0
  12. package/dist/bridge/client.d.ts +3 -0
  13. package/dist/bridge/client.js +36 -0
  14. package/dist/bridge/code-note.d.ts +23 -0
  15. package/dist/bridge/code-note.js +51 -0
  16. package/dist/bridge/code-routes.d.ts +151 -0
  17. package/dist/bridge/code-routes.js +442 -0
  18. package/dist/bridge/codex-threads.d.ts +27 -0
  19. package/dist/bridge/codex-threads.js +442 -0
  20. package/dist/bridge/command.d.ts +7 -0
  21. package/dist/bridge/command.js +50 -5
  22. package/dist/bridge/computer-names.d.ts +4 -0
  23. package/dist/bridge/computer-names.js +16 -0
  24. package/dist/bridge/computers.d.ts +9 -0
  25. package/dist/bridge/computers.js +111 -0
  26. package/dist/bridge/context.d.ts +14 -0
  27. package/dist/bridge/context.js +149 -0
  28. package/dist/bridge/dispatch-command.d.ts +3 -0
  29. package/dist/bridge/dispatch-command.js +93 -0
  30. package/dist/bridge/dispatch-hosts.d.ts +23 -0
  31. package/dist/bridge/dispatch-hosts.js +25 -0
  32. package/dist/bridge/dispatch-returns.d.ts +125 -0
  33. package/dist/bridge/dispatch-returns.js +283 -0
  34. package/dist/bridge/dispatch-tree.d.ts +54 -0
  35. package/dist/bridge/dispatch-tree.js +198 -0
  36. package/dist/bridge/dispatch.d.ts +210 -0
  37. package/dist/bridge/dispatch.js +286 -0
  38. package/dist/bridge/enroll.d.ts +31 -0
  39. package/dist/bridge/enroll.js +236 -0
  40. package/dist/bridge/fanout-messages.d.ts +74 -0
  41. package/dist/bridge/fanout-messages.js +230 -0
  42. package/dist/bridge/fanouts.d.ts +160 -0
  43. package/dist/bridge/fanouts.js +702 -0
  44. package/dist/bridge/file-range.d.ts +16 -0
  45. package/dist/bridge/file-range.js +90 -0
  46. package/dist/bridge/files.d.ts +20 -0
  47. package/dist/bridge/files.js +54 -0
  48. package/dist/bridge/git-publish.d.ts +23 -0
  49. package/dist/bridge/git-publish.js +145 -0
  50. package/dist/bridge/git-worktrees.d.ts +21 -0
  51. package/dist/bridge/git-worktrees.js +150 -0
  52. package/dist/bridge/git.d.ts +54 -0
  53. package/dist/bridge/git.js +552 -0
  54. package/dist/bridge/grants.d.ts +31 -0
  55. package/dist/bridge/grants.js +181 -0
  56. package/dist/bridge/hand-off.d.ts +79 -0
  57. package/dist/bridge/hand-off.js +151 -0
  58. package/dist/bridge/health.d.ts +128 -0
  59. package/dist/bridge/health.js +260 -0
  60. package/dist/bridge/herdr.d.ts +79 -6
  61. package/dist/bridge/herdr.js +292 -27
  62. package/dist/bridge/hook-main.js +2 -0
  63. package/dist/bridge/install.d.ts +28 -1
  64. package/dist/bridge/install.js +225 -38
  65. package/dist/bridge/launch-worktree.d.ts +21 -0
  66. package/dist/bridge/launch-worktree.js +70 -0
  67. package/dist/bridge/limits.d.ts +20 -0
  68. package/dist/bridge/limits.js +65 -0
  69. package/dist/bridge/locate.d.ts +16 -0
  70. package/dist/bridge/locate.js +75 -0
  71. package/dist/bridge/metrics.d.ts +29 -0
  72. package/dist/bridge/metrics.js +71 -0
  73. package/dist/bridge/model-switch.d.ts +35 -0
  74. package/dist/bridge/model-switch.js +250 -0
  75. package/dist/bridge/models.d.ts +46 -0
  76. package/dist/bridge/models.js +257 -0
  77. package/dist/bridge/opencode-approvals.d.ts +6 -0
  78. package/dist/bridge/opencode-approvals.js +60 -0
  79. package/dist/bridge/pane-text.d.ts +15 -0
  80. package/dist/bridge/pane-text.js +23 -0
  81. package/dist/bridge/peers.d.ts +27 -0
  82. package/dist/bridge/peers.js +130 -0
  83. package/dist/bridge/projects.d.ts +12 -1
  84. package/dist/bridge/projects.js +268 -20
  85. package/dist/bridge/protocol.d.ts +35 -2
  86. package/dist/bridge/protocol.js +61 -7
  87. package/dist/bridge/push.d.ts +83 -0
  88. package/dist/bridge/push.js +199 -0
  89. package/dist/bridge/questions.d.ts +38 -0
  90. package/dist/bridge/questions.js +205 -0
  91. package/dist/bridge/schedule-format.d.ts +103 -0
  92. package/dist/bridge/schedule-format.js +266 -0
  93. package/dist/bridge/schedule-launch.d.ts +11 -0
  94. package/dist/bridge/schedule-launch.js +169 -0
  95. package/dist/bridge/schedule-watch.d.ts +54 -0
  96. package/dist/bridge/schedule-watch.js +255 -0
  97. package/dist/bridge/schedules.d.ts +48 -0
  98. package/dist/bridge/schedules.js +205 -0
  99. package/dist/bridge/server-launch.d.ts +14 -0
  100. package/dist/bridge/server-launch.js +218 -0
  101. package/dist/bridge/server-overview.d.ts +45 -0
  102. package/dist/bridge/server-overview.js +102 -0
  103. package/dist/bridge/server-pane-routes.d.ts +36 -0
  104. package/dist/bridge/server-pane-routes.js +479 -0
  105. package/dist/bridge/server-routes.d.ts +108 -0
  106. package/dist/bridge/server-routes.js +556 -0
  107. package/dist/bridge/server-stream.d.ts +46 -0
  108. package/dist/bridge/server-stream.js +253 -0
  109. package/dist/bridge/server.d.ts +3 -15
  110. package/dist/bridge/server.js +162 -264
  111. package/dist/bridge/session-servers.d.ts +24 -0
  112. package/dist/bridge/session-servers.js +136 -0
  113. package/dist/bridge/side-questions.d.ts +74 -0
  114. package/dist/bridge/side-questions.js +252 -0
  115. package/dist/bridge/simulators.d.ts +28 -0
  116. package/dist/bridge/simulators.js +198 -0
  117. package/dist/bridge/speech-transcribe.d.ts +24 -0
  118. package/dist/bridge/speech-transcribe.js +124 -0
  119. package/dist/bridge/speech.d.ts +35 -0
  120. package/dist/bridge/speech.js +98 -0
  121. package/dist/bridge/steps.d.ts +13 -0
  122. package/dist/bridge/steps.js +222 -0
  123. package/dist/bridge/tab-activity.d.ts +18 -0
  124. package/dist/bridge/tab-activity.js +99 -0
  125. package/dist/bridge/terminal-choice.d.ts +64 -0
  126. package/dist/bridge/terminal-choice.js +281 -0
  127. package/dist/bridge/transcript-claude.d.ts +22 -0
  128. package/dist/bridge/transcript-claude.js +353 -0
  129. package/dist/bridge/transcript-codex.d.ts +30 -0
  130. package/dist/bridge/transcript-codex.js +282 -0
  131. package/dist/bridge/transcript-copilot.d.ts +4 -0
  132. package/dist/bridge/transcript-copilot.js +14 -0
  133. package/dist/bridge/transcript-opencode.d.ts +5 -0
  134. package/dist/bridge/transcript-opencode.js +26 -0
  135. package/dist/bridge/transcript-preview.d.ts +96 -0
  136. package/dist/bridge/transcript-preview.js +491 -0
  137. package/dist/bridge/transcripts.d.ts +81 -4
  138. package/dist/bridge/transcripts.js +332 -67
  139. package/dist/bridge/transport.d.ts +3 -0
  140. package/dist/bridge/transport.js +96 -15
  141. package/dist/bridge/uploads.d.ts +15 -0
  142. package/dist/bridge/uploads.js +44 -2
  143. package/dist/bridge/usage.d.ts +124 -0
  144. package/dist/bridge/usage.js +859 -0
  145. package/dist/bridge-hook.mjs +46545 -21051
  146. package/dist/cli/actions.js +14 -1
  147. package/dist/cli/config-policy.js +25 -0
  148. package/dist/cli/config-proactivity.d.ts +3 -1
  149. package/dist/cli/config-proactivity.js +35 -3
  150. package/dist/cli/config.js +4 -1
  151. package/dist/cli/extract.d.ts +0 -8
  152. package/dist/cli/extract.js +4 -7
  153. package/dist/cli/govern.js +5 -2
  154. package/dist/cli/hooks-globs.js +1 -1
  155. package/dist/cli/hooks.d.ts +1 -1
  156. package/dist/cli/hooks.js +9 -7
  157. package/dist/cli/namespaces-projects.js +12 -6
  158. package/dist/cli/namespaces-store.js +37 -6
  159. package/dist/cli/namespaces-tasks.js +1 -1
  160. package/dist/cli/schedules.d.ts +1 -0
  161. package/dist/cli/schedules.js +164 -0
  162. package/dist/cli/session-background.js +1 -1
  163. package/dist/cli/session-git.d.ts +8 -5
  164. package/dist/cli/session-git.js +45 -120
  165. package/dist/cli/session-start.js +3 -1
  166. package/dist/cli/session-stop.js +19 -8
  167. package/dist/cli/team.js +13 -10
  168. package/dist/cli-handlers.d.ts +1 -1
  169. package/dist/cli-handlers.js +8 -4
  170. package/dist/cli-help.d.ts +5 -4
  171. package/dist/cli-help.js +15 -15
  172. package/dist/cli-registry.d.ts +4 -1
  173. package/dist/cli-registry.js +119 -6
  174. package/dist/content/archive.js +2 -2
  175. package/dist/content/citation.d.ts +11 -0
  176. package/dist/content/citation.js +18 -0
  177. package/dist/content/learning.js +2 -0
  178. package/dist/content/summarize.d.ts +14 -15
  179. package/dist/content/summarize.js +60 -5
  180. package/dist/content/validate.d.ts +17 -4
  181. package/dist/content/validate.js +200 -122
  182. package/dist/core/project-registry.d.ts +26 -0
  183. package/dist/core/project-registry.js +573 -0
  184. package/dist/core/project.js +2 -3
  185. package/dist/data/access.d.ts +16 -1
  186. package/dist/data/access.js +31 -3
  187. package/dist/data/tasks.d.ts +18 -3
  188. package/dist/data/tasks.js +8 -7
  189. package/dist/entrypoint.js +44 -10
  190. package/dist/fanout/adapters/claude.d.ts +2 -0
  191. package/dist/fanout/adapters/claude.js +7 -0
  192. package/dist/fanout/adapters/codex.d.ts +2 -0
  193. package/dist/fanout/adapters/codex.js +9 -0
  194. package/dist/fanout/adapters/opencode.d.ts +4 -0
  195. package/dist/fanout/adapters/opencode.js +9 -0
  196. package/dist/fanout/adapters/types.d.ts +21 -0
  197. package/dist/fanout/adapters/types.js +3 -0
  198. package/dist/fanout/command.d.ts +2 -0
  199. package/dist/fanout/command.js +78 -0
  200. package/dist/fanout/launcher.d.ts +27 -0
  201. package/dist/fanout/launcher.js +156 -0
  202. package/dist/fanout/opencode-serve.d.ts +24 -0
  203. package/dist/fanout/opencode-serve.js +191 -0
  204. package/dist/fanout/picker.d.ts +91 -0
  205. package/dist/fanout/picker.js +51 -0
  206. package/dist/fanout/usage.d.ts +5 -0
  207. package/dist/fanout/usage.js +51 -0
  208. package/dist/fanout/watchdog.d.ts +10 -0
  209. package/dist/fanout/watchdog.js +27 -0
  210. package/dist/filenames.d.ts +9 -0
  211. package/dist/filenames.js +11 -0
  212. package/dist/finding/context.js +4 -22
  213. package/dist/generated/memory-ui-graph.browser.js +525 -419
  214. package/dist/governance/policy-constants.d.ts +11 -0
  215. package/dist/governance/policy-constants.js +9 -0
  216. package/dist/governance/policy.d.ts +5 -8
  217. package/dist/governance/policy.js +11 -8
  218. package/dist/graph-core/camera.d.ts +24 -0
  219. package/dist/graph-core/camera.js +18 -0
  220. package/dist/graph-core/index.d.ts +2 -0
  221. package/dist/graph-core/index.js +2 -0
  222. package/dist/graph-core/labels.d.ts +77 -0
  223. package/dist/graph-core/labels.js +124 -0
  224. package/dist/graph-core/model.d.ts +13 -0
  225. package/dist/graph-core/model.js +33 -0
  226. package/dist/graph-core/types.d.ts +2 -0
  227. package/dist/home-paths.d.ts +7 -0
  228. package/dist/home-paths.js +21 -0
  229. package/dist/hooks.d.ts +3 -15
  230. package/dist/hooks.js +14 -1
  231. package/dist/index.js +24 -2
  232. package/dist/init/guard-globals.d.ts +1 -1
  233. package/dist/init/guard-globals.js +4 -4
  234. package/dist/init/init-configure.js +3 -3
  235. package/dist/init/init-uninstall.js +15 -5
  236. package/dist/init/init-walkthrough.js +1 -1
  237. package/dist/init/init.js +26 -6
  238. package/dist/init/management-preset.d.ts +1 -1
  239. package/dist/init/management-preset.js +2 -2
  240. package/dist/init/preferences.js +1 -1
  241. package/dist/init/self-wiring.js +1 -1
  242. package/dist/init/setup.d.ts +3 -26
  243. package/dist/init/setup.js +68 -593
  244. package/dist/init/shared.js +2 -0
  245. package/dist/init/store-gitignore.d.ts +1 -6
  246. package/dist/init/store-gitignore.js +2 -8
  247. package/dist/init/teardown.d.ts +1 -1
  248. package/dist/init/teardown.js +2 -2
  249. package/dist/link/context-imports.d.ts +15 -0
  250. package/dist/link/context-imports.js +101 -0
  251. package/dist/link/context.js +1 -1
  252. package/dist/link/doctor.d.ts +22 -1
  253. package/dist/link/doctor.js +128 -58
  254. package/dist/link/link.js +29 -61
  255. package/dist/link/refresh.js +2 -2
  256. package/dist/link/skills.js +26 -5
  257. package/dist/machine-identity.d.ts +3 -0
  258. package/dist/machine-identity.js +6 -0
  259. package/dist/mcp/profile.d.ts +2 -19
  260. package/dist/mcp/profile.js +64 -22
  261. package/dist/memory-ui-graph.runtime.js +525 -419
  262. package/dist/modules/code-package.d.ts +16 -0
  263. package/dist/modules/code-package.js +160 -0
  264. package/dist/modules/command.d.ts +2 -0
  265. package/dist/modules/command.js +67 -0
  266. package/dist/modules/config.d.ts +4 -0
  267. package/dist/modules/config.js +70 -0
  268. package/dist/modules/manifest.d.ts +41 -0
  269. package/dist/modules/manifest.js +1 -0
  270. package/dist/modules/provision.d.ts +3 -0
  271. package/dist/modules/provision.js +84 -0
  272. package/dist/modules/registry.d.ts +16 -0
  273. package/dist/modules/registry.js +250 -0
  274. package/dist/modules/runtime.d.ts +15 -0
  275. package/dist/modules/runtime.js +59 -0
  276. package/dist/package-metadata.js +10 -2
  277. package/dist/phren-dotenv.js +4 -2
  278. package/dist/phren-paths.d.ts +3 -2
  279. package/dist/phren-paths.js +4 -5
  280. package/dist/profile-store.js +43 -8
  281. package/dist/project-config.d.ts +19 -1
  282. package/dist/project-config.js +29 -3
  283. package/dist/project-topics.d.ts +1 -0
  284. package/dist/project-topics.js +13 -10
  285. package/dist/provider-adapters.js +1 -4
  286. package/dist/query-correlation.js +6 -6
  287. package/dist/session/artifacts.js +5 -5
  288. package/dist/session/checkpoints.js +5 -0
  289. package/dist/session/utils.d.ts +2 -2
  290. package/dist/session/utils.js +6 -6
  291. package/dist/shared/content.d.ts +1 -1
  292. package/dist/shared/content.js +1 -1
  293. package/dist/shared/data-utils.js +1 -1
  294. package/dist/shared/fragment-graph.d.ts +1 -1
  295. package/dist/shared/fragment-graph.js +5 -5
  296. package/dist/shared/index.js +48 -7
  297. package/dist/shared/retrieval.d.ts +18 -3
  298. package/dist/shared/retrieval.js +101 -12
  299. package/dist/shared/search-fallback.js +4 -6
  300. package/dist/shared/sqljs.d.ts +2 -0
  301. package/dist/shared/sqljs.js +4 -2
  302. package/dist/shared.d.ts +0 -1
  303. package/dist/shared.js +0 -1
  304. package/dist/shell/input.d.ts +1 -5
  305. package/dist/shell/input.js +16 -10
  306. package/dist/shell/palette.d.ts +2 -2
  307. package/dist/shell/palette.js +3 -7
  308. package/dist/shell/render.d.ts +3 -1
  309. package/dist/shell/render.js +4 -4
  310. package/dist/shell/shell.js +4 -1
  311. package/dist/shell/types.d.ts +1 -0
  312. package/dist/shell/types.js +4 -0
  313. package/dist/shell/view.d.ts +0 -4
  314. package/dist/shell/view.js +19 -27
  315. package/dist/skill/registry.js +25 -17
  316. package/dist/skill/state.d.ts +3 -0
  317. package/dist/skill/state.js +13 -7
  318. package/dist/status.js +38 -17
  319. package/dist/store-registry.d.ts +44 -18
  320. package/dist/store-registry.js +169 -60
  321. package/dist/store-weight.d.ts +1 -6
  322. package/dist/store-weight.js +4 -2
  323. package/dist/sync/auth-doctor.d.ts +8 -0
  324. package/dist/sync/auth-doctor.js +27 -0
  325. package/dist/sync/auth.d.ts +27 -0
  326. package/dist/sync/auth.js +114 -0
  327. package/dist/sync/conflict-resolve.d.ts +9 -0
  328. package/dist/sync/conflict-resolve.js +146 -0
  329. package/dist/sync/git-state.d.ts +4 -0
  330. package/dist/sync/git-state.js +49 -0
  331. package/dist/sync/outcome.d.ts +34 -0
  332. package/dist/sync/outcome.js +57 -0
  333. package/dist/sync/pull.d.ts +15 -7
  334. package/dist/sync/pull.js +84 -35
  335. package/dist/sync/store-merge.d.ts +29 -0
  336. package/dist/sync/store-merge.js +137 -0
  337. package/dist/sync/task-merge.d.ts +22 -0
  338. package/dist/sync/task-merge.js +158 -0
  339. package/dist/task/github.js +1 -1
  340. package/dist/task/lifecycle.d.ts +5 -0
  341. package/dist/task/lifecycle.js +67 -23
  342. package/dist/terminal-text.d.ts +5 -0
  343. package/dist/terminal-text.js +11 -0
  344. package/dist/test-global-setup.js +7 -0
  345. package/dist/tool-registry.d.ts +1 -1
  346. package/dist/tool-registry.js +3 -1
  347. package/dist/tools/code.d.ts +3 -0
  348. package/dist/tools/code.js +186 -0
  349. package/dist/tools/config.js +8 -0
  350. package/dist/tools/data.js +14 -7
  351. package/dist/tools/dispatch.d.ts +2 -0
  352. package/dist/tools/dispatch.js +66 -0
  353. package/dist/tools/finding.d.ts +11 -0
  354. package/dist/tools/finding.js +180 -123
  355. package/dist/tools/ops.js +5 -2
  356. package/dist/tools/search.js +21 -8
  357. package/dist/tools/session.js +21 -22
  358. package/dist/tools/tasks.js +8 -2
  359. package/dist/tools/types.d.ts +2 -2
  360. package/dist/tools/types.js +2 -2
  361. package/dist/ui/assets.js +1 -1
  362. package/dist/ui/data.js +14 -15
  363. package/dist/ui/deep-void.d.ts +1 -1
  364. package/dist/ui/deep-void.js +0 -1
  365. package/dist/ui/graph-chrome.d.ts +1 -1
  366. package/dist/ui/graph-chrome.js +51 -0
  367. package/dist/ui/page.js +5 -5
  368. package/dist/ui/scripts.js +67 -30
  369. package/dist/ui/server.js +52 -7
  370. package/dist/update.js +22 -11
  371. package/dist/utils-fts.js +1 -0
  372. package/dist/utils-helpers.d.ts +7 -0
  373. package/dist/utils-helpers.js +17 -0
  374. package/dist/utils.d.ts +1 -1
  375. package/dist/utils.js +1 -1
  376. package/package.json +49 -7
  377. package/plugins/opencode/phren-transcript.js +340 -0
  378. package/starter/README.md +4 -4
  379. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  380. package/starter/global/skills/conductor/SKILL.md +106 -0
  381. package/starter/global/skills/fanout/SKILL.md +20 -0
  382. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  383. package/starter/global/skills/phren-init/SKILL.md +4 -4
  384. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  385. package/starter/templates/frontend/reference/README.md +1 -1
  386. package/starter/templates/library/reference/README.md +1 -1
  387. package/starter/templates/monorepo/reference/README.md +1 -1
  388. package/starter/templates/python-project/reference/README.md +1 -1
  389. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  390. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  391. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  392. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -47,6 +47,17 @@ const LOW_FOCUS_SNIPPET_CHAR_FRACTION = 0.55;
47
47
  * PHREN_MIN_QUERY_RELEVANCE (0 disables the floor). */
48
48
  const DEFAULT_MIN_QUERY_RELEVANCE = 0.12;
49
49
  const CROSS_PROJECT_MIN_QUERY_RELEVANCE = 0.25;
50
+ /** A chunk (one bullet or paragraph) must match this many distinct prompt
51
+ * keywords before its doc is worth injecting. */
52
+ const MIN_CHUNK_MATCHES = 2;
53
+ /** The matched keywords' summed rarity (normalised IDF, 0..1 each) a chunk
54
+ * needs. Common words across the index ("main", "push", "agent") weigh little,
55
+ * project and technical terms a lot, so a prompt of common words clears
56
+ * nothing. With no detected project (the conductor) the bar is higher. */
57
+ const MIN_CHUNK_RARITY = 0.55;
58
+ const NO_PROJECT_MIN_CHUNK_RARITY = 0.6;
59
+ /** Rarity for a token the index never saw, or when no index is at hand. */
60
+ const DEFAULT_TOKEN_RARITY = 0.5;
50
61
  const TASK_RESCUE_MIN_OVERLAP = 0.3;
51
62
  const TASK_RESCUE_OVERLAP_MARGIN = 0.12;
52
63
  const TASK_RESCUE_SCORE_MARGIN = 0.6;
@@ -205,9 +216,81 @@ function overlapScore(queryTokens, content) {
205
216
  return matched / denominator;
206
217
  }
207
218
  function docOverlapScore(queryTokens, doc) {
208
- const corpus = `${doc.project} ${doc.filename} ${doc.type} ${doc.path}\n${doc.content.slice(0, 5000)}`;
219
+ // Never the path: every store path contains "/.phren/", so "phren" would match every doc.
220
+ const corpus = `${doc.project} ${doc.filename} ${doc.type}\n${doc.content.slice(0, 5000)}`;
209
221
  return overlapScore(queryTokens, corpus);
210
222
  }
223
+ /** A doc's bullets (with their continuation lines) or, with none, its
224
+ * paragraphs: the unit relevance is judged on. Topic archives are one doc
225
+ * with hundreds of bullets, so a whole-file score matches almost anything. */
226
+ export function contentChunks(content, maxChunks = 600) {
227
+ const chunks = [];
228
+ let current = [];
229
+ const flush = () => { if (current.length)
230
+ chunks.push(current.join("\n")); current = []; };
231
+ for (const line of content.split("\n")) {
232
+ const trimmed = line.trim();
233
+ if (!trimmed) {
234
+ flush();
235
+ continue;
236
+ }
237
+ if (/^([-*+]|\d+[.)])\s/.test(trimmed) || trimmed.startsWith("#"))
238
+ flush();
239
+ current.push(line);
240
+ if (chunks.length >= maxChunks)
241
+ break;
242
+ }
243
+ flush();
244
+ return chunks.slice(0, maxChunks);
245
+ }
246
+ /** The doc's best chunk for this prompt: most summed keyword rarity among
247
+ * chunks with the most distinct keyword matches. */
248
+ export function bestChunkMatch(queryTokens, doc, rarity) {
249
+ if (!queryTokens.length)
250
+ return null;
251
+ const wanted = new Set(queryTokens);
252
+ let best = null;
253
+ for (const chunk of contentChunks(doc.content)) {
254
+ const tokens = new Set(tokenizeForOverlap(chunk, Number.POSITIVE_INFINITY));
255
+ let distinct = 0, weight = 0;
256
+ for (const token of wanted) {
257
+ if (!tokens.has(token))
258
+ continue;
259
+ distinct += 1;
260
+ weight += rarity?.get(token) ?? DEFAULT_TOKEN_RARITY;
261
+ }
262
+ if (!distinct)
263
+ continue;
264
+ if (!best || weight > best.rarity || (weight === best.rarity && distinct > best.distinct))
265
+ best = { chunk, distinct, rarity: weight };
266
+ }
267
+ return best;
268
+ }
269
+ /** How rare each prompt token is across the index: normalised IDF, 1 for a
270
+ * token in one doc, near 0 for one in every doc. One FTS count per token. */
271
+ /** `tokenRarity` for a prompt's keywords, tokenised as the floor tokenises them. */
272
+ export function promptRarity(db, keywords) {
273
+ return tokenRarity(db, tokenizeForOverlap(keywords));
274
+ }
275
+ export function tokenRarity(db, queryTokens) {
276
+ const rarity = new Map();
277
+ if (!db || !queryTokens.length)
278
+ return rarity;
279
+ try {
280
+ const total = Number(queryRows(db, "SELECT COUNT(*) FROM docs", [])?.[0]?.[0] ?? 0);
281
+ if (!(total > 1))
282
+ return rarity;
283
+ const scale = Math.log(total + 1);
284
+ for (const token of queryTokens.slice(0, 12)) {
285
+ if (!/^[a-z0-9_-]+$/.test(token))
286
+ continue;
287
+ const df = Number(queryRows(db, "SELECT COUNT(*) FROM docs WHERE docs MATCH ?", [`"${token}"*`])?.[0]?.[0] ?? 0);
288
+ rarity.set(token, Math.max(0, Math.min(1, Math.log((total + 1) / (df + 1)) / scale)));
289
+ }
290
+ }
291
+ catch { /* the default rarity stands in */ }
292
+ return rarity;
293
+ }
211
294
  function loadSemanticFallbackWindow(db, startRowid, limit, project, wrapBefore) {
212
295
  const where = [
213
296
  project ? "project = ?" : "",
@@ -315,7 +398,7 @@ function semanticFallbackDocs(db, prompt, project) {
315
398
  return scored;
316
399
  }
317
400
  /** @internal Exported for tests. */
318
- export function shouldRunVectorExpansion(rows, prompt, desiredResults = VECTOR_FALLBACK_SKIP_COUNT) {
401
+ function shouldRunVectorExpansion(rows, prompt, desiredResults = VECTOR_FALLBACK_SKIP_COUNT) {
319
402
  if (!rows || rows.length === 0)
320
403
  return true;
321
404
  const targetCount = Math.max(2, Math.min(VECTOR_FALLBACK_SKIP_COUNT, desiredResults));
@@ -888,24 +971,27 @@ export { DEFAULT_MIN_QUERY_RELEVANCE };
888
971
  * floor to 0 (env PHREN_MIN_QUERY_RELEVANCE=0) disables it and restores the
889
972
  * previous always-fill behavior.
890
973
  */
891
- export function applyRelevanceFloor(rows, keywords, gitCtx, detectedProject, floor = DEFAULT_MIN_QUERY_RELEVANCE) {
974
+ export function applyRelevanceFloor(rows, keywords, gitCtx, detectedProject, floor = DEFAULT_MIN_QUERY_RELEVANCE, rarity) {
892
975
  if (!(floor > 0))
893
976
  return rows;
894
977
  const queryTokens = tokenizeForOverlap(keywords);
895
- if (!queryTokens.length)
896
- return rows; // no query signal to judge against
897
978
  const changedFiles = gitCtx?.changedFiles ?? new Set();
898
- const branch = gitCtx?.branch;
899
979
  const crossFloor = Math.max(floor, CROSS_PROJECT_MIN_QUERY_RELEVANCE);
980
+ // Fewer meaningful keywords than a chunk must match: nothing can be about
981
+ // this prompt ("Yes"), so only the structural signals remain.
982
+ const minRarity = detectedProject ? MIN_CHUNK_RARITY : NO_PROJECT_MIN_CHUNK_RARITY;
900
983
  return rows.filter((doc) => {
984
+ // A changed file is a tie to this work; a branch name is not: its words
985
+ // ("audio") run through a whole project's memory. It still orders results.
901
986
  if (fileRelevanceBoost(doc.path, changedFiles) > 0)
902
987
  return true;
903
- if (branchMatchBoost(doc.content, branch) > 0)
904
- return true;
905
- if (detectedProject && doc.project === detectedProject && doc.type === "canonical")
906
- return true;
988
+ if (queryTokens.length < MIN_CHUNK_MATCHES)
989
+ return false;
990
+ const match = bestChunkMatch(queryTokens, doc, rarity);
991
+ if (!match || match.distinct < MIN_CHUNK_MATCHES || match.rarity < minRarity)
992
+ return false;
907
993
  const isCrossProject = Boolean(detectedProject) && doc.project !== detectedProject;
908
- return docOverlapScore(queryTokens, doc) >= (isCrossProject ? crossFloor : floor);
994
+ return overlapScore(queryTokens, match.chunk) >= (isCrossProject ? crossFloor : floor);
909
995
  });
910
996
  }
911
997
  export function selectSnippets(rows, keywords, tokenBudget, lineBudget, charBudget) {
@@ -931,7 +1017,10 @@ export function selectSnippets(rows, keywords, tokenBudget, lineBudget, charBudg
931
1017
  // unconditionally true of everything injected, so it is checked here too.
932
1018
  if (!isInjectableDocType(doc.type))
933
1019
  continue;
934
- let snippet = compactSnippet(extractSnippet(doc.content, keywords, 8), lineBudget, charBudget);
1020
+ // The bullet that matched, not the doc's opening lines.
1021
+ const match = bestChunkMatch(queryTokens, doc);
1022
+ const source = match && match.distinct >= MIN_CHUNK_MATCHES ? match.chunk : extractSnippet(doc.content, keywords, 8);
1023
+ let snippet = compactSnippet(source, lineBudget, charBudget);
935
1024
  if (!snippet.trim())
936
1025
  continue;
937
1026
  // Mark findings with stale citations before injection
@@ -66,7 +66,7 @@ function cachedTokenize(text) {
66
66
  const hit = tokenCache.get(key);
67
67
  if (hit)
68
68
  return hit;
69
- const tokens = tokenize(text);
69
+ const tokens = stemmedTerms(text);
70
70
  if (tokenCache.size >= MAX_TOKEN_CACHE) {
71
71
  // Evict oldest entry
72
72
  tokenCache.delete(tokenCache.keys().next().value ?? "");
@@ -88,10 +88,8 @@ function loadCosineFallbackWindow(db, startRowid, limit, wrapBefore) {
88
88
  const rows = db.exec(`SELECT rowid, project, filename, type, content, path FROM docs WHERE ${where} ORDER BY rowid LIMIT ?`, params);
89
89
  return rows?.[0]?.values ?? [];
90
90
  }
91
- /**
92
- * Tokenize text into non-stop-word tokens for TF-IDF computation, with stemming.
93
- */
94
- function tokenize(text) {
91
+ /** Punctuation-free, stop-word-free, Porter-stemmed terms for TF-IDF scoring. */
92
+ function stemmedTerms(text) {
95
93
  return text
96
94
  .toLowerCase()
97
95
  .replace(/[^\w\s]/g, " ")
@@ -107,7 +105,7 @@ function tokenize(text) {
107
105
  * Pass the real total when docs is a pre-filtered subset so IDF scores are not inflated.
108
106
  */
109
107
  function tfidfCosine(docs, query, corpusN) {
110
- const queryTokens = tokenize(query);
108
+ const queryTokens = stemmedTerms(query);
111
109
  if (queryTokens.length === 0)
112
110
  return docs.map(() => 0);
113
111
  // Collect all unique terms from query + all docs (use cached tokenization for repeated content)
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Bootstrap sql.js-fts5: find the WASM binary and initialise the library.
3
3
  * Shared across shared-index.ts and embedding.ts to avoid duplication.
4
+ * The require is lazy so importing this module (the Hook bundle pulls it in
5
+ * through the CLI context) does not need the native package on disk.
4
6
  */
5
7
  export declare function bootstrapSqlJs(): Promise<unknown>;
@@ -32,12 +32,14 @@ function findWasmBinary() {
32
32
  }
33
33
  return undefined;
34
34
  }
35
- const _initSqlJs = require("sql.js-fts5");
36
35
  /**
37
36
  * Bootstrap sql.js-fts5: find the WASM binary and initialise the library.
38
37
  * Shared across shared-index.ts and embedding.ts to avoid duplication.
38
+ * The require is lazy so importing this module (the Hook bundle pulls it in
39
+ * through the CLI context) does not need the native package on disk.
39
40
  */
40
41
  export async function bootstrapSqlJs() {
42
+ const initSqlJs = require("sql.js-fts5");
41
43
  const wasmBinary = findWasmBinary();
42
- return _initSqlJs(wasmBinary ? { wasmBinary } : {});
44
+ return initSqlJs(wasmBinary ? { wasmBinary } : {});
43
45
  }
package/dist/shared.d.ts CHANGED
@@ -2,7 +2,6 @@ export type { HookToolName } from "./provider-adapters.js";
2
2
  export { HOOK_TOOL_NAMES, hookConfigPath } from "./provider-adapters.js";
3
3
  export { EXEC_TIMEOUT_MS, EXEC_TIMEOUT_QUICK_MS, PhrenError, type PhrenErrorCode, type PhrenResult, phrenOk, phrenErr, forwardErr, parsePhrenErrorCode, isRecord, withDefaults, FINDING_TYPES, type FindingType, FINDING_TAGS, type FindingTag, KNOWN_OBSERVATION_TAGS, DOC_TYPES, type DocType, capCache, RESERVED_PROJECT_DIR_NAMES, } from "./phren-core.js";
4
4
  export { ROOT_MANIFEST_FILENAME, type InstallMode, type SyncMode, type PhrenRootManifest, type InstallContext, isInstallMode, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, lookupEventsLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, projectSlugFromPath, canonicalProjectKey, findProjectNameCaseInsensitive, findProjectNamesByCanonicalKey, findArchivedProjectNameCaseInsensitive, getProjectDirs, listInvalidProjectDirs, collectNativeMemoryFiles, nativeMemoryEnabled, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, ensurePrivateDir, ftsCacheRoot, ensureFtsCacheRootPrivate, } from "./phren-paths.js";
5
- export { PROACTIVITY_LEVELS, type ProactivityLevel, parseProactivityLevel, getProactivityLevel, getProactivityLevelForFindings, getProactivityLevelForTask, hasExplicitFindingSignal, hasExplicitTaskSignal, hasExecutionIntent, hasDiscoveryIntent, shouldAutoCaptureFindingsForLevel, shouldAutoCaptureTaskForLevel, } from "./proactivity.js";
6
5
  export declare function normalizeMemoryScope(scope?: string | null): string | undefined;
7
6
  export declare function isMemoryScopeVisible(itemScope: string | undefined, activeScope?: string): boolean;
8
7
  export declare function impactLogFile(phrenPath: string): string;
package/dist/shared.js CHANGED
@@ -7,7 +7,6 @@ const MAX_LOG_LINES = 1000;
7
7
  export { HOOK_TOOL_NAMES, hookConfigPath } from "./provider-adapters.js";
8
8
  export { EXEC_TIMEOUT_MS, EXEC_TIMEOUT_QUICK_MS, PhrenError, phrenOk, phrenErr, forwardErr, parsePhrenErrorCode, isRecord, withDefaults, FINDING_TYPES, FINDING_TAGS, KNOWN_OBSERVATION_TAGS, DOC_TYPES, capCache, RESERVED_PROJECT_DIR_NAMES, } from "./phren-core.js";
9
9
  export { ROOT_MANIFEST_FILENAME, isInstallMode, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, lookupEventsLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, projectSlugFromPath, canonicalProjectKey, findProjectNameCaseInsensitive, findProjectNamesByCanonicalKey, findArchivedProjectNameCaseInsensitive, getProjectDirs, listInvalidProjectDirs, collectNativeMemoryFiles, nativeMemoryEnabled, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, ensurePrivateDir, ftsCacheRoot, ensureFtsCacheRootPrivate, } from "./phren-paths.js";
10
- export { PROACTIVITY_LEVELS, parseProactivityLevel, getProactivityLevel, getProactivityLevelForFindings, getProactivityLevelForTask, hasExplicitFindingSignal, hasExplicitTaskSignal, hasExecutionIntent, hasDiscoveryIntent, shouldAutoCaptureFindingsForLevel, shouldAutoCaptureTaskForLevel, } from "./proactivity.js";
11
10
  const MEMORY_SCOPE_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
12
11
  export function normalizeMemoryScope(scope) {
13
12
  if (typeof scope !== "string")
@@ -1,7 +1,3 @@
1
- /**
2
- * Command palette and input handling for the phren interactive shell.
3
- * Extracted from shell.ts to keep the orchestrator under 300 lines.
4
- */
5
1
  import { ShellState } from "../data/access.js";
6
2
  import { type DoctorResultLike, type ShellDeps, type ShellView } from "./types.js";
7
3
  import type { GraphController } from "./graph/controller.js";
@@ -52,7 +48,7 @@ export interface NavigationHost extends PaletteHost {
52
48
  }
53
49
  /**
54
50
  * The file `e` and `E` edit for the current view. Skills edit their own
55
- * markdown; a project edits the CLAUDE.md the store owns and symlinks into the
51
+ * markdown; a project edits the AGENTS.md the store owns and symlinks into the
56
52
  * repo, so editing here reaches every linked checkout.
57
53
  */
58
54
  export declare function editTargetFor(host: NavigationHost, item: {
@@ -1,3 +1,4 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
1
2
  /**
2
3
  * Command palette and input handling for the phren interactive shell.
3
4
  * Extracted from shell.ts to keep the orchestrator under 300 lines.
@@ -11,17 +12,17 @@ import { handleGovernMemories } from "../cli/govern.js";
11
12
  import { runSearch } from "../cli/search.js";
12
13
  import { consolidateProjectFindings } from "../governance/policy.js";
13
14
  import { style } from "./render.js";
14
- import { SUB_VIEWS, TAB_ICONS } from "./types.js";
15
+ import { enabledSubViews, TAB_ICONS } from "./types.js";
15
16
  import { getProjectSkills, getHookEntries, writeInstallPreferences } from "./view.js";
16
17
  import { resolveProjectStorePath } from "../cli/namespaces-utils.js";
17
18
  import { openInEditor } from "../editor/launch.js";
18
19
  import { removeSkillPath, setSkillEnabledAndSync } from "../skill/files.js";
19
- import { resultMsg, editDistance, tokenize, expandIds, normalizeSection, tasksByFilter, queueByFilter, } from "./palette.js";
20
+ import { resultMsg, editDistance, splitCommandLine, expandIds, normalizeSection, tasksByFilter, queueByFilter, } from "./palette.js";
20
21
  import { errorMessage } from "../utils.js";
21
22
  import { logger } from "../logger.js";
22
23
  /**
23
24
  * The file `e` and `E` edit for the current view. Skills edit their own
24
- * markdown; a project edits the CLAUDE.md the store owns and symlinks into the
25
+ * markdown; a project edits the AGENTS.md the store owns and symlinks into the
25
26
  * repo, so editing here reaches every linked checkout.
26
27
  */
27
28
  export function editTargetFor(host, item) {
@@ -35,7 +36,7 @@ export function editTargetFor(host, item) {
35
36
  if (!project)
36
37
  return null;
37
38
  const store = resolveProjectStorePath(host.phrenPath, project);
38
- return { path: path.join(store, project, "CLAUDE.md"), label: `${project}/CLAUDE.md`, kind: "claude" };
39
+ return { path: path.join(store, project, "AGENTS.md"), label: `${project}/AGENTS.md`, kind: "claude" };
39
40
  }
40
41
  return null;
41
42
  }
@@ -48,7 +49,7 @@ export async function executePalette(host, input) {
48
49
  const trimmed = input.trim();
49
50
  if (!trimmed)
50
51
  return;
51
- const parts = tokenize(trimmed);
52
+ const parts = splitCommandLine(trimmed);
52
53
  const command = (parts[0] || "").toLowerCase();
53
54
  if (command === "help") {
54
55
  host.showHelp = true;
@@ -396,6 +397,7 @@ export async function executePalette(host, input) {
396
397
  const lines = [];
397
398
  try {
398
399
  const conflicted = execFileSync("git", ["diff", "--name-only", "--diff-filter=U"], {
400
+ env: nonInteractiveGitEnv(),
399
401
  cwd: host.phrenPath, encoding: "utf8", timeout: 10_000,
400
402
  stdio: ["ignore", "pipe", "ignore"],
401
403
  }).trim();
@@ -450,11 +452,13 @@ export async function executePalette(host, input) {
450
452
  try {
451
453
  const projectDir = path.join(host.phrenPath, project);
452
454
  const diff = execFileSync("git", ["diff", "--no-color", "--", projectDir], {
455
+ env: nonInteractiveGitEnv(),
453
456
  cwd: host.phrenPath, encoding: "utf8", timeout: 10_000,
454
457
  stdio: ["ignore", "pipe", "ignore"],
455
458
  }).trim();
456
459
  if (!diff) {
457
460
  const staged = execFileSync("git", ["diff", "--cached", "--no-color", "--", projectDir], {
461
+ env: nonInteractiveGitEnv(),
458
462
  cwd: host.phrenPath, encoding: "utf8", timeout: 10_000,
459
463
  stdio: ["ignore", "pipe", "ignore"],
460
464
  }).trim();
@@ -521,7 +525,7 @@ export function completeInput(line, phrenPath, profile, state) {
521
525
  if (!trimmed.startsWith(":"))
522
526
  return [];
523
527
  const after = trimmed.slice(1);
524
- const parts = tokenize(after);
528
+ const parts = splitCommandLine(after);
525
529
  const endsWithSpace = /\s$/.test(trimmed);
526
530
  if (parts.length === 0)
527
531
  return commands;
@@ -1008,8 +1012,9 @@ export async function handleNavigateKey(host, rawKey) {
1008
1012
  function nextTab(host) {
1009
1013
  if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
1010
1014
  return;
1011
- const idx = SUB_VIEWS.indexOf(host.state.view);
1012
- const next = SUB_VIEWS[(idx + 1) % SUB_VIEWS.length];
1015
+ const views = enabledSubViews(host.phrenPath, host.profile);
1016
+ const idx = views.indexOf(host.state.view);
1017
+ const next = views[(idx + 1) % views.length];
1013
1018
  if (next) {
1014
1019
  host.setView(next);
1015
1020
  host.setMessage(` ${TAB_ICONS[next]} ${next}`);
@@ -1018,8 +1023,9 @@ function nextTab(host) {
1018
1023
  function prevTab(host) {
1019
1024
  if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
1020
1025
  return;
1021
- const idx = SUB_VIEWS.indexOf(host.state.view);
1022
- const prev = SUB_VIEWS[(idx - 1 + SUB_VIEWS.length) % SUB_VIEWS.length];
1026
+ const views = enabledSubViews(host.phrenPath, host.profile);
1027
+ const idx = views.indexOf(host.state.view);
1028
+ const prev = views[(idx - 1 + views.length) % views.length];
1023
1029
  if (prev) {
1024
1030
  host.setView(prev);
1025
1031
  host.setMessage(` ${TAB_ICONS[prev]} ${prev}`);
@@ -2,12 +2,12 @@ import type { TaskItem, QueueItem } from "../data/access.js";
2
2
  import { type PhrenResult } from "../shared.js";
3
3
  export declare function resultMsg(r: PhrenResult<unknown>): string;
4
4
  export declare function editDistance(a: string, b: string): number;
5
- export declare function tokenize(input: string): string[];
5
+ /** Splits a typed palette command into words on whitespace, honoring single and double quotes. */
6
+ export declare function splitCommandLine(input: string): string[];
6
7
  export declare function tasksByFilter(items: TaskItem[], filter: string): TaskItem[];
7
8
  export declare function queueByFilter(items: QueueItem[], filter: string): QueueItem[];
8
9
  export declare function expandIds(input: string): string[];
9
10
  export declare function normalizeSection(sectionRaw: string): "Active" | "Queue" | "Done" | null;
10
- export declare function resolveEntryScript(): string;
11
11
  export declare function defaultRunHooks(phrenPath: string): Promise<string>;
12
12
  export declare function defaultRunUpdate(): Promise<string>;
13
13
  export declare function defaultRunRelink(phrenPath: string): Promise<string>;
@@ -1,8 +1,7 @@
1
1
  import { execFileSync } from "child_process";
2
- import * as path from "path";
3
- import { fileURLToPath } from "url";
4
2
  import { runLink } from "../link/link.js";
5
3
  import { runPhrenUpdate } from "../update.js";
4
+ import { resolveEntryScript } from "../init/shared.js";
6
5
  import { EXEC_TIMEOUT_MS, } from "../shared.js";
7
6
  export function resultMsg(r) {
8
7
  if (!r.ok)
@@ -31,7 +30,8 @@ export function editDistance(a, b) {
31
30
  }
32
31
  return dp[m][n];
33
32
  }
34
- export function tokenize(input) {
33
+ /** Splits a typed palette command into words on whitespace, honoring single and double quotes. */
34
+ export function splitCommandLine(input) {
35
35
  const out = [];
36
36
  let current = "";
37
37
  let quote = null;
@@ -96,10 +96,6 @@ export function normalizeSection(sectionRaw) {
96
96
  return null;
97
97
  }
98
98
  // ── Infrastructure ───────────────────────────────────────────────────────────
99
- export function resolveEntryScript() {
100
- const current = fileURLToPath(import.meta.url);
101
- return path.resolve(path.dirname(current), "index.js");
102
- }
103
99
  export async function defaultRunHooks(phrenPath) {
104
100
  const entry = resolveEntryScript();
105
101
  execFileSync(process.execPath, [entry, "hook-session-start"], {
@@ -1,3 +1,4 @@
1
+ import { stripTerminal } from "../terminal-text.js";
1
2
  export declare const RESET = "\u001B[0m";
2
3
  export declare const BOLD = "\u001B[1m";
3
4
  export declare const DIM = "\u001B[2m";
@@ -28,7 +29,8 @@ export declare const style: {
28
29
  };
29
30
  export declare function badge(label: string, colorFn: (s: string) => string): string;
30
31
  export declare function separator(width?: number): string;
31
- export declare function stripAnsi(s: string): string;
32
+ /** The shell's name for {@link stripTerminal}. */
33
+ export declare const stripAnsi: typeof stripTerminal;
32
34
  /** Terminal cells occupied by `s`, ignoring any ANSI escape codes it contains. */
33
35
  export declare function displayWidth(s: string): number;
34
36
  export declare function padToWidth(s: string, width: number): string;
@@ -1,4 +1,5 @@
1
1
  // ── ANSI utilities ──────────────────────────────────────────────────────────
2
+ import { stripTerminal } from "../terminal-text.js";
2
3
  const ESC = "\x1b[";
3
4
  export const RESET = `${ESC}0m`;
4
5
  export const BOLD = `${ESC}1m`;
@@ -34,9 +35,8 @@ export function badge(label, colorFn) {
34
35
  export function separator(width = 50) {
35
36
  return style.dim("━".repeat(Math.max(1, width)));
36
37
  }
37
- export function stripAnsi(s) {
38
- return s.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "");
39
- }
38
+ /** The shell's name for {@link stripTerminal}. */
39
+ export const stripAnsi = stripTerminal;
40
40
  // ── Display width ────────────────────────────────────────────────────────────
41
41
  // String length counts UTF-16 code units, which is not what a terminal draws:
42
42
  // combining marks occupy no cell, and East Asian Wide / emoji-presentation
@@ -246,7 +246,7 @@ export function shellHelpText() {
246
246
  ` ${k("/")} ${d("filter")} ${k(":")} ${d("command palette")} ${k("Esc")} ${d("cancel / clear filter")} ${k("?")} ${d("toggle this help")}`,
247
247
  "",
248
248
  hdr("View-specific keys"),
249
- ` ${style.bold("Projects")} ${k("↵")} ${d("open project tasks")} ${k("e")}${d("/")}${k("E")} ${d("edit CLAUDE.md")} ${k("i")} ${d("cycle intro mode")}`,
249
+ ` ${style.bold("Projects")} ${k("↵")} ${d("open project tasks")} ${k("e")}${d("/")}${k("E")} ${d("edit AGENTS.md")} ${k("i")} ${d("cycle intro mode")}`,
250
250
  ` ${style.bold("Tasks")} ${k("a")} ${d("add task")} ${k("d")} ${d("toggle active/queue")} ${k("↵")} ${d("mark complete")}`,
251
251
  ` ${style.bold("Findings")} ${k("a")} ${d("tell phren")} ${k("d")} ${d("delete selected")}`,
252
252
  ` ${style.bold("Review Queue")} ${k("↵")} ${d("inspect selected item")} ${d("(read-only)")}`,
@@ -1,3 +1,4 @@
1
+ import { moduleEnabled } from "../modules/runtime.js";
1
2
  import * as fs from "fs";
2
3
  import * as path from "path";
3
4
  import { addTask, addFinding, loadShellState, saveShellState, } from "../data/access.js";
@@ -83,7 +84,7 @@ export class PhrenShell {
83
84
  if (startup.project)
84
85
  this.state.project = startup.project;
85
86
  this.graphLive = startup.live;
86
- this.state.view = startup.view ?? "Projects";
87
+ this.state.view = startup.view === "Tasks" && !moduleEnabled(phrenPath, "tasks", profile) ? "Findings" : startup.view ?? "Projects";
87
88
  this.message = startup.notice
88
89
  ? ` ${style.yellow("⚠")} ${startup.notice}`
89
90
  : this.state.view === "Graph"
@@ -145,6 +146,8 @@ export class PhrenShell {
145
146
  this.setMessage(`${label} ${style.boldCyan("y")} ${style.dim("confirm")} ${style.boldCyan("n")} ${style.dim("cancel")}`);
146
147
  }
147
148
  setView(view) {
149
+ if (view === "Tasks" && !moduleEnabled(this.phrenPath, "tasks", this.profile))
150
+ view = "Findings";
148
151
  if (this.state.view === "Graph" && view !== "Graph")
149
152
  this._graph?.stopAnimation();
150
153
  const hadMouse = this.state.view === "Graph";
@@ -26,4 +26,5 @@ export interface DoctorResultLike {
26
26
  profile?: string;
27
27
  checks: DoctorCheck[];
28
28
  }
29
+ export declare function enabledSubViews(store: string, profile?: string): readonly typeof SUB_VIEWS[number][];
29
30
  export {};
@@ -1,3 +1,4 @@
1
+ import { moduleEnabled } from "../modules/runtime.js";
1
2
  // Projects is level 0 (the home screen); these sub-views are level 1 (drill-down into a project)
2
3
  // Health is NOT a sub-view — it's a global overlay accessible from anywhere via [h]
3
4
  export const SUB_VIEWS = ["Tasks", "Findings", "Review Queue", "Skills", "Hooks"];
@@ -12,3 +13,6 @@ export const TAB_ICONS = {
12
13
  Graph: "❖",
13
14
  };
14
15
  export const MAX_UNDO_STACK = 10;
16
+ export function enabledSubViews(store, profile) {
17
+ return moduleEnabled(store, "tasks", profile) ? SUB_VIEWS : SUB_VIEWS.filter(view => view !== "Tasks");
18
+ }
@@ -1,7 +1,3 @@
1
- /**
2
- * View rendering functions for the phren interactive shell.
3
- * Extracted from shell.ts to keep the orchestrator under 300 lines.
4
- */
5
1
  import { ShellState } from "../data/access.js";
6
2
  import { type DoctorResultLike } from "./types.js";
7
3
  import type { GraphController } from "./graph/controller.js";
@@ -1,42 +1,31 @@
1
+ import { moduleEnabled } from "../modules/runtime.js";
1
2
  /**
2
3
  * View rendering functions for the phren interactive shell.
3
4
  * Extracted from shell.ts to keep the orchestrator under 300 lines.
4
5
  */
6
+ import { projectMemoryCounts } from "../content/summarize.js";
5
7
  import * as fs from "fs";
6
8
  import * as path from "path";
7
9
  import { canonicalTaskFilePath, listProjectCards, readTasks, readFindings, readReviewQueue, readRuntimeHealth, resolveTaskFilePath, } from "../data/access.js";
8
- import { getNonPrimaryStores } from "../store-registry.js";
9
10
  import { style, badge, separator, stripAnsi, truncateLine, displayWidth, renderWidth, wrapSegments, lineViewport, shellHelpText, gradient, } from "./render.js";
10
11
  import { formatSelectableLine, viewportWithStatus, } from "./view-list.js";
11
- import { SUB_VIEWS, TAB_ICONS, } from "./types.js";
12
+ import { SUB_VIEWS, enabledSubViews, TAB_ICONS, } from "./types.js";
12
13
  import { tasksByFilter, queueByFilter, } from "./palette.js";
13
14
  import { listMachines, listProfiles, } from "../data/access.js";
14
15
  import { readInstallPreferences } from "../init/preferences.js";
15
16
  import { isProjectHookEnabled, readProjectConfig } from "../project-config.js";
16
17
  import { getScopedSkills } from "../skill/registry.js";
17
18
  import { errorMessage } from "../utils.js";
19
+ import { resolveProjectStorePath } from "../cli/namespaces-utils.js";
18
20
  import { logger } from "../logger.js";
19
21
  import { renderGraphView, graphSummary } from "./graph/graph-view.js";
20
- /** Resolve which store (primary or team) contains a project */
21
- function resolveProjectStorePath(phrenPath, project) {
22
- if (fs.existsSync(path.join(phrenPath, project)))
23
- return phrenPath;
24
- try {
25
- for (const store of getNonPrimaryStores(phrenPath)) {
26
- if (fs.existsSync(path.join(store.path, project)))
27
- return store.path;
28
- }
29
- }
30
- catch { /* fall through */ }
31
- return phrenPath;
32
- }
33
22
  // ── Tab bar ────────────────────────────────────────────────────────────────
34
23
  /**
35
24
  * The whole top of the frame in as few rows as possible: brand, current view,
36
25
  * project and filter on one line, then a rule. On a 24-row terminal the old
37
26
  * three-row header cost more than a tenth of the screen.
38
27
  */
39
- function renderTopBar(state, summary = "") {
28
+ function renderTopBar(state, summary = "", views = SUB_VIEWS) {
40
29
  const cols = renderWidth();
41
30
  const brand = gradient("◆ phren");
42
31
  const dot = style.dim("·");
@@ -51,8 +40,8 @@ function renderTopBar(state, summary = "") {
51
40
  // Sub-views carry a tab strip. Try full labels, then icons for the inactive
52
41
  // tabs, before giving up and taking a second row.
53
42
  const head = ` ${brand}${project ? ` ${project}` : ""}${filter ? ` ${filter}` : ""}`;
54
- const full = SUB_VIEWS.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(`${TAB_ICONS[v]} ${v}`)));
55
- const terse = SUB_VIEWS.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(TAB_ICONS[v] ?? "")));
43
+ const full = views.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(`${TAB_ICONS[v]} ${v}`)));
44
+ const terse = views.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(TAB_ICONS[v] ?? "")));
56
45
  for (const tabs of [full, terse]) {
57
46
  const merged = `${head} ${style.dim("│")} ${tabs.join(style.dim(" │ "))}`;
58
47
  if (displayWidth(merged) <= cols)
@@ -83,7 +72,7 @@ function renderBottomBar(state, navMode, inputCtx, inputBuf) {
83
72
  // Only what you reach for constantly. Everything else is one `?` away, so
84
73
  // the bar never costs more than a single row.
85
74
  const essentials = {
86
- Projects: [`${k("↑↓")} ${d("move")}`, `${k("↵")} ${d("open")}`, `${k("e")} ${d("edit CLAUDE.md")}`],
75
+ Projects: [`${k("↑↓")} ${d("move")}`, `${k("↵")} ${d("open")}`, `${k("e")} ${d("edit AGENTS.md")}`],
87
76
  Tasks: [`${k("↑↓")} ${d("move")}`, `${k("a")} ${d("add")}`, `${k("↵")} ${d("done")}`],
88
77
  Findings: [`${k("↑↓")} ${d("move")}`, `${k("a")} ${d("add")}`],
89
78
  "Review Queue": [`${k("↑↓")} ${d("move")}`, `${k("↵")} ${d("inspect")}`],
@@ -134,12 +123,14 @@ function collectProjectDashboardEntries(ctx) {
134
123
  ...card,
135
124
  activeCount: task.ok ? task.data.items.Active.length : 0,
136
125
  queueCount: task.ok ? task.data.items.Queue.length : 0,
137
- findingCount: findings.ok ? findings.data.length : 0,
126
+ // Everything the project holds, archive included, as every graph shows it.
127
+ findingCount: findings.ok ? projectMemoryCounts(storePath, card.name).findings : 0,
138
128
  reviewCount: review.ok ? review.data.length : 0,
139
129
  };
140
130
  });
141
131
  }
142
132
  function renderProjectsDashboard(ctx, entries, height) {
133
+ const tasksEnabled = moduleEnabled(ctx.phrenPath, "tasks", ctx.profile);
143
134
  const runtime = readRuntimeHealth(ctx.phrenPath);
144
135
  const scoped = entries.filter((entry) => entry.name !== "global");
145
136
  const totals = scoped.reduce((acc, entry) => {
@@ -158,15 +149,16 @@ function renderProjectsDashboard(ctx, entries, height) {
158
149
  .slice(0, 3)
159
150
  .map((entry) => `${style.bold(entry.name)} ${style.dim(`${entry.findingCount} findings`)}`);
160
151
  const lines = [
161
- ` ${badge(ctx.profile || "default", style.boldBlue)} ${style.bold(String(scoped.length))} projects ${style.dim("·")} ${style.boldGreen(String(totals.active))} active ${style.dim("·")} ${style.boldYellow(String(totals.queue))} queued ${style.dim("·")} ${style.boldCyan(String(totals.findings))} findings ${style.dim("·")} ${style.boldMagenta(String(totals.review))} review`,
152
+ ` ${badge(ctx.profile || "default", style.boldBlue)} ${style.bold(String(scoped.length))} projects ${style.dim("·")} ${tasksEnabled ? `${style.boldGreen(String(totals.active))} active ${style.dim("·")} ${style.boldYellow(String(totals.queue))} queued ${style.dim("·")} ` : ""}${style.boldCyan(String(totals.findings))} findings ${style.dim("·")} ${style.boldMagenta(String(totals.review))} review`,
162
153
  ctx.state.project
163
- ? ` ${style.green("●")} active context ${style.boldCyan(ctx.state.project)} ${style.dim("· ↵ opens selected project tasks")}`
164
- : ` ${style.dim("No project selected yet")} ${style.dim("· ↵ sets context and opens tasks")}`,
154
+ ? ` ${style.green("●")} active context ${style.boldCyan(ctx.state.project)} ${style.dim(tasksEnabled ? "· ↵ opens selected project tasks" : "· ↵ opens selected project findings")}`
155
+ : ` ${style.dim("No project selected yet")} ${style.dim(tasksEnabled ? "· ↵ sets context and opens tasks" : "· ↵ sets context and opens findings")}`,
165
156
  ` ${style.dim("Sync")} ${style.dim(runtime.lastSync?.lastPushStatus || runtime.lastAutoSave?.status || "unknown")} ${style.dim("·")} ${style.dim("unsynced")} ${style.bold(String(runtime.lastSync?.unsyncedCommits ?? 0))} ${style.dim("·")} ${style.dim("intro")} ${style.cyan(ctx.state.introMode || "once-per-version")}`,
166
157
  ];
167
158
  if (height >= 12) {
168
159
  lines.push("");
169
- lines.push(` ${style.bold("Task pulse")} ${activePreview.length ? activePreview.join(style.dim(" · ")) : style.dim("No active tasks across this profile.")}`);
160
+ if (tasksEnabled)
161
+ lines.push(` ${style.bold("Task pulse")} ${activePreview.length ? activePreview.join(style.dim(" · ")) : style.dim("No active tasks across this profile.")}`);
170
162
  lines.push(` ${style.bold("Recent fragments")} ${findingsPreview.length ? findingsPreview.join(style.dim(" · ")) : style.dim("Nothing yet.")}`);
171
163
  }
172
164
  lines.push("");
@@ -196,7 +188,7 @@ function renderProjectsView(ctx, cursor, height) {
196
188
  const cursorChar = isSelected ? style.cyan("▶") : " ";
197
189
  const bullet = isActive ? style.green("●") : style.dim("○");
198
190
  const nameStr = isActive ? style.boldGreen(card.name) : style.bold(card.name);
199
- const docsStr = style.dim(`[A${card.activeCount} · Q${card.queueCount} · F${card.findingCount} · R${card.reviewCount}]`);
191
+ const docsStr = style.dim(`[${moduleEnabled(ctx.phrenPath, "tasks", ctx.profile) ? `A${card.activeCount} · Q${card.queueCount} · ` : ""}F${card.findingCount} · R${card.reviewCount}]`);
200
192
  const storeStr = card.store ? ` ${style.dim("·")} ${style.cyan(card.store)}` : "";
201
193
  let nameRow = ` ${cursorChar} ${bullet} ${nameStr} ${docsStr}${storeStr}`;
202
194
  let summaryRow = ` ${style.dim(card.summary || "No summary yet.")}`;
@@ -671,7 +663,7 @@ function renderHealthView(phrenPath, doctor, cursor, height, currentScroll, setS
671
663
  // ── Main render ────────────────────────────────────────────────────────────
672
664
  export async function renderShell(ctx, navMode, inputCtx, inputBuf, showHelp, helpScroll, message, doctorSnapshot, subsectionsCache, setHealthLineCount, setSubsectionsCache) {
673
665
  const graphSummaryLine = ctx.state.view === "Graph" && ctx.graph ? graphSummary(ctx.graph()) : "";
674
- const topBar = renderTopBar(ctx.state, graphSummaryLine);
666
+ const topBar = renderTopBar(ctx.state, graphSummaryLine, enabledSubViews(ctx.phrenPath, ctx.profile));
675
667
  const bottomBar = renderBottomBar(ctx.state, navMode, inputCtx, inputBuf);
676
668
  const cursor = ctx.currentCursor();
677
669
  // An empty message line used to hold a row open on every frame.
@@ -681,7 +673,7 @@ export async function renderShell(ctx, navMode, inputCtx, inputBuf, showHelp, he
681
673
  if (showHelp) {
682
674
  // The help is longer than a small terminal, and used to be clipped in
683
675
  // silence — on 24 rows more than half of it simply was not there.
684
- const all = shellHelpText().split("\n");
676
+ const all = shellHelpText().split("\n").filter(line => moduleEnabled(ctx.phrenPath, "tasks", ctx.profile) || !/task/i.test(stripAnsi(line)));
685
677
  if (all.length <= height) {
686
678
  contentLines = all;
687
679
  }