@atolis-hq/wake 0.4.105 → 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 (128) hide show
  1. package/dist/src/activities/agent/agent-activity.js +7 -0
  2. package/dist/src/activities/contracts/activity.d.ts +12 -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 +6 -0
  32. package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
  33. package/dist/src/bootstrap/delivery-integration.js +46 -0
  34. package/dist/src/bootstrap/surface-api-delivery.js +27 -0
  35. package/dist/src/bootstrap/version.js +1 -1
  36. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  37. package/dist/src/control-plane/application/advance-once-dispatch.js +10 -6
  38. package/dist/src/execution/application/execution-service.js +10 -0
  39. package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
  40. package/dist/src/execution/application/maintenance-workspaces.js +84 -0
  41. package/dist/src/execution/application/run-lifecycle.js +1 -0
  42. package/dist/src/execution/contracts/commands.d.ts +2 -0
  43. package/dist/src/execution/contracts/events.d.ts +13 -0
  44. package/dist/src/execution/contracts/events.js +2 -0
  45. package/dist/src/execution/contracts/maintenance.d.ts +36 -0
  46. package/dist/src/execution/contracts/maintenance.js +44 -0
  47. package/dist/src/execution/contracts/views.d.ts +2 -0
  48. package/dist/src/execution/contracts/workspace.d.ts +2 -0
  49. package/dist/src/execution/index.d.ts +1 -0
  50. package/dist/src/execution/index.js +1 -0
  51. package/dist/src/integrations/application/delegation-outputs.js +1 -1
  52. package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
  53. package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
  54. package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
  55. package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
  56. package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
  57. package/dist/src/integrations/fake/external-source.d.ts +5 -2
  58. package/dist/src/integrations/fake/external-source.js +12 -2
  59. package/dist/src/integrations/fake/inbound-translator.js +7 -2
  60. package/dist/src/integrations/fake/provider.d.ts +17 -0
  61. package/dist/src/integrations/fake/provider.js +18 -2
  62. package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
  63. package/dist/src/integrations/github/contracts/events.d.ts +3 -1
  64. package/dist/src/integrations/github/contracts/events.js +3 -1
  65. package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
  66. package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
  67. package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
  68. package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
  69. package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
  70. package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
  71. package/dist/src/integrations/github/infrastructure/client.js +4 -0
  72. package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
  73. package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
  74. package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
  75. package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
  76. package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
  77. package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
  78. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
  79. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
  80. package/dist/src/integrations/index.d.ts +1 -0
  81. package/dist/src/integrations/index.js +1 -0
  82. package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
  83. package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
  84. package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
  85. package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
  86. package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
  87. package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
  88. package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
  89. package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
  90. package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
  91. package/dist/src/orchestration/application/delivery-preparation.js +7 -2
  92. package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
  93. package/dist/src/orchestration/application/orchestration-service.js +55 -2
  94. package/dist/src/orchestration/contracts/config.d.ts +6 -0
  95. package/dist/src/orchestration/contracts/config.js +6 -0
  96. package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
  97. package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
  98. package/dist/src/orchestration/contracts/delivery.js +53 -1
  99. package/dist/src/orchestration/contracts/event-decoder.js +2 -1
  100. package/dist/src/orchestration/contracts/event-factory.js +2 -0
  101. package/dist/src/orchestration/contracts/events.d.ts +3 -1
  102. package/dist/src/orchestration/contracts/events.js +1 -0
  103. package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
  104. package/dist/src/orchestration/contracts/vocabulary.js +40 -1
  105. package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
  106. package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
  107. package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
  108. package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
  109. package/dist/src/orchestration/domain/delivery-facts.js +33 -1
  110. package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
  111. package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
  112. package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
  113. package/dist/src/orchestration/domain/delivery-integration.js +144 -0
  114. package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
  115. package/dist/src/orchestration/domain/delivery-qa.js +24 -4
  116. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
  117. package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
  118. package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
  119. package/dist/src/orchestration/index.d.ts +3 -2
  120. package/dist/src/orchestration/index.js +1 -1
  121. package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
  122. package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
  123. package/dist/src/surfaces/api/presenters/execution.js +1 -0
  124. package/dist/src/surfaces/mcp/delegation.js +5 -1
  125. package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
  126. package/dist/src/surfaces/web-assets/index.html +1 -1
  127. package/package.json +1 -1
  128. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.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 &&
@@ -24,6 +24,9 @@ declare const orchestrationConfigSchema: z.ZodDefault<z.ZodObject<{
24
24
  stage: z.ZodString;
25
25
  recipe: z.ZodOptional<z.ZodString>;
26
26
  }, z.core.$strict>>;
27
+ maintenance: z.ZodOptional<z.ZodObject<{
28
+ stage: z.ZodString;
29
+ }, z.core.$strict>>;
27
30
  }, z.core.$strict>>;
28
31
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
29
32
  activity: z.ZodString;
@@ -200,6 +203,9 @@ export declare const rootConfigSchema: z.ZodObject<{
200
203
  stage: z.ZodString;
201
204
  recipe: z.ZodOptional<z.ZodString>;
202
205
  }, z.core.$strict>>;
206
+ maintenance: z.ZodOptional<z.ZodObject<{
207
+ stage: z.ZodString;
208
+ }, z.core.$strict>>;
203
209
  }, z.core.$strict>>;
204
210
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
205
211
  activity: z.ZodString;
@@ -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
+ }
@@ -47,6 +47,33 @@ async function deliveryQaFor(root, work) {
47
47
  return state === undefined
48
48
  ? undefined
49
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
+ }),
50
77
  selectionRevision: state.selectionRevision,
51
78
  ...(state.candidate === null ? {} : { candidateId: state.candidate.candidateId }),
52
79
  repositories: state.candidate?.repositories.map((entry) => ({
@@ -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.105";
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 { ExecutionCandidate, 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';
@@ -14,6 +14,7 @@ export interface OrchestrationPort {
14
14
  }[]>;
15
15
  listWaiting(): Promise<readonly (WorkflowInstanceView | null)[]>;
16
16
  deliveryQaPreparation?(workflowInstanceId: string): Promise<ExecutionCandidate | undefined>;
17
+ deliveryMaintenancePreparation?(workflowInstanceId: string): Promise<ExecutionMaintenance | undefined>;
17
18
  repositoryAssignment?(workItemId: string): Promise<RepositoryAssignment | undefined>;
18
19
  get?(workflowInstanceId: string): Promise<WorkflowInstanceView | null>;
19
20
  expireTimedOutWaits?(context: CommandContext): Promise<readonly WorkflowInstanceView[]>;
@@ -48,6 +49,7 @@ export interface ExecutionPort {
48
49
  orchestrationGroupId: WorkflowInstanceView['orchestrationGroupId'];
49
50
  repositoryAssignment?: RepositoryAssignment;
50
51
  candidate?: ExecutionCandidate;
52
+ maintenance?: ExecutionMaintenance;
51
53
  resources: readonly NonNullable<Awaited<ReturnType<ResourceService['get']>>>[];
52
54
  ineligibleRunners?: ReadonlySet<string>;
53
55
  sessionPolicy?: 'fresh' | 'resume-stage';
@@ -91,17 +91,21 @@ 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);
96
- const candidate = await ctx.orchestration.deliveryQaPreparation?.(selected.workflow.workflowInstanceId);
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);
97
100
  const run = await ctx.execution.attempt(selected.activation, {
98
- workItemId: selected.workflow.workItemId,
99
- workflowInstanceId: selected.workflow.workflowInstanceId,
101
+ workItemId,
102
+ workflowInstanceId: instanceId,
100
103
  orchestrationGroupId: selected.workflow.orchestrationGroupId,
101
104
  resources: resourceViews,
102
105
  ...(candidate === undefined ? {} : { candidate }),
106
+ ...(maintenance === undefined ? {} : { maintenance }),
103
107
  ...(repositoryAssignment === undefined ? {} : { repositoryAssignment }),
104
- sessionPolicy: candidate !== undefined ||
108
+ sessionPolicy: (candidate ?? maintenance) !== undefined ||
105
109
  selected.activation.sessionPolicy === 'fresh' ||
106
110
  selected.workflow.parentWorkflowInstanceId !== undefined
107
111
  ? 'fresh'
@@ -1,4 +1,5 @@
1
1
  import { acquireCandidateWorkspaces } from './candidate-workspaces.js';
2
+ import { acquireMaintenanceWorkspaces } from './maintenance-workspaces.js';
2
3
  import { ActivityExecutionKind, } from '../../activities/index.js';
3
4
  import { runId } from '../contracts/identifiers.js';
4
5
  import { ExecutionStreamKind } from '../contracts/streams.js';
@@ -600,6 +601,14 @@ async function claimActivationForAttempt(runtime, activation, currentRunId, owne
600
601
  });
601
602
  }
602
603
  async function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
604
+ if (context.maintenance !== undefined)
605
+ return acquireMaintenanceWorkspaces({
606
+ runId: currentRunId,
607
+ resources: context.resources,
608
+ maintenance: context.maintenance,
609
+ runs: await runtime.repository.list(),
610
+ signal: signal ?? new AbortController().signal,
611
+ }, runtime.dependencies.workspaces);
603
612
  if (context.candidate !== undefined)
604
613
  return acquireCandidateWorkspaces({
605
614
  runId: currentRunId,
@@ -653,6 +662,7 @@ function activityWorkspace(lease, context) {
653
662
  candidate: lease.candidate === undefined
654
663
  ? undefined
655
664
  : { ...context.candidate, ...lease.candidate },
665
+ maintenance: lease.maintenance,
656
666
  },
657
667
  }),
658
668
  };
@@ -0,0 +1,17 @@
1
+ import { type ResourceView } from '../../resources/index.js';
2
+ import type { RunId } from '../contracts/identifiers.js';
3
+ import { type ExecutionMaintenance } from '../contracts/maintenance.js';
4
+ import type { RunView } from '../contracts/views.js';
5
+ import type { WorkspaceLease, WorkspaceProvider } from '../contracts/workspace.js';
6
+ /**
7
+ * Leases the recorded branch workspace of every maintenance target as a unit, in a fixed order so
8
+ * concurrent parents cannot deadlock. An unresolved earlier writer of any target stops the whole
9
+ * preparation: it must be reconciled before another writer is allowed to act.
10
+ */
11
+ export declare function acquireMaintenanceWorkspaces(request: {
12
+ readonly runId: RunId;
13
+ readonly resources: readonly ResourceView[];
14
+ readonly maintenance: ExecutionMaintenance;
15
+ readonly runs: readonly RunView[];
16
+ readonly signal: AbortSignal;
17
+ }, provider: WorkspaceProvider | undefined): Promise<WorkspaceLease>;
@@ -0,0 +1,84 @@
1
+ import { BuiltInResourceKind } from '../../resources/index.js';
2
+ import { executionMaintenanceSchema } from '../contracts/maintenance.js';
3
+ import { RunStatus, WorkspaceMode } from '../contracts/vocabulary.js';
4
+ /**
5
+ * Leases the recorded branch workspace of every maintenance target as a unit, in a fixed order so
6
+ * concurrent parents cannot deadlock. An unresolved earlier writer of any target stops the whole
7
+ * preparation: it must be reconciled before another writer is allowed to act.
8
+ */
9
+ export async function acquireMaintenanceWorkspaces(request, provider) {
10
+ if (provider === undefined)
11
+ throw new Error('Maintenance needs a workspace provider');
12
+ const maintenance = executionMaintenanceSchema.parse(request.maintenance);
13
+ const targets = [...maintenance.targets].sort((a, b) => a.childWorkItemId < b.childWorkItemId ? -1 : a.childWorkItemId === b.childWorkItemId ? 0 : 1);
14
+ if (new Set(targets.map((entry) => entry.childWorkItemId)).size !== targets.length)
15
+ throw new Error('Duplicate maintenance target');
16
+ for (const target of targets) {
17
+ const unresolved = request.runs.find((run) => run.runId !== request.runId &&
18
+ run.status === RunStatus.Ambiguous &&
19
+ ((run.workspace?.branch === target.childWorkItemId &&
20
+ run.workspace?.mode === WorkspaceMode.Branch) ||
21
+ run.workspace?.maintenance?.targets.some((entry) => entry.childWorkItemId === target.childWorkItemId) === true));
22
+ if (unresolved !== undefined)
23
+ throw new Error(`Maintenance target ${target.childWorkItemId} has an unresolved earlier writer: Run ${unresolved.runId}`);
24
+ }
25
+ const leases = [];
26
+ try {
27
+ for (const target of targets) {
28
+ request.signal.throwIfAborted();
29
+ const resource = request.resources.find((entry) => entry.resourceId === target.repository.resourceId &&
30
+ entry.kind === BuiltInResourceKind.Repository);
31
+ if (resource === undefined)
32
+ throw new Error('Maintenance repository is unavailable');
33
+ const lease = await provider.acquire({
34
+ runId: request.runId,
35
+ workItemId: target.childWorkItemId,
36
+ signal: request.signal,
37
+ mode: WorkspaceMode.Branch,
38
+ repositoryResource: resource,
39
+ assignment: target.repository,
40
+ checkoutRevision: target.revision,
41
+ });
42
+ leases.push(lease);
43
+ }
44
+ return {
45
+ ...leases[0],
46
+ maintenance: {
47
+ targets: targets.map((target, index) => ({
48
+ childWorkItemId: target.childWorkItemId,
49
+ outputName: target.outputName,
50
+ resourceId: target.resourceId,
51
+ branch: target.branch,
52
+ revision: target.revision,
53
+ path: leases[index].path,
54
+ ...(target.reason === undefined ? {} : { reason: target.reason }),
55
+ })),
56
+ },
57
+ release: () => releaseAll(leases),
58
+ };
59
+ }
60
+ catch (error) {
61
+ try {
62
+ await releaseAll(leases);
63
+ }
64
+ catch (cleanup) {
65
+ throw new AggregateError([error, cleanup], 'Maintenance preparation and cleanup failed', {
66
+ cause: cleanup,
67
+ });
68
+ }
69
+ throw error;
70
+ }
71
+ }
72
+ async function releaseAll(leases) {
73
+ const failures = [];
74
+ for (const lease of [...leases].reverse()) {
75
+ try {
76
+ await lease.release();
77
+ }
78
+ catch (error) {
79
+ failures.push(error);
80
+ }
81
+ }
82
+ if (failures.length > 0)
83
+ throw new AggregateError(failures, 'Maintenance lease cleanup failed');
84
+ }
@@ -197,6 +197,7 @@ function workspacePayload(lease) {
197
197
  : { checkoutRevision: lease.checkoutRevision }),
198
198
  path: lease.path,
199
199
  ...(lease.candidate === undefined ? {} : { candidate: lease.candidate }),
200
+ ...(lease.maintenance === undefined ? {} : { maintenance: lease.maintenance }),
200
201
  ...(lease.branch === undefined ? {} : { branch: lease.branch }),
201
202
  },
202
203
  }),
@@ -2,6 +2,7 @@ import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, Activity
2
2
  import type { ResourceView } from '../../resources/index.js';
3
3
  import type { WorkItemId } from '../../work/index.js';
4
4
  import type { ExecutionCandidate } from './candidate.js';
5
+ import type { ExecutionMaintenance } from './maintenance.js';
5
6
  import type { RepositoryAssignment } from './repository-assignment.js';
6
7
  import type { WorkspaceMode } from './vocabulary.js';
7
8
  export interface ExecutionActivation {
@@ -19,6 +20,7 @@ export interface ExecutionActivation {
19
20
  }
20
21
  export interface ExecutionAttemptContext {
21
22
  readonly candidate?: ExecutionCandidate;
23
+ readonly maintenance?: ExecutionMaintenance;
22
24
  readonly workItemId: WorkItemId;
23
25
  readonly workflowInstanceId: ActivityWorkflowInstanceId;
24
26
  readonly orchestrationGroupId: ActivityOrchestrationGroupId;
@@ -4,6 +4,7 @@ import { type ActivationId, type ActivityName, type ActivityOrchestrationGroupId
4
4
  import { type PreparedCandidate } from './candidate.js';
5
5
  import { runId } from './identifiers.js';
6
6
  import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
7
+ import { type PreparedMaintenance } from './maintenance.js';
7
8
  import { type RepositoryAssignment } from './repository-assignment.js';
8
9
  import type { ExecutionFailure, RecordedRunnerResult, RecoveredRunResult } from './results.js';
9
10
  import { type ActivationStreamRef, type RunStreamRef } from './streams.js';
@@ -47,6 +48,17 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
47
48
  path: z.ZodString;
48
49
  }, z.core.$strict>>;
49
50
  }, z.core.$strict>>;
51
+ maintenance: z.ZodOptional<z.ZodObject<{
52
+ targets: z.ZodArray<z.ZodObject<{
53
+ childWorkItemId: z.ZodString;
54
+ outputName: z.ZodString;
55
+ resourceId: z.ZodString;
56
+ branch: z.ZodString;
57
+ revision: z.ZodString;
58
+ path: z.ZodString;
59
+ reason: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strict>>;
61
+ }, z.core.$strict>>;
50
62
  }, z.core.$strict>>;
51
63
  }, z.core.$strict>;
52
64
  export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
@@ -148,6 +160,7 @@ export interface RunStartedPayload {
148
160
  readonly repositoryResourceId?: string | undefined;
149
161
  readonly checkoutRevision?: string | undefined;
150
162
  readonly candidate?: PreparedCandidate | undefined;
163
+ readonly maintenance?: PreparedMaintenance | undefined;
151
164
  } | undefined;
152
165
  }
153
166
  export interface RunPreparationStartedPayload {