Skip to content

feat(cli): Add squad loop command (#761)#767

Merged
diberry merged 11 commits intodevfrom
squad/761-loop-only
Apr 3, 2026
Merged

feat(cli): Add squad loop command (#761)#767
diberry merged 11 commits intodevfrom
squad/761-loop-only

Conversation

@diberry
Copy link
Copy Markdown
Collaborator

@diberry diberry commented Apr 2, 2026

Summary

Split from PR #765 — loop command only, Teams adapter extracted to separate PR.

Adds the squad loop command — a prompt-driven continuous work loop that reads a loop.md file and runs it on a configurable interval, no GitHub issues required.

Closes #761

Review findings addressed

  1. Lazy storage — removed module-level FSStorageProvider side effect
  2. Adapter safety — replaced type-assertion with proper NoopAdapter
  3. gh preflight — added checkGhCopilot() validation before loop entry

diberry and others added 2 commits April 2, 2026 16:17
…r safety, gh preflight

- Replace module-level FSStorageProvider with direct node:fs calls (existsSync/readFileSync)
  to eliminate import side-effect
- Replace unsafe type-assertion adapter stub with createNoopAdapter() that implements all
  PlatformAdapter methods with safe no-ops / clear errors
- Add gh copilot preflight check before entering the loop (skipped when agentCmd is set)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diberry and others added 2 commits April 2, 2026 17:36
…utdown, path.resolve, docs

Closes #765

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cherry-pick squad.agent.md.template changes from PR #765 that implement
decisions archiving hard gates (20KB/51KB thresholds) and history
summarization gates (15KB) — needed to prevent runaway file growth
during continuous loop operation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry marked this pull request as ready for review April 3, 2026 03:02
Copilot AI review requested due to automatic review settings April 3, 2026 03:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new squad loop CLI command to run a prompt-driven continuous work loop from a loop.md file, reusing the existing watch capability system (pre-scan + housekeeping) without requiring GitHub issues.

Changes:

  • Introduces packages/squad-cli/src/cli/commands/loop.ts with frontmatter parsing, loop scaffolding, capability preflight, and round execution.
  • Wires loop into packages/squad-cli/src/cli-entry.ts with --help, --init, --file, --interval, --timeout, and capability flags.
  • Adds docs, template(s), tests for the pure parser/generator, and a changeset for a minor CLI release.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/squad-cli/src/cli/commands/loop.ts New loop command implementation: frontmatter parser, boilerplate generator, capability integration, and interval runner.
packages/squad-cli/src/cli-entry.ts Adds squad loop help + argument parsing and --init scaffolding behavior.
test/cli/loop.test.ts Unit tests for parseLoopFile() and generateLoopFile().
templates/loop.md Adds a user-facing loop prompt template intended to be copied into .squad/templates/.
docs/src/content/docs/features/loop.md New feature documentation for Loop usage, frontmatter, and examples.
docs/src/content/docs/reference/cli.md Updates CLI reference: adds loop entries and a new squad loop section.
templates/squad.agent.md.template Updates coordinator template content (incl. Scribe task ordering/thresholds).
packages/squad-cli/templates/squad.agent.md.template Updates CLI-packaged coordinator template (incl. Scribe task ordering/thresholds).
.changeset/loop-command.md Declares a minor bump for @bradygaster/squad-cli with loop command release notes.
Comments suppressed due to low confidence (1)

docs/src/content/docs/reference/cli.md:206

  • After adding the new ### squad loop section, the documentation no longer has a heading for the interactive shell section — the text Enter the shell with \squad`now appears immediately after a horizontal rule. Consider reintroducing an## Interactive Shell` (or similar) heading before that content so the page structure and TOC remain clear.
For complete documentation and examples, see [Loop — Prompt-driven work loop](../features/loop.md).

---

Enter the shell with `squad` (no arguments). You'll see:

</details>

Comment thread packages/squad-cli/src/cli/commands/loop.ts Outdated
Comment thread docs/src/content/docs/features/loop.md Outdated
Comment thread packages/squad-cli/src/cli/commands/loop.ts
Comment thread packages/squad-cli/src/cli/commands/loop.ts Outdated
…ocs default

- Stream stdout/stderr from execFile to terminal in real-time
- Use workTreeRoot for consistent CWD in worktree scenarios
- Align docs description default with code ("Squad Loop")

Closes review comments on #767

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Test configured gate (configured: false returns early)
- Test missing loop.md file handling
- Test empty prompt body fatal error
- Test interval/timeout validation
- Test gh copilot preflight check

Addresses review comment on #767

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

docs/src/content/docs/reference/cli.md:206

  • The ## Interactive Shell section header appears to have been removed when inserting the new squad loop docs. After the --- separator, the text jumps straight into “Enter the shell…” without a heading, which breaks the page’s structure/TOC. Re-add an appropriate heading (e.g., restore ## Interactive Shell) before the shell instructions.
For complete documentation and examples, see [Loop — Prompt-driven work loop](../features/loop.md).

---

Enter the shell with `squad` (no arguments). You'll see:

</details>

Comment thread packages/squad-cli/src/cli/commands/loop.ts
Comment thread packages/squad-cli/src/cli/commands/loop.ts Outdated
Comment thread docs/src/content/docs/features/loop.md Outdated
diberry and others added 5 commits April 2, 2026 20:28
- Move 71 dated entries (2026-02-21:2026-03-25) to decisions-archive.md
- Trim decisions.md to foundational directives + current entries (2026-03-26+)
- decisions.md: 12.1KB (from 385KB)
- decisions-archive.md: 373.8KB (append-only preserved)
- Archive gate: PASS (decisions.md now below 20KB threshold)

Archival timestamp: 2026-04-03T03:28:22.5673588Z

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Archive log: decisions.md trimmed 385KB → 11.9KB (96.9% reduction)
- 71 entries (2026-02-21:2026-03-25) moved to append-only archive
- Archive gate: PASS (decisions.md < 20KB threshold)
- Context savings: ~373KB per agent load

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Derive teamRoot from detectSquadDir() path for worktree consistency
- Read loop scaffold from templates/loop.md instead of hardcoding
- Update docs prerequisites: gh+copilot required, --agent-cmd is escape hatch

Addresses review comments on #767

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Teaches agents to reply to PR review threads after fixing issues,
making resolutions traceable and visible to reviewers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry merged commit efb56ac into dev Apr 3, 2026
11 checks passed
@diberry
Copy link
Copy Markdown
Collaborator Author

diberry commented Apr 3, 2026

Post-Merge Team Review — Squad Mission Control

Reviewed by: Flight (Architecture), RETRO (Security), FIDO (Quality), CONTROL (TypeScript), GNC (Runtime)

Verdicts

Reviewer Domain Verdict
Flight Architecture APPROVE WITH NOTES
RETRO Security PASS WITH NOTES
FIDO Test Coverage PASS WITH NOTES
CONTROL Type Safety PASS WITH NOTES
GNC Runtime PASS WITH NOTES

0 blockers. 0 red findings from architecture, security, types, or runtime.

Key Findings

Architecture (Flight):

  • Clean capability system reuse from watch — composes, doesn't fork
  • NoopAdapter is the right degradation pattern for prompt-driven mode
  • runPhase() and buildAgentCommand() should be extracted to shared utils to prevent divergence

Security (RETRO):

  • execFile without shell: true — secure by design, no injection path
  • --agent-cmd runs arbitrary executables (intentional, CLI-only flag, matches watch pattern)
  • Prompt visible in process args during execution — inherent to CLI tools, document it

Test Coverage (FIDO):

  • Pure functions (parseLoopFile, generateLoopFile) have excellent coverage (14+ cases)
  • runLoop() early-exit paths well tested (7 tests)
  • Execution core (executeRound, buildLoopAgentCommand, timeout handling) has zero coverage — recommend follow-up

Type Safety (CONTROL):

  • Strict-mode compliant, no any leaks, all unchecked indexing guarded
  • NoopAdapter cast should use satisfies PlatformAdapter instead of as to catch interface drift
  • Redundant err cast — ExecFileException already has killed

Runtime (GNC):

  • roundInProgress guard correctly prevents overlapping executions
  • execFile buffers 50MB internally that is never read — consider spawn() instead
  • setInterval causes drift — self-rescheduling setTimeout would give predictable spacing
  • Housekeeping can run after shutdown resolves — add isShuttingDown guard

Recommended Follow-ups (non-blocking)

  1. Extract runPhase() + buildAgentCommand() to shared utils
  2. Replace execFile with spawn (eliminate phantom 50MB buffer)
  3. Replace setInterval with self-rescheduling setTimeout
  4. Test executeRound + buildLoopAgentCommand in isolation
  5. Use satisfies PlatformAdapter on NoopAdapter
  6. Add isShuttingDown guard before housekeeping phase
  7. Document --agent-cmd security note in --help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): Add squad loop command — prompt-driven continuous work loop

2 participants