@ipab/cli 0.1.0-rc.11 → 0.1.0-rc.13

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 (151) hide show
  1. package/README.md +15 -10
  2. package/dist/authoring.d.ts +6 -2
  3. package/dist/authoring.d.ts.map +1 -1
  4. package/dist/authoring.js +65 -18
  5. package/dist/authoring.js.map +1 -1
  6. package/dist/builtins/skill.ipab.car +0 -0
  7. package/dist/cli-daemon.d.ts +14 -0
  8. package/dist/cli-daemon.d.ts.map +1 -0
  9. package/dist/cli-daemon.js +400 -0
  10. package/dist/cli-daemon.js.map +1 -0
  11. package/dist/cli.d.ts +2 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +1631 -1100
  14. package/dist/cli.js.map +1 -1
  15. package/dist/config-secret.js +1 -1
  16. package/dist/config-secret.js.map +1 -1
  17. package/dist/daemon-api.d.ts +80 -0
  18. package/dist/daemon-api.d.ts.map +1 -0
  19. package/dist/daemon-api.js +2411 -0
  20. package/dist/daemon-api.js.map +1 -0
  21. package/dist/daemon-client.d.ts +322 -0
  22. package/dist/daemon-client.d.ts.map +1 -0
  23. package/dist/daemon-client.js +400 -0
  24. package/dist/daemon-client.js.map +1 -0
  25. package/dist/daemon-protocol.d.ts +22 -0
  26. package/dist/daemon-protocol.d.ts.map +1 -0
  27. package/dist/daemon-protocol.js +39 -0
  28. package/dist/daemon-protocol.js.map +1 -0
  29. package/dist/daemon-telemetry.d.ts +86 -0
  30. package/dist/daemon-telemetry.d.ts.map +1 -0
  31. package/dist/daemon-telemetry.js +502 -0
  32. package/dist/daemon-telemetry.js.map +1 -0
  33. package/dist/daemon-ui.d.ts +69 -0
  34. package/dist/daemon-ui.d.ts.map +1 -1
  35. package/dist/daemon-ui.js +285 -4
  36. package/dist/daemon-ui.js.map +1 -1
  37. package/dist/daemon.d.ts +10 -0
  38. package/dist/daemon.d.ts.map +1 -1
  39. package/dist/daemon.js +289 -38
  40. package/dist/daemon.js.map +1 -1
  41. package/dist/history.d.ts +3 -1
  42. package/dist/history.d.ts.map +1 -1
  43. package/dist/history.js +16 -1
  44. package/dist/history.js.map +1 -1
  45. package/dist/identity.d.ts.map +1 -1
  46. package/dist/identity.js +7 -2
  47. package/dist/identity.js.map +1 -1
  48. package/dist/ipc.d.ts +19 -7
  49. package/dist/ipc.d.ts.map +1 -1
  50. package/dist/ipc.js +96 -70
  51. package/dist/ipc.js.map +1 -1
  52. package/dist/kubo-topology.d.ts +2 -0
  53. package/dist/kubo-topology.d.ts.map +1 -1
  54. package/dist/kubo-topology.js +17 -20
  55. package/dist/kubo-topology.js.map +1 -1
  56. package/dist/kubo.d.ts +5 -3
  57. package/dist/kubo.d.ts.map +1 -1
  58. package/dist/kubo.js +83 -13
  59. package/dist/kubo.js.map +1 -1
  60. package/dist/name-reference.d.ts +8 -0
  61. package/dist/name-reference.d.ts.map +1 -0
  62. package/dist/name-reference.js +63 -0
  63. package/dist/name-reference.js.map +1 -0
  64. package/dist/pins.d.ts.map +1 -1
  65. package/dist/pins.js +18 -3
  66. package/dist/pins.js.map +1 -1
  67. package/dist/pivot-rpc.d.ts +37 -2
  68. package/dist/pivot-rpc.d.ts.map +1 -1
  69. package/dist/pivot-rpc.js +188 -8
  70. package/dist/pivot-rpc.js.map +1 -1
  71. package/dist/search-index.d.ts.map +1 -1
  72. package/dist/search-index.js +1 -0
  73. package/dist/search-index.js.map +1 -1
  74. package/dist/skill-definition.d.ts +9 -0
  75. package/dist/skill-definition.d.ts.map +1 -1
  76. package/dist/skill-definition.js +26 -2
  77. package/dist/skill-definition.js.map +1 -1
  78. package/dist/skill-source.d.ts +1 -0
  79. package/dist/skill-source.d.ts.map +1 -1
  80. package/dist/skill-source.js +10 -4
  81. package/dist/skill-source.js.map +1 -1
  82. package/dist/skills.d.ts +8 -2
  83. package/dist/skills.d.ts.map +1 -1
  84. package/dist/skills.js +31 -2
  85. package/dist/skills.js.map +1 -1
  86. package/dist/state-storage.d.ts.map +1 -1
  87. package/dist/state-storage.js +2 -1
  88. package/dist/state-storage.js.map +1 -1
  89. package/dist/state.d.ts +1 -1
  90. package/dist/state.d.ts.map +1 -1
  91. package/dist/state.js +3 -2
  92. package/dist/state.js.map +1 -1
  93. package/dist/swarm-files.d.ts.map +1 -1
  94. package/dist/swarm-files.js +7 -2
  95. package/dist/swarm-files.js.map +1 -1
  96. package/dist/swarm-fs-core.d.ts +217 -0
  97. package/dist/swarm-fs-core.d.ts.map +1 -0
  98. package/dist/swarm-fs-core.js +885 -0
  99. package/dist/swarm-fs-core.js.map +1 -0
  100. package/dist/swarm-fs-path.d.ts +17 -0
  101. package/dist/swarm-fs-path.d.ts.map +1 -0
  102. package/dist/swarm-fs-path.js +46 -0
  103. package/dist/swarm-fs-path.js.map +1 -0
  104. package/dist/swarm-fs.d.ts +9 -0
  105. package/dist/swarm-fs.d.ts.map +1 -0
  106. package/dist/swarm-fs.js +21 -0
  107. package/dist/swarm-fs.js.map +1 -0
  108. package/dist/swarm-observations.d.ts +6 -0
  109. package/dist/swarm-observations.d.ts.map +1 -1
  110. package/dist/swarm-observations.js +28 -8
  111. package/dist/swarm-observations.js.map +1 -1
  112. package/dist/swarm.d.ts +134 -18
  113. package/dist/swarm.d.ts.map +1 -1
  114. package/dist/swarm.js +1293 -484
  115. package/dist/swarm.js.map +1 -1
  116. package/dist/unixfs-tree.d.ts +55 -0
  117. package/dist/unixfs-tree.d.ts.map +1 -1
  118. package/dist/unixfs-tree.js +361 -2
  119. package/dist/unixfs-tree.js.map +1 -1
  120. package/package.json +5 -5
  121. package/src/authoring.ts +88 -28
  122. package/src/cli-daemon.ts +482 -0
  123. package/src/cli.ts +2080 -1464
  124. package/src/config-secret.ts +1 -1
  125. package/src/daemon-api.ts +3148 -0
  126. package/src/daemon-client.ts +975 -0
  127. package/src/daemon-protocol.ts +61 -0
  128. package/src/daemon-telemetry.ts +656 -0
  129. package/src/daemon-ui.ts +364 -4
  130. package/src/daemon.ts +337 -43
  131. package/src/history.ts +26 -1
  132. package/src/identity.ts +10 -2
  133. package/src/ipc.ts +113 -79
  134. package/src/kubo-topology.ts +25 -22
  135. package/src/kubo.ts +127 -9
  136. package/src/name-reference.ts +91 -0
  137. package/src/pins.ts +23 -3
  138. package/src/pivot-rpc.ts +272 -14
  139. package/src/search-index.ts +1 -0
  140. package/src/skill-definition.ts +45 -3
  141. package/src/skill-source.ts +10 -4
  142. package/src/skills.ts +43 -2
  143. package/src/state-storage.ts +5 -1
  144. package/src/state.ts +3 -1
  145. package/src/swarm-files.ts +10 -2
  146. package/src/swarm-fs-core.ts +1461 -0
  147. package/src/swarm-fs-path.ts +68 -0
  148. package/src/swarm-fs.ts +104 -0
  149. package/src/swarm-observations.ts +40 -14
  150. package/src/swarm.ts +2149 -1033
  151. package/src/unixfs-tree.ts +447 -2
@@ -0,0 +1,68 @@
1
+ import { syntax } from "./host-error.js";
2
+
3
+ export interface NormalizedFsPath {
4
+ /** Normalized relative path; empty string for root "/". */
5
+ path: string;
6
+ /** Path segments; empty array for root "/". */
7
+ segments: string[];
8
+ /** True when the normalized path is root "/". */
9
+ isRoot: boolean;
10
+ }
11
+
12
+ // eslint-disable-next-line no-control-regex
13
+ const FORBIDDEN_PATH_CHARS = /[\\:%*?"<>|\u0000-\u001f\u007f]/;
14
+
15
+ /**
16
+ * Normalizes a Swarm UnixFS path and rejects unsafe or invalid syntax with
17
+ * exitCode 2 / INVALID_ARGUMENT.
18
+ */
19
+ export function normalizeSwarmFsPath(
20
+ input: string | undefined,
21
+ options?: { allowRoot?: boolean; allowTrailingSlash?: boolean },
22
+ ): NormalizedFsPath {
23
+ const allowRoot = options?.allowRoot ?? false;
24
+ const allowTrailingSlash = options?.allowTrailingSlash ?? false;
25
+
26
+ if (input === undefined || input === "") {
27
+ if (allowRoot) return { path: "", segments: [], isRoot: true };
28
+ syntax("Path must not be empty.");
29
+ }
30
+
31
+ if (input.length > 1024)
32
+ syntax("Path exceeds maximum length of 1024 characters.");
33
+
34
+ if (FORBIDDEN_PATH_CHARS.test(input))
35
+ syntax(`Path "${input}" contains forbidden characters.`);
36
+
37
+ if (input.includes("//"))
38
+ syntax(`Path "${input}" must not contain consecutive slashes.`);
39
+
40
+ if (input === "/" || input === ".") {
41
+ if (allowRoot) return { path: "", segments: [], isRoot: true };
42
+ syntax("Root path is not allowed for this operation.");
43
+ }
44
+
45
+ let normalized = input.startsWith("/") ? input.slice(1) : input;
46
+
47
+ if (normalized.endsWith("/")) {
48
+ if (!allowTrailingSlash)
49
+ syntax(`Trailing slash is not allowed in path "${input}".`);
50
+ normalized = normalized.slice(0, -1);
51
+ }
52
+
53
+ const segments = normalized.split("/");
54
+ for (const segment of segments) {
55
+ if (!segment || segment === "." || segment === "..")
56
+ syntax(`Path "${input}" contains an invalid segment "${segment}".`);
57
+ if (segment.endsWith(".") || segment.endsWith(" "))
58
+ syntax(
59
+ `Path "${input}" segment "${segment}" must not end with a dot or space.`,
60
+ );
61
+ }
62
+
63
+ return {
64
+ path: segments.join("/"),
65
+ segments,
66
+ isRoot: false,
67
+ };
68
+ }
@@ -0,0 +1,104 @@
1
+ import {
2
+ assertWritableSwarmFsPath,
3
+ createSwarmFs,
4
+ isV7Snapshot,
5
+ listSubtreeNames,
6
+ normalizeSwarmFsPath,
7
+ protectedRootNames,
8
+ resolveSnapshotName,
9
+ v7RootSkipFiles,
10
+ type BoundHead,
11
+ type CommitSwarmPathsOptions,
12
+ type CommitSwarmPathsResult,
13
+ type NormalizedFsPath,
14
+ type ReadSwarmSnapshotOptions,
15
+ type RemoveSwarmFsPathOptions,
16
+ type RemoveSwarmFsPathResult,
17
+ type SetSwarmFsPathOptions,
18
+ type SetSwarmFsPathResult,
19
+ type SwarmFs,
20
+ type SwarmFsListEntry,
21
+ type SwarmFsListResult,
22
+ type SwarmFsMutationPlan,
23
+ type SwarmFsNodeKind,
24
+ type SwarmFsNoopPlan,
25
+ type SwarmFsPlan,
26
+ type SwarmFsPlanContext,
27
+ type SwarmFsSnapshotContext,
28
+ type SwarmFsStatResult,
29
+ type SwarmFsTransport,
30
+ type SwarmReadMode,
31
+ } from "./swarm-fs-core.js";
32
+ import {
33
+ invalidateSwarmHeader,
34
+ lazyPrivateSource,
35
+ localHeader,
36
+ missingContent,
37
+ pointer,
38
+ prepareNamesPublication,
39
+ readSnapshot,
40
+ swarmHeader,
41
+ writeNamesHead,
42
+ } from "./swarm.js";
43
+
44
+ export {
45
+ assertWritableSwarmFsPath,
46
+ createSwarmFs,
47
+ isV7Snapshot,
48
+ listSubtreeNames,
49
+ normalizeSwarmFsPath,
50
+ protectedRootNames,
51
+ resolveSnapshotName,
52
+ v7RootSkipFiles,
53
+ type BoundHead,
54
+ type CommitSwarmPathsOptions,
55
+ type CommitSwarmPathsResult,
56
+ type NormalizedFsPath,
57
+ type ReadSwarmSnapshotOptions,
58
+ type RemoveSwarmFsPathOptions,
59
+ type RemoveSwarmFsPathResult,
60
+ type SetSwarmFsPathOptions,
61
+ type SetSwarmFsPathResult,
62
+ type SwarmFs,
63
+ type SwarmFsListEntry,
64
+ type SwarmFsListResult,
65
+ type SwarmFsMutationPlan,
66
+ type SwarmFsNodeKind,
67
+ type SwarmFsNoopPlan,
68
+ type SwarmFsPlan,
69
+ type SwarmFsPlanContext,
70
+ type SwarmFsSnapshotContext,
71
+ type SwarmFsStatResult,
72
+ type SwarmFsTransport,
73
+ type SwarmReadMode,
74
+ };
75
+
76
+ const defaultSwarmFs = createSwarmFs({
77
+ pointer,
78
+ writeNamesHead,
79
+ readSnapshot,
80
+ swarmHeader,
81
+ localHeader,
82
+ lazyPrivateSource,
83
+ invalidateSwarmHeader,
84
+ prepareNamesPublication,
85
+ missingContent,
86
+ });
87
+
88
+ export const readSwarmFsSnapshot: SwarmFs["readSwarmFsSnapshot"] = (...args) =>
89
+ defaultSwarmFs.readSwarmFsSnapshot(...args);
90
+
91
+ export const statSwarmFsPath: SwarmFs["statSwarmFsPath"] = (...args) =>
92
+ defaultSwarmFs.statSwarmFsPath(...args);
93
+
94
+ export const listSwarmFsPath: SwarmFs["listSwarmFsPath"] = (...args) =>
95
+ defaultSwarmFs.listSwarmFsPath(...args);
96
+
97
+ export const commitSwarmPaths: SwarmFs["commitSwarmPaths"] = (...args) =>
98
+ defaultSwarmFs.commitSwarmPaths(...args);
99
+
100
+ export const setSwarmFsPath: SwarmFs["setSwarmFsPath"] = (...args) =>
101
+ defaultSwarmFs.setSwarmFsPath(...args);
102
+
103
+ export const removeSwarmFsPath: SwarmFs["removeSwarmFsPath"] = (...args) =>
104
+ defaultSwarmFs.removeSwarmFsPath(...args);
@@ -6,6 +6,7 @@ import { nodeRecord, validateAddress, type PeerConnection } from "./kubo.js";
6
6
  import { isCanonicalPublicKey } from "@ipab/bundle/pointer/protocol";
7
7
  import type { PivotCandidate } from "./kubo-topology.js";
8
8
  import type { Organization } from "./swarm.js";
9
+ import { parsePivotStatus, type PivotStatus } from "./pivot-rpc.js";
9
10
 
10
11
  export type PivotLocalStatus =
11
12
  "selected" | "cooldown" | "unknown" | "self" | "candidate";
@@ -25,6 +26,14 @@ export interface NetworkingSnapshot {
25
26
  topology: string | null;
26
27
  pivots: PivotObservation[];
27
28
  account?: string;
29
+ readiness?: Record<
30
+ string,
31
+ {
32
+ observedAt: number;
33
+ status: PivotStatus | null;
34
+ error: string | null;
35
+ }
36
+ >;
28
37
  connections?: {
29
38
  observedAt: number | null;
30
39
  error: string | null;
@@ -96,6 +105,7 @@ const timestamp = (value: unknown): value is number =>
96
105
  const nullableError = (value: unknown): value is string | null =>
97
106
  value === null || (typeof value === "string" && value.length <= 2048);
98
107
  function sameAddresses(value: unknown, expected: readonly string[]): boolean {
108
+ if (value === null || value === undefined) return expected.length === 0;
99
109
  if (!Array.isArray(value)) return false;
100
110
  const addresses = value as unknown[];
101
111
  return (
@@ -172,6 +182,33 @@ function parseSnapshot(input: unknown): NetworkingSnapshot {
172
182
  throw new HostError("Duplicate local Pivot observation.");
173
183
  if (data.account !== undefined && !isCanonicalPublicKey(data.account))
174
184
  throw new HostError("Invalid observation account.");
185
+ let readiness: NetworkingSnapshot["readiness"];
186
+ if (data.readiness !== undefined) {
187
+ const saved = object(data.readiness, "Pivot readiness observations");
188
+ if (Object.keys(saved).length > 256)
189
+ throw new HostError("Too many Pivot readiness observations.");
190
+ readiness = Object.fromEntries(
191
+ Object.entries(saved).map(([peerId, input]) => {
192
+ const entry = object(input, "Pivot readiness observation");
193
+ if (
194
+ !/^[A-Za-z0-9]{32,128}$/.test(peerId) ||
195
+ !timestamp(entry.observedAt) ||
196
+ entry.observedAt > updatedAt ||
197
+ !nullableError(entry.error)
198
+ )
199
+ throw new HostError("Invalid Pivot readiness observation.");
200
+ return [
201
+ peerId,
202
+ {
203
+ observedAt: entry.observedAt,
204
+ status:
205
+ entry.status === null ? null : parsePivotStatus(entry.status),
206
+ error: entry.error,
207
+ },
208
+ ];
209
+ }),
210
+ );
211
+ }
175
212
  let connections: NetworkingSnapshot["connections"];
176
213
  if (data.connections !== undefined) {
177
214
  const saved = object(data.connections, "connection observation");
@@ -220,6 +257,7 @@ function parseSnapshot(input: unknown): NetworkingSnapshot {
220
257
  pivots,
221
258
  ...(typeof data.account === "string" ? { account: data.account } : {}),
222
259
  ...(connections ? { connections } : {}),
260
+ ...(readiness ? { readiness } : {}),
223
261
  };
224
262
  }
225
263
  export async function networkingAccount(
@@ -325,25 +363,13 @@ export async function readNetworkingSnapshot(
325
363
  );
326
364
  const selected = snapshot.pivots.filter((pivot) => pivot.selected);
327
365
  const bootstrap = selected.flatMap(({ addresses }) => addresses).sort();
328
- const relays = selected
329
- .flatMap(({ addresses }) => (addresses[0] ? [addresses[0]] : []))
330
- .sort();
331
- const swarm = object(
332
- config?.Swarm ?? {},
333
- "local Kubo Swarm configuration",
334
- );
335
- const relayClient = object(
336
- swarm.RelayClient ?? {},
337
- "local Kubo relay configuration",
338
- );
339
366
  if (
340
367
  !config ||
341
368
  object(config.Identity, "local Kubo identity").PeerID !== peerId ||
342
- !sameAddresses(config.Bootstrap, bootstrap) ||
343
- !sameAddresses(relayClient.StaticRelays, relays)
369
+ !sameAddresses(config.Bootstrap, bootstrap)
344
370
  )
345
371
  topologyError =
346
- "Current Bootstrap/StaticRelays differ from the observed applied selection.";
372
+ "Current Bootstrap differs from the observed applied selection.";
347
373
  }
348
374
  } else topologyError = "No existing managed node.";
349
375
  return {