reasonix 0.40.0 → 0.43.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.
- package/README.md +47 -16
- package/README.zh-CN.md +19 -13
- package/dashboard/app.css +8 -4
- package/dashboard/dist/app.js +377 -227
- package/dashboard/dist/app.js.map +1 -1
- package/dist/cli/acp-DAGPCVFZ.js +713 -0
- package/dist/cli/acp-DAGPCVFZ.js.map +1 -0
- package/dist/cli/chat-7ES4IBNH.js +50 -0
- package/dist/cli/{chunk-E46ECXJD.js → chunk-2425HK6U.js} +2 -1
- package/dist/cli/{chunk-E46ECXJD.js.map → chunk-2425HK6U.js.map} +1 -1
- package/dist/cli/chunk-25T6CVUP.js +172 -0
- package/dist/cli/chunk-25T6CVUP.js.map +1 -0
- package/dist/cli/{chunk-7DLHHBGN.js → chunk-2K65GZBT.js} +16 -5
- package/dist/cli/chunk-2K65GZBT.js.map +1 -0
- package/dist/cli/{chunk-KMWKGPFZ.js → chunk-2KDUS647.js} +14 -4
- package/dist/cli/chunk-2KDUS647.js.map +1 -0
- package/dist/cli/chunk-2R4QCDOZ.js +11392 -0
- package/dist/cli/chunk-2R4QCDOZ.js.map +1 -0
- package/dist/cli/{chunk-3Q3C4W66.js → chunk-2UQP6H6T.js} +2 -1
- package/dist/cli/{chunk-3Q3C4W66.js.map → chunk-2UQP6H6T.js.map} +1 -1
- package/dist/cli/chunk-2Z35JOA4.js +96 -0
- package/dist/cli/chunk-2Z35JOA4.js.map +1 -0
- package/dist/cli/chunk-32TIKD5U.js +54 -0
- package/dist/cli/{chunk-JWCTX5S4.js.map → chunk-32TIKD5U.js.map} +1 -1
- package/dist/cli/{chunk-UVRXTSK3.js → chunk-3BXRZFWS.js} +65 -3
- package/dist/cli/chunk-3BXRZFWS.js.map +1 -0
- package/dist/cli/chunk-3Z6IBU3D.js +249 -0
- package/dist/cli/chunk-3Z6IBU3D.js.map +1 -0
- package/dist/cli/{chunk-VLNRQMCI.js → chunk-45U62RI3.js} +12 -5
- package/dist/cli/chunk-45U62RI3.js.map +1 -0
- package/dist/cli/{chunk-5GKJLNP2.js → chunk-4QUNBQQ2.js} +3 -2
- package/dist/cli/{chunk-5GKJLNP2.js.map → chunk-4QUNBQQ2.js.map} +1 -1
- package/dist/cli/{chunk-R4YTW7PR.js → chunk-5JJRUIPA.js} +57 -12
- package/dist/cli/chunk-5JJRUIPA.js.map +1 -0
- package/dist/cli/{chunk-HCC42PEI.js → chunk-6AK4EY3D.js} +12 -6
- package/dist/cli/chunk-6AK4EY3D.js.map +1 -0
- package/dist/cli/chunk-6G3CUUFG.js +34320 -0
- package/dist/cli/chunk-6G3CUUFG.js.map +1 -0
- package/dist/cli/{chunk-XST7BSZJ.js → chunk-6PBZN4VI.js} +21 -3
- package/dist/cli/chunk-6PBZN4VI.js.map +1 -0
- package/dist/cli/{chunk-A5LSGEEK.js → chunk-6PZ3CXBP.js} +88 -66
- package/dist/cli/chunk-6PZ3CXBP.js.map +1 -0
- package/dist/cli/chunk-74EX7SUH.js +25293 -0
- package/dist/cli/chunk-74EX7SUH.js.map +1 -0
- package/dist/cli/{chunk-FFNOMR32.js → chunk-7O5ALB4C.js} +3 -2
- package/dist/cli/{chunk-FFNOMR32.js.map → chunk-7O5ALB4C.js.map} +1 -1
- package/dist/cli/{chunk-UCMTWZKU.js → chunk-DOYHN4KB.js} +3 -2
- package/dist/cli/{chunk-UCMTWZKU.js.map → chunk-DOYHN4KB.js.map} +1 -1
- package/dist/cli/{chunk-XJLZ4HKU.js → chunk-F3PXYSNN.js} +3 -2
- package/dist/cli/{chunk-XJLZ4HKU.js.map → chunk-F3PXYSNN.js.map} +1 -1
- package/dist/cli/{chunk-XHQIK7B6.js → chunk-FHOGSSCH.js} +4 -3
- package/dist/cli/{chunk-XHQIK7B6.js.map → chunk-FHOGSSCH.js.map} +1 -1
- package/dist/cli/{chunk-IYF36OCJ.js → chunk-H6PS7IUE.js} +3 -2
- package/dist/cli/{chunk-IYF36OCJ.js.map → chunk-H6PS7IUE.js.map} +1 -1
- package/dist/cli/{chunk-ZTLZO42A.js → chunk-HFEAY5DT.js} +3 -2
- package/dist/cli/{chunk-ZTLZO42A.js.map → chunk-HFEAY5DT.js.map} +1 -1
- package/dist/cli/{chunk-FWGEHRB7.js → chunk-J5XJHLWM.js} +2 -1
- package/dist/cli/{chunk-FWGEHRB7.js.map → chunk-J5XJHLWM.js.map} +1 -1
- package/dist/cli/chunk-JMBMLOBP.js +26 -0
- package/dist/cli/chunk-JMBMLOBP.js.map +1 -0
- package/dist/cli/{chunk-SZH34P45.js → chunk-O52OLQL3.js} +52 -18
- package/dist/cli/chunk-O52OLQL3.js.map +1 -0
- package/dist/cli/{chunk-4DCHFFEY.js → chunk-OSZC7C6F.js} +3 -2
- package/dist/cli/{chunk-4DCHFFEY.js.map → chunk-OSZC7C6F.js.map} +1 -1
- package/dist/cli/chunk-P7EKE5ZQ.js +60641 -0
- package/dist/cli/chunk-P7EKE5ZQ.js.map +1 -0
- package/dist/cli/{chunk-FM57FNPJ.js → chunk-PLHAZOLZ.js} +2 -1
- package/dist/cli/{chunk-FM57FNPJ.js.map → chunk-PLHAZOLZ.js.map} +1 -1
- package/dist/cli/{chunk-RFX7TYVV.js → chunk-PQXPXJBJ.js} +16 -2
- package/dist/cli/chunk-PQXPXJBJ.js.map +1 -0
- package/dist/cli/{chunk-DAEAAVDF.js → chunk-PV55UMTO.js} +2 -1
- package/dist/cli/{chunk-DAEAAVDF.js.map → chunk-PV55UMTO.js.map} +1 -1
- package/dist/cli/{chunk-H7PHYVPM.js → chunk-RE4RAVFF.js} +85 -14
- package/dist/cli/chunk-RE4RAVFF.js.map +1 -0
- package/dist/cli/chunk-S4XVGLRW.js +499 -0
- package/dist/cli/chunk-S4XVGLRW.js.map +1 -0
- package/dist/cli/{chunk-WJ3YX4PZ.js → chunk-SZ5XES2N.js} +3 -2
- package/dist/cli/{chunk-WJ3YX4PZ.js.map → chunk-SZ5XES2N.js.map} +1 -1
- package/dist/cli/{chunk-4X3NY5ZM.js → chunk-TJX6BFZZ.js} +16 -9
- package/dist/cli/{chunk-4X3NY5ZM.js.map → chunk-TJX6BFZZ.js.map} +1 -1
- package/dist/cli/chunk-TUK7OWJA.js +51 -0
- package/dist/cli/{chunk-WKOMCPXP.js → chunk-VK5HG73G.js} +26 -17
- package/dist/cli/chunk-VK5HG73G.js.map +1 -0
- package/dist/cli/{chunk-CLAN6PVH.js → chunk-XCGGEJTI.js} +21 -8
- package/dist/cli/chunk-XCGGEJTI.js.map +1 -0
- package/dist/cli/{chunk-SOZE7V7V.js → chunk-XJXDHAES.js} +3 -2
- package/dist/cli/{chunk-SOZE7V7V.js.map → chunk-XJXDHAES.js.map} +1 -1
- package/dist/cli/chunk-XPDVG52A.js +2648 -0
- package/dist/cli/chunk-XPDVG52A.js.map +1 -0
- package/dist/cli/{chunk-CRPQUBP6.js → chunk-XXC2BYTV.js} +2 -1
- package/dist/cli/{chunk-CRPQUBP6.js.map → chunk-XXC2BYTV.js.map} +1 -1
- package/dist/cli/{chunk-AVB3WZWU.js → chunk-YFGF5NKA.js} +17 -14
- package/dist/cli/{chunk-AVB3WZWU.js.map → chunk-YFGF5NKA.js.map} +1 -1
- package/dist/cli/{chunk-ORM6PK57.js → chunk-YQ6NTIIE.js} +2 -1
- package/dist/cli/{chunk-ORM6PK57.js.map → chunk-YQ6NTIIE.js.map} +1 -1
- package/dist/cli/{chunk-ULBW7DYL.js → chunk-YYQAUTTN.js} +3 -2
- package/dist/cli/{chunk-ULBW7DYL.js.map → chunk-YYQAUTTN.js.map} +1 -1
- package/dist/cli/chunk-ZZM6QJ4W.js +109 -0
- package/dist/cli/chunk-ZZM6QJ4W.js.map +1 -0
- package/dist/cli/code-SMKEW6CD.js +154 -0
- package/dist/cli/code-SMKEW6CD.js.map +1 -0
- package/dist/cli/{commands-FQZOBLLZ.js → commands-FVVB5FZF.js} +7 -5
- package/dist/cli/{commands-FQZOBLLZ.js.map → commands-FVVB5FZF.js.map} +1 -1
- package/dist/cli/{commit-ZS24SHPG.js → commit-HE4VSPZ7.js} +7 -4
- package/dist/cli/{commit-ZS24SHPG.js.map → commit-HE4VSPZ7.js.map} +1 -1
- package/dist/cli/{desktop-6OLENOOO.js → desktop-Q7NDXCON.js} +379 -72
- package/dist/cli/desktop-Q7NDXCON.js.map +1 -0
- package/dist/cli/devtools-YECO25QO.js +3719 -0
- package/dist/cli/devtools-YECO25QO.js.map +1 -0
- package/dist/cli/diff-435UTPC5.js +165 -0
- package/dist/cli/{diff-2VUKNGEI.js.map → diff-435UTPC5.js.map} +1 -1
- package/dist/cli/doctor-OT7KH75K.js +27 -0
- package/dist/cli/{events-APSVNROZ.js → events-XEFAD5VX.js} +6 -4
- package/dist/cli/{events-APSVNROZ.js.map → events-XEFAD5VX.js.map} +1 -1
- package/dist/cli/index.js +3233 -123
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-DCKOE5RF.js → mcp-WUL2WO75.js} +6 -4
- package/dist/cli/{mcp-DCKOE5RF.js.map → mcp-WUL2WO75.js.map} +1 -1
- package/dist/cli/{mcp-browse-D6GBP5RQ.js → mcp-browse-RR7R4XET.js} +34 -19
- package/dist/cli/mcp-browse-RR7R4XET.js.map +1 -0
- package/dist/cli/{mcp-inspect-KFGFPJ3E.js → mcp-inspect-REGLYBWT.js} +9 -8
- package/dist/cli/{mcp-inspect-KFGFPJ3E.js.map → mcp-inspect-REGLYBWT.js.map} +1 -1
- package/dist/cli/package.json +3 -0
- package/dist/cli/prompt-UW6EFLVR.js +16 -0
- package/dist/cli/{prune-sessions-LV33R47N.js → prune-sessions-3RWUBYRS.js} +4 -2
- package/dist/cli/{prune-sessions-LV33R47N.js.map → prune-sessions-3RWUBYRS.js.map} +1 -1
- package/dist/cli/{replay-WFCYX7XF.js → replay-YOURXV4C.js} +42 -30
- package/dist/cli/{replay-WFCYX7XF.js.map → replay-YOURXV4C.js.map} +1 -1
- package/dist/cli/{run-IUJYEPMT.js → run-Q6BUXV66.js} +28 -27
- package/dist/cli/{run-IUJYEPMT.js.map → run-Q6BUXV66.js.map} +1 -1
- package/dist/cli/{server-CN4QPPVJ.js → server-XGDBRWMB.js} +44 -43
- package/dist/cli/server-XGDBRWMB.js.map +1 -0
- package/dist/cli/{sessions-F5GPGTJN.js → sessions-FH7QVYSY.js} +22 -19
- package/dist/cli/{sessions-F5GPGTJN.js.map → sessions-FH7QVYSY.js.map} +1 -1
- package/dist/cli/setup-VDS6SVEP.js +618 -0
- package/dist/cli/setup-VDS6SVEP.js.map +1 -0
- package/dist/cli/stats-MQVI2XQH.js +14 -0
- package/dist/cli/update-6ITLPRDV.js +15 -0
- package/dist/cli/update-6ITLPRDV.js.map +1 -0
- package/dist/cli/version-DAHGZY5N.js +33 -0
- package/dist/cli/{version-KQUPV6T5.js.map → version-DAHGZY5N.js.map} +1 -1
- package/dist/index.d.ts +157 -103
- package/dist/index.js +597 -178
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/cli/chat-G7CUW4ZI.js +0 -45
- package/dist/cli/chunk-26UDIXLD.js +0 -16481
- package/dist/cli/chunk-26UDIXLD.js.map +0 -1
- package/dist/cli/chunk-4YV2GBYG.js +0 -5237
- package/dist/cli/chunk-4YV2GBYG.js.map +0 -1
- package/dist/cli/chunk-5X7LZJDE.js +0 -36
- package/dist/cli/chunk-5X7LZJDE.js.map +0 -1
- package/dist/cli/chunk-7DLHHBGN.js.map +0 -1
- package/dist/cli/chunk-A5LSGEEK.js.map +0 -1
- package/dist/cli/chunk-AFFZF3MW.js +0 -36
- package/dist/cli/chunk-AFFZF3MW.js.map +0 -1
- package/dist/cli/chunk-CLAN6PVH.js.map +0 -1
- package/dist/cli/chunk-CPOV2O73.js +0 -39
- package/dist/cli/chunk-CPOV2O73.js.map +0 -1
- package/dist/cli/chunk-CPTZ5OHX.js +0 -18
- package/dist/cli/chunk-CPTZ5OHX.js.map +0 -1
- package/dist/cli/chunk-CZSJILQP.js +0 -854
- package/dist/cli/chunk-CZSJILQP.js.map +0 -1
- package/dist/cli/chunk-H7PHYVPM.js.map +0 -1
- package/dist/cli/chunk-HCC42PEI.js.map +0 -1
- package/dist/cli/chunk-JWCTX5S4.js +0 -46
- package/dist/cli/chunk-KMWKGPFZ.js.map +0 -1
- package/dist/cli/chunk-MRLXEMZ7.js +0 -26
- package/dist/cli/chunk-MRLXEMZ7.js.map +0 -1
- package/dist/cli/chunk-R4YTW7PR.js.map +0 -1
- package/dist/cli/chunk-RFX7TYVV.js.map +0 -1
- package/dist/cli/chunk-SZH34P45.js.map +0 -1
- package/dist/cli/chunk-UVRXTSK3.js.map +0 -1
- package/dist/cli/chunk-VLNRQMCI.js.map +0 -1
- package/dist/cli/chunk-WKOMCPXP.js.map +0 -1
- package/dist/cli/chunk-XST7BSZJ.js.map +0 -1
- package/dist/cli/code-YQGVLIT2.js +0 -147
- package/dist/cli/code-YQGVLIT2.js.map +0 -1
- package/dist/cli/desktop-6OLENOOO.js.map +0 -1
- package/dist/cli/diff-2VUKNGEI.js +0 -153
- package/dist/cli/doctor-JO2WNN6C.js +0 -24
- package/dist/cli/mcp-browse-D6GBP5RQ.js.map +0 -1
- package/dist/cli/prompt-PKCCLLAD.js +0 -13
- package/dist/cli/server-CN4QPPVJ.js.map +0 -1
- package/dist/cli/setup-WWMDBPSB.js +0 -516
- package/dist/cli/setup-WWMDBPSB.js.map +0 -1
- package/dist/cli/stats-5RJCATCE.js +0 -12
- package/dist/cli/update-GUCWB4UN.js +0 -13
- package/dist/cli/version-KQUPV6T5.js +0 -30
- /package/dist/cli/{chat-G7CUW4ZI.js.map → chat-7ES4IBNH.js.map} +0 -0
- /package/dist/cli/{doctor-JO2WNN6C.js.map → chunk-TUK7OWJA.js.map} +0 -0
- /package/dist/cli/{prompt-PKCCLLAD.js.map → doctor-OT7KH75K.js.map} +0 -0
- /package/dist/cli/{stats-5RJCATCE.js.map → prompt-UW6EFLVR.js.map} +0 -0
- /package/dist/cli/{update-GUCWB4UN.js.map → stats-MQVI2XQH.js.map} +0 -0
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cr } from 'node:module'; if (typeof globalThis.require === 'undefined') { globalThis.require = __cr(import.meta.url); }
|
|
3
|
+
import {
|
|
4
|
+
buildCodeToolset
|
|
5
|
+
} from "./chunk-YFGF5NKA.js";
|
|
6
|
+
import {
|
|
7
|
+
Eventizer,
|
|
8
|
+
autoResolveVerdict
|
|
9
|
+
} from "./chunk-45U62RI3.js";
|
|
10
|
+
import {
|
|
11
|
+
formatMcpLifecycleEvent,
|
|
12
|
+
formatMcpSlowToast
|
|
13
|
+
} from "./chunk-H6PS7IUE.js";
|
|
14
|
+
import {
|
|
15
|
+
buildTransportFromSpec,
|
|
16
|
+
preflightStdioSpec
|
|
17
|
+
} from "./chunk-PQXPXJBJ.js";
|
|
18
|
+
import {
|
|
19
|
+
CacheFirstLoop,
|
|
20
|
+
ImmutablePrefix,
|
|
21
|
+
bridgeMcpTools
|
|
22
|
+
} from "./chunk-2R4QCDOZ.js";
|
|
23
|
+
import "./chunk-F3PXYSNN.js";
|
|
24
|
+
import {
|
|
25
|
+
openTranscriptFile,
|
|
26
|
+
recordFromLoopEvent,
|
|
27
|
+
writeRecord
|
|
28
|
+
} from "./chunk-FHOGSSCH.js";
|
|
29
|
+
import {
|
|
30
|
+
McpClient,
|
|
31
|
+
parseMcpSpec
|
|
32
|
+
} from "./chunk-6AK4EY3D.js";
|
|
33
|
+
import {
|
|
34
|
+
codeSystemPrompt
|
|
35
|
+
} from "./chunk-5JJRUIPA.js";
|
|
36
|
+
import {
|
|
37
|
+
canonicalPresetName,
|
|
38
|
+
resolvePreset
|
|
39
|
+
} from "./chunk-2425HK6U.js";
|
|
40
|
+
import "./chunk-PV55UMTO.js";
|
|
41
|
+
import {
|
|
42
|
+
DeepSeekClient
|
|
43
|
+
} from "./chunk-2KDUS647.js";
|
|
44
|
+
import "./chunk-25T6CVUP.js";
|
|
45
|
+
import {
|
|
46
|
+
loadDotenv
|
|
47
|
+
} from "./chunk-2UQP6H6T.js";
|
|
48
|
+
import "./chunk-YYQAUTTN.js";
|
|
49
|
+
import {
|
|
50
|
+
pauseGate
|
|
51
|
+
} from "./chunk-O52OLQL3.js";
|
|
52
|
+
import "./chunk-2K65GZBT.js";
|
|
53
|
+
import "./chunk-PLHAZOLZ.js";
|
|
54
|
+
import "./chunk-XCGGEJTI.js";
|
|
55
|
+
import "./chunk-7O5ALB4C.js";
|
|
56
|
+
import "./chunk-S4XVGLRW.js";
|
|
57
|
+
import {
|
|
58
|
+
timestampSuffix
|
|
59
|
+
} from "./chunk-6PBZN4VI.js";
|
|
60
|
+
import {
|
|
61
|
+
t
|
|
62
|
+
} from "./chunk-RE4RAVFF.js";
|
|
63
|
+
import {
|
|
64
|
+
loadApiKey,
|
|
65
|
+
loadBaseUrl,
|
|
66
|
+
loadEditMode,
|
|
67
|
+
loadPreset,
|
|
68
|
+
loadReasoningEffort,
|
|
69
|
+
mcpEnvFor,
|
|
70
|
+
readConfig
|
|
71
|
+
} from "./chunk-XPDVG52A.js";
|
|
72
|
+
import "./chunk-HFEAY5DT.js";
|
|
73
|
+
import "./chunk-YQ6NTIIE.js";
|
|
74
|
+
import {
|
|
75
|
+
VERSION
|
|
76
|
+
} from "./chunk-XXC2BYTV.js";
|
|
77
|
+
import "./chunk-TUK7OWJA.js";
|
|
78
|
+
|
|
79
|
+
// src/cli/commands/acp.ts
|
|
80
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
81
|
+
import { existsSync, statSync } from "fs";
|
|
82
|
+
import { resolve } from "path";
|
|
83
|
+
|
|
84
|
+
// src/acp/dispatch.ts
|
|
85
|
+
var READ_TOOLS = /* @__PURE__ */ new Set([
|
|
86
|
+
"read_file",
|
|
87
|
+
"list_directory",
|
|
88
|
+
"directory_tree",
|
|
89
|
+
"get_file_info",
|
|
90
|
+
"glob"
|
|
91
|
+
]);
|
|
92
|
+
var EDIT_TOOLS = /* @__PURE__ */ new Set([
|
|
93
|
+
"write_file",
|
|
94
|
+
"edit_file",
|
|
95
|
+
"multi_edit",
|
|
96
|
+
"create_directory",
|
|
97
|
+
"delete_file",
|
|
98
|
+
"delete_directory",
|
|
99
|
+
"move_file",
|
|
100
|
+
"copy_file"
|
|
101
|
+
]);
|
|
102
|
+
var SEARCH_TOOLS = /* @__PURE__ */ new Set(["search_content", "search_files"]);
|
|
103
|
+
var EXECUTE_TOOLS = /* @__PURE__ */ new Set(["run_command", "run_background"]);
|
|
104
|
+
function toolKindFor(name) {
|
|
105
|
+
if (READ_TOOLS.has(name)) return "read";
|
|
106
|
+
if (EDIT_TOOLS.has(name)) return "edit";
|
|
107
|
+
if (SEARCH_TOOLS.has(name)) return "search";
|
|
108
|
+
if (EXECUTE_TOOLS.has(name)) return "execute";
|
|
109
|
+
return "other";
|
|
110
|
+
}
|
|
111
|
+
function tryParseJson(raw) {
|
|
112
|
+
if (!raw) return void 0;
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(raw);
|
|
115
|
+
} catch {
|
|
116
|
+
return raw;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function dispatchKernelEvent(server, sessionId, ev) {
|
|
120
|
+
switch (ev.type) {
|
|
121
|
+
case "model.delta": {
|
|
122
|
+
if (!ev.text) return;
|
|
123
|
+
const variant = ev.channel === "reasoning" ? "agent_thought_chunk" : "agent_message_chunk";
|
|
124
|
+
emit(server, {
|
|
125
|
+
sessionId,
|
|
126
|
+
update: { sessionUpdate: variant, content: { type: "text", text: ev.text } }
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
case "tool.preparing": {
|
|
131
|
+
emit(server, {
|
|
132
|
+
sessionId,
|
|
133
|
+
update: {
|
|
134
|
+
sessionUpdate: "tool_call",
|
|
135
|
+
toolCallId: ev.callId,
|
|
136
|
+
title: ev.name,
|
|
137
|
+
kind: toolKindFor(ev.name),
|
|
138
|
+
status: "pending"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
case "tool.intent": {
|
|
144
|
+
emit(server, {
|
|
145
|
+
sessionId,
|
|
146
|
+
update: {
|
|
147
|
+
sessionUpdate: "tool_call_update",
|
|
148
|
+
toolCallId: ev.callId,
|
|
149
|
+
status: "in_progress"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const rawInput = tryParseJson(ev.args);
|
|
153
|
+
if (rawInput !== void 0) {
|
|
154
|
+
emit(server, {
|
|
155
|
+
sessionId,
|
|
156
|
+
update: {
|
|
157
|
+
sessionUpdate: "tool_call",
|
|
158
|
+
toolCallId: ev.callId,
|
|
159
|
+
title: ev.name,
|
|
160
|
+
kind: toolKindFor(ev.name),
|
|
161
|
+
status: "in_progress",
|
|
162
|
+
rawInput
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
case "tool.result": {
|
|
169
|
+
emit(server, {
|
|
170
|
+
sessionId,
|
|
171
|
+
update: {
|
|
172
|
+
sessionUpdate: "tool_call_update",
|
|
173
|
+
toolCallId: ev.callId,
|
|
174
|
+
status: ev.ok ? "completed" : "failed",
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
type: "content",
|
|
178
|
+
content: { type: "text", text: clip(ev.output) }
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
default:
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
var MAX_RESULT_CHARS = 8e3;
|
|
190
|
+
function clip(text) {
|
|
191
|
+
if (text.length <= MAX_RESULT_CHARS) return text;
|
|
192
|
+
return `${text.slice(0, MAX_RESULT_CHARS)}
|
|
193
|
+
\u2026(${text.length - MAX_RESULT_CHARS} more chars truncated)`;
|
|
194
|
+
}
|
|
195
|
+
function emit(server, params) {
|
|
196
|
+
server.sendNotification("session/update", params);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/acp/gates.ts
|
|
200
|
+
var ID_ALLOW_ONCE = "allow_once";
|
|
201
|
+
var ID_ALLOW_ALWAYS = "allow_always";
|
|
202
|
+
var ID_REJECT = "reject";
|
|
203
|
+
var ID_REFINE = "refine";
|
|
204
|
+
var ID_REVISE = "revise";
|
|
205
|
+
var ID_STOP = "stop";
|
|
206
|
+
var ID_CANCEL = "cancel";
|
|
207
|
+
var ID_ACCEPT = "accept";
|
|
208
|
+
function permissionOptionsFor(req) {
|
|
209
|
+
switch (req.kind) {
|
|
210
|
+
case "run_command":
|
|
211
|
+
case "run_background":
|
|
212
|
+
case "path_access":
|
|
213
|
+
return [
|
|
214
|
+
{ optionId: ID_ALLOW_ONCE, name: "Allow once", kind: "allow_once" },
|
|
215
|
+
{ optionId: ID_ALLOW_ALWAYS, name: "Allow always", kind: "allow_always" },
|
|
216
|
+
{ optionId: ID_REJECT, name: "Reject", kind: "reject_once" }
|
|
217
|
+
];
|
|
218
|
+
case "plan_proposed":
|
|
219
|
+
return [
|
|
220
|
+
{ optionId: ID_ALLOW_ONCE, name: "Approve plan", kind: "allow_once" },
|
|
221
|
+
{ optionId: ID_REFINE, name: "Refine", kind: "allow_once" },
|
|
222
|
+
{ optionId: ID_CANCEL, name: "Cancel", kind: "reject_once" }
|
|
223
|
+
];
|
|
224
|
+
case "plan_checkpoint":
|
|
225
|
+
return [
|
|
226
|
+
{ optionId: ID_ALLOW_ONCE, name: "Continue", kind: "allow_once" },
|
|
227
|
+
{ optionId: ID_REVISE, name: "Revise", kind: "allow_once" },
|
|
228
|
+
{ optionId: ID_STOP, name: "Stop", kind: "reject_once" }
|
|
229
|
+
];
|
|
230
|
+
case "plan_revision":
|
|
231
|
+
return [
|
|
232
|
+
{ optionId: ID_ACCEPT, name: "Accept revision", kind: "allow_once" },
|
|
233
|
+
{ optionId: ID_REJECT, name: "Keep original plan", kind: "reject_once" }
|
|
234
|
+
];
|
|
235
|
+
case "choice": {
|
|
236
|
+
const payload = req.payload;
|
|
237
|
+
const opts = (payload.options ?? []).map((o) => ({
|
|
238
|
+
optionId: o.id,
|
|
239
|
+
name: o.title ?? o.id,
|
|
240
|
+
kind: "allow_once"
|
|
241
|
+
}));
|
|
242
|
+
opts.push({ optionId: ID_CANCEL, name: "Cancel", kind: "reject_once" });
|
|
243
|
+
return opts;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function commandPrefix(command) {
|
|
248
|
+
const first = command.trim().split(/\s+/)[0] ?? command.trim();
|
|
249
|
+
return `${first} *`;
|
|
250
|
+
}
|
|
251
|
+
function pathPrefix(p) {
|
|
252
|
+
return p;
|
|
253
|
+
}
|
|
254
|
+
function verdictFor(req, result) {
|
|
255
|
+
const cancelled = result.outcome.outcome === "cancelled";
|
|
256
|
+
const optionId = result.outcome.outcome === "selected" ? result.outcome.optionId : null;
|
|
257
|
+
switch (req.kind) {
|
|
258
|
+
case "run_command":
|
|
259
|
+
case "run_background": {
|
|
260
|
+
if (cancelled || optionId === ID_REJECT) return { type: "deny" };
|
|
261
|
+
if (optionId === ID_ALLOW_ALWAYS) {
|
|
262
|
+
const payload = req.payload;
|
|
263
|
+
return { type: "always_allow", prefix: commandPrefix(payload.command ?? "") };
|
|
264
|
+
}
|
|
265
|
+
return { type: "run_once" };
|
|
266
|
+
}
|
|
267
|
+
case "path_access": {
|
|
268
|
+
if (cancelled || optionId === ID_REJECT) return { type: "deny" };
|
|
269
|
+
if (optionId === ID_ALLOW_ALWAYS) {
|
|
270
|
+
const payload = req.payload;
|
|
271
|
+
return { type: "always_allow", prefix: pathPrefix(payload.allowPrefix) };
|
|
272
|
+
}
|
|
273
|
+
return { type: "run_once" };
|
|
274
|
+
}
|
|
275
|
+
case "plan_proposed": {
|
|
276
|
+
if (cancelled || optionId === ID_CANCEL) return { type: "cancel" };
|
|
277
|
+
if (optionId === ID_REFINE) return { type: "refine" };
|
|
278
|
+
return { type: "approve" };
|
|
279
|
+
}
|
|
280
|
+
case "plan_checkpoint": {
|
|
281
|
+
if (cancelled || optionId === ID_STOP) return { type: "stop" };
|
|
282
|
+
if (optionId === ID_REVISE) return { type: "revise" };
|
|
283
|
+
return { type: "continue" };
|
|
284
|
+
}
|
|
285
|
+
case "plan_revision": {
|
|
286
|
+
if (cancelled) return { type: "cancelled" };
|
|
287
|
+
if (optionId === ID_ACCEPT) return { type: "accepted" };
|
|
288
|
+
return { type: "rejected" };
|
|
289
|
+
}
|
|
290
|
+
case "choice": {
|
|
291
|
+
if (cancelled || optionId === ID_CANCEL || !optionId) return { type: "cancel" };
|
|
292
|
+
return { type: "pick", optionId };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function permissionTitleFor(req) {
|
|
297
|
+
switch (req.kind) {
|
|
298
|
+
case "run_command":
|
|
299
|
+
case "run_background":
|
|
300
|
+
return `Run command \u2014 ${(req.payload.command ?? "").slice(0, 80)}`;
|
|
301
|
+
case "path_access":
|
|
302
|
+
return `Access path \u2014 ${req.payload.path}`;
|
|
303
|
+
case "plan_proposed":
|
|
304
|
+
return "Approve plan";
|
|
305
|
+
case "plan_checkpoint":
|
|
306
|
+
return `Checkpoint \u2014 ${req.payload.title ?? "step complete"}`;
|
|
307
|
+
case "plan_revision":
|
|
308
|
+
return "Approve plan revision";
|
|
309
|
+
case "choice":
|
|
310
|
+
return req.payload.question ?? "Choose an option";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function permissionKindFor(req) {
|
|
314
|
+
if (req.kind === "run_command" || req.kind === "run_background") return "execute";
|
|
315
|
+
if (req.kind === "path_access") {
|
|
316
|
+
return req.payload.intent === "write" ? "edit" : "other";
|
|
317
|
+
}
|
|
318
|
+
return "other";
|
|
319
|
+
}
|
|
320
|
+
async function requestPermissionForGate(server, sessionId, req) {
|
|
321
|
+
const params = {
|
|
322
|
+
sessionId,
|
|
323
|
+
toolCall: {
|
|
324
|
+
toolCallId: `gate-${req.id}`,
|
|
325
|
+
title: permissionTitleFor(req),
|
|
326
|
+
kind: permissionKindFor(req),
|
|
327
|
+
status: "pending",
|
|
328
|
+
rawInput: req.payload
|
|
329
|
+
},
|
|
330
|
+
options: permissionOptionsFor(req)
|
|
331
|
+
};
|
|
332
|
+
let result;
|
|
333
|
+
try {
|
|
334
|
+
result = await server.sendRequest(
|
|
335
|
+
"session/request_permission",
|
|
336
|
+
params
|
|
337
|
+
);
|
|
338
|
+
} catch {
|
|
339
|
+
result = { outcome: { outcome: "cancelled" } };
|
|
340
|
+
}
|
|
341
|
+
return verdictFor(req, result);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/acp/protocol.ts
|
|
345
|
+
var ACP_PROTOCOL_VERSION = 1;
|
|
346
|
+
var ERR_PARSE = -32700;
|
|
347
|
+
var ERR_METHOD_NOT_FOUND = -32601;
|
|
348
|
+
var ERR_INVALID_PARAMS = -32602;
|
|
349
|
+
var ERR_INTERNAL = -32603;
|
|
350
|
+
function flattenPrompt(blocks) {
|
|
351
|
+
const parts = [];
|
|
352
|
+
for (const b of blocks) {
|
|
353
|
+
if (b.type === "text") parts.push(b.text);
|
|
354
|
+
else if (b.type === "resource" && b.resource.text) parts.push(b.resource.text);
|
|
355
|
+
}
|
|
356
|
+
return parts.join("\n\n").trim();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/acp/server.ts
|
|
360
|
+
import { createInterface } from "readline";
|
|
361
|
+
var AcpServer = class {
|
|
362
|
+
requestHandlers = /* @__PURE__ */ new Map();
|
|
363
|
+
notificationHandlers = /* @__PURE__ */ new Map();
|
|
364
|
+
pending = /* @__PURE__ */ new Map();
|
|
365
|
+
nextOutboundId = 1;
|
|
366
|
+
output;
|
|
367
|
+
rl;
|
|
368
|
+
closed = false;
|
|
369
|
+
constructor(opts = {}) {
|
|
370
|
+
this.output = opts.output ?? process.stdout;
|
|
371
|
+
const input = opts.input ?? process.stdin;
|
|
372
|
+
this.rl = createInterface({ input });
|
|
373
|
+
this.rl.on("line", (line) => {
|
|
374
|
+
void this.handleLine(line);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
onRequest(method, handler) {
|
|
378
|
+
this.requestHandlers.set(method, handler);
|
|
379
|
+
}
|
|
380
|
+
onNotification(method, handler) {
|
|
381
|
+
this.notificationHandlers.set(method, handler);
|
|
382
|
+
}
|
|
383
|
+
sendNotification(method, params) {
|
|
384
|
+
this.write({ jsonrpc: "2.0", method, params });
|
|
385
|
+
}
|
|
386
|
+
/** Send an outbound JSON-RPC request and resolve when the peer responds. */
|
|
387
|
+
sendRequest(method, params) {
|
|
388
|
+
const id = this.nextOutboundId++;
|
|
389
|
+
return new Promise((resolve2, reject) => {
|
|
390
|
+
this.pending.set(id, {
|
|
391
|
+
resolve: resolve2,
|
|
392
|
+
reject
|
|
393
|
+
});
|
|
394
|
+
this.write({ jsonrpc: "2.0", id, method, params });
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
close() {
|
|
398
|
+
if (this.closed) return;
|
|
399
|
+
this.closed = true;
|
|
400
|
+
for (const p of this.pending.values()) p.reject(new Error("server closed"));
|
|
401
|
+
this.pending.clear();
|
|
402
|
+
this.rl.close();
|
|
403
|
+
}
|
|
404
|
+
/** Wait for the input stream to end. */
|
|
405
|
+
done() {
|
|
406
|
+
return new Promise((resolve2) => this.rl.once("close", () => resolve2()));
|
|
407
|
+
}
|
|
408
|
+
write(msg) {
|
|
409
|
+
this.output.write(`${JSON.stringify(msg)}
|
|
410
|
+
`);
|
|
411
|
+
}
|
|
412
|
+
writeError(id, code, message) {
|
|
413
|
+
this.write({ jsonrpc: "2.0", id, error: { code, message } });
|
|
414
|
+
}
|
|
415
|
+
async handleLine(raw) {
|
|
416
|
+
const line = raw.trim();
|
|
417
|
+
if (!line) return;
|
|
418
|
+
let parsed;
|
|
419
|
+
try {
|
|
420
|
+
parsed = JSON.parse(line);
|
|
421
|
+
} catch {
|
|
422
|
+
this.writeError(null, ERR_PARSE, "parse error");
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (!parsed || typeof parsed !== "object") {
|
|
426
|
+
this.writeError(null, ERR_PARSE, "expected JSON object");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const msg = parsed;
|
|
430
|
+
if (typeof msg.method === "string" && msg.id !== void 0) {
|
|
431
|
+
const id = msg.id;
|
|
432
|
+
const handler = this.requestHandlers.get(msg.method);
|
|
433
|
+
if (!handler) {
|
|
434
|
+
this.writeError(id, ERR_METHOD_NOT_FOUND, `method not found: ${msg.method}`);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
const result = await handler(msg.params);
|
|
439
|
+
this.write({ jsonrpc: "2.0", id, result });
|
|
440
|
+
} catch (err) {
|
|
441
|
+
this.writeError(id, ERR_INTERNAL, err.message);
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (typeof msg.method === "string" && msg.id === void 0) {
|
|
446
|
+
const handler = this.notificationHandlers.get(msg.method);
|
|
447
|
+
if (!handler) return;
|
|
448
|
+
try {
|
|
449
|
+
await handler(msg.params);
|
|
450
|
+
} catch {
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (msg.id !== void 0 && msg.method === void 0) {
|
|
455
|
+
const response = parsed;
|
|
456
|
+
const pending = this.pending.get(response.id);
|
|
457
|
+
if (!pending) return;
|
|
458
|
+
this.pending.delete(response.id);
|
|
459
|
+
if (response.error) {
|
|
460
|
+
pending.reject(new Error(response.error.message));
|
|
461
|
+
} else {
|
|
462
|
+
pending.resolve(response.result);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// src/cli/commands/acp.ts
|
|
469
|
+
function resolveMcpPrefix(specName, specCount, globalPrefix) {
|
|
470
|
+
if (specName) return `${specName}_`;
|
|
471
|
+
if (specCount === 1 && globalPrefix) return globalPrefix;
|
|
472
|
+
return "";
|
|
473
|
+
}
|
|
474
|
+
async function loadMcpServers(tools, specs, globalPrefix) {
|
|
475
|
+
const clients = [];
|
|
476
|
+
if (specs.length === 0) return clients;
|
|
477
|
+
const cfg = readConfig();
|
|
478
|
+
const disabledNames = new Set(cfg.mcpDisabled ?? []);
|
|
479
|
+
for (const raw of specs) {
|
|
480
|
+
let label = "anon";
|
|
481
|
+
let mcp;
|
|
482
|
+
try {
|
|
483
|
+
const spec = parseMcpSpec(raw);
|
|
484
|
+
label = spec.name ?? "anon";
|
|
485
|
+
if (spec.name && disabledNames.has(spec.name)) {
|
|
486
|
+
process.stderr.write(`${formatMcpLifecycleEvent({ state: "disabled", name: label })}
|
|
487
|
+
`);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
process.stderr.write(`${formatMcpLifecycleEvent({ state: "handshake", name: label })}
|
|
491
|
+
`);
|
|
492
|
+
const t0 = Date.now();
|
|
493
|
+
const prefix = resolveMcpPrefix(spec.name, specs.length, globalPrefix);
|
|
494
|
+
if (spec.transport === "stdio") preflightStdioSpec(spec);
|
|
495
|
+
const transport = buildTransportFromSpec(spec, { env: mcpEnvFor(spec.name, cfg) });
|
|
496
|
+
mcp = new McpClient({ transport });
|
|
497
|
+
await mcp.initialize();
|
|
498
|
+
const bridge = await bridgeMcpTools(mcp, {
|
|
499
|
+
registry: tools,
|
|
500
|
+
namePrefix: prefix,
|
|
501
|
+
serverName: label,
|
|
502
|
+
onSlow: (info) => process.stderr.write(
|
|
503
|
+
`${formatMcpSlowToast({ name: info.serverName, p95Ms: info.p95Ms, sampleSize: info.sampleSize })}
|
|
504
|
+
`
|
|
505
|
+
)
|
|
506
|
+
});
|
|
507
|
+
process.stderr.write(
|
|
508
|
+
`${formatMcpLifecycleEvent({
|
|
509
|
+
state: "connected",
|
|
510
|
+
name: label,
|
|
511
|
+
tools: bridge.registeredNames.length,
|
|
512
|
+
ms: Date.now() - t0
|
|
513
|
+
})}
|
|
514
|
+
`
|
|
515
|
+
);
|
|
516
|
+
clients.push(mcp);
|
|
517
|
+
} catch (err) {
|
|
518
|
+
await mcp?.close().catch(() => void 0);
|
|
519
|
+
process.stderr.write(
|
|
520
|
+
`${formatMcpLifecycleEvent({ state: "failed", name: label, reason: err.message })}
|
|
521
|
+
\u2192 ${t("mcpLifecycle.failedSetupConfigHint")}
|
|
522
|
+
`
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return clients;
|
|
527
|
+
}
|
|
528
|
+
function resolveDir(raw, fallback) {
|
|
529
|
+
if (!raw) return fallback;
|
|
530
|
+
const abs = resolve(raw);
|
|
531
|
+
if (!existsSync(abs) || !statSync(abs).isDirectory()) {
|
|
532
|
+
throw new Error(`workspace directory not found: ${abs}`);
|
|
533
|
+
}
|
|
534
|
+
return abs;
|
|
535
|
+
}
|
|
536
|
+
async function buildSession(opts) {
|
|
537
|
+
const preset = canonicalPresetName(loadPreset());
|
|
538
|
+
const resolved = resolvePreset(preset);
|
|
539
|
+
const model = opts.modelOverride || resolved.model;
|
|
540
|
+
const toolset = await buildCodeToolset({ rootDir: opts.rootDir });
|
|
541
|
+
const mcpClients = await loadMcpServers(toolset.tools, opts.mcpSpecs ?? [], opts.mcpPrefix);
|
|
542
|
+
const system = codeSystemPrompt(opts.rootDir, {
|
|
543
|
+
hasSemanticSearch: toolset.semantic.enabled,
|
|
544
|
+
modelId: model
|
|
545
|
+
});
|
|
546
|
+
const client = new DeepSeekClient({ baseUrl: loadBaseUrl() });
|
|
547
|
+
const prefix = new ImmutablePrefix({ system, toolSpecs: toolset.tools.specs() });
|
|
548
|
+
const loop = new CacheFirstLoop({
|
|
549
|
+
client,
|
|
550
|
+
prefix,
|
|
551
|
+
tools: toolset.tools,
|
|
552
|
+
model,
|
|
553
|
+
budgetUsd: opts.budgetUsd,
|
|
554
|
+
session: `acp-${timestampSuffix()}`
|
|
555
|
+
});
|
|
556
|
+
return {
|
|
557
|
+
id: `sess_${timestampSuffix()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
558
|
+
rootDir: opts.rootDir,
|
|
559
|
+
model,
|
|
560
|
+
toolset,
|
|
561
|
+
mcpClients,
|
|
562
|
+
loop,
|
|
563
|
+
eventizer: new Eventizer(),
|
|
564
|
+
ctx: {
|
|
565
|
+
model,
|
|
566
|
+
prefixHash: prefix.fingerprint,
|
|
567
|
+
reasoningEffort: loadReasoningEffort()
|
|
568
|
+
},
|
|
569
|
+
aborter: null
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
async function acpCommand(opts) {
|
|
573
|
+
loadDotenv();
|
|
574
|
+
if (loadApiKey()) {
|
|
575
|
+
process.env.DEEPSEEK_API_KEY = loadApiKey();
|
|
576
|
+
}
|
|
577
|
+
const defaultDir = resolveDir(opts.dir, process.cwd());
|
|
578
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
579
|
+
const sessionContext = new AsyncLocalStorage();
|
|
580
|
+
const server = new AcpServer();
|
|
581
|
+
let transcriptStream = null;
|
|
582
|
+
if (opts.transcript) {
|
|
583
|
+
const defaultModel = opts.model || resolvePreset(canonicalPresetName(loadPreset())).model;
|
|
584
|
+
transcriptStream = openTranscriptFile(opts.transcript, {
|
|
585
|
+
version: 1,
|
|
586
|
+
source: "reasonix acp",
|
|
587
|
+
model: defaultModel,
|
|
588
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
pauseGate.on((req) => {
|
|
592
|
+
const editMode = opts.yolo ? "yolo" : loadEditMode();
|
|
593
|
+
const auto = autoResolveVerdict(req, editMode);
|
|
594
|
+
if (auto !== null) {
|
|
595
|
+
pauseGate.resolve(req.id, auto);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const activeSessionId = sessionContext.getStore();
|
|
599
|
+
if (!activeSessionId || !sessions.has(activeSessionId)) {
|
|
600
|
+
pauseGate.cancel(req.id);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
void (async () => {
|
|
604
|
+
const verdict = await requestPermissionForGate(server, activeSessionId, req);
|
|
605
|
+
pauseGate.resolve(req.id, verdict);
|
|
606
|
+
})();
|
|
607
|
+
});
|
|
608
|
+
server.onRequest("initialize", (params) => {
|
|
609
|
+
if (!params || typeof params !== "object") {
|
|
610
|
+
throw Object.assign(new Error("initialize: missing params"), { code: ERR_INVALID_PARAMS });
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
614
|
+
agentCapabilities: {
|
|
615
|
+
loadSession: false,
|
|
616
|
+
promptCapabilities: { image: false, audio: false, embeddedContext: true },
|
|
617
|
+
mcpCapabilities: { http: false, sse: false }
|
|
618
|
+
},
|
|
619
|
+
agentInfo: { name: "reasonix", title: "Reasonix", version: VERSION },
|
|
620
|
+
authMethods: []
|
|
621
|
+
};
|
|
622
|
+
});
|
|
623
|
+
server.onRequest("session/new", async (params) => {
|
|
624
|
+
const rootDir = resolveDir(params?.cwd, defaultDir);
|
|
625
|
+
const session = await buildSession({
|
|
626
|
+
rootDir,
|
|
627
|
+
modelOverride: opts.model,
|
|
628
|
+
budgetUsd: opts.budgetUsd,
|
|
629
|
+
mcpSpecs: opts.mcpSpecs,
|
|
630
|
+
mcpPrefix: opts.mcpPrefix
|
|
631
|
+
});
|
|
632
|
+
sessions.set(session.id, session);
|
|
633
|
+
return { sessionId: session.id };
|
|
634
|
+
});
|
|
635
|
+
server.onRequest("session/prompt", async (params) => {
|
|
636
|
+
if (!params?.sessionId) {
|
|
637
|
+
throw Object.assign(new Error("session/prompt: missing sessionId"), {
|
|
638
|
+
code: ERR_INVALID_PARAMS
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
const session = sessions.get(params.sessionId);
|
|
642
|
+
if (!session) {
|
|
643
|
+
throw Object.assign(new Error(`session/prompt: unknown session ${params.sessionId}`), {
|
|
644
|
+
code: ERR_INVALID_PARAMS
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
const text = flattenPrompt(params.prompt);
|
|
648
|
+
if (!text) {
|
|
649
|
+
throw Object.assign(new Error("session/prompt: empty prompt"), { code: ERR_INVALID_PARAMS });
|
|
650
|
+
}
|
|
651
|
+
session.aborter = new AbortController();
|
|
652
|
+
let stopReason = "end_turn";
|
|
653
|
+
try {
|
|
654
|
+
await sessionContext.run(session.id, async () => {
|
|
655
|
+
for await (const ev of session.loop.step(text)) {
|
|
656
|
+
if (session.aborter?.signal.aborted) {
|
|
657
|
+
stopReason = "cancelled";
|
|
658
|
+
break;
|
|
659
|
+
}
|
|
660
|
+
if (transcriptStream) {
|
|
661
|
+
writeRecord(
|
|
662
|
+
transcriptStream,
|
|
663
|
+
recordFromLoopEvent(ev, {
|
|
664
|
+
model: session.ctx.model,
|
|
665
|
+
prefixHash: session.ctx.prefixHash
|
|
666
|
+
})
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
for (const kev of session.eventizer.consume(ev, session.ctx)) {
|
|
670
|
+
dispatchKernelEvent(server, session.id, kev);
|
|
671
|
+
if (kev.type === "error") stopReason = "error";
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
} catch (err) {
|
|
676
|
+
const message = err.message;
|
|
677
|
+
server.sendNotification("session/update", {
|
|
678
|
+
sessionId: session.id,
|
|
679
|
+
update: {
|
|
680
|
+
sessionUpdate: "agent_message_chunk",
|
|
681
|
+
content: { type: "text", text: `
|
|
682
|
+
|
|
683
|
+
[error] ${message}` }
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
stopReason = "error";
|
|
687
|
+
} finally {
|
|
688
|
+
session.aborter = null;
|
|
689
|
+
}
|
|
690
|
+
return { stopReason };
|
|
691
|
+
});
|
|
692
|
+
server.onNotification("session/cancel", (params) => {
|
|
693
|
+
const session = params?.sessionId ? sessions.get(params.sessionId) : void 0;
|
|
694
|
+
session?.aborter?.abort();
|
|
695
|
+
});
|
|
696
|
+
try {
|
|
697
|
+
await server.done();
|
|
698
|
+
} finally {
|
|
699
|
+
transcriptStream?.end();
|
|
700
|
+
const closes = [];
|
|
701
|
+
for (const session of sessions.values()) {
|
|
702
|
+
for (const mcp of session.mcpClients) {
|
|
703
|
+
closes.push(mcp.close().catch(() => void 0));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
await Promise.all(closes);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
export {
|
|
710
|
+
acpCommand,
|
|
711
|
+
loadMcpServers
|
|
712
|
+
};
|
|
713
|
+
//# sourceMappingURL=acp-DAGPCVFZ.js.map
|