@posthog/agent 2.3.556 → 2.3.619
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 +64 -30
- package/dist/agent.js.map +1 -1
- package/dist/handoff-checkpoint.js +142 -117
- 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 +125 -69
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +136 -81
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/conversion/sdk-to-acp.ts +1 -26
- package/src/adapters/codex/codex-agent.test.ts +83 -0
- package/src/adapters/codex/codex-agent.ts +16 -0
- package/src/adapters/error-classification.ts +30 -0
- package/src/server/agent-server.test.ts +17 -0
- package/src/server/agent-server.ts +28 -9
- package/src/server/question-relay.test.ts +67 -5
|
@@ -809,10 +809,10 @@ var require_src2 = __commonJS({
|
|
|
809
809
|
var fs_1 = __require("fs");
|
|
810
810
|
var debug_1 = __importDefault(require_src());
|
|
811
811
|
var log = debug_1.default("@kwsites/file-exists");
|
|
812
|
-
function check(
|
|
813
|
-
log(`checking %s`,
|
|
812
|
+
function check(path5, isFile, isDirectory) {
|
|
813
|
+
log(`checking %s`, path5);
|
|
814
814
|
try {
|
|
815
|
-
const stat3 = fs_1.statSync(
|
|
815
|
+
const stat3 = fs_1.statSync(path5);
|
|
816
816
|
if (stat3.isFile() && isFile) {
|
|
817
817
|
log(`[OK] path represents a file`);
|
|
818
818
|
return true;
|
|
@@ -832,8 +832,8 @@ var require_src2 = __commonJS({
|
|
|
832
832
|
throw e;
|
|
833
833
|
}
|
|
834
834
|
}
|
|
835
|
-
function exists2(
|
|
836
|
-
return check(
|
|
835
|
+
function exists2(path5, type = exports.READABLE) {
|
|
836
|
+
return check(path5, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
|
|
837
837
|
}
|
|
838
838
|
exports.exists = exists2;
|
|
839
839
|
exports.FILE = 1;
|
|
@@ -897,15 +897,15 @@ var require_dist2 = __commonJS({
|
|
|
897
897
|
});
|
|
898
898
|
|
|
899
899
|
// src/handoff-checkpoint.ts
|
|
900
|
-
import { mkdtemp as mkdtemp2, readFile as
|
|
900
|
+
import { mkdtemp as mkdtemp2, readFile as readFile3, rm as rm3, writeFile as writeFile2 } from "fs/promises";
|
|
901
901
|
import { tmpdir as tmpdir2 } from "os";
|
|
902
|
-
import { dirname, join as
|
|
902
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
903
903
|
|
|
904
904
|
// ../git/dist/handoff.js
|
|
905
|
-
import { spawn as
|
|
906
|
-
import { copyFile, mkdtemp, readFile, rm as rm2, stat as stat2 } from "fs/promises";
|
|
905
|
+
import { spawn as spawn3 } from "child_process";
|
|
906
|
+
import { copyFile, mkdtemp, readFile as readFile2, rm as rm2, stat as stat2 } from "fs/promises";
|
|
907
907
|
import { tmpdir } from "os";
|
|
908
|
-
import
|
|
908
|
+
import path4 from "path";
|
|
909
909
|
|
|
910
910
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
911
911
|
var import_file_exists = __toESM(require_dist(), 1);
|
|
@@ -944,8 +944,8 @@ function pathspec(...paths) {
|
|
|
944
944
|
cache.set(key, paths);
|
|
945
945
|
return key;
|
|
946
946
|
}
|
|
947
|
-
function isPathSpec(
|
|
948
|
-
return
|
|
947
|
+
function isPathSpec(path5) {
|
|
948
|
+
return path5 instanceof String && cache.has(path5);
|
|
949
949
|
}
|
|
950
950
|
function toPaths(pathSpec) {
|
|
951
951
|
return cache.get(pathSpec) || [];
|
|
@@ -1034,8 +1034,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
1034
1034
|
function forEachLineWithContent(input, callback) {
|
|
1035
1035
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
1036
1036
|
}
|
|
1037
|
-
function folderExists(
|
|
1038
|
-
return (0, import_file_exists.exists)(
|
|
1037
|
+
function folderExists(path5) {
|
|
1038
|
+
return (0, import_file_exists.exists)(path5, import_file_exists.FOLDER);
|
|
1039
1039
|
}
|
|
1040
1040
|
function append(target, item) {
|
|
1041
1041
|
if (Array.isArray(target)) {
|
|
@@ -1439,8 +1439,8 @@ function checkIsRepoRootTask() {
|
|
|
1439
1439
|
commands,
|
|
1440
1440
|
format: "utf-8",
|
|
1441
1441
|
onError,
|
|
1442
|
-
parser(
|
|
1443
|
-
return /^\.(git)?$/.test(
|
|
1442
|
+
parser(path5) {
|
|
1443
|
+
return /^\.(git)?$/.test(path5.trim());
|
|
1444
1444
|
}
|
|
1445
1445
|
};
|
|
1446
1446
|
}
|
|
@@ -1874,11 +1874,11 @@ function parseGrep(grep) {
|
|
|
1874
1874
|
const paths = /* @__PURE__ */ new Set();
|
|
1875
1875
|
const results = {};
|
|
1876
1876
|
forEachLineWithContent(grep, (input) => {
|
|
1877
|
-
const [
|
|
1878
|
-
paths.add(
|
|
1879
|
-
(results[
|
|
1877
|
+
const [path5, line, preview] = input.split(NULL);
|
|
1878
|
+
paths.add(path5);
|
|
1879
|
+
(results[path5] = results[path5] || []).push({
|
|
1880
1880
|
line: asNumber(line),
|
|
1881
|
-
path:
|
|
1881
|
+
path: path5,
|
|
1882
1882
|
preview
|
|
1883
1883
|
});
|
|
1884
1884
|
});
|
|
@@ -2643,14 +2643,14 @@ var init_hash_object = __esm({
|
|
|
2643
2643
|
init_task();
|
|
2644
2644
|
}
|
|
2645
2645
|
});
|
|
2646
|
-
function parseInit(bare,
|
|
2646
|
+
function parseInit(bare, path5, text) {
|
|
2647
2647
|
const response = String(text).trim();
|
|
2648
2648
|
let result;
|
|
2649
2649
|
if (result = initResponseRegex.exec(response)) {
|
|
2650
|
-
return new InitSummary(bare,
|
|
2650
|
+
return new InitSummary(bare, path5, false, result[1]);
|
|
2651
2651
|
}
|
|
2652
2652
|
if (result = reInitResponseRegex.exec(response)) {
|
|
2653
|
-
return new InitSummary(bare,
|
|
2653
|
+
return new InitSummary(bare, path5, true, result[1]);
|
|
2654
2654
|
}
|
|
2655
2655
|
let gitDir = "";
|
|
2656
2656
|
const tokens = response.split(" ");
|
|
@@ -2661,7 +2661,7 @@ function parseInit(bare, path4, text) {
|
|
|
2661
2661
|
break;
|
|
2662
2662
|
}
|
|
2663
2663
|
}
|
|
2664
|
-
return new InitSummary(bare,
|
|
2664
|
+
return new InitSummary(bare, path5, /^re/i.test(response), gitDir);
|
|
2665
2665
|
}
|
|
2666
2666
|
var InitSummary;
|
|
2667
2667
|
var initResponseRegex;
|
|
@@ -2670,9 +2670,9 @@ var init_InitSummary = __esm({
|
|
|
2670
2670
|
"src/lib/responses/InitSummary.ts"() {
|
|
2671
2671
|
"use strict";
|
|
2672
2672
|
InitSummary = class {
|
|
2673
|
-
constructor(bare,
|
|
2673
|
+
constructor(bare, path5, existing, gitDir) {
|
|
2674
2674
|
this.bare = bare;
|
|
2675
|
-
this.path =
|
|
2675
|
+
this.path = path5;
|
|
2676
2676
|
this.existing = existing;
|
|
2677
2677
|
this.gitDir = gitDir;
|
|
2678
2678
|
}
|
|
@@ -2684,7 +2684,7 @@ var init_InitSummary = __esm({
|
|
|
2684
2684
|
function hasBareCommand(command) {
|
|
2685
2685
|
return command.includes(bareCommand);
|
|
2686
2686
|
}
|
|
2687
|
-
function initTask(bare = false,
|
|
2687
|
+
function initTask(bare = false, path5, customArgs) {
|
|
2688
2688
|
const commands = ["init", ...customArgs];
|
|
2689
2689
|
if (bare && !hasBareCommand(commands)) {
|
|
2690
2690
|
commands.splice(1, 0, bareCommand);
|
|
@@ -2693,7 +2693,7 @@ function initTask(bare = false, path4, customArgs) {
|
|
|
2693
2693
|
commands,
|
|
2694
2694
|
format: "utf-8",
|
|
2695
2695
|
parser(text) {
|
|
2696
|
-
return parseInit(commands.includes("--bare"),
|
|
2696
|
+
return parseInit(commands.includes("--bare"), path5, text);
|
|
2697
2697
|
}
|
|
2698
2698
|
};
|
|
2699
2699
|
}
|
|
@@ -3509,12 +3509,12 @@ var init_FileStatusSummary = __esm({
|
|
|
3509
3509
|
"use strict";
|
|
3510
3510
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
3511
3511
|
FileStatusSummary = class {
|
|
3512
|
-
constructor(
|
|
3513
|
-
this.path =
|
|
3512
|
+
constructor(path5, index, working_dir) {
|
|
3513
|
+
this.path = path5;
|
|
3514
3514
|
this.index = index;
|
|
3515
3515
|
this.working_dir = working_dir;
|
|
3516
3516
|
if (index === "R" || working_dir === "R") {
|
|
3517
|
-
const detail = fromPathRegex.exec(
|
|
3517
|
+
const detail = fromPathRegex.exec(path5) || [null, path5, path5];
|
|
3518
3518
|
this.from = detail[2] || "";
|
|
3519
3519
|
this.path = detail[1] || "";
|
|
3520
3520
|
}
|
|
@@ -3545,14 +3545,14 @@ function splitLine(result, lineStr) {
|
|
|
3545
3545
|
default:
|
|
3546
3546
|
return;
|
|
3547
3547
|
}
|
|
3548
|
-
function data(index, workingDir,
|
|
3548
|
+
function data(index, workingDir, path5) {
|
|
3549
3549
|
const raw = `${index}${workingDir}`;
|
|
3550
3550
|
const handler = parsers6.get(raw);
|
|
3551
3551
|
if (handler) {
|
|
3552
|
-
handler(result,
|
|
3552
|
+
handler(result, path5);
|
|
3553
3553
|
}
|
|
3554
3554
|
if (raw !== "##" && raw !== "!!") {
|
|
3555
|
-
result.files.push(new FileStatusSummary(
|
|
3555
|
+
result.files.push(new FileStatusSummary(path5, index, workingDir));
|
|
3556
3556
|
}
|
|
3557
3557
|
}
|
|
3558
3558
|
}
|
|
@@ -3865,9 +3865,9 @@ var init_simple_git_api = __esm({
|
|
|
3865
3865
|
next
|
|
3866
3866
|
);
|
|
3867
3867
|
}
|
|
3868
|
-
hashObject(
|
|
3868
|
+
hashObject(path5, write) {
|
|
3869
3869
|
return this._runTask(
|
|
3870
|
-
hashObjectTask(
|
|
3870
|
+
hashObjectTask(path5, write === true),
|
|
3871
3871
|
trailingFunctionArgument(arguments)
|
|
3872
3872
|
);
|
|
3873
3873
|
}
|
|
@@ -4220,8 +4220,8 @@ var init_branch = __esm({
|
|
|
4220
4220
|
}
|
|
4221
4221
|
});
|
|
4222
4222
|
function toPath(input) {
|
|
4223
|
-
const
|
|
4224
|
-
return
|
|
4223
|
+
const path5 = input.trim().replace(/^["']|["']$/g, "");
|
|
4224
|
+
return path5 && normalize(path5);
|
|
4225
4225
|
}
|
|
4226
4226
|
var parseCheckIgnore;
|
|
4227
4227
|
var init_CheckIgnore = __esm({
|
|
@@ -4535,8 +4535,8 @@ __export(sub_module_exports, {
|
|
|
4535
4535
|
subModuleTask: () => subModuleTask,
|
|
4536
4536
|
updateSubModuleTask: () => updateSubModuleTask
|
|
4537
4537
|
});
|
|
4538
|
-
function addSubModuleTask(repo,
|
|
4539
|
-
return subModuleTask(["add", repo,
|
|
4538
|
+
function addSubModuleTask(repo, path5) {
|
|
4539
|
+
return subModuleTask(["add", repo, path5]);
|
|
4540
4540
|
}
|
|
4541
4541
|
function initSubModuleTask(customArgs) {
|
|
4542
4542
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -4866,8 +4866,8 @@ var require_git = __commonJS2({
|
|
|
4866
4866
|
}
|
|
4867
4867
|
return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
|
|
4868
4868
|
};
|
|
4869
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
4870
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
4869
|
+
Git2.prototype.submoduleAdd = function(repo, path5, then) {
|
|
4870
|
+
return this._runTask(addSubModuleTask2(repo, path5), trailingFunctionArgument2(arguments));
|
|
4871
4871
|
};
|
|
4872
4872
|
Git2.prototype.submoduleUpdate = function(args, then) {
|
|
4873
4873
|
return this._runTask(
|
|
@@ -5455,21 +5455,28 @@ init_git_response_error();
|
|
|
5455
5455
|
var simpleGit = gitInstanceFactory;
|
|
5456
5456
|
|
|
5457
5457
|
// ../git/dist/client.js
|
|
5458
|
+
var PERFORMANCE_CONFIG = [
|
|
5459
|
+
"core.untrackedCache=true",
|
|
5460
|
+
"core.fsmonitor=true",
|
|
5461
|
+
"core.preloadIndex=true"
|
|
5462
|
+
];
|
|
5458
5463
|
function createGitClient(baseDir, options) {
|
|
5459
|
-
const { abortSignal: signal, ...rest } = options ?? {};
|
|
5464
|
+
const { abortSignal: signal, config: callerConfig, ...rest } = options ?? {};
|
|
5465
|
+
const config = callerConfig ? [...PERFORMANCE_CONFIG, ...callerConfig] : PERFORMANCE_CONFIG;
|
|
5460
5466
|
return simpleGit({
|
|
5461
5467
|
baseDir,
|
|
5462
5468
|
maxConcurrentProcesses: 6,
|
|
5463
5469
|
trimmed: true,
|
|
5464
5470
|
abort: signal,
|
|
5471
|
+
config,
|
|
5465
5472
|
...rest
|
|
5466
5473
|
});
|
|
5467
5474
|
}
|
|
5468
5475
|
|
|
5469
5476
|
// ../git/dist/sagas/checkpoint.js
|
|
5470
5477
|
import { randomUUID } from "crypto";
|
|
5471
|
-
import * as
|
|
5472
|
-
import * as
|
|
5478
|
+
import * as fs3 from "fs/promises";
|
|
5479
|
+
import * as path3 from "path";
|
|
5473
5480
|
|
|
5474
5481
|
// ../shared/dist/index.js
|
|
5475
5482
|
var consoleLogger = {
|
|
@@ -5647,10 +5654,10 @@ var AsyncReaderWriterLock = class {
|
|
|
5647
5654
|
this.readers++;
|
|
5648
5655
|
return;
|
|
5649
5656
|
}
|
|
5650
|
-
return new Promise((
|
|
5657
|
+
return new Promise((resolve3) => {
|
|
5651
5658
|
this.readQueue.push(() => {
|
|
5652
5659
|
this.readers++;
|
|
5653
|
-
|
|
5660
|
+
resolve3();
|
|
5654
5661
|
});
|
|
5655
5662
|
});
|
|
5656
5663
|
}
|
|
@@ -5664,11 +5671,11 @@ var AsyncReaderWriterLock = class {
|
|
|
5664
5671
|
return;
|
|
5665
5672
|
}
|
|
5666
5673
|
this.writerWaiting = true;
|
|
5667
|
-
return new Promise((
|
|
5674
|
+
return new Promise((resolve3) => {
|
|
5668
5675
|
this.writeQueue.push(() => {
|
|
5669
5676
|
this.writerWaiting = this.writeQueue.length > 0;
|
|
5670
5677
|
this.writer = true;
|
|
5671
|
-
|
|
5678
|
+
resolve3();
|
|
5672
5679
|
});
|
|
5673
5680
|
});
|
|
5674
5681
|
}
|
|
@@ -5740,14 +5747,18 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
5740
5747
|
}
|
|
5741
5748
|
async executeRead(repoPath, operation, options) {
|
|
5742
5749
|
const state = this.getRepoState(repoPath);
|
|
5750
|
+
const env = {
|
|
5751
|
+
...getCleanEnv(),
|
|
5752
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
5753
|
+
...options?.env
|
|
5754
|
+
};
|
|
5743
5755
|
if (options?.signal) {
|
|
5744
5756
|
const scopedGit = createGitClient(repoPath, {
|
|
5745
5757
|
abortSignal: options.signal
|
|
5746
5758
|
});
|
|
5747
|
-
return operation(scopedGit.env(
|
|
5759
|
+
return operation(scopedGit.env(env));
|
|
5748
5760
|
}
|
|
5749
|
-
|
|
5750
|
-
return operation(git);
|
|
5761
|
+
return operation(state.client.env(env));
|
|
5751
5762
|
}
|
|
5752
5763
|
async executeWrite(repoPath, operation, options) {
|
|
5753
5764
|
const state = this.getRepoState(repoPath);
|
|
@@ -5757,15 +5768,16 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
5757
5768
|
throw new Error(`Git repository is locked: ${repoPath}`);
|
|
5758
5769
|
}
|
|
5759
5770
|
}
|
|
5771
|
+
const env = { ...getCleanEnv(), ...options?.env };
|
|
5760
5772
|
await state.lock.acquireWrite();
|
|
5761
5773
|
try {
|
|
5762
5774
|
if (options?.signal) {
|
|
5763
5775
|
const scopedGit = createGitClient(repoPath, {
|
|
5764
5776
|
abortSignal: options.signal
|
|
5765
5777
|
});
|
|
5766
|
-
return await operation(scopedGit.env(
|
|
5778
|
+
return await operation(scopedGit.env(env));
|
|
5767
5779
|
}
|
|
5768
|
-
return await operation(state.client.env(
|
|
5780
|
+
return await operation(state.client.env(env));
|
|
5769
5781
|
} catch (error) {
|
|
5770
5782
|
if (options?.signal?.aborted) {
|
|
5771
5783
|
await removeLock(repoPath).catch(() => {
|
|
@@ -5806,10 +5818,58 @@ var GitSaga = class extends Saga {
|
|
|
5806
5818
|
return manager.executeWrite(input.baseDir, async (git) => {
|
|
5807
5819
|
this._git = git;
|
|
5808
5820
|
return this.executeGitOperations(input);
|
|
5809
|
-
}, { signal: input.signal });
|
|
5821
|
+
}, { signal: input.signal, env: input.env });
|
|
5810
5822
|
}
|
|
5811
5823
|
};
|
|
5812
5824
|
|
|
5825
|
+
// ../git/dist/queries.js
|
|
5826
|
+
import { createReadStream } from "fs";
|
|
5827
|
+
import * as fs2 from "fs/promises";
|
|
5828
|
+
import * as path2 from "path";
|
|
5829
|
+
|
|
5830
|
+
// ../git/dist/status-stream.js
|
|
5831
|
+
import { spawn as spawn2 } from "child_process";
|
|
5832
|
+
|
|
5833
|
+
// ../git/dist/queries.js
|
|
5834
|
+
async function inspectGitBusyState(git) {
|
|
5835
|
+
const toplevel = (await git.raw(["rev-parse", "--show-toplevel"])).trim();
|
|
5836
|
+
const resolveGitPath = async (gitPath) => {
|
|
5837
|
+
const relative = (await git.raw(["rev-parse", "--git-path", gitPath])).trim();
|
|
5838
|
+
return path2.isAbsolute(relative) ? relative : path2.resolve(toplevel, relative);
|
|
5839
|
+
};
|
|
5840
|
+
const pathExists = async (gitPath) => {
|
|
5841
|
+
const resolved = await resolveGitPath(gitPath);
|
|
5842
|
+
try {
|
|
5843
|
+
await fs2.access(resolved);
|
|
5844
|
+
return true;
|
|
5845
|
+
} catch {
|
|
5846
|
+
return false;
|
|
5847
|
+
}
|
|
5848
|
+
};
|
|
5849
|
+
const dirExists = async (gitPath) => {
|
|
5850
|
+
const resolved = await resolveGitPath(gitPath);
|
|
5851
|
+
try {
|
|
5852
|
+
const stat3 = await fs2.stat(resolved);
|
|
5853
|
+
return stat3.isDirectory();
|
|
5854
|
+
} catch {
|
|
5855
|
+
return false;
|
|
5856
|
+
}
|
|
5857
|
+
};
|
|
5858
|
+
if (await dirExists("rebase-merge") || await dirExists("rebase-apply")) {
|
|
5859
|
+
return { busy: true, operation: "rebase" };
|
|
5860
|
+
}
|
|
5861
|
+
if (await pathExists("MERGE_HEAD")) {
|
|
5862
|
+
return { busy: true, operation: "merge" };
|
|
5863
|
+
}
|
|
5864
|
+
if (await pathExists("CHERRY_PICK_HEAD")) {
|
|
5865
|
+
return { busy: true, operation: "cherry-pick" };
|
|
5866
|
+
}
|
|
5867
|
+
if (await pathExists("REVERT_HEAD")) {
|
|
5868
|
+
return { busy: true, operation: "revert" };
|
|
5869
|
+
}
|
|
5870
|
+
return { busy: false };
|
|
5871
|
+
}
|
|
5872
|
+
|
|
5813
5873
|
// ../git/dist/sagas/checkpoint.js
|
|
5814
5874
|
var CHECKPOINT_REF_PREFIX = "refs/posthog-code-checkpoint/";
|
|
5815
5875
|
var CHECKPOINT_VERSION = "v1";
|
|
@@ -5918,42 +5978,7 @@ async function hasUnmergedEntries(git) {
|
|
|
5918
5978
|
return output.trim().length > 0;
|
|
5919
5979
|
}
|
|
5920
5980
|
async function getGitBusyState(git) {
|
|
5921
|
-
|
|
5922
|
-
const resolveGitPath = async (gitPath) => {
|
|
5923
|
-
const relative = (await git.raw(["rev-parse", "--git-path", gitPath])).trim();
|
|
5924
|
-
return path2.isAbsolute(relative) ? relative : path2.resolve(toplevel, relative);
|
|
5925
|
-
};
|
|
5926
|
-
const pathExists = async (gitPath) => {
|
|
5927
|
-
const resolved = await resolveGitPath(gitPath);
|
|
5928
|
-
try {
|
|
5929
|
-
await fs2.access(resolved);
|
|
5930
|
-
return true;
|
|
5931
|
-
} catch {
|
|
5932
|
-
return false;
|
|
5933
|
-
}
|
|
5934
|
-
};
|
|
5935
|
-
const dirExists = async (gitPath) => {
|
|
5936
|
-
const resolved = await resolveGitPath(gitPath);
|
|
5937
|
-
try {
|
|
5938
|
-
const stat3 = await fs2.stat(resolved);
|
|
5939
|
-
return stat3.isDirectory();
|
|
5940
|
-
} catch {
|
|
5941
|
-
return false;
|
|
5942
|
-
}
|
|
5943
|
-
};
|
|
5944
|
-
if (await dirExists("rebase-merge") || await dirExists("rebase-apply")) {
|
|
5945
|
-
return { busy: true, operation: "rebase" };
|
|
5946
|
-
}
|
|
5947
|
-
if (await pathExists("MERGE_HEAD")) {
|
|
5948
|
-
return { busy: true, operation: "merge" };
|
|
5949
|
-
}
|
|
5950
|
-
if (await pathExists("CHERRY_PICK_HEAD")) {
|
|
5951
|
-
return { busy: true, operation: "cherry-pick" };
|
|
5952
|
-
}
|
|
5953
|
-
if (await pathExists("REVERT_HEAD")) {
|
|
5954
|
-
return { busy: true, operation: "revert" };
|
|
5955
|
-
}
|
|
5956
|
-
return { busy: false };
|
|
5981
|
+
return inspectGitBusyState(git);
|
|
5957
5982
|
}
|
|
5958
5983
|
var MAX_WORKTREE_FILE_BYTES = 1024 * 1024;
|
|
5959
5984
|
async function createWorktreeTree(git, baseDir, head) {
|
|
@@ -5969,7 +5994,7 @@ async function createWorktreeTree(git, baseDir, head) {
|
|
|
5969
5994
|
const treeHash = await tempGit.raw(["write-tree"]);
|
|
5970
5995
|
return treeHash.trim();
|
|
5971
5996
|
} finally {
|
|
5972
|
-
await
|
|
5997
|
+
await fs3.rm(tempIndexPath, { force: true }).catch(() => {
|
|
5973
5998
|
});
|
|
5974
5999
|
}
|
|
5975
6000
|
}
|
|
@@ -6067,7 +6092,7 @@ async function createMetaTree(git, baseDir, indexTree, worktreeTree) {
|
|
|
6067
6092
|
const metaTree = await tempGit.raw(["write-tree"]);
|
|
6068
6093
|
return metaTree.trim();
|
|
6069
6094
|
} finally {
|
|
6070
|
-
await
|
|
6095
|
+
await fs3.rm(tempIndexPath, { force: true }).catch(() => {
|
|
6071
6096
|
});
|
|
6072
6097
|
}
|
|
6073
6098
|
}
|
|
@@ -6084,12 +6109,12 @@ function formatCheckpointMessage(meta) {
|
|
|
6084
6109
|
async function getGitCommonDir(git, baseDir) {
|
|
6085
6110
|
const raw = await git.raw(["rev-parse", "--git-common-dir"]);
|
|
6086
6111
|
const dir = raw.trim() || ".git";
|
|
6087
|
-
return
|
|
6112
|
+
return path3.isAbsolute(dir) ? dir : path3.resolve(baseDir, dir);
|
|
6088
6113
|
}
|
|
6089
6114
|
async function createTempIndexGit(git, baseDir, label) {
|
|
6090
|
-
const tmpDir =
|
|
6091
|
-
await
|
|
6092
|
-
const tempIndexPath =
|
|
6115
|
+
const tmpDir = path3.join(await getGitCommonDir(git, baseDir), "posthog-code-tmp");
|
|
6116
|
+
await fs3.mkdir(tmpDir, { recursive: true });
|
|
6117
|
+
const tempIndexPath = path3.join(tmpDir, `${label}-${Date.now()}-${randomUUID()}`);
|
|
6093
6118
|
const tempGit = createGitClient(baseDir).env({
|
|
6094
6119
|
...process.env,
|
|
6095
6120
|
GIT_INDEX_FILE: tempIndexPath
|
|
@@ -6144,7 +6169,7 @@ var GitHandoffTracker = class {
|
|
|
6144
6169
|
packBaseline ? `^${packBaseline}` : null
|
|
6145
6170
|
].filter((ref) => !!ref);
|
|
6146
6171
|
const headRef = checkpoint.head ? `${HANDOFF_HEAD_REF_PREFIX}${checkpoint.checkpointId}` : void 0;
|
|
6147
|
-
const packPrefix =
|
|
6172
|
+
const packPrefix = path4.join(tempDir, checkpoint.checkpointId);
|
|
6148
6173
|
const [headPack, indexFile, tracking] = await Promise.all([
|
|
6149
6174
|
this.captureObjectPack(packPrefix, packRefs),
|
|
6150
6175
|
this.statFileArtifact(reconciledIndex.indexFilePath),
|
|
@@ -6219,7 +6244,7 @@ var GitHandoffTracker = class {
|
|
|
6219
6244
|
}
|
|
6220
6245
|
async reconcileHandoffIndex(git, head, indexTree, tempDir, checkpointId) {
|
|
6221
6246
|
const realIndexPath = await this.getGitPath(git, "index");
|
|
6222
|
-
const tempIndexPath =
|
|
6247
|
+
const tempIndexPath = path4.join(tempDir, `${checkpointId}.index`);
|
|
6223
6248
|
await copyFile(realIndexPath, tempIndexPath);
|
|
6224
6249
|
const largePaths = await this.listLargeBlobsInTree(indexTree, MAX_HANDOFF_FILE_BYTES);
|
|
6225
6250
|
if (largePaths.length === 0) {
|
|
@@ -6306,7 +6331,7 @@ var GitHandoffTracker = class {
|
|
|
6306
6331
|
await copyFile(indexPath, gitIndexPath);
|
|
6307
6332
|
}
|
|
6308
6333
|
async unpackPackFile(packPath) {
|
|
6309
|
-
const content = await
|
|
6334
|
+
const content = await readFile2(packPath);
|
|
6310
6335
|
await this.runGitWithBuffer(["unpack-objects", "-r"], content);
|
|
6311
6336
|
}
|
|
6312
6337
|
getPreferredTracking(localGitState, checkpoint) {
|
|
@@ -6441,7 +6466,7 @@ var GitHandoffTracker = class {
|
|
|
6441
6466
|
async getGitPath(git, gitPath) {
|
|
6442
6467
|
const raw = await git.raw(["rev-parse", "--git-path", gitPath]);
|
|
6443
6468
|
const resolved = raw.trim();
|
|
6444
|
-
return
|
|
6469
|
+
return path4.isAbsolute(resolved) ? resolved : path4.resolve(this.repositoryPath, resolved);
|
|
6445
6470
|
}
|
|
6446
6471
|
async getFileSize(filePath) {
|
|
6447
6472
|
return (await stat2(filePath)).size;
|
|
@@ -6454,8 +6479,8 @@ var GitHandoffTracker = class {
|
|
|
6454
6479
|
await this.runGitProcess(args, input);
|
|
6455
6480
|
}
|
|
6456
6481
|
async runGitProcessAllowingFailure(args) {
|
|
6457
|
-
return new Promise((
|
|
6458
|
-
const child =
|
|
6482
|
+
return new Promise((resolve3, reject) => {
|
|
6483
|
+
const child = spawn3("git", args, {
|
|
6459
6484
|
cwd: this.repositoryPath,
|
|
6460
6485
|
stdio: ["ignore", "ignore", "pipe"]
|
|
6461
6486
|
});
|
|
@@ -6473,13 +6498,13 @@ var GitHandoffTracker = class {
|
|
|
6473
6498
|
reject(new Error(stderr || `git ${args.join(" ")} failed with code ${code}`));
|
|
6474
6499
|
return;
|
|
6475
6500
|
}
|
|
6476
|
-
|
|
6501
|
+
resolve3(code);
|
|
6477
6502
|
});
|
|
6478
6503
|
});
|
|
6479
6504
|
}
|
|
6480
6505
|
async runGitWithEnv(env, args) {
|
|
6481
|
-
return new Promise((
|
|
6482
|
-
const child =
|
|
6506
|
+
return new Promise((resolve3, reject) => {
|
|
6507
|
+
const child = spawn3("git", args, {
|
|
6483
6508
|
cwd: this.repositoryPath,
|
|
6484
6509
|
stdio: ["ignore", "pipe", "pipe"],
|
|
6485
6510
|
env
|
|
@@ -6495,7 +6520,7 @@ var GitHandoffTracker = class {
|
|
|
6495
6520
|
child.on("error", reject);
|
|
6496
6521
|
child.on("close", (code) => {
|
|
6497
6522
|
if (code === 0) {
|
|
6498
|
-
|
|
6523
|
+
resolve3(stdout);
|
|
6499
6524
|
return;
|
|
6500
6525
|
}
|
|
6501
6526
|
reject(new Error(stderr || `git ${args.join(" ")} failed with code ${code}`));
|
|
@@ -6503,8 +6528,8 @@ var GitHandoffTracker = class {
|
|
|
6503
6528
|
});
|
|
6504
6529
|
}
|
|
6505
6530
|
runGitProcess(args, input) {
|
|
6506
|
-
return new Promise((
|
|
6507
|
-
const child =
|
|
6531
|
+
return new Promise((resolve3, reject) => {
|
|
6532
|
+
const child = spawn3("git", args, {
|
|
6508
6533
|
cwd: this.repositoryPath,
|
|
6509
6534
|
stdio: "pipe"
|
|
6510
6535
|
});
|
|
@@ -6519,7 +6544,7 @@ var GitHandoffTracker = class {
|
|
|
6519
6544
|
child.on("error", reject);
|
|
6520
6545
|
child.on("close", (code) => {
|
|
6521
6546
|
if (code === 0) {
|
|
6522
|
-
|
|
6547
|
+
resolve3({ stdout, stderr });
|
|
6523
6548
|
return;
|
|
6524
6549
|
}
|
|
6525
6550
|
reject(new Error(stderr || `git ${args.join(" ")} failed with code ${code}`));
|
|
@@ -6531,7 +6556,7 @@ var GitHandoffTracker = class {
|
|
|
6531
6556
|
}
|
|
6532
6557
|
};
|
|
6533
6558
|
function joinTempPrefix(checkpointId) {
|
|
6534
|
-
return
|
|
6559
|
+
return path4.join(tmpdir(), `posthog-code-handoff-${checkpointId}-`);
|
|
6535
6560
|
}
|
|
6536
6561
|
async function getCurrentBranchName(git) {
|
|
6537
6562
|
try {
|
|
@@ -6672,7 +6697,7 @@ var HandoffCheckpointTracker = class {
|
|
|
6672
6697
|
indexArtifactPath: uploads.index?.storagePath
|
|
6673
6698
|
};
|
|
6674
6699
|
} finally {
|
|
6675
|
-
const tempDir = capture.headPack?.path ?
|
|
6700
|
+
const tempDir = capture.headPack?.path ? dirname2(capture.headPack.path) : dirname2(capture.indexFile.path);
|
|
6676
6701
|
await this.removeIfPresent(capture.headPack?.path);
|
|
6677
6702
|
await this.removeIfPresent(capture.indexFile.path);
|
|
6678
6703
|
await rm3(tempDir, { recursive: true, force: true }).catch(() => {
|
|
@@ -6687,10 +6712,10 @@ var HandoffCheckpointTracker = class {
|
|
|
6687
6712
|
}
|
|
6688
6713
|
const gitTracker = this.createGitTracker();
|
|
6689
6714
|
const tmpDir = await mkdtemp2(
|
|
6690
|
-
|
|
6715
|
+
join3(tmpdir2(), `posthog-code-handoff-${checkpoint.checkpointId}-`)
|
|
6691
6716
|
);
|
|
6692
|
-
const packPath =
|
|
6693
|
-
const indexPath =
|
|
6717
|
+
const packPath = join3(tmpDir, `${checkpoint.checkpointId}.pack`);
|
|
6718
|
+
const indexPath = join3(tmpDir, `${checkpoint.checkpointId}.index`);
|
|
6694
6719
|
try {
|
|
6695
6720
|
const downloads = await this.downloadArtifacts([
|
|
6696
6721
|
{
|
|
@@ -6746,7 +6771,7 @@ var HandoffCheckpointTracker = class {
|
|
|
6746
6771
|
if (!this.apiClient) {
|
|
6747
6772
|
return { rawBytes: 0, wireBytes: 0 };
|
|
6748
6773
|
}
|
|
6749
|
-
const content = await
|
|
6774
|
+
const content = await readFile3(filePath);
|
|
6750
6775
|
const base64Content = content.toString("base64");
|
|
6751
6776
|
const artifacts = await this.apiClient.uploadTaskArtifacts(
|
|
6752
6777
|
this.taskId,
|
|
@@ -6798,7 +6823,7 @@ var HandoffCheckpointTracker = class {
|
|
|
6798
6823
|
}
|
|
6799
6824
|
const base64Content = Buffer.from(arrayBuffer).toString("utf-8");
|
|
6800
6825
|
const binaryContent = Buffer.from(base64Content, "base64");
|
|
6801
|
-
await
|
|
6826
|
+
await writeFile2(filePath, binaryContent);
|
|
6802
6827
|
return {
|
|
6803
6828
|
filePath,
|
|
6804
6829
|
rawBytes: binaryContent.byteLength,
|