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

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 (94) hide show
  1. package/README.md +82 -15
  2. package/dist/app-templates.js +1 -1
  3. package/dist/app-templates.js.map +1 -1
  4. package/dist/builtins/skill.ipab.car +0 -0
  5. package/dist/builtins/template.node.car +0 -0
  6. package/dist/builtins/template.web-app.car +0 -0
  7. package/dist/cli.d.ts +3 -1
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +561 -272
  10. package/dist/cli.js.map +1 -1
  11. package/dist/content-provider.d.ts +1 -1
  12. package/dist/content-provider.d.ts.map +1 -1
  13. package/dist/content-provider.js +4 -3
  14. package/dist/content-provider.js.map +1 -1
  15. package/dist/context.d.ts +0 -1
  16. package/dist/context.d.ts.map +1 -1
  17. package/dist/context.js +0 -10
  18. package/dist/context.js.map +1 -1
  19. package/dist/doctor.d.ts +29 -0
  20. package/dist/doctor.d.ts.map +1 -0
  21. package/dist/doctor.js +576 -0
  22. package/dist/doctor.js.map +1 -0
  23. package/dist/identity.d.ts +1 -1
  24. package/dist/identity.d.ts.map +1 -1
  25. package/dist/identity.js +9 -9
  26. package/dist/identity.js.map +1 -1
  27. package/dist/ipc.d.ts +1 -2
  28. package/dist/ipc.d.ts.map +1 -1
  29. package/dist/ipc.js +1 -10
  30. package/dist/ipc.js.map +1 -1
  31. package/dist/kubo-install.d.ts +18 -1
  32. package/dist/kubo-install.d.ts.map +1 -1
  33. package/dist/kubo-install.js +424 -61
  34. package/dist/kubo-install.js.map +1 -1
  35. package/dist/kubo-release.d.ts +19 -0
  36. package/dist/kubo-release.d.ts.map +1 -1
  37. package/dist/kubo-release.js +164 -0
  38. package/dist/kubo-release.js.map +1 -1
  39. package/dist/kubo.d.ts +1 -0
  40. package/dist/kubo.d.ts.map +1 -1
  41. package/dist/kubo.js +102 -96
  42. package/dist/kubo.js.map +1 -1
  43. package/dist/pins.d.ts +15 -17
  44. package/dist/pins.d.ts.map +1 -1
  45. package/dist/pins.js +144 -106
  46. package/dist/pins.js.map +1 -1
  47. package/dist/publish-source.d.ts +3 -0
  48. package/dist/publish-source.d.ts.map +1 -0
  49. package/dist/publish-source.js +85 -0
  50. package/dist/publish-source.js.map +1 -0
  51. package/dist/runtime.d.ts.map +1 -1
  52. package/dist/runtime.js +1 -3
  53. package/dist/runtime.js.map +1 -1
  54. package/dist/state-storage-windows.js +1 -1
  55. package/dist/state-storage.d.ts +3 -1
  56. package/dist/state-storage.d.ts.map +1 -1
  57. package/dist/state-storage.js +38 -7
  58. package/dist/state-storage.js.map +1 -1
  59. package/dist/state.d.ts +40 -6
  60. package/dist/state.d.ts.map +1 -1
  61. package/dist/state.js +208 -82
  62. package/dist/state.js.map +1 -1
  63. package/dist/swarm-envelope.d.ts +1 -0
  64. package/dist/swarm-envelope.d.ts.map +1 -1
  65. package/dist/swarm-envelope.js +12 -0
  66. package/dist/swarm-envelope.js.map +1 -1
  67. package/dist/swarm.d.ts +64 -8
  68. package/dist/swarm.d.ts.map +1 -1
  69. package/dist/swarm.js +858 -106
  70. package/dist/swarm.js.map +1 -1
  71. package/package.json +4 -4
  72. package/src/app-templates.ts +1 -1
  73. package/src/cli.ts +702 -338
  74. package/src/content-provider.ts +4 -2
  75. package/src/context.ts +0 -10
  76. package/src/doctor.ts +902 -0
  77. package/src/identity.ts +10 -10
  78. package/src/ipc.ts +0 -8
  79. package/src/kubo-install.ts +562 -78
  80. package/src/kubo-release.ts +213 -0
  81. package/src/kubo.ts +134 -106
  82. package/src/pins.ts +188 -126
  83. package/src/publish-source.ts +103 -0
  84. package/src/runtime.ts +0 -3
  85. package/src/state-storage-windows.ts +1 -1
  86. package/src/state-storage.ts +53 -7
  87. package/src/state.ts +357 -98
  88. package/src/swarm-envelope.ts +14 -0
  89. package/src/swarm.ts +1234 -125
  90. package/dist/setup.d.ts +0 -8
  91. package/dist/setup.d.ts.map +0 -1
  92. package/dist/setup.js +0 -27
  93. package/dist/setup.js.map +0 -1
  94. package/src/setup.ts +0 -34
package/src/cli.ts CHANGED
@@ -26,12 +26,18 @@ import {
26
26
  } from "./history.js";
27
27
  import { execute } from "./runtime.js";
28
28
  import { validatedBundle } from "./space.js";
29
- import { exactCid, pinName, State, type RunRecord } from "./state.js";
29
+ import {
30
+ createAssociation,
31
+ exactCid,
32
+ State,
33
+ type Association,
34
+ type RunRecord,
35
+ } from "./state.js";
30
36
  import { buildBundle, inspectBundle, importBundle } from "./authoring.js";
31
37
  import { initApp } from "./app-authoring.js";
32
38
  import { assembleBundle } from "./assembly.js";
33
39
  import { getBundle } from "./get.js";
34
- import { setupDevice } from "./setup.js";
40
+ import { doctorDevice, doctorText } from "./doctor.js";
35
41
  import { keyId } from "@ipab/bundle/pointer/crypto";
36
42
  import {
37
43
  createSwarm,
@@ -41,7 +47,11 @@ import {
41
47
  removeMember,
42
48
  resumeRemoval,
43
49
  updateProfile,
50
+ accountProfile,
51
+ updateAccountProfile,
52
+ swarmMembers,
44
53
  verifiedRequest,
54
+ verifiedRequestStream,
45
55
  membershipRequestSummary,
46
56
  swarmHeader,
47
57
  sharedSwarmStatus,
@@ -51,11 +61,19 @@ import {
51
61
  formatNameReference,
52
62
  resolveReference,
53
63
  parseNameReference,
64
+ formalName,
54
65
  publish,
66
+ pinNameSubscription,
67
+ pinReference,
68
+ swarmRegistrations,
69
+ swarmAssociation,
70
+ setSwarmAssociation,
71
+ removeSwarmAssociation,
55
72
  type SwarmContext,
56
73
  } from "./swarm.js";
57
74
  import { schemaAlias } from "./app-definition.js";
58
- import { addPin, deletePin, pinDetails, renamePin } from "./pins.js";
75
+ import { unpin, pinDetails } from "./pins.js";
76
+ import { publicationSource } from "./publish-source.js";
59
77
  import { logFiles } from "./logs.js";
60
78
  import { builtinContent } from "./builtins.js";
61
79
  import { readSecretStream } from "./config-secret.js";
@@ -65,8 +83,9 @@ export interface IO {
65
83
  err(text: string, progress?: boolean): void;
66
84
  tty: boolean;
67
85
  columns?(): number | undefined;
68
- confirm(text: string): Promise<boolean>;
86
+ confirm(text: string, signal?: AbortSignal): Promise<boolean>;
69
87
  readSecret?(): Promise<string>;
88
+ requestInput?(): AsyncIterable<string | Uint8Array>;
70
89
  }
71
90
  let progressLine = false;
72
91
  export const processIO: IO = {
@@ -88,6 +107,13 @@ export const processIO: IO = {
88
107
  columns() {
89
108
  return process.stdout.columns;
90
109
  },
110
+ requestInput() {
111
+ if (process.stdin.isTTY)
112
+ syntax(
113
+ "Pipe Request JSON into swarm approve - --yes, or pass a Request file.",
114
+ );
115
+ return process.stdin;
116
+ },
91
117
  async readSecret() {
92
118
  if (process.stdin.isTTY)
93
119
  syntax(
@@ -96,14 +122,16 @@ export const processIO: IO = {
96
122
  process.stdin.setEncoding("utf8");
97
123
  return readSecretStream(process.stdin as AsyncIterable<string>);
98
124
  },
99
- async confirm(text) {
125
+ async confirm(text, signal) {
100
126
  const reader = createInterface({
101
127
  input: process.stdin,
102
128
  output: process.stderr,
103
129
  });
104
130
  try {
105
131
  return /^(y|yes)$/i.test(
106
- (await reader.question(`${text} [y/N] `)).trim(),
132
+ (
133
+ await reader.question(`${text} [y/N] `, signal ? { signal } : {})
134
+ ).trim(),
107
135
  );
108
136
  } finally {
109
137
  reader.close();
@@ -111,28 +139,25 @@ export const processIO: IO = {
111
139
  },
112
140
  };
113
141
  const commands: Record<string, string> = {
114
- setup: "setup [--yes] [--kubo-archive FILE]",
142
+ doctor: "doctor [--fix [--yes]]",
143
+ profile: "profile [--name NAME] [--description TEXT]",
115
144
  "swarm create": "swarm create [--service URL] [--resume OPERATION]",
116
- "swarm request":
117
- "swarm request CONFIG_URL --owner-fingerprint FINGERPRINT [--output FILE] [--alias ALIAS]",
118
- "swarm export": "swarm export URL_OR_ALIAS --output FILE",
145
+ "swarm request": "swarm request CONFIG_URL [--output FILE] [--alias ALIAS]",
146
+ "swarm export": "swarm export --output FILE",
119
147
  "swarm approve": "swarm approve REQUEST_FILE [--again] --yes",
120
- "swarm exclude":
121
- "swarm exclude MEMBER_PUBLIC_KEY [--swarm URL_OR_ALIAS] --yes",
122
- "swarm resume": "swarm resume [URL_OR_ALIAS]",
123
- "swarm profile":
124
- "swarm profile [URL_OR_ALIAS] [--name NAME] [--address MULTIADDR]",
125
- "swarm status": "swarm status [URL_OR_ALIAS]",
148
+ "swarm exclude": "swarm exclude MEMBER_PUBLIC_KEY --yes",
149
+ "swarm resume": "swarm resume",
150
+ "swarm profile": "swarm profile --address MULTIADDR",
151
+ "swarm status": "swarm status [--local]",
152
+ "swarm members": "swarm members",
126
153
  "swarm list": "swarm list",
127
154
  "swarm add": "swarm add CONFIG_URL [--alias ALIAS]",
128
155
  "swarm use": "swarm use URL_OR_ALIAS",
129
156
  "swarm remove": "swarm remove URL_OR_ALIAS",
130
- "swarm update":
131
- "swarm update [URL_OR_ALIAS] [--name TEXT] [--description TEXT]",
132
- publish:
133
- "publish CID_OR_CAR [--name NAME [--expect OLD_NODE_CID | --snapshot]]",
157
+ "swarm update": "swarm update [--name TEXT] [--description TEXT]",
158
+ publish: "publish NAME SOURCE [--expect OLD_ARTIFACT_CID | --snapshot]",
134
159
  get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
135
- search: "search QUERY [--current] [--force | --no-force]",
160
+ search: "search QUERY [--all | --current] [--force | --no-force]",
136
161
  init: "init NAME [DIR] [OPTIONS]",
137
162
  build: "build [SOURCE] [OPTIONS]",
138
163
  "bundle build": "bundle build SOURCE [OPTIONS]",
@@ -140,14 +165,14 @@ const commands: Record<string, string> = {
140
165
  "bundle import": "bundle import FILE.car",
141
166
  exec: "exec [--log] [--force | --no-force] APP [APP_ARGS...]",
142
167
  open: "open [--log] [--raw] [--force | --no-force] CONTENT",
143
- "pin add": "pin add NAME CID",
144
- "pin delete": "pin delete NAME",
145
- "pin list": "pin list [--type TYPE]",
146
- "pin show": "pin show NAME",
147
- "pin rename": "pin rename OLD_NAME NEW_NAME",
148
- "register list": "register list",
149
- "register set": "register set SCHEMA APP [--replace] [-- TEMPLATE...]",
150
- "register remove": "register remove SCHEMA",
168
+ pin: "pin REF",
169
+ unpin: "unpin REF",
170
+ "pin list": "pin list",
171
+ "pin show": "pin show REF",
172
+ "register list": "register list [--swarm URL_OR_ALIAS]...",
173
+ "register set":
174
+ "register set SCHEMA APP [--swarm URL_OR_ALIAS]... [--replace] [-- TEMPLATE...]",
175
+ "register remove": "register remove SCHEMA [--swarm URL_OR_ALIAS]...",
151
176
  "config get": "config get [KEY]",
152
177
  "config set":
153
178
  "config set KEY VALUE\n ipab config set pointers.apiKey - < protected-key-file",
@@ -162,7 +187,7 @@ const commands: Record<string, string> = {
162
187
  const groups: Record<string, string> = {
163
188
  swarm: "Create, authorize, select and manage personal swarms",
164
189
  bundle: "Create, inspect and import content bundles",
165
- pin: "Retain content and manage short names",
190
+ pin: "Retain an exact CID or follow a shared Swarm Name",
166
191
  register: "Associate content types with Apps",
167
192
  config: "Manage local configuration",
168
193
  store: "Query local storage and collect unreferenced blocks",
@@ -178,16 +203,42 @@ const commandHelp: Record<
178
203
  notes?: string[];
179
204
  }
180
205
  > = {
181
- setup: {
206
+ profile: {
207
+ summary: "Read or update your account-wide public name and description",
208
+ examples: [
209
+ "ipab profile",
210
+ 'ipab profile --name Wei --description "Developer"',
211
+ 'ipab profile --description ""',
212
+ ],
213
+ options: [
214
+ "--name NAME Replace only your personal name.",
215
+ "--description TEXT Replace only your description; empty text clears it.",
216
+ ],
217
+ notes: [
218
+ "Independent of Swarm selection. Reading never creates an identity, persists a profile or activates a node.",
219
+ "An explicit update prepares a missing account identity without starting Kubo.",
220
+ "Updates persist locally first, then synchronize all registered memberships without changing network addresses. Partial failure exits nonzero and reports every result.",
221
+ "Retry the same profile update, or normally activate a failed membership to synchronize the saved profile.",
222
+ "First use preserves unanimous legacy values; conflicting fields require an explicit choice. New memberships adopt this same profile.",
223
+ ],
224
+ },
225
+ doctor: {
182
226
  summary:
183
- "Verify/install Kubo and prepare the protected HOME account identity",
184
- examples: ["ipab setup --yes", "ipab setup"],
227
+ "Inspect device readiness without writes; explicitly authorize safe repairs",
228
+ examples: [
229
+ "ipab doctor",
230
+ "ipab doctor --fix",
231
+ "ipab --json doctor --fix --yes",
232
+ ],
185
233
  options: [
186
- "--yes Confirm installation and identity initialization outside a TTY.",
187
- "--kubo-archive FILE Use a local official archive matching this CLI's pinned platform digest, without network access.",
234
+ "--fix Repair missing components, cache official archives to verify existing Kubo without reinstall, and authorize healthy compatible upgrades within ^0.43.2.",
235
+ "--yes Authorize planned repairs without prompting; requires --fix.",
188
236
  ],
189
237
  notes: [
190
- "Idempotent: reuse the same verified program and existing identity.",
238
+ "Always checks local state/configuration, managed Kubo, HOME identity, local Swarm registry and compatible updates.",
239
+ "Inspection never creates state, locks, credentials or caches. Official release metadata may be queried; unavailable updates are not claimed current.",
240
+ "Healthy current components are reused without download or confirmation. Fixed protected archive cache is automatic.",
241
+ "Unverified existing Kubo: --fix may download/cache its exact-version official archive for byte comparison only; never execute it to authenticate itself or overwrite a mismatch.",
191
242
  "Does not create Swarm repos, start or contact any daemon, deploy services or install login startup.",
192
243
  ],
193
244
  },
@@ -214,16 +265,20 @@ const commandHelp: Record<
214
265
  "swarm request": {
215
266
  summary: "Save and export a signed self-contained membership Request",
216
267
  examples: [
217
- "ipab swarm request CONFIG_URL --owner-fingerprint TRUSTED_FINGERPRINT --output request.json --alias work",
268
+ "ipab swarm request CONFIG_URL --alias work",
269
+ "ipab swarm request CONFIG_URL --output request.json --alias work",
218
270
  ],
219
271
  options: [
220
- "--owner-fingerprint VALUE Verify Owner through a trusted independent channel.",
221
- "--name NAME Initial public display name.",
222
272
  "--alias ALIAS Pre-register the target for lazy onboarding.",
223
- "--output FILE Export the saved exact Request; no expiry or new PeerID on retry.",
273
+ "--output FILE Export to a new file instead of stdout; never overwrites.",
224
274
  ],
225
275
  notes: [
276
+ "Verify the printed Owner fingerprint through an independent trusted channel before manually sending the Request file to the Owner.",
277
+ "Without --output, stdout is the signed Request JSON, including in --json mode.",
278
+ "With --output, reports the file on stderr; --json returns file, requestId and ownerFingerprint.",
279
+ "Retries export the exact saved Request without expiry or a new PeerID.",
226
280
  "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
281
+ "Set your account-wide personal name with ipab profile --name NAME before requesting membership.",
227
282
  "If the alias is taken, choose another to keep both Swarms. If you mean to replace only the local registration, run ipab swarm remove ALIAS and retry.",
228
283
  ],
229
284
  },
@@ -233,14 +288,18 @@ const commandHelp: Record<
233
288
  "--yes Explicit approval; required outside a TTY.",
234
289
  "--again Explicit fresh approval of an old Request; history is advisory.",
235
290
  ],
236
- examples: ["ipab swarm approve request.json --yes"],
291
+ examples: [
292
+ "ipab swarm approve request.json --yes",
293
+ "ipab swarm approve - --yes < request.json",
294
+ ],
237
295
  notes: [
296
+ "Use '-' to read Request JSON from stdin (maximum 16 KiB); --yes is required and no confirmation prompt reads stdin.",
238
297
  "Creates a public profile and publishes an Owner-signed X25519/AES-GCM package. Exact-ID certificates have no expiry.",
239
298
  ],
240
299
  },
241
300
  "swarm export": {
242
301
  summary: "Re-export the same persisted Request",
243
- examples: ["ipab swarm export work --output request.json"],
302
+ examples: ["ipab --swarm work swarm export --output request.json"],
244
303
  },
245
304
  "swarm exclude": {
246
305
  summary: "Owner removes a member with irreversible HEAD/key rotation",
@@ -251,13 +310,22 @@ const commandHelp: Record<
251
310
  },
252
311
  "swarm resume": {
253
312
  summary: "Owner resumes an interrupted organization switch",
254
- examples: ["ipab swarm resume work"],
313
+ examples: ["ipab --swarm work swarm resume"],
255
314
  },
256
315
  "swarm profile": {
257
- summary: "Update your public display name and LAN/VPN IPv4 TCP address",
316
+ summary: "Configure only your selected Swarm's LAN/VPN IPv4 TCP address",
258
317
  examples: [
259
- "ipab swarm profile work --name Wei",
260
- "ipab swarm profile work --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
318
+ "ipab --swarm work swarm profile --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
319
+ ],
320
+ notes: [
321
+ "Personal name/description are managed only by ipab profile, not this network configuration command.",
322
+ ],
323
+ },
324
+ "swarm members": {
325
+ summary: "List every public member, including the Owner",
326
+ examples: ["ipab --swarm work swarm members", "ipab --json swarm members"],
327
+ notes: [
328
+ "Public HTTP reads only; no local membership, identity creation or node activation. Failed reads fail the command, never omit members.",
261
329
  ],
262
330
  },
263
331
  "swarm status": {
@@ -267,8 +335,8 @@ const commandHelp: Record<
267
335
  ],
268
336
  examples: [
269
337
  "ipab swarm status",
270
- "ipab swarm status work",
271
- "ipab swarm status work --local",
338
+ "ipab --swarm work swarm status",
339
+ "ipab --swarm work swarm status --local",
272
340
  ],
273
341
  notes: [
274
342
  "Always read public configuration, Scope and HEAD, and verify the State. Local content needs no HOME identity or node activation.",
@@ -304,13 +372,12 @@ const commandHelp: Record<
304
372
  },
305
373
  "swarm update": {
306
374
  summary: "Owner updates public organization information",
307
- arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
308
375
  options: [
309
376
  "--name TEXT Replace the shared display name; empty text clears it.",
310
377
  "--description TEXT Replace the shared description; empty text clears it.",
311
378
  ],
312
379
  examples: [
313
- 'ipab swarm update work --name "Team" --description "Shared workspace"',
380
+ 'ipab --swarm work swarm update --name "Team" --description "Shared workspace"',
314
381
  'ipab swarm update --description ""',
315
382
  ],
316
383
  notes: [
@@ -320,37 +387,44 @@ const commandHelp: Record<
320
387
  ],
321
388
  },
322
389
  search: {
323
- summary: "Search formal Names across registered swarms",
390
+ summary: "Search formal Names in the current swarm",
324
391
  arguments: [
325
392
  "QUERY Case-insensitive literal name substring, 1..256 characters.",
326
393
  ],
327
394
  options: [
328
- "--current Search only the effective current swarm; conflicts with --swarm.",
395
+ "--all Search all registered swarms; conflicts with --current and --swarm.",
396
+ "--current Explicitly select the default search scope; conflicts with --swarm.",
329
397
  "--force Refresh HEAD for every swarm in the search scope.",
330
398
  "--no-force Override swarm.forceRefresh and use valid cached headers.",
331
399
  ],
332
- examples: ["ipab search hello", "ipab --swarm work search hello --force"],
400
+ examples: [
401
+ "ipab search hello",
402
+ "ipab search hello --all",
403
+ "ipab --swarm work search hello --force",
404
+ ],
333
405
  notes: [
334
- "Searches all registered swarms unless --current or --swarm selects one.",
335
- "Valid caches use local Names only; absent/expired caches refresh. No payload downloads.",
406
+ "Searches only --swarm or the saved current swarm by default. Use --all to search every registration.",
407
+ "Valid caches use local Names; absent/expired caches refresh. Active Name pins may synchronize content.",
408
+ "Refresh reads public configuration and HEAD; private networking is activated only for missing content.",
336
409
  "No matches is success, not a reason to refresh valid caches. Any failed swarm fails the whole search.",
337
410
  "Text uses local alias URIs when available; JSON references use full configuration URLs for cross-device sharing.",
338
411
  ],
339
412
  },
340
413
  publish: {
341
- summary: "Provide built content and explicitly publish a Name",
414
+ summary: "Protect content locally and publish a shared Swarm Name",
342
415
  options: [
343
- "--name NAME New formal Name; occupied Names fail.",
344
416
  "--expect CID Exact old Artifact node, required for iteration.",
345
417
  "--snapshot Name ordinary content without an Artifact; initial only.",
346
418
  ],
347
419
  examples: [
348
- "ipab publish app.car --name apps/hello",
349
- "ipab publish APP_CID --name apps/hello --expect OLD_NODE_CID",
350
- "ipab publish CONTENT_CID",
420
+ "ipab --swarm work publish apps/hello app.car",
421
+ "ipab publish apps/hello APP_CID --expect OLD_ARTIFACT_CID",
422
+ "ipab publish notes/readme ./README.md",
351
423
  ],
352
424
  notes: [
353
- "No build, edit, install or execution. CID-only stdout.",
425
+ "SOURCE is an exact Bundle CID, CAR, regular file or directory. No compiler, hooks, install or App execution.",
426
+ "Directories require .bundle.yaml/type, or a package.json source snapshot. Standalone .json/.yaml/.yml/.md/.txt entries get a standard Bundle; other file types require explicit metadata.",
427
+ "Occupied Names require --expect EXACT_OLD_ARTIFACT_CID. Published payloads are local CID pins; unpin CID releases that current protection, not legitimate history holders.",
354
428
  "Different-name CAS contention is rebased; same-name edits conflict (exit 3).",
355
429
  "Kubo pin confirmation precedes HEAD; it does not prove a remote device is online.",
356
430
  ],
@@ -450,7 +524,9 @@ const commandHelp: Record<
450
524
  },
451
525
  "bundle inspect": {
452
526
  summary: "Inspect a Bundle or type definition",
453
- arguments: ["SOURCE Directory, definition file, CAR, CID or named pin."],
527
+ arguments: [
528
+ "SOURCE Directory, definition file, CAR, CID or packaged builtin reference.",
529
+ ],
454
530
  examples: ["ipab bundle inspect note\\dist\\bundle.car"],
455
531
  notes: ["Does not execute Apps, import content or create pins."],
456
532
  },
@@ -460,11 +536,11 @@ const commandHelp: Record<
460
536
  examples: ["ipab bundle import hello\\dist\\app.car"],
461
537
  notes: [
462
538
  "Repeated imports are safe; no App execution or daemon startup.",
463
- "Does not pin or retain content. Use pin add for persistent retention.",
539
+ "Does not pin or retain content. Use pin CID for persistent retention.",
464
540
  ],
465
541
  },
466
542
  exec: {
467
- summary: "Run an App by CID, named pin or IPAB URI",
543
+ summary: "Run an App by exact CID or Swarm IPAB URI",
468
544
  arguments: [
469
545
  "APP_ARGS Everything after APP is passed verbatim, including --help.",
470
546
  ],
@@ -488,7 +564,9 @@ const commandHelp: Record<
488
564
  },
489
565
  open: {
490
566
  summary: "Open content with its registered App",
491
- arguments: ["CONTENT Bundle CID, named pin or IPAB URI."],
567
+ arguments: [
568
+ "CONTENT Bundle CID, packaged builtin reference or Swarm IPAB URI.",
569
+ ],
492
570
  options: [
493
571
  "--log Record stdout/stderr; requires history enabled.",
494
572
  "--raw Open the Artifact node rather than its value.",
@@ -502,86 +580,107 @@ const commandHelp: Record<
502
580
  ],
503
581
  notes: [
504
582
  "Requires a saved registration and App support for the exact content type.",
583
+ "Uses only the content URI's Swarm, otherwise --swarm, otherwise swarm.default. A selected Swarm is required.",
584
+ "A registered App's retrieval, compatibility or execution failure never triggers fallback.",
585
+ "Legacy User registrations are inactive and preserved in the state database's legacy_user_registrations table; review them before explicit Swarm registration.",
505
586
  "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
506
587
  "Apps are NOT sandboxed; run only Apps you trust.",
507
588
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
508
589
  "--json is not supported; App stdio is passed through.",
509
590
  ],
510
591
  },
511
- "pin add": {
512
- summary: "Verify, retain and name a Bundle",
592
+ pin: {
593
+ summary: "Retain an immutable CID or follow a shared Swarm Name",
513
594
  arguments: [
514
- "NAME Unused short name.",
515
- "CID Exact Bundle CID, not another pin name or a standalone type block.",
595
+ "REF Exact Bundle CID or ipab://SWARM/NAME; no local content aliases.",
596
+ ],
597
+ examples: [
598
+ "ipab pin APP_CID",
599
+ "ipab pin ipab://work/apps/reader",
600
+ "ipab pin list",
516
601
  ],
517
- examples: ["ipab pin add reader APP_CID"],
518
602
  notes: [
519
603
  "Validates a complete Bundle and retains its full DAG in the configured Store.",
520
- "Does not execute or trust Apps, install dependencies or start a daemon.",
604
+ "A CID stays fixed. A shared Name saves its canonical configuration URL and exact Name, refreshing on related Swarm HEAD reads/sync, not continuously.",
605
+ "New content is verified and retained before the previous subscription version is released. Failures keep the last good version marked stale; deleted Names keep it marked missing.",
606
+ "Does not execute Apps or install dependencies. Shared Names connect to their Swarm content source only as needed.",
521
607
  "The builtin namespace is read-only.",
522
608
  ],
523
609
  },
524
- "pin delete": {
525
- summary: "Remove a user pin and release its retention",
526
- examples: ["ipab pin delete reader"],
610
+ unpin: {
611
+ summary: "Release a CID pin or stop following a shared Name",
612
+ examples: ["ipab unpin APP_CID", "ipab unpin ipab://work/apps/reader"],
527
613
  notes: [
528
614
  "Releases only this pin's ownership on its original backend; no block deletion or GC.",
529
- "Does not change registrations or history. Built-in pins are read-only.",
615
+ "Never re-resolves a shared Name to release content. Uses only saved actual roots. Missing pins are success.",
616
+ "Exact CID also releases archived legacy named-pin holders for that CID. Does not change shared Names, registrations or history. Built-ins are read-only.",
617
+ "Publication/history owners are independent; --snapshot payloads remain recursively retained by publication history after ordinary unpin.",
530
618
  ],
531
619
  },
532
620
  "pin list": {
533
- summary: "List user and built-in pins",
534
- options: [
535
- "--type TYPE Exact type CID or the name of a Bundle pin of that type.",
536
- ],
537
- examples: ["ipab pin list", "ipab pin list --type reader"],
621
+ summary: "List local retention, following Names and packaged built-ins",
622
+ examples: ["ipab pin list"],
538
623
  notes: [
539
- "Unfinished operations and legacy non-Bundle pins are reported separately.",
540
- "Legacy retention is preserved; use pin delete to explicitly release it.",
624
+ "Includes pending/stale/missing records and inactive archived local pin names.",
625
+ "Legacy retention is preserved; use unpin EXACT_CID to explicitly release its archived holders.",
541
626
  "Reads local registrations and packaged built-ins, not live node status.",
542
627
  ],
543
628
  },
544
629
  "pin show": {
545
- summary: "Show a pin's CID and type metadata",
546
- examples: ["ipab pin show reader", "ipab pin show builtin:template.node"],
630
+ summary: "Show saved retention and following status",
631
+ examples: ["ipab pin show APP_CID", "ipab pin show builtin:template.node"],
547
632
  notes: [
548
633
  "Reads local metadata; built-in pins do not claim user Store retention.",
549
634
  ],
550
635
  },
551
- "pin rename": {
552
- summary: "Rename a user pin without changing its content",
553
- examples: ["ipab pin rename reader my-reader"],
554
- notes: [
555
- "NEW_NAME must be unused. Built-in pins are read-only.",
556
- "CID, ownership, registrations and history are unchanged.",
557
- ],
558
- },
559
636
  "register list": {
560
637
  summary: "List saved content-type associations",
561
- examples: ["ipab register list"],
638
+ options: [
639
+ "--swarm URL_OR_ALIAS Read this Swarm registry; repeat for multiple Swarms.",
640
+ ],
641
+ examples: ["ipab register list", "ipab register list --swarm work"],
642
+ notes: [
643
+ "Without explicit --swarm, reads the saved default Swarm. Select one with --swarm or ipab swarm use.",
644
+ "Legacy User registrations are inactive and preserved in legacy_user_registrations; no automatic upload or deletion.",
645
+ ],
562
646
  },
563
647
  "register set": {
564
648
  summary: "Associate a content type with an App",
565
649
  arguments: [
566
650
  "SCHEMA Exact type CID or builtin:node-app.v1.",
567
- "APP App CID or named pin; the exact CID is saved.",
651
+ "APP App CID or Swarm IPAB URI; the exact CID is saved.",
568
652
  "TEMPLATE App argv after --; must contain a whole argument % (default: %).",
569
653
  ],
570
- options: ["--replace Allow changing an existing association."],
654
+ options: [
655
+ "--replace Allow changing an existing association.",
656
+ "--swarm URL_OR_ALIAS Write this Swarm registry; repeat for multiple Swarms.",
657
+ ],
571
658
  examples: [
572
659
  "ipab register set SCHEMA_CID reader",
573
660
  "ipab register set SCHEMA_CID reader '--' '--cid' '%'",
661
+ "ipab register set SCHEMA_CID ipab:///apps/reader --swarm work --swarm team",
574
662
  ],
575
663
  notes: [
576
664
  "Replaces only the whole % argument with the content CID; no shell expansion.",
577
665
  "Does not verify App type support; open checks it before execution.",
666
+ "Without explicit --swarm, writes the saved default Swarm. Swarm writes require HEAD write access.",
667
+ "Multiple Swarms commit sequentially, not atomically; failures report completed targets.",
578
668
  ],
579
669
  },
580
670
  "register remove": {
581
671
  summary: "Remove a saved content-type association",
582
672
  arguments: ["SCHEMA Exact type CID or builtin:node-app.v1."],
583
- examples: ["ipab register remove SCHEMA_CID"],
584
- notes: ["Does not remove Apps, pins or content."],
673
+ options: [
674
+ "--swarm URL_OR_ALIAS Remove from this Swarm registry; repeat for multiple Swarms.",
675
+ ],
676
+ examples: [
677
+ "ipab register remove SCHEMA_CID",
678
+ "ipab register remove SCHEMA_CID --swarm work",
679
+ ],
680
+ notes: [
681
+ "Without explicit --swarm, removes from the saved default Swarm. Multiple Swarm edits are not atomic.",
682
+ "Does not remove Apps, pins or content.",
683
+ ],
585
684
  },
586
685
  "config get": {
587
686
  summary: "Show effective configuration",
@@ -609,7 +708,7 @@ const commandHelp: Record<
609
708
  "history list": {
610
709
  summary: "List execution history",
611
710
  options: [
612
- "--app APP Filter by App CID or named pin.",
711
+ "--app APP Filter by exact App CID.",
613
712
  "--status STATUS succeeded, failed or cancelled.",
614
713
  "--since TIME Include runs ended at or after TIME.",
615
714
  "--until TIME Include runs ended before TIME.",
@@ -632,7 +731,7 @@ const commandHelp: Record<
632
731
  "history remove": {
633
732
  summary: "Remove execution records and their logs",
634
733
  options: [
635
- "--app APP Filter by App CID or named pin.",
734
+ "--app APP Filter by exact App CID.",
636
735
  "--status STATUS succeeded, failed or cancelled.",
637
736
  "--since TIME Include runs ended at or after TIME.",
638
737
  "--until TIME Include runs ended before TIME.",
@@ -673,12 +772,14 @@ Create:
673
772
  bundle ${groups.bundle}
674
773
 
675
774
  Manage:
676
- setup ${commandHelp.setup!.summary}
775
+ doctor ${commandHelp.doctor!.summary}
776
+ profile ${commandHelp.profile!.summary}
677
777
  swarm ${groups.swarm}
678
- search Search formal Names across registered swarms
778
+ search Search formal Names in the current swarm
679
779
  publish ${commandHelp.publish!.summary}
680
780
  get ${commandHelp.get!.summary}
681
781
  pin ${groups.pin}
782
+ unpin ${commandHelp.unpin!.summary}
682
783
  register ${groups.register}
683
784
  config ${groups.config}
684
785
  store ${groups.store}
@@ -701,7 +802,25 @@ ${footer}`;
701
802
  ...(topic.arguments ? [section("Arguments", topic.arguments)] : []),
702
803
  ...(topic.options ? [section("Options", topic.options)] : []),
703
804
  section("Examples", topic.examples),
704
- ...(topic.notes ? [section("Notes", topic.notes)] : []),
805
+ ...([
806
+ "swarm status",
807
+ "swarm members",
808
+ "swarm update",
809
+ "swarm resume",
810
+ "swarm profile",
811
+ "swarm export",
812
+ "swarm approve",
813
+ "swarm exclude",
814
+ ].includes(path)
815
+ ? [
816
+ section("Notes", [
817
+ ...(topic.notes ?? []),
818
+ "Select only with global --swarm URL_OR_ALIAS (before the command), or the saved swarm.default. Neither means an error.",
819
+ ]),
820
+ ]
821
+ : topic.notes
822
+ ? [section("Notes", topic.notes)]
823
+ : []),
705
824
  `\n\n-h, --help shows this help. Global options: see 'ipab --help'.\n${footer}`,
706
825
  ].join("");
707
826
  }
@@ -844,6 +963,7 @@ interface Parsed {
844
963
  options: Record<string, string | boolean>;
845
964
  template?: string[];
846
965
  parameters?: string[];
966
+ registrySwarms?: string[];
847
967
  help: boolean;
848
968
  version: boolean;
849
969
  }
@@ -867,6 +987,7 @@ async function closeStore(
867
987
  export function parse(argv: readonly string[]): Parsed {
868
988
  const tokens = [...argv];
869
989
  const flags: GlobalOptions = { json: false };
990
+ const swarms: string[] = [];
870
991
  while (tokens[0]?.startsWith("-")) {
871
992
  const flag = tokens.shift()!;
872
993
  if (flag === "-h" || flag === "--help")
@@ -902,8 +1023,10 @@ export function parse(argv: readonly string[]): Parsed {
902
1023
  const value = tokens.shift();
903
1024
  if (!value || value.startsWith("-")) syntax(`${flag} needs a value.`);
904
1025
  if (flag === "--state-dir") flags.stateDir = value;
905
- else if (flag === "--swarm") flags.swarm = value;
906
- else {
1026
+ else if (flag === "--swarm") {
1027
+ flags.swarm = value;
1028
+ swarms.push(value);
1029
+ } else {
907
1030
  flags.storeGateway = publicUrl(value);
908
1031
  }
909
1032
  } else syntax(`Unknown global option "${flag}".`);
@@ -916,6 +1039,7 @@ export function parse(argv: readonly string[]): Parsed {
916
1039
  options: {},
917
1040
  help: !group,
918
1041
  version: false,
1042
+ ...(group === "register" ? { registrySwarms: swarms } : {}),
919
1043
  };
920
1044
  if (!group) return result;
921
1045
  if (group === "exec") {
@@ -938,9 +1062,17 @@ export function parse(argv: readonly string[]): Parsed {
938
1062
  return result;
939
1063
  }
940
1064
  if (
941
- !["open", "init", "build", "publish", "get", "search", "setup"].includes(
942
- group,
943
- )
1065
+ ![
1066
+ "open",
1067
+ "init",
1068
+ "build",
1069
+ "publish",
1070
+ "get",
1071
+ "search",
1072
+ "doctor",
1073
+ "profile",
1074
+ "unpin",
1075
+ ].includes(group)
944
1076
  ) {
945
1077
  if (
946
1078
  ![
@@ -953,12 +1085,18 @@ export function parse(argv: readonly string[]): Parsed {
953
1085
  "swarm",
954
1086
  ].includes(group)
955
1087
  )
956
- syntax(`Unknown command "${group}".`);
957
- if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
1088
+ syntax(
1089
+ `Unknown command "${group}".${group === "setup" ? " Run ipab doctor to inspect, or ipab doctor --fix to prepare this device." : " Run ipab --help."}`,
1090
+ );
1091
+ if (group === "pin" && !["list", "show"].includes(tokens[0] ?? "")) {
1092
+ if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
1093
+ result.help = true;
1094
+ return result;
1095
+ }
1096
+ } else if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
958
1097
  result.help = true;
959
1098
  return result;
960
- }
961
- result.path = `${group} ${tokens.shift()!}`;
1099
+ } else result.path = `${group} ${tokens.shift()!}`;
962
1100
  } else if (group === "open" && flags.json)
963
1101
  syntax("--json is not supported for exec/open.");
964
1102
  if (!commands[result.path]) syntax(`Unknown command "${result.path}".`);
@@ -978,8 +1116,8 @@ export function parse(argv: readonly string[]): Parsed {
978
1116
  "API key must be provided through '-' and piped stdin; never pass it in command arguments.",
979
1117
  );
980
1118
  const booleans =
981
- result.path === "setup"
982
- ? ["yes"]
1119
+ result.path === "doctor"
1120
+ ? ["fix", "yes"]
983
1121
  : result.path === "bundle build"
984
1122
  ? ["replace", "schema-only", "no-import"]
985
1123
  : result.path === "build"
@@ -989,7 +1127,7 @@ export function parse(argv: readonly string[]): Parsed {
989
1127
  : result.path === "get"
990
1128
  ? ["raw", "force", "no-force"]
991
1129
  : result.path === "search"
992
- ? ["current", "force", "no-force"]
1130
+ ? ["all", "current", "force", "no-force"]
993
1131
  : result.path === "swarm approve"
994
1132
  ? ["yes", "again"]
995
1133
  : result.path === "swarm status"
@@ -1009,17 +1147,17 @@ export function parse(argv: readonly string[]): Parsed {
1009
1147
  : result.path === "swarm add"
1010
1148
  ? ["alias"]
1011
1149
  : result.path === "swarm request"
1012
- ? ["owner-fingerprint", "name", "alias", "output"]
1150
+ ? ["alias", "output"]
1013
1151
  : result.path === "swarm export"
1014
1152
  ? ["output"]
1015
1153
  : result.path === "swarm profile"
1016
- ? ["name", "address"]
1017
- : result.path === "swarm update"
1154
+ ? ["address"]
1155
+ : result.path === "swarm update" || result.path === "profile"
1018
1156
  ? ["name", "description"]
1019
1157
  : result.path === "swarm approve"
1020
1158
  ? []
1021
1159
  : result.path === "publish"
1022
- ? ["name", "expect"]
1160
+ ? ["expect"]
1023
1161
  : result.path === "get"
1024
1162
  ? ["output"]
1025
1163
  : result.path === "init"
@@ -1038,10 +1176,7 @@ export function parse(argv: readonly string[]): Parsed {
1038
1176
  ]
1039
1177
  : result.path === "history remove"
1040
1178
  ? ["app", "status", "since", "until"]
1041
- : result.path === "pin list"
1042
- ? ["type"]
1043
- : [];
1044
- if (result.path === "setup") values.push("kubo-archive");
1179
+ : [];
1045
1180
  while (tokens.length) {
1046
1181
  const value = tokens.shift()!;
1047
1182
  if (
@@ -1051,6 +1186,13 @@ export function parse(argv: readonly string[]): Parsed {
1051
1186
  result.positional.push(value);
1052
1187
  } else if (value.startsWith("--") || value === "-o") {
1053
1188
  const option = value === "-o" ? "output" : value.slice(2);
1189
+ if (result.path.startsWith("register ") && option === "swarm") {
1190
+ const input = tokens.shift();
1191
+ if (!input || input.startsWith("-")) syntax("--swarm needs a value.");
1192
+ result.registrySwarms!.push(input);
1193
+ flags.swarm = input;
1194
+ continue;
1195
+ }
1054
1196
  if (result.path === "init" && option === "param") {
1055
1197
  const input = tokens.shift();
1056
1198
  if (!input || input.startsWith("--") || input.indexOf("=") < 1)
@@ -1066,15 +1208,19 @@ export function parse(argv: readonly string[]): Parsed {
1066
1208
  if (
1067
1209
  input === undefined ||
1068
1210
  (input.startsWith("--") &&
1069
- !(
1070
- ["resume", "owner-fingerprint"].includes(option) &&
1071
- /^[A-Za-z0-9_-]{43}$/.test(input)
1072
- )) ||
1073
- (input === "" && result.path !== "swarm update")
1211
+ !(option === "resume" && /^[A-Za-z0-9_-]{43}$/.test(input))) ||
1212
+ (input === "" && !["swarm update", "profile"].includes(result.path))
1074
1213
  )
1075
1214
  syntax(`${value} needs a value.`);
1076
1215
  result.options[option] = input;
1077
- } else syntax(`Unknown option "${value}".`);
1216
+ } else if (
1217
+ option === "name" &&
1218
+ ["swarm profile", "swarm request"].includes(result.path)
1219
+ )
1220
+ syntax(
1221
+ `Personal names are account-wide. Use ipab profile --name NAME instead.${result.path === "swarm profile" ? " For network configuration, use ipab --swarm URL_OR_ALIAS swarm profile --address MULTIADDR." : ""}`,
1222
+ );
1223
+ else syntax(`Unknown option "${value}".`);
1078
1224
  } else result.positional.push(value);
1079
1225
  }
1080
1226
  if (result.options.force && result.options["no-force"])
@@ -1085,22 +1231,30 @@ export function parse(argv: readonly string[]): Parsed {
1085
1231
  flags.swarm !== undefined
1086
1232
  )
1087
1233
  syntax("--current and --swarm are mutually exclusive.");
1234
+ if (
1235
+ result.path === "search" &&
1236
+ result.options.all &&
1237
+ (result.options.current || flags.swarm !== undefined)
1238
+ )
1239
+ syntax("--all is mutually exclusive with --current and --swarm.");
1088
1240
  const counts: Record<string, [number, number]> = {
1089
- setup: [0, 0],
1241
+ doctor: [0, 0],
1242
+ profile: [0, 0],
1090
1243
  "swarm create": [0, 0],
1091
1244
  "swarm request": [1, 1],
1092
1245
  "swarm approve": [1, 1],
1093
- "swarm export": [1, 1],
1246
+ "swarm export": [0, 0],
1094
1247
  "swarm exclude": [1, 1],
1095
- "swarm resume": [0, 1],
1096
- "swarm profile": [0, 1],
1097
- "swarm status": [0, 1],
1248
+ "swarm resume": [0, 0],
1249
+ "swarm profile": [0, 0],
1250
+ "swarm status": [0, 0],
1251
+ "swarm members": [0, 0],
1098
1252
  "swarm list": [0, 0],
1099
1253
  "swarm add": [1, 1],
1100
1254
  "swarm use": [1, 1],
1101
1255
  "swarm remove": [1, 1],
1102
- "swarm update": [0, 1],
1103
- publish: [1, 1],
1256
+ "swarm update": [0, 0],
1257
+ publish: [2, 2],
1104
1258
  get: [1, 1],
1105
1259
  search: [1, 1],
1106
1260
  init: [1, 2],
@@ -1109,11 +1263,10 @@ export function parse(argv: readonly string[]): Parsed {
1109
1263
  "bundle inspect": [1, 1],
1110
1264
  "bundle import": [1, 1],
1111
1265
  open: [1, 1],
1112
- "pin add": [2, 2],
1113
- "pin delete": [1, 1],
1266
+ pin: [1, 1],
1267
+ unpin: [1, 1],
1114
1268
  "pin list": [0, 0],
1115
1269
  "pin show": [1, 1],
1116
- "pin rename": [2, 2],
1117
1270
  "register list": [0, 0],
1118
1271
  "register set": [2, 2],
1119
1272
  "register remove": [1, 1],
@@ -1129,6 +1282,22 @@ export function parse(argv: readonly string[]): Parsed {
1129
1282
  if (result.options["with-source"] && result.options["without-source"])
1130
1283
  syntax("--with-source and --without-source are mutually exclusive.");
1131
1284
  const [minimum, maximum] = counts[result.path]!;
1285
+ if (result.path === "profile" && flags.swarm !== undefined)
1286
+ syntax("Personal profile is account-wide; do not pass --swarm.");
1287
+ if (
1288
+ result.positional.length &&
1289
+ [
1290
+ "swarm status",
1291
+ "swarm update",
1292
+ "swarm resume",
1293
+ "swarm profile",
1294
+ "swarm export",
1295
+ "swarm members",
1296
+ ].includes(result.path)
1297
+ )
1298
+ syntax(
1299
+ `Swarm target positionals are no longer supported. Use ipab --swarm URL_OR_ALIAS ${result.path} instead.`,
1300
+ );
1132
1301
  if (result.positional.length < minimum || result.positional.length > maximum)
1133
1302
  syntax(`Invalid arguments.\n${help(result.path)}`);
1134
1303
  if (
@@ -1147,10 +1316,26 @@ export function parse(argv: readonly string[]): Parsed {
1147
1316
  syntax("history remove requires explicit IDs OR filters, not both.");
1148
1317
  }
1149
1318
  // Validate syntactic values before state access, let alone a backend connection.
1150
- if (result.path.startsWith("pin ") && result.path !== "pin list") {
1151
- pinName(result.positional[0]!, result.path === "pin show");
1152
- if (result.path === "pin add") exactCid(result.positional[1]!);
1153
- if (result.path === "pin rename") pinName(result.positional[1]!);
1319
+ if (["pin", "unpin", "pin show"].includes(result.path)) {
1320
+ const reference = result.positional[0]!;
1321
+ if (reference.startsWith("builtin:") && result.path !== "pin show")
1322
+ syntax(
1323
+ "Packaged builtin references are read-only; they cannot be pinned or unpinned.",
1324
+ );
1325
+ if (
1326
+ !(result.path === "pin show" && reference.startsWith("builtin:")) &&
1327
+ !parseNameReference(reference)
1328
+ )
1329
+ exactCid(reference);
1330
+ }
1331
+ if (result.path === "publish") {
1332
+ formalName(result.positional[0]!);
1333
+ if (typeof result.options.expect === "string")
1334
+ exactCid(result.options.expect);
1335
+ if (result.options.expect && result.options.snapshot)
1336
+ syntax(
1337
+ "--snapshot is initial-only and cannot be combined with --expect.",
1338
+ );
1154
1339
  }
1155
1340
  if (result.path.startsWith("config ") && result.positional[0]) {
1156
1341
  if (
@@ -1172,6 +1357,8 @@ export function parse(argv: readonly string[]): Parsed {
1172
1357
  parseValue("history.limit", result.options.limit, true);
1173
1358
  if (result.options.output === "-")
1174
1359
  syntax("CAR output requires a file path; binary stdout is not supported.");
1360
+ if (result.path === "doctor" && result.options.yes && !result.options.fix)
1361
+ syntax("doctor --yes requires --fix.");
1175
1362
  return result;
1176
1363
  }
1177
1364
 
@@ -1204,28 +1391,18 @@ async function performCli(
1204
1391
  }
1205
1392
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
1206
1393
  syntax("Non-interactive history remove requires --yes.");
1207
- if (parsed.path === "setup") {
1208
- if (
1209
- !parsed.options.yes &&
1210
- (!io.tty ||
1211
- !(await io.confirm(
1212
- "Install checksum-verified Kubo and initialize/reuse the protected HOME identity? No daemon will be contacted or started.",
1213
- )))
1214
- )
1215
- throw new HostError(
1216
- "Setup requires explicit --yes or interactive confirmation.",
1217
- );
1394
+ if (parsed.path === "doctor") {
1218
1395
  const controller = new AbortController();
1219
1396
  const interrupt = () => {
1220
- controller.abort(new HostError("Setup interrupted.", 130, "ABORTED"));
1397
+ controller.abort(new HostError("Doctor interrupted.", 130, "ABORTED"));
1221
1398
  };
1222
1399
  const terminate = () => {
1223
- controller.abort(new HostError("Setup terminated.", 143, "ABORTED"));
1400
+ controller.abort(new HostError("Doctor terminated.", 143, "ABORTED"));
1224
1401
  };
1225
1402
  process.once("SIGINT", interrupt);
1226
1403
  process.once("SIGTERM", terminate);
1227
1404
  try {
1228
- const result = await setupDevice(
1405
+ const result = await doctorDevice(
1229
1406
  stateLocation(parsed.flags, env).path,
1230
1407
  env,
1231
1408
  {
@@ -1233,17 +1410,14 @@ async function performCli(
1233
1410
  io.err(text, progress);
1234
1411
  },
1235
1412
  signal: controller.signal,
1236
- ...(typeof parsed.options["kubo-archive"] === "string"
1237
- ? { archive: parsed.options["kubo-archive"] }
1238
- : {}),
1413
+ fix: Boolean(parsed.options.fix),
1414
+ yes: Boolean(parsed.options.yes),
1415
+ tty: io.tty,
1416
+ confirm: (text, signal) => io.confirm(text, signal),
1239
1417
  },
1240
1418
  );
1241
- io.out(
1242
- parsed.flags.json
1243
- ? JSON.stringify(result)
1244
- : `Kubo ${result.kuboVersion}: ${result.binary}\nAccount fingerprint: ${result.fingerprint}\nReady. Nodes start only when a Swarm is used.`,
1245
- );
1246
- return 0;
1419
+ io.out(parsed.flags.json ? JSON.stringify(result) : doctorText(result));
1420
+ return result.ready ? 0 : 1;
1247
1421
  } finally {
1248
1422
  process.removeListener("SIGINT", interrupt);
1249
1423
  process.removeListener("SIGTERM", terminate);
@@ -1270,7 +1444,8 @@ async function performCli(
1270
1444
  const items = effectiveConfig(
1271
1445
  state.config({
1272
1446
  includeSecrets:
1273
- parsed.path !== "swarm status" || Boolean(parsed.options.local),
1447
+ !["swarm members", "profile", "swarm status"].includes(parsed.path) ||
1448
+ Boolean(parsed.options.local),
1274
1449
  }),
1275
1450
  parsed.flags,
1276
1451
  env,
@@ -1286,6 +1461,13 @@ async function performCli(
1286
1461
  value("swarm.default") === null
1287
1462
  ? undefined
1288
1463
  : String(value("swarm.default"));
1464
+ const requireSwarm = () => {
1465
+ if (!selectedSwarm)
1466
+ syntax(
1467
+ "Select a Swarm with ipab --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS.",
1468
+ );
1469
+ return selectedSwarm;
1470
+ };
1289
1471
  const swarmContext = (): SwarmContext => ({
1290
1472
  get store() {
1291
1473
  return store!;
@@ -1327,7 +1509,159 @@ async function performCli(
1327
1509
  source: current.source,
1328
1510
  };
1329
1511
  };
1512
+ if (parsed.path === "open" || parsed.path.startsWith("register ")) {
1513
+ if (state.legacyRegistrationCount)
1514
+ io.err(
1515
+ `Legacy User registrations are inactive. ${state.legacyRegistrationCount} entries are preserved in legacy_user_registrations in the state database under ${state.directory}; nothing was uploaded or deleted. Review the archived values and explicitly run ipab register set TYPE_CID APP_CID --swarm URL_OR_ALIAS [-- TEMPLATE...] to publish only intended associations.`,
1516
+ );
1517
+ }
1518
+ if (state.legacyPinCount)
1519
+ io.err(
1520
+ `Legacy local pin names are inactive: ${state.legacyPinCount} records are preserved in legacy_named_pins under ${state.directory}. Retention and original Store owners are unchanged; inspect ipab pin list and release intended archived holders with ipab unpin EXACT_CID.`,
1521
+ );
1522
+ if (parsed.path.startsWith("register ")) {
1523
+ const references = parsed.registrySwarms?.length
1524
+ ? parsed.registrySwarms
1525
+ : selectedSwarm
1526
+ ? [selectedSwarm]
1527
+ : [];
1528
+ if (!references.length)
1529
+ throw new HostError(
1530
+ "Register requires a selected Swarm. Pass --swarm URL_OR_ALIAS (repeat for multiple Swarms), or save a default with ipab swarm use URL_OR_ALIAS.",
1531
+ );
1532
+ const targets = [
1533
+ ...new Set(
1534
+ references.map((reference) => state!.resolveSwarm(reference)),
1535
+ ),
1536
+ ];
1537
+ const schema = first
1538
+ ? state.resolve(schemaAlias(first), true)
1539
+ : undefined;
1540
+ const results: (
1541
+ | {
1542
+ items: Association[];
1543
+ }
1544
+ | {
1545
+ association: Association;
1546
+ }
1547
+ | {
1548
+ removed: string[];
1549
+ }
1550
+ )[] = [];
1551
+ const completed: string[] = [];
1552
+ const human: string[] = [];
1553
+ store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1554
+ for (const configUrl of targets) {
1555
+ const context = swarmContext();
1556
+ try {
1557
+ if (parsed.path === "register list") {
1558
+ const items = await swarmRegistrations(context, configUrl);
1559
+ results.push({ items });
1560
+ human.push(
1561
+ `${configUrl}\n${table(
1562
+ ["SCHEMA CID", "APP CID", "ARGV"],
1563
+ items.map((item) => [
1564
+ item.schemaCid,
1565
+ item.appCid,
1566
+ JSON.stringify(item.argv),
1567
+ ]),
1568
+ "No associations.",
1569
+ )}`,
1570
+ );
1571
+ } else if (parsed.path === "register set") {
1572
+ const appCid = parseNameReference(second!)
1573
+ ? (
1574
+ await resolveReference(
1575
+ context,
1576
+ second!,
1577
+ configUrl,
1578
+ (reference) => state!.resolve(reference),
1579
+ )
1580
+ ).cid
1581
+ : state.resolve(second!);
1582
+ const association = await setSwarmAssociation(
1583
+ context,
1584
+ configUrl,
1585
+ createAssociation(schema!, appCid, parsed.template ?? ["%"]),
1586
+ Boolean(parsed.options.replace),
1587
+ );
1588
+ results.push({ association });
1589
+ human.push(
1590
+ `${configUrl}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`,
1591
+ );
1592
+ } else {
1593
+ const removed = await removeSwarmAssociation(
1594
+ context,
1595
+ configUrl,
1596
+ schema!,
1597
+ );
1598
+ results.push({ removed: [removed] });
1599
+ human.push(`${configUrl}: removed association for ${removed}.`);
1600
+ }
1601
+ completed.push(configUrl);
1602
+ } catch (cause) {
1603
+ throw new HostError(
1604
+ `Registry operation failed for ${configUrl}: ${message(cause)}. Completed Swarms: ${completed.length ? completed.join(", ") : "(none)"}. Multiple Swarm edits are not atomic.`,
1605
+ cause instanceof HostError ? cause.exitCode : 1,
1606
+ cause instanceof HostError ? cause.code : "REGISTRY_FAILED",
1607
+ "publication",
1608
+ );
1609
+ } finally {
1610
+ await context.finishRead?.();
1611
+ }
1612
+ }
1613
+ emit(
1614
+ {
1615
+ swarms: results.map((result, index) => ({
1616
+ configUrl: targets[index],
1617
+ ...result,
1618
+ })),
1619
+ },
1620
+ human.join("\n\n"),
1621
+ );
1622
+ return 0;
1623
+ }
1330
1624
  switch (parsed.path) {
1625
+ case "profile": {
1626
+ const context = swarmContext();
1627
+ readContext = context;
1628
+ const changes = {
1629
+ ...(typeof parsed.options.name === "string"
1630
+ ? { name: parsed.options.name }
1631
+ : {}),
1632
+ ...(typeof parsed.options.description === "string"
1633
+ ? { description: parsed.options.description }
1634
+ : {}),
1635
+ };
1636
+ if (!Object.keys(changes).length) {
1637
+ const profile = await accountProfile(context);
1638
+ emit(
1639
+ { profile, localPersisted: profile.updatedAt !== null },
1640
+ `Name: ${printable(profile.name)}\nDescription: ${printable(profile.description)}\nPublic key: ${profile.publicKey}`,
1641
+ );
1642
+ } else {
1643
+ const result = await updateAccountProfile(context, changes);
1644
+ emit(
1645
+ result,
1646
+ [
1647
+ `Name: ${printable(result.profile.name)}`,
1648
+ `Description: ${printable(result.profile.description)}`,
1649
+ "Personal profile saved locally.",
1650
+ ...result.swarms.map(
1651
+ (entry) =>
1652
+ `${entry.configUrl}: ${entry.synchronized ? "synchronized" : `FAILED: ${entry.error}`}`,
1653
+ ),
1654
+ ].join("\n"),
1655
+ );
1656
+ if (result.swarms.some((entry) => !entry.synchronized)) {
1657
+ io.err(
1658
+ "Profile saved locally, but some Swarms failed. Retry the profile update or normally activate each failed membership to synchronize it.",
1659
+ );
1660
+ return 1;
1661
+ }
1662
+ }
1663
+ break;
1664
+ }
1331
1665
  case "swarm list": {
1332
1666
  const result = { swarms: state.swarms(), ...selection() };
1333
1667
  emit(
@@ -1388,15 +1722,49 @@ async function performCli(
1388
1722
  case "swarm exclude":
1389
1723
  case "swarm resume":
1390
1724
  case "swarm profile":
1725
+ case "swarm members":
1391
1726
  case "swarm status":
1392
1727
  case "publish":
1728
+ case "pin":
1393
1729
  case "get": {
1394
1730
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1395
1731
  const context = swarmContext();
1732
+ readContext = context;
1733
+ if (parsed.path === "pin") {
1734
+ io.err("Fetching, verifying and retaining content...");
1735
+ const result = await pinNameSubscription(
1736
+ context,
1737
+ first!,
1738
+ selectedSwarm,
1739
+ );
1740
+ store = context.store;
1741
+ emit(
1742
+ result,
1743
+ `${result.reference} → ${result.cid}\nStatus: ${result.freshness}`,
1744
+ );
1745
+ break;
1746
+ }
1747
+ if (parsed.path === "swarm members") {
1748
+ const result = await swarmMembers(context, requireSwarm());
1749
+ emit(
1750
+ result,
1751
+ table(
1752
+ ["NAME", "DESCRIPTION", "ROLE", "PUBLIC KEY"],
1753
+ result.members.map((member) => [
1754
+ member.name,
1755
+ member.description,
1756
+ member.role,
1757
+ member.publicKey,
1758
+ ]),
1759
+ "No members.",
1760
+ ),
1761
+ );
1762
+ break;
1763
+ }
1396
1764
  if (parsed.path === "swarm export") {
1397
1765
  const id = await exportRequest(
1398
1766
  context,
1399
- state.resolveSwarm(first!),
1767
+ requireSwarm(),
1400
1768
  String(parsed.options.output ?? ""),
1401
1769
  );
1402
1770
  emit({ id }, id);
@@ -1407,13 +1775,7 @@ async function performCli(
1407
1775
  parsed.path,
1408
1776
  )
1409
1777
  ) {
1410
- const url =
1411
- parsed.path === "swarm exclude"
1412
- ? selectedSwarm
1413
- : first
1414
- ? state.resolveSwarm(first)
1415
- : selectedSwarm;
1416
- if (!url) syntax("Select a Swarm configuration URL or alias.");
1778
+ const url = requireSwarm();
1417
1779
  if (parsed.path === "swarm exclude") {
1418
1780
  if (!parsed.options.yes)
1419
1781
  syntax("Member removal is irreversible; --yes required.");
@@ -1422,9 +1784,6 @@ async function performCli(
1422
1784
  await resumeRemoval(context, url);
1423
1785
  else {
1424
1786
  const profile = await updateProfile(context, url, {
1425
- ...(typeof parsed.options.name === "string"
1426
- ? { name: parsed.options.name }
1427
- : {}),
1428
1787
  ...(typeof parsed.options.address === "string"
1429
1788
  ? { addresses: [parsed.options.address] }
1430
1789
  : {}),
@@ -1441,11 +1800,7 @@ async function performCli(
1441
1800
  break;
1442
1801
  }
1443
1802
  if (parsed.path === "swarm update") {
1444
- const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1445
- if (!cid)
1446
- syntax(
1447
- "swarm update requires a registered alias, configuration URL or current swarm.",
1448
- );
1803
+ const cid = requireSwarm();
1449
1804
  const result = await updateSwarm(context, cid, {
1450
1805
  ...(typeof parsed.options.name === "string"
1451
1806
  ? { name: parsed.options.name }
@@ -1483,35 +1838,23 @@ async function performCli(
1483
1838
  break;
1484
1839
  }
1485
1840
  if (parsed.path === "search") {
1486
- const source = items.find(
1487
- (item) => item.key === "swarm.default",
1488
- )!.source;
1489
- const limited = parsed.options.current || source === "flag";
1490
- if (limited && !selectedSwarm)
1491
- syntax(
1492
- "Search of the current swarm requires --swarm or swarm.default.",
1493
- );
1494
1841
  const registrations = state.swarms();
1495
- const scope = limited
1496
- ? [
1842
+ const scope = parsed.options.all
1843
+ ? registrations
1844
+ : [
1497
1845
  {
1498
- cid: selectedSwarm!,
1846
+ cid: requireSwarm(),
1499
1847
  alias:
1500
1848
  registrations.find((entry) => entry.cid === selectedSwarm)
1501
1849
  ?.alias ?? null,
1502
1850
  },
1503
- ]
1504
- : registrations;
1851
+ ];
1505
1852
  const result = await searchNames(context, first!, scope);
1506
1853
  emit(result, formatSearchResults(result.matches));
1507
1854
  break;
1508
1855
  }
1509
1856
  if (parsed.path === "swarm status") {
1510
- const cid = first ? state.resolveSwarm(first) : selectedSwarm;
1511
- if (!cid)
1512
- syntax(
1513
- "swarm status requires a configuration URL or swarm.default.",
1514
- );
1857
+ const cid = requireSwarm();
1515
1858
  const local = Boolean(parsed.options.local);
1516
1859
  const { head, config } = local
1517
1860
  ? await swarmHeader(context, cid, true)
@@ -1569,7 +1912,6 @@ async function performCli(
1569
1912
  break;
1570
1913
  }
1571
1914
  if (parsed.path === "get") {
1572
- readContext = context;
1573
1915
  const localCid = /^(ipab|name):/i.test(first!)
1574
1916
  ? undefined
1575
1917
  : state.resolve(first!);
@@ -1613,6 +1955,11 @@ async function performCli(
1613
1955
  } finally {
1614
1956
  await source.close();
1615
1957
  }
1958
+ try {
1959
+ await context.finishRead?.();
1960
+ } finally {
1961
+ readContext = undefined;
1962
+ }
1616
1963
  const closing = store;
1617
1964
  store = undefined;
1618
1965
  await closeStore(closing, undefined);
@@ -1622,6 +1969,7 @@ async function performCli(
1622
1969
  break;
1623
1970
  }
1624
1971
  let cid: string;
1972
+ let contentCid: string | undefined;
1625
1973
  if (parsed.path === "swarm create") {
1626
1974
  cid = await createSwarm(context, {
1627
1975
  ...(typeof parsed.options.service === "string"
@@ -1638,12 +1986,8 @@ async function performCli(
1638
1986
  ? { alias: parsed.options.alias }
1639
1987
  : {}),
1640
1988
  });
1641
- } else if (parsed.path === "swarm request")
1642
- cid = await requestMembership(context, first!, {
1643
- ownerFingerprint: String(parsed.options["owner-fingerprint"] ?? ""),
1644
- ...(typeof parsed.options.name === "string"
1645
- ? { name: parsed.options.name }
1646
- : {}),
1989
+ } else if (parsed.path === "swarm request") {
1990
+ const result = await requestMembership(context, first!, {
1647
1991
  ...(typeof parsed.options.alias === "string"
1648
1992
  ? { alias: parsed.options.alias }
1649
1993
  : {}),
@@ -1651,8 +1995,41 @@ async function performCli(
1651
1995
  ? { output: parsed.options.output }
1652
1996
  : {}),
1653
1997
  });
1654
- else if (parsed.path === "swarm approve") {
1655
- const request = await verifiedRequest(first!);
1998
+ store = context.store;
1999
+ io.err(
2000
+ `Owner fingerprint: ${result.ownerFingerprint}\nVerify this fingerprint through an independent trusted channel before manually sending the Request file to the Owner.`,
2001
+ );
2002
+ if (result.file === undefined)
2003
+ io.out(JSON.stringify(result.request, null, 2));
2004
+ else {
2005
+ io.err(`Request saved to: ${result.file}`);
2006
+ if (parsed.flags.json)
2007
+ emit(
2008
+ {
2009
+ file: result.file,
2010
+ requestId: result.requestId,
2011
+ ownerFingerprint: result.ownerFingerprint,
2012
+ },
2013
+ "",
2014
+ );
2015
+ }
2016
+ break;
2017
+ } else if (parsed.path === "swarm approve") {
2018
+ const selected = requireSwarm();
2019
+ if (first === "-" && !parsed.options.yes)
2020
+ syntax(
2021
+ "Reading a Request from stdin requires explicit --yes; no interactive confirmation is available.",
2022
+ );
2023
+ const request =
2024
+ first === "-"
2025
+ ? await verifiedRequestStream(
2026
+ (io.requestInput ?? processIO.requestInput!)(),
2027
+ )
2028
+ : await verifiedRequest(first!);
2029
+ if (request.configUrl !== selected)
2030
+ syntax(
2031
+ `Request belongs to ${request.configUrl}, not the selected Swarm. Use ipab --swarm ${request.configUrl} swarm approve REQUEST_FILE --yes.`,
2032
+ );
1656
2033
  io.err(await membershipRequestSummary(request));
1657
2034
  if (
1658
2035
  !parsed.options.yes &&
@@ -1668,17 +2045,11 @@ async function performCli(
1668
2045
  again: Boolean(parsed.options.again),
1669
2046
  });
1670
2047
  } else {
1671
- let content: string;
1672
- if (first!.toLowerCase().endsWith(".car"))
1673
- content = (
1674
- await importBundle(first!, () => Promise.resolve(store!))
1675
- ).cid;
1676
- else content = exactCid(first!);
2048
+ const content = await publicationSource(second!, store);
2049
+ contentCid = content;
1677
2050
  cid = await publish(context, content, {
1678
2051
  ...(selectedSwarm ? { swarm: selectedSwarm } : {}),
1679
- ...(typeof parsed.options.name === "string"
1680
- ? { name: parsed.options.name }
1681
- : {}),
2052
+ name: first!,
1682
2053
  ...(typeof parsed.options.expect === "string"
1683
2054
  ? { expect: parsed.options.expect }
1684
2055
  : {}),
@@ -1690,12 +2061,14 @@ async function performCli(
1690
2061
  io.err(
1691
2062
  `Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config({ includeSecrets: false })["swarm.default"] ?? "(none)"}.`,
1692
2063
  );
2064
+ if (contentCid)
2065
+ io.err(
2066
+ `Locally protected payload: ${contentCid}. Use ipab unpin ${contentCid} to release this CID pin only; Name subscriptions and publication/history owners remain. --snapshot links payloads directly into retained publication history, so unpin cannot release that protection.`,
2067
+ );
1693
2068
  emit(
1694
- parsed.path === "swarm request"
1695
- ? { requestId: cid }
1696
- : parsed.path === "swarm create" || parsed.path === "swarm approve"
1697
- ? { configUrl: cid }
1698
- : { cid },
2069
+ parsed.path === "swarm create" || parsed.path === "swarm approve"
2070
+ ? { configUrl: cid }
2071
+ : { cid, ...(contentCid ? { contentCid } : {}) },
1699
2072
  cid,
1700
2073
  );
1701
2074
  break;
@@ -1851,7 +2224,7 @@ async function performCli(
1851
2224
  result.files.includes("ipab.json"))
1852
2225
  )
1853
2226
  io.err(
1854
- `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.`,
2227
+ `Next: install declared dependencies in ${JSON.stringify(result.directory)}; if your template does not declare @ipab/cli, add or link it as a development dependency. Run pnpm build to prepare and package the App. Root ipab build does not compile.`,
1855
2228
  );
1856
2229
  else if (result.files.includes(".bundle.yaml"))
1857
2230
  io.err(
@@ -1878,128 +2251,74 @@ async function performCli(
1878
2251
  break;
1879
2252
  }
1880
2253
  case "pin list": {
1881
- const type =
1882
- typeof parsed.options.type === "string"
1883
- ? state.resolve(parsed.options.type, true)
1884
- : undefined;
1885
- const pins = state.pins();
1886
- const listed = pins
1887
- .filter(
1888
- (pin) => pin.status === "ready" && pin.metadata?.kind === "bundle",
1889
- )
1890
- .map(pinDetails)
1891
- .filter((pin) => type === undefined || pin.schemaCid === type);
1892
- const invalid = pins
1893
- .filter(
1894
- (pin) => pin.status === "ready" && pin.metadata?.kind !== "bundle",
1895
- )
1896
- .map(({ name, cid, metadata }) => ({
1897
- name,
1898
- cid,
1899
- kind: metadata?.kind,
1900
- reason:
1901
- "Not a Bundle pin; retention is preserved. Use pin delete to release it.",
1902
- }));
1903
- const pending = pins
1904
- .filter((pin) => pin.status !== "ready")
1905
- .map(({ name, cid, status }) => ({ name, cid, status }));
1906
- if (pending.length)
1907
- io.err(
1908
- `Unfinished pin operations (not usable pins): ${JSON.stringify(pending)}. Retry pin add/delete.`,
1909
- );
1910
- if (invalid.length)
1911
- io.err(
1912
- `Legacy non-Bundle pins (not usable pins): ${JSON.stringify(invalid)}. Retention is unchanged; delete explicitly and wrap content in a Bundle before pinning again.`,
1913
- );
2254
+ const listed = state.contentPins();
2255
+ const archived = state.archivedPins();
2256
+ const builtins = state.pins().map(pinDetails);
1914
2257
  emit(
1915
- { items: listed, pending, invalid },
2258
+ { items: listed, builtins, archived },
1916
2259
  table(
1917
- ["NAME", "CID", "KIND", "TITLE", "TYPE CID", "SOURCE"],
1918
- listed.map((pin) => [
1919
- pin.name,
1920
- pin.cid,
1921
- pin.kind,
1922
- pin.title,
1923
- pin.schemaCid,
1924
- pin.builtin ? "built-in (read-only)" : "user",
1925
- ]),
1926
- "No named pins.",
2260
+ ["REFERENCE", "CID", "STATUS", "SOURCE"],
2261
+ [
2262
+ ...listed.map((pin) => [
2263
+ pin.reference,
2264
+ pin.cid ?? "(none)",
2265
+ `${pin.status}/${pin.freshness}${pin.error ? `: ${pin.error}` : ""}`,
2266
+ pin.swarm ? "following shared Name" : "fixed CID",
2267
+ ]),
2268
+ ...builtins.map((pin) => [
2269
+ pin.name,
2270
+ pin.cid,
2271
+ "read-only",
2272
+ "built-in",
2273
+ ]),
2274
+ ...archived.map((pin) => [
2275
+ pin.cid,
2276
+ pin.cid,
2277
+ pin.status,
2278
+ `inactive archive (${pin.name}); unpin exact CID`,
2279
+ ]),
2280
+ ],
2281
+ "No pins.",
1927
2282
  ),
1928
2283
  );
1929
2284
  break;
1930
2285
  }
1931
- case "pin add": {
1932
- io.err("Fetching, verifying and retaining content in Store...");
1933
- const result = await addPin(
1934
- state,
1935
- first!,
1936
- second!,
1937
- await storeConfiguration(value("store.gateway")),
1938
- );
2286
+ case "unpin": {
2287
+ const canonical = pinReference(state, first!, selectedSwarm);
2288
+ const result = await unpin(state, canonical.reference);
1939
2289
  emit(
1940
2290
  result,
1941
- `${result.name} → ${result.cid}\nTitle: ${printable(result.title)}\nType CID: ${result.schemaCid}`,
1942
- );
1943
- break;
1944
- }
1945
- case "pin delete": {
1946
- const result = await deletePin(state, first!);
1947
- emit(
1948
- result,
1949
- `Deleted ${first}; released only its retention responsibility. No blocks deleted or GC requested.`,
2291
+ `Unpinned ${canonical.reference}; released only its saved retention responsibility. No blocks deleted or GC requested.`,
1950
2292
  );
1951
2293
  break;
1952
2294
  }
1953
2295
  case "pin show": {
1954
- const pin = state.pin(first!);
1955
- if (!pin)
2296
+ const builtin = first!.startsWith("builtin:")
2297
+ ? state.pin(first!)
2298
+ : undefined;
2299
+ const canonical = builtin
2300
+ ? undefined
2301
+ : pinReference(state, first!, selectedSwarm);
2302
+ const pin = canonical
2303
+ ? state.contentPin(canonical.reference)
2304
+ : undefined;
2305
+ const archived = canonical
2306
+ ? state
2307
+ .archivedPins()
2308
+ .filter((pin) => pin.cid === canonical.reference)
2309
+ : [];
2310
+ if (!pin && !builtin && !archived.length)
1956
2311
  throw new HostError(
1957
2312
  `Pin "${first}" does not exist. Run ipab pin list.`,
1958
2313
  );
1959
- const result = pinDetails(pin);
1960
- emit(
1961
- result,
1962
- `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)"}`,
1963
- );
1964
- break;
1965
- }
1966
- case "pin rename": {
1967
- const result = renamePin(state, first!, second!);
1968
- emit(result, `${first} → ${result.name} (${result.cid})`);
1969
- break;
1970
- }
1971
- case "register list": {
1972
- const associations = state.registrations();
1973
- emit(
1974
- { items: associations },
1975
- table(
1976
- ["SCHEMA CID", "APP CID", "ARGV"],
1977
- associations.map((association) => [
1978
- association.schemaCid,
1979
- association.appCid,
1980
- JSON.stringify(association.argv),
1981
- ]),
1982
- "No associations.",
1983
- ),
1984
- );
1985
- break;
1986
- }
1987
- case "register set": {
1988
- const association = state.setAssociation(
1989
- schemaAlias(first!),
1990
- second!,
1991
- parsed.template ?? ["%"],
1992
- Boolean(parsed.options.replace),
1993
- );
1994
- emit(
1995
- association,
1996
- `${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`,
1997
- );
1998
- break;
1999
- }
2000
- case "register remove": {
2001
- const removed = state.removeAssociation(schemaAlias(first!));
2002
- emit({ removed: [removed] }, `Removed association for ${removed}.`);
2314
+ const result = builtin
2315
+ ? pinDetails(builtin)
2316
+ : {
2317
+ pin: pin ?? null,
2318
+ roots: pin ? state.hold(pin.owner)?.roots : [],
2319
+ archived,
2320
+ };
2321
+ emit(result, JSON.stringify(result, null, 2));
2003
2322
  break;
2004
2323
  }
2005
2324
  case "config get": {
@@ -2127,6 +2446,15 @@ async function performCli(
2127
2446
  }
2128
2447
  case "exec":
2129
2448
  case "open": {
2449
+ const named =
2450
+ parsed.path === "open" ? parseNameReference(first!) : undefined;
2451
+ const registrySwarm = named?.swarm
2452
+ ? state.resolveSwarm(named.swarm)
2453
+ : selectedSwarm;
2454
+ if (parsed.path === "open" && !registrySwarm)
2455
+ throw new HostError(
2456
+ "Open requires a selected Swarm. Use ipab://URL_OR_ALIAS/PATH, pass --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS. To select an App directly, use ipab exec.",
2457
+ );
2130
2458
  if (parsed.options.log && !value("history.enabled"))
2131
2459
  throw new HostError(
2132
2460
  "Execution logging requires history.enabled=true.",
@@ -2134,6 +2462,7 @@ async function performCli(
2134
2462
  await recoverInactive(state);
2135
2463
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
2136
2464
  const context = swarmContext();
2465
+ readContext = context;
2137
2466
  const target = (
2138
2467
  await resolveReference(
2139
2468
  context,
@@ -2141,6 +2470,7 @@ async function performCli(
2141
2470
  selectedSwarm,
2142
2471
  (reference) => state!.resolve(reference),
2143
2472
  Boolean(parsed.options.raw),
2473
+ "local-first",
2144
2474
  )
2145
2475
  ).cid;
2146
2476
  store = context.store;
@@ -2164,8 +2494,13 @@ async function performCli(
2164
2494
  ? state!.resolveSwarm(preferredSwarm)
2165
2495
  : selectedSwarm;
2166
2496
  const resolve = (source: string | undefined) =>
2167
- resolveReference(lookup, reference, source, (input) =>
2168
- state!.resolve(input),
2497
+ resolveReference(
2498
+ lookup,
2499
+ reference,
2500
+ source,
2501
+ (input) => state!.resolve(input),
2502
+ false,
2503
+ "local-first",
2169
2504
  );
2170
2505
  let resolved;
2171
2506
  try {
@@ -2191,7 +2526,11 @@ async function performCli(
2191
2526
  signal.throwIfAborted();
2192
2527
  return { ...resolved, ...(swarm ? { swarm } : {}) };
2193
2528
  } finally {
2194
- await lookup.store.close();
2529
+ try {
2530
+ await lookup.finishRead?.();
2531
+ } finally {
2532
+ await lookup.store.close();
2533
+ }
2195
2534
  }
2196
2535
  };
2197
2536
  let appCid: string;
@@ -2207,10 +2546,32 @@ async function performCli(
2207
2546
  try {
2208
2547
  const content = await validatedBundle(root, store, owner);
2209
2548
  const schema = content.schemaKey;
2210
- const association = state.association(schema);
2549
+ let association: Association | undefined;
2550
+ if (registrySwarm) {
2551
+ const lookup: SwarmContext = {
2552
+ ...swarmContext(),
2553
+ store: new IpfsStore(
2554
+ await storeConfiguration(value("store.gateway")),
2555
+ ),
2556
+ };
2557
+ try {
2558
+ association = await swarmAssociation(
2559
+ lookup,
2560
+ registrySwarm,
2561
+ schema,
2562
+ "local-first",
2563
+ );
2564
+ } finally {
2565
+ try {
2566
+ await lookup.finishRead?.();
2567
+ } finally {
2568
+ await lookup.store.close();
2569
+ }
2570
+ }
2571
+ }
2211
2572
  if (!association)
2212
2573
  throw new HostError(
2213
- `No App registered for Schema ${schema}. Use ipab register set or ipab exec.`,
2574
+ `No App registered for Schema ${schema} in Swarm ${registrySwarm}. Use ipab register set ${schema} APP_CID --swarm ${registrySwarm} or ipab exec.`,
2214
2575
  );
2215
2576
  appCid = association.appCid;
2216
2577
  appArgv = association.argv.map((argument) =>
@@ -2268,8 +2629,11 @@ async function performCli(
2268
2629
  return error instanceof HostError ? error.exitCode : 1;
2269
2630
  } finally {
2270
2631
  try {
2271
- await readContext?.finishRead?.();
2272
- await closeStore(store, appExitCode);
2632
+ try {
2633
+ await readContext?.finishRead?.();
2634
+ } finally {
2635
+ await closeStore(store, appExitCode);
2636
+ }
2273
2637
  } finally {
2274
2638
  state?.close();
2275
2639
  }