prjct-cli 0.10.14 → 0.11.1
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/CHANGELOG.md +19 -0
- package/bin/dev.js +217 -0
- package/bin/prjct +10 -0
- package/bin/serve.js +78 -0
- package/core/bus/index.js +322 -0
- package/core/command-registry.js +65 -0
- package/core/domain/snapshot-manager.js +375 -0
- package/core/plugin/hooks.js +313 -0
- package/core/plugin/index.js +52 -0
- package/core/plugin/loader.js +331 -0
- package/core/plugin/registry.js +325 -0
- package/core/plugins/webhook.js +143 -0
- package/core/session/index.js +449 -0
- package/core/session/metrics.js +293 -0
- package/package.json +28 -4
- package/packages/shared/dist/index.d.ts +615 -0
- package/packages/shared/dist/index.js +204 -0
- package/packages/shared/package.json +29 -0
- package/packages/shared/src/index.ts +9 -0
- package/packages/shared/src/schemas.ts +124 -0
- package/packages/shared/src/types.ts +187 -0
- package/packages/shared/src/utils.ts +148 -0
- package/packages/shared/tsconfig.json +18 -0
- package/packages/web/README.md +36 -0
- package/packages/web/app/api/claude/sessions/route.ts +44 -0
- package/packages/web/app/api/claude/status/route.ts +34 -0
- package/packages/web/app/api/projects/[id]/delete/route.ts +21 -0
- package/packages/web/app/api/projects/[id]/icon/route.ts +33 -0
- package/packages/web/app/api/projects/[id]/route.ts +29 -0
- package/packages/web/app/api/projects/[id]/stats/route.ts +36 -0
- package/packages/web/app/api/projects/[id]/status/route.ts +21 -0
- package/packages/web/app/api/projects/route.ts +16 -0
- package/packages/web/app/api/sessions/history/route.ts +122 -0
- package/packages/web/app/api/stats/route.ts +38 -0
- package/packages/web/app/error.tsx +34 -0
- package/packages/web/app/favicon.ico +0 -0
- package/packages/web/app/globals.css +155 -0
- package/packages/web/app/layout.tsx +43 -0
- package/packages/web/app/loading.tsx +7 -0
- package/packages/web/app/not-found.tsx +25 -0
- package/packages/web/app/page.tsx +227 -0
- package/packages/web/app/project/[id]/error.tsx +41 -0
- package/packages/web/app/project/[id]/loading.tsx +9 -0
- package/packages/web/app/project/[id]/not-found.tsx +27 -0
- package/packages/web/app/project/[id]/page.tsx +253 -0
- package/packages/web/app/project/[id]/stats/page.tsx +447 -0
- package/packages/web/app/sessions/page.tsx +165 -0
- package/packages/web/app/settings/page.tsx +150 -0
- package/packages/web/components/AppSidebar.tsx +113 -0
- package/packages/web/components/CommandButton.tsx +39 -0
- package/packages/web/components/ConnectionStatus.tsx +29 -0
- package/packages/web/components/Logo.tsx +65 -0
- package/packages/web/components/MarkdownContent.tsx +123 -0
- package/packages/web/components/ProjectAvatar.tsx +54 -0
- package/packages/web/components/TechStackBadges.tsx +20 -0
- package/packages/web/components/TerminalTab.tsx +84 -0
- package/packages/web/components/TerminalTabs.tsx +210 -0
- package/packages/web/components/charts/SessionsChart.tsx +172 -0
- package/packages/web/components/providers.tsx +45 -0
- package/packages/web/components/ui/alert-dialog.tsx +157 -0
- package/packages/web/components/ui/badge.tsx +46 -0
- package/packages/web/components/ui/button.tsx +60 -0
- package/packages/web/components/ui/card.tsx +92 -0
- package/packages/web/components/ui/chart.tsx +385 -0
- package/packages/web/components/ui/dropdown-menu.tsx +257 -0
- package/packages/web/components/ui/scroll-area.tsx +58 -0
- package/packages/web/components/ui/sheet.tsx +139 -0
- package/packages/web/components/ui/tabs.tsx +66 -0
- package/packages/web/components/ui/tooltip.tsx +61 -0
- package/packages/web/components.json +22 -0
- package/packages/web/context/TerminalContext.tsx +45 -0
- package/packages/web/context/TerminalTabsContext.tsx +136 -0
- package/packages/web/eslint.config.mjs +18 -0
- package/packages/web/hooks/useClaudeTerminal.ts +375 -0
- package/packages/web/hooks/useProjectStats.ts +38 -0
- package/packages/web/hooks/useProjects.ts +73 -0
- package/packages/web/hooks/useStats.ts +28 -0
- package/packages/web/lib/format.ts +23 -0
- package/packages/web/lib/parse-prjct-files.ts +1122 -0
- package/packages/web/lib/projects.ts +452 -0
- package/packages/web/lib/pty.ts +101 -0
- package/packages/web/lib/query-config.ts +44 -0
- package/packages/web/lib/utils.ts +6 -0
- package/packages/web/next-env.d.ts +6 -0
- package/packages/web/next.config.ts +7 -0
- package/packages/web/package.json +53 -0
- package/packages/web/postcss.config.mjs +7 -0
- package/packages/web/public/file.svg +1 -0
- package/packages/web/public/globe.svg +1 -0
- package/packages/web/public/next.svg +1 -0
- package/packages/web/public/vercel.svg +1 -0
- package/packages/web/public/window.svg +1 -0
- package/packages/web/server.ts +262 -0
- package/packages/web/tsconfig.json +34 -0
- package/templates/commands/done.md +176 -54
- package/templates/commands/history.md +176 -0
- package/templates/commands/init.md +28 -1
- package/templates/commands/now.md +191 -9
- package/templates/commands/pause.md +176 -12
- package/templates/commands/redo.md +142 -0
- package/templates/commands/resume.md +166 -62
- package/templates/commands/serve.md +121 -0
- package/templates/commands/ship.md +45 -1
- package/templates/commands/sync.md +34 -1
- package/templates/commands/undo.md +152 -0
package/core/command-registry.js
CHANGED
|
@@ -427,6 +427,71 @@ const COMMANDS = [
|
|
|
427
427
|
isOptional: true,
|
|
428
428
|
},
|
|
429
429
|
|
|
430
|
+
// ===== SNAPSHOT COMMANDS (Undo/Redo Support) =====
|
|
431
|
+
{
|
|
432
|
+
name: 'undo',
|
|
433
|
+
category: 'optional',
|
|
434
|
+
description: 'Revert to previous snapshot',
|
|
435
|
+
usage: {
|
|
436
|
+
claude: '/p:undo',
|
|
437
|
+
terminal: 'prjct undo',
|
|
438
|
+
},
|
|
439
|
+
params: null,
|
|
440
|
+
implemented: true,
|
|
441
|
+
hasTemplate: true,
|
|
442
|
+
icon: 'RotateCcw',
|
|
443
|
+
requiresInit: true,
|
|
444
|
+
blockingRules: null,
|
|
445
|
+
isOptional: true,
|
|
446
|
+
features: [
|
|
447
|
+
'Git-based snapshots',
|
|
448
|
+
'Preserves redo history',
|
|
449
|
+
'Non-destructive',
|
|
450
|
+
],
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
name: 'redo',
|
|
454
|
+
category: 'optional',
|
|
455
|
+
description: 'Redo previously undone changes',
|
|
456
|
+
usage: {
|
|
457
|
+
claude: '/p:redo',
|
|
458
|
+
terminal: 'prjct redo',
|
|
459
|
+
},
|
|
460
|
+
params: null,
|
|
461
|
+
implemented: true,
|
|
462
|
+
hasTemplate: true,
|
|
463
|
+
icon: 'RotateCw',
|
|
464
|
+
requiresInit: true,
|
|
465
|
+
blockingRules: null,
|
|
466
|
+
isOptional: true,
|
|
467
|
+
features: [
|
|
468
|
+
'Only available after undo',
|
|
469
|
+
'Restores undone state',
|
|
470
|
+
'Clears on new snapshot',
|
|
471
|
+
],
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
name: 'history',
|
|
475
|
+
category: 'optional',
|
|
476
|
+
description: 'View snapshot history',
|
|
477
|
+
usage: {
|
|
478
|
+
claude: '/p:history',
|
|
479
|
+
terminal: 'prjct history',
|
|
480
|
+
},
|
|
481
|
+
params: null,
|
|
482
|
+
implemented: true,
|
|
483
|
+
hasTemplate: true,
|
|
484
|
+
icon: 'Clock',
|
|
485
|
+
requiresInit: true,
|
|
486
|
+
blockingRules: null,
|
|
487
|
+
isOptional: true,
|
|
488
|
+
features: [
|
|
489
|
+
'Shows all snapshots',
|
|
490
|
+
'Current position indicator',
|
|
491
|
+
'Redo availability count',
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
|
|
430
495
|
// ===== SETUP COMMANDS (Not part of daily workflow) =====
|
|
431
496
|
{
|
|
432
497
|
name: 'start',
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SnapshotManager - Git-based Undo/Redo System
|
|
3
|
+
*
|
|
4
|
+
* Uses Git internally to track file changes and enable undo/redo.
|
|
5
|
+
* Inspired by OpenCode's snapshot system.
|
|
6
|
+
*
|
|
7
|
+
* Storage: ~/.prjct-cli/projects/{projectId}/snapshots/
|
|
8
|
+
*
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs').promises
|
|
13
|
+
const path = require('path')
|
|
14
|
+
const { exec } = require('child_process')
|
|
15
|
+
const { promisify } = require('util')
|
|
16
|
+
const pathManager = require('../infrastructure/path-manager')
|
|
17
|
+
const configManager = require('../infrastructure/config-manager')
|
|
18
|
+
const { emit } = require('../bus')
|
|
19
|
+
|
|
20
|
+
const execAsync = promisify(exec)
|
|
21
|
+
|
|
22
|
+
class SnapshotManager {
|
|
23
|
+
constructor(projectPath) {
|
|
24
|
+
this.projectPath = projectPath
|
|
25
|
+
this.projectId = null
|
|
26
|
+
this.snapshotDir = null
|
|
27
|
+
this.initialized = false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize snapshot system for project
|
|
32
|
+
*/
|
|
33
|
+
async initialize() {
|
|
34
|
+
this.projectId = await configManager.getProjectId(this.projectPath)
|
|
35
|
+
if (!this.projectId) {
|
|
36
|
+
throw new Error('No prjct project found. Run /p:init first.')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Snapshots live in global storage
|
|
40
|
+
const globalPath = pathManager.getGlobalProjectPath(this.projectId)
|
|
41
|
+
this.snapshotDir = path.join(globalPath, 'snapshots')
|
|
42
|
+
|
|
43
|
+
// Ensure directory exists
|
|
44
|
+
await fs.mkdir(this.snapshotDir, { recursive: true })
|
|
45
|
+
|
|
46
|
+
// Initialize bare git repo if not exists
|
|
47
|
+
const gitDir = path.join(this.snapshotDir, '.git')
|
|
48
|
+
try {
|
|
49
|
+
await fs.access(gitDir)
|
|
50
|
+
} catch {
|
|
51
|
+
await this.initGitRepo()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.initialized = true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Initialize internal Git repository
|
|
59
|
+
*/
|
|
60
|
+
async initGitRepo() {
|
|
61
|
+
const gitDir = path.join(this.snapshotDir, '.git')
|
|
62
|
+
|
|
63
|
+
// Create bare-ish repo structure
|
|
64
|
+
await execAsync(`git init "${this.snapshotDir}"`, { cwd: this.projectPath })
|
|
65
|
+
|
|
66
|
+
// Configure for snapshot use
|
|
67
|
+
await execAsync(`git config user.email "prjct@local"`, { cwd: this.snapshotDir })
|
|
68
|
+
await execAsync(`git config user.name "prjct-snapshots"`, { cwd: this.snapshotDir })
|
|
69
|
+
|
|
70
|
+
// Create initial empty commit
|
|
71
|
+
await execAsync(`git commit --allow-empty -m "init: snapshot system"`, { cwd: this.snapshotDir })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create a snapshot of current project state
|
|
76
|
+
*
|
|
77
|
+
* @param {string} message - Snapshot description
|
|
78
|
+
* @param {string[]} files - Specific files to track (optional, defaults to all changed)
|
|
79
|
+
* @returns {Promise<Object>} Snapshot info {hash, message, timestamp, files}
|
|
80
|
+
*/
|
|
81
|
+
async create(message, files = null) {
|
|
82
|
+
if (!this.initialized) await this.initialize()
|
|
83
|
+
|
|
84
|
+
const timestamp = new Date().toISOString()
|
|
85
|
+
|
|
86
|
+
// Copy changed files to snapshot directory
|
|
87
|
+
const changedFiles = files || await this.getChangedFiles()
|
|
88
|
+
|
|
89
|
+
if (changedFiles.length === 0) {
|
|
90
|
+
return {
|
|
91
|
+
hash: null,
|
|
92
|
+
message: 'No changes to snapshot',
|
|
93
|
+
timestamp,
|
|
94
|
+
files: []
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Copy files to snapshot dir maintaining structure
|
|
99
|
+
for (const file of changedFiles) {
|
|
100
|
+
const srcPath = path.join(this.projectPath, file)
|
|
101
|
+
const destPath = path.join(this.snapshotDir, file)
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const content = await fs.readFile(srcPath, 'utf-8')
|
|
105
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true })
|
|
106
|
+
await fs.writeFile(destPath, content)
|
|
107
|
+
} catch (err) {
|
|
108
|
+
// File might be deleted, mark for removal
|
|
109
|
+
try {
|
|
110
|
+
await fs.unlink(destPath)
|
|
111
|
+
} catch {}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Stage and commit in snapshot repo
|
|
116
|
+
await execAsync(`git add -A`, { cwd: this.snapshotDir })
|
|
117
|
+
|
|
118
|
+
const commitMsg = `${message}\n\nFiles: ${changedFiles.length}\nTimestamp: ${timestamp}`
|
|
119
|
+
await execAsync(`git commit -m "${commitMsg.replace(/"/g, '\\"')}"`, { cwd: this.snapshotDir })
|
|
120
|
+
|
|
121
|
+
// Get commit hash
|
|
122
|
+
const { stdout } = await execAsync(`git rev-parse HEAD`, { cwd: this.snapshotDir })
|
|
123
|
+
const hash = stdout.trim()
|
|
124
|
+
|
|
125
|
+
// Log to manifest
|
|
126
|
+
await this.logSnapshot({
|
|
127
|
+
hash,
|
|
128
|
+
message,
|
|
129
|
+
timestamp,
|
|
130
|
+
files: changedFiles
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Emit event for plugins
|
|
134
|
+
await emit.snapshotCreated({
|
|
135
|
+
hash,
|
|
136
|
+
message,
|
|
137
|
+
timestamp,
|
|
138
|
+
filesCount: changedFiles.length,
|
|
139
|
+
projectId: this.projectId
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
return { hash, message, timestamp, files: changedFiles }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get list of changed files in project
|
|
147
|
+
*/
|
|
148
|
+
async getChangedFiles() {
|
|
149
|
+
try {
|
|
150
|
+
const { stdout } = await execAsync(
|
|
151
|
+
`git status --porcelain`,
|
|
152
|
+
{ cwd: this.projectPath }
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
return stdout
|
|
156
|
+
.split('\n')
|
|
157
|
+
.filter(Boolean)
|
|
158
|
+
.map(line => line.slice(3).trim())
|
|
159
|
+
.filter(file => !file.startsWith('.prjct/'))
|
|
160
|
+
} catch {
|
|
161
|
+
return []
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* List all snapshots
|
|
167
|
+
*
|
|
168
|
+
* @param {number} limit - Max snapshots to return
|
|
169
|
+
* @returns {Promise<Array>} List of snapshots
|
|
170
|
+
*/
|
|
171
|
+
async list(limit = 10) {
|
|
172
|
+
if (!this.initialized) await this.initialize()
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
const { stdout } = await execAsync(
|
|
176
|
+
`git log --pretty=format:'{"hash":"%H","short":"%h","message":"%s","date":"%ai"}' -n ${limit}`,
|
|
177
|
+
{ cwd: this.snapshotDir }
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
return stdout
|
|
181
|
+
.split('\n')
|
|
182
|
+
.filter(Boolean)
|
|
183
|
+
.map(line => {
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(line)
|
|
186
|
+
} catch {
|
|
187
|
+
return null
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
.filter(Boolean)
|
|
191
|
+
} catch {
|
|
192
|
+
return []
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Restore project to a specific snapshot
|
|
198
|
+
*
|
|
199
|
+
* @param {string} hash - Commit hash to restore
|
|
200
|
+
* @returns {Promise<Object>} Restore result
|
|
201
|
+
*/
|
|
202
|
+
async restore(hash) {
|
|
203
|
+
if (!this.initialized) await this.initialize()
|
|
204
|
+
|
|
205
|
+
// Get files changed in that commit
|
|
206
|
+
const { stdout: filesOutput } = await execAsync(
|
|
207
|
+
`git diff-tree --no-commit-id --name-only -r ${hash}`,
|
|
208
|
+
{ cwd: this.snapshotDir }
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
const files = filesOutput.split('\n').filter(Boolean)
|
|
212
|
+
|
|
213
|
+
// Checkout files from that snapshot
|
|
214
|
+
await execAsync(`git checkout ${hash} -- .`, { cwd: this.snapshotDir })
|
|
215
|
+
|
|
216
|
+
// Copy files back to project
|
|
217
|
+
for (const file of files) {
|
|
218
|
+
const srcPath = path.join(this.snapshotDir, file)
|
|
219
|
+
const destPath = path.join(this.projectPath, file)
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
const content = await fs.readFile(srcPath, 'utf-8')
|
|
223
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true })
|
|
224
|
+
await fs.writeFile(destPath, content)
|
|
225
|
+
} catch (err) {
|
|
226
|
+
// File doesn't exist in snapshot, might need to delete from project
|
|
227
|
+
try {
|
|
228
|
+
await fs.unlink(destPath)
|
|
229
|
+
} catch {}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Log restoration
|
|
234
|
+
await this.logRestore(hash, files)
|
|
235
|
+
|
|
236
|
+
const timestamp = new Date().toISOString()
|
|
237
|
+
|
|
238
|
+
// Emit event for plugins
|
|
239
|
+
await emit.snapshotRestored({
|
|
240
|
+
hash,
|
|
241
|
+
filesCount: files.length,
|
|
242
|
+
timestamp,
|
|
243
|
+
projectId: this.projectId
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
return { hash, files, timestamp }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get diff between current state and a snapshot
|
|
251
|
+
*
|
|
252
|
+
* @param {string} hash - Snapshot hash to compare
|
|
253
|
+
* @returns {Promise<string>} Diff output
|
|
254
|
+
*/
|
|
255
|
+
async diff(hash) {
|
|
256
|
+
if (!this.initialized) await this.initialize()
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
const { stdout } = await execAsync(
|
|
260
|
+
`git diff ${hash} --stat`,
|
|
261
|
+
{ cwd: this.snapshotDir }
|
|
262
|
+
)
|
|
263
|
+
return stdout
|
|
264
|
+
} catch {
|
|
265
|
+
return ''
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get the most recent snapshot hash
|
|
271
|
+
*/
|
|
272
|
+
async getLatestHash() {
|
|
273
|
+
if (!this.initialized) await this.initialize()
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
const { stdout } = await execAsync(
|
|
277
|
+
`git rev-parse HEAD`,
|
|
278
|
+
{ cwd: this.snapshotDir }
|
|
279
|
+
)
|
|
280
|
+
return stdout.trim()
|
|
281
|
+
} catch {
|
|
282
|
+
return null
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Get the hash before the current one (for undo)
|
|
288
|
+
*/
|
|
289
|
+
async getPreviousHash() {
|
|
290
|
+
if (!this.initialized) await this.initialize()
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
const { stdout } = await execAsync(
|
|
294
|
+
`git rev-parse HEAD~1`,
|
|
295
|
+
{ cwd: this.snapshotDir }
|
|
296
|
+
)
|
|
297
|
+
return stdout.trim()
|
|
298
|
+
} catch {
|
|
299
|
+
return null
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Log snapshot to manifest
|
|
305
|
+
*/
|
|
306
|
+
async logSnapshot(snapshot) {
|
|
307
|
+
const manifestPath = path.join(this.snapshotDir, 'manifest.jsonl')
|
|
308
|
+
const entry = JSON.stringify({
|
|
309
|
+
type: 'snapshot',
|
|
310
|
+
...snapshot
|
|
311
|
+
}) + '\n'
|
|
312
|
+
|
|
313
|
+
await fs.appendFile(manifestPath, entry)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Log restoration to manifest
|
|
318
|
+
*/
|
|
319
|
+
async logRestore(hash, files) {
|
|
320
|
+
const manifestPath = path.join(this.snapshotDir, 'manifest.jsonl')
|
|
321
|
+
const entry = JSON.stringify({
|
|
322
|
+
type: 'restore',
|
|
323
|
+
hash,
|
|
324
|
+
files,
|
|
325
|
+
timestamp: new Date().toISOString()
|
|
326
|
+
}) + '\n'
|
|
327
|
+
|
|
328
|
+
await fs.appendFile(manifestPath, entry)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Get redo stack (snapshots after current position)
|
|
333
|
+
* This tracks undone snapshots that can be redone
|
|
334
|
+
*/
|
|
335
|
+
async getRedoStack() {
|
|
336
|
+
const stackPath = path.join(this.snapshotDir, 'redo-stack.json')
|
|
337
|
+
try {
|
|
338
|
+
const content = await fs.readFile(stackPath, 'utf-8')
|
|
339
|
+
return JSON.parse(content)
|
|
340
|
+
} catch {
|
|
341
|
+
return []
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Push to redo stack (when undoing)
|
|
347
|
+
*/
|
|
348
|
+
async pushToRedoStack(snapshot) {
|
|
349
|
+
const stack = await this.getRedoStack()
|
|
350
|
+
stack.push(snapshot)
|
|
351
|
+
const stackPath = path.join(this.snapshotDir, 'redo-stack.json')
|
|
352
|
+
await fs.writeFile(stackPath, JSON.stringify(stack, null, 2))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Pop from redo stack (when redoing)
|
|
357
|
+
*/
|
|
358
|
+
async popFromRedoStack() {
|
|
359
|
+
const stack = await this.getRedoStack()
|
|
360
|
+
const snapshot = stack.pop()
|
|
361
|
+
const stackPath = path.join(this.snapshotDir, 'redo-stack.json')
|
|
362
|
+
await fs.writeFile(stackPath, JSON.stringify(stack, null, 2))
|
|
363
|
+
return snapshot
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Clear redo stack (when creating new snapshot after undo)
|
|
368
|
+
*/
|
|
369
|
+
async clearRedoStack() {
|
|
370
|
+
const stackPath = path.join(this.snapshotDir, 'redo-stack.json')
|
|
371
|
+
await fs.writeFile(stackPath, '[]')
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
module.exports = SnapshotManager
|