@persistmemory/cli 0.2.3 → 0.3.1

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
@@ -1525,7 +1525,7 @@ function shortDate(iso) {
1525
1525
  }
1526
1526
 
1527
1527
  // src/help.ts
1528
- var VERSION = true ? "0.2.3" : versionFromManifest();
1528
+ var VERSION = true ? "0.3.1" : versionFromManifest();
1529
1529
  var PACKAGE = "@persistmemory/cli";
1530
1530
  var HELP = `
1531
1531
  pm \u2014 PersistMemory from your terminal
@@ -1546,8 +1546,6 @@ var HELP = `
1546
1546
  auth login sign in through the browser
1547
1547
  auth login --api-key sign in with a key, for CI and headless machines
1548
1548
 
1549
- agent --root <dir> answer file requests from your assistants,
1550
- reading only inside the folders you name
1551
1549
  auth status who am I, and does the server still accept it
1552
1550
  auth logout forget the stored credential
1553
1551
 
@@ -1559,12 +1557,23 @@ var HELP = `
1559
1557
  setup --new-space "Acme" create one and use it
1560
1558
 
1561
1559
  spaces list your Spaces
1562
- spaces create <name> make a new one
1560
+ spaces create "Acme" make a new one
1561
+ spaces delete "Acme" --memories keep|delete
1562
+ delete one \u2014 you must say what happens
1563
+ to what is in it
1564
+ spaces merge "A" "B" --name "C" a new Space holding both, originals kept
1563
1565
 
1564
1566
  remember <text> capture text
1565
1567
  remember - capture whatever is piped in
1566
1568
  remember --file <path> capture a file's contents
1567
1569
 
1570
+ agent --root <dir> [--root ...] answer file requests from this machine \u2014
1571
+ nothing outside those folders is read.
1572
+ It stays in the foreground. Background it,
1573
+ and stop it later, with:
1574
+ nohup pm agent --root ~/Desktop &
1575
+ pkill -f "pm agent"
1576
+
1568
1577
  search <query> search your memory
1569
1578
  list memories the most recent memories
1570
1579
  list spaces your Spaces
@@ -2447,7 +2456,14 @@ async function agentCommand(context) {
2447
2456
  context.error(
2448
2457
  "Say which folders this machine may read from, and nothing outside them will be:"
2449
2458
  );
2450
- context.error(" pm agent --root ~/notes --root ~/projects");
2459
+ context.error("");
2460
+ context.error(" pm agent --root ~/Desktop --root ~/Documents");
2461
+ context.error("");
2462
+ context.error("It stays in the foreground. To leave it running:");
2463
+ context.error("");
2464
+ context.error(" nohup pm agent --root ~/Desktop > ~/agent.log 2>&1 &");
2465
+ context.error("");
2466
+ context.error('And to stop it later: pkill -f "pm agent"');
2451
2467
  return 1;
2452
2468
  }
2453
2469
  for (const root of roots) {
@@ -2478,10 +2494,14 @@ async function agentCommand(context) {
2478
2494
  };
2479
2495
  process.on("SIGINT", stop);
2480
2496
  process.on("SIGTERM", stop);
2497
+ const authorization = async () => {
2498
+ const held = await currentCredential(context.resolved, context.session);
2499
+ return held.token;
2500
+ };
2481
2501
  const call = async (path, body) => fetch(`${apiUrl}/api/v1/agent/${path}`, {
2482
2502
  method: "POST",
2483
2503
  headers: {
2484
- authorization: `Bearer ${credential.token}`,
2504
+ authorization: `Bearer ${await authorization()}`,
2485
2505
  "content-type": "application/json"
2486
2506
  },
2487
2507
  body: JSON.stringify(body)
@@ -2522,7 +2542,7 @@ async function agentCommand(context) {
2522
2542
  const { items } = await claimed.json();
2523
2543
  for (const request of items) {
2524
2544
  context.print(`Reading ${request.path}`);
2525
- const outcome = await answer(context, apiUrl, credential.token, roots, request);
2545
+ const outcome = await answer(context, apiUrl, await authorization(), roots, request);
2526
2546
  const done = await call(
2527
2547
  `complete/${encodeURIComponent(request.id)}`,
2528
2548
  outcome.ok ? { result: { attachToken: outcome.attachToken } } : { error: outcome.error }
@@ -3713,6 +3733,67 @@ var spaceFields = [
3713
3733
  { header: "name", value: (s) => s.name },
3714
3734
  { header: "kind", value: (s) => s.kind }
3715
3735
  ];
3736
+ async function deleteSpaceCommand(context) {
3737
+ const named = context.args.words.slice(2).join(" ").trim();
3738
+ if (named === "") {
3739
+ context.error('Which Space? Try `pm spaces delete "Acme" --memories keep`.');
3740
+ return 2;
3741
+ }
3742
+ const memories = stringFlag(context.args, "memories");
3743
+ if (memories !== "keep" && memories !== "delete") {
3744
+ context.error("Say what happens to what is in it \u2014 there is no default:");
3745
+ context.error("");
3746
+ context.error(` pm spaces delete "${named}" --memories keep the memories survive`);
3747
+ context.error(` pm spaces delete "${named}" --memories delete they go with it`);
3748
+ return 2;
3749
+ }
3750
+ const client = await context.client();
3751
+ const { data } = await client.spaces.list({ limit: 200 }).first();
3752
+ const found = named.startsWith("space_") ? data.find((one) => one.id === named) : data.find((one) => one.name.toLowerCase() === named.toLowerCase());
3753
+ if (!found) {
3754
+ context.error(`No Space called "${named}". Run \`pm spaces list\` to see them.`);
3755
+ return 1;
3756
+ }
3757
+ const result = await client.spaces.delete(found.id, { memories });
3758
+ if (context.flags.output !== "table") {
3759
+ context.print(JSON.stringify({ id: found.id, ...result }, void 0, 2));
3760
+ return 0;
3761
+ }
3762
+ context.print(`Deleted "${found.name}".`);
3763
+ context.print(` ${result.deleted} memories deleted, ${result.kept} kept`);
3764
+ return 0;
3765
+ }
3766
+ async function mergeSpacesCommand(context) {
3767
+ const named = context.args.words.slice(2);
3768
+ const name = stringFlag(context.args, "name");
3769
+ if (named.length < 2 || !name) {
3770
+ context.error("Two or more Spaces, and a name for the one this makes:");
3771
+ context.error("");
3772
+ context.error(' pm spaces merge "Work" "Personal" --name "Everything"');
3773
+ return 2;
3774
+ }
3775
+ const client = await context.client();
3776
+ const { data } = await client.spaces.list({ limit: 200 }).first();
3777
+ const ids = [];
3778
+ for (const one of named) {
3779
+ const found = one.startsWith("space_") ? data.find((space2) => space2.id === one) : data.find((space2) => space2.name.toLowerCase() === one.toLowerCase());
3780
+ if (!found) {
3781
+ context.error(`No Space called "${one}". Run \`pm spaces list\` to see them.`);
3782
+ return 1;
3783
+ }
3784
+ ids.push(found.id);
3785
+ }
3786
+ const { space, added } = await client.spaces.merge({ sourceIds: ids, name });
3787
+ if (context.flags.output !== "table") {
3788
+ context.print(renderOne(space, spaceFields, { format: context.flags.output }));
3789
+ return 0;
3790
+ }
3791
+ context.print(`Created "${space.name}" from ${ids.length} Spaces, holding ${added} memories.`);
3792
+ context.print(` id ${space.id}`);
3793
+ context.print("");
3794
+ context.print("The Spaces it drew from are unchanged \u2014 nothing was moved or deleted.");
3795
+ return 0;
3796
+ }
3716
3797
 
3717
3798
  // src/index.ts
3718
3799
  async function run(deps) {
@@ -3868,8 +3949,10 @@ async function dispatch(context) {
3868
3949
  case "spaces":
3869
3950
  case "space":
3870
3951
  if (noun === "create" || noun === "new") return createSpaceCommand(context);
3952
+ if (noun === "delete" || noun === "remove") return deleteSpaceCommand(context);
3953
+ if (noun === "merge") return mergeSpacesCommand(context);
3871
3954
  if (noun === void 0 || noun === "list") return listSpacesCommand(context);
3872
- context.error(`Cannot "pm spaces ${noun}". Try list or create.`);
3955
+ context.error(`Cannot "pm spaces ${noun}". Try list, create, delete or merge.`);
3873
3956
  return 2;
3874
3957
  case "list":
3875
3958
  if (noun === "memories" || noun === "memory") return listMemoriesCommand(context);