@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/dist/cli.js CHANGED
@@ -2,6 +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 { CID } from "multiformats/cid";
5
6
  import stringWidth from "string-width";
6
7
  import { configKey, effectiveConfig, parseValue, publicUrl, stateLocation, storeConfiguration, visibleConfig, } from "./config.js";
7
8
  import { HostError, message, object, syntax } from "./errors.js";
@@ -13,7 +14,9 @@ import { buildBundle, inspectBundle, importBundle } from "./authoring.js";
13
14
  import { initApp } from "./app-authoring.js";
14
15
  import { assembleBundle } from "./assembly.js";
15
16
  import { getBundle } from "./get.js";
16
- import { createSwarm, requestMembership, approveMembership, joinSwarm, descriptor, swarmHeader, addSwarm, updateSwarm, searchNames, resolveReference, publish, } from "./swarm.js";
17
+ import { setupDevice } from "./setup.js";
18
+ 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";
17
20
  import { schemaAlias } from "./app-definition.js";
18
21
  import { addPin, deletePin, pinDetails, renamePin } from "./pins.js";
19
22
  import { logFiles } from "./logs.js";
@@ -50,16 +53,20 @@ export const processIO = {
50
53
  },
51
54
  };
52
55
  const commands = {
56
+ setup: "setup [--yes]",
53
57
  "swarm create": "swarm create [--service URL] [--resume OPERATION]",
54
- "swarm request": "swarm request SWARM_CID",
55
- "swarm approve": "swarm approve REQUEST_CID [--expires-in SECONDS] --yes",
56
- "swarm join": "swarm join RESPONSE_CID",
57
- "swarm status": "swarm status [SWARM_CID]",
58
+ "swarm request": "swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
59
+ "swarm export": "swarm export URL_OR_ALIAS --output FILE",
60
+ "swarm approve": "swarm approve REQUEST_FILE [--again] --yes",
61
+ "swarm exclude": "swarm exclude MEMBER_PUBLIC_KEY [--swarm URL_OR_ALIAS] --yes",
62
+ "swarm resume": "swarm resume [URL_OR_ALIAS]",
63
+ "swarm profile": "swarm profile [URL_OR_ALIAS] [--name NAME] [--address MULTIADDR]",
64
+ "swarm status": "swarm status [URL_OR_ALIAS]",
58
65
  "swarm list": "swarm list",
59
- "swarm add": "swarm add SWARM_CID [--alias ALIAS]",
60
- "swarm use": "swarm use CID_OR_ALIAS",
61
- "swarm remove": "swarm remove CID_OR_ALIAS",
62
- "swarm update": "swarm update [CID_OR_ALIAS] [--name TEXT] [--description TEXT]",
66
+ "swarm add": "swarm add CONFIG_URL [--alias ALIAS]",
67
+ "swarm use": "swarm use URL_OR_ALIAS",
68
+ "swarm remove": "swarm remove URL_OR_ALIAS",
69
+ "swarm update": "swarm update [URL_OR_ALIAS] [--name TEXT] [--description TEXT]",
63
70
  publish: "publish CID_OR_CAR [--name NAME [--expect OLD_NODE_CID | --snapshot]]",
64
71
  get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
65
72
  search: "search QUERY [--current] [--force | --no-force]",
@@ -97,6 +104,17 @@ const groups = {
97
104
  history: "View and remove execution history",
98
105
  };
99
106
  const commandHelp = {
107
+ setup: {
108
+ summary: "Verify/install Kubo and prepare the protected HOME account identity",
109
+ examples: ["ipab setup --yes", "ipab setup"],
110
+ options: [
111
+ "--yes Confirm installation and identity initialization outside a TTY.",
112
+ ],
113
+ notes: [
114
+ "Idempotent: reuse the same verified program and existing identity.",
115
+ "Does not create Swarm repos, start or contact any daemon, deploy services or install login startup.",
116
+ ],
117
+ },
100
118
  "swarm create": {
101
119
  summary: "Create a swarm using the account HOME identity",
102
120
  options: [
@@ -113,39 +131,71 @@ const commandHelp = {
113
131
  ],
114
132
  notes: [
115
133
  "Creation uses the protected, origin-bound API key and owner possession proof.",
116
- "Uses the prepared private Kubo provider; never deploys infrastructure.",
117
- "Returns one descriptor CID; owner needs no member certificate.",
134
+ "Installs checksum-verified Kubo on demand; each Swarm has its own protected repo and ports.",
135
+ "Returns the public organization configuration URL; owner needs no certificate.",
118
136
  ],
119
137
  },
120
138
  "swarm request": {
121
- summary: "Publish a signed account membership request",
122
- examples: ["ipab swarm request SWARM_CID"],
139
+ summary: "Save and export a signed self-contained membership Request",
140
+ examples: [
141
+ "ipab swarm request CONFIG_URL --owner-fingerprint TRUSTED_FINGERPRINT --output request.json --alias work",
142
+ ],
143
+ options: [
144
+ "--owner-fingerprint VALUE Verify Owner through a trusted independent channel.",
145
+ "--name NAME Initial public display name.",
146
+ "--alias ALIAS Pre-register the target for lazy onboarding.",
147
+ "--output FILE Export the saved exact Request; no expiry or new PeerID on retry.",
148
+ ],
123
149
  notes: [
124
- "Returns one request CID. Private IPFS access is a prerequisite, not membership.",
150
+ "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
125
151
  ],
126
152
  },
127
153
  "swarm approve": {
128
154
  summary: "Owner signs a certificate for an exact request",
129
155
  options: [
130
156
  "--yes Explicit approval; required outside a TTY.",
131
- "--expires-in SECONDS 60..2592000; default 604800.",
157
+ "--again Explicit fresh approval of an old Request; history is advisory.",
158
+ ],
159
+ examples: ["ipab swarm approve request.json --yes"],
160
+ notes: [
161
+ "Creates a public profile and publishes an Owner-signed X25519/AES-GCM package. Exact-ID certificates have no expiry.",
132
162
  ],
133
- examples: ["ipab swarm approve REQUEST_CID --yes"],
134
- notes: ["Returns one response CID. Never exports the owner private key."],
135
163
  },
136
- "swarm join": {
137
- summary: "Verify a response and authenticate HEAD",
138
- examples: ["ipab swarm join RESPONSE_CID"],
139
- options: ["--alias ALIAS Register this swarm with a local alias."],
164
+ "swarm export": {
165
+ summary: "Re-export the same persisted Request",
166
+ examples: ["ipab swarm export work --output request.json"],
167
+ },
168
+ "swarm exclude": {
169
+ summary: "Owner removes a member with irreversible HEAD/key rotation",
170
+ examples: ["ipab --swarm work swarm exclude MEMBER_PUBLIC_KEY --yes"],
140
171
  notes: [
141
- "Requires this account's exact pending request and bound member certificate.",
172
+ "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.",
173
+ ],
174
+ },
175
+ "swarm resume": {
176
+ summary: "Owner resumes an interrupted organization switch",
177
+ examples: ["ipab swarm resume work"],
178
+ },
179
+ "swarm profile": {
180
+ summary: "Update your public display name and LAN/VPN IPv4 TCP address",
181
+ examples: [
182
+ "ipab swarm profile work --name Wei",
183
+ "ipab swarm profile work --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
142
184
  ],
143
185
  },
144
186
  "swarm status": {
145
- summary: "Authenticate the current swarm HEAD",
146
- examples: ["ipab swarm status", "ipab swarm status work"],
187
+ summary: "Read the current shared Swarm state",
188
+ options: [
189
+ "--local Also authenticate local membership, connect the node and diagnose interrupted Owner operations.",
190
+ ],
191
+ examples: [
192
+ "ipab swarm status",
193
+ "ipab swarm status work",
194
+ "ipab swarm status work --local",
195
+ ],
147
196
  notes: [
148
- "Always authenticate and refresh HEAD; update the local header cache.",
197
+ "Always read public configuration, Scope and HEAD, and verify the State. Local content needs no HOME identity or node activation.",
198
+ "Missing local content may require the registered Swarm's private source. --local preserves the full local diagnostic and header-cache update.",
149
199
  ],
150
200
  },
151
201
  "swarm list": {
@@ -158,7 +208,7 @@ const commandHelp = {
158
208
  options: [
159
209
  "--alias ALIAS Unique local alias; does not rename the shared swarm.",
160
210
  ],
161
- examples: ["ipab swarm add SWARM_CID --alias work"],
211
+ examples: ["ipab swarm add CONFIG_URL --alias work"],
162
212
  notes: [
163
213
  "Not a membership grant. The first registration becomes the saved default only if none exists.",
164
214
  ],
@@ -176,8 +226,8 @@ const commandHelp = {
176
226
  ],
177
227
  },
178
228
  "swarm update": {
179
- summary: "Update shared swarm information as an owner or member",
180
- arguments: ["CID_OR_ALIAS Defaults to the effective current swarm."],
229
+ summary: "Owner updates public organization information",
230
+ arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
181
231
  options: [
182
232
  "--name TEXT Replace the shared display name; empty text clears it.",
183
233
  "--description TEXT Replace the shared description; empty text clears it.",
@@ -187,9 +237,8 @@ const commandHelp = {
187
237
  'ipab swarm update --description ""',
188
238
  ],
189
239
  notes: [
190
- "Requires at least one field. Any authorized member can update both fields.",
191
- "Last successful write wins for the specified fields; no expected-value/version input.",
192
- "Automatically retries HEAD contention while preserving current Names and unspecified properties.",
240
+ "Requires at least one field. Members can change only their own profile.",
241
+ "Content-CID CAS prevents overwriting concurrent organization changes.",
193
242
  "Shared name changes do not rename local registry aliases.",
194
243
  ],
195
244
  },
@@ -234,16 +283,18 @@ const commandHelp = {
234
283
  "--raw Select the Artifact node instead of its value.",
235
284
  "--force Refresh the shared Name's swarm HEAD.",
236
285
  "--no-force Override swarm.forceRefresh and use valid cached headers.",
237
- "-o, --output DIRECTORY New or empty directory; defaults to resolved CID.",
286
+ "-o, --output DIRECTORY New or empty directory; defaults to a unique temporary directory.",
238
287
  ],
239
288
  examples: [
240
289
  "ipab --json get ipab:///apps/hello -o hello-app",
241
290
  "ipab get ipab://work/apps/hello -o hello-app",
291
+ "ipab get CONTENT_CID",
242
292
  "ipab get --raw RELEASE_CID",
243
293
  ],
244
294
  notes: [
245
- "Returns the selected content CID and original target CID (editing baseline).",
246
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
295
+ "Stdout contains only the absolute directory path; --json also returns content and original target CIDs.",
296
+ "Temporary exports remain after exit; copy before cleanup, not symlink. Use --output for a persistent destination.",
297
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
247
298
  "Does not install, build, edit, or automatically retrieve associated source.",
248
299
  ],
249
300
  },
@@ -294,7 +345,7 @@ const commandHelp = {
294
345
  ],
295
346
  notes: [
296
347
  "Recipe explicitly maps source files and exact CID imports to target paths.",
297
- "Type and entry come from .bundle.yaml; imported DAG identities are preserved.",
348
+ "Instance paths come from .bundle.yaml; the referenced file defines the type. Imported DAG identities are preserved.",
298
349
  "Legacy App ipab.yaml is rejected; use project preparation tools separately.",
299
350
  "Select explicit files; review private files before providing Bundles.",
300
351
  "Store failures preserve the CAR; retry with ipab bundle import FILE.car.",
@@ -311,7 +362,7 @@ const commandHelp = {
311
362
  ],
312
363
  examples: [
313
364
  "ipab bundle build note",
314
- "ipab bundle build types\\.bundle.yaml --schema-only",
365
+ "ipab bundle build types\\.bundle-type.yaml --schema-only",
315
366
  ],
316
367
  notes: [
317
368
  "Imports into the configured Store without pinning or executing Apps.",
@@ -350,7 +401,7 @@ const commandHelp = {
350
401
  ],
351
402
  notes: [
352
403
  "Apps are NOT sandboxed; run only Apps you trust.",
353
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
404
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
354
405
  "History stores argv by default; do not put secrets in arguments.",
355
406
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
356
407
  "--json is not supported; App stdio is passed through.",
@@ -372,7 +423,7 @@ const commandHelp = {
372
423
  ],
373
424
  notes: [
374
425
  "Requires a saved registration and App support for the exact content type.",
375
- "ipab://SWARM_CID_OR_ALIAS/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
426
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
376
427
  "Apps are NOT sandboxed; run only Apps you trust.",
377
428
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
378
429
  "--json is not supported; App stdio is passed through.",
@@ -521,7 +572,7 @@ const commandHelp = {
521
572
  };
522
573
  export function help(path = "") {
523
574
  const globalOptions = `Global options (before COMMAND):
524
- --swarm CID|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
575
+ --swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
525
576
  --state-dir PATH Set the local state directory
526
577
  --store-gateway URL Use a read-only upstream HTTP gateway
527
578
  --json Output management/development metadata, not App stdio`;
@@ -541,6 +592,7 @@ Create:
541
592
  bundle ${groups.bundle}
542
593
 
543
594
  Manage:
595
+ setup ${commandHelp.setup.summary}
544
596
  swarm ${groups.swarm}
545
597
  search Search formal Names across registered swarms
546
598
  publish ${commandHelp.publish.summary}
@@ -759,7 +811,7 @@ export function parse(argv) {
759
811
  result.positional = tokens;
760
812
  return result;
761
813
  }
762
- if (!["open", "init", "build", "publish", "get", "search"].includes(group)) {
814
+ if (!["open", "init", "build", "publish", "get", "search", "setup"].includes(group)) {
763
815
  if (![
764
816
  "bundle",
765
817
  "pin",
@@ -793,51 +845,75 @@ export function parse(argv) {
793
845
  tokens.includes("pointers.apiKey") &&
794
846
  !(tokens.length === 2 && tokens[1] === "-"))
795
847
  syntax("API key must be provided through '-' and piped stdin; never pass it in command arguments.");
796
- const booleans = result.path === "bundle build"
797
- ? ["replace", "schema-only", "no-import"]
798
- : result.path === "build"
799
- ? ["replace", "no-import"]
800
- : result.path === "publish"
801
- ? ["snapshot"]
802
- : result.path === "get"
803
- ? ["raw", "force", "no-force"]
804
- : result.path === "search"
805
- ? ["current", "force", "no-force"]
806
- : result.path === "swarm approve"
807
- ? ["yes"]
808
- : result.path === "register set"
809
- ? ["replace"]
810
- : result.path === "history remove"
811
- ? ["yes"]
812
- : result.path === "open"
813
- ? ["log", "raw", "force", "no-force"]
814
- : [];
848
+ const booleans = result.path === "setup"
849
+ ? ["yes"]
850
+ : result.path === "bundle build"
851
+ ? ["replace", "schema-only", "no-import"]
852
+ : result.path === "build"
853
+ ? ["replace", "no-import"]
854
+ : result.path === "publish"
855
+ ? ["snapshot"]
856
+ : result.path === "get"
857
+ ? ["raw", "force", "no-force"]
858
+ : result.path === "search"
859
+ ? ["current", "force", "no-force"]
860
+ : result.path === "swarm approve"
861
+ ? ["yes", "again"]
862
+ : result.path === "swarm status"
863
+ ? ["local"]
864
+ : result.path === "swarm exclude"
865
+ ? ["yes"]
866
+ : result.path === "register set"
867
+ ? ["replace"]
868
+ : result.path === "history remove"
869
+ ? ["yes"]
870
+ : result.path === "open"
871
+ ? ["log", "raw", "force", "no-force"]
872
+ : [];
815
873
  const values = result.path === "swarm create"
816
874
  ? ["service", "resume", "name", "description", "alias"]
817
- : result.path === "swarm add" || result.path === "swarm join"
875
+ : result.path === "swarm add"
818
876
  ? ["alias"]
819
- : result.path === "swarm update"
820
- ? ["name", "description"]
821
- : result.path === "swarm approve"
822
- ? ["expires-in"]
823
- : result.path === "publish"
824
- ? ["name", "expect"]
825
- : result.path === "get"
826
- ? ["output"]
827
- : result.path === "init"
828
- ? ["template"]
829
- : result.path === "bundle build" || result.path === "build"
830
- ? ["output"]
831
- : result.path === "history list"
832
- ? ["app", "status", "since", "until", "limit", "before"]
833
- : result.path === "history remove"
834
- ? ["app", "status", "since", "until"]
835
- : result.path === "pin list"
836
- ? ["type"]
837
- : [];
877
+ : result.path === "swarm request"
878
+ ? ["owner-fingerprint", "name", "alias", "output"]
879
+ : result.path === "swarm export"
880
+ ? ["output"]
881
+ : result.path === "swarm profile"
882
+ ? ["name", "address"]
883
+ : result.path === "swarm update"
884
+ ? ["name", "description"]
885
+ : result.path === "swarm approve"
886
+ ? []
887
+ : result.path === "publish"
888
+ ? ["name", "expect"]
889
+ : result.path === "get"
890
+ ? ["output"]
891
+ : result.path === "init"
892
+ ? ["template"]
893
+ : result.path === "bundle build" ||
894
+ result.path === "build"
895
+ ? ["output"]
896
+ : result.path === "history list"
897
+ ? [
898
+ "app",
899
+ "status",
900
+ "since",
901
+ "until",
902
+ "limit",
903
+ "before",
904
+ ]
905
+ : result.path === "history remove"
906
+ ? ["app", "status", "since", "until"]
907
+ : result.path === "pin list"
908
+ ? ["type"]
909
+ : [];
838
910
  while (tokens.length) {
839
911
  const value = tokens.shift();
840
- if (value.startsWith("--") || value === "-o") {
912
+ if (result.path === "swarm exclude" &&
913
+ /^--[A-Za-z0-9_-]{41}$/.test(value)) {
914
+ result.positional.push(value);
915
+ }
916
+ else if (value.startsWith("--") || value === "-o") {
841
917
  const option = value === "-o" ? "output" : value.slice(2);
842
918
  if (result.path === "init" && option === "param") {
843
919
  const input = tokens.shift();
@@ -853,7 +929,9 @@ export function parse(argv) {
853
929
  else if (values.includes(option)) {
854
930
  const input = tokens.shift();
855
931
  if (input === undefined ||
856
- input.startsWith("--") ||
932
+ (input.startsWith("--") &&
933
+ !(["resume", "owner-fingerprint"].includes(option) &&
934
+ /^[A-Za-z0-9_-]{43}$/.test(input))) ||
857
935
  (input === "" && result.path !== "swarm update"))
858
936
  syntax(`${value} needs a value.`);
859
937
  result.options[option] = input;
@@ -871,10 +949,14 @@ export function parse(argv) {
871
949
  flags.swarm !== undefined)
872
950
  syntax("--current and --swarm are mutually exclusive.");
873
951
  const counts = {
952
+ setup: [0, 0],
874
953
  "swarm create": [0, 0],
875
954
  "swarm request": [1, 1],
876
955
  "swarm approve": [1, 1],
877
- "swarm join": [1, 1],
956
+ "swarm export": [1, 1],
957
+ "swarm exclude": [1, 1],
958
+ "swarm resume": [0, 1],
959
+ "swarm profile": [0, 1],
878
960
  "swarm status": [0, 1],
879
961
  "swarm list": [0, 0],
880
962
  "swarm add": [1, 1],
@@ -967,6 +1049,17 @@ async function performCli(argv, io, env) {
967
1049
  }
968
1050
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
969
1051
  syntax("Non-interactive history remove requires --yes.");
1052
+ if (parsed.path === "setup") {
1053
+ if (!parsed.options.yes &&
1054
+ (!io.tty ||
1055
+ !(await io.confirm("Install checksum-verified Kubo and initialize/reuse the protected HOME identity? No daemon will be contacted or started."))))
1056
+ 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;
1062
+ }
970
1063
  const builtins = await builtinContent();
971
1064
  state = new State(stateLocation(parsed.flags, env).path, builtins.pins);
972
1065
  if (parsed.path === "config reset" &&
@@ -977,7 +1070,9 @@ async function performCli(argv, io, env) {
977
1070
  : "Removed legacy store.rpc configuration. Existing Kubo pins and content are unchanged.");
978
1071
  return 0;
979
1072
  }
980
- const items = effectiveConfig(state.config(), parsed.flags, env, (reference) => state.resolveSwarm(reference));
1073
+ const items = effectiveConfig(state.config({
1074
+ includeSecrets: parsed.path !== "swarm status" || Boolean(parsed.options.local),
1075
+ }), parsed.flags, env, (reference) => state.resolveSwarm(reference));
981
1076
  const value = (key) => items.find((item) => item.key === key).value;
982
1077
  const emit = (result, human) => {
983
1078
  io.out(parsed.flags.json ? JSON.stringify(result) : human);
@@ -987,12 +1082,17 @@ async function performCli(argv, io, env) {
987
1082
  ? undefined
988
1083
  : String(value("swarm.default"));
989
1084
  const swarmContext = () => ({
990
- store: store,
1085
+ get store() {
1086
+ return store;
1087
+ },
1088
+ set store(next) {
1089
+ store = next;
1090
+ },
991
1091
  state: state,
992
1092
  env,
993
1093
  stateDir: stateLocation(parsed.flags, env).path,
994
- provider: String(value("swarm.provider") ?? "http://127.0.0.1:5001"),
995
1094
  cacheTtl: Number(value("swarm.cacheTtl")),
1095
+ listen: value("swarm.listen") === "loopback" ? "loopback" : "lan",
996
1096
  forceRefresh: parsed.options.force
997
1097
  ? true
998
1098
  : parsed.options["no-force"]
@@ -1022,10 +1122,23 @@ async function performCli(argv, io, env) {
1022
1122
  switch (parsed.path) {
1023
1123
  case "swarm list": {
1024
1124
  const result = { swarms: state.swarms(), ...selection() };
1025
- emit(result, [
1026
- ...result.swarms.map((entry) => `${entry.cid === result.savedCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`),
1027
- `Saved current: ${result.savedCurrent ?? "(none)"}`,
1028
- `Effective current: ${result.effectiveCurrent ?? "(none)"} (${result.source})`,
1125
+ emit({
1126
+ ...result,
1127
+ swarms: result.swarms.map((entry) => ({
1128
+ configUrl: entry.cid,
1129
+ alias: entry.alias,
1130
+ })),
1131
+ }, [
1132
+ ...result.swarms.map((entry) => `${entry.cid === result.effectiveCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`),
1133
+ ...(result.swarms.length ? [] : ["No registered Swarms."]),
1134
+ ...(result.effectiveCurrent === null
1135
+ ? ["Use ipab swarm use <alias> to select a default Swarm."]
1136
+ : []),
1137
+ ...(result.effectiveCurrent !== result.savedCurrent
1138
+ ? [
1139
+ `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)"))}.`,
1140
+ ]
1141
+ : []),
1029
1142
  ].join("\n"));
1030
1143
  break;
1031
1144
  }
@@ -1048,16 +1161,56 @@ async function performCli(argv, io, env) {
1048
1161
  case "swarm create":
1049
1162
  case "swarm request":
1050
1163
  case "swarm approve":
1051
- case "swarm join":
1164
+ case "swarm export":
1165
+ case "swarm exclude":
1166
+ case "swarm resume":
1167
+ case "swarm profile":
1052
1168
  case "swarm status":
1053
1169
  case "publish":
1054
1170
  case "get": {
1055
1171
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1056
1172
  const context = swarmContext();
1173
+ if (parsed.path === "swarm export") {
1174
+ const id = await exportRequest(context, state.resolveSwarm(first), String(parsed.options.output ?? ""));
1175
+ emit({ id }, id);
1176
+ break;
1177
+ }
1178
+ if (["swarm exclude", "swarm resume", "swarm profile"].includes(parsed.path)) {
1179
+ const url = parsed.path === "swarm exclude"
1180
+ ? selectedSwarm
1181
+ : first
1182
+ ? state.resolveSwarm(first)
1183
+ : selectedSwarm;
1184
+ if (!url)
1185
+ syntax("Select a Swarm configuration URL or alias.");
1186
+ if (parsed.path === "swarm exclude") {
1187
+ if (!parsed.options.yes)
1188
+ syntax("Member removal is irreversible; --yes required.");
1189
+ await removeMember(context, url, first);
1190
+ }
1191
+ else if (parsed.path === "swarm resume")
1192
+ await resumeRemoval(context, url);
1193
+ else {
1194
+ const profile = await updateProfile(context, url, {
1195
+ ...(typeof parsed.options.name === "string"
1196
+ ? { name: parsed.options.name }
1197
+ : {}),
1198
+ ...(typeof parsed.options.address === "string"
1199
+ ? { addresses: [parsed.options.address] }
1200
+ : {}),
1201
+ });
1202
+ emit(profile, JSON.stringify(profile));
1203
+ store = context.store;
1204
+ break;
1205
+ }
1206
+ store = context.store;
1207
+ emit({ url, completed: true }, `Organization switch complete: ${url}`);
1208
+ break;
1209
+ }
1057
1210
  if (parsed.path === "swarm update") {
1058
1211
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1059
1212
  if (!cid)
1060
- syntax("swarm update requires a registered alias, Swarm CID or current swarm.");
1213
+ syntax("swarm update requires a registered alias, configuration URL or current swarm.");
1061
1214
  const result = await updateSwarm(context, cid, {
1062
1215
  ...(typeof parsed.options.name === "string"
1063
1216
  ? { name: parsed.options.name }
@@ -1066,16 +1219,20 @@ async function performCli(argv, io, env) {
1066
1219
  ? { description: parsed.options.description }
1067
1220
  : {}),
1068
1221
  });
1069
- emit(result, `Swarm: ${result.cid}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD: ${result.root}\nRevision: ${result.revision}`);
1222
+ emit(result, `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`);
1070
1223
  break;
1071
1224
  }
1072
1225
  if (parsed.path === "swarm add") {
1073
- const cid = exactCid(first);
1226
+ const cid = state.resolveSwarm(first);
1074
1227
  await addSwarm(context, cid, typeof parsed.options.alias === "string"
1075
1228
  ? parsed.options.alias
1076
1229
  : undefined);
1077
1230
  const entry = state.registeredSwarm(cid);
1078
- emit({ ...entry, savedCurrent: state.config()["swarm.default"] ?? null }, `Registered swarm ${entry.alias ?? cid} (${cid}).`);
1231
+ emit({
1232
+ configUrl: entry.cid,
1233
+ alias: entry.alias,
1234
+ savedCurrent: state.config()["swarm.default"] ?? null,
1235
+ }, `Registered swarm ${entry.alias ?? cid} (${cid}).`);
1079
1236
  break;
1080
1237
  }
1081
1238
  if (parsed.path === "search") {
@@ -1104,24 +1261,93 @@ async function performCli(argv, io, env) {
1104
1261
  if (parsed.path === "swarm status") {
1105
1262
  const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1106
1263
  if (!cid)
1107
- syntax("swarm status requires a Swarm CID or swarm.default.");
1108
- const data = await descriptor(store, cid);
1109
- const { head, snapshot } = await swarmHeader(context, cid, true);
1264
+ syntax("swarm status requires a configuration URL or swarm.default.");
1265
+ const local = Boolean(parsed.options.local);
1266
+ const { head, config } = local
1267
+ ? await swarmHeader(context, cid, true)
1268
+ : await sharedSwarmStatus(context, cid);
1269
+ const fingerprint = await keyId(config.owner);
1270
+ store = context.store;
1110
1271
  emit({
1111
- cid,
1112
- ...data,
1272
+ configUrl: cid,
1273
+ owner: config.owner,
1274
+ ownerFingerprint: fingerprint,
1275
+ epoch: config.epoch,
1276
+ ...(local
1277
+ ? {
1278
+ peerId: context.node.peerId,
1279
+ addresses: context.node.addresses,
1280
+ }
1281
+ : {}),
1113
1282
  root: head.root,
1114
- revision: head.revision,
1115
- properties: snapshot.properties,
1116
- }, `Swarm: ${cid}\nName: ${printable(snapshot.properties.name)}\nDescription: ${printable(snapshot.properties.description)}\nHEAD: ${head.root}\nRevision: ${head.revision}`);
1283
+ valueCid: head.cid,
1284
+ properties: {
1285
+ name: config.name,
1286
+ description: config.description,
1287
+ },
1288
+ }, [
1289
+ "Swarm",
1290
+ ` Name: ${printable(config.name)}`,
1291
+ ` Description: ${config.description ? printable(config.description) : "(none)"}`,
1292
+ " Config URL:",
1293
+ ` ${cid}`,
1294
+ "",
1295
+ "Identity",
1296
+ " Owner fingerprint:",
1297
+ ` ${fingerprint}`,
1298
+ ...(local
1299
+ ? [
1300
+ " PeerID:",
1301
+ ` ${context.node.peerId}`,
1302
+ "",
1303
+ "Local addresses",
1304
+ ...context.node.addresses.map((address) => ` ${printable(address)}`),
1305
+ ]
1306
+ : []),
1307
+ "",
1308
+ "Content",
1309
+ " HEAD (publication root):",
1310
+ ` ${head.root}`,
1311
+ " Content CID (HEAD value):",
1312
+ ` ${head.cid}`,
1313
+ ].join("\n"));
1117
1314
  break;
1118
1315
  }
1119
1316
  if (parsed.path === "get") {
1120
- const selected = await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw));
1121
- const directory = await getBundle(store, selected.cid, typeof parsed.options.output === "string"
1122
- ? parsed.options.output
1123
- : undefined);
1124
- emit({ ...selected, directory }, `CID: ${selected.cid}\nTarget CID: ${selected.targetCid}\nDirectory: ${directory}`);
1317
+ const localCid = first.startsWith("ipab://")
1318
+ ? undefined
1319
+ : state.resolve(first);
1320
+ const builtin = builtins.pins.find((pin) => pin.cid === localCid);
1321
+ const selected = builtin
1322
+ ? { cid: builtin.cid, targetCid: builtin.cid }
1323
+ : await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw));
1324
+ const contentStore = context.store;
1325
+ const source = IpfsStore.fromClient({
1326
+ block: {
1327
+ get: (key, options) => {
1328
+ options?.signal?.throwIfAborted();
1329
+ const builtin = builtins.blocks.get(CID.parse(key).toV1().toString());
1330
+ return builtin
1331
+ ? Promise.resolve(builtin.slice())
1332
+ : contentStore.block.get(key, options);
1333
+ },
1334
+ },
1335
+ }, contentStore.limits);
1336
+ let directory;
1337
+ try {
1338
+ directory = await getBundle(source, selected.cid, typeof parsed.options.output === "string"
1339
+ ? parsed.options.output
1340
+ : undefined);
1341
+ }
1342
+ finally {
1343
+ await source.close();
1344
+ }
1345
+ const closing = store;
1346
+ store = undefined;
1347
+ await closeStore(closing, undefined);
1348
+ state.close();
1349
+ state = undefined;
1350
+ emit({ ...selected, directory }, directory);
1125
1351
  break;
1126
1352
  }
1127
1353
  let cid;
@@ -1143,20 +1369,29 @@ async function performCli(argv, io, env) {
1143
1369
  });
1144
1370
  }
1145
1371
  else if (parsed.path === "swarm request")
1146
- cid = await requestMembership(context, exactCid(first));
1372
+ cid = await requestMembership(context, first, {
1373
+ ownerFingerprint: String(parsed.options["owner-fingerprint"] ?? ""),
1374
+ ...(typeof parsed.options.name === "string"
1375
+ ? { name: parsed.options.name }
1376
+ : {}),
1377
+ ...(typeof parsed.options.alias === "string"
1378
+ ? { alias: parsed.options.alias }
1379
+ : {}),
1380
+ ...(typeof parsed.options.output === "string"
1381
+ ? { output: parsed.options.output }
1382
+ : {}),
1383
+ });
1147
1384
  else if (parsed.path === "swarm approve") {
1385
+ const request = await verifiedRequest(first);
1386
+ io.err(await membershipRequestSummary(request));
1148
1387
  if (!parsed.options.yes &&
1149
1388
  (!io.tty ||
1150
- !(await io.confirm(`Approve membership request ${first}? This grants swarm HEAD read/write access.`))))
1389
+ !(await io.confirm(`Approve the verified Request ${request.id} above? This grants current HEAD and the member's profile write access; all reads are public.`))))
1151
1390
  throw new HostError("Approval requires explicit --yes or interactive confirmation.");
1152
- cid = await approveMembership(context, exactCid(first), parsed.options["expires-in"] === undefined
1153
- ? undefined
1154
- : Number(parsed.options["expires-in"]));
1391
+ cid = await approveMembership(context, request, {
1392
+ again: Boolean(parsed.options.again),
1393
+ });
1155
1394
  }
1156
- else if (parsed.path === "swarm join")
1157
- cid = await joinSwarm(context, exactCid(first), typeof parsed.options.alias === "string"
1158
- ? parsed.options.alias
1159
- : undefined);
1160
1395
  else {
1161
1396
  let content;
1162
1397
  if (first.toLowerCase().endsWith(".car"))
@@ -1174,9 +1409,14 @@ async function performCli(argv, io, env) {
1174
1409
  snapshot: Boolean(parsed.options.snapshot),
1175
1410
  });
1176
1411
  }
1177
- if (parsed.path === "swarm create" || parsed.path === "swarm join")
1412
+ store = context.store;
1413
+ if (parsed.path === "swarm create")
1178
1414
  io.err(`Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`);
1179
- emit({ cid }, cid);
1415
+ emit(parsed.path === "swarm request"
1416
+ ? { requestId: cid }
1417
+ : parsed.path === "swarm create" || parsed.path === "swarm approve"
1418
+ ? { configUrl: cid }
1419
+ : { cid }, cid);
1180
1420
  break;
1181
1421
  }
1182
1422
  case "store usage":
@@ -1309,7 +1549,7 @@ async function performCli(argv, io, env) {
1309
1549
  io.err(`Next: ipab bundle build ${JSON.stringify(result.directory)}`);
1310
1550
  }
1311
1551
  else
1312
- emit(result, `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"}`);
1552
+ emit(result, `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"}`);
1313
1553
  }
1314
1554
  catch (cause) {
1315
1555
  if (cancelled)
@@ -1346,11 +1586,12 @@ async function performCli(argv, io, env) {
1346
1586
  io.err(`Unfinished pin operations (not usable pins): ${JSON.stringify(pending)}. Retry pin add/delete.`);
1347
1587
  if (invalid.length)
1348
1588
  io.err(`Legacy non-Bundle pins (not usable pins): ${JSON.stringify(invalid)}. Retention is unchanged; delete explicitly and wrap content in a Bundle before pinning again.`);
1349
- emit({ items: listed, pending, invalid }, table(["NAME", "CID", "KIND", "BUNDLE TYPE", "SOURCE"], listed.map((pin) => [
1589
+ emit({ items: listed, pending, invalid }, table(["NAME", "CID", "KIND", "TITLE", "TYPE CID", "SOURCE"], listed.map((pin) => [
1350
1590
  pin.name,
1351
1591
  pin.cid,
1352
1592
  pin.kind,
1353
- pin.typeName,
1593
+ pin.title,
1594
+ pin.schemaCid,
1354
1595
  pin.builtin ? "built-in (read-only)" : "user",
1355
1596
  ]), "No named pins."));
1356
1597
  break;
@@ -1358,7 +1599,7 @@ async function performCli(argv, io, env) {
1358
1599
  case "pin add": {
1359
1600
  io.err("Fetching, verifying and retaining content in Store...");
1360
1601
  const result = await addPin(state, first, second, await storeConfiguration(value("store.gateway")));
1361
- emit(result, `${result.name} → ${result.cid}\nBundle type: ${printable(result.typeName)}`);
1602
+ emit(result, `${result.name} → ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}`);
1362
1603
  break;
1363
1604
  }
1364
1605
  case "pin delete": {
@@ -1371,7 +1612,7 @@ async function performCli(argv, io, env) {
1371
1612
  if (!pin)
1372
1613
  throw new HostError(`Pin "${first}" does not exist. Run ipab pin list.`);
1373
1614
  const result = pinDetails(pin);
1374
- emit(result, `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)"}`);
1615
+ emit(result, `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)"}`);
1375
1616
  break;
1376
1617
  }
1377
1618
  case "pin rename": {
@@ -1489,7 +1730,9 @@ async function performCli(argv, io, env) {
1489
1730
  throw new HostError("Execution logging requires history.enabled=true.");
1490
1731
  await recoverInactive(state);
1491
1732
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1492
- const target = (await resolveReference(swarmContext(), first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw))).cid;
1733
+ const context = swarmContext();
1734
+ const target = (await resolveReference(context, first, selectedSwarm, (reference) => state.resolve(reference), Boolean(parsed.options.raw))).cid;
1735
+ store = context.store;
1493
1736
  let appCid;
1494
1737
  let appArgv;
1495
1738
  if (parsed.path === "open") {