Skip to content

refactor(appkit): split the agents plugin into focused modules (stacked on #543) - #547

Open
MarioCadenas wants to merge 4 commits into
split/532/sdk-featurefrom
refactor/agents-plugin
Open

refactor(appkit): split the agents plugin into focused modules (stacked on #543)#547
MarioCadenas wants to merge 4 commits into
split/532/sdk-featurefrom
refactor/agents-plugin

Conversation

@MarioCadenas

@MarioCadenas MarioCadenas commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Behavior-preserving refactor of the ~2,500-line agents.ts god-file into focused modules. Stacked on #543 (it only touches agents.ts, which #543 owns) — independent of #544.

No behavior changes: every commit keeps pnpm --filter=@databricks/appkit typecheck and the agent test suite (394 tests) green.

agents.ts: 2,512 → 1,839 lines (−673, ~27%). The plugin is now an orchestrator (registry wiring + route handlers + SSE plumbing) delegating cohesive concerns to focused modules.

Commits

  1. Pure helpersapproval.ts, prompt.ts, builtin-tools.ts, adapter-extensions.ts (module-scope pure functions/constants). 2512 → 2331.
  2. Skill loading/dispatchskill-loader.ts (discovery, catalog resolution, load_skill/read_skill_file dispatch). 2331 → 2152.
  3. Registry assemblyregistry.ts (loadCodeAgents, hasCodeAgentSources, resolveDefaultAgent, AgentSource). buildAgentRegistry stays as the orchestrator. 2152 → 2088.
  4. Tool-dispatch enginetool-dispatch.ts (RunState + dispatchToolCall + runSubAgent: tool-call budget, approval gate, sub-agent recursion) as free functions over a ToolDispatchDeps object. 2088 → 1839.

Notes

  • The delegator pattern keeps call sites stable; skillWorkspaceClient() stays as the OBO credential seam.
  • Deliberately not extracted: buildToolIndex + the HTTP handlers — they're context/MCP-coupled orchestration where extraction would widen interfaces more than it'd clarify (a wide dependency interface fails the deep-module test).
  • dispatch-tool-call.test.ts / dos-limits.test.ts updated to call the now-free dispatchToolCall/runSubAgent, building deps via the plugin's own toolDispatchDeps().

Merge order

Stacked on #543; auto-retargets to main once #543 merges. Merge after #543.

…ules

Step 1 of splitting the ~2.5k-line agents plugin. Moves module-scope pure
functions/constants out of agents.ts verbatim (behavior-preserving):
- approval.ts            requiresApproval
- prompt.ts              composePromptForAgent
- builtin-tools.ts       LOAD_SKILL_TOOL_DEF, READ_SKILL_FILE_TOOL_DEF
- adapter-extensions.ts  buildAdapterExtensions, supervisorToolDescription, warnOnCapabilityMismatch

agents.ts: 2512 -> 2331 lines. typecheck + 394 agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas
MarioCadenas requested a review from a team as a code owner August 21, 2026 15:13
@MarioCadenas
MarioCadenas requested review from ditadi and removed request for a team August 21, 2026 15:13
…ader

Step 2 of splitting the agents plugin. Moves skill discovery, per-agent
catalog resolution, and the load_skill/read_skill_file dispatch into
skill-loader.ts as free functions; the class keeps thin delegators (call sites
unchanged) and skillWorkspaceClient() as the OBO credential seam.

agents.ts: 2331 -> 2152 lines. typecheck + 394 agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Step 3 of splitting the agents plugin. Moves the decoupled boot-time
assembly helpers into registry.ts: loadCodeAgents, hasCodeAgentSources (now
internal), resolveDefaultAgent, and the AgentSource type. buildAgentRegistry
stays as the orchestrator that wires them. Also merges a duplicate import in
skill-loader.ts.

agents.ts: 2152 -> 2088 lines. typecheck + 394 agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
…tch.ts

Step 4 (final) of splitting the agents plugin. Moves dispatchToolCall +
runSubAgent — the tool-call budget, approval gate, and sub-agent recursion —
into tool-dispatch.ts as free functions over RunState + a ToolDispatchDeps
object. The plugin builds deps via toolDispatchDeps(); the two executeTool
closures call the free function. RunState moves with them. Tests updated to
invoke the free functions (deps built from the plugin's own builder).

agents.ts: 2088 -> 1839 lines (2512 -> 1839 across all four steps). typecheck +
394 agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
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