SQQ Agent Flow Documentation
On Sun, 04 Oct 2026, by @lucasdicioccio, 552 words, 8 code snippets, 0 links, 0images.
Generated from documentation/sqq-flow.md, the repository is the canonical source and may be ahead of this page.
SQQ Agent Flow Documentation
Overview
The sqq-agent.sh is a task queue automation system that manages AI agent execution on Git repositories. It integrates with GitHub issues, uses git worktrees for isolated task execution, and automatically creates pull requests with the results.
Architecture Components
Core Configuration
| Variable | Purpose |
|---|---|
SQQ_BIN | Path to the sqq queue management binary |
QUEUE_DB | SQLite database path for task queue storage (tasks/queue.sql) |
TASK_DIR | Directory for instruction files (tasks/) |
SESSIONS_DIR | Directory for agent session outputs (tasks-sessions/) |
BASE_BRANCH | Base git branch for new worktrees (main) |
GITHUB_USERNAME | GitHub username to filter issues by author (security filter) |
PROJECT_MAP | Maps labels to relative paths in worktree |
AGENT_MAP | Maps labels to agent configuration files |
Data Flow
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ GitHub Issues │────▶│ Task Files │────▶│ Queue (sqq) │
│ (with labels) │ │ (.md files) │ │ (SQLite) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │
│ ▼
│ ┌─────────────────┐
│ │ Process Loop │
│ └─────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ WORKTREE EXECUTION │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
│ │ Setup │─▶│ Prepare │─▶│ Run Agent │ │
│ │ Worktree │ │ Environment │ │ (agents-exe) │ │
│ └──────────────┘ └──────────────┘ └──────────────────────┘ │
│ │ │
│ ┌──────────────┐ ┌──────────────┐ │ │
│ │ Create PR │◀─│ Push Branch │◀────────┘ │
│ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Command Flows
1. Initialization (init)
sqq-agent.sh init- Creates
TASK_DIRandSESSIONS_DIRdirectories - Initializes SQLite queue database via
sqq init --queue
2. Manual Task Addition (add)
sqq-agent.sh add <label> <branch>- Validates the project label exists in
PROJECT_MAP - Finds or creates a numbered task file (format:
NNNN-<branch>.md) - Opens
$EDITORfor user to write instructions - Enqueues job:
sqq-agent.sh worktree_exec "<label>" "<branch>" "<taskfile>"
3. GitHub Issue Import (from_github)
sqq-agent.sh from_github- Queries GitHub for issues labeled
agents/to-be-takenfrom the configured author only - For each issue:
- Matches project label from issue labels
- Creates task file with issue content (title, body, comments)
- Adds note to mention issue number in commit
- Enqueues worktree_exec job
- Updates issue labels: removes
agents/to-be-taken, addsagents/taken
Security Note: The GITHUB_USERNAME filter ensures that only issues created by the trusted author are processed. This prevents arbitrary code execution from malicious issues filed by third parties on public repositories.
4. Queue Processing (process)
sqq-agent.sh process- Runs
sqq process --action Execin a loop - On failure: waits 60 seconds and retries
- Continues until queue is empty or manually stopped
5. Worktree Execution (worktree_exec) - Core Engine
sqq-agent.sh worktree_exec <label> <name> <instruction_file>Phase 1: Worktree Setup
- Fetch latest
origin/BASE_BRANCH - Remove existing worktree (if any) and prune
- Create new git worktree at directory
<name>
Phase 2: Navigation
- Change to project directory based on
PROJECT_MAP[<label>]
Phase 3: Environment Preparation
- Execute
./git-agent-task.sh prepareif present - This allows per-project dependency installation or setup
Phase 4: Agent Execution
- Check agent configuration with
agents-exe --agent-file check - Run agent with instruction file:
agents-exe --agent-file <config> run \ --session-file <session>.json \ -f <instruction_file> - Capture agent output as commit message
- Export session to markdown:
agents-exe session-print
Phase 5: Commit and PR
- Create and checkout new branch
<name> - If changes detected:
- Stage all changes:
git add -A - Commit with agent output as message (no verify)
- Push to origin
- Create Pull Request via
gh pr createwith labelagents/agent-pr
- Stage all changes:
- For non-GitHub tasks: optionally run
./git-agent-task.sh preview
6. Automatic Merging (merge-pr)
sqq-agent.sh merge-pr- Identifies the default branch of the repository.
- Lists all Pull Requests with the label
agents/agent-pr. - For each PR:
- If the base branch is not the default branch, it triggers an automatic merge (
gh pr merge --auto). - If the base branch is the default branch, it skips the PR to ensure manual review for main branch changes.
- If the base branch is not the default branch, it triggers an automatic merge (
File Naming Conventions
Task Files
- Format:
TASK_DIR/NNNN-<branch>.md - Sequential numbering starting from 0001
- Preserves existing files when re-queueing same branch
Session Files
- JSON:
SESSIONS_DIR/<name>.session.json(agent state) - Markdown:
SESSIONS_DIR/<name>.session.md(human-readable)
Error Handling and Retries
- Queue processing loops indefinitely with 60s delay on failure
- Failed worktrees are force-removed before retry
- Agent execution errors don’t prevent commit/push if changes exist
- Missing
git-agent-task.shgenerates warnings but continues
Integration Points
| Tool | Purpose |
|---|---|
sqq | Task queue management (enqueue/dequeue/process) |
gh | GitHub CLI for issue/PR management |
agents-exe | AI agent execution engine |
git worktree | Isolated working directories per task |
Security Considerations
- Uses
--no-verifyon git commits to bypass hooks in worktrees - Force-removes worktrees (potential data loss if in-progress)
- Executes
./git-agent-task.shwithout sandboxing - Critical:
GITHUB_USERNAMEenvironment variable filters GitHub issues by author to prevent processing malicious issues from third parties on public repositories. Default islucasdicioccio.