@ipab/cli 0.1.0-rc.14 → 0.1.0-rc.16

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 (52) hide show
  1. package/dist/authoring.d.ts +3 -1
  2. package/dist/authoring.d.ts.map +1 -1
  3. package/dist/authoring.js +14 -2
  4. package/dist/authoring.js.map +1 -1
  5. package/dist/builtins/skill.ipab.car +0 -0
  6. package/dist/builtins/template.bundle-viewer.car +0 -0
  7. package/dist/builtins/template.web-app.car +0 -0
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +62 -45
  10. package/dist/cli.js.map +1 -1
  11. package/dist/daemon-api.d.ts.map +1 -1
  12. package/dist/daemon-api.js +59 -19
  13. package/dist/daemon-api.js.map +1 -1
  14. package/dist/daemon-client.d.ts +67 -20
  15. package/dist/daemon-client.d.ts.map +1 -1
  16. package/dist/daemon-client.js.map +1 -1
  17. package/dist/publish-source.d.ts +8 -1
  18. package/dist/publish-source.d.ts.map +1 -1
  19. package/dist/publish-source.js +71 -13
  20. package/dist/publish-source.js.map +1 -1
  21. package/dist/swarm-fs-core.d.ts +7 -2
  22. package/dist/swarm-fs-core.d.ts.map +1 -1
  23. package/dist/swarm-fs-core.js +30 -4
  24. package/dist/swarm-fs-core.js.map +1 -1
  25. package/dist/swarm.d.ts +21 -1
  26. package/dist/swarm.d.ts.map +1 -1
  27. package/dist/swarm.js +186 -49
  28. package/dist/swarm.js.map +1 -1
  29. package/dist/template-source.d.ts +1 -1
  30. package/dist/template-source.d.ts.map +1 -1
  31. package/dist/template-source.js +1 -6
  32. package/dist/template-source.js.map +1 -1
  33. package/dist/templates.d.ts +2 -1
  34. package/dist/templates.d.ts.map +1 -1
  35. package/dist/templates.js +11 -2
  36. package/dist/templates.js.map +1 -1
  37. package/dist/unixfs-tree.d.ts +1 -1
  38. package/dist/unixfs-tree.d.ts.map +1 -1
  39. package/dist/unixfs-tree.js +5 -2
  40. package/dist/unixfs-tree.js.map +1 -1
  41. package/package.json +3 -3
  42. package/src/authoring.ts +21 -9
  43. package/src/cli.ts +67 -49
  44. package/src/daemon-api.ts +74 -20
  45. package/src/daemon-client.ts +62 -22
  46. package/src/publish-source.ts +98 -12
  47. package/src/swarm-fs-core.ts +47 -3
  48. package/src/swarm.ts +281 -54
  49. package/src/template-source.ts +1 -6
  50. package/src/templates.ts +16 -1
  51. package/src/unixfs-tree.ts +3 -1
  52. package/dist/builtins/template.check.car +0 -0
package/src/cli.ts CHANGED
@@ -37,9 +37,7 @@ import type {
37
37
  replicateSwarm,
38
38
  requestMembership,
39
39
  grantPivotAuthority,
40
- setSwarmTemplate,
41
40
  removeSwarmTemplate,
42
- setSwarmSkill,
43
41
  removeSwarmSkill,
44
42
  swarmTypeSkills,
45
43
  SwarmContext,
@@ -149,7 +147,7 @@ const commands: Record<string, string> = {
149
147
  "swarm use": "swarm use URL_OR_ALIAS",
150
148
  "swarm remove": "swarm remove URL_OR_ALIAS",
151
149
  "swarm update": "swarm update [--name TEXT] [--description TEXT]",
152
- publish: "publish NAME SOURCE [--expect OLD_CID | --snapshot]",
150
+ publish: "publish NAME SOURCE [--expect OLD_CID]",
153
151
  get: "get REF [--raw] [--refresh | --no-refresh] [-o DIRECTORY]",
154
152
  search:
155
153
  "search QUERY [--all | --current] [--prefix PATH] [--kind all|bundle|dir|file] [--schema CID] [--limit N] [--offset N] [--refresh | --no-refresh]",
@@ -180,7 +178,8 @@ const commands: Record<string, string> = {
180
178
  "store gc": "store gc",
181
179
  "fs ls": "fs ls [PATH] [--all] [--recursive] [--refresh | --no-refresh]",
182
180
  "fs stat": "fs stat PATH [--refresh | --no-refresh]",
183
- "fs set": "fs set PATH CID [--expect OLD_CID | --replace]",
181
+ "fs set":
182
+ "fs set PATH CID [--expect OLD_CID | --replace]\n ipab fs set PATH --source SOURCE [--expect OLD_CID | --replace]",
184
183
  "fs rm": "fs rm PATH [--expect OLD_CID]",
185
184
  "history list": "history list [OPTIONS]",
186
185
  "history show": "history show RUN_ID",
@@ -194,7 +193,7 @@ const groups: Record<string, string> = {
194
193
  pin: "Retain an exact CID or follow a shared Swarm Name",
195
194
  register: "Associate content types with Apps",
196
195
  templates: "Inspect, render and manage Template Bundles",
197
- fs: "Inspect and modify paths in a Swarm UnixFS tree",
196
+ fs: "Bind raw CIDs in a Swarm UnixFS tree, without Artifact wrapping",
198
197
  config: "Manage local configuration",
199
198
  store: "Query local storage and collect unreferenced blocks",
200
199
  history: "View and remove execution history",
@@ -217,7 +216,7 @@ const commandHelp: Record<
217
216
  "Maintains membership and network topology: probes pivot candidates, refreshes approved profiles and retries with cooldown. Diagnostics go to stderr.",
218
217
  "Synchronizes the latest HEAD/State and automatically syncs Skills (to universal), Templates and Registry App Bundles for each activated Swarm on startup and every swarm.syncInterval seconds (default 60; IPAB_SWARM_SYNC_INTERVAL). Preserves local edits and other sources.",
219
218
  "Serves a read-only loopback status WebUI on 127.0.0.1 (automatic port by default; configurable via daemon.uiPort / IPAB_DAEMON_UI_PORT). Inspect or open it with `ipab daemon ui [--open]`.",
220
- "Swarm network operations start one background daemon on demand per state-dir; local commands, doctor and status/members inspections do not. No OS startup service is installed.",
219
+ "Normal operations reuse one background daemon on demand per state-dir, including local source binding. Help/version, doctor and stateless local authoring remain direct. No OS startup service is installed.",
221
220
  "Ctrl-C / TERM drains foreground operations and releases the device/state-dir lock; Kubo stays running. An existing background daemon already owns this lock.",
222
221
  "Role and relay candidate changes restart only the verified managed Kubo node.",
223
222
  ],
@@ -650,10 +649,9 @@ const commandHelp: Record<
650
649
  ],
651
650
  },
652
651
  publish: {
653
- summary: "Protect content locally and publish a shared Swarm Name",
652
+ summary: "Protect content locally and publish an Artifact version",
654
653
  options: [
655
654
  "--expect CID Exact old Name target CID, required for iteration.",
656
- "--snapshot Name ordinary content without an Artifact; initial only.",
657
655
  ],
658
656
  examples: [
659
657
  "ipab --swarm work publish apps/hello app.car",
@@ -663,7 +661,8 @@ const commandHelp: Record<
663
661
  notes: [
664
662
  "SOURCE is an exact Bundle CID, CAR, regular file or directory. No compiler, hooks, install or App execution.",
665
663
  "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.",
666
- "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.",
664
+ "Every valid Content Bundle, including App and Meta, creates an Artifact. Occupied Names require --expect EXACT_OLD_CID, never the unwrapped payload. The exact old Bundle is previous; no synthetic baseline is created.",
665
+ "For direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID]. --snapshot is rejected (exit 2). Unlike old initial-only snapshots, FS allows same-target no-op. Current payloads have ordinary CID pins; previous history has independent protection.",
667
666
  "Different-name CAS contention is rebased; same-name edits conflict (exit 3).",
668
667
  "Kubo pin confirmation precedes HEAD; it does not prove a remote device is online.",
669
668
  ],
@@ -875,7 +874,7 @@ const commandHelp: Record<
875
874
  "Releases only this pin's ownership on its original backend; no block deletion or GC.",
876
875
  "Never re-resolves a shared Name to release content. Uses only saved actual roots. Missing pins are success.",
877
876
  "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.",
878
- "Publication/history owners are independent; --snapshot payloads remain recursively retained by publication history after ordinary unpin.",
877
+ "Publication/history owners are independent; previous version payloads remain protected after ordinary unpin. Current unreferenced payloads can be collected after their ordinary pins are released.",
879
878
  ],
880
879
  },
881
880
  "pin list": {
@@ -990,6 +989,7 @@ const commandHelp: Record<
990
989
  options: [
991
990
  "--expect OLD_CID Require the current path CID to match OLD_CID before replacing.",
992
991
  "--replace Allow replacing an existing different CID at PATH.",
992
+ "--source SOURCE Prepare a valid Bundle from CID/CAR/directory/project or .json/.yaml/.yml/.md/.txt; mutually exclusive with CID.",
993
993
  ],
994
994
  examples: [
995
995
  "ipab fs set docs/guide bafy...",
@@ -999,6 +999,7 @@ const commandHelp: Record<
999
999
  notes: [
1000
1000
  "Requires a State v7 UnixFS Swarm root; legacy (v2-v6) Swarms are not implicitly migrated.",
1001
1001
  "Protected v7 root metadata files (.bundle.yaml, typeFile, entryFile) cannot be overwritten.",
1002
+ "Raw CID inputs are not Bundle-only and never unwrapped or Artifact-wrapped. Source preparation and binding are one protected Daemon operation; result.cid is the direct content CID.",
1002
1003
  ],
1003
1004
  },
1004
1005
  "fs rm": {
@@ -1087,7 +1088,7 @@ const commandHelp: Record<
1087
1088
 
1088
1089
  export function help(path = ""): string {
1089
1090
  const globalOptions = `Global options (before COMMAND):
1090
- --swarm URL|ALIAS Select Swarm (defaults to built-in local Swarm or saved swarm.default; URI swarm takes precedence)
1091
+ --swarm URL|ALIAS Select one Swarm: URI authority > flag > saved swarm.default > unsaved built-in local; saved null never falls back
1091
1092
  --state-dir PATH Set a dedicated, account-private local state directory
1092
1093
  --store-gateway URL Use a read-only upstream HTTP gateway
1093
1094
  --json Output management/development metadata, not App stdio`;
@@ -1098,30 +1099,37 @@ export function help(path = ""): string {
1098
1099
 
1099
1100
  Usage: ipab [GLOBAL_OPTIONS] COMMAND
1100
1101
 
1101
- Run Apps:
1102
- exec ${commandHelp.exec!.summary}
1103
- open ${commandHelp.open!.summary}
1102
+ Swarm management:
1103
+ swarm ${groups.swarm}
1104
+
1105
+ Shared file tree and Artifacts:
1106
+ fs ${groups.fs}
1107
+ publish Create an Artifact version for every valid Content Bundle
1108
+ search Search formal Names in the current swarm
1104
1109
 
1105
- Create:
1110
+ Shared associations and resources:
1111
+ register ${groups.register}
1106
1112
  templates ${groups.templates}
1113
+ skills ${groups.skills}
1114
+
1115
+ Content preparation and use:
1107
1116
  build ${commandHelp.build!.summary}
1108
1117
  bundle ${groups.bundle}
1109
-
1110
- Manage:
1111
- doctor ${commandHelp.doctor!.summary}
1112
- profile ${commandHelp.profile!.summary}
1113
- swarm ${groups.swarm}
1114
- fs ${groups.fs}
1115
- skills ${groups.skills}
1116
- search Search formal Names in the current swarm
1117
- publish ${commandHelp.publish!.summary}
1118
1118
  get ${commandHelp.get!.summary}
1119
+ exec ${commandHelp.exec!.summary}
1120
+ open ${commandHelp.open!.summary}
1121
+
1122
+ Local retention and execution records:
1119
1123
  pin ${groups.pin}
1120
1124
  unpin ${commandHelp.unpin!.summary}
1121
- register ${groups.register}
1125
+ history ${groups.history}
1126
+
1127
+ Account, configuration and runtime:
1128
+ profile ${commandHelp.profile!.summary}
1122
1129
  config ${groups.config}
1123
1130
  store ${groups.store}
1124
- history ${groups.history}
1131
+ doctor ${commandHelp.doctor!.summary}
1132
+ daemon Manage this state-dir runtime; daemon ui [--open]
1125
1133
 
1126
1134
  ${globalOptions}
1127
1135
  -h, --help Show help for the current command
@@ -1400,8 +1408,12 @@ export function parse(argv: readonly string[]): Parsed {
1400
1408
  syntax(
1401
1409
  "Root init was removed. Use ipab templates render TEMPLATE NAME [DIR]; TEMPLATE is the first positional argument, not --template.",
1402
1410
  );
1403
- if (group === "templates" && swarms.length > 1)
1404
- syntax("Templates accepts only one global --swarm, before the command.");
1411
+ if (group !== "register" && swarms.length > 1)
1412
+ syntax("Single-domain operations accept at most one --swarm.");
1413
+ if (group === "publish" && tokens.includes("--snapshot"))
1414
+ syntax(
1415
+ "--snapshot was removed. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].",
1416
+ );
1405
1417
  if (group === "daemon" && swarms.length)
1406
1418
  syntax("daemon manages all registered Swarms and does not accept --swarm.");
1407
1419
  const result: Parsed = {
@@ -1599,7 +1611,9 @@ export function parse(argv: readonly string[]): Parsed {
1599
1611
  "fs set",
1600
1612
  "fs rm",
1601
1613
  ].includes(result.path)
1602
- ? ["expect"]
1614
+ ? result.path === "fs set"
1615
+ ? ["expect", "source"]
1616
+ : ["expect"]
1603
1617
  : result.path === "get"
1604
1618
  ? ["output"]
1605
1619
  : result.path === "search"
@@ -1798,7 +1812,7 @@ export function parse(argv: readonly string[]): Parsed {
1798
1812
  "templates remove": [1, 1],
1799
1813
  "fs ls": [0, 1],
1800
1814
  "fs stat": [1, 1],
1801
- "fs set": [2, 2],
1815
+ "fs set": [1, 2],
1802
1816
  "fs rm": [1, 1],
1803
1817
  "config get": [0, 1],
1804
1818
  "config set": [2, 2],
@@ -1861,10 +1875,6 @@ export function parse(argv: readonly string[]): Parsed {
1861
1875
  formalName(result.positional[0]!);
1862
1876
  if (typeof result.options.expect === "string")
1863
1877
  exactCid(result.options.expect);
1864
- if (result.options.expect && result.options.snapshot)
1865
- syntax(
1866
- "--snapshot is initial-only and cannot be combined with --expect.",
1867
- );
1868
1878
  }
1869
1879
  if (
1870
1880
  result.path.startsWith("templates ") &&
@@ -1893,7 +1903,12 @@ export function parse(argv: readonly string[]): Parsed {
1893
1903
  allowRoot: false,
1894
1904
  allowTrailingSlash: false,
1895
1905
  });
1896
- exactCid(result.positional[1]!);
1906
+ if (
1907
+ (result.positional[1] !== undefined) ===
1908
+ (result.options.source !== undefined)
1909
+ )
1910
+ syntax("fs set requires exactly one CID or --source SOURCE.");
1911
+ if (result.positional[1] !== undefined) exactCid(result.positional[1]);
1897
1912
  if (typeof result.options.expect === "string")
1898
1913
  exactCid(result.options.expect);
1899
1914
  if (result.options.expect !== undefined && result.options.replace)
@@ -2510,7 +2525,7 @@ async function performCli(
2510
2525
  }
2511
2526
  } else if (parsed.path === "templates set") {
2512
2527
  const source = await resolveLocalPathIfPresent(second!);
2513
- const item = (await client.swarms.fsSet(
2528
+ const item = await client.swarms.fsSet(
2514
2529
  {
2515
2530
  swarm: configUrl,
2516
2531
  kind: "template",
@@ -2519,7 +2534,7 @@ async function performCli(
2519
2534
  expect: expected,
2520
2535
  },
2521
2536
  { ndjson: true },
2522
- )) as unknown as Awaited<ReturnType<typeof setSwarmTemplate>>;
2537
+ );
2523
2538
  emit(
2524
2539
  item,
2525
2540
  `${item.reference} → ${item.targetCid} (Template ${item.templateCid})`,
@@ -2568,10 +2583,10 @@ async function performCli(
2568
2583
  ? await resolveLocalPathIfPresent(second!)
2569
2584
  : undefined;
2570
2585
  if (parsed.path === "register set" && targets.length > 1) {
2571
- const batch = (await client.swarms.fsSet(
2586
+ const batch = await client.swarms.fsSet(
2572
2587
  {
2573
2588
  swarm: targets[0]!,
2574
- swarms: targets,
2589
+ swarms: [targets[0]!, ...targets.slice(1)],
2575
2590
  kind: "register",
2576
2591
  schema: first!,
2577
2592
  app: resolvedApp!,
@@ -2579,7 +2594,7 @@ async function performCli(
2579
2594
  replace: Boolean(parsed.options.replace),
2580
2595
  },
2581
2596
  { ndjson: true },
2582
- )) as unknown as { associations: Association[] };
2597
+ );
2583
2598
  for (let i = 0; i < targets.length; i++) {
2584
2599
  const association = batch.associations[i]!;
2585
2600
  results.push({ association });
@@ -2614,7 +2629,7 @@ async function performCli(
2614
2629
  )}`,
2615
2630
  );
2616
2631
  } else if (parsed.path === "register set") {
2617
- const association = (await client.swarms.fsSet(
2632
+ const association = await client.swarms.fsSet(
2618
2633
  {
2619
2634
  swarm: configUrl,
2620
2635
  kind: "register",
@@ -2624,7 +2639,7 @@ async function performCli(
2624
2639
  replace: Boolean(parsed.options.replace),
2625
2640
  },
2626
2641
  { ndjson: true },
2627
- )) as unknown as Association;
2642
+ );
2628
2643
  results.push({ association });
2629
2644
  human.push(
2630
2645
  `${configUrl}: ${association.schemaCid} → ${association.appCid} ${JSON.stringify(association.argv)}`,
@@ -2823,11 +2838,15 @@ async function performCli(
2823
2838
  break;
2824
2839
  }
2825
2840
  case "fs set": {
2841
+ const target =
2842
+ typeof parsed.options.source === "string"
2843
+ ? { source: await resolveLocalPathIfPresent(parsed.options.source) }
2844
+ : { cid: second! };
2826
2845
  const result = await client.swarms.fsSet(
2827
2846
  {
2828
2847
  swarm: requireSwarm(),
2829
2848
  path: first!,
2830
- cid: second!,
2849
+ ...target,
2831
2850
  ...(typeof parsed.options.expect === "string"
2832
2851
  ? { expect: parsed.options.expect }
2833
2852
  : {}),
@@ -2924,7 +2943,7 @@ async function performCli(
2924
2943
  case "skills set": {
2925
2944
  const targetSwarm = requireSwarm();
2926
2945
  const skill = await resolveLocalPathIfPresent(first!);
2927
- const result = (await client.swarms.fsSet(
2946
+ const result = await client.swarms.fsSet(
2928
2947
  {
2929
2948
  swarm: targetSwarm,
2930
2949
  kind: "skill",
@@ -2934,7 +2953,7 @@ async function performCli(
2934
2953
  replace: Boolean(parsed.options.replace),
2935
2954
  },
2936
2955
  { ndjson: true },
2937
- )) as unknown as Awaited<ReturnType<typeof setSwarmSkill>>;
2956
+ );
2938
2957
  const text = result.changed
2939
2958
  ? [
2940
2959
  `Skill: ${result.identity} (${result.cid})`,
@@ -3608,7 +3627,7 @@ async function performCli(
3608
3627
  ? resolveSwarm(named.swarm)
3609
3628
  : requireSwarm();
3610
3629
  const source = await resolveLocalPathIfPresent(second!);
3611
- const result = (await client.swarms.fsSet(
3630
+ const result = await client.swarms.fsSet(
3612
3631
  {
3613
3632
  swarm: targetSwarm,
3614
3633
  kind: "publish",
@@ -3617,12 +3636,11 @@ async function performCli(
3617
3636
  ...(typeof parsed.options.expect === "string"
3618
3637
  ? { expect: parsed.options.expect }
3619
3638
  : {}),
3620
- snapshot: Boolean(parsed.options.snapshot),
3621
3639
  },
3622
3640
  { ndjson: true },
3623
- )) as unknown as { cid: string; contentCid: string };
3641
+ );
3624
3642
  io.err(
3625
- `Locally protected payload: ${result.contentCid}. Use ipab unpin ${result.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.`,
3643
+ `Locally protected payload: ${result.contentCid}. Use ipab unpin ${result.contentCid} to release this CID pin only; Name subscriptions and publication/history owners remain.`,
3626
3644
  );
3627
3645
  emit(result, result.cid);
3628
3646
  break;
package/src/daemon-api.ts CHANGED
@@ -63,9 +63,13 @@ import {
63
63
  } from "./history.js";
64
64
  import { ContextHandler } from "./ipc.js";
65
65
  import { logFiles } from "./logs.js";
66
- import { parseNameReference, templateName } from "./name-reference.js";
66
+ import {
67
+ formalName,
68
+ parseNameReference,
69
+ templateName,
70
+ } from "./name-reference.js";
71
+ import { normalizeSwarmFsPath } from "./swarm-fs-core.js";
67
72
  import { pinDetails, unpin } from "./pins.js";
68
- import { publicationSource } from "./publish-source.js";
69
73
  import {
70
74
  listSwarmFsPath,
71
75
  removeSwarmFsPath,
@@ -76,13 +80,13 @@ import {
76
80
  accountProfile,
77
81
  approveMembership,
78
82
  artifactValue,
83
+ bindPublicationSource,
79
84
  createSwarm,
80
85
  exportRequest,
81
86
  grantPivotAuthority,
82
87
  inspectSwarmStatus,
83
88
  pinNameSubscription,
84
89
  pinReference,
85
- publish,
86
90
  removeMember,
87
91
  removeSwarmAssociation,
88
92
  removeSwarmSkill,
@@ -1030,8 +1034,8 @@ export class DaemonService {
1030
1034
  return {
1031
1035
  pattern: "/v1/swarms/fs/set",
1032
1036
  params: {},
1033
- handler: ({ body, diagnostic }) =>
1034
- this.handleSwarmFsSet(body, diagnostic),
1037
+ handler: ({ body, signal, diagnostic }) =>
1038
+ this.handleSwarmFsSet(body, diagnostic, signal),
1035
1039
  };
1036
1040
  }
1037
1041
  if (method === "POST" && pathname === "/v1/swarms/fs/rm") {
@@ -1982,27 +1986,63 @@ export class DaemonService {
1982
1986
  private async handleSwarmFsSet(
1983
1987
  body: Record<string, unknown>,
1984
1988
  diagnostic: (text: string, progress?: boolean) => void,
1989
+ signal: AbortSignal,
1985
1990
  ): Promise<unknown> {
1991
+ if (Object.hasOwn(body, "snapshot"))
1992
+ syntax(
1993
+ "--snapshot was removed. For a direct binding use ipab fs set NAME --source SOURCE [--expect OLD_CID].",
1994
+ );
1995
+ const kind = body.kind === undefined ? "fs" : requireString(body, "kind");
1996
+ if (!["fs", "publish", "template", "register", "skill"].includes(kind))
1997
+ syntax(`Unknown binding kind "${kind}".`);
1998
+ if (kind === "fs") {
1999
+ if (Object.hasOwn(body, "cid") === Object.hasOwn(body, "source"))
2000
+ syntax("fs set requires exactly one cid or source.");
2001
+ if (optionalBoolean(body, "wrapArtifact"))
2002
+ syntax("Raw FS does not wrap Artifacts; use publish for a version.");
2003
+ normalizeSwarmFsPath(requireString(body, "path"));
2004
+ if (Object.hasOwn(body, "source")) requireString(body, "source");
2005
+ else exactCid(requireString(body, "cid"));
2006
+ const expect = optionalString(body, "expect");
2007
+ if (expect !== undefined) exactCid(expect);
2008
+ if (expect !== undefined && optionalBoolean(body, "replace"))
2009
+ syntax("Options expect and replace are mutually exclusive.");
2010
+ }
2011
+ if (kind === "publish") {
2012
+ if (
2013
+ [
2014
+ "replace",
2015
+ "cid",
2016
+ "path",
2017
+ "wrapArtifact",
2018
+ "validator",
2019
+ "versioned",
2020
+ ].some((field) => Object.hasOwn(body, field))
2021
+ )
2022
+ syntax(
2023
+ "Publish accepts name, source and an exact expect baseline; raw/replacement/version flags are not supported.",
2024
+ );
2025
+ formalName(requireString(body, "name"));
2026
+ requireString(body, "source");
2027
+ const expect = optionalString(body, "expect");
2028
+ if (expect !== undefined) exactCid(expect);
2029
+ }
1986
2030
  const swarm = requireSwarmParam(body);
1987
2031
  const url = this.state.resolveSwarm(swarm);
1988
- const kind = optionalString(body, "kind") ?? "fs";
1989
2032
 
1990
2033
  if (kind === "publish") {
1991
2034
  const name = requireString(body, "name");
1992
2035
  const source = requireString(body, "source");
1993
2036
  const expect = optionalString(body, "expect");
1994
- const snapshot = optionalBoolean(body, "snapshot") ?? false;
1995
2037
  return this.mutex.run(`swarm-fs:${url}`, () =>
1996
2038
  this.withSwarmContext(async (ctx) => {
1997
- const store = await this.getStore();
1998
- const contentCid = await publicationSource(source, store);
1999
- const cid = await publish(ctx, contentCid, {
2039
+ return bindPublicationSource(ctx, source, {
2000
2040
  swarm: url,
2001
2041
  name,
2042
+ kind: "publish",
2002
2043
  ...(expect !== undefined ? { expect } : {}),
2003
- snapshot,
2044
+ signal,
2004
2045
  });
2005
- return { cid, contentCid };
2006
2046
  }, diagnostic),
2007
2047
  );
2008
2048
  }
@@ -2192,15 +2232,35 @@ export class DaemonService {
2192
2232
  }
2193
2233
 
2194
2234
  const path = requireString(body, "path");
2195
- const cid = exactCid(requireString(body, "cid"));
2196
2235
  const expect = optionalString(body, "expect");
2197
2236
  const replace = optionalBoolean(body, "replace");
2198
2237
  const validator = optionalString(body, "validator");
2199
- const wrapArtifact = optionalBoolean(body, "wrapArtifact") ?? false;
2200
2238
 
2201
2239
  if (expect !== undefined && replace) {
2202
2240
  syntax("Options expect and replace are mutually exclusive.");
2203
2241
  }
2242
+ if (Object.hasOwn(body, "source")) {
2243
+ const source = requireString(body, "source");
2244
+ if (validator !== undefined)
2245
+ syntax(
2246
+ "Source bindings validate a Content Bundle; validator is only supported with cid.",
2247
+ );
2248
+ return this.mutex.run(`swarm-fs:${url}`, () =>
2249
+ this.withSwarmContext(
2250
+ (ctx) =>
2251
+ bindPublicationSource(ctx, source, {
2252
+ kind: "fs",
2253
+ swarm: url,
2254
+ name: path,
2255
+ ...(expect !== undefined ? { expect: exactCid(expect) } : {}),
2256
+ ...(replace !== undefined ? { replace } : {}),
2257
+ signal,
2258
+ }),
2259
+ diagnostic,
2260
+ ),
2261
+ );
2262
+ }
2263
+ const cid = exactCid(requireString(body, "cid"));
2204
2264
 
2205
2265
  if (validator === "template") {
2206
2266
  const store = await this.getStore();
@@ -2227,12 +2287,6 @@ export class DaemonService {
2227
2287
  syntax(`Unknown validator "${validator}".`);
2228
2288
  }
2229
2289
 
2230
- // If wrapArtifact is requested, validate the target exists as a block/bundle before committing.
2231
- if (wrapArtifact) {
2232
- const store = await this.getStore();
2233
- await store.block.get(cid);
2234
- }
2235
-
2236
2290
  return this.mutex.run(`swarm-fs:${url}`, () =>
2237
2291
  this.withSwarmContext(
2238
2292
  (ctx) =>
@@ -24,6 +24,65 @@ import type {
24
24
  SwarmFsListResult,
25
25
  SwarmFsStatResult,
26
26
  } from "./swarm-fs-core.js";
27
+ import type { Association } from "./state.js";
28
+ import type { setSwarmSkill, setSwarmTemplate } from "./swarm.js";
29
+
30
+ type FsBinding = {
31
+ kind?: "fs";
32
+ swarm: string;
33
+ path: string;
34
+ expect?: string | undefined;
35
+ replace?: boolean | undefined;
36
+ } & (
37
+ | { cid: string; source?: never; validator?: "template" | "app" | "bundle" }
38
+ | { source: string; cid?: never; validator?: never }
39
+ );
40
+ export type BindingRequest =
41
+ | FsBinding
42
+ | {
43
+ kind: "publish";
44
+ swarm: string;
45
+ name: string;
46
+ source: string;
47
+ expect?: string | undefined;
48
+ }
49
+ | {
50
+ kind: "template";
51
+ swarm: string;
52
+ name: string;
53
+ source: string;
54
+ expect?: string | undefined;
55
+ }
56
+ | ({
57
+ kind: "register";
58
+ swarm: string;
59
+ schema: string;
60
+ app: string;
61
+ argv?: string[];
62
+ replace?: boolean;
63
+ } & ({ swarms?: never } | { swarms: [string, ...string[]] }))
64
+ | {
65
+ kind: "skill";
66
+ swarm: string;
67
+ skill: string;
68
+ global?: boolean;
69
+ types?: string[];
70
+ replace?: boolean;
71
+ };
72
+
73
+ export type BindingResult<T extends BindingRequest> = T extends {
74
+ kind: "publish";
75
+ }
76
+ ? { cid: string; contentCid: string }
77
+ : T extends { kind: "template" }
78
+ ? Awaited<ReturnType<typeof setSwarmTemplate>>
79
+ : T extends { kind: "register"; swarms: string[] }
80
+ ? { associations: Association[] }
81
+ : T extends { kind: "register" }
82
+ ? Association
83
+ : T extends { kind: "skill" }
84
+ ? Awaited<ReturnType<typeof setSwarmSkill>>
85
+ : SetSwarmFsPathResult;
27
86
 
28
87
  export interface DaemonClientOptions {
29
88
  stateDir: string;
@@ -654,30 +713,11 @@ export class DaemonClient {
654
713
  options,
655
714
  ),
656
715
 
657
- fsSet: (
658
- params: {
659
- swarm: string;
660
- swarms?: string[] | undefined;
661
- kind?: "fs" | "publish" | "template" | "register" | "skill";
662
- path?: string | undefined;
663
- cid?: string | undefined;
664
- name?: string | undefined;
665
- source?: string | undefined;
666
- expect?: string | undefined;
667
- replace?: boolean | undefined;
668
- snapshot?: boolean | undefined;
669
- wrapArtifact?: boolean | undefined;
670
- validator?: "template" | "app" | "bundle" | undefined;
671
- schema?: string | undefined;
672
- app?: string | undefined;
673
- argv?: string[] | undefined;
674
- skill?: string | undefined;
675
- global?: boolean | undefined;
676
- types?: string[] | undefined;
677
- },
716
+ fsSet: <T extends BindingRequest>(
717
+ params: T,
678
718
  options?: DaemonRequestOptions,
679
719
  ) =>
680
- this.request<SetSwarmFsPathResult>(
720
+ this.request<BindingResult<T>>(
681
721
  "POST",
682
722
  "/v1/swarms/fs/set",
683
723
  params,