mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-13 03:09:14 +00:00
|
Some checks are pending
CI / test-windows (push) Waiting to run
CI / lint (push) Waiting to run
CI / build (push) Waiting to run
CI / test (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 / Native release artifact (push) Blocked by required conditions
Release / Release (push) Waiting to run
Release / Deploy docs (push) Blocked by required conditions
Release / Publish native release assets (push) Blocked by required conditions
* feat(agent-core): repair malformed tool args JSON Attempt jsonrepair when tool call arguments fail JSON.parse, then continue schema validation. Return malformed JSON errors with a concise expected schema hint so the model can retry with corrected arguments. * chore(nix): update pnpm deps hash Update the fixed-output pnpmDeps hash after adding jsonrepair so the Nix build can fetch dependencies. * refactor(agent-core): drop tool args JSON repair Stop repairing malformed tool call arguments. Fall back to an empty object on JSON parse failure and let schema validation produce the retry error, while preserving valid arguments for unknown tools in the transcript. * chore: add changeset for tool args validation |
||
|---|---|---|
| .. | ||
| errors.ts | ||
| events.ts | ||
| index.ts | ||
| llm.ts | ||
| README.md | ||
| retry.ts | ||
| run-turn.ts | ||
| tool-access.ts | ||
| tool-args-parse.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.