dsh-message-rewind 1.2.3 → 1.2.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.en.md CHANGED
@@ -64,7 +64,7 @@ If you prefer editing the profile yourself, the manual route is the same three s
64
64
  ```json
65
65
  {
66
66
  "dependencies": {
67
- "dsh-message-rewind": "^1.2.3"
67
+ "dsh-message-rewind": "^1.2.4"
68
68
  }
69
69
  }
70
70
  ```
@@ -125,10 +125,10 @@ Lost or truncated snapshots, queued prompts, and non-Git workspaces are called o
125
125
  ## FAQ
126
126
 
127
127
  **Q: Does the sidebar get an extra conversation after a rollback?**
128
- No — there is always just one conversation, and its title normally carries over. The underlying session ID does change, though: DSH session logs are append-only and have no "delete a middle chunk" API, so the plugin forks a truncated branch, archives the original out of the sidebar, and deletes its log directory. If you referenced that session ID elsewhere, fetch it again. When the first message is deleted, the replacement is a new conversation that has not been titled yet, so it may show the default title.
128
+ No — there is always just one conversation, and its title normally carries over. The underlying session ID does change, though: DSH session logs are append-only and have no "delete a middle chunk" API, so the plugin forks a truncated branch, removes the original from the sidebar, and deletes its log directory directly; the normal path writes no archive entry. Repeated edits therefore do not pile up same-titled archive entries. If you referenced that session ID elsewhere, fetch it again. When the first message is deleted, the replacement is a new conversation that has not been titled yet, so it may show the default title.
129
129
 
130
130
  **Q: Can the original record be recovered?**
131
- Normally it is deleted. Only when its log directory is still held open and cannot be removed does the original stay in the archive.
131
+ Normally it is deleted outright and never reaches the archive. Only when the live session cannot be detached, or its log directory is still held open and cannot be removed, does the plugin fall back to archiving it; the log is not silently lost.
132
132
 
133
133
  **Q: Why can't messages with attachments be edited?**
134
134
  Attachments are stored as part of the message content, and editing only supports plain-text messages. Messages with attachments can still be deleted.
package/README.md CHANGED
@@ -66,7 +66,7 @@ dsh plugin --profile web add dsh-message-rewind
66
66
  ```json
67
67
  {
68
68
  "dependencies": {
69
- "dsh-message-rewind": "^1.2.3"
69
+ "dsh-message-rewind": "^1.2.4"
70
70
  }
71
71
  }
72
72
  ```
@@ -127,10 +127,10 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
127
127
  ## 常见问题
128
128
 
129
129
  **Q:回滚之后,侧边栏是不是会多出一条对话?**
130
- 不会,始终只有一条对话(标题通常沿用原会话)。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话移出侧边栏并删除其日志目录。所以如果你在别处引用过这个会话 ID,需要重新取一次。删除的是第一条消息时,替换出来的新会话还没有标题,可能先显示默认标题。
130
+ 不会,始终只有一条对话(标题通常沿用原会话)。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话从侧边栏摘掉并直接删除其日志目录;正常路径不写入归档。所以反复编辑/删除不会在归档里堆出同名会话;如果你在别处引用过这个会话 ID,需要重新取一次。删除的是第一条消息时,替换出来的新会话还没有标题,可能先显示默认标题。
131
131
 
132
132
  **Q:原会话的记录还能找回吗?**
133
- 正常情况下会被删除。只有当日志目录被占用删不掉时,原会话会保留在归档里。
133
+ 正常情况下会被直接删除,不进入归档。只有当运行中的原会话摘不掉,或日志目录被占用、删不掉时,才会退回归档兜底;失败也不会静默丢日志。
134
134
 
135
135
  **Q:为什么带附件的消息不能编辑?**
136
136
  附件是作为消息内容的一部分存下来的,编辑只支持纯文本消息。带附件的消息可以删除。
package/client.js CHANGED
@@ -457,7 +457,7 @@ window.__ModuleLoader__.load({
457
457
  .then(() => new Promise((resolveDelay) => window.setTimeout(resolveDelay, 200)))
458
458
  .then(() => remote('purge', { sessionId: source }, typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(REQUEST_TIMEOUT) : undefined))
459
459
  .then((outcome) => {
460
- if (!outcome || outcome.removed !== true) console.warn('[message-rewind] source session kept in archive:', outcome?.message ?? 'log not deleted');
460
+ if (!outcome || outcome.removed !== true) console.warn('[message-rewind] source session not fully removed:', outcome?.message ?? 'log not deleted');
461
461
  })
462
462
  .catch((error) => { console.warn('[message-rewind] purge failed:', error instanceof Error ? error.message : String(error)); });
463
463
  }
package/index.js CHANGED
@@ -259,43 +259,123 @@ export function apply(ctx) {
259
259
  }
260
260
 
261
261
  /**
262
- * Remove a rolled-back source session for good. The harness keeps session logs
263
- * append-only and offers no delete API, so this retires the artifact instead:
264
- * archive it out of the sidebar, delete its directory, and report whether the
265
- * bytes are gone.
266
- *
267
- * The archive only cancels the running turn — the Agent stays in the session
268
- * store for this Host's lifetime — so waiting for `sessions.get()` to clear
269
- * would never finish. Deletion is attempted directly and its outcome is
270
- * reported, with liveness used only to explain a failure.
262
+ * Detach one live source Session. The store's disposal event closes its
263
+ * persistence writer and makes the harness publish `api-session/removed`, so
264
+ * the log can be deleted after the write handle is gone.
265
+ * @param sessionId - session to detach.
266
+ * @returns true when a live session was detached, false when it was cold.
267
+ * @throws when a live session is still attached afterwards.
271
268
  */
272
- async function purge(sessionId) {
269
+ async function detachSession(sessionId) {
270
+ const sessions = ctx.get('sessions');
271
+ const live = sessions?.get?.(sessionId);
272
+ if (live === undefined) return false;
273
+ // Archive used to stop queued work before hiding the session; keep that
274
+ // stop without writing an archive entry.
275
+ try { await ctx.parallel?.('workspace/session-stop', { sessionId }); } catch { /* stop is best effort */ }
276
+ try { await sessions.flush?.(live); } catch { /* the log is about to be deleted */ }
273
277
  try {
274
- await ctx.workspaceController.archiveSession({ sessionId, stopActivity: true });
278
+ const entry = sessions.liveEntryFor?.(live);
279
+ if (entry !== undefined) sessions.detachEntered?.(entry);
275
280
  } catch (error) {
276
- // Without the archive the session would stay visible after its log is gone.
277
- return { removed: false, archivedOnly: false, message: `会话归档失败,未删除任何内容:${text(error)}` };
281
+ throw new Error(`会话仍在本进程中运行,无法移除:${text(error)}`);
282
+ }
283
+ if (sessions.get?.(sessionId) !== undefined) throw new Error('会话仍在本进程中运行,无法移除。');
284
+ return true;
285
+ }
286
+
287
+ /**
288
+ * Drop the traces a deleted source session leaves outside its log: the
289
+ * archived/pinned registry flags, workspace accounting, and projection cache.
290
+ * @param sessionId - deleted session.
291
+ * @param detachedLive - whether {@link detachSession} already published its removal.
292
+ */
293
+ async function cleanupSession(sessionId, detachedLive) {
294
+ if (!detachedLive) {
295
+ try { ctx.emit?.('api-session/removed', sessionId); } catch { /* client refresh is the fallback */ }
296
+ }
297
+ const registry = ctx.get('workspaceRegistry');
298
+ try {
299
+ if (registry?.archivedSessionIds?.includes?.(sessionId) === true) {
300
+ await ctx.workspaceController.unarchiveSession({ sessionId });
301
+ }
302
+ } catch {
303
+ /* a stale archive id is cleaned up by the harness/archive surfaces */
304
+ }
305
+ try {
306
+ if (registry?.pinnedSessionIds?.includes?.(sessionId) === true) {
307
+ await ctx.workspaceController.unpinSession({ sessionId });
308
+ }
309
+ } catch {
310
+ /* a stale pin never renders a row without a session */
311
+ }
312
+ try {
313
+ const table = ctx.get('sessionProjectionCache')?.requireTable?.();
314
+ if (table !== undefined) await table.delete(sessionId);
315
+ } catch {
316
+ /* the projection cache is a fold shortcut, not an authority */
278
317
  }
318
+ try {
319
+ for (const workspace of registry?.list?.() ?? []) {
320
+ if (typeof workspace.detachSession === 'function') await workspace.detachSession(sessionId);
321
+ }
322
+ } catch {
323
+ /* stale accounting never shows a row without a live or persisted session */
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Remove a rolled-back source session for good. The harness keeps session logs
329
+ * append-only and offers no delete API, so this retires the artifact itself:
330
+ * detach the live Session, delete its directory, and drop its archive flag /
331
+ * workspace accounting / projection cache. The normal path never archives, so
332
+ * repeated rewinds cannot fill the archive with copies of one conversation.
333
+ */
334
+ async function purge(sessionId) {
279
335
  const directory = await sessionDirectory(SESSIONS_ROOT, sessionId);
280
- if (directory === undefined) return { removed: false, archivedOnly: false, message: '未找到会话日志目录,未删除任何内容。' };
281
- const live = ctx.get('sessions')?.get(sessionId) !== undefined;
336
+ let detachedLive = false;
337
+ if (directory === undefined) {
338
+ // A log another surface already removed still needs its row cleaned up.
339
+ try { detachedLive = await detachSession(sessionId); } catch { /* remove the row below */ }
340
+ await cleanupSession(sessionId, detachedLive);
341
+ return { removed: false, archivedOnly: false, message: '未找到会话日志目录,未删除任何内容。' };
342
+ }
343
+ if (ctx.get('sessions')?.get?.(sessionId) !== undefined) {
344
+ try {
345
+ detachedLive = await detachSession(sessionId);
346
+ } catch (error) {
347
+ // Leaving a live session with its log is better than deleting the log
348
+ // out from under it; hide the row with the old archive fallback.
349
+ try {
350
+ await ctx.workspaceController.archiveSession({ sessionId, stopActivity: true });
351
+ return { removed: false, archivedOnly: true, message: `${text(error)},已移出侧边栏` };
352
+ } catch (archiveError) {
353
+ return { removed: false, archivedOnly: false, message: `${text(error)};${text(archiveError)}` };
354
+ }
355
+ }
356
+ }
282
357
  let failure;
283
358
  for (let attempt = 0; attempt < 6; attempt += 1) {
284
359
  try {
285
360
  await fsp.rm(directory, { recursive: true, force: true });
286
- return { removed: true, archivedOnly: false };
361
+ failure = undefined;
362
+ break;
287
363
  } catch (error) {
288
364
  failure = error;
289
365
  await delay(250);
290
366
  }
291
367
  }
292
- return {
293
- removed: false,
294
- archivedOnly: true,
295
- message: live
296
- ? `会话仍在本进程中运行,日志目录无法删除,已移出侧边栏:${text(failure)}`
297
- : `日志目录无法删除,已移出侧边栏:${text(failure)}`,
298
- };
368
+ if (failure !== undefined) {
369
+ // Keep the old fallback only when the bytes could not be removed.
370
+ try {
371
+ await ctx.workspaceController.archiveSession({ sessionId, stopActivity: true });
372
+ return { removed: false, archivedOnly: true, message: `日志目录无法删除,已移出侧边栏:${text(failure)}` };
373
+ } catch (archiveError) {
374
+ return { removed: false, archivedOnly: false, message: `日志目录无法删除,且未能移出侧边栏:${text(failure)};${text(archiveError)}` };
375
+ }
376
+ }
377
+ await cleanupSession(sessionId, detachedLive);
378
+ return { removed: true, archivedOnly: false };
299
379
  }
300
380
 
301
381
  async function dispatch(endpoint, payload) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-message-rewind",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "DeepSeek Harness plugin: edit sent messages and roll back following turns, optionally restoring recorded file changes.",
5
5
  "license": "MIT",
6
6
  "author": "xCube007",