@dev-anywhere/proxy 0.10.10 → 0.11.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/dist/{autostart-Y7PAITXN.js → autostart-ZEUB5VIE.js} +5 -5
- package/dist/{chunk-AR6KNZ2D.js → chunk-5DGT5OCO.js} +5 -5
- package/dist/chunk-7DIHPKGQ.js +892 -0
- package/dist/chunk-7DIHPKGQ.js.map +1 -0
- package/dist/{chunk-EMWUDUL4.js → chunk-7TJUPVKD.js} +2 -2
- package/dist/{chunk-D6G3TKLY.js → chunk-F73NHGQP.js} +3 -3
- package/dist/chunk-F73NHGQP.js.map +1 -0
- package/dist/{chunk-52OJHVZO.js → chunk-GBNUJCH4.js} +2 -2
- package/dist/chunk-GBNUJCH4.js.map +1 -0
- package/dist/{chunk-Q3CPWHHP.js → chunk-GGLHFEXA.js} +2 -2
- package/dist/{chunk-7BNZO6DB.js → chunk-GKG5ZNSI.js} +61 -4
- package/dist/chunk-GKG5ZNSI.js.map +1 -0
- package/dist/{chunk-RQKKZC5T.js → chunk-GSYEOTS5.js} +23 -9
- package/dist/chunk-GSYEOTS5.js.map +1 -0
- package/dist/{chunk-M3NPN6JZ.js → chunk-RSHWLFLA.js} +14 -11
- package/dist/chunk-RSHWLFLA.js.map +1 -0
- package/dist/{chunk-V3JJ352Q.js → chunk-SERCDXCV.js} +1 -1
- package/dist/chunk-SERCDXCV.js.map +1 -0
- package/dist/{chunk-AWAVTR2H.js → chunk-UOWFBLU4.js} +15 -8
- package/dist/chunk-UOWFBLU4.js.map +1 -0
- package/dist/{chunk-S2QVJFCM.js → chunk-XCQ7CGLY.js} +2 -52
- package/dist/chunk-XCQ7CGLY.js.map +1 -0
- package/dist/{chunk-5OJFDJ65.js → chunk-XEEHK4YQ.js} +101 -8
- package/dist/{chunk-5OJFDJ65.js.map → chunk-XEEHK4YQ.js.map} +1 -1
- package/dist/{chunk-RW32NTSD.js → chunk-YFCPLWNV.js} +3 -2
- package/dist/chunk-YFCPLWNV.js.map +1 -0
- package/dist/index.js +14 -14
- package/dist/{logger-U5XYVVXY.js → logger-4E3T7YWT.js} +3 -3
- package/dist/preview-worker.js +5 -5
- package/dist/{relay-token-LFUK2JW6.js → relay-token-YP4HZGIJ.js} +4 -4
- package/dist/serve.js +222 -88
- package/dist/serve.js.map +1 -1
- package/dist/{service-host-XIAWRF4P.js → service-host-XIBF772J.js} +3 -3
- package/dist/session-worker.js +48 -646
- package/dist/session-worker.js.map +1 -1
- package/dist/{terminal-ATPVD7KA.js → terminal-D2E4NE43.js} +16 -13
- package/dist/terminal-D2E4NE43.js.map +1 -0
- package/dist/terminal-worker.js +10 -10
- package/dist/update-runner.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-44IM5SVF.js +0 -205
- package/dist/chunk-44IM5SVF.js.map +0 -1
- package/dist/chunk-52OJHVZO.js.map +0 -1
- package/dist/chunk-7BNZO6DB.js.map +0 -1
- package/dist/chunk-AWAVTR2H.js.map +0 -1
- package/dist/chunk-D6G3TKLY.js.map +0 -1
- package/dist/chunk-M3NPN6JZ.js.map +0 -1
- package/dist/chunk-RQKKZC5T.js.map +0 -1
- package/dist/chunk-RW32NTSD.js.map +0 -1
- package/dist/chunk-S2QVJFCM.js.map +0 -1
- package/dist/chunk-V3JJ352Q.js.map +0 -1
- package/dist/terminal-ATPVD7KA.js.map +0 -1
- /package/dist/{autostart-Y7PAITXN.js.map → autostart-ZEUB5VIE.js.map} +0 -0
- /package/dist/{chunk-AR6KNZ2D.js.map → chunk-5DGT5OCO.js.map} +0 -0
- /package/dist/{chunk-EMWUDUL4.js.map → chunk-7TJUPVKD.js.map} +0 -0
- /package/dist/{chunk-Q3CPWHHP.js.map → chunk-GGLHFEXA.js.map} +0 -0
- /package/dist/{logger-U5XYVVXY.js.map → logger-4E3T7YWT.js.map} +0 -0
- /package/dist/{relay-token-LFUK2JW6.js.map → relay-token-YP4HZGIJ.js.map} +0 -0
- /package/dist/{service-host-XIAWRF4P.js.map → service-host-XIBF772J.js.map} +0 -0
package/dist/session-worker.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
AcpRpcError,
|
|
4
|
+
AcpSession,
|
|
3
5
|
ControlRequestEventSchema,
|
|
4
6
|
SeqCounter,
|
|
5
7
|
createApprovalRequestIdFactory
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-7DIHPKGQ.js";
|
|
7
9
|
import {
|
|
8
10
|
acceptCurrentWorkerSocketMessage,
|
|
9
11
|
readWorkerConnection,
|
|
@@ -15,22 +17,21 @@ import {
|
|
|
15
17
|
CLAUDE_PROVIDER,
|
|
16
18
|
CODEX_PROVIDER,
|
|
17
19
|
CURSOR_PROVIDER,
|
|
18
|
-
KIMI_PROVIDER,
|
|
19
20
|
cursorAcpAutoApprovesPermissions,
|
|
20
21
|
resolveCodexPermissionPolicy,
|
|
21
|
-
resolveCursorAcpMode
|
|
22
|
-
|
|
23
|
-
} from "./chunk-5OJFDJ65.js";
|
|
22
|
+
resolveCursorAcpMode
|
|
23
|
+
} from "./chunk-XEEHK4YQ.js";
|
|
24
24
|
import {
|
|
25
25
|
WORKER_IPC_PROTOCOL_VERSION,
|
|
26
26
|
createWorkerReader,
|
|
27
27
|
serializeWorkerMsg
|
|
28
|
-
} from "./chunk-
|
|
29
|
-
import "./chunk-
|
|
28
|
+
} from "./chunk-F73NHGQP.js";
|
|
29
|
+
import "./chunk-SERCDXCV.js";
|
|
30
30
|
import {
|
|
31
31
|
ControlErrorCode,
|
|
32
|
-
LineBuffer
|
|
33
|
-
|
|
32
|
+
LineBuffer,
|
|
33
|
+
isProviderId
|
|
34
|
+
} from "./chunk-UOWFBLU4.js";
|
|
34
35
|
import {
|
|
35
36
|
prepareLocalIpcEndpoint,
|
|
36
37
|
removeLocalIpcEndpoint,
|
|
@@ -50,7 +51,7 @@ import {
|
|
|
50
51
|
spawnCommand
|
|
51
52
|
} from "./chunk-EWIHC4BK.js";
|
|
52
53
|
import "./chunk-HJOYOYGB.js";
|
|
53
|
-
import "./chunk-
|
|
54
|
+
import "./chunk-GKG5ZNSI.js";
|
|
54
55
|
|
|
55
56
|
// src/session-worker.ts
|
|
56
57
|
import { createServer } from "net";
|
|
@@ -1536,611 +1537,6 @@ var CursorAcpSession = class {
|
|
|
1536
1537
|
}
|
|
1537
1538
|
};
|
|
1538
1539
|
|
|
1539
|
-
// src/worker/kimi-acp-session.ts
|
|
1540
|
-
var CLIENT_INFO3 = {
|
|
1541
|
-
name: "dev-anywhere",
|
|
1542
|
-
title: "Dev Anywhere",
|
|
1543
|
-
version: PROXY_VERSION
|
|
1544
|
-
};
|
|
1545
|
-
var DEFAULT_REQUEST_TIMEOUT_MS3 = 1e4;
|
|
1546
|
-
var DEFAULT_CANCEL_ACKNOWLEDGE_TIMEOUT_MS2 = 2e3;
|
|
1547
|
-
var STDERR_TAIL_LIMIT4 = 8192;
|
|
1548
|
-
var CANCELLED_RESPONSE_TOMBSTONE_LIMIT2 = 128;
|
|
1549
|
-
var denyPermission2 = () => ({
|
|
1550
|
-
behavior: "deny",
|
|
1551
|
-
message: "Tool use denied by default policy. Remote approval is not configured."
|
|
1552
|
-
});
|
|
1553
|
-
function isRecord3(value) {
|
|
1554
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1555
|
-
}
|
|
1556
|
-
function toError3(error) {
|
|
1557
|
-
return error instanceof Error ? error : new Error(String(error));
|
|
1558
|
-
}
|
|
1559
|
-
function normalizeApprovalInput3(value) {
|
|
1560
|
-
if (!isRecord3(value)) return {};
|
|
1561
|
-
const input = { ...value };
|
|
1562
|
-
if (Array.isArray(input.command)) {
|
|
1563
|
-
input.command = input.command.map((part) => String(part)).join(" ");
|
|
1564
|
-
}
|
|
1565
|
-
return input;
|
|
1566
|
-
}
|
|
1567
|
-
function parsePermissionOptions2(value) {
|
|
1568
|
-
if (!Array.isArray(value)) return [];
|
|
1569
|
-
const options = [];
|
|
1570
|
-
for (const candidate of value) {
|
|
1571
|
-
if (!isRecord3(candidate) || typeof candidate.optionId !== "string") continue;
|
|
1572
|
-
options.push({
|
|
1573
|
-
...candidate,
|
|
1574
|
-
optionId: candidate.optionId,
|
|
1575
|
-
name: typeof candidate.name === "string" ? candidate.name : candidate.optionId,
|
|
1576
|
-
kind: typeof candidate.kind === "string" ? candidate.kind : ""
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
return options;
|
|
1580
|
-
}
|
|
1581
|
-
function normalizedOptionText2(option) {
|
|
1582
|
-
return `${option.optionId} ${option.name}`.toLowerCase().replace(/[^a-z0-9]+/g, " ");
|
|
1583
|
-
}
|
|
1584
|
-
function isAllowOption2(option) {
|
|
1585
|
-
const text = normalizedOptionText2(option);
|
|
1586
|
-
return option.kind.startsWith("allow") || /\b(allow|approve|accept)\b/.test(text);
|
|
1587
|
-
}
|
|
1588
|
-
function isAlwaysOption2(option) {
|
|
1589
|
-
const text = normalizedOptionText2(option);
|
|
1590
|
-
return option.kind === "allow_always" || /\b(always|session|persist)\b/.test(text);
|
|
1591
|
-
}
|
|
1592
|
-
function isDenyOption2(option) {
|
|
1593
|
-
const text = normalizedOptionText2(option);
|
|
1594
|
-
return option.kind.startsWith("reject") || /\b(reject|deny|decline|cancel|skip)\b/.test(text);
|
|
1595
|
-
}
|
|
1596
|
-
function optionMatchesBehavior2(option, behavior) {
|
|
1597
|
-
if (behavior === "deny") return isDenyOption2(option);
|
|
1598
|
-
if (behavior === "allow_always") {
|
|
1599
|
-
return isAllowOption2(option) && isAlwaysOption2(option);
|
|
1600
|
-
}
|
|
1601
|
-
return isAllowOption2(option) && !isAlwaysOption2(option);
|
|
1602
|
-
}
|
|
1603
|
-
function selectPermissionOption2(options, behavior) {
|
|
1604
|
-
if (behavior === "deny") {
|
|
1605
|
-
return options.find((option) => option.kind.startsWith("reject")) ?? options.find(isDenyOption2);
|
|
1606
|
-
}
|
|
1607
|
-
if (behavior === "allow_always") {
|
|
1608
|
-
return options.find((option) => option.kind === "allow_always") ?? options.find((option) => isAllowOption2(option) && isAlwaysOption2(option)) ?? // Never upgrade a one-shot decision, but safely downgrade a persistent allow when the
|
|
1609
|
-
// provider only advertises allow-once.
|
|
1610
|
-
options.find((option) => option.kind === "allow_once") ?? options.find((option) => isAllowOption2(option) && !isAlwaysOption2(option));
|
|
1611
|
-
}
|
|
1612
|
-
return options.find((option) => option.kind === "allow_once") ?? options.find((option) => isAllowOption2(option) && !isAlwaysOption2(option));
|
|
1613
|
-
}
|
|
1614
|
-
function promptResult2(value) {
|
|
1615
|
-
return isRecord3(value) ? value : {};
|
|
1616
|
-
}
|
|
1617
|
-
function responseErrorMessage2(error) {
|
|
1618
|
-
return typeof error.message === "string" ? error.message : "Kimi ACP request failed";
|
|
1619
|
-
}
|
|
1620
|
-
var KimiAcpRpcError = class extends Error {
|
|
1621
|
-
constructor(method, code, message, data) {
|
|
1622
|
-
super(`Kimi ACP ${method} failed${code === void 0 ? "" : ` (${code})`}: ${message}`);
|
|
1623
|
-
this.method = method;
|
|
1624
|
-
this.code = code;
|
|
1625
|
-
this.data = data;
|
|
1626
|
-
this.name = "KimiAcpRpcError";
|
|
1627
|
-
}
|
|
1628
|
-
method;
|
|
1629
|
-
code;
|
|
1630
|
-
data;
|
|
1631
|
-
};
|
|
1632
|
-
var KimiAcpProtocolError = class extends Error {
|
|
1633
|
-
constructor(message, payload) {
|
|
1634
|
-
super(message);
|
|
1635
|
-
this.payload = payload;
|
|
1636
|
-
this.name = "KimiAcpProtocolError";
|
|
1637
|
-
}
|
|
1638
|
-
payload;
|
|
1639
|
-
};
|
|
1640
|
-
var KimiAcpSession = class {
|
|
1641
|
-
child = null;
|
|
1642
|
-
stderrTail = "";
|
|
1643
|
-
nextRequestId = 1;
|
|
1644
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
1645
|
-
pendingPermissions = /* @__PURE__ */ new Map();
|
|
1646
|
-
cancelledResponseIds = /* @__PURE__ */ new Set();
|
|
1647
|
-
toolCalls = /* @__PURE__ */ new Map();
|
|
1648
|
-
sessionReady;
|
|
1649
|
-
resolveSessionReady = () => {
|
|
1650
|
-
};
|
|
1651
|
-
rejectSessionReady = () => {
|
|
1652
|
-
};
|
|
1653
|
-
sessionReadySettled = false;
|
|
1654
|
-
exitReported = false;
|
|
1655
|
-
closed = false;
|
|
1656
|
-
transportFailure = null;
|
|
1657
|
-
sessionId = null;
|
|
1658
|
-
activePrompt = null;
|
|
1659
|
-
promptQueue = Promise.resolve();
|
|
1660
|
-
workDir;
|
|
1661
|
-
resumeSessionId;
|
|
1662
|
-
acpMode;
|
|
1663
|
-
requestTimeoutMs;
|
|
1664
|
-
promptTimeoutMs;
|
|
1665
|
-
cancelAcknowledgeTimeoutMs;
|
|
1666
|
-
onUpdate;
|
|
1667
|
-
onNotification;
|
|
1668
|
-
onPermissionRequest;
|
|
1669
|
-
onPromptStart;
|
|
1670
|
-
onPromptComplete;
|
|
1671
|
-
onPromptError;
|
|
1672
|
-
onSessionId;
|
|
1673
|
-
onProtocolError;
|
|
1674
|
-
onProcessError;
|
|
1675
|
-
onExitCb;
|
|
1676
|
-
constructor(options = {}) {
|
|
1677
|
-
this.workDir = options.cwd ?? options.workDir ?? process.cwd();
|
|
1678
|
-
this.resumeSessionId = options.resumeSessionId;
|
|
1679
|
-
this.acpMode = resolveKimiAcpMode(options.permissionMode);
|
|
1680
|
-
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS3;
|
|
1681
|
-
this.promptTimeoutMs = options.promptTimeoutMs ?? 0;
|
|
1682
|
-
this.cancelAcknowledgeTimeoutMs = options.cancelAcknowledgeTimeoutMs ?? DEFAULT_CANCEL_ACKNOWLEDGE_TIMEOUT_MS2;
|
|
1683
|
-
this.onUpdate = options.onUpdate;
|
|
1684
|
-
this.onNotification = options.onNotification;
|
|
1685
|
-
this.onPermissionRequest = options.onPermissionRequest ?? denyPermission2;
|
|
1686
|
-
this.onPromptStart = options.onPromptStart;
|
|
1687
|
-
this.onPromptComplete = options.onPromptComplete;
|
|
1688
|
-
this.onPromptError = options.onPromptError;
|
|
1689
|
-
this.onSessionId = options.onSessionId;
|
|
1690
|
-
this.onProtocolError = options.onProtocolError;
|
|
1691
|
-
this.onProcessError = options.onProcessError;
|
|
1692
|
-
this.onExitCb = options.onExit;
|
|
1693
|
-
this.sessionReady = new Promise((resolve, reject) => {
|
|
1694
|
-
this.resolveSessionReady = resolve;
|
|
1695
|
-
this.rejectSessionReady = reject;
|
|
1696
|
-
});
|
|
1697
|
-
}
|
|
1698
|
-
getKimiSessionId() {
|
|
1699
|
-
return this.sessionId;
|
|
1700
|
-
}
|
|
1701
|
-
getPendingPermission(requestId) {
|
|
1702
|
-
return this.pendingPermissions.get(requestId)?.request;
|
|
1703
|
-
}
|
|
1704
|
-
start() {
|
|
1705
|
-
if (this.child) throw new Error("Kimi ACP session has already been started");
|
|
1706
|
-
const command = KIMI_PROVIDER.buildJsonCommand({ cwd: this.workDir }, process.env);
|
|
1707
|
-
this.child = spawnCommand(command.command, command.args, {
|
|
1708
|
-
cwd: this.workDir,
|
|
1709
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
1710
|
-
env: command.env
|
|
1711
|
-
});
|
|
1712
|
-
this.setupStdoutParsing();
|
|
1713
|
-
this.setupStderrCollection();
|
|
1714
|
-
this.setupExitHandler();
|
|
1715
|
-
void this.initializeSession().catch((error) => this.rejectSessionReadyOnce(toError3(error)));
|
|
1716
|
-
if (!this.child.pid) throw new Error("Kimi ACP failed to start: missing child pid");
|
|
1717
|
-
return this.child.pid;
|
|
1718
|
-
}
|
|
1719
|
-
waitUntilReady() {
|
|
1720
|
-
return this.sessionReady;
|
|
1721
|
-
}
|
|
1722
|
-
sendMessage(content) {
|
|
1723
|
-
this.promptQueue = this.promptQueue.then(() => this.runPrompt(content));
|
|
1724
|
-
}
|
|
1725
|
-
async interruptCurrentTurn() {
|
|
1726
|
-
const activePrompt = this.activePrompt;
|
|
1727
|
-
if (!activePrompt || activePrompt.cancelled || !this.sessionId) return false;
|
|
1728
|
-
activePrompt.cancelled = true;
|
|
1729
|
-
if (!this.writeLine({
|
|
1730
|
-
jsonrpc: "2.0",
|
|
1731
|
-
method: "session/cancel",
|
|
1732
|
-
params: { sessionId: this.sessionId }
|
|
1733
|
-
})) {
|
|
1734
|
-
activePrompt.cancelled = false;
|
|
1735
|
-
return false;
|
|
1736
|
-
}
|
|
1737
|
-
this.cancelPendingPermissions();
|
|
1738
|
-
if (this.cancelAcknowledgeTimeoutMs <= 0) {
|
|
1739
|
-
this.abortUnacknowledgedCancellation(activePrompt);
|
|
1740
|
-
} else {
|
|
1741
|
-
activePrompt.cancelSettleTimer = setTimeout(
|
|
1742
|
-
() => this.abortUnacknowledgedCancellation(activePrompt),
|
|
1743
|
-
this.cancelAcknowledgeTimeoutMs
|
|
1744
|
-
);
|
|
1745
|
-
activePrompt.cancelSettleTimer.unref?.();
|
|
1746
|
-
}
|
|
1747
|
-
return true;
|
|
1748
|
-
}
|
|
1749
|
-
async close() {
|
|
1750
|
-
if (this.closed) return;
|
|
1751
|
-
if (!this.child) throw new Error("Kimi ACP session has not been started");
|
|
1752
|
-
const sessionId2 = this.sessionId ?? await this.sessionReady;
|
|
1753
|
-
await this.request("session/close", { sessionId: sessionId2 });
|
|
1754
|
-
this.closed = true;
|
|
1755
|
-
}
|
|
1756
|
-
async stop(gracePeriodMs = 5e3) {
|
|
1757
|
-
const child = this.child;
|
|
1758
|
-
if (!child || !this.isAlive()) return;
|
|
1759
|
-
if (this.activePrompt) await this.interruptCurrentTurn();
|
|
1760
|
-
if (this.sessionId && !this.closed) {
|
|
1761
|
-
try {
|
|
1762
|
-
await this.close();
|
|
1763
|
-
} catch (error) {
|
|
1764
|
-
this.appendStderr(`Kimi ACP close failed: ${toError3(error).message}
|
|
1765
|
-
`);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
terminateOwnedProcessTree(child, "SIGTERM");
|
|
1769
|
-
const startedAt = Date.now();
|
|
1770
|
-
while (Date.now() - startedAt < gracePeriodMs) {
|
|
1771
|
-
if (!this.isChildAlive(child)) return;
|
|
1772
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1773
|
-
}
|
|
1774
|
-
if (this.isChildAlive(child)) terminateOwnedProcessTree(child, "SIGKILL");
|
|
1775
|
-
}
|
|
1776
|
-
isAlive() {
|
|
1777
|
-
return this.child ? this.isChildAlive(this.child) : false;
|
|
1778
|
-
}
|
|
1779
|
-
getStderr() {
|
|
1780
|
-
return this.stderrTail;
|
|
1781
|
-
}
|
|
1782
|
-
isChildAlive(child) {
|
|
1783
|
-
if (!child.pid) return false;
|
|
1784
|
-
try {
|
|
1785
|
-
process.kill(child.pid, 0);
|
|
1786
|
-
return true;
|
|
1787
|
-
} catch {
|
|
1788
|
-
return false;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
async initializeSession() {
|
|
1792
|
-
await this.request("initialize", {
|
|
1793
|
-
protocolVersion: 1,
|
|
1794
|
-
clientCapabilities: {
|
|
1795
|
-
fs: { readTextFile: false, writeTextFile: false },
|
|
1796
|
-
terminal: false
|
|
1797
|
-
},
|
|
1798
|
-
clientInfo: CLIENT_INFO3
|
|
1799
|
-
});
|
|
1800
|
-
const result = this.resumeSessionId ? await this.request("session/resume", {
|
|
1801
|
-
sessionId: this.resumeSessionId,
|
|
1802
|
-
cwd: this.workDir,
|
|
1803
|
-
mcpServers: []
|
|
1804
|
-
}) : await this.request("session/new", {
|
|
1805
|
-
cwd: this.workDir,
|
|
1806
|
-
mcpServers: []
|
|
1807
|
-
});
|
|
1808
|
-
const sessionId2 = this.resumeSessionId ?? this.sessionIdFromResult(result);
|
|
1809
|
-
if (!sessionId2) throw new Error("Kimi ACP session/new did not return a session id");
|
|
1810
|
-
await this.request("session/set_mode", { sessionId: sessionId2, modeId: this.acpMode });
|
|
1811
|
-
this.sessionId = sessionId2;
|
|
1812
|
-
this.onSessionId?.(sessionId2);
|
|
1813
|
-
this.resolveSessionReadyOnce(sessionId2);
|
|
1814
|
-
}
|
|
1815
|
-
sessionIdFromResult(result) {
|
|
1816
|
-
if (!isRecord3(result)) return null;
|
|
1817
|
-
return typeof result.sessionId === "string" ? result.sessionId : null;
|
|
1818
|
-
}
|
|
1819
|
-
async runPrompt(content) {
|
|
1820
|
-
let prompt = null;
|
|
1821
|
-
try {
|
|
1822
|
-
const sessionId2 = await this.sessionReady;
|
|
1823
|
-
if (this.transportFailure) throw this.transportFailure;
|
|
1824
|
-
const currentPrompt = { cancelled: false };
|
|
1825
|
-
prompt = currentPrompt;
|
|
1826
|
-
this.activePrompt = currentPrompt;
|
|
1827
|
-
this.invokeCallback(() => this.onPromptStart?.(), "session/prompt start callback failed");
|
|
1828
|
-
const result = await this.request(
|
|
1829
|
-
"session/prompt",
|
|
1830
|
-
{
|
|
1831
|
-
sessionId: sessionId2,
|
|
1832
|
-
prompt: [{ type: "text", text: content }]
|
|
1833
|
-
},
|
|
1834
|
-
this.promptTimeoutMs,
|
|
1835
|
-
(requestId) => {
|
|
1836
|
-
if (this.activePrompt === currentPrompt) currentPrompt.requestId = requestId;
|
|
1837
|
-
}
|
|
1838
|
-
);
|
|
1839
|
-
if (!prompt.cancelled) {
|
|
1840
|
-
this.invokeCallback(
|
|
1841
|
-
() => this.onPromptComplete?.(promptResult2(result)),
|
|
1842
|
-
"session/prompt completion callback failed"
|
|
1843
|
-
);
|
|
1844
|
-
}
|
|
1845
|
-
} catch (error) {
|
|
1846
|
-
if (!prompt?.cancelled) {
|
|
1847
|
-
this.invokeCallback(
|
|
1848
|
-
() => this.onPromptError?.(toError3(error)),
|
|
1849
|
-
"session/prompt error callback failed"
|
|
1850
|
-
);
|
|
1851
|
-
}
|
|
1852
|
-
} finally {
|
|
1853
|
-
if (prompt?.cancelSettleTimer) clearTimeout(prompt.cancelSettleTimer);
|
|
1854
|
-
if (this.activePrompt === prompt) this.activePrompt = null;
|
|
1855
|
-
this.toolCalls.clear();
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
request(method, params, timeoutMs = this.requestTimeoutMs, onRequestId) {
|
|
1859
|
-
const id = this.nextRequestId++;
|
|
1860
|
-
onRequestId?.(id);
|
|
1861
|
-
const payload = { jsonrpc: "2.0", id, method, params };
|
|
1862
|
-
return new Promise((resolve, reject) => {
|
|
1863
|
-
const timeout = timeoutMs > 0 ? setTimeout(() => {
|
|
1864
|
-
this.pendingRequests.delete(id);
|
|
1865
|
-
reject(new Error(`Kimi ACP request ${method} timed out after ${timeoutMs}ms`));
|
|
1866
|
-
}, timeoutMs) : void 0;
|
|
1867
|
-
timeout?.unref?.();
|
|
1868
|
-
this.pendingRequests.set(id, { method, resolve, reject, timeout });
|
|
1869
|
-
if (!this.writeLine(payload)) {
|
|
1870
|
-
if (timeout) clearTimeout(timeout);
|
|
1871
|
-
this.pendingRequests.delete(id);
|
|
1872
|
-
reject(new Error(`Kimi ACP stdin is not writable for ${method}`));
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
writeLine(payload) {
|
|
1877
|
-
if (this.transportFailure || !this.child?.stdin?.writable) return false;
|
|
1878
|
-
try {
|
|
1879
|
-
this.child.stdin.write(`${JSON.stringify(payload)}
|
|
1880
|
-
`);
|
|
1881
|
-
return true;
|
|
1882
|
-
} catch (error) {
|
|
1883
|
-
this.reportProtocolError(new KimiAcpProtocolError("Failed to write Kimi ACP message", error));
|
|
1884
|
-
return false;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
setupStdoutParsing() {
|
|
1888
|
-
const child = this.child;
|
|
1889
|
-
if (!child?.stdout) return;
|
|
1890
|
-
const lineBuffer = new LineBuffer();
|
|
1891
|
-
child.stdout.pipe(lineBuffer);
|
|
1892
|
-
lineBuffer.on("data", (line) => {
|
|
1893
|
-
const text = typeof line === "string" ? line : line.toString();
|
|
1894
|
-
let message;
|
|
1895
|
-
try {
|
|
1896
|
-
message = JSON.parse(text);
|
|
1897
|
-
} catch (error) {
|
|
1898
|
-
this.reportProtocolError(
|
|
1899
|
-
new KimiAcpProtocolError(`Invalid Kimi ACP JSON: ${toError3(error).message}`, text),
|
|
1900
|
-
text
|
|
1901
|
-
);
|
|
1902
|
-
return;
|
|
1903
|
-
}
|
|
1904
|
-
this.handleAcpMessage(message);
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
handleAcpMessage(message) {
|
|
1908
|
-
if (!isRecord3(message)) {
|
|
1909
|
-
this.reportProtocolError(
|
|
1910
|
-
new KimiAcpProtocolError("Kimi ACP message must be an object", message)
|
|
1911
|
-
);
|
|
1912
|
-
return;
|
|
1913
|
-
}
|
|
1914
|
-
const id = message.id;
|
|
1915
|
-
const method = message.method;
|
|
1916
|
-
if (typeof method === "string" && (typeof id === "string" || typeof id === "number")) {
|
|
1917
|
-
this.handleServerRequest({ id, method, params: message.params });
|
|
1918
|
-
return;
|
|
1919
|
-
}
|
|
1920
|
-
if (typeof method === "string") {
|
|
1921
|
-
this.handleNotification(method, message.params);
|
|
1922
|
-
return;
|
|
1923
|
-
}
|
|
1924
|
-
if (typeof id === "string" || typeof id === "number") {
|
|
1925
|
-
this.handleResponse(id, message);
|
|
1926
|
-
return;
|
|
1927
|
-
}
|
|
1928
|
-
this.reportProtocolError(new KimiAcpProtocolError("Unrecognized Kimi ACP message", message));
|
|
1929
|
-
}
|
|
1930
|
-
handleResponse(id, message) {
|
|
1931
|
-
const pending = this.pendingRequests.get(id);
|
|
1932
|
-
if (!pending) {
|
|
1933
|
-
if (this.cancelledResponseIds.delete(id)) return;
|
|
1934
|
-
this.reportProtocolError(
|
|
1935
|
-
new KimiAcpProtocolError(`Unexpected Kimi ACP response id: ${String(id)}`, message)
|
|
1936
|
-
);
|
|
1937
|
-
return;
|
|
1938
|
-
}
|
|
1939
|
-
this.pendingRequests.delete(id);
|
|
1940
|
-
if (pending.timeout) clearTimeout(pending.timeout);
|
|
1941
|
-
if (isRecord3(message.error)) {
|
|
1942
|
-
pending.reject(
|
|
1943
|
-
new KimiAcpRpcError(
|
|
1944
|
-
pending.method,
|
|
1945
|
-
typeof message.error.code === "number" ? message.error.code : void 0,
|
|
1946
|
-
responseErrorMessage2(message.error),
|
|
1947
|
-
message.error.data
|
|
1948
|
-
)
|
|
1949
|
-
);
|
|
1950
|
-
return;
|
|
1951
|
-
}
|
|
1952
|
-
pending.resolve(message.result);
|
|
1953
|
-
}
|
|
1954
|
-
abortUnacknowledgedCancellation(prompt) {
|
|
1955
|
-
const requestId = prompt.requestId;
|
|
1956
|
-
if (requestId === void 0) return;
|
|
1957
|
-
const pending = this.pendingRequests.get(requestId);
|
|
1958
|
-
if (!pending || pending.method !== "session/prompt") return;
|
|
1959
|
-
const error = new Error(
|
|
1960
|
-
`Kimi ACP did not acknowledge session/cancel within ${this.cancelAcknowledgeTimeoutMs}ms; terminating the unsafe transport`
|
|
1961
|
-
);
|
|
1962
|
-
this.transportFailure = error;
|
|
1963
|
-
this.pendingRequests.delete(requestId);
|
|
1964
|
-
if (pending.timeout) clearTimeout(pending.timeout);
|
|
1965
|
-
this.cancelledResponseIds.add(requestId);
|
|
1966
|
-
if (this.cancelledResponseIds.size > CANCELLED_RESPONSE_TOMBSTONE_LIMIT2) {
|
|
1967
|
-
const oldest = this.cancelledResponseIds.values().next().value;
|
|
1968
|
-
if (oldest !== void 0) this.cancelledResponseIds.delete(oldest);
|
|
1969
|
-
}
|
|
1970
|
-
this.appendStderr(`${error.message}
|
|
1971
|
-
`);
|
|
1972
|
-
this.cancelPendingPermissions();
|
|
1973
|
-
pending.reject(error);
|
|
1974
|
-
if (this.child) terminateOwnedProcessTree(this.child, "SIGKILL");
|
|
1975
|
-
}
|
|
1976
|
-
handleNotification(method, rawParams) {
|
|
1977
|
-
const params = isRecord3(rawParams) ? rawParams : {};
|
|
1978
|
-
if (method === "session/update") {
|
|
1979
|
-
this.trackToolCall(params);
|
|
1980
|
-
this.invokeCallback(() => this.onUpdate?.(params), "session/update callback failed");
|
|
1981
|
-
}
|
|
1982
|
-
this.invokeCallback(
|
|
1983
|
-
() => this.onNotification?.(method, params),
|
|
1984
|
-
`${method} notification callback failed`
|
|
1985
|
-
);
|
|
1986
|
-
}
|
|
1987
|
-
trackToolCall(params) {
|
|
1988
|
-
if (!isRecord3(params.update) || typeof params.update.toolCallId !== "string") return;
|
|
1989
|
-
const previous = this.toolCalls.get(params.update.toolCallId) ?? {};
|
|
1990
|
-
const next = { ...previous, ...params.update };
|
|
1991
|
-
if (next.status === "completed" || next.status === "failed") {
|
|
1992
|
-
this.toolCalls.delete(params.update.toolCallId);
|
|
1993
|
-
return;
|
|
1994
|
-
}
|
|
1995
|
-
this.toolCalls.set(params.update.toolCallId, next);
|
|
1996
|
-
}
|
|
1997
|
-
handleServerRequest(request) {
|
|
1998
|
-
if (request.method === "session/request_permission") {
|
|
1999
|
-
void this.handlePermissionRequest(request.id, request.params);
|
|
2000
|
-
return;
|
|
2001
|
-
}
|
|
2002
|
-
this.writeLine({
|
|
2003
|
-
jsonrpc: "2.0",
|
|
2004
|
-
id: request.id,
|
|
2005
|
-
error: { code: -32601, message: `Unsupported Kimi ACP client request: ${request.method}` }
|
|
2006
|
-
});
|
|
2007
|
-
}
|
|
2008
|
-
async handlePermissionRequest(id, rawParams) {
|
|
2009
|
-
const params = isRecord3(rawParams) ? rawParams : {};
|
|
2010
|
-
const incomingToolCall = isRecord3(params.toolCall) ? params.toolCall : {};
|
|
2011
|
-
const toolCallId = typeof incomingToolCall.toolCallId === "string" ? incomingToolCall.toolCallId : void 0;
|
|
2012
|
-
const trackedToolCall = toolCallId ? this.toolCalls.get(toolCallId) ?? {} : {};
|
|
2013
|
-
const toolCall = { ...trackedToolCall, ...incomingToolCall };
|
|
2014
|
-
const rawInput = isRecord3(incomingToolCall.rawInput) ? incomingToolCall.rawInput : trackedToolCall.rawInput;
|
|
2015
|
-
const request = {
|
|
2016
|
-
requestId: id,
|
|
2017
|
-
sessionId: typeof params.sessionId === "string" ? params.sessionId : this.sessionId ?? "",
|
|
2018
|
-
toolName: typeof incomingToolCall.title === "string" ? incomingToolCall.title : typeof trackedToolCall.title === "string" ? trackedToolCall.title : "Tool",
|
|
2019
|
-
input: normalizeApprovalInput3(rawInput),
|
|
2020
|
-
rawToolCall: incomingToolCall,
|
|
2021
|
-
toolCall,
|
|
2022
|
-
options: parsePermissionOptions2(params.options),
|
|
2023
|
-
rawParams: params
|
|
2024
|
-
};
|
|
2025
|
-
if (this.transportFailure || this.activePrompt?.cancelled) {
|
|
2026
|
-
this.writeLine({
|
|
2027
|
-
jsonrpc: "2.0",
|
|
2028
|
-
id,
|
|
2029
|
-
result: { outcome: { outcome: "cancelled" } }
|
|
2030
|
-
});
|
|
2031
|
-
return;
|
|
2032
|
-
}
|
|
2033
|
-
const pending = { request, responded: false };
|
|
2034
|
-
this.pendingPermissions.set(id, pending);
|
|
2035
|
-
let decision;
|
|
2036
|
-
try {
|
|
2037
|
-
decision = await this.onPermissionRequest(request);
|
|
2038
|
-
} catch (error) {
|
|
2039
|
-
decision = { behavior: "deny", message: toError3(error).message };
|
|
2040
|
-
}
|
|
2041
|
-
if (pending.responded) return;
|
|
2042
|
-
pending.responded = true;
|
|
2043
|
-
this.pendingPermissions.delete(id);
|
|
2044
|
-
const requestedOptionId = typeof decision.optionId === "string" && decision.optionId.trim().length > 0 ? decision.optionId : void 0;
|
|
2045
|
-
const explicitOption = requestedOptionId ? request.options.find((candidate) => candidate.optionId === requestedOptionId) : void 0;
|
|
2046
|
-
const cancelled = decision.cancelled === true || decision.behavior === "cancel";
|
|
2047
|
-
const behavior = decision.behavior === "allow_once" || decision.behavior === "allow_always" || decision.behavior === "deny" ? decision.behavior : void 0;
|
|
2048
|
-
const validExplicitOption = explicitOption && (!behavior || optionMatchesBehavior2(explicitOption, behavior)) ? explicitOption : void 0;
|
|
2049
|
-
const option = cancelled || requestedOptionId || !behavior ? void 0 : selectPermissionOption2(request.options, behavior);
|
|
2050
|
-
const selectedOptionId = cancelled ? void 0 : validExplicitOption?.optionId || option?.optionId;
|
|
2051
|
-
const outcome = selectedOptionId ? { outcome: "selected", optionId: selectedOptionId } : { outcome: "cancelled" };
|
|
2052
|
-
if (!this.writeLine({ jsonrpc: "2.0", id, result: { outcome } })) {
|
|
2053
|
-
this.reportProtocolError(
|
|
2054
|
-
new KimiAcpProtocolError(`Failed to respond to permission request ${String(id)}`)
|
|
2055
|
-
);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
cancelPendingPermissions() {
|
|
2059
|
-
for (const [id, pending] of this.pendingPermissions) {
|
|
2060
|
-
if (pending.responded) continue;
|
|
2061
|
-
pending.responded = true;
|
|
2062
|
-
this.writeLine({
|
|
2063
|
-
jsonrpc: "2.0",
|
|
2064
|
-
id,
|
|
2065
|
-
result: { outcome: { outcome: "cancelled" } }
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
this.pendingPermissions.clear();
|
|
2069
|
-
}
|
|
2070
|
-
setupStderrCollection() {
|
|
2071
|
-
const child = this.child;
|
|
2072
|
-
if (!child?.stderr) return;
|
|
2073
|
-
child.stderr.on("data", (chunk) => {
|
|
2074
|
-
this.appendStderr(typeof chunk === "string" ? chunk : chunk.toString());
|
|
2075
|
-
});
|
|
2076
|
-
}
|
|
2077
|
-
setupExitHandler() {
|
|
2078
|
-
const child = this.child;
|
|
2079
|
-
if (!child) return;
|
|
2080
|
-
child.on("error", (error) => {
|
|
2081
|
-
const wrapped = new Error(`Kimi ACP failed to start: ${error.message}`);
|
|
2082
|
-
this.appendStderr(`${wrapped.message}
|
|
2083
|
-
`);
|
|
2084
|
-
this.rejectAllPendingRequests(wrapped);
|
|
2085
|
-
this.rejectSessionReadyOnce(wrapped);
|
|
2086
|
-
this.onProcessError?.(wrapped);
|
|
2087
|
-
this.reportExit(1);
|
|
2088
|
-
});
|
|
2089
|
-
child.on("exit", (code) => {
|
|
2090
|
-
const exitCode = code ?? 1;
|
|
2091
|
-
const error = new Error(
|
|
2092
|
-
this.sessionReadySettled ? `Kimi ACP exited (code ${exitCode})` : `Kimi ACP exited before ready (code ${exitCode})`
|
|
2093
|
-
);
|
|
2094
|
-
this.rejectAllPendingRequests(error);
|
|
2095
|
-
this.pendingPermissions.clear();
|
|
2096
|
-
this.rejectSessionReadyOnce(error);
|
|
2097
|
-
if (exitCode !== 0) this.onProcessError?.(error);
|
|
2098
|
-
this.reportExit(exitCode);
|
|
2099
|
-
});
|
|
2100
|
-
}
|
|
2101
|
-
invokeCallback(callback, message) {
|
|
2102
|
-
try {
|
|
2103
|
-
callback();
|
|
2104
|
-
} catch (error) {
|
|
2105
|
-
this.reportProtocolError(new KimiAcpProtocolError(`${message}: ${toError3(error).message}`));
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
reportProtocolError(error, line) {
|
|
2109
|
-
this.appendStderr(`${error.message}
|
|
2110
|
-
`);
|
|
2111
|
-
try {
|
|
2112
|
-
this.onProtocolError?.(error, line);
|
|
2113
|
-
} catch {
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
appendStderr(chunk) {
|
|
2117
|
-
this.stderrTail = `${this.stderrTail}${chunk}`.slice(-STDERR_TAIL_LIMIT4);
|
|
2118
|
-
}
|
|
2119
|
-
resolveSessionReadyOnce(sessionId2) {
|
|
2120
|
-
if (this.sessionReadySettled) return;
|
|
2121
|
-
this.sessionReadySettled = true;
|
|
2122
|
-
this.resolveSessionReady(sessionId2);
|
|
2123
|
-
}
|
|
2124
|
-
rejectSessionReadyOnce(error) {
|
|
2125
|
-
if (this.sessionReadySettled) return;
|
|
2126
|
-
this.sessionReadySettled = true;
|
|
2127
|
-
this.rejectSessionReady(error);
|
|
2128
|
-
}
|
|
2129
|
-
rejectAllPendingRequests(error) {
|
|
2130
|
-
for (const pending of this.pendingRequests.values()) {
|
|
2131
|
-
if (pending.timeout) clearTimeout(pending.timeout);
|
|
2132
|
-
pending.reject(error);
|
|
2133
|
-
}
|
|
2134
|
-
this.pendingRequests.clear();
|
|
2135
|
-
this.cancelledResponseIds.clear();
|
|
2136
|
-
}
|
|
2137
|
-
reportExit(code) {
|
|
2138
|
-
if (this.exitReported) return;
|
|
2139
|
-
this.exitReported = true;
|
|
2140
|
-
this.onExitCb?.(code);
|
|
2141
|
-
}
|
|
2142
|
-
};
|
|
2143
|
-
|
|
2144
1540
|
// src/worker/serve-connection.ts
|
|
2145
1541
|
function readServeConnection(socket, sessionId2, callbacks, timeoutMs = 5e3) {
|
|
2146
1542
|
readWorkerConnection(socket, {
|
|
@@ -2178,7 +1574,7 @@ if (!sessionId || !sockPath) {
|
|
|
2178
1574
|
console.error("Usage: session-worker <sessionId> <socketPath> [-- claudeArgs...]");
|
|
2179
1575
|
process.exit(1);
|
|
2180
1576
|
}
|
|
2181
|
-
if (providerArg
|
|
1577
|
+
if (!isProviderId(providerArg)) {
|
|
2182
1578
|
console.error(
|
|
2183
1579
|
providerArg === void 0 ? "JSON worker provider is required" : `Unsupported JSON worker provider: ${providerArg}`
|
|
2184
1580
|
);
|
|
@@ -2194,7 +1590,7 @@ var workerHook = workerHookUrl && workerHookMarker && workerHookToken && workerH
|
|
|
2194
1590
|
} : void 0;
|
|
2195
1591
|
var serveSocket = null;
|
|
2196
1592
|
var queuedServeMessages = [];
|
|
2197
|
-
var
|
|
1593
|
+
var latestAcpCommandEvent = null;
|
|
2198
1594
|
var readyMessage = null;
|
|
2199
1595
|
var providerReady = false;
|
|
2200
1596
|
var exiting = false;
|
|
@@ -2204,10 +1600,10 @@ var whitelist = new ToolWhitelist();
|
|
|
2204
1600
|
var nextApprovalRequestId = createApprovalRequestIdFactory(sessionId);
|
|
2205
1601
|
var pendingApprovals = /* @__PURE__ */ new Map();
|
|
2206
1602
|
function isAcpProvider(value) {
|
|
2207
|
-
return value === "kimi" || value === "cursor";
|
|
1603
|
+
return value === "kimi" || value === "cursor" || value === "antigravity";
|
|
2208
1604
|
}
|
|
2209
|
-
function
|
|
2210
|
-
if (msg.type !== "worker_event" || msg.event.type !== "kimi_acp" && msg.event.type !== "cursor_acp") {
|
|
1605
|
+
function isAcpCommandEvent(msg) {
|
|
1606
|
+
if (msg.type !== "worker_event" || msg.event.type !== "kimi_acp" && msg.event.type !== "cursor_acp" && msg.event.type !== "antigravity_acp") {
|
|
2211
1607
|
return false;
|
|
2212
1608
|
}
|
|
2213
1609
|
const params = msg.event.params;
|
|
@@ -2218,9 +1614,9 @@ function isKimiCommandEvent(msg) {
|
|
|
2218
1614
|
);
|
|
2219
1615
|
}
|
|
2220
1616
|
function sendToServe(msg) {
|
|
2221
|
-
if (
|
|
1617
|
+
if (isAcpCommandEvent(msg)) latestAcpCommandEvent = msg;
|
|
2222
1618
|
if (!providerReady && msg.type !== "worker_startup_error" && msg.type !== "worker_exit") {
|
|
2223
|
-
if (!
|
|
1619
|
+
if (!isAcpCommandEvent(msg) && msg.type !== "worker_approval_request") {
|
|
2224
1620
|
queuedServeMessages.push(msg);
|
|
2225
1621
|
}
|
|
2226
1622
|
return;
|
|
@@ -2229,7 +1625,7 @@ function sendToServe(msg) {
|
|
|
2229
1625
|
serveSocket.write(serializeWorkerMsg(msg));
|
|
2230
1626
|
return;
|
|
2231
1627
|
}
|
|
2232
|
-
if (
|
|
1628
|
+
if (isAcpCommandEvent(msg)) return;
|
|
2233
1629
|
if (msg.type !== "worker_approval_request") {
|
|
2234
1630
|
queuedServeMessages.push(msg);
|
|
2235
1631
|
}
|
|
@@ -2250,15 +1646,15 @@ function replayServeState(socket) {
|
|
|
2250
1646
|
if (!socket?.writable || serveSocket !== socket) return;
|
|
2251
1647
|
if (!providerReady || !readyMessage) return;
|
|
2252
1648
|
socket.write(serializeWorkerMsg(readyMessage));
|
|
2253
|
-
const
|
|
1649
|
+
const queuedAcpTurnStart = queuedServeMessages.some(
|
|
2254
1650
|
(message) => message.type === "worker_turn_started"
|
|
2255
1651
|
);
|
|
2256
|
-
if (isAcpProvider(provider) && acpTurnActive && !
|
|
1652
|
+
if (isAcpProvider(provider) && acpTurnActive && !queuedAcpTurnStart) {
|
|
2257
1653
|
socket.write(serializeWorkerMsg({ type: "worker_turn_started" }));
|
|
2258
1654
|
}
|
|
2259
1655
|
flushQueuedServeMessages();
|
|
2260
|
-
if (
|
|
2261
|
-
socket.write(serializeWorkerMsg(
|
|
1656
|
+
if (latestAcpCommandEvent && socket.writable) {
|
|
1657
|
+
socket.write(serializeWorkerMsg(latestAcpCommandEvent));
|
|
2262
1658
|
}
|
|
2263
1659
|
for (const [requestId, pending] of pendingApprovals) {
|
|
2264
1660
|
socket.write(
|
|
@@ -2303,8 +1699,12 @@ function handleProviderEvent(event) {
|
|
|
2303
1699
|
event
|
|
2304
1700
|
});
|
|
2305
1701
|
}
|
|
2306
|
-
function
|
|
2307
|
-
handleProviderEvent({
|
|
1702
|
+
function handleAcpEvent(method, params) {
|
|
1703
|
+
handleProviderEvent({
|
|
1704
|
+
type: provider === "antigravity" ? "antigravity_acp" : "kimi_acp",
|
|
1705
|
+
method,
|
|
1706
|
+
params
|
|
1707
|
+
});
|
|
2308
1708
|
}
|
|
2309
1709
|
function handleCursorEvent(method, params) {
|
|
2310
1710
|
handleProviderEvent({ type: "cursor_acp", method, params });
|
|
@@ -2318,7 +1718,7 @@ function workerApprovalOptions(options) {
|
|
|
2318
1718
|
return [{ optionId: option.optionId, name: option.name, kind }];
|
|
2319
1719
|
});
|
|
2320
1720
|
}
|
|
2321
|
-
async function
|
|
1721
|
+
async function handleAcpPermissionRequest(request) {
|
|
2322
1722
|
if (whitelist.has(request.toolName)) return { behavior: "allow_always" };
|
|
2323
1723
|
const options = workerApprovalOptions(request.options);
|
|
2324
1724
|
const decision = await forwardToRelay(
|
|
@@ -2398,31 +1798,32 @@ var session = provider === "codex" ? new CodexAppServerSession({
|
|
|
2398
1798
|
});
|
|
2399
1799
|
},
|
|
2400
1800
|
onExit: handleProviderExit
|
|
2401
|
-
}) : provider === "kimi" ? new
|
|
1801
|
+
}) : provider === "kimi" || provider === "antigravity" ? new AcpSession({
|
|
1802
|
+
provider,
|
|
2402
1803
|
cwd: workerCwd,
|
|
2403
1804
|
resumeSessionId: workerResume,
|
|
2404
1805
|
permissionMode: workerPermissionMode,
|
|
2405
|
-
onUpdate: (params) =>
|
|
2406
|
-
onPermissionRequest:
|
|
1806
|
+
onUpdate: (params) => handleAcpEvent("session/update", params),
|
|
1807
|
+
onPermissionRequest: handleAcpPermissionRequest,
|
|
2407
1808
|
onPromptStart: () => {
|
|
2408
1809
|
acpTurnActive = true;
|
|
2409
1810
|
sendToServe({ type: "worker_turn_started" });
|
|
2410
1811
|
},
|
|
2411
1812
|
onPromptComplete: (result) => {
|
|
2412
1813
|
acpTurnActive = false;
|
|
2413
|
-
|
|
1814
|
+
handleAcpEvent("session/prompt/result", { response: result });
|
|
2414
1815
|
},
|
|
2415
1816
|
onPromptError: (error) => {
|
|
2416
1817
|
acpTurnActive = false;
|
|
2417
|
-
|
|
2418
|
-
message: sanitizeProviderErrorTail(error.message) || "
|
|
1818
|
+
handleAcpEvent("session/prompt/error", {
|
|
1819
|
+
message: sanitizeProviderErrorTail(error.message) || "ACP prompt failed"
|
|
2419
1820
|
});
|
|
2420
1821
|
},
|
|
2421
|
-
onSessionId: (
|
|
1822
|
+
onSessionId: (nativeSessionId) => {
|
|
2422
1823
|
sendToServe({
|
|
2423
1824
|
type: "worker_native_session_id",
|
|
2424
|
-
provider
|
|
2425
|
-
sessionId:
|
|
1825
|
+
provider,
|
|
1826
|
+
sessionId: nativeSessionId
|
|
2426
1827
|
});
|
|
2427
1828
|
},
|
|
2428
1829
|
onProtocolError: (error) => console.error(`[worker] ${error.message}`),
|
|
@@ -2619,23 +2020,24 @@ ${session.getStderr()}`;
|
|
|
2619
2020
|
console.error(`[worker] Codex app-server failed to initialize: ${diagnostic}`);
|
|
2620
2021
|
void session.stop(0).finally(() => handleProviderExit(1));
|
|
2621
2022
|
});
|
|
2622
|
-
} else if (provider === "kimi" && session instanceof
|
|
2623
|
-
void session.waitUntilReady().then((
|
|
2023
|
+
} else if ((provider === "kimi" || provider === "antigravity") && session instanceof AcpSession) {
|
|
2024
|
+
void session.waitUntilReady().then((nativeSessionId) => {
|
|
2624
2025
|
reportReady({
|
|
2625
2026
|
type: "worker_ready",
|
|
2626
2027
|
pid,
|
|
2627
|
-
nativeSession: { provider
|
|
2028
|
+
nativeSession: { provider, sessionId: nativeSessionId }
|
|
2628
2029
|
});
|
|
2629
2030
|
}).catch((err) => {
|
|
2630
2031
|
const message = err instanceof Error ? err.message : String(err);
|
|
2631
2032
|
const diagnostic = sanitizeProviderErrorTail(`${message}
|
|
2632
|
-
${session.getStderr()}`) || "
|
|
2033
|
+
${session.getStderr()}`) || "ACP \u521D\u59CB\u5316\u5931\u8D25";
|
|
2633
2034
|
sendToServe({
|
|
2634
2035
|
type: "worker_startup_error",
|
|
2635
|
-
provider
|
|
2636
|
-
message: diagnostic
|
|
2036
|
+
provider,
|
|
2037
|
+
message: diagnostic,
|
|
2038
|
+
...provider === "antigravity" && err instanceof AcpRpcError && err.code === -32e3 ? { errorCode: ControlErrorCode.PROVIDER_AUTH_REQUIRED } : {}
|
|
2637
2039
|
});
|
|
2638
|
-
console.error(`[worker]
|
|
2040
|
+
console.error(`[worker] ${provider} ACP failed to initialize: ${diagnostic}`);
|
|
2639
2041
|
void session.stop(0).finally(() => handleProviderExit(1));
|
|
2640
2042
|
});
|
|
2641
2043
|
} else if (provider === "cursor" && session instanceof CursorAcpSession) {
|