@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
@@ -13,7 +13,7 @@ const ACK = /^[0-9a-f]{8}$/;
13
13
  export function contextAck(content) {
14
14
  return createHash("sha256").update(content).digest("hex").slice(0, 8);
15
15
  }
16
- export function contextAckFile() {
16
+ function contextAckFile() {
17
17
  return oceanPath(SYSTEM_DIR, "state", "mcp", "context-acks.json");
18
18
  }
19
19
  async function readIssued() {
@@ -0,0 +1,67 @@
1
+ import { normalizeText, tokenize } from "./text-tokens.js";
2
+ // Trigger words for policies and tool groups (T-339). The owner writes in Iraqi Arabic as often
3
+ // as in English, so a trigger is matched two ways: an English trigger by its stemmed words (all
4
+ // of them in the text, as profile triggers are), an Arabic one as a normalized substring, since
5
+ // Arabic attaches prefixes and suffixes to the word itself (دمج → ادمجه, الفرع → فرع).
6
+ // Deterministic, no model call.
7
+ const ARABIC = /[؀-ۿ]/;
8
+ // An Arabic trigger shorter than this would match inside unrelated words.
9
+ const ARABIC_MIN_CHARS = 3;
10
+ const MAX_TEXT = 2_000;
11
+ // Hamza forms, taa marbuta and alif maqsura folded; diacritics and tatweel dropped.
12
+ export function normalizeArabic(text) {
13
+ return text
14
+ .normalize("NFKC")
15
+ .replace(/[ً-ٰٟـ]/g, "")
16
+ .replace(/[أإآٱ]/g, "ا")
17
+ .replace(/ة/g, "ه")
18
+ .replace(/ى/g, "ي");
19
+ }
20
+ export function compileTriggers(triggers) {
21
+ const out = [];
22
+ for (const raw of triggers) {
23
+ if (typeof raw !== "string" || !raw.trim())
24
+ continue;
25
+ if (ARABIC.test(raw)) {
26
+ const phrase = normalizeText(normalizeArabic(raw));
27
+ if (phrase.replace(/ /g, "").length >= ARABIC_MIN_CHARS)
28
+ out.push({ raw, arabic: true, tokens: [phrase] });
29
+ continue;
30
+ }
31
+ const tokens = tokenize(raw);
32
+ if (tokens.length)
33
+ out.push({ raw, arabic: false, tokens });
34
+ }
35
+ return out;
36
+ }
37
+ export function prepareText(text) {
38
+ const head = text.slice(0, MAX_TEXT);
39
+ return {
40
+ words: new Set(tokenize(head)),
41
+ arabic: ARABIC.test(head)
42
+ ? ` ${normalizeText(normalizeArabic(head))} `
43
+ : "",
44
+ };
45
+ }
46
+ // The triggers that hit, by their raw spelling. A phrase (two words or more) is a strong hit.
47
+ export function triggerHits(compiled, text) {
48
+ const hits = [];
49
+ let score = 0;
50
+ for (const trigger of compiled) {
51
+ const hit = trigger.arabic
52
+ ? text.arabic.includes(trigger.tokens[0])
53
+ : trigger.tokens.every((token) => text.words.has(token));
54
+ if (!hit)
55
+ continue;
56
+ hits.push(trigger.raw);
57
+ const words = trigger.arabic
58
+ ? trigger.tokens[0].split(" ").length
59
+ : trigger.tokens.length;
60
+ score += words > 1 ? 2 : 1;
61
+ }
62
+ return { hits, score };
63
+ }
64
+ export function matchTriggers(triggers, text) {
65
+ return triggerHits(compileTriggers(triggers), prepareText(text));
66
+ }
67
+ //# sourceMappingURL=context-triggers.js.map
@@ -6,11 +6,11 @@ import { isValidProjectId, PROJECT_CATEGORY_FOLDERS, UNCATEGORIZED, } from "../d
6
6
  // The engine root is the `ocean` package root — skills/, templates/, dist/main.js. Core
7
7
  // cannot find it from its own location (in an installed tree the two packages can sit
8
8
  // anywhere), so the CLI publishes it under this global key before core loads
9
- // (packages/harness/src/engine-root.ts) — early enough for the module-level layout
9
+ // (packages/cli/src/engine-root.ts) — early enough for the module-level layout
10
10
  // constants below. Without it (tests, or core imported directly) it is the workspace
11
- // sibling packages/harness.
11
+ // sibling packages/cli.
12
12
  const ENGINE_ROOT_KEY = Symbol.for("ocean.engineRoot");
13
- const workspaceEngineRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "harness");
13
+ const workspaceEngineRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "cli");
14
14
  export function registerEngineRoot(directory) {
15
15
  globalThis[ENGINE_ROOT_KEY] =
16
16
  path.resolve(directory);
@@ -27,7 +27,7 @@ export function liveEngineEntry(root = engineRoot()) {
27
27
  return path.join(root, "dist", "main.js");
28
28
  }
29
29
  // The pnpm workspace root (kernel/), two directories above the engine root
30
- // (packages/harness → packages → kernel). Repo-wide tooling that lives outside any
30
+ // (packages/cli → packages → kernel). Repo-wide tooling that lives outside any
31
31
  // workspace package (e.g. scripts/ shared across packages) is anchored here, not on
32
32
  // engineRoot(), which is this package's own root.
33
33
  export function repoRoot() {
@@ -108,7 +108,7 @@ export const BRAIN_RECORD_DIRS = [
108
108
  ];
109
109
  // The workspace's own project. Callers use these helpers instead of a literal.
110
110
  export const WORKSPACE_PROJECT_ID = "ocean";
111
- export const WORKSPACE_PROJECT_CATEGORY = "personal";
111
+ const WORKSPACE_PROJECT_CATEGORY = "personal";
112
112
  export function sameProject(a, b) {
113
113
  return a === b || (isWorkspaceProject(a) && isWorkspaceProject(b));
114
114
  }
@@ -286,7 +286,7 @@ export function oceanRoot() {
286
286
  const root = oceanEnv("ROOT");
287
287
  return root ? path.resolve(root) : defaultOceanRoot();
288
288
  }
289
- // A dev checkout (~/ocean/kernel/packages/harness) serves the workspace three directories up,
289
+ // A dev checkout (~/ocean/kernel/packages/cli) serves the workspace three directories up,
290
290
  // once that holds one; a global npm install sits under the npm prefix, so it uses ~/ocean.
291
291
  function defaultOceanRoot() {
292
292
  const checkoutParent = path.resolve(engineRoot(), "..", "..", "..");
@@ -0,0 +1,232 @@
1
+ import { existsSync } from "node:fs";
2
+ import { mkdir, readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { isValidProjectId } from "../domain/context/project-id.js";
5
+ import { NO_PROJECT, } from "../domain/sessions/session-identity.js";
6
+ import { atomicWrite, registryFile, withFileLock } from "./fs-utils.js";
7
+ import { oceanPath, oceanRoot, projectDir, SYSTEM_DIR } from "./paths.js";
8
+ import { canonicalPath, listProjectManifests, matchProject, newManifest, portablePath, writeManifest, } from "./project-manifest.js";
9
+ function bindingsFile() {
10
+ return registryFile("project-bindings.json");
11
+ }
12
+ // Bindings recorded before T-256, read from the flat registry file. Kept as a fallback until
13
+ // `ocean project migrate --write` folds them into manifests, and rewritten as a cache after
14
+ // every manifest change for anything that still reads the file. Entries the cache holds for
15
+ // manifests are skipped, so a deleted project folder does not come back through it.
16
+ // A corrupt file throws: resolution fails closed (no project, no task references) and writers
17
+ // never overwrite what they cannot read. The session-start hook catches it on its own.
18
+ export async function listLegacyBindings() {
19
+ try {
20
+ const raw = await readFile(bindingsFile(), "utf8");
21
+ const parsed = JSON.parse(raw);
22
+ if (!Array.isArray(parsed?.bindings ?? []))
23
+ throw new Error(`${bindingsFile()}: bindings is not a list`);
24
+ return (parsed.bindings ?? []).filter((binding) => !binding.manifest);
25
+ }
26
+ catch (error) {
27
+ if (error.code === "ENOENT")
28
+ return [];
29
+ throw error;
30
+ }
31
+ }
32
+ // gitRoot is left null here: resolution matches on paths, and walking up from every path of
33
+ // every project on each session start would cost a filesystem walk per path for nothing.
34
+ function manifestBindings(manifests) {
35
+ return manifests.flatMap((manifest) => manifest.paths.map((stored) => ({
36
+ id: manifest.id,
37
+ name: manifest.name,
38
+ path: canonicalPath(stored),
39
+ gitRoot: null,
40
+ boundAt: manifest.created,
41
+ manifest: true,
42
+ })));
43
+ }
44
+ export function combineBindings(manifests, legacy) {
45
+ const fromManifests = manifestBindings(manifests);
46
+ const claimed = new Set(fromManifests.map((binding) => binding.path));
47
+ return [
48
+ ...fromManifests,
49
+ ...legacy
50
+ .map((binding) => ({ ...binding, path: canonicalPath(binding.path) }))
51
+ .filter((binding) => !claimed.has(binding.path)),
52
+ ];
53
+ }
54
+ // The cache keeps every legacy entry, including ones a manifest now claims, so deleting that
55
+ // manifest later never loses the old binding.
56
+ export function cacheBindings(manifests, legacy) {
57
+ return [...manifestBindings(manifests), ...legacy];
58
+ }
59
+ export async function saveProjectBindings(bindings) {
60
+ const file = bindingsFile();
61
+ await mkdir(path.dirname(file), { recursive: true });
62
+ await atomicWrite(file, `${JSON.stringify({ version: 1, bindings }, null, 2)}\n`);
63
+ }
64
+ // One lock for every manifest/cache write: bindings are checked across all projects (a path
65
+ // may belong to one project only), so per-project locks would let two writers both pass.
66
+ export function withProjectsLock(run) {
67
+ return withFileLock(bindingsFile(), run);
68
+ }
69
+ // One-time fold of the legacy bindings file into manifests. Generic on purpose (the kernel is
70
+ // public): a binding becomes a path of `04-projects/<id>/project.json` only when that project
71
+ // folder exists; any other binding is reported and left alone, never turned into a new folder.
72
+ export async function migrateProjectBindings(write) {
73
+ return withProjectsLock(async () => {
74
+ const legacy = await listLegacyBindings();
75
+ const manifests = await listProjectManifests();
76
+ const claimed = new Set(manifestBindings(manifests).map((binding) => binding.path));
77
+ const result = {
78
+ migrated: [],
79
+ orphaned: [],
80
+ written: write,
81
+ };
82
+ const updates = new Map();
83
+ for (const binding of legacy) {
84
+ const resolved = canonicalPath(binding.path);
85
+ if (claimed.has(resolved))
86
+ continue;
87
+ if (!isValidProjectId(binding.id)) {
88
+ result.orphaned.push({
89
+ id: binding.id,
90
+ path: resolved,
91
+ reason: "id is not a valid project folder name; bind it explicitly",
92
+ });
93
+ continue;
94
+ }
95
+ const folder = oceanPath(projectDir(binding.id));
96
+ if (!existsSync(folder)) {
97
+ result.orphaned.push({
98
+ id: binding.id,
99
+ path: resolved,
100
+ reason: `no project folder ${path.relative(oceanRoot(), folder)}; bind it explicitly`,
101
+ });
102
+ continue;
103
+ }
104
+ const base = updates.get(binding.id) ??
105
+ manifests.find((manifest) => manifest.id === binding.id) ??
106
+ (await newManifest(binding.id, {
107
+ name: binding.name || binding.id,
108
+ paths: [],
109
+ created: binding.boundAt || new Date().toISOString(),
110
+ autoRegistered: false,
111
+ }, [...manifests, ...updates.values()]));
112
+ updates.set(binding.id, {
113
+ ...base,
114
+ paths: [...base.paths, portablePath(resolved)],
115
+ });
116
+ claimed.add(resolved);
117
+ result.migrated.push({ id: binding.id, path: resolved });
118
+ }
119
+ if (write && updates.size) {
120
+ for (const manifest of updates.values())
121
+ await writeManifest(manifest);
122
+ await saveProjectBindings(cacheBindings(await listProjectManifests(), legacy));
123
+ }
124
+ return result;
125
+ });
126
+ }
127
+ // The names of the owner's Claude projects this machine has seen, as the always-on service last
128
+ // wrote them (T-307): reading Claude Desktop's caches takes too long for a tool call.
129
+ export function claudeProjectsFile() {
130
+ return oceanPath(SYSTEM_DIR, "state", "clients", "claude-projects.json");
131
+ }
132
+ export async function readClaudeProjects() {
133
+ try {
134
+ const parsed = JSON.parse(await readFile(claudeProjectsFile(), "utf8"));
135
+ return Array.isArray(parsed.names)
136
+ ? parsed.names.filter((name) => typeof name === "string")
137
+ : [];
138
+ }
139
+ catch {
140
+ return [];
141
+ }
142
+ }
143
+ function claudeConversationsFile() {
144
+ return oceanPath(SYSTEM_DIR, "state", "clients", "claude-conversations.json");
145
+ }
146
+ async function readJsonMap(file) {
147
+ try {
148
+ const parsed = JSON.parse(await readFile(file, "utf8"));
149
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
150
+ ? parsed
151
+ : {};
152
+ }
153
+ catch {
154
+ return {};
155
+ }
156
+ }
157
+ async function writeOwnerJson(file, value) {
158
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
159
+ await atomicWrite(file, `${JSON.stringify(value, null, 2)}\n`, 0o600);
160
+ }
161
+ export async function readClaudeConversations() {
162
+ const parsed = await readJsonMap(claudeConversationsFile());
163
+ const conversations = parsed.conversations;
164
+ return conversations && typeof conversations === "object"
165
+ ? conversations
166
+ : {};
167
+ }
168
+ export async function mergeClaudeConversations(found) {
169
+ const file = claudeConversationsFile();
170
+ return withFileLock(file, async () => {
171
+ const conversations = { ...(await readClaudeConversations()) };
172
+ for (const [uuid, seen] of Object.entries(found)) {
173
+ const known = conversations[uuid];
174
+ conversations[uuid] = {
175
+ title: seen.title || known?.title || "",
176
+ ...((seen.projectName ?? known?.projectName)
177
+ ? { projectName: seen.projectName ?? known?.projectName }
178
+ : {}),
179
+ ...((seen.updated ?? known?.updated)
180
+ ? { updated: seen.updated ?? known?.updated }
181
+ : {}),
182
+ };
183
+ }
184
+ await writeOwnerJson(file, {
185
+ at: new Date().toISOString(),
186
+ conversations,
187
+ });
188
+ return Object.keys(conversations).length;
189
+ });
190
+ }
191
+ // A Desktop chat bound to a project by hand (`ocean_project_link`, `capture --project`): the
192
+ // explicit evidence, ahead of the Claude project the chat sits in.
193
+ function conversationProjectsFile() {
194
+ return oceanPath(SYSTEM_DIR, "state", "clients", "conversation-projects.json");
195
+ }
196
+ export async function bindConversation(uuid, projectId) {
197
+ if (!uuid)
198
+ throw new Error("a conversation to bind is required");
199
+ const manifests = await listProjectManifests();
200
+ if (!manifests.some((manifest) => manifest.id === projectId))
201
+ throw new Error(`no project '${projectId}'`);
202
+ const file = conversationProjectsFile();
203
+ await withFileLock(file, async () => {
204
+ const bindings = await readJsonMap(file);
205
+ await writeOwnerJson(file, { ...bindings, [uuid]: projectId });
206
+ });
207
+ }
208
+ // The project of one Claude conversation, decided once (T-333): a hand binding, else the Claude
209
+ // project it sits in when that name matches a project, else none. Never a model guess.
210
+ export async function conversationProjectDecision(uuid) {
211
+ const seen = (await readClaudeConversations())[uuid];
212
+ const facts = {
213
+ ...(seen?.title ? { title: seen.title } : {}),
214
+ ...(seen?.projectName ? { claudeProject: seen.projectName } : {}),
215
+ };
216
+ const manifests = await listProjectManifests();
217
+ const bound = (await readJsonMap(conversationProjectsFile()))[uuid];
218
+ if (bound && manifests.some((manifest) => manifest.id === bound))
219
+ return { projectId: bound, how: "explicit", confidence: "high", ...facts };
220
+ const named = seen?.projectName
221
+ ? matchProject(manifests, seen.projectName)
222
+ : undefined;
223
+ if (named)
224
+ return {
225
+ projectId: named,
226
+ how: "claude-project",
227
+ confidence: "high",
228
+ ...facts,
229
+ };
230
+ return { ...NO_PROJECT, ...facts };
231
+ }
232
+ //# sourceMappingURL=project-legacy.js.map
@@ -0,0 +1,308 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import { mkdir, readdir, readFile } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { isProjectCategory, isValidProjectId, PROJECT_CATEGORIES, PROJECT_CATEGORY_FOLDERS, UNCATEGORIZED, } from "../domain/context/project-id.js";
6
+ import { derivePrefix, isValidPrefix, LEGACY_PREFIX, } from "../domain/task-id.js";
7
+ import { atomicWrite } from "./fs-utils.js";
8
+ import { isWorkspaceProject, listProjectDirs, oceanPath, oceanRoot, PROJECTS_DIR, projectDir, projectFolder, } from "./paths.js";
9
+ import { nearName, normalizeName } from "./project-names.js";
10
+ export { PROJECT_CATEGORIES, UNCATEGORIZED };
11
+ const MAX_PROJECT_RULES = 10;
12
+ const MAX_PROJECT_RULE_BYTES = 200;
13
+ const MAX_PROJECT_VERIFY = 5;
14
+ const MAX_PROJECT_VERIFY_BYTES = 300;
15
+ const MAX_PROJECT_TAGS = 10;
16
+ const MAX_PROJECT_FORMER_PATHS = 20;
17
+ export const MAX_PROJECT_ALIASES = 20;
18
+ const MAX_PROJECT_PROFILES = 5;
19
+ const MANIFEST_FILE = "project.json";
20
+ export function expandHome(value) {
21
+ if (value === "~")
22
+ return os.homedir();
23
+ if (value.startsWith("~/") || value.startsWith("~\\"))
24
+ return path.join(os.homedir(), value.slice(2));
25
+ return value;
26
+ }
27
+ export function portablePath(value) {
28
+ const home = os.homedir();
29
+ const resolved = path.resolve(value);
30
+ if (resolved === home)
31
+ return "~";
32
+ if (resolved.startsWith(`${home}${path.sep}`))
33
+ return `~/${path.relative(home, resolved).split(path.sep).join("/")}`;
34
+ return resolved;
35
+ }
36
+ // One spelling per directory: symlinks resolved (macOS /var is /private/var, and process.cwd()
37
+ // returns the resolved form), so a bound path and the cwd of a session inside it compare equal.
38
+ // A path that does not exist (a repo not cloned on this machine yet) is kept as written.
39
+ export function canonicalPath(value) {
40
+ const resolved = path.resolve(expandHome(value));
41
+ try {
42
+ return realpathSync(resolved);
43
+ }
44
+ catch {
45
+ return resolved;
46
+ }
47
+ }
48
+ export function projectsRoot() {
49
+ return oceanPath(PROJECTS_DIR);
50
+ }
51
+ // The category folder a project folder sits in, or undefined while it is flat.
52
+ export function folderCategory(dir) {
53
+ const [first, second] = path.posix.relative(PROJECTS_DIR, dir).split("/");
54
+ return second && PROJECT_CATEGORY_FOLDERS.includes(first) ? first : undefined;
55
+ }
56
+ // Control characters (tab aside) and Unicode line breaks: a rule or command is one plain line.
57
+ const LINE_BREAKING = /[\p{Cc}\u2028\u2029]/u;
58
+ export function hasControlCharacters(value) {
59
+ return LINE_BREAKING.test(value.replace(/\t/g, " "));
60
+ }
61
+ function lineList(field, value, maxEntries, maxBytes) {
62
+ if (value === undefined)
63
+ return [];
64
+ if (!Array.isArray(value))
65
+ throw new Error(`${field} must be a list of strings`);
66
+ if (value.length > maxEntries)
67
+ throw new Error(`${field} holds at most ${maxEntries} entries`);
68
+ return value.map((entry, index) => {
69
+ if (typeof entry !== "string" || !entry.trim())
70
+ throw new Error(`${field}[${index}] must be a non-empty string`);
71
+ const line = entry.trim();
72
+ if (hasControlCharacters(line))
73
+ throw new Error(`${field}[${index}] must be a single line without control characters`);
74
+ if (Buffer.byteLength(line, "utf8") > maxBytes)
75
+ throw new Error(`${field}[${index}] exceeds ${maxBytes} bytes`);
76
+ return line;
77
+ });
78
+ }
79
+ // The validated lists, or an Error naming the field.
80
+ export function projectRules(manifest) {
81
+ return lineList("rules", manifest.rules, MAX_PROJECT_RULES, MAX_PROJECT_RULE_BYTES);
82
+ }
83
+ export function projectVerify(manifest) {
84
+ return lineList("verify", manifest.verify, MAX_PROJECT_VERIFY, MAX_PROJECT_VERIFY_BYTES);
85
+ }
86
+ export function projectTags(manifest) {
87
+ return lineList("tags", manifest.tags, MAX_PROJECT_TAGS, 40).map((tag) => tag.toLowerCase());
88
+ }
89
+ // The category, undefined when none is set, or an Error naming the allowed values.
90
+ export function projectCategory(manifest) {
91
+ if (manifest.category === undefined)
92
+ return undefined;
93
+ if (!isProjectCategory(manifest.category))
94
+ throw new Error(`category must be one of ${PROJECT_CATEGORIES.join(", ")}`);
95
+ return manifest.category;
96
+ }
97
+ export function projectFormerPaths(manifest) {
98
+ return lineList("formerPaths", manifest.formerPaths, MAX_PROJECT_FORMER_PATHS, 500);
99
+ }
100
+ export function projectAliases(manifest) {
101
+ return lineList("aliases", manifest.aliases, MAX_PROJECT_ALIASES, 200);
102
+ }
103
+ // Read best-effort: a typo here must never unbind the project or break its session start.
104
+ export function projectProfiles(manifest) {
105
+ try {
106
+ return lineList("profiles", manifest.profiles, MAX_PROJECT_PROFILES, 64);
107
+ }
108
+ catch {
109
+ return [];
110
+ }
111
+ }
112
+ // Matching reads aliases best-effort: a typo in one manifest's aliases never unbinds it.
113
+ function aliasesOrNone(manifest) {
114
+ try {
115
+ return projectAliases(manifest);
116
+ }
117
+ catch {
118
+ return [];
119
+ }
120
+ }
121
+ // `folder` is the project folder's name, `category` the category folder it sits in, if any.
122
+ function parseManifest(folder, raw, category) {
123
+ const parsed = JSON.parse(raw);
124
+ if (!parsed ||
125
+ typeof parsed !== "object" ||
126
+ !Array.isArray(parsed.paths) ||
127
+ parsed.paths.some((entry) => typeof entry !== "string" || !entry.trim()))
128
+ throw new Error("paths must be a list of non-empty strings");
129
+ if (parsed.prefix !== undefined &&
130
+ (typeof parsed.prefix !== "string" ||
131
+ parsed.prefix === LEGACY_PREFIX ||
132
+ !isValidPrefix(parsed.prefix)))
133
+ throw new Error(`prefix '${String(parsed.prefix)}' is not a valid task prefix`);
134
+ if (parsed.nextTask !== undefined &&
135
+ (!Number.isInteger(parsed.nextTask) || parsed.nextTask < 1))
136
+ throw new Error("nextTask must be a positive integer");
137
+ // The folder name is the id; a manifest cannot claim another project's identity.
138
+ return {
139
+ id: folder,
140
+ name: typeof parsed.name === "string" && parsed.name ? parsed.name : folder,
141
+ paths: parsed.paths,
142
+ created: typeof parsed.created === "string" ? parsed.created : "",
143
+ autoRegistered: parsed.autoRegistered === true,
144
+ ...(parsed.prefix !== undefined ? { prefix: parsed.prefix } : {}),
145
+ ...(parsed.nextTask !== undefined ? { nextTask: parsed.nextTask } : {}),
146
+ ...(parsed.rules !== undefined ? { rules: parsed.rules } : {}),
147
+ ...(parsed.verify !== undefined ? { verify: parsed.verify } : {}),
148
+ ...(parsed.tags !== undefined ? { tags: parsed.tags } : {}),
149
+ ...(parsed.formerPaths !== undefined
150
+ ? { formerPaths: parsed.formerPaths }
151
+ : {}),
152
+ ...(parsed.aliases !== undefined ? { aliases: parsed.aliases } : {}),
153
+ ...(parsed.profiles !== undefined ? { profiles: parsed.profiles } : {}),
154
+ ...(category === UNCATEGORIZED
155
+ ? {}
156
+ : category !== undefined
157
+ ? { category }
158
+ : parsed.category !== undefined
159
+ ? { category: parsed.category }
160
+ : {}),
161
+ };
162
+ }
163
+ // A broken project.json takes only its own project out of resolution: resolveProject runs in
164
+ // every session's start hook, so one bad file must not break every project. The errors are
165
+ // returned for `ocean project list` to report.
166
+ export async function scanProjectManifests() {
167
+ const scan = { manifests: [], errors: [] };
168
+ const seen = new Set();
169
+ for (const { id, category, dir } of listProjectDirs()) {
170
+ const file = oceanPath(dir, MANIFEST_FILE);
171
+ // One id with project.json in two folders: the first, where projectDir looks first, is the
172
+ // project. A folder without project.json claims nothing.
173
+ if (seen.has(id)) {
174
+ if (existsSync(file))
175
+ scan.errors.push({
176
+ file,
177
+ error: `project id '${id}' is already used by another category folder`,
178
+ });
179
+ continue;
180
+ }
181
+ try {
182
+ scan.manifests.push(parseManifest(id, await readFile(file, "utf8"), category));
183
+ seen.add(id);
184
+ }
185
+ catch (error) {
186
+ if (error.code === "ENOENT")
187
+ continue;
188
+ seen.add(id);
189
+ scan.errors.push({
190
+ file,
191
+ error: error instanceof Error ? error.message : String(error),
192
+ });
193
+ }
194
+ }
195
+ return scan;
196
+ }
197
+ // One project's manifest, or null when it has none. A manifest that does not parse throws:
198
+ // callers that must hold a project's rules fail closed instead of dropping them.
199
+ export async function readProjectManifest(id, root = oceanRoot()) {
200
+ if (!isValidProjectId(id))
201
+ return null;
202
+ const dir = projectDir(id, root);
203
+ try {
204
+ return parseManifest(projectFolder(id), await readFile(path.join(root, dir, MANIFEST_FILE), "utf8"), folderCategory(dir));
205
+ }
206
+ catch (error) {
207
+ if (error.code === "ENOENT")
208
+ return null;
209
+ throw error;
210
+ }
211
+ }
212
+ export async function listProjectManifests() {
213
+ return (await scanProjectManifests()).manifests;
214
+ }
215
+ export async function writeManifest(manifest) {
216
+ const dir = projectDir(manifest.id);
217
+ const file = oceanPath(dir, MANIFEST_FILE);
218
+ // In a category folder the folder is the category; only a flat project keeps the field.
219
+ const { category, ...rest } = manifest;
220
+ const record = folderCategory(dir) === undefined && category !== undefined
221
+ ? manifest
222
+ : rest;
223
+ await mkdir(path.dirname(file), { recursive: true });
224
+ await atomicWrite(file, `${JSON.stringify(record, null, 2)}\n`);
225
+ }
226
+ // A manifest for a project seen for the first time. A folder with no tasks gets its own task
227
+ // prefix and counter; one that already holds tasks stays on the legacy T namespace until
228
+ // `ocean tasks renumber`. The workspace project is always T.
229
+ export async function newManifest(id, fields, others) {
230
+ const manifest = { id, ...fields };
231
+ if (isWorkspaceProject(id))
232
+ return manifest;
233
+ const tasks = await readdir(oceanPath(projectDir(id), "tasks")).catch(() => []);
234
+ if (tasks.some((entry) => !entry.startsWith(".")))
235
+ return manifest;
236
+ const taken = others.flatMap((other) => (other.prefix ? [other.prefix] : []));
237
+ return { ...manifest, prefix: derivePrefix(id, taken), nextTask: 1 };
238
+ }
239
+ // The existing project a client names (T-307, T-332), first hit wins: its id, its name in any
240
+ // case (`LetSpeak` is `letspeak`), one of its aliases, then any of those normalized
241
+ // (`Jira - KarWatt` is `jira_karwatt`), then the name's slug. A normalized form two projects
242
+ // share binds neither. Never a guess beyond that: near names only suggest (suggestProjects).
243
+ export function matchProject(manifests, ref) {
244
+ const name = ref.trim().toLowerCase();
245
+ if (!name)
246
+ return undefined;
247
+ const byId = manifests.find((manifest) => manifest.id === ref || manifest.id === ref.trim());
248
+ if (byId)
249
+ return byId.id;
250
+ const byName = manifests.find((manifest) => manifest.name.trim().toLowerCase() === name);
251
+ if (byName)
252
+ return byName.id;
253
+ const byAlias = manifests.find((manifest) => aliasesOrNone(manifest).some((alias) => alias.toLowerCase() === name));
254
+ if (byAlias)
255
+ return byAlias.id;
256
+ const normalized = normalizeName(ref);
257
+ const byNormalized = [
258
+ ...new Set(manifests
259
+ .filter((manifest) => [manifest.id, manifest.name, ...aliasesOrNone(manifest)].some((known) => normalizeName(known) === normalized))
260
+ .map((manifest) => manifest.id)),
261
+ ];
262
+ if (byNormalized.length === 1)
263
+ return byNormalized[0];
264
+ if (byNormalized.length > 1)
265
+ return undefined;
266
+ const slug = projectSlug(ref);
267
+ return slug
268
+ ? manifests.find((manifest) => manifest.id === slug)?.id
269
+ : undefined;
270
+ }
271
+ // The projects a name probably means, when matchProject binds none. Never bound on their own:
272
+ // a warning shows them beside the `ocean project link` that would.
273
+ export function suggestProjects(manifests, ref) {
274
+ const normalized = normalizeName(ref);
275
+ const suggestions = [];
276
+ for (const manifest of manifests) {
277
+ const near = [manifest.id, manifest.name, ...aliasesOrNone(manifest)].find((known) => nearName(known, ref));
278
+ if (near) {
279
+ suggestions.push({ id: manifest.id, via: "near-name", name: near });
280
+ continue;
281
+ }
282
+ let former = [];
283
+ try {
284
+ former = projectFormerPaths(manifest);
285
+ }
286
+ catch {
287
+ /* a bad formerPaths only loses its suggestions */
288
+ }
289
+ const folder = [...manifest.paths, ...former]
290
+ .map((stored) => path.basename(stored))
291
+ .find((base) => normalized && normalizeName(base) === normalized);
292
+ if (folder)
293
+ suggestions.push({ id: manifest.id, via: "path", name: folder });
294
+ }
295
+ return suggestions;
296
+ }
297
+ // A run of separators is one separator (T-332): `Jira - KarWatt` is `jira-karwatt`, never
298
+ // `jira---karwatt`. A run holding a hyphen becomes a hyphen; any other run keeps its first.
299
+ export function projectSlug(name) {
300
+ return name
301
+ .toLowerCase()
302
+ .replace(/[^a-z0-9._-]+/g, "-")
303
+ .replace(/[-._]{2,}/g, (run) => (run.includes("-") ? "-" : run[0]))
304
+ .replace(/^[^a-z0-9]+/, "")
305
+ .slice(0, 64)
306
+ .replace(/[-._]+$/, "");
307
+ }
308
+ //# sourceMappingURL=project-manifest.js.map