@atolis-hq/wake 0.4.65 → 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.
Files changed (50) hide show
  1. package/dist/src/activities/agent/agent-activity-definition.d.ts +2 -0
  2. package/dist/src/activities/agent/agent-activity-definition.js +2 -0
  3. package/dist/src/activities/agent/agent-activity.d.ts +3 -0
  4. package/dist/src/activities/agent/agent-activity.js +4 -3
  5. package/dist/src/activities/agent/delivery-oversight-input.d.ts +7 -0
  6. package/dist/src/activities/agent/delivery-oversight-input.js +8 -0
  7. package/dist/src/activities/index.d.ts +1 -0
  8. package/dist/src/activities/index.js +1 -0
  9. package/dist/src/bootstrap/artifact-mcp.d.ts +7 -0
  10. package/dist/src/bootstrap/artifact-mcp.js +29 -3
  11. package/dist/src/bootstrap/integration-runtime.js +17 -2
  12. package/dist/src/bootstrap/surface-api-work-applications.js +38 -3
  13. package/dist/src/bootstrap/version.js +1 -1
  14. package/dist/src/conversations/contracts/events.js +2 -0
  15. package/dist/src/conversations/contracts/views.d.ts +5 -1
  16. package/dist/src/integrations/application/conversation-command-feedback.d.ts +11 -0
  17. package/dist/src/integrations/application/conversation-command-feedback.js +36 -0
  18. package/dist/src/integrations/delivery/application/delivery-intent-lookup.d.ts +4 -0
  19. package/dist/src/integrations/delivery/application/delivery-intent-lookup.js +23 -0
  20. package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +4 -11
  21. package/dist/src/integrations/delivery/application/delivery-projector.js +7 -1
  22. package/dist/src/integrations/delivery/contracts/intents.d.ts +3 -1
  23. package/dist/src/integrations/delivery/contracts/intents.js +1 -1
  24. package/dist/src/integrations/delivery/contracts/views.d.ts +1 -0
  25. package/dist/src/integrations/github/application/agent-run-comment.js +7 -9
  26. package/dist/src/integrations/github/application/inbound-translator.js +13 -1
  27. package/dist/src/integrations/github/application/work-control-authorization.d.ts +6 -0
  28. package/dist/src/integrations/github/application/work-control-authorization.js +10 -0
  29. package/dist/src/integrations/github/contracts/vocabulary.d.ts +15 -0
  30. package/dist/src/integrations/github/contracts/vocabulary.js +15 -0
  31. package/dist/src/integrations/github/infrastructure/oversight-mcp.d.ts +15 -0
  32. package/dist/src/integrations/github/infrastructure/oversight-mcp.js +169 -0
  33. package/dist/src/integrations/index.d.ts +2 -0
  34. package/dist/src/integrations/index.js +2 -0
  35. package/dist/src/orchestration/application/conversation-command-reactor.d.ts +16 -1
  36. package/dist/src/orchestration/application/conversation-command-reactor.js +34 -5
  37. package/dist/src/orchestration/application/conversation-command.d.ts +27 -4
  38. package/dist/src/orchestration/application/conversation-command.js +60 -22
  39. package/dist/src/orchestration/application/orchestration-service.d.ts +5 -8
  40. package/dist/src/orchestration/application/orchestration-service.js +93 -34
  41. package/dist/src/orchestration/domain/interpreter.d.ts +1 -1
  42. package/dist/src/orchestration/domain/interpreter.js +1 -1
  43. package/dist/src/orchestration/domain/operator-retry-policy.d.ts +2 -0
  44. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -1
  45. package/dist/src/surfaces/api/contracts/work.d.ts +3 -0
  46. package/dist/src/surfaces/api/routes/commands.js +8 -2
  47. package/dist/src/surfaces/web-assets/assets/{index-9IfrHvBo.js → index-DMS1vQy3.js} +3 -3
  48. package/dist/src/surfaces/web-assets/index.html +1 -1
  49. package/package.json +1 -1
  50. package/prompts/triage-assign.md +55 -32
@@ -1,9 +1,11 @@
1
1
  import type { ActivityDefinition } from '../contracts/activity.js';
2
2
  import { BuiltInActivityName } from '../contracts/vocabulary.js';
3
3
  import { type AgentActivityOutcome } from './agent-result.js';
4
+ import { type DeliveryOversightInput } from './delivery-oversight-input.js';
4
5
  export declare const agentActivityDefinition: ActivityDefinition<typeof BuiltInActivityName.Agent, {
5
6
  prompt?: string | undefined;
6
7
  template?: string | undefined;
7
8
  model?: string | undefined;
8
9
  allowedTools?: readonly string[] | undefined;
10
+ deliveryOversight?: DeliveryOversightInput | undefined;
9
11
  }, AgentActivityOutcome>;
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { ActivityExecutionKind, BuiltInActivityName } from '../contracts/vocabulary.js';
3
3
  import { createAgentActivity } from './agent-activity.js';
4
4
  import { agentActivityOutcomeKinds, agentActivityOutcomeSchema, } from './agent-result.js';
5
+ import { deliveryOversightInputSchema, } from './delivery-oversight-input.js';
5
6
  export const agentActivityDefinition = {
6
7
  name: BuiltInActivityName.Agent,
7
8
  inputSchema: z
@@ -13,6 +14,7 @@ export const agentActivityDefinition = {
13
14
  .optional(),
14
15
  model: z.string().min(1).optional(),
15
16
  allowedTools: z.array(z.string().min(1)).optional(),
17
+ deliveryOversight: deliveryOversightInputSchema.optional(),
16
18
  })
17
19
  .refine((value) => (value.prompt === undefined) !== (value.template === undefined), {
18
20
  message: 'Agent Activity requires exactly one of prompt or template',
@@ -1,5 +1,6 @@
1
1
  import type { ActivityHandler } from '../contracts/activity.js';
2
2
  import { type AgentActivityOutcome } from './agent-result.js';
3
+ import type { DeliveryOversightInput } from './delivery-oversight-input.js';
3
4
  export interface AgentContextReader {
4
5
  forWorkItem(workItemId: string, options?: {
5
6
  readonly observedSince?: string;
@@ -39,8 +40,10 @@ export declare function createAgentActivity(templates?: AgentTemplateRenderer, c
39
40
  template?: string;
40
41
  model?: string;
41
42
  allowedTools?: readonly string[];
43
+ deliveryOversight?: DeliveryOversightInput;
42
44
  }, AgentActivityOutcome>;
43
45
  interface AgentTemplateContext extends Readonly<Record<string, unknown>> {
46
+ readonly deliveryOversightJson: string;
44
47
  readonly workItemId: string;
45
48
  readonly isStart: boolean;
46
49
  readonly isResume: boolean;
@@ -78,18 +78,19 @@ async function recordTranscript(context, write) {
78
78
  }
79
79
  async function agentRequest(invocation, templates, contextReader, context) {
80
80
  const input = invocation.input;
81
- const template = await resolveTemplate(input.template, invocation.workItemId, templates, contextReader, context.resumeSessionId !== undefined, context.resumeStartedAt);
81
+ const template = await resolveTemplate(input.template, invocation.workItemId, templates, contextReader, context.resumeSessionId !== undefined, { observedSince: context.resumeStartedAt, deliveryOversight: input.deliveryOversight });
82
82
  return requestFrom(input, context.runId ?? invocation.activationId, template, context.runnerContext, context.resumeSessionId, context.usageBaseline, context.workspace, context.mcpServers, context.mcpPrompt, context.reportRunnerTimeout);
83
83
  }
84
- async function resolveTemplate(name, workItemId, templates, contextReader, isResume, observedSince) {
84
+ async function resolveTemplate(name, workItemId, templates, contextReader, isResume, options) {
85
85
  if (name === undefined)
86
86
  return undefined;
87
- const untrustedContext = await buildUntrustedContext(workItemId, contextReader, observedSince);
87
+ const untrustedContext = await buildUntrustedContext(workItemId, contextReader, options.observedSince);
88
88
  const template = await templates?.render(name, {
89
89
  workItemId,
90
90
  isStart: !isResume,
91
91
  isResume,
92
92
  ...untrustedContext,
93
+ deliveryOversightJson: JSON.stringify(options.deliveryOversight ?? null),
93
94
  });
94
95
  if (template === undefined)
95
96
  throw new Error('Agent Activity template rendering is not configured');
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ /** Operator-supplied task context, never inferred from ticket text. */
3
+ export declare const deliveryOversightInputSchema: z.ZodObject<{
4
+ repositories: z.ZodArray<z.ZodString>;
5
+ focus: z.ZodOptional<z.ZodString>;
6
+ }, z.core.$strict>;
7
+ export type DeliveryOversightInput = z.infer<typeof deliveryOversightInputSchema>;
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ /** Operator-supplied task context, never inferred from ticket text. */
3
+ export const deliveryOversightInputSchema = z
4
+ .object({
5
+ repositories: z.array(z.string().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/)).min(1),
6
+ focus: z.string().min(1).optional(),
7
+ })
8
+ .strict();
@@ -22,3 +22,4 @@ export * from './review/authorization.js';
22
22
  export * from './review/contracts.js';
23
23
  export * from './review/signals.js';
24
24
  export * from './pr/merge-policy-denial.js';
25
+ export * from './agent/delivery-oversight-input.js';
@@ -22,3 +22,4 @@ export * from './review/authorization.js';
22
22
  export * from './review/contracts.js';
23
23
  export * from './review/signals.js';
24
24
  export * from './pr/merge-policy-denial.js';
25
+ export * from './agent/delivery-oversight-input.js';
@@ -1,6 +1,8 @@
1
+ import type { ProcessorStateStore } from '@atolis-hq/eventing';
1
2
  import type { FileArtifactMcpSessionStore } from '../artifacts/index.js';
2
3
  import { type ArtifactRevisionReference, type ArtifactService } from '../artifacts/index.js';
3
4
  import { type ExecutionDependencies } from '../execution/index.js';
5
+ import { type OversightGh } from '../integrations/index.js';
4
6
  import type { OrchestrationService } from '../orchestration/index.js';
5
7
  /** Bootstrap binds Artifact's generic policy to verified Execution and Orchestration facts. */
6
8
  export declare function createArtifactMcpProvisioner(input: {
@@ -20,8 +22,13 @@ export declare function createArtifactMcpProvisioner(input: {
20
22
  export declare function createArtifactMcpServerForSession(root: ArtifactMcpRoot, sessions: FileArtifactMcpSessionStore, path: string, token: string, options: {
21
23
  readonly now: () => string;
22
24
  readonly nextId: () => string;
25
+ readonly gh?: OversightGh;
23
26
  }): Promise<import("@modelcontextprotocol/sdk/server/mcp").McpServer>;
24
27
  interface ArtifactMcpRoot {
28
+ readonly processorState?: ProcessorStateStore;
29
+ readonly paths?: {
30
+ readonly locksRoot: string;
31
+ };
25
32
  readonly artifacts: ArtifactService;
26
33
  readonly orchestration: OrchestrationService;
27
34
  }
@@ -1,7 +1,11 @@
1
- import { EventActorKind, correlationId } from '@atolis-hq/eventing';
2
- import { randomUUID } from 'node:crypto';
1
+ import { correlationId, EventActorKind } from '@atolis-hq/eventing';
2
+ import { withFileLock } from '@atolis-hq/eventing-filesystem';
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { join } from 'node:path';
5
+ import { agentActivityDefinition, BuiltInActivityName } from '../activities/index.js';
3
6
  import { createArtifactMcpServer, } from '../artifacts/index.js';
4
7
  import { WakeMcpServerName } from '../execution/index.js';
8
+ import { registerDeliveryOversightTools } from '../integrations/index.js';
5
9
  const sessionLifetimeMs = 2 * 60 * 60 * 1000;
6
10
  /** Bootstrap binds Artifact's generic policy to verified Execution and Orchestration facts. */
7
11
  export function createArtifactMcpProvisioner(input) {
@@ -48,7 +52,7 @@ export function createArtifactMcpProvisioner(input) {
48
52
  export async function createArtifactMcpServerForSession(root, sessions, path, token, options) {
49
53
  const descriptor = await sessions.read(path, token);
50
54
  const accepted = acceptedActivation(root.orchestration, descriptor.workItemId);
51
- return createArtifactMcpServer(root.artifacts, {
55
+ const server = createArtifactMcpServer(root.artifacts, {
52
56
  ...descriptor,
53
57
  readableProducers: new Set(descriptor.readableProducers),
54
58
  nextRevisionId: options.nextId,
@@ -58,6 +62,28 @@ export async function createArtifactMcpServerForSession(root, sessions, path, to
58
62
  await sessions.read(path, token);
59
63
  },
60
64
  });
65
+ const workflow = (await root.orchestration.listAll()).find((item) => item.workItemId === descriptor.workItemId &&
66
+ item.pendingActivation?.activationId === descriptor.activationId);
67
+ const activation = workflow?.pendingActivation;
68
+ if (activation?.activity === BuiltInActivityName.Agent) {
69
+ const parsed = agentActivityDefinition.inputSchema.parse(activation.input);
70
+ if (parsed.deliveryOversight !== undefined) {
71
+ if (root.processorState === undefined || root.paths === undefined)
72
+ throw new Error('Oversight recovery storage unavailable');
73
+ const key = workflow.workflowInstanceId;
74
+ registerDeliveryOversightTools(server, {
75
+ repositories: parsed.deliveryOversight.repositories,
76
+ invocationId: key,
77
+ state: root.processorState,
78
+ ...(options.gh === undefined ? {} : { gh: options.gh }),
79
+ assertActive: async () => {
80
+ await sessions.read(path, token);
81
+ },
82
+ serialise: (operation) => withFileLock(join(root.paths.locksRoot, 'delivery-oversight', createHash('sha256').update(key).digest('hex') + '.lock'), operation, { waitMs: 5_000 }),
83
+ });
84
+ }
85
+ }
86
+ return server;
61
87
  }
62
88
  function commandContext(occurredAt, descriptor) {
63
89
  return {
@@ -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.resumeBlockedStageForChanges(workflow.workflowInstanceId, context);
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: presentConversation(conversation, root.config?.surfaces.api.conversationMessages.enabled === true),
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.65";
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
- /** Authority established by the receiving surface before the entry is recorded. */
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 { DeliveryIntentKind, DeliveryResultKind } from '../contracts/vocabulary.js';
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
- : { kind: DeliveryIntentKind.ReplyPublish, body: integrationIntent.event.payload.body },
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('_To approve this work, reply with /approved. To request changes, reply with /changes followed by your feedback. To ask a question without requesting changes, reply with /ask followed by your question._');
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('_Reply on this thread to continue. To request changes instead, reply with /changes followed by your feedback._');
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: isAuthorizedConversationActor(event),
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
+ }
@@ -63,3 +63,18 @@ export declare const GitHubBuiltInCommand: {
63
63
  readonly Extend: "/extend";
64
64
  };
65
65
  export type GitHubBuiltInCommand = ValueOf<typeof GitHubBuiltInCommand>;
66
+ export declare const GitHubCliIssueState: {
67
+ readonly Open: "OPEN";
68
+ readonly Closed: "CLOSED";
69
+ };
70
+ export declare const GitHubOversightReadOperation: {
71
+ readonly Repository: "repository";
72
+ readonly Issues: "issues";
73
+ readonly AssignedIssues: "assigned-issues";
74
+ readonly Issue: "issue";
75
+ readonly PullRequests: "pull-requests";
76
+ readonly PullRequest: "pull-request";
77
+ readonly BlockedBy: "blocked-by";
78
+ readonly Compare: "compare";
79
+ };
80
+ export type GitHubOversightReadOperation = ValueOf<typeof GitHubOversightReadOperation>;
@@ -71,3 +71,18 @@ export const GitHubBuiltInCommand = defineClosedVocabulary({
71
71
  Restart: '/restart',
72
72
  Extend: '/extend',
73
73
  });
74
+ export const GitHubCliIssueState = defineClosedVocabulary({
75
+ Open: 'OPEN',
76
+ Closed: 'CLOSED',
77
+ });
78
+ // Tool operations form a local protocol vocabulary, separate from domain/event values.
79
+ export const GitHubOversightReadOperation = {
80
+ Repository: 'repository',
81
+ Issues: 'issues',
82
+ AssignedIssues: 'assigned-issues',
83
+ Issue: 'issue',
84
+ PullRequests: 'pull-requests',
85
+ PullRequest: 'pull-request',
86
+ BlockedBy: 'blocked-by',
87
+ Compare: 'compare',
88
+ };