@atolis-hq/wake 0.4.103 → 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.
- package/dist/src/activities/agent/agent-activity.js +3 -0
- package/dist/src/activities/contracts/activity.d.ts +16 -0
- package/dist/src/bootstrap/artifact-mcp.js +20 -1
- package/dist/src/bootstrap/config/root-schema.d.ts +16 -0
- package/dist/src/bootstrap/delegation-authority.js +17 -0
- package/dist/src/bootstrap/surface-api-delivery.js +25 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
- package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
- package/dist/src/execution/application/candidate-workspaces.d.ts +13 -0
- package/dist/src/execution/application/candidate-workspaces.js +75 -0
- package/dist/src/execution/application/execution-service.js +27 -11
- package/dist/src/execution/application/run-lifecycle.js +1 -0
- package/dist/src/execution/contracts/candidate.d.ts +31 -0
- package/dist/src/execution/contracts/candidate.js +40 -0
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +11 -0
- package/dist/src/execution/contracts/events.js +2 -0
- package/dist/src/execution/contracts/repository-assignment.d.ts +5 -0
- package/dist/src/execution/contracts/repository-assignment.js +8 -0
- package/dist/src/execution/contracts/views.d.ts +2 -0
- package/dist/src/execution/contracts/vocabulary.d.ts +5 -0
- package/dist/src/execution/contracts/vocabulary.js +4 -0
- package/dist/src/execution/contracts/workspace.d.ts +6 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/execution/infrastructure/workspace/git-source.d.ts +2 -2
- package/dist/src/execution/infrastructure/workspace/git-source.js +18 -1
- package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +2 -4
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +12 -1
- package/dist/src/orchestration/application/conversation-command-reactor.js +25 -0
- package/dist/src/orchestration/application/delegated-work.d.ts +14 -0
- package/dist/src/orchestration/application/delegated-work.js +63 -20
- package/dist/src/orchestration/application/delegation-attention-escalations.d.ts +11 -0
- package/dist/src/orchestration/application/delegation-attention-escalations.js +36 -0
- package/dist/src/orchestration/application/delegation-attention-state.d.ts +53 -0
- package/dist/src/orchestration/application/delegation-attention-state.js +194 -0
- package/dist/src/orchestration/application/delegation-attention.d.ts +58 -0
- package/dist/src/orchestration/application/delegation-attention.js +206 -0
- package/dist/src/orchestration/application/delegation-commands.d.ts +18 -1
- package/dist/src/orchestration/application/delegation-commands.js +18 -1
- package/dist/src/orchestration/application/delegation-gate.d.ts +4 -1
- package/dist/src/orchestration/application/delegation-gate.js +15 -3
- package/dist/src/orchestration/application/delivery-coordinator.d.ts +279 -0
- package/dist/src/orchestration/application/delivery-coordinator.js +213 -0
- package/dist/src/orchestration/application/delivery-facts-reader.d.ts +9 -0
- package/dist/src/orchestration/application/delivery-facts-reader.js +46 -0
- package/dist/src/orchestration/application/delivery-preparation.d.ts +15 -0
- package/dist/src/orchestration/application/delivery-preparation.js +100 -0
- package/dist/src/orchestration/application/delivery-sources.d.ts +10 -0
- package/dist/src/orchestration/application/delivery-sources.js +41 -0
- package/dist/src/orchestration/application/orchestration-repository.d.ts +3 -1
- package/dist/src/orchestration/application/orchestration-repository.js +10 -1
- package/dist/src/orchestration/application/orchestration-service.d.ts +284 -1
- package/dist/src/orchestration/application/orchestration-service.js +71 -5
- package/dist/src/orchestration/contracts/config.d.ts +16 -0
- package/dist/src/orchestration/contracts/config.js +7 -1
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +4 -0
- package/dist/src/orchestration/contracts/delegation.d.ts +76 -2
- package/dist/src/orchestration/contracts/delegation.js +54 -1
- package/dist/src/orchestration/contracts/delivery-ports.d.ts +9 -0
- package/dist/src/orchestration/contracts/delivery-ports.js +1 -0
- package/dist/src/orchestration/contracts/delivery.d.ts +252 -0
- package/dist/src/orchestration/contracts/delivery.js +134 -0
- package/dist/src/orchestration/contracts/event-decoder.js +17 -2
- package/dist/src/orchestration/contracts/event-factory.js +13 -1
- package/dist/src/orchestration/contracts/events.d.ts +23 -1
- package/dist/src/orchestration/contracts/events.js +6 -0
- package/dist/src/orchestration/contracts/views.d.ts +9 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +65 -0
- package/dist/src/orchestration/contracts/vocabulary.js +59 -0
- package/dist/src/orchestration/domain/compiler.js +2 -0
- package/dist/src/orchestration/domain/delivery-candidate.d.ts +9 -0
- package/dist/src/orchestration/domain/delivery-candidate.js +92 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +83 -0
- package/dist/src/orchestration/domain/delivery-facts.js +34 -0
- package/dist/src/orchestration/domain/delivery-qa.d.ts +32 -0
- package/dist/src/orchestration/domain/delivery-qa.js +77 -0
- package/dist/src/orchestration/domain/delivery-replacement.d.ts +9 -0
- package/dist/src/orchestration/domain/delivery-replacement.js +54 -0
- package/dist/src/orchestration/domain/delivery-selection.d.ts +17 -0
- package/dist/src/orchestration/domain/delivery-selection.js +132 -0
- package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +4 -0
- package/dist/src/orchestration/domain/delivery-workflow-policy.js +13 -0
- package/dist/src/orchestration/domain/operator-retry-policy.js +24 -13
- package/dist/src/orchestration/domain/workflow-instance-events.d.ts +2 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +39 -0
- package/dist/src/orchestration/index.d.ts +5 -3
- package/dist/src/orchestration/index.js +3 -2
- package/dist/src/surfaces/api/contracts/work.d.ts +16 -0
- package/dist/src/surfaces/mcp/delegation.js +51 -1
- package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-C5R-aWzH.js +0 -1192
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DelegationConflictError } from '../contracts/delegation.js';
|
|
2
|
+
import { DelegationConflictCode } from '../contracts/vocabulary.js';
|
|
3
|
+
import { isChange } from './delivery-facts.js';
|
|
4
|
+
const invalid = (message) => new DelegationConflictError(DelegationConflictCode.ReplacementInvalid, message);
|
|
5
|
+
/** The original must be a required assignment of this delivery, never another replacement. */
|
|
6
|
+
export function originalOf(facts, replaces) {
|
|
7
|
+
const original = facts.reservations
|
|
8
|
+
.filter((reservation) => reservation.cohortId === replaces.cohortId)
|
|
9
|
+
.flatMap((reservation) => reservation.children)
|
|
10
|
+
.find((child) => child.assignmentId === replaces.assignmentId && child.replaces === undefined);
|
|
11
|
+
if (original === undefined)
|
|
12
|
+
throw invalid('A replacement must name an original required assignment of this delivery');
|
|
13
|
+
return original;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A corrective child keeps the original acceptance criteria, repository and outputs. When the
|
|
17
|
+
* original contribution is unmerged it must be the starting point, aimed at the intended base.
|
|
18
|
+
*/
|
|
19
|
+
export function assertCriteriaPreserving(facts, original, assignment) {
|
|
20
|
+
if (!original.criteria.every((criterion) => assignment.criteria.includes(criterion)))
|
|
21
|
+
throw invalid('A replacement must preserve every original acceptance criterion');
|
|
22
|
+
if (original.repository?.resourceId !== assignment.repository?.resourceId)
|
|
23
|
+
throw invalid('A replacement must target the original repository');
|
|
24
|
+
assertOutputsProvided(original, assignment);
|
|
25
|
+
const unmerged = facts.results
|
|
26
|
+
.filter((entry) => entry.childWorkItemId === original.workItemId)
|
|
27
|
+
.flatMap((entry) => entry.outputs.filter(isChange))
|
|
28
|
+
.map((output) => output.reference)
|
|
29
|
+
.filter((reference) => reference.merged !== true);
|
|
30
|
+
for (const reference of unmerged)
|
|
31
|
+
assertCarriesContribution(assignment, reference);
|
|
32
|
+
}
|
|
33
|
+
function assertOutputsProvided(original, assignment) {
|
|
34
|
+
for (const output of original.outputs) {
|
|
35
|
+
const counterpart = assignment.outputs.find((entry) => entry.name === output.name);
|
|
36
|
+
if (counterpart === undefined || 'kind' in output !== 'kind' in counterpart)
|
|
37
|
+
throw invalid(`A replacement must provide the original output ${output.name}`);
|
|
38
|
+
if ('kind' in output && 'kind' in counterpart)
|
|
39
|
+
assertChangeRequirements(output, counterpart);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function assertCarriesContribution(assignment, reference) {
|
|
43
|
+
const repository = assignment.repository;
|
|
44
|
+
if (repository?.sourceRevision !== reference.revision)
|
|
45
|
+
throw invalid(`A replacement must start from the unmerged contribution ${reference.branch}@${reference.revision}`);
|
|
46
|
+
if (repository.pullRequestBase !== reference.pullRequestBase)
|
|
47
|
+
throw invalid(`A replacement must target the intended integration branch ${reference.pullRequestBase}`);
|
|
48
|
+
}
|
|
49
|
+
function assertChangeRequirements(original, replacement) {
|
|
50
|
+
if ((original.requireReview ?? true) && !(replacement.requireReview ?? true))
|
|
51
|
+
throw invalid('A replacement must preserve the original review requirement');
|
|
52
|
+
if ((original.requireChecks ?? true) && !(replacement.requireChecks ?? true))
|
|
53
|
+
throw invalid('A replacement must preserve the original checks requirement');
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DeliverySelection, DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
2
|
+
import { type DeliveryFacts } from './delivery-facts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates a complete selection against the current one and the original requirements.
|
|
5
|
+
* An omitted requirement is never a waiver: every original output must stay covered by its own
|
|
6
|
+
* qualifying result or an authorized, criteria-preserving replacement that names the output
|
|
7
|
+
* currently selected.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reviseSelection(facts: DeliveryFacts, command: DeliverySelectionCommand): {
|
|
10
|
+
readonly selection: DeliverySelection;
|
|
11
|
+
readonly replay: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Selected results whose upstream input was replaced. A superseded output makes every consumer
|
|
15
|
+
* stale, transitively; unrelated evidence is untouched and old facts stay in the history.
|
|
16
|
+
*/
|
|
17
|
+
export declare function staleEntries(facts: DeliveryFacts): ReadonlySet<string>;
|
|
@@ -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
|
|
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.
|
|
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
|
|
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) {
|
|
@@ -24,8 +24,10 @@ export type MutableWorkflowInstance = {
|
|
|
24
24
|
requestId?: string;
|
|
25
25
|
delegationFence?: WorkflowInstanceView['delegationFence'];
|
|
26
26
|
delegationWait?: WorkflowInstanceView['delegationWait'];
|
|
27
|
+
delegationAttention?: WorkflowInstanceView['delegationAttention'];
|
|
27
28
|
status: WorkflowInstanceView['status'];
|
|
28
29
|
blockReason?: string;
|
|
30
|
+
deliveryGateBlock?: NonNullable<WorkflowInstanceView['deliveryGateBlock']>;
|
|
29
31
|
currentStage: WorkflowInstanceView['currentStage'];
|
|
30
32
|
pendingActivation?: ActivityActivationView;
|
|
31
33
|
repeatCounts: Record<string, number>;
|
|
@@ -129,20 +129,27 @@ function applyLifecycleFact(state, event) {
|
|
|
129
129
|
return;
|
|
130
130
|
case OrchestrationEventType.InstanceCompleted:
|
|
131
131
|
delete state.delegationWait;
|
|
132
|
+
delete state.delegationAttention;
|
|
132
133
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.InstanceCompleted];
|
|
133
134
|
delete state.pendingActivation;
|
|
134
135
|
delete state.waitingFor;
|
|
135
136
|
return;
|
|
136
137
|
case OrchestrationEventType.InstanceBlocked:
|
|
137
138
|
delete state.delegationWait;
|
|
139
|
+
delete state.delegationAttention;
|
|
138
140
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.InstanceBlocked];
|
|
139
141
|
state.blockReason = event.payload.reason;
|
|
142
|
+
if (event.payload.deliveryGate === undefined)
|
|
143
|
+
delete state.deliveryGateBlock;
|
|
144
|
+
else
|
|
145
|
+
state.deliveryGateBlock = event.payload.deliveryGate;
|
|
140
146
|
return;
|
|
141
147
|
case OrchestrationEventType.OperatorRetryRequested:
|
|
142
148
|
state.operatorRetryCommandIds.push(event.payload.commandId);
|
|
143
149
|
return;
|
|
144
150
|
case OrchestrationEventType.InstanceSuperseded:
|
|
145
151
|
delete state.delegationWait;
|
|
152
|
+
delete state.delegationAttention;
|
|
146
153
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.InstanceSuperseded];
|
|
147
154
|
return;
|
|
148
155
|
default:
|
|
@@ -152,6 +159,7 @@ function applyLifecycleFact(state, event) {
|
|
|
152
159
|
function applyDelegationFact(state, event) {
|
|
153
160
|
if (event.eventType === OrchestrationEventType.DelegationJoined) {
|
|
154
161
|
delete state.delegationWait;
|
|
162
|
+
delete state.delegationAttention;
|
|
155
163
|
delete state.delegationFence;
|
|
156
164
|
return;
|
|
157
165
|
}
|
|
@@ -168,6 +176,27 @@ function applyCoordinationFact(state, event) {
|
|
|
168
176
|
case OrchestrationEventType.GroupBudgetExhausted:
|
|
169
177
|
case OrchestrationEventType.DelegationFailed:
|
|
170
178
|
delete state.delegationFence;
|
|
179
|
+
delete state.delegationAttention;
|
|
180
|
+
return;
|
|
181
|
+
case OrchestrationEventType.DelegationAttentionRequested:
|
|
182
|
+
state.delegationAttention = {
|
|
183
|
+
cohortId: event.payload.cohortId,
|
|
184
|
+
attentionKey: event.payload.attentionKey,
|
|
185
|
+
activationId: event.payload.activationId,
|
|
186
|
+
};
|
|
187
|
+
return;
|
|
188
|
+
case OrchestrationEventType.DelegationAttentionResolved:
|
|
189
|
+
// The assessment is not an outcome route: the unresolved cohort wait is simply restored.
|
|
190
|
+
if (state.delegationAttention?.attentionKey !== event.payload.attentionKey)
|
|
191
|
+
return;
|
|
192
|
+
delete state.delegationAttention;
|
|
193
|
+
if (!state.acceptedOutcomes.includes(event.payload.activationId))
|
|
194
|
+
state.acceptedOutcomes.push(event.payload.activationId);
|
|
195
|
+
updateActivationStatus(state, event.payload.activationId, ActivityActivationStatus.Completed);
|
|
196
|
+
if (state.delegationWait !== undefined)
|
|
197
|
+
state.status = WorkflowStatus.Waiting;
|
|
198
|
+
return;
|
|
199
|
+
case OrchestrationEventType.DelegationAttentionResponded:
|
|
171
200
|
return;
|
|
172
201
|
case OrchestrationEventType.DelegationReconciliationFailed:
|
|
173
202
|
case OrchestrationEventType.SignalDeferred:
|
|
@@ -184,6 +213,9 @@ function applyCoordinationFact(state, event) {
|
|
|
184
213
|
case OrchestrationEventType.DelegationPrerequisiteBlocked:
|
|
185
214
|
case OrchestrationEventType.DelegationChildBlocked:
|
|
186
215
|
case OrchestrationEventType.DelegationResultSelected:
|
|
216
|
+
case OrchestrationEventType.DeliverySelectionRevised:
|
|
217
|
+
case OrchestrationEventType.DeliveryCandidateRecorded:
|
|
218
|
+
case OrchestrationEventType.DeliveryQaRecorded:
|
|
187
219
|
return;
|
|
188
220
|
case OrchestrationEventType.DelegationWaitStarted:
|
|
189
221
|
case OrchestrationEventType.DelegationJoined:
|
|
@@ -238,6 +270,7 @@ function updateActivationStatus(state, activationId, status) {
|
|
|
238
270
|
function applyActivityRequested(state, payload) {
|
|
239
271
|
state.status = orchestrationStatusTransitions[OrchestrationEventType.ActivityRequested];
|
|
240
272
|
delete state.waitingFor;
|
|
273
|
+
delete state.deliveryGateBlock;
|
|
241
274
|
state.pendingActivation = {
|
|
242
275
|
...(payload.notBefore === undefined ? {} : { notBefore: payload.notBefore }),
|
|
243
276
|
activationId: payload.activationId,
|
|
@@ -273,8 +306,14 @@ export function immutableWorkflowInstanceView(state) {
|
|
|
273
306
|
...(state.requestId === undefined ? {} : { requestId: state.requestId }),
|
|
274
307
|
...(state.delegationFence === undefined ? {} : { delegationFence: state.delegationFence }),
|
|
275
308
|
...(state.delegationWait === undefined ? {} : { delegationWait: state.delegationWait }),
|
|
309
|
+
...(state.delegationAttention === undefined
|
|
310
|
+
? {}
|
|
311
|
+
: { delegationAttention: state.delegationAttention }),
|
|
276
312
|
status: state.status,
|
|
277
313
|
...(state.blockReason === undefined ? {} : { blockReason: state.blockReason }),
|
|
314
|
+
...(state.deliveryGateBlock === undefined
|
|
315
|
+
? {}
|
|
316
|
+
: { deliveryGateBlock: state.deliveryGateBlock }),
|
|
278
317
|
currentStage: state.currentStage,
|
|
279
318
|
repeatCounts: state.repeatCounts,
|
|
280
319
|
retryCounts: state.retryCounts,
|
|
@@ -33,7 +33,9 @@ export * from './domain/workflow-selector.js';
|
|
|
33
33
|
export * from './application/work-completion-summary.js';
|
|
34
34
|
export type { WorkflowCompileDiagnostic } from './domain/compile-diagnostics.js';
|
|
35
35
|
export type { DelegationArtifacts, DelegationRepositories } from './contracts/delegation-ports.js';
|
|
36
|
-
export { DelegationConflictError, DelegationPendingError } from './contracts/delegation.js';
|
|
36
|
+
export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
|
|
37
37
|
export type { DelegationAuthority } from './contracts/delegation-ports.js';
|
|
38
|
-
export {
|
|
39
|
-
export type {
|
|
38
|
+
export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
|
|
39
|
+
export type { DeliveryCandidate, DeliveryCandidateCommand, DeliveryQa, DeliveryQaCommand, DeliverySelection, DeliverySelectionCommand, } from './contracts/delivery.js';
|
|
40
|
+
export { delegationAttentionReplySchema, delegationSubmissionSchema, } from './contracts/delegation.js';
|
|
41
|
+
export type { DelegationAttentionBlocker, DelegationAttentionReply, DelegationAttentionRequest, DelegationCaller, DelegationInputs, DelegationPrerequisite, DelegationReservation, DelegationResult, DelegationSubmission, } from './contracts/delegation.js';
|
|
@@ -31,5 +31,6 @@ export * from './domain/interpreter.js';
|
|
|
31
31
|
export * from './domain/workflow-instance.js';
|
|
32
32
|
export * from './domain/workflow-selector.js';
|
|
33
33
|
export * from './application/work-completion-summary.js';
|
|
34
|
-
export { DelegationConflictError, DelegationPendingError } from './contracts/delegation.js';
|
|
35
|
-
export {
|
|
34
|
+
export { DelegationAttentionError, DelegationConflictError, DelegationPendingError, } from './contracts/delegation.js';
|
|
35
|
+
export { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from './contracts/delivery.js';
|
|
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 { DelegationConflictError, 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', {
|
|
@@ -20,6 +20,56 @@ export function registerDelegationTools(server, input) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
server.registerTool('wake_delegation_respond', {
|
|
24
|
+
description: 'Answer one assignment-context blocker from the attention request returned by wake_delegation_inspect. Name the child, blocker and expectedRevision, and list the exact accepted artifact revisions the child may read. Only a child blocked for assignment context can be resumed; failures need follow-up work in a new cohort and human review, consent or approval gates cannot be answered here. End the activity normally afterwards; unresolved reasons stay tracked and the cohort wait resumes.',
|
|
25
|
+
inputSchema: delegationAttentionReplySchema,
|
|
26
|
+
}, async (reply) => {
|
|
27
|
+
try {
|
|
28
|
+
const attention = await input.orchestration.respondToDelegationAttention(await input.caller(), reply, input.commandContext());
|
|
29
|
+
return { content: [{ type: 'text', text: JSON.stringify(attention) }] };
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!(error instanceof DelegationAttentionError))
|
|
33
|
+
throw error;
|
|
34
|
+
return {
|
|
35
|
+
isError: true,
|
|
36
|
+
content: [
|
|
37
|
+
{ type: 'text', text: JSON.stringify({ code: error.code, message: error.message }) },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
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())));
|
|
23
73
|
server.registerTool('wake_delegation_inspect', {
|
|
24
74
|
description: 'Inspect this delivery tree, child workflows, results and blockers, and the Repository Resource IDs an explicit repository selection may name.',
|
|
25
75
|
}, async () => ({
|