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

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 (107) hide show
  1. package/README.md +40 -13
  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 +367 -124
  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 +29 -16
  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/identity.d.ts +5 -0
  40. package/dist/identity.d.ts.map +1 -1
  41. package/dist/identity.js +5 -0
  42. package/dist/identity.js.map +1 -1
  43. package/dist/kubo.d.ts +40 -0
  44. package/dist/kubo.d.ts.map +1 -0
  45. package/dist/kubo.js +555 -0
  46. package/dist/kubo.js.map +1 -0
  47. package/dist/pins.d.ts +3 -3
  48. package/dist/pins.js +1 -1
  49. package/dist/pins.js.map +1 -1
  50. package/dist/setup.d.ts +7 -0
  51. package/dist/setup.d.ts.map +1 -0
  52. package/dist/setup.js +22 -0
  53. package/dist/setup.js.map +1 -0
  54. package/dist/source-bundle.d.ts +3 -8
  55. package/dist/source-bundle.d.ts.map +1 -1
  56. package/dist/source-bundle.js +16 -11
  57. package/dist/source-bundle.js.map +1 -1
  58. package/dist/space.d.ts.map +1 -1
  59. package/dist/space.js +2 -2
  60. package/dist/space.js.map +1 -1
  61. package/dist/state.d.ts +7 -5
  62. package/dist/state.d.ts.map +1 -1
  63. package/dist/state.js +17 -14
  64. package/dist/state.js.map +1 -1
  65. package/dist/swarm-envelope.d.ts +36 -0
  66. package/dist/swarm-envelope.d.ts.map +1 -0
  67. package/dist/swarm-envelope.js +145 -0
  68. package/dist/swarm-envelope.js.map +1 -0
  69. package/dist/swarm-files.d.ts +6 -0
  70. package/dist/swarm-files.d.ts.map +1 -0
  71. package/dist/swarm-files.js +107 -0
  72. package/dist/swarm-files.js.map +1 -0
  73. package/dist/swarm.d.ts +120 -58
  74. package/dist/swarm.d.ts.map +1 -1
  75. package/dist/swarm.js +1065 -548
  76. package/dist/swarm.js.map +1 -1
  77. package/dist/template-definition.d.ts +47 -52
  78. package/dist/template-definition.d.ts.map +1 -1
  79. package/dist/template-definition.js +36 -41
  80. package/dist/template-definition.js.map +1 -1
  81. package/dist/template-source.d.ts +2 -0
  82. package/dist/template-source.d.ts.map +1 -1
  83. package/dist/template-source.js +4 -3
  84. package/dist/template-source.js.map +1 -1
  85. package/package.json +3 -3
  86. package/src/app-authoring.ts +22 -5
  87. package/src/app-definition.ts +33 -39
  88. package/src/app-templates.ts +9 -1
  89. package/src/assembly.ts +7 -4
  90. package/src/authoring.ts +31 -14
  91. package/src/builtins.ts +23 -2
  92. package/src/cli.ts +427 -147
  93. package/src/config.ts +32 -19
  94. package/src/content-provider.ts +5 -4
  95. package/src/get.ts +37 -15
  96. package/src/identity.ts +13 -0
  97. package/src/kubo.ts +732 -0
  98. package/src/pins.ts +1 -1
  99. package/src/setup.ts +21 -0
  100. package/src/source-bundle.ts +25 -12
  101. package/src/space.ts +2 -5
  102. package/src/state.ts +24 -15
  103. package/src/swarm-envelope.ts +255 -0
  104. package/src/swarm-files.ts +116 -0
  105. package/src/swarm.ts +1728 -836
  106. package/src/template-definition.ts +36 -41
  107. 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,13 +30,20 @@ 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,
46
+ sharedSwarmStatus,
40
47
  addSwarm,
41
48
  updateSwarm,
42
49
  searchNames,
@@ -92,17 +99,24 @@ export const processIO: IO = {
92
99
  },
93
100
  };
94
101
  const commands: Record<string, string> = {
102
+ setup: "setup [--yes]",
95
103
  "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]",
104
+ "swarm request":
105
+ "swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
106
+ "swarm export": "swarm export URL_OR_ALIAS --output FILE",
107
+ "swarm approve": "swarm approve REQUEST_FILE [--again] --yes",
108
+ "swarm exclude":
109
+ "swarm exclude MEMBER_PUBLIC_KEY [--swarm URL_OR_ALIAS] --yes",
110
+ "swarm resume": "swarm resume [URL_OR_ALIAS]",
111
+ "swarm profile":
112
+ "swarm profile [URL_OR_ALIAS] [--name NAME] [--address MULTIADDR]",
113
+ "swarm status": "swarm status [URL_OR_ALIAS]",
100
114
  "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",
115
+ "swarm add": "swarm add CONFIG_URL [--alias ALIAS]",
116
+ "swarm use": "swarm use URL_OR_ALIAS",
117
+ "swarm remove": "swarm remove URL_OR_ALIAS",
104
118
  "swarm update":
105
- "swarm update [CID_OR_ALIAS] [--name TEXT] [--description TEXT]",
119
+ "swarm update [URL_OR_ALIAS] [--name TEXT] [--description TEXT]",
106
120
  publish:
107
121
  "publish CID_OR_CAR [--name NAME [--expect OLD_NODE_CID | --snapshot]]",
108
122
  get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
@@ -152,6 +166,18 @@ const commandHelp: Record<
152
166
  notes?: string[];
153
167
  }
154
168
  > = {
169
+ setup: {
170
+ summary:
171
+ "Verify/install Kubo and prepare the protected HOME account identity",
172
+ examples: ["ipab setup --yes", "ipab setup"],
173
+ options: [
174
+ "--yes Confirm installation and identity initialization outside a TTY.",
175
+ ],
176
+ notes: [
177
+ "Idempotent: reuse the same verified program and existing identity.",
178
+ "Does not create Swarm repos, start or contact any daemon, deploy services or install login startup.",
179
+ ],
180
+ },
155
181
  "swarm create": {
156
182
  summary: "Create a swarm using the account HOME identity",
157
183
  options: [
@@ -168,39 +194,71 @@ const commandHelp: Record<
168
194
  ],
169
195
  notes: [
170
196
  "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.",
197
+ "Installs checksum-verified Kubo on demand; each Swarm has its own protected repo and ports.",
198
+ "Returns the public organization configuration URL; owner needs no certificate.",
173
199
  ],
174
200
  },
175
201
  "swarm request": {
176
- summary: "Publish a signed account membership request",
177
- examples: ["ipab swarm request SWARM_CID"],
202
+ summary: "Save and export a signed self-contained membership Request",
203
+ examples: [
204
+ "ipab swarm request CONFIG_URL --owner-fingerprint TRUSTED_FINGERPRINT --output request.json --alias work",
205
+ ],
206
+ options: [
207
+ "--owner-fingerprint VALUE Verify Owner through a trusted independent channel.",
208
+ "--name NAME Initial public display name.",
209
+ "--alias ALIAS Pre-register the target for lazy onboarding.",
210
+ "--output FILE Export the saved exact Request; no expiry or new PeerID on retry.",
211
+ ],
178
212
  notes: [
179
- "Returns one request CID. Private IPFS access is a prerequisite, not membership.",
213
+ "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
180
214
  ],
181
215
  },
182
216
  "swarm approve": {
183
217
  summary: "Owner signs a certificate for an exact request",
184
218
  options: [
185
219
  "--yes Explicit approval; required outside a TTY.",
186
- "--expires-in SECONDS 60..2592000; default 604800.",
220
+ "--again Explicit fresh approval of an old Request; history is advisory.",
221
+ ],
222
+ examples: ["ipab swarm approve request.json --yes"],
223
+ notes: [
224
+ "Creates a public profile and publishes an Owner-signed X25519/AES-GCM package. Exact-ID certificates have no expiry.",
187
225
  ],
188
- examples: ["ipab swarm approve REQUEST_CID --yes"],
189
- notes: ["Returns one response CID. Never exports the owner private key."],
190
226
  },
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."],
227
+ "swarm export": {
228
+ summary: "Re-export the same persisted Request",
229
+ examples: ["ipab swarm export work --output request.json"],
230
+ },
231
+ "swarm exclude": {
232
+ summary: "Owner removes a member with irreversible HEAD/key rotation",
233
+ examples: ["ipab --swarm work swarm exclude MEMBER_PUBLIC_KEY --yes"],
195
234
  notes: [
196
- "Requires this account's exact pending request and bound member certificate.",
235
+ "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.",
236
+ ],
237
+ },
238
+ "swarm resume": {
239
+ summary: "Owner resumes an interrupted organization switch",
240
+ examples: ["ipab swarm resume work"],
241
+ },
242
+ "swarm profile": {
243
+ summary: "Update your public display name and LAN/VPN IPv4 TCP address",
244
+ examples: [
245
+ "ipab swarm profile work --name Wei",
246
+ "ipab swarm profile work --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
197
247
  ],
198
248
  },
199
249
  "swarm status": {
200
- summary: "Authenticate the current swarm HEAD",
201
- examples: ["ipab swarm status", "ipab swarm status work"],
250
+ summary: "Read the current shared Swarm state",
251
+ options: [
252
+ "--local Also authenticate local membership, connect the node and diagnose interrupted Owner operations.",
253
+ ],
254
+ examples: [
255
+ "ipab swarm status",
256
+ "ipab swarm status work",
257
+ "ipab swarm status work --local",
258
+ ],
202
259
  notes: [
203
- "Always authenticate and refresh HEAD; update the local header cache.",
260
+ "Always read public configuration, Scope and HEAD, and verify the State. Local content needs no HOME identity or node activation.",
261
+ "Missing local content may require the registered Swarm's private source. --local preserves the full local diagnostic and header-cache update.",
204
262
  ],
205
263
  },
206
264
  "swarm list": {
@@ -213,7 +271,7 @@ const commandHelp: Record<
213
271
  options: [
214
272
  "--alias ALIAS Unique local alias; does not rename the shared swarm.",
215
273
  ],
216
- examples: ["ipab swarm add SWARM_CID --alias work"],
274
+ examples: ["ipab swarm add CONFIG_URL --alias work"],
217
275
  notes: [
218
276
  "Not a membership grant. The first registration becomes the saved default only if none exists.",
219
277
  ],
@@ -231,8 +289,8 @@ const commandHelp: Record<
231
289
  ],
232
290
  },
233
291
  "swarm update": {
234
- summary: "Update shared swarm information as an owner or member",
235
- arguments: ["CID_OR_ALIAS Defaults to the effective current swarm."],
292
+ summary: "Owner updates public organization information",
293
+ arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
236
294
  options: [
237
295
  "--name TEXT Replace the shared display name; empty text clears it.",
238
296
  "--description TEXT Replace the shared description; empty text clears it.",
@@ -242,9 +300,8 @@ const commandHelp: Record<
242
300
  'ipab swarm update --description ""',
243
301
  ],
244
302
  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.",
303
+ "Requires at least one field. Members can change only their own profile.",
304
+ "Content-CID CAS prevents overwriting concurrent organization changes.",
248
305
  "Shared name changes do not rename local registry aliases.",
249
306
  ],
250
307
  },
@@ -289,16 +346,18 @@ const commandHelp: Record<
289
346
  "--raw Select the Artifact node instead of its value.",
290
347
  "--force Refresh the shared Name's swarm HEAD.",
291
348
  "--no-force Override swarm.forceRefresh and use valid cached headers.",
292
- "-o, --output DIRECTORY New or empty directory; defaults to resolved CID.",
349
+ "-o, --output DIRECTORY New or empty directory; defaults to a unique temporary directory.",
293
350
  ],
294
351
  examples: [
295
352
  "ipab --json get ipab:///apps/hello -o hello-app",
296
353
  "ipab get ipab://work/apps/hello -o hello-app",
354
+ "ipab get CONTENT_CID",
297
355
  "ipab get --raw RELEASE_CID",
298
356
  ],
299
357
  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.",
358
+ "Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
359
+ "Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
360
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
302
361
  "Does not install, build, edit, or automatically retrieve associated source.",
303
362
  ],
304
363
  },
@@ -349,7 +408,7 @@ const commandHelp: Record<
349
408
  ],
350
409
  notes: [
351
410
  "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.",
411
+ "Instance paths come from .bundle.yaml; the referenced file defines the type. Imported DAG identities are preserved.",
353
412
  "Legacy App ipab.yaml is rejected; use project preparation tools separately.",
354
413
  "Select explicit files; review private files before providing Bundles.",
355
414
  "Store failures preserve the CAR; retry with ipab bundle import FILE.car.",
@@ -366,7 +425,7 @@ const commandHelp: Record<
366
425
  ],
367
426
  examples: [
368
427
  "ipab bundle build note",
369
- "ipab bundle build types\\.bundle.yaml --schema-only",
428
+ "ipab bundle build types\\.bundle-type.yaml --schema-only",
370
429
  ],
371
430
  notes: [
372
431
  "Imports into the configured Store without pinning or executing Apps.",
@@ -405,7 +464,7 @@ const commandHelp: Record<
405
464
  ],
406
465
  notes: [
407
466
  "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.",
467
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
409
468
  "History stores argv by default; do not put secrets in arguments.",
410
469
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
411
470
  "--json is not supported; App stdio is passed through.",
@@ -427,7 +486,7 @@ const commandHelp: Record<
427
486
  ],
428
487
  notes: [
429
488
  "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.",
489
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
431
490
  "Apps are NOT sandboxed; run only Apps you trust.",
432
491
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
433
492
  "--json is not supported; App stdio is passed through.",
@@ -577,7 +636,7 @@ const commandHelp: Record<
577
636
 
578
637
  export function help(path = ""): string {
579
638
  const globalOptions = `Global options (before COMMAND):
580
- --swarm CID|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
639
+ --swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
581
640
  --state-dir PATH Set the local state directory
582
641
  --store-gateway URL Use a read-only upstream HTTP gateway
583
642
  --json Output management/development metadata, not App stdio`;
@@ -598,6 +657,7 @@ Create:
598
657
  bundle ${groups.bundle}
599
658
 
600
659
  Manage:
660
+ setup ${commandHelp.setup!.summary}
601
661
  swarm ${groups.swarm}
602
662
  search Search formal Names across registered swarms
603
663
  publish ${commandHelp.publish!.summary}
@@ -848,7 +908,11 @@ export function parse(argv: readonly string[]): Parsed {
848
908
  result.positional = tokens;
849
909
  return result;
850
910
  }
851
- if (!["open", "init", "build", "publish", "get", "search"].includes(group)) {
911
+ if (
912
+ !["open", "init", "build", "publish", "get", "search", "setup"].includes(
913
+ group,
914
+ )
915
+ ) {
852
916
  if (
853
917
  ![
854
918
  "bundle",
@@ -885,52 +949,77 @@ export function parse(argv: readonly string[]): Parsed {
885
949
  "API key must be provided through '-' and piped stdin; never pass it in command arguments.",
886
950
  );
887
951
  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"
903
- ? ["yes"]
904
- : result.path === "open"
905
- ? ["log", "raw", "force", "no-force"]
906
- : [];
952
+ result.path === "setup"
953
+ ? ["yes"]
954
+ : result.path === "bundle build"
955
+ ? ["replace", "schema-only", "no-import"]
956
+ : result.path === "build"
957
+ ? ["replace", "no-import"]
958
+ : result.path === "publish"
959
+ ? ["snapshot"]
960
+ : result.path === "get"
961
+ ? ["raw", "force", "no-force"]
962
+ : result.path === "search"
963
+ ? ["current", "force", "no-force"]
964
+ : result.path === "swarm approve"
965
+ ? ["yes", "again"]
966
+ : result.path === "swarm status"
967
+ ? ["local"]
968
+ : result.path === "swarm exclude"
969
+ ? ["yes"]
970
+ : result.path === "register set"
971
+ ? ["replace"]
972
+ : result.path === "history remove"
973
+ ? ["yes"]
974
+ : result.path === "open"
975
+ ? ["log", "raw", "force", "no-force"]
976
+ : [];
907
977
  const values =
908
978
  result.path === "swarm create"
909
979
  ? ["service", "resume", "name", "description", "alias"]
910
- : result.path === "swarm add" || result.path === "swarm join"
980
+ : result.path === "swarm add"
911
981
  ? ["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
- : [];
982
+ : result.path === "swarm request"
983
+ ? ["owner-fingerprint", "name", "alias", "output"]
984
+ : result.path === "swarm export"
985
+ ? ["output"]
986
+ : result.path === "swarm profile"
987
+ ? ["name", "address"]
988
+ : result.path === "swarm update"
989
+ ? ["name", "description"]
990
+ : result.path === "swarm approve"
991
+ ? []
992
+ : result.path === "publish"
993
+ ? ["name", "expect"]
994
+ : result.path === "get"
995
+ ? ["output"]
996
+ : result.path === "init"
997
+ ? ["template"]
998
+ : result.path === "bundle build" ||
999
+ result.path === "build"
1000
+ ? ["output"]
1001
+ : result.path === "history list"
1002
+ ? [
1003
+ "app",
1004
+ "status",
1005
+ "since",
1006
+ "until",
1007
+ "limit",
1008
+ "before",
1009
+ ]
1010
+ : result.path === "history remove"
1011
+ ? ["app", "status", "since", "until"]
1012
+ : result.path === "pin list"
1013
+ ? ["type"]
1014
+ : [];
931
1015
  while (tokens.length) {
932
1016
  const value = tokens.shift()!;
933
- if (value.startsWith("--") || value === "-o") {
1017
+ if (
1018
+ result.path === "swarm exclude" &&
1019
+ /^--[A-Za-z0-9_-]{41}$/.test(value)
1020
+ ) {
1021
+ result.positional.push(value);
1022
+ } else if (value.startsWith("--") || value === "-o") {
934
1023
  const option = value === "-o" ? "output" : value.slice(2);
935
1024
  if (result.path === "init" && option === "param") {
936
1025
  const input = tokens.shift();
@@ -946,7 +1035,11 @@ export function parse(argv: readonly string[]): Parsed {
946
1035
  const input = tokens.shift();
947
1036
  if (
948
1037
  input === undefined ||
949
- input.startsWith("--") ||
1038
+ (input.startsWith("--") &&
1039
+ !(
1040
+ ["resume", "owner-fingerprint"].includes(option) &&
1041
+ /^[A-Za-z0-9_-]{43}$/.test(input)
1042
+ )) ||
950
1043
  (input === "" && result.path !== "swarm update")
951
1044
  )
952
1045
  syntax(`${value} needs a value.`);
@@ -963,10 +1056,14 @@ export function parse(argv: readonly string[]): Parsed {
963
1056
  )
964
1057
  syntax("--current and --swarm are mutually exclusive.");
965
1058
  const counts: Record<string, [number, number]> = {
1059
+ setup: [0, 0],
966
1060
  "swarm create": [0, 0],
967
1061
  "swarm request": [1, 1],
968
1062
  "swarm approve": [1, 1],
969
- "swarm join": [1, 1],
1063
+ "swarm export": [1, 1],
1064
+ "swarm exclude": [1, 1],
1065
+ "swarm resume": [0, 1],
1066
+ "swarm profile": [0, 1],
970
1067
  "swarm status": [0, 1],
971
1068
  "swarm list": [0, 0],
972
1069
  "swarm add": [1, 1],
@@ -1076,6 +1173,28 @@ async function performCli(
1076
1173
  }
1077
1174
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
1078
1175
  syntax("Non-interactive history remove requires --yes.");
1176
+ if (parsed.path === "setup") {
1177
+ if (
1178
+ !parsed.options.yes &&
1179
+ (!io.tty ||
1180
+ !(await io.confirm(
1181
+ "Install checksum-verified Kubo and initialize/reuse the protected HOME identity? No daemon will be contacted or started.",
1182
+ )))
1183
+ )
1184
+ throw new HostError(
1185
+ "Setup requires explicit --yes or interactive confirmation.",
1186
+ );
1187
+ const result = await setupDevice(
1188
+ stateLocation(parsed.flags, env).path,
1189
+ env,
1190
+ );
1191
+ io.out(
1192
+ parsed.flags.json
1193
+ ? JSON.stringify(result)
1194
+ : `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`,
1195
+ );
1196
+ return 0;
1197
+ }
1079
1198
  const builtins = await builtinContent();
1080
1199
  state = new State(stateLocation(parsed.flags, env).path, builtins.pins);
1081
1200
  if (
@@ -1091,7 +1210,10 @@ async function performCli(
1091
1210
  return 0;
1092
1211
  }
1093
1212
  const items = effectiveConfig(
1094
- state.config(),
1213
+ state.config({
1214
+ includeSecrets:
1215
+ parsed.path !== "swarm status" || Boolean(parsed.options.local),
1216
+ }),
1095
1217
  parsed.flags,
1096
1218
  env,
1097
1219
  (reference) => state!.resolveSwarm(reference),
@@ -1107,12 +1229,17 @@ async function performCli(
1107
1229
  ? undefined
1108
1230
  : String(value("swarm.default"));
1109
1231
  const swarmContext = (): SwarmContext => ({
1110
- store: store!,
1232
+ get store() {
1233
+ return store!;
1234
+ },
1235
+ set store(next) {
1236
+ store = next;
1237
+ },
1111
1238
  state: state!,
1112
1239
  env,
1113
1240
  stateDir: stateLocation(parsed.flags, env).path,
1114
- provider: String(value("swarm.provider") ?? "http://127.0.0.1:5001"),
1115
1241
  cacheTtl: Number(value("swarm.cacheTtl")),
1242
+ listen: value("swarm.listen") === "loopback" ? "loopback" : "lan",
1116
1243
  forceRefresh: parsed.options.force
1117
1244
  ? true
1118
1245
  : parsed.options["no-force"]
@@ -1148,14 +1275,27 @@ async function performCli(
1148
1275
  case "swarm list": {
1149
1276
  const result = { swarms: state.swarms(), ...selection() };
1150
1277
  emit(
1151
- result,
1278
+ {
1279
+ ...result,
1280
+ swarms: result.swarms.map((entry) => ({
1281
+ configUrl: entry.cid,
1282
+ alias: entry.alias,
1283
+ })),
1284
+ },
1152
1285
  [
1153
1286
  ...result.swarms.map(
1154
1287
  (entry) =>
1155
- `${entry.cid === result.savedCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`,
1288
+ `${entry.cid === result.effectiveCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`,
1156
1289
  ),
1157
- `Saved current: ${result.savedCurrent ?? "(none)"}`,
1158
- `Effective current: ${result.effectiveCurrent ?? "(none)"} (${result.source})`,
1290
+ ...(result.swarms.length ? [] : ["No registered Swarms."]),
1291
+ ...(result.effectiveCurrent === null
1292
+ ? ["Use ipab swarm use <alias> to select a default Swarm."]
1293
+ : []),
1294
+ ...(result.effectiveCurrent !== result.savedCurrent
1295
+ ? [
1296
+ `Selected via --swarm: ${printable(String(result.swarms.find((entry) => entry.cid === result.effectiveCurrent)?.alias ?? result.effectiveCurrent ?? "(none)"))}; saved default: ${printable(String(result.swarms.find((entry) => entry.cid === result.savedCurrent)?.alias ?? result.savedCurrent ?? "(none)"))}.`,
1297
+ ]
1298
+ : []),
1159
1299
  ].join("\n"),
1160
1300
  );
1161
1301
  break;
@@ -1184,17 +1324,67 @@ async function performCli(
1184
1324
  case "swarm create":
1185
1325
  case "swarm request":
1186
1326
  case "swarm approve":
1187
- case "swarm join":
1327
+ case "swarm export":
1328
+ case "swarm exclude":
1329
+ case "swarm resume":
1330
+ case "swarm profile":
1188
1331
  case "swarm status":
1189
1332
  case "publish":
1190
1333
  case "get": {
1191
1334
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1192
1335
  const context = swarmContext();
1336
+ if (parsed.path === "swarm export") {
1337
+ const id = await exportRequest(
1338
+ context,
1339
+ state.resolveSwarm(first!),
1340
+ String(parsed.options.output ?? ""),
1341
+ );
1342
+ emit({ id }, id);
1343
+ break;
1344
+ }
1345
+ if (
1346
+ ["swarm exclude", "swarm resume", "swarm profile"].includes(
1347
+ parsed.path,
1348
+ )
1349
+ ) {
1350
+ const url =
1351
+ parsed.path === "swarm exclude"
1352
+ ? selectedSwarm
1353
+ : first
1354
+ ? state.resolveSwarm(first)
1355
+ : selectedSwarm;
1356
+ if (!url) syntax("Select a Swarm configuration URL or alias.");
1357
+ if (parsed.path === "swarm exclude") {
1358
+ if (!parsed.options.yes)
1359
+ syntax("Member removal is irreversible; --yes required.");
1360
+ await removeMember(context, url, first!);
1361
+ } else if (parsed.path === "swarm resume")
1362
+ await resumeRemoval(context, url);
1363
+ else {
1364
+ const profile = await updateProfile(context, url, {
1365
+ ...(typeof parsed.options.name === "string"
1366
+ ? { name: parsed.options.name }
1367
+ : {}),
1368
+ ...(typeof parsed.options.address === "string"
1369
+ ? { addresses: [parsed.options.address] }
1370
+ : {}),
1371
+ });
1372
+ emit(profile, JSON.stringify(profile));
1373
+ store = context.store;
1374
+ break;
1375
+ }
1376
+ store = context.store;
1377
+ emit(
1378
+ { url, completed: true },
1379
+ `Organization switch complete: ${url}`,
1380
+ );
1381
+ break;
1382
+ }
1193
1383
  if (parsed.path === "swarm update") {
1194
1384
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1195
1385
  if (!cid)
1196
1386
  syntax(
1197
- "swarm update requires a registered alias, Swarm CID or current swarm.",
1387
+ "swarm update requires a registered alias, configuration URL or current swarm.",
1198
1388
  );
1199
1389
  const result = await updateSwarm(context, cid, {
1200
1390
  ...(typeof parsed.options.name === "string"
@@ -1206,12 +1396,12 @@ async function performCli(
1206
1396
  });
1207
1397
  emit(
1208
1398
  result,
1209
- `Swarm: ${result.cid}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD: ${result.root}\nRevision: ${result.revision}`,
1399
+ `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`,
1210
1400
  );
1211
1401
  break;
1212
1402
  }
1213
1403
  if (parsed.path === "swarm add") {
1214
- const cid = exactCid(first!);
1404
+ const cid = state.resolveSwarm(first!);
1215
1405
  await addSwarm(
1216
1406
  context,
1217
1407
  cid,
@@ -1221,7 +1411,11 @@ async function performCli(
1221
1411
  );
1222
1412
  const entry = state.registeredSwarm(cid);
1223
1413
  emit(
1224
- { ...entry, savedCurrent: state.config()["swarm.default"] ?? null },
1414
+ {
1415
+ configUrl: entry.cid,
1416
+ alias: entry.alias,
1417
+ savedCurrent: state.config()["swarm.default"] ?? null,
1418
+ },
1225
1419
  `Registered swarm ${entry.alias ?? cid} (${cid}).`,
1226
1420
  );
1227
1421
  break;
@@ -1263,40 +1457,114 @@ async function performCli(
1263
1457
  if (parsed.path === "swarm status") {
1264
1458
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1265
1459
  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);
1460
+ syntax(
1461
+ "swarm status requires a configuration URL or swarm.default.",
1462
+ );
1463
+ const local = Boolean(parsed.options.local);
1464
+ const { head, config } = local
1465
+ ? await swarmHeader(context, cid, true)
1466
+ : await sharedSwarmStatus(context, cid);
1467
+ const fingerprint = await keyId(config.owner);
1468
+ store = context.store;
1269
1469
  emit(
1270
1470
  {
1271
- cid,
1272
- ...data,
1471
+ configUrl: cid,
1472
+ owner: config.owner,
1473
+ ownerFingerprint: fingerprint,
1474
+ epoch: config.epoch,
1475
+ ...(local
1476
+ ? {
1477
+ peerId: context.node!.peerId,
1478
+ addresses: context.node!.addresses,
1479
+ }
1480
+ : {}),
1273
1481
  root: head.root,
1274
- revision: head.revision,
1275
- properties: snapshot.properties,
1482
+ valueCid: head.cid,
1483
+ properties: {
1484
+ name: config.name,
1485
+ description: config.description,
1486
+ },
1276
1487
  },
1277
- `Swarm: ${cid}\nName: ${printable(snapshot.properties.name)}\nDescription: ${printable(snapshot.properties.description)}\nHEAD: ${head.root}\nRevision: ${head.revision}`,
1488
+ [
1489
+ "Swarm",
1490
+ ` Name: ${printable(config.name)}`,
1491
+ ` Description: ${config.description ? printable(config.description) : "(none)"}`,
1492
+ " Config URL:",
1493
+ ` ${cid}`,
1494
+ "",
1495
+ "Identity",
1496
+ " Owner fingerprint:",
1497
+ ` ${fingerprint}`,
1498
+ ...(local
1499
+ ? [
1500
+ " PeerID:",
1501
+ ` ${context.node!.peerId}`,
1502
+ "",
1503
+ "Local addresses",
1504
+ ...context.node!.addresses.map(
1505
+ (address) => ` ${printable(address)}`,
1506
+ ),
1507
+ ]
1508
+ : []),
1509
+ "",
1510
+ "Content",
1511
+ " HEAD (publication root):",
1512
+ ` ${head.root}`,
1513
+ " Content CID (HEAD value):",
1514
+ ` ${head.cid}`,
1515
+ ].join("\n"),
1278
1516
  );
1279
1517
  break;
1280
1518
  }
1281
1519
  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}`,
1520
+ const localCid = first!.startsWith("ipab://")
1521
+ ? undefined
1522
+ : state.resolve(first!);
1523
+ const builtin = builtins.pins.find((pin) => pin.cid === localCid);
1524
+ const selected = builtin
1525
+ ? { cid: builtin.cid, targetCid: builtin.cid }
1526
+ : await resolveReference(
1527
+ context,
1528
+ first!,
1529
+ selectedSwarm,
1530
+ (reference) => state!.resolve(reference),
1531
+ Boolean(parsed.options.raw),
1532
+ );
1533
+ const contentStore = context.store;
1534
+ const source = IpfsStore.fromClient(
1535
+ {
1536
+ block: {
1537
+ get: (key, options) => {
1538
+ options?.signal?.throwIfAborted();
1539
+ const builtin = builtins.blocks.get(
1540
+ CID.parse(key).toV1().toString(),
1541
+ );
1542
+ return builtin
1543
+ ? Promise.resolve(builtin.slice())
1544
+ : contentStore.block.get(key, options);
1545
+ },
1546
+ },
1547
+ },
1548
+ contentStore.limits,
1299
1549
  );
1550
+ let directory: string;
1551
+ try {
1552
+ directory = await getBundle(
1553
+ source,
1554
+ selected.cid,
1555
+ typeof parsed.options.output === "string"
1556
+ ? parsed.options.output
1557
+ : undefined,
1558
+ );
1559
+ } finally {
1560
+ await source.close();
1561
+ }
1562
+ const closing = store;
1563
+ store = undefined;
1564
+ await closeStore(closing, undefined);
1565
+ state.close();
1566
+ state = undefined;
1567
+ emit({ ...selected, directory }, directory);
1300
1568
  break;
1301
1569
  }
1302
1570
  let cid: string;
@@ -1317,34 +1585,35 @@ async function performCli(
1317
1585
  : {}),
1318
1586
  });
1319
1587
  } else if (parsed.path === "swarm request")
1320
- cid = await requestMembership(context, exactCid(first!));
1588
+ cid = await requestMembership(context, first!, {
1589
+ ownerFingerprint: String(parsed.options["owner-fingerprint"] ?? ""),
1590
+ ...(typeof parsed.options.name === "string"
1591
+ ? { name: parsed.options.name }
1592
+ : {}),
1593
+ ...(typeof parsed.options.alias === "string"
1594
+ ? { alias: parsed.options.alias }
1595
+ : {}),
1596
+ ...(typeof parsed.options.output === "string"
1597
+ ? { output: parsed.options.output }
1598
+ : {}),
1599
+ });
1321
1600
  else if (parsed.path === "swarm approve") {
1601
+ const request = await verifiedRequest(first!);
1602
+ io.err(await membershipRequestSummary(request));
1322
1603
  if (
1323
1604
  !parsed.options.yes &&
1324
1605
  (!io.tty ||
1325
1606
  !(await io.confirm(
1326
- `Approve membership request ${first!}? This grants swarm HEAD read/write access.`,
1607
+ `Approve the verified Request ${request.id} above? This grants current HEAD and the member's profile write access; all reads are public.`,
1327
1608
  )))
1328
1609
  )
1329
1610
  throw new HostError(
1330
1611
  "Approval requires explicit --yes or interactive confirmation.",
1331
1612
  );
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 {
1613
+ cid = await approveMembership(context, request, {
1614
+ again: Boolean(parsed.options.again),
1615
+ });
1616
+ } else {
1348
1617
  let content: string;
1349
1618
  if (first!.toLowerCase().endsWith(".car"))
1350
1619
  content = (
@@ -1362,11 +1631,19 @@ async function performCli(
1362
1631
  snapshot: Boolean(parsed.options.snapshot),
1363
1632
  });
1364
1633
  }
1365
- if (parsed.path === "swarm create" || parsed.path === "swarm join")
1634
+ store = context.store;
1635
+ if (parsed.path === "swarm create")
1366
1636
  io.err(
1367
1637
  `Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`,
1368
1638
  );
1369
- emit({ cid }, cid);
1639
+ emit(
1640
+ parsed.path === "swarm request"
1641
+ ? { requestId: cid }
1642
+ : parsed.path === "swarm create" || parsed.path === "swarm approve"
1643
+ ? { configUrl: cid }
1644
+ : { cid },
1645
+ cid,
1646
+ );
1370
1647
  break;
1371
1648
  }
1372
1649
  case "store usage":
@@ -1529,7 +1806,7 @@ async function performCli(
1529
1806
  } else
1530
1807
  emit(
1531
1808
  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"}`,
1809
+ `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
1810
  );
1534
1811
  } catch (cause) {
1535
1812
  if (cancelled)
@@ -1583,12 +1860,13 @@ async function performCli(
1583
1860
  emit(
1584
1861
  { items: listed, pending, invalid },
1585
1862
  table(
1586
- ["NAME", "CID", "KIND", "BUNDLE TYPE", "SOURCE"],
1863
+ ["NAME", "CID", "KIND", "TITLE", "TYPE CID", "SOURCE"],
1587
1864
  listed.map((pin) => [
1588
1865
  pin.name,
1589
1866
  pin.cid,
1590
1867
  pin.kind,
1591
- pin.typeName,
1868
+ pin.title,
1869
+ pin.schemaCid,
1592
1870
  pin.builtin ? "built-in (read-only)" : "user",
1593
1871
  ]),
1594
1872
  "No named pins.",
@@ -1606,7 +1884,7 @@ async function performCli(
1606
1884
  );
1607
1885
  emit(
1608
1886
  result,
1609
- `${result.name} → ${result.cid}\nBundle type: ${printable(result.typeName)}`,
1887
+ `${result.name} → ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}`,
1610
1888
  );
1611
1889
  break;
1612
1890
  }
@@ -1627,7 +1905,7 @@ async function performCli(
1627
1905
  const result = pinDetails(pin);
1628
1906
  emit(
1629
1907
  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)"}`,
1908
+ `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
1909
  );
1632
1910
  break;
1633
1911
  }
@@ -1801,15 +2079,17 @@ async function performCli(
1801
2079
  );
1802
2080
  await recoverInactive(state);
1803
2081
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
2082
+ const context = swarmContext();
1804
2083
  const target = (
1805
2084
  await resolveReference(
1806
- swarmContext(),
2085
+ context,
1807
2086
  first!,
1808
2087
  selectedSwarm,
1809
2088
  (reference) => state!.resolve(reference),
1810
2089
  Boolean(parsed.options.raw),
1811
2090
  )
1812
2091
  ).cid;
2092
+ store = context.store;
1813
2093
  let appCid: string;
1814
2094
  let appArgv: string[];
1815
2095
  if (parsed.path === "open") {