@posthog/agent 2.3.510 → 2.3.517
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 +131 -104
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.js +212 -18
- package/dist/handoff-checkpoint.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +2 -1
- package/dist/server/agent-server.js +409 -160
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +389 -141
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/session/mcp-config.test.ts +112 -0
- package/src/adapters/claude/session/mcp-config.ts +45 -0
- package/src/adapters/claude/session/options.ts +4 -0
- package/src/server/agent-server.test.ts +59 -1
- package/src/server/agent-server.ts +54 -20
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 os8 = 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 = os8.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(path17, isFile2, isDirectory) {
|
|
809
|
+
log(`checking %s`, path17);
|
|
810
810
|
try {
|
|
811
|
-
const stat4 = fs_1.statSync(
|
|
811
|
+
const stat4 = fs_1.statSync(path17);
|
|
812
812
|
if (stat4.isFile() && isFile2) {
|
|
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(path17, type = exports2.READABLE) {
|
|
832
|
+
return check(path17, (type & exports2.FILE) > 0, (type & exports2.FOLDER) > 0);
|
|
833
833
|
}
|
|
834
834
|
exports2.exists = exists2;
|
|
835
835
|
exports2.FILE = 1;
|
|
@@ -925,11 +925,11 @@ var require_tree_sitter = __commonJS({
|
|
|
925
925
|
throw toThrow;
|
|
926
926
|
};
|
|
927
927
|
var scriptDirectory = "";
|
|
928
|
-
function locateFile(
|
|
928
|
+
function locateFile(path17) {
|
|
929
929
|
if (Module["locateFile"]) {
|
|
930
|
-
return Module["locateFile"](
|
|
930
|
+
return Module["locateFile"](path17, scriptDirectory);
|
|
931
931
|
}
|
|
932
|
-
return scriptDirectory +
|
|
932
|
+
return scriptDirectory + path17;
|
|
933
933
|
}
|
|
934
934
|
var readAsync, readBinary;
|
|
935
935
|
if (ENVIRONMENT_IS_NODE) {
|
|
@@ -3450,8 +3450,8 @@ var require_tree_sitter = __commonJS({
|
|
|
3450
3450
|
} else {
|
|
3451
3451
|
const url = input;
|
|
3452
3452
|
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
3453
|
-
const
|
|
3454
|
-
bytes = Promise.resolve(
|
|
3453
|
+
const fs14 = require("fs");
|
|
3454
|
+
bytes = Promise.resolve(fs14.readFileSync(url));
|
|
3455
3455
|
} else {
|
|
3456
3456
|
bytes = fetch(url).then((response) => response.arrayBuffer().then((buffer) => {
|
|
3457
3457
|
if (response.ok) {
|
|
@@ -3991,8 +3991,8 @@ function pathspec(...paths) {
|
|
|
3991
3991
|
cache.set(key, paths);
|
|
3992
3992
|
return key;
|
|
3993
3993
|
}
|
|
3994
|
-
function isPathSpec(
|
|
3995
|
-
return
|
|
3994
|
+
function isPathSpec(path17) {
|
|
3995
|
+
return path17 instanceof String && cache.has(path17);
|
|
3996
3996
|
}
|
|
3997
3997
|
function toPaths(pathSpec) {
|
|
3998
3998
|
return cache.get(pathSpec) || [];
|
|
@@ -4081,8 +4081,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
4081
4081
|
function forEachLineWithContent(input, callback) {
|
|
4082
4082
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
4083
4083
|
}
|
|
4084
|
-
function folderExists(
|
|
4085
|
-
return (0, import_file_exists.exists)(
|
|
4084
|
+
function folderExists(path17) {
|
|
4085
|
+
return (0, import_file_exists.exists)(path17, import_file_exists.FOLDER);
|
|
4086
4086
|
}
|
|
4087
4087
|
function append(target, item) {
|
|
4088
4088
|
if (Array.isArray(target)) {
|
|
@@ -4486,8 +4486,8 @@ function checkIsRepoRootTask() {
|
|
|
4486
4486
|
commands,
|
|
4487
4487
|
format: "utf-8",
|
|
4488
4488
|
onError,
|
|
4489
|
-
parser(
|
|
4490
|
-
return /^\.(git)?$/.test(
|
|
4489
|
+
parser(path17) {
|
|
4490
|
+
return /^\.(git)?$/.test(path17.trim());
|
|
4491
4491
|
}
|
|
4492
4492
|
};
|
|
4493
4493
|
}
|
|
@@ -4921,11 +4921,11 @@ function parseGrep(grep) {
|
|
|
4921
4921
|
const paths = /* @__PURE__ */ new Set();
|
|
4922
4922
|
const results = {};
|
|
4923
4923
|
forEachLineWithContent(grep, (input) => {
|
|
4924
|
-
const [
|
|
4925
|
-
paths.add(
|
|
4926
|
-
(results[
|
|
4924
|
+
const [path17, line, preview] = input.split(NULL);
|
|
4925
|
+
paths.add(path17);
|
|
4926
|
+
(results[path17] = results[path17] || []).push({
|
|
4927
4927
|
line: asNumber(line),
|
|
4928
|
-
path:
|
|
4928
|
+
path: path17,
|
|
4929
4929
|
preview
|
|
4930
4930
|
});
|
|
4931
4931
|
});
|
|
@@ -5690,14 +5690,14 @@ var init_hash_object = __esm({
|
|
|
5690
5690
|
init_task();
|
|
5691
5691
|
}
|
|
5692
5692
|
});
|
|
5693
|
-
function parseInit(bare,
|
|
5693
|
+
function parseInit(bare, path17, text2) {
|
|
5694
5694
|
const response = String(text2).trim();
|
|
5695
5695
|
let result;
|
|
5696
5696
|
if (result = initResponseRegex.exec(response)) {
|
|
5697
|
-
return new InitSummary(bare,
|
|
5697
|
+
return new InitSummary(bare, path17, false, result[1]);
|
|
5698
5698
|
}
|
|
5699
5699
|
if (result = reInitResponseRegex.exec(response)) {
|
|
5700
|
-
return new InitSummary(bare,
|
|
5700
|
+
return new InitSummary(bare, path17, true, result[1]);
|
|
5701
5701
|
}
|
|
5702
5702
|
let gitDir = "";
|
|
5703
5703
|
const tokens = response.split(" ");
|
|
@@ -5708,7 +5708,7 @@ function parseInit(bare, path16, text2) {
|
|
|
5708
5708
|
break;
|
|
5709
5709
|
}
|
|
5710
5710
|
}
|
|
5711
|
-
return new InitSummary(bare,
|
|
5711
|
+
return new InitSummary(bare, path17, /^re/i.test(response), gitDir);
|
|
5712
5712
|
}
|
|
5713
5713
|
var InitSummary;
|
|
5714
5714
|
var initResponseRegex;
|
|
@@ -5717,9 +5717,9 @@ var init_InitSummary = __esm({
|
|
|
5717
5717
|
"src/lib/responses/InitSummary.ts"() {
|
|
5718
5718
|
"use strict";
|
|
5719
5719
|
InitSummary = class {
|
|
5720
|
-
constructor(bare,
|
|
5720
|
+
constructor(bare, path17, existing, gitDir) {
|
|
5721
5721
|
this.bare = bare;
|
|
5722
|
-
this.path =
|
|
5722
|
+
this.path = path17;
|
|
5723
5723
|
this.existing = existing;
|
|
5724
5724
|
this.gitDir = gitDir;
|
|
5725
5725
|
}
|
|
@@ -5731,7 +5731,7 @@ var init_InitSummary = __esm({
|
|
|
5731
5731
|
function hasBareCommand(command) {
|
|
5732
5732
|
return command.includes(bareCommand);
|
|
5733
5733
|
}
|
|
5734
|
-
function initTask(bare = false,
|
|
5734
|
+
function initTask(bare = false, path17, customArgs) {
|
|
5735
5735
|
const commands = ["init", ...customArgs];
|
|
5736
5736
|
if (bare && !hasBareCommand(commands)) {
|
|
5737
5737
|
commands.splice(1, 0, bareCommand);
|
|
@@ -5740,7 +5740,7 @@ function initTask(bare = false, path16, customArgs) {
|
|
|
5740
5740
|
commands,
|
|
5741
5741
|
format: "utf-8",
|
|
5742
5742
|
parser(text2) {
|
|
5743
|
-
return parseInit(commands.includes("--bare"),
|
|
5743
|
+
return parseInit(commands.includes("--bare"), path17, text2);
|
|
5744
5744
|
}
|
|
5745
5745
|
};
|
|
5746
5746
|
}
|
|
@@ -6556,12 +6556,12 @@ var init_FileStatusSummary = __esm({
|
|
|
6556
6556
|
"use strict";
|
|
6557
6557
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
6558
6558
|
FileStatusSummary = class {
|
|
6559
|
-
constructor(
|
|
6560
|
-
this.path =
|
|
6559
|
+
constructor(path17, index, working_dir) {
|
|
6560
|
+
this.path = path17;
|
|
6561
6561
|
this.index = index;
|
|
6562
6562
|
this.working_dir = working_dir;
|
|
6563
6563
|
if (index === "R" || working_dir === "R") {
|
|
6564
|
-
const detail = fromPathRegex.exec(
|
|
6564
|
+
const detail = fromPathRegex.exec(path17) || [null, path17, path17];
|
|
6565
6565
|
this.from = detail[2] || "";
|
|
6566
6566
|
this.path = detail[1] || "";
|
|
6567
6567
|
}
|
|
@@ -6592,14 +6592,14 @@ function splitLine(result, lineStr) {
|
|
|
6592
6592
|
default:
|
|
6593
6593
|
return;
|
|
6594
6594
|
}
|
|
6595
|
-
function data(index, workingDir,
|
|
6595
|
+
function data(index, workingDir, path17) {
|
|
6596
6596
|
const raw = `${index}${workingDir}`;
|
|
6597
6597
|
const handler = parsers6.get(raw);
|
|
6598
6598
|
if (handler) {
|
|
6599
|
-
handler(result,
|
|
6599
|
+
handler(result, path17);
|
|
6600
6600
|
}
|
|
6601
6601
|
if (raw !== "##" && raw !== "!!") {
|
|
6602
|
-
result.files.push(new FileStatusSummary(
|
|
6602
|
+
result.files.push(new FileStatusSummary(path17, index, workingDir));
|
|
6603
6603
|
}
|
|
6604
6604
|
}
|
|
6605
6605
|
}
|
|
@@ -6912,9 +6912,9 @@ var init_simple_git_api = __esm({
|
|
|
6912
6912
|
next
|
|
6913
6913
|
);
|
|
6914
6914
|
}
|
|
6915
|
-
hashObject(
|
|
6915
|
+
hashObject(path17, write) {
|
|
6916
6916
|
return this._runTask(
|
|
6917
|
-
hashObjectTask(
|
|
6917
|
+
hashObjectTask(path17, write === true),
|
|
6918
6918
|
trailingFunctionArgument(arguments)
|
|
6919
6919
|
);
|
|
6920
6920
|
}
|
|
@@ -7267,8 +7267,8 @@ var init_branch = __esm({
|
|
|
7267
7267
|
}
|
|
7268
7268
|
});
|
|
7269
7269
|
function toPath(input) {
|
|
7270
|
-
const
|
|
7271
|
-
return
|
|
7270
|
+
const path17 = input.trim().replace(/^["']|["']$/g, "");
|
|
7271
|
+
return path17 && (0, import_node_path.normalize)(path17);
|
|
7272
7272
|
}
|
|
7273
7273
|
var parseCheckIgnore;
|
|
7274
7274
|
var init_CheckIgnore = __esm({
|
|
@@ -7582,8 +7582,8 @@ __export(sub_module_exports, {
|
|
|
7582
7582
|
subModuleTask: () => subModuleTask,
|
|
7583
7583
|
updateSubModuleTask: () => updateSubModuleTask
|
|
7584
7584
|
});
|
|
7585
|
-
function addSubModuleTask(repo,
|
|
7586
|
-
return subModuleTask(["add", repo,
|
|
7585
|
+
function addSubModuleTask(repo, path17) {
|
|
7586
|
+
return subModuleTask(["add", repo, path17]);
|
|
7587
7587
|
}
|
|
7588
7588
|
function initSubModuleTask(customArgs) {
|
|
7589
7589
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -7913,8 +7913,8 @@ var require_git = __commonJS2({
|
|
|
7913
7913
|
}
|
|
7914
7914
|
return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
|
|
7915
7915
|
};
|
|
7916
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
7917
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
7916
|
+
Git2.prototype.submoduleAdd = function(repo, path17, then) {
|
|
7917
|
+
return this._runTask(addSubModuleTask2(repo, path17), trailingFunctionArgument2(arguments));
|
|
7918
7918
|
};
|
|
7919
7919
|
Git2.prototype.submoduleUpdate = function(args2, then) {
|
|
7920
7920
|
return this._runTask(
|
|
@@ -8755,7 +8755,7 @@ var import_zod3 = require("zod");
|
|
|
8755
8755
|
// package.json
|
|
8756
8756
|
var package_default = {
|
|
8757
8757
|
name: "@posthog/agent",
|
|
8758
|
-
version: "2.3.
|
|
8758
|
+
version: "2.3.517",
|
|
8759
8759
|
repository: "https://github.com/PostHog/code",
|
|
8760
8760
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8761
8761
|
exports: {
|
|
@@ -9191,9 +9191,9 @@ function nodeWritableToWebWritable(nodeStream) {
|
|
|
9191
9191
|
|
|
9192
9192
|
// src/adapters/claude/claude-agent.ts
|
|
9193
9193
|
var import_node_crypto = require("crypto");
|
|
9194
|
-
var
|
|
9195
|
-
var
|
|
9196
|
-
var
|
|
9194
|
+
var fs9 = __toESM(require("fs"), 1);
|
|
9195
|
+
var os5 = __toESM(require("os"), 1);
|
|
9196
|
+
var path11 = __toESM(require("path"), 1);
|
|
9197
9197
|
var import_sdk2 = require("@agentclientprotocol/sdk");
|
|
9198
9198
|
var import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
9199
9199
|
var import_uuid = require("uuid");
|
|
@@ -13600,8 +13600,8 @@ var ToolContentBuilder = class {
|
|
|
13600
13600
|
this.items.push({ type: "content", content: image(data, mimeType, uri) });
|
|
13601
13601
|
return this;
|
|
13602
13602
|
}
|
|
13603
|
-
diff(
|
|
13604
|
-
this.items.push({ type: "diff", path:
|
|
13603
|
+
diff(path17, oldText, newText) {
|
|
13604
|
+
this.items.push({ type: "diff", path: path17, oldText, newText });
|
|
13605
13605
|
return this;
|
|
13606
13606
|
}
|
|
13607
13607
|
build() {
|
|
@@ -15976,6 +15976,31 @@ function getAvailableSlashCommands(commands) {
|
|
|
15976
15976
|
}
|
|
15977
15977
|
|
|
15978
15978
|
// src/adapters/claude/session/mcp-config.ts
|
|
15979
|
+
var fs6 = __toESM(require("fs"), 1);
|
|
15980
|
+
var os2 = __toESM(require("os"), 1);
|
|
15981
|
+
var path8 = __toESM(require("path"), 1);
|
|
15982
|
+
function loadUserClaudeJsonMcpServers(cwd, logger, homeDir = os2.homedir()) {
|
|
15983
|
+
const claudeJsonPath = path8.join(homeDir, ".claude.json");
|
|
15984
|
+
let raw;
|
|
15985
|
+
try {
|
|
15986
|
+
raw = fs6.readFileSync(claudeJsonPath, "utf8");
|
|
15987
|
+
} catch {
|
|
15988
|
+
return {};
|
|
15989
|
+
}
|
|
15990
|
+
let cfg;
|
|
15991
|
+
try {
|
|
15992
|
+
cfg = JSON.parse(raw);
|
|
15993
|
+
} catch (err2) {
|
|
15994
|
+
logger?.warn("Failed to parse ~/.claude.json", {
|
|
15995
|
+
error: err2 instanceof Error ? err2.message : String(err2)
|
|
15996
|
+
});
|
|
15997
|
+
return {};
|
|
15998
|
+
}
|
|
15999
|
+
const topLevel = cfg.mcpServers && typeof cfg.mcpServers === "object" ? cfg.mcpServers : {};
|
|
16000
|
+
const project = cfg.projects?.[cwd];
|
|
16001
|
+
const projectScoped = project?.mcpServers && typeof project.mcpServers === "object" ? project.mcpServers : {};
|
|
16002
|
+
return { ...topLevel, ...projectScoped };
|
|
16003
|
+
}
|
|
15979
16004
|
function parseMcpServers(params) {
|
|
15980
16005
|
const mcpServers = {};
|
|
15981
16006
|
if (!Array.isArray(params.mcpServers)) {
|
|
@@ -16002,9 +16027,9 @@ function parseMcpServers(params) {
|
|
|
16002
16027
|
|
|
16003
16028
|
// src/adapters/claude/session/options.ts
|
|
16004
16029
|
var import_node_child_process2 = require("child_process");
|
|
16005
|
-
var
|
|
16006
|
-
var
|
|
16007
|
-
var
|
|
16030
|
+
var fs7 = __toESM(require("fs"), 1);
|
|
16031
|
+
var os3 = __toESM(require("os"), 1);
|
|
16032
|
+
var path9 = __toESM(require("path"), 1);
|
|
16008
16033
|
|
|
16009
16034
|
// src/adapters/claude/session/instructions.ts
|
|
16010
16035
|
var BRANCH_NAMING = `
|
|
@@ -16055,8 +16080,9 @@ function buildSystemPrompt(customPrompt) {
|
|
|
16055
16080
|
}
|
|
16056
16081
|
return defaultPrompt;
|
|
16057
16082
|
}
|
|
16058
|
-
function buildMcpServers(userServers, acpServers) {
|
|
16083
|
+
function buildMcpServers(userServers, acpServers, projectScopedServers) {
|
|
16059
16084
|
return {
|
|
16085
|
+
...projectScopedServers,
|
|
16060
16086
|
...userServers || {},
|
|
16061
16087
|
...acpServers
|
|
16062
16088
|
};
|
|
@@ -16205,12 +16231,12 @@ function buildSpawnWrapper(sessionId, onProcessSpawned, onProcessExited, logger)
|
|
|
16205
16231
|
};
|
|
16206
16232
|
}
|
|
16207
16233
|
function ensureLocalSettings(cwd) {
|
|
16208
|
-
const claudeDir =
|
|
16209
|
-
const localSettingsPath =
|
|
16234
|
+
const claudeDir = path9.join(cwd, ".claude");
|
|
16235
|
+
const localSettingsPath = path9.join(claudeDir, "settings.local.json");
|
|
16210
16236
|
try {
|
|
16211
|
-
if (!
|
|
16212
|
-
|
|
16213
|
-
|
|
16237
|
+
if (!fs7.existsSync(localSettingsPath)) {
|
|
16238
|
+
fs7.mkdirSync(claudeDir, { recursive: true });
|
|
16239
|
+
fs7.writeFileSync(localSettingsPath, "{}\n", { flag: "wx" });
|
|
16214
16240
|
}
|
|
16215
16241
|
} catch {
|
|
16216
16242
|
}
|
|
@@ -16240,7 +16266,8 @@ function buildSessionOptions(params) {
|
|
|
16240
16266
|
},
|
|
16241
16267
|
mcpServers: buildMcpServers(
|
|
16242
16268
|
params.userProvidedOptions?.mcpServers,
|
|
16243
|
-
params.mcpServers
|
|
16269
|
+
params.mcpServers,
|
|
16270
|
+
loadUserClaudeJsonMcpServers(params.cwd, params.logger)
|
|
16244
16271
|
),
|
|
16245
16272
|
env: buildEnvironment(),
|
|
16246
16273
|
hooks: buildHooks(
|
|
@@ -16285,18 +16312,18 @@ function buildSessionOptions(params) {
|
|
|
16285
16312
|
return options;
|
|
16286
16313
|
}
|
|
16287
16314
|
function clearStatsigCache() {
|
|
16288
|
-
const statsigPath =
|
|
16289
|
-
process.env.CLAUDE_CONFIG_DIR ||
|
|
16315
|
+
const statsigPath = path9.join(
|
|
16316
|
+
process.env.CLAUDE_CONFIG_DIR || path9.join(os3.homedir(), ".claude"),
|
|
16290
16317
|
"statsig"
|
|
16291
16318
|
);
|
|
16292
|
-
|
|
16319
|
+
fs7.rm(statsigPath, { recursive: true, force: true }, () => {
|
|
16293
16320
|
});
|
|
16294
16321
|
}
|
|
16295
16322
|
|
|
16296
16323
|
// src/adapters/claude/session/settings.ts
|
|
16297
|
-
var
|
|
16298
|
-
var
|
|
16299
|
-
var
|
|
16324
|
+
var fs8 = __toESM(require("fs"), 1);
|
|
16325
|
+
var os4 = __toESM(require("os"), 1);
|
|
16326
|
+
var path10 = __toESM(require("path"), 1);
|
|
16300
16327
|
var import_minimatch = require("minimatch");
|
|
16301
16328
|
|
|
16302
16329
|
// src/utils/async-mutex.ts
|
|
@@ -16377,13 +16404,13 @@ function parseRule(rule) {
|
|
|
16377
16404
|
function normalizePath(filePath, cwd) {
|
|
16378
16405
|
let resolved = filePath;
|
|
16379
16406
|
if (resolved.startsWith("~/")) {
|
|
16380
|
-
resolved =
|
|
16407
|
+
resolved = path10.join(os4.homedir(), resolved.slice(2));
|
|
16381
16408
|
} else if (resolved.startsWith("./")) {
|
|
16382
|
-
resolved =
|
|
16383
|
-
} else if (!
|
|
16384
|
-
resolved =
|
|
16409
|
+
resolved = path10.join(cwd, resolved.slice(2));
|
|
16410
|
+
} else if (!path10.isAbsolute(resolved)) {
|
|
16411
|
+
resolved = path10.join(cwd, resolved);
|
|
16385
16412
|
}
|
|
16386
|
-
return
|
|
16413
|
+
return path10.normalize(resolved).replace(/\\/g, "/");
|
|
16387
16414
|
}
|
|
16388
16415
|
function matchesGlob(pattern, filePath, cwd) {
|
|
16389
16416
|
const normalizedPattern = normalizePath(pattern, cwd);
|
|
@@ -16430,11 +16457,11 @@ function formatRule(rule) {
|
|
|
16430
16457
|
}
|
|
16431
16458
|
async function writeFileAtomic(filePath, data) {
|
|
16432
16459
|
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
16433
|
-
await
|
|
16460
|
+
await fs8.promises.writeFile(tmpPath, data);
|
|
16434
16461
|
try {
|
|
16435
|
-
await
|
|
16462
|
+
await fs8.promises.rename(tmpPath, filePath);
|
|
16436
16463
|
} catch (error) {
|
|
16437
|
-
await
|
|
16464
|
+
await fs8.promises.rm(tmpPath, { force: true });
|
|
16438
16465
|
throw error;
|
|
16439
16466
|
}
|
|
16440
16467
|
}
|
|
@@ -16443,7 +16470,7 @@ async function loadSettingsFile(filePath) {
|
|
|
16443
16470
|
return {};
|
|
16444
16471
|
}
|
|
16445
16472
|
try {
|
|
16446
|
-
const content = await
|
|
16473
|
+
const content = await fs8.promises.readFile(filePath, "utf-8");
|
|
16447
16474
|
return JSON.parse(content);
|
|
16448
16475
|
} catch (error) {
|
|
16449
16476
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -16458,7 +16485,7 @@ async function loadSettingsFile(filePath) {
|
|
|
16458
16485
|
}
|
|
16459
16486
|
async function readSettingsFileForUpdate(filePath) {
|
|
16460
16487
|
try {
|
|
16461
|
-
const content = await
|
|
16488
|
+
const content = await fs8.promises.readFile(filePath, "utf-8");
|
|
16462
16489
|
return JSON.parse(content);
|
|
16463
16490
|
} catch (error) {
|
|
16464
16491
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
@@ -16504,11 +16531,11 @@ var SettingsManager = class {
|
|
|
16504
16531
|
return this.initPromise;
|
|
16505
16532
|
}
|
|
16506
16533
|
getUserSettingsPath() {
|
|
16507
|
-
const configDir = process.env.CLAUDE_CONFIG_DIR ||
|
|
16508
|
-
return
|
|
16534
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR || path10.join(os4.homedir(), ".claude");
|
|
16535
|
+
return path10.join(configDir, "settings.json");
|
|
16509
16536
|
}
|
|
16510
16537
|
getProjectSettingsPath() {
|
|
16511
|
-
return
|
|
16538
|
+
return path10.join(this.cwd, ".claude", "settings.json");
|
|
16512
16539
|
}
|
|
16513
16540
|
/**
|
|
16514
16541
|
* Local settings are anchored to the primary worktree so every worktree of
|
|
@@ -16516,7 +16543,7 @@ var SettingsManager = class {
|
|
|
16516
16543
|
* avoids re-prompting for the same permission in every worktree.
|
|
16517
16544
|
*/
|
|
16518
16545
|
getLocalSettingsPath() {
|
|
16519
|
-
return
|
|
16546
|
+
return path10.join(this.repoRoot, ".claude", "settings.local.json");
|
|
16520
16547
|
}
|
|
16521
16548
|
async loadAllSettings() {
|
|
16522
16549
|
this.repoRoot = await resolveMainRepoPath(this.cwd);
|
|
@@ -16643,7 +16670,7 @@ var SettingsManager = class {
|
|
|
16643
16670
|
}
|
|
16644
16671
|
permissions.allow = Array.from(current2);
|
|
16645
16672
|
const next = { ...existing, permissions };
|
|
16646
|
-
await
|
|
16673
|
+
await fs8.promises.mkdir(path10.dirname(filePath), { recursive: true });
|
|
16647
16674
|
await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
|
|
16648
16675
|
`);
|
|
16649
16676
|
this.localSettings = next;
|
|
@@ -16676,7 +16703,7 @@ var SettingsManager = class {
|
|
|
16676
16703
|
...existing,
|
|
16677
16704
|
posthogApprovedExecTools: Array.from(current2)
|
|
16678
16705
|
};
|
|
16679
|
-
await
|
|
16706
|
+
await fs8.promises.mkdir(path10.dirname(filePath), { recursive: true });
|
|
16680
16707
|
await writeFileAtomic(filePath, `${JSON.stringify(next, null, 2)}
|
|
16681
16708
|
`);
|
|
16682
16709
|
this.localSettings = next;
|
|
@@ -16782,7 +16809,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
|
|
|
16782
16809
|
};
|
|
16783
16810
|
}
|
|
16784
16811
|
async newSession(params) {
|
|
16785
|
-
if (
|
|
16812
|
+
if (fs9.existsSync(path11.resolve(os5.homedir(), ".claude.json.backup")) && !fs9.existsSync(path11.resolve(os5.homedir(), ".claude.json"))) {
|
|
16786
16813
|
throw import_sdk2.RequestError.authRequired();
|
|
16787
16814
|
}
|
|
16788
16815
|
const response = await this.createSession(params, {
|
|
@@ -17987,9 +18014,9 @@ function resetUsage(state) {
|
|
|
17987
18014
|
}
|
|
17988
18015
|
|
|
17989
18016
|
// src/adapters/codex/settings.ts
|
|
17990
|
-
var
|
|
17991
|
-
var
|
|
17992
|
-
var
|
|
18017
|
+
var fs10 = __toESM(require("fs"), 1);
|
|
18018
|
+
var os6 = __toESM(require("os"), 1);
|
|
18019
|
+
var path12 = __toESM(require("path"), 1);
|
|
17993
18020
|
var CodexSettingsManager = class {
|
|
17994
18021
|
cwd;
|
|
17995
18022
|
settings = { mcpServerNames: [] };
|
|
@@ -18000,12 +18027,12 @@ var CodexSettingsManager = class {
|
|
|
18000
18027
|
async initialize() {
|
|
18001
18028
|
}
|
|
18002
18029
|
getConfigPath() {
|
|
18003
|
-
return
|
|
18030
|
+
return path12.join(os6.homedir(), ".codex", "config.toml");
|
|
18004
18031
|
}
|
|
18005
18032
|
loadSettings() {
|
|
18006
18033
|
const configPath = this.getConfigPath();
|
|
18007
18034
|
try {
|
|
18008
|
-
const content =
|
|
18035
|
+
const content = fs10.readFileSync(configPath, "utf-8");
|
|
18009
18036
|
this.settings = parseCodexToml(content, this.cwd);
|
|
18010
18037
|
} catch {
|
|
18011
18038
|
this.settings = { mcpServerNames: [] };
|
|
@@ -18786,8 +18813,8 @@ var import_node_path5 = __toESM(require("path"), 1);
|
|
|
18786
18813
|
|
|
18787
18814
|
// ../git/dist/sagas/checkpoint.js
|
|
18788
18815
|
var import_node_crypto2 = require("crypto");
|
|
18789
|
-
var
|
|
18790
|
-
var
|
|
18816
|
+
var fs11 = __toESM(require("fs/promises"), 1);
|
|
18817
|
+
var path13 = __toESM(require("path"), 1);
|
|
18791
18818
|
|
|
18792
18819
|
// ../shared/dist/index.js
|
|
18793
18820
|
var CLOUD_PROMPT_PREFIX = "__twig_cloud_prompt_v1__:";
|
|
@@ -19060,12 +19087,12 @@ async function getGitBusyState(git) {
|
|
|
19060
19087
|
const toplevel = (await git.raw(["rev-parse", "--show-toplevel"])).trim();
|
|
19061
19088
|
const resolveGitPath = async (gitPath) => {
|
|
19062
19089
|
const relative = (await git.raw(["rev-parse", "--git-path", gitPath])).trim();
|
|
19063
|
-
return
|
|
19090
|
+
return path13.isAbsolute(relative) ? relative : path13.resolve(toplevel, relative);
|
|
19064
19091
|
};
|
|
19065
19092
|
const pathExists = async (gitPath) => {
|
|
19066
19093
|
const resolved = await resolveGitPath(gitPath);
|
|
19067
19094
|
try {
|
|
19068
|
-
await
|
|
19095
|
+
await fs11.access(resolved);
|
|
19069
19096
|
return true;
|
|
19070
19097
|
} catch {
|
|
19071
19098
|
return false;
|
|
@@ -19074,7 +19101,7 @@ async function getGitBusyState(git) {
|
|
|
19074
19101
|
const dirExists = async (gitPath) => {
|
|
19075
19102
|
const resolved = await resolveGitPath(gitPath);
|
|
19076
19103
|
try {
|
|
19077
|
-
const stat4 = await
|
|
19104
|
+
const stat4 = await fs11.stat(resolved);
|
|
19078
19105
|
return stat4.isDirectory();
|
|
19079
19106
|
} catch {
|
|
19080
19107
|
return false;
|
|
@@ -19094,6 +19121,7 @@ async function getGitBusyState(git) {
|
|
|
19094
19121
|
}
|
|
19095
19122
|
return { busy: false };
|
|
19096
19123
|
}
|
|
19124
|
+
var MAX_WORKTREE_FILE_BYTES = 1024 * 1024;
|
|
19097
19125
|
async function createWorktreeTree(git, baseDir, head) {
|
|
19098
19126
|
const { tempGit, tempIndexPath } = await createTempIndexGit(git, baseDir, "checkpoint-worktree");
|
|
19099
19127
|
try {
|
|
@@ -19103,13 +19131,85 @@ async function createWorktreeTree(git, baseDir, head) {
|
|
|
19103
19131
|
await tempGit.raw(["read-tree", "--empty"]);
|
|
19104
19132
|
}
|
|
19105
19133
|
await tempGit.raw(["add", "-A", "--", "."]);
|
|
19134
|
+
await reconcileLargeBlobs(tempGit, head, MAX_WORKTREE_FILE_BYTES);
|
|
19106
19135
|
const treeHash = await tempGit.raw(["write-tree"]);
|
|
19107
19136
|
return treeHash.trim();
|
|
19108
19137
|
} finally {
|
|
19109
|
-
await
|
|
19138
|
+
await fs11.rm(tempIndexPath, { force: true }).catch(() => {
|
|
19110
19139
|
});
|
|
19111
19140
|
}
|
|
19112
19141
|
}
|
|
19142
|
+
async function reconcileLargeBlobs(tempGit, head, maxBytes) {
|
|
19143
|
+
const intermediateTree = (await tempGit.raw(["write-tree"])).trim();
|
|
19144
|
+
const largePaths = await listLargeBlobPaths(tempGit, intermediateTree, maxBytes);
|
|
19145
|
+
if (largePaths.length === 0)
|
|
19146
|
+
return;
|
|
19147
|
+
const headEntries = head ? await readHeadBlobEntries(tempGit, head, largePaths) : /* @__PURE__ */ new Map();
|
|
19148
|
+
for (const filePath of largePaths) {
|
|
19149
|
+
const headEntry = headEntries.get(filePath);
|
|
19150
|
+
if (headEntry) {
|
|
19151
|
+
await tempGit.raw([
|
|
19152
|
+
"update-index",
|
|
19153
|
+
"--cacheinfo",
|
|
19154
|
+
`${headEntry.mode},${headEntry.hash},${filePath}`
|
|
19155
|
+
]);
|
|
19156
|
+
} else {
|
|
19157
|
+
await tempGit.raw(["update-index", "--force-remove", filePath]).catch(() => {
|
|
19158
|
+
});
|
|
19159
|
+
}
|
|
19160
|
+
}
|
|
19161
|
+
}
|
|
19162
|
+
async function listLargeBlobPaths(tempGit, tree, maxBytes) {
|
|
19163
|
+
const output = await tempGit.raw(["ls-tree", "-r", "-l", tree]);
|
|
19164
|
+
const result = [];
|
|
19165
|
+
for (const line of output.split("\n")) {
|
|
19166
|
+
if (!line)
|
|
19167
|
+
continue;
|
|
19168
|
+
const tabIndex = line.indexOf(" ");
|
|
19169
|
+
if (tabIndex < 0)
|
|
19170
|
+
continue;
|
|
19171
|
+
const meta = line.slice(0, tabIndex);
|
|
19172
|
+
const filePath = line.slice(tabIndex + 1);
|
|
19173
|
+
const parts2 = meta.split(/\s+/);
|
|
19174
|
+
if (parts2.length < 4)
|
|
19175
|
+
continue;
|
|
19176
|
+
const [, type, , sizeStr] = parts2;
|
|
19177
|
+
if (type !== "blob")
|
|
19178
|
+
continue;
|
|
19179
|
+
if (sizeStr === "-")
|
|
19180
|
+
continue;
|
|
19181
|
+
const size = Number.parseInt(sizeStr, 10);
|
|
19182
|
+
if (Number.isFinite(size) && size > maxBytes) {
|
|
19183
|
+
result.push(filePath);
|
|
19184
|
+
}
|
|
19185
|
+
}
|
|
19186
|
+
return result;
|
|
19187
|
+
}
|
|
19188
|
+
async function readHeadBlobEntries(tempGit, head, paths) {
|
|
19189
|
+
const result = /* @__PURE__ */ new Map();
|
|
19190
|
+
const CHUNK_SIZE = 100;
|
|
19191
|
+
for (let i2 = 0; i2 < paths.length; i2 += CHUNK_SIZE) {
|
|
19192
|
+
const chunk = paths.slice(i2, i2 + CHUNK_SIZE);
|
|
19193
|
+
const output = await tempGit.raw(["ls-tree", "-r", head, "--", ...chunk]).catch(() => "");
|
|
19194
|
+
for (const line of output.split("\n")) {
|
|
19195
|
+
if (!line)
|
|
19196
|
+
continue;
|
|
19197
|
+
const tabIndex = line.indexOf(" ");
|
|
19198
|
+
if (tabIndex < 0)
|
|
19199
|
+
continue;
|
|
19200
|
+
const meta = line.slice(0, tabIndex);
|
|
19201
|
+
const filePath = line.slice(tabIndex + 1);
|
|
19202
|
+
const parts2 = meta.split(/\s+/);
|
|
19203
|
+
if (parts2.length < 3)
|
|
19204
|
+
continue;
|
|
19205
|
+
const [mode, type, hash] = parts2;
|
|
19206
|
+
if (type !== "blob")
|
|
19207
|
+
continue;
|
|
19208
|
+
result.set(filePath, { mode, hash });
|
|
19209
|
+
}
|
|
19210
|
+
}
|
|
19211
|
+
return result;
|
|
19212
|
+
}
|
|
19113
19213
|
async function createMetaTree(git, baseDir, indexTree, worktreeTree) {
|
|
19114
19214
|
const { tempGit, tempIndexPath } = await createTempIndexGit(git, baseDir, "checkpoint-meta");
|
|
19115
19215
|
try {
|
|
@@ -19133,7 +19233,7 @@ async function createMetaTree(git, baseDir, indexTree, worktreeTree) {
|
|
|
19133
19233
|
const metaTree = await tempGit.raw(["write-tree"]);
|
|
19134
19234
|
return metaTree.trim();
|
|
19135
19235
|
} finally {
|
|
19136
|
-
await
|
|
19236
|
+
await fs11.rm(tempIndexPath, { force: true }).catch(() => {
|
|
19137
19237
|
});
|
|
19138
19238
|
}
|
|
19139
19239
|
}
|
|
@@ -19150,12 +19250,12 @@ function formatCheckpointMessage(meta) {
|
|
|
19150
19250
|
async function getGitCommonDir(git, baseDir) {
|
|
19151
19251
|
const raw = await git.raw(["rev-parse", "--git-common-dir"]);
|
|
19152
19252
|
const dir = raw.trim() || ".git";
|
|
19153
|
-
return
|
|
19253
|
+
return path13.isAbsolute(dir) ? dir : path13.resolve(baseDir, dir);
|
|
19154
19254
|
}
|
|
19155
19255
|
async function createTempIndexGit(git, baseDir, label) {
|
|
19156
|
-
const tmpDir =
|
|
19157
|
-
await
|
|
19158
|
-
const tempIndexPath =
|
|
19256
|
+
const tmpDir = path13.join(await getGitCommonDir(git, baseDir), "posthog-code-tmp");
|
|
19257
|
+
await fs11.mkdir(tmpDir, { recursive: true });
|
|
19258
|
+
const tempIndexPath = path13.join(tmpDir, `${label}-${Date.now()}-${(0, import_node_crypto2.randomUUID)()}`);
|
|
19159
19259
|
const tempGit = createGitClient(baseDir).env({
|
|
19160
19260
|
...process.env,
|
|
19161
19261
|
GIT_INDEX_FILE: tempIndexPath
|
|
@@ -19182,6 +19282,7 @@ async function deleteCheckpoint(git, checkpointId) {
|
|
|
19182
19282
|
// ../git/dist/handoff.js
|
|
19183
19283
|
var HANDOFF_HEAD_REF_PREFIX = "refs/posthog-code-handoff/head/";
|
|
19184
19284
|
var CHECKPOINT_REF_PREFIX2 = "refs/posthog-code-checkpoint/";
|
|
19285
|
+
var MAX_HANDOFF_FILE_BYTES = 1024 * 1024;
|
|
19185
19286
|
var GitHandoffTracker = class {
|
|
19186
19287
|
repositoryPath;
|
|
19187
19288
|
logger;
|
|
@@ -19189,7 +19290,7 @@ var GitHandoffTracker = class {
|
|
|
19189
19290
|
this.repositoryPath = config.repositoryPath;
|
|
19190
19291
|
this.logger = config.logger;
|
|
19191
19292
|
}
|
|
19192
|
-
async captureForHandoff(
|
|
19293
|
+
async captureForHandoff(localGitState) {
|
|
19193
19294
|
const captureSaga = new CaptureCheckpointSaga(this.logger);
|
|
19194
19295
|
const result = await captureSaga.run({ baseDir: this.repositoryPath });
|
|
19195
19296
|
if (!result.success) {
|
|
@@ -19199,17 +19300,20 @@ var GitHandoffTracker = class {
|
|
|
19199
19300
|
const git = createGitClient(this.repositoryPath);
|
|
19200
19301
|
const tempDir = await this.createTempDir(checkpoint.checkpointId);
|
|
19201
19302
|
const checkpointRef = `${CHECKPOINT_REF_PREFIX2}${checkpoint.checkpointId}`;
|
|
19202
|
-
const packRefs = [
|
|
19203
|
-
checkpoint.head,
|
|
19204
|
-
checkpoint.indexTree,
|
|
19205
|
-
checkpoint.worktreeTree
|
|
19206
|
-
].filter((ref) => !!ref);
|
|
19207
|
-
const headRef = checkpoint.head ? `${HANDOFF_HEAD_REF_PREFIX}${checkpoint.checkpointId}` : void 0;
|
|
19208
|
-
const packPrefix = import_node_path5.default.join(tempDir, checkpoint.checkpointId);
|
|
19209
19303
|
try {
|
|
19304
|
+
const reconciledIndex = await this.reconcileHandoffIndex(git, checkpoint.head, checkpoint.indexTree, tempDir, checkpoint.checkpointId);
|
|
19305
|
+
const packBaseline = localGitState?.upstreamHead ?? null;
|
|
19306
|
+
const packRefs = [
|
|
19307
|
+
checkpoint.head,
|
|
19308
|
+
reconciledIndex.indexTree,
|
|
19309
|
+
checkpoint.worktreeTree,
|
|
19310
|
+
packBaseline ? `^${packBaseline}` : null
|
|
19311
|
+
].filter((ref) => !!ref);
|
|
19312
|
+
const headRef = checkpoint.head ? `${HANDOFF_HEAD_REF_PREFIX}${checkpoint.checkpointId}` : void 0;
|
|
19313
|
+
const packPrefix = import_node_path5.default.join(tempDir, checkpoint.checkpointId);
|
|
19210
19314
|
const [headPack, indexFile, tracking] = await Promise.all([
|
|
19211
19315
|
this.captureObjectPack(packPrefix, packRefs),
|
|
19212
|
-
this.
|
|
19316
|
+
this.statFileArtifact(reconciledIndex.indexFilePath),
|
|
19213
19317
|
getTrackingMetadata(git, checkpoint.branch)
|
|
19214
19318
|
]);
|
|
19215
19319
|
return {
|
|
@@ -19220,7 +19324,7 @@ var GitHandoffTracker = class {
|
|
|
19220
19324
|
headRef,
|
|
19221
19325
|
head: checkpoint.head,
|
|
19222
19326
|
branch: checkpoint.branch,
|
|
19223
|
-
indexTree:
|
|
19327
|
+
indexTree: reconciledIndex.indexTree,
|
|
19224
19328
|
worktreeTree: checkpoint.worktreeTree,
|
|
19225
19329
|
timestamp: checkpoint.timestamp,
|
|
19226
19330
|
upstreamRemote: tracking.upstreamRemote,
|
|
@@ -19240,6 +19344,7 @@ var GitHandoffTracker = class {
|
|
|
19240
19344
|
const { checkpoint, headPackPath, indexPath, localGitState, onDivergedBranch } = input;
|
|
19241
19345
|
const git = createGitClient(this.repositoryPath);
|
|
19242
19346
|
if (headPackPath) {
|
|
19347
|
+
await this.ensureBaselineForApply(git, checkpoint, localGitState);
|
|
19243
19348
|
await this.unpackPackFile(headPackPath);
|
|
19244
19349
|
}
|
|
19245
19350
|
if (checkpoint.branch && checkpoint.head) {
|
|
@@ -19278,14 +19383,89 @@ var GitHandoffTracker = class {
|
|
|
19278
19383
|
});
|
|
19279
19384
|
return { path: packPath, rawBytes };
|
|
19280
19385
|
}
|
|
19281
|
-
async
|
|
19282
|
-
const
|
|
19283
|
-
const
|
|
19284
|
-
await (0, import_promises2.copyFile)(
|
|
19285
|
-
|
|
19286
|
-
|
|
19287
|
-
|
|
19288
|
-
}
|
|
19386
|
+
async reconcileHandoffIndex(git, head, indexTree, tempDir, checkpointId) {
|
|
19387
|
+
const realIndexPath = await this.getGitPath(git, "index");
|
|
19388
|
+
const tempIndexPath = import_node_path5.default.join(tempDir, `${checkpointId}.index`);
|
|
19389
|
+
await (0, import_promises2.copyFile)(realIndexPath, tempIndexPath);
|
|
19390
|
+
const largePaths = await this.listLargeBlobsInTree(indexTree, MAX_HANDOFF_FILE_BYTES);
|
|
19391
|
+
if (largePaths.length === 0) {
|
|
19392
|
+
return { indexTree, indexFilePath: tempIndexPath };
|
|
19393
|
+
}
|
|
19394
|
+
const headBlobs = head ? await this.readHeadBlobsForPaths(head, largePaths) : /* @__PURE__ */ new Map();
|
|
19395
|
+
const env = { ...process.env, GIT_INDEX_FILE: tempIndexPath };
|
|
19396
|
+
for (const filePath of largePaths) {
|
|
19397
|
+
const headBlob = headBlobs.get(filePath);
|
|
19398
|
+
if (headBlob) {
|
|
19399
|
+
await this.runGitWithEnv(env, [
|
|
19400
|
+
"update-index",
|
|
19401
|
+
"--cacheinfo",
|
|
19402
|
+
`${headBlob.mode},${headBlob.hash},${filePath}`
|
|
19403
|
+
]);
|
|
19404
|
+
} else {
|
|
19405
|
+
await this.runGitWithEnv(env, [
|
|
19406
|
+
"update-index",
|
|
19407
|
+
"--force-remove",
|
|
19408
|
+
filePath
|
|
19409
|
+
]).catch(() => {
|
|
19410
|
+
});
|
|
19411
|
+
}
|
|
19412
|
+
}
|
|
19413
|
+
const reconciledTree = (await this.runGitWithEnv(env, ["write-tree"])).trim();
|
|
19414
|
+
return { indexTree: reconciledTree, indexFilePath: tempIndexPath };
|
|
19415
|
+
}
|
|
19416
|
+
async listLargeBlobsInTree(tree, maxBytes) {
|
|
19417
|
+
const { stdout } = await this.runGitProcess(["ls-tree", "-r", "-l", tree], "");
|
|
19418
|
+
const result = [];
|
|
19419
|
+
for (const line of stdout.split("\n")) {
|
|
19420
|
+
if (!line)
|
|
19421
|
+
continue;
|
|
19422
|
+
const tabIndex = line.indexOf(" ");
|
|
19423
|
+
if (tabIndex < 0)
|
|
19424
|
+
continue;
|
|
19425
|
+
const meta = line.slice(0, tabIndex);
|
|
19426
|
+
const filePath = line.slice(tabIndex + 1);
|
|
19427
|
+
const parts2 = meta.split(/\s+/);
|
|
19428
|
+
if (parts2.length < 4)
|
|
19429
|
+
continue;
|
|
19430
|
+
const [, type, , sizeStr] = parts2;
|
|
19431
|
+
if (type !== "blob")
|
|
19432
|
+
continue;
|
|
19433
|
+
if (sizeStr === "-")
|
|
19434
|
+
continue;
|
|
19435
|
+
const size = Number.parseInt(sizeStr, 10);
|
|
19436
|
+
if (Number.isFinite(size) && size > maxBytes) {
|
|
19437
|
+
result.push(filePath);
|
|
19438
|
+
}
|
|
19439
|
+
}
|
|
19440
|
+
return result;
|
|
19441
|
+
}
|
|
19442
|
+
async readHeadBlobsForPaths(head, paths) {
|
|
19443
|
+
const result = /* @__PURE__ */ new Map();
|
|
19444
|
+
const CHUNK_SIZE = 100;
|
|
19445
|
+
for (let i2 = 0; i2 < paths.length; i2 += CHUNK_SIZE) {
|
|
19446
|
+
const chunk = paths.slice(i2, i2 + CHUNK_SIZE);
|
|
19447
|
+
const { stdout } = await this.runGitProcess(["ls-tree", "-r", head, "--", ...chunk], "").catch(() => ({ stdout: "", stderr: "" }));
|
|
19448
|
+
for (const line of stdout.split("\n")) {
|
|
19449
|
+
if (!line)
|
|
19450
|
+
continue;
|
|
19451
|
+
const tabIndex = line.indexOf(" ");
|
|
19452
|
+
if (tabIndex < 0)
|
|
19453
|
+
continue;
|
|
19454
|
+
const meta = line.slice(0, tabIndex);
|
|
19455
|
+
const filePath = line.slice(tabIndex + 1);
|
|
19456
|
+
const parts2 = meta.split(/\s+/);
|
|
19457
|
+
if (parts2.length < 3)
|
|
19458
|
+
continue;
|
|
19459
|
+
const [mode, type, hash] = parts2;
|
|
19460
|
+
if (type !== "blob")
|
|
19461
|
+
continue;
|
|
19462
|
+
result.set(filePath, { mode, hash });
|
|
19463
|
+
}
|
|
19464
|
+
}
|
|
19465
|
+
return result;
|
|
19466
|
+
}
|
|
19467
|
+
async statFileArtifact(filePath) {
|
|
19468
|
+
return { path: filePath, rawBytes: await this.getFileSize(filePath) };
|
|
19289
19469
|
}
|
|
19290
19470
|
async restoreIndexFile(git, indexPath) {
|
|
19291
19471
|
const gitIndexPath = await this.getGitPath(git, "index");
|
|
@@ -19313,6 +19493,20 @@ var GitHandoffTracker = class {
|
|
|
19313
19493
|
shouldRestoreTracking(branchStatus2, localGitState, tracking) {
|
|
19314
19494
|
return branchStatus2.kind === "missing" || !hasTrackingConfig(localGitState) && (tracking.upstreamRemote !== null || tracking.upstreamMergeRef !== null);
|
|
19315
19495
|
}
|
|
19496
|
+
async ensureBaselineForApply(git, checkpoint, localGitState) {
|
|
19497
|
+
const tracking = this.getPreferredTracking(localGitState, checkpoint);
|
|
19498
|
+
if (!tracking.upstreamRemote || !tracking.upstreamMergeRef)
|
|
19499
|
+
return;
|
|
19500
|
+
await this.ensureRemoteForTracking(git, tracking).catch(() => {
|
|
19501
|
+
});
|
|
19502
|
+
await git.raw(["fetch", tracking.upstreamRemote, tracking.upstreamMergeRef]).catch((err2) => {
|
|
19503
|
+
this.logger?.error("Handoff baseline fetch failed; if the pack excludes commits the receiver does not already have, the subsequent unpack/read-tree will fail with an object-missing error", {
|
|
19504
|
+
err: String(err2),
|
|
19505
|
+
remote: tracking.upstreamRemote,
|
|
19506
|
+
ref: tracking.upstreamMergeRef
|
|
19507
|
+
});
|
|
19508
|
+
});
|
|
19509
|
+
}
|
|
19316
19510
|
async ensureRemoteForTracking(git, tracking) {
|
|
19317
19511
|
if (!tracking.upstreamRemote || !tracking.remoteUrl)
|
|
19318
19512
|
return;
|
|
@@ -19449,6 +19643,31 @@ var GitHandoffTracker = class {
|
|
|
19449
19643
|
});
|
|
19450
19644
|
});
|
|
19451
19645
|
}
|
|
19646
|
+
async runGitWithEnv(env, args2) {
|
|
19647
|
+
return new Promise((resolve7, reject) => {
|
|
19648
|
+
const child = (0, import_node_child_process4.spawn)("git", args2, {
|
|
19649
|
+
cwd: this.repositoryPath,
|
|
19650
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19651
|
+
env
|
|
19652
|
+
});
|
|
19653
|
+
let stdout = "";
|
|
19654
|
+
let stderr = "";
|
|
19655
|
+
child.stdout.on("data", (chunk) => {
|
|
19656
|
+
stdout += chunk.toString();
|
|
19657
|
+
});
|
|
19658
|
+
child.stderr.on("data", (chunk) => {
|
|
19659
|
+
stderr += chunk.toString();
|
|
19660
|
+
});
|
|
19661
|
+
child.on("error", reject);
|
|
19662
|
+
child.on("close", (code) => {
|
|
19663
|
+
if (code === 0) {
|
|
19664
|
+
resolve7(stdout);
|
|
19665
|
+
return;
|
|
19666
|
+
}
|
|
19667
|
+
reject(new Error(stderr || `git ${args2.join(" ")} failed with code ${code}`));
|
|
19668
|
+
});
|
|
19669
|
+
});
|
|
19670
|
+
}
|
|
19452
19671
|
runGitProcess(args2, input) {
|
|
19453
19672
|
return new Promise((resolve7, reject) => {
|
|
19454
19673
|
const child = (0, import_node_child_process4.spawn)("git", args2, {
|
|
@@ -19471,6 +19690,8 @@ var GitHandoffTracker = class {
|
|
|
19471
19690
|
}
|
|
19472
19691
|
reject(new Error(stderr || `git ${args2.join(" ")} failed with code ${code}`));
|
|
19473
19692
|
});
|
|
19693
|
+
child.stdin.on("error", () => {
|
|
19694
|
+
});
|
|
19474
19695
|
child.stdin.end(input);
|
|
19475
19696
|
});
|
|
19476
19697
|
}
|
|
@@ -19961,9 +20182,9 @@ var PostHogAPIClient = class {
|
|
|
19961
20182
|
|
|
19962
20183
|
// src/adapters/claude/session/jsonl-hydration.ts
|
|
19963
20184
|
var import_node_crypto3 = require("crypto");
|
|
19964
|
-
var
|
|
19965
|
-
var
|
|
19966
|
-
var
|
|
20185
|
+
var fs12 = __toESM(require("fs/promises"), 1);
|
|
20186
|
+
var os7 = __toESM(require("os"), 1);
|
|
20187
|
+
var path15 = __toESM(require("path"), 1);
|
|
19967
20188
|
var CHARS_PER_TOKEN = 4;
|
|
19968
20189
|
var DEFAULT_MAX_TOKENS = 15e4;
|
|
19969
20190
|
function estimateTurnTokens(turn) {
|
|
@@ -20629,7 +20850,7 @@ async function getAgentshVersion() {
|
|
|
20629
20850
|
}
|
|
20630
20851
|
async function resolveAgentshRuntimeInfo({
|
|
20631
20852
|
sessionIdPath = AGENTSH_SESSION_ID_FILE,
|
|
20632
|
-
readSessionId = async (
|
|
20853
|
+
readSessionId = async (path17) => (0, import_promises5.readFile)(path17, "utf8"),
|
|
20633
20854
|
getVersion = getAgentshVersion
|
|
20634
20855
|
} = {}) {
|
|
20635
20856
|
let sessionId;
|
|
@@ -20837,6 +21058,7 @@ var agentErrorClassificationSchema = import_zod3.z.enum([
|
|
|
20837
21058
|
var errorWithClassificationSchema = import_zod3.z.object({
|
|
20838
21059
|
data: import_zod3.z.object({ classification: agentErrorClassificationSchema })
|
|
20839
21060
|
});
|
|
21061
|
+
var SSE_KEEPALIVE_INTERVAL_MS = 25e3;
|
|
20840
21062
|
var NdJsonTap = class {
|
|
20841
21063
|
constructor(onMessage) {
|
|
20842
21064
|
this.onMessage = onMessage;
|
|
@@ -21015,41 +21237,67 @@ var AgentServer = class {
|
|
|
21015
21237
|
401
|
|
21016
21238
|
);
|
|
21017
21239
|
}
|
|
21240
|
+
let keepaliveInterval = null;
|
|
21241
|
+
const clearKeepalive = () => {
|
|
21242
|
+
if (keepaliveInterval) {
|
|
21243
|
+
clearInterval(keepaliveInterval);
|
|
21244
|
+
keepaliveInterval = null;
|
|
21245
|
+
}
|
|
21246
|
+
};
|
|
21018
21247
|
const stream = new ReadableStream({
|
|
21019
21248
|
start: async (controller) => {
|
|
21020
|
-
|
|
21249
|
+
let sseController = null;
|
|
21250
|
+
const encoder = new TextEncoder();
|
|
21251
|
+
const detachCurrentSseController = () => {
|
|
21252
|
+
if (sseController) {
|
|
21253
|
+
this.detachSseController(sseController);
|
|
21254
|
+
}
|
|
21255
|
+
};
|
|
21256
|
+
const enqueueSseFrame = (frame) => {
|
|
21257
|
+
try {
|
|
21258
|
+
controller.enqueue(encoder.encode(frame));
|
|
21259
|
+
} catch {
|
|
21260
|
+
clearKeepalive();
|
|
21261
|
+
detachCurrentSseController();
|
|
21262
|
+
}
|
|
21263
|
+
};
|
|
21264
|
+
sseController = {
|
|
21021
21265
|
send: (data) => {
|
|
21022
|
-
|
|
21023
|
-
controller.enqueue(
|
|
21024
|
-
new TextEncoder().encode(`data: ${JSON.stringify(data)}
|
|
21266
|
+
enqueueSseFrame(`data: ${JSON.stringify(data)}
|
|
21025
21267
|
|
|
21026
|
-
`)
|
|
21027
|
-
);
|
|
21028
|
-
} catch {
|
|
21029
|
-
this.detachSseController(sseController);
|
|
21030
|
-
}
|
|
21268
|
+
`);
|
|
21031
21269
|
},
|
|
21032
21270
|
close: () => {
|
|
21033
21271
|
try {
|
|
21272
|
+
clearKeepalive();
|
|
21034
21273
|
controller.close();
|
|
21035
21274
|
} catch {
|
|
21036
|
-
|
|
21275
|
+
detachCurrentSseController();
|
|
21037
21276
|
}
|
|
21038
21277
|
}
|
|
21039
21278
|
};
|
|
21040
|
-
|
|
21041
|
-
|
|
21042
|
-
}
|
|
21043
|
-
|
|
21044
|
-
this.session.
|
|
21045
|
-
|
|
21279
|
+
keepaliveInterval = setInterval(() => {
|
|
21280
|
+
enqueueSseFrame(": keepalive\n\n");
|
|
21281
|
+
}, SSE_KEEPALIVE_INTERVAL_MS);
|
|
21282
|
+
try {
|
|
21283
|
+
if (!this.session || this.session.payload.run_id !== payload.run_id) {
|
|
21284
|
+
await this.initializeSession(payload, sseController);
|
|
21285
|
+
} else {
|
|
21286
|
+
this.session.sseController = sseController;
|
|
21287
|
+
this.session.hasDesktopConnected = true;
|
|
21288
|
+
this.replayPendingEvents();
|
|
21289
|
+
}
|
|
21290
|
+
this.sendSseEvent(sseController, {
|
|
21291
|
+
type: "connected",
|
|
21292
|
+
run_id: payload.run_id
|
|
21293
|
+
});
|
|
21294
|
+
} catch (error) {
|
|
21295
|
+
clearKeepalive();
|
|
21296
|
+
throw error;
|
|
21046
21297
|
}
|
|
21047
|
-
this.sendSseEvent(sseController, {
|
|
21048
|
-
type: "connected",
|
|
21049
|
-
run_id: payload.run_id
|
|
21050
|
-
});
|
|
21051
21298
|
},
|
|
21052
21299
|
cancel: () => {
|
|
21300
|
+
clearKeepalive();
|
|
21053
21301
|
this.logger.debug("SSE connection closed");
|
|
21054
21302
|
if (this.session?.sseController) {
|
|
21055
21303
|
this.session.sseController = null;
|