feat: HTTP /v1/chat/completions + WS bridge + process manager

Real first cut. OpenClaw routes agent turns via /v1/chat/completions
(OpenAI-compatible SSE) into our bridge. Bridge ensures a long-lived
claude process per session-key, pushes the user message as
notifications/claude/channel into the running Claude Code, awaits a
reply via the WS connection, streams the reply back as SSE deltas.

- core/process-manager: spawn / track / reap claude processes, auto-confirm
  the --dangerously-load-development-channels dev-mode prompt by piping
  "1\n" to stdin shortly after spawn
- web/bridge-server: unified HTTP + WS server, per-session FIFO queue,
  SSE heartbeat (empty content delta — SSE comments don't reset OpenClaw's
  idle watchdog), reply buffering for streaming progress chunks
- index.ts: definePluginEntry for OpenClaw runtime + standalone-mode main
  for laptop smoke testing (just `bun index.ts`)

Same-machine simplifications: no bridge token, no permission_request
reverse channel. Session key = agent_id::chat_id (contractor-agent
convention).
This commit is contained in:
zhi
2026-05-14 13:28:00 +00:00
parent 38ac6d20b7
commit 0324a47d13
8 changed files with 492 additions and 286 deletions

View File

@@ -1,37 +1,4 @@
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk/core'
import type { ProcessManager } from './process-manager.js'
import type { SessionMapping } from './session-mapping.js'
import type { SynthesisConfig } from './config.js'
interface CliDeps {
processManager: ProcessManager
mapping: SessionMapping
config: SynthesisConfig
}
/**
* `openclaw synthesis ...` admin commands. Used to inspect & poke the running
* pool from outside (helpful for testing without a real channel inbound).
*
* Subcommands (planned):
* list — show live processes + mapping
* push <session> <text> — fake an inbound message
* kill <session> — terminate a process (mapping preserved)
* forget <session> — drop mapping entirely (next msg = new claude session)
*/
export function registerCli(api: OpenClawPluginApi, deps: CliDeps): void {
// The exact API shape for command registration depends on the OpenClaw
// plugin-sdk version. Two common forms seen in existing plugins:
//
// api.commands?.register('synthesis', { describe, handler })
// api.cli?.command('synthesis', sub => sub.command('list', '...', () => {...}))
//
// Both are stubbed below — pick whichever the loaded SDK exposes when
// wiring this for real.
const _ = { api, deps }
// TODO: wire actual command registration once the surrounding plugin
// patterns are confirmed (see contractor-agent/commands/register-cli.ts
// for the canonical example in this codebase).
void _
}
// Reserved for future `openclaw synthesis ...` admin commands (list, kill,
// forget). Stub kept in place so index.ts can wire registerCli once OpenClaw
// plugin-sdk's exact CLI registration surface is confirmed.
export {}