@scarn/sdk 0.8.15 → 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 (82) hide show
  1. package/dist/automations/index.js +4 -4
  2. package/dist/{chunk-4ggr8af6.js → chunk-098740f7.js} +1 -1
  3. package/dist/{chunk-1yb2h6t9.js → chunk-0c60x3v8.js} +53 -61
  4. package/dist/{chunk-y2pv8d6a.js → chunk-19brnwkp.js} +1 -1
  5. package/dist/{chunk-b8hxjwag.js → chunk-2tmrw253.js} +2 -2
  6. package/dist/{chunk-z25n32z0.js → chunk-3zp2qtf8.js} +88 -9
  7. package/dist/{chunk-k4y5qt4y.js → chunk-46wmsgv7.js} +1 -1
  8. package/dist/{chunk-ar6hcj1r.js → chunk-6tra3gw8.js} +7 -1
  9. package/dist/{chunk-zf4gwg0p.js → chunk-833ef6dg.js} +170 -269
  10. package/dist/{chunk-11hbmexe.js → chunk-9we3vqsv.js} +1 -1
  11. package/dist/{chunk-5zsavw98.js → chunk-aemxz9r7.js} +19 -3
  12. package/dist/{chunk-43y7tfn4.js → chunk-aknfw08j.js} +1 -1
  13. package/dist/chunk-e0pt5x0e.js +167 -0
  14. package/dist/{chunk-cnxaagfj.js → chunk-evb3hw48.js} +1 -1
  15. package/dist/chunk-mmy80pec.js +64 -0
  16. package/dist/chunk-mzj1j0p5.js +116 -0
  17. package/dist/{chunk-76d1bwwz.js → chunk-p1fs73bd.js} +2 -2
  18. package/dist/{chunk-e1h021kq.js → chunk-pqtd0hr7.js} +13 -3
  19. package/dist/chunk-qgkx89eg.js +210 -0
  20. package/dist/chunk-rphfy0fj.js +167 -0
  21. package/dist/chunk-t1dq2c2s.js +224 -0
  22. package/dist/{chunk-7bpy3w3z.js → chunk-tvjcfh6s.js} +5 -1
  23. package/dist/{chunk-63f90zky.js → chunk-y34zsgsw.js} +1 -1
  24. package/dist/{chunk-skzxcba3.js → chunk-yf15kdte.js} +7087 -1944
  25. package/dist/{chunk-efs789y2.js → chunk-ymywp5ht.js} +2 -2
  26. package/dist/client.js +8 -2
  27. package/dist/connectors/catalog.d.ts +49 -0
  28. package/dist/connectors/index.d.ts +45 -0
  29. package/dist/connectors/index.js +41 -0
  30. package/dist/contracts/artifacts.js +2 -2
  31. package/dist/contracts/automation-document/index.js +3 -3
  32. package/dist/contracts/pipeline-document/index.js +2 -2
  33. package/dist/contracts/step-artifact-submissions.js +2 -2
  34. package/dist/contracts/work-item-changes.js +1 -1
  35. package/dist/defaults/index.js +2 -2
  36. package/dist/definitions/automations/index.js +3 -3
  37. package/dist/definitions/environments/define-environment.d.ts +39 -0
  38. package/dist/definitions/environments/environments-client.d.ts +50 -0
  39. package/dist/definitions/environments/index.d.ts +6 -0
  40. package/dist/definitions/environments/index.js +97 -0
  41. package/dist/definitions/pipelines/index.js +3 -3
  42. package/dist/definitions/steps/compile-mcps.d.ts +8 -12
  43. package/dist/definitions/steps/define-code-step.d.ts +18 -11
  44. package/dist/definitions/steps/define-step.d.ts +14 -25
  45. package/dist/definitions/steps/env.d.ts +30 -8
  46. package/dist/definitions/steps/index.js +35 -18
  47. package/dist/definitions/steps/mcp-server-config.d.ts +19 -9
  48. package/dist/definitions/steps/repo.d.ts +56 -28
  49. package/dist/definitions/steps/runtime.d.ts +54 -39
  50. package/dist/definitions/steps/step-definitions-client.d.ts +222 -63
  51. package/dist/definitions/steps/step-handle.d.ts +8 -1
  52. package/dist/definitions/validation/index.js +10 -7
  53. package/dist/definitions/validation/validate-repo.d.ts +3 -7
  54. package/dist/definitions/validation/validate-runtime.d.ts +2 -7
  55. package/dist/devcontainer-config-path.js +2 -2
  56. package/dist/env-vars.d.ts +57 -1
  57. package/dist/env-vars.js +8 -2
  58. package/dist/environment.d.ts +564 -0
  59. package/dist/environment.js +46 -0
  60. package/dist/generated/index.d.ts +2 -2
  61. package/dist/generated/sdk.gen.d.ts +35 -10
  62. package/dist/generated/types.gen.d.ts +2151 -188
  63. package/dist/health-checks.d.ts +3 -3
  64. package/dist/health-checks.js +2 -2
  65. package/dist/index.d.ts +2 -0
  66. package/dist/index.js +100 -34
  67. package/dist/managed-runtimes.js +2 -2
  68. package/dist/opencode-mcp.d.ts +75 -4
  69. package/dist/opencode-mcp.js +3 -2
  70. package/dist/pipelines/index.js +3 -3
  71. package/dist/push/code-step-lookup.d.ts +6 -0
  72. package/dist/push/code-step-lookup.js +3 -1
  73. package/dist/push/collect-definitions.d.ts +13 -0
  74. package/dist/push/index.js +132 -20
  75. package/dist/push/push-from-directory.d.ts +11 -2
  76. package/dist/repo-config.d.ts +88 -30
  77. package/dist/repo-config.js +22 -6
  78. package/dist/resolve-environment.d.ts +19 -0
  79. package/dist/resolve-environment.js +19 -0
  80. package/dist/task-plane-client.d.ts +139 -22
  81. package/package.json +17 -1
  82. package/dist/chunk-xzx08r6y.js +0 -103
@@ -1,46 +1,56 @@
1
1
  // @bun
2
- import {
3
- collectEnvPlaceholderNames,
4
- isEnvPlaceholderValue,
5
- openCodeMcpLocalConfigSchema,
6
- openCodeMcpRefConfigSchema,
7
- openCodeMcpRemoteConfigSchema
8
- } from "./chunk-e1h021kq.js";
9
2
  import {
10
3
  stepHealthChecksInputSchema,
11
4
  toolHealthCheckSchema
12
- } from "./chunk-63f90zky.js";
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-5zsavw98.js";
22
+ describeBaseBranchEnvProblem,
23
+ findBaseBranchEnvProblems,
24
+ repoConfigInputSchema
25
+ } from "./chunk-rphfy0fj.js";
26
+ import {
27
+ DEFAULT_CODE_STEP_RUNTIME_ID
28
+ } from "./chunk-46wmsgv7.js";
23
29
  import {
24
- devcontainerConfigPathSchema
25
- } from "./chunk-4ggr8af6.js";
30
+ connectorMcpCollisionMessage,
31
+ findConnectorMcpCollisions
32
+ } from "./chunk-qgkx89eg.js";
26
33
  import {
27
- DEFAULT_CODE_STEP_RUNTIME_ID,
28
- MANAGED_RUNTIME_IDS
29
- } from "./chunk-k4y5qt4y.js";
34
+ collectEnvPlaceholderNames,
35
+ isEnvPlaceholderValue,
36
+ openCodeMcpLocalConfigSchema,
37
+ openCodeMcpRefConfigSchema,
38
+ openCodeMcpRemoteConfigSchema
39
+ } from "./chunk-pqtd0hr7.js";
30
40
  import {
31
- repoConfigInputSchema,
32
- repoRuntimeMismatch
33
- } from "./chunk-xzx08r6y.js";
41
+ ENV_VAR_NAME_PATTERN,
42
+ isReservedEnvVarName
43
+ } from "./chunk-aemxz9r7.js";
34
44
  import {
35
45
  StepDefinitions,
36
46
  createClient
37
- } from "./chunk-z25n32z0.js";
47
+ } from "./chunk-3zp2qtf8.js";
38
48
  import {
39
49
  buildArtifactMarker
40
50
  } from "./chunk-ngy1fdcx.js";
41
51
  import {
42
52
  ARTIFACT_SCHEMA_KEYWORD
43
- } from "./chunk-y2pv8d6a.js";
53
+ } from "./chunk-19brnwkp.js";
44
54
  import {
45
55
  BUILT_IN_ERRORS
46
56
  } from "./chunk-01nfqm18.js";
@@ -48,6 +58,7 @@ import {
48
58
  $brand,
49
59
  $input,
50
60
  $output,
61
+ INVALID,
51
62
  NEVER,
52
63
  TimePrecision,
53
64
  ZodAny,
@@ -63,6 +74,9 @@ import {
63
74
  ZodCUID2,
64
75
  ZodCatch,
65
76
  ZodCodec,
77
+ ZodCompileAsyncError,
78
+ ZodCompileUnsupportedError,
79
+ ZodCreditCard,
66
80
  ZodCustom,
67
81
  ZodCustomStringFormat,
68
82
  ZodDate,
@@ -78,12 +92,14 @@ import {
78
92
  ZodFirstPartyTypeKind,
79
93
  ZodFunction,
80
94
  ZodGUID,
95
+ ZodIBAN,
81
96
  ZodIPv4,
82
97
  ZodIPv6,
83
98
  ZodISODate,
84
99
  ZodISODateTime,
85
100
  ZodISODuration,
86
101
  ZodISOTime,
102
+ ZodInstanceOf,
87
103
  ZodIntersection,
88
104
  ZodIssueCode,
89
105
  ZodJWT,
@@ -154,6 +170,7 @@ import {
154
170
  _null,
155
171
  _overwrite,
156
172
  _positive,
173
+ _properties,
157
174
  _property,
158
175
  _regex,
159
176
  _size,
@@ -176,13 +193,17 @@ import {
176
193
  cidrv6,
177
194
  clone,
178
195
  codec,
196
+ compile,
179
197
  config,
198
+ creditCard,
180
199
  cuid,
181
200
  cuid2,
201
+ currencyCode,
182
202
  custom,
183
203
  date,
184
204
  decode,
185
205
  decodeAsync,
206
+ deepPartial,
186
207
  describe,
187
208
  discriminatedUnion,
188
209
  e164,
@@ -204,6 +225,7 @@ import {
204
225
  float64,
205
226
  formatError,
206
227
  fromJSONSchema,
228
+ getDiscriminatedOption,
207
229
  getErrorMap,
208
230
  globalRegistry,
209
231
  guid,
@@ -211,6 +233,8 @@ import {
211
233
  hex,
212
234
  hostname,
213
235
  httpUrl,
236
+ iban,
237
+ input,
214
238
  int,
215
239
  int32,
216
240
  int64,
@@ -228,6 +252,7 @@ import {
228
252
  looseRecord,
229
253
  mac,
230
254
  map,
255
+ memoizer,
231
256
  meta,
232
257
  nan,
233
258
  nanoid,
@@ -239,6 +264,7 @@ import {
239
264
  number,
240
265
  object,
241
266
  optional,
267
+ output,
242
268
  parse,
243
269
  parseAsync,
244
270
  partialRecord,
@@ -268,6 +294,7 @@ import {
268
294
  symbol,
269
295
  templateLiteral,
270
296
  toJSONSchema,
297
+ toZod,
271
298
  transform,
272
299
  treeifyError,
273
300
  tuple,
@@ -281,9 +308,12 @@ import {
281
308
  uuidv4,
282
309
  uuidv6,
283
310
  uuidv7,
311
+ validate,
312
+ validateAsync,
313
+ withParser,
284
314
  xid,
285
315
  xor
286
- } from "./chunk-skzxcba3.js";
316
+ } from "./chunk-yf15kdte.js";
287
317
  import {
288
318
  __export
289
319
  } from "./chunk-y64skrwp.js";
@@ -294,6 +324,7 @@ __export(exports_z, {
294
324
  $brand: () => $brand,
295
325
  $input: () => $input,
296
326
  $output: () => $output,
327
+ INVALID: () => INVALID,
297
328
  NEVER: () => NEVER,
298
329
  TimePrecision: () => TimePrecision,
299
330
  ZodAny: () => ZodAny,
@@ -309,6 +340,9 @@ __export(exports_z, {
309
340
  ZodCUID2: () => ZodCUID2,
310
341
  ZodCatch: () => ZodCatch,
311
342
  ZodCodec: () => ZodCodec,
343
+ ZodCompileAsyncError: () => ZodCompileAsyncError,
344
+ ZodCompileUnsupportedError: () => ZodCompileUnsupportedError,
345
+ ZodCreditCard: () => ZodCreditCard,
312
346
  ZodCustom: () => ZodCustom,
313
347
  ZodCustomStringFormat: () => ZodCustomStringFormat,
314
348
  ZodDate: () => ZodDate,
@@ -324,12 +358,14 @@ __export(exports_z, {
324
358
  ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
325
359
  ZodFunction: () => ZodFunction,
326
360
  ZodGUID: () => ZodGUID,
361
+ ZodIBAN: () => ZodIBAN,
327
362
  ZodIPv4: () => ZodIPv4,
328
363
  ZodIPv6: () => ZodIPv6,
329
364
  ZodISODate: () => ZodISODate,
330
365
  ZodISODateTime: () => ZodISODateTime,
331
366
  ZodISODuration: () => ZodISODuration,
332
367
  ZodISOTime: () => ZodISOTime,
368
+ ZodInstanceOf: () => ZodInstanceOf,
333
369
  ZodIntersection: () => ZodIntersection,
334
370
  ZodIssueCode: () => ZodIssueCode,
335
371
  ZodJWT: () => ZodJWT,
@@ -390,14 +426,18 @@ __export(exports_z, {
390
426
  clone: () => clone,
391
427
  codec: () => codec,
392
428
  coerce: () => exports_coerce,
429
+ compile: () => compile,
393
430
  config: () => config,
394
431
  core: () => exports_core,
432
+ creditCard: () => creditCard,
395
433
  cuid: () => cuid,
396
434
  cuid2: () => cuid2,
435
+ currencyCode: () => currencyCode,
397
436
  custom: () => custom,
398
437
  date: () => date,
399
438
  decode: () => decode,
400
439
  decodeAsync: () => decodeAsync,
440
+ deepPartial: () => deepPartial,
401
441
  describe: () => describe,
402
442
  discriminatedUnion: () => discriminatedUnion,
403
443
  e164: () => e164,
@@ -415,6 +455,7 @@ __export(exports_z, {
415
455
  formatError: () => formatError,
416
456
  fromJSONSchema: () => fromJSONSchema,
417
457
  function: () => _function,
458
+ getDiscriminatedOption: () => getDiscriminatedOption,
418
459
  getErrorMap: () => getErrorMap,
419
460
  globalRegistry: () => globalRegistry,
420
461
  gt: () => _gt,
@@ -424,7 +465,9 @@ __export(exports_z, {
424
465
  hex: () => hex,
425
466
  hostname: () => hostname,
426
467
  httpUrl: () => httpUrl,
468
+ iban: () => iban,
427
469
  includes: () => _includes,
470
+ input: () => input,
428
471
  instanceof: () => _instanceof,
429
472
  int: () => int,
430
473
  int32: () => int32,
@@ -451,6 +494,7 @@ __export(exports_z, {
451
494
  map: () => map,
452
495
  maxLength: () => _maxLength,
453
496
  maxSize: () => _maxSize,
497
+ memoizer: () => memoizer,
454
498
  meta: () => meta,
455
499
  mime: () => _mime,
456
500
  minLength: () => _minLength,
@@ -471,6 +515,7 @@ __export(exports_z, {
471
515
  number: () => number,
472
516
  object: () => object,
473
517
  optional: () => optional,
518
+ output: () => output,
474
519
  overwrite: () => _overwrite,
475
520
  parse: () => parse,
476
521
  parseAsync: () => parseAsync,
@@ -481,6 +526,7 @@ __export(exports_z, {
481
526
  preprocess: () => preprocess,
482
527
  prettifyError: () => prettifyError,
483
528
  promise: () => promise,
529
+ properties: () => _properties,
484
530
  property: () => _property,
485
531
  readonly: () => readonly,
486
532
  record: () => record,
@@ -510,6 +556,7 @@ __export(exports_z, {
510
556
  toJSONSchema: () => toJSONSchema,
511
557
  toLowerCase: () => _toLowerCase,
512
558
  toUpperCase: () => _toUpperCase,
559
+ toZod: () => toZod,
513
560
  transform: () => transform,
514
561
  treeifyError: () => treeifyError,
515
562
  trim: () => _trim,
@@ -527,7 +574,10 @@ __export(exports_z, {
527
574
  uuidv4: () => uuidv4,
528
575
  uuidv6: () => uuidv6,
529
576
  uuidv7: () => uuidv7,
577
+ validate: () => validate,
578
+ validateAsync: () => validateAsync,
530
579
  void: () => _void,
580
+ withParser: () => withParser,
531
581
  xid: () => xid,
532
582
  xor: () => xor,
533
583
  z: () => exports_external
@@ -596,131 +646,8 @@ var Artifact = {
596
646
  return buildArtifactMarker("link", toMarkerRef(target), options.label);
597
647
  }
598
648
  };
599
- // src/definitions/steps/prompt-template.ts
600
- function createPromptInputProxy(path = []) {
601
- const token = () => path.length ? `{{${path.join(".")}}}` : "";
602
- return new Proxy(Object.freeze({}), {
603
- get(_, key) {
604
- if (key === Symbol.toPrimitive || key === "valueOf") {
605
- return (_hint) => token();
606
- }
607
- if (key === "toString") {
608
- return () => token();
609
- }
610
- if (typeof key !== "string")
611
- return;
612
- return createPromptInputProxy([...path, key]);
613
- }
614
- });
615
- }
616
- function createPromptTemplateContext() {
617
- return {
618
- input: createPromptInputProxy(["input"]),
619
- env: createPromptInputProxy(["env"]),
620
- scarn: {
621
- artifactsDir: createPromptInputProxy([
622
- "scarn",
623
- "artifactsDir"
624
- ])
625
- }
626
- };
627
- }
628
- function renderPromptTemplate(template, contextJson) {
629
- return template.replace(/\{\{([^}]+)\}\}/g, (_, path) => {
630
- const value = path.split(".").reduce((curr, key) => curr != null ? curr[key] : undefined, contextJson);
631
- return value != null ? String(value) : "";
632
- });
633
- }
634
-
635
- // src/definitions/steps/env.ts
636
- var SECRET_LOOKING_NAME = /SECRET|TOKEN|PASSWORD|PASSWD|API_?KEY|PRIVATE/i;
637
- function isSecretLookingEnvName(name) {
638
- return SECRET_LOOKING_NAME.test(name);
639
- }
640
- var helperEntries = new WeakSet;
641
- function brand(entry) {
642
- helperEntries.add(entry);
643
- return entry;
644
- }
645
- var Env = {
646
- value(opts) {
647
- return brand({
648
- kind: "value",
649
- value: opts.value,
650
- secret: opts.secret ?? false,
651
- unsafeAllowStatic: opts.unsafeAllowStatic ?? false,
652
- applies: opts.applies ?? "agent"
653
- });
654
- },
655
- inherit(opts) {
656
- return brand({
657
- kind: "inherit",
658
- from: opts?.from,
659
- secret: opts?.secret ?? false,
660
- optional: opts?.optional ?? false,
661
- default: opts?.default,
662
- applies: opts?.applies ?? "agent"
663
- });
664
- }
665
- };
666
- function isHelperEntry(entry) {
667
- return typeof entry === "object" && helperEntries.has(entry);
668
- }
669
- function assertNotStaticSecret(name, value, flags) {
670
- if (containsInputToken(value))
671
- return;
672
- if (flags.secret) {
673
- 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.`);
674
- }
675
- if (isSecretLookingEnvName(name) && !flags.unsafeAllowStatic) {
676
- 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.`);
677
- }
678
- }
679
- function appliesField(applies) {
680
- return applies === "agent" ? {} : { applies };
681
- }
682
- function toEnvVarSpec(name, entry) {
683
- if (!isHelperEntry(entry)) {
684
- const value = `${entry}`;
685
- assertNotStaticSecret(name, value, {
686
- secret: false,
687
- unsafeAllowStatic: false
688
- });
689
- return { name, source: "value", value, secret: false };
690
- }
691
- if (entry.kind === "value") {
692
- assertNotStaticSecret(name, entry.value, entry);
693
- return {
694
- name,
695
- source: "value",
696
- value: entry.value,
697
- secret: entry.secret,
698
- ...appliesField(entry.applies)
699
- };
700
- }
701
- return {
702
- name,
703
- source: "inherit",
704
- from: entry.from ?? name,
705
- secret: entry.secret,
706
- optional: entry.optional,
707
- ...entry.default !== undefined ? { default: entry.default } : {},
708
- ...appliesField(entry.applies)
709
- };
710
- }
711
- function normalizeEnv(fn) {
712
- if (!fn)
713
- return null;
714
- const record2 = fn({ input: createPromptInputProxy(["input"]) });
715
- const specs = Object.entries(record2).map(([name, entry]) => toEnvVarSpec(name, entry));
716
- return specs.length > 0 ? specs : null;
717
- }
718
-
719
649
  // src/definitions/steps/repo.ts
720
650
  var Repo = {
721
- none() {
722
- return { mode: "none" };
723
- },
724
651
  readOnly(opts) {
725
652
  return { mode: "readOnly", ...opts };
726
653
  },
@@ -728,23 +655,24 @@ var Repo = {
728
655
  return { mode: "readWrite", ...opts };
729
656
  }
730
657
  };
731
- function executionModeOf(runtime) {
732
- return runtime?.kind === "host" ? "no_workspace" : "workspace";
733
- }
734
- 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 = {}) {
735
667
  if (repo === undefined)
736
668
  return;
737
669
  const spec = typeof repo === "function" ? repo({
738
670
  input: createPromptInputProxy(["input"]),
739
671
  result: createPromptInputProxy(["result"]),
740
- workItem: createPromptInputProxy(["workItem"])
672
+ workItem: createPromptInputProxy(["workItem"]),
673
+ env: createPromptInputProxy(["env"])
741
674
  }) : repo;
742
675
  const where = ctx.stepKey ? `Step "${ctx.stepKey}" repo` : "repo";
743
- const executionMode = executionModeOf(runtime);
744
- const mismatch = repoRuntimeMismatch(executionMode, spec.mode);
745
- if (mismatch !== null) {
746
- throw new Error(`${where} "${spec.mode}" cannot be used with executionMode "${executionMode}": ${mismatch}.`);
747
- }
748
676
  const config2 = toRepoConfigInput(spec);
749
677
  const parsed = repoConfigInputSchema.safeParse(config2);
750
678
  if (!parsed.success) {
@@ -753,61 +681,46 @@ function compileRepo(repo, runtime, ctx = {}) {
753
681
  return config2;
754
682
  }
755
683
  function toRepoConfigInput(spec) {
756
- if (spec.mode === "readWrite")
757
- return toReadWriteConfig(spec);
758
- if (spec.mode === "readOnly")
759
- return { mode: "readOnly", ...gitCredentialsOf(spec) };
760
- 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("; ")}`);
761
705
  }
762
706
  function gitCredentialsOf(spec) {
763
707
  return spec.gitCredentials !== undefined ? { gitCredentials: spec.gitCredentials } : {};
764
708
  }
709
+ function branchOptsOf(spec) {
710
+ return spec.baseBranch !== undefined ? {
711
+ baseBranch: `${spec.baseBranch}`
712
+ } : {};
713
+ }
765
714
  function toReadWriteConfig(spec) {
766
715
  return {
767
716
  mode: "readWrite",
768
717
  ...gitCredentialsOf(spec),
718
+ ...branchOptsOf(spec),
769
719
  ...spec.message !== undefined ? {
770
720
  message: `${spec.message}`
771
721
  } : {},
772
- ...spec.onPushFailure !== undefined ? { onPushFailure: spec.onPushFailure } : {}
773
- };
774
- }
775
-
776
- // src/definitions/steps/runtime.ts
777
- var managedRuntimeFactories = Object.fromEntries(MANAGED_RUNTIME_IDS.map((id) => [id, () => ({ kind: "managed", id })]));
778
- var Runtime = {
779
- managed: managedRuntimeFactories,
780
- devcontainer(opts) {
781
- if (opts?.config === undefined)
782
- return { kind: "devcontainer" };
783
- const parsed = devcontainerConfigPathSchema.safeParse(opts.config);
784
- if (!parsed.success) {
785
- throw new Error(`Runtime.devcontainer config "${opts.config}": ${parsed.error.issues.map((issue) => issue.message).join("; ")}`);
786
- }
787
- return { kind: "devcontainer", config: parsed.data };
788
- },
789
- host() {
790
- return { kind: "host" };
791
- }
792
- };
793
- function assertNoSetupVarsOnHost(envJson, runtime, stepKey) {
794
- if (runtime?.kind !== "host")
795
- return;
796
- const setupVar = (envJson ?? []).find((entry) => (entry.applies ?? "agent") !== "agent");
797
- if (!setupVar)
798
- return;
799
- 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().`);
800
- }
801
- function compileEnvironment(environment, ctx = {}) {
802
- const runtime = environment?.runtime ?? ctx.defaultRuntime;
803
- const envJson = normalizeEnv(environment?.vars);
804
- assertNoSetupVarsOnHost(envJson, runtime, ctx.stepKey);
805
- return {
806
- executionMode: runtime?.kind === "host" ? "no_workspace" : "workspace",
807
- devcontainerConfigPath: runtime?.kind === "devcontainer" ? runtime.config ?? null : null,
808
- managedRuntime: runtime?.kind === "managed" ? runtime.id : null,
809
- envJson,
810
- repo: compileRepo(environment?.repo, runtime, ctx)
722
+ ...spec.onPushFailure !== undefined ? { onPushFailure: spec.onPushFailure } : {},
723
+ ...spec.workBranch !== undefined ? { workBranch: spec.workBranch } : {}
811
724
  };
812
725
  }
813
726
 
@@ -1049,17 +962,20 @@ function resolveMcpChecks(handle) {
1049
962
 
1050
963
  // src/definitions/steps/compile-mcps.ts
1051
964
  function compileServer(key, handle) {
965
+ const workerVars = compileEnv(key, handle);
966
+ const metadata = workerVars.length > 0 ? { workerVars } : {};
1052
967
  switch (handle.type) {
1053
968
  case "ref":
1054
969
  return {
1055
970
  type: "ref",
1056
971
  ...handle.name !== key ? { name: handle.name } : {},
1057
- ...structuredClone(handle.server)
972
+ ...structuredClone(handle.server),
973
+ ...metadata
1058
974
  };
1059
975
  case "local":
1060
- return { type: "local", ...structuredClone(handle.server) };
976
+ return { type: "local", ...structuredClone(handle.server), ...metadata };
1061
977
  case "remote":
1062
- return { type: "remote", ...structuredClone(handle.server) };
978
+ return { type: "remote", ...structuredClone(handle.server), ...metadata };
1063
979
  }
1064
980
  }
1065
981
  function compileChecks(key, handle) {
@@ -1092,30 +1008,10 @@ function compileEnv(key, handle) {
1092
1008
  ...handle.optionalEnv.map((name) => entry(name, true))
1093
1009
  ];
1094
1010
  }
1095
- function dedupeEnv(entries) {
1096
- const byName = new Map;
1097
- for (const entry of entries) {
1098
- const existing = byName.get(entry.name);
1099
- if (!existing) {
1100
- byName.set(entry.name, entry);
1101
- continue;
1102
- }
1103
- byName.set(entry.name, {
1104
- source: "inherit",
1105
- name: entry.name,
1106
- from: entry.from,
1107
- secret: true,
1108
- optional: existing.optional && entry.optional,
1109
- applies: "agent"
1110
- });
1111
- }
1112
- return [...byName.values()];
1113
- }
1114
1011
  function compileMcps(mcps, stepKey) {
1115
1012
  const compiled = {
1116
1013
  opencodeMcpJson: {},
1117
- healthChecks: [],
1118
- envEntries: []
1014
+ healthChecks: []
1119
1015
  };
1120
1016
  for (const [key, handle] of Object.entries(mcps)) {
1121
1017
  if (!isMcpHandle(handle)) {
@@ -1123,35 +1019,36 @@ function compileMcps(mcps, stepKey) {
1123
1019
  }
1124
1020
  compiled.opencodeMcpJson[key] = compileServer(key, handle);
1125
1021
  compiled.healthChecks.push(...compileChecks(key, handle));
1126
- compiled.envEntries.push(...compileEnv(key, handle));
1127
1022
  }
1128
- compiled.envEntries = dedupeEnv(compiled.envEntries);
1129
1023
  return compiled;
1130
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
+ }
1131
1033
  function nonEmpty(items) {
1132
1034
  return items.length > 0 ? items : null;
1133
1035
  }
1134
- function mergeStepMcps(stepKey, input) {
1135
- if (!input.mcps || Object.keys(input.mcps).length === 0) {
1036
+ function mergeStepMcps(stepKey, input2) {
1037
+ if (!input2.mcps || Object.keys(input2.mcps).length === 0) {
1136
1038
  return {
1137
1039
  opencodeMcpJson: null,
1138
- healthChecksJson: input.healthChecks ?? null,
1139
- envJson: input.envJson
1040
+ healthChecksJson: input2.healthChecks ?? null,
1041
+ envJson: input2.envJson
1140
1042
  };
1141
1043
  }
1142
- const compiled = compileMcps(input.mcps, stepKey);
1143
- const stepVars = input.envJson ?? [];
1144
- const stepVarNames = new Set(stepVars.map((entry) => entry.name));
1044
+ const compiled = compileMcps(input2.mcps, stepKey);
1145
1045
  return {
1146
1046
  opencodeMcpJson: compiled.opencodeMcpJson,
1147
1047
  healthChecksJson: nonEmpty([
1148
1048
  ...compiled.healthChecks,
1149
- ...input.healthChecks ?? []
1049
+ ...input2.healthChecks ?? []
1150
1050
  ]),
1151
- envJson: nonEmpty([
1152
- ...compiled.envEntries.filter((entry) => !stepVarNames.has(entry.name)),
1153
- ...stepVars
1154
- ])
1051
+ envJson: input2.envJson
1155
1052
  };
1156
1053
  }
1157
1054
 
@@ -1201,7 +1098,7 @@ function compileStepConcurrency(stepKey, concurrency) {
1201
1098
  }
1202
1099
  return { max: concurrency.max, waiting: concurrency.waiting };
1203
1100
  }
1204
- function toStepHandle(spec) {
1101
+ function toStepHandle(spec, environmentHandle) {
1205
1102
  const node = stepNode(spec);
1206
1103
  const call = stepCall(node);
1207
1104
  const { name, ...rest } = spec;
@@ -1210,8 +1107,22 @@ function toStepHandle(spec) {
1210
1107
  enumerable: true
1211
1108
  });
1212
1109
  Object.assign(call, rest);
1110
+ if (environmentHandle !== undefined) {
1111
+ Object.defineProperty(call, "environmentHandle", {
1112
+ value: environmentHandle,
1113
+ enumerable: false
1114
+ });
1115
+ }
1213
1116
  return makeHandle(call, node);
1214
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
+ }
1215
1126
  function toStepSpec(step) {
1216
1127
  return { ...step };
1217
1128
  }
@@ -1263,18 +1174,17 @@ function defineStep(config2) {
1263
1174
  ${feature._promptAddition}` : feature._promptAddition;
1264
1175
  }
1265
1176
  }
1266
- const {
1267
- executionMode,
1268
- devcontainerConfigPath,
1269
- managedRuntime,
1270
- envJson,
1271
- repo
1272
- } = 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 });
1273
1182
  assertStepMcpInput(config2);
1183
+ assertNoConnectorMcpCollisions(config2.key, config2.environment, config2.mcps);
1274
1184
  const mcpFields = mergeStepMcps(config2.key, {
1275
1185
  mcps: config2.mcps,
1276
1186
  healthChecks: config2.healthChecks,
1277
- envJson
1187
+ envJson: environment?.kind === "inline" ? environment.envJson : null
1278
1188
  });
1279
1189
  const resultSchemaJson = effectiveResult ? toJSONSchema(effectiveResult) : null;
1280
1190
  const spec = {
@@ -1284,15 +1194,12 @@ ${feature._promptAddition}` : feature._promptAddition;
1284
1194
  version: config2.version ?? 1,
1285
1195
  kind: "user_defined",
1286
1196
  status: config2.status ?? "active",
1287
- executionMode,
1288
- devcontainerConfigPath,
1289
- ...managedRuntime !== null ? { managedRuntime } : {},
1197
+ environment,
1290
1198
  prompt: effectivePrompt,
1291
1199
  inputSchemaJson: config2.input ? toJSONSchema(config2.input) : null,
1292
1200
  resultSchemaJson,
1293
1201
  opencodeMcpJson: mcpFields.opencodeMcpJson,
1294
1202
  healthChecksJson: mcpFields.healthChecksJson,
1295
- envJson: mcpFields.envJson,
1296
1203
  ...repo !== undefined ? { repo } : {},
1297
1204
  errors: compileStepErrors(config2.key, config2.errors),
1298
1205
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
@@ -1302,7 +1209,7 @@ ${feature._promptAddition}` : feature._promptAddition;
1302
1209
  } : {},
1303
1210
  ...grants.length > 0 ? { grants } : {}
1304
1211
  };
1305
- return toStepHandle(spec);
1212
+ return toStepHandle(spec, isEnvironmentHandle(config2.environment) ? config2.environment : undefined);
1306
1213
  }
1307
1214
  // src/definitions/steps/define-code-step.ts
1308
1215
  function codeStep(config2) {
@@ -1313,16 +1220,16 @@ function codeStep(config2) {
1313
1220
  continue;
1314
1221
  effectiveResult = effectiveResult ? effectiveResult.extend(feature._resultExtension.shape) : feature._resultExtension;
1315
1222
  }
1316
- const {
1317
- executionMode,
1318
- devcontainerConfigPath,
1319
- managedRuntime,
1320
- envJson,
1321
- repo
1322
- } = 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, {
1323
1228
  stepKey: config2.key,
1324
1229
  defaultRuntime: Runtime.managed[DEFAULT_CODE_STEP_RUNTIME_ID]()
1325
1230
  });
1231
+ const repo = compileRepo(config2.repo, { stepKey: config2.key });
1232
+ assertBaseBranchFitsEnvironment(repo, knownEnvironmentVars(config2.environment, environment), { stepKey: config2.key });
1326
1233
  const spec = {
1327
1234
  key: config2.key,
1328
1235
  name: config2.name,
@@ -1330,15 +1237,12 @@ function codeStep(config2) {
1330
1237
  version: config2.version ?? 1,
1331
1238
  kind: "code",
1332
1239
  status: config2.status ?? "active",
1333
- executionMode,
1334
- devcontainerConfigPath,
1335
- managedRuntime,
1240
+ environment,
1336
1241
  prompt: null,
1337
1242
  inputSchemaJson: config2.inputSchema ? toJSONSchema(config2.inputSchema) : null,
1338
1243
  resultSchemaJson: effectiveResult ? toJSONSchema(effectiveResult) : null,
1339
1244
  opencodeMcpJson: null,
1340
1245
  healthChecksJson: null,
1341
- envJson,
1342
1246
  ...repo !== undefined ? { repo } : {},
1343
1247
  errors: compileStepErrors(config2.key, config2.errors),
1344
1248
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
@@ -1347,7 +1251,7 @@ function codeStep(config2) {
1347
1251
  } : {},
1348
1252
  entrypoint: { fn: config2.fn }
1349
1253
  };
1350
- return toStepHandle(spec);
1254
+ return toStepHandle(spec, environmentHandle);
1351
1255
  }
1352
1256
  // src/definitions/steps/step-definitions-client.ts
1353
1257
  var ANY_OBJECT_SCHEMA = { type: "object" };
@@ -1385,15 +1289,12 @@ var buildStepDefinitionsClient = (stepDefinitions) => {
1385
1289
  version: spec.version,
1386
1290
  kind: spec.kind,
1387
1291
  entrypointJson: spec.entrypointJson ?? null,
1388
- executionMode: spec.executionMode,
1389
- devcontainerConfigPath: spec.devcontainerConfigPath,
1390
- managedRuntime: spec.managedRuntime,
1292
+ environment: spec.environment,
1391
1293
  repo: spec.repo,
1392
1294
  inputSchemaJson: spec.inputSchemaJson ?? ANY_OBJECT_SCHEMA,
1393
1295
  resultSchemaJson: spec.kind === "code" ? spec.resultSchemaJson ?? ANY_OBJECT_SCHEMA : spec.resultSchemaJson,
1394
1296
  opencodeMcpJson: spec.opencodeMcpJson,
1395
1297
  healthChecksJson: spec.healthChecksJson,
1396
- envJson: spec.envJson,
1397
1298
  errors: [...spec.errors ?? []],
1398
1299
  retry: (spec.retryJson ?? []).map((entry) => ({
1399
1300
  on: [...entry.on],
@@ -1605,4 +1506,4 @@ var Notify = {
1605
1506
  [NOTIFICATION_RESULT_KEY]: fragments.flatMap((fragment) => fragment[NOTIFICATION_RESULT_KEY])
1606
1507
  })
1607
1508
  };
1608
- 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 };