@borgee/agents-host 0.2.44 → 0.2.56
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/README.md +23 -27
- package/dist/agents-host.d.ts +26 -5
- package/dist/agents-host.js +163 -192
- package/dist/chat/chat-control-plane.d.ts +3 -0
- package/dist/chat/sdk-chat-control-plane.d.ts +4 -3
- package/dist/chat/sdk-chat-control-plane.js +3 -0
- package/dist/cli.js +1 -5
- package/dist/compatibility-gates.d.ts +4 -0
- package/dist/compatibility-gates.js +18 -1
- package/dist/context/claude-file-brief.d.ts +2 -0
- package/dist/context/claude-file-brief.js +83 -0
- package/dist/context/compaction.d.ts +20 -0
- package/dist/context/compaction.js +59 -0
- package/dist/context/injection.d.ts +39 -6
- package/dist/context/injection.js +317 -26
- package/dist/context/main-session-delegation.d.ts +1 -1
- package/dist/context/projection-strategy.d.ts +24 -0
- package/dist/context/projection-strategy.js +90 -0
- package/dist/context/prompt.d.ts +16 -1
- package/dist/context/prompt.js +456 -22
- package/dist/context/resolved-workspace.d.ts +2 -0
- package/dist/context/resolved-workspace.js +64 -0
- package/dist/context/skill-manual.d.ts +1 -0
- package/dist/context/skill-manual.js +4 -1
- package/dist/context/turn-preparation.d.ts +8 -2
- package/dist/context/turn-preparation.js +56 -14
- package/dist/gateway/localhost-gateway.js +2 -0
- package/dist/managed-daemon.js +122 -9
- package/dist/plugin-sdk.js +276 -359
- package/dist/plugin-sdk.js.map +4 -4
- package/dist/progress-to-activity.d.ts +16 -0
- package/dist/progress-to-activity.js +24 -0
- package/dist/projection-strategy-values.d.ts +4 -0
- package/dist/projection-strategy-values.js +28 -0
- package/dist/providers/acp-progress-collector.d.ts +44 -0
- package/dist/providers/acp-progress-collector.js +130 -0
- package/dist/providers/awaiting-user.d.ts +2 -3
- package/dist/providers/awaiting-user.js +5 -7
- package/dist/providers/claude/activity-metadata.d.ts +14 -0
- package/dist/providers/claude/activity-metadata.js +81 -0
- package/dist/providers/claude/cli-client.d.ts +1 -2
- package/dist/providers/claude/cli-client.js +190 -117
- package/dist/providers/codex/cli-client.js +3 -83
- package/dist/providers/codex/project-doc.js +12 -11
- package/dist/providers/copilot/cli-client.js +3 -83
- package/dist/providers/create-provider.d.ts +2 -0
- package/dist/providers/create-provider.js +20 -4
- package/dist/state-paths.d.ts +1 -1
- package/dist/state-paths.js +3 -3
- package/dist/task-thread-resolution.d.ts +3 -2
- package/dist/types.d.ts +130 -6
- package/package.json +2 -2
- package/skills/borgee-agent/SKILL.md +9 -1
- package/skills/borgee-agent/references/task-properties.md +5 -2
- package/dist/durable-cursor-store.d.ts +0 -5
- package/dist/durable-cursor-store.js +0 -7
package/dist/context/prompt.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_PROJECTION_STRATEGY, normalizeProjectionStrategy, } from '../projection-strategy-values.js';
|
|
1
2
|
import { AWAITING_USER_CONTROL_PREFIX } from '../providers/awaiting-user.js';
|
|
2
3
|
import { buildAttentionSummaryLines } from './attention.js';
|
|
3
4
|
import { buildCollaborationCapabilityDeclarationSummaryLines, buildMissedCollaborationDiagnosticSummaryLines, } from './collaboration-capabilities-diagnostics.js';
|
|
4
5
|
import { buildCollaborationOutcomeSummaryLines } from './collaboration-outcome.js';
|
|
5
6
|
import { MAIN_SESSION_DELEGATION_LINES } from './main-session-delegation.js';
|
|
6
|
-
import {
|
|
7
|
+
import { buildResolvedWorkspaceGuidanceLines } from './resolved-workspace.js';
|
|
8
|
+
import { buildSkillManualLines, buildSkillManualReadLine } from './skill-manual.js';
|
|
7
9
|
import { buildTaskThreadCollaborationSummaryLines } from './task-thread-collaboration.js';
|
|
8
10
|
function providerLabel(provider) {
|
|
9
11
|
if (provider === 'copilot') {
|
|
@@ -40,14 +42,36 @@ function buildLocalhostGatewayPromptLines(context) {
|
|
|
40
42
|
lines.push(context.taskAssignmentContext?.active === true
|
|
41
43
|
? 'This turn runs inside a task assignment thread.'
|
|
42
44
|
: 'This turn runs in a parent channel, not a task thread.');
|
|
45
|
+
if (context.runtimeSurface?.task.currentThread === 'parent-channel'
|
|
46
|
+
&& (context.collaborationTurnMode ?? 'ordinary') === 'ordinary') {
|
|
47
|
+
if (context.runtimeSurface.task.parentChannelTaskCollection === 'available') {
|
|
48
|
+
lines.push('Task list and task create are available in this parent channel.');
|
|
49
|
+
lines.push(`For parent-channel task operations on this turn, read the packaged borgee-agent manual at ${context.skillRuntime.skillMarkdownPath} and follow that command grammar exactly.`);
|
|
50
|
+
lines.push('For task creation and task updates in this parent channel, use the packaged borgee-agent task rail through this gateway credential file.');
|
|
51
|
+
lines.push('Do not invent a bare task or bare borgee command.');
|
|
52
|
+
}
|
|
53
|
+
if (context.runtimeSurface.task.currentTaskShorthand === 'requires-task-id') {
|
|
54
|
+
lines.push('In this parent channel, task get, task update, task history, and task property commands require an explicit task id.');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (context.runtimeSurface?.task.currentThread === 'task-assignment-thread'
|
|
58
|
+
&& (context.collaborationTurnMode ?? 'ordinary') === 'ordinary') {
|
|
59
|
+
lines.push('In this task thread, task list and task create stay on the parent channel.');
|
|
60
|
+
}
|
|
43
61
|
const collaborationLive = context.localhostGateway.collaboration?.enabled === true
|
|
44
62
|
&& (context.collaborationTurnMode ?? 'ordinary') === 'ordinary';
|
|
45
63
|
if (!collaborationLive) {
|
|
46
|
-
lines.push('
|
|
64
|
+
lines.push('Auxiliary collaboration commands (users, draft, send, mention) are not available this turn.');
|
|
47
65
|
}
|
|
48
66
|
else if (context.collaborationTurnExecutionId) {
|
|
49
67
|
lines.push(`Pass --turn-execution-id ${context.collaborationTurnExecutionId} on send, mention and draft.`);
|
|
50
68
|
}
|
|
69
|
+
if (context.runtimeSurface?.response.mainVisibleReply === 'model-visible-reply') {
|
|
70
|
+
lines.push('Keep the main visible completion in this thread.');
|
|
71
|
+
}
|
|
72
|
+
if (context.runtimeSurface?.response.auxiliaryMessageUsage === 'targeted-escalation-only') {
|
|
73
|
+
lines.push('Use auxiliary sends only for intentional targeted escalation, mention, or reply notices when the injected runtimeSurface allows them.');
|
|
74
|
+
}
|
|
51
75
|
return lines;
|
|
52
76
|
}
|
|
53
77
|
function buildTaskAssignmentPromptLines(params) {
|
|
@@ -56,6 +80,12 @@ function buildTaskAssignmentPromptLines(params) {
|
|
|
56
80
|
if (!isTaskAssignmentTurn && taskAssignmentContext?.active !== true) {
|
|
57
81
|
return [];
|
|
58
82
|
}
|
|
83
|
+
if (params.provider === 'claude'
|
|
84
|
+
&& params.forceInlineForClaude !== true
|
|
85
|
+
&& !isTaskAssignmentTurn
|
|
86
|
+
&& taskAssignmentContext?.active === true) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
59
89
|
const lines = isTaskAssignmentTurn
|
|
60
90
|
? [
|
|
61
91
|
'This message is a task assignment.',
|
|
@@ -65,19 +95,167 @@ function buildTaskAssignmentPromptLines(params) {
|
|
|
65
95
|
'This thread is continuing an existing task assignment.',
|
|
66
96
|
'Keep the main work in this thread.',
|
|
67
97
|
];
|
|
68
|
-
if (
|
|
98
|
+
if ((params.provider !== 'claude' || params.forceInlineForClaude === true) && params.promptContext?.resolvedWorkspace) {
|
|
99
|
+
lines.push(...buildResolvedWorkspacePromptLines(params.provider, params.promptContext));
|
|
100
|
+
}
|
|
101
|
+
if ((params.provider !== 'claude' || params.forceInlineForClaude === true) && taskAssignmentContext?.currentTaskId) {
|
|
69
102
|
lines.push(`Current assigned task id: ${taskAssignmentContext.currentTaskId}.`);
|
|
70
|
-
if (params.promptContext?.taskWorkspace) {
|
|
71
|
-
lines.push(`Task-scoped writable workspace root: ${params.promptContext.taskWorkspace.rootPath}.`);
|
|
72
|
-
lines.push('This writable workspace is local to agents-host for the current task thread. It does not imply that the target repository has already been checked out there.');
|
|
73
|
-
}
|
|
74
103
|
}
|
|
75
|
-
else if (taskAssignmentContext?.active === true) {
|
|
104
|
+
else if ((params.provider !== 'claude' || params.forceInlineForClaude === true) && taskAssignmentContext?.active === true) {
|
|
76
105
|
lines.push('No current task id is persisted in the injected thread context for this task thread.');
|
|
77
106
|
}
|
|
78
|
-
|
|
107
|
+
if (params.provider !== 'claude' || params.forceInlineForClaude === true) {
|
|
108
|
+
lines.push('Return your normal final response in this thread, and do not move the main work back to the parent channel.');
|
|
109
|
+
}
|
|
79
110
|
return lines;
|
|
80
111
|
}
|
|
112
|
+
function buildResolvedWorkspacePromptLines(provider, context) {
|
|
113
|
+
return buildResolvedWorkspaceGuidanceLines(context, provider);
|
|
114
|
+
}
|
|
115
|
+
function buildClaudeOrdinaryGatewayTaskLines(context) {
|
|
116
|
+
if (!context?.skillRuntime || !context.localhostGateway || !context.gatewayCredentialPath) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
if ((context.collaborationTurnMode ?? 'ordinary') !== 'ordinary') {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
if (context.runtimeSurface?.task.currentThread !== 'parent-channel') {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
if (context.runtimeSurface.task.parentChannelTaskCollection !== 'available') {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const lines = [
|
|
129
|
+
`Gateway credential file for this turn: ${context.gatewayCredentialPath}`,
|
|
130
|
+
'This turn runs in a parent channel, not a task thread.',
|
|
131
|
+
'Task list and task create are available in this parent channel.',
|
|
132
|
+
`For parent-channel task operations on this turn, read the packaged borgee-agent manual at ${context.skillRuntime.skillMarkdownPath} and follow that command grammar exactly.`,
|
|
133
|
+
'For task creation and task updates in this parent channel, use the packaged borgee-agent task rail through this gateway credential file.',
|
|
134
|
+
'Do not invent a bare task or bare borgee command.',
|
|
135
|
+
];
|
|
136
|
+
if (context.runtimeSurface.task.currentTaskShorthand === 'requires-task-id') {
|
|
137
|
+
lines.push('In this parent channel, task get, task update, task history, and task property commands require an explicit task id.');
|
|
138
|
+
}
|
|
139
|
+
return lines;
|
|
140
|
+
}
|
|
141
|
+
function buildClaudeProjectedBriefSessionLines(context) {
|
|
142
|
+
if (!context?.claudeProjectedBriefPath) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
const lines = [
|
|
146
|
+
`Read the stable Borgee runtime brief for this session at ${context.claudeProjectedBriefPath} before you act on this channel; it is authoritative for the stable platform rules on this channel.`,
|
|
147
|
+
];
|
|
148
|
+
if (context.skillRuntime) {
|
|
149
|
+
lines.push(`For command grammar and CLI inventory, read the packaged borgee-agent manual at ${context.skillRuntime.skillMarkdownPath}.`);
|
|
150
|
+
}
|
|
151
|
+
lines.push(...buildClaudeOrdinarySessionControlLines());
|
|
152
|
+
return lines;
|
|
153
|
+
}
|
|
154
|
+
function buildClaudeProjectedBriefTurnDeltaLines(context) {
|
|
155
|
+
if (!context?.localhostGateway || !context.gatewayCredentialPath) {
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
const lines = [];
|
|
159
|
+
if ((context.collaborationTurnMode ?? 'ordinary') !== 'ordinary') {
|
|
160
|
+
return [`Gateway credential file for this turn: ${context.gatewayCredentialPath}`];
|
|
161
|
+
}
|
|
162
|
+
if (context.runtimeSurface?.task.currentThread === 'parent-channel') {
|
|
163
|
+
const taskLines = buildClaudeOrdinaryGatewayTaskLines(context);
|
|
164
|
+
if (taskLines.length > 0) {
|
|
165
|
+
lines.push(...taskLines);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
lines.push(`Gateway credential file for this turn: ${context.gatewayCredentialPath}`, 'This turn runs in a parent channel, not a task thread.');
|
|
169
|
+
if (context.runtimeSurface.task.parentChannelTaskCollection === 'available') {
|
|
170
|
+
lines.push('Task list and task create are available in this parent channel.');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (context.runtimeSurface?.task.currentThread === 'task-assignment-thread') {
|
|
175
|
+
lines.push(`Gateway credential file for this turn: ${context.gatewayCredentialPath}`, 'This turn runs inside a task assignment thread.', 'In this task thread, task list and task create stay on the parent channel.');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
lines.push(`Gateway credential file for this turn: ${context.gatewayCredentialPath}`);
|
|
179
|
+
}
|
|
180
|
+
const collaborationLive = context.localhostGateway.collaboration?.enabled === true
|
|
181
|
+
&& (context.collaborationTurnMode ?? 'ordinary') === 'ordinary';
|
|
182
|
+
if (!collaborationLive) {
|
|
183
|
+
lines.push('Auxiliary collaboration commands (users, draft, send, mention) are not available this turn.');
|
|
184
|
+
}
|
|
185
|
+
else if (context.collaborationTurnExecutionId) {
|
|
186
|
+
lines.push(`Pass --turn-execution-id ${context.collaborationTurnExecutionId} on send, mention and draft.`);
|
|
187
|
+
}
|
|
188
|
+
if (context.runtimeSurface?.response.mainVisibleReply === 'model-visible-reply') {
|
|
189
|
+
lines.push('Keep the main visible completion in this thread.');
|
|
190
|
+
}
|
|
191
|
+
if (context.runtimeSurface?.response.auxiliaryMessageUsage === 'targeted-escalation-only') {
|
|
192
|
+
lines.push('Use auxiliary sends only for intentional targeted escalation, mention, or reply notices when the injected runtimeSurface allows them.');
|
|
193
|
+
}
|
|
194
|
+
return lines;
|
|
195
|
+
}
|
|
196
|
+
function buildClaudeProjectedBriefTurnPrompt(params) {
|
|
197
|
+
if (isClaudeZeroTurnFallbackRequired(params)) {
|
|
198
|
+
return buildClaudeZeroTurnPrompt(params);
|
|
199
|
+
}
|
|
200
|
+
if (!params.promptContext?.claudeProjectedBriefPath) {
|
|
201
|
+
return [
|
|
202
|
+
...buildClaudeTurnControlPromptLines(params.promptContext),
|
|
203
|
+
...buildPromptBodyLines({
|
|
204
|
+
provider: 'claude',
|
|
205
|
+
channelId: params.channelId,
|
|
206
|
+
incomingAuthorId: params.incomingAuthorId,
|
|
207
|
+
incomingContent: params.incomingContent,
|
|
208
|
+
incomingEventKind: params.incomingEventKind,
|
|
209
|
+
incomingMessageType: params.incomingMessageType,
|
|
210
|
+
promptContext: params.promptContext,
|
|
211
|
+
}),
|
|
212
|
+
].join('\n');
|
|
213
|
+
}
|
|
214
|
+
const deltaLines = buildClaudeProjectedBriefTurnDeltaLines(params.promptContext);
|
|
215
|
+
return [
|
|
216
|
+
...buildClaudeTurnControlPromptLines(params.promptContext),
|
|
217
|
+
`Channel: ${params.channelId}`,
|
|
218
|
+
...buildInboundMetadataLines({
|
|
219
|
+
provider: 'claude',
|
|
220
|
+
incomingEventKind: params.incomingEventKind,
|
|
221
|
+
incomingMessageType: params.incomingMessageType,
|
|
222
|
+
promptContext: params.promptContext,
|
|
223
|
+
}),
|
|
224
|
+
...(() => {
|
|
225
|
+
const lines = buildCollaborationOutcomeSummaryLines(params.promptContext?.collaborationOutcome);
|
|
226
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
227
|
+
})(),
|
|
228
|
+
...(() => {
|
|
229
|
+
const lines = buildAttentionSummaryLines(params.promptContext?.attentionSnapshot);
|
|
230
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
231
|
+
})(),
|
|
232
|
+
...(() => {
|
|
233
|
+
const lines = buildCollaborationCapabilityDeclarationSummaryLines(params.promptContext?.collaborationCapabilities);
|
|
234
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
235
|
+
})(),
|
|
236
|
+
...(() => {
|
|
237
|
+
const lines = buildMissedCollaborationDiagnosticSummaryLines(params.promptContext?.missedCollaborationDiagnostic);
|
|
238
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
239
|
+
})(),
|
|
240
|
+
...(deltaLines.length > 0 ? ['', ...deltaLines] : []),
|
|
241
|
+
'',
|
|
242
|
+
`New message from ${params.incomingAuthorId}:`,
|
|
243
|
+
params.incomingContent,
|
|
244
|
+
].join('\n');
|
|
245
|
+
}
|
|
246
|
+
function buildOrdinaryCopilotWorkspacePromptLines(params) {
|
|
247
|
+
if (params.provider !== 'copilot') {
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
if (!params.promptContext?.resolvedWorkspace) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
if (params.incomingMessageType?.trim() === 'task_assignment'
|
|
254
|
+
|| params.promptContext.taskAssignmentContext?.active === true) {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
return buildResolvedWorkspacePromptLines(params.provider, params.promptContext);
|
|
258
|
+
}
|
|
81
259
|
function buildInboundMetadataLines(params) {
|
|
82
260
|
return [
|
|
83
261
|
`Incoming transport event kind: ${params.incomingEventKind?.trim() || 'message'}`,
|
|
@@ -86,7 +264,16 @@ function buildInboundMetadataLines(params) {
|
|
|
86
264
|
const lines = buildTaskThreadCollaborationSummaryLines(params.promptContext?.taskThreadCollaborationContract);
|
|
87
265
|
return lines.length > 0 ? ['', ...lines] : [];
|
|
88
266
|
})(),
|
|
89
|
-
...
|
|
267
|
+
...(() => {
|
|
268
|
+
const lines = buildOrdinaryCopilotWorkspacePromptLines(params);
|
|
269
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
270
|
+
})(),
|
|
271
|
+
...buildTaskAssignmentPromptLines({
|
|
272
|
+
provider: params.provider,
|
|
273
|
+
incomingMessageType: params.incomingMessageType,
|
|
274
|
+
promptContext: params.promptContext,
|
|
275
|
+
forceInlineForClaude: params.forceClaudeTaskAssignmentInline,
|
|
276
|
+
}),
|
|
90
277
|
];
|
|
91
278
|
}
|
|
92
279
|
function describeIdentity(identity) {
|
|
@@ -97,7 +284,7 @@ function describeIdentity(identity) {
|
|
|
97
284
|
const label = name && name.length > 0 ? `${name} (${identity.id})` : identity.id;
|
|
98
285
|
return `${label}, kind=${identity.kind}`;
|
|
99
286
|
}
|
|
100
|
-
function
|
|
287
|
+
function buildTurnControlAttentionLines(context) {
|
|
101
288
|
const taskThreadAttentionAvailable = context?.taskAssignmentContext?.active === true
|
|
102
289
|
&& typeof context.taskAssignmentContext.currentTaskId === 'string'
|
|
103
290
|
&& context.taskAssignmentContext.currentTaskId.trim().length > 0;
|
|
@@ -123,6 +310,10 @@ function buildTurnControlPromptLines(context) {
|
|
|
123
310
|
`For an attention-only reply, keep a non-empty visible body and append: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"attention-only","attentionUpdate":"follow-channel"}`,
|
|
124
311
|
]
|
|
125
312
|
: [];
|
|
313
|
+
return { attentionLines, attentionOnlyLine };
|
|
314
|
+
}
|
|
315
|
+
function buildTurnControlPromptLines(context) {
|
|
316
|
+
const { attentionLines, attentionOnlyLine } = buildTurnControlAttentionLines(context);
|
|
126
317
|
if (!context) {
|
|
127
318
|
return [
|
|
128
319
|
`Only when you need host-local turn control, append exactly one final non-empty line starting with ${AWAITING_USER_CONTROL_PREFIX}.`,
|
|
@@ -195,14 +386,69 @@ function buildTurnControlPromptLines(context) {
|
|
|
195
386
|
'Do not emit multiple control lines, and do not use a control footer for ordinary answers.',
|
|
196
387
|
];
|
|
197
388
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
389
|
+
function buildClaudeTurnControlPromptLines(context) {
|
|
390
|
+
const { attentionLines, attentionOnlyLine } = buildTurnControlAttentionLines(context);
|
|
391
|
+
if (context?.collaborationTurnMode === 'protocol-managed' && context.protocol) {
|
|
392
|
+
const selfIdentity = describeIdentity(context.grounding?.self);
|
|
393
|
+
const incomingIdentity = describeIdentity(context.grounding?.incomingAuthor);
|
|
394
|
+
const peerIdentity = describeIdentity(context.grounding?.peer);
|
|
395
|
+
return [
|
|
396
|
+
`Protocol-managed collaboration is already active for this turn. Your host-managed role is ${context.protocol.role}, and your target peer is ${context.protocol.targetPeerId}.`,
|
|
397
|
+
...(selfIdentity ? [`Your self identity for this turn: ${selfIdentity}.`] : []),
|
|
398
|
+
...(peerIdentity ? [`Your peer for this turn: ${peerIdentity}.`] : []),
|
|
399
|
+
...(incomingIdentity ? [`The incoming author for this turn is ${incomingIdentity}.`] : []),
|
|
400
|
+
'The host will deliver the visible protocol reply body for you; you only decide the body plus exactly one control footer.',
|
|
401
|
+
'Do not use auxiliary collaboration send commands during this turn, even if other turns can use them.',
|
|
402
|
+
'Do not attempt a localhost gateway message post during this turn.',
|
|
403
|
+
`When handing off to the named peer, use: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"continue-to-peer"}`,
|
|
404
|
+
`When finishing locally, use: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"conclude-locally"}`,
|
|
405
|
+
`If you are blocked on the human instead, use: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"awaiting-user","question":"<short question>","reason":"<short reason>"}`,
|
|
406
|
+
...(context.attentionSnapshot
|
|
407
|
+
? ['You may add one attentionUpdate field to continue-to-peer, conclude-locally, or awaiting-user when you also need an attention change for this channel.']
|
|
408
|
+
: []),
|
|
409
|
+
...attentionLines,
|
|
410
|
+
'Do not use start-protocol while host-managed collaboration is already active.',
|
|
411
|
+
];
|
|
412
|
+
}
|
|
413
|
+
if (context?.collaborationTurnMode === 'silent-kickoff' && context.kickoff) {
|
|
414
|
+
const kickoff = context.kickoff;
|
|
415
|
+
const otherParticipantId = kickoff.participantIds.find((participantId) => participantId !== kickoff.issuerId);
|
|
416
|
+
const selfIdentity = describeIdentity(context.grounding?.self);
|
|
417
|
+
const incomingIdentity = describeIdentity(context.grounding?.incomingAuthor);
|
|
418
|
+
const peerIdentity = describeIdentity(context.grounding?.peer);
|
|
419
|
+
const participantSummary = context.grounding?.participants
|
|
420
|
+
?.map((participant) => describeIdentity(participant))
|
|
421
|
+
.filter((participant) => participant != null)
|
|
422
|
+
.join('; ');
|
|
423
|
+
return [
|
|
424
|
+
`Silent protocol kickoff evaluation is active for anchor ${kickoff.anchorMessageId}. The issuer is ${kickoff.issuerId}${otherParticipantId ? ` and the other participant is ${otherParticipantId}` : ''}.`,
|
|
425
|
+
...(context.grounding?.hostRecognizedKickoffCandidate
|
|
426
|
+
? [
|
|
427
|
+
'The host has already recognized this message as a structurally valid kickoff candidate and is asking you to decide whether host-managed collaboration should start.',
|
|
428
|
+
]
|
|
429
|
+
: []),
|
|
430
|
+
...(selfIdentity ? [`Your self identity for this decision: ${selfIdentity}.`] : []),
|
|
431
|
+
...(peerIdentity ? [`Your peer candidate for this decision: ${peerIdentity}.`] : []),
|
|
432
|
+
...(incomingIdentity
|
|
433
|
+
? [`The incoming author for this decision is ${incomingIdentity}.`]
|
|
434
|
+
: []),
|
|
435
|
+
...(participantSummary ? [`Visible kickoff participants: ${participantSummary}.`] : []),
|
|
436
|
+
'This evaluation is read-only and silent: do not use auxiliary collaboration send commands, and do not draft a user-visible reply body for this turn.',
|
|
437
|
+
`If the anchor message is genuinely requesting host-managed collaboration between the named agents, use: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"start-protocol","rounds":<positive integer>}`,
|
|
438
|
+
'Do not combine start-protocol with any attentionUpdate field.',
|
|
439
|
+
'If collaboration should not start, omit the control footer entirely.',
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
return [
|
|
443
|
+
'Do not claim to have performed actions you did not actually perform.',
|
|
444
|
+
...(context?.attentionSnapshot
|
|
445
|
+
? ['You may add one attentionUpdate field to awaiting-user when you also need an attention change for this channel.']
|
|
446
|
+
: []),
|
|
447
|
+
...attentionLines,
|
|
448
|
+
...attentionOnlyLine,
|
|
449
|
+
];
|
|
450
|
+
}
|
|
451
|
+
function buildPromptHeaderLines(params) {
|
|
206
452
|
return [
|
|
207
453
|
`You are ${params.agentName}, a helpful AI teammate inside Borgee.`,
|
|
208
454
|
`Your current backend provider is ${providerLabel(params.provider)} (${params.provider}).`,
|
|
@@ -210,14 +456,34 @@ export function buildPrompt(params) {
|
|
|
210
456
|
'Be concise, helpful, and honest about uncertainty.',
|
|
211
457
|
'Do not claim to have performed actions you did not actually perform.',
|
|
212
458
|
'Keep the visible reply text concise.',
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
459
|
+
];
|
|
460
|
+
}
|
|
461
|
+
function buildProviderIdentityReminderLine(provider) {
|
|
462
|
+
return `If the user asks who you are, what powers you, or which backend/provider you use, mention that you are currently running on ${providerLabel(provider)}.`;
|
|
463
|
+
}
|
|
464
|
+
function buildSessionDelegationPromptLines(provider, context) {
|
|
465
|
+
if (provider === 'copilot') {
|
|
466
|
+
return MAIN_SESSION_DELEGATION_LINES;
|
|
467
|
+
}
|
|
468
|
+
return context?.skillRuntime ? [] : MAIN_SESSION_DELEGATION_LINES;
|
|
469
|
+
}
|
|
470
|
+
function buildClaudeOrdinarySessionControlLines() {
|
|
471
|
+
return [
|
|
472
|
+
`Only when you need host-local turn control, append exactly one final non-empty line starting with ${AWAITING_USER_CONTROL_PREFIX}.`,
|
|
473
|
+
`For ordinary blocked-on-human turns, use: ${AWAITING_USER_CONTROL_PREFIX}{"kind":"awaiting-user","question":"<short question>","reason":"<short reason>"}`,
|
|
474
|
+
'Do not emit multiple control lines.',
|
|
475
|
+
'Do not use a control footer for ordinary answers.',
|
|
476
|
+
];
|
|
477
|
+
}
|
|
478
|
+
function buildPromptBodyLines(params) {
|
|
479
|
+
return [
|
|
216
480
|
`Channel: ${params.channelId}`,
|
|
217
481
|
...buildInboundMetadataLines({
|
|
482
|
+
provider: params.provider,
|
|
218
483
|
incomingEventKind: params.incomingEventKind,
|
|
219
484
|
incomingMessageType: params.incomingMessageType,
|
|
220
485
|
promptContext: params.promptContext,
|
|
486
|
+
forceClaudeTaskAssignmentInline: params.forceClaudeTaskAssignmentInline,
|
|
221
487
|
}),
|
|
222
488
|
...(() => {
|
|
223
489
|
const lines = buildCollaborationOutcomeSummaryLines(params.promptContext?.collaborationOutcome);
|
|
@@ -240,5 +506,173 @@ export function buildPrompt(params) {
|
|
|
240
506
|
'',
|
|
241
507
|
`New message from ${params.incomingAuthorId}:`,
|
|
242
508
|
params.incomingContent,
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
function resolveProjectionStrategy(strategy) {
|
|
512
|
+
return normalizeProjectionStrategy(strategy) ?? DEFAULT_PROJECTION_STRATEGY;
|
|
513
|
+
}
|
|
514
|
+
function isClaudeZeroTurnFallbackRequired(params) {
|
|
515
|
+
return (params.incomingMessageType?.trim() === 'task_assignment'
|
|
516
|
+
|| params.promptContext?.collaborationTurnMode === 'protocol-managed'
|
|
517
|
+
|| params.promptContext?.collaborationTurnMode === 'silent-kickoff');
|
|
518
|
+
}
|
|
519
|
+
function buildClaudeLegacyTurnPrompt(params) {
|
|
520
|
+
const controlLines = params.promptContext?.collaborationTurnMode
|
|
521
|
+
&& params.promptContext.collaborationTurnMode !== 'ordinary'
|
|
522
|
+
? buildClaudeTurnControlPromptLines(params.promptContext)
|
|
523
|
+
: buildTurnControlPromptLines(params.promptContext);
|
|
524
|
+
const environmentLines = buildClaudeSessionEnvironmentLines(params.promptContext);
|
|
525
|
+
const sessionDelegationLines = params.promptContext?.skillRuntime ? [] : MAIN_SESSION_DELEGATION_LINES;
|
|
526
|
+
return [
|
|
527
|
+
...buildPromptHeaderLines({
|
|
528
|
+
agentName: params.agentName ?? 'Borgee agent',
|
|
529
|
+
provider: 'claude',
|
|
530
|
+
}),
|
|
531
|
+
...sessionDelegationLines,
|
|
532
|
+
...(environmentLines.length > 0 ? ['', ...environmentLines] : []),
|
|
533
|
+
...controlLines,
|
|
534
|
+
buildProviderIdentityReminderLine('claude'),
|
|
535
|
+
...buildPromptBodyLines({
|
|
536
|
+
provider: 'claude',
|
|
537
|
+
channelId: params.channelId,
|
|
538
|
+
incomingAuthorId: params.incomingAuthorId,
|
|
539
|
+
incomingContent: params.incomingContent,
|
|
540
|
+
incomingEventKind: params.incomingEventKind,
|
|
541
|
+
incomingMessageType: params.incomingMessageType,
|
|
542
|
+
promptContext: params.promptContext,
|
|
543
|
+
forceClaudeTaskAssignmentInline: true,
|
|
544
|
+
}),
|
|
545
|
+
].join('\n');
|
|
546
|
+
}
|
|
547
|
+
function buildClaudeZeroTurnPrompt(params) {
|
|
548
|
+
if (isClaudeZeroTurnFallbackRequired(params)) {
|
|
549
|
+
return [
|
|
550
|
+
...buildClaudeTurnControlPromptLines(params.promptContext),
|
|
551
|
+
...buildPromptBodyLines({
|
|
552
|
+
provider: 'claude',
|
|
553
|
+
channelId: params.channelId,
|
|
554
|
+
incomingAuthorId: params.incomingAuthorId,
|
|
555
|
+
incomingContent: params.incomingContent,
|
|
556
|
+
incomingEventKind: params.incomingEventKind,
|
|
557
|
+
incomingMessageType: params.incomingMessageType,
|
|
558
|
+
promptContext: params.promptContext,
|
|
559
|
+
}),
|
|
560
|
+
].join('\n');
|
|
561
|
+
}
|
|
562
|
+
const gatewayTaskLines = buildClaudeOrdinaryGatewayTaskLines(params.promptContext);
|
|
563
|
+
return [
|
|
564
|
+
'Do not claim to have performed actions you did not actually perform.',
|
|
565
|
+
...(gatewayTaskLines.length > 0 ? [...gatewayTaskLines, ''] : []),
|
|
566
|
+
`New message from ${params.incomingAuthorId}:`,
|
|
567
|
+
params.incomingContent,
|
|
568
|
+
].join('\n');
|
|
569
|
+
}
|
|
570
|
+
function buildClaudeMinimalTurnPrompt(params) {
|
|
571
|
+
if (isClaudeZeroTurnFallbackRequired(params)) {
|
|
572
|
+
return buildClaudeZeroTurnPrompt(params);
|
|
573
|
+
}
|
|
574
|
+
const gatewayTaskLines = buildClaudeOrdinaryGatewayTaskLines(params.promptContext);
|
|
575
|
+
return [
|
|
576
|
+
`You are ${params.agentName ?? 'Borgee agent'}, a helpful AI teammate inside Borgee.`,
|
|
577
|
+
'You are replying inside a shared collaboration channel.',
|
|
578
|
+
'Do not claim to have performed actions you did not actually perform.',
|
|
579
|
+
'Keep the visible reply text concise.',
|
|
580
|
+
...(gatewayTaskLines.length > 0 ? ['', ...gatewayTaskLines] : []),
|
|
581
|
+
'',
|
|
582
|
+
`New message from ${params.incomingAuthorId}:`,
|
|
583
|
+
params.incomingContent,
|
|
584
|
+
].join('\n');
|
|
585
|
+
}
|
|
586
|
+
function buildClaudeSessionEnvironmentLines(context) {
|
|
587
|
+
if (!context) {
|
|
588
|
+
return [];
|
|
589
|
+
}
|
|
590
|
+
const lines = [];
|
|
591
|
+
if (context.skillRuntime) {
|
|
592
|
+
lines.push(...(context.gatewayCredentialPath
|
|
593
|
+
? buildSkillManualLines(context.skillRuntime)
|
|
594
|
+
: [buildSkillManualReadLine(context.skillRuntime)]));
|
|
595
|
+
}
|
|
596
|
+
if (context.localhostGateway && context.gatewayCredentialPath) {
|
|
597
|
+
lines.push(`Gateway credential file for this session: ${context.gatewayCredentialPath}`);
|
|
598
|
+
}
|
|
599
|
+
lines.push(...buildResolvedWorkspaceGuidanceLines(context));
|
|
600
|
+
if (context.taskAssignmentContext?.currentTaskId) {
|
|
601
|
+
lines.push(`Current assigned task id: ${context.taskAssignmentContext.currentTaskId}.`);
|
|
602
|
+
}
|
|
603
|
+
else if (context.taskAssignmentContext?.active === true) {
|
|
604
|
+
lines.push('No current task id is persisted in the injected thread context for this task thread.');
|
|
605
|
+
}
|
|
606
|
+
if (context.taskAssignmentContext?.active === true) {
|
|
607
|
+
lines.push('This session is an active task assignment thread. Keep the main work in this thread.', 'Return your normal final response in this thread, and do not move the main work back to the parent channel.');
|
|
608
|
+
}
|
|
609
|
+
return lines;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Builds the per-turn prompt. Conversation memory is intentionally NOT
|
|
613
|
+
* assembled here: each provider's CLI client resumes a native per-channel
|
|
614
|
+
* session (Claude `--resume`, Copilot `--session-id`), so the CLI itself
|
|
615
|
+
* already has the prior turns. This only needs to carry the agent's
|
|
616
|
+
* identity/instructions plus the new incoming message.
|
|
617
|
+
*/
|
|
618
|
+
export function buildPrompt(params) {
|
|
619
|
+
return [
|
|
620
|
+
...buildPromptHeaderLines(params),
|
|
621
|
+
...buildSessionDelegationPromptLines(params.provider, params.promptContext),
|
|
622
|
+
...buildTurnControlPromptLines(params.promptContext),
|
|
623
|
+
buildProviderIdentityReminderLine(params.provider),
|
|
624
|
+
...buildPromptBodyLines(params),
|
|
625
|
+
].join('\n');
|
|
626
|
+
}
|
|
627
|
+
export function buildClaudeSessionPromptAppend(params) {
|
|
628
|
+
const promptStrategy = resolveProjectionStrategy(params.promptStrategy);
|
|
629
|
+
if (promptStrategy === 'turn-full') {
|
|
630
|
+
return undefined;
|
|
631
|
+
}
|
|
632
|
+
if (promptStrategy === 'file-brief' && params.promptContext?.claudeProjectedBriefPath) {
|
|
633
|
+
const bootstrapLines = buildClaudeProjectedBriefSessionLines(params.promptContext);
|
|
634
|
+
return [
|
|
635
|
+
...buildPromptHeaderLines({ agentName: params.agentName, provider: 'claude' }),
|
|
636
|
+
...(bootstrapLines.length > 0 ? ['', ...bootstrapLines] : []),
|
|
637
|
+
'',
|
|
638
|
+
buildProviderIdentityReminderLine('claude'),
|
|
639
|
+
].join('\n');
|
|
640
|
+
}
|
|
641
|
+
const environmentLines = buildClaudeSessionEnvironmentLines(params.promptContext);
|
|
642
|
+
const sessionDelegationLines = params.promptContext?.skillRuntime ? [] : MAIN_SESSION_DELEGATION_LINES;
|
|
643
|
+
return [
|
|
644
|
+
...buildPromptHeaderLines({ agentName: params.agentName, provider: 'claude' }),
|
|
645
|
+
...sessionDelegationLines,
|
|
646
|
+
...(environmentLines.length > 0 ? ['', ...environmentLines] : []),
|
|
647
|
+
'',
|
|
648
|
+
...buildClaudeOrdinarySessionControlLines(),
|
|
649
|
+
buildProviderIdentityReminderLine('claude'),
|
|
650
|
+
].join('\n');
|
|
651
|
+
}
|
|
652
|
+
export function buildClaudeTurnPrompt(params) {
|
|
653
|
+
const promptStrategy = resolveProjectionStrategy(params.promptStrategy);
|
|
654
|
+
if (promptStrategy === 'turn-full') {
|
|
655
|
+
return buildClaudeLegacyTurnPrompt(params);
|
|
656
|
+
}
|
|
657
|
+
if (promptStrategy === 'message-only') {
|
|
658
|
+
return buildClaudeZeroTurnPrompt(params);
|
|
659
|
+
}
|
|
660
|
+
if (promptStrategy === 'turn-thin') {
|
|
661
|
+
return buildClaudeMinimalTurnPrompt(params);
|
|
662
|
+
}
|
|
663
|
+
if (promptStrategy === 'file-brief') {
|
|
664
|
+
return buildClaudeProjectedBriefTurnPrompt(params);
|
|
665
|
+
}
|
|
666
|
+
return [
|
|
667
|
+
...buildClaudeTurnControlPromptLines(params.promptContext),
|
|
668
|
+
...buildPromptBodyLines({
|
|
669
|
+
provider: 'claude',
|
|
670
|
+
channelId: params.channelId,
|
|
671
|
+
incomingAuthorId: params.incomingAuthorId,
|
|
672
|
+
incomingContent: params.incomingContent,
|
|
673
|
+
incomingEventKind: params.incomingEventKind,
|
|
674
|
+
incomingMessageType: params.incomingMessageType,
|
|
675
|
+
promptContext: params.promptContext,
|
|
676
|
+
}),
|
|
243
677
|
].join('\n');
|
|
244
678
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function buildWorkspaceRootLine(context) {
|
|
2
|
+
const resolvedWorkspace = context.resolvedWorkspace;
|
|
3
|
+
if (!resolvedWorkspace) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (resolvedWorkspace.authority === 'task') {
|
|
7
|
+
return `Writable task-isolated workspace root for this task thread: ${resolvedWorkspace.rootPath}.`;
|
|
8
|
+
}
|
|
9
|
+
if (context.taskAssignmentContext?.active === true) {
|
|
10
|
+
return `Writable workspace root inherited from this task thread's channel: ${resolvedWorkspace.rootPath}.`;
|
|
11
|
+
}
|
|
12
|
+
return `Writable workspace root for this channel: ${resolvedWorkspace.rootPath}.`;
|
|
13
|
+
}
|
|
14
|
+
function buildWorkspaceModeLine(context) {
|
|
15
|
+
if (context.taskAssignmentContext?.active !== true || !context.resolvedWorkspace) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (context.resolvedWorkspace.authority === 'task') {
|
|
19
|
+
return 'This task thread runs in a task-isolated workspace instead of inheriting the channel workspace.';
|
|
20
|
+
}
|
|
21
|
+
return 'This task thread inherits the channel workspace rather than using a task-isolated workspace.';
|
|
22
|
+
}
|
|
23
|
+
function buildWorkspaceLocalityLine(context) {
|
|
24
|
+
if (!context.resolvedWorkspace) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (context.resolvedWorkspace.authority === 'task') {
|
|
28
|
+
return 'This writable workspace is local to agents-host for this task thread. It does not imply that the target repository has already been checked out there.';
|
|
29
|
+
}
|
|
30
|
+
if (context.taskAssignmentContext?.active === true) {
|
|
31
|
+
return 'This writable workspace is local to agents-host for this task thread because the task inherits its channel workspace. It does not imply that the target repository has already been checked out there.';
|
|
32
|
+
}
|
|
33
|
+
return 'This writable workspace is local to agents-host for this channel. It does not imply that the target repository has already been checked out there.';
|
|
34
|
+
}
|
|
35
|
+
function buildCopilotCwdLine(context) {
|
|
36
|
+
if (!context.resolvedWorkspace) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
if (context.resolvedWorkspace.authority === 'task') {
|
|
40
|
+
return 'GitHub Copilot runs this turn with that task-isolated workspace as its real cwd.';
|
|
41
|
+
}
|
|
42
|
+
if (context.taskAssignmentContext?.active === true) {
|
|
43
|
+
return 'GitHub Copilot runs this turn with that inherited channel workspace as its real cwd.';
|
|
44
|
+
}
|
|
45
|
+
return 'GitHub Copilot runs this turn with that workspace as its real cwd.';
|
|
46
|
+
}
|
|
47
|
+
export function buildResolvedWorkspaceGuidanceLines(context, provider) {
|
|
48
|
+
if (!context?.resolvedWorkspace) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const lines = [buildWorkspaceRootLine(context), buildWorkspaceModeLine(context)]
|
|
52
|
+
.filter((line) => line != null);
|
|
53
|
+
if (provider === 'copilot') {
|
|
54
|
+
const copilotCwdLine = buildCopilotCwdLine(context);
|
|
55
|
+
if (copilotCwdLine) {
|
|
56
|
+
lines.push(copilotCwdLine);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const localityLine = buildWorkspaceLocalityLine(context);
|
|
60
|
+
if (localityLine) {
|
|
61
|
+
lines.push(localityLine);
|
|
62
|
+
}
|
|
63
|
+
return lines;
|
|
64
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SkillRuntimeBootstrapMetadata } from '../types.js';
|
|
2
|
+
export declare function buildSkillManualReadLine(skillRuntime: SkillRuntimeBootstrapMetadata): string;
|
|
2
3
|
/**
|
|
3
4
|
* What every model-facing surface says about the packaged CLI: what it is, where its manual is, and
|
|
4
5
|
* that the manual has to be opened before acting. Nothing else about the CLI is stated on a host
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function buildSkillManualReadLine(skillRuntime) {
|
|
2
|
+
return `Read its manual at ${skillRuntime.skillMarkdownPath} before you act on this channel; it defines both the session-level coordination and delegation contract and the CLI invocation.`;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* What every model-facing surface says about the packaged CLI: what it is, where its manual is, and
|
|
3
6
|
* that the manual has to be opened before acting. Nothing else about the CLI is stated on a host
|
|
@@ -12,7 +15,7 @@
|
|
|
12
15
|
export function buildSkillManualLines(skillRuntime) {
|
|
13
16
|
return [
|
|
14
17
|
"A packaged local CLI reads this Borgee channel and acts on its tasks: channel history, visible participants, this channel's tasks and their properties, and short auxiliary mentions.",
|
|
15
|
-
|
|
18
|
+
buildSkillManualReadLine(skillRuntime),
|
|
16
19
|
'Every command the manual documents is already authorized on a turn whose prompt names a gateway credential file. Run them directly and do not ask the user for permission first.',
|
|
17
20
|
];
|
|
18
21
|
}
|