@atolis-hq/wake 0.4.123 → 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/composition-root.js +2 -1
- package/dist/src/bootstrap/surface-api-delivery.js +1 -1
- 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 +23 -0
- package/dist/src/integrations/application/delegation-output-review.js +40 -0
- package/dist/src/integrations/application/delegation-outputs.d.ts +3 -0
- package/dist/src/integrations/application/delegation-outputs.js +32 -35
- package/dist/src/integrations/github/application/inbound-watch-gate-signals.js +7 -1
- package/dist/src/orchestration/application/delegation-review-policy.d.ts +9 -0
- package/dist/src/orchestration/application/delegation-review-policy.js +47 -0
- package/dist/src/orchestration/application/delegation-wait-graph.js +5 -1
- 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 +13 -15
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +2 -1
- package/dist/src/orchestration/contracts/events.d.ts +1 -0
- package/dist/src/orchestration/index.d.ts +1 -0
- package/dist/src/orchestration/index.js +1 -0
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { ExecutionCancellationReason, GitWorkspaceProvider, RecoveryService, Run
|
|
|
7
7
|
import { createGitHubAgentContextReader, gitHubProviderDefinition, gitHubRepositoryIdentity, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
|
|
8
8
|
import { createDelegationOutputs, createDeliveryIntegrationVerification, } from '../integrations/index.js';
|
|
9
9
|
import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
|
|
10
|
-
import { compileWorkflow, createAgentActivityClassifier, createOrchestrationService, workflowInstanceId, } from '../orchestration/index.js';
|
|
10
|
+
import { OrchestrationRepository, WorkflowDefinitionRegistry, compileWorkflow, createAgentActivityClassifier, createDelegationReviewPolicy, createOrchestrationService, workflowInstanceId, } from '../orchestration/index.js';
|
|
11
11
|
import { ResourceCorrelationProvenance, ResourceCorrelationRole, createResourceLookup, createResourceService, resourceId, } from '../resources/index.js';
|
|
12
12
|
import { createWorkService } from '../work/index.js';
|
|
13
13
|
import { createFileActivationSchedulerSerialiser } from './activation-scheduler-serialiser.js';
|
|
@@ -79,6 +79,7 @@ async function createApplicationServices(wakeRoot, options = {}) {
|
|
|
79
79
|
}),
|
|
80
80
|
repositories: createRepositoryAssignments(resources, (request) => resolveGitSource(cloneResolver, request), (id) => orchestration.repositoryAssignment(id), (id) => orchestration.repositoryAuthority(id)),
|
|
81
81
|
artifacts: createDelegationOutputs({
|
|
82
|
+
reviewPolicy: createDelegationReviewPolicy(new OrchestrationRepository(journal), new WorkflowDefinitionRegistry(journal, projections, definitions)),
|
|
82
83
|
providers: () => providerInstances.promise,
|
|
83
84
|
resources,
|
|
84
85
|
pullRequests,
|
|
@@ -4,7 +4,7 @@ import { primaryExternalRef } from './external-ref.js';
|
|
|
4
4
|
export async function presentDelivery(root, work) {
|
|
5
5
|
if (root.orchestration?.deliveryTree === undefined)
|
|
6
6
|
return {};
|
|
7
|
-
const cohorts = await root.orchestration.deliveryTree(work.workItemId);
|
|
7
|
+
const cohorts = await root.orchestration.deliveryTree(work.workItemId, { verify: true });
|
|
8
8
|
if (cohorts.length === 0 && work.delegation === undefined)
|
|
9
9
|
return {};
|
|
10
10
|
const delivery = await root.work.deliverySnapshot();
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PullRequestDenialCode } from '../../activities/index.js';
|
|
2
|
+
import { type RunView } from '../../execution/index.js';
|
|
3
|
+
import type { WorkflowInstanceView } from '../../orchestration/index.js';
|
|
4
|
+
export type DelegationReviewPolicy = (child: WorkflowInstanceView) => Promise<{
|
|
5
|
+
readonly requireApproval: boolean;
|
|
6
|
+
readonly allowTrustedReview?: boolean;
|
|
7
|
+
readonly review?: WorkflowInstanceView | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
/** A watch verdict is usable only with an accepted review Run's exact checkout attestation. */
|
|
10
|
+
export declare function deliveryReadyRequirements(input: {
|
|
11
|
+
readonly reviewPolicy?: DelegationReviewPolicy;
|
|
12
|
+
readonly blocked?: (reason: string) => void;
|
|
13
|
+
readonly runs: () => Promise<readonly RunView[]>;
|
|
14
|
+
}, child: WorkflowInstanceView, revision: string): Promise<{
|
|
15
|
+
requireReview: boolean;
|
|
16
|
+
requireChecks: boolean;
|
|
17
|
+
reviewFallbackReason: string;
|
|
18
|
+
} | {
|
|
19
|
+
requireReview: boolean;
|
|
20
|
+
requireChecks: boolean;
|
|
21
|
+
reviewFallbackReason?: never;
|
|
22
|
+
} | null>;
|
|
23
|
+
export declare function outputAuthorityReason(reason: PullRequestDenialCode, requireApproval: boolean, reviewFallbackReason?: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ActivityOutcomeKind, PullRequestDenialCode } from '../../activities/index.js';
|
|
2
|
+
import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
3
|
+
/** A watch verdict is usable only with an accepted review Run's exact checkout attestation. */
|
|
4
|
+
export async function deliveryReadyRequirements(input, child, revision) {
|
|
5
|
+
const policy = (await input.reviewPolicy?.(child)) ?? { requireApproval: true };
|
|
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
|
+
}
|
|
15
|
+
return { requireReview: policy.requireApproval, requireChecks: true };
|
|
16
|
+
}
|
|
17
|
+
async function reviewedHead(runs, child, review, revision) {
|
|
18
|
+
if (review === undefined || review.parentWorkflowInstanceId !== child.workflowInstanceId)
|
|
19
|
+
return 'No accepted review verdict';
|
|
20
|
+
const reviewed = (await runs())
|
|
21
|
+
.filter((run) => run.workflowInstanceId === review.workflowInstanceId &&
|
|
22
|
+
review.acceptedOutcomes.includes(run.activationId) &&
|
|
23
|
+
run.workspace?.mode === WorkspaceMode.ReadOnly)
|
|
24
|
+
.at(-1);
|
|
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);
|
|
40
|
+
}
|
|
@@ -3,7 +3,10 @@ import { type RunView } from '../../execution/index.js';
|
|
|
3
3
|
import type { DelegationArtifacts } from '../../orchestration/index.js';
|
|
4
4
|
import { type ResourceService } from '../../resources/index.js';
|
|
5
5
|
import type { ProviderInstance } from '../contracts/provider.js';
|
|
6
|
+
import { type DelegationReviewPolicy } from './delegation-output-review.js';
|
|
6
7
|
interface OutputDependencies {
|
|
8
|
+
readonly blocked?: (reason: string) => void;
|
|
9
|
+
readonly reviewPolicy?: DelegationReviewPolicy;
|
|
7
10
|
readonly artifacts: DelegationArtifacts;
|
|
8
11
|
readonly resources: ResourceService;
|
|
9
12
|
readonly pullRequests: PullRequestService;
|
|
@@ -1,10 +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
|
-
|
|
6
|
+
import { reportedChange } from './delegation-output-claims.js';
|
|
7
|
+
import { deliveryReadyRequirements, outputAuthorityReason, } from './delegation-output-review.js';
|
|
8
8
|
/** Select exact provider-verified results owned by the producing child. */
|
|
9
9
|
export function createDelegationOutputs(input) {
|
|
10
10
|
return {
|
|
@@ -12,14 +12,14 @@ export function createDelegationOutputs(input) {
|
|
|
12
12
|
async runActivation(runId) {
|
|
13
13
|
return (await input.runs()).find((run) => run.runId === runId)?.activationId;
|
|
14
14
|
},
|
|
15
|
-
async prerequisiteOutput(child, output, condition) {
|
|
15
|
+
async prerequisiteOutput(child, output, condition, blocked) {
|
|
16
16
|
if ('path' in output &&
|
|
17
17
|
(condition === Condition.AcceptedOutput || condition === Condition.DeliveryReady)) {
|
|
18
18
|
return (await input.artifacts.qualifyingOutputs(child, [output]))?.[0] ?? null;
|
|
19
19
|
}
|
|
20
20
|
if (!('kind' in output))
|
|
21
21
|
return null;
|
|
22
|
-
return qualifyingChange(input, child, output, condition);
|
|
22
|
+
return qualifyingChange(blocked === undefined ? input : { ...input, blocked }, child, output, condition);
|
|
23
23
|
},
|
|
24
24
|
async qualifyingOutputs(child, outputs) {
|
|
25
25
|
const references = [];
|
|
@@ -49,23 +49,6 @@ export function createDelegationOutputs(input) {
|
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
/** Latest run's claim for a name; identical repeats collapse, conflicting repeats yield no claim. */
|
|
53
|
-
function reportedChange(runs, name) {
|
|
54
|
-
const claims = runs.flatMap((run) => {
|
|
55
|
-
const data = reportsSchema.safeParse(run.outcome?.data);
|
|
56
|
-
const reports = data.success
|
|
57
|
-
? data.data.reportedArtifacts.filter((entry) => entry.name === name && entry.kind === BuiltInResourceKind.PullRequest)
|
|
58
|
-
: [];
|
|
59
|
-
return reports.length === 0 ? [] : [{ run, reports }];
|
|
60
|
-
});
|
|
61
|
-
const latest = claims.at(-1);
|
|
62
|
-
const report = latest?.reports[0];
|
|
63
|
-
if (latest === undefined || report === undefined)
|
|
64
|
-
return undefined;
|
|
65
|
-
const conflicting = latest.reports.some((entry) => entry.externalKey.adapter !== report.externalKey.adapter ||
|
|
66
|
-
entry.externalKey.key !== report.externalKey.key);
|
|
67
|
-
return conflicting ? undefined : { run: latest.run, report };
|
|
68
|
-
}
|
|
69
52
|
async function verifiedChange(input, report, source) {
|
|
70
53
|
const { assignment, branch, revision } = source;
|
|
71
54
|
const repository = await input.resources.get(resourceId(assignment.resourceId));
|
|
@@ -130,10 +113,7 @@ async function qualifyingChange(input, child, output, condition) {
|
|
|
130
113
|
};
|
|
131
114
|
}
|
|
132
115
|
async function qualifyingObservation(input, child, output, id, revision, condition) {
|
|
133
|
-
|
|
134
|
-
if (owner?.workItemId !== child.workItemId ||
|
|
135
|
-
owner.role !== ResourceCorrelationRole.Primary ||
|
|
136
|
-
owner.provenance !== ResourceCorrelationProvenance.AgentReported)
|
|
116
|
+
if (!(await ownsOutput(input, child, id)))
|
|
137
117
|
return null;
|
|
138
118
|
const observed = await input.pullRequests.get(id);
|
|
139
119
|
if (observed === null || observed.headRevision !== revision)
|
|
@@ -142,17 +122,20 @@ async function qualifyingObservation(input, child, output, id, revision, conditi
|
|
|
142
122
|
if (observed.state !== PullRequestState.Merged)
|
|
143
123
|
return null;
|
|
144
124
|
}
|
|
145
|
-
else
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
125
|
+
else {
|
|
126
|
+
const requirements = condition === Condition.DeliveryReady
|
|
127
|
+
? await deliveryReadyRequirements(input, child, revision)
|
|
128
|
+
: condition === Condition.PushedChange
|
|
129
|
+
? { requireReview: false, requireChecks: false }
|
|
130
|
+
: output;
|
|
131
|
+
if (requirements === null ||
|
|
132
|
+
!(await hasOutputAuthority(input, child, { ...output, ...requirements }, id, revision)))
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
149
135
|
return observed;
|
|
150
136
|
}
|
|
151
137
|
async function hasOutputAuthority(input, child, output, id, revision) {
|
|
152
|
-
|
|
153
|
-
if (owner?.workItemId !== child.workItemId ||
|
|
154
|
-
owner.role !== ResourceCorrelationRole.Primary ||
|
|
155
|
-
owner.provenance !== ResourceCorrelationProvenance.AgentReported)
|
|
138
|
+
if (!(await ownsOutput(input, child, id)))
|
|
156
139
|
return false;
|
|
157
140
|
const options = {
|
|
158
141
|
target: { resourceId: id },
|
|
@@ -163,8 +146,16 @@ async function hasOutputAuthority(input, child, output, id, revision) {
|
|
|
163
146
|
const authority = observed?.state === PullRequestState.Merged
|
|
164
147
|
? decidePullRequestOutputAuthority(await input.pullRequests.authorityInput(child.workItemId), options)
|
|
165
148
|
: await input.pullRequests.decideAuthority(child.workItemId, options);
|
|
166
|
-
if (!authority.allowed
|
|
149
|
+
if (!authority.allowed) {
|
|
150
|
+
input.blocked?.(outputAuthorityReason(authority.reason, options.requireAcceptedReview, output.reviewFallbackReason));
|
|
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('; '));
|
|
167
157
|
return false;
|
|
158
|
+
}
|
|
168
159
|
return true;
|
|
169
160
|
}
|
|
170
161
|
function runSource(run, name) {
|
|
@@ -191,3 +182,9 @@ function hasSuccessfulOutcome(run) {
|
|
|
191
182
|
run.outcome.kind !== ActivityOutcomeKind.Blocked &&
|
|
192
183
|
run.outcome.kind !== ActivityOutcomeKind.Rejected);
|
|
193
184
|
}
|
|
185
|
+
async function ownsOutput(input, child, id) {
|
|
186
|
+
const owner = await input.resources.primaryCorrelation(id);
|
|
187
|
+
return (owner?.workItemId === child.workItemId &&
|
|
188
|
+
owner.role === ResourceCorrelationRole.Primary &&
|
|
189
|
+
owner.provenance === ResourceCorrelationProvenance.AgentReported);
|
|
190
|
+
}
|
|
@@ -51,6 +51,7 @@ export async function applyWatchGateVerdictSignal(input) {
|
|
|
51
51
|
await orchestration.acceptSignal(verdict.parentWorkflowInstanceId, {
|
|
52
52
|
kind: WatchGateVerdictSignal,
|
|
53
53
|
outcome: verdict.outcome,
|
|
54
|
+
childWorkflowInstanceId: verdict.childWorkflowInstanceId,
|
|
54
55
|
authority: { kind: ApprovalAuthorityKind.Watch, watch: verdict.childWatchId },
|
|
55
56
|
actorId: event.event.payload.actor.id,
|
|
56
57
|
actorDecision: { authorized: true, evidenceId: event.event.eventId },
|
|
@@ -74,7 +75,12 @@ async function verifyWatchGateVerdict(input) {
|
|
|
74
75
|
const parent = workflows.find((workflow) => workflow.workflowInstanceId === child.parentWorkflowInstanceId);
|
|
75
76
|
if (!isWaitingForChildWatch(parent, childWatchId))
|
|
76
77
|
return null;
|
|
77
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
parentWorkflowInstanceId: child.parentWorkflowInstanceId,
|
|
80
|
+
childWorkflowInstanceId: child.workflowInstanceId,
|
|
81
|
+
outcome,
|
|
82
|
+
childWatchId,
|
|
83
|
+
};
|
|
78
84
|
}
|
|
79
85
|
function isWaitingForChildWatch(parent, childWatchId) {
|
|
80
86
|
return (parent?.waitingFor?.signalKind === WatchGateVerdictSignal &&
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
2
|
+
import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
3
|
+
import type { WorkflowDefinitionRegistry } from './workflow-definition-registry.js';
|
|
4
|
+
/** Read the pinned merge policy and accepted configured watch verdicts, never issue prose. */
|
|
5
|
+
export declare function createDelegationReviewPolicy(repository: OrchestrationRepository, definitions: WorkflowDefinitionRegistry): (child: WorkflowInstanceView) => Promise<{
|
|
6
|
+
requireApproval: boolean;
|
|
7
|
+
review: WorkflowInstanceView | undefined;
|
|
8
|
+
allowTrustedReview: boolean;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ActivityOutcomeKind, ActivityResourceRole, BuiltInActivityName, pullRequestMergeInputSchema, } from '../../activities/index.js';
|
|
2
|
+
import { OrchestrationEventType as Event, WatchGateVerdictSignal, } from '../contracts/events.js';
|
|
3
|
+
import { ApprovalAuthorityKind } from '../contracts/vocabulary.js';
|
|
4
|
+
/** Read the pinned merge policy and accepted configured watch verdicts, never issue prose. */
|
|
5
|
+
export function createDelegationReviewPolicy(repository, definitions) {
|
|
6
|
+
return async (child) => {
|
|
7
|
+
const definition = await definitions.resolve(child, { journalFallback: true });
|
|
8
|
+
const merges = Object.values(definition.stages)
|
|
9
|
+
.flatMap((stage) => [
|
|
10
|
+
{ use: stage.activity, with: stage.with },
|
|
11
|
+
...Object.values(stage.on).flatMap((route) => route.activities ?? []),
|
|
12
|
+
])
|
|
13
|
+
.filter((activity) => activity.use === BuiltInActivityName.PullRequestMerge)
|
|
14
|
+
.map((activity) => pullRequestMergeInputSchema.safeParse(activity.with));
|
|
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
|
+
const history = await repository.history(child.workflowInstanceId);
|
|
21
|
+
const accepted = acceptedReview(history.events);
|
|
22
|
+
const review = accepted === undefined ? undefined : ((await repository.load(accepted)).view ?? undefined);
|
|
23
|
+
return { requireApproval, review, allowTrustedReview: merges.length === 0 };
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function acceptedReview(events) {
|
|
27
|
+
let watch;
|
|
28
|
+
let accepted;
|
|
29
|
+
for (const { event } of events) {
|
|
30
|
+
if (event.eventType === Event.SignalWaitStarted &&
|
|
31
|
+
event.payload.signalKind === WatchGateVerdictSignal) {
|
|
32
|
+
watch = event.payload.from?.find((authority) => authority.kind === ApprovalAuthorityKind.Watch)?.watch;
|
|
33
|
+
accepted = undefined;
|
|
34
|
+
}
|
|
35
|
+
if (event.eventType === Event.SignalAccepted && event.payload.kind === WatchGateVerdictSignal) {
|
|
36
|
+
const signal = event.payload;
|
|
37
|
+
accepted =
|
|
38
|
+
signal.outcome === ActivityOutcomeKind.Done &&
|
|
39
|
+
signal.authority?.kind === ApprovalAuthorityKind.Watch &&
|
|
40
|
+
signal.authority.watch === watch
|
|
41
|
+
? signal.childWorkflowInstanceId
|
|
42
|
+
: undefined;
|
|
43
|
+
watch = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return accepted;
|
|
47
|
+
}
|
|
@@ -37,7 +37,11 @@ function resolveChild(candidate, child, all) {
|
|
|
37
37
|
return {
|
|
38
38
|
...child,
|
|
39
39
|
prerequisiteWorkItemIds: child.prerequisites.map((edge) => {
|
|
40
|
-
const
|
|
40
|
+
const cohorts = all.filter((entry) => entry.cohortId === (edge.cohortId ?? candidate.cohortId) &&
|
|
41
|
+
entry.children.some((target) => target.assignmentId === edge.assignmentId));
|
|
42
|
+
if (cohorts.length !== 1)
|
|
43
|
+
reject(Code.MissingTarget, 'Prerequisite cohort is missing or ambiguous within this delivery');
|
|
44
|
+
const cohort = cohorts[0];
|
|
41
45
|
const target = cohort?.children.find((entry) => entry.assignmentId === edge.assignmentId);
|
|
42
46
|
if (target === undefined)
|
|
43
47
|
reject(Code.MissingTarget, 'Prerequisite target is outside this delivery or does not exist');
|
|
@@ -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. */
|
|
@@ -82,8 +83,8 @@ export class PrerequisiteReadiness {
|
|
|
82
83
|
return undefined;
|
|
83
84
|
}
|
|
84
85
|
upstreamOf(child, edge) {
|
|
85
|
-
const
|
|
86
|
-
return
|
|
86
|
+
const index = child.prerequisites?.indexOf(edge) ?? -1;
|
|
87
|
+
return this.children.get(child.prerequisiteWorkItemIds?.[index] ?? '');
|
|
87
88
|
}
|
|
88
89
|
recordedUpstreamReason(upstream, edge, seen) {
|
|
89
90
|
const inherited = this.recordedReason(upstream.workItemId, seen);
|
|
@@ -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;
|
|
@@ -291,6 +291,7 @@ export interface SignalExpectation {
|
|
|
291
291
|
readonly resourceTransitions?: readonly CompiledResourceTransition[] | undefined;
|
|
292
292
|
}
|
|
293
293
|
export interface OrchestrationSignal {
|
|
294
|
+
readonly childWorkflowInstanceId?: WorkflowInstanceId | undefined;
|
|
294
295
|
readonly kind: SignalName;
|
|
295
296
|
readonly resourceId?: string | undefined;
|
|
296
297
|
readonly revision?: string | undefined;
|
|
@@ -43,3 +43,4 @@ export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryMainten
|
|
|
43
43
|
export type { DeliveryCandidate, DeliveryCandidateCommand, DeliveryMaintenance, DeliveryMaintenanceCommand, DeliveryQa, DeliveryQaCommand, DeliverySelection, DeliverySelectionCommand, } from './contracts/delivery.js';
|
|
44
44
|
export { delegationAttentionReplySchema, delegationSubmissionSchema, } from './contracts/delegation.js';
|
|
45
45
|
export type { DelegationAttentionBlocker, DelegationAttentionReply, DelegationAttentionRequest, DelegationCaller, DelegationInputs, DelegationPrerequisite, DelegationReservation, DelegationResult, DelegationSubmission, } from './contracts/delegation.js';
|
|
46
|
+
export { createDelegationReviewPolicy } from './application/delegation-review-policy.js';
|
|
@@ -37,3 +37,4 @@ export * from './application/work-completion-summary.js';
|
|
|
37
37
|
export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
|
|
38
38
|
export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryMaintenanceCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
|
|
39
39
|
export { delegationAttentionReplySchema, delegationSubmissionSchema, } from './contracts/delegation.js';
|
|
40
|
+
export { createDelegationReviewPolicy } from './application/delegation-review-policy.js';
|