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.
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 massiveswitchstatement. 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.jsserver/services/ai/tools/shell.jsserver/services/ai/tools/memory.jsserver/services/ai/tools/files.jsserver/services/ai/tools/messaging.jsserver/services/ai/tools/http.jsA thin
tools/index.jsroutes thetoolNameto the correct module.engine.js— Extract cohesive concerns into collaborating modules:server/services/ai/runner.js— the main loop and iteration logicserver/services/ai/planner.js— task analysis and plan constructionserver/services/ai/executor.js— tool dispatch and result handlingPublic API of
engine.jsremains unchanged; it re-exports from the new modules.Acceptance criteria
server/services/ai/exceeds 500 lines.