@borgee/agents-host 0.2.35 → 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 +28 -5
- package/dist/agents-host.js +274 -236
- 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 +6 -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 +44 -9
- package/dist/context/injection.js +360 -53
- 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 +475 -53
- package/dist/context/resolved-workspace.d.ts +2 -0
- package/dist/context/resolved-workspace.js +64 -0
- package/dist/context/skill-manual.d.ts +14 -0
- package/dist/context/skill-manual.js +21 -0
- package/dist/context/turn-preparation.d.ts +8 -2
- package/dist/context/turn-preparation.js +68 -17
- package/dist/gateway/localhost-gateway.js +18 -8
- package/dist/hosted-turn-content.d.ts +15 -0
- package/dist/hosted-turn-content.js +50 -0
- package/dist/managed-daemon.d.ts +3 -2
- package/dist/managed-daemon.js +198 -37
- 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/adapter.d.ts +3 -1
- package/dist/providers/claude/adapter.js +10 -0
- package/dist/providers/claude/cli-client.d.ts +9 -1
- package/dist/providers/claude/cli-client.js +270 -126
- package/dist/providers/codex/adapter.d.ts +3 -1
- package/dist/providers/codex/adapter.js +10 -0
- package/dist/providers/codex/cli-client.d.ts +10 -2
- package/dist/providers/codex/cli-client.js +88 -104
- package/dist/providers/codex/project-doc.js +22 -37
- package/dist/providers/copilot/adapter.d.ts +3 -1
- package/dist/providers/copilot/adapter.js +10 -0
- package/dist/providers/copilot/cli-client.d.ts +9 -1
- package/dist/providers/copilot/cli-client.js +68 -85
- package/dist/providers/create-provider.d.ts +3 -1
- package/dist/providers/create-provider.js +36 -9
- package/dist/providers/provider-adapter.d.ts +35 -0
- package/dist/providers/provider-adapter.js +44 -1
- package/dist/state-paths.d.ts +10 -2
- package/dist/state-paths.js +25 -6
- package/dist/task-thread-resolution.d.ts +3 -2
- package/dist/types.d.ts +163 -8
- package/package.json +2 -2
- package/skills/borgee-agent/SKILL.md +127 -38
- package/skills/borgee-agent/references/errors.md +38 -0
- package/skills/borgee-agent/references/task-properties.md +33 -0
- package/skills/borgee-agent/scripts/borgee-agent.mjs +553 -0
- package/skills/borgee-agent/scripts/borgee-agent.py +547 -0
- package/dist/durable-cursor-store.d.ts +0 -5
- package/dist/durable-cursor-store.js +0 -7
- package/skills/borgee-agent/borgee-agent.mjs +0 -562
- package/skills/borgee-agent/borgee-agent.py +0 -469
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReportTurnActivityInput, TurnActivityReporter } from '../plugin-sdk.js';
|
|
1
2
|
import type { ChannelSummary, ChannelHistoryEntry, ChannelMessageEvent, CreateTaskInput, DirectoryUser, MeResponseUser, PostMessageInput, PostedMessage, ReadChannelHistoryInput, Task, UpdateTaskInput } from '../types.js';
|
|
2
3
|
export interface ChatControlPlane {
|
|
3
4
|
connect(onMessage: (message: ChannelMessageEvent) => void): Promise<void>;
|
|
@@ -6,6 +7,8 @@ export interface ChatControlPlane {
|
|
|
6
7
|
editMessage(messageId: string, content: string): Promise<void>;
|
|
7
8
|
deleteMessage(messageId: string): Promise<void>;
|
|
8
9
|
startTyping(channelId: string): () => void;
|
|
10
|
+
/** Opens one turn's report on the activity rail. Fire-and-forget: nothing recovers what it sends. */
|
|
11
|
+
reportTurnActivity(input: ReportTurnActivityInput): TurnActivityReporter;
|
|
9
12
|
getMe(): Promise<MeResponseUser>;
|
|
10
13
|
listUsers(): Promise<DirectoryUser[]>;
|
|
11
14
|
listChannels(): Promise<ChannelSummary[]>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type BorgeePluginClient, type BorgeePluginOptions, type InboundMessageEvent } from '../plugin-sdk.js';
|
|
1
|
+
import { type BorgeePluginClient, type BorgeePluginOptions, type InboundMessageEvent, type ReportTurnActivityInput, type TurnActivityReporter } from '../plugin-sdk.js';
|
|
2
2
|
import type { ChannelSummary, ChannelHistoryEntry, ChannelMessageEvent, CreateTaskInput, DirectoryUser, MeResponseUser, PostMessageInput, PostedMessage, ReadChannelHistoryInput, Task, UpdateTaskInput } from '../types.js';
|
|
3
3
|
import type { ChatControlPlane } from './chat-control-plane.js';
|
|
4
|
-
type PluginClientLike = Pick<BorgeePluginClient, 'agentId' | 'close' | 'connect' | 'createTask' | 'deleteMessage' | 'editMessage' | 'getMe' | 'getTask' | 'listChannels' | 'listTasks' | 'listUsers' | 'on' | 'readHistory' | 'sendMessage' | 'startTyping' | 'updateTask' | 'setTaskProperty' | 'deleteTaskProperty'>;
|
|
4
|
+
type PluginClientLike = Pick<BorgeePluginClient, 'agentId' | 'close' | 'connect' | 'createTask' | 'deleteMessage' | 'editMessage' | 'getMe' | 'getTask' | 'listChannels' | 'listTasks' | 'listUsers' | 'on' | 'readHistory' | 'reportTurnActivity' | 'sendMessage' | 'startTyping' | 'updateTask' | 'setTaskProperty' | 'deleteTaskProperty'>;
|
|
5
5
|
type PluginClientFactory = (options: BorgeePluginOptions) => PluginClientLike;
|
|
6
|
-
type SdkChatControlPlaneOptions = Pick<BorgeePluginOptions, '
|
|
6
|
+
type SdkChatControlPlaneOptions = Pick<BorgeePluginOptions, 'pluginId'>;
|
|
7
7
|
/**
|
|
8
8
|
* Thin adapter over `@borgee/plugin-sdk` (the same BPP/`/ws/plugin` SDK used by
|
|
9
9
|
* the OpenClaw plugin) that implements the minimal `ChatControlPlane` surface
|
|
@@ -22,6 +22,7 @@ export declare class SdkChatControlPlane implements ChatControlPlane {
|
|
|
22
22
|
editMessage(messageId: string, content: string): Promise<void>;
|
|
23
23
|
deleteMessage(messageId: string): Promise<void>;
|
|
24
24
|
startTyping(channelId: string): () => void;
|
|
25
|
+
reportTurnActivity(input: ReportTurnActivityInput): TurnActivityReporter;
|
|
25
26
|
getMe(): Promise<MeResponseUser>;
|
|
26
27
|
listUsers(): Promise<DirectoryUser[]>;
|
|
27
28
|
readChannelHistory(input: ReadChannelHistoryInput): Promise<ChannelHistoryEntry[]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createBorgeePlugin, } from '../plugin-sdk.js';
|
|
2
|
+
import { normalizeHostedMessageAttachment } from '../hosted-turn-content.js';
|
|
2
3
|
/**
|
|
3
4
|
* Thin adapter over `@borgee/plugin-sdk` (the same BPP/`/ws/plugin` SDK used by
|
|
4
5
|
* the OpenClaw plugin) that implements the minimal `ChatControlPlane` surface
|
|
@@ -64,6 +65,9 @@ export class SdkChatControlPlane {
|
|
|
64
65
|
startTyping(channelId) {
|
|
65
66
|
return this.client.startTyping(channelId);
|
|
66
67
|
}
|
|
68
|
+
reportTurnActivity(input) {
|
|
69
|
+
return this.client.reportTurnActivity(input);
|
|
70
|
+
}
|
|
67
71
|
async getMe() {
|
|
68
72
|
if (this.me) {
|
|
69
73
|
return this.me;
|
|
@@ -97,6 +101,7 @@ export class SdkChatControlPlane {
|
|
|
97
101
|
authorId: message.authorId,
|
|
98
102
|
body: message.body,
|
|
99
103
|
contentType: message.contentType,
|
|
104
|
+
attachments: message.attachments?.map(normalizeHostedMessageAttachment),
|
|
100
105
|
type: message.type,
|
|
101
106
|
replyToId: message.replyToId,
|
|
102
107
|
createdAt: message.createdAt,
|
|
@@ -142,6 +147,7 @@ export function mapInboundToChannelMessage(event) {
|
|
|
142
147
|
content: event.message?.body,
|
|
143
148
|
body: event.message?.body,
|
|
144
149
|
content_type: event.message?.contentType,
|
|
150
|
+
attachments: event.message?.attachments?.map(normalizeHostedMessageAttachment),
|
|
145
151
|
created_at: event.createdAt,
|
|
146
152
|
};
|
|
147
153
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { realpathSync } from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { assertNoUpdateArgs, CliUsageError, parseApplyManagedArgs, parseDaemonArgs, parseDescribeArgs, parseDescribeManagedArgs, parseCleanupManagedArgs, parseGenerateConfigArgs, parseLogArgs, parseManagedStartArgs, parsePrintLayoutArgs, parseStartArgs, parseValidateArgs, USAGE, } from './cli-args.js';
|
|
6
6
|
import { resolveAgentsHostDebugMode } from './debug.js';
|
|
@@ -15,7 +15,6 @@ function formatErrorMessage(error) {
|
|
|
15
15
|
}
|
|
16
16
|
return String(error);
|
|
17
17
|
}
|
|
18
|
-
const TASK_WORKSPACE_ROOT_DIR_ENV = 'AGENTS_HOST_INTERNAL_TASK_WORKSPACE_ROOT_DIR';
|
|
19
18
|
export async function dispatchCli(argv, deps = {}) {
|
|
20
19
|
const [command, ...rest] = argv;
|
|
21
20
|
const env = deps.env ?? process.env;
|
|
@@ -31,7 +30,6 @@ export async function dispatchCli(argv, deps = {}) {
|
|
|
31
30
|
const applyManagedSpecImpl = deps.applyManagedSpec ?? applyManagedSpec;
|
|
32
31
|
const startManagedDaemonImpl = deps.startManagedDaemon ??
|
|
33
32
|
(async (rootPath, debug) => {
|
|
34
|
-
env[TASK_WORKSPACE_ROOT_DIR_ENV] = rootPath;
|
|
35
33
|
const daemon = new ManagedAgentsHostDaemon(rootPath, debug, {
|
|
36
34
|
logPath: env.AGENTS_HOST_MANAGED_DAEMON_LOG_PATH,
|
|
37
35
|
});
|
|
@@ -63,7 +61,6 @@ export async function dispatchCli(argv, deps = {}) {
|
|
|
63
61
|
await runMainImpl({ debug });
|
|
64
62
|
return;
|
|
65
63
|
}
|
|
66
|
-
env[TASK_WORKSPACE_ROOT_DIR_ENV] = dirname(resolve(parsed.configPath));
|
|
67
64
|
await runMainImpl({ configPath: parsed.configPath, debug });
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
@@ -167,7 +164,6 @@ export async function dispatchCli(argv, deps = {}) {
|
|
|
167
164
|
}
|
|
168
165
|
if (command === 'daemon') {
|
|
169
166
|
const parsed = parseDaemonArgs(rest);
|
|
170
|
-
env[TASK_WORKSPACE_ROOT_DIR_ENV] = parsed.rootPath;
|
|
171
167
|
await startManagedDaemonImpl(parsed.rootPath, parsed.debug);
|
|
172
168
|
return;
|
|
173
169
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProjectionStrategy } from './types.js';
|
|
1
2
|
export declare const CLAUDE_PROVIDER_V2_COMPATIBILITY_GATE = "claude-provider-v2";
|
|
2
3
|
export declare const COPILOT_PROVIDER_V2_COMPATIBILITY_GATE = "copilot-provider-v2";
|
|
3
4
|
export declare const CODEX_PROVIDER_COMPATIBILITY_GATE = "codex-provider";
|
|
@@ -18,6 +19,7 @@ export declare const COMPATIBILITY_GATES_ENV = "AGENTS_HOST_INTERNAL_COMPATIBILI
|
|
|
18
19
|
export declare const INTERNAL_DISABLED_COMPATIBILITY_GATES_ENV = "AGENTS_HOST_INTERNAL_DISABLED_COMPATIBILITY_GATES";
|
|
19
20
|
export declare const INTERNAL_POLICY_MODE_ENV = "AGENTS_HOST_INTERNAL_POLICY_MODE";
|
|
20
21
|
export declare const INTERNAL_PROVIDER_IMPLEMENTATIONS_ENV = "AGENTS_HOST_INTERNAL_PROVIDER_IMPLEMENTATIONS";
|
|
22
|
+
export declare const INTERNAL_CLAUDE_PROMPT_STRATEGY_ENV = "AGENTS_HOST_INTERNAL_CLAUDE_PROMPT_STRATEGY";
|
|
21
23
|
export declare const MANAGED_RUNTIME_SETTINGS_SCHEMA_VERSION = 1;
|
|
22
24
|
export type InternalPolicyMode = 'audit-only' | 'enforce';
|
|
23
25
|
export type InternalProviderImplementationPath = 'v1' | 'v2';
|
|
@@ -28,8 +30,10 @@ export interface ManagedRuntimeSettingsSnapshot {
|
|
|
28
30
|
compatibilityGates: string[];
|
|
29
31
|
providerImplementationOverrides: string[];
|
|
30
32
|
internalPolicyMode: InternalPolicyMode;
|
|
33
|
+
projectionStrategy: ProjectionStrategy;
|
|
31
34
|
}
|
|
32
35
|
export declare const DEFAULT_INTERNAL_COMPATIBILITY_GATES: readonly string[];
|
|
36
|
+
export declare function resolveInternalProjectionStrategy(env?: NodeJS.ProcessEnv): ProjectionStrategy;
|
|
33
37
|
export declare function parseCompatibilityGates(rawValue: string | undefined): ReadonlySet<string>;
|
|
34
38
|
export declare function resolveInternalCompatibilityGates(env?: NodeJS.ProcessEnv): ReadonlySet<string>;
|
|
35
39
|
export declare function resolveDisabledDefaultCompatibilityGates(compatibilityGates: Iterable<string>): string[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { DEFAULT_PROJECTION_STRATEGY, normalizeProjectionStrategy, } from './projection-strategy-values.js';
|
|
2
3
|
export const CLAUDE_PROVIDER_V2_COMPATIBILITY_GATE = 'claude-provider-v2';
|
|
3
4
|
export const COPILOT_PROVIDER_V2_COMPATIBILITY_GATE = 'copilot-provider-v2';
|
|
4
5
|
export const CODEX_PROVIDER_COMPATIBILITY_GATE = 'codex-provider';
|
|
@@ -19,6 +20,7 @@ export const COMPATIBILITY_GATES_ENV = 'AGENTS_HOST_INTERNAL_COMPATIBILITY_GATES
|
|
|
19
20
|
export const INTERNAL_DISABLED_COMPATIBILITY_GATES_ENV = 'AGENTS_HOST_INTERNAL_DISABLED_COMPATIBILITY_GATES';
|
|
20
21
|
export const INTERNAL_POLICY_MODE_ENV = 'AGENTS_HOST_INTERNAL_POLICY_MODE';
|
|
21
22
|
export const INTERNAL_PROVIDER_IMPLEMENTATIONS_ENV = 'AGENTS_HOST_INTERNAL_PROVIDER_IMPLEMENTATIONS';
|
|
23
|
+
export const INTERNAL_CLAUDE_PROMPT_STRATEGY_ENV = 'AGENTS_HOST_INTERNAL_CLAUDE_PROMPT_STRATEGY';
|
|
22
24
|
export const MANAGED_RUNTIME_SETTINGS_SCHEMA_VERSION = 1;
|
|
23
25
|
const VALID_PROVIDER_IMPLEMENTATION_ENTRIES = '"claude:v1", "claude:v2", "copilot:v1", or "copilot:v2"';
|
|
24
26
|
export const DEFAULT_INTERNAL_COMPATIBILITY_GATES = Object.freeze([
|
|
@@ -44,6 +46,17 @@ function sortUniqueStrings(values) {
|
|
|
44
46
|
return [...new Set([...values].map((value) => value.trim()).filter((value) => value.length > 0))]
|
|
45
47
|
.sort((left, right) => left.localeCompare(right));
|
|
46
48
|
}
|
|
49
|
+
export function resolveInternalProjectionStrategy(env = process.env) {
|
|
50
|
+
const rawValue = env[INTERNAL_CLAUDE_PROMPT_STRATEGY_ENV]?.trim();
|
|
51
|
+
if (!rawValue || rawValue.length === 0) {
|
|
52
|
+
return DEFAULT_PROJECTION_STRATEGY;
|
|
53
|
+
}
|
|
54
|
+
const strategy = normalizeProjectionStrategy(rawValue);
|
|
55
|
+
if (strategy) {
|
|
56
|
+
return strategy;
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Invalid ${INTERNAL_CLAUDE_PROMPT_STRATEGY_ENV}: expected "session-brief", "turn-full", "message-only", or "turn-thin"`);
|
|
59
|
+
}
|
|
47
60
|
function isInternalProviderImplementationPath(value) {
|
|
48
61
|
return value === 'v1' || value === 'v2';
|
|
49
62
|
}
|
|
@@ -160,10 +173,14 @@ export function resolveManagedRuntimeSettingsSnapshot(env = process.env) {
|
|
|
160
173
|
compatibilityGates,
|
|
161
174
|
providerImplementationOverrides: resolveManagedRuntimeProviderImplementationOverrides(env, compatibilityGates),
|
|
162
175
|
internalPolicyMode: resolveInternalPolicyMode(compatibilityGates.includes(POLICY_AUDIT_ENFORCEMENT_COMPATIBILITY_GATE), env),
|
|
176
|
+
projectionStrategy: resolveInternalProjectionStrategy(env),
|
|
163
177
|
};
|
|
164
178
|
}
|
|
165
179
|
export function serializeManagedRuntimeSettingsSnapshot(snapshot) {
|
|
166
|
-
return JSON.stringify(
|
|
180
|
+
return JSON.stringify({
|
|
181
|
+
...snapshot,
|
|
182
|
+
claudePromptStrategy: snapshot.projectionStrategy,
|
|
183
|
+
});
|
|
167
184
|
}
|
|
168
185
|
export function createManagedRuntimeSettingsFingerprint(snapshot) {
|
|
169
186
|
return createHash('sha256')
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { buildCollaborationCapabilityDeclarationSummaryLines, } from './collaboration-capabilities-diagnostics.js';
|
|
2
|
+
import { MAIN_SESSION_DELEGATION_LINES } from './main-session-delegation.js';
|
|
3
|
+
import { buildResolvedWorkspaceGuidanceLines } from './resolved-workspace.js';
|
|
4
|
+
import { buildSkillManualLines, buildSkillManualReadLine } from './skill-manual.js';
|
|
5
|
+
function buildStableSkillLines(context) {
|
|
6
|
+
if (!context?.skillRuntime) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
return context.gatewayCredentialPath
|
|
10
|
+
? buildSkillManualLines(context.skillRuntime)
|
|
11
|
+
: [buildSkillManualReadLine(context.skillRuntime)];
|
|
12
|
+
}
|
|
13
|
+
function buildStableGatewayLines(context) {
|
|
14
|
+
if (!context?.localhostGateway || !context.gatewayCredentialPath) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const lines = [`Gateway credential file: ${context.gatewayCredentialPath}`];
|
|
18
|
+
if (context.runtimeSurface?.task.currentThread === 'parent-channel') {
|
|
19
|
+
lines.push('This channel is a parent channel, not a task thread.', 'For parent-channel task operations, use the packaged borgee-agent task rail through this gateway credential file.', 'Do not invent a bare task or bare borgee command.');
|
|
20
|
+
if (context.runtimeSurface.task.currentTaskShorthand === 'requires-task-id') {
|
|
21
|
+
lines.push('In this parent channel, task get, task update, task history, and task property commands require an explicit task id.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (context.runtimeSurface?.task.currentThread === 'task-assignment-thread') {
|
|
25
|
+
lines.push('This channel is an active task thread.', 'Task list and task create stay on the parent channel.', '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.');
|
|
26
|
+
if (context.taskAssignmentContext?.currentTaskId) {
|
|
27
|
+
lines.push(`Current assigned task id: ${context.taskAssignmentContext.currentTaskId}.`);
|
|
28
|
+
}
|
|
29
|
+
else if (context.taskAssignmentContext?.active === true) {
|
|
30
|
+
lines.push('No current task id is persisted in the injected thread context for this task thread.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
35
|
+
function buildStableTaskThreadLines(context) {
|
|
36
|
+
if (context?.taskAssignmentContext?.active !== true) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const lines = [
|
|
40
|
+
'This session is an active task assignment thread.',
|
|
41
|
+
'Keep the main work in this thread.',
|
|
42
|
+
'Return your normal final response in this thread, and do not move the main work back to the parent channel.',
|
|
43
|
+
];
|
|
44
|
+
if (context.taskAssignmentContext.currentTaskId) {
|
|
45
|
+
lines.push(`Current assigned task id: ${context.taskAssignmentContext.currentTaskId}.`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
lines.push('No current task id is persisted in the injected thread context for this task thread.');
|
|
49
|
+
}
|
|
50
|
+
return lines;
|
|
51
|
+
}
|
|
52
|
+
export function buildClaudeFileBrief(context) {
|
|
53
|
+
const sessionDelegationLines = context?.skillRuntime ? [] : MAIN_SESSION_DELEGATION_LINES;
|
|
54
|
+
const lines = [
|
|
55
|
+
'# Borgee Claude runtime brief',
|
|
56
|
+
'',
|
|
57
|
+
'This directory belongs to one Borgee Claude channel session hosted by agents-host.',
|
|
58
|
+
'Keep visible replies concise, honest, and grounded in the current channel. Do not claim actions you did not actually perform.',
|
|
59
|
+
'',
|
|
60
|
+
...sessionDelegationLines,
|
|
61
|
+
...(() => {
|
|
62
|
+
const workspaceLines = buildResolvedWorkspaceGuidanceLines(context);
|
|
63
|
+
return workspaceLines.length > 0 ? ['', ...workspaceLines] : [];
|
|
64
|
+
})(),
|
|
65
|
+
...(() => {
|
|
66
|
+
const capabilityLines = buildCollaborationCapabilityDeclarationSummaryLines(context?.collaborationCapabilities);
|
|
67
|
+
return capabilityLines.length > 0 ? ['', ...capabilityLines] : [];
|
|
68
|
+
})(),
|
|
69
|
+
...(() => {
|
|
70
|
+
const taskThreadLines = buildStableTaskThreadLines(context);
|
|
71
|
+
return taskThreadLines.length > 0 ? ['', ...taskThreadLines] : [];
|
|
72
|
+
})(),
|
|
73
|
+
...(() => {
|
|
74
|
+
const skillLines = buildStableSkillLines(context);
|
|
75
|
+
return skillLines.length > 0 ? ['', ...skillLines] : [];
|
|
76
|
+
})(),
|
|
77
|
+
...(() => {
|
|
78
|
+
const gatewayLines = buildStableGatewayLines(context);
|
|
79
|
+
return gatewayLines.length > 0 ? ['', ...gatewayLines] : [];
|
|
80
|
+
})(),
|
|
81
|
+
];
|
|
82
|
+
return `${lines.join('\n').trimEnd()}\n`;
|
|
83
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CompactionSnapshot, ProviderCompactionStage, ProviderKind } from '../types.js';
|
|
2
|
+
export declare function buildCompactionSnapshot(params: {
|
|
3
|
+
provider: ProviderKind;
|
|
4
|
+
stage: ProviderCompactionStage;
|
|
5
|
+
observedAt?: number;
|
|
6
|
+
turnExecutionId?: string;
|
|
7
|
+
usedTokens?: number;
|
|
8
|
+
contextWindowTokens?: number;
|
|
9
|
+
failureReason?: string;
|
|
10
|
+
}): CompactionSnapshot;
|
|
11
|
+
export declare function mergeCompactionSnapshot(current: CompactionSnapshot | undefined, update: {
|
|
12
|
+
provider: ProviderKind;
|
|
13
|
+
stage: ProviderCompactionStage;
|
|
14
|
+
observedAt?: number;
|
|
15
|
+
turnExecutionId?: string;
|
|
16
|
+
usedTokens?: number;
|
|
17
|
+
contextWindowTokens?: number;
|
|
18
|
+
failureReason?: string;
|
|
19
|
+
}): CompactionSnapshot;
|
|
20
|
+
export declare function parsePersistedCompactionSnapshot(raw: unknown): CompactionSnapshot | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function isProviderKind(value) {
|
|
5
|
+
return value === 'claude' || value === 'copilot' || value === 'codex';
|
|
6
|
+
}
|
|
7
|
+
function isCompactionStage(value) {
|
|
8
|
+
return value === 'started' || value === 'completed' || value === 'failed';
|
|
9
|
+
}
|
|
10
|
+
function isTerminalCompactionStage(value) {
|
|
11
|
+
return value === 'completed' || value === 'failed';
|
|
12
|
+
}
|
|
13
|
+
function normalizeFiniteNumber(value) {
|
|
14
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
function normalizeNonEmptyString(value) {
|
|
17
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function buildCompactionSnapshot(params) {
|
|
20
|
+
return {
|
|
21
|
+
source: 'host-observed',
|
|
22
|
+
provider: params.provider,
|
|
23
|
+
stage: params.stage,
|
|
24
|
+
observedAt: params.observedAt ?? Date.now(),
|
|
25
|
+
...(params.turnExecutionId ? { turnExecutionId: params.turnExecutionId } : {}),
|
|
26
|
+
...(params.usedTokens !== undefined ? { usedTokens: params.usedTokens } : {}),
|
|
27
|
+
...(params.contextWindowTokens !== undefined
|
|
28
|
+
? { contextWindowTokens: params.contextWindowTokens }
|
|
29
|
+
: {}),
|
|
30
|
+
...(params.failureReason ? { failureReason: params.failureReason } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function mergeCompactionSnapshot(current, update) {
|
|
34
|
+
const retainUsageFromCurrent = current?.stage === 'completed' && update.stage === 'completed';
|
|
35
|
+
return buildCompactionSnapshot({
|
|
36
|
+
provider: update.provider,
|
|
37
|
+
stage: update.stage,
|
|
38
|
+
observedAt: update.observedAt,
|
|
39
|
+
turnExecutionId: update.turnExecutionId,
|
|
40
|
+
usedTokens: update.usedTokens ?? (retainUsageFromCurrent ? current?.usedTokens : undefined),
|
|
41
|
+
contextWindowTokens: update.contextWindowTokens
|
|
42
|
+
?? (retainUsageFromCurrent ? current?.contextWindowTokens : undefined),
|
|
43
|
+
failureReason: update.failureReason,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function parsePersistedCompactionSnapshot(raw) {
|
|
47
|
+
if (!isRecord(raw) || !isProviderKind(raw.provider) || !isTerminalCompactionStage(raw.stage)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return buildCompactionSnapshot({
|
|
51
|
+
provider: raw.provider,
|
|
52
|
+
stage: raw.stage,
|
|
53
|
+
observedAt: normalizeFiniteNumber(raw.observedAt) ?? Date.now(),
|
|
54
|
+
turnExecutionId: normalizeNonEmptyString(raw.turnExecutionId),
|
|
55
|
+
usedTokens: normalizeFiniteNumber(raw.usedTokens),
|
|
56
|
+
contextWindowTokens: normalizeFiniteNumber(raw.contextWindowTokens),
|
|
57
|
+
failureReason: normalizeNonEmptyString(raw.failureReason),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChatControlPlane } from '../chat/chat-control-plane.js';
|
|
2
|
+
import type { AttentionSnapshot, ProjectionStrategy, CollaborationCapabilityDeclaration, CollaborationOutcomeSnapshot, CompactionSnapshot, LocalhostGatewayBootstrapMetadata, MissedCollaborationDiagnostic, ProviderKind, ProviderCollaborationContext, ResolvedWorkspaceContext, RuntimeSurface, SkillRuntimeBootstrapMetadata, TaskThreadCollaborationContract, TaskAssignmentThreadContext } from '../types.js';
|
|
2
3
|
export interface SkillRuntimeBootstrapPayload {
|
|
3
4
|
skillDirectoryPath: string;
|
|
4
5
|
nodeCliPath: string;
|
|
@@ -7,24 +8,28 @@ export interface SkillRuntimeBootstrapPayload {
|
|
|
7
8
|
export interface ChannelContextPayload {
|
|
8
9
|
schemaVersion: 1;
|
|
9
10
|
channelId: string;
|
|
11
|
+
runtimeSurface?: RuntimeSurface;
|
|
10
12
|
collaborationOutcome?: CollaborationOutcomeSnapshot;
|
|
11
13
|
attentionSnapshot?: AttentionSnapshot;
|
|
14
|
+
compactionSnapshot?: CompactionSnapshot;
|
|
12
15
|
taskThreadCollaborationContract?: TaskThreadCollaborationContract;
|
|
13
16
|
collaborationCapabilities?: CollaborationCapabilityDeclaration;
|
|
14
17
|
missedCollaborationDiagnostic?: MissedCollaborationDiagnostic;
|
|
15
18
|
skillRuntime?: SkillRuntimeBootstrapPayload;
|
|
16
19
|
localhostGateway?: LocalhostGatewayBootstrapMetadata;
|
|
17
20
|
taskAssignmentContext?: TaskAssignmentThreadContext;
|
|
18
|
-
|
|
21
|
+
resolvedWorkspace?: ResolvedWorkspaceContext;
|
|
19
22
|
}
|
|
20
23
|
export interface PreparedChannelContext {
|
|
21
24
|
directoryPath: string;
|
|
22
25
|
payload: ChannelContextPayload;
|
|
23
26
|
payloadPath?: string;
|
|
24
|
-
|
|
27
|
+
claudeProjectedBriefPath?: string;
|
|
28
|
+
claudeProjectedBriefHash?: string;
|
|
29
|
+
gatewayCredentialPath?: string;
|
|
25
30
|
skillRuntime?: SkillRuntimeBootstrapMetadata;
|
|
26
31
|
localhostGateway?: LocalhostGatewayBootstrapMetadata;
|
|
27
|
-
|
|
32
|
+
resolvedWorkspace?: ResolvedWorkspaceContext;
|
|
28
33
|
}
|
|
29
34
|
export declare class ChannelContextPreparationError extends Error {
|
|
30
35
|
readonly partialContext: PreparedChannelContext;
|
|
@@ -33,9 +38,12 @@ export declare class ChannelContextPreparationError extends Error {
|
|
|
33
38
|
export interface ChannelContextStore {
|
|
34
39
|
prepare(input: {
|
|
35
40
|
channelId: string;
|
|
41
|
+
provider?: ProviderKind;
|
|
42
|
+
projectionStrategy?: ProjectionStrategy;
|
|
36
43
|
collaboration?: ProviderCollaborationContext;
|
|
37
44
|
collaborationOutcome?: CollaborationOutcomeSnapshot;
|
|
38
45
|
attentionSnapshot?: AttentionSnapshot;
|
|
46
|
+
compactionSnapshot?: CompactionSnapshot;
|
|
39
47
|
taskThreadCollaborationContract?: TaskThreadCollaborationContract;
|
|
40
48
|
collaborationCapabilities?: CollaborationCapabilityDeclaration;
|
|
41
49
|
missedCollaborationDiagnostic?: MissedCollaborationDiagnostic;
|
|
@@ -43,9 +51,12 @@ export interface ChannelContextStore {
|
|
|
43
51
|
incomingContent?: string;
|
|
44
52
|
}): Promise<PreparedChannelContext>;
|
|
45
53
|
prepare(channelId: string, options?: {
|
|
54
|
+
provider?: ProviderKind;
|
|
55
|
+
projectionStrategy?: ProjectionStrategy;
|
|
46
56
|
collaboration?: ProviderCollaborationContext;
|
|
47
57
|
collaborationOutcome?: CollaborationOutcomeSnapshot;
|
|
48
58
|
attentionSnapshot?: AttentionSnapshot;
|
|
59
|
+
compactionSnapshot?: CompactionSnapshot;
|
|
49
60
|
taskThreadCollaborationContract?: TaskThreadCollaborationContract;
|
|
50
61
|
collaborationCapabilities?: CollaborationCapabilityDeclaration;
|
|
51
62
|
missedCollaborationDiagnostic?: MissedCollaborationDiagnostic;
|
|
@@ -83,6 +94,7 @@ interface ContextFileSystem {
|
|
|
83
94
|
mode?: number;
|
|
84
95
|
}): Promise<void>;
|
|
85
96
|
unlink(path: string): Promise<void>;
|
|
97
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
86
98
|
access(path: string): Promise<void>;
|
|
87
99
|
}
|
|
88
100
|
interface FileChannelContextStoreOptions {
|
|
@@ -90,16 +102,31 @@ interface FileChannelContextStoreOptions {
|
|
|
90
102
|
skillRuntimeEnabled?: boolean;
|
|
91
103
|
skillAssetResolver?: SkillAssetResolver;
|
|
92
104
|
localhostGateway?: LocalhostGatewayContextPublisher;
|
|
93
|
-
|
|
105
|
+
workspaceCollectionRootDir?: string;
|
|
106
|
+
taskReader?: Pick<ChatControlPlane, 'getTask' | 'listChannels' | 'listTasks'>;
|
|
107
|
+
taskResolutionTimeoutMs?: number;
|
|
108
|
+
env?: NodeJS.ProcessEnv;
|
|
109
|
+
resolvedHomeDir?: string;
|
|
94
110
|
}
|
|
111
|
+
export declare function buildRuntimeSurfaceForTurn(options?: {
|
|
112
|
+
localhostGateway?: LocalhostGatewayBootstrapMetadata;
|
|
113
|
+
collaboration?: Pick<ProviderCollaborationContext, 'sendRoutesAllowed' | 'turnMode'>;
|
|
114
|
+
taskAssignmentContext?: TaskAssignmentThreadContext;
|
|
115
|
+
}): RuntimeSurface;
|
|
95
116
|
export declare function extractTaskIdFromTaskAssignmentContent(incomingContent: string | undefined): string | undefined;
|
|
96
117
|
export declare function encodeChannelPathSegment(channelId: string): string;
|
|
97
118
|
export declare function resolveChannelContextDirectory(stateRootDir: string, channelId: string): string;
|
|
98
119
|
export declare function resolveChannelContextPayloadPath(stateRootDir: string, channelId: string): string;
|
|
99
120
|
export declare function resolveTaskWorkspaceRootDirectory(startupWorkspaceRootDir: string): string;
|
|
100
|
-
export declare function
|
|
101
|
-
export declare function
|
|
102
|
-
export declare function
|
|
121
|
+
export declare function resolveManagedWorkspaceCollectionRoot(workspaceCollectionRootDir: string | undefined, env?: NodeJS.ProcessEnv, resolvedHomeDir?: string): string;
|
|
122
|
+
export declare function resolveChannelWorkspaceRootDirectory(workspaceCollectionRootDir: string, channelId: string): string;
|
|
123
|
+
export declare function resolveChannelWorkspaceDirectory(workspaceCollectionRootDir: string, channelId: string): string;
|
|
124
|
+
export declare function resolveTaskIsolatedWorkspaceDirectory(workspaceCollectionRootDir: string, channelId: string, taskId: string): string;
|
|
125
|
+
export declare const resolveTaskWorkspaceDirectory: typeof resolveTaskIsolatedWorkspaceDirectory;
|
|
126
|
+
export declare function resolveChannelGatewayCredentialPath(stateRootDir: string, channelId: string): string;
|
|
127
|
+
export declare function resolveGatewayCredentialPathFromPayloadPath(payloadPath: string): string;
|
|
128
|
+
export declare function resolveClaudeProjectedBriefPathFromPayloadPath(payloadPath: string): string;
|
|
129
|
+
export declare function isGatewayCredentialSidecarBasename(basename: string): boolean;
|
|
103
130
|
export declare function resolveBorgeeAgentSkillRuntimeAssets(moduleUrl: string, fileSystem?: Pick<ContextFileSystem, 'access'>): Promise<SkillRuntimeBootstrapMetadata>;
|
|
104
131
|
export declare class FileChannelContextStore implements ChannelContextStore {
|
|
105
132
|
private readonly stateRootDir;
|
|
@@ -107,22 +134,30 @@ export declare class FileChannelContextStore implements ChannelContextStore {
|
|
|
107
134
|
private readonly skillRuntimeEnabled;
|
|
108
135
|
private readonly skillAssetResolver;
|
|
109
136
|
private readonly localhostGateway?;
|
|
110
|
-
private readonly
|
|
137
|
+
private readonly workspaceCollectionRootDir;
|
|
138
|
+
private readonly taskReader?;
|
|
139
|
+
private readonly taskResolutionTimeoutMs;
|
|
111
140
|
constructor(stateRootDir: string, options?: FileChannelContextStoreOptions);
|
|
112
141
|
prepare(inputOrChannelId: {
|
|
113
142
|
channelId: string;
|
|
143
|
+
provider?: ProviderKind;
|
|
144
|
+
projectionStrategy?: ProjectionStrategy;
|
|
114
145
|
collaboration?: ProviderCollaborationContext;
|
|
115
146
|
collaborationOutcome?: CollaborationOutcomeSnapshot;
|
|
116
147
|
attentionSnapshot?: AttentionSnapshot;
|
|
148
|
+
compactionSnapshot?: CompactionSnapshot;
|
|
117
149
|
taskThreadCollaborationContract?: TaskThreadCollaborationContract;
|
|
118
150
|
collaborationCapabilities?: CollaborationCapabilityDeclaration;
|
|
119
151
|
missedCollaborationDiagnostic?: MissedCollaborationDiagnostic;
|
|
120
152
|
incomingMessageType?: string;
|
|
121
153
|
incomingContent?: string;
|
|
122
154
|
} | string, options?: {
|
|
155
|
+
provider?: ProviderKind;
|
|
156
|
+
projectionStrategy?: ProjectionStrategy;
|
|
123
157
|
collaboration?: ProviderCollaborationContext;
|
|
124
158
|
collaborationOutcome?: CollaborationOutcomeSnapshot;
|
|
125
159
|
attentionSnapshot?: AttentionSnapshot;
|
|
160
|
+
compactionSnapshot?: CompactionSnapshot;
|
|
126
161
|
taskThreadCollaborationContract?: TaskThreadCollaborationContract;
|
|
127
162
|
collaborationCapabilities?: CollaborationCapabilityDeclaration;
|
|
128
163
|
missedCollaborationDiagnostic?: MissedCollaborationDiagnostic;
|