@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,133 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { Array, Context, Effect, Layer, Option, Record, Redacted, Schema, Stream } from "effect";
|
|
4
|
+
|
|
5
|
+
import { Tar } from "effect/encoding";
|
|
6
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
7
|
+
|
|
8
|
+
const Archive = Schema.Struct({
|
|
9
|
+
filename: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9._-]+\.tgz$/)),
|
|
10
|
+
name: Schema.NonEmptyString,
|
|
11
|
+
version: Schema.NonEmptyString,
|
|
12
|
+
});
|
|
13
|
+
type Packed = typeof Packed.Type;
|
|
14
|
+
const Packed = Schema.Union([
|
|
15
|
+
Schema.Array(Archive).check(Schema.isBetweenLength(1, 1)),
|
|
16
|
+
Schema.Record(Schema.String, Archive).check(Schema.isBetweenProperties(1, 1)),
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export class ArchiveError extends Schema.TaggedError<ArchiveError>()("ArchiveError", {
|
|
20
|
+
cause: Schema.Redacted(Schema.Defect()),
|
|
21
|
+
}) {}
|
|
22
|
+
const failure = (cause: unknown) => new ArchiveError({ cause: Redacted.make(cause) });
|
|
23
|
+
|
|
24
|
+
export type Interface = {
|
|
25
|
+
/** The caller owns a fresh disposable directory for archives and cache. */
|
|
26
|
+
readonly pack: (
|
|
27
|
+
specifier: string,
|
|
28
|
+
cwd: string,
|
|
29
|
+
) => Effect.Effect<typeof Archive.Type, ArchiveError>;
|
|
30
|
+
};
|
|
31
|
+
export class Service extends Context.Service<Service, Interface>()("@dual-os/cli/Archives") {}
|
|
32
|
+
export const layer = Layer.effect(
|
|
33
|
+
Service,
|
|
34
|
+
Effect.gen(function* () {
|
|
35
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
36
|
+
const pack = Effect.fn("Archives.pack")(
|
|
37
|
+
function* (specifier: string, cwd: string) {
|
|
38
|
+
// Fetch one archive, not a dependency tree or peer solver. A fresh cache
|
|
39
|
+
// forbids stale offline fallback. Never run scripts or echo child output.
|
|
40
|
+
const handle = yield* spawner.spawn(
|
|
41
|
+
ChildProcess.make(
|
|
42
|
+
"npm",
|
|
43
|
+
[
|
|
44
|
+
"pack",
|
|
45
|
+
specifier,
|
|
46
|
+
"--ignore-scripts",
|
|
47
|
+
"--json",
|
|
48
|
+
"--cache",
|
|
49
|
+
join(cwd, "cache"),
|
|
50
|
+
"--prefer-online",
|
|
51
|
+
"--fetch-retries=0",
|
|
52
|
+
],
|
|
53
|
+
{ cwd, stderr: "ignore", stdin: "ignore", stdout: "pipe" },
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
const output = yield* Stream.mkString(Stream.decodeText(handle.stdout));
|
|
57
|
+
if ((yield* handle.exitCode) !== 0) return yield* failure("Native package fetch failed");
|
|
58
|
+
const packed = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Packed))(output);
|
|
59
|
+
const archive = (Array.isArray<Packed>(packed) ? packed : Record.values(packed))[0];
|
|
60
|
+
if (archive === undefined) return yield* failure("Missing archive");
|
|
61
|
+
if (specifier !== archive.name && specifier !== `${archive.name}@${archive.version}`) {
|
|
62
|
+
return yield* failure("Package identity mismatch");
|
|
63
|
+
}
|
|
64
|
+
return archive;
|
|
65
|
+
},
|
|
66
|
+
Effect.scoped,
|
|
67
|
+
Effect.timeout("60 seconds"),
|
|
68
|
+
Effect.mapError(failure),
|
|
69
|
+
);
|
|
70
|
+
return Service.of({ pack });
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const documentBytes = 262144;
|
|
75
|
+
|
|
76
|
+
// The body of a named regular file, kept byte-exact (a BOM stays and fails JSON decoding).
|
|
77
|
+
const documentText = (
|
|
78
|
+
entry: Tar.Entry<Tar.TarError | ArchiveError>,
|
|
79
|
+
documents: ReadonlyArray<string>,
|
|
80
|
+
) => {
|
|
81
|
+
const { path, size, type } = entry.header;
|
|
82
|
+
if (!Array.contains(documents, path) || type !== "File" || size > documentBytes) {
|
|
83
|
+
return Effect.succeedNone;
|
|
84
|
+
}
|
|
85
|
+
return Effect.map(Stream.mkUint8Array(entry.body), body =>
|
|
86
|
+
Option.some(new TextDecoder("utf-8", { ignoreBOM: true }).decode(body)),
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Lists a gzipped npm archive's regular files and reads the named documents.
|
|
92
|
+
* Never extracts or evaluates package code; a duplicate path, or a named document
|
|
93
|
+
* that is not a regular file within 256 KiB, fails.
|
|
94
|
+
*/
|
|
95
|
+
export const read = Effect.fn("Archives.read")(function* (
|
|
96
|
+
archive: Uint8Array,
|
|
97
|
+
documents: ReadonlyArray<string>,
|
|
98
|
+
) {
|
|
99
|
+
const entries = yield* Stream.fromReadableStream({
|
|
100
|
+
evaluate: () =>
|
|
101
|
+
new Blob([Uint8Array.from(archive)]).stream().pipeThrough(new DecompressionStream("gzip")),
|
|
102
|
+
onError: failure,
|
|
103
|
+
}).pipe(
|
|
104
|
+
Stream.pipeThroughChannel(Tar.decode()),
|
|
105
|
+
Stream.mapEffect(entry =>
|
|
106
|
+
Effect.map(documentText(entry, documents), text => ({ header: entry.header, text })),
|
|
107
|
+
),
|
|
108
|
+
Stream.runCollect,
|
|
109
|
+
);
|
|
110
|
+
const paths = Array.map(entries, entry => entry.header.path);
|
|
111
|
+
const named = Array.filter(entries, entry => Array.contains(documents, entry.header.path));
|
|
112
|
+
if (
|
|
113
|
+
Array.dedupe(paths).length !== paths.length ||
|
|
114
|
+
Array.some(named, entry => Option.isNone(entry.text))
|
|
115
|
+
) {
|
|
116
|
+
return yield* failure("Duplicate or invalid metadata archive entries");
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
documents: Record.fromEntries(
|
|
120
|
+
Array.getSomes(
|
|
121
|
+
Array.map(named, entry =>
|
|
122
|
+
Option.map(entry.text, text => [entry.header.path, text] as const),
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
files: Array.map(
|
|
127
|
+
Array.filter(entries, entry => entry.header.type === "File"),
|
|
128
|
+
entry => entry.header.path,
|
|
129
|
+
),
|
|
130
|
+
};
|
|
131
|
+
}, Effect.mapError(failure));
|
|
132
|
+
|
|
133
|
+
export * as Archives from "./archives.ts";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Array, Schema, String } from "effect";
|
|
2
|
+
|
|
3
|
+
import semver from "semver";
|
|
4
|
+
|
|
5
|
+
import { Deployment } from "../create/deployment.ts";
|
|
6
|
+
|
|
7
|
+
export const packageName = "@dual/release-manifest";
|
|
8
|
+
export const Version = Schema.String.check(Schema.isPattern(/^0\.0\.[1-9][0-9]*$/));
|
|
9
|
+
export const ExactVersion = Schema.String.check(
|
|
10
|
+
Schema.makeFilter(value => {
|
|
11
|
+
const parsed = semver.parse(value);
|
|
12
|
+
return (
|
|
13
|
+
parsed !== null &&
|
|
14
|
+
value ===
|
|
15
|
+
`${parsed.version}${Array.isReadonlyArrayEmpty(parsed.build) ? "" : `+${Array.join(parsed.build, ".")}`}`
|
|
16
|
+
);
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
// Field order is the manifest's key order: candidates first, then the public toolchain in
|
|
20
|
+
// download order.
|
|
21
|
+
const framework = {
|
|
22
|
+
"@dual/core": ExactVersion,
|
|
23
|
+
"@dual-os/sdk": ExactVersion,
|
|
24
|
+
"@dual/dualspec": ExactVersion,
|
|
25
|
+
"@dual/workspace-opensandbox": ExactVersion,
|
|
26
|
+
effect: ExactVersion,
|
|
27
|
+
"@effect/platform-node": ExactVersion,
|
|
28
|
+
"@effect/vitest": ExactVersion,
|
|
29
|
+
typescript: ExactVersion,
|
|
30
|
+
vitest: ExactVersion,
|
|
31
|
+
"bun-types": ExactVersion,
|
|
32
|
+
};
|
|
33
|
+
export const Packages = Schema.Struct({
|
|
34
|
+
...framework,
|
|
35
|
+
"@dual/ai-providers": Schema.optionalKey(ExactVersion),
|
|
36
|
+
"@deslop/coding-standards": ExactVersion,
|
|
37
|
+
});
|
|
38
|
+
// Releases published before the scaffold moved to @deslop/coding-standards. The CLI still lists
|
|
39
|
+
// them, but creates repositories only from current releases.
|
|
40
|
+
const PreviousPackages = Schema.Struct({ ...framework, "@deslop/workflow": ExactVersion });
|
|
41
|
+
const manifestFields = {
|
|
42
|
+
schemaVersion: Schema.Literal(1),
|
|
43
|
+
version: Version,
|
|
44
|
+
commit: Schema.String.check(Schema.isPattern(/^[a-f0-9]{40}$/)),
|
|
45
|
+
compatibility: Schema.Struct({
|
|
46
|
+
cli: Schema.NonEmptyString.check(Schema.makeFilter(value => semver.validRange(value) !== null)),
|
|
47
|
+
template: Schema.NonEmptyString,
|
|
48
|
+
}),
|
|
49
|
+
packageManager: Schema.String.check(
|
|
50
|
+
Schema.makeFilter(
|
|
51
|
+
value => String.startsWith("bun@")(value) && Schema.is(ExactVersion)(String.slice(4)(value)),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
pair: Deployment.CurrentPair,
|
|
55
|
+
};
|
|
56
|
+
const corePinMatchesPair = Schema.makeFilter(
|
|
57
|
+
(manifest: { packages: { "@dual/core": string }; pair: { coreVersion: string } }) =>
|
|
58
|
+
manifest.packages["@dual/core"] === manifest.pair.coreVersion,
|
|
59
|
+
{ message: "Core pin must match the qualified image pair" },
|
|
60
|
+
);
|
|
61
|
+
export const Manifest = Schema.Struct({ ...manifestFields, packages: Packages }).check(
|
|
62
|
+
corePinMatchesPair,
|
|
63
|
+
);
|
|
64
|
+
export type Manifest = typeof Manifest.Type;
|
|
65
|
+
/** A current manifest or one published before the move to @deslop/coding-standards or before
|
|
66
|
+
* plugins left the release. */
|
|
67
|
+
export const ReadableManifest = Schema.Struct({
|
|
68
|
+
...manifestFields,
|
|
69
|
+
packages: Schema.Union([Packages, PreviousPackages]),
|
|
70
|
+
plugins: Schema.optionalKey(Schema.Record(Schema.String, ExactVersion)),
|
|
71
|
+
}).check(corePinMatchesPair);
|
|
72
|
+
export type ReadableManifest = typeof ReadableManifest.Type;
|
|
73
|
+
const integrity = Schema.String.check(Schema.isPattern(/^sha512-[A-Za-z0-9+/]{85}[AQgw]==$/));
|
|
74
|
+
export const Selection = Schema.Struct({ integrity, manifest: Manifest });
|
|
75
|
+
export type Selection = typeof Selection.Type;
|
|
76
|
+
export const ReadableSelection = Schema.Struct({ integrity, manifest: ReadableManifest });
|
|
77
|
+
export type ReadableSelection = typeof ReadableSelection.Type;
|
|
78
|
+
|
|
79
|
+
export * as ReleaseManifest from "./release-manifest.ts";
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Array,
|
|
8
|
+
Context,
|
|
9
|
+
Effect,
|
|
10
|
+
FileSystem,
|
|
11
|
+
Layer,
|
|
12
|
+
Order,
|
|
13
|
+
Redacted,
|
|
14
|
+
Schema,
|
|
15
|
+
Stream,
|
|
16
|
+
String,
|
|
17
|
+
} from "effect";
|
|
18
|
+
|
|
19
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
20
|
+
import semver from "semver";
|
|
21
|
+
|
|
22
|
+
import { Archives } from "./archives.ts";
|
|
23
|
+
import { ReleaseManifest } from "./release-manifest.ts";
|
|
24
|
+
|
|
25
|
+
export const packageName = ReleaseManifest.packageName;
|
|
26
|
+
export const Version = ReleaseManifest.Version;
|
|
27
|
+
export const CoreSelector = Schema.Union([Schema.Literal("latest"), ReleaseManifest.ExactVersion]);
|
|
28
|
+
export const Selector = CoreSelector;
|
|
29
|
+
export const Request = Schema.Union([
|
|
30
|
+
Schema.Struct({ core: CoreSelector, manifest: Schema.optionalKey(Schema.Never) }),
|
|
31
|
+
Schema.Struct({ core: Schema.optionalKey(Schema.Never), manifest: Version }),
|
|
32
|
+
]);
|
|
33
|
+
export type Request = typeof Request.Type;
|
|
34
|
+
const Metadata = Schema.Struct({
|
|
35
|
+
bin: Schema.optionalKey(Schema.Never),
|
|
36
|
+
bundleDependencies: Schema.optionalKey(Schema.Array(Schema.Never)),
|
|
37
|
+
bundledDependencies: Schema.optionalKey(Schema.Array(Schema.Never)),
|
|
38
|
+
dependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.Never)),
|
|
39
|
+
devDependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.Never)),
|
|
40
|
+
dualRelease: Schema.optionalKey(Schema.Unknown),
|
|
41
|
+
files: Schema.Tuple([Schema.Literal("release.json")]),
|
|
42
|
+
name: Schema.Literal(packageName),
|
|
43
|
+
optionalDependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.Never)),
|
|
44
|
+
peerDependencies: Schema.optionalKey(Schema.Record(Schema.String, Schema.Never)),
|
|
45
|
+
scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.Never)),
|
|
46
|
+
version: Version,
|
|
47
|
+
});
|
|
48
|
+
export class ReleaseError extends Schema.TaggedError<ReleaseError>()("ReleaseError", {
|
|
49
|
+
cause: Schema.Redacted(Schema.Defect()),
|
|
50
|
+
}) {}
|
|
51
|
+
const failure = (cause: unknown) => new ReleaseError({ cause: Redacted.make(cause) });
|
|
52
|
+
export type Interface = {
|
|
53
|
+
readonly resolve: (
|
|
54
|
+
request: Request,
|
|
55
|
+
) => Effect.Effect<ReleaseManifest.ReadableSelection, ReleaseError>;
|
|
56
|
+
readonly resolveForCreate: (
|
|
57
|
+
request: Request,
|
|
58
|
+
compatibility: { readonly cli: string; readonly template: string },
|
|
59
|
+
) => Effect.Effect<ReleaseManifest.Selection, ReleaseError>;
|
|
60
|
+
readonly verify: (
|
|
61
|
+
selection: ReleaseManifest.Selection,
|
|
62
|
+
) => Effect.Effect<ReleaseManifest.Selection, ReleaseError>;
|
|
63
|
+
};
|
|
64
|
+
export class Service extends Context.Service<Service, Interface>()("@dual-os/cli/Releases") {}
|
|
65
|
+
export const layer = Layer.effect(
|
|
66
|
+
Service,
|
|
67
|
+
Effect.gen(function* () {
|
|
68
|
+
const archives = yield* Archives.Service;
|
|
69
|
+
const fs = yield* FileSystem.FileSystem;
|
|
70
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
71
|
+
const resolve = Effect.fn("Releases.resolve")(
|
|
72
|
+
function* (
|
|
73
|
+
input: Request,
|
|
74
|
+
compatibility?: { readonly cli: string; readonly template: string },
|
|
75
|
+
) {
|
|
76
|
+
const request = yield* Schema.decodeUnknownEffect(Request, { onExcessProperty: "error" })(
|
|
77
|
+
input,
|
|
78
|
+
);
|
|
79
|
+
const cwd = yield* fs.makeTempDirectoryScoped({
|
|
80
|
+
directory: tmpdir(),
|
|
81
|
+
prefix: "dual-releases-",
|
|
82
|
+
});
|
|
83
|
+
yield* fs.writeFileString(join(cwd, "package.json"), '{"private":true}\n');
|
|
84
|
+
const view = Effect.fn("Releases.view")(function* () {
|
|
85
|
+
const handle = yield* spawner.spawn(
|
|
86
|
+
ChildProcess.make(
|
|
87
|
+
"npm",
|
|
88
|
+
[
|
|
89
|
+
"view",
|
|
90
|
+
`${packageName}@>=0.0.0`,
|
|
91
|
+
"version",
|
|
92
|
+
"--json",
|
|
93
|
+
"--cache",
|
|
94
|
+
join(cwd, "cache"),
|
|
95
|
+
"--prefer-online",
|
|
96
|
+
"--fetch-retries=0",
|
|
97
|
+
],
|
|
98
|
+
{ cwd, stderr: "ignore", stdin: "ignore", stdout: "pipe" },
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
const output = yield* Stream.mkString(Stream.decodeText(handle.stdout));
|
|
102
|
+
if ((yield* handle.exitCode) !== 0) {
|
|
103
|
+
return yield* failure(
|
|
104
|
+
"Manifest unavailable; check external npm registry credentials and release activation",
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return output;
|
|
108
|
+
});
|
|
109
|
+
// Range enumeration ignores mutable/default dist-tags, including latest.
|
|
110
|
+
const enumerated =
|
|
111
|
+
request.manifest === undefined
|
|
112
|
+
? yield* Schema.decodeUnknownEffect(
|
|
113
|
+
Schema.fromJsonString(
|
|
114
|
+
Schema.Union([Version, Schema.Array(Version).check(Schema.isMinLength(1))]),
|
|
115
|
+
),
|
|
116
|
+
)(yield* view())
|
|
117
|
+
: [request.manifest];
|
|
118
|
+
const versions = typeof enumerated === "string" ? [enumerated] : enumerated;
|
|
119
|
+
for (const version of Array.sortWith(
|
|
120
|
+
[...new Set(versions)],
|
|
121
|
+
version => BigInt(String.slice(4)(version)),
|
|
122
|
+
Order.flip(Order.BigInt),
|
|
123
|
+
)) {
|
|
124
|
+
const directory = join(cwd, version);
|
|
125
|
+
yield* fs.makeDirectory(directory);
|
|
126
|
+
const archive = yield* archives.pack(`${packageName}@${version}`, directory);
|
|
127
|
+
const bytes = yield* fs.readFile(join(directory, archive.filename));
|
|
128
|
+
// Hash actual downloaded archive bytes, never trust registry integrity metadata.
|
|
129
|
+
const integrity = `sha512-${createHash("sha512").update(bytes).digest("base64")}`;
|
|
130
|
+
const { documents } = yield* Archives.read(bytes, [
|
|
131
|
+
"package/package.json",
|
|
132
|
+
"package/release.json",
|
|
133
|
+
]);
|
|
134
|
+
const metadata = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Metadata))(
|
|
135
|
+
documents["package/package.json"],
|
|
136
|
+
);
|
|
137
|
+
if (metadata.dualRelease !== undefined) {
|
|
138
|
+
yield* Schema.decodeUnknownEffect(ReleaseManifest.ReadableManifest, {
|
|
139
|
+
onExcessProperty: "error",
|
|
140
|
+
})(metadata.dualRelease);
|
|
141
|
+
}
|
|
142
|
+
const manifest = yield* Schema.decodeUnknownEffect(
|
|
143
|
+
Schema.fromJsonString(ReleaseManifest.ReadableManifest),
|
|
144
|
+
{ onExcessProperty: "error" },
|
|
145
|
+
)(documents["package/release.json"]);
|
|
146
|
+
if (
|
|
147
|
+
metadata.version !== version ||
|
|
148
|
+
manifest.version !== version ||
|
|
149
|
+
(metadata.dualRelease !== undefined &&
|
|
150
|
+
!isDeepStrictEqual(metadata.dualRelease, manifest))
|
|
151
|
+
) {
|
|
152
|
+
return yield* failure("Manifest identity or metadata mismatch");
|
|
153
|
+
}
|
|
154
|
+
// Validate archive and identity before filtering; malformed candidates fail closed.
|
|
155
|
+
if (
|
|
156
|
+
request.core !== undefined &&
|
|
157
|
+
request.core !== "latest" &&
|
|
158
|
+
manifest.packages["@dual/core"] !== request.core
|
|
159
|
+
) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (
|
|
163
|
+
compatibility === undefined ||
|
|
164
|
+
(manifest.compatibility.template === compatibility.template &&
|
|
165
|
+
semver.satisfies(compatibility.cli, manifest.compatibility.cli))
|
|
166
|
+
) {
|
|
167
|
+
return { integrity, manifest };
|
|
168
|
+
}
|
|
169
|
+
// Core discovery may skip valid incompatible snapshots of the SAME core.
|
|
170
|
+
// An explicit manifest is exact and never substitutes.
|
|
171
|
+
if (request.manifest !== undefined) {
|
|
172
|
+
return yield* failure("Exact release is incompatible with this CLI/template");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return yield* failure("No completed release matches the requested core and compatibility");
|
|
176
|
+
},
|
|
177
|
+
Effect.scoped,
|
|
178
|
+
Effect.timeout("60 seconds"),
|
|
179
|
+
Effect.mapError(failure),
|
|
180
|
+
);
|
|
181
|
+
// Repositories come only from current releases; an older one names the CLI that creates it.
|
|
182
|
+
const resolveForCreate = Effect.fn("Releases.resolveForCreate")(function* (
|
|
183
|
+
request: Request,
|
|
184
|
+
compatibility: { readonly cli: string; readonly template: string },
|
|
185
|
+
) {
|
|
186
|
+
return yield* Schema.decodeUnknownEffect(ReleaseManifest.Selection)(
|
|
187
|
+
yield* resolve(request, compatibility),
|
|
188
|
+
).pipe(
|
|
189
|
+
Effect.mapError(() =>
|
|
190
|
+
failure(
|
|
191
|
+
"This release predates @deslop/coding-standards; create it with the CLI it names",
|
|
192
|
+
),
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
const verify = Effect.fn("Releases.verify")(function* (input: ReleaseManifest.Selection) {
|
|
197
|
+
const selection = yield* Schema.decodeUnknownEffect(ReleaseManifest.Selection, {
|
|
198
|
+
onExcessProperty: "error",
|
|
199
|
+
})(input).pipe(Effect.mapError(failure));
|
|
200
|
+
const actual = yield* resolve({ manifest: selection.manifest.version });
|
|
201
|
+
if (!isDeepStrictEqual(actual, selection)) {
|
|
202
|
+
return yield* failure("Exact release archive integrity or manifest changed");
|
|
203
|
+
}
|
|
204
|
+
return selection;
|
|
205
|
+
});
|
|
206
|
+
return Service.of({ resolve: request => resolve(request), resolveForCreate, verify });
|
|
207
|
+
}),
|
|
208
|
+
).pipe(Layer.provide(Archives.layer));
|
|
209
|
+
|
|
210
|
+
export * as Releases from "./releases.ts";
|