@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.
- package/dist/src/activities/agent/agent-activity.js +3 -0
- package/dist/src/activities/contracts/activity.d.ts +16 -0
- 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/delegated-work.d.ts +5 -0
- package/dist/src/orchestration/application/delegated-work.js +10 -0
- package/dist/src/orchestration/application/delegation-commands.d.ts +13 -0
- 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 +268 -0
- package/dist/src/orchestration/application/orchestration-service.js +33 -4
- 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 +13 -1
- package/dist/src/orchestration/contracts/delegation.js +5 -0
- 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 +13 -1
- package/dist/src/orchestration/contracts/event-factory.js +6 -0
- package/dist/src/orchestration/contracts/events.d.ts +8 -0
- package/dist/src/orchestration/contracts/events.js +3 -0
- package/dist/src/orchestration/contracts/views.d.ts +3 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +47 -0
- package/dist/src/orchestration/contracts/vocabulary.js +43 -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 +1 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +11 -0
- package/dist/src/orchestration/index.d.ts +2 -0
- package/dist/src/orchestration/index.js +1 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +16 -0
- package/dist/src/surfaces/mcp/delegation.js +32 -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
|
@@ -84,6 +84,8 @@ export declare const DelegationConflictCode: {
|
|
|
84
84
|
readonly WaitCycle: "wait-cycle";
|
|
85
85
|
readonly StalePlan: "stale-plan";
|
|
86
86
|
readonly AttentionOpen: "attention-open";
|
|
87
|
+
readonly ReplacementUnsupported: "replacement-unsupported";
|
|
88
|
+
readonly ReplacementInvalid: "replacement-invalid";
|
|
87
89
|
};
|
|
88
90
|
export type DelegationConflictCode = ValueOf<typeof DelegationConflictCode>;
|
|
89
91
|
export declare const PrerequisiteBlockCode: {
|
|
@@ -95,3 +97,48 @@ export declare const PrerequisiteBlockCode: {
|
|
|
95
97
|
readonly Blocked: "prerequisite-blocked";
|
|
96
98
|
};
|
|
97
99
|
export type PrerequisiteBlockCode = ValueOf<typeof PrerequisiteBlockCode>;
|
|
100
|
+
export declare const DeliveryRejection: {
|
|
101
|
+
/** The submitted revision is not the current one; re-inspect before retrying. */
|
|
102
|
+
readonly StaleSelection: "stale-selection";
|
|
103
|
+
/** An original required assignment has no qualifying output or authorized replacement. */
|
|
104
|
+
readonly UncoveredRequirement: "uncovered-requirement";
|
|
105
|
+
readonly UnknownRequirement: "unknown-requirement";
|
|
106
|
+
/** The named output is not a qualifying result of the claimed child. */
|
|
107
|
+
readonly OutputMismatch: "output-mismatch";
|
|
108
|
+
/** A replacement did not name the output currently selected, or is not criteria-preserving. */
|
|
109
|
+
readonly ReplacementConflict: "replacement-conflict";
|
|
110
|
+
/** The selection still contains results whose upstream input was replaced. */
|
|
111
|
+
readonly StaleOutput: "stale-output";
|
|
112
|
+
readonly NoSelection: "no-selection";
|
|
113
|
+
readonly CandidateCoverage: "candidate-coverage";
|
|
114
|
+
/** A retained ref is missing, outside the delivery namespace, or no longer at its recorded commit. */
|
|
115
|
+
readonly SourceUnavailable: "source-unavailable";
|
|
116
|
+
readonly UnknownCandidate: "unknown-candidate";
|
|
117
|
+
/** QA named revisions other than the candidate's exact set. */
|
|
118
|
+
readonly RevisionMismatch: "revision-mismatch";
|
|
119
|
+
readonly InvalidVerdict: "invalid-verdict";
|
|
120
|
+
/** An identity was reused for different content. */
|
|
121
|
+
readonly Conflict: "identity-conflict";
|
|
122
|
+
};
|
|
123
|
+
export type DeliveryRejection = ValueOf<typeof DeliveryRejection>;
|
|
124
|
+
export declare const QaVerdict: {
|
|
125
|
+
readonly Pass: "pass";
|
|
126
|
+
readonly Fail: "fail";
|
|
127
|
+
/** The environment or a source was unavailable; never a pass. */
|
|
128
|
+
readonly Blocked: "blocked";
|
|
129
|
+
};
|
|
130
|
+
export type QaVerdict = ValueOf<typeof QaVerdict>;
|
|
131
|
+
export declare const CandidateSourceKind: {
|
|
132
|
+
/** The selected output revision is itself the tip (a single change or an intentional stack). */
|
|
133
|
+
readonly Output: "output";
|
|
134
|
+
/** An agent-assembled commit published under the delivery's retained ref namespace. */
|
|
135
|
+
readonly RetainedRef: "retained-ref";
|
|
136
|
+
};
|
|
137
|
+
export type CandidateSourceKind = ValueOf<typeof CandidateSourceKind>;
|
|
138
|
+
export declare const DeliveryCompletion: {
|
|
139
|
+
/** The parent may finish once the current candidate has an effective QA pass. */
|
|
140
|
+
readonly QaApproved: "qa-approved";
|
|
141
|
+
/** The parent additionally needs governed integration, which is not yet available. */
|
|
142
|
+
readonly MergeRequired: "merge-required";
|
|
143
|
+
};
|
|
144
|
+
export type DeliveryCompletion = ValueOf<typeof DeliveryCompletion>;
|
|
@@ -75,6 +75,8 @@ export const DelegationConflictCode = defineClosedVocabulary({
|
|
|
75
75
|
WaitCycle: 'wait-cycle',
|
|
76
76
|
StalePlan: 'stale-plan',
|
|
77
77
|
AttentionOpen: 'attention-open',
|
|
78
|
+
ReplacementUnsupported: 'replacement-unsupported',
|
|
79
|
+
ReplacementInvalid: 'replacement-invalid',
|
|
78
80
|
});
|
|
79
81
|
export const PrerequisiteBlockCode = defineClosedVocabulary({
|
|
80
82
|
Waiting: 'prerequisite-waiting',
|
|
@@ -84,3 +86,44 @@ export const PrerequisiteBlockCode = defineClosedVocabulary({
|
|
|
84
86
|
Cycle: 'prerequisite-cycle',
|
|
85
87
|
Blocked: 'prerequisite-blocked',
|
|
86
88
|
});
|
|
89
|
+
export const DeliveryRejection = defineClosedVocabulary({
|
|
90
|
+
/** The submitted revision is not the current one; re-inspect before retrying. */
|
|
91
|
+
StaleSelection: 'stale-selection',
|
|
92
|
+
/** An original required assignment has no qualifying output or authorized replacement. */
|
|
93
|
+
UncoveredRequirement: 'uncovered-requirement',
|
|
94
|
+
UnknownRequirement: 'unknown-requirement',
|
|
95
|
+
/** The named output is not a qualifying result of the claimed child. */
|
|
96
|
+
OutputMismatch: 'output-mismatch',
|
|
97
|
+
/** A replacement did not name the output currently selected, or is not criteria-preserving. */
|
|
98
|
+
ReplacementConflict: 'replacement-conflict',
|
|
99
|
+
/** The selection still contains results whose upstream input was replaced. */
|
|
100
|
+
StaleOutput: 'stale-output',
|
|
101
|
+
NoSelection: 'no-selection',
|
|
102
|
+
CandidateCoverage: 'candidate-coverage',
|
|
103
|
+
/** A retained ref is missing, outside the delivery namespace, or no longer at its recorded commit. */
|
|
104
|
+
SourceUnavailable: 'source-unavailable',
|
|
105
|
+
UnknownCandidate: 'unknown-candidate',
|
|
106
|
+
/** QA named revisions other than the candidate's exact set. */
|
|
107
|
+
RevisionMismatch: 'revision-mismatch',
|
|
108
|
+
InvalidVerdict: 'invalid-verdict',
|
|
109
|
+
/** An identity was reused for different content. */
|
|
110
|
+
Conflict: 'identity-conflict',
|
|
111
|
+
});
|
|
112
|
+
export const QaVerdict = defineClosedVocabulary({
|
|
113
|
+
Pass: 'pass',
|
|
114
|
+
Fail: 'fail',
|
|
115
|
+
/** The environment or a source was unavailable; never a pass. */
|
|
116
|
+
Blocked: 'blocked',
|
|
117
|
+
});
|
|
118
|
+
export const CandidateSourceKind = defineClosedVocabulary({
|
|
119
|
+
/** The selected output revision is itself the tip (a single change or an intentional stack). */
|
|
120
|
+
Output: 'output',
|
|
121
|
+
/** An agent-assembled commit published under the delivery's retained ref namespace. */
|
|
122
|
+
RetainedRef: 'retained-ref',
|
|
123
|
+
});
|
|
124
|
+
export const DeliveryCompletion = defineClosedVocabulary({
|
|
125
|
+
/** The parent may finish once the current candidate has an effective QA pass. */
|
|
126
|
+
QaApproved: 'qa-approved',
|
|
127
|
+
/** The parent additionally needs governed integration, which is not yet available. */
|
|
128
|
+
MergeRequired: 'merge-required',
|
|
129
|
+
});
|
|
@@ -5,6 +5,7 @@ import { ApprovalAuthorityKind, TransitionTargetKind } from '../contracts/vocabu
|
|
|
5
5
|
import { defaultApprovalAwait } from './approval-defaults.js';
|
|
6
6
|
import { compileCommands } from './command-compiler.js';
|
|
7
7
|
import { reportUnroutedOutcomes } from './compile-diagnostics.js';
|
|
8
|
+
import { assertDeliveryQa } from './delivery-workflow-policy.js';
|
|
8
9
|
import { compileResourceTransitions } from './resource-transition-compiler.js';
|
|
9
10
|
import { compileTarget, isReservedRouteTarget, isReservedTerminalTarget, } from './transition-target.js';
|
|
10
11
|
import { assertCyclesBounded, assertReachable, remainingAgentSteps } from './workflow-graph.js';
|
|
@@ -24,6 +25,7 @@ export function compileWorkflow(name, input, activities, knownWorkflowNames = [n
|
|
|
24
25
|
const compiledEntry = stageName(entry);
|
|
25
26
|
const declaredWatchIds = new Set((config.watches ?? []).map((watch) => watch.id));
|
|
26
27
|
const stages = compileStages(compiledName, config.stages, activities, declaredWatchIds);
|
|
28
|
+
assertDeliveryQa(config, stages, activities);
|
|
27
29
|
const commands = compileCommands(config, activities);
|
|
28
30
|
const watches = compileWatches(config, rawStageNames, knownWorkflowNames);
|
|
29
31
|
assertReachable(compiledEntry, stages);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DeliveryCandidate, DeliveryCandidateCommand } from '../contracts/delivery.js';
|
|
2
|
+
import { type DeliveryFacts } from './delivery-facts.js';
|
|
3
|
+
export interface CandidatePlan {
|
|
4
|
+
readonly candidate: DeliveryCandidate;
|
|
5
|
+
}
|
|
6
|
+
/** The namespace a delivery's candidate refs must live in; no automatic deletion is performed. */
|
|
7
|
+
export declare const retainedRefPrefix: (root: string, candidateId: string) => string;
|
|
8
|
+
/** Shapes the candidate manifest from the current selection; source verification is separate. */
|
|
9
|
+
export declare function planCandidate(facts: DeliveryFacts, command: DeliveryCandidateCommand, root: string): CandidatePlan;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { CandidateSourceKind, DeliveryRejection } from '../contracts/vocabulary.js';
|
|
3
|
+
import { currentSelection, isChange, outputKey, reject, requirements, } from './delivery-facts.js';
|
|
4
|
+
import { staleEntries } from './delivery-selection.js';
|
|
5
|
+
const sameKeys = (left, right) => isDeepStrictEqual(left.map(outputKey).sort(), right.map(outputKey).sort());
|
|
6
|
+
/** The namespace a delivery's candidate refs must live in; no automatic deletion is performed. */
|
|
7
|
+
export const retainedRefPrefix = (root, candidateId) => `refs/wake/delivery/${root}/${candidateId}/`;
|
|
8
|
+
/** Shapes the candidate manifest from the current selection; source verification is separate. */
|
|
9
|
+
export function planCandidate(facts, command, root) {
|
|
10
|
+
const current = currentSelection(facts);
|
|
11
|
+
if (current === undefined)
|
|
12
|
+
throw reject(DeliveryRejection.NoSelection, 'Record a delivery selection first');
|
|
13
|
+
if (command.selectionRevision !== current.revision)
|
|
14
|
+
throw reject(DeliveryRejection.StaleSelection, `Selection is at revision ${current.revision}, not ${command.selectionRevision}`);
|
|
15
|
+
const stale = staleEntries(facts);
|
|
16
|
+
if (stale.size > 0)
|
|
17
|
+
throw reject(DeliveryRejection.StaleOutput, `Replace or reverify stale results first: ${[...stale].join(', ')}`);
|
|
18
|
+
const byRepository = new Map();
|
|
19
|
+
for (const entry of current.entries.filter((candidate) => isChange(candidate.output))) {
|
|
20
|
+
const { repositoryResourceId } = entry.output.reference;
|
|
21
|
+
byRepository.set(repositoryResourceId, [
|
|
22
|
+
...(byRepository.get(repositoryResourceId) ?? []),
|
|
23
|
+
entry,
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
const requested = command.repositories.map((entry) => entry.resourceId);
|
|
27
|
+
if (new Set(requested).size !== requested.length ||
|
|
28
|
+
!isDeepStrictEqual([...requested].sort(), [...byRepository.keys()].sort()))
|
|
29
|
+
throw reject(DeliveryRejection.CandidateCoverage, 'The candidate must name exactly the repositories of the selected changes, once each');
|
|
30
|
+
const repositories = command.repositories.map((request) => repositoryOf(request, byRepository.get(request.resourceId) ?? [], root, command.candidateId));
|
|
31
|
+
return {
|
|
32
|
+
candidate: {
|
|
33
|
+
candidateId: command.candidateId,
|
|
34
|
+
selectionRevision: current.revision,
|
|
35
|
+
repositories: repositories.sort((a, b) => a.resourceId.localeCompare(b.resourceId)),
|
|
36
|
+
context: current.entries
|
|
37
|
+
.filter((entry) => !isChange(entry.output))
|
|
38
|
+
.map((entry) => ({
|
|
39
|
+
childWorkItemId: entry.childWorkItemId,
|
|
40
|
+
outputName: entry.output.name,
|
|
41
|
+
})),
|
|
42
|
+
criteria: [
|
|
43
|
+
...new Set(requirements(facts.reservations).flatMap((requirement) => requirement.criteria)),
|
|
44
|
+
],
|
|
45
|
+
...(command.recipe === undefined ? {} : { recipe: command.recipe }),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function repositoryOf(request, entries, root, candidateId) {
|
|
50
|
+
const expected = entries.map((entry) => ({
|
|
51
|
+
childWorkItemId: entry.childWorkItemId,
|
|
52
|
+
outputName: entry.output.name,
|
|
53
|
+
}));
|
|
54
|
+
const source = request.source;
|
|
55
|
+
if (source.kind === CandidateSourceKind.Output) {
|
|
56
|
+
if (!sameKeys([source.tip, ...(source.includes ?? [])], expected))
|
|
57
|
+
throw reject(DeliveryRejection.CandidateCoverage, `Candidate for ${request.resourceId} must account for every selected change in it; independent changes need an assembled retained ref`);
|
|
58
|
+
const tip = entries.find((entry) => outputKey(source.tip) === outputKey(keyOf(entry)));
|
|
59
|
+
if (tip === undefined)
|
|
60
|
+
throw reject(DeliveryRejection.CandidateCoverage, 'The tip is not a selected change');
|
|
61
|
+
const reference = tip.output.reference;
|
|
62
|
+
return {
|
|
63
|
+
resourceId: request.resourceId,
|
|
64
|
+
revision: reference.revision,
|
|
65
|
+
pullRequestBase: reference.pullRequestBase,
|
|
66
|
+
source: { kind: CandidateSourceKind.Output, tip: source.tip },
|
|
67
|
+
contributions: expected,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (!sameKeys(source.contributions, expected))
|
|
71
|
+
throw reject(DeliveryRejection.CandidateCoverage, `Assembly for ${request.resourceId} must declare every selected change in it`);
|
|
72
|
+
assertRetainedRef(source.ref, retainedRefPrefix(root, candidateId));
|
|
73
|
+
const bases = entries.map((entry) => entry.output.reference.pullRequestBase);
|
|
74
|
+
return {
|
|
75
|
+
resourceId: request.resourceId,
|
|
76
|
+
revision: source.revision,
|
|
77
|
+
pullRequestBase: [...bases].sort()[0],
|
|
78
|
+
source: { kind: CandidateSourceKind.RetainedRef, ref: source.ref },
|
|
79
|
+
contributions: expected,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const keyOf = (entry) => ({
|
|
83
|
+
childWorkItemId: entry.childWorkItemId,
|
|
84
|
+
outputName: entry.output.name,
|
|
85
|
+
});
|
|
86
|
+
function assertRetainedRef(ref, prefix) {
|
|
87
|
+
if (!ref.startsWith(prefix) ||
|
|
88
|
+
ref.length === prefix.length ||
|
|
89
|
+
!/^[A-Za-z0-9._/-]+$/.test(ref) ||
|
|
90
|
+
ref.includes('..'))
|
|
91
|
+
throw reject(DeliveryRejection.SourceUnavailable, `Retained refs must live under ${prefix}`);
|
|
92
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DelegationReservation, DelegationResult } from '../contracts/delegation.js';
|
|
2
|
+
import { DeliveryRejectionError, type DeliveryCandidate, type DeliveryOutputKey, type DeliveryQa, type DeliverySelection } from '../contracts/delivery.js';
|
|
3
|
+
import type { DeliveryRejection } from '../contracts/vocabulary.js';
|
|
4
|
+
export type Output = DelegationResult['outputs'][number];
|
|
5
|
+
export type Child = DelegationReservation['children'][number];
|
|
6
|
+
export type ChangeReference = Extract<Output['reference'], {
|
|
7
|
+
readonly repositoryResourceId: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Everything the delivery rules read; all of it is journal-derived. */
|
|
10
|
+
export interface DeliveryFacts {
|
|
11
|
+
readonly reservations: readonly DelegationReservation[];
|
|
12
|
+
readonly results: readonly DelegationResult[];
|
|
13
|
+
/** Outputs each child consumed as prerequisites, by child WorkItem. */
|
|
14
|
+
readonly consumed: ReadonlyMap<string, readonly Output[]>;
|
|
15
|
+
readonly selections: readonly DeliverySelection[];
|
|
16
|
+
readonly candidates: readonly DeliveryCandidate[];
|
|
17
|
+
readonly qa: readonly DeliveryQa[];
|
|
18
|
+
}
|
|
19
|
+
export declare const outputKey: (key: DeliveryOutputKey) => string;
|
|
20
|
+
export declare const entryKey: (entry: {
|
|
21
|
+
cohortId: string;
|
|
22
|
+
assignmentId: string;
|
|
23
|
+
}, name: string) => string;
|
|
24
|
+
export declare const reject: (code: DeliveryRejection, message: string) => DeliveryRejectionError;
|
|
25
|
+
export declare const isChange: (output: Output) => output is Output & {
|
|
26
|
+
reference: ChangeReference;
|
|
27
|
+
};
|
|
28
|
+
export declare function currentSelection(facts: DeliveryFacts): DeliverySelection | undefined;
|
|
29
|
+
export interface Requirement {
|
|
30
|
+
readonly cohortId: string;
|
|
31
|
+
readonly assignmentId: string;
|
|
32
|
+
readonly outputName: string;
|
|
33
|
+
readonly child: Child;
|
|
34
|
+
readonly criteria: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
/** Original required assignments: those not themselves declared as a replacement. */
|
|
37
|
+
export declare function requirements(reservations: readonly DelegationReservation[]): Requirement[];
|
|
38
|
+
export declare function childOf(reservations: readonly DelegationReservation[], id: string): {
|
|
39
|
+
cohortId: string;
|
|
40
|
+
child: {
|
|
41
|
+
assignmentId: string;
|
|
42
|
+
objective: string;
|
|
43
|
+
criteria: string[];
|
|
44
|
+
workflowName: import("../index.js").WorkflowName;
|
|
45
|
+
workflowFingerprint: string;
|
|
46
|
+
context: {
|
|
47
|
+
workItemId: import("../../work/index.js").WorkItemId;
|
|
48
|
+
revisionId: string;
|
|
49
|
+
}[];
|
|
50
|
+
outputs: ({
|
|
51
|
+
name: string;
|
|
52
|
+
path: string;
|
|
53
|
+
} | {
|
|
54
|
+
name: string;
|
|
55
|
+
kind: "change";
|
|
56
|
+
requireReview?: boolean | undefined;
|
|
57
|
+
requireChecks?: boolean | undefined;
|
|
58
|
+
})[];
|
|
59
|
+
workItemId: import("../../work/index.js").WorkItemId;
|
|
60
|
+
workflowInstanceId: import("../index.js").WorkflowInstanceId;
|
|
61
|
+
grantId: string;
|
|
62
|
+
repositoryResourceIds?: string[] | undefined;
|
|
63
|
+
prerequisites?: {
|
|
64
|
+
assignmentId: string;
|
|
65
|
+
output: string;
|
|
66
|
+
condition: "accepted-output" | "pushed-change" | "delivery-ready" | "merged-change";
|
|
67
|
+
cohortId?: string | undefined;
|
|
68
|
+
useAsBase?: boolean | undefined;
|
|
69
|
+
}[] | undefined;
|
|
70
|
+
replaces?: {
|
|
71
|
+
cohortId: string;
|
|
72
|
+
assignmentId: string;
|
|
73
|
+
} | undefined;
|
|
74
|
+
repository?: {
|
|
75
|
+
resourceId: string;
|
|
76
|
+
sourceRef: string;
|
|
77
|
+
pullRequestBase: string;
|
|
78
|
+
sourceRevision: string;
|
|
79
|
+
} | undefined;
|
|
80
|
+
prerequisiteWorkItemIds?: import("../../work/index.js").WorkItemId[] | undefined;
|
|
81
|
+
};
|
|
82
|
+
} | undefined;
|
|
83
|
+
export declare function qualifying(facts: DeliveryFacts, key: DeliveryOutputKey): Output | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DeliveryRejectionError, } from '../contracts/delivery.js';
|
|
2
|
+
export const outputKey = (key) => `${key.childWorkItemId}/${key.outputName}`;
|
|
3
|
+
export const entryKey = (entry, name) => `${entry.cohortId}/${entry.assignmentId}/${name}`;
|
|
4
|
+
export const reject = (code, message) => new DeliveryRejectionError(code, message);
|
|
5
|
+
export const isChange = (output) => 'repositoryResourceId' in output.reference;
|
|
6
|
+
export function currentSelection(facts) {
|
|
7
|
+
return facts.selections.at(-1);
|
|
8
|
+
}
|
|
9
|
+
/** Original required assignments: those not themselves declared as a replacement. */
|
|
10
|
+
export function requirements(reservations) {
|
|
11
|
+
return reservations.flatMap((reservation) => reservation.children
|
|
12
|
+
.filter((child) => child.replaces === undefined)
|
|
13
|
+
.flatMap((child) => child.outputs.map((output) => ({
|
|
14
|
+
cohortId: reservation.cohortId,
|
|
15
|
+
assignmentId: child.assignmentId,
|
|
16
|
+
outputName: output.name,
|
|
17
|
+
child,
|
|
18
|
+
criteria: child.criteria,
|
|
19
|
+
}))));
|
|
20
|
+
}
|
|
21
|
+
export function childOf(reservations, id) {
|
|
22
|
+
for (const reservation of reservations) {
|
|
23
|
+
const child = reservation.children.find((entry) => entry.workItemId === id);
|
|
24
|
+
if (child !== undefined)
|
|
25
|
+
return { cohortId: reservation.cohortId, child };
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
export function qualifying(facts, key) {
|
|
30
|
+
return facts.results
|
|
31
|
+
.filter((result) => result.childWorkItemId === key.childWorkItemId)
|
|
32
|
+
.flatMap((result) => result.outputs)
|
|
33
|
+
.find((output) => output.name === key.outputName);
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DeliveryCandidate, DeliveryQa, DeliveryQaCommand } from '../contracts/delivery.js';
|
|
2
|
+
import { DeliveryCompletion } from '../contracts/vocabulary.js';
|
|
3
|
+
import { type DeliveryFacts } from './delivery-facts.js';
|
|
4
|
+
/** The exact repository and revision set QA must have checked. */
|
|
5
|
+
export declare const revisionSet: (items: readonly {
|
|
6
|
+
resourceId: string;
|
|
7
|
+
revision: string;
|
|
8
|
+
}[]) => string[];
|
|
9
|
+
/** QA can only vouch for the candidate's own revisions, and never passes without an environment. */
|
|
10
|
+
export declare function assertQa(facts: DeliveryFacts, command: DeliveryQaCommand): DeliveryQa;
|
|
11
|
+
export interface DeliveryState {
|
|
12
|
+
readonly selectionRevision: number;
|
|
13
|
+
readonly stale: readonly string[];
|
|
14
|
+
readonly candidate: DeliveryCandidate | null;
|
|
15
|
+
/** The latest candidate belongs to the current selection and nothing in it is stale. */
|
|
16
|
+
readonly candidateCurrent: boolean;
|
|
17
|
+
readonly qa: DeliveryQa | null;
|
|
18
|
+
/** The latest QA is for the current candidate; older verdicts stay historical. */
|
|
19
|
+
readonly qaEffective: boolean;
|
|
20
|
+
readonly repair: {
|
|
21
|
+
readonly failedRounds: number;
|
|
22
|
+
readonly exhausted: boolean;
|
|
23
|
+
readonly unresolvedFindings: readonly string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function deliveryState(facts: DeliveryFacts): DeliveryState;
|
|
27
|
+
export interface CompletionDecision {
|
|
28
|
+
readonly complete: boolean;
|
|
29
|
+
readonly reason?: string;
|
|
30
|
+
}
|
|
31
|
+
/** DC-24 handoff boundary: QA approval finishes a QA-approved parent but never a merge-required one. */
|
|
32
|
+
export declare function completionDecision(state: DeliveryState, mode: DeliveryCompletion): CompletionDecision;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { DeliveryCompletion, DeliveryRejection, QaVerdict } from '../contracts/vocabulary.js';
|
|
3
|
+
import { currentSelection, entryKey, reject, requirements, } from './delivery-facts.js';
|
|
4
|
+
import { staleEntries } from './delivery-selection.js';
|
|
5
|
+
/** The exact repository and revision set QA must have checked. */
|
|
6
|
+
export const revisionSet = (items) => items.map((item) => `${item.resourceId}@${item.revision.toLowerCase()}`).sort();
|
|
7
|
+
/** QA can only vouch for the candidate's own revisions, and never passes without an environment. */
|
|
8
|
+
export function assertQa(facts, command) {
|
|
9
|
+
const candidate = facts.candidates.find((entry) => entry.candidateId === command.candidateId);
|
|
10
|
+
if (candidate === undefined)
|
|
11
|
+
throw reject(DeliveryRejection.UnknownCandidate, `Unknown candidate ${command.candidateId}`);
|
|
12
|
+
if (!isDeepStrictEqual(revisionSet(command.revisions), revisionSet(candidate.repositories)))
|
|
13
|
+
throw reject(DeliveryRejection.RevisionMismatch, 'QA must check exactly the candidate repository revisions; testing main or another candidate cannot satisfy the gate');
|
|
14
|
+
if (!command.environment.available && command.verdict !== QaVerdict.Blocked)
|
|
15
|
+
throw reject(DeliveryRejection.InvalidVerdict, 'An unavailable environment must be reported as blocked');
|
|
16
|
+
if (command.verdict === QaVerdict.Pass)
|
|
17
|
+
assertPass(candidate, command);
|
|
18
|
+
if (command.verdict === QaVerdict.Fail && command.findings.length === 0)
|
|
19
|
+
throw reject(DeliveryRejection.InvalidVerdict, 'A failing verdict must state its findings');
|
|
20
|
+
return { ...command };
|
|
21
|
+
}
|
|
22
|
+
function assertPass(candidate, command) {
|
|
23
|
+
if (!command.environment.available)
|
|
24
|
+
throw reject(DeliveryRejection.InvalidVerdict, 'An unavailable environment is a blocker, never a pass');
|
|
25
|
+
if (command.findings.length > 0)
|
|
26
|
+
throw reject(DeliveryRejection.InvalidVerdict, 'A passing verdict cannot carry findings');
|
|
27
|
+
if (candidate.recipe !== undefined && command.environment.recipe !== candidate.recipe)
|
|
28
|
+
throw reject(DeliveryRejection.InvalidVerdict, 'QA must run the configured environment and test recipe');
|
|
29
|
+
}
|
|
30
|
+
export function deliveryState(facts) {
|
|
31
|
+
const current = currentSelection(facts);
|
|
32
|
+
const stale = [...staleEntries(facts)];
|
|
33
|
+
const candidate = facts.candidates.at(-1) ?? null;
|
|
34
|
+
const candidateCurrent = isCandidateCurrent(facts, current, candidate, stale);
|
|
35
|
+
const qa = facts.qa.filter((entry) => entry.candidateId === candidate?.candidateId).at(-1) ?? null;
|
|
36
|
+
const qaEffective = qa !== null && qa.runId !== undefined && qa.activationId !== undefined && candidateCurrent;
|
|
37
|
+
return {
|
|
38
|
+
selectionRevision: current?.revision ?? 0,
|
|
39
|
+
stale,
|
|
40
|
+
candidate,
|
|
41
|
+
candidateCurrent,
|
|
42
|
+
qa,
|
|
43
|
+
qaEffective,
|
|
44
|
+
repair: {
|
|
45
|
+
failedRounds: facts.qa.filter((entry) => entry.verdict === QaVerdict.Fail).length,
|
|
46
|
+
exhausted: facts.qa.at(-1)?.exhausted === true,
|
|
47
|
+
unresolvedFindings: qaEffective && qa.verdict !== QaVerdict.Pass ? qa.findings : [],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** DC-24 handoff boundary: QA approval finishes a QA-approved parent but never a merge-required one. */
|
|
52
|
+
export function completionDecision(state, mode) {
|
|
53
|
+
if (state.stale.length > 0)
|
|
54
|
+
return {
|
|
55
|
+
complete: false,
|
|
56
|
+
reason: `Stale results need reverification: ${state.stale.join(', ')}`,
|
|
57
|
+
};
|
|
58
|
+
if (state.candidate === null || !state.candidateCurrent)
|
|
59
|
+
return { complete: false, reason: 'No current candidate has been recorded for the selection' };
|
|
60
|
+
if (state.qa === null || !state.qaEffective)
|
|
61
|
+
return { complete: false, reason: 'The current candidate has no QA result' };
|
|
62
|
+
if (state.qa.verdict !== QaVerdict.Pass)
|
|
63
|
+
return { complete: false, reason: `QA verdict is ${state.qa.verdict}` };
|
|
64
|
+
if (mode === DeliveryCompletion.MergeRequired)
|
|
65
|
+
return {
|
|
66
|
+
complete: false,
|
|
67
|
+
reason: 'Governed integration is required and its gates are not satisfied',
|
|
68
|
+
};
|
|
69
|
+
return { complete: true };
|
|
70
|
+
}
|
|
71
|
+
function isCandidateCurrent(facts, current, candidate, stale) {
|
|
72
|
+
return (candidate !== null &&
|
|
73
|
+
current !== undefined &&
|
|
74
|
+
candidate.selectionRevision === current?.revision &&
|
|
75
|
+
stale.length === 0 &&
|
|
76
|
+
requirements(facts.reservations).every((requirement) => current.entries.some((entry) => entryKey(entry, entry.output.name) === entryKey(requirement, requirement.outputName))));
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DelegatedAssignment } from '../contracts/delegation.js';
|
|
2
|
+
import { type Child, type DeliveryFacts } from './delivery-facts.js';
|
|
3
|
+
/** The original must be a required assignment of this delivery, never another replacement. */
|
|
4
|
+
export declare function originalOf(facts: DeliveryFacts, replaces: NonNullable<DelegatedAssignment['replaces']>): Child;
|
|
5
|
+
/**
|
|
6
|
+
* A corrective child keeps the original acceptance criteria, repository and outputs. When the
|
|
7
|
+
* original contribution is unmerged it must be the starting point, aimed at the intended base.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertCriteriaPreserving(facts: DeliveryFacts, original: Child, assignment: DelegatedAssignment): void;
|
|
@@ -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>;
|