@borgee/agents-host 0.2.2 → 0.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +184 -21
  2. package/dist/agents-host-supervisor.d.ts +7 -5
  3. package/dist/agents-host-supervisor.js +24 -4
  4. package/dist/agents-host.d.ts +114 -15
  5. package/dist/agents-host.js +2712 -141
  6. package/dist/chat/chat-control-plane.d.ts +13 -2
  7. package/dist/chat/sdk-chat-control-plane.d.ts +14 -3
  8. package/dist/chat/sdk-chat-control-plane.js +54 -2
  9. package/dist/cli-args.d.ts +46 -5
  10. package/dist/cli-args.js +313 -32
  11. package/dist/cli.d.ts +9 -0
  12. package/dist/cli.js +112 -5
  13. package/dist/compatibility-gates.d.ts +39 -0
  14. package/dist/compatibility-gates.js +131 -0
  15. package/dist/config.d.ts +1 -0
  16. package/dist/config.js +23 -5
  17. package/dist/connections-state-store.d.ts +81 -0
  18. package/dist/connections-state-store.js +228 -0
  19. package/dist/context/attention.d.ts +12 -0
  20. package/dist/context/attention.js +137 -0
  21. package/dist/context/collaboration-capabilities-diagnostics.d.ts +3 -0
  22. package/dist/context/collaboration-capabilities-diagnostics.js +18 -0
  23. package/dist/context/collaboration-outcome.d.ts +2 -0
  24. package/dist/context/collaboration-outcome.js +26 -0
  25. package/dist/context/injection.d.ts +134 -0
  26. package/dist/context/injection.js +355 -0
  27. package/dist/context/prompt.d.ts +4 -1
  28. package/dist/context/prompt.js +231 -1
  29. package/dist/context/task-thread-collaboration.d.ts +6 -0
  30. package/dist/context/task-thread-collaboration.js +31 -0
  31. package/dist/context/turn-preparation.d.ts +9 -0
  32. package/dist/context/turn-preparation.js +135 -0
  33. package/dist/debug.d.ts +44 -0
  34. package/dist/debug.js +135 -0
  35. package/dist/gateway/localhost-gateway.d.ts +52 -0
  36. package/dist/gateway/localhost-gateway.js +857 -0
  37. package/dist/index.js +7 -5
  38. package/dist/local-config.d.ts +4 -1
  39. package/dist/local-config.js +24 -7
  40. package/dist/managed-daemon-log.d.ts +34 -0
  41. package/dist/managed-daemon-log.js +261 -0
  42. package/dist/managed-daemon.d.ts +220 -0
  43. package/dist/managed-daemon.js +1601 -0
  44. package/dist/policy/authorization-audit.d.ts +63 -0
  45. package/dist/policy/authorization-audit.js +94 -0
  46. package/dist/policy/copilot-permission.d.ts +15 -0
  47. package/dist/policy/copilot-permission.js +193 -0
  48. package/dist/policy/gateway-authorization.d.ts +42 -0
  49. package/dist/policy/gateway-authorization.js +162 -0
  50. package/dist/providers/awaiting-user.d.ts +12 -0
  51. package/dist/providers/awaiting-user.js +192 -0
  52. package/dist/providers/claude/adapter.d.ts +3 -1
  53. package/dist/providers/claude/adapter.js +8 -12
  54. package/dist/providers/claude/cli-client.d.ts +12 -5
  55. package/dist/providers/claude/cli-client.js +184 -37
  56. package/dist/providers/claude/session-store.d.ts +1 -0
  57. package/dist/providers/codex/adapter.d.ts +11 -0
  58. package/dist/providers/codex/adapter.js +19 -0
  59. package/dist/providers/codex/cli-client.d.ts +103 -0
  60. package/dist/providers/codex/cli-client.js +1133 -0
  61. package/dist/providers/codex/project-doc.d.ts +3 -0
  62. package/dist/providers/codex/project-doc.js +90 -0
  63. package/dist/providers/codex/session-store.d.ts +38 -0
  64. package/dist/providers/codex/session-store.js +150 -0
  65. package/dist/providers/copilot/adapter.d.ts +3 -1
  66. package/dist/providers/copilot/adapter.js +8 -12
  67. package/dist/providers/copilot/cli-client.d.ts +20 -2
  68. package/dist/providers/copilot/cli-client.js +251 -71
  69. package/dist/providers/copilot/session-store.d.ts +1 -0
  70. package/dist/providers/create-provider.d.ts +11 -2
  71. package/dist/providers/create-provider.js +131 -12
  72. package/dist/run.d.ts +1 -0
  73. package/dist/run.js +5 -2
  74. package/dist/state-paths.d.ts +14 -1
  75. package/dist/state-paths.js +87 -3
  76. package/dist/task-thread-resolution.d.ts +10 -0
  77. package/dist/task-thread-resolution.js +48 -0
  78. package/dist/types.d.ts +267 -1
  79. package/dist/visible-mentions.d.ts +3 -0
  80. package/dist/visible-mentions.js +15 -0
  81. package/package.json +19 -17
  82. package/skills/borgee-agent/SKILL.md +33 -0
  83. package/skills/borgee-agent/borgee-agent.mjs +473 -0
  84. package/skills/borgee-agent/borgee-agent.py +409 -0
@@ -0,0 +1,9 @@
1
+ import { type DebugLogger } from '../debug.js';
2
+ import type { PreparedProviderTurnInput, ProviderInput } from '../types.js';
3
+ import { type ChannelContextStore } from './injection.js';
4
+ export declare class ProviderTurnPreparer {
5
+ private readonly channelContextStore?;
6
+ private readonly logger;
7
+ constructor(channelContextStore?: ChannelContextStore | undefined, logger?: DebugLogger);
8
+ prepare(input: ProviderInput): Promise<PreparedProviderTurnInput>;
9
+ }
@@ -0,0 +1,135 @@
1
+ import { HostLogger, summarizeError } from '../debug.js';
2
+ import { ChannelContextPreparationError, } from './injection.js';
3
+ import { buildPrompt } from './prompt.js';
4
+ function providerLabel(provider) {
5
+ if (provider === 'copilot') {
6
+ return 'Copilot';
7
+ }
8
+ if (provider === 'codex') {
9
+ return 'Codex';
10
+ }
11
+ return 'Claude';
12
+ }
13
+ function toPromptContext(channelContext, input) {
14
+ if (!channelContext
15
+ && !input.collaboration
16
+ && !input.collaborationOutcome
17
+ && !input.attentionSnapshot
18
+ && !input.collaborationCapabilities
19
+ && !input.missedCollaborationDiagnostic
20
+ && !input.taskThreadCollaborationContract) {
21
+ return undefined;
22
+ }
23
+ return {
24
+ ...(channelContext
25
+ ? {
26
+ channelContextPayloadPath: channelContext.payloadPath,
27
+ gatewayAuthPath: channelContext.gatewayAuthPath,
28
+ skillRuntime: channelContext.skillRuntime,
29
+ localhostGateway: channelContext.localhostGateway,
30
+ taskAssignmentContext: channelContext.payload.taskAssignmentContext,
31
+ taskWorkspace: channelContext.taskWorkspace,
32
+ }
33
+ : {}),
34
+ collaborationTurnExecutionId: input.collaboration?.turnExecutionId,
35
+ collaborationTurnMode: input.collaboration?.turnMode,
36
+ collaborationOutcome: input.collaborationOutcome ?? channelContext?.payload.collaborationOutcome,
37
+ attentionSnapshot: input.attentionSnapshot ?? channelContext?.payload.attentionSnapshot,
38
+ ...(() => {
39
+ const collaborationCapabilities = input.collaborationCapabilities ?? channelContext?.payload.collaborationCapabilities;
40
+ return collaborationCapabilities ? { collaborationCapabilities } : {};
41
+ })(),
42
+ ...(() => {
43
+ const missedCollaborationDiagnostic = input.missedCollaborationDiagnostic ?? channelContext?.payload.missedCollaborationDiagnostic;
44
+ return missedCollaborationDiagnostic ? { missedCollaborationDiagnostic } : {};
45
+ })(),
46
+ ...(input.taskThreadCollaborationContract || channelContext?.payload.taskThreadCollaborationContract
47
+ ? {
48
+ taskThreadCollaborationContract: input.taskThreadCollaborationContract
49
+ ?? channelContext?.payload.taskThreadCollaborationContract,
50
+ }
51
+ : {}),
52
+ kickoff: input.collaboration?.kickoff,
53
+ protocol: input.collaboration?.protocol,
54
+ grounding: input.collaboration?.grounding,
55
+ };
56
+ }
57
+ function resolveProviderSessionRouting(input) {
58
+ const kickoff = input.collaboration?.kickoff;
59
+ if (input.collaboration?.turnMode === 'silent-kickoff' && kickoff) {
60
+ return {
61
+ key: `${input.channelId}::kickoff::${kickoff.anchorMessageId}`,
62
+ persistence: 'ephemeral',
63
+ };
64
+ }
65
+ return {
66
+ key: input.channelId,
67
+ persistence: 'persistent',
68
+ };
69
+ }
70
+ export class ProviderTurnPreparer {
71
+ channelContextStore;
72
+ logger;
73
+ constructor(channelContextStore, logger = new HostLogger()) {
74
+ this.channelContextStore = channelContextStore;
75
+ this.logger = logger;
76
+ }
77
+ async prepare(input) {
78
+ let channelContext;
79
+ if (this.channelContextStore) {
80
+ try {
81
+ const prepareInput = {
82
+ channelId: input.channelId,
83
+ collaboration: input.collaboration
84
+ ? {
85
+ ...input.collaboration,
86
+ sendRoutesAllowed: input.collaboration.turnMode !== 'protocol-managed'
87
+ && input.collaboration.turnMode !== 'silent-kickoff',
88
+ }
89
+ : undefined,
90
+ collaborationOutcome: input.collaborationOutcome,
91
+ attentionSnapshot: input.attentionSnapshot,
92
+ collaborationCapabilities: input.collaborationCapabilities,
93
+ missedCollaborationDiagnostic: input.missedCollaborationDiagnostic,
94
+ ...(input.taskThreadCollaborationContract
95
+ ? { taskThreadCollaborationContract: input.taskThreadCollaborationContract }
96
+ : {}),
97
+ ...(input.incomingMessageType !== undefined
98
+ ? { incomingMessageType: input.incomingMessageType }
99
+ : {}),
100
+ ...(input.incomingMessageType !== undefined && input.incomingContent !== undefined
101
+ ? { incomingContent: input.incomingContent }
102
+ : {}),
103
+ };
104
+ channelContext = await this.channelContextStore.prepare(prepareInput);
105
+ }
106
+ catch (error) {
107
+ if (error instanceof ChannelContextPreparationError) {
108
+ channelContext = error.partialContext;
109
+ }
110
+ this.logger.error(`failed to materialize ${providerLabel(input.provider)} channel context payload; keeping prompt delivery`, {
111
+ channelId: input.channelId,
112
+ error: summarizeError(error),
113
+ });
114
+ }
115
+ }
116
+ const promptContext = toPromptContext(channelContext, input);
117
+ return {
118
+ channelId: input.channelId,
119
+ incomingEventKind: input.incomingEventKind,
120
+ incomingMessageType: input.incomingMessageType,
121
+ prompt: buildPrompt({
122
+ agentName: input.agentName,
123
+ provider: input.provider,
124
+ channelId: input.channelId,
125
+ incomingAuthorId: input.incomingAuthorId,
126
+ incomingContent: input.incomingContent,
127
+ incomingEventKind: input.incomingEventKind,
128
+ incomingMessageType: input.incomingMessageType,
129
+ promptContext,
130
+ }),
131
+ promptContext,
132
+ providerSessionRouting: resolveProviderSessionRouting(input),
133
+ };
134
+ }
135
+ }
@@ -0,0 +1,44 @@
1
+ export interface LoggerLike {
2
+ log(...args: unknown[]): void;
3
+ error(...args: unknown[]): void;
4
+ }
5
+ export interface DebugLogger {
6
+ readonly enabled: boolean;
7
+ error(message: string, details?: unknown): void;
8
+ debug(message: string, details?: unknown): void;
9
+ debugError(message: string, details?: unknown): void;
10
+ childStderr(label: string, summary: ChildStderrSummary): void;
11
+ }
12
+ export interface AgentsHostRuntimeOptions {
13
+ debug?: boolean;
14
+ logger?: LoggerLike;
15
+ logPrefix?: string;
16
+ }
17
+ export interface ChildStderrSummary {
18
+ bytes: number;
19
+ lineCount: number;
20
+ }
21
+ export interface SafeErrorSummary {
22
+ name: string;
23
+ messageBytes?: number;
24
+ messageLineCount?: number;
25
+ code?: number | string;
26
+ exitCode?: number;
27
+ signal?: string;
28
+ stderrBytes?: number;
29
+ stderrLineCount?: number;
30
+ }
31
+ export declare function resolveAgentsHostDebugMode(cliDebugFlag?: boolean, env?: NodeJS.ProcessEnv): boolean;
32
+ export declare function summarizeChildStderr(chunk: string): ChildStderrSummary;
33
+ export declare function summarizeError(error: unknown): SafeErrorSummary;
34
+ export declare class HostLogger implements DebugLogger {
35
+ readonly enabled: boolean;
36
+ private readonly logger;
37
+ private readonly prefix;
38
+ constructor(options?: AgentsHostRuntimeOptions);
39
+ log(message: string, details?: unknown): void;
40
+ error(message: string, details?: unknown): void;
41
+ debug(message: string, details?: unknown): void;
42
+ debugError(message: string, details?: unknown): void;
43
+ childStderr(label: string, summary: ChildStderrSummary): void;
44
+ }
package/dist/debug.js ADDED
@@ -0,0 +1,135 @@
1
+ const DEFAULT_LOG_PREFIX = '[agents-host]';
2
+ export function resolveAgentsHostDebugMode(cliDebugFlag = false, env = process.env) {
3
+ return cliDebugFlag || env.AGENTS_HOST_DEBUG?.trim() === '1';
4
+ }
5
+ export function summarizeChildStderr(chunk) {
6
+ if (chunk.length === 0) {
7
+ return { bytes: 0, lineCount: 0 };
8
+ }
9
+ const segments = chunk.split(/\r?\n/u);
10
+ return {
11
+ bytes: Buffer.byteLength(chunk, 'utf8'),
12
+ lineCount: chunk.endsWith('\n') ? segments.length - 1 : segments.length,
13
+ };
14
+ }
15
+ function asObject(value) {
16
+ return typeof value === 'object' && value !== null ? value : null;
17
+ }
18
+ function readFiniteNumber(value) {
19
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
20
+ }
21
+ function readNonEmptyString(value) {
22
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
23
+ }
24
+ export function summarizeError(error) {
25
+ if (error instanceof Error) {
26
+ const summary = {
27
+ name: error.name || 'Error',
28
+ };
29
+ if (error.message.length > 0) {
30
+ const messageSummary = summarizeChildStderr(error.message);
31
+ summary.messageBytes = messageSummary.bytes;
32
+ summary.messageLineCount = messageSummary.lineCount;
33
+ }
34
+ const errorRecord = asObject(error);
35
+ const code = readFiniteNumber(errorRecord?.code) ?? readNonEmptyString(errorRecord?.code);
36
+ if (code !== undefined) {
37
+ summary.code = code;
38
+ }
39
+ const exitCode = readFiniteNumber(errorRecord?.exitCode);
40
+ if (exitCode !== undefined) {
41
+ summary.exitCode = exitCode;
42
+ }
43
+ const signal = readNonEmptyString(errorRecord?.signal);
44
+ if (signal !== undefined) {
45
+ summary.signal = signal;
46
+ }
47
+ const stderrBytes = readFiniteNumber(errorRecord?.stderrBytes);
48
+ if (stderrBytes !== undefined) {
49
+ summary.stderrBytes = stderrBytes;
50
+ }
51
+ const stderrLineCount = readFiniteNumber(errorRecord?.stderrLineCount);
52
+ if (stderrLineCount !== undefined) {
53
+ summary.stderrLineCount = stderrLineCount;
54
+ }
55
+ return summary;
56
+ }
57
+ if (typeof error === 'string') {
58
+ const summary = summarizeChildStderr(error);
59
+ return {
60
+ name: 'NonErrorThrow',
61
+ messageBytes: summary.bytes,
62
+ messageLineCount: summary.lineCount,
63
+ };
64
+ }
65
+ return {
66
+ name: 'NonErrorThrow',
67
+ };
68
+ }
69
+ function sanitizeDebugDetails(details, seen = new WeakSet()) {
70
+ if (details instanceof Error) {
71
+ return summarizeError(details);
72
+ }
73
+ if (Array.isArray(details)) {
74
+ return details.map((item) => sanitizeDebugDetails(item, seen));
75
+ }
76
+ const record = asObject(details);
77
+ if (record === null) {
78
+ return details;
79
+ }
80
+ const prototype = Object.getPrototypeOf(record);
81
+ if (prototype !== Object.prototype && prototype !== null) {
82
+ return details;
83
+ }
84
+ if (seen.has(record)) {
85
+ return '[Circular]';
86
+ }
87
+ seen.add(record);
88
+ const sanitized = {};
89
+ for (const [key, value] of Object.entries(record)) {
90
+ sanitized[key] = sanitizeDebugDetails(value, seen);
91
+ }
92
+ return sanitized;
93
+ }
94
+ function emit(sink, prefix, message, details) {
95
+ const rendered = `${prefix} ${message}`;
96
+ if (details === undefined) {
97
+ sink(rendered);
98
+ return;
99
+ }
100
+ sink(rendered, details);
101
+ }
102
+ export class HostLogger {
103
+ enabled;
104
+ logger;
105
+ prefix;
106
+ constructor(options = {}) {
107
+ this.enabled = options.debug === true;
108
+ this.logger = options.logger ?? console;
109
+ this.prefix = options.logPrefix?.trim() || DEFAULT_LOG_PREFIX;
110
+ }
111
+ log(message, details) {
112
+ emit(this.logger.log.bind(this.logger), this.prefix, message, details);
113
+ }
114
+ error(message, details) {
115
+ emit(this.logger.error.bind(this.logger), this.prefix, message, details);
116
+ }
117
+ debug(message, details) {
118
+ if (!this.enabled) {
119
+ return;
120
+ }
121
+ this.log(message, details);
122
+ }
123
+ debugError(message, details) {
124
+ if (!this.enabled) {
125
+ return;
126
+ }
127
+ this.error(message, details === undefined ? undefined : sanitizeDebugDetails(details));
128
+ }
129
+ childStderr(label, summary) {
130
+ if (!this.enabled) {
131
+ return;
132
+ }
133
+ this.error(`${label} summary`, summary);
134
+ }
135
+ }
@@ -0,0 +1,52 @@
1
+ import type { ChatControlPlane } from '../chat/chat-control-plane.js';
2
+ import type { DebugLogger } from '../debug.js';
3
+ import type { InternalPolicyMode } from '../compatibility-gates.js';
4
+ import type { CollaborationDraftSnapshot } from '../types.js';
5
+ import type { LocalhostGatewayContextPublisher } from '../context/injection.js';
6
+ import { type ConnectionsStateStore } from '../connections-state-store.js';
7
+ import type { AuthorizationAuditSinkLike } from '../policy/authorization-audit.js';
8
+ export declare const LOCALHOST_GATEWAY_HISTORY_LIMIT = 20;
9
+ export declare const LOCALHOST_GATEWAY_COLLABORATION_BODY_LIMIT_BYTES = 512;
10
+ export declare const LOCALHOST_GATEWAY_COLLABORATION_BODY_MAX_WORDS = 12;
11
+ export declare const LOCALHOST_GATEWAY_COLLABORATION_TARGET_COOLDOWN_MS = 5000;
12
+ export interface GatewayCollaborationSendAuthorizationInput {
13
+ channelId: string;
14
+ turnExecutionId: string;
15
+ mentions: string[];
16
+ replyToId?: string;
17
+ }
18
+ export interface GatewayCollaborationSendAuthorizationResult {
19
+ ok: boolean;
20
+ statusCode: number;
21
+ error?: string;
22
+ commit?: () => void;
23
+ rollback?: () => void;
24
+ }
25
+ export interface GatewayCollaborationDraftReadInput {
26
+ channelId: string;
27
+ turnExecutionId: string;
28
+ }
29
+ export interface LocalhostGatewayController {
30
+ readonly enabled: boolean;
31
+ readonly contextPublisher?: LocalhostGatewayContextPublisher;
32
+ start(): Promise<void>;
33
+ stop(): Promise<void>;
34
+ }
35
+ interface CreateLocalhostGatewayOptions {
36
+ gateEnabled: boolean;
37
+ collaborationEnabled?: boolean;
38
+ tokenBindingGateEnabled?: boolean;
39
+ policyAuditGateEnabled?: boolean;
40
+ policyMode?: InternalPolicyMode;
41
+ controlPlane: ChatControlPlane;
42
+ stateRootDir?: string;
43
+ resolveStableAgentId?: () => string | undefined;
44
+ tokenBindingStore?: ConnectionsStateStore;
45
+ logger?: DebugLogger;
46
+ tokenFactory?: () => string;
47
+ auditSink?: AuthorizationAuditSinkLike;
48
+ authorizeCollaborationSend?: (input: GatewayCollaborationSendAuthorizationInput) => GatewayCollaborationSendAuthorizationResult;
49
+ readCollaborationDraft?: (input: GatewayCollaborationDraftReadInput) => CollaborationDraftSnapshot | null;
50
+ }
51
+ export declare function createLocalhostGatewayController(options: CreateLocalhostGatewayOptions): LocalhostGatewayController;
52
+ export {};