@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
@@ -1,3 +1,4 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
1
2
  import { mcpResponse, resolveStoreForProject } from "./types.js";
2
3
  import { z } from "zod";
3
4
  import * as fs from "fs";
@@ -7,9 +8,12 @@ import { isValidProjectName, errorMessage } from "../utils.js";
7
8
  import { storeAwareProjectPath } from "../store-routing.js";
8
9
  import { removeFinding as removeFindingCore, removeFindings as removeFindingsCore, applyFindingTypePrefix, } from "../core/finding.js";
9
10
  import { debugLog, EXEC_TIMEOUT_MS, FINDING_TYPES, normalizeMemoryScope, } from "../shared.js";
10
- import { getCurrentActor, getMachineName } from "../machine-identity.js";
11
- import { addFindingToFile, addFindingsToFile, checkSemanticConflicts, autoMergeConflicts, } from "../shared/content.js";
11
+ import { getCurrentActor, getMachineName, storeCommitMessage } from "../machine-identity.js";
12
+ import { loadCodePackage } from "../modules/code-package.js";
13
+ import { moduleEnabled } from "../modules/runtime.js";
14
+ import { addFindingToFile, addFindingsToFile, checkSemanticConflicts, } from "../shared/content.js";
12
15
  import { jaccardTokenize, jaccardSimilarity, stripMetadata, detectConflicts, extractDynamicEntities } from "../content/dedup.js";
16
+ import { scanForSecrets } from "../content/secrets.js";
13
17
  import { runCustomHooks } from "../hooks.js";
14
18
  import { incrementSessionFindings } from "./session.js";
15
19
  import { extractFragmentNames } from "../shared/fragment-graph.js";
@@ -21,6 +25,7 @@ import { permissionDeniedError } from "../governance/rbac.js";
21
25
  import { TEAM_STORE_PATHSPECS } from "../cli/session-git.js";
22
26
  import { withFileLock } from "../governance/locks.js";
23
27
  import { runtimeFile } from "../phren-paths.js";
28
+ import { mergeStoreUpstream } from "../sync/store-merge.js";
24
29
  const JACCARD_MAYBE_LOW = 0.25;
25
30
  const JACCARD_MAYBE_HIGH = 0.40; // above this isDuplicateFinding already catches it
26
31
  function findJaccardCandidates(phrenPath, project, finding) {
@@ -113,7 +118,14 @@ function withLifecycleMutation(phrenPath, project, writeQueue, updateIndex, hand
113
118
  }
114
119
  // ── Handlers ─────────────────────────────────────────────────────────────────
115
120
  async function handleAddFinding(ctx, params) {
116
- const { finding, citation, sessionId, findingType, scope } = params;
121
+ const { finding, sessionId, findingType, scope } = params;
122
+ // `name` is the citation's code link (a function, type or variable);
123
+ // `symbol` is its deprecated spelling, accepted until 0.3.1. The stored
124
+ // citation keeps its existing key.
125
+ const { name: citedName, ...citationRest } = params.citation ?? {};
126
+ const citation = params.citation
127
+ ? { ...citationRest, ...(citedName ?? citationRest.symbol ? { symbol: citedName ?? citationRest.symbol } : {}) }
128
+ : undefined;
117
129
  // Resolve store-qualified project names (e.g., "team/arc" → store path + "arc")
118
130
  let phrenPath;
119
131
  let project;
@@ -137,35 +149,67 @@ async function handleAddFinding(ctx, params) {
137
149
  actor: getCurrentActor(),
138
150
  session_id: sessionId,
139
151
  };
152
+ const normalizedScope = normalizeMemoryScope(scope ?? "shared");
153
+ if (!normalizedScope)
154
+ return mcpResponse({ ok: false, error: `Invalid scope: "${scope}". Use lowercase letters/numbers with '-' or '_' (max 64 chars), e.g. "researcher".` });
155
+ // Size caps apply to every store; they used to sit after the team branch.
156
+ const findingList = Array.isArray(finding) ? finding : [finding];
157
+ if (findingList.length > 100)
158
+ return mcpResponse({ ok: false, error: "Bulk add limited to 100 findings per call." });
159
+ if (findingList.some((f) => f.length > 5000)) {
160
+ return mcpResponse({
161
+ ok: false,
162
+ error: Array.isArray(finding) ? "One or more findings exceed 5000 character limit." : "Finding text exceeds 5000 character limit.",
163
+ });
164
+ }
140
165
  // Team stores: use append-only journal (no FINDINGS.md mutation, no merge conflicts)
141
166
  {
142
167
  const storeResolved = resolveStoreForProject(ctx, params.project);
143
168
  if (storeResolved.storeRole === "team") {
144
169
  const { appendTeamJournal } = await import("../finding/journal.js");
145
- const findings = Array.isArray(finding) ? finding : [finding];
146
- const added = [];
147
- for (const f of findings) {
148
- const taggedFinding = applyFindingTypePrefix(f, findingType);
149
- const result = appendTeamJournal(phrenPath, project, taggedFinding, provenance.actor, provenance.machine);
150
- if (result.ok)
151
- added.push(taggedFinding);
170
+ // The journal is pushed to a repo shared with colleagues, so it gets the
171
+ // same secret scan the personal store applies.
172
+ const rejected = [];
173
+ const accepted = [];
174
+ for (const f of findingList) {
175
+ const secretType = scanForSecrets(f);
176
+ if (secretType)
177
+ rejected.push({ finding: f.slice(0, 60), reason: `Contains ${secretType}` });
178
+ else
179
+ accepted.push(applyFindingTypePrefix(f, findingType));
152
180
  }
153
- return mcpResponse({
154
- ok: added.length > 0,
155
- message: `Added ${added.length} finding(s) to ${params.project} journal`,
156
- data: { project: params.project, added, journalMode: true },
181
+ return withWriteQueue(async () => {
182
+ const added = [];
183
+ const journals = new Set();
184
+ for (const taggedFinding of accepted) {
185
+ const result = appendTeamJournal(phrenPath, project, taggedFinding, provenance.actor, provenance.machine);
186
+ if (result.ok) {
187
+ added.push(taggedFinding);
188
+ journals.add(path.join(phrenPath, project, "journal", result.data));
189
+ }
190
+ else {
191
+ rejected.push({ finding: taggedFinding.slice(0, 60), reason: result.error });
192
+ }
193
+ }
194
+ for (const journalPath of journals)
195
+ updateFileInIndex(journalPath);
196
+ if (added.length === 0) {
197
+ return mcpResponse({
198
+ ok: false,
199
+ error: `No findings written to ${params.project} journal: ${rejected.map((r) => `"${r.finding}" ${r.reason}`).join("; ")}`,
200
+ data: { project: params.project, rejected, journalMode: true },
201
+ });
202
+ }
203
+ return mcpResponse({
204
+ ok: true,
205
+ message: `Added ${added.length} finding(s) to ${params.project} journal${rejected.length > 0 ? `, ${rejected.length} rejected` : ""}`,
206
+ data: { project: params.project, added, journalMode: true, ...(rejected.length > 0 ? { rejected } : {}) },
207
+ });
157
208
  });
158
209
  }
159
210
  }
160
- const normalizedScope = normalizeMemoryScope(scope ?? "shared");
161
- if (!normalizedScope)
162
- return mcpResponse({ ok: false, error: `Invalid scope: "${scope}". Use lowercase letters/numbers with '-' or '_' (max 64 chars), e.g. "researcher".` });
163
211
  if (Array.isArray(finding)) {
164
212
  const findings = finding;
165
- if (findings.length > 100)
166
- return mcpResponse({ ok: false, error: "Bulk add limited to 100 findings per call." });
167
- if (findings.some((f) => f.length > 5000))
168
- return mcpResponse({ ok: false, error: "One or more findings exceed 5000 character limit." });
169
213
  return withWriteQueue(async () => {
170
214
  runCustomHooks(phrenPath, "pre-finding", { PHREN_PROJECT: project });
171
215
  const allPotentialDuplicates = [];
@@ -216,18 +260,24 @@ async function handleAddFinding(ctx, params) {
216
260
  });
217
261
  });
218
262
  }
219
- if (finding.length > 5000)
220
- return mcpResponse({ ok: false, error: "Finding text exceeds 5000 character limit." });
221
263
  return withWriteQueue(async () => {
222
264
  try {
223
265
  const taggedFinding = applyFindingTypePrefix(finding, findingType);
266
+ // Memory link: link the finding to the one function, type or variable it
267
+ // names, or validate an explicit citation `name`. Never rewrites the
268
+ // finding text; only the citation comment gains the link.
269
+ const code = moduleEnabled(phrenPath, "code") ? await loadCodePackage(phrenPath) : undefined;
270
+ const symbolCitation = code ? await code.symbolCitationForFinding(phrenPath, project, taggedFinding, citation?.symbol) : citation?.symbol ? { symbol: citation.symbol } : {};
271
+ const citationForWrite = (citation || symbolCitation.symbol)
272
+ ? { ...(citation ?? {}), ...symbolCitation }
273
+ : undefined;
224
274
  // Jaccard "maybe zone" scan — free, no LLM call. Return candidates so the agent decides.
225
275
  const potentialDuplicates = findJaccardCandidates(phrenPath, project, taggedFinding);
226
276
  // Heuristic contradiction candidates — also free, also agent-decides. No extra API call.
227
277
  const potentialConflicts = findConflictCandidates(phrenPath, project, taggedFinding);
228
278
  const semanticConflicts = await checkSemanticConflicts(phrenPath, project, taggedFinding);
229
279
  runCustomHooks(phrenPath, "pre-finding", { PHREN_PROJECT: project });
230
- const result = addFindingToFile(phrenPath, project, taggedFinding, citation, {
280
+ const result = addFindingToFile(phrenPath, project, taggedFinding, citationForWrite, {
231
281
  sessionId,
232
282
  scope: normalizedScope,
233
283
  extraAnnotations: semanticConflicts.checked ? semanticConflicts.annotations : undefined,
@@ -496,6 +546,87 @@ async function handleRemoveFinding(ctx, { project: projectInput, finding }) {
496
546
  return mcpResponse({ ok: true, message: result.message, data: result.data });
497
547
  });
498
548
  }
549
+ /**
550
+ * Commit and push the team-safe pathspecs of every attached team store. Team
551
+ * stores are independent repos, so push_changes runs this whatever happens to
552
+ * the primary store.
553
+ */
554
+ export async function syncTeamStores(phrenPath) {
555
+ const teamResults = [];
556
+ try {
557
+ const { execFileSync } = await import("child_process");
558
+ const { getNonPrimaryStores } = await import("../store-registry.js");
559
+ const teamStores = getNonPrimaryStores(phrenPath).filter((s) => s.role === "team");
560
+ for (const store of teamStores) {
561
+ if (!fs.existsSync(store.path) || !fs.existsSync(path.join(store.path, ".git")))
562
+ continue;
563
+ const runStoreGit = (args, opts = {}) => execFileSync("git", args, {
564
+ cwd: store.path,
565
+ encoding: "utf8",
566
+ timeout: opts.timeout ?? EXEC_TIMEOUT_MS,
567
+ env: nonInteractiveGitEnv(opts.env),
568
+ stdio: ["ignore", "pipe", "pipe"],
569
+ }).trim();
570
+ const mergeStoreGit = async (_cwd, gitArgs) => {
571
+ try {
572
+ return { ok: true, output: runStoreGit(gitArgs) };
573
+ }
574
+ catch (err) {
575
+ return { ok: false, output: "", error: errorMessage(err) };
576
+ }
577
+ };
578
+ try {
579
+ if (!runStoreGit(["status", "--porcelain"]))
580
+ continue;
581
+ // Stage each team-safe pathspec individually — a single no-match
582
+ // (e.g. no */truths.md in this store) used to abort the whole add.
583
+ for (const spec of TEAM_STORE_PATHSPECS) {
584
+ try {
585
+ runStoreGit(["add", "--sparse", "--", spec]);
586
+ }
587
+ catch { /* best-effort */ }
588
+ }
589
+ if (!runStoreGit(["diff", "--cached", "--name-only"]))
590
+ continue;
591
+ const actor = process.env.PHREN_ACTOR || process.env.USER || "unknown";
592
+ runStoreGit(["commit", "-m", storeCommitMessage(`phren: ${actor} team sync`)]);
593
+ try {
594
+ runStoreGit(["push"], { timeout: 15000 });
595
+ teamResults.push({ store: store.name, pushed: true });
596
+ }
597
+ catch {
598
+ try {
599
+ const merged = await mergeStoreUpstream(store.path, { git: mergeStoreGit, commitLocalWrites: false });
600
+ if (merged.status !== "updated" && merged.status !== "unchanged")
601
+ throw new Error(merged.detail);
602
+ runStoreGit(["push"], { timeout: 15000 });
603
+ teamResults.push({ store: store.name, pushed: true });
604
+ }
605
+ catch (retryErr) {
606
+ teamResults.push({ store: store.name, pushed: false, error: errorMessage(retryErr) });
607
+ }
608
+ }
609
+ }
610
+ catch (storeErr) {
611
+ teamResults.push({ store: store.name, pushed: false, error: errorMessage(storeErr) });
612
+ }
613
+ }
614
+ }
615
+ catch (err) {
616
+ debugLog(`syncTeamStores: ${errorMessage(err)}`);
617
+ }
618
+ return teamResults;
619
+ }
620
+ /** Team-store outcomes appended to a push_changes message, so a failure is visible. */
621
+ function describeTeamSync(results) {
622
+ if (results.length === 0)
623
+ return "";
624
+ const pushed = results.filter((r) => r.pushed).map((r) => r.store);
625
+ const parts = pushed.length > 0 ? [`Pushed ${pushed.length} team store(s): ${pushed.join(", ")}.`] : [];
626
+ for (const failure of results.filter((r) => !r.pushed))
627
+ parts.push(`Team store "${failure.store}" failed: ${failure.error ?? "unknown error"}.`);
628
+ return ` ${parts.join(" ")}`;
629
+ }
499
630
  async function handlePushChanges(ctx, { message }) {
500
631
  const { phrenPath, withWriteQueue } = ctx;
501
632
  return withWriteQueue(async () => withFileLock(runtimeFile(phrenPath, "git-op"), async () => {
@@ -504,13 +635,24 @@ async function handlePushChanges(ctx, { message }) {
504
635
  cwd: phrenPath,
505
636
  encoding: "utf8",
506
637
  timeout: opts.timeout ?? EXEC_TIMEOUT_MS,
507
- env: opts.env,
638
+ env: nonInteractiveGitEnv(opts.env),
508
639
  stdio: ["ignore", "pipe", "pipe"],
509
640
  }).trim();
641
+ const mergeGit = async (_cwd, args) => {
642
+ try {
643
+ return { ok: true, output: runGit(args) };
644
+ }
645
+ catch (err) {
646
+ return { ok: false, output: "", error: errorMessage(err) };
647
+ }
648
+ };
649
+ const teamResults = await syncTeamStores(phrenPath);
650
+ const teamSuffix = describeTeamSync(teamResults);
651
+ const teamData = teamResults.length > 0 ? { teamStores: teamResults } : {};
510
652
  try {
511
653
  const status = runGit(["status", "--porcelain"]);
512
654
  if (!status)
513
- return mcpResponse({ ok: true, message: "Nothing to save. Phren is up to date.", data: { files: 0, pushed: false } });
655
+ return mcpResponse({ ok: true, message: `Nothing to save. Phren is up to date.${teamSuffix}`, data: { files: 0, pushed: false, ...teamData } });
514
656
  const files = status.split("\n").filter(Boolean);
515
657
  const projectNames = Array.from(new Set(files
516
658
  .map((line) => line.slice(3).trim().split("/")[0])
@@ -530,7 +672,7 @@ async function handlePushChanges(ctx, { message }) {
530
672
  runGit(["reset", "HEAD", "--", ".env", "**/.env", "*.pem", "*.key", ".config/auth-profiles.json"]);
531
673
  }
532
674
  catch { /* best effort */ }
533
- runGit(["commit", "-m", commitMsg]);
675
+ runGit(["commit", "-m", storeCommitMessage(commitMsg)]);
534
676
  let hasRemote = false;
535
677
  try {
536
678
  const remotes = runGit(["remote"]);
@@ -541,7 +683,7 @@ async function handlePushChanges(ctx, { message }) {
541
683
  }
542
684
  if (!hasRemote) {
543
685
  const changedFiles = status.split("\n").filter(Boolean).length;
544
- return mcpResponse({ ok: true, message: `Saved ${changedFiles} changed file(s). No remote configured, skipping push.`, data: { files: changedFiles, pushed: false } });
686
+ return mcpResponse({ ok: true, message: `Saved ${changedFiles} changed file(s). No remote configured, skipping push.${teamSuffix}`, data: { files: changedFiles, pushed: false, ...teamData } });
545
687
  }
546
688
  let pushed = false;
547
689
  let lastPushError = "";
@@ -556,39 +698,10 @@ async function handlePushChanges(ctx, { message }) {
556
698
  lastPushError = pushErr instanceof Error ? pushErr.message : String(pushErr);
557
699
  debugLog(`Push attempt ${attempt + 1} failed: ${lastPushError}`);
558
700
  if (attempt < 3) {
559
- try {
560
- runGit(["pull", "--rebase", "--quiet"], { timeout: 15000 });
561
- }
562
- catch (pullErr) {
563
- logger.warn("push_changes", `pullRebase: ${pullErr instanceof Error ? pullErr.message : String(pullErr)}`);
564
- const resolved = autoMergeConflicts(phrenPath);
565
- if (resolved) {
566
- try {
567
- runGit(["rebase", "--continue"], {
568
- timeout: 10000,
569
- env: { ...process.env, GIT_EDITOR: "true" },
570
- });
571
- }
572
- catch (continueErr) {
573
- logger.warn("push_changes", `rebaseContinue: ${continueErr instanceof Error ? continueErr.message : String(continueErr)}`);
574
- try {
575
- runGit(["rebase", "--abort"]);
576
- }
577
- catch (abortErr) {
578
- logger.warn("push_changes", `rebaseAbort: ${abortErr instanceof Error ? abortErr.message : String(abortErr)}`);
579
- }
580
- break;
581
- }
582
- }
583
- else {
584
- try {
585
- runGit(["rebase", "--abort"]);
586
- }
587
- catch (abortErr) {
588
- logger.warn("push_changes", `rebaseAbort2: ${abortErr instanceof Error ? abortErr.message : String(abortErr)}`);
589
- }
590
- break;
591
- }
701
+ const merged = await mergeStoreUpstream(phrenPath, { git: mergeGit, commitLocalWrites: false });
702
+ if (merged.status !== "updated" && merged.status !== "unchanged") {
703
+ logger.warn("push_changes", `mergeRemote: ${merged.detail}`);
704
+ break;
592
705
  }
593
706
  await new Promise(r => setTimeout(r, delays[attempt]));
594
707
  }
@@ -597,76 +710,18 @@ async function handlePushChanges(ctx, { message }) {
597
710
  const changedFiles = status.split("\n").filter(Boolean).length;
598
711
  runCustomHooks(phrenPath, "post-save", { PHREN_FILES_CHANGED: String(changedFiles), PHREN_PUSHED: String(pushed) });
599
712
  if (pushed) {
600
- return mcpResponse({ ok: true, message: `Saved ${changedFiles} changed file(s). Pushed to remote.`, data: { files: changedFiles, pushed: true } });
713
+ return mcpResponse({ ok: true, message: `Saved ${changedFiles} changed file(s). Pushed to remote.${teamSuffix}`, data: { files: changedFiles, pushed: true, ...teamData } });
601
714
  }
602
715
  else {
603
716
  return mcpResponse({
604
717
  ok: true,
605
- message: `Changes were committed but push failed.\n\nGit error: ${lastPushError}\n\nRun 'git push' manually from your phren directory.`,
606
- data: { files: changedFiles, pushed: false, pushError: lastPushError },
718
+ message: `Changes were committed but push failed.\n\nGit error: ${lastPushError}\n\nRun 'git push' manually from your phren directory.${teamSuffix}`,
719
+ data: { files: changedFiles, pushed: false, pushError: lastPushError, ...teamData },
607
720
  });
608
721
  }
609
722
  }
610
723
  catch (err) {
611
- return mcpResponse({ ok: false, error: `Save failed: ${errorMessage(err)}`, errorCode: "INTERNAL_ERROR" });
612
- }
613
- // Sync team stores: commit and push journal/tasks/truths changes
614
- try {
615
- const { getNonPrimaryStores } = await import("../store-registry.js");
616
- const teamStores = getNonPrimaryStores(phrenPath).filter((s) => s.role === "team");
617
- const teamResults = [];
618
- for (const store of teamStores) {
619
- if (!fs.existsSync(store.path) || !fs.existsSync(path.join(store.path, ".git")))
620
- continue;
621
- const runStoreGit = (args, opts = {}) => execFileSync("git", args, {
622
- cwd: store.path,
623
- encoding: "utf8",
624
- timeout: opts.timeout ?? EXEC_TIMEOUT_MS,
625
- env: opts.env,
626
- stdio: ["ignore", "pipe", "pipe"],
627
- }).trim();
628
- try {
629
- const storeStatus = runStoreGit(["status", "--porcelain"]);
630
- if (!storeStatus) {
631
- teamResults.push({ store: store.name, pushed: false });
632
- continue;
633
- }
634
- // Stage each team-safe pathspec individually — a single no-match
635
- // (e.g. no */truths.md in this store) used to abort the whole add.
636
- for (const spec of TEAM_STORE_PATHSPECS) {
637
- try {
638
- runStoreGit(["add", "--sparse", "--", spec]);
639
- }
640
- catch { /* best-effort */ }
641
- }
642
- const actor = process.env.PHREN_ACTOR || process.env.USER || "unknown";
643
- runStoreGit(["commit", "-m", `phren: ${actor} team sync`]);
644
- try {
645
- runStoreGit(["push"], { timeout: 15000 });
646
- teamResults.push({ store: store.name, pushed: true });
647
- }
648
- catch {
649
- try {
650
- runStoreGit(["pull", "--rebase", "--quiet"], { timeout: 15000 });
651
- runStoreGit(["push"], { timeout: 15000 });
652
- teamResults.push({ store: store.name, pushed: true });
653
- }
654
- catch (retryErr) {
655
- teamResults.push({ store: store.name, pushed: false, error: errorMessage(retryErr) });
656
- }
657
- }
658
- }
659
- catch (storeErr) {
660
- teamResults.push({ store: store.name, pushed: false, error: errorMessage(storeErr) });
661
- }
662
- }
663
- // Team store results are best-effort — don't fail the primary push for them
664
- if (teamResults.length > 0) {
665
- debugLog(`push_changes team stores: ${JSON.stringify(teamResults)}`);
666
- }
667
- }
668
- catch {
669
- // store-registry not available — skip silently
724
+ return mcpResponse({ ok: false, error: `Save failed: ${errorMessage(err)}${teamSuffix}`, errorCode: "INTERNAL_ERROR" });
670
725
  }
671
726
  }));
672
727
  }
@@ -687,6 +742,8 @@ export function register(server, ctx) {
687
742
  line: z.number().int().positive().optional().describe("1-based line number in file."),
688
743
  repo: z.string().optional().describe("Git repository root path for citation validation."),
689
744
  commit: z.string().optional().describe("Git commit SHA that supports this finding."),
745
+ name: z.string().optional().describe("The function, type or variable this finding is about: Name, Type.member or name(). Validated against the project's code index; stored unresolved when it does not resolve."),
746
+ symbol: z.string().optional().describe("Deprecated: use name. Accepted until @phren/cli 0.3.1."),
690
747
  supersedes: z.string().optional().describe("First 60 chars of the old finding this one replaces. The old entry will be marked as superseded."),
691
748
  task_item: z.string().optional().describe("Task item stable ID like bid:abcd1234, positional ID like A1, or item text to link this finding to."),
692
749
  }).optional().describe("Optional source citation for traceability (only used when finding is a single string)."),
package/dist/tools/ops.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
1
2
  import { mcpResponse, resolveStoreForProject } from "./types.js";
2
3
  import { z } from "zod";
3
4
  import * as fs from "fs";
@@ -159,6 +160,7 @@ async function handleHealthCheck(ctx, { include_consolidation }) {
159
160
  try {
160
161
  const { execFileSync } = await import("child_process");
161
162
  const remote = execFileSync("git", ["-C", phrenPath, "remote", "get-url", "origin"], {
163
+ env: nonInteractiveGitEnv(),
162
164
  encoding: "utf8",
163
165
  stdio: ["ignore", "pipe", "ignore"],
164
166
  timeout: 5_000,
@@ -166,6 +168,7 @@ async function handleHealthCheck(ctx, { include_consolidation }) {
166
168
  if (remote) {
167
169
  try {
168
170
  execFileSync("git", ["-C", phrenPath, "ls-remote", "--exit-code", "origin"], {
171
+ env: nonInteractiveGitEnv(),
169
172
  stdio: ["ignore", "ignore", "ignore"],
170
173
  timeout: 10_000,
171
174
  });
@@ -448,14 +451,14 @@ export function register(server, ctx) {
448
451
  server.registerTool("add_project", {
449
452
  title: "◆ phren · add project",
450
453
  description: "Bootstrap a project into phren from a repo or working directory. " +
451
- "Copies or creates CLAUDE.md/summary/tasks/findings under ~/.phren/<project> and adds the project to the active profile.",
454
+ "Copies or creates AGENTS.md/summary/tasks/findings under ~/.phren/<project> and adds the project to the active profile.",
452
455
  inputSchema: z.object({
453
456
  path: z.string().describe("Project path to import. Pass the current repo path explicitly."),
454
457
  profile: z.string().optional().describe("Profile to update. Defaults to the active profile."),
455
458
  ownership: z.enum(PROJECT_OWNERSHIP_MODES).optional()
456
459
  .describe("How Phren should treat repo-facing instruction files: phren-managed, detached, or repo-managed."),
457
460
  store: z.string().optional()
458
- .describe("Target store name (from stores.yaml). If omitted, auto-routes to the store that claims this project, or falls back to the primary store."),
461
+ .describe("Target store name (one attached on this machine). If omitted, auto-routes to the store that claims this project, or falls back to the primary store."),
459
462
  }),
460
463
  }, (params) => handleAddProject(ctx, params));
461
464
  server.registerTool("health_check", {
@@ -1,3 +1,6 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
2
+ import { projectMemoryCounts } from "../content/summarize.js";
3
+ import { moduleEnabled } from "../modules/runtime.js";
1
4
  import { mcpResponse, resolveStoreForProject } from "./types.js";
2
5
  import { z } from "zod";
3
6
  import * as fs from "fs";
@@ -15,7 +18,7 @@ import { entryScoreKey, getQualityMultiplier, getRetentionPolicy, recordLookupEv
15
18
  import { bestFindingNodeId } from "../finding-graph-id.js";
16
19
  import { callLlm } from "../content/dedup.js";
17
20
  import { rankResults, searchKnowledgeRows, applyTrustFilter, searchFederatedStores } from "../shared/retrieval.js";
18
- import { formatActorAttribution, parseScopeComment, parseSourceComment } from "../content/citation.js";
21
+ import { formatActorAttribution, parseScopeComment, parseSourceComment, collectSymbolCitations } from "../content/citation.js";
19
22
  import { resolveActiveSessionScope } from "./session.js";
20
23
  import { logger } from "../logger.js";
21
24
  /**
@@ -368,6 +371,7 @@ async function handleSearchKnowledge(ctx, { query, limit, project, type, tag, si
368
371
  const snippet = extractSnippet(row.content, query);
369
372
  const lifecycle = row.type === "findings" ? lifecycleByRowKey.get(findingRowKey(row)) : undefined;
370
373
  const federationSource = "federationSource" in row ? row.federationSource : undefined;
374
+ const symbols = row.type === "findings" ? collectSymbolCitations(row.content) : [];
371
375
  return {
372
376
  project: row.project,
373
377
  filename: row.filename,
@@ -376,6 +380,7 @@ async function handleSearchKnowledge(ctx, { query, limit, project, type, tag, si
376
380
  path: row.path,
377
381
  status: lifecycle?.primaryStatus,
378
382
  statuses: lifecycle?.statuses,
383
+ ...(symbols.length > 0 ? { symbol: symbols[0], symbols } : {}),
379
384
  ...(federationSource ? { federation_source: federationSource } : {}),
380
385
  };
381
386
  });
@@ -497,7 +502,9 @@ async function handleGetProjectSummary(ctx, { name }) {
497
502
  if (store && fs.existsSync(path.join(store.path, lookupName))) {
498
503
  const projDir = path.join(store.path, lookupName);
499
504
  const fsDocs = [];
500
- for (const [file, type] of [["summary.md", "summary"], ["CLAUDE.md", "claude"], [FINDINGS_FILENAME, "findings"], ["tasks.md", "task"], ["truths.md", "canonical"]]) {
505
+ for (const [file, type] of [["summary.md", "summary"], ["AGENTS.md", "claude"], [FINDINGS_FILENAME, "findings"], ["tasks.md", "task"], ["truths.md", "canonical"]]) {
506
+ if (type === "task" && !moduleEnabled(store.path, "tasks", ctx.profile))
507
+ continue;
501
508
  const filePath = path.join(projDir, file);
502
509
  if (fs.existsSync(filePath)) {
503
510
  fsDocs.push({ project: lookupName, filename: file, type, content: fs.readFileSync(filePath, "utf8").slice(0, 8000), path: filePath });
@@ -524,7 +531,7 @@ async function handleGetProjectSummary(ctx, { name }) {
524
531
  parts.push("\n*No summary.md found for this project.*");
525
532
  }
526
533
  if (claudeDoc) {
527
- parts.push(`\n## CLAUDE.md path\n\`${claudeDoc.path}\``);
534
+ parts.push(`\n## AGENTS.md path\n\`${claudeDoc.path}\``);
528
535
  }
529
536
  // Show truths if they exist
530
537
  if (canonicalDoc) {
@@ -541,6 +548,9 @@ async function handleGetProjectSummary(ctx, { name }) {
541
548
  data: {
542
549
  name,
543
550
  summary: summaryDoc?.content ?? null,
551
+ // What the project holds, counted the way every graph counts it.
552
+ counts: projectMemoryCounts(storeName ? (resolveAllStores(ctx.phrenPath).find((s) => s.name === storeName)?.path ?? ctx.phrenPath) : ctx.phrenPath, lookupName),
553
+ agentsMdPath: claudeDoc?.path ?? null,
544
554
  claudeMdPath: claudeDoc?.path ?? null,
545
555
  truthsPath: canonicalDoc?.path ?? null,
546
556
  files: indexedFiles,
@@ -589,7 +599,7 @@ async function handleListProjects(ctx, { page, page_size }) {
589
599
  return mcpResponse({ ok: false, error: `Page ${pageNum} out of range. Total pages: ${totalPages}.` });
590
600
  }
591
601
  const badgeTypes = ["claude", "findings", "summary", "task"];
592
- const badgeLabels = { claude: "CLAUDE.md", findings: "FINDINGS", summary: "summary", task: "task" };
602
+ const badgeLabels = { claude: "AGENTS.md", findings: "FINDINGS", summary: "summary", task: "task" };
593
603
  const projectList = pageProjects.map((entry) => {
594
604
  // Primary store projects: query the DB for badge info
595
605
  if (!entry.store) {
@@ -611,13 +621,13 @@ async function handleListProjects(ctx, { page, page_size }) {
611
621
  const projDir = store ? path.join(store.path, entry.name) : "";
612
622
  const badges = [];
613
623
  if (projDir) {
614
- if (fs.existsSync(path.join(projDir, "CLAUDE.md")))
615
- badges.push("CLAUDE.md");
624
+ if (fs.existsSync(path.join(projDir, "AGENTS.md")))
625
+ badges.push("AGENTS.md");
616
626
  if (fs.existsSync(path.join(projDir, FINDINGS_FILENAME)))
617
627
  badges.push("FINDINGS");
618
628
  if (fs.existsSync(path.join(projDir, "summary.md")))
619
629
  badges.push("summary");
620
- if (fs.existsSync(path.join(projDir, "tasks.md")))
630
+ if (store && moduleEnabled(store.path, "tasks", ctx.profile) && fs.existsSync(path.join(projDir, "tasks.md")))
621
631
  badges.push("task");
622
632
  }
623
633
  return { name: entry.name, store: entry.store, brief: "", badges, fileCount: badges.length };
@@ -672,6 +682,7 @@ async function handleGetFindings(ctx, { project, limit, include_superseded, incl
672
682
  }
673
683
  const capped = filteredItems.slice(0, limit ?? 50).map(entry => ({
674
684
  ...entry,
685
+ symbol: entry.citationData?.symbol,
675
686
  lifecycle: {
676
687
  status: entry.status,
677
688
  status_updated: entry.status_updated,
@@ -686,6 +697,8 @@ async function handleGetFindings(ctx, { project, limit, include_superseded, incl
686
697
  metadata.push(`task=${entry.taskItem}`);
687
698
  if (entry.scope)
688
699
  metadata.push(`scope=${entry.scope}`);
700
+ if (entry.symbol)
701
+ metadata.push(`symbol=${entry.symbol}`);
689
702
  if (entry.supersedes)
690
703
  metadata.push(`supersedes="${entry.supersedes.slice(0, 30)}"`);
691
704
  if (entry.supersededBy)
@@ -713,7 +726,7 @@ async function handleStoreList(ctx) {
713
726
  // Get last sync time from git log
714
727
  let lastSync = null;
715
728
  try {
716
- const result = execFileSync("git", ["log", "-1", "--format=%ci"], { cwd: store.path, encoding: "utf8", timeout: 3000 }).trim();
729
+ const result = execFileSync("git", ["log", "-1", "--format=%ci"], { env: nonInteractiveGitEnv(), cwd: store.path, encoding: "utf8", timeout: 3000 }).trim();
717
730
  lastSync = result || null;
718
731
  }
719
732
  catch { /* non-critical */ }