Commit graph

562 commits

Author SHA1 Message Date
haozhe.yang
83b93eca64 feat(server-v2): port v1 terminals REST routes
- add /sessions/{session_id}/terminals routes (list/create/get/close)
  mirroring packages/server, backed by the Session-scoped ITerminalService
- add node-pty ITerminalBackend overriding the agent-core-v2 stub
- map session/terminal not-found and cwd-escape to protocol error codes
2026-06-30 14:55:05 +08:00
haozhe.yang
adaa4de0a8 feat(server-v2): port v1 /sessions/:sid/skills routes
- add GET /sessions/{session_id}/skills and POST .../{name}:activate, mirroring the v1 wire contract and protocol schemas
- gate both endpoints on activated (live) sessions via ISessionLifecycleService; when persisted but not live, return 40401 with a "you need to activate it first" hint
- resolve ISkillCatalog for listing and the main agent's IAgentSkillService for activation; map skill.not_found to 40415 and skill.type_unsupported to 40912
- export IAgentSkillService and ISkillCatalog from agent-core-v2
2026-06-30 14:30:53 +08:00
haozhe.yang
f3ebc1e2a7 feat(server-v2): port v1 session fs routes
- expose /api/v1/sessions/{sid}/fs:* mirror routes backed by the
  Session-scoped IFsService (list, read, list_many, stat, stat_many,
  mkdir, search, grep, git_status, diff, open, open-in, reveal) plus the
  fs/{path}:download stream
- extend agent-core-v2 IFsService with list/read/stat/mkdir/resolve
  methods and add fs.is_directory/is_binary/too_large/already_exists
  error codes (protocol KimiErrorCode + FsErrors)
- seed IWorkspaceContext with the session work dir in session-lifecycle
  so workspace-relative services resolve paths against the session root
- port fileLaunch lib for open/reveal/open-in
2026-06-30 14:19:18 +08:00
haozhe.yang
f6720b8c9e feat(skill): add filesystem-agnostic discovery, session-scoped
- port SKILL.md parser (frontmatter + body) from agent-core
- add ISkillCatalogStore business-specific Store so the skill domain never
  touches node:fs; File backend walks roots recursively, InMemory backend
  backs tests
- split the catalog into three scopes: IGlobalSkillCatalog (Core; builtin +
  user/brand), ISkillCatalog (Session; project skills merged by workDir),
  IAgentSkillService (Agent; activation)
- inject ISkillCatalog into AgentSkillService; make activate/activateFromModel
  async and await ISkillCatalog.ready to remove the first-activation race
- bind the File backend in the composition root and trigger loading from
  session-lifecycle
- rename SessionSkillRegistry to InMemorySkillCatalog (backs both Core global
  and Session catalogs)
- add js-yaml for frontmatter parsing
2026-06-30 14:19:18 +08:00
haozhe.yang
78320259a5 feat(agent-core-v2): add built-in file and shell tools
- add fileTools domain (Read/Write/Edit/Grep/Glob)
- add shellTools domain (Bash)
- wire registration through FileToolsService and ShellToolsService
- add readLines to IAgentFileSystem for the Read tool
2026-06-30 14:12:22 +08:00
haozhe.yang
69084ab683 refactor(agent-core-v2): move managed OAuth model refresh into OAuthService
- IOAuthService/OAuthService now owns refreshOAuthProviderModels: the managed
  OAuth provider's credential provisioning and server-side model refresh live
  together in the auth domain.
- modelCatalog is back to a read-only catalog projection (listModels,
  listProviders, getProvider, setDefaultModel); the OAuth refresh method and
  its helpers are removed.
- server-v2 /providers:refresh_oauth route and the oauth example resolve
  IOAuthService for the refresh.
- Move the refresh tests into test/auth and add the auth --> config edge to
  the DI scope diagram.
2026-06-30 14:12:22 +08:00
_Kerman
632e0a7c9f Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-06-30 12:28:48 +08:00
_Kerman
48e4c3dae7 fix: agent-core-v2 tests and background persistence options 2026-06-30 12:28:42 +08:00
haozhe.yang
9076f55643 refactor(agent-core-v2): add kaos domain for execution environment
- Add `kaos` domain (`IKaos` per session + `IKaosFactory`) wrapping
  `@moonshot-ai/kaos`, so business code imports `#/kaos` instead of the
  package directly.
- Back `agentFs` and `process` with `IKaos`; drop the per-domain
  `IFileSystemBackend` / `IProcessBackend` interfaces and their
  local/ssh stubs.
- Migrate `read-media`, `path-access`, `background/process-task`, and
  `bootstrap` off direct kaos-package imports.
- Seed `IKaos` per session in `SessionLifecycleService` and expose
  `agentFs` / `fs` on the server-v2 action map.
- Create the server-v2 main agent on demand (`ensureMainAgent`)
  instead of failing requests when it is missing.
2026-06-30 12:17:09 +08:00
haozhe.yang
d4f9933b92 fix(server-v2): serve v1 fs browse/home on distinct routes
- replace the `/fs:action` parametric dispatcher with two routes that
  mirror v1 (`/fs::browse`, `/fs::home`), so the wire path is the
  single-colon `/api/v1/fs:browse` and `/api/v1/fs:home` that v1 serves
- update the folder-picker test to hit the single-colon URLs and assert
  the double-colon form 404s, guarding against reintroducing the
  parametric dispatcher
2026-06-30 12:11:31 +08:00
haozhe.yang
90557d8eaf chore(agent-core-v2): sync agentFs barrel doc, fs test fakes, lockfile
- reword agentFs barrel doc comment to mention fs/fsService/errors
- add exitCode/dispose to fake IProcess in fs test helpers
- add ignore to pnpm-lock to match package.json
2026-06-30 11:24:14 +08:00
haozhe.yang
01509910a7 refactor(storage): give each storage role token its own FileStorageService
- bootstrap: storageSeed() now returns a per-token SyncDescriptor so
  IStorageService / IAppendLogStorage / IAtomicDocumentStorage / IBlobStorage
  each resolve to a distinct FileStorageService rooted at homeDir, instead of
  sharing one instance. Keeps the roles independently routable.
- server-v2: drop the now-redundant durableStorageSeeds and rely on bootstrap()
  for file-backed storage.
- add a regression test asserting the four tokens are distinct instances.
2026-06-30 11:06:57 +08:00
haozhe.yang
2fe629aede fix(agent-core-v2): add missing _serviceBrand and repair migrated tests
- add `_serviceBrand` to 17 DI service interfaces and 18 implementations that were missing it (red line #3)
- restore bare tool-result slice retention in normalizeToolExchanges (lost in the context-projection rewrite)
- make BackgroundTaskPersistence.listTasks skip corrupt task files
- add optional dirMode to FileStorageService so background task dirs can be 0700
- fix migrated tests: register IBlobStorage, use the 4-arg BackgroundTaskPersistence construction, add the approval stub and kaos/execute-tool fixtures
2026-06-30 10:51:35 +08:00
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