lark-remote 0.1.6 → 0.1.8
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/CHANGELOG.md +51 -1
- package/README.en.md +9 -1
- package/README.md +14 -2
- package/dist/bridge/approval-coordinator.d.ts +71 -34
- package/dist/bridge/approval-coordinator.js +225 -41
- package/dist/bridge/inbound-media.d.ts +62 -0
- package/dist/bridge/inbound-media.js +282 -0
- package/dist/bridge/index.d.ts +97 -13
- package/dist/bridge/index.js +227 -87
- package/dist/bridge/queue-manager.d.ts +2 -1
- package/dist/bridge/queue-manager.js +1 -0
- package/dist/card/approval-render.js +294 -36
- package/dist/card/bash-card-session.d.ts +2 -24
- package/dist/card/bash-card-session.js +6 -73
- package/dist/card/bash-renderer.js +2 -3
- package/dist/card/card-budget.js +29 -75
- package/dist/card/card-session.d.ts +48 -0
- package/dist/card/card-session.js +86 -0
- package/dist/card/card-shared.d.ts +7 -16
- package/dist/card/card-shared.js +7 -30
- package/dist/card/run-card-session.d.ts +2 -55
- package/dist/card/run-card-session.js +6 -104
- package/dist/card/run-renderer.d.ts +7 -0
- package/dist/card/run-renderer.js +116 -238
- package/dist/card/run-state.d.ts +13 -0
- package/dist/card/run-state.js +25 -16
- package/dist/card/text-truncate.d.ts +13 -12
- package/dist/card/text-truncate.js +13 -63
- package/dist/common/fs.d.ts +8 -0
- package/dist/common/fs.js +17 -0
- package/dist/common/guards.d.ts +0 -20
- package/dist/common/guards.js +0 -43
- package/dist/common/sleep.d.ts +2 -0
- package/dist/common/sleep.js +5 -0
- package/dist/common/truncate.d.ts +39 -0
- package/dist/common/truncate.js +92 -0
- package/dist/config/codex-config.d.ts +1 -1
- package/dist/config/codex-config.js +1 -1
- package/dist/config/index.d.ts +112 -24
- package/dist/config/index.js +139 -37
- package/dist/connector/index.d.ts +69 -2
- package/dist/connector/index.js +107 -1
- package/dist/index.js +150 -118
- package/dist/instance-lock.js +4 -12
- package/dist/order/alias-resolve.d.ts +13 -0
- package/dist/order/alias-resolve.js +22 -0
- package/dist/order/alias-store.d.ts +38 -0
- package/dist/order/alias-store.js +106 -0
- package/dist/persistence/atomic-write.d.ts +8 -2
- package/dist/persistence/atomic-write.js +23 -7
- package/dist/restart.js +2 -1
- package/dist/router/card-action-payload.d.ts +30 -0
- package/dist/router/card-action-payload.js +39 -0
- package/dist/router/card-helpers.d.ts +63 -0
- package/dist/router/card-helpers.js +146 -0
- package/dist/router/config/claude.js +30 -1
- package/dist/router/config/codex.js +29 -50
- package/dist/router/config/common/model-patch.d.ts +22 -0
- package/dist/router/config/common/model-patch.js +26 -0
- package/dist/router/config/common/render.js +5 -4
- package/dist/router/config/dsh.d.ts +51 -0
- package/dist/router/config/dsh.js +179 -0
- package/dist/router/config/index.d.ts +12 -0
- package/dist/router/config/index.js +28 -1
- package/dist/router/config/kimi.d.ts +4 -1
- package/dist/router/config/kimi.js +27 -0
- package/dist/router/config/opencode.js +18 -5
- package/dist/router/config/pi.js +4 -5
- package/dist/router/config/types.d.ts +17 -2
- package/dist/router/index.d.ts +76 -22
- package/dist/router/index.js +479 -548
- package/dist/router/utils.d.ts +2 -0
- package/dist/router/utils.js +16 -2
- package/dist/runner/agent-choices-common.d.ts +16 -0
- package/dist/runner/agent-choices-common.js +34 -0
- package/dist/runner/claude/runner.d.ts +47 -10
- package/dist/runner/claude/runner.js +117 -46
- package/dist/runner/claude/session.d.ts +166 -0
- package/dist/runner/claude/session.js +768 -0
- package/dist/runner/codex/app-server/protocol-types.d.ts +66 -39
- package/dist/runner/codex/app-server/protocol-types.js +2 -13
- package/dist/runner/codex/app-server/runner.d.ts +52 -59
- package/dist/runner/codex/app-server/runner.js +216 -338
- package/dist/runner/codex/app-server/translator.d.ts +8 -21
- package/dist/runner/codex/app-server/translator.js +45 -18
- package/dist/runner/codex/index.d.ts +0 -2
- package/dist/runner/codex/index.js +0 -2
- package/dist/runner/common/acp/protocol-helpers.d.ts +14 -0
- package/dist/runner/common/acp/protocol-helpers.js +21 -0
- package/dist/runner/common/acp/protocol-types.d.ts +271 -0
- package/dist/runner/common/acp/protocol-types.js +77 -0
- package/dist/runner/common/connection-based-runner.d.ts +111 -0
- package/dist/runner/common/connection-based-runner.js +261 -0
- package/dist/runner/{codex/app-server → common/jsonrpc}/client.d.ts +14 -7
- package/dist/runner/{codex/app-server → common/jsonrpc}/client.js +27 -18
- package/dist/runner/common/jsonrpc/connection-manager.d.ts +125 -0
- package/dist/runner/{codex/app-server → common/jsonrpc}/connection-manager.js +63 -28
- package/dist/runner/{codex/app-server → common/jsonrpc}/transport.d.ts +5 -4
- package/dist/runner/{codex/app-server → common/jsonrpc}/transport.js +18 -19
- package/dist/runner/common/jsonrpc/types.d.ts +32 -0
- package/dist/runner/common/jsonrpc/types.js +9 -0
- package/dist/runner/common/process-stopper.d.ts +2 -1
- package/dist/runner/common/process-stopper.js +1 -0
- package/dist/runner/common/runner-utils.d.ts +6 -13
- package/dist/runner/common/runner-utils.js +6 -47
- package/dist/runner/common/spawning-runner.d.ts +24 -70
- package/dist/runner/common/spawning-runner.js +98 -152
- package/dist/runner/dsh/client.d.ts +95 -0
- package/dist/runner/dsh/client.js +418 -0
- package/dist/runner/dsh/fake-dsh-server.d.ts +60 -0
- package/dist/runner/dsh/fake-dsh-server.js +156 -0
- package/dist/runner/dsh/index.d.ts +3 -0
- package/dist/runner/dsh/index.js +4 -0
- package/dist/runner/dsh/runner.d.ts +57 -0
- package/dist/runner/dsh/runner.js +191 -0
- package/dist/runner/dsh/translator.d.ts +28 -0
- package/dist/runner/dsh/translator.js +98 -0
- package/dist/runner/dsh/types.d.ts +155 -0
- package/dist/runner/dsh/types.js +14 -0
- package/dist/runner/index.d.ts +5 -4
- package/dist/runner/index.js +5 -4
- package/dist/runner/kimi/acp/runner.d.ts +106 -0
- package/dist/runner/kimi/acp/runner.js +516 -0
- package/dist/runner/kimi/acp/translator.d.ts +138 -0
- package/dist/runner/kimi/acp/translator.js +441 -0
- package/dist/runner/kimi/index.d.ts +1 -1
- package/dist/runner/kimi/index.js +1 -1
- package/dist/runner/opencode/acp/index.d.ts +1 -0
- package/dist/runner/opencode/acp/index.js +2 -0
- package/dist/runner/opencode/acp/runner.d.ts +121 -0
- package/dist/runner/opencode/acp/runner.js +429 -0
- package/dist/runner/opencode/acp/translator.d.ts +119 -0
- package/dist/runner/opencode/acp/translator.js +345 -0
- package/dist/runner/opencode/index.d.ts +1 -1
- package/dist/runner/opencode/index.js +1 -1
- package/dist/runner/pi/index.d.ts +1 -1
- package/dist/runner/pi/index.js +1 -1
- package/dist/runner/pi/rpc/client.d.ts +52 -0
- package/dist/runner/pi/rpc/client.js +114 -0
- package/dist/runner/pi/rpc/index.d.ts +4 -0
- package/dist/runner/pi/rpc/index.js +4 -0
- package/dist/runner/pi/rpc/protocol-types.d.ts +127 -0
- package/dist/runner/pi/rpc/protocol-types.js +21 -0
- package/dist/runner/pi/rpc/runner.d.ts +74 -0
- package/dist/runner/pi/rpc/runner.js +190 -0
- package/dist/runner/pi/rpc/translator.d.ts +55 -0
- package/dist/runner/pi/rpc/translator.js +258 -0
- package/dist/runner/probe.js +6 -1
- package/dist/runner/question-common.d.ts +26 -0
- package/dist/runner/question-common.js +42 -0
- package/dist/runner/registry.d.ts +7 -8
- package/dist/runner/registry.js +3 -4
- package/dist/runner/resolve-agent-choices.js +18 -59
- package/dist/runner/sync-agent-choices.js +16 -67
- package/dist/runner/types.d.ts +97 -14
- package/dist/session/claude/session-index.js +2 -3
- package/dist/session/claude/session-reader.js +3 -6
- package/dist/session/claude/sessions.js +43 -28
- package/dist/session/codex/rollout-reader.d.ts +2 -2
- package/dist/session/codex/rollout-reader.js +14 -17
- package/dist/session/codex/sessions.d.ts +1 -1
- package/dist/session/codex/sessions.js +2 -2
- package/dist/session/common/content-blocks.d.ts +7 -0
- package/dist/session/common/content-blocks.js +13 -9
- package/dist/session/common/jsonl.d.ts +8 -25
- package/dist/session/common/jsonl.js +126 -261
- package/dist/session/common/pagination.d.ts +28 -0
- package/dist/session/common/pagination.js +33 -0
- package/dist/session/dsh/index.d.ts +1 -0
- package/dist/session/dsh/index.js +2 -0
- package/dist/session/dsh/sessions.d.ts +39 -0
- package/dist/session/dsh/sessions.js +237 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.js +1 -0
- package/dist/session/kimi/sessions.d.ts +34 -1
- package/dist/session/kimi/sessions.js +208 -98
- package/dist/session/opencode/sessions.d.ts +17 -3
- package/dist/session/opencode/sessions.js +29 -29
- package/dist/session/pi/sessions.d.ts +5 -1
- package/dist/session/pi/sessions.js +12 -16
- package/dist/session/session-store.d.ts +11 -1
- package/dist/session/session-store.js +75 -178
- package/dist/update/index.d.ts +2 -2
- package/dist/update/index.js +2 -2
- package/dist/update/install.d.ts +20 -2
- package/dist/update/install.js +51 -7
- package/dist/workspace/index.d.ts +4 -0
- package/dist/workspace/index.js +8 -1
- package/package.json +2 -1
- package/dist/runner/codex/app-server/connection-manager.d.ts +0 -56
- package/dist/runner/codex/argv.d.ts +0 -33
- package/dist/runner/codex/argv.js +0 -40
- package/dist/runner/codex/factory.d.ts +0 -29
- package/dist/runner/codex/factory.js +0 -39
- package/dist/runner/codex/jsonl.d.ts +0 -37
- package/dist/runner/codex/jsonl.js +0 -221
- package/dist/runner/codex/runner.d.ts +0 -66
- package/dist/runner/codex/runner.js +0 -129
- package/dist/runner/common/exec-translator.d.ts +0 -73
- package/dist/runner/common/exec-translator.js +0 -105
- package/dist/runner/kimi/jsonl.d.ts +0 -28
- package/dist/runner/kimi/jsonl.js +0 -143
- package/dist/runner/kimi/runner.d.ts +0 -49
- package/dist/runner/kimi/runner.js +0 -105
- package/dist/runner/opencode/argv.d.ts +0 -32
- package/dist/runner/opencode/argv.js +0 -35
- package/dist/runner/opencode/jsonl.d.ts +0 -68
- package/dist/runner/opencode/jsonl.js +0 -295
- package/dist/runner/opencode/runner.d.ts +0 -61
- package/dist/runner/opencode/runner.js +0 -93
- package/dist/runner/pi/jsonl.d.ts +0 -128
- package/dist/runner/pi/jsonl.js +0 -249
- package/dist/runner/pi/runner.d.ts +0 -36
- package/dist/runner/pi/runner.js +0 -76
- package/dist/session/common/catch-up.d.ts +0 -12
- package/dist/session/common/catch-up.js +0 -31
|
@@ -7,29 +7,9 @@
|
|
|
7
7
|
* completes. Method names and parameter shapes follow the real Codex
|
|
8
8
|
* app-server v2 protocol (see protocol-types.ts).
|
|
9
9
|
*/
|
|
10
|
-
import type { AgentEvent } from '../../types.js';
|
|
10
|
+
import type { AgentEvent, TurnStartedEvent, TurnDiffEvent } from '../../types.js';
|
|
11
11
|
import type { ApprovalRequestedEvent, ApprovalResolvedEvent } from '../../types.js';
|
|
12
12
|
import { type TurnCompletedNotification } from './protocol-types.js';
|
|
13
|
-
export interface TurnStartedEvent {
|
|
14
|
-
type: 'turn_started';
|
|
15
|
-
threadId: string;
|
|
16
|
-
turnId: string;
|
|
17
|
-
operationKind: 'turn' | 'compaction';
|
|
18
|
-
}
|
|
19
|
-
export interface TurnDiffEvent {
|
|
20
|
-
type: 'turn_diff';
|
|
21
|
-
text?: string;
|
|
22
|
-
reasoning?: string;
|
|
23
|
-
toolOutput?: string;
|
|
24
|
-
plan?: string;
|
|
25
|
-
fileChanges?: Array<{
|
|
26
|
-
path: string;
|
|
27
|
-
kind: 'add' | 'update' | 'delete';
|
|
28
|
-
diff?: string;
|
|
29
|
-
}>;
|
|
30
|
-
threadId: string;
|
|
31
|
-
turnId: string;
|
|
32
|
-
}
|
|
33
13
|
export type TranslatorEvent = AgentEvent | TurnStartedEvent | TurnDiffEvent | ApprovalRequestedEvent | ApprovalResolvedEvent;
|
|
34
14
|
export declare class CodexAppServerTranslator {
|
|
35
15
|
private turnId;
|
|
@@ -63,6 +43,13 @@ export declare class CodexAppServerTranslator {
|
|
|
63
43
|
* Handle a server request (incoming JSON-RPC request from server, e.g. approval).
|
|
64
44
|
*/
|
|
65
45
|
handleServerRequest(id: number | string, method: string, params: unknown): TranslatorEvent[];
|
|
46
|
+
/**
|
|
47
|
+
* Codex AskUserQuestion:item/tool/requestUserInput → question 审批事件。
|
|
48
|
+
* 问题 id 保留在 UserQuestion.id(回编时文本 → id 映射),options 为
|
|
49
|
+
* null/空 → 自由文本题(空数组驱动卡片渲染输入框);autoResolutionMs
|
|
50
|
+
* 透传为 per-request 超时(coordinator 优先使用)。
|
|
51
|
+
*/
|
|
52
|
+
private handleRequestUserInput;
|
|
66
53
|
/**
|
|
67
54
|
* Synthesize a ResultEvent from the current turn state.
|
|
68
55
|
* Called when the turn completes.
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* completes. Method names and parameter shapes follow the real Codex
|
|
8
8
|
* app-server v2 protocol (see protocol-types.ts).
|
|
9
9
|
*/
|
|
10
|
+
import { makeQuestionApprovalEvent } from '../../question-common.js';
|
|
10
11
|
import { NotificationMethod, ServerRequestMethod, UNSUPPORTED_SERVER_REQUEST_METHODS, } from './protocol-types.js';
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// Translator
|
|
@@ -86,10 +87,33 @@ export class CodexAppServerTranslator {
|
|
|
86
87
|
return this.handleFileApproval(id, params);
|
|
87
88
|
case ServerRequestMethod.PERMISSIONS_APPROVAL:
|
|
88
89
|
return this.handlePermissionsApproval(id, params);
|
|
90
|
+
case ServerRequestMethod.REQUEST_USER_INPUT:
|
|
91
|
+
return this.handleRequestUserInput(id, params);
|
|
89
92
|
default:
|
|
90
93
|
return [];
|
|
91
94
|
}
|
|
92
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Codex AskUserQuestion:item/tool/requestUserInput → question 审批事件。
|
|
98
|
+
* 问题 id 保留在 UserQuestion.id(回编时文本 → id 映射),options 为
|
|
99
|
+
* null/空 → 自由文本题(空数组驱动卡片渲染输入框);autoResolutionMs
|
|
100
|
+
* 透传为 per-request 超时(coordinator 优先使用)。
|
|
101
|
+
*/
|
|
102
|
+
handleRequestUserInput(requestId, params) {
|
|
103
|
+
const questions = params.questions
|
|
104
|
+
.map((q) => requestUserInputQuestionToUserQuestion(q))
|
|
105
|
+
.filter((q) => q !== null);
|
|
106
|
+
if (questions.length === 0) {
|
|
107
|
+
// 无有效问题:不渲染空提问卡,返回 [] 由 runner 以 method-not-found
|
|
108
|
+
// 拒绝(服务端视作请求失败,不会悬挂)。
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
return [
|
|
112
|
+
makeQuestionApprovalEvent(requestId, questions, params.threadId, {
|
|
113
|
+
timeoutMs: params.autoResolutionMs ?? undefined,
|
|
114
|
+
}),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
93
117
|
/**
|
|
94
118
|
* Synthesize a ResultEvent from the current turn state.
|
|
95
119
|
* Called when the turn completes.
|
|
@@ -450,21 +474,11 @@ export class CodexAppServerTranslator {
|
|
|
450
474
|
const view = {
|
|
451
475
|
requestId,
|
|
452
476
|
kind: 'command',
|
|
453
|
-
threadShort: params.threadId.slice(0, 8),
|
|
454
|
-
turnShort: params.turnId.slice(0, 8),
|
|
455
|
-
workspace: params.cwd ?? '',
|
|
456
477
|
command: params.command ?? undefined,
|
|
457
478
|
commandCwd: params.cwd ?? undefined,
|
|
458
479
|
reason: params.reason ?? undefined,
|
|
459
|
-
network: params.networkApprovalContext
|
|
460
|
-
? {
|
|
461
|
-
host: params.networkApprovalContext.host,
|
|
462
|
-
protocol: params.networkApprovalContext.protocol,
|
|
463
|
-
}
|
|
464
|
-
: undefined,
|
|
465
480
|
availableDecisions: decisions,
|
|
466
481
|
...(payloads ? { decisionPayloads: payloads } : {}),
|
|
467
|
-
pendingTotal: 1,
|
|
468
482
|
};
|
|
469
483
|
return [
|
|
470
484
|
{
|
|
@@ -492,14 +506,10 @@ export class CodexAppServerTranslator {
|
|
|
492
506
|
const view = {
|
|
493
507
|
requestId,
|
|
494
508
|
kind: 'file',
|
|
495
|
-
threadShort: params.threadId.slice(0, 8),
|
|
496
|
-
turnShort: params.turnId.slice(0, 8),
|
|
497
|
-
workspace: '',
|
|
498
509
|
fileChanges,
|
|
499
510
|
reason: params.reason ?? undefined,
|
|
500
511
|
// 真实 FileChangeApprovalDecision 枚举:accept/acceptForSession/decline/cancel。
|
|
501
512
|
availableDecisions: ['accept', 'acceptForSession', 'decline', 'cancel'],
|
|
502
|
-
pendingTotal: 1,
|
|
503
513
|
};
|
|
504
514
|
// 乱序流:审批先到、item/started 后到。先出事件(回退信息),item 到达时
|
|
505
515
|
// 以 approval_view_updated 补全,避免卡片永久空白。
|
|
@@ -582,12 +592,8 @@ export class CodexAppServerTranslator {
|
|
|
582
592
|
const view = {
|
|
583
593
|
requestId,
|
|
584
594
|
kind: 'permissions',
|
|
585
|
-
threadShort: params.threadId.slice(0, 8),
|
|
586
|
-
turnShort: params.turnId.slice(0, 8),
|
|
587
|
-
workspace: params.cwd,
|
|
588
595
|
reason: params.reason ?? undefined,
|
|
589
596
|
availableDecisions: ['accept', 'decline', 'cancel'],
|
|
590
|
-
pendingTotal: 1,
|
|
591
597
|
permissions: {
|
|
592
598
|
items: permItems,
|
|
593
599
|
},
|
|
@@ -731,4 +737,25 @@ function normalizeCommandDecisions(list) {
|
|
|
731
737
|
...(Object.keys(payloads).length > 0 ? { payloads } : {}),
|
|
732
738
|
};
|
|
733
739
|
}
|
|
740
|
+
/** Codex wire question → 统一 UserQuestion(options null/空 → 自由文本题)。 */
|
|
741
|
+
function requestUserInputQuestionToUserQuestion(q) {
|
|
742
|
+
const question = q.question?.trim();
|
|
743
|
+
if (!question)
|
|
744
|
+
return null;
|
|
745
|
+
const options = (q.options ?? []).map((opt) => ({
|
|
746
|
+
label: opt.label,
|
|
747
|
+
...(opt.description ? { description: opt.description } : {}),
|
|
748
|
+
}));
|
|
749
|
+
return {
|
|
750
|
+
id: q.id,
|
|
751
|
+
header: q.header || undefined,
|
|
752
|
+
question,
|
|
753
|
+
isOther: q.isOther,
|
|
754
|
+
isSecret: q.isSecret,
|
|
755
|
+
options,
|
|
756
|
+
// Codex user_note:选项题渲染「补充说明(可选)」输入(live 验证模型理解
|
|
757
|
+
// "user_note:" 条目);自由文本题(options 空)不需要。
|
|
758
|
+
...(options.length > 0 ? { allowNote: true } : {}),
|
|
759
|
+
};
|
|
760
|
+
}
|
|
734
761
|
//# sourceMappingURL=translator.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper functions for the ACP protocol layer.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from runner.ts and translator.ts to avoid duplication (G5).
|
|
5
|
+
* Shape source: approval.ts:28-29 — optionId is opaque, echo back as-is.
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionOption } from './protocol-types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Find an option by matching its `kind` against a list of candidate values,
|
|
10
|
+
* and return the `optionId` to echo back in the approval response.
|
|
11
|
+
* ACP option kind values vary between kimi versions; this handles both
|
|
12
|
+
* the documented names and the observed real names (§2.3).
|
|
13
|
+
*/
|
|
14
|
+
export declare function findOptionIdByKind(options: PermissionOption[], candidateKinds: string[]): string | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper functions for the ACP protocol layer.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from runner.ts and translator.ts to avoid duplication (G5).
|
|
5
|
+
* Shape source: approval.ts:28-29 — optionId is opaque, echo back as-is.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Find an option by matching its `kind` against a list of candidate values,
|
|
9
|
+
* and return the `optionId` to echo back in the approval response.
|
|
10
|
+
* ACP option kind values vary between kimi versions; this handles both
|
|
11
|
+
* the documented names and the observed real names (§2.3).
|
|
12
|
+
*/
|
|
13
|
+
export function findOptionIdByKind(options, candidateKinds) {
|
|
14
|
+
for (const kind of candidateKinds) {
|
|
15
|
+
const found = options.find((opt) => opt.kind === kind);
|
|
16
|
+
if (found)
|
|
17
|
+
return found.optionId;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=protocol-helpers.js.map
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Client Protocol) JSON-RPC Protocol Types — shared layer.
|
|
3
|
+
*
|
|
4
|
+
* Aligned with the real `kimi acp` protocol (kimi-code/packages/acp-server).
|
|
5
|
+
* Method names and field names use the wire format exactly.
|
|
6
|
+
* Only covers the methods and events needed for the integration
|
|
7
|
+
* (§4 event mapping table + §5 approval + §6 compact).
|
|
8
|
+
*
|
|
9
|
+
* ============================================================================
|
|
10
|
+
* 事件契约(translator 共享规范 —— 文档不是抽象,各家 translator 仍各自实现)
|
|
11
|
+
* ============================================================================
|
|
12
|
+
*
|
|
13
|
+
* lark-remote 内部事件流对 ACP 系 agent(kimi acp、后续 opencode acp)的约定:
|
|
14
|
+
*
|
|
15
|
+
* 1. `assistant/text` 与 `assistant/thinking` 是**增量通道**:run-state 收到后
|
|
16
|
+
* 向对应 item **追加**文本。
|
|
17
|
+
* 2. `turn_diff` 是**快照通道**:run-state 按 itemId **原地替换**全文(kimi ACP
|
|
18
|
+
* 文本/思考固定 itemId `'text'`/`'thinking'`)。
|
|
19
|
+
* 3. kimi wire 的 `content.text`(agent_message_chunk / agent_thought_chunk)
|
|
20
|
+
* 是**增量 delta**(来源:kimi-code events-map.ts
|
|
21
|
+
* `assistantDeltaToSessionUpdate`)。translator 必须把 delta 累积成全文后
|
|
22
|
+
* 以 `turn_diff` 快照发出——禁止把 delta 直接当快照或把全文当增量重复追加。
|
|
23
|
+
* 4. `tool_call` 事件可能**没有 rawInput**(工具 lazy-create,参数在后续
|
|
24
|
+
* tool_call_update 才补齐);translator 必须归一化为 `{}`,不得因缺失崩溃。
|
|
25
|
+
*/
|
|
26
|
+
export type { JsonRpcRequest, JsonRpcNotification, JsonRpcSuccessResponse, JsonRpcErrorResponse, } from '../jsonrpc/types.js';
|
|
27
|
+
/** Standard JSON-RPC error codes. */
|
|
28
|
+
export declare const RpcErrorCode: {
|
|
29
|
+
readonly PARSE_ERROR: -32700;
|
|
30
|
+
readonly INVALID_REQUEST: -32600;
|
|
31
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
32
|
+
readonly INVALID_PARAMS: -32602;
|
|
33
|
+
readonly INTERNAL_ERROR: -32603;
|
|
34
|
+
/** Timeout error (custom, not standard JSON-RPC). */
|
|
35
|
+
readonly TIMEOUT_ERROR: -32000;
|
|
36
|
+
/** Connection lost / transport error (custom). */
|
|
37
|
+
readonly CONNECTION_LOST: -32001;
|
|
38
|
+
};
|
|
39
|
+
export interface InitializeParams {
|
|
40
|
+
/** Protocol version — must be 1 (number, not string). */
|
|
41
|
+
protocolVersion: number;
|
|
42
|
+
/** Client capabilities: explicitly declare what we support (all off). */
|
|
43
|
+
clientCapabilities: {
|
|
44
|
+
fs: {
|
|
45
|
+
readTextFile: boolean;
|
|
46
|
+
writeTextFile: boolean;
|
|
47
|
+
};
|
|
48
|
+
terminal: boolean;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface AgentInfo {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
}
|
|
55
|
+
export interface InitializeResult {
|
|
56
|
+
/** Protocol version returned by the server. */
|
|
57
|
+
protocolVersion: number;
|
|
58
|
+
/** Agent info — NOTE: field is `agentInfo`, NOT `serverInfo`. */
|
|
59
|
+
agentInfo: AgentInfo;
|
|
60
|
+
/** Authentication methods the server supports. */
|
|
61
|
+
authMethods?: string[];
|
|
62
|
+
/** Agent capabilities declared by the server. */
|
|
63
|
+
agentCapabilities?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* ACP mode ids (what the server accepts in session/set_mode).
|
|
67
|
+
* kimi exposes default/auto/yolo (plan not exposed in v1);
|
|
68
|
+
* opencode uses agent names build/plan.
|
|
69
|
+
*/
|
|
70
|
+
export type AcpMode = 'default' | 'plan' | 'auto' | 'yolo' | 'build';
|
|
71
|
+
export interface SessionNewParams {
|
|
72
|
+
cwd: string;
|
|
73
|
+
/** MCP servers config — REQUIRED (can be empty array). */
|
|
74
|
+
mcpServers: unknown[];
|
|
75
|
+
}
|
|
76
|
+
export interface SessionNewResult {
|
|
77
|
+
sessionId: string;
|
|
78
|
+
configOptions?: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
export interface SessionResumeParams {
|
|
81
|
+
sessionId: string;
|
|
82
|
+
cwd: string;
|
|
83
|
+
}
|
|
84
|
+
export interface SessionResumeResult {
|
|
85
|
+
sessionId: string;
|
|
86
|
+
configOptions?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
export interface SessionPromptParams {
|
|
89
|
+
sessionId: string;
|
|
90
|
+
prompt: Array<{
|
|
91
|
+
type: 'text';
|
|
92
|
+
text: string;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
export interface SessionPromptResult {
|
|
96
|
+
stopReason: 'end_turn' | 'cancelled' | string;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
}
|
|
99
|
+
export interface SessionCancelParams {
|
|
100
|
+
sessionId: string;
|
|
101
|
+
}
|
|
102
|
+
export interface SessionSetModeParams {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
/** Parameter name is `modeId`, NOT `mode` (server.ts:439). */
|
|
105
|
+
modeId: AcpMode;
|
|
106
|
+
}
|
|
107
|
+
/** Notification method names for ACP protocol. */
|
|
108
|
+
export declare const NotificationMethod: {
|
|
109
|
+
/** Session update carries one of the event types below. */
|
|
110
|
+
readonly SESSION_UPDATE: "session/update";
|
|
111
|
+
};
|
|
112
|
+
/** Event types within session/update params. */
|
|
113
|
+
export declare const SessionEventType: {
|
|
114
|
+
readonly AGENT_MESSAGE_CHUNK: "agent_message_chunk";
|
|
115
|
+
readonly AGENT_THOUGHT_CHUNK: "agent_thought_chunk";
|
|
116
|
+
readonly TOOL_CALL: "tool_call";
|
|
117
|
+
readonly TOOL_CALL_UPDATE: "tool_call_update";
|
|
118
|
+
readonly PLAN: "plan";
|
|
119
|
+
readonly AVAILABLE_COMMANDS_UPDATE: "available_commands_update";
|
|
120
|
+
readonly SESSION_INFO_UPDATE: "session_info_update";
|
|
121
|
+
readonly CURRENT_MODE_UPDATE: "current_mode_update";
|
|
122
|
+
readonly CONFIG_OPTION_UPDATE: "config_option_update";
|
|
123
|
+
readonly USAGE_UPDATE: "usage_update";
|
|
124
|
+
};
|
|
125
|
+
export interface AgentMessageChunkEvent {
|
|
126
|
+
sessionUpdate: 'agent_message_chunk';
|
|
127
|
+
/** events-map.ts:30-37 — content.text, NOT delta. */
|
|
128
|
+
content: {
|
|
129
|
+
type: 'text';
|
|
130
|
+
text: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface AgentThoughtChunkEvent {
|
|
134
|
+
sessionUpdate: 'agent_thought_chunk';
|
|
135
|
+
/** events-map.ts:280-288 — same content.text structure. */
|
|
136
|
+
content: {
|
|
137
|
+
type: 'text';
|
|
138
|
+
text: string;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export interface ToolCallEvent {
|
|
142
|
+
sessionUpdate: 'tool_call';
|
|
143
|
+
toolCallId: string;
|
|
144
|
+
title: string;
|
|
145
|
+
/** events-map.ts toolCallStartToSessionUpdate — rawInput is the args
|
|
146
|
+
* OBJECT (not a JSON string). */
|
|
147
|
+
kind: string;
|
|
148
|
+
status: 'pending' | 'in_progress' | string;
|
|
149
|
+
rawInput: unknown;
|
|
150
|
+
locations?: unknown[];
|
|
151
|
+
content?: unknown[];
|
|
152
|
+
[key: string]: unknown;
|
|
153
|
+
}
|
|
154
|
+
export interface ToolCallUpdateEvent {
|
|
155
|
+
sessionUpdate: 'tool_call_update';
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
status: 'running' | 'completed' | 'failed';
|
|
158
|
+
title?: string;
|
|
159
|
+
rawInput?: unknown;
|
|
160
|
+
/** events-map.ts toolResultToSessionUpdate — raw output of the tool. */
|
|
161
|
+
rawOutput?: string;
|
|
162
|
+
locations?: unknown[];
|
|
163
|
+
content?: unknown[];
|
|
164
|
+
[key: string]: unknown;
|
|
165
|
+
}
|
|
166
|
+
export interface AcpPlanEvent {
|
|
167
|
+
sessionUpdate: 'plan';
|
|
168
|
+
entries?: unknown[];
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
export interface AvailableCommandsUpdateEvent {
|
|
172
|
+
sessionUpdate: 'available_commands_update';
|
|
173
|
+
availableCommands?: unknown[];
|
|
174
|
+
[key: string]: unknown;
|
|
175
|
+
}
|
|
176
|
+
export interface SessionInfoUpdateEvent {
|
|
177
|
+
sessionUpdate: 'session_info_update';
|
|
178
|
+
title: string | null;
|
|
179
|
+
[key: string]: unknown;
|
|
180
|
+
}
|
|
181
|
+
export interface CurrentModeUpdateEvent {
|
|
182
|
+
sessionUpdate: 'current_mode_update';
|
|
183
|
+
currentModeId: string;
|
|
184
|
+
[key: string]: unknown;
|
|
185
|
+
}
|
|
186
|
+
export interface ConfigOptionUpdateEvent {
|
|
187
|
+
sessionUpdate: 'config_option_update';
|
|
188
|
+
configOptions?: unknown[];
|
|
189
|
+
[key: string]: unknown;
|
|
190
|
+
}
|
|
191
|
+
export interface UsageUpdateEvent {
|
|
192
|
+
sessionUpdate: 'usage_update';
|
|
193
|
+
/** events-map.ts:505-516 — current context occupancy (token count).
|
|
194
|
+
* There is NO inputTokens/outputTokens split. */
|
|
195
|
+
used: number;
|
|
196
|
+
/** Model context window upper bound. */
|
|
197
|
+
size: number;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
export type SessionUpdateEvent = AgentMessageChunkEvent | AgentThoughtChunkEvent | ToolCallEvent | ToolCallUpdateEvent | AcpPlanEvent | AvailableCommandsUpdateEvent | SessionInfoUpdateEvent | CurrentModeUpdateEvent | ConfigOptionUpdateEvent | UsageUpdateEvent;
|
|
201
|
+
export interface SessionUpdateNotification {
|
|
202
|
+
method: 'session/update';
|
|
203
|
+
params: {
|
|
204
|
+
sessionId: string;
|
|
205
|
+
update: SessionUpdateEvent;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export declare const ServerRequestMethod: {
|
|
209
|
+
readonly REQUEST_PERMISSION: "session/request_permission";
|
|
210
|
+
/** Kimi AskUserQuestion elicitation form(客户端广告 elicitation.form 时启用)。 */
|
|
211
|
+
readonly ELICITATION_CREATE: "elicitation/create";
|
|
212
|
+
};
|
|
213
|
+
export interface PermissionOption {
|
|
214
|
+
/** Opaque option identifier — echo back in response outcome.optionId. */
|
|
215
|
+
optionId: string;
|
|
216
|
+
/** Human-readable option name. */
|
|
217
|
+
name: string;
|
|
218
|
+
/** Option kind: 'approve_once'/'allow_once', 'approve_always'/'allow_always', 'reject'/'reject_once'. */
|
|
219
|
+
kind: string;
|
|
220
|
+
}
|
|
221
|
+
export interface RequestPermissionParams {
|
|
222
|
+
sessionId: string;
|
|
223
|
+
toolCall?: {
|
|
224
|
+
title: string;
|
|
225
|
+
rawInput: string;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
};
|
|
228
|
+
options: PermissionOption[];
|
|
229
|
+
/** Question elicitation marker: true when this is a question rather than
|
|
230
|
+
* a tool approval (§5.4). Identified by absence of toolCall and/or presence
|
|
231
|
+
* of options with Skip semantics. */
|
|
232
|
+
isQuestion?: boolean;
|
|
233
|
+
[key: string]: unknown;
|
|
234
|
+
}
|
|
235
|
+
export interface RequestPermissionResponse {
|
|
236
|
+
outcome: {
|
|
237
|
+
outcome: 'selected' | 'cancelled';
|
|
238
|
+
optionId?: string;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
export interface ElicitationEnumOption {
|
|
242
|
+
const: string;
|
|
243
|
+
title?: string;
|
|
244
|
+
description?: string;
|
|
245
|
+
}
|
|
246
|
+
export interface ElicitationPropertySchema {
|
|
247
|
+
type: 'string' | 'array';
|
|
248
|
+
title?: string;
|
|
249
|
+
description?: string;
|
|
250
|
+
minItems?: number;
|
|
251
|
+
oneOf?: ElicitationEnumOption[];
|
|
252
|
+
items?: {
|
|
253
|
+
anyOf?: ElicitationEnumOption[];
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export interface ElicitationCreateParams {
|
|
257
|
+
sessionId: string;
|
|
258
|
+
toolCallId?: string;
|
|
259
|
+
mode: 'form';
|
|
260
|
+
message?: string;
|
|
261
|
+
requestedSchema: {
|
|
262
|
+
type: 'object';
|
|
263
|
+
required?: string[];
|
|
264
|
+
properties: Record<string, ElicitationPropertySchema>;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
export interface ElicitationCreateResponse {
|
|
268
|
+
action: 'accept' | 'decline' | 'cancel';
|
|
269
|
+
/** accept 时的答案,key 为 q0..qn(按问题顺序)。 */
|
|
270
|
+
content?: Record<string, string | string[]>;
|
|
271
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Client Protocol) JSON-RPC Protocol Types — shared layer.
|
|
3
|
+
*
|
|
4
|
+
* Aligned with the real `kimi acp` protocol (kimi-code/packages/acp-server).
|
|
5
|
+
* Method names and field names use the wire format exactly.
|
|
6
|
+
* Only covers the methods and events needed for the integration
|
|
7
|
+
* (§4 event mapping table + §5 approval + §6 compact).
|
|
8
|
+
*
|
|
9
|
+
* ============================================================================
|
|
10
|
+
* 事件契约(translator 共享规范 —— 文档不是抽象,各家 translator 仍各自实现)
|
|
11
|
+
* ============================================================================
|
|
12
|
+
*
|
|
13
|
+
* lark-remote 内部事件流对 ACP 系 agent(kimi acp、后续 opencode acp)的约定:
|
|
14
|
+
*
|
|
15
|
+
* 1. `assistant/text` 与 `assistant/thinking` 是**增量通道**:run-state 收到后
|
|
16
|
+
* 向对应 item **追加**文本。
|
|
17
|
+
* 2. `turn_diff` 是**快照通道**:run-state 按 itemId **原地替换**全文(kimi ACP
|
|
18
|
+
* 文本/思考固定 itemId `'text'`/`'thinking'`)。
|
|
19
|
+
* 3. kimi wire 的 `content.text`(agent_message_chunk / agent_thought_chunk)
|
|
20
|
+
* 是**增量 delta**(来源:kimi-code events-map.ts
|
|
21
|
+
* `assistantDeltaToSessionUpdate`)。translator 必须把 delta 累积成全文后
|
|
22
|
+
* 以 `turn_diff` 快照发出——禁止把 delta 直接当快照或把全文当增量重复追加。
|
|
23
|
+
* 4. `tool_call` 事件可能**没有 rawInput**(工具 lazy-create,参数在后续
|
|
24
|
+
* tool_call_update 才补齐);translator 必须归一化为 `{}`,不得因缺失崩溃。
|
|
25
|
+
*/
|
|
26
|
+
/** Standard JSON-RPC error codes. */
|
|
27
|
+
export const RpcErrorCode = {
|
|
28
|
+
PARSE_ERROR: -32700,
|
|
29
|
+
INVALID_REQUEST: -32600,
|
|
30
|
+
METHOD_NOT_FOUND: -32601,
|
|
31
|
+
INVALID_PARAMS: -32602,
|
|
32
|
+
INTERNAL_ERROR: -32603,
|
|
33
|
+
/** Timeout error (custom, not standard JSON-RPC). */
|
|
34
|
+
TIMEOUT_ERROR: -32000,
|
|
35
|
+
/** Connection lost / transport error (custom). */
|
|
36
|
+
CONNECTION_LOST: -32001,
|
|
37
|
+
};
|
|
38
|
+
// =============================================================================
|
|
39
|
+
// Notifications (server → client, via session/update)
|
|
40
|
+
// Shape source: kimi-code/packages/acp-server/src/events-map.ts
|
|
41
|
+
// (each constructor below) + 2026-08-15 live smoke test against kimi 0.36.0
|
|
42
|
+
//
|
|
43
|
+
// REAL envelope: {sessionId, update: {sessionUpdate: '<kind>', ...}}.
|
|
44
|
+
// The discriminator field is `update.sessionUpdate` — there is NO nested
|
|
45
|
+
// `event.type` / `event.delta` (S5/S6 打回根因:旧实现读 params.event,
|
|
46
|
+
// 真实通知全部静默丢弃)。
|
|
47
|
+
// =============================================================================
|
|
48
|
+
/** Notification method names for ACP protocol. */
|
|
49
|
+
export const NotificationMethod = {
|
|
50
|
+
/** Session update carries one of the event types below. */
|
|
51
|
+
SESSION_UPDATE: 'session/update',
|
|
52
|
+
};
|
|
53
|
+
/** Event types within session/update params. */
|
|
54
|
+
export const SessionEventType = {
|
|
55
|
+
AGENT_MESSAGE_CHUNK: 'agent_message_chunk',
|
|
56
|
+
AGENT_THOUGHT_CHUNK: 'agent_thought_chunk',
|
|
57
|
+
TOOL_CALL: 'tool_call',
|
|
58
|
+
TOOL_CALL_UPDATE: 'tool_call_update',
|
|
59
|
+
PLAN: 'plan',
|
|
60
|
+
AVAILABLE_COMMANDS_UPDATE: 'available_commands_update',
|
|
61
|
+
SESSION_INFO_UPDATE: 'session_info_update',
|
|
62
|
+
CURRENT_MODE_UPDATE: 'current_mode_update',
|
|
63
|
+
CONFIG_OPTION_UPDATE: 'config_option_update',
|
|
64
|
+
USAGE_UPDATE: 'usage_update',
|
|
65
|
+
};
|
|
66
|
+
// =============================================================================
|
|
67
|
+
// Server Requests (approval — reverse RPC)
|
|
68
|
+
// Shape source: kimi-code/packages/acp-server/src/approval.ts:28-29
|
|
69
|
+
// options: [{optionId, name, kind}]; optionId is opaque, echo back as-is
|
|
70
|
+
// + 2026-08-15 live smoke test: approve_once / approve_always / reject
|
|
71
|
+
// =============================================================================
|
|
72
|
+
export const ServerRequestMethod = {
|
|
73
|
+
REQUEST_PERMISSION: 'session/request_permission',
|
|
74
|
+
/** Kimi AskUserQuestion elicitation form(客户端广告 elicitation.form 时启用)。 */
|
|
75
|
+
ELICITATION_CREATE: 'elicitation/create',
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=protocol-types.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConnectionBasedRunner: abstract base class for workspace-lifetime JSON-RPC
|
|
3
|
+
* agent runners (codex app-server / kimi acp / opencode acp).
|
|
4
|
+
*
|
|
5
|
+
* Encapsulates the shared connection-based turn machinery the three runners
|
|
6
|
+
* were duplicating (and had drifted apart on):
|
|
7
|
+
* - notification queue + waitResolve pump (consumeTurn / waitForEvents)
|
|
8
|
+
* - forceFinish / stopRequested / deferred-stop semantics
|
|
9
|
+
* - connection-lost respawn-and-retry-once in run()
|
|
10
|
+
* - turn idle watchdog (nextTurnIdleDeadline)
|
|
11
|
+
* - dispose / killOrphan / registerExitHandlers / getUsageAuthority no-ops
|
|
12
|
+
*
|
|
13
|
+
* Subclasses keep the protocol-specific parts (setupTurn, runCompact,
|
|
14
|
+
* handleNotification/handleServerRequest, respondApproval, pendingApprovals,
|
|
15
|
+
* updateApprovalMode, getStatusInfo) and provide the small abstract hooks below.
|
|
16
|
+
*/
|
|
17
|
+
import type { AgentKind, AgentSessionReader, AgentEvent, AgentRunner, AgentStatusInfo, SpawnOptions } from '../types.js';
|
|
18
|
+
/** How long to wait for turn output notifications before failing. */
|
|
19
|
+
export declare const TURN_IDLE_TIMEOUT_MS: number;
|
|
20
|
+
export declare abstract class ConnectionBasedRunner<TClient, TEvent = AgentEvent> implements AgentRunner {
|
|
21
|
+
readonly kind: AgentKind;
|
|
22
|
+
readonly sessionReader: AgentSessionReader;
|
|
23
|
+
readonly lifetime: "workspace";
|
|
24
|
+
protected currentClient: TClient | null;
|
|
25
|
+
protected currentTurnId: string | null;
|
|
26
|
+
protected lastEventAt: number;
|
|
27
|
+
protected _isRunning: boolean;
|
|
28
|
+
protected readonly turnIdleTimeoutMs: number;
|
|
29
|
+
/** Notification queue consumed by the active run generator. */
|
|
30
|
+
protected notificationQueue: TEvent[];
|
|
31
|
+
protected waitResolve: (() => void) | null;
|
|
32
|
+
protected forceFinish: boolean;
|
|
33
|
+
/** stop() 在 turn/start 或 prompt 响应前到达时置位,完成后再补发 cancel/interrupt。 */
|
|
34
|
+
protected stopRequested: boolean;
|
|
35
|
+
protected constructor(opts: {
|
|
36
|
+
kind: AgentKind;
|
|
37
|
+
sessionReader: AgentSessionReader;
|
|
38
|
+
turnIdleTimeoutMs?: number;
|
|
39
|
+
}, defaultTurnIdleTimeoutMs?: number);
|
|
40
|
+
/** Log tag used for operational log lines (e.g. 'kimi-acp-runner'). */
|
|
41
|
+
protected abstract get logTag(): string;
|
|
42
|
+
/** Error message for the turn-idle-timeout result. */
|
|
43
|
+
protected abstract get turnTimeoutErrorMessage(): string;
|
|
44
|
+
/** Error message for the interrupted (stop/forceFinish) result. */
|
|
45
|
+
protected abstract get turnInterruptedErrorMessage(): string;
|
|
46
|
+
/** The active thread/session id, used for result events / synthetic init. */
|
|
47
|
+
protected abstract currentSessionId(): string | null;
|
|
48
|
+
/** Deferred-stop predicate: stop() marks stopRequested instead of cancelling now. */
|
|
49
|
+
protected abstract shouldDeferStop(): boolean;
|
|
50
|
+
/** Cancel the current turn (codex: turn/interrupt request; acp: session/cancel notify). */
|
|
51
|
+
protected abstract cancelCurrentTurn(): Promise<void>;
|
|
52
|
+
/** Set up the turn: acquire + thread|session new/resume + prompt. */
|
|
53
|
+
protected abstract setupTurn(message: string, opts: SpawnOptions): Promise<void>;
|
|
54
|
+
get isRunning(): boolean;
|
|
55
|
+
/** Agent self-describing status info for /status display. */
|
|
56
|
+
abstract getStatusInfo(): AgentStatusInfo;
|
|
57
|
+
/**
|
|
58
|
+
* Run a message. Delegates to executeTurn() with the standard setup.
|
|
59
|
+
*/
|
|
60
|
+
run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
|
|
61
|
+
/**
|
|
62
|
+
* Shared turn lifecycle used by run() and runCompact(): isRunning guard →
|
|
63
|
+
* resetRunState → setupFn (with connection-lost respawn-and-retry-once) →
|
|
64
|
+
* deferred stop → synthetic init → consumeTurn; catch yields synthetic init
|
|
65
|
+
* + error result; finally resets flags + notifyIdle.
|
|
66
|
+
*
|
|
67
|
+
* `setupFn` performs the turn-specific setup (acquire, session new/resume,
|
|
68
|
+
* prompt, etc.) and may push events into the notification queue.
|
|
69
|
+
*/
|
|
70
|
+
protected executeTurn(opts: SpawnOptions, setupFn: () => Promise<void>): AsyncGenerator<AgentEvent>;
|
|
71
|
+
/**
|
|
72
|
+
* Stop the current turn by cancelling it. Shared skeleton: if the turn/start
|
|
73
|
+
* or prompt has not yet resolved (shouldDeferStop), mark stopRequested and
|
|
74
|
+
* unblock; otherwise cancel now via cancelCurrentTurn().
|
|
75
|
+
*/
|
|
76
|
+
stop(_opts?: {
|
|
77
|
+
immediate?: boolean;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Dispose the runner: release the connection.
|
|
81
|
+
*/
|
|
82
|
+
dispose(): Promise<void>;
|
|
83
|
+
getUsageAuthority(): 'live';
|
|
84
|
+
killOrphan(): void;
|
|
85
|
+
registerExitHandlers(): void;
|
|
86
|
+
unregisterExitHandlers(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Consume the notification queue until a result event arrives or the turn
|
|
89
|
+
* times out / is interrupted. forceFinish drains the queue first (the
|
|
90
|
+
* deferred cancel's own events may still be in it) before yielding the
|
|
91
|
+
* interrupted result.
|
|
92
|
+
*/
|
|
93
|
+
protected consumeTurn(): AsyncGenerator<AgentEvent>;
|
|
94
|
+
/** Compute the current idle deadline. 0 disables; otherwise rolling on last event. */
|
|
95
|
+
protected nextTurnIdleDeadline(): number;
|
|
96
|
+
protected waitForEvents(deadline: number): Promise<boolean>;
|
|
97
|
+
protected pushEvents(events: TEvent[]): void;
|
|
98
|
+
protected wakeWaiters(): void;
|
|
99
|
+
protected failTurn(message: string): void;
|
|
100
|
+
protected resetRunState(): void;
|
|
101
|
+
/** Release the connection + detach stale client hooks after a lost connection. */
|
|
102
|
+
protected respawnAfterConnectionLost(opts: SpawnOptions): Promise<void>;
|
|
103
|
+
/** Hook: clear subclass turn state in run() finally (session ids, translator, flags). */
|
|
104
|
+
protected abstract clearTurnState(): void;
|
|
105
|
+
/** Release the connection for a workspace (subclass dispatches to its manager). */
|
|
106
|
+
protected abstract releaseConnection(cwd: string): Promise<void>;
|
|
107
|
+
/** Notify the connection manager that the workspace is idle (subclass). */
|
|
108
|
+
protected abstract notifyIdle(cwd: string): void;
|
|
109
|
+
/** Dispose all connections (subclass dispatches to its manager). */
|
|
110
|
+
protected abstract disposeConnections(): Promise<void>;
|
|
111
|
+
}
|