Skip to content

refactor(agent): split veryfront-cloud-agent-service into concern modules - #3054

Merged
kwakayama merged 4 commits into
mainfrom
refactor/split-cloud-agent-service
Jul 24, 2026
Merged

kwakayama merged 4 commits into
mainfrom
refactor/split-cloud-agent-service

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

Candidate #4 from the architecture review. veryfront-cloud-agent-service.ts was 1551 lines / 57 internal functions / 7 exports — five concerns fused into one file, and the mandatory read for nearly every hosted change (the second-hottest area of the repo).

Changes

Pure move refactor into five concern modules, with the original file keeping all 7 public exports (and public types) as thin wiring — no importer changes:

Module Lines Concern
cloud-agent-chat-execution.ts ~524 chat-execution preparation and runtime wiring
cloud-agent-child-tools.ts ~433 hosted-child tool assembly
cloud-agent-config.ts ~208 agent-config resolution
cloud-agent-provider-bootstrap.ts ~199 default-provider bootstrap (schema/auth/telemetry)
cloud-agent-paths.ts ~160 path/dir resolution
veryfront-cloud-agent-service.ts ~190 thin re-export wiring (was 1551)

Accounting

Net +197 lines — move-refactor overhead (imports, module headers). Shipped as-is per explicit approval: the reduction rule keeps applying to dedup PRs, while this one buys locality (a provider-bootstrap change no longer means navigating 1500 lines) and per-concern testability.

Verification

  • Zero behavior change; hosted suite passes unmodified: 342 tests / 181 steps, 0 failed
  • deno task verify:quick exit 0 · pre-push (fmt + full suite) passed

Implemented by a worktree executor from the review spec; verified, with five unused-import leftovers removed on review.

…ules

Decompose the 1551-line monolith into five sibling modules under
src/agent/hosted/, each owning one concern:

- cloud-agent-paths.ts        — path/dir resolution, service naming, env
- cloud-agent-provider-bootstrap.ts — schema/auth/telemetry/bash defaults
- cloud-agent-config.ts       — context creation, agent-config resolution, steering
- cloud-agent-child-tools.ts  — MCP resolution, delegation, invoke-agent, skill/steering accessors
- cloud-agent-chat-execution.ts — chat execution preparation, runtime wiring

veryfront-cloud-agent-service.ts retains all 7 public function/const exports
and all public types as thin re-exports; no importer of the file changes.
Zero behavior change. All 26 tests pass.
Copilot AI review requested due to automatic review settings July 24, 2026 05:14
@kojiwakayama
kojiwakayama requested a review from kwakayama as a code owner July 24, 2026 05:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the hosted cloud agent service by splitting the former veryfront-cloud-agent-service.ts monolith into focused concern modules, while keeping the original file as a thin public wiring layer that preserves the existing public exports and types.

Changes:

  • Extracted provider/bootstrap logic (schema, auth, telemetry, bash tooling) into cloud-agent-provider-bootstrap.ts.
  • Extracted path/project/service-name resolution into cloud-agent-paths.ts, and agent config/context initialization into cloud-agent-config.ts.
  • Extracted hosted child-tool assembly and chat execution preparation/runtime wiring into cloud-agent-child-tools.ts and cloud-agent-chat-execution.ts.

Verification

  • Not run in this review environment.
  • Next step: run deno test --no-check --allow-all --parallel (or the repo’s deno task verify:quick if available) to ensure the refactor stays behavior-neutral.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/agent/hosted/veryfront-cloud-agent-service.ts Reduced to a thin public wiring layer that re-exports the existing public surface and delegates to concern modules.
src/agent/hosted/cloud-agent-provider-bootstrap.ts Centralizes default extension/provider bootstrap and option resolution.
src/agent/hosted/cloud-agent-paths.ts Centralizes baseDir/projectDir/environment/serviceName resolution helpers.
src/agent/hosted/cloud-agent-config.ts Centralizes agent discovery, default agent selection, and cached project-steering/config access.
src/agent/hosted/cloud-agent-child-tools.ts Centralizes MCP server resolution, invoke-agent wiring, and hosted child tool/context helpers.
src/agent/hosted/cloud-agent-chat-execution.ts Centralizes chat execution preparation, runtime creation, and control-plane registration lifecycle wiring.
Comments suppressed due to low confidence (1)

src/agent/hosted/cloud-agent-chat-execution.ts:116

  • Avoid taskContext as unknown as ChildRunContext when wiring invoke_agent. The unknown hop bypasses type checking, so future changes could accidentally rely on properties that aren't present on the root chat runtime task context. Align the context types so this call can pass taskContext without a double assertion.
      // child-fork tool. Explicit scoped delegate bindings opt out.
      tools.invoke_agent = createInvokeAgentTool(
        context,
        taskContext as unknown as ChildRunContext,
      );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/agent/hosted/cloud-agent-child-tools.ts
Comment thread src/agent/hosted/cloud-agent-chat-execution.ts
Copilot AI review requested due to automatic review settings July 24, 2026 05:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/agent/hosted/cloud-agent-chat-execution.ts:27

  • This import becomes redundant once "createRemoteMCPToolSource" is included in the top-level "#veryfront/tool" import.
import { createRemoteMCPToolSource } from "#veryfront/tool";

Comment thread src/agent/hosted/cloud-agent-config.ts Outdated
Comment thread src/agent/hosted/cloud-agent-chat-execution.ts Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 05:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 24, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/agent/hosted/cloud-agent-provider-bootstrap.ts
@kwakayama
kwakayama added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit dfaddef Jul 24, 2026
29 checks passed
@kwakayama
kwakayama deleted the refactor/split-cloud-agent-service branch July 24, 2026 06:52
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.

3 participants