@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,162 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { actionFingerprint, mcpToolSchema, } from "@ocean/core/domain/mcp/mcp-contract.js";
|
|
3
|
+
export class McpClient {
|
|
4
|
+
options;
|
|
5
|
+
child = null;
|
|
6
|
+
nextId = 1;
|
|
7
|
+
pending = new Map();
|
|
8
|
+
buffer = "";
|
|
9
|
+
tools = new Map();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
async connect() {
|
|
14
|
+
this.child = spawn(this.options.command, this.options.args ?? [], {
|
|
15
|
+
cwd: this.options.cwd,
|
|
16
|
+
env: this.options.inheritEnv === false
|
|
17
|
+
? (this.options.env ?? {})
|
|
18
|
+
: { ...process.env, ...this.options.env },
|
|
19
|
+
stdio: "pipe",
|
|
20
|
+
});
|
|
21
|
+
// An unread stderr pipe fills up and stalls the server.
|
|
22
|
+
const label = this.options.stderrLabel;
|
|
23
|
+
if (label) {
|
|
24
|
+
let pending = "";
|
|
25
|
+
this.child.stderr.setEncoding("utf8");
|
|
26
|
+
this.child.stderr.on("data", (chunk) => {
|
|
27
|
+
const lines = (pending + chunk).split("\n");
|
|
28
|
+
pending = lines.pop() ?? "";
|
|
29
|
+
for (const line of lines)
|
|
30
|
+
process.stderr.write(`${label}: ${line}\n`);
|
|
31
|
+
});
|
|
32
|
+
this.child.stderr.on("end", () => {
|
|
33
|
+
if (pending)
|
|
34
|
+
process.stderr.write(`${label}: ${pending}\n`);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
this.child.stderr.resume();
|
|
39
|
+
this.child.stdout.setEncoding("utf8");
|
|
40
|
+
this.child.stdout.on("data", (chunk) => this.consume(chunk));
|
|
41
|
+
this.child.once("error", (error) => this.failPending(error));
|
|
42
|
+
this.child.once("close", () => this.failPending(new Error("MCP server stopped")));
|
|
43
|
+
await this.request("initialize", {
|
|
44
|
+
protocolVersion: "2025-06-18",
|
|
45
|
+
capabilities: {},
|
|
46
|
+
clientInfo: { name: "ocean", version: "0.3.2" },
|
|
47
|
+
});
|
|
48
|
+
this.notify("notifications/initialized", {});
|
|
49
|
+
}
|
|
50
|
+
async listTools() {
|
|
51
|
+
const result = (await this.request("tools/list", {}));
|
|
52
|
+
const tools = (result.tools ?? []).map((tool) => mcpToolSchema.parse(tool));
|
|
53
|
+
this.tools = new Map(tools.map((tool) => [tool.name, tool]));
|
|
54
|
+
return this.filterAllowed(tools);
|
|
55
|
+
}
|
|
56
|
+
async callTool(name, arguments_ = {}, approval = false) {
|
|
57
|
+
const tool = this.tools.get(name) ??
|
|
58
|
+
(await this.listTools()).find((candidate) => candidate.name === name);
|
|
59
|
+
if (!tool)
|
|
60
|
+
throw new Error(`MCP tool is not allowed or unavailable: ${name}`);
|
|
61
|
+
if (!this.isAllowed(name))
|
|
62
|
+
throw new Error(`MCP tool is not allowed: ${name}`);
|
|
63
|
+
if (tool.annotations?.readOnlyHint === false && !approval)
|
|
64
|
+
throw new Error(`MCP write requires explicit approval: ${name}`);
|
|
65
|
+
const args = tool.annotations?.readOnlyHint === false && approval
|
|
66
|
+
? {
|
|
67
|
+
...arguments_,
|
|
68
|
+
approval: {
|
|
69
|
+
approved: true,
|
|
70
|
+
fingerprint: actionFingerprint(name, arguments_),
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
: arguments_;
|
|
74
|
+
return this.request("tools/call", { name, arguments: args });
|
|
75
|
+
}
|
|
76
|
+
// For a proxy whose own client already gated the call: the arguments go to the server
|
|
77
|
+
// unchanged, so the server's own checks (such as an approval fingerprint) still decide.
|
|
78
|
+
async forwardToolCall(name, arguments_) {
|
|
79
|
+
if (!this.isAllowed(name))
|
|
80
|
+
throw new Error(`MCP tool is not allowed: ${name}`);
|
|
81
|
+
return this.request("tools/call", { name, arguments: arguments_ });
|
|
82
|
+
}
|
|
83
|
+
close() {
|
|
84
|
+
if (this.child) {
|
|
85
|
+
this.child.stdin.destroy();
|
|
86
|
+
this.child.stdout.destroy();
|
|
87
|
+
this.child.kill("SIGKILL");
|
|
88
|
+
}
|
|
89
|
+
this.child = null;
|
|
90
|
+
}
|
|
91
|
+
isAllowed(name) {
|
|
92
|
+
return (!this.options.allowedTools || this.options.allowedTools.includes(name));
|
|
93
|
+
}
|
|
94
|
+
filterAllowed(tools) {
|
|
95
|
+
return tools.filter((tool) => this.isAllowed(tool.name));
|
|
96
|
+
}
|
|
97
|
+
request(method, params) {
|
|
98
|
+
if (!this.child?.stdin.writable)
|
|
99
|
+
return Promise.reject(new Error("MCP client is not connected"));
|
|
100
|
+
const id = this.nextId++;
|
|
101
|
+
this.send({ jsonrpc: "2.0", id, method, params });
|
|
102
|
+
return new Promise((resolve, reject) => this.pending.set(id, { resolve, reject }));
|
|
103
|
+
}
|
|
104
|
+
notify(method, params) {
|
|
105
|
+
this.send({ jsonrpc: "2.0", method, params });
|
|
106
|
+
}
|
|
107
|
+
send(message) {
|
|
108
|
+
if (!this.child?.stdin.writable)
|
|
109
|
+
return;
|
|
110
|
+
this.child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
111
|
+
}
|
|
112
|
+
consume(chunk) {
|
|
113
|
+
this.buffer += chunk;
|
|
114
|
+
while (true) {
|
|
115
|
+
const newline = this.buffer.indexOf("\n");
|
|
116
|
+
if (newline < 0)
|
|
117
|
+
return;
|
|
118
|
+
const line = this.buffer.slice(0, newline).trim();
|
|
119
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
120
|
+
if (!line)
|
|
121
|
+
continue;
|
|
122
|
+
// A stray log line on stdout is not a reason to drop the connection.
|
|
123
|
+
let response;
|
|
124
|
+
try {
|
|
125
|
+
response = JSON.parse(line);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (response.id === undefined)
|
|
131
|
+
continue;
|
|
132
|
+
// A request from the server: answer `ping`, decline the rest (no client capabilities).
|
|
133
|
+
if (response.method !== undefined) {
|
|
134
|
+
this.send(response.method === "ping"
|
|
135
|
+
? { jsonrpc: "2.0", id: response.id, result: {} }
|
|
136
|
+
: {
|
|
137
|
+
jsonrpc: "2.0",
|
|
138
|
+
id: response.id,
|
|
139
|
+
error: {
|
|
140
|
+
code: -32601,
|
|
141
|
+
message: `Unsupported method: ${response.method}`,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const pending = this.pending.get(response.id);
|
|
147
|
+
if (!pending)
|
|
148
|
+
continue;
|
|
149
|
+
this.pending.delete(response.id);
|
|
150
|
+
if (response.error)
|
|
151
|
+
pending.reject(new Error(`MCP ${response.error.message ?? "request failed"}`));
|
|
152
|
+
else
|
|
153
|
+
pending.resolve(response.result);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
failPending(error) {
|
|
157
|
+
for (const pending of this.pending.values())
|
|
158
|
+
pending.reject(error);
|
|
159
|
+
this.pending.clear();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=mcp-client.js.map
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { actionFingerprint, mcpApprovalSchema, } from "@ocean/core/domain/mcp/mcp-contract.js";
|
|
3
|
+
import { oceanPath, SYSTEM_DIR } from "@ocean/core/shared/paths.js";
|
|
4
|
+
import { listInboxCandidates, promoteInboxNote, } from "../../obsidian/inbox-promotion.js";
|
|
5
|
+
import { discoverObsidianVault, loadObsidianConnection, validateObsidianVault, } from "../../obsidian/vault-discovery.js";
|
|
6
|
+
import { syncObsidianVault } from "../../obsidian/vault-sync.js";
|
|
7
|
+
import { resolveObsidianNotePath, writeObsidianNote, } from "../../obsidian/vault-writer.js";
|
|
8
|
+
import { serverVersion } from "./server-version.js";
|
|
9
|
+
import { McpToolRegistry } from "./tool-registry.js";
|
|
10
|
+
const tools = new McpToolRegistry([
|
|
11
|
+
{
|
|
12
|
+
name: "obsidian_discover",
|
|
13
|
+
description: "List Obsidian Markdown notes and metadata issues.",
|
|
14
|
+
annotations: { readOnlyHint: true },
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {},
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "obsidian_sync",
|
|
23
|
+
description: "Compare the configured Obsidian vault with Ocean metadata state.",
|
|
24
|
+
annotations: { readOnlyHint: true },
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {},
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "obsidian_read",
|
|
33
|
+
description: "Read one validated Markdown note by relative path.",
|
|
34
|
+
annotations: { readOnlyHint: true },
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: { path: { type: "string" } },
|
|
38
|
+
required: ["path"],
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "obsidian_inbox_list",
|
|
44
|
+
description: "List raw notes waiting in 00-Inbox.",
|
|
45
|
+
annotations: { readOnlyHint: true },
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {},
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "obsidian_conflicts_list",
|
|
54
|
+
description: "List Ocean-recorded Obsidian write conflicts without proposed note content.",
|
|
55
|
+
annotations: { readOnlyHint: true },
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {},
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "obsidian_write",
|
|
64
|
+
description: "Plan or apply a guarded Obsidian note write.",
|
|
65
|
+
annotations: { readOnlyHint: false },
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
path: { type: "string" },
|
|
70
|
+
content: { type: "string" },
|
|
71
|
+
expectedSha256: { type: ["string", "null"] },
|
|
72
|
+
approved: { type: "boolean" },
|
|
73
|
+
},
|
|
74
|
+
required: ["path", "content", "approved"],
|
|
75
|
+
additionalProperties: false,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "obsidian_inbox_promote",
|
|
80
|
+
description: "Plan or apply promotion of one inbox note into an approved vault area.",
|
|
81
|
+
annotations: { readOnlyHint: false },
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: {
|
|
85
|
+
source: { type: "string" },
|
|
86
|
+
targetDirectory: { type: "string" },
|
|
87
|
+
approved: { type: "boolean" },
|
|
88
|
+
},
|
|
89
|
+
required: ["source", "targetDirectory", "approved"],
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
94
|
+
function textResult(value) {
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: "text", text: JSON.stringify(value) }],
|
|
97
|
+
structuredContent: value,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function requiredString(args, key) {
|
|
101
|
+
const value = args[key];
|
|
102
|
+
if (typeof value !== "string" || !value)
|
|
103
|
+
throw new Error(`${key} is required`);
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function requiredText(args, key) {
|
|
107
|
+
const value = args[key];
|
|
108
|
+
if (typeof value !== "string")
|
|
109
|
+
throw new Error(`${key} is required`);
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
async function conflicts() {
|
|
113
|
+
const directory = oceanPath(SYSTEM_DIR, "integrations", "obsidian", "conflicts");
|
|
114
|
+
try {
|
|
115
|
+
return (await readdir(directory, { withFileTypes: true }))
|
|
116
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
117
|
+
.map((entry) => ({ record: entry.name }));
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error.code === "ENOENT")
|
|
121
|
+
return [];
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function callTool(name, args, connection) {
|
|
126
|
+
await validateObsidianVault(connection);
|
|
127
|
+
if (name === "obsidian_discover") {
|
|
128
|
+
const result = await discoverObsidianVault(connection);
|
|
129
|
+
return {
|
|
130
|
+
noteCount: result.noteCount,
|
|
131
|
+
totalBytes: result.totalBytes,
|
|
132
|
+
notes: result.notes,
|
|
133
|
+
issues: result.issues,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (name === "obsidian_sync")
|
|
137
|
+
return syncObsidianVault(connection);
|
|
138
|
+
if (name === "obsidian_read") {
|
|
139
|
+
const relative = requiredString(args, "path");
|
|
140
|
+
const file = resolveObsidianNotePath(connection.vaultPath, relative);
|
|
141
|
+
const content = await readFile(file, "utf8");
|
|
142
|
+
if (Buffer.byteLength(content) > 1_000_000)
|
|
143
|
+
throw new Error("Obsidian note exceeds 1000000 bytes");
|
|
144
|
+
return { path: relative, content };
|
|
145
|
+
}
|
|
146
|
+
if (name === "obsidian_inbox_list")
|
|
147
|
+
return listInboxCandidates(connection);
|
|
148
|
+
if (name === "obsidian_conflicts_list")
|
|
149
|
+
return conflicts();
|
|
150
|
+
if (name === "obsidian_write") {
|
|
151
|
+
const approval = mcpApprovalSchema.parse(args.approval);
|
|
152
|
+
const actionArgs = {
|
|
153
|
+
path: args.path,
|
|
154
|
+
content: args.content,
|
|
155
|
+
...(args.expectedSha256 === undefined
|
|
156
|
+
? {}
|
|
157
|
+
: { expectedSha256: args.expectedSha256 }),
|
|
158
|
+
};
|
|
159
|
+
if (approval.fingerprint !== actionFingerprint(name, actionArgs))
|
|
160
|
+
throw new Error("Obsidian write approval does not match the requested action");
|
|
161
|
+
return writeObsidianNote(connection, requiredString(args, "path"), requiredText(args, "content"), args.expectedSha256 === null || args.expectedSha256 === undefined
|
|
162
|
+
? null
|
|
163
|
+
: requiredString(args, "expectedSha256"), true);
|
|
164
|
+
}
|
|
165
|
+
if (name === "obsidian_inbox_promote") {
|
|
166
|
+
const approval = mcpApprovalSchema.parse(args.approval);
|
|
167
|
+
const actionArgs = {
|
|
168
|
+
source: args.source,
|
|
169
|
+
targetDirectory: args.targetDirectory,
|
|
170
|
+
};
|
|
171
|
+
if (approval.fingerprint !== actionFingerprint(name, actionArgs))
|
|
172
|
+
throw new Error("Inbox promotion approval does not match the requested action");
|
|
173
|
+
return promoteInboxNote(connection, requiredString(args, "source"), requiredString(args, "targetDirectory"), true);
|
|
174
|
+
}
|
|
175
|
+
throw new Error(`Unknown MCP tool: ${name}`);
|
|
176
|
+
}
|
|
177
|
+
export async function handleObsidianMcpRequest(request, connection) {
|
|
178
|
+
if (request.method === "notifications/initialized")
|
|
179
|
+
return null;
|
|
180
|
+
if (request.method === "initialize")
|
|
181
|
+
return {
|
|
182
|
+
jsonrpc: "2.0",
|
|
183
|
+
id: request.id,
|
|
184
|
+
result: {
|
|
185
|
+
protocolVersion: "2025-06-18",
|
|
186
|
+
capabilities: { tools: {} },
|
|
187
|
+
serverInfo: { name: "ocean-obsidian", version: await serverVersion() },
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
if (request.method === "tools/list")
|
|
191
|
+
return { jsonrpc: "2.0", id: request.id, result: { tools: tools.list() } };
|
|
192
|
+
if (request.method !== "tools/call")
|
|
193
|
+
return {
|
|
194
|
+
jsonrpc: "2.0",
|
|
195
|
+
id: request.id,
|
|
196
|
+
error: {
|
|
197
|
+
code: -32601,
|
|
198
|
+
message: `Unsupported MCP method: ${request.method ?? ""}`,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
const name = request.params?.name;
|
|
202
|
+
if (typeof name !== "string" || !tools.has(name))
|
|
203
|
+
return {
|
|
204
|
+
jsonrpc: "2.0",
|
|
205
|
+
id: request.id,
|
|
206
|
+
error: { code: -32602, message: "Unknown MCP tool" },
|
|
207
|
+
};
|
|
208
|
+
try {
|
|
209
|
+
return {
|
|
210
|
+
jsonrpc: "2.0",
|
|
211
|
+
id: request.id,
|
|
212
|
+
result: textResult(await callTool(name, (request.params?.arguments ?? {}), connection)),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
jsonrpc: "2.0",
|
|
218
|
+
id: request.id,
|
|
219
|
+
error: {
|
|
220
|
+
code: -32000,
|
|
221
|
+
message: error instanceof Error ? error.message : String(error),
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export async function runObsidianMcpServer() {
|
|
227
|
+
const connection = await loadObsidianConnection();
|
|
228
|
+
let buffer = "";
|
|
229
|
+
process.stdin.setEncoding("utf8");
|
|
230
|
+
process.stdin.on("data", async (chunk) => {
|
|
231
|
+
buffer += chunk;
|
|
232
|
+
while (true) {
|
|
233
|
+
const newline = buffer.indexOf("\n");
|
|
234
|
+
if (newline < 0)
|
|
235
|
+
return;
|
|
236
|
+
const line = buffer.slice(0, newline).trim();
|
|
237
|
+
buffer = buffer.slice(newline + 1);
|
|
238
|
+
if (!line)
|
|
239
|
+
continue;
|
|
240
|
+
const request = JSON.parse(line);
|
|
241
|
+
const response = await handleObsidianMcpRequest(request, connection);
|
|
242
|
+
if (!response)
|
|
243
|
+
continue;
|
|
244
|
+
process.stdout.write(`${JSON.stringify(response)}\n`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
await new Promise((resolve) => {
|
|
248
|
+
process.stdin.once("end", resolve);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=obsidian-server.js.map
|