@atolis-hq/wake 0.4.124 → 0.4.125
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/bootstrap/version.js +1 -1
- package/dist/src/integrations/application/delegation-output-claims.d.ts +13 -0
- package/dist/src/integrations/application/delegation-output-claims.js +21 -0
- package/dist/src/integrations/application/delegation-output-review.d.ts +9 -0
- package/dist/src/integrations/application/delegation-output-review.js +26 -8
- package/dist/src/integrations/application/delegation-outputs.d.ts +1 -0
- package/dist/src/integrations/application/delegation-outputs.js +14 -24
- package/dist/src/orchestration/application/delegation-review-policy.d.ts +1 -0
- package/dist/src/orchestration/application/delegation-review-policy.js +6 -6
- package/dist/src/orchestration/application/prerequisite-output-blocker.d.ts +4 -0
- package/dist/src/orchestration/application/prerequisite-output-blocker.js +15 -0
- package/dist/src/orchestration/application/prerequisite-readiness.js +11 -13
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +2 -1
- package/package.json +1 -1
|
@@ -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.125";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RunView } from '../../execution/index.js';
|
|
2
|
+
/** Latest run's claim for a name; identical repeats collapse, conflicting repeats yield no claim. */
|
|
3
|
+
export declare function reportedChange(runs: readonly RunView[], name: string): {
|
|
4
|
+
run: RunView;
|
|
5
|
+
report: {
|
|
6
|
+
kind: string;
|
|
7
|
+
externalKey: {
|
|
8
|
+
adapter: string;
|
|
9
|
+
key: string;
|
|
10
|
+
};
|
|
11
|
+
name?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
} | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { reportedArtifactSchema } from '../../activities/index.js';
|
|
3
|
+
import { BuiltInResourceKind } from '../../resources/index.js';
|
|
4
|
+
const reportsSchema = z.object({ reportedArtifacts: z.array(reportedArtifactSchema) });
|
|
5
|
+
/** Latest run's claim for a name; identical repeats collapse, conflicting repeats yield no claim. */
|
|
6
|
+
export function reportedChange(runs, name) {
|
|
7
|
+
const claims = runs.flatMap((run) => {
|
|
8
|
+
const data = reportsSchema.safeParse(run.outcome?.data);
|
|
9
|
+
const reports = data.success
|
|
10
|
+
? data.data.reportedArtifacts.filter((entry) => entry.name === name && entry.kind === BuiltInResourceKind.PullRequest)
|
|
11
|
+
: [];
|
|
12
|
+
return reports.length === 0 ? [] : [{ run, reports }];
|
|
13
|
+
});
|
|
14
|
+
const latest = claims.at(-1);
|
|
15
|
+
const report = latest?.reports[0];
|
|
16
|
+
if (latest === undefined || report === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
const conflicting = latest.reports.some((entry) => entry.externalKey.adapter !== report.externalKey.adapter ||
|
|
19
|
+
entry.externalKey.key !== report.externalKey.key);
|
|
20
|
+
return conflicting ? undefined : { run: latest.run, report };
|
|
21
|
+
}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
import { PullRequestDenialCode } from '../../activities/index.js';
|
|
1
2
|
import { type RunView } from '../../execution/index.js';
|
|
2
3
|
import type { WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
4
|
export type DelegationReviewPolicy = (child: WorkflowInstanceView) => Promise<{
|
|
4
5
|
readonly requireApproval: boolean;
|
|
6
|
+
readonly allowTrustedReview?: boolean;
|
|
5
7
|
readonly review?: WorkflowInstanceView | undefined;
|
|
6
8
|
}>;
|
|
7
9
|
/** A watch verdict is usable only with an accepted review Run's exact checkout attestation. */
|
|
8
10
|
export declare function deliveryReadyRequirements(input: {
|
|
9
11
|
readonly reviewPolicy?: DelegationReviewPolicy;
|
|
12
|
+
readonly blocked?: (reason: string) => void;
|
|
10
13
|
readonly runs: () => Promise<readonly RunView[]>;
|
|
11
14
|
}, child: WorkflowInstanceView, revision: string): Promise<{
|
|
12
15
|
requireReview: boolean;
|
|
13
16
|
requireChecks: boolean;
|
|
17
|
+
reviewFallbackReason: string;
|
|
18
|
+
} | {
|
|
19
|
+
requireReview: boolean;
|
|
20
|
+
requireChecks: boolean;
|
|
21
|
+
reviewFallbackReason?: never;
|
|
14
22
|
} | null>;
|
|
23
|
+
export declare function outputAuthorityReason(reason: PullRequestDenialCode, requireApproval: boolean, reviewFallbackReason?: string): string;
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
1
|
+
import { ActivityOutcomeKind, PullRequestDenialCode } from '../../activities/index.js';
|
|
2
2
|
import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
3
3
|
/** A watch verdict is usable only with an accepted review Run's exact checkout attestation. */
|
|
4
4
|
export async function deliveryReadyRequirements(input, child, revision) {
|
|
5
5
|
const policy = (await input.reviewPolicy?.(child)) ?? { requireApproval: true };
|
|
6
|
-
if (!policy.requireApproval
|
|
7
|
-
|
|
6
|
+
if (!policy.requireApproval) {
|
|
7
|
+
const reason = await reviewedHead(input.runs, child, policy.review, revision);
|
|
8
|
+
if (reason !== undefined) {
|
|
9
|
+
if (policy.allowTrustedReview)
|
|
10
|
+
return { requireReview: true, requireChecks: true, reviewFallbackReason: reason };
|
|
11
|
+
input.blocked?.(reason);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
return { requireReview: policy.requireApproval, requireChecks: true };
|
|
9
16
|
}
|
|
10
17
|
async function reviewedHead(runs, child, review, revision) {
|
|
11
18
|
if (review === undefined || review.parentWorkflowInstanceId !== child.workflowInstanceId)
|
|
12
|
-
return
|
|
19
|
+
return 'No accepted review verdict';
|
|
13
20
|
const reviewed = (await runs())
|
|
14
21
|
.filter((run) => run.workflowInstanceId === review.workflowInstanceId &&
|
|
15
22
|
review.acceptedOutcomes.includes(run.activationId) &&
|
|
16
23
|
run.workspace?.mode === WorkspaceMode.ReadOnly)
|
|
17
24
|
.at(-1);
|
|
18
|
-
|
|
19
|
-
reviewed.status
|
|
20
|
-
reviewed.outcome?.kind
|
|
21
|
-
|
|
25
|
+
if (reviewed === undefined ||
|
|
26
|
+
reviewed.status !== RunStatus.Succeeded ||
|
|
27
|
+
reviewed.outcome?.kind !== ActivityOutcomeKind.Done)
|
|
28
|
+
return 'No accepted successful read-only review verdict';
|
|
29
|
+
return reviewed.workspaceRevision === revision
|
|
30
|
+
? undefined
|
|
31
|
+
: 'No accepted review attesting exact head ' + revision;
|
|
32
|
+
}
|
|
33
|
+
export function outputAuthorityReason(reason, requireApproval, reviewFallbackReason) {
|
|
34
|
+
if (reviewFallbackReason !== undefined)
|
|
35
|
+
return reviewFallbackReason + '; Trusted PR review fallback: ' + reason;
|
|
36
|
+
const trustedReview = requireApproval &&
|
|
37
|
+
(reason === PullRequestDenialCode.StaleApproval ||
|
|
38
|
+
reason === PullRequestDenialCode.UntrustedActor);
|
|
39
|
+
return ((trustedReview ? 'Approval policy requires trusted review: ' : 'Output authority: ') + reason);
|
|
22
40
|
}
|
|
@@ -5,6 +5,7 @@ import { type ResourceService } from '../../resources/index.js';
|
|
|
5
5
|
import type { ProviderInstance } from '../contracts/provider.js';
|
|
6
6
|
import { type DelegationReviewPolicy } from './delegation-output-review.js';
|
|
7
7
|
interface OutputDependencies {
|
|
8
|
+
readonly blocked?: (reason: string) => void;
|
|
8
9
|
readonly reviewPolicy?: DelegationReviewPolicy;
|
|
9
10
|
readonly artifacts: DelegationArtifacts;
|
|
10
11
|
readonly resources: ResourceService;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ActivityOutcomeKind, decidePullRequestOutputAuthority, PullRequestState, reportedArtifactSchema, } from '../../activities/index.js';
|
|
1
|
+
import { ActivityOutcomeKind, decidePullRequestOutputAuthority, PullRequestState, } from '../../activities/index.js';
|
|
3
2
|
import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
4
3
|
import { DelegationPrerequisiteCondition as Condition } from '../../orchestration/index.js';
|
|
5
4
|
import { BuiltInResourceKind, ResourceCorrelationProvenance, ResourceCorrelationRole, resourceId, } from '../../resources/index.js';
|
|
6
5
|
import { ArtifactVerificationResult } from '../contracts/artifact-vocabulary.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import { reportedChange } from './delegation-output-claims.js';
|
|
7
|
+
import { deliveryReadyRequirements, outputAuthorityReason, } from './delegation-output-review.js';
|
|
9
8
|
/** Select exact provider-verified results owned by the producing child. */
|
|
10
9
|
export function createDelegationOutputs(input) {
|
|
11
10
|
return {
|
|
@@ -13,14 +12,14 @@ export function createDelegationOutputs(input) {
|
|
|
13
12
|
async runActivation(runId) {
|
|
14
13
|
return (await input.runs()).find((run) => run.runId === runId)?.activationId;
|
|
15
14
|
},
|
|
16
|
-
async prerequisiteOutput(child, output, condition) {
|
|
15
|
+
async prerequisiteOutput(child, output, condition, blocked) {
|
|
17
16
|
if ('path' in output &&
|
|
18
17
|
(condition === Condition.AcceptedOutput || condition === Condition.DeliveryReady)) {
|
|
19
18
|
return (await input.artifacts.qualifyingOutputs(child, [output]))?.[0] ?? null;
|
|
20
19
|
}
|
|
21
20
|
if (!('kind' in output))
|
|
22
21
|
return null;
|
|
23
|
-
return qualifyingChange(input, child, output, condition);
|
|
22
|
+
return qualifyingChange(blocked === undefined ? input : { ...input, blocked }, child, output, condition);
|
|
24
23
|
},
|
|
25
24
|
async qualifyingOutputs(child, outputs) {
|
|
26
25
|
const references = [];
|
|
@@ -50,23 +49,6 @@ export function createDelegationOutputs(input) {
|
|
|
50
49
|
},
|
|
51
50
|
};
|
|
52
51
|
}
|
|
53
|
-
/** Latest run's claim for a name; identical repeats collapse, conflicting repeats yield no claim. */
|
|
54
|
-
function reportedChange(runs, name) {
|
|
55
|
-
const claims = runs.flatMap((run) => {
|
|
56
|
-
const data = reportsSchema.safeParse(run.outcome?.data);
|
|
57
|
-
const reports = data.success
|
|
58
|
-
? data.data.reportedArtifacts.filter((entry) => entry.name === name && entry.kind === BuiltInResourceKind.PullRequest)
|
|
59
|
-
: [];
|
|
60
|
-
return reports.length === 0 ? [] : [{ run, reports }];
|
|
61
|
-
});
|
|
62
|
-
const latest = claims.at(-1);
|
|
63
|
-
const report = latest?.reports[0];
|
|
64
|
-
if (latest === undefined || report === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
const conflicting = latest.reports.some((entry) => entry.externalKey.adapter !== report.externalKey.adapter ||
|
|
67
|
-
entry.externalKey.key !== report.externalKey.key);
|
|
68
|
-
return conflicting ? undefined : { run: latest.run, report };
|
|
69
|
-
}
|
|
70
52
|
async function verifiedChange(input, report, source) {
|
|
71
53
|
const { assignment, branch, revision } = source;
|
|
72
54
|
const repository = await input.resources.get(resourceId(assignment.resourceId));
|
|
@@ -164,8 +146,16 @@ async function hasOutputAuthority(input, child, output, id, revision) {
|
|
|
164
146
|
const authority = observed?.state === PullRequestState.Merged
|
|
165
147
|
? decidePullRequestOutputAuthority(await input.pullRequests.authorityInput(child.workItemId), options)
|
|
166
148
|
: await input.pullRequests.decideAuthority(child.workItemId, options);
|
|
167
|
-
if (!authority.allowed
|
|
149
|
+
if (!authority.allowed) {
|
|
150
|
+
input.blocked?.(outputAuthorityReason(authority.reason, options.requireAcceptedReview, output.reviewFallbackReason));
|
|
168
151
|
return false;
|
|
152
|
+
}
|
|
153
|
+
if (authority.revision !== revision) {
|
|
154
|
+
input.blocked?.([output.reviewFallbackReason, 'Output authority does not attest exact head ' + revision]
|
|
155
|
+
.filter((reason) => reason !== undefined)
|
|
156
|
+
.join('; '));
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
169
159
|
return true;
|
|
170
160
|
}
|
|
171
161
|
function runSource(run, name) {
|
|
@@ -5,4 +5,5 @@ import type { WorkflowDefinitionRegistry } from './workflow-definition-registry.
|
|
|
5
5
|
export declare function createDelegationReviewPolicy(repository: OrchestrationRepository, definitions: WorkflowDefinitionRegistry): (child: WorkflowInstanceView) => Promise<{
|
|
6
6
|
requireApproval: boolean;
|
|
7
7
|
review: WorkflowInstanceView | undefined;
|
|
8
|
+
allowTrustedReview: boolean;
|
|
8
9
|
}>;
|
|
@@ -12,15 +12,15 @@ export function createDelegationReviewPolicy(repository, definitions) {
|
|
|
12
12
|
])
|
|
13
13
|
.filter((activity) => activity.use === BuiltInActivityName.PullRequestMerge)
|
|
14
14
|
.map((activity) => pullRequestMergeInputSchema.safeParse(activity.with));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
// Without a merge policy, either trusted PR review or an exact-head watch review can qualify.
|
|
16
|
+
const requireApproval = merges.some((parsed) => !parsed.success ||
|
|
17
|
+
parsed.data.target !== ActivityResourceRole.Primary ||
|
|
18
|
+
parsed.data.scope !== undefined ||
|
|
19
|
+
parsed.data.requireApproval);
|
|
20
20
|
const history = await repository.history(child.workflowInstanceId);
|
|
21
21
|
const accepted = acceptedReview(history.events);
|
|
22
22
|
const review = accepted === undefined ? undefined : ((await repository.load(accepted)).view ?? undefined);
|
|
23
|
-
return { requireApproval, review };
|
|
23
|
+
return { requireApproval, review, allowTrustedReview: merges.length === 0 };
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
function acceptedReview(events) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DelegationPrerequisite } from '../contracts/delegation.js';
|
|
2
|
+
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
3
|
+
export declare function outputBlocker(edge: DelegationPrerequisite, assignment: string, reason?: string): string;
|
|
4
|
+
export declare function workflowReason(workflow: WorkflowInstanceView, edge: DelegationPrerequisite): "Upstream workflow failed" | "Waiting for delivery-ready upstream" | "Upstream workflow was superseded" | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DelegationPrerequisiteCondition as Condition, WorkflowStatus, } from '../contracts/vocabulary.js';
|
|
2
|
+
import { isSuccessfulWorkflowCompletion } from '../domain/workflow-completion.js';
|
|
3
|
+
export function outputBlocker(edge, assignment, reason) {
|
|
4
|
+
const prefix = `Waiting for ${edge.condition} output ${assignment}/${edge.output}`;
|
|
5
|
+
return reason === undefined ? prefix : prefix + ': ' + reason;
|
|
6
|
+
}
|
|
7
|
+
export function workflowReason(workflow, edge) {
|
|
8
|
+
if (workflow.status === WorkflowStatus.Completed && !isSuccessfulWorkflowCompletion(workflow))
|
|
9
|
+
return 'Upstream workflow failed';
|
|
10
|
+
if (edge.condition === Condition.DeliveryReady && !isSuccessfulWorkflowCompletion(workflow))
|
|
11
|
+
return 'Waiting for delivery-ready upstream';
|
|
12
|
+
if (workflow.status === WorkflowStatus.Superseded)
|
|
13
|
+
return 'Upstream workflow was superseded';
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { WorkStatus } from '../../work/index.js';
|
|
3
3
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
4
|
-
import { PrerequisiteBlockCode as Code,
|
|
4
|
+
import { PrerequisiteBlockCode as Code, WorkflowStatus } from '../contracts/vocabulary.js';
|
|
5
5
|
import { isSuccessfulWorkflowCompletion } from '../domain/workflow-completion.js';
|
|
6
6
|
import { reservationsOf } from './delegation-ledger.js';
|
|
7
|
+
import { outputBlocker, workflowReason } from './prerequisite-output-blocker.js';
|
|
7
8
|
import { changedInputsBlock, freshness, inheritedBlock, } from './prerequisite-refresh-inputs.js';
|
|
8
9
|
import { prerequisiteRevisions, revisionOutputPending, revisionPending, } from './prerequisite-revisions.js';
|
|
9
10
|
/** A bounded read pass: one journal/Work snapshot and one lookup per declared input. */
|
|
@@ -139,7 +140,10 @@ export class PrerequisiteReadiness {
|
|
|
139
140
|
for (const [index, edge] of (child.prerequisites ?? []).entries()) {
|
|
140
141
|
const upstream = this.children.get(child.prerequisiteWorkItemIds?.[index] ?? '');
|
|
141
142
|
if (upstream === undefined)
|
|
142
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
code: Code.Unavailable,
|
|
145
|
+
reason: 'Upstream prerequisite not found: ' + edge.assignmentId + '/' + edge.output,
|
|
146
|
+
};
|
|
143
147
|
const key = JSON.stringify([upstream.workItemId, edge.output, edge.condition]);
|
|
144
148
|
let pending = this.selected.get(key);
|
|
145
149
|
if (pending === undefined) {
|
|
@@ -194,13 +198,16 @@ export class PrerequisiteReadiness {
|
|
|
194
198
|
const evidence = this.revisionEvidence;
|
|
195
199
|
if (revisionPending(workflow, evidence.pending))
|
|
196
200
|
return { code: Code.Waiting, reason: 'Waiting for upstream review revision' };
|
|
197
|
-
|
|
201
|
+
let reason;
|
|
202
|
+
const selected = await this.artifacts.prerequisiteOutput?.(workflow, output, edge.condition, (value) => {
|
|
203
|
+
reason = value;
|
|
204
|
+
});
|
|
198
205
|
if (selected == null ||
|
|
199
206
|
selected.name !== edge.output ||
|
|
200
207
|
selected.reference.workItemId !== upstream.workItemId)
|
|
201
208
|
return {
|
|
202
209
|
code: Code.Waiting,
|
|
203
|
-
reason:
|
|
210
|
+
reason: outputBlocker(edge, upstream.assignmentId, reason),
|
|
204
211
|
};
|
|
205
212
|
if (await revisionOutputPending(workflow, selected.reference, this.artifacts, evidence))
|
|
206
213
|
return { code: Code.Waiting, reason: 'Waiting for verified upstream review revision' };
|
|
@@ -239,12 +246,3 @@ export class PrerequisiteReadiness {
|
|
|
239
246
|
return undefined;
|
|
240
247
|
}
|
|
241
248
|
}
|
|
242
|
-
function workflowReason(workflow, edge) {
|
|
243
|
-
if (workflow.status === WorkflowStatus.Completed && !isSuccessfulWorkflowCompletion(workflow))
|
|
244
|
-
return 'Upstream workflow failed';
|
|
245
|
-
if (edge.condition === Condition.DeliveryReady && !isSuccessfulWorkflowCompletion(workflow))
|
|
246
|
-
return 'Waiting for delivery-ready upstream';
|
|
247
|
-
if (workflow.status === WorkflowStatus.Superseded)
|
|
248
|
-
return 'Upstream workflow was superseded';
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
@@ -6,7 +6,8 @@ import type { WorkflowInstanceView } from './views.js';
|
|
|
6
6
|
/** Trusted Bootstrap adapters; no provider, Run or session authority is supplied by assignments. */
|
|
7
7
|
export interface DelegationArtifacts {
|
|
8
8
|
runActivation?(runId: string): Promise<ActivationId | undefined>;
|
|
9
|
-
|
|
9
|
+
/** Reports a wait reason from the same evaluation, without repeating provider verification. */
|
|
10
|
+
prerequisiteOutput?(child: WorkflowInstanceView, output: DelegatedAssignment['outputs'][number], condition: DelegationPrerequisite['condition'], blocked?: (reason: string) => void): Promise<DelegationResult['outputs'][number] | null>;
|
|
10
11
|
validateInputs(parent: WorkflowInstanceView, references: readonly DelegationRevisionReference[]): Promise<void>;
|
|
11
12
|
registerChild(grant: {
|
|
12
13
|
readonly delegationId: string;
|