@ipab/cli 0.1.0-rc.1 → 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 (116) hide show
  1. package/README.md +43 -6
  2. package/dist/app-authoring.d.ts +10 -0
  3. package/dist/app-authoring.d.ts.map +1 -1
  4. package/dist/app-authoring.js +138 -13
  5. package/dist/app-authoring.js.map +1 -1
  6. package/dist/app-definition.d.ts +52 -57
  7. package/dist/app-definition.d.ts.map +1 -1
  8. package/dist/app-definition.js +33 -38
  9. package/dist/app-definition.js.map +1 -1
  10. package/dist/app-templates.d.ts.map +1 -1
  11. package/dist/app-templates.js +2 -1
  12. package/dist/app-templates.js.map +1 -1
  13. package/dist/assembly.d.ts +7 -0
  14. package/dist/assembly.d.ts.map +1 -0
  15. package/dist/assembly.js +130 -0
  16. package/dist/assembly.js.map +1 -0
  17. package/dist/authoring.d.ts +4 -8
  18. package/dist/authoring.d.ts.map +1 -1
  19. package/dist/authoring.js +25 -15
  20. package/dist/authoring.js.map +1 -1
  21. package/dist/builtins/skill.ipab.car +0 -0
  22. package/dist/builtins/template.node.car +0 -0
  23. package/dist/builtins/template.web-app.car +0 -0
  24. package/dist/builtins.d.ts.map +1 -1
  25. package/dist/builtins.js +18 -2
  26. package/dist/builtins.js.map +1 -1
  27. package/dist/cli.d.ts +1 -0
  28. package/dist/cli.d.ts.map +1 -1
  29. package/dist/cli.js +720 -76
  30. package/dist/cli.js.map +1 -1
  31. package/dist/config-secret.d.ts +3 -0
  32. package/dist/config-secret.d.ts.map +1 -0
  33. package/dist/config-secret.js +83 -0
  34. package/dist/config-secret.js.map +1 -0
  35. package/dist/config.d.ts +6 -2
  36. package/dist/config.d.ts.map +1 -1
  37. package/dist/config.js +109 -7
  38. package/dist/config.js.map +1 -1
  39. package/dist/content-provider.d.ts +9 -0
  40. package/dist/content-provider.d.ts.map +1 -0
  41. package/dist/content-provider.js +93 -0
  42. package/dist/content-provider.js.map +1 -0
  43. package/dist/get.d.ts +3 -0
  44. package/dist/get.d.ts.map +1 -0
  45. package/dist/get.js +80 -0
  46. package/dist/get.js.map +1 -0
  47. package/dist/identity.d.ts +9 -0
  48. package/dist/identity.d.ts.map +1 -0
  49. package/dist/identity.js +89 -0
  50. package/dist/identity.js.map +1 -0
  51. package/dist/kubo.d.ts +38 -0
  52. package/dist/kubo.d.ts.map +1 -0
  53. package/dist/kubo.js +528 -0
  54. package/dist/kubo.js.map +1 -0
  55. package/dist/pins.d.ts +3 -3
  56. package/dist/pins.js +1 -1
  57. package/dist/pins.js.map +1 -1
  58. package/dist/setup.d.ts +7 -0
  59. package/dist/setup.d.ts.map +1 -0
  60. package/dist/setup.js +22 -0
  61. package/dist/setup.js.map +1 -0
  62. package/dist/source-bundle.d.ts +3 -8
  63. package/dist/source-bundle.d.ts.map +1 -1
  64. package/dist/source-bundle.js +17 -12
  65. package/dist/source-bundle.js.map +1 -1
  66. package/dist/space.d.ts.map +1 -1
  67. package/dist/space.js +2 -2
  68. package/dist/space.js.map +1 -1
  69. package/dist/state.d.ts +19 -4
  70. package/dist/state.d.ts.map +1 -1
  71. package/dist/state.js +105 -7
  72. package/dist/state.js.map +1 -1
  73. package/dist/swarm-envelope.d.ts +36 -0
  74. package/dist/swarm-envelope.d.ts.map +1 -0
  75. package/dist/swarm-envelope.js +145 -0
  76. package/dist/swarm-envelope.js.map +1 -0
  77. package/dist/swarm-files.d.ts +5 -0
  78. package/dist/swarm-files.d.ts.map +1 -0
  79. package/dist/swarm-files.js +94 -0
  80. package/dist/swarm-files.js.map +1 -0
  81. package/dist/swarm.d.ts +173 -0
  82. package/dist/swarm.d.ts.map +1 -0
  83. package/dist/swarm.js +1245 -0
  84. package/dist/swarm.js.map +1 -0
  85. package/dist/template-definition.d.ts +47 -52
  86. package/dist/template-definition.d.ts.map +1 -1
  87. package/dist/template-definition.js +36 -41
  88. package/dist/template-definition.js.map +1 -1
  89. package/dist/template-source.d.ts +2 -0
  90. package/dist/template-source.d.ts.map +1 -1
  91. package/dist/template-source.js +4 -3
  92. package/dist/template-source.js.map +1 -1
  93. package/package.json +10 -5
  94. package/src/app-authoring.ts +210 -21
  95. package/src/app-definition.ts +33 -39
  96. package/src/app-templates.ts +9 -1
  97. package/src/assembly.ts +185 -0
  98. package/src/authoring.ts +41 -17
  99. package/src/builtins.ts +23 -2
  100. package/src/cli.ts +875 -79
  101. package/src/config-secret.ts +96 -0
  102. package/src/config.ts +146 -7
  103. package/src/content-provider.ts +124 -0
  104. package/src/get.ts +90 -0
  105. package/src/identity.ts +133 -0
  106. package/src/kubo.ts +691 -0
  107. package/src/pins.ts +1 -1
  108. package/src/setup.ts +21 -0
  109. package/src/source-bundle.ts +26 -13
  110. package/src/space.ts +2 -5
  111. package/src/state.ts +121 -9
  112. package/src/swarm-envelope.ts +255 -0
  113. package/src/swarm-files.ts +100 -0
  114. package/src/swarm.ts +2025 -0
  115. package/src/template-definition.ts +36 -41
  116. 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,
@@ -11,6 +11,7 @@ import {
11
11
  publicUrl,
12
12
  stateLocation,
13
13
  storeConfiguration,
14
+ visibleConfig,
14
15
  type GlobalOptions,
15
16
  } from "./config.js";
16
17
  import { HostError, message, object, syntax } from "./errors.js";
@@ -26,11 +27,34 @@ import { execute } from "./runtime.js";
26
27
  import { validatedBundle } from "./space.js";
27
28
  import { exactCid, pinName, State, type RunRecord } from "./state.js";
28
29
  import { buildBundle, inspectBundle, importBundle } from "./authoring.js";
29
- import { buildApp, initApp } from "./app-authoring.js";
30
+ import { initApp } from "./app-authoring.js";
31
+ import { assembleBundle } from "./assembly.js";
32
+ import { getBundle } from "./get.js";
33
+ import { setupDevice } from "./setup.js";
34
+ import { keyId } from "@ipab/bundle/pointer/crypto";
35
+ import {
36
+ createSwarm,
37
+ requestMembership,
38
+ approveMembership,
39
+ exportRequest,
40
+ removeMember,
41
+ resumeRemoval,
42
+ updateProfile,
43
+ verifiedRequest,
44
+ membershipRequestSummary,
45
+ swarmHeader,
46
+ addSwarm,
47
+ updateSwarm,
48
+ searchNames,
49
+ resolveReference,
50
+ publish,
51
+ type SwarmContext,
52
+ } from "./swarm.js";
30
53
  import { schemaAlias } from "./app-definition.js";
31
54
  import { addPin, deletePin, pinDetails, renamePin } from "./pins.js";
32
55
  import { logFiles } from "./logs.js";
33
56
  import { builtinContent } from "./builtins.js";
57
+ import { readSecretStream } from "./config-secret.js";
34
58
 
35
59
  export interface IO {
36
60
  out(text: string): void;
@@ -38,6 +62,7 @@ export interface IO {
38
62
  tty: boolean;
39
63
  columns?(): number | undefined;
40
64
  confirm(text: string): Promise<boolean>;
65
+ readSecret?(): Promise<string>;
41
66
  }
42
67
  export const processIO: IO = {
43
68
  out(text) {
@@ -50,6 +75,14 @@ export const processIO: IO = {
50
75
  columns() {
51
76
  return process.stdout.columns;
52
77
  },
78
+ async readSecret() {
79
+ if (process.stdin.isTTY)
80
+ syntax(
81
+ "Pipe the API key through stdin; interactive echo is not permitted.",
82
+ );
83
+ process.stdin.setEncoding("utf8");
84
+ return readSecretStream(process.stdin as AsyncIterable<string>);
85
+ },
53
86
  async confirm(text) {
54
87
  const reader = createInterface({
55
88
  input: process.stdin,
@@ -65,13 +98,35 @@ export const processIO: IO = {
65
98
  },
66
99
  };
67
100
  const commands: Record<string, string> = {
101
+ setup: "setup [--yes]",
102
+ "swarm create": "swarm create [--service URL] [--resume OPERATION]",
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]",
113
+ "swarm list": "swarm list",
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",
117
+ "swarm update":
118
+ "swarm update [URL_OR_ALIAS] [--name TEXT] [--description TEXT]",
119
+ publish:
120
+ "publish CID_OR_CAR [--name NAME [--expect OLD_NODE_CID | --snapshot]]",
121
+ get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
122
+ search: "search QUERY [--current] [--force | --no-force]",
68
123
  init: "init NAME [DIR] [OPTIONS]",
69
- build: "build [DIR] [OPTIONS]",
124
+ build: "build [SOURCE] [OPTIONS]",
70
125
  "bundle build": "bundle build SOURCE [OPTIONS]",
71
126
  "bundle inspect": "bundle inspect SOURCE",
72
127
  "bundle import": "bundle import FILE.car",
73
- exec: "exec [--log] APP [APP_ARGS...]",
74
- open: "open [--log] CONTENT",
128
+ exec: "exec [--log] [--force | --no-force] APP [APP_ARGS...]",
129
+ open: "open [--log] [--raw] [--force | --no-force] CONTENT",
75
130
  "pin add": "pin add NAME CID",
76
131
  "pin delete": "pin delete NAME",
77
132
  "pin list": "pin list [--type TYPE]",
@@ -81,7 +136,8 @@ const commands: Record<string, string> = {
81
136
  "register set": "register set SCHEMA APP [--replace] [-- TEMPLATE...]",
82
137
  "register remove": "register remove SCHEMA",
83
138
  "config get": "config get [KEY]",
84
- "config set": "config set KEY VALUE",
139
+ "config set":
140
+ "config set KEY VALUE\n ipab config set pointers.apiKey - < protected-key-file",
85
141
  "config reset": "config reset KEY",
86
142
  "store usage": "store usage",
87
143
  "store gc": "store gc",
@@ -91,6 +147,7 @@ const commands: Record<string, string> = {
91
147
  "history remove RUN_ID... [--yes]\n ipab history remove FILTERS [--yes]",
92
148
  };
93
149
  const groups: Record<string, string> = {
150
+ swarm: "Create, authorize, select and manage personal swarms",
94
151
  bundle: "Create, inspect and import content bundles",
95
152
  pin: "Retain content and manage short names",
96
153
  register: "Associate content types with Apps",
@@ -108,6 +165,193 @@ const commandHelp: Record<
108
165
  notes?: string[];
109
166
  }
110
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
+ },
180
+ "swarm create": {
181
+ summary: "Create a swarm using the account HOME identity",
182
+ options: [
183
+ "--service URL Must match the protected pointers.service origin.",
184
+ "--resume OPERATION Recover the same saved create/idempotency result.",
185
+ "--name TEXT Initial mutable swarm name.",
186
+ "--description TEXT Initial mutable description.",
187
+ "--alias ALIAS Optional local registry alias (not the shared name).",
188
+ ],
189
+ examples: [
190
+ "ipab config set pointers.service https://service.example",
191
+ "ipab config set pointers.apiKey -",
192
+ "ipab swarm create",
193
+ ],
194
+ notes: [
195
+ "Creation uses the protected, origin-bound API key and owner possession proof.",
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.",
198
+ ],
199
+ },
200
+ "swarm request": {
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
+ ],
211
+ notes: [
212
+ "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
213
+ ],
214
+ },
215
+ "swarm approve": {
216
+ summary: "Owner signs a certificate for an exact request",
217
+ options: [
218
+ "--yes Explicit approval; required outside a TTY.",
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.",
224
+ ],
225
+ },
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"],
233
+ notes: [
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",
246
+ ],
247
+ },
248
+ "swarm status": {
249
+ summary: "Authenticate the current swarm HEAD",
250
+ examples: ["ipab swarm status", "ipab swarm status work"],
251
+ notes: [
252
+ "Always authenticate and refresh HEAD; update the local header cache.",
253
+ ],
254
+ },
255
+ "swarm list": {
256
+ summary: "List local swarm registrations and the effective selection",
257
+ examples: ["ipab swarm list", "ipab --json swarm list"],
258
+ notes: ["Local only; does not verify remote membership or refresh HEAD."],
259
+ },
260
+ "swarm add": {
261
+ summary: "Authenticate and register a swarm you already have access to",
262
+ options: [
263
+ "--alias ALIAS Unique local alias; does not rename the shared swarm.",
264
+ ],
265
+ examples: ["ipab swarm add CONFIG_URL --alias work"],
266
+ notes: [
267
+ "Not a membership grant. The first registration becomes the saved default only if none exists.",
268
+ ],
269
+ },
270
+ "swarm use": {
271
+ summary: "Save a registered swarm as the current default",
272
+ examples: ["ipab swarm use work"],
273
+ notes: ["Local only. --swarm still overrides the saved default."],
274
+ },
275
+ "swarm remove": {
276
+ summary: "Forget a local registration without revoking membership",
277
+ examples: ["ipab swarm remove work"],
278
+ notes: [
279
+ "Preserves credentials, content and remote membership. Clears a matching saved default without selecting a replacement.",
280
+ ],
281
+ },
282
+ "swarm update": {
283
+ summary: "Owner updates public organization information",
284
+ arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
285
+ options: [
286
+ "--name TEXT Replace the shared display name; empty text clears it.",
287
+ "--description TEXT Replace the shared description; empty text clears it.",
288
+ ],
289
+ examples: [
290
+ 'ipab swarm update work --name "Team" --description "Shared workspace"',
291
+ 'ipab swarm update --description ""',
292
+ ],
293
+ notes: [
294
+ "Requires at least one field. Members can change only their own profile.",
295
+ "Content-CID CAS prevents overwriting concurrent organization changes.",
296
+ "Shared name changes do not rename local registry aliases.",
297
+ ],
298
+ },
299
+ search: {
300
+ summary: "Search formal Names across registered swarms",
301
+ arguments: [
302
+ "QUERY Case-insensitive literal name substring, 1..256 characters.",
303
+ ],
304
+ options: [
305
+ "--current Search only the effective current swarm; conflicts with --swarm.",
306
+ "--force Refresh HEAD for every swarm in the search scope.",
307
+ "--no-force Override swarm.forceRefresh and use valid cached headers.",
308
+ ],
309
+ examples: ["ipab search hello", "ipab --swarm work search hello --force"],
310
+ notes: [
311
+ "Searches all registered swarms unless --current or --swarm selects one.",
312
+ "Valid caches use local Names only; absent/expired caches refresh. No payload downloads.",
313
+ "No matches is success, not a reason to refresh valid caches. Any failed swarm fails the whole search.",
314
+ ],
315
+ },
316
+ publish: {
317
+ summary: "Provide built content and explicitly publish a Name",
318
+ options: [
319
+ "--name NAME New formal Name; occupied Names fail.",
320
+ "--expect CID Exact old Artifact node, required for iteration.",
321
+ "--snapshot Name ordinary content without an Artifact; initial only.",
322
+ ],
323
+ examples: [
324
+ "ipab publish app.car --name apps/hello",
325
+ "ipab publish APP_CID --name apps/hello --expect OLD_NODE_CID",
326
+ "ipab publish CONTENT_CID",
327
+ ],
328
+ notes: [
329
+ "No build, edit, install or execution. CID-only stdout.",
330
+ "Different-name CAS contention is rebased; same-name edits conflict (exit 3).",
331
+ "Kubo pin confirmation precedes HEAD; it does not prove a remote device is online.",
332
+ ],
333
+ },
334
+ get: {
335
+ summary: "Verify and unpack Bundle content without executing it",
336
+ options: [
337
+ "--raw Select the Artifact node instead of its value.",
338
+ "--force Refresh the shared Name's swarm HEAD.",
339
+ "--no-force Override swarm.forceRefresh and use valid cached headers.",
340
+ "-o, --output DIRECTORY New or empty directory; defaults to a unique temporary directory.",
341
+ ],
342
+ examples: [
343
+ "ipab --json get ipab:///apps/hello -o hello-app",
344
+ "ipab get ipab://work/apps/hello -o hello-app",
345
+ "ipab get CONTENT_CID",
346
+ "ipab get --raw RELEASE_CID",
347
+ ],
348
+ notes: [
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.",
352
+ "Does not install, build, edit, or automatically retrieve associated source.",
353
+ ],
354
+ },
111
355
  "store usage": {
112
356
  summary: "Query cached and recursively pinned block bytes",
113
357
  examples: ["ipab store usage", "ipab --json store usage"],
@@ -140,21 +384,24 @@ const commandHelp: Record<
140
384
  notes: ["Does not install dependencies or execute template code."],
141
385
  },
142
386
  build: {
143
- summary: "Build an App CAR from a project",
144
- arguments: ["DIR Project directory (default: current directory)."],
387
+ summary: "Assemble any Bundle using ipab.build.yaml (no compilation)",
388
+ arguments: [
389
+ "SOURCE Recipe file or Bundle directory (default: current directory).",
390
+ ],
145
391
  options: [
146
- "-o, --output FILE Destination (default: dist/app.car).",
392
+ "-o, --output FILE Destination (default: dist/bundle.car).",
147
393
  "--replace Allow replacing existing regular artifacts.",
148
- "--no-import Write CAR files without importing the App into Store.",
149
- "--with-source Include a separate source CAR (default: enabled).",
150
- "--without-source Omit source CAR; conflicts with --with-source.",
394
+ "--no-import Write the CAR without importing the Bundle into Store.",
395
+ ],
396
+ examples: [
397
+ "ipab build prepared-app",
398
+ "ipab build ipab.build.yaml --replace",
151
399
  ],
152
- examples: ["ipab build", "ipab build hello --replace --without-source"],
153
400
  notes: [
154
- "Uses local tsc and bundles Node CommonJS; ipab.yaml configures the build.",
155
- "Explicit ipab-prebuild strategy executes trusted project code.",
156
- "Source follows project .gitignore rules; review private files before sharing.",
157
- "Imports only the App, without pinning; source needs separate import/retention.",
401
+ "Recipe explicitly maps source files and exact CID imports to target paths.",
402
+ "Instance paths come from .bundle.yaml; the referenced file defines the type. Imported DAG identities are preserved.",
403
+ "Legacy App ipab.yaml is rejected; use project preparation tools separately.",
404
+ "Select explicit files; review private files before providing Bundles.",
158
405
  "Store failures preserve the CAR; retry with ipab bundle import FILE.car.",
159
406
  ],
160
407
  },
@@ -169,7 +416,7 @@ const commandHelp: Record<
169
416
  ],
170
417
  examples: [
171
418
  "ipab bundle build note",
172
- "ipab bundle build types\\.bundle.yaml --schema-only",
419
+ "ipab bundle build types\\.bundle-type.yaml --schema-only",
173
420
  ],
174
421
  notes: [
175
422
  "Imports into the configured Store without pinning or executing Apps.",
@@ -192,20 +439,23 @@ const commandHelp: Record<
192
439
  ],
193
440
  },
194
441
  exec: {
195
- summary: "Run an App by CID or named pin",
442
+ summary: "Run an App by CID, named pin or IPAB URI",
196
443
  arguments: [
197
444
  "APP_ARGS Everything after APP is passed verbatim, including --help.",
198
445
  ],
199
446
  options: [
200
447
  "--log Record stdout/stderr; must precede APP. Requires history enabled.",
448
+ "--force Refresh the shared Name's swarm HEAD; must precede APP.",
449
+ "--no-force Override swarm.forceRefresh; must precede APP.",
201
450
  ],
202
451
  examples: [
203
452
  "ipab exec reader",
204
- "ipab exec reader --help",
205
453
  "ipab exec --log reader",
454
+ "ipab exec ipab://work/apps/hello --help",
206
455
  ],
207
456
  notes: [
208
457
  "Apps are NOT sandboxed; run only Apps you trust.",
458
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
209
459
  "History stores argv by default; do not put secrets in arguments.",
210
460
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
211
461
  "--json is not supported; App stdio is passed through.",
@@ -213,11 +463,21 @@ const commandHelp: Record<
213
463
  },
214
464
  open: {
215
465
  summary: "Open content with its registered App",
216
- arguments: ["CONTENT Bundle CID or named pin."],
217
- options: ["--log Record stdout/stderr; requires history enabled."],
218
- examples: ["ipab open CONTENT_CID", "ipab open --log my-note"],
466
+ arguments: ["CONTENT Bundle CID, named pin or IPAB URI."],
467
+ options: [
468
+ "--log Record stdout/stderr; requires history enabled.",
469
+ "--raw Open the Artifact node rather than its value.",
470
+ "--force Refresh the shared Name's swarm HEAD.",
471
+ "--no-force Override swarm.forceRefresh and use valid cached headers.",
472
+ ],
473
+ examples: [
474
+ "ipab open CONTENT_CID",
475
+ "ipab open --log my-note",
476
+ "ipab open ipab:///documents/readme",
477
+ ],
219
478
  notes: [
220
479
  "Requires a saved registration and App support for the exact content type.",
480
+ "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
221
481
  "Apps are NOT sandboxed; run only Apps you trust.",
222
482
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
223
483
  "--json is not supported; App stdio is passed through.",
@@ -306,11 +566,15 @@ const commandHelp: Record<
306
566
  "config set": {
307
567
  summary: "Save a local configuration value",
308
568
  examples: [
569
+ "ipab config set pointers.apiKey -",
309
570
  "ipab config set store.gateway http://127.0.0.1:8080",
310
571
  "ipab config set history.enabled false",
311
572
  ],
312
573
  notes: [
313
574
  "store.gateway is a read-only HTTP gateway; blocks, pins and GC remain local.",
575
+ "pointers.service is a canonical HTTPS origin (HTTP loopback allowed).",
576
+ "pointers.apiKey is accepted only through stdin using VALUE '-'; queries and confirmations redact it.",
577
+ "Saving pointers.apiKey protects state SQLite files with account-only Unix modes or Windows ACLs.",
314
578
  ],
315
579
  },
316
580
  "config reset": {
@@ -363,6 +627,7 @@ const commandHelp: Record<
363
627
 
364
628
  export function help(path = ""): string {
365
629
  const globalOptions = `Global options (before COMMAND):
630
+ --swarm URL|ALIAS Select shared swarm (otherwise swarm.default; URI swarm takes precedence)
366
631
  --state-dir PATH Set the local state directory
367
632
  --store-gateway URL Use a read-only upstream HTTP gateway
368
633
  --json Output management/development metadata, not App stdio`;
@@ -383,6 +648,11 @@ Create:
383
648
  bundle ${groups.bundle}
384
649
 
385
650
  Manage:
651
+ setup ${commandHelp.setup!.summary}
652
+ swarm ${groups.swarm}
653
+ search Search formal Names across registered swarms
654
+ publish ${commandHelp.publish!.summary}
655
+ get ${commandHelp.get!.summary}
386
656
  pin ${groups.pin}
387
657
  register ${groups.register}
388
658
  config ${groups.config}
@@ -586,10 +856,15 @@ export function parse(argv: readonly string[]): Parsed {
586
856
  syntax(
587
857
  "Store RPC is no longer supported. Use --store-gateway with an HTTP gateway URL; existing Kubo pins are not migrated.",
588
858
  );
589
- else if (flag === "--state-dir" || flag === "--store-gateway") {
859
+ else if (
860
+ flag === "--state-dir" ||
861
+ flag === "--store-gateway" ||
862
+ flag === "--swarm"
863
+ ) {
590
864
  const value = tokens.shift();
591
865
  if (!value || value.startsWith("-")) syntax(`${flag} needs a value.`);
592
866
  if (flag === "--state-dir") flags.stateDir = value;
867
+ else if (flag === "--swarm") flags.swarm = value;
593
868
  else {
594
869
  flags.storeGateway = publicUrl(value);
595
870
  }
@@ -607,10 +882,14 @@ export function parse(argv: readonly string[]): Parsed {
607
882
  if (!group) return result;
608
883
  if (group === "exec") {
609
884
  if (flags.json) syntax("--json is not supported for exec/open.");
610
- if (tokens[0] === "--log") {
611
- result.options.log = true;
612
- tokens.shift();
885
+ while (["--log", "--force", "--no-force"].includes(tokens[0] ?? "")) {
886
+ const option = tokens.shift()!.slice(2);
887
+ if (Object.hasOwn(result.options, option))
888
+ syntax(`Duplicate option --${option}.`);
889
+ result.options[option] = true;
613
890
  }
891
+ if (result.options.force && result.options["no-force"])
892
+ syntax("--force and --no-force are mutually exclusive.");
614
893
  if (tokens[0] === "-h" || tokens[0] === "--help") {
615
894
  result.help = true;
616
895
  return result;
@@ -620,11 +899,21 @@ export function parse(argv: readonly string[]): Parsed {
620
899
  result.positional = tokens;
621
900
  return result;
622
901
  }
623
- if (!["open", "init", "build"].includes(group)) {
902
+ if (
903
+ !["open", "init", "build", "publish", "get", "search", "setup"].includes(
904
+ group,
905
+ )
906
+ ) {
624
907
  if (
625
- !["bundle", "pin", "register", "config", "history", "store"].includes(
626
- group,
627
- )
908
+ ![
909
+ "bundle",
910
+ "pin",
911
+ "register",
912
+ "config",
913
+ "history",
914
+ "store",
915
+ "swarm",
916
+ ].includes(group)
628
917
  )
629
918
  syntax(`Unknown command "${group}".`);
630
919
  if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
@@ -642,33 +931,84 @@ export function parse(argv: readonly string[]): Parsed {
642
931
  result.help = true;
643
932
  return result;
644
933
  }
934
+ if (
935
+ result.path === "config set" &&
936
+ tokens.includes("pointers.apiKey") &&
937
+ !(tokens.length === 2 && tokens[1] === "-")
938
+ )
939
+ syntax(
940
+ "API key must be provided through '-' and piped stdin; never pass it in command arguments.",
941
+ );
645
942
  const booleans =
646
- result.path === "bundle build"
647
- ? ["replace", "schema-only", "no-import"]
648
- : result.path === "build"
649
- ? ["replace", "no-import", "with-source", "without-source"]
650
- : result.path === "register set"
651
- ? ["replace"]
652
- : result.path === "history remove"
653
- ? ["yes"]
654
- : result.path === "open"
655
- ? ["log"]
656
- : [];
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"
958
+ ? ["yes"]
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
+ : [];
657
966
  const values =
658
- result.path === "init"
659
- ? ["template"]
660
- : result.path === "bundle build" || result.path === "build"
661
- ? ["output"]
662
- : result.path === "history list"
663
- ? ["app", "status", "since", "until", "limit", "before"]
664
- : result.path === "history remove"
665
- ? ["app", "status", "since", "until"]
666
- : result.path === "pin list"
667
- ? ["type"]
668
- : [];
967
+ result.path === "swarm create"
968
+ ? ["service", "resume", "name", "description", "alias"]
969
+ : result.path === "swarm add"
970
+ ? ["alias"]
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
+ : [];
669
1004
  while (tokens.length) {
670
1005
  const value = tokens.shift()!;
671
- 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") {
672
1012
  const option = value === "-o" ? "output" : value.slice(2);
673
1013
  if (result.path === "init" && option === "param") {
674
1014
  const input = tokens.shift();
@@ -682,12 +1022,46 @@ export function parse(argv: readonly string[]): Parsed {
682
1022
  if (booleans.includes(option)) result.options[option] = true;
683
1023
  else if (values.includes(option)) {
684
1024
  const input = tokens.shift();
685
- if (!input || input.startsWith("--")) syntax(`${value} needs a value.`);
1025
+ if (
1026
+ input === undefined ||
1027
+ (input.startsWith("--") &&
1028
+ !(
1029
+ ["resume", "owner-fingerprint"].includes(option) &&
1030
+ /^[A-Za-z0-9_-]{43}$/.test(input)
1031
+ )) ||
1032
+ (input === "" && result.path !== "swarm update")
1033
+ )
1034
+ syntax(`${value} needs a value.`);
686
1035
  result.options[option] = input;
687
1036
  } else syntax(`Unknown option "${value}".`);
688
1037
  } else result.positional.push(value);
689
1038
  }
1039
+ if (result.options.force && result.options["no-force"])
1040
+ syntax("--force and --no-force are mutually exclusive.");
1041
+ if (
1042
+ result.path === "search" &&
1043
+ result.options.current &&
1044
+ flags.swarm !== undefined
1045
+ )
1046
+ syntax("--current and --swarm are mutually exclusive.");
690
1047
  const counts: Record<string, [number, number]> = {
1048
+ setup: [0, 0],
1049
+ "swarm create": [0, 0],
1050
+ "swarm request": [1, 1],
1051
+ "swarm approve": [1, 1],
1052
+ "swarm export": [1, 1],
1053
+ "swarm exclude": [1, 1],
1054
+ "swarm resume": [0, 1],
1055
+ "swarm profile": [0, 1],
1056
+ "swarm status": [0, 1],
1057
+ "swarm list": [0, 0],
1058
+ "swarm add": [1, 1],
1059
+ "swarm use": [1, 1],
1060
+ "swarm remove": [1, 1],
1061
+ "swarm update": [0, 1],
1062
+ publish: [1, 1],
1063
+ get: [1, 1],
1064
+ search: [1, 1],
691
1065
  init: [1, 2],
692
1066
  build: [0, 1],
693
1067
  "bundle build": [1, 1],
@@ -743,8 +1117,15 @@ export function parse(argv: readonly string[]): Parsed {
743
1117
  !(result.path === "config reset" && result.positional[0] === "store.rpc")
744
1118
  )
745
1119
  configKey(result.positional[0]);
746
- if (result.path === "config set")
747
- parseValue(configKey(result.positional[0]), result.positional[1], true);
1120
+ if (result.path === "config set") {
1121
+ if (result.positional[0] === "pointers.apiKey") {
1122
+ if (result.positional[1] !== "-")
1123
+ syntax(
1124
+ "Set pointers.apiKey using '-' and piped stdin; never put the key in command-line arguments.",
1125
+ );
1126
+ } else
1127
+ parseValue(configKey(result.positional[0]), result.positional[1], true);
1128
+ }
748
1129
  }
749
1130
  if (typeof result.options.limit === "string")
750
1131
  parseValue("history.limit", result.options.limit, true);
@@ -781,6 +1162,28 @@ async function performCli(
781
1162
  }
782
1163
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
783
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
+ }
784
1187
  const builtins = await builtinContent();
785
1188
  state = new State(stateLocation(parsed.flags, env).path, builtins.pins);
786
1189
  if (
@@ -795,17 +1198,397 @@ async function performCli(
795
1198
  );
796
1199
  return 0;
797
1200
  }
798
- const items = effectiveConfig(state.config(), parsed.flags, env);
1201
+ const items = effectiveConfig(
1202
+ state.config(),
1203
+ parsed.flags,
1204
+ env,
1205
+ (reference) => state!.resolveSwarm(reference),
1206
+ );
799
1207
  const value = (key: string) =>
800
1208
  items.find((item) => item.key === key)!.value;
801
1209
  const emit = (result: unknown, human: string) => {
802
1210
  io.out(parsed.flags.json ? JSON.stringify(result) : human);
803
1211
  };
804
1212
  const [first, second] = parsed.positional;
1213
+ const selectedSwarm =
1214
+ value("swarm.default") === null
1215
+ ? undefined
1216
+ : String(value("swarm.default"));
1217
+ const swarmContext = (): SwarmContext => ({
1218
+ get store() {
1219
+ return store!;
1220
+ },
1221
+ set store(next) {
1222
+ store = next;
1223
+ },
1224
+ state: state!,
1225
+ env,
1226
+ stateDir: stateLocation(parsed.flags, env).path,
1227
+ cacheTtl: Number(value("swarm.cacheTtl")),
1228
+ forceRefresh: parsed.options.force
1229
+ ? true
1230
+ : parsed.options["no-force"]
1231
+ ? false
1232
+ : Boolean(value("swarm.forceRefresh")),
1233
+ diagnostic: (text) => {
1234
+ io.err(text);
1235
+ },
1236
+ ...(typeof value("pointers.service") === "string"
1237
+ ? { pointerService: String(value("pointers.service")) }
1238
+ : {}),
1239
+ ...(typeof value("pointers.apiKey") === "string"
1240
+ ? { pointerApiKey: String(value("pointers.apiKey")) }
1241
+ : {}),
1242
+ });
805
1243
  const filter = parsed.path.startsWith("history ")
806
1244
  ? filters(state, parsed.options)
807
1245
  : {};
1246
+ const selection = () => {
1247
+ const current = effectiveConfig(
1248
+ state!.config(),
1249
+ parsed.flags,
1250
+ env,
1251
+ (reference) => state!.resolveSwarm(reference),
1252
+ ).find((item) => item.key === "swarm.default")!;
1253
+ return {
1254
+ savedCurrent: state!.config()["swarm.default"] ?? null,
1255
+ effectiveCurrent: current.value,
1256
+ source: current.source,
1257
+ };
1258
+ };
808
1259
  switch (parsed.path) {
1260
+ case "swarm list": {
1261
+ const result = { swarms: state.swarms(), ...selection() };
1262
+ emit(
1263
+ {
1264
+ ...result,
1265
+ swarms: result.swarms.map((entry) => ({
1266
+ configUrl: entry.cid,
1267
+ alias: entry.alias,
1268
+ })),
1269
+ },
1270
+ [
1271
+ ...result.swarms.map(
1272
+ (entry) =>
1273
+ `${entry.cid === result.savedCurrent ? "*" : " "} ${printable(entry.alias ?? entry.cid)} ${entry.cid}`,
1274
+ ),
1275
+ `Saved current: ${result.savedCurrent ?? "(none)"}`,
1276
+ `Effective current: ${result.effectiveCurrent ?? "(none)"} (${result.source})`,
1277
+ ].join("\n"),
1278
+ );
1279
+ break;
1280
+ }
1281
+ case "swarm use": {
1282
+ state.useSwarm(first!);
1283
+ const result = selection();
1284
+ emit(result, `Saved current swarm: ${result.savedCurrent}`);
1285
+ if (result.source === "flag" || result.source === "env")
1286
+ io.err(
1287
+ `The saved default is overridden by ${result.source}: ${result.effectiveCurrent}.`,
1288
+ );
1289
+ break;
1290
+ }
1291
+ case "swarm remove": {
1292
+ const removed = state.removeSwarm(first!);
1293
+ emit(
1294
+ { removed, savedCurrent: state.config()["swarm.default"] ?? null },
1295
+ `Removed registration ${removed}. Credentials, content and remote membership are unchanged.`,
1296
+ );
1297
+ break;
1298
+ }
1299
+ case "swarm add":
1300
+ case "swarm update":
1301
+ case "search":
1302
+ case "swarm create":
1303
+ case "swarm request":
1304
+ case "swarm approve":
1305
+ case "swarm export":
1306
+ case "swarm exclude":
1307
+ case "swarm resume":
1308
+ case "swarm profile":
1309
+ case "swarm status":
1310
+ case "publish":
1311
+ case "get": {
1312
+ store = new IpfsStore(await storeConfiguration(value("store.gateway")));
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
+ }
1361
+ if (parsed.path === "swarm update") {
1362
+ const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1363
+ if (!cid)
1364
+ syntax(
1365
+ "swarm update requires a registered alias, configuration URL or current swarm.",
1366
+ );
1367
+ const result = await updateSwarm(context, cid, {
1368
+ ...(typeof parsed.options.name === "string"
1369
+ ? { name: parsed.options.name }
1370
+ : {}),
1371
+ ...(typeof parsed.options.description === "string"
1372
+ ? { description: parsed.options.description }
1373
+ : {}),
1374
+ });
1375
+ emit(
1376
+ result,
1377
+ `Swarm: ${result.configUrl}\nName: ${printable(result.properties.name)}\nDescription: ${printable(result.properties.description)}\nHEAD ID: ${result.headId}\nConfig content CID: ${result.valueCid}`,
1378
+ );
1379
+ break;
1380
+ }
1381
+ if (parsed.path === "swarm add") {
1382
+ const cid = state.resolveSwarm(first!);
1383
+ await addSwarm(
1384
+ context,
1385
+ cid,
1386
+ typeof parsed.options.alias === "string"
1387
+ ? parsed.options.alias
1388
+ : undefined,
1389
+ );
1390
+ const entry = state.registeredSwarm(cid);
1391
+ emit(
1392
+ {
1393
+ configUrl: entry.cid,
1394
+ alias: entry.alias,
1395
+ savedCurrent: state.config()["swarm.default"] ?? null,
1396
+ },
1397
+ `Registered swarm ${entry.alias ?? cid} (${cid}).`,
1398
+ );
1399
+ break;
1400
+ }
1401
+ if (parsed.path === "search") {
1402
+ const source = items.find(
1403
+ (item) => item.key === "swarm.default",
1404
+ )!.source;
1405
+ const limited = parsed.options.current || source === "flag";
1406
+ if (limited && !selectedSwarm)
1407
+ syntax(
1408
+ "Search of the current swarm requires --swarm or swarm.default.",
1409
+ );
1410
+ const registrations = state.swarms();
1411
+ const scope = limited
1412
+ ? [
1413
+ {
1414
+ cid: selectedSwarm!,
1415
+ alias:
1416
+ registrations.find((entry) => entry.cid === selectedSwarm)
1417
+ ?.alias ?? null,
1418
+ },
1419
+ ]
1420
+ : registrations;
1421
+ const result = await searchNames(context, first!, scope);
1422
+ emit(
1423
+ result,
1424
+ result.matches.length
1425
+ ? result.matches
1426
+ .map(
1427
+ (match) =>
1428
+ `${printable(match.alias ?? match.swarm)} ${printable(match.name)} ${match.targetCid}\n ipab get ${printable(match.reference)}`,
1429
+ )
1430
+ .join("\n")
1431
+ : "No matching Names.",
1432
+ );
1433
+ break;
1434
+ }
1435
+ if (parsed.path === "swarm status") {
1436
+ const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1437
+ if (!cid)
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;
1443
+ emit(
1444
+ {
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,
1451
+ root: head.root,
1452
+ valueCid: head.cid,
1453
+ properties: {
1454
+ name: config.name,
1455
+ description: config.description,
1456
+ },
1457
+ },
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}`,
1459
+ );
1460
+ break;
1461
+ }
1462
+ if (parsed.path === "get") {
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,
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);
1511
+ break;
1512
+ }
1513
+ let cid: string;
1514
+ if (parsed.path === "swarm create") {
1515
+ cid = await createSwarm(context, {
1516
+ ...(typeof parsed.options.service === "string"
1517
+ ? { service: parsed.options.service }
1518
+ : {}),
1519
+ ...(typeof parsed.options.resume === "string"
1520
+ ? { resume: parsed.options.resume }
1521
+ : {}),
1522
+ properties: {
1523
+ name: String(parsed.options.name ?? ""),
1524
+ description: String(parsed.options.description ?? ""),
1525
+ },
1526
+ ...(typeof parsed.options.alias === "string"
1527
+ ? { alias: parsed.options.alias }
1528
+ : {}),
1529
+ });
1530
+ } else if (parsed.path === "swarm request")
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
+ });
1543
+ else if (parsed.path === "swarm approve") {
1544
+ const request = await verifiedRequest(first!);
1545
+ io.err(await membershipRequestSummary(request));
1546
+ if (
1547
+ !parsed.options.yes &&
1548
+ (!io.tty ||
1549
+ !(await io.confirm(
1550
+ `Approve the verified Request ${request.id} above? This grants current HEAD and the member's profile write access; all reads are public.`,
1551
+ )))
1552
+ )
1553
+ throw new HostError(
1554
+ "Approval requires explicit --yes or interactive confirmation.",
1555
+ );
1556
+ cid = await approveMembership(context, request, {
1557
+ again: Boolean(parsed.options.again),
1558
+ });
1559
+ } else {
1560
+ let content: string;
1561
+ if (first!.toLowerCase().endsWith(".car"))
1562
+ content = (
1563
+ await importBundle(first!, () => Promise.resolve(store!))
1564
+ ).cid;
1565
+ else content = exactCid(first!);
1566
+ cid = await publish(context, content, {
1567
+ ...(selectedSwarm ? { swarm: selectedSwarm } : {}),
1568
+ ...(typeof parsed.options.name === "string"
1569
+ ? { name: parsed.options.name }
1570
+ : {}),
1571
+ ...(typeof parsed.options.expect === "string"
1572
+ ? { expect: parsed.options.expect }
1573
+ : {}),
1574
+ snapshot: Boolean(parsed.options.snapshot),
1575
+ });
1576
+ }
1577
+ store = context.store;
1578
+ if (parsed.path === "swarm create")
1579
+ io.err(
1580
+ `Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config()["swarm.default"] ?? "(none)"}.`,
1581
+ );
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
+ );
1590
+ break;
1591
+ }
809
1592
  case "store usage":
810
1593
  case "store gc": {
811
1594
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
@@ -872,7 +1655,7 @@ async function performCli(
872
1655
  if (parsed.path === "bundle build" || parsed.path === "build")
873
1656
  io.err(
874
1657
  parsed.path === "build"
875
- ? "Typechecking, bundling and building App..."
1658
+ ? "Assembling and validating Bundle (no compilation)..."
876
1659
  : "Validating and building bundle...",
877
1660
  );
878
1661
  if (parsed.path === "bundle import")
@@ -895,14 +1678,9 @@ async function performCli(
895
1678
  : {}),
896
1679
  })
897
1680
  : parsed.path === "build"
898
- ? await buildApp(first, {
1681
+ ? await assembleBundle(first, {
899
1682
  ...request,
900
1683
  replace: Boolean(parsed.options.replace),
901
- ...(parsed.options["with-source"]
902
- ? { includeSource: true }
903
- : parsed.options["without-source"]
904
- ? { includeSource: false }
905
- : {}),
906
1684
  ...(typeof parsed.options.output === "string"
907
1685
  ? { output: parsed.options.output }
908
1686
  : {}),
@@ -944,7 +1722,7 @@ async function performCli(
944
1722
  if ("output" in result)
945
1723
  emit(
946
1724
  { ...result, imported: importing },
947
- `CID: ${result.cid}\nSchema CID: ${result.schemaCid}\nCAR: ${result.output}${result.validation !== undefined ? `\nEntry validation: ${result.validation?.status ?? "not-applicable"}` : ""}${"source" in result ? `\nSource CID: ${result.source.cid}\nSource CAR: ${result.source.output} (not imported or pinned)` : ""}\nStore: ${importing ? "imported (not pinned)" : "not imported (--no-import)"}`,
1725
+ `CID: ${result.cid}\nSchema CID: ${result.schemaCid}\nCAR: ${result.output}${result.validation !== undefined ? `\nEntry validation: ${result.validation?.status ?? "not-applicable"}` : ""}\nStore: ${importing ? "imported (not pinned)" : "not imported (--no-import)"}`,
948
1726
  );
949
1727
  else if (result.kind === "bundle-import")
950
1728
  emit(
@@ -962,7 +1740,7 @@ async function performCli(
962
1740
  result.files.includes("ipab.json"))
963
1741
  )
964
1742
  io.err(
965
- `Next: install declared dependencies in ${JSON.stringify(result.directory)}; then ipab build ${JSON.stringify(result.directory)} (requires locally linked ipab).`,
1743
+ `Next: install declared dependencies and explicitly link the candidate @ipab/cli as a project dependency in ${JSON.stringify(result.directory)}; run pnpm build to prepare and package the App. Root ipab build does not compile.`,
966
1744
  );
967
1745
  else if (result.files.includes(".bundle.yaml"))
968
1746
  io.err(
@@ -971,7 +1749,7 @@ async function performCli(
971
1749
  } else
972
1750
  emit(
973
1751
  result,
974
- `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"}`,
975
1753
  );
976
1754
  } catch (cause) {
977
1755
  if (cancelled)
@@ -1025,12 +1803,13 @@ async function performCli(
1025
1803
  emit(
1026
1804
  { items: listed, pending, invalid },
1027
1805
  table(
1028
- ["NAME", "CID", "KIND", "BUNDLE TYPE", "SOURCE"],
1806
+ ["NAME", "CID", "KIND", "TITLE", "TYPE CID", "SOURCE"],
1029
1807
  listed.map((pin) => [
1030
1808
  pin.name,
1031
1809
  pin.cid,
1032
1810
  pin.kind,
1033
- pin.typeName,
1811
+ pin.title,
1812
+ pin.schemaCid,
1034
1813
  pin.builtin ? "built-in (read-only)" : "user",
1035
1814
  ]),
1036
1815
  "No named pins.",
@@ -1048,7 +1827,7 @@ async function performCli(
1048
1827
  );
1049
1828
  emit(
1050
1829
  result,
1051
- `${result.name} → ${result.cid}\nBundle type: ${printable(result.typeName)}`,
1830
+ `${result.name} → ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}`,
1052
1831
  );
1053
1832
  break;
1054
1833
  }
@@ -1069,7 +1848,7 @@ async function performCli(
1069
1848
  const result = pinDetails(pin);
1070
1849
  emit(
1071
1850
  result,
1072
- `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)"}`,
1073
1852
  );
1074
1853
  break;
1075
1854
  }
@@ -1113,9 +1892,9 @@ async function performCli(
1113
1892
  break;
1114
1893
  }
1115
1894
  case "config get": {
1116
- const selected = first
1117
- ? items.filter((item) => item.key === first)
1118
- : items;
1895
+ const selected = (
1896
+ first ? items.filter((item) => item.key === first) : items
1897
+ ).map(visibleConfig);
1119
1898
  emit(
1120
1899
  { items: selected },
1121
1900
  table(
@@ -1128,14 +1907,21 @@ async function performCli(
1128
1907
  }
1129
1908
  case "config set": {
1130
1909
  const key = configKey(first!);
1131
- const saved = parseValue(key, second, true);
1910
+ const saved = parseValue(
1911
+ key,
1912
+ key === "pointers.apiKey"
1913
+ ? await (io.readSecret ?? processIO.readSecret!)()
1914
+ : second,
1915
+ true,
1916
+ );
1132
1917
  state.setConfig(key, saved);
1133
1918
  const source = items.find((item) => item.key === key)!.source;
1134
1919
  if (source === "env" || source === "flag")
1135
1920
  io.err(`Warning: saved user value is masked by ${source}.`);
1921
+ const display = visibleConfig({ key, value: saved, source: "user" });
1136
1922
  emit(
1137
- { key, value: saved, source: "user" },
1138
- `Saved ${key} = ${printable(String(saved))} (user).`,
1923
+ display,
1924
+ `Saved ${key} = ${printable(String(display.value))} (user).`,
1139
1925
  );
1140
1926
  break;
1141
1927
  }
@@ -1234,9 +2020,19 @@ async function performCli(
1234
2020
  throw new HostError(
1235
2021
  "Execution logging requires history.enabled=true.",
1236
2022
  );
1237
- const target = state.resolve(first!);
1238
2023
  await recoverInactive(state);
1239
2024
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
2025
+ const context = swarmContext();
2026
+ const target = (
2027
+ await resolveReference(
2028
+ context,
2029
+ first!,
2030
+ selectedSwarm,
2031
+ (reference) => state!.resolve(reference),
2032
+ Boolean(parsed.options.raw),
2033
+ )
2034
+ ).cid;
2035
+ store = context.store;
1240
2036
  let appCid: string;
1241
2037
  let appArgv: string[];
1242
2038
  if (parsed.path === "open") {