@scarn/sdk 0.0.0-stage → 0.8.0

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 (152) hide show
  1. package/dist/chunk-0y2fy5en.js +166 -0
  2. package/dist/chunk-3ctaaseb.js +1456 -0
  3. package/dist/chunk-4ggr8af6.js +30 -0
  4. package/dist/chunk-5zsavw98.js +91 -0
  5. package/dist/chunk-63f90zky.js +39 -0
  6. package/dist/chunk-700xe701.js +100 -0
  7. package/dist/chunk-ar6hcj1r.js +35 -0
  8. package/dist/chunk-cdanncng.js +74 -0
  9. package/dist/chunk-dp86pa6m.js +68 -0
  10. package/dist/chunk-e1h021kq.js +86 -0
  11. package/dist/chunk-gds7w7zh.js +330 -0
  12. package/dist/chunk-k4y5qt4y.js +14 -0
  13. package/dist/chunk-mz53r914.js +300 -0
  14. package/dist/chunk-ngy1fdcx.js +57 -0
  15. package/dist/chunk-p7yrcmqm.js +322 -0
  16. package/dist/chunk-rt9tq4j6.js +116 -0
  17. package/dist/chunk-skzxcba3.js +14282 -0
  18. package/dist/chunk-vfeytkqx.js +1687 -0
  19. package/dist/chunk-y2pv8d6a.js +162 -0
  20. package/dist/chunk-y64skrwp.js +17 -0
  21. package/dist/chunk-yjtaq94c.js +1094 -0
  22. package/dist/chunk-zm72ksz0.js +256 -0
  23. package/dist/client.d.ts +4 -0
  24. package/dist/client.js +58 -0
  25. package/dist/contracts/artifact-markers.d.ts +42 -0
  26. package/dist/contracts/artifact-markers.js +16 -0
  27. package/dist/contracts/artifacts.d.ts +67 -0
  28. package/dist/contracts/artifacts.js +27 -0
  29. package/dist/contracts/pipeline-document/built-ins.d.ts +23 -0
  30. package/dist/contracts/pipeline-document/conditions/operators.d.ts +8 -0
  31. package/dist/contracts/pipeline-document/index.d.ts +11 -0
  32. package/dist/contracts/pipeline-document/index.js +99 -0
  33. package/dist/contracts/pipeline-document/json.d.ts +35 -0
  34. package/dist/contracts/pipeline-document/routes.d.ts +16 -0
  35. package/dist/contracts/pipeline-document/schema.d.ts +780 -0
  36. package/dist/contracts/pipeline-document/step-contract.d.ts +11 -0
  37. package/dist/contracts/step-artifact-submissions.d.ts +71 -0
  38. package/dist/contracts/step-artifact-submissions.js +171 -0
  39. package/dist/defaults/atomic-json-file.d.ts +10 -0
  40. package/dist/defaults/auth-file.d.ts +14 -0
  41. package/dist/defaults/base-url.d.ts +1 -0
  42. package/dist/defaults/config-file.d.ts +46 -0
  43. package/dist/defaults/home-dir.d.ts +3 -0
  44. package/dist/defaults/index.d.ts +12 -0
  45. package/dist/defaults/index.js +1240 -0
  46. package/dist/defaults/legacy-config-migration.d.ts +27 -0
  47. package/dist/defaults/load-push-defaults.d.ts +25 -0
  48. package/dist/defaults/project-config.d.ts +32 -0
  49. package/dist/defaults/project-ref.d.ts +34 -0
  50. package/dist/definitions/artifacts/artifact.d.ts +62 -0
  51. package/dist/definitions/artifacts/index.d.ts +1 -0
  52. package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +263 -0
  53. package/dist/definitions/pipelines/index.d.ts +3 -0
  54. package/dist/definitions/pipelines/index.js +26 -0
  55. package/dist/definitions/pipelines/pipeline-definitions-client.d.ts +208 -0
  56. package/dist/definitions/pipelines/work-item-fields.d.ts +93 -0
  57. package/dist/definitions/steps/compile-mcps.d.ts +34 -0
  58. package/dist/definitions/steps/define-code-step.d.ts +84 -0
  59. package/dist/definitions/steps/define-mcp.d.ts +79 -0
  60. package/dist/definitions/steps/define-step.d.ts +137 -0
  61. package/dist/definitions/steps/env.d.ts +136 -0
  62. package/dist/definitions/steps/index.d.ts +14 -0
  63. package/dist/definitions/steps/index.js +76 -0
  64. package/dist/definitions/steps/mcp-server-config.d.ts +102 -0
  65. package/dist/definitions/steps/prompt-template.d.ts +24 -0
  66. package/dist/definitions/steps/repo.d.ts +67 -0
  67. package/dist/definitions/steps/runtime.d.ts +115 -0
  68. package/dist/definitions/steps/step-definitions-client.d.ts +400 -0
  69. package/dist/definitions/steps/step-features.d.ts +109 -0
  70. package/dist/definitions/steps/step-handle.d.ts +25 -0
  71. package/dist/definitions/steps/step-ref.d.ts +19 -0
  72. package/dist/definitions/validation/index.d.ts +2 -0
  73. package/dist/definitions/validation/index.js +19 -0
  74. package/dist/definitions/validation/validate-artifact-markers.d.ts +3 -0
  75. package/dist/definitions/validation/validate-artifacts.d.ts +7 -0
  76. package/dist/definitions/validation/validate-definition-specs.d.ts +16 -0
  77. package/dist/definitions/validation/validate-env.d.ts +15 -0
  78. package/dist/definitions/validation/validate-repo.d.ts +13 -0
  79. package/dist/definitions/validation/validate-runtime.d.ts +12 -0
  80. package/dist/definitions/validation/validation-issue.d.ts +11 -0
  81. package/dist/devcontainer-config-path.d.ts +21 -0
  82. package/dist/devcontainer-config-path.js +15 -0
  83. package/dist/env-vars.d.ts +136 -0
  84. package/dist/env-vars.js +37 -0
  85. package/dist/eslint.d.ts +42 -0
  86. package/dist/eslint.js +127 -0
  87. package/dist/generated/client/client.gen.d.ts +2 -0
  88. package/dist/generated/client/index.d.ts +8 -0
  89. package/dist/generated/client/types.gen.d.ts +117 -0
  90. package/dist/generated/client/utils.gen.d.ts +33 -0
  91. package/dist/generated/client.gen.d.ts +12 -0
  92. package/dist/generated/core/auth.gen.d.ts +18 -0
  93. package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
  94. package/dist/generated/core/params.gen.d.ts +43 -0
  95. package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
  96. package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
  97. package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
  98. package/dist/generated/core/types.gen.d.ts +78 -0
  99. package/dist/generated/core/utils.gen.d.ts +19 -0
  100. package/dist/generated/index.d.ts +2 -0
  101. package/dist/generated/sdk.gen.d.ts +302 -0
  102. package/dist/generated/types.gen.d.ts +18375 -0
  103. package/dist/git-url/git-remote.d.ts +30 -0
  104. package/dist/git-url/git-repo-identity.d.ts +44 -0
  105. package/dist/git-url/git-repo-identity.js +161 -0
  106. package/dist/git-url/parse-git-host.d.ts +23 -0
  107. package/dist/health-checks.d.ts +169 -0
  108. package/dist/health-checks.js +21 -0
  109. package/dist/index.d.ts +11 -0
  110. package/dist/index.js +296 -0
  111. package/dist/jsonc.d.ts +3 -0
  112. package/dist/jsonc.js +12 -0
  113. package/dist/managed-runtimes.d.ts +20 -0
  114. package/dist/managed-runtimes.js +15 -0
  115. package/dist/opencode-mcp.d.ts +313 -0
  116. package/dist/opencode-mcp.js +31 -0
  117. package/dist/pipelines/chain.d.ts +7 -0
  118. package/dist/pipelines/compile-args.d.ts +12 -0
  119. package/dist/pipelines/compile-chain.d.ts +9 -0
  120. package/dist/pipelines/compile-checks.d.ts +16 -0
  121. package/dist/pipelines/compile-state.d.ts +30 -0
  122. package/dist/pipelines/condition-data.d.ts +78 -0
  123. package/dist/pipelines/conditions.d.ts +47 -0
  124. package/dist/pipelines/context.d.ts +16 -0
  125. package/dist/pipelines/define-pipeline.d.ts +32 -0
  126. package/dist/pipelines/each.d.ts +5 -0
  127. package/dist/pipelines/errors.d.ts +26 -0
  128. package/dist/pipelines/handles.d.ts +29 -0
  129. package/dist/pipelines/index.d.ts +18 -0
  130. package/dist/pipelines/index.js +83 -0
  131. package/dist/pipelines/model.d.ts +103 -0
  132. package/dist/pipelines/nodes.d.ts +54 -0
  133. package/dist/pipelines/ref-types.d.ts +54 -0
  134. package/dist/pipelines/refs.d.ts +80 -0
  135. package/dist/pipelines/registry.d.ts +12 -0
  136. package/dist/pipelines/source.d.ts +17 -0
  137. package/dist/pipelines/types.d.ts +160 -0
  138. package/dist/push/code-step-lookup.d.ts +32 -0
  139. package/dist/push/code-step-lookup.js +12 -0
  140. package/dist/push/collect-definitions.d.ts +70 -0
  141. package/dist/push/collect-pipeline-documents.d.ts +14 -0
  142. package/dist/push/index.d.ts +6 -0
  143. package/dist/push/index.js +327 -0
  144. package/dist/push/push-from-directory.d.ts +37 -0
  145. package/dist/repo-config.d.ts +80 -0
  146. package/dist/repo-config.js +25 -0
  147. package/dist/scarn-config-parser.d.ts +29 -0
  148. package/dist/scarn-config-parser.js +10 -0
  149. package/dist/task-plane-client.d.ts +489 -0
  150. package/dist/z.d.ts +7 -0
  151. package/package.json +132 -4
  152. package/README.md +0 -3
@@ -0,0 +1,208 @@
1
+ import { z } from "zod";
2
+ import { PipelineDefinitions } from "../../generated/sdk.gen";
3
+ import type { PostApiPipelineDefinitionsByPipelineDefinitionIdVersionsResponses, PostApiPipelineDefinitionsResponses } from "../../generated/types.gen";
4
+ type RequestOptions = {
5
+ headers?: Record<string, unknown> | undefined;
6
+ };
7
+ export type PipelineDefinition = PostApiPipelineDefinitionsResponses[200];
8
+ export type PublishPipelineVersionResult = PostApiPipelineDefinitionsByPipelineDefinitionIdVersionsResponses[200];
9
+ declare const pipelineDocumentIssueSchema: z.ZodObject<{
10
+ code: z.ZodString;
11
+ path: z.ZodString;
12
+ message: z.ZodString;
13
+ hint: z.ZodOptional<z.ZodString>;
14
+ }, z.core.$strip>;
15
+ /** One validation error the server reports for a rejected pipeline document. */
16
+ export type PipelineDocumentIssue = z.infer<typeof pipelineDocumentIssueSchema>;
17
+ type ApiError = {
18
+ title?: string;
19
+ detail?: string;
20
+ code?: string;
21
+ meta?: {
22
+ [key: string]: unknown;
23
+ };
24
+ };
25
+ /**
26
+ * Thrown when the API rejects a request. `issues` carries the per-path
27
+ * validation errors of a `PIPELINE_DOCUMENT_INVALID` rejection.
28
+ */
29
+ export declare class PipelineDefinitionsApiError extends Error {
30
+ readonly code: string | undefined;
31
+ readonly issues: readonly PipelineDocumentIssue[];
32
+ constructor(error: ApiError);
33
+ }
34
+ export declare function createPipelineDefinitionsClient(baseUrl: string): ReturnType<typeof buildPipelineDefinitionsClient>;
35
+ declare const buildPipelineDefinitionsClient: (pipelineDefinitions: PipelineDefinitions) => {
36
+ listByProjectId: (projectId: string, options?: RequestOptions) => Promise<{
37
+ id: string;
38
+ projectId: string;
39
+ key: string;
40
+ name: string;
41
+ archivedAt: string | unknown;
42
+ currentVersion: {
43
+ id: string;
44
+ pipelineDefinitionId: string;
45
+ version: number;
46
+ schemaVersion: number;
47
+ contentHash: string;
48
+ definition: {
49
+ [key: string]: unknown;
50
+ };
51
+ steps: Array<{
52
+ stepKey: string;
53
+ stepDefinitionId: string;
54
+ }>;
55
+ createdAt: string;
56
+ } | unknown;
57
+ createdAt: string;
58
+ updatedAt: string;
59
+ }[]>;
60
+ get: (pipelineDefinitionId: string, options?: RequestOptions) => Promise<{
61
+ id: string;
62
+ projectId: string;
63
+ key: string;
64
+ name: string;
65
+ archivedAt: string | unknown;
66
+ currentVersion: {
67
+ id: string;
68
+ pipelineDefinitionId: string;
69
+ version: number;
70
+ schemaVersion: number;
71
+ contentHash: string;
72
+ definition: {
73
+ [key: string]: unknown;
74
+ };
75
+ steps: Array<{
76
+ stepKey: string;
77
+ stepDefinitionId: string;
78
+ }>;
79
+ createdAt: string;
80
+ } | unknown;
81
+ createdAt: string;
82
+ updatedAt: string;
83
+ }>;
84
+ /** Creates a pipeline; `document`, when given, is published as version 1. */
85
+ create: (input: {
86
+ projectId: string;
87
+ key: string;
88
+ name: string;
89
+ document?: Record<string, unknown>;
90
+ }, options?: RequestOptions) => Promise<{
91
+ id: string;
92
+ projectId: string;
93
+ key: string;
94
+ name: string;
95
+ archivedAt: string | unknown;
96
+ currentVersion: {
97
+ id: string;
98
+ pipelineDefinitionId: string;
99
+ version: number;
100
+ schemaVersion: number;
101
+ contentHash: string;
102
+ definition: {
103
+ [key: string]: unknown;
104
+ };
105
+ steps: Array<{
106
+ stepKey: string;
107
+ stepDefinitionId: string;
108
+ }>;
109
+ createdAt: string;
110
+ } | unknown;
111
+ createdAt: string;
112
+ updatedAt: string;
113
+ }>;
114
+ /**
115
+ * Publishes `document` as the pipeline's next version, which becomes the
116
+ * active one. `published` is false when it matched the latest version.
117
+ */
118
+ publishVersion: (pipelineDefinitionId: string, document: Record<string, unknown>, options?: RequestOptions) => Promise<{
119
+ published: boolean;
120
+ version: {
121
+ id: string;
122
+ pipelineDefinitionId: string;
123
+ version: number;
124
+ schemaVersion: number;
125
+ contentHash: string;
126
+ definition: {
127
+ [key: string]: unknown;
128
+ };
129
+ steps: Array<{
130
+ stepKey: string;
131
+ stepDefinitionId: string;
132
+ }>;
133
+ createdAt: string;
134
+ };
135
+ pipelineDefinition: {
136
+ id: string;
137
+ projectId: string;
138
+ key: string;
139
+ name: string;
140
+ archivedAt: string | unknown;
141
+ currentVersion: {
142
+ id: string;
143
+ pipelineDefinitionId: string;
144
+ version: number;
145
+ schemaVersion: number;
146
+ contentHash: string;
147
+ definition: {
148
+ [key: string]: unknown;
149
+ };
150
+ steps: Array<{
151
+ stepKey: string;
152
+ stepDefinitionId: string;
153
+ }>;
154
+ createdAt: string;
155
+ } | unknown;
156
+ createdAt: string;
157
+ updatedAt: string;
158
+ };
159
+ }>;
160
+ activateVersion: (pipelineDefinitionId: string, version: number, options?: RequestOptions) => Promise<{
161
+ id: string;
162
+ projectId: string;
163
+ key: string;
164
+ name: string;
165
+ archivedAt: string | unknown;
166
+ currentVersion: {
167
+ id: string;
168
+ pipelineDefinitionId: string;
169
+ version: number;
170
+ schemaVersion: number;
171
+ contentHash: string;
172
+ definition: {
173
+ [key: string]: unknown;
174
+ };
175
+ steps: Array<{
176
+ stepKey: string;
177
+ stepDefinitionId: string;
178
+ }>;
179
+ createdAt: string;
180
+ } | unknown;
181
+ createdAt: string;
182
+ updatedAt: string;
183
+ }>;
184
+ listVersions: (pipelineDefinitionId: string, options?: RequestOptions) => Promise<{
185
+ id: string;
186
+ pipelineDefinitionId: string;
187
+ version: number;
188
+ schemaVersion: number;
189
+ contentHash: string;
190
+ createdAt: string;
191
+ }[]>;
192
+ getVersion: (pipelineDefinitionId: string, version: number, options?: RequestOptions) => Promise<{
193
+ id: string;
194
+ pipelineDefinitionId: string;
195
+ version: number;
196
+ schemaVersion: number;
197
+ contentHash: string;
198
+ definition: {
199
+ [key: string]: unknown;
200
+ };
201
+ steps: Array<{
202
+ stepKey: string;
203
+ stepDefinitionId: string;
204
+ }>;
205
+ createdAt: string;
206
+ }>;
207
+ };
208
+ export {};
@@ -0,0 +1,93 @@
1
+ import type { GetApiWorkItemsByWorkItemIdResponses } from "../../generated/types.gen";
2
+ /**
3
+ * Top-level work-item properties addressable by the default-pipeline-assignment
4
+ * DSL's `workItem.<field>` accessor (`define-default-pipeline-assignment.ts`)
5
+ * and, reversed, its `scarn pipelines pull` file generator
6
+ * (`default-pipeline-assignment-file-generator.ts`). `fields` is deliberately excluded from this
7
+ * list: it's reached via `.field(name)` on every one of those accessors, not
8
+ * as a top-level property.
9
+ *
10
+ * This is the single source of truth for the list — it must stay in sync
11
+ * with the `workItem` fact/context shape every corresponding server-side
12
+ * resolver publishes (`buildFacts` in
13
+ * `evaluate-default-pipeline-assignment.ts`; `buildResolvedWorkItemContext`
14
+ * in `resolve-node-input.ts`).
15
+ */
16
+ export declare const WORK_ITEM_TOP_LEVEL_FIELDS: readonly ["id", "projectId", "platform", "platformId", "platformKey", "url", "title", "description", "sourceCreatedAt", "sourceUpdatedAt", "createdByUserId", "parentWorkItemId", "createdAt", "updatedAt"];
17
+ export type WorkItemTopLevelField = (typeof WORK_ITEM_TOP_LEVEL_FIELDS)[number];
18
+ /**
19
+ * The literal union of valid work-item platforms, sourced from the generated
20
+ * OpenAPI response type (`GetApiWorkItemsByWorkItemIdResponses[200]["platform"]`)
21
+ * rather than hand-duplicated, so it cannot drift from the API contract. It
22
+ * must mirror `WorkItemPlatform` in
23
+ * `packages/core/src/work-items/work-item/domain/work-item-platform.ts`.
24
+ */
25
+ type WorkItemPlatformLiteral = GetApiWorkItemsByWorkItemIdResponses[200]["platform"];
26
+ /**
27
+ * Per-field value types for every member of `WORK_ITEM_TOP_LEVEL_FIELDS`,
28
+ * mirroring exactly what the server-side resolvers publish at evaluation/
29
+ * resolution time (`buildFacts` for default-pipeline-assignment;
30
+ * `buildResolvedWorkItemContext` for regular pipeline/step input bindings).
31
+ * Notably, `sourceCreatedAt`/`sourceUpdatedAt`/`createdAt`/`updatedAt` are
32
+ * serialized as ISO date strings (or `null`), never `Date` objects.
33
+ */
34
+ export type WorkItemTopLevelFieldTypeMap = {
35
+ id: string;
36
+ projectId: string;
37
+ platform: WorkItemPlatformLiteral;
38
+ platformId: string | null;
39
+ platformKey: string;
40
+ url: string | null;
41
+ title: string;
42
+ description: string | null;
43
+ sourceCreatedAt: string | null;
44
+ sourceUpdatedAt: string | null;
45
+ createdByUserId: string | null;
46
+ parentWorkItemId: string | null;
47
+ createdAt: string | null;
48
+ updatedAt: string | null;
49
+ };
50
+ /**
51
+ * The path prefix marking a reference into a work item's platform-specific
52
+ * `fields` bag (a Jira custom field, a GitHub label, etc.), as opposed to a
53
+ * `WorkItemTopLevelField`. Shared by every accessor that authors these paths
54
+ * (`workItem.field(name)` in the default-pipeline-assignment DSL) and every resolver that
55
+ * reads them back (`resolveWorkItemFieldPath` below; the JSONPath-rooted
56
+ * variant in `evaluate-default-pipeline-assignment.ts`, which layers a `$.`
57
+ * prefix on top of this same convention).
58
+ */
59
+ export declare const WORK_ITEM_FIELDS_PATH_PREFIX = "fields.";
60
+ /**
61
+ * Resolves a work-item path — either a `WorkItemTopLevelField` name (a
62
+ * single, code-controlled segment) or a `fields.<name>` reference into the
63
+ * platform-specific `fields` bag — against a plain object shaped like
64
+ * `WorkItemTopLevelFieldTypeMap & { fields: ... }`.
65
+ *
66
+ * `<name>` in `fields.<name>` is an arbitrary, unescaped, platform-supplied
67
+ * field name (a Jira custom field label, a GitHub key, etc.) that may
68
+ * contain any character, including `.`, `[`, `]`, `~`, `^`, `;`, or even be
69
+ * the empty string. A naive dot-splitting path walker would silently
70
+ * misresolve a field literally named `"a.b"` as nested property access
71
+ * (`fields.a.b`) instead of the flat key `fields["a.b"]` — a silent-wrong-
72
+ * match hazard, not a visible error, since the walker degrades to "no
73
+ * match"/"wrong match" rather than throwing.
74
+ *
75
+ * This resolver sidesteps that hazard entirely: everything after `fields.`
76
+ * is treated as one atomic, unsplit key. Every work-item path resolver in
77
+ * the codebase must use this same convention for a field name to round-trip
78
+ * correctly — see `evaluate-default-pipeline-assignment.ts`'s
79
+ * `resolveWorkItemAssignmentPath` (which layers `$.` path-rooting on top of
80
+ * this function) and `resolve-node-input.ts`'s `work_item` binding
81
+ * resolution (which calls this function directly, replacing what used to be
82
+ * a dot-splitting walker shared with unrelated binding sources and
83
+ * susceptible to the exact hazard described above).
84
+ *
85
+ * `path` is untyped (`string`, not `WorkItemTopLevelField | \`fields.${string}\``)
86
+ * because callers validate membership separately
87
+ * (`WORK_ITEM_TOP_LEVEL_FIELDS`/`isSupportedWorkItemField`) before ever
88
+ * reaching a resolver — this function's contract is purely "resolve
89
+ * whatever path string you hand it, treating `fields.` as atomic," not
90
+ * "validate the path."
91
+ */
92
+ export declare function resolveWorkItemFieldPath(record: unknown, path: string): unknown;
93
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { EnvVarSpec, EnvVarsInput } from "../../env-vars";
2
+ import type { HealthChecksInput } from "../../health-checks";
3
+ import type { OpenCodeMcpServers } from "../../opencode-mcp";
4
+ import { type McpHandle } from "./define-mcp";
5
+ /**
6
+ * Compiles a step's `mcps` (`defineMcp` handles keyed by the step's server
7
+ * key) into the wire fields, and merges them with the step's own
8
+ * `healthChecks` and `environment.vars`.
9
+ */
10
+ type InheritEnvVarSpec = Extract<EnvVarSpec, {
11
+ source: "inherit";
12
+ }>;
13
+ export type CompiledMcps = {
14
+ opencodeMcpJson: OpenCodeMcpServers;
15
+ healthChecks: HealthChecksInput;
16
+ envEntries: InheritEnvVarSpec[];
17
+ };
18
+ export type StepMcpFields = {
19
+ opencodeMcpJson: OpenCodeMcpServers | null;
20
+ healthChecksJson: HealthChecksInput | null;
21
+ envJson: EnvVarsInput | null;
22
+ };
23
+ /** Throws when a value under `mcps` is not a `defineMcp` handle. */
24
+ export declare function compileMcps(mcps: Readonly<Record<string, McpHandle>>, stepKey: string): CompiledMcps;
25
+ /**
26
+ * Merges compiled `mcps` into the step's own fields: MCP checks run before the
27
+ * step's own, and a step var replaces an MCP var of the same name.
28
+ */
29
+ export declare function mergeStepMcps(stepKey: string, input: {
30
+ mcps: Readonly<Record<string, McpHandle>> | undefined;
31
+ healthChecks: HealthChecksInput | null | undefined;
32
+ envJson: EnvVarsInput | null;
33
+ }): StepMcpFields;
34
+ export {};
@@ -0,0 +1,84 @@
1
+ import type { ZodType } from "zod";
2
+ import type { EffectiveResult, StepRetryEntry } from "./define-step";
3
+ import type { BuiltInError } from "../../pipelines/types";
4
+ import { type StepHandle } from "./step-handle";
5
+ import { type CodeStepEnvironment } from "./runtime";
6
+ import type { AnyStepFeature } from "./step-features";
7
+ /** What the worker passes a code step besides its input. */
8
+ export type CodeStepContext = {
9
+ /**
10
+ * Absolute path of the step-artifacts folder, which already exists. Write
11
+ * a file here and return its path relative to this folder with
12
+ * `Artifact.path(...)` to fill an artifact field.
13
+ */
14
+ artifactsDir: string;
15
+ };
16
+ export type CodeStepFn<TInput, TResult> = (input: TInput, context: CodeStepContext) => TResult | Promise<TResult>;
17
+ export type DefineCodeStepInput<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, TFeatures extends ReadonlyArray<AnyStepFeature> = never[]> = {
18
+ key: string;
19
+ name: string;
20
+ description?: string | null;
21
+ version?: number;
22
+ /**
23
+ * The step's own implementation. It may be an inline arrow or a reference
24
+ * to a function declared elsewhere; it does not need to be exported. Only
25
+ * the file that defines the step is pushed (as `{ sourceFile }`), and the
26
+ * worker re-imports that file from the repo checkout and finds the step by
27
+ * `key`, so closures and module-level helpers keep working. The step must
28
+ * be exported by name from that file.
29
+ *
30
+ * Typed against `EffectiveResult`, not the bare `resultSchema` output, so
31
+ * a step with `features: [Features.notifications()]` can return the
32
+ * `$scarn_notifications_v1` field (e.g. via `Notify.inApp(...)`)
33
+ * without a type error.
34
+ */
35
+ fn: CodeStepFn<TInput["_output"], EffectiveResult<TResult["_output"], TFeatures>>;
36
+ inputSchema?: TInput;
37
+ resultSchema?: TResult;
38
+ /**
39
+ * Step features to attach — unlike `defineStep()`, only each feature's
40
+ * `_resultExtension` applies here (there is no prompt to append
41
+ * to on a `kind: "code"` step).
42
+ */
43
+ features?: TFeatures;
44
+ /**
45
+ * Where the step's runner executes (`runtime`) and the environment variables
46
+ * it receives (`vars`). The function reads the variables back through
47
+ * `process.env`; unlike `defineStep()`, there is no typed `env` argument to
48
+ * `fn`.
49
+ *
50
+ * Omitting `runtime` compiles to `Runtime.managed.bun1()`, a worker-supplied
51
+ * container. `Runtime.devcontainer()` opts into the project's own container,
52
+ * which must then provide a JS runtime for the runner script.
53
+ *
54
+ * `Runtime.host()` is not supported: a code step runs repo code, so it needs
55
+ * a workspace, and the host runtime has none. It is a type error here and
56
+ * `validateDefinitionSpecs` rejects it for hand-built specs.
57
+ *
58
+ * `repo` follows the same rules as for `defineStep()`; `result` is typed from
59
+ * `resultSchema`.
60
+ */
61
+ environment?: CodeStepEnvironment<TInput["_output"], TResult["_output"]>;
62
+ status?: "draft" | "active";
63
+ /**
64
+ * Error names this step can fail with, beyond the built-in ones. A
65
+ * pipeline's `retry.on` and `catch.on` may name them.
66
+ */
67
+ errors?: readonly string[];
68
+ /** As `defineStep()`'s `retry`: how a standalone Task of this step retries. */
69
+ retry?: readonly StepRetryEntry[];
70
+ };
71
+ /**
72
+ * Defines a `kind: "code"` step: a plain function instead of an LLM
73
+ * prompt. Produces the same callable step handle `defineStep()` does (so a
74
+ * pipeline calls it the same way), but with no `prompt` and a live
75
+ * `entrypoint.fn` reference attached instead — see `StepDefinitionSpec`'s
76
+ * own doc comment for what happens to it during collection.
77
+ */
78
+ export declare function codeStep<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, const TFeatures extends ReadonlyArray<AnyStepFeature> = never[], const TErrors extends string = never>(config: Omit<DefineCodeStepInput<TInput, TResult, TFeatures>, "errors" | "retry"> & {
79
+ errors?: readonly TErrors[];
80
+ retry?: readonly {
81
+ on: readonly (BuiltInError | TErrors)[];
82
+ maxAttempts: number;
83
+ }[];
84
+ }): StepHandle<TInput["_output"], EffectiveResult<TResult["_output"], TFeatures>, TErrors>;
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ import { toolHealthCheckSchema } from "../../health-checks";
3
+ import { type McpServerConfig, type McpServerDefinition } from "./mcp-server-config";
4
+ export type { McpLocalServerFields, McpRefServerFields, McpRemoteServerFields, McpServerDefinition, McpServerType, } from "./mcp-server-config";
5
+ type ToolCheckAuthoring = Omit<z.input<typeof toolHealthCheckSchema>, "kind" | "mcp" | "name">;
6
+ /** A health check on a `defineMcp` server: a tool check without `mcp`/`name`. */
7
+ export type McpCheckInput = ToolCheckAuthoring & {
8
+ enabled?: boolean;
9
+ };
10
+ /** The fields `overrideCheck` may change. */
11
+ export type McpCheckPatch = Partial<Pick<McpCheckInput, "tool" | "args" | "timeoutSeconds" | "severity" | "serialGroup">>;
12
+ export type McpOp = {
13
+ readonly op: "override";
14
+ readonly name: string;
15
+ readonly patch: McpCheckPatch;
16
+ } | {
17
+ readonly op: "enable";
18
+ readonly name: string;
19
+ } | {
20
+ readonly op: "disable";
21
+ readonly name: string;
22
+ } | {
23
+ readonly op: "add";
24
+ readonly name: string;
25
+ readonly check: McpCheckInput;
26
+ } | {
27
+ readonly op: "disableAll";
28
+ };
29
+ /**
30
+ * `{ type: "ref", name }`, `{ type: "local", name, command, cwd?,
31
+ * environment? }` or `{ type: "remote", name, url, headers?, oauth? }`, each
32
+ * with the shared OpenCode fields (`timeout`, `protocol`, `codemode`). Inline
33
+ * `environment` and `headers` values must be written as `{env:VAR}`.
34
+ */
35
+ export type DefineMcpConfig<TChecks extends Record<string, McpCheckInput>> = McpServerConfig & {
36
+ /** Worker env vars the server needs; a missing one fails the step. */
37
+ env?: readonly string[];
38
+ /** Worker env vars passed through when set. */
39
+ optionalEnv?: readonly string[];
40
+ healthChecks?: TChecks;
41
+ };
42
+ type McpHandleData = {
43
+ readonly env: readonly string[];
44
+ readonly optionalEnv: readonly string[];
45
+ /** The checks from `defineMcp`; `addCheck`ed checks live in `overrides`. */
46
+ readonly checks: Readonly<Record<string, Readonly<McpCheckInput>>>;
47
+ readonly overrides: readonly McpOp[];
48
+ };
49
+ interface McpHandleMethods<TNames extends string> {
50
+ overrideCheck(name: TNames, patch: McpCheckPatch): McpHandle<TNames>;
51
+ disableCheck(name: TNames): McpHandle<TNames>;
52
+ enableCheck(name: TNames): McpHandle<TNames>;
53
+ addCheck<N extends string>(name: N & Exclude<N, TNames>, check: McpCheckInput): McpHandle<TNames | N>;
54
+ disableAllChecks(): McpHandle<TNames>;
55
+ }
56
+ /**
57
+ * An immutable `defineMcp` server: `type`, `name` and `server` (its OpenCode
58
+ * fields; for a `ref`, only the shared ones), its env vars, checks and op log.
59
+ */
60
+ export type McpHandle<TNames extends string = string> = McpServerDefinition & McpHandleData & McpHandleMethods<TNames>;
61
+ export type ResolvedMcpCheck = {
62
+ readonly name: string;
63
+ readonly check: McpCheckInput;
64
+ readonly enabled: boolean;
65
+ };
66
+ /** True for a handle built by `defineMcp` or one of its builder methods. */
67
+ export declare function isMcpHandle(value: unknown): value is McpHandle;
68
+ /**
69
+ * Defines an MCP server once, with its env vars and health checks. Throws on
70
+ * an invalid server field, a literal `environment`/`headers` value, or an
71
+ * invalid check or env var name.
72
+ */
73
+ export declare function defineMcp<TChecks extends Record<string, McpCheckInput> = Record<never, never>>(config: DefineMcpConfig<TChecks>): McpHandle<keyof TChecks & string>;
74
+ /**
75
+ * Replays a handle's op log over its checks and returns every check, in
76
+ * definition then `addCheck` order, with its patched fields and whether it is
77
+ * enabled. See the module comment for the precedence rules.
78
+ */
79
+ export declare function resolveMcpChecks(handle: McpHandle): ResolvedMcpCheck[];
@@ -0,0 +1,137 @@
1
+ import type { ZodType } from "zod";
2
+ import type { AnyStepFeature, FeatureResultExtensions } from "./step-features";
3
+ import { type PromptTemplateContext } from "./prompt-template";
4
+ import { type HealthChecksInput, type StepHealthChecksInput } from "../../health-checks";
5
+ import type { OpenCodeMcpServers } from "../../opencode-mcp";
6
+ import type { EnvVarsInput } from "../../env-vars";
7
+ import type { RepoConfigInput } from "../../repo-config";
8
+ import type { EnvRecord, PromptEnvContext } from "./env";
9
+ import { type StepEnvironment } from "./runtime";
10
+ import type { McpHandle } from "./define-mcp";
11
+ import type { BuiltInError, ConversationResult } from "../../pipelines/types";
12
+ import { type StepHandle } from "./step-handle";
13
+ type Prettify<T> = {
14
+ [K in keyof T]: T[K];
15
+ } & {};
16
+ export type DefineStepInput<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, TEnv extends EnvRecord = EnvRecord> = {
17
+ key: string;
18
+ name: string;
19
+ description?: string | null;
20
+ version?: number;
21
+ /**
22
+ * Where the step runs (`runtime`), its environment variables (`vars`) and what
23
+ * it may do to the repository (`repo`). Declare it before `agentPrompt` so
24
+ * `TEnv` is inferred from `vars` into the prompt's `env`, which is then
25
+ * strict: only declared, non-secret keys.
26
+ */
27
+ environment?: StepEnvironment<TInput["_output"], TEnv, TResult["_output"]>;
28
+ agentPrompt: string | ((context: PromptTemplateContext<TInput["_output"], PromptEnvContext<TEnv>>) => string);
29
+ additionalInput?: TInput;
30
+ result?: TResult;
31
+ features?: AnyStepFeature[];
32
+ /**
33
+ * The step's MCP servers, built with `defineMcp` and keyed by the step's
34
+ * server key. Each contributes its server, its health checks (run before
35
+ * `healthChecks`) and its env vars (a same-named `environment.vars` entry
36
+ * wins).
37
+ */
38
+ mcps?: Record<string, McpHandle>;
39
+ /**
40
+ * `cli` checks and `tool` checks for plugin or built-in tools. MCP checks
41
+ * belong on the server's `defineMcp`.
42
+ */
43
+ healthChecks?: StepHealthChecksInput | null;
44
+ status?: "draft" | "active";
45
+ /**
46
+ * Error names this step can fail with, beyond the built-in ones. A
47
+ * pipeline's `retry.on` and `catch.on` may name them.
48
+ */
49
+ errors?: readonly string[];
50
+ /**
51
+ * How a standalone Task of this step retries: errors named in `on` (built-in
52
+ * or declared in `errors`) get up to `maxAttempts` more runs. A pipeline
53
+ * step uses its node's `.retry(...)` instead.
54
+ */
55
+ retry?: readonly StepRetryEntry[];
56
+ };
57
+ /** One `retry` entry: the same shape as a pipeline node's `retry`. */
58
+ export type StepRetryEntry = {
59
+ on: readonly string[];
60
+ maxAttempts: number;
61
+ };
62
+ /**
63
+ * A `kind: "code"` step's portable entrypoint, once resolved by
64
+ * `collect-definitions.ts`: the repo-relative file that defines the step. The
65
+ * worker finds the step inside that file by its `key`.
66
+ */
67
+ export type StepDefinitionEntrypointJson = {
68
+ sourceFile: string;
69
+ };
70
+ export type StepDefinitionSpec = {
71
+ key: string;
72
+ name: string;
73
+ description: string | null;
74
+ version: number;
75
+ kind: "user_defined" | "code";
76
+ status: "draft" | "active" | "archived";
77
+ executionMode?: "workspace" | "no_workspace";
78
+ /**
79
+ * Repo-relative path of the devcontainer config to launch; `null` or omitted
80
+ * means auto-detect. Only valid with `executionMode: "workspace"`.
81
+ */
82
+ devcontainerConfigPath?: string | null;
83
+ /**
84
+ * Identifier of the worker-supplied managed runtime (`Runtime.managed.<id>()`);
85
+ * `null` or omitted means not managed. Only valid on a `code` step with
86
+ * `executionMode: "workspace"` and no `devcontainerConfigPath`.
87
+ */
88
+ managedRuntime?: string | null;
89
+ /**
90
+ * Repository access. Omitted means the runtime's default (`readWrite` for
91
+ * `workspace`, `none` for `no_workspace`), which the server resolves.
92
+ */
93
+ repo?: RepoConfigInput;
94
+ prompt: string | null;
95
+ inputSchemaJson: Record<string, unknown> | null;
96
+ resultSchemaJson: Record<string, unknown> | null;
97
+ opencodeMcpJson: OpenCodeMcpServers | null;
98
+ healthChecksJson: HealthChecksInput | null;
99
+ envJson?: EnvVarsInput | null;
100
+ /** Error names the step declares besides the built-in ones. */
101
+ errors?: readonly string[];
102
+ /**
103
+ * The step's `retry` policy for standalone Tasks. Not `retry`: that name is
104
+ * the handle's pipeline chain method.
105
+ */
106
+ retryJson?: StepRetryEntry[];
107
+ /**
108
+ * `kind === "code"` only: the live function of a spec produced by
109
+ * `codeStep()`. Code-step discovery (`findCodeStepInModule`) reads it to
110
+ * find the function to run. `collect-definitions.ts` strips it from the
111
+ * copy it pushes, since a function cannot be serialized into the push
112
+ * request; the original spec keeps it.
113
+ */
114
+ entrypoint?: {
115
+ fn: (input: unknown, context: {
116
+ artifactsDir: string;
117
+ }) => unknown;
118
+ };
119
+ /** `kind === "code"` only, present after `collect-definitions.ts` has run. */
120
+ entrypointJson?: StepDefinitionEntrypointJson | null;
121
+ };
122
+ export type EffectiveResult<TResult, TFeatures extends ReadonlyArray<AnyStepFeature>> = Prettify<TResult & FeatureResultExtensions<TFeatures>>;
123
+ /**
124
+ * A `defineStep` handle's result type: `ConversationResult` when the step has
125
+ * no `result` and no features (a conversation step), else its effective
126
+ * result.
127
+ */
128
+ export type DefineStepResult<TResult extends ZodType, TFeatures extends ReadonlyArray<AnyStepFeature>> = ZodType extends TResult ? [TFeatures[number]] extends [never] ? ConversationResult : EffectiveResult<TResult["_output"], TFeatures> : EffectiveResult<TResult["_output"], TFeatures>;
129
+ export declare function defineStep<TInput extends ZodType = ZodType, TResult extends ZodType = ZodType, const TFeatures extends ReadonlyArray<AnyStepFeature> = never[], TEnv extends EnvRecord = EnvRecord, const TErrors extends string = never>(config: Omit<DefineStepInput<TInput, TResult, TEnv>, "features" | "errors" | "retry"> & {
130
+ features?: TFeatures;
131
+ errors?: readonly TErrors[];
132
+ retry?: readonly {
133
+ on: readonly (BuiltInError | TErrors)[];
134
+ maxAttempts: number;
135
+ }[];
136
+ }): StepHandle<TInput["_output"], DefineStepResult<TResult, TFeatures>, TErrors>;
137
+ export {};