@atolis-hq/wake 0.4.104 → 0.4.105

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 (84) hide show
  1. package/dist/src/activities/agent/agent-activity.js +3 -0
  2. package/dist/src/activities/contracts/activity.d.ts +16 -0
  3. package/dist/src/bootstrap/config/root-schema.d.ts +16 -0
  4. package/dist/src/bootstrap/delegation-authority.js +17 -0
  5. package/dist/src/bootstrap/surface-api-delivery.js +25 -0
  6. package/dist/src/bootstrap/version.js +1 -1
  7. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  8. package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
  9. package/dist/src/execution/application/candidate-workspaces.d.ts +13 -0
  10. package/dist/src/execution/application/candidate-workspaces.js +75 -0
  11. package/dist/src/execution/application/execution-service.js +27 -11
  12. package/dist/src/execution/application/run-lifecycle.js +1 -0
  13. package/dist/src/execution/contracts/candidate.d.ts +31 -0
  14. package/dist/src/execution/contracts/candidate.js +40 -0
  15. package/dist/src/execution/contracts/commands.d.ts +2 -0
  16. package/dist/src/execution/contracts/events.d.ts +11 -0
  17. package/dist/src/execution/contracts/events.js +2 -0
  18. package/dist/src/execution/contracts/repository-assignment.d.ts +5 -0
  19. package/dist/src/execution/contracts/repository-assignment.js +8 -0
  20. package/dist/src/execution/contracts/views.d.ts +2 -0
  21. package/dist/src/execution/contracts/vocabulary.d.ts +5 -0
  22. package/dist/src/execution/contracts/vocabulary.js +4 -0
  23. package/dist/src/execution/contracts/workspace.d.ts +6 -0
  24. package/dist/src/execution/index.d.ts +1 -0
  25. package/dist/src/execution/index.js +1 -0
  26. package/dist/src/execution/infrastructure/workspace/git-source.d.ts +2 -2
  27. package/dist/src/execution/infrastructure/workspace/git-source.js +18 -1
  28. package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +2 -4
  29. package/dist/src/execution/infrastructure/workspace/git-workspace.js +12 -1
  30. package/dist/src/orchestration/application/delegated-work.d.ts +5 -0
  31. package/dist/src/orchestration/application/delegated-work.js +10 -0
  32. package/dist/src/orchestration/application/delegation-commands.d.ts +13 -0
  33. package/dist/src/orchestration/application/delivery-coordinator.d.ts +279 -0
  34. package/dist/src/orchestration/application/delivery-coordinator.js +213 -0
  35. package/dist/src/orchestration/application/delivery-facts-reader.d.ts +9 -0
  36. package/dist/src/orchestration/application/delivery-facts-reader.js +46 -0
  37. package/dist/src/orchestration/application/delivery-preparation.d.ts +15 -0
  38. package/dist/src/orchestration/application/delivery-preparation.js +100 -0
  39. package/dist/src/orchestration/application/delivery-sources.d.ts +10 -0
  40. package/dist/src/orchestration/application/delivery-sources.js +41 -0
  41. package/dist/src/orchestration/application/orchestration-repository.d.ts +3 -1
  42. package/dist/src/orchestration/application/orchestration-repository.js +10 -1
  43. package/dist/src/orchestration/application/orchestration-service.d.ts +268 -0
  44. package/dist/src/orchestration/application/orchestration-service.js +33 -4
  45. package/dist/src/orchestration/contracts/config.d.ts +16 -0
  46. package/dist/src/orchestration/contracts/config.js +7 -1
  47. package/dist/src/orchestration/contracts/delegation-ports.d.ts +4 -0
  48. package/dist/src/orchestration/contracts/delegation.d.ts +13 -1
  49. package/dist/src/orchestration/contracts/delegation.js +5 -0
  50. package/dist/src/orchestration/contracts/delivery-ports.d.ts +9 -0
  51. package/dist/src/orchestration/contracts/delivery-ports.js +1 -0
  52. package/dist/src/orchestration/contracts/delivery.d.ts +252 -0
  53. package/dist/src/orchestration/contracts/delivery.js +134 -0
  54. package/dist/src/orchestration/contracts/event-decoder.js +13 -1
  55. package/dist/src/orchestration/contracts/event-factory.js +6 -0
  56. package/dist/src/orchestration/contracts/events.d.ts +8 -0
  57. package/dist/src/orchestration/contracts/events.js +3 -0
  58. package/dist/src/orchestration/contracts/views.d.ts +3 -0
  59. package/dist/src/orchestration/contracts/vocabulary.d.ts +47 -0
  60. package/dist/src/orchestration/contracts/vocabulary.js +43 -0
  61. package/dist/src/orchestration/domain/compiler.js +2 -0
  62. package/dist/src/orchestration/domain/delivery-candidate.d.ts +9 -0
  63. package/dist/src/orchestration/domain/delivery-candidate.js +92 -0
  64. package/dist/src/orchestration/domain/delivery-facts.d.ts +83 -0
  65. package/dist/src/orchestration/domain/delivery-facts.js +34 -0
  66. package/dist/src/orchestration/domain/delivery-qa.d.ts +32 -0
  67. package/dist/src/orchestration/domain/delivery-qa.js +77 -0
  68. package/dist/src/orchestration/domain/delivery-replacement.d.ts +9 -0
  69. package/dist/src/orchestration/domain/delivery-replacement.js +54 -0
  70. package/dist/src/orchestration/domain/delivery-selection.d.ts +17 -0
  71. package/dist/src/orchestration/domain/delivery-selection.js +132 -0
  72. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +4 -0
  73. package/dist/src/orchestration/domain/delivery-workflow-policy.js +13 -0
  74. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -13
  75. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  76. package/dist/src/orchestration/domain/workflow-instance-events.js +11 -0
  77. package/dist/src/orchestration/index.d.ts +2 -0
  78. package/dist/src/orchestration/index.js +1 -0
  79. package/dist/src/surfaces/api/contracts/work.d.ts +16 -0
  80. package/dist/src/surfaces/mcp/delegation.js +32 -1
  81. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +1192 -0
  82. package/dist/src/surfaces/web-assets/index.html +1 -1
  83. package/package.json +1 -1
  84. package/dist/src/surfaces/web-assets/assets/index-C5R-aWzH.js +0 -1192
@@ -0,0 +1,132 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { DeliveryRejection } from '../contracts/vocabulary.js';
3
+ import { childOf, currentSelection, entryKey, outputKey, qualifying, reject, requirements, } from './delivery-facts.js';
4
+ /**
5
+ * Validates a complete selection against the current one and the original requirements.
6
+ * An omitted requirement is never a waiver: every original output must stay covered by its own
7
+ * qualifying result or an authorized, criteria-preserving replacement that names the output
8
+ * currently selected.
9
+ */
10
+ export function reviseSelection(facts, command) {
11
+ const prior = facts.selections.find((entry) => entry.requestId === command.requestId);
12
+ const revision = currentSelection(facts)?.revision ?? 0;
13
+ if (prior !== undefined) {
14
+ if (prior.revision !== command.expectedRevision + 1 || !sameEntries(prior, command))
15
+ throw reject(DeliveryRejection.Conflict, 'Selection request identity was reused');
16
+ return { selection: prior, replay: true };
17
+ }
18
+ if (command.expectedRevision !== revision)
19
+ throw reject(DeliveryRejection.StaleSelection, `Selection is at revision ${revision}, not ${command.expectedRevision}; inspect and retry`);
20
+ const required = requirements(facts.reservations);
21
+ const seen = new Set();
22
+ const entries = command.entries.map((entry) => {
23
+ const requirement = required.find((candidate) => candidate.cohortId === entry.cohortId &&
24
+ candidate.assignmentId === entry.assignmentId &&
25
+ candidate.outputName === entry.output.outputName);
26
+ if (requirement === undefined)
27
+ throw reject(DeliveryRejection.UnknownRequirement, `${entryKey(entry, entry.output.outputName)} is not an original required output`);
28
+ const key = entryKey(entry, requirement.outputName);
29
+ if (seen.has(key))
30
+ throw reject(DeliveryRejection.Conflict, `${key} is selected twice`);
31
+ seen.add(key);
32
+ return selected(facts, entry, requirement);
33
+ });
34
+ const missing = required.filter((requirement) => !seen.has(entryKey(requirement, requirement.outputName)));
35
+ if (missing.length > 0)
36
+ throw reject(DeliveryRejection.UncoveredRequirement, `Original requirements are not covered: ${missing
37
+ .map((requirement) => entryKey(requirement, requirement.outputName))
38
+ .join(', ')}`);
39
+ return {
40
+ replay: false,
41
+ selection: { requestId: command.requestId, revision: revision + 1, entries },
42
+ };
43
+ }
44
+ function selected(facts, entry, requirement) {
45
+ const output = qualifying(facts, entry.output);
46
+ if (output === undefined)
47
+ throw reject(DeliveryRejection.OutputMismatch, `${outputKey(entry.output)} is not a qualifying result`);
48
+ if (entry.output.childWorkItemId === requirement.child.workItemId) {
49
+ if (entry.replaces !== undefined)
50
+ throw reject(DeliveryRejection.ReplacementConflict, `${entryKey(requirement, requirement.outputName)} is not a replacement`);
51
+ }
52
+ else
53
+ assertReplacement(facts, requirement, entry);
54
+ return entryOf(entry, requirement, output);
55
+ }
56
+ function entryOf(entry, requirement, output) {
57
+ return {
58
+ cohortId: requirement.cohortId,
59
+ assignmentId: requirement.assignmentId,
60
+ childWorkItemId: entry.output.childWorkItemId,
61
+ output,
62
+ ...(entry.replaces === undefined ? {} : { replaces: entry.replaces }),
63
+ };
64
+ }
65
+ function assertReplacement(facts, requirement, entry) {
66
+ const key = entryKey(requirement, requirement.outputName);
67
+ const found = childOf(facts.reservations, entry.output.childWorkItemId);
68
+ if (found?.child.replaces?.cohortId !== requirement.cohortId ||
69
+ found.child.replaces.assignmentId !== requirement.assignmentId)
70
+ throw reject(DeliveryRejection.ReplacementConflict, `${outputKey(entry.output)} was not delegated as a replacement for ${key}`);
71
+ if (!requirement.criteria.every((criterion) => found.child.criteria.includes(criterion)))
72
+ throw reject(DeliveryRejection.ReplacementConflict, `${outputKey(entry.output)} does not preserve the original acceptance criteria`);
73
+ const current = currentFor(facts, requirement);
74
+ if (entry.replaces === undefined && outputKey(entry.output) === outputKey(current))
75
+ return;
76
+ if (entry.replaces === undefined)
77
+ throw reject(DeliveryRejection.ReplacementConflict, `${key} replacement must name the output it replaces`);
78
+ if (outputKey(entry.replaces) !== outputKey(current))
79
+ throw reject(DeliveryRejection.ReplacementConflict, `${key} currently selects ${outputKey(current)}, not ${outputKey(entry.replaces)}`);
80
+ }
81
+ function currentFor(facts, requirement) {
82
+ const entry = currentSelection(facts)?.entries.find((candidate) => entryKey(candidate, candidate.output.name) === entryKey(requirement, requirement.outputName));
83
+ return entry === undefined
84
+ ? { childWorkItemId: requirement.child.workItemId, outputName: requirement.outputName }
85
+ : { childWorkItemId: entry.childWorkItemId, outputName: entry.output.name };
86
+ }
87
+ function sameEntries(prior, command) {
88
+ const priorKeys = prior.entries.map((entry) => `${entryKey(entry, entry.output.name)}/${entry.childWorkItemId}`);
89
+ const commandKeys = command.entries.map((entry) => `${entryKey(entry, entry.output.outputName)}/${entry.output.childWorkItemId}`);
90
+ return isDeepStrictEqual(priorKeys.sort(), commandKeys.sort());
91
+ }
92
+ /**
93
+ * Selected results whose upstream input was replaced. A superseded output makes every consumer
94
+ * stale, transitively; unrelated evidence is untouched and old facts stay in the history.
95
+ */
96
+ export function staleEntries(facts) {
97
+ const current = currentSelection(facts);
98
+ if (current === undefined)
99
+ return new Set();
100
+ const live = current.entries.map((entry) => entry.output.reference);
101
+ const dead = facts.selections
102
+ .flatMap((selection) => selection.entries)
103
+ .flatMap((entry) => (entry.replaces === undefined ? [] : [qualifying(facts, entry.replaces)]))
104
+ .flatMap((output) => (output === undefined ? [] : [output.reference]))
105
+ .filter((reference) => !live.some((candidate) => sameRevision(candidate, reference)));
106
+ const stale = new Set();
107
+ for (let changed = true; changed;) {
108
+ changed = false;
109
+ for (const entry of current.entries) {
110
+ const key = entryKey(entry, entry.output.name);
111
+ const consumed = facts.consumed.get(entry.childWorkItemId) ?? [];
112
+ if (stale.has(key) || !consumesAny(consumed, dead))
113
+ continue;
114
+ stale.add(key);
115
+ dead.push(entry.output.reference);
116
+ changed = true;
117
+ }
118
+ }
119
+ return stale;
120
+ }
121
+ const consumesAny = (consumed, dead) => consumed.some((input) => dead.some((reference) => sameRevision(reference, input.reference)));
122
+ /** Provider metadata can gain a base/merge observation without changing the consumed code. */
123
+ function sameRevision(a, b) {
124
+ if (a.workItemId !== b.workItemId)
125
+ return false;
126
+ if ('revisionId' in a)
127
+ return 'revisionId' in b && a.revisionId === b.revisionId;
128
+ return (!('revisionId' in b) &&
129
+ a.resourceId === b.resourceId &&
130
+ a.repositoryResourceId === b.repositoryResourceId &&
131
+ a.revision === b.revision);
132
+ }
@@ -0,0 +1,4 @@
1
+ import { type ActivityRegistry } from '../../activities/index.js';
2
+ import type { CompiledStage, WorkflowDefinitionConfig } from '../contracts/config.js';
3
+ import { type StageName } from '../contracts/identifiers.js';
4
+ export declare function assertDeliveryQa(config: WorkflowDefinitionConfig, stages: Readonly<Record<StageName, CompiledStage>>, activities: ActivityRegistry): void;
@@ -0,0 +1,13 @@
1
+ import { ActivityExecutionKind } from '../../activities/index.js';
2
+ import { WorkspaceMode } from '../../execution/index.js';
3
+ import { stageName } from '../contracts/identifiers.js';
4
+ export function assertDeliveryQa(config, stages, activities) {
5
+ const qa = config.delegation?.qa;
6
+ if (qa !== undefined) {
7
+ const stage = stages[stageName(qa.stage)];
8
+ if (stage === undefined ||
9
+ stage.execution?.workspace !== WorkspaceMode.ReadOnly ||
10
+ activities.describe(stage.activity).executionKind !== ActivityExecutionKind.Agent)
11
+ throw new Error('Delegation QA must name a configured read-only agent stage');
12
+ }
13
+ }
@@ -11,19 +11,25 @@ import { AwaitTimeoutBlockReason } from './signal-policy.js';
11
11
  const FailedOutcomeSignal = signalName(ActivityOutcomeKind.Failed);
12
12
  export function isOperatorRetryEligible(view) {
13
13
  const pending = view.pendingActivation;
14
+ const deliveryGate = view.status === WorkflowStatus.Blocked && view.deliveryGateBlock !== undefined;
14
15
  const eligibleActivation = pending !== undefined &&
15
- pending.status === ActivityActivationStatus.Completed &&
16
+ retryableActivationStatus(pending.status, deliveryGate) &&
16
17
  pending.supplemental !== true &&
17
- pending.followOnIndex === undefined &&
18
- view.acceptedOutcomes.includes(pending.activationId);
18
+ (pending.followOnIndex === undefined || deliveryGate) &&
19
+ (deliveryGate || view.acceptedOutcomes.includes(pending.activationId));
19
20
  if (!eligibleActivation || pending === undefined)
20
21
  return false;
21
22
  if (view.status === WorkflowStatus.Blocked)
22
23
  return isRetryEligibleBlock(view, pending);
23
24
  return isRetryEligibleFailedWait(view);
24
25
  }
26
+ function retryableActivationStatus(status, deliveryGate) {
27
+ return (status === ActivityActivationStatus.Completed ||
28
+ (deliveryGate && status === ActivityActivationStatus.Waiting));
29
+ }
25
30
  function isRetryEligibleBlock(view, pending) {
26
- return (view.blockReason === AwaitTimeoutBlockReason ||
31
+ return (view.deliveryGateBlock !== undefined ||
32
+ view.blockReason === AwaitTimeoutBlockReason ||
27
33
  (view.blockReason === 'unconfigured outcome failed' &&
28
34
  view.lastOutcome?.kind === ActivityOutcomeKind.Failed) ||
29
35
  view.executionFailure?.activationId === pending.activationId);
@@ -114,7 +120,10 @@ function requestRetry(definition, state, input, sessionPolicy) {
114
120
  kind: 'ignored',
115
121
  reason: 'workflow is not in a retryable failed-stage state',
116
122
  };
117
- const stage = definition.stages[stageName(state.currentStage)];
123
+ const retryStage = state.deliveryGateBlock?.retryStage ?? state.currentStage;
124
+ const stage = definition.stages[retryStage];
125
+ if (state.deliveryGateBlock !== undefined)
126
+ sessionPolicy = 'fresh';
118
127
  const events = [
119
128
  stateDraft(state, input, {
120
129
  eventType: OrchestrationEventType.OperatorRetryRequested,
@@ -123,15 +132,17 @@ function requestRetry(definition, state, input, sessionPolicy) {
123
132
  commandId: input.commandId,
124
133
  },
125
134
  }, 1),
126
- stateDraft(state, input, {
127
- eventType: OrchestrationEventType.ActivityRequested,
128
- payload: activation(state.workflowInstanceId, nextOrdinal(state), stage.activity, stage.with, {
129
- execution: stage.execution,
130
- stage: stageName(state.currentStage),
131
- ...(sessionPolicy === undefined ? {} : { sessionPolicy }),
132
- }),
133
- }, 2),
134
135
  ];
136
+ if (retryStage !== state.currentStage)
137
+ events.push(stateDraft(state, input, { eventType: OrchestrationEventType.StageEntered, payload: { stage: retryStage } }, 2));
138
+ events.push(stateDraft(state, input, {
139
+ eventType: OrchestrationEventType.ActivityRequested,
140
+ payload: activation(state.workflowInstanceId, nextOrdinal(state), stage.activity, stage.with, {
141
+ execution: stage.execution,
142
+ stage: retryStage,
143
+ ...(sessionPolicy === undefined ? {} : { sessionPolicy }),
144
+ }),
145
+ }, events.length + 1));
135
146
  return { kind: 'append', events };
136
147
  }
137
148
  export function requestChangesResume(definition, state, input) {
@@ -27,6 +27,7 @@ export type MutableWorkflowInstance = {
27
27
  delegationAttention?: WorkflowInstanceView['delegationAttention'];
28
28
  status: WorkflowInstanceView['status'];
29
29
  blockReason?: string;
30
+ deliveryGateBlock?: NonNullable<WorkflowInstanceView['deliveryGateBlock']>;
30
31
  currentStage: WorkflowInstanceView['currentStage'];
31
32
  pendingActivation?: ActivityActivationView;
32
33
  repeatCounts: Record<string, number>;
@@ -139,6 +139,10 @@ function applyLifecycleFact(state, event) {
139
139
  delete state.delegationAttention;
140
140
  state.status = orchestrationStatusTransitions[OrchestrationEventType.InstanceBlocked];
141
141
  state.blockReason = event.payload.reason;
142
+ if (event.payload.deliveryGate === undefined)
143
+ delete state.deliveryGateBlock;
144
+ else
145
+ state.deliveryGateBlock = event.payload.deliveryGate;
142
146
  return;
143
147
  case OrchestrationEventType.OperatorRetryRequested:
144
148
  state.operatorRetryCommandIds.push(event.payload.commandId);
@@ -209,6 +213,9 @@ function applyCoordinationFact(state, event) {
209
213
  case OrchestrationEventType.DelegationPrerequisiteBlocked:
210
214
  case OrchestrationEventType.DelegationChildBlocked:
211
215
  case OrchestrationEventType.DelegationResultSelected:
216
+ case OrchestrationEventType.DeliverySelectionRevised:
217
+ case OrchestrationEventType.DeliveryCandidateRecorded:
218
+ case OrchestrationEventType.DeliveryQaRecorded:
212
219
  return;
213
220
  case OrchestrationEventType.DelegationWaitStarted:
214
221
  case OrchestrationEventType.DelegationJoined:
@@ -263,6 +270,7 @@ function updateActivationStatus(state, activationId, status) {
263
270
  function applyActivityRequested(state, payload) {
264
271
  state.status = orchestrationStatusTransitions[OrchestrationEventType.ActivityRequested];
265
272
  delete state.waitingFor;
273
+ delete state.deliveryGateBlock;
266
274
  state.pendingActivation = {
267
275
  ...(payload.notBefore === undefined ? {} : { notBefore: payload.notBefore }),
268
276
  activationId: payload.activationId,
@@ -303,6 +311,9 @@ export function immutableWorkflowInstanceView(state) {
303
311
  : { delegationAttention: state.delegationAttention }),
304
312
  status: state.status,
305
313
  ...(state.blockReason === undefined ? {} : { blockReason: state.blockReason }),
314
+ ...(state.deliveryGateBlock === undefined
315
+ ? {}
316
+ : { deliveryGateBlock: state.deliveryGateBlock }),
306
317
  currentStage: state.currentStage,
307
318
  repeatCounts: state.repeatCounts,
308
319
  retryCounts: state.retryCounts,
@@ -35,5 +35,7 @@ export type { WorkflowCompileDiagnostic } from './domain/compile-diagnostics.js'
35
35
  export type { DelegationArtifacts, DelegationRepositories } from './contracts/delegation-ports.js';
36
36
  export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
37
37
  export type { DelegationAuthority } from './contracts/delegation-ports.js';
38
+ export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
39
+ export type { DeliveryCandidate, DeliveryCandidateCommand, DeliveryQa, DeliveryQaCommand, DeliverySelection, DeliverySelectionCommand, } from './contracts/delivery.js';
38
40
  export { delegationAttentionReplySchema, delegationSubmissionSchema, } from './contracts/delegation.js';
39
41
  export type { DelegationAttentionBlocker, DelegationAttentionReply, DelegationAttentionRequest, DelegationCaller, DelegationInputs, DelegationPrerequisite, DelegationReservation, DelegationResult, DelegationSubmission, } from './contracts/delegation.js';
@@ -32,4 +32,5 @@ export * from './domain/workflow-instance.js';
32
32
  export * from './domain/workflow-selector.js';
33
33
  export * from './application/work-completion-summary.js';
34
34
  export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
35
+ export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
35
36
  export { delegationAttentionReplySchema, delegationSubmissionSchema, } from './contracts/delegation.js';
@@ -18,8 +18,24 @@ export interface WorkItemResponse {
18
18
  /** Raw outcome emitted by the latest agent run, when one is available. */
19
19
  readonly lastRunOutcome?: string;
20
20
  }
21
+ export interface DeliveryQaResponse {
22
+ readonly selectionRevision: number;
23
+ readonly candidateId?: string;
24
+ readonly repositories: readonly {
25
+ readonly resourceId: string;
26
+ readonly revision: string;
27
+ }[];
28
+ readonly stale: readonly string[];
29
+ readonly verdict?: string;
30
+ readonly effective: boolean;
31
+ readonly canComplete: boolean;
32
+ readonly reason?: string;
33
+ readonly exhausted: boolean;
34
+ readonly findings: readonly string[];
35
+ }
21
36
  export interface WorkDetailResponse {
22
37
  readonly delegation?: {
38
+ readonly qa?: DeliveryQaResponse;
23
39
  readonly rootWorkItemKey: WorkItemKey;
24
40
  readonly parentWorkItemKey?: WorkItemKey;
25
41
  readonly children: readonly {
@@ -1,4 +1,4 @@
1
- import { DelegationAttentionError, DelegationConflictError, delegationAttentionReplySchema, delegationSubmissionSchema, } from '../../orchestration/index.js';
1
+ import { DelegationAttentionError, DelegationConflictError, DeliveryRejectionError, delegationAttentionReplySchema, delegationSubmissionSchema, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from '../../orchestration/index.js';
2
2
  /** The bound caller is never accepted as a tool argument. */
3
3
  export function registerDelegationTools(server, input) {
4
4
  server.registerTool('wake_delegation_submit', {
@@ -39,6 +39,37 @@ export function registerDelegationTools(server, input) {
39
39
  };
40
40
  }
41
41
  });
42
+ // Rejections carry a typed code so the agent can correct the request instead of retrying.
43
+ const guarded = async (run) => {
44
+ try {
45
+ return { content: [{ type: 'text', text: JSON.stringify(await run()) }] };
46
+ }
47
+ catch (error) {
48
+ if (!(error instanceof DeliveryRejectionError))
49
+ throw error;
50
+ return {
51
+ isError: true,
52
+ content: [
53
+ {
54
+ type: 'text',
55
+ text: JSON.stringify({ code: error.code, message: error.message }),
56
+ },
57
+ ],
58
+ };
59
+ }
60
+ };
61
+ server.registerTool('wake_delivery_select', {
62
+ description: 'Record the complete current delivery selection: for every original required output, the qualifying child output that covers it, or an authorized replacement that names the output it replaces. Pass expectedRevision from wake_delegation_inspect (delivery.selectionRevision). Omitting a required output, selecting an unqualified output or replacing a stale choice is rejected.',
63
+ inputSchema: deliverySelectionCommandSchema,
64
+ }, async (command) => guarded(async () => input.orchestration.selectDelivery(await input.caller(), command, input.commandContext())));
65
+ server.registerTool('wake_delivery_candidate', {
66
+ description: 'Record the exact combined candidate for the current selection: one repository entry per repository with selected changes, using the selected output tip (a single change or intentional stack) or an assembled commit pushed under refs/wake/delivery/<root>/<candidateId>/. Wake verifies the commit is fetchable from the repository before QA can rely on it.',
67
+ inputSchema: deliveryCandidateCommandSchema,
68
+ }, async (command) => guarded(async () => input.orchestration.recordDeliveryCandidate(await input.caller(), command, input.commandContext())));
69
+ server.registerTool('wake_delivery_qa', {
70
+ description: 'Record the QA verdict for a recorded candidate. Name the exact repository revisions checked; they must equal the candidate set. Use verdict blocked when the environment or a source is unavailable, fail with findings when defects remain, and pass only after the configured recipe ran.',
71
+ inputSchema: deliveryQaCommandSchema,
72
+ }, async (command) => guarded(async () => input.orchestration.recordDeliveryQa(await input.caller(), command, input.commandContext())));
42
73
  server.registerTool('wake_delegation_inspect', {
43
74
  description: 'Inspect this delivery tree, child workflows, results and blockers, and the Repository Resource IDs an explicit repository selection may name.',
44
75
  }, async () => ({