@dual-os/cli 0.0.0-stage → 0.11.0
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/LICENSE +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- Effect FileSystem.stat follows links; destination checks require lstat.
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Array,
|
|
7
|
+
Context,
|
|
8
|
+
Effect,
|
|
9
|
+
FileSystem,
|
|
10
|
+
Layer,
|
|
11
|
+
Path,
|
|
12
|
+
Record,
|
|
13
|
+
Redacted,
|
|
14
|
+
Schema,
|
|
15
|
+
String,
|
|
16
|
+
pipe,
|
|
17
|
+
} from "effect";
|
|
18
|
+
|
|
19
|
+
import { Diagnostics } from "#diagnostics";
|
|
20
|
+
|
|
21
|
+
import { Baseline } from "../baseline.ts";
|
|
22
|
+
|
|
23
|
+
type Identifier = typeof Identifier.Type;
|
|
24
|
+
const Identifier = Schema.String.check(Schema.isPattern(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u));
|
|
25
|
+
type SdkManifest = typeof SdkManifest.Type;
|
|
26
|
+
const SdkManifest = Schema.Struct({
|
|
27
|
+
dependencies: Schema.Struct({ effect: Schema.NonEmptyString }),
|
|
28
|
+
version: Schema.NonEmptyString,
|
|
29
|
+
});
|
|
30
|
+
type MissingFile = typeof MissingFile.Type;
|
|
31
|
+
const MissingFile = Schema.Struct({ code: Schema.Literal("ENOENT") });
|
|
32
|
+
|
|
33
|
+
export class InitError extends Schema.TaggedError<InitError>()("InitError", {
|
|
34
|
+
cause: Schema.optionalKey(Schema.Redacted(Schema.Defect())),
|
|
35
|
+
message: Schema.String,
|
|
36
|
+
}) {}
|
|
37
|
+
|
|
38
|
+
export type Interface = {
|
|
39
|
+
readonly create: (directory: string) => Effect.Effect<string, InitError>;
|
|
40
|
+
};
|
|
41
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
42
|
+
"@dual-os/cli/plugin/init/Service",
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
export const layer = Layer.effect(
|
|
46
|
+
Service,
|
|
47
|
+
Effect.gen(function* () {
|
|
48
|
+
const fs = yield* FileSystem.FileSystem;
|
|
49
|
+
const path = yield* Path.Path;
|
|
50
|
+
const emptyDestination = Effect.fnUntraced(function* (destination: string) {
|
|
51
|
+
const info = yield* pipe(
|
|
52
|
+
Effect.tryPromise(() => lstat(destination)),
|
|
53
|
+
Effect.catchIf(
|
|
54
|
+
error => Schema.is(MissingFile)(error.cause),
|
|
55
|
+
() => Effect.void,
|
|
56
|
+
),
|
|
57
|
+
Effect.uninterruptible,
|
|
58
|
+
);
|
|
59
|
+
if (info === undefined) return;
|
|
60
|
+
if (
|
|
61
|
+
!info.isDirectory() ||
|
|
62
|
+
info.isSymbolicLink() ||
|
|
63
|
+
Array.isReadonlyArrayNonEmpty(yield* fs.readDirectory(destination))
|
|
64
|
+
) {
|
|
65
|
+
return yield* InitError.make({
|
|
66
|
+
message:
|
|
67
|
+
"Choose an absent or empty directory, not a file or symlink. No files were overwritten.",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return Service.of({
|
|
72
|
+
create: Effect.fn("PluginInit.create")(
|
|
73
|
+
function* (directory: string) {
|
|
74
|
+
const destination = path.resolve(directory);
|
|
75
|
+
const identifier = yield* pipe(
|
|
76
|
+
Schema.decodeEffect(Identifier)(path.basename(destination)),
|
|
77
|
+
Effect.mapError(cause =>
|
|
78
|
+
InitError.make({
|
|
79
|
+
cause: Redacted.make(cause),
|
|
80
|
+
message:
|
|
81
|
+
"Use a directory name in lowercase kebab-case, starting with a letter, such as my-plugin.",
|
|
82
|
+
}),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
yield* emptyDestination(destination);
|
|
86
|
+
const sdk = yield* Schema.decodeEffect(Schema.fromJsonString(SdkManifest))(
|
|
87
|
+
yield* fs.readFileString(
|
|
88
|
+
createRequire(import.meta.url).resolve("@dual-os/sdk/package.json"),
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
const quotedIdentifier = yield* Schema.encodeEffect(Schema.fromJsonString(Schema.String))(
|
|
92
|
+
identifier,
|
|
93
|
+
);
|
|
94
|
+
const files = {
|
|
95
|
+
".gitignore": "node_modules/\ndist/\n.dual/\n.env\n.env.*\n",
|
|
96
|
+
"README.md": `# ${identifier}\n\nThis standalone plugin uses the Dual SDK and exposes a ping action.\n\nUse Bun 1.4.2 and public npm, then run:\n\n\`\`\`sh\nbun install\n# Commit bun.lock before building a release.\nbun run build\ndual plugin validate\ndual plugin build\n\`\`\`\n\nThe self-contained archive is .dual/plugin.tgz. It includes the SDK, Effect, runner, JavaScript dependencies and licenses; the sandbox never installs packages. Build and validation do not publish or activate the plugin.\nDeclare finite dynamic-import helpers, child scripts and resources in dual.plugin.assets.\nEdit src/plugin.ts to add actions and handlers. The release version comes only from package.json. Publish a new package version for every code or contract change.\n\nTo upload, authorize with dual login --web --url <deployment-url>, then run dual plugin push.\nThe deployment must support plugin uploads.\n`,
|
|
97
|
+
"package.json": yield* Schema.encodeEffect(
|
|
98
|
+
Schema.fromJsonString(Schema.JsonObject, { space: 2 }),
|
|
99
|
+
)({
|
|
100
|
+
dependencies: { "@dual-os/sdk": sdk.version, effect: sdk.dependencies.effect },
|
|
101
|
+
devDependencies: { typescript: Baseline.versions.typescript },
|
|
102
|
+
dual: { plugin: { entrypoint: "dist/plugin.js", export: "default" } },
|
|
103
|
+
exports: "./dist/plugin.js",
|
|
104
|
+
files: ["dist"],
|
|
105
|
+
name: identifier,
|
|
106
|
+
private: true,
|
|
107
|
+
scripts: { build: "tsc -p tsconfig.json" },
|
|
108
|
+
type: "module",
|
|
109
|
+
version: "1.0.0",
|
|
110
|
+
}),
|
|
111
|
+
"src/plugin.ts": `import { Action, Plugin } from "@dual-os/sdk";
|
|
112
|
+
import { Effect, Schema, pipe } from "effect";
|
|
113
|
+
|
|
114
|
+
const ping = pipe(
|
|
115
|
+
Action.make("ping", { description: "Echo a message to verify the plugin.",
|
|
116
|
+
input: Schema.Struct({ message: Schema.String }),
|
|
117
|
+
output: Schema.Struct({ echoed: Schema.String }),
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const plugin = Plugin.make(${quotedIdentifier}).pipe(Plugin.withAction(ping));
|
|
122
|
+
const handlers = Plugin.toLayer(plugin, handlers => handlers.action("ping", input => Effect.succeed({ echoed: input.message })));
|
|
123
|
+
|
|
124
|
+
export default pipe(
|
|
125
|
+
plugin,
|
|
126
|
+
Plugin.provide(handlers),
|
|
127
|
+
);
|
|
128
|
+
`,
|
|
129
|
+
"tsconfig.json": yield* Schema.encodeEffect(
|
|
130
|
+
Schema.fromJsonString(Schema.JsonObject, { space: 2 }),
|
|
131
|
+
)({
|
|
132
|
+
compilerOptions: {
|
|
133
|
+
declaration: true,
|
|
134
|
+
module: "NodeNext",
|
|
135
|
+
moduleResolution: "NodeNext",
|
|
136
|
+
noEmitOnError: true,
|
|
137
|
+
outDir: "dist",
|
|
138
|
+
rootDir: "src",
|
|
139
|
+
skipLibCheck: true,
|
|
140
|
+
strict: true,
|
|
141
|
+
target: "ES2022",
|
|
142
|
+
},
|
|
143
|
+
include: ["src/**/*.ts"],
|
|
144
|
+
}),
|
|
145
|
+
};
|
|
146
|
+
yield* fs.makeDirectory(path.dirname(destination), { recursive: true });
|
|
147
|
+
const temporary = yield* fs.makeTempDirectoryScoped({
|
|
148
|
+
directory: path.dirname(destination),
|
|
149
|
+
prefix: ".dual-plugin-init-",
|
|
150
|
+
});
|
|
151
|
+
const staging = path.join(temporary, "plugin");
|
|
152
|
+
yield* fs.makeDirectory(staging);
|
|
153
|
+
yield* pipe(
|
|
154
|
+
Effect.gen(function* () {
|
|
155
|
+
for (const file of Record.toEntries(files)) {
|
|
156
|
+
const target = path.join(staging, file[0]);
|
|
157
|
+
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
158
|
+
yield* fs.writeFileString(target, `${String.trimEnd(file[1])}\n`, { flag: "wx" });
|
|
159
|
+
}
|
|
160
|
+
yield* emptyDestination(destination);
|
|
161
|
+
yield* fs.rename(staging, destination);
|
|
162
|
+
}),
|
|
163
|
+
Effect.uninterruptible,
|
|
164
|
+
);
|
|
165
|
+
return destination;
|
|
166
|
+
},
|
|
167
|
+
Effect.scoped,
|
|
168
|
+
Effect.mapError(cause =>
|
|
169
|
+
Schema.is(InitError)(cause)
|
|
170
|
+
? cause
|
|
171
|
+
: InitError.make({ cause: Redacted.make(cause), message: Diagnostics.format(cause) }),
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
export * as PluginInit from "./init.ts";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export type Result = typeof Result.Type;
|
|
4
|
+
export const Result = Schema.Struct({
|
|
5
|
+
plugin: Schema.NonEmptyString,
|
|
6
|
+
registry: Schema.Unknown,
|
|
7
|
+
sdkVersion: Schema.NonEmptyString,
|
|
8
|
+
version: Schema.NonEmptyString,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type Output = typeof Output.Type;
|
|
12
|
+
export const Output = Schema.Struct({
|
|
13
|
+
...Result.fields,
|
|
14
|
+
activated: Schema.Literal(false),
|
|
15
|
+
published: Schema.Literal(false),
|
|
16
|
+
status: Schema.Literal("local-only"),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export * as PluginInspection from "./inspection.ts";
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Context,
|
|
4
|
+
Effect,
|
|
5
|
+
FileSystem,
|
|
6
|
+
Layer,
|
|
7
|
+
MutableList,
|
|
8
|
+
Option,
|
|
9
|
+
Path,
|
|
10
|
+
Redacted,
|
|
11
|
+
Schema,
|
|
12
|
+
String,
|
|
13
|
+
pipe,
|
|
14
|
+
} from "effect";
|
|
15
|
+
|
|
16
|
+
import { Diagnostics } from "#diagnostics";
|
|
17
|
+
import { ReleaseManifest } from "#release/release-manifest";
|
|
18
|
+
|
|
19
|
+
type RelativePath = typeof RelativePath.Type;
|
|
20
|
+
const RelativePath = Schema.NonEmptyString.check(
|
|
21
|
+
Schema.isPattern(/^(?!\/|[A-Za-z]:)(?!.*(?:^|\/)\.\.(?:\/|$))[^\\\p{Cc}]+$/u),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
type Manifest = typeof Manifest.Type;
|
|
25
|
+
const Manifest = Schema.Struct({
|
|
26
|
+
version: ReleaseManifest.ExactVersion,
|
|
27
|
+
dual: Schema.Struct({
|
|
28
|
+
plugin: Schema.Struct({
|
|
29
|
+
assets: Schema.optionalKey(Schema.Array(RelativePath)),
|
|
30
|
+
entrypoint: RelativePath.check(Schema.isPattern(/\.(?:js|mjs|cjs)$/u)),
|
|
31
|
+
export: Schema.NonEmptyString,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export class PackageError extends Schema.TaggedError<PackageError>()("PackageError", {
|
|
37
|
+
cause: Schema.optionalKey(Schema.Redacted(Schema.Defect())),
|
|
38
|
+
message: Schema.String,
|
|
39
|
+
}) {}
|
|
40
|
+
|
|
41
|
+
export function fromCause(cause: unknown, context = "") {
|
|
42
|
+
return PackageError.make({
|
|
43
|
+
cause: Redacted.make(cause),
|
|
44
|
+
message: pipe(
|
|
45
|
+
String.trim(`${context}\n${Diagnostics.format(cause)}`),
|
|
46
|
+
Option.liftPredicate(String.isNonEmpty),
|
|
47
|
+
Option.getOrElse(() => "No error details returned by the plugin."),
|
|
48
|
+
),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type Prepared = {
|
|
53
|
+
assets: string[];
|
|
54
|
+
directory: string;
|
|
55
|
+
entrypoint: string;
|
|
56
|
+
export: string;
|
|
57
|
+
version: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type Interface = {
|
|
61
|
+
readonly inspect: (directory: string) => Effect.Effect<Prepared, PackageError>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
65
|
+
"@dual-os/cli/plugin/package/Service",
|
|
66
|
+
) {}
|
|
67
|
+
|
|
68
|
+
export const layer = Layer.effect(
|
|
69
|
+
Service,
|
|
70
|
+
Effect.gen(function* () {
|
|
71
|
+
const fs = yield* FileSystem.FileSystem;
|
|
72
|
+
const path = yield* Path.Path;
|
|
73
|
+
const containedPath = Effect.fnUntraced(function* (directory: string, file: string) {
|
|
74
|
+
const target = path.resolve(directory, file);
|
|
75
|
+
const relative = path.relative(directory, yield* fs.realPath(target));
|
|
76
|
+
if (
|
|
77
|
+
path.isAbsolute(relative) ||
|
|
78
|
+
relative === ".." ||
|
|
79
|
+
String.startsWith(`..${path.sep}`)(relative)
|
|
80
|
+
) {
|
|
81
|
+
return yield* PackageError.make({ message: `Plugin file escapes the package: ${file}` });
|
|
82
|
+
}
|
|
83
|
+
return target;
|
|
84
|
+
});
|
|
85
|
+
return Service.of({
|
|
86
|
+
inspect: Effect.fn("PluginPackage.inspect")(
|
|
87
|
+
function* (directory: string) {
|
|
88
|
+
const root = yield* fs.realPath(path.resolve(directory));
|
|
89
|
+
const manifest = yield* pipe(
|
|
90
|
+
Schema.decodeEffect(Schema.fromJsonString(Manifest))(
|
|
91
|
+
yield* fs.readFileString(path.join(root, "package.json")),
|
|
92
|
+
),
|
|
93
|
+
Effect.mapError(cause =>
|
|
94
|
+
fromCause(
|
|
95
|
+
cause,
|
|
96
|
+
"Declare a canonical SemVer version and dual.plugin.entrypoint, export and optional assets in package.json. The entrypoint must be compiled JavaScript and paths must stay inside the package.",
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
const entrypoint = yield* containedPath(root, manifest.dual.plugin.entrypoint);
|
|
101
|
+
if ((yield* fs.stat(entrypoint)).type !== "File") {
|
|
102
|
+
return yield* PackageError.make({
|
|
103
|
+
message: "The compiled entrypoint must be a regular file.",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const assets = MutableList.make<string>();
|
|
107
|
+
for (const pattern of manifest.dual.plugin.assets ?? []) {
|
|
108
|
+
const matches = yield* fs.glob(pattern, { root });
|
|
109
|
+
const files = MutableList.make<string>();
|
|
110
|
+
for (const match of matches) {
|
|
111
|
+
const target = yield* containedPath(root, match);
|
|
112
|
+
const info = yield* fs.stat(target);
|
|
113
|
+
if (info.type === "File") {
|
|
114
|
+
MutableList.append(files, target);
|
|
115
|
+
MutableList.append(assets, target);
|
|
116
|
+
} else if (info.type !== "Directory") {
|
|
117
|
+
return yield* PackageError.make({
|
|
118
|
+
message: `Asset is not a regular file: ${match}`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (Array.isReadonlyArrayEmpty(MutableList.toArray(files))) {
|
|
123
|
+
return yield* PackageError.make({ message: `No asset files match: ${pattern}` });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
assets: MutableList.toArray(assets),
|
|
128
|
+
directory: root,
|
|
129
|
+
entrypoint,
|
|
130
|
+
export: manifest.dual.plugin.export,
|
|
131
|
+
version: manifest.version,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
Effect.mapError(cause => (Schema.is(PackageError)(cause) ? cause : fromCause(cause))),
|
|
135
|
+
),
|
|
136
|
+
});
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
export * as PluginPackage from "./package.ts";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
Effect,
|
|
4
|
+
FileSystem,
|
|
5
|
+
Inspectable,
|
|
6
|
+
Layer,
|
|
7
|
+
Path,
|
|
8
|
+
Redacted,
|
|
9
|
+
Schema,
|
|
10
|
+
pipe,
|
|
11
|
+
} from "effect";
|
|
12
|
+
|
|
13
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
14
|
+
|
|
15
|
+
import { CliCredentials } from "#auth/credentials";
|
|
16
|
+
import { CliDestination } from "#auth/destination";
|
|
17
|
+
import { CliHttp } from "#auth/http";
|
|
18
|
+
import { AuthProtocol } from "#auth/protocol";
|
|
19
|
+
|
|
20
|
+
import { PluginArchive } from "./archive.ts";
|
|
21
|
+
import { PluginPackage } from "./package.ts";
|
|
22
|
+
|
|
23
|
+
export type Receipt = typeof Receipt.Type;
|
|
24
|
+
export const Receipt = Schema.Struct({
|
|
25
|
+
digest: Schema.String.check(Schema.isPattern(/^[a-f0-9]{128}$/u)),
|
|
26
|
+
organizationId: Schema.NonEmptyString,
|
|
27
|
+
plugin: Schema.NonEmptyString,
|
|
28
|
+
published: Schema.Literal(true),
|
|
29
|
+
status: Schema.Literal("validated"),
|
|
30
|
+
version: Schema.NonEmptyString,
|
|
31
|
+
});
|
|
32
|
+
export type Interface = {
|
|
33
|
+
readonly organizations: (
|
|
34
|
+
deployment: string,
|
|
35
|
+
) => Effect.Effect<AuthProtocol.Organizations, AuthProtocol.AuthError>;
|
|
36
|
+
readonly push: (
|
|
37
|
+
directory: string,
|
|
38
|
+
target: CliDestination.Target,
|
|
39
|
+
) => Effect.Effect<Receipt, PluginPackage.PackageError | AuthProtocol.AuthError>;
|
|
40
|
+
};
|
|
41
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
42
|
+
"@dual-os/cli/plugin/publication/Service",
|
|
43
|
+
) {}
|
|
44
|
+
export const layer = Layer.effect(
|
|
45
|
+
Service,
|
|
46
|
+
Effect.gen(function* () {
|
|
47
|
+
const fs = yield* FileSystem.FileSystem;
|
|
48
|
+
const path = yield* Path.Path;
|
|
49
|
+
const client = CliHttp.withErrors(yield* HttpClient.HttpClient);
|
|
50
|
+
const credentials = yield* CliCredentials.Service;
|
|
51
|
+
const archives = yield* PluginArchive.Service;
|
|
52
|
+
const destination = yield* CliDestination.Service;
|
|
53
|
+
const mapError = Effect.mapError(cause =>
|
|
54
|
+
Schema.is(AuthProtocol.AuthError)(cause) || Schema.is(PluginPackage.PackageError)(cause)
|
|
55
|
+
? cause
|
|
56
|
+
: PluginPackage.fromCause(cause),
|
|
57
|
+
);
|
|
58
|
+
return Service.of({
|
|
59
|
+
organizations: Effect.fn("PluginPublication.organizations")(
|
|
60
|
+
function* (deployment) {
|
|
61
|
+
const credential = Redacted.value(yield* credentials.get(deployment));
|
|
62
|
+
const response = yield* client.execute(
|
|
63
|
+
pipe(
|
|
64
|
+
HttpClientRequest.get(new URL("/api/cli-auth/organizations", deployment).href),
|
|
65
|
+
HttpClientRequest.bearerToken(credential.token),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
yield* CliHttp.requireStatus(response, [200]);
|
|
69
|
+
return yield* Schema.decodeUnknownEffect(AuthProtocol.Organizations)(
|
|
70
|
+
yield* pipe(response.json, Effect.mapError(CliHttp.fromCause)),
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
Effect.scoped,
|
|
74
|
+
Effect.mapError(cause =>
|
|
75
|
+
Schema.is(AuthProtocol.AuthError)(cause)
|
|
76
|
+
? cause
|
|
77
|
+
: AuthProtocol.AuthError.make({
|
|
78
|
+
cause: Redacted.make(cause),
|
|
79
|
+
message: Inspectable.toStringUnknown(cause),
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
push: Effect.fn("PluginPublication.push")(
|
|
84
|
+
function* (directory, target) {
|
|
85
|
+
const credential = Redacted.value(yield* credentials.get(target.deployment));
|
|
86
|
+
const file = path.join(
|
|
87
|
+
yield* fs.makeTempDirectoryScoped({ prefix: "dual-plugin-push-" }),
|
|
88
|
+
"plugin.tgz",
|
|
89
|
+
);
|
|
90
|
+
const artifact = yield* archives.build(directory, file);
|
|
91
|
+
const response = yield* client.execute(
|
|
92
|
+
pipe(
|
|
93
|
+
HttpClientRequest.post(new URL("/api/cli/plugins/push", target.deployment).href),
|
|
94
|
+
HttpClientRequest.bearerToken(credential.token),
|
|
95
|
+
HttpClientRequest.setHeaders({
|
|
96
|
+
"x-dual-artifact-sha512": artifact.digest,
|
|
97
|
+
"x-dual-organization-id": target.organizationId,
|
|
98
|
+
"x-dual-plugin-key": artifact.plugin,
|
|
99
|
+
"x-dual-plugin-version": artifact.version,
|
|
100
|
+
}),
|
|
101
|
+
HttpClientRequest.bodyUint8Array(yield* fs.readFile(file), "application/gzip"),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
yield* CliHttp.requireStatus(response, [200, 201]);
|
|
105
|
+
const receipt = yield* Schema.decodeUnknownEffect(Receipt)(
|
|
106
|
+
yield* pipe(response.json, Effect.mapError(CliHttp.fromCause)),
|
|
107
|
+
);
|
|
108
|
+
if (
|
|
109
|
+
receipt.digest !== artifact.digest ||
|
|
110
|
+
receipt.plugin !== artifact.plugin ||
|
|
111
|
+
receipt.version !== artifact.version ||
|
|
112
|
+
receipt.organizationId !== target.organizationId
|
|
113
|
+
) {
|
|
114
|
+
return yield* AuthProtocol.AuthError.make({
|
|
115
|
+
message:
|
|
116
|
+
"Dual returned a different artifact identity. No publication success was confirmed.",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
yield* destination.save(directory, target);
|
|
120
|
+
return receipt;
|
|
121
|
+
},
|
|
122
|
+
Effect.scoped,
|
|
123
|
+
mapError,
|
|
124
|
+
),
|
|
125
|
+
});
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
export * as PluginPublication from "./publication.ts";
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
import { NodeStream } from "@effect/platform-node";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Context,
|
|
8
|
+
Effect,
|
|
9
|
+
Fiber,
|
|
10
|
+
FileSystem,
|
|
11
|
+
Layer,
|
|
12
|
+
Path,
|
|
13
|
+
Schema,
|
|
14
|
+
Scope,
|
|
15
|
+
Stream,
|
|
16
|
+
pipe,
|
|
17
|
+
} from "effect";
|
|
18
|
+
|
|
19
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
20
|
+
|
|
21
|
+
import { PluginRuntime } from "@dual-os/sdk/PluginRuntime";
|
|
22
|
+
import { RemoteRuntime } from "@dual-os/sdk/RemoteRuntime";
|
|
23
|
+
|
|
24
|
+
import { ReleaseManifest } from "#release/release-manifest";
|
|
25
|
+
|
|
26
|
+
import { PluginInspection } from "./inspection.ts";
|
|
27
|
+
import { PluginPackage } from "./package.ts";
|
|
28
|
+
|
|
29
|
+
export class Service extends Context.Service<
|
|
30
|
+
Service,
|
|
31
|
+
{
|
|
32
|
+
readonly validate: (
|
|
33
|
+
directory: string,
|
|
34
|
+
) => Effect.Effect<PluginInspection.Result, PluginPackage.PackageError>;
|
|
35
|
+
}
|
|
36
|
+
>()("@dual-os/cli/plugin/validation/Service") {}
|
|
37
|
+
|
|
38
|
+
export const layer = Layer.effect(
|
|
39
|
+
Service,
|
|
40
|
+
Effect.gen(function* () {
|
|
41
|
+
const fs = yield* FileSystem.FileSystem;
|
|
42
|
+
const path = yield* Path.Path;
|
|
43
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
44
|
+
const packages = yield* PluginPackage.Service;
|
|
45
|
+
return Service.of({
|
|
46
|
+
validate: Effect.fn("PluginValidation.validate")(
|
|
47
|
+
function* (directory: string) {
|
|
48
|
+
const scope = yield* Scope.Scope;
|
|
49
|
+
const prepared = yield* packages.inspect(directory);
|
|
50
|
+
const require = createRequire(prepared.entrypoint);
|
|
51
|
+
const metadata = yield* Schema.decodeEffect(
|
|
52
|
+
Schema.fromJsonString(
|
|
53
|
+
Schema.Struct({
|
|
54
|
+
dual: Schema.Struct({
|
|
55
|
+
plugin: Schema.Struct({
|
|
56
|
+
runner: Schema.optionalKey(Schema.String),
|
|
57
|
+
sdk_version: Schema.optionalKey(ReleaseManifest.ExactVersion),
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
),
|
|
62
|
+
)(yield* fs.readFileString(path.join(prepared.directory, "package.json")));
|
|
63
|
+
const bundled = metadata.dual.plugin;
|
|
64
|
+
const runner =
|
|
65
|
+
bundled.runner === undefined
|
|
66
|
+
? yield* Effect.try(() => require.resolve("@dual-os/sdk/Runner"))
|
|
67
|
+
: yield* fs.realPath(path.join(prepared.directory, bundled.runner));
|
|
68
|
+
if (
|
|
69
|
+
bundled.runner !== undefined &&
|
|
70
|
+
!runner.startsWith(`${prepared.directory}${path.sep}`)
|
|
71
|
+
)
|
|
72
|
+
return yield* PluginPackage.PackageError.make({
|
|
73
|
+
message: "Bundle runner escapes the artifact",
|
|
74
|
+
});
|
|
75
|
+
const sdk =
|
|
76
|
+
bundled.sdk_version === undefined
|
|
77
|
+
? yield* Schema.decodeEffect(
|
|
78
|
+
Schema.fromJsonString(Schema.Struct({ version: ReleaseManifest.ExactVersion })),
|
|
79
|
+
)(
|
|
80
|
+
yield* fs.readFileString(
|
|
81
|
+
yield* Effect.try(() => require.resolve("@dual-os/sdk/package.json")),
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
: { version: bundled.sdk_version };
|
|
85
|
+
const executable =
|
|
86
|
+
bundled.runner === undefined
|
|
87
|
+
? process.execPath
|
|
88
|
+
: (yield* spawner.string(ChildProcess.make("which", ["bun"]))).trim();
|
|
89
|
+
const request = {
|
|
90
|
+
_tag: "extract" as const,
|
|
91
|
+
identity: {
|
|
92
|
+
artifactDigest: "0".repeat(128),
|
|
93
|
+
invocationId: "inspection",
|
|
94
|
+
organizationId: "local",
|
|
95
|
+
pluginKey: "local-inspection",
|
|
96
|
+
pluginVersion: prepared.version,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
const { child, exited } = yield* Effect.acquireRelease(
|
|
100
|
+
Effect.gen(function* () {
|
|
101
|
+
const child = yield* Effect.try(() =>
|
|
102
|
+
fork(runner, [prepared.entrypoint, prepared.export, "inspect", prepared.version], {
|
|
103
|
+
execPath: executable,
|
|
104
|
+
execArgv: bundled.runner === undefined ? [] : ["--no-env-file", "--no-install"],
|
|
105
|
+
serialization: "json",
|
|
106
|
+
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
107
|
+
cwd: prepared.directory,
|
|
108
|
+
env: {},
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
const exited = Effect.callback<number | null>(resume => {
|
|
112
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
113
|
+
resume(Effect.succeed(child.exitCode));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const closed = (code: number | null) => resume(Effect.succeed(code));
|
|
117
|
+
child.once("close", closed);
|
|
118
|
+
return Effect.sync(() => {
|
|
119
|
+
child.removeListener("close", closed);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
return { child, exited };
|
|
123
|
+
}),
|
|
124
|
+
owned =>
|
|
125
|
+
pipe(
|
|
126
|
+
Effect.sync(() => {
|
|
127
|
+
if (owned.child.exitCode === null && owned.child.signalCode === null)
|
|
128
|
+
owned.child.kill("SIGKILL");
|
|
129
|
+
}),
|
|
130
|
+
Effect.andThen(Effect.interruptible(owned.exited)),
|
|
131
|
+
Effect.timeout("5 seconds"),
|
|
132
|
+
// oxlint-disable-next-line @deslop/coding-standards/no-discarded-failure -- Scope finalizers cannot fail; unconfirmed child termination must remain a defect.
|
|
133
|
+
Effect.orDie,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
const stdout = yield* Effect.fromNullishOr(child.stdout);
|
|
137
|
+
const stderr = yield* Effect.fromNullishOr(child.stderr);
|
|
138
|
+
const diagnostic = yield* pipe(
|
|
139
|
+
Effect.all(
|
|
140
|
+
{
|
|
141
|
+
stderr: PluginRuntime.readBounded(
|
|
142
|
+
NodeStream.fromReadable({
|
|
143
|
+
evaluate: () => stderr,
|
|
144
|
+
onError: cause => PluginPackage.fromCause(cause),
|
|
145
|
+
}),
|
|
146
|
+
),
|
|
147
|
+
stdout: PluginRuntime.readBounded(
|
|
148
|
+
NodeStream.fromReadable({
|
|
149
|
+
evaluate: () => stdout,
|
|
150
|
+
onError: cause => PluginPackage.fromCause(cause),
|
|
151
|
+
}),
|
|
152
|
+
),
|
|
153
|
+
},
|
|
154
|
+
{ concurrency: "unbounded" },
|
|
155
|
+
),
|
|
156
|
+
Effect.forkIn(scope, { startImmediately: true }),
|
|
157
|
+
);
|
|
158
|
+
const output = yield* pipe(
|
|
159
|
+
PluginRuntime.ipcMessages(child),
|
|
160
|
+
Stream.mapEffect(PluginRuntime.decodeOutput),
|
|
161
|
+
Stream.take(2),
|
|
162
|
+
Stream.runCollect,
|
|
163
|
+
Effect.forkIn(scope, { startImmediately: true }),
|
|
164
|
+
);
|
|
165
|
+
yield* PluginRuntime.sendIpc(child, yield* PluginRuntime.encodeInput(request));
|
|
166
|
+
const exitCode = yield* exited;
|
|
167
|
+
const diagnostics = yield* Fiber.join(diagnostic);
|
|
168
|
+
if (exitCode !== 0) {
|
|
169
|
+
return yield* PluginPackage.PackageError.make({
|
|
170
|
+
message:
|
|
171
|
+
`${diagnostics.stderr}\n${diagnostics.stdout}`.trim() ||
|
|
172
|
+
"Plugin inspection failed. Check the compiled module and its installed SDK.",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const messages = yield* Fiber.join(output);
|
|
176
|
+
if (messages.length !== 1)
|
|
177
|
+
return yield* PluginPackage.PackageError.make({
|
|
178
|
+
message: "Plugin inspection must return one IPC response",
|
|
179
|
+
});
|
|
180
|
+
const result = yield* Schema.decodeUnknownEffect(RemoteRuntime.Response)(messages[0]);
|
|
181
|
+
yield* PluginRuntime.verifyResponse(request, result);
|
|
182
|
+
if (result._tag === "failure")
|
|
183
|
+
return yield* PluginPackage.PackageError.make({ message: result.error.message });
|
|
184
|
+
const registry = yield* Schema.decodeUnknownEffect(
|
|
185
|
+
Schema.Struct({
|
|
186
|
+
pluginIdentifier: Schema.NonEmptyString,
|
|
187
|
+
pluginVersion: ReleaseManifest.ExactVersion,
|
|
188
|
+
providers: Schema.Array(Schema.Unknown),
|
|
189
|
+
}),
|
|
190
|
+
)(result.value);
|
|
191
|
+
return {
|
|
192
|
+
plugin: registry.pluginIdentifier,
|
|
193
|
+
registry: result.value,
|
|
194
|
+
sdkVersion: sdk.version,
|
|
195
|
+
version: prepared.version,
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
Effect.timeout("30 seconds"),
|
|
199
|
+
Effect.scoped,
|
|
200
|
+
Effect.mapError(cause =>
|
|
201
|
+
Schema.is(PluginPackage.PackageError)(cause)
|
|
202
|
+
? cause
|
|
203
|
+
: PluginPackage.fromCause(
|
|
204
|
+
cause,
|
|
205
|
+
"Plugin validation failed or timed out. No publication occurred.",
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
),
|
|
209
|
+
});
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
export * as PluginValidation from "./validation.ts";
|