@ipab/cli 0.1.0-rc.1 → 0.1.0-rc.11
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 +234 -9
- package/dist/app-authoring.d.ts +15 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +144 -58
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-definition.d.ts +52 -57
- package/dist/app-definition.d.ts.map +1 -1
- package/dist/app-definition.js +33 -38
- package/dist/app-definition.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 +8 -46
- package/dist/app-templates.js.map +1 -1
- package/dist/assembly.d.ts +7 -0
- package/dist/assembly.d.ts.map +1 -0
- package/dist/assembly.js +130 -0
- package/dist/assembly.js.map +1 -0
- package/dist/authoring.d.ts +7 -8
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +59 -16
- package/dist/authoring.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 -23
- package/dist/builtins.js.map +1 -1
- package/dist/bundled-skills.d.ts +14 -0
- package/dist/bundled-skills.d.ts.map +1 -0
- package/dist/bundled-skills.js +34 -0
- package/dist/bundled-skills.js.map +1 -0
- package/dist/cli.d.ts +8 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1967 -258
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.d.ts +3 -0
- package/dist/config-secret.d.ts.map +1 -0
- package/dist/config-secret.js +12 -0
- package/dist/config-secret.js.map +1 -0
- package/dist/config.d.ts +11 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +166 -8
- package/dist/config.js.map +1 -1
- package/dist/content-provider.d.ts +32 -0
- package/dist/content-provider.d.ts.map +1 -0
- package/dist/content-provider.js +222 -0
- package/dist/content-provider.js.map +1 -0
- package/dist/context-types.d.ts +12 -0
- package/dist/context-types.d.ts.map +1 -0
- package/dist/context-types.js +2 -0
- package/dist/context-types.js.map +1 -0
- package/dist/context.d.ts +26 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +54 -10
- package/dist/context.js.map +1 -1
- package/dist/daemon-ui.d.ts +93 -0
- package/dist/daemon-ui.d.ts.map +1 -0
- package/dist/daemon-ui.js +713 -0
- package/dist/daemon-ui.js.map +1 -0
- package/dist/daemon.d.ts +21 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +317 -0
- package/dist/daemon.js.map +1 -0
- package/dist/doctor.d.ts +32 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +688 -0
- package/dist/doctor.js.map +1 -0
- 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/get.d.ts +3 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +80 -0
- package/dist/get.js.map +1 -0
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +6 -14
- package/dist/history.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/identity.d.ts +16 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +119 -0
- package/dist/identity.js.map +1 -0
- package/dist/ipc.d.ts +5 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +124 -12
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +26 -0
- package/dist/kubo-install.d.ts.map +1 -0
- package/dist/kubo-install.js +724 -0
- package/dist/kubo-install.js.map +1 -0
- package/dist/kubo-peering.d.ts +11 -0
- package/dist/kubo-peering.d.ts.map +1 -0
- package/dist/kubo-peering.js +93 -0
- package/dist/kubo-peering.js.map +1 -0
- package/dist/kubo-peers.d.ts +12 -0
- package/dist/kubo-peers.d.ts.map +1 -0
- package/dist/kubo-peers.js +119 -0
- package/dist/kubo-peers.js.map +1 -0
- package/dist/kubo-release.d.ts +22 -0
- package/dist/kubo-release.d.ts.map +1 -0
- package/dist/kubo-release.js +176 -0
- package/dist/kubo-release.js.map +1 -0
- package/dist/kubo-topology.d.ts +19 -0
- package/dist/kubo-topology.d.ts.map +1 -0
- package/dist/kubo-topology.js +113 -0
- package/dist/kubo-topology.js.map +1 -0
- package/dist/kubo.d.ts +85 -0
- package/dist/kubo.d.ts.map +1 -0
- package/dist/kubo.js +755 -0
- package/dist/kubo.js.map +1 -0
- package/dist/pins.d.ts +16 -18
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +144 -106
- package/dist/pins.js.map +1 -1
- package/dist/pivot-rpc.d.ts +62 -0
- package/dist/pivot-rpc.d.ts.map +1 -0
- package/dist/pivot-rpc.js +407 -0
- package/dist/pivot-rpc.js.map +1 -0
- package/dist/pivot-service.d.ts +16 -0
- package/dist/pivot-service.d.ts.map +1 -0
- package/dist/pivot-service.js +50 -0
- package/dist/pivot-service.js.map +1 -0
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +9 -4
- package/dist/runtime.js.map +1 -1
- package/dist/search-index.d.ts +64 -0
- package/dist/search-index.d.ts.map +1 -0
- package/dist/search-index.js +409 -0
- package/dist/search-index.js.map +1 -0
- package/dist/search-service.d.ts +23 -0
- package/dist/search-service.d.ts.map +1 -0
- package/dist/search-service.js +116 -0
- package/dist/search-service.js.map +1 -0
- 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 +9 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +24 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +104 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +894 -0
- package/dist/skills.js.map +1 -0
- package/dist/source-bundle.d.ts +3 -8
- package/dist/source-bundle.d.ts.map +1 -1
- package/dist/source-bundle.js +17 -12
- package/dist/source-bundle.js.map +1 -1
- 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 +170 -24
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.d.ts +2 -0
- package/dist/state-storage-windows.d.ts.map +1 -0
- package/dist/state-storage-windows.js +114 -0
- package/dist/state-storage-windows.js.map +1 -0
- package/dist/state-storage.d.ts +5 -0
- package/dist/state-storage.d.ts.map +1 -0
- package/dist/state-storage.js +333 -0
- package/dist/state-storage.js.map +1 -0
- package/dist/state.d.ts +135 -13
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +577 -92
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +57 -0
- package/dist/swarm-envelope.d.ts.map +1 -0
- package/dist/swarm-envelope.js +299 -0
- package/dist/swarm-envelope.js.map +1 -0
- package/dist/swarm-files.d.ts +6 -0
- package/dist/swarm-files.d.ts.map +1 -0
- package/dist/swarm-files.js +116 -0
- package/dist/swarm-files.js.map +1 -0
- package/dist/swarm-meta.d.ts +15 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +68 -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 +271 -0
- package/dist/swarm-observations.js.map +1 -0
- package/dist/swarm.d.ts +537 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +4991 -0
- package/dist/swarm.js.map +1 -0
- package/dist/template-definition.d.ts +47 -52
- package/dist/template-definition.d.ts.map +1 -1
- package/dist/template-definition.js +36 -41
- package/dist/template-definition.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 +4 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +11 -4
- 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/dist/unixfs-tree.d.ts +67 -0
- package/dist/unixfs-tree.d.ts.map +1 -0
- package/dist/unixfs-tree.js +329 -0
- package/dist/unixfs-tree.js.map +1 -0
- package/package.json +14 -7
- package/src/app-authoring.ts +240 -76
- package/src/app-definition.ts +33 -39
- package/src/app-prebuild.ts +61 -0
- package/src/app-templates.ts +17 -73
- package/src/assembly.ts +185 -0
- package/src/authoring.ts +99 -18
- package/src/builtins.ts +2 -27
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +2461 -323
- package/src/config-secret.ts +14 -0
- package/src/config.ts +214 -8
- package/src/content-provider.ts +299 -0
- package/src/context-types.ts +11 -0
- package/src/context.ts +98 -10
- package/src/daemon-ui.ts +812 -0
- package/src/daemon.ts +386 -0
- package/src/doctor.ts +1092 -0
- package/src/errors.ts +1 -25
- package/src/get.ts +91 -0
- package/src/history.ts +5 -15
- package/src/host-error.ts +26 -0
- package/src/identity.ts +175 -0
- package/src/ipc.ts +160 -11
- package/src/kubo-install.ts +936 -0
- package/src/kubo-peering.ts +126 -0
- package/src/kubo-peers.ts +144 -0
- package/src/kubo-release.ts +230 -0
- package/src/kubo-topology.ts +148 -0
- package/src/kubo.ts +1088 -0
- package/src/pins.ts +188 -126
- package/src/pivot-rpc.ts +601 -0
- package/src/pivot-service.ts +87 -0
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +16 -4
- package/src/search-index.ts +560 -0
- package/src/search-service.ts +152 -0
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +29 -0
- package/src/skills.ts +1236 -0
- package/src/source-bundle.ts +26 -13
- package/src/space-path.ts +30 -0
- package/src/space.ts +230 -42
- package/src/state-storage-windows.ts +134 -0
- package/src/state-storage.ts +378 -0
- package/src/state.ts +875 -108
- package/src/swarm-envelope.ts +461 -0
- package/src/swarm-files.ts +126 -0
- package/src/swarm-meta.ts +98 -0
- package/src/swarm-observations.ts +393 -0
- package/src/swarm.ts +7392 -0
- package/src/template-definition.ts +36 -41
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +19 -5
- package/src/templates.ts +77 -0
- package/src/unixfs-tree.ts +401 -0
package/src/assembly.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { CID } from "multiformats/cid";
|
|
4
|
+
import { parseData, parseBundleManifest } from "@ipab/bundle";
|
|
5
|
+
import {
|
|
6
|
+
encodeBundleCar,
|
|
7
|
+
fileTree,
|
|
8
|
+
readBytes,
|
|
9
|
+
type FileReader,
|
|
10
|
+
} from "@ipab/bundle-builder";
|
|
11
|
+
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
12
|
+
import { HostError, object } from "./errors.js";
|
|
13
|
+
import { relativePath } from "./space.js";
|
|
14
|
+
import {
|
|
15
|
+
nodeError,
|
|
16
|
+
outputAvailable,
|
|
17
|
+
readCar,
|
|
18
|
+
writeCar,
|
|
19
|
+
type AuthoringOptions,
|
|
20
|
+
type BuildResult,
|
|
21
|
+
} from "./authoring.js";
|
|
22
|
+
|
|
23
|
+
function keys(value: Record<string, unknown>, allowed: string[]): void {
|
|
24
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
25
|
+
throw new HostError(
|
|
26
|
+
"Unknown assembly recipe field. Legacy App ipab.yaml/ipab.json is not a generic assembly recipe; run project preparation separately.",
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function assembleBundle(
|
|
31
|
+
source = ".",
|
|
32
|
+
options: AuthoringOptions & {
|
|
33
|
+
output?: string;
|
|
34
|
+
outputDir?: string;
|
|
35
|
+
replace?: boolean;
|
|
36
|
+
} = {},
|
|
37
|
+
): Promise<BuildResult> {
|
|
38
|
+
const input = resolve(source);
|
|
39
|
+
const stat = await lstat(input);
|
|
40
|
+
if (stat.isSymbolicLink())
|
|
41
|
+
throw new HostError("Assembly input must not be a symlink.");
|
|
42
|
+
const recipePath = stat.isDirectory()
|
|
43
|
+
? join(input, "ipab.build.yaml")
|
|
44
|
+
: input;
|
|
45
|
+
const root = dirname(recipePath);
|
|
46
|
+
const tree = await filesystemTree(root);
|
|
47
|
+
let recipeBytes: Uint8Array;
|
|
48
|
+
try {
|
|
49
|
+
recipeBytes = await readBytes(
|
|
50
|
+
tree,
|
|
51
|
+
basename(recipePath),
|
|
52
|
+
64 * 1024,
|
|
53
|
+
options,
|
|
54
|
+
);
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
if (stat.isDirectory()) {
|
|
57
|
+
for (const legacy of ["ipab.yaml", "ipab.json"]) {
|
|
58
|
+
try {
|
|
59
|
+
await lstat(join(root, legacy));
|
|
60
|
+
throw new HostError(
|
|
61
|
+
"Legacy App build configuration is unsupported by generic build. Run the project preparation script, then supply ipab.build.yaml.",
|
|
62
|
+
);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!nodeError(error, "ENOENT")) throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw cause;
|
|
69
|
+
}
|
|
70
|
+
const recipe = object(
|
|
71
|
+
parseData(recipeBytes, "application/yaml"),
|
|
72
|
+
"assembly recipe",
|
|
73
|
+
);
|
|
74
|
+
keys(recipe, ["version", "files", "imports"]);
|
|
75
|
+
if (
|
|
76
|
+
recipe.version !== 1 ||
|
|
77
|
+
!Array.isArray(recipe.files) ||
|
|
78
|
+
!Array.isArray(recipe.imports ?? [])
|
|
79
|
+
)
|
|
80
|
+
throw new HostError(
|
|
81
|
+
"Assembly recipe requires version: 1, files: [{source,target}], and optional imports: [{cid,target}].",
|
|
82
|
+
);
|
|
83
|
+
const files = new Map<string, FileReader>();
|
|
84
|
+
const paths: string[] = [];
|
|
85
|
+
const claim = (target: string) => {
|
|
86
|
+
relativePath(target);
|
|
87
|
+
const key = target.toLowerCase();
|
|
88
|
+
if (
|
|
89
|
+
paths.some(
|
|
90
|
+
(previous) =>
|
|
91
|
+
previous === key ||
|
|
92
|
+
previous.startsWith(`${key}/`) ||
|
|
93
|
+
key.startsWith(`${previous}/`),
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
throw new HostError(`Assembly target collision: ${target}.`);
|
|
97
|
+
paths.push(key);
|
|
98
|
+
};
|
|
99
|
+
files.set(".bundle.yaml", () => tree.read(".bundle.yaml", options));
|
|
100
|
+
claim(".bundle.yaml");
|
|
101
|
+
const definition = parseBundleManifest(
|
|
102
|
+
await readBytes(tree, ".bundle.yaml", 1024 * 1024, options),
|
|
103
|
+
);
|
|
104
|
+
const inputs = new Set<string>([resolve(root, ".bundle.yaml"), recipePath]);
|
|
105
|
+
for (const item of recipe.files) {
|
|
106
|
+
const mapping = object(item, "file mapping");
|
|
107
|
+
keys(mapping, ["source", "target"]);
|
|
108
|
+
if (
|
|
109
|
+
typeof mapping.source !== "string" ||
|
|
110
|
+
typeof mapping.target !== "string"
|
|
111
|
+
)
|
|
112
|
+
throw new HostError(
|
|
113
|
+
"Recipe file mappings require source and target strings.",
|
|
114
|
+
);
|
|
115
|
+
relativePath(mapping.source);
|
|
116
|
+
claim(mapping.target);
|
|
117
|
+
inputs.add(resolve(root, ...mapping.source.split("/")));
|
|
118
|
+
const sourcePath = mapping.source;
|
|
119
|
+
files.set(mapping.target, () => tree.read(sourcePath, options));
|
|
120
|
+
}
|
|
121
|
+
// CID grafts are processed sequentially; keep at most one local CAR in memory.
|
|
122
|
+
let localCar:
|
|
123
|
+
{ path: string; data: Awaited<ReturnType<typeof readCar>> } | undefined;
|
|
124
|
+
const imports = ((recipe.imports as unknown[] | undefined) ?? []).map(
|
|
125
|
+
(item) => {
|
|
126
|
+
const mapping = object(item, "CID import");
|
|
127
|
+
keys(mapping, ["cid", "target", "car"]);
|
|
128
|
+
if (typeof mapping.cid !== "string" || typeof mapping.target !== "string")
|
|
129
|
+
throw new HostError("CID imports require cid and target strings.");
|
|
130
|
+
const cid = CID.parse(mapping.cid);
|
|
131
|
+
claim(mapping.target);
|
|
132
|
+
if (mapping.car !== undefined) {
|
|
133
|
+
if (typeof mapping.car !== "string")
|
|
134
|
+
throw new HostError("CID import car must be a relative file path.");
|
|
135
|
+
const path = resolve(root, relativePath(mapping.car));
|
|
136
|
+
inputs.add(path);
|
|
137
|
+
return {
|
|
138
|
+
path: mapping.target,
|
|
139
|
+
cid,
|
|
140
|
+
resolveCid: async (block: CID) => {
|
|
141
|
+
if (localCar?.path !== path)
|
|
142
|
+
localCar = { path, data: await readCar(path, options, root) };
|
|
143
|
+
if (!localCar.data.root.equals(cid))
|
|
144
|
+
throw new HostError(
|
|
145
|
+
"CID import does not match the local CAR root.",
|
|
146
|
+
);
|
|
147
|
+
return localCar.data.resolveCid(block);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (!options.resolveCid)
|
|
152
|
+
throw new HostError("CID imports require a Store.");
|
|
153
|
+
return { path: mapping.target, cid, resolveCid: options.resolveCid };
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
if (
|
|
157
|
+
[definition.entry, definition.type].some(
|
|
158
|
+
(path) => !files.has(path) && !imports.some((item) => item.path === path),
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
throw new HostError(
|
|
162
|
+
"Recipe must explicitly select the Bundle entry and type files.",
|
|
163
|
+
);
|
|
164
|
+
const output = options.output
|
|
165
|
+
? resolve(options.output)
|
|
166
|
+
: join(root, options.outputDir ?? "dist", "bundle.car");
|
|
167
|
+
if ([...inputs].some((input) => input.toLowerCase() === output.toLowerCase()))
|
|
168
|
+
throw new HostError("CAR output cannot replace recipe or source inputs.");
|
|
169
|
+
await outputAvailable(output, Boolean(options.replace));
|
|
170
|
+
const encoded = await encodeBundleCar(fileTree(files), {
|
|
171
|
+
...options,
|
|
172
|
+
imports,
|
|
173
|
+
});
|
|
174
|
+
const result = {
|
|
175
|
+
kind: "content-bundle" as const,
|
|
176
|
+
cid: encoded.cid.toString(),
|
|
177
|
+
schemaCid: encoded.schema.cid.toString(),
|
|
178
|
+
output,
|
|
179
|
+
validation: encoded.validation,
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
...result,
|
|
183
|
+
bytes: await writeCar(encoded, output, Boolean(options.replace), options),
|
|
184
|
+
};
|
|
185
|
+
}
|
package/src/authoring.ts
CHANGED
|
@@ -28,12 +28,14 @@ import {
|
|
|
28
28
|
openBundle,
|
|
29
29
|
openSchema,
|
|
30
30
|
parseBundleManifest,
|
|
31
|
+
parseBundleType,
|
|
31
32
|
ContentBundleError,
|
|
32
33
|
} from "@ipab/bundle";
|
|
33
34
|
import type {
|
|
34
35
|
EntryValidation,
|
|
35
36
|
OpenBundleOptions,
|
|
36
37
|
SchemaBlock,
|
|
38
|
+
BundleManifest,
|
|
37
39
|
} from "@ipab/bundle";
|
|
38
40
|
import {
|
|
39
41
|
encodeBundleCar,
|
|
@@ -44,7 +46,8 @@ import {
|
|
|
44
46
|
import type { EncodedBundleCar } from "@ipab/bundle-builder";
|
|
45
47
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
46
48
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
47
|
-
import { HostError } from "./errors.js";
|
|
49
|
+
import { HostError, message } from "./errors.js";
|
|
50
|
+
import type { Ownership } from "./history.js";
|
|
48
51
|
import { builtinAppSchema, schemaAlias } from "./app-definition.js";
|
|
49
52
|
import {
|
|
50
53
|
builtinTemplateSchema,
|
|
@@ -69,9 +72,8 @@ export interface InspectResult {
|
|
|
69
72
|
sourceKind: "directory" | "definition" | "car" | "cid";
|
|
70
73
|
cid: string | null;
|
|
71
74
|
schemaCid: string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
entry: { path: string; contentType: string };
|
|
75
|
+
manifest?: BundleManifest;
|
|
76
|
+
type: SchemaBlock["type"];
|
|
75
77
|
validation: {
|
|
76
78
|
definition: "valid";
|
|
77
79
|
storage: "verified" | "not-applicable";
|
|
@@ -110,7 +112,7 @@ async function localFile(
|
|
|
110
112
|
return readBytes(tree, basename(path), maximum, options);
|
|
111
113
|
}
|
|
112
114
|
async function definitionAt(path: string, options: AuthoringOptions) {
|
|
113
|
-
return
|
|
115
|
+
return parseBundleType(
|
|
114
116
|
await localFile(path, bundleLimits.parsingBytes, options),
|
|
115
117
|
);
|
|
116
118
|
}
|
|
@@ -160,16 +162,23 @@ export async function selectedTree(
|
|
|
160
162
|
pathKey(path).startsWith(`${pathKey(outputDir)}/`)),
|
|
161
163
|
) ||
|
|
162
164
|
matcher.ignores(directory ? `${path}/` : path);
|
|
163
|
-
for (const required of [".bundle.yaml", definition.entry.
|
|
165
|
+
for (const required of [".bundle.yaml", definition.entry, definition.type])
|
|
164
166
|
if (excluded(required, false))
|
|
165
167
|
throw new HostError(
|
|
166
168
|
`Required bundle file is excluded: ${required}. Fix .bundle-ignore or choose an output outside the entry tree.`,
|
|
167
169
|
);
|
|
168
170
|
return filesystemTree(root, { exclude: excluded });
|
|
169
171
|
}
|
|
170
|
-
export async function readCar(
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
export async function readCar(
|
|
173
|
+
path: string,
|
|
174
|
+
options: AuthoringOptions,
|
|
175
|
+
directory = dirname(path),
|
|
176
|
+
) {
|
|
177
|
+
const tree = await filesystemTree(directory);
|
|
178
|
+
const input = await tree.read(
|
|
179
|
+
relative(directory, path).split(sep).join("/"),
|
|
180
|
+
options,
|
|
181
|
+
);
|
|
173
182
|
const chunks = streamChunks(input, options);
|
|
174
183
|
let bytes = 0;
|
|
175
184
|
try {
|
|
@@ -241,6 +250,62 @@ function cidInput(source: string): CID | undefined {
|
|
|
241
250
|
return undefined;
|
|
242
251
|
}
|
|
243
252
|
}
|
|
253
|
+
export async function localBundleDirectory(
|
|
254
|
+
source: string,
|
|
255
|
+
): Promise<string | undefined> {
|
|
256
|
+
if (
|
|
257
|
+
source.startsWith("ipab:") ||
|
|
258
|
+
source.startsWith("builtin:") ||
|
|
259
|
+
cidInput(source)
|
|
260
|
+
)
|
|
261
|
+
return undefined;
|
|
262
|
+
const path = resolve(source);
|
|
263
|
+
const stat = await existing(path);
|
|
264
|
+
if (!stat)
|
|
265
|
+
throw new HostError(
|
|
266
|
+
`Local open input does not exist: ${path}. Pass a Content Bundle directory containing .bundle.yaml, a Bundle CID or an IPAB URI.`,
|
|
267
|
+
);
|
|
268
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
269
|
+
throw new HostError(
|
|
270
|
+
`Local open input must be a regular Content Bundle directory, not a file or symbolic link: ${path}.`,
|
|
271
|
+
);
|
|
272
|
+
return path;
|
|
273
|
+
}
|
|
274
|
+
export async function snapshotBundle(
|
|
275
|
+
source: string,
|
|
276
|
+
owner: Ownership,
|
|
277
|
+
session: string,
|
|
278
|
+
options: AuthoringOptions = {},
|
|
279
|
+
): Promise<string> {
|
|
280
|
+
try {
|
|
281
|
+
const encoded = await encodeBundleCar(
|
|
282
|
+
await selectedTree(source, undefined, undefined, options),
|
|
283
|
+
options,
|
|
284
|
+
);
|
|
285
|
+
try {
|
|
286
|
+
const iterator = await CarBlockIterator.fromIterable(
|
|
287
|
+
streamChunks(encoded.stream, options),
|
|
288
|
+
);
|
|
289
|
+
for await (const block of iterator)
|
|
290
|
+
await owner.store.stageBlock(session, block.cid, block.bytes, options);
|
|
291
|
+
await owner.store.finishImport(
|
|
292
|
+
session,
|
|
293
|
+
encoded.cid,
|
|
294
|
+
owner.owner,
|
|
295
|
+
options,
|
|
296
|
+
);
|
|
297
|
+
const cid = encoded.cid.toString();
|
|
298
|
+
await owner.retain([cid], options.signal);
|
|
299
|
+
return cid;
|
|
300
|
+
} finally {
|
|
301
|
+
await encoded.close();
|
|
302
|
+
}
|
|
303
|
+
} catch (cause) {
|
|
304
|
+
throw new HostError(
|
|
305
|
+
`Cannot open local Bundle directory ${source}: ${message(cause)} Ensure .bundle.yaml, its type definition and entry form a valid Content Bundle.`,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
244
309
|
async function artifact(source: string, options: AuthoringOptions) {
|
|
245
310
|
if (source.startsWith("builtin:")) {
|
|
246
311
|
schemaAlias(source);
|
|
@@ -300,19 +365,18 @@ async function fromRoot(
|
|
|
300
365
|
});
|
|
301
366
|
return {
|
|
302
367
|
schema: bundle.schema,
|
|
368
|
+
manifest: bundle.manifest,
|
|
303
369
|
validation: bundle.validation,
|
|
304
370
|
kind: "content-bundle" as const,
|
|
305
371
|
sourceKind,
|
|
306
372
|
cid: root.toString(),
|
|
307
373
|
};
|
|
308
374
|
}
|
|
309
|
-
function summary(schema: SchemaBlock) {
|
|
310
|
-
const { name, description, entry } = schema.manifest;
|
|
375
|
+
function summary(schema: SchemaBlock, manifest?: BundleManifest) {
|
|
311
376
|
return {
|
|
312
377
|
schemaCid: schema.cid.toString(),
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
entry: { path: entry.path, contentType: entry.contentType },
|
|
378
|
+
type: schema.type,
|
|
379
|
+
...(manifest ? { manifest } : {}),
|
|
316
380
|
};
|
|
317
381
|
}
|
|
318
382
|
export async function inspectBundle(
|
|
@@ -335,7 +399,7 @@ export async function inspectBundle(
|
|
|
335
399
|
kind: "content-bundle",
|
|
336
400
|
sourceKind: "directory",
|
|
337
401
|
cid: null,
|
|
338
|
-
...summary(encoded.schema),
|
|
402
|
+
...summary(encoded.schema, encoded.manifest ?? undefined),
|
|
339
403
|
validation: {
|
|
340
404
|
definition: "valid",
|
|
341
405
|
storage: "verified",
|
|
@@ -351,7 +415,10 @@ export async function inspectBundle(
|
|
|
351
415
|
kind: loaded.kind,
|
|
352
416
|
sourceKind: loaded.sourceKind,
|
|
353
417
|
cid: loaded.cid,
|
|
354
|
-
...summary(
|
|
418
|
+
...summary(
|
|
419
|
+
loaded.schema,
|
|
420
|
+
"manifest" in loaded ? loaded.manifest : undefined,
|
|
421
|
+
),
|
|
355
422
|
validation: {
|
|
356
423
|
definition: "valid",
|
|
357
424
|
storage: loaded.kind === "content-bundle" ? "verified" : "not-applicable",
|
|
@@ -466,14 +533,28 @@ export async function buildBundle(
|
|
|
466
533
|
const output = options.output
|
|
467
534
|
? resolve(options.output)
|
|
468
535
|
: join(outputDirectory, options.schemaOnly ? "schema.car" : "bundle.car");
|
|
469
|
-
const
|
|
536
|
+
const manifestPath = join(root, ".bundle.yaml");
|
|
537
|
+
const manifest =
|
|
538
|
+
!options.schemaOnly || (await existing(manifestPath))
|
|
539
|
+
? parseBundleManifest(
|
|
540
|
+
await localFile(manifestPath, bundleLimits.manifestBytes, options),
|
|
541
|
+
)
|
|
542
|
+
: undefined;
|
|
543
|
+
const definitionPath = stat.isDirectory()
|
|
544
|
+
? join(root, manifest?.type ?? ".bundle-type.yaml")
|
|
545
|
+
: path;
|
|
470
546
|
const definition = await definitionAt(definitionPath, options);
|
|
471
547
|
if (
|
|
472
548
|
[
|
|
473
549
|
definitionPath,
|
|
474
550
|
join(root, ".bundle.yaml"),
|
|
475
551
|
join(root, ".bundle-ignore"),
|
|
476
|
-
|
|
552
|
+
...(manifest
|
|
553
|
+
? [
|
|
554
|
+
resolve(root, ...manifest.entry.split("/")),
|
|
555
|
+
resolve(root, ...manifest.type.split("/")),
|
|
556
|
+
]
|
|
557
|
+
: []),
|
|
477
558
|
].some((input) => pathKey(output) === pathKey(input))
|
|
478
559
|
)
|
|
479
560
|
throw new HostError(
|
package/src/builtins.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { builtinAppSchema } from "./app-definition.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
templateSchema,
|
|
5
|
-
templateSchemaCid,
|
|
6
|
-
} from "./template-definition.js";
|
|
7
|
-
import { builtinTemplateNames } from "./app-templates.js";
|
|
8
|
-
import { builtinTemplateSource } from "./template-source.js";
|
|
9
|
-
import type { NamedPin, PinMetadata } from "./state.js";
|
|
2
|
+
import { builtinTemplateSchema } from "./template-definition.js";
|
|
3
|
+
import type { NamedPin } from "./state.js";
|
|
10
4
|
|
|
11
5
|
async function loadBuiltins(): Promise<{
|
|
12
6
|
pins: readonly NamedPin[];
|
|
@@ -14,16 +8,6 @@ async function loadBuiltins(): Promise<{
|
|
|
14
8
|
}> {
|
|
15
9
|
const pins: NamedPin[] = [];
|
|
16
10
|
const blocks = new Map<string, Uint8Array>();
|
|
17
|
-
const add = (name: string, cid: string, metadata: PinMetadata) => {
|
|
18
|
-
pins.push({
|
|
19
|
-
name,
|
|
20
|
-
cid,
|
|
21
|
-
owner: name,
|
|
22
|
-
status: "ready",
|
|
23
|
-
metadata,
|
|
24
|
-
builtin: true,
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
11
|
for (const schema of [
|
|
28
12
|
await builtinAppSchema(),
|
|
29
13
|
await builtinTemplateSchema(),
|
|
@@ -31,15 +15,6 @@ async function loadBuiltins(): Promise<{
|
|
|
31
15
|
const cid = schema.cid.toString();
|
|
32
16
|
blocks.set(cid, schema.bytes);
|
|
33
17
|
}
|
|
34
|
-
for (const [name, selector] of builtinTemplateNames) {
|
|
35
|
-
const template = await builtinTemplateSource(selector);
|
|
36
|
-
for (const [cid, bytes] of template.blocks) blocks.set(cid, bytes);
|
|
37
|
-
add(name, template.cid, {
|
|
38
|
-
kind: "bundle",
|
|
39
|
-
typeName: templateSchema.name,
|
|
40
|
-
schemaCid: templateSchemaCid.toString(),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
18
|
return { pins, blocks };
|
|
44
19
|
}
|
|
45
20
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { bundledSkillSource } from "./skill-source.js";
|
|
3
|
+
import {
|
|
4
|
+
inspectBundledSkill,
|
|
5
|
+
manageSkills,
|
|
6
|
+
officialSkillsPort,
|
|
7
|
+
bundledSkillOrigin,
|
|
8
|
+
type SkillsPort,
|
|
9
|
+
} from "./skills.js";
|
|
10
|
+
import { HostError } from "./errors.js";
|
|
11
|
+
|
|
12
|
+
export async function inspectBundledSkills(
|
|
13
|
+
port: SkillsPort = officialSkillsPort,
|
|
14
|
+
) {
|
|
15
|
+
return inspectBundledSkill(await bundledSkillSource(), port);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function installBundledSkills(
|
|
19
|
+
env: NodeJS.ProcessEnv,
|
|
20
|
+
preview: (text: string) => void,
|
|
21
|
+
port: SkillsPort = officialSkillsPort,
|
|
22
|
+
) {
|
|
23
|
+
const catalog = await port.catalog();
|
|
24
|
+
const agents = catalog.detected
|
|
25
|
+
.filter((agent) =>
|
|
26
|
+
catalog.supported.some(
|
|
27
|
+
(entry) => entry.id === agent.id && entry.globalSkillsDir !== null,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
.map((agent) => agent.id);
|
|
31
|
+
if (!agents.length)
|
|
32
|
+
throw new HostError(
|
|
33
|
+
"No globally supported agents detected. Install an Agent, then retry ipab doctor --fix.",
|
|
34
|
+
);
|
|
35
|
+
const result = await manageSkills(
|
|
36
|
+
{ env, bundledSkill: await bundledSkillSource() },
|
|
37
|
+
bundledSkillOrigin,
|
|
38
|
+
{
|
|
39
|
+
sync: true,
|
|
40
|
+
names: [],
|
|
41
|
+
agents,
|
|
42
|
+
overrideExisting: false,
|
|
43
|
+
dryRun: false,
|
|
44
|
+
yes: true,
|
|
45
|
+
tty: false,
|
|
46
|
+
confirm: () => Promise.resolve(false),
|
|
47
|
+
preview,
|
|
48
|
+
},
|
|
49
|
+
port,
|
|
50
|
+
);
|
|
51
|
+
if (!result.ok)
|
|
52
|
+
throw new HostError(
|
|
53
|
+
[
|
|
54
|
+
"Bundled IPAB Skill installation failed; existing custom content was preserved.",
|
|
55
|
+
...result.items.flatMap((item) => item.problems),
|
|
56
|
+
...result.results.flatMap((item) => (item.error ? [item.error] : [])),
|
|
57
|
+
`Inspect ${join(port.home, ".ipab", "skills", "installations.json")} and retry ipab doctor --fix.`,
|
|
58
|
+
].join("\n"),
|
|
59
|
+
);
|
|
60
|
+
}
|