@atolis-hq/wake 0.4.66 → 0.4.67

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 (35) hide show
  1. package/dist/src/bootstrap/integration-runtime.js +17 -2
  2. package/dist/src/bootstrap/surface-api-work-applications.js +38 -3
  3. package/dist/src/bootstrap/version.js +1 -1
  4. package/dist/src/conversations/contracts/events.js +2 -0
  5. package/dist/src/conversations/contracts/views.d.ts +5 -1
  6. package/dist/src/integrations/application/conversation-command-feedback.d.ts +11 -0
  7. package/dist/src/integrations/application/conversation-command-feedback.js +36 -0
  8. package/dist/src/integrations/delivery/application/delivery-intent-lookup.d.ts +4 -0
  9. package/dist/src/integrations/delivery/application/delivery-intent-lookup.js +23 -0
  10. package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +4 -11
  11. package/dist/src/integrations/delivery/application/delivery-projector.js +7 -1
  12. package/dist/src/integrations/delivery/contracts/intents.d.ts +3 -1
  13. package/dist/src/integrations/delivery/contracts/intents.js +1 -1
  14. package/dist/src/integrations/delivery/contracts/views.d.ts +1 -0
  15. package/dist/src/integrations/github/application/agent-run-comment.js +7 -9
  16. package/dist/src/integrations/github/application/inbound-translator.js +13 -1
  17. package/dist/src/integrations/github/application/work-control-authorization.d.ts +6 -0
  18. package/dist/src/integrations/github/application/work-control-authorization.js +10 -0
  19. package/dist/src/integrations/index.d.ts +1 -0
  20. package/dist/src/integrations/index.js +1 -0
  21. package/dist/src/orchestration/application/conversation-command-reactor.d.ts +16 -1
  22. package/dist/src/orchestration/application/conversation-command-reactor.js +34 -5
  23. package/dist/src/orchestration/application/conversation-command.d.ts +27 -4
  24. package/dist/src/orchestration/application/conversation-command.js +60 -22
  25. package/dist/src/orchestration/application/orchestration-service.d.ts +5 -8
  26. package/dist/src/orchestration/application/orchestration-service.js +93 -34
  27. package/dist/src/orchestration/domain/interpreter.d.ts +1 -1
  28. package/dist/src/orchestration/domain/interpreter.js +1 -1
  29. package/dist/src/orchestration/domain/operator-retry-policy.d.ts +2 -0
  30. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -1
  31. package/dist/src/surfaces/api/contracts/work.d.ts +3 -0
  32. package/dist/src/surfaces/api/routes/commands.js +8 -2
  33. package/dist/src/surfaces/web-assets/assets/{index-9IfrHvBo.js → index-DMS1vQy3.js} +3 -3
  34. package/dist/src/surfaces/web-assets/index.html +1 -1
  35. package/package.json +1 -1
@@ -1,46 +1,84 @@
1
1
  import { ActivityOutcomeKind } from '../../activities/index.js';
2
2
  import { ConversationBuiltInCommand, ConversationSurfaceCapability, } from '../contracts/vocabulary.js';
3
- import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, selectOperatorRetryTarget, } from '../domain/operator-retry-policy.js';
3
+ import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, selectChangesResumeTargets, selectOperatorRetryTarget, } from '../domain/operator-retry-policy.js';
4
4
  export const BuiltInConversationCommands = Object.values(ConversationBuiltInCommand);
5
5
  export function conversationCommand(body) {
6
6
  const line = body.trim().split('\n', 1)[0]?.trim().toLowerCase() ?? '';
7
7
  return /^\/[a-z][a-z0-9-]*(?:\s.*)?$/.test(line) ? line.split(/\s/, 1)[0] : null;
8
8
  }
9
- // The command matrix is intentionally explicit so future built-ins cannot silently inherit power.
9
+ // The command matrix is explicit so new built-ins cannot silently inherit power.
10
10
  // eslint-disable-next-line complexity
11
11
  export async function applyBuiltInConversationCommand(input) {
12
+ const denied = (reason) => ({ applied: false, reason });
12
13
  if (!BuiltInConversationCommands.includes(input.command))
13
- return false;
14
+ return denied('Unknown command. Use /changes with instructions to continue eligible blocked work, or /retry for a failed stage.');
14
15
  if (!input.capabilities.includes(ConversationSurfaceCapability.Review) &&
15
16
  !input.capabilities.includes(ConversationSurfaceCapability.Operator))
16
- return false;
17
- if (input.command === ConversationBuiltInCommand.Approved ||
18
- input.command === ConversationBuiltInCommand.Accepted ||
19
- input.command === ConversationBuiltInCommand.Changes) {
20
- const outcome = input.command === ConversationBuiltInCommand.Changes
21
- ? ActivityOutcomeKind.Rejected
22
- : ActivityOutcomeKind.Done;
17
+ return denied('This conversation surface does not permit work-control or review commands.');
18
+ if (input.command === ConversationBuiltInCommand.Changes) {
19
+ let applied = false;
20
+ const continuationTargets = new Set(selectChangesResumeTargets(input.workflows));
23
21
  for (const workflow of input.workflows) {
24
- if (workflow.waitingFor !== undefined)
25
- await input.acceptSignal(workflow.workflowInstanceId, outcome);
26
- else if (input.command === ConversationBuiltInCommand.Changes)
27
- await input.resumeChanges(workflow.workflowInstanceId);
22
+ if (isOperatorRetryEligible(workflow) || isGroupBudgetExtensionEligible(workflow))
23
+ continue;
24
+ const reviewed = !input.continuation && input.reviewAuthorized && workflow.waitingFor !== undefined
25
+ ? await input.acceptSignal(workflow.workflowInstanceId, ActivityOutcomeKind.Rejected)
26
+ : false;
27
+ if (reviewed)
28
+ applied = true;
29
+ else if (input.workAuthorized && continuationTargets.has(workflow))
30
+ applied = (await input.resumeChanges(workflow.workflowInstanceId)) || applied;
28
31
  }
29
- return true;
32
+ return applied ? { applied: true } : denied(changesDeniedReason(input.workAuthorized));
33
+ }
34
+ if (input.command === ConversationBuiltInCommand.Approved ||
35
+ input.command === ConversationBuiltInCommand.Accepted) {
36
+ if (!input.reviewAuthorized)
37
+ return denied('Independent-review authority is required. An author cannot approve their own work; clarification uses /changes with instructions.');
38
+ let applied = false;
39
+ for (const workflow of input.workflows)
40
+ if (workflow.waitingFor !== undefined)
41
+ applied =
42
+ (await input.acceptSignal(workflow.workflowInstanceId, ActivityOutcomeKind.Done)) ||
43
+ applied;
44
+ return applied
45
+ ? { applied: true }
46
+ : denied('No wait accepted this review decision. Check the configured authority and current revision.');
30
47
  }
31
48
  if (input.command === ConversationBuiltInCommand.Retry) {
32
49
  const target = selectOperatorRetryTarget(input.workflows);
33
- if (target !== undefined)
34
- await input.retry(target.workflowInstanceId);
35
- return true;
50
+ if (target === undefined)
51
+ return denied('No retry-eligible failed stage. To continue eligible blocked agent work, use /changes followed by instructions.');
52
+ await input.retry(target.workflowInstanceId);
53
+ return { applied: true };
36
54
  }
37
55
  const primary = input.workflows.find((workflow) => workflow.parentWorkflowInstanceId === undefined);
38
56
  if (primary === undefined)
39
- return true;
40
- if (input.command === ConversationBuiltInCommand.Restart && isOperatorRetryEligible(primary))
57
+ return denied('Work item has no primary workflow.');
58
+ if (input.command === ConversationBuiltInCommand.Restart && isOperatorRetryEligible(primary)) {
41
59
  await input.restart(primary.workflowInstanceId);
60
+ return { applied: true };
61
+ }
42
62
  if (input.command === ConversationBuiltInCommand.Extend &&
43
- isGroupBudgetExtensionEligible(primary))
63
+ isGroupBudgetExtensionEligible(primary)) {
44
64
  await input.extend(primary.workflowInstanceId);
45
- return true;
65
+ return { applied: true };
66
+ }
67
+ return denied('Command is inapplicable: restart requires a failed stage; extend requires an exhausted watch-group budget.');
68
+ }
69
+ function changesDeniedReason(workAuthorized) {
70
+ return workAuthorized
71
+ ? 'No eligible blocked agent stage or authorized review wait. Use /retry for an eligible failed stage; watch gates require their configured authority.'
72
+ : 'No review wait accepted this decision. Continuing blocked work requires verified repository write, maintain, or admin permission; watch gates retain their configured authority.';
73
+ }
74
+ export function continuationCommandRejection(input, command) {
75
+ if (!input.continuation)
76
+ return null;
77
+ if (command !== ConversationBuiltInCommand.Changes)
78
+ return 'Continuation must use /changes followed by instructions.';
79
+ if (!input.authorized)
80
+ return 'Continuation requires verified work-control authority.';
81
+ if (input.body.trim().slice(command.length).trim() === '')
82
+ return 'Supply instructions after /changes to continue the blocked stage.';
83
+ return null;
46
84
  }
@@ -8,7 +8,7 @@ import type { ChildWorkflowRequest, OrchestrationSignal, SignalExpectation, Supp
8
8
  import { type SignalName, type WorkflowInstanceId } from '../contracts/identifiers.js';
9
9
  import type { WorkflowInstanceView } from '../contracts/views.js';
10
10
  import { AdvanceWorkflow } from './advance-workflow.js';
11
- import { type SurfaceCapability } from './conversation-command.js';
11
+ import { type ConversationCommandInput, type ConversationCommandResult } from './conversation-command.js';
12
12
  export declare class OrchestrationService {
13
13
  private readonly startWorkflow;
14
14
  private readonly acceptActivityOutcome;
@@ -38,13 +38,9 @@ export declare class OrchestrationService {
38
38
  setAcceptSignalOperationCoordinator(coordinator: OperationCoordinator): void;
39
39
  setWatchChildCancellation(cancellation: WatchChildCancellation): void;
40
40
  requestSupplementalActivity(workflowInstanceId: WorkflowInstanceId, request: SupplementalActivityRequest, context: CommandContext): Promise<WorkflowInstanceView>;
41
- applyConversationCommand(workItemId: WorkItemId, input: {
42
- readonly body: string;
43
- readonly actorId: string;
44
- readonly capabilities: readonly SurfaceCapability[];
45
- /** The adapter authenticated and authorized the actor for command control. */
46
- readonly authorized: boolean;
47
- }, context: CommandContext): Promise<boolean>;
41
+ applyConversationCommand(workItemId: WorkItemId, input: ConversationCommandInput, context: CommandContext): Promise<boolean>;
42
+ applyConversationCommandWithFeedback(workItemId: WorkItemId, input: ConversationCommandInput, context: CommandContext): Promise<ConversationCommandResult>;
43
+ private applyConfiguredConversationCommands;
48
44
  markActivationStarted(workflowInstanceId: WorkflowInstanceId, activationId: ActivationId, context: CommandContext): Promise<WorkflowInstanceView | null>;
49
45
  validateActivationDispatch(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<boolean>;
50
46
  block(workflowInstanceId: WorkflowInstanceId, reason: string, context: CommandContext): Promise<WorkflowInstanceView | null>;
@@ -62,6 +58,7 @@ export declare class OrchestrationService {
62
58
  retryBlockedFailedStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView>;
63
59
  restartBlockedFailedStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView>;
64
60
  resumeBlockedStageForChanges(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
61
+ resumeBlockedStageForReply(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
65
62
  resumeNeedsClarificationStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
66
63
  extendBlockedGroupBudget(workflowInstanceId: WorkflowInstanceId, authority: {
67
64
  readonly kind: string;
@@ -1,15 +1,15 @@
1
1
  import { recoverPolicyBlockedMerges } from './policy-blocked-merge-recovery.js';
2
- import { WorkStatus } from '../../work/index.js';
2
+ import { WorkStatus, } from '../../work/index.js';
3
3
  import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
4
4
  import { OrchestrationEventType } from '../contracts/events.js';
5
5
  import { commandName, workflowInstanceId as toWorkflowInstanceId, } from '../contracts/identifiers.js';
6
6
  import { childOrchestrationGroupStream, workflowInstanceStream } from '../contracts/streams.js';
7
- import { ApprovalAuthorityKind } from '../contracts/vocabulary.js';
8
- import { isGroupBudgetExtensionEligible } from '../domain/operator-retry-policy.js';
7
+ import { ApprovalAuthorityKind, ConversationBuiltInCommand } from '../contracts/vocabulary.js';
8
+ import { isGroupBudgetExtensionEligible, isNeedsClarificationResumeEligible, isPlainReplyResumeEligible, selectChangesResumeTargets, } from '../domain/operator-retry-policy.js';
9
9
  import { AcceptActivityOutcome } from './accept-activity-outcome.js';
10
10
  import { AcceptSignal } from './accept-signal.js';
11
11
  import { AdvanceWorkflow } from './advance-workflow.js';
12
- import { applyBuiltInConversationCommand, conversationCommand, } from './conversation-command.js';
12
+ import { applyBuiltInConversationCommand, continuationCommandRejection, conversationCommand, } from './conversation-command.js';
13
13
  import { CoordinationClaims } from './coordination-claims.js';
14
14
  import { GroupBudgetRecorder } from './group-budget-recorder.js';
15
15
  import { workflowsByWorkItemProjection } from './orchestration-projection.js';
@@ -72,48 +72,77 @@ export class OrchestrationService {
72
72
  return this.advanceWorkflow.requestSupplementalActivity(workflowInstanceId, request, context);
73
73
  }
74
74
  async applyConversationCommand(workItemId, input, context) {
75
+ return (await this.applyConversationCommandWithFeedback(workItemId, input, context)).applied;
76
+ }
77
+ async applyConversationCommandWithFeedback(workItemId, input, context) {
75
78
  const command = conversationCommand(input.body);
76
79
  if (command === null)
77
- return false;
78
- if (!input.authorized)
79
- return false;
80
- const work = await this.work.get(workItemId);
81
- if (work === null || work.deleted || work.frozen || work.state !== WorkStatus.Open)
82
- return false;
80
+ return { applied: false, reason: 'Message contains no command.' };
81
+ const continuationRejection = continuationCommandRejection(input, command);
82
+ if (continuationRejection !== null)
83
+ return { applied: false, reason: continuationRejection };
84
+ const reviewAuthorized = input.reviewAuthorized === true;
85
+ if (!input.authorized && !reviewAuthorized)
86
+ return {
87
+ applied: false,
88
+ reason: 'Verified repository write, maintain, or admin permission is required for work control; independent-review authority is required for approval.',
89
+ };
83
90
  // A command is causally adjacent to its conversation entry; projections may lag
84
91
  // the journal, so command application must read the authoritative workflow state.
85
92
  const workflows = (await this.advanceWorkflow.listAll()).filter((workflow) => workflow.workItemId === workItemId);
86
- // Configured commands deliberately win over built-ins, even when their spelling collides.
87
- let supplemental = false;
88
- for (const workflow of workflows) {
89
- const definition = await this.definitions.resolve(workflow);
90
- if (definition.commands[command] === undefined)
91
- continue;
92
- supplemental = true;
93
- await this.requestSupplementalActivity(workflow.workflowInstanceId, { command: commandName(command) }, context);
94
- }
95
- if (supplemental)
96
- return true;
93
+ if (conversationCommandAlreadyApplied(workflows, context.commandId))
94
+ return { applied: true };
95
+ const work = await this.work.get(workItemId);
96
+ if (!isWorkControllable(work))
97
+ return { applied: false, reason: 'Work item must be open, unfrozen, and not deleted.' };
98
+ if (!input.authorized && !isReviewConversationCommand(command))
99
+ return { applied: false, reason: 'Verified repository work-control authority is required.' };
100
+ // Explicit continuation invokes the owning recovery command; ordinary commands keep configured precedence.
101
+ if (!input.continuation &&
102
+ (await this.applyConfiguredConversationCommands(command, workflows, context)))
103
+ return { applied: true };
97
104
  return applyBuiltInConversationCommand({
98
105
  command,
99
106
  capabilities: input.capabilities,
107
+ reviewAuthorized,
108
+ workAuthorized: input.authorized,
109
+ continuation: input.continuation === true,
100
110
  workflows,
101
111
  context,
102
- acceptSignal: (id, outcome) => this.acceptSignal(id, {
103
- kind: (workflows.find((workflow) => workflow.workflowInstanceId === id)?.waitingFor
104
- ?.signalKind ?? 'approved'),
105
- outcome,
106
- actorId: input.actorId,
107
- actorDecision: { authorized: true, evidenceId: context.commandId },
108
- providerEventId: context.commandId,
109
- authority: { kind: ApprovalAuthorityKind.Human },
110
- }, context),
112
+ acceptSignal: async (id, outcome) => {
113
+ const updated = await this.acceptSignal(id, {
114
+ kind: (workflows.find((workflow) => workflow.workflowInstanceId === id)?.waitingFor
115
+ ?.signalKind ?? 'approved'),
116
+ outcome,
117
+ actorId: input.actorId,
118
+ actorDecision: { authorized: true, evidenceId: context.commandId },
119
+ providerEventId: context.commandId,
120
+ authority: { kind: ApprovalAuthorityKind.Human },
121
+ }, context);
122
+ return updated.acceptedSignalIds.includes(context.commandId);
123
+ },
111
124
  retry: (id) => this.retryBlockedFailedStage(id, context),
112
125
  restart: (id) => this.restartBlockedFailedStage(id, context),
113
126
  extend: (id) => this.extendBlockedGroupBudget(id, { kind: ApprovalAuthorityKind.Human }, context),
114
- resumeChanges: (id) => this.resumeBlockedStageForChanges(id, context),
127
+ resumeChanges: async (id) => {
128
+ if (!input.authorized)
129
+ return false;
130
+ const updated = await this.resumeBlockedStageForChanges(id, context);
131
+ return updated?.operatorRetryCommandIds.includes(context.commandId) === true;
132
+ },
115
133
  });
116
134
  }
135
+ async applyConfiguredConversationCommands(command, workflows, context) {
136
+ let supplemental = false;
137
+ for (const workflow of workflows) {
138
+ const definition = await this.definitions.resolve(workflow);
139
+ if (definition.commands[command] === undefined)
140
+ continue;
141
+ supplemental = true;
142
+ await this.requestSupplementalActivity(workflow.workflowInstanceId, { command: commandName(command) }, context);
143
+ }
144
+ return supplemental;
145
+ }
117
146
  markActivationStarted(workflowInstanceId, activationId, context) {
118
147
  return this.advanceWorkflow.markActivationStarted(workflowInstanceId, activationId, context);
119
148
  }
@@ -135,11 +164,29 @@ export class OrchestrationService {
135
164
  restartBlockedFailedStage(workflowInstanceId, context) {
136
165
  return this.transitionWatchChildren(context, () => this.advanceWorkflow.restartBlockedFailedStage(workflowInstanceId, context));
137
166
  }
138
- resumeBlockedStageForChanges(workflowInstanceId, context) {
167
+ async resumeBlockedStageForChanges(workflowInstanceId, context) {
168
+ const current = await this.advanceWorkflow.get(workflowInstanceId);
169
+ if (current === null)
170
+ return null;
171
+ const work = await this.work.get(current.workItemId);
172
+ if (work === null || work.deleted || work.frozen || work.state !== WorkStatus.Open)
173
+ return current;
174
+ if (!current.operatorRetryCommandIds.includes(context.commandId) &&
175
+ !selectChangesResumeTargets((await this.advanceWorkflow.listAll()).filter((workflow) => workflow.workItemId === current.workItemId)).some((workflow) => workflow.workflowInstanceId === workflowInstanceId))
176
+ return current;
139
177
  return this.transitionWatchChildren(context, () => this.advanceWorkflow.resumeBlockedStageForChanges(workflowInstanceId, context));
140
178
  }
141
- resumeNeedsClarificationStage(workflowInstanceId, context) {
142
- return this.transitionWatchChildren(context, () => this.advanceWorkflow.resumeNeedsClarificationStage(workflowInstanceId, context));
179
+ async resumeBlockedStageForReply(workflowInstanceId, context) {
180
+ const current = await this.advanceWorkflow.get(workflowInstanceId);
181
+ if (current === null || !isPlainReplyResumeEligible(current))
182
+ return current;
183
+ return this.resumeBlockedStageForChanges(workflowInstanceId, context);
184
+ }
185
+ async resumeNeedsClarificationStage(workflowInstanceId, context) {
186
+ const current = await this.advanceWorkflow.get(workflowInstanceId);
187
+ if (current === null || !isNeedsClarificationResumeEligible(current))
188
+ return current;
189
+ return this.resumeBlockedStageForChanges(workflowInstanceId, context);
143
190
  }
144
191
  async extendBlockedGroupBudget(workflowInstanceId, authority, context) {
145
192
  if (authority.kind !== ApprovalAuthorityKind.Human)
@@ -254,3 +301,15 @@ async function journalGroupBudgetExhaustion(journal, workflowInstanceId) {
254
301
  });
255
302
  }
256
303
  export const createOrchestrationService = (journal, work, definitions, projections) => new OrchestrationService(journal, work, definitions, projections);
304
+ function isWorkControllable(work) {
305
+ return work !== null && !work.deleted && !work.frozen && work.state === WorkStatus.Open;
306
+ }
307
+ function conversationCommandAlreadyApplied(workflows, commandId) {
308
+ return workflows.some((workflow) => workflow.operatorRetryCommandIds.includes(commandId) ||
309
+ workflow.acceptedSignalIds.includes(commandId));
310
+ }
311
+ function isReviewConversationCommand(command) {
312
+ return (command === ConversationBuiltInCommand.Approved ||
313
+ command === ConversationBuiltInCommand.Accepted ||
314
+ command === ConversationBuiltInCommand.Changes);
315
+ }
@@ -7,7 +7,7 @@ export { acceptSignal, AwaitTimeoutBlockReason, expireTimedOutAwait, hasTimedOut
7
7
  export type { AcceptSignal } from './signal-policy.js';
8
8
  export { requestSupplementalActivity } from './supplemental-policy.js';
9
9
  export type { SupplementalActivityRequest } from './supplemental-policy.js';
10
- export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isNeedsClarificationResumeEligible, isOperatorRetryEligible, requestChangesResume, requestFreshOperatorRetry, requestOperatorRetry, selectOperatorRetryTarget, } from './operator-retry-policy.js';
10
+ export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isNeedsClarificationResumeEligible, isOperatorRetryEligible, isPlainReplyResumeEligible, requestChangesResume, requestFreshOperatorRetry, requestOperatorRetry, selectChangesResumeTargets, selectOperatorRetryTarget, } from './operator-retry-policy.js';
11
11
  export type { OperatorRetryRequest } from './operator-retry-policy.js';
12
12
  export { isRunnerQuotaRetryEligible, requestRunnerQuotaRetry, } from './runner-quota-retry-policy.js';
13
13
  export type { RunnerQuotaRetryRequest } from './runner-quota-retry-policy.js';
@@ -10,7 +10,7 @@ import { finishRoute } from './transition.js';
10
10
  export { startInstance } from './activation-policy.js';
11
11
  export { acceptSignal, AwaitTimeoutBlockReason, expireTimedOutAwait, hasTimedOutAwait, waitForSignal, } from './signal-policy.js';
12
12
  export { requestSupplementalActivity } from './supplemental-policy.js';
13
- export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isNeedsClarificationResumeEligible, isOperatorRetryEligible, requestChangesResume, requestFreshOperatorRetry, requestOperatorRetry, selectOperatorRetryTarget, } from './operator-retry-policy.js';
13
+ export { isChangesResumeEligible, isGroupBudgetExtensionEligible, isNeedsClarificationResumeEligible, isOperatorRetryEligible, isPlainReplyResumeEligible, requestChangesResume, requestFreshOperatorRetry, requestOperatorRetry, selectChangesResumeTargets, selectOperatorRetryTarget, } from './operator-retry-policy.js';
14
14
  export { isRunnerQuotaRetryEligible, requestRunnerQuotaRetry, } from './runner-quota-retry-policy.js';
15
15
  export function acceptActivityOutcome(definition, state, input) {
16
16
  if (!isPendingOutcome(state, input))
@@ -6,7 +6,9 @@ export interface OperatorRetryRequest extends DecisionContext {
6
6
  }
7
7
  export declare function isOperatorRetryEligible(view: WorkflowInstanceView): boolean;
8
8
  export declare function selectOperatorRetryTarget(workflows: readonly WorkflowInstanceView[]): WorkflowInstanceView | undefined;
9
+ export declare function selectChangesResumeTargets(workflows: readonly WorkflowInstanceView[]): readonly WorkflowInstanceView[];
9
10
  export declare function isChangesResumeEligible(view: WorkflowInstanceView): boolean;
11
+ export declare function isPlainReplyResumeEligible(view: WorkflowInstanceView): boolean;
10
12
  /** A clarification reply may be supplied by any conversation participant. */
11
13
  export declare function isNeedsClarificationResumeEligible(view: WorkflowInstanceView): boolean;
12
14
  export declare function isGroupBudgetExtensionEligible(view: WorkflowInstanceView): boolean;
@@ -50,13 +50,36 @@ export function selectOperatorRetryTarget(workflows) {
50
50
  watched.has(watchId(workflow.watchId)) &&
51
51
  isOperatorRetryEligible(workflow));
52
52
  }
53
+ export function selectChangesResumeTargets(workflows) {
54
+ const primary = workflows.find((workflow) => workflow.parentWorkflowInstanceId === undefined);
55
+ if (primary === undefined)
56
+ return [];
57
+ if (isChangesResumeEligible(primary))
58
+ return [primary];
59
+ if (primary.status !== WorkflowStatus.Waiting ||
60
+ primary.waitingFor?.signalKind !== WatchGateVerdictSignal)
61
+ return [];
62
+ const watches = new Set((primary.waitingFor.from ?? []).flatMap((authority) => authority.kind === ApprovalAuthorityKind.Watch ? [authority.watch] : []));
63
+ return workflows.filter((workflow) => workflow.parentWorkflowInstanceId === primary.workflowInstanceId &&
64
+ workflow.workItemId === primary.workItemId &&
65
+ workflow.orchestrationGroupId === primary.orchestrationGroupId &&
66
+ workflow.watchId !== undefined &&
67
+ watches.has(watchId(workflow.watchId)) &&
68
+ isChangesResumeEligible(workflow));
69
+ }
53
70
  export function isChangesResumeEligible(view) {
54
71
  if (!isCompletedAgentStage(view))
55
72
  return false;
56
73
  return ((view.status === WorkflowStatus.Blocked &&
57
74
  view.blockReason === 'unconfigured outcome blocked' &&
58
75
  view.lastOutcome?.kind === ActivityOutcomeKind.Blocked) ||
59
- (view.status === WorkflowStatus.Waiting && view.waitingFor !== undefined));
76
+ (view.status === WorkflowStatus.Waiting &&
77
+ view.waitingFor !== undefined &&
78
+ view.lastOutcome?.kind !== ActivityOutcomeKind.Failed &&
79
+ !(view.waitingFor.from ?? []).some((authority) => authority.kind === ApprovalAuthorityKind.Watch)));
80
+ }
81
+ export function isPlainReplyResumeEligible(view) {
82
+ return isChangesResumeEligible(view) && view.lastOutcome?.kind === ActivityOutcomeKind.Blocked;
60
83
  }
61
84
  /** A clarification reply may be supplied by any conversation participant. */
62
85
  export function isNeedsClarificationResumeEligible(view) {
@@ -49,6 +49,8 @@ export interface WorkDetailResponse {
49
49
  readonly conversation: {
50
50
  /** Whether this authenticated surface may create control-plane entries. */
51
51
  readonly canCreateEntries: boolean;
52
+ /** Owning orchestration policy permits continuation with instructions. */
53
+ readonly canContinue?: boolean;
52
54
  readonly entries: readonly {
53
55
  readonly entryId: string;
54
56
  readonly body: string;
@@ -71,6 +73,7 @@ export interface WorkDetailResponse {
71
73
  export interface ConversationMessageRequest {
72
74
  readonly idempotencyKey: string;
73
75
  readonly body: string;
76
+ readonly continuation?: boolean;
74
77
  }
75
78
  export interface PullRequestResponse {
76
79
  readonly resourceId: string;
@@ -76,7 +76,7 @@ async function dispatchWorkCommand(applications, pathname, body) {
76
76
  function conversationMessageRequest(body) {
77
77
  if (!isObject(body))
78
78
  return invalidRequest('', 'A JSON object is required');
79
- if (Object.keys(body).some((key) => key !== 'idempotencyKey' && key !== 'body'))
79
+ if (Object.keys(body).some((key) => key !== 'idempotencyKey' && key !== 'body' && key !== 'continuation'))
80
80
  return invalidRequest('', 'The command body contains unknown fields');
81
81
  const command = commandRequest({ idempotencyKey: body.idempotencyKey });
82
82
  if (isHttpResponse(command))
@@ -85,7 +85,13 @@ function conversationMessageRequest(body) {
85
85
  return invalidRequest('body', 'Must be a non-empty string');
86
86
  if (body.body.length > 20_000)
87
87
  return invalidRequest('body', 'Must be at most 20000 characters');
88
- return { ...command, body: body.body };
88
+ if (body.continuation !== undefined && typeof body.continuation !== 'boolean')
89
+ return invalidRequest('continuation', 'Must be a boolean');
90
+ return {
91
+ ...command,
92
+ body: body.body,
93
+ ...(body.continuation === undefined ? {} : { continuation: body.continuation }),
94
+ };
89
95
  }
90
96
  async function dispatchControlCommand(applications, pathname, request) {
91
97
  const name = controlCommandName(pathname);