Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/fix-migration-experience.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@bradygaster/squad-cli": patch
---

Fix migration experience for users upgrading from v0.5.x

- Shell now scaffolds `.squad/` via `sdkInitSquad()` when `team.md` is absent, instead of blocking all input with a circular "Run /init" message
- Add `squad migrate` command: backs up `.squad/`, cleans squad-owned files, reinitializes, then restores user-owned files. Supports `--dry-run` and `--backup-dir` flags
- Fix `scrub-emails` default directory (`.ai-team/` → `.squad/`)
- Rewrite `docs/scenarios/upgrading.md`: remove stale `npx github:bradygaster/squad` references, add correct commands for global/local/npx install methods
- Update `docs/scenarios/troubleshooting.md`: fix Node.js version requirement (22→20), remove SSH hang section specific to removed distribution
- Update `docs/get-started/migration.md`: fix Node.js version (18→20), use `@latest` instead of pinned version, document all three install methods, add `squad migrate` usage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ coverage/
# Squad: ignore generated logs
.squad/orchestration-log/
.squad/log/
.squad/config.json
.test-cli-*
# Docs site generated files
docs/dist/
1 change: 1 addition & 0 deletions .squad/.first-run
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2026-03-04T23:48:26.577Z
29 changes: 29 additions & 0 deletions .squad/agents/breedan/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,32 @@ What a real user would encounter that no test catches:
3. [CORRECTED] Fixed timestamp format on public readiness entry — changed from mixed ISO-T format to standard (2026-02-24) for consistency with other history entries

**Status:** Clean after corrections.

### Squad Migrate E2E Tests — 2025-03-05

**Context:** The migrate command was added to safely upgrade .squad/ directories (backup → clean → reinit → restore). A critical bug where re-launching shell after migrate would trigger re-initialization (overwriting agent files) was fixed by cleaning up `.first-run` and `.init-prompt` markers after migration.

**Tests created:** `test/migrate-e2e.test.ts` — 23 tests, all passing.

#### Test Coverage (6 groups)
1. **--dry-run:** Exit 0, outputs [dry-run] marker, no backups created, .squad/ untouched (3 tests)
2. **Full migrate flow:** Creates backup, preserves user files (agents/, team.md), removes .first-run/.init-prompt markers (6 tests)
3. **--restore (auto-detect):** Finds latest .squad-backup-*, restores content correctly (3 tests)
4. **--restore <path>:** Works with relative and absolute paths (3 tests)
5. **No .squad/ directory:** Fresh init path works (creates .squad/, .first-run IS present since it's genuinely first run) (3 tests)
6. **Shell reinit guard:** Verifies .first-run/.init-prompt cleanup after migrate prevents unwanted shell reinit (5 tests)

#### Key Implementation Details
- Used `execFileSync` (not node-pty) since migrate is non-interactive
- Built CLI at `packages/squad-cli/dist/cli-entry.js` instead of root `index.js` (which has CJS syntax despite package.json type:module)
- Helper `createPopulatedSquadDir()` scaffolds realistic post-init .squad/ with agents, charters, history
- Tests validate filesystem state before/after migrate (marker files, backup dirs, user content preservation)
- Important behavior: fresh init via migrate (no existing .squad/) DOES create .first-run (correct), but migrating existing .squad/ removes it (prevents shell reinit)

#### Learnings
1. **CLI entry points matter:** Root index.js is CJS syntax but package.json has type:module, causing syntax errors. Built CLI works correctly.
2. **Marker cleanup location:** migrate.ts lines 246-251 clean up .first-run/.init-prompt ONLY after migrating existing .squad/, not during fresh init path (which is correct behavior).
3. **Test isolation:** temp dirs + afterEach cleanup ensure no cross-test pollution.
4. **Backup validation:** Verified both auto-detect (latest .squad-backup-*) and explicit path restore scenarios work.

**Test execution:** 23/23 passing in ~10s. All scenarios covered.
25 changes: 24 additions & 1 deletion .squad/agents/hockney/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,27 @@ All labeled squad:hockney for routing. Each issue includes: what's missing, why
- **What:** Updated test description and path from `.squad-templates/` to `.squad/templates/` to match the corrected install path in `init.ts`.
- **Key finding:** The SDK dist was stale (still had old `.squad-templates` path). Source was already updated but `npm run build` hadn't been run. Rebuilt SDK to verify test passes.
- **Pre-existing failure:** Line 94 gitattributes content mismatch (unrelated, not introduced by this change).
- **Lesson:** On Windows, use `join(root, '.squad', 'templates')` not `join(root, '.squad/templates')` — forward-slash segments in `join` args work on Node but it's better practice to use separate args.
- **Lesson:** On Windows, use `join(root, '.squad', 'templates')` not `join(root, '.squad/templates')` — forward-slash segments in `join` args work on Node but it's better practice to use separate args.

### Migration command test coverage (2026-03-05)
**Status:** Complete — 30 tests added, all pass.
- **Files created:**
- `test/migrate-command.test.ts` (19 tests for `runMigrate`)
- `test/cast-guard.test.ts` (11 tests for `createTeam` guard logic)
- **Coverage highlights:**
- `findLatestBackup` tested via `--restore` flag with 0, 1, and 3 backups
- Dry-run mode: no filesystem changes, no sdkInitSquad call
- Normal migration: backup creation, SQUAD_OWNED removal, USER_OWNED restoration, first-run marker cleanup
- Legacy `.ai-team/` migration
- Auto-rollback on sdkInitSquad failure
- Explicit and auto-detected restore paths
- Cast guard: protects non-empty charter.md and history.md from overwrite; writes when absent or whitespace-only
- **Key patterns:**
- `vi.spyOn(process, 'exit').mockImplementation(() => { throw new Error() })` to test error paths without actually exiting
- `vi.mock('@bradygaster/squad-sdk')` to isolate CLI logic from SDK behavior
- `mkdtempSync(join(tmpdir(), ...))` for clean temp dirs per test
- **Learnings:**
- Migration has solid error handling (auto-rollback is critical)
- Cast guard protects against accidental overwrite after migrate (BUG FIX)
- Tests are structural — they verify the logic without caring about console output
- All 30 tests pass on first run (implementation is solid)
43 changes: 43 additions & 0 deletions .squad/agents/mcmanus/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,46 @@ Multi-agent build of Rock-Paper-Scissors game with 10 AI strategies, Docker infr


📌 Team update (2026-03-04T17:52:00Z): Migration docs file-safety guidance added — doctor command now live in CLI (fixes #188) — decided by Keaton, implemented by McManus

### 2026-03-[Current]: Documentation sweep for `squad migrate` consistency (Issue #197)

**Status:** Complete. Sweep across migration-related docs to ensure consistency with new `squad migrate` command and restore functionality.

**What was fixed:**
1. **docs/reference/cli.md** — Added missing `squad migrate` and related flags to command table (count: 16 → 17 commands)
- Added: `squad migrate`, `squad migrate --dry-run`, `squad migrate --restore [path]`
2. **docs/scenarios/disaster-recovery.md** — Updated all 9 sections from `.ai-team/` → `.squad/`
- Changed: directory paths, commands, file references
- Added: explicit mention of `squad migrate` in section 6 (Upgrade broke something) as the recovery tool
- Added: tip about using `squad migrate` for broken `.squad/` directories
3. **docs/scenarios/keep-my-squad.md** — Updated from deprecated `npx github:bradygaster/squad` to `squad init` and modern npm install
- Changed: export/import examples, version upgrade examples, command references
- Updated: `.ai-team/` → `.squad/`, `.ai-team-templates/` → `.squad/templates/`
4. **README.md** — Added `squad migrate` command to commands table
- Count: 15 → 16 commands
- Added full description with --dry-run and --restore flags

**Files not changed (determined out of scope):**
- Blog posts (historical, not end-user facing in current release)
- General scenario docs (mid-project, new-project, etc.) — these use old commands but not migration-specific

**Consistency check performed:**
- All three key migration docs (migration.md, upgrading.md, troubleshooting.md) already had proper `squad migrate` coverage
- No inconsistencies found between what migrate does across these files
- `--restore` flag well-documented in migration.md and troubleshooting.md

**Tone and style:**
- Maintained consistent, action-oriented voice ("Back up", "Reinitialize", "Restore")
- No marketing language added — purely functional updates
- All changes are substantiated by actual code behavior described in the migration context

**Learnings:**
1. **Documentation fragmentation risk:** Scenario docs referencing `.ai-team/` should be addressed in a separate sweep targeting all scenario files (not just migration-focused ones).
2. **Command inventory pattern:** CLI reference and README command counts need to stay synchronized. This is a manual maintenance risk — consider automation.
3. **Major version boundaries:** The `.ai-team/` → `.squad/` transition is a hard boundary (v0.5.4 → v0.8.x). Docs should clearly signal this is non-backwards-compatible, which they now do.
4. **Restore UX:** Having both `--restore` (auto-detect) and `--restore [path]` (explicit) is well-documented and matches actual CLI behavior.


---

📌 **Team update (2026-03-05T03:25:00Z):** Documentation sweep for migrate --restore changes completed by McManus. Updated cli.md, disaster-recovery.md, keep-my-squad.md, README.md to reflect new command and flag. Migration-related docs now synchronized.
104 changes: 104 additions & 0 deletions .squad/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2001,4 +2001,108 @@ This is low-effort, high-value — a broken link on the GitHub Pages site erodes
**Judgment Call:** Preserved both origin/insider (singular, existing) and origin/insiders (plural, new). Conservative approach pending Brady confirmation.
**Action Required:** Brady to decide: keep origin/insiders (matches decision) + delete origin/insider, or keep origin/insider and delete origin/insiders.
**Status:** Infrastructure ready. Awaiting final branch naming confirmation.
### 2026-03-05: Documentation Sweep — migrate --restore Changes
**By:** McManus (DevRel)
**What:** Performed targeted documentation sweep to synchronize docs after adding `squad migrate` command and `--restore` flag. Updated 4 files:
- docs/reference/cli.md (added `squad migrate` command documentation)
- docs/scenarios/disaster-recovery.md (modernized `.ai-team/` → `.squad/`, all paths updated)
- docs/scenarios/keep-my-squad.md (updated commands and examples)
- README.md (updated command table, added 16th command)

Verified 3 files already consistent:
- docs/get-started/migration.md (full `squad migrate` coverage present)
- docs/scenarios/upgrading.md (already references migrate for major upgrades)
- docs/scenarios/troubleshooting.md (already documents --restore)

**Why:** After PR adding migrate command merged, reference docs, README, and scenario docs needed consistency sweep. Users need to know to use `squad migrate --restore` for recovery, not manual steps.

**Outcomes:**
1. All migration-related docs now synchronously reference `squad migrate` and `--restore` flag
2. Disaster recovery guidance modernized — users know to use migrate, not manual restore
3. No manual restore steps remain — all restore guidance points to `squad migrate --restore`
4. General scenario docs (non-migration) still reference old distribution methods, deferred for future sweep

**Implications:** Users upgrading from v0.5.4 or recovering from `.squad/` corruption now have clear, consistent guidance pointing to migrate command.

# Hockney — Migration Test Patterns

**Date:** 2026-03-05
**Status:** Complete
**Requestor:** williamhallatt

## Decision

Test suite patterns for migration command and cast guard are now standardized:

### 1. Error Path Testing (process.exit)

Migration calls `process.exit(1)` on error. Mock pattern:

```typescript
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((code?: any) => {
throw new Error(`process.exit: ${code}`);
});

await expect(runMigrate(...)).rejects.toThrow('process.exit: 1');
```

### 2. SDK Mocking for CLI Commands

CLI commands that call SDK functions must mock them:

```typescript
vi.mock('@bradygaster/squad-sdk', () => ({
initSquad: vi.fn(async (opts) => {
// Simulate filesystem changes
mkdirSync(join(opts.teamRoot, '.squad'), { recursive: true });
}),
}));
```

### 3. Temp Directory Hygiene

Use OS temp dirs with cleanup:

```typescript
beforeEach(() => {
testDir = mkdtempSync(join(tmpdir(), 'squad-migrate-test-'));
});

afterEach(() => {
if (existsSync(testDir)) {
rmSync(testDir, { recursive: true, force: true });
}
});
```

### 4. Guard Logic Testing (cast.ts)

Test both the positive and negative cases:
- **Negative:** File exists with content → guard fires, no overwrite
- **Positive:** File absent or empty → write happens

```typescript
it('should NOT overwrite an existing non-empty charter.md', async () => {
writeFileSync(join(agentDir, 'charter.md'), '# Real Charter\n');
await createTeam(testDir, proposal);
expect(readFileSync(join(agentDir, 'charter.md'), 'utf8')).toBe('# Real Charter\n');
});
```

## Coverage Achieved

- **19 tests** for `migrate.ts` (dry-run, normal flow, legacy `.ai-team/`, rollback, restore)
- **11 tests** for `cast.ts` guard logic (charter.md and history.md protection)
- **All 30 tests pass** on first run

## Why This Matters

1. Migration is a high-risk operation (user data). Tests verify rollback on error.
2. Cast guard prevents accidental overwrites when `/init` is triggered after migrate.
3. These patterns are reusable for future CLI command tests.

## Related

- Branch: `williamhallatt/197-migration-experience`
- Files: `test/migrate-command.test.ts`, `test/cast-guard.test.ts`
- Blocking: None — tests verify existing implementation
22 changes: 22 additions & 0 deletions .squad/log/2026-03-05T03-25-00Z-doc-sweep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Session: Documentation Sweep for migrate --restore (2026-03-05)

**Agent:** McManus (DevRel)
**Duration:** Background task
**Issue:** #197

## What Happened
Targeted documentation sweep to synchronize CLI docs after adding `squad migrate` command and `--restore` flag.

**Updated:** 4 files
- docs/reference/cli.md (added migrate command)
- docs/scenarios/disaster-recovery.md (modernized paths, .ai-team/ → .squad/)
- docs/scenarios/keep-my-squad.md (updated commands)
- README.md (updated command table)

**Already consistent:** 3 files
- docs/get-started/migration.md
- docs/scenarios/upgrading.md
- docs/scenarios/troubleshooting.md

## Outcome
All migration docs synchronized. Disaster recovery is clearer.
25 changes: 25 additions & 0 deletions .squad/log/2026-03-05T04-02-47Z-migrate-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Session Log: Migration Test Suite

**Date:** 2026-03-05T04-02-47Z
**Agents:** Hockney (Tester), Breedan (E2E Test Engineer)
**Topic:** Test coverage for squad migrate command and cast guard

## Summary
Spawned two agents to fill test gaps on #197 migration fixes. Hockney wrote 30 unit/integration tests (migrate-command, cast-guard). Breedan wrote 23 E2E tests (migrate-e2e). All 53 tests pass on first run.

## Coverage Added
1. **test/migrate-command.test.ts** (19 tests) — migrate, restore, dry-run, rollback, .first-run cleanup, legacy .ai-team/ support
2. **test/cast-guard.test.ts** (11 tests) — createTeam() charter/history guard, prevent overwrites
3. **test/migrate-e2e.test.ts** (23 tests) — full CLI flow, shell reinit guard, backup/restore

## Key Patterns Documented
- Error path testing (process.exit mocking)
- SDK command mocking
- Temp directory hygiene
- Guard logic (positive/negative cases)

## Decisions
- Test patterns published to `.squad/decisions/inbox/hockney-migrate-tests.md`

## Status
All tests passing. Ready for commit.
34 changes: 34 additions & 0 deletions .squad/orchestration-log/2026-03-05T03-25-00Z-mcmanus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Orchestration: McManus Documentation Sweep (2026-03-05T03:25:00Z)

**Agent:** McManus (DevRel)
**Model:** claude-haiku-4.5
**Mode:** Background
**Requested by:** williamhallatt
**Status:** ✅ Complete

## Objective
Documentation sweep for `squad migrate --restore` changes. Ensure CLI reference, README, and scenario docs consistently reflect new command and flag.

## Work Completed
- Reviewed docs/reference/cli.md — added `squad migrate` command documentation
- Reviewed docs/scenarios/disaster-recovery.md — updated `.ai-team/` → `.squad/`, modernized paths
- Reviewed docs/scenarios/keep-my-squad.md — updated commands and examples
- Reviewed README.md — updated command table
- Verified docs/get-started/migration.md — already accurate
- Verified docs/scenarios/upgrading.md — already accurate
- Verified docs/scenarios/troubleshooting.md — already accurate

## Files Modified
- `docs/reference/cli.md`
- `docs/scenarios/disaster-recovery.md`
- `docs/scenarios/keep-my-squad.md`
- `README.md`

## Decisions Merged
- Decision: mcmanus-doc-sweep-migrate.md merged into decisions.md

## Key Outcome
All migration-related documentation now synchronously references `squad migrate` and `--restore` flag. Disaster recovery guidance is modernized. Non-migration scenario docs (general, mid-project) deferred for future sweep.

---
**End time:** 2026-03-05T03:25:00Z
41 changes: 41 additions & 0 deletions .squad/orchestration-log/2026-03-05T04-02-47Z-breedan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Breedan Orchestration — 2026-03-05T04-02-47Z

## Agent Info
- **Agent:** Breedan (E2E Test Engineer)
- **Model:** claude-sonnet-4.5
- **Mode:** background

## Work Completed
Created `test/migrate-e2e.test.ts` with 23 end-to-end tests exercising the built CLI via `execFileSync`, covering:
- Full migration flow (`.ai-team/` → `.squad/` with data preservation)
- Dry-run mode with no side effects
- Backup creation and restore operations
- Legacy `.ai-team/` directory detection and handling
- Shell reinit guard (prevents re-initializing after migration)
- Auto-rollback on error scenarios
- Team root resolution and `.first-run` cleanup
- Exit code validation

## Test Results
- **migrate-e2e.test.ts:** 23 tests ✓ PASS
- **All E2E assertions pass** — CLI behaves correctly end-to-end

## Test Coverage Summary
Combined with Hockney's unit tests:
- **Total test suite:** 53 tests (19 unit + 11 integration + 23 E2E)
- **Coverage areas:** migrate command, restore, backup discovery, guard logic, full CLI flow
- **All tests passing** on first run

## Files Changed
- `test/migrate-e2e.test.ts` (new)

## Integration Points Validated
- CLI compilation and execution
- Filesystem operations (backup, restore, migration)
- Error handling and rollback
- Guard patterns (shell reinit, .first-run cleanup)

## Next Steps
- Scribe to write session log
- Merge orchestration logs and decision inbox
- Commit all test files and squad/ changes
Loading
Loading