pi-mono/packages/coding-agent/src/experimental/services/README.md
2026-08-27 10:19:02 +02:00

4.2 KiB

Experimental client/server service slices

Facet setup generates each host's RPC service catalogue from its provided RPC-capable tokens. Connections exchange those catalogues and bind only services required by consuming facets; there is no handwritten built-in service inventory. With no selected Session, its deferred connection admits unresolved requirements as unavailable and keeps their handles disconnected. Attachment validates them against the worker's generated catalogue, which is cached for later detached generations. A built-in token is either implemented end to end or registered with an explicit ServiceSliceNotImplemented provider. Framed callers receive the stable service_not_implemented code. Keyed services hydrate as an empty directory until their owning feature spawns an instance.

Scope Service Current slice Continuation point
server SessionDirectory replicated state and semantic directory events implemented add authenticated per-client projection when identity lands
server SessionManagement create, remove, attach, detach implemented add authenticated workspace authorization
session Models state, selection, thinking, refresh implemented move provider/auth composition behind plugin facets
session Chat prompt and durable requestAbort implemented; queue, resume, compaction, and navigation contracts declared replace each explicit throwing provider member with its Harness adapter slice
session Accounts state declared; mutations throw connect the local credential service to the presentation-safe facade
session Transcript revisioned events surface declared; snapshot throws and no Harness event producer is attached implement snapshot/event gap handling and remove the compatibility lane watch

RemoteEvents has local and remote ordered delivery, hydration-race buffering, keyed-instance routing, and no replay for late subscribers. ServerServiceConnection.connection and SessionServiceConnection.attachment are implemented local control states.

With PI_EXPERIMENTAL=1, an interactive pi client opens the service-only TUI. It lists the repository-backed SessionDirectory, creates or switches Sessions through SessionManagement, and selects from the attached worker's Models state without invoking Harness drive.

The Session worker loads all built-in and configured Session facets through one FacetLoader, then creates one active FacetHost. The service-only TUI likewise loads all TUI facets once and creates one host that combines its local Tui service with connected server and selected-Session services. Runtime facets provide host-created services such as Harness, ModelsRuntime, and Tui through the same env.provide() operation used by every other facet. Synchronous setup-time env.provide(), env.provideMany(), env.use(), and env.observe() calls produce the internal dependency graph; setup does not repeat a declarative dependency list, and service handles remain disconnected until the complete graph validates. Providers activate before consumers, observations connect with their consuming facet, and disposal runs in reverse dependency order for the complete generation. Services are RPC-capable by default; process-local tokens such as Harness, ModelsRuntime, and Tui declare { rpc: false }. The host automatically publishes every provided RPC-capable service.

A facet always calls unqualified env.use() or env.observe(). The host resolves each token across facet-provided and connected services. Transport namespaces remain internal binding machinery rather than part of the facet environment. TUI facets own subscriptions to their remote replicated state and events; ExperimentalClientTui retains only terminal rendering, navigation, and action dispatch. The server provider remains directly assembled until its complete host environment exists. The question dialog, diff review, Git, indexing-job, and canvas examples in packages/agent/docs/plugins.md are extension patterns, not built-in coding-agent services. Private references, trace carriers, and flow control remain protocol/host infrastructure slices rather than presentation service tokens.