@atolis-hq/wake 0.4.66 → 0.4.67
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/integration-runtime.js +17 -2
- package/dist/src/bootstrap/surface-api-work-applications.js +38 -3
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/conversations/contracts/events.js +2 -0
- package/dist/src/conversations/contracts/views.d.ts +5 -1
- package/dist/src/integrations/application/conversation-command-feedback.d.ts +11 -0
- package/dist/src/integrations/application/conversation-command-feedback.js +36 -0
- package/dist/src/integrations/delivery/application/delivery-intent-lookup.d.ts +4 -0
- package/dist/src/integrations/delivery/application/delivery-intent-lookup.js +23 -0
- package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +4 -11
- package/dist/src/integrations/delivery/application/delivery-projector.js +7 -1
- package/dist/src/integrations/delivery/contracts/intents.d.ts +3 -1
- package/dist/src/integrations/delivery/contracts/intents.js +1 -1
- package/dist/src/integrations/delivery/contracts/views.d.ts +1 -0
- package/dist/src/integrations/github/application/agent-run-comment.js +7 -9
- package/dist/src/integrations/github/application/inbound-translator.js +13 -1
- package/dist/src/integrations/github/application/work-control-authorization.d.ts +6 -0
- package/dist/src/integrations/github/application/work-control-authorization.js +10 -0
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/orchestration/application/conversation-command-reactor.d.ts +16 -1
- package/dist/src/orchestration/application/conversation-command-reactor.js +34 -5
- package/dist/src/orchestration/application/conversation-command.d.ts +27 -4
- package/dist/src/orchestration/application/conversation-command.js +60 -22
- package/dist/src/orchestration/application/orchestration-service.d.ts +5 -8
- package/dist/src/orchestration/application/orchestration-service.js +93 -34
- package/dist/src/orchestration/domain/interpreter.d.ts +1 -1
- package/dist/src/orchestration/domain/interpreter.js +1 -1
- package/dist/src/orchestration/domain/operator-retry-policy.d.ts +2 -0
- package/dist/src/orchestration/domain/operator-retry-policy.js +24 -1
- package/dist/src/surfaces/api/contracts/work.d.ts +3 -0
- package/dist/src/surfaces/api/routes/commands.js +8 -2
- package/dist/src/surfaces/web-assets/assets/{index-9IfrHvBo.js → index-DMS1vQy3.js} +3 -3
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
|
@@ -4,8 +4,9 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ActivityExecutionKind, activityName, } from '../activities/index.js';
|
|
6
6
|
import { ControlEventType, ControlStreamKind, TriggerService, createDurableRunnerIneligibility, createIntakePipeline, createRunnerPipeline, createTriggerReactor, createWorkCancellationPolicy, selectControlEvent, triggerInvocationProjection, triggerInvocationStream, } from '../control-plane/index.js';
|
|
7
|
+
import { ConversationOriginKind, workItemIdForConversation } from '../conversations/index.js';
|
|
7
8
|
import { ExecutionStreamKind, NoEligibleRunnerError, RunRepository, createRuntimeMemoryProfile, decodeActivationExecutionEvent, isActiveRunStatus, isRunStream, runId, } from '../execution/index.js';
|
|
8
|
-
import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, PollService, ProviderRegistry, deliveryProjectionDefinitions, fakeProviderDefinition, } from '../integrations/index.js';
|
|
9
|
+
import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, PollService, ProviderRegistry, deliveryProjectionDefinitions, fakeProviderDefinition, publishConversationCommandFeedback, } from '../integrations/index.js';
|
|
9
10
|
import { compileWorkflowSelectors, createConversationCommandReactor, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, createWatchReconciler, isWorkflowInstanceStream, selectWorkflow, workflowInstanceId, workflowName, } from '../orchestration/index.js';
|
|
10
11
|
import { BuiltInResourceCapability, resourceId, } from '../resources/index.js';
|
|
11
12
|
import { isWorkItemStream } from '../work/index.js';
|
|
@@ -212,7 +213,21 @@ export async function composeIntegrationRuntime(input) {
|
|
|
212
213
|
return operation();
|
|
213
214
|
});
|
|
214
215
|
const outcomes = new DeliveryOutcomeReactor(input.journal, input.orchestration, input.projections, input.processorState, input.conversations, input.subscriptionRunSerialiser);
|
|
215
|
-
const conversationCommands = createConversationCommandReactor(input.orchestration
|
|
216
|
+
const conversationCommands = createConversationCommandReactor(input.orchestration, {
|
|
217
|
+
conversations: input.conversations,
|
|
218
|
+
publish: async (event, body, context) => {
|
|
219
|
+
if (event.entry.origin.kind !== ConversationOriginKind.External)
|
|
220
|
+
return;
|
|
221
|
+
await publishConversationCommandFeedback({
|
|
222
|
+
journal: input.journal,
|
|
223
|
+
orchestration: input.orchestration,
|
|
224
|
+
workItemId: workItemIdForConversation(event.conversationId),
|
|
225
|
+
resourceId: event.entry.origin.resourceId,
|
|
226
|
+
body,
|
|
227
|
+
context,
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
});
|
|
216
231
|
// Only poll hits a rate-limited external API, so only this half of the
|
|
217
232
|
// Tick needs a backing-off host; see bootstrap/surface-cli-applications.ts.
|
|
218
233
|
// Inbound translation reads durable provider facts through its own services,
|
|
@@ -3,7 +3,7 @@ import { pullRequestProjection } from '../activities/index.js';
|
|
|
3
3
|
import { triggerInvocationProjection } from '../control-plane/index.js';
|
|
4
4
|
import { conversationIdForWorkItem, ConversationOriginKind, } from '../conversations/index.js';
|
|
5
5
|
import { executionProjection, runsByWorkflowInstanceProjection, } from '../execution/index.js';
|
|
6
|
-
import { ApprovalAuthorityKind, ConversationSurfaceCapability, GroupBudgetExtensionIneligibleError, isGroupBudgetExtensionEligible, OperatorRetryIneligibleError, orchestrationProjection, selectOperatorRetryTarget, workflowsByWorkItemProjection, } from '../orchestration/index.js';
|
|
6
|
+
import { ApprovalAuthorityKind, conversationCommand, ConversationSurfaceCapability, GroupBudgetExtensionIneligibleError, isGroupBudgetExtensionEligible, OperatorRetryIneligibleError, orchestrationProjection, selectChangesResumeTargets, selectOperatorRetryTarget, workflowsByWorkItemProjection, } from '../orchestration/index.js';
|
|
7
7
|
import { workCorrelationsProjection, } from '../resources/index.js';
|
|
8
8
|
import { ApiCommandStatus, fromWorkItemKey, presentResource, presentRun, presentWorkflowInstance, presentWorkItem, toWorkItemKey, } from '../surfaces/index.js';
|
|
9
9
|
import { workItemId, WorkStatus } from '../work/index.js';
|
|
@@ -87,6 +87,8 @@ export function createSurfaceWorkApplications(root, now) {
|
|
|
87
87
|
return retryIneligible('Work item was not found');
|
|
88
88
|
if (work.deleted === true)
|
|
89
89
|
return retryIneligible('Work item is deleted');
|
|
90
|
+
if (work.frozen)
|
|
91
|
+
return retryIneligible('Work item is frozen');
|
|
90
92
|
if (work.state !== WorkStatus.Open)
|
|
91
93
|
return retryIneligible('Work item is not open');
|
|
92
94
|
const workflows = (await root.orchestration.listAll()).filter((workflow) => workflow.workItemId === id);
|
|
@@ -114,6 +116,8 @@ export function createSurfaceWorkApplications(root, now) {
|
|
|
114
116
|
return extendIneligible('Work item was not found');
|
|
115
117
|
if (work.deleted === true)
|
|
116
118
|
return extendIneligible('Work item is deleted');
|
|
119
|
+
if (work.frozen)
|
|
120
|
+
return extendIneligible('Work item is frozen');
|
|
117
121
|
if (work.state !== WorkStatus.Open)
|
|
118
122
|
return extendIneligible('Work item is not open');
|
|
119
123
|
const primary = (await root.orchestration.listForWorkItem(id)).find((workflow) => workflow.parentWorkflowInstanceId === undefined);
|
|
@@ -150,6 +154,23 @@ export function createSurfaceWorkApplications(root, now) {
|
|
|
150
154
|
body: command.body,
|
|
151
155
|
origin: { kind: ConversationOriginKind.ControlPlane, actorId: context.actor.id },
|
|
152
156
|
}, context);
|
|
157
|
+
if (conversationCommand(command.body) !== null || command.continuation === true) {
|
|
158
|
+
const result = await root.orchestration.applyConversationCommandWithFeedback(id, {
|
|
159
|
+
body: command.body,
|
|
160
|
+
actorId: context.actor.id,
|
|
161
|
+
capabilities: [ConversationSurfaceCapability.Operator],
|
|
162
|
+
authorized: true,
|
|
163
|
+
reviewAuthorized: true,
|
|
164
|
+
continuation: command.continuation === true,
|
|
165
|
+
}, context);
|
|
166
|
+
if (!result.applied)
|
|
167
|
+
return {
|
|
168
|
+
conflict: true,
|
|
169
|
+
code: 'conversation-command-inapplicable',
|
|
170
|
+
detail: result.reason,
|
|
171
|
+
};
|
|
172
|
+
return accepted(command.idempotencyKey, now());
|
|
173
|
+
}
|
|
153
174
|
const dispatch = root.orchestration
|
|
154
175
|
.applyConversationCommand;
|
|
155
176
|
const applied = dispatch === undefined
|
|
@@ -172,7 +193,7 @@ async function resumeAgentStages(root, itemId, context) {
|
|
|
172
193
|
const workflows = await root.orchestration.listForWorkItem(itemId);
|
|
173
194
|
for (const workflow of workflows)
|
|
174
195
|
try {
|
|
175
|
-
await root.orchestration.
|
|
196
|
+
await root.orchestration.resumeBlockedStageForReply(workflow.workflowInstanceId, context);
|
|
176
197
|
}
|
|
177
198
|
catch (error) {
|
|
178
199
|
console.error(`Conversation message resume failed for workflow ${workflow.workflowInstanceId}`, error);
|
|
@@ -215,7 +236,11 @@ async function workDetail(root, key, now) {
|
|
|
215
236
|
},
|
|
216
237
|
activities: presentPullRequest(pullRequest?.value),
|
|
217
238
|
artifacts: await presentArtifacts(root, id),
|
|
218
|
-
conversation:
|
|
239
|
+
conversation: {
|
|
240
|
+
...presentConversation(conversation, root.config?.surfaces.api.conversationMessages.enabled ===
|
|
241
|
+
true),
|
|
242
|
+
canContinue: canContinueWork(work, workflows, conversationMessagesAllowed(root)),
|
|
243
|
+
},
|
|
219
244
|
};
|
|
220
245
|
const [projections, correlationFacts] = await Promise.all([
|
|
221
246
|
contributingProjections(root, id, resources, workflows, runs),
|
|
@@ -360,3 +385,13 @@ async function triggerOriginForWork(root, id) {
|
|
|
360
385
|
const origin = await root.projections.read(triggerInvocationProjection.name, id);
|
|
361
386
|
return origin?.value == null ? {} : { triggerOrigin: origin.value.claim.triggerId };
|
|
362
387
|
}
|
|
388
|
+
function conversationMessagesAllowed(root) {
|
|
389
|
+
return (root.config?.surfaces.api.conversationMessages.enabled === true);
|
|
390
|
+
}
|
|
391
|
+
function canContinueWork(work, workflows, enabled) {
|
|
392
|
+
return (enabled &&
|
|
393
|
+
work.state === WorkStatus.Open &&
|
|
394
|
+
!work.frozen &&
|
|
395
|
+
!work.deleted &&
|
|
396
|
+
selectChangesResumeTargets(workflows).length > 0);
|
|
397
|
+
}
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.67";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -40,6 +40,8 @@ const origin = z.discriminatedUnion('kind', [
|
|
|
40
40
|
threadId: z.string().min(1),
|
|
41
41
|
messageId: z.string().min(1),
|
|
42
42
|
authorized: z.boolean().optional(),
|
|
43
|
+
reviewAuthorized: z.boolean().optional(),
|
|
44
|
+
canClarify: z.boolean().optional(),
|
|
43
45
|
capabilities: z.array(z.string().min(1)).readonly().optional(),
|
|
44
46
|
location: z
|
|
45
47
|
.object({
|
|
@@ -16,8 +16,12 @@ export type ConversationEntryOrigin = {
|
|
|
16
16
|
readonly resourceId: string;
|
|
17
17
|
readonly threadId: string;
|
|
18
18
|
readonly messageId: string;
|
|
19
|
-
/**
|
|
19
|
+
/** Work-control authority established by the receiving surface. Legacy entries used review authority. */
|
|
20
20
|
readonly authorized?: boolean | undefined;
|
|
21
|
+
/** Independent-review authority, separate from work control. */
|
|
22
|
+
readonly reviewAuthorized?: boolean | undefined;
|
|
23
|
+
/** Whether this participant may answer a clarification without control authority. */
|
|
24
|
+
readonly canClarify?: boolean | undefined;
|
|
21
25
|
/** Commands available to this entry's receiving surface. */
|
|
22
26
|
readonly capabilities?: readonly string[] | undefined;
|
|
23
27
|
readonly location?: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CommandContext, type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
+
import type { OrchestrationService } from '../../orchestration/index.js';
|
|
3
|
+
/** Publish command feedback through the same durable delivery lane as activity replies. */
|
|
4
|
+
export declare function publishConversationCommandFeedback(input: {
|
|
5
|
+
readonly journal: EventJournal;
|
|
6
|
+
readonly orchestration: OrchestrationService;
|
|
7
|
+
readonly workItemId: Parameters<OrchestrationService['listForWorkItem']>[0];
|
|
8
|
+
readonly resourceId: string;
|
|
9
|
+
readonly body: string;
|
|
10
|
+
readonly context: CommandContext;
|
|
11
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventActorKind, EventSourceKind, } from '@atolis-hq/eventing';
|
|
2
|
+
import { resourceId, resourceStream } from '../../resources/index.js';
|
|
3
|
+
import { createDeliveryIntentEventData } from '../delivery/contracts/event-factory.js';
|
|
4
|
+
import { DeliveryIntentEventType } from '../delivery/contracts/intents.js';
|
|
5
|
+
/** Publish command feedback through the same durable delivery lane as activity replies. */
|
|
6
|
+
export async function publishConversationCommandFeedback(input) {
|
|
7
|
+
const primary = (await input.orchestration.listAll())
|
|
8
|
+
.filter((workflow) => workflow.workItemId === input.workItemId)
|
|
9
|
+
.find((workflow) => workflow.parentWorkflowInstanceId === undefined);
|
|
10
|
+
if (primary?.pendingActivation === undefined)
|
|
11
|
+
return;
|
|
12
|
+
const target = resourceId(input.resourceId);
|
|
13
|
+
const stream = resourceStream(target);
|
|
14
|
+
const eventId = `${input.context.commandId}:feedback-delivery`;
|
|
15
|
+
const events = await input.journal.readStream(stream);
|
|
16
|
+
if (events.some((event) => event.event.eventId === eventId))
|
|
17
|
+
return;
|
|
18
|
+
await input.journal.appendToStream(stream, events.length, [
|
|
19
|
+
createDeliveryIntentEventData({
|
|
20
|
+
eventId,
|
|
21
|
+
eventType: DeliveryIntentEventType.ReplyPublishRequested,
|
|
22
|
+
occurredAt: input.context.occurredAt,
|
|
23
|
+
correlationId: input.context.correlationId,
|
|
24
|
+
causationId: input.context.commandId,
|
|
25
|
+
actor: { kind: EventActorKind.System, id: 'conversation-command-feedback' },
|
|
26
|
+
source: { kind: EventSourceKind.Internal, id: 'conversation-command-feedback' },
|
|
27
|
+
payload: {
|
|
28
|
+
resourceId: target,
|
|
29
|
+
publicationOnly: true,
|
|
30
|
+
workflowInstanceId: primary.workflowInstanceId,
|
|
31
|
+
activationId: primary.pendingActivation.activationId,
|
|
32
|
+
body: input.body,
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProjectionStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { DeliveryIntentView } from '../contracts/views.js';
|
|
3
|
+
export declare function isPublicationOnlyDelivery(projections: ProjectionStore, intentEventId: string): Promise<boolean>;
|
|
4
|
+
export declare function conversationDeliveryIntent(projections: ProjectionStore, intentEventId: string): Promise<DeliveryIntentView | undefined>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IntegrationStreamKind } from '../../contracts/streams.js';
|
|
2
|
+
import { DeliveryIntentKind } from '../contracts/vocabulary.js';
|
|
3
|
+
export async function isPublicationOnlyDelivery(projections, intentEventId) {
|
|
4
|
+
const intent = (await projections.list(IntegrationStreamKind.Delivery)).find((entry) => entry.value.intentEventId === intentEventId)?.value;
|
|
5
|
+
return (intent !== undefined &&
|
|
6
|
+
isReplyPublication(intent.payload) &&
|
|
7
|
+
intent.payload.publicationOnly === true);
|
|
8
|
+
}
|
|
9
|
+
export async function conversationDeliveryIntent(projections, intentEventId) {
|
|
10
|
+
const intent = (await projections.list(IntegrationStreamKind.Delivery)).find((candidate) => candidate.value.intentEventId === intentEventId)?.value;
|
|
11
|
+
if (intent === undefined ||
|
|
12
|
+
!isAgentRunPublication(intent.payload) ||
|
|
13
|
+
intent.payload.conversationId === undefined ||
|
|
14
|
+
intent.payload.conversationEntryId === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
return intent;
|
|
17
|
+
}
|
|
18
|
+
function isReplyPublication(payload) {
|
|
19
|
+
return payload.kind === DeliveryIntentKind.ReplyPublish;
|
|
20
|
+
}
|
|
21
|
+
function isAgentRunPublication(payload) {
|
|
22
|
+
return payload.kind === DeliveryIntentKind.AgentRunPublish;
|
|
23
|
+
}
|
|
@@ -3,9 +3,9 @@ import { z } from 'zod';
|
|
|
3
3
|
import { activationId, ActivityOutcomeKind } from '../../../activities/index.js';
|
|
4
4
|
import { brandedStringSchema, offsetIsoTimestampSchema } from '../../../kernel/index.js';
|
|
5
5
|
import { ActivityActivationStatus, workflowInstanceId, } from '../../../orchestration/index.js';
|
|
6
|
-
import { IntegrationStreamKind } from '../../contracts/streams.js';
|
|
7
6
|
import { DeliveryEventType, selectDeliveryEvent, } from '../contracts/events.js';
|
|
8
|
-
import {
|
|
7
|
+
import { DeliveryResultKind } from '../contracts/vocabulary.js';
|
|
8
|
+
import { conversationDeliveryIntent, isPublicationOnlyDelivery } from './delivery-intent-lookup.js';
|
|
9
9
|
const deliveryResultSignalKind = 'delivery-result';
|
|
10
10
|
export const DeliveryOutcomeProcessorConsumer = 'reactor:delivery-outcomes';
|
|
11
11
|
const pendingConsumer = DeliveryOutcomeProcessorConsumer;
|
|
@@ -120,6 +120,8 @@ export class DeliveryOutcomeReactor {
|
|
|
120
120
|
// Optional conversation provenance must not block delivery reconciliation.
|
|
121
121
|
console.error(`Conversation provenance recording failed for ${delivery.eventId}`, error);
|
|
122
122
|
}
|
|
123
|
+
if (await isPublicationOnlyDelivery(this.projections, delivery.payload.intentEventId))
|
|
124
|
+
return true;
|
|
123
125
|
const command = {
|
|
124
126
|
workflowInstanceId: workflowInstanceId(delivery.payload.workflowInstanceId),
|
|
125
127
|
activationId: activationId(delivery.payload.activationId),
|
|
@@ -224,12 +226,3 @@ function isConfirmedDelivery(delivery) {
|
|
|
224
226
|
function confirmedExternalId(delivery) {
|
|
225
227
|
return delivery.eventType === DeliveryEventType.Failed ? undefined : delivery.payload.externalId;
|
|
226
228
|
}
|
|
227
|
-
async function conversationDeliveryIntent(projections, intentEventId) {
|
|
228
|
-
const intent = (await projections.list(IntegrationStreamKind.Delivery)).find((candidate) => candidate.value.intentEventId === intentEventId)?.value;
|
|
229
|
-
if (intent?.payload.kind !== DeliveryIntentKind.AgentRunPublish ||
|
|
230
|
-
!('conversationId' in intent.payload) ||
|
|
231
|
-
intent.payload.conversationId === undefined ||
|
|
232
|
-
intent.payload.conversationEntryId === undefined)
|
|
233
|
-
return undefined;
|
|
234
|
-
return intent;
|
|
235
|
-
}
|
|
@@ -141,7 +141,13 @@ function integrationIntentView(integrationIntent) {
|
|
|
141
141
|
resourceId: integrationIntent.event.payload.resourceId,
|
|
142
142
|
payload: status
|
|
143
143
|
? { kind: DeliveryIntentKind.StatusPublish, body: integrationIntent.event.payload.body }
|
|
144
|
-
: {
|
|
144
|
+
: {
|
|
145
|
+
kind: DeliveryIntentKind.ReplyPublish,
|
|
146
|
+
body: integrationIntent.event.payload.body,
|
|
147
|
+
...(integrationIntent.event.payload.publicationOnly === true
|
|
148
|
+
? { publicationOnly: true }
|
|
149
|
+
: {}),
|
|
150
|
+
},
|
|
145
151
|
state: DeliveryState.Pending,
|
|
146
152
|
attempts: 0,
|
|
147
153
|
occurrenceOrdinal: 0,
|
|
@@ -44,7 +44,9 @@ interface AgentRunPublishRequestedPayload {
|
|
|
44
44
|
}
|
|
45
45
|
export interface DeliveryIntentEventPayloads {
|
|
46
46
|
readonly [DeliveryIntentEventType.StatusPublishRequested]: PublishRequestedPayload;
|
|
47
|
-
readonly [DeliveryIntentEventType.ReplyPublishRequested]: PublishRequestedPayload
|
|
47
|
+
readonly [DeliveryIntentEventType.ReplyPublishRequested]: PublishRequestedPayload & {
|
|
48
|
+
readonly publicationOnly?: true | undefined;
|
|
49
|
+
};
|
|
48
50
|
readonly [DeliveryIntentEventType.AgentRunPublishRequested]: AgentRunPublishRequestedPayload;
|
|
49
51
|
}
|
|
50
52
|
export type DeliveryIntentEvent = EventUnion<DeliveryIntentEventPayloads, ResourceStreamRef>;
|
|
@@ -63,7 +63,7 @@ const intentEventSchema = z
|
|
|
63
63
|
eventEnvelopeSchema.extend({
|
|
64
64
|
event: eventDataSchema.extend({
|
|
65
65
|
eventType: z.literal(DeliveryIntentEventType.ReplyPublishRequested),
|
|
66
|
-
payload: publishSchema,
|
|
66
|
+
payload: publishSchema.extend({ publicationOnly: z.literal(true).optional() }),
|
|
67
67
|
}),
|
|
68
68
|
stream: resourceStreamSchema,
|
|
69
69
|
}),
|
|
@@ -28,6 +28,7 @@ export interface DeliveryIntentView {
|
|
|
28
28
|
} | {
|
|
29
29
|
readonly kind: typeof DeliveryIntentKind.ReplyPublish;
|
|
30
30
|
readonly body: string;
|
|
31
|
+
readonly publicationOnly?: true;
|
|
31
32
|
} | {
|
|
32
33
|
readonly kind: typeof DeliveryIntentKind.AgentRunPublish;
|
|
33
34
|
readonly report: AgentRunPublicationReport;
|
|
@@ -8,9 +8,13 @@ export function formatAgentRunComment(value) {
|
|
|
8
8
|
value.displayBody.trim() || fallback(value.outcome),
|
|
9
9
|
];
|
|
10
10
|
if (value.awaitingApproval === true)
|
|
11
|
-
sections.push('
|
|
11
|
+
sections.push('_An authorized independent reviewer can reply with /approved or /changes followed by feedback. Approval of your own work is not permitted. To ask a question, reply with /ask followed by your question._');
|
|
12
12
|
if (value.outcome === 'BLOCKED' || value.outcome === 'NEEDS_CLARIFICATION')
|
|
13
|
-
sections.push(
|
|
13
|
+
sections.push(value.outcome === 'NEEDS_CLARIFICATION'
|
|
14
|
+
? '_Reply with the requested clarification. A maintainer with repository write, maintain, or admin permission can also use /changes followed by instructions to continue eligible blocked work._'
|
|
15
|
+
: '_A maintainer with repository write, maintain, or admin permission can continue eligible blocked work with /changes followed by instructions, including on an issue they authored. The authenticated UI also offers Continue with instructions. /retry is for eligible failed stages._');
|
|
16
|
+
if (value.outcome === 'FAILED')
|
|
17
|
+
sections.push('_An authorized maintainer can use /retry for an eligible failed stage, or /restart for a fresh session. These commands do not continue a blocked outcome._');
|
|
14
18
|
const session = sessionSection(value);
|
|
15
19
|
if (session !== undefined)
|
|
16
20
|
sections.push(session);
|
|
@@ -59,13 +63,7 @@ function sessionSection(value) {
|
|
|
59
63
|
const resume = value.workspacePath === undefined
|
|
60
64
|
? `codex resume ${value.sessionId}`
|
|
61
65
|
: `cd "${value.workspacePath}"\ncodex resume ${value.sessionId}`;
|
|
62
|
-
return [
|
|
63
|
-
'---',
|
|
64
|
-
'_Next steps: reply on this thread to continue, or resume this exact Wake session locally:_',
|
|
65
|
-
'```',
|
|
66
|
-
resume,
|
|
67
|
-
'```',
|
|
68
|
-
].join('\n');
|
|
66
|
+
return ['---', '_To inspect this exact Wake session locally:_', '```', resume, '```'].join('\n');
|
|
69
67
|
}
|
|
70
68
|
function outcome(value) {
|
|
71
69
|
return {
|
|
@@ -13,11 +13,13 @@ import { DeliveryEventType, selectDeliveryEvent } from '../../delivery/contracts
|
|
|
13
13
|
import { createGitHubEventData } from '../contracts/event-factory.js';
|
|
14
14
|
import { GitHubEventType, selectGitHubAdapterEvent } from '../contracts/events.js';
|
|
15
15
|
import { GitHubAdapter, UnknownGitHubIdentity } from '../contracts/vocabulary.js';
|
|
16
|
+
import { isHumanNonWakeReply } from './inbound-comment-syntax.js';
|
|
16
17
|
import { commandContext } from './inbound-context.js';
|
|
17
18
|
import { applyReviewSignal } from './inbound-review-signals.js';
|
|
18
19
|
import { applyWatchGateVerdictSignal } from './inbound-watch-gate-signals.js';
|
|
19
20
|
import { gitHubIntakeFacts, gitHubIntakeRules } from './intake-policy.js';
|
|
20
21
|
import { observePullRequest } from './pull-request-translation.js';
|
|
22
|
+
import { isWorkControlAuthorized } from './work-control-authorization.js';
|
|
21
23
|
export class InboundTranslator {
|
|
22
24
|
journal;
|
|
23
25
|
work;
|
|
@@ -248,7 +250,9 @@ export class InboundTranslator {
|
|
|
248
250
|
resourceId: resource.resourceId,
|
|
249
251
|
threadId: resource.externalKey.key,
|
|
250
252
|
messageId: externalId,
|
|
251
|
-
authorized:
|
|
253
|
+
authorized: isAuthorizedWorkControlActor(event),
|
|
254
|
+
reviewAuthorized: isAuthorizedConversationActor(event),
|
|
255
|
+
canClarify: isHumanNonWakeReply(event.event.payload.actor.kind, event.event.payload.body),
|
|
252
256
|
capabilities: this.conversationCapabilities,
|
|
253
257
|
...(event.event.payload.reviewKind !== 'issue' ||
|
|
254
258
|
event.event.payload.location === undefined
|
|
@@ -730,3 +734,11 @@ function observedCommentExternalId(event) {
|
|
|
730
734
|
function isGitHubAdapterEventType(event, eventType) {
|
|
731
735
|
return event.event.eventType === eventType;
|
|
732
736
|
}
|
|
737
|
+
function isAuthorizedWorkControlActor(event) {
|
|
738
|
+
return isWorkControlAuthorized({
|
|
739
|
+
actorKind: event.event.payload.actor.kind,
|
|
740
|
+
authorization: event.event.payload.authorization ?? {
|
|
741
|
+
source: ReviewerAuthorizationSource.None,
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ReviewerAuthorizationEvidence } from '../../../activities/index.js';
|
|
2
|
+
/** Repository control permits an issue author to clarify their own work. */
|
|
3
|
+
export declare function isWorkControlAuthorized(input: {
|
|
4
|
+
readonly actorKind: string;
|
|
5
|
+
readonly authorization: ReviewerAuthorizationEvidence;
|
|
6
|
+
}): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProviderPermission, ReviewActorKind, ReviewerAuthorizationSource, } from '../../../activities/index.js';
|
|
2
|
+
/** Repository control permits an issue author to clarify their own work. */
|
|
3
|
+
export function isWorkControlAuthorized(input) {
|
|
4
|
+
if (input.actorKind !== ReviewActorKind.Human ||
|
|
5
|
+
input.authorization.source !== ReviewerAuthorizationSource.ProviderPermission)
|
|
6
|
+
return false;
|
|
7
|
+
return (input.authorization.permission === ProviderPermission.Write ||
|
|
8
|
+
input.authorization.permission === ProviderPermission.Maintain ||
|
|
9
|
+
input.authorization.permission === ProviderPermission.Admin);
|
|
10
|
+
}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import type { CommandContext } from '@atolis-hq/eventing';
|
|
1
2
|
import { type EventProcessor } from '@atolis-hq/eventing';
|
|
3
|
+
import type { ConversationService } from '../../conversations/index.js';
|
|
4
|
+
import { ConversationEventType, workItemIdForConversation, type ConversationEventPayloads } from '../../conversations/index.js';
|
|
2
5
|
import type { OrchestrationService } from './orchestration-service.js';
|
|
6
|
+
type ConversationCommandMessage = {
|
|
7
|
+
readonly conversationId: Parameters<typeof workItemIdForConversation>[0];
|
|
8
|
+
readonly eventId: string;
|
|
9
|
+
readonly correlationId: string;
|
|
10
|
+
readonly occurredAt: string;
|
|
11
|
+
readonly entry: ConversationEventPayloads[typeof ConversationEventType.EntryRecorded];
|
|
12
|
+
};
|
|
13
|
+
interface ConversationCommandFeedback {
|
|
14
|
+
readonly conversations: ConversationService;
|
|
15
|
+
readonly publish: (event: ConversationCommandMessage, body: string, context: CommandContext) => Promise<void>;
|
|
16
|
+
}
|
|
3
17
|
/** Applies human commands only after their external message is canonical conversation history. */
|
|
4
|
-
export declare function createConversationCommandReactor(orchestration: OrchestrationService): {
|
|
18
|
+
export declare function createConversationCommandReactor(orchestration: OrchestrationService, feedback?: ConversationCommandFeedback): {
|
|
5
19
|
readonly processor: EventProcessor;
|
|
6
20
|
};
|
|
21
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { EventActorKind, EventProcessorCategory, EventProcessorReplayPolicy, cor
|
|
|
2
2
|
import { ConversationEventType, ConversationOriginKind, selectConversationEvent, workItemIdForConversation, } from '../../conversations/index.js';
|
|
3
3
|
import { conversationCommand } from './conversation-command.js';
|
|
4
4
|
/** Applies human commands only after their external message is canonical conversation history. */
|
|
5
|
-
export function createConversationCommandReactor(orchestration) {
|
|
5
|
+
export function createConversationCommandReactor(orchestration, feedback) {
|
|
6
6
|
return {
|
|
7
7
|
processor: defineEventProcessor({
|
|
8
8
|
consumer: 'reactor:orchestration.conversation-command',
|
|
@@ -34,20 +34,26 @@ export function createConversationCommandReactor(orchestration) {
|
|
|
34
34
|
actorId: entry.origin.actorId,
|
|
35
35
|
capabilities: (entry.origin.capabilities ?? []),
|
|
36
36
|
authorized: entry.origin.authorized === true,
|
|
37
|
+
// Legacy entries authorized commands only after enforcing review independence.
|
|
38
|
+
reviewAuthorized: entry.origin.reviewAuthorized ?? entry.origin.authorized === true,
|
|
37
39
|
};
|
|
38
|
-
|
|
40
|
+
const context = {
|
|
39
41
|
commandId: `${event.eventId}:conversation-command`,
|
|
40
42
|
correlationId: correlationId(event.correlationId),
|
|
41
43
|
occurredAt: event.occurredAt,
|
|
42
44
|
actor: { kind: EventActorKind.Integration, id: entry.origin.adapter },
|
|
43
|
-
}
|
|
44
|
-
if (conversationCommand(entry.body) !== null)
|
|
45
|
+
};
|
|
46
|
+
if (conversationCommand(entry.body) !== null) {
|
|
47
|
+
await applyExternalCommand(orchestration, feedback, event, input, context);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (entry.origin.canClarify === false)
|
|
45
51
|
return;
|
|
46
52
|
for (const workflow of await orchestration.listAll()) {
|
|
47
53
|
if (workflow.workItemId !== workItemId)
|
|
48
54
|
continue;
|
|
49
55
|
const resume = input.authorized
|
|
50
|
-
? orchestration.
|
|
56
|
+
? orchestration.resumeBlockedStageForReply.bind(orchestration)
|
|
51
57
|
: orchestration.resumeNeedsClarificationStage.bind(orchestration);
|
|
52
58
|
await resume(workflow.workflowInstanceId, {
|
|
53
59
|
commandId: `${event.eventId}:conversation-reply`,
|
|
@@ -60,3 +66,26 @@ export function createConversationCommandReactor(orchestration) {
|
|
|
60
66
|
}),
|
|
61
67
|
};
|
|
62
68
|
}
|
|
69
|
+
async function applyExternalCommand(orchestration, feedback, event, input, context) {
|
|
70
|
+
const entryId = context.commandId + ':feedback';
|
|
71
|
+
const canPublish = input.authorized || input.reviewAuthorized === true;
|
|
72
|
+
const prior = (await feedback?.conversations.get(event.conversationId))?.entries.find((entry) => entry.entryId === entryId);
|
|
73
|
+
// A recorded receipt fixes the result even if publication retries after the workflow changes.
|
|
74
|
+
if (prior !== undefined && feedback !== undefined) {
|
|
75
|
+
if (canPublish)
|
|
76
|
+
await feedback.publish(event, prior.body, context);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const result = await orchestration.applyConversationCommandWithFeedback(workItemIdForConversation(event.conversationId), input, context);
|
|
80
|
+
if (feedback === undefined)
|
|
81
|
+
return;
|
|
82
|
+
const body = result.applied ? 'Command applied.' : 'Command not applied: ' + result.reason;
|
|
83
|
+
await feedback.conversations.record({
|
|
84
|
+
conversationId: event.conversationId,
|
|
85
|
+
entryId,
|
|
86
|
+
body,
|
|
87
|
+
origin: { kind: ConversationOriginKind.ControlPlane, actorId: 'wake' },
|
|
88
|
+
}, context);
|
|
89
|
+
if (canPublish)
|
|
90
|
+
await feedback.publish(event, body, context);
|
|
91
|
+
}
|
|
@@ -8,15 +8,38 @@ export type SurfaceCapability = ConversationSurfaceCapability;
|
|
|
8
8
|
export type ConversationCommandSurface = {
|
|
9
9
|
readonly capabilities: readonly SurfaceCapability[];
|
|
10
10
|
};
|
|
11
|
+
export interface ConversationCommandInput {
|
|
12
|
+
readonly body: string;
|
|
13
|
+
readonly actorId: string;
|
|
14
|
+
readonly capabilities: readonly SurfaceCapability[];
|
|
15
|
+
/** Verified work-control authority. */
|
|
16
|
+
readonly authorized: boolean;
|
|
17
|
+
/** Independent-review authority must be supplied explicitly. */
|
|
18
|
+
readonly reviewAuthorized?: boolean;
|
|
19
|
+
/** Explicit continuation reenters the agent stage without a review decision. */
|
|
20
|
+
readonly continuation?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type ConversationCommandResult = {
|
|
23
|
+
readonly applied: true;
|
|
24
|
+
} | {
|
|
25
|
+
readonly applied: false;
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
};
|
|
11
28
|
export declare function conversationCommand(body: string): string | null;
|
|
12
|
-
|
|
29
|
+
interface BuiltInConversationCommandInput {
|
|
13
30
|
readonly command: string;
|
|
14
31
|
readonly capabilities: readonly SurfaceCapability[];
|
|
32
|
+
readonly reviewAuthorized: boolean;
|
|
15
33
|
readonly workflows: readonly WorkflowInstanceView[];
|
|
16
34
|
readonly context: CommandContext;
|
|
17
|
-
readonly acceptSignal: (id: WorkflowInstanceId, outcome: typeof ActivityOutcomeKind.Done | typeof ActivityOutcomeKind.Rejected) => Promise<
|
|
35
|
+
readonly acceptSignal: (id: WorkflowInstanceId, outcome: typeof ActivityOutcomeKind.Done | typeof ActivityOutcomeKind.Rejected) => Promise<boolean>;
|
|
18
36
|
readonly retry: (id: WorkflowInstanceId) => Promise<unknown>;
|
|
19
37
|
readonly restart: (id: WorkflowInstanceId) => Promise<unknown>;
|
|
20
38
|
readonly extend: (id: WorkflowInstanceId) => Promise<unknown>;
|
|
21
|
-
readonly resumeChanges: (id: WorkflowInstanceId) => Promise<
|
|
22
|
-
|
|
39
|
+
readonly resumeChanges: (id: WorkflowInstanceId) => Promise<boolean>;
|
|
40
|
+
readonly workAuthorized: boolean;
|
|
41
|
+
readonly continuation: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare function applyBuiltInConversationCommand(input: BuiltInConversationCommandInput): Promise<ConversationCommandResult>;
|
|
44
|
+
export declare function continuationCommandRejection(input: ConversationCommandInput, command: string): string | null;
|
|
45
|
+
export {};
|