@scarn/sdk 0.8.17 → 0.8.19
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/dist/{chunk-g2mzg278.js → chunk-0c60x3v8.js} +51 -59
- package/dist/{chunk-dhqeg0wf.js → chunk-2tmrw253.js} +1 -1
- package/dist/{chunk-r03knh9j.js → chunk-3zp2qtf8.js} +80 -1
- package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
- package/dist/{chunk-a04phj60.js → chunk-833ef6dg.js} +121 -260
- package/dist/{chunk-2ekz6tr5.js → chunk-aemxz9r7.js} +18 -2
- package/dist/chunk-e0pt5x0e.js +167 -0
- package/dist/chunk-mmy80pec.js +64 -0
- package/dist/chunk-mzj1j0p5.js +116 -0
- package/dist/{chunk-cdj0yqgs.js → chunk-pqtd0hr7.js} +12 -2
- package/dist/chunk-qgkx89eg.js +210 -0
- package/dist/chunk-rphfy0fj.js +167 -0
- package/dist/chunk-t1dq2c2s.js +224 -0
- package/dist/{chunk-qs7p11rp.js → chunk-tvjcfh6s.js} +5 -1
- package/dist/{chunk-1wnv6rb2.js → chunk-ymywp5ht.js} +1 -1
- package/dist/client.js +8 -2
- package/dist/connectors/catalog.d.ts +49 -0
- package/dist/connectors/index.d.ts +45 -0
- package/dist/connectors/index.js +41 -0
- package/dist/defaults/index.js +2 -2
- package/dist/definitions/automations/index.js +2 -2
- package/dist/definitions/environments/define-environment.d.ts +39 -0
- package/dist/definitions/environments/environments-client.d.ts +50 -0
- package/dist/definitions/environments/index.d.ts +6 -0
- package/dist/definitions/environments/index.js +97 -0
- package/dist/definitions/pipelines/index.js +2 -2
- package/dist/definitions/steps/compile-mcps.d.ts +8 -12
- package/dist/definitions/steps/define-code-step.d.ts +18 -11
- package/dist/definitions/steps/define-step.d.ts +14 -25
- package/dist/definitions/steps/env.d.ts +30 -8
- package/dist/definitions/steps/index.js +30 -13
- package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
- package/dist/definitions/steps/repo.d.ts +56 -28
- package/dist/definitions/steps/runtime.d.ts +54 -39
- package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
- package/dist/definitions/steps/step-handle.d.ts +8 -1
- package/dist/definitions/validation/index.js +6 -3
- package/dist/definitions/validation/validate-repo.d.ts +3 -7
- package/dist/definitions/validation/validate-runtime.d.ts +2 -7
- package/dist/env-vars.d.ts +57 -1
- package/dist/env-vars.js +7 -1
- package/dist/environment.d.ts +564 -0
- package/dist/environment.js +46 -0
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +27 -2
- package/dist/generated/types.gen.d.ts +2141 -187
- package/dist/index.d.ts +2 -0
- package/dist/index.js +94 -28
- package/dist/opencode-mcp.d.ts +75 -4
- package/dist/opencode-mcp.js +2 -1
- package/dist/push/code-step-lookup.d.ts +6 -0
- package/dist/push/code-step-lookup.js +3 -1
- package/dist/push/collect-definitions.d.ts +13 -0
- package/dist/push/index.js +127 -15
- package/dist/push/push-from-directory.d.ts +11 -2
- package/dist/repo-config.d.ts +88 -30
- package/dist/repo-config.js +21 -5
- package/dist/resolve-environment.d.ts +19 -0
- package/dist/resolve-environment.js +19 -0
- package/dist/task-plane-client.d.ts +132 -22
- package/package.json +17 -1
- package/dist/chunk-2sk92cnd.js +0 -103
package/dist/push/index.js
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "../chunk-
|
|
3
|
+
EnvironmentsApiError,
|
|
4
|
+
createEnvironmentsClient
|
|
5
|
+
} from "../chunk-mmy80pec.js";
|
|
6
6
|
import {
|
|
7
7
|
AutomationsApiError,
|
|
8
8
|
createAutomationsClient
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-2tmrw253.js";
|
|
10
10
|
import {
|
|
11
11
|
assertValidDefinitionSpecs
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-0c60x3v8.js";
|
|
13
13
|
import {
|
|
14
14
|
PipelineDefinitionsApiError,
|
|
15
15
|
createPipelineDefinitionsClient
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-ymywp5ht.js";
|
|
17
17
|
import {
|
|
18
18
|
createStepDefinitionsClient,
|
|
19
|
+
stepEnvironmentHandle,
|
|
19
20
|
toStepSpec
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import"../chunk-cdj0yqgs.js";
|
|
21
|
+
} from "../chunk-833ef6dg.js";
|
|
22
22
|
import"../chunk-y34zsgsw.js";
|
|
23
|
+
import"../chunk-t1dq2c2s.js";
|
|
24
|
+
import {
|
|
25
|
+
isEnvironmentHandle,
|
|
26
|
+
isStepDefinitionSpec,
|
|
27
|
+
stepsInModule
|
|
28
|
+
} from "../chunk-6tra3gw8.js";
|
|
23
29
|
import"../chunk-jj9pezwb.js";
|
|
24
30
|
import"../chunk-y11p1q7r.js";
|
|
25
|
-
import"../chunk-
|
|
31
|
+
import"../chunk-rphfy0fj.js";
|
|
32
|
+
import"../chunk-e0pt5x0e.js";
|
|
26
33
|
import"../chunk-098740f7.js";
|
|
27
34
|
import"../chunk-46wmsgv7.js";
|
|
28
|
-
import"../chunk-
|
|
29
|
-
import"../chunk-
|
|
35
|
+
import"../chunk-qgkx89eg.js";
|
|
36
|
+
import"../chunk-pqtd0hr7.js";
|
|
37
|
+
import"../chunk-aemxz9r7.js";
|
|
38
|
+
import"../chunk-3zp2qtf8.js";
|
|
30
39
|
import"../chunk-ngy1fdcx.js";
|
|
31
40
|
import"../chunk-19brnwkp.js";
|
|
32
41
|
import"../chunk-01nfqm18.js";
|
|
@@ -39,6 +48,7 @@ import"../chunk-y64skrwp.js";
|
|
|
39
48
|
import { readdirSync } from "fs";
|
|
40
49
|
import { join, relative, resolve } from "path";
|
|
41
50
|
import { pathToFileURL } from "url";
|
|
51
|
+
import { isDeepStrictEqual } from "util";
|
|
42
52
|
var INTERNAL_SCRIPT_NAMES = new Set([
|
|
43
53
|
"push.ts",
|
|
44
54
|
"push.mjs",
|
|
@@ -48,7 +58,38 @@ var INTERNAL_SCRIPT_NAMES = new Set([
|
|
|
48
58
|
]);
|
|
49
59
|
var PIPELINE_BUILDER_DIR = ".scarn/pipeline-builder";
|
|
50
60
|
function createCollectionState() {
|
|
51
|
-
return { stepMap: new Map, codeSteps: new Map };
|
|
61
|
+
return { stepMap: new Map, codeSteps: new Map, environments: new Map };
|
|
62
|
+
}
|
|
63
|
+
function environmentHandlesInModule(mod) {
|
|
64
|
+
const found = new Map;
|
|
65
|
+
for (const [exportName, value] of Object.entries(mod)) {
|
|
66
|
+
if (exportName !== "default" && isEnvironmentHandle(value)) {
|
|
67
|
+
found.set(value, true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const step of stepsInModule(mod)) {
|
|
71
|
+
const handle = stepEnvironmentHandle(step);
|
|
72
|
+
if (handle && !found.has(handle))
|
|
73
|
+
found.set(handle, false);
|
|
74
|
+
}
|
|
75
|
+
return [...found].map(([handle, exported]) => ({ handle, exported }));
|
|
76
|
+
}
|
|
77
|
+
function environmentEntriesForFile(state, found, sourceFile) {
|
|
78
|
+
const entries = new Map;
|
|
79
|
+
for (const { handle, exported } of found) {
|
|
80
|
+
const existing = entries.get(handle.name) ?? state.environments.get(handle.name);
|
|
81
|
+
if (existing === undefined) {
|
|
82
|
+
entries.set(handle.name, { handle, sourceFile, exported });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (existing.handle !== handle && !isDeepStrictEqual(existing.handle.content, handle.content)) {
|
|
86
|
+
throw new Error(`Environment "${handle.name}" is defined twice with different content ` + `(${existing.sourceFile} and ${sourceFile}). ` + `Give each environment a unique name, or define it once and import it.`);
|
|
87
|
+
}
|
|
88
|
+
if (exported && !existing.exported) {
|
|
89
|
+
entries.set(handle.name, { handle, sourceFile, exported });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...entries.values()];
|
|
52
93
|
}
|
|
53
94
|
function registerCodeStep(state, spec, sourceFile) {
|
|
54
95
|
const fn = spec.entrypoint?.fn;
|
|
@@ -91,9 +132,13 @@ function fileNameWithoutExtension(file) {
|
|
|
91
132
|
}
|
|
92
133
|
async function collectFile(absoluteFilePath, absDir, state) {
|
|
93
134
|
const mod = await importModule(absoluteFilePath);
|
|
135
|
+
const environmentEntries = environmentEntriesForFile(state, environmentHandlesInModule(mod), relative(absDir, absoluteFilePath));
|
|
94
136
|
for (const step of stepsInModule(mod)) {
|
|
95
137
|
registerCodeStep(state, step, absoluteFilePath);
|
|
96
138
|
}
|
|
139
|
+
for (const entry of environmentEntries) {
|
|
140
|
+
state.environments.set(entry.handle.name, entry);
|
|
141
|
+
}
|
|
97
142
|
for (const [exportName, value] of Object.entries(mod)) {
|
|
98
143
|
if (exportName === "default" || !isStepDefinitionSpec(value))
|
|
99
144
|
continue;
|
|
@@ -101,6 +146,13 @@ async function collectFile(absoluteFilePath, absDir, state) {
|
|
|
101
146
|
state.stepMap.set(`${resolved.key}@v${String(resolved.version)}`, resolved);
|
|
102
147
|
}
|
|
103
148
|
}
|
|
149
|
+
function collectedEnvironments(state) {
|
|
150
|
+
return [...state.environments.values()].map(({ handle, sourceFile }) => ({
|
|
151
|
+
name: handle.name,
|
|
152
|
+
content: handle.content,
|
|
153
|
+
sourceFile
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
104
156
|
async function collectDefinitionsFromDirectory(dir) {
|
|
105
157
|
const absDir = resolve(dir);
|
|
106
158
|
const sourceFiles = listSourceFiles(absDir);
|
|
@@ -108,7 +160,10 @@ async function collectDefinitionsFromDirectory(dir) {
|
|
|
108
160
|
for (const file of sourceFiles) {
|
|
109
161
|
await collectFile(join(absDir, file), absDir, state);
|
|
110
162
|
}
|
|
111
|
-
return {
|
|
163
|
+
return {
|
|
164
|
+
steps: [...state.stepMap.values()],
|
|
165
|
+
environments: collectedEnvironments(state)
|
|
166
|
+
};
|
|
112
167
|
}
|
|
113
168
|
async function collectDefinitionsFromDirectoryTolerant(dir) {
|
|
114
169
|
const absDir = resolve(dir);
|
|
@@ -127,6 +182,7 @@ async function collectDefinitionsFromDirectoryTolerant(dir) {
|
|
|
127
182
|
}
|
|
128
183
|
return {
|
|
129
184
|
steps: [...state.stepMap.values()],
|
|
185
|
+
environments: collectedEnvironments(state),
|
|
130
186
|
brokenPipelines
|
|
131
187
|
};
|
|
132
188
|
}
|
|
@@ -206,12 +262,20 @@ async function pushFromDirectory(dir, opts) {
|
|
|
206
262
|
console.warn(msg);
|
|
207
263
|
});
|
|
208
264
|
const headers = { Authorization: `Bearer ${opts.accessToken}` };
|
|
209
|
-
const { steps } = await collectDefinitionsFromDirectory(dir);
|
|
265
|
+
const { steps, environments } = await collectDefinitionsFromDirectory(dir);
|
|
210
266
|
const built = collectBuiltDocuments(dir);
|
|
211
267
|
const documents = built.filter((file) => file.kind === "pipeline");
|
|
212
268
|
const automations = built.filter((file) => file.kind === "automation").sort((a, b) => Number(a.document["scope"] === "project") - Number(b.document["scope"] === "project"));
|
|
213
|
-
log(`Found ${String(steps.length)} step(s), ${String(documents.length)} pipeline document(s) and ${String(automations.length)} automation document(s).`);
|
|
269
|
+
log(`Found ${String(environments.length)} environment(s), ${String(steps.length)} step(s), ${String(documents.length)} pipeline document(s) and ${String(automations.length)} automation document(s).`);
|
|
214
270
|
assertValidDefinitionSpecs(steps);
|
|
271
|
+
const environmentsClient = createEnvironmentsClient(opts.baseUrl);
|
|
272
|
+
await assertNamedEnvironmentsExist(steps, environments, opts.projectId, headers, environmentsClient);
|
|
273
|
+
const publishedEnvironments = [];
|
|
274
|
+
const unchangedEnvironments = [];
|
|
275
|
+
for (const environment of environments) {
|
|
276
|
+
const published = await publishEnvironment(environment, opts.projectId, headers, environmentsClient, log);
|
|
277
|
+
(published ? publishedEnvironments : unchangedEnvironments).push(environment.name);
|
|
278
|
+
}
|
|
215
279
|
const stepsClient = createStepDefinitionsClient(opts.baseUrl);
|
|
216
280
|
for (const spec of steps) {
|
|
217
281
|
await stepsClient.upsertFromSpec(opts.projectId, spec, { headers });
|
|
@@ -236,6 +300,8 @@ async function pushFromDirectory(dir, opts) {
|
|
|
236
300
|
(published ? publishedAutomations : unchangedAutomations).push(document.key);
|
|
237
301
|
}
|
|
238
302
|
return {
|
|
303
|
+
publishedEnvironments,
|
|
304
|
+
unchangedEnvironments,
|
|
239
305
|
pushedSteps: steps.length,
|
|
240
306
|
publishedPipelines,
|
|
241
307
|
unchangedPipelines,
|
|
@@ -243,6 +309,52 @@ async function pushFromDirectory(dir, opts) {
|
|
|
243
309
|
unchangedAutomations
|
|
244
310
|
};
|
|
245
311
|
}
|
|
312
|
+
async function assertNamedEnvironmentsExist(steps, environments, projectId, headers, environmentsClient) {
|
|
313
|
+
const local = new Set(environments.map((environment) => environment.name));
|
|
314
|
+
const stepsByMissingName = new Map;
|
|
315
|
+
for (const step of steps) {
|
|
316
|
+
if (step.environment?.kind !== "named")
|
|
317
|
+
continue;
|
|
318
|
+
const name = step.environment.name;
|
|
319
|
+
if (local.has(name))
|
|
320
|
+
continue;
|
|
321
|
+
stepsByMissingName.set(name, [
|
|
322
|
+
...stepsByMissingName.get(name) ?? [],
|
|
323
|
+
step.key
|
|
324
|
+
]);
|
|
325
|
+
}
|
|
326
|
+
if (stepsByMissingName.size === 0)
|
|
327
|
+
return;
|
|
328
|
+
const onServer = new Set((await environmentsClient.listByProjectId(projectId, { headers })).map((environment) => environment.name));
|
|
329
|
+
const unknown = [...stepsByMissingName].filter(([name]) => !onServer.has(name));
|
|
330
|
+
if (unknown.length === 0)
|
|
331
|
+
return;
|
|
332
|
+
throw new Error([
|
|
333
|
+
"Steps name environments that aren't defined locally or on the server:",
|
|
334
|
+
...unknown.map(([name, keys]) => ` "${name}" (used by ${[...new Set(keys)].join(", ")})`),
|
|
335
|
+
"Define them with defineEnvironment in the pipeline-builder directory, then push again. Nothing was uploaded."
|
|
336
|
+
].join(`
|
|
337
|
+
`));
|
|
338
|
+
}
|
|
339
|
+
async function publishEnvironment({ name, content, sourceFile }, projectId, headers, environmentsClient, log) {
|
|
340
|
+
try {
|
|
341
|
+
const result = await environmentsClient.publish(projectId, name, content, {
|
|
342
|
+
headers
|
|
343
|
+
});
|
|
344
|
+
const version = String(result.version.version);
|
|
345
|
+
log(result.published ? `\u2713 environment ${name} v${version} \u2192 published (${sourceFile})` : `\u2713 environment ${name} v${version} \u2192 unchanged (${sourceFile})`);
|
|
346
|
+
return result.published;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
if (!(error instanceof EnvironmentsApiError))
|
|
349
|
+
throw error;
|
|
350
|
+
const issues = error.issues.map((issue) => ` ${issue.path || "/"}: ${issue.message}`);
|
|
351
|
+
throw new Error([
|
|
352
|
+
`Could not publish environment "${name}" (${sourceFile}): ${error.message}`,
|
|
353
|
+
...issues
|
|
354
|
+
].join(`
|
|
355
|
+
`), { cause: error });
|
|
356
|
+
}
|
|
357
|
+
}
|
|
246
358
|
async function publishPipelineDocument({ file, key, title, document }, pipelineDefinitionId, projectId, headers, pipelinesClient, log) {
|
|
247
359
|
try {
|
|
248
360
|
if (pipelineDefinitionId === undefined) {
|
|
@@ -6,6 +6,10 @@ export interface PushFromDirectoryOptions {
|
|
|
6
6
|
log?: (message: string) => void;
|
|
7
7
|
}
|
|
8
8
|
export interface PushFromDirectoryResult {
|
|
9
|
+
/** Names of the environments that got a new version. */
|
|
10
|
+
publishedEnvironments: string[];
|
|
11
|
+
/** Names of the environments whose content matched their latest version. */
|
|
12
|
+
unchangedEnvironments: string[];
|
|
9
13
|
pushedSteps: number;
|
|
10
14
|
/** Keys of the pipelines that got a new active version. */
|
|
11
15
|
publishedPipelines: string[];
|
|
@@ -17,10 +21,15 @@ export interface PushFromDirectoryResult {
|
|
|
17
21
|
unchangedAutomations: string[];
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
|
-
* Pushes a pipeline-builder directory to the server, in
|
|
24
|
+
* Pushes a pipeline-builder directory to the server, in four passes:
|
|
21
25
|
*
|
|
26
|
+
* 0. Publishes every environment collected from the `.ts`/`.js` files: each
|
|
27
|
+
* exported `defineEnvironment` handle and each handle a collected step
|
|
28
|
+
* uses. Content matching the latest version publishes nothing.
|
|
22
29
|
* 1. Upserts every step exported from the `.ts`/`.js` files (except the push
|
|
23
|
-
* script itself).
|
|
30
|
+
* script itself). A step naming an environment by string that isn't
|
|
31
|
+
* collected must already exist on the server; that's checked with one
|
|
32
|
+
* list call before anything is uploaded.
|
|
24
33
|
* 2. Publishes every built pipeline document (`<key>.json`, from
|
|
25
34
|
* `scarn pipelines build`), creating the pipeline when its key is new.
|
|
26
35
|
* The server pins each document to the steps just pushed; a document
|
package/dist/repo-config.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { z } from "zod";
|
|
|
3
3
|
* Wire schema for a step's repository access (`repo`): what the worker does
|
|
4
4
|
* with the clone.
|
|
5
5
|
*
|
|
6
|
-
* - `none`: no repository. The worker does not clone, branch, commit or push.
|
|
7
6
|
* - `readOnly`: clones and checks out the base branch, but creates no work
|
|
8
7
|
* branch, commits nothing and pushes nothing.
|
|
9
8
|
* - `readWrite`: creates a work branch, commits and pushes. `message` is the
|
|
@@ -13,7 +12,11 @@ import { z } from "zod";
|
|
|
13
12
|
*
|
|
14
13
|
* `readOnly` and `readWrite` also carry `gitCredentials` (`"auto"` or
|
|
15
14
|
* `"none"`): whether git inside the container gets credentials through the
|
|
16
|
-
* worker's credential relay when the worker offers one
|
|
15
|
+
* worker's credential relay when the worker offers one; `baseBranch`, a branch
|
|
16
|
+
* template (`{{input.…}}`, `{{env.NAME}}` and `{{workItem.platformKey}}`
|
|
17
|
+
* tokens only) the worker renders, which beats the previous step's work
|
|
18
|
+
* branch when set. `readWrite` also carries
|
|
19
|
+
* `workBranch`: a new branch, or the branch the step started from.
|
|
17
20
|
*
|
|
18
21
|
* Two shapes of the same data. `RepoConfigInput` is what an author or API client
|
|
19
22
|
* sends and may leave things out; `RepoConfig` is what is stored, returned and
|
|
@@ -21,8 +24,7 @@ import { z } from "zod";
|
|
|
21
24
|
* `RepoConfig` is also a valid `RepoConfigInput`, so a client can send back what
|
|
22
25
|
* it read (hence a `null` message is accepted on input).
|
|
23
26
|
*
|
|
24
|
-
*
|
|
25
|
-
* a row there instead of changing the schema.
|
|
27
|
+
* Every runtime accepts both repository modes.
|
|
26
28
|
*/
|
|
27
29
|
export declare const MAX_REPO_COMMIT_MESSAGE_LENGTH = 500;
|
|
28
30
|
export declare const REPO_COMMIT_MESSAGE_TOKEN_ROOTS: readonly string[];
|
|
@@ -33,17 +35,77 @@ export declare const REPO_COMMIT_MESSAGE_TOKEN_ROOTS: readonly string[];
|
|
|
33
35
|
export declare const REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS: readonly string[];
|
|
34
36
|
/** Whether `message` has a `{{workItem.…}}` token. */
|
|
35
37
|
export declare function commitMessageUsesWorkItem(message: string): boolean;
|
|
36
|
-
export type RepoMode = "
|
|
38
|
+
export type RepoMode = "readOnly" | "readWrite";
|
|
37
39
|
export type RepoOnPushFailure = "fail" | "warn";
|
|
38
|
-
export type RepoExecutionMode = "workspace" | "no_workspace";
|
|
39
40
|
/**
|
|
40
41
|
* Every `{{…}}` token in `message` a commit message may not use, in order of
|
|
41
42
|
* appearance: its root when that is not one of
|
|
42
43
|
* `REPO_COMMIT_MESSAGE_TOKEN_ROOTS`, or the whole path for a `workItem` token
|
|
43
|
-
* other than `REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS`.
|
|
44
|
-
* `renderPromptTemplate` renders them.
|
|
44
|
+
* other than `REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS`.
|
|
45
45
|
*/
|
|
46
46
|
export declare function findDisallowedCommitMessageTokenRoots(message: string): string[];
|
|
47
|
+
export declare const MAX_REPO_BASE_BRANCH_LENGTH = 255;
|
|
48
|
+
/**
|
|
49
|
+
* The token roots a `baseBranch` template may use. No `result`: there is no
|
|
50
|
+
* result before the step runs. `{{env.X}}` names one variable of the step's
|
|
51
|
+
* environment.
|
|
52
|
+
*/
|
|
53
|
+
export declare const REPO_BASE_BRANCH_TOKEN_ROOTS: readonly string[];
|
|
54
|
+
/** The only `{{workItem.…}}` path a `baseBranch` may use. */
|
|
55
|
+
export declare const REPO_BASE_BRANCH_WORK_ITEM_KEYS: readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* Every `{{…}}` token in `baseBranch` a base branch template may not use, as
|
|
58
|
+
* `findDisallowedCommitMessageTokenRoots` reports them. An `env` token must
|
|
59
|
+
* name exactly one variable.
|
|
60
|
+
*/
|
|
61
|
+
export declare function findDisallowedBaseBranchTokens(baseBranch: string): string[];
|
|
62
|
+
/** Why a `{{env.X}}` token in a `baseBranch` doesn't fit the environment. */
|
|
63
|
+
export type BaseBranchEnvProblemReason = "undeclared" | "secret";
|
|
64
|
+
export type BaseBranchEnvProblem = {
|
|
65
|
+
/** The whole token path, e.g. `env.TICKET`. */
|
|
66
|
+
token: string;
|
|
67
|
+
reason: BaseBranchEnvProblemReason;
|
|
68
|
+
};
|
|
69
|
+
/** The parts of an env var the base branch check reads (stored or write shape). */
|
|
70
|
+
export type BaseBranchEnvVar = {
|
|
71
|
+
name: string;
|
|
72
|
+
source: "value" | "inherit";
|
|
73
|
+
secret: boolean;
|
|
74
|
+
} | {
|
|
75
|
+
name: string;
|
|
76
|
+
source: "secret";
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Every `{{env.X}}` token in `baseBranch` that `vars` don't allow, in order
|
|
80
|
+
* of appearance: `X` is not declared, or it is an `Env.secret` or a secret
|
|
81
|
+
* `Env.inherit` (branch names end up in logs, git and the UI).
|
|
82
|
+
*/
|
|
83
|
+
export declare function findBaseBranchEnvProblems(baseBranch: string, vars: readonly BaseBranchEnvVar[]): BaseBranchEnvProblem[];
|
|
84
|
+
/** One line per problem, e.g. `{{env.TOKEN}} names a secret var`. */
|
|
85
|
+
export declare function describeBaseBranchEnvProblem({ token, reason, }: BaseBranchEnvProblem): string;
|
|
86
|
+
/**
|
|
87
|
+
* Whether `name` is a valid branch name by `git check-ref-format --branch`'s
|
|
88
|
+
* rules.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isValidGitBranchName(name: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether `template`'s literal text can be part of a valid branch name: each
|
|
93
|
+
* token is stood in for by a plain segment, so a token-free template must be
|
|
94
|
+
* a valid branch name itself. The rendered name is checked again by the
|
|
95
|
+
* worker.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isValidBaseBranchTemplate(template: string): boolean;
|
|
98
|
+
export declare const repoBaseBranchSchema: z.ZodString;
|
|
99
|
+
/**
|
|
100
|
+
* Which branch a `readWrite` step commits to. `create`: a new
|
|
101
|
+
* `scarn/<key>-<id>` branch. `base`: the branch the step started from.
|
|
102
|
+
*/
|
|
103
|
+
export declare const repoWorkBranchSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
104
|
+
kind: z.ZodLiteral<"create">;
|
|
105
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
106
|
+
kind: z.ZodLiteral<"base">;
|
|
107
|
+
}, z.core.$strict>], "kind">;
|
|
108
|
+
export type RepoWorkBranch = z.output<typeof repoWorkBranchSchema>;
|
|
47
109
|
export declare const repoCommitMessageSchema: z.ZodString;
|
|
48
110
|
/**
|
|
49
111
|
* Whether git inside the step's container gets credentials through the
|
|
@@ -60,13 +122,12 @@ export declare const repoGitCredentialsSchema: z.ZodEnum<{
|
|
|
60
122
|
}>;
|
|
61
123
|
export type RepoGitCredentials = z.output<typeof repoGitCredentialsSchema>;
|
|
62
124
|
export declare const repoConfigInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
|
-
mode: z.ZodLiteral<"none">;
|
|
64
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
65
125
|
mode: z.ZodLiteral<"readOnly">;
|
|
66
126
|
gitCredentials: z.ZodOptional<z.ZodEnum<{
|
|
67
127
|
auto: "auto";
|
|
68
128
|
none: "none";
|
|
69
129
|
}>>;
|
|
130
|
+
baseBranch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
70
131
|
}, z.core.$strict>, z.ZodObject<{
|
|
71
132
|
mode: z.ZodLiteral<"readWrite">;
|
|
72
133
|
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -78,15 +139,20 @@ export declare const repoConfigInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
78
139
|
auto: "auto";
|
|
79
140
|
none: "none";
|
|
80
141
|
}>>;
|
|
142
|
+
baseBranch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
143
|
+
workBranch: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
144
|
+
kind: z.ZodLiteral<"create">;
|
|
145
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
146
|
+
kind: z.ZodLiteral<"base">;
|
|
147
|
+
}, z.core.$strict>], "kind">>;
|
|
81
148
|
}, z.core.$strict>], "mode">;
|
|
82
149
|
export declare const repoConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
83
|
-
mode: z.ZodLiteral<"none">;
|
|
84
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
85
150
|
mode: z.ZodLiteral<"readOnly">;
|
|
86
151
|
gitCredentials: z.ZodEnum<{
|
|
87
152
|
auto: "auto";
|
|
88
153
|
none: "none";
|
|
89
154
|
}>;
|
|
155
|
+
baseBranch: z.ZodNullable<z.ZodString>;
|
|
90
156
|
}, z.core.$strict>, z.ZodObject<{
|
|
91
157
|
mode: z.ZodLiteral<"readWrite">;
|
|
92
158
|
message: z.ZodNullable<z.ZodString>;
|
|
@@ -98,28 +164,20 @@ export declare const repoConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
98
164
|
auto: "auto";
|
|
99
165
|
none: "none";
|
|
100
166
|
}>;
|
|
167
|
+
baseBranch: z.ZodNullable<z.ZodString>;
|
|
168
|
+
workBranch: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
169
|
+
kind: z.ZodLiteral<"create">;
|
|
170
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
171
|
+
kind: z.ZodLiteral<"base">;
|
|
172
|
+
}, z.core.$strict>], "kind">;
|
|
101
173
|
}, z.core.$strict>], "mode">;
|
|
102
174
|
export type RepoConfigInput = z.input<typeof repoConfigInputSchema>;
|
|
103
175
|
export type RepoConfig = z.output<typeof repoConfigSchema>;
|
|
104
|
-
type RepoRuntimeSupport = {
|
|
105
|
-
readonly modes: readonly RepoMode[];
|
|
106
|
-
readonly default: RepoMode;
|
|
107
|
-
/** Why the modes outside `modes` are rejected. */
|
|
108
|
-
readonly unsupportedBecause: string;
|
|
109
|
-
};
|
|
110
|
-
/** Which `repo` modes each execution mode accepts, and its default. */
|
|
111
|
-
export declare const REPO_RUNTIME_SUPPORT: Record<RepoExecutionMode, RepoRuntimeSupport>;
|
|
112
|
-
/**
|
|
113
|
-
* Why `mode` cannot be used with `executionMode`, or `null` when the pair is
|
|
114
|
-
* valid.
|
|
115
|
-
*/
|
|
116
|
-
export declare function repoRuntimeMismatch(executionMode: RepoExecutionMode, mode: RepoMode): string | null;
|
|
117
176
|
/**
|
|
118
177
|
* Fills what an author left out: an omitted `repo` becomes the runtime's default
|
|
119
|
-
* (`readWrite` for
|
|
178
|
+
* (`readWrite` for every runtime), an omitted
|
|
120
179
|
* `onPushFailure` becomes `"fail"`, an omitted `message` becomes `null` and an
|
|
121
|
-
* omitted `gitCredentials` becomes `"auto"
|
|
122
|
-
*
|
|
180
|
+
* omitted `gitCredentials` becomes `"auto"`, an omitted `baseBranch` becomes
|
|
181
|
+
* `null` and an omitted `workBranch` becomes `{ kind: "create" }`.
|
|
123
182
|
*/
|
|
124
|
-
export declare function resolveRepoConfig(
|
|
125
|
-
export {};
|
|
183
|
+
export declare function resolveRepoConfig(input?: RepoConfigInput | null): RepoConfig;
|
package/dist/repo-config.js
CHANGED
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
+
MAX_REPO_BASE_BRANCH_LENGTH,
|
|
3
4
|
MAX_REPO_COMMIT_MESSAGE_LENGTH,
|
|
5
|
+
REPO_BASE_BRANCH_TOKEN_ROOTS,
|
|
6
|
+
REPO_BASE_BRANCH_WORK_ITEM_KEYS,
|
|
4
7
|
REPO_COMMIT_MESSAGE_TOKEN_ROOTS,
|
|
5
8
|
REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS,
|
|
6
|
-
REPO_RUNTIME_SUPPORT,
|
|
7
9
|
commitMessageUsesWorkItem,
|
|
10
|
+
describeBaseBranchEnvProblem,
|
|
11
|
+
findBaseBranchEnvProblems,
|
|
12
|
+
findDisallowedBaseBranchTokens,
|
|
8
13
|
findDisallowedCommitMessageTokenRoots,
|
|
14
|
+
isValidBaseBranchTemplate,
|
|
15
|
+
isValidGitBranchName,
|
|
16
|
+
repoBaseBranchSchema,
|
|
9
17
|
repoCommitMessageSchema,
|
|
10
18
|
repoConfigInputSchema,
|
|
11
19
|
repoConfigSchema,
|
|
12
20
|
repoGitCredentialsSchema,
|
|
13
|
-
|
|
21
|
+
repoWorkBranchSchema,
|
|
14
22
|
resolveRepoConfig
|
|
15
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-rphfy0fj.js";
|
|
16
24
|
import"./chunk-yf15kdte.js";
|
|
17
25
|
import"./chunk-y64skrwp.js";
|
|
18
26
|
export {
|
|
27
|
+
MAX_REPO_BASE_BRANCH_LENGTH,
|
|
19
28
|
MAX_REPO_COMMIT_MESSAGE_LENGTH,
|
|
29
|
+
REPO_BASE_BRANCH_TOKEN_ROOTS,
|
|
30
|
+
REPO_BASE_BRANCH_WORK_ITEM_KEYS,
|
|
20
31
|
REPO_COMMIT_MESSAGE_TOKEN_ROOTS,
|
|
21
32
|
REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS,
|
|
22
|
-
REPO_RUNTIME_SUPPORT,
|
|
23
33
|
commitMessageUsesWorkItem,
|
|
34
|
+
describeBaseBranchEnvProblem,
|
|
35
|
+
findBaseBranchEnvProblems,
|
|
36
|
+
findDisallowedBaseBranchTokens,
|
|
24
37
|
findDisallowedCommitMessageTokenRoots,
|
|
38
|
+
isValidBaseBranchTemplate,
|
|
39
|
+
isValidGitBranchName,
|
|
40
|
+
repoBaseBranchSchema,
|
|
25
41
|
repoCommitMessageSchema,
|
|
26
42
|
repoConfigInputSchema,
|
|
27
43
|
repoConfigSchema,
|
|
28
44
|
repoGitCredentialsSchema,
|
|
29
|
-
|
|
45
|
+
repoWorkBranchSchema,
|
|
30
46
|
resolveRepoConfig
|
|
31
47
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EnvironmentError, type EnvironmentRefRead, type ResolvedEnvironment, type ResolvedEnvironmentRefInput } from "./environment";
|
|
2
|
+
export type ResolveEnvironmentDeps = {
|
|
3
|
+
devcontainerExists(path: string): Promise<boolean>;
|
|
4
|
+
};
|
|
5
|
+
export type EnvironmentDefinition = Omit<ResolvedEnvironment, "runtime"> & {
|
|
6
|
+
runtime?: Exclude<EnvironmentRefRead, null | {
|
|
7
|
+
kind: "named";
|
|
8
|
+
}>["runtime"];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Validates a run's environment without inspecting the checked-out runtime
|
|
12
|
+
* files. A named environment's pinned content goes through the same checks
|
|
13
|
+
* as an inline environment.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readEnvironmentDefinition(ref: ResolvedEnvironmentRefInput): EnvironmentDefinition | EnvironmentError;
|
|
16
|
+
/** Resolves a run's environment, inspecting runtime files in the checkout. Dependency I/O failures propagate. */
|
|
17
|
+
export declare function resolveEnvironment(deps: ResolveEnvironmentDeps, ref: ResolvedEnvironmentRefInput): Promise<ResolvedEnvironment | EnvironmentError>;
|
|
18
|
+
/** Resolves runtime files only after the caller has selected the code checkout. */
|
|
19
|
+
export declare function resolveEnvironmentDefinition(deps: Pick<ResolveEnvironmentDeps, "devcontainerExists">, definition: EnvironmentDefinition): Promise<ResolvedEnvironment | EnvironmentError>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
readEnvironmentDefinition,
|
|
4
|
+
resolveEnvironment,
|
|
5
|
+
resolveEnvironmentDefinition
|
|
6
|
+
} from "./chunk-mzj1j0p5.js";
|
|
7
|
+
import"./chunk-e0pt5x0e.js";
|
|
8
|
+
import"./chunk-098740f7.js";
|
|
9
|
+
import"./chunk-46wmsgv7.js";
|
|
10
|
+
import"./chunk-qgkx89eg.js";
|
|
11
|
+
import"./chunk-pqtd0hr7.js";
|
|
12
|
+
import"./chunk-aemxz9r7.js";
|
|
13
|
+
import"./chunk-yf15kdte.js";
|
|
14
|
+
import"./chunk-y64skrwp.js";
|
|
15
|
+
export {
|
|
16
|
+
readEnvironmentDefinition,
|
|
17
|
+
resolveEnvironment,
|
|
18
|
+
resolveEnvironmentDefinition
|
|
19
|
+
};
|