@atolis-hq/wake 0.4.58 → 0.4.60
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/contracts/event-schema.d.ts +88 -0
- package/dist/src/activities/contracts/event-schema.js +9 -1
- package/dist/src/activities/index.d.ts +1 -0
- package/dist/src/activities/index.js +1 -0
- package/dist/src/activities/pr/activity-support.js +4 -0
- package/dist/src/activities/pr/contracts.d.ts +5 -0
- package/dist/src/activities/pr/merge-policy-denial.d.ts +19 -0
- package/dist/src/activities/pr/merge-policy-denial.js +32 -0
- package/dist/src/activities/pr/merge.d.ts +2 -0
- package/dist/src/activities/pr/merge.js +21 -3
- package/dist/src/activities/pr/policy.js +12 -3
- package/dist/src/bootstrap/analytics-reports.d.ts +1 -1
- package/dist/src/bootstrap/analytics-reports.js +5 -2
- package/dist/src/bootstrap/integration-runtime.js +8 -0
- package/dist/src/bootstrap/surface-api-merge-policy.d.ts +19 -0
- package/dist/src/bootstrap/surface-api-merge-policy.js +52 -0
- package/dist/src/bootstrap/surface-api-work-applications.js +2 -1
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/application/run-reports.d.ts +13 -1
- package/dist/src/execution/application/run-reports.js +42 -1
- package/dist/src/kernel/contracts/reports.d.ts +14 -1
- package/dist/src/orchestration/application/orchestration-service.d.ts +2 -0
- package/dist/src/orchestration/application/orchestration-service.js +4 -0
- package/dist/src/orchestration/application/policy-blocked-merge-recovery.d.ts +7 -0
- package/dist/src/orchestration/application/policy-blocked-merge-recovery.js +54 -0
- package/dist/src/orchestration/application/pull-request-transition-evidence.js +11 -2
- package/dist/src/orchestration/application/resource-transition-evidence.d.ts +2 -0
- package/dist/src/orchestration/application/resource-transition-matching.d.ts +3 -1
- package/dist/src/orchestration/application/resource-transition-matching.js +3 -0
- package/dist/src/surfaces/api/contracts/observability.d.ts +1 -1
- package/dist/src/surfaces/api/contracts/orchestration.d.ts +13 -0
- package/dist/src/surfaces/api/presenters/merge-policy-block.d.ts +9 -0
- package/dist/src/surfaces/api/presenters/merge-policy-block.js +23 -0
- package/dist/src/surfaces/api/routes/applications.d.ts +2 -2
- package/dist/src/surfaces/index.d.ts +1 -0
- package/dist/src/surfaces/index.js +1 -0
- package/dist/src/surfaces/web-assets/assets/index-CCvwzTeC.js +1131 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-DXxSMyln.js +0 -1131
|
@@ -31,8 +31,21 @@ export interface TimeSeriesReport {
|
|
|
31
31
|
readonly values: Readonly<Record<string, number>>;
|
|
32
32
|
}[];
|
|
33
33
|
}
|
|
34
|
+
export interface BreakdownReport {
|
|
35
|
+
readonly report: ReportDescriptor;
|
|
36
|
+
readonly window: ReportWindow;
|
|
37
|
+
readonly total: number;
|
|
38
|
+
readonly dimensions: readonly (ReportDescriptor & {
|
|
39
|
+
readonly rows: readonly {
|
|
40
|
+
readonly value: string;
|
|
41
|
+
readonly count: number;
|
|
42
|
+
readonly share: number;
|
|
43
|
+
}[];
|
|
44
|
+
})[];
|
|
45
|
+
}
|
|
46
|
+
export type AnalyticsReport = TimeSeriesReport | BreakdownReport;
|
|
34
47
|
export interface ReportDefinition extends ReportDescriptor {
|
|
35
|
-
query(query: ReportQuery): Promise<
|
|
48
|
+
query(query: ReportQuery): Promise<AnalyticsReport>;
|
|
36
49
|
}
|
|
37
50
|
export declare function reportWindow(id: ReportWindowId, now: string): ReportWindow;
|
|
38
51
|
/** Exact median with bounded sorting/merging work between caller-supplied pauses. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ResourceTransitionEvidence } from './resource-transition-evidence.js';
|
|
1
2
|
import type { CommandContext, EventJournal, ProjectionStore } from '@atolis-hq/eventing';
|
|
2
3
|
import type { ActivationId, ActivityOutcome } from '../../activities/index.js';
|
|
3
4
|
import { type WorkItemId, type WorkService } from '../../work/index.js';
|
|
@@ -91,6 +92,7 @@ export declare class OrchestrationService {
|
|
|
91
92
|
parent: WorkflowInstanceView;
|
|
92
93
|
watch: Readonly<import("../contracts/config.js").CompiledWatch>;
|
|
93
94
|
}[]>;
|
|
95
|
+
recoverPolicyBlockedMerges(evidence: ResourceTransitionEvidence, context: CommandContext): Promise<void>;
|
|
94
96
|
listResourceTransitionMatches(event: Parameters<AdvanceWorkflow['listResourceTransitionMatches']>[0]): Promise<readonly import("./resource-transition-matching.js").ResourceTransitionMatch[]>;
|
|
95
97
|
applyResourceTransition(workflowInstanceId: WorkflowInstanceId, target: TransitionTarget, evidenceId: string, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
96
98
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recoverPolicyBlockedMerges } from './policy-blocked-merge-recovery.js';
|
|
1
2
|
import { WorkStatus } from '../../work/index.js';
|
|
2
3
|
import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
|
|
3
4
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
@@ -228,6 +229,9 @@ export class OrchestrationService {
|
|
|
228
229
|
listWatchMatches(event, context) {
|
|
229
230
|
return this.advanceWorkflow.listWatchMatches(event, context);
|
|
230
231
|
}
|
|
232
|
+
recoverPolicyBlockedMerges(evidence, context) {
|
|
233
|
+
return recoverPolicyBlockedMerges(new OrchestrationRepository(this.journal), this.startWorkflow, evidence, context);
|
|
234
|
+
}
|
|
231
235
|
listResourceTransitionMatches(event) {
|
|
232
236
|
return this.advanceWorkflow.listResourceTransitionMatches(event);
|
|
233
237
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandContext } from '@atolis-hq/eventing';
|
|
2
|
+
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
3
|
+
import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
4
|
+
import type { ResourceTransitionEvidence } from './resource-transition-evidence.js';
|
|
5
|
+
import type { StartWorkflow } from './start-workflow.js';
|
|
6
|
+
export declare function recoverPolicyBlockedMerges(repository: OrchestrationRepository, workflows: StartWorkflow, evidence: ResourceTransitionEvidence, context: CommandContext): Promise<void>;
|
|
7
|
+
export declare function isPolicyBlockedMergeWait(view: WorkflowInstanceView): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ActivityEventType, ActivityOutcomeKind, BuiltInActivityName, PullRequestState, readMergePolicyDenial, } from '../../activities/index.js';
|
|
2
|
+
import { TransitionTargetKind, WorkflowStatus } from '../contracts/vocabulary.js';
|
|
3
|
+
import { acceptResourceTransition } from './resource-transition-matching.js';
|
|
4
|
+
export async function recoverPolicyBlockedMerges(repository, workflows, evidence, context) {
|
|
5
|
+
for (const loaded of await repository.list()) {
|
|
6
|
+
const view = loaded.view;
|
|
7
|
+
if (view === null || !isPolicyBlockedMergeWait(view))
|
|
8
|
+
continue;
|
|
9
|
+
const definition = await workflows.definitionForOperation(view, loaded.sequence, context);
|
|
10
|
+
if (definition === null)
|
|
11
|
+
continue;
|
|
12
|
+
const stage = definition.stages[view.currentStage];
|
|
13
|
+
if (!isBlockedRouteWait(stage, view))
|
|
14
|
+
continue;
|
|
15
|
+
// The pinned definition supplies the completion destination, never current config.
|
|
16
|
+
const transitions = mergedTransitions(stage);
|
|
17
|
+
const activationId = view.acceptedOutcomes.at(-1);
|
|
18
|
+
if (transitions === undefined || transitions.length !== 1 || activationId === undefined)
|
|
19
|
+
continue;
|
|
20
|
+
const resolved = await evidence.resolve({
|
|
21
|
+
workItemId: view.workItemId,
|
|
22
|
+
transitions,
|
|
23
|
+
mergeDenialActivationId: activationId,
|
|
24
|
+
});
|
|
25
|
+
if (resolved === null)
|
|
26
|
+
continue;
|
|
27
|
+
await acceptResourceTransition(repository, workflows, view.workflowInstanceId, resolved.transition.target, resolved.evidenceId, { ...context, expectedSequence: loaded.sequence });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function isPolicyBlockedMergeWait(view) {
|
|
31
|
+
return (view.status === WorkflowStatus.Waiting &&
|
|
32
|
+
view.parentWorkflowInstanceId === undefined &&
|
|
33
|
+
view.waitingFor !== undefined &&
|
|
34
|
+
view.waitingFor.intentEventId === undefined &&
|
|
35
|
+
view.pendingActivation?.activity === BuiltInActivityName.PullRequestMerge &&
|
|
36
|
+
readMergePolicyDenial(view.lastOutcome) !== null);
|
|
37
|
+
}
|
|
38
|
+
function isBlockedRouteWait(stage, view) {
|
|
39
|
+
const blocked = stage?.on[ActivityOutcomeKind.Blocked];
|
|
40
|
+
return (stage?.activity === BuiltInActivityName.PullRequestMerge &&
|
|
41
|
+
blocked?.target.kind === TransitionTargetKind.AwaitSignal &&
|
|
42
|
+
blocked.target.signal === view.waitingFor?.signalKind);
|
|
43
|
+
}
|
|
44
|
+
function isMergedTransition(transition) {
|
|
45
|
+
return (transition.event === ActivityEventType.PrStateChanged &&
|
|
46
|
+
transition.where !== undefined &&
|
|
47
|
+
'state' in transition.where &&
|
|
48
|
+
transition.where.state === PullRequestState.Merged &&
|
|
49
|
+
(transition.target.kind === TransitionTargetKind.Stage ||
|
|
50
|
+
transition.target.kind === TransitionTargetKind.Complete));
|
|
51
|
+
}
|
|
52
|
+
function mergedTransitions(stage) {
|
|
53
|
+
return stage?.on[ActivityOutcomeKind.Done]?.resourceTransitions?.filter(isMergedTransition);
|
|
54
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActivityEventType, ActivityResourceRole, decidePullRequestAuthority, PullRequestCheckState, PullRequestState, selectActivityEvent, selectPrimaryPullRequest, } from '../../activities/index.js';
|
|
1
|
+
import { ActivityEventType, ActivityResourceRole, decidePullRequestAuthority, PullRequestCheckState, PullRequestDenialCode, PullRequestState, selectActivityEvent, selectPrimaryPullRequest, } from '../../activities/index.js';
|
|
2
2
|
const triggers = [
|
|
3
3
|
ActivityEventType.PrReviewAccepted,
|
|
4
4
|
ActivityEventType.PrStateChanged,
|
|
@@ -7,12 +7,21 @@ const triggers = [
|
|
|
7
7
|
export function createPullRequestTransitionEvidence(pullRequests) {
|
|
8
8
|
return {
|
|
9
9
|
triggers,
|
|
10
|
-
async resolve({ workItemId, transitions, fact, }) {
|
|
10
|
+
async resolve({ workItemId, transitions, fact, mergeDenialActivationId, }) {
|
|
11
11
|
const input = await pullRequests.authorityInput(workItemId);
|
|
12
12
|
const selected = selectPrimaryPullRequest(input, workItemId);
|
|
13
13
|
if (selected === null)
|
|
14
14
|
return null;
|
|
15
15
|
const resourceId = selected.pullRequest.resourceId;
|
|
16
|
+
if (mergeDenialActivationId !== undefined) {
|
|
17
|
+
const denied = (await pullRequests.factsFor(resourceId)).some((entry) => entry.event.eventType === ActivityEventType.PrMergeDenied &&
|
|
18
|
+
entry.event.causationId === mergeDenialActivationId &&
|
|
19
|
+
(entry.event.payload.reason === PullRequestDenialCode.BlockedPathChanged ||
|
|
20
|
+
entry.event.payload.reason === PullRequestDenialCode.TooManyFilesChanged ||
|
|
21
|
+
entry.event.payload.reason === PullRequestDenialCode.ChangedFilesUnavailable));
|
|
22
|
+
if (!denied)
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
16
25
|
const candidates = fact === undefined ? await pullRequests.factsFor(resourceId) : scoped(fact, resourceId);
|
|
17
26
|
if (candidates.length === 0)
|
|
18
27
|
return null;
|
|
@@ -6,6 +6,8 @@ export interface ResourceTransitionEvidenceInput {
|
|
|
6
6
|
readonly workItemId: WorkItemId;
|
|
7
7
|
readonly transitions: readonly CompiledResourceTransition[];
|
|
8
8
|
readonly fact?: ResourceTransitionFact;
|
|
9
|
+
/** Requires a policy denial on the selected PR from this exact activation. */
|
|
10
|
+
readonly mergeDenialActivationId?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface ResourceTransitionEvidenceResolution {
|
|
11
13
|
readonly transition: CompiledResourceTransition;
|
|
@@ -15,5 +15,7 @@ export interface ResourceTransitionMatch {
|
|
|
15
15
|
export declare function matchResourceTransitions(loaded: readonly {
|
|
16
16
|
readonly view: WorkflowInstanceView;
|
|
17
17
|
}[], event: PersistedEvent): Promise<readonly ResourceTransitionMatch[]>;
|
|
18
|
-
export declare function acceptResourceTransition(repository: OrchestrationRepository, workflows: StartWorkflow, id: WorkflowInstanceId, target: TransitionTarget, evidenceId: string, context: CommandContext
|
|
18
|
+
export declare function acceptResourceTransition(repository: OrchestrationRepository, workflows: StartWorkflow, id: WorkflowInstanceId, target: TransitionTarget, evidenceId: string, context: CommandContext & {
|
|
19
|
+
readonly expectedSequence?: number;
|
|
20
|
+
}): Promise<WorkflowInstanceView | null>;
|
|
19
21
|
export {};
|
|
@@ -55,6 +55,9 @@ export async function acceptResourceTransition(repository, workflows, id, target
|
|
|
55
55
|
const loaded = await repository.load(id);
|
|
56
56
|
if (loaded.view === null || loaded.view.waitingFor === undefined)
|
|
57
57
|
return loaded.view;
|
|
58
|
+
if (context.expectedSequence !== undefined &&
|
|
59
|
+
(loaded.sequence !== context.expectedSequence || loaded.view.status !== WorkflowStatus.Waiting))
|
|
60
|
+
return loaded.view;
|
|
58
61
|
const definition = await workflows.definitionForOperation(loaded.view, loaded.sequence, context);
|
|
59
62
|
if (definition === null)
|
|
60
63
|
return loaded.view;
|
|
@@ -10,7 +10,7 @@ export interface MetricsResponse {
|
|
|
10
10
|
readonly values: Readonly<Record<string, number>>;
|
|
11
11
|
}
|
|
12
12
|
export { ReportWindowId } from '../../../kernel/index.js';
|
|
13
|
-
export type { ReportWindowId as AnalyticsReportWindowId, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
13
|
+
export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
14
14
|
export interface AnalyticsSummaryResponse {
|
|
15
15
|
readonly window: ReportWindow;
|
|
16
16
|
readonly runs: number;
|
|
@@ -10,7 +10,20 @@ export interface WorkflowInstanceResponse {
|
|
|
10
10
|
readonly blockReason?: string;
|
|
11
11
|
readonly retryEligible?: boolean;
|
|
12
12
|
readonly extendEligible?: boolean;
|
|
13
|
+
readonly mergePolicyBlock?: MergePolicyBlockResponse;
|
|
13
14
|
readonly waitingFor?: {
|
|
14
15
|
readonly signalKind: string;
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
export interface MergePolicyBlockResponse {
|
|
19
|
+
readonly status: 'awaiting-human-merge' | 'recovering';
|
|
20
|
+
readonly explanation: string;
|
|
21
|
+
readonly nextAction: string;
|
|
22
|
+
readonly href?: string;
|
|
23
|
+
readonly policy?: {
|
|
24
|
+
readonly blockedPaths?: readonly string[] | undefined;
|
|
25
|
+
readonly matchedPaths?: readonly string[] | undefined;
|
|
26
|
+
readonly maxFilesChanged?: number | undefined;
|
|
27
|
+
readonly filesChanged?: number | undefined;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MergePolicyDetails, type PullRequestView } from '../../../activities/index.js';
|
|
2
|
+
import { type WorkflowInstanceView } from '../../../orchestration/index.js';
|
|
3
|
+
import type { MergePolicyBlockResponse } from '../contracts/orchestration.js';
|
|
4
|
+
export declare function presentMergePolicyBlock(input: {
|
|
5
|
+
readonly workflow: WorkflowInstanceView;
|
|
6
|
+
readonly pullRequest: PullRequestView;
|
|
7
|
+
readonly href?: string | undefined;
|
|
8
|
+
readonly policy?: MergePolicyDetails | undefined;
|
|
9
|
+
}): MergePolicyBlockResponse | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PullRequestDenialCode, PullRequestState, readMergePolicyDenial, } from '../../../activities/index.js';
|
|
2
|
+
import { WorkflowStatus } from '../../../orchestration/index.js';
|
|
3
|
+
export function presentMergePolicyBlock(input) {
|
|
4
|
+
const denial = readMergePolicyDenial(input.workflow.lastOutcome);
|
|
5
|
+
if (denial === null || input.workflow.status !== WorkflowStatus.Waiting)
|
|
6
|
+
return undefined;
|
|
7
|
+
const policy = denial.policy ?? input.policy;
|
|
8
|
+
const merged = input.pullRequest.state === PullRequestState.Merged;
|
|
9
|
+
const explanation = denial.reason === PullRequestDenialCode.BlockedPathChanged
|
|
10
|
+
? 'Automatic merge stopped because this PR changes a protected path.'
|
|
11
|
+
: denial.reason === PullRequestDenialCode.TooManyFilesChanged
|
|
12
|
+
? 'Automatic merge stopped because this PR exceeds the configured file-count limit.'
|
|
13
|
+
: 'Automatic merge stopped because changed-file evidence required by policy is unavailable.';
|
|
14
|
+
return {
|
|
15
|
+
status: merged ? 'recovering' : 'awaiting-human-merge',
|
|
16
|
+
explanation,
|
|
17
|
+
nextAction: merged
|
|
18
|
+
? 'The PR has merged. Normal control-plane advancement will check the durable evidence and continue the configured completion flow.'
|
|
19
|
+
: 'Review and merge the correlated PR manually. Wake will observe the merge and continue. Approval or a comment only retries automation and does not override this policy.',
|
|
20
|
+
...(input.href === undefined ? {} : { href: input.href }),
|
|
21
|
+
...(policy === undefined ? {} : { policy }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunStatus } from '../../../execution/index.js';
|
|
2
|
-
import type { ReportDescriptor, ReportWindowId
|
|
2
|
+
import type { AnalyticsReport, ReportDescriptor, ReportWindowId } from '../../../kernel/index.js';
|
|
3
3
|
import type { ApiCommandResult, AuditEventResponse, BoardCardResponse, BoardResponse, CommandsResponse, ConfigurationResponse, ControlPlaneStatusResponse, ConversationMessageRequest, HealthResponse, MetricsResponse, ResourceItemResponse, ResourceResponse, ResponseMeta, RunnerResponse, RunResponse, RunTranscriptResponse, StatusResponse, WebhookSetupResponse, WorkDetailResponse, WorkflowDiagramsResponse, WorkflowInstanceResponse, WorkItemResponse, WorkItemTranscriptResponse } from '../contracts/index.js';
|
|
4
4
|
import type { AnalyticsSummaryResponse } from '../contracts/observability.js';
|
|
5
5
|
export interface CollectionQuery {
|
|
@@ -94,7 +94,7 @@ export interface ApiApplications {
|
|
|
94
94
|
readonly observability: {
|
|
95
95
|
readonly reports?: {
|
|
96
96
|
catalogue(): readonly ReportDescriptor[];
|
|
97
|
-
report(id: string, window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<
|
|
97
|
+
report(id: string, window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<AnalyticsReport>>;
|
|
98
98
|
summary(window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<AnalyticsSummaryResponse>>;
|
|
99
99
|
};
|
|
100
100
|
metrics(query?: {
|