@kici-dev/sdk 0.0.0 → 0.1.1

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 (112) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1 -6
  3. package/dist/api-types.d.ts +47 -0
  4. package/dist/api-types.js +15 -0
  5. package/dist/chunk-gOLHoazu.js +4 -0
  6. package/dist/context.d.ts +185 -0
  7. package/dist/context.js +2 -0
  8. package/dist/dynamic-group.d.ts +29 -0
  9. package/dist/dynamic-group.js +34 -0
  10. package/dist/errors.d.ts +9 -0
  11. package/dist/errors.js +17 -0
  12. package/dist/events/define-event.d.ts +32 -0
  13. package/dist/events/define-event.js +29 -0
  14. package/dist/events/event-payloads.d.ts +396 -0
  15. package/dist/events/event-payloads.js +21 -0
  16. package/dist/events/index.d.ts +6 -0
  17. package/dist/events/index.js +4 -0
  18. package/dist/events/types.d.ts +13 -0
  19. package/dist/events/types.js +2 -0
  20. package/dist/fixture.d.ts +50 -0
  21. package/dist/fixture.js +35 -0
  22. package/dist/hooks/index.d.ts +33 -0
  23. package/dist/hooks/index.js +94 -0
  24. package/dist/hooks/types.d.ts +35 -0
  25. package/dist/hooks/types.js +2 -0
  26. package/dist/idempotent.d.ts +71 -0
  27. package/dist/idempotent.js +77 -0
  28. package/dist/index.d.ts +40 -0
  29. package/dist/index.js +50 -0
  30. package/dist/job.d.ts +31 -0
  31. package/dist/job.js +46 -0
  32. package/dist/matrix/expand.d.ts +32 -0
  33. package/dist/matrix/expand.js +77 -0
  34. package/dist/matrix/index.d.ts +4 -0
  35. package/dist/matrix/index.js +4 -0
  36. package/dist/matrix/types.d.ts +60 -0
  37. package/dist/matrix/types.js +18 -0
  38. package/dist/outputs.d.ts +86 -0
  39. package/dist/outputs.js +180 -0
  40. package/dist/rules/evaluator.d.ts +24 -0
  41. package/dist/rules/evaluator.js +52 -0
  42. package/dist/rules/index.d.ts +6 -0
  43. package/dist/rules/index.js +5 -0
  44. package/dist/rules/rule.d.ts +34 -0
  45. package/dist/rules/rule.js +37 -0
  46. package/dist/rules/types.d.ts +42 -0
  47. package/dist/rules/types.js +2 -0
  48. package/dist/secrets.d.ts +192 -0
  49. package/dist/secrets.js +132 -0
  50. package/dist/step.d.ts +50 -0
  51. package/dist/step.js +78 -0
  52. package/dist/triggers/comment.d.ts +20 -0
  53. package/dist/triggers/comment.js +47 -0
  54. package/dist/triggers/create.d.ts +20 -0
  55. package/dist/triggers/create.js +32 -0
  56. package/dist/triggers/delete.d.ts +20 -0
  57. package/dist/triggers/delete.js +29 -0
  58. package/dist/triggers/dispatch.d.ts +17 -0
  59. package/dist/triggers/dispatch.js +27 -0
  60. package/dist/triggers/fork.d.ts +17 -0
  61. package/dist/triggers/fork.js +26 -0
  62. package/dist/triggers/generic-webhook.d.ts +32 -0
  63. package/dist/triggers/generic-webhook.js +45 -0
  64. package/dist/triggers/index.d.ts +28 -0
  65. package/dist/triggers/index.js +25 -0
  66. package/dist/triggers/job-complete.d.ts +23 -0
  67. package/dist/triggers/job-complete.js +33 -0
  68. package/dist/triggers/kici-event.d.ts +23 -0
  69. package/dist/triggers/kici-event.js +34 -0
  70. package/dist/triggers/lifecycle.d.ts +20 -0
  71. package/dist/triggers/lifecycle.js +29 -0
  72. package/dist/triggers/pr.d.ts +27 -0
  73. package/dist/triggers/pr.js +48 -0
  74. package/dist/triggers/push.d.ts +29 -0
  75. package/dist/triggers/push.js +48 -0
  76. package/dist/triggers/release.d.ts +17 -0
  77. package/dist/triggers/release.js +27 -0
  78. package/dist/triggers/review-comment.d.ts +17 -0
  79. package/dist/triggers/review-comment.js +27 -0
  80. package/dist/triggers/review.d.ts +17 -0
  81. package/dist/triggers/review.js +28 -0
  82. package/dist/triggers/schedule.d.ts +20 -0
  83. package/dist/triggers/schedule.js +29 -0
  84. package/dist/triggers/star.d.ts +17 -0
  85. package/dist/triggers/star.js +27 -0
  86. package/dist/triggers/status.d.ts +17 -0
  87. package/dist/triggers/status.js +28 -0
  88. package/dist/triggers/tag.d.ts +20 -0
  89. package/dist/triggers/tag.js +31 -0
  90. package/dist/triggers/types.d.ts +529 -0
  91. package/dist/triggers/types.js +36 -0
  92. package/dist/triggers/watch.d.ts +17 -0
  93. package/dist/triggers/watch.js +27 -0
  94. package/dist/triggers/webhook.d.ts +19 -0
  95. package/dist/triggers/webhook.js +29 -0
  96. package/dist/triggers/workflow-complete.d.ts +23 -0
  97. package/dist/triggers/workflow-complete.js +32 -0
  98. package/dist/triggers/workflow-run.d.ts +17 -0
  99. package/dist/triggers/workflow-run.js +29 -0
  100. package/dist/types.d.ts +483 -0
  101. package/dist/types.js +35 -0
  102. package/dist/validation/dag.d.ts +42 -0
  103. package/dist/validation/dag.js +70 -0
  104. package/dist/validation/index.d.ts +3 -0
  105. package/dist/validation/index.js +3 -0
  106. package/dist/wait-for.d.ts +109 -0
  107. package/dist/wait-for.js +144 -0
  108. package/dist/workflow.d.ts +3 -0
  109. package/dist/workflow.js +83 -0
  110. package/package.json +42 -5
  111. package/sbom.spdx.json +9150 -0
  112. package/index.js +0 -3
@@ -0,0 +1,71 @@
1
+ /**
2
+ * SDK idempotency helpers for workflow authors.
3
+ *
4
+ * Workflows run unattended on agents — no operator at the prompt, no
5
+ * dry-run flag to flip. The helpers in this file expose the same
6
+ * check/apply discipline as the shared primitive but with a workflow
7
+ * shape:
8
+ *
9
+ * - apply on drift unconditionally (no confirm, no dryRun).
10
+ * - optional whenInSync() callback to surface the already-satisfied
11
+ * resource when check() reports no drift (e.g. fetch an existing
12
+ * resource id when a create-if-missing was already done).
13
+ * - typed return values threaded through both branches via the
14
+ * discriminated IdempotentResult union.
15
+ *
16
+ * Two entry points:
17
+ *
18
+ * - `idempotent(options)` — generic helper callable from any step,
19
+ * hook, or bare async function. Returns the discriminated result.
20
+ * - `idempotentStep(name, options)` — factory returning an SDK `Step`
21
+ * whose run function executes `idempotent(...)` and propagates ctx.log
22
+ * into the runner's status sink.
23
+ */
24
+ import type { Step } from './types.js';
25
+ export interface IdempotentOptions<TDrift, TInSync = void, TApplied = void> {
26
+ /** Optional name surfaced in status lines and error messages. */
27
+ name?: string;
28
+ /** Read-only inspection. Returns drift if apply() would change state,
29
+ * or null if the system is already in the desired state. */
30
+ check: () => Promise<TDrift | null>;
31
+ /** Brings the system to the desired state. Its return value is
32
+ * surfaced as `result` on the 'applied' outcome. */
33
+ apply: (drift: TDrift) => Promise<TApplied>;
34
+ /** Runs when check() returns null. Use to fetch the already-satisfied
35
+ * resource. Its return value is surfaced as `result` on the
36
+ * 'skipped' outcome. */
37
+ whenInSync?: () => Promise<TInSync>;
38
+ /** Multi-line description of what apply() would do. Defaults to a
39
+ * JSON dump of the drift value. */
40
+ summarize?: (drift: TDrift) => string;
41
+ /** Sink for status lines. Defaults to console.log. */
42
+ log?: (line: string) => void;
43
+ }
44
+ /**
45
+ * The result of an SDK idempotent invocation. The runner always applies
46
+ * on drift (no interactive confirm, no dryRun) so the only possible
47
+ * outcomes are 'skipped' (check returned null) and 'applied' (check
48
+ * returned drift; apply ran).
49
+ */
50
+ export type IdempotentResult<TDrift, TInSync = void, TApplied = void> = {
51
+ outcome: 'skipped';
52
+ drift: null;
53
+ result: TInSync;
54
+ } | {
55
+ outcome: 'applied';
56
+ drift: TDrift;
57
+ result: TApplied;
58
+ };
59
+ /**
60
+ * Generic idempotent helper for use inside any step, hook, or bare
61
+ * async function. Resolves to a discriminated result indicating whether
62
+ * the system was already in sync or apply() ran.
63
+ */
64
+ export declare function idempotent<TDrift, TInSync = void, TApplied = void>(opts: IdempotentOptions<TDrift, TInSync, TApplied>): Promise<IdempotentResult<TDrift, TInSync, TApplied>>;
65
+ /**
66
+ * Factory returning an SDK Step whose run function executes
67
+ * `idempotent(...)`. Status lines are routed through `ctx.log.info`.
68
+ * The step's typed return value is the IdempotentResult union.
69
+ */
70
+ export declare function idempotentStep<TDrift, TInSync = void, TApplied = void>(name: string, opts: Omit<IdempotentOptions<TDrift, TInSync, TApplied>, 'name' | 'log'>): Step<IdempotentResult<TDrift, TInSync, TApplied>>;
71
+ //# sourceMappingURL=idempotent.d.ts.map
@@ -0,0 +1,77 @@
1
+ import "./chunk-gOLHoazu.js";
2
+ import { step } from "./step.js";
3
+ import { runIdempotentStep } from "@kici-dev/shared/idempotency";
4
+ //#region src/idempotent.ts
5
+ /**
6
+ * SDK idempotency helpers for workflow authors.
7
+ *
8
+ * Workflows run unattended on agents — no operator at the prompt, no
9
+ * dry-run flag to flip. The helpers in this file expose the same
10
+ * check/apply discipline as the shared primitive but with a workflow
11
+ * shape:
12
+ *
13
+ * - apply on drift unconditionally (no confirm, no dryRun).
14
+ * - optional whenInSync() callback to surface the already-satisfied
15
+ * resource when check() reports no drift (e.g. fetch an existing
16
+ * resource id when a create-if-missing was already done).
17
+ * - typed return values threaded through both branches via the
18
+ * discriminated IdempotentResult union.
19
+ *
20
+ * Two entry points:
21
+ *
22
+ * - `idempotent(options)` — generic helper callable from any step,
23
+ * hook, or bare async function. Returns the discriminated result.
24
+ * - `idempotentStep(name, options)` — factory returning an SDK `Step`
25
+ * whose run function executes `idempotent(...)` and propagates ctx.log
26
+ * into the runner's status sink.
27
+ */
28
+ const DEFAULT_NAME = "idempotent";
29
+ /**
30
+ * Generic idempotent helper for use inside any step, hook, or bare
31
+ * async function. Resolves to a discriminated result indicating whether
32
+ * the system was already in sync or apply() ran.
33
+ */
34
+ async function idempotent(opts) {
35
+ const name = opts.name ?? DEFAULT_NAME;
36
+ const summarize = opts.summarize ?? ((drift) => JSON.stringify(drift, null, 2));
37
+ const sharedResult = await runIdempotentStep({
38
+ name,
39
+ check: opts.check,
40
+ apply: opts.apply,
41
+ summarize,
42
+ whenInSync: opts.whenInSync
43
+ }, {
44
+ yes: true,
45
+ log: opts.log
46
+ });
47
+ if (sharedResult.outcome === "skipped") return {
48
+ outcome: "skipped",
49
+ drift: null,
50
+ result: sharedResult.result
51
+ };
52
+ if (sharedResult.outcome === "applied") return {
53
+ outcome: "applied",
54
+ drift: sharedResult.drift,
55
+ result: sharedResult.result
56
+ };
57
+ throw new Error(`idempotent(${name}): unreachable outcome '${sharedResult.outcome}'`);
58
+ }
59
+ /**
60
+ * Factory returning an SDK Step whose run function executes
61
+ * `idempotent(...)`. Status lines are routed through `ctx.log.info`.
62
+ * The step's typed return value is the IdempotentResult union.
63
+ */
64
+ function idempotentStep(name, opts) {
65
+ return step(name, { run: async (ctx) => idempotent({
66
+ name,
67
+ check: opts.check,
68
+ apply: opts.apply,
69
+ whenInSync: opts.whenInSync,
70
+ summarize: opts.summarize,
71
+ log: (line) => ctx.log.info(line)
72
+ }) });
73
+ }
74
+ //#endregion
75
+ export { idempotent, idempotentStep };
76
+
77
+ //# sourceMappingURL=idempotent.js.map
@@ -0,0 +1,40 @@
1
+ export { step } from './step.js';
2
+ export { job } from './job.js';
3
+ export { workflow } from './workflow.js';
4
+ export { pr, push, tag, comment, review, reviewComment, release, dispatch, create, delete as delete, status, workflowRun, fork, star, watch, webhook, kiciEvent, workflowComplete, jobComplete, genericWebhook, schedule, lifecycle, } from './triggers/index.js';
5
+ export type { TriggerConfig, PrTriggerConfig, PushTriggerConfig, TagTriggerConfig, CommentTriggerConfig, ReviewTriggerConfig, ReviewCommentTriggerConfig, ReleaseTriggerConfig, DispatchTriggerConfig, CreateTriggerConfig, DeleteTriggerConfig, StatusTriggerConfig, WorkflowRunTriggerConfig, ForkTriggerConfig, StarTriggerConfig, WatchTriggerConfig, WebhookTriggerConfig, BranchPattern, BodyMatchPattern, PrEvent, PushEvent, PrConfigInput, PushConfigInput, TagConfigInput, CommentConfigInput, CommentAction, CommentSource, ReviewConfigInput, ReviewAction, ReviewState, ReviewCommentConfigInput, ReviewCommentAction, ReleaseConfigInput, ReleaseAction, DispatchConfigInput, CreateConfigInput, DeleteConfigInput, RefType, StatusConfigInput, StatusState, WorkflowRunConfigInput, WorkflowRunAction, ForkConfigInput, StarConfigInput, StarAction, WatchConfigInput, WatchAction, WebhookConfigInput, KiciEventConfigInput, KiciEventTriggerConfig, WorkflowCompleteConfigInput, WorkflowCompleteTriggerConfig, WorkflowCompleteStatus, JobCompleteConfigInput, JobCompleteTriggerConfig, JobCompleteStatus, GenericWebhookConfigInput, GenericWebhookTriggerConfig, GenericWebhookAuthMethod, GenericWebhookHmacAuth, GenericWebhookApiKeyAuth, GenericWebhookAuth, ScheduleConfigInput, ScheduleTriggerConfig, LifecycleEvent, LifecycleConfigInput, LifecycleTriggerConfig, } from './triggers/index.js';
6
+ export { onCancel, cleanup, onSuccess, onFailure, beforeStep, afterStep } from './hooks/index.js';
7
+ export type { HookConfig, HookFn, HookInput, HookContext, OutcomeMetadata } from './hooks/index.js';
8
+ export { rule, skip } from './rules/index.js';
9
+ export { evaluateRules } from './rules/index.js';
10
+ export { isEventType } from './rules/index.js';
11
+ 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';
12
+ export { validateDag } from './validation/index.js';
13
+ export type { DagNode, DagValidationResult } from './validation/index.js';
14
+ export type { SourceLocation, OutputProxy, Step, StepOptions, StepRunFn, BareStepFn, StepInput, OutputSchema, InferOutputs, Job, JobOptions, ContainerConfig, RunsOnSelector, RunsOn, Workflow, WorkflowOptions, Registry, Trigger, DynamicJobFn, DynamicJobContext, JobOrFactory, } from './types.js';
15
+ export { isDynamicJobFn, dynamicJob, getDynamicJobGroup, DYNAMIC_JOB_GROUP_TAG } from './types.js';
16
+ export type { TaggedDynamicJobFn } from './types.js';
17
+ export { dynamicGroup, isDynamicGroupRef, DYNAMIC_GROUP_TAG } from './dynamic-group.js';
18
+ export type { DynamicGroupRef } from './dynamic-group.js';
19
+ export type { StepContext, Logger, WorkflowInfo, JobInfo, RepoInfo, StepSecretsTyped, KnownSecretKeys, } from './context.js';
20
+ export { buildKiciApi } from './api-types.js';
21
+ export type { KiciApi, KiciApiTransport, InfrastructureApi, InfrastructureListResult, } from './api-types.js';
22
+ export { SecretNotFoundError } from './errors.js';
23
+ export { createStepSecrets } from './secrets.js';
24
+ export type { StepSecrets, TrackedStepSecrets, SecretMeta, SecretFileOptions, MountedFile, StepSecretsFileHost, StepSecretsFileWiring, StepSecretsHandle, StepSecretMountKind, StepSecretMountRecord, } from './secrets.js';
25
+ export { createStepOutputProxy, createJobOutputProxy, resolveStepOutputs, resolveJobOutputs, setStepOutputsMap, setJobOutputsMap, setStepRefMap, getStepOutputsMap, getJobOutputsMap, getStepRefMap, } from './outputs.js';
26
+ export type { OutputsMap, StepRefMap } from './outputs.js';
27
+ export type { StaticMatrixArray, StaticMatrixObject, DynamicMatrixFn, DynamicMatrixContext, Matrix, MatrixInclude, MatrixExclude, MatrixValues, } from './matrix/index.js';
28
+ export { isStaticArray, isStaticObject, isDynamicFunction } from './matrix/index.js';
29
+ export { expandMatrix, applyIncludeExclude } from './matrix/index.js';
30
+ export { defineEvent } from './events/index.js';
31
+ export type { EventDefinition } from './events/index.js';
32
+ export type { EventEmitOptions } from './events/index.js';
33
+ export { fixture } from './fixture.js';
34
+ export type { Fixture, FixtureOptions } from './fixture.js';
35
+ export { idempotent, idempotentStep } from './idempotent.js';
36
+ export type { IdempotentOptions, IdempotentResult } from './idempotent.js';
37
+ export { waitFor, waitForStep, WaitForTimeoutError } from './wait-for.js';
38
+ export type { WaitForOptions, WaitForResult } from './wait-for.js';
39
+ export { z } from 'zod';
40
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ import "./chunk-gOLHoazu.js";
2
+ import { buildKiciApi } from "./api-types.js";
3
+ import { DYNAMIC_GROUP_TAG, dynamicGroup, isDynamicGroupRef } from "./dynamic-group.js";
4
+ import { SecretNotFoundError } from "./errors.js";
5
+ import { fixture } from "./fixture.js";
6
+ import { createJobOutputProxy, createStepOutputProxy, getJobOutputsMap, getStepOutputsMap, getStepRefMap, resolveJobOutputs, resolveStepOutputs, setJobOutputsMap, setStepOutputsMap, setStepRefMap } from "./outputs.js";
7
+ import { step } from "./step.js";
8
+ import { idempotent, idempotentStep } from "./idempotent.js";
9
+ import { job } from "./job.js";
10
+ import { workflow } from "./workflow.js";
11
+ import { pr } from "./triggers/pr.js";
12
+ import { push } from "./triggers/push.js";
13
+ import { tag } from "./triggers/tag.js";
14
+ import { comment } from "./triggers/comment.js";
15
+ import { review } from "./triggers/review.js";
16
+ import { reviewComment } from "./triggers/review-comment.js";
17
+ import { release } from "./triggers/release.js";
18
+ import { dispatch } from "./triggers/dispatch.js";
19
+ import { create } from "./triggers/create.js";
20
+ import { del } from "./triggers/delete.js";
21
+ import { status } from "./triggers/status.js";
22
+ import { workflowRun } from "./triggers/workflow-run.js";
23
+ import { fork } from "./triggers/fork.js";
24
+ import { star } from "./triggers/star.js";
25
+ import { watch } from "./triggers/watch.js";
26
+ import { webhook } from "./triggers/webhook.js";
27
+ import { kiciEvent } from "./triggers/kici-event.js";
28
+ import { workflowComplete } from "./triggers/workflow-complete.js";
29
+ import { jobComplete } from "./triggers/job-complete.js";
30
+ import { genericWebhook } from "./triggers/generic-webhook.js";
31
+ import { schedule } from "./triggers/schedule.js";
32
+ import { lifecycle } from "./triggers/lifecycle.js";
33
+ import "./triggers/index.js";
34
+ import { afterStep, beforeStep, cleanup, onCancel, onFailure, onSuccess } from "./hooks/index.js";
35
+ import { rule, skip } from "./rules/rule.js";
36
+ import { evaluateRules } from "./rules/evaluator.js";
37
+ import { isEventType } from "./events/event-payloads.js";
38
+ import "./rules/index.js";
39
+ import { validateDag } from "./validation/dag.js";
40
+ import "./validation/index.js";
41
+ import { DYNAMIC_JOB_GROUP_TAG, dynamicJob, getDynamicJobGroup, isDynamicJobFn } from "./types.js";
42
+ import { createStepSecrets } from "./secrets.js";
43
+ import { isDynamicFunction, isStaticArray, isStaticObject } from "./matrix/types.js";
44
+ import { applyIncludeExclude, expandMatrix } from "./matrix/expand.js";
45
+ import "./matrix/index.js";
46
+ import { defineEvent } from "./events/define-event.js";
47
+ import "./events/index.js";
48
+ import { WaitForTimeoutError, waitFor, waitForStep } from "./wait-for.js";
49
+ import { z } from "zod";
50
+ export { 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, 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 };
package/dist/job.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { Job, JobOptions } from './types.js';
2
+ /**
3
+ * Create a job with an explicit name.
4
+ *
5
+ * @example
6
+ * const build = job('build', {
7
+ * runsOn: 'linux',
8
+ * steps: [checkout, install, compile],
9
+ * });
10
+ *
11
+ * @example
12
+ * // With rules and description
13
+ * const build = job('build', {
14
+ * runsOn: 'linux',
15
+ * steps: [checkout, install, compile],
16
+ * rules: [rule('env: CI')],
17
+ * description: 'Build the project',
18
+ * });
19
+ */
20
+ export declare function job(name: string, options: JobOptions): Job;
21
+ /**
22
+ * Create a job with auto-generated ID.
23
+ *
24
+ * @example
25
+ * const build = job({
26
+ * runsOn: 'linux',
27
+ * steps: [checkout, install],
28
+ * });
29
+ */
30
+ export declare function job(options: JobOptions): Job;
31
+ //# sourceMappingURL=job.d.ts.map
package/dist/job.js ADDED
@@ -0,0 +1,46 @@
1
+ import "./chunk-gOLHoazu.js";
2
+ import { createJobOutputProxy } from "./outputs.js";
3
+ import { randomUUID } from "node:crypto";
4
+ //#region src/job.ts
5
+ /**
6
+ * Implementation of job() factory.
7
+ */
8
+ function job(nameOrOptions, maybeOptions) {
9
+ const name = typeof nameOrOptions === "string" ? nameOrOptions : randomUUID();
10
+ const options = typeof nameOrOptions === "string" ? maybeOptions : nameOrOptions;
11
+ let steps = options.steps ?? [];
12
+ if (options.run) {
13
+ if (options.steps && options.steps.length > 0) throw new Error("job() cannot have both \"run\" and \"steps\" -- use one or the other");
14
+ steps = [options.run];
15
+ }
16
+ return {
17
+ _tag: "Job",
18
+ name,
19
+ runsOn: options.runsOn,
20
+ steps,
21
+ needs: options.needs,
22
+ rules: options.rules,
23
+ description: options.description,
24
+ matrix: options.matrix,
25
+ include: options.include,
26
+ exclude: options.exclude,
27
+ checkout: options.checkout,
28
+ container: options.container,
29
+ environment: options.environment,
30
+ env: options.env,
31
+ concurrencyGroup: options.concurrencyGroup,
32
+ onCancel: options.onCancel,
33
+ cleanup: options.cleanup,
34
+ onSuccess: options.onSuccess,
35
+ onFailure: options.onFailure,
36
+ beforeStep: options.beforeStep,
37
+ afterStep: options.afterStep,
38
+ gracePeriod: options.gracePeriod,
39
+ resources: options.resources,
40
+ result: createJobOutputProxy(name)
41
+ };
42
+ }
43
+ //#endregion
44
+ export { job };
45
+
46
+ //# sourceMappingURL=job.js.map
@@ -0,0 +1,32 @@
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[];
25
+ /**
26
+ * Generate job name from base job name and matrix values.
27
+ * Per CONTEXT.md bracket notation:
28
+ * - Single dimension: job[value]
29
+ * - Multi-dimensional: job[dim:val,dim:val] (sorted keys for determinism)
30
+ */
31
+ export declare function generateJobName(baseJobName: string, matrixValues: MatrixValues): string;
32
+ //# sourceMappingURL=expand.d.ts.map
@@ -0,0 +1,77 @@
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
+ /**
64
+ * Generate job name from base job name and matrix values.
65
+ * Per CONTEXT.md bracket notation:
66
+ * - Single dimension: job[value]
67
+ * - Multi-dimensional: job[dim:val,dim:val] (sorted keys for determinism)
68
+ */
69
+ function generateJobName(baseJobName, matrixValues) {
70
+ const keys = Object.keys(matrixValues).filter((k) => matrixValues[k] !== void 0);
71
+ if (keys.length === 1 && keys[0] === "value") return `${baseJobName}[${matrixValues.value}]`;
72
+ return `${baseJobName}[${keys.sort().map((key) => `${key}:${matrixValues[key]}`).join(",")}]`;
73
+ }
74
+ //#endregion
75
+ export { applyIncludeExclude, expandMatrix, expandMultiDimension, expandSingleDimension, generateJobName };
76
+
77
+ //# sourceMappingURL=expand.js.map
@@ -0,0 +1,4 @@
1
+ export type { StaticMatrixArray, StaticMatrixObject, DynamicMatrixFn, DynamicMatrixContext, Matrix, MatrixInclude, MatrixExclude, MatrixValues, } from './types.js';
2
+ export { isStaticArray, isStaticObject, isDynamicFunction } from './types.js';
3
+ export { expandMatrix, applyIncludeExclude } from './expand.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ import { isDynamicFunction, isStaticArray, isStaticObject } from "./types.js";
3
+ import { applyIncludeExclude, expandMatrix } from "./expand.js";
4
+ export { applyIncludeExclude, expandMatrix, isDynamicFunction, isStaticArray, isStaticObject };
@@ -0,0 +1,60 @@
1
+ import type { $ as Shell } from 'zx';
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[]>;
7
+ /**
8
+ * Context passed to dynamic matrix functions.
9
+ * Uses destructured form: async ({$, ctx, log, env}) => values
10
+ */
11
+ export interface DynamicMatrixContext {
12
+ /** zx shell executor for running commands */
13
+ $: typeof Shell;
14
+ /** Event context and workflow metadata */
15
+ ctx: {
16
+ workflow: {
17
+ name: string;
18
+ };
19
+ job: {
20
+ name: string;
21
+ runsOn: string | string[] | {
22
+ labels: string | string[];
23
+ exclude?: string | string[];
24
+ };
25
+ };
26
+ };
27
+ /** Structured logger */
28
+ log: Logger;
29
+ /** Environment variables */
30
+ env: Record<string, string | undefined>;
31
+ }
32
+ /**
33
+ * Async function that computes matrix values dynamically.
34
+ * Signature: async ({$, ctx, log, env}) => values
35
+ */
36
+ export type DynamicMatrixFn = (context: DynamicMatrixContext) => Promise<StaticMatrixArray | StaticMatrixObject>;
37
+ /** Union type for all matrix forms */
38
+ 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
+ /** Type guard for static array matrices */
55
+ export declare function isStaticArray(m: Matrix): m is StaticMatrixArray;
56
+ /** Type guard for static object matrices */
57
+ export declare function isStaticObject(m: Matrix): m is StaticMatrixObject;
58
+ /** Type guard for dynamic function matrices */
59
+ export declare function isDynamicFunction(m: Matrix): m is DynamicMatrixFn;
60
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,18 @@
1
+ import "../chunk-gOLHoazu.js";
2
+ //#region src/matrix/types.ts
3
+ /** Type guard for static array matrices */
4
+ function isStaticArray(m) {
5
+ return Array.isArray(m);
6
+ }
7
+ /** Type guard for static object matrices */
8
+ function isStaticObject(m) {
9
+ return m !== null && typeof m === "object" && !Array.isArray(m);
10
+ }
11
+ /** Type guard for dynamic function matrices */
12
+ function isDynamicFunction(m) {
13
+ return typeof m === "function";
14
+ }
15
+ //#endregion
16
+ export { isDynamicFunction, isStaticArray, isStaticObject };
17
+
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,86 @@
1
+ import type { OutputProxy } from './types.js';
2
+ /**
3
+ * Shared mutable map that steps write their outputs to and proxies read from.
4
+ * Keys are step/job names, values are the outputs records.
5
+ */
6
+ export type OutputsMap = Map<string, Record<string, unknown>>;
7
+ /**
8
+ * WeakMap for mapping bare function references to step names.
9
+ * Populated when the job normalizes bare functions into internal Step objects.
10
+ */
11
+ export type StepRefMap = WeakMap<Function, string>;
12
+ /**
13
+ * Structural type for step references used in resolveStepOutputs.
14
+ * Avoids circular dependency with types.ts.
15
+ */
16
+ interface StepLike {
17
+ readonly _tag: 'Step';
18
+ readonly name: string;
19
+ }
20
+ /**
21
+ * Inject a fresh step outputs map for a new execution.
22
+ * Called by workflow runners (compiler test runner, agent sandbox) before execution.
23
+ */
24
+ export declare function setStepOutputsMap(map: OutputsMap): void;
25
+ /**
26
+ * Inject a fresh job outputs map for a new execution.
27
+ */
28
+ export declare function setJobOutputsMap(map: OutputsMap): void;
29
+ /**
30
+ * Inject a fresh step-ref map for bare function -> step name resolution.
31
+ */
32
+ export declare function setStepRefMap(map: StepRefMap): void;
33
+ /**
34
+ * Get the current step outputs map (for runners to populate).
35
+ */
36
+ export declare function getStepOutputsMap(): OutputsMap;
37
+ /**
38
+ * Get the current job outputs map (for runners to populate).
39
+ */
40
+ export declare function getJobOutputsMap(): OutputsMap;
41
+ /**
42
+ * Get the current step ref map.
43
+ */
44
+ export declare function getStepRefMap(): StepRefMap;
45
+ /**
46
+ * Create a Proxy over step outputs that resolves property access lazily
47
+ * against the module-global step outputs map.
48
+ *
49
+ * @param stepName - The name of the step whose outputs to proxy
50
+ * @returns A Proxy that resolves property access at runtime
51
+ */
52
+ export declare function createStepOutputProxy<T>(stepName: string): OutputProxy<T>;
53
+ /**
54
+ * Create a Proxy over job outputs that resolves property access lazily
55
+ * against the module-global job outputs map.
56
+ *
57
+ * For multi-step jobs: job.result.stepName.field
58
+ * For single-step (run shorthand) jobs: job.result.field
59
+ *
60
+ * @param jobName - The name of the job whose outputs to proxy
61
+ * @returns A Proxy that resolves property access at runtime
62
+ */
63
+ export declare function createJobOutputProxy(jobName: string): OutputProxy<any>;
64
+ /**
65
+ * Resolve step outputs by step reference (Step object or bare function).
66
+ * Used by ctx.outputsOf() implementation.
67
+ *
68
+ * @param ref - Step object (with _tag: 'Step') or bare function reference
69
+ * @param outputsMap - The outputs map to resolve against (defaults to module-global)
70
+ * @param refMap - The ref map for bare function -> name resolution (defaults to module-global)
71
+ * @returns The step's outputs
72
+ */
73
+ export declare function resolveStepOutputs<T>(ref: StepLike | Function, outputsMap?: OutputsMap, refMap?: StepRefMap): T;
74
+ /**
75
+ * Resolve job outputs by job reference.
76
+ * Used by ctx.jobOutputs() implementation.
77
+ *
78
+ * @param ref - Job object reference (needs .name property)
79
+ * @param outputsMap - The outputs map to resolve against (defaults to module-global)
80
+ * @returns The job's outputs
81
+ */
82
+ export declare function resolveJobOutputs(ref: {
83
+ name: string;
84
+ }, outputsMap?: OutputsMap): Record<string, unknown>;
85
+ export {};
86
+ //# sourceMappingURL=outputs.d.ts.map