effect-ci 0.0.0-stage → 0.1.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.
@@ -0,0 +1,12 @@
1
+ import {
2
+ boundedCommandOutput,
3
+ commandDiagnosticLimit,
4
+ decodeCommandDiagnostics,
5
+ encodeCommandDiagnostics
6
+ } from "./chunks/chunk-WGBTI7DS.js";
7
+ export {
8
+ boundedCommandOutput,
9
+ commandDiagnosticLimit,
10
+ decodeCommandDiagnostics,
11
+ encodeCommandDiagnostics
12
+ };
@@ -0,0 +1,167 @@
1
+ import {
2
+ executionMode
3
+ } from "./chunks/chunk-X4HGOXPL.js";
4
+ import "./chunks/chunk-WGBTI7DS.js";
5
+ import "./chunks/chunk-MZ5FQEN6.js";
6
+ import {
7
+ pathPatterns,
8
+ pathPrefixes
9
+ } from "./chunks/chunk-U3DVQKHN.js";
10
+ import "./chunks/chunk-WOG7K3QJ.js";
11
+
12
+ // ../ci/src/directory-deployment.ts
13
+ import { createHash, randomUUID } from "node:crypto";
14
+ import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
15
+ import { join, parse, resolve } from "node:path";
16
+ import * as Effect from "effect/Effect";
17
+ import * as Glob from "effect/Glob";
18
+ var hash = (value) => createHash("sha256").update(value).digest("hex");
19
+ var hex = /^[a-f0-9]{64}$/;
20
+ var uuid = /^[a-f0-9-]{36}$/;
21
+ var relativePath = (path) => !!path && path.length <= 4096 && !path.startsWith("/") && !/[\\\x00-\x1f]/.test(path) && !path.split("/").some((p) => !p || p === "." || p === "..");
22
+ var missing = (error) => error?.code === "ENOENT";
23
+ function bytes(root, path) {
24
+ if (!relativePath(path)) throw Error("Invalid deployment path");
25
+ if (lstatSync(root).isSymbolicLink() || !lstatSync(root).isDirectory()) throw Error("Invalid deployment root");
26
+ let current = root;
27
+ for (const part of path.split("/")) {
28
+ current = join(current, part);
29
+ if (lstatSync(current).isSymbolicLink()) throw Error("Deployment symlinks are unsupported");
30
+ }
31
+ const stat = lstatSync(current);
32
+ if (!stat.isFile() || stat.size > 16 * 1024 * 1024) throw Error("Invalid deployment file");
33
+ const data = readFileSync(current);
34
+ if (data.length !== stat.size) throw Error("Deployment file changed while reading");
35
+ return { bytes: data, file: { path, size: data.length, sha256: hash(data), executable: !!(stat.mode & 73) } };
36
+ }
37
+ function directoryUnder(root, path) {
38
+ let current = root;
39
+ for (const part of path.split("/")) {
40
+ if (!part || part === "." || part === "..") throw Error("Invalid deployment directory");
41
+ current = join(current, part);
42
+ try {
43
+ const stat = lstatSync(current);
44
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw Error("Invalid deployment directory");
45
+ } catch (error) {
46
+ if (!missing(error)) throw error;
47
+ mkdirSync(current, { mode: 448 });
48
+ }
49
+ }
50
+ }
51
+ function directoryDeployment(options) {
52
+ const directory = resolve(options.directory), paths = pathPatterns(options.paths), matchers = paths.map((pattern) => Glob.make(pattern, { dot: true }));
53
+ if (directory === parse(directory).root) throw Error("A deployment needs its own directory");
54
+ const configuration = hash(options.configuration ?? "directory-deployment-v1");
55
+ const currentPath = join(directory, "current.json");
56
+ const root = () => {
57
+ if (lstatSync(directory).isSymbolicLink() || !lstatSync(directory).isDirectory()) throw Error("Invalid deployment directory");
58
+ return realpathSync(directory);
59
+ };
60
+ const candidate = (workspace) => {
61
+ if (workspace.kind !== "local") throw Error("Directory deployment requires a local workspace");
62
+ const cwd = realpathSync(workspace.cwd), found = /* @__PURE__ */ new Set();
63
+ let visited = 0, size = 0;
64
+ const walk = (path) => {
65
+ if (++visited > 1e4) throw Error("Deployment traversal limit exceeded");
66
+ let stat;
67
+ try {
68
+ stat = lstatSync(join(cwd, path));
69
+ } catch (error) {
70
+ if (missing(error)) return;
71
+ throw error;
72
+ }
73
+ if (stat.isSymbolicLink()) throw Error("Deployment symlinks are unsupported");
74
+ if (stat.isDirectory()) for (const name of readdirSync(join(cwd, path)).sort()) walk(path ? `${path}/${name}` : name);
75
+ else if (matchers.some((pattern) => Glob.match(pattern, path))) {
76
+ if (!stat.isFile()) throw Error("Invalid deployment file");
77
+ found.add(path);
78
+ }
79
+ };
80
+ for (const prefix of pathPrefixes(paths)) walk(prefix);
81
+ const data = [...found].sort().map((path) => {
82
+ const value = bytes(cwd, path);
83
+ size += value.bytes.length;
84
+ if (size > 16 * 1024 * 1024 || found.size > 1e3) throw Error("Deployment byte limit exceeded");
85
+ return value;
86
+ });
87
+ const manifest = { version: 1, paths, configuration, files: data.map((value) => value.file) };
88
+ return { manifest, data, digest: hash(JSON.stringify(manifest)) };
89
+ };
90
+ const current = () => {
91
+ let pointer;
92
+ try {
93
+ if (!lstatSync(currentPath).isFile() || lstatSync(currentPath).isSymbolicLink() || lstatSync(currentPath).size > 4096)
94
+ throw Error("Invalid deployment pointer");
95
+ pointer = JSON.parse(readFileSync(currentPath, "utf8"));
96
+ } catch (error) {
97
+ if (missing(error)) return;
98
+ throw error;
99
+ }
100
+ if (pointer.version !== 1 || !uuid.test(pointer.id) || !hex.test(pointer.digest)) throw Error("Invalid deployment receipt");
101
+ const base = root(), versions = join(base, "versions"), version = join(versions, pointer.id);
102
+ if (lstatSync(versions).isSymbolicLink() || lstatSync(version).isSymbolicLink()) throw Error("Invalid deployment version");
103
+ const raw = bytes(version, "manifest.json").bytes;
104
+ if (raw.length > 1024 * 1024 || hash(raw) !== pointer.digest) throw Error("Deployment manifest mismatch");
105
+ const manifest = JSON.parse(raw.toString("utf8"));
106
+ if (manifest.version !== 1 || !hex.test(manifest.configuration) || !Array.isArray(manifest.files) || manifest.files.length > 1e3 || JSON.stringify(manifest.paths) !== JSON.stringify(pathPatterns(manifest.paths))) throw Error("Invalid deployment manifest");
107
+ let size = 0;
108
+ const seen = /* @__PURE__ */ new Set();
109
+ for (const file of manifest.files) {
110
+ if (!relativePath(file.path) || seen.has(file.path)) throw Error("Invalid deployment manifest path");
111
+ seen.add(file.path);
112
+ const actual = bytes(join(version, "files"), file.path);
113
+ size += actual.bytes.length;
114
+ if (size > 16 * 1024 * 1024 || JSON.stringify(actual.file) !== JSON.stringify(file)) throw Error("Deployed bytes mismatch");
115
+ }
116
+ return { pointer, manifest, directory: join(version, "files") };
117
+ };
118
+ const changes = { changed: (request) => Effect.try({ try: () => {
119
+ if (JSON.stringify(pathPatterns(request.patterns)) !== JSON.stringify(paths)) return void 0;
120
+ const deployed = current();
121
+ if (!deployed) return true;
122
+ return candidate(request.workspace).digest !== deployed.pointer.digest;
123
+ }, catch: (error) => error }) };
124
+ return {
125
+ changes,
126
+ publish: (workspace) => Effect.gen(function* () {
127
+ if ((yield* executionMode) === "plan") return void 0;
128
+ return yield* Effect.try({ try: () => {
129
+ const selected = candidate(workspace);
130
+ if (!selected.data.length) throw Error("Refusing an empty directory deployment");
131
+ mkdirSync(directory, { recursive: true, mode: 448 });
132
+ const base = root(), lock = join(base, "publication.lock");
133
+ writeFileSync(lock, "active", { flag: "wx", mode: 384 });
134
+ try {
135
+ const id = randomUUID(), version = join(base, "versions", id);
136
+ directoryUnder(base, "versions");
137
+ mkdirSync(version, { mode: 448 });
138
+ directoryUnder(version, "files");
139
+ for (const item of selected.data) {
140
+ const path = join(version, "files", item.file.path);
141
+ const parent = item.file.path.split("/").slice(0, -1).join("/");
142
+ if (parent) directoryUnder(join(version, "files"), parent);
143
+ writeFileSync(path, item.bytes, { flag: "wx", mode: item.file.executable ? 448 : 384 });
144
+ if (JSON.stringify(bytes(join(version, "files"), item.file.path).file) !== JSON.stringify(item.file))
145
+ throw Error("Deployment readback mismatch");
146
+ }
147
+ writeFileSync(join(version, "manifest.json"), JSON.stringify(selected.manifest), { flag: "wx", mode: 384 });
148
+ const receipt = { version: 1, id, digest: selected.digest };
149
+ const next = join(base, `current-${id}.json`);
150
+ writeFileSync(next, JSON.stringify(receipt), { flag: "wx", mode: 384 });
151
+ renameSync(next, currentPath);
152
+ return receipt;
153
+ } finally {
154
+ unlinkSync(lock);
155
+ }
156
+ }, catch: (error) => error });
157
+ }),
158
+ read: (path) => Effect.try({ try: () => {
159
+ const deployed = current();
160
+ if (!deployed || !deployed.manifest.files.some((file) => file.path === path)) return void 0;
161
+ return bytes(deployed.directory, path).bytes;
162
+ }, catch: (error) => error })
163
+ };
164
+ }
165
+ export {
166
+ directoryDeployment
167
+ };
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../cli/src/sdk-loader.ts
4
+ import { readFileSync } from "node:fs";
5
+ import { registerHooks, stripTypeScriptTypes } from "node:module";
6
+ import { fileURLToPath } from "node:url";
7
+ var runtime = new URL("../", import.meta.url).href;
8
+ registerHooks({
9
+ resolve(specifier, context, nextResolve) {
10
+ if (specifier === "effect" || specifier.startsWith("effect/")) {
11
+ return nextResolve(specifier, { ...context, parentURL: import.meta.url });
12
+ }
13
+ const sdk = /^(@effect-ci-testbed\/ci|effect-ci)(\/.*)?$/.exec(specifier);
14
+ if (sdk) {
15
+ const runtimeContext = { ...context, parentURL: import.meta.url };
16
+ try {
17
+ return nextResolve(specifier, runtimeContext);
18
+ } catch (error) {
19
+ const other = (sdk[1] === "effect-ci" ? "@effect-ci-testbed/ci" : "effect-ci") + (sdk[2] ?? "");
20
+ try {
21
+ return nextResolve(other, runtimeContext);
22
+ } catch {
23
+ throw error;
24
+ }
25
+ }
26
+ }
27
+ return nextResolve(specifier, context);
28
+ },
29
+ load(url, context, nextLoad) {
30
+ if (url.startsWith(runtime) && url.includes("/node_modules/") && url.endsWith(".ts")) {
31
+ return {
32
+ format: "module",
33
+ shortCircuit: true,
34
+ source: stripTypeScriptTypes(readFileSync(fileURLToPath(url), "utf8"), { mode: "strip", sourceUrl: url })
35
+ };
36
+ }
37
+ return nextLoad(url, context);
38
+ }
39
+ });
40
+
41
+ // ../cli/src/effect-ci.ts
42
+ var { runCli } = await import("./chunks/src-FUJGARUK.js");
43
+ await runCli();
package/dist/index.js ADDED
@@ -0,0 +1,103 @@
1
+ import {
2
+ Approval,
3
+ ApprovalError,
4
+ Apt,
5
+ Artifact,
6
+ Attempt,
7
+ CommandCheckpointError,
8
+ CommandError,
9
+ CommandExecutionError,
10
+ Condition,
11
+ JavaScript,
12
+ PackageManager,
13
+ PackageManagerError,
14
+ RollbackError,
15
+ Secret,
16
+ SecretError,
17
+ Source,
18
+ Toolchain,
19
+ ToolchainError,
20
+ VitePlus,
21
+ VitePlusAvailable,
22
+ WorkflowEvent,
23
+ WorkflowPlanError,
24
+ Workspace,
25
+ WorkspaceArtifact,
26
+ WorkspaceCheckpoint,
27
+ action,
28
+ check,
29
+ executionMode,
30
+ force,
31
+ formatCondition,
32
+ formatPlan,
33
+ fromPackageJson,
34
+ isAction,
35
+ makeRuntimeObservers,
36
+ matchesCondition,
37
+ optional,
38
+ parallel,
39
+ planRerun,
40
+ run,
41
+ runPromise,
42
+ step,
43
+ when,
44
+ workflow
45
+ } from "./chunks/chunk-X4HGOXPL.js";
46
+ import {
47
+ boundedCommandOutput,
48
+ commandDiagnosticLimit,
49
+ decodeCommandDiagnostics,
50
+ encodeCommandDiagnostics
51
+ } from "./chunks/chunk-WGBTI7DS.js";
52
+ import "./chunks/chunk-MZ5FQEN6.js";
53
+ import "./chunks/chunk-U3DVQKHN.js";
54
+ import "./chunks/chunk-WOG7K3QJ.js";
55
+ export {
56
+ Approval,
57
+ ApprovalError,
58
+ Apt,
59
+ Artifact,
60
+ Attempt,
61
+ CommandCheckpointError,
62
+ CommandError,
63
+ CommandExecutionError,
64
+ Condition,
65
+ JavaScript,
66
+ PackageManager,
67
+ PackageManagerError,
68
+ RollbackError,
69
+ Secret,
70
+ SecretError,
71
+ Source,
72
+ Toolchain,
73
+ ToolchainError,
74
+ VitePlus,
75
+ VitePlusAvailable,
76
+ WorkflowEvent,
77
+ WorkflowPlanError,
78
+ Workspace,
79
+ WorkspaceArtifact,
80
+ WorkspaceCheckpoint,
81
+ action,
82
+ boundedCommandOutput,
83
+ check,
84
+ commandDiagnosticLimit,
85
+ decodeCommandDiagnostics,
86
+ encodeCommandDiagnostics,
87
+ executionMode,
88
+ force,
89
+ formatCondition,
90
+ formatPlan,
91
+ fromPackageJson,
92
+ isAction,
93
+ makeRuntimeObservers,
94
+ matchesCondition,
95
+ optional,
96
+ parallel,
97
+ planRerun,
98
+ run,
99
+ runPromise,
100
+ step,
101
+ when,
102
+ workflow
103
+ };
package/dist/paths.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ pathPatterns,
3
+ pathPrefixes
4
+ } from "./chunks/chunk-U3DVQKHN.js";
5
+ export {
6
+ pathPatterns,
7
+ pathPrefixes
8
+ };
@@ -0,0 +1,11 @@
1
+ import {
2
+ gitSourceChangesCommand,
3
+ makeSourceQueries,
4
+ parseGitSourceChanges
5
+ } from "./chunks/chunk-MZ5FQEN6.js";
6
+ import "./chunks/chunk-U3DVQKHN.js";
7
+ export {
8
+ gitSourceChangesCommand,
9
+ makeSourceQueries,
10
+ parseGitSourceChanges
11
+ };
@@ -0,0 +1,64 @@
1
+ // ../ci/src/task-cache.ts
2
+ var taskCacheProgram = String.raw`
3
+ const fs = require("node:fs")
4
+ const path = require("node:path")
5
+ const root = path.resolve(process.argv[1])
6
+ const project = path.resolve(root, process.argv[2] || ".")
7
+ const relative = path.relative(root, project)
8
+ if (relative === ".." || relative.startsWith(".." + path.sep) || path.isAbsolute(relative)) {
9
+ throw Error("Cache discovery root must be inside the repository")
10
+ }
11
+ const paths = new Set()
12
+ const add = (directory, name) => paths.add(
13
+ path.relative(root, path.join(directory, name)).split(path.sep).join("/"),
14
+ )
15
+ const inspect = (directory, conventional = false) => {
16
+ const entries = fs.readdirSync(directory, { withFileTypes: true })
17
+ const names = new Set(entries.filter(entry => entry.isFile()).map(entry => entry.name))
18
+ let manifest = {}
19
+ if (names.has("package.json")) {
20
+ try { manifest = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8")) ?? {} }
21
+ catch { /* Invalid project metadata cannot grant cache eligibility. */ }
22
+ }
23
+ const dependencies = { ...manifest.dependencies, ...manifest.devDependencies }
24
+ const scripts = Object.values(manifest.scripts ?? {}).filter(value => typeof value === "string").join("\n")
25
+ if (conventional || dependencies["vite-plus"] || /\b(?:vp|vpr)\b/.test(scripts) ||
26
+ [...names].some(name => /^vite\.config\.[cm]?[jt]s$/.test(name))) {
27
+ add(directory, "node_modules/.vite/task-cache")
28
+ }
29
+ if (conventional || dependencies.turbo || /\bturbo\b/.test(scripts) || names.has("turbo.json") || names.has("turbo.jsonc")) {
30
+ add(directory, ".turbo/cache")
31
+ }
32
+ if (conventional || names.has("package.json")) {
33
+ add(directory, ".effect-ci/cache")
34
+ // pnpm otherwise rewrites prunedAt after every fresh install, producing
35
+ // timestamp-only misses in tools that track dependency metadata.
36
+ add(directory, "node_modules/.modules.yaml")
37
+ }
38
+ return entries
39
+ }
40
+ // Include ancestors: a nested project can use the repository's installation.
41
+ for (let directory = project; ; directory = path.dirname(directory)) {
42
+ inspect(directory, directory === project || directory === root)
43
+ if (directory === root) break
44
+ }
45
+ let visited = 0
46
+ const walk = (directory) => {
47
+ if (++visited > 10_000) throw Error("Cache discovery directory limit exceeded")
48
+ for (const entry of inspect(directory)) {
49
+ if (entry.isDirectory() && ![".git", "node_modules", ".effect-ci", ".turbo", ".wrangler", "dist"].includes(entry.name)) {
50
+ walk(path.join(directory, entry.name))
51
+ }
52
+ }
53
+ }
54
+ walk(project)
55
+ console.log(JSON.stringify([...paths].sort()))
56
+ `;
57
+ function taskCachePaths(repository, projectRoot = ".") {
58
+ const { execFileSync } = process.getBuiltinModule("node:child_process");
59
+ return JSON.parse(execFileSync(process.execPath, ["-e", taskCacheProgram, repository, projectRoot], { encoding: "utf8" }));
60
+ }
61
+ export {
62
+ taskCachePaths,
63
+ taskCacheProgram
64
+ };
@@ -0,0 +1,24 @@
1
+ /** Diagnostic data only: never an executable command, reuse proof or authority. */
2
+ export interface CommandDiagnostics {
3
+ readonly version: 1;
4
+ readonly stepId: string;
5
+ readonly command: string;
6
+ readonly cwd: string;
7
+ readonly exitCode: number;
8
+ readonly output: {
9
+ readonly stdout: string;
10
+ readonly stderr: string;
11
+ readonly truncated: boolean;
12
+ };
13
+ }
14
+ export declare const commandDiagnosticLimit = 32768;
15
+ export declare const boundedCommandOutput: (stdout: string, stderr: string) => {
16
+ stdout: string;
17
+ stderr: string;
18
+ truncated: boolean;
19
+ };
20
+ /** Native checkpoints retain error messages but may drop custom Error fields.
21
+ * The checkpoint still THROWS; failure is never cached as a successful result.
22
+ */
23
+ export declare function encodeCommandDiagnostics(value: CommandDiagnostics): string | undefined;
24
+ export declare function decodeCommandDiagnostics(message: unknown, expected?: Partial<Pick<CommandDiagnostics, "stepId" | "command" | "cwd">>): CommandDiagnostics | undefined;
@@ -0,0 +1,25 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { type Workspace, type WorkspaceChangeProvider } from "./index.js";
3
+ export interface DirectoryDeploymentReceipt {
4
+ readonly version: 1;
5
+ readonly id: string;
6
+ readonly digest: string;
7
+ }
8
+ /** Local filesystem destination. The default comparison scope is supplied by
9
+ * this host adapter, never inferred from a build/snapshot ID. Not a remote
10
+ * deployment adapter, signed attestation or generic external retry protocol.
11
+ */
12
+ export declare function directoryDeployment(options: {
13
+ readonly directory: string;
14
+ readonly paths: ReadonlyArray<string>;
15
+ /** Non-secret serving/runtime policy identity; a policy change requires publish. */
16
+ readonly configuration?: string;
17
+ }): {
18
+ changes: WorkspaceChangeProvider;
19
+ publish: (workspace: Workspace) => Effect.Effect<DirectoryDeploymentReceipt | undefined, unknown, {
20
+ readonly Service: import("./index.js").RuntimeShape;
21
+ readonly "~effect/Context/Service": typeof import("effect/Context").ServiceTypeId;
22
+ readonly key: "@effect-ci-testbed/Runtime";
23
+ }>;
24
+ read: (path: string) => Effect.Effect<Buffer<ArrayBufferLike> | undefined, unknown, never>;
25
+ };