@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
@@ -0,0 +1,208 @@
1
+ // A session record's metadata block (T-334): how its project was decided and what the session
2
+ // did, counted from the transcript or the store, never asked of a model. Every key is bounded,
3
+ // and every value sits on one line (JSON is valid YAML), so the flat frontmatter reader reads it.
4
+ export const MAX_TOOLS = 5;
5
+ export const MAX_FILES = 8;
6
+ const NAME_CHARS = 60;
7
+ const PATH_CHARS = 160;
8
+ const TEXT_CHARS = 120;
9
+ const clip = (value, max) => value.replace(/\s+/g, " ").trim().slice(0, max);
10
+ // The `limit` most-counted entries, ties by name, so the same counts always write the same block.
11
+ function topCounts(counts, limit) {
12
+ return Object.entries(counts)
13
+ .filter(([name, count]) => name && count > 0)
14
+ .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
15
+ .slice(0, limit);
16
+ }
17
+ // Tool names as a person reads them: "mcp__ocean__brain_search" → "brain_search".
18
+ function toolLabel(name) {
19
+ return clip(name.split("__").at(-1) || name, NAME_CHARS);
20
+ }
21
+ // Counts what a stretch of conversation did, one turn or tool call at a time.
22
+ export class ActivityTally {
23
+ activity = {
24
+ turnsUser: 0,
25
+ turnsAssistant: 0,
26
+ tools: {},
27
+ files: {},
28
+ };
29
+ last;
30
+ turn(role) {
31
+ if (role === "user")
32
+ this.activity.turnsUser++;
33
+ else if (this.last !== "assistant")
34
+ this.activity.turnsAssistant = (this.activity.turnsAssistant ?? 0) + 1;
35
+ this.last = role;
36
+ }
37
+ tool(name, file) {
38
+ const label = toolLabel(name);
39
+ if (label)
40
+ this.activity.tools[label] = (this.activity.tools[label] ?? 0) + 1;
41
+ if (file)
42
+ this.activity.files[file] = (this.activity.files[file] ?? 0) + 1;
43
+ }
44
+ model(name) {
45
+ if (typeof name === "string" && name && !name.startsWith("<"))
46
+ this.activity.model = clip(name, TEXT_CHARS);
47
+ }
48
+ branch(name) {
49
+ if (typeof name === "string" && name)
50
+ this.activity.branch = clip(name, TEXT_CHARS);
51
+ }
52
+ result() {
53
+ return {
54
+ ...this.activity,
55
+ tools: { ...this.activity.tools },
56
+ files: { ...this.activity.files },
57
+ };
58
+ }
59
+ }
60
+ // A later stretch of the same session added to what its record already says. A record keeps
61
+ // only the top counts, so a merged count can miss calls that fell outside them earlier.
62
+ export function mergeActivity(earlier, later) {
63
+ if (!earlier)
64
+ return later;
65
+ if (!later)
66
+ return earlier;
67
+ const add = (a, b) => {
68
+ const sum = { ...a };
69
+ for (const [key, count] of Object.entries(b))
70
+ sum[key] = (sum[key] ?? 0) + count;
71
+ return sum;
72
+ };
73
+ const assistant = earlier.turnsAssistant === undefined && later.turnsAssistant === undefined
74
+ ? undefined
75
+ : (earlier.turnsAssistant ?? 0) + (later.turnsAssistant ?? 0);
76
+ return {
77
+ turnsUser: earlier.turnsUser + later.turnsUser,
78
+ ...(assistant === undefined ? {} : { turnsAssistant: assistant }),
79
+ tools: add(earlier.tools, later.tools),
80
+ files: add(earlier.files, later.files),
81
+ ...((later.model ?? earlier.model)
82
+ ? { model: later.model ?? earlier.model }
83
+ : {}),
84
+ ...((later.branch ?? earlier.branch)
85
+ ? { branch: later.branch ?? earlier.branch }
86
+ : {}),
87
+ };
88
+ }
89
+ const minutes = (started, ended) => {
90
+ const span = Date.parse(ended ?? "") - Date.parse(started ?? "");
91
+ return Number.isFinite(span) ? Math.max(0, Math.round(span / 60_000)) : null;
92
+ };
93
+ // The block's frontmatter lines, in a fixed order. A key with nothing derived is left out.
94
+ export function metadataLines(meta) {
95
+ const quote = (value) => JSON.stringify(value);
96
+ const activity = meta.activity;
97
+ const branch = meta.branch ?? activity?.branch;
98
+ const duration = minutes(meta.started, meta.ended);
99
+ const tools = activity ? topCounts(activity.tools, MAX_TOOLS) : [];
100
+ const files = activity ? topCounts(activity.files, MAX_FILES) : [];
101
+ return [
102
+ `project_how: ${quote(meta.projectHow)}`,
103
+ `project_confidence: ${quote(meta.projectConfidence)}`,
104
+ ...(branch ? [`branch: ${quote(clip(branch, TEXT_CHARS))}`] : []),
105
+ ...(meta.started ? [`started: ${quote(meta.started)}`] : []),
106
+ ...(meta.ended ? [`ended: ${quote(meta.ended)}`] : []),
107
+ ...(duration === null ? [] : [`duration_min: ${duration}`]),
108
+ ...(activity ? [`turns_user: ${activity.turnsUser}`] : []),
109
+ ...(activity?.turnsAssistant === undefined
110
+ ? []
111
+ : [`turns_assistant: ${activity.turnsAssistant}`]),
112
+ ...(tools.length
113
+ ? [
114
+ `tools: ${JSON.stringify(Object.fromEntries(tools.map(([name, count]) => [clip(name, NAME_CHARS), count])))}`,
115
+ ]
116
+ : []),
117
+ ...(files.length
118
+ ? [
119
+ `files: ${JSON.stringify(files.map(([file]) => clip(file, PATH_CHARS)))}`,
120
+ ]
121
+ : []),
122
+ ...(activity?.model ? [`model: ${quote(activity.model)}`] : []),
123
+ ...(meta.extraction
124
+ ? [
125
+ `extraction: ${JSON.stringify({
126
+ model: clip(meta.extraction.model, TEXT_CHARS),
127
+ input_chars: Math.max(0, Math.round(meta.extraction.inputChars)),
128
+ ms: Math.max(0, Math.round(meta.extraction.ms)),
129
+ })}`,
130
+ ]
131
+ : []),
132
+ ];
133
+ }
134
+ const json = (value) => {
135
+ if (!value)
136
+ return undefined;
137
+ try {
138
+ return JSON.parse(value);
139
+ }
140
+ catch {
141
+ return undefined;
142
+ }
143
+ };
144
+ const count = (value) => {
145
+ const number = Number(value);
146
+ return value !== undefined && value !== "" && Number.isInteger(number)
147
+ ? number
148
+ : undefined;
149
+ };
150
+ const isCounts = (value) => typeof value === "object" &&
151
+ value !== null &&
152
+ !Array.isArray(value) &&
153
+ Object.values(value).every((each) => Number.isFinite(each));
154
+ // The block back from a record's flat frontmatter fields (parseFrontmatter's output): what the
155
+ // start brief, the weekly patterns and brain_search read instead of the record's body. A record
156
+ // written before T-334 has none of it.
157
+ export function readMetadata(fields) {
158
+ const tools = json(fields.tools);
159
+ const files = json(fields.files);
160
+ const extraction = json(fields.extraction);
161
+ const turnsUser = count(fields.turns_user);
162
+ const turnsAssistant = count(fields.turns_assistant);
163
+ const hasActivity = turnsUser !== undefined || isCounts(tools) || Array.isArray(files);
164
+ const text = (key) => fields[key] || undefined;
165
+ return {
166
+ ...(text("project_how") ? { projectHow: text("project_how") } : {}),
167
+ ...(text("project_confidence")
168
+ ? { projectConfidence: text("project_confidence") }
169
+ : {}),
170
+ ...(text("task") ? { task: text("task") } : {}),
171
+ ...(text("branch") ? { branch: text("branch") } : {}),
172
+ ...(text("started") ? { started: text("started") } : {}),
173
+ ...(text("ended") ? { ended: text("ended") } : {}),
174
+ ...(count(fields.duration_min) === undefined
175
+ ? {}
176
+ : { durationMin: count(fields.duration_min) }),
177
+ ...(hasActivity
178
+ ? {
179
+ activity: {
180
+ turnsUser: turnsUser ?? 0,
181
+ ...(turnsAssistant === undefined ? {} : { turnsAssistant }),
182
+ tools: isCounts(tools) ? tools : {},
183
+ // Order is rank: the first path was touched most.
184
+ files: Array.isArray(files)
185
+ ? Object.fromEntries(files
186
+ .filter((file) => typeof file === "string")
187
+ .map((file, index) => [file, files.length - index]))
188
+ : {},
189
+ ...(text("model") ? { model: text("model") } : {}),
190
+ ...(text("branch") ? { branch: text("branch") } : {}),
191
+ },
192
+ }
193
+ : {}),
194
+ ...(extraction &&
195
+ typeof extraction.model === "string" &&
196
+ typeof extraction.input_chars === "number" &&
197
+ typeof extraction.ms === "number"
198
+ ? {
199
+ extraction: {
200
+ model: extraction.model,
201
+ inputChars: extraction.input_chars,
202
+ ms: extraction.ms,
203
+ },
204
+ }
205
+ : {}),
206
+ };
207
+ }
208
+ //# sourceMappingURL=session-metadata.js.map
@@ -3,11 +3,11 @@
3
3
  // one rule.
4
4
  // The namespace every task had before prefixes existed; it stays valid forever.
5
5
  export const LEGACY_PREFIX = "T";
6
- export const PREFIX_SHAPE = /^[A-Z][A-Z0-9]{0,5}$/;
6
+ const PREFIX_SHAPE = /^[A-Z][A-Z0-9]{0,5}$/;
7
7
  export const TASK_ID = /^[A-Z][A-Z0-9]{0,5}-\d{1,6}$/;
8
8
  // Real-world tokens shaped like an id ("UTF-8", "SHA-256", "ISO-8601", "GPT-5"): a project
9
9
  // may never claim one, or free text would turn every mention into a task reference.
10
- export const RESERVED_PREFIXES = [
10
+ const RESERVED_PREFIXES = [
11
11
  "CVE",
12
12
  "GPT",
13
13
  "HTTP",
@@ -0,0 +1,57 @@
1
+ import { readdir, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { oceanPath, SYSTEM_DIR } from "../shared/paths.js";
4
+ // The same rule as a profile name: other files in the root (a README, `.upgrade/`) are not
5
+ // profiles.
6
+ const profileName = /^[a-z0-9][a-z0-9_-]{0,63}$/;
7
+ export function profilesDir() {
8
+ return oceanPath(SYSTEM_DIR, "profiles");
9
+ }
10
+ // Every profile form in the root, sorted by name. A name present in more than one form appears
11
+ // once per form, so a caller can report the collision.
12
+ export async function listProfileEntries(dir = profilesDir()) {
13
+ let names;
14
+ try {
15
+ names = await readdir(dir);
16
+ }
17
+ catch (error) {
18
+ if (error.code === "ENOENT")
19
+ return [];
20
+ throw error;
21
+ }
22
+ const entries = [];
23
+ for (const entry of names) {
24
+ const full = path.join(dir, entry);
25
+ const extension = path.extname(entry);
26
+ const name = path.basename(entry, extension);
27
+ if (!profileName.test(name))
28
+ continue;
29
+ if (extension === ".md" || extension === ".json") {
30
+ if ((await stat(full).catch(() => null))?.isFile())
31
+ entries.push({
32
+ name,
33
+ file: full,
34
+ format: extension === ".md" ? "md" : "json",
35
+ });
36
+ }
37
+ else if (!extension &&
38
+ (await stat(path.join(full, "profile.json")).catch(() => null))?.isFile())
39
+ entries.push({
40
+ name,
41
+ file: path.join(full, "profile.json"),
42
+ format: "directory",
43
+ });
44
+ }
45
+ return entries.sort((a, b) => a.name.localeCompare(b.name) || a.format.localeCompare(b.format));
46
+ }
47
+ export async function listProfileNames(dir = profilesDir()) {
48
+ return [...new Set((await listProfileEntries(dir)).map((e) => e.name))];
49
+ }
50
+ // Names present in more than one form: which file is the profile would be ambiguous.
51
+ export function profileCollisions(entries) {
52
+ const seen = new Map();
53
+ for (const entry of entries)
54
+ seen.set(entry.name, (seen.get(entry.name) ?? 0) + 1);
55
+ return [...seen].filter(([, count]) => count > 1).map(([name]) => name);
56
+ }
57
+ //# sourceMappingURL=profile-files.js.map
@@ -0,0 +1,97 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { assertProfileName } from "../domain/profiles/profile.js";
4
+ import { parseProfileMarkdown } from "../domain/profiles/profile-markdown.js";
5
+ import { validateProfile } from "../domain/profiles/profile-validator.js";
6
+ import { resolveWithin } from "../shared/paths.js";
7
+ import { profilesDir } from "./profile-files.js";
8
+ function missingAsNull(error) {
9
+ if (error.code === "ENOENT")
10
+ return null;
11
+ throw error;
12
+ }
13
+ // The parser's message quotes the text around the error, which could be part of a secret
14
+ // pasted into the file, so only the file is named.
15
+ function parseProfile(source, file) {
16
+ try {
17
+ return JSON.parse(source);
18
+ }
19
+ catch {
20
+ throw new Error(`Invalid profile JSON in ${file}`);
21
+ }
22
+ }
23
+ function asRecord(value, file) {
24
+ if (!value || typeof value !== "object" || Array.isArray(value))
25
+ throw new Error(`Profile ${file} must be an object`);
26
+ return value;
27
+ }
28
+ // The name inside the file must be the name it was loaded by: the name keys sessions and the
29
+ // profile's memory namespace, so a mismatch would read or write another profile's facts.
30
+ function requireName(raw, name, file) {
31
+ if (raw.name !== name)
32
+ throw new Error(`Profile ${file} declares name "${String(raw.name)}", expected "${name}"`);
33
+ }
34
+ // One profile's own fields, unvalidated and before inheritance; the name is checked by the
35
+ // caller, after validation, so an invalid name is reported as invalid first. `<name>.md` and `<name>.json`
36
+ // together are ambiguous and refused; only a missing canonical file falls through to the
37
+ // legacy directory form, and a file that exists but cannot be read or parsed is an error,
38
+ // never a silent fallback.
39
+ async function readRawProfile(name) {
40
+ assertProfileName(name);
41
+ const root = profilesDir();
42
+ const markdownFile = resolveWithin(root, `${name}.md`);
43
+ const jsonFile = resolveWithin(root, `${name}.json`);
44
+ const markdown = await readFile(markdownFile, "utf8").catch(missingAsNull);
45
+ const json = await readFile(jsonFile, "utf8").catch(missingAsNull);
46
+ if (markdown !== null && json !== null)
47
+ throw new Error(`Profile ${name} exists as both ${name}.md and ${name}.json; keep one`);
48
+ if (markdown !== null)
49
+ return {
50
+ raw: parseProfileMarkdown(markdown, markdownFile),
51
+ file: markdownFile,
52
+ };
53
+ if (json !== null)
54
+ return {
55
+ raw: asRecord(parseProfile(json, jsonFile), jsonFile),
56
+ file: jsonFile,
57
+ };
58
+ const directory = resolveWithin(root, name);
59
+ if ((await stat(directory).catch(missingAsNull))?.isDirectory()) {
60
+ const legacy = path.join(directory, "profile.json");
61
+ const input = asRecord(parseProfile(await readFile(legacy, "utf8"), legacy), legacy);
62
+ const instructions = await readFile(path.join(directory, "instructions.md"), "utf8").catch(() => "");
63
+ return {
64
+ raw: { ...input, instructions },
65
+ file: legacy,
66
+ };
67
+ }
68
+ throw new Error(`Profile not found: ${name}`);
69
+ }
70
+ // A chain deeper than this is a mistake, not a design.
71
+ const MAX_EXTENDS = 4;
72
+ // `extends: <parent>` (T-338): the child's fields replace the parent's, key by key (a nested
73
+ // map such as `clients` is replaced whole, never merged). `name` and `extends` are the child's.
74
+ // A parent must declare its own file's name, like any profile.
75
+ async function resolveRawProfile(name, chain = []) {
76
+ if (chain.includes(name))
77
+ throw new Error(`Profile inheritance cycle: ${[...chain, name].join(" → ")}`);
78
+ if (chain.length > MAX_EXTENDS)
79
+ throw new Error(`Profile ${chain[0]} extends more than ${MAX_EXTENDS} deep`);
80
+ const own = await readRawProfile(name);
81
+ const parentName = own.raw.extends;
82
+ if (parentName === undefined)
83
+ return own;
84
+ if (typeof parentName !== "string")
85
+ throw new Error(`Profile ${name}: extends must be a profile name`);
86
+ const parent = await resolveRawProfile(parentName, [...chain, name]);
87
+ requireName(parent.raw, parentName, parent.file);
88
+ const { extends: _parentExtends, ...inherited } = parent.raw;
89
+ return { raw: { ...inherited, ...own.raw }, file: own.file };
90
+ }
91
+ export async function loadProfile(name) {
92
+ const { raw, file } = await resolveRawProfile(name);
93
+ const profile = validateProfile(raw);
94
+ requireName(profile, name, file);
95
+ return profile;
96
+ }
97
+ //# sourceMappingURL=profile-loader.js.map
@@ -0,0 +1,33 @@
1
+ import { resolveProfile } from "../domain/profiles/profile-resolution.js";
2
+ import { withProjectsLock } from "../shared/project-legacy.js";
3
+ import { listProjectManifests, writeManifest, } from "../shared/project-manifest.js";
4
+ import { projectSignals } from "../shared/repo-signals.js";
5
+ import { profileCatalog } from "./session-profile.js";
6
+ // A new project gets the profile its repository points at in `project.json` `profiles` (T-338
7
+ // P2), so its sessions start there without guessing again. Only a project that has no
8
+ // `profiles` yet, and only when the repository gives a real answer: base is what an absent
9
+ // list already means. The owner's edit is never replaced. Never throws: registering a project
10
+ // does not depend on the profiles being readable.
11
+ export async function fillProjectProfiles(projectId, repoPath) {
12
+ try {
13
+ const catalog = await profileCatalog();
14
+ const resolution = resolveProfile({
15
+ profiles: catalog.profiles,
16
+ signals: await projectSignals(repoPath),
17
+ });
18
+ if (resolution.primary === "base" || resolution.confidence === "none")
19
+ return null;
20
+ return await withProjectsLock(async () => {
21
+ const manifest = (await listProjectManifests()).find((candidate) => candidate.id === projectId);
22
+ if (!manifest || manifest.profiles !== undefined)
23
+ return null;
24
+ const profiles = [resolution.primary];
25
+ await writeManifest({ ...manifest, profiles });
26
+ return profiles;
27
+ });
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ //# sourceMappingURL=project-profile-fill.js.map
@@ -0,0 +1,158 @@
1
+ import { appendFile, mkdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { resolveProfile, } from "../domain/profiles/profile-resolution.js";
4
+ import { oceanPath, SYSTEM_DIR } from "../shared/paths.js";
5
+ import { listProjectManifests, projectProfiles, } from "../shared/project-manifest.js";
6
+ import { projectSignals } from "../shared/repo-signals.js";
7
+ import { listProfileNames } from "./profile-files.js";
8
+ import { loadProfile } from "./profile-loader.js";
9
+ // The profile a session works in (T-338 P2, plan §3.2–3.3): resolveProfile() over the
10
+ // installed profiles, the project's `profiles` list and the repository's signals, delivered
11
+ // as `profile=<name>` on the start line and one brief line beside it. Never throws: a session
12
+ // keeps its bootstrap whatever state the profiles are in.
13
+ export const PROFILE_BRIEF_MAX_BYTES = 200;
14
+ export const PROFILE_BUNDLE_MAX_BYTES = 2_048;
15
+ function summary(profile) {
16
+ return {
17
+ name: profile.name,
18
+ kind: profile.kind ?? "role",
19
+ description: profile.description,
20
+ skills: profile.skills,
21
+ triggers: profile.triggers ?? [],
22
+ signals: profile.signals ?? [],
23
+ mcp: profile.mcp ?? [],
24
+ connectors: profile.connectors ?? [],
25
+ composio: profile.composio ?? [],
26
+ plugins: profile.plugins ?? [],
27
+ policies: profile.policies ?? [],
28
+ tools: profile.tools ?? [],
29
+ instructions: profile.instructions,
30
+ };
31
+ }
32
+ export async function profileCatalog() {
33
+ const names = await listProfileNames().catch(() => []);
34
+ const catalog = { profiles: [], problems: [] };
35
+ for (const name of names) {
36
+ try {
37
+ catalog.profiles.push(summary(await loadProfile(name)));
38
+ }
39
+ catch (error) {
40
+ catalog.problems.push({
41
+ name,
42
+ error: error instanceof Error ? error.message : String(error),
43
+ });
44
+ }
45
+ }
46
+ return catalog;
47
+ }
48
+ async function declaredProfiles(projectId) {
49
+ const manifests = await listProjectManifests().catch(() => []);
50
+ const manifest = manifests.find((candidate) => candidate.id === projectId);
51
+ return manifest ? projectProfiles(manifest) : [];
52
+ }
53
+ export async function sessionProfile(options) {
54
+ try {
55
+ const catalog = options.catalog ?? (await profileCatalog());
56
+ const [projectProfilesList, signals] = await Promise.all([
57
+ options.projectId ? declaredProfiles(options.projectId) : [],
58
+ options.cwd
59
+ ? projectSignals(options.cwd).catch(() => new Set())
60
+ : new Set(),
61
+ ]);
62
+ const resolution = resolveProfile({
63
+ profiles: catalog.profiles,
64
+ projectProfiles: projectProfilesList,
65
+ signals,
66
+ prompt: options.prompt,
67
+ });
68
+ return {
69
+ ...resolution,
70
+ profile: catalog.profiles.find((candidate) => candidate.name === resolution.primary) ?? null,
71
+ };
72
+ }
73
+ catch (error) {
74
+ return {
75
+ primary: "base",
76
+ secondary: [],
77
+ confidence: "none",
78
+ why: [
79
+ `profiles unreadable: ${error instanceof Error ? error.message : String(error)}`,
80
+ ],
81
+ profile: null,
82
+ };
83
+ }
84
+ }
85
+ function fitBytes(text, max) {
86
+ if (Buffer.byteLength(text, "utf8") <= max)
87
+ return text;
88
+ let out = text;
89
+ while (out && Buffer.byteLength(`${out}…`, "utf8") > max)
90
+ out = out.slice(0, -1);
91
+ return `${out.trimEnd()}…`;
92
+ }
93
+ // "Profile frontend · skills: a, b · tools: ocean-uiux · connectors: Meta", at most 200 bytes.
94
+ // Whole names only; the last group is cut with an ellipsis when the line would overflow.
95
+ export function profileBrief(session) {
96
+ const profile = session.profile;
97
+ if (!profile)
98
+ return null;
99
+ const parts = [`Profile ${profile.name}`];
100
+ if (profile.skills.length)
101
+ parts.push(`skills: ${profile.skills.slice(0, 6).join(", ")}`);
102
+ if (profile.mcp.length)
103
+ parts.push(`tools: ${profile.mcp.join(", ")}`);
104
+ if (profile.connectors.length)
105
+ parts.push(`connectors: ${profile.connectors.join(", ")}`);
106
+ if (profile.composio.length)
107
+ parts.push(`composio: ${profile.composio.join(", ")}`);
108
+ if (session.secondary.length)
109
+ parts.push(`also: ${session.secondary.join(", ")}`);
110
+ return fitBytes(parts.join(" · "), PROFILE_BRIEF_MAX_BYTES);
111
+ }
112
+ // The whole bundle for `ocean_profile_get`: the fields as a short header and the instructions,
113
+ // capped at 2 KB.
114
+ export function profileBundle(profile) {
115
+ const list = (label, values) => values.length ? [`${label}: ${values.join(", ")}`] : [];
116
+ const lines = [
117
+ `# Profile ${profile.name} (${profile.kind})`,
118
+ ...(profile.description ? [profile.description] : []),
119
+ ...list("Skills", profile.skills),
120
+ ...list("Gateway tools", profile.mcp),
121
+ ...list("Connectors", profile.connectors),
122
+ ...list("Composio", profile.composio),
123
+ ...list("Plugins", profile.plugins),
124
+ ...list("Triggers", profile.triggers),
125
+ ];
126
+ const text = profile.instructions
127
+ ? `${lines.join("\n")}\n\n${profile.instructions}`
128
+ : lines.join("\n");
129
+ return fitBytes(text, PROFILE_BUNDLE_MAX_BYTES);
130
+ }
131
+ // Every session choice is one line in bridge/state/profiles/selections.jsonl beside `ocean
132
+ // run`'s task selections (plan §3.2); P5 reads it to find misroutes. Best-effort.
133
+ export async function recordProfileSelection(entry) {
134
+ const log = oceanPath(SYSTEM_DIR, "state", "profiles", "selections.jsonl");
135
+ try {
136
+ await mkdir(path.dirname(log), { recursive: true, mode: 0o700 });
137
+ await appendFile(log, `${JSON.stringify({
138
+ ts: new Date().toISOString(),
139
+ source: entry.source,
140
+ project: entry.project,
141
+ profile: entry.session.primary,
142
+ secondary: entry.session.secondary,
143
+ confidence: entry.session.confidence,
144
+ why: entry.session.why,
145
+ })}\n`, { mode: 0o600 });
146
+ }
147
+ catch { }
148
+ }
149
+ // The base profile's body (T-339 P1): the working style and the short "where things live" that
150
+ // left `charter/core.md`. Every session gets it — by the start hook, or `ocean_context` for a
151
+ // client without one — whatever its primary profile, capped at 1,200 bytes.
152
+ export const BASE_BODY_MAX_BYTES = 1_200;
153
+ export function baseProfileBody(catalog) {
154
+ const base = catalog.profiles.find((profile) => profile.name === "base");
155
+ const body = base?.instructions.trim();
156
+ return body ? fitBytes(body, BASE_BODY_MAX_BYTES) : null;
157
+ }
158
+ //# sourceMappingURL=session-profile.js.map
@@ -0,0 +1,110 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { parse as parseYaml } from "yaml";
3
+ import { compileTriggers, prepareText, triggerHits, } from "./context-triggers.js";
4
+ import { CHARTER_DIR, oceanPath, POLICIES_DIR, resolveWithin, } from "./paths.js";
5
+ // The owner's rules: `charter/core.md` and the policy modules beside it. One reader for
6
+ // `ocean policy` and the `ocean_policy` MCP tool, so a hookless client reads what a CLI reads.
7
+ const NAME = /^[a-z][a-z-]*$/;
8
+ // `core` is the bootstrap itself, the rest are the policy files.
9
+ export const CORE_RULES = "core";
10
+ export async function policyNames() {
11
+ const entries = await readdir(oceanPath(POLICIES_DIR), {
12
+ withFileTypes: true,
13
+ }).catch(() => []);
14
+ return entries
15
+ .filter((entry) => entry.isFile() &&
16
+ entry.name.endsWith(".md") &&
17
+ entry.name !== "README.md")
18
+ .map((entry) => entry.name.slice(0, -3))
19
+ .sort();
20
+ }
21
+ export async function readCoreRules() {
22
+ return readFile(oceanPath(CHARTER_DIR, "core.md"), "utf8").catch(() => null);
23
+ }
24
+ // `core` or one policy's text; an unknown or malformed name throws.
25
+ export async function readRules(name) {
26
+ if (name === CORE_RULES) {
27
+ const core = await readCoreRules();
28
+ if (core === null)
29
+ throw new Error("No rules: charter/core.md is missing");
30
+ return core;
31
+ }
32
+ if (!NAME.test(name) || !(await policyNames()).includes(name))
33
+ throw new Error(`Unknown policy: ${name}`);
34
+ return readFile(resolveWithin(oceanPath(POLICIES_DIR), `${name}.md`), "utf8");
35
+ }
36
+ // For a client with no hook: the rules arrive through `ocean_context` (T-339 P1 folded
37
+ // `ocean_policy` into it). Null when the user has no rules, so nothing points at an empty store.
38
+ export async function rulesPointer() {
39
+ if ((await readCoreRules()) === null)
40
+ return null;
41
+ return 'Rules: before your first substantial reply, call ocean_context with policy "core" (language, direction, hard boundaries); a policy\'s full text: the same call with its name.';
42
+ }
43
+ // ── Policy catalog (T-339 P1) ────────────────────────────────────────────────────────────────
44
+ // Each policy declares in its frontmatter the words that summon it (`triggers:`, English and
45
+ // Iraqi Arabic) and its hard lines (`digest:`, 200 bytes or less). The prompt hook injects the
46
+ // digest of at most two matching policies per prompt, once per session; a hookless client gets
47
+ // the list from `ocean_context`.
48
+ export const POLICY_DIGEST_MAX_BYTES = 200;
49
+ const POLICIES_PER_PROMPT = 2;
50
+ const FENCE = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
51
+ export function parsePolicy(name, text) {
52
+ const problems = [];
53
+ let fields = {};
54
+ const match = FENCE.exec(text.replace(/^/, ""));
55
+ if (!match)
56
+ problems.push("no frontmatter");
57
+ else
58
+ try {
59
+ const parsed = parseYaml(match[1] ?? "", { prettyErrors: false });
60
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
61
+ fields = parsed;
62
+ else
63
+ problems.push("frontmatter is not a mapping");
64
+ }
65
+ catch {
66
+ problems.push("frontmatter is not valid YAML");
67
+ }
68
+ const triggers = Array.isArray(fields.triggers)
69
+ ? fields.triggers.filter((item) => typeof item === "string" && !!item.trim())
70
+ : [];
71
+ const digest = typeof fields.digest === "string" ? fields.digest.trim() : "";
72
+ if (match && !triggers.length)
73
+ problems.push("no triggers");
74
+ if (match && !digest)
75
+ problems.push("no digest");
76
+ if (Buffer.byteLength(digest, "utf8") > POLICY_DIGEST_MAX_BYTES)
77
+ problems.push(`digest over ${POLICY_DIGEST_MAX_BYTES} bytes`);
78
+ return { name, triggers, digest, problems };
79
+ }
80
+ export async function policyCatalog() {
81
+ const out = [];
82
+ for (const name of await policyNames()) {
83
+ const text = await readFile(resolveWithin(oceanPath(POLICIES_DIR), `${name}.md`), "utf8").catch(() => "");
84
+ out.push(parsePolicy(name, text));
85
+ }
86
+ return out;
87
+ }
88
+ // Most hits first, then name; at most `max`. A slash command or an empty prompt summons nothing.
89
+ export function routePolicies(catalog, prompt, options = {}) {
90
+ const max = options.max ?? POLICIES_PER_PROMPT;
91
+ if (!prompt.trim() || prompt.trimStart().startsWith("/"))
92
+ return [];
93
+ const text = prepareText(prompt);
94
+ const scored = catalog
95
+ .map((entry) => ({
96
+ entry,
97
+ ...triggerHits(compileTriggers(entry.triggers), text),
98
+ }))
99
+ .filter((item) => item.score > 0 && item.entry.digest)
100
+ .sort((a, b) => b.score - a.score || a.entry.name.localeCompare(b.entry.name));
101
+ return scored.slice(0, max).map((item) => ({
102
+ name: item.entry.name,
103
+ digest: item.entry.digest,
104
+ why: item.hits,
105
+ }));
106
+ }
107
+ export function policyLine(match) {
108
+ return `Policy ${match.name}: ${match.digest} — full: ocean policy ${match.name}`;
109
+ }
110
+ //# sourceMappingURL=charter.js.map