@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.
- package/README.md +96 -34
- package/dist/app-authoring.d.ts +5 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +6 -45
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-prebuild.d.ts +18 -0
- package/dist/app-prebuild.d.ts.map +1 -1
- package/dist/app-prebuild.js +46 -0
- package/dist/app-prebuild.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +6 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -39
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +668 -221
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -4
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +20 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +31 -2
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +1 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -20
- package/dist/errors.js.map +1 -1
- package/dist/host-error.d.ts +9 -0
- package/dist/host-error.d.ts.map +1 -0
- package/dist/host-error.js +21 -0
- package/dist/host-error.js.map +1 -0
- package/dist/ipc.d.ts +2 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +61 -3
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.js +1 -1
- package/dist/kubo-install.js.map +1 -1
- package/dist/kubo-peers.d.ts.map +1 -1
- package/dist/kubo-peers.js +2 -1
- package/dist/kubo-peers.js.map +1 -1
- package/dist/kubo-topology.d.ts +19 -0
- package/dist/kubo-topology.d.ts.map +1 -0
- package/dist/kubo-topology.js +105 -0
- package/dist/kubo-topology.js.map +1 -0
- package/dist/kubo.d.ts +10 -0
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +96 -15
- package/dist/kubo.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -3
- package/dist/runtime.js.map +1 -1
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +5 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +12 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +84 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +736 -0
- package/dist/skills.js.map +1 -0
- package/dist/space-path.d.ts +3 -0
- package/dist/space-path.d.ts.map +1 -0
- package/dist/space-path.js +17 -0
- package/dist/space-path.js.map +1 -0
- package/dist/space.d.ts +16 -4
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +155 -18
- package/dist/space.js.map +1 -1
- package/dist/state-storage.js +1 -1
- package/dist/state-storage.js.map +1 -1
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +32 -13
- package/dist/state.js.map +1 -1
- package/dist/swarm-files.d.ts +2 -2
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +4 -4
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm-meta.d.ts +14 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +65 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm-observations.d.ts +40 -0
- package/dist/swarm-observations.d.ts.map +1 -0
- package/dist/swarm-observations.js +262 -0
- package/dist/swarm-observations.js.map +1 -0
- package/dist/swarm.d.ts +172 -6
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1106 -132
- package/dist/swarm.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +2 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +7 -1
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/package.json +7 -6
- package/src/app-authoring.ts +30 -55
- package/src/app-prebuild.ts +61 -0
- package/src/app-templates.ts +8 -72
- package/src/builtins.ts +2 -48
- package/src/cli.ts +830 -247
- package/src/config.ts +12 -4
- package/src/context.ts +60 -2
- package/src/errors.ts +1 -25
- package/src/host-error.ts +26 -0
- package/src/ipc.ts +82 -2
- package/src/kubo-install.ts +1 -1
- package/src/kubo-peers.ts +2 -3
- package/src/kubo-topology.ts +135 -0
- package/src/kubo.ts +134 -25
- package/src/runtime.ts +6 -2
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +15 -0
- package/src/skills.ts +1005 -0
- package/src/space-path.ts +30 -0
- package/src/space.ts +216 -33
- package/src/state-storage.ts +1 -1
- package/src/state.ts +38 -13
- package/src/swarm-files.ts +4 -2
- package/src/swarm-meta.ts +90 -0
- package/src/swarm-observations.ts +374 -0
- package/src/swarm.ts +1637 -193
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +9 -2
- package/src/templates.ts +77 -0
package/src/app-templates.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
1
|
import { resolve } from "node:path";
|
|
3
|
-
import { lstat
|
|
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 {
|
|
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,
|
|
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
|
-
|
|
274
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|