@kici-dev/sdk 0.1.16 → 0.1.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 (70) hide show
  1. package/dist/api-types.d.ts +25 -1
  2. package/dist/api-types.js +29 -3
  3. package/dist/approval.js +1 -1
  4. package/dist/cache-types.js +1 -1
  5. package/dist/context.d.ts +75 -2
  6. package/dist/context.js +14 -2
  7. package/dist/dynamic-group.js +1 -1
  8. package/dist/errors.js +3 -1
  9. package/dist/events/define-event.js +1 -1
  10. package/dist/events/event-payloads.js +1 -1
  11. package/dist/events/event-payloads.test-d.js +1 -1
  12. package/dist/events/index.js +1 -1
  13. package/dist/events/types.js +1 -1
  14. package/dist/fixture.js +1 -1
  15. package/dist/hooks/index.js +1 -1
  16. package/dist/hooks/types.js +1 -1
  17. package/dist/idempotent.js +1 -1
  18. package/dist/index.d.ts +10 -5
  19. package/dist/index.js +7 -4
  20. package/dist/job.js +21 -7
  21. package/dist/matrix/expand.d.ts +1 -24
  22. package/dist/matrix/expand.js +2 -65
  23. package/dist/matrix/index.js +1 -1
  24. package/dist/matrix/types.d.ts +2 -19
  25. package/dist/matrix/types.js +1 -1
  26. package/dist/needs-context.d.ts +32 -0
  27. package/dist/needs-context.js +44 -0
  28. package/dist/outputs.d.ts +12 -0
  29. package/dist/outputs.js +37 -2
  30. package/dist/provenance-types.d.ts +38 -0
  31. package/dist/provenance-types.js +10 -0
  32. package/dist/rules/evaluator.js +1 -1
  33. package/dist/rules/index.js +1 -1
  34. package/dist/rules/rule.js +1 -1
  35. package/dist/rules/types.js +1 -1
  36. package/dist/secrets.js +1 -1
  37. package/dist/step.js +1 -1
  38. package/dist/triggers/comment.js +1 -1
  39. package/dist/triggers/create.js +1 -1
  40. package/dist/triggers/delete.js +1 -1
  41. package/dist/triggers/dispatch.js +1 -1
  42. package/dist/triggers/fork.js +1 -1
  43. package/dist/triggers/generic-webhook.js +1 -1
  44. package/dist/triggers/index.js +1 -1
  45. package/dist/triggers/job-complete.js +1 -1
  46. package/dist/triggers/kici-event.js +1 -1
  47. package/dist/triggers/lifecycle.js +1 -1
  48. package/dist/triggers/pr.js +1 -1
  49. package/dist/triggers/push.js +1 -1
  50. package/dist/triggers/release.js +1 -1
  51. package/dist/triggers/review-comment.js +1 -1
  52. package/dist/triggers/review.js +1 -1
  53. package/dist/triggers/schedule.js +1 -1
  54. package/dist/triggers/star.js +1 -1
  55. package/dist/triggers/status.js +1 -1
  56. package/dist/triggers/tag.js +1 -1
  57. package/dist/triggers/types.js +1 -1
  58. package/dist/triggers/watch.js +1 -1
  59. package/dist/triggers/webhook.js +1 -1
  60. package/dist/triggers/workflow-complete.js +1 -1
  61. package/dist/triggers/workflow-run.js +1 -1
  62. package/dist/types.d.ts +162 -28
  63. package/dist/types.js +25 -5
  64. package/dist/validation/dag.js +1 -1
  65. package/dist/validation/index.js +1 -1
  66. package/dist/wait-for.js +1 -1
  67. package/dist/workflow.js +1 -1
  68. package/package.json +4 -5
  69. package/sbom.spdx.json +229 -179
  70. /package/dist/{chunk-gOLHoazu.js → chunk-BTugEXQM.js} +0 -0
@@ -8,6 +8,8 @@
8
8
  * 1. Add the typed method here (with param + return types)
9
9
  * 2. Register the handler in the orchestrator's AgentApiRegistry
10
10
  */
11
+ import { type OidcTokenResult } from '@kici-dev/engine/protocol/messages/oidc-token-relay';
12
+ export type { OidcTokenResult };
11
13
  export interface InfrastructureListResult {
12
14
  scalers: Array<{
13
15
  name: string;
@@ -28,9 +30,23 @@ export interface InfrastructureApi {
28
30
  /** List available scalers and connected agents. */
29
31
  list(): Promise<InfrastructureListResult>;
30
32
  }
33
+ export interface OidcApi {
34
+ /**
35
+ * Request a short-lived OIDC ID token for the current job, bound to
36
+ * `audience`. The token's identity claims (repository, ref, sha, run/job id)
37
+ * are derived server-side from the build context and cannot be spoofed by the
38
+ * workflow. The token is automatically masked in step logs. Only available
39
+ * inside a running job step (throws otherwise).
40
+ */
41
+ token(opts: {
42
+ audience: string;
43
+ }): Promise<OidcTokenResult>;
44
+ }
31
45
  export interface KiciApi {
32
46
  /** Query orchestrator infrastructure (scalers, agents). */
33
47
  infrastructure: InfrastructureApi;
48
+ /** Request short-lived OIDC ID tokens for the current job (build provenance). */
49
+ oidc: OidcApi;
34
50
  }
35
51
  /**
36
52
  * Low-level transport function used to implement KiciApi.
@@ -42,6 +58,14 @@ export type KiciApiTransport = (method: string, params?: Record<string, unknown>
42
58
  *
43
59
  * This is the bridge between the typed SDK interface and the untyped WS/IPC
44
60
  * transport. Each method call is mapped to { method: 'namespace.method', params }.
61
+ *
62
+ * `jobCtx` carries the per-job execution context (the job the step is running
63
+ * in). It is supplied by the agent's sandbox step context so `oidc.token()` can
64
+ * bind its request to that job; the workflow author never supplies it. It is
65
+ * omitted for contexts with no running job (e.g. DynamicJobFn re-evaluation),
66
+ * where `oidc.token()` throws rather than silently misattributing a token.
45
67
  */
46
- export declare function buildKiciApi(transport: KiciApiTransport): KiciApi;
68
+ export declare function buildKiciApi(transport: KiciApiTransport, jobCtx?: {
69
+ jobId: string;
70
+ }): KiciApi;
47
71
  //# sourceMappingURL=api-types.d.ts.map
package/dist/api-types.js CHANGED
@@ -1,13 +1,39 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
+ import { OIDC_TOKEN_REQUEST_METHOD } from "@kici-dev/engine/protocol/messages/oidc-token-relay";
2
3
  //#region src/api-types.ts
3
4
  /**
5
+ * Typed KiCI API available to workflows via ctx.kici.
6
+ *
7
+ * Each namespace groups related methods. Under the hood, calls are serialized
8
+ * to { method: 'namespace.method', params } and sent over the agent's WS
9
+ * connection to the orchestrator. Adding a new API method:
10
+ *
11
+ * 1. Add the typed method here (with param + return types)
12
+ * 2. Register the handler in the orchestrator's AgentApiRegistry
13
+ */
14
+ /**
4
15
  * Build a typed KiciApi proxy from a raw transport function.
5
16
  *
6
17
  * This is the bridge between the typed SDK interface and the untyped WS/IPC
7
18
  * transport. Each method call is mapped to { method: 'namespace.method', params }.
19
+ *
20
+ * `jobCtx` carries the per-job execution context (the job the step is running
21
+ * in). It is supplied by the agent's sandbox step context so `oidc.token()` can
22
+ * bind its request to that job; the workflow author never supplies it. It is
23
+ * omitted for contexts with no running job (e.g. DynamicJobFn re-evaluation),
24
+ * where `oidc.token()` throws rather than silently misattributing a token.
8
25
  */
9
- function buildKiciApi(transport) {
10
- return { infrastructure: { list: () => transport("infrastructure.list", {}) } };
26
+ function buildKiciApi(transport, jobCtx) {
27
+ return {
28
+ infrastructure: { list: () => transport("infrastructure.list", {}) },
29
+ oidc: { token: (opts) => {
30
+ if (!jobCtx) return Promise.reject(/* @__PURE__ */ new Error("ctx.kici.oidc.token() is only available inside a running job step"));
31
+ return transport(OIDC_TOKEN_REQUEST_METHOD, {
32
+ jobId: jobCtx.jobId,
33
+ audience: opts.audience
34
+ });
35
+ } }
36
+ };
11
37
  }
12
38
  //#endregion
13
39
  export { buildKiciApi };
package/dist/approval.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  //#region src/approval.ts
3
3
  /** Normalize any `RequireApproval` form into `{ clauses, reason?, timeoutSeconds? }`. */
4
4
  function normalizeRequireApproval(r) {
@@ -1,4 +1,4 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  import { z } from "zod";
3
3
  //#region src/cache-types.ts
4
4
  /** Zod schema validating a CacheSpec at compile/serialize time. */
package/dist/context.d.ts CHANGED
@@ -19,6 +19,52 @@ export interface JobInfo {
19
19
  name: string;
20
20
  runsOn: string;
21
21
  }
22
+ /**
23
+ * Facts about the agent a `runsOnAll` host-fanout child is pinned to, exposed
24
+ * as `ctx.agent`. Present only for jobs that use `runsOnAll`.
25
+ */
26
+ export interface AgentInfo {
27
+ /** Hostname of the agent. */
28
+ host: string;
29
+ /** The agent's label set. */
30
+ labels: readonly string[];
31
+ /** Operating-system platform (os.platform()). */
32
+ platform?: string;
33
+ /** CPU architecture (os.arch()). */
34
+ arch?: string;
35
+ }
36
+ /**
37
+ * Outputs of a matrix job as seen by a downstream `needs:` consumer.
38
+ * A downstream that consumes a matrix upstream receives this envelope instead of
39
+ * a flat outputs object, identically under `kici run local` and the remote path.
40
+ */
41
+ export interface MatrixJobOutputs<T = Record<string, unknown>> {
42
+ /** Keyed by the combination suffix (the text inside `(...)` of the child name). */
43
+ byMatrix: Record<string, T>;
44
+ /** Last-write-wins flat merge across children, in child (name) order. */
45
+ merged: T;
46
+ }
47
+ /** Runtime discriminator: true when `ctx.jobOutputs(ref)` returned a matrix envelope. */
48
+ export declare function isMatrixJobOutputs(value: Record<string, unknown> | MatrixJobOutputs | HostJobOutputs): value is MatrixJobOutputs;
49
+ /**
50
+ * Outputs of a `runsOnAll` host-fanout job as seen by a downstream `needs:`
51
+ * consumer. Keyed by hostname. Unlike {@link MatrixJobOutputs}, the summary does
52
+ * NOT collapse to a last-write-wins scalar (a fleet footgun): `summary.outputs`
53
+ * is an array view across hosts, and `succeededHosts`/`failedHosts` name the
54
+ * per-host outcome.
55
+ */
56
+ export interface HostJobOutputs<T = Record<string, unknown>> {
57
+ /** Keyed by hostname. */
58
+ byHost: Record<string, T>;
59
+ summary: {
60
+ succeededHosts: string[];
61
+ failedHosts: string[];
62
+ /** Per output key, every host's value (array view; never a collapsing scalar). */
63
+ outputs: Record<string, unknown[]>;
64
+ };
65
+ }
66
+ /** Runtime discriminator: true when `ctx.jobOutputs(ref)` returned a host envelope. */
67
+ export declare function isHostJobOutputs(value: Record<string, unknown> | MatrixJobOutputs | HostJobOutputs): value is HostJobOutputs;
22
68
  /**
23
69
  * Augmentable interface for known secret keys.
24
70
  * When augmented via `kici types` (.d.ts generation), narrows get/expose key parameter.
@@ -80,6 +126,17 @@ export interface StepContext<TInputs = Record<string, unknown>> {
80
126
  * - Undefined for jobs without matrix configuration
81
127
  */
82
128
  matrix?: MatrixValues;
129
+ /**
130
+ * Hostname of the agent this job instance is running on.
131
+ * Set only for jobs that use `runsOnAll` (host fan-out — one pinned execution
132
+ * per matching host). Undefined for jobs without host fan-out.
133
+ */
134
+ host?: string;
135
+ /**
136
+ * Facts about the agent this job instance is pinned to (hostname, labels,
137
+ * platform, arch). Set only for jobs that use `runsOnAll`. Undefined otherwise.
138
+ */
139
+ agent?: AgentInfo;
83
140
  /**
84
141
  * Raw webhook payload from the git provider.
85
142
  * Contains the full, unmodified payload as received from the webhook.
@@ -158,14 +215,22 @@ export interface StepContext<TInputs = Record<string, unknown>> {
158
215
  } | ((...args: any[]) => any)): T;
159
216
  /**
160
217
  * Resolve outputs from a preceding job by reference.
161
- * Returns the job's collected outputs (step-keyed for multi-step, flat for run shorthand).
218
+ *
219
+ * For a plain upstream this returns the job's collected outputs (step-keyed
220
+ * for multi-step, flat for run shorthand). For a **matrix** upstream it returns
221
+ * a {@link MatrixJobOutputs} envelope `{ byMatrix, merged }` keyed by the
222
+ * combination suffix — identical under `kici run local` and the remote path.
223
+ * Use {@link isMatrixJobOutputs} (or `'byMatrix' in result`) to discriminate.
162
224
  *
163
225
  * @example
164
226
  * const setupOutputs = ctx.jobOutputs(setupJob);
227
+ * @example
228
+ * const m = ctx.jobOutputs(buildMatrixJob);
229
+ * if (isMatrixJobOutputs(m)) console.log(m.byMatrix['linux, arm64']);
165
230
  */
166
231
  jobOutputs(ref: {
167
232
  name: string;
168
- }): Record<string, unknown>;
233
+ }): Record<string, unknown> | MatrixJobOutputs | HostJobOutputs;
169
234
  /**
170
235
  * Publish a secret output value from this job.
171
236
  * Secret outputs are encrypted before leaving the agent and can be consumed
@@ -188,6 +253,14 @@ export interface StepContext<TInputs = Record<string, unknown>> {
188
253
  * under `spec.key` (immutable — first save wins). Scoped per org + ref.
189
254
  */
190
255
  cache: import('./cache-types.js').CacheApi;
256
+ /**
257
+ * Build, sign, and persist a KiCI build-provenance attestation for a produced
258
+ * artifact. The in-toto statement's identity is derived from a Platform-minted
259
+ * identity token (unforgeable); the bundle is signed with an ephemeral key and
260
+ * is offline-verifiable. Pass the artifact via a precomputed digest or a path
261
+ * the agent digests with SHA-256.
262
+ */
263
+ attestProvenance(opts: import('./provenance-types.js').AttestProvenanceOptions): Promise<import('./provenance-types.js').AttestProvenanceResult>;
191
264
  }
192
265
  export {};
193
266
  //# sourceMappingURL=context.d.ts.map
package/dist/context.js CHANGED
@@ -1,2 +1,14 @@
1
- import "./chunk-gOLHoazu.js";
2
- export {};
1
+ import "./chunk-BTugEXQM.js";
2
+ //#region src/context.ts
3
+ /** Runtime discriminator: true when `ctx.jobOutputs(ref)` returned a matrix envelope. */
4
+ function isMatrixJobOutputs(value) {
5
+ return typeof value === "object" && value !== null && "byMatrix" in value && "merged" in value && typeof value.byMatrix === "object";
6
+ }
7
+ /** Runtime discriminator: true when `ctx.jobOutputs(ref)` returned a host envelope. */
8
+ function isHostJobOutputs(value) {
9
+ return typeof value === "object" && value !== null && "byHost" in value && "summary" in value && typeof value.byHost === "object";
10
+ }
11
+ //#endregion
12
+ export { isHostJobOutputs, isMatrixJobOutputs };
13
+
14
+ //# sourceMappingURL=context.js.map
@@ -1,4 +1,4 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  //#region src/dynamic-group.ts
3
3
  /**
4
4
  * Dynamic group helpers for cross-domain needs.
package/dist/errors.js CHANGED
@@ -1,9 +1,11 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  //#region src/errors.ts
3
3
  /**
4
4
  * Thrown when accessing a secret key that does not exist in the flat secrets proxy.
5
5
  */
6
6
  var SecretNotFoundError = class extends Error {
7
+ key;
8
+ availableKeys;
7
9
  constructor(key, availableKeys) {
8
10
  super(`Secret "${key}" not found. Available keys: ${availableKeys.join(", ") || "(none)"}. Use ctx.secrets.has('${key}') to check existence, or await ctx.secrets.get('${key}') in a try/catch.`);
9
11
  this.key = key;
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  //#region src/events/define-event.ts
3
3
  /**
4
4
  * Create a typed event definition with a Zod schema.
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  //#region src/events/event-payloads.ts
3
3
  /**
4
4
  * Narrow an EventPayload to a specific event type.
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  import { describe, expectTypeOf, it } from "vitest";
3
3
  //#region src/events/event-payloads.test-d.ts
4
4
  describe("EventPayload narrowing", () => {
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  import { isEventType } from "./event-payloads.js";
3
3
  import { defineEvent } from "./define-event.js";
4
4
  export { defineEvent, isEventType };
@@ -1,2 +1,2 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  export {};
package/dist/fixture.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  //#region src/fixture.ts
3
3
  /**
4
4
  * Create a test fixture definition.
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  //#region src/hooks/index.ts
3
3
  /**
4
4
  * Normalize HookInput to extract run function and optional timeout.
@@ -1,2 +1,2 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  export {};
@@ -1,4 +1,4 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  import { step } from "./step.js";
3
3
  import { runIdempotentStep } from "@kici-dev/core/idempotency";
4
4
  //#region src/idempotent.ts
package/dist/index.d.ts CHANGED
@@ -13,21 +13,26 @@ export { isEventType } from './rules/index.js';
13
13
  export type { Rule, RuleContext, RuleCheckFn, RuleResult, EventPayload, RuleEvaluationResult, EventBase, PullRequestEventPayload, PushEventPayload, TagEventPayload, CommentEventPayload, ReviewEventPayload, ReviewCommentEventPayload, ReleaseEventPayload, DispatchEventPayload, CreateEventPayload, DeleteEventPayload, StatusEventPayload, WorkflowRunEventPayload, ForkEventPayload, StarEventPayload, WatchEventPayload, WebhookEventPayload, KiciEventPayload, WorkflowCompleteEventPayload, JobCompleteEventPayload, GenericWebhookEventPayload, ScheduleEventPayload, LifecycleEventPayload, GitHubRepository, GitHubUser, GitHubPullRequest, GitHubCommit, GitHubComment, GitHubReview, GitHubRelease, } from './rules/index.js';
14
14
  export { validateDag } from './validation/index.js';
15
15
  export type { DagNode, DagValidationResult } from './validation/index.js';
16
- export type { SourceLocation, OutputProxy, Step, StepOptions, StepRunFn, BareStepFn, StepInput, OutputSchema, InferOutputs, Job, JobOptions, GenericInitConfig, ContainerConfig, RunsOnSelector, RunsOn, Workflow, WorkflowOptions, Registry, Trigger, DynamicJobFn, DynamicJobContext, JobOrFactory, } from './types.js';
17
- export { isDynamicJobFn, dynamicJob, getDynamicJobGroup, DYNAMIC_JOB_GROUP_TAG } from './types.js';
18
- export type { TaggedDynamicJobFn } from './types.js';
16
+ export type { SourceLocation, OutputProxy, Step, StepOptions, StepRunFn, BareStepFn, StepInput, OutputSchema, InferOutputs, Job, JobOptions, GenericInitConfig, MiseInitConfig, InitPreset, InitItem, InitConfig, ContainerConfig, RunsOnSelector, RunsOn, Workflow, WorkflowOptions, Registry, Trigger, DynamicJobFn, DynamicJobContext, JobOrFactory, } from './types.js';
17
+ export { isDynamicJobFn, dynamicJob, getDynamicJobGroup, getDynamicJobNeeds, DYNAMIC_JOB_GROUP_TAG, DYNAMIC_JOB_NEEDS_TAG, } from './types.js';
18
+ export type { TaggedDynamicJobFn, ResultAwareDynamicJobConfig, ResultAwareDynamicJobFn, DynamicJobNeed, } from './types.js';
19
+ export { buildNeedsContext } from './needs-context.js';
20
+ export type { UpstreamSnapshot, NeedsContext, NeedEntry, GroupNeedEntry } from './needs-context.js';
19
21
  export { CacheSpecSchema, normalizeCacheSpecs } from './cache-types.js';
20
22
  export type { CacheSpec, CacheInput } from './cache-types.js';
21
23
  export type { CacheRestoreResult, CacheApi } from './cache-types.js';
24
+ export { provenanceSubjectIsPath } from './provenance-types.js';
25
+ export type { AttestProvenanceOptions, AttestProvenanceResult, ProvenanceSubjectInput, } from './provenance-types.js';
22
26
  export { dynamicGroup, isDynamicGroupRef, DYNAMIC_GROUP_TAG } from './dynamic-group.js';
23
27
  export type { DynamicGroupRef } from './dynamic-group.js';
24
- export type { StepContext, Logger, WorkflowInfo, JobInfo, RepoInfo, StepSecretsTyped, KnownSecretKeys, } from './context.js';
28
+ export type { StepContext, Logger, WorkflowInfo, JobInfo, AgentInfo, MatrixJobOutputs, HostJobOutputs, RepoInfo, StepSecretsTyped, KnownSecretKeys, } from './context.js';
29
+ export { isMatrixJobOutputs, isHostJobOutputs } from './context.js';
25
30
  export { buildKiciApi } from './api-types.js';
26
31
  export type { KiciApi, KiciApiTransport, InfrastructureApi, InfrastructureListResult, } from './api-types.js';
27
32
  export { SecretNotFoundError } from './errors.js';
28
33
  export { createStepSecrets } from './secrets.js';
29
34
  export type { StepSecrets, TrackedStepSecrets, SecretMeta, SecretFileOptions, MountedFile, StepSecretsFileHost, StepSecretsFileWiring, StepSecretsHandle, StepSecretMountKind, StepSecretMountRecord, } from './secrets.js';
30
- export { createStepOutputProxy, createJobOutputProxy, resolveStepOutputs, resolveJobOutputs, setStepOutputsMap, setJobOutputsMap, setStepRefMap, getStepOutputsMap, getJobOutputsMap, getStepRefMap, } from './outputs.js';
35
+ export { createStepOutputProxy, createJobOutputProxy, createSnapshotOutputProxy, resolveStepOutputs, resolveJobOutputs, setStepOutputsMap, setJobOutputsMap, setStepRefMap, getStepOutputsMap, getJobOutputsMap, getStepRefMap, } from './outputs.js';
31
36
  export type { OutputsMap, StepRefMap } from './outputs.js';
32
37
  export type { StaticMatrixArray, StaticMatrixObject, DynamicMatrixFn, DynamicMatrixContext, Matrix, MatrixInclude, MatrixExclude, MatrixValues, } from './matrix/index.js';
33
38
  export { isStaticArray, isStaticObject, isDynamicFunction } from './matrix/index.js';
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  import { buildKiciApi } from "./api-types.js";
3
3
  import { normalizeRequireApproval } from "./approval.js";
4
4
  import { CacheSpecSchema, normalizeCacheSpecs } from "./cache-types.js";
5
+ import { isHostJobOutputs, isMatrixJobOutputs } from "./context.js";
5
6
  import { DYNAMIC_GROUP_TAG, dynamicGroup, isDynamicGroupRef } from "./dynamic-group.js";
6
7
  import { SecretNotFoundError } from "./errors.js";
7
8
  import { fixture } from "./fixture.js";
8
- import { createJobOutputProxy, createStepOutputProxy, getJobOutputsMap, getStepOutputsMap, getStepRefMap, resolveJobOutputs, resolveStepOutputs, setJobOutputsMap, setStepOutputsMap, setStepRefMap } from "./outputs.js";
9
+ import { createJobOutputProxy, createSnapshotOutputProxy, createStepOutputProxy, getJobOutputsMap, getStepOutputsMap, getStepRefMap, resolveJobOutputs, resolveStepOutputs, setJobOutputsMap, setStepOutputsMap, setStepRefMap } from "./outputs.js";
9
10
  import { step } from "./step.js";
10
11
  import { idempotent, idempotentStep } from "./idempotent.js";
11
12
  import { job } from "./job.js";
@@ -40,7 +41,9 @@ import { isEventType } from "./events/event-payloads.js";
40
41
  import "./rules/index.js";
41
42
  import { validateDag } from "./validation/dag.js";
42
43
  import "./validation/index.js";
43
- import { DYNAMIC_JOB_GROUP_TAG, dynamicJob, getDynamicJobGroup, isDynamicJobFn } from "./types.js";
44
+ import { DYNAMIC_JOB_GROUP_TAG, DYNAMIC_JOB_NEEDS_TAG, dynamicJob, getDynamicJobGroup, getDynamicJobNeeds, isDynamicJobFn } from "./types.js";
45
+ import { buildNeedsContext } from "./needs-context.js";
46
+ import { provenanceSubjectIsPath } from "./provenance-types.js";
44
47
  import { createStepSecrets } from "./secrets.js";
45
48
  import { isDynamicFunction, isStaticArray, isStaticObject } from "./matrix/types.js";
46
49
  import { applyIncludeExclude, expandMatrix } from "./matrix/expand.js";
@@ -49,4 +52,4 @@ import { defineEvent } from "./events/define-event.js";
49
52
  import "./events/index.js";
50
53
  import { WaitForTimeoutError, waitFor, waitForStep } from "./wait-for.js";
51
54
  import { z } from "zod";
52
- export { CacheSpecSchema, DYNAMIC_GROUP_TAG, DYNAMIC_JOB_GROUP_TAG, SecretNotFoundError, WaitForTimeoutError, afterStep, applyIncludeExclude, beforeStep, buildKiciApi, cleanup, comment, create, createJobOutputProxy, createStepOutputProxy, createStepSecrets, defineEvent, del as delete, dispatch, dynamicGroup, dynamicJob, evaluateRules, expandMatrix, fixture, fork, genericWebhook, getDynamicJobGroup, getJobOutputsMap, getStepOutputsMap, getStepRefMap, idempotent, idempotentStep, isDynamicFunction, isDynamicGroupRef, isDynamicJobFn, isEventType, isStaticArray, isStaticObject, job, jobComplete, kiciEvent, lifecycle, normalizeCacheSpecs, normalizeRequireApproval, onCancel, onFailure, onSuccess, pr, push, release, resolveJobOutputs, resolveStepOutputs, review, reviewComment, rule, schedule, setJobOutputsMap, setStepOutputsMap, setStepRefMap, skip, star, status, step, tag, validateDag, waitFor, waitForStep, watch, webhook, workflow, workflowComplete, workflowRun, z };
55
+ export { CacheSpecSchema, DYNAMIC_GROUP_TAG, DYNAMIC_JOB_GROUP_TAG, DYNAMIC_JOB_NEEDS_TAG, SecretNotFoundError, WaitForTimeoutError, afterStep, applyIncludeExclude, beforeStep, buildKiciApi, buildNeedsContext, cleanup, comment, create, createJobOutputProxy, createSnapshotOutputProxy, createStepOutputProxy, createStepSecrets, defineEvent, del as delete, dispatch, dynamicGroup, dynamicJob, evaluateRules, expandMatrix, fixture, fork, genericWebhook, getDynamicJobGroup, getDynamicJobNeeds, getJobOutputsMap, getStepOutputsMap, getStepRefMap, idempotent, idempotentStep, isDynamicFunction, isDynamicGroupRef, isDynamicJobFn, isEventType, isHostJobOutputs, isMatrixJobOutputs, isStaticArray, isStaticObject, job, jobComplete, kiciEvent, lifecycle, normalizeCacheSpecs, normalizeRequireApproval, onCancel, onFailure, onSuccess, pr, provenanceSubjectIsPath, push, release, resolveJobOutputs, resolveStepOutputs, review, reviewComment, rule, schedule, setJobOutputsMap, setStepOutputsMap, setStepRefMap, skip, star, status, step, tag, validateDag, waitFor, waitForStep, watch, webhook, workflow, workflowComplete, workflowRun, z };
package/dist/job.js CHANGED
@@ -1,15 +1,22 @@
1
- import "./chunk-gOLHoazu.js";
1
+ import "./chunk-BTugEXQM.js";
2
2
  import { createJobOutputProxy } from "./outputs.js";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/job.ts
5
+ /** A typed preset is a `'mise'` string or a `{ mise }` object — neither carries `run`. */
6
+ function isPreset(item) {
7
+ return item === "mise" || typeof item === "object" && item !== null && "mise" in item;
8
+ }
5
9
  /**
6
- * Validate a job's `init` config. `undefined` / `false` are no-ops; every
7
- * remaining spec (one, or each element of an array) must carry a non-empty
8
- * `run` command. Throws with the offending index when validation fails.
10
+ * Validate a job's `init` config. `undefined` / `false` / `'auto'` are no-ops;
11
+ * typed presets (`'mise'` / `{ mise }`) carry no `run`, so they need no check.
12
+ * Every remaining generic spec (one, or each element of an array) must carry a
13
+ * non-empty `run` command. Throws with the offending index when validation fails.
9
14
  */
10
15
  function validateInit(init, jobName) {
11
- if (init === void 0 || init === false) return;
12
- (Array.isArray(init) ? init : [init]).forEach((spec, i) => {
16
+ if (init === void 0 || init === false || init === "auto") return;
17
+ (Array.isArray(init) ? init : [init]).forEach((item, i) => {
18
+ if (isPreset(item)) return;
19
+ const spec = item;
13
20
  if (typeof spec.run !== "string" || spec.run.trim().length === 0) throw new Error(`job('${jobName}'): init[${i}].run must be a non-empty command`);
14
21
  });
15
22
  }
@@ -25,10 +32,17 @@ function job(nameOrOptions, maybeOptions) {
25
32
  steps = [options.run];
26
33
  }
27
34
  validateInit(options.init, name);
35
+ if (options.runsOn !== void 0 && options.runsOnAll !== void 0) throw new Error(`job('${name}'): runsOn and runsOnAll are mutually exclusive`);
36
+ if (options.runsOn === void 0 && options.runsOnAll === void 0) throw new Error(`job('${name}'): one of runsOn or runsOnAll is required`);
37
+ if (options.onUnreachable !== void 0 && options.runsOnAll === void 0) console.warn(`[kici] job('${name}'): onUnreachable is ignored without runsOnAll`);
28
38
  return {
29
39
  _tag: "Job",
30
40
  name,
31
- runsOn: options.runsOn,
41
+ ...options.runsOn !== void 0 && { runsOn: options.runsOn },
42
+ ...options.runsOnAll !== void 0 && { runsOnAll: options.runsOnAll },
43
+ ...options.onUnreachable !== void 0 && { onUnreachable: options.onUnreachable },
44
+ ...options.maxParallel !== void 0 && { maxParallel: options.maxParallel },
45
+ ...options.failFast !== void 0 && { failFast: options.failFast },
32
46
  steps,
33
47
  needs: options.needs,
34
48
  rules: options.rules,
@@ -1,25 +1,2 @@
1
- import type { StaticMatrixArray, StaticMatrixObject, MatrixInclude, MatrixExclude, MatrixValues } from './types.js';
2
- /**
3
- * Expand single-dimension matrix (array form) to MatrixValues array.
4
- * Each value becomes {value: string}.
5
- */
6
- export declare function expandSingleDimension(matrix: StaticMatrixArray): MatrixValues[];
7
- /**
8
- * Expand multi-dimensional matrix (object form) to MatrixValues array.
9
- * Uses fast-cartesian to compute cartesian product of all dimensions.
10
- * Dimension names are sorted for deterministic output.
11
- */
12
- export declare function expandMultiDimension(matrix: StaticMatrixObject): MatrixValues[];
13
- /**
14
- * Unified expand function that dispatches to single or multi-dimensional expansion.
15
- */
16
- export declare function expandMatrix(matrix: StaticMatrixArray | StaticMatrixObject): MatrixValues[];
17
- /**
18
- * Apply include/exclude modifications to expanded matrix combinations.
19
- * Per CONTEXT.md: exclude first (remove matching), then include (add new).
20
- *
21
- * Exclude matches if ALL specified dimensions match.
22
- * Include adds new combinations if they don't already exist.
23
- */
24
- export declare function applyIncludeExclude(expanded: MatrixValues[], include?: MatrixInclude[], exclude?: MatrixExclude[]): MatrixValues[];
1
+ export { expandSingleDimension, expandMultiDimension, expandMatrix, applyIncludeExclude, } from '@kici-dev/engine';
25
2
  //# sourceMappingURL=expand.d.ts.map
@@ -1,66 +1,3 @@
1
- import "../chunk-gOLHoazu.js";
2
- import fastCartesian from "fast-cartesian";
3
- //#region src/matrix/expand.ts
4
- /**
5
- * Expand single-dimension matrix (array form) to MatrixValues array.
6
- * Each value becomes {value: string}.
7
- */
8
- function expandSingleDimension(matrix) {
9
- return matrix.map((value) => ({ value }));
10
- }
11
- /**
12
- * Expand multi-dimensional matrix (object form) to MatrixValues array.
13
- * Uses fast-cartesian to compute cartesian product of all dimensions.
14
- * Dimension names are sorted for deterministic output.
15
- */
16
- function expandMultiDimension(matrix) {
17
- const dimensions = Object.entries(matrix);
18
- if (dimensions.length === 0) return [];
19
- dimensions.sort((a, b) => a[0].localeCompare(b[0]));
20
- const names = dimensions.map(([name]) => name);
21
- return fastCartesian(dimensions.map(([, values]) => values)).map((combo) => {
22
- const result = {};
23
- names.forEach((name, idx) => {
24
- result[name] = combo[idx];
25
- });
26
- return result;
27
- });
28
- }
29
- /**
30
- * Unified expand function that dispatches to single or multi-dimensional expansion.
31
- */
32
- function expandMatrix(matrix) {
33
- if (Array.isArray(matrix)) return expandSingleDimension(matrix);
34
- return expandMultiDimension(matrix);
35
- }
36
- /**
37
- * Apply include/exclude modifications to expanded matrix combinations.
38
- * Per CONTEXT.md: exclude first (remove matching), then include (add new).
39
- *
40
- * Exclude matches if ALL specified dimensions match.
41
- * Include adds new combinations if they don't already exist.
42
- */
43
- function applyIncludeExclude(expanded, include, exclude) {
44
- let result = [...expanded];
45
- if (exclude && exclude.length > 0) result = result.filter((combo) => {
46
- return !exclude.some((excl) => {
47
- const exclEntries = Object.entries(excl);
48
- if (exclEntries.length === 0) return false;
49
- return exclEntries.every(([key, value]) => combo[key] === value);
50
- });
51
- });
52
- if (include && include.length > 0) for (const incl of include) {
53
- const inclKeys = Object.keys(incl);
54
- if (inclKeys.length === 0) continue;
55
- if (!result.some((combo) => {
56
- const comboKeys = Object.keys(combo);
57
- if (inclKeys.length !== comboKeys.length) return false;
58
- return inclKeys.every((key) => combo[key] === incl[key]);
59
- })) result.push(incl);
60
- }
61
- return result;
62
- }
63
- //#endregion
1
+ import "../chunk-BTugEXQM.js";
2
+ import { applyIncludeExclude, expandMatrix, expandMultiDimension, expandSingleDimension } from "@kici-dev/engine";
64
3
  export { applyIncludeExclude, expandMatrix, expandMultiDimension, expandSingleDimension };
65
-
66
- //# sourceMappingURL=expand.js.map
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  import { isDynamicFunction, isStaticArray, isStaticObject } from "./types.js";
3
3
  import { applyIncludeExclude, expandMatrix } from "./expand.js";
4
4
  export { applyIncludeExclude, expandMatrix, isDynamicFunction, isStaticArray, isStaticObject };
@@ -1,9 +1,7 @@
1
1
  import type { $ as Shell } from 'zx';
2
2
  import type { Logger } from '../context.js';
3
- /** Single-dimension static matrix: array of values */
4
- export type StaticMatrixArray = string[];
5
- /** Multi-dimensional static matrix: named dimensions with values */
6
- export type StaticMatrixObject = Record<string, string[]>;
3
+ export type { StaticMatrixArray, StaticMatrixObject, MatrixInclude, MatrixExclude, MatrixValues, } from '@kici-dev/engine';
4
+ import type { StaticMatrixArray, StaticMatrixObject } from '@kici-dev/engine';
7
5
  /**
8
6
  * Context passed to dynamic matrix functions.
9
7
  * Uses destructured form: async ({$, ctx, log, env}) => values
@@ -36,21 +34,6 @@ export interface DynamicMatrixContext {
36
34
  export type DynamicMatrixFn = (context: DynamicMatrixContext) => Promise<StaticMatrixArray | StaticMatrixObject>;
37
35
  /** Union type for all matrix forms */
38
36
  export type Matrix = StaticMatrixArray | StaticMatrixObject | DynamicMatrixFn;
39
- /** Include entries for adding specific matrix combinations */
40
- export type MatrixInclude = Record<string, string>;
41
- /** Exclude entries for removing specific matrix combinations */
42
- export type MatrixExclude = Record<string, string>;
43
- /**
44
- * Matrix values as exposed to steps.
45
- * Single-dimension: {value: 'linux'}
46
- * Multi-dimensional: {os: 'linux', node: '18'}
47
- */
48
- export interface MatrixValues {
49
- /** Single-dimension: the value */
50
- value?: string;
51
- /** Multi-dimensional: named properties */
52
- [dimension: string]: string | undefined;
53
- }
54
37
  /** Type guard for static array matrices */
55
38
  export declare function isStaticArray(m: Matrix): m is StaticMatrixArray;
56
39
  /** Type guard for static object matrices */
@@ -1,4 +1,4 @@
1
- import "../chunk-gOLHoazu.js";
1
+ import "../chunk-BTugEXQM.js";
2
2
  //#region src/matrix/types.ts
3
3
  /** Type guard for static array matrices */
4
4
  function isStaticArray(m) {
@@ -0,0 +1,32 @@
1
+ import type { OutputProxy, DynamicJobNeed } from './types.js';
2
+ /**
3
+ * Frozen snapshot of upstream outputs, captured once at first eval of a
4
+ * result-aware dynamic generator and replayed unchanged on re-eval.
5
+ *
6
+ * - `jobs` maps an upstream job name to its outputs record.
7
+ * - `groups` maps a dynamic group name to its ordered member job names.
8
+ */
9
+ export interface UpstreamSnapshot {
10
+ jobs: Record<string, Record<string, unknown>>;
11
+ groups: Record<string, string[]>;
12
+ }
13
+ /** One entry in the array exposed for a `dynamicGroup(...)` need. */
14
+ export interface GroupNeedEntry {
15
+ name: string;
16
+ result: OutputProxy<any>;
17
+ }
18
+ /** A single-job need exposes `{ result }`; a group need exposes an ordered array. */
19
+ export type NeedEntry = {
20
+ result: OutputProxy<any>;
21
+ } | GroupNeedEntry[];
22
+ /** The resolved `ctx.needs` map keyed by job name or group name. */
23
+ export type NeedsContext = Record<string, NeedEntry>;
24
+ /**
25
+ * Resolve declared needs against a frozen snapshot into the `ctx.needs` map.
26
+ *
27
+ * - A single static/named-job need resolves to `{ result: <proxy over jobs[name]> }`.
28
+ * - A `dynamicGroup(...)` need resolves to an ordered array of `{ name, result }`,
29
+ * one entry per group member in the snapshot's deterministic eval order.
30
+ */
31
+ export declare function buildNeedsContext(snapshot: UpstreamSnapshot, declaredNeeds: ReadonlyArray<DynamicJobNeed>): NeedsContext;
32
+ //# sourceMappingURL=needs-context.d.ts.map