dsh-timeback 0.7.3 → 0.7.4
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 +16 -7
- package/client.js +1 -1
- package/docs/MARKET.md +2 -2
- package/package.json +1 -1
- package/src/snapshots.js +64 -20
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ desktop app):
|
|
|
104
104
|
```bash
|
|
105
105
|
# From npm (published: https://www.npmjs.com/package/dsh-timeback)
|
|
106
106
|
dsh plugin --profile web add dsh-timeback
|
|
107
|
-
dsh plugin --profile web add dsh-timeback@0.7.
|
|
107
|
+
dsh plugin --profile web add dsh-timeback@0.7.4 # pin a release
|
|
108
108
|
|
|
109
109
|
# Straight from GitHub (no npm release needed)
|
|
110
110
|
dsh plugin --profile web add github:<owner>/dsh-timeback
|
|
@@ -272,12 +272,21 @@ are `0600` inside a `0700` directory.
|
|
|
272
272
|
### Huge workspaces
|
|
273
273
|
|
|
274
274
|
Before the first snapshot of an **enabled** workspace, timeback runs
|
|
275
|
-
`git add --dry-run` to count what would be stored. More than `maxFiles` files
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
Session's working directory, then reload the plugin (config
|
|
275
|
+
`git add --dry-run` to count what would be stored. More than `maxFiles` files
|
|
276
|
+
blocks snapshots for that workspace for the life of the Host process, with the
|
|
277
|
+
reason shown in the panel. This is what stops a session whose working directory
|
|
278
|
+
is your home directory from snapshotting gigabytes by accident. Raise
|
|
279
|
+
`maxFiles`, add `exclude` patterns, use the per-workspace folder/file selection,
|
|
280
|
+
or change the Session's working directory, then reload the plugin (config
|
|
281
|
+
changes remount it).
|
|
282
|
+
|
|
283
|
+
A probe that **fails transiently** (for example a stale `probe.index.lock` left
|
|
284
|
+
by a timed-out git on Windows) is retried once, all `probe.index.lock`,
|
|
285
|
+
`index.lock` and `index.filtered.lock` files are cleared before the next
|
|
286
|
+
attempt, and the failure is reported as `snapshot/probe-failed` instead of
|
|
287
|
+
being misclassified as an oversized workspace. If snapshots still fail with a
|
|
288
|
+
lock error after reloading, remove leftover `*.lock` files under
|
|
289
|
+
`<DSH_HOME>/timeback/repos/*/` and try again.
|
|
281
290
|
|
|
282
291
|
## Model tools
|
|
283
292
|
|
package/client.js
CHANGED
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const REFRESH_MS = 3000
|
|
24
24
|
const MAX_ROWS = 240
|
|
25
25
|
/** Bump together with package.json so a stale browser bundle is obvious. */
|
|
26
|
-
const BUILD = '0.7.
|
|
26
|
+
const BUILD = '0.7.4+sticky'
|
|
27
27
|
/** Set by apply(): opens another Session in the main column. */
|
|
28
28
|
let openSessionBridge = null
|
|
29
29
|
/** Set by apply(): opens the Timeback tab in the right sidebar. */
|
package/docs/MARKET.md
CHANGED
|
@@ -78,12 +78,12 @@ dshmarket;要让所有人的 dshmarket 搜到,必须走下一节的公共目
|
|
|
78
78
|
|
|
79
79
|
## 4. npm(已发布 0.6.0)
|
|
80
80
|
|
|
81
|
-
`dsh-timeback@0.7.
|
|
81
|
+
`dsh-timeback@0.7.4` 已发布到官方 npm(<https://www.npmjs.com/package/dsh-timeback>),
|
|
82
82
|
用户可以直接安装/固定版本:
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
85
|
dsh plugin --profile web add dsh-timeback
|
|
86
|
-
dsh plugin --profile web add dsh-timeback@0.7.
|
|
86
|
+
dsh plugin --profile web add dsh-timeback@0.7.4
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
awesome 目录 CI 会从 npm 自动补充映射,之后市场安装和更新会走 registry。发布流程参考:
|
package/package.json
CHANGED
package/src/snapshots.js
CHANGED
|
@@ -216,31 +216,58 @@ export class SnapshotStore {
|
|
|
216
216
|
const cacheKey = `${repo.id}:${excludes.join('|')}`
|
|
217
217
|
const cached = this.probes.get(cacheKey)
|
|
218
218
|
if (cached) return cached
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
const probeIndex = path.join(repo.gitDir, 'probe.index')
|
|
220
|
+
const probeLock = `${probeIndex}.lock`
|
|
221
|
+
const env = { GIT_INDEX_FILE: probeIndex }
|
|
222
|
+
const isLockError = (result) =>
|
|
223
|
+
result?.exitCode !== 0 &&
|
|
224
|
+
/\.lock['"]?: File exists|Another git process seems to be running|Unable to create .*\.lock/i.test(String(result?.stderr || ''))
|
|
225
|
+
const clean = async () => {
|
|
226
|
+
await fs.rm(probeIndex, { force: true }).catch(() => {})
|
|
227
|
+
await fs.rm(probeLock, { force: true }).catch(() => {})
|
|
228
|
+
}
|
|
229
|
+
const run = async () => {
|
|
222
230
|
const pathspecs = selectionPathspecs(excludes)
|
|
223
|
-
|
|
231
|
+
return this.git(repo, ['--work-tree', repo.cwd, 'add', '-A', '--ignore-errors', '--dry-run', '--', ...(pathspecs ?? ['.'])], {
|
|
224
232
|
env,
|
|
225
233
|
signal,
|
|
226
234
|
timeoutMs: this.probeTimeoutMs,
|
|
227
235
|
maxBytes: 2 * 1024 * 1024,
|
|
228
236
|
})
|
|
237
|
+
}
|
|
238
|
+
let verdict
|
|
239
|
+
try {
|
|
240
|
+
await clean()
|
|
241
|
+
let dryRun = await run()
|
|
242
|
+
// On Windows a timed-out/killed git can leave probe.index.lock behind;
|
|
243
|
+
// clear it and retry once instead of blaming the workspace size.
|
|
244
|
+
if (isLockError(dryRun)) {
|
|
245
|
+
await clean()
|
|
246
|
+
await new Promise((resolve) => setTimeout(resolve, 250))
|
|
247
|
+
dryRun = await run()
|
|
248
|
+
}
|
|
229
249
|
const lines = dryRun.stdout === '' ? 0 : dryRun.stdout.split('\n').filter((line) => line !== '').length
|
|
230
250
|
if (dryRun.truncated || lines > this.maxFiles) {
|
|
231
|
-
verdict = { ok: false, files: dryRun.truncated ? -1 : lines, reason: 'workspace-too-large' }
|
|
251
|
+
verdict = { ok: false, tooLarge: true, files: dryRun.truncated ? -1 : lines, reason: 'workspace-too-large' }
|
|
252
|
+
} else if (isLockError(dryRun)) {
|
|
253
|
+
verdict = { ok: false, code: 'probe-failed', reason: `git lock is stuck: ${dryRun.stderr.trim().slice(0, 200)}` }
|
|
232
254
|
} else if (dryRun.exitCode !== 0 && dryRun.exitCode !== 1) {
|
|
233
|
-
verdict = { ok: false,
|
|
255
|
+
verdict = { ok: false, code: 'probe-failed', reason: dryRun.stderr.trim().slice(0, 200) || `git exit ${dryRun.exitCode}` }
|
|
234
256
|
} else {
|
|
235
257
|
verdict = { ok: true }
|
|
236
258
|
}
|
|
237
259
|
} catch (error) {
|
|
238
|
-
|
|
260
|
+
const message = String(error?.message ?? error)
|
|
261
|
+
verdict = {
|
|
262
|
+
ok: false,
|
|
263
|
+
code: /timed? ?out|timeout/i.test(message) ? 'probe-timeout' : 'probe-failed',
|
|
264
|
+
reason: message,
|
|
265
|
+
}
|
|
239
266
|
} finally {
|
|
240
|
-
await
|
|
267
|
+
await clean()
|
|
241
268
|
}
|
|
242
269
|
this.probes.set(cacheKey, verdict)
|
|
243
|
-
if (!verdict.ok && excludes.length === 0) {
|
|
270
|
+
if (!verdict.ok && verdict.tooLarge && excludes.length === 0) {
|
|
244
271
|
this.blocked.set(repo.cwd, verdict)
|
|
245
272
|
this.logger?.warn?.(
|
|
246
273
|
`timeback: refusing to snapshot ${repo.cwd}: ${verdict.reason}` +
|
|
@@ -256,14 +283,18 @@ export class SnapshotStore {
|
|
|
256
283
|
return this.runner.run(['--git-dir', repo.gitDir, ...args], options)
|
|
257
284
|
}
|
|
258
285
|
|
|
259
|
-
/**
|
|
260
|
-
|
|
261
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Remove a lock file left behind by a killed/timed-out git process. All
|
|
288
|
+
* private-repository operations are serialized by `exclusive()`, so a lock in
|
|
289
|
+
* our own data directory cannot belong to a live timeback operation; on
|
|
290
|
+
* Windows git sometimes leaves it after a timeout and every later snapshot
|
|
291
|
+
* would fail forever with "Another git process seems to be running".
|
|
292
|
+
*/
|
|
293
|
+
async clearStaleLock(gitDir, name = 'index.lock') {
|
|
262
294
|
try {
|
|
263
|
-
|
|
264
|
-
if (Date.now() - stat.mtimeMs > 5 * 60_000) await fs.rm(lock, { force: true })
|
|
295
|
+
await fs.rm(path.join(gitDir, name), { force: true })
|
|
265
296
|
} catch {
|
|
266
|
-
// No lock present.
|
|
297
|
+
// No lock present / not removable.
|
|
267
298
|
}
|
|
268
299
|
}
|
|
269
300
|
|
|
@@ -279,7 +310,10 @@ export class SnapshotStore {
|
|
|
279
310
|
// A selection needs a fresh index, otherwise files outside the selection
|
|
280
311
|
// would survive from the previous full capture.
|
|
281
312
|
const indexPath = pathspecs ? path.join(repo.gitDir, 'index.filtered') : path.join(repo.gitDir, 'index')
|
|
282
|
-
if (pathspecs)
|
|
313
|
+
if (pathspecs) {
|
|
314
|
+
await fs.rm(indexPath, { force: true })
|
|
315
|
+
await this.clearStaleLock(repo.gitDir, 'index.filtered.lock')
|
|
316
|
+
}
|
|
283
317
|
const env = { GIT_INDEX_FILE: indexPath }
|
|
284
318
|
try {
|
|
285
319
|
const args = ['--work-tree', repo.cwd, 'add', '-A', '--ignore-errors']
|
|
@@ -296,7 +330,10 @@ export class SnapshotStore {
|
|
|
296
330
|
if (!/^[0-9a-f]{40,64}$/.test(tree)) throw new SnapshotError('快照失败:git 返回了无效的 tree id', 'snapshot/tree-invalid')
|
|
297
331
|
return tree
|
|
298
332
|
} finally {
|
|
299
|
-
if (pathspecs)
|
|
333
|
+
if (pathspecs) {
|
|
334
|
+
await fs.rm(indexPath, { force: true }).catch(() => {})
|
|
335
|
+
await this.clearStaleLock(repo.gitDir, 'index.filtered.lock')
|
|
336
|
+
}
|
|
300
337
|
}
|
|
301
338
|
}
|
|
302
339
|
|
|
@@ -320,10 +357,17 @@ export class SnapshotStore {
|
|
|
320
357
|
}
|
|
321
358
|
const probe = await this.probeWorkspace(repo, options.signal, excludePaths)
|
|
322
359
|
if (!probe.ok) {
|
|
360
|
+
if (probe.tooLarge || probe.reason === 'workspace-too-large') {
|
|
361
|
+
throw new SnapshotError(
|
|
362
|
+
`工作区过大,未创建文件快照(${probe.reason})。可在插件配置里提高 maxFiles 或添加 exclude 规则。`,
|
|
363
|
+
'snapshot/workspace-too-large',
|
|
364
|
+
{ files: probe.files ?? null, maxFiles: this.maxFiles },
|
|
365
|
+
)
|
|
366
|
+
}
|
|
323
367
|
throw new SnapshotError(
|
|
324
|
-
|
|
325
|
-
'snapshot/
|
|
326
|
-
{
|
|
368
|
+
`快照前检查失败(${probe.reason})。请重试;如果反复出现,请清理 dataDir/repos 下的 *.lock 文件。`,
|
|
369
|
+
'snapshot/probe-failed',
|
|
370
|
+
{ reason: probe.reason, maxFiles: this.maxFiles },
|
|
327
371
|
)
|
|
328
372
|
}
|
|
329
373
|
const tree = await this.treeOfHead(repo, options.signal, excludePaths)
|