This document describes the internal architecture of SquadAI.
The system is organized into six layers, each with a clear responsibility:
1. Domain contracts (types, interfaces, errors — no side effects)
2. Config merge/validate (three-layer precedence resolution)
3. Planner (compute intended actions from merged config)
4. Pipeline executor (apply actions with backup/rollback safety)
5. Verifier (post-apply compliance assertions)
6. Interfaces (CLI commands, TUI)
User Config (~/.squadai/config.json)
Project Config (.squadai/project.json)
Policy Config (.squadai/policy.json)
|
config.Merge()
(policy locked > project > user)
|
planner.Plan()
(iterates enabled adapters x components + copilot + methodology team)
|
backup.SnapshotFiles()
(copies all target files before mutation)
|
pipeline.Execute()
(runs each PlannedAction, records StepResults)
(on failure: rollback from backup)
|
verify.Verify()
(checks files exist, markers present, content current)
Core types and interfaces with no filesystem dependencies. Defines:
- AgentID —
opencode,claude-code,vscode-copilot,cursor,windsurf - AdapterLane —
team(required) orpersonal(optional) - Methodology —
tdd,sdd,conventional - DelegationStrategy —
native(OpenCode, Cursor),prompt(Claude Code),solo(VS Code, Windsurf) - ComponentID —
memory,rules,settings,mcp,agents,skills,commands,plugins,workflows - OperationalMode —
team,personal(hybridis a deprecated alias, resolved at load time) - PlannedAction — a single step the planner produces
- StepResult — outcome of executing one action
- ApplyReport — full result of a plan execution
- VerifyResult / VerifyReport — compliance check results
Key interfaces:
- Adapter — agent detection, path resolution, component support
- ComponentInstaller — plan/apply/verify for a single component
- ConfigLoader — load and merge the three config layers
- Planner — compute action plan from merged config
- Executor — run plan with backup/rollback
- Verifier — post-apply state checks
Three-layer configuration loading and merging.
loader.go— reads JSON files from well-known pathsmerger.go— applies precedence: policy locked > project > uservalidator.go— schema validation for each config type
Each adapter is isolated in its own package and implements domain.Adapter. No path logic exists outside adapter packages.
opencode/— team baseline adapter (always included), native delegationclaude/— personal-lane adapter, prompt-based delegationvscode/— personal-lane adapter (VS Code Copilot), solo delegationcursor/— personal-lane adapter, native delegationwindsurf/— personal-lane adapter, solo delegation
Component installers implement domain.ComponentInstaller.
memory/— installs memory protocol files for supported adapterscopilot/— manages.github/copilot-instructions.mdwith marker blocksrules/— writes agent-specific rule/instruction files with team standardssettings/— manages agent-specific settings and preferencesmcp/— installs MCP server configurations for agents that support themagents/— installs sub-agent definitions from methodology team compositionskills/— installs methodology-specific skill filescommands/— installs custom slash commands for agents that support themplugins/— installs optional plugin configurationsworkflows/— installs workflow definitions
Atomic file operations:
WriteAtomic— writes via temp file + rename for crash safety, skips if content unchanged (idempotent)ReadFileOrEmpty— returns empty string if file doesn't exist
HTML comment-based marker block system for managing content in shared files:
InjectSection(document, sectionID, content)— inserts or replaces a managed sectionExtractSection(document, sectionID)— reads content between markersHasSection(document, sectionID)— checks if markers exist
Marker format:
<!-- squadai:SECTION_ID -->
managed content here
<!-- /squadai:SECTION_ID -->
Content outside markers is never modified.
Computes a list of PlannedAction values from merged config and detected adapters. Returns ActionSkip for items already in desired state (idempotency).
Executes planned actions in order. Before mutating any files, it creates a backup snapshot via the backup store. On failure, it rolls back all completed steps and marks remaining steps as rolled_back.
Manages backup manifests and file snapshots on disk.
Storage layout:
~/.squadai/backups/<id>/manifest.json
~/.squadai/backups/<id>/files/0
~/.squadai/backups/<id>/files/1
Manifest fields: id, timestamp, command, affected_files, status.
Each FileSnapshot records: path, existed_before, checksum_before, backup_file.
Aggregates verification checks from all component installers, plus policy compliance. Returns a VerifyReport with individual check results grouped by component.
Command implementations. Each command function accepts args and stdout, loads config, and delegates to the appropriate subsystem.
Bubbletea TUI with nine screens:
- Intro — tool name, version, detected mode, adapter summary with delegation strategies
- Menu — Init/Setup, Plan, Apply, Sync, Team Status, Verify, Restore backup, Quit
- Running — progress indicator while a command executes
- Result — command output display
- Init Methodology — select TDD, SDD, or Conventional (shows role pipeline)
- Team Status — shows current methodology, team roles, MCP servers, and plugins
- Init MCP — toggle MCP servers (Context7 pre-selected)
- Init Plugins — toggle available plugins (filtered by agent and methodology)
- Init Summary — review all selections before confirming
Delegates to the same command handlers used by CLI.
- Adapters own all paths — no hardcoded agent paths outside adapter packages
- Marker blocks for managed content — user content outside markers is never touched
- Atomic writes everywhere — temp file + rename via
fileutil.WriteAtomic - Idempotency by default — planner returns
ActionSkipwhen state matches; writer skips when bytes match - Fail loudly — errors and warnings are always surfaced, never silently ignored
An in-agent slash command that reads the repository and refines installed agent/skill/command
templates per-codebase. State tracked in .squadai/.squad-refined (JSON). The squadrefine
package (planned: internal/squadrefine/) handles drift detection and nudge throttling.
An indexed docs/memory/ tree with _inbox/, decisions/, learnings/, incidents/ buckets.
CLI: squadai memory add|search|promote|reindex|status. Librarian agent searches memory before
planning. Per-adapter protocol injection (<!-- squadai:memory-protocol --> marker blocks).