@amoree-code/ocean 2.23.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/README.md +46 -53
  2. package/dist/application/clients/bundles.js +1 -1
  3. package/dist/application/clients/client-detect.js +291 -0
  4. package/dist/application/clients/clients.js +104 -25
  5. package/dist/application/clients/desktop-link.js +40 -0
  6. package/dist/application/clients/desktop-watcher.js +6 -4
  7. package/dist/application/clients/hook-trust.js +106 -0
  8. package/dist/application/clients/hooks.js +7 -1
  9. package/dist/application/clients/mcp-schema-cost.js +74 -0
  10. package/dist/application/clients/native.js +38 -2
  11. package/dist/application/clients/registry.js +51 -9
  12. package/dist/application/clients/status.js +7 -2
  13. package/dist/application/gateway/webhook-gateway.js +1 -1
  14. package/dist/application/integrations/charter-copies.js +1 -1
  15. package/dist/application/integrations/engine-entry-repair.js +4 -3
  16. package/dist/application/integrations/skill-auto-sync.js +2 -2
  17. package/dist/application/integrations/skill-filter.js +1 -1
  18. package/dist/application/integrations/skill-router.js +134 -90
  19. package/dist/application/layout/layout-apply.js +1 -1
  20. package/dist/application/layout/workspace-template.js +1 -1
  21. package/dist/application/onboarding/steps.js +121 -30
  22. package/dist/application/profiles/profile-doctor.js +118 -0
  23. package/dist/application/profiles/profile-migration-service.js +208 -0
  24. package/dist/application/profiles/profile-suggestion.js +3 -7
  25. package/dist/application/profiles/profile-upgrade-service.js +98 -86
  26. package/dist/application/pull/history-index.js +1 -1
  27. package/dist/application/pull/project-match.js +3 -3
  28. package/dist/application/pull/pull.js +1 -1
  29. package/dist/application/pull/server-capture.js +92 -9
  30. package/dist/application/scheduler/local-scheduler.js +2 -2
  31. package/dist/application/spend/claude-prices.js +55 -0
  32. package/dist/application/spend/claude-spend.js +365 -0
  33. package/dist/application/uninstall/uninstall.js +25 -3
  34. package/dist/application/upkeep/nightly-upkeep.js +4 -4
  35. package/dist/composition/runtime.js +2 -2
  36. package/dist/infrastructure/desktop/claude-export.js +1 -1
  37. package/dist/infrastructure/desktop/desktop-chat.js +60 -13
  38. package/dist/infrastructure/desktop/indexeddb.js +4 -4
  39. package/dist/infrastructure/desktop/leveldb.js +2 -2
  40. package/dist/infrastructure/filesystem/profile-loader.js +3 -45
  41. package/dist/infrastructure/filesystem/runtime-config-loader.js +1 -1
  42. package/dist/infrastructure/observability/runtime-logger.js +1 -1
  43. package/dist/infrastructure/process/agent-tool-executor.js +3 -3
  44. package/dist/infrastructure/process/process-supervisor.js +1 -1
  45. package/dist/infrastructure/process/service.js +8 -8
  46. package/dist/infrastructure/providers/openai-compatible.js +2 -2
  47. package/dist/infrastructure/providers/provider-invocation.js +1 -1
  48. package/dist/infrastructure/providers/session-facts-completer.js +78 -5
  49. package/dist/interfaces/cli/auth-command.js +2 -2
  50. package/dist/interfaces/cli/brief-command.js +1 -1
  51. package/dist/interfaces/cli/browser-command.js +6 -6
  52. package/dist/interfaces/cli/browser-findings.js +6 -9
  53. package/dist/interfaces/cli/browser-settings.js +10 -10
  54. package/dist/interfaces/cli/capture-command.js +6 -6
  55. package/dist/interfaces/cli/client-test-command.js +3 -3
  56. package/dist/interfaces/cli/clients-command.js +33 -6
  57. package/dist/interfaces/cli/command-aliases.js +56 -0
  58. package/dist/interfaces/cli/command-registry.js +48 -1414
  59. package/dist/interfaces/cli/commands/browser.js +5 -0
  60. package/dist/interfaces/cli/commands/capture.js +19 -0
  61. package/dist/interfaces/cli/commands/catalog.js +9 -0
  62. package/dist/interfaces/cli/commands/client.js +135 -0
  63. package/dist/interfaces/cli/commands/clients.js +33 -0
  64. package/dist/interfaces/cli/commands/connectors.js +14 -0
  65. package/dist/interfaces/cli/commands/context.js +9 -0
  66. package/dist/interfaces/cli/commands/cost.js +15 -0
  67. package/dist/interfaces/cli/commands/daily.js +11 -0
  68. package/dist/interfaces/cli/commands/day.js +25 -0
  69. package/dist/interfaces/cli/commands/dispatch.js +31 -0
  70. package/dist/interfaces/cli/commands/doctor.js +60 -0
  71. package/dist/interfaces/cli/commands/env.js +5 -0
  72. package/dist/interfaces/cli/commands/gateway.js +16 -0
  73. package/dist/interfaces/cli/commands/handoff.js +11 -0
  74. package/dist/interfaces/cli/commands/health.js +17 -0
  75. package/dist/interfaces/cli/commands/hook.js +142 -0
  76. package/dist/interfaces/cli/commands/idea.js +11 -0
  77. package/dist/interfaces/cli/commands/install.js +31 -0
  78. package/dist/interfaces/cli/commands/intent.js +14 -0
  79. package/dist/interfaces/cli/commands/intercept.js +22 -0
  80. package/dist/interfaces/cli/commands/layout.js +11 -0
  81. package/dist/interfaces/cli/commands/lifecycle.js +5 -0
  82. package/dist/interfaces/cli/commands/loop.js +73 -0
  83. package/dist/interfaces/cli/commands/market.js +11 -0
  84. package/dist/interfaces/cli/commands/mcp.js +57 -0
  85. package/dist/interfaces/cli/commands/memory.js +5 -0
  86. package/dist/interfaces/cli/commands/migrate.js +5 -0
  87. package/dist/interfaces/cli/commands/observe.js +11 -0
  88. package/dist/interfaces/cli/commands/obsidian.js +111 -0
  89. package/dist/interfaces/cli/commands/operate.js +7 -0
  90. package/dist/interfaces/cli/commands/policy.js +16 -0
  91. package/dist/interfaces/cli/commands/project.js +207 -0
  92. package/dist/interfaces/cli/commands/repair.js +20 -0
  93. package/dist/interfaces/cli/commands/run.js +52 -0
  94. package/dist/interfaces/cli/commands/schedule.js +58 -0
  95. package/dist/interfaces/cli/commands/service.js +21 -0
  96. package/dist/interfaces/cli/commands/session.js +182 -0
  97. package/dist/interfaces/cli/commands/sessions.js +12 -0
  98. package/dist/interfaces/cli/commands/setup.js +21 -0
  99. package/dist/interfaces/cli/commands/skill.js +159 -0
  100. package/dist/interfaces/cli/commands/tasks.js +10 -0
  101. package/dist/interfaces/cli/commands/update-remove.js +25 -0
  102. package/dist/interfaces/cli/connectors-command.js +150 -0
  103. package/dist/interfaces/cli/context-command.js +39 -3
  104. package/dist/interfaces/cli/cost-command.js +104 -0
  105. package/dist/interfaces/cli/curator-command.js +1 -1
  106. package/dist/interfaces/cli/daily-command.js +7 -1
  107. package/dist/interfaces/cli/desktop-command.js +43 -7
  108. package/dist/interfaces/cli/distill-command.js +7 -2
  109. package/dist/interfaces/cli/express-command.js +1 -1
  110. package/dist/interfaces/cli/failures-command.js +4 -4
  111. package/dist/interfaces/cli/gateway-findings.js +2 -2
  112. package/dist/interfaces/cli/governance-command.js +23 -16
  113. package/dist/interfaces/cli/handoff-command.js +1 -1
  114. package/dist/interfaces/cli/harvest-command.js +2 -2
  115. package/dist/interfaces/cli/help-command.js +53 -169
  116. package/dist/interfaces/cli/hygiene-command.js +1 -1
  117. package/dist/interfaces/cli/idea-command.js +1 -1
  118. package/dist/interfaces/cli/intercept-command.js +8 -7
  119. package/dist/interfaces/cli/interests-command.js +1 -1
  120. package/dist/interfaces/cli/layout-command.js +2 -0
  121. package/dist/interfaces/cli/market-command.js +9 -9
  122. package/dist/interfaces/cli/mcp-gateway-command.js +124 -7
  123. package/dist/interfaces/cli/mcp-probe-command.js +186 -0
  124. package/dist/interfaces/cli/mcp-status-command.js +5 -5
  125. package/dist/interfaces/cli/memory-command.js +41 -7
  126. package/dist/interfaces/cli/migrate-command.js +2 -2
  127. package/dist/interfaces/cli/note-command.js +1 -1
  128. package/dist/interfaces/cli/onboard-command.js +14 -0
  129. package/dist/interfaces/cli/operate-command.js +5 -5
  130. package/dist/interfaces/cli/profiles-command.js +61 -1
  131. package/dist/interfaces/cli/rhythm-command.js +11 -5
  132. package/dist/interfaces/cli/running-server-findings.js +1 -1
  133. package/dist/interfaces/cli/scorecard-command.js +8 -8
  134. package/dist/interfaces/cli/session-facts-command.js +2 -2
  135. package/dist/interfaces/cli/sessions-command.js +145 -0
  136. package/dist/interfaces/cli/setup-command.js +15 -2
  137. package/dist/interfaces/cli/tasks-command.js +63 -13
  138. package/dist/interfaces/cli/telemetry-command.js +4 -4
  139. package/dist/interfaces/cli/uninstall-command.js +1 -1
  140. package/dist/interfaces/cli/week-failures.js +32 -0
  141. package/dist/main.js +12 -0
  142. package/node_modules/@ocean/brain/dist/{infrastructure/brain/brain-index.js → brain-index.js} +2 -2
  143. package/node_modules/@ocean/brain/dist/{brain/brain-markdown.js → brain-markdown.js} +1 -1
  144. package/node_modules/@ocean/brain/dist/{brain/brain-service.js → brain-service.js} +12 -2
  145. package/node_modules/@ocean/brain/dist/memory/brain-dump.js +92 -16
  146. package/node_modules/@ocean/brain/dist/memory/extraction-log.js +125 -0
  147. package/node_modules/@ocean/brain/dist/memory/extraction-retry.js +54 -0
  148. package/node_modules/@ocean/brain/dist/memory/fact-routing.js +44 -1
  149. package/node_modules/@ocean/brain/dist/memory/lesson-activation.js +2 -2
  150. package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +2 -2
  151. package/node_modules/@ocean/brain/dist/memory/lessons.js +1 -1
  152. package/node_modules/@ocean/brain/dist/memory/memory-audit.js +2 -2
  153. package/node_modules/@ocean/brain/dist/memory/memory-harvest.js +1 -1
  154. package/node_modules/@ocean/brain/dist/memory/memory-paths.js +8 -0
  155. package/node_modules/@ocean/brain/dist/memory/memory-review.js +31 -3
  156. package/node_modules/@ocean/brain/dist/memory/memory-trash.js +29 -0
  157. package/node_modules/@ocean/brain/dist/memory/memory-write.js +4 -2
  158. package/node_modules/@ocean/brain/dist/memory/model-narrative.js +2 -2
  159. package/node_modules/@ocean/brain/dist/memory/profile-facts.js +1 -1
  160. package/node_modules/@ocean/brain/dist/memory/routing.json +6 -6
  161. package/node_modules/@ocean/{market/dist/skills → brain/dist/memory}/signal-detection.js +1 -1
  162. package/node_modules/@ocean/brain/dist/{memory → people}/people.js +1 -1
  163. package/node_modules/@ocean/brain/dist/sessions-capture/session-facts.js +625 -0
  164. package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-promotion.js +7 -15
  165. package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-summary.js +1 -1
  166. package/node_modules/@ocean/brain/dist/sessions-capture/session-triage.js +52 -0
  167. package/node_modules/@ocean/brain/package.json +1 -1
  168. package/node_modules/@ocean/connect/dist/connectors/connector-hub.js +173 -0
  169. package/node_modules/@ocean/{market → connect}/dist/install/default-marketplace.js +6 -2
  170. package/node_modules/@ocean/{market → connect}/dist/install/marketplace-service.js +1 -1
  171. package/node_modules/@ocean/connect/dist/mcp/mcp-gateway.js +987 -0
  172. package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-launch.js +102 -5
  173. package/node_modules/@ocean/{market → connect}/dist/registry/official-registry.js +1 -1
  174. package/node_modules/@ocean/{market → connect}/dist/security/permissions.js +1 -1
  175. package/node_modules/@ocean/{market → connect}/dist/skills/skill-hub.js +104 -6
  176. package/node_modules/@ocean/{market → connect}/package.json +2 -2
  177. package/node_modules/@ocean/context/dist/{context/context-ladder.js → context-ladder.js} +3 -3
  178. package/node_modules/@ocean/context/dist/{context/context-references.js → context-references.js} +5 -4
  179. package/node_modules/@ocean/context/dist/{context/context-cost.js → context-size.js} +6 -6
  180. package/node_modules/@ocean/context/dist/{context/intent-router.js → intent-router.js} +1 -1
  181. package/node_modules/@ocean/context/dist/{context/resource-injection.js → resource-injection.js} +3 -1
  182. package/node_modules/@ocean/context/package.json +1 -1
  183. package/node_modules/@ocean/core/dist/domain/brain/brain-record.js +1 -1
  184. package/node_modules/@ocean/core/dist/domain/capabilities/capability-manifest.js +5 -5
  185. package/node_modules/@ocean/core/dist/domain/connector-entry.js +86 -0
  186. package/node_modules/@ocean/core/dist/domain/context/context.js +1 -1
  187. package/node_modules/@ocean/core/dist/domain/context/project-id.js +8 -2
  188. package/node_modules/@ocean/core/dist/domain/{evidence/evidence.js → evidence.js} +1 -1
  189. package/node_modules/@ocean/core/dist/domain/mcp/memory-contract.js +4 -1
  190. package/node_modules/@ocean/core/dist/domain/ports/brain-index-port.js +1 -1
  191. package/node_modules/@ocean/core/dist/domain/profiles/profile-markdown.js +40 -0
  192. package/node_modules/@ocean/core/dist/domain/profiles/profile-resolution.js +276 -0
  193. package/node_modules/@ocean/core/dist/domain/profiles/profile-selection.js +23 -60
  194. package/node_modules/@ocean/core/dist/domain/profiles/profile-upgrade.js +2 -2
  195. package/node_modules/@ocean/core/dist/domain/profiles/profile.js +66 -6
  196. package/node_modules/@ocean/core/dist/domain/profiles/runtime-config.js +1 -1
  197. package/node_modules/@ocean/core/dist/domain/runs/agent-tools.js +2 -2
  198. package/node_modules/@ocean/core/dist/domain/sessions/session-identity.js +53 -0
  199. package/node_modules/@ocean/core/dist/domain/sessions/session-metadata.js +208 -0
  200. package/node_modules/@ocean/core/dist/domain/{tasks/task-id.js → task-id.js} +2 -2
  201. package/node_modules/@ocean/core/dist/profiles/profile-files.js +57 -0
  202. package/node_modules/@ocean/core/dist/profiles/profile-loader.js +97 -0
  203. package/node_modules/@ocean/core/dist/profiles/project-profile-fill.js +33 -0
  204. package/node_modules/@ocean/core/dist/profiles/session-profile.js +158 -0
  205. package/node_modules/@ocean/core/dist/shared/charter.js +110 -0
  206. package/node_modules/@ocean/core/dist/shared/context-ack.js +1 -1
  207. package/node_modules/@ocean/core/dist/shared/context-triggers.js +67 -0
  208. package/node_modules/@ocean/core/dist/shared/paths.js +6 -6
  209. package/node_modules/@ocean/core/dist/shared/project-legacy.js +232 -0
  210. package/node_modules/@ocean/core/dist/shared/project-manifest.js +308 -0
  211. package/node_modules/@ocean/core/dist/shared/project-names.js +87 -0
  212. package/node_modules/@ocean/core/dist/shared/project-register.js +560 -0
  213. package/node_modules/@ocean/core/dist/shared/project-resolution.js +83 -861
  214. package/node_modules/@ocean/core/dist/shared/repo-signals.js +45 -0
  215. package/node_modules/@ocean/core/dist/shared/task-reference.js +1 -1
  216. package/node_modules/@ocean/core/dist/shared/text-tokens.js +37 -0
  217. package/node_modules/@ocean/core/dist/shared/tool-groups.js +224 -0
  218. package/node_modules/@ocean/core/package.json +4 -1
  219. package/node_modules/@ocean/services/dist/day/day.js +45 -3
  220. package/node_modules/@ocean/services/dist/{distill → day}/distill.js +29 -3
  221. package/node_modules/@ocean/services/dist/{harvest → day}/harvest.js +54 -14
  222. package/node_modules/@ocean/services/dist/{brief → day}/interest-discovery.js +3 -3
  223. package/node_modules/@ocean/services/dist/day/note.js +2 -2
  224. package/node_modules/@ocean/services/dist/{onboarding → day}/onboarding.js +1 -1
  225. package/node_modules/@ocean/services/dist/day/patterns.js +68 -0
  226. package/node_modules/@ocean/services/dist/{curator → health}/curator.js +5 -5
  227. package/node_modules/@ocean/services/dist/{journey → health}/failures.js +7 -5
  228. package/node_modules/@ocean/services/dist/{hygiene → health}/hygiene.js +2 -2
  229. package/node_modules/@ocean/services/dist/{journey → health}/lesson-effect.js +1 -1
  230. package/node_modules/@ocean/services/dist/{scorecard → health}/scorecard.js +3 -3
  231. package/node_modules/@ocean/services/dist/{upkeep → health}/upkeep.js +2 -2
  232. package/node_modules/@ocean/services/dist/{doctor → health}/workspace-doctor.js +57 -17
  233. package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-session.js +1 -1
  234. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/call-ledger.js +3 -0
  235. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-client.js +19 -3
  236. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/obsidian-server.js +4 -4
  237. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/ocean-server.js +423 -34
  238. package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/conflict-log.js +1 -1
  239. package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/folder-templates.js +8 -5
  240. package/node_modules/@ocean/services/dist/projects/project-doctor.js +173 -0
  241. package/node_modules/@ocean/services/dist/projects/project-snippet.js +9 -0
  242. package/node_modules/@ocean/services/dist/projects/projects-overview.js +2 -2
  243. package/node_modules/@ocean/services/package.json +1 -1
  244. package/node_modules/@ocean/{loop/dist/loops → work/dist/runs}/guard-runtime.js +3 -3
  245. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/memory-knowledge-operations.js +4 -12
  246. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-contract.js +2 -2
  247. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/project-operations.js +2 -1
  248. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/task-operations.js +4 -4
  249. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/write-guard.js +1 -1
  250. package/node_modules/@ocean/{loop → work}/dist/runs/prompt-assembly.js +2 -2
  251. package/node_modules/@ocean/{loop → work}/dist/runs/run-agent.js +4 -4
  252. package/node_modules/@ocean/{loop → work}/dist/runs/tool-loop.js +4 -4
  253. package/node_modules/@ocean/work/dist/sessions/hooks/desktop-facts.js +309 -0
  254. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-end-hook.js +36 -5
  255. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-facts-hook.js +144 -14
  256. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-start-hook.js +129 -12
  257. package/node_modules/@ocean/work/dist/sessions/hooks/start-brief.js +110 -0
  258. package/node_modules/@ocean/work/dist/sessions/hooks/unlinked-warning.js +68 -0
  259. package/node_modules/@ocean/{loop → work}/dist/sessions/session-closeout.js +4 -4
  260. package/node_modules/@ocean/{loop → work}/dist/sessions/session-projects.js +13 -3
  261. package/node_modules/@ocean/work/dist/sessions/session-relink.js +300 -0
  262. package/node_modules/@ocean/{loop → work}/dist/sessions/session-retention.js +1 -1
  263. package/node_modules/@ocean/{loop → work}/dist/tasks/list-tasks.js +7 -2
  264. package/node_modules/@ocean/{loop → work}/dist/tasks/renumber-tasks.js +4 -2
  265. package/node_modules/@ocean/{loop → work}/dist/tasks/session-task.js +2 -2
  266. package/node_modules/@ocean/{loop → work}/dist/tasks/sync-task-prs.js +77 -7
  267. package/node_modules/@ocean/work/dist/tasks/task-git.js +63 -0
  268. package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop.js +4 -4
  269. package/node_modules/@ocean/{loop → work}/dist/tasks/verification-readiness.js +1 -1
  270. package/node_modules/@ocean/{loop → work}/dist/tasks/verify-task.js +1 -1
  271. package/node_modules/@ocean/{loop → work}/package.json +2 -2
  272. package/ocean-marketplace.json +41 -41
  273. package/package.json +12 -11
  274. package/skills/core/daily-harvest/SKILL.md +1 -1
  275. package/skills/core/ocean-memory/SKILL.md +4 -0
  276. package/skills/core/use-browser/SKILL.md +30 -7
  277. package/skills/index.json +1 -1
  278. package/templates/profiles/default.md +44 -0
  279. package/templates/profiles/developer.md +45 -0
  280. package/templates/profiles/reviewer.md +44 -0
  281. package/templates/profiles/strategist.md +44 -0
  282. package/templates/profiles-v3/analysis.md +16 -0
  283. package/templates/profiles-v3/backend.md +16 -0
  284. package/templates/profiles-v3/base.md +57 -0
  285. package/templates/profiles-v3/code-review.md +16 -0
  286. package/templates/profiles-v3/devops.md +16 -0
  287. package/templates/profiles-v3/docs-office.md +16 -0
  288. package/templates/profiles-v3/frontend.md +16 -0
  289. package/templates/profiles-v3/learning.md +16 -0
  290. package/templates/profiles-v3/marketing-ads.md +16 -0
  291. package/templates/profiles-v3/marketing-content-seo.md +16 -0
  292. package/templates/profiles-v3/ocean-ops.md +16 -0
  293. package/templates/profiles-v3/product-strategy.md +16 -0
  294. package/templates/profiles-v3/qa-testing.md +16 -0
  295. package/templates/profiles-v3/security.md +16 -0
  296. package/templates/workspace/MANIFEST.json +1 -0
  297. package/templates/workspace/charter/core.md +22 -90
  298. package/templates/workspace/charter/policies/README.md +7 -1
  299. package/templates/workspace/charter/policies/claude-code-context.md +6 -1
  300. package/templates/workspace/charter/policies/concise-output.md +5 -0
  301. package/templates/workspace/charter/policies/context.md +5 -0
  302. package/templates/workspace/charter/policies/contracts/task.md +2 -2
  303. package/templates/workspace/charter/policies/git.md +5 -0
  304. package/templates/workspace/charter/policies/graph.md +6 -1
  305. package/templates/workspace/charter/policies/knowledge.md +11 -4
  306. package/templates/workspace/charter/policies/layout.md +23 -0
  307. package/templates/workspace/charter/policies/lifecycle.md +5 -0
  308. package/templates/workspace/charter/policies/memory.md +5 -0
  309. package/templates/workspace/charter/policies/minimal-change.md +5 -0
  310. package/templates/workspace/charter/policies/models.md +5 -0
  311. package/templates/workspace/charter/policies/response.md +5 -0
  312. package/templates/workspace/charter/policies/skill-observer.md +12 -0
  313. package/templates/workspace/charter/policies/stack.md +5 -0
  314. package/templates/workspace/charter/policies/task.md +17 -3
  315. package/templates/workspace/charter/policies/verification.md +5 -0
  316. package/node_modules/@ocean/brain/dist/evidence/verification-report.js +0 -13
  317. package/node_modules/@ocean/brain/dist/memory/daily-narrative.js +0 -142
  318. package/node_modules/@ocean/brain/dist/memory/session-facts.js +0 -283
  319. package/node_modules/@ocean/context/dist/context/context-compression.js +0 -66
  320. package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +0 -174
  321. package/node_modules/@ocean/loop/dist/operations/task-linker.js +0 -40
  322. package/node_modules/@ocean/loop/dist/sessions/session-pointer.js +0 -133
  323. package/node_modules/@ocean/loop/dist/tasks/task-git.js +0 -28
  324. package/node_modules/@ocean/market/dist/mcp/mcp-gateway.js +0 -533
  325. package/templates/profiles/default.json +0 -51
  326. package/templates/profiles/developer.json +0 -51
  327. package/templates/profiles/reviewer.json +0 -51
  328. package/templates/profiles/strategist.json +0 -51
  329. /package/node_modules/@ocean/brain/dist/{brain/brain-eval.js → brain-eval.js} +0 -0
  330. /package/node_modules/@ocean/brain/dist/{brain/brain-reindex.js → brain-reindex.js} +0 -0
  331. /package/node_modules/@ocean/brain/dist/{capture → sessions-capture}/inbox-sync.js +0 -0
  332. /package/node_modules/@ocean/{market → connect}/dist/adapters/mcp-adapter.js +0 -0
  333. /package/node_modules/@ocean/{market → connect}/dist/adapters/owned-directory.js +0 -0
  334. /package/node_modules/@ocean/{market → connect}/dist/adapters/plugin-adapter.js +0 -0
  335. /package/node_modules/@ocean/{market → connect}/dist/adapters/skill-adapter.js +0 -0
  336. /package/node_modules/@ocean/{market → connect}/dist/capability/adapter.js +0 -0
  337. /package/node_modules/@ocean/{market → connect}/dist/capability/catalog.js +0 -0
  338. /package/node_modules/@ocean/{market → connect}/dist/capability/content-digest.js +0 -0
  339. /package/node_modules/@ocean/{market → connect}/dist/capability/registry.js +0 -0
  340. /package/node_modules/@ocean/{market → connect}/dist/install/lock.js +0 -0
  341. /package/node_modules/@ocean/{market → connect}/dist/install/own-server.js +0 -0
  342. /package/node_modules/@ocean/{market → connect}/dist/mcp/chrome-debugging.js +0 -0
  343. /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-connection.js +0 -0
  344. /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-runner.js +0 -0
  345. /package/node_modules/@ocean/{market → connect}/dist/security/description-scan.js +0 -0
  346. /package/node_modules/@ocean/{market → connect}/dist/security/secrets.js +0 -0
  347. /package/node_modules/@ocean/{market → connect}/dist/skills/core-skill-sync.js +0 -0
  348. /package/node_modules/@ocean/context/dist/{context/context-packet.js → context-packet.js} +0 -0
  349. /package/node_modules/@ocean/core/dist/domain/{process/process-events.js → process-events.js} +0 -0
  350. /package/node_modules/@ocean/core/dist/domain/{redaction/redaction.js → redaction.js} +0 -0
  351. /package/node_modules/@ocean/services/dist/{brief → day}/brief.js +0 -0
  352. /package/node_modules/@ocean/services/dist/{express → day}/express.js +0 -0
  353. /package/node_modules/@ocean/services/dist/{brief → day}/source-registry.json +0 -0
  354. /package/node_modules/@ocean/services/dist/{journey → health}/telemetry.js +0 -0
  355. /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-service.js +0 -0
  356. /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-task-runner.js +0 -0
  357. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-session.js +0 -0
  358. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/server-version.js +0 -0
  359. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/tool-registry.js +0 -0
  360. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/inbox-promotion.js +0 -0
  361. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-discovery.js +0 -0
  362. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-ingestion.js +0 -0
  363. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-sync.js +0 -0
  364. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-writer.js +0 -0
  365. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-scope.js +0 -0
  366. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-io.js +0 -0
  367. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-operations.js +0 -0
  368. /package/node_modules/@ocean/{loop → work}/dist/runs/run-authorization.js +0 -0
  369. /package/node_modules/@ocean/{loop → work}/dist/runs/session-tokens.js +0 -0
  370. /package/node_modules/@ocean/{loop/dist/handoff → work/dist/sessions}/handoff-service.js +0 -0
  371. /package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/lifecycle-hooks.js +0 -0
  372. /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-store.js +0 -0
  373. /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-validator.js +0 -0
  374. /package/node_modules/@ocean/{loop → work}/dist/tasks/archive-tasks.js +0 -0
  375. /package/node_modules/@ocean/{loop → work}/dist/tasks/checkpoint-task.js +0 -0
  376. /package/node_modules/@ocean/{loop → work}/dist/tasks/claim-task.js +0 -0
  377. /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/iteration-graph.js +0 -0
  378. /package/node_modules/@ocean/{loop → work}/dist/tasks/new-task.js +0 -0
  379. /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop-record.js +0 -0
  380. /package/node_modules/@ocean/{loop → work}/dist/tasks/task-verification.js +0 -0
@@ -0,0 +1,87 @@
1
+ // One project goes by many names: its id, its display name, the Claude project it is in, the
2
+ // folder it used to live in (T-332). These are the deterministic comparisons between them. An
3
+ // exact or normalized match binds; a near one only ever suggests.
4
+ // Case, outer and repeated whitespace, and the separators people put between words (` - `, `|`,
5
+ // `_`, `.`, space) carry no meaning: `Jira - KarWatt`, `jira_karwatt` and `Jira KarWatt` are one.
6
+ export function normalizeName(name) {
7
+ return name
8
+ .normalize("NFKC")
9
+ .toLowerCase()
10
+ .replace(/[\s|_.-]+/g, " ")
11
+ .trim();
12
+ }
13
+ // Edit distance with adjacent transpositions (optimal string alignment): `Desginer` is one edit
14
+ // from `designer`, not two.
15
+ function editDistance(a, b) {
16
+ const rows = a.length + 1;
17
+ const cols = b.length + 1;
18
+ const d = Array.from({ length: rows }, (_, i) => Array.from({ length: cols }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
19
+ for (let i = 1; i < rows; i++)
20
+ for (let j = 1; j < cols; j++) {
21
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
22
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
23
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
24
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
25
+ }
26
+ return d[a.length][b.length];
27
+ }
28
+ const singular = (normalized) => normalized
29
+ .split(" ")
30
+ .map((word) => word.length > 3
31
+ ? word.replace(/ies$/, "y").replace(/([^s])s$/, "$1")
32
+ : word)
33
+ .join(" ");
34
+ // Two names that are probably the same thing but not equal once normalized: one or two edits
35
+ // apart (both long enough that this is not noise), singular against plural, or the same letters
36
+ // with the separators dropped (`star people` / `starpeople`). For suggestions only.
37
+ export function nearName(a, b) {
38
+ const left = normalizeName(a);
39
+ const right = normalizeName(b);
40
+ if (!left || !right || left === right)
41
+ return false;
42
+ if (singular(left) === singular(right))
43
+ return true;
44
+ if (left.replace(/ /g, "") === right.replace(/ /g, ""))
45
+ return true;
46
+ return (Math.min(left.length, right.length) >= 5 &&
47
+ Math.abs(left.length - right.length) <= 2 &&
48
+ editDistance(left, right) <= 2);
49
+ }
50
+ // Words that turn up in the owner's project names. A word one or two edits from one of these,
51
+ // and not itself one of them, is reported as a probable typo.
52
+ const KNOWN_WORDS = [
53
+ "backend",
54
+ "certificates",
55
+ "company",
56
+ "courses",
57
+ "dashboard",
58
+ "designer",
59
+ "developer",
60
+ "education",
61
+ "frontend",
62
+ "generator",
63
+ "javascript",
64
+ "marketing",
65
+ "roadmap",
66
+ "scanner",
67
+ "studying",
68
+ "typescript",
69
+ "website",
70
+ "workspace",
71
+ ];
72
+ // The probable typos in a name: [written, meant] pairs.
73
+ export function nameTypos(name) {
74
+ const typos = [];
75
+ for (const word of normalizeName(name).split(" ")) {
76
+ if (word.length < 5 || KNOWN_WORDS.includes(word))
77
+ continue;
78
+ if (KNOWN_WORDS.some((known) => singular(known) === singular(word)))
79
+ continue;
80
+ const meant = KNOWN_WORDS.find((known) => Math.abs(known.length - word.length) <= 2 &&
81
+ editDistance(word, known) <= 2);
82
+ if (meant)
83
+ typos.push([word, meant]);
84
+ }
85
+ return typos;
86
+ }
87
+ //# sourceMappingURL=project-names.js.map
@@ -0,0 +1,560 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import { mkdir, readdir, readFile, realpath, rename, rmdir, writeFile, } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { isProjectCategory, isValidProjectId, PROJECT_CATEGORIES, } from "../domain/context/project-id.js";
6
+ import { atomicWrite } from "./fs-utils.js";
7
+ import { BRAIN_RECORD_DIRS, CHARTER_DIR, listProjectDirs, oceanEnv, oceanPath, oceanRoot, PROJECTS_DIR, projectDir, projectFolder, } from "./paths.js";
8
+ import { cacheBindings, combineBindings, listLegacyBindings, saveProjectBindings, withProjectsLock, } from "./project-legacy.js";
9
+ import { canonicalPath, expandHome, folderCategory, hasControlCharacters, listProjectManifests, MAX_PROJECT_ALIASES, matchProject, newManifest, portablePath, projectAliases, projectCategory, projectSlug, projectsRoot, suggestProjects, writeManifest, } from "./project-manifest.js";
10
+ import { resolveProject, } from "./project-resolution.js";
11
+ // Explicit registration/binding: never guesses on a name or path collision, always returns
12
+ // the conflict instead of silently overwriting an existing binding. `addPath` is the one
13
+ // deliberate exception: it adds another repo to an existing project (dashboard + backend).
14
+ export async function bindProject(name, targetPath, options = {}) {
15
+ if (!isValidProjectId(name))
16
+ throw new Error(`Invalid project id '${name}': use lowercase letters, digits, dot, underscore or hyphen`);
17
+ const resolvedPath = canonicalPath(targetPath);
18
+ return withProjectsLock(async () => {
19
+ const manifests = await listProjectManifests();
20
+ const legacy = await listLegacyBindings();
21
+ const bindings = combineBindings(manifests, legacy);
22
+ const existingAtPath = bindings.find((binding) => path.resolve(binding.path) === resolvedPath);
23
+ if (existingAtPath && existingAtPath.id !== name)
24
+ return {
25
+ binding: existingAtPath,
26
+ created: false,
27
+ conflict: existingAtPath,
28
+ };
29
+ if (existingAtPath?.manifest)
30
+ return { binding: existingAtPath, created: false };
31
+ // From here the path is free, or is this project's own legacy binding being folded in,
32
+ // which is never a conflict.
33
+ const existingByName = bindings.find((binding) => binding.id === name && binding.path !== resolvedPath);
34
+ if (existingByName && !existingAtPath && !options.addPath)
35
+ return {
36
+ binding: existingByName,
37
+ created: false,
38
+ conflict: existingByName,
39
+ };
40
+ const existing = manifests.find((manifest) => manifest.id === name);
41
+ // Auto-registration never takes over a folder someone else made (checked under the lock,
42
+ // so a folder created a moment ago by another writer counts).
43
+ if (options.autoRegistered &&
44
+ !existing &&
45
+ existsSync(oceanPath(projectDir(name))))
46
+ throw new ProjectFolderTaken(`${projectDir(name)} already exists; bind it explicitly`);
47
+ const manifest = existing
48
+ ? { ...existing, paths: [...existing.paths, portablePath(resolvedPath)] }
49
+ : await newManifest(name, {
50
+ name,
51
+ paths: [portablePath(resolvedPath)],
52
+ created: new Date().toISOString(),
53
+ autoRegistered: options.autoRegistered === true,
54
+ }, manifests);
55
+ await writeManifest(manifest);
56
+ const updated = manifests
57
+ .filter((candidate) => candidate.id !== name)
58
+ .concat(manifest);
59
+ const next = combineBindings(updated, legacy);
60
+ await saveProjectBindings(cacheBindings(updated, legacy));
61
+ const binding = next.find((candidate) => candidate.path === resolvedPath);
62
+ return { binding, created: true };
63
+ });
64
+ }
65
+ const INDEX_BEGIN = "<!-- ocean:projects:begin (generated by `ocean project index --write`) -->";
66
+ const INDEX_END = "<!-- ocean:projects:end -->";
67
+ // Generated view of every project.json, kept in a managed block of 04-projects/registry.md so
68
+ // the hand-kept rows around it are never rewritten.
69
+ export async function renderProjectIndex() {
70
+ // Table cells: a `|` or a line break in a name or path would split the row.
71
+ const cell = (value) => value.replace(/[\r\n]+/g, " ").replaceAll("|", "\\|");
72
+ // One table per category, in PROJECT_CATEGORIES order; a project without one comes after,
73
+ // and a bad one shows as invalid instead of failing the whole index.
74
+ const category = (manifest) => {
75
+ try {
76
+ return projectCategory(manifest) ?? "uncategorized";
77
+ }
78
+ catch {
79
+ return "invalid";
80
+ }
81
+ };
82
+ const groups = new Map([...PROJECT_CATEGORIES, "uncategorized", "invalid"].map((name) => [
83
+ name,
84
+ [],
85
+ ]));
86
+ for (const manifest of await listProjectManifests())
87
+ groups
88
+ .get(category(manifest))
89
+ ?.push(`| \`${manifest.id}\` | ${cell(manifest.name)} | ${manifest.paths.length
90
+ ? manifest.paths.map((entry) => `\`${cell(entry)}\``).join("<br>")
91
+ : "—"} | ${manifest.autoRegistered ? "auto" : "manual"} |`);
92
+ const sections = [...groups]
93
+ .filter(([, rows]) => rows.length)
94
+ .flatMap(([name, rows]) => [
95
+ "",
96
+ `### ${name}`,
97
+ "",
98
+ "| Project | Name | Paths | Registered |",
99
+ "|---|---|---|---|",
100
+ ...rows,
101
+ ]);
102
+ return [
103
+ INDEX_BEGIN,
104
+ "## Projects (from project.json)",
105
+ ...sections,
106
+ INDEX_END,
107
+ ].join("\n");
108
+ }
109
+ export async function writeProjectIndex() {
110
+ return withProjectsLock(writeProjectIndexLocked);
111
+ }
112
+ async function writeProjectIndexLocked() {
113
+ const file = path.join(projectsRoot(), "registry.md");
114
+ let existing = "";
115
+ try {
116
+ existing = await readFile(file, "utf8");
117
+ }
118
+ catch (error) {
119
+ if (error.code !== "ENOENT")
120
+ throw error;
121
+ }
122
+ const block = await renderProjectIndex();
123
+ const begin = existing.indexOf(INDEX_BEGIN);
124
+ const end = existing.indexOf(INDEX_END);
125
+ let next;
126
+ if (begin >= 0 && end > begin)
127
+ next = `${existing.slice(0, begin)}${block}${existing.slice(end + INDEX_END.length)}`;
128
+ else if (begin >= 0 || end >= 0)
129
+ throw new Error(`${file}: unmatched ocean:projects marker; fix it by hand before regenerating`);
130
+ else
131
+ next = existing
132
+ ? `${existing.replace(/\n*$/, "")}\n\n${block}\n`
133
+ : `# Project registry\n\n${block}\n`;
134
+ if (next === existing)
135
+ return { file, changed: false };
136
+ await mkdir(path.dirname(file), { recursive: true });
137
+ await atomicWrite(file, next);
138
+ return { file, changed: true };
139
+ }
140
+ // Where a session may register its repo as a project without being asked (T-256 phase 2).
141
+ // OCEAN_CODE_ROOTS (a PATH-style list) overrides the default, ~/Documents.
142
+ function codeRoots() {
143
+ const configured = oceanEnv("CODE_ROOTS");
144
+ return (configured ? configured.split(path.delimiter) : ["~/Documents"])
145
+ .map((entry) => entry.trim())
146
+ .filter(Boolean)
147
+ .map((entry) => path.resolve(expandHome(entry)));
148
+ }
149
+ // `ocean project link "<name>" <id>` (T-332): the name becomes an alias of the project, so every
150
+ // later match on it binds there. A name another project already answers to is refused.
151
+ export async function linkProjectAlias(name, id) {
152
+ const alias = name.trim();
153
+ if (!alias)
154
+ throw new Error("a name to link is required");
155
+ if (hasControlCharacters(alias) || Buffer.byteLength(alias, "utf8") > 200)
156
+ throw new Error("the name must be one line of at most 200 bytes");
157
+ return withProjectsLock(async () => {
158
+ const manifests = await listProjectManifests();
159
+ const manifest = manifests.find((candidate) => candidate.id === id);
160
+ if (!manifest)
161
+ throw new Error(`no project '${id}'`);
162
+ const owner = matchProject(manifests, alias);
163
+ if (owner && owner !== id)
164
+ return { id, alias, added: false, conflict: owner };
165
+ const aliases = projectAliases(manifest);
166
+ if (aliases.some((known) => known.toLowerCase() === alias.toLowerCase()))
167
+ return { id, alias, added: false };
168
+ if (aliases.length >= MAX_PROJECT_ALIASES)
169
+ throw new Error(`project '${id}' already has ${MAX_PROJECT_ALIASES} aliases`);
170
+ await writeManifest({ ...manifest, aliases: [...aliases, alias] });
171
+ return { id, alias, added: true };
172
+ });
173
+ }
174
+ // `ocean project link "<name>" --new <category>` (T-332): a name no project answers to becomes
175
+ // a project of its own, linked to that name in one step. A name some project already answers to
176
+ // is reported as that project, never registered twice.
177
+ export async function linkNewProject(name, category) {
178
+ const known = matchProject(await listProjectManifests(), name);
179
+ if (known)
180
+ return { id: known, alias: name.trim(), added: false, created: false };
181
+ const id = projectSlug(name);
182
+ const project = await createProject(id, category, name.trim());
183
+ return { ...(await linkProjectAlias(name, id)), created: project.created };
184
+ }
185
+ // First sight of a Claude project name (T-333): a name a project answers to is linked; a name
186
+ // near some project's is only suggested, so a typo never becomes a second project; any other
187
+ // name becomes a project of its own, linked to that name.
188
+ export async function linkClaudeProjectName(name) {
189
+ const manifests = await listProjectManifests();
190
+ const known = matchProject(manifests, name);
191
+ if (known)
192
+ return { name, status: "linked", id: known };
193
+ const suggestions = [
194
+ ...new Set(suggestProjects(manifests, name).map((each) => each.id)),
195
+ ];
196
+ if (suggestions.length)
197
+ return { name, status: "suggested", suggestions };
198
+ const { id } = await registerNamedProject(name, ["claude.ai"]);
199
+ await linkProjectAlias(name, id);
200
+ return { name, status: "registered", id };
201
+ }
202
+ export async function findProject(ref) {
203
+ return matchProject(await listProjectManifests(), ref);
204
+ }
205
+ // A Claude project (claude.ai or Claude Desktop) first seen in a conversation (T-307): it has no
206
+ // repo or path, so it is registered by name — 04-projects/<slug>/ with project.json, marked
207
+ // auto-registered, and the standard layout. An existing project with that id or name is
208
+ // returned instead; a folder that exists without a manifest is never taken over.
209
+ export async function registerNamedProject(name, tags = []) {
210
+ return withProjectsLock(async () => {
211
+ const manifests = await listProjectManifests();
212
+ const known = matchProject(manifests, name);
213
+ if (known)
214
+ return { id: known, created: false };
215
+ const id = projectSlug(name);
216
+ if (!isValidProjectId(id))
217
+ throw new Error(`no usable project id from '${name}'`);
218
+ if (existsSync(oceanPath(projectDir(id))))
219
+ throw new ProjectFolderTaken(`${projectDir(id)}/ exists without project.json; register it explicitly`);
220
+ const manifest = await newManifest(id, {
221
+ name: name.trim(),
222
+ paths: [],
223
+ created: new Date().toISOString(),
224
+ autoRegistered: true,
225
+ }, manifests);
226
+ await writeManifest(tags.length ? { ...manifest, tags } : manifest);
227
+ await ensureProjectLayout(id);
228
+ await writeProjectIndexLocked();
229
+ return { id, created: true };
230
+ });
231
+ }
232
+ async function realOrSelf(target) {
233
+ try {
234
+ return await realpath(target);
235
+ }
236
+ catch {
237
+ return path.resolve(target);
238
+ }
239
+ }
240
+ function within(root, target) {
241
+ const prefix = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
242
+ return target === root || target.startsWith(prefix);
243
+ }
244
+ class ProjectFolderTaken extends Error {
245
+ }
246
+ // A session opened in a git repo that no project claims registers that repo as its own
247
+ // project: 04-projects/<slug>/ with project.json and the standard layout (ensureProjectLayout:
248
+ // tasks/, memory/, docs/, MEMORY.md). Automatic runs stay
249
+ // under the code roots, out of the temp dir and off a code root itself; `explicit` (the
250
+ // `ocean project register` command) is the owner asking, so only the hard rules apply: a git
251
+ // repo, not a linked worktree or submodule, not the Ocean workspace, never over an existing
252
+ // project folder. Sibling repos are never merged: a code-root folder often holds unrelated
253
+ // repos, so joining one project to another stays explicit (`bind --add`).
254
+ export async function autoRegisterProject(cwd, options = {}) {
255
+ let resolution = options.resolution ?? (await resolveProject(cwd));
256
+ const skipped = (reason) => ({
257
+ status: "skipped",
258
+ reason,
259
+ resolution,
260
+ });
261
+ if (!options.explicit && oceanEnv("AUTO_REGISTER") === "0")
262
+ return skipped("disabled by OCEAN_AUTO_REGISTER=0");
263
+ if (resolution.status !== "unbound")
264
+ return skipped(`already ${resolution.status}`);
265
+ if (!resolution.gitRoot)
266
+ return skipped("not inside a git repository");
267
+ if (!statSync(path.join(resolution.gitRoot, ".git")).isDirectory())
268
+ return skipped("a linked worktree or submodule; bind it explicitly");
269
+ const repo = await realOrSelf(resolution.gitRoot);
270
+ if (within(await realOrSelf(oceanRoot()), repo))
271
+ return skipped("inside the Ocean workspace");
272
+ if (!options.explicit) {
273
+ const roots = await Promise.all(codeRoots().map(realOrSelf));
274
+ if (roots.includes(repo))
275
+ return skipped("is a code root itself");
276
+ const root = roots.find((candidate) => within(candidate, repo));
277
+ if (!root)
278
+ return skipped("outside the code roots");
279
+ // The temp dir is excluded unless the owner deliberately put a code root inside it.
280
+ const temp = await realOrSelf(os.tmpdir());
281
+ if (within(temp, repo) && !within(temp, root))
282
+ return skipped("inside the temp directory");
283
+ }
284
+ const id = projectSlug(path.basename(repo));
285
+ if (!isValidProjectId(id))
286
+ return skipped(`no usable id from '${repo}'`);
287
+ let result;
288
+ try {
289
+ result = await bindProject(id, resolution.gitRoot, {
290
+ autoRegistered: true,
291
+ });
292
+ }
293
+ catch (error) {
294
+ if (!(error instanceof ProjectFolderTaken))
295
+ throw error;
296
+ // Another session may have registered this very repo a moment ago.
297
+ resolution = await resolveProject(cwd);
298
+ return skipped(error.message);
299
+ }
300
+ if (result.conflict) {
301
+ resolution = await resolveProject(cwd);
302
+ return skipped(`conflicts with project '${result.conflict.id}'`);
303
+ }
304
+ await ensureProjectLayout(id);
305
+ resolution = {
306
+ status: "bound",
307
+ projectId: id,
308
+ name: id,
309
+ path: result.binding.path,
310
+ matchedOn: result.binding.path === path.resolve(cwd) ? "cwd" : "path",
311
+ confidence: "high",
312
+ };
313
+ return {
314
+ status: "registered",
315
+ projectId: id,
316
+ path: result.binding.path,
317
+ resolution,
318
+ };
319
+ }
320
+ function memoryHeading(id) {
321
+ return `# ${id} — memory`;
322
+ }
323
+ // The only entries a project folder holds at its root. Lessons and decisions go in memory/
324
+ // (indexed by MEMORY.md, which every session in the project loads); reference material goes
325
+ // in docs/ (indexed by docs/README.md); work goes in tasks/. index.md is the generated board.
326
+ export const PROJECT_ROOT_ENTRIES = [
327
+ "project.json",
328
+ "MEMORY.md",
329
+ "README.md",
330
+ "index.md",
331
+ "tasks",
332
+ "memory",
333
+ "docs",
334
+ ];
335
+ function memorySeed(id) {
336
+ return `${memoryHeading(id)}
337
+
338
+ Index of this project's memory. Loaded only for sessions in this project.
339
+
340
+ Layout — nothing else goes at the project root:
341
+ - Lessons, decisions, gotchas → one file in \`memory/\`, plus one line here.
342
+ - Reference material (requirements, API notes, plans, maps) → \`docs/\`, plus one line in \`docs/README.md\`.
343
+ - Work → \`tasks/<ID>/task.md\`.
344
+ `;
345
+ }
346
+ function docsHeading(id) {
347
+ return `# ${id} — docs`;
348
+ }
349
+ function docsSeed(id) {
350
+ return `${docsHeading(id)}
351
+
352
+ Reference material for this project: requirements, API notes, plans, maps. One line per file
353
+ below. Status lives in the tasks, never here.
354
+ `;
355
+ }
356
+ // Creates whatever of the standard layout is missing and never overwrites a file. Returns the
357
+ // paths it created, relative to the project folder.
358
+ export async function ensureProjectLayout(projectId) {
359
+ const folder = oceanPath(projectDir(projectId));
360
+ const created = [];
361
+ for (const directory of ["tasks", "memory", "docs"])
362
+ if (await mkdir(path.join(folder, directory), { recursive: true }))
363
+ created.push(`${directory}/`);
364
+ const seeds = [
365
+ ["MEMORY.md", memorySeed(projectId)],
366
+ [path.join("docs", "README.md"), docsSeed(projectId)],
367
+ ];
368
+ for (const [file, text] of seeds) {
369
+ try {
370
+ await writeFile(path.join(folder, file), text, { flag: "wx" });
371
+ created.push(file.split(path.sep).join("/"));
372
+ }
373
+ catch (error) {
374
+ if (error.code !== "EEXIST")
375
+ throw error;
376
+ }
377
+ }
378
+ return created;
379
+ }
380
+ // Undoes a binding (a wrong auto-registration, a moved repo). Only the path goes; the project
381
+ // folder and its tasks stay, since deleting them is the owner's call.
382
+ export async function unbindProjectPath(targetPath) {
383
+ const resolvedPath = canonicalPath(targetPath);
384
+ return withProjectsLock(async () => {
385
+ const manifests = await listProjectManifests();
386
+ const legacy = await listLegacyBindings();
387
+ // The binding whose path contains the given one, longest first, so `unbind .` works from
388
+ // anywhere inside the repo.
389
+ const removed = combineBindings(manifests, legacy)
390
+ .filter((binding) => within(path.resolve(binding.path), resolvedPath))
391
+ .sort((a, b) => b.path.length - a.path.length)[0] ?? null;
392
+ if (!removed)
393
+ return { removed };
394
+ const boundPath = path.resolve(removed.path);
395
+ const owner = manifests.find((manifest) => manifest.paths.some((stored) => canonicalPath(stored) === boundPath));
396
+ if (owner)
397
+ await writeManifest({
398
+ ...owner,
399
+ paths: owner.paths.filter((stored) => canonicalPath(stored) !== boundPath),
400
+ });
401
+ // A legacy entry for the same path would otherwise take the binding back.
402
+ const keptLegacy = legacy.filter((binding) => canonicalPath(binding.path) !== boundPath);
403
+ await saveProjectBindings(cacheBindings(await listProjectManifests(), keptLegacy));
404
+ return { removed };
405
+ });
406
+ }
407
+ // Workspace text that may name a project folder by path: the records, the projects, the charter.
408
+ const REFERENCE_FILE = /\.(md|json|ya?ml|toml)$/i;
409
+ const REFERENCE_MAX_BYTES = 2_000_000;
410
+ // Rewrites `from` (a project folder relative to the Ocean root) to `to` in workspace text, as a
411
+ // whole path: `04-projects/ocean` never touches `04-projects/ocean-ielts` or `ocean.md`, but
412
+ // does match inside an absolute path and before a full stop. Dot folders are skipped. Returns
413
+ // the files that change, relative to the Ocean root; writes them only when `write`.
414
+ async function rewriteProjectReferences(from, to, write) {
415
+ const escaped = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
416
+ const pattern = new RegExp(`(?<![A-Za-z0-9_.-])${escaped}(?![A-Za-z0-9_-]|\\.[A-Za-z0-9])`, "g");
417
+ const changed = [];
418
+ const visit = async (dir) => {
419
+ let entries;
420
+ try {
421
+ entries = await readdir(dir, { withFileTypes: true });
422
+ }
423
+ catch {
424
+ return;
425
+ }
426
+ for (const entry of entries) {
427
+ if (entry.name.startsWith(".") || entry.name === "node_modules")
428
+ continue;
429
+ const file = path.join(dir, entry.name);
430
+ if (entry.isDirectory())
431
+ await visit(file);
432
+ else if (entry.isFile() &&
433
+ REFERENCE_FILE.test(entry.name) &&
434
+ statSync(file).size <= REFERENCE_MAX_BYTES) {
435
+ const text = await readFile(file, "utf8");
436
+ const next = text.replace(pattern, to);
437
+ if (next === text)
438
+ continue;
439
+ changed.push(path.relative(oceanRoot(), file).split(path.sep).join("/"));
440
+ if (write)
441
+ await atomicWrite(file, next);
442
+ }
443
+ }
444
+ };
445
+ for (const root of new Set([...BRAIN_RECORD_DIRS, PROJECTS_DIR, CHARTER_DIR]))
446
+ await visit(oceanPath(root));
447
+ return changed.sort();
448
+ }
449
+ // A project with no code yet, e.g. one grown from a note: a manifest with no paths, filed in its
450
+ // category folder with the usual tasks/, memory/ and docs/. `bind` adds its first path later.
451
+ // An id already registered is returned as it is, never overwritten.
452
+ export async function createProject(id, category, name = id) {
453
+ if (!isValidProjectId(id))
454
+ throw new Error(`Invalid project id '${id}': use lowercase letters, digits, dot, underscore or hyphen`);
455
+ if (!isProjectCategory(category))
456
+ throw new Error(`Unknown category '${category}': use ${PROJECT_CATEGORIES.join(", ")}`);
457
+ const created = await withProjectsLock(async () => {
458
+ const manifests = await listProjectManifests();
459
+ if (manifests.some((manifest) => manifest.id === id))
460
+ return false;
461
+ if (existsSync(oceanPath(projectDir(id))))
462
+ throw new ProjectFolderTaken(`${projectDir(id)} already exists; bind it explicitly`);
463
+ const manifest = await newManifest(id, {
464
+ name,
465
+ paths: [],
466
+ created: new Date().toISOString(),
467
+ autoRegistered: false,
468
+ }, manifests);
469
+ // The folder first, so projectDir resolves to the category folder the manifest goes into.
470
+ await mkdir(oceanPath(PROJECTS_DIR, category, id), { recursive: true });
471
+ await writeManifest(manifest);
472
+ await saveProjectBindings(cacheBindings(manifests.concat(manifest), await listLegacyBindings()));
473
+ return true;
474
+ });
475
+ if (created)
476
+ await ensureProjectLayout(id);
477
+ return { id, dir: projectDir(id), created };
478
+ }
479
+ // Files a project under a category folder (T-311) and rewrites the workspace paths that name
480
+ // its old folder. A dry run unless `write`: it reports the move and the files that would change.
481
+ export async function moveProject(id, category, write = false) {
482
+ if (!isValidProjectId(id))
483
+ throw new Error("Project ids must be lowercase letters, digits, . _ or -");
484
+ if (!isProjectCategory(category))
485
+ throw new Error(`category must be one of ${PROJECT_CATEGORIES.join(", ")}`);
486
+ return withProjectsLock(async () => {
487
+ const manifest = (await listProjectManifests()).find((candidate) => candidate.id === projectFolder(id));
488
+ if (!manifest)
489
+ throw new Error(`No project.json for '${id}'`);
490
+ const from = projectDir(manifest.id);
491
+ const to = path.posix.join(PROJECTS_DIR, category, manifest.id);
492
+ if (from === to)
493
+ return { id: manifest.id, from, to, moved: false, references: [] };
494
+ if (existsSync(oceanPath(to)))
495
+ throw new Error(`${to} already exists`);
496
+ if (!write)
497
+ return {
498
+ id: manifest.id,
499
+ from,
500
+ to,
501
+ moved: false,
502
+ references: await rewriteProjectReferences(from, to, false),
503
+ };
504
+ await mkdir(path.dirname(oceanPath(to)), { recursive: true });
505
+ await rename(oceanPath(from), oceanPath(to));
506
+ // A category folder left empty goes; a flat project's written category is dropped.
507
+ if (folderCategory(from))
508
+ await rmdir(path.dirname(oceanPath(from))).catch(() => { });
509
+ await writeManifest(manifest);
510
+ const references = await rewriteProjectReferences(from, to, true);
511
+ if ((await readFile(path.join(projectsRoot(), "registry.md"), "utf8").catch(() => "")).includes(INDEX_BEGIN))
512
+ await writeProjectIndexLocked();
513
+ return { id: manifest.id, from, to, moved: true, references };
514
+ });
515
+ }
516
+ // Renames a project folder (fixes a wrong auto-registered id). Refused while the project has
517
+ // tasks: their records carry the project id, and rewriting them belongs to phase 3.
518
+ export async function renameProject(from, to) {
519
+ if (!isValidProjectId(from) || !isValidProjectId(to))
520
+ throw new Error("Project ids must be lowercase letters, digits, . _ or -");
521
+ return withProjectsLock(async () => {
522
+ // The project keeps its category folder.
523
+ const source = oceanPath(projectDir(from));
524
+ const target = path.join(path.dirname(source), to);
525
+ const manifest = (await listProjectManifests()).find((candidate) => candidate.id === from);
526
+ if (!manifest)
527
+ throw new Error(`No project.json for '${from}'`);
528
+ if (existsSync(target) || listProjectDirs().some(({ id }) => id === to))
529
+ throw new Error(`project '${to}' already exists`);
530
+ const tasks = await readdir(path.join(source, "tasks")).catch(() => []);
531
+ if (tasks.some((entry) => !entry.startsWith(".")))
532
+ throw new Error(`'${from}' has tasks; renaming a project with tasks is not supported yet`);
533
+ await rename(source, target);
534
+ await writeManifest({
535
+ ...manifest,
536
+ id: to,
537
+ name: manifest.name === from ? to : manifest.name,
538
+ });
539
+ for (const [file, heading] of [
540
+ ["MEMORY.md", memoryHeading],
541
+ [path.join("docs", "README.md"), docsHeading],
542
+ ]) {
543
+ const index = path.join(target, file);
544
+ try {
545
+ const text = await readFile(index, "utf8");
546
+ if (text.startsWith(heading(from)))
547
+ await atomicWrite(index, `${heading(to)}${text.slice(heading(from).length)}`);
548
+ }
549
+ catch (error) {
550
+ if (error.code !== "ENOENT")
551
+ throw error;
552
+ }
553
+ }
554
+ if ((await readFile(path.join(projectsRoot(), "registry.md"), "utf8").catch(() => "")).includes(INDEX_BEGIN))
555
+ await writeProjectIndexLocked();
556
+ await saveProjectBindings(cacheBindings(await listProjectManifests(), await listLegacyBindings()));
557
+ return { from, to };
558
+ });
559
+ }
560
+ //# sourceMappingURL=project-register.js.map