@amoree-code/ocean 2.22.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 (382) hide show
  1. package/README.md +46 -53
  2. package/dist/application/clients/bundles.js +220 -0
  3. package/dist/application/clients/chat-plugin.js +4 -42
  4. package/dist/application/clients/client-detect.js +291 -0
  5. package/dist/application/clients/clients.js +104 -25
  6. package/dist/application/clients/desktop-link.js +40 -0
  7. package/dist/application/clients/desktop-watcher.js +6 -4
  8. package/dist/application/clients/hook-trust.js +106 -0
  9. package/dist/application/clients/hooks.js +7 -1
  10. package/dist/application/clients/mcp-schema-cost.js +74 -0
  11. package/dist/application/clients/native.js +38 -2
  12. package/dist/application/clients/registry.js +51 -9
  13. package/dist/application/clients/status.js +7 -2
  14. package/dist/application/clients/zip.js +44 -0
  15. package/dist/application/gateway/webhook-gateway.js +1 -1
  16. package/dist/application/integrations/charter-copies.js +1 -1
  17. package/dist/application/integrations/engine-entry-repair.js +4 -3
  18. package/dist/application/integrations/skill-auto-sync.js +2 -2
  19. package/dist/application/integrations/skill-filter.js +1 -1
  20. package/dist/application/integrations/skill-router.js +134 -90
  21. package/dist/application/layout/layout-apply.js +1 -1
  22. package/dist/application/layout/workspace-template.js +1 -1
  23. package/dist/application/onboarding/steps.js +121 -30
  24. package/dist/application/profiles/profile-doctor.js +118 -0
  25. package/dist/application/profiles/profile-migration-service.js +208 -0
  26. package/dist/application/profiles/profile-suggestion.js +3 -7
  27. package/dist/application/profiles/profile-upgrade-service.js +98 -86
  28. package/dist/application/pull/history-index.js +1 -1
  29. package/dist/application/pull/project-match.js +3 -3
  30. package/dist/application/pull/pull.js +1 -1
  31. package/dist/application/pull/server-capture.js +92 -9
  32. package/dist/application/scheduler/local-scheduler.js +2 -2
  33. package/dist/application/spend/claude-prices.js +55 -0
  34. package/dist/application/spend/claude-spend.js +365 -0
  35. package/dist/application/uninstall/uninstall.js +25 -3
  36. package/dist/application/upkeep/nightly-upkeep.js +4 -4
  37. package/dist/composition/runtime.js +2 -2
  38. package/dist/infrastructure/desktop/claude-export.js +1 -1
  39. package/dist/infrastructure/desktop/desktop-chat.js +60 -13
  40. package/dist/infrastructure/desktop/indexeddb.js +4 -4
  41. package/dist/infrastructure/desktop/leveldb.js +2 -2
  42. package/dist/infrastructure/filesystem/profile-loader.js +3 -45
  43. package/dist/infrastructure/filesystem/runtime-config-loader.js +1 -1
  44. package/dist/infrastructure/observability/runtime-logger.js +1 -1
  45. package/dist/infrastructure/process/agent-tool-executor.js +3 -3
  46. package/dist/infrastructure/process/process-supervisor.js +1 -1
  47. package/dist/infrastructure/process/service.js +8 -8
  48. package/dist/infrastructure/providers/openai-compatible.js +2 -2
  49. package/dist/infrastructure/providers/provider-invocation.js +1 -1
  50. package/dist/infrastructure/providers/session-facts-completer.js +78 -5
  51. package/dist/interfaces/cli/auth-command.js +2 -2
  52. package/dist/interfaces/cli/brief-command.js +1 -1
  53. package/dist/interfaces/cli/browser-command.js +6 -6
  54. package/dist/interfaces/cli/browser-findings.js +6 -9
  55. package/dist/interfaces/cli/browser-settings.js +10 -10
  56. package/dist/interfaces/cli/capture-command.js +6 -6
  57. package/dist/interfaces/cli/client-test-command.js +3 -3
  58. package/dist/interfaces/cli/clients-command.js +55 -6
  59. package/dist/interfaces/cli/command-aliases.js +56 -0
  60. package/dist/interfaces/cli/command-registry.js +48 -1414
  61. package/dist/interfaces/cli/commands/browser.js +5 -0
  62. package/dist/interfaces/cli/commands/capture.js +19 -0
  63. package/dist/interfaces/cli/commands/catalog.js +9 -0
  64. package/dist/interfaces/cli/commands/client.js +135 -0
  65. package/dist/interfaces/cli/commands/clients.js +33 -0
  66. package/dist/interfaces/cli/commands/connectors.js +14 -0
  67. package/dist/interfaces/cli/commands/context.js +9 -0
  68. package/dist/interfaces/cli/commands/cost.js +15 -0
  69. package/dist/interfaces/cli/commands/daily.js +11 -0
  70. package/dist/interfaces/cli/commands/day.js +25 -0
  71. package/dist/interfaces/cli/commands/dispatch.js +31 -0
  72. package/dist/interfaces/cli/commands/doctor.js +60 -0
  73. package/dist/interfaces/cli/commands/env.js +5 -0
  74. package/dist/interfaces/cli/commands/gateway.js +16 -0
  75. package/dist/interfaces/cli/commands/handoff.js +11 -0
  76. package/dist/interfaces/cli/commands/health.js +17 -0
  77. package/dist/interfaces/cli/commands/hook.js +142 -0
  78. package/dist/interfaces/cli/commands/idea.js +11 -0
  79. package/dist/interfaces/cli/commands/install.js +31 -0
  80. package/dist/interfaces/cli/commands/intent.js +14 -0
  81. package/dist/interfaces/cli/commands/intercept.js +22 -0
  82. package/dist/interfaces/cli/commands/layout.js +11 -0
  83. package/dist/interfaces/cli/commands/lifecycle.js +5 -0
  84. package/dist/interfaces/cli/commands/loop.js +73 -0
  85. package/dist/interfaces/cli/commands/market.js +11 -0
  86. package/dist/interfaces/cli/commands/mcp.js +57 -0
  87. package/dist/interfaces/cli/commands/memory.js +5 -0
  88. package/dist/interfaces/cli/commands/migrate.js +5 -0
  89. package/dist/interfaces/cli/commands/observe.js +11 -0
  90. package/dist/interfaces/cli/commands/obsidian.js +111 -0
  91. package/dist/interfaces/cli/commands/operate.js +7 -0
  92. package/dist/interfaces/cli/commands/policy.js +16 -0
  93. package/dist/interfaces/cli/commands/project.js +207 -0
  94. package/dist/interfaces/cli/commands/repair.js +20 -0
  95. package/dist/interfaces/cli/commands/run.js +52 -0
  96. package/dist/interfaces/cli/commands/schedule.js +58 -0
  97. package/dist/interfaces/cli/commands/service.js +21 -0
  98. package/dist/interfaces/cli/commands/session.js +182 -0
  99. package/dist/interfaces/cli/commands/sessions.js +12 -0
  100. package/dist/interfaces/cli/commands/setup.js +21 -0
  101. package/dist/interfaces/cli/commands/skill.js +159 -0
  102. package/dist/interfaces/cli/commands/tasks.js +10 -0
  103. package/dist/interfaces/cli/commands/update-remove.js +25 -0
  104. package/dist/interfaces/cli/connectors-command.js +150 -0
  105. package/dist/interfaces/cli/context-command.js +39 -3
  106. package/dist/interfaces/cli/cost-command.js +104 -0
  107. package/dist/interfaces/cli/curator-command.js +1 -1
  108. package/dist/interfaces/cli/daily-command.js +7 -1
  109. package/dist/interfaces/cli/desktop-command.js +43 -7
  110. package/dist/interfaces/cli/distill-command.js +7 -2
  111. package/dist/interfaces/cli/express-command.js +1 -1
  112. package/dist/interfaces/cli/failures-command.js +4 -4
  113. package/dist/interfaces/cli/gateway-findings.js +2 -2
  114. package/dist/interfaces/cli/governance-command.js +23 -16
  115. package/dist/interfaces/cli/handoff-command.js +1 -1
  116. package/dist/interfaces/cli/harvest-command.js +2 -2
  117. package/dist/interfaces/cli/help-command.js +53 -169
  118. package/dist/interfaces/cli/hygiene-command.js +1 -1
  119. package/dist/interfaces/cli/idea-command.js +1 -1
  120. package/dist/interfaces/cli/intercept-command.js +8 -7
  121. package/dist/interfaces/cli/interests-command.js +1 -1
  122. package/dist/interfaces/cli/layout-command.js +2 -0
  123. package/dist/interfaces/cli/market-command.js +9 -9
  124. package/dist/interfaces/cli/mcp-gateway-command.js +124 -7
  125. package/dist/interfaces/cli/mcp-probe-command.js +186 -0
  126. package/dist/interfaces/cli/mcp-status-command.js +5 -5
  127. package/dist/interfaces/cli/memory-command.js +41 -7
  128. package/dist/interfaces/cli/migrate-command.js +2 -2
  129. package/dist/interfaces/cli/note-command.js +1 -1
  130. package/dist/interfaces/cli/onboard-command.js +14 -0
  131. package/dist/interfaces/cli/operate-command.js +5 -5
  132. package/dist/interfaces/cli/profiles-command.js +61 -1
  133. package/dist/interfaces/cli/rhythm-command.js +11 -5
  134. package/dist/interfaces/cli/running-server-findings.js +1 -1
  135. package/dist/interfaces/cli/scorecard-command.js +8 -8
  136. package/dist/interfaces/cli/session-facts-command.js +2 -2
  137. package/dist/interfaces/cli/sessions-command.js +145 -0
  138. package/dist/interfaces/cli/setup-command.js +15 -2
  139. package/dist/interfaces/cli/tasks-command.js +63 -13
  140. package/dist/interfaces/cli/telemetry-command.js +4 -4
  141. package/dist/interfaces/cli/uninstall-command.js +1 -1
  142. package/dist/interfaces/cli/week-failures.js +32 -0
  143. package/dist/main.js +12 -0
  144. package/node_modules/@ocean/brain/dist/{infrastructure/brain/brain-index.js → brain-index.js} +2 -2
  145. package/node_modules/@ocean/brain/dist/{brain/brain-markdown.js → brain-markdown.js} +1 -1
  146. package/node_modules/@ocean/brain/dist/{brain/brain-service.js → brain-service.js} +12 -2
  147. package/node_modules/@ocean/brain/dist/memory/brain-dump.js +92 -16
  148. package/node_modules/@ocean/brain/dist/memory/extraction-log.js +125 -0
  149. package/node_modules/@ocean/brain/dist/memory/extraction-retry.js +54 -0
  150. package/node_modules/@ocean/brain/dist/memory/fact-routing.js +44 -1
  151. package/node_modules/@ocean/brain/dist/memory/lesson-activation.js +2 -2
  152. package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +2 -2
  153. package/node_modules/@ocean/brain/dist/memory/lessons.js +1 -1
  154. package/node_modules/@ocean/brain/dist/memory/memory-audit.js +2 -2
  155. package/node_modules/@ocean/brain/dist/memory/memory-harvest.js +1 -1
  156. package/node_modules/@ocean/brain/dist/memory/memory-paths.js +8 -0
  157. package/node_modules/@ocean/brain/dist/memory/memory-review.js +31 -3
  158. package/node_modules/@ocean/brain/dist/memory/memory-trash.js +29 -0
  159. package/node_modules/@ocean/brain/dist/memory/memory-write.js +4 -2
  160. package/node_modules/@ocean/brain/dist/memory/model-narrative.js +2 -2
  161. package/node_modules/@ocean/brain/dist/memory/profile-facts.js +1 -1
  162. package/node_modules/@ocean/brain/dist/memory/routing.json +6 -6
  163. package/node_modules/@ocean/{market/dist/skills → brain/dist/memory}/signal-detection.js +1 -1
  164. package/node_modules/@ocean/brain/dist/{memory → people}/people.js +1 -1
  165. package/node_modules/@ocean/brain/dist/sessions-capture/session-facts.js +625 -0
  166. package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-promotion.js +7 -15
  167. package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-summary.js +1 -1
  168. package/node_modules/@ocean/brain/dist/sessions-capture/session-triage.js +52 -0
  169. package/node_modules/@ocean/brain/package.json +1 -1
  170. package/node_modules/@ocean/connect/dist/connectors/connector-hub.js +173 -0
  171. package/node_modules/@ocean/{market → connect}/dist/install/default-marketplace.js +6 -2
  172. package/node_modules/@ocean/{market → connect}/dist/install/marketplace-service.js +1 -1
  173. package/node_modules/@ocean/connect/dist/mcp/mcp-gateway.js +987 -0
  174. package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-launch.js +102 -5
  175. package/node_modules/@ocean/{market → connect}/dist/registry/official-registry.js +1 -1
  176. package/node_modules/@ocean/{market → connect}/dist/security/permissions.js +1 -1
  177. package/node_modules/@ocean/{market → connect}/dist/skills/skill-hub.js +104 -6
  178. package/node_modules/@ocean/{market → connect}/package.json +2 -2
  179. package/node_modules/@ocean/context/dist/{context/context-ladder.js → context-ladder.js} +3 -3
  180. package/node_modules/@ocean/context/dist/{context/context-references.js → context-references.js} +5 -4
  181. package/node_modules/@ocean/context/dist/{context/context-cost.js → context-size.js} +6 -6
  182. package/node_modules/@ocean/context/dist/{context/intent-router.js → intent-router.js} +1 -1
  183. package/node_modules/@ocean/context/dist/{context/resource-injection.js → resource-injection.js} +3 -1
  184. package/node_modules/@ocean/context/package.json +1 -1
  185. package/node_modules/@ocean/core/dist/domain/brain/brain-record.js +1 -1
  186. package/node_modules/@ocean/core/dist/domain/capabilities/capability-manifest.js +5 -5
  187. package/node_modules/@ocean/core/dist/domain/connector-entry.js +86 -0
  188. package/node_modules/@ocean/core/dist/domain/context/context.js +1 -1
  189. package/node_modules/@ocean/core/dist/domain/context/project-id.js +8 -2
  190. package/node_modules/@ocean/core/dist/domain/{evidence/evidence.js → evidence.js} +1 -1
  191. package/node_modules/@ocean/core/dist/domain/mcp/memory-contract.js +4 -1
  192. package/node_modules/@ocean/core/dist/domain/ports/brain-index-port.js +1 -1
  193. package/node_modules/@ocean/core/dist/domain/profiles/profile-markdown.js +40 -0
  194. package/node_modules/@ocean/core/dist/domain/profiles/profile-resolution.js +276 -0
  195. package/node_modules/@ocean/core/dist/domain/profiles/profile-selection.js +23 -60
  196. package/node_modules/@ocean/core/dist/domain/profiles/profile-upgrade.js +2 -2
  197. package/node_modules/@ocean/core/dist/domain/profiles/profile.js +66 -6
  198. package/node_modules/@ocean/core/dist/domain/profiles/runtime-config.js +1 -1
  199. package/node_modules/@ocean/core/dist/domain/runs/agent-tools.js +2 -2
  200. package/node_modules/@ocean/core/dist/domain/sessions/session-identity.js +53 -0
  201. package/node_modules/@ocean/core/dist/domain/sessions/session-metadata.js +208 -0
  202. package/node_modules/@ocean/core/dist/domain/{tasks/task-id.js → task-id.js} +2 -2
  203. package/node_modules/@ocean/core/dist/profiles/profile-files.js +57 -0
  204. package/node_modules/@ocean/core/dist/profiles/profile-loader.js +97 -0
  205. package/node_modules/@ocean/core/dist/profiles/project-profile-fill.js +33 -0
  206. package/node_modules/@ocean/core/dist/profiles/session-profile.js +158 -0
  207. package/node_modules/@ocean/core/dist/shared/charter.js +110 -0
  208. package/node_modules/@ocean/core/dist/shared/context-ack.js +1 -1
  209. package/node_modules/@ocean/core/dist/shared/context-triggers.js +67 -0
  210. package/node_modules/@ocean/core/dist/shared/paths.js +6 -6
  211. package/node_modules/@ocean/core/dist/shared/project-legacy.js +232 -0
  212. package/node_modules/@ocean/core/dist/shared/project-manifest.js +308 -0
  213. package/node_modules/@ocean/core/dist/shared/project-names.js +87 -0
  214. package/node_modules/@ocean/core/dist/shared/project-register.js +560 -0
  215. package/node_modules/@ocean/core/dist/shared/project-resolution.js +83 -861
  216. package/node_modules/@ocean/core/dist/shared/repo-signals.js +45 -0
  217. package/node_modules/@ocean/core/dist/shared/task-reference.js +1 -1
  218. package/node_modules/@ocean/core/dist/shared/text-tokens.js +37 -0
  219. package/node_modules/@ocean/core/dist/shared/tool-groups.js +224 -0
  220. package/node_modules/@ocean/core/package.json +4 -1
  221. package/node_modules/@ocean/services/dist/day/day.js +45 -3
  222. package/node_modules/@ocean/services/dist/{distill → day}/distill.js +29 -3
  223. package/node_modules/@ocean/services/dist/{harvest → day}/harvest.js +54 -14
  224. package/node_modules/@ocean/services/dist/{brief → day}/interest-discovery.js +3 -3
  225. package/node_modules/@ocean/services/dist/day/note.js +2 -2
  226. package/node_modules/@ocean/services/dist/{onboarding → day}/onboarding.js +1 -1
  227. package/node_modules/@ocean/services/dist/day/patterns.js +68 -0
  228. package/node_modules/@ocean/services/dist/{curator → health}/curator.js +5 -5
  229. package/node_modules/@ocean/services/dist/{journey → health}/failures.js +7 -5
  230. package/node_modules/@ocean/services/dist/{hygiene → health}/hygiene.js +2 -2
  231. package/node_modules/@ocean/services/dist/{journey → health}/lesson-effect.js +1 -1
  232. package/node_modules/@ocean/services/dist/{scorecard → health}/scorecard.js +3 -3
  233. package/node_modules/@ocean/services/dist/{upkeep → health}/upkeep.js +2 -2
  234. package/node_modules/@ocean/services/dist/{doctor → health}/workspace-doctor.js +57 -17
  235. package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-session.js +1 -1
  236. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/call-ledger.js +3 -0
  237. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-client.js +19 -3
  238. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/obsidian-server.js +4 -4
  239. package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/ocean-server.js +423 -34
  240. package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/conflict-log.js +1 -1
  241. package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/folder-templates.js +8 -5
  242. package/node_modules/@ocean/services/dist/projects/project-doctor.js +173 -0
  243. package/node_modules/@ocean/services/dist/projects/project-snippet.js +9 -0
  244. package/node_modules/@ocean/services/dist/projects/projects-overview.js +2 -2
  245. package/node_modules/@ocean/services/package.json +1 -1
  246. package/node_modules/@ocean/{loop/dist/loops → work/dist/runs}/guard-runtime.js +3 -3
  247. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/memory-knowledge-operations.js +4 -12
  248. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-contract.js +2 -2
  249. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/project-operations.js +2 -1
  250. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/task-operations.js +4 -4
  251. package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/write-guard.js +1 -1
  252. package/node_modules/@ocean/{loop → work}/dist/runs/prompt-assembly.js +2 -2
  253. package/node_modules/@ocean/{loop → work}/dist/runs/run-agent.js +4 -4
  254. package/node_modules/@ocean/{loop → work}/dist/runs/tool-loop.js +4 -4
  255. package/node_modules/@ocean/work/dist/sessions/hooks/desktop-facts.js +309 -0
  256. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-end-hook.js +36 -5
  257. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-facts-hook.js +144 -14
  258. package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-start-hook.js +129 -12
  259. package/node_modules/@ocean/work/dist/sessions/hooks/start-brief.js +110 -0
  260. package/node_modules/@ocean/work/dist/sessions/hooks/unlinked-warning.js +68 -0
  261. package/node_modules/@ocean/{loop → work}/dist/sessions/session-closeout.js +4 -4
  262. package/node_modules/@ocean/{loop → work}/dist/sessions/session-projects.js +13 -3
  263. package/node_modules/@ocean/work/dist/sessions/session-relink.js +300 -0
  264. package/node_modules/@ocean/{loop → work}/dist/sessions/session-retention.js +1 -1
  265. package/node_modules/@ocean/{loop → work}/dist/tasks/list-tasks.js +7 -2
  266. package/node_modules/@ocean/{loop → work}/dist/tasks/renumber-tasks.js +4 -2
  267. package/node_modules/@ocean/{loop → work}/dist/tasks/session-task.js +2 -2
  268. package/node_modules/@ocean/{loop → work}/dist/tasks/sync-task-prs.js +77 -7
  269. package/node_modules/@ocean/work/dist/tasks/task-git.js +63 -0
  270. package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop.js +4 -4
  271. package/node_modules/@ocean/{loop → work}/dist/tasks/verification-readiness.js +1 -1
  272. package/node_modules/@ocean/{loop → work}/dist/tasks/verify-task.js +1 -1
  273. package/node_modules/@ocean/{loop → work}/package.json +2 -2
  274. package/ocean-marketplace.json +41 -41
  275. package/package.json +12 -11
  276. package/skills/core/daily-harvest/SKILL.md +1 -1
  277. package/skills/core/ocean-memory/SKILL.md +4 -0
  278. package/skills/core/use-browser/SKILL.md +30 -7
  279. package/skills/index.json +1 -1
  280. package/templates/profiles/default.md +44 -0
  281. package/templates/profiles/developer.md +45 -0
  282. package/templates/profiles/reviewer.md +44 -0
  283. package/templates/profiles/strategist.md +44 -0
  284. package/templates/profiles-v3/analysis.md +16 -0
  285. package/templates/profiles-v3/backend.md +16 -0
  286. package/templates/profiles-v3/base.md +57 -0
  287. package/templates/profiles-v3/code-review.md +16 -0
  288. package/templates/profiles-v3/devops.md +16 -0
  289. package/templates/profiles-v3/docs-office.md +16 -0
  290. package/templates/profiles-v3/frontend.md +16 -0
  291. package/templates/profiles-v3/learning.md +16 -0
  292. package/templates/profiles-v3/marketing-ads.md +16 -0
  293. package/templates/profiles-v3/marketing-content-seo.md +16 -0
  294. package/templates/profiles-v3/ocean-ops.md +16 -0
  295. package/templates/profiles-v3/product-strategy.md +16 -0
  296. package/templates/profiles-v3/qa-testing.md +16 -0
  297. package/templates/profiles-v3/security.md +16 -0
  298. package/templates/workspace/MANIFEST.json +1 -0
  299. package/templates/workspace/charter/core.md +22 -90
  300. package/templates/workspace/charter/policies/README.md +7 -1
  301. package/templates/workspace/charter/policies/claude-code-context.md +6 -1
  302. package/templates/workspace/charter/policies/concise-output.md +5 -0
  303. package/templates/workspace/charter/policies/context.md +5 -0
  304. package/templates/workspace/charter/policies/contracts/task.md +2 -2
  305. package/templates/workspace/charter/policies/git.md +5 -0
  306. package/templates/workspace/charter/policies/graph.md +6 -1
  307. package/templates/workspace/charter/policies/knowledge.md +11 -4
  308. package/templates/workspace/charter/policies/layout.md +23 -0
  309. package/templates/workspace/charter/policies/lifecycle.md +5 -0
  310. package/templates/workspace/charter/policies/memory.md +5 -0
  311. package/templates/workspace/charter/policies/minimal-change.md +5 -0
  312. package/templates/workspace/charter/policies/models.md +5 -0
  313. package/templates/workspace/charter/policies/response.md +5 -0
  314. package/templates/workspace/charter/policies/skill-observer.md +12 -0
  315. package/templates/workspace/charter/policies/stack.md +5 -0
  316. package/templates/workspace/charter/policies/task.md +17 -3
  317. package/templates/workspace/charter/policies/verification.md +5 -0
  318. package/node_modules/@ocean/brain/dist/evidence/verification-report.js +0 -13
  319. package/node_modules/@ocean/brain/dist/memory/daily-narrative.js +0 -142
  320. package/node_modules/@ocean/brain/dist/memory/session-facts.js +0 -283
  321. package/node_modules/@ocean/context/dist/context/context-compression.js +0 -66
  322. package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +0 -174
  323. package/node_modules/@ocean/loop/dist/operations/task-linker.js +0 -40
  324. package/node_modules/@ocean/loop/dist/sessions/session-pointer.js +0 -133
  325. package/node_modules/@ocean/loop/dist/tasks/task-git.js +0 -28
  326. package/node_modules/@ocean/market/dist/mcp/mcp-gateway.js +0 -533
  327. package/templates/profiles/default.json +0 -51
  328. package/templates/profiles/developer.json +0 -51
  329. package/templates/profiles/reviewer.json +0 -51
  330. package/templates/profiles/strategist.json +0 -51
  331. /package/node_modules/@ocean/brain/dist/{brain/brain-eval.js → brain-eval.js} +0 -0
  332. /package/node_modules/@ocean/brain/dist/{brain/brain-reindex.js → brain-reindex.js} +0 -0
  333. /package/node_modules/@ocean/brain/dist/{capture → sessions-capture}/inbox-sync.js +0 -0
  334. /package/node_modules/@ocean/{market → connect}/dist/adapters/mcp-adapter.js +0 -0
  335. /package/node_modules/@ocean/{market → connect}/dist/adapters/owned-directory.js +0 -0
  336. /package/node_modules/@ocean/{market → connect}/dist/adapters/plugin-adapter.js +0 -0
  337. /package/node_modules/@ocean/{market → connect}/dist/adapters/skill-adapter.js +0 -0
  338. /package/node_modules/@ocean/{market → connect}/dist/capability/adapter.js +0 -0
  339. /package/node_modules/@ocean/{market → connect}/dist/capability/catalog.js +0 -0
  340. /package/node_modules/@ocean/{market → connect}/dist/capability/content-digest.js +0 -0
  341. /package/node_modules/@ocean/{market → connect}/dist/capability/registry.js +0 -0
  342. /package/node_modules/@ocean/{market → connect}/dist/install/lock.js +0 -0
  343. /package/node_modules/@ocean/{market → connect}/dist/install/own-server.js +0 -0
  344. /package/node_modules/@ocean/{market → connect}/dist/mcp/chrome-debugging.js +0 -0
  345. /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-connection.js +0 -0
  346. /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-runner.js +0 -0
  347. /package/node_modules/@ocean/{market → connect}/dist/security/description-scan.js +0 -0
  348. /package/node_modules/@ocean/{market → connect}/dist/security/secrets.js +0 -0
  349. /package/node_modules/@ocean/{market → connect}/dist/skills/core-skill-sync.js +0 -0
  350. /package/node_modules/@ocean/context/dist/{context/context-packet.js → context-packet.js} +0 -0
  351. /package/node_modules/@ocean/core/dist/domain/{process/process-events.js → process-events.js} +0 -0
  352. /package/node_modules/@ocean/core/dist/domain/{redaction/redaction.js → redaction.js} +0 -0
  353. /package/node_modules/@ocean/services/dist/{brief → day}/brief.js +0 -0
  354. /package/node_modules/@ocean/services/dist/{express → day}/express.js +0 -0
  355. /package/node_modules/@ocean/services/dist/{brief → day}/source-registry.json +0 -0
  356. /package/node_modules/@ocean/services/dist/{journey → health}/telemetry.js +0 -0
  357. /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-service.js +0 -0
  358. /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-task-runner.js +0 -0
  359. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-session.js +0 -0
  360. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/server-version.js +0 -0
  361. /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/tool-registry.js +0 -0
  362. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/inbox-promotion.js +0 -0
  363. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-discovery.js +0 -0
  364. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-ingestion.js +0 -0
  365. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-sync.js +0 -0
  366. /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-writer.js +0 -0
  367. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-scope.js +0 -0
  368. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-io.js +0 -0
  369. /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-operations.js +0 -0
  370. /package/node_modules/@ocean/{loop → work}/dist/runs/run-authorization.js +0 -0
  371. /package/node_modules/@ocean/{loop → work}/dist/runs/session-tokens.js +0 -0
  372. /package/node_modules/@ocean/{loop/dist/handoff → work/dist/sessions}/handoff-service.js +0 -0
  373. /package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/lifecycle-hooks.js +0 -0
  374. /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-store.js +0 -0
  375. /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-validator.js +0 -0
  376. /package/node_modules/@ocean/{loop → work}/dist/tasks/archive-tasks.js +0 -0
  377. /package/node_modules/@ocean/{loop → work}/dist/tasks/checkpoint-task.js +0 -0
  378. /package/node_modules/@ocean/{loop → work}/dist/tasks/claim-task.js +0 -0
  379. /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/iteration-graph.js +0 -0
  380. /package/node_modules/@ocean/{loop → work}/dist/tasks/new-task.js +0 -0
  381. /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop-record.js +0 -0
  382. /package/node_modules/@ocean/{loop → work}/dist/tasks/task-verification.js +0 -0
@@ -1,142 +0,0 @@
1
- import { mkdir, readFile, realpath } from "node:fs/promises";
2
- import path from "node:path";
3
- import { redactRuntimeText } from "@ocean/core/domain/redaction/redaction.js";
4
- import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
5
- import { localDate } from "@ocean/core/shared/local-date.js";
6
- import { DAILY_DIR, oceanPath } from "@ocean/core/shared/paths.js";
7
- import { findGitRoot } from "@ocean/core/shared/project-resolution.js";
8
- const dailyTemplate = (date) => `# Daily — ${date}\n\n## Focus\n\n## Work log\n\n## Decisions\n\n## Problems\n\n## Next\n\n## Observations\n`;
9
- // The literal fallback title stamped on a session with no explicit title
10
- // (see run request construction) — never meaningful content on its own.
11
- const GENERIC_TITLE = /^claude session$/i;
12
- function safeText(value, max = 240) {
13
- return redactRuntimeText(value).replace(/\s+/g, " ").trim().slice(0, max);
14
- }
15
- function isGenericContent(text) {
16
- const trimmed = (text ?? "").trim();
17
- return trimmed.length === 0 || GENERIC_TITLE.test(trimmed);
18
- }
19
- // Markup a client wraps around a prompt (`<ide_opened_file>…</ide_opened_file>`,
20
- // `<task-notification>…`) is not what the session was about. Client tags carry `_` or `-`,
21
- // which HTML tag names never do, so a prompt about `<button>Save</button>` keeps its words.
22
- const CLIENT_TAG = "[a-z][a-z0-9]*(?:[_-][a-z0-9]+)+";
23
- function withoutClientMarkup(text) {
24
- return text
25
- .replace(new RegExp(`<(${CLIENT_TAG})\\b[^>]*>[\\s\\S]*?<\\/\\1>`, "gi"), " ")
26
- .replace(new RegExp(`<\\/?${CLIENT_TAG}\\b[^>]*>`, "gi"), " ");
27
- }
28
- // Local wall-clock date and time, like the SessionEnd hook's own line: a UTC stamp put one
29
- // session three hours apart in the same log, and after midnight UTC into another day's file.
30
- function localStamp(now = new Date()) {
31
- const pad = (value) => String(value).padStart(2, "0");
32
- return {
33
- date: localDate(now),
34
- time: `${pad(now.getHours())}:${pad(now.getMinutes())}`,
35
- };
36
- }
37
- function insertUnderHeading(content, heading, line) {
38
- // A client that reports one session end twice must not log it twice.
39
- if (content.split("\n").includes(line))
40
- return content;
41
- const marker = `${heading}\n`;
42
- const index = content.indexOf(marker);
43
- if (index < 0)
44
- return `${content.trimEnd()}\n\n${heading}\n${line}\n`;
45
- const insertAt = index + marker.length;
46
- return `${content.slice(0, insertAt)}${line}\n${content.slice(insertAt)}`;
47
- }
48
- // Read-modify-write of today's daily file. Two sessions closing out at once would otherwise
49
- // each write back their own copy and drop the other's lines (T-257), so it runs under the
50
- // file lock and lands atomically.
51
- async function updateDailyFile(update) {
52
- const { date } = localStamp();
53
- const directory = oceanPath(DAILY_DIR);
54
- const file = path.join(directory, `${date}.md`);
55
- await mkdir(directory, { recursive: true });
56
- await withFileLock(file, async () => {
57
- let content;
58
- try {
59
- content = await readFile(file, "utf8");
60
- }
61
- catch (error) {
62
- // Only a missing file starts from the template: any other read failure must not
63
- // replace a real day's log with an empty one.
64
- if (error.code !== "ENOENT")
65
- throw error;
66
- content = dailyTemplate(date);
67
- }
68
- // A symlinked daily file keeps its link: the write goes to the real file.
69
- const target = await realpath(file).catch(() => file);
70
- await atomicWrite(target, update(content));
71
- });
72
- }
73
- /**
74
- * Human-readable narrative entry appended to today's
75
- * brain/01-daily/YYYY-MM-DD.md at session closeout. A field from `narrative`
76
- * (produced by a cheap model call — see model-narrative.ts) is used verbatim
77
- * when present; any field it omits (including when the model call was
78
- * skipped or failed entirely) falls back to the deterministic heuristic
79
- * below, so this never depends on the model call succeeding.
80
- */
81
- export async function appendDailyNarrative(input) {
82
- const { session, events, narrative } = input;
83
- const inserts = [];
84
- const { time } = localStamp();
85
- const project = path.basename(session.workingDirectory) || session.workingDirectory;
86
- const status = session.status === "completed" && (input.exitCode ?? 0) === 0
87
- ? "completed"
88
- : "failed";
89
- const workLog = narrative?.workLog ??
90
- (() => {
91
- const objectiveEvent = events.find((event) => event.type === "user_input" || event.type === "resume_requested");
92
- // A prompt that was only client markup falls back to the session's title.
93
- const prompt = safeText(withoutClientMarkup(objectiveEvent?.data ?? ""));
94
- return safeText(prompt || session.title, 160);
95
- })();
96
- // Skip an entry with nothing to say (the SessionEnd hook already notes that a session
97
- // ended), and the doubly-useless case: only the generic placeholder title AND no real
98
- // project (root/home session, no git repo). A generic title in a real project, or real
99
- // content with no project, still gets logged.
100
- const hasRealProject = findGitRoot(session.workingDirectory) !== null;
101
- const skipWorkLog = !workLog.trim() || (isGenericContent(workLog) && !hasRealProject);
102
- if (!skipWorkLog) {
103
- inserts.push([
104
- "## Work log",
105
- `- ${time} ${session.provider} session in ${project}: ${workLog} — ${status}`,
106
- ]);
107
- }
108
- const decisionLine = narrative?.decision ??
109
- events
110
- .filter((event) => event.type === "provider_output" ||
111
- event.type === "text" ||
112
- event.type === "json")
113
- .map((event) => safeText(event.data, 500))
114
- .find((text) => /\bdecision\s*:/i.test(text));
115
- if (decisionLine)
116
- inserts.push(["## Decisions", `- ${decisionLine}`]);
117
- const problemLine = narrative?.problem ??
118
- events
119
- .filter((event) => event.type === "error" || event.type === "provider_blocked")
120
- .map((event) => safeText(event.data, 500))[0];
121
- if (problemLine)
122
- inserts.push(["## Problems", `- ${problemLine}`]);
123
- const nextAction = narrative?.next ?? input.nextAction ?? session.nextAction;
124
- if (nextAction &&
125
- nextAction !== "Review the summary and verify the next action.") {
126
- inserts.push(["## Next", `- [${project}] ${safeText(nextAction, 240)}`]);
127
- }
128
- await updateDailyFile((content) => inserts.reduce((next, [heading, line]) => insertUnderHeading(next, heading, line), content));
129
- }
130
- /**
131
- * Appends newly detected observations (corrections, repeated procedures,
132
- * explicit decisions, proven verifications — see lesson-learning.ts) to
133
- * today's brain/01-daily/YYYY-MM-DD.md, so they surface next to the
134
- * session narrative instead of sitting only in 05-knowledge/lessons.
135
- */
136
- export async function appendObservations(session, observations) {
137
- if (!observations.length)
138
- return;
139
- const project = path.basename(session.workingDirectory) || session.workingDirectory;
140
- await updateDailyFile((content) => observations.reduce((next, observation) => insertUnderHeading(next, "## Observations", `- [${observation.signalType}] ${safeText(observation.summary, 300)} _(${project}, confidence ${observation.confidence})_`), content));
141
- }
142
- //# sourceMappingURL=daily-narrative.js.map
@@ -1,283 +0,0 @@
1
- import { mkdir, readFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { MemoryContractError } from "@ocean/core/domain/mcp/memory-contract.js";
4
- import { redactSecrets } from "@ocean/core/domain/redaction/redaction.js";
5
- import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
6
- import { FACT_TYPES, factTarget, isFactType, } from "./fact-routing.js";
7
- import { sha256 } from "./memory-audit.js";
8
- import { sessionFactsLedgerFile } from "./memory-paths.js";
9
- import { proposeMemory } from "./memory-write.js";
10
- export const SESSION_FACTS_SOURCE_PREFIX = "session:";
11
- export function isSessionFactSource(source) {
12
- return (typeof source === "string" && source.startsWith(SESSION_FACTS_SOURCE_PREFIX));
13
- }
14
- // About 6k tokens of transcript per call; the user's own words get most of it.
15
- export const DEFAULT_FACTS_BUDGET_CHARS = 24_000;
16
- const USER_SHARE = 0.7;
17
- const MAX_TURN_CHARS = 4_000;
18
- export const MAX_FACTS = 5;
19
- const MAX_TITLE = 100;
20
- const MAX_CONTENT = 1_200;
21
- const MAX_EVIDENCE = 300;
22
- const MIN_EVIDENCE = 8;
23
- // Secrets and private paths are replaced before any text reaches a model (the candidate check
24
- // runs again on the output). Turns are then chosen within the budget: the newest user turns
25
- // first, up to USER_SHARE of it, then the newest assistant turns in what is left, and the chosen
26
- // ones are put back in conversation order.
27
- export function selectTurns(turns, budgetChars = DEFAULT_FACTS_BUDGET_CHARS) {
28
- const redacted = turns
29
- .map((turn, index) => ({
30
- index,
31
- role: turn.role,
32
- text: redactSecrets(turn.text.replace(/\s+/g, " ").trim()).slice(0, MAX_TURN_CHARS),
33
- }))
34
- .filter((turn) => turn.text);
35
- const chosen = new Set();
36
- let used = 0;
37
- const take = (role, limit) => {
38
- for (let i = redacted.length - 1; i >= 0; i--) {
39
- const turn = redacted[i];
40
- if (turn.role !== role || chosen.has(turn.index))
41
- continue;
42
- if (used + turn.text.length > limit)
43
- continue;
44
- chosen.add(turn.index);
45
- used += turn.text.length;
46
- }
47
- };
48
- take("user", Math.floor(budgetChars * USER_SHARE));
49
- take("assistant", budgetChars);
50
- // Left-over room from the assistant pass goes back to older user turns.
51
- take("user", budgetChars);
52
- return redacted
53
- .filter((turn) => chosen.has(turn.index))
54
- .map(({ role, text }) => ({ role, text }));
55
- }
56
- const DIGEST_ITEMS = 3;
57
- const DIGEST_ITEM_CHARS = 220;
58
- const DIGEST_PROMPT = [
59
- "Also summarize the whole conversation for the user's daily log, in the digest field. Plain short sentences in English; lists may be empty; never a secret or a [REDACTED] value.",
60
- `title: what the conversation was about, at most 8 words. goal and outcome: one sentence each. decisions, fixes ("problem → fix"), learned, next: at most ${DIGEST_ITEMS} items each.`,
61
- ];
62
- export function buildFactsPrompt(turns, options = {}) {
63
- const transcript = turns
64
- .map((turn) => `[${turn.role === "user" ? "USER" : "ASSISTANT"}] ${turn.text}`)
65
- .join("\n");
66
- return [
67
- "You extract durable memory from one conversation between a user and an AI assistant.",
68
- "Durable means still true and useful in a later, unrelated conversation: the user's identity, role, preferences, standing decisions, project facts, constraints, and corrections to the assistant.",
69
- "Only extract what the USER stated or explicitly confirmed. Never extract the assistant's suggestions, guesses or plans the user did not confirm.",
70
- "Never extract temporary state (what is being debugged right now, today's to-do, a file being edited), secrets, credentials, or anything marked [REDACTED] or [PRIVATE_PATH].",
71
- `Return at most ${MAX_FACTS} facts. Returning none is correct and common.`,
72
- ...(options.digest ? DIGEST_PROMPT : []),
73
- "Answer with JSON only, no prose and no code fence:",
74
- `{"facts":[{"title":"short label","content":"the fact as one or two plain sentences","evidence":"an exact quote, copied character for character from one USER line","reason":"why it is durable","type":"one of the types below","project":"project name if the fact is about one, else omit"}]${options.digest ? ',"digest":{"title":"","goal":"","outcome":"","decisions":[],"fixes":[],"learned":[],"next":[]}' : ""}}`,
75
- `type is one of: ${FACT_TYPES.join(", ")}. Use project only for a fact about one project, and then also give its project name; a fact about the user stays a personal type even when it came up in a project.`,
76
- 'Answer {"facts":[]} when nothing qualifies.',
77
- "",
78
- "Conversation:",
79
- transcript,
80
- ].join("\n");
81
- }
82
- const clean = (value, max) => typeof value === "string"
83
- ? value.replace(/\s+/g, " ").trim().slice(0, max)
84
- : "";
85
- // The model's answer → well-formed facts. Anything else (prose, a fence around the JSON, missing
86
- // fields) yields what can be read and drops the rest; never throws.
87
- // The `facts` list the answer holds, or null when the answer is no such JSON at all (a failed
88
- // call, prose, a refusal): then the turns are read again by a later run.
89
- function factsList(text) {
90
- if (!text)
91
- return null;
92
- const start = text.indexOf("{");
93
- const end = text.lastIndexOf("}");
94
- if (start < 0 || end <= start)
95
- return null;
96
- let parsed;
97
- try {
98
- parsed = JSON.parse(text.slice(start, end + 1));
99
- }
100
- catch {
101
- return null;
102
- }
103
- return parsed &&
104
- typeof parsed === "object" &&
105
- Array.isArray(parsed.facts)
106
- ? parsed.facts
107
- : null;
108
- }
109
- // The digest the answer holds, cleaned and bounded; null when there is none or it says nothing.
110
- export function parseDigest(text) {
111
- if (!text)
112
- return null;
113
- const start = text.indexOf("{");
114
- const end = text.lastIndexOf("}");
115
- if (start < 0 || end <= start)
116
- return null;
117
- let value;
118
- try {
119
- const parsed = JSON.parse(text.slice(start, end + 1));
120
- if (!parsed.digest || typeof parsed.digest !== "object")
121
- return null;
122
- value = parsed.digest;
123
- }
124
- catch {
125
- return null;
126
- }
127
- const list = (key) => (Array.isArray(value[key]) ? value[key] : [])
128
- .map((item) => redactSecrets(clean(item, DIGEST_ITEM_CHARS)))
129
- .filter((item) => item && !/\[(redacted|private_path)\]/i.test(item))
130
- .slice(0, DIGEST_ITEMS);
131
- const digest = {
132
- title: redactSecrets(clean(value.title, 80)),
133
- goal: redactSecrets(clean(value.goal, DIGEST_ITEM_CHARS)),
134
- outcome: redactSecrets(clean(value.outcome, DIGEST_ITEM_CHARS)),
135
- decisions: list("decisions"),
136
- fixes: list("fixes"),
137
- learned: list("learned"),
138
- next: list("next"),
139
- };
140
- return digest.title || digest.goal ? digest : null;
141
- }
142
- export function parseFacts(text) {
143
- const list = factsList(text) ?? [];
144
- const facts = [];
145
- for (const item of list) {
146
- if (!item || typeof item !== "object")
147
- continue;
148
- const value = item;
149
- const fact = {
150
- title: clean(value.title, MAX_TITLE),
151
- content: clean(value.content, MAX_CONTENT),
152
- evidence: clean(value.evidence, MAX_EVIDENCE),
153
- reason: clean(value.reason, 300),
154
- };
155
- const project = clean(value.project, 64);
156
- if (project)
157
- fact.project = project;
158
- if (isFactType(value.type))
159
- fact.type = value.type;
160
- if (fact.title && fact.content && fact.evidence)
161
- facts.push(fact);
162
- if (facts.length === MAX_FACTS)
163
- break;
164
- }
165
- return facts;
166
- }
167
- const normalize = (value) => value
168
- .toLowerCase()
169
- .normalize("NFKC")
170
- .replace(/[‘’“”"'`]/g, "")
171
- .replace(/\s+/g, " ")
172
- .trim();
173
- // The false-positive guard: a fact counts only when its evidence is really in what the user
174
- // said (after the same redaction the model saw). An assistant line, a paraphrase passed off as a
175
- // quote, or an invented fact has no such quote.
176
- export function isGrounded(fact, turns) {
177
- const evidence = normalize(fact.evidence);
178
- if (evidence.length < MIN_EVIDENCE)
179
- return false;
180
- if (/\[(redacted|private_path)\]/.test(evidence))
181
- return false;
182
- return turns.some((turn) => turn.role === "user" && normalize(turn.text).includes(evidence));
183
- }
184
- export async function extractSessionFacts(options) {
185
- const turns = selectTurns(options.turns, options.budgetChars);
186
- if (!turns.some((turn) => turn.role === "user"))
187
- return { facts: [], rejected: [], prompt: "", turns: 0, failed: false };
188
- const prompt = buildFactsPrompt(turns, { digest: options.digest });
189
- let answer = null;
190
- try {
191
- answer = await options.complete(prompt);
192
- }
193
- catch {
194
- answer = null;
195
- }
196
- const facts = [];
197
- const rejected = [];
198
- for (const fact of parseFacts(answer)) {
199
- if (isGrounded(fact, turns))
200
- facts.push(fact);
201
- else
202
- rejected.push({
203
- title: fact.title,
204
- reason: "evidence not found in a user turn",
205
- });
206
- }
207
- return {
208
- facts,
209
- rejected,
210
- prompt,
211
- turns: turns.length,
212
- failed: factsList(answer) === null,
213
- ...(options.digest ? { digest: parseDigest(answer) } : {}),
214
- };
215
- }
216
- const factKey = (fact) => `f:${sha256(normalize(fact.content))}`;
217
- async function readLedger() {
218
- try {
219
- return JSON.parse(await readFile(sessionFactsLedgerFile(), "utf8"));
220
- }
221
- catch {
222
- return {};
223
- }
224
- }
225
- async function writeLedger(ledger) {
226
- const file = sessionFactsLedgerFile();
227
- await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
228
- await atomicWrite(file, `${JSON.stringify(ledger, null, 2)}\n`, 0o600);
229
- }
230
- // Each fact → one candidate, through proposeMemory's own checks (size, secrets). A ledger of
231
- // content hashes keeps the same fact from being proposed twice across sessions; within one
232
- // session the transcript cursor already keeps the same turns from being read twice.
233
- export async function proposeSessionFacts(options) {
234
- // Two sessions ending together read and write the same ledger.
235
- await mkdir(path.dirname(sessionFactsLedgerFile()), {
236
- recursive: true,
237
- mode: 0o700,
238
- });
239
- return withFileLock(sessionFactsLedgerFile(), () => proposeLocked(options));
240
- }
241
- async function proposeLocked(options) {
242
- const ledger = await readLedger();
243
- const result = { proposed: [], skipped: [] };
244
- for (const fact of options.facts) {
245
- const key = factKey(fact);
246
- if (ledger[key]) {
247
- result.skipped.push({
248
- title: fact.title,
249
- reason: `already proposed as ${ledger[key]}`,
250
- });
251
- continue;
252
- }
253
- try {
254
- const { candidate } = await proposeMemory({
255
- content: `# ${fact.title}\n\n${fact.content}\n\n> ${fact.evidence}\n`,
256
- origin: "inferred",
257
- source: `${SESSION_FACTS_SOURCE_PREFIX}${options.sessionId}`,
258
- reason: fact.reason || "stated by the user in a session",
259
- target: await factTarget(fact),
260
- meta: {
261
- kind: "fact",
262
- client: options.client,
263
- ...(fact.type ? { type: fact.type } : {}),
264
- ...(fact.project ? { project: fact.project } : {}),
265
- },
266
- });
267
- ledger[key] = candidate;
268
- result.proposed.push(candidate);
269
- }
270
- catch (error) {
271
- if (!(error instanceof MemoryContractError))
272
- throw error;
273
- result.skipped.push({
274
- title: fact.title,
275
- reason: `${error.code}: ${error.message}`,
276
- });
277
- }
278
- }
279
- if (result.proposed.length)
280
- await writeLedger(ledger);
281
- return result;
282
- }
283
- //# sourceMappingURL=session-facts.js.map
@@ -1,66 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- const REQUIRED = /changed files?|verification|security|approval|error|failed|next action/i;
3
- function boundedByBytes(value, budget) {
4
- return Buffer.from(value).subarray(0, budget).toString("utf8");
5
- }
6
- function unique(lines) {
7
- return [...new Set(lines.map((line) => line.trim()).filter(Boolean))];
8
- }
9
- export function compressContext(input) {
10
- const originalBytes = Buffer.byteLength(input.content);
11
- const sourceHash = createHash("sha256").update(input.content).digest("hex");
12
- if (input.budget <= 0)
13
- throw new Error("Compression budget must be positive");
14
- if (originalBytes <= input.budget) {
15
- return {
16
- content: input.content,
17
- sourceId: input.sourceId,
18
- sourceHash,
19
- originalBytes,
20
- compressedBytes: originalBytes,
21
- method: "none",
22
- budget: input.budget,
23
- omittedSections: [],
24
- recoveryRef: input.sourceId,
25
- safeToUse: true,
26
- };
27
- }
28
- const lines = input.content.split(/\r?\n/);
29
- const required = unique(lines.filter((line) => REQUIRED.test(line)));
30
- const selected = unique([lines[0] ?? "", ...required, lines.at(-1) ?? ""]);
31
- const content = selected.join("\n");
32
- const compressedBytes = Buffer.byteLength(content);
33
- const omittedSections = lines
34
- .filter((line) => line.trim() && !selected.includes(line.trim()))
35
- .slice(0, 20)
36
- .map((line) => line.trim().slice(0, 120));
37
- if (compressedBytes <= input.budget &&
38
- required.every((line) => content.includes(line.trim()))) {
39
- return {
40
- content,
41
- sourceId: input.sourceId,
42
- sourceHash,
43
- originalBytes,
44
- compressedBytes,
45
- method: "ocean-bounded-v1",
46
- budget: input.budget,
47
- omittedSections,
48
- recoveryRef: input.sourceId,
49
- safeToUse: true,
50
- };
51
- }
52
- const fallback = boundedByBytes(input.content, input.budget);
53
- return {
54
- content: fallback,
55
- sourceId: input.sourceId,
56
- sourceHash,
57
- originalBytes,
58
- compressedBytes: Buffer.byteLength(fallback),
59
- method: "fallback-original-bounded",
60
- budget: input.budget,
61
- omittedSections,
62
- recoveryRef: input.sourceId,
63
- safeToUse: false,
64
- };
65
- }
66
- //# sourceMappingURL=context-compression.js.map
@@ -1,174 +0,0 @@
1
- import { mkdir, readFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { writeDigestRecord } from "@ocean/brain/memory/brain-dump.js";
4
- import { sessionFactsEnabled } from "@ocean/brain/memory/memory-audit.js";
5
- import { extractSessionFacts, proposeSessionFacts, } from "@ocean/brain/memory/session-facts.js";
6
- import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
7
- import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
8
- // Fact capture from Claude Desktop's plain chat (T-315). Desktop has no hooks, so a run reads
9
- // the conversations the app keeps locally (the reader is injected: it lives in harness) and
10
- // sends the new turns of each conversation that has gone quiet to the same extraction T-313
11
- // uses. A per-conversation cursor — the creation time of the newest message already claimed,
12
- // which the app's store and the official export both carry — makes every turn read once,
13
- // whichever source it came from: a run claims (cursor, newest] under a short lock, calls the
14
- // model unlocked,
15
- // and hands the turns back if the model gave no answer. Candidates carry
16
- // `source: session:desktop:<uuid>`, so they are never auto-approved. No message text is ever
17
- // written outside the candidates themselves: the state file and the run report hold ids,
18
- // times and counts only.
19
- export const DESKTOP_CLIENT = "claude-desktop";
20
- export const DEFAULT_QUIET_MS = 10 * 60 * 1000;
21
- export function desktopFactsStateFile() {
22
- return oceanPath(SYSTEM_DIR, "state", "memory", "desktop", "cursors.json");
23
- }
24
- // The last run's outcome, for `ocean doctor`: status, counts and an error code, never text.
25
- export function desktopFactsLastRunFile() {
26
- return oceanPath(SYSTEM_DIR, "state", "memory", "desktop", "last-run.json");
27
- }
28
- export async function recordDesktopRun(run) {
29
- await mkdir(path.dirname(desktopFactsLastRunFile()), {
30
- recursive: true,
31
- mode: 0o700,
32
- });
33
- await atomicWrite(desktopFactsLastRunFile(), `${JSON.stringify(run, null, 2)}\n`, 0o600);
34
- }
35
- async function readState() {
36
- try {
37
- const parsed = JSON.parse(await readFile(desktopFactsStateFile(), "utf8"));
38
- if (parsed && typeof parsed.conversations === "object") {
39
- // Only claims in the current shape count; any other is read from the start.
40
- for (const [uuid, claim] of Object.entries(parsed.conversations))
41
- if (typeof claim?.to !== "string")
42
- delete parsed.conversations[uuid];
43
- return parsed;
44
- }
45
- }
46
- catch {
47
- // no state yet, or unreadable: start from the beginning of each conversation
48
- }
49
- return { conversations: {} };
50
- }
51
- async function writeState(state) {
52
- await atomicWrite(desktopFactsStateFile(), `${JSON.stringify(state, null, 2)}\n`, 0o600);
53
- }
54
- async function locked(run) {
55
- await mkdir(path.dirname(desktopFactsStateFile()), {
56
- recursive: true,
57
- mode: 0o700,
58
- });
59
- return withFileLock(desktopFactsStateFile(), async () => run(await readState()));
60
- }
61
- const toTurn = (message) => ({
62
- role: message.sender === "human" ? "user" : "assistant",
63
- text: message.text,
64
- });
65
- export async function runDesktopFacts(options) {
66
- if (!(await (options.enabled ?? sessionFactsEnabled)()))
67
- return { status: "off" };
68
- const read = await options.read();
69
- if (read.status === "absent")
70
- return { status: "absent" };
71
- const now = (options.now ?? new Date()).getTime();
72
- const quietMs = options.quietMs ?? DEFAULT_QUIET_MS;
73
- const result = {
74
- status: "done",
75
- conversations: read.conversations.length,
76
- waiting: 0,
77
- upToDate: 0,
78
- runs: [],
79
- };
80
- for (const conversation of read.conversations) {
81
- const updated = Date.parse(conversation.updatedAt);
82
- if (options.since && !(updated >= options.since.getTime()))
83
- continue;
84
- // A conversation still being written is left for a later run.
85
- if (!(updated <= now - quietMs)) {
86
- result.waiting++;
87
- continue;
88
- }
89
- const run = await captureOne(conversation, options.complete);
90
- if (run)
91
- result.runs.push(run);
92
- else
93
- result.upToDate++;
94
- }
95
- return result;
96
- }
97
- async function captureOne(conversation, complete) {
98
- const dated = conversation.messages.filter((m) => m.createdAt);
99
- const newest = dated.reduce((max, m) => (m.createdAt > max ? m.createdAt : max), "");
100
- const claim = await locked(async (state) => {
101
- const from = state.conversations[conversation.uuid]?.to ?? "";
102
- // Nothing is claimed without a model, so a later run that has one still reads the turns.
103
- if (newest <= from || !complete)
104
- return { from, claimed: false };
105
- state.conversations[conversation.uuid] = {
106
- from,
107
- to: newest,
108
- at: new Date().toISOString(),
109
- };
110
- await writeState(state);
111
- return { from, claimed: true };
112
- });
113
- const base = { uuid: conversation.uuid, from: claim.from, to: newest };
114
- if (newest <= claim.from)
115
- return null;
116
- if (!claim.claimed || !complete)
117
- return { ...base, status: "no-provider" };
118
- const turns = dated
119
- .filter((message) => message.createdAt > claim.from && message.text.trim())
120
- .map(toTurn);
121
- if (!turns.some((turn) => turn.role === "user"))
122
- return { ...base, status: "no-user-text" };
123
- // The same call also returns the conversation's digest for the day's log (no second call).
124
- const extraction = await extractSessionFacts({
125
- turns,
126
- complete,
127
- digest: true,
128
- });
129
- if (extraction.failed) {
130
- // Nothing was learned: hand the turns back, unless a later run already claimed past them.
131
- await locked(async (state) => {
132
- const latest = state.conversations[conversation.uuid];
133
- if (latest?.from === claim.from && latest.to === newest) {
134
- if (!claim.from)
135
- delete state.conversations[conversation.uuid];
136
- else
137
- state.conversations[conversation.uuid] = {
138
- from: claim.from,
139
- to: claim.from,
140
- at: new Date().toISOString(),
141
- };
142
- await writeState(state);
143
- }
144
- });
145
- return { ...base, status: "failed" };
146
- }
147
- const proposed = await proposeSessionFacts({
148
- sessionId: `desktop:${conversation.uuid}`,
149
- client: DESKTOP_CLIENT,
150
- facts: extraction.facts,
151
- });
152
- let record;
153
- if (extraction.digest) {
154
- const times = dated
155
- .filter((message) => message.createdAt > claim.from)
156
- .map((message) => message.createdAt);
157
- record = (await writeDigestRecord({
158
- provider: DESKTOP_CLIENT,
159
- sessionId: `desktop:${conversation.uuid}`,
160
- startedAt: times[0] ?? newest,
161
- endedAt: newest,
162
- digest: extraction.digest,
163
- })).path;
164
- }
165
- return {
166
- ...base,
167
- status: "done",
168
- ...(record ? { record } : {}),
169
- candidates: proposed.proposed,
170
- rejected: extraction.rejected.length,
171
- skipped: proposed.skipped.length,
172
- };
173
- }
174
- //# sourceMappingURL=desktop-facts.js.map