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

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 (157) hide show
  1. package/README.md +128 -22
  2. package/dist/app-authoring.d.ts +5 -0
  3. package/dist/app-authoring.d.ts.map +1 -1
  4. package/dist/app-authoring.js +4 -1
  5. package/dist/app-authoring.js.map +1 -1
  6. package/dist/app-templates.d.ts +0 -1
  7. package/dist/app-templates.d.ts.map +1 -1
  8. package/dist/app-templates.js +6 -45
  9. package/dist/app-templates.js.map +1 -1
  10. package/dist/builtins/skill.ipab.car +0 -0
  11. package/dist/builtins/template.bundle-viewer.car +0 -0
  12. package/dist/builtins/template.check.car +0 -0
  13. package/dist/builtins/template.node.car +0 -0
  14. package/dist/builtins/template.web-app.car +0 -0
  15. package/dist/builtins.d.ts.map +1 -1
  16. package/dist/builtins.js +1 -39
  17. package/dist/builtins.js.map +1 -1
  18. package/dist/cli.d.ts +4 -1
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/cli.js +934 -336
  21. package/dist/cli.js.map +1 -1
  22. package/dist/content-provider.d.ts +1 -1
  23. package/dist/content-provider.d.ts.map +1 -1
  24. package/dist/content-provider.js +4 -3
  25. package/dist/content-provider.js.map +1 -1
  26. package/dist/context.d.ts +16 -1
  27. package/dist/context.d.ts.map +1 -1
  28. package/dist/context.js +20 -10
  29. package/dist/context.js.map +1 -1
  30. package/dist/doctor.d.ts +29 -0
  31. package/dist/doctor.d.ts.map +1 -0
  32. package/dist/doctor.js +576 -0
  33. package/dist/doctor.js.map +1 -0
  34. package/dist/identity.d.ts +1 -1
  35. package/dist/identity.d.ts.map +1 -1
  36. package/dist/identity.js +9 -9
  37. package/dist/identity.js.map +1 -1
  38. package/dist/ipc.d.ts +2 -2
  39. package/dist/ipc.d.ts.map +1 -1
  40. package/dist/ipc.js +44 -12
  41. package/dist/ipc.js.map +1 -1
  42. package/dist/kubo-install.d.ts +18 -1
  43. package/dist/kubo-install.d.ts.map +1 -1
  44. package/dist/kubo-install.js +424 -61
  45. package/dist/kubo-install.js.map +1 -1
  46. package/dist/kubo-release.d.ts +19 -0
  47. package/dist/kubo-release.d.ts.map +1 -1
  48. package/dist/kubo-release.js +164 -0
  49. package/dist/kubo-release.js.map +1 -1
  50. package/dist/kubo.d.ts +1 -0
  51. package/dist/kubo.d.ts.map +1 -1
  52. package/dist/kubo.js +102 -96
  53. package/dist/kubo.js.map +1 -1
  54. package/dist/pins.d.ts +15 -17
  55. package/dist/pins.d.ts.map +1 -1
  56. package/dist/pins.js +144 -106
  57. package/dist/pins.js.map +1 -1
  58. package/dist/publish-source.d.ts +3 -0
  59. package/dist/publish-source.d.ts.map +1 -0
  60. package/dist/publish-source.js +85 -0
  61. package/dist/publish-source.js.map +1 -0
  62. package/dist/runtime.d.ts.map +1 -1
  63. package/dist/runtime.js +6 -5
  64. package/dist/runtime.js.map +1 -1
  65. package/dist/skill-definition.d.ts +6 -0
  66. package/dist/skill-definition.d.ts.map +1 -0
  67. package/dist/skill-definition.js +38 -0
  68. package/dist/skill-definition.js.map +1 -0
  69. package/dist/skill-source.d.ts +5 -0
  70. package/dist/skill-source.d.ts.map +1 -0
  71. package/dist/skill-source.js +12 -0
  72. package/dist/skill-source.js.map +1 -0
  73. package/dist/skills.d.ts +84 -0
  74. package/dist/skills.d.ts.map +1 -0
  75. package/dist/skills.js +736 -0
  76. package/dist/skills.js.map +1 -0
  77. package/dist/space.d.ts +15 -2
  78. package/dist/space.d.ts.map +1 -1
  79. package/dist/space.js +153 -3
  80. package/dist/space.js.map +1 -1
  81. package/dist/state-storage-windows.js +1 -1
  82. package/dist/state-storage.d.ts +3 -1
  83. package/dist/state-storage.d.ts.map +1 -1
  84. package/dist/state-storage.js +38 -7
  85. package/dist/state-storage.js.map +1 -1
  86. package/dist/state.d.ts +40 -6
  87. package/dist/state.d.ts.map +1 -1
  88. package/dist/state.js +208 -82
  89. package/dist/state.js.map +1 -1
  90. package/dist/swarm-envelope.d.ts +1 -0
  91. package/dist/swarm-envelope.d.ts.map +1 -1
  92. package/dist/swarm-envelope.js +12 -0
  93. package/dist/swarm-envelope.js.map +1 -1
  94. package/dist/swarm-files.d.ts +1 -1
  95. package/dist/swarm-files.d.ts.map +1 -1
  96. package/dist/swarm-files.js +2 -2
  97. package/dist/swarm-files.js.map +1 -1
  98. package/dist/swarm-meta.d.ts +17 -0
  99. package/dist/swarm-meta.d.ts.map +1 -0
  100. package/dist/swarm-meta.js +96 -0
  101. package/dist/swarm-meta.js.map +1 -0
  102. package/dist/swarm.d.ts +117 -8
  103. package/dist/swarm.d.ts.map +1 -1
  104. package/dist/swarm.js +1275 -131
  105. package/dist/swarm.js.map +1 -1
  106. package/dist/template-paths.d.ts +7 -0
  107. package/dist/template-paths.d.ts.map +1 -0
  108. package/dist/template-paths.js +23 -0
  109. package/dist/template-paths.js.map +1 -0
  110. package/dist/template-presentation.d.ts +20 -0
  111. package/dist/template-presentation.d.ts.map +1 -0
  112. package/dist/template-presentation.js +133 -0
  113. package/dist/template-presentation.js.map +1 -0
  114. package/dist/template-source.d.ts +2 -1
  115. package/dist/template-source.d.ts.map +1 -1
  116. package/dist/template-source.js +7 -1
  117. package/dist/template-source.js.map +1 -1
  118. package/dist/templates.d.ts +11 -0
  119. package/dist/templates.d.ts.map +1 -0
  120. package/dist/templates.js +53 -0
  121. package/dist/templates.js.map +1 -0
  122. package/package.json +7 -6
  123. package/src/app-authoring.ts +18 -2
  124. package/src/app-templates.ts +8 -72
  125. package/src/builtins.ts +2 -48
  126. package/src/cli.ts +1154 -387
  127. package/src/content-provider.ts +4 -2
  128. package/src/context.ts +45 -10
  129. package/src/doctor.ts +902 -0
  130. package/src/identity.ts +10 -10
  131. package/src/ipc.ts +63 -10
  132. package/src/kubo-install.ts +562 -78
  133. package/src/kubo-release.ts +213 -0
  134. package/src/kubo.ts +134 -106
  135. package/src/pins.ts +188 -126
  136. package/src/publish-source.ts +103 -0
  137. package/src/runtime.ts +6 -5
  138. package/src/skill-definition.ts +53 -0
  139. package/src/skill-source.ts +15 -0
  140. package/src/skills.ts +1005 -0
  141. package/src/space.ts +214 -5
  142. package/src/state-storage-windows.ts +1 -1
  143. package/src/state-storage.ts +53 -7
  144. package/src/state.ts +357 -98
  145. package/src/swarm-envelope.ts +14 -0
  146. package/src/swarm-files.ts +2 -1
  147. package/src/swarm-meta.ts +109 -0
  148. package/src/swarm.ts +1877 -175
  149. package/src/template-paths.ts +43 -0
  150. package/src/template-presentation.ts +151 -0
  151. package/src/template-source.ts +9 -2
  152. package/src/templates.ts +77 -0
  153. package/dist/setup.d.ts +0 -8
  154. package/dist/setup.d.ts.map +0 -1
  155. package/dist/setup.js +0 -27
  156. package/dist/setup.js.map +0 -1
  157. package/src/setup.ts +0 -34
package/src/cli.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createInterface } from "node:readline/promises";
2
- import { readFile } from "node:fs/promises";
2
+ import { lstat, readFile } from "node:fs/promises";
3
3
  import { ContentError, IpfsStore } from "@ipab/ipfs-store";
4
4
  import { ContentBundleError } from "@ipab/bundle";
5
5
  import { randomUUID } from "node:crypto";
@@ -26,12 +26,23 @@ 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";
30
- import { buildBundle, inspectBundle, importBundle } from "./authoring.js";
29
+ import {
30
+ createAssociation,
31
+ exactCid,
32
+ State,
33
+ type Association,
34
+ type RunRecord,
35
+ } from "./state.js";
36
+ import {
37
+ buildBundle,
38
+ inspectBundle,
39
+ importBundle,
40
+ nodeError,
41
+ } from "./authoring.js";
31
42
  import { initApp } from "./app-authoring.js";
32
43
  import { assembleBundle } from "./assembly.js";
33
44
  import { getBundle } from "./get.js";
34
- import { setupDevice } from "./setup.js";
45
+ import { doctorDevice, doctorText } from "./doctor.js";
35
46
  import { keyId } from "@ipab/bundle/pointer/crypto";
36
47
  import {
37
48
  createSwarm,
@@ -41,7 +52,11 @@ import {
41
52
  removeMember,
42
53
  resumeRemoval,
43
54
  updateProfile,
55
+ accountProfile,
56
+ updateAccountProfile,
57
+ swarmMembers,
44
58
  verifiedRequest,
59
+ verifiedRequestStream,
45
60
  membershipRequestSummary,
46
61
  swarmHeader,
47
62
  sharedSwarmStatus,
@@ -51,22 +66,42 @@ import {
51
66
  formatNameReference,
52
67
  resolveReference,
53
68
  parseNameReference,
69
+ formalName,
54
70
  publish,
71
+ pinNameSubscription,
72
+ pinReference,
73
+ swarmRegistrations,
74
+ swarmAssociation,
75
+ setSwarmAssociation,
76
+ removeSwarmAssociation,
77
+ resolveTemplateSelector,
78
+ templateName,
79
+ swarmTemplates,
80
+ setSwarmTemplate,
81
+ removeSwarmTemplate,
55
82
  type SwarmContext,
56
83
  } from "./swarm.js";
57
84
  import { schemaAlias } from "./app-definition.js";
58
- import { addPin, deletePin, pinDetails, renamePin } from "./pins.js";
85
+ import { unpin, pinDetails } from "./pins.js";
86
+ import { publicationSource } from "./publish-source.js";
87
+ import {
88
+ templateRenderExample,
89
+ templateOutputTree,
90
+ templateParameterRows,
91
+ } from "./template-presentation.js";
59
92
  import { logFiles } from "./logs.js";
60
93
  import { builtinContent } from "./builtins.js";
61
94
  import { readSecretStream } from "./config-secret.js";
95
+ import { manageSkills } from "./skills.js";
62
96
 
63
97
  export interface IO {
64
98
  out(text: string): void;
65
99
  err(text: string, progress?: boolean): void;
66
100
  tty: boolean;
67
101
  columns?(): number | undefined;
68
- confirm(text: string): Promise<boolean>;
102
+ confirm(text: string, signal?: AbortSignal): Promise<boolean>;
69
103
  readSecret?(): Promise<string>;
104
+ requestInput?(): AsyncIterable<string | Uint8Array>;
70
105
  }
71
106
  let progressLine = false;
72
107
  export const processIO: IO = {
@@ -88,6 +123,13 @@ export const processIO: IO = {
88
123
  columns() {
89
124
  return process.stdout.columns;
90
125
  },
126
+ requestInput() {
127
+ if (process.stdin.isTTY)
128
+ syntax(
129
+ "Pipe Request JSON into swarm approve - --yes, or pass a Request file.",
130
+ );
131
+ return process.stdin;
132
+ },
91
133
  async readSecret() {
92
134
  if (process.stdin.isTTY)
93
135
  syntax(
@@ -96,14 +138,16 @@ export const processIO: IO = {
96
138
  process.stdin.setEncoding("utf8");
97
139
  return readSecretStream(process.stdin as AsyncIterable<string>);
98
140
  },
99
- async confirm(text) {
141
+ async confirm(text, signal) {
100
142
  const reader = createInterface({
101
143
  input: process.stdin,
102
144
  output: process.stderr,
103
145
  });
104
146
  try {
105
147
  return /^(y|yes)$/i.test(
106
- (await reader.question(`${text} [y/N] `)).trim(),
148
+ (
149
+ await reader.question(`${text} [y/N] `, signal ? { signal } : {})
150
+ ).trim(),
107
151
  );
108
152
  } finally {
109
153
  reader.close();
@@ -111,43 +155,47 @@ export const processIO: IO = {
111
155
  },
112
156
  };
113
157
  const commands: Record<string, string> = {
114
- setup: "setup [--yes] [--kubo-archive FILE]",
158
+ "skills list": "skills list [--force | --no-force]",
159
+ "skills sync":
160
+ "skills sync [NAMES...] [--agent AGENT]... [--dry-run] [--yes] [--force | --no-force]",
161
+ doctor: "doctor [--fix [--yes]]",
162
+ profile: "profile [--name NAME] [--description TEXT]",
115
163
  "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",
164
+ "swarm request": "swarm request CONFIG_URL [--output FILE] [--alias ALIAS]",
165
+ "swarm export": "swarm export --output FILE",
119
166
  "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]",
167
+ "swarm exclude": "swarm exclude MEMBER_PUBLIC_KEY --yes",
168
+ "swarm resume": "swarm resume",
169
+ "swarm profile": "swarm profile --address MULTIADDR",
170
+ "swarm status": "swarm status [--local]",
171
+ "swarm members": "swarm members",
126
172
  "swarm list": "swarm list",
127
173
  "swarm add": "swarm add CONFIG_URL [--alias ALIAS]",
128
174
  "swarm use": "swarm use URL_OR_ALIAS",
129
175
  "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]]",
176
+ "swarm update": "swarm update [--name TEXT] [--description TEXT]",
177
+ publish: "publish NAME SOURCE [--expect OLD_CID | --snapshot]",
134
178
  get: "get REF [--raw] [--force | --no-force] [-o DIRECTORY]",
135
- search: "search QUERY [--current] [--force | --no-force]",
136
- init: "init NAME [DIR] [OPTIONS]",
179
+ search: "search QUERY [--all | --current] [--force | --no-force]",
180
+ "templates render": "templates render TEMPLATE NAME [DIR] [OPTIONS]",
137
181
  build: "build [SOURCE] [OPTIONS]",
138
182
  "bundle build": "bundle build SOURCE [OPTIONS]",
139
183
  "bundle inspect": "bundle inspect SOURCE",
140
184
  "bundle import": "bundle import FILE.car",
141
185
  exec: "exec [--log] [--force | --no-force] APP [APP_ARGS...]",
142
186
  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",
187
+ pin: "pin REF",
188
+ unpin: "unpin REF",
189
+ "pin list": "pin list",
190
+ "pin show": "pin show REF",
191
+ "register list": "register list [--swarm URL_OR_ALIAS]",
192
+ "register set":
193
+ "register set SCHEMA APP [--swarm URL_OR_ALIAS]... [--replace]",
194
+ "register remove": "register remove SCHEMA [--swarm URL_OR_ALIAS]...",
195
+ "templates list": "templates list [--force | --no-force]",
196
+ "templates show": "templates show NAME [--force | --no-force]",
197
+ "templates set": "templates set NAME SOURCE [--expect OLD_TARGET_CID]",
198
+ "templates remove": "templates remove NAME --expect OLD_TARGET_CID",
151
199
  "config get": "config get [KEY]",
152
200
  "config set":
153
201
  "config set KEY VALUE\n ipab config set pointers.apiKey - < protected-key-file",
@@ -160,10 +208,12 @@ const commands: Record<string, string> = {
160
208
  "history remove RUN_ID... [--yes]\n ipab history remove FILTERS [--yes]",
161
209
  };
162
210
  const groups: Record<string, string> = {
211
+ skills: "Discover and explicitly synchronize selected Swarm Skills globally",
163
212
  swarm: "Create, authorize, select and manage personal swarms",
164
213
  bundle: "Create, inspect and import content bundles",
165
- pin: "Retain content and manage short names",
214
+ pin: "Retain an exact CID or follow a shared Swarm Name",
166
215
  register: "Associate content types with Apps",
216
+ templates: "Inspect, render and manage Template Bundles",
167
217
  config: "Manage local configuration",
168
218
  store: "Query local storage and collect unreferenced blocks",
169
219
  history: "View and remove execution history",
@@ -178,16 +228,132 @@ const commandHelp: Record<
178
228
  notes?: string[];
179
229
  }
180
230
  > = {
181
- setup: {
231
+ "templates list": {
232
+ summary: "List templates under the selected Swarm Meta templatePath",
233
+ options: [
234
+ "--force / --no-force Refresh HEAD now / allow a valid cached snapshot.",
235
+ ],
236
+ examples: [
237
+ "ipab --swarm work templates list",
238
+ "ipab --json templates list",
239
+ ],
240
+ notes: [
241
+ "Uses only global --swarm (once, before the command), otherwise the saved default. No builtin or other Swarm fallback.",
242
+ ],
243
+ },
244
+ "templates show": {
245
+ summary: "Show one template, its exact targets and declared parameters",
246
+ arguments: [
247
+ "NAME Safe relative template Name; nested names are supported.",
248
+ ],
249
+ options: [
250
+ "--force / --no-force Refresh HEAD now / allow a valid cached snapshot.",
251
+ ],
252
+ examples: ["ipab --swarm work templates show node"],
253
+ },
254
+ "templates set": {
255
+ summary:
256
+ "Publish one validated Template Bundle with exact Name conflict checks",
257
+ arguments: [
258
+ "NAME Safe relative template Name.",
259
+ "SOURCE Exact Template CID, self-contained CAR or explicit manifest directory; no URI, build or hooks.",
260
+ ],
261
+ options: [
262
+ "--expect OLD_TARGET_CID Required to replace an occupied Name; use its exact target CID, including an Artifact wrapper.",
263
+ ],
264
+ examples: [
265
+ "ipab --swarm work templates set team/node ./template.car",
266
+ "ipab templates set node TEMPLATE_CID --expect OLD_TARGET_CID",
267
+ ],
268
+ notes: [
269
+ "Publishes an ordinary Artifact and preserves publication history and content retention.",
270
+ ],
271
+ },
272
+ "templates remove": {
273
+ summary: "Remove only one template Name, without deleting content",
274
+ arguments: ["NAME Safe relative template Name."],
275
+ options: [
276
+ "--expect OLD_TARGET_CID Required exact current Name target CID.",
277
+ ],
278
+ examples: [
279
+ "ipab --swarm work templates remove team/node --expect OLD_TARGET_CID",
280
+ ],
281
+ notes: [
282
+ "Missing Names are errors. Does not unpin, GC or delete content or history.",
283
+ ],
284
+ },
285
+ "skills list": {
286
+ summary: "List typed Skills and local installation status from one Swarm",
287
+ options: [
288
+ "--force / --no-force Refresh HEAD now / reuse a valid verified snapshot.",
289
+ "Global --json Emit machine-readable names, exact payload CIDs and status.",
290
+ ],
291
+ examples: ["ipab --swarm work skills list", "ipab --json skills list"],
292
+ notes: [
293
+ "Select one Swarm with global --swarm or swarm use; there is no --all.",
294
+ "Requires skillPath in the exact root State Bundle or legacy Meta type. Older v5 roots require a new seeded Swarm; only legacy v2/v3/v4 Meta can be explicitly replaced with --expect. No silent upgrades.",
295
+ ],
296
+ },
297
+ "skills sync": {
182
298
  summary:
183
- "Verify/install Kubo and prepare the protected HOME account identity",
184
- examples: ["ipab setup --yes", "ipab setup"],
299
+ "Install reviewed Swarm Skills using the pinned official npx installer",
300
+ arguments: [
301
+ "NAMES Install identities, e.g. ipab code-review, or full shared Names such as ipab/skills/ipab. Resolved from one verified snapshot; omit for all Skills.",
302
+ ],
303
+ options: [
304
+ "--agent AGENT Repeatable globally supported agent ID; default is detected agents.",
305
+ "--dry-run Preview without invoking npx or changing installed Skills.",
306
+ "--yes Skip IPAB consent only; conflicts and local edits remain protected.",
307
+ "--force / --no-force Refresh HEAD now / reuse a valid verified snapshot.",
308
+ ],
309
+ examples: [
310
+ "ipab --swarm work skills sync --dry-run",
311
+ "ipab skills sync ipab code-review --agent github-copilot --yes",
312
+ ],
313
+ notes: [
314
+ "Global installs only, through official skills@1.9.1 with --copy. Requires Node >=22.20.0.",
315
+ "Non-interactive execution requires --yes. Installer version, source, paths and agents are shown first.",
316
+ "No Skill hooks/scripts run. The trusted installer is not sandboxed. Telemetry and remote audits are disabled.",
317
+ "Non-IPAB installs, local edits, cross-Swarm collisions and symlink/junction aliases are never overwritten. Removed sources are reported, not deleted.",
318
+ "Partial failures report individual results, preserve pending attribution and exit nonzero; retry the same sync.",
319
+ ],
320
+ },
321
+ profile: {
322
+ summary: "Read or update your account-wide public name and description",
323
+ examples: [
324
+ "ipab profile",
325
+ 'ipab profile --name Wei --description "Developer"',
326
+ 'ipab profile --description ""',
327
+ ],
185
328
  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.",
329
+ "--name NAME Replace only your personal name.",
330
+ "--description TEXT Replace only your description; empty text clears it.",
188
331
  ],
189
332
  notes: [
190
- "Idempotent: reuse the same verified program and existing identity.",
333
+ "Independent of Swarm selection. Reading never creates an identity, persists a profile or activates a node.",
334
+ "An explicit update prepares a missing account identity without starting Kubo.",
335
+ "Updates persist locally first, then synchronize all registered memberships without changing network addresses. Partial failure exits nonzero and reports every result.",
336
+ "Retry the same profile update, or normally activate a failed membership to synchronize the saved profile.",
337
+ "First use preserves unanimous legacy values; conflicting fields require an explicit choice. New memberships adopt this same profile.",
338
+ ],
339
+ },
340
+ doctor: {
341
+ summary:
342
+ "Inspect device readiness without writes; explicitly authorize safe repairs",
343
+ examples: [
344
+ "ipab doctor",
345
+ "ipab doctor --fix",
346
+ "ipab --json doctor --fix --yes",
347
+ ],
348
+ options: [
349
+ "--fix Repair missing components, cache official archives to verify existing Kubo without reinstall, and authorize healthy compatible upgrades within ^0.43.2.",
350
+ "--yes Authorize planned repairs without prompting; requires --fix.",
351
+ ],
352
+ notes: [
353
+ "Always checks local state/configuration, managed Kubo, HOME identity, local Swarm registry and compatible updates.",
354
+ "Inspection never creates state, locks, credentials or caches. Official release metadata may be queried; unavailable updates are not claimed current.",
355
+ "Healthy current components are reused without download or confirmation. Fixed protected archive cache is automatic.",
356
+ "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
357
  "Does not create Swarm repos, start or contact any daemon, deploy services or install login startup.",
192
358
  ],
193
359
  },
@@ -214,16 +380,20 @@ const commandHelp: Record<
214
380
  "swarm request": {
215
381
  summary: "Save and export a signed self-contained membership Request",
216
382
  examples: [
217
- "ipab swarm request CONFIG_URL --owner-fingerprint TRUSTED_FINGERPRINT --output request.json --alias work",
383
+ "ipab swarm request CONFIG_URL --alias work",
384
+ "ipab swarm request CONFIG_URL --output request.json --alias work",
218
385
  ],
219
386
  options: [
220
- "--owner-fingerprint VALUE Verify Owner through a trusted independent channel.",
221
- "--name NAME Initial public display name.",
222
387
  "--alias ALIAS Pre-register the target for lazy onboarding.",
223
- "--output FILE Export the saved exact Request; no expiry or new PeerID on retry.",
388
+ "--output FILE Export to a new file instead of stdout; never overwrites.",
224
389
  ],
225
390
  notes: [
391
+ "Verify the printed Owner fingerprint through an independent trusted channel before manually sending the Request file to the Owner.",
392
+ "Without --output, stdout is the signed Request JSON, including in --json mode.",
393
+ "With --output, reports the file on stderr; --json returns file, requestId and ownerFingerprint.",
394
+ "Retries export the exact saved Request without expiry or a new PeerID.",
226
395
  "No Invite, Response file, password or Join. Next normal use fetches and decrypts the approved package.",
396
+ "Set your account-wide personal name with ipab profile --name NAME before requesting membership.",
227
397
  "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
398
  ],
229
399
  },
@@ -233,14 +403,18 @@ const commandHelp: Record<
233
403
  "--yes Explicit approval; required outside a TTY.",
234
404
  "--again Explicit fresh approval of an old Request; history is advisory.",
235
405
  ],
236
- examples: ["ipab swarm approve request.json --yes"],
406
+ examples: [
407
+ "ipab swarm approve request.json --yes",
408
+ "ipab swarm approve - --yes < request.json",
409
+ ],
237
410
  notes: [
411
+ "Use '-' to read Request JSON from stdin (maximum 16 KiB); --yes is required and no confirmation prompt reads stdin.",
238
412
  "Creates a public profile and publishes an Owner-signed X25519/AES-GCM package. Exact-ID certificates have no expiry.",
239
413
  ],
240
414
  },
241
415
  "swarm export": {
242
416
  summary: "Re-export the same persisted Request",
243
- examples: ["ipab swarm export work --output request.json"],
417
+ examples: ["ipab --swarm work swarm export --output request.json"],
244
418
  },
245
419
  "swarm exclude": {
246
420
  summary: "Owner removes a member with irreversible HEAD/key rotation",
@@ -251,13 +425,22 @@ const commandHelp: Record<
251
425
  },
252
426
  "swarm resume": {
253
427
  summary: "Owner resumes an interrupted organization switch",
254
- examples: ["ipab swarm resume work"],
428
+ examples: ["ipab --swarm work swarm resume"],
255
429
  },
256
430
  "swarm profile": {
257
- summary: "Update your public display name and LAN/VPN IPv4 TCP address",
431
+ summary: "Configure only your selected Swarm's LAN/VPN IPv4 TCP address",
258
432
  examples: [
259
- "ipab swarm profile work --name Wei",
260
- "ipab swarm profile work --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
433
+ "ipab --swarm work swarm profile --address /ip4/192.168.1.12/tcp/4001/p2p/PEER_ID",
434
+ ],
435
+ notes: [
436
+ "Personal name/description are managed only by ipab profile, not this network configuration command.",
437
+ ],
438
+ },
439
+ "swarm members": {
440
+ summary: "List every public member, including the Owner",
441
+ examples: ["ipab --swarm work swarm members", "ipab --json swarm members"],
442
+ notes: [
443
+ "Public HTTP reads only; no local membership, identity creation or node activation. Failed reads fail the command, never omit members.",
261
444
  ],
262
445
  },
263
446
  "swarm status": {
@@ -267,8 +450,8 @@ const commandHelp: Record<
267
450
  ],
268
451
  examples: [
269
452
  "ipab swarm status",
270
- "ipab swarm status work",
271
- "ipab swarm status work --local",
453
+ "ipab --swarm work swarm status",
454
+ "ipab --swarm work swarm status --local",
272
455
  ],
273
456
  notes: [
274
457
  "Always read public configuration, Scope and HEAD, and verify the State. Local content needs no HOME identity or node activation.",
@@ -304,13 +487,12 @@ const commandHelp: Record<
304
487
  },
305
488
  "swarm update": {
306
489
  summary: "Owner updates public organization information",
307
- arguments: ["URL_OR_ALIAS Defaults to the effective current swarm."],
308
490
  options: [
309
491
  "--name TEXT Replace the shared display name; empty text clears it.",
310
492
  "--description TEXT Replace the shared description; empty text clears it.",
311
493
  ],
312
494
  examples: [
313
- 'ipab swarm update work --name "Team" --description "Shared workspace"',
495
+ 'ipab --swarm work swarm update --name "Team" --description "Shared workspace"',
314
496
  'ipab swarm update --description ""',
315
497
  ],
316
498
  notes: [
@@ -320,37 +502,44 @@ const commandHelp: Record<
320
502
  ],
321
503
  },
322
504
  search: {
323
- summary: "Search formal Names across registered swarms",
505
+ summary: "Search formal Names in the current swarm",
324
506
  arguments: [
325
507
  "QUERY Case-insensitive literal name substring, 1..256 characters.",
326
508
  ],
327
509
  options: [
328
- "--current Search only the effective current swarm; conflicts with --swarm.",
510
+ "--all Search all registered swarms; conflicts with --current and --swarm.",
511
+ "--current Explicitly select the default search scope; conflicts with --swarm.",
329
512
  "--force Refresh HEAD for every swarm in the search scope.",
330
513
  "--no-force Override swarm.forceRefresh and use valid cached headers.",
331
514
  ],
332
- examples: ["ipab search hello", "ipab --swarm work search hello --force"],
515
+ examples: [
516
+ "ipab search hello",
517
+ "ipab search hello --all",
518
+ "ipab --swarm work search hello --force",
519
+ ],
333
520
  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.",
521
+ "Searches only --swarm or the saved current swarm by default. Use --all to search every registration.",
522
+ "Valid caches use local Names; absent/expired caches refresh. Active Name pins may synchronize content.",
523
+ "Refresh reads public configuration and HEAD; private networking is activated only for missing content.",
336
524
  "No matches is success, not a reason to refresh valid caches. Any failed swarm fails the whole search.",
337
525
  "Text uses local alias URIs when available; JSON references use full configuration URLs for cross-device sharing.",
338
526
  ],
339
527
  },
340
528
  publish: {
341
- summary: "Provide built content and explicitly publish a Name",
529
+ summary: "Protect content locally and publish a shared Swarm Name",
342
530
  options: [
343
- "--name NAME New formal Name; occupied Names fail.",
344
- "--expect CID Exact old Artifact node, required for iteration.",
531
+ "--expect CID Exact old Name target CID, required for iteration.",
345
532
  "--snapshot Name ordinary content without an Artifact; initial only.",
346
533
  ],
347
534
  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",
535
+ "ipab --swarm work publish apps/hello app.car",
536
+ "ipab publish apps/hello APP_CID --expect OLD_APP_CID",
537
+ "ipab publish notes/readme ./README.md",
351
538
  ],
352
539
  notes: [
353
- "No build, edit, install or execution. CID-only stdout.",
540
+ "SOURCE is an exact Bundle CID, CAR, regular file or directory. No compiler, hooks, install or App execution.",
541
+ "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.",
542
+ "App and Meta Bundles publish direct CID links; other content uses Artifact records. Occupied Names require --expect EXACT_OLD_CID (the old Artifact CID when applicable). Published payloads are local CID pins; unpin CID releases that protection, not history holders.",
354
543
  "Different-name CAS contention is rebased; same-name edits conflict (exit 3).",
355
544
  "Kubo pin confirmation precedes HEAD; it does not prove a remote device is online.",
356
545
  ],
@@ -393,20 +582,28 @@ const commandHelp: Record<
393
582
  "Does not unpin, clear history, delete unknown files or request Kubo daemon GC.",
394
583
  ],
395
584
  },
396
- init: {
397
- summary: "Create files from a Template Bundle (default: Node App project)",
398
- arguments: ["NAME Project name; DIR defaults to NAME (new/empty only)."],
585
+ "templates render": {
586
+ summary: "Render a template's project files into a new or empty folder",
587
+ arguments: [
588
+ "TEMPLATE Explicit Swarm selector, directory, CAR, exact CID or IPAB URI.",
589
+ "NAME Project name parameter; DIR defaults to NAME (new/empty only).",
590
+ ],
399
591
  options: [
400
- "--template TEMPLATE node (default), web-app, directory, CAR, CID or pin.",
592
+ "--description TEXT Set the declared description parameter.",
593
+ "--force / --no-force Refresh Swarm HEAD now / allow its valid cached snapshot.",
401
594
  "--param KEY=VALUE Template parameter; repeatable. Strings are literal;",
402
595
  " other parameter types use JSON.",
403
596
  ],
404
597
  examples: [
405
- "ipab init hello",
406
- "ipab init dashboard --template web-app",
407
- "ipab init hello --param description=Demo",
598
+ "ipab templates render node hello",
599
+ "ipab templates render web-app dashboard --param webAppDependency=0.1.0-rc.2",
600
+ "ipab templates render ./template.car hello --description Demo",
601
+ ],
602
+ notes: [
603
+ "Short selectors resolve through the selected Swarm's typed root configuration (legacy v2/v3/v4 use Meta Name ipab); no builtin fallback.",
604
+ "Explicit directory, CAR and available exact CID work offline without a Swarm.",
605
+ "Does not install dependencies or execute template code.",
408
606
  ],
409
- notes: ["Does not install dependencies or execute template code."],
410
607
  },
411
608
  build: {
412
609
  summary: "Assemble any Bundle using ipab.build.yaml (no compilation)",
@@ -450,7 +647,9 @@ const commandHelp: Record<
450
647
  },
451
648
  "bundle inspect": {
452
649
  summary: "Inspect a Bundle or type definition",
453
- arguments: ["SOURCE Directory, definition file, CAR, CID or named pin."],
650
+ arguments: [
651
+ "SOURCE Directory, definition file, CAR, CID or packaged builtin reference.",
652
+ ],
454
653
  examples: ["ipab bundle inspect note\\dist\\bundle.car"],
455
654
  notes: ["Does not execute Apps, import content or create pins."],
456
655
  },
@@ -460,11 +659,11 @@ const commandHelp: Record<
460
659
  examples: ["ipab bundle import hello\\dist\\app.car"],
461
660
  notes: [
462
661
  "Repeated imports are safe; no App execution or daemon startup.",
463
- "Does not pin or retain content. Use pin add for persistent retention.",
662
+ "Does not pin or retain content. Use pin CID for persistent retention.",
464
663
  ],
465
664
  },
466
665
  exec: {
467
- summary: "Run an App by CID, named pin or IPAB URI",
666
+ summary: "Run an App by exact CID or Swarm IPAB URI",
468
667
  arguments: [
469
668
  "APP_ARGS Everything after APP is passed verbatim, including --help.",
470
669
  ],
@@ -488,7 +687,9 @@ const commandHelp: Record<
488
687
  },
489
688
  open: {
490
689
  summary: "Open content with its registered App",
491
- arguments: ["CONTENT Bundle CID, named pin or IPAB URI."],
690
+ arguments: [
691
+ "CONTENT Bundle CID, packaged builtin reference or Swarm IPAB URI.",
692
+ ],
492
693
  options: [
493
694
  "--log Record stdout/stderr; requires history enabled.",
494
695
  "--raw Open the Artifact node rather than its value.",
@@ -502,86 +703,106 @@ const commandHelp: Record<
502
703
  ],
503
704
  notes: [
504
705
  "Requires a saved registration and App support for the exact content type.",
706
+ "Uses only the content URI's Swarm, otherwise --swarm, otherwise swarm.default. A selected Swarm is required.",
707
+ "A registered App's retrieval, compatibility or execution failure never triggers fallback.",
708
+ "Legacy User registrations are inactive and preserved in the state database's legacy_user_registrations table; review them before explicit Swarm registration.",
505
709
  "ipab://ALIAS_OR_ENCODED_CONFIG_URL/PATH selects its own swarm; ipab:///PATH uses --swarm or swarm.default.",
506
710
  "Apps are NOT sandboxed; run only Apps you trust.",
507
711
  "Logs may contain secrets; stdin is never logged. Logging makes output non-TTY.",
508
712
  "--json is not supported; App stdio is passed through.",
509
713
  ],
510
714
  },
511
- "pin add": {
512
- summary: "Verify, retain and name a Bundle",
715
+ pin: {
716
+ summary: "Retain an immutable CID or follow a shared Swarm Name",
513
717
  arguments: [
514
- "NAME Unused short name.",
515
- "CID Exact Bundle CID, not another pin name or a standalone type block.",
718
+ "REF Exact Bundle CID or ipab://SWARM/NAME; no local content aliases.",
719
+ ],
720
+ examples: [
721
+ "ipab pin APP_CID",
722
+ "ipab pin ipab://work/apps/reader",
723
+ "ipab pin list",
516
724
  ],
517
- examples: ["ipab pin add reader APP_CID"],
518
725
  notes: [
519
726
  "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.",
727
+ "A CID stays fixed. A shared Name saves its canonical configuration URL and exact Name, refreshing on related Swarm HEAD reads/sync, not continuously.",
728
+ "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.",
729
+ "Does not execute Apps or install dependencies. Shared Names connect to their Swarm content source only as needed.",
521
730
  "The builtin namespace is read-only.",
522
731
  ],
523
732
  },
524
- "pin delete": {
525
- summary: "Remove a user pin and release its retention",
526
- examples: ["ipab pin delete reader"],
733
+ unpin: {
734
+ summary: "Release a CID pin or stop following a shared Name",
735
+ examples: ["ipab unpin APP_CID", "ipab unpin ipab://work/apps/reader"],
527
736
  notes: [
528
737
  "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.",
738
+ "Never re-resolves a shared Name to release content. Uses only saved actual roots. Missing pins are success.",
739
+ "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.",
740
+ "Publication/history owners are independent; --snapshot payloads remain recursively retained by publication history after ordinary unpin.",
530
741
  ],
531
742
  },
532
743
  "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"],
744
+ summary: "List local retention, following Names and packaged built-ins",
745
+ examples: ["ipab pin list"],
538
746
  notes: [
539
- "Unfinished operations and legacy non-Bundle pins are reported separately.",
540
- "Legacy retention is preserved; use pin delete to explicitly release it.",
747
+ "Includes pending/stale/missing records and inactive archived local pin names.",
748
+ "Legacy retention is preserved; use unpin EXACT_CID to explicitly release its archived holders.",
541
749
  "Reads local registrations and packaged built-ins, not live node status.",
542
750
  ],
543
751
  },
544
752
  "pin show": {
545
- summary: "Show a pin's CID and type metadata",
546
- examples: ["ipab pin show reader", "ipab pin show builtin:template.node"],
753
+ summary: "Show saved retention and following status",
754
+ examples: ["ipab pin show APP_CID"],
547
755
  notes: [
548
756
  "Reads local metadata; built-in pins do not claim user Store retention.",
549
757
  ],
550
758
  },
551
- "pin rename": {
552
- summary: "Rename a user pin without changing its content",
553
- examples: ["ipab pin rename reader my-reader"],
759
+ "register list": {
760
+ summary: "List content-type associations in the current or selected Swarm",
761
+ options: [
762
+ "--swarm URL_OR_ALIAS Read only this Swarm registry; specify at most once.",
763
+ ],
764
+ examples: ["ipab register list", "ipab register list --swarm work"],
554
765
  notes: [
555
- "NEW_NAME must be unused. Built-in pins are read-only.",
556
- "CID, ownership, registrations and history are unchanged.",
766
+ "Without explicit --swarm, reads the saved default Swarm. Select one with --swarm or ipab swarm use.",
767
+ "Legacy User registrations are inactive and preserved in legacy_user_registrations; no automatic upload or deletion.",
557
768
  ],
558
769
  },
559
- "register list": {
560
- summary: "List saved content-type associations",
561
- examples: ["ipab register list"],
562
- },
563
770
  "register set": {
564
771
  summary: "Associate a content type with an App",
565
772
  arguments: [
566
773
  "SCHEMA Exact type CID or builtin:node-app.v1.",
567
- "APP App CID or named pin; the exact CID is saved.",
568
- "TEMPLATE App argv after --; must contain a whole argument % (default: %).",
774
+ "APP App CID or Swarm IPAB URI; the exact CID is saved.",
775
+ ],
776
+ options: [
777
+ "--replace Allow changing an existing association.",
778
+ "--swarm URL_OR_ALIAS Write this Swarm registry; repeat for multiple Swarms.",
569
779
  ],
570
- options: ["--replace Allow changing an existing association."],
571
780
  examples: [
572
- "ipab register set SCHEMA_CID reader",
573
- "ipab register set SCHEMA_CID reader '--' '--cid' '%'",
781
+ "ipab register set SCHEMA_CID APP_CID",
782
+ "ipab register set SCHEMA_CID ipab:///apps/reader --swarm work --swarm team",
574
783
  ],
575
784
  notes: [
576
- "Replaces only the whole % argument with the content CID; no shell expansion.",
785
+ "Writes the Name META.registryPath/TYPE_CID directly to the App CID. Open passes only the content CID.",
786
+ "Custom per-association argv is unsupported; adapt the App or use ipab exec APP_CID ARGS.",
577
787
  "Does not verify App type support; open checks it before execution.",
788
+ "Without explicit --swarm, writes the saved default Swarm. Swarm writes require HEAD write access.",
789
+ "Multiple Swarms commit sequentially, not atomically; failures report completed targets.",
578
790
  ],
579
791
  },
580
792
  "register remove": {
581
793
  summary: "Remove a saved content-type association",
582
794
  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."],
795
+ options: [
796
+ "--swarm URL_OR_ALIAS Remove from this Swarm registry; repeat for multiple Swarms.",
797
+ ],
798
+ examples: [
799
+ "ipab register remove SCHEMA_CID",
800
+ "ipab register remove SCHEMA_CID --swarm work",
801
+ ],
802
+ notes: [
803
+ "Without explicit --swarm, removes from the saved default Swarm. Multiple Swarm edits are not atomic.",
804
+ "Does not remove Apps, pins or content.",
805
+ ],
585
806
  },
586
807
  "config get": {
587
808
  summary: "Show effective configuration",
@@ -609,7 +830,7 @@ const commandHelp: Record<
609
830
  "history list": {
610
831
  summary: "List execution history",
611
832
  options: [
612
- "--app APP Filter by App CID or named pin.",
833
+ "--app APP Filter by exact App CID.",
613
834
  "--status STATUS succeeded, failed or cancelled.",
614
835
  "--since TIME Include runs ended at or after TIME.",
615
836
  "--until TIME Include runs ended before TIME.",
@@ -632,7 +853,7 @@ const commandHelp: Record<
632
853
  "history remove": {
633
854
  summary: "Remove execution records and their logs",
634
855
  options: [
635
- "--app APP Filter by App CID or named pin.",
856
+ "--app APP Filter by exact App CID.",
636
857
  "--status STATUS succeeded, failed or cancelled.",
637
858
  "--since TIME Include runs ended at or after TIME.",
638
859
  "--until TIME Include runs ended before TIME.",
@@ -668,17 +889,20 @@ Run Apps:
668
889
  open ${commandHelp.open!.summary}
669
890
 
670
891
  Create:
671
- init ${commandHelp.init!.summary}
892
+ templates ${groups.templates}
672
893
  build ${commandHelp.build!.summary}
673
894
  bundle ${groups.bundle}
674
895
 
675
896
  Manage:
676
- setup ${commandHelp.setup!.summary}
897
+ doctor ${commandHelp.doctor!.summary}
898
+ profile ${commandHelp.profile!.summary}
677
899
  swarm ${groups.swarm}
678
- search Search formal Names across registered swarms
900
+ skills ${groups.skills}
901
+ search Search formal Names in the current swarm
679
902
  publish ${commandHelp.publish!.summary}
680
903
  get ${commandHelp.get!.summary}
681
904
  pin ${groups.pin}
905
+ unpin ${commandHelp.unpin!.summary}
682
906
  register ${groups.register}
683
907
  config ${groups.config}
684
908
  store ${groups.store}
@@ -701,7 +925,25 @@ ${footer}`;
701
925
  ...(topic.arguments ? [section("Arguments", topic.arguments)] : []),
702
926
  ...(topic.options ? [section("Options", topic.options)] : []),
703
927
  section("Examples", topic.examples),
704
- ...(topic.notes ? [section("Notes", topic.notes)] : []),
928
+ ...([
929
+ "swarm status",
930
+ "swarm members",
931
+ "swarm update",
932
+ "swarm resume",
933
+ "swarm profile",
934
+ "swarm export",
935
+ "swarm approve",
936
+ "swarm exclude",
937
+ ].includes(path)
938
+ ? [
939
+ section("Notes", [
940
+ ...(topic.notes ?? []),
941
+ "Select only with global --swarm URL_OR_ALIAS (before the command), or the saved swarm.default. Neither means an error.",
942
+ ]),
943
+ ]
944
+ : topic.notes
945
+ ? [section("Notes", topic.notes)]
946
+ : []),
705
947
  `\n\n-h, --help shows this help. Global options: see 'ipab --help'.\n${footer}`,
706
948
  ].join("");
707
949
  }
@@ -844,6 +1086,8 @@ interface Parsed {
844
1086
  options: Record<string, string | boolean>;
845
1087
  template?: string[];
846
1088
  parameters?: string[];
1089
+ registrySwarms?: string[];
1090
+ agents?: string[];
847
1091
  help: boolean;
848
1092
  version: boolean;
849
1093
  }
@@ -867,6 +1111,7 @@ async function closeStore(
867
1111
  export function parse(argv: readonly string[]): Parsed {
868
1112
  const tokens = [...argv];
869
1113
  const flags: GlobalOptions = { json: false };
1114
+ const swarms: string[] = [];
870
1115
  while (tokens[0]?.startsWith("-")) {
871
1116
  const flag = tokens.shift()!;
872
1117
  if (flag === "-h" || flag === "--help")
@@ -902,13 +1147,21 @@ export function parse(argv: readonly string[]): Parsed {
902
1147
  const value = tokens.shift();
903
1148
  if (!value || value.startsWith("-")) syntax(`${flag} needs a value.`);
904
1149
  if (flag === "--state-dir") flags.stateDir = value;
905
- else if (flag === "--swarm") flags.swarm = value;
906
- else {
1150
+ else if (flag === "--swarm") {
1151
+ flags.swarm = value;
1152
+ swarms.push(value);
1153
+ } else {
907
1154
  flags.storeGateway = publicUrl(value);
908
1155
  }
909
1156
  } else syntax(`Unknown global option "${flag}".`);
910
1157
  }
911
1158
  const group = tokens.shift() ?? "";
1159
+ if (group === "init")
1160
+ syntax(
1161
+ "Root init was removed. Use ipab templates render TEMPLATE NAME [DIR]; TEMPLATE is the first positional argument, not --template.",
1162
+ );
1163
+ if (group === "templates" && swarms.length > 1)
1164
+ syntax("Templates accepts only one global --swarm, before the command.");
912
1165
  const result: Parsed = {
913
1166
  flags,
914
1167
  path: group,
@@ -916,6 +1169,7 @@ export function parse(argv: readonly string[]): Parsed {
916
1169
  options: {},
917
1170
  help: !group,
918
1171
  version: false,
1172
+ ...(group === "register" ? { registrySwarms: swarms } : {}),
919
1173
  };
920
1174
  if (!group) return result;
921
1175
  if (group === "exec") {
@@ -938,30 +1192,49 @@ export function parse(argv: readonly string[]): Parsed {
938
1192
  return result;
939
1193
  }
940
1194
  if (
941
- !["open", "init", "build", "publish", "get", "search", "setup"].includes(
942
- group,
943
- )
1195
+ ![
1196
+ "open",
1197
+ "build",
1198
+ "publish",
1199
+ "get",
1200
+ "search",
1201
+ "doctor",
1202
+ "profile",
1203
+ "unpin",
1204
+ ].includes(group)
944
1205
  ) {
945
1206
  if (
946
1207
  ![
947
1208
  "bundle",
948
1209
  "pin",
949
1210
  "register",
1211
+ "templates",
950
1212
  "config",
951
1213
  "history",
952
1214
  "store",
953
1215
  "swarm",
1216
+ "skills",
954
1217
  ].includes(group)
955
1218
  )
956
- syntax(`Unknown command "${group}".`);
957
- if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
1219
+ syntax(
1220
+ `Unknown command "${group}".${group === "setup" ? " Run ipab doctor to inspect, or ipab doctor --fix to prepare this device." : " Run ipab --help."}`,
1221
+ );
1222
+ if (group === "pin" && !["list", "show"].includes(tokens[0] ?? "")) {
1223
+ if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
1224
+ result.help = true;
1225
+ return result;
1226
+ }
1227
+ } else if (!tokens.length || tokens[0] === "-h" || tokens[0] === "--help") {
958
1228
  result.help = true;
959
1229
  return result;
960
- }
961
- result.path = `${group} ${tokens.shift()!}`;
1230
+ } else result.path = `${group} ${tokens.shift()!}`;
962
1231
  } else if (group === "open" && flags.json)
963
1232
  syntax("--json is not supported for exec/open.");
964
1233
  if (!commands[result.path]) syntax(`Unknown command "${result.path}".`);
1234
+ if (group === "skills" && swarms.length > 1)
1235
+ syntax(
1236
+ "Skills operations select exactly one Swarm; repeated --swarm is not supported.",
1237
+ );
965
1238
  const separator = result.path === "register set" ? tokens.indexOf("--") : -1;
966
1239
  if (separator >= 0) result.template = tokens.splice(separator + 1);
967
1240
  if (separator >= 0) tokens.splice(separator);
@@ -977,19 +1250,31 @@ export function parse(argv: readonly string[]): Parsed {
977
1250
  syntax(
978
1251
  "API key must be provided through '-' and piped stdin; never pass it in command arguments.",
979
1252
  );
980
- const booleans =
981
- result.path === "setup"
982
- ? ["yes"]
1253
+ const booleans = result.path.startsWith("skills ")
1254
+ ? result.path === "skills sync"
1255
+ ? ["dry-run", "yes", "force", "no-force"]
1256
+ : ["force", "no-force"]
1257
+ : result.path === "doctor"
1258
+ ? ["fix", "yes"]
983
1259
  : result.path === "bundle build"
984
1260
  ? ["replace", "schema-only", "no-import"]
985
1261
  : result.path === "build"
986
1262
  ? ["replace", "no-import"]
987
1263
  : result.path === "publish"
988
1264
  ? ["snapshot"]
989
- : result.path === "get"
990
- ? ["raw", "force", "no-force"]
1265
+ : [
1266
+ "get",
1267
+ "templates render",
1268
+ "templates list",
1269
+ "templates show",
1270
+ ].includes(result.path)
1271
+ ? result.path === "templates render"
1272
+ ? ["force", "no-force"]
1273
+ : result.path === "get"
1274
+ ? ["raw", "force", "no-force"]
1275
+ : ["force", "no-force"]
991
1276
  : result.path === "search"
992
- ? ["current", "force", "no-force"]
1277
+ ? ["all", "current", "force", "no-force"]
993
1278
  : result.path === "swarm approve"
994
1279
  ? ["yes", "again"]
995
1280
  : result.path === "swarm status"
@@ -1009,21 +1294,23 @@ export function parse(argv: readonly string[]): Parsed {
1009
1294
  : result.path === "swarm add"
1010
1295
  ? ["alias"]
1011
1296
  : result.path === "swarm request"
1012
- ? ["owner-fingerprint", "name", "alias", "output"]
1297
+ ? ["alias", "output"]
1013
1298
  : result.path === "swarm export"
1014
1299
  ? ["output"]
1015
1300
  : result.path === "swarm profile"
1016
- ? ["name", "address"]
1017
- : result.path === "swarm update"
1301
+ ? ["address"]
1302
+ : result.path === "swarm update" || result.path === "profile"
1018
1303
  ? ["name", "description"]
1019
1304
  : result.path === "swarm approve"
1020
1305
  ? []
1021
- : result.path === "publish"
1022
- ? ["name", "expect"]
1306
+ : ["publish", "templates set", "templates remove"].includes(
1307
+ result.path,
1308
+ )
1309
+ ? ["expect"]
1023
1310
  : result.path === "get"
1024
1311
  ? ["output"]
1025
- : result.path === "init"
1026
- ? ["template"]
1312
+ : result.path === "templates render"
1313
+ ? ["description"]
1027
1314
  : result.path === "bundle build" ||
1028
1315
  result.path === "build"
1029
1316
  ? ["output"]
@@ -1038,10 +1325,7 @@ export function parse(argv: readonly string[]): Parsed {
1038
1325
  ]
1039
1326
  : result.path === "history remove"
1040
1327
  ? ["app", "status", "since", "until"]
1041
- : result.path === "pin list"
1042
- ? ["type"]
1043
- : [];
1044
- if (result.path === "setup") values.push("kubo-archive");
1328
+ : [];
1045
1329
  while (tokens.length) {
1046
1330
  const value = tokens.shift()!;
1047
1331
  if (
@@ -1051,7 +1335,24 @@ export function parse(argv: readonly string[]): Parsed {
1051
1335
  result.positional.push(value);
1052
1336
  } else if (value.startsWith("--") || value === "-o") {
1053
1337
  const option = value === "-o" ? "output" : value.slice(2);
1054
- if (result.path === "init" && option === "param") {
1338
+ if (result.path === "skills sync" && option === "agent") {
1339
+ const input = tokens.shift();
1340
+ if (!input || input.startsWith("-")) syntax("--agent needs a value.");
1341
+ (result.agents ??= []).push(input);
1342
+ continue;
1343
+ }
1344
+ if (result.path.startsWith("register ") && option === "swarm") {
1345
+ const input = tokens.shift();
1346
+ if (!input || input.startsWith("-")) syntax("--swarm needs a value.");
1347
+ result.registrySwarms!.push(input);
1348
+ flags.swarm = input;
1349
+ continue;
1350
+ }
1351
+ if (result.path === "templates render" && option === "template")
1352
+ syntax(
1353
+ "--template was removed. Use ipab templates render TEMPLATE NAME [DIR], with TEMPLATE first.",
1354
+ );
1355
+ if (result.path === "templates render" && option === "param") {
1055
1356
  const input = tokens.shift();
1056
1357
  if (!input || input.startsWith("--") || input.indexOf("=") < 1)
1057
1358
  syntax("--param requires KEY=VALUE.");
@@ -1066,15 +1367,22 @@ export function parse(argv: readonly string[]): Parsed {
1066
1367
  if (
1067
1368
  input === undefined ||
1068
1369
  (input.startsWith("--") &&
1069
- !(
1070
- ["resume", "owner-fingerprint"].includes(option) &&
1071
- /^[A-Za-z0-9_-]{43}$/.test(input)
1072
- )) ||
1073
- (input === "" && result.path !== "swarm update")
1370
+ !(option === "resume" && /^[A-Za-z0-9_-]{43}$/.test(input))) ||
1371
+ (input === "" &&
1372
+ !["swarm update", "profile", "templates render"].includes(
1373
+ result.path,
1374
+ ))
1074
1375
  )
1075
1376
  syntax(`${value} needs a value.`);
1076
1377
  result.options[option] = input;
1077
- } else syntax(`Unknown option "${value}".`);
1378
+ } else if (
1379
+ option === "name" &&
1380
+ ["swarm profile", "swarm request"].includes(result.path)
1381
+ )
1382
+ syntax(
1383
+ `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." : ""}`,
1384
+ );
1385
+ else syntax(`Unknown option "${value}".`);
1078
1386
  } else result.positional.push(value);
1079
1387
  }
1080
1388
  if (result.options.force && result.options["no-force"])
@@ -1085,38 +1393,58 @@ export function parse(argv: readonly string[]): Parsed {
1085
1393
  flags.swarm !== undefined
1086
1394
  )
1087
1395
  syntax("--current and --swarm are mutually exclusive.");
1396
+ if (
1397
+ result.path === "search" &&
1398
+ result.options.all &&
1399
+ (result.options.current || flags.swarm !== undefined)
1400
+ )
1401
+ syntax("--all is mutually exclusive with --current and --swarm.");
1402
+ if (
1403
+ result.path === "register list" &&
1404
+ (result.registrySwarms?.length ?? 0) > 1
1405
+ )
1406
+ syntax(
1407
+ "register list accepts --swarm at most once. Select one Swarm or omit it to use the current Swarm.",
1408
+ );
1088
1409
  const counts: Record<string, [number, number]> = {
1089
- setup: [0, 0],
1410
+ doctor: [0, 0],
1411
+ "skills list": [0, 0],
1412
+ "skills sync": [0, Number.MAX_SAFE_INTEGER],
1413
+ profile: [0, 0],
1090
1414
  "swarm create": [0, 0],
1091
1415
  "swarm request": [1, 1],
1092
1416
  "swarm approve": [1, 1],
1093
- "swarm export": [1, 1],
1417
+ "swarm export": [0, 0],
1094
1418
  "swarm exclude": [1, 1],
1095
- "swarm resume": [0, 1],
1096
- "swarm profile": [0, 1],
1097
- "swarm status": [0, 1],
1419
+ "swarm resume": [0, 0],
1420
+ "swarm profile": [0, 0],
1421
+ "swarm status": [0, 0],
1422
+ "swarm members": [0, 0],
1098
1423
  "swarm list": [0, 0],
1099
1424
  "swarm add": [1, 1],
1100
1425
  "swarm use": [1, 1],
1101
1426
  "swarm remove": [1, 1],
1102
- "swarm update": [0, 1],
1103
- publish: [1, 1],
1427
+ "swarm update": [0, 0],
1428
+ publish: [2, 2],
1104
1429
  get: [1, 1],
1105
1430
  search: [1, 1],
1106
- init: [1, 2],
1431
+ "templates render": [2, 3],
1107
1432
  build: [0, 1],
1108
1433
  "bundle build": [1, 1],
1109
1434
  "bundle inspect": [1, 1],
1110
1435
  "bundle import": [1, 1],
1111
1436
  open: [1, 1],
1112
- "pin add": [2, 2],
1113
- "pin delete": [1, 1],
1437
+ pin: [1, 1],
1438
+ unpin: [1, 1],
1114
1439
  "pin list": [0, 0],
1115
1440
  "pin show": [1, 1],
1116
- "pin rename": [2, 2],
1117
1441
  "register list": [0, 0],
1118
1442
  "register set": [2, 2],
1119
1443
  "register remove": [1, 1],
1444
+ "templates list": [0, 0],
1445
+ "templates show": [1, 1],
1446
+ "templates set": [2, 2],
1447
+ "templates remove": [1, 1],
1120
1448
  "config get": [0, 1],
1121
1449
  "config set": [2, 2],
1122
1450
  "config reset": [1, 1],
@@ -1129,13 +1457,28 @@ export function parse(argv: readonly string[]): Parsed {
1129
1457
  if (result.options["with-source"] && result.options["without-source"])
1130
1458
  syntax("--with-source and --without-source are mutually exclusive.");
1131
1459
  const [minimum, maximum] = counts[result.path]!;
1132
- if (result.positional.length < minimum || result.positional.length > maximum)
1133
- syntax(`Invalid arguments.\n${help(result.path)}`);
1460
+ if (result.path === "profile" && flags.swarm !== undefined)
1461
+ syntax("Personal profile is account-wide; do not pass --swarm.");
1134
1462
  if (
1135
- result.template &&
1136
- (!result.template.length || !result.template.includes("%"))
1463
+ result.positional.length &&
1464
+ [
1465
+ "swarm status",
1466
+ "swarm update",
1467
+ "swarm resume",
1468
+ "swarm profile",
1469
+ "swarm export",
1470
+ "swarm members",
1471
+ ].includes(result.path)
1137
1472
  )
1138
- syntax('Argument template must contain a whole "%" token.');
1473
+ syntax(
1474
+ `Swarm target positionals are no longer supported. Use ipab --swarm URL_OR_ALIAS ${result.path} instead.`,
1475
+ );
1476
+ if (result.positional.length < minimum || result.positional.length > maximum)
1477
+ syntax(`Invalid arguments.\n${help(result.path)}`);
1478
+ if (result.template)
1479
+ syntax(
1480
+ 'Custom per-association argv is unsupported. Remove "-- TEMPLATE..."; open passes only the content CID. Adapt the App or use ipab exec APP_CID ARGS.',
1481
+ );
1139
1482
  if (result.path === "history remove") {
1140
1483
  const selected = values.some((value) =>
1141
1484
  Object.hasOwn(result.options, value),
@@ -1147,10 +1490,36 @@ export function parse(argv: readonly string[]): Parsed {
1147
1490
  syntax("history remove requires explicit IDs OR filters, not both.");
1148
1491
  }
1149
1492
  // 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]!);
1493
+ if (["pin", "unpin", "pin show"].includes(result.path)) {
1494
+ const reference = result.positional[0]!;
1495
+ if (reference.startsWith("builtin:") && result.path !== "pin show")
1496
+ syntax(
1497
+ "Packaged builtin references are read-only; they cannot be pinned or unpinned.",
1498
+ );
1499
+ if (
1500
+ !(result.path === "pin show" && reference.startsWith("builtin:")) &&
1501
+ !parseNameReference(reference)
1502
+ )
1503
+ exactCid(reference);
1504
+ }
1505
+ if (result.path === "publish") {
1506
+ formalName(result.positional[0]!);
1507
+ if (typeof result.options.expect === "string")
1508
+ exactCid(result.options.expect);
1509
+ if (result.options.expect && result.options.snapshot)
1510
+ syntax(
1511
+ "--snapshot is initial-only and cannot be combined with --expect.",
1512
+ );
1513
+ }
1514
+ if (
1515
+ result.path.startsWith("templates ") &&
1516
+ result.path !== "templates render"
1517
+ ) {
1518
+ if (result.positional[0] !== undefined) templateName(result.positional[0]);
1519
+ if (typeof result.options.expect === "string")
1520
+ exactCid(result.options.expect);
1521
+ if (result.path === "templates remove" && !result.options.expect)
1522
+ syntax("templates remove requires --expect OLD_TARGET_CID.");
1154
1523
  }
1155
1524
  if (result.path.startsWith("config ") && result.positional[0]) {
1156
1525
  if (
@@ -1172,6 +1541,8 @@ export function parse(argv: readonly string[]): Parsed {
1172
1541
  parseValue("history.limit", result.options.limit, true);
1173
1542
  if (result.options.output === "-")
1174
1543
  syntax("CAR output requires a file path; binary stdout is not supported.");
1544
+ if (result.path === "doctor" && result.options.yes && !result.options.fix)
1545
+ syntax("doctor --yes requires --fix.");
1175
1546
  return result;
1176
1547
  }
1177
1548
 
@@ -1204,28 +1575,18 @@ async function performCli(
1204
1575
  }
1205
1576
  if (parsed.path === "history remove" && !parsed.options.yes && !io.tty)
1206
1577
  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
- );
1578
+ if (parsed.path === "doctor") {
1218
1579
  const controller = new AbortController();
1219
1580
  const interrupt = () => {
1220
- controller.abort(new HostError("Setup interrupted.", 130, "ABORTED"));
1581
+ controller.abort(new HostError("Doctor interrupted.", 130, "ABORTED"));
1221
1582
  };
1222
1583
  const terminate = () => {
1223
- controller.abort(new HostError("Setup terminated.", 143, "ABORTED"));
1584
+ controller.abort(new HostError("Doctor terminated.", 143, "ABORTED"));
1224
1585
  };
1225
1586
  process.once("SIGINT", interrupt);
1226
1587
  process.once("SIGTERM", terminate);
1227
1588
  try {
1228
- const result = await setupDevice(
1589
+ const result = await doctorDevice(
1229
1590
  stateLocation(parsed.flags, env).path,
1230
1591
  env,
1231
1592
  {
@@ -1233,17 +1594,14 @@ async function performCli(
1233
1594
  io.err(text, progress);
1234
1595
  },
1235
1596
  signal: controller.signal,
1236
- ...(typeof parsed.options["kubo-archive"] === "string"
1237
- ? { archive: parsed.options["kubo-archive"] }
1238
- : {}),
1597
+ fix: Boolean(parsed.options.fix),
1598
+ yes: Boolean(parsed.options.yes),
1599
+ tty: io.tty,
1600
+ confirm: (text, signal) => io.confirm(text, signal),
1239
1601
  },
1240
1602
  );
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;
1603
+ io.out(parsed.flags.json ? JSON.stringify(result) : doctorText(result));
1604
+ return result.ready ? 0 : 1;
1247
1605
  } finally {
1248
1606
  process.removeListener("SIGINT", interrupt);
1249
1607
  process.removeListener("SIGTERM", terminate);
@@ -1270,7 +1628,8 @@ async function performCli(
1270
1628
  const items = effectiveConfig(
1271
1629
  state.config({
1272
1630
  includeSecrets:
1273
- parsed.path !== "swarm status" || Boolean(parsed.options.local),
1631
+ !["swarm members", "profile", "swarm status"].includes(parsed.path) ||
1632
+ Boolean(parsed.options.local),
1274
1633
  }),
1275
1634
  parsed.flags,
1276
1635
  env,
@@ -1286,6 +1645,13 @@ async function performCli(
1286
1645
  value("swarm.default") === null
1287
1646
  ? undefined
1288
1647
  : String(value("swarm.default"));
1648
+ const requireSwarm = () => {
1649
+ if (!selectedSwarm)
1650
+ syntax(
1651
+ "Select a Swarm with ipab --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS.",
1652
+ );
1653
+ return selectedSwarm;
1654
+ };
1289
1655
  const swarmContext = (): SwarmContext => ({
1290
1656
  get store() {
1291
1657
  return store!;
@@ -1327,7 +1693,277 @@ async function performCli(
1327
1693
  source: current.source,
1328
1694
  };
1329
1695
  };
1696
+ if (parsed.path === "open" || parsed.path.startsWith("register ")) {
1697
+ if (state.legacyRegistrationCount)
1698
+ io.err(
1699
+ `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. Custom per-association argv is unsupported. Review the archived values and explicitly run ipab register set TYPE_CID APP_CID --swarm URL_OR_ALIAS to publish only intended associations.`,
1700
+ );
1701
+ }
1702
+ if (state.legacyPinCount)
1703
+ io.err(
1704
+ `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.`,
1705
+ );
1706
+ if (
1707
+ parsed.path.startsWith("templates ") &&
1708
+ parsed.path !== "templates render"
1709
+ ) {
1710
+ const configUrl = requireSwarm();
1711
+ store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1712
+ const context = swarmContext();
1713
+ const expected =
1714
+ typeof parsed.options.expect === "string"
1715
+ ? parsed.options.expect
1716
+ : undefined;
1717
+ try {
1718
+ if (parsed.path === "templates list") {
1719
+ const items = await swarmTemplates(context, configUrl);
1720
+ const alias = state
1721
+ .swarms()
1722
+ .find((swarm) => swarm.cid === configUrl)?.alias;
1723
+ emit(
1724
+ { items },
1725
+ `Swarm: ${alias ? printable(alias) : "(no local alias)"}\nConfig URL: ${configUrl}\nTemplates: ${items.length}\n\n${table(
1726
+ ["NAME", "TITLE", "TARGET CID", "TEMPLATE CID"],
1727
+ items.map((item) => [
1728
+ item.selector,
1729
+ item.title,
1730
+ item.targetCid,
1731
+ item.templateCid,
1732
+ ]),
1733
+ "No templates registered in this Swarm.\nAdd a template: ipab templates set NAME SOURCE",
1734
+ )}`,
1735
+ );
1736
+ } else if (parsed.path === "templates show") {
1737
+ const item = (await swarmTemplates(context, configUrl, first))[0]!;
1738
+ if (parsed.flags.json) io.out(JSON.stringify(item));
1739
+ else {
1740
+ const alias = state
1741
+ .swarms()
1742
+ .find((swarm) => swarm.cid === configUrl)?.alias;
1743
+ const swarm = alias ?? configUrl;
1744
+ const reference = formatNameReference(swarm, item.name);
1745
+ const tree = await templateOutputTree(
1746
+ context.store,
1747
+ item.templateCid,
1748
+ );
1749
+ const shell = process.platform === "win32" ? "powershell" : "posix";
1750
+ io.out(
1751
+ [
1752
+ `${printable(item.selector)} — ${printable(item.title)}`,
1753
+ printable(item.description) || "(No description.)",
1754
+ "",
1755
+ "Location",
1756
+ ` Swarm: ${printable(swarm)}`,
1757
+ ` Name: ${printable(item.name)}`,
1758
+ "",
1759
+ `Create a project (${shell === "powershell" ? "PowerShell" : "POSIX shell"})`,
1760
+ ` ${templateRenderExample(reference, swarm, item.definition, shell)}`,
1761
+ " Replace example parameter values as needed. No code is run by show.",
1762
+ "",
1763
+ "Parameters",
1764
+ table(
1765
+ ["NAME", "TYPE", "REQUIRED", "DEFAULT", "INPUT"],
1766
+ templateParameterRows(item.definition),
1767
+ "No parameters declared.",
1768
+ ),
1769
+ "Required means an input is needed when no default is declared.",
1770
+ "",
1771
+ "Output files (from project/)",
1772
+ " my-project/",
1773
+ ...tree.entries.map(
1774
+ (entry) =>
1775
+ `${" ".repeat(entry.path.split("/").length + 1)}${printable(entry.path.split("/").at(-1)!)}${entry.kind === "directory" ? "/" : ""}`,
1776
+ ),
1777
+ ...(tree.truncated
1778
+ ? [
1779
+ ` ... truncated: ${tree.truncated}; more files may exist.`,
1780
+ ]
1781
+ : tree.entries.length
1782
+ ? []
1783
+ : [" (no output files)"]),
1784
+ "",
1785
+ "Versions",
1786
+ ` Template CID: ${item.templateCid}`,
1787
+ ` Reference: ${reference}`,
1788
+ ...(item.targetCid !== item.templateCid
1789
+ ? [` Target CID (--expect): ${item.targetCid}`]
1790
+ : []),
1791
+ ].join("\n"),
1792
+ );
1793
+ }
1794
+ } else if (parsed.path === "templates set") {
1795
+ const item = await setSwarmTemplate(
1796
+ context,
1797
+ configUrl,
1798
+ first!,
1799
+ second!,
1800
+ expected,
1801
+ );
1802
+ emit(
1803
+ item,
1804
+ `${item.reference} → ${item.targetCid} (Template ${item.templateCid})`,
1805
+ );
1806
+ } else {
1807
+ const item = await removeSwarmTemplate(
1808
+ context,
1809
+ configUrl,
1810
+ first!,
1811
+ expected!,
1812
+ );
1813
+ emit(
1814
+ { removed: item },
1815
+ `Removed ${item.reference}; content and history are retained.`,
1816
+ );
1817
+ }
1818
+ } finally {
1819
+ await context.finishRead?.();
1820
+ }
1821
+ return 0;
1822
+ }
1823
+ if (parsed.path.startsWith("register ")) {
1824
+ const references = parsed.registrySwarms?.length
1825
+ ? parsed.registrySwarms
1826
+ : selectedSwarm
1827
+ ? [selectedSwarm]
1828
+ : [];
1829
+ if (!references.length)
1830
+ throw new HostError(
1831
+ "Register requires a selected Swarm. Pass --swarm URL_OR_ALIAS, or save a default with ipab swarm use URL_OR_ALIAS.",
1832
+ );
1833
+ const targets = [
1834
+ ...new Set(
1835
+ references.map((reference) => state!.resolveSwarm(reference)),
1836
+ ),
1837
+ ];
1838
+ const schema = first
1839
+ ? state.resolve(schemaAlias(first), true)
1840
+ : undefined;
1841
+ const results: (
1842
+ | {
1843
+ items: Association[];
1844
+ }
1845
+ | {
1846
+ association: Association;
1847
+ }
1848
+ | {
1849
+ removed: string[];
1850
+ }
1851
+ )[] = [];
1852
+ const completed: string[] = [];
1853
+ const human: string[] = [];
1854
+ store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1855
+ for (const configUrl of targets) {
1856
+ const context = swarmContext();
1857
+ try {
1858
+ if (parsed.path === "register list") {
1859
+ const items = await swarmRegistrations(context, configUrl);
1860
+ const alias = state
1861
+ .swarms()
1862
+ .find((swarm) => swarm.cid === configUrl)?.alias;
1863
+ results.push({ items });
1864
+ human.push(
1865
+ `Swarm: ${alias ? printable(alias) : "(no local alias)"}\nConfig URL: ${configUrl}\nAssociations: ${items.length}\n\n${table(
1866
+ ["TYPE CID", "APP CID"],
1867
+ items.map((item) => [item.schemaCid, item.appCid]),
1868
+ "No associations registered in this Swarm.\nRegister an App: ipab register set TYPE_CID APP_CID --swarm URL_OR_ALIAS",
1869
+ )}`,
1870
+ );
1871
+ } else if (parsed.path === "register set") {
1872
+ const appCid = parseNameReference(second!)
1873
+ ? (
1874
+ await resolveReference(
1875
+ context,
1876
+ second!,
1877
+ configUrl,
1878
+ (reference) => state!.resolve(reference),
1879
+ )
1880
+ ).cid
1881
+ : state.resolve(second!);
1882
+ const association = await setSwarmAssociation(
1883
+ context,
1884
+ configUrl,
1885
+ createAssociation(schema!, appCid, parsed.template ?? ["%"]),
1886
+ Boolean(parsed.options.replace),
1887
+ );
1888
+ results.push({ association });
1889
+ human.push(
1890
+ `${configUrl}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`,
1891
+ );
1892
+ } else {
1893
+ const removed = await removeSwarmAssociation(
1894
+ context,
1895
+ configUrl,
1896
+ schema!,
1897
+ );
1898
+ results.push({ removed: [removed] });
1899
+ human.push(`${configUrl}: removed association for ${removed}.`);
1900
+ }
1901
+ completed.push(configUrl);
1902
+ } catch (cause) {
1903
+ throw new HostError(
1904
+ parsed.path === "register list"
1905
+ ? `Cannot list associations for Swarm ${configUrl}: ${message(cause)}`
1906
+ : `Registry operation failed for ${configUrl}: ${message(cause)}. Completed Swarms: ${completed.length ? completed.join(", ") : "(none)"}. Multiple Swarm edits are not atomic.`,
1907
+ cause instanceof HostError ? cause.exitCode : 1,
1908
+ cause instanceof HostError ? cause.code : "REGISTRY_FAILED",
1909
+ "publication",
1910
+ );
1911
+ } finally {
1912
+ await context.finishRead?.();
1913
+ }
1914
+ }
1915
+ emit(
1916
+ {
1917
+ swarms: results.map((result, index) => ({
1918
+ configUrl: targets[index],
1919
+ ...result,
1920
+ })),
1921
+ },
1922
+ human.join("\n\n"),
1923
+ );
1924
+ return 0;
1925
+ }
1330
1926
  switch (parsed.path) {
1927
+ case "profile": {
1928
+ const context = swarmContext();
1929
+ readContext = context;
1930
+ const changes = {
1931
+ ...(typeof parsed.options.name === "string"
1932
+ ? { name: parsed.options.name }
1933
+ : {}),
1934
+ ...(typeof parsed.options.description === "string"
1935
+ ? { description: parsed.options.description }
1936
+ : {}),
1937
+ };
1938
+ if (!Object.keys(changes).length) {
1939
+ const profile = await accountProfile(context);
1940
+ emit(
1941
+ { profile, localPersisted: profile.updatedAt !== null },
1942
+ `Name: ${printable(profile.name)}\nDescription: ${printable(profile.description)}\nPublic key: ${profile.publicKey}`,
1943
+ );
1944
+ } else {
1945
+ const result = await updateAccountProfile(context, changes);
1946
+ emit(
1947
+ result,
1948
+ [
1949
+ `Name: ${printable(result.profile.name)}`,
1950
+ `Description: ${printable(result.profile.description)}`,
1951
+ "Personal profile saved locally.",
1952
+ ...result.swarms.map(
1953
+ (entry) =>
1954
+ `${entry.configUrl}: ${entry.synchronized ? "synchronized" : `FAILED: ${entry.error}`}`,
1955
+ ),
1956
+ ].join("\n"),
1957
+ );
1958
+ if (result.swarms.some((entry) => !entry.synchronized)) {
1959
+ io.err(
1960
+ "Profile saved locally, but some Swarms failed. Retry the profile update or normally activate each failed membership to synchronize it.",
1961
+ );
1962
+ return 1;
1963
+ }
1964
+ }
1965
+ break;
1966
+ }
1331
1967
  case "swarm list": {
1332
1968
  const result = { swarms: state.swarms(), ...selection() };
1333
1969
  emit(
@@ -1381,6 +2017,8 @@ async function performCli(
1381
2017
  case "swarm add":
1382
2018
  case "swarm update":
1383
2019
  case "search":
2020
+ case "skills list":
2021
+ case "skills sync":
1384
2022
  case "swarm create":
1385
2023
  case "swarm request":
1386
2024
  case "swarm approve":
@@ -1388,15 +2026,90 @@ async function performCli(
1388
2026
  case "swarm exclude":
1389
2027
  case "swarm resume":
1390
2028
  case "swarm profile":
2029
+ case "swarm members":
1391
2030
  case "swarm status":
1392
2031
  case "publish":
2032
+ case "pin":
1393
2033
  case "get": {
1394
2034
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
1395
2035
  const context = swarmContext();
2036
+ readContext = context;
2037
+ if (parsed.path.startsWith("skills ")) {
2038
+ const result = await manageSkills(context, requireSwarm(), {
2039
+ sync: parsed.path === "skills sync",
2040
+ names: parsed.positional,
2041
+ agents: parsed.agents ?? [],
2042
+ dryRun: Boolean(parsed.options["dry-run"]),
2043
+ yes: Boolean(parsed.options.yes),
2044
+ tty: io.tty,
2045
+ confirm: (text) => io.confirm(text),
2046
+ preview: (text) => {
2047
+ io.err(text);
2048
+ },
2049
+ });
2050
+ store = context.store;
2051
+ emit(
2052
+ result,
2053
+ [
2054
+ table(
2055
+ ["NAME", "PAYLOAD CID", "INSTALL NAME", "STATUS"],
2056
+ result.items.map((skill) => [
2057
+ skill.name,
2058
+ skill.cid,
2059
+ skill.identity,
2060
+ skill.status,
2061
+ ]),
2062
+ "No Skills.",
2063
+ ),
2064
+ ...result.items.flatMap((skill) => skill.problems),
2065
+ ...result.orphaned.map(
2066
+ (skill) =>
2067
+ `Source removed: ${skill.name} ${skill.cid} (${skill.path}); installation retained.`,
2068
+ ),
2069
+ ...result.results.map(
2070
+ (entry) =>
2071
+ `${entry.name} / ${entry.agent}: ${entry.status}${entry.error ? `: ${entry.error}` : ""}`,
2072
+ ),
2073
+ ].join("\n"),
2074
+ );
2075
+ if (!result.ok) return 1;
2076
+ break;
2077
+ }
2078
+ if (parsed.path === "pin") {
2079
+ io.err("Fetching, verifying and retaining content...");
2080
+ const result = await pinNameSubscription(
2081
+ context,
2082
+ first!,
2083
+ selectedSwarm,
2084
+ );
2085
+ store = context.store;
2086
+ emit(
2087
+ result,
2088
+ `${result.reference} → ${result.cid}\nStatus: ${result.freshness}`,
2089
+ );
2090
+ break;
2091
+ }
2092
+ if (parsed.path === "swarm members") {
2093
+ const result = await swarmMembers(context, requireSwarm());
2094
+ emit(
2095
+ result,
2096
+ table(
2097
+ ["NAME", "DESCRIPTION", "ROLE", "PUBLIC KEY"],
2098
+ result.members.map((member) => [
2099
+ member.name,
2100
+ member.description,
2101
+ member.role,
2102
+ member.publicKey,
2103
+ ]),
2104
+ "No members.",
2105
+ ),
2106
+ );
2107
+ break;
2108
+ }
1396
2109
  if (parsed.path === "swarm export") {
1397
2110
  const id = await exportRequest(
1398
2111
  context,
1399
- state.resolveSwarm(first!),
2112
+ requireSwarm(),
1400
2113
  String(parsed.options.output ?? ""),
1401
2114
  );
1402
2115
  emit({ id }, id);
@@ -1407,13 +2120,7 @@ async function performCli(
1407
2120
  parsed.path,
1408
2121
  )
1409
2122
  ) {
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.");
2123
+ const url = requireSwarm();
1417
2124
  if (parsed.path === "swarm exclude") {
1418
2125
  if (!parsed.options.yes)
1419
2126
  syntax("Member removal is irreversible; --yes required.");
@@ -1422,9 +2129,6 @@ async function performCli(
1422
2129
  await resumeRemoval(context, url);
1423
2130
  else {
1424
2131
  const profile = await updateProfile(context, url, {
1425
- ...(typeof parsed.options.name === "string"
1426
- ? { name: parsed.options.name }
1427
- : {}),
1428
2132
  ...(typeof parsed.options.address === "string"
1429
2133
  ? { addresses: [parsed.options.address] }
1430
2134
  : {}),
@@ -1441,11 +2145,7 @@ async function performCli(
1441
2145
  break;
1442
2146
  }
1443
2147
  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
- );
2148
+ const cid = requireSwarm();
1449
2149
  const result = await updateSwarm(context, cid, {
1450
2150
  ...(typeof parsed.options.name === "string"
1451
2151
  ? { name: parsed.options.name }
@@ -1483,35 +2183,23 @@ async function performCli(
1483
2183
  break;
1484
2184
  }
1485
2185
  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
2186
  const registrations = state.swarms();
1495
- const scope = limited
1496
- ? [
2187
+ const scope = parsed.options.all
2188
+ ? registrations
2189
+ : [
1497
2190
  {
1498
- cid: selectedSwarm!,
2191
+ cid: requireSwarm(),
1499
2192
  alias:
1500
2193
  registrations.find((entry) => entry.cid === selectedSwarm)
1501
2194
  ?.alias ?? null,
1502
2195
  },
1503
- ]
1504
- : registrations;
2196
+ ];
1505
2197
  const result = await searchNames(context, first!, scope);
1506
2198
  emit(result, formatSearchResults(result.matches));
1507
2199
  break;
1508
2200
  }
1509
2201
  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
- );
2202
+ const cid = requireSwarm();
1515
2203
  const local = Boolean(parsed.options.local);
1516
2204
  const { head, config } = local
1517
2205
  ? await swarmHeader(context, cid, true)
@@ -1569,7 +2257,6 @@ async function performCli(
1569
2257
  break;
1570
2258
  }
1571
2259
  if (parsed.path === "get") {
1572
- readContext = context;
1573
2260
  const localCid = /^(ipab|name):/i.test(first!)
1574
2261
  ? undefined
1575
2262
  : state.resolve(first!);
@@ -1613,6 +2300,11 @@ async function performCli(
1613
2300
  } finally {
1614
2301
  await source.close();
1615
2302
  }
2303
+ try {
2304
+ await context.finishRead?.();
2305
+ } finally {
2306
+ readContext = undefined;
2307
+ }
1616
2308
  const closing = store;
1617
2309
  store = undefined;
1618
2310
  await closeStore(closing, undefined);
@@ -1622,6 +2314,7 @@ async function performCli(
1622
2314
  break;
1623
2315
  }
1624
2316
  let cid: string;
2317
+ let contentCid: string | undefined;
1625
2318
  if (parsed.path === "swarm create") {
1626
2319
  cid = await createSwarm(context, {
1627
2320
  ...(typeof parsed.options.service === "string"
@@ -1638,12 +2331,8 @@ async function performCli(
1638
2331
  ? { alias: parsed.options.alias }
1639
2332
  : {}),
1640
2333
  });
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
- : {}),
2334
+ } else if (parsed.path === "swarm request") {
2335
+ const result = await requestMembership(context, first!, {
1647
2336
  ...(typeof parsed.options.alias === "string"
1648
2337
  ? { alias: parsed.options.alias }
1649
2338
  : {}),
@@ -1651,8 +2340,41 @@ async function performCli(
1651
2340
  ? { output: parsed.options.output }
1652
2341
  : {}),
1653
2342
  });
1654
- else if (parsed.path === "swarm approve") {
1655
- const request = await verifiedRequest(first!);
2343
+ store = context.store;
2344
+ io.err(
2345
+ `Owner fingerprint: ${result.ownerFingerprint}\nVerify this fingerprint through an independent trusted channel before manually sending the Request file to the Owner.`,
2346
+ );
2347
+ if (result.file === undefined)
2348
+ io.out(JSON.stringify(result.request, null, 2));
2349
+ else {
2350
+ io.err(`Request saved to: ${result.file}`);
2351
+ if (parsed.flags.json)
2352
+ emit(
2353
+ {
2354
+ file: result.file,
2355
+ requestId: result.requestId,
2356
+ ownerFingerprint: result.ownerFingerprint,
2357
+ },
2358
+ "",
2359
+ );
2360
+ }
2361
+ break;
2362
+ } else if (parsed.path === "swarm approve") {
2363
+ const selected = requireSwarm();
2364
+ if (first === "-" && !parsed.options.yes)
2365
+ syntax(
2366
+ "Reading a Request from stdin requires explicit --yes; no interactive confirmation is available.",
2367
+ );
2368
+ const request =
2369
+ first === "-"
2370
+ ? await verifiedRequestStream(
2371
+ (io.requestInput ?? processIO.requestInput!)(),
2372
+ )
2373
+ : await verifiedRequest(first!);
2374
+ if (request.configUrl !== selected)
2375
+ syntax(
2376
+ `Request belongs to ${request.configUrl}, not the selected Swarm. Use ipab --swarm ${request.configUrl} swarm approve REQUEST_FILE --yes.`,
2377
+ );
1656
2378
  io.err(await membershipRequestSummary(request));
1657
2379
  if (
1658
2380
  !parsed.options.yes &&
@@ -1668,17 +2390,11 @@ async function performCli(
1668
2390
  again: Boolean(parsed.options.again),
1669
2391
  });
1670
2392
  } 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!);
2393
+ const content = await publicationSource(second!, store);
2394
+ contentCid = content;
1677
2395
  cid = await publish(context, content, {
1678
2396
  ...(selectedSwarm ? { swarm: selectedSwarm } : {}),
1679
- ...(typeof parsed.options.name === "string"
1680
- ? { name: parsed.options.name }
1681
- : {}),
2397
+ name: first!,
1682
2398
  ...(typeof parsed.options.expect === "string"
1683
2399
  ? { expect: parsed.options.expect }
1684
2400
  : {}),
@@ -1690,12 +2406,14 @@ async function performCli(
1690
2406
  io.err(
1691
2407
  `Registered swarm ${state.registeredSwarm(cid).alias ?? cid}. Saved current: ${state.config({ includeSecrets: false })["swarm.default"] ?? "(none)"}.`,
1692
2408
  );
2409
+ if (contentCid)
2410
+ io.err(
2411
+ `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.`,
2412
+ );
1693
2413
  emit(
1694
- parsed.path === "swarm request"
1695
- ? { requestId: cid }
1696
- : parsed.path === "swarm create" || parsed.path === "swarm approve"
1697
- ? { configUrl: cid }
1698
- : { cid },
2414
+ parsed.path === "swarm create" || parsed.path === "swarm approve"
2415
+ ? { configUrl: cid }
2416
+ : { cid, ...(contentCid ? { contentCid } : {}) },
1699
2417
  cid,
1700
2418
  );
1701
2419
  break;
@@ -1718,7 +2436,7 @@ async function performCli(
1718
2436
  }
1719
2437
  break;
1720
2438
  }
1721
- case "init":
2439
+ case "templates render":
1722
2440
  case "build":
1723
2441
  case "bundle build":
1724
2442
  case "bundle inspect":
@@ -1755,7 +2473,10 @@ async function performCli(
1755
2473
  options.signal?.throwIfAborted();
1756
2474
  const builtin = builtins.blocks.get(cid.toV1().toString());
1757
2475
  if (builtin) return builtin.slice();
1758
- return (await getStore()).block.get(cid.toString(), options);
2476
+ return (store ?? (await getStore())).block.get(
2477
+ cid.toString(),
2478
+ options,
2479
+ );
1759
2480
  },
1760
2481
  };
1761
2482
  const builtinSource = first ? state.pin(first) : undefined;
@@ -1763,6 +2484,64 @@ async function performCli(
1763
2484
  builtinSource?.builtin && builtinSource.metadata?.kind === "bundle"
1764
2485
  ? builtinSource.cid
1765
2486
  : first;
2487
+ let selectedTemplate: string | undefined;
2488
+ if (parsed.path === "templates render") {
2489
+ const selector = first!;
2490
+ selectedTemplate = selector;
2491
+ if (parseNameReference(selector)) {
2492
+ await getStore();
2493
+ const context = swarmContext();
2494
+ readContext = context;
2495
+ selectedTemplate = (
2496
+ await resolveReference(
2497
+ context,
2498
+ selector,
2499
+ selectedSwarm,
2500
+ (reference) => state!.resolve(reference),
2501
+ false,
2502
+ "local-first",
2503
+ )
2504
+ ).cid;
2505
+ store = context.store;
2506
+ } else {
2507
+ let explicit = false;
2508
+ try {
2509
+ CID.parse(selector);
2510
+ explicit = true;
2511
+ } catch {
2512
+ /* Not a CID. */
2513
+ }
2514
+ explicit ||= selector.toLowerCase().endsWith(".car");
2515
+ if (!explicit) {
2516
+ try {
2517
+ await lstat(selector);
2518
+ explicit = true;
2519
+ } catch (cause) {
2520
+ if (
2521
+ !nodeError(cause, "ENOENT") &&
2522
+ !nodeError(cause, "ENOTDIR")
2523
+ )
2524
+ throw cause;
2525
+ }
2526
+ }
2527
+ if (!explicit) {
2528
+ templateName(selector);
2529
+ if (!selectedSwarm)
2530
+ throw new HostError(
2531
+ "Template selectors require a selected Swarm. Use --swarm or swarm use, or supply an explicit Bundle directory, CAR, exact CID or IPAB URI.",
2532
+ );
2533
+ await getStore();
2534
+ const context = swarmContext();
2535
+ readContext = context;
2536
+ selectedTemplate = await resolveTemplateSelector(
2537
+ context,
2538
+ selector,
2539
+ selectedSwarm,
2540
+ );
2541
+ store = context.store;
2542
+ }
2543
+ }
2544
+ }
1766
2545
  if (parsed.path === "bundle build" || parsed.path === "build")
1767
2546
  io.err(
1768
2547
  parsed.path === "build"
@@ -1772,21 +2551,16 @@ async function performCli(
1772
2551
  if (parsed.path === "bundle import")
1773
2552
  io.err("Validating and importing CAR into Store...");
1774
2553
  const result =
1775
- parsed.path === "init"
1776
- ? await initApp(first!, second, {
2554
+ parsed.path === "templates render"
2555
+ ? await initApp(second!, parsed.positional[2], {
1777
2556
  ...request,
1778
- ...(typeof parsed.options.template === "string"
1779
- ? {
1780
- template: state.pin(parsed.options.template)?.builtin
1781
- ? parsed.options.template
1782
- : state.pin(parsed.options.template)
1783
- ? state.resolve(parsed.options.template)
1784
- : parsed.options.template,
1785
- }
1786
- : {}),
1787
- ...(parsed.parameters
1788
- ? { parameters: parsed.parameters }
1789
- : {}),
2557
+ ...(selectedTemplate ? { template: selectedTemplate } : {}),
2558
+ parameters: [
2559
+ ...(parsed.parameters ?? []),
2560
+ ...(typeof parsed.options.description === "string"
2561
+ ? [`description=${parsed.options.description}`]
2562
+ : []),
2563
+ ],
1790
2564
  })
1791
2565
  : parsed.path === "build"
1792
2566
  ? await assembleBundle(first, {
@@ -1851,7 +2625,7 @@ async function performCli(
1851
2625
  result.files.includes("ipab.json"))
1852
2626
  )
1853
2627
  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.`,
2628
+ `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
2629
  );
1856
2630
  else if (result.files.includes(".bundle.yaml"))
1857
2631
  io.err(
@@ -1878,128 +2652,74 @@ async function performCli(
1878
2652
  break;
1879
2653
  }
1880
2654
  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
- );
2655
+ const listed = state.contentPins();
2656
+ const archived = state.archivedPins();
2657
+ const builtins = state.pins().map(pinDetails);
1914
2658
  emit(
1915
- { items: listed, pending, invalid },
2659
+ { items: listed, builtins, archived },
1916
2660
  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.",
2661
+ ["REFERENCE", "CID", "STATUS", "SOURCE"],
2662
+ [
2663
+ ...listed.map((pin) => [
2664
+ pin.reference,
2665
+ pin.cid ?? "(none)",
2666
+ `${pin.status}/${pin.freshness}${pin.error ? `: ${pin.error}` : ""}`,
2667
+ pin.swarm ? "following shared Name" : "fixed CID",
2668
+ ]),
2669
+ ...builtins.map((pin) => [
2670
+ pin.name,
2671
+ pin.cid,
2672
+ "read-only",
2673
+ "built-in",
2674
+ ]),
2675
+ ...archived.map((pin) => [
2676
+ pin.cid,
2677
+ pin.cid,
2678
+ pin.status,
2679
+ `inactive archive (${pin.name}); unpin exact CID`,
2680
+ ]),
2681
+ ],
2682
+ "No pins.",
1927
2683
  ),
1928
2684
  );
1929
2685
  break;
1930
2686
  }
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
- );
1939
- emit(
1940
- 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!);
2687
+ case "unpin": {
2688
+ const canonical = pinReference(state, first!, selectedSwarm);
2689
+ const result = await unpin(state, canonical.reference);
1947
2690
  emit(
1948
2691
  result,
1949
- `Deleted ${first}; released only its retention responsibility. No blocks deleted or GC requested.`,
2692
+ `Unpinned ${canonical.reference}; released only its saved retention responsibility. No blocks deleted or GC requested.`,
1950
2693
  );
1951
2694
  break;
1952
2695
  }
1953
2696
  case "pin show": {
1954
- const pin = state.pin(first!);
1955
- if (!pin)
2697
+ const builtin = first!.startsWith("builtin:")
2698
+ ? state.pin(first!)
2699
+ : undefined;
2700
+ const canonical = builtin
2701
+ ? undefined
2702
+ : pinReference(state, first!, selectedSwarm);
2703
+ const pin = canonical
2704
+ ? state.contentPin(canonical.reference)
2705
+ : undefined;
2706
+ const archived = canonical
2707
+ ? state
2708
+ .archivedPins()
2709
+ .filter((pin) => pin.cid === canonical.reference)
2710
+ : [];
2711
+ if (!pin && !builtin && !archived.length)
1956
2712
  throw new HostError(
1957
2713
  `Pin "${first}" does not exist. Run ipab pin list.`,
1958
2714
  );
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}.`);
2715
+ const result = builtin
2716
+ ? pinDetails(builtin)
2717
+ : {
2718
+ pin: pin ?? null,
2719
+ roots: pin ? state.hold(pin.owner)?.roots : [],
2720
+ archived,
2721
+ };
2722
+ emit(result, JSON.stringify(result, null, 2));
2003
2723
  break;
2004
2724
  }
2005
2725
  case "config get": {
@@ -2127,6 +2847,15 @@ async function performCli(
2127
2847
  }
2128
2848
  case "exec":
2129
2849
  case "open": {
2850
+ const named =
2851
+ parsed.path === "open" ? parseNameReference(first!) : undefined;
2852
+ const registrySwarm = named?.swarm
2853
+ ? state.resolveSwarm(named.swarm)
2854
+ : selectedSwarm;
2855
+ if (parsed.path === "open" && !registrySwarm)
2856
+ throw new HostError(
2857
+ "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.",
2858
+ );
2130
2859
  if (parsed.options.log && !value("history.enabled"))
2131
2860
  throw new HostError(
2132
2861
  "Execution logging requires history.enabled=true.",
@@ -2134,6 +2863,7 @@ async function performCli(
2134
2863
  await recoverInactive(state);
2135
2864
  store = new IpfsStore(await storeConfiguration(value("store.gateway")));
2136
2865
  const context = swarmContext();
2866
+ readContext = context;
2137
2867
  const target = (
2138
2868
  await resolveReference(
2139
2869
  context,
@@ -2141,6 +2871,7 @@ async function performCli(
2141
2871
  selectedSwarm,
2142
2872
  (reference) => state!.resolve(reference),
2143
2873
  Boolean(parsed.options.raw),
2874
+ "local-first",
2144
2875
  )
2145
2876
  ).cid;
2146
2877
  store = context.store;
@@ -2164,8 +2895,13 @@ async function performCli(
2164
2895
  ? state!.resolveSwarm(preferredSwarm)
2165
2896
  : selectedSwarm;
2166
2897
  const resolve = (source: string | undefined) =>
2167
- resolveReference(lookup, reference, source, (input) =>
2168
- state!.resolve(input),
2898
+ resolveReference(
2899
+ lookup,
2900
+ reference,
2901
+ source,
2902
+ (input) => state!.resolve(input),
2903
+ false,
2904
+ "local-first",
2169
2905
  );
2170
2906
  let resolved;
2171
2907
  try {
@@ -2191,7 +2927,11 @@ async function performCli(
2191
2927
  signal.throwIfAborted();
2192
2928
  return { ...resolved, ...(swarm ? { swarm } : {}) };
2193
2929
  } finally {
2194
- await lookup.store.close();
2930
+ try {
2931
+ await lookup.finishRead?.();
2932
+ } finally {
2933
+ await lookup.store.close();
2934
+ }
2195
2935
  }
2196
2936
  };
2197
2937
  let appCid: string;
@@ -2207,15 +2947,39 @@ async function performCli(
2207
2947
  try {
2208
2948
  const content = await validatedBundle(root, store, owner);
2209
2949
  const schema = content.schemaKey;
2210
- const association = state.association(schema);
2950
+ let association: Association | undefined;
2951
+ if (registrySwarm) {
2952
+ const lookup: SwarmContext = {
2953
+ ...swarmContext(),
2954
+ store: new IpfsStore(
2955
+ await storeConfiguration(value("store.gateway")),
2956
+ ),
2957
+ };
2958
+ try {
2959
+ association = await swarmAssociation(
2960
+ lookup,
2961
+ registrySwarm,
2962
+ schema,
2963
+ "local-first",
2964
+ );
2965
+ } finally {
2966
+ try {
2967
+ await lookup.finishRead?.();
2968
+ } finally {
2969
+ await lookup.store.close();
2970
+ }
2971
+ }
2972
+ }
2211
2973
  if (!association)
2212
2974
  throw new HostError(
2213
- `No App registered for Schema ${schema}. Use ipab register set or ipab exec.`,
2975
+ `No App registered for Schema ${schema} in Swarm ${registrySwarm}. Use ipab register set ${schema} APP_CID --swarm ${registrySwarm} or ipab exec.`,
2214
2976
  );
2215
2977
  appCid = association.appCid;
2216
- appArgv = association.argv.map((argument) =>
2217
- argument === "%" ? root : argument,
2218
- );
2978
+ if (association.argv.length !== 1 || association.argv[0] !== "%")
2979
+ throw new HostError(
2980
+ "Custom per-association argv is unsupported; adapt the App to accept only the content CID or use ipab exec APP_CID ARGS.",
2981
+ );
2982
+ appArgv = [root];
2219
2983
  // execute owns the App/input context before this validation owner's eventual release.
2220
2984
  const result = await execute(
2221
2985
  state,
@@ -2268,8 +3032,11 @@ async function performCli(
2268
3032
  return error instanceof HostError ? error.exitCode : 1;
2269
3033
  } finally {
2270
3034
  try {
2271
- await readContext?.finishRead?.();
2272
- await closeStore(store, appExitCode);
3035
+ try {
3036
+ await readContext?.finishRead?.();
3037
+ } finally {
3038
+ await closeStore(store, appExitCode);
3039
+ }
2273
3040
  } finally {
2274
3041
  state?.close();
2275
3042
  }