@aiaiai-pt/martha-cli 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +104 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11077,7 +11077,7 @@ import { createInterface as createInterface2 } from "node:readline";
11077
11077
  init_errors();
11078
11078
 
11079
11079
  // src/version.ts
11080
- var CLI_VERSION = "0.14.0";
11080
+ var CLI_VERSION = "0.15.0";
11081
11081
 
11082
11082
  // src/commands/sessions.ts
11083
11083
  function relativeTime(iso) {
@@ -18746,6 +18746,108 @@ function registerSkillCommand(program2) {
18746
18746
  });
18747
18747
  }
18748
18748
 
18749
+ // src/commands/update.ts
18750
+ import { spawnSync } from "node:child_process";
18751
+ init_errors();
18752
+ var PKG = "@aiaiai-pt/martha-cli";
18753
+ var LATEST_URL = "https://registry.npmjs.org/@aiaiai-pt%2Fmartha-cli/latest";
18754
+ function compareSemver2(a, b) {
18755
+ const parse = (v) => v.replace(/^v/, "").split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
18756
+ const pa = parse(a);
18757
+ const pb = parse(b);
18758
+ for (let i = 0;i < Math.max(pa.length, pb.length); i++) {
18759
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
18760
+ if (d !== 0)
18761
+ return d > 0 ? 1 : -1;
18762
+ }
18763
+ return 0;
18764
+ }
18765
+ async function fetchLatest() {
18766
+ try {
18767
+ const res = await fetch(LATEST_URL, {
18768
+ headers: { accept: "application/json" }
18769
+ });
18770
+ if (!res.ok)
18771
+ return null;
18772
+ const j = await res.json();
18773
+ return j.version ?? null;
18774
+ } catch {
18775
+ return null;
18776
+ }
18777
+ }
18778
+ function resolveManager(explicit) {
18779
+ if (explicit) {
18780
+ if (explicit !== "npm" && explicit !== "bun") {
18781
+ throw new CLIError(`--manager must be 'npm' or 'bun' (got '${explicit}').`, 4 /* Validation */);
18782
+ }
18783
+ return explicit;
18784
+ }
18785
+ return process.versions?.bun ? "bun" : "npm";
18786
+ }
18787
+ function registerUpdateCommand(program2) {
18788
+ program2.command("update").description("Update the Martha CLI to the latest published version").option("--check", "Report whether a newer version is available; don't install").option("--yes", "Skip the confirmation prompt").option("--manager <pm>", "Package manager to use: npm | bun (default: auto)").action(async (opts) => {
18789
+ const isJson = !!program2.opts().json;
18790
+ const latest = await fetchLatest();
18791
+ if (!latest) {
18792
+ throw new CLIError(`Could not reach the npm registry to determine the latest version (${LATEST_URL}). Check your network.`, 1 /* Error */);
18793
+ }
18794
+ const updateAvailable = compareSemver2(CLI_VERSION, latest) < 0;
18795
+ if (opts.check) {
18796
+ if (isJson) {
18797
+ console.log(JSON.stringify({
18798
+ current: CLI_VERSION,
18799
+ latest,
18800
+ update_available: updateAvailable
18801
+ }, null, 2));
18802
+ } else if (updateAvailable) {
18803
+ console.log(`Update available: ${CLI_VERSION} ${source_default.dim("→")} ${source_default.green(latest)}. Run ${source_default.cyan("martha update")}.`);
18804
+ } else {
18805
+ console.log(`Up to date (${CLI_VERSION}).`);
18806
+ }
18807
+ if (updateAvailable)
18808
+ process.exitCode = 1;
18809
+ return;
18810
+ }
18811
+ if (!updateAvailable) {
18812
+ if (isJson) {
18813
+ console.log(JSON.stringify({
18814
+ current: CLI_VERSION,
18815
+ latest,
18816
+ updated: false,
18817
+ reason: "already_latest"
18818
+ }, null, 2));
18819
+ } else {
18820
+ console.log(`Already on the latest version (${CLI_VERSION}).`);
18821
+ }
18822
+ return;
18823
+ }
18824
+ if (!opts.yes) {
18825
+ if (!process.stdin.isTTY) {
18826
+ throw new CLIError(`Update available (${CLI_VERSION} → ${latest}). Re-run with --yes to install.`, 4 /* Validation */);
18827
+ }
18828
+ const ok = await confirm(`Update martha-cli ${CLI_VERSION} → ${latest}?`);
18829
+ if (!ok) {
18830
+ console.error("Cancelled.");
18831
+ return;
18832
+ }
18833
+ }
18834
+ const pm = resolveManager(opts.manager);
18835
+ const args = pm === "bun" ? ["install", "-g", `${PKG}@latest`] : ["i", "-g", `${PKG}@latest`];
18836
+ if (!isJson) {
18837
+ console.error(source_default.dim(`$ ${pm} ${args.join(" ")}`));
18838
+ }
18839
+ const r = spawnSync(pm, args, { stdio: isJson ? "ignore" : "inherit" });
18840
+ if (r.error || r.status !== 0) {
18841
+ throw new CLIError(`${pm} install failed${r.error ? `: ${r.error.message}` : ` (exit ${r.status})`}. ` + `Try manually: ${pm} ${args.join(" ")}`, 1 /* Error */);
18842
+ }
18843
+ if (isJson) {
18844
+ console.log(JSON.stringify({ current: CLI_VERSION, latest, updated: true, manager: pm }, null, 2));
18845
+ } else {
18846
+ console.log(source_default.green(`Updated to ${latest}.`));
18847
+ }
18848
+ });
18849
+ }
18850
+
18749
18851
  // src/index.ts
18750
18852
  var program2 = new Command;
18751
18853
  program2.name("martha").description("Terminal-first client for the Martha AI platform").version(CLI_VERSION).option("--profile <name>", "Use a named profile").option("--json", "Machine-readable JSON output").option("--quiet", "Suppress non-essential output").option("--verbose", "Verbose logging").option("--no-color", "Disable color output").option("--api-url <url>", "Override API base URL");
@@ -18813,6 +18915,7 @@ registerPolicyCommands(program2);
18813
18915
  registerInitCommand(program2);
18814
18916
  registerDoctorCommand(program2);
18815
18917
  registerSkillCommand(program2);
18918
+ registerUpdateCommand(program2);
18816
18919
  async function main() {
18817
18920
  try {
18818
18921
  await program2.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/martha-cli",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Terminal-first client for the Martha AI platform",
5
5
  "homepage": "https://docs.martha.nomadriver.co",
6
6
  "repository": {