@piut/cli 3.2.0 → 3.3.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/cli.js +124 -71
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1824,11 +1824,112 @@ async function logoutCommand() {
1824
1824
  console.log();
1825
1825
  }
1826
1826
 
1827
+ // src/commands/update.ts
1828
+ import chalk7 from "chalk";
1829
+
1830
+ // src/lib/update-check.ts
1831
+ import { execFile } from "child_process";
1832
+ import chalk6 from "chalk";
1833
+ import { confirm as confirm5 } from "@inquirer/prompts";
1834
+ var PACKAGE_NAME = "@piut/cli";
1835
+ function isNpx() {
1836
+ return process.env.npm_command === "exec" || (process.env._?.includes("npx") ?? false);
1837
+ }
1838
+ async function getLatestVersion() {
1839
+ try {
1840
+ const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`);
1841
+ if (!res.ok) return null;
1842
+ const data = await res.json();
1843
+ return data.version ?? null;
1844
+ } catch {
1845
+ return null;
1846
+ }
1847
+ }
1848
+ function isNewer(current, latest) {
1849
+ const [cMaj, cMin, cPat] = current.split(".").map(Number);
1850
+ const [lMaj, lMin, lPat] = latest.split(".").map(Number);
1851
+ if (lMaj !== cMaj) return lMaj > cMaj;
1852
+ if (lMin !== cMin) return lMin > cMin;
1853
+ return lPat > cPat;
1854
+ }
1855
+ function runUpdate() {
1856
+ return new Promise((resolve) => {
1857
+ execFile("npm", ["install", "-g", `${PACKAGE_NAME}@latest`], { timeout: 6e4 }, (err) => {
1858
+ resolve(!err);
1859
+ });
1860
+ });
1861
+ }
1862
+ async function checkForUpdate(currentVersion) {
1863
+ const latest = await getLatestVersion();
1864
+ if (!latest || !isNewer(currentVersion, latest)) return;
1865
+ const npx = isNpx();
1866
+ const updateCmd = npx ? `npx ${PACKAGE_NAME}@latest` : `npm install -g ${PACKAGE_NAME}@latest`;
1867
+ console.log();
1868
+ console.log(brand(" Update available!") + dim(` ${currentVersion} \u2192 ${latest}`));
1869
+ console.log(dim(` Run ${chalk6.bold(updateCmd)} to update`));
1870
+ console.log();
1871
+ if (npx) return;
1872
+ try {
1873
+ const shouldUpdate = await confirm5({
1874
+ message: `Update to v${latest} now?`,
1875
+ default: true
1876
+ });
1877
+ if (shouldUpdate) {
1878
+ console.log(dim(" Updating..."));
1879
+ const ok = await runUpdate();
1880
+ if (ok) {
1881
+ console.log(chalk6.green(` \u2713 Updated to v${latest}`));
1882
+ console.log(dim(" Restart the CLI to use the new version."));
1883
+ process.exit(0);
1884
+ } else {
1885
+ console.log(chalk6.yellow(` Could not auto-update. Run manually:`));
1886
+ console.log(chalk6.bold(` npm install -g ${PACKAGE_NAME}@latest`));
1887
+ console.log();
1888
+ }
1889
+ }
1890
+ } catch {
1891
+ }
1892
+ }
1893
+
1894
+ // src/commands/update.ts
1895
+ var PACKAGE_NAME2 = "@piut/cli";
1896
+ async function updateCommand(currentVersion) {
1897
+ console.log(dim(` Current version: ${currentVersion}`));
1898
+ console.log(dim(" Checking for updates..."));
1899
+ const latest = await getLatestVersion();
1900
+ if (!latest) {
1901
+ console.log(chalk7.yellow(" Could not reach the npm registry. Check your connection."));
1902
+ return;
1903
+ }
1904
+ if (!isNewer(currentVersion, latest)) {
1905
+ console.log(success(` \u2713 You're on the latest version (${currentVersion})`));
1906
+ return;
1907
+ }
1908
+ console.log();
1909
+ console.log(brand(" Update available!") + dim(` ${currentVersion} \u2192 ${latest}`));
1910
+ if (isNpx()) {
1911
+ console.log();
1912
+ console.log(dim(" You're running via npx. Use the latest version with:"));
1913
+ console.log(chalk7.bold(` npx ${PACKAGE_NAME2}@latest`));
1914
+ console.log();
1915
+ return;
1916
+ }
1917
+ console.log(dim(" Updating..."));
1918
+ const ok = await runUpdate();
1919
+ if (ok) {
1920
+ console.log(success(` \u2713 Updated to v${latest}`));
1921
+ console.log(dim(" Restart the CLI to use the new version."));
1922
+ } else {
1923
+ console.log(chalk7.yellow(" Could not auto-update. Run manually:"));
1924
+ console.log(chalk7.bold(` npm install -g ${PACKAGE_NAME2}@latest`));
1925
+ }
1926
+ }
1927
+
1827
1928
  // src/commands/interactive.ts
1828
- import { select as select2, confirm as confirm5, checkbox as checkbox6, password as password3 } from "@inquirer/prompts";
1929
+ import { select as select2, confirm as confirm6, checkbox as checkbox6, password as password3 } from "@inquirer/prompts";
1829
1930
  import fs11 from "fs";
1830
1931
  import path12 from "path";
1831
- import chalk6 from "chalk";
1932
+ import chalk8 from "chalk";
1832
1933
  async function authenticate() {
1833
1934
  const config = readStore();
1834
1935
  let apiKey = config.apiKey;
@@ -1856,7 +1957,7 @@ async function authenticate() {
1856
1957
  try {
1857
1958
  result = await validateKey(apiKey);
1858
1959
  } catch (err) {
1859
- console.log(chalk6.red(` \u2717 ${err.message}`));
1960
+ console.log(chalk8.red(` \u2717 ${err.message}`));
1860
1961
  console.log(dim(" Get a key at https://piut.com/dashboard/keys"));
1861
1962
  process.exit(1);
1862
1963
  }
@@ -1879,7 +1980,7 @@ async function interactiveMenu() {
1879
1980
  console.log(warning(" You haven\u2019t built a brain yet."));
1880
1981
  console.log(dim(" Your brain is how AI tools learn about you \u2014 your projects, preferences, and context."));
1881
1982
  console.log();
1882
- const wantBuild = await confirm5({
1983
+ const wantBuild = await confirm6({
1883
1984
  message: "Build your brain now?",
1884
1985
  default: true
1885
1986
  });
@@ -1895,7 +1996,7 @@ async function interactiveMenu() {
1895
1996
  console.log(warning(" Your brain is built but not deployed yet."));
1896
1997
  console.log(dim(" Deploy it to make your MCP server live so AI tools can read your brain."));
1897
1998
  console.log();
1898
- const wantDeploy = await confirm5({
1999
+ const wantDeploy = await confirm6({
1899
2000
  message: "Deploy your brain now?",
1900
2001
  default: true
1901
2002
  });
@@ -2015,7 +2116,7 @@ async function interactiveMenu() {
2015
2116
  } else if (err instanceof CliError) {
2016
2117
  console.log();
2017
2118
  } else {
2018
- console.log(chalk6.red(` Error: ${err.message}`));
2119
+ console.log(chalk8.red(` Error: ${err.message}`));
2019
2120
  console.log();
2020
2121
  }
2021
2122
  }
@@ -2026,7 +2127,7 @@ async function interactiveMenu() {
2026
2127
  }
2027
2128
  }
2028
2129
  async function handleUndeploy(apiKey) {
2029
- const confirmed = await confirm5({
2130
+ const confirmed = await confirm6({
2030
2131
  message: "Undeploy your brain? AI tools will lose access to your MCP server.",
2031
2132
  default: false
2032
2133
  });
@@ -2038,7 +2139,7 @@ async function handleUndeploy(apiKey) {
2038
2139
  console.log(dim(" Run ") + brand("piut deploy") + dim(" to re-deploy anytime."));
2039
2140
  console.log();
2040
2141
  } catch (err) {
2041
- console.log(chalk6.red(` \u2717 ${err.message}`));
2142
+ console.log(chalk8.red(` \u2717 ${err.message}`));
2042
2143
  }
2043
2144
  }
2044
2145
  async function handleConnectTools(apiKey, validation) {
@@ -2125,7 +2226,7 @@ async function handleDisconnectTools() {
2125
2226
  console.log(dim(" No tools selected."));
2126
2227
  return;
2127
2228
  }
2128
- const proceed = await confirm5({
2229
+ const proceed = await confirm6({
2129
2230
  message: `Disconnect p\u0131ut from ${selected.length} tool(s)?`,
2130
2231
  default: false
2131
2232
  });
@@ -2144,70 +2245,12 @@ async function handleDisconnectTools() {
2144
2245
  console.log();
2145
2246
  }
2146
2247
 
2147
- // src/lib/update-check.ts
2148
- import { execFile } from "child_process";
2149
- import chalk7 from "chalk";
2150
- import { confirm as confirm6 } from "@inquirer/prompts";
2151
- var PACKAGE_NAME = "@piut/cli";
2152
- async function getLatestVersion() {
2153
- try {
2154
- const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`);
2155
- if (!res.ok) return null;
2156
- const data = await res.json();
2157
- return data.version ?? null;
2158
- } catch {
2159
- return null;
2160
- }
2161
- }
2162
- function isNewer(current, latest) {
2163
- const [cMaj, cMin, cPat] = current.split(".").map(Number);
2164
- const [lMaj, lMin, lPat] = latest.split(".").map(Number);
2165
- if (lMaj !== cMaj) return lMaj > cMaj;
2166
- if (lMin !== cMin) return lMin > cMin;
2167
- return lPat > cPat;
2168
- }
2169
- function runUpdate() {
2170
- return new Promise((resolve) => {
2171
- execFile("npm", ["install", "-g", `${PACKAGE_NAME}@latest`], { timeout: 6e4 }, (err) => {
2172
- resolve(!err);
2173
- });
2174
- });
2175
- }
2176
- async function checkForUpdate(currentVersion) {
2177
- const latest = await getLatestVersion();
2178
- if (!latest || !isNewer(currentVersion, latest)) return;
2179
- console.log();
2180
- console.log(brand(" Update available!") + dim(` ${currentVersion} \u2192 ${latest}`));
2181
- console.log(dim(` Run ${chalk7.bold(`npm install -g ${PACKAGE_NAME}@latest`)} to update`));
2182
- console.log();
2183
- try {
2184
- const shouldUpdate = await confirm6({
2185
- message: `Update to v${latest} now?`,
2186
- default: true
2187
- });
2188
- if (shouldUpdate) {
2189
- console.log(dim(" Updating..."));
2190
- const ok = await runUpdate();
2191
- if (ok) {
2192
- console.log(chalk7.green(` \u2713 Updated to v${latest}`));
2193
- console.log(dim(" Restart the CLI to use the new version."));
2194
- process.exit(0);
2195
- } else {
2196
- console.log(chalk7.yellow(` Could not auto-update. Run manually:`));
2197
- console.log(chalk7.bold(` npm install -g ${PACKAGE_NAME}@latest`));
2198
- console.log();
2199
- }
2200
- }
2201
- } catch {
2202
- }
2203
- }
2204
-
2205
2248
  // src/cli.ts
2206
- var VERSION = "3.2.0";
2249
+ var VERSION = "3.3.0";
2207
2250
  function withExit(fn) {
2208
- return async (...args) => {
2251
+ return async (...args2) => {
2209
2252
  try {
2210
- await fn(...args);
2253
+ await fn(...args2);
2211
2254
  } catch (err) {
2212
2255
  if (err instanceof CliError) process.exit(1);
2213
2256
  throw err;
@@ -2215,7 +2258,10 @@ function withExit(fn) {
2215
2258
  };
2216
2259
  }
2217
2260
  var program = new Command();
2218
- program.name("piut").description("Build your AI brain instantly. Deploy it as an MCP server. Connect it to every project.").version(VERSION).hook("preAction", () => checkForUpdate(VERSION)).action(interactiveMenu);
2261
+ program.name("piut").description("Build your AI brain instantly. Deploy it as an MCP server. Connect it to every project.").version(VERSION).hook("preAction", (thisCommand, actionCommand) => {
2262
+ if (actionCommand.name() === "update") return;
2263
+ return checkForUpdate(VERSION);
2264
+ }).action(interactiveMenu);
2219
2265
  program.command("build").description("Build or rebuild your brain from your files").option("-k, --key <key>", "API key").option("--folders <paths>", "Comma-separated folder paths to scan").action(withExit(buildCommand));
2220
2266
  program.command("deploy").description("Publish your MCP server (requires paid account)").option("-k, --key <key>", "API key").action(withExit(deployCommand));
2221
2267
  program.command("connect").description("Add brain references to project config files").option("-k, --key <key>", "API key").option("-y, --yes", "Skip interactive prompts").option("--folders <paths>", "Comma-separated folder paths to scan").action(withExit(connectCommand));
@@ -2224,4 +2270,11 @@ program.command("setup").description("Auto-detect and configure AI tools (MCP co
2224
2270
  program.command("status").description("Show brain, deployment, and connected projects").action(statusCommand);
2225
2271
  program.command("remove").description("Remove all p\u0131ut configurations").action(withExit(removeCommand));
2226
2272
  program.command("logout").description("Remove saved API key").action(logoutCommand);
2273
+ program.command("update").description("Check for and install CLI updates").action(() => updateCommand(VERSION));
2274
+ var args = process.argv.slice(2);
2275
+ if (args.includes("--version") || args.includes("-V")) {
2276
+ console.log(VERSION);
2277
+ await checkForUpdate(VERSION);
2278
+ process.exit(0);
2279
+ }
2227
2280
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piut/cli",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Build your AI brain instantly. Deploy it as an MCP server. Connect it to every project.",
5
5
  "type": "module",
6
6
  "bin": {