@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.
Files changed (62) hide show
  1. package/dist/{chunk-g2mzg278.js → chunk-0c60x3v8.js} +51 -59
  2. package/dist/{chunk-dhqeg0wf.js → chunk-2tmrw253.js} +1 -1
  3. package/dist/{chunk-r03knh9j.js → chunk-3zp2qtf8.js} +80 -1
  4. package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
  5. package/dist/{chunk-a04phj60.js → chunk-833ef6dg.js} +121 -260
  6. package/dist/{chunk-2ekz6tr5.js → chunk-aemxz9r7.js} +18 -2
  7. package/dist/chunk-e0pt5x0e.js +167 -0
  8. package/dist/chunk-mmy80pec.js +64 -0
  9. package/dist/chunk-mzj1j0p5.js +116 -0
  10. package/dist/{chunk-cdj0yqgs.js → chunk-pqtd0hr7.js} +12 -2
  11. package/dist/chunk-qgkx89eg.js +210 -0
  12. package/dist/chunk-rphfy0fj.js +167 -0
  13. package/dist/chunk-t1dq2c2s.js +224 -0
  14. package/dist/{chunk-qs7p11rp.js → chunk-tvjcfh6s.js} +5 -1
  15. package/dist/{chunk-1wnv6rb2.js → chunk-ymywp5ht.js} +1 -1
  16. package/dist/client.js +8 -2
  17. package/dist/connectors/catalog.d.ts +49 -0
  18. package/dist/connectors/index.d.ts +45 -0
  19. package/dist/connectors/index.js +41 -0
  20. package/dist/defaults/index.js +2 -2
  21. package/dist/definitions/automations/index.js +2 -2
  22. package/dist/definitions/environments/define-environment.d.ts +39 -0
  23. package/dist/definitions/environments/environments-client.d.ts +50 -0
  24. package/dist/definitions/environments/index.d.ts +6 -0
  25. package/dist/definitions/environments/index.js +97 -0
  26. package/dist/definitions/pipelines/index.js +2 -2
  27. package/dist/definitions/steps/compile-mcps.d.ts +8 -12
  28. package/dist/definitions/steps/define-code-step.d.ts +18 -11
  29. package/dist/definitions/steps/define-step.d.ts +14 -25
  30. package/dist/definitions/steps/env.d.ts +30 -8
  31. package/dist/definitions/steps/index.js +30 -13
  32. package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
  33. package/dist/definitions/steps/repo.d.ts +56 -28
  34. package/dist/definitions/steps/runtime.d.ts +54 -39
  35. package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
  36. package/dist/definitions/steps/step-handle.d.ts +8 -1
  37. package/dist/definitions/validation/index.js +6 -3
  38. package/dist/definitions/validation/validate-repo.d.ts +3 -7
  39. package/dist/definitions/validation/validate-runtime.d.ts +2 -7
  40. package/dist/env-vars.d.ts +57 -1
  41. package/dist/env-vars.js +7 -1
  42. package/dist/environment.d.ts +564 -0
  43. package/dist/environment.js +46 -0
  44. package/dist/generated/index.d.ts +2 -2
  45. package/dist/generated/sdk.gen.d.ts +26 -1
  46. package/dist/generated/types.gen.d.ts +2090 -187
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.js +94 -28
  49. package/dist/opencode-mcp.d.ts +75 -4
  50. package/dist/opencode-mcp.js +2 -1
  51. package/dist/push/code-step-lookup.d.ts +6 -0
  52. package/dist/push/code-step-lookup.js +3 -1
  53. package/dist/push/collect-definitions.d.ts +13 -0
  54. package/dist/push/index.js +127 -15
  55. package/dist/push/push-from-directory.d.ts +11 -2
  56. package/dist/repo-config.d.ts +88 -30
  57. package/dist/repo-config.js +21 -5
  58. package/dist/resolve-environment.d.ts +19 -0
  59. package/dist/resolve-environment.js +19 -0
  60. package/dist/task-plane-client.d.ts +124 -22
  61. package/package.json +17 -1
  62. package/dist/chunk-2sk92cnd.js +0 -103
@@ -1,40 +1,50 @@
1
1
  // @bun
2
- import {
3
- collectEnvPlaceholderNames,
4
- isEnvPlaceholderValue,
5
- openCodeMcpLocalConfigSchema,
6
- openCodeMcpRefConfigSchema,
7
- openCodeMcpRemoteConfigSchema
8
- } from "./chunk-cdj0yqgs.js";
9
2
  import {
10
3
  stepHealthChecksInputSchema,
11
4
  toolHealthCheckSchema
12
5
  } from "./chunk-y34zsgsw.js";
6
+ import {
7
+ Runtime,
8
+ compileEnvironment,
9
+ createPromptInputProxy,
10
+ createPromptTemplateContext,
11
+ knownEnvironmentVars
12
+ } from "./chunk-t1dq2c2s.js";
13
+ import {
14
+ isEnvironmentHandle
15
+ } from "./chunk-6tra3gw8.js";
13
16
  import {
14
17
  makeHandle,
15
18
  stepCall,
16
19
  stepNode
17
20
  } from "./chunk-jj9pezwb.js";
18
21
  import {
19
- ENV_VAR_NAME_PATTERN,
20
- containsInputToken,
21
- isReservedEnvVarName
22
- } from "./chunk-2ekz6tr5.js";
23
- import {
24
- devcontainerConfigPathSchema
25
- } from "./chunk-098740f7.js";
22
+ describeBaseBranchEnvProblem,
23
+ findBaseBranchEnvProblems,
24
+ repoConfigInputSchema
25
+ } from "./chunk-rphfy0fj.js";
26
26
  import {
27
- DEFAULT_CODE_STEP_RUNTIME_ID,
28
- MANAGED_RUNTIME_IDS
27
+ DEFAULT_CODE_STEP_RUNTIME_ID
29
28
  } from "./chunk-46wmsgv7.js";
30
29
  import {
31
- repoConfigInputSchema,
32
- repoRuntimeMismatch
33
- } from "./chunk-2sk92cnd.js";
30
+ connectorMcpCollisionMessage,
31
+ findConnectorMcpCollisions
32
+ } from "./chunk-qgkx89eg.js";
33
+ import {
34
+ collectEnvPlaceholderNames,
35
+ isEnvPlaceholderValue,
36
+ openCodeMcpLocalConfigSchema,
37
+ openCodeMcpRefConfigSchema,
38
+ openCodeMcpRemoteConfigSchema
39
+ } from "./chunk-pqtd0hr7.js";
40
+ import {
41
+ ENV_VAR_NAME_PATTERN,
42
+ isReservedEnvVarName
43
+ } from "./chunk-aemxz9r7.js";
34
44
  import {
35
45
  StepDefinitions,
36
46
  createClient
37
- } from "./chunk-r03knh9j.js";
47
+ } from "./chunk-3zp2qtf8.js";
38
48
  import {
39
49
  buildArtifactMarker
40
50
  } from "./chunk-ngy1fdcx.js";
@@ -636,131 +646,8 @@ var Artifact = {
636
646
  return buildArtifactMarker("link", toMarkerRef(target), options.label);
637
647
  }
638
648
  };
639
- // src/definitions/steps/prompt-template.ts
640
- function createPromptInputProxy(path = []) {
641
- const token = () => path.length ? `{{${path.join(".")}}}` : "";
642
- return new Proxy(Object.freeze({}), {
643
- get(_, key) {
644
- if (key === Symbol.toPrimitive || key === "valueOf") {
645
- return (_hint) => token();
646
- }
647
- if (key === "toString") {
648
- return () => token();
649
- }
650
- if (typeof key !== "string")
651
- return;
652
- return createPromptInputProxy([...path, key]);
653
- }
654
- });
655
- }
656
- function createPromptTemplateContext() {
657
- return {
658
- input: createPromptInputProxy(["input"]),
659
- env: createPromptInputProxy(["env"]),
660
- scarn: {
661
- artifactsDir: createPromptInputProxy([
662
- "scarn",
663
- "artifactsDir"
664
- ])
665
- }
666
- };
667
- }
668
- function renderPromptTemplate(template, contextJson) {
669
- return template.replace(/\{\{([^}]+)\}\}/g, (_, path) => {
670
- const value = path.split(".").reduce((curr, key) => curr != null ? curr[key] : undefined, contextJson);
671
- return value != null ? String(value) : "";
672
- });
673
- }
674
-
675
- // src/definitions/steps/env.ts
676
- var SECRET_LOOKING_NAME = /SECRET|TOKEN|PASSWORD|PASSWD|API_?KEY|PRIVATE/i;
677
- function isSecretLookingEnvName(name) {
678
- return SECRET_LOOKING_NAME.test(name);
679
- }
680
- var helperEntries = new WeakSet;
681
- function brand(entry) {
682
- helperEntries.add(entry);
683
- return entry;
684
- }
685
- var Env = {
686
- value(opts) {
687
- return brand({
688
- kind: "value",
689
- value: opts.value,
690
- secret: opts.secret ?? false,
691
- unsafeAllowStatic: opts.unsafeAllowStatic ?? false,
692
- applies: opts.applies ?? "agent"
693
- });
694
- },
695
- inherit(opts) {
696
- return brand({
697
- kind: "inherit",
698
- from: opts?.from,
699
- secret: opts?.secret ?? false,
700
- optional: opts?.optional ?? false,
701
- default: opts?.default,
702
- applies: opts?.applies ?? "agent"
703
- });
704
- }
705
- };
706
- function isHelperEntry(entry) {
707
- return typeof entry === "object" && helperEntries.has(entry);
708
- }
709
- function assertNotStaticSecret(name, value, flags) {
710
- if (containsInputToken(value))
711
- return;
712
- if (flags.secret) {
713
- 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.`);
714
- }
715
- if (isSecretLookingEnvName(name) && !flags.unsafeAllowStatic) {
716
- 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.`);
717
- }
718
- }
719
- function appliesField(applies) {
720
- return applies === "agent" ? {} : { applies };
721
- }
722
- function toEnvVarSpec(name, entry) {
723
- if (!isHelperEntry(entry)) {
724
- const value = `${entry}`;
725
- assertNotStaticSecret(name, value, {
726
- secret: false,
727
- unsafeAllowStatic: false
728
- });
729
- return { name, source: "value", value, secret: false };
730
- }
731
- if (entry.kind === "value") {
732
- assertNotStaticSecret(name, entry.value, entry);
733
- return {
734
- name,
735
- source: "value",
736
- value: entry.value,
737
- secret: entry.secret,
738
- ...appliesField(entry.applies)
739
- };
740
- }
741
- return {
742
- name,
743
- source: "inherit",
744
- from: entry.from ?? name,
745
- secret: entry.secret,
746
- optional: entry.optional,
747
- ...entry.default !== undefined ? { default: entry.default } : {},
748
- ...appliesField(entry.applies)
749
- };
750
- }
751
- function normalizeEnv(fn) {
752
- if (!fn)
753
- return null;
754
- const record2 = fn({ input: createPromptInputProxy(["input"]) });
755
- const specs = Object.entries(record2).map(([name, entry]) => toEnvVarSpec(name, entry));
756
- return specs.length > 0 ? specs : null;
757
- }
758
-
759
649
  // src/definitions/steps/repo.ts
760
650
  var Repo = {
761
- none() {
762
- return { mode: "none" };
763
- },
764
651
  readOnly(opts) {
765
652
  return { mode: "readOnly", ...opts };
766
653
  },
@@ -768,23 +655,24 @@ var Repo = {
768
655
  return { mode: "readWrite", ...opts };
769
656
  }
770
657
  };
771
- function executionModeOf(runtime) {
772
- return runtime?.kind === "host" ? "no_workspace" : "workspace";
773
- }
774
- function compileRepo(repo, runtime, ctx = {}) {
658
+ var WorkBranch = {
659
+ create() {
660
+ return { kind: "create" };
661
+ },
662
+ base() {
663
+ return { kind: "base" };
664
+ }
665
+ };
666
+ function compileRepo(repo, ctx = {}) {
775
667
  if (repo === undefined)
776
668
  return;
777
669
  const spec = typeof repo === "function" ? repo({
778
670
  input: createPromptInputProxy(["input"]),
779
671
  result: createPromptInputProxy(["result"]),
780
- workItem: createPromptInputProxy(["workItem"])
672
+ workItem: createPromptInputProxy(["workItem"]),
673
+ env: createPromptInputProxy(["env"])
781
674
  }) : repo;
782
675
  const where = ctx.stepKey ? `Step "${ctx.stepKey}" repo` : "repo";
783
- const executionMode = executionModeOf(runtime);
784
- const mismatch = repoRuntimeMismatch(executionMode, spec.mode);
785
- if (mismatch !== null) {
786
- throw new Error(`${where} "${spec.mode}" cannot be used with executionMode "${executionMode}": ${mismatch}.`);
787
- }
788
676
  const config2 = toRepoConfigInput(spec);
789
677
  const parsed = repoConfigInputSchema.safeParse(config2);
790
678
  if (!parsed.success) {
@@ -793,61 +681,46 @@ function compileRepo(repo, runtime, ctx = {}) {
793
681
  return config2;
794
682
  }
795
683
  function toRepoConfigInput(spec) {
796
- if (spec.mode === "readWrite")
797
- return toReadWriteConfig(spec);
798
- if (spec.mode === "readOnly")
799
- return { mode: "readOnly", ...gitCredentialsOf(spec) };
800
- return { mode: "none" };
684
+ switch (spec.mode) {
685
+ case "readWrite":
686
+ return toReadWriteConfig(spec);
687
+ case "readOnly":
688
+ return {
689
+ mode: "readOnly",
690
+ ...gitCredentialsOf(spec),
691
+ ...branchOptsOf(spec)
692
+ };
693
+ }
694
+ throw new Error("repo mode must be readOnly or readWrite");
695
+ }
696
+ function assertBaseBranchFitsEnvironment(repo, vars, ctx = {}) {
697
+ const baseBranch = repo?.baseBranch;
698
+ if (baseBranch == null || vars === undefined)
699
+ return;
700
+ const problems = findBaseBranchEnvProblems(baseBranch, vars);
701
+ if (problems.length === 0)
702
+ return;
703
+ const where = ctx.stepKey ? `Step "${ctx.stepKey}" repo` : "repo";
704
+ throw new Error(`${where}: baseBranch ${problems.map(describeBaseBranchEnvProblem).join("; ")}`);
801
705
  }
802
706
  function gitCredentialsOf(spec) {
803
707
  return spec.gitCredentials !== undefined ? { gitCredentials: spec.gitCredentials } : {};
804
708
  }
709
+ function branchOptsOf(spec) {
710
+ return spec.baseBranch !== undefined ? {
711
+ baseBranch: `${spec.baseBranch}`
712
+ } : {};
713
+ }
805
714
  function toReadWriteConfig(spec) {
806
715
  return {
807
716
  mode: "readWrite",
808
717
  ...gitCredentialsOf(spec),
718
+ ...branchOptsOf(spec),
809
719
  ...spec.message !== undefined ? {
810
720
  message: `${spec.message}`
811
721
  } : {},
812
- ...spec.onPushFailure !== undefined ? { onPushFailure: spec.onPushFailure } : {}
813
- };
814
- }
815
-
816
- // src/definitions/steps/runtime.ts
817
- var managedRuntimeFactories = Object.fromEntries(MANAGED_RUNTIME_IDS.map((id) => [id, () => ({ kind: "managed", id })]));
818
- var Runtime = {
819
- managed: managedRuntimeFactories,
820
- devcontainer(opts) {
821
- if (opts?.config === undefined)
822
- return { kind: "devcontainer" };
823
- const parsed = devcontainerConfigPathSchema.safeParse(opts.config);
824
- if (!parsed.success) {
825
- throw new Error(`Runtime.devcontainer config "${opts.config}": ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
826
- }
827
- return { kind: "devcontainer", config: parsed.data };
828
- },
829
- host() {
830
- return { kind: "host" };
831
- }
832
- };
833
- function assertNoSetupVarsOnHost(envJson, runtime, stepKey) {
834
- if (runtime?.kind !== "host")
835
- return;
836
- const setupVar = (envJson ?? []).find((entry) => (entry.applies ?? "agent") !== "agent");
837
- if (!setupVar)
838
- return;
839
- throw new Error(`${stepKey ? `Step "${stepKey}" ` : ""}env "${setupVar.name}": applies "${String(setupVar.applies)}" needs a container to set up, but Runtime.host() has none. Use applies "agent" or Runtime.devcontainer().`);
840
- }
841
- function compileEnvironment(environment, ctx = {}) {
842
- const runtime = environment?.runtime ?? ctx.defaultRuntime;
843
- const envJson = normalizeEnv(environment?.vars);
844
- assertNoSetupVarsOnHost(envJson, runtime, ctx.stepKey);
845
- return {
846
- executionMode: runtime?.kind === "host" ? "no_workspace" : "workspace",
847
- devcontainerConfigPath: runtime?.kind === "devcontainer" ? runtime.config ?? null : null,
848
- managedRuntime: runtime?.kind === "managed" ? runtime.id : null,
849
- envJson,
850
- repo: compileRepo(environment?.repo, runtime, ctx)
722
+ ...spec.onPushFailure !== undefined ? { onPushFailure: spec.onPushFailure } : {},
723
+ ...spec.workBranch !== undefined ? { workBranch: spec.workBranch } : {}
851
724
  };
852
725
  }
853
726
 
@@ -1089,17 +962,20 @@ function resolveMcpChecks(handle) {
1089
962
 
1090
963
  // src/definitions/steps/compile-mcps.ts
1091
964
  function compileServer(key, handle) {
965
+ const workerVars = compileEnv(key, handle);
966
+ const metadata = workerVars.length > 0 ? { workerVars } : {};
1092
967
  switch (handle.type) {
1093
968
  case "ref":
1094
969
  return {
1095
970
  type: "ref",
1096
971
  ...handle.name !== key ? { name: handle.name } : {},
1097
- ...structuredClone(handle.server)
972
+ ...structuredClone(handle.server),
973
+ ...metadata
1098
974
  };
1099
975
  case "local":
1100
- return { type: "local", ...structuredClone(handle.server) };
976
+ return { type: "local", ...structuredClone(handle.server), ...metadata };
1101
977
  case "remote":
1102
- return { type: "remote", ...structuredClone(handle.server) };
978
+ return { type: "remote", ...structuredClone(handle.server), ...metadata };
1103
979
  }
1104
980
  }
1105
981
  function compileChecks(key, handle) {
@@ -1132,30 +1008,10 @@ function compileEnv(key, handle) {
1132
1008
  ...handle.optionalEnv.map((name) => entry(name, true))
1133
1009
  ];
1134
1010
  }
1135
- function dedupeEnv(entries) {
1136
- const byName = new Map;
1137
- for (const entry of entries) {
1138
- const existing = byName.get(entry.name);
1139
- if (!existing) {
1140
- byName.set(entry.name, entry);
1141
- continue;
1142
- }
1143
- byName.set(entry.name, {
1144
- source: "inherit",
1145
- name: entry.name,
1146
- from: entry.from,
1147
- secret: true,
1148
- optional: existing.optional && entry.optional,
1149
- applies: "agent"
1150
- });
1151
- }
1152
- return [...byName.values()];
1153
- }
1154
1011
  function compileMcps(mcps, stepKey) {
1155
1012
  const compiled = {
1156
1013
  opencodeMcpJson: {},
1157
- healthChecks: [],
1158
- envEntries: []
1014
+ healthChecks: []
1159
1015
  };
1160
1016
  for (const [key, handle] of Object.entries(mcps)) {
1161
1017
  if (!isMcpHandle(handle)) {
@@ -1163,11 +1019,17 @@ function compileMcps(mcps, stepKey) {
1163
1019
  }
1164
1020
  compiled.opencodeMcpJson[key] = compileServer(key, handle);
1165
1021
  compiled.healthChecks.push(...compileChecks(key, handle));
1166
- compiled.envEntries.push(...compileEnv(key, handle));
1167
1022
  }
1168
- compiled.envEntries = dedupeEnv(compiled.envEntries);
1169
1023
  return compiled;
1170
1024
  }
1025
+ function assertNoConnectorMcpCollisions(stepKey, environment, mcps) {
1026
+ if (!isEnvironmentHandle(environment) || mcps === undefined)
1027
+ return;
1028
+ const collisions = findConnectorMcpCollisions(environment.content.connectors ?? [], Object.keys(mcps));
1029
+ if (collisions.length === 0)
1030
+ return;
1031
+ throw new Error(`Step "${stepKey}" environment "${environment.name}": ${connectorMcpCollisionMessage(collisions)}`);
1032
+ }
1171
1033
  function nonEmpty(items) {
1172
1034
  return items.length > 0 ? items : null;
1173
1035
  }
@@ -1180,18 +1042,13 @@ function mergeStepMcps(stepKey, input2) {
1180
1042
  };
1181
1043
  }
1182
1044
  const compiled = compileMcps(input2.mcps, stepKey);
1183
- const stepVars = input2.envJson ?? [];
1184
- const stepVarNames = new Set(stepVars.map((entry) => entry.name));
1185
1045
  return {
1186
1046
  opencodeMcpJson: compiled.opencodeMcpJson,
1187
1047
  healthChecksJson: nonEmpty([
1188
1048
  ...compiled.healthChecks,
1189
1049
  ...input2.healthChecks ?? []
1190
1050
  ]),
1191
- envJson: nonEmpty([
1192
- ...compiled.envEntries.filter((entry) => !stepVarNames.has(entry.name)),
1193
- ...stepVars
1194
- ])
1051
+ envJson: input2.envJson
1195
1052
  };
1196
1053
  }
1197
1054
 
@@ -1241,7 +1098,7 @@ function compileStepConcurrency(stepKey, concurrency) {
1241
1098
  }
1242
1099
  return { max: concurrency.max, waiting: concurrency.waiting };
1243
1100
  }
1244
- function toStepHandle(spec) {
1101
+ function toStepHandle(spec, environmentHandle) {
1245
1102
  const node = stepNode(spec);
1246
1103
  const call = stepCall(node);
1247
1104
  const { name, ...rest } = spec;
@@ -1250,8 +1107,22 @@ function toStepHandle(spec) {
1250
1107
  enumerable: true
1251
1108
  });
1252
1109
  Object.assign(call, rest);
1110
+ if (environmentHandle !== undefined) {
1111
+ Object.defineProperty(call, "environmentHandle", {
1112
+ value: environmentHandle,
1113
+ enumerable: false
1114
+ });
1115
+ }
1253
1116
  return makeHandle(call, node);
1254
1117
  }
1118
+ function stepEnvironmentHandle(step) {
1119
+ if (typeof step !== "function" && typeof step !== "object")
1120
+ return;
1121
+ if (step === null)
1122
+ return;
1123
+ const handle = step.environmentHandle;
1124
+ return isEnvironmentHandle(handle) ? handle : undefined;
1125
+ }
1255
1126
  function toStepSpec(step) {
1256
1127
  return { ...step };
1257
1128
  }
@@ -1303,18 +1174,17 @@ function defineStep(config2) {
1303
1174
  ${feature._promptAddition}` : feature._promptAddition;
1304
1175
  }
1305
1176
  }
1306
- const {
1307
- executionMode,
1308
- devcontainerConfigPath,
1309
- managedRuntime,
1310
- envJson,
1311
- repo
1312
- } = compileEnvironment(config2.environment, { stepKey: config2.key });
1177
+ const environment = compileEnvironment(config2.environment, {
1178
+ stepKey: config2.key
1179
+ });
1180
+ const repo = compileRepo(config2.repo, { stepKey: config2.key });
1181
+ assertBaseBranchFitsEnvironment(repo, knownEnvironmentVars(config2.environment, environment), { stepKey: config2.key });
1313
1182
  assertStepMcpInput(config2);
1183
+ assertNoConnectorMcpCollisions(config2.key, config2.environment, config2.mcps);
1314
1184
  const mcpFields = mergeStepMcps(config2.key, {
1315
1185
  mcps: config2.mcps,
1316
1186
  healthChecks: config2.healthChecks,
1317
- envJson
1187
+ envJson: environment?.kind === "inline" ? environment.envJson : null
1318
1188
  });
1319
1189
  const resultSchemaJson = effectiveResult ? toJSONSchema(effectiveResult) : null;
1320
1190
  const spec = {
@@ -1324,15 +1194,12 @@ ${feature._promptAddition}` : feature._promptAddition;
1324
1194
  version: config2.version ?? 1,
1325
1195
  kind: "user_defined",
1326
1196
  status: config2.status ?? "active",
1327
- executionMode,
1328
- devcontainerConfigPath,
1329
- ...managedRuntime !== null ? { managedRuntime } : {},
1197
+ environment,
1330
1198
  prompt: effectivePrompt,
1331
1199
  inputSchemaJson: config2.input ? toJSONSchema(config2.input) : null,
1332
1200
  resultSchemaJson,
1333
1201
  opencodeMcpJson: mcpFields.opencodeMcpJson,
1334
1202
  healthChecksJson: mcpFields.healthChecksJson,
1335
- envJson: mcpFields.envJson,
1336
1203
  ...repo !== undefined ? { repo } : {},
1337
1204
  errors: compileStepErrors(config2.key, config2.errors),
1338
1205
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
@@ -1342,7 +1209,7 @@ ${feature._promptAddition}` : feature._promptAddition;
1342
1209
  } : {},
1343
1210
  ...grants.length > 0 ? { grants } : {}
1344
1211
  };
1345
- return toStepHandle(spec);
1212
+ return toStepHandle(spec, isEnvironmentHandle(config2.environment) ? config2.environment : undefined);
1346
1213
  }
1347
1214
  // src/definitions/steps/define-code-step.ts
1348
1215
  function codeStep(config2) {
@@ -1353,16 +1220,16 @@ function codeStep(config2) {
1353
1220
  continue;
1354
1221
  effectiveResult = effectiveResult ? effectiveResult.extend(feature._resultExtension.shape) : feature._resultExtension;
1355
1222
  }
1356
- const {
1357
- executionMode,
1358
- devcontainerConfigPath,
1359
- managedRuntime,
1360
- envJson,
1361
- repo
1362
- } = compileEnvironment(config2.environment, {
1223
+ const environmentHandle = isEnvironmentHandle(config2.environment) ? config2.environment : undefined;
1224
+ if (environmentHandle?.content.runtime?.kind === "host") {
1225
+ throw new Error(`Step "${config2.key}" environment "${environmentHandle.name}": a code step needs a container, but the environment's runtime is Runtime.host(). Use Runtime.managed.bun1() or Runtime.devcontainer().`);
1226
+ }
1227
+ const environment = compileEnvironment(config2.environment, {
1363
1228
  stepKey: config2.key,
1364
1229
  defaultRuntime: Runtime.managed[DEFAULT_CODE_STEP_RUNTIME_ID]()
1365
1230
  });
1231
+ const repo = compileRepo(config2.repo, { stepKey: config2.key });
1232
+ assertBaseBranchFitsEnvironment(repo, knownEnvironmentVars(config2.environment, environment), { stepKey: config2.key });
1366
1233
  const spec = {
1367
1234
  key: config2.key,
1368
1235
  name: config2.name,
@@ -1370,15 +1237,12 @@ function codeStep(config2) {
1370
1237
  version: config2.version ?? 1,
1371
1238
  kind: "code",
1372
1239
  status: config2.status ?? "active",
1373
- executionMode,
1374
- devcontainerConfigPath,
1375
- managedRuntime,
1240
+ environment,
1376
1241
  prompt: null,
1377
1242
  inputSchemaJson: config2.inputSchema ? toJSONSchema(config2.inputSchema) : null,
1378
1243
  resultSchemaJson: effectiveResult ? toJSONSchema(effectiveResult) : null,
1379
1244
  opencodeMcpJson: null,
1380
1245
  healthChecksJson: null,
1381
- envJson,
1382
1246
  ...repo !== undefined ? { repo } : {},
1383
1247
  errors: compileStepErrors(config2.key, config2.errors),
1384
1248
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
@@ -1387,7 +1251,7 @@ function codeStep(config2) {
1387
1251
  } : {},
1388
1252
  entrypoint: { fn: config2.fn }
1389
1253
  };
1390
- return toStepHandle(spec);
1254
+ return toStepHandle(spec, environmentHandle);
1391
1255
  }
1392
1256
  // src/definitions/steps/step-definitions-client.ts
1393
1257
  var ANY_OBJECT_SCHEMA = { type: "object" };
@@ -1425,15 +1289,12 @@ var buildStepDefinitionsClient = (stepDefinitions) => {
1425
1289
  version: spec.version,
1426
1290
  kind: spec.kind,
1427
1291
  entrypointJson: spec.entrypointJson ?? null,
1428
- executionMode: spec.executionMode,
1429
- devcontainerConfigPath: spec.devcontainerConfigPath,
1430
- managedRuntime: spec.managedRuntime,
1292
+ environment: spec.environment,
1431
1293
  repo: spec.repo,
1432
1294
  inputSchemaJson: spec.inputSchemaJson ?? ANY_OBJECT_SCHEMA,
1433
1295
  resultSchemaJson: spec.kind === "code" ? spec.resultSchemaJson ?? ANY_OBJECT_SCHEMA : spec.resultSchemaJson,
1434
1296
  opencodeMcpJson: spec.opencodeMcpJson,
1435
1297
  healthChecksJson: spec.healthChecksJson,
1436
- envJson: spec.envJson,
1437
1298
  errors: [...spec.errors ?? []],
1438
1299
  retry: (spec.retryJson ?? []).map((entry) => ({
1439
1300
  on: [...entry.on],
@@ -1645,4 +1506,4 @@ var Notify = {
1645
1506
  [NOTIFICATION_RESULT_KEY]: fragments.flatMap((fragment) => fragment[NOTIFICATION_RESULT_KEY])
1646
1507
  })
1647
1508
  };
1648
- export { ARTIFACT_BRAND, ArtifactTypes, normalizeArtifactAccept, artifact, Artifact, exports_z, createPromptInputProxy, createPromptTemplateContext, renderPromptTemplate, isSecretLookingEnvName, Env, normalizeEnv, Repo, compileRepo, Runtime, compileEnvironment, isMcpHandle, defineMcp, resolveMcpChecks, compileMcps, compileStepErrors, compileStepRetry, compileStepMaxTurns, compileStepConcurrency, toStepHandle, toStepSpec, defineStep, codeStep, createStepDefinitionsClient, grantActionValues, grantScopeValues, Features, Notify };
1509
+ export { ARTIFACT_BRAND, ArtifactTypes, normalizeArtifactAccept, artifact, Artifact, exports_z, Repo, WorkBranch, compileRepo, assertBaseBranchFitsEnvironment, isMcpHandle, defineMcp, resolveMcpChecks, compileMcps, compileStepErrors, compileStepRetry, compileStepMaxTurns, compileStepConcurrency, toStepHandle, stepEnvironmentHandle, toStepSpec, defineStep, codeStep, createStepDefinitionsClient, grantActionValues, grantScopeValues, Features, Notify };
@@ -63,10 +63,20 @@ var inheritEnvVarSchema = exports_external.object({
63
63
  path: ["default"],
64
64
  message: "a secret cannot carry a default; it would be stored in plaintext"
65
65
  });
66
+ var secretEnvVarSchema = exports_external.object({
67
+ name: envVarNameSchema,
68
+ source: exports_external.literal("secret"),
69
+ secretName: envVarNameSchema,
70
+ applies: envVarAppliesSchema
71
+ }).strict();
66
72
  var envVarSpecSchema = exports_external.discriminatedUnion("source", [
67
73
  valueEnvVarSchema,
68
- inheritEnvVarSchema
74
+ inheritEnvVarSchema,
75
+ secretEnvVarSchema
69
76
  ]);
77
+ function isMaskedEnvVar(entry) {
78
+ return entry.source === "secret" || entry.secret;
79
+ }
70
80
  var envVarsSchema = exports_external.array(envVarSpecSchema).max(MAX_ENV_VARS).refine((entries) => new Set(entries.map((entry) => entry.name)).size === entries.length, { message: "environment variable names must be unique" });
71
81
  var storedEnvVarsSchema = exports_external.array(exports_external.discriminatedUnion("source", [
72
82
  exports_external.object({
@@ -85,7 +95,13 @@ var storedEnvVarsSchema = exports_external.array(exports_external.discriminatedU
85
95
  default: exports_external.string().optional(),
86
96
  mcp: exports_external.string().optional(),
87
97
  applies: exports_external.enum(envVarAppliesValues).default("agent")
98
+ }),
99
+ exports_external.object({
100
+ name: exports_external.string(),
101
+ source: exports_external.literal("secret"),
102
+ secretName: exports_external.string(),
103
+ applies: exports_external.enum(envVarAppliesValues).default("agent")
88
104
  })
89
105
  ]));
90
106
 
91
- export { ENV_VAR_NAME_PATTERN, RESERVED_ENV_VAR_NAMES, RESERVED_ENV_VAR_PREFIX, MAX_ENV_VARS, MAX_ENV_VAR_NAME_LENGTH, MAX_ENV_VAR_VALUE_LENGTH, containsInputToken, isReservedEnvVarName, envVarAppliesValues, appliesToAgent, appliesToSetup, isUninheritableWorkerEnvVarName, envVarSpecSchema, envVarsSchema, storedEnvVarsSchema };
107
+ export { ENV_VAR_NAME_PATTERN, RESERVED_ENV_VAR_NAMES, RESERVED_ENV_VAR_PREFIX, MAX_ENV_VARS, MAX_ENV_VAR_NAME_LENGTH, MAX_ENV_VAR_VALUE_LENGTH, containsInputToken, isReservedEnvVarName, envVarAppliesValues, appliesToAgent, appliesToSetup, isUninheritableWorkerEnvVarName, inheritEnvVarSchema, secretEnvVarSchema, envVarSpecSchema, isMaskedEnvVar, envVarsSchema, storedEnvVarsSchema };