mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 01:14:47 +00:00
fix(cli): make logicsrc update actually check for updates
`update` was three hardcoded console.log lines: it printed 0.1.0 as both current and latest, claimed "already up to date", and never checked or installed anything. `--version` was hardcoded the same way. A version comparison alone could not have worked either. install.sh ships a tarball of the master branch, not a tagged release, and packages/cli/package.json has been 0.1.0 since the repo began, so version equality says "up to date" no matter how far master has moved. The commit is the real signal. - install.sh records ref/commit/version/installed_at to $LOGICSRC_HOME/install.json. The sha comes from GitHub's Accept: application/vnd.github.sha media type, so this needs no jq. It is resolved before the download on purpose: if master moves mid-install we under-report (a spurious update) rather than falsely claim to be current. - update compares the installed commit against the remote ref head, falls back to version comparison for installs predating the manifest, and reports why it reached its verdict instead of just asserting one. --check reports without installing; otherwise it re-runs the installer. - --version now reads the package's real version. Verified against live GitHub in all three states: matching commit, stale commit, and no manifest. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cf475f0f4c
commit
8c3c0bb12a
4 changed files with 339 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { evaluateAccountPolicy, scoreAccountActionRisk } from "@logicsrc/account-core";
|
||||
import { Command } from "commander";
|
||||
|
|
@ -30,6 +31,17 @@ import { exportOpenSpecSummary, importOpenSpec, writeOpenSpecChange } from "./op
|
|||
import { registerOntologyCommands } from "./ontology.js";
|
||||
import { registerPrdCommands } from "./prd.js";
|
||||
import { defaultPluginRegistry } from "./registry.js";
|
||||
import {
|
||||
GH_REPO,
|
||||
INSTALL_URL,
|
||||
fetchRemoteState,
|
||||
installHome,
|
||||
localVersion,
|
||||
readManifest,
|
||||
short,
|
||||
trackedRef,
|
||||
updateStatus
|
||||
} from "./update.js";
|
||||
|
||||
process.stdout.on("error", (error: NodeJS.ErrnoException) => {
|
||||
if (error.code === "EPIPE") {
|
||||
|
|
@ -51,7 +63,7 @@ program
|
|||
.option("--waiting-arcade", "Alias for --arcade.")
|
||||
.option("--waiting-game <game>", "Alias for --arcade=<game>.")
|
||||
.option("--no-arcade", "Disable Waiting Arcade.")
|
||||
.version("0.1.0");
|
||||
.version(localVersion());
|
||||
|
||||
program.action(async (options) => {
|
||||
if (!options.yolo) {
|
||||
|
|
@ -744,12 +756,45 @@ program.command("tui").description("Launch the tmux-friendly TUI.").action(() =>
|
|||
console.log("\nPlugin status:\n" + renderPluginStatus());
|
||||
});
|
||||
|
||||
program.command("update").alias("upgrade").description("Update the local LogicSRC CLI.").action(() => {
|
||||
console.log("Current version: 0.1.0");
|
||||
console.log("Latest version: 0.1.0");
|
||||
console.log("LogicSRC CLI is already up to date.");
|
||||
console.log("Config preserved at $HOME/.logicsrc");
|
||||
});
|
||||
program
|
||||
.command("update")
|
||||
.alias("upgrade")
|
||||
.description("Update the local LogicSRC CLI.")
|
||||
.option("--check", "Report whether an update is available without installing it")
|
||||
.action(async (options) => {
|
||||
const manifest = readManifest();
|
||||
const ref = trackedRef(manifest);
|
||||
const local = { version: localVersion(), commit: manifest?.commit ?? null };
|
||||
|
||||
console.log(`Tracking: ${GH_REPO}@${ref}`);
|
||||
const remote = await fetchRemoteState(ref);
|
||||
const status = updateStatus(local, remote);
|
||||
|
||||
console.log(`Current version: ${status.currentVersion}${local.commit ? ` (${short(local.commit)})` : ""}`);
|
||||
console.log(
|
||||
`Latest version: ${status.latestVersion ?? "unknown"}${status.latestCommit ? ` (${short(status.latestCommit)})` : ""}`
|
||||
);
|
||||
|
||||
if (status.upToDate) {
|
||||
console.log(`LogicSRC CLI is already up to date — ${status.reason}.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Update available — ${status.reason}.`);
|
||||
if (options.check) {
|
||||
console.log(`Run 'logicsrc update' (or: curl -fsSL ${INSTALL_URL} | sh -s -- update) to install it.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Reinstalling from ${INSTALL_URL}…`);
|
||||
const result = spawnSync("sh", ["-c", `curl -fsSL ${INSTALL_URL} | sh -s -- update`], { stdio: "inherit" });
|
||||
if (result.status !== 0) {
|
||||
console.error(`Update failed (exit ${result.status ?? "signal"}). Re-run by hand: curl -fsSL ${INSTALL_URL} | sh -s -- update`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
console.log(`Updated. Install root: ${installHome()} — config preserved at ~/.logicsrc`);
|
||||
});
|
||||
|
||||
program.command("remove").alias("uninstall").option("--purge", "Remove config and auth tokens").description("Remove local LogicSRC CLI.").action((options) => {
|
||||
console.log("Removed LogicSRC CLI.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue