@atolis-hq/wake 0.4.107 → 0.4.109
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/src/activities/agent/agent-activity.js +4 -0
- package/dist/src/activities/agent/agent-result.js +1 -0
- package/dist/src/activities/contracts/activity.d.ts +6 -0
- package/dist/src/activities/pr/approve.js +1 -1
- package/dist/src/activities/pr/merge.js +1 -1
- package/dist/src/activities/pr/parent-scope.d.ts +8 -2
- package/dist/src/activities/pr/parent-scope.js +7 -1
- package/dist/src/activities/pr/parent-target.d.ts +2 -2
- package/dist/src/activities/pr/parent-target.js +1 -0
- package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
- package/dist/src/bootstrap/delivery-integration.js +7 -4
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
- package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
- package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
- package/dist/src/control-plane/application/dispatch-resources.js +9 -0
- package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
- package/dist/src/execution/application/change-output-workspaces.js +123 -0
- package/dist/src/execution/application/execution-service.js +15 -2
- package/dist/src/execution/application/maintenance-workspaces.js +20 -12
- package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
- package/dist/src/execution/application/run-lifecycle.js +2 -0
- package/dist/src/execution/contracts/change-output.d.ts +15 -0
- package/dist/src/execution/contracts/change-output.js +12 -0
- package/dist/src/execution/contracts/commands.d.ts +5 -0
- package/dist/src/execution/contracts/events.d.ts +16 -0
- package/dist/src/execution/contracts/events.js +4 -0
- package/dist/src/execution/contracts/runner.d.ts +1 -0
- package/dist/src/execution/contracts/views.d.ts +3 -0
- package/dist/src/execution/contracts/workspace.d.ts +4 -0
- package/dist/src/execution/domain/run.js +3 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/execution/infrastructure/runners/claude.js +5 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
- package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
- package/dist/src/integrations/application/artifact-registration-reactor.js +9 -22
- package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
- package/dist/src/integrations/application/artifact-verification-source.js +36 -0
- package/dist/src/integrations/application/delegation-outputs.js +56 -20
- package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
- package/dist/src/integrations/contracts/artifact-events.js +1 -0
- package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
- package/dist/src/orchestration/application/delegated-work.js +30 -3
- package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
- package/dist/src/orchestration/application/delegation-reservation.js +33 -5
- package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
- package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
- package/dist/src/orchestration/application/orchestration-service.js +6 -1
- package/dist/src/orchestration/contracts/config.d.ts +15 -0
- package/dist/src/orchestration/contracts/config.js +8 -1
- package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
- package/dist/src/orchestration/contracts/delegation.js +11 -5
- package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
- package/dist/src/orchestration/contracts/vocabulary.js +2 -0
- package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
- package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
- package/dist/src/orchestration/domain/compiler.js +1 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
- package/dist/src/orchestration/domain/delivery-facts.js +4 -2
- package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
- package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
- package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
- package/dist/src/orchestration/domain/delivery-selection.js +2 -1
- package/package.json +1 -1
|
@@ -232,6 +232,10 @@ function appendWorkspacePrompt(prompt, workspace) {
|
|
|
232
232
|
if (workspace?.candidate !== undefined)
|
|
233
233
|
prompt +=
|
|
234
234
|
'\n\nExact delivery candidate prepared by Wake:\n' + JSON.stringify(workspace.candidate);
|
|
235
|
+
if (workspace?.changeOutputs !== undefined)
|
|
236
|
+
prompt +=
|
|
237
|
+
'\n\nNamed change output workspaces (use each separate leased path and branch; report every PR with its exact output name):\n' +
|
|
238
|
+
JSON.stringify(workspace.changeOutputs);
|
|
235
239
|
if (workspace?.maintenance !== undefined)
|
|
236
240
|
prompt +=
|
|
237
241
|
'\n\nPull requests Wake leased for maintenance (each path is the owning child branch workspace; ' +
|
|
@@ -110,6 +110,12 @@ export interface ActivityExecutionContext {
|
|
|
110
110
|
/** Isolated workspace leased by Execution for this invocation, when requested. */
|
|
111
111
|
readonly workspace?: {
|
|
112
112
|
readonly path: string;
|
|
113
|
+
readonly changeOutputs?: readonly {
|
|
114
|
+
readonly name: string;
|
|
115
|
+
readonly path: string;
|
|
116
|
+
readonly branch: string;
|
|
117
|
+
readonly revision: string;
|
|
118
|
+
}[] | undefined;
|
|
113
119
|
readonly mode: ActivityWorkspaceMode;
|
|
114
120
|
readonly checkoutRevision?: string | undefined;
|
|
115
121
|
readonly candidate?: {
|
|
@@ -55,7 +55,7 @@ async function executeApproval(journal, pullRequests, appender, parentActions, i
|
|
|
55
55
|
const prior = await readDecisionClaim(journal, invocation.activationId, 'approve');
|
|
56
56
|
if (prior !== null)
|
|
57
57
|
return completeDecisionClaim(journal, appender, prior);
|
|
58
|
-
const parentTarget = await resolveParentTarget(parentActions, invocation, invocation.input.scope
|
|
58
|
+
const parentTarget = await resolveParentTarget(parentActions, invocation, invocation.input.scope, ParentActionKind.Approve);
|
|
59
59
|
if (parentTarget.kind === 'fully-integrated')
|
|
60
60
|
return { kind: ActivityOutcomeKind.Integrated, data: { complete: true } };
|
|
61
61
|
const scoped = parentTarget.kind === 'target' ? parentTarget : undefined;
|
|
@@ -94,7 +94,7 @@ async function executeMerge(journal, pullRequests, appender, parentActions, invo
|
|
|
94
94
|
const prior = await readDecisionClaim(journal, invocation.activationId, MergeMethod.Merge);
|
|
95
95
|
if (prior !== null)
|
|
96
96
|
return completeDecisionClaim(journal, appender, prior);
|
|
97
|
-
const parentTarget = await resolveParentTarget(parentActions, invocation, invocation.input.scope
|
|
97
|
+
const parentTarget = await resolveParentTarget(parentActions, invocation, invocation.input.scope, ParentActionKind.Merge);
|
|
98
98
|
if (parentTarget.kind === 'fully-integrated')
|
|
99
99
|
return { kind: ActivityOutcomeKind.Integrated, data: { complete: true } };
|
|
100
100
|
const scoped = parentTarget.kind === 'target' ? parentTarget : undefined;
|
|
@@ -10,11 +10,16 @@ export declare const ParentActionKind: {
|
|
|
10
10
|
};
|
|
11
11
|
export type ParentActionKind = (typeof ParentActionKind)[keyof typeof ParentActionKind];
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Select a named output from the parent's durable selection. The child identity may be
|
|
14
|
+
* omitted only when the output name resolves uniquely across that selection.
|
|
15
15
|
*/
|
|
16
|
+
export interface ParentOutputTarget {
|
|
17
|
+
readonly childWorkItemId?: string | undefined;
|
|
18
|
+
readonly outputName: string;
|
|
19
|
+
}
|
|
16
20
|
export interface ParentDeliveryScope {
|
|
17
21
|
readonly delivery: 'next';
|
|
22
|
+
readonly output?: ParentOutputTarget | undefined;
|
|
18
23
|
}
|
|
19
24
|
export declare const parentDeliveryScopeSchema: z.ZodType<ParentDeliveryScope>;
|
|
20
25
|
/**
|
|
@@ -47,6 +52,7 @@ export interface ParentActionRequest {
|
|
|
47
52
|
readonly workflowInstanceId: string;
|
|
48
53
|
readonly activationId: ActivationId;
|
|
49
54
|
readonly action: ParentActionKind;
|
|
55
|
+
readonly output?: ParentOutputTarget | undefined;
|
|
50
56
|
}
|
|
51
57
|
export type ParentActionDecision = {
|
|
52
58
|
readonly kind: 'target';
|
|
@@ -4,7 +4,13 @@ import { workItemId } from '../../work/index.js';
|
|
|
4
4
|
/** The one action a parent delivery may ask of a child-owned pull request. */
|
|
5
5
|
export const ParentActionKind = { Approve: 'approve', Merge: 'merge-pr' };
|
|
6
6
|
export const parentDeliveryScopeSchema = z
|
|
7
|
-
.object({
|
|
7
|
+
.object({
|
|
8
|
+
delivery: z.literal('next'),
|
|
9
|
+
output: z
|
|
10
|
+
.object({ childWorkItemId: z.string().min(1).optional(), outputName: z.string().min(1) })
|
|
11
|
+
.strict()
|
|
12
|
+
.optional(),
|
|
13
|
+
})
|
|
8
14
|
.strict();
|
|
9
15
|
/**
|
|
10
16
|
* Durable context recorded on the delivery intent. The requesting parent and the resource owner
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ResourceCapability } from '../../resources/index.js';
|
|
2
2
|
import type { ActivityInvocation } from '../contracts/activity.js';
|
|
3
3
|
import type { PullRequestAuthorityInput, PullRequestTarget } from './contracts.js';
|
|
4
|
-
import type { ParentActionAuthorizer, ParentActionDecision, ParentActionKind } from './parent-scope.js';
|
|
4
|
+
import type { ParentActionAuthorizer, ParentActionDecision, ParentActionKind, ParentDeliveryScope } from './parent-scope.js';
|
|
5
5
|
import { PullRequestDenialCode } from './vocabulary.js';
|
|
6
6
|
export type ParentTarget = {
|
|
7
7
|
readonly kind: 'unscoped';
|
|
@@ -13,7 +13,7 @@ export type ParentTarget = {
|
|
|
13
13
|
* not a validated delivery parent, the request is denied rather than falling back to the
|
|
14
14
|
* invoking WorkItem: a scoped input never widens into generic cross-WorkItem invocation.
|
|
15
15
|
*/
|
|
16
|
-
export declare function resolveParentTarget(authorizer: ParentActionAuthorizer | undefined, invocation: Pick<ActivityInvocation, 'workflowInstanceId' | 'activationId'>, scoped: boolean, action: ParentActionKind): Promise<ParentTarget>;
|
|
16
|
+
export declare function resolveParentTarget(authorizer: ParentActionAuthorizer | undefined, invocation: Pick<ActivityInvocation, 'workflowInstanceId' | 'activationId'>, scoped: boolean | ParentDeliveryScope | undefined, action: ParentActionKind): Promise<ParentTarget>;
|
|
17
17
|
/** The pull request an action applies to: the parent's scoped target, or the WorkItem's own primary. */
|
|
18
18
|
export declare function resolveActionResource(parentTarget: ParentTarget, authority: PullRequestAuthorityInput, invocation: Pick<ActivityInvocation, 'resources' | 'workItemId'>, target: PullRequestTarget, capability: ResourceCapability): {
|
|
19
19
|
readonly allowed: true;
|
|
@@ -16,6 +16,7 @@ export async function resolveParentTarget(authorizer, invocation, scoped, action
|
|
|
16
16
|
workflowInstanceId: invocation.workflowInstanceId,
|
|
17
17
|
activationId: invocation.activationId,
|
|
18
18
|
action,
|
|
19
|
+
...(typeof scoped === 'object' && scoped.output !== undefined ? { output: scoped.output } : {}),
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
/** The pull request an action applies to: the parent's scoped target, or the WorkItem's own primary. */
|
|
@@ -28,6 +28,13 @@ declare const orchestrationConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
28
28
|
stage: z.ZodString;
|
|
29
29
|
}, z.core.$strict>>;
|
|
30
30
|
}, z.core.$strict>>;
|
|
31
|
+
outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
32
|
+
kind: z.ZodEnum<{
|
|
33
|
+
change: "change";
|
|
34
|
+
artifact: "artifact";
|
|
35
|
+
}>;
|
|
36
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
}, z.core.$strict>>>;
|
|
31
38
|
commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
32
39
|
activity: z.ZodString;
|
|
33
40
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -207,6 +214,13 @@ export declare const rootConfigSchema: z.ZodObject<{
|
|
|
207
214
|
stage: z.ZodString;
|
|
208
215
|
}, z.core.$strict>>;
|
|
209
216
|
}, z.core.$strict>>;
|
|
217
|
+
outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
218
|
+
kind: z.ZodEnum<{
|
|
219
|
+
change: "change";
|
|
220
|
+
artifact: "artifact";
|
|
221
|
+
}>;
|
|
222
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
}, z.core.$strict>>>;
|
|
210
224
|
commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
211
225
|
activity: z.ZodString;
|
|
212
226
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -23,7 +23,7 @@ export function createDeliveryIntegration(pullRequests, runs, verification) {
|
|
|
23
23
|
async assertMaintenanceWriter(request) {
|
|
24
24
|
const all = await runs();
|
|
25
25
|
const run = all.find((entry) => entry.runId === request.runId);
|
|
26
|
-
const leased = run?.workspace?.maintenance?.targets.
|
|
26
|
+
const leased = run?.workspace?.maintenance?.targets.find((target) => target.childWorkItemId === request.childWorkItemId &&
|
|
27
27
|
target.resourceId === request.resourceId &&
|
|
28
28
|
target.revision.toLowerCase() === request.revision.toLowerCase());
|
|
29
29
|
if (run === undefined ||
|
|
@@ -31,14 +31,17 @@ export function createDeliveryIntegration(pullRequests, runs, verification) {
|
|
|
31
31
|
run.cancellation !== undefined ||
|
|
32
32
|
run.activationId !== request.activationId ||
|
|
33
33
|
run.workflowInstanceId !== request.workflowInstanceId ||
|
|
34
|
-
leased
|
|
34
|
+
leased === undefined)
|
|
35
35
|
throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, 'Maintenance must be reported by the Run that Wake prepared with this target branch lease');
|
|
36
36
|
// An earlier writer whose outcome is unknown may have pushed; it must be reconciled first.
|
|
37
37
|
const unresolved = all.find((entry) => entry.runId !== request.runId &&
|
|
38
38
|
entry.status === RunStatus.Ambiguous &&
|
|
39
|
-
((entry.workspace?.branch ===
|
|
39
|
+
(((entry.workspace?.branch === leased.branch ||
|
|
40
|
+
entry.workspace?.changeOutputs?.some((output) => output.branch === leased.branch) ===
|
|
41
|
+
true) &&
|
|
40
42
|
entry.workspace?.mode === WorkspaceMode.Branch) ||
|
|
41
|
-
entry.workspace?.maintenance?.targets.some((target) => target.childWorkItemId === request.childWorkItemId
|
|
43
|
+
entry.workspace?.maintenance?.targets.some((target) => target.childWorkItemId === request.childWorkItemId &&
|
|
44
|
+
target.outputName === leased.outputName) === true));
|
|
42
45
|
if (unresolved !== undefined)
|
|
43
46
|
throw new DeliveryRejectionError(DeliveryRejection.AmbiguousWriter, `Run ${unresolved.runId} may have written to ${request.childWorkItemId}; reconcile it before recording maintenance`);
|
|
44
47
|
},
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.109";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -15,6 +15,11 @@ export interface OrchestrationPort {
|
|
|
15
15
|
listWaiting(): Promise<readonly (WorkflowInstanceView | null)[]>;
|
|
16
16
|
deliveryQaPreparation?(workflowInstanceId: string): Promise<ExecutionCandidate | undefined>;
|
|
17
17
|
deliveryMaintenancePreparation?(workflowInstanceId: string): Promise<ExecutionMaintenance | undefined>;
|
|
18
|
+
changeOutputAssignments?(workItemId: string): Promise<readonly {
|
|
19
|
+
name: string;
|
|
20
|
+
repository: RepositoryAssignment;
|
|
21
|
+
isolated?: boolean;
|
|
22
|
+
}[] | undefined>;
|
|
18
23
|
repositoryAssignment?(workItemId: string): Promise<RepositoryAssignment | undefined>;
|
|
19
24
|
get?(workflowInstanceId: string): Promise<WorkflowInstanceView | null>;
|
|
20
25
|
expireTimedOutWaits?(context: CommandContext): Promise<readonly WorkflowInstanceView[]>;
|
|
@@ -47,6 +52,11 @@ export interface ExecutionPort {
|
|
|
47
52
|
workItemId: WorkflowInstanceView['workItemId'];
|
|
48
53
|
workflowInstanceId: WorkflowInstanceView['workflowInstanceId'];
|
|
49
54
|
orchestrationGroupId: WorkflowInstanceView['orchestrationGroupId'];
|
|
55
|
+
changeOutputAssignments?: readonly {
|
|
56
|
+
name: string;
|
|
57
|
+
repository: RepositoryAssignment;
|
|
58
|
+
isolated?: boolean;
|
|
59
|
+
}[];
|
|
50
60
|
repositoryAssignment?: RepositoryAssignment;
|
|
51
61
|
candidate?: ExecutionCandidate;
|
|
52
62
|
maintenance?: ExecutionMaintenance;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deliveryCapacity } from '../domain/delivery-capacity.js';
|
|
2
|
-
import {
|
|
2
|
+
import { dispatchRepositoryContext } from './dispatch-resources.js';
|
|
3
3
|
import { isRunnerQuotaOutcome, reportUnappliedRunnerQuotaRetry, runnerQuotaMessage, } from './runner-quota-outcome.js';
|
|
4
4
|
import { ActivationClaimConflictError, isActiveRunStatus, NoEligibleRunnerError, RunStatus, WorkspaceMode, } from '../../execution/index.js';
|
|
5
5
|
import { DelegationPendingError, WorkflowStatus } from '../../orchestration/index.js';
|
|
@@ -92,8 +92,7 @@ export async function runDispatchLoop(pending, ctx) {
|
|
|
92
92
|
await ctx.orchestration.markActivationStarted(selected.workflow.workflowInstanceId, selected.activation.activationId, ctx.commandContext(selected.activation.activationId));
|
|
93
93
|
startedWorkflowIds.add(selected.workflow.workflowInstanceId);
|
|
94
94
|
const { workItemId } = selected.workflow;
|
|
95
|
-
const
|
|
96
|
-
const resourceViews = await dispatchResources(ctx.resources, workItemId, repositoryAssignment);
|
|
95
|
+
const repositoryContext = await dispatchRepositoryContext(ctx.orchestration, ctx.resources, workItemId);
|
|
97
96
|
const instanceId = selected.workflow.workflowInstanceId;
|
|
98
97
|
const candidate = await ctx.orchestration.deliveryQaPreparation?.(instanceId);
|
|
99
98
|
const maintenance = await ctx.orchestration.deliveryMaintenancePreparation?.(instanceId);
|
|
@@ -101,10 +100,9 @@ export async function runDispatchLoop(pending, ctx) {
|
|
|
101
100
|
workItemId,
|
|
102
101
|
workflowInstanceId: instanceId,
|
|
103
102
|
orchestrationGroupId: selected.workflow.orchestrationGroupId,
|
|
104
|
-
|
|
103
|
+
...repositoryContext,
|
|
105
104
|
...(candidate === undefined ? {} : { candidate }),
|
|
106
105
|
...(maintenance === undefined ? {} : { maintenance }),
|
|
107
|
-
...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
|
|
108
106
|
sessionPolicy: (candidate ?? maintenance) !== undefined ||
|
|
109
107
|
selected.activation.sessionPolicy === 'fresh' ||
|
|
110
108
|
selected.workflow.parentWorkflowInstanceId !== undefined
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { RepositoryAssignment } from '../../execution/index.js';
|
|
2
2
|
import { type ResourceService } from '../../resources/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
|
+
import type { OrchestrationPort } from './activation-scheduler-ports.js';
|
|
4
5
|
export declare function dispatchResources(resources: ResourceService, workItemId: WorkItemId, assignment: RepositoryAssignment | undefined): Promise<import("../../resources/index.js").ResourceView[]>;
|
|
6
|
+
export declare function dispatchRepositoryContext(orchestration: OrchestrationPort, resources: ResourceService, workItemId: WorkItemId): Promise<{
|
|
7
|
+
changeOutputAssignments?: readonly {
|
|
8
|
+
name: string;
|
|
9
|
+
repository: RepositoryAssignment;
|
|
10
|
+
isolated?: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
repositoryAssignment?: RepositoryAssignment;
|
|
13
|
+
resources: import("../../resources/index.js").ResourceView[];
|
|
14
|
+
}>;
|
|
@@ -11,3 +11,12 @@ export async function dispatchResources(resources, workItemId, assignment) {
|
|
|
11
11
|
}
|
|
12
12
|
return views;
|
|
13
13
|
}
|
|
14
|
+
export async function dispatchRepositoryContext(orchestration, resources, workItemId) {
|
|
15
|
+
const repositoryAssignment = await orchestration.repositoryAssignment?.(workItemId);
|
|
16
|
+
const changeOutputAssignments = await orchestration.changeOutputAssignments?.(workItemId);
|
|
17
|
+
return {
|
|
18
|
+
resources: await dispatchResources(resources, workItemId, repositoryAssignment),
|
|
19
|
+
...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
|
|
20
|
+
...(changeOutputAssignments === undefined ? {} : { changeOutputAssignments }),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExecutionActivation, ExecutionAttemptContext } from '../contracts/commands.js';
|
|
2
|
+
import type { RunId } from '../contracts/identifiers.js';
|
|
3
|
+
import type { RunView } from '../contracts/views.js';
|
|
4
|
+
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
5
|
+
import type { WorkspaceLease, WorkspaceProvider } from '../contracts/workspace.js';
|
|
6
|
+
interface ChangeOutputRequest {
|
|
7
|
+
readonly runId: RunId;
|
|
8
|
+
readonly context: ExecutionAttemptContext;
|
|
9
|
+
readonly mode: typeof WorkspaceMode.Branch | typeof WorkspaceMode.ReadOnly;
|
|
10
|
+
readonly runs: readonly RunView[];
|
|
11
|
+
readonly signal: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export declare function needsChangeOutputWorkspaces(context: ExecutionAttemptContext, activation: ExecutionActivation, runs: readonly RunView[]): activation is ExecutionActivation & {
|
|
14
|
+
readonly execution: {
|
|
15
|
+
readonly workspace: typeof WorkspaceMode.Branch | typeof WorkspaceMode.ReadOnly;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** Lease all named branches in a stable order; retain the real child as each workspace owner. */
|
|
19
|
+
export declare function acquireChangeOutputWorkspaces(request: ChangeOutputRequest, provider: WorkspaceProvider | undefined): Promise<WorkspaceLease>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { BuiltInResourceKind } from '../../resources/index.js';
|
|
2
|
+
import { RunStatus, WorkspaceMode } from '../contracts/vocabulary.js';
|
|
3
|
+
export function needsChangeOutputWorkspaces(context, activation, runs) {
|
|
4
|
+
if (context.changeOutputAssignments?.some((output) => output.isolated === true) !== true)
|
|
5
|
+
return false;
|
|
6
|
+
if (activation.execution?.workspace === WorkspaceMode.Branch)
|
|
7
|
+
return true;
|
|
8
|
+
return (activation.execution?.workspace === WorkspaceMode.ReadOnly &&
|
|
9
|
+
runs.some((run) => run.orchestrationGroupId === context.orchestrationGroupId &&
|
|
10
|
+
run.changeOutputs !== undefined));
|
|
11
|
+
}
|
|
12
|
+
/** Lease all named branches in a stable order; retain the real child as each workspace owner. */
|
|
13
|
+
export async function acquireChangeOutputWorkspaces(request, provider) {
|
|
14
|
+
if (provider === undefined)
|
|
15
|
+
throw new Error('Named change outputs need a workspace provider');
|
|
16
|
+
const { outputs, repository } = prepareOutputs(request);
|
|
17
|
+
const leases = [];
|
|
18
|
+
const snapshots = [];
|
|
19
|
+
try {
|
|
20
|
+
for (const output of outputs) {
|
|
21
|
+
const previous = previousOutput(request, output.name);
|
|
22
|
+
const lease = await provider.acquire({
|
|
23
|
+
runId: request.runId,
|
|
24
|
+
workItemId: request.context.workItemId,
|
|
25
|
+
outputName: output.name,
|
|
26
|
+
signal: request.signal,
|
|
27
|
+
mode: request.mode,
|
|
28
|
+
repositoryResource: repository,
|
|
29
|
+
assignment: output.repository,
|
|
30
|
+
checkoutRevision: request.mode === WorkspaceMode.ReadOnly
|
|
31
|
+
? (previous?.revision ?? output.repository.sourceRevision)
|
|
32
|
+
: output.repository.sourceRevision,
|
|
33
|
+
});
|
|
34
|
+
leases.push(lease);
|
|
35
|
+
snapshots.push(await snapshot(output, lease, request.mode === WorkspaceMode.Branch ? lease.branch : previous?.branch));
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...leases[0],
|
|
39
|
+
changeOutputs: snapshots,
|
|
40
|
+
...(request.mode === WorkspaceMode.Branch
|
|
41
|
+
? {
|
|
42
|
+
readChangeOutputs: () => Promise.all(snapshots.map(async (entry, index) => ({
|
|
43
|
+
...entry,
|
|
44
|
+
revision: await readRevision(leases[index]),
|
|
45
|
+
}))),
|
|
46
|
+
}
|
|
47
|
+
: {}),
|
|
48
|
+
release: () => releaseAll(leases),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
try {
|
|
53
|
+
await releaseAll(leases);
|
|
54
|
+
}
|
|
55
|
+
catch (cleanup) {
|
|
56
|
+
throw new AggregateError([error, cleanup], 'Change output preparation and cleanup failed', {
|
|
57
|
+
cause: cleanup,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function prepareOutputs(request) {
|
|
64
|
+
const { context } = request;
|
|
65
|
+
const outputs = [...(context.changeOutputAssignments ?? [])].sort((a, b) => a.name.localeCompare(b.name));
|
|
66
|
+
const names = outputs.map((output) => output.name);
|
|
67
|
+
const repository = context.resources.find((entry) => entry.resourceId === context.repositoryAssignment?.resourceId &&
|
|
68
|
+
entry.kind === BuiltInResourceKind.Repository);
|
|
69
|
+
if (repository === undefined || names.length === 0)
|
|
70
|
+
throw new Error('Assigned change output repository is unavailable');
|
|
71
|
+
if (new Set(names).size !== names.length)
|
|
72
|
+
throw new Error('Duplicate named change output');
|
|
73
|
+
if (outputs.some((output) => output.repository.resourceId !== repository.resourceId))
|
|
74
|
+
throw new Error('Change output is outside the assigned repository');
|
|
75
|
+
if (request.runs.some((run) => ambiguousWriter(run, context)))
|
|
76
|
+
throw new Error('Named change output has an unresolved earlier writer');
|
|
77
|
+
return { outputs, repository };
|
|
78
|
+
}
|
|
79
|
+
function ambiguousWriter(run, context) {
|
|
80
|
+
return (run.status === RunStatus.Ambiguous &&
|
|
81
|
+
((run.orchestrationGroupId === context.orchestrationGroupId &&
|
|
82
|
+
run.workspace?.mode === WorkspaceMode.Branch) ||
|
|
83
|
+
run.workspace?.maintenance?.targets.some((target) => target.childWorkItemId === context.workItemId) === true));
|
|
84
|
+
}
|
|
85
|
+
function previousOutput(request, name) {
|
|
86
|
+
return request.runs
|
|
87
|
+
.filter((run) => run.orchestrationGroupId === request.context.orchestrationGroupId &&
|
|
88
|
+
run.status === RunStatus.Succeeded &&
|
|
89
|
+
run.workspace?.mode === WorkspaceMode.Branch)
|
|
90
|
+
.flatMap((run) => run.changeOutputs ?? [])
|
|
91
|
+
.filter((entry) => entry.name === name)
|
|
92
|
+
.at(-1);
|
|
93
|
+
}
|
|
94
|
+
async function snapshot(output, lease, branch) {
|
|
95
|
+
if (branch === undefined)
|
|
96
|
+
throw new Error('Named change output workspace lacks attested branch');
|
|
97
|
+
return {
|
|
98
|
+
name: output.name,
|
|
99
|
+
path: lease.path,
|
|
100
|
+
branch,
|
|
101
|
+
repository: output.repository,
|
|
102
|
+
revision: await readRevision(lease),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function readRevision(lease) {
|
|
106
|
+
const revision = await lease.readRevision?.();
|
|
107
|
+
if (revision === undefined)
|
|
108
|
+
throw new Error('Change output HEAD is unavailable');
|
|
109
|
+
return revision;
|
|
110
|
+
}
|
|
111
|
+
async function releaseAll(leases) {
|
|
112
|
+
const failures = [];
|
|
113
|
+
for (const lease of [...leases].reverse()) {
|
|
114
|
+
try {
|
|
115
|
+
await lease.release();
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
failures.push(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (failures.length > 0)
|
|
122
|
+
throw new AggregateError(failures, 'Change output lease cleanup failed');
|
|
123
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { acquireCandidateWorkspaces } from './candidate-workspaces.js';
|
|
2
|
+
import { acquireChangeOutputWorkspaces, needsChangeOutputWorkspaces, } from './change-output-workspaces.js';
|
|
2
3
|
import { acquireMaintenanceWorkspaces } from './maintenance-workspaces.js';
|
|
3
4
|
import { ActivityExecutionKind, } from '../../activities/index.js';
|
|
4
5
|
import { runId } from '../contracts/identifiers.js';
|
|
@@ -344,6 +345,7 @@ async function settleRunSuccess(runtime, currentRunId, activation, context, outc
|
|
|
344
345
|
return;
|
|
345
346
|
}
|
|
346
347
|
const workspaceRevision = await lease?.readRevision?.();
|
|
348
|
+
const changeOutputs = await lease?.readChangeOutputs?.();
|
|
347
349
|
await recordRunSuccess({
|
|
348
350
|
dependencies: runLifecycleDependencies(runtime),
|
|
349
351
|
runId: currentRunId,
|
|
@@ -351,6 +353,7 @@ async function settleRunSuccess(runtime, currentRunId, activation, context, outc
|
|
|
351
353
|
context,
|
|
352
354
|
outcome,
|
|
353
355
|
...(workspaceRevision === undefined ? {} : { workspaceRevision }),
|
|
356
|
+
...(changeOutputs === undefined ? {} : { changeOutputs }),
|
|
354
357
|
});
|
|
355
358
|
}
|
|
356
359
|
async function settleRunFailure(runtime, currentRunId, activation, context, error) {
|
|
@@ -601,12 +604,21 @@ async function claimActivationForAttempt(runtime, activation, currentRunId, owne
|
|
|
601
604
|
});
|
|
602
605
|
}
|
|
603
606
|
async function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
|
|
607
|
+
const runs = await runtime.repository.list();
|
|
608
|
+
if (needsChangeOutputWorkspaces(context, activation, runs))
|
|
609
|
+
return acquireChangeOutputWorkspaces({
|
|
610
|
+
runId: currentRunId,
|
|
611
|
+
context,
|
|
612
|
+
mode: activation.execution.workspace,
|
|
613
|
+
runs,
|
|
614
|
+
signal: signal ?? new AbortController().signal,
|
|
615
|
+
}, runtime.dependencies.workspaces);
|
|
604
616
|
if (context.maintenance !== undefined)
|
|
605
617
|
return acquireMaintenanceWorkspaces({
|
|
606
618
|
runId: currentRunId,
|
|
607
619
|
resources: context.resources,
|
|
608
620
|
maintenance: context.maintenance,
|
|
609
|
-
runs
|
|
621
|
+
runs,
|
|
610
622
|
signal: signal ?? new AbortController().signal,
|
|
611
623
|
}, runtime.dependencies.workspaces);
|
|
612
624
|
if (context.candidate !== undefined)
|
|
@@ -619,7 +631,7 @@ async function acquireAttemptWorkspace(runtime, activation, context, currentRunI
|
|
|
619
631
|
}, runtime.dependencies.workspaces);
|
|
620
632
|
const previous = context.repositoryAssignment === undefined
|
|
621
633
|
? undefined
|
|
622
|
-
:
|
|
634
|
+
: runs
|
|
623
635
|
.filter((run) => run.orchestrationGroupId === context.orchestrationGroupId &&
|
|
624
636
|
run.workspace?.mode === WorkspaceMode.Branch &&
|
|
625
637
|
run.status === RunStatus.Succeeded)
|
|
@@ -663,6 +675,7 @@ function activityWorkspace(lease, context) {
|
|
|
663
675
|
? undefined
|
|
664
676
|
: { ...context.candidate, ...lease.candidate },
|
|
665
677
|
maintenance: lease.maintenance,
|
|
678
|
+
changeOutputs: lease.changeOutputs,
|
|
666
679
|
},
|
|
667
680
|
}),
|
|
668
681
|
};
|
|
@@ -10,18 +10,9 @@ export async function acquireMaintenanceWorkspaces(request, provider) {
|
|
|
10
10
|
if (provider === undefined)
|
|
11
11
|
throw new Error('Maintenance needs a workspace provider');
|
|
12
12
|
const maintenance = executionMaintenanceSchema.parse(request.maintenance);
|
|
13
|
-
const targets = [...maintenance.targets].sort((a, b) => a.childWorkItemId
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (const target of targets) {
|
|
17
|
-
const unresolved = request.runs.find((run) => run.runId !== request.runId &&
|
|
18
|
-
run.status === RunStatus.Ambiguous &&
|
|
19
|
-
((run.workspace?.branch === target.childWorkItemId &&
|
|
20
|
-
run.workspace?.mode === WorkspaceMode.Branch) ||
|
|
21
|
-
run.workspace?.maintenance?.targets.some((entry) => entry.childWorkItemId === target.childWorkItemId) === true));
|
|
22
|
-
if (unresolved !== undefined)
|
|
23
|
-
throw new Error(`Maintenance target ${target.childWorkItemId} has an unresolved earlier writer: Run ${unresolved.runId}`);
|
|
24
|
-
}
|
|
13
|
+
const targets = [...maintenance.targets].sort((a, b) => a.childWorkItemId.localeCompare(b.childWorkItemId) ||
|
|
14
|
+
a.outputName.localeCompare(b.outputName));
|
|
15
|
+
assertMaintenanceWriters(targets, request);
|
|
25
16
|
const leases = [];
|
|
26
17
|
try {
|
|
27
18
|
for (const target of targets) {
|
|
@@ -33,6 +24,7 @@ export async function acquireMaintenanceWorkspaces(request, provider) {
|
|
|
33
24
|
const lease = await provider.acquire({
|
|
34
25
|
runId: request.runId,
|
|
35
26
|
workItemId: target.childWorkItemId,
|
|
27
|
+
...(target.branch === target.childWorkItemId ? {} : { outputName: target.outputName }),
|
|
36
28
|
signal: request.signal,
|
|
37
29
|
mode: WorkspaceMode.Branch,
|
|
38
30
|
repositoryResource: resource,
|
|
@@ -82,3 +74,19 @@ async function releaseAll(leases) {
|
|
|
82
74
|
if (failures.length > 0)
|
|
83
75
|
throw new AggregateError(failures, 'Maintenance lease cleanup failed');
|
|
84
76
|
}
|
|
77
|
+
function assertMaintenanceWriters(targets, request) {
|
|
78
|
+
if (new Set(targets.map((entry) => JSON.stringify([entry.childWorkItemId, entry.outputName])))
|
|
79
|
+
.size !== targets.length)
|
|
80
|
+
throw new Error('Duplicate maintenance target');
|
|
81
|
+
for (const target of targets) {
|
|
82
|
+
const unresolved = request.runs.find((run) => run.runId !== request.runId &&
|
|
83
|
+
run.status === RunStatus.Ambiguous &&
|
|
84
|
+
(((run.workspace?.branch === target.branch ||
|
|
85
|
+
run.workspace?.changeOutputs?.some((entry) => entry.branch === target.branch) === true) &&
|
|
86
|
+
run.workspace?.mode === WorkspaceMode.Branch) ||
|
|
87
|
+
run.workspace?.maintenance?.targets.some((entry) => entry.childWorkItemId === target.childWorkItemId &&
|
|
88
|
+
entry.outputName === target.outputName) === true));
|
|
89
|
+
if (unresolved !== undefined)
|
|
90
|
+
throw new Error(`Maintenance target ${target.childWorkItemId} has an unresolved earlier writer: Run ${unresolved.runId}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ActivityOutcome } from '../../activities/index.js';
|
|
2
2
|
import { type Clock } from '../../kernel/index.js';
|
|
3
|
+
import type { ChangeOutputWorkspace } from '../contracts/change-output.js';
|
|
3
4
|
import type { ExecutionActivation, ExecutionAttemptContext } from '../contracts/commands.js';
|
|
4
5
|
import type { ExecutionConfig } from '../contracts/config.js';
|
|
5
6
|
import { type RunExecutionEventData, type RunExecutionEventPayloads } from '../contracts/events.js';
|
|
@@ -51,6 +52,7 @@ export declare function recordRunSuccess(input: {
|
|
|
51
52
|
readonly context: ExecutionAttemptContext;
|
|
52
53
|
readonly outcome: ActivityOutcome;
|
|
53
54
|
readonly workspaceRevision?: string;
|
|
55
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[];
|
|
54
56
|
}): Promise<void>;
|
|
55
57
|
export declare function recordRunFailure(input: {
|
|
56
58
|
readonly dependencies: RunLifecycleDependencies;
|
|
@@ -122,6 +122,7 @@ export async function recordRunSuccess(input) {
|
|
|
122
122
|
payload: {
|
|
123
123
|
outcome,
|
|
124
124
|
finishedAt,
|
|
125
|
+
...(input.changeOutputs === undefined ? {} : { changeOutputs: input.changeOutputs }),
|
|
125
126
|
...(input.workspaceRevision === undefined
|
|
126
127
|
? {}
|
|
127
128
|
: { workspaceRevision: input.workspaceRevision }),
|
|
@@ -196,6 +197,7 @@ function workspacePayload(lease) {
|
|
|
196
197
|
? {}
|
|
197
198
|
: { checkoutRevision: lease.checkoutRevision }),
|
|
198
199
|
path: lease.path,
|
|
200
|
+
...(lease.changeOutputs === undefined ? {} : { changeOutputs: lease.changeOutputs }),
|
|
199
201
|
...(lease.candidate === undefined ? {} : { candidate: lease.candidate }),
|
|
200
202
|
...(lease.maintenance === undefined ? {} : { maintenance: lease.maintenance }),
|
|
201
203
|
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Recorded by Execution from leased workspaces, never supplied by a PR claim. */
|
|
3
|
+
export declare const changeOutputWorkspaceSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
path: z.ZodString;
|
|
6
|
+
branch: z.ZodString;
|
|
7
|
+
repository: z.ZodObject<{
|
|
8
|
+
resourceId: z.ZodString;
|
|
9
|
+
sourceRef: z.ZodString;
|
|
10
|
+
sourceRevision: z.ZodString;
|
|
11
|
+
pullRequestBase: z.ZodString;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
revision: z.ZodString;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export type ChangeOutputWorkspace = z.infer<typeof changeOutputWorkspaceSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { repositoryAssignmentSchema } from './repository-assignment.js';
|
|
3
|
+
/** Recorded by Execution from leased workspaces, never supplied by a PR claim. */
|
|
4
|
+
export const changeOutputWorkspaceSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
name: z.string().min(1),
|
|
7
|
+
path: z.string().min(1),
|
|
8
|
+
branch: z.string().min(1),
|
|
9
|
+
repository: repositoryAssignmentSchema,
|
|
10
|
+
revision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i),
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
@@ -25,6 +25,11 @@ export interface ExecutionAttemptContext {
|
|
|
25
25
|
readonly workflowInstanceId: ActivityWorkflowInstanceId;
|
|
26
26
|
readonly orchestrationGroupId: ActivityOrchestrationGroupId;
|
|
27
27
|
readonly resources: readonly ResourceView[];
|
|
28
|
+
readonly changeOutputAssignments?: readonly {
|
|
29
|
+
name: string;
|
|
30
|
+
repository: RepositoryAssignment;
|
|
31
|
+
isolated?: boolean;
|
|
32
|
+
}[];
|
|
28
33
|
readonly repositoryAssignment?: RepositoryAssignment;
|
|
29
34
|
readonly owner?: string;
|
|
30
35
|
/** Runner names currently quota-paused; unset means none. */
|