Skip to content

chore: merge upstream main 2026-07-26 (agent-core-v2 DI refactor) - #9

Merged
zicochaos merged 3 commits into
mainfrom
merge/upstream-2026-07-26
Jul 26, 2026
Merged

chore: merge upstream main 2026-07-26 (agent-core-v2 DI refactor)#9
zicochaos merged 3 commits into
mainfrom
merge/upstream-2026-07-26

Conversation

@zicochaos

Copy link
Copy Markdown
Owner

Related Issue

Resolve #8

Problem

Daily upstream-sync automation flagged that upstream advanced by 2 commits (tip bf8e967d5): PR MoonshotAI#2192 (per-scope keyed StateRegistry + eager scope instantiation) and PR MoonshotAI#2196 (builtin tools as Agent-scope DI services under agent/tools/). Both themes are interdependent and touch 362 files, with 6 content conflicts against the fork's subagent-model-selection and skills work — so a single merge with a manual port of fork features onto the new structure.

What changed

  • Ported subagent-model-selection (353a1c573) onto the relocated tools: schema changes in the new contract files (agent/tools/agent/agent.ts, agent/tools/agent-swarm/agent-swarm.ts), behavior in agentTool.ts / agentSwarmTool.ts (exact-alias preflight, model directory in description, approval display names via subagentApprovalAgentName, spawn binding, resume keeps the child's model). Old tool files deleted (upstream relocated them).
  • Resolved skillCatalogService.ts conflict keeping upstream's defineState/ISessionStateService structure; the fork's disabled_skills denylist, catalog reload wait (awaitPendingReloads), and disabled plugin guidance all survived — the only true conflict was the import block. Re-applied the isSkillDisabled gate in the relocated agent/tools/skill/skillTool.ts.
  • Test reconciliation: 3 conflicted test files resolved onto upstream's fixtures (scoped-service registration, real SessionStateService); all fork assertions kept. profileOps.test.ts skill-catalog stub gained onDidChange (fork subscribes to it in AgentProfileService); loop.test.ts tools inline snapshot updated (intended schema change); docs/state-manifest.d.ts regenerated.
  • Semantics verified: disabled_skills (skill-level, config-driven, filtered at listSkills source) composes with upstream's profile-driven AgentToolActivationService (tool-level) — orthogonal layers, no shadowing.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (existing fork tests ported; full suites green: agent-core-v2 4134/4134, apps/kimi-code 2411/2411)
  • Ran gen-changesets skill, or this PR needs no changeset. (upstream sync merge — fork feature changesets shipped with their original commits)
  • Ran gen-docs skill, or this PR needs no doc update. (no user-facing behavior change beyond what fork features already documented)

sailist and others added 3 commits July 26, 2026 10:10
…2192)

* refactor(agent-core-v2): instantiate all registered services eagerly at scope creation

- add instantiateAll to scope creation: every service registered for a
  scope tier is constructed when the scope is created, following the
  static dependency graph; a failing constructor fails scope creation
- drop the hand-maintained eager-resolution lists: igniteEagerServices
  in AgentLifecycleService, the force-instantiated session services in
  SessionLifecycleService, and the kosong config bridge get in bootstrap
- update DI docs and agent-core-dev skill guidance for the new semantics
- adjust affected tests (registry hygiene, timer draining, listener
  ordering) and add scope-tree coverage for eager instantiation

* feat(agent-core-v2): add per-scope keyed state container (state domain)

- add _base StateRegistry: typed StateKey/defineState descriptors with
  register/get/set, per-key onDidChange and global onDidChangeAny events,
  and BugIndicatingError on duplicate or unregistered key access
- bind thin per-scope services at each tier: IStateService (App),
  ISessionStateService (Session), IAgentStateService (Agent), so scoped
  plain-data state lives in one observable container that dies with the scope
- register the state domain in the layer check script and export the new
  services from the package index
- add StateRegistry unit tests and scoped resolution tests

* refactor(agent-core-v2): move session-scope service state into ISessionStateService

- add StateRegistry.snapshot() with JSON-safe serialization for Map/Set/Date/circular values
- migrate plain-data fields of 13 session-scope services (cron, interaction, sessionActivity, agentProfileCatalog, fs, fsWatch, log, metadata, skillCatalog, toolPolicy, workspaceCommand, workspaceContext) to defineState keys registered in sessionState
- register SessionStateService in affected tests and add test/state/stubs.ts helper

* feat(kimi-inspect): rework chat layout with session pane and tabbed right dock

- add SessionPane column next to the sidebar: Services tab (pending
  interactions + session Service panels) and State tab polling
  ISessionStateService.snapshot() every second, rendered as a live
  diff tree
- merge the transcript audit panel and the agent inspector into one
  RightPanel with Audit/Agent tabs that keep panel state across switches
- extract InteractionsCard from Inspector into its own component
- collapse multiline strings in StateTree into a compact hover-preview
  button with a viewport-clamped fixed popup
- test: cover StateRegistry.snapshot() conversions (Map/Set/circular);
  pass a session state service to SessionInteractionService in kap-server
  test fakes
- update the AGENTS.md project map for the new layout

* refactor(agent-core-v2): move agent-scope service mutable state into agentState

Register each Agent-scope service's mutable fields into the agent-state
container (IAgentStateService) via defineState keys, and access them
through get/set accessors backed by states.get/set. Promise locks,
disposables, and other mechanism-only fields stay plain instance fields.

- define per-service state keys (e.g. activityView.*, goal.*, toolDedupe.*)
  and register them in each service constructor
- replace direct field reads/writes with states-backed accessors across
  the touched services
- update the affected unit tests for the new IAgentStateService dependency

* fix(agent-core-v2): collapse class instances in state snapshots

- StateRegistry.snapshot() now stops at custom-prototype boundaries and
  emits '(ClassName)' markers, so resource graphs reachable from registered
  values (e.g. tool instances holding service references) can no longer
  exhaust the heap during export; plain data keeps recursing
- add agent-scope state test covering the full assembled agent scope
- kimi-inspect: extract the session State card into a shared StateCard and
  add an agent State tab in RightPanel polling IAgentStateService.snapshot()
- document the per-scope state container pattern in the agent-core-dev skill

* refactor(agent-core-v2): keep resource-holding state out of the state container

- move fields holding live resources (tool entries, managed tasks, turn
  jobs, prompt records, MCP registrations, profile callbacks) back to
  plain private fields so the agent state service only holds
  snapshot-safe plain data
- add gen:state-manifest script that statically collects defineState
  keys and their register call sites into docs/state-manifest.d.ts
- add state manifest freshness test and update agent-state docs

* chore: add changeset for session-scope state container

* docs(agent-core-v2): move eager-instantiation notes into the scope.ts header

* fix(kimi-inspect): suppress stale state tree while switching state owner
…I#2196)

* refactor(agent-core-v2): register agent tools as DI services with profile-aware activation

- replace module-level registerTool + Eager AgentBuiltinToolsRegistrar with registerAgentTool double registration (Agent-scope DI service + contribution table)
- add toolActivation domain: AgentToolActivationService filters contributions by the bound Profile's tool policy using declared names, resolves instances lazily via accessor.get, and re-activates on agent.status.updated
- rename BuiltinTool to AgentTool service interface; tools become Agent-scope services with decorator-injected dependencies (e.g. AgentTool -> SubagentTool/ISubagentTool)
- AgentLifecycleService.create runs one activation pass after restore and profile binding so tools reflect the Profile before the first turn
- update tool registrations, scripts, and tests; add toolActivationService tests

* refactor(agent-core-v2): centralize builtin tools under agent/tools

- move builtin tools from scattered domain folders (plan/tools,
  goal/tools, os/backends/node-local/tools, task/tools, etc.) into a
  unified agent/tools/ directory
- split each tool into a kebab-case definition file (bash.ts) and a
  registration file (bashTool.ts) pairing with its prompt markdown
- update imports across src, tests, kap-server, and TUI comments

* fix(agent-core-v2): keep agent tools out of scope-creation instantiation

Main's instantiateAll constructs every registered service at scope
creation, but agent tool constructors may legitimately throw when their
host capability is absent (e.g. WebSearchTool without a configured
provider), and profile-aware activation must stay the only resolution
path so the runtime registry holds real instances, never proxies.

- add SyncDescriptor.instantiateWithScope (default true) and let
  registerScopedService opt registrations out of the instantiateAll
  sweep
- registerAgentTool passes the opt-out, restoring lazy
  activation-driven construction on top of the eager-scope semantics
- regenerate docs/state-manifest.d.ts

* refactor(agent-core-v2): replace delayed DI with scope activation

- add explicit OnScopeCreated and OnDemand activation modes
- remove delayed proxy and idle initialization support
- migrate service registrations, tests, and DI guidance
Upstream PRs MoonshotAI#2192 (per-scope StateRegistry, eager scope instantiation) and
MoonshotAI#2196 (tools as Agent-scope DI services under agent/tools/). Ported fork
features onto the new structure:

- subagent-model-selection (353a1c5) re-applied onto
  agent/tools/agent/agentTool.ts and agent/tools/agent-swarm/agentSwarmTool.ts
  (exact-alias preflight, model directory in description, approval display
  names, spawn binding, resume keeps child model)
- disabled_skills denylist gate re-applied in agent/tools/skill/skillTool.ts;
  skillCatalogService conflict resolved keeping upstream defineState layout
  with the fork's IConfigService wiring (reload wait + plugin guidance
  survived unconflicted)
- test conflicts resolved onto upstream fixtures; profileOps skill-catalog
  stub gained onDidChange; loop tools snapshot updated; state manifest
  regenerated
@zicochaos
zicochaos merged commit b01dc62 into main Jul 26, 2026
13 of 14 checks passed
@zicochaos
zicochaos deleted the merge/upstream-2026-07-26 branch July 26, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream kimi-code — Daily Summary (2026-07-26): agent-core-v2 DI refactor

2 participants