Commit graph

510 commits

Author SHA1 Message Date
haozhe.yang
262d201b00 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 05:15:01 +08:00
haozhe.yang
0875c23014 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 05:12:14 +08:00
haozhe.yang
eb3752c74f 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 04:23:03 +08:00
haozhe.yang
6173c6a97a feat(server-v2): add RPC and WebSocket transport layer 2026-06-29 01:14:14 +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
haozhe.yang
f392bcbac7 refactor(agent-core-v2): rework config and bootstrap around domain-owned sections
- add bootstrap domain as frozen startup snapshot and composition root
- replace monolithic config schema/env-model with per-domain configSection + EnvBinding (env > config.toml > default)
- remove environment module and legacy config machinery (schema, env-model, sessionConfig)
- split flag registry into IFlagRegistry contract plus scoped service
- add _base/utils/env boolean parser and provider env overlay
- rework storage atomic/file/in-memory document stores
2026-06-28 11:05:03 +08:00
_Kerman
e45771668e feat: migrate AgentTool 2026-06-27 15:41:16 +08:00
_Kerman
c037fd3518 Merge branch 'kimi-code-v2' of https://github.com/MoonshotAI/kimi-code into kimi-code-v2 2026-06-27 15:13:35 +08:00
_Kerman
94f8d1bc78 refactor: move execution resolving to toolExecutor 2026-06-27 15:13:00 +08:00
haozhe.yang
ddab6a2293 refactor(agent-core-v2): decouple persistence from filesystem via Store/Storage layering
- rename IRecordStore → IAppendLogStore and IConfigStore → IAtomicDocumentStore (name Stores by access pattern, not business)
- add IAppendLogStorage / IAtomicDocumentStorage tokens — same IStorageService interface, distinct tokens so each access pattern can bind a different backend
- add Store.acquire(scope, key) → IDisposable for flush-on-dispose; add IStorageService.readStream for streaming reads
- delete WireRecordPersistence; WireRecordService now depends directly on IAppendLogStore (preparePersistentRecord inlined, onError per-append)
- BlobStoreService now depends on IHostFileSystem (new createExclusive primitive) instead of node:fs
- rename sessionStore → sessionIndex as a domain-specific Store over hostFs
- document the "business code never persists directly" rule in AGENTS.md and the new persistence subskill
2026-06-27 14:07:42 +08:00
haozhe.yang
a9d67f4514 chore(gitignore): anchor plan/ ignore to repository root 2026-06-27 10:11:04 +08:00
haozhe.yang
790f033e20 test(auth): migrate auth tests to provider service
- replace IConfigService/PROVIDERS_SECTION stubs with IProviderService
- stub ILogService for the OAuthService provisioning path
- cover managed provider provisioning after login
2026-06-27 10:06:14 +08:00
haozhe.yang
db02c18ddc refactor(agent-core-v2): split kaos into host/agent filesystem, process and storage domains
- introduce storage domain (IStorageService/IRecordStore/IConfigStore) as the program-side persistence substrate over raw node fs
- add hostFs (local real-filesystem primitives reused by persistence and the local agent backend)
- add agentFs (IAgentFileSystem + IFileSystemBackend) and process (IProcessRunner + IProcessBackend) with local/ssh backends for the Agent execution environment
- add workspaceContext (session workspace root + path access), workspaceRegistry (process-wide catalog) and hostFolderBrowser (host-side folder picker)
- remove kaos/fs/terminal/filestore/workspace domains
- route persistence through storage (sessionMetaStore -> IConfigStore) and hostFs (sessionStore); route plan file IO through agentFs
- collect app paths in IEnvironmentService; register new domains in DOMAIN_LAYER and refresh the dependency map
2026-06-27 10:06:14 +08:00
haozhe.yang
6185ea8e89 refactor(agent-core-v2): reshape kosong domain wiring
- remove fictional IModelCatalogService / ILLMService stubs and the unused kosong config section
- add IProtocolHandlerRegistry (Core) to build protocol adapters by provider type, realizing provider != request handler
- promote ProviderManager to IProviderManager (Session, seeded) and move it into the kosong domain
- rewire IProfileService and ILLMRequester to inject IProviderManager (and IProtocolHandlerRegistry) instead of the options.modelProvider side-channel
- update DI scope docs, service-design notes, and tests
2026-06-27 10:00:53 +08:00
haozhe.yang
402ebee779 refactor(agent-core-v2): introduce session interaction kernel
- add Session-scoped `interaction` domain, a unified blocking
  request/response kernel (pending set + onDidChange) for
  human-in-the-loop requests
- rebuild `approval` and `question` as typed facades over the kernel;
  their public contracts are unchanged
- derive the full session phase (awaiting_approval / awaiting_question /
  running / idle) in `session-activity` from the kernel's pending set and
  each agent's active turn; move `SessionStatus` there
- implement `session` facade `archive()` (persist flag, remove agents,
  publish event) and brand `ISessionContext` with `_serviceBrand`
2026-06-27 09:57:22 +08:00
haozhe.yang
99bbd80925 docs(agent-core-dev): add staged development workflow docs
- orient: DI x Scope black box and file conventions
- design: domain boundaries, scope, and DI wiring
- implement: service authoring against interfaces
- verify: build and validation checks
- align / test / errors / flags / permission / service-authoring
2026-06-27 09:57:22 +08:00
_Kerman
6ba7e77b4b fix 2026-06-26 22:25:37 +08:00
_Kerman
16841c16c1 fix: refine interfaces 2026-06-26 22:21:26 +08:00
_Kerman
98aa76d83e fix: refine interfaces 2026-06-26 22:02:57 +08:00
_Kerman
54a20040bf fix: refine interfaces 2026-06-26 21:42:10 +08:00
_Kerman
24137a5638 fix: refine interfaces 2026-06-26 21:15:32 +08:00
_Kerman
85755b902e fix: refine interfaces 2026-06-26 21:06:12 +08:00
haozhe.yang
98e88a91ac refactor(config): load real config.toml and distribute section schemas
- ConfigService now reads/writes real config.toml: snake_case↔camelCase
  transforms, lossless raw round-trip, KIMI_MODEL_* env overlay, and
  lenient load diagnostics.
- Add IConfigRegistry.onDidRegisterSection so late-registered sections are
  validated, get defaults applied, and fire onDidChange.
- Move section schemas to their owner domains: providers→provider,
  experimental→flag, thinking→profile, loopControl→loop,
  McpServerConfig→mcp.
- profile/loop/llmRequester read config through IConfigService instead of
  the dangling KimiConfig options.
- Add the agent-core-dev config topic (section ownership + TOML format).
2026-06-26 16:20:07 +08:00
haozhe.yang
11e6553553 feat(agent-core-v2): add workspace registry and fs services
- port IWorkspaceRegistry (Core) backed by <homeDir>/workspaces.json
- port IWorkspaceFsService (Core) host-fs folder-picker backend
- rename IWorkspaceService to ISessionWorkspaceService (Session)
- extend ISessionStore with sessionDir/workspaceIdFor/countActiveSessions
  and drop the unused read/write stubs
- add workspace.not_found, fs.path_not_found, fs.permission_denied and
  validation.failed to protocol KimiErrorCode
- update the DI scope map and allow the workspace>event layer exception
2026-06-26 15:36:03 +08:00
haozhe.yang
a7761e0583 feat(agent-core-v2): add cloud and console telemetry appenders
- rename TelemetryClient to ITelemetryAppender and noopTelemetryClient to nullTelemetryAppender (vscode-style); add addAppender/removeAppender/setAppender/setEnabled/flush/shutdown to ITelemetryService
- TelemetryService fans track out to all appenders with per-appender error isolation via onUnexpectedError; withContext shares appenders and inherits enabled state
- add ConsoleAppender (dev echo) and CloudAppender + CloudTransport: HTTP POST to telemetry-logs.kimi.com with Bearer auth, retry, and on-disk fallback, decoupled from @moonshot-ai/kimi-telemetry
- document telemetry usage (inject/track/context/appenders/bootstrap) in the agent-core-dev skill
2026-06-26 15:22:09 +08:00
haozhe.yang
ae1e61c5a2 refactor(agent-core-v2): route tool execution gates through turn hooks
- add onWillExecuteTool / onDidExecuteTool HookSlots to ITurnService
- remove loop prepareToolExecution / authorizeToolExecution / finalizeToolResult hooks
- externalHooks, permission, tooldedup now register on turn.hooks
- drop Turn lifecycle scope; tooldedup moves to Agent scope
- delete PreToolCallHookPermissionPolicyService (now a turn hook)
2026-06-26 15:07:01 +08:00
haozhe.yang
3fd5cb9729 feat(agent-core-v2): add provider domain and route auth through it
- add provider domain with IProviderService CRUD over the providers config section
- refactor OAuthService and AuthSummaryService to read and write providers via provider
- add ConfigService.replace for whole-section writes used by provider delete
- move provider/OAuth schemas from auth/oauthSchemas into the provider domain
- update DI scope diagram and domain layer map; remove the Turn scope
2026-06-26 14:46:23 +08:00
haozhe.yang
7c2bcc14c6 refactor(agent-core-v2): tighten DI instantiation and domain layering
- expand domain-layer map and add L3/L4 type-sharing exceptions
- resolve bare domain imports (e.g. `#/turn`) via targetDomainOf
- add `_serviceBrand` to externalHooks/permissionMode/permissionRules/profile services
- mark injected constructor deps private readonly (cron/flag/goal)
- build permission policies via instantiation.createInstance
- add HookSlot.run and a cross-package `#/` import resolver for vitest
- reorganize tests, add config/permissionRules/sessionStore coverage, drop legacy records tests
2026-06-26 13:14:37 +08:00
haozhe.yang
aa776246dc chore(agent-core-v2): merge before-rebase-v2 into HEAD
Resolve merge conflicts by keeping the HEAD (kimi-code-v2) architecture
as the base and adopting compatible increments from before-rebase-v2:

- adopt auth OAuth flow, structured log domain, telemetry sinks,
  workspace service, and the file-backed config service
- migrate IAgentConfigService to the Session-scoped ISessionConfigService
- keep HEAD's turn/agent-lifecycle/permission domains and the removed
  tool/message/records domains, since before-rebase-v2's versions depend
  on domains (context/injection/tool/records) that HEAD has removed
- repair auto-merge fallout: dedupe auth vs config schema exports,
  restore cwd/chdir on AgentKaos, retarget records imports to
  sessionMetaStore, and revert THEIRS test files that no longer match
  HEAD's src

Note: agent-core-v2 typecheck already fails on HEAD (138 errors); this
merge introduces no new error types (132, a subset of HEAD).
2026-06-26 01:27:18 +08:00
haozhe.yang
3122e0803a feat(agent-core-v2): flesh out auth, config, telemetry and workspace services
- auth: device-code OAuth flow (startLogin/getFlow/cancelLogin),
  resolveTokenProvider, provider config schemas, ensureReady,
  AUTH_LOGIN_REQUIRED error code
- config: schema-driven registry (validate/merge/defaultValue/diagnostics),
  reload/getAll/ready, new Session-scoped ISessionConfigService replacing
  IAgentConfigService, pure helpers in configPure
- telemetry: multi-sink fan-out with flush/shutdown, add ConsoleSink,
  CloudSink and CloudTransport
- workspace: Session-scoped IWorkspaceService (workDir/additionalDirs,
  resolve/isWithin/assertAllowed) replacing the registry/fs split
- kaos: add cwd/chdir; gateway: add flushLogs/flushGlobalLogs
- docs: add Permission design doc, refresh service-design and
  di-scope-domains for ISessionConfigService
- update kosong/tool/gateway consumers and tests to ISessionConfigService
2026-06-26 00:32:38 +08:00
haozhe.yang
f6c2c513dc feat(agent-core-v2): migrate structured logging into log domain
- add logfmt formatter with redaction, truncation and ANSI coloring
- add rotating file writer plus a Session-scoped file writer service
- add env-driven logging config and ILogOptions seed
- add Session-scoped ISessionLogService and flush on ILogService
2026-06-26 00:23:37 +08:00
_Kerman
fef2b880c8 fix: agent-core-v2 2026-06-26 00:22:40 +08:00
_Kerman
f52248f5a5 fix: agent-core-v2 2026-06-25 23:52:54 +08:00
_Kerman
86f721f76f fix: agent-core-v2 2026-06-25 23:40:01 +08:00
_Kerman
fb3e4253d5 fix 2026-06-25 23:30:17 +08:00
haozhe.yang
67810a822f refactor(agent-core-v2): rework DI test services and decompose turn domain
- rework createServices around ServiceRegistration groups (base + additionalServices) and add per-domain register*Services stubs
- extract loopRunner, toolCallExecutor and turnEvents out of turnService; switch turn lifecycle to typed events
- add AsyncEmitter / IWaitUntil / handleVetos to _base/event for interceptable onWill and veto events
- document DI x scope (docs/di.md, docs/service-design.md, scope-domain diagram) and refresh di-testing.md
- ignore plan/
2026-06-25 23:10:24 +08:00
_Kerman
75e030173d fix 2026-06-25 22:55:05 +08:00
_Kerman
1e031182f9 chore: remove IMessageService 2026-06-25 19:01:00 +08:00
_Kerman
b21d8820d1 fix: move files, fix types 2026-06-25 18:58:27 +08:00
_Kerman
2014198b73 fix: types, copy mcp deps 2026-06-25 18:42:26 +08:00
_Kerman
6c7a000dee fix: types, dedupe services 2026-06-25 18:35:57 +08:00
_Kerman
41d7e029e0 fix types 2026-06-25 18:00:23 +08:00
_Kerman
50b501c8bb fix types 2026-06-25 17:58:12 +08:00
_Kerman
3cd3edb47c fix: dedupe turn 2026-06-25 17:51:55 +08:00