@agimon-ai/po-file-edit 0.0.0-alpha.153 → 0.0.0-alpha.154
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/README.md +7 -4
- package/dist/extensions/server.cjs +234 -81
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +234 -81
- package/dist/extensions/server.mjs.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -53,10 +53,13 @@ and keeps it, content-addressed, beside the session timeline; both go when the s
|
|
|
53
53
|
call ends.
|
|
54
54
|
- A file changed outside any tool. There is no always-on watcher.
|
|
55
55
|
- Content past 1 MiB, and binary files. These are listed as changed, without content.
|
|
56
|
-
- A file
|
|
57
|
-
but never diffed. Rows and versions say so rather
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
- A file a Bash command writes without naming it is found only through `git status`, so it has no
|
|
57
|
+
baseline: it is listed, readable and editable, but never diffed. Rows and versions say so rather
|
|
58
|
+
than showing an empty diff. Outside a git checkout, and on the edge host, such a file is not seen.
|
|
59
|
+
- A file a Bash command names (`> f`, `>> f`, `tee`, `sed -i`, `cp`/`mv` destination, `rm`, `touch`,
|
|
60
|
+
`git checkout/restore -- f`) is read before the command runs and gets a real diff.
|
|
61
|
+
- Dependency and build directories are skipped, and a tracked file a script deletes without naming
|
|
62
|
+
it is not reported.
|
|
60
63
|
|
|
61
64
|
## Data behavior
|
|
62
65
|
|
|
@@ -157,6 +157,21 @@ function isInside$1(root, filePath) {
|
|
|
157
157
|
return relative !== "" && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
158
158
|
}
|
|
159
159
|
var NodeGitStatusAdapter = class {
|
|
160
|
+
/** Repository roots already found, so a call per bash command costs one git process, not two. */
|
|
161
|
+
roots = /* @__PURE__ */ new Map();
|
|
162
|
+
async dirty(cwd) {
|
|
163
|
+
const root = await this.topLevel(cwd);
|
|
164
|
+
if (root === void 0) return void 0;
|
|
165
|
+
const output = await this.git(cwd, [
|
|
166
|
+
"status",
|
|
167
|
+
"--porcelain",
|
|
168
|
+
"-z",
|
|
169
|
+
"--untracked-files=all",
|
|
170
|
+
"--",
|
|
171
|
+
"."
|
|
172
|
+
]);
|
|
173
|
+
return output === void 0 ? void 0 : statusPaths(output).map((entry) => node_path.default.resolve(root, entry));
|
|
174
|
+
}
|
|
160
175
|
async unchanged(cwd, filePaths) {
|
|
161
176
|
const clean = /* @__PURE__ */ new Set();
|
|
162
177
|
if (filePaths.length === 0) return clean;
|
|
@@ -187,8 +202,12 @@ var NodeGitStatusAdapter = class {
|
|
|
187
202
|
}
|
|
188
203
|
/** The repository root, or undefined when this tree is not one. */
|
|
189
204
|
async topLevel(cwd) {
|
|
205
|
+
const known = this.roots.get(cwd);
|
|
206
|
+
if (known !== void 0) return known;
|
|
190
207
|
const root = (await this.git(cwd, ["rev-parse", "--show-toplevel"]))?.trim();
|
|
191
|
-
|
|
208
|
+
if (root === void 0 || root === "") return void 0;
|
|
209
|
+
this.roots.set(cwd, node_path.default.resolve(root));
|
|
210
|
+
return node_path.default.resolve(root);
|
|
192
211
|
}
|
|
193
212
|
/** Git's stdout, or undefined when the call failed for any reason at all. */
|
|
194
213
|
async git(cwd, args) {
|
|
@@ -1054,8 +1073,9 @@ var TimelineStore = class {
|
|
|
1054
1073
|
* grows. The rest are where tooling, including this agent's own, writes while a
|
|
1055
1074
|
* session runs: a telemetry log under `logs`, a test run's artifacts under
|
|
1056
1075
|
* `test-results` and `playwright-report`, scratch space under `tmp`, and agent
|
|
1057
|
-
* state under `.pi`.
|
|
1058
|
-
* by file, because
|
|
1076
|
+
* state under `.pi`. A changed path under any of them is dropped by construction
|
|
1077
|
+
* rather than judged file by file, because recording it reports the session
|
|
1078
|
+
* watching itself.
|
|
1059
1079
|
*/
|
|
1060
1080
|
const IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
1061
1081
|
".git",
|
|
@@ -1085,9 +1105,8 @@ const IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
|
1085
1105
|
"venv"
|
|
1086
1106
|
]);
|
|
1087
1107
|
/**
|
|
1088
|
-
* How a file is summarised. Size and modification time are
|
|
1089
|
-
*
|
|
1090
|
-
* into a read of the whole tree.
|
|
1108
|
+
* How a file is summarised. Size and modification time are one stat away;
|
|
1109
|
+
* hashing every candidate would turn each comparison into a read of each file.
|
|
1091
1110
|
*/
|
|
1092
1111
|
function fingerprintOf(size, modifiedMs) {
|
|
1093
1112
|
return `${size}:${modifiedMs}`;
|
|
@@ -1111,23 +1130,13 @@ function sizesDiffer(before, after) {
|
|
|
1111
1130
|
}
|
|
1112
1131
|
//#endregion
|
|
1113
1132
|
//#region src/services/treeManifest/index.ts
|
|
1133
|
+
/**
|
|
1134
|
+
* Fingerprints single files with node's fs.
|
|
1135
|
+
*
|
|
1136
|
+
* One technology per adapter. This is where node enters the package; the
|
|
1137
|
+
* services that depend on the capability keep importing the port.
|
|
1138
|
+
*/
|
|
1114
1139
|
var NodeTreeManifestAdapter = class {
|
|
1115
|
-
maxEntries;
|
|
1116
|
-
maxDepth;
|
|
1117
|
-
ignored;
|
|
1118
|
-
constructor(options = {}) {
|
|
1119
|
-
this.maxEntries = options.maxEntries ?? 2e4;
|
|
1120
|
-
this.maxDepth = options.maxDepth ?? 12;
|
|
1121
|
-
this.ignored = options.ignoredDirectories ?? IGNORED_DIRECTORIES;
|
|
1122
|
-
}
|
|
1123
|
-
async take(root, exclude = []) {
|
|
1124
|
-
const entries = /* @__PURE__ */ new Map();
|
|
1125
|
-
const skipped = new Set(exclude.map((entry) => node_path.default.resolve(entry)));
|
|
1126
|
-
return {
|
|
1127
|
-
entries,
|
|
1128
|
-
truncated: await this.walk(root, 0, entries, skipped)
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
1140
|
async fingerprint(filePath) {
|
|
1132
1141
|
try {
|
|
1133
1142
|
const stat = await node_fs_promises.default.stat(filePath);
|
|
@@ -1150,34 +1159,6 @@ var NodeTreeManifestAdapter = class {
|
|
|
1150
1159
|
sizeChanged(before, after) {
|
|
1151
1160
|
return sizesDiffer(before, after);
|
|
1152
1161
|
}
|
|
1153
|
-
/** Fills `entries` depth-first and answers whether a cap cut the walk short. */
|
|
1154
|
-
async walk(directory, depth, entries, skipped) {
|
|
1155
|
-
if (depth > this.maxDepth) return true;
|
|
1156
|
-
let listing;
|
|
1157
|
-
try {
|
|
1158
|
-
listing = await node_fs_promises.default.readdir(directory, { withFileTypes: true });
|
|
1159
|
-
} catch {
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
let truncated = false;
|
|
1163
|
-
for (const entry of listing) {
|
|
1164
|
-
if (entries.size >= this.maxEntries) return true;
|
|
1165
|
-
const entryPath = node_path.default.join(directory, entry.name);
|
|
1166
|
-
if (skipped.has(entryPath)) continue;
|
|
1167
|
-
if (entry.isSymbolicLink()) continue;
|
|
1168
|
-
if (entry.isDirectory()) {
|
|
1169
|
-
if (this.ignored.has(entry.name)) continue;
|
|
1170
|
-
truncated = await this.walk(entryPath, depth + 1, entries, skipped) || truncated;
|
|
1171
|
-
continue;
|
|
1172
|
-
}
|
|
1173
|
-
if (!entry.isFile()) continue;
|
|
1174
|
-
try {
|
|
1175
|
-
const stat = await node_fs_promises.default.stat(entryPath);
|
|
1176
|
-
entries.set(entryPath, fingerprintOf(stat.size, stat.mtimeMs));
|
|
1177
|
-
} catch {}
|
|
1178
|
-
}
|
|
1179
|
-
return truncated;
|
|
1180
|
-
}
|
|
1181
1162
|
};
|
|
1182
1163
|
//#endregion
|
|
1183
1164
|
//#region src/types/webFiles.ts
|
|
@@ -1544,11 +1525,132 @@ function createSessionPresence(options) {
|
|
|
1544
1525
|
};
|
|
1545
1526
|
}
|
|
1546
1527
|
//#endregion
|
|
1528
|
+
//#region src/services/bashTargets/index.ts
|
|
1529
|
+
const SEPARATOR = ";";
|
|
1530
|
+
/** `>&2` and `2>&1` duplicate a descriptor and name no file. */
|
|
1531
|
+
const DUPLICATE = ">&";
|
|
1532
|
+
/** Words a shell would expand: what they name is unknowable from the text. */
|
|
1533
|
+
const EXPANDS = /[$`*?{}()<>]/u;
|
|
1534
|
+
const WRITE_ARGUMENTS = /* @__PURE__ */ new Set([
|
|
1535
|
+
"tee",
|
|
1536
|
+
"touch",
|
|
1537
|
+
"rm",
|
|
1538
|
+
"truncate"
|
|
1539
|
+
]);
|
|
1540
|
+
const WRITE_DESTINATION = /* @__PURE__ */ new Set([
|
|
1541
|
+
"cp",
|
|
1542
|
+
"mv",
|
|
1543
|
+
"install"
|
|
1544
|
+
]);
|
|
1545
|
+
function tokens(command) {
|
|
1546
|
+
const out = [];
|
|
1547
|
+
let word = "";
|
|
1548
|
+
let started = false;
|
|
1549
|
+
let quote;
|
|
1550
|
+
const flush = () => {
|
|
1551
|
+
if (started) out.push({
|
|
1552
|
+
op: false,
|
|
1553
|
+
value: word
|
|
1554
|
+
});
|
|
1555
|
+
word = "";
|
|
1556
|
+
started = false;
|
|
1557
|
+
};
|
|
1558
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
1559
|
+
const character = command[index];
|
|
1560
|
+
const next = command[index + 1];
|
|
1561
|
+
if (quote !== void 0) {
|
|
1562
|
+
if (character === quote) quote = void 0;
|
|
1563
|
+
else if (character === "\\" && quote === "\"" && next !== void 0) word += command[++index];
|
|
1564
|
+
else word += character;
|
|
1565
|
+
} else if (character === "'" || character === "\"") {
|
|
1566
|
+
quote = character;
|
|
1567
|
+
started = true;
|
|
1568
|
+
} else if (character === "\\" && next !== void 0) {
|
|
1569
|
+
word += command[++index];
|
|
1570
|
+
started = true;
|
|
1571
|
+
} else if (character === "&" && next === ">") {
|
|
1572
|
+
flush();
|
|
1573
|
+
word = "&";
|
|
1574
|
+
started = true;
|
|
1575
|
+
} else if (character === ">") {
|
|
1576
|
+
const prefix = started && /^(?:\d|&)$/u.test(word) ? word : "";
|
|
1577
|
+
if (prefix) {
|
|
1578
|
+
word = "";
|
|
1579
|
+
started = false;
|
|
1580
|
+
} else flush();
|
|
1581
|
+
let operator = `${prefix}>`;
|
|
1582
|
+
if (command[index + 1] === ">") operator += command[++index];
|
|
1583
|
+
if (command[index + 1] === "&") {
|
|
1584
|
+
while (/[&\d-]/u.test(command[index + 1] ?? "")) index += 1;
|
|
1585
|
+
operator = DUPLICATE;
|
|
1586
|
+
}
|
|
1587
|
+
out.push({
|
|
1588
|
+
op: true,
|
|
1589
|
+
value: operator
|
|
1590
|
+
});
|
|
1591
|
+
} else if (character === ";" || character === "|" || character === "&" || character === "\n") {
|
|
1592
|
+
flush();
|
|
1593
|
+
if ((character === "&" || character === "|") && (next === character || next === "&")) index += 1;
|
|
1594
|
+
out.push({
|
|
1595
|
+
op: true,
|
|
1596
|
+
value: SEPARATOR
|
|
1597
|
+
});
|
|
1598
|
+
} else if (/\s/u.test(character)) flush();
|
|
1599
|
+
else {
|
|
1600
|
+
word += character;
|
|
1601
|
+
started = true;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
flush();
|
|
1605
|
+
return out;
|
|
1606
|
+
}
|
|
1607
|
+
/** The targets one simple command writes through its arguments. */
|
|
1608
|
+
function argumentTargets(words) {
|
|
1609
|
+
const start = words.findIndex((word) => !/^\w+=/u.test(word));
|
|
1610
|
+
if (start === -1) return [];
|
|
1611
|
+
const program = node_path.default.basename(words[start]);
|
|
1612
|
+
const rest = words.slice(start + 1);
|
|
1613
|
+
const operands = rest.filter((word) => word !== "" && !word.startsWith("-"));
|
|
1614
|
+
if (WRITE_ARGUMENTS.has(program)) return operands;
|
|
1615
|
+
if (WRITE_DESTINATION.has(program)) return operands.length >= 2 ? [operands.at(-1)] : [];
|
|
1616
|
+
if (program === "sed" && rest.some((word) => word.startsWith("-i") || word === "--in-place")) {
|
|
1617
|
+
if (!rest.some((word) => word === "-e" || word === "-f")) return operands.slice(1);
|
|
1618
|
+
return rest.filter((word, index) => word !== "" && !word.startsWith("-") && rest[index - 1] !== "-e" && rest[index - 1] !== "-f");
|
|
1619
|
+
}
|
|
1620
|
+
if (program === "git" && (operands[0] === "checkout" || operands[0] === "restore")) {
|
|
1621
|
+
const separator = rest.indexOf("--");
|
|
1622
|
+
if (separator !== -1) return rest.slice(separator + 1);
|
|
1623
|
+
return operands[0] === "restore" ? operands.slice(1) : [];
|
|
1624
|
+
}
|
|
1625
|
+
return [];
|
|
1626
|
+
}
|
|
1627
|
+
/** Absolute paths of the files `command`, run in `cwd`, names as outputs. */
|
|
1628
|
+
function bashTargets(command, cwd) {
|
|
1629
|
+
const named = /* @__PURE__ */ new Set();
|
|
1630
|
+
const add = (word) => {
|
|
1631
|
+
if (word === "" || word.startsWith("-") || word.startsWith("~") || EXPANDS.test(word)) return;
|
|
1632
|
+
if (word.startsWith("/dev/")) return;
|
|
1633
|
+
named.add(node_path.default.resolve(cwd, word));
|
|
1634
|
+
};
|
|
1635
|
+
let words = [];
|
|
1636
|
+
const list = tokens(command);
|
|
1637
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1638
|
+
const token = list[index];
|
|
1639
|
+
if (!token.op) words.push(token.value);
|
|
1640
|
+
else if (token.value === SEPARATOR) {
|
|
1641
|
+
argumentTargets(words).forEach(add);
|
|
1642
|
+
words = [];
|
|
1643
|
+
} else if (token.value !== DUPLICATE && list[index + 1]?.op === false) add(list[++index].value);
|
|
1644
|
+
}
|
|
1645
|
+
argumentTargets(words).forEach(add);
|
|
1646
|
+
return [...named];
|
|
1647
|
+
}
|
|
1648
|
+
//#endregion
|
|
1547
1649
|
//#region src/services/editTracker/index.ts
|
|
1548
1650
|
const EDIT_TOOL = "edit";
|
|
1549
1651
|
const WRITE_TOOL = "write";
|
|
1550
1652
|
const BASH_TOOL = "bash";
|
|
1551
|
-
/** Code mode scripts can write files like a shell can, so they get the same
|
|
1653
|
+
/** Code mode scripts can write files like a shell can, so they get the same git comparison. */
|
|
1552
1654
|
const EXEC_TOOL = "exec";
|
|
1553
1655
|
function objectValue(value, key) {
|
|
1554
1656
|
if (!value || typeof value !== "object") return void 0;
|
|
@@ -1568,18 +1670,20 @@ var EditTracker = class {
|
|
|
1568
1670
|
snapshots;
|
|
1569
1671
|
manifests;
|
|
1570
1672
|
pending = /* @__PURE__ */ new Map();
|
|
1673
|
+
/** The files each in-flight bash call named in its text, read before it ran. */
|
|
1674
|
+
named = /* @__PURE__ */ new Map();
|
|
1571
1675
|
/** Start time per in-flight bash call, so its end knows what it may claim. */
|
|
1572
1676
|
bracketed = /* @__PURE__ */ new Map();
|
|
1573
1677
|
/**
|
|
1574
|
-
* The
|
|
1575
|
-
* then replaces it, so
|
|
1576
|
-
*
|
|
1678
|
+
* The watched files as this tracker last saw them. A bash call compares
|
|
1679
|
+
* against it and then replaces it, so a change made between calls is still
|
|
1680
|
+
* noticed on the next one.
|
|
1577
1681
|
*/
|
|
1578
1682
|
manifest;
|
|
1579
1683
|
/**
|
|
1580
|
-
* This package's own storage, which
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1684
|
+
* This package's own storage, which must never be reported. The timeline and
|
|
1685
|
+
* its snapshots can land inside the tree being watched, and recording them
|
|
1686
|
+
* would make every change cause another one.
|
|
1583
1687
|
*/
|
|
1584
1688
|
excluded = [];
|
|
1585
1689
|
/**
|
|
@@ -1595,18 +1699,20 @@ var EditTracker = class {
|
|
|
1595
1699
|
contents = /* @__PURE__ */ new Map();
|
|
1596
1700
|
now;
|
|
1597
1701
|
git;
|
|
1702
|
+
onScanFailed;
|
|
1598
1703
|
/**
|
|
1599
1704
|
* The scan deferred by the last bash call. Every bracket joins this chain, so
|
|
1600
|
-
* at most one
|
|
1601
|
-
* one left behind.
|
|
1705
|
+
* at most one comparison runs at a time and each one sees the baseline the
|
|
1706
|
+
* previous one left behind.
|
|
1602
1707
|
*/
|
|
1603
1708
|
scanning = Promise.resolve();
|
|
1604
|
-
constructor(timeline, snapshots, manifests, options
|
|
1709
|
+
constructor(timeline, snapshots, manifests, options) {
|
|
1605
1710
|
this.timeline = timeline;
|
|
1606
1711
|
this.snapshots = snapshots;
|
|
1607
1712
|
this.manifests = manifests;
|
|
1608
1713
|
this.now = options.now ?? Date.now;
|
|
1609
1714
|
this.git = options.git;
|
|
1715
|
+
this.onScanFailed = options.onScanFailed;
|
|
1610
1716
|
}
|
|
1611
1717
|
/**
|
|
1612
1718
|
* Forgets the previous session's tree so a new one does not inherit its
|
|
@@ -1614,6 +1720,7 @@ var EditTracker = class {
|
|
|
1614
1720
|
*/
|
|
1615
1721
|
reset(options = {}) {
|
|
1616
1722
|
this.pending.clear();
|
|
1723
|
+
this.named.clear();
|
|
1617
1724
|
this.bracketed.clear();
|
|
1618
1725
|
this.contents.clear();
|
|
1619
1726
|
this.manifest = void 0;
|
|
@@ -1633,26 +1740,40 @@ var EditTracker = class {
|
|
|
1633
1740
|
if (tool === EDIT_TOOL || tool === WRITE_TOOL) {
|
|
1634
1741
|
const supplied = objectValue(args, "path");
|
|
1635
1742
|
if (!supplied) return false;
|
|
1636
|
-
|
|
1637
|
-
const [before, fingerprint] = await Promise.all([this.snapshots.capture(filePath), this.manifests.fingerprint(filePath)]);
|
|
1638
|
-
this.pending.set(id, {
|
|
1639
|
-
tool,
|
|
1640
|
-
filePath,
|
|
1641
|
-
before,
|
|
1642
|
-
existed: fingerprint !== void 0
|
|
1643
|
-
});
|
|
1743
|
+
this.pending.set(id, await this.prepare(tool, node_path.default.resolve(cwd, supplied)));
|
|
1644
1744
|
return true;
|
|
1645
1745
|
}
|
|
1646
1746
|
if (tool !== BASH_TOOL && tool !== EXEC_TOOL) return false;
|
|
1647
1747
|
this.bracketed.set(id, this.now());
|
|
1648
|
-
|
|
1748
|
+
const command = tool === BASH_TOOL ? objectValue(args, "command") : void 0;
|
|
1749
|
+
if (command !== void 0) {
|
|
1750
|
+
const targets = bashTargets(command, cwd).filter((filePath) => this.watched(cwd, filePath));
|
|
1751
|
+
this.named.set(id, await Promise.all(targets.map((filePath) => this.prepare(BASH_TOOL, filePath))));
|
|
1752
|
+
}
|
|
1753
|
+
this.manifest ??= await this.takeManifest(cwd);
|
|
1649
1754
|
return true;
|
|
1650
1755
|
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Reads a named file before the call that may change it. The fingerprint is
|
|
1758
|
+
* the only thing that tells a file being created from one whose content could
|
|
1759
|
+
* not be captured, because a capture answers undefined for either.
|
|
1760
|
+
*/
|
|
1761
|
+
async prepare(tool, filePath) {
|
|
1762
|
+
const [before, fingerprint] = await Promise.all([this.snapshots.capture(filePath), this.manifests.fingerprint(filePath)]);
|
|
1763
|
+
return {
|
|
1764
|
+
tool,
|
|
1765
|
+
filePath,
|
|
1766
|
+
before,
|
|
1767
|
+
existed: fingerprint !== void 0
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1651
1770
|
async end(id, isError, cwd) {
|
|
1652
1771
|
const pending = this.pending.get(id);
|
|
1653
1772
|
this.pending.delete(id);
|
|
1654
1773
|
const startedAt = this.bracketed.get(id);
|
|
1655
1774
|
this.bracketed.delete(id);
|
|
1775
|
+
const named = this.named.get(id) ?? [];
|
|
1776
|
+
this.named.delete(id);
|
|
1656
1777
|
if (pending) {
|
|
1657
1778
|
if (!isError) await this.recordTool(pending);
|
|
1658
1779
|
return;
|
|
@@ -1660,11 +1781,14 @@ var EditTracker = class {
|
|
|
1660
1781
|
if (startedAt === void 0) return;
|
|
1661
1782
|
this.scanning = this.scanning.then(async () => {
|
|
1662
1783
|
try {
|
|
1784
|
+
for (const target of named) if (target.existed ? target.before !== void 0 : await this.manifests.fingerprint(target.filePath) !== void 0) await this.recordTool(target);
|
|
1663
1785
|
await this.recordScan(cwd, startedAt);
|
|
1664
|
-
} catch {
|
|
1786
|
+
} catch (error) {
|
|
1787
|
+
this.onScanFailed(error);
|
|
1788
|
+
}
|
|
1665
1789
|
});
|
|
1666
1790
|
}
|
|
1667
|
-
/**
|
|
1791
|
+
/** A file named before the call, by `edit`, `write` or a bash command's text, read on both sides of it. */
|
|
1668
1792
|
async recordTool(pending) {
|
|
1669
1793
|
const after = await this.snapshots.capture(pending.filePath);
|
|
1670
1794
|
const created = !pending.existed;
|
|
@@ -1683,11 +1807,38 @@ var EditTracker = class {
|
|
|
1683
1807
|
});
|
|
1684
1808
|
await this.remember(pending.filePath);
|
|
1685
1809
|
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Whether a path is worth watching: inside the session's tree, outside this
|
|
1812
|
+
* package's own storage and the directories builds and tooling fill, and not
|
|
1813
|
+
* disowned by the project.
|
|
1814
|
+
*/
|
|
1815
|
+
watched(cwd, filePath) {
|
|
1816
|
+
const relative = node_path.default.relative(cwd, filePath);
|
|
1817
|
+
if (relative === "" || relative.startsWith("..") || node_path.default.isAbsolute(relative)) return false;
|
|
1818
|
+
if (this.excluded.some((entry) => filePath === entry || filePath.startsWith(`${entry}${node_path.default.sep}`))) return false;
|
|
1819
|
+
if (relative.split(node_path.default.sep).some((segment) => IGNORED_DIRECTORIES.has(segment))) return false;
|
|
1820
|
+
return this.isIgnored === void 0 || !this.isIgnored(filePath);
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Fingerprints what git calls dirty under `cwd`, plus the paths already being
|
|
1824
|
+
* followed, so a file reverted to clean still shows as moved. Outside a
|
|
1825
|
+
* repository it holds only what it carries.
|
|
1826
|
+
*/
|
|
1827
|
+
async takeManifest(cwd, carried = []) {
|
|
1828
|
+
const paths = new Set(carried);
|
|
1829
|
+
for (const filePath of await this.git?.dirty(cwd) ?? []) if (this.watched(cwd, filePath)) paths.add(filePath);
|
|
1830
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1831
|
+
for (const filePath of paths) {
|
|
1832
|
+
const fingerprint = await this.manifests.fingerprint(filePath);
|
|
1833
|
+
if (fingerprint !== void 0) entries.set(filePath, fingerprint);
|
|
1834
|
+
}
|
|
1835
|
+
return { entries };
|
|
1836
|
+
}
|
|
1686
1837
|
/** Whatever a bash call actually edited, however the command wrote it. */
|
|
1687
1838
|
async recordScan(cwd, startedAt) {
|
|
1688
1839
|
const before = this.manifest;
|
|
1689
1840
|
if (before === void 0) return;
|
|
1690
|
-
const after = await this.
|
|
1841
|
+
const after = await this.takeManifest(cwd, before.entries.keys());
|
|
1691
1842
|
this.manifest = after;
|
|
1692
1843
|
const disowned = this.isIgnored;
|
|
1693
1844
|
const named = this.manifests.changed(before, after).filter((filePath) => disowned === void 0 || !disowned(filePath));
|
|
@@ -1773,7 +1924,7 @@ var EditTracker = class {
|
|
|
1773
1924
|
* Folds a path the tool layer just handled into the tracked manifest, so the
|
|
1774
1925
|
* next bash comparison sees it as already accounted for.
|
|
1775
1926
|
*
|
|
1776
|
-
* The fingerprint has to be the one a
|
|
1927
|
+
* The fingerprint has to be the one a comparison would read, not a stand-in, or the
|
|
1777
1928
|
* next comparison reports the file again under bash and every tool edit is
|
|
1778
1929
|
* recorded twice.
|
|
1779
1930
|
*/
|
|
@@ -1783,10 +1934,7 @@ var EditTracker = class {
|
|
|
1783
1934
|
const fingerprint = await this.manifests.fingerprint(filePath);
|
|
1784
1935
|
if (fingerprint === void 0) entries.delete(filePath);
|
|
1785
1936
|
else entries.set(filePath, fingerprint);
|
|
1786
|
-
this.manifest = {
|
|
1787
|
-
entries,
|
|
1788
|
-
truncated: this.manifest.truncated
|
|
1789
|
-
};
|
|
1937
|
+
this.manifest = { entries };
|
|
1790
1938
|
}
|
|
1791
1939
|
};
|
|
1792
1940
|
//#endregion
|
|
@@ -2075,9 +2223,6 @@ function createFileEditSession({ agent, host }, fs, storage = createFileEditStor
|
|
|
2075
2223
|
const paths = storage.paths(environment);
|
|
2076
2224
|
const timeline = storage.timeline();
|
|
2077
2225
|
const snapshots = storage.snapshots();
|
|
2078
|
-
const editTracker = new EditTracker(timeline, snapshots, storage.manifests(), { git: storage.git() });
|
|
2079
|
-
if (host.context.directEvents === void 0) throw new Error("File-edit server plugin requires the session direct event bus.");
|
|
2080
|
-
const directEvents = host.context.directEvents;
|
|
2081
2226
|
const telemetry = (0, _agimon_ai_po_core_telemetry.createPoTelemetry)({
|
|
2082
2227
|
serviceName: "po-file-edit",
|
|
2083
2228
|
packageName: "@agimon-ai/po-file-edit",
|
|
@@ -2085,6 +2230,12 @@ function createFileEditSession({ agent, host }, fs, storage = createFileEditStor
|
|
|
2085
2230
|
enableLogs: true,
|
|
2086
2231
|
enableTraces: true
|
|
2087
2232
|
});
|
|
2233
|
+
const editTracker = new EditTracker(timeline, snapshots, storage.manifests(), {
|
|
2234
|
+
git: storage.git(),
|
|
2235
|
+
onScanFailed: (error) => void track(() => telemetry.recordWarning("po_file_edit.scan_failed", error))
|
|
2236
|
+
});
|
|
2237
|
+
if (host.context.directEvents === void 0) throw new Error("File-edit server plugin requires the session direct event bus.");
|
|
2238
|
+
const directEvents = host.context.directEvents;
|
|
2088
2239
|
const toolStartedAt = /* @__PURE__ */ new Map();
|
|
2089
2240
|
const pending = /* @__PURE__ */ new Set();
|
|
2090
2241
|
let closed = false;
|
|
@@ -2185,7 +2336,9 @@ function createFileEditSession({ agent, host }, fs, storage = createFileEditStor
|
|
|
2185
2336
|
track(async () => {
|
|
2186
2337
|
try {
|
|
2187
2338
|
await storage.sweepAbandoned?.(paths.stateDirectory(), timelinePath);
|
|
2188
|
-
} catch {
|
|
2339
|
+
} catch (error) {
|
|
2340
|
+
await telemetry.recordWarning("po_file_edit.sweep_failed", error);
|
|
2341
|
+
}
|
|
2189
2342
|
});
|
|
2190
2343
|
if (!initialized) {
|
|
2191
2344
|
initialized = true;
|