mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-10 17:29:18 +00:00
|
Some checks are pending
CI / build (push) Waiting to run
CI / test (push) Waiting to run
CI / lint (push) Waiting to run
CI / typecheck (push) Waiting to run
Nix Build / Check flake.nix workspace sync (push) Waiting to run
Nix Build / nix build .#kimi-code (push) Blocked by required conditions
Release / Release (push) Waiting to run
Release / Deploy docs (push) Blocked by required conditions
Release / Native release artifact (push) Blocked by required conditions
Release / Publish native release assets (push) Blocked by required conditions
|
||
|---|---|---|
| .. | ||
| errors.ts | ||
| events.ts | ||
| index.ts | ||
| llm.ts | ||
| README.md | ||
| retry.ts | ||
| run-turn.ts | ||
| tool-access.ts | ||
| tool-call.ts | ||
| tool-scheduler.ts | ||
| turn-step.ts | ||
| types.ts | ||
Loop
loop is the stateless agent loop. It does not own sessions, wire
transport, compaction execution, permissions UI, or durable protocol
bridging. Those are host-layer responsibilities.
Internal Owners
run-turn.tsowns turn-level convergence: abort and compaction safe points, max-step enforcement, usage aggregation, optional continuation after non-tool stops, and finalTurnResultmapping.turn-step.tsowns one provider step: pre/post step hooks, message construction, the atomic step envelope, LLM call, streaming callback wiring, and the handoff to the tool-call lifecycle.tool-call.tsowns the tool-call batch lifecycle. Classification is pure; preparation dispatches recordedtool.callevents in provider order; terminaltool.resultevents are recorded in provider order beforestep.endseals the step.tool-scheduler.tsowns stateful tool execution scheduling: tasks with non-conflicting resource accesses may overlap, while conflicting tasks are serialized at provider-order boundaries.llm.ts,events.ts, andtypes.tsdefine the narrow model, event/transcript, message, and tool surfaces that hosts provide to the loop.
Contracts
- The core loop must not import from host-layer implementations.
LLMis the only source of model metadata, optional capability metadata, and system prompt.buildMessagesbuilds the latest model-visible messages per model step.dispatchEventis the only event path the loop writes to. The dispatcher recordsLoopRecordedEvents, publishesLoopLiveOnlyEvents, and routes shared events such asstep.begin,step.end,tool.call, andtool.resultto both transcript and live listeners.- Live event listener failures are contained by
LoopEventDispatcherand must not affect the agent loop. - Provider usage is recorded immediately after
LLM.chatreturns, not after tool execution completes. Aborted tool execution must still report spent LLM usage. - The transcript step envelope is intentionally partial on provider abort:
step.beginmay exist withoutstep.end. - Every dispatched
tool.callmust be followed by a matchingtool.resultunless the step is interrupted before the result dispatch point.
Test Boundaries
The main regression guards live in test/loop:
turn-lifecycle.e2e.test.tscovers turn convergence and usage aggregation.transcript.e2e.test.tscovers step ordering and durable transcript linkage.tool-call.e2e.test.tsandhooks.e2e.test.tscover tool preparation, description, result finalization, and hook safety points.abort.e2e.test.ts,error-paths.e2e.test.ts, andevents.e2e.test.tscover abort convergence, error propagation, and live event containment.streaming.e2e.test.tscovers provider streaming callback wiring.