@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.
- package/dist/src/activities/agent/agent-activity-definition.d.ts +2 -0
- package/dist/src/activities/agent/agent-activity-definition.js +2 -0
- package/dist/src/activities/agent/agent-activity.d.ts +3 -0
- package/dist/src/activities/agent/agent-activity.js +4 -3
- package/dist/src/activities/agent/delivery-oversight-input.d.ts +7 -0
- package/dist/src/activities/agent/delivery-oversight-input.js +8 -0
- package/dist/src/activities/index.d.ts +1 -0
- package/dist/src/activities/index.js +1 -0
- package/dist/src/bootstrap/artifact-mcp.d.ts +7 -0
- package/dist/src/bootstrap/artifact-mcp.js +29 -3
- 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/github/contracts/vocabulary.d.ts +15 -0
- package/dist/src/integrations/github/contracts/vocabulary.js +15 -0
- package/dist/src/integrations/github/infrastructure/oversight-mcp.d.ts +15 -0
- package/dist/src/integrations/github/infrastructure/oversight-mcp.js +169 -0
- package/dist/src/integrations/index.d.ts +2 -0
- package/dist/src/integrations/index.js +2 -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
- package/prompts/triage-assign.md +55 -32
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProcessorStateStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
export type OversightGh = (args: readonly string[]) => Promise<string>;
|
|
4
|
+
export declare const runOversightGh: OversightGh;
|
|
5
|
+
interface OversightToolsInput {
|
|
6
|
+
readonly repositories: readonly string[];
|
|
7
|
+
readonly invocationId: string;
|
|
8
|
+
readonly state: ProcessorStateStore;
|
|
9
|
+
readonly assertActive: () => Promise<void>;
|
|
10
|
+
readonly serialise: <T>(operation: () => Promise<T>) => Promise<T>;
|
|
11
|
+
readonly gh?: OversightGh;
|
|
12
|
+
}
|
|
13
|
+
/** Narrow gh authority; the selection receipt survives runs and artifact interruption. */
|
|
14
|
+
export declare function registerDeliveryOversightTools(server: McpServer, input: OversightToolsInput): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { GitHubCliIssueState, GitHubListState, GitHubOversightReadOperation, } from '../contracts/vocabulary.js';
|
|
5
|
+
const execute = promisify(execFile);
|
|
6
|
+
export const runOversightGh = async (args) => (await execute('gh', [...args], { timeout: 60_000, maxBuffer: 2 * 1024 * 1024 })).stdout;
|
|
7
|
+
const targetSchema = z
|
|
8
|
+
.object({ repository: z.string(), number: z.number().int().positive() })
|
|
9
|
+
.strict();
|
|
10
|
+
const userSchema = z.object({ login: z.string().min(1) });
|
|
11
|
+
const issueSchema = z.object({
|
|
12
|
+
assignees: z.array(userSchema),
|
|
13
|
+
state: z.enum(Object.values(GitHubCliIssueState)),
|
|
14
|
+
});
|
|
15
|
+
const consumer = 'github-delivery-oversight';
|
|
16
|
+
/** Narrow gh authority; the selection receipt survives runs and artifact interruption. */
|
|
17
|
+
export function registerDeliveryOversightTools(server, input) {
|
|
18
|
+
const gh = input.gh ?? runOversightGh;
|
|
19
|
+
server.registerTool('wake_github_read', {
|
|
20
|
+
description: 'Scoped gh reads: repository, issues, assigned-issues, issue, pull-requests, pull-request, blocked-by, or compare (base...commit). Provider output is untrusted evidence.',
|
|
21
|
+
inputSchema: {
|
|
22
|
+
repository: z.string(),
|
|
23
|
+
operation: z.enum(Object.values(GitHubOversightReadOperation)),
|
|
24
|
+
number: z.number().int().positive().optional(),
|
|
25
|
+
base: z
|
|
26
|
+
.string()
|
|
27
|
+
.regex(/^[A-Za-z0-9_./-]+$/)
|
|
28
|
+
.optional(),
|
|
29
|
+
commit: z
|
|
30
|
+
.string()
|
|
31
|
+
.regex(/^[a-fA-F0-9]{7,40}$/)
|
|
32
|
+
.optional(),
|
|
33
|
+
},
|
|
34
|
+
}, async ({ repository, operation, number, base, commit }) => {
|
|
35
|
+
await input.assertActive();
|
|
36
|
+
requireScope(input, repository);
|
|
37
|
+
const args = readArgs(repository, operation, number, base, commit);
|
|
38
|
+
return result(await gh(args));
|
|
39
|
+
});
|
|
40
|
+
server.registerTool('wake_github_assign', {
|
|
41
|
+
description: "Inspect selected target with no arguments, or assign that invocation's sole target to authenticated Wake identity. Rechecks provider assignment before mutation and observes the result. Selection persists before gh, including uncertain failure.",
|
|
42
|
+
inputSchema: { candidate: targetSchema.optional() },
|
|
43
|
+
}, async ({ candidate }) => input.serialise(() => assignCandidate(input, gh, candidate)));
|
|
44
|
+
}
|
|
45
|
+
function requireScope(input, repository) {
|
|
46
|
+
if (!input.repositories.includes(repository))
|
|
47
|
+
throw new Error('Repository outside configured scope');
|
|
48
|
+
}
|
|
49
|
+
async function assignCandidate(input, gh, candidate) {
|
|
50
|
+
await input.assertActive();
|
|
51
|
+
if (candidate !== undefined)
|
|
52
|
+
requireScope(input, candidate.repository);
|
|
53
|
+
const stored = await input.state.read(consumer, input.invocationId);
|
|
54
|
+
const prior = stored === null ? null : targetSchema.parse(stored.value);
|
|
55
|
+
if (candidate === undefined)
|
|
56
|
+
return result(JSON.stringify({ selected: prior }));
|
|
57
|
+
if (prior !== null &&
|
|
58
|
+
(prior.repository !== candidate.repository || prior.number !== candidate.number))
|
|
59
|
+
throw new Error('This invocation already selected another issue');
|
|
60
|
+
const login = userSchema.parse(JSON.parse(await gh(['api', 'user']))).login;
|
|
61
|
+
const inspect = async () => issueSchema.parse(JSON.parse(await gh([
|
|
62
|
+
'issue',
|
|
63
|
+
'view',
|
|
64
|
+
String(candidate.number),
|
|
65
|
+
'--repo',
|
|
66
|
+
candidate.repository,
|
|
67
|
+
'--json',
|
|
68
|
+
'assignees,state',
|
|
69
|
+
])));
|
|
70
|
+
let observed = await inspect();
|
|
71
|
+
if (observed.state !== GitHubCliIssueState.Open)
|
|
72
|
+
throw new Error('Selected issue is closed');
|
|
73
|
+
if (observed.assignees.some((user) => user.login !== login))
|
|
74
|
+
throw new Error('Selected issue already assigned to another identity');
|
|
75
|
+
if (prior === null)
|
|
76
|
+
await input.state.write({ consumer, key: input.invocationId, value: candidate });
|
|
77
|
+
if (!observed.assignees.some((user) => user.login === login)) {
|
|
78
|
+
await gh([
|
|
79
|
+
'issue',
|
|
80
|
+
'edit',
|
|
81
|
+
String(candidate.number),
|
|
82
|
+
'--repo',
|
|
83
|
+
candidate.repository,
|
|
84
|
+
'--add-assignee',
|
|
85
|
+
login,
|
|
86
|
+
]);
|
|
87
|
+
observed = await inspect();
|
|
88
|
+
}
|
|
89
|
+
if (!observed.assignees.some((user) => user.login === login))
|
|
90
|
+
throw new Error('Assignment not observed; inspect provider state before retrying');
|
|
91
|
+
return result(JSON.stringify({ selected: candidate, assignee: login, observed }));
|
|
92
|
+
}
|
|
93
|
+
function result(text) {
|
|
94
|
+
return { content: [{ type: 'text', text }] };
|
|
95
|
+
}
|
|
96
|
+
function readArgs(repository, operation, number, base, commit) {
|
|
97
|
+
if (operation === GitHubOversightReadOperation.Repository)
|
|
98
|
+
return ['api', '--method', 'GET', `repos/${repository}`];
|
|
99
|
+
if (operation === GitHubOversightReadOperation.Issues ||
|
|
100
|
+
operation === GitHubOversightReadOperation.AssignedIssues) {
|
|
101
|
+
const fields = 'number,title,body,assignees,labels,url';
|
|
102
|
+
const args = [
|
|
103
|
+
'issue',
|
|
104
|
+
'list',
|
|
105
|
+
'--repo',
|
|
106
|
+
repository,
|
|
107
|
+
'--state',
|
|
108
|
+
GitHubListState.Open,
|
|
109
|
+
'--limit',
|
|
110
|
+
'100',
|
|
111
|
+
'--json',
|
|
112
|
+
fields,
|
|
113
|
+
];
|
|
114
|
+
return operation === GitHubOversightReadOperation.AssignedIssues
|
|
115
|
+
? [...args, '--assignee', '@me']
|
|
116
|
+
: args;
|
|
117
|
+
}
|
|
118
|
+
if (operation === GitHubOversightReadOperation.PullRequests) {
|
|
119
|
+
const fields = 'number,title,state,mergedAt,baseRefName,closingIssuesReferences,url';
|
|
120
|
+
return [
|
|
121
|
+
'pr',
|
|
122
|
+
'list',
|
|
123
|
+
'--repo',
|
|
124
|
+
repository,
|
|
125
|
+
'--state',
|
|
126
|
+
GitHubListState.Open,
|
|
127
|
+
'--limit',
|
|
128
|
+
'100',
|
|
129
|
+
'--json',
|
|
130
|
+
fields,
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
if (operation === GitHubOversightReadOperation.Compare) {
|
|
134
|
+
if (base === undefined || commit === undefined)
|
|
135
|
+
throw new Error('compare requires base and commit');
|
|
136
|
+
return [
|
|
137
|
+
'api',
|
|
138
|
+
'--method',
|
|
139
|
+
'GET',
|
|
140
|
+
`repos/${repository}/compare/${encodeURIComponent(base)}...${commit}`,
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
if (number === undefined)
|
|
144
|
+
throw new Error('Read requires issue or PR number');
|
|
145
|
+
if (operation === GitHubOversightReadOperation.BlockedBy)
|
|
146
|
+
return [
|
|
147
|
+
'api',
|
|
148
|
+
'--method',
|
|
149
|
+
'GET',
|
|
150
|
+
`repos/${repository}/issues/${number}/dependencies/blocked_by`,
|
|
151
|
+
'--paginate',
|
|
152
|
+
];
|
|
153
|
+
return viewArgs(repository, operation, number);
|
|
154
|
+
}
|
|
155
|
+
function viewArgs(repository, operation, number) {
|
|
156
|
+
const pullRequest = operation === GitHubOversightReadOperation.PullRequest;
|
|
157
|
+
const fields = pullRequest
|
|
158
|
+
? 'number,title,body,state,mergedAt,mergeCommit,baseRefName,closingIssuesReferences,url'
|
|
159
|
+
: 'number,title,body,state,assignees,closedAt,closedByPullRequestsReferences,comments,url';
|
|
160
|
+
return [
|
|
161
|
+
pullRequest ? 'pr' : 'issue',
|
|
162
|
+
'view',
|
|
163
|
+
String(number),
|
|
164
|
+
'--repo',
|
|
165
|
+
repository,
|
|
166
|
+
'--json',
|
|
167
|
+
fields,
|
|
168
|
+
];
|
|
169
|
+
}
|
|
@@ -30,3 +30,5 @@ export * from './fake/durable-delivery-provider.js';
|
|
|
30
30
|
export * from './fake/external-sink.js';
|
|
31
31
|
export * from './fake/external-source.js';
|
|
32
32
|
export * from './fake/provider.js';
|
|
33
|
+
export * from './github/infrastructure/oversight-mcp.js';
|
|
34
|
+
export * from './application/conversation-command-feedback.js';
|
|
@@ -30,3 +30,5 @@ export * from './fake/durable-delivery-provider.js';
|
|
|
30
30
|
export * from './fake/external-sink.js';
|
|
31
31
|
export * from './fake/external-source.js';
|
|
32
32
|
export * from './fake/provider.js';
|
|
33
|
+
export * from './github/infrastructure/oversight-mcp.js';
|
|
34
|
+
export * from './application/conversation-command-feedback.js';
|
|
@@ -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 {};
|
|
@@ -1,46 +1,84 @@
|
|
|
1
1
|
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
2
2
|
import { ConversationBuiltInCommand, ConversationSurfaceCapability, } from '../contracts/vocabulary.js';
|
|
3
|
-
import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, selectOperatorRetryTarget, } from '../domain/operator-retry-policy.js';
|
|
3
|
+
import { isGroupBudgetExtensionEligible, isOperatorRetryEligible, selectChangesResumeTargets, selectOperatorRetryTarget, } from '../domain/operator-retry-policy.js';
|
|
4
4
|
export const BuiltInConversationCommands = Object.values(ConversationBuiltInCommand);
|
|
5
5
|
export function conversationCommand(body) {
|
|
6
6
|
const line = body.trim().split('\n', 1)[0]?.trim().toLowerCase() ?? '';
|
|
7
7
|
return /^\/[a-z][a-z0-9-]*(?:\s.*)?$/.test(line) ? line.split(/\s/, 1)[0] : null;
|
|
8
8
|
}
|
|
9
|
-
// The command matrix is
|
|
9
|
+
// The command matrix is explicit so new built-ins cannot silently inherit power.
|
|
10
10
|
// eslint-disable-next-line complexity
|
|
11
11
|
export async function applyBuiltInConversationCommand(input) {
|
|
12
|
+
const denied = (reason) => ({ applied: false, reason });
|
|
12
13
|
if (!BuiltInConversationCommands.includes(input.command))
|
|
13
|
-
return
|
|
14
|
+
return denied('Unknown command. Use /changes with instructions to continue eligible blocked work, or /retry for a failed stage.');
|
|
14
15
|
if (!input.capabilities.includes(ConversationSurfaceCapability.Review) &&
|
|
15
16
|
!input.capabilities.includes(ConversationSurfaceCapability.Operator))
|
|
16
|
-
return
|
|
17
|
-
if (input.command === ConversationBuiltInCommand.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const outcome = input.command === ConversationBuiltInCommand.Changes
|
|
21
|
-
? ActivityOutcomeKind.Rejected
|
|
22
|
-
: ActivityOutcomeKind.Done;
|
|
17
|
+
return denied('This conversation surface does not permit work-control or review commands.');
|
|
18
|
+
if (input.command === ConversationBuiltInCommand.Changes) {
|
|
19
|
+
let applied = false;
|
|
20
|
+
const continuationTargets = new Set(selectChangesResumeTargets(input.workflows));
|
|
23
21
|
for (const workflow of input.workflows) {
|
|
24
|
-
if (workflow
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await input.
|
|
22
|
+
if (isOperatorRetryEligible(workflow) || isGroupBudgetExtensionEligible(workflow))
|
|
23
|
+
continue;
|
|
24
|
+
const reviewed = !input.continuation && input.reviewAuthorized && workflow.waitingFor !== undefined
|
|
25
|
+
? await input.acceptSignal(workflow.workflowInstanceId, ActivityOutcomeKind.Rejected)
|
|
26
|
+
: false;
|
|
27
|
+
if (reviewed)
|
|
28
|
+
applied = true;
|
|
29
|
+
else if (input.workAuthorized && continuationTargets.has(workflow))
|
|
30
|
+
applied = (await input.resumeChanges(workflow.workflowInstanceId)) || applied;
|
|
28
31
|
}
|
|
29
|
-
return true;
|
|
32
|
+
return applied ? { applied: true } : denied(changesDeniedReason(input.workAuthorized));
|
|
33
|
+
}
|
|
34
|
+
if (input.command === ConversationBuiltInCommand.Approved ||
|
|
35
|
+
input.command === ConversationBuiltInCommand.Accepted) {
|
|
36
|
+
if (!input.reviewAuthorized)
|
|
37
|
+
return denied('Independent-review authority is required. An author cannot approve their own work; clarification uses /changes with instructions.');
|
|
38
|
+
let applied = false;
|
|
39
|
+
for (const workflow of input.workflows)
|
|
40
|
+
if (workflow.waitingFor !== undefined)
|
|
41
|
+
applied =
|
|
42
|
+
(await input.acceptSignal(workflow.workflowInstanceId, ActivityOutcomeKind.Done)) ||
|
|
43
|
+
applied;
|
|
44
|
+
return applied
|
|
45
|
+
? { applied: true }
|
|
46
|
+
: denied('No wait accepted this review decision. Check the configured authority and current revision.');
|
|
30
47
|
}
|
|
31
48
|
if (input.command === ConversationBuiltInCommand.Retry) {
|
|
32
49
|
const target = selectOperatorRetryTarget(input.workflows);
|
|
33
|
-
if (target
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
if (target === undefined)
|
|
51
|
+
return denied('No retry-eligible failed stage. To continue eligible blocked agent work, use /changes followed by instructions.');
|
|
52
|
+
await input.retry(target.workflowInstanceId);
|
|
53
|
+
return { applied: true };
|
|
36
54
|
}
|
|
37
55
|
const primary = input.workflows.find((workflow) => workflow.parentWorkflowInstanceId === undefined);
|
|
38
56
|
if (primary === undefined)
|
|
39
|
-
return
|
|
40
|
-
if (input.command === ConversationBuiltInCommand.Restart && isOperatorRetryEligible(primary))
|
|
57
|
+
return denied('Work item has no primary workflow.');
|
|
58
|
+
if (input.command === ConversationBuiltInCommand.Restart && isOperatorRetryEligible(primary)) {
|
|
41
59
|
await input.restart(primary.workflowInstanceId);
|
|
60
|
+
return { applied: true };
|
|
61
|
+
}
|
|
42
62
|
if (input.command === ConversationBuiltInCommand.Extend &&
|
|
43
|
-
isGroupBudgetExtensionEligible(primary))
|
|
63
|
+
isGroupBudgetExtensionEligible(primary)) {
|
|
44
64
|
await input.extend(primary.workflowInstanceId);
|
|
45
|
-
|
|
65
|
+
return { applied: true };
|
|
66
|
+
}
|
|
67
|
+
return denied('Command is inapplicable: restart requires a failed stage; extend requires an exhausted watch-group budget.');
|
|
68
|
+
}
|
|
69
|
+
function changesDeniedReason(workAuthorized) {
|
|
70
|
+
return workAuthorized
|
|
71
|
+
? 'No eligible blocked agent stage or authorized review wait. Use /retry for an eligible failed stage; watch gates require their configured authority.'
|
|
72
|
+
: 'No review wait accepted this decision. Continuing blocked work requires verified repository write, maintain, or admin permission; watch gates retain their configured authority.';
|
|
73
|
+
}
|
|
74
|
+
export function continuationCommandRejection(input, command) {
|
|
75
|
+
if (!input.continuation)
|
|
76
|
+
return null;
|
|
77
|
+
if (command !== ConversationBuiltInCommand.Changes)
|
|
78
|
+
return 'Continuation must use /changes followed by instructions.';
|
|
79
|
+
if (!input.authorized)
|
|
80
|
+
return 'Continuation requires verified work-control authority.';
|
|
81
|
+
if (input.body.trim().slice(command.length).trim() === '')
|
|
82
|
+
return 'Supply instructions after /changes to continue the blocked stage.';
|
|
83
|
+
return null;
|
|
46
84
|
}
|
|
@@ -8,7 +8,7 @@ import type { ChildWorkflowRequest, OrchestrationSignal, SignalExpectation, Supp
|
|
|
8
8
|
import { type SignalName, type WorkflowInstanceId } from '../contracts/identifiers.js';
|
|
9
9
|
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
10
10
|
import { AdvanceWorkflow } from './advance-workflow.js';
|
|
11
|
-
import { type
|
|
11
|
+
import { type ConversationCommandInput, type ConversationCommandResult } from './conversation-command.js';
|
|
12
12
|
export declare class OrchestrationService {
|
|
13
13
|
private readonly startWorkflow;
|
|
14
14
|
private readonly acceptActivityOutcome;
|
|
@@ -38,13 +38,9 @@ export declare class OrchestrationService {
|
|
|
38
38
|
setAcceptSignalOperationCoordinator(coordinator: OperationCoordinator): void;
|
|
39
39
|
setWatchChildCancellation(cancellation: WatchChildCancellation): void;
|
|
40
40
|
requestSupplementalActivity(workflowInstanceId: WorkflowInstanceId, request: SupplementalActivityRequest, context: CommandContext): Promise<WorkflowInstanceView>;
|
|
41
|
-
applyConversationCommand(workItemId: WorkItemId, input:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
readonly capabilities: readonly SurfaceCapability[];
|
|
45
|
-
/** The adapter authenticated and authorized the actor for command control. */
|
|
46
|
-
readonly authorized: boolean;
|
|
47
|
-
}, context: CommandContext): Promise<boolean>;
|
|
41
|
+
applyConversationCommand(workItemId: WorkItemId, input: ConversationCommandInput, context: CommandContext): Promise<boolean>;
|
|
42
|
+
applyConversationCommandWithFeedback(workItemId: WorkItemId, input: ConversationCommandInput, context: CommandContext): Promise<ConversationCommandResult>;
|
|
43
|
+
private applyConfiguredConversationCommands;
|
|
48
44
|
markActivationStarted(workflowInstanceId: WorkflowInstanceId, activationId: ActivationId, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
49
45
|
validateActivationDispatch(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<boolean>;
|
|
50
46
|
block(workflowInstanceId: WorkflowInstanceId, reason: string, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
@@ -62,6 +58,7 @@ export declare class OrchestrationService {
|
|
|
62
58
|
retryBlockedFailedStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView>;
|
|
63
59
|
restartBlockedFailedStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView>;
|
|
64
60
|
resumeBlockedStageForChanges(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
61
|
+
resumeBlockedStageForReply(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
65
62
|
resumeNeedsClarificationStage(workflowInstanceId: WorkflowInstanceId, context: CommandContext): Promise<WorkflowInstanceView | null>;
|
|
66
63
|
extendBlockedGroupBudget(workflowInstanceId: WorkflowInstanceId, authority: {
|
|
67
64
|
readonly kind: string;
|