@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
@@ -1,9 +1,11 @@
1
+ import { existsSync } from "node:fs";
1
2
  import { mkdir, open, readdir, readFile } from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import zlib from "node:zlib";
4
5
  import { proposeImported, } from "@ocean/brain/memory/memory-harvest.js";
5
6
  import { atomicWrite } from "@ocean/core/shared/fs-utils.js";
6
- import { claudeProjectsFile } from "@ocean/core/shared/project-resolution.js";
7
+ import { claudeProjectsFile, mergeClaudeConversations, readClaudeProjects, } from "@ocean/core/shared/project-legacy.js";
8
+ import { linkClaudeProjectName, } from "@ocean/core/shared/project-register.js";
7
9
  import { serverHistoryDir } from "./history-index.js";
8
10
  // claude.ai and ChatGPT keep their conversations, projects and memory on their servers (T-305).
9
11
  // Claude Desktop and the browsers keep what they fetched of those pages in a Chromium HTTP cache;
@@ -118,32 +120,113 @@ const iso = (value) => {
118
120
  };
119
121
  // Project uuid → name, from the claude.ai project responses Claude Desktop and the browsers
120
122
  // cached.
121
- function projectNames(entries) {
123
+ function projectNames(entries, keep = () => true) {
122
124
  const names = new Map();
123
125
  for (const { url, json } of entries) {
124
126
  if (/\/projects(_v2)?(\?|$)/.test(url))
125
127
  for (const project of list(json))
126
- if (text(project.uuid))
128
+ if (text(project.uuid) && keep(project))
127
129
  names.set(text(project.uuid), text(project.name));
128
130
  const one = new RegExp(`/projects/(${UUID})(\\?|$)`).exec(url)?.[1];
129
- if (one && text(object(json).name))
131
+ if (one && text(object(json).name) && keep(object(json)))
130
132
  names.set(one, text(object(json).name));
131
133
  }
132
134
  return names;
133
135
  }
136
+ // A project the owner can delete is his own; one shared with him in a team organization (view
137
+ // only) is not his to rename or to file under, so its name is not one of his. A response without
138
+ // permissions says nothing either way, and the project is kept.
139
+ function isOwned(project) {
140
+ const permissions = project.permissions;
141
+ return (!Array.isArray(permissions) || permissions.includes("chat_project:delete"));
142
+ }
143
+ async function claudeEntries(home) {
144
+ return (await readCaches(home)).filter((entry) => entry.url.includes("claude.ai/"));
145
+ }
134
146
  // The names of the owner's Claude projects that this machine has seen (T-307): what lets Ocean
135
147
  // tell a real Claude project from a topic a client calls a project. Read-only, from the caches.
136
148
  export async function claudeProjectNames(home) {
137
- const entries = (await readCaches(home)).filter((entry) => entry.url.includes("claude.ai/"));
138
- return [...new Set(projectNames(entries).values())].filter(Boolean);
149
+ return namesIn(await claudeEntries(home));
150
+ }
151
+ // An account whose newest list is this much older than the newest list of any account is one
152
+ // this machine no longer uses: its cached names are not the owner's projects today.
153
+ const STALE_ACCOUNT_MS = 30 * 24 * 60 * 60 * 1000;
154
+ const PROJECT_LIST = /\/projects(_v2)?(\?|$)/;
155
+ // A list of every project the account has: not a lookup by uuid, not starred, not filtered by
156
+ // creator, type or search, not the archive, and not a page cut short by its limit.
157
+ function isFullList({ url, json }) {
158
+ const query = new URL(url, "https://claude.ai").searchParams;
159
+ if (["uuids", "starred", "filter", "creator_filter", "type"].some((key) => query.has(key)))
160
+ return false;
161
+ if (query.get("is_archived") === "true" || query.get("searchQuery"))
162
+ return false;
163
+ const limit = Number(query.get("limit"));
164
+ return !(limit && list(json).length >= limit);
139
165
  }
140
- // Writes those names (names only, owner-only file) where a tool call can read them at once.
166
+ // The names of the projects the owner has now. A cache keeps every response it was ever sent, so
167
+ // a project since deleted or renamed is still named by an older one (T-330): for each account the
168
+ // newest full list is what it has, plus any project named in a response newer than that list. An
169
+ // account with no full list keeps every name it was sent; an account not seen for a month is
170
+ // dropped; a project someone else made and only shared with the owner is left out.
171
+ function currentProjectNames(entries) {
172
+ const byOrg = new Map();
173
+ for (const entry of entries) {
174
+ if (!entry.url.includes("/projects"))
175
+ continue;
176
+ const org = /\/organizations\/([^/?]+)/.exec(entry.url)?.[1] ?? "";
177
+ byOrg.set(org, [...(byOrg.get(org) ?? []), entry]);
178
+ }
179
+ const newestList = (items) => Math.max(0, ...items
180
+ .filter((each) => PROJECT_LIST.test(each.url))
181
+ .map((each) => each.at));
182
+ const latest = Math.max(0, ...[...byOrg.values()].map(newestList));
183
+ const names = [];
184
+ for (const items of byOrg.values()) {
185
+ const newest = newestList(items);
186
+ if (newest && latest - newest > STALE_ACCOUNT_MS)
187
+ continue;
188
+ const full = items
189
+ .filter((each) => PROJECT_LIST.test(each.url) && isFullList(each))
190
+ .sort((a, b) => b.at - a.at)[0];
191
+ const kept = full
192
+ ? items.filter((each) => each === full || each.at > full.at)
193
+ : items;
194
+ names.push(...projectNames(kept, isOwned).values());
195
+ }
196
+ return [...new Set(names)].filter(Boolean);
197
+ }
198
+ function namesIn(entries) {
199
+ return currentProjectNames(entries);
200
+ }
201
+ // Writes those names (names only, owner-only file) where a tool call can read them at once, and
202
+ // each conversation's title and Claude project (T-333). A name not in the last list is seen for
203
+ // the first time and linked to its project; the very first list only records, so a new machine
204
+ // never registers every Claude project it finds at once.
141
205
  export async function refreshClaudeProjects(home) {
142
- const names = await claudeProjectNames(home);
206
+ const entries = await claudeEntries(home);
207
+ const names = namesIn(entries);
208
+ const previous = existsSync(claudeProjectsFile())
209
+ ? new Set(await readClaudeProjects())
210
+ : undefined;
143
211
  const file = claudeProjectsFile();
144
212
  await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
145
213
  await atomicWrite(file, `${JSON.stringify({ at: new Date().toISOString(), names }, null, 2)}\n`, 0o600);
146
- return names.length;
214
+ const found = {};
215
+ for (const row of claudeAi(entries).conversations.values())
216
+ found[row.id] = {
217
+ title: row.title,
218
+ ...(row.projectName ? { projectName: row.projectName } : {}),
219
+ ...(row.updated ? { updated: row.updated } : {}),
220
+ };
221
+ const conversations = await mergeClaudeConversations(found);
222
+ const linked = [];
223
+ // A name that cannot become a project (its folder is taken) is left to `ocean project doctor`.
224
+ for (const name of previous ? names.filter((n) => !previous.has(n)) : []) {
225
+ const link = await linkClaudeProjectName(name).catch(() => undefined);
226
+ if (link)
227
+ linked.push(link);
228
+ }
229
+ return { names: names.length, conversations, linked };
147
230
  }
148
231
  function claudeAi(entries) {
149
232
  const names = projectNames(entries);
@@ -2,8 +2,8 @@ import { mkdir, open, readFile, rename, unlink, writeFile, } from "node:fs/promi
2
2
  import path from "node:path";
3
3
  import { assertGuard, guardProblems, } from "@ocean/core/domain/runs/loop-guard.js";
4
4
  import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
5
- import { afterGuardedRun, emptyUsage, writeEscalation, } from "@ocean/loop/loops/guard-runtime.js";
6
- import { runAgent } from "@ocean/loop/runs/run-agent.js";
5
+ import { afterGuardedRun, emptyUsage, writeEscalation, } from "@ocean/work/runs/guard-runtime.js";
6
+ import { runAgent } from "@ocean/work/runs/run-agent.js";
7
7
  const file = () => oceanPath(SYSTEM_DIR, "schedules.json");
8
8
  const running = new Set();
9
9
  export async function listSchedules() {
@@ -0,0 +1,55 @@
1
+ // What a Claude model call costs at API list price (T-340), per million tokens. A subscription
2
+ // is not billed this way; the figure is how heavy the use is, in one comparable unit. Prices
3
+ // change: update the table and PRICES_AS_OF together, from the provider's price page.
4
+ export const PRICES_AS_OF = "2026-11-29";
5
+ const price = (input, output, cacheRead) => ({
6
+ input,
7
+ output,
8
+ cacheRead,
9
+ cacheWrite5m: input * 1.25,
10
+ cacheWrite1h: input * 2,
11
+ });
12
+ // Most specific first: the first prefix a model id starts with wins. A bare alias
13
+ // ("sonnet", as the extraction log records it) means the current model of that line.
14
+ const TABLE = [
15
+ ["claude-fable-5-2", price(8, 40, 0.2)],
16
+ ["claude-mythos-5-2", price(8, 40, 0.2)],
17
+ ["claude-fable-5-1", price(10, 50, 0.25)],
18
+ ["claude-mythos-5-1", price(10, 50, 0.25)],
19
+ ["claude-fable", price(10, 50, 1)],
20
+ ["claude-mythos", price(10, 50, 1)],
21
+ ["claude-opus-5-5", price(4, 20, 0.2)],
22
+ ["claude-opus-5", price(5, 25, 0.5)],
23
+ ["claude-opus-4-8", price(5, 25, 0.5)],
24
+ ["claude-opus-4-7", price(5, 25, 0.5)],
25
+ ["claude-opus-4-6", price(5, 25, 0.5)],
26
+ ["claude-opus-4-5", price(5, 25, 0.5)],
27
+ ["claude-opus", price(15, 75, 1.5)],
28
+ ["claude-sonnet-5-5", price(2, 10, 0.1)],
29
+ ["claude-sonnet-5", price(2, 10, 0.2)],
30
+ ["claude-sonnet", price(3, 15, 0.3)],
31
+ ["claude-haiku-5-5", price(0.1, 0.5, 0.01)],
32
+ ["claude-haiku-4-5", price(1, 5, 0.1)],
33
+ ["claude-haiku", price(0.8, 4, 0.08)],
34
+ ["fable", price(8, 40, 0.2)],
35
+ ["opus", price(4, 20, 0.2)],
36
+ ["sonnet", price(2, 10, 0.1)],
37
+ ["haiku", price(0.1, 0.5, 0.01)],
38
+ ];
39
+ // The price for a model id, or null for one the table does not know (counted, not priced).
40
+ export function priceFor(model) {
41
+ const id = model.toLowerCase();
42
+ for (const [prefix, entry] of TABLE)
43
+ if (id.startsWith(prefix))
44
+ return entry;
45
+ return null;
46
+ }
47
+ export function costOf(usage, rate) {
48
+ return ((usage.input * rate.input +
49
+ usage.output * rate.output +
50
+ usage.cacheRead * rate.cacheRead +
51
+ usage.cacheWrite5m * rate.cacheWrite5m +
52
+ usage.cacheWrite1h * rate.cacheWrite1h) /
53
+ 1_000_000);
54
+ }
55
+ //# sourceMappingURL=claude-prices.js.map
@@ -0,0 +1,365 @@
1
+ import { readdir, readFile, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { localDate } from "@ocean/core/shared/local-date.js";
4
+ import { costOf, PRICES_AS_OF, priceFor } from "./claude-prices.js";
5
+ const CAPTURE_DIR = /[\\/]state[\\/]memory[\\/]extract$/;
6
+ const tokens = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
7
+ // One transcript line as a spend record, or null when it is not a model reply, is synthetic,
8
+ // or was already counted (`seen` holds message id + request id).
9
+ export function parseTranscriptLine(line, seen) {
10
+ if (!line.includes('"usage"'))
11
+ return null;
12
+ let entry;
13
+ try {
14
+ entry = JSON.parse(line);
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ const message = entry.message;
20
+ const usage = message?.usage;
21
+ const model = typeof message?.model === "string" ? message.model : "";
22
+ if (!usage || !model || model.startsWith("<"))
23
+ return null;
24
+ const at = Date.parse(String(entry.timestamp ?? ""));
25
+ if (Number.isNaN(at))
26
+ return null;
27
+ const key = `${message?.id ?? ""}:${entry.requestId ?? ""}`;
28
+ if (key !== ":") {
29
+ if (seen.has(key))
30
+ return null;
31
+ seen.add(key);
32
+ }
33
+ const split = usage.cache_creation;
34
+ const written = tokens(usage.cache_creation_input_tokens);
35
+ const oneHour = tokens(split?.ephemeral_1h_input_tokens);
36
+ const fiveMinute = split
37
+ ? tokens(split.ephemeral_5m_input_tokens)
38
+ : written - oneHour;
39
+ const counted = {
40
+ input: tokens(usage.input_tokens),
41
+ output: tokens(usage.output_tokens),
42
+ cacheRead: tokens(usage.cache_read_input_tokens),
43
+ cacheWrite5m: Math.max(0, fiveMinute),
44
+ cacheWrite1h: oneHour,
45
+ };
46
+ const rate = priceFor(model);
47
+ const cwd = typeof entry.cwd === "string" ? entry.cwd : "";
48
+ return {
49
+ at,
50
+ session: typeof entry.sessionId === "string" ? entry.sessionId : "",
51
+ client: typeof entry.entrypoint === "string" ? entry.entrypoint : "unknown",
52
+ project: cwd ? path.basename(cwd) : "unknown",
53
+ kind: CAPTURE_DIR.test(cwd)
54
+ ? "capture"
55
+ : entry.isSidechain === true
56
+ ? "subagent"
57
+ : "interactive",
58
+ model,
59
+ usage: counted,
60
+ context: counted.input +
61
+ counted.cacheRead +
62
+ counted.cacheWrite5m +
63
+ counted.cacheWrite1h,
64
+ cost: rate ? costOf(counted, rate) : 0,
65
+ priced: rate !== null,
66
+ };
67
+ }
68
+ async function transcriptFiles(dir, since) {
69
+ let entries;
70
+ try {
71
+ entries = await readdir(dir, { withFileTypes: true });
72
+ }
73
+ catch {
74
+ return [];
75
+ }
76
+ const found = [];
77
+ for (const entry of entries) {
78
+ const full = path.join(dir, entry.name);
79
+ if (entry.isDirectory())
80
+ found.push(...(await transcriptFiles(full, since)));
81
+ else if (entry.name.endsWith(".jsonl")) {
82
+ // A file last written before the window holds nothing in it.
83
+ const info = await stat(full).catch(() => null);
84
+ if (info && info.mtimeMs >= since)
85
+ found.push(full);
86
+ }
87
+ }
88
+ return found;
89
+ }
90
+ // Every request in the transcripts under `root` made at or after `since` (epoch ms).
91
+ export async function scanTranscripts(root, since) {
92
+ const seen = new Set();
93
+ const records = [];
94
+ for (const file of await transcriptFiles(root, since)) {
95
+ const text = await readFile(file, "utf8").catch(() => "");
96
+ for (const line of text.split("\n")) {
97
+ const record = parseTranscriptLine(line, seen);
98
+ if (record && record.at >= since)
99
+ records.push(record);
100
+ }
101
+ }
102
+ return records.sort((a, b) => a.at - b.at);
103
+ }
104
+ export function parseMeter(text) {
105
+ let parsed;
106
+ try {
107
+ parsed = JSON.parse(text);
108
+ }
109
+ catch {
110
+ return [];
111
+ }
112
+ if (!Array.isArray(parsed.samples))
113
+ return [];
114
+ const rows = parsed.samples.filter((sample) => typeof sample?.t === "number" &&
115
+ typeof sample?.u?.fh === "number" &&
116
+ typeof sample?.u?.sd === "number");
117
+ // The organization sampled last is the one in use.
118
+ const org = rows.reduce((latest, row) => (!latest || row.t > latest.t ? row : latest), null)?.org;
119
+ return rows
120
+ .filter((row) => row.org === org)
121
+ .map((row) => ({ at: row.t, fiveHour: row.u.fh, weekly: row.u.sd }))
122
+ .sort((a, b) => a.at - b.at);
123
+ }
124
+ // Session capture's calls as spend records, from the tokens each one reported to the
125
+ // extraction log (T-340). Its calls stopped leaving transcripts, so the log is the only place
126
+ // they show; a call that did leave one (a capture record in `records` while it ran) is
127
+ // already counted and skipped. A line from before tokens were logged has no figures to price.
128
+ export function captureRecords(entries, records) {
129
+ const transcribed = records
130
+ .filter((record) => record.kind === "capture")
131
+ .map((record) => record.at);
132
+ const found = [];
133
+ for (const entry of entries) {
134
+ if (entry.outcome === "repeat")
135
+ continue;
136
+ const reported = [
137
+ entry.input_tokens,
138
+ entry.output_tokens,
139
+ entry.cache_read_tokens,
140
+ entry.cache_write_tokens,
141
+ ];
142
+ if (reported.every((value) => value === undefined))
143
+ continue;
144
+ const at = Date.parse(entry.at);
145
+ if (Number.isNaN(at))
146
+ continue;
147
+ if (transcribed.some((time) => time >= at - entry.ms - 60_000 && time <= at + 60_000))
148
+ continue;
149
+ const usage = {
150
+ input: tokens(entry.input_tokens),
151
+ output: tokens(entry.output_tokens),
152
+ cacheRead: tokens(entry.cache_read_tokens),
153
+ cacheWrite5m: 0,
154
+ // Claude Code writes its cache for an hour; a write is priced as that.
155
+ cacheWrite1h: tokens(entry.cache_write_tokens),
156
+ };
157
+ const rate = priceFor(entry.model);
158
+ found.push({
159
+ at,
160
+ session: `capture:${entry.session}`,
161
+ client: entry.client,
162
+ project: "session capture",
163
+ kind: "capture",
164
+ model: entry.model,
165
+ usage,
166
+ context: usage.input + usage.cacheRead + usage.cacheWrite1h,
167
+ cost: rate ? costOf(usage, rate) : 0,
168
+ priced: rate !== null,
169
+ });
170
+ }
171
+ return found;
172
+ }
173
+ export const GROUPS = [
174
+ "day",
175
+ "hour",
176
+ "client",
177
+ "project",
178
+ "model",
179
+ "session",
180
+ "kind",
181
+ ];
182
+ const LONG_CONTEXT = 100_000;
183
+ const SESSION_FLAG_COST = 15;
184
+ const IDLE_FLAG_COST = 0.5;
185
+ const FAILURE_RUN_FLAG = 5;
186
+ const pad = (value) => String(value).padStart(2, "0");
187
+ const hourOf = (at) => pad(new Date(at).getHours());
188
+ const dayOf = (at) => localDate(new Date(at));
189
+ function keyOf(record, by) {
190
+ switch (by) {
191
+ case "day":
192
+ return dayOf(record.at);
193
+ case "hour":
194
+ return hourOf(record.at);
195
+ case "client":
196
+ return record.client;
197
+ case "project":
198
+ return record.project;
199
+ case "model":
200
+ return record.model;
201
+ case "session":
202
+ return record.session;
203
+ case "kind":
204
+ return record.kind;
205
+ }
206
+ }
207
+ const empty = (key) => ({
208
+ key,
209
+ requests: 0,
210
+ cost: 0,
211
+ input: 0,
212
+ output: 0,
213
+ cacheRead: 0,
214
+ cacheWrite: 0,
215
+ });
216
+ function add(bucket, record) {
217
+ bucket.requests++;
218
+ bucket.cost += record.cost;
219
+ bucket.input += record.usage.input;
220
+ bucket.output += record.usage.output;
221
+ bucket.cacheRead += record.usage.cacheRead;
222
+ bucket.cacheWrite += record.usage.cacheWrite5m + record.usage.cacheWrite1h;
223
+ return bucket;
224
+ }
225
+ function bucketsBy(records, key) {
226
+ const buckets = new Map();
227
+ for (const record of records) {
228
+ const name = key(record);
229
+ let bucket = buckets.get(name);
230
+ if (!bucket) {
231
+ bucket = empty(name);
232
+ buckets.set(name, bucket);
233
+ }
234
+ add(bucket, record);
235
+ }
236
+ return buckets;
237
+ }
238
+ const median = (values) => {
239
+ const sorted = [...values].sort((a, b) => a - b);
240
+ const middle = Math.floor(sorted.length / 2);
241
+ return sorted.length % 2
242
+ ? sorted[middle]
243
+ : (sorted[middle - 1] + sorted[middle]) / 2;
244
+ };
245
+ const dollars = (value) => `$${value.toFixed(2)}`;
246
+ // The days of the window, oldest first, each with what it cost (a day with no use costs 0).
247
+ function dailyCosts(records, since, now) {
248
+ const costs = new Map();
249
+ for (let at = since; at <= now; at += 86_400_000)
250
+ costs.set(dayOf(at), 0);
251
+ costs.set(dayOf(now), costs.get(dayOf(now)) ?? 0);
252
+ for (const record of records) {
253
+ const day = dayOf(record.at);
254
+ costs.set(day, (costs.get(day) ?? 0) + record.cost);
255
+ }
256
+ return [...costs].sort(([a], [b]) => a.localeCompare(b));
257
+ }
258
+ export function summarizeSpend(records, options) {
259
+ const since = options.now - options.days * 86_400_000;
260
+ const all = [...records, ...captureRecords(options.capture ?? [], records)];
261
+ const inWindow = all.filter((record) => record.at >= since && record.at <= options.now);
262
+ const total = inWindow.reduce(add, empty("total"));
263
+ const byCost = (a, b) => b.cost - a.cost;
264
+ const groups = [...bucketsBy(inWindow, (r) => keyOf(r, options.by)).values()];
265
+ groups.sort(options.by === "day" || options.by === "hour"
266
+ ? (a, b) => a.key.localeCompare(b.key)
267
+ : byCost);
268
+ const sessions = bucketsBy(inWindow, (r) => r.session);
269
+ const firstOf = new Map();
270
+ for (const record of inWindow)
271
+ if (!firstOf.has(record.session))
272
+ firstOf.set(record.session, record);
273
+ const topSessions = [...sessions.values()]
274
+ .sort(byCost)
275
+ .slice(0, 5)
276
+ .map((bucket) => ({
277
+ ...bucket,
278
+ project: firstOf.get(bucket.key)?.project ?? "unknown",
279
+ client: firstOf.get(bucket.key)?.client ?? "unknown",
280
+ }));
281
+ const long = inWindow.filter((record) => record.context > LONG_CONTEXT);
282
+ // An hour with capture calls but no request of his own: the work ran while he was away.
283
+ const activeHours = new Set(inWindow
284
+ .filter((record) => record.kind !== "capture")
285
+ .map((record) => `${dayOf(record.at)} ${hourOf(record.at)}`));
286
+ const idleCost = inWindow
287
+ .filter((record) => record.kind === "capture" &&
288
+ !activeHours.has(`${dayOf(record.at)} ${hourOf(record.at)}`))
289
+ .reduce((sum, record) => sum + record.cost, 0);
290
+ const calls = (options.capture ?? [])
291
+ .filter((entry) => {
292
+ const at = Date.parse(entry.at);
293
+ return at >= since && at <= options.now;
294
+ })
295
+ .sort((a, b) => a.at.localeCompare(b.at));
296
+ const failures = {};
297
+ let run = 0;
298
+ let longestFailureRun = 0;
299
+ for (const entry of calls) {
300
+ if (entry.outcome === "failed") {
301
+ const reason = entry.reason ?? "no reason logged";
302
+ failures[reason] = (failures[reason] ?? 0) + 1;
303
+ longestFailureRun = Math.max(longestFailureRun, ++run);
304
+ }
305
+ else if (entry.outcome === "ok")
306
+ run = 0;
307
+ }
308
+ const samples = (options.meter ?? []).filter((sample) => sample.at >= since && sample.at <= options.now);
309
+ let weeklyRise = 0;
310
+ for (let index = 1; index < samples.length; index++)
311
+ weeklyRise += Math.max(0, samples[index].weekly - samples[index - 1].weekly);
312
+ const flags = [];
313
+ const days = dailyCosts(inWindow, since, options.now);
314
+ days.forEach(([day, cost], index) => {
315
+ const before = days.slice(Math.max(0, index - 7), index).map(([, c]) => c);
316
+ if (before.length < 3)
317
+ return;
318
+ const usual = median(before);
319
+ if (usual > 0 && cost > 2 * usual)
320
+ flags.push(`${day} cost ${dollars(cost)}, ${(cost / usual).toFixed(1)}x the median of the ${before.length} days before (${dollars(usual)})`);
321
+ });
322
+ for (const session of topSessions)
323
+ if (session.cost > SESSION_FLAG_COST)
324
+ flags.push(`session ${session.key.slice(0, 8)} (${session.project}, ${session.client}) cost ${dollars(session.cost)} over ${session.requests} requests`);
325
+ if (idleCost > IDLE_FLAG_COST)
326
+ flags.push(`session capture spent ${dollars(idleCost)} in hours with no session of yours`);
327
+ if (longestFailureRun >= FAILURE_RUN_FLAG)
328
+ flags.push(`session capture failed ${longestFailureRun} calls in a row (${Object.entries(failures)
329
+ .map(([reason, count]) => `${reason} ${count}`)
330
+ .join(", ")})`);
331
+ const unpricedModels = [
332
+ ...new Set(inWindow.filter((r) => !r.priced).map((r) => r.model)),
333
+ ];
334
+ if (unpricedModels.length)
335
+ flags.push(`no price for ${unpricedModels.join(", ")}: counted, not costed; add it to claude-prices.ts`);
336
+ return {
337
+ since: new Date(since).toISOString(),
338
+ until: new Date(options.now).toISOString(),
339
+ pricesAsOf: PRICES_AS_OF,
340
+ total,
341
+ unpricedModels,
342
+ by: options.by,
343
+ groups,
344
+ kinds: [...bucketsBy(inWindow, (r) => r.kind).values()].sort(byCost),
345
+ topSessions,
346
+ longContext: {
347
+ threshold: LONG_CONTEXT,
348
+ requests: long.length,
349
+ cost: long.reduce((sum, record) => sum + record.cost, 0),
350
+ },
351
+ capture: {
352
+ calls: calls.length,
353
+ ok: calls.filter((entry) => entry.outcome === "ok").length,
354
+ failed: calls.filter((entry) => entry.outcome === "failed").length,
355
+ repeats: calls.filter((entry) => entry.outcome === "repeat").length,
356
+ failures,
357
+ longestFailureRun,
358
+ idleCost,
359
+ },
360
+ meter: { latest: samples.at(-1) ?? null, weeklyRise },
361
+ flags,
362
+ notCounted: "claude.ai chats, Cowork tasks, scheduled cloud routines and Desktop chats leave no local transcript: the dollar figures leave them out, the plan meter counts them.",
363
+ };
364
+ }
365
+ //# sourceMappingURL=claude-spend.js.map
@@ -3,10 +3,11 @@ import { existsSync } from "node:fs";
3
3
  import { readFile, rm } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { promisify } from "node:util";
6
+ import { removeCoreSkills } from "@ocean/connect/skills/core-skill-sync.js";
6
7
  import { atomicWrite } from "@ocean/core/shared/fs-utils.js";
7
8
  import { liveEngineEntry, oceanRoot } from "@ocean/core/shared/paths.js";
8
- import { removeCoreSkills } from "@ocean/market/skills/core-skill-sync.js";
9
- import { defaultClientEnv, newBatch, readJournal, removeOceanEntries, restoreClients, } from "../clients/clients.js";
9
+ import { CLIENT_DETECT_FILE, CLIENT_DETECT_LABEL, restoreClientDetect, } from "../clients/client-detect.js";
10
+ import { backupPath, defaultClientEnv, newBatch, readJournal, removeBackups, removeOceanEntries, restoreClients, } from "../clients/clients.js";
10
11
  import { DESKTOP_WATCHER_FILE, DESKTOP_WATCHER_LABEL, restoreDesktopWatcher, } from "../clients/desktop-watcher.js";
11
12
  import { removeOceanHooks, restoreHooks } from "../clients/hooks.js";
12
13
  import { restoreNative } from "../clients/native.js";
@@ -80,6 +81,7 @@ function serviceFiles(ctx) {
80
81
  ctx.launchAgent(RUNTIME_LABEL),
81
82
  ctx.launchAgent(BRIDGE_LABEL),
82
83
  path.join(ctx.home, DESKTOP_WATCHER_FILE),
84
+ path.join(ctx.home, CLIENT_DETECT_FILE),
83
85
  ]
84
86
  : ctx.platform === "linux"
85
87
  ? [ctx.systemdUnit]
@@ -117,6 +119,15 @@ export async function planUninstall(options) {
117
119
  area: "clients",
118
120
  target: "remove any Ocean MCP entry and hook still in a client config",
119
121
  });
122
+ const backups = new Set((await readJournal())
123
+ .filter((entry) => !entry.restoreOf)
124
+ .map((entry) => backupPath(path.join(ctx.home, entry.file), entry.batch))
125
+ .filter((file) => existsSync(file)));
126
+ if (backups.size)
127
+ items.push({
128
+ area: "backups",
129
+ target: `${backups.size} config backup(s) Ocean wrote before editing (kept where a change cannot be undone cleanly)`,
130
+ });
120
131
  items.push({
121
132
  area: "skills",
122
133
  target: "Ocean's core skill copies, the charter copy in Codex and Gemini rules, the skills Ocean disabled",
@@ -136,7 +147,12 @@ export async function planUninstall(options) {
136
147
  }
137
148
  async function stopServices(ctx, report) {
138
149
  if (ctx.platform === "darwin") {
139
- for (const label of [DESKTOP_WATCHER_LABEL, BRIDGE_LABEL, RUNTIME_LABEL]) {
150
+ for (const label of [
151
+ CLIENT_DETECT_LABEL,
152
+ DESKTOP_WATCHER_LABEL,
153
+ BRIDGE_LABEL,
154
+ RUNTIME_LABEL,
155
+ ]) {
140
156
  const file = ctx.launchAgent(label);
141
157
  if (!existsSync(file))
142
158
  continue;
@@ -185,6 +201,7 @@ export async function runUninstall(options) {
185
201
  await restoreOpencodePlugin({ batch, env }),
186
202
  await restoreNative({ batch, env }),
187
203
  await restoreDesktopWatcher({ batch, env, run: ctx.run }),
204
+ await restoreClientDetect({ batch, env, run: ctx.run }),
188
205
  ];
189
206
  for (const result of results) {
190
207
  removed("clients", result.restored);
@@ -204,6 +221,11 @@ export async function runUninstall(options) {
204
221
  left("clients", [
205
222
  `${conflict} (changed since Ocean wrote it; check by hand)`,
206
223
  ]);
224
+ // The config backups apply wrote (T-328 P5) go too, except where a conflict above means the
225
+ // copy is still the owner's way back.
226
+ const backups = await removeBackups(ctx.home, await readJournal(), new Set([...conflicts].map((conflict) => conflict.split(":")[0])));
227
+ removed("backups", backups.removed);
228
+ left("backups", backups.kept.map((file) => `${file} (your config before Ocean edited it)`));
207
229
  // 3. Skills and rules Ocean copied into clients.
208
230
  const skills = await removeCoreSkills(ctx.home);
209
231
  removed("skills", skills.removed);
@@ -3,10 +3,10 @@ import { access, mkdir, readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
5
5
  import { KNOWLEDGE_DIR, oceanPath, SYSTEM_DIR, } from "@ocean/core/shared/paths.js";
6
- import { listTaskLoops } from "@ocean/loop/loops/task-loop.js";
7
- import { hygieneFile } from "@ocean/services/hygiene/hygiene.js";
8
- import { scorecardFile, searchEvalFile, } from "@ocean/services/scorecard/scorecard.js";
9
- import { previousScorecard, renderDigest, runUpkeepJobs, scorecardMoves, writeDigest, } from "@ocean/services/upkeep/upkeep.js";
6
+ import { hygieneFile } from "@ocean/services/health/hygiene.js";
7
+ import { scorecardFile, searchEvalFile, } from "@ocean/services/health/scorecard.js";
8
+ import { previousScorecard, renderDigest, runUpkeepJobs, scorecardMoves, writeDigest, } from "@ocean/services/health/upkeep.js";
9
+ import { listTaskLoops } from "@ocean/work/tasks/task-loop.js";
10
10
  import { listSchedules } from "../scheduler/local-scheduler.js";
11
11
  // Nightly upkeep (T-322): each job is a child `ocean` process with a timeout; the results become
12
12
  // the morning digest in 01-daily/reports/digest/. Once a day through `ocean rhythm` (ifDue), and the
@@ -2,9 +2,9 @@
2
2
  // import infrastructure concretes: it wires them to the domain ports that the
3
3
  // application layer depends on. Dependencies point inward everywhere else —
4
4
  // application → domain ports, never application → infrastructure.
5
- import { brainIndexPort } from "@ocean/brain/infrastructure/brain/brain-index.js";
5
+ import { brainIndexPort } from "@ocean/brain/brain-index.js";
6
6
  import { selectActiveLessons } from "@ocean/brain/memory/lesson-activation.js";
7
- import { openSessionStore, SessionStore, } from "@ocean/loop/infrastructure/persistence/session-store.js";
7
+ import { openSessionStore, SessionStore, } from "@ocean/work/sessions/session-store.js";
8
8
  import { loadProfile } from "../infrastructure/filesystem/profile-loader.js";
9
9
  import { loadSkillIndex } from "../infrastructure/filesystem/skill-loader.js";
10
10
  import { appendRuntimeLog } from "../infrastructure/observability/runtime-logger.js";