Skip to content

refactor(appkit): split the agents plugin into focused modules (#532) - #547

Open
MarioCadenas wants to merge 8 commits into
split/532/fixtures-docsfrom
refactor/agents-plugin
Open

refactor(appkit): split the agents plugin into focused modules (#532)#547
MarioCadenas wants to merge 8 commits into
split/532/fixtures-docsfrom
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,784 lines (−728, ~29%). The plugin is now an orchestrator (registry wiring + route handlers + SSE plumbing) delegating cohesive concerns to focused sibling modules.

What moved

  • Pure helpersapproval.ts, prompt.ts, builtin-tools.ts, adapter-extensions.ts.
  • Skill loading/dispatchskill-loader.ts (discovery, catalog resolution, load_skill/read_skill_file).
  • Registry assemblyregistry.ts (loadCodeAgents, hasCodeAgentSources, resolveDefaultAgent, AgentSource).
  • Tool-dispatch enginetool-dispatch.ts (RunState + dispatchToolCall + runSubAgent) as free functions over a ToolDispatchDeps object.
  • Config resolutionresolve-config.ts (resolveApprovalPolicy / resolveLimits pure fns; getters keep the memo cache).
  • Stream trackingActiveStreamTracker (active-stream map + per-user O(1) concurrency counter). Named to avoid clashing with the unrelated SSE-layer StreamRegistry in src/stream/.

Notes

  • Delegator pattern keeps call sites stable throughout; skillWorkspaceClient() stays as the OBO credential seam.
  • Deliberately not extracted: buildToolIndex (owns the mutable mcpClient lifecycle) and the HTTP handlers (the Plugin route contract) — both need 5-8 pieces of plugin state, so extraction would widen interfaces more than it'd clarify (fails the deep-module test). The remaining ~1,784 lines are the plugin genuinely being a plugin.
  • The agents-plugin concurrency tracker is intentionally separate from the SSE StreamRegistry: that one is a global, transport-level store (event replay buffers, global cap) with no per-user dimension; this one counts streams per user for maxConcurrentStreamsPerUser + ownership checks.
  • Tests updated where they white-boxed moved internals (dispatch-tool-call, dos-limits, approval-route).

Merge order

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

@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
@MarioCadenas MarioCadenas changed the title refactor(appkit): split the agents plugin into focused modules (stacked on #543) feat(appkit): Agent Skills v1 (SKILL.md progressive disclosure) + agents plugin refactor (#532) Aug 21, 2026
@MarioCadenas
MarioCadenas changed the base branch from split/532/sdk-feature to main August 21, 2026 17:02
@MarioCadenas MarioCadenas changed the title feat(appkit): Agent Skills v1 (SKILL.md progressive disclosure) + agents plugin refactor (#532) refactor(appkit): split the agents plugin into focused modules (#532) Aug 21, 2026
@MarioCadenas
MarioCadenas changed the base branch from main to split/532/fixtures-docs August 21, 2026 17:11
…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>
…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>
…g.ts

Moves resolvedApprovalPolicy / resolvedLimits defaulting into pure functions
over AgentsPluginConfig. The getters keep the approval-policy memo cache and
delegate. Config-only interface; both now unit-testable in isolation.

agents.ts: 1839 -> 1812 lines. typecheck + agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Moves the active-stream map + per-user counter (the O(1) concurrency-limit
check) into a StreamRegistry class. The plugin holds one instance and keeps
trackStream/untrackStream/countUserStreams as delegators; cancel/approve read
via streams.get(). Tests inject via trackStream and assert via the registry.

agents.ts: 1812 -> 1784 lines. typecheck + 394 agent tests green.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
The previous commit named it StreamRegistry, colliding with the existing
SSE-layer StreamRegistry in src/stream/ (connection/event-buffer tracking used
by StreamManager). They're different concepts; renamed the agents-plugin one to
ActiveStreamTracker (tracks active streams + per-user counts for the O(1)
concurrency limit) to avoid the name clash.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
…ing)

The prior commit's git add hit the already-deleted stream-registry.ts path,
aborted, and recorded only the deletion — leaving the pushed tip non-compiling
(agents.ts imported the removed file; active-stream-tracker.ts was uncommitted).
This adds the new module and the agents.ts import/usage so the tree builds.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas
MarioCadenas force-pushed the refactor/agents-plugin branch from 9831cec to a8f7cba Compare August 21, 2026 17:15
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