@phren/cli 0.2.14 → 0.2.16

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 (387) 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 +193 -2
  7. package/dist/bridge/agent-hooks.js +1045 -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 +22 -0
  15. package/dist/bridge/code-note.js +42 -0
  16. package/dist/bridge/code-routes.d.ts +133 -0
  17. package/dist/bridge/code-routes.js +319 -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 +123 -0
  33. package/dist/bridge/dispatch-returns.js +279 -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 +207 -0
  37. package/dist/bridge/dispatch.js +261 -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 +32 -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 +42 -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 +52 -0
  96. package/dist/bridge/schedule-watch.js +242 -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 +29 -0
  104. package/dist/bridge/server-pane-routes.js +400 -0
  105. package/dist/bridge/server-routes.d.ts +106 -0
  106. package/dist/bridge/server-routes.js +538 -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 +94 -0
  136. package/dist/bridge/transcript-preview.js +476 -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 +41246 -21385
  146. package/dist/cli/actions.js +14 -1
  147. package/dist/cli/config-proactivity.d.ts +3 -1
  148. package/dist/cli/config-proactivity.js +35 -3
  149. package/dist/cli/config.js +4 -1
  150. package/dist/cli/extract.js +3 -6
  151. package/dist/cli/govern.js +5 -2
  152. package/dist/cli/hooks-globs.js +1 -1
  153. package/dist/cli/hooks.d.ts +1 -1
  154. package/dist/cli/hooks.js +9 -7
  155. package/dist/cli/namespaces-projects.js +12 -6
  156. package/dist/cli/namespaces-store.js +37 -6
  157. package/dist/cli/namespaces-tasks.js +1 -1
  158. package/dist/cli/schedules.d.ts +1 -0
  159. package/dist/cli/schedules.js +164 -0
  160. package/dist/cli/session-background.js +1 -1
  161. package/dist/cli/session-git.d.ts +8 -5
  162. package/dist/cli/session-git.js +45 -120
  163. package/dist/cli/session-start.js +3 -1
  164. package/dist/cli/session-stop.js +19 -8
  165. package/dist/cli/team.js +13 -10
  166. package/dist/cli-handlers.d.ts +1 -1
  167. package/dist/cli-handlers.js +8 -4
  168. package/dist/cli-help.d.ts +5 -4
  169. package/dist/cli-help.js +15 -15
  170. package/dist/cli-registry.d.ts +4 -1
  171. package/dist/cli-registry.js +119 -6
  172. package/dist/content/archive.js +2 -2
  173. package/dist/content/citation.d.ts +11 -0
  174. package/dist/content/citation.js +18 -0
  175. package/dist/content/learning.js +2 -0
  176. package/dist/content/summarize.d.ts +14 -15
  177. package/dist/content/summarize.js +60 -5
  178. package/dist/content/validate.d.ts +3 -1
  179. package/dist/content/validate.js +26 -8
  180. package/dist/core/project-registry.d.ts +26 -0
  181. package/dist/core/project-registry.js +573 -0
  182. package/dist/core/project.js +2 -3
  183. package/dist/data/access.d.ts +7 -1
  184. package/dist/data/access.js +13 -3
  185. package/dist/data/tasks.d.ts +18 -3
  186. package/dist/data/tasks.js +8 -7
  187. package/dist/entrypoint.js +44 -10
  188. package/dist/fanout/adapters/claude.d.ts +2 -0
  189. package/dist/fanout/adapters/claude.js +7 -0
  190. package/dist/fanout/adapters/codex.d.ts +2 -0
  191. package/dist/fanout/adapters/codex.js +9 -0
  192. package/dist/fanout/adapters/opencode.d.ts +4 -0
  193. package/dist/fanout/adapters/opencode.js +9 -0
  194. package/dist/fanout/adapters/types.d.ts +21 -0
  195. package/dist/fanout/adapters/types.js +3 -0
  196. package/dist/fanout/command.d.ts +2 -0
  197. package/dist/fanout/command.js +78 -0
  198. package/dist/fanout/launcher.d.ts +27 -0
  199. package/dist/fanout/launcher.js +156 -0
  200. package/dist/fanout/opencode-serve.d.ts +24 -0
  201. package/dist/fanout/opencode-serve.js +191 -0
  202. package/dist/fanout/picker.d.ts +91 -0
  203. package/dist/fanout/picker.js +51 -0
  204. package/dist/fanout/usage.d.ts +5 -0
  205. package/dist/fanout/usage.js +51 -0
  206. package/dist/fanout/watchdog.d.ts +10 -0
  207. package/dist/fanout/watchdog.js +27 -0
  208. package/dist/filenames.d.ts +9 -0
  209. package/dist/filenames.js +11 -0
  210. package/dist/finding/context.js +4 -22
  211. package/dist/generated/memory-ui-graph.browser.js +279 -283
  212. package/dist/governance/policy-constants.d.ts +11 -0
  213. package/dist/governance/policy-constants.js +9 -0
  214. package/dist/governance/policy.d.ts +5 -8
  215. package/dist/governance/policy.js +7 -5
  216. package/dist/graph-core/camera.d.ts +24 -0
  217. package/dist/graph-core/camera.js +18 -0
  218. package/dist/graph-core/index.d.ts +2 -0
  219. package/dist/graph-core/index.js +2 -0
  220. package/dist/graph-core/labels.d.ts +77 -0
  221. package/dist/graph-core/labels.js +124 -0
  222. package/dist/graph-core/model.d.ts +13 -0
  223. package/dist/graph-core/model.js +33 -0
  224. package/dist/graph-core/types.d.ts +2 -0
  225. package/dist/home-paths.d.ts +7 -0
  226. package/dist/home-paths.js +21 -0
  227. package/dist/hooks.d.ts +3 -0
  228. package/dist/hooks.js +13 -0
  229. package/dist/index.js +24 -2
  230. package/dist/init/guard-globals.d.ts +1 -1
  231. package/dist/init/guard-globals.js +4 -4
  232. package/dist/init/init-configure.js +3 -3
  233. package/dist/init/init-uninstall.js +2 -2
  234. package/dist/init/init-walkthrough.d.ts +2 -0
  235. package/dist/init/init-walkthrough.js +17 -6
  236. package/dist/init/init.js +26 -6
  237. package/dist/init/management-preset.d.ts +1 -1
  238. package/dist/init/management-preset.js +2 -2
  239. package/dist/init/preferences.js +1 -1
  240. package/dist/init/self-wiring.js +1 -1
  241. package/dist/init/setup.d.ts +3 -26
  242. package/dist/init/setup.js +49 -588
  243. package/dist/init/shared.js +2 -0
  244. package/dist/init/store-gitignore.d.ts +1 -1
  245. package/dist/init/store-gitignore.js +2 -0
  246. package/dist/init/teardown.d.ts +1 -1
  247. package/dist/init/teardown.js +2 -2
  248. package/dist/link/context.js +1 -1
  249. package/dist/link/doctor.d.ts +22 -1
  250. package/dist/link/doctor.js +100 -54
  251. package/dist/link/link.js +29 -61
  252. package/dist/link/refresh.js +2 -2
  253. package/dist/link/skills.js +26 -5
  254. package/dist/machine-identity.d.ts +3 -0
  255. package/dist/machine-identity.js +6 -0
  256. package/dist/mcp/profile.d.ts +2 -15
  257. package/dist/mcp/profile.js +64 -9
  258. package/dist/memory-ui-graph.runtime.js +279 -283
  259. package/dist/modules/code-package.d.ts +16 -0
  260. package/dist/modules/code-package.js +152 -0
  261. package/dist/modules/command.d.ts +2 -0
  262. package/dist/modules/command.js +67 -0
  263. package/dist/modules/config.d.ts +4 -0
  264. package/dist/modules/config.js +70 -0
  265. package/dist/modules/manifest.d.ts +41 -0
  266. package/dist/modules/manifest.js +1 -0
  267. package/dist/modules/provision.d.ts +3 -0
  268. package/dist/modules/provision.js +84 -0
  269. package/dist/modules/registry.d.ts +16 -0
  270. package/dist/modules/registry.js +250 -0
  271. package/dist/modules/runtime.d.ts +15 -0
  272. package/dist/modules/runtime.js +59 -0
  273. package/dist/package-metadata.js +10 -2
  274. package/dist/phren-dotenv.js +4 -2
  275. package/dist/phren-paths.d.ts +3 -2
  276. package/dist/phren-paths.js +4 -5
  277. package/dist/profile-store.js +4 -5
  278. package/dist/project-config.d.ts +19 -1
  279. package/dist/project-config.js +29 -3
  280. package/dist/project-topics.js +4 -4
  281. package/dist/provider-adapters.js +1 -4
  282. package/dist/query-correlation.js +6 -6
  283. package/dist/session/artifacts.js +5 -5
  284. package/dist/session/checkpoints.js +5 -0
  285. package/dist/session/utils.d.ts +2 -2
  286. package/dist/session/utils.js +6 -6
  287. package/dist/shared/content.d.ts +1 -1
  288. package/dist/shared/content.js +1 -1
  289. package/dist/shared/data-utils.js +1 -1
  290. package/dist/shared/fragment-graph.d.ts +1 -1
  291. package/dist/shared/fragment-graph.js +5 -5
  292. package/dist/shared/index.js +48 -7
  293. package/dist/shared/retrieval.d.ts +18 -1
  294. package/dist/shared/retrieval.js +100 -11
  295. package/dist/shared/search-fallback.js +4 -6
  296. package/dist/shared/sqljs.d.ts +2 -0
  297. package/dist/shared/sqljs.js +4 -2
  298. package/dist/shared.d.ts +0 -1
  299. package/dist/shared.js +0 -1
  300. package/dist/shell/input.d.ts +1 -5
  301. package/dist/shell/input.js +16 -10
  302. package/dist/shell/palette.d.ts +2 -2
  303. package/dist/shell/palette.js +3 -7
  304. package/dist/shell/render.d.ts +3 -1
  305. package/dist/shell/render.js +4 -4
  306. package/dist/shell/shell.js +4 -1
  307. package/dist/shell/types.d.ts +1 -0
  308. package/dist/shell/types.js +4 -0
  309. package/dist/shell/view.d.ts +0 -4
  310. package/dist/shell/view.js +19 -27
  311. package/dist/skill/registry.js +25 -17
  312. package/dist/skill/state.d.ts +3 -0
  313. package/dist/skill/state.js +13 -7
  314. package/dist/status.js +38 -17
  315. package/dist/store-registry.d.ts +44 -18
  316. package/dist/store-registry.js +169 -60
  317. package/dist/store-weight.d.ts +1 -6
  318. package/dist/store-weight.js +4 -2
  319. package/dist/sync/auth-doctor.d.ts +8 -0
  320. package/dist/sync/auth-doctor.js +27 -0
  321. package/dist/sync/auth.d.ts +27 -0
  322. package/dist/sync/auth.js +114 -0
  323. package/dist/sync/conflict-resolve.d.ts +9 -0
  324. package/dist/sync/conflict-resolve.js +146 -0
  325. package/dist/sync/git-state.d.ts +4 -0
  326. package/dist/sync/git-state.js +49 -0
  327. package/dist/sync/outcome.d.ts +34 -0
  328. package/dist/sync/outcome.js +57 -0
  329. package/dist/sync/pull.d.ts +15 -7
  330. package/dist/sync/pull.js +84 -35
  331. package/dist/sync/store-merge.d.ts +29 -0
  332. package/dist/sync/store-merge.js +137 -0
  333. package/dist/sync/task-merge.d.ts +22 -0
  334. package/dist/sync/task-merge.js +158 -0
  335. package/dist/task/github.js +1 -1
  336. package/dist/task/lifecycle.d.ts +5 -0
  337. package/dist/task/lifecycle.js +67 -23
  338. package/dist/terminal-text.d.ts +5 -0
  339. package/dist/terminal-text.js +11 -0
  340. package/dist/test-global-setup.js +7 -0
  341. package/dist/tool-registry.d.ts +1 -1
  342. package/dist/tool-registry.js +3 -1
  343. package/dist/tools/code.d.ts +3 -0
  344. package/dist/tools/code.js +178 -0
  345. package/dist/tools/config.js +5 -0
  346. package/dist/tools/data.js +14 -7
  347. package/dist/tools/dispatch.d.ts +2 -0
  348. package/dist/tools/dispatch.js +66 -0
  349. package/dist/tools/finding.js +43 -41
  350. package/dist/tools/ops.js +5 -2
  351. package/dist/tools/search.js +21 -8
  352. package/dist/tools/session.js +21 -22
  353. package/dist/tools/tasks.js +8 -2
  354. package/dist/tools/types.d.ts +2 -2
  355. package/dist/tools/types.js +2 -2
  356. package/dist/ui/assets.js +1 -1
  357. package/dist/ui/data.js +14 -15
  358. package/dist/ui/deep-void.d.ts +1 -1
  359. package/dist/ui/deep-void.js +0 -1
  360. package/dist/ui/graph-chrome.d.ts +1 -1
  361. package/dist/ui/graph-chrome.js +51 -0
  362. package/dist/ui/page.js +5 -5
  363. package/dist/ui/scripts.js +67 -30
  364. package/dist/ui/server.js +34 -6
  365. package/dist/update.js +1 -1
  366. package/dist/utils-fts.js +1 -0
  367. package/dist/utils-helpers.d.ts +7 -0
  368. package/dist/utils-helpers.js +17 -0
  369. package/dist/utils.d.ts +1 -1
  370. package/dist/utils.js +1 -1
  371. package/package.json +45 -3
  372. package/plugins/opencode/phren-transcript.js +340 -0
  373. package/starter/README.md +4 -4
  374. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  375. package/starter/global/skills/conductor/SKILL.md +106 -0
  376. package/starter/global/skills/fanout/SKILL.md +20 -0
  377. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  378. package/starter/global/skills/phren-init/SKILL.md +4 -4
  379. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  380. package/starter/templates/frontend/reference/README.md +1 -1
  381. package/starter/templates/library/reference/README.md +1 -1
  382. package/starter/templates/monorepo/reference/README.md +1 -1
  383. package/starter/templates/python-project/reference/README.md +1 -1
  384. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  385. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  386. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  387. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -1,11 +1,10 @@
1
1
  import * as fs from "fs";
2
- import { addTask, completeTask, readTasks, resolveTaskItem, updateTask, } from "../data/access.js";
2
+ import { addTask, readTasks, resolveTaskItem, updateTask, } from "../data/access.js";
3
3
  import { parseGithubIssueUrl, resolveProjectGithubRepo } from "./github.js";
4
- import { getProactivityLevelForTask, shouldAutoCaptureTaskForLevel, hasExecutionIntent, hasDiscoveryIntent, hasSuppressTaskIntent, hasCodeChangeContext } from "../proactivity.js";
4
+ import { getProactivityLevelForTask, shouldAutoCaptureTaskForLevel, hasExecutionIntent, hasDiscoveryIntent, hasExplicitTaskSignal, hasSuppressTaskIntent, hasCodeChangeContext } from "../proactivity.js";
5
5
  import { getWorkflowPolicy } from "../shared/governance.js";
6
6
  import { debugLog, sessionMarker } from "../shared.js";
7
7
  import { errorMessage } from "../utils.js";
8
- import { incrementSessionTasksCompleted } from "../tools/session.js";
9
8
  const ACTION_PREFIX_RE = /^(?:please\s+|can you\s+|could you\s+|would you\s+|i want you to\s+|i want to\s+|let(?:'|’)s\s+|lets\s+|help me\s+)/i;
10
9
  const EXPLICIT_TASK_PREFIX_RE = /^(?:add(?:\s+(?:this|that|it))?\s+(?:to\s+(?:the\s+)?)?(?:task|todo(?:\s+list)?|task(?:\s+list)?)|add\s+(?:a\s+)?task|put(?:\s+(?:this|that|it))?\s+(?:in|on)\s+(?:the\s+)?(?:task|todo(?:\s+list)?|task(?:\s+list)?))\s*(?::|-|,)?\s*/i;
11
10
  const NON_ACTIONABLE_RE = /\b(brainstorm|idea|ideas|maybe|what if|should we|could we|would it make sense|question|explain|why is|how does)\b/i;
@@ -40,6 +39,39 @@ const PASTED_CONTENT_RE = new RegExp([
40
39
  // because the observed echoes wrap filler around an incidental verb — "Its literally just the
41
40
  // start of the day LMAO" clears the substance floor on "start" but is not a task.
42
41
  const CONVERSATIONAL_FILLER_RE = /\b(?:lmao|lmfao|rofl|lol+|haha+|idk|idc|tbh|ngl|smh|wtf|meh|yolo)\b/i;
42
+ // Claude Code wraps bracketed-paste input as <pasted_content id="…">…</pasted_content id="…">:
43
+ // any multi-line paste, every message typed in from the phone, and every message another
44
+ // agent relays into the pane. The text inside cannot be told apart from someone else's
45
+ // words (a relayed conductor message rewrote a task's Context three times), so it never
46
+ // files or touches a task; only what was typed outside the wrapper counts.
47
+ const PASTED_CONTENT_WRAPPER_RE = /<pasted_content\b[^>]*>[\s\S]*?<\/pasted_content\b[^>]*>/g;
48
+ // A message relayed from another agent: "From the conductor, a correction: …",
49
+ // "From tidy-phren: …". One name (optionally after "the"), then a comma or colon.
50
+ const RELAYED_MESSAGE_RE = /^\s*from\s+(?:the\s+)?(?!(?:now|here|there|then|scratch|today|tomorrow)\b)[\w.-]+\s*[,:]/i;
51
+ // Frames another agent or the harness put in the prompt: a cross-session message, a
52
+ // sub-agent hand-back, a delivery/idle notice, a task or system notification, a system
53
+ // reminder. Not the person's request. Matched anywhere, since a harness may put the
54
+ // person's own words inside or after one of these, and a frame is never worth a task.
55
+ const AGENT_FRAME_RE = /<\/?(?:agent-message|cross-session-message|task-notification|system-reminder|system-notification|phren-notice|command-name|command-message)\b|\[(?:SYSTEM NOTIFICATION|Cross-session (?:delivery|idle) notice)\b/i;
56
+ // A reply to the agent — "Yep /herdr the phren agent is there" — starts with an
57
+ // acknowledgement and asks for nothing; a question ends with one.
58
+ const REPLY_OPENER_RE = /^(?:yep|yeah|yes|yup|ya|nah|no|nope|ok|okay|right|correct|exactly|indeed|true|sure|fine|agreed|(?:just\s+)?curious|(?:i(?:'|’)?m\s+)?wondering|i wonder)\b/i;
59
+ const QUESTION_RE = /\?\s*$/;
60
+ /** What the person typed: the prompt without pasted blocks. */
61
+ export function typedPromptText(prompt) {
62
+ return prompt.includes("<pasted_content") ? prompt.replace(PASTED_CONTENT_WRAPPER_RE, " ").trim() : prompt;
63
+ }
64
+ /** A frame from another agent or the harness, or a message relayed from one,
65
+ * rather than something the person asked. */
66
+ export function isAgentFramePrompt(prompt) {
67
+ return AGENT_FRAME_RE.test(prompt) || RELAYED_MESSAGE_RE.test(prompt);
68
+ }
69
+ /** A reply or a question: conversation with the agent, not a request for work. */
70
+ function isConversationalTurn(prompt) {
71
+ if (QUESTION_RE.test(prompt))
72
+ return true;
73
+ return REPLY_OPENER_RE.test(prompt) && !hasExplicitTaskSignal(prompt) && !hasExecutionIntent(prompt);
74
+ }
43
75
  const ACTIONABLE_RE = /\b(add|build|change|complete|continue|create|delete|fix|implement|improve|investigate|make|move|refactor|remove|rename|repair|ship|start|update|wire)\b/i;
44
76
  const CONTINUE_RE = /\b(continue|keep going|finish|resume|pick up|work on that|that task)\b/i;
45
77
  const GITHUB_URL_RE = /https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/\d+(?:[?#][^\s]*)?/g;
@@ -149,6 +181,10 @@ function isActionablePrompt(prompt, intent) {
149
181
  return false;
150
182
  if (CONVERSATIONAL_FILLER_RE.test(normalized))
151
183
  return false;
184
+ if (isAgentFramePrompt(normalized))
185
+ return false;
186
+ if (isConversationalTurn(normalized))
187
+ return false;
152
188
  // Substance floor — independent of intent / proactivity. Short utterances without
153
189
  // any actionable signal are conversational fragments, not tasks.
154
190
  if (!hasMinimumTaskSubstance(normalized))
@@ -272,24 +308,31 @@ export function handleTaskPromptLifecycle(args) {
272
308
  if (mode === "off" || mode === "manual" || !args.project || !args.sessionId) {
273
309
  return { mode, noticeLines: [] };
274
310
  }
311
+ // A sub-agent hand-back, a system notification or a harness reminder arrives as a
312
+ // prompt but nobody typed it: it never creates, moves or reuses a task.
313
+ if (isAgentFramePrompt(args.prompt)) {
314
+ debugLog(`task lifecycle skipped ${args.project}: machine-originated prompt`);
315
+ return { mode, noticeLines: [] };
316
+ }
317
+ const prompt = typedPromptText(args.prompt);
275
318
  // Suppression takes absolute priority — user explicitly said not to create a task.
276
- if (hasSuppressTaskIntent(args.prompt)) {
319
+ if (hasSuppressTaskIntent(prompt)) {
277
320
  debugLog(`task lifecycle suppressed ${args.project}: suppress-task intent detected`);
278
321
  return { mode, noticeLines: [] };
279
322
  }
280
- if (!isActionablePrompt(args.prompt, args.intent)) {
323
+ if (!isActionablePrompt(prompt, args.intent)) {
281
324
  return { mode, noticeLines: [] };
282
325
  }
283
326
  const taskLevel = args.taskLevel ?? getProactivityLevelForTask(args.phrenPath);
284
- if (mode === "auto" && !shouldAutoCaptureTaskForLevel(taskLevel, args.prompt)) {
327
+ if (mode === "auto" && !shouldAutoCaptureTaskForLevel(taskLevel, prompt)) {
285
328
  debugLog(`task lifecycle skipped ${args.project}: task proactivity=${taskLevel}`);
286
329
  return { mode, noticeLines: [] };
287
330
  }
288
331
  const parsed = readTasks(args.phrenPath, args.project);
289
332
  if (!parsed.ok)
290
333
  return { mode, noticeLines: [] };
291
- const summary = normalizeTaskSummary(args.prompt);
292
- const issueMeta = extractGithubMetadata(args.phrenPath, args.project, args.prompt);
334
+ const summary = normalizeTaskSummary(prompt);
335
+ const issueMeta = extractGithubMetadata(args.phrenPath, args.project, prompt);
293
336
  const trackedState = readTaskSessionState(args.phrenPath, args.sessionId);
294
337
  const trackedItem = trackedState && trackedState.project === args.project
295
338
  ? resolveTrackedSessionTask(args.phrenPath, trackedState)
@@ -297,7 +340,7 @@ export function handleTaskPromptLifecycle(args) {
297
340
  const activeItems = parsed.data.items.Active;
298
341
  const reusable = trackedItem && trackedItem.section === "Active"
299
342
  ? trackedItem
300
- : matchExistingActiveTask(args.prompt, activeItems);
343
+ : matchExistingActiveTask(prompt, activeItems);
301
344
  if (mode === "suggest") {
302
345
  const line = reusable?.line || summary;
303
346
  return {
@@ -308,7 +351,7 @@ export function handleTaskPromptLifecycle(args) {
308
351
  // Intent-aware auto mode: if the user is in discovery mode (brainstorming,
309
352
  // exploring ideas) and NOT in execution mode (approving, committing to work,
310
353
  // or performing code changes), create a speculative task and surface a suggestion.
311
- if (mode === "auto" && !hasExecutionIntent(args.prompt) && !hasCodeChangeContext(args.prompt) && hasDiscoveryIntent(args.prompt)) {
354
+ if (mode === "auto" && !hasExecutionIntent(prompt) && !hasCodeChangeContext(prompt) && hasDiscoveryIntent(prompt)) {
312
355
  const line = reusable?.line || summary;
313
356
  debugLog(`task lifecycle auto→speculative ${args.project}: discovery intent detected`);
314
357
  if (!reusable) {
@@ -334,12 +377,15 @@ export function handleTaskPromptLifecycle(args) {
334
377
  return { mode, noticeLines: [] };
335
378
  }
336
379
  }
337
- const update = updateTask(args.phrenPath, args.project, targetMatch || summary, {
338
- section: "active",
339
- context: summary,
340
- replace_context: true,
341
- ...issueMeta,
342
- });
380
+ // Something the person asked to track ("add this to task") goes to Active, as does
381
+ // a match on a task that is already there. What the hook picked up on its own is a
382
+ // guess about the work: it waits in Queue until someone takes it up.
383
+ // An existing task keeps its own Context and GitHub link: a later prompt that
384
+ // matches it is not a better description of the work.
385
+ const section = reusable || hasExplicitTaskSignal(prompt) ? "active" : "queue";
386
+ const update = updateTask(args.phrenPath, args.project, targetMatch || summary, reusable
387
+ ? { section }
388
+ : { section, context: summary, replace_context: true, ...issueMeta });
343
389
  if (!update.ok) {
344
390
  debugLog(`task lifecycle update ${args.project}: ${update.error}`);
345
391
  return { mode, noticeLines: [] };
@@ -354,7 +400,7 @@ export function handleTaskPromptLifecycle(args) {
354
400
  mode,
355
401
  noticeLines: [
356
402
  "<phren-notice>",
357
- `Active task (${args.project}): ${resolved.data.line}`,
403
+ `${section === "active" ? "Active" : "Queued"} task (${args.project}): ${resolved.data.line}`,
358
404
  "<phren-notice>",
359
405
  ],
360
406
  };
@@ -367,12 +413,10 @@ export function finalizeTaskSession(args) {
367
413
  return;
368
414
  const match = state.stableId ? `bid:${state.stableId}` : state.item;
369
415
  if (args.status === "saved-local" || args.status === "saved-pushed" || args.status === "no-upstream") {
370
- const completed = completeTask(args.phrenPath, state.project, match);
371
- if (!completed.ok) {
372
- debugLog(`task lifecycle complete ${state.project}: ${completed.error}`);
373
- return;
374
- }
375
- incrementSessionTasksCompleted(args.phrenPath, 1, state.sessionId, state.project);
416
+ // A saved turn is not finished work. The Stop hook runs after every turn, so
417
+ // completing here marked real work Done as soon as the next prompt came in.
418
+ // The task stays where it is; completion is explicit. Detaching it keeps the
419
+ // next prompt from rewriting its context unless that prompt matches it.
376
420
  clearTaskSessionState(args.phrenPath, args.sessionId);
377
421
  return;
378
422
  }
@@ -0,0 +1,5 @@
1
+ /** Removes CSI sequences (colors, cursor moves, modes), OSC sequences (window
2
+ * titles, hyperlinks) and carriage returns. Line breaks and every printable
3
+ * character are kept, box drawing and spinners included: callers that parse a
4
+ * harness screen drop those themselves, because there they carry meaning. */
5
+ export declare function stripTerminal(text: string): string;
@@ -0,0 +1,11 @@
1
+ // Plain text from terminal output: pane reads, harness screens, CLI stdout.
2
+ // CSI (ESC [ parameters, intermediates, final byte), OSC (ESC ] up to BEL or
3
+ // ESC \) and carriage returns, in one pass.
4
+ const TERMINAL_CONTROL = /\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\r/g;
5
+ /** Removes CSI sequences (colors, cursor moves, modes), OSC sequences (window
6
+ * titles, hyperlinks) and carriage returns. Line breaks and every printable
7
+ * character are kept, box drawing and spinners included: callers that parse a
8
+ * harness screen drop those themselves, because there they carry meaning. */
9
+ export function stripTerminal(text) {
10
+ return text.replace(TERMINAL_CONTROL, "");
11
+ }
@@ -35,6 +35,13 @@ function sandboxHomeDir() {
35
35
  sandboxHome = fs.mkdtempSync(path.join(os.tmpdir(), "phren-test-home-"));
36
36
  process.env.HOME = sandboxHome;
37
37
  process.env.USERPROFILE = sandboxHome;
38
+ // findPhrenPath walks up from the cwd before it tries $HOME/.phren. The
39
+ // checkout usually sits under the developer's real home, so that walk found
40
+ // their real ~/.phren and the logger appended every test's errors to its
41
+ // .runtime/debug.log. Naming the sandbox's own store skips the walk and
42
+ // resolves exactly as on a clean CI machine: the sandbox store if a test
43
+ // makes one, otherwise no store. A test that needs the walk clears this.
44
+ process.env.PHREN_PATH = path.join(sandboxHome, ".phren");
38
45
  }
39
46
  export async function teardown() {
40
47
  if (sandboxHome)
@@ -11,4 +11,4 @@ export declare function getToolsByCategory(): Array<{
11
11
  category: string;
12
12
  tools: ToolMetadata[];
13
13
  }>;
14
- export declare function renderToolCatalogMarkdown(): string;
14
+ export declare function renderToolCatalogMarkdown(allowed?: ReadonlySet<string>): string;
@@ -108,8 +108,10 @@ export function getToolsByCategory() {
108
108
  }))
109
109
  .filter((entry) => entry.tools.length > 0);
110
110
  }
111
- export function renderToolCatalogMarkdown() {
111
+ export function renderToolCatalogMarkdown(allowed) {
112
112
  return getToolsByCategory()
113
+ .map(entry => ({ ...entry, tools: entry.tools.filter(tool => !allowed || allowed.has(tool.name)) }))
114
+ .filter(entry => entry.tools.length > 0)
113
115
  .map(({ category, tools }) => {
114
116
  const lines = tools.map((tool) => `- \`${tool.name}\`: ${tool.description}`);
115
117
  return `**${category}:**\n${lines.join("\n")}`;
@@ -0,0 +1,3 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { type McpContext } from "./types.js";
3
+ export declare function register(server: McpServer, ctx: McpContext): void;
@@ -0,0 +1,178 @@
1
+ import { z } from "zod";
2
+ import { resolveStoreForProject } from "./types.js";
3
+ import { loadCodePackage, CODE_PACKAGE_HINT } from "../modules/code-package.js";
4
+ /**
5
+ * Read tools over the `code` module's local symbol index (stage 2).
6
+ *
7
+ * These answer symbol questions from the project's own index instead of a grep
8
+ * sweep: a definition, the references grouped by file, a file's outline, a
9
+ * ranked search and the hottest and coldest symbols. Every tool lives in the
10
+ * `code` module, so it is absent until the module is enabled and the project is
11
+ * indexed; the result is compact text, one line per hit, not a JSON dump.
12
+ */
13
+ function text(value) {
14
+ return { content: [{ type: "text", text: value }] };
15
+ }
16
+ function noIndex(project) {
17
+ return `No code index for "${project}". Build one with: phren code index ${project}`;
18
+ }
19
+ function resolveTarget(ctx, projectInput) {
20
+ try {
21
+ const { phrenPath, project } = resolveStoreForProject(ctx, projectInput, "read");
22
+ return { store: phrenPath, project };
23
+ }
24
+ catch (err) {
25
+ return { error: err instanceof Error ? err.message : String(err) };
26
+ }
27
+ }
28
+ function compactLines(textValue) {
29
+ return textValue.split("\n").filter(line => line.trim().length > 0).join("\n");
30
+ }
31
+ function outlineLines(entries, depth = 0) {
32
+ const out = [];
33
+ for (const entry of entries) {
34
+ const signature = entry.signature ? ` ${entry.signature}` : "";
35
+ const doc = entry.doc ? ` | ${entry.doc.split("\n")[0]}` : "";
36
+ out.push(`${" ".repeat(depth)}${entry.line} ${entry.kind} ${entry.name}${signature}${doc}`);
37
+ out.push(...outlineLines(entry.children, depth + 1));
38
+ }
39
+ return out;
40
+ }
41
+ function usageLine(entry) {
42
+ return `${entry.file}:${entry.line} ${entry.kind} ${entry.name} ${entry.uses}`;
43
+ }
44
+ export function register(server, ctx) {
45
+ server.registerTool("code_search", {
46
+ title: "◆ phren · code search",
47
+ description: "Search a project's code index for symbols by name, signature or doc text. Use this instead of grep when you want a symbol (a function, class, method, type) rather than raw text: results are ranked exact name, then prefix, then full-text relevance, then usage count, and each hit carries its kind, signature, doc and path:line. Pass `kind` to narrow to function, method, class, struct, enum, interface, type or variable.",
48
+ inputSchema: z.object({
49
+ project: z.string().describe("Project name, optionally store-qualified."),
50
+ query: z.string().describe("Symbol name or words from its signature or doc comment."),
51
+ kind: z.enum(["function", "method", "class", "struct", "enum", "interface", "type", "variable"]).optional().describe("Only symbols of this kind."),
52
+ limit: z.number().int().min(1).max(100).optional().describe("Maximum hits. Defaults to 20."),
53
+ }),
54
+ }, async ({ project: projectInput, query, kind, limit }) => {
55
+ const code = await loadCodePackage(ctx.phrenPath);
56
+ if (!code)
57
+ return text(CODE_PACKAGE_HINT);
58
+ const { search, formatSymbolLine } = code;
59
+ const target = resolveTarget(ctx, projectInput);
60
+ if ("error" in target)
61
+ return text(target.error);
62
+ const result = await search(target.store, target.project, query, kind, limit ?? 20);
63
+ if (!result.available)
64
+ return text(noIndex(target.project));
65
+ if (result.value.length === 0)
66
+ return text(`No symbols match "${query}" in ${target.project}.`);
67
+ return text(`${target.project}: ${result.value.length} match(es) for "${query}"\n${result.value.map(formatSymbolLine).join("\n")}`);
68
+ });
69
+ server.registerTool("code_definition", {
70
+ title: "◆ phren · code definition",
71
+ description: "Go to a symbol's definition in a project's code index. Use this instead of grep to find where a function, class or method is declared: it accepts `Foo`, `Foo.bar` and `bar()` forms and returns the file and lines, signature, doc comment, the last change (a blame hash and date, never a name) and a short source snippet. When a common name matches several symbols it prefers an exported, non-variable declaration and reports how many candidates there were.",
72
+ inputSchema: z.object({
73
+ project: z.string().describe("Project name, optionally store-qualified."),
74
+ symbol: z.string().describe("A symbol name: Foo, Foo.bar or bar()."),
75
+ }),
76
+ }, async ({ project: projectInput, symbol }) => {
77
+ const code = await loadCodePackage(ctx.phrenPath);
78
+ if (!code)
79
+ return text(CODE_PACKAGE_HINT);
80
+ const { definition, findingsCitingSymbol, formatCitingFinding } = code;
81
+ const target = resolveTarget(ctx, projectInput);
82
+ if ("error" in target)
83
+ return text(target.error);
84
+ const result = await definition(target.store, target.project, symbol);
85
+ if (!result.available)
86
+ return text(noIndex(target.project));
87
+ if (!result.value)
88
+ return text(`No symbol "${symbol}" in ${target.project}.`);
89
+ const { symbol: hit, candidates, snippet, blame } = result.value;
90
+ const lines = [
91
+ `${hit.file}:${hit.line}-${hit.endLine} ${hit.kind} ${hit.name}${hit.exported ? " (exported)" : ""}`,
92
+ hit.signature,
93
+ hit.doc,
94
+ candidates > 1 ? `${candidates} candidates shared this name; showing the best.` : "",
95
+ blame ? `last change ${blame.at} ${blame.authorHash.slice(0, 12)}` : "",
96
+ ];
97
+ const citing = findingsCitingSymbol(target.store, target.project, symbol);
98
+ const findingsBlock = citing.length > 0 ? ["Findings", ...citing.map(formatCitingFinding)] : [];
99
+ return text(compactLines([...lines, snippet, ...findingsBlock].filter(Boolean).join("\n")));
100
+ });
101
+ server.registerTool("code_references", {
102
+ title: "◆ phren · code references",
103
+ description: "Find every resolved reference to a symbol in a project's code index, grouped by file. Use this instead of grep to answer who calls or uses a function, class or method: it accepts `Foo`, `Foo.bar` and `bar()` forms and counts only references the index could resolve to exactly one definition. Common-name ambiguity is reported as a candidate count.",
104
+ inputSchema: z.object({
105
+ project: z.string().describe("Project name, optionally store-qualified."),
106
+ symbol: z.string().describe("A symbol name: Foo, Foo.bar or bar()."),
107
+ limit: z.number().int().min(1).max(500).optional().describe("Maximum reference lines. Defaults to 200."),
108
+ }),
109
+ }, async ({ project: projectInput, symbol, limit }) => {
110
+ const code = await loadCodePackage(ctx.phrenPath);
111
+ if (!code)
112
+ return text(CODE_PACKAGE_HINT);
113
+ const { references } = code;
114
+ const target = resolveTarget(ctx, projectInput);
115
+ if ("error" in target)
116
+ return text(target.error);
117
+ const result = await references(target.store, target.project, symbol, limit ?? 200);
118
+ if (!result.available)
119
+ return text(noIndex(target.project));
120
+ if (!result.value)
121
+ return text(`No symbol "${symbol}" in ${target.project}.`);
122
+ const { symbol: hit, candidates, groups, total } = result.value;
123
+ const header = `references for ${hit.name} (${hit.file}:${hit.line} ${hit.kind}), ${total} in ${groups.length} file(s)`;
124
+ const note = candidates > 1 ? `\n${candidates} candidates shared this name; showing the best.` : "";
125
+ if (groups.length === 0)
126
+ return text(`${header}\nNo resolved references.${note}`);
127
+ const body = groups.map(group => `${group.file}\n${group.references.map(ref => ` ${ref.line} ${ref.kind}`).join("\n")}`).join("\n");
128
+ return text(`${header}${note}\n${body}`);
129
+ });
130
+ server.registerTool("code_outline", {
131
+ title: "◆ phren · code outline",
132
+ description: "List a file's symbols in source order, nested under their parent class or container. Use this before reading a large file: it is far cheaper than opening the source and it shows the structure (classes and their methods, top-level functions and types) with each symbol's line, signature and doc. The path is the project-relative path the index uses.",
133
+ inputSchema: z.object({
134
+ project: z.string().describe("Project name, optionally store-qualified."),
135
+ path: z.string().describe("Project-relative file path, as stored in the index."),
136
+ }),
137
+ }, async ({ project: projectInput, path: filePath }) => {
138
+ const code = await loadCodePackage(ctx.phrenPath);
139
+ if (!code)
140
+ return text(CODE_PACKAGE_HINT);
141
+ const { outline } = code;
142
+ const target = resolveTarget(ctx, projectInput);
143
+ if ("error" in target)
144
+ return text(target.error);
145
+ const result = await outline(target.store, target.project, filePath);
146
+ if (!result.available)
147
+ return text(noIndex(target.project));
148
+ if (result.value.length === 0)
149
+ return text(`No indexed symbols for ${filePath} in ${target.project}.`);
150
+ const count = result.value.reduce((n, entry) => n + 1 + countOutline(entry.children), 0);
151
+ return text(`${target.project}/${filePath} (${count} symbols)\n${outlineLines(result.value).join("\n")}`);
152
+ });
153
+ server.registerTool("code_usage", {
154
+ title: "◆ phren · code usage",
155
+ description: "Show a project's hottest and coldest symbols by resolved-reference count. Use this instead of grep to see what code is central and what is barely used: it returns the top and bottom N so cold code is visible too. Local variables are excluded from the hot list so a busy one-function local or a one-letter loop name cannot dominate it.",
156
+ inputSchema: z.object({
157
+ project: z.string().describe("Project name, optionally store-qualified."),
158
+ top: z.number().int().min(1).max(100).optional().describe("How many hot and how many cold symbols. Defaults to 10."),
159
+ }),
160
+ }, async ({ project: projectInput, top }) => {
161
+ const code = await loadCodePackage(ctx.phrenPath);
162
+ if (!code)
163
+ return text(CODE_PACKAGE_HINT);
164
+ const { usage } = code;
165
+ const target = resolveTarget(ctx, projectInput);
166
+ if ("error" in target)
167
+ return text(target.error);
168
+ const result = await usage(target.store, target.project, top ?? 10);
169
+ if (!result.available)
170
+ return text(noIndex(target.project));
171
+ const { top: hot, bottom: cold } = result.value;
172
+ const section = (label, entries) => entries.length === 0 ? `${label}\nnone` : `${label}\n${entries.map(usageLine).join("\n")}`;
173
+ return text(`${target.project} symbols by reference count\n${section("hot", hot)}\n${section("cold", cold)}`);
174
+ });
175
+ }
176
+ function countOutline(entries) {
177
+ return entries.reduce((sum, entry) => sum + 1 + countOutline(entry.children), 0);
178
+ }
@@ -1,3 +1,5 @@
1
+ import { moduleEnabled } from "../modules/runtime.js";
2
+ import { disabledHint } from "../modules/registry.js";
1
3
  import * as fs from "fs";
2
4
  import * as path from "path";
3
5
  import { mcpResponse, resolveStoreForProject } from "./types.js";
@@ -220,6 +222,9 @@ async function handleGetConfig(ctx, { domain, project }) {
220
222
  }
221
223
  async function handleSetConfig(ctx, { domain, settings, project }) {
222
224
  const { phrenPath } = ctx;
225
+ if (!moduleEnabled(phrenPath, "tasks", ctx.profile) && (domain === "taskMode" || settings.scope === "tasks" || "taskMode" in settings || "proactivityTask" in settings)) {
226
+ return mcpResponse({ ok: false, error: disabledHint("tasks"), errorCode: "UNAVAILABLE" });
227
+ }
223
228
  switch (domain) {
224
229
  // ── proactivity ───────────────────────────────────────────────
225
230
  case "proactivity": {
@@ -10,6 +10,7 @@ const importPayloadSchema = z.object({
10
10
  project: z.string(),
11
11
  overwrite: z.boolean().optional(),
12
12
  summary: z.string().optional(),
13
+ agentsMd: z.string().optional(),
13
14
  claudeMd: z.string().optional(),
14
15
  taskRaw: z.string().optional(),
15
16
  findingsRaw: z.string().optional(),
@@ -70,9 +71,14 @@ export function register(server, ctx) {
70
71
  if (taskRawPath && fs.existsSync(taskRawPath))
71
72
  exported.taskRaw = fs.readFileSync(taskRawPath, "utf8");
72
73
  }
73
- const claudePath = safeProjectPath(projectDir, "CLAUDE.md");
74
- if (claudePath && fs.existsSync(claudePath))
75
- exported.claudeMd = fs.readFileSync(claudePath, "utf8");
74
+ const agentsPath = safeProjectPath(projectDir, "AGENTS.md");
75
+ const legacyPath = safeProjectPath(projectDir, "CLAUDE.md");
76
+ const instructionsPath = agentsPath && fs.existsSync(agentsPath) ? agentsPath : legacyPath;
77
+ if (instructionsPath && fs.existsSync(instructionsPath)) {
78
+ const instructions = fs.readFileSync(instructionsPath, "utf8");
79
+ exported.agentsMd = instructions;
80
+ exported.claudeMd = instructions; // Deprecated export alias for older clients.
81
+ }
76
82
  return mcpResponse({ ok: true, message: `Exported project "${project}".`, data: exported });
77
83
  });
78
84
  server.registerTool("import_project", {
@@ -97,7 +103,7 @@ export function register(server, ctx) {
97
103
  }
98
104
  const parsed = parsedResult.data;
99
105
  // Warn about unknown fields silently discarded by .passthrough()
100
- const knownTopLevel = new Set(["project", "overwrite", "summary", "claudeMd", "learnings", "task", "taskRaw", "exportedAt", "version", "findingsRaw"]);
106
+ const knownTopLevel = new Set(["project", "overwrite", "summary", "agentsMd", "claudeMd", "learnings", "task", "taskRaw", "exportedAt", "version", "findingsRaw"]);
101
107
  const unknownFields = Object.keys(decoded).filter(k => !knownTopLevel.has(k));
102
108
  if (unknownFields.length > 0) {
103
109
  debugLog(`import_project: unknown fields will be ignored: ${unknownFields.join(", ")}`);
@@ -181,9 +187,10 @@ export function register(server, ctx) {
181
187
  fs.writeFileSync(path.join(stagedProjectDir, "summary.md"), parsed.summary);
182
188
  imported.push("summary.md");
183
189
  }
184
- if (parsed.claudeMd) {
185
- fs.writeFileSync(path.join(stagedProjectDir, "CLAUDE.md"), parsed.claudeMd);
186
- imported.push("CLAUDE.md");
190
+ const instructions = parsed.agentsMd ?? parsed.claudeMd;
191
+ if (instructions) {
192
+ fs.writeFileSync(path.join(stagedProjectDir, "AGENTS.md"), instructions);
193
+ imported.push("AGENTS.md");
187
194
  }
188
195
  const findingsContent = typeof parsed.findingsRaw === "string" ? parsed.findingsRaw : buildFindingsContent();
189
196
  if (findingsContent) {
@@ -0,0 +1,2 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare function register(server: McpServer): void;
@@ -0,0 +1,66 @@
1
+ import { hookRequest } from "../bridge/client.js";
2
+ import { dispatchSchema } from "../bridge/dispatch.js";
3
+ import { handOff, handOffSchema, listLiveSessions } from "../bridge/hand-off.js";
4
+ import { herdrPaneFromEnv } from "../bridge/herdr.js";
5
+ import { mcpResponse } from "./types.js";
6
+ export function register(server) {
7
+ server.registerTool("dispatch", {
8
+ title: "◆ phren · dispatch",
9
+ description: "Send a worker brief to an enrolled computer through the local Phren Hook. Returns a launch receipt and remote target. The worker's finish, question or exit comes back later through dispatch_returns. Never automatically retry an uncertain delivery.",
10
+ inputSchema: dispatchSchema,
11
+ }, async (input) => {
12
+ try {
13
+ // The pane this agent runs in receives the one-line return notices.
14
+ const origin = herdrPaneFromEnv();
15
+ const result = await hookRequest("/v1/dispatch", { ...input, ...(origin ? { origin } : {}) }, undefined, 180_000);
16
+ return mcpResponse({ ok: result.ok === true, data: result, message: `${result.computer}: ${result.state}.` });
17
+ }
18
+ catch (error) {
19
+ return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Dispatch failed." });
20
+ }
21
+ });
22
+ server.registerTool("dispatch_returns", {
23
+ title: "◆ phren · dispatch returns",
24
+ description: "List unread returns from dispatched workers and mark them read: the worker finished (done, with its final reply), finished by asking the owner something (needs-you, with the question), is blocked on terminal input, or its pane is gone. Each row has the dispatch id, computer, project, label and the worker's target for hand_off.",
25
+ inputSchema: {},
26
+ }, async () => {
27
+ try {
28
+ const result = await hookRequest("/v1/dispatch/returns", {});
29
+ const returns = Array.isArray(result.returns) ? result.returns : [];
30
+ return mcpResponse({ ok: true, data: result, message: returns.length ? `${returns.length} unread returns.` : "No unread returns." });
31
+ }
32
+ catch (error) {
33
+ return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Could not read dispatch returns." });
34
+ }
35
+ });
36
+ server.registerTool("live_sessions", {
37
+ title: "◆ phren · live sessions",
38
+ description: "List the live agent sessions on this computer and every enrolled computer: computer, project, harness, status, idleFor (seconds since the tab last changed), role and the target hand_off takes. Computers that could not be reached are listed separately, and computers registered in the store but not linked in hooks.yaml come back in notLinked: their sessions are unknown, not absent.",
39
+ inputSchema: {},
40
+ }, async () => {
41
+ try {
42
+ const result = await listLiveSessions();
43
+ const note = result.peerError ? ` Enrolled computers were skipped: ${result.peerError}`
44
+ : result.enrolled === 0 && !result.notLinked.length ? " No other computers are enrolled here; run `phren bridge enroll-computer` to add them." : "";
45
+ const unlinked = result.notLinked.length
46
+ ? ` Not linked, so not checked (this does not mean nothing is running there): ${result.notLinked.map(item => item.aliases?.length ? `${item.name} (also ${item.aliases.join(", ")})` : item.name).join("; ")}. Link one with \`phren bridge enroll-computer\`.` : "";
47
+ return mcpResponse({ ok: true, data: result, message: `${result.sessions.length} live sessions across ${result.enrolled + 1} computers.${note}${unlinked}` });
48
+ }
49
+ catch (error) {
50
+ return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Could not list live sessions." });
51
+ }
52
+ });
53
+ server.registerTool("hand_off", {
54
+ title: "◆ phren · hand off",
55
+ description: "Deliver a prompt to an existing local or enrolled-computer agent session through Phren Hook. Prefer a session that already owns the project and is idle or doing related work.",
56
+ inputSchema: handOffSchema,
57
+ }, async (input) => {
58
+ try {
59
+ const result = await handOff(input);
60
+ return mcpResponse({ ok: result.ok, data: result, message: result.delivered ? "Prompt delivered to the existing session." : "Prompt delivery was not confirmed." });
61
+ }
62
+ catch (error) {
63
+ return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Hand-off failed." });
64
+ }
65
+ });
66
+ }