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

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 (150) hide show
  1. package/README.md +96 -34
  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 +6 -45
  5. package/dist/app-authoring.js.map +1 -1
  6. package/dist/app-prebuild.d.ts +18 -0
  7. package/dist/app-prebuild.d.ts.map +1 -1
  8. package/dist/app-prebuild.js +46 -0
  9. package/dist/app-prebuild.js.map +1 -1
  10. package/dist/app-templates.d.ts +0 -1
  11. package/dist/app-templates.d.ts.map +1 -1
  12. package/dist/app-templates.js +6 -45
  13. package/dist/app-templates.js.map +1 -1
  14. package/dist/builtins/skill.ipab.car +0 -0
  15. package/dist/builtins/template.bundle-viewer.car +0 -0
  16. package/dist/builtins/template.check.car +0 -0
  17. package/dist/builtins/template.node.car +0 -0
  18. package/dist/builtins/template.web-app.car +0 -0
  19. package/dist/builtins.d.ts.map +1 -1
  20. package/dist/builtins.js +1 -39
  21. package/dist/builtins.js.map +1 -1
  22. package/dist/cli.d.ts +1 -0
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js +668 -221
  25. package/dist/cli.js.map +1 -1
  26. package/dist/config.d.ts +1 -1
  27. package/dist/config.d.ts.map +1 -1
  28. package/dist/config.js +9 -4
  29. package/dist/config.js.map +1 -1
  30. package/dist/context.d.ts +20 -0
  31. package/dist/context.d.ts.map +1 -1
  32. package/dist/context.js +31 -2
  33. package/dist/context.js.map +1 -1
  34. package/dist/errors.d.ts +1 -8
  35. package/dist/errors.d.ts.map +1 -1
  36. package/dist/errors.js +1 -20
  37. package/dist/errors.js.map +1 -1
  38. package/dist/host-error.d.ts +9 -0
  39. package/dist/host-error.d.ts.map +1 -0
  40. package/dist/host-error.js +21 -0
  41. package/dist/host-error.js.map +1 -0
  42. package/dist/ipc.d.ts +2 -1
  43. package/dist/ipc.d.ts.map +1 -1
  44. package/dist/ipc.js +61 -3
  45. package/dist/ipc.js.map +1 -1
  46. package/dist/kubo-install.js +1 -1
  47. package/dist/kubo-install.js.map +1 -1
  48. package/dist/kubo-peers.d.ts.map +1 -1
  49. package/dist/kubo-peers.js +2 -1
  50. package/dist/kubo-peers.js.map +1 -1
  51. package/dist/kubo-topology.d.ts +19 -0
  52. package/dist/kubo-topology.d.ts.map +1 -0
  53. package/dist/kubo-topology.js +105 -0
  54. package/dist/kubo-topology.js.map +1 -0
  55. package/dist/kubo.d.ts +10 -0
  56. package/dist/kubo.d.ts.map +1 -1
  57. package/dist/kubo.js +96 -15
  58. package/dist/kubo.js.map +1 -1
  59. package/dist/runtime.d.ts.map +1 -1
  60. package/dist/runtime.js +6 -3
  61. package/dist/runtime.js.map +1 -1
  62. package/dist/skill-definition.d.ts +6 -0
  63. package/dist/skill-definition.d.ts.map +1 -0
  64. package/dist/skill-definition.js +38 -0
  65. package/dist/skill-definition.js.map +1 -0
  66. package/dist/skill-source.d.ts +5 -0
  67. package/dist/skill-source.d.ts.map +1 -0
  68. package/dist/skill-source.js +12 -0
  69. package/dist/skill-source.js.map +1 -0
  70. package/dist/skills.d.ts +84 -0
  71. package/dist/skills.d.ts.map +1 -0
  72. package/dist/skills.js +736 -0
  73. package/dist/skills.js.map +1 -0
  74. package/dist/space-path.d.ts +3 -0
  75. package/dist/space-path.d.ts.map +1 -0
  76. package/dist/space-path.js +17 -0
  77. package/dist/space-path.js.map +1 -0
  78. package/dist/space.d.ts +16 -4
  79. package/dist/space.d.ts.map +1 -1
  80. package/dist/space.js +155 -18
  81. package/dist/space.js.map +1 -1
  82. package/dist/state-storage.js +1 -1
  83. package/dist/state-storage.js.map +1 -1
  84. package/dist/state.d.ts +2 -0
  85. package/dist/state.d.ts.map +1 -1
  86. package/dist/state.js +32 -13
  87. package/dist/state.js.map +1 -1
  88. package/dist/swarm-files.d.ts +2 -2
  89. package/dist/swarm-files.d.ts.map +1 -1
  90. package/dist/swarm-files.js +4 -4
  91. package/dist/swarm-files.js.map +1 -1
  92. package/dist/swarm-meta.d.ts +14 -0
  93. package/dist/swarm-meta.d.ts.map +1 -0
  94. package/dist/swarm-meta.js +65 -0
  95. package/dist/swarm-meta.js.map +1 -0
  96. package/dist/swarm-observations.d.ts +40 -0
  97. package/dist/swarm-observations.d.ts.map +1 -0
  98. package/dist/swarm-observations.js +262 -0
  99. package/dist/swarm-observations.js.map +1 -0
  100. package/dist/swarm.d.ts +172 -6
  101. package/dist/swarm.d.ts.map +1 -1
  102. package/dist/swarm.js +1106 -132
  103. package/dist/swarm.js.map +1 -1
  104. package/dist/template-paths.d.ts +7 -0
  105. package/dist/template-paths.d.ts.map +1 -0
  106. package/dist/template-paths.js +23 -0
  107. package/dist/template-paths.js.map +1 -0
  108. package/dist/template-presentation.d.ts +20 -0
  109. package/dist/template-presentation.d.ts.map +1 -0
  110. package/dist/template-presentation.js +133 -0
  111. package/dist/template-presentation.js.map +1 -0
  112. package/dist/template-source.d.ts +2 -1
  113. package/dist/template-source.d.ts.map +1 -1
  114. package/dist/template-source.js +7 -1
  115. package/dist/template-source.js.map +1 -1
  116. package/dist/templates.d.ts +11 -0
  117. package/dist/templates.d.ts.map +1 -0
  118. package/dist/templates.js +53 -0
  119. package/dist/templates.js.map +1 -0
  120. package/package.json +7 -6
  121. package/src/app-authoring.ts +30 -55
  122. package/src/app-prebuild.ts +61 -0
  123. package/src/app-templates.ts +8 -72
  124. package/src/builtins.ts +2 -48
  125. package/src/cli.ts +830 -247
  126. package/src/config.ts +12 -4
  127. package/src/context.ts +60 -2
  128. package/src/errors.ts +1 -25
  129. package/src/host-error.ts +26 -0
  130. package/src/ipc.ts +82 -2
  131. package/src/kubo-install.ts +1 -1
  132. package/src/kubo-peers.ts +2 -3
  133. package/src/kubo-topology.ts +135 -0
  134. package/src/kubo.ts +134 -25
  135. package/src/runtime.ts +6 -2
  136. package/src/skill-definition.ts +53 -0
  137. package/src/skill-source.ts +15 -0
  138. package/src/skills.ts +1005 -0
  139. package/src/space-path.ts +30 -0
  140. package/src/space.ts +216 -33
  141. package/src/state-storage.ts +1 -1
  142. package/src/state.ts +38 -13
  143. package/src/swarm-files.ts +4 -2
  144. package/src/swarm-meta.ts +90 -0
  145. package/src/swarm-observations.ts +374 -0
  146. package/src/swarm.ts +1637 -193
  147. package/src/template-paths.ts +43 -0
  148. package/src/template-presentation.ts +151 -0
  149. package/src/template-source.ts +9 -2
  150. package/src/templates.ts +77 -0
@@ -1,12 +1,12 @@
1
- import { fileURLToPath } from "node:url";
2
1
  import { resolve } from "node:path";
3
- import { lstat, readFile } from "node:fs/promises";
2
+ import { lstat } from "node:fs/promises";
4
3
  import { Liquid, type Template } from "liquidjs";
5
4
  import { parseBundleManifest } from "@ipab/bundle";
6
5
  import {
7
6
  listTree,
8
7
  readBytes,
9
8
  type ReadonlyFileTree,
9
+ type TreeEntry,
10
10
  } from "@ipab/bundle-builder";
11
11
  import { filesystemTree } from "@ipab/bundle-builder/node";
12
12
  import { HostError, object } from "./errors.js";
@@ -16,14 +16,10 @@ import {
16
16
  templateDefinition,
17
17
  templateParameters,
18
18
  } from "./template-definition.js";
19
- import { builtinTemplateSource, templateSource } from "./template-source.js";
19
+ import { templateSource } from "./template-source.js";
20
+ import { addTemplateOutputPath, templateOutputPath } from "./template-paths.js";
20
21
  import { nodeError } from "./authoring.js";
21
22
 
22
- export const builtinTemplateNames = new Map([
23
- ["builtin:template.node", "node"],
24
- ["builtin:template.web-app", "web-app"],
25
- ] as const);
26
-
27
23
  function appName(name: string) {
28
24
  if (
29
25
  !/^[a-z0-9][a-z0-9._-]*$/.test(name) ||
@@ -260,7 +256,7 @@ export async function renderTemplate(
260
256
  );
261
257
  const values = templateParameters(definition, name, options.parameters);
262
258
  const files = new Map<string, string | Uint8Array>();
263
- const paths = new Map<string, string>();
259
+ const paths = new Map<string, TreeEntry["kind"]>();
264
260
  let count = 0,
265
261
  total = 0;
266
262
  const collect = async (directory: string, depth: number): Promise<void> => {
@@ -270,35 +266,8 @@ export async function renderTemplate(
270
266
  if (++count > 256)
271
267
  throw new HostError("Template exceeds 256 project paths.");
272
268
  const source = `${directory}/${entry.name}`;
273
- relativePath(source);
274
- const original = source.slice("project/".length);
275
- const rendered = entry.kind === "file" && original.endsWith(".liquid");
276
- const target = relativePath(
277
- rendered ? original.slice(0, -".liquid".length) : original,
278
- );
279
- if (
280
- target
281
- .split("/")
282
- .some(
283
- (part) =>
284
- ["node_modules", ".git", "dist"].includes(part.toLowerCase()) ||
285
- /^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/i.test(part),
286
- )
287
- )
288
- throw new HostError(`Unsafe template output path: ${target}.`);
289
- const key = target.toLowerCase();
290
- if (
291
- paths.has(key) ||
292
- [...paths].some(
293
- ([existing, kind]) =>
294
- (kind === "file" && key.startsWith(`${existing}/`)) ||
295
- (entry.kind === "file" && existing.startsWith(`${key}/`)),
296
- )
297
- )
298
- throw new HostError(
299
- `Duplicate or overlapping template output path: ${target}.`,
300
- );
301
- paths.set(key, entry.kind);
269
+ const { target, rendered } = templateOutputPath(source, entry.kind);
270
+ addTemplateOutputPath(paths, target, entry.kind);
302
271
  if (entry.kind === "directory") {
303
272
  await collect(source, depth + 1);
304
273
  continue;
@@ -333,39 +302,6 @@ export async function appTemplate(
333
302
  options: AuthoringOptions & { parameters?: readonly string[] },
334
303
  ): Promise<{ files: Map<string, string | Uint8Array>; cid: string | null }> {
335
304
  options.signal?.throwIfAborted();
336
- for (const [alias, name] of builtinTemplateNames)
337
- if (selector === alias) selector = name;
338
- if (selector === "node" || selector === "web-app") {
339
- appName(name);
340
- const loaded = await builtinTemplateSource(selector, options);
341
- const parameters = [...(options.parameters ?? [])];
342
- if (
343
- selector === "web-app" &&
344
- !parameters.some((value) => value.startsWith("webAppDependency="))
345
- ) {
346
- const framework = object(
347
- JSON.parse(
348
- await readFile(
349
- fileURLToPath(import.meta.resolve("@ipab/web-app/package.json")),
350
- "utf8",
351
- ),
352
- ) as unknown,
353
- "Web App framework package",
354
- );
355
- if (typeof framework.version !== "string" || !framework.version.trim())
356
- throw new HostError(
357
- "Web App framework package is missing its version.",
358
- );
359
- parameters.push(`webAppDependency=${framework.version}`);
360
- }
361
- return {
362
- files: await renderTemplate(loaded.tree, name, {
363
- ...options,
364
- parameters,
365
- }),
366
- cid: loaded.cid,
367
- };
368
- }
369
305
  let legacy = false;
370
306
  try {
371
307
  await lstat(resolve(selector, ".bundle.yaml"));
@@ -396,7 +332,7 @@ export async function appTemplate(
396
332
  } catch (error) {
397
333
  if (nodeError(error, "ENOENT"))
398
334
  throw new HostError(
399
- `Unknown template "${selector}". Use node, web-app, a valid Bundle directory, single-root CAR, exact CID or packaged builtin reference. Local content aliases are unsupported.`,
335
+ `Unknown template "${selector}". Use a Swarm template selector, valid Bundle directory, single-root CAR, exact CID or IPAB URI. Builtin templates and local aliases are unsupported.`,
400
336
  );
401
337
  throw error;
402
338
  }
package/src/builtins.ts CHANGED
@@ -1,14 +1,6 @@
1
1
  import { builtinAppSchema } from "./app-definition.js";
2
- import {
3
- builtinTemplateSchema,
4
- templateSchemaCid,
5
- } from "./template-definition.js";
6
- import { builtinTemplateNames } from "./app-templates.js";
7
- import { builtinTemplateSource } from "./template-source.js";
8
- import { openBundle } from "@ipab/bundle";
9
- import { fileURLToPath } from "node:url";
10
- import { readCar } from "./authoring.js";
11
- import type { NamedPin, PinMetadata } from "./state.js";
2
+ import { builtinTemplateSchema } from "./template-definition.js";
3
+ import type { NamedPin } from "./state.js";
12
4
 
13
5
  async function loadBuiltins(): Promise<{
14
6
  pins: readonly NamedPin[];
@@ -16,16 +8,6 @@ async function loadBuiltins(): Promise<{
16
8
  }> {
17
9
  const pins: NamedPin[] = [];
18
10
  const blocks = new Map<string, Uint8Array>();
19
- const add = (name: string, cid: string, metadata: PinMetadata) => {
20
- pins.push({
21
- name,
22
- cid,
23
- owner: name,
24
- status: "ready",
25
- metadata,
26
- builtin: true,
27
- });
28
- };
29
11
  for (const schema of [
30
12
  await builtinAppSchema(),
31
13
  await builtinTemplateSchema(),
@@ -33,34 +15,6 @@ async function loadBuiltins(): Promise<{
33
15
  const cid = schema.cid.toString();
34
16
  blocks.set(cid, schema.bytes);
35
17
  }
36
- for (const [name, selector] of builtinTemplateNames) {
37
- const template = await builtinTemplateSource(selector);
38
- for (const [cid, bytes] of template.blocks) blocks.set(cid, bytes);
39
- add(name, template.cid, {
40
- kind: "bundle",
41
- title: template.manifest.title,
42
- schemaCid: templateSchemaCid.toString(),
43
- });
44
- }
45
- const skill = await readCar(
46
- fileURLToPath(new URL("../dist/builtins/skill.ipab.car", import.meta.url)),
47
- {},
48
- );
49
- const bundle = await openBundle(skill.root, { resolveCid: skill.resolveCid });
50
- if (
51
- bundle.manifest.entry !== "SKILL.md" ||
52
- bundle.schema.type.contentType !== "text/markdown" ||
53
- bundle.validation.status !== "validated"
54
- )
55
- throw new Error(
56
- "Built-in IPAB Skill must be a validated Markdown Skill Bundle.",
57
- );
58
- for (const [cid, bytes] of skill.blocks) blocks.set(cid, bytes);
59
- add("builtin:skill.ipab", skill.root.toString(), {
60
- kind: "bundle",
61
- title: bundle.manifest.title,
62
- schemaCid: bundle.schemaKey,
63
- });
64
18
  return { pins, blocks };
65
19
  }
66
20