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