@amoree-code/ocean 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +284 -2
- package/dist/application/auth/auth-orchestrator.js +77 -0
- package/dist/application/clients/clients.js +646 -0
- package/dist/application/clients/editors.js +398 -0
- package/dist/application/clients/hooks.js +335 -0
- package/dist/application/clients/native.js +410 -0
- package/dist/application/clients/opencode-plugin.js +158 -0
- package/dist/application/clients/registry.js +188 -0
- package/dist/application/gateway/webhook-gateway.js +137 -0
- package/dist/application/install/provider-installer.js +184 -0
- package/dist/application/integrations/charter-copies.js +76 -0
- package/dist/application/integrations/claude-vscode.js +106 -0
- package/dist/application/integrations/engine-entry-repair.js +105 -0
- package/dist/application/integrations/skill-filter.js +254 -0
- package/dist/application/layout/layout-apply.js +443 -0
- package/dist/application/layout/layout-plan.js +236 -0
- package/dist/application/layout/workspace-template.js +34 -0
- package/dist/application/onboarding/state.js +23 -0
- package/dist/application/onboarding/steps.js +249 -0
- package/dist/application/profiles/profile-distribution.js +53 -0
- package/dist/application/profiles/profile-suggestion.js +39 -0
- package/dist/application/profiles/profile-upgrade-service.js +208 -0
- package/dist/application/pull/history-index.js +476 -0
- package/dist/application/pull/project-match.js +132 -0
- package/dist/application/pull/pull.js +202 -0
- package/dist/application/pull/server-capture.js +307 -0
- package/dist/application/scheduler/local-scheduler.js +210 -0
- package/dist/composition/runtime.js +64 -0
- package/dist/engine-root.js +9 -0
- package/dist/infrastructure/filesystem/profile-loader.js +46 -0
- package/dist/infrastructure/filesystem/runtime-config-loader.js +29 -0
- package/dist/infrastructure/filesystem/skill-loader.js +84 -0
- package/dist/infrastructure/filesystem/workspace-capability.js +37 -0
- package/dist/infrastructure/observability/runtime-logger.js +16 -0
- package/dist/infrastructure/process/agent-tool-executor.js +99 -0
- package/dist/infrastructure/process/cli-process.js +49 -0
- package/dist/infrastructure/process/interactive-process.js +145 -0
- package/dist/infrastructure/process/process-supervisor.js +194 -0
- package/dist/infrastructure/process/service.js +252 -0
- package/dist/infrastructure/providers/browser-provider.js +2 -0
- package/dist/infrastructure/providers/claude-sdk.js +137 -0
- package/dist/infrastructure/providers/client-home.js +14 -0
- package/dist/infrastructure/providers/fake-browser-provider.js +146 -0
- package/dist/infrastructure/providers/ollama-embedder.js +74 -0
- package/dist/infrastructure/providers/openai-compatible.js +268 -0
- package/dist/infrastructure/providers/playwright-browser-provider.js +380 -0
- package/dist/infrastructure/providers/provider-capabilities.js +50 -0
- package/dist/infrastructure/providers/provider-invocation.js +184 -0
- package/dist/infrastructure/providers/provider-registry.js +77 -0
- package/dist/infrastructure/providers/providers.js +134 -0
- package/dist/infrastructure/wrappers/wrapper-manager.js +374 -0
- package/dist/interfaces/cli/auth-command.js +54 -0
- package/dist/interfaces/cli/browser-bridge-command.js +93 -0
- package/dist/interfaces/cli/browser-command.js +119 -0
- package/dist/interfaces/cli/capture-command.js +125 -0
- package/dist/interfaces/cli/client-test-command.js +133 -0
- package/dist/interfaces/cli/clients-command.js +129 -0
- package/dist/interfaces/cli/command-registry.js +1211 -0
- package/dist/interfaces/cli/context-command.js +172 -0
- package/dist/interfaces/cli/daily-command.js +131 -0
- package/dist/interfaces/cli/governance-command.js +55 -0
- package/dist/interfaces/cli/handoff-command.js +35 -0
- package/dist/interfaces/cli/help-command.js +207 -0
- package/dist/interfaces/cli/idea-command.js +47 -0
- package/dist/interfaces/cli/intercept-command.js +317 -0
- package/dist/interfaces/cli/layout-command.js +27 -0
- package/dist/interfaces/cli/market-command.js +52 -0
- package/dist/interfaces/cli/mcp-gateway-command.js +30 -0
- package/dist/interfaces/cli/memory-command.js +317 -0
- package/dist/interfaces/cli/migrate-command.js +26 -0
- package/dist/interfaces/cli/observe-command.js +78 -0
- package/dist/interfaces/cli/onboard-command.js +123 -0
- package/dist/interfaces/cli/operate-command.js +59 -0
- package/dist/interfaces/cli/profiles-command.js +70 -0
- package/dist/interfaces/cli/pull-command.js +54 -0
- package/dist/interfaces/cli/setup-command.js +143 -0
- package/dist/interfaces/cli/tasks-command.js +249 -0
- package/dist/main.js +49 -0
- package/dist/node-warnings.js +17 -0
- package/dist/version.js +8 -0
- package/market/mcp/chrome-devtools/ocean.capability.json +28 -0
- package/market/mcp/gateway/ocean.capability.json +21 -0
- package/market/mcp/obsidian/ocean.capability.json +21 -0
- package/market/mcp/ocean/ocean.capability.json +21 -0
- package/market/mcp/playwright/ocean.capability.json +23 -0
- package/node_modules/@ocean/brain/dist/brain/brain-eval.js +29 -0
- package/node_modules/@ocean/brain/dist/brain/brain-markdown.js +226 -0
- package/node_modules/@ocean/brain/dist/brain/brain-reindex.js +247 -0
- package/node_modules/@ocean/brain/dist/brain/brain-service.js +320 -0
- package/node_modules/@ocean/brain/dist/capture/inbox-sync.js +22 -0
- package/node_modules/@ocean/brain/dist/evidence/verification-report.js +13 -0
- package/node_modules/@ocean/brain/dist/infrastructure/brain/brain-index.js +285 -0
- package/node_modules/@ocean/brain/dist/memory/brain-dump.js +145 -0
- package/node_modules/@ocean/brain/dist/memory/daily-narrative.js +142 -0
- package/node_modules/@ocean/brain/dist/memory/index-sync.js +124 -0
- package/node_modules/@ocean/brain/dist/memory/lesson-activation.js +93 -0
- package/node_modules/@ocean/brain/dist/memory/lesson-learning.js +188 -0
- package/node_modules/@ocean/brain/dist/memory/lessons.js +321 -0
- package/node_modules/@ocean/brain/dist/memory/memory-audit.js +100 -0
- package/node_modules/@ocean/brain/dist/memory/memory-digest.js +49 -0
- package/node_modules/@ocean/brain/dist/memory/memory-harvest.js +345 -0
- package/node_modules/@ocean/brain/dist/memory/memory-paths.js +174 -0
- package/node_modules/@ocean/brain/dist/memory/memory-review.js +278 -0
- package/node_modules/@ocean/brain/dist/memory/memory-trash.js +152 -0
- package/node_modules/@ocean/brain/dist/memory/memory-write.js +216 -0
- package/node_modules/@ocean/brain/dist/memory/model-narrative.js +129 -0
- package/node_modules/@ocean/brain/dist/memory/profile-facts.js +103 -0
- package/node_modules/@ocean/brain/dist/memory/session-promotion.js +61 -0
- package/node_modules/@ocean/brain/dist/memory/session-summary.js +113 -0
- package/node_modules/@ocean/brain/dist/memory/signal-detection.js +66 -0
- package/node_modules/@ocean/brain/package.json +11 -0
- package/node_modules/@ocean/context/dist/context/context-compression.js +66 -0
- package/node_modules/@ocean/context/dist/context/context-cost.js +587 -0
- package/node_modules/@ocean/context/dist/context/context-ladder.js +363 -0
- package/node_modules/@ocean/context/dist/context/context-packet.js +213 -0
- package/node_modules/@ocean/context/dist/context/context-references.js +255 -0
- package/node_modules/@ocean/context/dist/context/intent-router.js +259 -0
- package/node_modules/@ocean/context/dist/context/resource-injection.js +36 -0
- package/node_modules/@ocean/context/package.json +11 -0
- package/node_modules/@ocean/core/dist/domain/brain/brain-record.js +22 -0
- package/node_modules/@ocean/core/dist/domain/brain/record-scope.js +22 -0
- package/node_modules/@ocean/core/dist/domain/capabilities/browser-contract.js +64 -0
- package/node_modules/@ocean/core/dist/domain/capabilities/capability-contract.js +16 -0
- package/node_modules/@ocean/core/dist/domain/capabilities/capability-manifest.js +72 -0
- package/node_modules/@ocean/core/dist/domain/context/context-validator.js +5 -0
- package/node_modules/@ocean/core/dist/domain/context/context.js +34 -0
- package/node_modules/@ocean/core/dist/domain/context/project-id.js +30 -0
- package/node_modules/@ocean/core/dist/domain/evidence/evidence.js +16 -0
- package/node_modules/@ocean/core/dist/domain/mcp/mcp-contract.js +36 -0
- package/node_modules/@ocean/core/dist/domain/mcp/memory-contract.js +41 -0
- package/node_modules/@ocean/core/dist/domain/ports/brain-index-port.js +7 -0
- package/node_modules/@ocean/core/dist/domain/ports/browser-port.js +8 -0
- package/node_modules/@ocean/core/dist/domain/ports/embedder-port.js +2 -0
- package/node_modules/@ocean/core/dist/domain/ports/platform-ports.js +2 -0
- package/node_modules/@ocean/core/dist/domain/ports/runtime-ports.js +2 -0
- package/node_modules/@ocean/core/dist/domain/ports/session-store-port.js +2 -0
- package/node_modules/@ocean/core/dist/domain/process/process-events.js +5 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-distribution.js +19 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-policy.js +34 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-selection.js +73 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-upgrade.js +123 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile-validator.js +5 -0
- package/node_modules/@ocean/core/dist/domain/profiles/profile.js +218 -0
- package/node_modules/@ocean/core/dist/domain/profiles/runtime-config.js +30 -0
- package/node_modules/@ocean/core/dist/domain/providers/provider-capability.js +28 -0
- package/node_modules/@ocean/core/dist/domain/providers/provider.js +2 -0
- package/node_modules/@ocean/core/dist/domain/redaction/redaction.js +86 -0
- package/node_modules/@ocean/core/dist/domain/runs/agent-tools.js +92 -0
- package/node_modules/@ocean/core/dist/domain/runs/execution-plan.js +71 -0
- package/node_modules/@ocean/core/dist/domain/runs/run-contract.js +38 -0
- package/node_modules/@ocean/core/dist/domain/sessions/entry-contract.js +31 -0
- package/node_modules/@ocean/core/dist/domain/sessions/handoff.js +78 -0
- package/node_modules/@ocean/core/dist/domain/sessions/session.js +58 -0
- package/node_modules/@ocean/core/dist/domain/skills/default-skills.js +29 -0
- package/node_modules/@ocean/core/dist/domain/skills/skill-validator.js +5 -0
- package/node_modules/@ocean/core/dist/domain/skills/skill.js +11 -0
- package/node_modules/@ocean/core/dist/domain/tasks/task-id.js +85 -0
- package/node_modules/@ocean/core/dist/shared/fs-utils.js +212 -0
- package/node_modules/@ocean/core/dist/shared/local-date.js +16 -0
- package/node_modules/@ocean/core/dist/shared/paths.js +324 -0
- package/node_modules/@ocean/core/dist/shared/project-resolution.js +1065 -0
- package/node_modules/@ocean/core/dist/shared/task-reference.js +133 -0
- package/node_modules/@ocean/core/package.json +14 -0
- package/node_modules/@ocean/loop/dist/handoff/handoff-service.js +133 -0
- package/node_modules/@ocean/loop/dist/hooks/lifecycle-hooks.js +15 -0
- package/node_modules/@ocean/loop/dist/hooks/session-end-hook.js +183 -0
- package/node_modules/@ocean/loop/dist/hooks/session-start-hook.js +237 -0
- package/node_modules/@ocean/loop/dist/infrastructure/persistence/session-store.js +690 -0
- package/node_modules/@ocean/loop/dist/infrastructure/persistence/session-validator.js +5 -0
- package/node_modules/@ocean/loop/dist/loops/iteration-graph.js +147 -0
- package/node_modules/@ocean/loop/dist/loops/task-loop-record.js +2 -0
- package/node_modules/@ocean/loop/dist/loops/task-loop.js +281 -0
- package/node_modules/@ocean/loop/dist/operations/memory-knowledge-operations.js +263 -0
- package/node_modules/@ocean/loop/dist/operations/operation-contract.js +227 -0
- package/node_modules/@ocean/loop/dist/operations/operation-scope.js +28 -0
- package/node_modules/@ocean/loop/dist/operations/project-operations.js +93 -0
- package/node_modules/@ocean/loop/dist/operations/record-io.js +65 -0
- package/node_modules/@ocean/loop/dist/operations/record-operations.js +45 -0
- package/node_modules/@ocean/loop/dist/operations/task-linker.js +40 -0
- package/node_modules/@ocean/loop/dist/operations/task-operations.js +279 -0
- package/node_modules/@ocean/loop/dist/operations/write-guard.js +157 -0
- package/node_modules/@ocean/loop/dist/runs/prompt-assembly.js +112 -0
- package/node_modules/@ocean/loop/dist/runs/run-agent.js +425 -0
- package/node_modules/@ocean/loop/dist/runs/run-authorization.js +24 -0
- package/node_modules/@ocean/loop/dist/runs/tool-loop.js +173 -0
- package/node_modules/@ocean/loop/dist/sessions/session-closeout.js +150 -0
- package/node_modules/@ocean/loop/dist/sessions/session-pointer.js +133 -0
- package/node_modules/@ocean/loop/dist/sessions/session-projects.js +26 -0
- package/node_modules/@ocean/loop/dist/sessions/session-retention.js +132 -0
- package/node_modules/@ocean/loop/dist/tasks/archive-tasks.js +210 -0
- package/node_modules/@ocean/loop/dist/tasks/checkpoint-task.js +31 -0
- package/node_modules/@ocean/loop/dist/tasks/claim-task.js +126 -0
- package/node_modules/@ocean/loop/dist/tasks/list-tasks.js +113 -0
- package/node_modules/@ocean/loop/dist/tasks/new-task.js +42 -0
- package/node_modules/@ocean/loop/dist/tasks/renumber-tasks.js +134 -0
- package/node_modules/@ocean/loop/dist/tasks/verification-readiness.js +78 -0
- package/node_modules/@ocean/loop/dist/tasks/verify-task.js +234 -0
- package/node_modules/@ocean/loop/package.json +11 -0
- package/node_modules/@ocean/market/dist/adapters/mcp-adapter.js +64 -0
- package/node_modules/@ocean/market/dist/adapters/owned-directory.js +89 -0
- package/node_modules/@ocean/market/dist/adapters/plugin-adapter.js +39 -0
- package/node_modules/@ocean/market/dist/adapters/skill-adapter.js +32 -0
- package/node_modules/@ocean/market/dist/capability/adapter.js +2 -0
- package/node_modules/@ocean/market/dist/capability/catalog.js +63 -0
- package/node_modules/@ocean/market/dist/capability/content-digest.js +40 -0
- package/node_modules/@ocean/market/dist/capability/registry.js +81 -0
- package/node_modules/@ocean/market/dist/install/default-marketplace.js +47 -0
- package/node_modules/@ocean/market/dist/install/lock.js +34 -0
- package/node_modules/@ocean/market/dist/install/marketplace-service.js +165 -0
- package/node_modules/@ocean/market/dist/mcp/browser-bridge.js +263 -0
- package/node_modules/@ocean/market/dist/mcp/mcp-connection.js +67 -0
- package/node_modules/@ocean/market/dist/mcp/mcp-gateway.js +317 -0
- package/node_modules/@ocean/market/dist/mcp/mcp-launch.js +102 -0
- package/node_modules/@ocean/market/dist/mcp/mcp-runner.js +32 -0
- package/node_modules/@ocean/market/dist/security/description-scan.js +45 -0
- package/node_modules/@ocean/market/dist/security/permissions.js +57 -0
- package/node_modules/@ocean/market/dist/security/sandbox.js +74 -0
- package/node_modules/@ocean/market/dist/skills/core-skill-sync.js +113 -0
- package/node_modules/@ocean/market/dist/skills/signal-detection.js +84 -0
- package/node_modules/@ocean/market/dist/skills/skill-curation.js +123 -0
- package/node_modules/@ocean/market/dist/skills/skill-hub.js +220 -0
- package/node_modules/@ocean/market/dist/skills/task-observer.js +165 -0
- package/node_modules/@ocean/market/package.json +11 -0
- package/node_modules/@ocean/services/dist/browser/browser-service.js +124 -0
- package/node_modules/@ocean/services/dist/browser/browser-session.js +287 -0
- package/node_modules/@ocean/services/dist/browser/browser-task-runner.js +70 -0
- package/node_modules/@ocean/services/dist/doctor/workspace-doctor.js +547 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/call-ledger.js +114 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/mcp-client.js +162 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/obsidian-server.js +251 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/ocean-server.js +880 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/server-version.js +20 -0
- package/node_modules/@ocean/services/dist/infrastructure/mcp/tool-registry.js +29 -0
- package/node_modules/@ocean/services/dist/obsidian/conflict-log.js +68 -0
- package/node_modules/@ocean/services/dist/obsidian/inbox-promotion.js +80 -0
- package/node_modules/@ocean/services/dist/obsidian/vault-discovery.js +113 -0
- package/node_modules/@ocean/services/dist/obsidian/vault-ingestion.js +77 -0
- package/node_modules/@ocean/services/dist/obsidian/vault-sync.js +73 -0
- package/node_modules/@ocean/services/dist/obsidian/vault-writer.js +75 -0
- package/node_modules/@ocean/services/package.json +11 -0
- package/ocean-marketplace.json +415 -0
- package/package.json +67 -4
- package/skills/core/business-logic/SKILL.md +22 -0
- package/skills/core/catch-up/SKILL.md +17 -0
- package/skills/core/core-thinking/SKILL.md +11 -0
- package/skills/core/design-thinking/SKILL.md +19 -0
- package/skills/core/graft/SKILL.md +156 -0
- package/skills/core/loop/SKILL.md +20 -0
- package/skills/core/session-handoff/SKILL.md +15 -0
- package/skills/core/use-browser/SKILL.md +69 -0
- package/skills/core/verification/SKILL.md +11 -0
- package/skills/index.json +56 -0
- package/templates/README.md +4 -0
- package/templates/profiles/default.json +51 -0
- package/templates/profiles/developer.json +51 -0
- package/templates/profiles/reviewer.json +51 -0
- package/templates/profiles/strategist.json +51 -0
- package/templates/workspace/00-inbox/INBOX.md +7 -0
- package/templates/workspace/00-inbox/candidates/.gitkeep +0 -0
- package/templates/workspace/00-inbox/native/.gitkeep +0 -0
- package/templates/workspace/01-daily/.gitkeep +0 -0
- package/templates/workspace/02-personal/CONFLICTS.md +7 -0
- package/templates/workspace/02-personal/MEMORY.md +15 -0
- package/templates/workspace/02-personal/goals/.gitkeep +0 -0
- package/templates/workspace/02-personal/identity/.gitkeep +0 -0
- package/templates/workspace/02-personal/preferences/.gitkeep +0 -0
- package/templates/workspace/03-professional/.gitkeep +0 -0
- package/templates/workspace/04-projects/PROJECTS.md +5 -0
- package/templates/workspace/04-projects/_template/docs/.gitkeep +0 -0
- package/templates/workspace/04-projects/_template/memory/.gitkeep +0 -0
- package/templates/workspace/04-projects/_template/tasks/.gitkeep +0 -0
- package/templates/workspace/05-knowledge/KNOWLEDGE.md +8 -0
- package/templates/workspace/05-knowledge/decisions/.gitkeep +0 -0
- package/templates/workspace/05-knowledge/lessons/.gitkeep +0 -0
- package/templates/workspace/06-templates/TEMPLATES.md +25 -0
- package/templates/workspace/06-templates/decision.md +8 -0
- package/templates/workspace/06-templates/intelligence.md +32 -0
- package/templates/workspace/06-templates/project-claude.md +48 -0
- package/templates/workspace/06-templates/session.md +38 -0
- package/templates/workspace/06-templates/task.md +42 -0
- package/templates/workspace/MANIFEST.json +51 -0
- package/templates/workspace/bridge/config/CONFIG.md +21 -0
- package/templates/workspace/bridge/config/runtime.json +4 -0
- package/templates/workspace/charter/core.md +104 -0
- package/templates/workspace/charter/policies/README.md +31 -0
- package/templates/workspace/charter/policies/claude-code-context.md +90 -0
- package/templates/workspace/charter/policies/concise-output.md +29 -0
- package/templates/workspace/charter/policies/context.md +91 -0
- package/templates/workspace/charter/policies/contracts/task.md +189 -0
- package/templates/workspace/charter/policies/git.md +60 -0
- package/templates/workspace/charter/policies/graph.md +47 -0
- package/templates/workspace/charter/policies/knowledge.md +33 -0
- package/templates/workspace/charter/policies/lifecycle.md +119 -0
- package/templates/workspace/charter/policies/memory.md +67 -0
- package/templates/workspace/charter/policies/minimal-change.md +43 -0
- package/templates/workspace/charter/policies/models.md +57 -0
- package/templates/workspace/charter/policies/privacy-terms.txt +3 -0
- package/templates/workspace/charter/policies/response.md +39 -0
- package/templates/workspace/charter/policies/skill-observer.md +44 -0
- package/templates/workspace/charter/policies/stack.md +23 -0
- package/templates/workspace/charter/policies/task.md +139 -0
- package/templates/workspace/charter/policies/verification.md +29 -0
- package/templates/workspace/sessions/.gitkeep +0 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { defaultClientEnv, edit, newBatch, planClients, readJournal, temporaryEntryProblem, } from "./clients.js";
|
|
5
|
+
import { canonicalJson, ManualEdit } from "./editors.js";
|
|
6
|
+
// The `ocean hook` action each event runs, and what an Ocean hook for it already looks like.
|
|
7
|
+
const EVENTS = {
|
|
8
|
+
SessionStart: {
|
|
9
|
+
action: "session-start",
|
|
10
|
+
flags: " --repair",
|
|
11
|
+
pattern: /ocean-session-bootstrap|\bhook session-start\b/,
|
|
12
|
+
},
|
|
13
|
+
SessionEnd: {
|
|
14
|
+
action: "session-end",
|
|
15
|
+
flags: "",
|
|
16
|
+
pattern: /ocean-session-close|\bhook session-end\b/,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export const HOOK_ADAPTERS = [
|
|
20
|
+
{
|
|
21
|
+
client: "claude-code",
|
|
22
|
+
hookClient: "claude",
|
|
23
|
+
file: ".claude/settings.json",
|
|
24
|
+
windowsShell: "powershell",
|
|
25
|
+
events: ["SessionStart", "SessionEnd"],
|
|
26
|
+
group: (command, windows) => ({
|
|
27
|
+
hooks: [
|
|
28
|
+
{
|
|
29
|
+
type: "command",
|
|
30
|
+
command,
|
|
31
|
+
...(windows ? { shell: "powershell" } : {}),
|
|
32
|
+
timeout: 10,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
client: "codex",
|
|
39
|
+
hookClient: "codex",
|
|
40
|
+
file: ".codex/hooks.json",
|
|
41
|
+
windowsShell: "cmd",
|
|
42
|
+
events: ["SessionStart", "SessionEnd"],
|
|
43
|
+
group: (command, _windows, event) => event === "SessionEnd"
|
|
44
|
+
? { hooks: [{ type: "command", command, timeout: 10 }] }
|
|
45
|
+
: {
|
|
46
|
+
matcher: "startup|resume",
|
|
47
|
+
hooks: [
|
|
48
|
+
{
|
|
49
|
+
type: "command",
|
|
50
|
+
command,
|
|
51
|
+
timeout: 10,
|
|
52
|
+
statusMessage: "Loading Ocean context",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
client: "gemini",
|
|
59
|
+
hookClient: "gemini",
|
|
60
|
+
file: ".gemini/settings.json",
|
|
61
|
+
windowsShell: "powershell",
|
|
62
|
+
// Gemini CLI 0.58 also fires SessionEnd (fireSessionEndEvent), T-307.
|
|
63
|
+
events: ["SessionStart", "SessionEnd"],
|
|
64
|
+
// Gemini's hook timeout is in milliseconds.
|
|
65
|
+
group: (command) => ({
|
|
66
|
+
matcher: "*",
|
|
67
|
+
hooks: [{ name: "ocean", type: "command", command, timeout: 10_000 }],
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
// Qwen Code 0.23: Claude's hook shape, `hookSpecificOutput.additionalContext` on
|
|
72
|
+
// SessionStart, timeouts in milliseconds (its bundled docs/features/hooks.md), T-307.
|
|
73
|
+
client: "qwen",
|
|
74
|
+
hookClient: "qwen",
|
|
75
|
+
file: ".qwen/settings.json",
|
|
76
|
+
windowsShell: "powershell",
|
|
77
|
+
events: ["SessionStart", "SessionEnd"],
|
|
78
|
+
group: (command, windows, event) => ({
|
|
79
|
+
...(event === "SessionStart" ? { matcher: "startup|resume" } : {}),
|
|
80
|
+
hooks: [
|
|
81
|
+
{
|
|
82
|
+
type: "command",
|
|
83
|
+
name: "ocean",
|
|
84
|
+
command,
|
|
85
|
+
...(windows ? { shell: "powershell" } : {}),
|
|
86
|
+
timeout: 10_000,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
// Cursor agent (hooks.json version 1): flat `{command}` entries under `sessionStart` /
|
|
93
|
+
// `sessionEnd`; sessionStart reads `additional_context` from the hook's output, T-307.
|
|
94
|
+
client: "cursor",
|
|
95
|
+
hookClient: "cursor",
|
|
96
|
+
file: ".cursor/hooks.json",
|
|
97
|
+
windowsShell: "powershell",
|
|
98
|
+
events: ["SessionStart", "SessionEnd"],
|
|
99
|
+
key: (event) => (event === "SessionStart" ? "sessionStart" : "sessionEnd"),
|
|
100
|
+
seed: { version: 1 },
|
|
101
|
+
group: (command) => ({ command }),
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
const shellWord = (word) => /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
105
|
+
// A Windows path cannot hold `"`. PowerShell also closes a string on the typographic quotes.
|
|
106
|
+
const cmdWord = (word) => `"${word}"`;
|
|
107
|
+
const powershellWord = (word) => `'${word.replace(/['\u2018\u2019\u201a\u201b]/g, "$&$&")}'`;
|
|
108
|
+
const isWindows = (env) => (env.platform ?? process.platform) === "win32";
|
|
109
|
+
// `--repair` also starts `client sync` in the background, which re-applies approved clients.
|
|
110
|
+
export function hookCommand(env, hookClient, event = "SessionStart") {
|
|
111
|
+
const program = Array.isArray(env.entry.args)
|
|
112
|
+
? String(env.entry.args[0])
|
|
113
|
+
: "";
|
|
114
|
+
// A shim entry (`ocean mcp serve`) names no engine file; the shim is the whole program.
|
|
115
|
+
const words = program === "mcp"
|
|
116
|
+
? [String(env.entry.command)]
|
|
117
|
+
: [String(env.entry.command), program];
|
|
118
|
+
const shell = isWindows(env)
|
|
119
|
+
? HOOK_ADAPTERS.find((item) => item.hookClient === hookClient)?.windowsShell
|
|
120
|
+
: undefined;
|
|
121
|
+
const invocation = shell === "cmd"
|
|
122
|
+
? words.map(cmdWord).join(" ")
|
|
123
|
+
: shell === "powershell"
|
|
124
|
+
? `& ${words.map(powershellWord).join(" ")}`
|
|
125
|
+
: words.map(shellWord).join(" ");
|
|
126
|
+
const { action, flags } = EVENTS[event];
|
|
127
|
+
return `${invocation} hook ${action} --client ${hookClient}${flags}`;
|
|
128
|
+
}
|
|
129
|
+
const hookGroup = (adapter, env, event) => adapter.group(hookCommand(env, adapter.hookClient, event), isWindows(env), event);
|
|
130
|
+
// The event's group list, `[]` when absent; null when the file holds another shape there.
|
|
131
|
+
function sessionGroups(root, event) {
|
|
132
|
+
const hooks = root.hooks;
|
|
133
|
+
if (hooks === undefined)
|
|
134
|
+
return [];
|
|
135
|
+
if (!hooks || typeof hooks !== "object" || Array.isArray(hooks))
|
|
136
|
+
return null;
|
|
137
|
+
const groups = hooks[event];
|
|
138
|
+
if (groups === undefined)
|
|
139
|
+
return [];
|
|
140
|
+
return Array.isArray(groups) ? groups : null;
|
|
141
|
+
}
|
|
142
|
+
const isOceanCommand = (hook, event) => {
|
|
143
|
+
const command = hook?.command;
|
|
144
|
+
return typeof command === "string" && EVENTS[event].pattern.test(command);
|
|
145
|
+
};
|
|
146
|
+
// A group of hooks (`{hooks: [...]}`), or one flat entry (Cursor's `{command}`).
|
|
147
|
+
const hasOceanHook = (groups, event) => groups.some((group) => {
|
|
148
|
+
const hooks = group?.hooks;
|
|
149
|
+
return Array.isArray(hooks)
|
|
150
|
+
? hooks.some((hook) => isOceanCommand(hook, event))
|
|
151
|
+
: isOceanCommand(group, event);
|
|
152
|
+
});
|
|
153
|
+
const eventKey = (adapter, event) => adapter.key?.(event) ?? event;
|
|
154
|
+
async function readText(file) {
|
|
155
|
+
try {
|
|
156
|
+
return await readFile(file, "utf8");
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error.code === "ENOENT")
|
|
160
|
+
return "";
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function planOne(text, adapter, env, event) {
|
|
165
|
+
const plan = {
|
|
166
|
+
client: adapter.client,
|
|
167
|
+
event,
|
|
168
|
+
file: `~/${adapter.file}`,
|
|
169
|
+
status: "change",
|
|
170
|
+
};
|
|
171
|
+
let root;
|
|
172
|
+
try {
|
|
173
|
+
root = JSON.parse(text.trim() ? text : "{}");
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return { ...plan, status: "manual", reason: "the file is not valid JSON" };
|
|
177
|
+
}
|
|
178
|
+
const key = eventKey(adapter, event);
|
|
179
|
+
const groups = sessionGroups(root, key);
|
|
180
|
+
if (!groups)
|
|
181
|
+
return {
|
|
182
|
+
...plan,
|
|
183
|
+
status: "manual",
|
|
184
|
+
reason: `hooks.${key} is not a list`,
|
|
185
|
+
};
|
|
186
|
+
if (hasOceanHook(groups, event))
|
|
187
|
+
return { ...plan, status: "current" };
|
|
188
|
+
const group = hookGroup(adapter, env, event);
|
|
189
|
+
try {
|
|
190
|
+
canonicalJson(text);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (!(error instanceof ManualEdit))
|
|
194
|
+
throw error;
|
|
195
|
+
return {
|
|
196
|
+
...plan,
|
|
197
|
+
status: "manual",
|
|
198
|
+
reason: error.message,
|
|
199
|
+
snippet: `hooks.${key} += ${JSON.stringify(group)}`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return plan;
|
|
203
|
+
}
|
|
204
|
+
export async function planHooks(env = defaultClientEnv()) {
|
|
205
|
+
const installed = new Set((await planClients(env))
|
|
206
|
+
.filter((plan) => plan.installed)
|
|
207
|
+
.map((plan) => plan.client));
|
|
208
|
+
const plans = [];
|
|
209
|
+
for (const adapter of HOOK_ADAPTERS) {
|
|
210
|
+
if (!installed.has(adapter.client))
|
|
211
|
+
continue;
|
|
212
|
+
const text = await readText(path.join(env.home, adapter.file));
|
|
213
|
+
for (const event of adapter.events)
|
|
214
|
+
plans.push(planOne(text, adapter, env, event));
|
|
215
|
+
}
|
|
216
|
+
return plans;
|
|
217
|
+
}
|
|
218
|
+
// Appends the Ocean group where it is missing; journaled under `batch` so `ocean clients
|
|
219
|
+
// restore` undoes it together with the MCP entries of the same apply.
|
|
220
|
+
export async function applyHooks(options = {}) {
|
|
221
|
+
const env = options.env ?? defaultClientEnv();
|
|
222
|
+
if (options.durable ?? !options.env) {
|
|
223
|
+
const problem = temporaryEntryProblem(env.entry);
|
|
224
|
+
if (problem)
|
|
225
|
+
throw new Error(`Refusing to add session hooks: ${problem}`);
|
|
226
|
+
}
|
|
227
|
+
const batch = options.batch ?? newBatch();
|
|
228
|
+
const results = [];
|
|
229
|
+
for (const plan of await planHooks(env)) {
|
|
230
|
+
if (options.clients && !options.clients.includes(plan.client))
|
|
231
|
+
continue;
|
|
232
|
+
if (plan.status !== "change")
|
|
233
|
+
continue;
|
|
234
|
+
const adapter = HOOK_ADAPTERS.find((item) => item.client === plan.client);
|
|
235
|
+
if (!adapter)
|
|
236
|
+
continue;
|
|
237
|
+
const result = await edit(path.join(env.home, adapter.file), (text) => {
|
|
238
|
+
const { event } = plan;
|
|
239
|
+
if (planOne(text, adapter, env, event).status !== "change")
|
|
240
|
+
return null;
|
|
241
|
+
const { parsed, render } = canonicalJson(text);
|
|
242
|
+
const created = [];
|
|
243
|
+
// A seeded top-level field is journaled as `root:<name>`, removed again with `hooks`.
|
|
244
|
+
for (const [field, value] of Object.entries(adapter.seed ?? {}))
|
|
245
|
+
if (parsed[field] === undefined) {
|
|
246
|
+
parsed[field] = value;
|
|
247
|
+
created.push(`root:${field}`);
|
|
248
|
+
}
|
|
249
|
+
if (parsed.hooks === undefined) {
|
|
250
|
+
parsed.hooks = {};
|
|
251
|
+
created.push("hooks");
|
|
252
|
+
}
|
|
253
|
+
const hooks = parsed.hooks;
|
|
254
|
+
const key = eventKey(adapter, event);
|
|
255
|
+
if (hooks[key] === undefined) {
|
|
256
|
+
hooks[key] = [];
|
|
257
|
+
created.push(key);
|
|
258
|
+
}
|
|
259
|
+
const group = hookGroup(adapter, env, event);
|
|
260
|
+
hooks[key].push(group);
|
|
261
|
+
return {
|
|
262
|
+
next: render(parsed),
|
|
263
|
+
entries: [
|
|
264
|
+
{
|
|
265
|
+
client: adapter.client,
|
|
266
|
+
file: adapter.file,
|
|
267
|
+
op: "hook-add",
|
|
268
|
+
key: event,
|
|
269
|
+
before: null,
|
|
270
|
+
after: group,
|
|
271
|
+
created,
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
}, batch);
|
|
276
|
+
results.push({ client: plan.client, event: plan.event, result });
|
|
277
|
+
}
|
|
278
|
+
return { batch, results };
|
|
279
|
+
}
|
|
280
|
+
// Removes the groups one apply batch added. A group the user changed or removed since is a
|
|
281
|
+
// conflict and left alone; keys the add created are removed again once empty.
|
|
282
|
+
export async function restoreHooks(options) {
|
|
283
|
+
const env = options.env ?? defaultClientEnv();
|
|
284
|
+
const entries = (await readJournal())
|
|
285
|
+
.filter((entry) => entry.batch === options.batch &&
|
|
286
|
+
entry.op === "hook-add" &&
|
|
287
|
+
!entry.restoreOf)
|
|
288
|
+
.reverse();
|
|
289
|
+
const restored = [];
|
|
290
|
+
const conflicts = [];
|
|
291
|
+
const undo = newBatch();
|
|
292
|
+
for (const entry of entries) {
|
|
293
|
+
const label = `${entry.client}:${entry.key === "SessionEnd" ? "end-hook" : "hook"}`;
|
|
294
|
+
// Set per attempt: edit() may run the change again when the file moved under it.
|
|
295
|
+
const outcome = { restored: false };
|
|
296
|
+
await edit(path.join(env.home, entry.file), (text) => {
|
|
297
|
+
outcome.restored = false;
|
|
298
|
+
let document;
|
|
299
|
+
try {
|
|
300
|
+
document = canonicalJson(text);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
const { parsed, render } = document;
|
|
306
|
+
// Batches journaled before SessionEnd existed carry SessionStart as their key.
|
|
307
|
+
const event = (entry.key ?? "SessionStart");
|
|
308
|
+
const adapter = HOOK_ADAPTERS.find((item) => item.client === entry.client);
|
|
309
|
+
const key = adapter ? eventKey(adapter, event) : event;
|
|
310
|
+
const groups = sessionGroups(parsed, key);
|
|
311
|
+
const index = groups?.findIndex((group) => isDeepStrictEqual(group, entry.after)) ??
|
|
312
|
+
-1;
|
|
313
|
+
if (!groups || index < 0)
|
|
314
|
+
return null;
|
|
315
|
+
groups.splice(index, 1);
|
|
316
|
+
const hooks = parsed.hooks;
|
|
317
|
+
if (entry.created?.includes(key) && groups.length === 0)
|
|
318
|
+
delete hooks[key];
|
|
319
|
+
if (entry.created?.includes("hooks") && !Object.keys(hooks).length) {
|
|
320
|
+
delete parsed.hooks;
|
|
321
|
+
for (const created of entry.created)
|
|
322
|
+
if (created.startsWith("root:"))
|
|
323
|
+
delete parsed[created.slice(5)];
|
|
324
|
+
}
|
|
325
|
+
outcome.restored = true;
|
|
326
|
+
return {
|
|
327
|
+
next: render(parsed),
|
|
328
|
+
entries: [{ ...entry, restoreOf: options.batch }],
|
|
329
|
+
};
|
|
330
|
+
}, undo);
|
|
331
|
+
(outcome.restored ? restored : conflicts).push(label);
|
|
332
|
+
}
|
|
333
|
+
return { restored, conflicts };
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=hooks.js.map
|