@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
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./contracts/artifact-markers";
5
5
  export * from "./definitions/steps";
6
6
  export * from "./definitions/pipelines";
7
7
  export * from "./pipelines";
8
+ export * from "./automations";
8
9
  export type { PipelineDefinition } from "./pipelines";
9
10
  export * from "./opencode-mcp";
10
11
  export * from "./jsonc";
package/dist/index.js CHANGED
@@ -3,6 +3,13 @@ import {
3
3
  SCARN_CONFIG_RELATIVE_PATH,
4
4
  parseScarnConfig
5
5
  } from "./chunk-0y2fy5en.js";
6
+ import {
7
+ PipelineDefinitionsApiError,
8
+ WORK_ITEM_FIELDS_PATH_PREFIX,
9
+ WORK_ITEM_TOP_LEVEL_FIELDS,
10
+ createPipelineDefinitionsClient,
11
+ resolveWorkItemFieldPath
12
+ } from "./chunk-8z1wa3kd.js";
6
13
  import {
7
14
  after,
8
15
  all,
@@ -38,28 +45,26 @@ import {
38
45
  sum,
39
46
  workItem,
40
47
  workItemField
41
- } from "./chunk-qrasq5xe.js";
48
+ } from "./chunk-43y7tfn4.js";
49
+ import {
50
+ attach,
51
+ defineAutomation,
52
+ onEvent,
53
+ skip
54
+ } from "./chunk-11hbmexe.js";
55
+ import"./chunk-x0hjhqrf.js";
56
+ import"./chunk-76d1bwwz.js";
42
57
  import {
43
58
  parseJsonc,
44
59
  stripJsoncComments,
45
60
  stripTrailingCommas
46
61
  } from "./chunk-rt9tq4j6.js";
47
- import {
48
- DEFAULT_PIPELINE_ASSIGNMENT_FILENAME,
49
- PipelineDefinitionsApiError,
50
- WORK_ITEM_FIELDS_PATH_PREFIX,
51
- WORK_ITEM_TOP_LEVEL_FIELDS,
52
- createPipelineDefinitionsClient,
53
- defaultPipelineAssignment,
54
- isDefaultPipelineAssignmentSpec,
55
- resolveWorkItemFieldPath,
56
- serializeDefaultPipelineAssignment
57
- } from "./chunk-ra53p0v8.js";
58
62
  import {
59
63
  createScarnClient,
60
64
  createTaskPlaneClient
61
- } from "./chunk-2fn95pdd.js";
62
- import"./chunk-p7yrcmqm.js";
65
+ } from "./chunk-3gy0cb5f.js";
66
+ import"./chunk-61jf8b6s.js";
67
+ import"./chunk-cnxaagfj.js";
63
68
  import {
64
69
  ARTIFACT_BRAND,
65
70
  Artifact,
@@ -74,6 +79,7 @@ import {
74
79
  compileEnvironment,
75
80
  compileMcps,
76
81
  compileRepo,
82
+ compileStepConcurrency,
77
83
  compileStepErrors,
78
84
  compileStepMaxTurns,
79
85
  compileStepRetry,
@@ -83,6 +89,8 @@ import {
83
89
  defineMcp,
84
90
  defineStep,
85
91
  exports_z,
92
+ grantActionValues,
93
+ grantScopeValues,
86
94
  isMcpHandle,
87
95
  isSecretLookingEnvName,
88
96
  normalizeArtifactAccept,
@@ -91,16 +99,7 @@ import {
91
99
  resolveMcpChecks,
92
100
  toStepHandle,
93
101
  toStepSpec
94
- } from "./chunk-x9788y82.js";
95
- import"./chunk-63f90zky.js";
96
- import {
97
- PipelineBuildError,
98
- formatIssue
99
- } from "./chunk-mz53r914.js";
100
- import"./chunk-5zsavw98.js";
101
- import"./chunk-4ggr8af6.js";
102
- import"./chunk-k4y5qt4y.js";
103
- import"./chunk-cdanncng.js";
102
+ } from "./chunk-hyaez4ee.js";
104
103
  import {
105
104
  collectEnvPlaceholderNames,
106
105
  isEnvPlaceholderValue,
@@ -115,8 +114,19 @@ import {
115
114
  openCodeResolvedMcpServerConfigSchema,
116
115
  openCodeResolvedMcpServersSchema
117
116
  } from "./chunk-e1h021kq.js";
117
+ import"./chunk-63f90zky.js";
118
+ import"./chunk-jj9pezwb.js";
119
+ import {
120
+ PipelineBuildError,
121
+ formatIssue
122
+ } from "./chunk-y11p1q7r.js";
123
+ import"./chunk-5zsavw98.js";
124
+ import"./chunk-4ggr8af6.js";
125
+ import"./chunk-k4y5qt4y.js";
126
+ import"./chunk-ejzfdm1z.js";
118
127
  import {
119
128
  Api,
129
+ Automations,
120
130
  Billing,
121
131
  Conversations,
122
132
  GitHubIntegrations,
@@ -139,7 +149,7 @@ import {
139
149
  WorkItemCommentDrafts,
140
150
  WorkItemComments,
141
151
  WorkItems
142
- } from "./chunk-8pyhrdgy.js";
152
+ } from "./chunk-wnfj3wyx.js";
143
153
  import {
144
154
  ARTIFACT_MARKER_SCHEME,
145
155
  buildArtifactMarker,
@@ -159,7 +169,7 @@ import {
159
169
  matchArtifactNode,
160
170
  readArtifactKeyword
161
171
  } from "./chunk-y2pv8d6a.js";
162
- import"./chunk-nb0nkt71.js";
172
+ import"./chunk-01nfqm18.js";
163
173
  import"./chunk-skzxcba3.js";
164
174
  import"./chunk-y64skrwp.js";
165
175
  export {
@@ -169,9 +179,9 @@ export {
169
179
  Api,
170
180
  Artifact,
171
181
  ArtifactTypes,
182
+ Automations,
172
183
  Billing,
173
184
  Conversations,
174
- DEFAULT_PIPELINE_ASSIGNMENT_FILENAME,
175
185
  EMBEDDABLE_ARTIFACT_EXTENSIONS,
176
186
  Env,
177
187
  Features,
@@ -211,6 +221,7 @@ export {
211
221
  artifactFileExtension,
212
222
  artifactKindSchema,
213
223
  artifactPlatforms,
224
+ attach,
214
225
  avg,
215
226
  before,
216
227
  buildArtifactMarker,
@@ -219,6 +230,7 @@ export {
219
230
  compileEnvironment,
220
231
  compileMcps,
221
232
  compileRepo,
233
+ compileStepConcurrency,
222
234
  compileStepErrors,
223
235
  compileStepMaxTurns,
224
236
  compileStepRetry,
@@ -231,7 +243,7 @@ export {
231
243
  createStepDefinitionsClient,
232
244
  createTaskPlaneClient,
233
245
  decision,
234
- defaultPipelineAssignment,
246
+ defineAutomation,
235
247
  defineMcp,
236
248
  definePipeline,
237
249
  defineStep,
@@ -245,9 +257,10 @@ export {
245
257
  findArtifactMarkers,
246
258
  formatArtifactMarkerRef,
247
259
  formatIssue,
260
+ grantActionValues,
261
+ grantScopeValues,
248
262
  greaterThan,
249
263
  greaterThanInclusive,
250
- isDefaultPipelineAssignmentSpec,
251
264
  isEmbeddableArtifactExtension,
252
265
  isEmpty,
253
266
  isEnvPlaceholderValue,
@@ -264,6 +277,7 @@ export {
264
277
  normalizeEnv,
265
278
  not,
266
279
  notEqual,
280
+ onEvent,
267
281
  openCodeMcpLocalConfigSchema,
268
282
  openCodeMcpOAuthConfigSchema,
269
283
  openCodeMcpProtocolSchema,
@@ -282,7 +296,7 @@ export {
282
296
  reply,
283
297
  resolveMcpChecks,
284
298
  resolveWorkItemFieldPath,
285
- serializeDefaultPipelineAssignment,
299
+ skip,
286
300
  some,
287
301
  startsWith,
288
302
  stepRef,
@@ -1,10 +1,5 @@
1
- /**
2
- * `definePipeline`: runs the authoring callbacks once, with placeholders, and
3
- * compiles the result to a pipeline JSON document. It doesn't validate the
4
- * document (that's `validatePipeline` in `@scarn/shared-core/pipelines`);
5
- * it reports what only the TS source can show, and throws
6
- * `PipelineBuildError` when anything is wrong.
7
- */
1
+ import type { AutomationTarget, EventWorkItem } from "../automations/types";
2
+ import type { AutomationScope, AutomationSubject } from "../contracts/automation-document";
8
3
  import type { PipelineDocument, StepCatalog } from "../contracts/pipeline-document";
9
4
  import { type BuildIssue } from "./errors";
10
5
  import { type SourceSite } from "./source";
@@ -27,6 +22,11 @@ export interface PipelineDefinition {
27
22
  readonly steps: StepCatalog;
28
23
  /** Problems that don't stop the build, such as chains left out of `flow`. */
29
24
  readonly warnings: readonly BuildIssue[];
25
+ /**
26
+ * In an automation rule: a run of this pipeline for `workItem`
27
+ * (`r.workItem` or `r.child`). The bare pipeline runs for `r.workItem`.
28
+ */
29
+ on(workItem: EventWorkItem<AutomationSubject>): AutomationTarget<AutomationScope>;
30
30
  }
31
31
  /** Compiles a pipeline to its JSON document. Throws `PipelineBuildError`. */
32
32
  export declare function definePipeline(config: PipelineConfig): PipelineDefinition;
@@ -1,8 +1,3 @@
1
- /**
2
- * Handles at run time: callable functions that record a target when called,
3
- * with the chain-starting methods attached. Step handles from `defineStep` /
4
- * `codeStep` and `stepRef` are built here, and so are wait handles.
5
- */
6
1
  import type { JsonSchema } from "../contracts/pipeline-document";
7
2
  import type { NodeDef, RawArgs } from "./model";
8
3
  /** What `toPipelineStep` needs from a step definition. */
@@ -34,13 +34,16 @@ import {
34
34
  sum,
35
35
  workItem,
36
36
  workItemField
37
- } from "../chunk-qrasq5xe.js";
38
- import"../chunk-p7yrcmqm.js";
37
+ } from "../chunk-43y7tfn4.js";
38
+ import"../chunk-x0hjhqrf.js";
39
+ import"../chunk-61jf8b6s.js";
40
+ import"../chunk-cnxaagfj.js";
41
+ import"../chunk-jj9pezwb.js";
39
42
  import {
40
43
  PipelineBuildError,
41
44
  formatIssue
42
- } from "../chunk-mz53r914.js";
43
- import"../chunk-nb0nkt71.js";
45
+ } from "../chunk-y11p1q7r.js";
46
+ import"../chunk-01nfqm18.js";
44
47
  import"../chunk-skzxcba3.js";
45
48
  import"../chunk-y64skrwp.js";
46
49
  export {
@@ -4,6 +4,8 @@
4
4
  * `docs/plans/pipeline-ts-sdk.md`), so an unfinished or misordered chain is
5
5
  * a type error rather than a build error.
6
6
  */
7
+ import type { AutomationTarget, EventWorkItem } from "../automations/types";
8
+ import type { AutomationScope, AutomationSubject } from "../contracts/automation-document";
7
9
  import type { BUILT_IN_ERRORS, ToleratedFailures, WAIT_ERRORS } from "../contracts/pipeline-document";
8
10
  import type { StepRef } from "../definitions/steps/step-ref";
9
11
  import type { Condition } from "./condition-data";
@@ -39,6 +41,16 @@ type NoKeys = Record<never, never>;
39
41
  export type CallArgs<I> = unknown extends I ? Readonly<Record<string, Ref<unknown> | JsonLiteral>> : Args<I>;
40
42
  /** Calling a handle: args are optional only when the input has no required keys. */
41
43
  export type Call<I> = NoKeys extends I ? (args?: CallArgs<I>) => Target : (args: CallArgs<I>) => Target;
44
+ /**
45
+ * A step called with its args. In a pipeline it's a target; in an
46
+ * automation rule, `.on(r.workItem | r.child)` picks the work item its Task
47
+ * is for.
48
+ */
49
+ export interface StepTarget extends Target {
50
+ on(workItem: EventWorkItem<AutomationSubject>): AutomationTarget<AutomationScope>;
51
+ }
52
+ /** Calling a step handle: like `Call`, but the target also has `.on(...)`. */
53
+ export type StepCall<I> = NoKeys extends I ? (args?: CallArgs<I>) => StepTarget : (args: CallArgs<I>) => StepTarget;
42
54
  /** A bare handle is a target only when its input has no required keys. */
43
55
  export interface Bare<I> {
44
56
  readonly [targetBrand]: NoKeys extends I ? true : false;
@@ -123,7 +135,7 @@ export interface StepChain<I, R, E extends string> extends StepAfterRetry<I, R,
123
135
  settings(settings: StepSettings): StepAfterRetry<I, R, E>;
124
136
  }
125
137
  /** A step in a pipeline: callable as a target, and the start of its chain. */
126
- export type PipelineStep<I, R, E extends string = string> = Call<I> & Bare<I> & StepRef<I, R, E> & StepChain<I, R, E> & Mergeable<I> & {
138
+ export type PipelineStep<I, R, E extends string = string> = StepCall<I> & Bare<I> & StepRef<I, R, E> & StepChain<I, R, E> & Mergeable<I> & {
127
139
  /** The same step as a second node, with id `id`. */
128
140
  as(id: string): PipelineStep<I, R, E>;
129
141
  };
@@ -1,4 +1,3 @@
1
- import { type DefaultPipelineAssignmentSpec } from "../definitions/pipelines/define-default-pipeline-assignment";
2
1
  import type { StepDefinitionSpec } from "../definitions/steps";
3
2
  /**
4
3
  * The fixed, repo-root-relative directory `scarn pipelines init` scaffolds
@@ -15,8 +14,6 @@ export declare const PIPELINE_BUILDER_DIR = ".scarn/pipeline-builder";
15
14
  export type CollectedDefinitions = {
16
15
  /** Deduped by `key@vN`. */
17
16
  readonly steps: readonly StepDefinitionSpec[];
18
- /** Present only when `default-pipeline-assignment.ts` exists in the directory. */
19
- readonly defaultPipelineAssignment: DefaultPipelineAssignmentSpec | null;
20
17
  };
21
18
  /**
22
19
  * One source file that failed to import —
@@ -31,13 +28,11 @@ export type BrokenPipeline = {
31
28
  export type TolerantCollectedDefinitions = CollectedDefinitions & {
32
29
  readonly brokenPipelines: readonly BrokenPipeline[];
33
30
  };
34
- /** `.ts`/`.js` files in `dir` that declare definitions — excludes internal scripts and `default-pipeline-assignment.ts`. */
31
+ /** `.ts`/`.js` files in `dir` that declare definitions — excludes internal scripts. */
35
32
  export declare function listSourceFiles(absDir: string): string[];
36
33
  /**
37
- * Imports every `.ts`/`.js` file in `dir` (except the push script itself and
38
- * `default-pipeline-assignment.ts`) and collects the step definitions they
39
- * export. The assignment file, when present, is imported and
40
- * validated too but returned separately — syncing it needs the server.
34
+ * Imports every `.ts`/`.js` file in `dir` (except the push script itself) and
35
+ * collects the step definitions they export.
41
36
  *
42
37
  * Designed to run on the user's native runtime (bun, node-with-tsx, deno), NOT
43
38
  * inside a `bun --compile`'d binary — that runtime can't resolve scoped package
@@ -1,3 +1,4 @@
1
+ export type BuiltDocumentKind = "pipeline" | "automation";
1
2
  export type PipelineDocumentFile = {
2
3
  /** The file name, relative to the builder directory. */
3
4
  readonly file: string;
@@ -6,9 +7,18 @@ export type PipelineDocumentFile = {
6
7
  /** The parsed document, sent to the server as-is. */
7
8
  readonly document: Record<string, unknown>;
8
9
  };
10
+ export type BuiltDocumentFile = PipelineDocumentFile & {
11
+ readonly kind: BuiltDocumentKind;
12
+ };
9
13
  /**
10
- * Every `.json` file in `dir` that holds a pipeline document (an object with
11
- * `nodes`), sorted by file name. Other JSON is skipped. Throws on a file that
12
- * isn't valid JSON, a document without a `key`, or two files with one `key`.
14
+ * Every `.json` file in `dir` that holds a pipeline or automation document,
15
+ * sorted by file name. Other JSON is skipped. Throws on a file that isn't
16
+ * valid JSON, a document without a `key`, or two files with one `key`:
17
+ * pipelines and automations share one key space, like their `<key>.json`
18
+ * file names.
13
19
  */
20
+ export declare function collectBuiltDocuments(dir: string): BuiltDocumentFile[];
21
+ /** The pipeline documents in `dir` (see `collectBuiltDocuments`). */
14
22
  export declare function collectPipelineDocuments(dir: string): PipelineDocumentFile[];
23
+ /** The automation documents in `dir` (see `collectBuiltDocuments`). */
24
+ export declare function collectAutomationDocuments(dir: string): PipelineDocumentFile[];
@@ -1,6 +1,6 @@
1
1
  export { PIPELINE_BUILDER_DIR, collectDefinitionsFromDirectory, collectDefinitionsFromDirectoryTolerant, } from "./collect-definitions";
2
2
  export type { BrokenPipeline, CollectedDefinitions, TolerantCollectedDefinitions, } from "./collect-definitions";
3
- export { collectPipelineDocuments } from "./collect-pipeline-documents";
4
- export type { PipelineDocumentFile } from "./collect-pipeline-documents";
3
+ export { collectAutomationDocuments, collectBuiltDocuments, collectPipelineDocuments, } from "./collect-pipeline-documents";
4
+ export type { BuiltDocumentFile, BuiltDocumentKind, PipelineDocumentFile, } from "./collect-pipeline-documents";
5
5
  export { pushFromDirectory } from "./push-from-directory";
6
6
  export type { PushFromDirectoryOptions, PushFromDirectoryResult, } from "./push-from-directory";