@atolis-hq/wake 0.4.105 → 0.4.107
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 +7 -0
- package/dist/src/activities/contracts/activity.d.ts +12 -0
- package/dist/src/activities/contracts/event-schema.d.ts +314 -8
- package/dist/src/activities/contracts/event-schema.js +20 -2
- package/dist/src/activities/contracts/events.d.ts +10 -0
- package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
- package/dist/src/activities/contracts/vocabulary.js +2 -0
- package/dist/src/activities/index.d.ts +2 -0
- package/dist/src/activities/index.js +2 -0
- package/dist/src/activities/pr/activity-support.d.ts +1 -1
- package/dist/src/activities/pr/activity-support.js +10 -0
- package/dist/src/activities/pr/application.js +31 -10
- package/dist/src/activities/pr/approve.d.ts +2 -1
- package/dist/src/activities/pr/approve.js +33 -11
- package/dist/src/activities/pr/check-evidence.d.ts +10 -0
- package/dist/src/activities/pr/check-evidence.js +16 -0
- package/dist/src/activities/pr/contracts.d.ts +14 -0
- package/dist/src/activities/pr/event-data.js +5 -1
- package/dist/src/activities/pr/merge.d.ts +2 -1
- package/dist/src/activities/pr/merge.js +54 -38
- package/dist/src/activities/pr/parent-scope.d.ts +65 -0
- package/dist/src/activities/pr/parent-scope.js +24 -0
- package/dist/src/activities/pr/parent-target.d.ts +45 -0
- package/dist/src/activities/pr/parent-target.js +59 -0
- package/dist/src/activities/pr/projection.js +10 -2
- package/dist/src/activities/pr/vocabulary.d.ts +8 -0
- package/dist/src/activities/pr/vocabulary.js +8 -0
- package/dist/src/bootstrap/activity-registry.d.ts +2 -2
- package/dist/src/bootstrap/activity-registry.js +3 -3
- package/dist/src/bootstrap/composition-root.js +12 -3
- package/dist/src/bootstrap/config/root-schema.d.ts +6 -0
- package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
- package/dist/src/bootstrap/delivery-integration.js +46 -0
- package/dist/src/bootstrap/surface-api-delivery.js +27 -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 +10 -6
- package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
- package/dist/src/conversations/application/conversation-repository.js +3 -1
- package/dist/src/execution/application/execution-service.js +10 -0
- package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
- package/dist/src/execution/application/maintenance-workspaces.js +84 -0
- package/dist/src/execution/application/run-lifecycle.js +1 -0
- package/dist/src/execution/application/run-repository.js +27 -10
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +13 -0
- package/dist/src/execution/contracts/events.js +2 -0
- package/dist/src/execution/contracts/maintenance.d.ts +36 -0
- package/dist/src/execution/contracts/maintenance.js +44 -0
- package/dist/src/execution/contracts/views.d.ts +2 -0
- package/dist/src/execution/contracts/workspace.d.ts +2 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +7 -14
- package/dist/src/integrations/application/delegation-outputs.js +1 -1
- package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
- package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
- package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
- package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
- package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
- package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
- package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
- package/dist/src/integrations/fake/external-source.d.ts +5 -2
- package/dist/src/integrations/fake/external-source.js +12 -2
- package/dist/src/integrations/fake/inbound-translator.js +7 -2
- package/dist/src/integrations/fake/provider.d.ts +17 -0
- package/dist/src/integrations/fake/provider.js +18 -2
- package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
- package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
- package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
- package/dist/src/integrations/github/contracts/events.d.ts +3 -1
- package/dist/src/integrations/github/contracts/events.js +3 -1
- package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
- package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
- package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
- package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/client.js +4 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
- package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
- package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
- package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
- package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
- package/dist/src/orchestration/application/advance-workflow.js +7 -2
- package/dist/src/orchestration/application/deferred-signals.js +2 -6
- package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
- package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
- package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
- package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
- package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
- package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
- package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
- package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
- package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
- package/dist/src/orchestration/application/delivery-preparation.js +7 -2
- package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
- package/dist/src/orchestration/application/orchestration-repository.js +139 -64
- package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
- package/dist/src/orchestration/application/orchestration-service.js +55 -2
- package/dist/src/orchestration/contracts/config.d.ts +6 -0
- package/dist/src/orchestration/contracts/config.js +6 -0
- package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
- package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
- package/dist/src/orchestration/contracts/delivery.js +53 -1
- package/dist/src/orchestration/contracts/event-decoder.js +2 -1
- package/dist/src/orchestration/contracts/event-factory.js +2 -0
- package/dist/src/orchestration/contracts/events.d.ts +3 -1
- package/dist/src/orchestration/contracts/events.js +1 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
- package/dist/src/orchestration/contracts/vocabulary.js +40 -1
- package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
- package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
- package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
- package/dist/src/orchestration/domain/delivery-facts.js +33 -1
- package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
- package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
- package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
- package/dist/src/orchestration/domain/delivery-integration.js +144 -0
- package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
- package/dist/src/orchestration/domain/delivery-qa.js +24 -4
- package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
- package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
- package/dist/src/orchestration/index.d.ts +3 -2
- package/dist/src/orchestration/index.js +1 -1
- package/dist/src/resources/application/resource-lookup.d.ts +2 -1
- package/dist/src/resources/application/resource-lookup.js +3 -11
- package/dist/src/resources/application/resource-repository.js +10 -10
- package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
- package/dist/src/surfaces/api/presenters/execution.js +1 -0
- package/dist/src/surfaces/mcp/delegation.js +5 -1
- package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
- package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +0 -1192
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { WrongExpectedSequenceError } from '@atolis-hq/eventing';
|
|
2
2
|
import { DelegationConflictError, delegationSubmissionSchema, } from '../contracts/delegation.js';
|
|
3
|
-
import { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from '../contracts/delivery.js';
|
|
3
|
+
import { DeliveryRejectionError, deliveryCandidateCommandSchema, deliveryMaintenanceCommandSchema, deliveryQaCommandSchema, deliverySelectionCommandSchema, } from '../contracts/delivery.js';
|
|
4
4
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
5
5
|
import { stageName } from '../contracts/identifiers.js';
|
|
6
6
|
import { DelegationConflictCode, DeliveryCompletion, DeliveryRejection, QaVerdict, WorkflowStatus, } from '../contracts/vocabulary.js';
|
|
7
7
|
import { planCandidate } from '../domain/delivery-candidate.js';
|
|
8
|
-
import { requirements } from '../domain/delivery-facts.js';
|
|
8
|
+
import { currentSelection, requirements } from '../domain/delivery-facts.js';
|
|
9
9
|
import { assertQa, completionDecision, deliveryState } from '../domain/delivery-qa.js';
|
|
10
10
|
import { originalOf } from '../domain/delivery-replacement.js';
|
|
11
11
|
import { reviseSelection } from '../domain/delivery-selection.js';
|
|
12
12
|
import { delegationDraft } from './delegation-ledger.js';
|
|
13
13
|
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
14
|
+
import { DeliveryIntegrationService } from './delivery-integration-service.js';
|
|
14
15
|
import { DeliveryPreparation } from './delivery-preparation.js';
|
|
15
16
|
import { verifyCandidateSources } from './delivery-sources.js';
|
|
16
17
|
/**
|
|
@@ -23,10 +24,30 @@ export class DeliveryCoordinator {
|
|
|
23
24
|
repository;
|
|
24
25
|
dependencies;
|
|
25
26
|
preparation;
|
|
27
|
+
integration;
|
|
26
28
|
constructor(repository, dependencies) {
|
|
27
29
|
this.repository = repository;
|
|
28
30
|
this.dependencies = dependencies;
|
|
29
31
|
this.preparation = new DeliveryPreparation(repository, dependencies);
|
|
32
|
+
this.integration = new DeliveryIntegrationService(repository, dependencies);
|
|
33
|
+
}
|
|
34
|
+
authorizeParentAction(request) {
|
|
35
|
+
return this.integration.authorize(request);
|
|
36
|
+
}
|
|
37
|
+
/** The targets the configured maintenance stage will lease, or undefined for other stages. */
|
|
38
|
+
async maintenanceTargets(id) {
|
|
39
|
+
const parent = (await this.repository.loadRequired(id)).view;
|
|
40
|
+
const stage = (await this.dependencies.definitionFor(parent)).delegation?.maintenance?.stage;
|
|
41
|
+
if (stage === undefined || parent.pendingActivation?.stage !== stage)
|
|
42
|
+
return undefined;
|
|
43
|
+
return this.integration.maintenanceTargets(parent);
|
|
44
|
+
}
|
|
45
|
+
/** Records what the maintaining agent actually produced as a new immutable subject. */
|
|
46
|
+
async recordMaintenance(caller, input, context) {
|
|
47
|
+
const command = deliveryMaintenanceCommandSchema.parse(input);
|
|
48
|
+
const parent = await this.parent(caller);
|
|
49
|
+
await this.assertCoordinatorStage(parent);
|
|
50
|
+
return this.commit(parent, context, `maintenance:${command.maintenanceId}`, (facts) => this.integration.planMaintenance(facts, command, caller, context.occurredAt));
|
|
30
51
|
}
|
|
31
52
|
async select(caller, input, context) {
|
|
32
53
|
const command = deliverySelectionCommandSchema.parse(input);
|
|
@@ -120,20 +141,25 @@ export class DeliveryCoordinator {
|
|
|
120
141
|
const parent = (await this.repository.loadRequired(id)).view;
|
|
121
142
|
const facts = await this.facts(parent);
|
|
122
143
|
const state = deliveryState(facts);
|
|
144
|
+
const mode = (await this.dependencies.definitionFor(parent)).delegation?.completion ??
|
|
145
|
+
DeliveryCompletion.QaApproved;
|
|
146
|
+
// Only merge-required deliveries pay for provider reads; QA-approved ones never integrate.
|
|
147
|
+
const integration = mode === DeliveryCompletion.MergeRequired ? await this.integration.assess(facts) : null;
|
|
123
148
|
return {
|
|
124
149
|
...state,
|
|
150
|
+
integration,
|
|
151
|
+
maintenance: facts.maintenance,
|
|
125
152
|
required: requirements(facts.reservations).map((requirement) => ({
|
|
126
153
|
cohortId: requirement.cohortId,
|
|
127
154
|
assignmentId: requirement.assignmentId,
|
|
128
155
|
outputName: requirement.outputName,
|
|
129
156
|
childWorkItemId: requirement.child.workItemId,
|
|
130
157
|
})),
|
|
131
|
-
selection: facts
|
|
158
|
+
selection: currentSelection(facts) ?? null,
|
|
132
159
|
history: facts.qa,
|
|
133
160
|
completion: parent.deliveryGateBlock !== undefined
|
|
134
161
|
? { complete: false, reason: parent.blockReason }
|
|
135
|
-
: completionDecision(state,
|
|
136
|
-
DeliveryCompletion.QaApproved),
|
|
162
|
+
: completionDecision(state, mode, integration ?? undefined),
|
|
137
163
|
};
|
|
138
164
|
}
|
|
139
165
|
/**
|
|
@@ -32,6 +32,7 @@ export async function readDeliveryFacts(repository, parent, own) {
|
|
|
32
32
|
selections: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliverySelectionRevised ? [event.payload] : []),
|
|
33
33
|
candidates: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryCandidateRecorded ? [event.payload] : []),
|
|
34
34
|
qa: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryQaRecorded ? [event.payload] : []),
|
|
35
|
+
maintenance: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryMaintenanceRecorded ? [event.payload] : []),
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
function distinctCohorts(reservations) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
|
|
2
|
+
import { type DeliveryFacts } from '../domain/delivery-facts.js';
|
|
3
|
+
import { type IntegrationAssessment } from '../domain/delivery-integration.js';
|
|
4
|
+
/** Reads the provider and Work facts the pure integration decision needs, fresh on every call. */
|
|
5
|
+
export declare class DeliveryIntegrationReader {
|
|
6
|
+
private readonly dependencies;
|
|
7
|
+
constructor(dependencies: DeliveryDependencies);
|
|
8
|
+
assess(facts: DeliveryFacts): Promise<IntegrationAssessment>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { currentSelection, isChange } from '../domain/delivery-facts.js';
|
|
2
|
+
import { assessIntegration, } from '../domain/delivery-integration.js';
|
|
3
|
+
/** Reads the provider and Work facts the pure integration decision needs, fresh on every call. */
|
|
4
|
+
export class DeliveryIntegrationReader {
|
|
5
|
+
dependencies;
|
|
6
|
+
constructor(dependencies) {
|
|
7
|
+
this.dependencies = dependencies;
|
|
8
|
+
}
|
|
9
|
+
async assess(facts) {
|
|
10
|
+
const changes = (currentSelection(facts)?.entries ?? []).flatMap((entry) => isChange(entry.output)
|
|
11
|
+
? [{ child: entry.childWorkItemId, reference: entry.output.reference }]
|
|
12
|
+
: []);
|
|
13
|
+
const observations = new Map();
|
|
14
|
+
for (const { reference } of changes) {
|
|
15
|
+
const observed = await this.dependencies.integration?.observe(reference.resourceId);
|
|
16
|
+
if (observed !== undefined && observed !== null)
|
|
17
|
+
observations.set(reference.resourceId, observed);
|
|
18
|
+
}
|
|
19
|
+
const held = (await this.dependencies.unavailable?.(changes.map((change) => change.child))) ??
|
|
20
|
+
new Map();
|
|
21
|
+
return assessIntegration(facts, observations, held);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type ParentActionDecision, type ParentActionRequest } from '../../activities/index.js';
|
|
2
|
+
import type { DelegationCaller } from '../contracts/delegation.js';
|
|
3
|
+
import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
|
|
4
|
+
import { type DeliveryMaintenance, type DeliveryMaintenanceCommand } from '../contracts/delivery.js';
|
|
5
|
+
import { OrchestrationEventType } from '../contracts/events.js';
|
|
6
|
+
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
7
|
+
import { type DeliveryFacts } from '../domain/delivery-facts.js';
|
|
8
|
+
import { type IntegrationAssessment } from '../domain/delivery-integration.js';
|
|
9
|
+
import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
10
|
+
/**
|
|
11
|
+
* Governed integration of child-owned pull requests by their parent delivery. Wake derives the
|
|
12
|
+
* one planned next action from the parent's journal and provider facts, authorizes exactly that
|
|
13
|
+
* target, and verifies what a maintaining agent actually produced. The agent chooses the repair;
|
|
14
|
+
* nothing here authors a change, reopens a child or transfers a pull request.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DeliveryIntegrationService {
|
|
17
|
+
private readonly repository;
|
|
18
|
+
private readonly dependencies;
|
|
19
|
+
private readonly reader;
|
|
20
|
+
constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
|
|
21
|
+
assess(facts: DeliveryFacts): Promise<IntegrationAssessment>;
|
|
22
|
+
authorize(request: ParentActionRequest): Promise<ParentActionDecision>;
|
|
23
|
+
private verifySelected;
|
|
24
|
+
/**
|
|
25
|
+
* Validates one maintenance report against the selected subject and the provider. The result is
|
|
26
|
+
* a new immutable subject; the replaced head, its reviews, checks and QA stay historical.
|
|
27
|
+
*/
|
|
28
|
+
planMaintenance(facts: DeliveryFacts, input: DeliveryMaintenanceCommand, caller: DelegationCaller, recordedAt: string): Promise<MaintenancePlan>;
|
|
29
|
+
/** Only the invocation Wake dispatched for this parent may ask, and only for its own action. */
|
|
30
|
+
private dispatchedMerge;
|
|
31
|
+
private assertAvailable;
|
|
32
|
+
private observeOpen;
|
|
33
|
+
/**
|
|
34
|
+
* The open pull requests a maintenance stage may lease. Merged, closed or held targets cannot
|
|
35
|
+
* be written to, so they are never offered.
|
|
36
|
+
*/
|
|
37
|
+
maintenanceTargets(parent: WorkflowInstanceView): Promise<import("../domain/delivery-integration.js").IntegrationTarget[]>;
|
|
38
|
+
private facts;
|
|
39
|
+
}
|
|
40
|
+
interface MaintenancePlan {
|
|
41
|
+
readonly result: {
|
|
42
|
+
readonly maintenance: DeliveryMaintenance;
|
|
43
|
+
readonly replay: boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly draft: {
|
|
46
|
+
readonly eventType: typeof OrchestrationEventType.DeliveryMaintenanceRecorded;
|
|
47
|
+
readonly payload: DeliveryMaintenance;
|
|
48
|
+
} | undefined;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { BuiltInActivityName, ParentActionKind, PullRequestDenialCode, PullRequestState, } from '../../activities/index.js';
|
|
2
|
+
import { resourceId } from '../../resources/index.js';
|
|
3
|
+
import { DeliveryRejectionError, deliveryMaintenanceCommandSchema, } from '../contracts/delivery.js';
|
|
4
|
+
import { OrchestrationEventType } from '../contracts/events.js';
|
|
5
|
+
import { DeliveryCompletion, DeliveryRejection, IntegrationState, QaVerdict, } from '../contracts/vocabulary.js';
|
|
6
|
+
import { currentSelection, isChange, outputKey, } from '../domain/delivery-facts.js';
|
|
7
|
+
import { targetRequirements } from '../domain/delivery-integration-policy.js';
|
|
8
|
+
import { known, sameRevision } from '../domain/delivery-integration.js';
|
|
9
|
+
import { deliveryState } from '../domain/delivery-qa.js';
|
|
10
|
+
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
11
|
+
import { DeliveryIntegrationReader } from './delivery-integration-reader.js';
|
|
12
|
+
/**
|
|
13
|
+
* Governed integration of child-owned pull requests by their parent delivery. Wake derives the
|
|
14
|
+
* one planned next action from the parent's journal and provider facts, authorizes exactly that
|
|
15
|
+
* target, and verifies what a maintaining agent actually produced. The agent chooses the repair;
|
|
16
|
+
* nothing here authors a change, reopens a child or transfers a pull request.
|
|
17
|
+
*/
|
|
18
|
+
export class DeliveryIntegrationService {
|
|
19
|
+
repository;
|
|
20
|
+
dependencies;
|
|
21
|
+
reader;
|
|
22
|
+
constructor(repository, dependencies) {
|
|
23
|
+
this.repository = repository;
|
|
24
|
+
this.dependencies = dependencies;
|
|
25
|
+
this.reader = new DeliveryIntegrationReader(dependencies);
|
|
26
|
+
}
|
|
27
|
+
assess(facts) {
|
|
28
|
+
return this.reader.assess(facts);
|
|
29
|
+
}
|
|
30
|
+
async authorize(request) {
|
|
31
|
+
const denied = (reason) => ({
|
|
32
|
+
kind: 'denied',
|
|
33
|
+
reason,
|
|
34
|
+
});
|
|
35
|
+
const parent = (await this.repository.load(request.workflowInstanceId)).view;
|
|
36
|
+
if (parent === null)
|
|
37
|
+
return denied(PullRequestDenialCode.OutsideDelivery);
|
|
38
|
+
if (!(await this.dispatchedMerge(parent, request)))
|
|
39
|
+
return denied(PullRequestDenialCode.OutsideDelivery);
|
|
40
|
+
const facts = await this.facts(parent);
|
|
41
|
+
const state = deliveryState(facts);
|
|
42
|
+
if (!state.candidateCurrent || !state.qaEffective || state.qa?.verdict !== QaVerdict.Pass)
|
|
43
|
+
return denied(PullRequestDenialCode.DeliveryNotReady);
|
|
44
|
+
// Current and effective imply a candidate and QA exist; narrow them for the context below.
|
|
45
|
+
if (state.candidate === null || state.qa === null)
|
|
46
|
+
return denied(PullRequestDenialCode.DeliveryNotReady);
|
|
47
|
+
const assessment = await this.reader.assess(facts);
|
|
48
|
+
if (assessment.complete)
|
|
49
|
+
return { kind: 'fully-integrated' };
|
|
50
|
+
const { next, blocking } = assessment;
|
|
51
|
+
if (next === null)
|
|
52
|
+
return denied(blockReason(blocking));
|
|
53
|
+
if (!(await this.verifySelected(facts, next.output, request.action)))
|
|
54
|
+
return denied(PullRequestDenialCode.DeliveryNotReady);
|
|
55
|
+
const context = {
|
|
56
|
+
requestingWorkItemId: parent.workItemId,
|
|
57
|
+
ownerWorkItemId: next.ownerWorkItemId,
|
|
58
|
+
output: { childWorkItemId: next.output.childWorkItemId, outputName: next.output.outputName },
|
|
59
|
+
candidateId: state.candidate.candidateId,
|
|
60
|
+
selectionRevision: state.selectionRevision,
|
|
61
|
+
qaId: state.qa.qaId,
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
kind: 'target',
|
|
65
|
+
context,
|
|
66
|
+
resourceId: resourceId(next.resourceId),
|
|
67
|
+
revision: next.revision,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async verifySelected(facts, output, action) {
|
|
71
|
+
const { reference } = selectedChange(facts, output);
|
|
72
|
+
const maintenance = facts.maintenance
|
|
73
|
+
.filter((item) => outputKey(item.target) === outputKey(output))
|
|
74
|
+
.at(-1);
|
|
75
|
+
return ((await this.dependencies.integration?.verifyTarget({
|
|
76
|
+
...reference,
|
|
77
|
+
maintenanceRunId: maintenance?.producer.runId,
|
|
78
|
+
maintenanceRecordedAt: maintenance?.recordedAt,
|
|
79
|
+
ownerWorkItemId: reference.workItemId,
|
|
80
|
+
...targetRequirements(facts, output, action),
|
|
81
|
+
})) === true);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validates one maintenance report against the selected subject and the provider. The result is
|
|
85
|
+
* a new immutable subject; the replaced head, its reviews, checks and QA stay historical.
|
|
86
|
+
*/
|
|
87
|
+
async planMaintenance(facts, input, caller, recordedAt) {
|
|
88
|
+
const command = deliveryMaintenanceCommandSchema.parse(input);
|
|
89
|
+
const { reference, childWorkItemId } = selectedChange(facts, command.target);
|
|
90
|
+
const recorded = facts.maintenance.find((item) => item.maintenanceId === command.maintenanceId);
|
|
91
|
+
if (recorded !== undefined)
|
|
92
|
+
return replayPlan(recorded, command);
|
|
93
|
+
if (!sameRevision(command.expectedRevision, reference.revision))
|
|
94
|
+
throw new DeliveryRejectionError(DeliveryRejection.MaintenanceMismatch, `Maintenance must start from the current subject ${reference.revision}, not ${command.expectedRevision}`);
|
|
95
|
+
await this.assertAvailable(childWorkItemId);
|
|
96
|
+
const observed = await this.observeOpen(reference.resourceId);
|
|
97
|
+
if (!sameRevision(observed.headRevision, command.revision))
|
|
98
|
+
throw new DeliveryRejectionError(DeliveryRejection.MaintenanceMismatch, `The provider reports head ${observed.headRevision}, not the reported ${command.revision}`);
|
|
99
|
+
if (sameRevision(command.revision, reference.revision) &&
|
|
100
|
+
command.pullRequestBase === reference.pullRequestBase &&
|
|
101
|
+
observed.baseRevision === reference.baseRevision)
|
|
102
|
+
throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, 'Maintenance changed neither the head nor the base subject');
|
|
103
|
+
if (!(await this.dependencies.integration?.verifyTarget({
|
|
104
|
+
...reference,
|
|
105
|
+
ownerWorkItemId: reference.workItemId,
|
|
106
|
+
revision: command.revision,
|
|
107
|
+
pullRequestBase: command.pullRequestBase,
|
|
108
|
+
requireReview: false,
|
|
109
|
+
requireChecks: false,
|
|
110
|
+
})))
|
|
111
|
+
throw new DeliveryRejectionError(DeliveryRejection.MaintenanceMismatch, 'The provider must verify the maintained repository, branch, head, base and original owner');
|
|
112
|
+
// The Run must hold this target's branch lease, and no earlier writer may be unresolved.
|
|
113
|
+
await this.dependencies.integration.assertMaintenanceWriter({
|
|
114
|
+
workflowInstanceId: caller.workflowInstanceId,
|
|
115
|
+
activationId: caller.activationId,
|
|
116
|
+
runId: caller.runId,
|
|
117
|
+
childWorkItemId: reference.workItemId,
|
|
118
|
+
resourceId: reference.resourceId,
|
|
119
|
+
revision: reference.revision,
|
|
120
|
+
});
|
|
121
|
+
const maintenance = {
|
|
122
|
+
maintenanceId: command.maintenanceId,
|
|
123
|
+
target: command.target,
|
|
124
|
+
kind: command.kind,
|
|
125
|
+
resourceId: reference.resourceId,
|
|
126
|
+
repositoryResourceId: reference.repositoryResourceId,
|
|
127
|
+
previous: {
|
|
128
|
+
revision: reference.revision,
|
|
129
|
+
pullRequestBase: reference.pullRequestBase,
|
|
130
|
+
...(reference.baseRevision === undefined ? {} : { baseRevision: reference.baseRevision }),
|
|
131
|
+
},
|
|
132
|
+
current: {
|
|
133
|
+
revision: command.revision,
|
|
134
|
+
pullRequestBase: command.pullRequestBase,
|
|
135
|
+
...(known(observed.baseRevision) ? { baseRevision: observed.baseRevision } : {}),
|
|
136
|
+
},
|
|
137
|
+
recordedAt,
|
|
138
|
+
producer: { runId: caller.runId, activationId: caller.activationId },
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
result: { maintenance, replay: false },
|
|
142
|
+
draft: {
|
|
143
|
+
eventType: OrchestrationEventType.DeliveryMaintenanceRecorded,
|
|
144
|
+
payload: maintenance,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Only the invocation Wake dispatched for this parent may ask, and only for its own action. */
|
|
149
|
+
async dispatchedMerge(parent, request) {
|
|
150
|
+
const policy = (await this.dependencies.definitionFor(parent)).delegation;
|
|
151
|
+
const expected = request.action === ParentActionKind.Merge
|
|
152
|
+
? BuiltInActivityName.PullRequestMerge
|
|
153
|
+
: BuiltInActivityName.PullRequestApprove;
|
|
154
|
+
return (policy?.qa !== undefined &&
|
|
155
|
+
policy.completion === DeliveryCompletion.MergeRequired &&
|
|
156
|
+
parent.pendingActivation?.activationId === request.activationId &&
|
|
157
|
+
parent.pendingActivation.activity === expected);
|
|
158
|
+
}
|
|
159
|
+
async assertAvailable(childWorkItemId) {
|
|
160
|
+
const unavailable = await this.dependencies.unavailable?.([childWorkItemId]);
|
|
161
|
+
if (unavailable?.has(childWorkItemId) === true)
|
|
162
|
+
throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, unavailable.get(childWorkItemId));
|
|
163
|
+
}
|
|
164
|
+
async observeOpen(resourceId) {
|
|
165
|
+
const integration = this.dependencies.integration;
|
|
166
|
+
if (integration === undefined)
|
|
167
|
+
throw new DeliveryRejectionError(DeliveryRejection.MaintenanceMismatch, 'Provider verification of maintenance is unavailable');
|
|
168
|
+
const observed = await integration.observe(resourceId);
|
|
169
|
+
if (observed === null)
|
|
170
|
+
throw new DeliveryRejectionError(DeliveryRejection.MaintenanceMismatch, 'The pull request has not been observed from the provider');
|
|
171
|
+
if (observed.state !== PullRequestState.Open)
|
|
172
|
+
throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, `A ${observed.state} pull request cannot be maintained`);
|
|
173
|
+
return observed;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The open pull requests a maintenance stage may lease. Merged, closed or held targets cannot
|
|
177
|
+
* be written to, so they are never offered.
|
|
178
|
+
*/
|
|
179
|
+
async maintenanceTargets(parent) {
|
|
180
|
+
const assessment = await this.reader.assess(await this.facts(parent));
|
|
181
|
+
const open = [
|
|
182
|
+
IntegrationState.Ready,
|
|
183
|
+
IntegrationState.AwaitingLowerLayer,
|
|
184
|
+
IntegrationState.MaintenanceRequired,
|
|
185
|
+
];
|
|
186
|
+
return assessment.targets.filter((target) => open.includes(target.state));
|
|
187
|
+
}
|
|
188
|
+
async facts(parent) {
|
|
189
|
+
const { events } = await this.repository.history(parent.workflowInstanceId);
|
|
190
|
+
return readDeliveryFacts(this.repository, parent, events);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function selectedChange(facts, target) {
|
|
194
|
+
const entry = currentSelection(facts)?.entries.find((candidate) => candidate.childWorkItemId === target.childWorkItemId &&
|
|
195
|
+
candidate.output.name === target.outputName);
|
|
196
|
+
if (entry === undefined || !isChange(entry.output))
|
|
197
|
+
throw new DeliveryRejectionError(DeliveryRejection.NotMaintainable, `${outputKey(target)} is not a selected change`);
|
|
198
|
+
return { reference: entry.output.reference, childWorkItemId: entry.childWorkItemId };
|
|
199
|
+
}
|
|
200
|
+
/** A repeated report is idempotent only when it says exactly what was recorded. */
|
|
201
|
+
function replayPlan(recorded, command) {
|
|
202
|
+
const same = outputKey(recorded.target) === outputKey(command.target) &&
|
|
203
|
+
recorded.kind === command.kind &&
|
|
204
|
+
sameRevision(recorded.current.revision, command.revision) &&
|
|
205
|
+
recorded.current.pullRequestBase === command.pullRequestBase &&
|
|
206
|
+
sameRevision(recorded.previous.revision, command.expectedRevision);
|
|
207
|
+
if (!same)
|
|
208
|
+
throw new DeliveryRejectionError(DeliveryRejection.Conflict, `Maintenance ${command.maintenanceId} was already recorded differently`);
|
|
209
|
+
return {
|
|
210
|
+
result: { maintenance: recorded, replay: true },
|
|
211
|
+
draft: undefined,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function blockReason(blocking) {
|
|
215
|
+
switch (blocking?.state) {
|
|
216
|
+
case IntegrationState.Held:
|
|
217
|
+
return PullRequestDenialCode.TargetHeld;
|
|
218
|
+
case IntegrationState.MaintenanceRequired:
|
|
219
|
+
case IntegrationState.AwaitingLowerLayer:
|
|
220
|
+
return PullRequestDenialCode.MaintenanceRequired;
|
|
221
|
+
case IntegrationState.Closed:
|
|
222
|
+
return PullRequestDenialCode.Closed;
|
|
223
|
+
case IntegrationState.Unobserved:
|
|
224
|
+
return PullRequestDenialCode.MissingResource;
|
|
225
|
+
default:
|
|
226
|
+
return PullRequestDenialCode.DeliveryNotReady;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
|
6
6
|
export declare class DeliveryPreparation {
|
|
7
7
|
private readonly repository;
|
|
8
8
|
private readonly dependencies;
|
|
9
|
+
private readonly integration;
|
|
9
10
|
constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
|
|
10
11
|
completionBlock(id: string): Promise<DeliveryCompletionBlock | undefined>;
|
|
11
12
|
prepare(id: string): Promise<ExecutionCandidate | undefined>;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { WorkspaceMode } from '../../execution/index.js';
|
|
2
2
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
3
3
|
import { CandidateSourceKind, DeliveryCompletion } from '../contracts/vocabulary.js';
|
|
4
|
+
import { currentSelection } from '../domain/delivery-facts.js';
|
|
4
5
|
import { completionDecision, deliveryState } from '../domain/delivery-qa.js';
|
|
5
6
|
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
7
|
+
import { DeliveryIntegrationReader } from './delivery-integration-reader.js';
|
|
6
8
|
import { verifyCandidateSources } from './delivery-sources.js';
|
|
7
9
|
export class DeliveryPreparation {
|
|
8
10
|
repository;
|
|
9
11
|
dependencies;
|
|
12
|
+
integration;
|
|
10
13
|
constructor(repository, dependencies) {
|
|
11
14
|
this.repository = repository;
|
|
12
15
|
this.dependencies = dependencies;
|
|
16
|
+
this.integration = new DeliveryIntegrationReader(dependencies);
|
|
13
17
|
}
|
|
14
18
|
async completionBlock(id) {
|
|
15
19
|
const parent = (await this.repository.loadRequired(id)).view;
|
|
@@ -20,7 +24,8 @@ export class DeliveryPreparation {
|
|
|
20
24
|
const facts = await this.facts(parent);
|
|
21
25
|
if (facts.reservations.length === 0)
|
|
22
26
|
return undefined;
|
|
23
|
-
const
|
|
27
|
+
const mode = definition.delegation?.completion ?? DeliveryCompletion.QaApproved;
|
|
28
|
+
const decision = completionDecision(deliveryState(facts), mode, mode === DeliveryCompletion.MergeRequired ? await this.integration.assess(facts) : undefined);
|
|
24
29
|
const retryStage = await this.delegatingStage(id, facts.reservations.at(-1));
|
|
25
30
|
const blocked = (reason) => ({
|
|
26
31
|
reason,
|
|
@@ -53,7 +58,7 @@ export class DeliveryPreparation {
|
|
|
53
58
|
candidateId: candidate.candidateId,
|
|
54
59
|
selectionRevision: candidate.selectionRevision,
|
|
55
60
|
criteria: candidate.criteria,
|
|
56
|
-
inputs: facts
|
|
61
|
+
inputs: currentSelection(facts).entries.map((entry) => ({
|
|
57
62
|
workItemId: entry.output.reference.workItemId,
|
|
58
63
|
outputName: entry.output.name,
|
|
59
64
|
revision: 'revisionId' in entry.output.reference
|
|
@@ -2,29 +2,35 @@ import { type EventJournal } from '@atolis-hq/eventing';
|
|
|
2
2
|
import type { DeliveryCompletionBlock } from '../contracts/delivery.js';
|
|
3
3
|
import type { WorkflowOrchestrationEvent, WorkflowOrchestrationEventData } from '../contracts/events.js';
|
|
4
4
|
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
5
|
-
type ListedInstance = {
|
|
5
|
+
export type ListedInstance = {
|
|
6
6
|
readonly sequence: number;
|
|
7
7
|
readonly view: WorkflowInstanceView | null;
|
|
8
8
|
};
|
|
9
|
+
export interface OrchestrationSnapshot {
|
|
10
|
+
readonly instances: readonly ListedInstance[];
|
|
11
|
+
readonly events: readonly WorkflowOrchestrationEvent[];
|
|
12
|
+
readonly inherited: ReadonlyMap<string, readonly WorkflowOrchestrationEvent[]>;
|
|
13
|
+
readonly deferredInstanceIds: ReadonlySet<string>;
|
|
14
|
+
}
|
|
9
15
|
export declare class OrchestrationRepository {
|
|
10
16
|
private readonly journal;
|
|
11
17
|
private readonly completionBlock?;
|
|
12
|
-
private readonly
|
|
18
|
+
private readonly state;
|
|
13
19
|
constructor(journal: EventJournal, completionBlock?: ((id: string) => Promise<DeliveryCompletionBlock | undefined>) | undefined);
|
|
14
20
|
load(id: string): Promise<{
|
|
15
21
|
sequence: number;
|
|
16
22
|
view: WorkflowInstanceView | null;
|
|
17
23
|
}>;
|
|
18
|
-
snapshot(): Promise<
|
|
19
|
-
instances: readonly ListedInstance[];
|
|
20
|
-
events: readonly WorkflowOrchestrationEvent[];
|
|
21
|
-
inherited: ReadonlyMap<string, readonly WorkflowOrchestrationEvent[]>;
|
|
22
|
-
}>;
|
|
24
|
+
snapshot(): Promise<OrchestrationSnapshot>;
|
|
23
25
|
events(): Promise<readonly WorkflowOrchestrationEvent[]>;
|
|
26
|
+
/** Workflow instances that hold at least one deferred signal. */
|
|
27
|
+
instancesWithDeferredSignals(): Promise<ReadonlySet<string>>;
|
|
24
28
|
history(id: string): Promise<{
|
|
25
29
|
sequence: number;
|
|
26
|
-
events: WorkflowOrchestrationEvent[];
|
|
30
|
+
events: readonly WorkflowOrchestrationEvent[];
|
|
27
31
|
}>;
|
|
32
|
+
/** The state for reads that span every instance, which fail while any instance is malformed. */
|
|
33
|
+
private healthyState;
|
|
28
34
|
loadRequired(id: string): Promise<{
|
|
29
35
|
sequence: number;
|
|
30
36
|
view: WorkflowInstanceView;
|
|
@@ -32,4 +38,3 @@ export declare class OrchestrationRepository {
|
|
|
32
38
|
append(id: string, sequence: number, drafts: readonly WorkflowOrchestrationEventData[]): Promise<readonly WorkflowOrchestrationEvent[]>;
|
|
33
39
|
list(): Promise<readonly ListedInstance[]>;
|
|
34
40
|
}
|
|
35
|
-
export {};
|