@atolis-hq/wake 0.4.104 → 0.4.106

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.
Files changed (161) hide show
  1. package/dist/src/activities/agent/agent-activity.js +10 -0
  2. package/dist/src/activities/contracts/activity.d.ts +28 -0
  3. package/dist/src/activities/contracts/event-schema.d.ts +314 -8
  4. package/dist/src/activities/contracts/event-schema.js +20 -2
  5. package/dist/src/activities/contracts/events.d.ts +10 -0
  6. package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
  7. package/dist/src/activities/contracts/vocabulary.js +2 -0
  8. package/dist/src/activities/index.d.ts +2 -0
  9. package/dist/src/activities/index.js +2 -0
  10. package/dist/src/activities/pr/activity-support.d.ts +1 -1
  11. package/dist/src/activities/pr/activity-support.js +10 -0
  12. package/dist/src/activities/pr/application.js +8 -1
  13. package/dist/src/activities/pr/approve.d.ts +2 -1
  14. package/dist/src/activities/pr/approve.js +33 -11
  15. package/dist/src/activities/pr/check-evidence.d.ts +10 -0
  16. package/dist/src/activities/pr/check-evidence.js +16 -0
  17. package/dist/src/activities/pr/contracts.d.ts +14 -0
  18. package/dist/src/activities/pr/event-data.js +5 -1
  19. package/dist/src/activities/pr/merge.d.ts +2 -1
  20. package/dist/src/activities/pr/merge.js +54 -38
  21. package/dist/src/activities/pr/parent-scope.d.ts +65 -0
  22. package/dist/src/activities/pr/parent-scope.js +24 -0
  23. package/dist/src/activities/pr/parent-target.d.ts +45 -0
  24. package/dist/src/activities/pr/parent-target.js +59 -0
  25. package/dist/src/activities/pr/projection.js +10 -2
  26. package/dist/src/activities/pr/vocabulary.d.ts +8 -0
  27. package/dist/src/activities/pr/vocabulary.js +8 -0
  28. package/dist/src/bootstrap/activity-registry.d.ts +2 -2
  29. package/dist/src/bootstrap/activity-registry.js +3 -3
  30. package/dist/src/bootstrap/composition-root.js +11 -2
  31. package/dist/src/bootstrap/config/root-schema.d.ts +22 -0
  32. package/dist/src/bootstrap/delegation-authority.js +17 -0
  33. package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
  34. package/dist/src/bootstrap/delivery-integration.js +46 -0
  35. package/dist/src/bootstrap/surface-api-delivery.js +52 -0
  36. package/dist/src/bootstrap/version.js +1 -1
  37. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +5 -1
  38. package/dist/src/control-plane/application/advance-once-dispatch.js +12 -6
  39. package/dist/src/execution/application/candidate-workspaces.d.ts +13 -0
  40. package/dist/src/execution/application/candidate-workspaces.js +75 -0
  41. package/dist/src/execution/application/execution-service.js +37 -11
  42. package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
  43. package/dist/src/execution/application/maintenance-workspaces.js +84 -0
  44. package/dist/src/execution/application/run-lifecycle.js +2 -0
  45. package/dist/src/execution/contracts/candidate.d.ts +31 -0
  46. package/dist/src/execution/contracts/candidate.js +40 -0
  47. package/dist/src/execution/contracts/commands.d.ts +4 -0
  48. package/dist/src/execution/contracts/events.d.ts +24 -0
  49. package/dist/src/execution/contracts/events.js +4 -0
  50. package/dist/src/execution/contracts/maintenance.d.ts +36 -0
  51. package/dist/src/execution/contracts/maintenance.js +44 -0
  52. package/dist/src/execution/contracts/repository-assignment.d.ts +5 -0
  53. package/dist/src/execution/contracts/repository-assignment.js +8 -0
  54. package/dist/src/execution/contracts/views.d.ts +4 -0
  55. package/dist/src/execution/contracts/vocabulary.d.ts +5 -0
  56. package/dist/src/execution/contracts/vocabulary.js +4 -0
  57. package/dist/src/execution/contracts/workspace.d.ts +8 -0
  58. package/dist/src/execution/index.d.ts +2 -0
  59. package/dist/src/execution/index.js +2 -0
  60. package/dist/src/execution/infrastructure/workspace/git-source.d.ts +2 -2
  61. package/dist/src/execution/infrastructure/workspace/git-source.js +18 -1
  62. package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +2 -4
  63. package/dist/src/execution/infrastructure/workspace/git-workspace.js +12 -1
  64. package/dist/src/integrations/application/delegation-outputs.js +1 -1
  65. package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
  66. package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
  67. package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
  68. package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
  69. package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
  70. package/dist/src/integrations/fake/external-source.d.ts +5 -2
  71. package/dist/src/integrations/fake/external-source.js +12 -2
  72. package/dist/src/integrations/fake/inbound-translator.js +7 -2
  73. package/dist/src/integrations/fake/provider.d.ts +17 -0
  74. package/dist/src/integrations/fake/provider.js +18 -2
  75. package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
  76. package/dist/src/integrations/github/contracts/events.d.ts +3 -1
  77. package/dist/src/integrations/github/contracts/events.js +3 -1
  78. package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
  79. package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
  80. package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
  81. package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
  82. package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
  83. package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
  84. package/dist/src/integrations/github/infrastructure/client.js +4 -0
  85. package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
  86. package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
  87. package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
  88. package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
  89. package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
  90. package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
  91. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
  92. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
  93. package/dist/src/integrations/index.d.ts +1 -0
  94. package/dist/src/integrations/index.js +1 -0
  95. package/dist/src/orchestration/application/delegated-work.d.ts +5 -0
  96. package/dist/src/orchestration/application/delegated-work.js +10 -0
  97. package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
  98. package/dist/src/orchestration/application/delivery-coordinator.d.ts +348 -0
  99. package/dist/src/orchestration/application/delivery-coordinator.js +239 -0
  100. package/dist/src/orchestration/application/delivery-facts-reader.d.ts +9 -0
  101. package/dist/src/orchestration/application/delivery-facts-reader.js +47 -0
  102. package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
  103. package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
  104. package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
  105. package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
  106. package/dist/src/orchestration/application/delivery-preparation.d.ts +16 -0
  107. package/dist/src/orchestration/application/delivery-preparation.js +105 -0
  108. package/dist/src/orchestration/application/delivery-sources.d.ts +10 -0
  109. package/dist/src/orchestration/application/delivery-sources.js +41 -0
  110. package/dist/src/orchestration/application/orchestration-repository.d.ts +3 -1
  111. package/dist/src/orchestration/application/orchestration-repository.js +10 -1
  112. package/dist/src/orchestration/application/orchestration-service.d.ts +341 -2
  113. package/dist/src/orchestration/application/orchestration-service.js +86 -4
  114. package/dist/src/orchestration/contracts/config.d.ts +22 -0
  115. package/dist/src/orchestration/contracts/config.js +13 -1
  116. package/dist/src/orchestration/contracts/delegation-ports.d.ts +4 -0
  117. package/dist/src/orchestration/contracts/delegation.d.ts +13 -1
  118. package/dist/src/orchestration/contracts/delegation.js +5 -0
  119. package/dist/src/orchestration/contracts/delivery-ports.d.ts +53 -0
  120. package/dist/src/orchestration/contracts/delivery-ports.js +1 -0
  121. package/dist/src/orchestration/contracts/delivery.d.ts +310 -0
  122. package/dist/src/orchestration/contracts/delivery.js +186 -0
  123. package/dist/src/orchestration/contracts/event-decoder.js +14 -1
  124. package/dist/src/orchestration/contracts/event-factory.js +8 -0
  125. package/dist/src/orchestration/contracts/events.d.ts +10 -0
  126. package/dist/src/orchestration/contracts/events.js +4 -0
  127. package/dist/src/orchestration/contracts/views.d.ts +3 -0
  128. package/dist/src/orchestration/contracts/vocabulary.d.ts +90 -0
  129. package/dist/src/orchestration/contracts/vocabulary.js +82 -0
  130. package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
  131. package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
  132. package/dist/src/orchestration/domain/compiler.js +2 -0
  133. package/dist/src/orchestration/domain/delivery-candidate.d.ts +9 -0
  134. package/dist/src/orchestration/domain/delivery-candidate.js +105 -0
  135. package/dist/src/orchestration/domain/delivery-facts.d.ts +89 -0
  136. package/dist/src/orchestration/domain/delivery-facts.js +66 -0
  137. package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
  138. package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
  139. package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
  140. package/dist/src/orchestration/domain/delivery-integration.js +144 -0
  141. package/dist/src/orchestration/domain/delivery-qa.d.ts +33 -0
  142. package/dist/src/orchestration/domain/delivery-qa.js +97 -0
  143. package/dist/src/orchestration/domain/delivery-replacement.d.ts +9 -0
  144. package/dist/src/orchestration/domain/delivery-replacement.js +54 -0
  145. package/dist/src/orchestration/domain/delivery-selection.d.ts +17 -0
  146. package/dist/src/orchestration/domain/delivery-selection.js +132 -0
  147. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +6 -0
  148. package/dist/src/orchestration/domain/delivery-workflow-policy.js +32 -0
  149. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -13
  150. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  151. package/dist/src/orchestration/domain/workflow-instance-events.js +12 -0
  152. package/dist/src/orchestration/index.d.ts +3 -0
  153. package/dist/src/orchestration/index.js +1 -0
  154. package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
  155. package/dist/src/surfaces/api/contracts/work.d.ts +42 -0
  156. package/dist/src/surfaces/api/presenters/execution.js +1 -0
  157. package/dist/src/surfaces/mcp/delegation.js +36 -1
  158. package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
  159. package/dist/src/surfaces/web-assets/index.html +1 -1
  160. package/package.json +1 -1
  161. package/dist/src/surfaces/web-assets/assets/index-C5R-aWzH.js +0 -1192
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ import { brandedStringSchema } from '../../kernel/index.js';
3
+ import { workItemId } from '../../work/index.js';
4
+ /** The one action a parent delivery may ask of a child-owned pull request. */
5
+ export const ParentActionKind = { Approve: 'approve', Merge: 'merge-pr' };
6
+ export const parentDeliveryScopeSchema = z
7
+ .object({ delivery: z.literal('next') })
8
+ .strict();
9
+ /**
10
+ * Durable context recorded on the delivery intent. The requesting parent and the resource owner
11
+ * stay separate: the child remains the PR's primary owner and nothing is transferred.
12
+ */
13
+ export const parentActionContextSchema = z
14
+ .object({
15
+ requestingWorkItemId: brandedStringSchema(workItemId),
16
+ ownerWorkItemId: brandedStringSchema(workItemId),
17
+ output: z
18
+ .object({ childWorkItemId: brandedStringSchema(workItemId), outputName: z.string().min(1) })
19
+ .strict(),
20
+ candidateId: z.string().min(1),
21
+ selectionRevision: z.number().int().positive(),
22
+ qaId: z.string().min(1),
23
+ })
24
+ .strict();
@@ -0,0 +1,45 @@
1
+ import { type ResourceCapability } from '../../resources/index.js';
2
+ import type { ActivityInvocation } from '../contracts/activity.js';
3
+ import type { PullRequestAuthorityInput, PullRequestTarget } from './contracts.js';
4
+ import type { ParentActionAuthorizer, ParentActionDecision, ParentActionKind } from './parent-scope.js';
5
+ import { PullRequestDenialCode } from './vocabulary.js';
6
+ export type ParentTarget = {
7
+ readonly kind: 'unscoped';
8
+ } | Extract<ParentActionDecision, {
9
+ readonly kind: 'target' | 'fully-integrated' | 'denied';
10
+ }>;
11
+ /**
12
+ * Resolves the one target a parent delivery may act on. Without a port, or when the caller is
13
+ * not a validated delivery parent, the request is denied rather than falling back to the
14
+ * invoking WorkItem: a scoped input never widens into generic cross-WorkItem invocation.
15
+ */
16
+ export declare function resolveParentTarget(authorizer: ParentActionAuthorizer | undefined, invocation: Pick<ActivityInvocation, 'workflowInstanceId' | 'activationId'>, scoped: boolean, action: ParentActionKind): Promise<ParentTarget>;
17
+ /** The pull request an action applies to: the parent's scoped target, or the WorkItem's own primary. */
18
+ export declare function resolveActionResource(parentTarget: ParentTarget, authority: PullRequestAuthorityInput, invocation: Pick<ActivityInvocation, 'resources' | 'workItemId'>, target: PullRequestTarget, capability: ResourceCapability): {
19
+ readonly allowed: true;
20
+ readonly resourceId: import("../../resources/index.js").ResourceId;
21
+ } | {
22
+ readonly allowed: false;
23
+ readonly reason: typeof PullRequestDenialCode.MissingResource | typeof PullRequestDenialCode.AmbiguousResource;
24
+ readonly candidates: readonly import("./activity-support.js").CandidateAudit[];
25
+ } | {
26
+ readonly allowed: false;
27
+ readonly reason: PullRequestDenialCode;
28
+ readonly candidates: readonly [];
29
+ };
30
+ /** The reason a scoped request cannot proceed, or undefined when it is allowed or unscoped. */
31
+ export declare function scopedDenialReason(parentTarget: ParentTarget, authority: PullRequestAuthorityInput, capability: ResourceCapability): PullRequestDenialCode | undefined;
32
+ type ScopedCapability = {
33
+ readonly allowed: true;
34
+ } | {
35
+ readonly allowed: false;
36
+ readonly reason: typeof PullRequestDenialCode.MissingResource | typeof PullRequestDenialCode.StaleApproval | typeof PullRequestDenialCode.CorrelationConflict;
37
+ };
38
+ /**
39
+ * The scoped target must still be the owner's single primary pull request, carry the concrete
40
+ * capability the action needs, and sit at exactly the revision the parent decided on.
41
+ */
42
+ export declare function checkScopedTarget(authority: PullRequestAuthorityInput, target: Extract<ParentTarget, {
43
+ readonly kind: 'target';
44
+ }>, capability: ResourceCapability): ScopedCapability;
45
+ export {};
@@ -0,0 +1,59 @@
1
+ import { ResourceCorrelationRole } from '../../resources/index.js';
2
+ import { resolvePrimaryCapability } from './activity-support.js';
3
+ import { isPullRequestLikeResource } from './capability.js';
4
+ import { PullRequestDenialCode } from './vocabulary.js';
5
+ /**
6
+ * Resolves the one target a parent delivery may act on. Without a port, or when the caller is
7
+ * not a validated delivery parent, the request is denied rather than falling back to the
8
+ * invoking WorkItem: a scoped input never widens into generic cross-WorkItem invocation.
9
+ */
10
+ export async function resolveParentTarget(authorizer, invocation, scoped, action) {
11
+ if (!scoped)
12
+ return { kind: 'unscoped' };
13
+ if (authorizer === undefined)
14
+ return { kind: 'denied', reason: PullRequestDenialCode.OutsideDelivery };
15
+ return authorizer.authorize({
16
+ workflowInstanceId: invocation.workflowInstanceId,
17
+ activationId: invocation.activationId,
18
+ action,
19
+ });
20
+ }
21
+ /** The pull request an action applies to: the parent's scoped target, or the WorkItem's own primary. */
22
+ export function resolveActionResource(parentTarget, authority, invocation, target, capability) {
23
+ const denial = scopedDenialReason(parentTarget, authority, capability);
24
+ if (denial !== undefined)
25
+ return { allowed: false, reason: denial, candidates: [] };
26
+ if (parentTarget.kind === 'target')
27
+ return { allowed: true, resourceId: parentTarget.resourceId };
28
+ return resolvePrimaryCapability(invocation.resources, authority, invocation.workItemId, target, capability);
29
+ }
30
+ /** The reason a scoped request cannot proceed, or undefined when it is allowed or unscoped. */
31
+ export function scopedDenialReason(parentTarget, authority, capability) {
32
+ if (parentTarget.kind === 'denied')
33
+ return parentTarget.reason;
34
+ if (parentTarget.kind !== 'target')
35
+ return undefined;
36
+ const check = checkScopedTarget(authority, parentTarget, capability);
37
+ return check.allowed ? undefined : check.reason;
38
+ }
39
+ /**
40
+ * The scoped target must still be the owner's single primary pull request, carry the concrete
41
+ * capability the action needs, and sit at exactly the revision the parent decided on.
42
+ */
43
+ export function checkScopedTarget(authority, target, capability) {
44
+ const entry = authority.resources.find((candidate) => candidate.resource.resourceId === target.resourceId &&
45
+ isPullRequestLikeResource(candidate.resource.capabilities));
46
+ if (entry === undefined || !entry.resource.capabilities.includes(capability))
47
+ return { allowed: false, reason: PullRequestDenialCode.MissingResource };
48
+ const primary = entry.correlations.filter((correlation) => correlation.role === ResourceCorrelationRole.Primary);
49
+ if (entry.resource.primaryCorrelationConflict !== undefined ||
50
+ primary.length !== 1 ||
51
+ primary[0].workItemId !== target.context.ownerWorkItemId)
52
+ return { allowed: false, reason: PullRequestDenialCode.CorrelationConflict };
53
+ const view = authority.pullRequests.find((candidate) => candidate.resourceId === target.resourceId);
54
+ if (view === undefined)
55
+ return { allowed: false, reason: PullRequestDenialCode.MissingResource };
56
+ return view.headRevision.toLowerCase() === target.revision.toLowerCase()
57
+ ? { allowed: true }
58
+ : { allowed: false, reason: PullRequestDenialCode.StaleApproval };
59
+ }
@@ -45,6 +45,7 @@ function clearRevisionEvidence(view) {
45
45
  delete copy.acceptedReview;
46
46
  delete copy.changedFiles;
47
47
  delete copy.mergeability;
48
+ delete copy.checkEvidence;
48
49
  return copy;
49
50
  }
50
51
  function projectPullRequest(previous, data, resourceId) {
@@ -56,9 +57,16 @@ function projectPullRequest(previous, data, resourceId) {
56
57
  case ActivityEventType.PrStateChanged:
57
58
  return previous === null
58
59
  ? previous
59
- : { ...previous, state: data.payload.state, mergeability: data.payload.mergeability };
60
+ : {
61
+ ...previous,
62
+ state: data.payload.state,
63
+ mergeability: data.payload.mergeability,
64
+ mergeRevision: data.payload.mergeRevision,
65
+ };
60
66
  case ActivityEventType.PrChecksChanged:
61
- return previous === null ? previous : { ...previous, checks: data.payload.checks };
67
+ return previous === null
68
+ ? previous
69
+ : { ...previous, checks: data.payload.checks, checkEvidence: data.payload.checkEvidence };
62
70
  case ActivityEventType.PrReviewAccepted:
63
71
  return previous === null
64
72
  ? previous
@@ -37,5 +37,13 @@ export declare const PullRequestDenialCode: {
37
37
  readonly TooManyFilesChanged: "too-many-files-changed";
38
38
  readonly BlockedPathChanged: "blocked-path-changed";
39
39
  readonly ChangedFilesUnavailable: "changed-files-unavailable";
40
+ /** The caller is not a validated delivery parent, or asked beyond the one planned action. */
41
+ readonly OutsideDelivery: "outside-delivery";
42
+ /** The parent has no current candidate with an effective passing QA verdict. */
43
+ readonly DeliveryNotReady: "delivery-not-ready";
44
+ /** The target or one of its ancestors is frozen, cancelled or deleted. */
45
+ readonly TargetHeld: "target-held";
46
+ /** The next planned change needs agent maintenance and fresh evidence first. */
47
+ readonly MaintenanceRequired: "maintenance-required";
40
48
  };
41
49
  export type PullRequestDenialCode = ValueOf<typeof PullRequestDenialCode>;
@@ -33,4 +33,12 @@ export const PullRequestDenialCode = defineClosedVocabulary({
33
33
  TooManyFilesChanged: 'too-many-files-changed',
34
34
  BlockedPathChanged: 'blocked-path-changed',
35
35
  ChangedFilesUnavailable: 'changed-files-unavailable',
36
+ /** The caller is not a validated delivery parent, or asked beyond the one planned action. */
37
+ OutsideDelivery: 'outside-delivery',
38
+ /** The parent has no current candidate with an effective passing QA verdict. */
39
+ DeliveryNotReady: 'delivery-not-ready',
40
+ /** The target or one of its ancestors is frozen, cancelled or deleted. */
41
+ TargetHeld: 'target-held',
42
+ /** The next planned change needs agent maintenance and fresh evidence first. */
43
+ MaintenanceRequired: 'maintenance-required',
36
44
  });
@@ -1,4 +1,4 @@
1
1
  import type { EventJournal } from '@atolis-hq/eventing';
2
- import { ActivityRegistry, type AgentContextReader, type createPullRequestService } from '../activities/index.js';
2
+ import { ActivityRegistry, type AgentContextReader, type createPullRequestService, type ParentActionAuthorizer } from '../activities/index.js';
3
3
  import type { createResourceService } from '../resources/index.js';
4
- export declare function createBuiltInActivityRegistry(journal: EventJournal, pullRequests: ReturnType<typeof createPullRequestService>, resources: ReturnType<typeof createResourceService>, wakeRoot: string, contextReader: AgentContextReader): ActivityRegistry;
4
+ export declare function createBuiltInActivityRegistry(journal: EventJournal, pullRequests: ReturnType<typeof createPullRequestService>, resources: ReturnType<typeof createResourceService>, wakeRoot: string, contextReader: AgentContextReader, parentActions?: ParentActionAuthorizer): ActivityRegistry;
@@ -1,7 +1,7 @@
1
1
  import { ActivityRegistry, agentActivityDefinition, createAgentActivity, createIssueCompleteActivity, createPullRequestApproveActivity, createPullRequestMergeActivity, } from '../activities/index.js';
2
2
  import { loadPromptTemplate, renderPromptTemplate } from '../execution/index.js';
3
3
  import { createStatusPublishActivity } from './status-publish-activity.js';
4
- export function createBuiltInActivityRegistry(journal, pullRequests, resources, wakeRoot, contextReader) {
4
+ export function createBuiltInActivityRegistry(journal, pullRequests, resources, wakeRoot, contextReader, parentActions) {
5
5
  const activities = new ActivityRegistry();
6
6
  activities.register({
7
7
  ...agentActivityDefinition,
@@ -26,7 +26,7 @@ export function createBuiltInActivityRegistry(journal, pullRequests, resources,
26
26
  });
27
27
  activities.register(createStatusPublishActivity(journal));
28
28
  activities.register(createIssueCompleteActivity(journal, resources));
29
- activities.register(createPullRequestApproveActivity(journal, pullRequests));
30
- activities.register(createPullRequestMergeActivity(journal, pullRequests));
29
+ activities.register(createPullRequestApproveActivity(journal, pullRequests, undefined, parentActions));
30
+ activities.register(createPullRequestMergeActivity(journal, pullRequests, undefined, parentActions));
31
31
  return activities;
32
32
  }
@@ -5,7 +5,7 @@ import { DispatchPolicy, createActivationScheduler, createActivationSchedulerSub
5
5
  import { createConversationService } from '../conversations/index.js';
6
6
  import { ExecutionCancellationReason, GitWorkspaceProvider, RecoveryService, RunStatus, TranscriptStore, createExecutionService, createLocalProcessInspector, createRepositoryAssignments, createRunnerMemoryProfileDecorator, isActiveRunStatus, resolveGitSource, } from '../execution/index.js';
7
7
  import { createGitHubAgentContextReader, gitHubProviderDefinition, gitHubRepositoryIdentity, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
8
- import { createDelegationOutputs } from '../integrations/index.js';
8
+ import { createDelegationOutputs, createDeliveryIntegrationVerification, } from '../integrations/index.js';
9
9
  import { SystemClock, UlidIdGenerator } from '../kernel/index.js';
10
10
  import { compileWorkflow, createAgentActivityClassifier, createOrchestrationService, } from '../orchestration/index.js';
11
11
  import { createResourceLookup, createResourceService, resourceId, } from '../resources/index.js';
@@ -16,6 +16,7 @@ import { createArtifactMcpProvisioner } from './artifact-mcp.js';
16
16
  import { createArtifactTriggerContext } from './artifact-trigger-context.js';
17
17
  import { loadConfig } from './config/load-config.js';
18
18
  import { createDelegationAuthority } from './delegation-authority.js';
19
+ import { createDeliveryIntegration } from './delivery-integration.js';
19
20
  import { EventProcessorRuntime } from './event-processor-runtime.js';
20
21
  import { loadFakeScenarios } from './fake-scenarios.js';
21
22
  import { composeIntegrationRuntime, composeProviders } from './integration-runtime.js';
@@ -56,7 +57,9 @@ async function createApplicationServices(wakeRoot, options = {}) {
56
57
  createBuiltInActivityRegistry(journal, pullRequests, resources, wakeRoot, createGitHubAgentContextReader(journal, resources, {
57
58
  publicUiUrl: config.surfaces.web.publicUrl,
58
59
  githubAdapters: githubAdapters(config),
59
- }, conversations));
60
+ }, conversations),
61
+ // Resolved lazily: Orchestration is composed after the registry it compiles against.
62
+ { authorize: (request) => orchestration.authorizeParentAction(request) });
60
63
  const workflowNotices = [];
61
64
  const definitions = Object.fromEntries(Object.entries(config.orchestration.workflows).map(([name, definition]) => [
62
65
  name,
@@ -84,6 +87,12 @@ async function createApplicationServices(wakeRoot, options = {}) {
84
87
  accepted: queries.isActivationAccepted,
85
88
  }),
86
89
  }),
90
+ integration: createDeliveryIntegration(pullRequests, () => execution.list(), createDeliveryIntegrationVerification({
91
+ runs: () => execution.list(),
92
+ resources,
93
+ pullRequests,
94
+ providers: () => providerInstances.promise,
95
+ })),
87
96
  runHasEnded: async (runId) => {
88
97
  const run = (await execution.list()).find((entry) => entry.runId === runId);
89
98
  return (run !== undefined &&
@@ -16,6 +16,17 @@ declare const orchestrationConfigSchema: z.ZodDefault<z.ZodObject<{
16
16
  maxDepth: z.ZodNumber;
17
17
  maxDescendants: z.ZodNumber;
18
18
  maxConcurrentRuns: z.ZodNumber;
19
+ completion: z.ZodOptional<z.ZodEnum<{
20
+ readonly QaApproved: "qa-approved";
21
+ readonly MergeRequired: "merge-required";
22
+ }>>;
23
+ qa: z.ZodOptional<z.ZodObject<{
24
+ stage: z.ZodString;
25
+ recipe: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strict>>;
27
+ maintenance: z.ZodOptional<z.ZodObject<{
28
+ stage: z.ZodString;
29
+ }, z.core.$strict>>;
19
30
  }, z.core.$strict>>;
20
31
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
21
32
  activity: z.ZodString;
@@ -184,6 +195,17 @@ export declare const rootConfigSchema: z.ZodObject<{
184
195
  maxDepth: z.ZodNumber;
185
196
  maxDescendants: z.ZodNumber;
186
197
  maxConcurrentRuns: z.ZodNumber;
198
+ completion: z.ZodOptional<z.ZodEnum<{
199
+ readonly QaApproved: "qa-approved";
200
+ readonly MergeRequired: "merge-required";
201
+ }>>;
202
+ qa: z.ZodOptional<z.ZodObject<{
203
+ stage: z.ZodString;
204
+ recipe: z.ZodOptional<z.ZodString>;
205
+ }, z.core.$strict>>;
206
+ maintenance: z.ZodOptional<z.ZodObject<{
207
+ stage: z.ZodString;
208
+ }, z.core.$strict>>;
187
209
  }, z.core.$strict>>;
188
210
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
189
211
  activity: z.ZodString;
@@ -24,6 +24,23 @@ export function createDelegationAuthority(journal, resources, activities, bindin
24
24
  activities.describe(run.activity).executionKind !== ActivityExecutionKind.Agent)
25
25
  throw new Error('Delegation capability is stale or does not own the parent activation');
26
26
  },
27
+ async assertQaCaller(caller, candidateId, selectionRevision, revisions) {
28
+ const run = (await runs.load(runId(caller.runId))).view;
29
+ const prepared = run?.workspace?.candidate;
30
+ const key = (entries) => entries
31
+ .map((entry) => entry.resourceId + '@' + entry.revision.toLowerCase())
32
+ .sort()
33
+ .join(',');
34
+ if (run === null ||
35
+ !isActiveRunStatus(run.status) ||
36
+ run.cancellation !== undefined ||
37
+ run.activationId !== caller.activationId ||
38
+ run.workflowInstanceId !== caller.workflowInstanceId ||
39
+ prepared?.candidateId !== candidateId ||
40
+ prepared.selectionRevision !== selectionRevision ||
41
+ key(prepared.repositories) !== key(revisions))
42
+ throw new Error('QA verdict requires the Run prepared for this exact candidate');
43
+ },
27
44
  repositories: (parent) => repositories(parent.workItemId),
28
45
  // The scope is the repository the provider observed the root Issue in, never an agent claim.
29
46
  // Any Repository Resource already correlated to the root (for example operator-declared)
@@ -0,0 +1,9 @@
1
+ import type { createPullRequestService } from '../activities/index.js';
2
+ import { type RunView } from '../execution/index.js';
3
+ import type { DeliveryIntegrationVerification } from '../integrations/index.js';
4
+ import { type DeliveryIntegration } from '../orchestration/index.js';
5
+ /**
6
+ * Binds delivery integration to provider-observed pull request facts and to durable Run
7
+ * identity. An agent's claim about what it leased or pushed is never enough on its own.
8
+ */
9
+ export declare function createDeliveryIntegration(pullRequests: ReturnType<typeof createPullRequestService>, runs: () => Promise<readonly RunView[]>, verification: DeliveryIntegrationVerification): DeliveryIntegration;
@@ -0,0 +1,46 @@
1
+ import { isActiveRunStatus, RunStatus, WorkspaceMode } from '../execution/index.js';
2
+ import { DeliveryRejection, DeliveryRejectionError, } from '../orchestration/index.js';
3
+ import { resourceId } from '../resources/index.js';
4
+ /**
5
+ * Binds delivery integration to provider-observed pull request facts and to durable Run
6
+ * identity. An agent's claim about what it leased or pushed is never enough on its own.
7
+ */
8
+ export function createDeliveryIntegration(pullRequests, runs, verification) {
9
+ return {
10
+ verifyTarget: verification.verifyTarget,
11
+ async observe(id) {
12
+ const view = await pullRequests.get(resourceId(id));
13
+ return view === null
14
+ ? null
15
+ : {
16
+ state: view.state,
17
+ headRevision: view.headRevision,
18
+ baseRevision: view.baseRevision,
19
+ mergeRevision: view.mergeRevision,
20
+ mergeability: view.mergeability,
21
+ };
22
+ },
23
+ async assertMaintenanceWriter(request) {
24
+ const all = await runs();
25
+ const run = all.find((entry) => entry.runId === request.runId);
26
+ const leased = run?.workspace?.maintenance?.targets.some((target) => target.childWorkItemId === request.childWorkItemId &&
27
+ target.resourceId === request.resourceId &&
28
+ target.revision.toLowerCase() === request.revision.toLowerCase());
29
+ if (run === undefined ||
30
+ !isActiveRunStatus(run.status) ||
31
+ run.cancellation !== undefined ||
32
+ run.activationId !== request.activationId ||
33
+ run.workflowInstanceId !== request.workflowInstanceId ||
34
+ leased !== true)
35
+ throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, 'Maintenance must be reported by the Run that Wake prepared with this target branch lease');
36
+ // An earlier writer whose outcome is unknown may have pushed; it must be reconciled first.
37
+ const unresolved = all.find((entry) => entry.runId !== request.runId &&
38
+ entry.status === RunStatus.Ambiguous &&
39
+ ((entry.workspace?.branch === request.childWorkItemId &&
40
+ entry.workspace?.mode === WorkspaceMode.Branch) ||
41
+ entry.workspace?.maintenance?.targets.some((target) => target.childWorkItemId === request.childWorkItemId) === true));
42
+ if (unresolved !== undefined)
43
+ throw new DeliveryRejectionError(DeliveryRejection.AmbiguousWriter, `Run ${unresolved.runId} may have written to ${request.childWorkItemId}; reconcile it before recording maintenance`);
44
+ },
45
+ };
46
+ }
@@ -6,8 +6,10 @@ export async function presentDelivery(root, work) {
6
6
  if (cohorts.length === 0 && work.delegation === undefined)
7
7
  return {};
8
8
  const delivery = await root.work.deliverySnapshot();
9
+ const qa = await deliveryQaFor(root, work);
9
10
  return {
10
11
  delegation: {
12
+ ...(qa === undefined ? {} : { qa }),
11
13
  rootWorkItemKey: toWorkItemKey(work.delegation?.rootWorkItemId ?? work.workItemId),
12
14
  ...(work.delegation === undefined
13
15
  ? {}
@@ -37,3 +39,53 @@ export async function presentDelivery(root, work) {
37
39
  },
38
40
  };
39
41
  }
42
+ async function deliveryQaFor(root, work) {
43
+ const parent = (await root.orchestration.listAll()).find((view) => view.workItemId === work.workItemId && view.parentWorkflowInstanceId === undefined);
44
+ const state = parent === undefined
45
+ ? undefined
46
+ : await root.orchestration.deliveryStateFor(parent.workflowInstanceId);
47
+ return state === undefined
48
+ ? undefined
49
+ : {
50
+ ...(state.integration === null
51
+ ? {}
52
+ : {
53
+ integration: {
54
+ complete: state.integration.complete,
55
+ summary: state.integration.summary,
56
+ targets: state.integration.targets.map((target) => ({
57
+ workItemKey: toWorkItemKey(target.ownerWorkItemId),
58
+ outputName: target.output.outputName,
59
+ state: target.state,
60
+ layer: target.layer,
61
+ baseMovement: target.baseMovement,
62
+ evidenceAffected: target.evidenceAffected,
63
+ ...(target.maintenance === undefined ? {} : { maintenance: target.maintenance }),
64
+ ...(target.detail === undefined ? {} : { detail: target.detail }),
65
+ })),
66
+ maintenance: state.maintenance.map((item) => ({
67
+ maintenanceId: item.maintenanceId,
68
+ workItemKey: toWorkItemKey(item.target.childWorkItemId),
69
+ outputName: item.target.outputName,
70
+ kind: item.kind,
71
+ previousRevision: item.previous.revision,
72
+ currentRevision: item.current.revision,
73
+ producerRunId: item.producer.runId,
74
+ })),
75
+ },
76
+ }),
77
+ selectionRevision: state.selectionRevision,
78
+ ...(state.candidate === null ? {} : { candidateId: state.candidate.candidateId }),
79
+ repositories: state.candidate?.repositories.map((entry) => ({
80
+ resourceId: entry.resourceId,
81
+ revision: entry.revision,
82
+ })) ?? [],
83
+ stale: state.stale,
84
+ ...(state.qa === null ? {} : { verdict: state.qa.verdict }),
85
+ effective: state.qaEffective,
86
+ canComplete: state.completion.complete,
87
+ ...(state.completion.reason === undefined ? {} : { reason: state.completion.reason }),
88
+ exhausted: state.repair.exhausted,
89
+ findings: state.repair.unresolvedFindings,
90
+ };
91
+ }
@@ -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.104";
127
+ export const wakeVersion = "v0.4.106";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -1,5 +1,5 @@
1
1
  import type { CommandContext } from '@atolis-hq/eventing';
2
- import type { ExecutionFailureCode, RepositoryAssignment, RunView, WorkspaceRecovery } from '../../execution/index.js';
2
+ import type { ExecutionCandidate, ExecutionFailureCode, ExecutionMaintenance, RepositoryAssignment, RunView, WorkspaceRecovery } from '../../execution/index.js';
3
3
  import type { IdGenerator } from '../../kernel/index.js';
4
4
  import type { ActivityActivationView, PendingActivationPriority, WorkflowInstanceView } from '../../orchestration/index.js';
5
5
  import type { ResourceService } from '../../resources/index.js';
@@ -13,6 +13,8 @@ export interface OrchestrationPort {
13
13
  priority?: PendingActivationPriority;
14
14
  }[]>;
15
15
  listWaiting(): Promise<readonly (WorkflowInstanceView | null)[]>;
16
+ deliveryQaPreparation?(workflowInstanceId: string): Promise<ExecutionCandidate | undefined>;
17
+ deliveryMaintenancePreparation?(workflowInstanceId: string): Promise<ExecutionMaintenance | undefined>;
16
18
  repositoryAssignment?(workItemId: string): Promise<RepositoryAssignment | undefined>;
17
19
  get?(workflowInstanceId: string): Promise<WorkflowInstanceView | null>;
18
20
  expireTimedOutWaits?(context: CommandContext): Promise<readonly WorkflowInstanceView[]>;
@@ -46,6 +48,8 @@ export interface ExecutionPort {
46
48
  workflowInstanceId: WorkflowInstanceView['workflowInstanceId'];
47
49
  orchestrationGroupId: WorkflowInstanceView['orchestrationGroupId'];
48
50
  repositoryAssignment?: RepositoryAssignment;
51
+ candidate?: ExecutionCandidate;
52
+ maintenance?: ExecutionMaintenance;
49
53
  resources: readonly NonNullable<Awaited<ReturnType<ResourceService['get']>>>[];
50
54
  ineligibleRunners?: ReadonlySet<string>;
51
55
  sessionPolicy?: 'fresh' | 'resume-stage';
@@ -91,15 +91,22 @@ export async function runDispatchLoop(pending, ctx) {
91
91
  }
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
- const repositoryAssignment = await ctx.orchestration.repositoryAssignment?.(selected.workflow.workItemId);
95
- const resourceViews = await dispatchResources(ctx.resources, selected.workflow.workItemId, repositoryAssignment);
94
+ const { workItemId } = selected.workflow;
95
+ const repositoryAssignment = await ctx.orchestration.repositoryAssignment?.(workItemId);
96
+ const resourceViews = await dispatchResources(ctx.resources, workItemId, repositoryAssignment);
97
+ const instanceId = selected.workflow.workflowInstanceId;
98
+ const candidate = await ctx.orchestration.deliveryQaPreparation?.(instanceId);
99
+ const maintenance = await ctx.orchestration.deliveryMaintenancePreparation?.(instanceId);
96
100
  const run = await ctx.execution.attempt(selected.activation, {
97
- workItemId: selected.workflow.workItemId,
98
- workflowInstanceId: selected.workflow.workflowInstanceId,
101
+ workItemId,
102
+ workflowInstanceId: instanceId,
99
103
  orchestrationGroupId: selected.workflow.orchestrationGroupId,
100
104
  resources: resourceViews,
105
+ ...(candidate === undefined ? {} : { candidate }),
106
+ ...(maintenance === undefined ? {} : { maintenance }),
101
107
  ...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
102
- sessionPolicy: selected.activation.sessionPolicy === 'fresh' ||
108
+ sessionPolicy: (candidate ?? maintenance) !== undefined ||
109
+ selected.activation.sessionPolicy === 'fresh' ||
103
110
  selected.workflow.parentWorkflowInstanceId !== undefined
104
111
  ? 'fresh'
105
112
  : 'resume-stage',
@@ -175,7 +182,6 @@ export async function runDispatchLoop(pending, ctx) {
175
182
  workflowInstanceId: selected.workflow.workflowInstanceId,
176
183
  reason,
177
184
  };
178
- continue;
179
185
  }
180
186
  }
181
187
  return dispatched.length > 0
@@ -0,0 +1,13 @@
1
+ import { type ResourceView } from '../../resources/index.js';
2
+ import type { WorkItemId } from '../../work/index.js';
3
+ import { type ExecutionCandidate } from '../contracts/candidate.js';
4
+ import type { RunId } from '../contracts/identifiers.js';
5
+ import type { WorkspaceLease, WorkspaceProvider } from '../contracts/workspace.js';
6
+ /** A candidate is acquired as a unit; partial preparation never reaches a runner. */
7
+ export declare function acquireCandidateWorkspaces(request: {
8
+ readonly runId: RunId;
9
+ readonly workItemId: WorkItemId;
10
+ readonly candidate: ExecutionCandidate;
11
+ readonly resources: readonly ResourceView[];
12
+ readonly signal: AbortSignal;
13
+ }, provider: WorkspaceProvider | undefined): Promise<WorkspaceLease>;
@@ -0,0 +1,75 @@
1
+ import { BuiltInResourceKind } from '../../resources/index.js';
2
+ import { executionCandidateSchema } from '../contracts/candidate.js';
3
+ import { WorkspaceMode } from '../contracts/vocabulary.js';
4
+ /** A candidate is acquired as a unit; partial preparation never reaches a runner. */
5
+ export async function acquireCandidateWorkspaces(request, provider) {
6
+ if (provider === undefined)
7
+ throw new Error('Candidate QA needs a workspace provider');
8
+ const candidate = executionCandidateSchema.parse(request.candidate);
9
+ const assignments = [...candidate.repositories].sort((a, b) => a.resourceId < b.resourceId ? -1 : a.resourceId === b.resourceId ? 0 : 1);
10
+ if (new Set(assignments.map((entry) => entry.resourceId)).size !== assignments.length)
11
+ throw new Error('Duplicate candidate repository');
12
+ const leases = [];
13
+ try {
14
+ for (const assignment of assignments) {
15
+ request.signal.throwIfAborted();
16
+ const resource = request.resources.find((entry) => entry.resourceId === assignment.resourceId &&
17
+ entry.kind === BuiltInResourceKind.Repository);
18
+ if (resource === undefined)
19
+ throw new Error('Candidate repository is unavailable');
20
+ const { requiredSourceRef, ...repository } = assignment;
21
+ const lease = await provider.acquire({
22
+ runId: request.runId,
23
+ workItemId: request.workItemId,
24
+ signal: request.signal,
25
+ mode: WorkspaceMode.ReadOnly,
26
+ repositoryResource: resource,
27
+ assignment: repository,
28
+ checkoutRevision: assignment.sourceRevision,
29
+ ...(requiredSourceRef === undefined ? {} : { requiredSourceRef }),
30
+ });
31
+ leases.push(lease);
32
+ const revision = (await lease.readRevision?.()) ?? lease.checkoutRevision;
33
+ if (revision !== assignment.sourceRevision)
34
+ throw new Error('Prepared candidate checkout differs from its exact revision');
35
+ }
36
+ const first = leases[0];
37
+ return {
38
+ ...first,
39
+ candidate: {
40
+ candidateId: candidate.candidateId,
41
+ selectionRevision: candidate.selectionRevision,
42
+ repositories: assignments.map((entry, index) => ({
43
+ resourceId: entry.resourceId,
44
+ revision: entry.sourceRevision,
45
+ path: leases[index].path,
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], 'Candidate preparation and cleanup failed', {
57
+ cause: cleanup,
58
+ });
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+ async function releaseAll(leases) {
64
+ const failures = [];
65
+ for (const lease of [...leases].reverse()) {
66
+ try {
67
+ await lease.release();
68
+ }
69
+ catch (error) {
70
+ failures.push(error);
71
+ }
72
+ }
73
+ if (failures.length > 0)
74
+ throw new AggregateError(failures, 'Candidate lease cleanup failed');
75
+ }