The LLM service exposed three call surfaces (stream/streamBlocks/generate) but the only production consumer — the agent loop — uses stream() exclusively, feeding raw chunks through its own BlockAssembler for replay fidelity. Drop the speculative convenience surfaces and the registry-change event that no listener consumed, leaving stream() as the single model-call contract for both production and tests. - Remove LlmService.streamBlocks() and generate(), the llm/generate waterfall, and GenerateResult. - Remove the llm/adapter-change event (declaration + emits) and the listener-throw rollback ordering that existed only to protect it; keep the HMR rollback disposer. - Remove BlockAssembler.flushReady()/flushRemaining()/result() and the flushed cursor — the streaming-flush slice existed only for streamBlocks(). - Adapter tests drive a stream()+BlockAssembler helper (tests/assemble.ts) instead of generate(), exercising the same path production uses. - Land the AGENTS.md "RFCs are proposals, not golden truth" principle and move both RFCs proposed -> implemented. Implements: - docs/rfc/implemented/simplification/2026-06-20-drop-unconsumed-llm-adapter-change-event.md - docs/rfc/implemented/simplification/2026-06-20-drop-unconsumed-llm-assembled-surfaces.md
5.5 KiB
RFC: Drop unconsumed assembled LLM convenience surfaces
Status: implemented (proposed and accepted 2026-06-20)
Problem
LlmService (packages/llm/llm/src/index.ts) exposes three call surfaces over a model:
stream()— rawStreamChunks, dispatched through thellm/streamwaterfall.streamBlocks()— a "convenience view" that runs the chunks through aBlockAssemblerand yields completedContentBlocks in stream order (index.ts:137-144).generate()— one fully-assembledGenerateResult, dispatched through a secondllm/generatewaterfall (index.ts:151-157).
The only production consumer of the LLM service is the agent loop, and it uses stream() exclusively — feeding raw chunks through its own BlockAssembler so it can log chunks for replay fidelity while assembling in parallel (packages/core/agent-loop/src/loop.ts, the ctx.llm.stream(req) step). Grepping streamBlocks and ctx.llm.generate across packages/*/src and examples/*/src finds no production callers. The references are the service methods, docs, and tests; adapter tests use generate() as a convenient driver, but they can hand-drain stream() through the same assembler helper without preserving a public production API.
This is the drop-mutable-session-summary pattern: assembled-view APIs with tested contracts, consumed by tests rather than production. They were built speculatively for consumers that do not care about token-level deltas, but the one real consumer cares about deltas precisely so it can persist high-fidelity replay data.
streamBlocks() drags a dedicated slice of BlockAssembler behind it: flushReady() and flushRemaining() (packages/llm/llm/src/assembler.ts:138-168) plus the flushed cursor field exist only to support incremental in-order yield. generate() drags GenerateResult, BlockAssembler.result(), and the llm/generate waterfall as a second interception surface over the same underlying stream. The loop's assembler usage is push() / message() / usage / finish — not streaming flush or one-shot service assembly.
Proposal
Make stream() the only public LLM call surface:
- Remove
LlmService.streamBlocks()and its JSDoc. - Remove
LlmService.generate(), thellm/generatewaterfall event, andGenerateResultif no surviving API needs that named result shape. - Remove
BlockAssembler.flushReady(),BlockAssembler.flushRemaining(), and theflushedcursor field. - Remove
BlockAssembler.result()if it is only a helper for the deletedgenerate()service path and tests. - Replace adapter-test use of
ctx.llm.generate()with a small test helper that callsctx.llm.stream(), pushes chunks intoBlockAssembler, and returns the assembled message, usage, and finish reason needed by that test. That keeps the twin-adapter design intact while avoiding a public method whose only callers are tests. - Remove or rework the
flushReady/flushRemaining-dependent tests. Keep assembler invariants that still apply topush()/blocks()/message(); delete behavior that only pins the removed flush API. - Update every doc/comment reference to
streamBlocks,generate,GenerateResult, andllm/generateacrossdocs/, package READMEs, and source comments. Thectx.llmservice-map row in docs/architecture.md becomesstream()only, the event taxonomy dropsllm/generate, and the property-based-testing RFC names block-assembly invariants without referring to removed convenience methods.
Acceptance criteria
streamBlocks,generate,llm/generate, and the assembler helpers they alone require are gone;pnpm run knipreports no new dead exports.pnpm run test:coveragestays at 100% per-file (the deleted methods take their dedicated tests with them; no remaining line goes uncovered).- Adapter tests still exercise both real adapters through
stream()and the shared assembler, not through a test-only public shortcut. - The loop behaves identically — verified by unchanged ACP snapshot goldens.
packages/llm/llm/README.md, docs/architecture.md, and module docs no longer mention the removed convenience surfaces.
Risks
- It removes public methods from a core vocabulary package. A future plugin that wants assembled blocks without deltas would need to call
stream()and useBlockAssemblerdirectly or reintroduce a focused helper with a real consumer. Given the pre-release "foundation over speculative future" stance (AGENTS.md), this is the right time to cut test-only public shape. - Adapter tests get a little more explicit. They lose the ergonomic
generate()wrapper, but that is useful pressure: tests exercise the same streaming path production uses. - Waterfall users lose
llm/generate. No production listener exists. Any future caching/retry/logging plugin should wrapllm/stream, which remains the single provider call path.
The size is modest, but it is a clean removal of speculative surface area from the LLM package, leaving one model-call contract for both production and tests.