@ipab/cli 0.1.0-rc.2 → 0.1.0-rc.3

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 (102) hide show
  1. package/README.md +35 -14
  2. package/dist/app-authoring.d.ts.map +1 -1
  3. package/dist/app-authoring.js +11 -2
  4. package/dist/app-authoring.js.map +1 -1
  5. package/dist/app-definition.d.ts +52 -57
  6. package/dist/app-definition.d.ts.map +1 -1
  7. package/dist/app-definition.js +33 -38
  8. package/dist/app-definition.js.map +1 -1
  9. package/dist/app-templates.d.ts.map +1 -1
  10. package/dist/app-templates.js +2 -1
  11. package/dist/app-templates.js.map +1 -1
  12. package/dist/assembly.d.ts.map +1 -1
  13. package/dist/assembly.js +3 -4
  14. package/dist/assembly.js.map +1 -1
  15. package/dist/authoring.d.ts +3 -7
  16. package/dist/authoring.d.ts.map +1 -1
  17. package/dist/authoring.js +22 -12
  18. package/dist/authoring.js.map +1 -1
  19. package/dist/builtins/skill.ipab.car +0 -0
  20. package/dist/builtins/template.node.car +0 -0
  21. package/dist/builtins/template.web-app.car +0 -0
  22. package/dist/builtins.d.ts.map +1 -1
  23. package/dist/builtins.js +18 -2
  24. package/dist/builtins.js.map +1 -1
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +306 -116
  27. package/dist/cli.js.map +1 -1
  28. package/dist/config.d.ts +2 -1
  29. package/dist/config.d.ts.map +1 -1
  30. package/dist/config.js +19 -15
  31. package/dist/config.js.map +1 -1
  32. package/dist/content-provider.d.ts +1 -1
  33. package/dist/content-provider.d.ts.map +1 -1
  34. package/dist/content-provider.js +5 -2
  35. package/dist/content-provider.js.map +1 -1
  36. package/dist/get.d.ts.map +1 -1
  37. package/dist/get.js +34 -15
  38. package/dist/get.js.map +1 -1
  39. package/dist/kubo.d.ts +38 -0
  40. package/dist/kubo.d.ts.map +1 -0
  41. package/dist/kubo.js +528 -0
  42. package/dist/kubo.js.map +1 -0
  43. package/dist/pins.d.ts +3 -3
  44. package/dist/pins.js +1 -1
  45. package/dist/pins.js.map +1 -1
  46. package/dist/setup.d.ts +7 -0
  47. package/dist/setup.d.ts.map +1 -0
  48. package/dist/setup.js +22 -0
  49. package/dist/setup.js.map +1 -0
  50. package/dist/source-bundle.d.ts +3 -8
  51. package/dist/source-bundle.d.ts.map +1 -1
  52. package/dist/source-bundle.js +16 -11
  53. package/dist/source-bundle.js.map +1 -1
  54. package/dist/space.d.ts.map +1 -1
  55. package/dist/space.js +2 -2
  56. package/dist/space.js.map +1 -1
  57. package/dist/state.d.ts +4 -4
  58. package/dist/state.d.ts.map +1 -1
  59. package/dist/state.js +11 -12
  60. package/dist/state.js.map +1 -1
  61. package/dist/swarm-envelope.d.ts +36 -0
  62. package/dist/swarm-envelope.d.ts.map +1 -0
  63. package/dist/swarm-envelope.js +145 -0
  64. package/dist/swarm-envelope.js.map +1 -0
  65. package/dist/swarm-files.d.ts +5 -0
  66. package/dist/swarm-files.d.ts.map +1 -0
  67. package/dist/swarm-files.js +94 -0
  68. package/dist/swarm-files.js.map +1 -0
  69. package/dist/swarm.d.ts +117 -57
  70. package/dist/swarm.d.ts.map +1 -1
  71. package/dist/swarm.js +1033 -548
  72. package/dist/swarm.js.map +1 -1
  73. package/dist/template-definition.d.ts +47 -52
  74. package/dist/template-definition.d.ts.map +1 -1
  75. package/dist/template-definition.js +36 -41
  76. package/dist/template-definition.js.map +1 -1
  77. package/dist/template-source.d.ts +2 -0
  78. package/dist/template-source.d.ts.map +1 -1
  79. package/dist/template-source.js +4 -3
  80. package/dist/template-source.js.map +1 -1
  81. package/package.json +3 -3
  82. package/src/app-authoring.ts +22 -5
  83. package/src/app-definition.ts +33 -39
  84. package/src/app-templates.ts +9 -1
  85. package/src/assembly.ts +7 -4
  86. package/src/authoring.ts +31 -14
  87. package/src/builtins.ts +23 -2
  88. package/src/cli.ts +362 -139
  89. package/src/config.ts +22 -18
  90. package/src/content-provider.ts +5 -4
  91. package/src/get.ts +37 -15
  92. package/src/kubo.ts +691 -0
  93. package/src/pins.ts +1 -1
  94. package/src/setup.ts +21 -0
  95. package/src/source-bundle.ts +25 -12
  96. package/src/space.ts +2 -5
  97. package/src/state.ts +14 -13
  98. package/src/swarm-envelope.ts +255 -0
  99. package/src/swarm-files.ts +100 -0
  100. package/src/swarm.ts +1676 -837
  101. package/src/template-definition.ts +36 -41
  102. package/src/template-source.ts +10 -3
package/src/cli.ts CHANGED
@@ -2,7 +2,7 @@ import { createInterface } from "node:readline/promises";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { IpfsStore } from "@ipab/ipfs-store";
4
4
  import { randomUUID } from "node:crypto";
5
- import type { CID } from "multiformats/cid";
5
+ import { CID } from "multiformats/cid";
6
6
  import stringWidth from "string-width";
7
7
  import {
8
8
  configKey,
@@ -30,12 +30,18 @@ import { buildBundle, inspectBundle, importBundle } from "./authoring.js";
30
30
  import { initApp } from "./app-authoring.js";
31
31
  import { assembleBundle } from "./assembly.js";
32
32
  import { getBundle } from "./get.js";
33
+ import { setupDevice } from "./setup.js";
34
+ import { keyId } from "@ipab/bundle/pointer/crypto";
33
35
  import {
34
36
  createSwarm,
35
37
  requestMembership,
36
38
  approveMembership,
37
- joinSwarm,
38
- descriptor,
39
+ exportRequest,
40
+ removeMember,
41
+ resumeRemoval,
42
+ updateProfile,
43
+ verifiedRequest,
44
+ membershipRequestSummary,
39
45
  swarmHeader,
40
46
  addSwarm,
41
47
  updateSwarm,
@@ -92,17 +98,24 @@ export const processIO: IO = {
92
98
  },
93
99
  };
94
100
  const commands: Record<string, string> = {
101
+ setup: "setup [--yes]",
95
102
  "swarm create": "swarm create [--service URL] [--resume OPERATION]",
96
- "swarm request": "swarm request SWARM_CID",
97
- "swarm approve": "swarm approve REQUEST_CID [--expires-in SECONDS] --yes",
98
- "swarm join": "swarm join RESPONSE_CID",
99
- "swarm status": "swarm status [SWARM_CID]",
103
+ "swarm request":
104
+ "swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
105
+ "swarm export": "swarm export URL_OR_ALIAS --output FILE",
106
+ "swarm approve": "swarm approve REQUEST_FILE [--again] --yes",
107
+ "swarm exclude":
108
+ "swarm exclude MEMBER_PUBLIC_KEY [--swarm URL_OR_ALIAS] --yes",
109
+ "swarm resume": "swarm resume [URL_OR_ALIAS]",
110
+ "swarm profile":
111
+ "swarm profile [URL_OR_ALIAS] [--name NAME] [--address MULTIADDR]",
112
+ "swarm status": "swarm status [URL_OR_ALIAS]",
100
113
  "swarm list": "swarm list",
101
- "swarm add": "swarm add SWARM_CID [--alias ALIAS]",
102
- "swarm use": "swarm use CID_OR_ALIAS",
103
- "swarm remove": "swarm remove CID_OR_ALIAS",
114
+ "swarm add": "swarm add CONFIG_URL [--alias ALIAS]",
115
+ "swarm use": "swarm use URL_OR_ALIAS",
116
+ "swarm remove": "swarm remove URL_OR_ALIAS",
104
117
  "swarm update":
105
- "swarm update [CID_OR_ALIAS] [--name TEXT] [--description TEXT]",
118
+ "swarm update [URL_OR_ALIAS] [--name TEXT] [--description TEXT]",
106
119
  publish:
107
120
  "publish CID_OR_CAR [--name NAME [--expect OLD_NODE_CID | --snapshot]]",
108
121
  get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
@@ -152,6 +165,18 @@ const commandHelp: Record<
152
165
  notes?: string[];
153
166
  }
154
167
  > = {
168
+ setup: {
169
+ summary:
170
+ "Verify/install Kubo and prepare the protected HOME account identity",
171
+ examples: ["ipab setup --yes", "ipab setup"],
172
+ options: [
173
+ "--yes Confirm installation and identity initialization outside a TTY.",
174
+ ],
175
+ notes: [
176
+ "Idempotent: reuse the same verified program and existing identity.",
177
+ "Does not create Swarm repos, start or contact any daemon, deploy services or install login startup.",
178
+ ],
179
+ },
155
180
  "swarm create": {
156
181
  summary: "Create a swarm using the account HOME identity",
157
182
  options: [
@@ -168,32 +193,56 @@ const commandHelp: Record<
168
193
  ],
169
194
  notes: [
170
195
  "Creation uses the protected, origin-bound API key and owner possession proof.",
171
- "Uses the prepared private Kubo provider; never deploys infrastructure.",
172
- "Returns one descriptor CID; owner needs no member certificate.",
196
+ "Installs checksum-verified Kubo on demand; each Swarm has its own protected repo and ports.",
197
+ "Returns the public organization configuration URL; owner needs no certificate.",
173
198
  ],
174
199
  },
175
200
  "swarm request": {
176
- summary: "Publish a signed account membership request",
177
- examples: ["ipab swarm request SWARM_CID"],
201
+ summary: "Save and export a signed self-contained membership Request",
202
+ examples: [
203
+ "ipab swarm request CONFIG_URL --owner-fingerprint TRUSTED_FINGERPRINT --output request.json --alias work",
204
+ ],
205
+ options: [
206
+ "--owner-fingerprint VALUE Verify Owner through a trusted independent channel.",
207
+ "--name NAME Initial public display name.",
208
+ "--alias ALIAS Pre-register the target for lazy onboarding.",
209
+ "--output FILE Export the saved exact Request; no expiry or new PeerID on retry.",
210
+ ],
178
211
  notes: [
179
- "Returns one request CID. Private IPFS access is a prerequisite, not membership.",
212
+ "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
180
213
  ],
181
214
  },
182
215
  "swarm approve": {
183
216
  summary: "Owner signs a certificate for an exact request",
184
217
  options: [
185
218
  "--yes Explicit approval; required outside a TTY.",
186
- "--expires-in SECONDS 60..2592000; default 604800.",
219
+ "--again Explicit fresh approval of an old Request; history is advisory.",
220
+ ],
221
+ examples: ["ipab swarm approve request.json --yes"],
222
+ notes: [
223
+ "Creates a public profile and publishes an Owner-signed X25519/AES-GCM package. Exact-ID certificates have no expiry.",
187
224
  ],
188
- examples: ["ipab swarm approve REQUEST_CID --yes"],
189
- notes: ["Returns one response CID. Never exports the owner private key."],
190
225
  },
191
- "swarm join": {
192
- summary: "Verify a response and authenticate HEAD",
193
- examples: ["ipab swarm join RESPONSE_CID"],
194
- options: ["--alias ALIAS Register this swarm with a local alias."],
226
+ "swarm export": {
227
+ summary: "Re-export the same persisted Request",
228
+ examples: ["ipab swarm export work --output request.json"],
229
+ },
230
+ "swarm exclude": {
231
+ summary: "Owner removes a member with irreversible HEAD/key rotation",
232
+ examples: ["ipab --swarm work swarm exclude MEMBER_PUBLIC_KEY --yes"],
195
233
  notes: [
196
- "Requires this account's exact pending request and bound member certificate.",
234
+ "Freezes the old HEAD atomically, preserves its final committed publication, rotates the key and remaining packages, deletes the leaving profile and retires the old HEAD.",
235
+ ],
236
+ },
237
+ "swarm resume": {
238
+ summary: "Owner resumes an interrupted organization switch",
239
+ examples: ["ipab swarm resume work"],
240
+ },
241
+ "swarm profile": {
242
+ summary: "Update your public display name and LAN/VPN IPv4 TCP address",
243
+ examples: [
244
+ "ipab swarm profile work --name Wei",
245
+ "ipab swarm profile work --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
197
246
  ],
198
247
  },
199
248
  "swarm status": {
@@ -213,7 +262,7 @@ const commandHelp: Record<
213
262
  options: [
214
263
  "--alias ALIAS Unique local alias; does not rename the shared swarm.",
215
264
  ],
216
- examples: ["ipab swarm add SWARM_CID --alias work"],
265
+ examples: ["ipab swarm add CONFIG_URL --alias work"],
217
266
  notes: [
218
267
  "Not a membership grant. The first registration becomes the saved default only if none exists.",
219
268
  ],
@@ -231,8 +280,8 @@ const commandHelp: Record<
231
280
  ],
232
281
  },
233
282
  "swarm update": {
234
- summary: "Update shared swarm information as an owner or member",
235
- arguments: ["CID_OR_ALIAS Defaults to the effective current swarm."],
283
+ summary: "Owner updates public organization information",
284
+ arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
236
285
  options: [
237
286
  "--name TEXT Replace the shared display name; empty text clears it.",
238
287
  "--description TEXT Replace the shared description; empty text clears it.",
@@ -242,9 +291,8 @@ const commandHelp: Record<
242
291
  'ipab swarm update --description ""',
243
292
  ],
244
293
  notes: [
245
- "Requires at least one field. Any authorized member can update both fields.",
246
- "Last successful write wins for the specified fields; no expected-value/version input.",
247
- "Automatically retries HEAD contention while preserving current Names and unspecified properties.",
294
+ "Requires at least one field. Members can change only their own profile.",
295
+ "Content-CID CAS prevents overwriting concurrent organization changes.",
248
296
  "Shared name changes do not rename local registry aliases.",
249
297
  ],
250
298
  },
@@ -289,16 +337,18 @@ const commandHelp: Record<
289
337
  "--raw Select the Artifact node instead of its value.",
290
338
  "--force Refresh the shared Name's swarm HEAD.",
291
339
  "--no-force Override swarm.forceRefresh and use valid cached headers.",
292
- "-o, --output DIRECTORY New or empty directory; defaults to resolved CID.",
340
+ "-o, --output DIRECTORY New or empty directory; defaults to a unique temporary directory.",
293
341
  ],
294
342
  examples: [
295
343
  "ipab --json get ipab:///apps/hello -o hello-app",
296
344
  "ipab get ipab://work/apps/hello -o hello-app",
345
+ "ipab get CONTENT_CID",
297
346
  "ipab get --raw RELEASE_CID",
298
347
  ],
299
348
  notes: [
300
- "Returns the selected content CID and original target CID (editing baseline).",
301
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
349
+ "Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
350
+ "Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
351
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
302
352
  "Does not install, build, edit, or automatically retrieve associated source.",
303
353
  ],
304
354
  },
@@ -349,7 +399,7 @@ const commandHelp: Record<
349
399
  ],
350
400
  notes: [
351
401
  "Recipe explicitly maps source files and exact CID imports to target paths.",
352
- "Type and entry come from .bundle.yaml; imported DAG identities are preserved.",
402
+ "Instance paths come from .bundle.yaml; the referenced file defines the type. Imported DAG identities are preserved.",
353
403
  "Legacy App ipab.yaml is rejected; use project preparation tools separately.",
354
404
  "Select explicit files; review private files before providing Bundles.",
355
405
  "Store failures preserve the CAR; retry with ipab bundle import FILE.car.",
@@ -366,7 +416,7 @@ const commandHelp: Record<
366
416
  ],
367
417
  examples: [
368
418
  "ipab bundle build note",
369
- "ipab bundle build types\\.bundle.yaml --schema-only",
419
+ "ipab bundle build types\\.bundle-type.yaml --schema-only",
370
420
  ],
371
421
  notes: [
372
422
  "Imports into the configured Store without pinning or executing Apps.",
@@ -405,7 +455,7 @@ const commandHelp: Record<
405
455
  ],
406
456
  notes: [
407
457
  "Apps are NOT sandboxed; run only Apps you trust.",
408
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
458
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
409
459
  "History stores argv by default; do not put secrets in arguments.",
410
460
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
411
461
  "--json is not supported; App stdio is passed through.",
@@ -427,7 +477,7 @@ const commandHelp: Record<
427
477
  ],
428
478
  notes: [
429
479
  "Requires a saved registration and App support for the exact content type.",
430
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
480
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
431
481
  "Apps are NOT sandboxed; run only Apps you trust.",
432
482
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
433
483
  "--json is not supported; App stdio is passed through.",
@@ -577,7 +627,7 @@ const commandHelp: Record<
577
627
 
578
628
  export function help(path = ""): string {
579
629
  const globalOptions = `Global options (before COMMAND):
580
- --swarm CID|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
630
+ --swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
581
631
  --state-dir PATH Set the local state directory
582
632
  --store-gateway URL Use a read-only upstream HTTP gateway
583
633
  --json Output management/development metadata, not App stdio`;
@@ -598,6 +648,7 @@ Create:
598
648
  bundle ${groups.bundle}
599
649
 
600
650
  Manage:
651
+ setup ${commandHelp.setup!.summary}
601
652
  swarm ${groups.swarm}
602
653
  search Search formal Names across registered swarms
603
654
  publish ${commandHelp.publish!.summary}
@@ -848,7 +899,11 @@ export function parse(argv: readonly string[]): Parsed {
848
899
  result.positional = tokens;
849
900
  return result;
850
901
  }
851
- if (!["open", "init", "build", "publish", "get", "search"].includes(group)) {
902
+ if (
903
+ !["open", "init", "build", "publish", "get", "search", "setup"].includes(
904
+ group,
905
+ )
906
+ ) {
852
907
  if (
853
908
  ![
854
909
  "bundle",
@@ -885,52 +940,75 @@ export function parse(argv: readonly string[]): Parsed {
885
940
  "API key must be provided through '-' and piped stdin; never pass it in command arguments.",
886
941
  );
887
942
  const booleans =
888
- result.path === "bundle build"
889
- ? ["replace", "schema-only", "no-import"]
890
- : result.path === "build"
891
- ? ["replace", "no-import"]
892
- : result.path === "publish"
893
- ? ["snapshot"]
894
- : result.path === "get"
895
- ? ["raw", "force", "no-force"]
896
- : result.path === "search"
897
- ? ["current", "force", "no-force"]
898
- : result.path === "swarm approve"
899
- ? ["yes"]
900
- : result.path === "register set"
901
- ? ["replace"]
902
- : result.path === "history remove"
943
+ result.path === "setup"
944
+ ? ["yes"]
945
+ : result.path === "bundle build"
946
+ ? ["replace", "schema-only", "no-import"]
947
+ : result.path === "build"
948
+ ? ["replace", "no-import"]
949
+ : result.path === "publish"
950
+ ? ["snapshot"]
951
+ : result.path === "get"
952
+ ? ["raw", "force", "no-force"]
953
+ : result.path === "search"
954
+ ? ["current", "force", "no-force"]
955
+ : result.path === "swarm approve"
956
+ ? ["yes", "again"]
957
+ : result.path === "swarm exclude"
903
958
  ? ["yes"]
904
- : result.path === "open"
905
- ? ["log", "raw", "force", "no-force"]
906
- : [];
959
+ : result.path === "register set"
960
+ ? ["replace"]
961
+ : result.path === "history remove"
962
+ ? ["yes"]
963
+ : result.path === "open"
964
+ ? ["log", "raw", "force", "no-force"]
965
+ : [];
907
966
  const values =
908
967
  result.path === "swarm create"
909
968
  ? ["service", "resume", "name", "description", "alias"]
910
- : result.path === "swarm add" || result.path === "swarm join"
969
+ : result.path === "swarm add"
911
970
  ? ["alias"]
912
- : result.path === "swarm update"
913
- ? ["name", "description"]
914
- : result.path === "swarm approve"
915
- ? ["expires-in"]
916
- : result.path === "publish"
917
- ? ["name", "expect"]
918
- : result.path === "get"
919
- ? ["output"]
920
- : result.path === "init"
921
- ? ["template"]
922
- : result.path === "bundle build" || result.path === "build"
923
- ? ["output"]
924
- : result.path === "history list"
925
- ? ["app", "status", "since", "until", "limit", "before"]
926
- : result.path === "history remove"
927
- ? ["app", "status", "since", "until"]
928
- : result.path === "pin list"
929
- ? ["type"]
930
- : [];
971
+ : result.path === "swarm request"
972
+ ? ["owner-fingerprint", "name", "alias", "output"]
973
+ : result.path === "swarm export"
974
+ ? ["output"]
975
+ : result.path === "swarm profile"
976
+ ? ["name", "address"]
977
+ : result.path === "swarm update"
978
+ ? ["name", "description"]
979
+ : result.path === "swarm approve"
980
+ ? []
981
+ : result.path === "publish"
982
+ ? ["name", "expect"]
983
+ : result.path === "get"
984
+ ? ["output"]
985
+ : result.path === "init"
986
+ ? ["template"]
987
+ : result.path === "bundle build" ||
988
+ result.path === "build"
989
+ ? ["output"]
990
+ : result.path === "history list"
991
+ ? [
992
+ "app",
993
+ "status",
994
+ "since",
995
+ "until",
996
+ "limit",
997
+ "before",
998
+ ]
999
+ : result.path === "history remove"
1000
+ ? ["app", "status", "since", "until"]
1001
+ : result.path === "pin list"
1002
+ ? ["type"]
1003
+ : [];
931
1004
  while (tokens.length) {
932
1005
  const value = tokens.shift()!;
933
- if (value.startsWith("--") || value === "-o") {
1006
+ if (
1007
+ result.path === "swarm exclude" &&
1008
+ /^--[A-Za-z0-9_-]{41}$/.test(value)
1009
+ ) {
1010
+ result.positional.push(value);
1011
+ } else if (value.startsWith("--") || value === "-o") {
934
1012
  const option = value === "-o" ? "output" : value.slice(2);
935
1013
  if (result.path === "init" && option === "param") {
936
1014
  const input = tokens.shift();
@@ -946,7 +1024,11 @@ export function parse(argv: readonly string[]): Parsed {
946
1024
  const input = tokens.shift();
947
1025
  if (
948
1026
  input === undefined ||
949
- input.startsWith("--") ||
1027
+ (input.startsWith("--") &&
1028
+ !(
1029
+ ["resume", "owner-fingerprint"].includes(option) &&
1030
+ /^[A-Za-z0-9_-]{43}$/.test(input)
1031
+ )) ||
950
1032
  (input === "" && result.path !== "swarm update")
951
1033
  )
952
1034
  syntax(`${value} needs a value.`);
@@ -963,10 +1045,14 @@ export function parse(argv: readonly string[]): Parsed {
963
1045
  )
964
1046
  syntax("--current and --swarm are mutually exclusive.");
965
1047
  const counts: Record<string, [number, number]> = {
1048
+ setup: [0, 0],
966
1049
  "swarm create": [0, 0],
967
1050
  "swarm request": [1, 1],
968
1051
  "swarm approve": [1, 1],
969
- "swarm join": [1, 1],
1052
+ "swarm export": [1, 1],
1053
+ "swarm exclude": [1, 1],
1054
+ "swarm resume": [0, 1],
1055
+ "swarm profile": [0, 1],
970
1056
  "swarm status": [0, 1],
971
1057
  "swarm list": [0, 0],
972
1058
  "swarm add": [1, 1],
@@ -1076,6 +1162,28 @@ async function performCli(
1076
1162
  }
1077
1163
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
1078
1164
  syntax("Non-interactive history remove requires --yes.");
1165
+ if (parsed.path === "setup") {
1166
+ if (
1167
+ !parsed.options.yes &&
1168
+ (!io.tty ||
1169
+ !(await io.confirm(
1170
+ "Install checksum-verified Kubo and initialize/reuse the protected HOME identity? No daemon will be contacted or started.",
1171
+ )))
1172
+ )
1173
+ throw new HostError(
1174
+ "Setup requires explicit --yes or interactive confirmation.",
1175
+ );
1176
+ const result = await setupDevice(
1177
+ stateLocation(parsed.flags, env).path,
1178
+ env,
1179
+ );
1180
+ io.out(
1181
+ parsed.flags.json
1182
+ ? JSON.stringify(result)
1183
+ : `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`,
1184
+ );
1185
+ return 0;
1186
+ }
1079
1187
  const builtins = await builtinContent();
1080
1188
  state = new State(stateLocation(parsed.flags, env).path, builtins.pins);
1081
1189
  if (
@@ -1107,11 +1215,15 @@ async function performCli(
1107
1215
  ? undefined
1108
1216
  : String(value("swarm.default"));
1109
1217
  const swarmContext = (): SwarmContext => ({
1110
- store: store!,
1218
+ get store() {
1219
+ return store!;
1220
+ },
1221
+ set store(next) {
1222
+ store = next;
1223
+ },
1111
1224
  state: state!,
1112
1225
  env,
1113
1226
  stateDir: stateLocation(parsed.flags, env).path,
1114
- provider: String(value("swarm.provider") ?? "http://127.0.0.1:5001"),
1115
1227
  cacheTtl: Number(value("swarm.cacheTtl")),
1116
1228
  forceRefresh: parsed.options.force
1117
1229
  ? true
@@ -1148,7 +1260,13 @@ async function performCli(
1148
1260
  case "swarm list": {
1149
1261
  const result = { swarms: state.swarms(), ...selection() };
1150
1262
  emit(
1151
- result,
1263
+ {
1264
+ ...result,
1265
+ swarms: result.swarms.map((entry) => ({
1266
+ configUrl: entry.cid,
1267
+ alias: entry.alias,
1268
+ })),
1269
+ },
1152
1270
  [
1153
1271
  ...result.swarms.map(
1154
1272
  (entry) =>
@@ -1184,17 +1302,67 @@ async function performCli(
1184
1302
  case "swarm create":
1185
1303
  case "swarm request":
1186
1304
  case "swarm approve":
1187
- case "swarm join":
1305
+ case "swarm export":
1306
+ case "swarm exclude":
1307
+ case "swarm resume":
1308
+ case "swarm profile":
1188
1309
  case "swarm status":
1189
1310
  case "publish":
1190
1311
  case "get": {
1191
1312
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1192
1313
  const context = swarmContext();
1314
+ if (parsed.path === "swarm export") {
1315
+ const id = await exportRequest(
1316
+ context,
1317
+ state.resolveSwarm(first!),
1318
+ String(parsed.options.output ?? ""),
1319
+ );
1320
+ emit({ id }, id);
1321
+ break;
1322
+ }
1323
+ if (
1324
+ ["swarm exclude", "swarm resume", "swarm profile"].includes(
1325
+ parsed.path,
1326
+ )
1327
+ ) {
1328
+ const url =
1329
+ parsed.path === "swarm exclude"
1330
+ ? selectedSwarm
1331
+ : first
1332
+ ? state.resolveSwarm(first)
1333
+ : selectedSwarm;
1334
+ if (!url) syntax("Select a Swarm configuration URL or alias.");
1335
+ if (parsed.path === "swarm exclude") {
1336
+ if (!parsed.options.yes)
1337
+ syntax("Member removal is irreversible; --yes required.");
1338
+ await removeMember(context, url, first!);
1339
+ } else if (parsed.path === "swarm resume")
1340
+ await resumeRemoval(context, url);
1341
+ else {
1342
+ const profile = await updateProfile(context, url, {
1343
+ ...(typeof parsed.options.name === "string"
1344
+ ? { name: parsed.options.name }
1345
+ : {}),
1346
+ ...(typeof parsed.options.address === "string"
1347
+ ? { addresses: [parsed.options.address] }
1348
+ : {}),
1349
+ });
1350
+ emit(profile, JSON.stringify(profile));
1351
+ store = context.store;
1352
+ break;
1353
+ }
1354
+ store = context.store;
1355
+ emit(
1356
+ { url, completed: true },
1357
+ `Organization switch complete: ${url}`,
1358
+ );
1359
+ break;
1360
+ }
1193
1361
  if (parsed.path === "swarm update") {
1194
1362
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1195
1363
  if (!cid)
1196
1364
  syntax(
1197
- "swarm update requires a registered alias, Swarm CID or current swarm.",
1365
+ "swarm update requires a registered alias, configuration URL or current swarm.",
1198
1366
  );
1199
1367
  const result = await updateSwarm(context, cid, {
1200
1368
  ...(typeof parsed.options.name === "string"
@@ -1206,12 +1374,12 @@ async function performCli(
1206
1374
  });
1207
1375
  emit(
1208
1376
  result,
1209
- `Swarm: ${result.cid}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD: ${result.root}\nRevision: ${result.revision}`,
1377
+ `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`,
1210
1378
  );
1211
1379
  break;
1212
1380
  }
1213
1381
  if (parsed.path === "swarm add") {
1214
- const cid = exactCid(first!);
1382
+ const cid = state.resolveSwarm(first!);
1215
1383
  await addSwarm(
1216
1384
  context,
1217
1385
  cid,
@@ -1221,7 +1389,11 @@ async function performCli(
1221
1389
  );
1222
1390
  const entry = state.registeredSwarm(cid);
1223
1391
  emit(
1224
- { ...entry, savedCurrent: state.config()["swarm.default"] ?? null },
1392
+ {
1393
+ configUrl: entry.cid,
1394
+ alias: entry.alias,
1395
+ savedCurrent: state.config()["swarm.default"] ?? null,
1396
+ },
1225
1397
  `Registered swarm ${entry.alias ?? cid} (${cid}).`,
1226
1398
  );
1227
1399
  break;
@@ -1263,40 +1435,79 @@ async function performCli(
1263
1435
  if (parsed.path === "swarm status") {
1264
1436
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1265
1437
  if (!cid)
1266
- syntax("swarm status requires a Swarm CID or swarm.default.");
1267
- const data = await descriptor(store, cid);
1268
- const { head, snapshot } = await swarmHeader(context, cid, true);
1438
+ syntax(
1439
+ "swarm status requires a configuration URL or swarm.default.",
1440
+ );
1441
+ const { head, config } = await swarmHeader(context, cid, true);
1442
+ store = context.store;
1269
1443
  emit(
1270
1444
  {
1271
- cid,
1272
- ...data,
1445
+ configUrl: cid,
1446
+ owner: config.owner,
1447
+ ownerFingerprint: await keyId(config.owner),
1448
+ epoch: config.epoch,
1449
+ peerId: context.node!.peerId,
1450
+ addresses: context.node!.addresses,
1273
1451
  root: head.root,
1274
- revision: head.revision,
1275
- properties: snapshot.properties,
1452
+ valueCid: head.cid,
1453
+ properties: {
1454
+ name: config.name,
1455
+ description: config.description,
1456
+ },
1276
1457
  },
1277
- `Swarm: ${cid}\nName: ${printable(snapshot.properties.name)}\nDescription: ${printable(snapshot.properties.description)}\nHEAD: ${head.root}\nRevision: ${head.revision}`,
1458
+ `Swarm: ${cid}\nOwner fingerprint: ${await keyId(config.owner)}\nPeerID: ${context.node!.peerId}\nLocal address: ${context.node!.addresses.join(", ")}\nName: ${printable(config.name)}\nDescription: ${printable(config.description)}\nHEAD: ${head.root}\nContent CID: ${head.cid}`,
1278
1459
  );
1279
1460
  break;
1280
1461
  }
1281
1462
  if (parsed.path === "get") {
1282
- const selected = await resolveReference(
1283
- context,
1284
- first!,
1285
- selectedSwarm,
1286
- (reference) => state!.resolve(reference),
1287
- Boolean(parsed.options.raw),
1288
- );
1289
- const directory = await getBundle(
1290
- store,
1291
- selected.cid,
1292
- typeof parsed.options.output === "string"
1293
- ? parsed.options.output
1294
- : undefined,
1295
- );
1296
- emit(
1297
- { ...selected, directory },
1298
- `CID: ${selected.cid}\nTarget CID: ${selected.targetCid}\nDirectory: ${directory}`,
1463
+ const localCid = first!.startsWith("ipab://")
1464
+ ? undefined
1465
+ : state.resolve(first!);
1466
+ const builtin = builtins.pins.find((pin) => pin.cid === localCid);
1467
+ const selected = builtin
1468
+ ? { cid: builtin.cid, targetCid: builtin.cid }
1469
+ : await resolveReference(
1470
+ context,
1471
+ first!,
1472
+ selectedSwarm,
1473
+ (reference) => state!.resolve(reference),
1474
+ Boolean(parsed.options.raw),
1475
+ );
1476
+ const contentStore = context.store;
1477
+ const source = IpfsStore.fromClient(
1478
+ {
1479
+ block: {
1480
+ get: (key, options) => {
1481
+ options?.signal?.throwIfAborted();
1482
+ const builtin = builtins.blocks.get(
1483
+ CID.parse(key).toV1().toString(),
1484
+ );
1485
+ return builtin
1486
+ ? Promise.resolve(builtin.slice())
1487
+ : contentStore.block.get(key, options);
1488
+ },
1489
+ },
1490
+ },
1491
+ contentStore.limits,
1299
1492
  );
1493
+ let directory: string;
1494
+ try {
1495
+ directory = await getBundle(
1496
+ source,
1497
+ selected.cid,
1498
+ typeof parsed.options.output === "string"
1499
+ ? parsed.options.output
1500
+ : undefined,
1501
+ );
1502
+ } finally {
1503
+ await source.close();
1504
+ }
1505
+ const closing = store;
1506
+ store = undefined;
1507
+ await closeStore(closing, undefined);
1508
+ state.close();
1509
+ state = undefined;
1510
+ emit({ ...selected, directory }, directory);
1300
1511
  break;
1301
1512
  }
1302
1513
  let cid: string;
@@ -1317,34 +1528,35 @@ async function performCli(
1317
1528
  : {}),
1318
1529
  });
1319
1530
  } else if (parsed.path === "swarm request")
1320
- cid = await requestMembership(context, exactCid(first!));
1531
+ cid = await requestMembership(context, first!, {
1532
+ ownerFingerprint: String(parsed.options["owner-fingerprint"] ?? ""),
1533
+ ...(typeof parsed.options.name === "string"
1534
+ ? { name: parsed.options.name }
1535
+ : {}),
1536
+ ...(typeof parsed.options.alias === "string"
1537
+ ? { alias: parsed.options.alias }
1538
+ : {}),
1539
+ ...(typeof parsed.options.output === "string"
1540
+ ? { output: parsed.options.output }
1541
+ : {}),
1542
+ });
1321
1543
  else if (parsed.path === "swarm approve") {
1544
+ const request = await verifiedRequest(first!);
1545
+ io.err(await membershipRequestSummary(request));
1322
1546
  if (
1323
1547
  !parsed.options.yes &&
1324
1548
  (!io.tty ||
1325
1549
  !(await io.confirm(
1326
- `Approve membership request ${first!}? This grants swarm HEAD read/write access.`,
1550
+ `Approve the verified Request ${request.id} above? This grants current HEAD and the member's profile write access; all reads are public.`,
1327
1551
  )))
1328
1552
  )
1329
1553
  throw new HostError(
1330
1554
  "Approval requires explicit --yes or interactive confirmation.",
1331
1555
  );
1332
- cid = await approveMembership(
1333
- context,
1334
- exactCid(first!),
1335
- parsed.options["expires-in"] === undefined
1336
- ? undefined
1337
- : Number(parsed.options["expires-in"]),
1338
- );
1339
- } else if (parsed.path === "swarm join")
1340
- cid = await joinSwarm(
1341
- context,
1342
- exactCid(first!),
1343
- typeof parsed.options.alias === "string"
1344
- ? parsed.options.alias
1345
- : undefined,
1346
- );
1347
- else {
1556
+ cid = await approveMembership(context, request, {
1557
+ again: Boolean(parsed.options.again),
1558
+ });
1559
+ } else {
1348
1560
  let content: string;
1349
1561
  if (first!.toLowerCase().endsWith(".car"))
1350
1562
  content = (
@@ -1362,11 +1574,19 @@ async function performCli(
1362
1574
  snapshot: Boolean(parsed.options.snapshot),
1363
1575
  });
1364
1576
  }
1365
- if (parsed.path === "swarm create" || parsed.path === "swarm join")
1577
+ store = context.store;
1578
+ if (parsed.path === "swarm create")
1366
1579
  io.err(
1367
1580
  `Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`,
1368
1581
  );
1369
- emit({ cid }, cid);
1582
+ emit(
1583
+ parsed.path === "swarm request"
1584
+ ? { requestId: cid }
1585
+ : parsed.path === "swarm create" || parsed.path === "swarm approve"
1586
+ ? { configUrl: cid }
1587
+ : { cid },
1588
+ cid,
1589
+ );
1370
1590
  break;
1371
1591
  }
1372
1592
  case "store usage":
@@ -1529,7 +1749,7 @@ async function performCli(
1529
1749
  } else
1530
1750
  emit(
1531
1751
  result,
1532
- `Kind: ${result.kind}\nName: ${printable(result.name)}\nSchema CID: ${result.schemaCid}\nEntry: ${result.entry.path} (${result.entry.contentType})\nDefinition validation: passed\nStorage verification: ${result.validation.storage}\nEntry validation: ${result.validation.entry?.status ?? "not-applicable"}`,
1752
+ `Kind: ${result.kind}\n${result.manifest ? `Title: ${printable(result.manifest.title)}\nEntry: ${result.manifest.entry}\nType file: ${result.manifest.type}\n` : ""}Type CID: ${result.schemaCid}\nContent type: ${result.type.contentType}\nDefinition validation: passed\nStorage verification: ${result.validation.storage}\nEntry validation: ${result.validation.entry?.status ?? "not-applicable"}`,
1533
1753
  );
1534
1754
  } catch (cause) {
1535
1755
  if (cancelled)
@@ -1583,12 +1803,13 @@ async function performCli(
1583
1803
  emit(
1584
1804
  { items: listed, pending, invalid },
1585
1805
  table(
1586
- ["NAME", "CID", "KIND", "BUNDLE TYPE", "SOURCE"],
1806
+ ["NAME", "CID", "KIND", "TITLE", "TYPE CID", "SOURCE"],
1587
1807
  listed.map((pin) => [
1588
1808
  pin.name,
1589
1809
  pin.cid,
1590
1810
  pin.kind,
1591
- pin.typeName,
1811
+ pin.title,
1812
+ pin.schemaCid,
1592
1813
  pin.builtin ? "built-in (read-only)" : "user",
1593
1814
  ]),
1594
1815
  "No named pins.",
@@ -1606,7 +1827,7 @@ async function performCli(
1606
1827
  );
1607
1828
  emit(
1608
1829
  result,
1609
- `${result.name} → ${result.cid}\nBundle type: ${printable(result.typeName)}`,
1830
+ `${result.name} → ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}`,
1610
1831
  );
1611
1832
  break;
1612
1833
  }
@@ -1627,7 +1848,7 @@ async function performCli(
1627
1848
  const result = pinDetails(pin);
1628
1849
  emit(
1629
1850
  result,
1630
- `Name: ${printable(result.name)}\nCID: ${result.cid}\nBundle type: ${printable(result.typeName)}\nSchema CID: ${result.schemaCid}\nSource: ${result.builtin ? "built-in (read-only; content bundled with IPAB)" : "local registration (not live node verification)"}`,
1851
+ `Name: ${printable(result.name)}\nCID: ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}\nSource: ${result.builtin ? "built-in (read-only; content bundled with IPAB)" : "local registration (not live node verification)"}`,
1631
1852
  );
1632
1853
  break;
1633
1854
  }
@@ -1801,15 +2022,17 @@ async function performCli(
1801
2022
  );
1802
2023
  await recoverInactive(state);
1803
2024
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
2025
+ const context = swarmContext();
1804
2026
  const target = (
1805
2027
  await resolveReference(
1806
- swarmContext(),
2028
+ context,
1807
2029
  first!,
1808
2030
  selectedSwarm,
1809
2031
  (reference) => state!.resolve(reference),
1810
2032
  Boolean(parsed.options.raw),
1811
2033
  )
1812
2034
  ).cid;
2035
+ store = context.store;
1813
2036
  let appCid: string;
1814
2037
  let appArgv: string[];
1815
2038
  if (parsed.path === "open") {