From c448a6ecd013dbd5d7facc50f3d500dbaf610042 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 18:21:12 +0000 Subject: [PATCH] Sort core's gateway into folders and give providers one way into core Moves the 50 files in plugins/multi-core/src/gateway/ into server/, mod/, providers/, direct/, harness/ and util/ (nested-env.ts to launch/), and adds plugins/multi-core/src/kit/ as the only entry providers import core through. No behavior change: path depths in provider.ts and the install copies of executable.ts and process-tree.ts follow the move (uninstall also cleans the old location), Effort moves to messages.ts and nativeSpelling to its own file so the permission hook's kit import stays light. Docs now say a busy harness waits rather than refuses, and the unused HarnessBusyError is removed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HyhDzVC7X4rmhG5ZBA2i6X --- AGENTS.md | 26 +++---- ARCHITECTURE.md | 71 +++++++++++------- CHANGELOG.md | 19 +++++ docs/claude-mods.md | 4 +- plugins/multi-antigravity/src/adapter.ts | 5 +- plugins/multi-antigravity/src/cli.ts | 4 +- plugins/multi-antigravity/src/harness.ts | 43 +++++------ plugins/multi-antigravity/src/hooks.ts | 3 +- plugins/multi-antigravity/src/models.ts | 7 +- plugins/multi-antigravity/src/permissions.ts | 7 +- plugins/multi-antigravity/src/progress.ts | 6 +- plugins/multi-antigravity/src/quota.ts | 6 +- plugins/multi-antigravity/src/request.ts | 5 +- .../multi-antigravity/src/usage-adapter.ts | 2 +- plugins/multi-core/src/account.ts | 4 +- .../src/gateway/{ => direct}/conversation.ts | 4 +- .../src/gateway/{ => direct}/direct-tools.ts | 4 +- .../request.ts} | 6 +- .../src/gateway/{ => direct}/responses.ts | 23 +++--- .../src/gateway/{ => direct}/tokens.ts | 0 .../src/gateway/{ => direct}/tools.ts | 2 +- .../{harness-cli.ts => harness/cli.ts} | 20 ++--- .../completion.ts} | 6 +- .../exchange.ts} | 16 ++-- .../failure.ts} | 6 +- .../handback.ts} | 4 +- .../migration.ts} | 2 +- .../gateway/{ => harness}/native-harness.ts | 6 +- .../notices.ts} | 6 +- .../process.ts} | 4 +- .../progress.ts} | 4 +- .../{harness-prompt.ts => harness/prompt.ts} | 4 +- .../response.ts} | 4 +- .../session.ts} | 26 +++---- .../gateway/{mod-bridge.ts => mod/bridge.ts} | 4 +- .../src/gateway/{ => mod}/display-rows.ts | 6 +- .../src/gateway/{mod-keys.ts => mod/keys.ts} | 0 .../src/gateway/{ => mod}/provider-usage.ts | 2 +- .../src/gateway/{ => mod}/receipts.ts | 4 +- .../gateway/{mod-routes.ts => mod/routes.ts} | 12 +-- .../gateway/{mod-usage.ts => mod/usage.ts} | 0 .../adapter.ts} | 6 +- .../{ => providers}/agent-definitions.ts | 4 +- .../{ => providers}/harness-settings.ts | 2 +- .../src/gateway/{ => providers}/mode-hook.ts | 2 +- .../src/gateway/{ => providers}/provider.ts | 11 +-- .../src/gateway/providers/spelling.ts | 7 ++ .../gateway/{ => providers}/worker-catalog.ts | 0 .../gateway/{ => providers}/worker-models.ts | 4 +- .../src/gateway/{ => server}/anthropic.ts | 0 .../src/gateway/{ => server}/front-door.ts | 0 .../src/gateway/{ => server}/messages.ts | 5 ++ .../src/gateway/{ => server}/reply.ts | 20 ++--- .../src/gateway/{ => server}/request.ts | 12 +-- .../src/gateway/{ => server}/self-signed.ts | 0 .../src/gateway/{ => server}/server.ts | 73 ++++++++++--------- .../src/gateway/{ => server}/verdicts.ts | 4 +- .../src/gateway/{ => util}/atomic-write.ts | 0 .../src/gateway/{ => util}/bounded.ts | 0 .../src/gateway/{ => util}/executable.ts | 0 .../src/gateway/{ => util}/fetch.ts | 0 .../src/gateway/{ => util}/process-tree.ts | 0 .../src/gateway/{ => util}/record.ts | 0 .../src/gateway/{ => util}/settle.ts | 0 .../src/gateway/{ => util}/state-lock.ts | 0 .../multi-core/src/install/installation.ts | 10 ++- plugins/multi-core/src/install/plugins.ts | 2 +- plugins/multi-core/src/install/process.ts | 4 +- plugins/multi-core/src/kit/adapter.ts | 24 ++++++ plugins/multi-core/src/kit/direct.ts | 20 +++++ plugins/multi-core/src/kit/harness.ts | 43 +++++++++++ plugins/multi-core/src/kit/util.ts | 10 +++ plugins/multi-core/src/launch/certificate.ts | 6 +- plugins/multi-core/src/launch/claude.ts | 7 +- plugins/multi-core/src/launch/desktop.ts | 2 +- plugins/multi-core/src/launch/environment.ts | 4 +- plugins/multi-core/src/launch/front-door.ts | 6 +- plugins/multi-core/src/launch/gateway.ts | 16 ++-- .../src/{gateway => launch}/nested-env.ts | 0 plugins/multi-core/src/launch/picker.ts | 3 +- plugins/multi-core/src/launch/providers.ts | 4 +- plugins/multi-core/src/launch/workers.ts | 6 +- plugins/multi-core/src/launcher.ts | 4 +- plugins/multi-core/src/serve.ts | 2 +- plugins/multi-cursor/src/adapter.ts | 2 +- plugins/multi-cursor/src/errors.ts | 6 -- plugins/multi-cursor/src/harness.ts | 66 +++++++---------- plugins/multi-cursor/src/permissions.ts | 7 +- plugins/multi-cursor/src/progress.ts | 4 +- plugins/multi-cursor/src/quota.ts | 2 +- plugins/multi-cursor/src/request.ts | 12 +-- plugins/multi-cursor/src/session-record.ts | 2 +- plugins/multi-cursor/src/usage-adapter.ts | 2 +- plugins/multi-cursor/src/workspaces.ts | 3 +- plugins/multi-grok/src/adapter.ts | 5 +- plugins/multi-grok/src/cli.ts | 4 +- plugins/multi-grok/src/harness.ts | 40 +++++----- plugins/multi-grok/src/models.ts | 7 +- plugins/multi-grok/src/permissions.ts | 7 +- plugins/multi-grok/src/progress.ts | 7 +- plugins/multi-grok/src/request.ts | 5 +- plugins/multi-grok/src/usage-adapter.ts | 2 +- plugins/multi-grok/src/usage.ts | 2 +- plugins/multi-openai/src/adapter.ts | 2 +- plugins/multi-openai/src/auth.ts | 6 +- plugins/multi-openai/src/gateway-request.ts | 17 ++--- plugins/multi-openai/src/models.ts | 2 +- plugins/multi-openai/src/usage-adapter.ts | 2 +- plugins/multi-openai/src/usage.ts | 6 +- plugins/multi-zen/src/adapter.ts | 2 +- plugins/multi-zen/src/auth.ts | 2 +- plugins/multi-zen/src/chat.ts | 18 ++--- plugins/multi-zen/src/gateway-request.ts | 14 ++-- plugins/multi-zen/src/models.ts | 2 +- plugins/multi-zen/src/request.ts | 15 ++-- plugins/multi-zen/src/usage-adapter.ts | 2 +- plugins/multi-zen/src/usage.ts | 2 +- scripts/check-providers.ts | 2 +- test/live/native-antigravity.ts | 4 +- test/live/native-auto-mode.ts | 2 +- test/live/native-compaction.ts | 2 +- test/live/native-cursor-harness.ts | 4 +- test/live/native-desktop.ts | 2 +- test/live/native-front-door.ts | 2 +- test/live/native-grok.ts | 4 +- test/live/native-openai-cache.ts | 8 +- test/live/native-openai-instructions.ts | 2 +- test/live/native-translation.ts | 4 +- test/live/native-zen.ts | 8 +- test/live/providers.ts | 4 +- 130 files changed, 563 insertions(+), 472 deletions(-) rename plugins/multi-core/src/gateway/{ => direct}/conversation.ts (98%) rename plugins/multi-core/src/gateway/{ => direct}/direct-tools.ts (93%) rename plugins/multi-core/src/gateway/{provider-request.ts => direct/request.ts} (92%) rename plugins/multi-core/src/gateway/{ => direct}/responses.ts (99%) rename plugins/multi-core/src/gateway/{ => direct}/tokens.ts (100%) rename plugins/multi-core/src/gateway/{ => direct}/tools.ts (95%) rename plugins/multi-core/src/gateway/{harness-cli.ts => harness/cli.ts} (93%) rename plugins/multi-core/src/gateway/{harness-completion.ts => harness/completion.ts} (96%) rename plugins/multi-core/src/gateway/{harness-exchange.ts => harness/exchange.ts} (95%) rename plugins/multi-core/src/gateway/{harness-failure.ts => harness/failure.ts} (90%) rename plugins/multi-core/src/gateway/{harness-handback.ts => harness/handback.ts} (98%) rename plugins/multi-core/src/gateway/{harness-migration.ts => harness/migration.ts} (97%) rename plugins/multi-core/src/gateway/{ => harness}/native-harness.ts (87%) rename plugins/multi-core/src/gateway/{harness-notices.ts => harness/notices.ts} (97%) rename plugins/multi-core/src/gateway/{harness-process.ts => harness/process.ts} (99%) rename plugins/multi-core/src/gateway/{harness-progress.ts => harness/progress.ts} (99%) rename plugins/multi-core/src/gateway/{harness-prompt.ts => harness/prompt.ts} (98%) rename plugins/multi-core/src/gateway/{harness-response.ts => harness/response.ts} (98%) rename plugins/multi-core/src/gateway/{harness-session.ts => harness/session.ts} (95%) rename plugins/multi-core/src/gateway/{mod-bridge.ts => mod/bridge.ts} (98%) rename plugins/multi-core/src/gateway/{ => mod}/display-rows.ts (99%) rename plugins/multi-core/src/gateway/{mod-keys.ts => mod/keys.ts} (100%) rename plugins/multi-core/src/gateway/{ => mod}/provider-usage.ts (98%) rename plugins/multi-core/src/gateway/{ => mod}/receipts.ts (99%) rename plugins/multi-core/src/gateway/{mod-routes.ts => mod/routes.ts} (97%) rename plugins/multi-core/src/gateway/{mod-usage.ts => mod/usage.ts} (100%) rename plugins/multi-core/src/gateway/{provider-adapter.ts => providers/adapter.ts} (95%) rename plugins/multi-core/src/gateway/{ => providers}/agent-definitions.ts (98%) rename plugins/multi-core/src/gateway/{ => providers}/harness-settings.ts (99%) rename plugins/multi-core/src/gateway/{ => providers}/mode-hook.ts (99%) rename plugins/multi-core/src/gateway/{ => providers}/provider.ts (93%) create mode 100644 plugins/multi-core/src/gateway/providers/spelling.ts rename plugins/multi-core/src/gateway/{ => providers}/worker-catalog.ts (100%) rename plugins/multi-core/src/gateway/{ => providers}/worker-models.ts (98%) rename plugins/multi-core/src/gateway/{ => server}/anthropic.ts (100%) rename plugins/multi-core/src/gateway/{ => server}/front-door.ts (100%) rename plugins/multi-core/src/gateway/{ => server}/messages.ts (96%) rename plugins/multi-core/src/gateway/{ => server}/reply.ts (97%) rename plugins/multi-core/src/gateway/{ => server}/request.ts (96%) rename plugins/multi-core/src/gateway/{ => server}/self-signed.ts (100%) rename plugins/multi-core/src/gateway/{ => server}/server.ts (96%) rename plugins/multi-core/src/gateway/{ => server}/verdicts.ts (96%) rename plugins/multi-core/src/gateway/{ => util}/atomic-write.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/bounded.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/executable.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/fetch.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/process-tree.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/record.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/settle.ts (100%) rename plugins/multi-core/src/gateway/{ => util}/state-lock.ts (100%) create mode 100644 plugins/multi-core/src/kit/adapter.ts create mode 100644 plugins/multi-core/src/kit/direct.ts create mode 100644 plugins/multi-core/src/kit/harness.ts create mode 100644 plugins/multi-core/src/kit/util.ts rename plugins/multi-core/src/{gateway => launch}/nested-env.ts (100%) diff --git a/AGENTS.md b/AGENTS.md index 998a7052..9d6e3ade 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,19 +16,16 @@ Claude Code function-hook UI and extensibility rules live in | Path | Responsibility | | --- | --- | | `plugins/multi-/provider.json` | A provider's manifest: name, label, kind (`direct` or `harness`), order, and usage text. Core reads these and names no provider. | -| `plugins/multi-/src/adapter.ts` | A provider's adapter: sign-in, models, runtime, launcher flags, and account verb, loaded by core through `gateway/provider-adapter.ts`. | -| `plugins/multi-core/src/launcher.ts`, `serve.ts`, `launch/` | Launches the gateway and Claude Code (`launcher.ts`), or the gateway alone for a desktop app session the mod serves (`serve.ts`). `launch/` holds the shared gateway start (`gateway.ts`), the provider connection (`providers.ts`), the `/model` picker (`picker.ts`), worker types (`workers.ts`), the Claude executable probes (`claude.ts`), the session environment (`environment.ts`), the desktop handshake and picker rows (`desktop.ts`), and the installed front-door certificate (`certificate.ts`). | -| `plugins/multi-core/src/gateway/server.ts`, `request.ts`, `reply.ts`, `anthropic.ts` | Routes requests and manages sessions; request admission and identity; replies and failures; Anthropic passthrough headers and paths. | -| `plugins/multi-core/src/gateway/messages.ts`, `fetch.ts`, `tools.ts`, `responses.ts`, `bounded.ts`, `record.ts` | Shared protocol, outbound fetch, tool aliases, Responses translation and SSE reader, bounded maps, and the `isRecord` guard. | -| `plugins/multi-core/src/gateway/provider.ts`, `provider-adapter.ts`, `provider-request.ts` | The provider table read from the manifests, `providerOf`, `nativeSpelling`; the adapter contract and loader; the contract through which direct providers build their own requests. | -| `plugins/multi-core/src/gateway/front-door.ts`, `self-signed.ts`, `launch/front-door.ts` | The gateway as Claude Code's HTTPS proxy, so Remote Control stays on: CONNECT handling, the per-session certificate, and when a launch uses it. | -| `plugins/multi-core/src/gateway/executable.ts`, `process-tree.ts` | Resolves executables and manages child processes. | -| `plugins/multi-core/src/gateway/atomic-write.ts`, `state-lock.ts` | Protects files and serializes native state. | -| `plugins/multi-core/src/gateway/harness-settings.ts`, `mode-hook.ts`, `agent-definitions.ts`, `worker-catalog.ts` | Reads what a native run takes from Claude's settings (`readHarnessSettings`, `mergePermissions`, `nativeMode`, `nativeRules`), keeps one permission record per session, and resolves the Agent tool's `model` against each provider's worker catalog. | -| `plugins/multi-core/src/gateway/verdicts.ts`, `provider.ts` | Core verdict contract (Plan checks, no model calls) and the provider table. `server.ts` alone finalises served replies and terminal events. | -| `plugins/multi-core/src/gateway/mod-*.ts`, `display-rows.ts`, `nested-env.ts` | Claude Mods control-plane routes, per-session mod key (`mod-keys.ts`), compaction, policy, native action display rows, and the nested-`claude` environment restore. | +| `plugins/multi-/src/adapter.ts` | A provider's adapter: sign-in, models, runtime, launcher flags, and account verb, loaded by core through `gateway/providers/adapter.ts`. | +| `plugins/multi-core/src/kit/` | The only files provider folders import core through: `adapter.ts` (adapter contract, request types, permission readers; kept light for Antigravity's per-tool-call hook), `util.ts` (Node-only helpers), `direct.ts` (direct-provider translation), `harness.ts` (shared harness runtime). | +| `plugins/multi-core/src/launcher.ts`, `serve.ts`, `launch/` | Launches the gateway and Claude Code (`launcher.ts`), or the gateway alone for a desktop app session the mod serves (`serve.ts`). `launch/` holds the shared gateway start (`gateway.ts`), the provider connection (`providers.ts`), the `/model` picker (`picker.ts`), worker types (`workers.ts`), the Claude executable probes (`claude.ts`), the session environment (`environment.ts`), the desktop handshake and picker rows (`desktop.ts`), the installed front-door certificate (`certificate.ts`), and the nested-`claude` environment restore (`nested-env.ts`). | +| `plugins/multi-core/src/gateway/server/` | Routes requests and manages sessions (`server.ts`, which alone finalises served replies and terminal events); request admission and identity (`request.ts`); replies and failures (`reply.ts`); Anthropic passthrough (`anthropic.ts`); the front door as Claude Code's HTTPS proxy, so Remote Control stays on (`front-door.ts`, `self-signed.ts`, with `launch/front-door.ts`); shared protocol types (`messages.ts`); and the core verdict contract (`verdicts.ts`: Plan checks, no model calls). | +| `plugins/multi-core/src/gateway/mod/` | Claude Mods control-plane routes (`routes.ts`, `bridge.ts`), the per-session mod key (`keys.ts`), native action display rows (`display-rows.ts`), receipts, and usage (`usage.ts`, `provider-usage.ts`). | +| `plugins/multi-core/src/gateway/providers/` | The provider table read from the manifests (`provider.ts`: `providerOf`, worker types); `nativeSpelling` (`spelling.ts`); the adapter contract and loader (`adapter.ts`); the Agent tool's worker types and models (`agent-definitions.ts`, `worker-catalog.ts`, `worker-models.ts`); one permission record per session (`mode-hook.ts`); and what a native run takes from Claude's settings (`harness-settings.ts`: `readHarnessSettings`, `mergePermissions`, `nativeMode`, `nativeRules`). | +| `plugins/multi-core/src/gateway/direct/` | The contract through which direct providers build their own requests (`request.ts`), Responses translation and SSE reader (`responses.ts`), conversation normalization, tool aliases, and token estimates. | +| `plugins/multi-core/src/gateway/harness/` | Shared by Cursor, Antigravity and Grok: the harness contract (`native-harness.ts`), session store, exchange registry, response builder, completion, notices, hand-back, and failure classifier; and, for Antigravity and Grok, the CLI harness base (`cli.ts`), process runner (`process.ts`), and text prompt preparation. | +| `plugins/multi-core/src/gateway/util/` | No Multi logic: executables and child processes, atomic writes, the state lock, bounded maps, outbound fetch, `settleOrAbort`, and the `isRecord` guard. `install/` copies `executable.ts` and `process-tree.ts` beside the installed bootstrap. | | `plugins/multi-core/hooks/` | Claude Mods function hooks; `gateway.ts` is the single gateway client, state lives in `$.state`, timing in `$.clock`. `provider.ts` is the hooks' own provider table, checked against the manifests by `npm run check:providers`. `desktop.ts` reads the handshake of the gateway the mod starts in a desktop app session. | -| `plugins/multi-core/src/gateway/harness-*.ts` | Session store, exchange registry, response builder, completion, notices, and failure classifier (`harness-failure.ts`) shared by Cursor, Antigravity, and Grok; the CLI harness base (`harness-cli.ts`), process runner, and text prompt preparation shared by Antigravity and Grok. | | `plugins/multi-core/src/account.ts`, `setup.ts`, `install/` | Accounts, bootstrap, plugin discovery, and installation. | | `plugins/multi-openai/src/` | Codex authentication, models, request construction (`gateway-request.ts`), and instructions. | | `plugins/multi-cursor/src/` | Cursor SDK harness, permissions, progress, requests, models, and workspaces. | @@ -44,8 +41,9 @@ Claude Code function-hook UI and extensibility rules live in Keep everything about one provider in its folder: core imports no provider code and names no provider, so adding or removing a provider touches its folder and the hooks' table in `plugins/multi-core/hooks/provider.ts`. Keep shared protocol -types and cross-provider helpers in `plugins/multi-core/src/gateway/`. Prefer -direct module imports, the existing repository convention. Platform-dependent code +types and cross-provider helpers in `plugins/multi-core/src/gateway/`. A provider +imports core only through `plugins/multi-core/src/kit/`; add an export there when a +provider needs one. Inside core, prefer direct module imports. Platform-dependent code accepts an explicit `platform` option so every branch is unit-testable on Linux. ## Current execution contracts diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index df2aede7..685debf6 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -16,7 +16,7 @@ Claude Mods provide the in-engine control plane for model rows, worker rows, permission state, progress, and compaction. The hooks (`plugins/multi-core/hooks/`) reach the gateway through one client (`hooks/gateway.ts`) and keep state in `$.state` so it survives a hot reload. The gateway mints a per-session mod key -(`mod-keys.ts`) on the mod's first request and, once the mod echoes it, refuses +(`mod/keys.ts`) on the mod's first request and, once the mod echoes it, refuses `/multi/mod/*` requests carrying only the environment token, so a shell command cannot loosen a session's permissions. Session state is dropped on `session.end`, not when a client detaches. [The local Mods reference](docs/claude-mods.md) @@ -28,11 +28,27 @@ states its name, label, kind (`direct`: Claude Code runs the tools; `harness`: t provider's SDK or CLI does), display order, and usage text. Its `src/adapter.ts` default-exports the adapter core loads: sign-in and model discovery for a launch, the harness or request builder that runs it, its launcher flags, and its -account verb. Core reads the manifests (`gateway/provider.ts`), loads the adapters -(`gateway/provider-adapter.ts`), and imports no provider code. The hooks run inside +account verb. Core reads the manifests (`gateway/providers/provider.ts`), loads the adapters +(`gateway/providers/adapter.ts`), and imports no provider code. The hooks run inside Claude Code and cannot read those files, so they keep one small table (`hooks/provider.ts`) that `npm run check:providers` compares with the manifests. +Providers import core only through four entry files in `src/kit/`: `adapter.ts` (the +adapter contract, Claude's request shapes and the permission readers; kept light because +Antigravity's permission hook loads it on every tool call), `util.ts` (Node-only helpers), +`direct.ts` (request translation for direct providers) and `harness.ts` (the shared +harness runtime). Core can move its own files without touching a provider folder. +Inside core, `src/gateway/` groups its files by job: + +| Folder | Holds | +| --- | --- | +| `server/` | The HTTP server, request admission, replies, Anthropic passthrough, the front door, the shared message types and verdicts. | +| `mod/` | The Claude Mods control plane: routes, the per-session mod key, display rows, receipts and usage. | +| `providers/` | Provider manifests and adapters, worker types and catalogs, and the permission record and settings readers. | +| `direct/` | Translation for providers whose models Claude Code drives (Responses, conversation, tools, token estimates). | +| `harness/` | The shared runtime of the CLI and SDK harnesses: session store, exchanges, process runner, progress, responses, notices. | +| `util/` | Helpers with no Multi logic in them. | + ```text Claude Code session (/model, workers, prompts) | @@ -55,7 +71,7 @@ session up. The mod does it instead (`hooks/register.ts`, `hooks/desktop.ts`): a for its one-line handshake (`launch/desktop.ts`: the variables to set, the worker types, whether the front door is in use, and a notice), sets each variable with `$.env.set`, and registers each worker with `$.agent.register`, which Claude Code names -`multi-core: