@scarn/sdk 0.8.2 → 0.8.4

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 (66) hide show
  1. package/dist/automations/define-automation.d.ts +20 -0
  2. package/dist/automations/index.d.ts +8 -0
  3. package/dist/automations/index.js +21 -0
  4. package/dist/automations/targets.d.ts +36 -0
  5. package/dist/automations/types.d.ts +116 -0
  6. package/dist/{chunk-nb0nkt71.js → chunk-01nfqm18.js} +1 -0
  7. package/dist/chunk-0vzq22dj.js +73 -0
  8. package/dist/chunk-11hbmexe.js +250 -0
  9. package/dist/{chunk-2fn95pdd.js → chunk-3gy0cb5f.js} +5 -1
  10. package/dist/{chunk-qrasq5xe.js → chunk-43y7tfn4.js} +33 -414
  11. package/dist/chunk-61jf8b6s.js +53 -0
  12. package/dist/chunk-76d1bwwz.js +119 -0
  13. package/dist/chunk-8z1wa3kd.js +109 -0
  14. package/dist/{chunk-p7yrcmqm.js → chunk-cnxaagfj.js} +2 -52
  15. package/dist/{chunk-cdanncng.js → chunk-ejzfdm1z.js} +21 -5
  16. package/dist/{chunk-gds7w7zh.js → chunk-fgfhvsee.js} +1 -4
  17. package/dist/{chunk-x9788y82.js → chunk-hyaez4ee.js} +145 -16
  18. package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
  19. package/dist/{chunk-8pyhrdgy.js → chunk-wnfj3wyx.js} +55 -11
  20. package/dist/chunk-x0hjhqrf.js +416 -0
  21. package/dist/chunk-y11p1q7r.js +159 -0
  22. package/dist/client.js +4 -2
  23. package/dist/contracts/automation-document/index.d.ts +5 -0
  24. package/dist/contracts/automation-document/index.js +34 -0
  25. package/dist/contracts/automation-document/schema.d.ts +363 -0
  26. package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
  27. package/dist/contracts/pipeline-document/index.js +9 -7
  28. package/dist/contracts/pipeline-document/schema.d.ts +3 -3
  29. package/dist/contracts/work-item-changes.d.ts +6 -4
  30. package/dist/contracts/work-item-changes.js +2 -2
  31. package/dist/defaults/index.js +2 -2
  32. package/dist/definitions/automations/automations-client.d.ts +178 -0
  33. package/dist/definitions/automations/index.d.ts +1 -0
  34. package/dist/definitions/automations/index.js +12 -0
  35. package/dist/definitions/pipelines/index.d.ts +0 -1
  36. package/dist/definitions/pipelines/index.js +4 -12
  37. package/dist/definitions/pipelines/work-item-fields.d.ts +11 -22
  38. package/dist/definitions/steps/define-code-step.d.ts +8 -5
  39. package/dist/definitions/steps/define-step.d.ts +22 -11
  40. package/dist/definitions/steps/index.js +13 -6
  41. package/dist/definitions/steps/repo.d.ts +11 -3
  42. package/dist/definitions/steps/runtime.d.ts +11 -12
  43. package/dist/definitions/steps/step-definitions-client.d.ts +105 -3
  44. package/dist/definitions/steps/step-features.d.ts +89 -6
  45. package/dist/definitions/steps/step-handle.d.ts +6 -1
  46. package/dist/definitions/validation/index.js +2 -2
  47. package/dist/generated/index.d.ts +2 -2
  48. package/dist/generated/sdk.gen.d.ts +38 -6
  49. package/dist/generated/types.gen.d.ts +3026 -1889
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.js +44 -30
  52. package/dist/pipelines/define-pipeline.d.ts +7 -7
  53. package/dist/pipelines/handles.d.ts +0 -5
  54. package/dist/pipelines/index.js +7 -4
  55. package/dist/pipelines/types.d.ts +13 -1
  56. package/dist/push/collect-definitions.d.ts +3 -8
  57. package/dist/push/collect-pipeline-documents.d.ts +13 -3
  58. package/dist/push/index.d.ts +2 -2
  59. package/dist/push/index.js +87 -124
  60. package/dist/push/push-from-directory.d.ts +10 -6
  61. package/dist/repo-config.d.ts +14 -4
  62. package/dist/repo-config.js +5 -1
  63. package/dist/task-plane-client.d.ts +71 -1
  64. package/package.json +13 -1
  65. package/dist/chunk-ra53p0v8.js +0 -256
  66. package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +0 -263
@@ -0,0 +1,109 @@
1
+ // @bun
2
+ import {
3
+ PipelineDefinitions,
4
+ createClient
5
+ } from "./chunk-wnfj3wyx.js";
6
+ import {
7
+ exports_external
8
+ } from "./chunk-skzxcba3.js";
9
+
10
+ // src/definitions/pipelines/pipeline-definitions-client.ts
11
+ var pipelineDocumentIssueSchema = exports_external.object({
12
+ code: exports_external.string(),
13
+ path: exports_external.string(),
14
+ message: exports_external.string(),
15
+ hint: exports_external.string().optional()
16
+ });
17
+
18
+ class PipelineDefinitionsApiError extends Error {
19
+ code;
20
+ issues;
21
+ constructor(error) {
22
+ super(error.detail ?? error.title ?? JSON.stringify(error));
23
+ this.name = "PipelineDefinitionsApiError";
24
+ this.code = error.code;
25
+ this.issues = documentIssuesOf(error.meta);
26
+ }
27
+ }
28
+ function documentIssuesOf(meta) {
29
+ const errors = meta?.["errors"];
30
+ if (!Array.isArray(errors))
31
+ return [];
32
+ return errors.flatMap((error) => {
33
+ const parsed = pipelineDocumentIssueSchema.safeParse(error);
34
+ return parsed.success ? [parsed.data] : [];
35
+ });
36
+ }
37
+ function unwrap(result) {
38
+ if (result.error !== undefined) {
39
+ throw new PipelineDefinitionsApiError(result.error);
40
+ }
41
+ return result.data;
42
+ }
43
+ function createPipelineDefinitionsClient(baseUrl) {
44
+ const client = createClient({ baseUrl });
45
+ return buildPipelineDefinitionsClient(new PipelineDefinitions({ client }));
46
+ }
47
+ var buildPipelineDefinitionsClient = (pipelineDefinitions) => ({
48
+ listByProjectId: async (projectId, options) => unwrap(await pipelineDefinitions.listPipelineDefinitions({
49
+ path: { projectId },
50
+ headers: options?.headers
51
+ })),
52
+ get: async (pipelineDefinitionId, options) => unwrap(await pipelineDefinitions.getPipelineDefinition({
53
+ path: { pipelineDefinitionId },
54
+ headers: options?.headers
55
+ })),
56
+ create: async (input, options) => unwrap(await pipelineDefinitions.createPipelineDefinition({
57
+ body: input,
58
+ headers: options?.headers
59
+ })),
60
+ publishVersion: async (pipelineDefinitionId, document, options) => unwrap(await pipelineDefinitions.publishPipelineDefinitionVersion({
61
+ path: { pipelineDefinitionId },
62
+ body: { document },
63
+ headers: options?.headers
64
+ })),
65
+ activateVersion: async (pipelineDefinitionId, version, options) => unwrap(await pipelineDefinitions.activatePipelineDefinitionVersion({
66
+ path: { pipelineDefinitionId, version },
67
+ headers: options?.headers
68
+ })),
69
+ listVersions: async (pipelineDefinitionId, options) => unwrap(await pipelineDefinitions.listPipelineDefinitionVersions({
70
+ path: { pipelineDefinitionId },
71
+ headers: options?.headers
72
+ })),
73
+ getVersion: async (pipelineDefinitionId, version, options) => unwrap(await pipelineDefinitions.getPipelineDefinitionVersion({
74
+ path: { pipelineDefinitionId, version },
75
+ headers: options?.headers
76
+ }))
77
+ });
78
+ // src/definitions/pipelines/work-item-fields.ts
79
+ var WORK_ITEM_TOP_LEVEL_FIELDS = [
80
+ "id",
81
+ "projectId",
82
+ "platform",
83
+ "platformId",
84
+ "platformKey",
85
+ "url",
86
+ "title",
87
+ "description",
88
+ "sourceCreatedAt",
89
+ "sourceUpdatedAt",
90
+ "createdByUserId",
91
+ "parentWorkItemId",
92
+ "createdAt",
93
+ "updatedAt"
94
+ ];
95
+ var WORK_ITEM_FIELDS_PATH_PREFIX = "fields.";
96
+ function resolveWorkItemFieldPath(record, path) {
97
+ if (typeof record !== "object" || record === null)
98
+ return;
99
+ const asRecord = record;
100
+ if (path.startsWith(WORK_ITEM_FIELDS_PATH_PREFIX)) {
101
+ const fieldName = path.slice(WORK_ITEM_FIELDS_PATH_PREFIX.length);
102
+ const fields = asRecord["fields"];
103
+ if (typeof fields !== "object" || fields === null)
104
+ return;
105
+ return fields[fieldName];
106
+ }
107
+ return asRecord[path];
108
+ }
109
+ export { PipelineDefinitionsApiError, createPipelineDefinitionsClient, WORK_ITEM_TOP_LEVEL_FIELDS, WORK_ITEM_FIELDS_PATH_PREFIX, resolveWorkItemFieldPath };
@@ -3,30 +3,6 @@ import {
3
3
  exports_external
4
4
  } from "./chunk-skzxcba3.js";
5
5
 
6
- // src/contracts/pipeline-document/json.ts
7
- function isJsonObject(value) {
8
- return typeof value === "object" && value !== null && !Array.isArray(value);
9
- }
10
- function escapePointerSegment(segment) {
11
- return String(segment).replaceAll("~", "~0").replaceAll("/", "~1");
12
- }
13
- function jsonPointer(segments) {
14
- return segments.map((segment) => `/${escapePointerSegment(segment)}`).join("");
15
- }
16
- function deepEqual(left, right) {
17
- if (left === right) {
18
- return true;
19
- }
20
- if (Array.isArray(left)) {
21
- return Array.isArray(right) && left.length === right.length && left.every((item, index) => deepEqual(item, right[index]));
22
- }
23
- if (isJsonObject(left) && isJsonObject(right)) {
24
- const leftKeys = Object.keys(left);
25
- const rightKeys = Object.keys(right);
26
- return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
27
- }
28
- return false;
29
- }
30
6
  // src/contracts/pipeline-document/conditions/operators.ts
31
7
  var COMPARISON_OPERATORS = [
32
8
  "equal",
@@ -292,31 +268,5 @@ var pipelineDocumentSchema = exports_external.strictObject({
292
268
  function pipelineDocumentJsonSchema() {
293
269
  return exports_external.toJSONSchema(pipelineDocumentSchema, { io: "input" });
294
270
  }
295
- // src/contracts/pipeline-document/routes.ts
296
- function routeEntries(next) {
297
- if (next === undefined) {
298
- return [];
299
- }
300
- const entries = next.routes.map((route, index) => ({
301
- kind: "route",
302
- index,
303
- route,
304
- pointer: ["routes", index]
305
- }));
306
- if (next.otherwise !== undefined) {
307
- entries.push({
308
- kind: "otherwise",
309
- index: 0,
310
- route: next.otherwise,
311
- pointer: ["otherwise"]
312
- });
313
- }
314
- return entries;
315
- }
316
- function routeAt(next, kind, index) {
317
- if (next === undefined) {
318
- return;
319
- }
320
- return kind === "otherwise" ? next.otherwise : next.routes[index];
321
- }
322
- export { isJsonObject, jsonPointer, deepEqual, COMPARISON_OPERATORS, CONDITION_OPERATORS, COMPUTED_FUNCTIONS, ORDERING_OPERATORS, STRING_OPERATORS, DATE_OPERATORS, LIST_OPERATORS, NODE_ID_PATTERN, ALIAS_PATTERN, literalSchema, listSchema, argValueSchema, computedSourceSchema, conditionSchema, toleratedFailuresSchema, eachSchema, routeSchema, otherwiseSchema, startSchema, MATCH_MODES, nextSchema, retrySchema, catchSchema, stepNodeSchema, DEFAULT_MAX_TURNS, DECISION_BODY_MODES, decisionActionSchema, waitNodeSchema, succeedNodeSchema, failNodeSchema, nodeSchema, pipelineDocumentSchema, pipelineDocumentJsonSchema, routeEntries, routeAt };
271
+
272
+ export { COMPARISON_OPERATORS, CONDITION_OPERATORS, COMPUTED_FUNCTIONS, ORDERING_OPERATORS, STRING_OPERATORS, DATE_OPERATORS, LIST_OPERATORS, NODE_ID_PATTERN, ALIAS_PATTERN, literalSchema, listSchema, argValueSchema, computedSourceSchema, conditionSchema, toleratedFailuresSchema, eachSchema, routeSchema, otherwiseSchema, startSchema, MATCH_MODES, nextSchema, retrySchema, catchSchema, stepNodeSchema, DEFAULT_MAX_TURNS, DECISION_BODY_MODES, decisionActionSchema, waitNodeSchema, succeedNodeSchema, failNodeSchema, nodeSchema, pipelineDocumentSchema, pipelineDocumentJsonSchema };
@@ -7,22 +7,38 @@ import {
7
7
  var MAX_REPO_COMMIT_MESSAGE_LENGTH = 500;
8
8
  var REPO_COMMIT_MESSAGE_TOKEN_ROOTS = [
9
9
  "input",
10
- "result"
10
+ "result",
11
+ "workItem"
11
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
+ }
12
24
  var TOKEN_PATTERN = /\{\{([^}]+)\}\}/g;
13
25
  function findDisallowedCommitMessageTokenRoots(message) {
14
26
  const disallowed = [];
15
27
  for (const match of message.matchAll(TOKEN_PATTERN)) {
16
- const root = (match[1] ?? "").split(".")[0] ?? "";
17
- if (!REPO_COMMIT_MESSAGE_TOKEN_ROOTS.includes(root))
28
+ const path = match[1] ?? "";
29
+ const [root = "", ...rest] = path.split(".");
30
+ if (!REPO_COMMIT_MESSAGE_TOKEN_ROOTS.includes(root)) {
18
31
  disallowed.push(root);
32
+ } else if (root === "workItem" && (rest.length !== 1 || !REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS.includes(rest[0] ?? ""))) {
33
+ disallowed.push(path);
34
+ }
19
35
  }
20
36
  return disallowed;
21
37
  }
22
38
  var repoCommitMessageSchema = exports_external.string().max(MAX_REPO_COMMIT_MESSAGE_LENGTH).refine((message) => !/[\r\n]/.test(message), {
23
39
  message: "must be a single line"
24
40
  }).refine((message) => findDisallowedCommitMessageTokenRoots(message).length === 0, {
25
- message: `may only use {{${REPO_COMMIT_MESSAGE_TOKEN_ROOTS.join(".\u2026}}, {{")}.\u2026}} tokens`
41
+ message: `may only use {{input.\u2026}}, {{result.\u2026}}, {{${REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS.map((key) => `workItem.${key}`).join("}} and {{")}}} tokens`
26
42
  });
27
43
  var onPushFailureSchema = exports_external.enum(["fail", "warn"]);
28
44
  var repoConfigInputSchema = exports_external.discriminatedUnion("mode", [
@@ -71,4 +87,4 @@ function resolveRepoConfig(executionMode, input) {
71
87
  };
72
88
  }
73
89
 
74
- export { MAX_REPO_COMMIT_MESSAGE_LENGTH, REPO_COMMIT_MESSAGE_TOKEN_ROOTS, findDisallowedCommitMessageTokenRoots, repoCommitMessageSchema, repoConfigInputSchema, repoConfigSchema, REPO_RUNTIME_SUPPORT, repoRuntimeMismatch, resolveRepoConfig };
90
+ export { MAX_REPO_COMMIT_MESSAGE_LENGTH, REPO_COMMIT_MESSAGE_TOKEN_ROOTS, REPO_COMMIT_MESSAGE_WORK_ITEM_KEYS, commitMessageUsesWorkItem, findDisallowedCommitMessageTokenRoots, repoCommitMessageSchema, repoConfigInputSchema, repoConfigSchema, REPO_RUNTIME_SUPPORT, repoRuntimeMismatch, resolveRepoConfig };
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  repoConfigInputSchema,
14
14
  repoRuntimeMismatch
15
- } from "./chunk-cdanncng.js";
15
+ } from "./chunk-ejzfdm1z.js";
16
16
  import {
17
17
  findArtifactMarkers
18
18
  } from "./chunk-ngy1fdcx.js";
@@ -250,9 +250,6 @@ function checkManagedRuntime(step) {
250
250
  if (!isManagedRuntimeId(step.managedRuntime)) {
251
251
  problems.push(`unknown managed runtime; expected one of ${MANAGED_RUNTIME_IDS.join(", ")}`);
252
252
  }
253
- if (step.kind !== "code") {
254
- problems.push("managed runtimes are only supported for code steps. Use Runtime.devcontainer() or Runtime.host() for defineStep");
255
- }
256
253
  if (step.executionMode === "no_workspace") {
257
254
  problems.push('a managed runtime needs a workspace, but the step runs on the host (executionMode "no_workspace")');
258
255
  }
@@ -1,4 +1,11 @@
1
1
  // @bun
2
+ import {
3
+ collectEnvPlaceholderNames,
4
+ isEnvPlaceholderValue,
5
+ openCodeMcpLocalConfigSchema,
6
+ openCodeMcpRefConfigSchema,
7
+ openCodeMcpRemoteConfigSchema
8
+ } from "./chunk-e1h021kq.js";
2
9
  import {
3
10
  stepHealthChecksInputSchema,
4
11
  toolHealthCheckSchema
@@ -7,7 +14,7 @@ import {
7
14
  makeHandle,
8
15
  stepCall,
9
16
  stepNode
10
- } from "./chunk-mz53r914.js";
17
+ } from "./chunk-jj9pezwb.js";
11
18
  import {
12
19
  ENV_VAR_NAME_PATTERN,
13
20
  containsInputToken,
@@ -23,18 +30,11 @@ import {
23
30
  import {
24
31
  repoConfigInputSchema,
25
32
  repoRuntimeMismatch
26
- } from "./chunk-cdanncng.js";
27
- import {
28
- collectEnvPlaceholderNames,
29
- isEnvPlaceholderValue,
30
- openCodeMcpLocalConfigSchema,
31
- openCodeMcpRefConfigSchema,
32
- openCodeMcpRemoteConfigSchema
33
- } from "./chunk-e1h021kq.js";
33
+ } from "./chunk-ejzfdm1z.js";
34
34
  import {
35
35
  StepDefinitions,
36
36
  createClient
37
- } from "./chunk-8pyhrdgy.js";
37
+ } from "./chunk-wnfj3wyx.js";
38
38
  import {
39
39
  buildArtifactMarker
40
40
  } from "./chunk-ngy1fdcx.js";
@@ -43,7 +43,7 @@ import {
43
43
  } from "./chunk-y2pv8d6a.js";
44
44
  import {
45
45
  BUILT_IN_ERRORS
46
- } from "./chunk-nb0nkt71.js";
46
+ } from "./chunk-01nfqm18.js";
47
47
  import {
48
48
  $brand,
49
49
  $input,
@@ -736,7 +736,8 @@ function compileRepo(repo, runtime, ctx = {}) {
736
736
  return;
737
737
  const spec = typeof repo === "function" ? repo({
738
738
  input: createPromptInputProxy(["input"]),
739
- result: createPromptInputProxy(["result"])
739
+ result: createPromptInputProxy(["result"]),
740
+ workItem: createPromptInputProxy(["workItem"])
740
741
  }) : repo;
741
742
  const where = ctx.stepKey ? `Step "${ctx.stepKey}" repo` : "repo";
742
743
  const executionMode = executionModeOf(runtime);
@@ -1180,6 +1181,15 @@ function compileStepMaxTurns(stepKey, maxTurns) {
1180
1181
  }
1181
1182
  return maxTurns;
1182
1183
  }
1184
+ function compileStepConcurrency(stepKey, concurrency) {
1185
+ if (!Number.isInteger(concurrency.max) || concurrency.max < 1) {
1186
+ throw new Error(`Step "${stepKey}": concurrency max must be an integer of at least 1.`);
1187
+ }
1188
+ if (!Number.isInteger(concurrency.waiting) || concurrency.waiting < 0) {
1189
+ throw new Error(`Step "${stepKey}": concurrency waiting must be a non-negative integer.`);
1190
+ }
1191
+ return { max: concurrency.max, waiting: concurrency.waiting };
1192
+ }
1183
1193
  function toStepHandle(spec) {
1184
1194
  const node = stepNode(spec);
1185
1195
  const call = stepCall(node);
@@ -1208,10 +1218,29 @@ function assertStepMcpInput(config2) {
1208
1218
  const issues = parsed.error.issues.map((issue) => issue.path.length > 0 ? `${issue.path.map(String).join(".")}: ${issue.message}` : issue.message).join("; ");
1209
1219
  throw new Error(`Step "${config2.key}" healthChecks: ${issues}. MCP health checks are declared on the server with defineMcp({ healthChecks }).`);
1210
1220
  }
1221
+ function collectGrants(stepKey, features) {
1222
+ const grants = [];
1223
+ const seen = new Set;
1224
+ for (const feature of features) {
1225
+ const grant = feature._grant;
1226
+ if (!grant)
1227
+ continue;
1228
+ const key = `${grant.resource}:${grant.action}:${grant.scope}`;
1229
+ if (seen.has(key)) {
1230
+ throw new Error(`Step "${stepKey}": more than one Features.${grant.resource}s.${grant.action}({ scope: "${grant.scope}" }). Attach each work item grant once.`);
1231
+ }
1232
+ seen.add(key);
1233
+ grants.push("labels" in grant ? { ...grant, labels: [...grant.labels] } : { ...grant });
1234
+ }
1235
+ return grants;
1236
+ }
1211
1237
  function defineStep(config2) {
1212
1238
  const features = config2.features ?? [];
1239
+ const grants = collectGrants(config2.key, features);
1213
1240
  let effectiveResult = config2.result;
1214
1241
  for (const feature of features) {
1242
+ if (!feature._resultExtension)
1243
+ continue;
1215
1244
  effectiveResult = effectiveResult ? effectiveResult.extend(feature._resultExtension.shape) : feature._resultExtension;
1216
1245
  }
1217
1246
  const basePrompt = typeof config2.agentPrompt === "function" ? config2.agentPrompt(createPromptTemplateContext()) : config2.agentPrompt;
@@ -1257,7 +1286,10 @@ ${feature._promptAddition}` : feature._promptAddition;
1257
1286
  errors: compileStepErrors(config2.key, config2.errors),
1258
1287
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
1259
1288
  ...config2.maxTurns !== undefined ? { maxTurns: compileStepMaxTurns(config2.key, config2.maxTurns) } : {},
1260
- ...config2.workItemPermissions !== undefined ? { workItemPermissions: [...config2.workItemPermissions] } : {}
1289
+ ...config2.concurrency !== undefined ? {
1290
+ concurrency: compileStepConcurrency(config2.key, config2.concurrency)
1291
+ } : {},
1292
+ ...grants.length > 0 ? { grants } : {}
1261
1293
  };
1262
1294
  return toStepHandle(spec);
1263
1295
  }
@@ -1266,6 +1298,8 @@ function codeStep(config2) {
1266
1298
  const features = config2.features ?? [];
1267
1299
  let effectiveResult = config2.resultSchema;
1268
1300
  for (const feature of features) {
1301
+ if (!feature._resultExtension)
1302
+ continue;
1269
1303
  effectiveResult = effectiveResult ? effectiveResult.extend(feature._resultExtension.shape) : feature._resultExtension;
1270
1304
  }
1271
1305
  const {
@@ -1297,6 +1331,9 @@ function codeStep(config2) {
1297
1331
  ...repo !== undefined ? { repo } : {},
1298
1332
  errors: compileStepErrors(config2.key, config2.errors),
1299
1333
  retryJson: compileStepRetry(config2.key, config2.retry, config2.errors ?? []),
1334
+ ...config2.concurrency !== undefined ? {
1335
+ concurrency: compileStepConcurrency(config2.key, config2.concurrency)
1336
+ } : {},
1300
1337
  entrypoint: { fn: config2.fn }
1301
1338
  };
1302
1339
  return toStepHandle(spec);
@@ -1352,7 +1389,8 @@ var buildStepDefinitionsClient = (stepDefinitions) => {
1352
1389
  maxAttempts: entry.maxAttempts
1353
1390
  })),
1354
1391
  maxTurns: spec.maxTurns ?? null,
1355
- workItemPermissions: [...spec.workItemPermissions ?? []],
1392
+ concurrency: spec.concurrency ?? null,
1393
+ grants: (spec.grants ?? []).map((grant) => ({ ...grant })),
1356
1394
  status: spec.status,
1357
1395
  projectId
1358
1396
  };
@@ -1367,6 +1405,16 @@ var buildStepDefinitionsClient = (stepDefinitions) => {
1367
1405
  };
1368
1406
  };
1369
1407
  // src/definitions/steps/step-features.ts
1408
+ var grantActionValues = [
1409
+ "read",
1410
+ "update",
1411
+ "comment",
1412
+ "label",
1413
+ "block",
1414
+ "close",
1415
+ "create"
1416
+ ];
1417
+ var grantScopeValues = ["self", "children"];
1370
1418
  var notificationKindSchema = exports_external.enum([
1371
1419
  "feedback_request",
1372
1420
  "status_update",
@@ -1436,9 +1484,90 @@ var feedbackRequestsFeature = {
1436
1484
  ].join(`
1437
1485
  `)
1438
1486
  };
1487
+ var WORK_ITEM_TOOLS = {
1488
+ read: "scarn-get-work-item",
1489
+ update: "scarn-set-work-item-description",
1490
+ comment: "scarn-comment-on-work-item",
1491
+ label: "scarn-label-work-item",
1492
+ block: "scarn-block-work-item",
1493
+ close: "scarn-close-work-item",
1494
+ create: "scarn-create-work-item"
1495
+ };
1496
+ var WORK_ITEM_ACTION_TEXT = {
1497
+ read: "read",
1498
+ update: "replace the description of",
1499
+ comment: "comment on",
1500
+ label: "add or remove labels on",
1501
+ block: "mark as blocked",
1502
+ close: "close",
1503
+ create: "create"
1504
+ };
1505
+ var scopeText = (action, scope) => {
1506
+ if (action === "create")
1507
+ return "child work items of your work item";
1508
+ return scope === "self" ? "your work item" : "its child work items";
1509
+ };
1510
+ var scopeHeading = {
1511
+ self: "Your Work Item",
1512
+ children: "Child Work Items"
1513
+ };
1514
+ var actionHeading = {
1515
+ read: "Read",
1516
+ update: "Update",
1517
+ comment: "Comment on",
1518
+ label: "Label",
1519
+ block: "Block",
1520
+ close: "Close",
1521
+ create: "Create"
1522
+ };
1523
+ function workItemPrompt(grant) {
1524
+ const heading = grant.action === "create" ? "## Work Items: Create Child Work Items" : `## Work Items: ${actionHeading[grant.action]} ${scopeHeading[grant.scope]}`;
1525
+ const lines = [
1526
+ heading,
1527
+ "",
1528
+ `You may ${WORK_ITEM_ACTION_TEXT[grant.action]} ${scopeText(grant.action, grant.scope)}. Use the \`${WORK_ITEM_TOOLS[grant.action]}\` tool.`
1529
+ ];
1530
+ if (grant.action === "label" || grant.action === "create") {
1531
+ lines.push("", "Allowed labels:", ...grant.labels.map((label) => `- \`${label}\``), "", "Any other label is rejected.");
1532
+ }
1533
+ return lines.join(`
1534
+ `);
1535
+ }
1536
+ function workItemFeature(grant) {
1537
+ return { _grant: grant, _promptAddition: workItemPrompt(grant) };
1538
+ }
1539
+ var workItems = {
1540
+ read: ({ scope }) => workItemFeature({ resource: "workItem", action: "read", scope }),
1541
+ update: ({ scope }) => workItemFeature({ resource: "workItem", action: "update", scope }),
1542
+ comment: ({ scope }) => workItemFeature({
1543
+ resource: "workItem",
1544
+ action: "comment",
1545
+ scope
1546
+ }),
1547
+ block: ({ scope }) => workItemFeature({ resource: "workItem", action: "block", scope }),
1548
+ close: ({ scope }) => workItemFeature({ resource: "workItem", action: "close", scope }),
1549
+ label: ({
1550
+ scope,
1551
+ labels
1552
+ }) => workItemFeature({
1553
+ resource: "workItem",
1554
+ action: "label",
1555
+ scope,
1556
+ labels: [...labels]
1557
+ }),
1558
+ create: ({
1559
+ labels
1560
+ }) => workItemFeature({
1561
+ resource: "workItem",
1562
+ action: "create",
1563
+ scope: "children",
1564
+ labels: [...labels]
1565
+ })
1566
+ };
1439
1567
  var Features = {
1440
1568
  notifications: () => notificationsFeature,
1441
- feedbackRequests: () => feedbackRequestsFeature
1569
+ feedbackRequests: () => feedbackRequestsFeature,
1570
+ workItems
1442
1571
  };
1443
1572
  var Notify = {
1444
1573
  create: (item) => ({
@@ -1463,4 +1592,4 @@ var Notify = {
1463
1592
  [NOTIFICATION_RESULT_KEY]: fragments.flatMap((fragment) => fragment[NOTIFICATION_RESULT_KEY])
1464
1593
  })
1465
1594
  };
1466
- 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, toStepHandle, toStepSpec, defineStep, codeStep, createStepDefinitionsClient, Features, Notify };
1595
+ 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 };
@@ -1,121 +1,16 @@
1
1
  // @bun
2
- // src/pipelines/source.ts
3
- var FRAME = /\(?((?:file:\/\/)?[^\s()]+):(\d+):(\d+)\)?\s*$/;
4
- function sdkRoot() {
5
- const here = new URL(import.meta.url).pathname;
6
- const parts = here.split("/");
7
- return parts.slice(0, -2).join("/") + "/";
8
- }
9
- var SDK_ROOT = sdkRoot();
10
- function toPath(file) {
11
- return file.startsWith("file://") ? new URL(file).pathname : file;
12
- }
13
- function parseFrame(frame) {
14
- const match = FRAME.exec(frame.trim());
15
- if (match === null) {
16
- return null;
17
- }
18
- const [, file, line, column] = match;
19
- if (file === undefined || line === undefined || column === undefined) {
20
- return null;
21
- }
22
- return { file: toPath(file), line: Number(line), column: Number(column) };
23
- }
24
- function captureSite(stack = new Error().stack) {
25
- for (const frame of (stack ?? "").split(`
26
- `).slice(1)) {
27
- const site = parseFrame(frame);
28
- if (site !== null && !site.file.startsWith(SDK_ROOT) && !site.file.startsWith("node:") && site.file.includes("/")) {
29
- return site;
30
- }
31
- }
32
- return null;
33
- }
34
- function cwd() {
35
- const proc = globalThis.process;
36
- return typeof proc?.cwd === "function" ? proc.cwd() : null;
37
- }
38
- function formatSite(site) {
39
- if (site === null) {
40
- return "<unknown>";
41
- }
42
- const base = cwd();
43
- const file = base !== null && site.file.startsWith(`${base}/`) ? site.file.slice(base.length + 1) : site.file;
44
- return `${file}:${String(site.line)}`;
45
- }
46
-
47
- // src/pipelines/errors.ts
48
- function formatIssue(issue) {
49
- return `${formatSite(issue.site)} (${issue.pointer === "" ? "/" : issue.pointer}): ${issue.message}`;
50
- }
51
-
52
- class PipelineBuildError extends Error {
53
- issues;
54
- constructor(key, issues) {
55
- super(`Pipeline "${key}" has ${String(issues.length)} build error${issues.length === 1 ? "" : "s"}:
56
- ${issues.map((issue) => ` ${formatIssue(issue)}`).join(`
57
- `)}`);
58
- this.name = "PipelineBuildError";
59
- this.issues = issues;
60
- }
61
- }
62
-
63
- class AuthoringError extends Error {
64
- site;
65
- constructor(message, site = captureSite()) {
66
- super(message);
67
- this.name = "AuthoringError";
68
- this.site = site;
69
- }
70
- }
71
-
72
- // src/pipelines/registry.ts
73
- var nodes = new WeakMap;
74
- var targets = new WeakMap;
75
- var eaches = new WeakMap;
76
- var chains = new WeakMap;
77
- var pendingChains = new Set;
78
- function registerNode(value, node) {
79
- nodes.set(value, node);
80
- return value;
81
- }
82
- function registerTarget(value, target) {
83
- targets.set(value, target);
84
- return value;
85
- }
86
- function registerEach(value, each) {
87
- eaches.set(value, each);
88
- return value;
89
- }
90
- function registerChain(value, chain) {
91
- chains.set(value, chain);
92
- if (chain.next !== undefined) {
93
- pendingChains.add(chain);
94
- }
95
- return value;
96
- }
97
- function isObject(value) {
98
- return (typeof value === "object" || typeof value === "function") && value !== null;
99
- }
100
- function nodeOf(value) {
101
- return isObject(value) ? nodes.get(value) : undefined;
102
- }
103
- function targetOf(value) {
104
- return isObject(value) ? targets.get(value) : undefined;
105
- }
106
- function eachOf(value) {
107
- return isObject(value) ? eaches.get(value) : undefined;
108
- }
109
- function chainOf(value) {
110
- return isObject(value) ? chains.get(value) : undefined;
111
- }
112
- function requireNode(value, what) {
113
- const node = nodeOf(value);
114
- if (node === undefined) {
115
- throw new AuthoringError(`${what} must be a step, decision or reply handle`);
116
- }
117
- return node;
118
- }
2
+ import {
3
+ AuthoringError,
4
+ captureSite,
5
+ chainOf,
6
+ eachOf,
7
+ nodeOf,
8
+ registerChain,
9
+ registerNode,
10
+ registerTarget,
11
+ stepOn,
12
+ targetOf
13
+ } from "./chunk-y11p1q7r.js";
119
14
 
120
15
  // src/pipelines/model.ts
121
16
  function emptyChain(node) {
@@ -236,7 +131,15 @@ function checkArgs(node, args) {
236
131
  function targetFn(node) {
237
132
  return (args) => {
238
133
  checkArgs(node, args);
239
- return registerTarget(Object.freeze({ _tag: "pipeline_target", to: node.id }), { node, args, site: captureSite() });
134
+ const data = { node, args, site: captureSite() };
135
+ const value = { _tag: "pipeline_target", to: node.id };
136
+ if (node.kind === "step") {
137
+ Object.defineProperty(value, "on", {
138
+ value: stepOn(data),
139
+ enumerable: false
140
+ });
141
+ }
142
+ return registerTarget(Object.freeze(value), data);
240
143
  };
241
144
  }
242
145
  function partialFn(node) {
@@ -297,4 +200,4 @@ function bareStepHandle(source, local) {
297
200
  return stepHandleFor(stepNode(source, local));
298
201
  }
299
202
 
300
- export { captureSite, formatIssue, PipelineBuildError, AuthoringError, pendingChains, registerNode, registerTarget, registerEach, nodeOf, targetOf, eachOf, chainOf, requireNode, makeHandle, stepNode, stepCall, waitHandle, bareStepHandle };
203
+ export { makeHandle, stepNode, stepCall, waitHandle, bareStepHandle };