@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
@@ -7,6 +7,7 @@ import * as path from "path";
7
7
  import { execFileSync } from "child_process";
8
8
  import { homePath, EXEC_TIMEOUT_QUICK_MS, debugLog } from "../shared.js";
9
9
  import { errorMessage } from "../utils.js";
10
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
10
11
  import { ROOT as PACKAGE_ROOT, VERSION } from "../package-metadata.js";
11
12
  export const ROOT = PACKAGE_ROOT;
12
13
  export { VERSION };
@@ -22,6 +23,7 @@ export function commandVersion(cmd, args = ["--version"]) {
22
23
  const effectiveCmd = process.platform === "win32" && (cmd === "npm" || cmd === "npx") ? `${cmd}.cmd` : cmd;
23
24
  try {
24
25
  return execFileSync(effectiveCmd, args, {
26
+ env: cmd === "git" ? nonInteractiveGitEnv() : process.env,
25
27
  encoding: "utf8",
26
28
  stdio: ["ignore", "pipe", "ignore"],
27
29
  shell: process.platform === "win32" && effectiveCmd.endsWith(".cmd"),
@@ -21,7 +21,7 @@
21
21
  * `phren init` writes into the store itself and which the docs tell users to
22
22
  * put `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` / `PHREN_LLM_KEY` in.
23
23
  */
24
- export declare const STORE_SECRET_GITIGNORE_LINES: readonly [".runtime/", ".sessions/", ".env", "*.pem", "*.key", ".config/auth-profiles.json"];
24
+ export declare const STORE_SECRET_GITIGNORE_LINES: readonly [".runtime/", ".sessions/", ".env", "*.pem", "*.key", ".config/auth-profiles.json", ".config/modules.yaml.migration-backup"];
25
25
  /**
26
26
  * Whether a .gitignore body already covers every secret-bearing entry.
27
27
  * Compares whole trimmed lines, so a commented-out entry does not count.
@@ -37,6 +37,8 @@ export const STORE_SECRET_GITIGNORE_LINES = [
37
37
  // store created before the move, or one where the migration has not run yet,
38
38
  // never has its credentials committed.
39
39
  ".config/auth-profiles.json",
40
+ // Legacy module migration backups were once written into the working tree.
41
+ ".config/modules.yaml.migration-backup",
40
42
  ];
41
43
  /**
42
44
  * Whether a .gitignore body already covers every secret-bearing entry.
@@ -7,7 +7,7 @@ export declare function sweepAgentSkillSymlinks(phrenPath: string): void;
7
7
  /** Remove the given exclude entries (and the phren-managed marker) from a repo's .git/info/exclude. */
8
8
  export declare function removeGitExcludes(projectDir: string, entries: string[]): void;
9
9
  /**
10
- * Remove per-project repo mirror symlinks (CLAUDE.md, REFERENCE.md, findings,
10
+ * Remove per-project repo mirror symlinks (AGENTS.md, REFERENCE.md, findings,
11
11
  * AGENTS.md, CLAUDE-*.md, .github/copilot-instructions.md, .claude/skills/*) that
12
12
  * phren created in phren-managed repos, and strip the matching exclude lines.
13
13
  * Only removes symlinks that resolve back into the phren store.
@@ -147,7 +147,7 @@ export function removeGitExcludes(projectDir, entries) {
147
147
  }
148
148
  }
149
149
  /**
150
- * Remove per-project repo mirror symlinks (CLAUDE.md, REFERENCE.md, findings,
150
+ * Remove per-project repo mirror symlinks (AGENTS.md, REFERENCE.md, findings,
151
151
  * AGENTS.md, CLAUDE-*.md, .github/copilot-instructions.md, .claude/skills/*) that
152
152
  * phren created in phren-managed repos, and strip the matching exclude lines.
153
153
  * Only removes symlinks that resolve back into the phren store.
@@ -213,7 +213,7 @@ export function sweepProjectMirrors(phrenPath) {
213
213
  }
214
214
  };
215
215
  // Fixed mirror files.
216
- for (const f of ["CLAUDE.md", "REFERENCE.md", FINDINGS_FILENAME, "AGENTS.md", path.join(".github", "copilot-instructions.md")]) {
216
+ for (const f of ["AGENTS.md", "CLAUDE.md", "REFERENCE.md", FINDINGS_FILENAME, path.join(".github", "copilot-instructions.md")]) {
217
217
  removeMirror(f);
218
218
  }
219
219
  // CLAUDE-*.md split files.
@@ -212,7 +212,7 @@ export function rebuildMemory(phrenPath, projects) {
212
212
  managed += `| ${displayName(project)} | ${what} | MEMORY-${project}.md |\n`;
213
213
  }
214
214
  managed += "\n<!-- phren:projects:end -->";
215
- const freshHeader = "# Root Memory\n\n## Machine Context\nRead `~/.phren-context.md` for profile, active projects, last sync date.\n\n## Cross-Project Notes\n- Read a project's CLAUDE.md before making changes.\n- Per-project memory files (MEMORY-{name}.md) have commands, versions, findings.\n\n";
215
+ const freshHeader = "# Root Memory\n\n## Machine Context\nRead `~/.phren-context.md` for profile, active projects, last sync date.\n\n## Cross-Project Notes\n- Read a project's AGENTS.md before making changes.\n- Per-project memory files (MEMORY-{name}.md) have commands, versions, findings.\n\n";
216
216
  fs.writeFileSync(memoryFile, (header || freshHeader) + managed + "\n");
217
217
  log(` rebuilt ${memoryFile} (pointer format)`);
218
218
  const SUMMARY_START = "<!-- phren:summary:start -->";
@@ -1,2 +1,23 @@
1
1
  import type { DoctorResult } from "./link.js";
2
- export declare function runDoctor(phrenPath: string, fix?: boolean, checkData?: boolean): Promise<DoctorResult>;
2
+ import { type ConfirmStoreRemoval } from "../sync/auth-doctor.js";
3
+ /**
4
+ * Where `tool` stands relative to its ~/.local/bin wrapper, as far as this
5
+ * process can tell. Doctor often runs without the user's shell setup (over
6
+ * SSH, from a hook or a LaunchAgent), where ~/.local/bin is added only by
7
+ * .zshrc; then PATH says nothing about what the user's shell runs, and an
8
+ * installed wrapper is reported as unconfirmed rather than missing.
9
+ */
10
+ export type WrapperState = {
11
+ state: "active" | "missing" | "off-path";
12
+ } | {
13
+ state: "shadowed";
14
+ by: string;
15
+ };
16
+ export declare function wrapperState(tool: string, env?: NodeJS.ProcessEnv, resolve?: (tool: string) => string): WrapperState;
17
+ /** One doctor line per wrapper. The phren wrapper works off PATH too: hooks call it by its full path. */
18
+ export declare function wrapperCheck(tool: string, state: WrapperState): {
19
+ name: string;
20
+ ok: boolean;
21
+ detail: string;
22
+ };
23
+ export declare function runDoctor(phrenPath: string, fix?: boolean, checkData?: boolean, confirmStoreRemoval?: ConfirmStoreRemoval): Promise<DoctorResult>;
@@ -1,3 +1,4 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
1
2
  import * as fs from "fs";
2
3
  import * as path from "path";
3
4
  import { execFileSync } from "child_process";
@@ -10,7 +11,7 @@ import { validateGovernanceJson } from "../shared/governance.js";
10
11
  import { errorMessage } from "../utils.js";
11
12
  import { buildIndex, queryRows } from "../shared/index.js";
12
13
  import { validateTaskFormat, validateFindingsFormat } from "../shared/content.js";
13
- import { detectInstalledTools, isEphemeralNpxPath, findStaleHookEntrypoints } from "../hooks.js";
14
+ import { commandExists, detectInstalledTools, isEphemeralNpxPath, findStaleHookEntrypoints } from "../hooks.js";
14
15
  import { validateSkillFrontmatter, validateSkillsDir } from "./skills.js";
15
16
  import { verifyFileChecksums, updateFileChecksums } from "./checksums.js";
16
17
  import { buildSkillManifest } from "../skill/registry.js";
@@ -26,33 +27,71 @@ import { readInstallPreferences } from "../init/preferences.js";
26
27
  import { logger } from "../logger.js";
27
28
  import { CONTEXT_COST_LIMITS, medianHookInjectionTokens, storeWeight } from "../store-weight.js";
28
29
  import { resolveMcpProfile } from "../mcp/profile.js";
29
- // ── Doctor ──────────────────────────────────────────────────────────────────
30
- function isWrapperActive(tool) {
30
+ import { activeStoreAuthFailure, isGitAuthFailure, recordStoreAuthFailure, storeAuthDetail, storeSyncRemote } from "../sync/auth.js";
31
+ import { storeCredentialCheck } from "../sync/auth-doctor.js";
32
+ import { describeAutoSave } from "../sync/outcome.js";
33
+ export function wrapperState(tool, env = process.env, resolve = resolveOnPath) {
31
34
  const isWindows = process.platform === "win32";
32
- const wrapperName = isWindows ? `${tool}.cmd` : tool;
33
- const wrapperPath = homePath(".local", "bin", wrapperName);
35
+ const wrapperPath = homePath(".local", "bin", isWindows ? `${tool}.cmd` : tool);
34
36
  if (!fs.existsSync(wrapperPath))
35
- return false;
37
+ return { state: "missing" };
38
+ const same = (a, b) => path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase();
39
+ const dirs = (env.PATH ?? env.Path ?? "").split(path.delimiter).filter(Boolean);
40
+ if (!dirs.some((dir) => same(dir, path.dirname(wrapperPath))))
41
+ return { state: "off-path" };
42
+ const first = resolve(tool);
43
+ return first && same(first, wrapperPath) ? { state: "active" } : { state: "shadowed", by: first };
44
+ }
45
+ function resolveOnPath(tool) {
36
46
  try {
37
- const whichCmd = isWindows ? "where.exe" : "which";
38
- const whichArgs = isWindows ? [tool] : [tool];
39
- const raw = execFileSync(whichCmd, whichArgs, {
47
+ const raw = execFileSync(process.platform === "win32" ? "where.exe" : "which", [tool], {
40
48
  encoding: "utf8",
41
49
  stdio: ["ignore", "pipe", "ignore"],
42
50
  timeout: EXEC_TIMEOUT_QUICK_MS,
43
51
  }).trim();
44
52
  // `where.exe` can print multiple paths, one per line; check the first hit.
45
- const first = raw.split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? "";
46
- return path.resolve(first).toLowerCase() === path.resolve(wrapperPath).toLowerCase();
53
+ return raw.split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? "";
47
54
  }
48
55
  catch (err) {
49
- debugLog(`isWrapperActive: resolve ${tool} failed: ${errorMessage(err)}`);
50
- return false;
56
+ debugLog(`wrapperState: resolve ${tool} failed: ${errorMessage(err)}`);
57
+ return "";
58
+ }
59
+ }
60
+ /** One doctor line per wrapper. The phren wrapper works off PATH too: hooks call it by its full path. */
61
+ export function wrapperCheck(tool, state) {
62
+ const where = `~/.local/bin/${tool}${process.platform === "win32" ? ".cmd" : ""}`;
63
+ const name = tool === "phren" ? "wrapper:phren-cli" : `wrapper:${tool}`;
64
+ const label = tool === "phren" ? "phren CLI" : tool;
65
+ switch (state.state) {
66
+ case "active":
67
+ return { name, ok: true, detail: `${label} wrapper active via ${where}` };
68
+ case "off-path":
69
+ return {
70
+ name, ok: true,
71
+ detail: `${label} wrapper installed at ${where}; ~/.local/bin is not on this process's PATH ` +
72
+ `(shell startup files such as .zshrc add it only to interactive shells), so doctor cannot confirm it comes first there`,
73
+ };
74
+ case "shadowed":
75
+ return {
76
+ name, ok: false,
77
+ detail: state.by
78
+ ? `${tool} resolves to ${state.by} before the wrapper at ${where}; move ~/.local/bin earlier in PATH`
79
+ : `${label} wrapper at ${where} is on PATH but does not run; check that it is executable`,
80
+ };
81
+ case "missing":
82
+ return {
83
+ name, ok: false,
84
+ detail: tool === "phren" ? "phren CLI wrapper missing — run 'npx @phren/cli init' to install" : `${tool} wrapper missing`,
85
+ };
51
86
  }
52
87
  }
53
88
  function gitRemoteStatus(phrenPath, syncIntent) {
89
+ const auth = activeStoreAuthFailure(phrenPath);
90
+ if (auth)
91
+ return { ok: false, detail: storeAuthDetail(auth) };
54
92
  try {
55
93
  execFileSync("git", ["-C", phrenPath, "rev-parse", "--is-inside-work-tree"], {
94
+ env: nonInteractiveGitEnv(),
56
95
  stdio: ["ignore", "ignore", "ignore"],
57
96
  timeout: EXEC_TIMEOUT_QUICK_MS,
58
97
  });
@@ -61,8 +100,10 @@ function gitRemoteStatus(phrenPath, syncIntent) {
61
100
  return { ok: false, detail: "phren path is not a git repository" };
62
101
  }
63
102
  let remote;
103
+ const remoteName = storeSyncRemote(phrenPath)?.remoteName || "origin";
64
104
  try {
65
- remote = execFileSync("git", ["-C", phrenPath, "remote", "get-url", "origin"], {
105
+ remote = execFileSync("git", ["-C", phrenPath, "remote", "get-url", "--", remoteName], {
106
+ env: nonInteractiveGitEnv(),
66
107
  encoding: "utf8",
67
108
  stdio: ["ignore", "pipe", "ignore"],
68
109
  timeout: EXEC_TIMEOUT_QUICK_MS,
@@ -82,17 +123,21 @@ function gitRemoteStatus(phrenPath, syncIntent) {
82
123
  }
83
124
  // Remote exists — verify it's reachable
84
125
  try {
85
- execFileSync("git", ["-C", phrenPath, "ls-remote", "--exit-code", "origin"], {
86
- stdio: ["ignore", "ignore", "ignore"],
126
+ execFileSync("git", ["-C", phrenPath, "ls-remote", "--exit-code", "--", remoteName], {
127
+ env: nonInteractiveGitEnv(),
128
+ stdio: ["ignore", "ignore", "pipe"],
87
129
  timeout: 10_000,
88
130
  });
89
- return { ok: true, detail: `origin=${remote}` };
131
+ return { ok: true, detail: `${remoteName}=${remote}` };
90
132
  }
91
- catch {
133
+ catch (err) {
134
+ if (isGitAuthFailure(err)) {
135
+ return { ok: false, detail: storeAuthDetail(recordStoreAuthFailure(phrenPath, remoteName, remote)) };
136
+ }
92
137
  if (syncIntent === "sync") {
93
- return { ok: false, detail: `origin=${remote} (unreachable) — check your network or SSH keys` };
138
+ return { ok: false, detail: `${remoteName}=${remote} (unreachable); check your network or SSH keys` };
94
139
  }
95
- return { ok: true, detail: `origin=${remote} (unreachable, local-only mode)` };
140
+ return { ok: true, detail: `${remoteName}=${remote} (unreachable, local-only mode)` };
96
141
  }
97
142
  }
98
143
  /**
@@ -107,6 +152,7 @@ function rootConfigStatus(phrenPath, filename) {
107
152
  }
108
153
  try {
109
154
  execFileSync("git", ["cat-file", "-e", `HEAD:${filename}`], {
155
+ env: nonInteractiveGitEnv(),
110
156
  cwd: phrenPath,
111
157
  stdio: "ignore",
112
158
  timeout: EXEC_TIMEOUT_QUICK_MS,
@@ -121,6 +167,7 @@ function rootConfigStatus(phrenPath, filename) {
121
167
  function materializeRootConfig(phrenPath, filename) {
122
168
  try {
123
169
  execFileSync("git", ["sparse-checkout", "add", `/${filename}`], {
170
+ env: nonInteractiveGitEnv(),
124
171
  cwd: phrenPath,
125
172
  stdio: "ignore",
126
173
  timeout: EXEC_TIMEOUT_QUICK_MS,
@@ -172,7 +219,7 @@ function pushSkillMirrorChecks(checks, scope, manifest, destDir) {
172
219
  });
173
220
  }
174
221
  }
175
- export async function runDoctor(phrenPath, fix = false, checkData = false) {
222
+ export async function runDoctor(phrenPath, fix = false, checkData = false, confirmStoreRemoval) {
176
223
  // Import runLink lazily to avoid circular dependency at module load time
177
224
  const { runLink } = await import("./link.js");
178
225
  const checks = [];
@@ -298,20 +345,20 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
298
345
  // Under presets that don't symlink into ~/.claude, the "missing" links are
299
346
  // expected — report them as ok with a preset note instead of failures.
300
347
  if (caps.linkGlobalClaudeMd) {
301
- const globalClaudeSrc = path.join(phrenPath, "global", "CLAUDE.md");
348
+ const globalClaudeSrc = path.join(phrenPath, "global", "AGENTS.md");
302
349
  const globalClaudeDest = homePath(".claude", "CLAUDE.md");
303
350
  let globalLinkOk = false;
304
351
  try {
305
352
  globalLinkOk = fs.existsSync(globalClaudeDest) && fs.realpathSync(globalClaudeDest) === fs.realpathSync(globalClaudeSrc);
306
353
  }
307
354
  catch (err) {
308
- debugLog(`doctor: global CLAUDE.md symlink check failed: ${errorMessage(err)}`);
355
+ debugLog(`doctor: global AGENTS.md symlink check failed: ${errorMessage(err)}`);
309
356
  globalLinkOk = false;
310
357
  }
311
358
  checks.push({
312
359
  name: "global-link",
313
360
  ok: globalLinkOk,
314
- detail: globalLinkOk ? "global CLAUDE.md symlink ok" : "global CLAUDE.md link drifted/missing",
361
+ detail: globalLinkOk ? "global AGENTS.md symlink ok" : "global AGENTS.md link drifted/missing",
315
362
  });
316
363
  }
317
364
  else {
@@ -353,7 +400,7 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
353
400
  checks.push({ name: `project-path:${project}`, ok: false, detail: "project directory not found on disk" });
354
401
  continue;
355
402
  }
356
- for (const f of ["CLAUDE.md", "REFERENCE.md", FINDINGS_FILENAME]) {
403
+ for (const f of ["AGENTS.md", "REFERENCE.md", FINDINGS_FILENAME]) {
357
404
  const src = path.join(phrenPath, project, f);
358
405
  if (!fs.existsSync(src))
359
406
  continue;
@@ -376,17 +423,27 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
376
423
  }
377
424
  // Store registry health
378
425
  try {
379
- const { resolveAllStores, storesFilePath, describeUnavailableStore } = await import("../store-registry.js");
380
- const storesFile = storesFilePath(phrenPath);
381
- if (fs.existsSync(storesFile)) {
426
+ const { resolveAllStores, storesFilePath, attachedStoresFilePath, describeUnavailableStore, ignoredSyncedStores } = await import("../store-registry.js");
427
+ if (fs.existsSync(storesFilePath(phrenPath)) || fs.existsSync(attachedStoresFilePath(phrenPath))) {
382
428
  const stores = resolveAllStores(phrenPath);
383
429
  checks.push({
384
430
  name: "store-registry",
385
431
  ok: stores.length > 0,
386
432
  detail: stores.length > 0
387
- ? `${stores.length} stores configured`
433
+ ? `${stores.length} stores on this machine`
388
434
  : "stores.yaml exists but no stores parsed",
389
435
  });
436
+ // Only this machine's attachments are checked. Team stores another
437
+ // machine joined with an older phren still sit in the synced file.
438
+ const ignored = ignoredSyncedStores(phrenPath);
439
+ if (ignored.length > 0) {
440
+ checks.push({
441
+ name: "store-registry-synced",
442
+ ok: true,
443
+ detail: `ignoring ${ignored.map((s) => s.name).join(", ")} in the synced ${path.basename(storesFilePath(phrenPath))}: ` +
444
+ `team stores are attached per machine (${attachedStoresFilePath(phrenPath)}); remove them from stores.yaml once every machine runs this phren`,
445
+ });
446
+ }
390
447
  // Projects claimed by a store that is not attached here cannot be written
391
448
  // at all — phren refuses rather than diverting them to the primary store.
392
449
  const orphanedClaims = stores
@@ -400,6 +457,11 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
400
457
  : `projects claimed by unattached stores (writes to them will fail): ${orphanedClaims.join("; ")}`,
401
458
  });
402
459
  for (const store of stores) {
460
+ const credentials = await storeCredentialCheck(phrenPath, store, fix, confirmStoreRemoval);
461
+ if (credentials) {
462
+ checks.push(credentials);
463
+ continue;
464
+ }
403
465
  const pathExists = store.available !== false;
404
466
  const gitExists = pathExists && fs.existsSync(path.join(store.path, ".git"));
405
467
  if (!pathExists) {
@@ -552,7 +614,7 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
552
614
  const injection = medianHookInjectionTokens(phrenPath);
553
615
  const problems = [];
554
616
  if (weight.globalClaude > CONTEXT_COST_LIMITS.globalClaudeWords)
555
- problems.push(`global CLAUDE.md is ${weight.globalClaude} words (aim under ${CONTEXT_COST_LIMITS.globalClaudeWords})`);
617
+ problems.push(`global AGENTS.md is ${weight.globalClaude} words (aim under ${CONTEXT_COST_LIMITS.globalClaudeWords})`);
556
618
  if (profile === "full")
557
619
  problems.push("MCP profile is full (61 tools, ~53k chars of schema per session); `phren config mcp-profile core` is ~17k");
558
620
  if (injection.medianTokens > CONTEXT_COST_LIMITS.medianInjectionTokens)
@@ -562,7 +624,7 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
562
624
  ok: problems.length === 0,
563
625
  detail: problems.length
564
626
  ? problems.join("; ")
565
- : `global CLAUDE.md ${weight.globalClaude} words · MCP profile ${profile} (${profile === "core" ? "10 tools, ~17k chars" : "61 tools, ~53k chars"})${injection.prompts ? ` · median injection ${injection.medianTokens} tokens over ${injection.prompts} prompts` : ""} · store: findings ${weight.findings.toLocaleString("en-US")} words, archive ${weight.reference.toLocaleString("en-US")}, tasks ${weight.tasks.toLocaleString("en-US")}, skills ${weight.skills.toLocaleString("en-US")}`,
627
+ : `global AGENTS.md ${weight.globalClaude} words · MCP profile ${profile} (${profile === "core" ? "10 tools, ~17k chars" : "61 tools, ~53k chars"})${injection.prompts ? ` · median injection ${injection.medianTokens} tokens over ${injection.prompts} prompts` : ""} · store: findings ${weight.findings.toLocaleString("en-US")} words, archive ${weight.reference.toLocaleString("en-US")}, tasks ${weight.tasks.toLocaleString("en-US")}, skills ${weight.skills.toLocaleString("en-US")}`,
566
628
  });
567
629
  }
568
630
  catch (err) {
@@ -580,9 +642,7 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
580
642
  checks.push({
581
643
  name: "runtime-auto-save",
582
644
  ok: autoSaveStatus === "saved-pushed" || autoSaveStatus === "saved-local" || autoSaveStatus === "clean",
583
- detail: autoSaveStatus
584
- ? `last auto-save: ${autoSaveStatus}${autoSaveAt ? ` @ ${autoSaveAt}` : ""}`
585
- : "no auto-save runtime record yet",
645
+ detail: describeAutoSave({ status: autoSaveStatus, at: autoSaveAt, detail: typeof autoSaveObj?.["detail"] === "string" ? autoSaveObj["detail"] : undefined }, isRecord(runtime?.["lastSync"]) ? runtime["lastSync"] : undefined),
586
646
  });
587
647
  checks.push({
588
648
  name: "runtime-prompt",
@@ -649,28 +709,14 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
649
709
  detail: codexWritable ? `writable: ${codexHooks}` : `not writable: ${codexHooks}`,
650
710
  });
651
711
  }
652
- const wrapperSuffix = process.platform === "win32" ? ".cmd" : "";
653
712
  for (const tool of ["copilot", "cursor", "codex"]) {
654
- if (!detected.has(tool))
713
+ // A tool can count as detected from its config folder alone (Copilot's
714
+ // ~/.copilot, say); a wrapper only makes sense around a binary on PATH.
715
+ if (!detected.has(tool) || !commandExists(tool))
655
716
  continue;
656
- const active = isWrapperActive(tool);
657
- checks.push({
658
- name: `wrapper:${tool}`,
659
- ok: active,
660
- detail: active
661
- ? `${tool} wrapper active via ~/.local/bin/${tool}${wrapperSuffix}`
662
- : `${tool} wrapper missing or not first in PATH`,
663
- });
717
+ checks.push(wrapperCheck(tool, wrapperState(tool)));
664
718
  }
665
- // Check phren CLI wrapper
666
- const phrenCliActive = isWrapperActive("phren");
667
- checks.push({
668
- name: "wrapper:phren-cli",
669
- ok: phrenCliActive,
670
- detail: phrenCliActive
671
- ? `phren CLI wrapper active via ~/.local/bin/phren${wrapperSuffix}`
672
- : "phren CLI wrapper missing — run 'npx @phren/cli init' to install",
673
- });
719
+ checks.push(wrapperCheck("phren", wrapperState("phren")));
674
720
  if (fix) {
675
721
  const repaired = repairPreexistingInstall(phrenPath);
676
722
  const details = [];
@@ -789,7 +835,7 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
789
835
  const projectName = path.basename(projectDir);
790
836
  if (projectName === "global")
791
837
  continue;
792
- for (const mdFile of [FINDINGS_FILENAME, ...TASK_FILE_ALIASES, "review.md", "CLAUDE.md", "REFERENCE.md"]) {
838
+ for (const mdFile of [FINDINGS_FILENAME, ...TASK_FILE_ALIASES, "review.md", "AGENTS.md", "REFERENCE.md"]) {
793
839
  const filePath = path.join(projectDir, mdFile);
794
840
  if (!fs.existsSync(filePath))
795
841
  continue;
package/dist/link/link.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
2
+ import { reconcileModuleHooks } from "../bridge/install.js";
1
3
  import * as fs from "fs";
2
4
  import * as path from "path";
3
5
  import * as readline from "readline";
@@ -18,7 +20,6 @@ import { listMachines as listMachinesShared, listProfiles as listProfilesShared,
18
20
  import { writeSkillMd, isManagedSymlink } from "./skills.js";
19
21
  import { resolveManagementCapabilities } from "../init/management-preset.js";
20
22
  import { syncScopeSkillsToDir } from "../skill/files.js";
21
- import { renderSkillInstructionsSection } from "../skill/registry.js";
22
23
  import { findProjectDir } from "../project-locator.js";
23
24
  import { getProjectOwnershipMode, readProjectConfig, } from "../project-config.js";
24
25
  import { writeContextDefault, writeContextDebugging, writeContextPlanning, writeContextClean, readBackNativeMemory, rebuildMemory, } from "./context.js";
@@ -81,7 +82,7 @@ function maybeOfferStarterTemplateUpdate(phrenPath) {
81
82
  const prefs = JSON.parse(fs.readFileSync(prefsPath, "utf8"));
82
83
  if (isVersionNewer(current, prefs.installedVersion)) {
83
84
  log(` Starter template update available: v${prefs.installedVersion} -> v${current}`);
84
- log(` Run \`phren init --apply-starter-update\` to refresh global/CLAUDE.md and global skills.`);
85
+ log(` Run \`phren init --apply-starter-update\` to refresh global/AGENTS.md and global skills.`);
85
86
  }
86
87
  }
87
88
  catch (err) {
@@ -118,7 +119,7 @@ async function registerMachine(phrenPath) {
118
119
  // ── Sparse checkout ─────────────────────────────────────────────────────────
119
120
  function setupSparseCheckout(phrenPath, projects) {
120
121
  try {
121
- execFileSync("git", ["rev-parse", "--git-dir"], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_QUICK_MS });
122
+ execFileSync("git", ["rev-parse", "--git-dir"], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_QUICK_MS });
122
123
  }
123
124
  catch (err) {
124
125
  logger.debug("link", `setupSparseCheckout notAGitRepo: ${errorMessage(err)}`);
@@ -141,8 +142,8 @@ function setupSparseCheckout(phrenPath, projects) {
141
142
  ];
142
143
  const paths = [...alwaysInclude, ...projects];
143
144
  try {
144
- execFileSync("git", ["sparse-checkout", "set", ...paths], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
145
- execFileSync("git", ["pull", "--ff-only"], { cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
145
+ execFileSync("git", ["sparse-checkout", "set", ...paths], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
146
+ execFileSync("git", ["pull", "--ff-only"], { env: nonInteractiveGitEnv(), cwd: phrenPath, stdio: "ignore", timeout: EXEC_TIMEOUT_MS });
146
147
  }
147
148
  catch (err) {
148
149
  debugLog(`setupSparseCheckout: git sparse-checkout or pull failed: ${errorMessage(err)}`);
@@ -157,10 +158,11 @@ function addGitExcludes(projectDir, entries) {
157
158
  return;
158
159
  try {
159
160
  // Filter out files already tracked by git — exclude only affects untracked files,
160
- // and adding tracked files could confuse users who version-control their own CLAUDE.md
161
+ // and adding tracked files could confuse users who version-control their own AGENTS.md
161
162
  let tracked;
162
163
  try {
163
164
  const out = execFileSync("git", ["ls-files", "--", ...entries], {
165
+ env: nonInteractiveGitEnv(),
164
166
  cwd: projectDir,
165
167
  timeout: EXEC_TIMEOUT_QUICK_MS,
166
168
  encoding: "utf8",
@@ -205,7 +207,10 @@ function symlinkFile(src, dest, managedRoot) {
205
207
  }
206
208
  else {
207
209
  try {
208
- if (stat.isFile() && fs.readFileSync(dest, "utf8") === fs.readFileSync(src, "utf8")) {
210
+ const existing = stat.isFile() ? fs.readFileSync(dest, "utf8") : "";
211
+ const isOldGeneratedAgents = path.basename(dest) === "AGENTS.md"
212
+ && existing.includes("<!-- phren:generated-agents -->");
213
+ if (stat.isFile() && (existing === fs.readFileSync(src, "utf8") || isOldGeneratedAgents)) {
209
214
  fs.unlinkSync(dest);
210
215
  }
211
216
  else {
@@ -237,41 +242,6 @@ function addTokenAnnotation(filePath) {
237
242
  const rounded = Math.round((tokens + 50) / 100) * 100;
238
243
  atomicWriteText(filePath, `<!-- tokens: ~${rounded} -->\n${content}`);
239
244
  }
240
- const GENERATED_AGENTS_MARKER = "<!-- phren:generated-agents -->";
241
- function writeManagedAgentsFile(src, dest, content, managedRoot) {
242
- try {
243
- const stat = fs.lstatSync(dest);
244
- if (stat.isDirectory()) {
245
- log(` preserve existing directory: ${dest}`);
246
- return false;
247
- }
248
- if (stat.isSymbolicLink()) {
249
- const currentTarget = fs.readlinkSync(dest);
250
- const resolvedTarget = path.resolve(path.dirname(dest), currentTarget);
251
- if (resolvedTarget === path.resolve(src) || isManagedSymlink(dest, managedRoot)) {
252
- fs.unlinkSync(dest);
253
- }
254
- else {
255
- log(` preserve existing file: ${dest}`);
256
- return false;
257
- }
258
- }
259
- else {
260
- const existing = fs.readFileSync(dest, "utf8");
261
- if (!existing.includes(GENERATED_AGENTS_MARKER)) {
262
- log(` preserve existing file: ${dest}`);
263
- return false;
264
- }
265
- fs.unlinkSync(dest);
266
- }
267
- }
268
- catch (err) {
269
- if (err.code !== "ENOENT")
270
- throw err;
271
- }
272
- atomicWriteText(dest, `${content.trimEnd()}\n`);
273
- return true;
274
- }
275
245
  // ── Linking operations ──────────────────────────────────────────────────────
276
246
  function linkGlobal(phrenPath, tools, caps) {
277
247
  if (caps.installSkillLinks) {
@@ -290,7 +260,7 @@ function linkGlobal(phrenPath, tools, caps) {
290
260
  }
291
261
  }
292
262
  if (caps.linkGlobalClaudeMd) {
293
- const globalClaude = path.join(phrenPath, "global", "CLAUDE.md");
263
+ const globalClaude = path.join(phrenPath, "global", "AGENTS.md");
294
264
  if (fs.existsSync(globalClaude)) {
295
265
  symlinkFile(globalClaude, homePath(".claude", "CLAUDE.md"), phrenPath);
296
266
  if (tools.has("copilot")) {
@@ -350,12 +320,21 @@ function linkProject(phrenPath, project, tools, caps) {
350
320
  return;
351
321
  log(` ${project} -> ${target}`);
352
322
  const excludeEntries = [];
353
- for (const f of ["CLAUDE.md", "REFERENCE.md", FINDINGS_FILENAME]) {
323
+ for (const f of ["AGENTS.md", "REFERENCE.md", FINDINGS_FILENAME]) {
354
324
  const src = path.join(phrenPath, project, f);
355
325
  if (fs.existsSync(src)) {
356
326
  if (symlinkFile(src, path.join(target, f), phrenPath))
357
327
  excludeEntries.push(f);
358
- if (f === "CLAUDE.md") {
328
+ if (f === "AGENTS.md") {
329
+ if (tools.has("claude")) {
330
+ try {
331
+ if (symlinkFile(src, path.join(target, "CLAUDE.md"), phrenPath))
332
+ excludeEntries.push("CLAUDE.md");
333
+ }
334
+ catch (err) {
335
+ logger.debug("link", `linkProject claudeInstructions: ${errorMessage(err)}`);
336
+ }
337
+ }
359
338
  if (tools.has("copilot")) {
360
339
  try {
361
340
  const copilotDir = path.join(target, ".github");
@@ -379,8 +358,8 @@ function linkProject(phrenPath, project, tools, caps) {
379
358
  }
380
359
  }
381
360
  }
382
- // Token annotation on CLAUDE.md
383
- const claudeFile = path.join(phrenPath, project, "CLAUDE.md");
361
+ // Token annotation on AGENTS.md
362
+ const claudeFile = path.join(phrenPath, project, "AGENTS.md");
384
363
  if (fs.existsSync(claudeFile)) {
385
364
  try {
386
365
  addTokenAnnotation(claudeFile);
@@ -391,20 +370,8 @@ function linkProject(phrenPath, project, tools, caps) {
391
370
  }
392
371
  // Project-level skills
393
372
  const targetSkills = path.join(target, ".claude", "skills");
394
- const skillManifest = config.skills !== false
395
- ? syncScopeSkillsToDir(phrenPath, project, targetSkills)
396
- : undefined;
397
- if (tools.has("codex") && fs.existsSync(claudeFile)) {
398
- try {
399
- const manifest = skillManifest || syncScopeSkillsToDir(phrenPath, project, targetSkills);
400
- const agentsContent = `${fs.readFileSync(claudeFile, "utf8").trimEnd()}\n\n${GENERATED_AGENTS_MARKER}\n${renderSkillInstructionsSection(manifest)}\n`;
401
- if (writeManagedAgentsFile(claudeFile, path.join(target, "AGENTS.md"), agentsContent, phrenPath))
402
- excludeEntries.push("AGENTS.md");
403
- }
404
- catch (err) {
405
- logger.debug("link", `linkProject agentsMd: ${errorMessage(err)}`);
406
- }
407
- }
373
+ if (config.skills !== false)
374
+ syncScopeSkillsToDir(phrenPath, project, targetSkills);
408
375
  // Auto-exclude phren-managed files from git status
409
376
  if (excludeEntries.length > 0)
410
377
  addGitExcludes(target, excludeEntries);
@@ -548,6 +515,7 @@ export async function runLink(phrenPath, opts = {}) {
548
515
  else {
549
516
  log(` Hooks registration skipped (hooks-mode is off)`);
550
517
  }
518
+ await reconcileModuleHooks(phrenPath, profile);
551
519
  // Write phren.SKILL.md
552
520
  try {
553
521
  writeSkillMd(phrenPath);
@@ -34,8 +34,8 @@ export function refreshLinkedContext(phrenPath, profile) {
34
34
  ? syncScopeSkillsToDir(phrenPath, project, skillsDir)
35
35
  : buildSkillManifest(phrenPath, profile, project);
36
36
  const agentsPath = path.join(target, "AGENTS.md");
37
- const claudePath = path.join(source, "CLAUDE.md");
38
- // The generated file is a snapshot, unlike the live CLAUDE.md symlink.
37
+ const claudePath = path.join(source, "AGENTS.md");
38
+ // The generated file is a snapshot, unlike the live AGENTS.md symlink.
39
39
  // Preserve native/user-owned instructions and installations without a Codex mirror.
40
40
  if (!fs.existsSync(agentsPath) || !fs.existsSync(claudePath) || fs.lstatSync(agentsPath).isSymbolicLink())
41
41
  continue;