dsh-progress-union 0.5.14 → 0.6.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 +16 -1
- package/README.md +54 -2
- package/archive.js +356 -0
- package/client.js +34 -17
- package/docs/consumer-guide.md +85 -1
- package/dsh.plugin.json +2 -2
- package/index.js +633 -0
- package/package.json +4 -2
- package/test/archive-inject.test.mjs +236 -0
- package/test/archive-restore.test.mjs +138 -0
- package/test/archive.test.mjs +224 -0
- package/test/star-panel.test.mjs +31 -1
package/docs/consumer-guide.md
CHANGED
|
@@ -198,7 +198,89 @@ const line = anchorLine(anchor)
|
|
|
198
198
|
if (line) statusBar.text = line
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
## 6.
|
|
201
|
+
## 6. 会话归档与 handoff(0.6.0 新增)
|
|
202
|
+
|
|
203
|
+
板是「当前态」,归档是「版本链 + 可读摘要」。想让模型/你的插件在会话重启后知道「这任务干到哪、下一步是什么」,读归档的 `handoff`,不要自己从板猜。
|
|
204
|
+
|
|
205
|
+
### 6.1 三种读法
|
|
206
|
+
|
|
207
|
+
- **同进程 service**:`ctx.get('progressAnchor').archive(sessionId)` → `{ seq, revision, at, reason, handoff, degraded } | null`;`.handoff(sessionId)` 直接拿 handoff。
|
|
208
|
+
- **锚点里顺带读**:`progressAnchor.get(sid).archive`(只追加字段,可选链读;`ANCHOR_VERSION` 仍是 1)。
|
|
209
|
+
- **HTTP / 外部脚本**:三条只读路由 —— 非 GET → 405,缺 `sessionId` → 400。
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# 最新一版(含 degraded 标记)
|
|
213
|
+
curl "http://127.0.0.1:<web-port>/progress-union/archive/latest?sessionId=<sid>"
|
|
214
|
+
|
|
215
|
+
# 版本列表(倒序,limit 默认 20、上限 100)
|
|
216
|
+
curl "http://127.0.0.1:<web-port>/progress-union/archive/versions?sessionId=<sid>&limit=5"
|
|
217
|
+
|
|
218
|
+
# 指定版本(seq 从 1 起,单调递增)
|
|
219
|
+
curl "http://127.0.0.1:<web-port>/progress-union/archive/version?sessionId=<sid>&seq=7"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
import { isArchive, ARCHIVE_VERSION, ARCHIVE_ROUTES } from 'dsh-progress-union/archive'
|
|
224
|
+
|
|
225
|
+
const anchor = ctx.get('progressAnchor')
|
|
226
|
+
if (anchor.version !== 1) return // 版本握手,不匹配跳过
|
|
227
|
+
const view = anchor?.archive?.(sessionId) // 0.6.0 之前不存在 → 可选链降级
|
|
228
|
+
if (view && isArchive({ ...view, version: ARCHIVE_VERSION, board: { summary: {} } })) {
|
|
229
|
+
// view.handoff.objective / inFlight / nextItems / filesTouched
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
> 路由返回 `{ ok, degraded, archive }`;读不到时 `ok:false`,`degraded:true` 表示 head 坏已回退 head-1,`reason:'missing'` 表示从未归档(不是坏版)。
|
|
234
|
+
|
|
235
|
+
### 6.2 归档记录形状(`version=1`,字段只追加)
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"version": 1, "sessionId": "session-…", "seq": 7, "revision": 12,
|
|
240
|
+
"at": 1756200000000, "reason": "turn|revision|dispose|manual",
|
|
241
|
+
"task": { "title": "一句话任务名", "goal": { "objective": "", "phase": "active", "roundsStarted": 0 } },
|
|
242
|
+
"board": {
|
|
243
|
+
"enabled": true,
|
|
244
|
+
"summary": { "total": 3, "done": 1, "doing": 1, "todo": 1, "blocked": 0, "percent": 45 },
|
|
245
|
+
"items": [ { "id": "p_x", "title": "", "status": "doing", "percent": 40, "current": "", "next": "", "order": 1, "unit": "", "targetTurns": 2, "closedAt": 0 } ]
|
|
246
|
+
},
|
|
247
|
+
"handoff": {
|
|
248
|
+
"objective": "一句话任务目标",
|
|
249
|
+
"doneSoFar": ["…"],
|
|
250
|
+
"inFlight": [ { "title": "", "current": "", "next": "" } ],
|
|
251
|
+
"nextItems": ["…"],
|
|
252
|
+
"filesTouched": ["path"],
|
|
253
|
+
"openUnits": [ { "id": "p_x", "title": "", "unit": "", "overTurns": 1 } ],
|
|
254
|
+
"lastTurn": { "turn": 12, "startSeq": 0, "endSeq": 0, "summary": "…" },
|
|
255
|
+
"generatedBy": "rules|rules-board-only"
|
|
256
|
+
},
|
|
257
|
+
"truncated": false,
|
|
258
|
+
"checksum": "sha256:…"
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
| 字段 | 含义 |
|
|
263
|
+
| --- | --- |
|
|
264
|
+
| `seq` | 每会话单调递增的版本号(头部即 `index.headSeq`);`/progress-resume <seq>` 用它取历史版 |
|
|
265
|
+
| `revision` | 写入时板的 `revision`——用来对账「注入的归档是否已落后于当前板」 |
|
|
266
|
+
| `reason` | `turn` 回合收尾 / `revision` 改板去抖 / `dispose` 退出兜底 |
|
|
267
|
+
| `handoff.objective` | goal.objective → 板首项标题 → `'未命名任务'` 的规则回退 |
|
|
268
|
+
| `handoff.doneSoFar` | 已完成项(按 `closedAt` 倒序,≤5)+ 最近 turn 的写/命令行(≤3) |
|
|
269
|
+
| `handoff.inFlight` / `nextItems` | doing/blocked 明细(≤6)/ todo 前 3 |
|
|
270
|
+
| `handoff.filesTouched` | 最近 `archiveHandoffTurns` 个 turn 工具调用里的路径(≤12,去重) |
|
|
271
|
+
| `handoff.openUnits` | 非 done 且跨 turn 超过 `targetTurns` 的未闭合单元(≤5) |
|
|
272
|
+
| `handoff.generatedBy` | `rules` 含事件原料;`rules-board-only` 表示宿主事件面缺失、只有板 |
|
|
273
|
+
| `truncated` | 超过 `archiveMaxBytes`(默认 32KB)被裁剪过 |
|
|
274
|
+
| `checksum` | 除自身外全字段的 `sha256`;`verifyChecksum()` 判坏版 |
|
|
275
|
+
|
|
276
|
+
### 6.3 消费规则
|
|
277
|
+
|
|
278
|
+
1. **先看 `degraded`**:为 `true` 时必须提示「来自上一版归档,可能落后」,并按当前板(`anchor.revision`)对账后再行动。
|
|
279
|
+
2. **`ok:false` 不是错误**:`missing`(从未归档)静默按无归档处理;只有 `degraded` 才值得提一句。
|
|
280
|
+
3. **归档只读**:写盘由插件在 turn/revision/dispose 三个钩子完成;consumer 不得代写,也不要直接改 `index.json`。
|
|
281
|
+
4. **别把 handoff 当全文**:它是有界的规则摘要,需要完整原文时读 `board.items` 或宿主 session log。
|
|
282
|
+
|
|
283
|
+
## 7. 快速自检清单
|
|
202
284
|
|
|
203
285
|
- [ ] 先用 `ANCHOR_VERSION` 握手,不等就跳过
|
|
204
286
|
- [ ] 同进程读包在 try/catch 里,服务缺席静默降级
|
|
@@ -208,3 +290,5 @@ if (line) statusBar.text = line
|
|
|
208
290
|
- [ ] `board.enabled=false` 当正常状态
|
|
209
291
|
- [ ] 新增字段可选链读取,缺失容忍
|
|
210
292
|
- [ ] ETA 缓存不超过 `staleMin`
|
|
293
|
+
- [ ] 归档读不到时先看 `degraded` / `reason`,不要把 `missing` 当坏版
|
|
294
|
+
- [ ] 归档路径用 `ARCHIVE_ROUTES`,`handoff` 只读不写
|
package/dsh.plugin.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-progress-union",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
|
-
"description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior
|
|
5
|
+
"description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面),并在 0.6.0 起每回合落一版会话归档(handoff 规则摘要 + 重启注入一次)。",
|
|
6
6
|
"engines": {
|
|
7
7
|
"dsh": ">=0.2.0-0 <0.3.0-0"
|
|
8
8
|
},
|