@borgee/agents-host 0.2.74 → 0.2.94

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 (82) hide show
  1. package/README.md +11 -24
  2. package/dist/agents-host.d.ts +6 -4
  3. package/dist/agents-host.js +127 -16
  4. package/dist/background-runs.d.ts +24 -0
  5. package/dist/background-runs.js +184 -0
  6. package/dist/chat/chat-control-plane.d.ts +7 -1
  7. package/dist/chat/sdk-chat-control-plane.d.ts +7 -2
  8. package/dist/chat/sdk-chat-control-plane.js +22 -0
  9. package/dist/context/claude-file-brief.js +3 -3
  10. package/dist/context/injection.d.ts +18 -12
  11. package/dist/context/injection.js +53 -53
  12. package/dist/context/prompt.js +10 -10
  13. package/dist/context/resolved-working-folder.d.ts +3 -0
  14. package/dist/context/resolved-working-folder.js +106 -0
  15. package/dist/context/turn-preparation.js +1 -1
  16. package/dist/managed-daemon.js +30 -30
  17. package/dist/plugin-sdk.js +315 -29
  18. package/dist/plugin-sdk.js.map +3 -3
  19. package/dist/policy/authorization-audit.d.ts +1 -1
  20. package/dist/policy/copilot-permission.d.ts +9 -0
  21. package/dist/policy/copilot-permission.js +120 -1
  22. package/dist/progress-to-activity.d.ts +1 -1
  23. package/dist/progress-to-activity.js +1 -0
  24. package/dist/providers/claude/adapter.d.ts +2 -1
  25. package/dist/providers/claude/adapter.js +36 -1
  26. package/dist/providers/claude/background-run-observer.d.ts +32 -0
  27. package/dist/providers/claude/background-run-observer.js +381 -0
  28. package/dist/providers/claude/cli-client.d.ts +12 -0
  29. package/dist/providers/claude/cli-client.js +453 -72
  30. package/dist/providers/claude/foreground-handoff.d.ts +4 -0
  31. package/dist/providers/claude/foreground-handoff.js +45 -0
  32. package/dist/providers/claude/task-cancellation-protocol.d.ts +14 -0
  33. package/dist/providers/claude/task-cancellation-protocol.js +21 -0
  34. package/dist/providers/codex/adapter.d.ts +1 -1
  35. package/dist/providers/codex/adapter.js +7 -0
  36. package/dist/providers/codex/cli-client.js +8 -7
  37. package/dist/providers/codex/project-doc.js +6 -6
  38. package/dist/providers/copilot/activity-metadata.d.ts +3 -0
  39. package/dist/providers/copilot/activity-metadata.js +19 -0
  40. package/dist/providers/copilot/adapter.d.ts +6 -2
  41. package/dist/providers/copilot/adapter.js +27 -1
  42. package/dist/providers/copilot/cli-client.d.ts +37 -10
  43. package/dist/providers/copilot/cli-client.js +756 -122
  44. package/dist/providers/copilot/sdk-session.d.ts +149 -0
  45. package/dist/providers/copilot/sdk-session.js +981 -0
  46. package/dist/providers/create-provider.js +33 -0
  47. package/dist/providers/provider-adapter.d.ts +24 -1
  48. package/dist/providers/provider-adapter.js +17 -0
  49. package/dist/types.d.ts +40 -11
  50. package/dist/vendor/claude-agent-acp/LICENSE +191 -0
  51. package/dist/vendor/claude-agent-acp/NOTICE +8 -0
  52. package/dist/vendor/claude-agent-acp/dist/acp-agent.d.ts +1017 -0
  53. package/dist/vendor/claude-agent-acp/dist/acp-agent.d.ts.map +1 -0
  54. package/dist/vendor/claude-agent-acp/dist/acp-agent.js +6305 -0
  55. package/dist/vendor/claude-agent-acp/dist/borgee-foreground-handoff-bridge.js +322 -0
  56. package/dist/vendor/claude-agent-acp/dist/borgee-task-cancellation-bridge.js +101 -0
  57. package/dist/vendor/claude-agent-acp/dist/borgee-task-lifecycle-bridge.js +58 -0
  58. package/dist/vendor/claude-agent-acp/dist/elicitation.d.ts +130 -0
  59. package/dist/vendor/claude-agent-acp/dist/elicitation.d.ts.map +1 -0
  60. package/dist/vendor/claude-agent-acp/dist/elicitation.js +304 -0
  61. package/dist/vendor/claude-agent-acp/dist/index.d.ts +3 -0
  62. package/dist/vendor/claude-agent-acp/dist/index.d.ts.map +1 -0
  63. package/dist/vendor/claude-agent-acp/dist/index.js +75 -0
  64. package/dist/vendor/claude-agent-acp/dist/lib.d.ts +6 -0
  65. package/dist/vendor/claude-agent-acp/dist/lib.d.ts.map +1 -0
  66. package/dist/vendor/claude-agent-acp/dist/lib.js +5 -0
  67. package/dist/vendor/claude-agent-acp/dist/settings.d.ts +68 -0
  68. package/dist/vendor/claude-agent-acp/dist/settings.d.ts.map +1 -0
  69. package/dist/vendor/claude-agent-acp/dist/settings.js +185 -0
  70. package/dist/vendor/claude-agent-acp/dist/tools.d.ts +102 -0
  71. package/dist/vendor/claude-agent-acp/dist/tools.d.ts.map +1 -0
  72. package/dist/vendor/claude-agent-acp/dist/tools.js +1000 -0
  73. package/dist/vendor/claude-agent-acp/dist/utils.d.ts +16 -0
  74. package/dist/vendor/claude-agent-acp/dist/utils.d.ts.map +1 -0
  75. package/dist/vendor/claude-agent-acp/dist/utils.js +81 -0
  76. package/dist/vendor/claude-agent-acp/package.json +85 -0
  77. package/package.json +15 -10
  78. package/skills/borgee-agent/references/task-properties.md +3 -3
  79. package/skills/borgee-agent/scripts/borgee-agent.mjs +1 -1
  80. package/skills/borgee-agent/scripts/borgee-agent.py +1 -1
  81. package/dist/context/resolved-workspace.d.ts +0 -3
  82. package/dist/context/resolved-workspace.js +0 -106
@@ -0,0 +1,4 @@
1
+ export declare const CLAUDE_FOREGROUND_HANDOFF_METHOD = "_borgee/session/foreground_handoff";
2
+ export declare const CLAUDE_FOREGROUND_LIFECYCLE_EVENT = "settled_with_background";
3
+ export declare function readClaudeForegroundSettledTurn(value: unknown): number | undefined;
4
+ export declare function isClaudeUpdateFromIsolatedTurn(value: unknown, isolationFence: number | undefined): boolean;
@@ -0,0 +1,45 @@
1
+ const NAMESPACE = 'claudeCode';
2
+ export const CLAUDE_FOREGROUND_HANDOFF_METHOD = '_borgee/session/foreground_handoff';
3
+ export const CLAUDE_FOREGROUND_LIFECYCLE_EVENT = 'settled_with_background';
4
+ function readClaudeProviderMetadata(value) {
5
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
6
+ return undefined;
7
+ }
8
+ const meta = value._meta;
9
+ if (typeof meta !== 'object' || meta === null || Array.isArray(meta)) {
10
+ return undefined;
11
+ }
12
+ const provider = meta[NAMESPACE];
13
+ if (typeof provider !== 'object' || provider === null || Array.isArray(provider)) {
14
+ return undefined;
15
+ }
16
+ return provider;
17
+ }
18
+ export function readClaudeForegroundSettledTurn(value) {
19
+ const provider = readClaudeProviderMetadata(value);
20
+ const lifecycle = provider?.foregroundLifecycle;
21
+ if (typeof lifecycle !== 'object' || lifecycle === null || Array.isArray(lifecycle)) {
22
+ return undefined;
23
+ }
24
+ if (lifecycle.event !== CLAUDE_FOREGROUND_LIFECYCLE_EVENT) {
25
+ return undefined;
26
+ }
27
+ const foregroundTurn = lifecycle.foregroundTurn;
28
+ return Number.isSafeInteger(foregroundTurn) && foregroundTurn > 0
29
+ ? foregroundTurn
30
+ : undefined;
31
+ }
32
+ export function isClaudeUpdateFromIsolatedTurn(value, isolationFence) {
33
+ if (isolationFence === undefined) {
34
+ return false;
35
+ }
36
+ const provider = readClaudeProviderMetadata(value);
37
+ if (!provider) {
38
+ return false;
39
+ }
40
+ const foregroundTurn = provider.foregroundTurn;
41
+ if (Number.isSafeInteger(foregroundTurn) && foregroundTurn > 0) {
42
+ return foregroundTurn <= isolationFence;
43
+ }
44
+ return provider.foregroundLane === 'background';
45
+ }
@@ -0,0 +1,14 @@
1
+ export declare const CLAUDE_TASK_CANCELLATION_METHOD = "_borgee/claude/task/cancel/v1";
2
+ export declare const CLAUDE_TASK_CANCELLATION_VERSION = 1;
3
+ export interface ClaudeTaskCancellationRequest {
4
+ sessionId: string;
5
+ taskId: string;
6
+ }
7
+ export type ClaudeTaskCancellationResponse = {
8
+ outcome: 'accepted';
9
+ } | {
10
+ outcome: 'not_found';
11
+ } | {
12
+ outcome: 'unsupported';
13
+ };
14
+ export declare function supportsClaudeTaskCancellation(response: unknown): boolean;
@@ -0,0 +1,21 @@
1
+ export const CLAUDE_TASK_CANCELLATION_METHOD = '_borgee/claude/task/cancel/v1';
2
+ export const CLAUDE_TASK_CANCELLATION_VERSION = 1;
3
+ export function supportsClaudeTaskCancellation(response) {
4
+ if (typeof response !== 'object' || response === null) {
5
+ return false;
6
+ }
7
+ const meta = response._meta;
8
+ if (typeof meta !== 'object' || meta === null) {
9
+ return false;
10
+ }
11
+ const borgee = meta.borgee;
12
+ if (typeof borgee !== 'object' || borgee === null) {
13
+ return false;
14
+ }
15
+ const capability = borgee.claudeTaskCancellation;
16
+ if (typeof capability !== 'object' || capability === null) {
17
+ return false;
18
+ }
19
+ return (capability.version === CLAUDE_TASK_CANCELLATION_VERSION
20
+ && capability.method === CLAUDE_TASK_CANCELLATION_METHOD);
21
+ }
@@ -7,7 +7,7 @@ export declare class CodexProviderAdapter implements ProviderAdapter {
7
7
  private readonly cli;
8
8
  private readonly turnPreparer;
9
9
  readonly capabilities: import("../provider-adapter.js").ProviderCapabilities;
10
- constructor(cli: CodexCliClient, turnPreparer: ProviderTurnPreparer);
10
+ constructor(cli: CodexCliClient, turnPreparer: Pick<ProviderTurnPreparer, 'prepare'>);
11
11
  generateReply(input: ProviderInput, options?: ProviderGenerateOptions): Promise<ProviderReply>;
12
12
  cancelTurn(channelId: string): Promise<boolean>;
13
13
  dispose(): Promise<void>;
@@ -7,6 +7,13 @@ export const CODEX_HOSTED_PROVIDER_CAPABILITIES = createHostedProviderCapabiliti
7
7
  reason: 'real-media-delivered',
8
8
  delivery: ['blob'],
9
9
  },
10
+ progressUpdates: {
11
+ support: 'supported',
12
+ },
13
+ backgroundRuns: {
14
+ lifecycle: 'not-supported',
15
+ targetedCancellation: 'not-supported',
16
+ },
10
17
  });
11
18
  export class CodexProviderAdapter {
12
19
  cli;
@@ -9,7 +9,7 @@ import { AcpProgressCollector } from '../acp-progress-collector.js';
9
9
  import { ProviderTurnCancelledError } from '../provider-adapter.js';
10
10
  import { assertCodexProjectDocumentSize, buildCodexProjectDocument } from './project-doc.js';
11
11
  import { isGatewayCredentialSidecarBasename } from '../../context/injection.js';
12
- import { isDiscussionOnlyResolvedWorkspace } from '../../context/resolved-workspace.js';
12
+ import { isDiscussionOnlyResolvedWorkingFolder } from '../../context/resolved-working-folder.js';
13
13
  import { resolveCopilotPermissionResponse } from '../../policy/copilot-permission.js';
14
14
  import { IDLE_BACKEND_SHUTDOWN_DISABLED_MS, IdleBackendShutdownScheduler, } from '../idle-backend-shutdown.js';
15
15
  const SESSION_TAINTED_ERRORS = new WeakSet();
@@ -488,7 +488,7 @@ export class CodexCliClient {
488
488
  state.activeTurn = turn;
489
489
  try {
490
490
  state.cwd = await this.resolveSessionCwd(turn.preparedTurn.promptContext);
491
- state.toolPermissionMode = isDiscussionOnlyResolvedWorkspace(turn.preparedTurn.promptContext)
491
+ state.toolPermissionMode = isDiscussionOnlyResolvedWorkingFolder(turn.preparedTurn.promptContext)
492
492
  ? 'deny-all'
493
493
  : 'default';
494
494
  const projectedPromptContext = await this.refreshProjectedPromptContextBestEffort(turn.channelId, turn.preparedTurn.promptContext);
@@ -658,7 +658,7 @@ export class CodexCliClient {
658
658
  }
659
659
  }
660
660
  async resolveSessionCwd(promptContext) {
661
- return promptContext?.resolvedWorkspace?.rootPath ?? this.runtime.cwd;
661
+ return promptContext?.resolvedWorkingFolder?.rootPath ?? this.runtime.cwd;
662
662
  }
663
663
  async recycleSessionIfInjectionScopeChanged(channelId, state) {
664
664
  const session = state.session;
@@ -969,7 +969,9 @@ export class CodexCliClient {
969
969
  policyMode: 'enforce',
970
970
  params,
971
971
  logger: this.logger,
972
+ agentId: this.resolveSessionStoreAgentId()?.trim() || undefined,
972
973
  channelId: state?.channelId,
974
+ sessionBound: state !== undefined,
973
975
  toolPermissionMode: state?.toolPermissionMode ?? 'default',
974
976
  });
975
977
  }
@@ -1136,6 +1138,7 @@ export class CodexCliClient {
1136
1138
  this.closeSession(session);
1137
1139
  }
1138
1140
  this.channels.delete(channelId);
1141
+ this.idleBackendShutdown.reconcile();
1139
1142
  }
1140
1143
  async shutdownBackend(error) {
1141
1144
  if (this.backendClosed) {
@@ -1194,10 +1197,8 @@ export class CodexCliClient {
1194
1197
  if (this.pendingSessionStarts.size > 0) {
1195
1198
  return false;
1196
1199
  }
1197
- for (const state of this.channels.values()) {
1198
- if (state.activeTurn || state.queue.length > 0 || state.sessionPromise || state.processing) {
1199
- return false;
1200
- }
1200
+ if (this.channels.size > 0) {
1201
+ return false;
1201
1202
  }
1202
1203
  return true;
1203
1204
  }
@@ -2,12 +2,12 @@ import { buildAttentionSummaryLines } from '../../context/attention.js';
2
2
  import { buildCollaborationCapabilityDeclarationSummaryLines, buildMissedCollaborationDiagnosticSummaryLines, } from '../../context/collaboration-capabilities-diagnostics.js';
3
3
  import { buildCollaborationOutcomeSummaryLines } from '../../context/collaboration-outcome.js';
4
4
  import { MAIN_SESSION_DELEGATION_LINES } from '../../context/main-session-delegation.js';
5
- import { buildResolvedWorkspaceGuidanceLines } from '../../context/resolved-workspace.js';
5
+ import { buildResolvedWorkingFolderGuidanceLines } from '../../context/resolved-working-folder.js';
6
6
  import { buildSkillManualLines, buildSkillManualReadLine } from '../../context/skill-manual.js';
7
7
  import { buildTaskThreadCollaborationSummaryLines } from '../../context/task-thread-collaboration.js';
8
8
  const PROJECT_DOC_MAX_BYTES = 32 * 1024;
9
9
  // Every command the CLI carries needs the gateway credential file, so the capability is only
10
- // worth naming in a workspace that also names one; otherwise the model is handed an invocation
10
+ // worth naming in a project document that also names one; otherwise the model is handed an invocation
11
11
  // template it cannot fill.
12
12
  function buildSkillRuntimeLines(context) {
13
13
  if (!context?.skillRuntime) {
@@ -29,15 +29,15 @@ function buildGatewayCredentialLines(context) {
29
29
  export function buildCodexProjectDocument(context) {
30
30
  const sessionDelegationLines = context?.skillRuntime ? [] : MAIN_SESSION_DELEGATION_LINES;
31
31
  const lines = [
32
- '# Borgee channel workspace',
32
+ '# Borgee channel session',
33
33
  '',
34
- 'This workspace belongs to one Borgee channel session hosted by agents-host.',
34
+ 'This directory belongs to one Borgee channel session hosted by agents-host.',
35
35
  'Keep visible replies concise, do not claim actions you did not perform, and prefer the per-turn prompt when it provides newer turn-local details.',
36
36
  '',
37
37
  ...sessionDelegationLines,
38
38
  ...(() => {
39
- const workspaceLines = buildResolvedWorkspaceGuidanceLines(context);
40
- return workspaceLines.length > 0 ? ['', ...workspaceLines] : [];
39
+ const workingFolderLines = buildResolvedWorkingFolderGuidanceLines(context);
40
+ return workingFolderLines.length > 0 ? ['', ...workingFolderLines] : [];
41
41
  })(),
42
42
  ...(() => {
43
43
  const collaborationOutcomeLines = buildCollaborationOutcomeSummaryLines(context?.collaborationOutcome);
@@ -0,0 +1,3 @@
1
+ import type { ProgressActivity, ProviderBackgroundRunProgress } from '../../types.js';
2
+ /** Registry state describes background work, never a wait on the foreground turn. */
3
+ export declare function toCopilotBackgroundActivity(sessionId: string, run: ProviderBackgroundRunProgress): ProgressActivity;
@@ -0,0 +1,19 @@
1
+ /** Registry state describes background work, never a wait on the foreground turn. */
2
+ export function toCopilotBackgroundActivity(sessionId, run) {
3
+ const active = run.state === 'running' || run.state === 'waiting';
4
+ return {
5
+ id: `copilot-background:${sessionId}:${run.providerRunId}:${run.startedAt ?? 0}`,
6
+ label: run.label,
7
+ kind: 'other',
8
+ status: run.state === 'waiting' ? 'waiting'
9
+ : active ? 'in_progress'
10
+ : run.state === 'completed' ? 'completed' : 'failed',
11
+ subagent: true,
12
+ background: true,
13
+ backgroundState: run.state === 'cancelled' || run.state === 'unknown' ? 'failed' : run.state,
14
+ followUpControl: run.state === 'cancelled' || run.state === 'unknown'
15
+ ? 'unavailable' : 'same-session-required',
16
+ reason: run.reason ?? (run.state === 'cancelled' ? 'Cancelled'
17
+ : run.state === 'unknown' ? 'Final background state unavailable' : undefined),
18
+ };
19
+ }
@@ -1,5 +1,5 @@
1
1
  import { type ProviderAdapter } from '../provider-adapter.js';
2
- import type { ProviderGenerateOptions, ProviderInput, ProviderReply } from '../../types.js';
2
+ import type { ProviderAutonomousReply, ProviderGenerateOptions, ProviderInput, ProviderReply } from '../../types.js';
3
3
  import { ProviderTurnPreparer } from '../../context/turn-preparation.js';
4
4
  import { CopilotCliClient } from './cli-client.js';
5
5
  export declare const COPILOT_HOSTED_PROVIDER_CAPABILITIES: import("../provider-adapter.js").ProviderCapabilities;
@@ -7,8 +7,12 @@ export declare class CopilotProviderAdapter implements ProviderAdapter {
7
7
  private readonly cli;
8
8
  private readonly turnPreparer;
9
9
  readonly capabilities: import("../provider-adapter.js").ProviderCapabilities;
10
- constructor(cli: CopilotCliClient, turnPreparer: ProviderTurnPreparer);
10
+ constructor(cli: CopilotCliClient, turnPreparer: Pick<ProviderTurnPreparer, 'prepare'>);
11
11
  generateReply(input: ProviderInput, options?: ProviderGenerateOptions): Promise<ProviderReply>;
12
+ onAutonomousReply(handler: ((reply: ProviderAutonomousReply) => void) | undefined): void;
12
13
  cancelTurn(channelId: string): Promise<boolean>;
14
+ interruptTurn(channelId: string): Promise<boolean>;
15
+ cancelSession(channelId: string): Promise<boolean>;
16
+ cancelBackgroundRun(channelId: string, providerRunId: string): Promise<boolean>;
13
17
  dispose(): Promise<void>;
14
18
  }
@@ -7,6 +7,13 @@ export const COPILOT_HOSTED_PROVIDER_CAPABILITIES = createHostedProviderCapabili
7
7
  reason: 'real-media-delivered',
8
8
  delivery: ['blob'],
9
9
  },
10
+ progressUpdates: {
11
+ support: 'supported',
12
+ },
13
+ backgroundRuns: {
14
+ lifecycle: 'supported',
15
+ targetedCancellation: 'supported',
16
+ },
10
17
  });
11
18
  export class CopilotProviderAdapter {
12
19
  cli;
@@ -25,8 +32,27 @@ export class CopilotProviderAdapter {
25
32
  // session as it runs, so before this point there is nothing to report.
26
33
  return { ...parseProviderReply(text), sessionId: this.cli.sessionIdForChannel(input.channelId) };
27
34
  }
35
+ onAutonomousReply(handler) {
36
+ this.cli.onAutonomousReply(handler
37
+ ? (reply) => {
38
+ const parsed = parseProviderReply(reply.text);
39
+ if (parsed.text.trim()) {
40
+ handler({ ...reply, text: parsed.text });
41
+ }
42
+ }
43
+ : undefined);
44
+ }
28
45
  async cancelTurn(channelId) {
29
- return this.cli.cancelTurn(channelId);
46
+ return this.cli.cancelSession(channelId);
47
+ }
48
+ async interruptTurn(channelId) {
49
+ return this.cli.interruptTurn(channelId);
50
+ }
51
+ async cancelSession(channelId) {
52
+ return this.cli.cancelSession(channelId);
53
+ }
54
+ async cancelBackgroundRun(channelId, providerRunId) {
55
+ return this.cli.cancelBackgroundRun(channelId, providerRunId);
30
56
  }
31
57
  async dispose() {
32
58
  await this.cli.dispose();
@@ -3,9 +3,12 @@ import { PROTOCOL_VERSION, client, methods, ndJsonStream } from '@agentclientpro
3
3
  import { type DebugLogger } from '../../debug.js';
4
4
  import type { InternalPolicyMode } from '../../compatibility-gates.js';
5
5
  import type { AuthorizationAuditSinkLike } from '../../policy/authorization-audit.js';
6
- import type { PreparedProviderTurnInput, ProviderGenerateOptions } from '../../types.js';
6
+ import type { PreparedProviderTurnInput, ProviderAutonomousReply, ProviderGenerateOptions } from '../../types.js';
7
7
  import type { CopilotChannelSessionStore } from './session-store.js';
8
- interface CopilotAcpRuntime {
8
+ import { type CopilotSdkClientFactory } from './sdk-session.js';
9
+ interface CopilotRuntime {
10
+ transport: 'sdk' | 'acp';
11
+ createSdkClient: CopilotSdkClientFactory;
9
12
  spawn: typeof spawn;
10
13
  client: typeof client;
11
14
  ndJsonStream: typeof ndJsonStream;
@@ -15,6 +18,7 @@ interface CopilotAcpRuntime {
15
18
  idleSessionTtlMs: number;
16
19
  idleBackendShutdownMs: number;
17
20
  idleShutdownGracePeriodMs: number;
21
+ sessionCloseTimeoutMs: number;
18
22
  shutdownGracePeriodMs: number;
19
23
  shutdownForceKillWaitMs: number;
20
24
  fetch(input: string | URL, init?: RequestInit): Promise<Response>;
@@ -29,12 +33,12 @@ interface CopilotHostedImageInputConfig {
29
33
  agentApiKey?: string;
30
34
  }
31
35
  /**
32
- * Persistent ACP-backed client for the GitHub Copilot CLI (`copilot --acp`).
36
+ * Persistent session client for the GitHub Copilot CLI.
33
37
  *
34
- * The legacy one-shot `COPILOT_ARGS` / constructor args are intentionally
35
- * ignored here: the prototype always launches the child as `copilot --acp`,
36
- * performs the ACP initialize handshake once, then reuses one ACP session per
37
- * Borgee channel for the process lifetime.
38
+ * Production uses the Copilot SDK headless JSON-RPC transport. The ACP runtime
39
+ * remains injectable for compatibility tests. Both paths reuse one provider
40
+ * session per Borgee channel because the background-agent registry belongs to
41
+ * that session and later read_agent/write_agent turns must keep that identity.
38
42
  */
39
43
  export declare class CopilotCliClient {
40
44
  private readonly command;
@@ -45,15 +49,21 @@ export declare class CopilotCliClient {
45
49
  private readonly imageInputConfig;
46
50
  private readonly runtime;
47
51
  private readonly channels;
52
+ private readonly channelWorkerRoutes;
53
+ private readonly sessionAuthorizationLeases;
48
54
  /**
49
55
  * The provider session currently bound to channelId, or undefined before a
50
56
  * turn has opened one. Surfaced so agents-host can record which session
51
57
  * worked a task without the agent being asked to report its own id.
52
58
  */
53
59
  sessionIdForChannel(channelId: string): string | undefined;
60
+ interruptTurn(channelId: string): Promise<boolean>;
61
+ cancelSession(channelId: string): Promise<boolean>;
54
62
  cancelTurn(channelId: string): Promise<boolean>;
63
+ cancelBackgroundRun(channelId: string, providerRunId: string): Promise<boolean>;
55
64
  private readonly persistedSessions;
56
65
  private readonly closingSessions;
66
+ private readonly orphanedSessions;
57
67
  private readonly pendingSessionStarts;
58
68
  private readonly pendingSessionCloses;
59
69
  private readonly pendingSessionStoreOperations;
@@ -61,6 +71,7 @@ export declare class CopilotCliClient {
61
71
  private rejectFatalPromise;
62
72
  private child?;
63
73
  private connection?;
74
+ private sdkClient?;
64
75
  private startPromise?;
65
76
  private shutdownPromise?;
66
77
  private childExitPromise?;
@@ -71,6 +82,7 @@ export declare class CopilotCliClient {
71
82
  */
72
83
  private backendGeneration;
73
84
  private idleShutdownPromise?;
85
+ private backendShutdownInProgress;
74
86
  private fatalError;
75
87
  private disposing;
76
88
  private backendClosed;
@@ -78,19 +90,25 @@ export declare class CopilotCliClient {
78
90
  private sessionStoreLoadPromise;
79
91
  private sessionStoreWriteQueue;
80
92
  private sessionCapabilities;
93
+ private backendRecycleRequired;
94
+ private autonomousReplyHandler?;
81
95
  private readonly idleBackendShutdown;
82
- constructor(command: string, _ignoredArgs?: string[], runtimeOverrides?: Partial<CopilotAcpRuntime>, sessionStore?: CopilotChannelSessionStore | undefined, resolveSessionStoreAgentId?: () => string | undefined, logger?: DebugLogger, permissionPolicy?: CopilotPermissionPolicyOptions, imageInputConfig?: CopilotHostedImageInputConfig);
96
+ constructor(command: string, _ignoredArgs?: string[], runtimeOverrides?: Partial<CopilotRuntime>, sessionStore?: CopilotChannelSessionStore | undefined, resolveSessionStoreAgentId?: () => string | undefined, logger?: DebugLogger, permissionPolicy?: CopilotPermissionPolicyOptions, imageInputConfig?: CopilotHostedImageInputConfig);
83
97
  generateReply(turn: PreparedProviderTurnInput, options?: ProviderGenerateOptions): Promise<string>;
84
98
  generateReply(channelId: string, prompt: string, options?: ProviderGenerateOptions): Promise<string>;
99
+ onAutonomousReply(handler: ((reply: ProviderAutonomousReply) => void) | undefined): void;
85
100
  dispose(): Promise<void>;
86
101
  private ensureStarted;
87
102
  private startBackend;
103
+ private startSdkBackend;
88
104
  private getOrCreateChannelState;
105
+ private resolveChannelState;
89
106
  private processChannelQueue;
90
107
  private getOrCreateSession;
91
108
  private startFreshSession;
92
109
  private restoreOrCreateSession;
93
110
  private restoreSession;
111
+ private createSdkSessionAdapter;
94
112
  private clearBufferedSessionReplay;
95
113
  private resolveSessionCwd;
96
114
  private buildPromptInput;
@@ -99,15 +117,21 @@ export declare class CopilotCliClient {
99
117
  private runTurn;
100
118
  private raceWithFatal;
101
119
  private handlePermissionRequest;
120
+ private handleSdkPermissionRequest;
102
121
  private failAll;
103
122
  private invalidateSession;
104
123
  private closeSession;
124
+ private markSessionOrphaned;
105
125
  private rejectQueuedTurnsAfterSessionTaint;
106
126
  private clearIdleTimer;
107
- private findChannelStateBySessionId;
127
+ private bindSessionAuthorization;
128
+ private promoteWorkerRoute;
129
+ private releaseWorkerRoute;
130
+ private releaseInactiveWorkerRoute;
108
131
  private reconcileIdleChannelState;
109
132
  private ensureSessionStoreLoaded;
110
133
  private readPersistedSessionId;
134
+ private isPersistentRouteOwner;
111
135
  private persistSession;
112
136
  private persistSessionBestEffort;
113
137
  private clearPersistedSession;
@@ -119,14 +143,17 @@ export declare class CopilotCliClient {
119
143
  /**
120
144
  * Backend teardown without the fatal latch: the client stays usable and
121
145
  * `ensureStarted()` spawns a replacement process on the next turn. Only safe
122
- * while `isBackendIdle()` holds, because every channel's live ACP session is
146
+ * while `isBackendIdle()` holds, because every channel's live session is
123
147
  * dropped here and no turn is ever replayed onto its successor.
124
148
  */
125
149
  private shutdownIdleBackend;
126
150
  private isBackendIdle;
151
+ private reconcileBackendLifecycle;
152
+ private releaseBackendAuthorizationLeases;
127
153
  private closeBackendProcess;
128
154
  private waitForPendingSessionStarts;
129
155
  private waitForPendingSessionCloses;
156
+ private waitForSessionClose;
130
157
  private waitForChildExit;
131
158
  }
132
159
  export {};