@borgee/agents-host 0.2.1 → 0.2.26

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 (78) 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 +89 -15
  5. package/dist/agents-host.js +2099 -142
  6. package/dist/chat/chat-control-plane.d.ts +14 -3
  7. package/dist/chat/sdk-chat-control-plane.d.ts +16 -4
  8. package/dist/chat/sdk-chat-control-plane.js +69 -9
  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 +35 -0
  14. package/dist/compatibility-gates.js +127 -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/injection.d.ts +109 -0
  20. package/dist/context/injection.js +350 -0
  21. package/dist/context/prompt.d.ts +4 -1
  22. package/dist/context/prompt.js +170 -1
  23. package/dist/context/turn-preparation.d.ts +9 -0
  24. package/dist/context/turn-preparation.js +106 -0
  25. package/dist/debug.d.ts +44 -0
  26. package/dist/debug.js +135 -0
  27. package/dist/gateway/localhost-gateway.d.ts +52 -0
  28. package/dist/gateway/localhost-gateway.js +857 -0
  29. package/dist/index.js +7 -5
  30. package/dist/local-config.d.ts +4 -1
  31. package/dist/local-config.js +24 -7
  32. package/dist/managed-daemon-log.d.ts +34 -0
  33. package/dist/managed-daemon-log.js +261 -0
  34. package/dist/managed-daemon.d.ts +220 -0
  35. package/dist/managed-daemon.js +1601 -0
  36. package/dist/policy/authorization-audit.d.ts +63 -0
  37. package/dist/policy/authorization-audit.js +94 -0
  38. package/dist/policy/copilot-permission.d.ts +15 -0
  39. package/dist/policy/copilot-permission.js +193 -0
  40. package/dist/policy/gateway-authorization.d.ts +42 -0
  41. package/dist/policy/gateway-authorization.js +162 -0
  42. package/dist/providers/awaiting-user.d.ts +12 -0
  43. package/dist/providers/awaiting-user.js +151 -0
  44. package/dist/providers/claude/adapter.d.ts +3 -1
  45. package/dist/providers/claude/adapter.js +8 -12
  46. package/dist/providers/claude/cli-client.d.ts +12 -5
  47. package/dist/providers/claude/cli-client.js +184 -37
  48. package/dist/providers/claude/session-store.d.ts +24 -0
  49. package/dist/providers/claude/session-store.js +65 -12
  50. package/dist/providers/codex/adapter.d.ts +11 -0
  51. package/dist/providers/codex/adapter.js +19 -0
  52. package/dist/providers/codex/cli-client.d.ts +103 -0
  53. package/dist/providers/codex/cli-client.js +1133 -0
  54. package/dist/providers/codex/project-doc.d.ts +3 -0
  55. package/dist/providers/codex/project-doc.js +66 -0
  56. package/dist/providers/codex/session-store.d.ts +38 -0
  57. package/dist/providers/codex/session-store.js +150 -0
  58. package/dist/providers/copilot/adapter.d.ts +3 -1
  59. package/dist/providers/copilot/adapter.js +8 -12
  60. package/dist/providers/copilot/cli-client.d.ts +20 -2
  61. package/dist/providers/copilot/cli-client.js +251 -71
  62. package/dist/providers/copilot/session-store.d.ts +24 -0
  63. package/dist/providers/copilot/session-store.js +65 -12
  64. package/dist/providers/create-provider.d.ts +11 -2
  65. package/dist/providers/create-provider.js +131 -12
  66. package/dist/run.d.ts +1 -0
  67. package/dist/run.js +5 -2
  68. package/dist/state-paths.d.ts +13 -1
  69. package/dist/state-paths.js +84 -3
  70. package/dist/task-thread-resolution.d.ts +10 -0
  71. package/dist/task-thread-resolution.js +48 -0
  72. package/dist/types.d.ts +174 -1
  73. package/dist/visible-mentions.d.ts +3 -0
  74. package/dist/visible-mentions.js +15 -0
  75. package/package.json +19 -17
  76. package/skills/borgee-agent/SKILL.md +33 -0
  77. package/skills/borgee-agent/borgee-agent.mjs +473 -0
  78. package/skills/borgee-agent/borgee-agent.py +409 -0
@@ -0,0 +1,106 @@
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 && !input.collaboration) {
15
+ return undefined;
16
+ }
17
+ return {
18
+ ...(channelContext
19
+ ? {
20
+ channelContextPayloadPath: channelContext.payloadPath,
21
+ gatewayAuthPath: channelContext.gatewayAuthPath,
22
+ skillRuntime: channelContext.skillRuntime,
23
+ localhostGateway: channelContext.localhostGateway,
24
+ taskAssignmentContext: channelContext.payload.taskAssignmentContext,
25
+ taskWorkspace: channelContext.taskWorkspace,
26
+ }
27
+ : {}),
28
+ collaborationTurnExecutionId: input.collaboration?.turnExecutionId,
29
+ collaborationTurnMode: input.collaboration?.turnMode,
30
+ kickoff: input.collaboration?.kickoff,
31
+ protocol: input.collaboration?.protocol,
32
+ grounding: input.collaboration?.grounding,
33
+ };
34
+ }
35
+ function resolveProviderSessionRouting(input) {
36
+ const kickoff = input.collaboration?.kickoff;
37
+ if (input.collaboration?.turnMode === 'silent-kickoff' && kickoff) {
38
+ return {
39
+ key: `${input.channelId}::kickoff::${kickoff.anchorMessageId}`,
40
+ persistence: 'ephemeral',
41
+ };
42
+ }
43
+ return {
44
+ key: input.channelId,
45
+ persistence: 'persistent',
46
+ };
47
+ }
48
+ export class ProviderTurnPreparer {
49
+ channelContextStore;
50
+ logger;
51
+ constructor(channelContextStore, logger = new HostLogger()) {
52
+ this.channelContextStore = channelContextStore;
53
+ this.logger = logger;
54
+ }
55
+ async prepare(input) {
56
+ let channelContext;
57
+ if (this.channelContextStore) {
58
+ try {
59
+ const prepareInput = {
60
+ channelId: input.channelId,
61
+ collaboration: input.collaboration
62
+ ? {
63
+ ...input.collaboration,
64
+ sendRoutesAllowed: input.collaboration.turnMode !== 'protocol-managed'
65
+ && input.collaboration.turnMode !== 'silent-kickoff',
66
+ }
67
+ : undefined,
68
+ ...(input.incomingMessageType !== undefined
69
+ ? { incomingMessageType: input.incomingMessageType }
70
+ : {}),
71
+ ...(input.incomingMessageType !== undefined && input.incomingContent !== undefined
72
+ ? { incomingContent: input.incomingContent }
73
+ : {}),
74
+ };
75
+ channelContext = await this.channelContextStore.prepare(prepareInput);
76
+ }
77
+ catch (error) {
78
+ if (error instanceof ChannelContextPreparationError) {
79
+ channelContext = error.partialContext;
80
+ }
81
+ this.logger.error(`failed to materialize ${providerLabel(input.provider)} channel context payload; keeping prompt delivery`, {
82
+ channelId: input.channelId,
83
+ error: summarizeError(error),
84
+ });
85
+ }
86
+ }
87
+ const promptContext = toPromptContext(channelContext, input);
88
+ return {
89
+ channelId: input.channelId,
90
+ incomingEventKind: input.incomingEventKind,
91
+ incomingMessageType: input.incomingMessageType,
92
+ prompt: buildPrompt({
93
+ agentName: input.agentName,
94
+ provider: input.provider,
95
+ channelId: input.channelId,
96
+ incomingAuthorId: input.incomingAuthorId,
97
+ incomingContent: input.incomingContent,
98
+ incomingEventKind: input.incomingEventKind,
99
+ incomingMessageType: input.incomingMessageType,
100
+ promptContext,
101
+ }),
102
+ promptContext,
103
+ providerSessionRouting: resolveProviderSessionRouting(input),
104
+ };
105
+ }
106
+ }
@@ -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 {};