@atolis-hq/wake 0.4.76 → 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 (67) 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/composition-root.js +1 -0
  11. package/dist/src/bootstrap/config/root-schema.d.ts +19 -0
  12. package/dist/src/bootstrap/initialise.js +1 -0
  13. package/dist/src/bootstrap/integration-runtime.js +8 -1
  14. package/dist/src/bootstrap/resource-transition-evidence.js +20 -14
  15. package/dist/src/bootstrap/version.js +1 -1
  16. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +1 -0
  17. package/dist/src/control-plane/application/activation-scheduler.js +4 -0
  18. package/dist/src/control-plane/application/advance-once-dispatch.d.ts +5 -0
  19. package/dist/src/control-plane/application/advance-once-dispatch.js +11 -1
  20. package/dist/src/control-plane/contracts/config.d.ts +2 -0
  21. package/dist/src/control-plane/contracts/config.js +2 -0
  22. package/dist/src/control-plane/domain/open-work-policy.d.ts +12 -0
  23. package/dist/src/control-plane/domain/open-work-policy.js +35 -0
  24. package/dist/src/control-plane/index.d.ts +1 -0
  25. package/dist/src/control-plane/index.js +1 -0
  26. package/dist/src/integrations/application/agent-run-publication-reactor.d.ts +1 -0
  27. package/dist/src/integrations/application/agent-run-publication-reactor.js +49 -25
  28. package/dist/src/integrations/application/agent-run-publication-report.d.ts +10 -0
  29. package/dist/src/integrations/application/agent-run-publication-report.js +53 -0
  30. package/dist/src/integrations/application/terminal-agent-run-report.d.ts +4 -0
  31. package/dist/src/integrations/application/terminal-agent-run-report.js +4 -0
  32. package/dist/src/integrations/delivery/contracts/intents.d.ts +2 -0
  33. package/dist/src/integrations/delivery/contracts/intents.js +2 -0
  34. package/dist/src/integrations/github/application/agent-run-comment.d.ts +2 -0
  35. package/dist/src/integrations/github/application/agent-run-comment.js +26 -5
  36. package/dist/src/integrations/github/application/pull-request-translation.js +1 -0
  37. package/dist/src/integrations/github/contracts/events.d.ts +2 -1
  38. package/dist/src/integrations/github/contracts/events.js +8 -1
  39. package/dist/src/integrations/github/contracts/payloads.d.ts +1 -0
  40. package/dist/src/integrations/github/infrastructure/client-reads.d.ts +18 -6
  41. package/dist/src/integrations/github/infrastructure/client-reads.js +6 -1
  42. package/dist/src/integrations/github/infrastructure/client.d.ts +18 -6
  43. package/dist/src/integrations/github/infrastructure/consecutive-pr-observations.d.ts +4 -0
  44. package/dist/src/integrations/github/infrastructure/consecutive-pr-observations.js +33 -0
  45. package/dist/src/integrations/github/infrastructure/pr-source.js +6 -1
  46. package/dist/src/integrations/github/infrastructure/source.d.ts +6 -2
  47. package/dist/src/integrations/github/infrastructure/source.js +9 -9
  48. package/dist/src/integrations/github/provider.js +1 -0
  49. package/dist/src/orchestration/application/advance-workflow.js +1 -0
  50. package/dist/src/orchestration/application/policy-blocked-merge-recovery.d.ts +5 -0
  51. package/dist/src/orchestration/application/policy-blocked-merge-recovery.js +108 -21
  52. package/dist/src/orchestration/application/pull-request-transition-evidence.js +22 -1
  53. package/dist/src/orchestration/application/resource-transition-evidence.d.ts +6 -1
  54. package/dist/src/orchestration/application/resource-transition-matching.d.ts +5 -0
  55. package/dist/src/orchestration/application/resource-transition-matching.js +23 -1
  56. package/dist/src/orchestration/contracts/config.d.ts +42 -1
  57. package/dist/src/orchestration/contracts/config.js +9 -1
  58. package/dist/src/orchestration/contracts/event-decoder.d.ts +5 -0
  59. package/dist/src/orchestration/contracts/event-decoder.js +6 -1
  60. package/dist/src/orchestration/contracts/views.d.ts +2 -0
  61. package/dist/src/orchestration/domain/resource-transition-compiler.js +1 -0
  62. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  63. package/dist/src/orchestration/domain/workflow-instance-events.js +2 -0
  64. package/dist/src/orchestration/domain/workflow-instance.js +9 -1
  65. package/dist/src/orchestration/index.d.ts +1 -0
  66. package/dist/src/orchestration/index.js +1 -0
  67. package/package.json +1 -1
@@ -203,6 +203,7 @@ export class AdvanceWorkflow {
203
203
  (signalKind === undefined || view.waitingFor?.signalKind === signalKind))
204
204
  .map(({ view }) => view);
205
205
  }
206
+ // Scheduler reads replayed journal facts, never potentially stale stored projections.
206
207
  async listAll() {
207
208
  return (await this.listAllLoaded()).map(({ view }) => view);
208
209
  }
@@ -5,3 +5,8 @@ import type { ResourceTransitionEvidence } from './resource-transition-evidence.
5
5
  import type { StartWorkflow } from './start-workflow.js';
6
6
  export declare function recoverPolicyBlockedMerges(repository: OrchestrationRepository, workflows: StartWorkflow, evidence: ResourceTransitionEvidence, context: CommandContext): Promise<void>;
7
7
  export declare function isPolicyBlockedMergeWait(view: WorkflowInstanceView): boolean;
8
+ export declare const MergeWaitBlockReason: {
9
+ readonly Closed: "merge.pr-closed-unmerged: primary PR was closed without merging; restore the PR and resolve the workflow explicitly";
10
+ readonly Conflict: "merge.pr-conflicting: primary PR conflicts with its base; no safe bounded repair route in the pinned workflow";
11
+ readonly Exhausted: "merge.conflict-retry-exhausted: bounded conflict repair exhausted; resolve the PR and workflow explicitly";
12
+ };
@@ -1,39 +1,26 @@
1
- import { ActivityEventType, ActivityOutcomeKind, BuiltInActivityName, PullRequestState, readMergePolicyDenial, } from '../../activities/index.js';
1
+ import { ActivityEventType, ActivityOutcomeKind, BuiltInActivityName, PullRequestMergeability, PullRequestState, readMergePolicyDenial, } from '../../activities/index.js';
2
+ import { OrchestrationEventType, ResourceTransitionSignal, WatchGateVerdictSignal, } from '../contracts/events.js';
2
3
  import { TransitionTargetKind, WorkflowStatus } from '../contracts/vocabulary.js';
4
+ import { stateDraft } from '../domain/decision-events.js';
3
5
  import { acceptResourceTransition } from './resource-transition-matching.js';
4
6
  export async function recoverPolicyBlockedMerges(repository, workflows, evidence, context) {
5
7
  for (const loaded of await repository.list()) {
6
8
  const view = loaded.view;
7
- if (view === null || !isPolicyBlockedMergeWait(view))
9
+ if (view === null || !isMergeWait(view))
8
10
  continue;
9
11
  const definition = await workflows.definitionForOperation(view, loaded.sequence, context);
10
12
  if (definition === null)
11
13
  continue;
12
14
  const stage = definition.stages[view.currentStage];
13
- if (!isBlockedRouteWait(stage, view))
15
+ if (stage === undefined || !isConfiguredMergeWait(stage, view))
14
16
  continue;
15
- // The pinned definition supplies the completion destination, never current config.
16
- const transitions = mergedTransitions(stage);
17
- const activationId = view.acceptedOutcomes.at(-1);
18
- if (transitions === undefined || transitions.length !== 1 || activationId === undefined)
17
+ if (await reconcileMergeProblem(repository, workflows, evidence, loaded, definition, context))
19
18
  continue;
20
- const resolved = await evidence.resolve({
21
- workItemId: view.workItemId,
22
- transitions,
23
- mergeDenialActivationId: activationId,
24
- });
25
- if (resolved === null)
26
- continue;
27
- await acceptResourceTransition(repository, workflows, view.workflowInstanceId, resolved.transition.target, resolved.evidenceId, { ...context, expectedSequence: loaded.sequence });
19
+ await recoverMergedPolicyWait(repository, workflows, evidence, loaded, stage, context);
28
20
  }
29
21
  }
30
22
  export function isPolicyBlockedMergeWait(view) {
31
- return (view.status === WorkflowStatus.Waiting &&
32
- view.parentWorkflowInstanceId === undefined &&
33
- view.waitingFor !== undefined &&
34
- view.waitingFor.intentEventId === undefined &&
35
- view.pendingActivation?.activity === BuiltInActivityName.PullRequestMerge &&
36
- readMergePolicyDenial(view.lastOutcome) !== null);
23
+ return isMergeWait(view) && readMergePolicyDenial(view.lastOutcome) !== null;
37
24
  }
38
25
  function isBlockedRouteWait(stage, view) {
39
26
  const blocked = stage?.on[ActivityOutcomeKind.Blocked];
@@ -52,3 +39,103 @@ function isMergedTransition(transition) {
52
39
  function mergedTransitions(stage) {
53
40
  return stage?.on[ActivityOutcomeKind.Done]?.resourceTransitions?.filter(isMergedTransition);
54
41
  }
42
+ export const MergeWaitBlockReason = {
43
+ Closed: 'merge.pr-closed-unmerged: primary PR was closed without merging; restore the PR and resolve the workflow explicitly',
44
+ Conflict: 'merge.pr-conflicting: primary PR conflicts with its base; no safe bounded repair route in the pinned workflow',
45
+ Exhausted: 'merge.conflict-retry-exhausted: bounded conflict repair exhausted; resolve the PR and workflow explicitly',
46
+ };
47
+ async function reconcileMergeProblem(repository, workflows, evidence, loaded, definition, context) {
48
+ const view = loaded.view;
49
+ const observed = await evidence.mergeWaitState?.(view.workItemId);
50
+ if (observed === undefined || observed === null || observed.state === PullRequestState.Merged)
51
+ return false;
52
+ if (observed.state === PullRequestState.Closed) {
53
+ await blockMergeWait(repository, loaded, MergeWaitBlockReason.Closed, context);
54
+ return true;
55
+ }
56
+ if (observed.mergeability !== PullRequestMergeability.Conflicting)
57
+ return false;
58
+ const route = safeConflictRoute(definition.stages[view.currentStage], definition, view);
59
+ if (route === undefined) {
60
+ await blockMergeWait(repository, loaded, MergeWaitBlockReason.Conflict, context);
61
+ return true;
62
+ }
63
+ await acceptResourceTransition(repository, workflows, view.workflowInstanceId, route.target, `${observed.evidenceId}:${view.pendingActivation?.activationId}`, {
64
+ ...context,
65
+ expectedSequence: loaded.sequence,
66
+ retry: {
67
+ key: `${BuiltInActivityName.PullRequestMerge}:${PullRequestMergeability.Conflicting}`,
68
+ max: route.retry.max,
69
+ exhaustedReason: MergeWaitBlockReason.Exhausted,
70
+ },
71
+ });
72
+ return true;
73
+ }
74
+ async function blockMergeWait(repository, loaded, reason, context) {
75
+ const view = loaded.view;
76
+ await repository.append(view.workflowInstanceId, loaded.sequence, [
77
+ stateDraft(view, {
78
+ occurredAt: context.occurredAt,
79
+ causationId: `${context.commandId}:${view.workflowInstanceId}`,
80
+ }, { eventType: OrchestrationEventType.InstanceBlocked, payload: { reason } }, 1),
81
+ ]);
82
+ }
83
+ function isMergeWait(view) {
84
+ return (view.status === WorkflowStatus.Waiting &&
85
+ view.parentWorkflowInstanceId === undefined &&
86
+ view.pendingActivation?.activity === BuiltInActivityName.PullRequestMerge &&
87
+ view.pendingActivation.supplemental !== true &&
88
+ view.waitingFor !== undefined &&
89
+ view.waitingFor.intentEventId === undefined);
90
+ }
91
+ function isConfiguredMergeWait(stage, view) {
92
+ if (stage?.activity !== BuiltInActivityName.PullRequestMerge || view.lastOutcome === undefined)
93
+ return false;
94
+ const route = stage.on[view.lastOutcome.kind];
95
+ return route !== undefined && configuredWaitSignal(route) === view.waitingFor?.signalKind;
96
+ }
97
+ function configuredWaitSignal(route) {
98
+ if (route.watchGates !== undefined)
99
+ return WatchGateVerdictSignal;
100
+ if (route.resourceTransitions !== undefined)
101
+ return ResourceTransitionSignal;
102
+ if (route.await !== undefined)
103
+ return route.await.signal;
104
+ return route.target.kind === TransitionTargetKind.AwaitSignal ? route.target.signal : undefined;
105
+ }
106
+ function safeConflictRoute(stage, definition, view) {
107
+ const routes = stage.on[ActivityOutcomeKind.Done]?.resourceTransitions?.filter(isConflictTransition) ?? [];
108
+ const route = routes.length === 1 ? routes[0] : undefined;
109
+ if (route?.retry === undefined ||
110
+ route.retry.max > 2 ||
111
+ route.target.kind !== TransitionTargetKind.Stage)
112
+ return undefined;
113
+ if (route.target.stage === view.currentStage ||
114
+ definition.stages[route.target.stage]?.activity !== BuiltInActivityName.Agent)
115
+ return undefined;
116
+ return route;
117
+ }
118
+ function isConflictTransition(transition) {
119
+ return (transition.event === ActivityEventType.PrStateChanged &&
120
+ transition.where !== undefined &&
121
+ 'mergeability' in transition.where &&
122
+ transition.where.mergeability === PullRequestMergeability.Conflicting);
123
+ }
124
+ async function recoverMergedPolicyWait(repository, workflows, evidence, loaded, stage, context) {
125
+ const view = loaded.view;
126
+ if (!isPolicyBlockedMergeWait(view) || !isBlockedRouteWait(stage, view))
127
+ return;
128
+ // The pinned definition supplies the completion destination, never current config.
129
+ const transitions = mergedTransitions(stage);
130
+ const activationId = view.acceptedOutcomes.at(-1);
131
+ if (transitions === undefined || transitions.length !== 1 || activationId === undefined)
132
+ return;
133
+ const resolved = await evidence.resolve({
134
+ workItemId: view.workItemId,
135
+ transitions,
136
+ mergeDenialActivationId: activationId,
137
+ });
138
+ if (resolved === null)
139
+ return;
140
+ await acceptResourceTransition(repository, workflows, view.workflowInstanceId, resolved.transition.target, resolved.evidenceId, { ...context, expectedSequence: loaded.sequence });
141
+ }
@@ -1,4 +1,4 @@
1
- import { ActivityEventType, ActivityResourceRole, decidePullRequestAuthority, PullRequestCheckState, PullRequestDenialCode, PullRequestState, selectActivityEvent, selectPrimaryPullRequest, } from '../../activities/index.js';
1
+ import { ActivityEventType, ActivityResourceRole, decidePullRequestAuthority, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, pullRequestProjection, PullRequestState, selectActivityEvent, selectPrimaryPullRequest, } from '../../activities/index.js';
2
2
  const triggers = [
3
3
  ActivityEventType.PrReviewAccepted,
4
4
  ActivityEventType.PrStateChanged,
@@ -7,6 +7,27 @@ const triggers = [
7
7
  export function createPullRequestTransitionEvidence(pullRequests) {
8
8
  return {
9
9
  triggers,
10
+ async mergeWaitState(workItemId) {
11
+ const selected = selectPrimaryPullRequest(await pullRequests.authorityInput(workItemId), workItemId);
12
+ if (selected === null)
13
+ return null;
14
+ const resourceId = selected.pullRequest.resourceId;
15
+ const facts = await pullRequests.factsFor(resourceId);
16
+ const pr = facts.reduce((view, event) => pullRequestProjection.project(view, event), pullRequestProjection.initial(resourceId));
17
+ if (pr === null)
18
+ return null;
19
+ const fact = [...facts]
20
+ .reverse()
21
+ .find((entry) => entry.event.eventType === ActivityEventType.PrStateChanged ||
22
+ entry.event.eventType === ActivityEventType.PrDiscovered);
23
+ if (fact === undefined)
24
+ return null;
25
+ return {
26
+ state: pr.state,
27
+ mergeability: pr.mergeability ?? PullRequestMergeability.Unknown,
28
+ evidenceId: fact.event.eventId,
29
+ };
30
+ },
10
31
  async resolve({ workItemId, transitions, fact, mergeDenialActivationId, }) {
11
32
  const input = await pullRequests.authorityInput(workItemId);
12
33
  const selected = selectPrimaryPullRequest(input, workItemId);
@@ -1,4 +1,4 @@
1
- import type { selectActivityEvent } from '../../activities/index.js';
1
+ import type { PullRequestMergeability, PullRequestState, selectActivityEvent } from '../../activities/index.js';
2
2
  import type { WorkItemId } from '../../work/index.js';
3
3
  import type { CompiledResourceTransition } from '../contracts/config.js';
4
4
  export type ResourceTransitionFact = Parameters<typeof selectActivityEvent>[0];
@@ -14,6 +14,11 @@ export interface ResourceTransitionEvidenceResolution {
14
14
  readonly evidenceId: string;
15
15
  }
16
16
  export interface ResourceTransitionEvidence {
17
+ mergeWaitState?(workItemId: WorkItemId): Promise<{
18
+ readonly state: PullRequestState;
19
+ readonly mergeability: PullRequestMergeability;
20
+ readonly evidenceId: string;
21
+ } | null>;
17
22
  /** Fact types the reactor tails on this policy's behalf. */
18
23
  readonly triggers: readonly string[];
19
24
  resolve(input: ResourceTransitionEvidenceInput): Promise<ResourceTransitionEvidenceResolution | null>;
@@ -17,5 +17,10 @@ export declare function matchResourceTransitions(loaded: readonly {
17
17
  }[], event: PersistedEvent): Promise<readonly ResourceTransitionMatch[]>;
18
18
  export declare function acceptResourceTransition(repository: OrchestrationRepository, workflows: StartWorkflow, id: WorkflowInstanceId, target: TransitionTarget, evidenceId: string, context: CommandContext & {
19
19
  readonly expectedSequence?: number;
20
+ readonly retry?: {
21
+ readonly key: string;
22
+ readonly max: number;
23
+ readonly exhaustedReason: string;
24
+ };
20
25
  }): Promise<WorkflowInstanceView | null>;
21
26
  export {};
@@ -1,5 +1,7 @@
1
1
  import { ActivityEventType, selectActivityEvent } from '../../activities/index.js';
2
+ import { OrchestrationEventType, } from '../contracts/events.js';
2
3
  import { WorkflowStatus } from '../contracts/vocabulary.js';
4
+ import { stateDraft } from '../domain/decision-events.js';
3
5
  import { acceptSignal as decideSignal } from '../domain/interpreter.js';
4
6
  import { appendWithIntentRecovery } from './durable-append.js';
5
7
  import { resolveTriggerWorkflowInstanceId } from './trigger-workflow-instance.js';
@@ -61,6 +63,11 @@ export async function acceptResourceTransition(repository, workflows, id, target
61
63
  const definition = await workflows.definitionForOperation(loaded.view, loaded.sequence, context);
62
64
  if (definition === null)
63
65
  return loaded.view;
66
+ const retry = retryDraft(loaded.view, evidenceId, context);
67
+ if (retry?.eventType === OrchestrationEventType.InstanceBlocked) {
68
+ await repository.append(id, loaded.sequence, [retry]);
69
+ return (await repository.load(id)).view;
70
+ }
64
71
  const decision = decideSignal(definition, { ...loaded.view, waitingFor: { ...loaded.view.waitingFor, resume: target } }, {
65
72
  signal: {
66
73
  kind: loaded.view.waitingFor.signalKind,
@@ -75,7 +82,10 @@ export async function acceptResourceTransition(repository, workflows, id, target
75
82
  if (decision.kind === 'append') {
76
83
  const recovered = await appendWithIntentRecovery({
77
84
  append: async () => {
78
- await repository.append(id, loaded.sequence, decision.events);
85
+ await repository.append(id, loaded.sequence, [
86
+ ...(retry === undefined ? [] : [retry]),
87
+ ...decision.events,
88
+ ]);
79
89
  },
80
90
  load: () => repository.load(id),
81
91
  alreadyApplied: (reloaded) => reloaded.view !== null &&
@@ -87,3 +97,15 @@ export async function acceptResourceTransition(repository, workflows, id, target
87
97
  }
88
98
  return (await repository.load(id)).view;
89
99
  }
100
+ function retryDraft(view, evidenceId, context) {
101
+ if (context.retry === undefined)
102
+ return undefined;
103
+ const retry = context.retry;
104
+ const count = (view.retryCounts[retry.key] ?? 0) + 1;
105
+ return stateDraft(view, { occurredAt: context.occurredAt, causationId: `${context.commandId}:${evidenceId}` }, count > retry.max
106
+ ? {
107
+ eventType: OrchestrationEventType.InstanceBlocked,
108
+ payload: { reason: retry.exhaustedReason },
109
+ }
110
+ : { eventType: OrchestrationEventType.RetryCounted, payload: { retryKey: retry.key, count } }, 100);
111
+ }
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { ApprovalAuthorityKind } from './vocabulary.js';
3
- import { ActivityEventType, PullRequestCheckState, PullRequestState, type ActivityName } from '../../activities/index.js';
3
+ import { ActivityEventType, PullRequestCheckState, PullRequestMergeability, PullRequestState, type ActivityName } from '../../activities/index.js';
4
4
  import { type WorkspaceMode as WorkspaceModeType } from '../../execution/index.js';
5
5
  import type { CommandName, SignalName, StageName, WatchId, WorkflowName } from './identifiers.js';
6
6
  import type { TransitionTargetKind } from './vocabulary.js';
@@ -23,6 +23,15 @@ declare const watchGateConfigSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObje
23
23
  }, z.core.$strict>>;
24
24
  }, z.core.$strict>]>;
25
25
  declare const resourceTransitionConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
26
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
27
+ where: z.ZodObject<{
28
+ mergeability: z.ZodLiteral<"conflicting">;
29
+ }, z.core.$strict>;
30
+ then: z.ZodString;
31
+ retry: z.ZodObject<{
32
+ max: z.ZodNumber;
33
+ }, z.core.$strict>;
34
+ }, z.core.$strict>, z.ZodObject<{
26
35
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
27
36
  then: z.ZodOptional<z.ZodString>;
28
37
  }, z.core.$strict>, z.ZodObject<{
@@ -96,6 +105,15 @@ export declare const outcomeRouteConfigSchema: z.ZodObject<{
96
105
  }, z.core.$strict>>;
97
106
  }, z.core.$strict>]>>>;
98
107
  resourceTransitions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
108
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
109
+ where: z.ZodObject<{
110
+ mergeability: z.ZodLiteral<"conflicting">;
111
+ }, z.core.$strict>;
112
+ then: z.ZodString;
113
+ retry: z.ZodObject<{
114
+ max: z.ZodNumber;
115
+ }, z.core.$strict>;
116
+ }, z.core.$strict>, z.ZodObject<{
99
117
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
100
118
  then: z.ZodOptional<z.ZodString>;
101
119
  }, z.core.$strict>, z.ZodObject<{
@@ -150,6 +168,15 @@ export declare const stageConfigSchema: z.ZodObject<{
150
168
  }, z.core.$strict>>;
151
169
  }, z.core.$strict>]>>>;
152
170
  resourceTransitions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
171
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
172
+ where: z.ZodObject<{
173
+ mergeability: z.ZodLiteral<"conflicting">;
174
+ }, z.core.$strict>;
175
+ then: z.ZodString;
176
+ retry: z.ZodObject<{
177
+ max: z.ZodNumber;
178
+ }, z.core.$strict>;
179
+ }, z.core.$strict>, z.ZodObject<{
153
180
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
154
181
  then: z.ZodOptional<z.ZodString>;
155
182
  }, z.core.$strict>, z.ZodObject<{
@@ -248,6 +275,15 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
248
275
  }, z.core.$strict>>;
249
276
  }, z.core.$strict>]>>>;
250
277
  resourceTransitions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
278
+ events: z.ZodTuple<[z.ZodLiteral<"pr.state-changed">], null>;
279
+ where: z.ZodObject<{
280
+ mergeability: z.ZodLiteral<"conflicting">;
281
+ }, z.core.$strict>;
282
+ then: z.ZodString;
283
+ retry: z.ZodObject<{
284
+ max: z.ZodNumber;
285
+ }, z.core.$strict>;
286
+ }, z.core.$strict>, z.ZodObject<{
251
287
  events: z.ZodTuple<[z.ZodLiteral<"pr.review-accepted">], null>;
252
288
  then: z.ZodOptional<z.ZodString>;
253
289
  }, z.core.$strict>, z.ZodObject<{
@@ -334,7 +370,12 @@ export interface CompiledOutcomeRoute extends Omit<OutcomeRouteConfig, 'activiti
334
370
  }
335
371
  export interface CompiledResourceTransition {
336
372
  readonly event: typeof ActivityEventType.PrReviewAccepted | typeof ActivityEventType.PrStateChanged | typeof ActivityEventType.PrChecksChanged;
373
+ readonly retry?: {
374
+ readonly max: number;
375
+ };
337
376
  readonly where?: {
377
+ readonly mergeability: typeof PullRequestMergeability.Conflicting;
378
+ } | {
338
379
  readonly state: typeof PullRequestState.Merged;
339
380
  } | {
340
381
  readonly checks: typeof PullRequestCheckState.Failing;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { ApprovalAuthorityKind, ConversationSurfaceCapability, WorkflowStatus, } from './vocabulary.js';
3
- import { ActivityEventType, PullRequestCheckState, PullRequestState, } from '../../activities/index.js';
3
+ import { ActivityEventType, PullRequestCheckState, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
4
4
  import { WorkspaceMode } from '../../execution/index.js';
5
5
  import { MatchMode } from '../../kernel/index.js';
6
6
  const identifier = z.string().trim().min(1);
@@ -33,6 +33,14 @@ const watchGateConfigSchema = z.union([
33
33
  .strict(),
34
34
  ]);
35
35
  const resourceTransitionConfigSchema = z.union([
36
+ z
37
+ .object({
38
+ events: z.tuple([z.literal(ActivityEventType.PrStateChanged)]),
39
+ where: z.object({ mergeability: z.literal(PullRequestMergeability.Conflicting) }).strict(),
40
+ then: identifier,
41
+ retry: z.object({ max: z.number().int().min(1).max(2) }).strict(),
42
+ })
43
+ .strict(),
36
44
  z
37
45
  .object({
38
46
  events: z.tuple([z.literal(ActivityEventType.PrReviewAccepted)]),
@@ -113,6 +113,8 @@ export declare const expectationSchema: z.ZodObject<{
113
113
  "pr.review-accepted": "pr.review-accepted";
114
114
  }>;
115
115
  where: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
116
+ mergeability: z.ZodLiteral<"conflicting">;
117
+ }, z.core.$strict>, z.ZodObject<{
116
118
  state: z.ZodLiteral<"merged">;
117
119
  }, z.core.$strict>, z.ZodObject<{
118
120
  checks: z.ZodLiteral<"failing">;
@@ -128,6 +130,9 @@ export declare const expectationSchema: z.ZodObject<{
128
130
  }, z.core.$strict>, z.ZodObject<{
129
131
  kind: z.ZodLiteral<"resource-transition-wait">;
130
132
  }, z.core.$strict>], "kind">;
133
+ retry: z.ZodOptional<z.ZodObject<{
134
+ max: z.ZodNumber;
135
+ }, z.core.$strict>>;
131
136
  }, z.core.$strict>>>;
132
137
  }, z.core.$strict>;
133
138
  export declare const signalSchema: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { eventDataSchema, eventEnvelopeSchema } from '@atolis-hq/eventing';
3
- import { activationId, ActivityEventType, activityName, ActivityOutcomeKind, PullRequestCheckState, PullRequestState, } from '../../activities/index.js';
3
+ import { activationId, ActivityEventType, activityName, ActivityOutcomeKind, PullRequestCheckState, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
4
4
  import { WorkspaceMode } from '../../execution/index.js';
5
5
  import { brandedStringSchema } from '../../kernel/index.js';
6
6
  import { workItemId } from '../../work/index.js';
@@ -111,11 +111,16 @@ const resourceTransitionSchema = z
111
111
  ]),
112
112
  where: z
113
113
  .union([
114
+ z.object({ mergeability: z.literal(PullRequestMergeability.Conflicting) }).strict(),
114
115
  z.object({ state: z.literal(PullRequestState.Merged) }).strict(),
115
116
  z.object({ checks: z.literal(PullRequestCheckState.Failing) }).strict(),
116
117
  ])
117
118
  .optional(),
118
119
  target: transitionTargetSchema,
120
+ retry: z
121
+ .object({ max: z.number().int().min(1).max(2) })
122
+ .strict()
123
+ .optional(),
119
124
  })
120
125
  .strict();
121
126
  export const expectationSchema = z
@@ -58,6 +58,8 @@ export interface WorkflowInstanceView {
58
58
  readonly supplementalQueue: readonly SupplementalActivityView[];
59
59
  readonly acceptedSignalIds: readonly string[];
60
60
  readonly operatorRetryCommandIds: readonly string[];
61
+ /** Retained after the pending activation is replaced, derived from ActivityStarted facts. */
62
+ readonly hasStartedActivation?: boolean;
61
63
  readonly acceptedOutcomes: readonly ActivationId[];
62
64
  readonly acceptedChildCompletionIds: readonly WorkflowInstanceId[];
63
65
  readonly causalRejectionIds: readonly string[];
@@ -9,6 +9,7 @@ export function compileResourceTransitions(entries, context, allStages, isReserv
9
9
  throw new Error(`Unknown resourceTransitions target: ${then}`);
10
10
  return Object.freeze({
11
11
  event: entry.events[0],
12
+ ...(!('retry' in entry) ? {} : { retry: entry.retry }),
12
13
  ...(!('where' in entry) || entry.where === undefined ? {} : { where: entry.where }),
13
14
  target: compileTarget(then, context.outcomeKind),
14
15
  });
@@ -32,6 +32,7 @@ export type MutableWorkflowInstance = {
32
32
  supplementalQueue: Array<WorkflowInstanceView['supplementalQueue'][number]>;
33
33
  acceptedSignalIds: string[];
34
34
  operatorRetryCommandIds: string[];
35
+ hasStartedActivation: boolean;
35
36
  acceptedOutcomes: ActivationId[];
36
37
  acceptedChildCompletionIds: WorkflowInstanceView['workflowInstanceId'][];
37
38
  causalRejectionIds: string[];
@@ -50,6 +50,7 @@ function applyActivityFact(state, event) {
50
50
  applyActivityRequested(state, event.payload);
51
51
  return;
52
52
  case OrchestrationEventType.ActivityStarted:
53
+ state.hasStartedActivation = true;
53
54
  updateActivationStatus(state, event.payload.activationId, ActivityActivationStatus.Running);
54
55
  return;
55
56
  case OrchestrationEventType.ActivityOutcomeAccepted:
@@ -238,6 +239,7 @@ export function immutableWorkflowInstanceView(state) {
238
239
  supplementalQueue: state.supplementalQueue,
239
240
  acceptedSignalIds: state.acceptedSignalIds,
240
241
  operatorRetryCommandIds: state.operatorRetryCommandIds,
242
+ hasStartedActivation: state.hasStartedActivation,
241
243
  acceptedOutcomes: state.acceptedOutcomes,
242
244
  acceptedChildCompletionIds: state.acceptedChildCompletionIds,
243
245
  causalRejectionIds: state.causalRejectionIds,
@@ -1,5 +1,5 @@
1
1
  import { OrchestrationEventType } from '../contracts/events.js';
2
- import { WorkflowStatus } from '../contracts/vocabulary.js';
2
+ import { ActivityActivationStatus, WorkflowStatus } from '../contracts/vocabulary.js';
3
3
  import { applyWorkflowInstanceEvent, immutableWorkflowInstanceView, orchestrationStatusTransitions, } from './workflow-instance-events.js';
4
4
  export { orchestrationStatusTransitions };
5
5
  export function foldWorkflowInstance(events) {
@@ -24,6 +24,7 @@ export function foldWorkflowInstance(events) {
24
24
  supplementalQueue: [],
25
25
  acceptedSignalIds: [],
26
26
  operatorRetryCommandIds: [],
27
+ hasStartedActivation: false,
27
28
  acceptedOutcomes: [],
28
29
  acceptedChildCompletionIds: [],
29
30
  causalRejectionIds: [],
@@ -39,6 +40,7 @@ export function continueWorkflowInstance(previous, event) {
39
40
  return foldWorkflowInstance([event]);
40
41
  const state = {
41
42
  ...previous,
43
+ hasStartedActivation: previous.hasStartedActivation ?? legacyStartEvidence(previous),
42
44
  repeatCounts: { ...previous.repeatCounts },
43
45
  retryCounts: { ...previous.retryCounts },
44
46
  supplementalQueue: [...previous.supplementalQueue],
@@ -62,3 +64,9 @@ function optionalChildFields(payload) {
62
64
  }
63
65
  : {};
64
66
  }
67
+ // Preserve visible start evidence when continuing a pre-field stored view.
68
+ function legacyStartEvidence(previous) {
69
+ return (previous.acceptedOutcomes.length > 0 ||
70
+ (previous.pendingActivation !== undefined &&
71
+ previous.pendingActivation.status !== ActivityActivationStatus.Pending));
72
+ }
@@ -4,6 +4,7 @@ export * from './application/orchestration-service.js';
4
4
  export * from './application/advance-workflow.js';
5
5
  export * from './application/durable-append.js';
6
6
  export * from './application/pull-request-transition-evidence.js';
7
+ export { isPolicyBlockedMergeWait } from './application/policy-blocked-merge-recovery.js';
7
8
  export * from './application/resource-transition-evidence.js';
8
9
  export * from './application/resource-transition-matching.js';
9
10
  export * from './application/resource-transition-reactor.js';
@@ -4,6 +4,7 @@ export * from './application/orchestration-service.js';
4
4
  export * from './application/advance-workflow.js';
5
5
  export * from './application/durable-append.js';
6
6
  export * from './application/pull-request-transition-evidence.js';
7
+ export { isPolicyBlockedMergeWait } from './application/policy-blocked-merge-recovery.js';
7
8
  export * from './application/resource-transition-evidence.js';
8
9
  export * from './application/resource-transition-matching.js';
9
10
  export * from './application/resource-transition-reactor.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.4.76",
3
+ "version": "0.4.78",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {