Skip to content

refactor(agent-core-v2): extract externalHooks into a scope-organized feature - #2805

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:refactor/external-hooks-feature-scopes
Open

refactor(agent-core-v2): extract externalHooks into a scope-organized feature#2805
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:refactor/external-hooks-feature-scopes

Conversation

@sailist

@sailist sailist commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — this is an internal refactor; the problem is explained below.

Problem

The external hook capability predates the features/ seam in agent-core-v2: its services lived in three flat per-scope domains (app/externalHooksRunner, session/externalHooks, agent/externalHooks) with their own index.ts barrels, while built-in capabilities are being unified as self-contained Feature units (plan was the first). The runner engine, the two per-scope observers, and the shared pure helpers were also mixed together, making the scope boundaries hard to see.

What changed

  • Extracted the capability into packages/agent-core-v2/src/features/externalHooks/ as ExternalHooksFeature — one App-scope Feature unit contributing the App-scope runner, the Session-scope observer, and the per-Agent observer through the ScopeUnits seam, so retracting the unit withdraws all of them across the scope tree. The hooks config section stays on the static import=register channel, keeping the config manifest discoverable.
  • Organized the feature directory by scope: services under app/ / session/ / agent/, and the shared pure helpers (hook types, matching/dispatch, process spawn, prompt result rendering) under internal/.
  • Updated the package entry leaf exports (replacing the deleted per-domain barrels), the plugin domain imports, the kap-server events-zod import, and the affected tests; regenerated the state manifest.
  • No behavior change. Covered by the existing externalHooks suites plus a new feature-assembly test (318 tests passing), lint:imports + typecheck green on both agent-core-v2 and kap-server, and verified end-to-end on a live server: SessionStart/UserPromptSubmit hooks fire with the expected payloads, and an exit-2 hook blocks a matching prompt while non-matching prompts run.

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.
  • Ran gen-changesets skill, or this PR needs no changeset. (Needs none: internal agent-core-v2 refactor, not user-perceivable.)
  • Ran gen-docs skill, or this PR needs no doc update. (No behavior or configuration change.)

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ea74229

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: 2c7a105398

ℹ️ 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 +34 to +38
this.contributeService(
LifecycleScope.App,
IExternalHooksRunnerService,
ExternalHooksRunnerService,
);

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 Preserve seeded hook-runner overrides

Previously IExternalHooksRunnerService was a registerScopedService, so bootstrap(..., extraSeeds) / createAppScope({ extra }) callers could seed a noop or custom runner and the static registration was skipped. This feature contribution materializes through ScopeUnits during app creation and unconditionally provides the production ExternalHooksRunnerService, so those callers silently lose their override and configured shell hooks can run anyway; preserve the seed check before contributing/providing the hook services.

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

Useful? React with 👍 / 👎.

… feature

Move the external hook services out of app/externalHooksRunner,
session/externalHooks, and agent/externalHooks into
features/externalHooks, assembled as the ExternalHooksFeature unit:

- services live under per-scope subdirectories (app/, session/, agent/);
  shared pure helpers (types, hook matching/dispatch, process spawn,
  prompt result rendering) live under internal/
- the runner and the two observers are contributed through the Feature
  seams (ScopeUnits materialization); the hooks config section stays on
  the static import=register channel
- update the package entry leaf exports, the plugin domain imports, the
  kap-server events-zod import, and the affected tests; regenerate the
  state manifest
@sailist
sailist force-pushed the refactor/external-hooks-feature-scopes branch from 2c7a105 to ea74229 Compare August 11, 2026 06:21
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

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

commit: ea74229

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