@bbigbang/runtime-acp 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ import type { Db } from './db.js';
2
+ import type { UiMode } from '../gateway/types.js';
3
+ export declare function getUiMode(db: Db, bindingKey: string): UiMode | null;
4
+ export declare function setUiMode(db: Db, bindingKey: string, mode: UiMode): void;
@@ -0,0 +1,18 @@
1
+ export function getUiMode(db, bindingKey) {
2
+ const row = db
3
+ .prepare('SELECT mode FROM ui_prefs WHERE binding_key = ?')
4
+ .get(bindingKey);
5
+ if (!row)
6
+ return null;
7
+ return row.mode === 'summary' ? 'summary' : 'verbose';
8
+ }
9
+ export function setUiMode(db, bindingKey, mode) {
10
+ const now = Date.now();
11
+ db.prepare(`
12
+ INSERT INTO ui_prefs(binding_key, mode, created_at, updated_at)
13
+ VALUES(?, ?, ?, ?)
14
+ ON CONFLICT(binding_key) DO UPDATE SET
15
+ mode = excluded.mode,
16
+ updated_at = excluded.updated_at
17
+ `).run(bindingKey, mode, now, now);
18
+ }
@@ -0,0 +1,113 @@
1
+ import type { Db } from '../db/db.js';
2
+ import type { OutboundSink, UiMode } from './types.js';
3
+ export interface RuntimeConfig {
4
+ acpAgentCommand: string;
5
+ acpAgentArgs: string[];
6
+ acpPromptTimeoutMs: number;
7
+ uiJsonMaxChars: number;
8
+ }
9
+ import { type PermissionRequest } from '../acp/client.js';
10
+ import type { InitializeResult, McpServerEntry } from '../acp/types.js';
11
+ import { ToolAuth, type ToolKind } from './toolAuth.js';
12
+ import type { WorkspaceLockManager } from '../runtime/workspaceLockManager.js';
13
+ export declare class BindingRuntime {
14
+ private readonly db;
15
+ private readonly config;
16
+ private readonly toolAuth;
17
+ private readonly sessionKey;
18
+ private readonly bindingKey;
19
+ private readonly client;
20
+ private init;
21
+ private acpSessionId;
22
+ private sessionSystemPromptText;
23
+ private queue;
24
+ private activeSink;
25
+ private pendingPermission;
26
+ private pendingPermissionActorUserId;
27
+ private currentRunId;
28
+ private currentRunLastSeq;
29
+ private currentUiMode;
30
+ private currentActorUserId;
31
+ private sinkWriteQueue;
32
+ private toolCallTitles;
33
+ private toolCallTextBreaks;
34
+ private readonly workspaceRoot;
35
+ private readonly agentCommand;
36
+ private readonly agentArgs;
37
+ private readonly env?;
38
+ private activeDisabledToolKinds;
39
+ private readonly channelBridgeMcpEntry?;
40
+ constructor(params: {
41
+ db: Db;
42
+ config: RuntimeConfig;
43
+ toolAuth: ToolAuth;
44
+ sessionKey: string;
45
+ bindingKey: string;
46
+ workspaceRoot: string;
47
+ agentCommand?: string;
48
+ agentArgs?: string[];
49
+ env?: Record<string, string>;
50
+ disabledToolKinds?: ToolKind[];
51
+ acpRpc?: import('../acp/stdio.js').StdioProcess;
52
+ channelBridgeMcpEntry?: McpServerEntry;
53
+ workspaceLockManager?: WorkspaceLockManager;
54
+ });
55
+ close(): void;
56
+ private setActiveDisabledToolKinds;
57
+ private isToolKindDisabled;
58
+ private enqueueSinkWrite;
59
+ private flushSinkWriteQueue;
60
+ ensureInitialized(): Promise<InitializeResult>;
61
+ ensureSessionId(): Promise<string>;
62
+ ensureSessionIdWithPrompt(systemPromptText?: string): Promise<string>;
63
+ getLoadSupported(): boolean;
64
+ getPendingPermission(): PermissionRequest | null;
65
+ selectPermissionOption(idx: number, sink: OutboundSink, actorUserId?: string): Promise<void>;
66
+ hasSessionId(): boolean;
67
+ decidePermission(params: {
68
+ decision: 'allow' | 'deny';
69
+ requestId?: string;
70
+ actorUserId?: string;
71
+ }): Promise<{
72
+ ok: boolean;
73
+ message: string;
74
+ }>;
75
+ denyPermission(sink: OutboundSink, actorUserId?: string): Promise<void>;
76
+ respondToPermission(requestId: string, decision: 'allow' | 'deny', actorUserId?: string): Promise<boolean>;
77
+ hasPendingPermission(): boolean;
78
+ cancelCurrentRun(runId?: string): Promise<boolean>;
79
+ private resetAcpSession;
80
+ private promptOnce;
81
+ prompt(params: {
82
+ runId: string;
83
+ promptText: string;
84
+ promptResources?: Array<{
85
+ uri: string;
86
+ mimeType?: string;
87
+ }>;
88
+ sink: OutboundSink;
89
+ uiMode: UiMode;
90
+ disabledToolKinds?: ToolKind[];
91
+ systemPromptText?: string;
92
+ contextText?: string;
93
+ resumeContextText?: string;
94
+ recoveryContextText?: string;
95
+ actorUserId?: string;
96
+ onPrepared?: (prepared: {
97
+ sessionId: string;
98
+ isFreshSession: boolean;
99
+ effectiveSystemPromptText?: string;
100
+ effectiveContextText?: string;
101
+ }) => void | Promise<void>;
102
+ }): Promise<{
103
+ stopReason: string;
104
+ lastSeq: number;
105
+ isFreshSession: boolean;
106
+ sessionId: string;
107
+ effectiveSystemPromptText?: string;
108
+ effectiveContextText?: string;
109
+ }>;
110
+ private isPermissionActorAuthorized;
111
+ private buildToolUiEvent;
112
+ private shouldBreakTextStreamForToolUpdate;
113
+ }