@kici-dev/agent 0.1.23 → 0.1.25
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.
- package/dist/execution/cache/cache-phase.d.ts +21 -4
- package/dist/execution/cache/index.d.ts +1 -1
- package/dist/execution/init-runner.d.ts +2 -1
- package/dist/execution/sandbox/capture-context.d.ts +11 -0
- package/dist/execution/sandbox/ipc-protocol.d.ts +44 -9
- package/dist/execution/sandbox/parallel-scheduler.d.ts +34 -0
- package/dist/execution/sandbox/step-loop.d.ts +91 -16
- package/dist/execution/sandbox/step-task-registry.d.ts +26 -0
- package/dist/execution/sandbox/types.d.ts +2 -2
- package/dist/execution/sandbox/workflow-runner.d.ts +22 -1
- package/dist/index.js +8 -2
- package/dist/provenance/attest.d.ts +27 -4
- package/dist/provenance/statement-builder.d.ts +50 -0
- package/dist/server.js +204 -101
- package/dist/workflow-runner.js +577 -131
- package/dist/ws/orchestrator-client.d.ts +6 -0
- package/package.json +6 -6
- package/sbom.spdx.json +68 -68
|
@@ -10,20 +10,37 @@ export interface CachePhaseDeps {
|
|
|
10
10
|
cache: CacheApi;
|
|
11
11
|
/** Emit a runner→agent IPC message (the masked send). */
|
|
12
12
|
sendIpc: (msg: RunnerToAgentMessage) => void;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Allocate the next cache pseudo-step index for `ownerStepIndex` (the real
|
|
15
|
+
* step the cache op belongs to, or {@link JOB_CACHE_OWNER} for job-level
|
|
16
|
+
* cache). Each owner draws from a disjoint block above every real-step and
|
|
17
|
+
* hook index, so two concurrently-running steps' cache pseudo-steps never
|
|
18
|
+
* collide.
|
|
19
|
+
*/
|
|
20
|
+
nextStepIndex: (ownerStepIndex: number) => number;
|
|
15
21
|
}
|
|
22
|
+
/** Owner sentinel for job-level (not step-scoped) cache restore/save. */
|
|
23
|
+
export declare const JOB_CACHE_OWNER = -1;
|
|
24
|
+
/**
|
|
25
|
+
* Build the cache pseudo-step index allocator. Each owner (a real step index, or
|
|
26
|
+
* {@link JOB_CACHE_OWNER}) gets its own disjoint block of {@link CACHE_INDEX_BLOCK}
|
|
27
|
+
* indices, all above every real-step and hook index (`stepCount * 3 + 100`). A
|
|
28
|
+
* step's two-or-more cache pseudo-steps are a pure function of its own owner
|
|
29
|
+
* index, so concurrent children never collide. Under sequential execution the
|
|
30
|
+
* emitted indices stay above all real/hook indices exactly as before.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createCacheStepIndexAllocator(stepCount: number): (ownerStepIndex: number) => number;
|
|
16
33
|
/**
|
|
17
34
|
* Restore every spec, surfacing each as a `cache:restore` pseudo-step. Returns
|
|
18
35
|
* a map keyed by spec key recording whether the EXACT key hit (so the save
|
|
19
36
|
* phase can skip a redundant save of an entry that already exists).
|
|
20
37
|
*/
|
|
21
|
-
export declare function restoreCacheSpecs(specs: CacheSpec[], deps: CachePhaseDeps): Promise<Map<string, CacheRestoreOutcome>>;
|
|
38
|
+
export declare function restoreCacheSpecs(specs: CacheSpec[], deps: CachePhaseDeps, ownerStepIndex: number): Promise<Map<string, CacheRestoreOutcome>>;
|
|
22
39
|
/**
|
|
23
40
|
* Save every spec whose EXACT key did not already hit on restore (immutable +
|
|
24
41
|
* no redundant save), surfacing each as a `cache:save` pseudo-step. A spec
|
|
25
42
|
* whose restore matched a different key via a `restoreKeys` prefix is still
|
|
26
43
|
* saved under its exact key.
|
|
27
44
|
*/
|
|
28
|
-
export declare function saveCacheSpecs(specs: CacheSpec[], restoreResults: Map<string, CacheRestoreOutcome>, deps: CachePhaseDeps): Promise<void>;
|
|
45
|
+
export declare function saveCacheSpecs(specs: CacheSpec[], restoreResults: Map<string, CacheRestoreOutcome>, deps: CachePhaseDeps, ownerStepIndex: number): Promise<void>;
|
|
29
46
|
//# sourceMappingURL=cache-phase.d.ts.map
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* `ctx.cache` API factory plus its transport interface.
|
|
6
6
|
*/
|
|
7
7
|
export { createCacheApi, packCachePaths, extractCacheTarball, downloadAndExtractCache, resolveCachePath, type CacheTransport, type CacheRoots, } from './cache-engine.js';
|
|
8
|
-
export { restoreCacheSpecs, saveCacheSpecs, type CachePhaseDeps, type CacheRestoreOutcome, } from './cache-phase.js';
|
|
8
|
+
export { restoreCacheSpecs, saveCacheSpecs, createCacheStepIndexAllocator, JOB_CACHE_OWNER, type CachePhaseDeps, type CacheRestoreOutcome, } from './cache-phase.js';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,7 +5,8 @@ import { type MatrixValues } from '@kici-dev/engine';
|
|
|
5
5
|
* Only fields that were flagged as dynamic and successfully resolved are set.
|
|
6
6
|
*/
|
|
7
7
|
export interface InitResult {
|
|
8
|
-
|
|
8
|
+
/** Resolved bound-environment names, in merge order (one per `environments` element). */
|
|
9
|
+
environmentNames?: string[];
|
|
9
10
|
env?: Record<string, string>;
|
|
10
11
|
concurrencyGroup?: string;
|
|
11
12
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run `fn` with `stepIndex` as the active console-capture attribution for the
|
|
3
|
+
* duration of its async execution (including everything it awaits).
|
|
4
|
+
*/
|
|
5
|
+
export declare function runInStepCapture<T>(stepIndex: number, fn: () => Promise<T>): Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* The step index whose run is currently on the async stack, or `-1` when no
|
|
8
|
+
* capture scope is active (workflow-level / between-steps output).
|
|
9
|
+
*/
|
|
10
|
+
export declare function currentCaptureStepIndex(): number;
|
|
11
|
+
//# sourceMappingURL=capture-context.d.ts.map
|
|
@@ -24,13 +24,27 @@ interface StepStartMessage {
|
|
|
24
24
|
stepName: string;
|
|
25
25
|
/** Distinguishes regular steps from hook executions (e.g., 'hook:onCancel', 'hook:cleanup'). Defaults to 'step'. */
|
|
26
26
|
step_type?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Initial state for the step. Defaults to `running`. A parallel-group child
|
|
29
|
+
* queued behind `maxParallel` is announced as `pending` before it acquires a
|
|
30
|
+
* slot; it later emits a second `step.start` with `running` when it launches.
|
|
31
|
+
*/
|
|
32
|
+
state?: 'running' | 'pending';
|
|
33
|
+
/** Step concurrency role; absent means an ordinary sequential step. */
|
|
34
|
+
concurrencyKind?: string;
|
|
35
|
+
/** Parallel-group correlation id shared by a group's children (e.g. `g0`). */
|
|
36
|
+
groupId?: string;
|
|
27
37
|
}
|
|
28
|
-
/** A step has completed (success, failure,
|
|
38
|
+
/** A step has completed (success, failure, check-mode skip, or fail-fast cancel). */
|
|
29
39
|
interface StepCompleteMessage {
|
|
30
40
|
type: 'step.complete';
|
|
31
41
|
stepIndex: number;
|
|
32
|
-
status: 'success' | 'failed' | 'skipped';
|
|
42
|
+
status: 'success' | 'failed' | 'skipped' | 'cancelled';
|
|
33
43
|
durationMs: number;
|
|
44
|
+
/** Step concurrency role; absent means an ordinary sequential step. */
|
|
45
|
+
concurrencyKind?: string;
|
|
46
|
+
/** Parallel-group correlation id shared by a group's children (e.g. `g0`). */
|
|
47
|
+
groupId?: string;
|
|
34
48
|
error?: {
|
|
35
49
|
message: string;
|
|
36
50
|
exitCode?: number;
|
|
@@ -202,12 +216,16 @@ export interface StepApprovalRequestIpc {
|
|
|
202
216
|
};
|
|
203
217
|
}
|
|
204
218
|
/** Which provenance upload operation to relay. */
|
|
205
|
-
export type ProvenanceRequestOp = 'requestUploadUrl' | 'complete';
|
|
219
|
+
export type ProvenanceRequestOp = 'requestUploadUrl' | 'complete' | 'defer';
|
|
206
220
|
/**
|
|
207
221
|
* Request a provenance bundle upload operation (runner -> agent). The agent
|
|
208
|
-
* relays it over the WS as a `provenance.upload.request` / `.complete`
|
|
209
|
-
* the response back as a {@link ProvenanceResponseIpc}.
|
|
210
|
-
* {@link CacheRequestIpc} relay pattern.
|
|
222
|
+
* relays it over the WS as a `provenance.upload.request` / `.complete` /
|
|
223
|
+
* `.defer` and pipes the response back as a {@link ProvenanceResponseIpc}.
|
|
224
|
+
* Mirrors the {@link CacheRequestIpc} relay pattern.
|
|
225
|
+
*
|
|
226
|
+
* `defer` captures a frozen, DSSE-signed statement for later minting (the
|
|
227
|
+
* transient mint-failure path): no upload happens; the orchestrator persists
|
|
228
|
+
* the envelope in its deferred-attestation outbox instead.
|
|
211
229
|
*/
|
|
212
230
|
export interface ProvenanceRequestIpc {
|
|
213
231
|
type: 'provenance.request';
|
|
@@ -217,10 +235,18 @@ export interface ProvenanceRequestIpc {
|
|
|
217
235
|
op: ProvenanceRequestOp;
|
|
218
236
|
/** Primary subject digest (lowercase hex) — the storage-key discriminator. */
|
|
219
237
|
subjectDigest: string;
|
|
220
|
-
/** Caller-supplied artifact name. `complete` only. */
|
|
238
|
+
/** Caller-supplied artifact name. `complete` + `defer` only. */
|
|
221
239
|
subjectName?: string;
|
|
222
|
-
/** Bundle media type. `complete` only. */
|
|
240
|
+
/** Bundle media type. `complete` + `defer` only. */
|
|
223
241
|
mediaType?: string;
|
|
242
|
+
/** Requested token audience. `defer` only. */
|
|
243
|
+
audience?: string;
|
|
244
|
+
/** SHA-256 of the frozen DSSE statement payload. `defer` only. */
|
|
245
|
+
statementHash?: string;
|
|
246
|
+
/** Frozen, DSSE-signed statement envelope. `defer` only. */
|
|
247
|
+
dsseEnvelope?: unknown;
|
|
248
|
+
/** Ephemeral public key JWK the envelope was signed with. `defer` only. */
|
|
249
|
+
publicKey?: unknown;
|
|
224
250
|
}
|
|
225
251
|
export type RunnerToAgentMessage = ReadyMessage | StepStartMessage | StepCompleteMessage | LogLineMessage | StepSecretMountMessage | JobCompleteMessage | EventEmitRequest | ConcurrencyReportMessage | AgentApiRequestIpc | CacheRequestIpc | ProvenanceRequestIpc | StepApprovalRequestIpc;
|
|
226
252
|
/** Instruct the workflow runner to execute a job. */
|
|
@@ -452,9 +478,18 @@ export interface JobExecutionRequest {
|
|
|
452
478
|
event?: Record<string, unknown>;
|
|
453
479
|
/** Git provider that originated the triggering event (e.g. 'github', 'forgejo'). */
|
|
454
480
|
provider?: string;
|
|
481
|
+
/**
|
|
482
|
+
* Platform provenance issuer, threaded from the orchestrator for a deferred
|
|
483
|
+
* attestation's frozen `builder.id`. Best-effort: absent when the orchestrator
|
|
484
|
+
* has no issuer wired (e.g. never authenticated to the Platform), in which
|
|
485
|
+
* case the frozen statement records an unknown issuer honestly. Not
|
|
486
|
+
* verification load-bearing — a deferred bundle's later token binds to the
|
|
487
|
+
* frozen statement by hash, and the authoritative org id lives in that token.
|
|
488
|
+
*/
|
|
489
|
+
provenanceIssuer?: string;
|
|
455
490
|
/** Whether to checkout the repo (default: true). */
|
|
456
491
|
checkout?: boolean;
|
|
457
|
-
/** Whether this job is part of a
|
|
492
|
+
/** Whether this job is part of a developer-initiated run triggered by `kici run`. */
|
|
458
493
|
isTestRun?: boolean;
|
|
459
494
|
/**
|
|
460
495
|
* Run mode for idempotent steps (`apply` | `check` | `check-fail-on-drift`).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concurrency-aware scheduler for `parallel()` step groups.
|
|
3
|
+
*
|
|
4
|
+
* A parallel group's children each run as their own observable step (own logs,
|
|
5
|
+
* status, timing, retry, cache, hooks — all task-scoped by the Phase 0 per-task
|
|
6
|
+
* isolation) through the same `runStepIteration` machinery the sequential loop
|
|
7
|
+
* uses. Children launch behind a `maxParallel` window (queued children report
|
|
8
|
+
* `pending`); the group joins at a barrier. On the first non-`continueOnError`
|
|
9
|
+
* child failure when `failFast`, every in-flight sibling's per-task abort
|
|
10
|
+
* controller is fired so its step race rejects and it is reported `cancelled`
|
|
11
|
+
* (which is NOT a failure).
|
|
12
|
+
*/
|
|
13
|
+
import { type StepLoopOptions, type StepNode } from './step-loop.js';
|
|
14
|
+
import type { SandboxStepResult } from './types.js';
|
|
15
|
+
type ParallelNode = Extract<StepNode, {
|
|
16
|
+
kind: 'parallel';
|
|
17
|
+
}>;
|
|
18
|
+
/** Outcome of running one parallel group. */
|
|
19
|
+
export interface ParallelGroupOutcome {
|
|
20
|
+
/** True when at least one non-`continueOnError` child failed. */
|
|
21
|
+
failed: boolean;
|
|
22
|
+
/** Name of the first failing child (drives the job failure reason). */
|
|
23
|
+
failedStepName?: string;
|
|
24
|
+
/** Per-child results, in child array order. */
|
|
25
|
+
results: SandboxStepResult[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run a parallel group: launch children with a bounded-concurrency window, join
|
|
29
|
+
* at a barrier, and fail-fast-cancel in-flight siblings on the first hard
|
|
30
|
+
* failure.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runParallelGroup(node: ParallelNode, opts: StepLoopOptions): Promise<ParallelGroupOutcome>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=parallel-scheduler.d.ts.map
|
|
@@ -10,6 +10,36 @@ import { CheckMode } from '@kici-dev/engine';
|
|
|
10
10
|
import type { RunnerToAgentMessage } from './ipc-protocol.js';
|
|
11
11
|
import type { SandboxStepResult } from './types.js';
|
|
12
12
|
import { type CachePhaseDeps } from '../cache/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Thrown inside the step race when a step's own per-task abort controller fires
|
|
15
|
+
* (parallel fail-fast cancels an in-flight sibling). Distinguished from a
|
|
16
|
+
* timeout/job-deadline reject so the loop reports the step as `cancelled`
|
|
17
|
+
* (which is NOT a failure) rather than `failed`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class StepCancelledError extends Error {
|
|
20
|
+
readonly name = "StepCancelledError";
|
|
21
|
+
constructor(stepName: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A node in the concurrency-aware step walk. A `sequential` node is one ordinary
|
|
25
|
+
* step; a `parallel` node is a `parallel()` group whose children each carry their
|
|
26
|
+
* own flat `stepIndex` (the group wrapper consumes no index).
|
|
27
|
+
*/
|
|
28
|
+
export type StepNode = {
|
|
29
|
+
kind: 'sequential';
|
|
30
|
+
step: Step;
|
|
31
|
+
stepIndex: number;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'parallel';
|
|
34
|
+
groupId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
failFast: boolean;
|
|
37
|
+
maxParallel?: number;
|
|
38
|
+
children: {
|
|
39
|
+
step: Step;
|
|
40
|
+
stepIndex: number;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
13
43
|
/** Job-level hooks passed to the step loop. */
|
|
14
44
|
export interface JobHooks {
|
|
15
45
|
beforeStep?: HookInput;
|
|
@@ -21,7 +51,32 @@ export interface JobHooks {
|
|
|
21
51
|
}
|
|
22
52
|
/** Options for the step execution loop. */
|
|
23
53
|
export interface StepLoopOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Flat list of every executable step (sequential steps + parallel-group
|
|
56
|
+
* children inlined in flat-stepIndex order). `steps.length` is the flat step
|
|
57
|
+
* count used to derive hook pseudo-indices. The structural walk order (which
|
|
58
|
+
* entries are grouped) is carried separately by `stepNodes`.
|
|
59
|
+
*/
|
|
24
60
|
steps: Step[];
|
|
61
|
+
/**
|
|
62
|
+
* Structural walk order: sequential steps and parallel groups in array order.
|
|
63
|
+
* When present, the loop walks these nodes (dispatching parallel groups to the
|
|
64
|
+
* concurrency-aware scheduler); when absent, it walks `steps` sequentially with
|
|
65
|
+
* the array index as the stepIndex (unit-harness back-compat).
|
|
66
|
+
*/
|
|
67
|
+
stepNodes?: StepNode[];
|
|
68
|
+
/**
|
|
69
|
+
* Abort the per-task controller for `stepIndex` (parallel fail-fast). Wired to
|
|
70
|
+
* the workflow-runner's `stepAbortControllers` map so an aborted sibling's
|
|
71
|
+
* `ctx.signal` fires and its step race rejects with {@link StepCancelledError}.
|
|
72
|
+
*/
|
|
73
|
+
abortStep?: (stepIndex: number) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the per-task abort signal for `stepIndex` (the same controller
|
|
76
|
+
* `abortStep` triggers). The step race watches it so a fail-fast abort
|
|
77
|
+
* interrupts an in-flight step even if its body ignores `ctx.signal`.
|
|
78
|
+
*/
|
|
79
|
+
getStepAbortSignal?: (stepIndex: number) => AbortSignal | undefined;
|
|
25
80
|
/**
|
|
26
81
|
* Run mode for idempotent steps. `apply` (default) converges; `check` /
|
|
27
82
|
* `check-fail-on-drift` preview drift and never invoke a checked step's apply.
|
|
@@ -29,6 +84,12 @@ export interface StepLoopOptions {
|
|
|
29
84
|
checkMode?: CheckMode;
|
|
30
85
|
/** Factory that creates a StepContext for a given step index and name. */
|
|
31
86
|
createStepContext: (stepIndex: number, stepName: string) => StepContext;
|
|
87
|
+
/**
|
|
88
|
+
* Run `fn` inside the step's console-capture scope so any console output it
|
|
89
|
+
* (or its hooks) produces attributes to `stepIndex`. Defaults to calling `fn`
|
|
90
|
+
* directly when absent (unit harnesses without capture wiring).
|
|
91
|
+
*/
|
|
92
|
+
runWithStepCapture?: <T>(stepIndex: number, fn: () => Promise<T>) => Promise<T>;
|
|
32
93
|
sendIpc: (msg: RunnerToAgentMessage) => void;
|
|
33
94
|
defaultTimeoutMs: number;
|
|
34
95
|
outputsMap: OutputsMap;
|
|
@@ -63,36 +124,38 @@ export interface StepLoopOptions {
|
|
|
63
124
|
/** Job start time (epoch ms) for outcome metadata duration. */
|
|
64
125
|
startTime?: number;
|
|
65
126
|
/**
|
|
66
|
-
* Returns the secret key names accessed by the
|
|
67
|
-
* Called after each step completes to include in step.complete
|
|
127
|
+
* Returns the secret key names accessed by the step context created for
|
|
128
|
+
* `stepIndex`. Called after each step completes to include in step.complete
|
|
129
|
+
* IPC messages.
|
|
68
130
|
*/
|
|
69
|
-
getSecretsAccessLog?: () => string[];
|
|
131
|
+
getSecretsAccessLog?: (stepIndex: number) => string[];
|
|
70
132
|
/**
|
|
71
|
-
* Tear down per-step state created by the
|
|
72
|
-
*
|
|
133
|
+
* Tear down per-step state created by the `createStepContext` call for
|
|
134
|
+
* `stepIndex`. Invoked from the step-loop's `finally` after the step completes
|
|
73
135
|
* (success, failure, rule-skip, or timeout) so resources like the
|
|
74
136
|
* `ctx.secrets.mountFile` tmpdir get removed even on the failure paths.
|
|
75
137
|
* Never throws -- errors are logged by the wired implementation.
|
|
76
138
|
*/
|
|
77
|
-
disposeStepResources?: () => Promise<void>;
|
|
139
|
+
disposeStepResources?: (stepIndex: number) => Promise<void>;
|
|
78
140
|
/**
|
|
79
|
-
* Returns the IPC `step.secret_mount` records collected by the
|
|
80
|
-
*
|
|
81
|
-
*
|
|
141
|
+
* Returns the IPC `step.secret_mount` records collected by the step context
|
|
142
|
+
* created for `stepIndex`. Emitted on step completion so the orchestrator can
|
|
143
|
+
* persist the audit trail alongside `secretsAccessed`.
|
|
82
144
|
*/
|
|
83
|
-
getSecretMountRecords?: () => StepSecretMountRecord[];
|
|
145
|
+
getSecretMountRecords?: (stepIndex: number) => StepSecretMountRecord[];
|
|
84
146
|
/**
|
|
85
147
|
* Before a step's run function executes, point KICI_ENV / KICI_PATH at fresh
|
|
86
|
-
* temp files for this step
|
|
148
|
+
* temp files for this step (keyed by `stepIndex` so concurrent steps never
|
|
149
|
+
* share a delta file). Invoked once per executed step (NOT for rule-skipped
|
|
87
150
|
* steps). The workflow-runner owns the file lifecycle.
|
|
88
151
|
*/
|
|
89
|
-
beforeStepEnvFiles?: () => Promise<void>;
|
|
152
|
+
beforeStepEnvFiles?: (stepIndex: number) => Promise<void>;
|
|
90
153
|
/**
|
|
91
|
-
* After a step's run function completes (success OR failure), read
|
|
92
|
-
* KICI_ENV / KICI_PATH files, apply the delta via applyEnvDelta, and
|
|
93
|
-
* them
|
|
154
|
+
* After a step's run function completes (success OR failure), read this
|
|
155
|
+
* step's KICI_ENV / KICI_PATH files, apply the delta via applyEnvDelta, and
|
|
156
|
+
* release them. Never throws -- errors are logged by the wired impl.
|
|
94
157
|
*/
|
|
95
|
-
afterStepApplyEnvFiles?: () => Promise<void>;
|
|
158
|
+
afterStepApplyEnvFiles?: (stepIndex: number) => Promise<void>;
|
|
96
159
|
/**
|
|
97
160
|
* Block an `approval` step (`when: 'always'`) pending an orchestrator-side
|
|
98
161
|
* approval hold. The runner sends the normalized requirement and awaits the
|
|
@@ -145,6 +208,18 @@ interface StepLoopResult {
|
|
|
145
208
|
stepResults: SandboxStepResult[];
|
|
146
209
|
failureReason?: string;
|
|
147
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Per-step iteration outcome returned by `runStepIteration`.
|
|
213
|
+
*/
|
|
214
|
+
export interface StepIterationOutcome {
|
|
215
|
+
/** The result to append to the running stepResults list. */
|
|
216
|
+
result: SandboxStepResult;
|
|
217
|
+
/** When true, the loop must break (failed step without continueOnError). */
|
|
218
|
+
shouldBreak: boolean;
|
|
219
|
+
/** Set when the step failed; carried into completion-hook outcome metadata. */
|
|
220
|
+
failedStepName?: string;
|
|
221
|
+
}
|
|
222
|
+
export declare function runStepIteration(step: Step, stepIndex: number, opts: StepLoopOptions): Promise<StepIterationOutcome>;
|
|
148
223
|
/**
|
|
149
224
|
* Execute the step loop with hook integration and step-level rule evaluation.
|
|
150
225
|
*
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StepSecretMountRecord, TrackedStepSecrets } from '@kici-dev/sdk';
|
|
2
|
+
/** Per-step secrets handle + its teardown closure, keyed by step index. */
|
|
3
|
+
export interface StepTaskSlot {
|
|
4
|
+
secrets: TrackedStepSecrets;
|
|
5
|
+
dispose: () => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Per-task replacement for the runner's former `currentStepSecrets` /
|
|
9
|
+
* `currentStepDispose` single-slots.
|
|
10
|
+
*
|
|
11
|
+
* The runner used to remember only the *most recent* step's secrets handle and
|
|
12
|
+
* dispose closure; the access-log / mount-record / dispose reader callbacks read
|
|
13
|
+
* that single slot. Under sequential execution that is correct (one step at a
|
|
14
|
+
* time), but two concurrently-running steps would clobber each other's
|
|
15
|
+
* secrets-audit trail. Keying every slot by the step's index keeps each step's
|
|
16
|
+
* audit trail and teardown isolated — sequential behavior is identical, Phase 1
|
|
17
|
+
* concurrency is correct.
|
|
18
|
+
*/
|
|
19
|
+
export declare class StepTaskRegistry {
|
|
20
|
+
#private;
|
|
21
|
+
set(stepIndex: number, slot: StepTaskSlot): void;
|
|
22
|
+
getAccessLog(stepIndex: number): string[];
|
|
23
|
+
getMountRecords(stepIndex: number): StepSecretMountRecord[];
|
|
24
|
+
dispose(stepIndex: number): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=step-task-registry.d.ts.map
|
|
@@ -150,8 +150,8 @@ export interface SandboxStepResult {
|
|
|
150
150
|
name: string;
|
|
151
151
|
/** Zero-based index of the step within the job. */
|
|
152
152
|
stepIndex: number;
|
|
153
|
-
/** Step execution status. */
|
|
154
|
-
status: 'success' | 'failed' | 'skipped';
|
|
153
|
+
/** Step execution status. `cancelled` = a parallel sibling fail-fast cancel. */
|
|
154
|
+
status: 'success' | 'failed' | 'skipped' | 'cancelled';
|
|
155
155
|
/** Step duration in milliseconds. */
|
|
156
156
|
durationMs: number;
|
|
157
157
|
/** Error details when status is 'failed'. */
|
|
@@ -35,7 +35,7 @@ export declare function buildStepNeedsContext(declaredNeeds: readonly unknown[]
|
|
|
35
35
|
* NOT serialized across the process boundary. This means zx $ runs natively
|
|
36
36
|
* inside this process with full shell access.
|
|
37
37
|
*/
|
|
38
|
-
export declare function createSandboxStepContext(workDir: string, stepIndex: number, stepName: string, request: JobExecutionRequest, maskedSendFn: (msg: RunnerToAgentMessage) => void, outputsMap: OutputsMap, refMap: StepRefMap, operatorSecretKeys: Set<string>, secretOutputs: Map<string, string>, jobOutputsMap: OutputsMap, secrets: TrackedStepSecrets, masker: LogMasker): StepContext;
|
|
38
|
+
export declare function createSandboxStepContext(workDir: string, stepIndex: number, stepName: string, request: JobExecutionRequest, maskedSendFn: (msg: RunnerToAgentMessage) => void, outputsMap: OutputsMap, refMap: StepRefMap, operatorSecretKeys: Set<string>, secretOutputs: Map<string, string>, jobOutputsMap: OutputsMap, secrets: TrackedStepSecrets, masker: LogMasker, signal: AbortSignal): StepContext;
|
|
39
39
|
/**
|
|
40
40
|
* Derive the fan-out position (`ctx.fanout`) from a dispatch request. Returns
|
|
41
41
|
* `undefined` for a non-fan-out job (no `fanoutTotal`), so `ctx.fanout` is only
|
|
@@ -44,4 +44,25 @@ export declare function createSandboxStepContext(workDir: string, stepIndex: num
|
|
|
44
44
|
export declare function deriveFanout(request: JobExecutionRequest): FanoutPosition | undefined;
|
|
45
45
|
/** Raw provider webhook body for ctx.rawPayload — nested in the envelope. */
|
|
46
46
|
export declare function rawPayloadFromEvent(event: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Build the step loop's KICI_ENV/KICI_PATH callbacks with a per-step delta-file
|
|
49
|
+
* pair (keyed by step index). `beforeStepEnvFiles(stepIndex)` lazily creates the
|
|
50
|
+
* step's pair and points the runner's process.env at it (each step's zx $
|
|
51
|
+
* snapshots process.env at context creation, which happens AFTER this
|
|
52
|
+
* before-hook, so the shell sees them; the pre-fork env allowlist does not
|
|
53
|
+
* re-filter runtime-set vars). `afterStepApplyEnvFiles(stepIndex)` applies that
|
|
54
|
+
* step's delta and releases the pair.
|
|
55
|
+
*
|
|
56
|
+
* Env-isolation contract: under sequential execution this is identical to a
|
|
57
|
+
* single shared pair truncated between steps — each step still sees only its own
|
|
58
|
+
* delta. The pair is now per-step so two concurrently-running steps cannot
|
|
59
|
+
* corrupt each other's delta file. `process.env.KICI_ENV` / `process.env.KICI_PATH`
|
|
60
|
+
* remain process-global, so Phase 1 forbids `setEnv` / `addPath` / `$KICI_ENV`
|
|
61
|
+
* writes inside `parallel()` children (compile-time validation); Phase 0 only
|
|
62
|
+
* makes the file pair per-task.
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildStepEnvFileHooks(operatorSecretKeys: Set<string>, maskedSend: (msg: RunnerToAgentMessage) => void): {
|
|
65
|
+
beforeStepEnvFiles: (stepIndex: number) => Promise<void>;
|
|
66
|
+
afterStepApplyEnvFiles: (stepIndex: number) => Promise<void>;
|
|
67
|
+
};
|
|
47
68
|
//# sourceMappingURL=workflow-runner.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,14 @@ import https from "node:https";
|
|
|
20
20
|
import http from "node:http";
|
|
21
21
|
import "node:url";
|
|
22
22
|
var __defProp = Object.defineProperty;
|
|
23
|
-
var __esmMin = (fn, res) => () =>
|
|
23
|
+
var __esmMin = (fn, res, err) => () => {
|
|
24
|
+
if (err) throw err[0];
|
|
25
|
+
try {
|
|
26
|
+
return fn && (res = fn(fn = 0)), res;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw err = [e], e;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
24
31
|
var __exportAll = (all, no_symbols) => {
|
|
25
32
|
let target = {};
|
|
26
33
|
for (var name in all) __defProp(target, name, {
|
|
@@ -30,7 +37,6 @@ var __exportAll = (all, no_symbols) => {
|
|
|
30
37
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
31
38
|
return target;
|
|
32
39
|
};
|
|
33
|
-
import.meta.url;
|
|
34
40
|
//#endregion
|
|
35
41
|
//#region src/config.ts
|
|
36
42
|
/** Execution mode for the agent's sandbox backend. Mirrors the runtime enum. */
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import { type KiciBundle } from '@kici-dev/engine/provenance/bundle';
|
|
2
2
|
import type { OidcTokenResult } from '@kici-dev/engine/protocol/messages/oidc-token-relay';
|
|
3
|
-
import { type ProvenanceSubject } from './statement-builder.js';
|
|
3
|
+
import { type LocalBuildContext, type ProvenanceSubject } from './statement-builder.js';
|
|
4
|
+
/** The frozen, DSSE-signed attestation the agent reports for later fulfilment. */
|
|
5
|
+
export interface DeferredAttestationReport {
|
|
6
|
+
subjectName: string;
|
|
7
|
+
subjectDigest: string;
|
|
8
|
+
audience: string;
|
|
9
|
+
mediaType: string;
|
|
10
|
+
statementHash: string;
|
|
11
|
+
dsseEnvelope: KiciBundle['dsseEnvelope'];
|
|
12
|
+
publicKey: Record<string, unknown>;
|
|
13
|
+
}
|
|
4
14
|
export interface AttestDeps {
|
|
5
|
-
/** P1.4 relay: returns a KiCI ID token
|
|
15
|
+
/** P1.4 relay: returns a minted KiCI ID token or a transient `deferred` signal. */
|
|
6
16
|
getIdToken: (opts: {
|
|
7
17
|
audience: string;
|
|
8
18
|
}) => Promise<OidcTokenResult>;
|
|
9
19
|
/** Upload the serialized bundle; returns the storage key it was written to. */
|
|
10
20
|
persist: (bundle: KiciBundle, subjectDigest: string) => Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Report a frozen, DSSE-signed statement for later minting (the transient
|
|
23
|
+
* mint-failure path). Required only when the relay may defer; the live path
|
|
24
|
+
* never calls it.
|
|
25
|
+
*/
|
|
26
|
+
reportDeferred?: (report: DeferredAttestationReport) => Promise<void>;
|
|
27
|
+
/** Agent-local job facts used to freeze a statement when the mint defers. */
|
|
28
|
+
localContext?: LocalBuildContext;
|
|
11
29
|
builderVersions: {
|
|
12
30
|
'kici-agent': string;
|
|
13
31
|
'kici-orchestrator': string;
|
|
@@ -19,11 +37,16 @@ export interface AttestInput {
|
|
|
19
37
|
subject: ProvenanceSubject;
|
|
20
38
|
audience?: string;
|
|
21
39
|
}
|
|
22
|
-
|
|
40
|
+
/** A minted-and-uploaded attestation, or a deferred one captured for later. */
|
|
41
|
+
export type AttestResult = {
|
|
23
42
|
storageKey: string;
|
|
24
43
|
bundle: KiciBundle;
|
|
25
44
|
subjectDigest: string;
|
|
26
|
-
}
|
|
45
|
+
} | {
|
|
46
|
+
deferred: true;
|
|
47
|
+
statementHash: string;
|
|
48
|
+
subjectDigest: string;
|
|
49
|
+
};
|
|
27
50
|
export declare function attestProvenance(deps: AttestDeps, input: AttestInput): Promise<AttestResult>;
|
|
28
51
|
/**
|
|
29
52
|
* Pick the primary digest (`sha256` preferred) as the storage-key discriminator.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* statement's identity equals the token's identity by construction.
|
|
6
6
|
*/
|
|
7
7
|
import { type KiciProvenanceStatement } from '@kici-dev/engine/provenance/schema';
|
|
8
|
+
import type { SourceOrigin } from '@kici-dev/engine';
|
|
8
9
|
/** The KiCI identity-token claims the builder reads (Platform server-truth). */
|
|
9
10
|
export interface ProvenanceTokenClaims {
|
|
10
11
|
iss: string;
|
|
@@ -15,6 +16,12 @@ export interface ProvenanceTokenClaims {
|
|
|
15
16
|
kici_run_id: string;
|
|
16
17
|
kici_job_id: string;
|
|
17
18
|
orchestrator_id?: string | null;
|
|
19
|
+
/** Authoritative origin: the customer's public org id (Platform-asserted). */
|
|
20
|
+
org_id?: string;
|
|
21
|
+
/** Source-origin brand: triggered vs run-remote (local working-tree overlay). */
|
|
22
|
+
source_origin?: SourceOrigin;
|
|
23
|
+
/** Informational source provider (github / gitlab / bitbucket / local). */
|
|
24
|
+
provider?: string | null;
|
|
18
25
|
}
|
|
19
26
|
/** Caller-supplied artifact subject: a name plus a lowercase-hex digest map. */
|
|
20
27
|
export interface ProvenanceSubject {
|
|
@@ -33,6 +40,49 @@ export interface BuildStatementInput {
|
|
|
33
40
|
/** ISO-8601 timestamp with offset. */
|
|
34
41
|
finishedOn: string;
|
|
35
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Agent-local job context used to freeze a provenance statement for a deferred
|
|
45
|
+
* attestation. When the Platform mint fails transiently there is no identity
|
|
46
|
+
* token to read claims from, so the statement is built from facts the agent
|
|
47
|
+
* already holds about the job it just ran. Only the identity token is deferred;
|
|
48
|
+
* these attested facts are sealed (DSSE-signed) at build time.
|
|
49
|
+
*/
|
|
50
|
+
export interface LocalBuildContext {
|
|
51
|
+
repository: string;
|
|
52
|
+
ref: string;
|
|
53
|
+
sha: string | null;
|
|
54
|
+
workflowRef: string;
|
|
55
|
+
runId: string;
|
|
56
|
+
jobId: string;
|
|
57
|
+
orgId?: string;
|
|
58
|
+
sourceOrigin?: SourceOrigin;
|
|
59
|
+
/**
|
|
60
|
+
* Platform provenance issuer for the `builder.id`. The agent does not always
|
|
61
|
+
* know it at build time (the orchestrator may be disconnected — that is why
|
|
62
|
+
* the mint deferred), so it is best-effort; an empty string yields a
|
|
63
|
+
* `/orchestrator/unknown` builder id. This field is not verification
|
|
64
|
+
* load-bearing for a deferred bundle: the later token binds to the frozen
|
|
65
|
+
* statement by hash, not by field-for-field cross-check.
|
|
66
|
+
*/
|
|
67
|
+
issuer: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build a frozen SLSA v1.0 provenance statement from agent-local job context,
|
|
71
|
+
* for a deferred attestation (no minted identity token yet). Marks
|
|
72
|
+
* `attestationOrigin: 'deferred'` in the internal parameters. The caller
|
|
73
|
+
* DSSE-signs the returned statement immediately and computes its statement hash
|
|
74
|
+
* — the binding the later OIDC mint commits to (truth-contract property 2).
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildLocalProvenanceStatement(input: {
|
|
77
|
+
context: LocalBuildContext;
|
|
78
|
+
subject: ProvenanceSubject;
|
|
79
|
+
builderVersions: {
|
|
80
|
+
'kici-agent': string;
|
|
81
|
+
'kici-orchestrator': string;
|
|
82
|
+
};
|
|
83
|
+
startedOn: string;
|
|
84
|
+
finishedOn: string;
|
|
85
|
+
}): KiciProvenanceStatement;
|
|
36
86
|
/** Build a KiCI SLSA v1.0 provenance statement (validates against the P1.1 schema). */
|
|
37
87
|
export declare function buildProvenanceStatement(input: BuildStatementInput): KiciProvenanceStatement;
|
|
38
88
|
//# sourceMappingURL=statement-builder.d.ts.map
|