@atolis-hq/wake 0.4.77 → 0.4.78

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 (49) hide show
  1. package/dist/src/activities/contracts/event-schema.d.ts +30 -0
  2. package/dist/src/activities/contracts/event-schema.js +8 -2
  3. package/dist/src/activities/contracts/events.d.ts +3 -1
  4. package/dist/src/activities/pr/application.js +6 -3
  5. package/dist/src/activities/pr/contracts.d.ts +3 -1
  6. package/dist/src/activities/pr/event-data.js +4 -1
  7. package/dist/src/activities/pr/projection.js +4 -1
  8. package/dist/src/activities/pr/vocabulary.d.ts +6 -0
  9. package/dist/src/activities/pr/vocabulary.js +5 -0
  10. package/dist/src/bootstrap/config/root-schema.d.ts +18 -0
  11. package/dist/src/bootstrap/resource-transition-evidence.js +20 -14
  12. package/dist/src/bootstrap/version.js +1 -1
  13. package/dist/src/integrations/application/agent-run-publication-reactor.d.ts +1 -0
  14. package/dist/src/integrations/application/agent-run-publication-reactor.js +49 -25
  15. package/dist/src/integrations/application/agent-run-publication-report.d.ts +10 -0
  16. package/dist/src/integrations/application/agent-run-publication-report.js +53 -0
  17. package/dist/src/integrations/application/terminal-agent-run-report.d.ts +4 -0
  18. package/dist/src/integrations/application/terminal-agent-run-report.js +4 -0
  19. package/dist/src/integrations/delivery/contracts/intents.d.ts +2 -0
  20. package/dist/src/integrations/delivery/contracts/intents.js +2 -0
  21. package/dist/src/integrations/github/application/agent-run-comment.d.ts +2 -0
  22. package/dist/src/integrations/github/application/agent-run-comment.js +26 -5
  23. package/dist/src/integrations/github/application/pull-request-translation.js +1 -0
  24. package/dist/src/integrations/github/contracts/events.d.ts +2 -1
  25. package/dist/src/integrations/github/contracts/events.js +8 -1
  26. package/dist/src/integrations/github/contracts/payloads.d.ts +1 -0
  27. package/dist/src/integrations/github/infrastructure/client-reads.d.ts +18 -6
  28. package/dist/src/integrations/github/infrastructure/client-reads.js +6 -1
  29. package/dist/src/integrations/github/infrastructure/client.d.ts +18 -6
  30. package/dist/src/integrations/github/infrastructure/consecutive-pr-observations.d.ts +4 -0
  31. package/dist/src/integrations/github/infrastructure/consecutive-pr-observations.js +33 -0
  32. package/dist/src/integrations/github/infrastructure/pr-source.js +6 -1
  33. package/dist/src/integrations/github/infrastructure/source.d.ts +6 -2
  34. package/dist/src/integrations/github/infrastructure/source.js +9 -9
  35. package/dist/src/integrations/github/provider.js +1 -0
  36. package/dist/src/orchestration/application/policy-blocked-merge-recovery.d.ts +5 -0
  37. package/dist/src/orchestration/application/policy-blocked-merge-recovery.js +108 -21
  38. package/dist/src/orchestration/application/pull-request-transition-evidence.js +22 -1
  39. package/dist/src/orchestration/application/resource-transition-evidence.d.ts +6 -1
  40. package/dist/src/orchestration/application/resource-transition-matching.d.ts +5 -0
  41. package/dist/src/orchestration/application/resource-transition-matching.js +23 -1
  42. package/dist/src/orchestration/contracts/config.d.ts +42 -1
  43. package/dist/src/orchestration/contracts/config.js +9 -1
  44. package/dist/src/orchestration/contracts/event-decoder.d.ts +5 -0
  45. package/dist/src/orchestration/contracts/event-decoder.js +6 -1
  46. package/dist/src/orchestration/domain/resource-transition-compiler.js +1 -0
  47. package/dist/src/orchestration/index.d.ts +1 -0
  48. package/dist/src/orchestration/index.js +1 -0
  49. package/package.json +1 -1
@@ -120,6 +120,11 @@ export declare function createResourceFactDraftSchemas(eventTypes: ActivityEvent
120
120
  closed: "closed";
121
121
  merged: "merged";
122
122
  }>;
123
+ mergeability: z.ZodOptional<z.ZodEnum<{
124
+ unknown: "unknown";
125
+ clean: "clean";
126
+ conflicting: "conflicting";
127
+ }>>;
123
128
  headRevision: z.ZodString;
124
129
  baseRevision: z.ZodString;
125
130
  checks: z.ZodEnum<{
@@ -187,6 +192,11 @@ export declare function createResourceFactDraftSchemas(eventTypes: ActivityEvent
187
192
  closed: "closed";
188
193
  merged: "merged";
189
194
  }>;
195
+ mergeability: z.ZodOptional<z.ZodEnum<{
196
+ unknown: "unknown";
197
+ clean: "clean";
198
+ conflicting: "conflicting";
199
+ }>>;
190
200
  }, z.core.$strict>;
191
201
  }, z.core.$strict>, z.ZodObject<{
192
202
  eventId: z.ZodPipe<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<import("@atolis-hq/eventing").EventId, string>>>;
@@ -615,6 +625,11 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
615
625
  closed: "closed";
616
626
  merged: "merged";
617
627
  }>;
628
+ mergeability: z.ZodOptional<z.ZodEnum<{
629
+ unknown: "unknown";
630
+ clean: "clean";
631
+ conflicting: "conflicting";
632
+ }>>;
618
633
  headRevision: z.ZodString;
619
634
  baseRevision: z.ZodString;
620
635
  checks: z.ZodEnum<{
@@ -682,6 +697,11 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
682
697
  closed: "closed";
683
698
  merged: "merged";
684
699
  }>;
700
+ mergeability: z.ZodOptional<z.ZodEnum<{
701
+ unknown: "unknown";
702
+ clean: "clean";
703
+ conflicting: "conflicting";
704
+ }>>;
685
705
  }, z.core.$strict>;
686
706
  }, z.core.$strict>, z.ZodObject<{
687
707
  eventId: z.ZodPipe<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<import("@atolis-hq/eventing").EventId, string>>>;
@@ -2123,6 +2143,11 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2123
2143
  closed: "closed";
2124
2144
  merged: "merged";
2125
2145
  }>;
2146
+ mergeability: z.ZodOptional<z.ZodEnum<{
2147
+ unknown: "unknown";
2148
+ clean: "clean";
2149
+ conflicting: "conflicting";
2150
+ }>>;
2126
2151
  headRevision: z.ZodString;
2127
2152
  baseRevision: z.ZodString;
2128
2153
  checks: z.ZodEnum<{
@@ -2190,6 +2215,11 @@ export declare function createActivityEventSchemas(eventTypes: ActivityEventType
2190
2215
  closed: "closed";
2191
2216
  merged: "merged";
2192
2217
  }>;
2218
+ mergeability: z.ZodOptional<z.ZodEnum<{
2219
+ unknown: "unknown";
2220
+ clean: "clean";
2221
+ conflicting: "conflicting";
2222
+ }>>;
2193
2223
  }, z.core.$strict>;
2194
2224
  }, z.core.$strict>, z.ZodObject<{
2195
2225
  eventId: z.ZodPipe<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<import("@atolis-hq/eventing").EventId, string>>>;
@@ -4,7 +4,7 @@ import { eventDataSchema, eventEnvelopeSchema } from '@atolis-hq/eventing';
4
4
  import { brandedStringSchema } from '../../kernel/index.js';
5
5
  import { ResourceStreamKind, resourceId } from '../../resources/index.js';
6
6
  import { WorkStreamKind, workItemId } from '../../work/index.js';
7
- import { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestState, } from '../pr/vocabulary.js';
7
+ import { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, PullRequestState, } from '../pr/vocabulary.js';
8
8
  import { ReviewActorKind } from '../review/contracts.js';
9
9
  import { legacyClaimPayload, newClaimPayload, normalizeLegacyFact, } from './decision-claim-schema.js';
10
10
  import { decisionClaimDataIdentity, decisionClaimIdentity, resourcePayloadIdentity, } from './event-integrity.js';
@@ -125,6 +125,11 @@ export const deniedOutcomeSchema = z
125
125
  .strict(),
126
126
  })
127
127
  .strict();
128
+ const mergeabilitySchema = z.enum([
129
+ PullRequestMergeability.Unknown,
130
+ PullRequestMergeability.Mergeable,
131
+ PullRequestMergeability.Conflicting,
132
+ ]);
128
133
  export function createResourceFactDraftSchemas(eventTypes) {
129
134
  return [
130
135
  resourceFactDraft(eventTypes.IssueCompleteRequested, z
@@ -139,6 +144,7 @@ export function createResourceFactDraftSchemas(eventTypes) {
139
144
  .object({
140
145
  workItemId: workItemIdSchema,
141
146
  state: stateSchema,
147
+ mergeability: mergeabilitySchema.optional(),
142
148
  headRevision: z.string(),
143
149
  baseRevision: z.string(),
144
150
  checks: checksSchema,
@@ -152,7 +158,7 @@ export function createResourceFactDraftSchemas(eventTypes) {
152
158
  changedFiles: z.array(z.string()).optional(),
153
159
  })
154
160
  .strict()),
155
- resourceFactDraft(eventTypes.PrStateChanged, z.object({ state: stateSchema }).strict()),
161
+ resourceFactDraft(eventTypes.PrStateChanged, z.object({ state: stateSchema, mergeability: mergeabilitySchema.optional() }).strict()),
156
162
  resourceFactDraft(eventTypes.PrChecksChanged, z.object({ checks: checksSchema }).strict()),
157
163
  resourceFactDraft(eventTypes.PrReviewAccepted, reviewSchema),
158
164
  resourceFactDraft(eventTypes.ReviewAcceptanceSignalRecorded, z
@@ -2,7 +2,7 @@ import { type EventData, type EventDataUnion, type EventEnvelope, type EventUnio
2
2
  import { type ResourceId, type ResourceStreamRef } from '../../resources/index.js';
3
3
  import { type WorkItemId, type WorkItemStreamRef } from '../../work/index.js';
4
4
  import type { PullRequestActivityOutcome, PullRequestTarget } from '../pr/contracts.js';
5
- import type { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestState } from '../pr/vocabulary.js';
5
+ import type { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, PullRequestState } from '../pr/vocabulary.js';
6
6
  import type { ReviewActorKind } from '../review/contracts.js';
7
7
  import type { ActivationId } from './identifiers.js';
8
8
  import { type ActivityDecisionStreamRef, type PullRequestDecisionAction } from './streams.js';
@@ -27,6 +27,7 @@ export declare const ActivityEventType: {
27
27
  };
28
28
  export type ActivityEventTypes = typeof ActivityEventType;
29
29
  export interface PullRequestDiscoveredPayload {
30
+ readonly mergeability?: PullRequestMergeability | undefined;
30
31
  readonly workItemId: WorkItemId;
31
32
  readonly state: typeof PullRequestState.Open | typeof PullRequestState.Closed | typeof PullRequestState.Merged;
32
33
  readonly headRevision: string;
@@ -104,6 +105,7 @@ export interface ActivityEventPayloads {
104
105
  };
105
106
  readonly [ActivityEventType.PrStateChanged]: {
106
107
  readonly state: PullRequestDiscoveredPayload['state'];
108
+ readonly mergeability?: PullRequestMergeability | undefined;
107
109
  };
108
110
  readonly [ActivityEventType.PrChecksChanged]: {
109
111
  readonly checks: PullRequestDiscoveredPayload['checks'];
@@ -82,10 +82,13 @@ class JournalPullRequestService {
82
82
  return decidePullRequestAuthority(await this.authorityInput(workItemId), options);
83
83
  }
84
84
  async appendObservationChanges(current, command, context) {
85
- if (current.headRevision !== command.headRevision ||
86
- current.baseRevision !== command.baseRevision)
85
+ const revisionHasChanged = current.headRevision !== command.headRevision ||
86
+ current.baseRevision !== command.baseRevision;
87
+ if (revisionHasChanged)
87
88
  await this.append(command.resourceId, revisionChanged(command, context));
88
- if (current.state !== command.state)
89
+ if (current.state !== command.state ||
90
+ current.mergeability !== command.mergeability ||
91
+ (revisionHasChanged && command.mergeability !== undefined))
89
92
  await this.append(command.resourceId, stateChanged(command, context));
90
93
  if (current.checks !== command.checks)
91
94
  await this.append(command.resourceId, checksChanged(command, context));
@@ -3,7 +3,7 @@ import type { WorkItemId, WorkItemView } from '../../work/index.js';
3
3
  import type { ActivityFailureCode, ActivityOutcomeKind, ActivityResourceRole } from '../contracts/vocabulary.js';
4
4
  import type { ReviewActorKind, ReviewerAuthorizationEvidence } from '../review/contracts.js';
5
5
  import type { MergePolicyDetails } from './merge-policy-denial.js';
6
- import type { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestState } from './vocabulary.js';
6
+ import type { MergeMethod, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, PullRequestState } from './vocabulary.js';
7
7
  export interface PullRequestView {
8
8
  readonly resourceId: ResourceId;
9
9
  readonly workItemId: WorkItemId;
@@ -11,6 +11,7 @@ export interface PullRequestView {
11
11
  readonly headRevision: string;
12
12
  readonly baseRevision: string;
13
13
  readonly checks: PullRequestCheckState;
14
+ readonly mergeability?: PullRequestMergeability | undefined;
14
15
  readonly acceptedReview?: {
15
16
  readonly revision: string;
16
17
  readonly actorId: string;
@@ -25,6 +26,7 @@ export interface ObservePullRequest {
25
26
  readonly headRevision: string;
26
27
  readonly baseRevision: string;
27
28
  readonly checks: PullRequestView['checks'];
29
+ readonly mergeability?: PullRequestMergeability | undefined;
28
30
  readonly changedFiles?: readonly string[] | undefined;
29
31
  }
30
32
  export interface AcceptReviewSignal {
@@ -14,7 +14,10 @@ export const revisionChanged = (command, context) => fact({
14
14
  });
15
15
  export const stateChanged = (command, context) => fact({
16
16
  ...metadata(ActivityEventType.PrStateChanged, context),
17
- payload: { state: command.state },
17
+ payload: {
18
+ state: command.state,
19
+ ...(command.mergeability === undefined ? {} : { mergeability: command.mergeability }),
20
+ },
18
21
  });
19
22
  export const checksChanged = (command, context) => fact({
20
23
  ...metadata(ActivityEventType.PrChecksChanged, context),
@@ -44,6 +44,7 @@ function clearRevisionEvidence(view) {
44
44
  const copy = { ...view };
45
45
  delete copy.acceptedReview;
46
46
  delete copy.changedFiles;
47
+ delete copy.mergeability;
47
48
  return copy;
48
49
  }
49
50
  function projectPullRequest(previous, data, resourceId) {
@@ -53,7 +54,9 @@ function projectPullRequest(previous, data, resourceId) {
53
54
  case ActivityEventType.PrRevisionChanged:
54
55
  return previous === null ? previous : { ...clearRevisionEvidence(previous), ...data.payload };
55
56
  case ActivityEventType.PrStateChanged:
56
- return previous === null ? previous : { ...previous, state: data.payload.state };
57
+ return previous === null
58
+ ? previous
59
+ : { ...previous, state: data.payload.state, mergeability: data.payload.mergeability };
57
60
  case ActivityEventType.PrChecksChanged:
58
61
  return previous === null ? previous : { ...previous, checks: data.payload.checks };
59
62
  case ActivityEventType.PrReviewAccepted:
@@ -5,6 +5,12 @@ export declare const PullRequestState: {
5
5
  readonly Merged: "merged";
6
6
  };
7
7
  export type PullRequestState = ValueOf<typeof PullRequestState>;
8
+ export declare const PullRequestMergeability: {
9
+ readonly Unknown: "unknown";
10
+ readonly Mergeable: "clean";
11
+ readonly Conflicting: "conflicting";
12
+ };
13
+ export type PullRequestMergeability = ValueOf<typeof PullRequestMergeability>;
8
14
  export declare const PullRequestCheckState: {
9
15
  readonly Unknown: "unknown";
10
16
  readonly Pending: "pending";
@@ -4,6 +4,11 @@ export const PullRequestState = defineClosedVocabulary({
4
4
  Closed: 'closed',
5
5
  Merged: 'merged',
6
6
  });
7
+ export const PullRequestMergeability = defineClosedVocabulary({
8
+ Unknown: 'unknown',
9
+ Mergeable: 'clean',
10
+ Conflicting: 'conflicting',
11
+ });
7
12
  export const PullRequestCheckState = defineClosedVocabulary({
8
13
  Unknown: 'unknown',
9
14
  Pending: 'pending',
@@ -79,6 +79,15 @@ declare const orchestrationConfigSchema: z.ZodDefault<z.ZodObject<{
79
79
  }, z.core.$strict>>;
80
80
  }, z.core.$strict>]>>>;
81
81
  resourceTransitions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
82
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
83
+ where: z.ZodObject<{
84
+ mergeability: z.ZodLiteral<"conflicting">;
85
+ }, z.core.$strict>;
86
+ then: z.ZodString;
87
+ retry: z.ZodObject<{
88
+ max: z.ZodNumber;
89
+ }, z.core.$strict>;
90
+ }, z.core.$strict>, z.ZodObject<{
82
91
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
83
92
  then: z.ZodOptional<z.ZodString>;
84
93
  }, z.core.$strict>, z.ZodObject<{
@@ -226,6 +235,15 @@ export declare const rootConfigSchema: z.ZodObject<{
226
235
  }, z.core.$strict>>;
227
236
  }, z.core.$strict>]>>>;
228
237
  resourceTransitions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
238
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
239
+ where: z.ZodObject<{
240
+ mergeability: z.ZodLiteral<"conflicting">;
241
+ }, z.core.$strict>;
242
+ then: z.ZodString;
243
+ retry: z.ZodObject<{
244
+ max: z.ZodNumber;
245
+ }, z.core.$strict>;
246
+ }, z.core.$strict>, z.ZodObject<{
229
247
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
230
248
  then: z.ZodOptional<z.ZodString>;
231
249
  }, z.core.$strict>, z.ZodObject<{
@@ -1,27 +1,33 @@
1
1
  import { ResourceCorrelationRole } from '../resources/index.js';
2
2
  export function createCapabilityResourceTransitionEvidence(input) {
3
3
  const registrationFor = (capabilities) => input.policies.find((registration) => registration.capabilities.some((capability) => capabilities.includes(capability)));
4
+ const policyFor = async (workItemId) => {
5
+ const correlations = await input.resources.correlationsForWork(workItemId);
6
+ const primaries = correlations.filter(({ role }) => role === ResourceCorrelationRole.Primary);
7
+ const registrations = [];
8
+ for (const primary of primaries) {
9
+ const resource = await input.resources.get(primary.resourceId);
10
+ if (resource === null)
11
+ continue;
12
+ const registration = registrationFor(resource.capabilities);
13
+ if (registration !== undefined)
14
+ registrations.push(registration);
15
+ }
16
+ return registrations.length === 1 ? registrations[0].policy : null;
17
+ };
4
18
  return {
19
+ async mergeWaitState(workItemId) {
20
+ const policy = await policyFor(workItemId);
21
+ return (await policy?.mergeWaitState?.(workItemId)) ?? null;
22
+ },
5
23
  triggers: [...new Set(input.policies.flatMap(({ policy }) => policy.triggers))],
6
24
  async resolve(evidence) {
7
25
  // A work item may hold several primary correlations (e.g. its
8
26
  // originating issue and an implementation PR). Only the correlation
9
27
  // whose resource matches a registered policy's capabilities is
10
28
  // relevant here; the rest drop out rather than blocking resolution.
11
- const correlations = await input.resources.correlationsForWork(evidence.workItemId);
12
- const primaries = correlations.filter(({ role }) => role === ResourceCorrelationRole.Primary);
13
- const registrations = [];
14
- for (const primary of primaries) {
15
- const resource = await input.resources.get(primary.resourceId);
16
- if (resource === null)
17
- continue;
18
- const registration = registrationFor(resource.capabilities);
19
- if (registration !== undefined)
20
- registrations.push(registration);
21
- }
22
- if (registrations.length !== 1)
23
- return null;
24
- return registrations[0].policy.resolve(evidence);
29
+ const policy = await policyFor(evidence.workItemId);
30
+ return (await policy?.resolve(evidence)) ?? null;
25
31
  },
26
32
  };
27
33
  }
@@ -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.77";
127
+ export const wakeVersion = "v0.4.78";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -19,6 +19,7 @@ export declare class AgentRunPublicationReactor {
19
19
  react(outcome: NonNullable<ReturnType<typeof selectWorkflowOrchestrationEvent>>): Promise<void>;
20
20
  private publishAcceptedOutcome;
21
21
  private publish;
22
+ private publishMergeWait;
22
23
  private recordConversationEntry;
23
24
  private resourceForTarget;
24
25
  private stageForActivation;
@@ -2,13 +2,14 @@ import { defineEventProcessor, EventActorKind, EventProcessorCategory, EventProc
2
2
  import { BuiltInActivityName } from '../../activities/index.js';
3
3
  import { conversationIdForWorkItem, ConversationOriginKind, } from '../../conversations/index.js';
4
4
  import { RunStatus } from '../../execution/index.js';
5
- import { ApprovalAuthorityKind, isApprovalAwaitingSignalKind, OrchestrationEventType, OrchestrationStreamKind, selectWorkflowOrchestrationEvent, WatchGateVerdictSignal, } from '../../orchestration/index.js';
5
+ import { OrchestrationEventType, OrchestrationStreamKind, selectWorkflowOrchestrationEvent, } from '../../orchestration/index.js';
6
6
  import { BuiltInResourceKind, ResourceCorrelationRole, resourceStream, } from '../../resources/index.js';
7
7
  import { ReplyTarget } from '../contracts/reply-routing.js';
8
8
  import { createDeliveryIntentEventData } from '../delivery/contracts/event-factory.js';
9
9
  import { DeliveryIntentEventType } from '../delivery/contracts/intents.js';
10
10
  import { defaultReplyPublication, selectReplyTarget, } from '../github/application/reply-target-selector.js';
11
11
  import { projectTerminalAgentRunReport } from './terminal-agent-run-report.js';
12
+ import { agentRunReportInput, mergeWaitComment } from './agent-run-publication-report.js';
12
13
  /** Projects terminal agent runs into one durable outbound intent per configured resource. */
13
14
  export class AgentRunPublicationReactor {
14
15
  dependencies;
@@ -24,7 +25,8 @@ export class AgentRunPublicationReactor {
24
25
  select(event) {
25
26
  const outcome = selectWorkflowOrchestrationEvent(event);
26
27
  return outcome?.event.eventType === OrchestrationEventType.ActivityOutcomeAccepted ||
27
- outcome?.event.eventType === OrchestrationEventType.ActivityExecutionFailed
28
+ outcome?.event.eventType === OrchestrationEventType.ActivityExecutionFailed ||
29
+ outcome?.event.eventType === OrchestrationEventType.SignalWaitStarted
28
30
  ? outcome
29
31
  : null;
30
32
  },
@@ -32,6 +34,10 @@ export class AgentRunPublicationReactor {
32
34
  });
33
35
  }
34
36
  async react(outcome) {
37
+ if (outcome.event.eventType === OrchestrationEventType.SignalWaitStarted) {
38
+ await this.publishMergeWait(outcome);
39
+ return;
40
+ }
35
41
  if (outcome.event.eventType === OrchestrationEventType.ActivityOutcomeAccepted) {
36
42
  await this.publishAcceptedOutcome(outcome.stream.id, outcome.event.payload.activationId, outcome.recordedAt, outcome.event.eventId, outcome.event.correlationId);
37
43
  return;
@@ -57,7 +63,7 @@ export class AgentRunPublicationReactor {
57
63
  if (workflow === undefined)
58
64
  return;
59
65
  const stage = await this.stageForActivation(workflow.workflowInstanceId, run.activationId);
60
- const report = projectTerminalAgentRunReport(reportInput(run, stage, workflow, allWorkflows));
66
+ const report = projectTerminalAgentRunReport(agentRunReportInput(run, stage, workflow, allWorkflows));
61
67
  if (report === null)
62
68
  return;
63
69
  await this.recordConversationEntry(workflow.workItemId, run.runId, report.displayBody, stage, occurredAt, correlationId);
@@ -99,6 +105,46 @@ export class AgentRunPublicationReactor {
99
105
  /* idempotency is the deterministic run event id */
100
106
  }
101
107
  }
108
+ async publishMergeWait(event) {
109
+ const workflow = (await this.dependencies.orchestration.listAll()).find((view) => view.workflowInstanceId === event.stream.id);
110
+ const body = mergeWaitComment(workflow);
111
+ if (workflow?.pendingActivation === undefined || body === undefined)
112
+ return;
113
+ // A replayed older wait event must not publish guidance for a newer wait.
114
+ if (event.event.eventType === OrchestrationEventType.SignalWaitStarted &&
115
+ event.event.payload.signalKind !== workflow.waitingFor?.signalKind)
116
+ return;
117
+ const replies = this.dependencies.replies ?? defaultReplyPublication;
118
+ const target = selectReplyTarget({ stage: workflow.currentStage, outcome: 'DONE' }, replies.rules, replies.default);
119
+ if (target === ReplyTarget.None)
120
+ return;
121
+ const resource = await this.resourceForTarget(workflow.workItemId, target);
122
+ if (resource === undefined)
123
+ return;
124
+ const stream = resourceStream(resource.resourceId);
125
+ const facts = await this.dependencies.journal.readStream(stream);
126
+ const eventId = `merge-wait:${event.event.eventId}`;
127
+ if (facts.some((fact) => fact.event.eventId === eventId))
128
+ return;
129
+ await this.dependencies.journal.appendToStream(stream, facts.length, [
130
+ createDeliveryIntentEventData({
131
+ eventId,
132
+ eventType: DeliveryIntentEventType.ReplyPublishRequested,
133
+ occurredAt: event.recordedAt,
134
+ correlationId: event.event.correlationId,
135
+ causationId: event.event.eventId,
136
+ actor: { kind: EventActorKind.Integration, id: 'agent-run-publication' },
137
+ source: { kind: EventSourceKind.Internal, id: 'agent-run-publication' },
138
+ payload: {
139
+ workflowInstanceId: workflow.workflowInstanceId,
140
+ activationId: workflow.pendingActivation.activationId,
141
+ resourceId: resource.resourceId,
142
+ body,
143
+ publicationOnly: true,
144
+ },
145
+ }),
146
+ ]);
147
+ }
102
148
  async recordConversationEntry(workItemId, runId, body, stage, occurredAt, correlationId) {
103
149
  const conversations = this.dependencies.conversations;
104
150
  if (conversations === undefined)
@@ -153,25 +199,3 @@ export class AgentRunPublicationReactor {
153
199
  return undefined;
154
200
  }
155
201
  }
156
- function reportInput(run, stage, workflow, allWorkflows) {
157
- const watchGateVerdict = watchGateVerdictFor(run, workflow, allWorkflows);
158
- const isWaiting = workflow.waitingFor !== undefined &&
159
- isApprovalAwaitingSignalKind(workflow.waitingFor.signalKind);
160
- return {
161
- run,
162
- ...(stage === undefined ? {} : { stage }),
163
- ...(isWaiting ? { awaitingApproval: true } : {}),
164
- ...(watchGateVerdict === undefined ? {} : { watchGateVerdict }),
165
- };
166
- }
167
- function watchGateVerdictFor(run, workflow, allWorkflows) {
168
- if (run.agent?.outcome !== 'DONE' && run.agent?.outcome !== 'REJECTED')
169
- return undefined;
170
- if (workflow.parentWorkflowInstanceId === undefined || workflow.watchId === undefined)
171
- return undefined;
172
- const parent = allWorkflows.find((value) => value.workflowInstanceId === workflow.parentWorkflowInstanceId);
173
- if (parent?.waitingFor?.signalKind !== WatchGateVerdictSignal)
174
- return undefined;
175
- const namesThisWatch = parent.waitingFor.from?.some((entry) => entry.kind === ApprovalAuthorityKind.Watch && entry.watch === workflow.watchId);
176
- return namesThisWatch === true ? { runId: run.runId } : undefined;
177
- }
@@ -0,0 +1,10 @@
1
+ import { type WorkflowInstanceView } from '../../orchestration/index.js';
2
+ import { type projectTerminalAgentRunReport, type TerminalRun } from './terminal-agent-run-report.js';
3
+ /** The comment to post when a merge stage starts waiting, or undefined when no hint applies. */
4
+ export declare function mergeWaitComment(workflow: WorkflowInstanceView | undefined): string | undefined;
5
+ export declare function agentRunReportInput(run: TerminalRun, stage: string | undefined, workflow: WorkflowInstanceView, allWorkflows: readonly WorkflowInstanceView[]): Parameters<typeof projectTerminalAgentRunReport>[0];
6
+ export declare function isMergePublicationWait(workflow: WorkflowInstanceView | undefined): workflow is WorkflowInstanceView & {
7
+ readonly pendingActivation: NonNullable<WorkflowInstanceView['pendingActivation']>;
8
+ };
9
+ /** An approved wait at the merge stage is resumed by /approved. */
10
+ export declare function isMergeStageApproval(workflow: WorkflowInstanceView): boolean;
@@ -0,0 +1,53 @@
1
+ import { BuiltInActivityName } from '../../activities/index.js';
2
+ import { ApprovalAuthorityKind, ApprovedSignal, isApprovalAwaitingSignalKind, isPolicyBlockedMergeWait, ResourceTransitionSignal, WatchGateVerdictSignal, WorkflowStatus, } from '../../orchestration/index.js';
3
+ import { MergeStageApprovalGuidance, MergeWaitGuidance, } from './terminal-agent-run-report.js';
4
+ /** The comment to post when a merge stage starts waiting, or undefined when no hint applies. */
5
+ export function mergeWaitComment(workflow) {
6
+ if (workflow === undefined)
7
+ return undefined;
8
+ if (isMergePublicationWait(workflow))
9
+ return `**Wake: Awaiting merge**\n\n${MergeWaitGuidance}`;
10
+ const waiting = workflow.status === WorkflowStatus.Waiting && workflow.parentWorkflowInstanceId === undefined;
11
+ return waiting && isMergeStageApproval(workflow)
12
+ ? `**Wake: Awaiting approval**\n\n${MergeStageApprovalGuidance}`
13
+ : undefined;
14
+ }
15
+ export function agentRunReportInput(run, stage, workflow, allWorkflows) {
16
+ const watchGateVerdict = watchGateVerdictFor(run, workflow, allWorkflows);
17
+ const isWaiting = workflow.waitingFor !== undefined &&
18
+ isApprovalAwaitingSignalKind(workflow.waitingFor.signalKind);
19
+ const isMergeWait = isMergePublicationWait(workflow);
20
+ return {
21
+ run,
22
+ ...(stage === undefined ? {} : { stage }),
23
+ ...(isWaiting ? { awaitingApproval: true } : {}),
24
+ ...(isMergeWait ? { awaitingMerge: true } : {}),
25
+ ...(isMergeStageApproval(workflow) ? { mergeStageApproval: true } : {}),
26
+ ...(watchGateVerdict === undefined ? {} : { watchGateVerdict }),
27
+ };
28
+ }
29
+ export function isMergePublicationWait(workflow) {
30
+ return (workflow?.status === WorkflowStatus.Waiting &&
31
+ workflow.parentWorkflowInstanceId === undefined &&
32
+ workflow.waitingFor !== undefined &&
33
+ workflow.waitingFor.intentEventId === undefined &&
34
+ workflow.pendingActivation?.activity === BuiltInActivityName.PullRequestMerge &&
35
+ (workflow.waitingFor.signalKind === ResourceTransitionSignal ||
36
+ isPolicyBlockedMergeWait(workflow)));
37
+ }
38
+ /** An approved wait at the merge stage is resumed by /approved. */
39
+ export function isMergeStageApproval(workflow) {
40
+ return (workflow.waitingFor?.signalKind === ApprovedSignal &&
41
+ workflow.pendingActivation?.activity === BuiltInActivityName.PullRequestMerge);
42
+ }
43
+ function watchGateVerdictFor(run, workflow, allWorkflows) {
44
+ if (run.agent?.outcome !== 'DONE' && run.agent?.outcome !== 'REJECTED')
45
+ return undefined;
46
+ if (workflow.parentWorkflowInstanceId === undefined || workflow.watchId === undefined)
47
+ return undefined;
48
+ const parent = allWorkflows.find((value) => value.workflowInstanceId === workflow.parentWorkflowInstanceId);
49
+ if (parent?.waitingFor?.signalKind !== WatchGateVerdictSignal)
50
+ return undefined;
51
+ const namesThisWatch = parent.waitingFor.from?.some((entry) => entry.kind === ApprovalAuthorityKind.Watch && entry.watch === workflow.watchId);
52
+ return namesThisWatch === true ? { runId: run.runId } : undefined;
53
+ }
@@ -1,4 +1,6 @@
1
1
  import type { AgentRunPublicationReport } from '../delivery/contracts/intents.js';
2
+ export declare const MergeWaitGuidance = "Wake is waiting for the primary pull request to merge. Resolve and merge it in the provider; explicit conflicts use the pinned workflow repair policy, and closed unmerged pull requests block the work.";
3
+ export declare const MergeStageApprovalGuidance = "An authorized independent reviewer can reply with /approved to continue. Approval of your own work is not permitted.";
2
4
  export interface TerminalRunAgentResult {
3
5
  readonly outcome: 'DONE' | 'REJECTED' | 'BLOCKED' | 'FAILED' | 'NEEDS_CLARIFICATION';
4
6
  readonly displayBody: string;
@@ -27,6 +29,8 @@ export declare function projectTerminalAgentRunReport(input: {
27
29
  readonly run: TerminalRun;
28
30
  readonly stage?: string;
29
31
  readonly awaitingApproval?: boolean;
32
+ readonly awaitingMerge?: boolean;
33
+ readonly mergeStageApproval?: boolean;
30
34
  readonly watchGateVerdict?: {
31
35
  readonly runId: string;
32
36
  };
@@ -1,3 +1,5 @@
1
+ export const MergeWaitGuidance = 'Wake is waiting for the primary pull request to merge. Resolve and merge it in the provider; explicit conflicts use the pinned workflow repair policy, and closed unmerged pull requests block the work.';
2
+ export const MergeStageApprovalGuidance = 'An authorized independent reviewer can reply with /approved to continue. Approval of your own work is not permitted.';
1
3
  export function projectTerminalAgentRunReport(input) {
2
4
  if (input.run.finishedAt === undefined)
3
5
  return null;
@@ -14,6 +16,8 @@ export function projectTerminalAgentRunReport(input) {
14
16
  ...(input.run.workspace === undefined ? {} : { workspacePath: input.run.workspace.path }),
15
17
  metadata: agent?.metadata ?? {},
16
18
  ...(input.awaitingApproval === true ? { awaitingApproval: true } : {}),
19
+ ...(input.awaitingMerge === true ? { awaitingMerge: true } : {}),
20
+ ...(input.mergeStageApproval === true ? { mergeStageApproval: true } : {}),
17
21
  ...(input.watchGateVerdict === undefined ? {} : { watchGateVerdict: input.watchGateVerdict }),
18
22
  };
19
23
  }
@@ -30,6 +30,8 @@ export interface AgentRunPublicationReport {
30
30
  readonly workspacePath?: string | undefined;
31
31
  readonly metadata: Readonly<Record<string, string | number | boolean | null>>;
32
32
  readonly awaitingApproval?: boolean | undefined;
33
+ readonly awaitingMerge?: boolean | undefined;
34
+ readonly mergeStageApproval?: boolean | undefined;
33
35
  readonly watchGateVerdict?: {
34
36
  readonly runId: string;
35
37
  } | undefined;
@@ -35,6 +35,8 @@ const reportSchema = z
35
35
  workspacePath: z.string().min(1).optional(),
36
36
  metadata: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()])),
37
37
  awaitingApproval: z.boolean().optional(),
38
+ awaitingMerge: z.boolean().optional(),
39
+ mergeStageApproval: z.boolean().optional(),
38
40
  watchGateVerdict: z
39
41
  .object({ runId: z.string().min(1) })
40
42
  .strict()
@@ -14,6 +14,8 @@ export interface AgentRunComment {
14
14
  readonly sessionId?: string | undefined;
15
15
  readonly workspacePath?: string | undefined;
16
16
  readonly awaitingApproval?: boolean | undefined;
17
+ readonly awaitingMerge?: boolean | undefined;
18
+ readonly mergeStageApproval?: boolean | undefined;
17
19
  readonly watchGateVerdict?: {
18
20
  readonly runId: string;
19
21
  } | undefined;
@@ -1,19 +1,31 @@
1
+ import { MergeStageApprovalGuidance, MergeWaitGuidance, } from '../../application/terminal-agent-run-report.js';
2
+ /** Names only the commands the current wait accepts. */
3
+ function waitHintFor(value) {
4
+ if (value.awaitingMerge === true)
5
+ return `_${MergeWaitGuidance}_`;
6
+ if (value.awaitingApproval !== true)
7
+ return undefined;
8
+ if (value.mergeStageApproval === true)
9
+ return `_${MergeStageApprovalGuidance}_`;
10
+ return '_An authorized independent reviewer can reply with /approved or /changes followed by feedback. Approval of your own work is not permitted. To ask a question, reply with /ask followed by your question._';
11
+ }
1
12
  export function formatAgentRunComment(value) {
2
13
  const details = detailsLine(value);
3
14
  const sections = [
4
15
  '<!-- wake:agent -->',
5
16
  `<!-- wake:delivery:${value.idempotencyKey} -->`,
6
17
  `**${wakeHeading(value.publicUiUrl)}** _(Wake${details ? ` - ${details}` : ''})_`,
7
- `**Outcome:** ${value.awaitingApproval === true ? '⏳ Awaiting approval' : outcome(value.outcome)}`,
18
+ `**Outcome:** ${commentOutcome(value)}`,
8
19
  value.displayBody.trim() || fallback(value.outcome),
9
20
  ];
10
- if (value.awaitingApproval === true)
11
- sections.push('_An authorized independent reviewer can reply with /approved or /changes followed by feedback. Approval of your own work is not permitted. To ask a question, reply with /ask followed by your question._');
12
- if (value.outcome === 'BLOCKED' || value.outcome === 'NEEDS_CLARIFICATION')
21
+ const waitHint = waitHintFor(value);
22
+ if (waitHint !== undefined)
23
+ sections.push(waitHint);
24
+ if (hasContinuationHint(value))
13
25
  sections.push(value.outcome === 'NEEDS_CLARIFICATION'
14
26
  ? '_Reply with the requested clarification. A maintainer with repository write, maintain, or admin permission can also use /changes followed by instructions to continue eligible blocked work._'
15
27
  : '_A maintainer with repository write, maintain, or admin permission can continue eligible blocked work with /changes followed by instructions, including on an issue they authored. The authenticated UI also offers Continue with instructions. /retry is for eligible failed stages._');
16
- if (value.outcome === 'FAILED')
28
+ if (value.outcome === 'FAILED' && value.awaitingMerge !== true)
17
29
  sections.push('_An authorized maintainer can use /retry for an eligible failed stage, or /restart for a fresh session. These commands do not continue a blocked outcome._');
18
30
  const session = sessionSection(value);
19
31
  if (session !== undefined)
@@ -95,3 +107,12 @@ function cost(metadata) {
95
107
  function formatDuration(value) {
96
108
  return `${Math.max(0, Math.round(value / 1000))}s`;
97
109
  }
110
+ function commentOutcome(value) {
111
+ if (value.awaitingMerge === true)
112
+ return '⏳ Awaiting merge';
113
+ return value.awaitingApproval === true ? '⏳ Awaiting approval' : outcome(value.outcome);
114
+ }
115
+ function hasContinuationHint(value) {
116
+ return (value.awaitingMerge !== true &&
117
+ (value.outcome === 'BLOCKED' || value.outcome === 'NEEDS_CLARIFICATION'));
118
+ }
@@ -3,6 +3,7 @@ export function observePullRequest(resourceId, workItemId, payload) {
3
3
  resourceId,
4
4
  workItemId,
5
5
  state: payload.state,
6
+ ...(payload.mergeability === undefined ? {} : { mergeability: payload.mergeability }),
6
7
  headRevision: payload.headRevision ?? payload.revision,
7
8
  baseRevision: payload.baseRevision ?? 'unknown',
8
9
  checks: payload.checks ?? 'unknown',