Skip to content

feat(agent-core-v2): add the L3 unit layer and the Feature seam - #2678

Merged
sailist merged 5 commits into
MoonshotAI:mainfrom
sailist:feat/agent-core-v2-feature-seam
Aug 6, 2026
Merged

feat(agent-core-v2): add the L3 unit layer and the Feature seam#2678
sailist merged 5 commits into
MoonshotAI:mainfrom
sailist:feat/agent-core-v2-feature-seam

Conversation

@sailist

@sailist sailist commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained in the next section.

Problem

agent-core-v2 (the DI × Scope engine behind kap-server) gained its L0 ledger and L2 cascade engine in #2551, but scoped services were still plain constructor-injected registrations: a service could not provide other tokens, effects, or event subscriptions as one retractable unit; there were no contribution points for extending built-in domains (tools / agent profiles / config sections / wire vocabulary / commands) at runtime; and there was no introspection surface over the live container tree. Built-in capabilities such as plan mode were hard-wired into the agent domain instead of being composable, retractable features.

What changed

  • L3 Service/Fiber unit layer (src/_base/di/): the Service base class with this.provide/effect/on/get/ref capabilities and two-phase construction, thenable FiberHandles (state / uid / update / dispose), collection<T> contribution tokens folded by consumer services, and the per-scope-kind ScopeUnits materialization fold.
  • Atomic scope registration: each scope's whole registerScopedService batch lands as ONE cascade transaction via provideAll — waiting-area activation, sticky Failed on construction error, seeds override static registrations.
  • DI unit inspection surface: App-scope IDebugLedgerService / IDebugGraphService / IDebugCascadeService (unit tree, dependency DAG, cascade history, waiting area) served over the /api/v1/debug reflection, plus the kimi-inspect DI view with unprovide / update / dispose triggers.
  • Feature unit seam (src/features/, src/app/feature/): IFeatureManager assembles / updates / retracts dynamic units at runtime; plan mode is ported from agent/plan + agent/tools/plan onto the seam as the first Feature; the contributed-command seam (agent/command/, folded by IAgentCommandService) is surfaced through the node-sdk RPC types.
  • Removed the legacy dep-graph tooling (scripts/dep-graph/).
  • Applied the header-only comment convention across src and test: non-header narration stripped; file headers, tooling pragmas, and NOTE: comments kept.

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 (unit layer, feature seam, command seam, debug surface, and session seed adapters each gained suites under packages/agent-core-v2/test/).
  • Ran gen-changesets skill, or this PR needs no changeset — no changeset: the changes are agent-core-v2 internals and dev tooling (kimi-inspect), not user-perceivable in the CLI.
  • Ran gen-docs skill, or this PR needs no doc update — no user-facing CLI behavior change.

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1598480

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f4825dd7c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +209 to +211
private removeContribution(contribution: ConfigSectionContribution): void {
if (!this.foldDomains.delete(contribution.domain)) return;
this.unregisterSection(contribution.domain);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refold config contributions before unregistering

When two live units contribute the same config section (the fold treats identical duplicates as silent in registerSection), removing either record deletes the domain from foldDomains and unregisters the section even though another provider's record is still visible. That leaves the remaining feature/plugin's config as an unknown raw TOML section until it is re-added; refold or count surviving records instead of keying ownership by a single domain bit.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L15-L15

Useful? React with 👍 / 👎.

Comment on lines +583 to +586
update: async () => {
await book.clear('unload');
try {
run();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply config updates to function units

For function/object recipes, FiberHandle.update(config) silently ignores the caller's new config because this callback accepts no argument and reruns with the closed-over initial config/facade. Any managed function unit updated through IFeatureManager.updateUnit(name, config) or a stored handle will restart with stale settings, unlike class and token units that revalidate and apply the new config.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L14-L14

Useful? React with 👍 / 👎.

Comment on lines +374 to +378
update: async () => {
await entry.dispose();
if (this._book.isActive) {
this._book.effect(body, label ?? `effect:${this.name}`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track the refreshed effect entry

If a unit keeps the handle returned by this.effect(...) and calls update(), the replacement effect created here is not assigned back to the handle. The handle stays tied to the disposed entry (so state reports unloading and later dispose() only disposes the old entry), leaving the restarted effect alive until the whole unit book is torn down.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L14-L14

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat/agent-core-v2-feature-seam branch from 1020b43 to 3eab705 Compare August 6, 2026 05:43
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@1598480
npx https://pkg.pr.new/@moonshot-ai/kimi-code@1598480

commit: 1598480

@sailist
sailist force-pushed the feat/agent-core-v2-feature-seam branch from 3eab705 to 636d0c5 Compare August 6, 2026 06:26
sailist added 2 commits August 6, 2026 17:55
- introduce the L3 Service/Fiber unit layer: the Service base class with this.provide/effect/on/get/ref capabilities, the fiber runtime with thenable FiberHandles, collection contribution points, and the per-scope-kind ScopeUnits materialization fold
- provide each scope's static registration batch as one atomic provideAll cascade transaction (waiting-area activation, sticky Failed on construction error)
- add the DI unit inspection surface: App-scope debug ledger / dependency graph / cascade history services and the kimi-inspect DI view
- add the Feature unit seam (IFeatureManager + feature assembly), port plan mode onto it, and add the contributed-command seam (agent-command domain + node-sdk RPC types)
- remove the legacy dep-graph tooling
- apply the header-only comment convention across src and test: strip non-header narration, keep the file header, tooling pragmas, and NOTE comments
…ections

- add an opt-in target set in SessionEventBroadcaster; the global fan-out
  now skips event.di.* frames for connections that never opted in, so
  kimi-web and other clients no longer receive the high-churn DI feed
- WsConnectionV1 opts a connection in when client_hello carries
  client_id 'kimi-inspect'; removeGlobalTarget drops the opt-in on close
- temporary gate until a client-declared event-type whitelist lands
@sailist
sailist force-pushed the feat/agent-core-v2-feature-seam branch from 6612fb1 to 341d313 Compare August 6, 2026 09:56
sailist added 3 commits August 6, 2026 18:11
- build the live-ref container chain without aliasing this (no-this-alias)
- snapshot the materialized map with Array.from and document why the copy
  is required (no-useless-spread)
The engine's LifecycleScope is a string enum now; the facade test doubles
still returned the old numeric kinds and failed the handleWireSchema output
validation.
@sailist
sailist merged commit 8c766a6 into MoonshotAI:main Aug 6, 2026
14 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
…shotAI#2678)

* feat(agent-core-v2): add the L3 unit layer and the Feature seam

- introduce the L3 Service/Fiber unit layer: the Service base class with this.provide/effect/on/get/ref capabilities, the fiber runtime with thenable FiberHandles, collection contribution points, and the per-scope-kind ScopeUnits materialization fold
- provide each scope's static registration batch as one atomic provideAll cascade transaction (waiting-area activation, sticky Failed on construction error)
- add the DI unit inspection surface: App-scope debug ledger / dependency graph / cascade history services and the kimi-inspect DI view
- add the Feature unit seam (IFeatureManager + feature assembly), port plan mode onto it, and add the contributed-command seam (agent-command domain + node-sdk RPC types)
- remove the legacy dep-graph tooling
- apply the header-only comment convention across src and test: strip non-header narration, keep the file header, tooling pragmas, and NOTE comments

* feat(kap-server): gate the event.di.* debug feed to kimi-inspect connections

- add an opt-in target set in SessionEventBroadcaster; the global fan-out
  now skips event.di.* frames for connections that never opted in, so
  kimi-web and other clients no longer receive the high-churn DI feed
- WsConnectionV1 opts a connection in when client_hello carries
  client_id 'kimi-inspect'; removeGlobalTarget drops the opt-in on close
- temporary gate until a client-declared event-type whitelist lands

* chore(agent-core-v2): fix oxlint errors in the DI unit layer

- build the live-ref container chain without aliasing this (no-this-alias)
- snapshot the materialized map with Array.from and document why the copy
  is required (no-useless-spread)

* test(klient): use string scope kinds in the lifecycle handle fakes

The engine's LifecycleScope is a string enum now; the facade test doubles
still returned the old numeric kinds and failed the handleWireSchema output
validation.

* build(nix): update the pnpmDeps fetch hash
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.

1 participant