@visorcraft/idlehands 2.2.7 → 2.2.8
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 +20 -0
- package/dist/agent.js.map +1 -1
- package/dist/bot/command-logic.js +1 -0
- package/dist/bot/command-logic.js.map +1 -1
- package/dist/bot/commands.js +12 -1
- package/dist/bot/commands.js.map +1 -1
- package/dist/bot/discord-commands.js +5 -1
- package/dist/bot/discord-commands.js.map +1 -1
- package/dist/bot/metrics-command.js +51 -0
- package/dist/bot/metrics-command.js.map +1 -0
- package/dist/bot/telegram.js +2 -1
- package/dist/bot/telegram.js.map +1 -1
- package/dist/tools/transaction.js +60 -0
- package/dist/tools/transaction.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export class EditTransaction {
|
|
2
|
+
modifiedFiles = [];
|
|
3
|
+
committed = false;
|
|
4
|
+
/** Record a file that was just modified (called after successful backup + write). */
|
|
5
|
+
track(absPath) {
|
|
6
|
+
if (!this.modifiedFiles.includes(absPath)) {
|
|
7
|
+
this.modifiedFiles.push(absPath);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Mark the transaction as committed (all edits succeeded). */
|
|
11
|
+
commit() {
|
|
12
|
+
this.committed = true;
|
|
13
|
+
}
|
|
14
|
+
/** Get list of files modified in this transaction. */
|
|
15
|
+
get files() {
|
|
16
|
+
return [...this.modifiedFiles];
|
|
17
|
+
}
|
|
18
|
+
/** Whether the transaction has any tracked files. */
|
|
19
|
+
get hasChanges() {
|
|
20
|
+
return this.modifiedFiles.length > 0;
|
|
21
|
+
}
|
|
22
|
+
/** Whether the transaction was committed. */
|
|
23
|
+
get isCommitted() {
|
|
24
|
+
return this.committed;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Roll back all modified files to their pre-transaction state.
|
|
28
|
+
* Uses the existing undo system (each file already has a backup).
|
|
29
|
+
* Returns array of results.
|
|
30
|
+
*/
|
|
31
|
+
async rollback(ctx) {
|
|
32
|
+
if (this.committed) {
|
|
33
|
+
return this.modifiedFiles.map((p) => ({
|
|
34
|
+
path: p,
|
|
35
|
+
ok: false,
|
|
36
|
+
error: 'Transaction already committed',
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
// Dynamic import to avoid circular deps
|
|
40
|
+
const { undo_path } = await import('../tools.js');
|
|
41
|
+
const results = [];
|
|
42
|
+
// Roll back in reverse order (last modified first)
|
|
43
|
+
for (const absPath of [...this.modifiedFiles].reverse()) {
|
|
44
|
+
try {
|
|
45
|
+
await undo_path(ctx, { path: absPath });
|
|
46
|
+
results.push({ path: absPath, ok: true });
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
results.push({ path: absPath, ok: false, error: e?.message ?? String(e) });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
/** Reset the transaction (clear tracked files). */
|
|
55
|
+
reset() {
|
|
56
|
+
this.modifiedFiles = [];
|
|
57
|
+
this.committed = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/tools/transaction.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,eAAe;IAClB,aAAa,GAAa,EAAE,CAAC;IAC7B,SAAS,GAAG,KAAK,CAAC;IAE1B,qFAAqF;IACrF,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,+DAA+D;IAC/D,MAAM;QACJ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,sDAAsD;IACtD,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