@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
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync,
|
|
3
|
-
import {
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { readdir } from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { NO_PROJECT, } from "../domain/sessions/session-identity.js";
|
|
8
|
+
import { formatTaskId, LEGACY_PREFIX } from "../domain/task-id.js";
|
|
9
|
+
import { listProjectDirs, oceanPath, oceanRoot, projectDir, projectFolder, WORKSPACE_PROJECT_ID, } from "./paths.js";
|
|
10
|
+
import { combineBindings, listLegacyBindings, withProjectsLock, } from "./project-legacy.js";
|
|
11
|
+
import { canonicalPath, listProjectManifests, writeManifest, } from "./project-manifest.js";
|
|
10
12
|
export function projectConfirmationQuestion(resolution) {
|
|
11
13
|
if (resolution.status === "bound")
|
|
12
14
|
return null;
|
|
@@ -14,9 +16,6 @@ export function projectConfirmationQuestion(resolution) {
|
|
|
14
16
|
return "Which Ocean project should this request use? Specify the project name or binding path.";
|
|
15
17
|
return "Which Ocean project should this request use? Provide the project name and path to bind it.";
|
|
16
18
|
}
|
|
17
|
-
function bindingsFile() {
|
|
18
|
-
return registryFile("project-bindings.json");
|
|
19
|
-
}
|
|
20
19
|
export function findGitRoot(startDir) {
|
|
21
20
|
let dir = path.resolve(startDir);
|
|
22
21
|
while (true) {
|
|
@@ -30,7 +29,7 @@ export function findGitRoot(startDir) {
|
|
|
30
29
|
}
|
|
31
30
|
// A linked worktree (`git worktree add`) has a `.git` file pointing into the main repo's
|
|
32
31
|
// `.git/worktrees/<name>`; returns that main repo, or null for a normal repo or a submodule.
|
|
33
|
-
|
|
32
|
+
function linkedWorktreeMain(gitRoot) {
|
|
34
33
|
try {
|
|
35
34
|
const dotGit = path.join(gitRoot, ".git");
|
|
36
35
|
if (!statSync(dotGit).isFile())
|
|
@@ -46,6 +45,42 @@ export function linkedWorktreeMain(gitRoot) {
|
|
|
46
45
|
return null;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
48
|
+
// The branch checked out in the repo containing `directory`, from its HEAD file (no git call);
|
|
49
|
+
// undefined outside a repo or on a detached HEAD.
|
|
50
|
+
export function gitBranch(directory) {
|
|
51
|
+
const root = findGitRoot(directory);
|
|
52
|
+
if (!root)
|
|
53
|
+
return undefined;
|
|
54
|
+
try {
|
|
55
|
+
let gitdir = path.join(root, ".git");
|
|
56
|
+
if (statSync(gitdir).isFile()) {
|
|
57
|
+
const pointer = readFileSync(gitdir, "utf8").match(/^gitdir:\s*(.+)$/m)?.[1];
|
|
58
|
+
if (!pointer)
|
|
59
|
+
return undefined;
|
|
60
|
+
gitdir = path.resolve(root, pointer.trim());
|
|
61
|
+
}
|
|
62
|
+
return readFileSync(path.join(gitdir, "HEAD"), "utf8").match(/^ref:\s*refs\/heads\/(.+)$/m)?.[1];
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// A touched path as a record names it: relative to the repo it sits in, else to the home folder
|
|
69
|
+
// (`~/…`), else as given. Forward slashes on every platform.
|
|
70
|
+
export function repoRelative(file, root) {
|
|
71
|
+
const slashed = (value) => value.split(path.sep).join("/");
|
|
72
|
+
if (!path.isAbsolute(file))
|
|
73
|
+
return slashed(file);
|
|
74
|
+
if (root) {
|
|
75
|
+
const relative = path.relative(root, file);
|
|
76
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative))
|
|
77
|
+
return slashed(relative);
|
|
78
|
+
}
|
|
79
|
+
const home = path.relative(os.homedir(), file);
|
|
80
|
+
if (home && !home.startsWith("..") && !path.isAbsolute(home))
|
|
81
|
+
return `~/${slashed(home)}`;
|
|
82
|
+
return slashed(file);
|
|
83
|
+
}
|
|
49
84
|
const execFileAsync = promisify(execFile);
|
|
50
85
|
// `git status --short` lines for the repo containing `directory`; [] when it is not a repo or
|
|
51
86
|
// git fails. --no-optional-locks: sessions share working trees, and a status that refreshes the
|
|
@@ -62,271 +97,9 @@ export async function gitChangedFiles(directory, timeout = 1_000) {
|
|
|
62
97
|
return [];
|
|
63
98
|
}
|
|
64
99
|
}
|
|
65
|
-
export const MAX_PROJECT_RULES = 10;
|
|
66
|
-
export const MAX_PROJECT_RULE_BYTES = 200;
|
|
67
|
-
export const MAX_PROJECT_VERIFY = 5;
|
|
68
|
-
export const MAX_PROJECT_VERIFY_BYTES = 300;
|
|
69
|
-
export const MAX_PROJECT_TAGS = 10;
|
|
70
|
-
export const MAX_PROJECT_FORMER_PATHS = 20;
|
|
71
|
-
const MANIFEST_FILE = "project.json";
|
|
72
|
-
export function expandHome(value) {
|
|
73
|
-
if (value === "~")
|
|
74
|
-
return os.homedir();
|
|
75
|
-
if (value.startsWith("~/") || value.startsWith("~\\"))
|
|
76
|
-
return path.join(os.homedir(), value.slice(2));
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
export function portablePath(value) {
|
|
80
|
-
const home = os.homedir();
|
|
81
|
-
const resolved = path.resolve(value);
|
|
82
|
-
if (resolved === home)
|
|
83
|
-
return "~";
|
|
84
|
-
if (resolved.startsWith(`${home}${path.sep}`))
|
|
85
|
-
return `~/${path.relative(home, resolved).split(path.sep).join("/")}`;
|
|
86
|
-
return resolved;
|
|
87
|
-
}
|
|
88
|
-
import { isProjectCategory, isValidProjectId, PROJECT_CATEGORIES, PROJECT_CATEGORY_FOLDERS, UNCATEGORIZED, } from "../domain/context/project-id.js";
|
|
89
|
-
export { isValidProjectId, PROJECT_CATEGORIES, UNCATEGORIZED, };
|
|
90
|
-
// One spelling per directory: symlinks resolved (macOS /var is /private/var, and process.cwd()
|
|
91
|
-
// returns the resolved form), so a bound path and the cwd of a session inside it compare equal.
|
|
92
|
-
// A path that does not exist (a repo not cloned on this machine yet) is kept as written.
|
|
93
|
-
export function canonicalPath(value) {
|
|
94
|
-
const resolved = path.resolve(expandHome(value));
|
|
95
|
-
try {
|
|
96
|
-
return realpathSync(resolved);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return resolved;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function projectsRoot() {
|
|
103
|
-
return oceanPath(PROJECTS_DIR);
|
|
104
|
-
}
|
|
105
|
-
// The category folder a project folder sits in, or undefined while it is flat.
|
|
106
|
-
function folderCategory(dir) {
|
|
107
|
-
const [first, second] = path.posix.relative(PROJECTS_DIR, dir).split("/");
|
|
108
|
-
return second && PROJECT_CATEGORY_FOLDERS.includes(first) ? first : undefined;
|
|
109
|
-
}
|
|
110
|
-
// Control characters (tab aside) and Unicode line breaks: a rule or command is one plain line.
|
|
111
|
-
const LINE_BREAKING = /[\p{Cc}\u2028\u2029]/u;
|
|
112
|
-
export function hasControlCharacters(value) {
|
|
113
|
-
return LINE_BREAKING.test(value.replace(/\t/g, " "));
|
|
114
|
-
}
|
|
115
|
-
function lineList(field, value, maxEntries, maxBytes) {
|
|
116
|
-
if (value === undefined)
|
|
117
|
-
return [];
|
|
118
|
-
if (!Array.isArray(value))
|
|
119
|
-
throw new Error(`${field} must be a list of strings`);
|
|
120
|
-
if (value.length > maxEntries)
|
|
121
|
-
throw new Error(`${field} holds at most ${maxEntries} entries`);
|
|
122
|
-
return value.map((entry, index) => {
|
|
123
|
-
if (typeof entry !== "string" || !entry.trim())
|
|
124
|
-
throw new Error(`${field}[${index}] must be a non-empty string`);
|
|
125
|
-
const line = entry.trim();
|
|
126
|
-
if (hasControlCharacters(line))
|
|
127
|
-
throw new Error(`${field}[${index}] must be a single line without control characters`);
|
|
128
|
-
if (Buffer.byteLength(line, "utf8") > maxBytes)
|
|
129
|
-
throw new Error(`${field}[${index}] exceeds ${maxBytes} bytes`);
|
|
130
|
-
return line;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
// The validated lists, or an Error naming the field.
|
|
134
|
-
export function projectRules(manifest) {
|
|
135
|
-
return lineList("rules", manifest.rules, MAX_PROJECT_RULES, MAX_PROJECT_RULE_BYTES);
|
|
136
|
-
}
|
|
137
|
-
export function projectVerify(manifest) {
|
|
138
|
-
return lineList("verify", manifest.verify, MAX_PROJECT_VERIFY, MAX_PROJECT_VERIFY_BYTES);
|
|
139
|
-
}
|
|
140
|
-
export function projectTags(manifest) {
|
|
141
|
-
return lineList("tags", manifest.tags, MAX_PROJECT_TAGS, 40).map((tag) => tag.toLowerCase());
|
|
142
|
-
}
|
|
143
|
-
// The category, undefined when none is set, or an Error naming the allowed values.
|
|
144
|
-
export function projectCategory(manifest) {
|
|
145
|
-
if (manifest.category === undefined)
|
|
146
|
-
return undefined;
|
|
147
|
-
if (!isProjectCategory(manifest.category))
|
|
148
|
-
throw new Error(`category must be one of ${PROJECT_CATEGORIES.join(", ")}`);
|
|
149
|
-
return manifest.category;
|
|
150
|
-
}
|
|
151
|
-
export function projectFormerPaths(manifest) {
|
|
152
|
-
return lineList("formerPaths", manifest.formerPaths, MAX_PROJECT_FORMER_PATHS, 500);
|
|
153
|
-
}
|
|
154
|
-
// `folder` is the project folder's name, `category` the category folder it sits in, if any.
|
|
155
|
-
function parseManifest(folder, raw, category) {
|
|
156
|
-
const parsed = JSON.parse(raw);
|
|
157
|
-
if (!parsed ||
|
|
158
|
-
typeof parsed !== "object" ||
|
|
159
|
-
!Array.isArray(parsed.paths) ||
|
|
160
|
-
parsed.paths.some((entry) => typeof entry !== "string" || !entry.trim()))
|
|
161
|
-
throw new Error("paths must be a list of non-empty strings");
|
|
162
|
-
if (parsed.prefix !== undefined &&
|
|
163
|
-
(typeof parsed.prefix !== "string" ||
|
|
164
|
-
parsed.prefix === LEGACY_PREFIX ||
|
|
165
|
-
!isValidPrefix(parsed.prefix)))
|
|
166
|
-
throw new Error(`prefix '${String(parsed.prefix)}' is not a valid task prefix`);
|
|
167
|
-
if (parsed.nextTask !== undefined &&
|
|
168
|
-
(!Number.isInteger(parsed.nextTask) || parsed.nextTask < 1))
|
|
169
|
-
throw new Error("nextTask must be a positive integer");
|
|
170
|
-
// The folder name is the id; a manifest cannot claim another project's identity.
|
|
171
|
-
return {
|
|
172
|
-
id: folder,
|
|
173
|
-
name: typeof parsed.name === "string" && parsed.name ? parsed.name : folder,
|
|
174
|
-
paths: parsed.paths,
|
|
175
|
-
created: typeof parsed.created === "string" ? parsed.created : "",
|
|
176
|
-
autoRegistered: parsed.autoRegistered === true,
|
|
177
|
-
...(parsed.prefix !== undefined ? { prefix: parsed.prefix } : {}),
|
|
178
|
-
...(parsed.nextTask !== undefined ? { nextTask: parsed.nextTask } : {}),
|
|
179
|
-
...(parsed.rules !== undefined ? { rules: parsed.rules } : {}),
|
|
180
|
-
...(parsed.verify !== undefined ? { verify: parsed.verify } : {}),
|
|
181
|
-
...(parsed.tags !== undefined ? { tags: parsed.tags } : {}),
|
|
182
|
-
...(parsed.formerPaths !== undefined
|
|
183
|
-
? { formerPaths: parsed.formerPaths }
|
|
184
|
-
: {}),
|
|
185
|
-
...(category === UNCATEGORIZED
|
|
186
|
-
? {}
|
|
187
|
-
: category !== undefined
|
|
188
|
-
? { category }
|
|
189
|
-
: parsed.category !== undefined
|
|
190
|
-
? { category: parsed.category }
|
|
191
|
-
: {}),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
// A broken project.json takes only its own project out of resolution: resolveProject runs in
|
|
195
|
-
// every session's start hook, so one bad file must not break every project. The errors are
|
|
196
|
-
// returned for `ocean project list` to report.
|
|
197
|
-
export async function scanProjectManifests() {
|
|
198
|
-
const scan = { manifests: [], errors: [] };
|
|
199
|
-
const seen = new Set();
|
|
200
|
-
for (const { id, category, dir } of listProjectDirs()) {
|
|
201
|
-
const file = oceanPath(dir, MANIFEST_FILE);
|
|
202
|
-
// One id with project.json in two folders: the first, where projectDir looks first, is the
|
|
203
|
-
// project. A folder without project.json claims nothing.
|
|
204
|
-
if (seen.has(id)) {
|
|
205
|
-
if (existsSync(file))
|
|
206
|
-
scan.errors.push({
|
|
207
|
-
file,
|
|
208
|
-
error: `project id '${id}' is already used by another category folder`,
|
|
209
|
-
});
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
scan.manifests.push(parseManifest(id, await readFile(file, "utf8"), category));
|
|
214
|
-
seen.add(id);
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
if (error.code === "ENOENT")
|
|
218
|
-
continue;
|
|
219
|
-
seen.add(id);
|
|
220
|
-
scan.errors.push({
|
|
221
|
-
file,
|
|
222
|
-
error: error instanceof Error ? error.message : String(error),
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return scan;
|
|
227
|
-
}
|
|
228
|
-
// One project's manifest, or null when it has none. A manifest that does not parse throws:
|
|
229
|
-
// callers that must hold a project's rules fail closed instead of dropping them.
|
|
230
|
-
export async function readProjectManifest(id, root = oceanRoot()) {
|
|
231
|
-
if (!isValidProjectId(id))
|
|
232
|
-
return null;
|
|
233
|
-
const dir = projectDir(id, root);
|
|
234
|
-
try {
|
|
235
|
-
return parseManifest(projectFolder(id), await readFile(path.join(root, dir, MANIFEST_FILE), "utf8"), folderCategory(dir));
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
if (error.code === "ENOENT")
|
|
239
|
-
return null;
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
export async function listProjectManifests() {
|
|
244
|
-
return (await scanProjectManifests()).manifests;
|
|
245
|
-
}
|
|
246
|
-
export async function writeManifest(manifest) {
|
|
247
|
-
const dir = projectDir(manifest.id);
|
|
248
|
-
const file = oceanPath(dir, MANIFEST_FILE);
|
|
249
|
-
// In a category folder the folder is the category; only a flat project keeps the field.
|
|
250
|
-
const { category, ...rest } = manifest;
|
|
251
|
-
const record = folderCategory(dir) === undefined && category !== undefined
|
|
252
|
-
? manifest
|
|
253
|
-
: rest;
|
|
254
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
255
|
-
await atomicWrite(file, `${JSON.stringify(record, null, 2)}\n`);
|
|
256
|
-
}
|
|
257
|
-
// Bindings recorded before T-256, read from the flat registry file. Kept as a fallback until
|
|
258
|
-
// `ocean project migrate --write` folds them into manifests, and rewritten as a cache after
|
|
259
|
-
// every manifest change for anything that still reads the file. Entries the cache holds for
|
|
260
|
-
// manifests are skipped, so a deleted project folder does not come back through it.
|
|
261
|
-
// A corrupt file throws: resolution fails closed (no project, no task references) and writers
|
|
262
|
-
// never overwrite what they cannot read. The session-start hook catches it on its own.
|
|
263
|
-
async function listLegacyBindings() {
|
|
264
|
-
try {
|
|
265
|
-
const raw = await readFile(bindingsFile(), "utf8");
|
|
266
|
-
const parsed = JSON.parse(raw);
|
|
267
|
-
if (!Array.isArray(parsed?.bindings ?? []))
|
|
268
|
-
throw new Error(`${bindingsFile()}: bindings is not a list`);
|
|
269
|
-
return (parsed.bindings ?? []).filter((binding) => !binding.manifest);
|
|
270
|
-
}
|
|
271
|
-
catch (error) {
|
|
272
|
-
if (error.code === "ENOENT")
|
|
273
|
-
return [];
|
|
274
|
-
throw error;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
// gitRoot is left null here: resolution matches on paths, and walking up from every path of
|
|
278
|
-
// every project on each session start would cost a filesystem walk per path for nothing.
|
|
279
|
-
function manifestBindings(manifests) {
|
|
280
|
-
return manifests.flatMap((manifest) => manifest.paths.map((stored) => ({
|
|
281
|
-
id: manifest.id,
|
|
282
|
-
name: manifest.name,
|
|
283
|
-
path: canonicalPath(stored),
|
|
284
|
-
gitRoot: null,
|
|
285
|
-
boundAt: manifest.created,
|
|
286
|
-
manifest: true,
|
|
287
|
-
})));
|
|
288
|
-
}
|
|
289
|
-
function combineBindings(manifests, legacy) {
|
|
290
|
-
const fromManifests = manifestBindings(manifests);
|
|
291
|
-
const claimed = new Set(fromManifests.map((binding) => binding.path));
|
|
292
|
-
return [
|
|
293
|
-
...fromManifests,
|
|
294
|
-
...legacy
|
|
295
|
-
.map((binding) => ({ ...binding, path: canonicalPath(binding.path) }))
|
|
296
|
-
.filter((binding) => !claimed.has(binding.path)),
|
|
297
|
-
];
|
|
298
|
-
}
|
|
299
100
|
export async function listProjectBindings() {
|
|
300
101
|
return combineBindings(await listProjectManifests(), await listLegacyBindings());
|
|
301
102
|
}
|
|
302
|
-
// The cache keeps every legacy entry, including ones a manifest now claims, so deleting that
|
|
303
|
-
// manifest later never loses the old binding.
|
|
304
|
-
function cacheBindings(manifests, legacy) {
|
|
305
|
-
return [...manifestBindings(manifests), ...legacy];
|
|
306
|
-
}
|
|
307
|
-
async function saveProjectBindings(bindings) {
|
|
308
|
-
const file = bindingsFile();
|
|
309
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
310
|
-
await atomicWrite(file, `${JSON.stringify({ version: 1, bindings }, null, 2)}\n`);
|
|
311
|
-
}
|
|
312
|
-
// One lock for every manifest/cache write: bindings are checked across all projects (a path
|
|
313
|
-
// may belong to one project only), so per-project locks would let two writers both pass.
|
|
314
|
-
export function withProjectsLock(run) {
|
|
315
|
-
return withFileLock(bindingsFile(), run);
|
|
316
|
-
}
|
|
317
|
-
// A manifest for a project seen for the first time. A folder with no tasks gets its own task
|
|
318
|
-
// prefix and counter; one that already holds tasks stays on the legacy T namespace until
|
|
319
|
-
// `ocean tasks renumber`. The workspace project is always T.
|
|
320
|
-
async function newManifest(id, fields, others) {
|
|
321
|
-
const manifest = { id, ...fields };
|
|
322
|
-
if (isWorkspaceProject(id))
|
|
323
|
-
return manifest;
|
|
324
|
-
const tasks = await readdir(oceanPath(projectDir(id), "tasks")).catch(() => []);
|
|
325
|
-
if (tasks.some((entry) => !entry.startsWith(".")))
|
|
326
|
-
return manifest;
|
|
327
|
-
const taken = others.flatMap((other) => (other.prefix ? [other.prefix] : []));
|
|
328
|
-
return { ...manifest, prefix: derivePrefix(id, taken), nextTask: 1 };
|
|
329
|
-
}
|
|
330
103
|
export async function knownTaskPrefixes() {
|
|
331
104
|
const prefixes = (await listProjectManifests()).flatMap((manifest) => manifest.prefix ? [manifest.prefix] : []);
|
|
332
105
|
return [LEGACY_PREFIX, ...new Set(prefixes)];
|
|
@@ -407,19 +180,44 @@ export async function withNextTaskId(projectId, run) {
|
|
|
407
180
|
return result;
|
|
408
181
|
});
|
|
409
182
|
}
|
|
183
|
+
// The project whose own folder (04-projects/<category>/<id>/, or a flat 04-projects/<id>/)
|
|
184
|
+
// holds the cwd, when that folder has a project.json (T-331). Without this a session started in
|
|
185
|
+
// a project folder resolved to the workspace project through the ocean root.
|
|
186
|
+
function projectFolderMatch(cwd, manifests) {
|
|
187
|
+
for (const manifest of manifests) {
|
|
188
|
+
const folder = canonicalPath(oceanPath(projectDir(manifest.id)));
|
|
189
|
+
if (cwd === folder || cwd.startsWith(`${folder}${path.sep}`))
|
|
190
|
+
return { manifest, folder };
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
410
194
|
// Resolves the active Ocean project from a working directory: no terminal-in-Ocean
|
|
411
|
-
// requirement. Match order is
|
|
412
|
-
// the
|
|
195
|
+
// requirement. Match order is the project's own folder (unless a bound path is deeper), git
|
|
196
|
+
// root, then the exact cwd, then (as a last resort) whether the path is inside the Ocean
|
|
197
|
+
// workspace root itself, which is always the workspace project.
|
|
413
198
|
export async function resolveProject(cwd) {
|
|
414
199
|
const resolvedCwd = canonicalPath(cwd);
|
|
415
200
|
const gitRoot = findGitRoot(resolvedCwd);
|
|
416
|
-
const
|
|
201
|
+
const manifests = await listProjectManifests();
|
|
202
|
+
const bindings = combineBindings(manifests, await listLegacyBindings());
|
|
203
|
+
const inFolder = projectFolderMatch(resolvedCwd, manifests);
|
|
417
204
|
const containing = bindings
|
|
418
205
|
.filter((binding) => {
|
|
419
206
|
const bound = path.resolve(binding.path);
|
|
420
207
|
return (resolvedCwd === bound || resolvedCwd.startsWith(`${bound}${path.sep}`));
|
|
421
208
|
})
|
|
422
209
|
.sort((a, b) => path.resolve(b.path).length - path.resolve(a.path).length);
|
|
210
|
+
if (inFolder &&
|
|
211
|
+
(!containing.length ||
|
|
212
|
+
path.resolve(containing[0].path).length <= inFolder.folder.length))
|
|
213
|
+
return {
|
|
214
|
+
status: "bound",
|
|
215
|
+
projectId: inFolder.manifest.id,
|
|
216
|
+
name: inFolder.manifest.name,
|
|
217
|
+
path: inFolder.folder,
|
|
218
|
+
matchedOn: "project-folder",
|
|
219
|
+
confidence: "high",
|
|
220
|
+
};
|
|
423
221
|
if (containing.length &&
|
|
424
222
|
(!containing[1] ||
|
|
425
223
|
path.resolve(containing[0].path).length >
|
|
@@ -485,593 +283,6 @@ export async function resolveProject(cwd) {
|
|
|
485
283
|
}
|
|
486
284
|
return { status: "unbound", cwd: resolvedCwd, gitRoot, confidence: "none" };
|
|
487
285
|
}
|
|
488
|
-
// Explicit registration/binding: never guesses on a name or path collision, always returns
|
|
489
|
-
// the conflict instead of silently overwriting an existing binding. `addPath` is the one
|
|
490
|
-
// deliberate exception: it adds another repo to an existing project (dashboard + backend).
|
|
491
|
-
export async function bindProject(name, targetPath, options = {}) {
|
|
492
|
-
if (!isValidProjectId(name))
|
|
493
|
-
throw new Error(`Invalid project id '${name}': use lowercase letters, digits, dot, underscore or hyphen`);
|
|
494
|
-
const resolvedPath = canonicalPath(targetPath);
|
|
495
|
-
return withProjectsLock(async () => {
|
|
496
|
-
const manifests = await listProjectManifests();
|
|
497
|
-
const legacy = await listLegacyBindings();
|
|
498
|
-
const bindings = combineBindings(manifests, legacy);
|
|
499
|
-
const existingAtPath = bindings.find((binding) => path.resolve(binding.path) === resolvedPath);
|
|
500
|
-
if (existingAtPath && existingAtPath.id !== name)
|
|
501
|
-
return {
|
|
502
|
-
binding: existingAtPath,
|
|
503
|
-
created: false,
|
|
504
|
-
conflict: existingAtPath,
|
|
505
|
-
};
|
|
506
|
-
if (existingAtPath?.manifest)
|
|
507
|
-
return { binding: existingAtPath, created: false };
|
|
508
|
-
// From here the path is free, or is this project's own legacy binding being folded in,
|
|
509
|
-
// which is never a conflict.
|
|
510
|
-
const existingByName = bindings.find((binding) => binding.id === name && binding.path !== resolvedPath);
|
|
511
|
-
if (existingByName && !existingAtPath && !options.addPath)
|
|
512
|
-
return {
|
|
513
|
-
binding: existingByName,
|
|
514
|
-
created: false,
|
|
515
|
-
conflict: existingByName,
|
|
516
|
-
};
|
|
517
|
-
const existing = manifests.find((manifest) => manifest.id === name);
|
|
518
|
-
// Auto-registration never takes over a folder someone else made (checked under the lock,
|
|
519
|
-
// so a folder created a moment ago by another writer counts).
|
|
520
|
-
if (options.autoRegistered &&
|
|
521
|
-
!existing &&
|
|
522
|
-
existsSync(oceanPath(projectDir(name))))
|
|
523
|
-
throw new ProjectFolderTaken(`${projectDir(name)} already exists; bind it explicitly`);
|
|
524
|
-
const manifest = existing
|
|
525
|
-
? { ...existing, paths: [...existing.paths, portablePath(resolvedPath)] }
|
|
526
|
-
: await newManifest(name, {
|
|
527
|
-
name,
|
|
528
|
-
paths: [portablePath(resolvedPath)],
|
|
529
|
-
created: new Date().toISOString(),
|
|
530
|
-
autoRegistered: options.autoRegistered === true,
|
|
531
|
-
}, manifests);
|
|
532
|
-
await writeManifest(manifest);
|
|
533
|
-
const updated = manifests
|
|
534
|
-
.filter((candidate) => candidate.id !== name)
|
|
535
|
-
.concat(manifest);
|
|
536
|
-
const next = combineBindings(updated, legacy);
|
|
537
|
-
await saveProjectBindings(cacheBindings(updated, legacy));
|
|
538
|
-
const binding = next.find((candidate) => candidate.path === resolvedPath);
|
|
539
|
-
return { binding, created: true };
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
// One-time fold of the legacy bindings file into manifests. Generic on purpose (the kernel is
|
|
543
|
-
// public): a binding becomes a path of `04-projects/<id>/project.json` only when that project
|
|
544
|
-
// folder exists; any other binding is reported and left alone, never turned into a new folder.
|
|
545
|
-
export async function migrateProjectBindings(write) {
|
|
546
|
-
return withProjectsLock(async () => {
|
|
547
|
-
const legacy = await listLegacyBindings();
|
|
548
|
-
const manifests = await listProjectManifests();
|
|
549
|
-
const claimed = new Set(manifestBindings(manifests).map((binding) => binding.path));
|
|
550
|
-
const result = {
|
|
551
|
-
migrated: [],
|
|
552
|
-
orphaned: [],
|
|
553
|
-
written: write,
|
|
554
|
-
};
|
|
555
|
-
const updates = new Map();
|
|
556
|
-
for (const binding of legacy) {
|
|
557
|
-
const resolved = canonicalPath(binding.path);
|
|
558
|
-
if (claimed.has(resolved))
|
|
559
|
-
continue;
|
|
560
|
-
if (!isValidProjectId(binding.id)) {
|
|
561
|
-
result.orphaned.push({
|
|
562
|
-
id: binding.id,
|
|
563
|
-
path: resolved,
|
|
564
|
-
reason: "id is not a valid project folder name; bind it explicitly",
|
|
565
|
-
});
|
|
566
|
-
continue;
|
|
567
|
-
}
|
|
568
|
-
const folder = oceanPath(projectDir(binding.id));
|
|
569
|
-
if (!existsSync(folder)) {
|
|
570
|
-
result.orphaned.push({
|
|
571
|
-
id: binding.id,
|
|
572
|
-
path: resolved,
|
|
573
|
-
reason: `no project folder ${path.relative(oceanRoot(), folder)}; bind it explicitly`,
|
|
574
|
-
});
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
const base = updates.get(binding.id) ??
|
|
578
|
-
manifests.find((manifest) => manifest.id === binding.id) ??
|
|
579
|
-
(await newManifest(binding.id, {
|
|
580
|
-
name: binding.name || binding.id,
|
|
581
|
-
paths: [],
|
|
582
|
-
created: binding.boundAt || new Date().toISOString(),
|
|
583
|
-
autoRegistered: false,
|
|
584
|
-
}, [...manifests, ...updates.values()]));
|
|
585
|
-
updates.set(binding.id, {
|
|
586
|
-
...base,
|
|
587
|
-
paths: [...base.paths, portablePath(resolved)],
|
|
588
|
-
});
|
|
589
|
-
claimed.add(resolved);
|
|
590
|
-
result.migrated.push({ id: binding.id, path: resolved });
|
|
591
|
-
}
|
|
592
|
-
if (write && updates.size) {
|
|
593
|
-
for (const manifest of updates.values())
|
|
594
|
-
await writeManifest(manifest);
|
|
595
|
-
await saveProjectBindings(cacheBindings(await listProjectManifests(), legacy));
|
|
596
|
-
}
|
|
597
|
-
return result;
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
const INDEX_BEGIN = "<!-- ocean:projects:begin (generated by `ocean project index --write`) -->";
|
|
601
|
-
const INDEX_END = "<!-- ocean:projects:end -->";
|
|
602
|
-
// Generated view of every project.json, kept in a managed block of 04-projects/registry.md so
|
|
603
|
-
// the hand-kept rows around it are never rewritten.
|
|
604
|
-
export async function renderProjectIndex() {
|
|
605
|
-
// Table cells: a `|` or a line break in a name or path would split the row.
|
|
606
|
-
const cell = (value) => value.replace(/[\r\n]+/g, " ").replaceAll("|", "\\|");
|
|
607
|
-
// One table per category, in PROJECT_CATEGORIES order; a project without one comes after,
|
|
608
|
-
// and a bad one shows as invalid instead of failing the whole index.
|
|
609
|
-
const category = (manifest) => {
|
|
610
|
-
try {
|
|
611
|
-
return projectCategory(manifest) ?? "uncategorized";
|
|
612
|
-
}
|
|
613
|
-
catch {
|
|
614
|
-
return "invalid";
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
const groups = new Map([...PROJECT_CATEGORIES, "uncategorized", "invalid"].map((name) => [
|
|
618
|
-
name,
|
|
619
|
-
[],
|
|
620
|
-
]));
|
|
621
|
-
for (const manifest of await listProjectManifests())
|
|
622
|
-
groups
|
|
623
|
-
.get(category(manifest))
|
|
624
|
-
?.push(`| \`${manifest.id}\` | ${cell(manifest.name)} | ${manifest.paths.length
|
|
625
|
-
? manifest.paths.map((entry) => `\`${cell(entry)}\``).join("<br>")
|
|
626
|
-
: "—"} | ${manifest.autoRegistered ? "auto" : "manual"} |`);
|
|
627
|
-
const sections = [...groups]
|
|
628
|
-
.filter(([, rows]) => rows.length)
|
|
629
|
-
.flatMap(([name, rows]) => [
|
|
630
|
-
"",
|
|
631
|
-
`### ${name}`,
|
|
632
|
-
"",
|
|
633
|
-
"| Project | Name | Paths | Registered |",
|
|
634
|
-
"|---|---|---|---|",
|
|
635
|
-
...rows,
|
|
636
|
-
]);
|
|
637
|
-
return [
|
|
638
|
-
INDEX_BEGIN,
|
|
639
|
-
"## Projects (from project.json)",
|
|
640
|
-
...sections,
|
|
641
|
-
INDEX_END,
|
|
642
|
-
].join("\n");
|
|
643
|
-
}
|
|
644
|
-
export async function writeProjectIndex() {
|
|
645
|
-
return withProjectsLock(writeProjectIndexLocked);
|
|
646
|
-
}
|
|
647
|
-
async function writeProjectIndexLocked() {
|
|
648
|
-
const file = path.join(projectsRoot(), "registry.md");
|
|
649
|
-
let existing = "";
|
|
650
|
-
try {
|
|
651
|
-
existing = await readFile(file, "utf8");
|
|
652
|
-
}
|
|
653
|
-
catch (error) {
|
|
654
|
-
if (error.code !== "ENOENT")
|
|
655
|
-
throw error;
|
|
656
|
-
}
|
|
657
|
-
const block = await renderProjectIndex();
|
|
658
|
-
const begin = existing.indexOf(INDEX_BEGIN);
|
|
659
|
-
const end = existing.indexOf(INDEX_END);
|
|
660
|
-
let next;
|
|
661
|
-
if (begin >= 0 && end > begin)
|
|
662
|
-
next = `${existing.slice(0, begin)}${block}${existing.slice(end + INDEX_END.length)}`;
|
|
663
|
-
else if (begin >= 0 || end >= 0)
|
|
664
|
-
throw new Error(`${file}: unmatched ocean:projects marker; fix it by hand before regenerating`);
|
|
665
|
-
else
|
|
666
|
-
next = existing
|
|
667
|
-
? `${existing.replace(/\n*$/, "")}\n\n${block}\n`
|
|
668
|
-
: `# Project registry\n\n${block}\n`;
|
|
669
|
-
if (next === existing)
|
|
670
|
-
return { file, changed: false };
|
|
671
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
672
|
-
await atomicWrite(file, next);
|
|
673
|
-
return { file, changed: true };
|
|
674
|
-
}
|
|
675
|
-
// Where a session may register its repo as a project without being asked (T-256 phase 2).
|
|
676
|
-
// OCEAN_CODE_ROOTS (a PATH-style list) overrides the default, ~/Documents.
|
|
677
|
-
export function codeRoots() {
|
|
678
|
-
const configured = oceanEnv("CODE_ROOTS");
|
|
679
|
-
return (configured ? configured.split(path.delimiter) : ["~/Documents"])
|
|
680
|
-
.map((entry) => entry.trim())
|
|
681
|
-
.filter(Boolean)
|
|
682
|
-
.map((entry) => path.resolve(expandHome(entry)));
|
|
683
|
-
}
|
|
684
|
-
// The existing project a client names (T-307): its id, or its name in any case (`LetSpeak` is
|
|
685
|
-
// `letspeak`), or that name's slug. Never a guess beyond that.
|
|
686
|
-
export function matchProject(manifests, ref) {
|
|
687
|
-
const name = ref.trim().toLowerCase();
|
|
688
|
-
const slug = projectSlug(ref);
|
|
689
|
-
return manifests.find((manifest) => manifest.id === ref ||
|
|
690
|
-
manifest.name.trim().toLowerCase() === name ||
|
|
691
|
-
(slug !== "" && manifest.id === slug))?.id;
|
|
692
|
-
}
|
|
693
|
-
// The names of the owner's Claude projects this machine has seen, as the always-on service last
|
|
694
|
-
// wrote them (T-307): reading Claude Desktop's caches takes too long for a tool call.
|
|
695
|
-
export function claudeProjectsFile() {
|
|
696
|
-
return oceanPath(SYSTEM_DIR, "state", "clients", "claude-projects.json");
|
|
697
|
-
}
|
|
698
|
-
export async function readClaudeProjects() {
|
|
699
|
-
try {
|
|
700
|
-
const parsed = JSON.parse(await readFile(claudeProjectsFile(), "utf8"));
|
|
701
|
-
return Array.isArray(parsed.names)
|
|
702
|
-
? parsed.names.filter((name) => typeof name === "string")
|
|
703
|
-
: [];
|
|
704
|
-
}
|
|
705
|
-
catch {
|
|
706
|
-
return [];
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
export async function findProject(ref) {
|
|
710
|
-
return matchProject(await listProjectManifests(), ref);
|
|
711
|
-
}
|
|
712
|
-
// A Claude project (claude.ai or Claude Desktop) first seen in a conversation (T-307): it has no
|
|
713
|
-
// repo or path, so it is registered by name — 04-projects/<slug>/ with project.json, marked
|
|
714
|
-
// auto-registered, and the standard layout. An existing project with that id or name is
|
|
715
|
-
// returned instead; a folder that exists without a manifest is never taken over.
|
|
716
|
-
export async function registerNamedProject(name, tags = []) {
|
|
717
|
-
return withProjectsLock(async () => {
|
|
718
|
-
const manifests = await listProjectManifests();
|
|
719
|
-
const known = matchProject(manifests, name);
|
|
720
|
-
if (known)
|
|
721
|
-
return { id: known, created: false };
|
|
722
|
-
const id = projectSlug(name);
|
|
723
|
-
if (!isValidProjectId(id))
|
|
724
|
-
throw new Error(`no usable project id from '${name}'`);
|
|
725
|
-
if (existsSync(oceanPath(projectDir(id))))
|
|
726
|
-
throw new ProjectFolderTaken(`${projectDir(id)}/ exists without project.json; register it explicitly`);
|
|
727
|
-
const manifest = await newManifest(id, {
|
|
728
|
-
name: name.trim(),
|
|
729
|
-
paths: [],
|
|
730
|
-
created: new Date().toISOString(),
|
|
731
|
-
autoRegistered: true,
|
|
732
|
-
}, manifests);
|
|
733
|
-
await writeManifest(tags.length ? { ...manifest, tags } : manifest);
|
|
734
|
-
await ensureProjectLayout(id);
|
|
735
|
-
await writeProjectIndexLocked();
|
|
736
|
-
return { id, created: true };
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
export function projectSlug(name) {
|
|
740
|
-
return name
|
|
741
|
-
.toLowerCase()
|
|
742
|
-
.replace(/[^a-z0-9._-]+/g, "-")
|
|
743
|
-
.replace(/^[^a-z0-9]+/, "")
|
|
744
|
-
.slice(0, 64)
|
|
745
|
-
.replace(/[-._]+$/, "");
|
|
746
|
-
}
|
|
747
|
-
async function realOrSelf(target) {
|
|
748
|
-
try {
|
|
749
|
-
return await realpath(target);
|
|
750
|
-
}
|
|
751
|
-
catch {
|
|
752
|
-
return path.resolve(target);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
function within(root, target) {
|
|
756
|
-
const prefix = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
|
|
757
|
-
return target === root || target.startsWith(prefix);
|
|
758
|
-
}
|
|
759
|
-
class ProjectFolderTaken extends Error {
|
|
760
|
-
}
|
|
761
|
-
// A session opened in a git repo that no project claims registers that repo as its own
|
|
762
|
-
// project: 04-projects/<slug>/ with project.json and the standard layout (ensureProjectLayout:
|
|
763
|
-
// tasks/, memory/, docs/, MEMORY.md). Automatic runs stay
|
|
764
|
-
// under the code roots, out of the temp dir and off a code root itself; `explicit` (the
|
|
765
|
-
// `ocean project register` command) is the owner asking, so only the hard rules apply: a git
|
|
766
|
-
// repo, not a linked worktree or submodule, not the Ocean workspace, never over an existing
|
|
767
|
-
// project folder. Sibling repos are never merged: a code-root folder often holds unrelated
|
|
768
|
-
// repos, so joining one project to another stays explicit (`bind --add`).
|
|
769
|
-
export async function autoRegisterProject(cwd, options = {}) {
|
|
770
|
-
let resolution = options.resolution ?? (await resolveProject(cwd));
|
|
771
|
-
const skipped = (reason) => ({
|
|
772
|
-
status: "skipped",
|
|
773
|
-
reason,
|
|
774
|
-
resolution,
|
|
775
|
-
});
|
|
776
|
-
if (!options.explicit && oceanEnv("AUTO_REGISTER") === "0")
|
|
777
|
-
return skipped("disabled by OCEAN_AUTO_REGISTER=0");
|
|
778
|
-
if (resolution.status !== "unbound")
|
|
779
|
-
return skipped(`already ${resolution.status}`);
|
|
780
|
-
if (!resolution.gitRoot)
|
|
781
|
-
return skipped("not inside a git repository");
|
|
782
|
-
if (!statSync(path.join(resolution.gitRoot, ".git")).isDirectory())
|
|
783
|
-
return skipped("a linked worktree or submodule; bind it explicitly");
|
|
784
|
-
const repo = await realOrSelf(resolution.gitRoot);
|
|
785
|
-
if (within(await realOrSelf(oceanRoot()), repo))
|
|
786
|
-
return skipped("inside the Ocean workspace");
|
|
787
|
-
if (!options.explicit) {
|
|
788
|
-
const roots = await Promise.all(codeRoots().map(realOrSelf));
|
|
789
|
-
if (roots.includes(repo))
|
|
790
|
-
return skipped("is a code root itself");
|
|
791
|
-
const root = roots.find((candidate) => within(candidate, repo));
|
|
792
|
-
if (!root)
|
|
793
|
-
return skipped("outside the code roots");
|
|
794
|
-
// The temp dir is excluded unless the owner deliberately put a code root inside it.
|
|
795
|
-
const temp = await realOrSelf(os.tmpdir());
|
|
796
|
-
if (within(temp, repo) && !within(temp, root))
|
|
797
|
-
return skipped("inside the temp directory");
|
|
798
|
-
}
|
|
799
|
-
const id = projectSlug(path.basename(repo));
|
|
800
|
-
if (!isValidProjectId(id))
|
|
801
|
-
return skipped(`no usable id from '${repo}'`);
|
|
802
|
-
let result;
|
|
803
|
-
try {
|
|
804
|
-
result = await bindProject(id, resolution.gitRoot, {
|
|
805
|
-
autoRegistered: true,
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
catch (error) {
|
|
809
|
-
if (!(error instanceof ProjectFolderTaken))
|
|
810
|
-
throw error;
|
|
811
|
-
// Another session may have registered this very repo a moment ago.
|
|
812
|
-
resolution = await resolveProject(cwd);
|
|
813
|
-
return skipped(error.message);
|
|
814
|
-
}
|
|
815
|
-
if (result.conflict) {
|
|
816
|
-
resolution = await resolveProject(cwd);
|
|
817
|
-
return skipped(`conflicts with project '${result.conflict.id}'`);
|
|
818
|
-
}
|
|
819
|
-
await ensureProjectLayout(id);
|
|
820
|
-
resolution = {
|
|
821
|
-
status: "bound",
|
|
822
|
-
projectId: id,
|
|
823
|
-
name: id,
|
|
824
|
-
path: result.binding.path,
|
|
825
|
-
matchedOn: result.binding.path === path.resolve(cwd) ? "cwd" : "path",
|
|
826
|
-
confidence: "high",
|
|
827
|
-
};
|
|
828
|
-
return {
|
|
829
|
-
status: "registered",
|
|
830
|
-
projectId: id,
|
|
831
|
-
path: result.binding.path,
|
|
832
|
-
resolution,
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
function memoryHeading(id) {
|
|
836
|
-
return `# ${id} — memory`;
|
|
837
|
-
}
|
|
838
|
-
// The only entries a project folder holds at its root. Lessons and decisions go in memory/
|
|
839
|
-
// (indexed by MEMORY.md, which every session in the project loads); reference material goes
|
|
840
|
-
// in docs/ (indexed by docs/README.md); work goes in tasks/. index.md is the generated board.
|
|
841
|
-
export const PROJECT_ROOT_ENTRIES = [
|
|
842
|
-
"project.json",
|
|
843
|
-
"MEMORY.md",
|
|
844
|
-
"README.md",
|
|
845
|
-
"index.md",
|
|
846
|
-
"tasks",
|
|
847
|
-
"memory",
|
|
848
|
-
"docs",
|
|
849
|
-
];
|
|
850
|
-
function memorySeed(id) {
|
|
851
|
-
return `${memoryHeading(id)}
|
|
852
|
-
|
|
853
|
-
Index of this project's memory. Loaded only for sessions in this project.
|
|
854
|
-
|
|
855
|
-
Layout — nothing else goes at the project root:
|
|
856
|
-
- Lessons, decisions, gotchas → one file in \`memory/\`, plus one line here.
|
|
857
|
-
- Reference material (requirements, API notes, plans, maps) → \`docs/\`, plus one line in \`docs/README.md\`.
|
|
858
|
-
- Work → \`tasks/<ID>/task.md\`.
|
|
859
|
-
`;
|
|
860
|
-
}
|
|
861
|
-
function docsHeading(id) {
|
|
862
|
-
return `# ${id} — docs`;
|
|
863
|
-
}
|
|
864
|
-
function docsSeed(id) {
|
|
865
|
-
return `${docsHeading(id)}
|
|
866
|
-
|
|
867
|
-
Reference material for this project: requirements, API notes, plans, maps. One line per file
|
|
868
|
-
below. Status lives in the tasks, never here.
|
|
869
|
-
`;
|
|
870
|
-
}
|
|
871
|
-
// Creates whatever of the standard layout is missing and never overwrites a file. Returns the
|
|
872
|
-
// paths it created, relative to the project folder.
|
|
873
|
-
export async function ensureProjectLayout(projectId) {
|
|
874
|
-
const folder = oceanPath(projectDir(projectId));
|
|
875
|
-
const created = [];
|
|
876
|
-
for (const directory of ["tasks", "memory", "docs"])
|
|
877
|
-
if (await mkdir(path.join(folder, directory), { recursive: true }))
|
|
878
|
-
created.push(`${directory}/`);
|
|
879
|
-
const seeds = [
|
|
880
|
-
["MEMORY.md", memorySeed(projectId)],
|
|
881
|
-
[path.join("docs", "README.md"), docsSeed(projectId)],
|
|
882
|
-
];
|
|
883
|
-
for (const [file, text] of seeds) {
|
|
884
|
-
try {
|
|
885
|
-
await writeFile(path.join(folder, file), text, { flag: "wx" });
|
|
886
|
-
created.push(file.split(path.sep).join("/"));
|
|
887
|
-
}
|
|
888
|
-
catch (error) {
|
|
889
|
-
if (error.code !== "EEXIST")
|
|
890
|
-
throw error;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
return created;
|
|
894
|
-
}
|
|
895
|
-
// Undoes a binding (a wrong auto-registration, a moved repo). Only the path goes; the project
|
|
896
|
-
// folder and its tasks stay, since deleting them is the owner's call.
|
|
897
|
-
export async function unbindProjectPath(targetPath) {
|
|
898
|
-
const resolvedPath = canonicalPath(targetPath);
|
|
899
|
-
return withProjectsLock(async () => {
|
|
900
|
-
const manifests = await listProjectManifests();
|
|
901
|
-
const legacy = await listLegacyBindings();
|
|
902
|
-
// The binding whose path contains the given one, longest first, so `unbind .` works from
|
|
903
|
-
// anywhere inside the repo.
|
|
904
|
-
const removed = combineBindings(manifests, legacy)
|
|
905
|
-
.filter((binding) => within(path.resolve(binding.path), resolvedPath))
|
|
906
|
-
.sort((a, b) => b.path.length - a.path.length)[0] ?? null;
|
|
907
|
-
if (!removed)
|
|
908
|
-
return { removed };
|
|
909
|
-
const boundPath = path.resolve(removed.path);
|
|
910
|
-
const owner = manifests.find((manifest) => manifest.paths.some((stored) => canonicalPath(stored) === boundPath));
|
|
911
|
-
if (owner)
|
|
912
|
-
await writeManifest({
|
|
913
|
-
...owner,
|
|
914
|
-
paths: owner.paths.filter((stored) => canonicalPath(stored) !== boundPath),
|
|
915
|
-
});
|
|
916
|
-
// A legacy entry for the same path would otherwise take the binding back.
|
|
917
|
-
const keptLegacy = legacy.filter((binding) => canonicalPath(binding.path) !== boundPath);
|
|
918
|
-
await saveProjectBindings(cacheBindings(await listProjectManifests(), keptLegacy));
|
|
919
|
-
return { removed };
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
// Workspace text that may name a project folder by path: the records, the projects, the charter.
|
|
923
|
-
const REFERENCE_FILE = /\.(md|json|ya?ml|toml)$/i;
|
|
924
|
-
const REFERENCE_MAX_BYTES = 2_000_000;
|
|
925
|
-
// Rewrites `from` (a project folder relative to the Ocean root) to `to` in workspace text, as a
|
|
926
|
-
// whole path: `04-projects/ocean` never touches `04-projects/ocean-ielts` or `ocean.md`, but
|
|
927
|
-
// does match inside an absolute path and before a full stop. Dot folders are skipped. Returns
|
|
928
|
-
// the files that change, relative to the Ocean root; writes them only when `write`.
|
|
929
|
-
export async function rewriteProjectReferences(from, to, write) {
|
|
930
|
-
const escaped = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
931
|
-
const pattern = new RegExp(`(?<![A-Za-z0-9_.-])${escaped}(?![A-Za-z0-9_-]|\\.[A-Za-z0-9])`, "g");
|
|
932
|
-
const changed = [];
|
|
933
|
-
const visit = async (dir) => {
|
|
934
|
-
let entries;
|
|
935
|
-
try {
|
|
936
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
937
|
-
}
|
|
938
|
-
catch {
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
for (const entry of entries) {
|
|
942
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
943
|
-
continue;
|
|
944
|
-
const file = path.join(dir, entry.name);
|
|
945
|
-
if (entry.isDirectory())
|
|
946
|
-
await visit(file);
|
|
947
|
-
else if (entry.isFile() &&
|
|
948
|
-
REFERENCE_FILE.test(entry.name) &&
|
|
949
|
-
statSync(file).size <= REFERENCE_MAX_BYTES) {
|
|
950
|
-
const text = await readFile(file, "utf8");
|
|
951
|
-
const next = text.replace(pattern, to);
|
|
952
|
-
if (next === text)
|
|
953
|
-
continue;
|
|
954
|
-
changed.push(path.relative(oceanRoot(), file).split(path.sep).join("/"));
|
|
955
|
-
if (write)
|
|
956
|
-
await atomicWrite(file, next);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
for (const root of new Set([...BRAIN_RECORD_DIRS, PROJECTS_DIR, CHARTER_DIR]))
|
|
961
|
-
await visit(oceanPath(root));
|
|
962
|
-
return changed.sort();
|
|
963
|
-
}
|
|
964
|
-
// A project with no code yet, e.g. one grown from a note: a manifest with no paths, filed in its
|
|
965
|
-
// category folder with the usual tasks/, memory/ and docs/. `bind` adds its first path later.
|
|
966
|
-
// An id already registered is returned as it is, never overwritten.
|
|
967
|
-
export async function createProject(id, category, name = id) {
|
|
968
|
-
if (!isValidProjectId(id))
|
|
969
|
-
throw new Error(`Invalid project id '${id}': use lowercase letters, digits, dot, underscore or hyphen`);
|
|
970
|
-
if (!isProjectCategory(category))
|
|
971
|
-
throw new Error(`Unknown category '${category}': use ${PROJECT_CATEGORIES.join(", ")}`);
|
|
972
|
-
const created = await withProjectsLock(async () => {
|
|
973
|
-
const manifests = await listProjectManifests();
|
|
974
|
-
if (manifests.some((manifest) => manifest.id === id))
|
|
975
|
-
return false;
|
|
976
|
-
if (existsSync(oceanPath(projectDir(id))))
|
|
977
|
-
throw new ProjectFolderTaken(`${projectDir(id)} already exists; bind it explicitly`);
|
|
978
|
-
const manifest = await newManifest(id, {
|
|
979
|
-
name,
|
|
980
|
-
paths: [],
|
|
981
|
-
created: new Date().toISOString(),
|
|
982
|
-
autoRegistered: false,
|
|
983
|
-
}, manifests);
|
|
984
|
-
// The folder first, so projectDir resolves to the category folder the manifest goes into.
|
|
985
|
-
await mkdir(oceanPath(PROJECTS_DIR, category, id), { recursive: true });
|
|
986
|
-
await writeManifest(manifest);
|
|
987
|
-
await saveProjectBindings(cacheBindings(manifests.concat(manifest), await listLegacyBindings()));
|
|
988
|
-
return true;
|
|
989
|
-
});
|
|
990
|
-
if (created)
|
|
991
|
-
await ensureProjectLayout(id);
|
|
992
|
-
return { id, dir: projectDir(id), created };
|
|
993
|
-
}
|
|
994
|
-
// Files a project under a category folder (T-311) and rewrites the workspace paths that name
|
|
995
|
-
// its old folder. A dry run unless `write`: it reports the move and the files that would change.
|
|
996
|
-
export async function moveProject(id, category, write = false) {
|
|
997
|
-
if (!isValidProjectId(id))
|
|
998
|
-
throw new Error("Project ids must be lowercase letters, digits, . _ or -");
|
|
999
|
-
if (!isProjectCategory(category))
|
|
1000
|
-
throw new Error(`category must be one of ${PROJECT_CATEGORIES.join(", ")}`);
|
|
1001
|
-
return withProjectsLock(async () => {
|
|
1002
|
-
const manifest = (await listProjectManifests()).find((candidate) => candidate.id === projectFolder(id));
|
|
1003
|
-
if (!manifest)
|
|
1004
|
-
throw new Error(`No project.json for '${id}'`);
|
|
1005
|
-
const from = projectDir(manifest.id);
|
|
1006
|
-
const to = path.posix.join(PROJECTS_DIR, category, manifest.id);
|
|
1007
|
-
if (from === to)
|
|
1008
|
-
return { id: manifest.id, from, to, moved: false, references: [] };
|
|
1009
|
-
if (existsSync(oceanPath(to)))
|
|
1010
|
-
throw new Error(`${to} already exists`);
|
|
1011
|
-
if (!write)
|
|
1012
|
-
return {
|
|
1013
|
-
id: manifest.id,
|
|
1014
|
-
from,
|
|
1015
|
-
to,
|
|
1016
|
-
moved: false,
|
|
1017
|
-
references: await rewriteProjectReferences(from, to, false),
|
|
1018
|
-
};
|
|
1019
|
-
await mkdir(path.dirname(oceanPath(to)), { recursive: true });
|
|
1020
|
-
await rename(oceanPath(from), oceanPath(to));
|
|
1021
|
-
// A category folder left empty goes; a flat project's written category is dropped.
|
|
1022
|
-
if (folderCategory(from))
|
|
1023
|
-
await rmdir(path.dirname(oceanPath(from))).catch(() => { });
|
|
1024
|
-
await writeManifest(manifest);
|
|
1025
|
-
const references = await rewriteProjectReferences(from, to, true);
|
|
1026
|
-
if ((await readFile(path.join(projectsRoot(), "registry.md"), "utf8").catch(() => "")).includes(INDEX_BEGIN))
|
|
1027
|
-
await writeProjectIndexLocked();
|
|
1028
|
-
return { id: manifest.id, from, to, moved: true, references };
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
// Renames a project folder (fixes a wrong auto-registered id). Refused while the project has
|
|
1032
|
-
// tasks: their records carry the project id, and rewriting them belongs to phase 3.
|
|
1033
|
-
export async function renameProject(from, to) {
|
|
1034
|
-
if (!isValidProjectId(from) || !isValidProjectId(to))
|
|
1035
|
-
throw new Error("Project ids must be lowercase letters, digits, . _ or -");
|
|
1036
|
-
return withProjectsLock(async () => {
|
|
1037
|
-
// The project keeps its category folder.
|
|
1038
|
-
const source = oceanPath(projectDir(from));
|
|
1039
|
-
const target = path.join(path.dirname(source), to);
|
|
1040
|
-
const manifest = (await listProjectManifests()).find((candidate) => candidate.id === from);
|
|
1041
|
-
if (!manifest)
|
|
1042
|
-
throw new Error(`No project.json for '${from}'`);
|
|
1043
|
-
if (existsSync(target) || listProjectDirs().some(({ id }) => id === to))
|
|
1044
|
-
throw new Error(`project '${to}' already exists`);
|
|
1045
|
-
const tasks = await readdir(path.join(source, "tasks")).catch(() => []);
|
|
1046
|
-
if (tasks.some((entry) => !entry.startsWith(".")))
|
|
1047
|
-
throw new Error(`'${from}' has tasks; renaming a project with tasks is not supported yet`);
|
|
1048
|
-
await rename(source, target);
|
|
1049
|
-
await writeManifest({
|
|
1050
|
-
...manifest,
|
|
1051
|
-
id: to,
|
|
1052
|
-
name: manifest.name === from ? to : manifest.name,
|
|
1053
|
-
});
|
|
1054
|
-
for (const [file, heading] of [
|
|
1055
|
-
["MEMORY.md", memoryHeading],
|
|
1056
|
-
[path.join("docs", "README.md"), docsHeading],
|
|
1057
|
-
]) {
|
|
1058
|
-
const index = path.join(target, file);
|
|
1059
|
-
try {
|
|
1060
|
-
const text = await readFile(index, "utf8");
|
|
1061
|
-
if (text.startsWith(heading(from)))
|
|
1062
|
-
await atomicWrite(index, `${heading(to)}${text.slice(heading(from).length)}`);
|
|
1063
|
-
}
|
|
1064
|
-
catch (error) {
|
|
1065
|
-
if (error.code !== "ENOENT")
|
|
1066
|
-
throw error;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
if ((await readFile(path.join(projectsRoot(), "registry.md"), "utf8").catch(() => "")).includes(INDEX_BEGIN))
|
|
1070
|
-
await writeProjectIndexLocked();
|
|
1071
|
-
await saveProjectBindings(cacheBindings(await listProjectManifests(), await listLegacyBindings()));
|
|
1072
|
-
return { from, to };
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
1075
286
|
// Project folders under 04-projects that hold a tasks/ directory, sorted.
|
|
1076
287
|
export async function projectsWithTasks() {
|
|
1077
288
|
const projects = [];
|
|
@@ -1086,6 +297,17 @@ export async function projectsWithTasks() {
|
|
|
1086
297
|
}
|
|
1087
298
|
return [...new Set(projects)].sort();
|
|
1088
299
|
}
|
|
300
|
+
// How a resolution decided the project, for the session's identity (T-331). An unbound or
|
|
301
|
+
// ambiguous folder decides nothing.
|
|
302
|
+
export function projectDecision(resolution) {
|
|
303
|
+
if (resolution.status !== "bound")
|
|
304
|
+
return NO_PROJECT;
|
|
305
|
+
const how = resolution.matchedOn === "project-folder" ||
|
|
306
|
+
resolution.matchedOn === "git-root"
|
|
307
|
+
? resolution.matchedOn
|
|
308
|
+
: "path";
|
|
309
|
+
return { projectId: resolution.projectId, how, confidence: "high" };
|
|
310
|
+
}
|
|
1089
311
|
// The project a folder belongs to, or null when it belongs to none. A registry that cannot be
|
|
1090
312
|
// read throws: no guessing which project a folder is.
|
|
1091
313
|
export async function folderProject(cwd) {
|