@persistmemory/cli 0.3.2 → 0.4.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.
package/dist/index.js CHANGED
@@ -1402,7 +1402,7 @@ function shortDate(iso) {
1402
1402
  }
1403
1403
 
1404
1404
  // src/help.ts
1405
- var VERSION = true ? "0.3.2" : versionFromManifest();
1405
+ var VERSION = true ? "0.4.0" : versionFromManifest();
1406
1406
  var PACKAGE = "@persistmemory/cli";
1407
1407
  var HELP = `
1408
1408
  pm \u2014 PersistMemory from your terminal
@@ -1444,12 +1444,14 @@ var HELP = `
1444
1444
  remember - capture whatever is piped in
1445
1445
  remember --file <path> capture a file's contents
1446
1446
 
1447
- agent --root <dir> [--root ...] answer file requests from this machine \u2014
1448
- nothing outside those folders is read.
1449
- It stays in the foreground. Background it,
1450
- and stop it later, with:
1451
- nohup pm agent --root ~/Desktop &
1447
+ agent answer file requests from this machine.
1448
+ Reads ~/Desktop, ~/Documents and
1449
+ ~/Downloads by default, and nothing
1450
+ outside them. It stays in the foreground.
1451
+ Background it, and stop it later, with:
1452
+ nohup pm agent > ~/agent.log 2>&1 &
1452
1453
  pkill -f "pm agent"
1454
+ agent --root <dir> [--root ...] choose the folders yourself instead
1453
1455
 
1454
1456
  search <query> search your memory
1455
1457
  list memories the most recent memories
@@ -2318,6 +2320,15 @@ async function upload(apiUrl, token, filename, bytes) {
2318
2320
  if (!stored.attachToken) return { ok: false, error: "the upload returned no reference" };
2319
2321
  return { ok: true, attachToken: stored.attachToken, bytes: bytes.length };
2320
2322
  }
2323
+ function defaultRoots(home = homedir2(), isDirectory = (path) => {
2324
+ try {
2325
+ return statSync2(path).isDirectory();
2326
+ } catch {
2327
+ return false;
2328
+ }
2329
+ }) {
2330
+ return ["Desktop", "Documents", "Downloads"].map((name) => join4(home, name)).filter(isDirectory);
2331
+ }
2321
2332
  var MAX_LISTED = 200;
2322
2333
  function sizeOf(path) {
2323
2334
  const size = statSync2(path).size;
@@ -2335,18 +2346,19 @@ async function agentCommand(context) {
2335
2346
  (one) => resolve3(one.startsWith("~") ? resolve3(homedir2(), one.slice(1).replace(/^[/\\]/, "")) : one)
2336
2347
  );
2337
2348
  if (roots.length === 0) {
2338
- context.error(
2339
- "Say which folders this machine may read from, and nothing outside them will be:"
2349
+ const usual = defaultRoots();
2350
+ if (usual.length === 0) {
2351
+ context.error(
2352
+ "This machine has no Desktop, Documents or Downloads folder, so there is nothing to offer by default. Say which folders it may read from:"
2353
+ );
2354
+ context.error("");
2355
+ context.error(" pm agent --root ~/projects");
2356
+ return 1;
2357
+ }
2358
+ roots.push(...usual);
2359
+ context.print(
2360
+ `Reading from ${usual.map((path) => path.replace(homedir2(), "~")).join(", ")} \u2014 nothing outside them. Use --root to choose your own.`
2340
2361
  );
2341
- context.error("");
2342
- context.error(" pm agent --root ~/Desktop --root ~/Documents");
2343
- context.error("");
2344
- context.error("It stays in the foreground. To leave it running:");
2345
- context.error("");
2346
- context.error(" nohup pm agent --root ~/Desktop > ~/agent.log 2>&1 &");
2347
- context.error("");
2348
- context.error('And to stop it later: pkill -f "pm agent"');
2349
- return 1;
2350
2362
  }
2351
2363
  for (const root of roots) {
2352
2364
  try {
@@ -2991,6 +3003,9 @@ import { existsSync as existsSync7, rmSync } from "node:fs";
2991
3003
  import { spawnSync } from "node:child_process";
2992
3004
  import { dirname as dirname4, resolve as resolve7 } from "node:path";
2993
3005
  import { fileURLToPath } from "node:url";
3006
+ function installArgs(pkg = PACKAGE) {
3007
+ return ["install", "-g", "--prefer-online", `${pkg}@latest`];
3008
+ }
2994
3009
  async function updateCommand(context) {
2995
3010
  const manager = installer();
2996
3011
  if (!manager) {
@@ -2999,19 +3014,38 @@ async function updateCommand(context) {
2999
3014
  );
3000
3015
  return 1;
3001
3016
  }
3017
+ const before = versionOf(manager);
3002
3018
  context.print(`Installing the newest ${PACKAGE}\u2026`);
3003
- const result = spawnSync(manager, ["install", "-g", `${PACKAGE}@latest`], {
3004
- stdio: "inherit"
3005
- });
3019
+ const result = spawnSync(manager, installArgs(), { stdio: "inherit" });
3006
3020
  if (result.status !== 0) {
3007
3021
  context.error(
3008
- "That did not work. If it failed on permissions, do NOT re-run it with sudo \u2014\npoint npm at a directory you own instead:\n npm config set prefix ~/.npm-global\n export PATH=$HOME/.npm-global/bin:$PATH"
3022
+ 'That did not work.\n\nIf npm said ETARGET or "no matching version", its cached list of versions is\nstale. Clear it and try again:\n npm cache clean --force\n\nIf it failed on permissions, do NOT re-run it with sudo \u2014 point npm at a\ndirectory you own instead:\n npm config set prefix ~/.npm-global\n export PATH=$HOME/.npm-global/bin:$PATH'
3009
3023
  );
3010
3024
  return result.status ?? 1;
3011
3025
  }
3012
- context.print("Done. `pm --version` will show the new one.");
3026
+ const after = versionOf(manager);
3027
+ if (after && before && after === before) {
3028
+ context.print(
3029
+ `npm finished, but ${PACKAGE} is still ${after}. That is usually a second copy
3030
+ earlier on your PATH \u2014 check with: which -a pm`
3031
+ );
3032
+ return 1;
3033
+ }
3034
+ context.print(after ? `Done \u2014 now on ${after}.` : "Done.");
3013
3035
  return 0;
3014
3036
  }
3037
+ function versionOf(manager) {
3038
+ const result = spawnSync(manager, ["ls", "-g", "--depth", "0", "--json", PACKAGE], {
3039
+ encoding: "utf8"
3040
+ });
3041
+ if (result.status !== 0 || !result.stdout) return void 0;
3042
+ try {
3043
+ const parsed = JSON.parse(result.stdout);
3044
+ return parsed.dependencies?.[PACKAGE]?.version;
3045
+ } catch {
3046
+ return void 0;
3047
+ }
3048
+ }
3015
3049
  async function uninstallCommand(context) {
3016
3050
  const manager = installer();
3017
3051
  if (!manager) {