@karlorz/codexhost-cli-linux-x64 0.22.0-5 → 0.22.0-6
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 +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/plugins/cursor-cli/plugin.mjs +361 -75
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install -g @karlorz/codexhost-cli@0.22.0-
|
|
10
|
+
npm install -g @karlorz/codexhost-cli@0.22.0-6
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Do not install this package directly. npm selects it through the optional dependencies of `@karlorz/codexhost-cli`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion":1,"version":"0.22.0-
|
|
1
|
+
{"schemaVersion":1,"version":"0.22.0-6","distribution":"npm","target":"linux-x64"}
|
|
@@ -18242,7 +18242,7 @@ var SessionImportScope = class {
|
|
|
18242
18242
|
};
|
|
18243
18243
|
|
|
18244
18244
|
// dist/native-history.js
|
|
18245
|
-
import { existsSync as existsSync2, readFileSync, realpathSync } from "node:fs";
|
|
18245
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
18246
18246
|
import os2 from "node:os";
|
|
18247
18247
|
import path6 from "node:path";
|
|
18248
18248
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -18265,6 +18265,13 @@ function cursorSessionDirectory(sessionId, environment) {
|
|
|
18265
18265
|
throw new Error("Unsupported Cursor native session ID");
|
|
18266
18266
|
return path6.join(cursorConfigDirectory(environment), "acp-sessions", sessionId);
|
|
18267
18267
|
}
|
|
18268
|
+
function cursorNativeStoreExists(sessionId, environment) {
|
|
18269
|
+
try {
|
|
18270
|
+
return existsSync2(path6.join(cursorSessionDirectory(sessionId, environment), "store.db"));
|
|
18271
|
+
} catch {
|
|
18272
|
+
return false;
|
|
18273
|
+
}
|
|
18274
|
+
}
|
|
18268
18275
|
function cursorSameWorkspace(left, right) {
|
|
18269
18276
|
return path6.resolve(left) === path6.resolve(right) || existsSync2(left) && existsSync2(right) && realpathSync.native(left) === realpathSync.native(right);
|
|
18270
18277
|
}
|
|
@@ -18366,6 +18373,47 @@ function readCursorNativeHistory(sessionId, cwd, environment, allowMissing = fal
|
|
|
18366
18373
|
db.close();
|
|
18367
18374
|
}
|
|
18368
18375
|
}
|
|
18376
|
+
function acpOnlyHistoryFile(sessionId, environment) {
|
|
18377
|
+
return path6.join(cursorConfigDirectory(environment), "codexhost-acp-only", `${sessionId}.json`);
|
|
18378
|
+
}
|
|
18379
|
+
function readCursorAcpOnlyTurns(sessionId, environment) {
|
|
18380
|
+
try {
|
|
18381
|
+
cursorSessionDirectory(sessionId, environment);
|
|
18382
|
+
const filename = acpOnlyHistoryFile(sessionId, environment);
|
|
18383
|
+
if (!existsSync2(filename))
|
|
18384
|
+
return [];
|
|
18385
|
+
const raw = JSON.parse(readFileSync(filename, "utf8"));
|
|
18386
|
+
if (!raw || typeof raw !== "object" || !Array.isArray(raw.turns))
|
|
18387
|
+
return [];
|
|
18388
|
+
const turns = [];
|
|
18389
|
+
for (const item of raw.turns) {
|
|
18390
|
+
if (!item || typeof item !== "object")
|
|
18391
|
+
continue;
|
|
18392
|
+
const id = item.id;
|
|
18393
|
+
const text = item.text;
|
|
18394
|
+
if (typeof id !== "string" || !id.trim() || typeof text !== "string")
|
|
18395
|
+
continue;
|
|
18396
|
+
const assistantText = item.assistantText;
|
|
18397
|
+
const itemId = item.itemId;
|
|
18398
|
+
turns.push({
|
|
18399
|
+
id,
|
|
18400
|
+
text,
|
|
18401
|
+
...typeof assistantText === "string" && assistantText.trim() ? { assistantText } : {},
|
|
18402
|
+
...typeof itemId === "string" && itemId.trim() ? { itemId } : {}
|
|
18403
|
+
});
|
|
18404
|
+
}
|
|
18405
|
+
return turns;
|
|
18406
|
+
} catch {
|
|
18407
|
+
return [];
|
|
18408
|
+
}
|
|
18409
|
+
}
|
|
18410
|
+
function writeCursorAcpOnlyTurns(sessionId, environment, turns) {
|
|
18411
|
+
cursorSessionDirectory(sessionId, environment);
|
|
18412
|
+
const filename = acpOnlyHistoryFile(sessionId, environment);
|
|
18413
|
+
mkdirSync(path6.dirname(filename), { recursive: true });
|
|
18414
|
+
writeFileSync(filename, `${JSON.stringify({ version: 1, nativeSessionId: sessionId, turns })}
|
|
18415
|
+
`, "utf8");
|
|
18416
|
+
}
|
|
18369
18417
|
function readCursorNativeTurns(sessionId, cwd, environment, allowMissing = false) {
|
|
18370
18418
|
return readCursorNativeHistory(sessionId, cwd, environment, allowMissing).turns;
|
|
18371
18419
|
}
|
|
@@ -18383,6 +18431,14 @@ function cursorNativeSessionRef(nativeSessionId, executionPolicy) {
|
|
|
18383
18431
|
formatVersion: 1
|
|
18384
18432
|
});
|
|
18385
18433
|
}
|
|
18434
|
+
function cursorNativeTurnRef(nativeSessionId, nativeTurnKey) {
|
|
18435
|
+
return nativeTurnRefSchema.parse({
|
|
18436
|
+
harnessId: cursorHarnessId,
|
|
18437
|
+
nativeSessionId,
|
|
18438
|
+
nativeTurnKey,
|
|
18439
|
+
formatVersion: 1
|
|
18440
|
+
});
|
|
18441
|
+
}
|
|
18386
18442
|
function cursorExecutionPolicy(ref) {
|
|
18387
18443
|
if (ref.harnessId !== cursorHarnessId || ref.formatVersion !== 1)
|
|
18388
18444
|
throw new Error("Invalid Cursor Native Session Ref");
|
|
@@ -18619,6 +18675,55 @@ var CURSOR_MODES = harnessPermissionModeCatalogSchema.parse({
|
|
|
18619
18675
|
}
|
|
18620
18676
|
]
|
|
18621
18677
|
});
|
|
18678
|
+
var GROK_ACP_MODES = harnessPermissionModeCatalogSchema.parse({
|
|
18679
|
+
defaultModeId: "default",
|
|
18680
|
+
modes: [
|
|
18681
|
+
{
|
|
18682
|
+
id: "default",
|
|
18683
|
+
label: "Default",
|
|
18684
|
+
description: "Native ACP default session mode"
|
|
18685
|
+
},
|
|
18686
|
+
{
|
|
18687
|
+
id: "plan",
|
|
18688
|
+
label: "Plan",
|
|
18689
|
+
description: "Native ACP plan session mode"
|
|
18690
|
+
}
|
|
18691
|
+
]
|
|
18692
|
+
});
|
|
18693
|
+
function parsedPermissionModeId(value) {
|
|
18694
|
+
const parsed = harnessPermissionModeIdSchema.safeParse(value);
|
|
18695
|
+
return parsed.success ? parsed.data : void 0;
|
|
18696
|
+
}
|
|
18697
|
+
function cursorUsesNativeSessionModes(info) {
|
|
18698
|
+
return cursorModes(info) !== CURSOR_MODES;
|
|
18699
|
+
}
|
|
18700
|
+
function cursorModes(info) {
|
|
18701
|
+
const available = (info.modes?.availableModes ?? []).flatMap((mode) => {
|
|
18702
|
+
const id = parsedPermissionModeId(mode.id);
|
|
18703
|
+
return id ? [
|
|
18704
|
+
{
|
|
18705
|
+
id,
|
|
18706
|
+
label: mode.name,
|
|
18707
|
+
...mode.description ? { description: mode.description } : {}
|
|
18708
|
+
}
|
|
18709
|
+
] : [];
|
|
18710
|
+
});
|
|
18711
|
+
const currentMode = info.modes?.currentModeId;
|
|
18712
|
+
if (available.length) {
|
|
18713
|
+
const current = available.some((mode) => mode.id === currentMode) ? currentMode : available[0]?.id;
|
|
18714
|
+
if (current)
|
|
18715
|
+
return harnessPermissionModeCatalogSchema.parse({ modes: available, defaultModeId: current });
|
|
18716
|
+
}
|
|
18717
|
+
if (GROK_ACP_MODES.modes.some((mode) => mode.id === currentMode) && currentMode)
|
|
18718
|
+
return harnessPermissionModeCatalogSchema.parse({
|
|
18719
|
+
...GROK_ACP_MODES,
|
|
18720
|
+
defaultModeId: currentMode
|
|
18721
|
+
});
|
|
18722
|
+
return CURSOR_MODES;
|
|
18723
|
+
}
|
|
18724
|
+
function cursorCurrentPermissionModeId(info) {
|
|
18725
|
+
return harnessPermissionModeIdSchema.parse(info.configOptions?.find((option) => option.id === "mode")?.currentValue ?? info.modes?.currentModeId ?? CURSOR_MODES.defaultModeId);
|
|
18726
|
+
}
|
|
18622
18727
|
var cursorModelRef = (nativeId) => harnessModelRefSchema.parse({ id: `cursor.${Buffer.from(nativeId).toString("base64url")}` });
|
|
18623
18728
|
function cursorModels(info) {
|
|
18624
18729
|
const option = info.configOptions?.find((option2) => option2.id === "model");
|
|
@@ -23036,6 +23141,11 @@ var CursorTransport = class {
|
|
|
23036
23141
|
throw new Error("Cursor session is not open");
|
|
23037
23142
|
return this.#bounded(this.#connection.setSessionConfigOption({ sessionId: this.sessionId, configId, value }));
|
|
23038
23143
|
}
|
|
23144
|
+
async setMode(modeId) {
|
|
23145
|
+
if (!this.#connection)
|
|
23146
|
+
throw new Error("Cursor session is not open");
|
|
23147
|
+
return this.#bounded(this.#connection.setSessionMode({ sessionId: this.sessionId, modeId }));
|
|
23148
|
+
}
|
|
23039
23149
|
async prompt(text, callbacks) {
|
|
23040
23150
|
if (!this.#connection || this.#closed || this.#callbacks)
|
|
23041
23151
|
throw new Error("Cursor session is closed or busy");
|
|
@@ -23808,6 +23918,7 @@ var CursorTurnOutput = class {
|
|
|
23808
23918
|
#hold = "";
|
|
23809
23919
|
#writableIterableClosed = false;
|
|
23810
23920
|
#visibleAssistantText = false;
|
|
23921
|
+
#agentMessage;
|
|
23811
23922
|
constructor(turnId, emit, nativeTurnIndex = 0) {
|
|
23812
23923
|
this.turnId = turnId;
|
|
23813
23924
|
this.emit = emit;
|
|
@@ -23825,6 +23936,13 @@ var CursorTurnOutput = class {
|
|
|
23825
23936
|
hasVisibleAssistantText() {
|
|
23826
23937
|
return this.#visibleAssistantText || takeCursorWritableIterableClosed(this.#hold).visible.trim().length > 0;
|
|
23827
23938
|
}
|
|
23939
|
+
visibleAgentMessage() {
|
|
23940
|
+
if (this.#agentMessage)
|
|
23941
|
+
return this.#agentMessage;
|
|
23942
|
+
if (this.#text?.type === "agentMessage" && this.#text.text.trim())
|
|
23943
|
+
return { itemId: this.#text.itemId, text: this.#text.text };
|
|
23944
|
+
return void 0;
|
|
23945
|
+
}
|
|
23828
23946
|
#flushHold() {
|
|
23829
23947
|
if (!this.#hold)
|
|
23830
23948
|
return;
|
|
@@ -23858,6 +23976,8 @@ var CursorTurnOutput = class {
|
|
|
23858
23976
|
});
|
|
23859
23977
|
}
|
|
23860
23978
|
#finishText(outcome = { status: "succeeded" }) {
|
|
23979
|
+
if (this.#text?.type === "agentMessage" && this.#text.text.trim())
|
|
23980
|
+
this.#agentMessage = { itemId: this.#text.itemId, text: this.#text.text };
|
|
23861
23981
|
if (this.#text)
|
|
23862
23982
|
this.emit({
|
|
23863
23983
|
type: "item.completed",
|
|
@@ -24527,7 +24647,33 @@ var CursorAdapter = class {
|
|
|
24527
24647
|
#sessions = /* @__PURE__ */ new Set();
|
|
24528
24648
|
#forks = /* @__PURE__ */ new Map();
|
|
24529
24649
|
#inspections = /* @__PURE__ */ new Map();
|
|
24650
|
+
/** Grok 2.0.7 holds GROK_HOME for one stdio child. Inspect and open must not overlap. */
|
|
24651
|
+
#stdioBusy = false;
|
|
24652
|
+
#liveStdioSession;
|
|
24530
24653
|
#closed = false;
|
|
24654
|
+
#tryAcquireStdio() {
|
|
24655
|
+
if (this.#stdioBusy)
|
|
24656
|
+
return false;
|
|
24657
|
+
this.#stdioBusy = true;
|
|
24658
|
+
return true;
|
|
24659
|
+
}
|
|
24660
|
+
#releaseStdio() {
|
|
24661
|
+
this.#stdioBusy = false;
|
|
24662
|
+
}
|
|
24663
|
+
#stdioBusyError() {
|
|
24664
|
+
const id = this.#liveStdioSession?.initialState.nativeRef?.nativeSessionId;
|
|
24665
|
+
return rejected("sessionBusy", id ? `Grok ACP is busy with session ${id}; close that cursor-cli thread or continue there` : "Grok ACP is already starting a session; close that cursor-cli thread or retry");
|
|
24666
|
+
}
|
|
24667
|
+
#busyInspection() {
|
|
24668
|
+
return {
|
|
24669
|
+
status: "unavailable",
|
|
24670
|
+
error: {
|
|
24671
|
+
code: "unavailable",
|
|
24672
|
+
message: "Grok ACP is busy; retry inspect after the live session is ready",
|
|
24673
|
+
retryable: true
|
|
24674
|
+
}
|
|
24675
|
+
};
|
|
24676
|
+
}
|
|
24531
24677
|
sessionImport;
|
|
24532
24678
|
constructor(options = {}) {
|
|
24533
24679
|
this.options = options;
|
|
@@ -24546,6 +24692,18 @@ var CursorAdapter = class {
|
|
|
24546
24692
|
...this.options.timeoutMs ? { timeoutMs: this.options.timeoutMs } : {}
|
|
24547
24693
|
};
|
|
24548
24694
|
}
|
|
24695
|
+
#inspectionFromLiveSession(cwd) {
|
|
24696
|
+
const sessions = [...this.#sessions];
|
|
24697
|
+
const match = sessions.find((session) => path9.resolve(session.transport.options.cwd) === cwd) ?? sessions[0];
|
|
24698
|
+
if (!match)
|
|
24699
|
+
return;
|
|
24700
|
+
return {
|
|
24701
|
+
status: "ready",
|
|
24702
|
+
catalog: cursorCatalog(match.info),
|
|
24703
|
+
capabilities: cursorCapabilities(match.info),
|
|
24704
|
+
permissionModes: cursorModes(match.info)
|
|
24705
|
+
};
|
|
24706
|
+
}
|
|
24549
24707
|
async inspect(input = {}) {
|
|
24550
24708
|
if (this.#closed)
|
|
24551
24709
|
return {
|
|
@@ -24553,27 +24711,40 @@ var CursorAdapter = class {
|
|
|
24553
24711
|
error: { code: "unavailable", message: "Cursor adapter is closed", retryable: false }
|
|
24554
24712
|
};
|
|
24555
24713
|
const cwd = path9.resolve(input.cwd ?? process.cwd());
|
|
24714
|
+
const live = this.#inspectionFromLiveSession(cwd);
|
|
24715
|
+
if (live)
|
|
24716
|
+
return live;
|
|
24717
|
+
if (this.#stdioBusy)
|
|
24718
|
+
return this.#busyInspection();
|
|
24556
24719
|
const cached2 = this.#inspections.get(cwd);
|
|
24557
24720
|
if (cached2 && (cached2.pending || !input.refresh))
|
|
24558
24721
|
return cached2.result;
|
|
24559
24722
|
const result = (async () => {
|
|
24560
|
-
|
|
24723
|
+
if (!this.#tryAcquireStdio()) {
|
|
24724
|
+
this.#inspections.delete(cwd);
|
|
24725
|
+
return this.#busyInspection();
|
|
24726
|
+
}
|
|
24561
24727
|
try {
|
|
24562
|
-
const
|
|
24563
|
-
|
|
24564
|
-
|
|
24565
|
-
|
|
24566
|
-
|
|
24567
|
-
|
|
24568
|
-
|
|
24569
|
-
|
|
24570
|
-
|
|
24571
|
-
|
|
24572
|
-
|
|
24573
|
-
|
|
24574
|
-
|
|
24728
|
+
const transport = new CursorTransport(this.transportOptions(cwd));
|
|
24729
|
+
try {
|
|
24730
|
+
const info = await transport.open();
|
|
24731
|
+
return {
|
|
24732
|
+
status: "ready",
|
|
24733
|
+
catalog: cursorCatalog(info),
|
|
24734
|
+
capabilities: cursorCapabilities(info),
|
|
24735
|
+
permissionModes: cursorModes(info)
|
|
24736
|
+
};
|
|
24737
|
+
} catch (error51) {
|
|
24738
|
+
const failure = cursorError(error51);
|
|
24739
|
+
return {
|
|
24740
|
+
status: failure.code === "notInstalled" ? "notInstalled" : "unavailable",
|
|
24741
|
+
error: failure
|
|
24742
|
+
};
|
|
24743
|
+
} finally {
|
|
24744
|
+
await transport.close();
|
|
24745
|
+
}
|
|
24575
24746
|
} finally {
|
|
24576
|
-
|
|
24747
|
+
this.#releaseStdio();
|
|
24577
24748
|
}
|
|
24578
24749
|
})();
|
|
24579
24750
|
const entry = { pending: true, result };
|
|
@@ -24622,52 +24793,88 @@ var CursorAdapter = class {
|
|
|
24622
24793
|
executionPolicy
|
|
24623
24794
|
};
|
|
24624
24795
|
const transport = prepared ?? new CursorTransport(options);
|
|
24625
|
-
|
|
24626
|
-
|
|
24627
|
-
|
|
24628
|
-
let
|
|
24629
|
-
if (
|
|
24630
|
-
const
|
|
24631
|
-
|
|
24632
|
-
|
|
24633
|
-
|
|
24634
|
-
|
|
24635
|
-
|
|
24636
|
-
|
|
24637
|
-
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
if (!selected.ok)
|
|
24643
|
-
throw new Error(selected.error.message);
|
|
24644
|
-
}
|
|
24645
|
-
if (input.thinkingOptionId) {
|
|
24646
|
-
const selected = await session.execute({
|
|
24647
|
-
type: "thinking.select",
|
|
24648
|
-
thinkingOptionId: input.thinkingOptionId
|
|
24649
|
-
});
|
|
24650
|
-
if (!selected.ok)
|
|
24651
|
-
throw new Error(selected.error.message);
|
|
24652
|
-
}
|
|
24653
|
-
if (input.permissionModeId) {
|
|
24654
|
-
const selected = await session.execute({
|
|
24655
|
-
type: "permissionMode.select",
|
|
24656
|
-
permissionModeId: input.permissionModeId
|
|
24657
|
-
});
|
|
24658
|
-
if (!selected.ok)
|
|
24659
|
-
throw new Error(selected.error.message);
|
|
24796
|
+
let session;
|
|
24797
|
+
const held = !prepared;
|
|
24798
|
+
const run = async () => {
|
|
24799
|
+
let acquired = false;
|
|
24800
|
+
if (held) {
|
|
24801
|
+
const live = this.#liveStdioSession;
|
|
24802
|
+
if (live) {
|
|
24803
|
+
const liveId = live.initialState.nativeRef?.nativeSessionId;
|
|
24804
|
+
if (input.kind === "resume" && liveId && input.nativeRef.nativeSessionId === liveId)
|
|
24805
|
+
return { ok: true, value: live };
|
|
24806
|
+
if (!live.stdioIdle())
|
|
24807
|
+
return this.#stdioBusyError();
|
|
24808
|
+
await live.close();
|
|
24809
|
+
}
|
|
24810
|
+
if (!this.#tryAcquireStdio())
|
|
24811
|
+
return this.#stdioBusyError();
|
|
24812
|
+
acquired = true;
|
|
24660
24813
|
}
|
|
24661
|
-
|
|
24662
|
-
|
|
24663
|
-
|
|
24814
|
+
try {
|
|
24815
|
+
const acpOnlyResume = input.kind === "resume" && !cursorNativeStoreExists(input.nativeRef.nativeSessionId, options.environment);
|
|
24816
|
+
const before = input.kind === "resume" && !acpOnlyResume ? readCursorNativeHistory(input.nativeRef.nativeSessionId, options.cwd, options.environment) : void 0;
|
|
24817
|
+
let info;
|
|
24818
|
+
if (acpOnlyResume) {
|
|
24819
|
+
info = await transport.open();
|
|
24820
|
+
} else {
|
|
24821
|
+
info = await transport.open(input.kind === "resume" ? input.nativeRef.nativeSessionId : void 0);
|
|
24822
|
+
}
|
|
24823
|
+
let loadedSnapshot;
|
|
24824
|
+
if (input.kind === "resume" && !acpOnlyResume) {
|
|
24825
|
+
const native = readCursorNativeHistory(transport.sessionId, options.cwd, options.environment);
|
|
24826
|
+
const snapshot = cursorSnapshot(transport.sessionId, native.turns, transport.replay);
|
|
24827
|
+
if (input.knownTurnRefs?.some((ref) => ref.harnessId !== this.harnessId || ref.nativeSessionId !== transport.sessionId || !native.turns.some((turn) => turn.id === ref.nativeTurnKey)))
|
|
24828
|
+
throw new Error("Saved Cursor turn identity no longer exists in native history");
|
|
24829
|
+
if (native.revision && before?.revision === native.revision)
|
|
24830
|
+
loadedSnapshot = { revision: native.revision, snapshot };
|
|
24831
|
+
}
|
|
24832
|
+
session = new CursorSession(transport, info, () => {
|
|
24833
|
+
const opened = session;
|
|
24834
|
+
if (!opened)
|
|
24835
|
+
return;
|
|
24836
|
+
this.#sessions.delete(opened);
|
|
24837
|
+
if (this.#liveStdioSession === opened) {
|
|
24838
|
+
this.#liveStdioSession = void 0;
|
|
24839
|
+
this.#releaseStdio();
|
|
24840
|
+
}
|
|
24841
|
+
}, input.kind === "create" || acpOnlyResume, loadedSnapshot, input.kind === "resume" ? input.nativeRef.nativeSessionId : void 0);
|
|
24842
|
+
this.#sessions.add(session);
|
|
24843
|
+
const restoreOrThrow = async (selected) => {
|
|
24844
|
+
if (!selected.ok && !acpOnlyResume)
|
|
24845
|
+
throw new Error(selected.error.message);
|
|
24846
|
+
};
|
|
24847
|
+
if (input.model)
|
|
24848
|
+
await restoreOrThrow(await session.execute({ type: "model.select", model: input.model }));
|
|
24849
|
+
if (input.thinkingOptionId)
|
|
24850
|
+
await restoreOrThrow(await session.execute({
|
|
24851
|
+
type: "thinking.select",
|
|
24852
|
+
thinkingOptionId: input.thinkingOptionId
|
|
24853
|
+
}));
|
|
24854
|
+
if (input.permissionModeId && cursorModes(info).modes.some((mode) => mode.id === input.permissionModeId))
|
|
24855
|
+
await restoreOrThrow(await session.execute({
|
|
24856
|
+
type: "permissionMode.select",
|
|
24857
|
+
permissionModeId: input.permissionModeId
|
|
24858
|
+
}));
|
|
24859
|
+
if (this.#closed) {
|
|
24860
|
+
await session.close();
|
|
24861
|
+
return rejected("invalidState", "Cursor adapter closed during session startup");
|
|
24862
|
+
}
|
|
24863
|
+
const acpOnly = acpOnlyResume || !cursorNativeStoreExists(transport.sessionId, options.environment);
|
|
24864
|
+
if (held && acpOnly)
|
|
24865
|
+
this.#liveStdioSession = session;
|
|
24866
|
+
return { ok: true, value: session };
|
|
24867
|
+
} catch (error51) {
|
|
24868
|
+
await session?.close();
|
|
24869
|
+
if (!session)
|
|
24870
|
+
await transport.close();
|
|
24871
|
+
return { ok: false, error: cursorError(error51) };
|
|
24872
|
+
} finally {
|
|
24873
|
+
if (acquired && !this.#liveStdioSession)
|
|
24874
|
+
this.#releaseStdio();
|
|
24664
24875
|
}
|
|
24665
|
-
|
|
24666
|
-
|
|
24667
|
-
} catch (error51) {
|
|
24668
|
-
await transport.close();
|
|
24669
|
-
return { ok: false, error: cursorError(error51) };
|
|
24670
|
-
}
|
|
24876
|
+
};
|
|
24877
|
+
return run();
|
|
24671
24878
|
}
|
|
24672
24879
|
async #fork(input, controller) {
|
|
24673
24880
|
const signal = controller.signal;
|
|
@@ -24770,6 +24977,8 @@ var CursorAdapter = class {
|
|
|
24770
24977
|
controller.abort();
|
|
24771
24978
|
await Promise.allSettled([importing, ...this.#forks.values()]);
|
|
24772
24979
|
await Promise.allSettled([...this.#sessions].map((session) => session.close()));
|
|
24980
|
+
this.#liveStdioSession = void 0;
|
|
24981
|
+
this.#stdioBusy = false;
|
|
24773
24982
|
await Promise.allSettled([...this.#inspections.values()].map((inspection) => inspection.result));
|
|
24774
24983
|
}
|
|
24775
24984
|
};
|
|
@@ -24808,12 +25017,17 @@ var CursorSession = class {
|
|
|
24808
25017
|
#configuring = false;
|
|
24809
25018
|
#closed = false;
|
|
24810
25019
|
#fresh;
|
|
25020
|
+
#nativeSessionId;
|
|
25021
|
+
#acpOnlyTurns;
|
|
24811
25022
|
#snapshot;
|
|
24812
25023
|
#subagentOutput;
|
|
24813
25024
|
/** A Turn is running and no configuration change is in flight. */
|
|
24814
25025
|
turnRunningForFork() {
|
|
24815
25026
|
return !this.#closed && !this.#configuring && this.#active !== void 0;
|
|
24816
25027
|
}
|
|
25028
|
+
stdioIdle() {
|
|
25029
|
+
return this.#closed || !this.#active && !this.#configuring;
|
|
25030
|
+
}
|
|
24817
25031
|
lockForFork() {
|
|
24818
25032
|
if (this.#closed || this.#active || this.#configuring)
|
|
24819
25033
|
return;
|
|
@@ -24829,24 +25043,68 @@ var CursorSession = class {
|
|
|
24829
25043
|
return void 0;
|
|
24830
25044
|
}
|
|
24831
25045
|
}
|
|
24832
|
-
constructor(transport, info, onClose, created = true, loadedSnapshot) {
|
|
25046
|
+
constructor(transport, info, onClose, created = true, loadedSnapshot, persistedSessionId) {
|
|
24833
25047
|
this.transport = transport;
|
|
24834
25048
|
this.info = info;
|
|
24835
25049
|
this.onClose = onClose;
|
|
24836
25050
|
this.info = structuredClone(info);
|
|
24837
25051
|
this.#fresh = created;
|
|
25052
|
+
this.#nativeSessionId = persistedSessionId ?? transport.sessionId;
|
|
25053
|
+
this.#acpOnlyTurns = readCursorAcpOnlyTurns(this.#nativeSessionId, transport.options.environment);
|
|
24838
25054
|
this.#snapshot = loadedSnapshot;
|
|
24839
25055
|
this.#executionPolicy = transport.options.executionPolicy ?? "default";
|
|
24840
25056
|
this.#interactions = new CursorInteractions((output) => this.#channel.emit(output), this.#executionPolicy === "unattended-full-access" ? () => this.#refuseUnattendedApproval() : void 0);
|
|
24841
25057
|
this.initialState = {
|
|
24842
|
-
nativeRef: cursorNativeSessionRef(
|
|
25058
|
+
nativeRef: cursorNativeSessionRef(this.#nativeSessionId, this.#executionPolicy),
|
|
24843
25059
|
effectiveModel: cursorConfiguredModelRef(cursorModels(info).current, info.configOptions),
|
|
24844
25060
|
...cursorThinkingState(info),
|
|
24845
|
-
effectivePermissionModeId:
|
|
25061
|
+
effectivePermissionModeId: cursorCurrentPermissionModeId(info)
|
|
24846
25062
|
};
|
|
24847
25063
|
}
|
|
24848
25064
|
#native(allowMissing = false) {
|
|
24849
|
-
|
|
25065
|
+
const missing = !cursorNativeStoreExists(this.transport.sessionId, this.transport.options.environment);
|
|
25066
|
+
try {
|
|
25067
|
+
return readCursorNativeTurns(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, allowMissing || missing);
|
|
25068
|
+
} catch (error51) {
|
|
25069
|
+
if (allowMissing || missing)
|
|
25070
|
+
return [];
|
|
25071
|
+
throw error51;
|
|
25072
|
+
}
|
|
25073
|
+
}
|
|
25074
|
+
#acpOnlyNativeStore() {
|
|
25075
|
+
return !cursorNativeStoreExists(this.transport.sessionId, this.transport.options.environment);
|
|
25076
|
+
}
|
|
25077
|
+
#acpOnlySnapshotTurns() {
|
|
25078
|
+
return this.#acpOnlyTurns.map((turn) => ({
|
|
25079
|
+
nativeTurnRef: cursorNativeTurnRef(this.#nativeSessionId, turn.id),
|
|
25080
|
+
input: [{ type: "text", text: turn.text }],
|
|
25081
|
+
items: turn.assistantText ? [
|
|
25082
|
+
{
|
|
25083
|
+
item: {
|
|
25084
|
+
type: "agentMessage",
|
|
25085
|
+
itemId: hostItemIdSchema.parse(turn.itemId ?? `cursor-${turn.id}-1`),
|
|
25086
|
+
text: turn.assistantText
|
|
25087
|
+
},
|
|
25088
|
+
outcome: { status: "succeeded" }
|
|
25089
|
+
}
|
|
25090
|
+
] : [],
|
|
25091
|
+
outcome: turn.assistantText ? { status: "succeeded" } : {
|
|
25092
|
+
status: "unknown",
|
|
25093
|
+
reason: "ACP-only history does not expose the terminal stop reason"
|
|
25094
|
+
}
|
|
25095
|
+
}));
|
|
25096
|
+
}
|
|
25097
|
+
#recordAcpOnlyTurn(command, output) {
|
|
25098
|
+
const assistant = output.visibleAgentMessage();
|
|
25099
|
+
this.#acpOnlyTurns.push({
|
|
25100
|
+
id: command.turnId,
|
|
25101
|
+
text: command.input.map((part) => part.text).join("\n"),
|
|
25102
|
+
...assistant ? { assistantText: assistant.text, itemId: assistant.itemId } : {}
|
|
25103
|
+
});
|
|
25104
|
+
try {
|
|
25105
|
+
writeCursorAcpOnlyTurns(this.#nativeSessionId, this.transport.options.environment, this.#acpOnlyTurns);
|
|
25106
|
+
} catch {
|
|
25107
|
+
}
|
|
24850
25108
|
}
|
|
24851
25109
|
/** Bound to unattended full access only; Cursor itself keeps enforcing its team policy. */
|
|
24852
25110
|
#refuseUnattendedApproval() {
|
|
@@ -24873,9 +25131,19 @@ var CursorSession = class {
|
|
|
24873
25131
|
this.#configuring = true;
|
|
24874
25132
|
let replay;
|
|
24875
25133
|
try {
|
|
24876
|
-
const
|
|
25134
|
+
const acpOnly = this.#acpOnlyNativeStore();
|
|
25135
|
+
if (acpOnly)
|
|
25136
|
+
return {
|
|
25137
|
+
ok: true,
|
|
25138
|
+
value: {
|
|
25139
|
+
turns: this.#acpOnlySnapshotTurns(),
|
|
25140
|
+
state: structuredClone(this.initialState)
|
|
25141
|
+
}
|
|
25142
|
+
};
|
|
25143
|
+
const allowMissing = this.#fresh;
|
|
25144
|
+
const history = () => readCursorNativeHistory(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, allowMissing);
|
|
24877
25145
|
const before = history();
|
|
24878
|
-
if (before.turns.length === 0 &&
|
|
25146
|
+
if (before.turns.length === 0 && allowMissing)
|
|
24879
25147
|
return { ok: true, value: { turns: [], state: structuredClone(this.initialState) } };
|
|
24880
25148
|
if (!this.#snapshot || !before.revision || this.#snapshot.revision !== before.revision) {
|
|
24881
25149
|
replay = new CursorTransport({
|
|
@@ -24940,7 +25208,7 @@ var CursorSession = class {
|
|
|
24940
25208
|
return rejected("invalidRequest", "Cursor requires nonempty text input");
|
|
24941
25209
|
let before;
|
|
24942
25210
|
try {
|
|
24943
|
-
before = this.#native(this.#fresh);
|
|
25211
|
+
before = this.#acpOnlyNativeStore() ? [] : this.#native(this.#fresh);
|
|
24944
25212
|
} catch (error51) {
|
|
24945
25213
|
return { ok: false, error: cursorError(error51) };
|
|
24946
25214
|
}
|
|
@@ -24962,8 +25230,26 @@ var CursorSession = class {
|
|
|
24962
25230
|
} else if (command.type === "model.select") {
|
|
24963
25231
|
selections = cursorModelSelection(this.info, command.model.id);
|
|
24964
25232
|
} else {
|
|
24965
|
-
|
|
25233
|
+
const catalog = cursorModes(this.info);
|
|
25234
|
+
if (!catalog.modes.some((mode) => mode.id === command.permissionModeId))
|
|
24966
25235
|
return rejected("invalidRequest", "Unknown Cursor execution mode");
|
|
25236
|
+
if (cursorCurrentPermissionModeId(this.info) === command.permissionModeId) {
|
|
25237
|
+
this.initialState.effectivePermissionModeId = command.permissionModeId;
|
|
25238
|
+
return { ok: true, value: { completed: true } };
|
|
25239
|
+
}
|
|
25240
|
+
if (cursorUsesNativeSessionModes(this.info)) {
|
|
25241
|
+
await this.transport.setMode(command.permissionModeId);
|
|
25242
|
+
this.info.modes = {
|
|
25243
|
+
currentModeId: command.permissionModeId,
|
|
25244
|
+
availableModes: this.info.modes?.availableModes ?? []
|
|
25245
|
+
};
|
|
25246
|
+
this.initialState.effectivePermissionModeId = command.permissionModeId;
|
|
25247
|
+
this.#channel.emit({
|
|
25248
|
+
kind: "event",
|
|
25249
|
+
event: { type: "session.state.changed", state: structuredClone(this.initialState) }
|
|
25250
|
+
});
|
|
25251
|
+
return { ok: true, value: { completed: true } };
|
|
25252
|
+
}
|
|
24967
25253
|
selections = [["mode", command.permissionModeId]];
|
|
24968
25254
|
}
|
|
24969
25255
|
for (const [configId, value] of selections) {
|
|
@@ -25046,21 +25332,21 @@ var CursorSession = class {
|
|
|
25046
25332
|
}
|
|
25047
25333
|
};
|
|
25048
25334
|
try {
|
|
25049
|
-
const
|
|
25335
|
+
const acpOnly = this.#acpOnlyNativeStore();
|
|
25336
|
+
const after = acpOnly ? [] : this.#native(this.#fresh);
|
|
25050
25337
|
const added = after.filter((turn) => !before.some((old) => old.id === turn.id));
|
|
25051
25338
|
const administrative = command.input.map((part) => part.text).join("\n").trim().toLowerCase() === "/copy-request-id";
|
|
25052
25339
|
if (administrative && JSON.stringify(before) === JSON.stringify(after)) {
|
|
25340
|
+
} else if (acpOnly && outcome.status === "succeeded" && output.hasVisibleAssistantText()) {
|
|
25341
|
+
nativeTurnRef = cursorNativeTurnRef(this.#nativeSessionId, command.turnId);
|
|
25342
|
+
this.#recordAcpOnlyTurn(command, output);
|
|
25343
|
+
this.#fresh = false;
|
|
25053
25344
|
} else {
|
|
25054
25345
|
const prompted = added.filter((turn) => !turn.notification);
|
|
25055
25346
|
const own = prompted[0];
|
|
25056
25347
|
if (!own || prompted.length !== 1 || after.length !== before.length + added.length || before.some((turn, index) => after[index]?.id !== turn.id) || own.text !== command.input.map((part) => part.text).join("\n"))
|
|
25057
25348
|
throw new Error("Cursor terminal has no unique, verified native turn identity");
|
|
25058
|
-
nativeTurnRef =
|
|
25059
|
-
harnessId: "cursor-cli",
|
|
25060
|
-
nativeSessionId: this.transport.sessionId,
|
|
25061
|
-
nativeTurnKey: own.id,
|
|
25062
|
-
formatVersion: 1
|
|
25063
|
-
});
|
|
25349
|
+
nativeTurnRef = cursorNativeTurnRef(this.#nativeSessionId, own.id);
|
|
25064
25350
|
this.#fresh = false;
|
|
25065
25351
|
const ownIndex = after.findIndex((turn) => turn.id === own.id);
|
|
25066
25352
|
if (outcome.status === "succeeded" && cursorForkAvailable() && (ownIndex === after.length - 1 || after[ownIndex + 1]?.rewindRoot))
|
package/bin/codexhost
CHANGED
|
Binary file
|
package/libexec/codexhost-shim
CHANGED
|
Binary file
|
|
Binary file
|