You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Init signal / work directory orchestration — ensureInitSignalDir, prepareWorkDirectories
The prepareLogDirectories function is 116 lines because it repeats a chown pattern for each log type (agent-logs, session-state, squid-logs, api-proxy-logs, cli-proxy-logs, MCP logs). This repetition could itself be reduced by a shared helper.
Proposed Split
src/workdir-setup.ts (397 lines) could be refactored as:
Alternatively, a lighter approach: extract a shared ensureOwnedDirectory(path, uid, gid) helper to eliminate the repeated chown pattern inside prepareLogDirectories, reducing it from 116 to ~40 lines.
Refactoring Opportunity
Summary
src/workdir-setup.tsprepareLogDirectories()at 116 lines (lines 144–260)Evidence
workdir-setup.tsconflates five conceptually distinct responsibilities:ensureDirectory,assertRealDirectory,createMissingOwnedDirectorySegmentsprepareChrootHomeMountpointprepareLogDirectories(116 lines: agent-logs, session-state, squid-logs, api-proxy-logs, MCP logs — each with UID/chown logic)pruneStaleMcpLogDirs,prepareChrootHomeMounts(handles home-dir allowlisting, runner tool cache, Docker socket)ensureInitSignalDir,prepareWorkDirectoriesThe
prepareLogDirectoriesfunction is 116 lines because it repeats a chown pattern for each log type (agent-logs, session-state, squid-logs, api-proxy-logs, cli-proxy-logs, MCP logs). This repetition could itself be reduced by a shared helper.Proposed Split
src/workdir-setup.ts(397 lines) could be refactored as:src/fs-utils.ts—ensureDirectory,assertRealDirectory,createMissingOwnedDirectorySegments(~104 lines; general-purpose, reusable)src/chroot-home-setup.ts—prepareChrootHomeMountpoint,prepareChrootHomeMounts,pruneStaleMcpLogDirs(~180 lines; chroot-specific logic)src/log-directory-setup.ts—prepareLogDirectoriesand its per-type chown helper (~120 lines)src/workdir-setup.ts— thin orchestrator:ensureInitSignalDir,prepareWorkDirectories(~40 lines)Alternatively, a lighter approach: extract a shared
ensureOwnedDirectory(path, uid, gid)helper to eliminate the repeated chown pattern insideprepareLogDirectories, reducing it from 116 to ~40 lines.Affected Callers
Current callers:
src/config-writer.ts:20— importsprepareWorkDirectoriessrc/workdir-setup.test.ts,src/coverage-improvements.test.tsEffort Estimate
Medium — involves moving internal functions across files and updating test imports.
Benefits
prepareLogDirectoriescan be simplified by a shared owned-directory helperDetected by Refactoring Scanner workflow. Run date: 2026-07-08
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.