Skip to content

feat(cli): add squad update-check --json for tooling/CI#1440

Open
omercangumus wants to merge 1 commit into
bradygaster:devfrom
omercangumus:omercangumus/1170-update-check-json
Open

feat(cli): add squad update-check --json for tooling/CI#1440
omercangumus wants to merge 1 commit into
bradygaster:devfrom
omercangumus:omercangumus/1170-update-check-json

Conversation

@omercangumus

@omercangumus omercangumus commented Jul 3, 2026

Copy link
Copy Markdown

What

Adds squad update-check [--json] [--refresh], a new CLI command that reports the CLI's cached update status.

Why

self-update.ts already maintains an OS-specific cache (update-check.json) for the background startup update check, but anything outside the CLI process that wants this information (editor extensions, coordinator instructions, CI scripts) currently has to replicate the OS-specific cache path logic, parse the JSON, check TTL freshness, and handle the no-cache-yet case. A dedicated command gives them a single, stable interface.

Closes #1170

How

  • New packages/squad-cli/src/cli/commands/update-check.ts:
    • detectChannel(version) derives the release channel (stable/preview/insider) from the version's prerelease tag, reusing the ReleaseChannel type and parseVersion from upgrade.ts.
    • formatCacheAge(ms) formats a millisecond duration as an ISO 8601 duration string (e.g. PT2H15M), matching the schema in the issue.
    • runUpdateCheck(currentVersion, { refresh }) — without refresh, only reads the existing cache (no network call, per the acceptance criteria); with refresh, always re-fetches from npm and updates the cache.
    • runUpdateCheckCommand(args) — CLI entry point; handles --json/--refresh, the SQUAD_NO_UPDATE_CHECK=1 opt-out, and returns the process exit code.
  • Exported getCachePath, fetchLatestVersion, and writeCache from self-update.ts (previously private) so the new command reuses the same cache I/O instead of duplicating it.
  • Wired into cli-entry.ts routing, the top-level squad help listing, and a dedicated squad update-check --help block in command-help.ts.
  • Added a ./commands/update-check subpath export to packages/squad-cli/package.json, following the existing convention for CLI command modules (e.g. ./commands/doctor).
  • Documented in README.md's command table and added a new section to docs/src/content/docs/features/self-upgrade.md.

Judgment calls where the issue was ambiguous (flagging for review):

  • No cache + no --refresh: reports latest: null, updateAvailable: false, exit code 0, with a human-readable hint to run --refresh. Chosen because the acceptance criteria explicitly says "No new network calls without --refresh", ruling out a fallback fetch.
  • Transport failure during --refresh: returns { ..., error: "Failed to reach the npm registry" } (an additive field beyond the issue's schema) and exit code 2.

Testing

  • Added test/cli/update-check.test.ts (21 tests): detectChannel branches, formatCacheAge formatting, runUpdateCheck cache-read/refresh/error paths (mocking self-update.js's network/cache functions — no real HTTP calls or shared-cache-path writes), and runUpdateCheckCommand exit codes / --json output / SQUAD_NO_UPDATE_CHECK opt-out.
  • Updated test/cli/command-help.test.ts's hardcoded command list to include update-check (was failing before this fix).
  • npx vitest run test/cli/update-check.test.ts test/cli/command-help.test.ts — 35 passed.
  • npm run build — passes.
  • npm run lint (tsc --noEmit) — passes.
  • npm run lint:eslint — 0 errors (pre-existing warnings only, unrelated to this change).
  • npm run lint:docs (markdownlint + cspell) — passes, since README.md and a docs page changed.
  • npm test (full suite) and npx vitest run test/cli/ — no regressions from this change. Verified test/cli/rc.test.ts, test/cli/start.test.ts, test/cli/watch.test.ts time out identically on a clean upstream/dev checkout before my changes (pre-existing local Windows-environment flakiness, not something this PR introduces).

⚠️ Quick Check

  • Changeset added: .changeset/feat-1170-update-check-json.md (minor bump, @bradygaster/squad-cli), since this adds a new CLI command (packages/squad-cli/src/)

PR Readiness Checklist

Branch & Commit

  • Branch created from dev
  • Branch is up to date with dev
  • Verified diff contains only intended changes (git diff --cached --stat)
  • PR is not in draft mode — will mark ready once CI is green
  • Commit history is clean (single commit)

Build & Test

  • npm run build passes
  • npm test passes (see testing notes above for pre-existing unrelated local failures)
  • npm run lint passes (type check clean)
  • npm run lint:eslint passes (0 errors)

Changeset

  • Changeset added (minor, @bradygaster/squad-cli)

Docs

  • README.md command table updated
  • Docs feature page updated (docs/src/content/docs/features/self-upgrade.md) — new capability documented under the existing self-upgrade feature, not a new page

Exports

  • package.json subpath export added (./commands/update-check), matching the convention for other CLI command modules

Breaking Changes

None.

Waivers

None.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🏗️ Architectural Review

⚠️ Architectural review: 1 warning(s).

Severity Category Finding Files
🟡 warning bootstrap-area 1 file(s) in the bootstrap area (packages/squad-cli/src/cli/core/) were modified. These files must maintain zero external dependencies. Review carefully. packages/squad-cli/src/cli/core/command-help.ts

Automated architectural review — informational only.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🟡 Impact Analysis — PR #1440

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 10
Files added 3
Files modified 7
Files deleted 0
Modules touched 4
Critical files 1

🎯 Risk Factors

  • 10 files changed (6-20 → MEDIUM)
  • 4 modules touched (2-4 → MEDIUM)
  • Critical files touched: packages/squad-cli/package.json

📦 Modules Affected

docs (1 file)
  • docs/src/content/docs/features/self-upgrade.md
root (2 files)
  • .changeset/feat-1170-update-check-json.md
  • README.md
squad-cli (5 files)
  • packages/squad-cli/package.json
  • packages/squad-cli/src/cli-entry.ts
  • packages/squad-cli/src/cli/commands/update-check.ts
  • packages/squad-cli/src/cli/core/command-help.ts
  • packages/squad-cli/src/cli/self-update.ts
tests (2 files)
  • test/cli/command-help.test.ts
  • test/cli/update-check.test.ts

⚠️ Critical Files

  • packages/squad-cli/package.json

This report is generated automatically for every PR. See #733 for details.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 98769ef

PR Scope: 📦🔧 Mixed (product + infrastructure)

⚠️ 1 item(s) to address before review

Status Check Details
Single commit 1 commit — clean history
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present Changeset file found
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved No Copilot review threads
CI passing All checks passing

Files Changed (10 files, +477 −4)

File +/−
.changeset/feat-1170-update-check-json.md +12 −0
README.md +1 −0
docs/src/content/docs/features/self-upgrade.md +39 −0
packages/squad-cli/package.json +4 −0
packages/squad-cli/src/cli-entry.ts +8 −0
packages/squad-cli/src/cli/commands/update-check.ts +166 −0
packages/squad-cli/src/cli/core/command-help.ts +12 −0
packages/squad-cli/src/cli/self-update.ts +5 −4
test/cli/command-help.test.ts +1 −0
test/cli/update-check.test.ts +229 −0

Total: +477 −4


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@omercangumus omercangumus marked this pull request as ready for review July 3, 2026 06:17
Comment thread packages/squad-cli/src/cli-entry.ts Outdated
console.log(` --global (personal squad dir)`);
console.log(` --no-workflows (skip CI setup)`);
console.log(` --preset <name> (apply a preset after init)`);
console.log(` --roles (use base roles)`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems like the change is in hidden chars or something. Please fix. There are a bunch of other files with same whitespace changes

Adds a squad update-check command that reads the existing
update-check.json cache (already maintained by self-update.ts) and
reports current/latest version, release channel, and update
availability, instead of requiring every consumer (editor extensions,
coordinator instructions, CI scripts) to replicate OS-specific cache
path resolution and TTL-freshness checks themselves.

- --json emits structured output matching the schema proposed in bradygaster#1170
- --refresh bypasses the cache and re-fetches from the npm registry
- Exit codes: 0 (up to date / no cache yet), 1 (update available),
  2 (transport failure during --refresh)
- Honors SQUAD_NO_UPDATE_CHECK=1 (no network call, silent exit 0)

Release channel is derived from the running version's prerelease tag
(stable/preview/insider) via the existing ReleaseChannel type in
upgrade.ts. cacheAge is formatted as an ISO 8601 duration (e.g.
"PT2H15M"). Exported getCachePath/fetchLatestVersion/writeCache from
self-update.ts for reuse instead of duplicating cache I/O.

Closes bradygaster#1170

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@omercangumus omercangumus force-pushed the omercangumus/1170-update-check-json branch from 2579618 to 98769ef Compare July 3, 2026 11:52
@omercangumus

Copy link
Copy Markdown
Author

yeah, windows autocrlf snuck in there and flipped a bunch of untouched lines in cli-entry.ts to CRLF. reset the file to upstream and reapplied just the real hunks, diff is down to the actual 10 files now (477 insertions, 4 deletions), no more phantom removes/adds.

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: squad update-check --json — expose cached update status for tooling

2 participants