Commit graph

908 commits

Author SHA1 Message Date
7Sageer
e181cb5f44 Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-07-06 20:22:11 +08:00
haozhe.yang
2ec070b1b2 refactor(agent-core-v2): scope wire records per agent as wire.jsonl
- replace the shared 'wire' append-log keyed by a hashed homedir with a
  per-agent wire.jsonl beneath each agent's homedir
- add WIRE_RECORD_FILENAME and wireRecordScope(homedir, homeDir); drop
  wireRecordPersistKey
- update session fork and agent wire wiring to the new scope/filename
- add one-off resume round-trip and debug tests over real wire logs, plus
  a cross-scope ILogService resolution test
2026-07-06 20:21:12 +08:00
haozhe.yang
dd3c7222a7 refactor(agent-core-v2): route context writes through 1.4 ops and declared tool delivery
- contextMemory: emit 1.4 ops (append_message/clear/apply_compaction/undo) on the live write path; demote context.splice to legacy (replay + rare single-deletes); drop context.append_loop_event; share computeUndoCut between reducer and service; extend contextBlobSelector to append_message records
- prompt: consume tool result `delivery` via onDidExecuteTool and perform the steer at L4, stripping the side channel before it reaches the loop; delegate undo/clear/append to context service
- skill tool: stop reaching into IAgentPromptService; declare a `delivery: steer` on the result for the agent layer to consume
- tests: update stubs/snapshots, add delivery threading coverage, drop obsolete v1.4->v1.5 migration test, clarify several test titles
- also includes a saved session transcript at repo root
2026-07-06 20:20:11 +08:00
haozhe.yang
f851cc4776 refactor(agent-core-v2): migrate service hooks to IEventBus events
- replace OrderedHookSlot-based hooks (turn onLaunched/onEnded, context onSpliced, permission approval request/resolve, task onDidNotify, fullCompaction onDidCompact, toolRegistry register/unregister) with IEventBus domain events
- add contextMemory named primitives (append/clear/undo/applyCompaction) on wire-protocol 1.4 ops, retaining splice for replay and rare single-deletes
- update externalHooks, goal, swarm, compaction, context-injector, micro-compaction, and task-notification to subscribe to the new events
- drop removed hook slots from the turn and task test stubs
2026-07-06 20:18:53 +08:00
7Sageer
935f5c5f5d fix: align v2 oauth web search cleanup 2026-07-06 19:53:58 +08:00
7Sageer
f54ebe0499 fix: resolve v2 model capabilities and headers 2026-07-06 18:49:26 +08:00
haozhe.yang
98fdb3fc06 docs(write-tests): require behavior/condition/outcome in it() names
- test names must encode behavior, condition, and expected outcome
- use spaces instead of Java-style underscores in it() strings
- add good/bad naming examples
2026-07-06 18:30:32 +08:00
haozhe.yang
34c7d3d1d4 refactor(agent-core-v2): retire wire signal channel in favor of IEventBus
- delete wire/signal.ts and drop signal() from IWireService, WireService, and the WireEmission union (now record-only)
- remove SignalMap augmentations and wire.signal() calls across loop, mcp, goal, plan, task, skill, usage, swarm, fullCompaction and other domains
- re-scope IEventBus to per-agent (Agent scope) and keep IEventService as the global channel, re-exported as GlobalEvent
- route Op-derived facts through IEventBus via op toEvent; keep onEmission for the live append-log record stream
- update server-v2 ws transport (eventMap, sessionEventBroadcaster) and affected tests
2026-07-06 18:30:32 +08:00
haozhe.yang
d2b5e173cf feat(agent-core-v2): add minidb read model for session index
- implement IQueryStore over minidb (lazy open, openOrRebuild, App scope)
- FileSessionIndex serves list/get/countActive from the read model behind the
  persistence_minidb_readmodel flag, backfilling on cold miss to drop the
  per-session state.json re-read (N+1)
- SessionMetadata mirrors updates into the read model for single-process
  freshness; create/fork backfill on first read
- allow sessionIndex>flag in the domain-layer exceptions
- add unit tests plus shared flag/persistence stubs
2026-07-06 18:30:32 +08:00
haozhe.yang
6d1cb3ab23 feat(agent-core-v2): add IEventBus and Op.toEvent alongside wire.signal
Phase 1-2 of the wire/event decoupling plan.

Phase 1 (infra, pure addition): introduce IEventBus (src/app/event/eventBus.ts + eventBusService.ts, App-scope, full + per-type emitters) and an optional Op.toEvent(payload, state) that WireService publishes to IEventBus after apply+persist on dispatch (replay stays silent). Add eventBus.test.ts and store-event.test.ts.

Phase 2 (per-service, dual-channel): every domain now derives/publishes its events to IEventBus - Op-companioned signals via *Ops.toEvent (skill/task/turn/swarm/plan/usage/contextSize/fullCompaction), transient and live-snapshot events via eventBus.publish (turn/goal/loop/toolExecutor/mcp/rpc/externalHooks/profile/session). Each domain adds a DomainEventMap augmentation while keeping its SignalMap.

wire.signal/onEmission are intentionally KEPT in this phase: PLAN.md runs onEmission and EventBus in parallel through Phase 1-2, and server-v2's WS event map forwards only signal emissions (ignoring records), so the consumer cutover and the signal/onEmission deletion are deferred to Phase 3. wire.signal count is unchanged (49); eventBus.publish (34) and toEvent (12) are additive.

Two deviations from the appendix for parity: compaction.cancelled and compaction.completed are manual eventBus.publish (resume must stay quiet, and the complete Op payload strips summary), not toEvent.
2026-07-06 18:30:32 +08:00
haozhe.yang
0ec26c5378 test(agent-core-v2): fix tests after wire/op state engine migration
- migrate imports of removed modules (eventSink, chatProvider, modelRuntime, execContext, completion-budget)
- register IAgentWireService and seed ILogOptions/IAgentBlobService/IHostEnvironment in the test harness
- rewrite toolDedup tests against the hook-driven model; migrate modelRuntime tests to IModelResolver
- drop stale wire-record time assertions; remove dead chatProviderFactory test and modelRuntime stubs
- fix v1.4 to v1.5 migration dropping string-typed turnId (restore Number coercion)
2026-07-06 18:30:32 +08:00
haozhe.yang
06dbd23c0f feat(agent-core-v2): introduce derived wire models and ReplayTimelineModel
- add defineDerivedModel/DerivedModelDef and wireService.attach() so models
  can fold heterogeneous ops via reducers during both dispatch and replay
- add ReplayTimelineModel as the v2 replacement for v1 imperative ReplayBuilder,
  folding context/goal/plan/profile/permission ops into one ordered timeline
- drop per-op toReplay/ReplayPayload projection; DTO mapping is now read-time
- coerce v1.5 migration turnId via Number() before integer check
2026-07-06 18:30:32 +08:00
7Sageer
b1103bb343 fix(server-v2): broadcast interaction question/approval events over v1 WS
The v1-compat SessionEventBroadcaster only forwarded agent wire signals
and model catalog events, so pending questions and approvals created via
the session interaction service never reached v1 WS clients (kimi-web)
in real time — they only appeared after a page refresh via the REST
snapshot. Subscribe to ISessionInteractionService per session and
synthesize durable event.question.requested/answered/dismissed and
event.approval.requested/resolved envelopes through the existing
seq/journal/fan-out pipeline.
2026-07-06 16:34:38 +08:00
7Sageer
1508b4f62b feat(agent-core-v2): filter dep-graph viewer via URL query params
Read domain/scope/kind/search/hideOrphans/groupByScope/focus from location.search at mount to seed the initial filter state and pre-select a node. Lets deep-links open the graph on a specific slice (e.g. ?domain=session&scope=Session&kind=ctor). Parsed values are validated against the known scope/kind vocabularies; the mapping is one-way: interaction does not write back to the URL.
2026-07-06 16:16:30 +08:00
haozhe.yang
a5fa4477b6 docs(skills): add write-tests skill for black-box example tests 2026-07-06 16:01:10 +08:00
_Kerman
5dd08b2426 refactor(agent-core-v2): simplify PermissionApprovalResultContext 2026-07-06 15:58:35 +08:00
_Kerman
bf5d7faa0c Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-07-06 15:57:31 +08:00
7Sageer
4aa50c0de9 feat(agent-core-v2): track mcp_connected/mcp_failed telemetry 2026-07-06 15:23:04 +08:00
7Sageer
4b84de2093 fix(agent-core-v2): align mcp media output with v1 2026-07-06 15:02:10 +08:00
haozhe.yang
7544de5d72 refactor(agent-core-v2): introduce wire model/op state engine
- add wire/ L2 domain: defineModel/defineOp primitives, OP_REGISTRY with DuplicateOpError guard, IWireService + WireService (dispatch/replay/signal/flush) and per-scope tokens
- extract per-domain *Ops + Models (goal, plan, profile, task, turn, usage, full/micro compaction, permission mode/rules, skill, swarm, tool state, user tool, context memory/size, cron, todo); services shrink to pure apply + wire dispatch
- drop legacy agent/record service superseded by the wire engine; dissolve llmProtocol/kosong into llmProtocol
- propagate wire emissions through protocol events and the server-v2 WS broadcaster
- add *-wire, store, and op-uniqueness lint tests; update existing tests and di-scope docs
2026-07-06 14:43:33 +08:00
7Sageer
bba9f4489f fix(server-v2): treat loopback origins as same-origin for WS upgrade
A browser behind a same-machine dev proxy (e.g. Vite on localhost:5175)
sends Origin localhost while the upstream server is bound to 127.0.0.1;
the two are not string-equal so the WS upgrade was rejected with 403.
Treat loopback<->loopback (localhost / 127.0.0.1 / [::1] / *.localhost)
as same-origin. Public cross-origin is unchanged, auth (401) is unchanged.
2026-07-06 14:17:03 +08:00
7Sageer
cb7be13f9a fix(server-v2): honor before_id cursor in GET /sessions pagination
Apply before_id/after_id id-cursors and page_size in the route handler
(FileSessionIndex does not implement a cursor, so page over its
recency-sorted result). Unknown cursor resolves to an empty terminal
page so clients cannot spin on a cursor the server cannot advance,
which caused the boot-time request storm on GET /api/v1/sessions.
2026-07-06 14:17:03 +08:00
haozhe.yang
82d7718ef5 fix(agent-core-v2): register TodoListTool via registerTool to break self-cycle
SessionTodoService (Session scope, eager) created TodoListTool with
createInstance inside bindAgent, which also ran from the constructor
catch-up loop. TodoListTool injects ISessionTodoService, so when an agent
already existed this re-entered the in-progress SessionTodoService and
threw a sessionTodoService -> sessionTodoService CyclicDependencyError.

Contribute TodoListTool through the module-level registerTool used by every
other builtin; AgentBuiltinToolsRegistrar instantiates it per agent on the
Agent scope, where the parent ISessionTodoService is already constructed.
SessionTodoService now only binds the stale-todo reminder and the main
agent todo.set resumer.
2026-07-06 11:29:26 +08:00
haozhe.yang
2f625b7b3e refactor(agent-core-v2): drop execContext domain, fold cwd into ISessionContext
- move the session's seeded cwd onto ISessionContext (set in sessionLifecycle)
  and delete the IExecContext value plus the session/execContext domain
- remove the dead envLayers/withEnv/withCwd surface; the process runner keeps
  only per-call options.env, matching v1 Kaos behaviour (no producer ever
  populated layers)
- drop the unused IExecContext injection from rpcService
- remove the public execContext re-export (no in-repo consumers) and update the
  layer map, the DI x Scope diagram source, and tests/harness (cwd now via
  TestAgentOptions.cwd)
2026-07-06 10:52:32 +08:00
haozhe.yang
c225a60f86 refactor(agent-core-v2): drop unwired session warning service
- remove ISessionWarningService/SessionWarningService skeleton, its barrel and test; the server-v2 warnings route already returns [] and nothing in v2 wired the service
- relocate SessionErrors codes to src/session/errors.ts so the redundant session/session/ directory is gone, and update the errors facade and package index exports
2026-07-06 09:12:43 +08:00
haozhe.yang
4a99a8dffe refactor(agent-core-v2): move edit capability to app scope and colocate EditTool
- add App-scope IFileEditService (textModel/editService/fileEdit) over IHostFileSystem, returning a domain-neutral FileEditResult
- turn EditTool into an Agent-scope adapter registered under app/edit/tools, injecting IFileEditService and mapping FileEditResult to ExecutableToolResult
- migrate edit tests to build EditTool through the container
2026-07-06 08:51:02 +08:00
haozhe.yang
8ec5f1901f refactor(agent-core-v2): rename agentFs domain to sessionFs
The Session-scoped fs facade backs the Web UI edge surface
(/api/v1 fs routes and /api/v2 fs:* actions), not the Agent -- the
Agent uses the os file tools instead. The `agentFs` name was a
leftover from when the interface was IAgentFileSystem.

- rename src/session/agentFs -> src/session/sessionFs (and tests)
- update #/session/agentFs imports and the 'agentFs' domain string
- update check-domain-layers entries, header/cross-ref comments, docs
- rename the misleading planService `agentFs` field to `hostFs`
  (it is an IHostFileSystem)
2026-07-06 08:43:27 +08:00
haozhe.yang
6ff2f62035 refactor(log): unify logging under _base/log as per-scope ILogService
- move logging to _base/log (contract, plain sinks, BoundLogger, AppLogService);
  drop Service suffix from new-able classes (RotatingFileWriter/FileLogWriter)
- single ILogService token: App and Session each bind an implementation, so
  consumers inject @ILogService and the scope picks the sink; remove
  ILogWriterService and ISessionLogService
- App log defaults to the global rotating file (fixes TUI console pollution and
  the ignored KIMI_LOG_LEVEL), with every sink routed through the redacting formatter
- Agent scope falls back to the Session logger (multiple agents share one session
  log file, so a single sink avoids rotate races)
2026-07-06 07:04:40 +08:00
_Kerman
95c7d99c11 Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-07-05 20:01:18 +08:00
haozhe.yang
ac9f528fd8 refactor(agent-core-v2): re-layer skill catalog around discovery + sink
- merge ISkillDiscovery into a single discover(roots); Global and Project
  differ only by which roots are passed (root resolution moved to
  userRoots/projectRoots, reusable without a Session)
- replace IGlobalSkillCatalog with pluggable ISkillSource producers
  (builtin/user at App, workspace/plugin at Session) that push into the
  Session skill sink
- SessionSkillCatalogService is now a priority-ordered merge sink
  (plugin > workspace > user > builtin) with ready/onDidChange, plus
  set/remove for future ad-hoc sources; fixes builtin wrongly winning
  name collisions over user
- renderSkillPrompt takes sessionId as an argument instead of baking it
  into the merged catalog value
- rename globalSkillCatalog -> skillCatalog; update the DI x Scope puml
  and the domain-layer map
2026-07-05 18:58:58 +08:00
haozhe.yang
66e766e0e0 refactor(agent-core-v2): unify storage layer on IFileSystemStorageService
- collapse Storage role tokens (IStorageService/IAtomicDocumentStorage/
  IAppendLogStorage/IBlobStorage) onto the single IFileSystemStorageService
  byte layer, with Store facades (append-log, atomic document, blob) above it
- rename AtomicDocumentStore to JsonAtomicDocumentStore and update IBlobStore
  references in server-v2
- add gen:contract-types script and tsconfig.contract.json for generating
  contract types, and ignore the .contract-types-tmp build dir
- document the storage read/write model in docs/rw-model-design.md and refresh
  the dep-graph analyzer and agent-core-dev skill docs
- update test stubs and server-v2 start/files to match
2026-07-05 13:47:04 +08:00
_Kerman
641a16618f refactor: move task notification XML renderer 2026-07-04 22:02:07 +08:00
_Kerman
9a869d94ad style: normalize agent-core-v2 service interface layout
Align all DI service contracts on _serviceBrand first, a blank line, methods and properties, then hooks last when present.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 17:54:21 +08:00
_Kerman
14e3c769f3 refactor: objectify agent loop run options 2026-07-04 17:30:38 +08:00
_Kerman
0d9d91f584 fix: remove TurnStartedEvent.origin 2026-07-04 17:23:52 +08:00
_Kerman
c0c9f155da fix: restore prompt id in server-v2 snapshots 2026-07-04 17:14:50 +08:00
_Kerman
8705d502f0 refactor: remove PromptOrigin from IAgentTurnService.launch
Turn origin is tracked on context messages instead; drop it from the turn launch API and wire records.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 17:03:45 +08:00
_Kerman
0d8b9f96ef refactor: remove promptMessageId from turn lifecycle
Turn no longer carries or emits the triggering message id; prompt and goal
callers keep message identity in context memory instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 16:24:17 +08:00
_Kerman
b71b2d20c2 refactor: ExecutableToolResult 2026-07-04 15:53:37 +08:00
_Kerman
86a7db1b35 refactor: remove lastEndedReason 2026-07-04 15:43:26 +08:00
_Kerman
14b5d581d8 refactor: promptService 2026-07-04 15:36:05 +08:00
_Kerman
589c6b6cf0 fix: rework steer 2026-07-04 15:32:17 +08:00
_Kerman
2471ae088f feat: simplify turn service 2026-07-04 15:04:06 +08:00
_Kerman
95901922e4 refactor: simplify loop and turn 2026-07-04 14:15:06 +08:00
_Kerman
4c2c3956fe refactor: generalize loop error recovery hook 2026-07-04 13:49:22 +08:00
_Kerman
58516f4900 feat: allow multi-shot hook 2026-07-04 13:11:40 +08:00
_Kerman
cc53ae6dd7 refactor: unify turn continuation handling 2026-07-04 12:22:14 +08:00
haozhe.yang
f060872ffc Merge remote-tracking branch 'origin/kimi-code-v2' into kimi-code-v2 2026-07-04 09:08:14 +08:00
haozhe.yang
b3ac27e79a refactor(agent-core-v2): make todo session-shared and wire-only
- move todo from agent scope (`IAgentTodoListService`) to session scope
  (`ISessionTodoService`); the list is now shared across every agent in a
  session instead of per-agent.
- persist every change as a `todo.set` record on the main agent's wire, which
  is the single source of truth and a replayable timeline; drop the agent
  tool-store `'todo'` key and the atomic-doc persistence store.
- bind `TodoListTool` and the stale reminder into every agent via
  `IAgentLifecycleService`, and register the `todo.set` resume resumer on the
  main agent.
- migrate `fullCompaction` to read `ISessionTodoService`; register the `todo`
  domain at L4 with a `todo>agentLifecycle` layer exception; refresh the DI
  scope/domain diagram.
2026-07-03 23:30:55 +08:00
_Kerman
483fc99696 Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-07-03 22:59:50 +08:00