@scarn/sdk 0.8.17 → 0.8.18
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 +26 -1
- package/dist/generated/types.gen.d.ts +2090 -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 +124 -22
- package/package.json +17 -1
- package/dist/chunk-2sk92cnd.js +0 -103
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
exports_external
|
|
4
|
+
} from "./chunk-yf15kdte.js";
|
|
5
|
+
|
|
6
|
+
// src/repo-config.ts
|
|
7
|
+
var MAX_REPO_COMMIT_MESSAGE_LENGTH = 500;
|
|
8
|
+
var REPO_COMMIT_MESSAGE_TOKEN_ROOTS = [
|
|
9
|
+
"input",
|
|
10
|
+
"result",
|
|
11
|
+
"workItem"
|
|
12
|
+
];
|
|
13
|
+
var REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS = [
|
|
14
|
+
"title",
|
|
15
|
+
"platformKey"
|
|
16
|
+
];
|
|
17
|
+
function commitMessageUsesWorkItem(message) {
|
|
18
|
+
for (const match of message.matchAll(TOKEN_PATTERN)) {
|
|
19
|
+
if ((match[1] ?? "").split(".")[0] === "workItem")
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
var TOKEN_PATTERN = /\{\{([^}]+)\}\}/g;
|
|
25
|
+
function findDisallowedTemplateTokens(template, rules) {
|
|
26
|
+
const disallowed = [];
|
|
27
|
+
for (const match of template.matchAll(TOKEN_PATTERN)) {
|
|
28
|
+
const path = match[1] ?? "";
|
|
29
|
+
const [root = "", ...rest] = path.split(".");
|
|
30
|
+
if (!rules.roots.includes(root)) {
|
|
31
|
+
disallowed.push(root);
|
|
32
|
+
} else if (root === "workItem" && (rest.length !== 1 || !rules.workItemKeys.includes(rest[0] ?? ""))) {
|
|
33
|
+
disallowed.push(path);
|
|
34
|
+
} else if (rules.singleSegmentRoots?.includes(root) && (rest.length !== 1 || rest[0] === "")) {
|
|
35
|
+
disallowed.push(path);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return disallowed;
|
|
39
|
+
}
|
|
40
|
+
function findDisallowedCommitMessageTokenRoots(message) {
|
|
41
|
+
return findDisallowedTemplateTokens(message, {
|
|
42
|
+
roots: REPO_COMMIT_MESSAGE_TOKEN_ROOTS,
|
|
43
|
+
workItemKeys: REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var MAX_REPO_BASE_BRANCH_LENGTH = 255;
|
|
47
|
+
var REPO_BASE_BRANCH_TOKEN_ROOTS = [
|
|
48
|
+
"input",
|
|
49
|
+
"env",
|
|
50
|
+
"workItem"
|
|
51
|
+
];
|
|
52
|
+
var REPO_BASE_BRANCH_WORK_ITEM_KEYS = [
|
|
53
|
+
"platformKey"
|
|
54
|
+
];
|
|
55
|
+
function findDisallowedBaseBranchTokens(baseBranch) {
|
|
56
|
+
return findDisallowedTemplateTokens(baseBranch, {
|
|
57
|
+
roots: REPO_BASE_BRANCH_TOKEN_ROOTS,
|
|
58
|
+
workItemKeys: REPO_BASE_BRANCH_WORK_ITEM_KEYS,
|
|
59
|
+
singleSegmentRoots: ["env"]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function findBaseBranchEnvProblems(baseBranch, vars) {
|
|
63
|
+
const problems = [];
|
|
64
|
+
for (const match of baseBranch.matchAll(TOKEN_PATTERN)) {
|
|
65
|
+
const path = (match[1] ?? "").trim();
|
|
66
|
+
const [root, name, ...rest] = path.split(".");
|
|
67
|
+
if (root !== "env" || name === undefined || rest.length > 0)
|
|
68
|
+
continue;
|
|
69
|
+
const entry = vars.find((candidate) => candidate.name === name);
|
|
70
|
+
if (entry === undefined) {
|
|
71
|
+
problems.push({ token: path, reason: "undeclared" });
|
|
72
|
+
} else if (entry.source === "secret" || entry.secret) {
|
|
73
|
+
problems.push({ token: path, reason: "secret" });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return problems;
|
|
77
|
+
}
|
|
78
|
+
function describeBaseBranchEnvProblem({
|
|
79
|
+
token,
|
|
80
|
+
reason
|
|
81
|
+
}) {
|
|
82
|
+
return reason === "secret" ? `{{${token}}} names a secret var; branch names end up in logs, git and the UI` : `{{${token}}} names a var the environment does not declare`;
|
|
83
|
+
}
|
|
84
|
+
function isValidGitBranchName(name) {
|
|
85
|
+
if (name === "" || name === "@")
|
|
86
|
+
return false;
|
|
87
|
+
if (name.startsWith("-") || name.startsWith("/"))
|
|
88
|
+
return false;
|
|
89
|
+
if (name.endsWith("/") || name.endsWith("."))
|
|
90
|
+
return false;
|
|
91
|
+
if (name.includes("..") || name.includes("//") || name.includes("@{")) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (/[\x00-\x20\x7f~^:?*[\\]/.test(name))
|
|
95
|
+
return false;
|
|
96
|
+
return name.split("/").every((component) => !component.startsWith(".") && !component.endsWith(".lock"));
|
|
97
|
+
}
|
|
98
|
+
function isValidBaseBranchTemplate(template) {
|
|
99
|
+
return isValidGitBranchName(template.replace(TOKEN_PATTERN, "x"));
|
|
100
|
+
}
|
|
101
|
+
var repoBaseBranchSchema = exports_external.string().max(MAX_REPO_BASE_BRANCH_LENGTH).refine((baseBranch) => !/[\r\n]/.test(baseBranch), {
|
|
102
|
+
message: "must be a single line"
|
|
103
|
+
}).refine((baseBranch) => findDisallowedBaseBranchTokens(baseBranch).length === 0, {
|
|
104
|
+
message: "may only use {{input.\u2026}}, {{env.NAME}} and {{workItem.platformKey}} tokens"
|
|
105
|
+
}).refine(isValidBaseBranchTemplate, {
|
|
106
|
+
message: "must be a valid branch name (git check-ref-format --branch)"
|
|
107
|
+
});
|
|
108
|
+
var repoWorkBranchSchema = exports_external.discriminatedUnion("kind", [
|
|
109
|
+
exports_external.object({ kind: exports_external.literal("create") }).strict(),
|
|
110
|
+
exports_external.object({ kind: exports_external.literal("base") }).strict()
|
|
111
|
+
]);
|
|
112
|
+
var repoCommitMessageSchema = exports_external.string().max(MAX_REPO_COMMIT_MESSAGE_LENGTH).refine((message) => !/[\r\n]/.test(message), {
|
|
113
|
+
message: "must be a single line"
|
|
114
|
+
}).refine((message) => findDisallowedCommitMessageTokenRoots(message).length === 0, {
|
|
115
|
+
message: `may only use {{input.\u2026}}, {{result.\u2026}}, {{${REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS.map((key) => `workItem.${key}`).join("}} and {{")}}} tokens`
|
|
116
|
+
});
|
|
117
|
+
var onPushFailureSchema = exports_external.enum(["fail", "warn"]);
|
|
118
|
+
var repoGitCredentialsSchema = exports_external.enum(["auto", "none"]);
|
|
119
|
+
var repoConfigInputSchema = exports_external.discriminatedUnion("mode", [
|
|
120
|
+
exports_external.object({
|
|
121
|
+
mode: exports_external.literal("readOnly"),
|
|
122
|
+
gitCredentials: repoGitCredentialsSchema.optional(),
|
|
123
|
+
baseBranch: repoBaseBranchSchema.nullish()
|
|
124
|
+
}).strict(),
|
|
125
|
+
exports_external.object({
|
|
126
|
+
mode: exports_external.literal("readWrite"),
|
|
127
|
+
message: repoCommitMessageSchema.nullish(),
|
|
128
|
+
onPushFailure: onPushFailureSchema.optional(),
|
|
129
|
+
gitCredentials: repoGitCredentialsSchema.optional(),
|
|
130
|
+
baseBranch: repoBaseBranchSchema.nullish(),
|
|
131
|
+
workBranch: repoWorkBranchSchema.optional()
|
|
132
|
+
}).strict()
|
|
133
|
+
]);
|
|
134
|
+
var repoConfigSchema = exports_external.discriminatedUnion("mode", [
|
|
135
|
+
exports_external.object({
|
|
136
|
+
mode: exports_external.literal("readOnly"),
|
|
137
|
+
gitCredentials: repoGitCredentialsSchema,
|
|
138
|
+
baseBranch: repoBaseBranchSchema.nullable()
|
|
139
|
+
}).strict(),
|
|
140
|
+
exports_external.object({
|
|
141
|
+
mode: exports_external.literal("readWrite"),
|
|
142
|
+
message: repoCommitMessageSchema.nullable(),
|
|
143
|
+
onPushFailure: onPushFailureSchema,
|
|
144
|
+
gitCredentials: repoGitCredentialsSchema,
|
|
145
|
+
baseBranch: repoBaseBranchSchema.nullable(),
|
|
146
|
+
workBranch: repoWorkBranchSchema
|
|
147
|
+
}).strict()
|
|
148
|
+
]);
|
|
149
|
+
function resolveRepoConfig(input) {
|
|
150
|
+
const mode = input?.mode ?? "readWrite";
|
|
151
|
+
const gitCredentials = (input && "gitCredentials" in input ? input.gitCredentials : undefined) ?? "auto";
|
|
152
|
+
const baseBranch = input?.baseBranch ?? null;
|
|
153
|
+
if (mode === "readOnly") {
|
|
154
|
+
return { mode, gitCredentials, baseBranch };
|
|
155
|
+
}
|
|
156
|
+
const readWrite = input?.mode === "readWrite" ? input : undefined;
|
|
157
|
+
return {
|
|
158
|
+
mode,
|
|
159
|
+
message: readWrite?.message ?? null,
|
|
160
|
+
onPushFailure: readWrite?.onPushFailure ?? "fail",
|
|
161
|
+
gitCredentials,
|
|
162
|
+
baseBranch,
|
|
163
|
+
workBranch: readWrite?.workBranch ?? { kind: "create" }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { MAX_REPO_COMMIT_MESSAGE_LENGTH, REPO_COMMIT_MESSAGE_TOKEN_ROOTS, REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS, commitMessageUsesWorkItem, findDisallowedCommitMessageTokenRoots, MAX_REPO_BASE_BRANCH_LENGTH, REPO_BASE_BRANCH_TOKEN_ROOTS, REPO_BASE_BRANCH_WORK_ITEM_KEYS, findDisallowedBaseBranchTokens, findBaseBranchEnvProblems, describeBaseBranchEnvProblem, isValidGitBranchName, isValidBaseBranchTemplate, repoBaseBranchSchema, repoWorkBranchSchema, repoCommitMessageSchema, repoGitCredentialsSchema, repoConfigInputSchema, repoConfigSchema, resolveRepoConfig };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
isEnvironmentHandle
|
|
4
|
+
} from "./chunk-6tra3gw8.js";
|
|
5
|
+
import {
|
|
6
|
+
environmentNameSchema
|
|
7
|
+
} from "./chunk-e0pt5x0e.js";
|
|
8
|
+
import {
|
|
9
|
+
devcontainerConfigPathSchema
|
|
10
|
+
} from "./chunk-098740f7.js";
|
|
11
|
+
import {
|
|
12
|
+
MANAGED_RUNTIME_IDS
|
|
13
|
+
} from "./chunk-46wmsgv7.js";
|
|
14
|
+
import {
|
|
15
|
+
connectorIdsSchema
|
|
16
|
+
} from "./chunk-qgkx89eg.js";
|
|
17
|
+
import {
|
|
18
|
+
containsInputToken
|
|
19
|
+
} from "./chunk-aemxz9r7.js";
|
|
20
|
+
|
|
21
|
+
// src/definitions/steps/prompt-template.ts
|
|
22
|
+
function createPromptInputProxy(path = []) {
|
|
23
|
+
const token = () => path.length ? `{{${path.join(".")}}}` : "";
|
|
24
|
+
return new Proxy(Object.freeze({}), {
|
|
25
|
+
get(_, key) {
|
|
26
|
+
if (key === Symbol.toPrimitive || key === "valueOf") {
|
|
27
|
+
return (_hint) => token();
|
|
28
|
+
}
|
|
29
|
+
if (key === "toString") {
|
|
30
|
+
return () => token();
|
|
31
|
+
}
|
|
32
|
+
if (typeof key !== "string")
|
|
33
|
+
return;
|
|
34
|
+
return createPromptInputProxy([...path, key]);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function createPromptTemplateContext() {
|
|
39
|
+
return {
|
|
40
|
+
input: createPromptInputProxy(["input"]),
|
|
41
|
+
env: createPromptInputProxy(["env"]),
|
|
42
|
+
scarn: {
|
|
43
|
+
artifactsDir: createPromptInputProxy([
|
|
44
|
+
"scarn",
|
|
45
|
+
"artifactsDir"
|
|
46
|
+
])
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function renderPromptTemplate(template, contextJson) {
|
|
51
|
+
return template.replace(/\{\{([^}]+)\}\}/g, (_, path) => {
|
|
52
|
+
const value = path.split(".").reduce((curr, key) => curr != null ? curr[key] : undefined, contextJson);
|
|
53
|
+
return value != null ? String(value) : "";
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/definitions/steps/env.ts
|
|
58
|
+
var SECRET_LOOKING_NAME = /SECRET|TOKEN|PASSWORD|PASSWD|API_?KEY|PRIVATE/i;
|
|
59
|
+
function isSecretLookingEnvName(name) {
|
|
60
|
+
return SECRET_LOOKING_NAME.test(name);
|
|
61
|
+
}
|
|
62
|
+
var helperEntries = new WeakSet;
|
|
63
|
+
function brand(entry) {
|
|
64
|
+
helperEntries.add(entry);
|
|
65
|
+
return entry;
|
|
66
|
+
}
|
|
67
|
+
var Env = {
|
|
68
|
+
value(opts) {
|
|
69
|
+
return brand({
|
|
70
|
+
kind: "value",
|
|
71
|
+
value: opts.value,
|
|
72
|
+
secret: opts.secret ?? false,
|
|
73
|
+
unsafeAllowStatic: opts.unsafeAllowStatic ?? false,
|
|
74
|
+
applies: opts.applies ?? "agent"
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
inherit(opts) {
|
|
78
|
+
return brand({
|
|
79
|
+
kind: "inherit",
|
|
80
|
+
from: opts?.from,
|
|
81
|
+
secret: opts?.secret ?? false,
|
|
82
|
+
optional: opts?.optional ?? false,
|
|
83
|
+
default: opts?.default,
|
|
84
|
+
applies: opts?.applies ?? "agent"
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
secret(secretName, opts) {
|
|
88
|
+
return brand({
|
|
89
|
+
kind: "secret",
|
|
90
|
+
secretName,
|
|
91
|
+
applies: opts?.applies ?? "agent"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function isHelperEntry(entry) {
|
|
96
|
+
return typeof entry === "object" && helperEntries.has(entry);
|
|
97
|
+
}
|
|
98
|
+
function assertNotStaticSecret(name, value, flags) {
|
|
99
|
+
if (containsInputToken(value))
|
|
100
|
+
return;
|
|
101
|
+
if (flags.secret) {
|
|
102
|
+
throw new Error(`Env "${name}": a secret must interpolate an input token; a static secret would be stored in plaintext. Use Env.inherit({ secret: true }) to read it from the worker.`);
|
|
103
|
+
}
|
|
104
|
+
if (isSecretLookingEnvName(name) && !flags.unsafeAllowStatic) {
|
|
105
|
+
throw new Error(`Env "${name}": a static value on a secret-looking name would be stored in plaintext. Use Env.inherit({ secret: true }) to read it from the worker, or Env.value({ value, unsafeAllowStatic: true }) if it is not actually secret.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function appliesField(applies) {
|
|
109
|
+
return applies === "agent" ? {} : { applies };
|
|
110
|
+
}
|
|
111
|
+
function toEnvVarSpec(name, entry) {
|
|
112
|
+
if (!isHelperEntry(entry)) {
|
|
113
|
+
const value = `${entry}`;
|
|
114
|
+
assertNotStaticSecret(name, value, {
|
|
115
|
+
secret: false,
|
|
116
|
+
unsafeAllowStatic: false
|
|
117
|
+
});
|
|
118
|
+
return { name, source: "value", value, secret: false };
|
|
119
|
+
}
|
|
120
|
+
if (entry.kind === "value") {
|
|
121
|
+
assertNotStaticSecret(name, entry.value, entry);
|
|
122
|
+
return {
|
|
123
|
+
name,
|
|
124
|
+
source: "value",
|
|
125
|
+
value: entry.value,
|
|
126
|
+
secret: entry.secret,
|
|
127
|
+
...appliesField(entry.applies)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (entry.kind === "secret") {
|
|
131
|
+
return {
|
|
132
|
+
name,
|
|
133
|
+
source: "secret",
|
|
134
|
+
secretName: entry.secretName,
|
|
135
|
+
...appliesField(entry.applies)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
name,
|
|
140
|
+
source: "inherit",
|
|
141
|
+
from: entry.from ?? name,
|
|
142
|
+
secret: entry.secret,
|
|
143
|
+
optional: entry.optional,
|
|
144
|
+
...entry.default !== undefined ? { default: entry.default } : {},
|
|
145
|
+
...appliesField(entry.applies)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function normalizeEnv(fn) {
|
|
149
|
+
if (!fn)
|
|
150
|
+
return null;
|
|
151
|
+
const record = typeof fn === "function" ? fn({ input: createPromptInputProxy(["input"]) }) : fn;
|
|
152
|
+
const specs = Object.entries(record).map(([name, entry]) => toEnvVarSpec(name, entry));
|
|
153
|
+
return specs.length > 0 ? specs : null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/definitions/steps/runtime.ts
|
|
157
|
+
var managedRuntimeFactories = Object.fromEntries(MANAGED_RUNTIME_IDS.map((id) => [id, () => ({ kind: "managed", id })]));
|
|
158
|
+
var Runtime = {
|
|
159
|
+
managed: managedRuntimeFactories,
|
|
160
|
+
devcontainer(opts) {
|
|
161
|
+
if (opts?.config === undefined)
|
|
162
|
+
return { kind: "devcontainer" };
|
|
163
|
+
const parsed = devcontainerConfigPathSchema.safeParse(opts.config);
|
|
164
|
+
if (!parsed.success) {
|
|
165
|
+
throw new Error(`Runtime.devcontainer config "${opts.config}": ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
|
|
166
|
+
}
|
|
167
|
+
return { kind: "devcontainer", config: parsed.data };
|
|
168
|
+
},
|
|
169
|
+
host() {
|
|
170
|
+
return { kind: "host" };
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
function assertNoSetupVarsOnHost(envJson, runtime, owner) {
|
|
174
|
+
if (runtime?.kind !== "host")
|
|
175
|
+
return;
|
|
176
|
+
const setupVar = (envJson ?? []).find((entry) => (entry.applies ?? "agent") !== "agent");
|
|
177
|
+
if (!setupVar)
|
|
178
|
+
return;
|
|
179
|
+
throw new Error(`${owner ? `${owner} ` : ""}env "${setupVar.name}": applies "${String(setupVar.applies)}" needs a container to set up, but Runtime.host() has none. Use applies "agent" or Runtime.devcontainer().`);
|
|
180
|
+
}
|
|
181
|
+
function compileConnectors(connectors, owner) {
|
|
182
|
+
if (connectors === undefined || connectors.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
const parsed = connectorIdsSchema.safeParse([...connectors]);
|
|
185
|
+
if (!parsed.success) {
|
|
186
|
+
throw new Error(`${owner ? `${owner} ` : ""}environment connectors: ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
|
|
187
|
+
}
|
|
188
|
+
return parsed.data;
|
|
189
|
+
}
|
|
190
|
+
function stepOwner(stepKey) {
|
|
191
|
+
return stepKey === undefined ? undefined : `Step "${stepKey}"`;
|
|
192
|
+
}
|
|
193
|
+
function knownEnvironmentVars(environment, compiled) {
|
|
194
|
+
if (isEnvironmentHandle(environment))
|
|
195
|
+
return environment.content.vars ?? [];
|
|
196
|
+
if (compiled?.kind === "named")
|
|
197
|
+
return;
|
|
198
|
+
return compiled?.envJson ?? [];
|
|
199
|
+
}
|
|
200
|
+
function compileEnvironment(environment, ctx = {}) {
|
|
201
|
+
if (typeof environment === "string") {
|
|
202
|
+
return { kind: "named", name: environmentNameSchema.parse(environment) };
|
|
203
|
+
}
|
|
204
|
+
if (isEnvironmentHandle(environment)) {
|
|
205
|
+
return { kind: "named", name: environment.name };
|
|
206
|
+
}
|
|
207
|
+
if (environment === undefined && ctx.defaultRuntime === undefined)
|
|
208
|
+
return null;
|
|
209
|
+
if (environment !== undefined && "branch" in environment) {
|
|
210
|
+
throw new Error(`${stepOwner(ctx.stepKey) ?? "Inline environment"}: environments have no branch; use the step's repo baseBranch.`);
|
|
211
|
+
}
|
|
212
|
+
const runtime = environment?.runtime ?? ctx.defaultRuntime;
|
|
213
|
+
const envJson = normalizeEnv(environment?.vars);
|
|
214
|
+
assertNoSetupVarsOnHost(envJson, runtime, stepOwner(ctx.stepKey));
|
|
215
|
+
const connectors = compileConnectors(environment !== undefined && "connectors" in environment ? environment.connectors : undefined, stepOwner(ctx.stepKey));
|
|
216
|
+
return {
|
|
217
|
+
kind: "inline",
|
|
218
|
+
...runtime === undefined ? {} : { runtime },
|
|
219
|
+
envJson,
|
|
220
|
+
...connectors === undefined ? {} : { connectors }
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { createPromptInputProxy, createPromptTemplateContext, renderPromptTemplate, isSecretLookingEnvName, Env, normalizeEnv, Runtime, assertNoSetupVarsOnHost, compileConnectors, knownEnvironmentVars, compileEnvironment };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ScarnClient,
|
|
4
4
|
TaskRuns,
|
|
5
5
|
createClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3zp2qtf8.js";
|
|
7
7
|
// src/task-plane-client.ts
|
|
8
8
|
function unwrap(result) {
|
|
9
9
|
if (result.error)
|
|
@@ -51,6 +51,10 @@ var buildTaskPlaneClient = (taskRuns) => {
|
|
|
51
51
|
taskRunId,
|
|
52
52
|
...body
|
|
53
53
|
}) => unwrap(await taskRuns.reportTaskRunBaseCommit({ path: { taskRunId }, body })),
|
|
54
|
+
resolveTaskRunEnvironment: async ({
|
|
55
|
+
taskRunId,
|
|
56
|
+
...body
|
|
57
|
+
}) => unwrap(await taskRuns.resolveTaskRunEnvironment({ path: { taskRunId }, body })),
|
|
54
58
|
readTaskRunWorkItem: async ({
|
|
55
59
|
taskRunId,
|
|
56
60
|
...body
|
package/dist/client.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createScarnClient,
|
|
4
4
|
createTaskPlaneClient
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-tvjcfh6s.js";
|
|
6
6
|
import {
|
|
7
7
|
Api,
|
|
8
8
|
Automations,
|
|
9
9
|
Billing,
|
|
10
|
+
Connectors,
|
|
10
11
|
Conversations,
|
|
12
|
+
Environments,
|
|
11
13
|
GitHubIntegrations,
|
|
12
14
|
Inbox,
|
|
13
15
|
NotificationRules,
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
ProjectArtifacts,
|
|
17
19
|
ProjectIntegrations,
|
|
18
20
|
ProjectInvites,
|
|
21
|
+
ProjectSecrets,
|
|
19
22
|
Projects,
|
|
20
23
|
ScarnClient,
|
|
21
24
|
Secrets,
|
|
@@ -28,13 +31,15 @@ import {
|
|
|
28
31
|
WorkItemCommentDrafts,
|
|
29
32
|
WorkItemComments,
|
|
30
33
|
WorkItems
|
|
31
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-3zp2qtf8.js";
|
|
32
35
|
import"./chunk-y64skrwp.js";
|
|
33
36
|
export {
|
|
34
37
|
Api,
|
|
35
38
|
Automations,
|
|
36
39
|
Billing,
|
|
40
|
+
Connectors,
|
|
37
41
|
Conversations,
|
|
42
|
+
Environments,
|
|
38
43
|
GitHubIntegrations,
|
|
39
44
|
Inbox,
|
|
40
45
|
NotificationRules,
|
|
@@ -43,6 +48,7 @@ export {
|
|
|
43
48
|
ProjectArtifacts,
|
|
44
49
|
ProjectIntegrations,
|
|
45
50
|
ProjectInvites,
|
|
51
|
+
ProjectSecrets,
|
|
46
52
|
Projects,
|
|
47
53
|
ScarnClient,
|
|
48
54
|
Secrets,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Scarn connector catalog: pre-built MCP servers an environment turns on
|
|
3
|
+
* with `connectors: [id, …]`. Each entry's `mcp` reads credentials only
|
|
4
|
+
* through `{env:NAME}` placeholders, and every placeholder is one of its
|
|
5
|
+
* `requiredVars`; the environment's `vars` provide them by any source.
|
|
6
|
+
* `validateConnectorCatalog` enforces this when the module loads.
|
|
7
|
+
*/
|
|
8
|
+
import { type ResolvedOpenCodeMcpServerConfig } from "../opencode-mcp";
|
|
9
|
+
/**
|
|
10
|
+
* How a connector authenticates. `none` is for local servers that need no
|
|
11
|
+
* credentials; `apiKey` reads static keys from `requiredVars`. OAuth joins
|
|
12
|
+
* this union in a later slice.
|
|
13
|
+
*/
|
|
14
|
+
export declare const connectorAuthValues: readonly ["none", "apiKey"];
|
|
15
|
+
export type ConnectorAuth = (typeof connectorAuthValues)[number];
|
|
16
|
+
export type ConnectorRequiredVar = {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
export type ConnectorDefinition = {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
auth: ConnectorAuth;
|
|
25
|
+
requiredVars: readonly ConnectorRequiredVar[];
|
|
26
|
+
mcp: ResolvedOpenCodeMcpServerConfig;
|
|
27
|
+
};
|
|
28
|
+
/** What the API exposes: everything but the MCP config. */
|
|
29
|
+
export type ConnectorSummary = Omit<ConnectorDefinition, "mcp" | "requiredVars"> & {
|
|
30
|
+
requiredVars: ConnectorRequiredVar[];
|
|
31
|
+
};
|
|
32
|
+
/** The env flag that adds {@link E2E_FAKE_CONNECTOR} to the catalog. */
|
|
33
|
+
export declare const E2E_FAKE_CONNECTOR_FLAG = "SCARN_E2E_FAKE_CONNECTOR";
|
|
34
|
+
/**
|
|
35
|
+
* A test-only connector for `packages/e2e-tests`. It runs the fake MCP server
|
|
36
|
+
* the e2e repository commits at `.scarn/e2e-fake-mcp.mjs`, and joins the
|
|
37
|
+
* catalog only in a process started with `SCARN_E2E_FAKE_CONNECTOR=true`. The
|
|
38
|
+
* e2e uses it through a named environment, which `scarn pipelines push`, the
|
|
39
|
+
* server and the worker all validate, so each of them needs the flag.
|
|
40
|
+
*/
|
|
41
|
+
export declare const E2E_FAKE_CONNECTOR: ConnectorDefinition;
|
|
42
|
+
/** The catalog's entries, plus the e2e fake when `env` sets its flag. */
|
|
43
|
+
export declare function connectorDefinitions(env: Readonly<Record<string, string | undefined>>): readonly ConnectorDefinition[];
|
|
44
|
+
/** Returns every problem with a catalog; empty when it is valid. */
|
|
45
|
+
export declare function validateConnectorCatalog(entries: readonly ConnectorDefinition[]): string[];
|
|
46
|
+
export declare const CONNECTOR_CATALOG: Readonly<Record<string, ConnectorDefinition>>;
|
|
47
|
+
export declare function isConnectorId(id: string): boolean;
|
|
48
|
+
export declare function getConnector(id: string): ConnectorDefinition | undefined;
|
|
49
|
+
export declare function listConnectorSummaries(): ConnectorSummary[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connectors: the catalog, the environment's `connectors` field, and the
|
|
3
|
+
* rules shared by the SDK, core and the worker (required vars, merging into a
|
|
4
|
+
* step's MCP servers, and the step `mcps` collision rule).
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import type { EnvVarSpecInput } from "../env-vars";
|
|
8
|
+
import type { ResolvedOpenCodeMcpServers } from "../opencode-mcp";
|
|
9
|
+
export * from "./catalog";
|
|
10
|
+
export declare const connectorIdsSchema: z.ZodArray<z.ZodString>;
|
|
11
|
+
export type ConnectorVarsMissingEntry = {
|
|
12
|
+
connector: string;
|
|
13
|
+
vars: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare class ConnectorVarsMissing extends Error {
|
|
16
|
+
readonly environment: string | undefined;
|
|
17
|
+
readonly missing: readonly ConnectorVarsMissingEntry[];
|
|
18
|
+
readonly kind = "ConnectorVarsMissing";
|
|
19
|
+
readonly code = "SCARN_CONNECTOR_VARS_MISSING";
|
|
20
|
+
/** `environment` is `environment <name> v<N>` for a named environment. */
|
|
21
|
+
constructor(environment: string | undefined, missing: readonly ConnectorVarsMissingEntry[]);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* For each connector, the required variables the environment does not give
|
|
25
|
+
* the agent. A setup-only var does not count: the MCP server runs in the
|
|
26
|
+
* agent.
|
|
27
|
+
*/
|
|
28
|
+
export declare function findMissingConnectorVars(connectors: readonly string[], envVars: readonly Pick<EnvVarSpecInput, "name" | "applies">[]): ConnectorVarsMissingEntry[];
|
|
29
|
+
/** Step `mcps` keys that reuse a connector id (decision 9). */
|
|
30
|
+
export declare function findConnectorMcpCollisions(connectors: readonly string[], stepMcpKeys: Iterable<string>): string[];
|
|
31
|
+
export declare function connectorMcpCollisionMessage(collisions: readonly string[]): string;
|
|
32
|
+
export declare class ConnectorMcpCollision extends Error {
|
|
33
|
+
readonly collisions: readonly string[];
|
|
34
|
+
readonly kind = "ConnectorMcpCollision";
|
|
35
|
+
readonly code = "SCARN_ENVIRONMENT_INVALID";
|
|
36
|
+
constructor(collisions: readonly string[]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The step's MCP servers plus each connector's catalog config under its id.
|
|
40
|
+
* Throws `ConnectorMcpCollision` when one of `stepMcpKeys` (the step's own
|
|
41
|
+
* `mcps` keys; default: every key of `servers`) reuses a connector id. Other
|
|
42
|
+
* entries under a connector id, such as a disabled repository server, are
|
|
43
|
+
* replaced.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeConnectorMcpServers(connectors: readonly string[], servers: ResolvedOpenCodeMcpServers | null, stepMcpKeys?: Iterable<string>): ResolvedOpenCodeMcpServers | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
CONNECTOR_CATALOG,
|
|
4
|
+
ConnectorMcpCollision,
|
|
5
|
+
ConnectorVarsMissing,
|
|
6
|
+
E2E_FAKE_CONNECTOR,
|
|
7
|
+
E2E_FAKE_CONNECTOR_FLAG,
|
|
8
|
+
connectorAuthValues,
|
|
9
|
+
connectorDefinitions,
|
|
10
|
+
connectorIdsSchema,
|
|
11
|
+
connectorMcpCollisionMessage,
|
|
12
|
+
findConnectorMcpCollisions,
|
|
13
|
+
findMissingConnectorVars,
|
|
14
|
+
getConnector,
|
|
15
|
+
isConnectorId,
|
|
16
|
+
listConnectorSummaries,
|
|
17
|
+
mergeConnectorMcpServers,
|
|
18
|
+
validateConnectorCatalog
|
|
19
|
+
} from "../chunk-qgkx89eg.js";
|
|
20
|
+
import"../chunk-pqtd0hr7.js";
|
|
21
|
+
import"../chunk-aemxz9r7.js";
|
|
22
|
+
import"../chunk-yf15kdte.js";
|
|
23
|
+
import"../chunk-y64skrwp.js";
|
|
24
|
+
export {
|
|
25
|
+
CONNECTOR_CATALOG,
|
|
26
|
+
ConnectorMcpCollision,
|
|
27
|
+
ConnectorVarsMissing,
|
|
28
|
+
E2E_FAKE_CONNECTOR,
|
|
29
|
+
E2E_FAKE_CONNECTOR_FLAG,
|
|
30
|
+
connectorAuthValues,
|
|
31
|
+
connectorDefinitions,
|
|
32
|
+
connectorIdsSchema,
|
|
33
|
+
connectorMcpCollisionMessage,
|
|
34
|
+
findConnectorMcpCollisions,
|
|
35
|
+
findMissingConnectorVars,
|
|
36
|
+
getConnector,
|
|
37
|
+
isConnectorId,
|
|
38
|
+
listConnectorSummaries,
|
|
39
|
+
mergeConnectorMcpServers,
|
|
40
|
+
validateConnectorCatalog
|
|
41
|
+
};
|
package/dist/defaults/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
} from "../chunk-rt9tq4j6.js";
|
|
5
5
|
import {
|
|
6
6
|
createScarnClient
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import"../chunk-
|
|
7
|
+
} from "../chunk-tvjcfh6s.js";
|
|
8
|
+
import"../chunk-3zp2qtf8.js";
|
|
9
9
|
import"../chunk-y64skrwp.js";
|
|
10
10
|
|
|
11
11
|
// src/defaults/auth-file.ts
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
AutomationsApiError,
|
|
4
4
|
createAutomationsClient
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import"../../chunk-
|
|
5
|
+
} from "../../chunk-2tmrw253.js";
|
|
6
|
+
import"../../chunk-3zp2qtf8.js";
|
|
7
7
|
import"../../chunk-yf15kdte.js";
|
|
8
8
|
import"../../chunk-y64skrwp.js";
|
|
9
9
|
export {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type EnvironmentContentOutput } from "../../environment";
|
|
2
|
+
import { type EnvRecord } from "../steps/env";
|
|
3
|
+
import { type RuntimeSpec } from "../steps/runtime";
|
|
4
|
+
export type DefineEnvironmentInput<TEnv extends EnvRecord = EnvRecord> = {
|
|
5
|
+
/** The name steps use to refer to it: `[a-z0-9][a-z0-9-]*`. */
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Defaults to the repository's runtime. */
|
|
9
|
+
runtime?: RuntimeSpec;
|
|
10
|
+
/**
|
|
11
|
+
* A record only: an environment is shared by steps with different inputs,
|
|
12
|
+
* so it has no function form and no `{{input.…}}` tokens.
|
|
13
|
+
*/
|
|
14
|
+
vars?: TEnv;
|
|
15
|
+
/**
|
|
16
|
+
* Scarn catalog connectors to turn on, e.g. `["datadog"]`. `vars` must
|
|
17
|
+
* provide each connector's required variables.
|
|
18
|
+
*/
|
|
19
|
+
connectors?: readonly string[];
|
|
20
|
+
};
|
|
21
|
+
/** A named environment's compiled content: what push uploads. */
|
|
22
|
+
export type EnvironmentContent = EnvironmentContentOutput;
|
|
23
|
+
/**
|
|
24
|
+
* What `defineEnvironment` returns. A step can use it in place of the
|
|
25
|
+
* environment's name. `__env` is a phantom field: it exists only in the type,
|
|
26
|
+
* so a step's prompt `env` can be typed from the environment's `vars`.
|
|
27
|
+
*/
|
|
28
|
+
export type EnvironmentHandle<TEnv extends EnvRecord = EnvRecord> = {
|
|
29
|
+
readonly kind: "environment";
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly content: EnvironmentContent;
|
|
32
|
+
readonly __env: TEnv;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Defines a named environment. Runs the checks inline environments run (no
|
|
36
|
+
* static secrets, no setup vars on host, known connectors) plus every
|
|
37
|
+
* connector's required vars, and throws on the first problem.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defineEnvironment<const TEnv extends EnvRecord = Record<never, never>>(config: DefineEnvironmentInput<TEnv>): EnvironmentHandle<TEnv>;
|