@atolis-hq/wake 0.4.110 → 0.4.112
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/bootstrap/board-projection.d.ts +4 -0
- package/dist/src/bootstrap/board-projection.js +33 -19
- package/dist/src/bootstrap/composition-root.d.ts +3 -1
- package/dist/src/bootstrap/composition-root.js +21 -6
- package/dist/src/bootstrap/delegated-artifact-context.d.ts +15 -0
- package/dist/src/bootstrap/delegated-artifact-context.js +17 -0
- package/dist/src/bootstrap/initialise.js +20 -2
- package/dist/src/bootstrap/integration-runtime.js +1 -0
- package/dist/src/bootstrap/objective-title-context.d.ts +7 -0
- package/dist/src/bootstrap/objective-title-context.js +15 -0
- package/dist/src/bootstrap/self-update-application.d.ts +9 -0
- package/dist/src/bootstrap/self-update-application.js +15 -1
- package/dist/src/bootstrap/self-update-build-failure.d.ts +7 -0
- package/dist/src/bootstrap/self-update-build-failure.js +18 -0
- package/dist/src/bootstrap/surface-api-delivery.js +6 -1
- package/dist/src/bootstrap/surface-api-work-applications.js +39 -5
- package/dist/src/bootstrap/surface-api-workflow-diagrams.js +8 -4
- package/dist/src/bootstrap/surface-cli-applications.js +10 -4
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/conversations/application/control-plane-entry.d.ts +14 -0
- package/dist/src/conversations/application/control-plane-entry.js +16 -0
- package/dist/src/conversations/index.d.ts +1 -0
- package/dist/src/conversations/index.js +1 -0
- package/dist/src/integrations/application/agent-run-publication-reactor.d.ts +2 -1
- package/dist/src/integrations/application/agent-run-publication-reactor.js +6 -17
- package/dist/src/integrations/application/agent-run-publication-target.d.ts +12 -0
- package/dist/src/integrations/application/agent-run-publication-target.js +31 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +4 -2
- package/dist/src/integrations/contracts/provider.d.ts +5 -0
- package/dist/src/integrations/github/application/inbound-translator.d.ts +7 -0
- package/dist/src/integrations/github/application/inbound-translator.js +46 -0
- package/dist/src/integrations/github/provider.js +1 -0
- package/dist/src/orchestration/application/conversation-command-reactor.js +6 -25
- package/dist/src/orchestration/application/delegated-work.d.ts +12 -2
- package/dist/src/orchestration/application/delegated-work.js +30 -3
- package/dist/src/orchestration/application/delegation-attention-state.d.ts +2 -0
- package/dist/src/orchestration/application/delegation-attention-state.js +11 -1
- package/dist/src/orchestration/application/delegation-attention.d.ts +9 -11
- package/dist/src/orchestration/application/delegation-attention.js +42 -23
- package/dist/src/orchestration/application/orchestration-service.d.ts +11 -4
- package/dist/src/orchestration/application/orchestration-service.js +22 -16
- package/dist/src/orchestration/application/prerequisite-readiness.d.ts +8 -0
- package/dist/src/orchestration/application/prerequisite-readiness.js +35 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +16 -0
- package/dist/src/orchestration/contracts/delegation.d.ts +6 -4
- package/dist/src/orchestration/contracts/delegation.js +13 -3
- package/dist/src/orchestration/contracts/vocabulary.d.ts +1 -0
- package/dist/src/orchestration/contracts/vocabulary.js +1 -0
- package/dist/src/orchestration/domain/delegated-brief.d.ts +8 -0
- package/dist/src/orchestration/domain/delegated-brief.js +35 -0
- package/dist/src/orchestration/index.d.ts +1 -1
- package/dist/src/resources/contracts/events.js +1 -0
- package/dist/src/resources/contracts/vocabulary.d.ts +2 -0
- package/dist/src/resources/contracts/vocabulary.js +2 -0
- package/dist/src/surfaces/api/contracts/board.d.ts +4 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +9 -0
- package/dist/src/surfaces/mcp/delegation.js +2 -2
- package/dist/src/surfaces/web-assets/assets/index-BDXgDwPe.js +1192 -0
- package/dist/src/surfaces/web-assets/assets/index-DKNzCDQl.css +1 -0
- package/dist/src/surfaces/web-assets/index.html +2 -2
- package/docker/Dockerfile.runtime +10 -1
- package/docker/Dockerfile.runtime.packaged +10 -1
- package/package.json +1 -1
- package/dist/src/orchestration/application/delegation-attention-escalations.d.ts +0 -11
- package/dist/src/orchestration/application/delegation-attention-escalations.js +0 -36
- package/dist/src/surfaces/web-assets/assets/index-CJVgp3N-.js +0 -1192
- package/dist/src/surfaces/web-assets/assets/index-EVgZ9q9N.css +0 -1
|
@@ -3,13 +3,14 @@ import { BuiltInActivityName } from '../../activities/index.js';
|
|
|
3
3
|
import { conversationIdForWorkItem, ConversationOriginKind, } from '../../conversations/index.js';
|
|
4
4
|
import { RunStatus } from '../../execution/index.js';
|
|
5
5
|
import { OrchestrationEventType, OrchestrationStreamKind, selectWorkflowOrchestrationEvent, } from '../../orchestration/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { resourceStream } from '../../resources/index.js';
|
|
7
7
|
import { ReplyTarget } from '../contracts/reply-routing.js';
|
|
8
8
|
import { createDeliveryIntentEventData } from '../delivery/contracts/event-factory.js';
|
|
9
9
|
import { DeliveryIntentEventType } from '../delivery/contracts/intents.js';
|
|
10
10
|
import { defaultReplyPublication, selectReplyTarget, } from '../github/application/reply-target-selector.js';
|
|
11
11
|
import { projectTerminalAgentRunReport } from './terminal-agent-run-report.js';
|
|
12
12
|
import { agentRunReportInput, mergeWaitComment } from './agent-run-publication-report.js';
|
|
13
|
+
import { labelledForSharedResource, resourceForTarget } from './agent-run-publication-target.js';
|
|
13
14
|
/** Projects terminal agent runs into one durable outbound intent per configured resource. */
|
|
14
15
|
export class AgentRunPublicationReactor {
|
|
15
16
|
dependencies;
|
|
@@ -71,9 +72,10 @@ export class AgentRunPublicationReactor {
|
|
|
71
72
|
const target = selectReplyTarget({ stage, outcome: report.outcome }, replies.rules, replies.default);
|
|
72
73
|
if (target === ReplyTarget.None)
|
|
73
74
|
return;
|
|
74
|
-
const resource = await this.
|
|
75
|
+
const resource = await resourceForTarget(this.dependencies.resources, workflow.workItemId, target);
|
|
75
76
|
if (resource === undefined)
|
|
76
77
|
return;
|
|
78
|
+
const published = await labelledForSharedResource(this.dependencies.work, workflow.workItemId, resource, report);
|
|
77
79
|
const stream = resourceStream(resource.resourceId);
|
|
78
80
|
const sequence = (await this.dependencies.journal.readStream(stream)).length;
|
|
79
81
|
try {
|
|
@@ -96,7 +98,7 @@ export class AgentRunPublicationReactor {
|
|
|
96
98
|
conversationId: conversationIdForWorkItem(workflow.workItemId),
|
|
97
99
|
conversationEntryId: `agent-run:${run.runId}`,
|
|
98
100
|
}),
|
|
99
|
-
report,
|
|
101
|
+
report: published,
|
|
100
102
|
},
|
|
101
103
|
}),
|
|
102
104
|
]);
|
|
@@ -118,7 +120,7 @@ export class AgentRunPublicationReactor {
|
|
|
118
120
|
const target = selectReplyTarget({ stage: workflow.currentStage, outcome: 'DONE' }, replies.rules, replies.default);
|
|
119
121
|
if (target === ReplyTarget.None)
|
|
120
122
|
return;
|
|
121
|
-
const resource = await this.
|
|
123
|
+
const resource = await resourceForTarget(this.dependencies.resources, workflow.workItemId, target);
|
|
122
124
|
if (resource === undefined)
|
|
123
125
|
return;
|
|
124
126
|
const stream = resourceStream(resource.resourceId);
|
|
@@ -168,19 +170,6 @@ export class AgentRunPublicationReactor {
|
|
|
168
170
|
},
|
|
169
171
|
}, { ...context, commandId: `agent-run:${runId}` });
|
|
170
172
|
}
|
|
171
|
-
async resourceForTarget(workItemId, target) {
|
|
172
|
-
const correlations = await this.dependencies.resources.correlationsForWork(workItemId);
|
|
173
|
-
const primary = () => correlations.find((value) => value.role === ResourceCorrelationRole.Primary);
|
|
174
|
-
if (target === ReplyTarget.Primary)
|
|
175
|
-
return primary();
|
|
176
|
-
const kind = target === ReplyTarget.Issue ? BuiltInResourceKind.Issue : BuiltInResourceKind.PullRequest;
|
|
177
|
-
for (const correlation of correlations) {
|
|
178
|
-
const resource = await this.dependencies.resources.get(correlation.resourceId);
|
|
179
|
-
if (resource?.kind === kind)
|
|
180
|
-
return correlation;
|
|
181
|
-
}
|
|
182
|
-
return primary();
|
|
183
|
-
}
|
|
184
173
|
async stageForActivation(workflowInstanceId, activationId) {
|
|
185
174
|
const events = await this.dependencies.journal.readStream({
|
|
186
175
|
kind: OrchestrationStreamKind.WorkflowInstance,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ResourceCorrelationView, type ResourceService } from '../../resources/index.js';
|
|
2
|
+
import type { WorkService } from '../../work/index.js';
|
|
3
|
+
import { ReplyTarget, type ReplyPublicationConfig } from '../contracts/reply-routing.js';
|
|
4
|
+
/** The resource a work item's reply should be published on, or undefined when it has none. */
|
|
5
|
+
export declare function resourceForTarget(resources: Pick<ResourceService, 'correlationsForWork' | 'get'>, workItemId: Parameters<ResourceService['correlationsForWork']>[0], target: Exclude<ReplyPublicationConfig['default'], typeof ReplyTarget.None>): Promise<ResourceCorrelationView | undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* A delegated child publishes onto its parent's resource, shared with its siblings, so its
|
|
8
|
+
* comment names the work it speaks for. The child's own conversation entry stays unlabelled.
|
|
9
|
+
*/
|
|
10
|
+
export declare function labelledForSharedResource<Report extends {
|
|
11
|
+
readonly displayBody: string;
|
|
12
|
+
}>(work: Pick<WorkService, 'get'> | undefined, workItemId: Parameters<ResourceService['correlationsForWork']>[0], resource: ResourceCorrelationView, report: Report): Promise<Report>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BuiltInResourceKind, ResourceCorrelationProvenance, ResourceCorrelationRole, } from '../../resources/index.js';
|
|
2
|
+
import { ReplyTarget } from '../contracts/reply-routing.js';
|
|
3
|
+
/** The resource a work item's reply should be published on, or undefined when it has none. */
|
|
4
|
+
export async function resourceForTarget(resources, workItemId, target) {
|
|
5
|
+
const correlations = await resources.correlationsForWork(workItemId);
|
|
6
|
+
const primary = () => correlations.find((value) => value.role === ResourceCorrelationRole.Primary);
|
|
7
|
+
const delegated = () => correlations.find((value) => value.provenance === ResourceCorrelationProvenance.Delegated);
|
|
8
|
+
// A child has no primary resource of its own until it reports a PR; until then it speaks on
|
|
9
|
+
// the resource its parent delegated it from.
|
|
10
|
+
if (target === ReplyTarget.Primary)
|
|
11
|
+
return primary() ?? delegated();
|
|
12
|
+
const kind = target === ReplyTarget.Issue ? BuiltInResourceKind.Issue : BuiltInResourceKind.PullRequest;
|
|
13
|
+
for (const correlation of correlations) {
|
|
14
|
+
const resource = await resources.get(correlation.resourceId);
|
|
15
|
+
if (resource?.kind === kind)
|
|
16
|
+
return correlation;
|
|
17
|
+
}
|
|
18
|
+
return primary();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A delegated child publishes onto its parent's resource, shared with its siblings, so its
|
|
22
|
+
* comment names the work it speaks for. The child's own conversation entry stays unlabelled.
|
|
23
|
+
*/
|
|
24
|
+
export async function labelledForSharedResource(work, workItemId, resource, report) {
|
|
25
|
+
if (resource.provenance !== ResourceCorrelationProvenance.Delegated)
|
|
26
|
+
return report;
|
|
27
|
+
const objective = (await work?.get(workItemId))?.objective;
|
|
28
|
+
if (objective === undefined)
|
|
29
|
+
return report;
|
|
30
|
+
return { ...report, displayBody: `**Child work:** ${objective}\n\n${report.displayBody}` };
|
|
31
|
+
}
|
|
@@ -89,9 +89,9 @@ export class ArtifactRegistrationReactor {
|
|
|
89
89
|
await this.recordUnresolved(provider, record, verified, attempt);
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
|
-
await this.registerVerified(record, verified, workItemId);
|
|
92
|
+
await this.registerVerified(record, verified, workItemId, provider);
|
|
93
93
|
}
|
|
94
|
-
async registerVerified(record, verified, workItemId) {
|
|
94
|
+
async registerVerified(record, verified, workItemId, provider) {
|
|
95
95
|
const existing = await this.dependencies.resources.findByExternalKey(verified.externalKey);
|
|
96
96
|
// Re-discover an existing resource so a re-report records its newly verified head.
|
|
97
97
|
const resource = await this.dependencies.resources.discover({
|
|
@@ -107,7 +107,9 @@ export class ArtifactRegistrationReactor {
|
|
|
107
107
|
}
|
|
108
108
|
catch {
|
|
109
109
|
// Resources records primary conflicts durably; this flow never guesses a secondary relation.
|
|
110
|
+
return;
|
|
110
111
|
}
|
|
112
|
+
await provider.reobserve?.(verified.externalKey);
|
|
111
113
|
}
|
|
112
114
|
async recordUnresolved(provider, record, result, attempt) {
|
|
113
115
|
const stream = integrationStream(provider.adapter);
|
|
@@ -80,6 +80,11 @@ export interface ProviderInstance {
|
|
|
80
80
|
readonly workspaceRevision?: string;
|
|
81
81
|
readonly pullRequestBase?: string;
|
|
82
82
|
}): Promise<VerifiedArtifact | ArtifactVerificationResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Re-applies the latest journaled observation of a resource Wake has just begun tracking,
|
|
85
|
+
* for observations that arrived before the resource had a WorkItem.
|
|
86
|
+
*/
|
|
87
|
+
readonly reobserve?: (externalKey: ExternalResourceKey) => Promise<void>;
|
|
83
88
|
readonly checkConnectivity?: () => Promise<void>;
|
|
84
89
|
readonly health?: () => readonly AdapterHealthCheck[];
|
|
85
90
|
/** Lets the poll runner report whole-poll failures (lock contention, timeouts) as health. */
|
|
@@ -67,6 +67,13 @@ export declare class InboundTranslator {
|
|
|
67
67
|
private readonly conversations;
|
|
68
68
|
private readonly conversationCapabilities;
|
|
69
69
|
private conversationRecordRecoveryPending;
|
|
70
|
+
/**
|
|
71
|
+
* Applies the newest journaled observation of a pull request Wake has just correlated to
|
|
72
|
+
* a WorkItem. A poll that saw the PR earlier was skipped as unowned, and unchanged evidence
|
|
73
|
+
* is not re-emitted, so without this the PR would never gain its WorkItem observation.
|
|
74
|
+
*/
|
|
75
|
+
reapplyObservation(externalKey: string): Promise<void>;
|
|
76
|
+
private latestPullRequestObservation;
|
|
70
77
|
private reconcileOnce;
|
|
71
78
|
private selectInboundEvent;
|
|
72
79
|
private isTranslatable;
|
|
@@ -88,6 +88,52 @@ export class InboundTranslator {
|
|
|
88
88
|
conversations;
|
|
89
89
|
conversationCapabilities;
|
|
90
90
|
conversationRecordRecoveryPending;
|
|
91
|
+
/**
|
|
92
|
+
* Applies the newest journaled observation of a pull request Wake has just correlated to
|
|
93
|
+
* a WorkItem. A poll that saw the PR earlier was skipped as unowned, and unchanged evidence
|
|
94
|
+
* is not re-emitted, so without this the PR would never gain its WorkItem observation.
|
|
95
|
+
*/
|
|
96
|
+
async reapplyObservation(externalKey) {
|
|
97
|
+
if (this.journal === undefined || this.resources === undefined)
|
|
98
|
+
return;
|
|
99
|
+
const pullRequests = this.pullRequests;
|
|
100
|
+
if (pullRequests === undefined)
|
|
101
|
+
return;
|
|
102
|
+
const latest = await this.latestPullRequestObservation(externalKey);
|
|
103
|
+
if (latest === undefined)
|
|
104
|
+
return;
|
|
105
|
+
const resourceIdValue = await this.lookup?.resourceIdForExternalKey({
|
|
106
|
+
adapter: this.adapter,
|
|
107
|
+
key: externalKey,
|
|
108
|
+
});
|
|
109
|
+
if (resourceIdValue === null || resourceIdValue === undefined)
|
|
110
|
+
return;
|
|
111
|
+
const primary = (await this.resources.correlations(resourceIdValue)).find((correlation) => correlation.role === ResourceCorrelationRole.Primary);
|
|
112
|
+
if (primary === undefined)
|
|
113
|
+
return;
|
|
114
|
+
await this.applyReobservation({
|
|
115
|
+
payload: latest.event.payload,
|
|
116
|
+
context: {
|
|
117
|
+
...commandContext(latest),
|
|
118
|
+
commandId: `${latest.event.eventId}:reobserve:${resourceIdValue}`,
|
|
119
|
+
},
|
|
120
|
+
pullRequests,
|
|
121
|
+
resourceId: resourceIdValue,
|
|
122
|
+
workItemId: primary.workItemId,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async latestPullRequestObservation(externalKey) {
|
|
126
|
+
let latest;
|
|
127
|
+
for (const envelope of await this.journal.readStream(integrationStream(this.adapter))) {
|
|
128
|
+
const owned = selectGitHubAdapterEvent(envelope);
|
|
129
|
+
if (owned !== null &&
|
|
130
|
+
isGitHubAdapterEventType(owned, GitHubEventType.WorkObserved) &&
|
|
131
|
+
owned.event.payload.kind === 'pull-request' &&
|
|
132
|
+
owned.event.payload.externalKey === externalKey)
|
|
133
|
+
latest = owned;
|
|
134
|
+
}
|
|
135
|
+
return latest;
|
|
136
|
+
}
|
|
91
137
|
async reconcileOnce() {
|
|
92
138
|
if (this.journal === undefined || this.work === undefined || this.resources === undefined) {
|
|
93
139
|
throw new Error('InboundTranslator services are required to run evidence translation');
|
|
@@ -208,6 +208,7 @@ export const gitHubProviderDefinition = {
|
|
|
208
208
|
},
|
|
209
209
|
inbound,
|
|
210
210
|
reconciler: inbound.reconciler,
|
|
211
|
+
reobserve: (externalKey) => inbound.reapplyObservation(externalKey.key),
|
|
211
212
|
checkConnectivity: async () => {
|
|
212
213
|
await client.authenticatedLogin();
|
|
213
214
|
},
|
|
@@ -49,7 +49,12 @@ export function createConversationCommandReactor(orchestration, feedback) {
|
|
|
49
49
|
}
|
|
50
50
|
if (entry.origin.canClarify === false)
|
|
51
51
|
return;
|
|
52
|
-
await
|
|
52
|
+
await orchestration.requestReplyAssessment(workItemId, event.eventId, {
|
|
53
|
+
commandId: `${event.eventId}:reply-assessment`,
|
|
54
|
+
correlationId: correlationId(event.correlationId),
|
|
55
|
+
occurredAt: event.occurredAt,
|
|
56
|
+
actor: { kind: EventActorKind.Integration, id: entry.origin.adapter },
|
|
57
|
+
});
|
|
53
58
|
for (const workflow of await orchestration.listAll()) {
|
|
54
59
|
if (workflow.workItemId !== workItemId)
|
|
55
60
|
continue;
|
|
@@ -67,30 +72,6 @@ export function createConversationCommandReactor(orchestration, feedback) {
|
|
|
67
72
|
}),
|
|
68
73
|
};
|
|
69
74
|
}
|
|
70
|
-
/**
|
|
71
|
-
* A parent that escalated a delegated child's question to a human has no stage to resume. The
|
|
72
|
-
* human's reply is recorded on each asking child's own conversation, where the ordinary reply path
|
|
73
|
-
* resumes it; the cohort stays tracked and nothing is settled or joined.
|
|
74
|
-
*/
|
|
75
|
-
async function routeEscalatedReply(orchestration, feedback, event, workItemId, adapter) {
|
|
76
|
-
if (feedback === undefined)
|
|
77
|
-
return;
|
|
78
|
-
const context = {
|
|
79
|
-
commandId: `${event.eventId}:escalated-reply`,
|
|
80
|
-
correlationId: correlationId(event.correlationId),
|
|
81
|
-
occurredAt: event.occurredAt,
|
|
82
|
-
actor: { kind: EventActorKind.Integration, id: adapter },
|
|
83
|
-
};
|
|
84
|
-
for (const childWorkItemId of await orchestration.escalatedReplyTargets(workItemId)) {
|
|
85
|
-
const conversation = await feedback.conversations.createForWorkItem(childWorkItemId, context);
|
|
86
|
-
await feedback.conversations.record({
|
|
87
|
-
conversationId: conversation.conversationId,
|
|
88
|
-
entryId: `${event.eventId}:routed:${childWorkItemId}`,
|
|
89
|
-
body: event.entry.body,
|
|
90
|
-
origin: event.entry.origin,
|
|
91
|
-
}, context);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
75
|
async function applyExternalCommand(orchestration, feedback, event, input, context) {
|
|
95
76
|
const entryId = context.commandId + ':feedback';
|
|
96
77
|
const canPublish = input.authorized || input.reviewAuthorized === true;
|
|
@@ -3,7 +3,7 @@ import type { DelegationAuthority } from '../contracts/delegation-ports.js';
|
|
|
3
3
|
import { type CommandContext } from '@atolis-hq/eventing';
|
|
4
4
|
import type { ActivityName } from '../../activities/index.js';
|
|
5
5
|
import { type WorkService } from '../../work/index.js';
|
|
6
|
-
import type { DelegationArtifacts, DelegationRepositories } from '../contracts/delegation-ports.js';
|
|
6
|
+
import type { DelegationArtifacts, DelegationMessages, DelegationRepositories, DelegationResources } from '../contracts/delegation-ports.js';
|
|
7
7
|
import type { DelegatedAssignment, DelegationCaller, DelegationLimits, DelegationReservation, DelegationResult } from '../contracts/delegation.js';
|
|
8
8
|
import { type WorkflowInstanceId } from '../contracts/identifiers.js';
|
|
9
9
|
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
@@ -37,8 +37,16 @@ export declare class DelegatedWork {
|
|
|
37
37
|
readonly authority?: DelegationAuthority | undefined;
|
|
38
38
|
readonly supportsAttention?: ((activity: ActivityName) => boolean) | undefined;
|
|
39
39
|
readonly resumeChild?: DelegationAttentionDependencies['resumeChild'] | undefined;
|
|
40
|
+
readonly messages?: DelegationMessages | undefined;
|
|
41
|
+
readonly resources?: DelegationResources | undefined;
|
|
40
42
|
});
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* `verify` re-checks upstream outputs with the provider. Reads default to recorded facts
|
|
45
|
+
* because that check costs provider round trips on every call.
|
|
46
|
+
*/
|
|
47
|
+
inspect(id: WorkItemId, options?: {
|
|
48
|
+
readonly verify?: boolean;
|
|
49
|
+
}): Promise<{
|
|
42
50
|
settled: boolean;
|
|
43
51
|
failureReason: string | undefined;
|
|
44
52
|
children: {
|
|
@@ -164,6 +172,8 @@ export declare class DelegatedWork {
|
|
|
164
172
|
/** Appends the reservation only if the root stream is unchanged since `events` was read. */
|
|
165
173
|
private commit;
|
|
166
174
|
private reconcileReservation;
|
|
175
|
+
/** A human reply on a parent: wake it to pass the answer to the children still waiting. */
|
|
176
|
+
assessReply(parent: WorkflowInstanceView, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
167
177
|
/** Independent members keep advancing; a blocked member is skipped, never retried blindly. */
|
|
168
178
|
private advanceMembers;
|
|
169
179
|
private settleUnusable;
|
|
@@ -9,6 +9,7 @@ import { OrchestrationEventType } from '../contracts/events.js';
|
|
|
9
9
|
import { orchestrationGroupId, workflowInstanceId, } from '../contracts/identifiers.js';
|
|
10
10
|
import { DelegationConflictCode, DelegationPrerequisiteCondition, WorkflowStatus, } from '../contracts/vocabulary.js';
|
|
11
11
|
import { nextOrdinal } from '../domain/decision-events.js';
|
|
12
|
+
import { renderDelegatedBrief } from '../domain/delegated-brief.js';
|
|
12
13
|
import { assertCriteriaPreserving, originalOf } from '../domain/delivery-replacement.js';
|
|
13
14
|
import { isSuccessfulWorkflowCompletion } from '../domain/workflow-completion.js';
|
|
14
15
|
import { DelegationAttention, } from './delegation-attention.js';
|
|
@@ -18,6 +19,8 @@ import { assertWithinRootLimits, buildReservation, matchesAssignments, } from '.
|
|
|
18
19
|
import { resolvePrerequisites } from './delegation-wait-graph.js';
|
|
19
20
|
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
20
21
|
const defaultLimits = { maxDepth: 1, maxDescendants: 8 };
|
|
22
|
+
/** How long completed-child outputs may stay invisible before the child is blocked. */
|
|
23
|
+
const OUTPUT_VISIBILITY_GRACE_MS = 120_000;
|
|
21
24
|
/**
|
|
22
25
|
* Durable delegation of independent child WorkItems. Reservation is the single commit point;
|
|
23
26
|
* every later boundary is reconciled idempotently from it, and the parent stays fenced until join.
|
|
@@ -50,12 +53,17 @@ export class DelegatedWork {
|
|
|
50
53
|
resumeChild: (id, context) => dependencies.resumeChild?.(id, context) ?? Promise.resolve(null),
|
|
51
54
|
contextWorkItems: (parent) => this.contextWorkItems(parent),
|
|
52
55
|
canContinue: (reservation) => this.canJoin(reservation),
|
|
56
|
+
messages: dependencies.messages,
|
|
53
57
|
});
|
|
54
58
|
this.prerequisites = new DelegationPrerequisites(repository, this.ledger, dependencies.artifacts, dependencies.repositories, work);
|
|
55
59
|
this.repositories = dependencies.repositories;
|
|
56
60
|
this.runHasEnded = dependencies.runHasEnded;
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
/**
|
|
63
|
+
* `verify` re-checks upstream outputs with the provider. Reads default to recorded facts
|
|
64
|
+
* because that check costs provider round trips on every call.
|
|
65
|
+
*/
|
|
66
|
+
async inspect(id, options = {}) {
|
|
59
67
|
const item = await this.work.get(id);
|
|
60
68
|
const root = item?.delegation?.rootWorkItemId ?? id;
|
|
61
69
|
const events = await this.ledger.events();
|
|
@@ -72,7 +80,9 @@ export class DelegatedWork {
|
|
|
72
80
|
children: await Promise.all(reservation.children.map(async (child) => ({
|
|
73
81
|
...child,
|
|
74
82
|
work: await this.work.get(child.workItemId),
|
|
75
|
-
prerequisiteBlocker: (
|
|
83
|
+
prerequisiteBlocker: (options.verify === true
|
|
84
|
+
? await read.reason(child.workItemId)
|
|
85
|
+
: read.recordedReason(child.workItemId)) ?? childBlocker(events, child.workItemId),
|
|
76
86
|
consumedInputs: read.inputs(child.workItemId),
|
|
77
87
|
workflow: read.workflow(child.workflowInstanceId) ?? null,
|
|
78
88
|
}))),
|
|
@@ -364,6 +374,13 @@ export class DelegatedWork {
|
|
|
364
374
|
if (await this.childrenQualified(reservation, results, context))
|
|
365
375
|
await this.join(reservation, results, context);
|
|
366
376
|
}
|
|
377
|
+
/** A human reply on a parent: wake it to pass the answer to the children still waiting. */
|
|
378
|
+
async assessReply(parent, replyEntryId, context) {
|
|
379
|
+
const reservation = (await this.ledger.reservations()).find((entry) => entry.parentWorkflowInstanceId === parent.workflowInstanceId &&
|
|
380
|
+
entry.cohortId === parent.delegationWait?.cohortId);
|
|
381
|
+
if (reservation !== undefined)
|
|
382
|
+
await this.attention.raiseForReply(reservation, replyEntryId, context);
|
|
383
|
+
}
|
|
367
384
|
/** Independent members keep advancing; a blocked member is skipped, never retried blindly. */
|
|
368
385
|
async advanceMembers(artifacts, root, reservation, context) {
|
|
369
386
|
const read = await this.prerequisites.read();
|
|
@@ -510,6 +527,13 @@ export class DelegatedWork {
|
|
|
510
527
|
ancestors: reservation.ancestors,
|
|
511
528
|
},
|
|
512
529
|
}, childContext);
|
|
530
|
+
await this.dependencies.resources?.relateChild({ childWorkItemId: child.workItemId, parentWorkItemId: reservation.parentWorkItemId }, childContext);
|
|
531
|
+
await this.dependencies.messages?.post({
|
|
532
|
+
workItemId: child.workItemId,
|
|
533
|
+
entryId: `delegation:${child.grantId}`,
|
|
534
|
+
authorId: `delegation:${reservation.parentWorkItemId}`,
|
|
535
|
+
body: renderDelegatedBrief(child),
|
|
536
|
+
}, childContext);
|
|
513
537
|
await this.claims.claimPrimary(child.workItemId, child.workflowInstanceId, childContext);
|
|
514
538
|
await artifacts.registerChild({
|
|
515
539
|
delegationId: child.grantId,
|
|
@@ -598,7 +622,10 @@ export class DelegatedWork {
|
|
|
598
622
|
});
|
|
599
623
|
return;
|
|
600
624
|
}
|
|
601
|
-
|
|
625
|
+
// Provider evidence (e.g. a PR observation) lags the child's completion, so a later
|
|
626
|
+
// pass alone does not prove the output is missing; only a bounded wait does.
|
|
627
|
+
const waitedMs = Date.parse(context.occurredAt) - Date.parse(observed.event.occurredAt);
|
|
628
|
+
if (observed.event.causationId !== context.commandId && waitedMs >= OUTPUT_VISIBILITY_GRACE_MS)
|
|
602
629
|
await this.failChild(reservation, child, `Child ${child.workItemId} completed without required outputs`, context);
|
|
603
630
|
}
|
|
604
631
|
endedRun(id) {
|
|
@@ -50,4 +50,6 @@ export declare function reject(code: DelegationAttentionRejection, message: stri
|
|
|
50
50
|
* blocker and its kind, and the assignment revision. Returns the earlier identical reply, if any.
|
|
51
51
|
*/
|
|
52
52
|
export declare function assertReplyAllowed(parent: WorkflowInstanceView, attention: OpenAttention | null, caller: DelegationCaller, reply: DelegationAttentionReply): DelegationAttentionResponse | undefined;
|
|
53
|
+
/** Only the parked cohort wait may start an assessment; a running one coalesces new reasons. */
|
|
54
|
+
export declare function canRequestAssessment(view: WorkflowInstanceView, reservation: DelegationReservation): boolean;
|
|
53
55
|
export {};
|
|
@@ -188,7 +188,17 @@ export function assertReplyAllowed(parent, attention, caller, reply) {
|
|
|
188
188
|
if (reply.expectedRevision !== attention.revision)
|
|
189
189
|
throw reject(DelegationAttentionRejection.StaleRevision, 'The assignment revision changed; inspect before replying');
|
|
190
190
|
const prior = attention.responses.find((entry) => entry.blockerId === reply.blockerId);
|
|
191
|
-
if (prior !== undefined &&
|
|
191
|
+
if (prior !== undefined &&
|
|
192
|
+
(JSON.stringify(prior.references) !== JSON.stringify(reply.references) ||
|
|
193
|
+
prior.message !== reply.message))
|
|
192
194
|
throw reject(DelegationAttentionRejection.Duplicate, 'This blocker already has a different accepted reply');
|
|
195
|
+
if (reply.references.length === 0 && reply.message === undefined)
|
|
196
|
+
throw reject(DelegationAttentionRejection.EmptyReply, 'A reply needs a message, accepted artifact references, or both');
|
|
193
197
|
return prior;
|
|
194
198
|
}
|
|
199
|
+
/** Only the parked cohort wait may start an assessment; a running one coalesces new reasons. */
|
|
200
|
+
export function canRequestAssessment(view, reservation) {
|
|
201
|
+
return (view.status === WorkflowStatus.Waiting &&
|
|
202
|
+
view.delegationWait?.cohortId === reservation.cohortId &&
|
|
203
|
+
view.delegationAttention === undefined);
|
|
204
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CommandContext } from '@atolis-hq/eventing';
|
|
2
2
|
import { type ActivityName } from '../../activities/index.js';
|
|
3
|
-
import type { DelegationArtifacts } from '../contracts/delegation-ports.js';
|
|
3
|
+
import type { DelegationArtifacts, DelegationMessages } from '../contracts/delegation-ports.js';
|
|
4
4
|
import type { DelegationAttentionBlocker, DelegationAttentionReply, DelegationCaller, DelegationReservation } from '../contracts/delegation.js';
|
|
5
5
|
import { type WorkflowOrchestrationEvent } from '../contracts/events.js';
|
|
6
6
|
import type { WorkflowInstanceId } from '../contracts/identifiers.js';
|
|
@@ -16,6 +16,8 @@ export interface DelegationAttentionDependencies {
|
|
|
16
16
|
readonly resumeChild: (id: WorkflowInstanceId, context: CommandContext) => Promise<WorkflowInstanceView | null>;
|
|
17
17
|
/** Work items whose artifacts the parent may reference (its own hierarchy). */
|
|
18
18
|
readonly contextWorkItems: (parent: WorkflowInstanceView) => Promise<ReadonlySet<string>>;
|
|
19
|
+
/** Where a parent's free-text answer is posted: the child's own conversation. */
|
|
20
|
+
readonly messages?: DelegationMessages | undefined;
|
|
19
21
|
/** Run end and delivery availability gate every attention continuation, like the join. */
|
|
20
22
|
readonly canContinue: (reservation: DelegationReservation) => Promise<boolean>;
|
|
21
23
|
}
|
|
@@ -33,8 +35,12 @@ export declare class DelegationAttention {
|
|
|
33
35
|
* Callers settle fully terminal batches through the ordinary unsuccessful continuation instead.
|
|
34
36
|
*/
|
|
35
37
|
raise(reservation: DelegationReservation, context: CommandContext): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A human replied on the parent while children wait on a clarification. The reply is new
|
|
40
|
+
* information on blockers already assessed, so wake the parent once per reply to decide how
|
|
41
|
+
* to pass it on; replaying the same reply never wakes it twice.
|
|
42
|
+
*/
|
|
43
|
+
raiseForReply(reservation: DelegationReservation, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
38
44
|
/** Returns false when a concurrent append won and the caller must re-read. */
|
|
39
45
|
private request;
|
|
40
46
|
/** The open attention request for a parent, with the replies already accepted. */
|
|
@@ -47,12 +53,4 @@ export declare class DelegationAttention {
|
|
|
47
53
|
/** Ends the assessment and restores the unresolved wait; a pending join then proceeds. */
|
|
48
54
|
resolve(parentId: WorkflowInstanceId, attentionActivation: string, context: CommandContext, verdict?: AttentionVerdict): Promise<WorkflowInstanceView>;
|
|
49
55
|
private priorFailures;
|
|
50
|
-
/**
|
|
51
|
-
* Children whose assignment-context blocker the parent escalated to a human and which are still
|
|
52
|
-
* blocked on it. A human reply on the parent is routed to exactly these, so a published question
|
|
53
|
-
* always has an answer path that moves the delivery without settling or joining the cohort.
|
|
54
|
-
*/
|
|
55
|
-
escalatedTargets(parent: WorkflowInstanceView): Promise<readonly {
|
|
56
|
-
readonly childWorkItemId: string;
|
|
57
|
-
}[]>;
|
|
58
56
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { WrongExpectedSequenceError } from '@atolis-hq/eventing';
|
|
2
2
|
import { activationId } from '../../activities/index.js';
|
|
3
3
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
4
|
-
import { DelegationAttentionRejection,
|
|
4
|
+
import { DelegationAttentionRejection, DelegationBlockerKind } from '../contracts/vocabulary.js';
|
|
5
5
|
import { nextOrdinal } from '../domain/decision-events.js';
|
|
6
|
-
import {
|
|
7
|
-
import { assertReplyAllowed, assessedBlockers, attentionKeyOf, blockerOf, contextBlockerId, digest, MaxAssessmentAttempts, reject, resolutionDrafts, } from './delegation-attention-state.js';
|
|
6
|
+
import { assertReplyAllowed, assessedBlockers, attentionKeyOf, blockerOf, canRequestAssessment, contextBlockerId, digest, MaxAssessmentAttempts, reject, resolutionDrafts, } from './delegation-attention-state.js';
|
|
8
7
|
import { delegationDraft, isSettled } from './delegation-ledger.js';
|
|
9
8
|
/** Durable cohort/blocker state for the parent attention protocol. */
|
|
10
9
|
export class DelegationAttention {
|
|
@@ -49,17 +48,36 @@ export class DelegationAttention {
|
|
|
49
48
|
const attentionKey = attentionKeyOf(reservation, blockers.map((blocker) => blocker.blockerId));
|
|
50
49
|
for (;;) {
|
|
51
50
|
const loaded = await this.repository.loadRequired(reservation.parentWorkflowInstanceId);
|
|
52
|
-
if (!
|
|
51
|
+
if (!canRequestAssessment(loaded.view, reservation))
|
|
53
52
|
return;
|
|
54
53
|
if (await this.request(reservation, loaded, { attentionKey, blockers }, context))
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A human replied on the parent while children wait on a clarification. The reply is new
|
|
59
|
+
* information on blockers already assessed, so wake the parent once per reply to decide how
|
|
60
|
+
* to pass it on; replaying the same reply never wakes it twice.
|
|
61
|
+
*/
|
|
62
|
+
async raiseForReply(reservation, replyEntryId, context) {
|
|
63
|
+
const events = await this.ledger.events();
|
|
64
|
+
if (isSettled(events, reservation))
|
|
65
|
+
return;
|
|
66
|
+
const blockers = (await this.blockers(reservation, events)).filter((blocker) => blocker.kind === DelegationBlockerKind.Context);
|
|
67
|
+
if (blockers.length === 0 || !(await this.dependencies.canContinue(reservation)))
|
|
68
|
+
return;
|
|
69
|
+
const attentionKey = `${attentionKeyOf(reservation, blockers.map((blocker) => blocker.blockerId))}:reply:${digest(replyEntryId)}`;
|
|
70
|
+
const asked = events.some(({ event }) => event.eventType === OrchestrationEventType.DelegationAttentionRequested &&
|
|
71
|
+
event.payload.attentionKey === attentionKey);
|
|
72
|
+
if (asked)
|
|
73
|
+
return;
|
|
74
|
+
for (;;) {
|
|
75
|
+
const loaded = await this.repository.loadRequired(reservation.parentWorkflowInstanceId);
|
|
76
|
+
if (!canRequestAssessment(loaded.view, reservation))
|
|
77
|
+
return;
|
|
78
|
+
if (await this.request(reservation, loaded, { attentionKey, blockers }, context))
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
63
81
|
}
|
|
64
82
|
/** Returns false when a concurrent append won and the caller must re-read. */
|
|
65
83
|
async request(reservation, loaded, input, context) {
|
|
@@ -158,12 +176,21 @@ export class DelegationAttention {
|
|
|
158
176
|
eventType: OrchestrationEventType.DelegationAttentionResponded,
|
|
159
177
|
payload: { cohortId: attention.cohortId, attentionKey: attention.attentionKey, ...reply },
|
|
160
178
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
if (reply.references.length > 0)
|
|
180
|
+
await this.dependencies.artifacts.registerChild({
|
|
181
|
+
delegationId: `${child.grantId}:response:${key}`,
|
|
182
|
+
parentWorkItemId: reservation.parentWorkItemId,
|
|
183
|
+
childWorkItemId: child.workItemId,
|
|
184
|
+
childReferences: reply.references,
|
|
185
|
+
}, context);
|
|
186
|
+
// Posted before the child resumes, so its next turn reads the answer.
|
|
187
|
+
if (reply.message !== undefined)
|
|
188
|
+
await this.dependencies.messages?.post({
|
|
189
|
+
workItemId: child.workItemId,
|
|
190
|
+
entryId: `delegation-reply:${key}`,
|
|
191
|
+
authorId: `delegation:${reservation.parentWorkItemId}`,
|
|
192
|
+
body: reply.message,
|
|
193
|
+
}, context);
|
|
167
194
|
if (stillBlocked)
|
|
168
195
|
await this.dependencies.resumeChild(child.workflowInstanceId, {
|
|
169
196
|
...context,
|
|
@@ -195,12 +222,4 @@ export class DelegationAttention {
|
|
|
195
222
|
event.payload.attentionKey === attentionKey &&
|
|
196
223
|
event.payload.assessmentFailure !== undefined).length;
|
|
197
224
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Children whose assignment-context blocker the parent escalated to a human and which are still
|
|
200
|
-
* blocked on it. A human reply on the parent is routed to exactly these, so a published question
|
|
201
|
-
* always has an answer path that moves the delivery without settling or joining the cohort.
|
|
202
|
-
*/
|
|
203
|
-
escalatedTargets(parent) {
|
|
204
|
-
return escalatedTargets(this.repository, this.ledger, parent);
|
|
205
|
-
}
|
|
206
225
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DelegationArtifacts, DelegationAuthority, DelegationRepositories } from '../contracts/delegation-ports.js';
|
|
1
|
+
import type { DelegationArtifacts, DelegationAuthority, DelegationMessages, DelegationRepositories, DelegationResources } from '../contracts/delegation-ports.js';
|
|
2
2
|
import type { DelegationAttentionReply, DelegationCaller, DelegationSubmission } from '../contracts/delegation.js';
|
|
3
3
|
import type { DeliveryIntegration } from '../contracts/delivery-ports.js';
|
|
4
4
|
import type { DeliveryCandidateCommand, DeliveryMaintenanceCommand, DeliveryQaCommand, DeliverySelectionCommand } from '../contracts/delivery.js';
|
|
@@ -547,7 +547,9 @@ export declare class OrchestrationService {
|
|
|
547
547
|
maxConcurrentRuns?: number | undefined;
|
|
548
548
|
}[];
|
|
549
549
|
}>;
|
|
550
|
-
deliveryTree(id: WorkItemId
|
|
550
|
+
deliveryTree(id: WorkItemId, options?: {
|
|
551
|
+
readonly verify?: boolean;
|
|
552
|
+
}): Promise<{
|
|
551
553
|
settled: boolean;
|
|
552
554
|
failureReason: string | undefined;
|
|
553
555
|
children: {
|
|
@@ -682,8 +684,11 @@ export declare class OrchestrationService {
|
|
|
682
684
|
* number of times. The cohort is never settled or cancelled by the assessment itself.
|
|
683
685
|
*/
|
|
684
686
|
private endAttention;
|
|
685
|
-
/**
|
|
686
|
-
|
|
687
|
+
/**
|
|
688
|
+
* A human replied on this work item while delegated children wait on a clarification: wake
|
|
689
|
+
* the delegating stage once, so the parent decides how to pass the reply to each child.
|
|
690
|
+
*/
|
|
691
|
+
requestReplyAssessment(workItemId: WorkItemId, replyEntryId: string, context: CommandContext): Promise<void>;
|
|
687
692
|
/** The open attention request when `activationId` is the attention activation, else null. */
|
|
688
693
|
openDelegationAttention(id: WorkflowInstanceId, activationId: ActivationId): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
|
|
689
694
|
respondToDelegationAttention(caller: DelegationCaller, reply: DelegationAttentionReply, context: CommandContext): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
|
|
@@ -761,6 +766,8 @@ type DelegationDependenciesFactory = (queries: {
|
|
|
761
766
|
artifacts: DelegationArtifacts;
|
|
762
767
|
authority?: DelegationAuthority;
|
|
763
768
|
repositories?: DelegationRepositories;
|
|
769
|
+
messages?: DelegationMessages;
|
|
770
|
+
resources?: DelegationResources;
|
|
764
771
|
integration?: DeliveryIntegration;
|
|
765
772
|
runHasEnded: (runId: string) => Promise<boolean>;
|
|
766
773
|
};
|