@phren/cli 0.2.15 → 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 (386) 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.js +1 -1
  235. package/dist/init/init.js +26 -6
  236. package/dist/init/management-preset.d.ts +1 -1
  237. package/dist/init/management-preset.js +2 -2
  238. package/dist/init/preferences.js +1 -1
  239. package/dist/init/self-wiring.js +1 -1
  240. package/dist/init/setup.d.ts +3 -26
  241. package/dist/init/setup.js +49 -588
  242. package/dist/init/shared.js +2 -0
  243. package/dist/init/store-gitignore.d.ts +1 -1
  244. package/dist/init/store-gitignore.js +2 -0
  245. package/dist/init/teardown.d.ts +1 -1
  246. package/dist/init/teardown.js +2 -2
  247. package/dist/link/context.js +1 -1
  248. package/dist/link/doctor.d.ts +22 -1
  249. package/dist/link/doctor.js +100 -54
  250. package/dist/link/link.js +29 -61
  251. package/dist/link/refresh.js +2 -2
  252. package/dist/link/skills.js +26 -5
  253. package/dist/machine-identity.d.ts +3 -0
  254. package/dist/machine-identity.js +6 -0
  255. package/dist/mcp/profile.d.ts +2 -15
  256. package/dist/mcp/profile.js +64 -9
  257. package/dist/memory-ui-graph.runtime.js +279 -283
  258. package/dist/modules/code-package.d.ts +16 -0
  259. package/dist/modules/code-package.js +152 -0
  260. package/dist/modules/command.d.ts +2 -0
  261. package/dist/modules/command.js +67 -0
  262. package/dist/modules/config.d.ts +4 -0
  263. package/dist/modules/config.js +70 -0
  264. package/dist/modules/manifest.d.ts +41 -0
  265. package/dist/modules/manifest.js +1 -0
  266. package/dist/modules/provision.d.ts +3 -0
  267. package/dist/modules/provision.js +84 -0
  268. package/dist/modules/registry.d.ts +16 -0
  269. package/dist/modules/registry.js +250 -0
  270. package/dist/modules/runtime.d.ts +15 -0
  271. package/dist/modules/runtime.js +59 -0
  272. package/dist/package-metadata.js +10 -2
  273. package/dist/phren-dotenv.js +4 -2
  274. package/dist/phren-paths.d.ts +3 -2
  275. package/dist/phren-paths.js +4 -5
  276. package/dist/profile-store.js +4 -5
  277. package/dist/project-config.d.ts +19 -1
  278. package/dist/project-config.js +29 -3
  279. package/dist/project-topics.js +4 -4
  280. package/dist/provider-adapters.js +1 -4
  281. package/dist/query-correlation.js +6 -6
  282. package/dist/session/artifacts.js +5 -5
  283. package/dist/session/checkpoints.js +5 -0
  284. package/dist/session/utils.d.ts +2 -2
  285. package/dist/session/utils.js +6 -6
  286. package/dist/shared/content.d.ts +1 -1
  287. package/dist/shared/content.js +1 -1
  288. package/dist/shared/data-utils.js +1 -1
  289. package/dist/shared/fragment-graph.d.ts +1 -1
  290. package/dist/shared/fragment-graph.js +5 -5
  291. package/dist/shared/index.js +48 -7
  292. package/dist/shared/retrieval.d.ts +18 -1
  293. package/dist/shared/retrieval.js +100 -11
  294. package/dist/shared/search-fallback.js +4 -6
  295. package/dist/shared/sqljs.d.ts +2 -0
  296. package/dist/shared/sqljs.js +4 -2
  297. package/dist/shared.d.ts +0 -1
  298. package/dist/shared.js +0 -1
  299. package/dist/shell/input.d.ts +1 -5
  300. package/dist/shell/input.js +16 -10
  301. package/dist/shell/palette.d.ts +2 -2
  302. package/dist/shell/palette.js +3 -7
  303. package/dist/shell/render.d.ts +3 -1
  304. package/dist/shell/render.js +4 -4
  305. package/dist/shell/shell.js +4 -1
  306. package/dist/shell/types.d.ts +1 -0
  307. package/dist/shell/types.js +4 -0
  308. package/dist/shell/view.d.ts +0 -4
  309. package/dist/shell/view.js +19 -27
  310. package/dist/skill/registry.js +25 -17
  311. package/dist/skill/state.d.ts +3 -0
  312. package/dist/skill/state.js +13 -7
  313. package/dist/status.js +38 -17
  314. package/dist/store-registry.d.ts +44 -18
  315. package/dist/store-registry.js +169 -60
  316. package/dist/store-weight.d.ts +1 -6
  317. package/dist/store-weight.js +4 -2
  318. package/dist/sync/auth-doctor.d.ts +8 -0
  319. package/dist/sync/auth-doctor.js +27 -0
  320. package/dist/sync/auth.d.ts +27 -0
  321. package/dist/sync/auth.js +114 -0
  322. package/dist/sync/conflict-resolve.d.ts +9 -0
  323. package/dist/sync/conflict-resolve.js +146 -0
  324. package/dist/sync/git-state.d.ts +4 -0
  325. package/dist/sync/git-state.js +49 -0
  326. package/dist/sync/outcome.d.ts +34 -0
  327. package/dist/sync/outcome.js +57 -0
  328. package/dist/sync/pull.d.ts +15 -7
  329. package/dist/sync/pull.js +84 -35
  330. package/dist/sync/store-merge.d.ts +29 -0
  331. package/dist/sync/store-merge.js +137 -0
  332. package/dist/sync/task-merge.d.ts +22 -0
  333. package/dist/sync/task-merge.js +158 -0
  334. package/dist/task/github.js +1 -1
  335. package/dist/task/lifecycle.d.ts +5 -0
  336. package/dist/task/lifecycle.js +67 -23
  337. package/dist/terminal-text.d.ts +5 -0
  338. package/dist/terminal-text.js +11 -0
  339. package/dist/test-global-setup.js +7 -0
  340. package/dist/tool-registry.d.ts +1 -1
  341. package/dist/tool-registry.js +3 -1
  342. package/dist/tools/code.d.ts +3 -0
  343. package/dist/tools/code.js +178 -0
  344. package/dist/tools/config.js +5 -0
  345. package/dist/tools/data.js +14 -7
  346. package/dist/tools/dispatch.d.ts +2 -0
  347. package/dist/tools/dispatch.js +66 -0
  348. package/dist/tools/finding.js +43 -41
  349. package/dist/tools/ops.js +5 -2
  350. package/dist/tools/search.js +21 -8
  351. package/dist/tools/session.js +21 -22
  352. package/dist/tools/tasks.js +8 -2
  353. package/dist/tools/types.d.ts +2 -2
  354. package/dist/tools/types.js +2 -2
  355. package/dist/ui/assets.js +1 -1
  356. package/dist/ui/data.js +14 -15
  357. package/dist/ui/deep-void.d.ts +1 -1
  358. package/dist/ui/deep-void.js +0 -1
  359. package/dist/ui/graph-chrome.d.ts +1 -1
  360. package/dist/ui/graph-chrome.js +51 -0
  361. package/dist/ui/page.js +5 -5
  362. package/dist/ui/scripts.js +67 -30
  363. package/dist/ui/server.js +34 -6
  364. package/dist/update.js +1 -1
  365. package/dist/utils-fts.js +1 -0
  366. package/dist/utils-helpers.d.ts +7 -0
  367. package/dist/utils-helpers.js +17 -0
  368. package/dist/utils.d.ts +1 -1
  369. package/dist/utils.js +1 -1
  370. package/package.json +45 -3
  371. package/plugins/opencode/phren-transcript.js +340 -0
  372. package/starter/README.md +4 -4
  373. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  374. package/starter/global/skills/conductor/SKILL.md +106 -0
  375. package/starter/global/skills/fanout/SKILL.md +20 -0
  376. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  377. package/starter/global/skills/phren-init/SKILL.md +4 -4
  378. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  379. package/starter/templates/frontend/reference/README.md +1 -1
  380. package/starter/templates/library/reference/README.md +1 -1
  381. package/starter/templates/monorepo/reference/README.md +1 -1
  382. package/starter/templates/python-project/reference/README.md +1 -1
  383. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  384. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  385. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  386. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -1,3 +1,6 @@
1
+ import { nonInteractiveGitEnv } from "../utils-helpers.js";
2
+ import { moduleEnabled, moduleSnapshot } from "../modules/runtime.js";
3
+ import { skillEnabled, reconcileStarterSkills, starterInstructions } from "../modules/provision.js";
1
4
  /**
2
5
  * Governance files, root file migration, verification, starter templates, bootstrap.
3
6
  */
@@ -6,26 +9,26 @@ import * as path from "path";
6
9
  import * as os from "os";
7
10
  import * as yaml from "js-yaml";
8
11
  import { loadYamlDocument } from "../phren-core.js";
9
- import { atomicWriteText, debugLog, findProjectNameCaseInsensitive, findProjectNamesByCanonicalKey, projectSlugFromPath, hookConfigPath, EXEC_TIMEOUT_QUICK_MS, readRootManifest, sessionsDir, runtimeHealthFile, isRecord, } from "../shared.js";
12
+ import { atomicWriteText, debugLog, hookConfigPath, EXEC_TIMEOUT_QUICK_MS, readRootManifest, sessionsDir, runtimeHealthFile, isRecord, } from "../shared.js";
10
13
  import { ensurePrivateDir, homePath } from "../phren-paths.js";
11
14
  import { isLiveForeignPhrenRoot, phrenRootFromGlobalClaudeLink } from "./guard-globals.js";
12
15
  import { resolveWorktreeParent } from "../git-worktree.js";
13
- import { addProjectToProfile, listProfiles, resolveActiveProfile, setMachineProfile } from "../profile-store.js";
16
+ import { listProfiles, resolveActiveProfile, setMachineProfile } from "../profile-store.js";
14
17
  import { getMachineName } from "../machine-identity.js";
15
18
  import { execFileSync } from "child_process";
16
19
  import { GOVERNANCE_SCHEMA_VERSION, } from "../shared/governance.js";
17
- import { STOP_WORDS, errorMessage } from "../utils.js";
20
+ import { errorMessage } from "../utils.js";
18
21
  import { ROOT, STARTER_DIR, VERSION, resolveEntryScript, commandVersion, versionAtLeast, nearestWritableTarget } from "./shared.js";
19
22
  import { readInstallPreferences } from "./preferences.js";
20
23
  import { getManagementPreset, resolveManagementCapabilities, } from "./management-preset.js";
21
24
  import { TASKS_FILENAME } from "../data/tasks.js";
22
- import { FINDINGS_FILENAME } from "../data/access.js";
23
- import { getProjectOwnershipDefault, parseProjectOwnershipMode, readProjectConfig, writeProjectConfig, } from "../project-config.js";
24
- import { getBuiltinTopicConfig, normalizeBuiltinTopicDomain } from "../project-topics.js";
25
25
  import { writeSkillMd } from "../link/skills.js";
26
26
  import { syncScopeSkillsToDir } from "../skill/files.js";
27
27
  import { detectInstalledTools } from "../hooks.js";
28
28
  import { logger } from "../logger.js";
29
+ import { migrateStoreAgentInstructions } from "../agent-instructions.js";
30
+ import { bootstrapFromExisting, ensureProjectScaffold, inferInitScaffoldFromRepo, } from "../core/project-registry.js";
31
+ export { bootstrapFromExisting, ensureProjectScaffold, inferInitScaffoldFromRepo, };
29
32
  const LEGACY_SAMPLE_PROJECTS = new Set(["my-api", "my-frontend"]);
30
33
  function normalizeProjects(raw) {
31
34
  if (!Array.isArray(raw))
@@ -158,17 +161,19 @@ function ensureGlobalStarterAssets(phrenPath) {
158
161
  return created;
159
162
  const targetGlobalDir = path.join(phrenPath, "global");
160
163
  fs.mkdirSync(targetGlobalDir, { recursive: true });
161
- const starterClaude = path.join(starterGlobal, "CLAUDE.md");
162
- const targetClaude = path.join(targetGlobalDir, "CLAUDE.md");
164
+ const starterClaude = path.join(starterGlobal, "AGENTS.md");
165
+ const targetClaude = path.join(targetGlobalDir, "AGENTS.md");
163
166
  if (fs.existsSync(starterClaude) && !fs.existsSync(targetClaude)) {
164
167
  fs.copyFileSync(starterClaude, targetClaude);
165
- created.push("global/CLAUDE.md");
168
+ created.push("global/AGENTS.md");
166
169
  }
167
170
  const starterSkillsDir = path.join(starterGlobal, "skills");
168
171
  const targetSkillsDir = path.join(targetGlobalDir, "skills");
169
172
  fs.mkdirSync(targetSkillsDir, { recursive: true });
170
173
  if (fs.existsSync(starterSkillsDir)) {
171
174
  for (const entry of fs.readdirSync(starterSkillsDir, { withFileTypes: true })) {
175
+ if (!skillEnabled(phrenPath, entry.name))
176
+ continue;
172
177
  const source = path.join(starterSkillsDir, entry.name);
173
178
  const target = path.join(targetSkillsDir, entry.name);
174
179
  if (entry.isFile() && entry.name.endsWith(".md")) {
@@ -269,15 +274,14 @@ function ensureGeneratedSkillArtifacts(phrenPath, preferredHome) {
269
274
  }
270
275
  }
271
276
  const skillMdPath = path.join(phrenPath, "phren.SKILL.md");
272
- if (!fs.existsSync(skillMdPath)) {
273
- try {
274
- writeSkillMd(phrenPath);
275
- if (fs.existsSync(skillMdPath))
276
- created.push("phren.SKILL.md");
277
- }
278
- catch (err) {
279
- debugLog(`ensureGeneratedSkillArtifacts: writeSkillMd failed: ${errorMessage(err)}`);
280
- }
277
+ const hadSkillMd = fs.existsSync(skillMdPath);
278
+ try {
279
+ writeSkillMd(phrenPath);
280
+ if (!hadSkillMd && fs.existsSync(skillMdPath))
281
+ created.push("phren.SKILL.md");
282
+ }
283
+ catch (err) {
284
+ debugLog(`ensureGeneratedSkillArtifacts: writeSkillMd failed: ${errorMessage(err)}`);
281
285
  }
282
286
  return created;
283
287
  }
@@ -323,8 +327,11 @@ export function repairPreexistingInstall(phrenPath, opts) {
323
327
  // self-heal path resolves from stored preferences.
324
328
  const caps = opts?.caps ?? resolveManagementCapabilities(phrenPath);
325
329
  const preset = opts?.preset ?? getManagementPreset(phrenPath);
330
+ moduleSnapshot(phrenPath);
331
+ reconcileStarterSkills(phrenPath, STARTER_DIR);
326
332
  const createdGovernanceAssets = ensureGovernanceFiles(phrenPath);
327
- const createdGlobalAssets = ensureGlobalStarterAssets(phrenPath);
333
+ const migratedInstructions = migrateStoreAgentInstructions(phrenPath);
334
+ const createdGlobalAssets = [...migratedInstructions, ...ensureGlobalStarterAssets(phrenPath)];
328
335
  const createdRuntimeAssets = [...createdGovernanceAssets, ...ensureRuntimeAssets(phrenPath)];
329
336
  const createdFeatureDefaults = ensureDefaultFeatureFlags(phrenPath, preset);
330
337
  const profileRepair = pruneLegacySampleProjectsFromProfiles(phrenPath);
@@ -352,7 +359,7 @@ export function repairPreexistingInstall(phrenPath, opts) {
352
359
  * is missing or broken.
353
360
  *
354
361
  * The ownership test used to be `target.includes(".phren") ||
355
- * target.endsWith("global/CLAUDE.md")`, which treats *any* live phren root's
362
+ * target.endsWith("global/AGENTS.md")`, which treats *any* live phren root's
356
363
  * global file as fair game to unlink. That is how a run with
357
364
  * `PHREN_PATH=/tmp/…` — a smoke test, or phren's own web UI — leaves the
358
365
  * user's real `~/.claude/CLAUDE.md` pointing into a temp directory that then
@@ -369,7 +376,7 @@ export function repairPreexistingInstall(phrenPath, opts) {
369
376
  * repaired, which is the case this function exists for.
370
377
  */
371
378
  function repairGlobalClaudeSymlink(phrenPath) {
372
- const src = path.join(phrenPath, "global", "CLAUDE.md");
379
+ const src = path.join(phrenPath, "global", "AGENTS.md");
373
380
  if (!fs.existsSync(src))
374
381
  return false;
375
382
  const dest = homePath(".claude", "CLAUDE.md");
@@ -385,7 +392,7 @@ function repairGlobalClaudeSymlink(phrenPath) {
385
392
  return false;
386
393
  }
387
394
  // Stale phren wiring — safe to replace. `.includes(".phren")` stays for
388
- // links that are not shaped like <root>/global/CLAUDE.md.
395
+ // links that are not shaped like <root>/global/AGENTS.md.
389
396
  if (owningRoot || target.includes(".phren"))
390
397
  fs.unlinkSync(dest);
391
398
  else
@@ -402,11 +409,11 @@ function repairGlobalClaudeSymlink(phrenPath) {
402
409
  try {
403
410
  fs.mkdirSync(path.dirname(dest), { recursive: true });
404
411
  fs.symlinkSync(src, dest);
405
- debugLog(`repaired global CLAUDE.md symlink: ${dest} -> ${src}`);
412
+ debugLog(`repaired global AGENTS.md symlink: ${dest} -> ${src}`);
406
413
  return true;
407
414
  }
408
415
  catch (err) {
409
- debugLog(`failed to repair global CLAUDE.md symlink: ${errorMessage(err)}`);
416
+ debugLog(`failed to repair global AGENTS.md symlink: ${errorMessage(err)}`);
410
417
  return false;
411
418
  }
412
419
  }
@@ -456,6 +463,7 @@ export function getHookEntrypointCheck(deps = {}) {
456
463
  function gitRemoteStatus(phrenPath) {
457
464
  try {
458
465
  execFileSync("git", ["-C", phrenPath, "rev-parse", "--is-inside-work-tree"], {
466
+ env: nonInteractiveGitEnv(),
459
467
  stdio: ["ignore", "ignore", "ignore"],
460
468
  timeout: EXEC_TIMEOUT_QUICK_MS,
461
469
  });
@@ -466,6 +474,7 @@ function gitRemoteStatus(phrenPath) {
466
474
  let remote;
467
475
  try {
468
476
  remote = execFileSync("git", ["-C", phrenPath, "remote", "get-url", "origin"], {
477
+ env: nonInteractiveGitEnv(),
469
478
  encoding: "utf8",
470
479
  stdio: ["ignore", "pipe", "ignore"],
471
480
  timeout: EXEC_TIMEOUT_QUICK_MS,
@@ -479,6 +488,7 @@ function gitRemoteStatus(phrenPath) {
479
488
  // Connectivity test: verify the remote is reachable (10s timeout)
480
489
  try {
481
490
  execFileSync("git", ["-C", phrenPath, "ls-remote", "--exit-code", "origin"], {
491
+ env: nonInteractiveGitEnv(),
482
492
  stdio: ["ignore", "ignore", "ignore"],
483
493
  timeout: 10_000,
484
494
  });
@@ -513,8 +523,8 @@ export function applyStarterTemplateUpdates(phrenPath) {
513
523
  const starterGlobal = path.join(STARTER_DIR, "global");
514
524
  if (!fs.existsSync(starterGlobal))
515
525
  return updates;
516
- const starterClaude = path.join(starterGlobal, "CLAUDE.md");
517
- const targetClaude = path.join(phrenPath, "global", "CLAUDE.md");
526
+ const starterClaude = path.join(starterGlobal, "AGENTS.md");
527
+ const targetClaude = path.join(phrenPath, "global", "AGENTS.md");
518
528
  if (fs.existsSync(starterClaude)) {
519
529
  const written = copyStarterFile(phrenPath, starterClaude, targetClaude);
520
530
  if (written)
@@ -525,6 +535,8 @@ export function applyStarterTemplateUpdates(phrenPath) {
525
535
  if (fs.existsSync(starterSkillsDir)) {
526
536
  fs.mkdirSync(targetSkillsDir, { recursive: true });
527
537
  for (const f of fs.readdirSync(starterSkillsDir, { withFileTypes: true })) {
538
+ if (!skillEnabled(phrenPath, f.name))
539
+ continue;
528
540
  const src = path.join(starterSkillsDir, f.name);
529
541
  const dest = path.join(targetSkillsDir, f.name);
530
542
  if (f.isFile() && f.name.endsWith(".md")) {
@@ -632,6 +644,8 @@ export function applyTemplate(projectDir, templateName, projectName) {
632
644
  function copyTemplateDir(srcDir, destDir) {
633
645
  fs.mkdirSync(destDir, { recursive: true });
634
646
  for (const entry of fs.readdirSync(srcDir, { withFileTypes: true })) {
647
+ if (entry.name === TASKS_FILENAME && !moduleEnabled(path.dirname(projectDir), "tasks"))
648
+ continue;
635
649
  const src = path.join(srcDir, entry.name);
636
650
  const dest = path.join(destDir, entry.name);
637
651
  if (entry.isDirectory()) {
@@ -639,6 +653,8 @@ export function applyTemplate(projectDir, templateName, projectName) {
639
653
  }
640
654
  else {
641
655
  let content = fs.readFileSync(src, "utf8");
656
+ if (entry.name === "AGENTS.md")
657
+ content = starterInstructions(path.dirname(projectDir), content);
642
658
  content = content.replace(/\{\{project\}\}/g, projectName);
643
659
  content = content.replace(/\{\{date\}\}/g, new Date().toISOString().slice(0, 10));
644
660
  atomicWriteText(dest, content);
@@ -648,387 +664,11 @@ export function applyTemplate(projectDir, templateName, projectName) {
648
664
  copyTemplateDir(templateDir, projectDir);
649
665
  return true;
650
666
  }
651
- const DOMAIN_KEYWORD_HINTS = {
652
- software: [
653
- "api", "backend", "frontend", "typescript", "javascript", "python", "rust", "golang", "cli", "sdk", "library", "service",
654
- "server", "database", "auth", "module", "package", "build", "test", "deploy",
655
- ],
656
- music: [
657
- "music", "audio", "mix", "master", "track", "daw", "synth", "midi", "song", "composition", "arrangement", "producer",
658
- ],
659
- game: [
660
- "game", "gameplay", "level", "shader", "physics", "npc", "engine", "unity", "godot", "unreal", "sprite", "multiplayer",
661
- ],
662
- research: [
663
- "research", "paper", "study", "experiment", "dataset", "analysis", "methodology", "hypothesis", "results", "evaluation",
664
- ],
665
- writing: [
666
- "writing", "manuscript", "chapter", "outline", "narrative", "character", "plot", "draft", "editorial",
667
- ],
668
- creative: [
669
- "creative", "story", "design", "worldbuilding", "script", "concept", "illustration", "art direction",
670
- ],
671
- };
672
- const DOMAIN_CONFIG_HINTS = {
673
- "package.json": { software: 3 },
674
- "tsconfig.json": { software: 3 },
675
- "Cargo.toml": { software: 4, game: 1 },
676
- "pyproject.toml": { software: 3, research: 1 },
677
- "requirements.txt": { software: 2, research: 1 },
678
- "go.mod": { software: 3 },
679
- "CMakeLists.txt": { software: 3, game: 1 },
680
- "pom.xml": { software: 3 },
681
- "build.gradle": { software: 3 },
682
- "project.godot": { game: 5 },
683
- ".uproject": { game: 5 },
684
- "paper.tex": { research: 4, writing: 1 },
685
- "references.bib": { research: 4 },
686
- };
687
- const EXTENSION_DOMAIN_HINTS = {
688
- ".ts": { software: 1 },
689
- ".tsx": { software: 1, game: 1 },
690
- ".js": { software: 1 },
691
- ".jsx": { software: 1 },
692
- ".py": { software: 1, research: 1 },
693
- ".rs": { software: 1, game: 1 },
694
- ".go": { software: 1 },
695
- ".java": { software: 1 },
696
- ".kt": { software: 1 },
697
- ".swift": { software: 1 },
698
- ".c": { software: 1, game: 1 },
699
- ".cc": { software: 1, game: 1 },
700
- ".cpp": { software: 1, game: 1 },
701
- ".h": { software: 1, game: 1 },
702
- ".hpp": { software: 1, game: 1 },
703
- ".cs": { software: 1, game: 1 },
704
- ".ipynb": { research: 2 },
705
- ".tex": { research: 2, writing: 1 },
706
- ".bib": { research: 2 },
707
- ".wav": { music: 2 },
708
- ".mp3": { music: 2 },
709
- ".flac": { music: 2 },
710
- ".mid": { music: 2 },
711
- ".midi": { music: 2 },
712
- ".als": { music: 2 },
713
- ".logicx": { music: 2 },
714
- ".unity": { game: 2 },
715
- ".gd": { game: 2 },
716
- ".glsl": { game: 2 },
717
- };
718
- function titleCase(text) {
719
- return text
720
- .split(/[\s_-]+/)
721
- .filter(Boolean)
722
- .map((token) => token.slice(0, 1).toUpperCase() + token.slice(1))
723
- .join(" ");
724
- }
725
- function addTermCount(terms, rawText, weight = 1) {
726
- const tokens = rawText
727
- .toLowerCase()
728
- .replace(/[^\w\s-]/g, " ")
729
- .split(/\s+/)
730
- .map((token) => token.trim())
731
- .filter((token) => token.length >= 3 && token.length <= 48 && !STOP_WORDS.has(token));
732
- for (const token of tokens) {
733
- terms.set(token, (terms.get(token) ?? 0) + weight);
734
- }
735
- }
736
- function maybeReadUtf8(filePath, maxBytes = 256_000) {
737
- try {
738
- const stat = fs.statSync(filePath);
739
- if (!stat.isFile() || stat.size > maxBytes)
740
- return "";
741
- return fs.readFileSync(filePath, "utf8");
742
- }
743
- catch {
744
- return "";
745
- }
746
- }
747
- function addDomainScores(target, patch, weight = 1) {
748
- for (const [domain, score] of Object.entries(patch)) {
749
- const typedDomain = domain;
750
- target[typedDomain] += (score ?? 0) * weight;
751
- }
752
- }
753
- function scoreTopicsFromTerms(domain, terms, docsText) {
754
- const baseTopics = getBuiltinTopicConfig(domain);
755
- const scored = baseTopics
756
- .filter((topic) => topic.name.toLowerCase() !== "general")
757
- .map((topic) => {
758
- const baseTerm = topic.name.toLowerCase();
759
- let score = terms.get(baseTerm) ?? 0;
760
- for (const keyword of topic.keywords) {
761
- const normalized = keyword.toLowerCase().trim();
762
- if (!normalized)
763
- continue;
764
- score += terms.get(normalized) ?? 0;
765
- if (normalized.includes(" ") && docsText.includes(normalized))
766
- score += 1;
767
- }
768
- return { topic, score };
769
- });
770
- const ranked = scored
771
- .filter((entry) => entry.score > 0)
772
- .sort((a, b) => b.score - a.score || a.topic.name.localeCompare(b.topic.name));
773
- const takenNames = new Set(baseTopics.map((topic) => topic.name.toLowerCase()));
774
- const customTopics = [];
775
- for (const [term, count] of [...terms.entries()].sort((a, b) => b[1] - a[1])) {
776
- if (customTopics.length >= 4)
777
- break;
778
- if (count < 3)
779
- break;
780
- if (term.includes("_"))
781
- continue;
782
- const topicName = titleCase(term);
783
- const normalizedName = topicName.toLowerCase();
784
- if (takenNames.has(normalizedName))
785
- continue;
786
- if (DOMAIN_KEYWORD_HINTS.software.includes(term) || DOMAIN_KEYWORD_HINTS.music.includes(term) || DOMAIN_KEYWORD_HINTS.game.includes(term)) {
787
- continue;
788
- }
789
- takenNames.add(normalizedName);
790
- customTopics.push({
791
- name: topicName,
792
- description: "Suggested from repeated terminology in project docs.",
793
- keywords: [term],
794
- });
795
- }
796
- if (ranked.length === 0 && customTopics.length === 0)
797
- return baseTopics;
798
- const orderedBase = [
799
- ...ranked.map((entry) => entry.topic),
800
- ...baseTopics.filter((topic) => topic.name.toLowerCase() !== "general"
801
- && !ranked.some((entry) => entry.topic.name === topic.name)),
802
- ];
803
- const topics = [...orderedBase.slice(0, 8), ...customTopics];
804
- if (!topics.some((topic) => topic.name.toLowerCase() === "general")) {
805
- topics.push({ name: "General", description: "Fallback bucket for uncategorized findings.", keywords: [] });
806
- }
807
- return topics;
808
- }
809
- export function inferInitScaffoldFromRepo(repoRoot, fallbackDomain = "software") {
810
- const resolvedRoot = path.resolve(repoRoot);
811
- if (!fs.existsSync(resolvedRoot))
812
- return null;
813
- const signal = {
814
- domainScores: { software: 0, music: 0, game: 0, research: 0, writing: 0, creative: 0, other: 0 },
815
- terms: new Map(),
816
- docsText: "",
817
- referenceHints: [],
818
- commandHints: [],
819
- usefulSignals: 0,
820
- };
821
- const skipDirs = new Set([".git", ".phren", "node_modules", "dist", "build", "coverage", ".next", ".turbo", "target"]);
822
- const packageJsonPath = path.join(resolvedRoot, "package.json");
823
- if (fs.existsSync(packageJsonPath)) {
824
- signal.usefulSignals++;
825
- addDomainScores(signal.domainScores, DOMAIN_CONFIG_HINTS["package.json"]);
826
- try {
827
- const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
828
- if (typeof parsed.description === "string") {
829
- addTermCount(signal.terms, parsed.description, 3);
830
- signal.docsText += ` ${parsed.description.toLowerCase()}`;
831
- }
832
- if (Array.isArray(parsed.keywords)) {
833
- for (const keyword of parsed.keywords) {
834
- if (typeof keyword === "string") {
835
- addTermCount(signal.terms, keyword, 3);
836
- signal.docsText += ` ${keyword.toLowerCase()}`;
837
- }
838
- }
839
- }
840
- if (parsed.scripts && typeof parsed.scripts === "object" && !Array.isArray(parsed.scripts)) {
841
- const scriptObject = parsed.scripts;
842
- for (const scriptName of ["dev", "start", "build", "test", "lint"]) {
843
- if (typeof scriptObject[scriptName] === "string") {
844
- signal.commandHints.push(`npm run ${scriptName}`);
845
- }
846
- }
847
- }
848
- }
849
- catch (err) {
850
- debugLog(`inferInitScaffoldFromRepo package.json parse failed: ${errorMessage(err)}`);
851
- }
852
- }
853
- const topLevelConfigs = Object.keys(DOMAIN_CONFIG_HINTS)
854
- .filter((fileName) => fs.existsSync(path.join(resolvedRoot, fileName)));
855
- for (const configName of topLevelConfigs) {
856
- signal.usefulSignals++;
857
- const configScore = DOMAIN_CONFIG_HINTS[configName];
858
- if (configScore)
859
- addDomainScores(signal.domainScores, configScore);
860
- }
861
- const readmeCandidates = [
862
- path.join(resolvedRoot, "README.md"),
863
- path.join(resolvedRoot, "readme.md"),
864
- ];
865
- for (const readmePath of readmeCandidates) {
866
- if (!fs.existsSync(readmePath))
867
- continue;
868
- const content = maybeReadUtf8(readmePath);
869
- if (!content)
870
- continue;
871
- signal.usefulSignals++;
872
- signal.referenceHints.push(path.relative(resolvedRoot, readmePath));
873
- addTermCount(signal.terms, content, 2);
874
- signal.docsText += ` ${content.toLowerCase()}`;
875
- break;
876
- }
877
- const docsDir = path.join(resolvedRoot, "docs");
878
- if (fs.existsSync(docsDir) && fs.statSync(docsDir).isDirectory()) {
879
- signal.referenceHints.push("docs/");
880
- for (const entry of fs.readdirSync(docsDir, { withFileTypes: true })) {
881
- if (!entry.isFile())
882
- continue;
883
- if (!/\.(md|txt|rst)$/i.test(entry.name))
884
- continue;
885
- const docsContent = maybeReadUtf8(path.join(docsDir, entry.name));
886
- if (!docsContent)
887
- continue;
888
- signal.usefulSignals++;
889
- addTermCount(signal.terms, docsContent, 1);
890
- signal.docsText += ` ${docsContent.toLowerCase()}`;
891
- }
892
- }
893
- for (const folderName of ["reference", "specs", "design", "architecture", "src", "packages", "apps"]) {
894
- const fullPath = path.join(resolvedRoot, folderName);
895
- if (fs.existsSync(fullPath)) {
896
- signal.referenceHints.push(`${folderName}/`);
897
- }
898
- }
899
- let scannedFiles = 0;
900
- const maxFiles = 3000;
901
- const walk = (dir) => {
902
- if (scannedFiles >= maxFiles)
903
- return;
904
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
905
- if (scannedFiles >= maxFiles)
906
- return;
907
- const fullPath = path.join(dir, entry.name);
908
- if (entry.isDirectory()) {
909
- if (skipDirs.has(entry.name))
910
- continue;
911
- walk(fullPath);
912
- continue;
913
- }
914
- scannedFiles++;
915
- const ext = path.extname(entry.name).toLowerCase();
916
- if (!ext)
917
- continue;
918
- const extScore = EXTENSION_DOMAIN_HINTS[ext];
919
- if (extScore) {
920
- addDomainScores(signal.domainScores, extScore);
921
- signal.usefulSignals++;
922
- }
923
- }
924
- };
925
- walk(resolvedRoot);
926
- for (const [domain, hints] of Object.entries(DOMAIN_KEYWORD_HINTS)) {
927
- for (const hint of hints) {
928
- const hitCount = signal.terms.get(hint) ?? 0;
929
- if (hitCount > 0) {
930
- signal.domainScores[domain] += Math.min(4, hitCount);
931
- signal.usefulSignals++;
932
- }
933
- }
934
- }
935
- const rankedDomains = Object.entries(signal.domainScores)
936
- .sort((a, b) => b[1] - a[1]);
937
- const [bestDomain, bestScore] = rankedDomains[0] ?? [fallbackDomain, 0];
938
- const secondScore = rankedDomains[1]?.[1] ?? 0;
939
- const inferredDomain = bestScore >= 2 ? bestDomain : fallbackDomain;
940
- const confidence = bestScore <= 0
941
- ? 0
942
- : Math.max(0.15, Math.min(0.98, (bestScore - secondScore + 1) / (bestScore + 2)));
943
- const topics = scoreTopicsFromTerms(inferredDomain, signal.terms, signal.docsText);
944
- const references = Array.from(new Set(signal.referenceHints)).slice(0, 8);
945
- const commands = Array.from(new Set(signal.commandHints)).slice(0, 5);
946
- const reason = bestScore > 0
947
- ? `inferred from repo files, config, and docs terminology (score ${bestScore})`
948
- : "fallback defaults";
949
- if (signal.usefulSignals === 0)
950
- return null;
951
- return {
952
- domain: inferredDomain,
953
- topics: topics.length > 0 ? topics : getBuiltinTopicConfig(inferredDomain),
954
- referenceHints: references,
955
- commandHints: commands,
956
- confidence: Number(confidence.toFixed(2)),
957
- reason,
958
- };
959
- }
960
- function appendInferredSections(base, inference) {
961
- if (!inference)
962
- return base;
963
- const lines = [];
964
- if (inference.referenceHints.length > 0) {
965
- lines.push("## Reference Structure");
966
- for (const hint of inference.referenceHints) {
967
- lines.push(`- ${hint}`);
968
- }
969
- lines.push("");
970
- }
971
- if (inference.topics.length > 0) {
972
- lines.push("## Initial Focus Topics");
973
- for (const topic of inference.topics.slice(0, 6)) {
974
- lines.push(`- ${topic.name}: ${topic.description}`);
975
- }
976
- lines.push("");
977
- }
978
- if (inference.commandHints.length > 0) {
979
- lines.push("## Commands");
980
- lines.push("```bash");
981
- for (const cmd of inference.commandHints)
982
- lines.push(cmd);
983
- lines.push("```");
984
- lines.push("");
985
- }
986
- return lines.length > 0 ? `${base.trimEnd()}\n\n${lines.join("\n")}` : base;
987
- }
988
- function getDomainClaudeTemplate(projectName, domain, inference) {
989
- if (domain === "software") {
990
- return appendInferredSections(`# ${projectName}\n\nOne paragraph about what this project is.\n\n## Commands\n\n\`\`\`bash\n# Install:\n# Run:\n# Test:\n\`\`\`\n`, inference);
991
- }
992
- if (domain === "music") {
993
- return appendInferredSections(`# ${projectName}\n\nThis is a music project. Keep notes on composition intent, arrangement choices, production workflow, and mixing/mastering decisions.\n\n## Session Focus\n\n- Capture creative intent before technical tweaks\n- Track instrument/sound-design decisions and why\n- Log mix/master changes with listening context\n`, inference);
994
- }
995
- if (domain === "game") {
996
- return appendInferredSections(`# ${projectName}\n\nThis is a game project. Prioritize clear notes on mechanics, rendering/performance tradeoffs, level and UI decisions, and iteration outcomes.\n\n## Development Focus\n\n- Record gameplay/mechanics decisions with player impact\n- Track rendering/physics/AI issues with repro context\n- Note level-design and networking constraints early\n`, inference);
997
- }
998
- if (domain === "research") {
999
- return appendInferredSections(`# ${projectName}\n\nThis is a research project. Focus on methodology, source quality, analysis assumptions, and review feedback loops.\n\n## Working Approach\n\n- Document hypotheses and evaluation criteria explicitly\n- Track source provenance and confidence level\n- Record analysis decisions and revision rationale\n`, inference);
1000
- }
1001
- if (domain === "writing" || domain === "creative") {
1002
- return appendInferredSections(`# ${projectName}\n\nThis is a creative writing project. Track worldbuilding rules, character arcs, plot structure, style constraints, and revision decisions.\n\n## Writing Workflow\n\n- Keep narrative intent and tone constraints visible\n- Capture character/plot changes with consequences\n- Log revision notes and unresolved questions\n`, inference);
1003
- }
1004
- return appendInferredSections(`# ${projectName}\n\nThis project is not software-first. Keep practical notes, references, and task decisions so future sessions can resume quickly.\n\n## Workflow\n\n- Capture non-obvious lessons and reusable patterns\n- Keep references curated and current\n- Track active tasks and follow-ups\n`, inference);
1005
- }
1006
- export function ensureProjectScaffold(projectDir, projectName, domain = "software", inference) {
1007
- const normalizedDomain = normalizeBuiltinTopicDomain(inference?.domain ?? domain);
1008
- const inferredTopics = Array.isArray(inference?.topics) && inference.topics.length > 0
1009
- ? inference.topics
1010
- : getBuiltinTopicConfig(normalizedDomain);
1011
- fs.mkdirSync(projectDir, { recursive: true });
1012
- if (!fs.existsSync(path.join(projectDir, "summary.md"))) {
1013
- atomicWriteText(path.join(projectDir, "summary.md"), `# ${projectName}\n\n**What:** Replace this with one sentence about what the project does\n**Stack:** The key tech\n**Status:** active\n**Run:** the command you use most\n**Watch out:** the one thing that will bite you if you forget\n`);
1014
- }
1015
- if (!fs.existsSync(path.join(projectDir, "CLAUDE.md"))) {
1016
- atomicWriteText(path.join(projectDir, "CLAUDE.md"), getDomainClaudeTemplate(projectName, inference?.domain ?? domain, inference));
1017
- }
1018
- if (!fs.existsSync(path.join(projectDir, "topic-config.json"))) {
1019
- atomicWriteText(path.join(projectDir, "topic-config.json"), JSON.stringify({ version: 1, domain: normalizedDomain, topics: inferredTopics }, null, 2) + "\n");
1020
- }
1021
- if (!fs.existsSync(path.join(projectDir, FINDINGS_FILENAME))) {
1022
- atomicWriteText(path.join(projectDir, FINDINGS_FILENAME), `# ${projectName} FINDINGS\n\n<!-- Findings are captured automatically during sessions and committed on exit -->\n`);
1023
- }
1024
- if (!fs.existsSync(path.join(projectDir, TASKS_FILENAME))) {
1025
- atomicWriteText(path.join(projectDir, TASKS_FILENAME), `# ${projectName} tasks\n\n## Active\n\n## Queue\n\n## Done\n`);
1026
- }
1027
- }
1028
667
  export function ensureLocalGitRepo(phrenPath) {
1029
668
  // Check if phrenPath already has its own git repo (not just being inside a parent)
1030
669
  try {
1031
670
  const topLevel = execFileSync("git", ["-C", phrenPath, "rev-parse", "--show-toplevel"], {
671
+ env: nonInteractiveGitEnv(),
1032
672
  encoding: "utf8",
1033
673
  stdio: ["ignore", "pipe", "ignore"],
1034
674
  timeout: EXEC_TIMEOUT_QUICK_MS,
@@ -1056,17 +696,20 @@ export function ensureLocalGitRepo(phrenPath) {
1056
696
  try {
1057
697
  try {
1058
698
  execFileSync("git", ["-C", phrenPath, "init", "--initial-branch=main"], {
699
+ env: nonInteractiveGitEnv(),
1059
700
  stdio: ["ignore", "ignore", "ignore"],
1060
701
  timeout: EXEC_TIMEOUT_QUICK_MS,
1061
702
  });
1062
703
  }
1063
704
  catch {
1064
705
  execFileSync("git", ["-C", phrenPath, "init"], {
706
+ env: nonInteractiveGitEnv(),
1065
707
  stdio: ["ignore", "ignore", "ignore"],
1066
708
  timeout: EXEC_TIMEOUT_QUICK_MS,
1067
709
  });
1068
710
  try {
1069
711
  execFileSync("git", ["-C", phrenPath, "branch", "-M", "main"], {
712
+ env: nonInteractiveGitEnv(),
1070
713
  stdio: ["ignore", "ignore", "ignore"],
1071
714
  timeout: EXEC_TIMEOUT_QUICK_MS,
1072
715
  });
@@ -1081,188 +724,6 @@ export function ensureLocalGitRepo(phrenPath) {
1081
724
  return { ok: false, initialized: false, detail: `git init failed: ${errorMessage(err)}` };
1082
725
  }
1083
726
  }
1084
- /** Bootstrap a phren project from an existing project directory with CLAUDE.md.
1085
- * @param profile - if provided, only this profile YAML is updated (avoids leaking project to unrelated profiles).
1086
- */
1087
- /**
1088
- * Find an already-registered project that `sourceRoot` should reuse rather than
1089
- * getting a near-duplicate directory of its own. Two signals, strongest first:
1090
- *
1091
- * 1. **Same source path.** Another project already points at this exact
1092
- * directory — unambiguous, reuse it whatever it is called.
1093
- * 2. **Same canonical slug.** `max4liveplugins` vs `max4live-plugins`: the same
1094
- * repo spelled two ways. Only reused when the existing project has no source
1095
- * path recorded, or records this one — if it points somewhere else it is a
1096
- * genuinely different project that merely slugs alike, and both are kept.
1097
- *
1098
- * Returns `null` when nothing matches, i.e. create the project normally.
1099
- */
1100
- function findExistingProjectForSource(phrenPath, sourceRoot, derivedName) {
1101
- let candidates;
1102
- try {
1103
- candidates = fs.readdirSync(phrenPath, { withFileTypes: true })
1104
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
1105
- .map((entry) => entry.name);
1106
- }
1107
- catch (err) {
1108
- debugLog(`findExistingProjectForSource readdir: ${errorMessage(err)}`);
1109
- return null;
1110
- }
1111
- const sourceOf = (project) => {
1112
- try {
1113
- return readProjectConfig(phrenPath, project).sourcePath
1114
- ? path.resolve(String(readProjectConfig(phrenPath, project).sourcePath))
1115
- : null;
1116
- }
1117
- catch (err) {
1118
- debugLog(`findExistingProjectForSource config ${project}: ${errorMessage(err)}`);
1119
- return null;
1120
- }
1121
- };
1122
- const resolvedSource = path.resolve(sourceRoot);
1123
- for (const project of candidates) {
1124
- if (sourceOf(project) === resolvedSource)
1125
- return project;
1126
- }
1127
- for (const project of findProjectNamesByCanonicalKey(phrenPath, derivedName)) {
1128
- if (project === derivedName)
1129
- return project; // exact match; nothing to reconcile
1130
- const existingSource = sourceOf(project);
1131
- if (existingSource === null || existingSource === resolvedSource)
1132
- return project;
1133
- }
1134
- return null;
1135
- }
1136
- export function bootstrapFromExisting(phrenPath, projectPath, opts = {}) {
1137
- const profile = typeof opts === "string" ? opts : opts.profile;
1138
- const profilePhrenPath = typeof opts === "string" ? phrenPath : (opts.profilePhrenPath ?? phrenPath);
1139
- const resolvedPath = path.resolve(projectPath);
1140
- if (!fs.existsSync(resolvedPath)) {
1141
- throw new Error(`Path does not exist: ${resolvedPath}`);
1142
- }
1143
- const manifest = readRootManifest(phrenPath);
1144
- const isProjectLocal = manifest?.installMode === "project-local";
1145
- // A git worktree — notably the agent-managed ones under `.claude/worktrees/`
1146
- // — is a checkout of a repository we may already track. Attribute it to that
1147
- // repository instead of registering the worktree's throwaway codename as a
1148
- // brand-new top-level project.
1149
- const worktree = isProjectLocal ? null : resolveWorktreeParent(resolvedPath);
1150
- const worktreeRepoRoot = worktree && fs.existsSync(worktree.repoRoot) ? worktree.repoRoot : null;
1151
- if (worktreeRepoRoot) {
1152
- debugLog(`bootstrapFromExisting: ${resolvedPath} is a ${worktree.reason}; attributing to ${worktreeRepoRoot}`);
1153
- }
1154
- const sourceRoot = isProjectLocal
1155
- ? path.resolve(manifest.workspaceRoot || resolvedPath)
1156
- : (worktreeRepoRoot ?? resolvedPath);
1157
- if (isProjectLocal) {
1158
- const matchesWorkspace = resolvedPath === sourceRoot || resolvedPath.startsWith(sourceRoot + path.sep);
1159
- if (!matchesWorkspace) {
1160
- throw new Error(`Project-local phren can only enroll the owning workspace: ${sourceRoot}`);
1161
- }
1162
- }
1163
- let claudeMdPath = null;
1164
- const candidates = [
1165
- path.join(sourceRoot, "CLAUDE.md"),
1166
- path.join(sourceRoot, ".claude", "CLAUDE.md"),
1167
- ];
1168
- for (const c of candidates) {
1169
- if (fs.existsSync(c)) {
1170
- claudeMdPath = c;
1171
- break;
1172
- }
1173
- }
1174
- const claudeContent = claudeMdPath ? fs.readFileSync(claudeMdPath, "utf8") : null;
1175
- const derivedName = isProjectLocal
1176
- ? String(manifest?.primaryProject)
1177
- : projectSlugFromPath(sourceRoot);
1178
- const projectName = isProjectLocal
1179
- ? derivedName
1180
- : (findExistingProjectForSource(phrenPath, sourceRoot, derivedName) ?? derivedName);
1181
- if (projectName !== derivedName) {
1182
- debugLog(`bootstrapFromExisting: reusing existing project "${projectName}" for ${sourceRoot} (derived "${derivedName}")`);
1183
- }
1184
- const existingProject = findProjectNameCaseInsensitive(phrenPath, projectName);
1185
- if (existingProject && existingProject !== projectName) {
1186
- throw new Error(`Project "${existingProject}" already exists with different casing. Refusing to bootstrap "${projectName}" because it would split the same project on case-sensitive filesystems.`);
1187
- }
1188
- const projDir = path.join(phrenPath, projectName);
1189
- fs.mkdirSync(projDir, { recursive: true });
1190
- const inferredScaffold = inferInitScaffoldFromRepo(sourceRoot);
1191
- const existingConfig = readProjectConfig(phrenPath, projectName);
1192
- const ownership = typeof opts === "string"
1193
- ? (parseProjectOwnershipMode(existingConfig.ownership) ?? getProjectOwnershipDefault(phrenPath))
1194
- : (opts.ownership ?? parseProjectOwnershipMode(existingConfig.ownership) ?? getProjectOwnershipDefault(phrenPath));
1195
- const claudePath = path.join(projDir, "CLAUDE.md");
1196
- if (ownership !== "repo-managed") {
1197
- if (claudeContent) {
1198
- if (!fs.existsSync(claudePath)) {
1199
- atomicWriteText(claudePath, claudeContent);
1200
- }
1201
- }
1202
- else {
1203
- // No CLAUDE.md found — create a starter one
1204
- if (!fs.existsSync(claudePath)) {
1205
- atomicWriteText(claudePath, getDomainClaudeTemplate(projectName, inferredScaffold?.domain ?? "software", inferredScaffold));
1206
- }
1207
- }
1208
- }
1209
- const summaryLines = [];
1210
- if (claudeContent) {
1211
- const lines = claudeContent.split("\n");
1212
- let foundHeading = false;
1213
- for (const line of lines) {
1214
- if (line.startsWith("# ") && !foundHeading) {
1215
- foundHeading = true;
1216
- summaryLines.push(line);
1217
- continue;
1218
- }
1219
- if (foundHeading && line.trim() === "") {
1220
- if (summaryLines.length > 1)
1221
- break;
1222
- continue;
1223
- }
1224
- if (foundHeading && summaryLines.length < 10) {
1225
- summaryLines.push(line);
1226
- }
1227
- }
1228
- }
1229
- const sourceInfo = claudeMdPath ? `**Source CLAUDE.md:** ${claudeMdPath}` : `**Source:** ${sourceRoot}`;
1230
- const summaryPath = path.join(projDir, "summary.md");
1231
- if (!fs.existsSync(summaryPath)) {
1232
- atomicWriteText(summaryPath, `# ${projectName}\n\n**What:** Bootstrapped from ${sourceRoot}\n${sourceInfo}\n\n${summaryLines.length > 1 ? summaryLines.slice(1).join("\n") : ""}\n`);
1233
- }
1234
- if (!fs.existsSync(path.join(projDir, FINDINGS_FILENAME))) {
1235
- atomicWriteText(path.join(projDir, FINDINGS_FILENAME), `# ${projectName} FINDINGS\n\n<!-- Bootstrapped from ${sourceRoot} -->\n`);
1236
- }
1237
- if (!fs.existsSync(path.join(projDir, TASKS_FILENAME))) {
1238
- atomicWriteText(path.join(projDir, TASKS_FILENAME), `# ${projectName} tasks\n\n## Active\n\n## Queue\n\n## Done\n`);
1239
- }
1240
- if (!fs.existsSync(path.join(projDir, "topic-config.json"))) {
1241
- const inferredDomain = normalizeBuiltinTopicDomain(inferredScaffold?.domain ?? "software");
1242
- const inferredTopics = inferredScaffold?.topics?.length
1243
- ? inferredScaffold.topics
1244
- : getBuiltinTopicConfig(inferredDomain);
1245
- atomicWriteText(path.join(projDir, "topic-config.json"), JSON.stringify({ version: 1, domain: inferredDomain, topics: inferredTopics }, null, 2) + "\n");
1246
- }
1247
- const activeProfile = resolveActiveProfile(profilePhrenPath, profile);
1248
- if (activeProfile.ok && activeProfile.data) {
1249
- const addResult = addProjectToProfile(profilePhrenPath, activeProfile.data, projectName);
1250
- if (!addResult.ok) {
1251
- throw new Error(addResult.error);
1252
- }
1253
- }
1254
- else if (!activeProfile.ok && activeProfile.code !== "FILE_NOT_FOUND") {
1255
- throw new Error(activeProfile.error);
1256
- }
1257
- writeProjectConfig(phrenPath, projectName, { ownership, sourcePath: sourceRoot });
1258
- return {
1259
- project: projectName,
1260
- ownership,
1261
- claudePath: ownership === "repo-managed"
1262
- ? (claudeMdPath ?? null)
1263
- : (fs.existsSync(claudePath) ? claudePath : null),
1264
- };
1265
- }
1266
727
  export function updateMachinesYaml(phrenPath, machine, profile) {
1267
728
  const machinesFile = path.join(phrenPath, "machines.yaml");
1268
729
  if (!fs.existsSync(machinesFile))
@@ -1294,7 +755,7 @@ export function updateMachinesYaml(phrenPath, machine, profile) {
1294
755
  * Returns the path if it qualifies, null otherwise.
1295
756
  * A directory qualifies if it:
1296
757
  * - Is not the home directory or phren directory
1297
- * - Has a CLAUDE.md, AGENTS.md, .claude/CLAUDE.md, or .git directory
758
+ * - Has an AGENTS.md, legacy CLAUDE.md, .claude/CLAUDE.md, or .git directory
1298
759
  *
1299
760
  * A git worktree resolves to the repository it belongs to. Without this a
1300
761
  * throwaway agent worktree under `.claude/worktrees/<codename>` looks like its
@@ -1468,12 +929,12 @@ export function runPostInitVerify(phrenPath) {
1468
929
  : "Run `phren init` to install or refresh hooks",
1469
930
  });
1470
931
  }
1471
- const globalClaude = path.join(phrenPath, "global", "CLAUDE.md");
932
+ const globalClaude = path.join(phrenPath, "global", "AGENTS.md");
1472
933
  const globalOk = fs.existsSync(globalClaude);
1473
934
  checks.push({
1474
935
  name: "global-claude",
1475
936
  ok: globalOk,
1476
- detail: globalOk ? "global/CLAUDE.md exists" : "global/CLAUDE.md missing",
937
+ detail: globalOk ? "global/AGENTS.md exists" : "global/AGENTS.md missing",
1477
938
  fix: globalOk ? undefined : "Run `phren init` to create starter files",
1478
939
  });
1479
940
  const govDir = path.join(phrenPath, ".config");