@posthog/agent 2.3.168 → 2.3.171
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/agent.js +649 -425
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +620 -397
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +597 -377
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/adapters/acp-connection.ts +53 -334
- package/src/adapters/base-acp-agent.ts +13 -2
- package/src/adapters/codex/codex-agent.ts +386 -0
- package/src/adapters/codex/codex-client.ts +168 -0
- package/src/adapters/codex/session-state.ts +65 -0
- package/src/adapters/codex/settings.ts +127 -0
- package/src/adapters/codex/spawn.ts +8 -0
- package/src/agent.ts +1 -0
- package/src/types.ts +1 -0
package/dist/server/bin.cjs
CHANGED
|
@@ -509,7 +509,7 @@ var require_has_flag = __commonJS({
|
|
|
509
509
|
var require_supports_color = __commonJS({
|
|
510
510
|
"../../node_modules/supports-color/index.js"(exports2, module2) {
|
|
511
511
|
"use strict";
|
|
512
|
-
var
|
|
512
|
+
var os7 = require("os");
|
|
513
513
|
var tty = require("tty");
|
|
514
514
|
var hasFlag = require_has_flag();
|
|
515
515
|
var { env } = process;
|
|
@@ -557,7 +557,7 @@ var require_supports_color = __commonJS({
|
|
|
557
557
|
return min;
|
|
558
558
|
}
|
|
559
559
|
if (process.platform === "win32") {
|
|
560
|
-
const osRelease =
|
|
560
|
+
const osRelease = os7.release().split(".");
|
|
561
561
|
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
562
562
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
563
563
|
}
|
|
@@ -805,10 +805,10 @@ var require_src2 = __commonJS({
|
|
|
805
805
|
var fs_1 = require("fs");
|
|
806
806
|
var debug_1 = __importDefault(require_src());
|
|
807
807
|
var log = debug_1.default("@kwsites/file-exists");
|
|
808
|
-
function check(
|
|
809
|
-
log(`checking %s`,
|
|
808
|
+
function check(path13, isFile, isDirectory) {
|
|
809
|
+
log(`checking %s`, path13);
|
|
810
810
|
try {
|
|
811
|
-
const stat = fs_1.statSync(
|
|
811
|
+
const stat = fs_1.statSync(path13);
|
|
812
812
|
if (stat.isFile() && isFile) {
|
|
813
813
|
log(`[OK] path represents a file`);
|
|
814
814
|
return true;
|
|
@@ -828,8 +828,8 @@ var require_src2 = __commonJS({
|
|
|
828
828
|
throw e;
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
|
-
function exists2(
|
|
832
|
-
return check(
|
|
831
|
+
function exists2(path13, type = exports2.READABLE) {
|
|
832
|
+
return check(path13, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
|
|
833
833
|
}
|
|
834
834
|
exports2.exists = exists2;
|
|
835
835
|
exports2.FILE = 1;
|
|
@@ -897,14 +897,14 @@ var import_commander = require("commander");
|
|
|
897
897
|
var import_zod4 = require("zod");
|
|
898
898
|
|
|
899
899
|
// src/server/agent-server.ts
|
|
900
|
-
var
|
|
900
|
+
var import_sdk5 = require("@agentclientprotocol/sdk");
|
|
901
901
|
var import_node_server = require("@hono/node-server");
|
|
902
902
|
var import_hono = require("hono");
|
|
903
903
|
|
|
904
904
|
// package.json
|
|
905
905
|
var package_default = {
|
|
906
906
|
name: "@posthog/agent",
|
|
907
|
-
version: "2.3.
|
|
907
|
+
version: "2.3.171",
|
|
908
908
|
repository: "https://github.com/PostHog/code",
|
|
909
909
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
910
910
|
exports: {
|
|
@@ -1066,64 +1066,7 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
1066
1066
|
};
|
|
1067
1067
|
|
|
1068
1068
|
// src/adapters/acp-connection.ts
|
|
1069
|
-
var
|
|
1070
|
-
|
|
1071
|
-
// src/gateway-models.ts
|
|
1072
|
-
var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
|
|
1073
|
-
var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
|
|
1074
|
-
var CACHE_TTL = 10 * 60 * 1e3;
|
|
1075
|
-
var gatewayModelsCache = null;
|
|
1076
|
-
async function fetchGatewayModels(options) {
|
|
1077
|
-
const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
|
|
1078
|
-
if (!gatewayUrl) {
|
|
1079
|
-
return [];
|
|
1080
|
-
}
|
|
1081
|
-
if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
|
|
1082
|
-
return gatewayModelsCache.models;
|
|
1083
|
-
}
|
|
1084
|
-
const modelsUrl = `${gatewayUrl}/v1/models`;
|
|
1085
|
-
try {
|
|
1086
|
-
const response = await fetch(modelsUrl);
|
|
1087
|
-
if (!response.ok) {
|
|
1088
|
-
return [];
|
|
1089
|
-
}
|
|
1090
|
-
const data = await response.json();
|
|
1091
|
-
const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
|
|
1092
|
-
gatewayModelsCache = {
|
|
1093
|
-
models,
|
|
1094
|
-
expiry: Date.now() + CACHE_TTL,
|
|
1095
|
-
url: gatewayUrl
|
|
1096
|
-
};
|
|
1097
|
-
return models;
|
|
1098
|
-
} catch {
|
|
1099
|
-
return [];
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
function isAnthropicModel(model) {
|
|
1103
|
-
if (model.owned_by) {
|
|
1104
|
-
return model.owned_by === "anthropic";
|
|
1105
|
-
}
|
|
1106
|
-
return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
|
|
1107
|
-
}
|
|
1108
|
-
var PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
|
|
1109
|
-
function formatGatewayModelName(model) {
|
|
1110
|
-
return formatModelId(model.id);
|
|
1111
|
-
}
|
|
1112
|
-
function formatModelId(modelId) {
|
|
1113
|
-
let cleanId = modelId;
|
|
1114
|
-
for (const prefix of PROVIDER_PREFIXES) {
|
|
1115
|
-
if (cleanId.startsWith(prefix)) {
|
|
1116
|
-
cleanId = cleanId.slice(prefix.length);
|
|
1117
|
-
break;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
cleanId = cleanId.replace(/(\d)-(\d)/g, "$1.$2");
|
|
1121
|
-
const words = cleanId.split(/[-_]/).map((word) => {
|
|
1122
|
-
if (word.match(/^[0-9.]+$/)) return word;
|
|
1123
|
-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
1124
|
-
});
|
|
1125
|
-
return words.join(" ");
|
|
1126
|
-
}
|
|
1069
|
+
var import_sdk4 = require("@agentclientprotocol/sdk");
|
|
1127
1070
|
|
|
1128
1071
|
// src/utils/logger.ts
|
|
1129
1072
|
var Logger = class _Logger {
|
|
@@ -1382,6 +1325,63 @@ function unreachable(value, logger) {
|
|
|
1382
1325
|
logger.error(`Unexpected case: ${valueAsString}`);
|
|
1383
1326
|
}
|
|
1384
1327
|
|
|
1328
|
+
// src/gateway-models.ts
|
|
1329
|
+
var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
|
|
1330
|
+
var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
|
|
1331
|
+
var CACHE_TTL = 10 * 60 * 1e3;
|
|
1332
|
+
var gatewayModelsCache = null;
|
|
1333
|
+
async function fetchGatewayModels(options) {
|
|
1334
|
+
const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
|
|
1335
|
+
if (!gatewayUrl) {
|
|
1336
|
+
return [];
|
|
1337
|
+
}
|
|
1338
|
+
if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
|
|
1339
|
+
return gatewayModelsCache.models;
|
|
1340
|
+
}
|
|
1341
|
+
const modelsUrl = `${gatewayUrl}/v1/models`;
|
|
1342
|
+
try {
|
|
1343
|
+
const response = await fetch(modelsUrl);
|
|
1344
|
+
if (!response.ok) {
|
|
1345
|
+
return [];
|
|
1346
|
+
}
|
|
1347
|
+
const data = await response.json();
|
|
1348
|
+
const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
|
|
1349
|
+
gatewayModelsCache = {
|
|
1350
|
+
models,
|
|
1351
|
+
expiry: Date.now() + CACHE_TTL,
|
|
1352
|
+
url: gatewayUrl
|
|
1353
|
+
};
|
|
1354
|
+
return models;
|
|
1355
|
+
} catch {
|
|
1356
|
+
return [];
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
function isAnthropicModel(model) {
|
|
1360
|
+
if (model.owned_by) {
|
|
1361
|
+
return model.owned_by === "anthropic";
|
|
1362
|
+
}
|
|
1363
|
+
return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
|
|
1364
|
+
}
|
|
1365
|
+
var PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
|
|
1366
|
+
function formatGatewayModelName(model) {
|
|
1367
|
+
return formatModelId(model.id);
|
|
1368
|
+
}
|
|
1369
|
+
function formatModelId(modelId) {
|
|
1370
|
+
let cleanId = modelId;
|
|
1371
|
+
for (const prefix of PROVIDER_PREFIXES) {
|
|
1372
|
+
if (cleanId.startsWith(prefix)) {
|
|
1373
|
+
cleanId = cleanId.slice(prefix.length);
|
|
1374
|
+
break;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
cleanId = cleanId.replace(/(\d)-(\d)/g, "$1.$2");
|
|
1378
|
+
const words = cleanId.split(/[-_]/).map((word) => {
|
|
1379
|
+
if (word.match(/^[0-9.]+$/)) return word;
|
|
1380
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
1381
|
+
});
|
|
1382
|
+
return words.join(" ");
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
1385
|
// src/adapters/base-acp-agent.ts
|
|
1386
1386
|
var DEFAULT_CONTEXT_WINDOW = 2e5;
|
|
1387
1387
|
var BaseAcpAgent = class {
|
|
@@ -1589,8 +1589,8 @@ var ToolContentBuilder = class {
|
|
|
1589
1589
|
this.items.push({ type: "content", content: image(data, mimeType, uri) });
|
|
1590
1590
|
return this;
|
|
1591
1591
|
}
|
|
1592
|
-
diff(
|
|
1593
|
-
this.items.push({ type: "diff", path:
|
|
1592
|
+
diff(path13, oldText, newText) {
|
|
1593
|
+
this.items.push({ type: "diff", path: path13, oldText, newText });
|
|
1594
1594
|
return this;
|
|
1595
1595
|
}
|
|
1596
1596
|
build() {
|
|
@@ -5001,6 +5001,201 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
5001
5001
|
}
|
|
5002
5002
|
};
|
|
5003
5003
|
|
|
5004
|
+
// src/adapters/codex/codex-agent.ts
|
|
5005
|
+
var import_sdk3 = require("@agentclientprotocol/sdk");
|
|
5006
|
+
|
|
5007
|
+
// src/adapters/codex/codex-client.ts
|
|
5008
|
+
function createCodexClient(upstreamClient, logger, sessionState, callbacks) {
|
|
5009
|
+
const terminalHandles = /* @__PURE__ */ new Map();
|
|
5010
|
+
return {
|
|
5011
|
+
async requestPermission(params) {
|
|
5012
|
+
logger.debug("Relaying permission request to upstream", {
|
|
5013
|
+
sessionId: params.sessionId
|
|
5014
|
+
});
|
|
5015
|
+
return upstreamClient.requestPermission(params);
|
|
5016
|
+
},
|
|
5017
|
+
async sessionUpdate(params) {
|
|
5018
|
+
const update = params.update;
|
|
5019
|
+
if (update?.sessionUpdate === "usage_update") {
|
|
5020
|
+
const used = update.used;
|
|
5021
|
+
const size = update.size;
|
|
5022
|
+
if (used !== void 0) sessionState.contextUsed = used;
|
|
5023
|
+
if (size !== void 0) sessionState.contextSize = size;
|
|
5024
|
+
const inputTokens = update.inputTokens;
|
|
5025
|
+
const outputTokens = update.outputTokens;
|
|
5026
|
+
if (inputTokens !== void 0) {
|
|
5027
|
+
sessionState.accumulatedUsage.inputTokens += inputTokens;
|
|
5028
|
+
}
|
|
5029
|
+
if (outputTokens !== void 0) {
|
|
5030
|
+
sessionState.accumulatedUsage.outputTokens += outputTokens;
|
|
5031
|
+
}
|
|
5032
|
+
const cachedRead = update.cachedReadTokens;
|
|
5033
|
+
const cachedWrite = update.cachedWriteTokens;
|
|
5034
|
+
if (cachedRead !== void 0) {
|
|
5035
|
+
sessionState.accumulatedUsage.cachedReadTokens += cachedRead;
|
|
5036
|
+
}
|
|
5037
|
+
if (cachedWrite !== void 0) {
|
|
5038
|
+
sessionState.accumulatedUsage.cachedWriteTokens += cachedWrite;
|
|
5039
|
+
}
|
|
5040
|
+
callbacks?.onUsageUpdate?.(update);
|
|
5041
|
+
}
|
|
5042
|
+
await upstreamClient.sessionUpdate(params);
|
|
5043
|
+
},
|
|
5044
|
+
async readTextFile(params) {
|
|
5045
|
+
return upstreamClient.readTextFile(params);
|
|
5046
|
+
},
|
|
5047
|
+
async writeTextFile(params) {
|
|
5048
|
+
return upstreamClient.writeTextFile(params);
|
|
5049
|
+
},
|
|
5050
|
+
async createTerminal(params) {
|
|
5051
|
+
const handle = await upstreamClient.createTerminal(params);
|
|
5052
|
+
terminalHandles.set(handle.id, handle);
|
|
5053
|
+
return { terminalId: handle.id };
|
|
5054
|
+
},
|
|
5055
|
+
async terminalOutput(params) {
|
|
5056
|
+
const handle = terminalHandles.get(params.terminalId);
|
|
5057
|
+
if (!handle) {
|
|
5058
|
+
return { output: "", truncated: false };
|
|
5059
|
+
}
|
|
5060
|
+
return handle.currentOutput();
|
|
5061
|
+
},
|
|
5062
|
+
async releaseTerminal(params) {
|
|
5063
|
+
const handle = terminalHandles.get(params.terminalId);
|
|
5064
|
+
if (handle) {
|
|
5065
|
+
terminalHandles.delete(params.terminalId);
|
|
5066
|
+
const result = await handle.release();
|
|
5067
|
+
return result ?? void 0;
|
|
5068
|
+
}
|
|
5069
|
+
},
|
|
5070
|
+
async waitForTerminalExit(params) {
|
|
5071
|
+
const handle = terminalHandles.get(params.terminalId);
|
|
5072
|
+
if (!handle) {
|
|
5073
|
+
return { exitCode: 1 };
|
|
5074
|
+
}
|
|
5075
|
+
return handle.waitForExit();
|
|
5076
|
+
},
|
|
5077
|
+
async killTerminal(params) {
|
|
5078
|
+
const handle = terminalHandles.get(params.terminalId);
|
|
5079
|
+
if (handle) {
|
|
5080
|
+
return handle.kill();
|
|
5081
|
+
}
|
|
5082
|
+
},
|
|
5083
|
+
async extMethod(method, params) {
|
|
5084
|
+
return upstreamClient.extMethod(method, params);
|
|
5085
|
+
},
|
|
5086
|
+
async extNotification(method, params) {
|
|
5087
|
+
return upstreamClient.extNotification(method, params);
|
|
5088
|
+
}
|
|
5089
|
+
};
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5092
|
+
// src/adapters/codex/session-state.ts
|
|
5093
|
+
function createSessionState(sessionId, cwd, opts) {
|
|
5094
|
+
return {
|
|
5095
|
+
sessionId,
|
|
5096
|
+
cwd,
|
|
5097
|
+
modeId: opts?.modeId ?? "default",
|
|
5098
|
+
modelId: opts?.modelId,
|
|
5099
|
+
configOptions: [],
|
|
5100
|
+
accumulatedUsage: {
|
|
5101
|
+
inputTokens: 0,
|
|
5102
|
+
outputTokens: 0,
|
|
5103
|
+
cachedReadTokens: 0,
|
|
5104
|
+
cachedWriteTokens: 0
|
|
5105
|
+
},
|
|
5106
|
+
cancelled: false,
|
|
5107
|
+
taskRunId: opts?.taskRunId,
|
|
5108
|
+
taskId: opts?.taskId
|
|
5109
|
+
};
|
|
5110
|
+
}
|
|
5111
|
+
function resetUsage(state) {
|
|
5112
|
+
state.accumulatedUsage = {
|
|
5113
|
+
inputTokens: 0,
|
|
5114
|
+
outputTokens: 0,
|
|
5115
|
+
cachedReadTokens: 0,
|
|
5116
|
+
cachedWriteTokens: 0
|
|
5117
|
+
};
|
|
5118
|
+
}
|
|
5119
|
+
|
|
5120
|
+
// src/adapters/codex/settings.ts
|
|
5121
|
+
var fs5 = __toESM(require("fs"), 1);
|
|
5122
|
+
var os5 = __toESM(require("os"), 1);
|
|
5123
|
+
var path7 = __toESM(require("path"), 1);
|
|
5124
|
+
var CodexSettingsManager = class {
|
|
5125
|
+
cwd;
|
|
5126
|
+
settings = {};
|
|
5127
|
+
initialized = false;
|
|
5128
|
+
constructor(cwd) {
|
|
5129
|
+
this.cwd = cwd;
|
|
5130
|
+
}
|
|
5131
|
+
async initialize() {
|
|
5132
|
+
if (this.initialized) {
|
|
5133
|
+
return;
|
|
5134
|
+
}
|
|
5135
|
+
await this.loadSettings();
|
|
5136
|
+
this.initialized = true;
|
|
5137
|
+
}
|
|
5138
|
+
getConfigPath() {
|
|
5139
|
+
return path7.join(os5.homedir(), ".codex", "config.toml");
|
|
5140
|
+
}
|
|
5141
|
+
async loadSettings() {
|
|
5142
|
+
const configPath = this.getConfigPath();
|
|
5143
|
+
try {
|
|
5144
|
+
const content = await fs5.promises.readFile(configPath, "utf-8");
|
|
5145
|
+
this.settings = parseCodexToml(content, this.cwd);
|
|
5146
|
+
} catch {
|
|
5147
|
+
this.settings = {};
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5150
|
+
getSettings() {
|
|
5151
|
+
return this.settings;
|
|
5152
|
+
}
|
|
5153
|
+
getCwd() {
|
|
5154
|
+
return this.cwd;
|
|
5155
|
+
}
|
|
5156
|
+
async setCwd(cwd) {
|
|
5157
|
+
if (this.cwd === cwd) {
|
|
5158
|
+
return;
|
|
5159
|
+
}
|
|
5160
|
+
this.dispose();
|
|
5161
|
+
this.cwd = cwd;
|
|
5162
|
+
this.initialized = false;
|
|
5163
|
+
await this.initialize();
|
|
5164
|
+
}
|
|
5165
|
+
dispose() {
|
|
5166
|
+
this.initialized = false;
|
|
5167
|
+
}
|
|
5168
|
+
};
|
|
5169
|
+
function parseCodexToml(content, cwd) {
|
|
5170
|
+
const settings = {};
|
|
5171
|
+
let currentSection = "";
|
|
5172
|
+
for (const line of content.split("\n")) {
|
|
5173
|
+
const trimmed2 = line.trim();
|
|
5174
|
+
if (!trimmed2 || trimmed2.startsWith("#")) continue;
|
|
5175
|
+
const sectionMatch = trimmed2.match(/^\[(.+)\]$/);
|
|
5176
|
+
if (sectionMatch) {
|
|
5177
|
+
currentSection = sectionMatch[1] ?? "";
|
|
5178
|
+
continue;
|
|
5179
|
+
}
|
|
5180
|
+
const kvMatch = trimmed2.match(/^(\w+)\s*=\s*(.+)$/);
|
|
5181
|
+
if (!kvMatch) continue;
|
|
5182
|
+
const key = kvMatch[1];
|
|
5183
|
+
let value = kvMatch[2]?.trim() ?? "";
|
|
5184
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
5185
|
+
value = value.slice(1, -1);
|
|
5186
|
+
}
|
|
5187
|
+
if (!currentSection) {
|
|
5188
|
+
if (key === "model") settings.model = value;
|
|
5189
|
+
if (key === "personality") settings.personality = value;
|
|
5190
|
+
if (key === "model_reasoning_effort")
|
|
5191
|
+
settings.modelReasoningEffort = value;
|
|
5192
|
+
} else if (currentSection === `projects."${cwd}"`) {
|
|
5193
|
+
if (key === "trust_level") settings.trustLevel = value;
|
|
5194
|
+
}
|
|
5195
|
+
}
|
|
5196
|
+
return settings;
|
|
5197
|
+
}
|
|
5198
|
+
|
|
5004
5199
|
// src/adapters/codex/spawn.ts
|
|
5005
5200
|
var import_node_child_process2 = require("child_process");
|
|
5006
5201
|
var import_node_fs2 = require("fs");
|
|
@@ -5021,6 +5216,10 @@ function buildConfigArgs(options) {
|
|
|
5021
5216
|
if (options.model) {
|
|
5022
5217
|
args.push("-c", `model="${options.model}"`);
|
|
5023
5218
|
}
|
|
5219
|
+
if (options.instructions) {
|
|
5220
|
+
const escaped = options.instructions.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
5221
|
+
args.push("-c", `instructions="${escaped}"`);
|
|
5222
|
+
}
|
|
5024
5223
|
return args;
|
|
5025
5224
|
}
|
|
5026
5225
|
function findCodexBinary(options) {
|
|
@@ -5097,64 +5296,236 @@ function spawnCodexProcess(options) {
|
|
|
5097
5296
|
};
|
|
5098
5297
|
}
|
|
5099
5298
|
|
|
5100
|
-
// src/adapters/
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
const
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5299
|
+
// src/adapters/codex/codex-agent.ts
|
|
5300
|
+
var CodexAcpAgent = class extends BaseAcpAgent {
|
|
5301
|
+
adapterName = "codex";
|
|
5302
|
+
codexProcess;
|
|
5303
|
+
codexConnection;
|
|
5304
|
+
sessionState;
|
|
5305
|
+
constructor(client, options) {
|
|
5306
|
+
super(client);
|
|
5307
|
+
this.logger = new Logger({ debug: true, prefix: "[CodexAcpAgent]" });
|
|
5308
|
+
this.codexProcess = spawnCodexProcess({
|
|
5309
|
+
...options.codexProcessOptions,
|
|
5310
|
+
logger: this.logger,
|
|
5311
|
+
processCallbacks: options.processCallbacks
|
|
5312
|
+
});
|
|
5313
|
+
const codexReadable = nodeReadableToWebReadable(this.codexProcess.stdout);
|
|
5314
|
+
const codexWritable = nodeWritableToWebWritable(this.codexProcess.stdin);
|
|
5315
|
+
const codexStream = (0, import_sdk3.ndJsonStream)(codexWritable, codexReadable);
|
|
5316
|
+
const cwd = options.codexProcessOptions.cwd ?? process.cwd();
|
|
5317
|
+
const settingsManager = new CodexSettingsManager(cwd);
|
|
5318
|
+
const abortController = new AbortController();
|
|
5319
|
+
this.session = {
|
|
5320
|
+
abortController,
|
|
5321
|
+
settingsManager,
|
|
5322
|
+
notificationHistory: [],
|
|
5323
|
+
cancelled: false
|
|
5324
|
+
};
|
|
5325
|
+
this.codexConnection = new import_sdk3.ClientSideConnection(
|
|
5326
|
+
(_agent) => createCodexClient(
|
|
5327
|
+
this.client,
|
|
5328
|
+
this.logger,
|
|
5329
|
+
this.sessionState ?? {
|
|
5330
|
+
sessionId: "",
|
|
5331
|
+
cwd: "",
|
|
5332
|
+
modeId: "default",
|
|
5333
|
+
configOptions: [],
|
|
5334
|
+
accumulatedUsage: {
|
|
5335
|
+
inputTokens: 0,
|
|
5336
|
+
outputTokens: 0,
|
|
5337
|
+
cachedReadTokens: 0,
|
|
5338
|
+
cachedWriteTokens: 0
|
|
5339
|
+
},
|
|
5340
|
+
cancelled: false
|
|
5341
|
+
}
|
|
5342
|
+
),
|
|
5343
|
+
codexStream
|
|
5344
|
+
);
|
|
5345
|
+
}
|
|
5346
|
+
async initialize(request) {
|
|
5347
|
+
await this.session.settingsManager.initialize();
|
|
5348
|
+
const response = await this.codexConnection.initialize(request);
|
|
5133
5349
|
return {
|
|
5134
|
-
...
|
|
5135
|
-
|
|
5136
|
-
|
|
5350
|
+
...response,
|
|
5351
|
+
agentCapabilities: {
|
|
5352
|
+
...response.agentCapabilities,
|
|
5353
|
+
sessionCapabilities: {
|
|
5354
|
+
...response.agentCapabilities?.sessionCapabilities,
|
|
5355
|
+
resume: {},
|
|
5356
|
+
fork: {}
|
|
5357
|
+
},
|
|
5358
|
+
_meta: {
|
|
5359
|
+
posthog: {
|
|
5360
|
+
resumeSession: true
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
},
|
|
5364
|
+
agentInfo: {
|
|
5365
|
+
name: package_default.name,
|
|
5366
|
+
title: "Codex Agent",
|
|
5367
|
+
version: package_default.version
|
|
5368
|
+
}
|
|
5137
5369
|
};
|
|
5138
|
-
});
|
|
5139
|
-
if (payload.result?.configOptions) {
|
|
5140
|
-
return { ...msg, result: { ...payload.result, configOptions: filtered } };
|
|
5141
5370
|
}
|
|
5142
|
-
|
|
5371
|
+
async newSession(params) {
|
|
5372
|
+
const meta = params._meta;
|
|
5373
|
+
const response = await this.codexConnection.newSession(params);
|
|
5374
|
+
this.sessionState = createSessionState(response.sessionId, params.cwd, {
|
|
5375
|
+
taskRunId: meta?.taskRunId,
|
|
5376
|
+
taskId: meta?.taskId ?? meta?.persistence?.taskId,
|
|
5377
|
+
modeId: response.modes?.currentModeId ?? "default",
|
|
5378
|
+
modelId: response.models?.currentModelId
|
|
5379
|
+
});
|
|
5380
|
+
this.sessionId = response.sessionId;
|
|
5381
|
+
this.sessionState.configOptions = response.configOptions ?? [];
|
|
5382
|
+
if (meta?.taskRunId) {
|
|
5383
|
+
await this.client.extNotification(POSTHOG_NOTIFICATIONS.SDK_SESSION, {
|
|
5384
|
+
taskRunId: meta.taskRunId,
|
|
5385
|
+
sessionId: response.sessionId,
|
|
5386
|
+
adapter: "codex"
|
|
5387
|
+
});
|
|
5388
|
+
}
|
|
5389
|
+
this.logger.info("Codex session created", {
|
|
5390
|
+
sessionId: response.sessionId,
|
|
5391
|
+
taskRunId: meta?.taskRunId
|
|
5392
|
+
});
|
|
5393
|
+
return response;
|
|
5394
|
+
}
|
|
5395
|
+
async loadSession(params) {
|
|
5396
|
+
const response = await this.codexConnection.loadSession(params);
|
|
5397
|
+
this.sessionState = createSessionState(params.sessionId, params.cwd);
|
|
5398
|
+
this.sessionId = params.sessionId;
|
|
5399
|
+
this.sessionState.configOptions = response.configOptions ?? [];
|
|
5400
|
+
return response;
|
|
5401
|
+
}
|
|
5402
|
+
async unstable_resumeSession(params) {
|
|
5403
|
+
const loadResponse = await this.codexConnection.loadSession({
|
|
5404
|
+
sessionId: params.sessionId,
|
|
5405
|
+
cwd: params.cwd,
|
|
5406
|
+
mcpServers: params.mcpServers ?? []
|
|
5407
|
+
});
|
|
5408
|
+
this.sessionState = createSessionState(params.sessionId, params.cwd);
|
|
5409
|
+
this.sessionId = params.sessionId;
|
|
5410
|
+
this.sessionState.configOptions = loadResponse.configOptions ?? [];
|
|
5411
|
+
const meta = params._meta;
|
|
5412
|
+
if (meta?.taskRunId) {
|
|
5413
|
+
await this.client.extNotification(POSTHOG_NOTIFICATIONS.SDK_SESSION, {
|
|
5414
|
+
taskRunId: meta.taskRunId,
|
|
5415
|
+
sessionId: params.sessionId,
|
|
5416
|
+
adapter: "codex"
|
|
5417
|
+
});
|
|
5418
|
+
}
|
|
5143
5419
|
return {
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
update: { ...payload.params.update, configOptions: filtered }
|
|
5148
|
-
}
|
|
5420
|
+
modes: loadResponse.modes,
|
|
5421
|
+
models: loadResponse.models,
|
|
5422
|
+
configOptions: loadResponse.configOptions
|
|
5149
5423
|
};
|
|
5150
5424
|
}
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5425
|
+
async unstable_forkSession(params) {
|
|
5426
|
+
const newResponse = await this.codexConnection.newSession({
|
|
5427
|
+
cwd: params.cwd,
|
|
5428
|
+
mcpServers: params.mcpServers ?? [],
|
|
5429
|
+
_meta: params._meta
|
|
5430
|
+
});
|
|
5431
|
+
this.sessionState = createSessionState(newResponse.sessionId, params.cwd);
|
|
5432
|
+
this.sessionId = newResponse.sessionId;
|
|
5433
|
+
this.sessionState.configOptions = newResponse.configOptions ?? [];
|
|
5434
|
+
return newResponse;
|
|
5435
|
+
}
|
|
5436
|
+
async listSessions(params) {
|
|
5437
|
+
return this.codexConnection.listSessions(params);
|
|
5438
|
+
}
|
|
5439
|
+
async unstable_listSessions(params) {
|
|
5440
|
+
return this.codexConnection.listSessions(params);
|
|
5441
|
+
}
|
|
5442
|
+
async prompt(params) {
|
|
5443
|
+
if (this.sessionState) {
|
|
5444
|
+
this.sessionState.cancelled = false;
|
|
5445
|
+
this.sessionState.interruptReason = void 0;
|
|
5446
|
+
resetUsage(this.sessionState);
|
|
5447
|
+
}
|
|
5448
|
+
const response = await this.codexConnection.prompt(params);
|
|
5449
|
+
if (this.sessionState && response.usage) {
|
|
5450
|
+
this.sessionState.accumulatedUsage.inputTokens += response.usage.inputTokens ?? 0;
|
|
5451
|
+
this.sessionState.accumulatedUsage.outputTokens += response.usage.outputTokens ?? 0;
|
|
5452
|
+
this.sessionState.accumulatedUsage.cachedReadTokens += response.usage.cachedReadTokens ?? 0;
|
|
5453
|
+
this.sessionState.accumulatedUsage.cachedWriteTokens += response.usage.cachedWriteTokens ?? 0;
|
|
5454
|
+
}
|
|
5455
|
+
if (this.sessionState?.taskRunId) {
|
|
5456
|
+
const { accumulatedUsage } = this.sessionState;
|
|
5457
|
+
await this.client.extNotification(POSTHOG_NOTIFICATIONS.TURN_COMPLETE, {
|
|
5458
|
+
sessionId: params.sessionId,
|
|
5459
|
+
stopReason: response.stopReason ?? "end_turn",
|
|
5460
|
+
usage: {
|
|
5461
|
+
inputTokens: accumulatedUsage.inputTokens,
|
|
5462
|
+
outputTokens: accumulatedUsage.outputTokens,
|
|
5463
|
+
cachedReadTokens: accumulatedUsage.cachedReadTokens,
|
|
5464
|
+
cachedWriteTokens: accumulatedUsage.cachedWriteTokens,
|
|
5465
|
+
totalTokens: accumulatedUsage.inputTokens + accumulatedUsage.outputTokens + accumulatedUsage.cachedReadTokens + accumulatedUsage.cachedWriteTokens
|
|
5466
|
+
}
|
|
5467
|
+
});
|
|
5468
|
+
if (response.usage) {
|
|
5469
|
+
await this.client.extNotification("_posthog/usage_update", {
|
|
5470
|
+
sessionId: params.sessionId,
|
|
5471
|
+
used: {
|
|
5472
|
+
inputTokens: response.usage.inputTokens ?? 0,
|
|
5473
|
+
outputTokens: response.usage.outputTokens ?? 0,
|
|
5474
|
+
cachedReadTokens: response.usage.cachedReadTokens ?? 0,
|
|
5475
|
+
cachedWriteTokens: response.usage.cachedWriteTokens ?? 0
|
|
5476
|
+
},
|
|
5477
|
+
cost: null
|
|
5478
|
+
});
|
|
5479
|
+
}
|
|
5480
|
+
}
|
|
5481
|
+
return response;
|
|
5482
|
+
}
|
|
5483
|
+
async interrupt() {
|
|
5484
|
+
if (this.sessionState) {
|
|
5485
|
+
this.sessionState.cancelled = true;
|
|
5486
|
+
}
|
|
5487
|
+
await this.codexConnection.cancel({
|
|
5488
|
+
sessionId: this.sessionId
|
|
5489
|
+
});
|
|
5490
|
+
}
|
|
5491
|
+
async cancel(params) {
|
|
5492
|
+
if (this.sessionState) {
|
|
5493
|
+
this.sessionState.cancelled = true;
|
|
5494
|
+
const meta = params._meta;
|
|
5495
|
+
if (meta?.interruptReason) {
|
|
5496
|
+
this.sessionState.interruptReason = meta.interruptReason;
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
await this.codexConnection.cancel(params);
|
|
5500
|
+
}
|
|
5501
|
+
async setSessionMode(params) {
|
|
5502
|
+
const response = await this.codexConnection.setSessionMode(params);
|
|
5503
|
+
if (this.sessionState) {
|
|
5504
|
+
this.sessionState.modeId = params.modeId;
|
|
5505
|
+
}
|
|
5506
|
+
return response ?? {};
|
|
5507
|
+
}
|
|
5508
|
+
async setSessionConfigOption(params) {
|
|
5509
|
+
const response = await this.codexConnection.setSessionConfigOption(params);
|
|
5510
|
+
if (this.sessionState && response.configOptions) {
|
|
5511
|
+
this.sessionState.configOptions = response.configOptions;
|
|
5512
|
+
}
|
|
5513
|
+
return response;
|
|
5514
|
+
}
|
|
5515
|
+
async authenticate(_params) {
|
|
5516
|
+
}
|
|
5517
|
+
async closeSession() {
|
|
5518
|
+
this.logger.info("Closing Codex session", { sessionId: this.sessionId });
|
|
5519
|
+
this.session.settingsManager.dispose();
|
|
5520
|
+
try {
|
|
5521
|
+
this.codexProcess.kill();
|
|
5522
|
+
} catch (err) {
|
|
5523
|
+
this.logger.warn("Failed to kill codex-acp process", { error: err });
|
|
5524
|
+
}
|
|
5525
|
+
}
|
|
5526
|
+
};
|
|
5527
|
+
|
|
5528
|
+
// src/adapters/acp-connection.ts
|
|
5158
5529
|
function createAcpConnection(config = {}) {
|
|
5159
5530
|
const adapterType = config.adapter ?? "claude";
|
|
5160
5531
|
if (adapterType === "codex") {
|
|
@@ -5195,9 +5566,9 @@ function createClaudeConnection(config) {
|
|
|
5195
5566
|
hasLogWriter: !!logWriter
|
|
5196
5567
|
});
|
|
5197
5568
|
}
|
|
5198
|
-
const agentStream = (0,
|
|
5569
|
+
const agentStream = (0, import_sdk4.ndJsonStream)(agentWritable, streams.agent.readable);
|
|
5199
5570
|
let agent = null;
|
|
5200
|
-
const agentConnection = new
|
|
5571
|
+
const agentConnection = new import_sdk4.AgentSideConnection((client) => {
|
|
5201
5572
|
agent = new ClaudeAcpAgent(client, config.processCallbacks);
|
|
5202
5573
|
logger.info(`Created ${agent.adapterName} agent`);
|
|
5203
5574
|
return agent;
|
|
@@ -5227,214 +5598,63 @@ function createClaudeConnection(config) {
|
|
|
5227
5598
|
function createCodexConnection(config) {
|
|
5228
5599
|
const logger = config.logger?.child("CodexConnection") ?? new Logger({ debug: true, prefix: "[CodexConnection]" });
|
|
5229
5600
|
const { logWriter } = config;
|
|
5230
|
-
const
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
let loadRequestId = null;
|
|
5240
|
-
let newSessionRequestId = null;
|
|
5241
|
-
let sdkSessionEmitted = false;
|
|
5242
|
-
const reasoningEffortBySessionId = /* @__PURE__ */ new Map();
|
|
5243
|
-
let injectedConfigId = 0;
|
|
5244
|
-
const decoder = new TextDecoder();
|
|
5245
|
-
const encoder = new TextEncoder();
|
|
5246
|
-
let readBuffer = "";
|
|
5247
|
-
const taskRunId = config.taskRunId;
|
|
5248
|
-
const filteringReadable = clientReadable.pipeThrough(
|
|
5249
|
-
new TransformStream({
|
|
5250
|
-
transform(chunk, controller) {
|
|
5251
|
-
readBuffer += decoder.decode(chunk, { stream: true });
|
|
5252
|
-
const lines = readBuffer.split("\n");
|
|
5253
|
-
readBuffer = lines.pop() ?? "";
|
|
5254
|
-
const outputLines = [];
|
|
5255
|
-
for (const line of lines) {
|
|
5256
|
-
const trimmed2 = line.trim();
|
|
5257
|
-
if (!trimmed2) {
|
|
5258
|
-
outputLines.push(line);
|
|
5259
|
-
continue;
|
|
5260
|
-
}
|
|
5261
|
-
let shouldFilter = false;
|
|
5262
|
-
try {
|
|
5263
|
-
const msg = JSON.parse(trimmed2);
|
|
5264
|
-
const sessionId = msg?.params?.sessionId ?? msg?.result?.sessionId ?? null;
|
|
5265
|
-
const configOptions = msg?.result?.configOptions ?? msg?.params?.update?.configOptions;
|
|
5266
|
-
if (sessionId && configOptions) {
|
|
5267
|
-
const effort = extractReasoningEffort(configOptions);
|
|
5268
|
-
if (effort) {
|
|
5269
|
-
reasoningEffortBySessionId.set(sessionId, effort);
|
|
5270
|
-
}
|
|
5271
|
-
}
|
|
5272
|
-
if (!sdkSessionEmitted && newSessionRequestId !== null && msg.id === newSessionRequestId && "result" in msg) {
|
|
5273
|
-
const sessionId2 = msg.result?.sessionId;
|
|
5274
|
-
if (sessionId2 && taskRunId) {
|
|
5275
|
-
const sdkSessionNotification = {
|
|
5276
|
-
jsonrpc: "2.0",
|
|
5277
|
-
method: POSTHOG_NOTIFICATIONS.SDK_SESSION,
|
|
5278
|
-
params: {
|
|
5279
|
-
taskRunId,
|
|
5280
|
-
sessionId: sessionId2,
|
|
5281
|
-
adapter: "codex"
|
|
5282
|
-
}
|
|
5283
|
-
};
|
|
5284
|
-
outputLines.push(JSON.stringify(sdkSessionNotification));
|
|
5285
|
-
sdkSessionEmitted = true;
|
|
5286
|
-
}
|
|
5287
|
-
newSessionRequestId = null;
|
|
5288
|
-
}
|
|
5289
|
-
if (isLoadingSession) {
|
|
5290
|
-
if (msg.id === loadRequestId && "result" in msg) {
|
|
5291
|
-
logger.debug("session/load complete, resuming stream");
|
|
5292
|
-
isLoadingSession = false;
|
|
5293
|
-
loadRequestId = null;
|
|
5294
|
-
} else if (msg.method === "session/update") {
|
|
5295
|
-
shouldFilter = true;
|
|
5296
|
-
}
|
|
5297
|
-
}
|
|
5298
|
-
if (!shouldFilter && allowedModelIds && allowedModelIds.size > 0) {
|
|
5299
|
-
const updated = filterModelConfigOptions(msg, allowedModelIds);
|
|
5300
|
-
if (updated) {
|
|
5301
|
-
outputLines.push(JSON.stringify(updated));
|
|
5302
|
-
continue;
|
|
5303
|
-
}
|
|
5304
|
-
}
|
|
5305
|
-
} catch {
|
|
5306
|
-
}
|
|
5307
|
-
if (!shouldFilter) {
|
|
5308
|
-
outputLines.push(line);
|
|
5309
|
-
const isChunkNoise = trimmed2.includes('"sessionUpdate":"agent_message_chunk"') || trimmed2.includes('"sessionUpdate":"agent_thought_chunk"');
|
|
5310
|
-
if (!isChunkNoise) {
|
|
5311
|
-
logger.debug("codex-acp stdout:", trimmed2);
|
|
5312
|
-
}
|
|
5313
|
-
}
|
|
5314
|
-
}
|
|
5315
|
-
if (outputLines.length > 0) {
|
|
5316
|
-
const output = `${outputLines.join("\n")}
|
|
5317
|
-
`;
|
|
5318
|
-
controller.enqueue(encoder.encode(output));
|
|
5319
|
-
}
|
|
5320
|
-
},
|
|
5321
|
-
flush(controller) {
|
|
5322
|
-
if (readBuffer.trim()) {
|
|
5323
|
-
controller.enqueue(encoder.encode(readBuffer));
|
|
5324
|
-
}
|
|
5325
|
-
}
|
|
5326
|
-
})
|
|
5327
|
-
);
|
|
5328
|
-
clientReadable = filteringReadable;
|
|
5329
|
-
const originalWritable = clientWritable;
|
|
5330
|
-
clientWritable = new WritableStream({
|
|
5331
|
-
write(chunk) {
|
|
5332
|
-
const text2 = decoder.decode(chunk, { stream: true });
|
|
5333
|
-
const trimmed2 = text2.trim();
|
|
5334
|
-
logger.debug("codex-acp stdin:", trimmed2);
|
|
5335
|
-
try {
|
|
5336
|
-
const msg = JSON.parse(trimmed2);
|
|
5337
|
-
if (msg.method === "session/set_config_option" && msg.params?.configId === "reasoning_effort" && msg.params?.sessionId && msg.params?.value) {
|
|
5338
|
-
reasoningEffortBySessionId.set(
|
|
5339
|
-
msg.params.sessionId,
|
|
5340
|
-
msg.params.value
|
|
5341
|
-
);
|
|
5342
|
-
}
|
|
5343
|
-
if (msg.method === "session/prompt" && msg.params?.sessionId) {
|
|
5344
|
-
const effort = reasoningEffortBySessionId.get(msg.params.sessionId);
|
|
5345
|
-
if (effort) {
|
|
5346
|
-
const injection = {
|
|
5347
|
-
jsonrpc: "2.0",
|
|
5348
|
-
id: `reasoning_effort_${Date.now()}_${injectedConfigId++}`,
|
|
5349
|
-
method: "session/set_config_option",
|
|
5350
|
-
params: {
|
|
5351
|
-
sessionId: msg.params.sessionId,
|
|
5352
|
-
configId: "reasoning_effort",
|
|
5353
|
-
value: effort
|
|
5354
|
-
}
|
|
5355
|
-
};
|
|
5356
|
-
const injectionLine = `${JSON.stringify(injection)}
|
|
5357
|
-
`;
|
|
5358
|
-
const writer2 = originalWritable.getWriter();
|
|
5359
|
-
return writer2.write(encoder.encode(injectionLine)).then(() => writer2.releaseLock()).then(() => {
|
|
5360
|
-
const nextWriter = originalWritable.getWriter();
|
|
5361
|
-
return nextWriter.write(chunk).finally(() => nextWriter.releaseLock());
|
|
5362
|
-
});
|
|
5363
|
-
}
|
|
5364
|
-
}
|
|
5365
|
-
if (msg.method === "session/new" && msg.id) {
|
|
5366
|
-
logger.debug("session/new detected, tracking request ID");
|
|
5367
|
-
newSessionRequestId = msg.id;
|
|
5368
|
-
} else if (msg.method === "session/load" && msg.id) {
|
|
5369
|
-
logger.debug("session/load detected, pausing stream updates");
|
|
5370
|
-
isLoadingSession = true;
|
|
5371
|
-
loadRequestId = msg.id;
|
|
5372
|
-
}
|
|
5373
|
-
} catch {
|
|
5374
|
-
}
|
|
5375
|
-
const writer = originalWritable.getWriter();
|
|
5376
|
-
return writer.write(chunk).finally(() => writer.releaseLock());
|
|
5377
|
-
},
|
|
5378
|
-
close() {
|
|
5379
|
-
const writer = originalWritable.getWriter();
|
|
5380
|
-
return writer.close().finally(() => writer.releaseLock());
|
|
5381
|
-
}
|
|
5382
|
-
});
|
|
5383
|
-
const shouldTapLogs = config.taskRunId && logWriter;
|
|
5384
|
-
if (shouldTapLogs && config.taskRunId) {
|
|
5385
|
-
const taskRunId2 = config.taskRunId;
|
|
5386
|
-
if (!logWriter.isRegistered(taskRunId2)) {
|
|
5387
|
-
logWriter.register(taskRunId2, {
|
|
5388
|
-
taskId: config.taskId ?? taskRunId2,
|
|
5389
|
-
runId: taskRunId2
|
|
5601
|
+
const streams = createBidirectionalStreams();
|
|
5602
|
+
let agentWritable = streams.agent.writable;
|
|
5603
|
+
let clientWritable = streams.client.writable;
|
|
5604
|
+
if (config.taskRunId && logWriter) {
|
|
5605
|
+
if (!logWriter.isRegistered(config.taskRunId)) {
|
|
5606
|
+
logWriter.register(config.taskRunId, {
|
|
5607
|
+
taskId: config.taskId ?? config.taskRunId,
|
|
5608
|
+
runId: config.taskRunId,
|
|
5609
|
+
deviceType: config.deviceType
|
|
5390
5610
|
});
|
|
5391
5611
|
}
|
|
5392
|
-
|
|
5612
|
+
const taskRunId = config.taskRunId;
|
|
5613
|
+
agentWritable = createTappedWritableStream(streams.agent.writable, {
|
|
5393
5614
|
onMessage: (line) => {
|
|
5394
|
-
logWriter.appendRawLine(
|
|
5615
|
+
logWriter.appendRawLine(taskRunId, line);
|
|
5616
|
+
},
|
|
5617
|
+
logger
|
|
5618
|
+
});
|
|
5619
|
+
clientWritable = createTappedWritableStream(streams.client.writable, {
|
|
5620
|
+
onMessage: (line) => {
|
|
5621
|
+
logWriter.appendRawLine(taskRunId, line);
|
|
5395
5622
|
},
|
|
5396
5623
|
logger
|
|
5397
5624
|
});
|
|
5398
|
-
const originalReadable = clientReadable;
|
|
5399
|
-
const logDecoder = new TextDecoder();
|
|
5400
|
-
let logBuffer = "";
|
|
5401
|
-
clientReadable = originalReadable.pipeThrough(
|
|
5402
|
-
new TransformStream({
|
|
5403
|
-
transform(chunk, controller) {
|
|
5404
|
-
logBuffer += logDecoder.decode(chunk, { stream: true });
|
|
5405
|
-
const lines = logBuffer.split("\n");
|
|
5406
|
-
logBuffer = lines.pop() ?? "";
|
|
5407
|
-
for (const line of lines) {
|
|
5408
|
-
if (line.trim()) {
|
|
5409
|
-
logWriter.appendRawLine(taskRunId2, line);
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5412
|
-
controller.enqueue(chunk);
|
|
5413
|
-
},
|
|
5414
|
-
flush() {
|
|
5415
|
-
if (logBuffer.trim()) {
|
|
5416
|
-
logWriter.appendRawLine(taskRunId2, logBuffer);
|
|
5417
|
-
}
|
|
5418
|
-
}
|
|
5419
|
-
})
|
|
5420
|
-
);
|
|
5421
5625
|
} else {
|
|
5422
5626
|
logger.info("Tapped streams NOT enabled for Codex", {
|
|
5423
5627
|
hasTaskRunId: !!config.taskRunId,
|
|
5424
5628
|
hasLogWriter: !!logWriter
|
|
5425
5629
|
});
|
|
5426
5630
|
}
|
|
5631
|
+
const agentStream = (0, import_sdk4.ndJsonStream)(agentWritable, streams.agent.readable);
|
|
5632
|
+
let agent = null;
|
|
5633
|
+
const agentConnection = new import_sdk4.AgentSideConnection((client) => {
|
|
5634
|
+
agent = new CodexAcpAgent(client, {
|
|
5635
|
+
codexProcessOptions: config.codexOptions ?? {},
|
|
5636
|
+
processCallbacks: config.processCallbacks
|
|
5637
|
+
});
|
|
5638
|
+
logger.info(`Created ${agent.adapterName} agent`);
|
|
5639
|
+
return agent;
|
|
5640
|
+
}, agentStream);
|
|
5427
5641
|
return {
|
|
5428
|
-
agentConnection
|
|
5642
|
+
agentConnection,
|
|
5429
5643
|
clientStreams: {
|
|
5430
|
-
readable:
|
|
5644
|
+
readable: streams.client.readable,
|
|
5431
5645
|
writable: clientWritable
|
|
5432
5646
|
},
|
|
5433
5647
|
cleanup: async () => {
|
|
5434
5648
|
logger.info("Cleaning up Codex connection");
|
|
5435
|
-
|
|
5649
|
+
if (agent) {
|
|
5650
|
+
await agent.closeSession();
|
|
5651
|
+
}
|
|
5436
5652
|
try {
|
|
5437
|
-
await
|
|
5653
|
+
await streams.client.writable.close();
|
|
5654
|
+
} catch {
|
|
5655
|
+
}
|
|
5656
|
+
try {
|
|
5657
|
+
await streams.agent.writable.close();
|
|
5438
5658
|
} catch {
|
|
5439
5659
|
}
|
|
5440
5660
|
}
|
|
@@ -5443,9 +5663,9 @@ function createCodexConnection(config) {
|
|
|
5443
5663
|
|
|
5444
5664
|
// src/adapters/claude/session/jsonl-hydration.ts
|
|
5445
5665
|
var import_node_crypto2 = require("crypto");
|
|
5446
|
-
var
|
|
5447
|
-
var
|
|
5448
|
-
var
|
|
5666
|
+
var fs6 = __toESM(require("fs/promises"), 1);
|
|
5667
|
+
var os6 = __toESM(require("os"), 1);
|
|
5668
|
+
var path8 = __toESM(require("path"), 1);
|
|
5449
5669
|
var CHARS_PER_TOKEN = 4;
|
|
5450
5670
|
var DEFAULT_MAX_TOKENS = 15e4;
|
|
5451
5671
|
function estimateTurnTokens(turn) {
|
|
@@ -5808,8 +6028,8 @@ var Saga = class {
|
|
|
5808
6028
|
};
|
|
5809
6029
|
|
|
5810
6030
|
// ../git/dist/queries.js
|
|
5811
|
-
var
|
|
5812
|
-
var
|
|
6031
|
+
var fs8 = __toESM(require("fs/promises"), 1);
|
|
6032
|
+
var path10 = __toESM(require("path"), 1);
|
|
5813
6033
|
|
|
5814
6034
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
5815
6035
|
var import_node_buffer = require("buffer");
|
|
@@ -5848,8 +6068,8 @@ function pathspec(...paths) {
|
|
|
5848
6068
|
cache.set(key, paths);
|
|
5849
6069
|
return key;
|
|
5850
6070
|
}
|
|
5851
|
-
function isPathSpec(
|
|
5852
|
-
return
|
|
6071
|
+
function isPathSpec(path13) {
|
|
6072
|
+
return path13 instanceof String && cache.has(path13);
|
|
5853
6073
|
}
|
|
5854
6074
|
function toPaths(pathSpec) {
|
|
5855
6075
|
return cache.get(pathSpec) || [];
|
|
@@ -5938,8 +6158,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
5938
6158
|
function forEachLineWithContent(input, callback) {
|
|
5939
6159
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
5940
6160
|
}
|
|
5941
|
-
function folderExists(
|
|
5942
|
-
return (0, import_file_exists.exists)(
|
|
6161
|
+
function folderExists(path13) {
|
|
6162
|
+
return (0, import_file_exists.exists)(path13, import_file_exists.FOLDER);
|
|
5943
6163
|
}
|
|
5944
6164
|
function append(target, item) {
|
|
5945
6165
|
if (Array.isArray(target)) {
|
|
@@ -6343,8 +6563,8 @@ function checkIsRepoRootTask() {
|
|
|
6343
6563
|
commands,
|
|
6344
6564
|
format: "utf-8",
|
|
6345
6565
|
onError,
|
|
6346
|
-
parser(
|
|
6347
|
-
return /^\.(git)?$/.test(
|
|
6566
|
+
parser(path13) {
|
|
6567
|
+
return /^\.(git)?$/.test(path13.trim());
|
|
6348
6568
|
}
|
|
6349
6569
|
};
|
|
6350
6570
|
}
|
|
@@ -6778,11 +6998,11 @@ function parseGrep(grep) {
|
|
|
6778
6998
|
const paths = /* @__PURE__ */ new Set();
|
|
6779
6999
|
const results = {};
|
|
6780
7000
|
forEachLineWithContent(grep, (input) => {
|
|
6781
|
-
const [
|
|
6782
|
-
paths.add(
|
|
6783
|
-
(results[
|
|
7001
|
+
const [path13, line, preview] = input.split(NULL);
|
|
7002
|
+
paths.add(path13);
|
|
7003
|
+
(results[path13] = results[path13] || []).push({
|
|
6784
7004
|
line: asNumber(line),
|
|
6785
|
-
path:
|
|
7005
|
+
path: path13,
|
|
6786
7006
|
preview
|
|
6787
7007
|
});
|
|
6788
7008
|
});
|
|
@@ -7547,14 +7767,14 @@ var init_hash_object = __esm({
|
|
|
7547
7767
|
init_task();
|
|
7548
7768
|
}
|
|
7549
7769
|
});
|
|
7550
|
-
function parseInit(bare,
|
|
7770
|
+
function parseInit(bare, path13, text2) {
|
|
7551
7771
|
const response = String(text2).trim();
|
|
7552
7772
|
let result;
|
|
7553
7773
|
if (result = initResponseRegex.exec(response)) {
|
|
7554
|
-
return new InitSummary(bare,
|
|
7774
|
+
return new InitSummary(bare, path13, false, result[1]);
|
|
7555
7775
|
}
|
|
7556
7776
|
if (result = reInitResponseRegex.exec(response)) {
|
|
7557
|
-
return new InitSummary(bare,
|
|
7777
|
+
return new InitSummary(bare, path13, true, result[1]);
|
|
7558
7778
|
}
|
|
7559
7779
|
let gitDir = "";
|
|
7560
7780
|
const tokens = response.split(" ");
|
|
@@ -7565,7 +7785,7 @@ function parseInit(bare, path12, text2) {
|
|
|
7565
7785
|
break;
|
|
7566
7786
|
}
|
|
7567
7787
|
}
|
|
7568
|
-
return new InitSummary(bare,
|
|
7788
|
+
return new InitSummary(bare, path13, /^re/i.test(response), gitDir);
|
|
7569
7789
|
}
|
|
7570
7790
|
var InitSummary;
|
|
7571
7791
|
var initResponseRegex;
|
|
@@ -7574,9 +7794,9 @@ var init_InitSummary = __esm({
|
|
|
7574
7794
|
"src/lib/responses/InitSummary.ts"() {
|
|
7575
7795
|
"use strict";
|
|
7576
7796
|
InitSummary = class {
|
|
7577
|
-
constructor(bare,
|
|
7797
|
+
constructor(bare, path13, existing, gitDir) {
|
|
7578
7798
|
this.bare = bare;
|
|
7579
|
-
this.path =
|
|
7799
|
+
this.path = path13;
|
|
7580
7800
|
this.existing = existing;
|
|
7581
7801
|
this.gitDir = gitDir;
|
|
7582
7802
|
}
|
|
@@ -7588,7 +7808,7 @@ var init_InitSummary = __esm({
|
|
|
7588
7808
|
function hasBareCommand(command) {
|
|
7589
7809
|
return command.includes(bareCommand);
|
|
7590
7810
|
}
|
|
7591
|
-
function initTask(bare = false,
|
|
7811
|
+
function initTask(bare = false, path13, customArgs) {
|
|
7592
7812
|
const commands = ["init", ...customArgs];
|
|
7593
7813
|
if (bare && !hasBareCommand(commands)) {
|
|
7594
7814
|
commands.splice(1, 0, bareCommand);
|
|
@@ -7597,7 +7817,7 @@ function initTask(bare = false, path12, customArgs) {
|
|
|
7597
7817
|
commands,
|
|
7598
7818
|
format: "utf-8",
|
|
7599
7819
|
parser(text2) {
|
|
7600
|
-
return parseInit(commands.includes("--bare"),
|
|
7820
|
+
return parseInit(commands.includes("--bare"), path13, text2);
|
|
7601
7821
|
}
|
|
7602
7822
|
};
|
|
7603
7823
|
}
|
|
@@ -8413,12 +8633,12 @@ var init_FileStatusSummary = __esm({
|
|
|
8413
8633
|
"use strict";
|
|
8414
8634
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
8415
8635
|
FileStatusSummary = class {
|
|
8416
|
-
constructor(
|
|
8417
|
-
this.path =
|
|
8636
|
+
constructor(path13, index, working_dir) {
|
|
8637
|
+
this.path = path13;
|
|
8418
8638
|
this.index = index;
|
|
8419
8639
|
this.working_dir = working_dir;
|
|
8420
8640
|
if (index === "R" || working_dir === "R") {
|
|
8421
|
-
const detail = fromPathRegex.exec(
|
|
8641
|
+
const detail = fromPathRegex.exec(path13) || [null, path13, path13];
|
|
8422
8642
|
this.from = detail[2] || "";
|
|
8423
8643
|
this.path = detail[1] || "";
|
|
8424
8644
|
}
|
|
@@ -8449,14 +8669,14 @@ function splitLine(result, lineStr) {
|
|
|
8449
8669
|
default:
|
|
8450
8670
|
return;
|
|
8451
8671
|
}
|
|
8452
|
-
function data(index, workingDir,
|
|
8672
|
+
function data(index, workingDir, path13) {
|
|
8453
8673
|
const raw = `${index}${workingDir}`;
|
|
8454
8674
|
const handler = parsers6.get(raw);
|
|
8455
8675
|
if (handler) {
|
|
8456
|
-
handler(result,
|
|
8676
|
+
handler(result, path13);
|
|
8457
8677
|
}
|
|
8458
8678
|
if (raw !== "##" && raw !== "!!") {
|
|
8459
|
-
result.files.push(new FileStatusSummary(
|
|
8679
|
+
result.files.push(new FileStatusSummary(path13, index, workingDir));
|
|
8460
8680
|
}
|
|
8461
8681
|
}
|
|
8462
8682
|
}
|
|
@@ -8769,9 +8989,9 @@ var init_simple_git_api = __esm({
|
|
|
8769
8989
|
next
|
|
8770
8990
|
);
|
|
8771
8991
|
}
|
|
8772
|
-
hashObject(
|
|
8992
|
+
hashObject(path13, write) {
|
|
8773
8993
|
return this._runTask(
|
|
8774
|
-
hashObjectTask(
|
|
8994
|
+
hashObjectTask(path13, write === true),
|
|
8775
8995
|
trailingFunctionArgument(arguments)
|
|
8776
8996
|
);
|
|
8777
8997
|
}
|
|
@@ -9124,8 +9344,8 @@ var init_branch = __esm({
|
|
|
9124
9344
|
}
|
|
9125
9345
|
});
|
|
9126
9346
|
function toPath(input) {
|
|
9127
|
-
const
|
|
9128
|
-
return
|
|
9347
|
+
const path13 = input.trim().replace(/^["']|["']$/g, "");
|
|
9348
|
+
return path13 && (0, import_node_path3.normalize)(path13);
|
|
9129
9349
|
}
|
|
9130
9350
|
var parseCheckIgnore;
|
|
9131
9351
|
var init_CheckIgnore = __esm({
|
|
@@ -9439,8 +9659,8 @@ __export(sub_module_exports, {
|
|
|
9439
9659
|
subModuleTask: () => subModuleTask,
|
|
9440
9660
|
updateSubModuleTask: () => updateSubModuleTask
|
|
9441
9661
|
});
|
|
9442
|
-
function addSubModuleTask(repo,
|
|
9443
|
-
return subModuleTask(["add", repo,
|
|
9662
|
+
function addSubModuleTask(repo, path13) {
|
|
9663
|
+
return subModuleTask(["add", repo, path13]);
|
|
9444
9664
|
}
|
|
9445
9665
|
function initSubModuleTask(customArgs) {
|
|
9446
9666
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -9770,8 +9990,8 @@ var require_git = __commonJS2({
|
|
|
9770
9990
|
}
|
|
9771
9991
|
return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
|
|
9772
9992
|
};
|
|
9773
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
9774
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
9993
|
+
Git2.prototype.submoduleAdd = function(repo, path13, then) {
|
|
9994
|
+
return this._runTask(addSubModuleTask2(repo, path13), trailingFunctionArgument2(arguments));
|
|
9775
9995
|
};
|
|
9776
9996
|
Git2.prototype.submoduleUpdate = function(args, then) {
|
|
9777
9997
|
return this._runTask(
|
|
@@ -10583,8 +10803,8 @@ var import_node_path5 = require("path");
|
|
|
10583
10803
|
|
|
10584
10804
|
// ../git/dist/sagas/tree.js
|
|
10585
10805
|
var import_node_fs3 = require("fs");
|
|
10586
|
-
var
|
|
10587
|
-
var
|
|
10806
|
+
var fs9 = __toESM(require("fs/promises"), 1);
|
|
10807
|
+
var path11 = __toESM(require("path"), 1);
|
|
10588
10808
|
var tar = __toESM(require("tar"), 1);
|
|
10589
10809
|
|
|
10590
10810
|
// ../git/dist/git-saga.js
|
|
@@ -10611,14 +10831,14 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10611
10831
|
tempIndexPath = null;
|
|
10612
10832
|
async executeGitOperations(input) {
|
|
10613
10833
|
const { baseDir, lastTreeHash, archivePath, signal } = input;
|
|
10614
|
-
const tmpDir =
|
|
10834
|
+
const tmpDir = path11.join(baseDir, ".git", "posthog-code-tmp");
|
|
10615
10835
|
await this.step({
|
|
10616
10836
|
name: "create_tmp_dir",
|
|
10617
|
-
execute: () =>
|
|
10837
|
+
execute: () => fs9.mkdir(tmpDir, { recursive: true }),
|
|
10618
10838
|
rollback: async () => {
|
|
10619
10839
|
}
|
|
10620
10840
|
});
|
|
10621
|
-
this.tempIndexPath =
|
|
10841
|
+
this.tempIndexPath = path11.join(tmpDir, `index-${Date.now()}`);
|
|
10622
10842
|
const tempIndexGit = this.git.env({
|
|
10623
10843
|
...process.env,
|
|
10624
10844
|
GIT_INDEX_FILE: this.tempIndexPath
|
|
@@ -10628,7 +10848,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10628
10848
|
execute: () => tempIndexGit.raw(["read-tree", "HEAD"]),
|
|
10629
10849
|
rollback: async () => {
|
|
10630
10850
|
if (this.tempIndexPath) {
|
|
10631
|
-
await
|
|
10851
|
+
await fs9.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10632
10852
|
});
|
|
10633
10853
|
}
|
|
10634
10854
|
}
|
|
@@ -10637,7 +10857,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10637
10857
|
const treeHash = await this.readOnlyStep("write_tree", () => tempIndexGit.raw(["write-tree"]));
|
|
10638
10858
|
if (lastTreeHash && treeHash === lastTreeHash) {
|
|
10639
10859
|
this.log.debug("No changes since last capture", { treeHash });
|
|
10640
|
-
await
|
|
10860
|
+
await fs9.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10641
10861
|
});
|
|
10642
10862
|
return { snapshot: null, changed: false };
|
|
10643
10863
|
}
|
|
@@ -10649,7 +10869,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10649
10869
|
}
|
|
10650
10870
|
});
|
|
10651
10871
|
const changes = await this.readOnlyStep("get_changes", () => this.getChanges(this.git, baseCommit, treeHash));
|
|
10652
|
-
await
|
|
10872
|
+
await fs9.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
10653
10873
|
});
|
|
10654
10874
|
const snapshot = {
|
|
10655
10875
|
treeHash,
|
|
@@ -10673,15 +10893,15 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10673
10893
|
if (filesToArchive.length === 0) {
|
|
10674
10894
|
return void 0;
|
|
10675
10895
|
}
|
|
10676
|
-
const existingFiles = filesToArchive.filter((f) => (0, import_node_fs3.existsSync)(
|
|
10896
|
+
const existingFiles = filesToArchive.filter((f) => (0, import_node_fs3.existsSync)(path11.join(baseDir, f)));
|
|
10677
10897
|
if (existingFiles.length === 0) {
|
|
10678
10898
|
return void 0;
|
|
10679
10899
|
}
|
|
10680
10900
|
await this.step({
|
|
10681
10901
|
name: "create_archive",
|
|
10682
10902
|
execute: async () => {
|
|
10683
|
-
const archiveDir =
|
|
10684
|
-
await
|
|
10903
|
+
const archiveDir = path11.dirname(archivePath);
|
|
10904
|
+
await fs9.mkdir(archiveDir, { recursive: true });
|
|
10685
10905
|
await tar.create({
|
|
10686
10906
|
gzip: true,
|
|
10687
10907
|
file: archivePath,
|
|
@@ -10689,7 +10909,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
10689
10909
|
}, existingFiles);
|
|
10690
10910
|
},
|
|
10691
10911
|
rollback: async () => {
|
|
10692
|
-
await
|
|
10912
|
+
await fs9.rm(archivePath, { force: true }).catch(() => {
|
|
10693
10913
|
});
|
|
10694
10914
|
}
|
|
10695
10915
|
});
|
|
@@ -10789,9 +11009,9 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10789
11009
|
const filesToExtract = changes.filter((c) => c.status !== "D").map((c) => c.path);
|
|
10790
11010
|
await this.readOnlyStep("backup_existing_files", async () => {
|
|
10791
11011
|
for (const filePath of filesToExtract) {
|
|
10792
|
-
const fullPath =
|
|
11012
|
+
const fullPath = path11.join(baseDir, filePath);
|
|
10793
11013
|
try {
|
|
10794
|
-
const content = await
|
|
11014
|
+
const content = await fs9.readFile(fullPath);
|
|
10795
11015
|
this.fileBackups.set(filePath, content);
|
|
10796
11016
|
} catch {
|
|
10797
11017
|
}
|
|
@@ -10808,16 +11028,16 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10808
11028
|
},
|
|
10809
11029
|
rollback: async () => {
|
|
10810
11030
|
for (const filePath of this.extractedFiles) {
|
|
10811
|
-
const fullPath =
|
|
11031
|
+
const fullPath = path11.join(baseDir, filePath);
|
|
10812
11032
|
const backup = this.fileBackups.get(filePath);
|
|
10813
11033
|
if (backup) {
|
|
10814
|
-
const dir =
|
|
10815
|
-
await
|
|
11034
|
+
const dir = path11.dirname(fullPath);
|
|
11035
|
+
await fs9.mkdir(dir, { recursive: true }).catch(() => {
|
|
10816
11036
|
});
|
|
10817
|
-
await
|
|
11037
|
+
await fs9.writeFile(fullPath, backup).catch(() => {
|
|
10818
11038
|
});
|
|
10819
11039
|
} else {
|
|
10820
|
-
await
|
|
11040
|
+
await fs9.rm(fullPath, { force: true }).catch(() => {
|
|
10821
11041
|
});
|
|
10822
11042
|
}
|
|
10823
11043
|
}
|
|
@@ -10825,10 +11045,10 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10825
11045
|
});
|
|
10826
11046
|
}
|
|
10827
11047
|
for (const change of changes.filter((c) => c.status === "D")) {
|
|
10828
|
-
const fullPath =
|
|
11048
|
+
const fullPath = path11.join(baseDir, change.path);
|
|
10829
11049
|
const backupContent = await this.readOnlyStep(`backup_${change.path}`, async () => {
|
|
10830
11050
|
try {
|
|
10831
|
-
return await
|
|
11051
|
+
return await fs9.readFile(fullPath);
|
|
10832
11052
|
} catch {
|
|
10833
11053
|
return null;
|
|
10834
11054
|
}
|
|
@@ -10836,15 +11056,15 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
10836
11056
|
await this.step({
|
|
10837
11057
|
name: `delete_${change.path}`,
|
|
10838
11058
|
execute: async () => {
|
|
10839
|
-
await
|
|
11059
|
+
await fs9.rm(fullPath, { force: true });
|
|
10840
11060
|
this.log.debug(`Deleted file: ${change.path}`);
|
|
10841
11061
|
},
|
|
10842
11062
|
rollback: async () => {
|
|
10843
11063
|
if (backupContent) {
|
|
10844
|
-
const dir =
|
|
10845
|
-
await
|
|
11064
|
+
const dir = path11.dirname(fullPath);
|
|
11065
|
+
await fs9.mkdir(dir, { recursive: true }).catch(() => {
|
|
10846
11066
|
});
|
|
10847
|
-
await
|
|
11067
|
+
await fs9.writeFile(fullPath, backupContent).catch(() => {
|
|
10848
11068
|
});
|
|
10849
11069
|
}
|
|
10850
11070
|
}
|
|
@@ -12378,13 +12598,13 @@ You MUST NOT create a new branch, close the existing PR, or create a new PR.`
|
|
|
12378
12598
|
onAcpMessage,
|
|
12379
12599
|
this.logger
|
|
12380
12600
|
);
|
|
12381
|
-
const clientStream = (0,
|
|
12382
|
-
const clientConnection = new
|
|
12601
|
+
const clientStream = (0, import_sdk5.ndJsonStream)(tappedWritable, tappedReadable);
|
|
12602
|
+
const clientConnection = new import_sdk5.ClientSideConnection(
|
|
12383
12603
|
() => this.createCloudClient(payload),
|
|
12384
12604
|
clientStream
|
|
12385
12605
|
);
|
|
12386
12606
|
await clientConnection.initialize({
|
|
12387
|
-
protocolVersion:
|
|
12607
|
+
protocolVersion: import_sdk5.PROTOCOL_VERSION,
|
|
12388
12608
|
clientCapabilities: {}
|
|
12389
12609
|
});
|
|
12390
12610
|
let preTaskRun = null;
|