ScienceDiscovery
中文 GitHub

Runtime Core boundaries

This page describes the in-process native executor kernel. JiuwenSwarm runs its own agent loop; the shared product control plane is described in Runtime architecture.

@sciencediscovery/runtime-core is the stable, domain-neutral execution kernel. It owns the Agent Loop state machine and only the invariants common to every agent execution:

The runtime depends on four ports and has no product package dependencies. RuntimeBuilder is its typed registration surface; it rejects incomplete composition and freezes a run's port registry before execution:

services/api/src/bootstrap/runtime.ts is the composition root. Its native-agent adapter wires the ports to prompt construction, history compaction, model transport, the tool registry, permission gates, provenance hooks, and SSE events. These policies deliberately remain outside Runtime Core. A subagent is dispatched through the existing task tool, so the core does not define a separate agent-dispatch path.

The dependency direction is:

apps -> services/api -> capability adapters -> packages/runtime-core

Capability code may implement Runtime Core ports. Runtime Core must never import HTTP/SSE, provider clients, tools, MCP, permissions, artifacts, provenance, specialists, or other ScienceDiscovery domain packages.

Current capability ownership:

services/api/src/bootstrap/platform.ts selects concrete storage, MCP, network, model, review, and execution adapters for these packages. The HTTP server consumes that assembled service set and translates HTTP/SSE requests; it does not own domain construction. SessionStore, the MCP Node process client, HTTP/SSE translation, and the small Reviewer-to-AgentRun bridge remain service adapters. Capability packages depend on narrow ports rather than on SessionStore or another service implementation.

Dynamic context modes, Contributor boundaries, budgets, and full-input trace export are documented in Dynamic context assembly.

Review behavior remains explicit: Artifact registration never dispatches a review automatically. The main Agent invokes review_checkpoint, and the result returns through the ordinary Tool Result/SSE path. Runtime Core and the Artifact manager do not contain a Review outbox or implicit Review coordinator.

The former private packages/agent-runtime aggregate has been removed after all repository imports were migrated to their owning capability package; no compatibility service locator or duplicate runtime remains.

Permissions, provenance, artifacts, data sources, and specialists remain domain services/adapters and enter execution only through registered tools or events. They are not allowed to add control branches to Runtime Core.

pnpm architecture:check enforces the direction: packages cannot import services/apps, production services cannot use the compatibility facade, Runtime Core cannot use non-relative imports, and domain sources already moved to packages cannot be recreated under services/api.