Commit graph

549 commits

Author SHA1 Message Date
haozhe.yang
4698ef36cc docs(agent-core-dev): add server-align subskill guide
- add server-align.md covering server-v2 /api/v1 mirror and /api/v2 native surfaces
- document schema-fidelity rule reusing @moonshot-ai/protocol schemas
- describe the LegacyService edge-adapter pattern for v1-only behavior
- link the subskill from SKILL.md align workflows
2026-06-30 10:32:07 +08:00
haozhe.yang
053ee9a150 feat(server-v2): add sessions tasks api/v1 endpoints
Port the v1 server's `/sessions/{sid}/tasks*` REST surface onto
agent-core-v2:

- GET /sessions/{sid}/tasks — list with optional `status` filter
- GET /sessions/{sid}/tasks/{tid} — get by id with optional
  `with_output` / `output_bytes` preview
- POST /sessions/{sid}/tasks/{tid}:cancel — cancel with the
  idempotent 40904 `{cancelled:false}` shape

The routes resolve the main agent's `IBackgroundService` through the
core -> session -> agent scope chain and project `BackgroundTaskInfo`
onto the protocol `BackgroundTask`, matching the v1 wire contract
(schemas, error codes, and messages). The `:cancel` suffix is parsed
via the shared `parseActionSuffix` helper.
2026-06-30 10:26:12 +08:00
haozhe.yang
73e97f4afd Merge remote-tracking branch 'origin/kimi-code-v2' into kimi-code-v2
Resolved the parallel kosong/tool refactors: kept the modelRuntime+model+chatProvider split and the tool contract domain (L3), adopted upstream's onContextOverflow turn hook and ToolCall unification, and ported prompt_cache_key/kimiRequestHeaders into ModelResolver.
2026-06-29 23:38:29 +08:00
_Kerman
63ee9826fc refactor: tools, handleOverflowError 2026-06-29 22:45:18 +08:00
_Kerman
223747fe7c fix: agent-code-v2 tests 2026-06-29 22:10:35 +08:00
_Kerman
7c3c66e925 fix: agent-code-v2 tests 2026-06-29 21:49:46 +08:00
_Kerman
ef2d138f97 test: add agent-core-v2 tests 2026-06-29 21:33:20 +08:00
haozhe.yang
b0c8aa8821 feat(server-v2): return turn ids for prompt actions
Return turn_id from agent prompt and steer RPC/gateway methods, route
prompt submit/steer/undo/clear/cancel through IAgentRPCService in the
server-v2 action map, and cover prompt submission and missing-agent errors.
2026-06-29 21:23:53 +08:00
haozhe.yang
6eaee09824 feat(agent-core-v2): add capability-gated read media tool
Add ReadMediaFile with image/video content handling, shared magic-byte file
type detection, and capability-based registration so the tool only appears
when the active model supports image or video input.
2026-06-29 21:23:39 +08:00
haozhe.yang
1ab0f64ff4 feat(agent-core-v2): add fs search grep git service
Add a session-scoped IFsService that backs fs search, content grep, git
status, and git diff using AgentFileSystem and IProcessRunner, with gitignore
filtering and protocol-shaped responses.
2026-06-29 21:23:26 +08:00
haozhe.yang
a3e33c13b1 feat(agent-core-v2): track workspace registry recency
Add createdAt/lastOpenedAt timestamps to registered workspaces and support
name updates so recent workspace roots can be ordered and maintained.
2026-06-29 21:23:12 +08:00
haozhe.yang
96cb9c4dc8 feat(agent-core-v2): track recently resolved interactions
Add createdAt to parked interactions and keep a bounded recently-resolved
ledger so edge transports can distinguish duplicate resolves from unknown
ids. Cover the server-v2 approval duplicate-resolve path.
2026-06-29 21:22:55 +08:00
haozhe.yang
3e4d92fc6d refactor(agent-core-v2): split model runtime from kosong domain
Replace the kosong domain with chatProvider, model, and modelRuntime
services, move model alias config and env overlay into model, and update
profile and LLM requester to resolve providers through IModelResolver and
IChatProviderFactory.
2026-06-29 21:22:41 +08:00
haozhe.yang
ec675f6c17 refactor(agent-core-v2): consolidate tool execution contracts
Move tool metadata, result, and execution hook contexts into the tool
domain, update callers to import from the new tool contract surface, and
make tool dedupe self-wiring through tool executor hooks.
2026-06-29 21:22:20 +08:00
haozhe.yang
7d04f4f7dd feat(server-v2): add fs::browse and fs::home folder picker routes
- implement GET /api/v1/fs::browse and /api/v1/fs::home, matching the
  packages/server v1 wire contract (directory-only entries, git metadata,
  dot-last sorting, parent resolution, $HOME + recent workspace roots)
- complete IHostFolderBrowser in agent-core-v2: realpath resolution, git
  detection, recent_roots from IWorkspaceRegistry, and HostFolder* domain
  errors mapped to protocol codes 40001/40409/40411
- register the routes behind a /fs:action semi-static path because
  find-my-way cannot register the literal /fs::browse / /fs::home paths
2026-06-29 21:17:43 +08:00
haozhe.yang
e083b923e5 feat(server-v2): add /api/v1 tools and MCP server routes
- GET /tools, GET /mcp/servers, POST /mcp/servers/{id}:restart
- resolve IToolRegistry / IMcpService from the most-recent session's
  main agent; empty list / 40408 when no session is live
- project v2 models to the protocol wire shapes, matching
  packages/server (source/status mapping, mcp_server_id, null input_schema)
2026-06-29 21:15:29 +08:00
haozhe.yang
55060e3942 feat(server-v2): port v1 /files routes
- add agent-core-v2 filestore domain (IFileStore) streaming blobs through IBlobStorage
- expose POST/GET/DELETE /api/v1/files (multipart upload, binary download, delete)
- map file errors to 40407/41301 envelopes; add unit + e2e coverage
2026-06-29 21:06:59 +08:00
haozhe.yang
a7a2708aee feat(server-v2): port v1 /sessions/:sid/prompts routes
- add PromptLegacyService (per-agent v1 scheduler: prompt_id, FIFO queue, steer/abort, auto-start-next) on top of IPromptService
- register prompt.not_found / session.busy / prompt.already_completed error codes in protocol and agent-core-v2
- expose GET/POST /api/v1/sessions/:sid/prompts, prompts::steer, prompts/:pid:abort|:steer
2026-06-29 20:59:02 +08:00
haozhe.yang
7c91ffc876 feat(server-v2): port v1 /sessions/:sid/questions routes
- add GET /sessions/:sid/questions (list pending) and POST
  /sessions/:sid/questions/:tail (resolve + :dismiss) on top of
  IQuestionService / IInteractionService
- enrich the agent-core-v2 question domain with the rich in-process
  model (QuestionItem / QuestionResult) and dismiss() so the v1 wire
  can be projected faithfully
- reimplement the protocol <-> in-process adapter at the edge (no v1
  agent-core import): synthesized item/option ids, allow_other,
  expires_at, and the 5-kind answer flattening
2026-06-29 20:44:28 +08:00
haozhe.yang
bca247b463 feat(server-v2): port v1 /sessions/:sid/messages routes
- add GET /sessions/{sid}/messages (paginated, role-filtered) and GET /sessions/{sid}/messages/{message_id}
- thin wrapper over the main agent's IContextMemory, already exposed in the v2 action map
- port v1 id derivation, content mapping, pagination and role-filter semantics
- register the routes under /api/v1 and cover with tests
2026-06-29 20:36:09 +08:00
haozhe.yang
420cefbc02 feat(server-v2): add model and provider catalog endpoints
- add Core-scoped IModelCatalogService in agent-core-v2 covering
  listModels, listProviders, getProvider, setDefaultModel, and
  refreshOAuthProviderModels
- expose the v1-compatible /api/v1 models and providers catalog routes
  in server-v2, mapping provider.not_found / model.not_found to the
  numeric protocol error codes
- add IOAuthService.getCachedAccessToken for provider status detection
- register provider.not_found and model.not_found protocol error codes
2026-06-29 20:10:12 +08:00
haozhe.yang
fc801c9ea0 feat(server-v2): port v1 approvals and workspaces routes
- add `/sessions/{sid}/approvals` GET (list pending) and POST (resolve)
  routes, backed by IApprovalService and IInteractionService; duplicate
  resolves return 40902 via the kernel's recently-resolved window
- add `/workspaces` GET / POST / PATCH / DELETE routes, backed by
  IWorkspaceRegistry, projecting v2 workspace records onto the v1 wire shape
- register both route groups in registerApiV1Routes
- add an agent-core-v2 interaction example that resolves the Session-scoped
  kernel and approval/question facades through the scope tree
2026-06-29 19:26:30 +08:00
haozhe.yang
f08840f4ca feat(server-v2): expose workspaces update action on v2 RPC
- map `workspaces:update` to IWorkspaceRegistry.update in the core actionMap
- cover the rename round-trip in rpc.test.ts
- sync the edge-exposure cheatsheet
2026-06-29 19:02:30 +08:00
haozhe.yang
67ccaafb69 feat(server-v2): add v1-compatible /config routes
- add GET/POST /config backed by agent-core-v2 IConfigService
- reuse protocol configResponseSchema/patchConfigRequestSchema for wire fidelity
- project resolved config generically (camelCase to snake_case); redact provider credentials to has_api_key
- split the flat POST patch into per-domain set calls and publish a config.changed DomainEvent
- wire registerConfigRoutes into /api/v1
2026-06-29 18:50:08 +08:00
_Kerman
bf0169276d fix: agent-code-v2 tests 2026-06-29 18:44:15 +08:00
_Kerman
d00e184855 fix: unify ToolCall 2026-06-29 18:02:02 +08:00
_Kerman
fd7909989a fix: agent-code-v2 re-exports 2026-06-29 17:56:37 +08:00
_Kerman
570e1524bd refactor: rename model provider service 2026-06-29 17:54:02 +08:00
_Kerman
e65023aa1d Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-06-29 17:45:40 +08:00
_Kerman
692fa75d47 fix: agent-code-v2 tests 2026-06-29 17:39:01 +08:00
haozhe.yang
e04122439b docs(agent-core-dev): add domain-boundaries topic
- add domain-boundaries.md covering scope vs domain, data-ownership test, and the session/agent/turn split conclusions
- cross-link the topic from SKILL.md, design.md, persistence.md, and service-authoring.md
- warn against I{Scope}EntityService bundles that re-merge domains by lifetime
2026-06-29 17:32:19 +08:00
haozhe.yang
c57d2f9063 feat(agent-core-v2): add domain-slice examples and runner
- add examples/ with runnable domain-slice scenarios covering scope,
  session, config, feature-flags, observability, persistence,
  session-index and wire-record
- add vitest.examples.config.ts and examples/_globalSetup.ts
  (per-run KIMI_CODE_HOME)
- add `example`, `dev:core-example` and `dev:core-example:list` scripts
2026-06-29 17:32:19 +08:00
haozhe.yang
57def298c5 chore(agent-core-v2): resync persistence layering docs/checks and prune dead code
- regenerate DI x Scope dependency graph from scripts/dep-graph.mjs output:
  add storage / bootstrap / session-metadata nodes, drop phantom records /
  environment / dynamicInjector / turnRunner nodes, and fix session-index /
  background / cron / wireRecord / blobStore / config storage edges
- fix check-domain-layers.mjs layer table (eventBus -> eventSink,
  toolDedup -> tooldedup, drop dynamicInjector, add toolExecutor>turn and
  permissionMode>contextInjector exceptions) so lint:domain passes again
- remove unused mcpCredentialsDir / defaultMcpCredentialsDir path helpers
  from the mcp oauth store (it now persists via IAtomicDocumentStore)
- correct stale persistence comments in fileStorageService and the AGENTS.md
  session example
2026-06-29 17:32:19 +08:00
haozhe.yang
f199720d39 refactor(agent-core-v2): route business persistence through the Store layer
- bootstrap seeds IAppendLogStorage + IAtomicDocumentStorage with
  FileStorageService so the Store layer is durable in the CLI
- background task state goes through IAtomicDocumentStore, output.log
  through IStorageService byte primitives
- cron task records go through IAtomicDocumentStore; the per-id-json-store
  util is deleted
- mcp OAuth credentials move to an async McpOAuthStore over
  IAtomicDocumentStore, with the provider caching eagerly so the SDK's
  synchronous getters stay non-blocking
- telemetry failed-event spool goes through IStorageService bytes
- session-index enumerates via IStorageService.list and reads state.json
  via IAtomicDocumentStore instead of hostFs
2026-06-29 17:32:19 +08:00
haozhe.yang
75a9729a6f feat(agent-core-v2): add session-scoped terminal domain
- add ITerminalService (create/list/get/attach/write/resize/close) and
  ITerminalBackend contract; Session-scoped so per-session sessionId
  threading is dropped
- implement TerminalService with per-terminal output buffering, seq replay,
  sink fan-out, and dispose-time process cleanup
- register a default NotImplementedTerminalBackend; the real PTY backend is
  supplied by the composition root
- add the terminal.not_found error code (protocol + ErrorCodes) and register
  the terminal layer in check-domain-layers
- cover the service with unit tests driven by a fake backend
2026-06-29 17:32:19 +08:00
haozhe.yang
d3a5ccc83f refactor(agent-core-v2): reroute blob store backend from host fs to storage layer
- Add IBlobStorage role token for pluggable blob backends
- Make BlobStoreService depend on IBlobStorage instead of IHostFileSystem
- Remove host filesystem dependency from WireRecordService
- Seed IBlobStorage in local and server-v2 composition roots
- Add BlobStoreService tests
2026-06-29 17:32:19 +08:00
haozhe.yang
ccfa71f0e3 feat(interaction): expose request flow over /api/v2
- add non-blocking `enqueue` and `onDidResolve` to the `IInteractionService` kernel
- add typed `enqueue` to `IApprovalService` and `IQuestionService`
- expose `interactions:request`, `approvals:request`, `questions:ask` actions
- stream pending set (`interactions`) and resolutions (`interactions:resolved`) over WS
2026-06-29 17:32:18 +08:00
haozhe.yang
e6f5183438 feat(server-v2): add RPC and WebSocket transport layer 2026-06-29 17:32:18 +08:00
_Kerman
8dbfeb2cbc fix: some tests, usage recording 2026-06-29 16:08:19 +08:00
_Kerman
13838fa144 fix 2026-06-29 15:39:39 +08:00
_Kerman
206950ab95 test: update simple agent-core-v2 test imports 2026-06-29 14:10:00 +08:00
_Kerman
1a69432dec test: copy agent tests into agent-core-v2 domains 2026-06-29 11:32:52 +08:00
_Kerman
e6a2957ac2 fix: context projection 2026-06-29 11:10:45 +08:00
haozhe.yang
f9df159c49 Merge remote-tracking branch 'origin/kimi-code-v2' into rebase/kimi-code-v2
# Conflicts:
#	packages/agent-core-v2/src/externalHooks/externalHooksService.ts
#	packages/agent-core-v2/src/loop/tool-call.ts
#	packages/agent-core-v2/src/loop/turn-step.ts
#	packages/agent-core-v2/src/loop/types.ts
#	packages/agent-core-v2/src/toolExecutor/toolExecutor.ts
#	packages/agent-core-v2/src/toolExecutor/toolExecutorService.ts
#	packages/agent-core-v2/src/toolExecutor/toolScheduler.ts
#	packages/agent-core-v2/src/turn/turn.ts
2026-06-28 19:19:48 +08:00
haozhe.yang
de1a28c902 docs(agent-core-dev): document cross-scope accessor borrow pattern
- tag `serves` consumers with inject / accessor access mechanism
- add cross-scope borrow diagram and update `session` example to use accessor
- sort minidb before migration-legacy in flake.nix workspaceNames
2026-06-28 18:53:59 +08:00
haozhe.yang
2eea427a21 refactor(agent-core-v2): rework session domain
- split session-metadata out of the untyped sessionMetaStore KV bag into a
  typed SessionMeta service (title, timestamps, archived, forkedFrom)
- make session-context carry pure seeded facts (sessionId, workspaceId,
  sessionDir, metaScope) instead of coupling identity to a persistence store
- slim ISessionService to session-level commands (archive); move fork to
  session-lifecycle and drop agent ops (compact/undo) and read views
- seed the session scope and materialize the initial metadata document on
  create; archive/close now dispose the scope tree
- add IScopeHandle.dispose so session and agent scopes tear down on close
- drop unused deps from agent-lifecycle and trim session error codes
- rename sessionIndex directory to session-index
2026-06-28 17:45:28 +08:00
haozhe.yang
4e7209394c feat(server-v2): add minimal server wired to agent-core-v2 DI
Add `packages/server-v2`, a minimal Fastify server bootstrapped through the
`agent-core-v2` DI engine (`bootstrap()` -> Core `Scope`), speaking the same
`/api/v1` interface as the v1 server. Route handlers resolve Core services
via `core.accessor.get(IXxx)`.

- Serve healthz, meta, auth, oauth (login poll/start/cancel/logout) and
  shutdown with the standard `{code, msg, data, request_id}` envelope.
- Re-point root `pnpm dev:server` to server-v2 and add a `src/main.ts`
  foreground entry.
- Add `build/hash-imports-loader.mjs` so tsx resolves `agent-core-v2`'s `#/`
  array-fallback subpath imports.
- `agent-core-v2` Phase 0 fixes so it compiles and boots: add the `event`
  domain (`IEventService`), fix `gateway` `event.subscribe` -> `event.on`, fix
  the `wireRecord` fallback `BlobStoreService` construction, export the
  `provider` barrel, and fix a `tooldedup` test import casing.
2026-06-28 17:26:39 +08:00
haozhe.yang
ca5aea91b6 feat(minidb): add embedded key-value database package
- add @moonshot-ai/minidb: pure-Node.js embedded KV store mixing
  Redis-style in-memory access with WAL + snapshot persistence
- implement core engine: codec, store, wal, snapshot, recovery,
  compaction, lockfile, skiplist
- add indexing: dt-index, compound-index, text-index/postings,
  index-manager, query engine
- add server, value-reader, crc32 utilities
- include unit/e2e tests plus fuzz/crash-recovery/soak suites and
  session-store benchmarks
- register package in flake.nix and pnpm-lock.yaml
2026-06-28 16:30:10 +08:00
haozhe.yang
a52aa78fb8 refactor(agent-core-v2): extract tool contract into tool domain
- move ExecutableTool contract (ExecutableTool, ToolExecution,
  ExecutableToolResult, ExecutableToolContext, ToolUpdate) from loop/types
  to a new tool/toolContract domain
- move tool-access into the tool domain and add a tool barrel
- group per-domain tools under tools/ (plan, skill, swarm, todoList, mcp)
- extract createMcpTool from mcpService into mcp/tools/mcp
- update domain-layer exceptions to point at the new tool domain
2026-06-28 15:11:19 +08:00
haozhe.yang
4673f50d85 refactor(agent-core-v2): split session lifecycle and session index domains
- add `session-lifecycle` (Core) owning the live session scope tree
  (create/get/list/close), extracted from `gateway`
- reshape `sessionIndex` into a backend-neutral query store
  (list/get/countActive) keyed by opaque `workspaceId`; drop fs paths
- move `encodeWorkDirKey` to `_base/utils` as the single workspace-id
  derivation, and align `workspaceRegistry` to use it
- `gateway` now injects `ISessionLifecycleService`; update dep map and tests
2026-06-28 15:05:56 +08:00