Skip to content

Split tools.js and engine.js into per-domain modules per GUIDELINES.md #75

Description

@neooriginal

This issue is AI generated.

Problem

Two files dramatically exceed the ~300 line limit set in GUIDELINES.md and create real maintenance, review, and security problems:

  • server/services/ai/tools.js~2800 lines, one massive switch statement. Every tool's security properties, SSRF risk, side-effect classification, and data access must be reasoned about by reading a single giant file. Adding a tool, reviewing a tool's security posture, or changing behaviour for one category requires reading past thousands of unrelated lines.

  • server/services/ai/engine.js~3400 lines. Task analysis, context building, history compaction, multi-step execution, parallel sub-agent orchestration, memory consolidation, and skill learning all live in one class. GUIDELINES.md: "If a file grows past ~300 lines, split it."

Required change

tools.js — Group tool handler functions by domain into separate modules:

  • server/services/ai/tools/browser.js
  • server/services/ai/tools/shell.js
  • server/services/ai/tools/memory.js
  • server/services/ai/tools/files.js
  • server/services/ai/tools/messaging.js
  • server/services/ai/tools/http.js
  • etc.

A thin tools/index.js routes the toolName to the correct module.

engine.js — Extract cohesive concerns into collaborating modules:

  • server/services/ai/runner.js — the main loop and iteration logic
  • server/services/ai/planner.js — task analysis and plan construction
  • server/services/ai/executor.js — tool dispatch and result handling

Public API of engine.js remains unchanged; it re-exports from the new modules.

Acceptance criteria

  • No file in server/services/ai/ exceeds 500 lines.
  • All existing tests pass without modification.
  • Each new module is independently testable.
  • No circular imports are introduced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomousGenerated by AIenhancementNew feature or requestpriority: lowNice to have — refactoring, minor UX, or future featuresreliabilityReliability, resilience, or concurrency concern

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions