dsh-turn-undo 0.0.6 → 0.0.7
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/index.js +14 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -278,6 +278,7 @@ class SnapshotStore {
|
|
|
278
278
|
sessionId,
|
|
279
279
|
turn,
|
|
280
280
|
timestamp: new Date().toISOString(),
|
|
281
|
+
cwd,
|
|
281
282
|
totalBytes,
|
|
282
283
|
manifest,
|
|
283
284
|
}
|
|
@@ -546,6 +547,10 @@ class SnapshotStore {
|
|
|
546
547
|
*/
|
|
547
548
|
restore(cwd, sessionId, targetTurn) {
|
|
548
549
|
const chain = this.loadChain(sessionId)
|
|
550
|
+
// Use the cwd from the latest snapshot (captures the workspace root at
|
|
551
|
+
// capture time). This avoids cross-workspace bugs when the session's
|
|
552
|
+
// header.cwd has changed or is wrong (e.g. forked from another workspace).
|
|
553
|
+
const snapCwd = chain.length ? (chain[chain.length - 1].cwd ?? cwd) : cwd
|
|
549
554
|
// Find the NEWEST snapshot whose turn <= targetTurn (best available state
|
|
550
555
|
// at/before the boundary). Filter to only completed turns present.
|
|
551
556
|
let target = null
|
|
@@ -559,7 +564,8 @@ class SnapshotStore {
|
|
|
559
564
|
}
|
|
560
565
|
|
|
561
566
|
// Restore files to the target manifest state.
|
|
562
|
-
const
|
|
567
|
+
const resolveCwd = snapCwd || cwd
|
|
568
|
+
const ignore = makeIgnore(resolveCwd, this.excludes)
|
|
563
569
|
const manifest = target.manifest
|
|
564
570
|
const rels = Object.keys(manifest)
|
|
565
571
|
|
|
@@ -569,7 +575,7 @@ class SnapshotStore {
|
|
|
569
575
|
// 1. Write back / refresh files present in target manifest.
|
|
570
576
|
for (const rel of rels) {
|
|
571
577
|
const entry = manifest[rel]
|
|
572
|
-
const abs = resolve(
|
|
578
|
+
const abs = resolve(resolveCwd, rel)
|
|
573
579
|
if (ignore(abs)) continue
|
|
574
580
|
try {
|
|
575
581
|
ensureDir(dirname(abs))
|
|
@@ -590,11 +596,11 @@ class SnapshotStore {
|
|
|
590
596
|
// 2. Delete files present on disk but absent from the target manifest,
|
|
591
597
|
// except excluded dirs. Only within cwd. Uses a boundary-unlimited walk
|
|
592
598
|
// (unlike scan, whose caps would silently stop the pruning early).
|
|
593
|
-
const current = this.walkAll(
|
|
599
|
+
const current = this.walkAll(resolveCwd, ignore)
|
|
594
600
|
const failedDeletions = []
|
|
595
601
|
for (const abs of current) {
|
|
596
602
|
if (ignore(abs)) continue
|
|
597
|
-
const rel = relative(
|
|
603
|
+
const rel = relative(resolveCwd, abs).split('\\').join('/')
|
|
598
604
|
if (!(rel in manifest)) {
|
|
599
605
|
try {
|
|
600
606
|
rmSync(abs, { force: true })
|
|
@@ -1396,6 +1402,8 @@ SnapshotStore.prototype.preview = function (sessionId, targetTurn, cwd) {
|
|
|
1396
1402
|
return { ok: true, status: 'ready', targetTurn: null, totalChanges: 0, changes: [] }
|
|
1397
1403
|
}
|
|
1398
1404
|
const chain = this.loadChain(sessionId)
|
|
1405
|
+
// Use cwd from latest snapshot to avoid cross-workspace path issues
|
|
1406
|
+
const snapCwd = chain.length ? (chain[chain.length - 1].cwd ?? cwd) : cwd
|
|
1399
1407
|
if (chain.length === 0) {
|
|
1400
1408
|
return { ok: true, status: 'no-snapshot', targetTurn, totalChanges: 0, changes: [], noSnapshot: true }
|
|
1401
1409
|
}
|
|
@@ -1427,8 +1435,8 @@ SnapshotStore.prototype.preview = function (sessionId, targetTurn, cwd) {
|
|
|
1427
1435
|
// preview shows meaningful changes even when the active turn has no snapshot.
|
|
1428
1436
|
let latestManifest = latest.manifest
|
|
1429
1437
|
let latestIsLive = false
|
|
1430
|
-
if (targetTurn > latest.turn &&
|
|
1431
|
-
const live = this.buildLiveManifest(
|
|
1438
|
+
if (targetTurn > latest.turn && snapCwd) {
|
|
1439
|
+
const live = this.buildLiveManifest(snapCwd, latest.manifest)
|
|
1432
1440
|
if (live) {
|
|
1433
1441
|
latestManifest = live
|
|
1434
1442
|
latestIsLive = true
|