@posthog/agent 2.1.48 → 2.1.59
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-DcBmoTR4.d.ts → agent-9gv5HohC.d.ts} +4 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +52 -12
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +122 -82
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +120 -81
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +127 -88
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +3 -2
- package/src/agent.ts +1 -0
- package/src/session-log-writer.ts +50 -0
- package/src/types.ts +2 -0
|
@@ -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(path8, isFile, isDirectory) {
|
|
813
|
+
log(`checking %s`, path8);
|
|
814
814
|
try {
|
|
815
|
-
const stat = fs_1.statSync(
|
|
815
|
+
const stat = fs_1.statSync(path8);
|
|
816
816
|
if (stat.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(path8, type = exports.READABLE) {
|
|
836
|
+
return check(path8, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
|
|
837
837
|
}
|
|
838
838
|
exports.exists = exists2;
|
|
839
839
|
exports.FILE = 1;
|
|
@@ -1183,7 +1183,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
1183
1183
|
// package.json
|
|
1184
1184
|
var package_default = {
|
|
1185
1185
|
name: "@posthog/agent",
|
|
1186
|
-
version: "2.1.
|
|
1186
|
+
version: "2.1.59",
|
|
1187
1187
|
repository: "https://github.com/PostHog/twig",
|
|
1188
1188
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
1189
1189
|
exports: {
|
|
@@ -1248,7 +1248,8 @@ var package_default = {
|
|
|
1248
1248
|
test: "vitest run",
|
|
1249
1249
|
"test:watch": "vitest",
|
|
1250
1250
|
typecheck: "pnpm exec tsc --noEmit",
|
|
1251
|
-
prepublishOnly: "pnpm run build"
|
|
1251
|
+
prepublishOnly: "pnpm run build",
|
|
1252
|
+
clean: "rm -rf dist .turbo"
|
|
1252
1253
|
},
|
|
1253
1254
|
engines: {
|
|
1254
1255
|
node: ">=20.0.0"
|
|
@@ -1561,8 +1562,8 @@ var ToolContentBuilder = class {
|
|
|
1561
1562
|
this.items.push({ type: "content", content: image(data, mimeType, uri) });
|
|
1562
1563
|
return this;
|
|
1563
1564
|
}
|
|
1564
|
-
diff(
|
|
1565
|
-
this.items.push({ type: "diff", path:
|
|
1565
|
+
diff(path8, oldText, newText) {
|
|
1566
|
+
this.items.push({ type: "diff", path: path8, oldText, newText });
|
|
1566
1567
|
return this;
|
|
1567
1568
|
}
|
|
1568
1569
|
build() {
|
|
@@ -1752,13 +1753,13 @@ function toolInfoFromToolUse(toolUse, cachedFileContent, logger = new Logger({ d
|
|
|
1752
1753
|
locations: []
|
|
1753
1754
|
};
|
|
1754
1755
|
case "Edit": {
|
|
1755
|
-
const
|
|
1756
|
+
const path8 = input?.file_path ? String(input.file_path) : void 0;
|
|
1756
1757
|
let oldText = input?.old_string ? String(input.old_string) : null;
|
|
1757
1758
|
let newText = input?.new_string ? String(input.new_string) : "";
|
|
1758
1759
|
let affectedLines = [];
|
|
1759
|
-
if (
|
|
1760
|
+
if (path8 && oldText) {
|
|
1760
1761
|
try {
|
|
1761
|
-
const oldContent = cachedFileContent[
|
|
1762
|
+
const oldContent = cachedFileContent[path8] || "";
|
|
1762
1763
|
const newContent = replaceAndCalculateLocation(oldContent, [
|
|
1763
1764
|
{
|
|
1764
1765
|
oldText,
|
|
@@ -1774,17 +1775,17 @@ function toolInfoFromToolUse(toolUse, cachedFileContent, logger = new Logger({ d
|
|
|
1774
1775
|
}
|
|
1775
1776
|
}
|
|
1776
1777
|
return {
|
|
1777
|
-
title:
|
|
1778
|
+
title: path8 ? `Edit \`${path8}\`` : "Edit",
|
|
1778
1779
|
kind: "edit",
|
|
1779
|
-
content: input &&
|
|
1780
|
+
content: input && path8 ? [
|
|
1780
1781
|
{
|
|
1781
1782
|
type: "diff",
|
|
1782
|
-
path:
|
|
1783
|
+
path: path8,
|
|
1783
1784
|
oldText,
|
|
1784
1785
|
newText
|
|
1785
1786
|
}
|
|
1786
1787
|
] : [],
|
|
1787
|
-
locations:
|
|
1788
|
+
locations: path8 ? affectedLines.length > 0 ? affectedLines.map((line) => ({ line, path: path8 })) : [{ path: path8 }] : []
|
|
1788
1789
|
};
|
|
1789
1790
|
}
|
|
1790
1791
|
case "Write": {
|
|
@@ -4278,6 +4279,8 @@ var PostHogAPIClient = class {
|
|
|
4278
4279
|
};
|
|
4279
4280
|
|
|
4280
4281
|
// src/session-log-writer.ts
|
|
4282
|
+
import fs3 from "fs";
|
|
4283
|
+
import path4 from "path";
|
|
4281
4284
|
var SessionLogWriter = class _SessionLogWriter {
|
|
4282
4285
|
static FLUSH_DEBOUNCE_MS = 500;
|
|
4283
4286
|
static FLUSH_MAX_INTERVAL_MS = 5e3;
|
|
@@ -4291,8 +4294,10 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4291
4294
|
sessions = /* @__PURE__ */ new Map();
|
|
4292
4295
|
messageCounts = /* @__PURE__ */ new Map();
|
|
4293
4296
|
logger;
|
|
4297
|
+
localCachePath;
|
|
4294
4298
|
constructor(options = {}) {
|
|
4295
4299
|
this.posthogAPI = options.posthogAPI;
|
|
4300
|
+
this.localCachePath = options.localCachePath;
|
|
4296
4301
|
this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
|
|
4297
4302
|
}
|
|
4298
4303
|
async flushAll() {
|
|
@@ -4322,6 +4327,21 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4322
4327
|
});
|
|
4323
4328
|
this.sessions.set(sessionId, { context });
|
|
4324
4329
|
this.lastFlushAttemptTime.set(sessionId, Date.now());
|
|
4330
|
+
if (this.localCachePath) {
|
|
4331
|
+
const sessionDir = path4.join(
|
|
4332
|
+
this.localCachePath,
|
|
4333
|
+
"sessions",
|
|
4334
|
+
context.runId
|
|
4335
|
+
);
|
|
4336
|
+
try {
|
|
4337
|
+
fs3.mkdirSync(sessionDir, { recursive: true });
|
|
4338
|
+
} catch (error) {
|
|
4339
|
+
this.logger.warn("Failed to create local cache directory", {
|
|
4340
|
+
sessionDir,
|
|
4341
|
+
error
|
|
4342
|
+
});
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4325
4345
|
}
|
|
4326
4346
|
isRegistered(sessionId) {
|
|
4327
4347
|
return this.sessions.has(sessionId);
|
|
@@ -4359,6 +4379,7 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4359
4379
|
timestamp,
|
|
4360
4380
|
notification: message
|
|
4361
4381
|
};
|
|
4382
|
+
this.writeToLocalCache(sessionId, entry);
|
|
4362
4383
|
if (this.posthogAPI) {
|
|
4363
4384
|
const pending = this.pendingEntries.get(sessionId) ?? [];
|
|
4364
4385
|
pending.push(entry);
|
|
@@ -4459,6 +4480,7 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4459
4480
|
}
|
|
4460
4481
|
}
|
|
4461
4482
|
};
|
|
4483
|
+
this.writeToLocalCache(sessionId, entry);
|
|
4462
4484
|
if (this.posthogAPI) {
|
|
4463
4485
|
const pending = this.pendingEntries.get(sessionId) ?? [];
|
|
4464
4486
|
pending.push(entry);
|
|
@@ -4486,11 +4508,28 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4486
4508
|
const timeout = setTimeout(() => this.flush(sessionId), delay2);
|
|
4487
4509
|
this.flushTimeouts.set(sessionId, timeout);
|
|
4488
4510
|
}
|
|
4511
|
+
writeToLocalCache(sessionId, entry) {
|
|
4512
|
+
if (!this.localCachePath) return;
|
|
4513
|
+
const session = this.sessions.get(sessionId);
|
|
4514
|
+
if (!session) return;
|
|
4515
|
+
const logPath = path4.join(
|
|
4516
|
+
this.localCachePath,
|
|
4517
|
+
"sessions",
|
|
4518
|
+
session.context.runId,
|
|
4519
|
+
"logs.ndjson"
|
|
4520
|
+
);
|
|
4521
|
+
try {
|
|
4522
|
+
fs3.appendFileSync(logPath, `${JSON.stringify(entry)}
|
|
4523
|
+
`);
|
|
4524
|
+
} catch (error) {
|
|
4525
|
+
this.logger.warn("Failed to write to local cache", { logPath, error });
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4489
4528
|
};
|
|
4490
4529
|
|
|
4491
4530
|
// ../git/dist/queries.js
|
|
4492
|
-
import * as
|
|
4493
|
-
import * as
|
|
4531
|
+
import * as fs5 from "fs/promises";
|
|
4532
|
+
import * as path6 from "path";
|
|
4494
4533
|
|
|
4495
4534
|
// ../../node_modules/simple-git/dist/esm/index.js
|
|
4496
4535
|
var import_file_exists = __toESM(require_dist(), 1);
|
|
@@ -4529,8 +4568,8 @@ function pathspec(...paths) {
|
|
|
4529
4568
|
cache.set(key, paths);
|
|
4530
4569
|
return key;
|
|
4531
4570
|
}
|
|
4532
|
-
function isPathSpec(
|
|
4533
|
-
return
|
|
4571
|
+
function isPathSpec(path8) {
|
|
4572
|
+
return path8 instanceof String && cache.has(path8);
|
|
4534
4573
|
}
|
|
4535
4574
|
function toPaths(pathSpec) {
|
|
4536
4575
|
return cache.get(pathSpec) || [];
|
|
@@ -4619,8 +4658,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = "\n") {
|
|
|
4619
4658
|
function forEachLineWithContent(input, callback) {
|
|
4620
4659
|
return toLinesWithContent(input, true).map((line) => callback(line));
|
|
4621
4660
|
}
|
|
4622
|
-
function folderExists(
|
|
4623
|
-
return (0, import_file_exists.exists)(
|
|
4661
|
+
function folderExists(path8) {
|
|
4662
|
+
return (0, import_file_exists.exists)(path8, import_file_exists.FOLDER);
|
|
4624
4663
|
}
|
|
4625
4664
|
function append(target, item) {
|
|
4626
4665
|
if (Array.isArray(target)) {
|
|
@@ -5024,8 +5063,8 @@ function checkIsRepoRootTask() {
|
|
|
5024
5063
|
commands,
|
|
5025
5064
|
format: "utf-8",
|
|
5026
5065
|
onError,
|
|
5027
|
-
parser(
|
|
5028
|
-
return /^\.(git)?$/.test(
|
|
5066
|
+
parser(path8) {
|
|
5067
|
+
return /^\.(git)?$/.test(path8.trim());
|
|
5029
5068
|
}
|
|
5030
5069
|
};
|
|
5031
5070
|
}
|
|
@@ -5459,11 +5498,11 @@ function parseGrep(grep) {
|
|
|
5459
5498
|
const paths = /* @__PURE__ */ new Set();
|
|
5460
5499
|
const results = {};
|
|
5461
5500
|
forEachLineWithContent(grep, (input) => {
|
|
5462
|
-
const [
|
|
5463
|
-
paths.add(
|
|
5464
|
-
(results[
|
|
5501
|
+
const [path8, line, preview] = input.split(NULL);
|
|
5502
|
+
paths.add(path8);
|
|
5503
|
+
(results[path8] = results[path8] || []).push({
|
|
5465
5504
|
line: asNumber(line),
|
|
5466
|
-
path:
|
|
5505
|
+
path: path8,
|
|
5467
5506
|
preview
|
|
5468
5507
|
});
|
|
5469
5508
|
});
|
|
@@ -6228,14 +6267,14 @@ var init_hash_object = __esm({
|
|
|
6228
6267
|
init_task();
|
|
6229
6268
|
}
|
|
6230
6269
|
});
|
|
6231
|
-
function parseInit(bare,
|
|
6270
|
+
function parseInit(bare, path8, text2) {
|
|
6232
6271
|
const response = String(text2).trim();
|
|
6233
6272
|
let result;
|
|
6234
6273
|
if (result = initResponseRegex.exec(response)) {
|
|
6235
|
-
return new InitSummary(bare,
|
|
6274
|
+
return new InitSummary(bare, path8, false, result[1]);
|
|
6236
6275
|
}
|
|
6237
6276
|
if (result = reInitResponseRegex.exec(response)) {
|
|
6238
|
-
return new InitSummary(bare,
|
|
6277
|
+
return new InitSummary(bare, path8, true, result[1]);
|
|
6239
6278
|
}
|
|
6240
6279
|
let gitDir = "";
|
|
6241
6280
|
const tokens = response.split(" ");
|
|
@@ -6246,7 +6285,7 @@ function parseInit(bare, path7, text2) {
|
|
|
6246
6285
|
break;
|
|
6247
6286
|
}
|
|
6248
6287
|
}
|
|
6249
|
-
return new InitSummary(bare,
|
|
6288
|
+
return new InitSummary(bare, path8, /^re/i.test(response), gitDir);
|
|
6250
6289
|
}
|
|
6251
6290
|
var InitSummary;
|
|
6252
6291
|
var initResponseRegex;
|
|
@@ -6255,9 +6294,9 @@ var init_InitSummary = __esm({
|
|
|
6255
6294
|
"src/lib/responses/InitSummary.ts"() {
|
|
6256
6295
|
"use strict";
|
|
6257
6296
|
InitSummary = class {
|
|
6258
|
-
constructor(bare,
|
|
6297
|
+
constructor(bare, path8, existing, gitDir) {
|
|
6259
6298
|
this.bare = bare;
|
|
6260
|
-
this.path =
|
|
6299
|
+
this.path = path8;
|
|
6261
6300
|
this.existing = existing;
|
|
6262
6301
|
this.gitDir = gitDir;
|
|
6263
6302
|
}
|
|
@@ -6269,7 +6308,7 @@ var init_InitSummary = __esm({
|
|
|
6269
6308
|
function hasBareCommand(command) {
|
|
6270
6309
|
return command.includes(bareCommand);
|
|
6271
6310
|
}
|
|
6272
|
-
function initTask(bare = false,
|
|
6311
|
+
function initTask(bare = false, path8, customArgs) {
|
|
6273
6312
|
const commands = ["init", ...customArgs];
|
|
6274
6313
|
if (bare && !hasBareCommand(commands)) {
|
|
6275
6314
|
commands.splice(1, 0, bareCommand);
|
|
@@ -6278,7 +6317,7 @@ function initTask(bare = false, path7, customArgs) {
|
|
|
6278
6317
|
commands,
|
|
6279
6318
|
format: "utf-8",
|
|
6280
6319
|
parser(text2) {
|
|
6281
|
-
return parseInit(commands.includes("--bare"),
|
|
6320
|
+
return parseInit(commands.includes("--bare"), path8, text2);
|
|
6282
6321
|
}
|
|
6283
6322
|
};
|
|
6284
6323
|
}
|
|
@@ -7094,12 +7133,12 @@ var init_FileStatusSummary = __esm({
|
|
|
7094
7133
|
"use strict";
|
|
7095
7134
|
fromPathRegex = /^(.+)\0(.+)$/;
|
|
7096
7135
|
FileStatusSummary = class {
|
|
7097
|
-
constructor(
|
|
7098
|
-
this.path =
|
|
7136
|
+
constructor(path8, index, working_dir) {
|
|
7137
|
+
this.path = path8;
|
|
7099
7138
|
this.index = index;
|
|
7100
7139
|
this.working_dir = working_dir;
|
|
7101
7140
|
if (index === "R" || working_dir === "R") {
|
|
7102
|
-
const detail = fromPathRegex.exec(
|
|
7141
|
+
const detail = fromPathRegex.exec(path8) || [null, path8, path8];
|
|
7103
7142
|
this.from = detail[2] || "";
|
|
7104
7143
|
this.path = detail[1] || "";
|
|
7105
7144
|
}
|
|
@@ -7130,14 +7169,14 @@ function splitLine(result, lineStr) {
|
|
|
7130
7169
|
default:
|
|
7131
7170
|
return;
|
|
7132
7171
|
}
|
|
7133
|
-
function data(index, workingDir,
|
|
7172
|
+
function data(index, workingDir, path8) {
|
|
7134
7173
|
const raw = `${index}${workingDir}`;
|
|
7135
7174
|
const handler = parsers6.get(raw);
|
|
7136
7175
|
if (handler) {
|
|
7137
|
-
handler(result,
|
|
7176
|
+
handler(result, path8);
|
|
7138
7177
|
}
|
|
7139
7178
|
if (raw !== "##" && raw !== "!!") {
|
|
7140
|
-
result.files.push(new FileStatusSummary(
|
|
7179
|
+
result.files.push(new FileStatusSummary(path8, index, workingDir));
|
|
7141
7180
|
}
|
|
7142
7181
|
}
|
|
7143
7182
|
}
|
|
@@ -7450,9 +7489,9 @@ var init_simple_git_api = __esm({
|
|
|
7450
7489
|
next
|
|
7451
7490
|
);
|
|
7452
7491
|
}
|
|
7453
|
-
hashObject(
|
|
7492
|
+
hashObject(path8, write) {
|
|
7454
7493
|
return this._runTask(
|
|
7455
|
-
hashObjectTask(
|
|
7494
|
+
hashObjectTask(path8, write === true),
|
|
7456
7495
|
trailingFunctionArgument(arguments)
|
|
7457
7496
|
);
|
|
7458
7497
|
}
|
|
@@ -7805,8 +7844,8 @@ var init_branch = __esm({
|
|
|
7805
7844
|
}
|
|
7806
7845
|
});
|
|
7807
7846
|
function toPath(input) {
|
|
7808
|
-
const
|
|
7809
|
-
return
|
|
7847
|
+
const path8 = input.trim().replace(/^["']|["']$/g, "");
|
|
7848
|
+
return path8 && normalize(path8);
|
|
7810
7849
|
}
|
|
7811
7850
|
var parseCheckIgnore;
|
|
7812
7851
|
var init_CheckIgnore = __esm({
|
|
@@ -8120,8 +8159,8 @@ __export(sub_module_exports, {
|
|
|
8120
8159
|
subModuleTask: () => subModuleTask,
|
|
8121
8160
|
updateSubModuleTask: () => updateSubModuleTask
|
|
8122
8161
|
});
|
|
8123
|
-
function addSubModuleTask(repo,
|
|
8124
|
-
return subModuleTask(["add", repo,
|
|
8162
|
+
function addSubModuleTask(repo, path8) {
|
|
8163
|
+
return subModuleTask(["add", repo, path8]);
|
|
8125
8164
|
}
|
|
8126
8165
|
function initSubModuleTask(customArgs) {
|
|
8127
8166
|
return subModuleTask(["init", ...customArgs]);
|
|
@@ -8451,8 +8490,8 @@ var require_git = __commonJS2({
|
|
|
8451
8490
|
}
|
|
8452
8491
|
return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
|
|
8453
8492
|
};
|
|
8454
|
-
Git2.prototype.submoduleAdd = function(repo,
|
|
8455
|
-
return this._runTask(addSubModuleTask2(repo,
|
|
8493
|
+
Git2.prototype.submoduleAdd = function(repo, path8, then) {
|
|
8494
|
+
return this._runTask(addSubModuleTask2(repo, path8), trailingFunctionArgument2(arguments));
|
|
8456
8495
|
};
|
|
8457
8496
|
Git2.prototype.submoduleUpdate = function(args, then) {
|
|
8458
8497
|
return this._runTask(
|
|
@@ -9053,22 +9092,22 @@ function createGitClient(baseDir, options) {
|
|
|
9053
9092
|
|
|
9054
9093
|
// ../git/dist/lock-detector.js
|
|
9055
9094
|
import { execFile } from "child_process";
|
|
9056
|
-
import
|
|
9057
|
-
import
|
|
9095
|
+
import fs4 from "fs/promises";
|
|
9096
|
+
import path5 from "path";
|
|
9058
9097
|
import { promisify } from "util";
|
|
9059
9098
|
var execFileAsync = promisify(execFile);
|
|
9060
9099
|
async function getIndexLockPath(repoPath) {
|
|
9061
9100
|
try {
|
|
9062
9101
|
const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "index.lock"], { cwd: repoPath });
|
|
9063
|
-
return
|
|
9102
|
+
return path5.resolve(repoPath, stdout.trim());
|
|
9064
9103
|
} catch {
|
|
9065
|
-
return
|
|
9104
|
+
return path5.join(repoPath, ".git", "index.lock");
|
|
9066
9105
|
}
|
|
9067
9106
|
}
|
|
9068
9107
|
async function getLockInfo(repoPath) {
|
|
9069
9108
|
const lockPath = await getIndexLockPath(repoPath);
|
|
9070
9109
|
try {
|
|
9071
|
-
const stat = await
|
|
9110
|
+
const stat = await fs4.stat(lockPath);
|
|
9072
9111
|
return {
|
|
9073
9112
|
path: lockPath,
|
|
9074
9113
|
ageMs: Date.now() - stat.mtimeMs
|
|
@@ -9079,7 +9118,7 @@ async function getLockInfo(repoPath) {
|
|
|
9079
9118
|
}
|
|
9080
9119
|
async function removeLock(repoPath) {
|
|
9081
9120
|
const lockPath = await getIndexLockPath(repoPath);
|
|
9082
|
-
await
|
|
9121
|
+
await fs4.rm(lockPath, { force: true });
|
|
9083
9122
|
}
|
|
9084
9123
|
async function isLocked(repoPath) {
|
|
9085
9124
|
return await getLockInfo(repoPath) !== null;
|
|
@@ -9375,8 +9414,8 @@ var Saga = class {
|
|
|
9375
9414
|
|
|
9376
9415
|
// ../git/dist/sagas/tree.js
|
|
9377
9416
|
import { existsSync as existsSync4 } from "fs";
|
|
9378
|
-
import * as
|
|
9379
|
-
import * as
|
|
9417
|
+
import * as fs6 from "fs/promises";
|
|
9418
|
+
import * as path7 from "path";
|
|
9380
9419
|
import * as tar from "tar";
|
|
9381
9420
|
|
|
9382
9421
|
// ../git/dist/git-saga.js
|
|
@@ -9402,14 +9441,14 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9402
9441
|
tempIndexPath = null;
|
|
9403
9442
|
async executeGitOperations(input) {
|
|
9404
9443
|
const { baseDir, lastTreeHash, archivePath, signal } = input;
|
|
9405
|
-
const tmpDir =
|
|
9444
|
+
const tmpDir = path7.join(baseDir, ".git", "twig-tmp");
|
|
9406
9445
|
await this.step({
|
|
9407
9446
|
name: "create_tmp_dir",
|
|
9408
|
-
execute: () =>
|
|
9447
|
+
execute: () => fs6.mkdir(tmpDir, { recursive: true }),
|
|
9409
9448
|
rollback: async () => {
|
|
9410
9449
|
}
|
|
9411
9450
|
});
|
|
9412
|
-
this.tempIndexPath =
|
|
9451
|
+
this.tempIndexPath = path7.join(tmpDir, `index-${Date.now()}`);
|
|
9413
9452
|
const tempIndexGit = this.git.env({
|
|
9414
9453
|
...process.env,
|
|
9415
9454
|
GIT_INDEX_FILE: this.tempIndexPath
|
|
@@ -9419,7 +9458,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9419
9458
|
execute: () => tempIndexGit.raw(["read-tree", "HEAD"]),
|
|
9420
9459
|
rollback: async () => {
|
|
9421
9460
|
if (this.tempIndexPath) {
|
|
9422
|
-
await
|
|
9461
|
+
await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
9423
9462
|
});
|
|
9424
9463
|
}
|
|
9425
9464
|
}
|
|
@@ -9428,7 +9467,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9428
9467
|
const treeHash = await this.readOnlyStep("write_tree", () => tempIndexGit.raw(["write-tree"]));
|
|
9429
9468
|
if (lastTreeHash && treeHash === lastTreeHash) {
|
|
9430
9469
|
this.log.debug("No changes since last capture", { treeHash });
|
|
9431
|
-
await
|
|
9470
|
+
await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
9432
9471
|
});
|
|
9433
9472
|
return { snapshot: null, changed: false };
|
|
9434
9473
|
}
|
|
@@ -9440,7 +9479,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9440
9479
|
}
|
|
9441
9480
|
});
|
|
9442
9481
|
const changes = await this.readOnlyStep("get_changes", () => this.getChanges(this.git, baseCommit, treeHash));
|
|
9443
|
-
await
|
|
9482
|
+
await fs6.rm(this.tempIndexPath, { force: true }).catch(() => {
|
|
9444
9483
|
});
|
|
9445
9484
|
const snapshot = {
|
|
9446
9485
|
treeHash,
|
|
@@ -9464,15 +9503,15 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9464
9503
|
if (filesToArchive.length === 0) {
|
|
9465
9504
|
return void 0;
|
|
9466
9505
|
}
|
|
9467
|
-
const existingFiles = filesToArchive.filter((f) => existsSync4(
|
|
9506
|
+
const existingFiles = filesToArchive.filter((f) => existsSync4(path7.join(baseDir, f)));
|
|
9468
9507
|
if (existingFiles.length === 0) {
|
|
9469
9508
|
return void 0;
|
|
9470
9509
|
}
|
|
9471
9510
|
await this.step({
|
|
9472
9511
|
name: "create_archive",
|
|
9473
9512
|
execute: async () => {
|
|
9474
|
-
const archiveDir =
|
|
9475
|
-
await
|
|
9513
|
+
const archiveDir = path7.dirname(archivePath);
|
|
9514
|
+
await fs6.mkdir(archiveDir, { recursive: true });
|
|
9476
9515
|
await tar.create({
|
|
9477
9516
|
gzip: true,
|
|
9478
9517
|
file: archivePath,
|
|
@@ -9480,7 +9519,7 @@ var CaptureTreeSaga = class extends GitSaga {
|
|
|
9480
9519
|
}, existingFiles);
|
|
9481
9520
|
},
|
|
9482
9521
|
rollback: async () => {
|
|
9483
|
-
await
|
|
9522
|
+
await fs6.rm(archivePath, { force: true }).catch(() => {
|
|
9484
9523
|
});
|
|
9485
9524
|
}
|
|
9486
9525
|
});
|
|
@@ -9579,9 +9618,9 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
9579
9618
|
const filesToExtract = changes.filter((c) => c.status !== "D").map((c) => c.path);
|
|
9580
9619
|
await this.readOnlyStep("backup_existing_files", async () => {
|
|
9581
9620
|
for (const filePath of filesToExtract) {
|
|
9582
|
-
const fullPath =
|
|
9621
|
+
const fullPath = path7.join(baseDir, filePath);
|
|
9583
9622
|
try {
|
|
9584
|
-
const content = await
|
|
9623
|
+
const content = await fs6.readFile(fullPath);
|
|
9585
9624
|
this.fileBackups.set(filePath, content);
|
|
9586
9625
|
} catch {
|
|
9587
9626
|
}
|
|
@@ -9598,16 +9637,16 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
9598
9637
|
},
|
|
9599
9638
|
rollback: async () => {
|
|
9600
9639
|
for (const filePath of this.extractedFiles) {
|
|
9601
|
-
const fullPath =
|
|
9640
|
+
const fullPath = path7.join(baseDir, filePath);
|
|
9602
9641
|
const backup = this.fileBackups.get(filePath);
|
|
9603
9642
|
if (backup) {
|
|
9604
|
-
const dir =
|
|
9605
|
-
await
|
|
9643
|
+
const dir = path7.dirname(fullPath);
|
|
9644
|
+
await fs6.mkdir(dir, { recursive: true }).catch(() => {
|
|
9606
9645
|
});
|
|
9607
|
-
await
|
|
9646
|
+
await fs6.writeFile(fullPath, backup).catch(() => {
|
|
9608
9647
|
});
|
|
9609
9648
|
} else {
|
|
9610
|
-
await
|
|
9649
|
+
await fs6.rm(fullPath, { force: true }).catch(() => {
|
|
9611
9650
|
});
|
|
9612
9651
|
}
|
|
9613
9652
|
}
|
|
@@ -9615,10 +9654,10 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
9615
9654
|
});
|
|
9616
9655
|
}
|
|
9617
9656
|
for (const change of changes.filter((c) => c.status === "D")) {
|
|
9618
|
-
const fullPath =
|
|
9657
|
+
const fullPath = path7.join(baseDir, change.path);
|
|
9619
9658
|
const backupContent = await this.readOnlyStep(`backup_${change.path}`, async () => {
|
|
9620
9659
|
try {
|
|
9621
|
-
return await
|
|
9660
|
+
return await fs6.readFile(fullPath);
|
|
9622
9661
|
} catch {
|
|
9623
9662
|
return null;
|
|
9624
9663
|
}
|
|
@@ -9626,15 +9665,15 @@ var ApplyTreeSaga = class extends GitSaga {
|
|
|
9626
9665
|
await this.step({
|
|
9627
9666
|
name: `delete_${change.path}`,
|
|
9628
9667
|
execute: async () => {
|
|
9629
|
-
await
|
|
9668
|
+
await fs6.rm(fullPath, { force: true });
|
|
9630
9669
|
this.log.debug(`Deleted file: ${change.path}`);
|
|
9631
9670
|
},
|
|
9632
9671
|
rollback: async () => {
|
|
9633
9672
|
if (backupContent) {
|
|
9634
|
-
const dir =
|
|
9635
|
-
await
|
|
9673
|
+
const dir = path7.dirname(fullPath);
|
|
9674
|
+
await fs6.mkdir(dir, { recursive: true }).catch(() => {
|
|
9636
9675
|
});
|
|
9637
|
-
await
|
|
9676
|
+
await fs6.writeFile(fullPath, backupContent).catch(() => {
|
|
9638
9677
|
});
|
|
9639
9678
|
}
|
|
9640
9679
|
}
|