@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.
- package/README.md +46 -53
- package/dist/application/clients/bundles.js +220 -0
- package/dist/application/clients/chat-plugin.js +4 -42
- 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/clients/zip.js +44 -0
- 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 +55 -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,625 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { MemoryContractError } from "@ocean/core/domain/mcp/memory-contract.js";
|
|
4
|
+
import { redactSecrets } from "@ocean/core/domain/redaction.js";
|
|
5
|
+
import { atomicWrite, withFileLock } from "@ocean/core/shared/fs-utils.js";
|
|
6
|
+
import { localDate } from "@ocean/core/shared/local-date.js";
|
|
7
|
+
import { oceanPath } from "@ocean/core/shared/paths.js";
|
|
8
|
+
import { projectSlug } from "@ocean/core/shared/project-manifest.js";
|
|
9
|
+
import { appendExtractionLog, extractedBefore, } from "../memory/extraction-log.js";
|
|
10
|
+
import { clearExtractionPause, readExtractionPause, setExtractionPause, } from "../memory/extraction-retry.js";
|
|
11
|
+
import { FACT_TYPES, factTarget, isFactType, listedProject, projectListLine, } from "../memory/fact-routing.js";
|
|
12
|
+
import { readAudit, sha256 } from "../memory/memory-audit.js";
|
|
13
|
+
import { sessionFactsLedgerFile, unroutedFile, } from "../memory/memory-paths.js";
|
|
14
|
+
import { checkContent, proposeMemory, writeMemoryRecord, } from "../memory/memory-write.js";
|
|
15
|
+
import { triageTurns } from "./session-triage.js";
|
|
16
|
+
const evidenceTag = (evidence) => `[${evidence}]`;
|
|
17
|
+
// The evidence a session record's list item carries, read back from its leading tag; null for an
|
|
18
|
+
// item written before tags existed.
|
|
19
|
+
export function itemEvidence(item) {
|
|
20
|
+
const tag = /^\[(user|tool|unverified)\]\s*/.exec(item);
|
|
21
|
+
return tag ? tag[1] : null;
|
|
22
|
+
}
|
|
23
|
+
export const untagged = (item) => item.replace(/^\[(user|tool|unverified)\]\s*/, "");
|
|
24
|
+
// A fact's project as the scope allows it (T-335). Bound: a project fact always goes to the
|
|
25
|
+
// session's project. Listed: an id or alias from the list, else the answer is only a suggestion.
|
|
26
|
+
// Without a scope the model's answer stands (older callers, tests).
|
|
27
|
+
export function scopeFact(fact, scope) {
|
|
28
|
+
if (!scope)
|
|
29
|
+
return fact;
|
|
30
|
+
const { project, suggestedProject, ...rest } = fact;
|
|
31
|
+
if (scope.kind === "bound")
|
|
32
|
+
return fact.type === "project" || project
|
|
33
|
+
? { ...rest, project: scope.project }
|
|
34
|
+
: rest;
|
|
35
|
+
const id = project ? listedProject(scope.projects, project) : undefined;
|
|
36
|
+
if (id)
|
|
37
|
+
return { ...rest, project: id };
|
|
38
|
+
const named = project && project.toLowerCase() !== "none" ? project : "";
|
|
39
|
+
const suggestion = suggestedProject || named;
|
|
40
|
+
return suggestion ? { ...rest, suggestedProject: suggestion } : rest;
|
|
41
|
+
}
|
|
42
|
+
// Read through a function: the assignment before the call would otherwise narrow the property
|
|
43
|
+
// to `undefined` for the compiler, though the call may have set it.
|
|
44
|
+
const lastFailureOf = (complete) => complete.lastFailure;
|
|
45
|
+
const lastUsageOf = (complete) => complete.lastUsage;
|
|
46
|
+
const SESSION_FACTS_SOURCE_PREFIX = "session:";
|
|
47
|
+
export function isSessionFactSource(source) {
|
|
48
|
+
return (typeof source === "string" && source.startsWith(SESSION_FACTS_SOURCE_PREFIX));
|
|
49
|
+
}
|
|
50
|
+
// About 6k tokens of transcript per call; the user's own words get most of it.
|
|
51
|
+
const DEFAULT_FACTS_BUDGET_CHARS = 24_000;
|
|
52
|
+
const USER_SHARE = 0.7;
|
|
53
|
+
const MAX_TURN_CHARS = 4_000;
|
|
54
|
+
const MAX_FACTS = 5;
|
|
55
|
+
const MAX_TITLE = 100;
|
|
56
|
+
const MAX_CONTENT = 1_200;
|
|
57
|
+
const MAX_EVIDENCE = 300;
|
|
58
|
+
const MIN_EVIDENCE = 8;
|
|
59
|
+
// A tool result keeps this much of its line in the prompt (T-335): enough to quote a version or
|
|
60
|
+
// a path from, not enough to crowd out what the user said.
|
|
61
|
+
export const TOOL_LINE_CHARS = 240;
|
|
62
|
+
const TOOL_LINE = /^\[tool (?:result|error): /;
|
|
63
|
+
// Spaces collapse within a line, but line breaks stay: a tool result is a line of its own, and
|
|
64
|
+
// the evidence check finds it by its line (RESULT_LINE).
|
|
65
|
+
function compactLines(text) {
|
|
66
|
+
return text
|
|
67
|
+
.split("\n")
|
|
68
|
+
.map((line) => line.replace(/\s+/g, " ").trim())
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join("\n");
|
|
71
|
+
}
|
|
72
|
+
function trimToolLines(text) {
|
|
73
|
+
return text
|
|
74
|
+
.split("\n")
|
|
75
|
+
.map((line) => TOOL_LINE.test(line) && line.length > TOOL_LINE_CHARS
|
|
76
|
+
? `${line.slice(0, TOOL_LINE_CHARS - 2)}…]`
|
|
77
|
+
: line)
|
|
78
|
+
.join("\n");
|
|
79
|
+
}
|
|
80
|
+
// Secrets and private paths are replaced before any text reaches a model (the candidate check
|
|
81
|
+
// runs again on the output), and tool results are cut short after that. Turns are then chosen
|
|
82
|
+
// within the budget: the newest user turns first, up to USER_SHARE of it, then the newest
|
|
83
|
+
// assistant turns in what is left, and the chosen ones are put back in conversation order.
|
|
84
|
+
export function selectTurns(turns, budgetChars = DEFAULT_FACTS_BUDGET_CHARS) {
|
|
85
|
+
const redacted = turns
|
|
86
|
+
.map((turn, index) => ({
|
|
87
|
+
index,
|
|
88
|
+
role: turn.role,
|
|
89
|
+
text: trimToolLines(redactSecrets(compactLines(turn.text))).slice(0, MAX_TURN_CHARS),
|
|
90
|
+
}))
|
|
91
|
+
.filter((turn) => turn.text);
|
|
92
|
+
const chosen = new Set();
|
|
93
|
+
let used = 0;
|
|
94
|
+
const take = (role, limit) => {
|
|
95
|
+
for (let i = redacted.length - 1; i >= 0; i--) {
|
|
96
|
+
const turn = redacted[i];
|
|
97
|
+
if (turn.role !== role || chosen.has(turn.index))
|
|
98
|
+
continue;
|
|
99
|
+
if (used + turn.text.length > limit)
|
|
100
|
+
continue;
|
|
101
|
+
chosen.add(turn.index);
|
|
102
|
+
used += turn.text.length;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
take("user", Math.floor(budgetChars * USER_SHARE));
|
|
106
|
+
take("assistant", budgetChars);
|
|
107
|
+
// Left-over room from the assistant pass goes back to older user turns.
|
|
108
|
+
take("user", budgetChars);
|
|
109
|
+
return redacted
|
|
110
|
+
.filter((turn) => chosen.has(turn.index))
|
|
111
|
+
.map(({ role, text }) => ({ role, text }));
|
|
112
|
+
}
|
|
113
|
+
// A digest's lists grow with the conversation instead of a fixed cap (T-329 phase 2).
|
|
114
|
+
const DIGEST_ITEMS = 3;
|
|
115
|
+
const DIGEST_ITEMS_LONG = 6;
|
|
116
|
+
const LONG_CONVERSATION_CHARS = 12_000;
|
|
117
|
+
const DIGEST_ITEM_CHARS = 220;
|
|
118
|
+
function digestItems(turns) {
|
|
119
|
+
const chars = turns.reduce((sum, turn) => sum + turn.text.length, 0);
|
|
120
|
+
return chars >= LONG_CONVERSATION_CHARS ? DIGEST_ITEMS_LONG : DIGEST_ITEMS;
|
|
121
|
+
}
|
|
122
|
+
const digestPrompt = (items) => [
|
|
123
|
+
"Also summarize the whole conversation for the user's daily log, in the digest field. Plain short sentences in English; lists may be empty; never a secret or a [REDACTED] value.",
|
|
124
|
+
`title: what the conversation was about, at most 8 words. goal and outcome: one sentence each. decisions, fixes ("problem → fix"), learned: at most ${items} items each, every item an object {"text","evidence","quote"}. next: at most ${items} plain strings.`,
|
|
125
|
+
'evidence is "user" when the USER said or confirmed it (quote: an exact copy from one USER line), "tool" when a tool result in the conversation shows it (quote: an exact copy from that [tool result: …]), else "unverified" (quote: ""). An assistant claim nobody confirmed and no tool showed is "unverified"; a decision the user did not confirm is not a decision.',
|
|
126
|
+
];
|
|
127
|
+
// What the prompt says about projects (T-335), and how the facts' project field reads.
|
|
128
|
+
function projectRules(scope) {
|
|
129
|
+
if (!scope)
|
|
130
|
+
return {
|
|
131
|
+
rules: [],
|
|
132
|
+
field: '"project":"project name if the fact is about one, else omit"',
|
|
133
|
+
};
|
|
134
|
+
if (scope.kind === "bound")
|
|
135
|
+
return {
|
|
136
|
+
rules: [
|
|
137
|
+
`This conversation is in the project "${scope.project}". Every project fact is about it: its project is "${scope.project}".`,
|
|
138
|
+
],
|
|
139
|
+
field: `"project":"${scope.project}"`,
|
|
140
|
+
};
|
|
141
|
+
const list = projectListLine(scope.projects);
|
|
142
|
+
return {
|
|
143
|
+
rules: [
|
|
144
|
+
`Known projects, as id (aliases): ${list || "(none)"}.`,
|
|
145
|
+
'For a project fact, project is one id from that list, or "none" when it is about a project not listed; then give that project\'s name in suggested_project.',
|
|
146
|
+
],
|
|
147
|
+
field: '"project":"an id from the known projects, or none","suggested_project":"only when project is none"',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export function buildFactsPrompt(turns, options = {}) {
|
|
151
|
+
const projects = projectRules(options.scope);
|
|
152
|
+
const transcript = turns
|
|
153
|
+
.map((turn) => `[${turn.role === "user" ? "USER" : "ASSISTANT"}] ${turn.text}`)
|
|
154
|
+
.join("\n");
|
|
155
|
+
return [
|
|
156
|
+
"You extract durable memory from one conversation between a user and an AI assistant.",
|
|
157
|
+
"Durable means still true and useful in a later, unrelated conversation: the user's identity, role, preferences, standing decisions, project facts, constraints, and corrections to the assistant.",
|
|
158
|
+
"Only extract what the USER stated or explicitly confirmed, or a durable project fact a tool result shows (a version, a path, a setting). Never extract the assistant's suggestions, guesses or plans the user did not confirm.",
|
|
159
|
+
"Never extract temporary state (what is being debugged right now, today's to-do, a file being edited), secrets, credentials, or anything marked [REDACTED] or [PRIVATE_PATH].",
|
|
160
|
+
`Return at most ${MAX_FACTS} facts. Returning none is correct and common.`,
|
|
161
|
+
...(options.digest ? digestPrompt(options.items ?? DIGEST_ITEMS) : []),
|
|
162
|
+
"Answer with JSON only, no prose and no code fence:",
|
|
163
|
+
`{"facts":[{"title":"short label","content":"the fact as one or two plain sentences","source":"user or tool","evidence":"an exact quote, copied character for character from one USER line (source user) or one [tool result: …] (source tool)","reason":"why it is durable","type":"one of the types below",${projects.field}}]${options.digest ? ',"digest":{"title":"","goal":"","outcome":"","decisions":[{"text":"","evidence":"user","quote":""}],"fixes":[],"learned":[],"next":[]}' : ""}}`,
|
|
164
|
+
`type is one of: ${FACT_TYPES.join(", ")}. Use project only for a fact about one project, and then also give its project; a fact about the user stays a personal type even when it came up in a project.`,
|
|
165
|
+
...projects.rules,
|
|
166
|
+
'Answer {"facts":[]} when nothing qualifies.',
|
|
167
|
+
"",
|
|
168
|
+
"Conversation:",
|
|
169
|
+
transcript,
|
|
170
|
+
].join("\n");
|
|
171
|
+
}
|
|
172
|
+
const clean = (value, max) => typeof value === "string"
|
|
173
|
+
? value.replace(/\s+/g, " ").trim().slice(0, max)
|
|
174
|
+
: "";
|
|
175
|
+
// The model's answer → well-formed facts. Anything else (prose, a fence around the JSON, missing
|
|
176
|
+
// fields) yields what can be read and drops the rest; never throws.
|
|
177
|
+
// The `facts` list the answer holds, or null when the answer is no such JSON at all (a failed
|
|
178
|
+
// call, prose, a refusal): then the turns are read again by a later run.
|
|
179
|
+
function factsList(text) {
|
|
180
|
+
if (!text)
|
|
181
|
+
return null;
|
|
182
|
+
const start = text.indexOf("{");
|
|
183
|
+
const end = text.lastIndexOf("}");
|
|
184
|
+
if (start < 0 || end <= start)
|
|
185
|
+
return null;
|
|
186
|
+
let parsed;
|
|
187
|
+
try {
|
|
188
|
+
parsed = JSON.parse(text.slice(start, end + 1));
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
return parsed &&
|
|
194
|
+
typeof parsed === "object" &&
|
|
195
|
+
Array.isArray(parsed.facts)
|
|
196
|
+
? parsed.facts
|
|
197
|
+
: null;
|
|
198
|
+
}
|
|
199
|
+
// The digest the answer holds, cleaned and bounded; null when there is none or it says nothing.
|
|
200
|
+
// Each decision, fix and learned item is checked against the turns and tagged with the evidence
|
|
201
|
+
// that held up ([user], [tool] or [unverified]); a bare string is unverified.
|
|
202
|
+
export function parseDigest(text, turns = [], items = DIGEST_ITEMS) {
|
|
203
|
+
if (!text)
|
|
204
|
+
return null;
|
|
205
|
+
const start = text.indexOf("{");
|
|
206
|
+
const end = text.lastIndexOf("}");
|
|
207
|
+
if (start < 0 || end <= start)
|
|
208
|
+
return null;
|
|
209
|
+
let value;
|
|
210
|
+
try {
|
|
211
|
+
const parsed = JSON.parse(text.slice(start, end + 1));
|
|
212
|
+
if (!parsed.digest || typeof parsed.digest !== "object")
|
|
213
|
+
return null;
|
|
214
|
+
value = parsed.digest;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const usable = (item) => item && !/\[(redacted|private_path)\]/i.test(item);
|
|
220
|
+
const raw = (key) => Array.isArray(value[key]) ? value[key] : [];
|
|
221
|
+
const list = (key) => raw(key)
|
|
222
|
+
.map((item) => redactSecrets(clean(item, DIGEST_ITEM_CHARS)))
|
|
223
|
+
.filter(usable)
|
|
224
|
+
.slice(0, items);
|
|
225
|
+
const claims = (key) => raw(key)
|
|
226
|
+
.map((item) => {
|
|
227
|
+
const claim = item && typeof item === "object"
|
|
228
|
+
? item
|
|
229
|
+
: { text: item };
|
|
230
|
+
const text = redactSecrets(clean(claim.text, DIGEST_ITEM_CHARS));
|
|
231
|
+
const evidence = checkedEvidence(claim.evidence, clean(claim.quote, MAX_EVIDENCE), turns);
|
|
232
|
+
return usable(text) ? `${evidenceTag(evidence)} ${text}` : "";
|
|
233
|
+
})
|
|
234
|
+
.filter(Boolean)
|
|
235
|
+
.slice(0, items);
|
|
236
|
+
const digest = {
|
|
237
|
+
title: redactSecrets(clean(value.title, 80)),
|
|
238
|
+
goal: redactSecrets(clean(value.goal, DIGEST_ITEM_CHARS)),
|
|
239
|
+
outcome: redactSecrets(clean(value.outcome, DIGEST_ITEM_CHARS)),
|
|
240
|
+
decisions: claims("decisions"),
|
|
241
|
+
fixes: claims("fixes"),
|
|
242
|
+
learned: claims("learned"),
|
|
243
|
+
next: list("next"),
|
|
244
|
+
};
|
|
245
|
+
return digest.title || digest.goal ? digest : null;
|
|
246
|
+
}
|
|
247
|
+
export function parseFacts(text) {
|
|
248
|
+
const list = factsList(text) ?? [];
|
|
249
|
+
const facts = [];
|
|
250
|
+
for (const item of list) {
|
|
251
|
+
if (!item || typeof item !== "object")
|
|
252
|
+
continue;
|
|
253
|
+
const value = item;
|
|
254
|
+
const fact = {
|
|
255
|
+
title: clean(value.title, MAX_TITLE),
|
|
256
|
+
content: clean(value.content, MAX_CONTENT),
|
|
257
|
+
evidence: clean(value.evidence, MAX_EVIDENCE),
|
|
258
|
+
reason: clean(value.reason, 300),
|
|
259
|
+
};
|
|
260
|
+
if (value.source === "tool")
|
|
261
|
+
fact.source = "tool";
|
|
262
|
+
const project = clean(value.project, 64);
|
|
263
|
+
if (project)
|
|
264
|
+
fact.project = project;
|
|
265
|
+
const suggested = clean(value.suggested_project, 64);
|
|
266
|
+
if (suggested)
|
|
267
|
+
fact.suggestedProject = suggested;
|
|
268
|
+
if (isFactType(value.type))
|
|
269
|
+
fact.type = value.type;
|
|
270
|
+
if (fact.title && fact.content && fact.evidence)
|
|
271
|
+
facts.push(fact);
|
|
272
|
+
if (facts.length === MAX_FACTS)
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
return facts;
|
|
276
|
+
}
|
|
277
|
+
const normalize = (value) => value
|
|
278
|
+
.toLowerCase()
|
|
279
|
+
.normalize("NFKC")
|
|
280
|
+
.replace(/[‘’“”"'`]/g, "")
|
|
281
|
+
.replace(/\s+/g, " ")
|
|
282
|
+
.trim();
|
|
283
|
+
// A tool result as desktop-chat.ts writes it: "[tool result: …]" or "[tool error: …]" on a line of
|
|
284
|
+
// its own, its body flattened to one line. The line is the result's exact extent, so assistant
|
|
285
|
+
// prose after it never counts as something a tool showed.
|
|
286
|
+
const RESULT_LINE = /^\[tool (?:result|error): (.*?)\]?$/gm;
|
|
287
|
+
function quoteInUser(quote, turns) {
|
|
288
|
+
return turns.some((turn) => turn.role === "user" && normalize(turn.text).includes(quote));
|
|
289
|
+
}
|
|
290
|
+
function quoteInTool(quote, turns) {
|
|
291
|
+
return turns.some((turn) => turn.role === "assistant" &&
|
|
292
|
+
[...turn.text.matchAll(RESULT_LINE)].some((line) => normalize(line[1] ?? "").includes(quote)));
|
|
293
|
+
}
|
|
294
|
+
function quoteFound(source, quote, turns) {
|
|
295
|
+
const normalized = normalize(quote);
|
|
296
|
+
if (normalized.length < MIN_EVIDENCE)
|
|
297
|
+
return false;
|
|
298
|
+
if (/\[(redacted|private_path)\]/.test(normalized))
|
|
299
|
+
return false;
|
|
300
|
+
if (source === "user")
|
|
301
|
+
return quoteInUser(normalized, turns);
|
|
302
|
+
if (source === "tool")
|
|
303
|
+
return quoteInTool(normalized, turns);
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
// What the claimed evidence holds up as: the claim when its quote is found where it says,
|
|
307
|
+
// unverified otherwise.
|
|
308
|
+
export function checkedEvidence(claimed, quote, turns) {
|
|
309
|
+
if (claimed !== "user" && claimed !== "tool")
|
|
310
|
+
return "unverified";
|
|
311
|
+
return quoteFound(claimed, quote, turns) ? claimed : "unverified";
|
|
312
|
+
}
|
|
313
|
+
// The false-positive guard: a fact counts only when its evidence is really in what the user
|
|
314
|
+
// said, or in a tool result for a fact whose source is a tool (after the same redaction the model
|
|
315
|
+
// saw). An assistant line, a paraphrase passed off as a quote, or an invented fact has no such
|
|
316
|
+
// quote.
|
|
317
|
+
export function isGrounded(fact, turns) {
|
|
318
|
+
return quoteFound(fact.source ?? "user", fact.evidence, turns);
|
|
319
|
+
}
|
|
320
|
+
// The hash that identifies a stretch of transcript: the turns exactly as the model would see them.
|
|
321
|
+
const turnsHash = (turns) => sha256(JSON.stringify(turns));
|
|
322
|
+
const FIRST_LINE_CHARS = 80;
|
|
323
|
+
// The one-line record of a chat triage found trivial: its first request, no model involved.
|
|
324
|
+
function trivialDigest(turns) {
|
|
325
|
+
const first = turns.find((turn) => turn.role === "user");
|
|
326
|
+
const line = first ? redactSecrets(clean(first.text, DIGEST_ITEM_CHARS)) : "";
|
|
327
|
+
if (!line || /\[(redacted|private_path)\]/i.test(line))
|
|
328
|
+
return null;
|
|
329
|
+
return {
|
|
330
|
+
title: clean(line, FIRST_LINE_CHARS),
|
|
331
|
+
goal: line,
|
|
332
|
+
outcome: "",
|
|
333
|
+
decisions: [],
|
|
334
|
+
fixes: [],
|
|
335
|
+
learned: [],
|
|
336
|
+
next: [],
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
export async function extractSessionFacts(options) {
|
|
340
|
+
const turns = selectTurns(options.turns, options.budgetChars);
|
|
341
|
+
if (!turns.some((turn) => turn.role === "user"))
|
|
342
|
+
return { facts: [], rejected: [], prompt: "", turns: 0, failed: false };
|
|
343
|
+
const triage = triageTurns(turns);
|
|
344
|
+
if (options.triage !== false && !triage.worth)
|
|
345
|
+
return {
|
|
346
|
+
facts: [],
|
|
347
|
+
rejected: [],
|
|
348
|
+
prompt: "",
|
|
349
|
+
turns: turns.length,
|
|
350
|
+
failed: false,
|
|
351
|
+
triage,
|
|
352
|
+
...(options.digest ? { digest: trivialDigest(turns) } : {}),
|
|
353
|
+
};
|
|
354
|
+
const hash = turnsHash(turns);
|
|
355
|
+
const model = options.complete.model || "unknown";
|
|
356
|
+
const logEntry = (outcome, cost, reason, usage) => options.log
|
|
357
|
+
? appendExtractionLog({
|
|
358
|
+
at: new Date().toISOString(),
|
|
359
|
+
client: options.log.client,
|
|
360
|
+
session: options.log.sessionId,
|
|
361
|
+
model,
|
|
362
|
+
input_chars: cost?.inputChars ?? 0,
|
|
363
|
+
ms: cost?.ms ?? 0,
|
|
364
|
+
hash,
|
|
365
|
+
outcome,
|
|
366
|
+
...(reason ? { reason } : {}),
|
|
367
|
+
...(usage ?? {}),
|
|
368
|
+
}).catch(() => { })
|
|
369
|
+
: Promise.resolve();
|
|
370
|
+
if (options.log && (await extractedBefore(hash).catch(() => false))) {
|
|
371
|
+
await logEntry("repeat");
|
|
372
|
+
return {
|
|
373
|
+
facts: [],
|
|
374
|
+
rejected: [],
|
|
375
|
+
prompt: "",
|
|
376
|
+
turns: turns.length,
|
|
377
|
+
failed: false,
|
|
378
|
+
triage,
|
|
379
|
+
repeat: true,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
// A sign-in failure paused the provider: no call, and these turns are handed back unchanged.
|
|
383
|
+
const pause = options.log
|
|
384
|
+
? await readExtractionPause(options.now).catch(() => null)
|
|
385
|
+
: null;
|
|
386
|
+
if (pause)
|
|
387
|
+
return {
|
|
388
|
+
facts: [],
|
|
389
|
+
rejected: [],
|
|
390
|
+
prompt: "",
|
|
391
|
+
turns: turns.length,
|
|
392
|
+
failed: true,
|
|
393
|
+
reason: pause.reason,
|
|
394
|
+
paused: true,
|
|
395
|
+
triage,
|
|
396
|
+
};
|
|
397
|
+
const items = digestItems(turns);
|
|
398
|
+
const prompt = buildFactsPrompt(turns, {
|
|
399
|
+
digest: options.digest,
|
|
400
|
+
items,
|
|
401
|
+
scope: options.scope,
|
|
402
|
+
});
|
|
403
|
+
let answer = null;
|
|
404
|
+
const calledAt = Date.now();
|
|
405
|
+
options.complete.lastFailure = undefined;
|
|
406
|
+
options.complete.lastUsage = undefined;
|
|
407
|
+
try {
|
|
408
|
+
answer = await options.complete(prompt);
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
answer = null;
|
|
412
|
+
if (!lastFailureOf(options.complete))
|
|
413
|
+
options.complete.lastFailure = "exit";
|
|
414
|
+
}
|
|
415
|
+
const call = {
|
|
416
|
+
model,
|
|
417
|
+
inputChars: prompt.length,
|
|
418
|
+
ms: Date.now() - calledAt,
|
|
419
|
+
};
|
|
420
|
+
const failed = factsList(answer) === null;
|
|
421
|
+
const reason = failed
|
|
422
|
+
? answer === null
|
|
423
|
+
? (lastFailureOf(options.complete) ?? "no-answer")
|
|
424
|
+
: "bad-answer"
|
|
425
|
+
: undefined;
|
|
426
|
+
await logEntry(failed ? "failed" : "ok", call, reason, lastUsageOf(options.complete));
|
|
427
|
+
if (options.log) {
|
|
428
|
+
if (reason === "auth")
|
|
429
|
+
await setExtractionPause(reason, options.now).catch(() => { });
|
|
430
|
+
else if (!failed)
|
|
431
|
+
await clearExtractionPause().catch(() => { });
|
|
432
|
+
}
|
|
433
|
+
const facts = [];
|
|
434
|
+
const rejected = [];
|
|
435
|
+
for (const parsed of parseFacts(answer)) {
|
|
436
|
+
const fact = scopeFact(parsed, options.scope);
|
|
437
|
+
if (isGrounded(fact, turns))
|
|
438
|
+
facts.push(fact);
|
|
439
|
+
else
|
|
440
|
+
rejected.push({
|
|
441
|
+
title: fact.title,
|
|
442
|
+
reason: "evidence not found in a user turn",
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
facts,
|
|
447
|
+
rejected,
|
|
448
|
+
prompt,
|
|
449
|
+
turns: turns.length,
|
|
450
|
+
failed,
|
|
451
|
+
...(reason ? { reason } : {}),
|
|
452
|
+
call,
|
|
453
|
+
triage,
|
|
454
|
+
...(options.digest ? { digest: parseDigest(answer, turns, items) } : {}),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
const factKey = (fact) => `f:${sha256(normalize(fact.content))}`;
|
|
458
|
+
async function readLedger() {
|
|
459
|
+
try {
|
|
460
|
+
return JSON.parse(await readFile(sessionFactsLedgerFile(), "utf8"));
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
return {};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function writeLedger(ledger) {
|
|
467
|
+
const file = sessionFactsLedgerFile();
|
|
468
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
469
|
+
await atomicWrite(file, `${JSON.stringify(ledger, null, 2)}\n`, 0o600);
|
|
470
|
+
}
|
|
471
|
+
// Each grounded fact (T-329 phase 3) is filed on its own when it routes to a record that does not
|
|
472
|
+
// exist yet: the audit keeps it, and undo is a soft delete. A fact that would change an existing
|
|
473
|
+
// or similar record, or that has no home, waits as a candidate (proposeMemory's own checks: size,
|
|
474
|
+
// secrets). A ledger of content hashes keeps the same fact from being captured twice across
|
|
475
|
+
// sessions; within one session the transcript cursor already keeps the same turns from being read
|
|
476
|
+
// twice.
|
|
477
|
+
export async function captureSessionFacts(options) {
|
|
478
|
+
// Two sessions ending together read and write the same ledger.
|
|
479
|
+
await mkdir(path.dirname(sessionFactsLedgerFile()), {
|
|
480
|
+
recursive: true,
|
|
481
|
+
mode: 0o700,
|
|
482
|
+
});
|
|
483
|
+
return withFileLock(sessionFactsLedgerFile(), () => proposeLocked(options));
|
|
484
|
+
}
|
|
485
|
+
async function proposeLocked(options) {
|
|
486
|
+
const ledger = await readLedger();
|
|
487
|
+
const result = {
|
|
488
|
+
filed: [],
|
|
489
|
+
proposed: [],
|
|
490
|
+
unrouted: [],
|
|
491
|
+
skipped: [],
|
|
492
|
+
};
|
|
493
|
+
for (const fact of options.facts) {
|
|
494
|
+
const key = factKey(fact);
|
|
495
|
+
if (ledger[key]) {
|
|
496
|
+
result.skipped.push({
|
|
497
|
+
title: fact.title,
|
|
498
|
+
reason: `already proposed as ${ledger[key]}`,
|
|
499
|
+
});
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const content = `# ${fact.title}\n\n${fact.content}\n\n> ${fact.evidence}\n`;
|
|
503
|
+
const source = `${SESSION_FACTS_SOURCE_PREFIX}${options.sessionId}`;
|
|
504
|
+
const target = await factTarget(fact);
|
|
505
|
+
if (!target && fact.type === "project") {
|
|
506
|
+
// A project fact whose project Ocean does not know (T-335): kept, with the project the
|
|
507
|
+
// model suggested, for the owner to place.
|
|
508
|
+
const kept = await keepUnrouted(fact, content, source, options.client);
|
|
509
|
+
if (kept) {
|
|
510
|
+
ledger[key] = kept;
|
|
511
|
+
result.unrouted.push(kept);
|
|
512
|
+
}
|
|
513
|
+
else
|
|
514
|
+
result.skipped.push({
|
|
515
|
+
title: fact.title,
|
|
516
|
+
reason: "unrouted fact refused (empty, too large or a secret)",
|
|
517
|
+
});
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (target) {
|
|
521
|
+
const written = await fileNew(target, content, source);
|
|
522
|
+
if (written) {
|
|
523
|
+
ledger[key] = written.path;
|
|
524
|
+
result.filed.push(written);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
const { candidate } = await proposeMemory({
|
|
530
|
+
content,
|
|
531
|
+
origin: "inferred",
|
|
532
|
+
source,
|
|
533
|
+
reason: fact.reason || "stated by the user in a session",
|
|
534
|
+
target,
|
|
535
|
+
meta: {
|
|
536
|
+
kind: "fact",
|
|
537
|
+
client: options.client,
|
|
538
|
+
evidence: fact.source ?? "user",
|
|
539
|
+
...(fact.type ? { type: fact.type } : {}),
|
|
540
|
+
...(fact.project ? { project: fact.project } : {}),
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
ledger[key] = candidate;
|
|
544
|
+
result.proposed.push(candidate);
|
|
545
|
+
}
|
|
546
|
+
catch (error) {
|
|
547
|
+
if (!(error instanceof MemoryContractError))
|
|
548
|
+
throw error;
|
|
549
|
+
result.skipped.push({
|
|
550
|
+
title: fact.title,
|
|
551
|
+
reason: `${error.code}: ${error.message}`,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (result.proposed.length || result.filed.length || result.unrouted.length)
|
|
556
|
+
await writeLedger(ledger);
|
|
557
|
+
return result;
|
|
558
|
+
}
|
|
559
|
+
// One project fact with no known project, as a note in 00-inbox/unrouted/; its path, relative to
|
|
560
|
+
// the workspace, or null when the content is refused.
|
|
561
|
+
async function keepUnrouted(fact, content, source, client) {
|
|
562
|
+
try {
|
|
563
|
+
checkContent(content);
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
if (error instanceof MemoryContractError)
|
|
567
|
+
return null;
|
|
568
|
+
throw error;
|
|
569
|
+
}
|
|
570
|
+
const name = `${localDate()}-${projectSlug(fact.title) || "fact"}-${sha256(content).slice(0, 8)}.md`;
|
|
571
|
+
const file = unroutedFile(name);
|
|
572
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
573
|
+
const body = [
|
|
574
|
+
"---",
|
|
575
|
+
"type: unrouted",
|
|
576
|
+
`suggested_project: ${JSON.stringify(fact.suggestedProject ?? fact.project ?? "")}`,
|
|
577
|
+
`source: ${JSON.stringify(source)}`,
|
|
578
|
+
`client: ${JSON.stringify(client)}`,
|
|
579
|
+
`evidence: ${fact.source ?? "user"}`,
|
|
580
|
+
`created: ${new Date().toISOString()}`,
|
|
581
|
+
"---",
|
|
582
|
+
"",
|
|
583
|
+
content,
|
|
584
|
+
].join("\n");
|
|
585
|
+
await atomicWrite(file, body, 0o600);
|
|
586
|
+
return path.relative(oceanPath(), file).split(path.sep).join("/");
|
|
587
|
+
}
|
|
588
|
+
// What sessions filed on their own on one local date and is still there (not undone or deleted
|
|
589
|
+
// since): the day's "Filed" list, each with its undo.
|
|
590
|
+
export async function filedFromSessions(date = localDate()) {
|
|
591
|
+
const entries = await readAudit();
|
|
592
|
+
const filed = [];
|
|
593
|
+
for (const [index, entry] of entries.entries()) {
|
|
594
|
+
if (entry.action !== "create" || !isSessionFactSource(entry.source))
|
|
595
|
+
continue;
|
|
596
|
+
if (localDate(new Date(entry.ts)) !== date)
|
|
597
|
+
continue;
|
|
598
|
+
const removed = entries
|
|
599
|
+
.slice(index + 1)
|
|
600
|
+
.some((later) => later.path === entry.path && later.action === "delete");
|
|
601
|
+
if (!removed)
|
|
602
|
+
filed.push({ path: entry.path, auditId: entry.id, at: entry.ts });
|
|
603
|
+
}
|
|
604
|
+
return filed;
|
|
605
|
+
}
|
|
606
|
+
// A new record, or null when the path or a similar record exists (or the write is refused):
|
|
607
|
+
// changing a record the owner has is left to his review.
|
|
608
|
+
async function fileNew(target, content, source) {
|
|
609
|
+
try {
|
|
610
|
+
const written = await writeMemoryRecord({
|
|
611
|
+
path: target,
|
|
612
|
+
content,
|
|
613
|
+
mode: "create",
|
|
614
|
+
source,
|
|
615
|
+
provenance: { origin: "inferred" },
|
|
616
|
+
});
|
|
617
|
+
return { path: written.path, auditId: written.auditId };
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
if (error instanceof MemoryContractError)
|
|
621
|
+
return null;
|
|
622
|
+
throw error;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
//# sourceMappingURL=session-facts.js.map
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { redactRuntimeText } from "@ocean/core/domain/redaction
|
|
3
|
+
import { redactRuntimeText } from "@ocean/core/domain/redaction.js";
|
|
4
4
|
import { KNOWLEDGE_DIR, oceanPath } from "@ocean/core/shared/paths.js";
|
|
5
|
-
import { syncMemoryIndexes } from "
|
|
6
|
-
import { isProvingEvidence } from "
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"discoveries",
|
|
11
|
-
"failures",
|
|
12
|
-
"research",
|
|
13
|
-
"results",
|
|
14
|
-
"solutions",
|
|
15
|
-
"references",
|
|
16
|
-
]);
|
|
17
|
-
export async function promoteSessionToKnowledge(sessionId, openStore, target = "knowledge/results", approved = false) {
|
|
5
|
+
import { syncMemoryIndexes } from "../memory/index-sync.js";
|
|
6
|
+
import { isProvingEvidence } from "../memory/lesson-learning.js";
|
|
7
|
+
// 05-knowledge holds two folders (T-329 phase 4).
|
|
8
|
+
const kinds = new Set(["decisions", "lessons"]);
|
|
9
|
+
export async function promoteSessionToKnowledge(sessionId, openStore, target = "knowledge/lessons", approved = false) {
|
|
18
10
|
if (!approved)
|
|
19
11
|
throw new Error("Session promotion requires explicit approval: use --approve or approved: true");
|
|
20
12
|
const match = /^knowledge\/(\w+)$/.exec(target);
|
|
21
13
|
if (!match || !kinds.has(match[1]))
|
|
22
|
-
throw new Error("Target must be knowledge/<
|
|
14
|
+
throw new Error("Target must be knowledge/<decisions|lessons>");
|
|
23
15
|
const store = await openStore();
|
|
24
16
|
try {
|
|
25
17
|
const session = store.get(sessionId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { redactRuntimeText } from "@ocean/core/domain/redaction
|
|
4
|
+
import { redactRuntimeText } from "@ocean/core/domain/redaction.js";
|
|
5
5
|
import { safeJsonParse } from "@ocean/core/shared/fs-utils.js";
|
|
6
6
|
import { localDate, localMoment } from "@ocean/core/shared/local-date.js";
|
|
7
7
|
import { oceanPath, oceanRoot, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|