@amoree-code/ocean 2.23.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -53
- package/dist/application/clients/bundles.js +1 -1
- package/dist/application/clients/client-detect.js +291 -0
- package/dist/application/clients/clients.js +104 -25
- package/dist/application/clients/desktop-link.js +40 -0
- package/dist/application/clients/desktop-watcher.js +6 -4
- package/dist/application/clients/hook-trust.js +106 -0
- package/dist/application/clients/hooks.js +7 -1
- package/dist/application/clients/mcp-schema-cost.js +74 -0
- package/dist/application/clients/native.js +38 -2
- package/dist/application/clients/registry.js +51 -9
- package/dist/application/clients/status.js +7 -2
- package/dist/application/gateway/webhook-gateway.js +1 -1
- package/dist/application/integrations/charter-copies.js +1 -1
- package/dist/application/integrations/engine-entry-repair.js +4 -3
- package/dist/application/integrations/skill-auto-sync.js +2 -2
- package/dist/application/integrations/skill-filter.js +1 -1
- package/dist/application/integrations/skill-router.js +134 -90
- package/dist/application/layout/layout-apply.js +1 -1
- package/dist/application/layout/workspace-template.js +1 -1
- package/dist/application/onboarding/steps.js +121 -30
- package/dist/application/profiles/profile-doctor.js +118 -0
- package/dist/application/profiles/profile-migration-service.js +208 -0
- package/dist/application/profiles/profile-suggestion.js +3 -7
- package/dist/application/profiles/profile-upgrade-service.js +98 -86
- package/dist/application/pull/history-index.js +1 -1
- package/dist/application/pull/project-match.js +3 -3
- package/dist/application/pull/pull.js +1 -1
- package/dist/application/pull/server-capture.js +92 -9
- package/dist/application/scheduler/local-scheduler.js +2 -2
- package/dist/application/spend/claude-prices.js +55 -0
- package/dist/application/spend/claude-spend.js +365 -0
- package/dist/application/uninstall/uninstall.js +25 -3
- package/dist/application/upkeep/nightly-upkeep.js +4 -4
- package/dist/composition/runtime.js +2 -2
- package/dist/infrastructure/desktop/claude-export.js +1 -1
- package/dist/infrastructure/desktop/desktop-chat.js +60 -13
- package/dist/infrastructure/desktop/indexeddb.js +4 -4
- package/dist/infrastructure/desktop/leveldb.js +2 -2
- package/dist/infrastructure/filesystem/profile-loader.js +3 -45
- package/dist/infrastructure/filesystem/runtime-config-loader.js +1 -1
- package/dist/infrastructure/observability/runtime-logger.js +1 -1
- package/dist/infrastructure/process/agent-tool-executor.js +3 -3
- package/dist/infrastructure/process/process-supervisor.js +1 -1
- package/dist/infrastructure/process/service.js +8 -8
- package/dist/infrastructure/providers/openai-compatible.js +2 -2
- package/dist/infrastructure/providers/provider-invocation.js +1 -1
- package/dist/infrastructure/providers/session-facts-completer.js +78 -5
- package/dist/interfaces/cli/auth-command.js +2 -2
- package/dist/interfaces/cli/brief-command.js +1 -1
- package/dist/interfaces/cli/browser-command.js +6 -6
- package/dist/interfaces/cli/browser-findings.js +6 -9
- package/dist/interfaces/cli/browser-settings.js +10 -10
- package/dist/interfaces/cli/capture-command.js +6 -6
- package/dist/interfaces/cli/client-test-command.js +3 -3
- package/dist/interfaces/cli/clients-command.js +33 -6
- package/dist/interfaces/cli/command-aliases.js +56 -0
- package/dist/interfaces/cli/command-registry.js +48 -1414
- package/dist/interfaces/cli/commands/browser.js +5 -0
- package/dist/interfaces/cli/commands/capture.js +19 -0
- package/dist/interfaces/cli/commands/catalog.js +9 -0
- package/dist/interfaces/cli/commands/client.js +135 -0
- package/dist/interfaces/cli/commands/clients.js +33 -0
- package/dist/interfaces/cli/commands/connectors.js +14 -0
- package/dist/interfaces/cli/commands/context.js +9 -0
- package/dist/interfaces/cli/commands/cost.js +15 -0
- package/dist/interfaces/cli/commands/daily.js +11 -0
- package/dist/interfaces/cli/commands/day.js +25 -0
- package/dist/interfaces/cli/commands/dispatch.js +31 -0
- package/dist/interfaces/cli/commands/doctor.js +60 -0
- package/dist/interfaces/cli/commands/env.js +5 -0
- package/dist/interfaces/cli/commands/gateway.js +16 -0
- package/dist/interfaces/cli/commands/handoff.js +11 -0
- package/dist/interfaces/cli/commands/health.js +17 -0
- package/dist/interfaces/cli/commands/hook.js +142 -0
- package/dist/interfaces/cli/commands/idea.js +11 -0
- package/dist/interfaces/cli/commands/install.js +31 -0
- package/dist/interfaces/cli/commands/intent.js +14 -0
- package/dist/interfaces/cli/commands/intercept.js +22 -0
- package/dist/interfaces/cli/commands/layout.js +11 -0
- package/dist/interfaces/cli/commands/lifecycle.js +5 -0
- package/dist/interfaces/cli/commands/loop.js +73 -0
- package/dist/interfaces/cli/commands/market.js +11 -0
- package/dist/interfaces/cli/commands/mcp.js +57 -0
- package/dist/interfaces/cli/commands/memory.js +5 -0
- package/dist/interfaces/cli/commands/migrate.js +5 -0
- package/dist/interfaces/cli/commands/observe.js +11 -0
- package/dist/interfaces/cli/commands/obsidian.js +111 -0
- package/dist/interfaces/cli/commands/operate.js +7 -0
- package/dist/interfaces/cli/commands/policy.js +16 -0
- package/dist/interfaces/cli/commands/project.js +207 -0
- package/dist/interfaces/cli/commands/repair.js +20 -0
- package/dist/interfaces/cli/commands/run.js +52 -0
- package/dist/interfaces/cli/commands/schedule.js +58 -0
- package/dist/interfaces/cli/commands/service.js +21 -0
- package/dist/interfaces/cli/commands/session.js +182 -0
- package/dist/interfaces/cli/commands/sessions.js +12 -0
- package/dist/interfaces/cli/commands/setup.js +21 -0
- package/dist/interfaces/cli/commands/skill.js +159 -0
- package/dist/interfaces/cli/commands/tasks.js +10 -0
- package/dist/interfaces/cli/commands/update-remove.js +25 -0
- package/dist/interfaces/cli/connectors-command.js +150 -0
- package/dist/interfaces/cli/context-command.js +39 -3
- package/dist/interfaces/cli/cost-command.js +104 -0
- package/dist/interfaces/cli/curator-command.js +1 -1
- package/dist/interfaces/cli/daily-command.js +7 -1
- package/dist/interfaces/cli/desktop-command.js +43 -7
- package/dist/interfaces/cli/distill-command.js +7 -2
- package/dist/interfaces/cli/express-command.js +1 -1
- package/dist/interfaces/cli/failures-command.js +4 -4
- package/dist/interfaces/cli/gateway-findings.js +2 -2
- package/dist/interfaces/cli/governance-command.js +23 -16
- package/dist/interfaces/cli/handoff-command.js +1 -1
- package/dist/interfaces/cli/harvest-command.js +2 -2
- package/dist/interfaces/cli/help-command.js +53 -169
- package/dist/interfaces/cli/hygiene-command.js +1 -1
- package/dist/interfaces/cli/idea-command.js +1 -1
- package/dist/interfaces/cli/intercept-command.js +8 -7
- package/dist/interfaces/cli/interests-command.js +1 -1
- package/dist/interfaces/cli/layout-command.js +2 -0
- package/dist/interfaces/cli/market-command.js +9 -9
- package/dist/interfaces/cli/mcp-gateway-command.js +124 -7
- package/dist/interfaces/cli/mcp-probe-command.js +186 -0
- package/dist/interfaces/cli/mcp-status-command.js +5 -5
- package/dist/interfaces/cli/memory-command.js +41 -7
- package/dist/interfaces/cli/migrate-command.js +2 -2
- package/dist/interfaces/cli/note-command.js +1 -1
- package/dist/interfaces/cli/onboard-command.js +14 -0
- package/dist/interfaces/cli/operate-command.js +5 -5
- package/dist/interfaces/cli/profiles-command.js +61 -1
- package/dist/interfaces/cli/rhythm-command.js +11 -5
- package/dist/interfaces/cli/running-server-findings.js +1 -1
- package/dist/interfaces/cli/scorecard-command.js +8 -8
- package/dist/interfaces/cli/session-facts-command.js +2 -2
- package/dist/interfaces/cli/sessions-command.js +145 -0
- package/dist/interfaces/cli/setup-command.js +15 -2
- package/dist/interfaces/cli/tasks-command.js +63 -13
- package/dist/interfaces/cli/telemetry-command.js +4 -4
- package/dist/interfaces/cli/uninstall-command.js +1 -1
- package/dist/interfaces/cli/week-failures.js +32 -0
- package/dist/main.js +12 -0
- package/node_modules/@ocean/brain/dist/{infrastructure/brain/brain-index.js → brain-index.js} +2 -2
- package/node_modules/@ocean/brain/dist/{brain/brain-markdown.js → brain-markdown.js} +1 -1
- package/node_modules/@ocean/brain/dist/{brain/brain-service.js → brain-service.js} +12 -2
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +92 -16
- package/node_modules/@ocean/brain/dist/memory/extraction-log.js +125 -0
- package/node_modules/@ocean/brain/dist/memory/extraction-retry.js +54 -0
- package/node_modules/@ocean/brain/dist/memory/fact-routing.js +44 -1
- package/node_modules/@ocean/brain/dist/memory/lesson-activation.js +2 -2
- package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +2 -2
- package/node_modules/@ocean/brain/dist/memory/lessons.js +1 -1
- package/node_modules/@ocean/brain/dist/memory/memory-audit.js +2 -2
- package/node_modules/@ocean/brain/dist/memory/memory-harvest.js +1 -1
- package/node_modules/@ocean/brain/dist/memory/memory-paths.js +8 -0
- package/node_modules/@ocean/brain/dist/memory/memory-review.js +31 -3
- package/node_modules/@ocean/brain/dist/memory/memory-trash.js +29 -0
- package/node_modules/@ocean/brain/dist/memory/memory-write.js +4 -2
- package/node_modules/@ocean/brain/dist/memory/model-narrative.js +2 -2
- package/node_modules/@ocean/brain/dist/memory/profile-facts.js +1 -1
- package/node_modules/@ocean/brain/dist/memory/routing.json +6 -6
- package/node_modules/@ocean/{market/dist/skills → brain/dist/memory}/signal-detection.js +1 -1
- package/node_modules/@ocean/brain/dist/{memory → people}/people.js +1 -1
- package/node_modules/@ocean/brain/dist/sessions-capture/session-facts.js +625 -0
- package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-promotion.js +7 -15
- package/node_modules/@ocean/brain/dist/{memory → sessions-capture}/session-summary.js +1 -1
- package/node_modules/@ocean/brain/dist/sessions-capture/session-triage.js +52 -0
- package/node_modules/@ocean/brain/package.json +1 -1
- package/node_modules/@ocean/connect/dist/connectors/connector-hub.js +173 -0
- package/node_modules/@ocean/{market → connect}/dist/install/default-marketplace.js +6 -2
- package/node_modules/@ocean/{market → connect}/dist/install/marketplace-service.js +1 -1
- package/node_modules/@ocean/connect/dist/mcp/mcp-gateway.js +987 -0
- package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-launch.js +102 -5
- package/node_modules/@ocean/{market → connect}/dist/registry/official-registry.js +1 -1
- package/node_modules/@ocean/{market → connect}/dist/security/permissions.js +1 -1
- package/node_modules/@ocean/{market → connect}/dist/skills/skill-hub.js +104 -6
- package/node_modules/@ocean/{market → connect}/package.json +2 -2
- package/node_modules/@ocean/context/dist/{context/context-ladder.js → context-ladder.js} +3 -3
- package/node_modules/@ocean/context/dist/{context/context-references.js → context-references.js} +5 -4
- package/node_modules/@ocean/context/dist/{context/context-cost.js → context-size.js} +6 -6
- package/node_modules/@ocean/context/dist/{context/intent-router.js → intent-router.js} +1 -1
- package/node_modules/@ocean/context/dist/{context/resource-injection.js → resource-injection.js} +3 -1
- package/node_modules/@ocean/context/package.json +1 -1
- package/node_modules/@ocean/core/dist/domain/brain/brain-record.js +1 -1
- package/node_modules/@ocean/core/dist/domain/capabilities/capability-manifest.js +5 -5
- package/node_modules/@ocean/core/dist/domain/connector-entry.js +86 -0
- package/node_modules/@ocean/core/dist/domain/context/context.js +1 -1
- package/node_modules/@ocean/core/dist/domain/context/project-id.js +8 -2
- package/node_modules/@ocean/core/dist/domain/{evidence/evidence.js → evidence.js} +1 -1
- package/node_modules/@ocean/core/dist/domain/mcp/memory-contract.js +4 -1
- package/node_modules/@ocean/core/dist/domain/ports/brain-index-port.js +1 -1
- package/node_modules/@ocean/core/dist/domain/profiles/profile-markdown.js +40 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-resolution.js +276 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-selection.js +23 -60
- package/node_modules/@ocean/core/dist/domain/profiles/profile-upgrade.js +2 -2
- package/node_modules/@ocean/core/dist/domain/profiles/profile.js +66 -6
- package/node_modules/@ocean/core/dist/domain/profiles/runtime-config.js +1 -1
- package/node_modules/@ocean/core/dist/domain/runs/agent-tools.js +2 -2
- package/node_modules/@ocean/core/dist/domain/sessions/session-identity.js +53 -0
- package/node_modules/@ocean/core/dist/domain/sessions/session-metadata.js +208 -0
- package/node_modules/@ocean/core/dist/domain/{tasks/task-id.js → task-id.js} +2 -2
- package/node_modules/@ocean/core/dist/profiles/profile-files.js +57 -0
- package/node_modules/@ocean/core/dist/profiles/profile-loader.js +97 -0
- package/node_modules/@ocean/core/dist/profiles/project-profile-fill.js +33 -0
- package/node_modules/@ocean/core/dist/profiles/session-profile.js +158 -0
- package/node_modules/@ocean/core/dist/shared/charter.js +110 -0
- package/node_modules/@ocean/core/dist/shared/context-ack.js +1 -1
- package/node_modules/@ocean/core/dist/shared/context-triggers.js +67 -0
- package/node_modules/@ocean/core/dist/shared/paths.js +6 -6
- package/node_modules/@ocean/core/dist/shared/project-legacy.js +232 -0
- package/node_modules/@ocean/core/dist/shared/project-manifest.js +308 -0
- package/node_modules/@ocean/core/dist/shared/project-names.js +87 -0
- package/node_modules/@ocean/core/dist/shared/project-register.js +560 -0
- package/node_modules/@ocean/core/dist/shared/project-resolution.js +83 -861
- package/node_modules/@ocean/core/dist/shared/repo-signals.js +45 -0
- package/node_modules/@ocean/core/dist/shared/task-reference.js +1 -1
- package/node_modules/@ocean/core/dist/shared/text-tokens.js +37 -0
- package/node_modules/@ocean/core/dist/shared/tool-groups.js +224 -0
- package/node_modules/@ocean/core/package.json +4 -1
- package/node_modules/@ocean/services/dist/day/day.js +45 -3
- package/node_modules/@ocean/services/dist/{distill → day}/distill.js +29 -3
- package/node_modules/@ocean/services/dist/{harvest → day}/harvest.js +54 -14
- package/node_modules/@ocean/services/dist/{brief → day}/interest-discovery.js +3 -3
- package/node_modules/@ocean/services/dist/day/note.js +2 -2
- package/node_modules/@ocean/services/dist/{onboarding → day}/onboarding.js +1 -1
- package/node_modules/@ocean/services/dist/day/patterns.js +68 -0
- package/node_modules/@ocean/services/dist/{curator → health}/curator.js +5 -5
- package/node_modules/@ocean/services/dist/{journey → health}/failures.js +7 -5
- package/node_modules/@ocean/services/dist/{hygiene → health}/hygiene.js +2 -2
- package/node_modules/@ocean/services/dist/{journey → health}/lesson-effect.js +1 -1
- package/node_modules/@ocean/services/dist/{scorecard → health}/scorecard.js +3 -3
- package/node_modules/@ocean/services/dist/{upkeep → health}/upkeep.js +2 -2
- package/node_modules/@ocean/services/dist/{doctor → health}/workspace-doctor.js +57 -17
- package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-session.js +1 -1
- package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/call-ledger.js +3 -0
- package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-client.js +19 -3
- package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/obsidian-server.js +4 -4
- package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/ocean-server.js +423 -34
- package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/conflict-log.js +1 -1
- package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/folder-templates.js +8 -5
- package/node_modules/@ocean/services/dist/projects/project-doctor.js +173 -0
- package/node_modules/@ocean/services/dist/projects/project-snippet.js +9 -0
- package/node_modules/@ocean/services/dist/projects/projects-overview.js +2 -2
- package/node_modules/@ocean/services/package.json +1 -1
- package/node_modules/@ocean/{loop/dist/loops → work/dist/runs}/guard-runtime.js +3 -3
- package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/memory-knowledge-operations.js +4 -12
- package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-contract.js +2 -2
- package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/project-operations.js +2 -1
- package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/task-operations.js +4 -4
- package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/write-guard.js +1 -1
- package/node_modules/@ocean/{loop → work}/dist/runs/prompt-assembly.js +2 -2
- package/node_modules/@ocean/{loop → work}/dist/runs/run-agent.js +4 -4
- package/node_modules/@ocean/{loop → work}/dist/runs/tool-loop.js +4 -4
- package/node_modules/@ocean/work/dist/sessions/hooks/desktop-facts.js +309 -0
- package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-end-hook.js +36 -5
- package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-facts-hook.js +144 -14
- package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/session-start-hook.js +129 -12
- package/node_modules/@ocean/work/dist/sessions/hooks/start-brief.js +110 -0
- package/node_modules/@ocean/work/dist/sessions/hooks/unlinked-warning.js +68 -0
- package/node_modules/@ocean/{loop → work}/dist/sessions/session-closeout.js +4 -4
- package/node_modules/@ocean/{loop → work}/dist/sessions/session-projects.js +13 -3
- package/node_modules/@ocean/work/dist/sessions/session-relink.js +300 -0
- package/node_modules/@ocean/{loop → work}/dist/sessions/session-retention.js +1 -1
- package/node_modules/@ocean/{loop → work}/dist/tasks/list-tasks.js +7 -2
- package/node_modules/@ocean/{loop → work}/dist/tasks/renumber-tasks.js +4 -2
- package/node_modules/@ocean/{loop → work}/dist/tasks/session-task.js +2 -2
- package/node_modules/@ocean/{loop → work}/dist/tasks/sync-task-prs.js +77 -7
- package/node_modules/@ocean/work/dist/tasks/task-git.js +63 -0
- package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop.js +4 -4
- package/node_modules/@ocean/{loop → work}/dist/tasks/verification-readiness.js +1 -1
- package/node_modules/@ocean/{loop → work}/dist/tasks/verify-task.js +1 -1
- package/node_modules/@ocean/{loop → work}/package.json +2 -2
- package/ocean-marketplace.json +41 -41
- package/package.json +12 -11
- package/skills/core/daily-harvest/SKILL.md +1 -1
- package/skills/core/ocean-memory/SKILL.md +4 -0
- package/skills/core/use-browser/SKILL.md +30 -7
- package/skills/index.json +1 -1
- package/templates/profiles/default.md +44 -0
- package/templates/profiles/developer.md +45 -0
- package/templates/profiles/reviewer.md +44 -0
- package/templates/profiles/strategist.md +44 -0
- package/templates/profiles-v3/analysis.md +16 -0
- package/templates/profiles-v3/backend.md +16 -0
- package/templates/profiles-v3/base.md +57 -0
- package/templates/profiles-v3/code-review.md +16 -0
- package/templates/profiles-v3/devops.md +16 -0
- package/templates/profiles-v3/docs-office.md +16 -0
- package/templates/profiles-v3/frontend.md +16 -0
- package/templates/profiles-v3/learning.md +16 -0
- package/templates/profiles-v3/marketing-ads.md +16 -0
- package/templates/profiles-v3/marketing-content-seo.md +16 -0
- package/templates/profiles-v3/ocean-ops.md +16 -0
- package/templates/profiles-v3/product-strategy.md +16 -0
- package/templates/profiles-v3/qa-testing.md +16 -0
- package/templates/profiles-v3/security.md +16 -0
- package/templates/workspace/MANIFEST.json +1 -0
- package/templates/workspace/charter/core.md +22 -90
- package/templates/workspace/charter/policies/README.md +7 -1
- package/templates/workspace/charter/policies/claude-code-context.md +6 -1
- package/templates/workspace/charter/policies/concise-output.md +5 -0
- package/templates/workspace/charter/policies/context.md +5 -0
- package/templates/workspace/charter/policies/contracts/task.md +2 -2
- package/templates/workspace/charter/policies/git.md +5 -0
- package/templates/workspace/charter/policies/graph.md +6 -1
- package/templates/workspace/charter/policies/knowledge.md +11 -4
- package/templates/workspace/charter/policies/layout.md +23 -0
- package/templates/workspace/charter/policies/lifecycle.md +5 -0
- package/templates/workspace/charter/policies/memory.md +5 -0
- package/templates/workspace/charter/policies/minimal-change.md +5 -0
- package/templates/workspace/charter/policies/models.md +5 -0
- package/templates/workspace/charter/policies/response.md +5 -0
- package/templates/workspace/charter/policies/skill-observer.md +12 -0
- package/templates/workspace/charter/policies/stack.md +5 -0
- package/templates/workspace/charter/policies/task.md +17 -3
- package/templates/workspace/charter/policies/verification.md +5 -0
- package/node_modules/@ocean/brain/dist/evidence/verification-report.js +0 -13
- package/node_modules/@ocean/brain/dist/memory/daily-narrative.js +0 -142
- package/node_modules/@ocean/brain/dist/memory/session-facts.js +0 -283
- package/node_modules/@ocean/context/dist/context/context-compression.js +0 -66
- package/node_modules/@ocean/loop/dist/hooks/desktop-facts.js +0 -174
- package/node_modules/@ocean/loop/dist/operations/task-linker.js +0 -40
- package/node_modules/@ocean/loop/dist/sessions/session-pointer.js +0 -133
- package/node_modules/@ocean/loop/dist/tasks/task-git.js +0 -28
- package/node_modules/@ocean/market/dist/mcp/mcp-gateway.js +0 -533
- package/templates/profiles/default.json +0 -51
- package/templates/profiles/developer.json +0 -51
- package/templates/profiles/reviewer.json +0 -51
- package/templates/profiles/strategist.json +0 -51
- /package/node_modules/@ocean/brain/dist/{brain/brain-eval.js → brain-eval.js} +0 -0
- /package/node_modules/@ocean/brain/dist/{brain/brain-reindex.js → brain-reindex.js} +0 -0
- /package/node_modules/@ocean/brain/dist/{capture → sessions-capture}/inbox-sync.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/adapters/mcp-adapter.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/adapters/owned-directory.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/adapters/plugin-adapter.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/adapters/skill-adapter.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/capability/adapter.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/capability/catalog.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/capability/content-digest.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/capability/registry.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/install/lock.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/install/own-server.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/mcp/chrome-debugging.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-connection.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/mcp/mcp-runner.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/security/description-scan.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/security/secrets.js +0 -0
- /package/node_modules/@ocean/{market → connect}/dist/skills/core-skill-sync.js +0 -0
- /package/node_modules/@ocean/context/dist/{context/context-packet.js → context-packet.js} +0 -0
- /package/node_modules/@ocean/core/dist/domain/{process/process-events.js → process-events.js} +0 -0
- /package/node_modules/@ocean/core/dist/domain/{redaction/redaction.js → redaction.js} +0 -0
- /package/node_modules/@ocean/services/dist/{brief → day}/brief.js +0 -0
- /package/node_modules/@ocean/services/dist/{express → day}/express.js +0 -0
- /package/node_modules/@ocean/services/dist/{brief → day}/source-registry.json +0 -0
- /package/node_modules/@ocean/services/dist/{journey → health}/telemetry.js +0 -0
- /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-service.js +0 -0
- /package/node_modules/@ocean/services/dist/{browser → integrations/browser}/browser-task-runner.js +0 -0
- /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/mcp-session.js +0 -0
- /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/server-version.js +0 -0
- /package/node_modules/@ocean/services/dist/{infrastructure → integrations}/mcp/tool-registry.js +0 -0
- /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/inbox-promotion.js +0 -0
- /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-discovery.js +0 -0
- /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-ingestion.js +0 -0
- /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-sync.js +0 -0
- /package/node_modules/@ocean/services/dist/{obsidian → integrations/obsidian}/vault-writer.js +0 -0
- /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/operation-scope.js +0 -0
- /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-io.js +0 -0
- /package/node_modules/@ocean/{loop/dist → work/dist/runs}/operations/record-operations.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/runs/run-authorization.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/runs/session-tokens.js +0 -0
- /package/node_modules/@ocean/{loop/dist/handoff → work/dist/sessions}/handoff-service.js +0 -0
- /package/node_modules/@ocean/{loop/dist → work/dist/sessions}/hooks/lifecycle-hooks.js +0 -0
- /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-store.js +0 -0
- /package/node_modules/@ocean/{loop/dist/infrastructure/persistence → work/dist/sessions}/session-validator.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/tasks/archive-tasks.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/tasks/checkpoint-task.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/tasks/claim-task.js +0 -0
- /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/iteration-graph.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/tasks/new-task.js +0 -0
- /package/node_modules/@ocean/{loop/dist/loops → work/dist/tasks}/task-loop-record.js +0 -0
- /package/node_modules/@ocean/{loop → work}/dist/tasks/task-verification.js +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
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 { bumpRetry, retryGate, } from "@ocean/brain/memory/extraction-retry.js";
|
|
5
|
+
import { projectScope } from "@ocean/brain/memory/fact-routing.js";
|
|
6
|
+
import { sessionFactsEnabled } from "@ocean/brain/memory/memory-audit.js";
|
|
7
|
+
import { captureSessionFacts, extractSessionFacts, } from "@ocean/brain/sessions-capture/session-facts.js";
|
|
8
|
+
import { ActivityTally, } from "@ocean/core/domain/sessions/session-metadata.js";
|
|
9
|
+
import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
10
|
+
import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|
|
11
|
+
import { bindConversation, conversationProjectDecision, } from "@ocean/core/shared/project-legacy.js";
|
|
12
|
+
// Fact capture from Claude Desktop's plain chat (T-315). Desktop has no hooks, so a run reads
|
|
13
|
+
// the conversations the app keeps locally (the reader is injected: it lives in cli) and
|
|
14
|
+
// sends the new turns of each conversation that has gone quiet to the same extraction T-313
|
|
15
|
+
// uses. A per-conversation cursor — the creation time of the newest message already claimed,
|
|
16
|
+
// which the app's store and the official export both carry — makes every turn read once,
|
|
17
|
+
// whichever source it came from: a run claims (cursor, newest] under a short lock, calls the
|
|
18
|
+
// model unlocked,
|
|
19
|
+
// and hands the turns back if the model gave no answer. Candidates carry
|
|
20
|
+
// `source: session:desktop:<uuid>`, so they are never auto-approved. No message text is ever
|
|
21
|
+
// written outside the candidates, the session record and the raw transcript (T-329): the state
|
|
22
|
+
// file and the run report hold ids, times and counts only.
|
|
23
|
+
//
|
|
24
|
+
// A conversation is read once it is closed (T-329), not every time it pauses: Desktop has no
|
|
25
|
+
// session end, so "closed" is quiet for DEFAULT_CLOSE_MS, or quiet for DEFAULT_QUIET_MS while a
|
|
26
|
+
// newer conversation has started since. One pass then sees the whole conversation, instead of
|
|
27
|
+
// summing quarter-hour stretches whose title stuck to the first one.
|
|
28
|
+
const DESKTOP_CLIENT = "claude-desktop";
|
|
29
|
+
const DEFAULT_QUIET_MS = 10 * 60 * 1000;
|
|
30
|
+
const DEFAULT_CLOSE_MS = 2 * 60 * 60 * 1000;
|
|
31
|
+
// Below this much new text a chat that is only quiet, not closed, is left for a later run
|
|
32
|
+
// (T-340): the stretch grows instead of costing one model call per few messages. A closed chat,
|
|
33
|
+
// or one saved on purpose, is read whatever its size.
|
|
34
|
+
const MIN_NEW_CHARS = 2_000;
|
|
35
|
+
// The conversation as read, kept whole so a later pass (or a better model) can read it again
|
|
36
|
+
// without the app still holding it. Local only, owner-readable, rewritten on each pass.
|
|
37
|
+
export function desktopTranscriptFile(uuid) {
|
|
38
|
+
return oceanPath(SYSTEM_DIR, "state", "transcripts", DESKTOP_CLIENT, `${uuid.replace(/[^\w-]/g, "_")}.jsonl`);
|
|
39
|
+
}
|
|
40
|
+
// Written when the kept copy is missing or ends before the conversation does, so a
|
|
41
|
+
// conversation read before transcripts were kept gets one too.
|
|
42
|
+
async function keepTranscript(conversation) {
|
|
43
|
+
const file = desktopTranscriptFile(conversation.uuid);
|
|
44
|
+
const kept = conversation.messages.filter((message) => message.createdAt && message.text.trim());
|
|
45
|
+
const last = kept.at(-1)?.createdAt;
|
|
46
|
+
if (!last)
|
|
47
|
+
return;
|
|
48
|
+
try {
|
|
49
|
+
const tail = (await readFile(file, "utf8")).trimEnd().split("\n").at(-1);
|
|
50
|
+
if (tail && JSON.parse(tail).at === last)
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// no copy yet, or unreadable: write it
|
|
55
|
+
}
|
|
56
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
57
|
+
const lines = kept.map((message) => JSON.stringify({
|
|
58
|
+
at: message.createdAt,
|
|
59
|
+
role: message.sender === "human" ? "user" : "assistant",
|
|
60
|
+
text: message.text,
|
|
61
|
+
}));
|
|
62
|
+
await atomicWrite(file, `${lines.join("\n")}\n`, 0o600);
|
|
63
|
+
}
|
|
64
|
+
export function desktopFactsStateFile() {
|
|
65
|
+
return oceanPath(SYSTEM_DIR, "state", "memory", "desktop", "cursors.json");
|
|
66
|
+
}
|
|
67
|
+
// The last run's outcome, for `ocean doctor`: status, counts and an error code, never text.
|
|
68
|
+
export function desktopFactsLastRunFile() {
|
|
69
|
+
return oceanPath(SYSTEM_DIR, "state", "memory", "desktop", "last-run.json");
|
|
70
|
+
}
|
|
71
|
+
export async function recordDesktopRun(run) {
|
|
72
|
+
await mkdir(path.dirname(desktopFactsLastRunFile()), {
|
|
73
|
+
recursive: true,
|
|
74
|
+
mode: 0o700,
|
|
75
|
+
});
|
|
76
|
+
await atomicWrite(desktopFactsLastRunFile(), `${JSON.stringify(run, null, 2)}\n`, 0o600);
|
|
77
|
+
}
|
|
78
|
+
async function readState() {
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(await readFile(desktopFactsStateFile(), "utf8"));
|
|
81
|
+
if (parsed && typeof parsed.conversations === "object") {
|
|
82
|
+
// Only claims in the current shape count; any other is read from the start.
|
|
83
|
+
for (const [uuid, claim] of Object.entries(parsed.conversations))
|
|
84
|
+
if (typeof claim?.to !== "string")
|
|
85
|
+
delete parsed.conversations[uuid];
|
|
86
|
+
return parsed;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// no state yet, or unreadable: start from the beginning of each conversation
|
|
91
|
+
}
|
|
92
|
+
return { conversations: {} };
|
|
93
|
+
}
|
|
94
|
+
async function writeState(state) {
|
|
95
|
+
await atomicWrite(desktopFactsStateFile(), `${JSON.stringify(state, null, 2)}\n`, 0o600);
|
|
96
|
+
}
|
|
97
|
+
async function locked(run) {
|
|
98
|
+
await mkdir(path.dirname(desktopFactsStateFile()), {
|
|
99
|
+
recursive: true,
|
|
100
|
+
mode: 0o700,
|
|
101
|
+
});
|
|
102
|
+
return withFileLock(desktopFactsStateFile(), async () => run(await readState()));
|
|
103
|
+
}
|
|
104
|
+
const toTurn = (message) => ({
|
|
105
|
+
role: message.sender === "human" ? "user" : "assistant",
|
|
106
|
+
text: message.text,
|
|
107
|
+
});
|
|
108
|
+
export async function runDesktopFacts(options) {
|
|
109
|
+
if (!(await (options.enabled ?? sessionFactsEnabled)()))
|
|
110
|
+
return { status: "off" };
|
|
111
|
+
const read = await options.read();
|
|
112
|
+
if (read.status === "absent")
|
|
113
|
+
return { status: "absent" };
|
|
114
|
+
const now = (options.now ?? new Date()).getTime();
|
|
115
|
+
const quietMs = options.latest ? 0 : (options.quietMs ?? DEFAULT_QUIET_MS);
|
|
116
|
+
const closeMs = options.latest
|
|
117
|
+
? 0
|
|
118
|
+
: (options.closeMs ?? options.quietMs ?? DEFAULT_CLOSE_MS);
|
|
119
|
+
const newest = read.conversations.reduce((max, c) => Math.max(max, Date.parse(c.updatedAt) || 0), 0);
|
|
120
|
+
const conversations = options.latest
|
|
121
|
+
? read.conversations
|
|
122
|
+
.filter((c) => (Date.parse(c.updatedAt) || 0) === newest)
|
|
123
|
+
.slice(0, 1)
|
|
124
|
+
: read.conversations;
|
|
125
|
+
if (options.project) {
|
|
126
|
+
if (!options.latest)
|
|
127
|
+
throw new Error("a project binds only the latest chat");
|
|
128
|
+
for (const conversation of conversations)
|
|
129
|
+
await bindConversation(conversation.uuid, options.project);
|
|
130
|
+
}
|
|
131
|
+
const result = {
|
|
132
|
+
status: "done",
|
|
133
|
+
conversations: read.conversations.length,
|
|
134
|
+
waiting: 0,
|
|
135
|
+
upToDate: 0,
|
|
136
|
+
runs: [],
|
|
137
|
+
};
|
|
138
|
+
for (const conversation of conversations) {
|
|
139
|
+
const updated = Date.parse(conversation.updatedAt);
|
|
140
|
+
if (options.since && !(updated >= options.since.getTime()))
|
|
141
|
+
continue;
|
|
142
|
+
const idle = now - updated;
|
|
143
|
+
// A conversation still open is left for a later run.
|
|
144
|
+
const closed = options.latest ||
|
|
145
|
+
idle >= closeMs ||
|
|
146
|
+
(idle >= quietMs && updated < newest);
|
|
147
|
+
if (!closed) {
|
|
148
|
+
result.waiting++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const final = Boolean(options.latest) || idle >= closeMs;
|
|
152
|
+
const run = await captureOne(conversation, options.complete, now, final);
|
|
153
|
+
// Too little new text to spend a call on yet: it waits, like a chat still open.
|
|
154
|
+
if (run?.status === "small")
|
|
155
|
+
result.waiting++;
|
|
156
|
+
else if (run)
|
|
157
|
+
result.runs.push(run);
|
|
158
|
+
else
|
|
159
|
+
result.upToDate++;
|
|
160
|
+
// A paused provider answers no conversation; the rest wait for the next run.
|
|
161
|
+
if (run?.status === "paused")
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
// What a stretch of a Desktop chat did (T-334): its turns and the tool calls its text names
|
|
167
|
+
// (`[tool name: …]`, see desktop-chat.ts). Desktop keeps no working folder, branch or model.
|
|
168
|
+
function desktopActivity(messages) {
|
|
169
|
+
const tally = new ActivityTally();
|
|
170
|
+
for (const message of messages) {
|
|
171
|
+
if (!message.text.trim())
|
|
172
|
+
continue;
|
|
173
|
+
tally.turn(message.sender === "human" ? "user" : "assistant");
|
|
174
|
+
for (const call of message.text.matchAll(/^\[tool ([^\]:\s]+)/gm))
|
|
175
|
+
tally.tool(call[1]);
|
|
176
|
+
}
|
|
177
|
+
return tally.result();
|
|
178
|
+
}
|
|
179
|
+
async function captureOne(conversation, complete, now,
|
|
180
|
+
// Closed for good, or saved on purpose: read now even when the new text is small.
|
|
181
|
+
final = true) {
|
|
182
|
+
const dated = conversation.messages.filter((m) => m.createdAt);
|
|
183
|
+
const newest = dated.reduce((max, m) => (m.createdAt > max ? m.createdAt : max), "");
|
|
184
|
+
const claim = await locked(async (state) => {
|
|
185
|
+
const prior = state.conversations[conversation.uuid];
|
|
186
|
+
const from = prior?.to ?? "";
|
|
187
|
+
const retry = prior?.retry;
|
|
188
|
+
const go = "go";
|
|
189
|
+
// Nothing is claimed without a model, so a later run that has one still reads the turns.
|
|
190
|
+
if (newest <= from || !complete)
|
|
191
|
+
return { from, claimed: false, gate: go, retry };
|
|
192
|
+
if (!final) {
|
|
193
|
+
const fresh = dated
|
|
194
|
+
.filter((m) => m.createdAt > from)
|
|
195
|
+
.reduce((sum, m) => sum + m.text.length, 0);
|
|
196
|
+
if (fresh < MIN_NEW_CHARS)
|
|
197
|
+
return { from, claimed: false, gate: go, retry, small: true };
|
|
198
|
+
}
|
|
199
|
+
// A stretch that keeps failing waits, or is parked until the conversation gets a new message.
|
|
200
|
+
const gate = retryGate(retry, newest, now);
|
|
201
|
+
if (gate !== "go")
|
|
202
|
+
return { from, claimed: false, gate, retry };
|
|
203
|
+
state.conversations[conversation.uuid] = {
|
|
204
|
+
from,
|
|
205
|
+
to: newest,
|
|
206
|
+
at: new Date().toISOString(),
|
|
207
|
+
};
|
|
208
|
+
await writeState(state);
|
|
209
|
+
return { from, claimed: true, gate, retry };
|
|
210
|
+
});
|
|
211
|
+
const base = { uuid: conversation.uuid, from: claim.from, to: newest };
|
|
212
|
+
// Kept whole whether or not there is anything new, or a model to read it now.
|
|
213
|
+
await keepTranscript(conversation).catch(() => { });
|
|
214
|
+
if (newest <= claim.from)
|
|
215
|
+
return null;
|
|
216
|
+
if ("small" in claim && claim.small)
|
|
217
|
+
return { ...base, status: "small" };
|
|
218
|
+
if (claim.gate !== "go")
|
|
219
|
+
return {
|
|
220
|
+
...base,
|
|
221
|
+
status: "backoff",
|
|
222
|
+
...(claim.retry ? { reason: claim.retry.reason } : {}),
|
|
223
|
+
};
|
|
224
|
+
if (!claim.claimed || !complete)
|
|
225
|
+
return { ...base, status: "no-provider" };
|
|
226
|
+
const turns = dated
|
|
227
|
+
.filter((message) => message.createdAt > claim.from && message.text.trim())
|
|
228
|
+
.map(toTurn);
|
|
229
|
+
if (!turns.some((turn) => turn.role === "user"))
|
|
230
|
+
return { ...base, status: "no-user-text" };
|
|
231
|
+
// Decided before the call, so the model is told the project (T-335).
|
|
232
|
+
const decision = await conversationProjectDecision(conversation.uuid);
|
|
233
|
+
// The same call also returns the conversation's digest for the day's log (no second call).
|
|
234
|
+
const extraction = await extractSessionFacts({
|
|
235
|
+
turns,
|
|
236
|
+
complete,
|
|
237
|
+
digest: true,
|
|
238
|
+
scope: await projectScope(decision.projectId),
|
|
239
|
+
log: { sessionId: `desktop:${conversation.uuid}`, client: DESKTOP_CLIENT },
|
|
240
|
+
now,
|
|
241
|
+
});
|
|
242
|
+
if (extraction.failed) {
|
|
243
|
+
// Nothing was learned: hand the turns back, unless a later run already claimed past them.
|
|
244
|
+
// The try counts against this stretch unless the provider is to blame (a sign-in failure
|
|
245
|
+
// pauses it as a whole), so a paused provider never parks a conversation.
|
|
246
|
+
const reason = extraction.reason ?? "no-answer";
|
|
247
|
+
const retry = extraction.paused || reason === "auth"
|
|
248
|
+
? claim.retry
|
|
249
|
+
: bumpRetry(claim.retry, newest, reason, now);
|
|
250
|
+
await locked(async (state) => {
|
|
251
|
+
const latest = state.conversations[conversation.uuid];
|
|
252
|
+
if (latest?.from === claim.from && latest.to === newest) {
|
|
253
|
+
if (!claim.from && !retry)
|
|
254
|
+
delete state.conversations[conversation.uuid];
|
|
255
|
+
else
|
|
256
|
+
state.conversations[conversation.uuid] = {
|
|
257
|
+
from: claim.from,
|
|
258
|
+
to: claim.from,
|
|
259
|
+
at: new Date().toISOString(),
|
|
260
|
+
...(retry ? { retry } : {}),
|
|
261
|
+
};
|
|
262
|
+
await writeState(state);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return {
|
|
266
|
+
...base,
|
|
267
|
+
status: extraction.paused ? "paused" : "failed",
|
|
268
|
+
reason,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const proposed = await captureSessionFacts({
|
|
272
|
+
sessionId: `desktop:${conversation.uuid}`,
|
|
273
|
+
client: DESKTOP_CLIENT,
|
|
274
|
+
facts: extraction.facts,
|
|
275
|
+
});
|
|
276
|
+
let record;
|
|
277
|
+
if (extraction.digest) {
|
|
278
|
+
const times = dated
|
|
279
|
+
.filter((message) => message.createdAt > claim.from)
|
|
280
|
+
.map((message) => message.createdAt);
|
|
281
|
+
record = (await writeDigestRecord({
|
|
282
|
+
provider: DESKTOP_CLIENT,
|
|
283
|
+
sessionId: `desktop:${conversation.uuid}`,
|
|
284
|
+
startedAt: times[0] ?? newest,
|
|
285
|
+
endedAt: newest,
|
|
286
|
+
digest: extraction.digest,
|
|
287
|
+
project: decision.projectId,
|
|
288
|
+
conversationTitle: decision.title,
|
|
289
|
+
claudeProject: decision.claudeProject,
|
|
290
|
+
identity: decision,
|
|
291
|
+
activity: desktopActivity(dated.filter((message) => message.createdAt > claim.from)),
|
|
292
|
+
...(extraction.call ? { extraction: extraction.call } : {}),
|
|
293
|
+
})).path;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
...base,
|
|
297
|
+
status: "done",
|
|
298
|
+
...(record ? { record } : {}),
|
|
299
|
+
...(decision.projectId ? { project: decision.projectId } : {}),
|
|
300
|
+
filed: proposed.filed.map((item) => item.path),
|
|
301
|
+
candidates: proposed.proposed,
|
|
302
|
+
rejected: extraction.rejected.length,
|
|
303
|
+
...(extraction.triage && !extraction.triage.worth ? { trivial: true } : {}),
|
|
304
|
+
...(extraction.repeat ? { repeat: true } : {}),
|
|
305
|
+
...(proposed.unrouted.length ? { unrouted: proposed.unrouted } : {}),
|
|
306
|
+
skipped: proposed.skipped.length,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=desktop-facts.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createReadStream } from "node:fs";
|
|
2
|
-
import { stat } from "node:fs/promises";
|
|
2
|
+
import { open, stat } from "node:fs/promises";
|
|
3
3
|
import readline from "node:readline";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { resolveSessionTask } from "../../tasks/session-task.js";
|
|
5
|
+
import { finalizeSession } from "../session-closeout.js";
|
|
6
|
+
import { recordProjectDecision, sessionProjectDecision, } from "../session-projects.js";
|
|
7
7
|
// Gemini CLI, Qwen Code and Cursor fire a session-end event too (T-307); their transcript
|
|
8
8
|
// formats are not read, so their sessions are recorded from metadata alone.
|
|
9
9
|
export const SESSION_END_CLIENTS = [
|
|
@@ -71,6 +71,33 @@ export function transcriptTurn(record, client) {
|
|
|
71
71
|
const message = record.message;
|
|
72
72
|
return { role: record.type, text: textFromContent(message?.content) };
|
|
73
73
|
}
|
|
74
|
+
// A Codex rollout opens with a session_meta line naming its originator; `codex exec` writes
|
|
75
|
+
// `codex_exec`. Those are headless runs (scripts, plugins, Ocean's own calls), not the owner's
|
|
76
|
+
// sessions, so no hook records or reads them (T-336). Only the head of the file is read: the
|
|
77
|
+
// originator comes before the long base instructions on that line.
|
|
78
|
+
const HEAD_BYTES = 64 * 1024;
|
|
79
|
+
export async function isHeadlessRun(payload, client) {
|
|
80
|
+
if (client !== "codex" || !payload.transcript_path)
|
|
81
|
+
return false;
|
|
82
|
+
let head = "";
|
|
83
|
+
try {
|
|
84
|
+
const file = await open(payload.transcript_path, "r");
|
|
85
|
+
try {
|
|
86
|
+
const buffer = Buffer.alloc(HEAD_BYTES);
|
|
87
|
+
const { bytesRead } = await file.read(buffer, 0, HEAD_BYTES, 0);
|
|
88
|
+
head = buffer.toString("utf8", 0, bytesRead).split("\n", 1)[0];
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
await file.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (!/"type"\s*:\s*"session_meta"/.test(head))
|
|
98
|
+
return false;
|
|
99
|
+
return /"originator"\s*:\s*"codex_exec"/.test(head);
|
|
100
|
+
}
|
|
74
101
|
/**
|
|
75
102
|
* Extracts a bounded set of plain-text user/assistant turns from a Claude
|
|
76
103
|
* Code transcript (JSONL: one record per line, {type, message:{role,
|
|
@@ -152,7 +179,8 @@ export async function ensureHookSession(store, sessionId, client, cwd) {
|
|
|
152
179
|
const existing = store.get(sessionId);
|
|
153
180
|
if (existing)
|
|
154
181
|
return existing;
|
|
155
|
-
const
|
|
182
|
+
const decision = await sessionProjectDecision(cwd);
|
|
183
|
+
const projectId = decision.projectId || null;
|
|
156
184
|
store.create({
|
|
157
185
|
sessionId,
|
|
158
186
|
taskId: await resolveSessionTask(cwd, projectId),
|
|
@@ -165,6 +193,7 @@ export async function ensureHookSession(store, sessionId, client, cwd) {
|
|
|
165
193
|
resumeData: null,
|
|
166
194
|
projectId,
|
|
167
195
|
});
|
|
196
|
+
recordProjectDecision(store, sessionId, decision);
|
|
168
197
|
store.updateStatus(sessionId, "running");
|
|
169
198
|
return store.get(sessionId);
|
|
170
199
|
}
|
|
@@ -172,6 +201,8 @@ export async function claudeSessionEndHook(payload, openStore, client = "claude"
|
|
|
172
201
|
const sessionId = payload.session_id;
|
|
173
202
|
if (!sessionId)
|
|
174
203
|
return;
|
|
204
|
+
if (await isHeadlessRun(payload, client))
|
|
205
|
+
return;
|
|
175
206
|
const cwd = payloadCwd(payload);
|
|
176
207
|
const store = await openStore();
|
|
177
208
|
try {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { mkdir, open, stat } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { writeDigestRecord } from "@ocean/brain/memory/brain-dump.js";
|
|
4
|
+
import { projectScope } from "@ocean/brain/memory/fact-routing.js";
|
|
4
5
|
import { sessionFactsEnabled } from "@ocean/brain/memory/memory-audit.js";
|
|
5
|
-
import {
|
|
6
|
+
import { captureSessionFacts, extractSessionFacts, } from "@ocean/brain/sessions-capture/session-facts.js";
|
|
7
|
+
import { sessionIdentity } from "@ocean/core/domain/sessions/session-identity.js";
|
|
8
|
+
import { ActivityTally, } from "@ocean/core/domain/sessions/session-metadata.js";
|
|
6
9
|
import { safeJsonParse, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
7
10
|
import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|
|
8
|
-
import {
|
|
11
|
+
import { findGitRoot, repoRelative, } from "@ocean/core/shared/project-resolution.js";
|
|
12
|
+
import { ensureHookSession, isHeadlessRun, payloadCwd, TRANSCRIPT_CLIENTS, transcriptTurn, } from "./session-end-hook.js";
|
|
9
13
|
// Fact capture from a client's transcript (T-313), run by `ocean hook session-facts` in the
|
|
10
14
|
// background after SessionEnd and PreCompact (a hook itself has seconds; a model call takes
|
|
11
15
|
// longer). A per-session cursor — the transcript byte offset already claimed — makes PreCompact
|
|
@@ -14,7 +18,7 @@ import { ensureHookSession, payloadCwd, TRANSCRIPT_CLIENTS, transcriptTurn, } fr
|
|
|
14
18
|
// The most of a transcript one run reads; a longer unread part keeps its newest end.
|
|
15
19
|
const MAX_SLICE_BYTES = 4 * 1024 * 1024;
|
|
16
20
|
export const FACTS_CLAIM_EVENT = "memory_extract_claim";
|
|
17
|
-
|
|
21
|
+
const FACTS_DONE_EVENT = "memory_extracted";
|
|
18
22
|
// Claude Code adds its own text to user turns: reminders, slash-command echoes, local command
|
|
19
23
|
// output. None of it is something the user said.
|
|
20
24
|
function userText(text) {
|
|
@@ -60,18 +64,124 @@ export async function readTranscriptSlice(transcriptPath, client, from = 0) {
|
|
|
60
64
|
if (partialFirst)
|
|
61
65
|
lines.shift();
|
|
62
66
|
const turns = [];
|
|
67
|
+
const tally = new ActivityTally();
|
|
68
|
+
let cwd;
|
|
69
|
+
let first;
|
|
70
|
+
let last;
|
|
63
71
|
for (const line of lines) {
|
|
64
72
|
const record = line.trim() ? safeJsonParse(line) : null;
|
|
73
|
+
const at = record ? lineTime(record) : undefined;
|
|
74
|
+
if (at) {
|
|
75
|
+
first ??= at;
|
|
76
|
+
last = at;
|
|
77
|
+
}
|
|
65
78
|
if (!record || record.isMeta === true)
|
|
66
79
|
continue;
|
|
80
|
+
cwd = noteActivity(record, client, tally) ?? cwd;
|
|
67
81
|
const turn = transcriptTurn(record, client);
|
|
68
82
|
if (!turn)
|
|
69
83
|
continue;
|
|
70
84
|
const text = turn.role === "user" ? userText(turn.text) : turn.text.trim();
|
|
71
|
-
if (text)
|
|
85
|
+
if (text) {
|
|
72
86
|
turns.push({ role: turn.role, text });
|
|
87
|
+
tally.turn(turn.role);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
turns,
|
|
92
|
+
offset: start + lastNewline + 1,
|
|
93
|
+
activity: tally.result(),
|
|
94
|
+
...(cwd ? { cwd } : {}),
|
|
95
|
+
...(first ? { first } : {}),
|
|
96
|
+
...(last ? { last } : {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const asRecord = (value) => value && typeof value === "object" && !Array.isArray(value)
|
|
100
|
+
? value
|
|
101
|
+
: undefined;
|
|
102
|
+
// The path a tool call's input names, if any.
|
|
103
|
+
function inputPath(input) {
|
|
104
|
+
const fields = asRecord(typeof input === "string" ? safeJsonParse(input) : input);
|
|
105
|
+
const found = fields?.file_path ?? fields?.notebook_path ?? fields?.path;
|
|
106
|
+
return typeof found === "string" && found ? found : undefined;
|
|
107
|
+
}
|
|
108
|
+
// One transcript line's model, branch and tool calls into the tally; returns the working folder
|
|
109
|
+
// the line names. Claude Code stamps cwd and gitBranch on each line and lists tool_use blocks
|
|
110
|
+
// in assistant messages; Codex keeps them in session_meta, turn_context and response_item lines.
|
|
111
|
+
function noteActivity(record, client, tally) {
|
|
112
|
+
if (client === "codex") {
|
|
113
|
+
const payload = asRecord(record.payload);
|
|
114
|
+
if (!payload)
|
|
115
|
+
return undefined;
|
|
116
|
+
if (record.type === "session_meta")
|
|
117
|
+
tally.branch(asRecord(payload.git)?.branch);
|
|
118
|
+
if (record.type === "turn_context")
|
|
119
|
+
tally.model(payload.model);
|
|
120
|
+
if (record.type === "response_item" &&
|
|
121
|
+
typeof payload.type === "string" &&
|
|
122
|
+
/call$/.test(payload.type) &&
|
|
123
|
+
!/output$/.test(payload.type))
|
|
124
|
+
tally.tool(typeof payload.name === "string" ? payload.name : payload.type, inputPath(payload.arguments ?? payload.input));
|
|
125
|
+
return typeof payload.cwd === "string" ? payload.cwd : undefined;
|
|
126
|
+
}
|
|
127
|
+
tally.branch(record.gitBranch);
|
|
128
|
+
if (record.type === "assistant") {
|
|
129
|
+
const message = asRecord(record.message);
|
|
130
|
+
tally.model(message?.model);
|
|
131
|
+
if (Array.isArray(message?.content))
|
|
132
|
+
for (const block of message.content) {
|
|
133
|
+
const each = asRecord(block);
|
|
134
|
+
if (each?.type === "tool_use" && typeof each.name === "string")
|
|
135
|
+
tally.tool(each.name, inputPath(each.input));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return typeof record.cwd === "string" ? record.cwd : undefined;
|
|
139
|
+
}
|
|
140
|
+
// The tally's touched paths made repo-relative, for the record.
|
|
141
|
+
export function recordActivity(activity, cwd) {
|
|
142
|
+
if (!activity)
|
|
143
|
+
return undefined;
|
|
144
|
+
const root = cwd ? findGitRoot(cwd) : null;
|
|
145
|
+
const files = {};
|
|
146
|
+
for (const [file, count] of Object.entries(activity.files)) {
|
|
147
|
+
const relative = repoRelative(cwd && !path.isAbsolute(file) ? path.resolve(cwd, file) : file, root);
|
|
148
|
+
files[relative] = (files[relative] ?? 0) + count;
|
|
149
|
+
}
|
|
150
|
+
return { ...activity, files };
|
|
151
|
+
}
|
|
152
|
+
// A transcript line's own time: Claude Code and Codex both stamp each line at the top level.
|
|
153
|
+
function lineTime(record) {
|
|
154
|
+
const at = record.timestamp;
|
|
155
|
+
return typeof at === "string" && Number.isFinite(Date.parse(at))
|
|
156
|
+
? new Date(at).toISOString()
|
|
157
|
+
: undefined;
|
|
158
|
+
}
|
|
159
|
+
// How much of a transcript's head is read to find when it started.
|
|
160
|
+
const HEAD_BYTES = 64 * 1024;
|
|
161
|
+
// When the transcript started: the first timestamp in its head, or undefined.
|
|
162
|
+
export async function transcriptStart(transcriptPath) {
|
|
163
|
+
let handle;
|
|
164
|
+
try {
|
|
165
|
+
handle = await open(transcriptPath, "r");
|
|
166
|
+
const buffer = Buffer.alloc(HEAD_BYTES);
|
|
167
|
+
const { bytesRead } = await handle.read(buffer, 0, HEAD_BYTES, 0);
|
|
168
|
+
for (const line of buffer
|
|
169
|
+
.subarray(0, bytesRead)
|
|
170
|
+
.toString("utf8")
|
|
171
|
+
.split("\n")) {
|
|
172
|
+
const record = line.trim() ? safeJsonParse(line) : null;
|
|
173
|
+
const at = record ? lineTime(record) : undefined;
|
|
174
|
+
if (at)
|
|
175
|
+
return at;
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
await handle?.close();
|
|
73
184
|
}
|
|
74
|
-
return { turns, offset: start + lastNewline + 1 };
|
|
75
185
|
}
|
|
76
186
|
// The cursor: where the latest claim for this transcript ended. Each claim starts at the
|
|
77
187
|
// cursor, so claims only move it forward, except a rewind, which a failed run appends to hand
|
|
@@ -92,6 +202,14 @@ function latestClaim(store, sessionId, transcriptPath) {
|
|
|
92
202
|
function lockFile(sessionId) {
|
|
93
203
|
return oceanPath(SYSTEM_DIR, "state", "memory", "extract", sessionId.replace(/[^A-Za-z0-9_-]/g, "_"));
|
|
94
204
|
}
|
|
205
|
+
// The session's real span: the transcript's first timestamp to the last one read. Capture time
|
|
206
|
+
// only when the transcript carries none.
|
|
207
|
+
async function digestTimes(transcriptPath, slice) {
|
|
208
|
+
const now = new Date().toISOString();
|
|
209
|
+
const startedAt = (await transcriptStart(transcriptPath)) ?? slice.first ?? now;
|
|
210
|
+
const endedAt = slice.last ?? now;
|
|
211
|
+
return { startedAt, endedAt: endedAt < startedAt ? startedAt : endedAt };
|
|
212
|
+
}
|
|
95
213
|
export async function runSessionFacts(payload, openStore, client, completer,
|
|
96
214
|
// digest: the same call also returns the stretch's summary, written as a session record so a
|
|
97
215
|
// long session is in the day's account before it ends (T-314) — no second model call.
|
|
@@ -102,6 +220,8 @@ options = {}) {
|
|
|
102
220
|
const transcript = payload.transcript_path;
|
|
103
221
|
if (!sessionId || !transcript || !TRANSCRIPT_CLIENTS.includes(client))
|
|
104
222
|
return { status: "no-transcript" };
|
|
223
|
+
if (await isHeadlessRun(payload, client))
|
|
224
|
+
return { status: "headless" };
|
|
105
225
|
const transcriptPath = path.resolve(transcript);
|
|
106
226
|
const complete = completer(client);
|
|
107
227
|
await mkdir(path.dirname(lockFile(sessionId)), {
|
|
@@ -113,15 +233,17 @@ options = {}) {
|
|
|
113
233
|
const claim = await withFileLock(lockFile(sessionId), async () => {
|
|
114
234
|
const store = await openStore();
|
|
115
235
|
try {
|
|
116
|
-
await ensureHookSession(store, sessionId, client, payloadCwd(payload));
|
|
236
|
+
const session = await ensureHookSession(store, sessionId, client, payloadCwd(payload));
|
|
237
|
+
// The project and task were decided when the session was created; read, never recomputed.
|
|
238
|
+
const identity = sessionIdentity(session ?? { projectId: null, taskId: null }, store.listEvents(sessionId));
|
|
117
239
|
const from = latestClaim(store, sessionId, transcriptPath)?.to ?? 0;
|
|
118
240
|
const slice = await readTranscriptSlice(transcriptPath, client, from);
|
|
119
241
|
if (slice.offset === from)
|
|
120
|
-
return { from, slice, claimed: false };
|
|
242
|
+
return { from, slice, identity, claimed: false };
|
|
121
243
|
if (!complete)
|
|
122
|
-
return { from, slice, claimed: false };
|
|
244
|
+
return { from, slice, identity, claimed: false };
|
|
123
245
|
store.appendEvent(sessionId, FACTS_CLAIM_EVENT, JSON.stringify({ transcript: transcriptPath, from, to: slice.offset }));
|
|
124
|
-
return { from, slice, claimed: true };
|
|
246
|
+
return { from, slice, identity, claimed: true };
|
|
125
247
|
}
|
|
126
248
|
finally {
|
|
127
249
|
store.close();
|
|
@@ -135,6 +257,8 @@ options = {}) {
|
|
|
135
257
|
turns: claim.slice.turns,
|
|
136
258
|
complete,
|
|
137
259
|
digest: options.digest,
|
|
260
|
+
scope: await projectScope(claim.identity.projectId),
|
|
261
|
+
log: { sessionId, client },
|
|
138
262
|
});
|
|
139
263
|
if (extraction.failed) {
|
|
140
264
|
// Nothing was learned: hand the turns back, unless a later run already claimed past them.
|
|
@@ -156,21 +280,23 @@ options = {}) {
|
|
|
156
280
|
});
|
|
157
281
|
return { status: "failed", from: claim.from, to: claim.slice.offset };
|
|
158
282
|
}
|
|
159
|
-
const proposed = await
|
|
283
|
+
const proposed = await captureSessionFacts({
|
|
160
284
|
sessionId,
|
|
161
285
|
client,
|
|
162
286
|
facts: extraction.facts,
|
|
163
287
|
});
|
|
164
288
|
let record;
|
|
165
289
|
if (extraction.digest) {
|
|
166
|
-
const now = new Date().toISOString();
|
|
167
290
|
record = (await writeDigestRecord({
|
|
168
291
|
provider: client,
|
|
169
292
|
sessionId,
|
|
170
|
-
|
|
171
|
-
endedAt: now,
|
|
293
|
+
...(await digestTimes(transcriptPath, claim.slice)),
|
|
172
294
|
digest: extraction.digest,
|
|
173
|
-
project:
|
|
295
|
+
project: claim.identity.projectId,
|
|
296
|
+
task: claim.identity.taskId,
|
|
297
|
+
identity: claim.identity,
|
|
298
|
+
activity: recordActivity(claim.slice.activity, claim.slice.cwd ?? payloadCwd(payload)),
|
|
299
|
+
...(extraction.call ? { extraction: extraction.call } : {}),
|
|
174
300
|
})).path;
|
|
175
301
|
}
|
|
176
302
|
const run = {
|
|
@@ -178,8 +304,12 @@ options = {}) {
|
|
|
178
304
|
...(record ? { record } : {}),
|
|
179
305
|
from: claim.from,
|
|
180
306
|
to: claim.slice.offset,
|
|
307
|
+
filed: proposed.filed.map((item) => item.path),
|
|
181
308
|
candidates: proposed.proposed,
|
|
182
309
|
rejected: extraction.rejected.length,
|
|
310
|
+
...(extraction.triage && !extraction.triage.worth ? { trivial: true } : {}),
|
|
311
|
+
...(extraction.repeat ? { repeat: true } : {}),
|
|
312
|
+
...(proposed.unrouted.length ? { unrouted: proposed.unrouted } : {}),
|
|
183
313
|
skipped: proposed.skipped.length,
|
|
184
314
|
};
|
|
185
315
|
const store = await openStore();
|