@persistmemory/cli 0.2.2 → 0.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.
package/dist/bin.js CHANGED
@@ -1527,7 +1527,7 @@ function shortDate(iso) {
1527
1527
  }
1528
1528
 
1529
1529
  // src/help.ts
1530
- var VERSION = true ? "0.2.2" : versionFromManifest();
1530
+ var VERSION = true ? "0.3.0" : versionFromManifest();
1531
1531
  var PACKAGE = "@persistmemory/cli";
1532
1532
  var HELP = `
1533
1533
  pm \u2014 PersistMemory from your terminal
@@ -1548,8 +1548,6 @@ var HELP = `
1548
1548
  auth login sign in through the browser
1549
1549
  auth login --api-key sign in with a key, for CI and headless machines
1550
1550
 
1551
- agent --root <dir> answer file requests from your assistants,
1552
- reading only inside the folders you name
1553
1551
  auth status who am I, and does the server still accept it
1554
1552
  auth logout forget the stored credential
1555
1553
 
@@ -1561,12 +1559,23 @@ var HELP = `
1561
1559
  setup --new-space "Acme" create one and use it
1562
1560
 
1563
1561
  spaces list your Spaces
1564
- spaces create <name> make a new one
1562
+ spaces create "Acme" make a new one
1563
+ spaces delete "Acme" --memories keep|delete
1564
+ delete one \u2014 you must say what happens
1565
+ to what is in it
1566
+ spaces merge "A" "B" --name "C" a new Space holding both, originals kept
1565
1567
 
1566
1568
  remember <text> capture text
1567
1569
  remember - capture whatever is piped in
1568
1570
  remember --file <path> capture a file's contents
1569
1571
 
1572
+ agent --root <dir> [--root ...] answer file requests from this machine \u2014
1573
+ nothing outside those folders is read.
1574
+ It stays in the foreground. Background it,
1575
+ and stop it later, with:
1576
+ nohup pm agent --root ~/Desktop &
1577
+ pkill -f "pm agent"
1578
+
1570
1579
  search <query> search your memory
1571
1580
  list memories the most recent memories
1572
1581
  list spaces your Spaces
@@ -2097,14 +2106,18 @@ async function currentCredential(resolved, deps) {
2097
2106
 
2098
2107
  // src/context.ts
2099
2108
  import { createInterface } from "node:readline";
2100
- async function askOnTty(prompt) {
2109
+ async function askOnTty(prompt, input = process.stdin, output = process.stdout) {
2101
2110
  return new Promise((resolve8) => {
2102
- const readline = createInterface({ input: process.stdin, output: process.stdout });
2111
+ const readline = createInterface({ input, output });
2112
+ let answered = false;
2103
2113
  readline.question(prompt, (answer3) => {
2104
- readline.close();
2114
+ answered = true;
2105
2115
  resolve8(answer3.trim());
2116
+ readline.close();
2117
+ });
2118
+ readline.once("close", () => {
2119
+ if (!answered) resolve8("");
2106
2120
  });
2107
- readline.once("close", () => resolve8(""));
2108
2121
  });
2109
2122
  }
2110
2123
  var ETX = "";
@@ -2115,11 +2128,15 @@ async function readSecretFromTty(prompt) {
2115
2128
  if (!input.isTTY) {
2116
2129
  return new Promise((resolve8) => {
2117
2130
  const readline = createInterface({ input });
2131
+ let answered = false;
2118
2132
  readline.once("line", (line) => {
2119
- readline.close();
2133
+ answered = true;
2120
2134
  resolve8(line.trim());
2135
+ readline.close();
2136
+ });
2137
+ readline.once("close", () => {
2138
+ if (!answered) resolve8("");
2121
2139
  });
2122
- readline.once("close", () => resolve8(""));
2123
2140
  });
2124
2141
  }
2125
2142
  process.stdout.write(prompt);
@@ -2441,7 +2458,14 @@ async function agentCommand(context) {
2441
2458
  context.error(
2442
2459
  "Say which folders this machine may read from, and nothing outside them will be:"
2443
2460
  );
2444
- context.error(" pm agent --root ~/notes --root ~/projects");
2461
+ context.error("");
2462
+ context.error(" pm agent --root ~/Desktop --root ~/Documents");
2463
+ context.error("");
2464
+ context.error("It stays in the foreground. To leave it running:");
2465
+ context.error("");
2466
+ context.error(" nohup pm agent --root ~/Desktop > ~/agent.log 2>&1 &");
2467
+ context.error("");
2468
+ context.error('And to stop it later: pkill -f "pm agent"');
2445
2469
  return 1;
2446
2470
  }
2447
2471
  for (const root of roots) {
@@ -3707,6 +3731,67 @@ var spaceFields = [
3707
3731
  { header: "name", value: (s) => s.name },
3708
3732
  { header: "kind", value: (s) => s.kind }
3709
3733
  ];
3734
+ async function deleteSpaceCommand(context) {
3735
+ const named = context.args.words.slice(2).join(" ").trim();
3736
+ if (named === "") {
3737
+ context.error('Which Space? Try `pm spaces delete "Acme" --memories keep`.');
3738
+ return 2;
3739
+ }
3740
+ const memories = stringFlag(context.args, "memories");
3741
+ if (memories !== "keep" && memories !== "delete") {
3742
+ context.error("Say what happens to what is in it \u2014 there is no default:");
3743
+ context.error("");
3744
+ context.error(` pm spaces delete "${named}" --memories keep the memories survive`);
3745
+ context.error(` pm spaces delete "${named}" --memories delete they go with it`);
3746
+ return 2;
3747
+ }
3748
+ const client = await context.client();
3749
+ const { data } = await client.spaces.list({ limit: 200 }).first();
3750
+ const found = named.startsWith("space_") ? data.find((one) => one.id === named) : data.find((one) => one.name.toLowerCase() === named.toLowerCase());
3751
+ if (!found) {
3752
+ context.error(`No Space called "${named}". Run \`pm spaces list\` to see them.`);
3753
+ return 1;
3754
+ }
3755
+ const result = await client.spaces.delete(found.id, { memories });
3756
+ if (context.flags.output !== "table") {
3757
+ context.print(JSON.stringify({ id: found.id, ...result }, void 0, 2));
3758
+ return 0;
3759
+ }
3760
+ context.print(`Deleted "${found.name}".`);
3761
+ context.print(` ${result.deleted} memories deleted, ${result.kept} kept`);
3762
+ return 0;
3763
+ }
3764
+ async function mergeSpacesCommand(context) {
3765
+ const named = context.args.words.slice(2);
3766
+ const name = stringFlag(context.args, "name");
3767
+ if (named.length < 2 || !name) {
3768
+ context.error("Two or more Spaces, and a name for the one this makes:");
3769
+ context.error("");
3770
+ context.error(' pm spaces merge "Work" "Personal" --name "Everything"');
3771
+ return 2;
3772
+ }
3773
+ const client = await context.client();
3774
+ const { data } = await client.spaces.list({ limit: 200 }).first();
3775
+ const ids = [];
3776
+ for (const one of named) {
3777
+ const found = one.startsWith("space_") ? data.find((space2) => space2.id === one) : data.find((space2) => space2.name.toLowerCase() === one.toLowerCase());
3778
+ if (!found) {
3779
+ context.error(`No Space called "${one}". Run \`pm spaces list\` to see them.`);
3780
+ return 1;
3781
+ }
3782
+ ids.push(found.id);
3783
+ }
3784
+ const { space, added } = await client.spaces.merge({ sourceIds: ids, name });
3785
+ if (context.flags.output !== "table") {
3786
+ context.print(renderOne(space, spaceFields, { format: context.flags.output }));
3787
+ return 0;
3788
+ }
3789
+ context.print(`Created "${space.name}" from ${ids.length} Spaces, holding ${added} memories.`);
3790
+ context.print(` id ${space.id}`);
3791
+ context.print("");
3792
+ context.print("The Spaces it drew from are unchanged \u2014 nothing was moved or deleted.");
3793
+ return 0;
3794
+ }
3710
3795
 
3711
3796
  // src/index.ts
3712
3797
  async function run(deps) {
@@ -3862,8 +3947,10 @@ async function dispatch(context) {
3862
3947
  case "spaces":
3863
3948
  case "space":
3864
3949
  if (noun === "create" || noun === "new") return createSpaceCommand(context);
3950
+ if (noun === "delete" || noun === "remove") return deleteSpaceCommand(context);
3951
+ if (noun === "merge") return mergeSpacesCommand(context);
3865
3952
  if (noun === void 0 || noun === "list") return listSpacesCommand(context);
3866
- context.error(`Cannot "pm spaces ${noun}". Try list or create.`);
3953
+ context.error(`Cannot "pm spaces ${noun}". Try list, create, delete or merge.`);
3867
3954
  return 2;
3868
3955
  case "list":
3869
3956
  if (noun === "memories" || noun === "memory") return listMemoriesCommand(context);