@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
@@ -113,6 +113,8 @@ export declare function createGitHubClient(token: string): {
113
113
  listIssueComments: (owner: string, repo: string, issueNumber: number, pageSize: number, since?: string, maxResults?: number) => Promise<readonly import("../index.js").GitHubIssueCommentPayload[]>;
114
114
  listReviewComments: (owner: string, repo: string, pullNumber: number, pageSize: number, maxResults?: number) => Promise<readonly import("../index.js").GitHubIssueCommentPayload[]>;
115
115
  getIssueLabels: (owner: string, repo: string, issueNumber: number) => Promise<readonly string[]>;
116
+ checkExecution: (owner: string, repo: string, runId: number, attempt: number, checkId: number) => Promise<import("./check-execution.js").TestedCommit | undefined>;
117
+ workflowRunsForSuite: (owner: string, repo: string, suiteId: number) => Promise<readonly import("../index.js").GitHubWorkflowRunPayload[]>;
116
118
  getPullRequest: (owner: string, repo: string, pullNumber: number) => Promise<{
117
119
  url: string;
118
120
  id: number;
@@ -2,8 +2,10 @@ import { Octokit } from '@octokit/rest';
2
2
  import { MergeMethod, ProviderPermission, PullRequestState } from '../../../activities/index.js';
3
3
  import { GitHubOutboundAction } from '../contracts/vocabulary.js';
4
4
  import { createBoundedGitHubFetch } from './bounded-fetch.js';
5
+ import { createCheckExecutionReader } from './check-execution.js';
5
6
  import { branch, findIssueCommentByMarker, getCombinedStatusForRef, getIssueLabels, getPullRequest, listCheckRunsForRef, listIssueComments, listIssues, listPullRequestFiles, listPullRequests, listReviewComments, listReviews, } from './client-reads.js';
6
7
  import { createEtagCache } from './etag-cache.js';
8
+ import { workflowRunsForSuite } from './workflow-run-evidence.js';
7
9
  /* eslint-disable max-lines */
8
10
  // Octokit's request-log plugin reports every non-2xx response through this
9
11
  // callback, including the expected 304 responses produced by conditional ETag
@@ -114,6 +116,8 @@ function createGitHubReadClient(octokit, cache) {
114
116
  ...(maxResults === undefined ? {} : { maxResults }),
115
117
  }),
116
118
  getIssueLabels: (owner, repo, issueNumber) => getIssueLabels(octokit, cache, owner, repo, issueNumber),
119
+ checkExecution: createCheckExecutionReader(octokit),
120
+ workflowRunsForSuite: (owner, repo, suiteId) => workflowRunsForSuite(octokit, cache, owner, repo, suiteId),
117
121
  getPullRequest: (owner, repo, pullNumber) => getPullRequest(octokit, cache, owner, repo, pullNumber),
118
122
  listReviews: (owner, repo, pullNumber, pageSize, maxResults) => listReviews(octokit, cache, owner, repo, pullNumber, {
119
123
  pageSize,
@@ -0,0 +1,7 @@
1
+ import type { PullRequestCheckEvidence } from '../../../activities/index.js';
2
+ import type { GitHubPullRequestPayload } from '../contracts/payloads.js';
3
+ import type { CheckEvidence, PullRequestEvidenceClient } from './pr-evidence.js';
4
+ /** Join head-SHA checks to their actual checkout, never mutable linked PR metadata. */
5
+ export declare function verifiedCheckSubject(client: PullRequestEvidenceClient, owner: string, repo: string, pullRequest: GitHubPullRequestPayload, evidence: CheckEvidence): Promise<{
6
+ readonly checkEvidence?: PullRequestCheckEvidence;
7
+ }>;
@@ -0,0 +1,77 @@
1
+ import { GitHubCheckRunStatus } from '../contracts/vocabulary.js';
2
+ /** Join head-SHA checks to their actual checkout, never mutable linked PR metadata. */
3
+ export async function verifiedCheckSubject(client, owner, repo, pullRequest, evidence) {
4
+ if (!eligibleEvidence(evidence, client))
5
+ return {};
6
+ try {
7
+ const suites = new Map();
8
+ const testedRevisions = [];
9
+ for (const check of evidence.checkRuns) {
10
+ if (!qualifyingCheck(check, pullRequest.head?.sha))
11
+ return {};
12
+ const suiteId = check.check_suite.id;
13
+ if (!suites.has(suiteId))
14
+ suites.set(suiteId, await client.workflowRunsForSuite(owner, repo, suiteId));
15
+ const matching = suites
16
+ .get(suiteId)
17
+ .filter((run) => matchesExecution(run, suiteId, pullRequest));
18
+ if (matching.length !== 1)
19
+ return {};
20
+ if (check.conclusion !== 'success')
21
+ continue;
22
+ const commit = await readCheckout(client.checkExecution, owner, repo, matching[0], check);
23
+ if (!matchesCheckout(commit, pullRequest))
24
+ return {};
25
+ testedRevisions.push(commit.sha);
26
+ }
27
+ if (testedRevisions.length === 0)
28
+ return {};
29
+ return {
30
+ checkEvidence: {
31
+ testedRevision: testedRevisions[0],
32
+ headRevision: pullRequest.head.sha,
33
+ baseRevision: pullRequest.base.sha,
34
+ startedAt: new Date(Math.min(...evidence.checkRuns.map((run) => Date.parse(run.started_at)))).toISOString(),
35
+ },
36
+ };
37
+ }
38
+ catch {
39
+ return {};
40
+ }
41
+ }
42
+ function eligibleEvidence(evidence, client) {
43
+ return (client.workflowRunsForSuite !== undefined &&
44
+ client.checkExecution !== undefined &&
45
+ evidence.available &&
46
+ evidence.complete &&
47
+ evidence.statuses.length === 0 &&
48
+ evidence.checkRuns.length > 0);
49
+ }
50
+ function qualifyingCheck(check, head) {
51
+ return (head !== undefined &&
52
+ check.head_sha === head &&
53
+ check.check_suite != null &&
54
+ check.status === GitHubCheckRunStatus.Completed &&
55
+ passingConclusions.has(check.conclusion ?? '') &&
56
+ typeof check.started_at === 'string' &&
57
+ Number.isFinite(Date.parse(check.started_at)));
58
+ }
59
+ function matchesExecution(run, suiteId, pr) {
60
+ return (run.check_suite_id === suiteId &&
61
+ run.event === 'pull_request' &&
62
+ run.head_sha === pr.head?.sha &&
63
+ run.status === GitHubCheckRunStatus.Completed &&
64
+ run.conclusion === 'success');
65
+ }
66
+ const passingConclusions = new Set(['success', 'neutral', 'skipped']);
67
+ function matchesCheckout(commit, pr) {
68
+ return (commit !== undefined &&
69
+ commit.parents.length === 2 &&
70
+ commit.parents[0]?.sha === pr.base?.sha &&
71
+ commit.parents[1]?.sha === pr.head?.sha);
72
+ }
73
+ async function readCheckout(reader, owner, repo, execution, check) {
74
+ if (check.id === undefined)
75
+ return undefined;
76
+ return reader(owner, repo, execution.id, execution.run_attempt ?? 1, check.id);
77
+ }
@@ -1,4 +1,5 @@
1
- import type { GitHubCheckRunPayload, GitHubCommitStatusPayload } from '../contracts/payloads.js';
1
+ import type { GitHubCheckRunPayload, GitHubCommitStatusPayload, GitHubWorkflowRunPayload } from '../contracts/payloads.js';
2
+ import type { TestedCommit } from './check-execution.js';
2
3
  export interface CheckEvidence {
3
4
  readonly available: boolean;
4
5
  readonly complete: boolean;
@@ -9,10 +10,12 @@ export interface ChangedFiles {
9
10
  readonly files: readonly string[] | undefined;
10
11
  readonly complete: boolean;
11
12
  }
12
- interface PullRequestEvidenceClient {
13
+ export interface PullRequestEvidenceClient {
14
+ checkExecution?(owner: string, repo: string, runId: number, attempt: number, checkId: number): Promise<TestedCommit | undefined>;
15
+ workflowRunsForSuite?(owner: string, repo: string, suiteId: number): Promise<readonly GitHubWorkflowRunPayload[]>;
13
16
  listCheckRunsForRef(owner: string, repo: string, ref: string, maxResults?: number): Promise<readonly GitHubCheckRunPayload[]>;
14
17
  getCombinedStatusForRef(owner: string, repo: string, ref: string, maxResults?: number): Promise<readonly GitHubCommitStatusPayload[]>;
15
18
  listPullRequestFiles(owner: string, repo: string, pullNumber: number, maxResults?: number): Promise<readonly string[]>;
16
19
  }
17
20
  export declare function readPullRequestEvidence(client: PullRequestEvidenceClient, owner: string, repo: string, headRevision: string, pullNumber: number, maxResults: number): Promise<readonly [CheckEvidence, ChangedFiles]>;
18
- export {};
21
+ export declare function readCheckEvidence(client: PullRequestEvidenceClient, owner: string, repo: string, headRevision: string, maxResults: number): Promise<CheckEvidence>;
@@ -4,7 +4,7 @@ export async function readPullRequestEvidence(client, owner, repo, headRevision,
4
4
  readChangedFiles(client, owner, repo, pullNumber, maxResults),
5
5
  ]);
6
6
  }
7
- async function readCheckEvidence(client, owner, repo, headRevision, maxResults) {
7
+ export async function readCheckEvidence(client, owner, repo, headRevision, maxResults) {
8
8
  try {
9
9
  const [checkRuns, statuses] = await Promise.all([
10
10
  client.listCheckRunsForRef(owner, repo, headRevision, maxResults),
@@ -1,12 +1,10 @@
1
1
  import type { AdapterId } from '../../contracts/identifiers.js';
2
2
  import type { ExternalEventSource } from '../application/poll-service.js';
3
- import { type GitHubCheckRunPayload, type GitHubCommitStatusPayload, type GitHubPullRequestPayload } from '../contracts/payloads.js';
3
+ import { type GitHubPullRequestPayload } from '../contracts/payloads.js';
4
4
  import type { PollBatch } from './poll-watermark.js';
5
- export interface GitHubPullRequestSourceClient {
5
+ import { type PullRequestEvidenceClient } from './pr-evidence.js';
6
+ export interface GitHubPullRequestSourceClient extends PullRequestEvidenceClient {
6
7
  listPullRequests(owner: string, repo: string, maxResults: number): Promise<readonly GitHubPullRequestPayload[]>;
7
- listCheckRunsForRef(owner: string, repo: string, ref: string, maxResults?: number): Promise<readonly GitHubCheckRunPayload[]>;
8
- getCombinedStatusForRef(owner: string, repo: string, ref: string, maxResults?: number): Promise<readonly GitHubCommitStatusPayload[]>;
9
- listPullRequestFiles(owner: string, repo: string, pullNumber: number, maxResults?: number): Promise<readonly string[]>;
10
8
  }
11
9
  interface GitHubPullRequestSourceInput {
12
10
  readonly client: GitHubPullRequestSourceClient;
@@ -8,7 +8,8 @@ import { formatGitHubResourceKey } from '../contracts/external-key.js';
8
8
  import { gitHubAssigneeLogins, gitHubLabelNames, } from '../contracts/payloads.js';
9
9
  import { GitHubAdapter, GitHubCheckRunStatus, UnknownGitHubIdentity, UnknownGitHubRevision, } from '../contracts/vocabulary.js';
10
10
  import { withoutWakeMarkers } from './content-fingerprint.js';
11
- import { readPullRequestEvidence } from './pr-evidence.js';
11
+ import { verifiedCheckSubject } from './pr-check-subject.js';
12
+ import { readPullRequestEvidence, } from './pr-evidence.js';
12
13
  export function createGitHubPullRequestSource(input) {
13
14
  return {
14
15
  async poll(signal) {
@@ -24,12 +25,14 @@ export async function pullRequestEventsFor(input, signal) {
24
25
  signal.throwIfAborted();
25
26
  const headRevision = fallback(pullRequest.head?.sha, pullRequest.updated_at);
26
27
  const [evidence, changedFiles] = await readPullRequestEvidence(input.client, owner, repo, headRevision, pullRequest.number, input.maxResults);
28
+ const checkSubject = await verifiedCheckSubject(input.client, owner, repo, pullRequest, evidence);
27
29
  return {
28
30
  complete: evidence.complete && changedFiles.complete,
29
31
  draft: pullRequestObservation({
30
32
  repository: input.repository,
31
33
  pullRequest,
32
34
  evidence,
35
+ checkSubject,
33
36
  changedFiles: changedFiles.files,
34
37
  ...(input.adapter === undefined ? {} : { adapter: input.adapter }),
35
38
  }),
@@ -57,6 +60,7 @@ function pullRequestObservation(input) {
57
60
  title: pullRequest.title,
58
61
  body: fallback(pullRequest.body, ''),
59
62
  state: pullRequestState(pullRequest),
63
+ ...mergedRevision(pullRequest),
60
64
  mergeability: pullRequest.mergeable === false
61
65
  ? PullRequestMergeability.Conflicting
62
66
  : pullRequest.mergeable === true
@@ -66,6 +70,7 @@ function pullRequestObservation(input) {
66
70
  headRevision: revision,
67
71
  baseRevision: fallback(pullRequest.base?.sha, UnknownGitHubRevision),
68
72
  checks,
73
+ ...input.checkSubject,
69
74
  actor: {
70
75
  id: fallback(pullRequest.user?.login, UnknownGitHubIdentity),
71
76
  kind: actorKind(pullRequest.user?.type),
@@ -198,3 +203,8 @@ const GitHubCommitStatusState = {
198
203
  Pending: PullRequestCheckState.Pending,
199
204
  Success: 'success',
200
205
  };
206
+ function mergedRevision(pullRequest) {
207
+ return pullRequestState(pullRequest) === PullRequestState.Merged && pullRequest.merge_commit_sha
208
+ ? { mergeRevision: pullRequest.merge_commit_sha }
209
+ : {};
210
+ }
@@ -0,0 +1,5 @@
1
+ import type { Octokit } from '@octokit/rest';
2
+ import type { GitHubWorkflowRunPayload } from '../contracts/payloads.js';
3
+ import { type createEtagCache } from './etag-cache.js';
4
+ /** Revalidate mutable run attempts; conditional requests reuse unchanged responses. */
5
+ export declare function workflowRunsForSuite(octokit: Octokit, cache: ReturnType<typeof createEtagCache>, owner: string, repo: string, suiteId: number): Promise<readonly GitHubWorkflowRunPayload[]>;
@@ -0,0 +1,22 @@
1
+ import { fetchWithEtag } from './etag-cache.js';
2
+ /** Revalidate mutable run attempts; conditional requests reuse unchanged responses. */
3
+ export function workflowRunsForSuite(octokit, cache, owner, repo, suiteId) {
4
+ return fetchWithEtag({
5
+ cache,
6
+ key: `workflow-run-suite:${owner}/${repo}@${suiteId}`,
7
+ request: async (headers) => {
8
+ const response = await octokit.rest.actions.listWorkflowRunsForRepo({
9
+ owner,
10
+ repo,
11
+ check_suite_id: suiteId,
12
+ event: 'pull_request',
13
+ per_page: 100,
14
+ ...(headers === undefined ? {} : { headers }),
15
+ });
16
+ return {
17
+ data: response.data.total_count >= 100 ? [] : response.data.workflow_runs,
18
+ ...(response.headers.etag === undefined ? {} : { etag: response.headers.etag }),
19
+ };
20
+ },
21
+ });
22
+ }
@@ -33,3 +33,4 @@ export * from './fake/external-source.js';
33
33
  export * from './fake/provider.js';
34
34
  export * from './application/conversation-command-feedback.js';
35
35
  export { createDelegationOutputs } from './application/delegation-outputs.js';
36
+ export * from './application/delivery-integration-verification.js';
@@ -33,3 +33,4 @@ export * from './fake/external-source.js';
33
33
  export * from './fake/provider.js';
34
34
  export * from './application/conversation-command-feedback.js';
35
35
  export { createDelegationOutputs } from './application/delegation-outputs.js';
36
+ export * from './application/delivery-integration-verification.js';
@@ -86,6 +86,9 @@ export declare class DelegationCommands {
86
86
  stage: string;
87
87
  recipe?: string | undefined;
88
88
  } | undefined;
89
+ maintenance?: {
90
+ stage: string;
91
+ } | undefined;
89
92
  } | null;
90
93
  repositories: string[];
91
94
  planRevision: number;
@@ -1,7 +1,8 @@
1
1
  import { type CommandContext } from '@atolis-hq/eventing';
2
+ import type { ParentActionRequest } from '../../activities/index.js';
2
3
  import { type DelegationCaller } from '../contracts/delegation.js';
3
4
  import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
4
- import { type DeliveryCandidate, type DeliveryCandidateCommand, type DeliveryQa, type DeliveryQaCommand, type DeliverySelectionCommand } from '../contracts/delivery.js';
5
+ import { type DeliveryCandidate, type DeliveryCandidateCommand, type DeliveryMaintenanceCommand, type DeliveryQa, type DeliveryQaCommand, type DeliverySelectionCommand } from '../contracts/delivery.js';
5
6
  import type { OrchestrationRepository } from './orchestration-repository.js';
6
7
  /**
7
8
  * Agent-led parent QA over the delegated delivery. The parent agent chooses what to select,
@@ -13,7 +14,16 @@ export declare class DeliveryCoordinator {
13
14
  private readonly repository;
14
15
  private readonly dependencies;
15
16
  private readonly preparation;
17
+ private readonly integration;
16
18
  constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
19
+ authorizeParentAction(request: ParentActionRequest): Promise<import("../../activities/index.js").ParentActionDecision>;
20
+ /** The targets the configured maintenance stage will lease, or undefined for other stages. */
21
+ maintenanceTargets(id: string): Promise<import("../domain/delivery-integration.js").IntegrationTarget[] | undefined>;
22
+ /** Records what the maintaining agent actually produced as a new immutable subject. */
23
+ recordMaintenance(caller: DelegationCaller, input: DeliveryMaintenanceCommand, context: CommandContext): Promise<{
24
+ readonly maintenance: import("../contracts/delivery.js").DeliveryMaintenance;
25
+ readonly replay: boolean;
26
+ }>;
17
27
  select(caller: DelegationCaller, input: DeliverySelectionCommand, context: CommandContext): Promise<{
18
28
  selection: {
19
29
  requestId: string;
@@ -75,6 +85,13 @@ export declare class DeliveryCoordinator {
75
85
  outputName: string;
76
86
  }[];
77
87
  criteria: string[];
88
+ subjects?: {
89
+ childWorkItemId: import("../../work/index.js").WorkItemId;
90
+ outputName: string;
91
+ revision: string;
92
+ pullRequestBase: string;
93
+ baseRevision?: string | undefined;
94
+ }[] | undefined;
78
95
  recipe?: string | undefined;
79
96
  };
80
97
  replay: boolean;
@@ -105,6 +122,32 @@ export declare class DeliveryCoordinator {
105
122
  }>;
106
123
  /** The inspectable delivery state: selection, staleness, candidate, QA, repair and completion. */
107
124
  inspectFor(caller: DelegationCaller): Promise<{
125
+ integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
126
+ maintenance: readonly {
127
+ maintenanceId: string;
128
+ target: {
129
+ childWorkItemId: import("../../work/index.js").WorkItemId;
130
+ outputName: string;
131
+ };
132
+ kind: "rebase" | "retarget" | "resolve-conflicts";
133
+ resourceId: string;
134
+ repositoryResourceId: string;
135
+ previous: {
136
+ revision: string;
137
+ pullRequestBase: string;
138
+ baseRevision?: string | undefined;
139
+ };
140
+ current: {
141
+ revision: string;
142
+ pullRequestBase: string;
143
+ baseRevision?: string | undefined;
144
+ };
145
+ producer: {
146
+ runId: string;
147
+ activationId: string;
148
+ };
149
+ recordedAt?: string | undefined;
150
+ }[];
108
151
  required: {
109
152
  cohortId: string;
110
153
  assignmentId: string;
@@ -176,6 +219,32 @@ export declare class DeliveryCoordinator {
176
219
  };
177
220
  }>;
178
221
  inspect(id: string): Promise<{
222
+ integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
223
+ maintenance: readonly {
224
+ maintenanceId: string;
225
+ target: {
226
+ childWorkItemId: import("../../work/index.js").WorkItemId;
227
+ outputName: string;
228
+ };
229
+ kind: "rebase" | "retarget" | "resolve-conflicts";
230
+ resourceId: string;
231
+ repositoryResourceId: string;
232
+ previous: {
233
+ revision: string;
234
+ pullRequestBase: string;
235
+ baseRevision?: string | undefined;
236
+ };
237
+ current: {
238
+ revision: string;
239
+ pullRequestBase: string;
240
+ baseRevision?: string | undefined;
241
+ };
242
+ producer: {
243
+ runId: string;
244
+ activationId: string;
245
+ };
246
+ recordedAt?: string | undefined;
247
+ }[];
179
248
  required: {
180
249
  cohortId: string;
181
250
  assignmentId: string;
@@ -1,16 +1,17 @@
1
1
  import { WrongExpectedSequenceError } from '@atolis-hq/eventing';
2
2
  import { DelegationConflictError, delegationSubmissionSchema, } from '../contracts/delegation.js';
3
- import { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from '../contracts/delivery.js';
3
+ import { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryMaintenanceCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from '../contracts/delivery.js';
4
4
  import { OrchestrationEventType } from '../contracts/events.js';
5
5
  import { stageName } from '../contracts/identifiers.js';
6
6
  import { DelegationConflictCode, DeliveryCompletion, DeliveryRejection, QaVerdict, WorkflowStatus, } from '../contracts/vocabulary.js';
7
7
  import { planCandidate } from '../domain/delivery-candidate.js';
8
- import { requirements } from '../domain/delivery-facts.js';
8
+ import { currentSelection, requirements } from '../domain/delivery-facts.js';
9
9
  import { assertQa, completionDecision, deliveryState } from '../domain/delivery-qa.js';
10
10
  import { originalOf } from '../domain/delivery-replacement.js';
11
11
  import { reviseSelection } from '../domain/delivery-selection.js';
12
12
  import { delegationDraft } from './delegation-ledger.js';
13
13
  import { readDeliveryFacts } from './delivery-facts-reader.js';
14
+ import { DeliveryIntegrationService } from './delivery-integration-service.js';
14
15
  import { DeliveryPreparation } from './delivery-preparation.js';
15
16
  import { verifyCandidateSources } from './delivery-sources.js';
16
17
  /**
@@ -23,10 +24,30 @@ export class DeliveryCoordinator {
23
24
  repository;
24
25
  dependencies;
25
26
  preparation;
27
+ integration;
26
28
  constructor(repository, dependencies) {
27
29
  this.repository = repository;
28
30
  this.dependencies = dependencies;
29
31
  this.preparation = new DeliveryPreparation(repository, dependencies);
32
+ this.integration = new DeliveryIntegrationService(repository, dependencies);
33
+ }
34
+ authorizeParentAction(request) {
35
+ return this.integration.authorize(request);
36
+ }
37
+ /** The targets the configured maintenance stage will lease, or undefined for other stages. */
38
+ async maintenanceTargets(id) {
39
+ const parent = (await this.repository.loadRequired(id)).view;
40
+ const stage = (await this.dependencies.definitionFor(parent)).delegation?.maintenance?.stage;
41
+ if (stage === undefined || parent.pendingActivation?.stage !== stage)
42
+ return undefined;
43
+ return this.integration.maintenanceTargets(parent);
44
+ }
45
+ /** Records what the maintaining agent actually produced as a new immutable subject. */
46
+ async recordMaintenance(caller, input, context) {
47
+ const command = deliveryMaintenanceCommandSchema.parse(input);
48
+ const parent = await this.parent(caller);
49
+ await this.assertCoordinatorStage(parent);
50
+ return this.commit(parent, context, `maintenance:${command.maintenanceId}`, (facts) => this.integration.planMaintenance(facts, command, caller, context.occurredAt));
30
51
  }
31
52
  async select(caller, input, context) {
32
53
  const command = deliverySelectionCommandSchema.parse(input);
@@ -120,20 +141,25 @@ export class DeliveryCoordinator {
120
141
  const parent = (await this.repository.loadRequired(id)).view;
121
142
  const facts = await this.facts(parent);
122
143
  const state = deliveryState(facts);
144
+ const mode = (await this.dependencies.definitionFor(parent)).delegation?.completion ??
145
+ DeliveryCompletion.QaApproved;
146
+ // Only merge-required deliveries pay for provider reads; QA-approved ones never integrate.
147
+ const integration = mode === DeliveryCompletion.MergeRequired ? await this.integration.assess(facts) : null;
123
148
  return {
124
149
  ...state,
150
+ integration,
151
+ maintenance: facts.maintenance,
125
152
  required: requirements(facts.reservations).map((requirement) => ({
126
153
  cohortId: requirement.cohortId,
127
154
  assignmentId: requirement.assignmentId,
128
155
  outputName: requirement.outputName,
129
156
  childWorkItemId: requirement.child.workItemId,
130
157
  })),
131
- selection: facts.selections.at(-1) ?? null,
158
+ selection: currentSelection(facts) ?? null,
132
159
  history: facts.qa,
133
160
  completion: parent.deliveryGateBlock !== undefined
134
161
  ? { complete: false, reason: parent.blockReason }
135
- : completionDecision(state, (await this.dependencies.definitionFor(parent)).delegation?.completion ??
136
- DeliveryCompletion.QaApproved),
162
+ : completionDecision(state, mode, integration ?? undefined),
137
163
  };
138
164
  }
139
165
  /**
@@ -32,6 +32,7 @@ export async function readDeliveryFacts(repository, parent, own) {
32
32
  selections: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliverySelectionRevised ? [event.payload] : []),
33
33
  candidates: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryCandidateRecorded ? [event.payload] : []),
34
34
  qa: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryQaRecorded ? [event.payload] : []),
35
+ maintenance: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryMaintenanceRecorded ? [event.payload] : []),
35
36
  };
36
37
  }
37
38
  function distinctCohorts(reservations) {
@@ -0,0 +1,9 @@
1
+ import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
2
+ import { type DeliveryFacts } from '../domain/delivery-facts.js';
3
+ import { type IntegrationAssessment } from '../domain/delivery-integration.js';
4
+ /** Reads the provider and Work facts the pure integration decision needs, fresh on every call. */
5
+ export declare class DeliveryIntegrationReader {
6
+ private readonly dependencies;
7
+ constructor(dependencies: DeliveryDependencies);
8
+ assess(facts: DeliveryFacts): Promise<IntegrationAssessment>;
9
+ }
@@ -0,0 +1,23 @@
1
+ import { currentSelection, isChange } from '../domain/delivery-facts.js';
2
+ import { assessIntegration, } from '../domain/delivery-integration.js';
3
+ /** Reads the provider and Work facts the pure integration decision needs, fresh on every call. */
4
+ export class DeliveryIntegrationReader {
5
+ dependencies;
6
+ constructor(dependencies) {
7
+ this.dependencies = dependencies;
8
+ }
9
+ async assess(facts) {
10
+ const changes = (currentSelection(facts)?.entries ?? []).flatMap((entry) => isChange(entry.output)
11
+ ? [{ child: entry.childWorkItemId, reference: entry.output.reference }]
12
+ : []);
13
+ const observations = new Map();
14
+ for (const { reference } of changes) {
15
+ const observed = await this.dependencies.integration?.observe(reference.resourceId);
16
+ if (observed !== undefined && observed !== null)
17
+ observations.set(reference.resourceId, observed);
18
+ }
19
+ const held = (await this.dependencies.unavailable?.(changes.map((change) => change.child))) ??
20
+ new Map();
21
+ return assessIntegration(facts, observations, held);
22
+ }
23
+ }
@@ -0,0 +1,50 @@
1
+ import { type ParentActionDecision, type ParentActionRequest } from '../../activities/index.js';
2
+ import type { DelegationCaller } from '../contracts/delegation.js';
3
+ import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
4
+ import { type DeliveryMaintenance, type DeliveryMaintenanceCommand } from '../contracts/delivery.js';
5
+ import { OrchestrationEventType } from '../contracts/events.js';
6
+ import type { WorkflowInstanceView } from '../contracts/views.js';
7
+ import { type DeliveryFacts } from '../domain/delivery-facts.js';
8
+ import { type IntegrationAssessment } from '../domain/delivery-integration.js';
9
+ import type { OrchestrationRepository } from './orchestration-repository.js';
10
+ /**
11
+ * Governed integration of child-owned pull requests by their parent delivery. Wake derives the
12
+ * one planned next action from the parent's journal and provider facts, authorizes exactly that
13
+ * target, and verifies what a maintaining agent actually produced. The agent chooses the repair;
14
+ * nothing here authors a change, reopens a child or transfers a pull request.
15
+ */
16
+ export declare class DeliveryIntegrationService {
17
+ private readonly repository;
18
+ private readonly dependencies;
19
+ private readonly reader;
20
+ constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
21
+ assess(facts: DeliveryFacts): Promise<IntegrationAssessment>;
22
+ authorize(request: ParentActionRequest): Promise<ParentActionDecision>;
23
+ private verifySelected;
24
+ /**
25
+ * Validates one maintenance report against the selected subject and the provider. The result is
26
+ * a new immutable subject; the replaced head, its reviews, checks and QA stay historical.
27
+ */
28
+ planMaintenance(facts: DeliveryFacts, input: DeliveryMaintenanceCommand, caller: DelegationCaller, recordedAt: string): Promise<MaintenancePlan>;
29
+ /** Only the invocation Wake dispatched for this parent may ask, and only for its own action. */
30
+ private dispatchedMerge;
31
+ private assertAvailable;
32
+ private observeOpen;
33
+ /**
34
+ * The open pull requests a maintenance stage may lease. Merged, closed or held targets cannot
35
+ * be written to, so they are never offered.
36
+ */
37
+ maintenanceTargets(parent: WorkflowInstanceView): Promise<import("../domain/delivery-integration.js").IntegrationTarget[]>;
38
+ private facts;
39
+ }
40
+ interface MaintenancePlan {
41
+ readonly result: {
42
+ readonly maintenance: DeliveryMaintenance;
43
+ readonly replay: boolean;
44
+ };
45
+ readonly draft: {
46
+ readonly eventType: typeof OrchestrationEventType.DeliveryMaintenanceRecorded;
47
+ readonly payload: DeliveryMaintenance;
48
+ } | undefined;
49
+ }
50
+ export {};