@240xu/dsh-message-ops 0.11.3 → 0.11.5
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 +20 -0
- package/package.json +1 -1
- package/src/index.js +9 -3
- package/src/ops-core.js +22 -3
package/README.md
CHANGED
|
@@ -89,6 +89,26 @@ dsh plugin --profile web add file:C:/path/to/dsh-message-ops
|
|
|
89
89
|
| POST | `/api/message-ops/session/restore` | `{trashId}` 从回收站恢复目录与投影/工作区元数据 |
|
|
90
90
|
| POST | `/api/message-ops/session/purge` | `{trashId}` 永久删除(唯一 destructive 操作) |
|
|
91
91
|
|
|
92
|
+
### 0.11.5 · restore 进度落盘 + `turnAligned` 可观测
|
|
93
|
+
|
|
94
|
+
- **磁盘 restore 漏写 `restoredSourceSeqs`(数据正确性)**:`buildRestoreNoticeEvent`
|
|
95
|
+
只写 `restoresSeq`,而 `restoreProgress` 靠 `restoredSourceSeqs` 累计已重放项。
|
|
96
|
+
结果每次恢复都被判 `legacy`(`complete:true` 但 `restoredSeqs` 恒空)→ 进度不可见,
|
|
97
|
+
且下一轮 `excludeSeqs` 为空 → **同一区间被反复重放**(实测 008f3759 两轮各 209 条)。
|
|
98
|
+
磁盘路径改为把 `plan.replayable.map(i => i.seq)` 落进 notice;discard 时不写。
|
|
99
|
+
- `/revert` 与 `/restore` 响应新增 `turnAligned`:live 路径应为 `true`,
|
|
100
|
+
disk/store-miss 路径没有内存 agent,`false` 属正常。便于运行时确认游标对齐是否生效。
|
|
101
|
+
|
|
102
|
+
### 0.11.4 · turn 游标对齐真正生效(会话损坏 P0 续)
|
|
103
|
+
|
|
104
|
+
- **`alignLiveTurnCursor` 此前从未执行**:插件 `export const inject = []`
|
|
105
|
+
(tools 是可选增强,故意不声明硬依赖),因此 `ctx.agents` **属性恒为 undefined**,
|
|
106
|
+
旧实现只读属性 → 恒返回 false。合成 turn 占用编号后宿主 idle agent 的
|
|
107
|
+
`phase.lastTurn` 不推进,下一条真实消息复用同一 turn 号,日志落成
|
|
108
|
+
`turn/start does not open the expected turn`,整份会话不可加载。
|
|
109
|
+
改为属性优先、`ctx.get("agents")` 兜底(与 `resolveSession` 同取法)。
|
|
110
|
+
- 回归测试:`ctx.agents` 缺失必须走 `ctx.get`;游标已领先时不得回退。
|
|
111
|
+
|
|
92
112
|
### 0.11.3 · 区间编码、回填落盘与会话损坏修复
|
|
93
113
|
|
|
94
114
|
- **`sourceEventSeqs` 区间语义修正(数据正确性)**:宿主用 `encodeSeqRanges` 把连续
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -667,11 +667,14 @@ async function opsCommit(targetCtx, mode, sessionId, seq) {
|
|
|
667
667
|
const event = applySurfaceReplace(session, plan.startSeq, plan.endSeq, plan.shadowedSeqs, text, turnStep);
|
|
668
668
|
// 必须闭合:否则引擎内存里 turn 永远开着 → isRunning 恒真 → 后续操作全被 409
|
|
669
669
|
closeWindow()
|
|
670
|
-
|
|
670
|
+
const aligned = win.synthetic ? alignLiveTurnCursor(targetCtx, session, win.turn) : false;
|
|
671
671
|
flushSessions(targetCtx, session);
|
|
672
672
|
return {
|
|
673
673
|
ok: true, mode, seq,
|
|
674
674
|
syntheticTurn: win.synthetic === true,
|
|
675
|
+
// 0.11.4:暴露对齐结果。live 路径必须 true;disk 路径(store-miss)没有
|
|
676
|
+
// 内存 agent,false 属正常。若 live 也 false,下一条真实消息就会重号。
|
|
677
|
+
turnAligned: aligned,
|
|
675
678
|
shadowedCount: plan.shadowedSeqs.length,
|
|
676
679
|
eventSeq: event && event.seq != null ? event.seq : null,
|
|
677
680
|
};
|
|
@@ -748,8 +751,8 @@ async function opsRestore(targetCtx, sessionId, restoreSeq, upToSeq, discard) {
|
|
|
748
751
|
flush: () => { flushSessions(targetCtx, acq.session); },
|
|
749
752
|
});
|
|
750
753
|
for (const post of noticeWindowPostamble(win)) acq.session.append(post.kind, post.data);
|
|
751
|
-
|
|
752
|
-
return { ok: true, ...result, discarded: plan.discard === true, upToSeq: plan.upToSeq, restoredSourceSeqs: plan.replayable.map((i) => i.seq), range: { startSeq: plan.startSeq, endSeq: plan.endSeq } };
|
|
754
|
+
const aligned = win.synthetic ? alignLiveTurnCursor(targetCtx, acq.session, win.turn) : false;
|
|
755
|
+
return { ok: true, ...result, turnAligned: aligned, discarded: plan.discard === true, upToSeq: plan.upToSeq, restoredSourceSeqs: plan.replayable.map((i) => i.seq), range: { startSeq: plan.startSeq, endSeq: plan.endSeq } };
|
|
753
756
|
} catch (err) {
|
|
754
757
|
for (const post of noticeWindowPostamble(win)) {
|
|
755
758
|
try { acq.session.append(post.kind, post.data); } catch { /* postamble 被引擎拒:维持原错误上抛 */ }
|
|
@@ -774,6 +777,9 @@ async function opsRestore(targetCtx, sessionId, restoreSeq, upToSeq, discard) {
|
|
|
774
777
|
: restoreNoticeText(plan),
|
|
775
778
|
restoreSeq: plan.restoreSeq,
|
|
776
779
|
discard: plan.discard === true,
|
|
780
|
+
// 0.11.4:把本轮实际重放的源 seq 落进 notice,restoreProgress 才能累计进度、
|
|
781
|
+
// 下一轮 excludeSeqs 才不会重复重放同一批消息(详见 ops-core 该函数注释)。
|
|
782
|
+
restoredSourceSeqs: plan.discard ? [] : plan.replayable.map((i) => i.seq),
|
|
777
783
|
}));
|
|
778
784
|
let offset = 0;
|
|
779
785
|
for (const item of plan.discard ? [] : plan.replayable) {
|
package/src/ops-core.js
CHANGED
|
@@ -239,7 +239,15 @@ export function deriveTurnStep(events) {
|
|
|
239
239
|
/** 合成 turn 落盘后,把宿主 idle agent 的 turn 游标对齐到该 turn(否则下一条真实消息会重号)。 */
|
|
240
240
|
export function alignLiveTurnCursor(ctx, session, turn) {
|
|
241
241
|
if (!Number.isSafeInteger(turn) || turn < 1 || !session || typeof session.id !== "string") return false;
|
|
242
|
-
|
|
242
|
+
// 0.11.4:插件 `inject` 故意留空(tools 是可选增强),因此 `ctx.agents`
|
|
243
|
+
// **属性访问恒为 undefined** —— 旧实现只写 `ctx.agents`,这条对齐从来没执行过。
|
|
244
|
+
// 实测 `ctx.get("agents")` 在 HTTP 请求期可解析(同 resolveSession 的取法),
|
|
245
|
+
// 故属性优先、ctx.get 兜底。
|
|
246
|
+
let agents = null;
|
|
247
|
+
try { if (ctx && ctx.agents) agents = ctx.agents; } catch { /* getter threw */ }
|
|
248
|
+
if (!agents) { try { agents = ctx && typeof ctx.get === "function" ? ctx.get("agents") : null; } catch { /* absent */ } }
|
|
249
|
+
let agent = null;
|
|
250
|
+
try { agent = agents && typeof agents.get === "function" ? agents.get(session.id) : null; } catch { /* registry miss */ }
|
|
243
251
|
if (!agent || agent.phase?.kind !== "idle" || typeof agent.setPhase !== "function") return false;
|
|
244
252
|
const lastTurn = Number.isSafeInteger(agent.phase.lastTurn) ? agent.phase.lastTurn : 0;
|
|
245
253
|
if (lastTurn >= turn) return false;
|
|
@@ -939,8 +947,18 @@ export function buildMarkerEvent({ seq, time, turnStep, text, startSeq, endSeq,
|
|
|
939
947
|
};
|
|
940
948
|
}
|
|
941
949
|
|
|
942
|
-
/**
|
|
943
|
-
|
|
950
|
+
/**
|
|
951
|
+
* 磁盘恢复说明事件(restoresSeq → dock 移除该行;surfaceOp 恒 "append")。
|
|
952
|
+
*
|
|
953
|
+
* 0.11.4:必须写入 `restoredSourceSeqs`。`restoreProgress` 靠它累计「已重放哪些
|
|
954
|
+
* 源 seq」来算 pending/complete;旧实现只写 `restoresSeq`,于是每次恢复都被判
|
|
955
|
+
* `legacy`(`complete:true` 但 `restoredSeqs` 恒空)→ 进度不可见,且下一轮
|
|
956
|
+
* `excludeSeqs` 为空 → 同一区间被**反复重放**(实测 008f3759 两轮各 209 条)。
|
|
957
|
+
*/
|
|
958
|
+
export function buildRestoreNoticeEvent({ seq, time, turnStep, text, restoreSeq, discard, restoredSourceSeqs, version = 4 }) {
|
|
959
|
+
const restored = Array.isArray(restoredSourceSeqs)
|
|
960
|
+
? [...new Set(restoredSourceSeqs.filter((q) => Number.isSafeInteger(q)))]
|
|
961
|
+
: [];
|
|
944
962
|
return {
|
|
945
963
|
type: "system/message",
|
|
946
964
|
seq,
|
|
@@ -950,6 +968,7 @@ export function buildRestoreNoticeEvent({ seq, time, turnStep, text, restoreSeq,
|
|
|
950
968
|
step: turnStep.step,
|
|
951
969
|
message: { id: randomUUID(), role: "system", source: messageSource("system", version), content: [{ type: "text", text }] },
|
|
952
970
|
restoresSeq: restoreSeq,
|
|
971
|
+
...(restored.length > 0 ? { restoredSourceSeqs: restored } : {}),
|
|
953
972
|
...(discard ? { discarded: true } : {}),
|
|
954
973
|
},
|
|
955
974
|
surfaceOp: "append",
|