Skip to content

feat: add 'clawatch update' command (Issue #55)#71

Closed
GalDayan wants to merge 2 commits intomainfrom
issue-55
Closed

feat: add 'clawatch update' command (Issue #55)#71
GalDayan wants to merge 2 commits intomainfrom
issue-55

Conversation

@GalDayan
Copy link
Copy Markdown
Contributor

Feature

Adds a clawatch update command for easy CLI updates.

Usage

clawatch update         # Check and update interactively
clawatch update --check # Check only, don't install

What it does

  1. Shows current installed version
  2. Fetches latest version from npm registry
  3. Compares versions with clear visual feedback
  4. If outdated: prompts to update (Y/n)
  5. Runs the appropriate update command
  6. Verifies installation and suggests restart

Features

  • ✅ Auto-detects package manager (npm/yarn/pnpm)
  • ✅ Handles npx users gracefully (explains auto-update)
  • --check flag for CI/scripting (check only, no prompt)
  • ✅ Graceful timeout + error for unreachable registry
  • ✅ Permission denied hint (suggests sudo)
  • ✅ Post-update verification
  • ✅ Restart instructions

Edge Cases Handled

  • npx users → explains that npx auto-fetches latest
  • No internet → graceful error with retry message
  • Permission denied → suggests sudo
  • Already up to date → clean exit

Closes #55

Implements #55 — users can now update ClaWatch from within the CLI.

Features:
- Checks current vs latest version from npm registry
- Shows comparison with clear visual feedback
- Prompts before installing (Y/n)
- Auto-detects package manager (npm/yarn/pnpm)
- Handles npx users gracefully (explains auto-update behavior)
- Supports --check flag for check-only mode (no install)
- Graceful error handling for network issues and permission errors
- Post-update verification and restart instructions

Usage:
  clawatch update         # Check and update interactively
  clawatch update --check # Check only, don't install
Copilot AI review requested due to automatic review settings March 18, 2026 20:30
Copy link
Copy Markdown

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 clawatch update CLI command to check the installed version against the latest npm registry release and (optionally) run a package-manager-specific global upgrade.

Changes:

  • Introduces helpers to detect install/package-manager context, fetch latest version from npm registry, and compare versions.
  • Adds clawatch update with interactive update flow plus a --check mode.
  • Adds post-update verification and restart guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread cli/src/cli.ts
}

// Detect package manager
const { manager, global: isGlobal } = detectPackageManager();
Comment thread cli/src/cli.ts Outdated

if (opts.check) {
console.log(chalk.gray(`\n Run "clawatch update" to install.\n`));
process.exit(0);
Comment thread cli/src/cli.ts Outdated
Comment on lines +735 to +744
// Prompt user
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });

const answer = await new Promise<string>((resolve) => {
rl.question(chalk.white(`\n Update now? [Y/n] `), (ans: string) => {
rl.close();
resolve(ans.trim().toLowerCase());
});
});
Comment thread cli/src/cli.ts Outdated
Comment on lines +641 to +658
async function fetchLatestVersion(packageName: string): Promise<string | null> {
const https = require('https');
return new Promise((resolve) => {
const req = https.get(`https://registry.npmjs.org/${packageName}/latest`, { timeout: 10000 }, (res: any) => {
let data = '';
res.on('data', (chunk: string) => { data += chunk; });
res.on('end', () => {
try {
const parsed = JSON.parse(data);
resolve(parsed.version || null);
} catch {
resolve(null);
}
});
});
req.on('error', () => resolve(null));
req.on('timeout', () => { req.destroy(); resolve(null); });
});
Comment thread cli/src/cli.ts
Comment on lines +687 to +690
if (!latestVersion) {
console.log(chalk.red('\n ❌ Could not reach npm registry.'));
console.log(chalk.yellow(' Check your internet connection and try again.\n'));
process.exit(1);
Comment thread cli/src/cli.ts
Comment on lines +661 to +670
// --- Helper: compare semver versions (returns -1, 0, or 1) ---
function compareSemver(a: string, b: string): number {
const pa = a.split('.').map(Number);
const pb = b.split('.').map(Number);
for (let i = 0; i < 3; i++) {
if ((pa[i] || 0) < (pb[i] || 0)) return -1;
if ((pa[i] || 0) > (pb[i] || 0)) return 1;
}
return 0;
}
…ror handling

Addresses all 6 PR #71 review comments:
1. detectPackageManager now detects local installs (node_modules/.bin) and sets global:false
2. --check mode exits with code 1 when update available (for CI/scripts)
3. Prompt checks process.stdin.isTTY before using readline, fails fast in non-interactive envs
4. fetchLatestVersion URL-encodes package name (scoped package support) and checks status codes
5. Error messages distinguish between connectivity, 404, 429, and parse errors
6. compareSemver strips pre-release/build metadata and validates numeric segments
@GalDayan
Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #67 for Issue #55. #67 is more complete: includes update.ts module, tests, and proper structure. #71 was a single-file implementation without tests.

@GalDayan GalDayan closed this Apr 15, 2026
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.

Feature: Add 'clawatch update' command

2 participants