@ipab/cli 0.1.0-rc.1 → 0.1.0-rc.10
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 +226 -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 +4 -8
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +25 -15
- 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 +1919 -256
- 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 +7 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +151 -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 +684 -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 +115 -13
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +492 -91
- 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 +469 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +4708 -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 +41 -17
- package/src/builtins.ts +2 -27
- package/src/bundled-skills.ts +60 -0
- package/src/cli.ts +2399 -320
- package/src/config-secret.ts +14 -0
- package/src/config.ts +196 -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 +1082 -0
- package/src/errors.ts +1 -25
- package/src/get.ts +90 -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 +759 -107
- 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 +7051 -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/source-bundle.ts
CHANGED
|
@@ -2,21 +2,15 @@ import { relative, isAbsolute, sep } from "node:path";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import ignore from "ignore";
|
|
4
4
|
import { stringify } from "yaml";
|
|
5
|
-
import { bundleLimits } from "@ipab/bundle";
|
|
5
|
+
import { bundleLimits, parseBundleManifest } from "@ipab/bundle";
|
|
6
6
|
import { listTree, readBytes } from "@ipab/bundle-builder";
|
|
7
7
|
import { filesystemTree } from "@ipab/bundle-builder/node";
|
|
8
8
|
import { nodeError, type AuthoringOptions } from "./authoring.js";
|
|
9
9
|
import { HostError } from "./errors.js";
|
|
10
10
|
|
|
11
11
|
export const sourceSchema = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"App project source snapshot; build inputs are ordinary resources.",
|
|
15
|
-
entry: {
|
|
16
|
-
path: "package.json",
|
|
17
|
-
contentType: "application/json",
|
|
18
|
-
schema: { type: "object" },
|
|
19
|
-
},
|
|
12
|
+
contentType: "application/json",
|
|
13
|
+
schema: { type: "object" },
|
|
20
14
|
} as const;
|
|
21
15
|
|
|
22
16
|
export async function captureSource(
|
|
@@ -41,7 +35,7 @@ export async function captureSource(
|
|
|
41
35
|
if (
|
|
42
36
|
normalized
|
|
43
37
|
.split("/")
|
|
44
|
-
.some((part) => [".git", "node_modules"].includes(part)) ||
|
|
38
|
+
.some((part) => [".git", ".ipab", "node_modules"].includes(part)) ||
|
|
45
39
|
normalized === ".bundle-ignore" ||
|
|
46
40
|
normalized === "dist" ||
|
|
47
41
|
normalized.startsWith("dist/") ||
|
|
@@ -113,11 +107,30 @@ export async function captureSource(
|
|
|
113
107
|
throw new HostError("Source .bundle.yaml is excluded by .gitignore.");
|
|
114
108
|
files.set(
|
|
115
109
|
".bundle.yaml",
|
|
116
|
-
new TextEncoder().encode(
|
|
110
|
+
new TextEncoder().encode(
|
|
111
|
+
stringify({
|
|
112
|
+
title: "IPAB App Source",
|
|
113
|
+
entry: "package.json",
|
|
114
|
+
type: ".bundle-type.yaml",
|
|
115
|
+
}),
|
|
116
|
+
),
|
|
117
117
|
);
|
|
118
|
+
if (excluded(".bundle-type.yaml", false))
|
|
119
|
+
throw new HostError(
|
|
120
|
+
"Source .bundle-type.yaml is excluded by .gitignore.",
|
|
121
|
+
);
|
|
122
|
+
if (!files.has(".bundle-type.yaml"))
|
|
123
|
+
files.set(
|
|
124
|
+
".bundle-type.yaml",
|
|
125
|
+
new TextEncoder().encode(stringify(sourceSchema)),
|
|
126
|
+
);
|
|
118
127
|
}
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
const manifest = parseBundleManifest(files.get(".bundle.yaml")!);
|
|
129
|
+
for (const required of [manifest.entry, manifest.type])
|
|
130
|
+
if (!files.has(required))
|
|
131
|
+
throw new HostError(
|
|
132
|
+
`Source required file is excluded or missing: ${required}.`,
|
|
133
|
+
);
|
|
121
134
|
return files;
|
|
122
135
|
}
|
|
123
136
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HostError } from "./host-error.js";
|
|
2
|
+
|
|
3
|
+
export const CHUNK_BYTES = 64 * 1024;
|
|
4
|
+
|
|
5
|
+
export function relativePath(path: string): string {
|
|
6
|
+
if (
|
|
7
|
+
path.length > 1024 ||
|
|
8
|
+
!path ||
|
|
9
|
+
path.includes("\\") ||
|
|
10
|
+
path.includes("%") ||
|
|
11
|
+
[...path].some(
|
|
12
|
+
(char) =>
|
|
13
|
+
char.charCodeAt(0) < 32 ||
|
|
14
|
+
char.charCodeAt(0) === 127 ||
|
|
15
|
+
':*?"<>|'.includes(char),
|
|
16
|
+
) ||
|
|
17
|
+
path
|
|
18
|
+
.split("/")
|
|
19
|
+
.some(
|
|
20
|
+
(part) => !part || part === "." || part === ".." || /[. ]$/.test(part),
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
throw new HostError(
|
|
24
|
+
"Unsafe Space path; use an unambiguous directory-relative / path.",
|
|
25
|
+
1,
|
|
26
|
+
"PATH_INVALID",
|
|
27
|
+
"execution",
|
|
28
|
+
);
|
|
29
|
+
return path;
|
|
30
|
+
}
|
package/src/space.ts
CHANGED
|
@@ -5,44 +5,21 @@ import { CID } from "multiformats/cid";
|
|
|
5
5
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
6
6
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
7
7
|
import { openBundle, type ContentBundle } from "@ipab/bundle";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
8
|
+
import { isSwarmRootSchema } from "./swarm-meta.js";
|
|
9
|
+
import { HostError, message, object } from "./errors.js";
|
|
10
|
+
import { Ownership } from "./history.js";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { ReadableStream as NodeReadableStream } from "node:stream/web";
|
|
10
13
|
import { appDescription, appSchemaCid } from "./app-definition.js";
|
|
11
14
|
import { readSupportedSchemas } from "./supported-schemas.js";
|
|
12
15
|
export { appSchema, appSchemaCid } from "./app-definition.js";
|
|
13
|
-
|
|
16
|
+
import { CHUNK_BYTES, relativePath } from "./space-path.js";
|
|
17
|
+
export { CHUNK_BYTES, relativePath } from "./space-path.js";
|
|
14
18
|
export const OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
15
19
|
export const MAX_PATHS = 4096;
|
|
16
20
|
|
|
17
|
-
export function relativePath(path: string): string {
|
|
18
|
-
if (
|
|
19
|
-
path.length > 1024 ||
|
|
20
|
-
!path ||
|
|
21
|
-
path.includes("\\") ||
|
|
22
|
-
path.includes("%") ||
|
|
23
|
-
[...path].some(
|
|
24
|
-
(char) =>
|
|
25
|
-
char.charCodeAt(0) < 32 ||
|
|
26
|
-
char.charCodeAt(0) === 127 ||
|
|
27
|
-
':*?"<>|'.includes(char),
|
|
28
|
-
) ||
|
|
29
|
-
path
|
|
30
|
-
.split("/")
|
|
31
|
-
.some(
|
|
32
|
-
(part) => !part || part === "." || part === ".." || /[. ]$/.test(part),
|
|
33
|
-
)
|
|
34
|
-
)
|
|
35
|
-
throw new HostError(
|
|
36
|
-
"Unsafe Space path; use an unambiguous directory-relative / path.",
|
|
37
|
-
1,
|
|
38
|
-
"PATH_INVALID",
|
|
39
|
-
"execution",
|
|
40
|
-
);
|
|
41
|
-
return path;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
21
|
export async function bytes(
|
|
45
|
-
stream: ReadableStream<Uint8Array>,
|
|
22
|
+
stream: ReadableStream<Uint8Array> | NodeReadableStream<Uint8Array>,
|
|
46
23
|
limit: number,
|
|
47
24
|
): Promise<Uint8Array> {
|
|
48
25
|
const reader = stream.getReader();
|
|
@@ -83,12 +60,19 @@ export async function validatedBundle(
|
|
|
83
60
|
owner: Ownership,
|
|
84
61
|
signal?: AbortSignal,
|
|
85
62
|
): Promise<ContentBundle> {
|
|
63
|
+
const cid = CID.parse(root);
|
|
64
|
+
const shallow = await openBundle(cid, {
|
|
65
|
+
...(signal ? { signal } : {}),
|
|
66
|
+
shallow: true,
|
|
67
|
+
resolveCid: (key, options) => store.block.get(key.toString(), options),
|
|
68
|
+
});
|
|
69
|
+
if (isSwarmRootSchema(shallow.schemaKey)) return shallow;
|
|
86
70
|
await owner.retain([root], signal);
|
|
87
|
-
return openBundle(
|
|
71
|
+
return openBundle(cid, {
|
|
88
72
|
...(signal ? { signal } : {}),
|
|
89
|
-
resolveCid: async (
|
|
90
|
-
await owner.retain([
|
|
91
|
-
return store.block.get(
|
|
73
|
+
resolveCid: async (key, options) => {
|
|
74
|
+
await owner.retain([key.toV1().toString()], options.signal);
|
|
75
|
+
return store.block.get(key.toString(), options);
|
|
92
76
|
},
|
|
93
77
|
});
|
|
94
78
|
}
|
|
@@ -106,7 +90,7 @@ export async function loadApp(
|
|
|
106
90
|
const bundle = await validatedBundle(root, store, owner, signal);
|
|
107
91
|
if (
|
|
108
92
|
bundle.schemaKey !== appSchemaCid.toString() ||
|
|
109
|
-
bundle.
|
|
93
|
+
bundle.schema.type.contentType !== "application/json"
|
|
110
94
|
)
|
|
111
95
|
throw new HostError(
|
|
112
96
|
"App must use the documented exact builtin Node App type CID.",
|
|
@@ -117,10 +101,7 @@ export async function loadApp(
|
|
|
117
101
|
const description = appDescription(
|
|
118
102
|
JSON.parse(
|
|
119
103
|
new TextDecoder("utf-8", { fatal: true }).decode(
|
|
120
|
-
await bytes(
|
|
121
|
-
await bundle.readFile(bundle.manifest.entry.path),
|
|
122
|
-
64 * 1024,
|
|
123
|
-
),
|
|
104
|
+
await bytes(await bundle.readFile(bundle.manifest.entry), 64 * 1024),
|
|
124
105
|
),
|
|
125
106
|
) as unknown,
|
|
126
107
|
);
|
|
@@ -160,6 +141,75 @@ export async function loadApp(
|
|
|
160
141
|
};
|
|
161
142
|
}
|
|
162
143
|
|
|
144
|
+
/** Checkpoints are owned by the execution, not pins; only the final result is handed to history. */
|
|
145
|
+
export async function deriveBundle(
|
|
146
|
+
inputCid: string,
|
|
147
|
+
replacements: unknown,
|
|
148
|
+
store: IpfsStore,
|
|
149
|
+
owner: Ownership,
|
|
150
|
+
signal?: AbortSignal,
|
|
151
|
+
): Promise<string> {
|
|
152
|
+
signal?.throwIfAborted();
|
|
153
|
+
const changes = Object.entries(object(replacements, "Bundle replacements"));
|
|
154
|
+
if (changes.length > MAX_PATHS)
|
|
155
|
+
throw new HostError("Bundle replacement path limit exceeded.");
|
|
156
|
+
let total = 0;
|
|
157
|
+
for (const [path, value] of changes) {
|
|
158
|
+
relativePath(path);
|
|
159
|
+
if (!(value instanceof Uint8Array))
|
|
160
|
+
throw new HostError("Bundle replacements must contain byte arrays.");
|
|
161
|
+
total += value.byteLength;
|
|
162
|
+
if (total > OUTPUT_BYTES)
|
|
163
|
+
throw new HostError("Bundle replacement byte limit exceeded.");
|
|
164
|
+
}
|
|
165
|
+
const input = CID.parse(inputCid).toV1().toString();
|
|
166
|
+
const original = await validatedBundle(input, store, owner, signal);
|
|
167
|
+
const id = randomUUID();
|
|
168
|
+
const session = `ipab-derive:${owner.state.identity}:${id}`;
|
|
169
|
+
const temporary = await Ownership.create(
|
|
170
|
+
owner.state,
|
|
171
|
+
store,
|
|
172
|
+
`derive:${id}`,
|
|
173
|
+
session,
|
|
174
|
+
);
|
|
175
|
+
try {
|
|
176
|
+
const output = new OutputSpace(store, temporary, session, signal);
|
|
177
|
+
const replaced = new Set(changes.map(([path]) => path));
|
|
178
|
+
for (const path of original.files) {
|
|
179
|
+
signal?.throwIfAborted();
|
|
180
|
+
if (replaced.has(path)) continue;
|
|
181
|
+
const file = await store.read(
|
|
182
|
+
`${input}/${path}`,
|
|
183
|
+
signal ? { signal } : {},
|
|
184
|
+
);
|
|
185
|
+
await output.link(path, file.cid.toString(), signal);
|
|
186
|
+
}
|
|
187
|
+
for (const [path, value] of changes) {
|
|
188
|
+
const content = value as Uint8Array;
|
|
189
|
+
const chunks = async function* () {
|
|
190
|
+
for (let offset = 0; offset < content.length; offset += CHUNK_BYTES) {
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
yield await Promise.resolve(
|
|
193
|
+
content.subarray(offset, offset + CHUNK_BYTES),
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
await output.write(path, chunks(), signal);
|
|
198
|
+
}
|
|
199
|
+
const result = await output.finalize();
|
|
200
|
+
const derived = await validatedBundle(result, store, temporary, signal);
|
|
201
|
+
if (derived.schemaKey !== original.schemaKey)
|
|
202
|
+
throw new HostError(
|
|
203
|
+
"Derived Bundle must preserve the input's exact type CID.",
|
|
204
|
+
);
|
|
205
|
+
await owner.retain([result], signal);
|
|
206
|
+
signal?.throwIfAborted();
|
|
207
|
+
return result;
|
|
208
|
+
} finally {
|
|
209
|
+
await temporary.release();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
163
213
|
interface Entry {
|
|
164
214
|
cid: CID;
|
|
165
215
|
size: bigint;
|
|
@@ -178,6 +228,11 @@ export class OutputSpace {
|
|
|
178
228
|
private readonly pending = new Set<string>();
|
|
179
229
|
private totalBytes = 0;
|
|
180
230
|
private fault: Error | undefined;
|
|
231
|
+
private bundleMode = false;
|
|
232
|
+
private bundleSchema: string | undefined;
|
|
233
|
+
private submittedBundle: string | undefined;
|
|
234
|
+
private selectingBundle = false;
|
|
235
|
+
private sessionStarted = false;
|
|
181
236
|
constructor(
|
|
182
237
|
readonly store: IpfsStore,
|
|
183
238
|
readonly owner: Ownership,
|
|
@@ -187,6 +242,10 @@ export class OutputSpace {
|
|
|
187
242
|
this.session = session;
|
|
188
243
|
}
|
|
189
244
|
private claim(path: string): void {
|
|
245
|
+
if (this.bundleMode)
|
|
246
|
+
throw new HostError(
|
|
247
|
+
"Explicit Bundle results cannot be mixed with output Space writes.",
|
|
248
|
+
);
|
|
190
249
|
relativePath(path);
|
|
191
250
|
if (this.claimed.size >= MAX_PATHS)
|
|
192
251
|
throw new HostError("Output path limit exceeded.");
|
|
@@ -202,7 +261,125 @@ export class OutputSpace {
|
|
|
202
261
|
this.pending.add(path);
|
|
203
262
|
}
|
|
204
263
|
fail(error: unknown): void {
|
|
205
|
-
this.fault ??=
|
|
264
|
+
this.fault ??=
|
|
265
|
+
error instanceof HostError ? error : new HostError(message(error));
|
|
266
|
+
}
|
|
267
|
+
private selectBundleMode(): void {
|
|
268
|
+
if (this.fault) throw this.fault;
|
|
269
|
+
if (this.claimed.size)
|
|
270
|
+
throw new HostError(
|
|
271
|
+
"Explicit Bundle results cannot be mixed with output Space writes.",
|
|
272
|
+
);
|
|
273
|
+
if (this.selectingBundle)
|
|
274
|
+
throw new HostError(
|
|
275
|
+
"Concurrent Bundle result selection is not supported.",
|
|
276
|
+
);
|
|
277
|
+
this.bundleMode = true;
|
|
278
|
+
}
|
|
279
|
+
async beginOpenSession(
|
|
280
|
+
inputCid: string,
|
|
281
|
+
signal?: AbortSignal,
|
|
282
|
+
supportedTypes?: ReadonlySet<string>,
|
|
283
|
+
expectedTypes?: unknown,
|
|
284
|
+
): Promise<void> {
|
|
285
|
+
try {
|
|
286
|
+
this.selectBundleMode();
|
|
287
|
+
if (this.sessionStarted || this.submittedBundle)
|
|
288
|
+
throw new HostError(
|
|
289
|
+
"Open session has already started or submitted a result.",
|
|
290
|
+
);
|
|
291
|
+
this.sessionStarted = true;
|
|
292
|
+
this.selectingBundle = true;
|
|
293
|
+
if (expectedTypes !== undefined) {
|
|
294
|
+
if (
|
|
295
|
+
!Array.isArray(expectedTypes) ||
|
|
296
|
+
expectedTypes.length > MAX_PATHS ||
|
|
297
|
+
!expectedTypes.every(
|
|
298
|
+
(cid: unknown) =>
|
|
299
|
+
typeof cid === "string" &&
|
|
300
|
+
CID.parse(cid).toV1().toString() === cid,
|
|
301
|
+
)
|
|
302
|
+
)
|
|
303
|
+
throw new HostError(
|
|
304
|
+
"Open supportedTypes must be exact canonical CID strings.",
|
|
305
|
+
);
|
|
306
|
+
const expected = new Set<string>(expectedTypes as string[]);
|
|
307
|
+
if (expected.size !== expectedTypes.length)
|
|
308
|
+
throw new HostError(
|
|
309
|
+
"Open supportedTypes must not contain duplicate CIDs.",
|
|
310
|
+
);
|
|
311
|
+
if (
|
|
312
|
+
!supportedTypes ||
|
|
313
|
+
expected.size !== supportedTypes.size ||
|
|
314
|
+
[...expected].some((cid) => !supportedTypes.has(cid))
|
|
315
|
+
)
|
|
316
|
+
throw new HostError(
|
|
317
|
+
"Open supportedTypes must exactly match the App supportedSchemas declaration.",
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
const bundle = await validatedBundle(
|
|
321
|
+
inputCid,
|
|
322
|
+
this.store,
|
|
323
|
+
this.owner,
|
|
324
|
+
signal,
|
|
325
|
+
);
|
|
326
|
+
signal?.throwIfAborted();
|
|
327
|
+
if (supportedTypes && !supportedTypes.has(bundle.schemaKey))
|
|
328
|
+
throw new HostError(
|
|
329
|
+
"App does not declare support for the Open input's exact type CID.",
|
|
330
|
+
);
|
|
331
|
+
this.bundleSchema = bundle.schemaKey;
|
|
332
|
+
} catch (error) {
|
|
333
|
+
this.fail(error);
|
|
334
|
+
throw error;
|
|
335
|
+
} finally {
|
|
336
|
+
this.selectingBundle = false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
cancelOpenSession(): void {
|
|
340
|
+
this.bundleMode = true;
|
|
341
|
+
this.fail(
|
|
342
|
+
new HostError(
|
|
343
|
+
"Open session cancelled without a committed Bundle result.",
|
|
344
|
+
130,
|
|
345
|
+
"CANCELLED",
|
|
346
|
+
"execution",
|
|
347
|
+
),
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
discardBundleResult(): void {
|
|
351
|
+
this.submittedBundle = undefined;
|
|
352
|
+
}
|
|
353
|
+
async submitBundleResult(root: string, signal?: AbortSignal): Promise<void> {
|
|
354
|
+
try {
|
|
355
|
+
this.selectBundleMode();
|
|
356
|
+
} catch (error) {
|
|
357
|
+
this.fail(error);
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
this.selectingBundle = true;
|
|
361
|
+
try {
|
|
362
|
+
const cid = CID.parse(root).toV1().toString();
|
|
363
|
+
if (this.submittedBundle && this.submittedBundle !== cid) {
|
|
364
|
+
const error = new HostError(
|
|
365
|
+
"A different Bundle result has already been submitted.",
|
|
366
|
+
);
|
|
367
|
+
this.fail(error);
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
signal?.throwIfAborted();
|
|
371
|
+
if (this.submittedBundle === cid) return;
|
|
372
|
+
const bundle = await validatedBundle(cid, this.store, this.owner, signal);
|
|
373
|
+
signal?.throwIfAborted();
|
|
374
|
+
if (this.bundleSchema && bundle.schemaKey !== this.bundleSchema)
|
|
375
|
+
throw new HostError(
|
|
376
|
+
"Bundle result must preserve the Open session's exact type CID.",
|
|
377
|
+
);
|
|
378
|
+
this.submittedBundle = cid;
|
|
379
|
+
} finally {
|
|
380
|
+
// Validation/storage failures leave the explicit session open for retry, never a Space result.
|
|
381
|
+
this.selectingBundle = false;
|
|
382
|
+
}
|
|
206
383
|
}
|
|
207
384
|
async write(
|
|
208
385
|
path: string,
|
|
@@ -238,7 +415,7 @@ export class OutputSpace {
|
|
|
238
415
|
block instanceof Uint8Array
|
|
239
416
|
? block
|
|
240
417
|
: await bytes(
|
|
241
|
-
|
|
418
|
+
NodeReadableStream.from(block),
|
|
242
419
|
this.store.limits.blockBytes,
|
|
243
420
|
);
|
|
244
421
|
await this.store.stageBlock(
|
|
@@ -315,7 +492,18 @@ export class OutputSpace {
|
|
|
315
492
|
}
|
|
316
493
|
}
|
|
317
494
|
async finalize(): Promise<string> {
|
|
495
|
+
this.signal?.throwIfAborted();
|
|
318
496
|
if (this.fault) throw this.fault;
|
|
497
|
+
if (this.bundleMode) {
|
|
498
|
+
if (this.selectingBundle || !this.submittedBundle)
|
|
499
|
+
throw new HostError(
|
|
500
|
+
"Open session ended without submitting a Bundle result.",
|
|
501
|
+
130,
|
|
502
|
+
"CANCELLED",
|
|
503
|
+
"commit",
|
|
504
|
+
);
|
|
505
|
+
return this.submittedBundle;
|
|
506
|
+
}
|
|
319
507
|
if (this.pending.size)
|
|
320
508
|
throw new HostError(
|
|
321
509
|
"Output has unfinished stream writes.",
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
// One process per preflight, not one per path or SQL statement. Use framework
|
|
5
|
+
// APIs directly: loading PowerShell's filesystem/ACL cmdlets dominates startup.
|
|
6
|
+
const script = `
|
|
7
|
+
$ErrorActionPreference = 'Stop'
|
|
8
|
+
$sid = [Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
9
|
+
$sidType = [Security.Principal.SecurityIdentifier]
|
|
10
|
+
$root = $env:IPAB_STATE_ROOT
|
|
11
|
+
$repair = $env:IPAB_STATE_ACTION -eq 'prepare'
|
|
12
|
+
$managed = $env:IPAB_STATE_MANAGED -eq '1'
|
|
13
|
+
function New-PrivateAcl($dir) {
|
|
14
|
+
if ($dir) {
|
|
15
|
+
$a = [Security.AccessControl.DirectorySecurity]::new()
|
|
16
|
+
$r = [Security.AccessControl.FileSystemAccessRule]::new($sid,'FullControl','ContainerInherit,ObjectInherit','None','Allow')
|
|
17
|
+
} else {
|
|
18
|
+
$a = [Security.AccessControl.FileSecurity]::new()
|
|
19
|
+
$r = [Security.AccessControl.FileSystemAccessRule]::new($sid,'FullControl','Allow')
|
|
20
|
+
}
|
|
21
|
+
$a.SetAccessRuleProtection($true,$false)
|
|
22
|
+
$a.AddAccessRule($r)
|
|
23
|
+
return $a
|
|
24
|
+
}
|
|
25
|
+
if ($repair -and ![IO.Directory]::Exists($root)) {
|
|
26
|
+
$new = New-PrivateAcl $true
|
|
27
|
+
$new.SetOwner($sid)
|
|
28
|
+
[void][IO.Directory]::CreateDirectory($root,$new)
|
|
29
|
+
}
|
|
30
|
+
$changes = @()
|
|
31
|
+
$paths = @($root)
|
|
32
|
+
foreach ($name in ([string]$env:IPAB_STATE_ENTRIES).Split('|',[StringSplitOptions]::RemoveEmptyEntries)) {
|
|
33
|
+
$paths += [IO.Path]::Combine($root,$name)
|
|
34
|
+
}
|
|
35
|
+
function Check-Path($path) {
|
|
36
|
+
try {
|
|
37
|
+
$attrs = [IO.File]::GetAttributes($path)
|
|
38
|
+
if ($attrs -band [IO.FileAttributes]::ReparsePoint) { throw 'Invalid state path' }
|
|
39
|
+
$dir = [bool]($attrs -band [IO.FileAttributes]::Directory)
|
|
40
|
+
$isDir = $path -eq $root -or [IO.Path]::GetFileName($path) -in 'runtime','logs','kubo-bin','kubo-cache','swarm-nodes','swarm-credentials','swarm-daemon','swarm-inspections','swarm-observations'
|
|
41
|
+
if ($dir -ne $isDir) { throw 'Invalid state type' }
|
|
42
|
+
if ($dir) { $acl = [IO.Directory]::GetAccessControl($path) }
|
|
43
|
+
else { $acl = [IO.File]::GetAccessControl($path) }
|
|
44
|
+
}
|
|
45
|
+
catch [IO.FileNotFoundException] {
|
|
46
|
+
if ($path -match 'state\\.sqlite-(wal|shm|journal)$') { return }
|
|
47
|
+
throw
|
|
48
|
+
}
|
|
49
|
+
if ($acl.GetOwner($sidType).Value -ne $sid.Value) { throw 'Invalid owner' }
|
|
50
|
+
if ($env:IPAB_STATE_ACTION -eq 'owners') { return }
|
|
51
|
+
if ($dir -and $path -ne $root -and [IO.Path]::GetFileName($path) -notin 'runtime','logs') { return }
|
|
52
|
+
$private = $false
|
|
53
|
+
$raw = [Security.AccessControl.RawSecurityDescriptor]::new($acl.GetSecurityDescriptorBinaryForm(),0)
|
|
54
|
+
foreach ($ace in $raw.DiscretionaryAcl) {
|
|
55
|
+
if ($ace.AceType -ne 'AccessAllowed' -or $ace.SecurityIdentifier.Value -ne $sid.Value) { $private = $false; break }
|
|
56
|
+
$flags = [int]$ace.AceFlags
|
|
57
|
+
if ($ace.AccessMask -eq [int][Security.AccessControl.FileSystemRights]::FullControl -and !($flags -band 8) -and (!$dir -or ($flags -band 15) -eq 3)) { $private = $true }
|
|
58
|
+
}
|
|
59
|
+
if (!$private -or ($path -eq $root -and !$acl.AreAccessRulesProtected)) {
|
|
60
|
+
if (!$repair -or (!$managed -and !$private)) { throw 'Not account-only' }
|
|
61
|
+
return @{path=$path; dir=$dir}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
foreach ($path in $paths) { $change = Check-Path $path; if ($change) { $changes += $change } }
|
|
65
|
+
foreach ($c in $changes) {
|
|
66
|
+
$acl = New-PrivateAcl $c.dir
|
|
67
|
+
if ($c.dir) {
|
|
68
|
+
# SetKernelObjectSecurity only updates this directory; SetAccessControl
|
|
69
|
+
# would propagate inheritable ACEs through existing, uninspected children.
|
|
70
|
+
if (!('IpabDirectoryAcl' -as [type])) {
|
|
71
|
+
Add-Type -TypeDefinition @'
|
|
72
|
+
using System;
|
|
73
|
+
using System.Runtime.InteropServices;
|
|
74
|
+
using Microsoft.Win32.SafeHandles;
|
|
75
|
+
public static class IpabDirectoryAcl {
|
|
76
|
+
[DllImport("kernel32", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
77
|
+
static extern SafeFileHandle CreateFile(string p, uint a, uint s, IntPtr sa, uint d, uint f, IntPtr t);
|
|
78
|
+
[DllImport("advapi32", SetLastError=true)]
|
|
79
|
+
static extern bool SetKernelObjectSecurity(SafeFileHandle h, uint i, byte[] sd);
|
|
80
|
+
public static void Set(string p, byte[] sd) {
|
|
81
|
+
using (var h = CreateFile(p, 0x40000, 3, IntPtr.Zero, 3, 0x02200000, IntPtr.Zero)) {
|
|
82
|
+
if (h.IsInvalid || !SetKernelObjectSecurity(h, 0x80000004, sd)) throw new System.ComponentModel.Win32Exception();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
'@
|
|
87
|
+
}
|
|
88
|
+
[IpabDirectoryAcl]::Set($c.path,$acl.GetSecurityDescriptorBinaryForm())
|
|
89
|
+
} else { [IO.File]::SetAccessControl($c.path,$acl) }
|
|
90
|
+
if (Check-Path $c.path) { throw 'ACL did not persist' }
|
|
91
|
+
if ($c.path -eq $root) { 'sealed'; break }
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
export function windowsStateAccess(
|
|
96
|
+
root: string,
|
|
97
|
+
entries: string[],
|
|
98
|
+
action: "owners" | "prepare" | "verify",
|
|
99
|
+
managed: boolean,
|
|
100
|
+
): boolean {
|
|
101
|
+
const result = execFileSync(
|
|
102
|
+
join(
|
|
103
|
+
process.env.SystemRoot!,
|
|
104
|
+
"System32",
|
|
105
|
+
"WindowsPowerShell",
|
|
106
|
+
"v1.0",
|
|
107
|
+
"powershell.exe",
|
|
108
|
+
),
|
|
109
|
+
[
|
|
110
|
+
"-NoLogo",
|
|
111
|
+
"-NoProfile",
|
|
112
|
+
"-NonInteractive",
|
|
113
|
+
"-EncodedCommand",
|
|
114
|
+
Buffer.from(script, "utf16le").toString("base64"),
|
|
115
|
+
],
|
|
116
|
+
{
|
|
117
|
+
windowsHide: true,
|
|
118
|
+
encoding: "utf8",
|
|
119
|
+
env: {
|
|
120
|
+
...Object.fromEntries(
|
|
121
|
+
Object.entries(process.env).filter(
|
|
122
|
+
([key]) => key.toLowerCase() !== "psmodulepath",
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
IPAB_STATE_ROOT: root,
|
|
126
|
+
IPAB_STATE_ENTRIES: entries.join("|"),
|
|
127
|
+
IPAB_STATE_ACTION: action,
|
|
128
|
+
IPAB_STATE_MANAGED: managed ? "1" : "0",
|
|
129
|
+
},
|
|
130
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
return result.trim() === "sealed";
|
|
134
|
+
}
|