@ipab/cli 0.1.0-rc.4 → 0.1.0-rc.5

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 (92) hide show
  1. package/README.md +12 -7
  2. package/dist/cli.d.ts +3 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +114 -25
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config-secret.d.ts +1 -1
  7. package/dist/config-secret.d.ts.map +1 -1
  8. package/dist/config-secret.js +2 -73
  9. package/dist/config-secret.js.map +1 -1
  10. package/dist/config.d.ts +1 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +12 -1
  13. package/dist/config.js.map +1 -1
  14. package/dist/context-types.d.ts +12 -0
  15. package/dist/context-types.d.ts.map +1 -0
  16. package/dist/context-types.js +2 -0
  17. package/dist/context-types.js.map +1 -0
  18. package/dist/context.d.ts +6 -0
  19. package/dist/context.d.ts.map +1 -1
  20. package/dist/context.js +25 -0
  21. package/dist/context.js.map +1 -1
  22. package/dist/ipc.d.ts +3 -1
  23. package/dist/ipc.d.ts.map +1 -1
  24. package/dist/ipc.js +34 -1
  25. package/dist/ipc.js.map +1 -1
  26. package/dist/kubo-install.d.ts +9 -0
  27. package/dist/kubo-install.d.ts.map +1 -0
  28. package/dist/kubo-install.js +361 -0
  29. package/dist/kubo-install.js.map +1 -0
  30. package/dist/kubo-peering.d.ts +11 -0
  31. package/dist/kubo-peering.d.ts.map +1 -0
  32. package/dist/kubo-peering.js +93 -0
  33. package/dist/kubo-peering.js.map +1 -0
  34. package/dist/kubo-peers.d.ts +12 -0
  35. package/dist/kubo-peers.d.ts.map +1 -0
  36. package/dist/kubo-peers.js +118 -0
  37. package/dist/kubo-peers.js.map +1 -0
  38. package/dist/kubo-release.d.ts +3 -0
  39. package/dist/kubo-release.d.ts.map +1 -0
  40. package/dist/kubo-release.js +12 -0
  41. package/dist/kubo-release.js.map +1 -0
  42. package/dist/kubo.d.ts +11 -4
  43. package/dist/kubo.d.ts.map +1 -1
  44. package/dist/kubo.js +150 -197
  45. package/dist/kubo.js.map +1 -1
  46. package/dist/runtime.d.ts +2 -0
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +6 -2
  49. package/dist/runtime.js.map +1 -1
  50. package/dist/setup.d.ts +2 -1
  51. package/dist/setup.d.ts.map +1 -1
  52. package/dist/setup.js +23 -18
  53. package/dist/setup.js.map +1 -1
  54. package/dist/state-storage-windows.d.ts +2 -0
  55. package/dist/state-storage-windows.d.ts.map +1 -0
  56. package/dist/state-storage-windows.js +114 -0
  57. package/dist/state-storage-windows.js.map +1 -0
  58. package/dist/state-storage.d.ts +3 -0
  59. package/dist/state-storage.d.ts.map +1 -0
  60. package/dist/state-storage.js +299 -0
  61. package/dist/state-storage.js.map +1 -0
  62. package/dist/state.d.ts +2 -2
  63. package/dist/state.d.ts.map +1 -1
  64. package/dist/state.js +59 -29
  65. package/dist/state.js.map +1 -1
  66. package/dist/swarm-files.d.ts +1 -1
  67. package/dist/swarm-files.d.ts.map +1 -1
  68. package/dist/swarm-files.js +4 -1
  69. package/dist/swarm-files.js.map +1 -1
  70. package/dist/swarm.d.ts +6 -3
  71. package/dist/swarm.d.ts.map +1 -1
  72. package/dist/swarm.js +184 -70
  73. package/dist/swarm.js.map +1 -1
  74. package/package.json +4 -4
  75. package/src/cli.ts +146 -39
  76. package/src/config-secret.ts +2 -84
  77. package/src/config.ts +14 -1
  78. package/src/context-types.ts +11 -0
  79. package/src/context.ts +40 -0
  80. package/src/ipc.ts +50 -1
  81. package/src/kubo-install.ts +452 -0
  82. package/src/kubo-peering.ts +126 -0
  83. package/src/kubo-peers.ts +145 -0
  84. package/src/kubo-release.ts +17 -0
  85. package/src/kubo.ts +207 -269
  86. package/src/runtime.ts +12 -1
  87. package/src/setup.ts +30 -17
  88. package/src/state-storage-windows.ts +134 -0
  89. package/src/state-storage.ts +329 -0
  90. package/src/state.ts +68 -35
  91. package/src/swarm-files.ts +4 -0
  92. package/src/swarm.ts +256 -90
package/README.md CHANGED
@@ -7,15 +7,19 @@ sandbox**: only execute Apps you trust.
7
7
  protected HOME identity without contacting or starting a daemon. It is
8
8
  idempotent; independent CID/local Store use still does not require Kubo.
9
9
 
10
- `0.1.0-rc.3` is published, with automated Swarm onboarding, temporary Bundle
11
- exports and the built-in IPAB Skill. Install this RC:
10
+ `0.1.0-rc.4` is published, with short Scope IDs, shared status queries and
11
+ configurable Swarm listeners. Install this RC:
12
12
 
13
13
  ```sh
14
- npm install --global @ipab/cli@0.1.0-rc.3
14
+ npm install --global @ipab/cli@0.1.0-rc.4
15
15
  ipab --version
16
16
  ipab --help
17
17
  ```
18
18
 
19
+ The current source prepares `0.1.0-rc.5` (not yet published), including Kubo
20
+ installation progress and cancellation, protected state storage, Scope request
21
+ retries and local alias references in search text output.
22
+
19
23
  Node.js 22.15.0 or newer is required. Built-in Node and Web App project
20
24
  templates are validated CAR assets shipped in this package; initialization works
21
25
  offline and does not install dependencies or run hooks.
@@ -51,10 +55,11 @@ exists.
51
55
 
52
56
  Shared references use `ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH`; `ipab:///PATH`
53
57
  selects `--swarm` or the saved `swarm.default`, in that order. URI swarm
54
- authorities take precedence and local aliases are case-sensitive. Search emits
55
- full configuration-URL-based URIs for sharing across devices. Legacy `name:PATH`
56
- references and `IPAB_SWARM` are no longer supported; remove the variable and use
57
- `--swarm` or `swarm use`.
58
+ authorities take precedence and local aliases are case-sensitive. Search text
59
+ uses local alias URIs when available, falling back to full configuration URLs.
60
+ JSON `reference` fields always use full configuration-URL-based URIs for sharing
61
+ across devices. Legacy `name:PATH` references and `IPAB_SWARM` are no longer
62
+ supported; remove the variable and use `--swarm` or `swarm use`.
58
63
 
59
64
  Owner uses `swarm update` for organization information and `swarm exclude` /
60
65
  `swarm resume` for irreversible, resumable member removal. Members change only
package/dist/cli.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type GlobalOptions } from "./config.js";
2
+ import { searchNames } from "./swarm.js";
2
3
  export interface IO {
3
4
  out(text: string): void;
4
- err(text: string): void;
5
+ err(text: string, progress?: boolean): void;
5
6
  tty: boolean;
6
7
  columns?(): number | undefined;
7
8
  confirm(text: string): Promise<boolean>;
@@ -9,6 +10,7 @@ export interface IO {
9
10
  }
10
11
  export declare const processIO: IO;
11
12
  export declare function help(path?: string): string;
13
+ export declare function formatSearchResults(matches: Awaited<ReturnType<typeof searchNames>>["matches"]): string;
12
14
  interface Parsed {
13
15
  flags: GlobalOptions;
14
16
  path: string;
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,EAQL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AA4CrB,MAAM,WAAW,EAAE;IACjB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,CAAC;IAC/B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,UAAU,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAChC;AACD,eAAO,MAAM,SAAS,EAAE,EAgCvB,CAAC;AAyhBF,wBAAgB,IAAI,CAAC,IAAI,SAAK,GAAG,MAAM,CAqEtC;AAyGD,UAAU,MAAM;IACd,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAkBD,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAoTrD;AAkgCD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,EAAE,GAAE,EAAc,EAClB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,MAAM,CAAC,CAOjB"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAOA,OAAO,EAQL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAmBrB,OAAO,EAcL,WAAW,EAMZ,MAAM,YAAY,CAAC;AAOpB,MAAM,WAAW,EAAE;IACjB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,GAAG,EAAE,OAAO,CAAC;IACb,OAAO,CAAC,IAAI,MAAM,GAAG,SAAS,CAAC;IAC/B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,UAAU,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,SAAS,EAAE,EAwCvB,CAAC;AA6hBF,wBAAgB,IAAI,CAAC,IAAI,SAAK,GAAG,MAAM,CAqEtC;AAWD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,GAC1D,MAAM,CASR;AAgGD,UAAU,MAAM;IACd,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAkBD,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAqTrD;AA+kCD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,EAAE,GAAE,EAAc,EAClB,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,MAAM,CAAC,CAOjB"}
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createInterface } from "node:readline/promises";
2
2
  import { readFile } from "node:fs/promises";
3
- import { IpfsStore } from "@ipab/ipfs-store";
3
+ import { ContentError, IpfsStore } from "@ipab/ipfs-store";
4
+ import { ContentBundleError } from "@ipab/bundle";
4
5
  import { randomUUID } from "node:crypto";
5
6
  import { CID } from "multiformats/cid";
6
7
  import stringWidth from "string-width";
@@ -16,18 +17,27 @@ import { assembleBundle } from "./assembly.js";
16
17
  import { getBundle } from "./get.js";
17
18
  import { setupDevice } from "./setup.js";
18
19
  import { keyId } from "@ipab/bundle/pointer/crypto";
19
- import { createSwarm, requestMembership, approveMembership, exportRequest, removeMember, resumeRemoval, updateProfile, verifiedRequest, membershipRequestSummary, swarmHeader, sharedSwarmStatus, addSwarm, updateSwarm, searchNames, resolveReference, publish, } from "./swarm.js";
20
+ import { createSwarm, requestMembership, approveMembership, exportRequest, removeMember, resumeRemoval, updateProfile, verifiedRequest, membershipRequestSummary, swarmHeader, sharedSwarmStatus, addSwarm, updateSwarm, searchNames, formatNameReference, resolveReference, parseNameReference, publish, } from "./swarm.js";
20
21
  import { schemaAlias } from "./app-definition.js";
21
22
  import { addPin, deletePin, pinDetails, renamePin } from "./pins.js";
22
23
  import { logFiles } from "./logs.js";
23
24
  import { builtinContent } from "./builtins.js";
24
25
  import { readSecretStream } from "./config-secret.js";
26
+ let progressLine = false;
25
27
  export const processIO = {
26
28
  out(text) {
27
29
  process.stdout.write(`${text}\n`);
28
30
  },
29
- err(text) {
30
- process.stderr.write(`${text}\n`);
31
+ err(text, progress = false) {
32
+ if (progress && process.stderr.isTTY) {
33
+ const width = (process.stderr.columns > 1 ? process.stderr.columns : 80) - 1;
34
+ process.stderr.write(`\r\x1b[2K${text.slice(0, width)}`);
35
+ progressLine = true;
36
+ }
37
+ else {
38
+ process.stderr.write(`${progressLine ? "\n" : ""}${text}\n`);
39
+ progressLine = false;
40
+ }
31
41
  },
32
42
  tty: Boolean(process.stdin.isTTY && process.stderr.isTTY),
33
43
  columns() {
@@ -53,7 +63,7 @@ export const processIO = {
53
63
  },
54
64
  };
55
65
  const commands = {
56
- setup: "setup [--yes]",
66
+ setup: "setup [--yes] [--kubo-archive FILE]",
57
67
  "swarm create": "swarm create [--service URL] [--resume OPERATION]",
58
68
  "swarm request": "swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
59
69
  "swarm export": "swarm export URL_OR_ALIAS --output FILE",
@@ -109,6 +119,7 @@ const commandHelp = {
109
119
  examples: ["ipab setup --yes", "ipab setup"],
110
120
  options: [
111
121
  "--yes Confirm installation and identity initialization outside a TTY.",
122
+ "--kubo-archive FILE Use a local official archive matching this CLI's pinned platform digest, without network access.",
112
123
  ],
113
124
  notes: [
114
125
  "Idempotent: reuse the same verified program and existing identity.",
@@ -148,6 +159,7 @@ const commandHelp = {
148
159
  ],
149
160
  notes: [
150
161
  "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
162
+ "If the alias is taken, choose another to keep both Swarms. If you mean to replace only the local registration, run ipab swarm remove ALIAS and retry.",
151
163
  ],
152
164
  },
153
165
  "swarm approve": {
@@ -257,6 +269,7 @@ const commandHelp = {
257
269
  "Searches all registered swarms unless --current or --swarm selects one.",
258
270
  "Valid caches use local Names only; absent/expired caches refresh. No payload downloads.",
259
271
  "No matches is success, not a reason to refresh valid caches. Any failed swarm fails the whole search.",
272
+ "Text uses local alias URIs when available; JSON references use full configuration URLs for cross-device sharing.",
260
273
  ],
261
274
  },
262
275
  publish: {
@@ -295,6 +308,7 @@ const commandHelp = {
295
308
  "Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
296
309
  "Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
297
310
  "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
311
+ "Copy the reference from ipab search, or percent-encode the entire configuration URL and each Name path segment separately.",
298
312
  "Does not install, build, edit, or automatically retrieve associated source.",
299
313
  ],
300
314
  },
@@ -520,7 +534,7 @@ const commandHelp = {
520
534
  "store.gateway is a read-only HTTP gateway; blocks, pins and GC remain local.",
521
535
  "pointers.service is a canonical HTTPS origin (HTTP loopback allowed).",
522
536
  "pointers.apiKey is accepted only through stdin using VALUE '-'; queries and confirmations redact it.",
523
- "Saving pointers.apiKey protects state SQLite files with account-only Unix modes or Windows ACLs.",
537
+ "SQLite state is account-only even without a key. Reading or saving a nonempty key rechecks Unix modes or Windows ACLs.",
524
538
  ],
525
539
  },
526
540
  "config reset": {
@@ -573,7 +587,7 @@ const commandHelp = {
573
587
  export function help(path = "") {
574
588
  const globalOptions = `Global options (before COMMAND):
575
589
  --swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
576
- --state-dir PATH Set the local state directory
590
+ --state-dir PATH Set a dedicated, account-private local state directory
577
591
  --store-gateway URL Use a read-only upstream HTTP gateway
578
592
  --json Output management/development metadata, not App stdio`;
579
593
  const footer = "Full reference: https://github.com/silvermoon-work/ipab/blob/main/docs/reference.md";
@@ -644,6 +658,13 @@ function printable(text) {
644
658
  : char)
645
659
  .join("");
646
660
  }
661
+ export function formatSearchResults(matches) {
662
+ return matches.length
663
+ ? matches
664
+ .map((match) => `${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${formatNameReference(match.alias ?? match.swarm, match.name)}`)
665
+ .join("\n")
666
+ : "No matching Names.";
667
+ }
647
668
  function runTime(value, field) {
648
669
  const date = new Date(value);
649
670
  if (!Number.isFinite(date.getTime()))
@@ -907,6 +928,8 @@ export function parse(argv) {
907
928
  : result.path === "pin list"
908
929
  ? ["type"]
909
930
  : [];
931
+ if (result.path === "setup")
932
+ values.push("kubo-archive");
910
933
  while (tokens.length) {
911
934
  const value = tokens.shift();
912
935
  if (result.path === "swarm exclude" &&
@@ -1034,6 +1057,7 @@ async function performCli(argv, io, env) {
1034
1057
  let state;
1035
1058
  let store;
1036
1059
  let appExitCode;
1060
+ let readContext;
1037
1061
  try {
1038
1062
  const parsed = parse(argv);
1039
1063
  if (parsed.help) {
@@ -1054,14 +1078,37 @@ async function performCli(argv, io, env) {
1054
1078
  (!io.tty ||
1055
1079
  !(await io.confirm("Install checksum-verified Kubo and initialize/reuse the protected HOME identity? No daemon will be contacted or started."))))
1056
1080
  throw new HostError("Setup requires explicit --yes or interactive confirmation.");
1057
- const result = await setupDevice(stateLocation(parsed.flags, env).path, env);
1058
- io.out(parsed.flags.json
1059
- ? JSON.stringify(result)
1060
- : `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`);
1061
- return 0;
1081
+ const controller = new AbortController();
1082
+ const interrupt = () => {
1083
+ controller.abort(new HostError("Setup interrupted.", 130, "ABORTED"));
1084
+ };
1085
+ const terminate = () => {
1086
+ controller.abort(new HostError("Setup terminated.", 143, "ABORTED"));
1087
+ };
1088
+ process.once("SIGINT", interrupt);
1089
+ process.once("SIGTERM", terminate);
1090
+ try {
1091
+ const result = await setupDevice(stateLocation(parsed.flags, env).path, env, {
1092
+ diagnostic: (text, progress) => {
1093
+ io.err(text, progress);
1094
+ },
1095
+ signal: controller.signal,
1096
+ ...(typeof parsed.options["kubo-archive"] === "string"
1097
+ ? { archive: parsed.options["kubo-archive"] }
1098
+ : {}),
1099
+ });
1100
+ io.out(parsed.flags.json
1101
+ ? JSON.stringify(result)
1102
+ : `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`);
1103
+ return 0;
1104
+ }
1105
+ finally {
1106
+ process.removeListener("SIGINT", interrupt);
1107
+ process.removeListener("SIGTERM", terminate);
1108
+ }
1062
1109
  }
1063
1110
  const builtins = await builtinContent();
1064
- state = new State(stateLocation(parsed.flags, env).path, builtins.pins);
1111
+ state = new State(stateLocation(parsed.flags, env).path, builtins.pins, env);
1065
1112
  if (parsed.path === "config reset" &&
1066
1113
  parsed.positional[0] === "store.rpc") {
1067
1114
  state.resetConfig("store.rpc");
@@ -1112,9 +1159,10 @@ async function performCli(argv, io, env) {
1112
1159
  ? filters(state, parsed.options)
1113
1160
  : {};
1114
1161
  const selection = () => {
1115
- const current = effectiveConfig(state.config(), parsed.flags, env, (reference) => state.resolveSwarm(reference)).find((item) => item.key === "swarm.default");
1162
+ const saved = state.config({ includeSecrets: false });
1163
+ const current = effectiveConfig(saved, parsed.flags, env, (reference) => state.resolveSwarm(reference)).find((item) => item.key === "swarm.default");
1116
1164
  return {
1117
- savedCurrent: state.config()["swarm.default"] ?? null,
1165
+ savedCurrent: saved["swarm.default"] ?? null,
1118
1166
  effectiveCurrent: current.value,
1119
1167
  source: current.source,
1120
1168
  };
@@ -1152,7 +1200,10 @@ async function performCli(argv, io, env) {
1152
1200
  }
1153
1201
  case "swarm remove": {
1154
1202
  const removed = state.removeSwarm(first);
1155
- emit({ removed, savedCurrent: state.config()["swarm.default"] ?? null }, `Removed registration ${removed}. Credentials, content and remote membership are unchanged.`);
1203
+ emit({
1204
+ removed,
1205
+ savedCurrent: state.config({ includeSecrets: false })["swarm.default"] ?? null,
1206
+ }, `Removed registration ${removed}. Credentials, content and remote membership are unchanged.`);
1156
1207
  break;
1157
1208
  }
1158
1209
  case "swarm add":
@@ -1231,7 +1282,8 @@ async function performCli(argv, io, env) {
1231
1282
  emit({
1232
1283
  configUrl: entry.cid,
1233
1284
  alias: entry.alias,
1234
- savedCurrent: state.config()["swarm.default"] ?? null,
1285
+ savedCurrent: state.config({ includeSecrets: false })["swarm.default"] ??
1286
+ null,
1235
1287
  }, `Registered swarm ${entry.alias ?? cid} (${cid}).`);
1236
1288
  break;
1237
1289
  }
@@ -1251,11 +1303,7 @@ async function performCli(argv, io, env) {
1251
1303
  ]
1252
1304
  : registrations;
1253
1305
  const result = await searchNames(context, first, scope);
1254
- emit(result, result.matches.length
1255
- ? result.matches
1256
- .map((match) => `${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${printable(match.reference)}`)
1257
- .join("\n")
1258
- : "No matching Names.");
1306
+ emit(result, formatSearchResults(result.matches));
1259
1307
  break;
1260
1308
  }
1261
1309
  if (parsed.path === "swarm status") {
@@ -1314,13 +1362,14 @@ async function performCli(argv, io, env) {
1314
1362
  break;
1315
1363
  }
1316
1364
  if (parsed.path === "get") {
1317
- const localCid = first.startsWith("ipab://")
1365
+ readContext = context;
1366
+ const localCid = /^(ipab|name):/i.test(first)
1318
1367
  ? undefined
1319
1368
  : state.resolve(first);
1320
1369
  const builtin = builtins.pins.find((pin) => pin.cid === localCid);
1321
1370
  const selected = builtin
1322
1371
  ? { cid: builtin.cid, targetCid: builtin.cid }
1323
- : await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw));
1372
+ : await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw), "local-first");
1324
1373
  const contentStore = context.store;
1325
1374
  const source = IpfsStore.fromClient({
1326
1375
  block: {
@@ -1411,7 +1460,7 @@ async function performCli(argv, io, env) {
1411
1460
  }
1412
1461
  store = context.store;
1413
1462
  if (parsed.path === "swarm create")
1414
- io.err(`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`);
1463
+ io.err(`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config({ includeSecrets: false })["swarm.default"] ?? "(none)"}.`);
1415
1464
  emit(parsed.path === "swarm request"
1416
1465
  ? { requestId: cid }
1417
1466
  : parsed.path === "swarm create" || parsed.path === "swarm approve"
@@ -1733,6 +1782,43 @@ async function performCli(argv, io, env) {
1733
1782
  const context = swarmContext();
1734
1783
  const target = (await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw))).cid;
1735
1784
  store = context.store;
1785
+ const resolveBundleReference = async (reference, signal, preferredSwarm) => {
1786
+ signal.throwIfAborted();
1787
+ const lookup = {
1788
+ ...swarmContext(),
1789
+ store: new IpfsStore(await storeConfiguration(value("store.gateway"))),
1790
+ };
1791
+ try {
1792
+ const named = parseNameReference(reference);
1793
+ const swarm = named?.swarm
1794
+ ? state.resolveSwarm(named.swarm)
1795
+ : preferredSwarm
1796
+ ? state.resolveSwarm(preferredSwarm)
1797
+ : selectedSwarm;
1798
+ const resolve = (source) => resolveReference(lookup, reference, source, (input) => state.resolve(input));
1799
+ let resolved;
1800
+ try {
1801
+ resolved = await resolve(named ? swarm : undefined);
1802
+ }
1803
+ catch (cause) {
1804
+ let failure = cause;
1805
+ for (let depth = 0; depth < 8 && failure instanceof ContentBundleError; depth++)
1806
+ failure = failure.cause;
1807
+ if (named ||
1808
+ !swarm ||
1809
+ !(failure instanceof ContentError) ||
1810
+ failure.code !== "missing_block")
1811
+ throw cause;
1812
+ signal.throwIfAborted();
1813
+ resolved = await resolve(swarm);
1814
+ }
1815
+ signal.throwIfAborted();
1816
+ return { ...resolved, ...(swarm ? { swarm } : {}) };
1817
+ }
1818
+ finally {
1819
+ await lookup.store.close();
1820
+ }
1821
+ };
1736
1822
  let appCid;
1737
1823
  let appArgv;
1738
1824
  if (parsed.path === "open") {
@@ -1749,6 +1835,7 @@ async function performCli(argv, io, env) {
1749
1835
  // execute owns the App/input context before this validation owner's eventual release.
1750
1836
  const result = await execute(state, store, { origin: "open", appCid, argv: appArgv }, {
1751
1837
  inputSchema: schema,
1838
+ resolveBundleReference,
1752
1839
  history: Boolean(value("history.enabled")),
1753
1840
  retain: value("output.retention") === "history",
1754
1841
  log: Boolean(parsed.options.log),
@@ -1768,6 +1855,7 @@ async function performCli(argv, io, env) {
1768
1855
  appArgv = parsed.positional.slice(1);
1769
1856
  }
1770
1857
  appExitCode = (await execute(state, store, { origin: "exec", appCid, argv: appArgv }, {
1858
+ resolveBundleReference,
1771
1859
  history: Boolean(value("history.enabled")),
1772
1860
  retain: value("output.retention") === "history",
1773
1861
  log: Boolean(parsed.options.log),
@@ -1788,6 +1876,7 @@ async function performCli(argv, io, env) {
1788
1876
  }
1789
1877
  finally {
1790
1878
  try {
1879
+ await readContext?.finishRead?.();
1791
1880
  await closeStore(store, appExitCode);
1792
1881
  }
1793
1882
  finally {