@atolis-hq/wake 0.4.122 → 0.4.124
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/surface-cli-applications.js +13 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/integrations/application/delegation-output-review.d.ts +14 -0
- package/dist/src/integrations/application/delegation-output-review.js +22 -0
- package/dist/src/integrations/application/delegation-outputs.d.ts +2 -0
- package/dist/src/integrations/application/delegation-outputs.js +19 -12
- package/dist/src/integrations/github/application/inbound-watch-gate-signals.js +7 -1
- package/dist/src/orchestration/application/delegation-review-policy.d.ts +8 -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-readiness.js +2 -2
- 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/dist/src/surfaces/cli/commands/sandbox-setup.d.ts +2 -0
- package/dist/src/surfaces/cli/commands/sandbox-setup.js +2 -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();
|
|
@@ -1020,6 +1020,19 @@ function createSandboxSetupDependencies(home) {
|
|
|
1020
1020
|
if ((await isReadable(sourceAuth)) && !(await isReadable(targetAuth)))
|
|
1021
1021
|
await copyFile(sourceAuth, targetAuth);
|
|
1022
1022
|
},
|
|
1023
|
+
configureGitIdentity: async () => {
|
|
1024
|
+
const { stdout } = await execFile('gh', ['api', 'user', '--jq', '[.login, .id] | @tsv']);
|
|
1025
|
+
const [login, id] = stdout.trim().split('\t');
|
|
1026
|
+
if (!login || !id || !/^\d+$/.test(id))
|
|
1027
|
+
throw new Error('Could not resolve the GitHub account for the git identity');
|
|
1028
|
+
await execFile('git', ['config', '--global', 'user.name', login]);
|
|
1029
|
+
await execFile('git', [
|
|
1030
|
+
'config',
|
|
1031
|
+
'--global',
|
|
1032
|
+
'user.email',
|
|
1033
|
+
`${id}+${login}@users.noreply.github.com`,
|
|
1034
|
+
]);
|
|
1035
|
+
},
|
|
1023
1036
|
log: (message) => process.stdout.write(`${message}\n`),
|
|
1024
1037
|
};
|
|
1025
1038
|
}
|
|
@@ -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.124";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RunView } from '../../execution/index.js';
|
|
2
|
+
import type { WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
|
+
export type DelegationReviewPolicy = (child: WorkflowInstanceView) => Promise<{
|
|
4
|
+
readonly requireApproval: boolean;
|
|
5
|
+
readonly review?: WorkflowInstanceView | undefined;
|
|
6
|
+
}>;
|
|
7
|
+
/** A watch verdict is usable only with an accepted review Run's exact checkout attestation. */
|
|
8
|
+
export declare function deliveryReadyRequirements(input: {
|
|
9
|
+
readonly reviewPolicy?: DelegationReviewPolicy;
|
|
10
|
+
readonly runs: () => Promise<readonly RunView[]>;
|
|
11
|
+
}, child: WorkflowInstanceView, revision: string): Promise<{
|
|
12
|
+
requireReview: boolean;
|
|
13
|
+
requireChecks: boolean;
|
|
14
|
+
} | null>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ActivityOutcomeKind } 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 && !(await reviewedHead(input.runs, child, policy.review, revision)))
|
|
7
|
+
return null;
|
|
8
|
+
return { requireReview: policy.requireApproval, requireChecks: true };
|
|
9
|
+
}
|
|
10
|
+
async function reviewedHead(runs, child, review, revision) {
|
|
11
|
+
if (review === undefined || review.parentWorkflowInstanceId !== child.workflowInstanceId)
|
|
12
|
+
return false;
|
|
13
|
+
const reviewed = (await runs())
|
|
14
|
+
.filter((run) => run.workflowInstanceId === review.workflowInstanceId &&
|
|
15
|
+
review.acceptedOutcomes.includes(run.activationId) &&
|
|
16
|
+
run.workspace?.mode === WorkspaceMode.ReadOnly)
|
|
17
|
+
.at(-1);
|
|
18
|
+
return (reviewed !== undefined &&
|
|
19
|
+
reviewed.status === RunStatus.Succeeded &&
|
|
20
|
+
reviewed.outcome?.kind === ActivityOutcomeKind.Done &&
|
|
21
|
+
reviewed.workspaceRevision === revision);
|
|
22
|
+
}
|
|
@@ -3,7 +3,9 @@ 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 reviewPolicy?: DelegationReviewPolicy;
|
|
7
9
|
readonly artifacts: DelegationArtifacts;
|
|
8
10
|
readonly resources: ResourceService;
|
|
9
11
|
readonly pullRequests: PullRequestService;
|
|
@@ -4,6 +4,7 @@ import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
|
4
4
|
import { DelegationPrerequisiteCondition as Condition } from '../../orchestration/index.js';
|
|
5
5
|
import { BuiltInResourceKind, ResourceCorrelationProvenance, ResourceCorrelationRole, resourceId, } from '../../resources/index.js';
|
|
6
6
|
import { ArtifactVerificationResult } from '../contracts/artifact-vocabulary.js';
|
|
7
|
+
import { deliveryReadyRequirements, } from './delegation-output-review.js';
|
|
7
8
|
const reportsSchema = z.object({ reportedArtifacts: z.array(reportedArtifactSchema) });
|
|
8
9
|
/** Select exact provider-verified results owned by the producing child. */
|
|
9
10
|
export function createDelegationOutputs(input) {
|
|
@@ -130,10 +131,7 @@ async function qualifyingChange(input, child, output, condition) {
|
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
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)
|
|
134
|
+
if (!(await ownsOutput(input, child, id)))
|
|
137
135
|
return null;
|
|
138
136
|
const observed = await input.pullRequests.get(id);
|
|
139
137
|
if (observed === null || observed.headRevision !== revision)
|
|
@@ -142,17 +140,20 @@ async function qualifyingObservation(input, child, output, id, revision, conditi
|
|
|
142
140
|
if (observed.state !== PullRequestState.Merged)
|
|
143
141
|
return null;
|
|
144
142
|
}
|
|
145
|
-
else
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
else {
|
|
144
|
+
const requirements = condition === Condition.DeliveryReady
|
|
145
|
+
? await deliveryReadyRequirements(input, child, revision)
|
|
146
|
+
: condition === Condition.PushedChange
|
|
147
|
+
? { requireReview: false, requireChecks: false }
|
|
148
|
+
: output;
|
|
149
|
+
if (requirements === null ||
|
|
150
|
+
!(await hasOutputAuthority(input, child, { ...output, ...requirements }, id, revision)))
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
149
153
|
return observed;
|
|
150
154
|
}
|
|
151
155
|
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)
|
|
156
|
+
if (!(await ownsOutput(input, child, id)))
|
|
156
157
|
return false;
|
|
157
158
|
const options = {
|
|
158
159
|
target: { resourceId: id },
|
|
@@ -191,3 +192,9 @@ function hasSuccessfulOutcome(run) {
|
|
|
191
192
|
run.outcome.kind !== ActivityOutcomeKind.Blocked &&
|
|
192
193
|
run.outcome.kind !== ActivityOutcomeKind.Rejected);
|
|
193
194
|
}
|
|
195
|
+
async function ownsOutput(input, child, id) {
|
|
196
|
+
const owner = await input.resources.primaryCorrelation(id);
|
|
197
|
+
return (owner?.workItemId === child.workItemId &&
|
|
198
|
+
owner.role === ResourceCorrelationRole.Primary &&
|
|
199
|
+
owner.provenance === ResourceCorrelationProvenance.AgentReported);
|
|
200
|
+
}
|
|
@@ -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,8 @@
|
|
|
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
|
+
}>;
|
|
@@ -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
|
+
const requireApproval = merges.length === 0 ||
|
|
16
|
+
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 };
|
|
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');
|
|
@@ -82,8 +82,8 @@ export class PrerequisiteReadiness {
|
|
|
82
82
|
return undefined;
|
|
83
83
|
}
|
|
84
84
|
upstreamOf(child, edge) {
|
|
85
|
-
const
|
|
86
|
-
return
|
|
85
|
+
const index = child.prerequisites?.indexOf(edge) ?? -1;
|
|
86
|
+
return this.children.get(child.prerequisiteWorkItemIds?.[index] ?? '');
|
|
87
87
|
}
|
|
88
88
|
recordedUpstreamReason(upstream, edge, seen) {
|
|
89
89
|
const inherited = this.recordedReason(upstream.workItemId, seen);
|
|
@@ -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';
|
|
@@ -3,6 +3,8 @@ export interface SandboxSetupDependencies {
|
|
|
3
3
|
readonly runInteractive: (command: string, arguments_: readonly string[]) => Promise<void>;
|
|
4
4
|
readonly ensureSshKey: () => Promise<void>;
|
|
5
5
|
readonly prepareCodexHome: () => Promise<void>;
|
|
6
|
+
/** Sets the global git author from the authenticated GitHub account. */
|
|
7
|
+
readonly configureGitIdentity: () => Promise<void>;
|
|
6
8
|
readonly log: (message: string) => void;
|
|
7
9
|
}
|
|
8
10
|
/** Configures the sandbox-owned credentials and git identity interactively. */
|
|
@@ -10,6 +10,8 @@ export async function runSandboxSetup(deps) {
|
|
|
10
10
|
deps.log('Use a dedicated GitHub identity with only the repository access Wake needs when possible.');
|
|
11
11
|
await deps.runInteractive('gh', ['auth', 'login']);
|
|
12
12
|
await deps.runInteractive('gh', ['auth', 'setup-git']);
|
|
13
|
+
// Without an identity the first agent commit fails and each agent improvises its own.
|
|
14
|
+
await deps.configureGitIdentity();
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
15
17
|
deps.log('Skipping GitHub auth setup.');
|