dsh-pstack-deck 0.4.0 → 0.5.0

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  ![npm](https://img.shields.io/npm/v/dsh-pstack-deck?style=flat-square&color=8A9A8C)
6
6
  ![技能](https://img.shields.io/badge/技能-58_个-D7B9C8?style=flat-square)
7
7
  ![中文正文](https://img.shields.io/badge/中文正文-58_篇-9AA8C4?style=flat-square)
8
- ![测试](https://img.shields.io/badge/测试-46_通过-C9A97A?style=flat-square)
8
+ ![测试](https://img.shields.io/badge/测试-60_通过-C9A97A?style=flat-square)
9
9
  ![许可](https://img.shields.io/badge/许可-MIT-8A9A8C?style=flat-square)
10
10
 
11
11
  - 插件名:`dsh-pstack-deck`
@@ -46,6 +46,14 @@
46
46
 
47
47
  ![下钻](docs/preview-drill.png)
48
48
 
49
+ **收尾必须写结论** —— 点「完成」不是改个状态,而是先回答「做成了什么、验过什么」;空着点确认会被拦住。写完这句话会同时进卡的 `## 结论` 和地图的「已经定了」。
50
+
51
+ ![收尾](docs/preview-finish.png)
52
+
53
+ **真宿主** —— 起一个真 DSH 实例、真浏览器点开的右栏,不是渲染稿:打开就是看板,项目名与板路径在顶上。
54
+
55
+ ![真机](docs/verify-real-host.png)
56
+
49
57
  ---
50
58
 
51
59
  ## pstack 是什么
@@ -248,7 +256,7 @@ agent 自己也能用:
248
256
  | `pstack_use` | 取一个技能的正文,当作这次任务的操作说明(有中文就用中文) |
249
257
  | `pstack_suggest` | 给 3~5 条带现成提示词的建议 |
250
258
  | `pstack_init` | 初始化一个项目的板:地图卡 + `.pstack/README.md` + `AGENTS.md` 里的看板段 |
251
- | `pstack_board` | 看板:`list / add / move / claim / release / next` |
259
+ | `pstack_board` | 看板:`list / add / move / claim / release / done / drop / reopen / next` |
252
260
  | `pstack_install` | 把技能装进某个项目的 `.dsh/skills`,让那个项目新开的会话也能用 |
253
261
 
254
262
  ### 4. 建议与流程图
@@ -283,8 +291,46 @@ verify: node --test 全绿 # 做完的证据
283
291
  ---
284
292
  正文……
285
293
 
294
+ ## 结论
295
+
296
+ 加了 cookie 重试,Safari 复测通过
297
+
286
298
  - 2026-11-23 [在做] 抓到请求头里少了 cookie
299
+ - 2026-11-23 [完成] 加了 cookie 重试,Safari 复测通过
300
+ ```
301
+
302
+ ### 闭环:一张卡要么做成,要么放掉,都要留下结论
303
+
304
+ 这是这套东西的**唯一规矩**,也是它能不能自己滚起来的关键:
305
+
287
306
  ```
307
+ add ──▶ claim ──▶ 干活 ──┬─▶ done (必须写:做成了什么、验过什么)
308
+ ▲ └─▶ drop (必须写:为什么放掉)
309
+ │ │
310
+ └────── reopen ◀─────────┘ 编号不变,结论留着
311
+ ```
312
+
313
+ 为什么不是「改个状态就完事」:
314
+
315
+ - `state: done` 而没有结论,三天后没人知道当时改了什么、验没验 —— 等于没做。
316
+ - `state: dropped` 而没有原因,下一个人会把同一条死路再走一遍。
317
+ - 结束之后卡不是删掉:`op: "reopen"` 回到待办,**结论是累加的**,之前为什么放弃还看得见。
318
+
319
+ 所以结束是一次**动作**,不是一次字段编辑:
320
+
321
+ | 入口 | 行为 |
322
+ |---|---|
323
+ | 面板「完成 / 废弃」 | 先弹出结论输入框,空着点确认会被拦住 |
324
+ | `pstack_board op: "done" / "drop"` | `note` 必填,缺了直接报错 |
325
+ | `op: "move" state: done` | 被拒绝,并告诉你该走 `op: "done"` |
326
+
327
+ 写完会发生三件事,一次原子地发生:
328
+
329
+ 1. 卡的 `## 结论` 段落下这句话,末尾追加一条进展;
330
+ 2. 认领人清空 —— 别人一看就知道不用再等这个会话;
331
+ 3. **地图跟着动**:完成写进「已经定了」,废弃写进「不做什么」。这块板的记忆不会断在地图之外。
332
+
333
+ 面板每 4 秒自己对一次盘:agent 在会话里把卡收尾了,你这边不用点刷新,分组和「建议接下来做这几件」会一起变。点按钮时也是同一帧刷新 —— 不会出现卡进了「完成」而推荐还停在上一条。
288
334
 
289
335
  ### 跟着项目走:先找到项目根,再谈板
290
336
 
@@ -407,7 +453,9 @@ npm publish --registry=https://registry.npmjs.org --access public
407
453
  ## 已知边界
408
454
 
409
455
  - `scope` 冲突是**路径前缀比对**,不是代码级依赖分析。同目录不同文件互依的情况挡不住。
410
- - WIP 上限没有硬拦:认领第二张 `doing` 不会被拒绝,只是分组里看得见。
456
+ - WIP 上限没有硬拦:认领第二张 `doing` 不会拒绝,只会提醒「你手上还有 #N」。硬拦会挡住「一张卡拆成两半同时推进」的合理情况。
457
+ - 卡进入 `done` / `dropped` 之后不会自动归档到别的文件,全躺在同一个 `.pstack/board/`;卡多了之后目录会长,暂时靠编号和分组读。
458
+ - 「收尾必须写结论」只在工具和面板上拦。手改 `.pstack/board/*.md` 把 `state: done` 写上去,是拦不住的 —— markdown 是真相,这是它的代价。
411
459
  - 地图「还没想清」的雾**不会自动毕业**成新卡,要人点一下。
412
460
  - 预期线路只画一步(推荐 → 完成),不画「完成之后接哪张」。
413
461
  - 中文正文是逐篇人工对齐翻译,上游改版后需要重跑 `npm run check:zh` 才发现漂移。
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-pstack-deck",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "pstack 的 DSH 面板:58 个技能点一下就用,带项目看板、依赖拓扑与三层决策推荐。",
6
6
  "license": "MIT",
@@ -207,7 +207,7 @@ await new Promise((r) => setTimeout(r, 300))
207
207
 
208
208
  // 可选第二参数:`board` 切到看板;其他值当成技能名点开详情
209
209
  const openName = process.argv[3]
210
- if (openName === 'board' || openName === 'flow' || openName === 'drill' || openName === 'init') {
210
+ if (openName === 'board' || openName === 'flow' || openName === 'drill' || openName === 'init' || openName === 'finish') {
211
211
  const tree = React.createElement(Panel, { sessionId: 'preview' })
212
212
  const walk = (node, label = '看板') => {
213
213
  if (!node || typeof node !== 'object') return false
@@ -217,6 +217,7 @@ if (openName === 'board' || openName === 'flow' || openName === 'drill' || openN
217
217
  // 文本可能包在子节点里(SVG 的 <text> 就是),所以除了直接相等也认「子树里有这句话」
218
218
  const flat = (n) => (Array.isArray(n) ? n.map(flat).join('') : typeof n === 'string' ? n : n && n.children ? flat(n.children) : '')
219
219
  if (node.props && typeof node.props.onClick === 'function' && (kids.includes(label) || flat(kids).includes(label))) {
220
+ if (process.env.PSP_DEBUG) console.error('[walk] click', label, 'on', flat(kids).slice(0, 40), '|', String(node.props.onClick).replace(/\s+/g, ' ').slice(0, 140))
220
221
  node.props.onClick()
221
222
  return true
222
223
  }
@@ -228,6 +229,11 @@ if (openName === 'board' || openName === 'flow' || openName === 'drill' || openN
228
229
  walk(React.createElement(Panel, { sessionId: 'preview' }), '流程')
229
230
  await new Promise((r) => setTimeout(r, 200))
230
231
  }
232
+ if (openName === 'finish') {
233
+ // 点第一张卡的「完成」,看收尾编辑器长什么样:结论是必填的
234
+ walk(React.createElement(Panel, { sessionId: 'preview' }), '完成')
235
+ await new Promise((r) => setTimeout(r, 200))
236
+ }
231
237
  if (openName === 'drill') {
232
238
  // 点第一格节点,看下钻出来的命令和「标记完成」
233
239
  walk(React.createElement(Panel, { sessionId: 'preview' }), '登录后偶发 …')
@@ -243,6 +249,7 @@ if (openName === 'list') {
243
249
  const kids = node.children || []
244
250
  const flat = (n) => (Array.isArray(n) ? n.map(flat).join('') : typeof n === 'string' ? n : n && n.children ? flat(n.children) : '')
245
251
  if (node.props && typeof node.props.onClick === 'function' && (kids.includes(label) || flat(kids).includes(label))) {
252
+ if (process.env.PSP_DEBUG) console.error('[walk] click', label, 'on', flat(kids).slice(0, 40), '|', String(node.props.onClick).replace(/\s+/g, ' ').slice(0, 140))
246
253
  node.props.onClick()
247
254
  return true
248
255
  }
@@ -251,7 +258,7 @@ if (openName === 'list') {
251
258
  walk(tree, '全部技能')
252
259
  await new Promise((r) => setTimeout(r, 300))
253
260
  }
254
- if (openName && !['board', 'flow', 'drill', 'init', 'list'].includes(openName)) {
261
+ if (openName && !['board', 'flow', 'drill', 'init', 'list', 'finish'].includes(openName)) {
255
262
  const toSkills = (node) => {
256
263
  if (!node || typeof node !== 'object') return false
257
264
  if (Array.isArray(node)) return node.some(toSkills)
package/src/board.js CHANGED
@@ -172,7 +172,8 @@ export function recommend(card, cards = []) {
172
172
 
173
173
  /** 看板的下一步:第一条在做,否则第一条待办/想法。 */
174
174
  export function nextOf(cards) {
175
- const open = cards.filter((c) => c.state !== 'done' && c.state !== 'dropped')
175
+ // 地图是上下文不是活:没有别的卡时不能把它当成「下一步」
176
+ const open = cards.filter((c) => isOpen(c) && c.kind !== 'map')
176
177
  const pick = open.find((c) => c.state === 'doing') ?? open.find((c) => c.state === 'todo') ?? open[0]
177
178
  if (!pick) return null
178
179
  return { card: pick, ...recommend(pick, cards) }
@@ -310,3 +311,124 @@ export function mapSections(card) {
310
311
  export function childrenOf(cards, id) {
311
312
  return cards.filter((c) => c.parent === Number(id))
312
313
  }
314
+
315
+ // ---------------------------------------------------------------- 闭环
316
+ //
317
+ // 教训来自一次真实的失败:注入一条命令、agent 干完活,卡还停在「在做」。
318
+ // 原因不是哪个按钮坏了,而是「结束」这件事没有闸门——它可以不写任何结论
319
+ // 就发生,也可以根本不发生。所以这里把结束变成一次显式的动作:
320
+ // 只有 done / dropped 算结束,而且必须留下一句结论。
321
+ // 结论文本会被复制进地图的「已经定了」,这块板的记忆才不会断。
322
+
323
+ export const ANSWER_HEAD = '## 结论'
324
+
325
+ /** 卡里「## 结论」段的内容;没有就是空串。 */
326
+ export function answerOf(card) {
327
+ const body = String(card?.body ?? '')
328
+ const m = body.match(/^##\s*结论\s*$/m)
329
+ if (!m) return ''
330
+ const after = body.slice(m.index + m[0].length)
331
+ const next = after.search(/^##\s/m)
332
+ const text = next === -1 ? after : after.slice(0, next)
333
+ // 进展行也是追加在文末的,会落进这一段;它们不是结论本身
334
+ return text.split('\n').filter((l) => !/^- \d{4}-\d{2}-\d{2} \[/.test(l)).join('\n').trim()
335
+ }
336
+
337
+ /** 往地图某一段末尾追加一行;这一段不存在就在文末补出来。 */
338
+ export function appendToSection(body, label, line) {
339
+ const lines = String(body ?? '').split('\n')
340
+ const at = lines.findIndex((l) => l.trim() === '## ' + label)
341
+ if (at === -1) return [...lines, '', '## ' + label, '', line].join('\n').trimEnd()
342
+ let end = lines.length
343
+ for (let i = at + 1; i < lines.length; i++) {
344
+ if (/^##\s/.test(lines[i])) {
345
+ end = i
346
+ break
347
+ }
348
+ }
349
+ let last = at
350
+ for (let i = at + 1; i < end; i++) if (lines[i].trim()) last = i
351
+ if (last === at) return [...lines.slice(0, at + 1), '', line, ...lines.slice(at + 1)].join('\n')
352
+ return [...lines.slice(0, last + 1), line, ...lines.slice(last + 1)].join('\n')
353
+ }
354
+
355
+ /**
356
+ * 结束一张卡:done(做成了)或 dropped(放掉了)。两者都必须带一句结论。
357
+ * 完成 → 地图「已经定了」记一笔;废弃 → 地图「不做什么」记一笔。
358
+ */
359
+ export async function finishCard(cwd, id, { state = 'done', note = '' } = {}) {
360
+ const target = String(state)
361
+ if (target !== 'done' && target !== 'dropped') {
362
+ throw new Error(`结束只能是 done 或 dropped,收到的是 ${target}`)
363
+ }
364
+ const text = String(note ?? '').trim()
365
+ if (!text) {
366
+ throw new Error(target === 'done'
367
+ ? '完成要写一句结论:这次到底做成了什么、验过没有(会写进卡里的「## 结论」)'
368
+ : '废弃要写一句原因:为什么不做了(会写进卡里的「## 结论」)')
369
+ }
370
+ const board = await loadBoard(cwd)
371
+ const card = board.cards.find((c) => c.id === Number(id))
372
+ if (!card) throw new Error(`看板里没有第 ${id} 号卡`)
373
+ if (card.kind === 'map') throw new Error('地图不是活:改它的四段就好,别把它标成完成')
374
+ if (card.state === target) throw new Error(`#${card.id} 已经是${stateZh(target)}了`)
375
+
376
+ let body = String(card.body ?? '').trimEnd()
377
+ body = answerOf(card)
378
+ ? `${body}\n- ${text}\n`
379
+ : `${body}\n\n${ANSWER_HEAD}\n\n${text}\n`
380
+
381
+ // 先改卡:状态、认领人清空、结论落盘、进展留痕
382
+ const saved = await saveCard(cwd, { id: card.id, title: card.title, state: target, owner: '' })
383
+ await saveCard(cwd, { id: saved.id, title: saved.title, body })
384
+ const withAnswer = await addProgress(cwd, card.id, text, target)
385
+
386
+ // 再把这一笔写回地图:换了别人接手,翻地图就知道当时定了什么
387
+ const map = (card.parent && board.cards.find((c) => c.id === card.parent)) || mapOf(board.cards)
388
+ if (map && map.id !== card.id) {
389
+ const line = target === 'done'
390
+ ? `- #${card.id} ${card.title} —— ${text}`
391
+ : `- #${card.id} ${card.title} —— 放掉了:${text}`
392
+ await saveCard(cwd, {
393
+ id: map.id,
394
+ title: map.title,
395
+ body: appendToSection(map.body, target === 'done' ? '已经定了' : '不做什么', line),
396
+ })
397
+ }
398
+ return withAnswer
399
+ }
400
+
401
+ /**
402
+ * 重开一张已结束的卡:回到待办,认领人清空。
403
+ * 废弃不等于删除——当时想的路走不通,换个做法还能接着用同一个编号。
404
+ */
405
+ export async function reopenCard(cwd, id, { note = '' } = {}) {
406
+ const board = await loadBoard(cwd)
407
+ const card = board.cards.find((c) => c.id === Number(id))
408
+ if (!card) throw new Error(`看板里没有第 ${id} 号卡`)
409
+ if (card.kind === 'map') throw new Error(`#${card.id} 是地图,不用重开`)
410
+ if (isOpen(card)) throw new Error(`#${card.id} 还没结束(${stateZh(card.state)}),不用重开`)
411
+ const why = String(note ?? '').trim()
412
+ const reopened = await saveCard(cwd, { id: card.id, title: card.title, state: 'todo', owner: '' })
413
+ return addProgress(cwd, reopened.id, why ? `重开:${why}` : '重开', 'todo')
414
+ }
415
+
416
+ /** 认领:先改状态再动手,别人扫一眼就知道这张有人在弄。 */
417
+ export async function claimCard(cwd, id, { owner = 'me', scope = [] } = {}) {
418
+ const board = await loadBoard(cwd)
419
+ const card = board.cards.find((c) => c.id === Number(id))
420
+ if (!card) throw new Error(`看板里没有第 ${id} 号卡`)
421
+ if (card.kind === 'map') throw new Error(`#${card.id} 是地图,不是活`)
422
+ if (!isOpen(card)) throw new Error(`#${card.id} 已经结束了,先 reopen 再认领`)
423
+ const blockers = blockersOf(card, board.cards)
424
+ if (blockers.length) throw new Error(`#${card.id} 还被挡着:等 ${blockers.map((n) => '#' + n).join('、')} 做完`)
425
+ if (card.owner && card.owner !== owner) throw new Error(`#${card.id} 已经被 ${card.owner} 认领了`)
426
+ const saved = await saveCard(cwd, {
427
+ id: card.id,
428
+ title: card.title,
429
+ state: 'doing',
430
+ owner,
431
+ scope: scope.length ? scope : card.scope,
432
+ })
433
+ return addProgress(cwd, saved.id, `认领:${owner}`, 'doing')
434
+ }
package/src/client.js CHANGED
@@ -42,6 +42,8 @@ window.__ModuleLoader__.load({
42
42
  detail: null,
43
43
  draft: '', // 详情页里「注入」后的原文,注入失败时给用户手抄
44
44
  zhOnly: false, // 有中文正文时默认显示中文,点一下切回原文
45
+ finish: null, // { id, state }:正在收尾哪张卡,收尾必须写一句结论
46
+ finNote: '',
45
47
  sugOpen: '', // 展开了哪条建议(看 Jev 分数和命令)
46
48
  node: null, // 流程图里下钻的卡号
47
49
  view: 'board', // board | skills —— 默认看板:进来先看到「这个项目要干什么」,而不是 58 个技能名
@@ -372,8 +374,14 @@ window.__ModuleLoader__.load({
372
374
  const open = store.sugOpen === it.id
373
375
  const doIt = async (method, payload, ok) => {
374
376
  try {
375
- set({ board: await rpc(method, { sessionId: store.sid, ...payload }), toast: ok, toastAt: Date.now() })
376
- loadBoard()
377
+ const view = await rpc(method, { sessionId: store.sid, ...payload })
378
+ const patch = { board: view, toast: ok, toastAt: Date.now() }
379
+ try {
380
+ patch.sug = await rpc('suggest', { sessionId: store.sid })
381
+ } catch {
382
+ /* 建议取不到不影响这次动作 */
383
+ }
384
+ set(patch)
377
385
  } catch (e) {
378
386
  set({ toast: String((e && e.message) || e), toastAt: Date.now() })
379
387
  }
@@ -415,18 +423,30 @@ window.__ModuleLoader__.load({
415
423
  : null,
416
424
  h('div', { key: 'c', style: { fontFamily: C.mono, fontSize: 11, background: 'rgba(0,0,0,.3)', border: '1px solid ' + C.line, borderRadius: 6, padding: '6px 8px', marginBottom: 8, userSelect: 'all', wordBreak: 'break-all' } }, it.prompt),
417
425
  h('div', { key: 'a', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } }, [
418
- h('button', { key: 'u', style: s.btn('primary'), onClick: () => inject(it.prompt) }, '执行这条命令'),
419
- it.cardId ? h('button', {
420
- key: 'c2',
421
- style: s.btn(),
422
- onClick: () => doIt('boardSave', { id: it.cardId, state: 'doing', owner: store.sid || 'me' }, `#${it.cardId} 归你了`),
423
- }, '我来做') : null,
426
+ // 点「执行」= 认领 + 注入,一步到位:命令进了输入框,卡也已经在「在做」,
427
+ // 两边不会一个走一个不动。
428
+ h('button', {
429
+ key: 'u',
430
+ style: s.btn('primary'),
431
+ onClick: async () => {
432
+ if (it.cardId && it.state !== 'doing' && !it.ask) {
433
+ try {
434
+ await rpc('boardAct', { sessionId: store.sid, id: it.cardId, action: 'claim', owner: store.sid || 'me' })
435
+ } catch {
436
+ /* 被挡着或已有人认领,注入照做 */
437
+ }
438
+ }
439
+ inject(it.prompt)
440
+ loadBoard()
441
+ },
442
+ }, '执行这条命令'),
424
443
  it.cardId ? h('button', {
425
444
  key: 'd',
426
445
  style: s.btn(),
427
- onClick: () => doIt('boardMove', { id: it.cardId, state: 'done', note: '做完' }, `#${it.cardId} 已完成`),
446
+ onClick: () => set({ finish: { id: it.cardId, state: 'done' }, finNote: '', sugOpen: '' }),
428
447
  }, '标为完成') : null,
429
448
  ]),
449
+ it.cardId ? FinishEditor({ id: it.cardId, call: doIt }) : null,
430
450
  ])
431
451
  : null,
432
452
  ])
@@ -434,11 +454,52 @@ window.__ModuleLoader__.load({
434
454
  ])
435
455
  }
436
456
 
457
+ // 收尾编辑器:完成和废弃都要一句结论才落盘。
458
+ // 这不是形式主义——没有结论的「已完成」,三天后没人知道当时到底做了什么、验没验。
459
+ const FinishEditor = ({ id, call }) => {
460
+ const fin = store.finish
461
+ if (!fin || fin.id !== id) return null
462
+ const isDrop = fin.state === 'dropped'
463
+ const go = () => {
464
+ const note = store.finNote.trim()
465
+ if (!note) {
466
+ set({ toast: isDrop ? '写一句为什么不做' : '写一句做成了什么', toastAt: Date.now() })
467
+ return
468
+ }
469
+ call('boardAct', { id, action: isDrop ? 'drop' : 'done', note }, isDrop ? '已废弃,可随时重开' : '已完成')
470
+ set({ finish: null, finNote: '' })
471
+ }
472
+ return h('div', { style: { border: '1px solid ' + (isDrop ? C.line : C.accent), borderRadius: 6, padding: 8, marginTop: 6, background: 'rgba(0,0,0,.18)' } }, [
473
+ h('div', { key: 'q', style: { ...s.faint, fontSize: 11, marginBottom: 4 } },
474
+ isDrop ? '为什么放掉?(会记进地图的「不做什么」)' : '做成了什么、验过什么?(会记进地图的「已经定了」)'),
475
+ h('textarea', {
476
+ key: 'n',
477
+ style: { ...s.input, minHeight: 54, resize: 'vertical', fontFamily: 'inherit', lineHeight: 1.5 },
478
+ value: store.finNote,
479
+ placeholder: isDrop ? '这条路走不通,因为…' : '改了 X,跑了 Y,结果是 Z',
480
+ onChange: (e) => set({ finNote: e.target.value }),
481
+ }),
482
+ h('div', { key: 'b', style: { display: 'flex', gap: 6, marginTop: 6 } }, [
483
+ h('button', { key: 'ok', style: s.btn('primary'), onClick: go }, isDrop ? '确认废弃' : '确认完成'),
484
+ h('button', { key: 'no', style: s.btn(), onClick: () => set({ finish: null, finNote: '' }) }, '取消'),
485
+ ]),
486
+ ])
487
+ }
488
+
437
489
  const Board = () => {
438
490
  const b = store.board
491
+ // 一次动作 = 一次整体刷新:卡片状态和「建议接下来做这几件」必须同一帧更新,
492
+ // 否则卡片落进「完成」但推荐还停在上一条,人就会以为没生效。
439
493
  const call = async (method, payload, okText) => {
440
494
  try {
441
- set({ board: await rpc(method, { sessionId: store.sid, ...payload }), toast: okText, toastAt: Date.now() })
495
+ const view = await rpc(method, { sessionId: store.sid, ...payload })
496
+ const patch = { board: view, toast: okText, toastAt: Date.now() }
497
+ try {
498
+ patch.sug = await rpc('suggest', { sessionId: store.sid })
499
+ } catch {
500
+ /* 建议取不到不该挡住这次动作 */
501
+ }
502
+ set(patch)
442
503
  } catch (e) {
443
504
  set({ toast: String((e && e.message) || e), toastAt: Date.now() })
444
505
  }
@@ -584,14 +645,25 @@ window.__ModuleLoader__.load({
584
645
  })(),
585
646
  h('div', { key: 'n', style: { marginTop: 6, display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' } }, [
586
647
  c.next ? h('button', { key: 'u', style: { ...s.btn('primary'), padding: '2px 8px', fontSize: 11 }, onClick: () => inject('/' + c.next.skill + ' ' + c.title) }, '/' + c.next.skill) : null,
587
- c.state !== 'done' && !c.owner && !(c.blocked || []).length ? h('button', { key: 'c', style: { ...s.btn('primary'), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardSave', { id: c.id, owner: store.sid || 'me', state: 'doing' }, '这张归你了') }, '我来做') : null,
648
+ c.state === 'done' || c.state === 'dropped'
649
+ ? h('button', { key: 're', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardAct', { id: c.id, action: 'reopen', note: '再试一次' }, '已重开,回到待办') }, '重开')
650
+ : null,
651
+ c.state !== 'done' && c.state !== 'dropped' && !c.owner && !(c.blocked || []).length
652
+ ? h('button', { key: 'c', style: { ...s.btn('primary'), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardAct', { id: c.id, action: 'claim', owner: store.sid || 'me' }, '这张归你了') }, '我来做')
653
+ : null,
588
654
  (c.blocked || []).length ? h('span', { key: 'w', style: { ...s.faint, fontSize: 10 } }, `等 #${c.blocked.join(' #')}`) : null,
589
- c.owner ? h('button', { key: 'r', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardSave', { id: c.id, owner: '' }, '已交回') }, '交回') : null,
590
- c.state !== 'doing' && c.state !== 'done' && c.owner ? h('button', { key: 'g', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardMove', { id: c.id, state: 'doing', note: '开始' }, '开始做了') }, '开始') : null,
591
- c.state !== 'done' ? h('button', { key: 'f', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardMove', { id: c.id, state: 'done', note: '做完' }, '已完成') }, '完成') : null,
592
- c.state !== 'dropped' ? h('button', { key: 'x', style: { ...s.btn(), padding: '2px 8px', fontSize: 11, color: C.faint }, onClick: () => call('boardMove', { id: c.id, state: 'dropped', note: '废弃' }, '已废弃') }, '废弃') : null,
655
+ c.owner && c.state !== 'done' && c.state !== 'dropped'
656
+ ? h('button', { key: 'r', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => call('boardAct', { id: c.id, action: 'release' }, '已交回') }, '交回')
657
+ : null,
658
+ c.state !== 'done' && c.state !== 'dropped'
659
+ ? h('button', { key: 'f', style: { ...s.btn(), padding: '2px 8px', fontSize: 11 }, onClick: () => set({ finish: { id: c.id, state: 'done' }, finNote: '' }) }, '完成')
660
+ : null,
661
+ c.state !== 'done' && c.state !== 'dropped'
662
+ ? h('button', { key: 'x', style: { ...s.btn(), padding: '2px 8px', fontSize: 11, color: C.faint }, onClick: () => set({ finish: { id: c.id, state: 'dropped' }, finNote: '' }) }, '废弃')
663
+ : null,
593
664
  c.progress ? h('span', { key: 'p', style: { ...s.faint, fontSize: 10 } }, c.progress + ' 条进展') : null,
594
665
  ]),
666
+ FinishEditor({ id: c.id, call }),
595
667
  ])),
596
668
  ])),
597
669
  ])
@@ -622,6 +694,8 @@ window.__ModuleLoader__.load({
622
694
  set({ toast: String((e && e.message) || e), toastAt: Date.now() })
623
695
  }
624
696
  }
697
+ const act = (action, note) => go('boardAct', { id: card.id, action, note })
698
+ const closing = card.state === 'done' || card.state === 'dropped'
625
699
  return h('div', { style: { border: '1px solid ' + C.accent, borderRadius: 8, padding: '8px 10px', marginTop: 8, background: 'rgba(122,162,247,.10)' } }, [
626
700
  h('div', { key: 't', style: { fontWeight: 600, wordBreak: 'break-word' } }, `#${card.id} ${card.title}`),
627
701
  h('div', { key: 'm', style: { ...s.faint, fontSize: 10, marginTop: 2 } }, [
@@ -640,15 +714,23 @@ window.__ModuleLoader__.load({
640
714
  : null,
641
715
  h('div', { key: 'a', style: { display: 'flex', gap: 6, flexWrap: 'wrap' } }, [
642
716
  prompt ? h('button', { key: 'u', style: s.btn('primary'), onClick: () => inject(prompt) }, '执行这条命令') : null,
643
- card.state !== 'doing'
644
- ? h('button', { key: 's', style: s.btn(), onClick: () => go('boardSave', { id: card.id, state: 'doing', owner: store.sid || 'me' }, `#${card.id} 归你了`) }, '我来做')
645
- : h('button', { key: 's2', style: s.btn(), onClick: () => go('boardSave', { id: card.id, owner: '' }, `#${card.id} 交回了`) }, '交回'),
717
+ card.state !== 'doing' && !closing && !(card.blocked || []).length
718
+ ? h('button', { key: 's', style: s.btn(), onClick: () => act('claim', undefined) }, '我来做')
719
+ : null,
720
+ card.owner && !closing
721
+ ? h('button', { key: 's2', style: s.btn(), onClick: () => act('release') }, '交回')
722
+ : null,
646
723
 
647
- card.state !== 'done' ? h('button', { key: 'd', style: s.btn(), onClick: () => go('boardMove', { id: card.id, state: 'done', note: '做完' }, `#${card.id} 已完成`) }, '标记完成') : null,
648
- card.state !== 'dropped' ? h('button', { key: 'x', style: { ...s.btn(), color: C.faint }, onClick: () => go('boardMove', { id: card.id, state: 'dropped', note: '废弃' }, '已废弃') }, '废弃') : null,
724
+ closing
725
+ ? h('button', { key: 're', style: s.btn('primary'), onClick: () => act('reopen', '再试一次') }, '重开')
726
+ : h('button', { key: 'd', style: s.btn(), onClick: () => set({ finish: { id: card.id, state: 'done' }, finNote: '' }) }, '标记完成'),
727
+ closing
728
+ ? null
729
+ : h('button', { key: 'x', style: { ...s.btn(), color: C.faint }, onClick: () => set({ finish: { id: card.id, state: 'dropped' }, finNote: '' }) }, '废弃'),
649
730
  h('div', { key: 'sp', style: { flex: 1 } }),
650
731
  h('button', { key: 'c0', style: { ...s.btn(), color: C.faint }, onClick: () => set({ node: null }) }, '收起'),
651
732
  ]),
733
+ FinishEditor({ id: card.id, call: go }),
652
734
  ])
653
735
  }
654
736
 
@@ -766,6 +848,19 @@ window.__ModuleLoader__.load({
766
848
  React.useEffect(() => {
767
849
  if (store.view === 'board' && !store.board) loadBoard()
768
850
  }, [store.view, store.sid])
851
+ // agent 干活是在会话里写的盘,面板不长眼睛。站在看板上就每 4 秒自己对一次,
852
+ // 它一收尾这里就跟着动——不然人会一直盯着一个不动的「在做」。
853
+ React.useEffect(() => {
854
+ if (store.view !== 'board') return undefined
855
+ const t = setInterval(() => {
856
+ if (store.finish || store.node) return // 正在写结论或看下钻,别把输入冲掉
857
+ loadBoard()
858
+ }, 4000)
859
+ // 浏览器里 setInterval 返回数字;node 里(自渲染截图、测试的假 React)返回 Timeout。
860
+ // unref 一下,否则这些假环境会因为一个轮询永远退不出去。
861
+ if (t && typeof t.unref === 'function') t.unref()
862
+ return () => clearInterval(t)
863
+ }, [store.view])
769
864
  const toBoard = () => {
770
865
  set({ view: 'board' })
771
866
  if (!store.board) loadBoard()
package/src/host.js CHANGED
@@ -13,6 +13,10 @@ import { readFile } from 'node:fs/promises'
13
13
 
14
14
  import {
15
15
  addProgress,
16
+ answerOf,
17
+ claimCard,
18
+ finishCard,
19
+ reopenCard,
16
20
  blockersOf,
17
21
  childrenOf,
18
22
  conflictsOf,
@@ -164,6 +168,9 @@ const methods = {
164
168
  if (!Number.isInteger(id) || id <= 0) return { ok: false, error: { code: 'bad-id', message: '卡号不对' } }
165
169
  const note = String(payload?.note ?? '').trim()
166
170
  const state = payload?.state
171
+ if (state === 'done' || state === 'dropped') {
172
+ return { ok: false, error: { code: 'need-answer', message: '结束要走「完成 / 废弃」,并且写一句结论' } }
173
+ }
167
174
  if (!note && !state) return { ok: false, error: { code: 'no-change', message: '要么改状态,要么写一句进展' } }
168
175
  try {
169
176
  await addProgress(cwd, id, note || `→ ${stateZh(state)}`, state)
@@ -172,6 +179,35 @@ const methods = {
172
179
  }
173
180
  return { ok: true, value: await view(await loadBoard(cwd), resolveWorkspace(ctx, payload?.sessionId)) }
174
181
  },
182
+
183
+ /**
184
+ * 闭环的四个动作,全都返回刷新后的整块板:
185
+ * claim 认领、finish 收尾(done/drop,必须带结论)、reopen 重开、release 交回。
186
+ * 面板点一下就走这里,所以状态和各处建议是同一帧刷新的,不会各说各话。
187
+ */
188
+ async boardAct(payload, ctx) {
189
+ const cwd = workspaceOf(ctx, payload?.sessionId)
190
+ const id = Number(payload?.id)
191
+ if (!Number.isInteger(id) || id <= 0) return { ok: false, error: { code: 'bad-id', message: '卡号不对' } }
192
+ const action = String(payload?.action ?? '').trim()
193
+ const note = String(payload?.note ?? '').trim()
194
+ let touched
195
+ try {
196
+ if (action === 'claim') touched = await claimCard(cwd, id, { owner: String(payload?.owner ?? 'me'), scope: Array.isArray(payload?.scope) ? payload.scope : [] })
197
+ else if (action === 'done') touched = await finishCard(cwd, id, { state: 'done', note })
198
+ else if (action === 'drop') touched = await finishCard(cwd, id, { state: 'dropped', note })
199
+ else if (action === 'reopen') touched = await reopenCard(cwd, id, { note })
200
+ else if (action === 'release') touched = await saveCard(cwd, { id, owner: '' })
201
+ else return { ok: false, error: { code: 'bad-action', message: `不认识的 action:${action}` } }
202
+ } catch (e) {
203
+ return { ok: false, error: { code: 'rejected', message: String(e?.message ?? e) } }
204
+ }
205
+ const nextBoard = await loadBoard(cwd)
206
+ return {
207
+ ok: true,
208
+ value: { ...(await view(nextBoard, resolveWorkspace(ctx, payload?.sessionId))), touched: { id: touched.id, state: touched.state } },
209
+ }
210
+ },
175
211
  }
176
212
 
177
213
  /** 面板要的形状:卡 + 每张卡的下一步建议 + 全局下一步 + 这是哪个项目、初始化到哪一步。 */
@@ -180,6 +216,7 @@ async function view(board, ws) {
180
216
  const cards = board.cards.map((c) => ({
181
217
  ...c,
182
218
  next: recommend(c, board.cards),
219
+ answer: answerOf(c),
183
220
  blocked: blockersOf(c, board.cards),
184
221
  children: childrenOf(board.cards, c.id).length,
185
222
  }))
package/src/init.js CHANGED
@@ -66,8 +66,10 @@ ${AGENTS_MARK}
66
66
  这个项目用 \`.pstack/board/\` 记任务,一张卡一个 markdown 文件。
67
67
 
68
68
  - 开工前先看板:调 \`pstack_board\` 的 \`op: "list"\`,从「可开工」那一组里挑一张。
69
- - 动手前先认领(\`op: "claim"\`),告诉别人这条你在做,别让两个会话撞在同一件事上。
70
- - 做完写一条进展(\`op: "move"\`),把结论留在卡上,别只留在对话里。
69
+ - 动手前先认领:\`op: "claim"\`,告诉别人这条你在做,别让两个会话撞在同一件事上。
70
+ - **干完必须收尾**:\`op: "done"\` 并写一句 \`note\`(做成了什么、验过什么),或 \`op: "drop"\` 并写为什么不做了。
71
+ 没有结论的「已完成」等于没做,卡会一直挂在「在做」——这就是这个看板唯一的规矩。
72
+ - 放掉的卡不是删掉:\`op: "reopen"\` 就能回到待办,编号不变,之前的结论还在卡里。
71
73
  - 不知道下一步做什么,调 \`pstack_suggest\`,它会给 3~5 条带现成提示词的动作。
72
74
  `
73
75
 
package/src/suggest.js CHANGED
@@ -111,10 +111,19 @@ function choiceOf(card, cards, project) {
111
111
  certainty,
112
112
  factors: noulFactors(card),
113
113
  ask: false,
114
- prompt: `/${next.skill} #${card.id} ${scope}`,
114
+ prompt: withLoop(`/${next.skill} #${card.id} ${scope}`, card.id),
115
115
  }
116
116
  }
117
117
 
118
+ /**
119
+ * 注入的命令不只是命令,还捎带一句收尾契约。
120
+ * 没有这句,agent 干完活不会回写看板——「执行完状态不动」就是这么来的。
121
+ */
122
+ export function withLoop(cmd, cardId) {
123
+ return `${cmd}\n\n(pstack 看板约定:#${cardId} 现在是「在做」。干完调 pstack_board op=done id=${cardId} note="做成什么、验过什么";`
124
+ + `干不下去调 op=drop id=${cardId} note="为什么放掉"。不要让它停在「在做」。)`
125
+ }
126
+
118
127
  // ------------------------------------------------------------------ 层选择
119
128
 
120
129
  /** 最近动过的项目目录,跳过隐藏目录。 */
@@ -227,7 +236,7 @@ export function directionOf(board, project) {
227
236
  urgency: top.urgency,
228
237
  certainty: noulClear(head),
229
238
  ask: false,
230
- prompt: `/${next.skill} #${head.id} ${scope}`,
239
+ prompt: withLoop(`/${next.skill} #${head.id} ${scope}`, head.id),
231
240
  }
232
241
  }
233
242
 
package/src/tools.js CHANGED
@@ -12,11 +12,14 @@ import {
12
12
  blockersOf,
13
13
  conflictsOf,
14
14
  KINDS,
15
+ claimCard,
16
+ finishCard,
15
17
  kindZh,
16
18
  loadBoard,
17
19
  mapOf,
18
20
  nextOf,
19
21
  recommend,
22
+ reopenCard,
20
23
  saveCard,
21
24
  stateZh,
22
25
  STATES,
@@ -171,22 +174,54 @@ async function boardTool(args, exec, ctx) {
171
174
  })
172
175
  return `已记入看板:#${card.id} ${card.title}(${kindZh(card.kind)} · ${stateZh(card.state)})\n${dir}`
173
176
  }
177
+ if (op === 'done' || op === 'drop') {
178
+ const id = Number(args?.id)
179
+ if (!Number.isInteger(id) || id <= 0) throw new Error('要给卡号 id')
180
+ const card = await finishCard(dir, id, { state: op === 'done' ? 'done' : 'dropped', note: String(args?.note ?? '') })
181
+ const map = mapOf((await loadBoard(dir)).cards)
182
+ return [
183
+ `#${card.id} ${card.title} → ${stateZh(card.state)}`,
184
+ `结论已写进卡里${map ? `,也记到地图 #${map.id} 的「${op === 'done' ? '已经定了' : '不做什么'}」` : ''}。`,
185
+ '下一张:op=list 看现在的可开工。',
186
+ ].join('\n')
187
+ }
188
+ if (op === 'reopen') {
189
+ const id = Number(args?.id)
190
+ if (!Number.isInteger(id) || id <= 0) throw new Error('要给卡号 id')
191
+ const card = await reopenCard(dir, id, { note: String(args?.note ?? '') })
192
+ return `#${card.id} ${card.title} 已重开(${stateZh(card.state)}),可以再认领。`
193
+ }
174
194
  if (op === 'move') {
175
195
  const id = Number(args?.id)
176
196
  if (!Number.isInteger(id) || id <= 0) throw new Error('要给卡号 id')
177
- const card = await addProgress(dir, id, String(args?.note ?? ''), STATES.includes(args?.state) ? args.state : undefined)
178
- return `#${card.id} ${card.title} → ${stateZh(card.state)}\n${card.body.trim().split('\n').slice(-1)[0] ?? ''}`
197
+ const want = String(args?.state ?? '').trim()
198
+ if (want === 'done' || want === 'dropped') {
199
+ throw new Error(`结束要走 op=${want === 'done' ? 'done' : 'drop'} 并给一句 note——没有结论的「结束」等于没做`)
200
+ }
201
+ if (!STATES.includes(want)) throw new Error('move 要 state=todo 或 doing(结束用 done / drop)')
202
+ const card = await addProgress(dir, id, String(args?.note ?? ''), want)
203
+ return `#${card.id} ${card.title} → ${stateZh(card.state)}`
204
+ }
205
+ if (op === 'claim') {
206
+ const id = Number(args?.id)
207
+ if (!Number.isInteger(id) || id <= 0) throw new Error('要给卡号 id')
208
+ const owner = String(args?.owner ?? exec?.sessionId ?? 'me').trim()
209
+ const scope = Array.isArray(args?.scope) ? args.scope : []
210
+ const card = await claimCard(dir, id, { owner, scope })
211
+ const doing = (await loadBoard(dir)).cards.filter((c) => c.owner && c.owner === owner && c.state === 'doing' && c.id !== card.id)
212
+ return [
213
+ `#${card.id} ${card.title} 归你了(${owner} → 在做)。`,
214
+ doing.length ? `提醒:你手上还有 ${doing.map((c) => '#' + c.id).join('、')} 没结束。一张做完再开下一张,不然两边都半截。` : '',
215
+ `收尾一定要调 op=done 或 op=drop,note 里写一句结论——不写的话这张卡会一直挂在「在做」,看板就停在那了。`,
216
+ ].filter(Boolean).join('\n')
179
217
  }
180
- if (op === 'claim' || op === 'release') {
218
+ if (op === 'release') {
181
219
  const id = Number(args?.id)
182
220
  if (!Number.isInteger(id) || id <= 0) throw new Error('要给卡号 id')
183
- const owner = op === 'claim' ? String(args?.owner ?? exec?.sessionId ?? 'me').trim() : ''
184
- const card = await saveCard(dir, { id, owner })
185
- return op === 'claim'
186
- ? `#${card.id} ${card.title} 归你了(认领人 ${owner})。做完记得 op=move state=done,并把跑过的验证写进 note。`
187
- : `#${card.id} ${card.title} 已交回待领(没人做)。`
221
+ const card = await saveCard(dir, { id, owner: '' })
222
+ return `#${card.id} ${card.title} 已交回待领(没人做)。`
188
223
  }
189
- if (op !== 'list' && op !== 'next') throw new Error('op 只能是 list / add / move / claim / release / next')
224
+ if (op !== 'list' && op !== 'next') throw new Error('op 只能是 list / add / move / claim / release / done / drop / reopen / next')
190
225
 
191
226
  const board = await loadBoard(dir)
192
227
  const cards = board.cards.map((c) => ({ ...c, next: recommend(c, board.cards), blocked: blockersOf(c, board.cards) }))
@@ -288,18 +323,24 @@ export function apply(ctx) { const tools = ctx?.tools
288
323
  tools.register({
289
324
  name: 'pstack_board',
290
325
  description:
291
- '项目看板(存在 <项目>/.pstack/board/ 的 markdown 卡里)。op=list 看板与下一步建议;'
292
- + 'op=add 记一张想法/缺陷/任务;op=move 改状态或写一条进展;op=next 只要下一步。',
326
+ '项目看板(存在 <项目>/.pstack/board/ 的 markdown 卡里)。一张卡的生命周期只有一条路:'
327
+ + 'add 建 → claim 认领(变 doing)→ 干活 → done 或 drop 收尾(必须带一句结论)。'
328
+ + '认领之后一定要走到 done/drop,否则这张卡会一直挂在「在做」,整个看板就停在那儿——'
329
+ + '这就是闭环。结束了想再干就 reopen。op=list 看全景,op=next 只要下一步。',
293
330
  parameters: {
294
331
  type: 'object',
295
332
  properties: {
296
- op: { type: 'string', enum: ['list', 'add', 'move', 'claim', 'release', 'next'], description: 'list / add / move / claim / release / next' },
333
+ op: {
334
+ type: 'string',
335
+ enum: ['list', 'add', 'move', 'claim', 'release', 'done', 'drop', 'reopen', 'next'],
336
+ description: 'list 看板 / add 建卡 / claim 认领 / move 改 todo|doing / done 做完 / drop 废弃 / reopen 重开 / release 交回 / next 下一步',
337
+ },
297
338
  title: { type: 'string', description: 'add 时必给:这张卡要干什么' },
298
339
  body: { type: 'string', description: 'add 时的详细说明(markdown)' },
299
340
  kind: { type: 'string', enum: ['idea', 'bug', 'task', 'map'], description: 'add 时给:想法 / 缺陷 / 任务 / 地图(一块板一张,写清去向)' },
300
341
  id: { type: 'number', description: 'move 时必给:卡号' },
301
342
  state: { type: 'string', enum: ['idea', 'todo', 'doing', 'done', 'dropped'], description: 'move 时给:新状态' },
302
- note: { type: 'string', description: 'move 时的进展说明' },
343
+ note: { type: 'string', description: 'move 时的进展说明;done/drop 时必给:这次做成了什么、验过什么,或为什么不做了' },
303
344
  after: { type: 'array', items: { type: 'number' }, description: 'add 时给:要等哪几张卡先做完(卡号)' },
304
345
  parent: { type: 'number', description: 'add 时给:挂在哪张卡下面(通常是地图的卡号)' },
305
346
  scope: { type: 'array', items: { type: 'string' }, description: 'add 时给:这张卡能动哪些路径,用来判断并行会不会打架' },