nx-kv 0.24.6 → 0.26.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/assets/kv-get/SKILL.md +11 -13
  3. package/assets/kv-get/references/localget.md +8 -8
  4. package/assets/kv-get/references/timegoal-workflow.md +2 -3
  5. package/assets/kv-get/references/timegoal.md +5 -26
  6. package/assets/kv-get/references/wait-workflow.md +24 -40
  7. package/assets/kv-get/references/waitloop.md +19 -29
  8. package/assets/kv-submit/SKILL.md +2 -2
  9. package/assets/kv-submit/references/submit-workflow.md +1 -1
  10. package/assets/nx-kv/SKILL.md +6 -25
  11. package/assets/nx-kv/references/repo-registry.md +1 -5
  12. package/assets/nx-kv/references/todo-commands.md +3 -3
  13. package/package.json +1 -1
  14. package/src/core/json-store.js +219 -0
  15. package/src/modules/localtask/index.js +168 -14
  16. package/src/modules/localtask/panel-presence.js +7 -7
  17. package/src/modules/localtask/store-io.js +42 -107
  18. package/src/modules/localtask/task-lifecycle.js +128 -54
  19. package/src/modules/localtask/task-ops.js +43 -2
  20. package/src/modules/localtask/task-view.js +189 -8
  21. package/src/modules/repos/service.js +32 -47
  22. package/src/modules/tasktool/add.js +5 -0
  23. package/src/modules/tasktool/attach.js +6 -2
  24. package/src/modules/tasktool/delivery-text.js +23 -0
  25. package/src/modules/tasktool/plugins/taskgoal-store.js +42 -0
  26. package/src/modules/tasktool/plugins/timegoal-store.js +19 -33
  27. package/src/modules/tasktool/preview.js +96 -0
  28. package/src/modules/tasktool/wait.js +35 -11
  29. package/src/modules/templates/service.js +23 -37
  30. package/src/web/frontend/App.jsx +4 -0
  31. package/src/web/frontend/components/md/sel-menu.jsx +112 -19
  32. package/src/web/frontend/components/md/task-chain.jsx +75 -0
  33. package/src/web/frontend/components/md/tool-bar.jsx +14 -0
  34. package/src/web/frontend/components/sidebar/index.jsx +1 -9
  35. package/src/web/frontend/components/sidebar/model.js +9 -20
  36. package/src/web/frontend/modules/board/ack-nodes.js +2 -2
  37. package/src/web/frontend/modules/md/lightbox.js +97 -0
  38. package/src/web/frontend/modules/md/style.css +85 -0
  39. package/src/web/frontend/page/dir/index.jsx +32 -15
  40. package/src/web/frontend/page/dir/landing.jsx +2 -2
  41. package/src/web/frontend/page/dir/task.jsx +440 -75
  42. package/src/web/frontend/page/group/index.jsx +4 -4
  43. package/src/web/frontend/page/progress/index.jsx +19 -9
  44. package/src/web/frontend/page/settings/index.jsx +7 -0
  45. package/src/web/frontend/page/settings/sidebar-section.jsx +72 -0
  46. package/src/web/frontend/panels.jsx +13 -4
  47. package/src/web/public/assets/{Introduction-B_U-xbb9.js → Introduction-ka0UxW_S.js} +1 -1
  48. package/src/web/public/assets/{cloud-zp3n4ola.js → cloud-y1mZIdlN.js} +1 -1
  49. package/src/web/public/assets/{dag-Clekc4yJ.js → dag-CiMSs7uT.js} +1 -1
  50. package/src/web/public/assets/dir-DKzzrY8P.js +3 -0
  51. package/src/web/public/assets/group-DOLdLkaj.js +1 -0
  52. package/src/web/public/assets/{index-3r8gg9d1.js → index-CbZfbzqr.js} +3 -3
  53. package/src/web/public/assets/{index-B1yzxhtQ.css → index-DUvCgdUV.css} +1 -1
  54. package/src/web/public/assets/{md-history-DUYRtww_.js → md-history-Ddk04A_2.js} +1 -1
  55. package/src/web/public/assets/{member-picker-Bw2AsF1j.js → member-picker-Dsy1GH0E.js} +1 -1
  56. package/src/web/public/assets/{overview-B4pRZYIr.js → overview-ty9m-bCh.js} +1 -1
  57. package/src/web/public/assets/{progress-Bwcg-x19.js → progress-BQJhISlF.js} +2 -2
  58. package/src/web/public/assets/{repos-BO0Eoktc.js → repos-Di5InllN.js} +1 -1
  59. package/src/web/public/assets/{route-crumb-DWHcDjTH.js → route-crumb-g3leiQhY.js} +1 -1
  60. package/src/web/public/assets/{settings-BUSNdkTd.js → settings-CE-rlcXr.js} +3 -3
  61. package/src/web/public/assets/task-D97dEZdc.js +6 -0
  62. package/src/web/public/assets/{template-slots-D6x4JKZ3.js → template-slots-D40ponA2.js} +1 -1
  63. package/src/web/public/assets/{templates-CESTAUsK.js → templates-Ca1jXhnO.js} +1 -1
  64. package/src/web/public/assets/{upload-d5Uchr6Y.js → upload-BeiJetbd.js} +1 -1
  65. package/src/web/public/index.html +2 -2
  66. package/src/web/public/assets/dir-Cll78K45.js +0 -3
  67. package/src/web/public/assets/group-dtrdwnRv.js +0 -1
  68. package/src/web/public/assets/task-DrUzpfEg.js +0 -5
@@ -11,9 +11,13 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } fr
11
11
  import { Actions } from 'flexlayout-react';
12
12
  import { api } from '../../api/client.js';
13
13
  import { useToast } from '../../components/toast/index.jsx';
14
- import { useDialog } from '../../components/popup/index.jsx';
14
+ import { Modal, useDialog } from '../../components/popup/index.jsx';
15
15
  import { GLOBAL_KEY } from '../../modules/board/board-view.js';
16
- import { buildReopenText } from '../../modules/board/reopen-text.js';
16
+ import {
17
+ buildReopenText,
18
+ FEEDBACK_HEADING,
19
+ PLAIN_FEEDBACK_HEADING,
20
+ } from '../../modules/board/reopen-text.js';
17
21
  import { extractAckNodes } from '../../modules/board/ack-nodes.js';
18
22
  import ToolBar from '../../components/md/tool-bar.jsx';
19
23
  import { MdPanes } from '../../components/md/md-panes.jsx';
@@ -21,6 +25,7 @@ import AckRail from '../../components/md/ack-rail.jsx';
21
25
  import AttachBar from '../../components/md/attach-bar.jsx';
22
26
  import SelMenu from '../../components/md/sel-menu.jsx';
23
27
  import ShortcutSheet from '../../components/md/shortcut-sheet.jsx';
28
+ import { TaskChainModal } from '../../components/md/task-chain.jsx';
24
29
  import { useApp } from '../../app-context.jsx';
25
30
  import { openBesideMain, openPanel } from '../../workspace.js';
26
31
  import { filesToAttachments, persistAtt } from '../../components/md/attachments.js';
@@ -47,7 +52,7 @@ import {
47
52
  useDocs,
48
53
  } from '../../modules/md/doc-store.js';
49
54
 
50
- export default function PagePanel({ dirKey, task, beside = false, tabId, model }) {
55
+ export default function PagePanel({ dirKey, task, beside = false, tabId, model, historyId = null }) {
51
56
  const app = useApp() || {};
52
57
  const toast = useToast();
53
58
  const { dialog, node: dialogNode } = useDialog();
@@ -85,9 +90,10 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
85
90
  const goal = goalDraft || { duration: declaredGoal?.duration || '', prompt: declaredGoal?.prompt || '' };
86
91
  const goalEditable = isDraft || (!!taskRow && taskRow.status !== 'consumed');
87
92
 
88
- // ─── 验收条(完成任务):agent 的完成总结(ack)+ 用户回复(通行 / 重做 / 划线评论提详细问题)───
93
+ // ─── 验收条(完成任务):agent 的完成总结(ack)+ 用户回复(通行 / 反馈 / 划线评论)───
89
94
  // 「通行」只在本机记一笔(localStorage,per-viewer 的轻量状态):done 本身已是终态,
90
95
  // 验收与否不进队列 schema——「无更新则直接结束」的口径里,通行 = 不需要再做什么。
96
+ // 「反馈」(#75):**新开一条任务**(不是重做/就地重开),原完成任务留档不动。
91
97
  const reviewAckKey = `nx-kv/review/${scope}/${task}`;
92
98
  const [reviewAcked, setReviewAcked] = useState(() => {
93
99
  try {
@@ -114,10 +120,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
114
120
  setReviewAcked(true);
115
121
  toast('已验收');
116
122
  };
117
- /** 重做:走**正常评论模式**(不再弹窗输入框)——评论框开在正文末尾,
118
- 提交即把这条任务重开,反馈文字(加粗)带进正文。 */
119
- const redoTask = () => {
120
- // 浮层是 .mdw 内的绝对定位 → 坐标要相对容器(用条带相对容器的偏移)
123
+ /** 反馈:开评论框写意见;提交后**新建一条任务**(forkOf 指回本条),原任务不动。 */
124
+ const openFeedback = () => {
121
125
  const bar = reviewBarRef.current;
122
126
  const host = bar?.closest?.('.mdw');
123
127
  const b = bar?.getBoundingClientRect();
@@ -126,39 +130,98 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
126
130
  const y = b && h ? b.top - h.top - 190 : 120;
127
131
  setSelMenu({
128
132
  kind: 'task',
129
- text: '', // 重做针对整条任务,不锚定选区
133
+ text: '',
130
134
  comment: true,
131
- mode: 'redo',
135
+ mode: 'feedback',
132
136
  x: Math.min(window.innerWidth - 320, Math.max(8, x)),
133
137
  y: Math.min(window.innerHeight - 260, Math.max(8, y)),
134
138
  });
135
139
  };
136
- /** 评论框提交:重做模式 → 重开本任务(反馈加粗进正文);普通划线评论 → 开新任务 */
137
- const onCommentSubmit = (q) => {
138
- if (selMenu?.mode === 'redo') {
139
- submitRedo(q);
140
+ /** 统一提交入口:feedback → 新开任务;comment → 就地回写原任务(可带附件)。 */
141
+ const onCommentSubmit = (payload) => {
142
+ const p =
143
+ payload && typeof payload === 'object'
144
+ ? payload
145
+ : {
146
+ text: String(payload || ''),
147
+ mode: selMenu?.mode === 'feedback' || selMenu?.mode === 'redo' ? 'feedback' : 'comment',
148
+ quote: lastSel.current || '',
149
+ };
150
+ if (p.mode === 'feedback' || p.mode === 'redo' || selMenu?.mode === 'feedback' || selMenu?.mode === 'redo') {
151
+ spawnFeedbackTask(p);
140
152
  return;
141
153
  }
142
- spawnComment(q);
154
+ submitCommentInPlace(p);
143
155
  };
144
- const submitRedo = (feedback) => {
145
- const fb = String(feedback || '').trim();
156
+ /** 验收反馈 → 新开任务(#75):正文 = 原正文 + 上轮总结 + 本轮反馈;forkOf 指回本条。 */
157
+ const spawnFeedbackTask = ({ text: fbRaw, attachments = [], inserts = '' } = {}) => {
158
+ const fb = String(fbRaw || '').trim();
146
159
  closeSelMenu();
147
- if (!fb) {
148
- toast('写一下要改的地方');
160
+ if (!fb && !(attachments && attachments.length)) {
161
+ toast('写一下反馈');
149
162
  return;
150
163
  }
151
164
  const title = doc?.title || `#${task}`;
152
165
  guard(async () => {
153
- // 反馈是**追加**不是替换:reopen 的 text 是整段新正文,直接把反馈当正文发
154
- // 会把原任务丢掉。拼成「原正文 + 上一轮 ack 完成总结 + 验收反馈」——
155
- // 重做后验收条会消失,上轮总结若不落进正文就没人看得见了(agent 下一轮
156
- // 同样看不见:它只拿到正文)。反馈逐行加粗(用户口径:重开的任务要携带着
157
- // 反馈文字在正文中,最好加粗)。
166
+ let feedbackBody = fb || '(见附件)';
167
+ if (inserts) feedbackBody = `${feedbackBody}${inserts}`;
158
168
  const text = buildReopenText({
159
169
  base: doc?.body || '',
160
- feedback: fb,
170
+ feedback: feedbackBody,
161
171
  ackSummary: taskRow?.roundSummary || '',
172
+ feedbackHeading: FEEDBACK_HEADING,
173
+ bold: true,
174
+ });
175
+ const linkFields =
176
+ !isDraft && task != null && !/^draft/i.test(String(task))
177
+ ? { forkOf: String(task), forkKind: 'reopen' }
178
+ : {};
179
+ const res = await api('/api/localtasks', {
180
+ method: 'POST',
181
+ body: isGlobal
182
+ ? { global: true, text, ...linkFields }
183
+ : { cwd: topic?.cwd, text, ...linkFields },
184
+ });
185
+ const newId = String(res?.task?.id ?? res?.id ?? '');
186
+ if (!newId) {
187
+ toast('反馈已提交,但未拿到新任务编号');
188
+ refreshLocal();
189
+ return;
190
+ }
191
+ const landedKey = res?.key || dirKey;
192
+ saveDoc(docIdOf(scopeOf(landedKey), newId), { title: titleFromMd(text), body: text });
193
+ if (attachments?.length) persistAtt(newId, attachments);
194
+ toast(`已反馈「${title}」→ 新任务 #${newId}`);
195
+ refreshLocal();
196
+ if (app.openPage) app.openPage({ dirKey: landedKey, task: newId, name: `${title.slice(0, 24)}(反馈)` });
197
+ });
198
+ };
199
+ /** 划选评论 → 就地回写原任务(#74),可带附件。 */
200
+ const submitCommentInPlace = ({ text: fbRaw, attachments = [], inserts = '', quote } = {}) => {
201
+ const fb = String(fbRaw || '').trim();
202
+ const quoteText = String(quote || lastSel.current || '').trim();
203
+ closeSelMenu();
204
+ if (!fb && !(attachments && attachments.length)) {
205
+ toast('写一下要提的问题');
206
+ return;
207
+ }
208
+ if (!quoteText && !fb) {
209
+ toast('先划选一段再评论');
210
+ return;
211
+ }
212
+ const title = doc?.title || `#${task}`;
213
+ guard(async () => {
214
+ let feedbackBody = fb;
215
+ if (quoteText) {
216
+ feedbackBody = `> 锚定:\n> ${quoteText.replace(/\n/g, '\n> ')}\n\n${fb || '(见附件)'}`;
217
+ }
218
+ if (inserts) feedbackBody = `${feedbackBody || ''}${inserts}`;
219
+ const text = buildReopenText({
220
+ base: doc?.body || '',
221
+ feedback: feedbackBody,
222
+ ackSummary: '',
223
+ feedbackHeading: PLAIN_FEEDBACK_HEADING,
224
+ bold: false,
162
225
  });
163
226
  const res = await api('/api/localtasks/reopen', {
164
227
  method: 'POST',
@@ -166,25 +229,27 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
166
229
  ...(isGlobal ? { key: GLOBAL_KEY } : { cwd: topic?.cwd }),
167
230
  id: Number(task),
168
231
  text,
232
+ kind: 'comment',
233
+ quote: quoteText,
234
+ feedback: fb,
235
+ attachments: (attachments || []).map((a) => ({
236
+ id: a.id,
237
+ name: a.name,
238
+ type: a.type,
239
+ size: a.size,
240
+ url: a.url || '',
241
+ })),
169
242
  },
170
243
  });
171
- // 重开 = **新建一条任务**(新 md),旧任务归档留档(#59:状态单向)。
172
- // 所以:旧文档**不动**(那是历史),新正文写进**新任务自己的文档**,
173
- // 页签切到新任务——用户接着看的就是「这一轮要干的活」。
174
- // text 是拿 doc.body 拼的,未保存的编辑原样带在里面,不会被抹掉。
175
- // 归属改了会搬家(同保存路径,任务 #43)——文档与页签跟到新队列新号。
176
244
  const landedKey = res?.key || dirKey;
177
- const newId = String(res?.task?.id ?? task);
178
- const newDocId = docIdOf(scopeOf(landedKey), newId);
179
- saveDoc(newDocId, { title: titleFromMd(text), body: text });
180
- if (model && tabId) {
181
- model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: newId } }));
245
+ const sameId = String(res?.task?.id ?? task);
246
+ saveDoc(docIdOf(scopeOf(landedKey), sameId), { title: titleFromMd(text), body: text });
247
+ if (attachments?.length) persistAtt(sameId, [...(doc?.attachments || []), ...attachments]);
248
+ if (model && tabId && landedKey !== dirKey) {
249
+ model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: sameId } }));
182
250
  }
183
251
  setDirty(false);
184
- toast(
185
- `已重开「${title}」→ 新任务 #${newId}(旧任务归档留档)` +
186
- (res?.moved && res.name ? `;归属迁到「${res.name}」` : ''),
187
- );
252
+ toast(`已回写评论「${title}」#${sameId}`);
188
253
  refreshLocal();
189
254
  });
190
255
  };
@@ -236,6 +301,7 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
236
301
 
237
302
  const [selMenu, setSelMenu] = useState(null);
238
303
  const [showShortcuts, setShowShortcuts] = useState(false);
304
+ const [chainOpen, setChainOpen] = useState(false);
239
305
  const fileMdRef = useRef(null);
240
306
  const fileAttRef = useRef(null);
241
307
  const articleRef = useRef(null);
@@ -352,12 +418,154 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
352
418
  });
353
419
  }, [parentRef, model, app.model, toast]);
354
420
 
421
+ /** 任务链节点 → 旁路查看:history 快照 / 祖先或子任务正文 */
422
+ const openHistoryBeside = useCallback(
423
+ (node) => {
424
+ const m = model || app.model;
425
+ if (!m || isDraft) return;
426
+ if (node?.current) {
427
+ toast('当前节点就是本页');
428
+ return;
429
+ }
430
+ // 同任务 history 快照
431
+ if (node?.historyId != null) {
432
+ openBesideMain(m, {
433
+ component: 'page',
434
+ name: `链 #${task} · ${node.kind || node.historyId}`,
435
+ config: {
436
+ dirKey: dirKey || GLOBAL_KEY,
437
+ task: String(task),
438
+ historyId: Number(node.historyId),
439
+ },
440
+ });
441
+ return;
442
+ }
443
+ // fork 祖先 / 子任务:打开对应任务页(旁路)
444
+ if (node?.taskId != null && node?.dirKey) {
445
+ openBesideMain(m, {
446
+ component: 'page',
447
+ name: node.excerpt ? String(node.excerpt).slice(0, 24) : `#${node.taskId}`,
448
+ config: { dirKey: String(node.dirKey), task: String(node.taskId) },
449
+ });
450
+ return;
451
+ }
452
+ toast('这个节点没有可打开的内容');
453
+ },
454
+ [model, app.model, isDraft, dirKey, task, toast],
455
+ );
456
+
355
457
  const closeBesideSelf = useCallback(() => {
356
458
  const m = model || app.model;
357
459
  if (!m || !tabId) return;
358
460
  m.doAction(Actions.deleteTab(tabId));
359
461
  }, [model, app.model, tabId]);
360
462
 
463
+ // 任务链:优先 history;无 history 时用 forkOf 祖先/子任务(#76 反馈「看不到链」)
464
+ const [chainApi, setChainApi] = useState(null);
465
+ useEffect(() => {
466
+ if (isDraft || task == null || /^draft/i.test(String(task))) {
467
+ setChainApi(null);
468
+ return undefined;
469
+ }
470
+ let cancelled = false;
471
+ const q = isGlobal
472
+ ? `key=${encodeURIComponent(GLOBAL_KEY)}&id=${Number(task)}`
473
+ : `cwd=${encodeURIComponent(topic?.cwd || '')}&id=${Number(task)}`;
474
+ api(`/api/localtasks/chain?${q}`)
475
+ .then((d) => {
476
+ if (!cancelled) setChainApi(d);
477
+ })
478
+ .catch(() => {
479
+ if (!cancelled) setChainApi(null);
480
+ });
481
+ return () => {
482
+ cancelled = true;
483
+ };
484
+ }, [isDraft, task, isGlobal, topic?.cwd, taskRow?.history?.length, taskRow?.forkOf, taskRow?.reopenCount]);
485
+
486
+ const chainNodes = useMemo(() => {
487
+ if (isDraft || !taskRow) return [];
488
+ const tip =
489
+ String(taskRow.text || '')
490
+ .split('\n')
491
+ .map((l) => l.trim())
492
+ .find(Boolean) || '';
493
+ const tipEx = tip.replace(/^#+\s*/, '').slice(0, 100);
494
+
495
+ // 1) 同任务 history 链
496
+ const hist = Array.isArray(taskRow.history) ? taskRow.history : [];
497
+ if (hist.length) {
498
+ const nodes = hist.map((h) => ({
499
+ historyId: h.id,
500
+ kind: h.kind,
501
+ at: h.at,
502
+ excerpt: h.excerpt || h.feedback || '',
503
+ feedback: h.feedback,
504
+ quote: h.quote,
505
+ attachmentCount: (h.attachments || []).length,
506
+ current: false,
507
+ }));
508
+ nodes.push({
509
+ historyId: null,
510
+ kind: 'current',
511
+ at: taskRow.lastReopenedAt || taskRow.createdAt || '',
512
+ excerpt: tipEx,
513
+ attachmentCount: 0,
514
+ current: true,
515
+ });
516
+ return nodes;
517
+ }
518
+
519
+ // 2) fork 派生链(祖先 → 本条 → 子任务)
520
+ const ancestors = Array.isArray(chainApi?.ancestors) ? [...chainApi.ancestors].reverse() : [];
521
+ const children = Array.isArray(chainApi?.children) ? chainApi.children : [];
522
+ if (!ancestors.length && !children.length && !taskRow.forkOf) return [];
523
+ const nodes = [];
524
+ for (const a of ancestors) {
525
+ if (a.missing) continue;
526
+ nodes.push({
527
+ historyId: null,
528
+ kind: a.forkKind || 'origin',
529
+ at: a.createdAt || '',
530
+ excerpt: a.excerpt || `#${a.id}`,
531
+ attachmentCount: 0,
532
+ current: false,
533
+ taskId: a.id,
534
+ dirKey: a.key,
535
+ });
536
+ }
537
+ nodes.push({
538
+ historyId: null,
539
+ kind: 'current',
540
+ at: taskRow.createdAt || '',
541
+ excerpt: tipEx,
542
+ attachmentCount: 0,
543
+ current: true,
544
+ taskId: Number(task),
545
+ dirKey: dirKey || GLOBAL_KEY,
546
+ });
547
+ for (const c of children) {
548
+ nodes.push({
549
+ historyId: null,
550
+ kind: c.forkKind || 'comment',
551
+ at: c.createdAt || '',
552
+ excerpt: c.excerpt || `#${c.id}`,
553
+ attachmentCount: 0,
554
+ current: false,
555
+ taskId: c.id,
556
+ dirKey: c.key,
557
+ });
558
+ }
559
+ // 弹窗里即使只有当前节点也展示(说明这是链的尖)
560
+ return nodes;
561
+ }, [isDraft, taskRow, chainApi, task, dirKey]);
562
+
563
+ const historyNode = useMemo(() => {
564
+ if (historyId == null || !taskRow) return null;
565
+ const want = Number(historyId);
566
+ return (taskRow.history || []).find((h) => Number(h.id) === want) || null;
567
+ }, [historyId, taskRow]);
568
+
361
569
  const markDirty = useCallback(() => setDirty(true), []);
362
570
 
363
571
  /** 标题 + frontmatter 拼装(提交/贴图同步共用)——标题行永远在 FM 之后。 */
@@ -371,6 +579,27 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
371
579
  return hasFm ? withFrontmatter(bare, fm) : bare;
372
580
  };
373
581
 
582
+ // ─── 预览提示词(任务 #65)───
583
+ // 工具栏「更多 → 预览提示词」:把 agent 执行 get 时会收到的**原文**摆出来。
584
+ // 后端是只读接口(不领取 / 不写盘 / 不启动时间目标计时 / 不为附件发网),
585
+ // 排版与 CLI 取任务共用 tasktool/delivery-text.js 同一份代码。
586
+ const [preview, setPreview] = useState(null); // null | {busy} | {error} | {data}
587
+ const openPreview = useCallback(() => {
588
+ setPreview({ busy: true });
589
+ // 草稿还没落库:把编辑器里的正文送去渲染(走与提交相同的 composeText,
590
+ // 标题行 / frontmatter 的位置与真实落库一致,预览才不会假装干净)。
591
+ const body = {
592
+ cwd: isGlobal ? (topic?.cwd || undefined) : topic?.cwd,
593
+ key: isGlobal ? GLOBAL_KEY : dirKey,
594
+ ...(isDraft
595
+ ? { text: composeText((doc?.title || '').trim() || '未命名任务', doc?.body || '') }
596
+ : { id: Number(task) }),
597
+ };
598
+ api('/api/localtasks/preview', { method: 'POST', body })
599
+ .then((d) => setPreview({ data: d }))
600
+ .catch((e) => setPreview({ error: String(e.message || e) }));
601
+ }, [isGlobal, topic?.cwd, dirKey, isDraft, doc?.title, doc?.body, task]);
602
+
374
603
  // ─── 保存 / 提交 ───
375
604
  // 时间目标的落库口径:草稿 → POST 带 duration/goalPrompt(后端 sanitize 校验写法);
376
605
  // 已有任务 → 与服务端声明比对,有变化才发(duration 空 = 清除,clearGoal);
@@ -590,46 +819,46 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
590
819
  lastSel.current = '';
591
820
  };
592
821
 
593
- /** 划线评论 → **直接提交**成新任务:锚定选区原文,正文就是提出的问题。
822
+ /** 「更多 → 新任务」:新草稿**带着当前上下文**(工作组 + 归属项目)。
823
+ *
824
+ * 原来这里只是开一个新页签(nextDraftId),草稿正文是空模板、**没有 frontmatter**——
825
+ * 于是「在组内的任务里新建任务」会丢掉归属:新任务落进本目录队列,而不是组里那个
826
+ * 项目(任务 #64:「创建新任务会丢失相关的一个上下文」)。
594
827
  *
595
- * 两条口径(用户验收反馈 2026-11-04):
596
- * 1. 原任务带工作组语义(frontmatter 里的 board / project)→ 评论出的新任务
597
- * **也归该组**。不继承的话,这条问题会从组面板里掉出去——用户是在组里
598
- * 提问的,闭环断在半路。正文整块继承原 frontmatter(归属 + 介绍引用)。
599
- * 2. 评论**直接提交**,不再先落成草稿、让人再点一次提交。评论是提问不是
600
- * 写作,多一道编辑页就多一次流失;提交完再打开新任务页(看得到提交了什么)。
828
+ * 现在与组页「新增任务」同一套口径:正文 = 模板默认正文 + frontmatter(board/project)。
601
829
  */
602
- const spawnComment = (question) => {
603
- const quote = lastSel.current || '';
604
- const q = String(question || '').trim();
605
- if (!quote) {
606
- toast('先划选一段再评论');
607
- return;
608
- }
609
- if (!q) {
610
- toast('写一下要提的问题');
830
+ const newTask = () => {
831
+ const draftId = nextDraftId();
832
+ const docId = docIdOf(scopeOf(dirKey), draftId);
833
+ const fm = {};
834
+ if (boardCtx && boardCtx.board && boardCtx.board.id) fm.board = boardCtx.board.id;
835
+ if (docFm.project) fm.project = docFm.project;
836
+ saveDoc(docId, {
837
+ title: '',
838
+ body: withFrontmatter(tpl ? tpl.defaultBody() : '', fm),
839
+ });
840
+ app.openPage && app.openPage({ dirKey, task: draftId, name: '新任务' });
841
+ };
842
+
843
+ /** 「更多 → 克隆任务」:以当前任务为模板快速复制一条新任务(#70)。
844
+ * 只复制正文内容,**不带派生链**(forkOf 留空——那条语义属于评论/反馈派生),
845
+ * 也不继承时间目标与依赖;源任务不动,克隆后两条并存。 */
846
+ const cloneCur = () => {
847
+ if (isDraft || task == null || /^draft/i.test(String(task))) {
848
+ toast('草稿没有可克隆的队列任务');
611
849
  return;
612
850
  }
613
- const parent = doc?.title || topic?.name || '';
614
- const t = `问题:${q.slice(0, 28)}`;
615
- const raw = `# ${t}\n\n> 锚定自「${parent}」:\n> ${quote.replace(/\n/g, '\n> ')}\n\n## 问题\n${q}\n\n## 要做什么\n- [ ] …\n`;
616
- // 工作组语义继承 + 原文锚点(parent/parentDir):评论页可一键并排打开原文
617
- const parentFields = (!isDraft && task != null && !/^draft/i.test(String(task)))
618
- ? { parent: String(task), parentDir: dirKey || '' }
619
- : {};
620
- const b = withFrontmatter(raw, { ...docFm, ...parentFields });
621
851
  guard(async () => {
622
- // 落点 = 原任务所在队列(显式给 cwd:尊重当前落点,不被归属推导挪走);
623
- // 归属由正文 frontmatter 决定(服务端 fail-open 补介绍引用)。
624
- const res = await api('/api/localtasks', {
852
+ const res = await api('/api/localtasks/clone', {
625
853
  method: 'POST',
626
- body: isGlobal ? { global: true, text: b } : { cwd: topic?.cwd, text: b },
854
+ body: isGlobal ? { id: Number(task) } : { id: Number(task), cwd: topic?.cwd },
627
855
  });
628
- closeSelMenu();
629
- toast('已提交问题(评论)');
856
+ toast(`已克隆为新任务 #${res.task?.id ?? res.id}`);
630
857
  refreshLocal();
631
858
  const newId = res?.task?.id ?? res?.id;
632
- if (newId != null && app.openPage) app.openPage({ dirKey, task: String(newId), name: t });
859
+ if (newId != null && app.openPage) {
860
+ app.openPage({ dirKey, task: String(newId), name: `${(doc?.title || '任务').slice(0, 30)}(克隆)` });
861
+ }
633
862
  });
634
863
  };
635
864
 
@@ -763,6 +992,49 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
763
992
  return () => window.removeEventListener('keydown', onKey);
764
993
  }, [parentRef, beside, openParentBeside]);
765
994
 
995
+ // 链节点旁路:只读展示 history 快照(不占编辑文档)
996
+ if (historyId != null) {
997
+ const kindLab = { origin: '起点', reopen: '反馈', comment: '评论' }[historyNode?.kind] || '节点';
998
+ const html = historyNode
999
+ ? renderMarkdownHtml(historyNode.text || '', historyNode.attachments || [])
1000
+ : '';
1001
+ return (
1002
+ <div className="mdw is-beside">
1003
+ <div className="mdw-beside-h">
1004
+ <span className="mdw-beside-lab">链节点 · {kindLab} #{historyId}</span>
1005
+ <span className="grow" />
1006
+ <button
1007
+ type="button"
1008
+ className="iconbtn"
1009
+ title="关闭"
1010
+ aria-label="关闭"
1011
+ onClick={closeBesideSelf}
1012
+ >
1013
+ ×
1014
+ </button>
1015
+ </div>
1016
+ <div className="mdw-hist-ro">
1017
+ {!historyNode ? (
1018
+ <div className="muted">找不到链节点 #{historyId}</div>
1019
+ ) : (
1020
+ <>
1021
+ <div className="mdw-hist-meta">
1022
+ <span>{historyNode.at || '—'}</span>
1023
+ {historyNode.quote ? <span>锚定:{historyNode.quote.slice(0, 80)}</span> : null}
1024
+ {historyNode.feedback ? <span>反馈:{historyNode.feedback.slice(0, 80)}</span> : null}
1025
+ {historyNode.summary ? <span>上轮总结:{historyNode.summary.slice(0, 80)}</span> : null}
1026
+ </div>
1027
+ <article
1028
+ className="md-body"
1029
+ dangerouslySetInnerHTML={{ __html: html || '<p class="muted">(空)</p>' }}
1030
+ />
1031
+ </>
1032
+ )}
1033
+ </div>
1034
+ </div>
1035
+ );
1036
+ }
1037
+
766
1038
  // 读不到文档分两种:**还在读**(队列首轮没回来)与**确实没有这一条**(被删 / 深链写错)。
767
1039
  // 后者不该永远转圈——给一句实话 + 一个出口(回目录)。
768
1040
  if (!doc) {
@@ -790,6 +1062,13 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
790
1062
  return (
791
1063
  <div className={`mdw${beside ? ' is-beside' : ''}`} data-mode={doc.mode || 'split'} onMouseUp={onPreviewMouseUp}>
792
1064
  {dialogNode}
1065
+ {preview && <PreviewModal state={preview} onClose={() => setPreview(null)} />}
1066
+ <TaskChainModal
1067
+ open={chainOpen}
1068
+ nodes={chainNodes}
1069
+ onOpenNode={openHistoryBeside}
1070
+ onClose={() => setChainOpen(false)}
1071
+ />
793
1072
  {beside && (
794
1073
  <div className="mdw-beside-h">
795
1074
  <span className="mdw-beside-lab">原文(旁路)</span>
@@ -895,16 +1174,19 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
895
1174
  onAtt={() => pickAtt('image/*,.pdf,.zip,.txt,.json,.csv')}
896
1175
  onShortcuts={() => setShowShortcuts(true)}
897
1176
  onImport={() => fileMdRef.current?.click()}
898
- onNew={() => app.openPage && app.openPage({ dirKey, task: nextDraftId(), name: '新任务' })}
1177
+ onNew={newTask}
899
1178
  onMark={openCommentFromToolbar}
900
1179
  onDraft={() => toast('草稿随页签保留(刷新后需从侧栏或页签重新打开)')}
901
1180
  onSubmit={submit}
902
1181
  onDelete={isDraft ? null : delTask}
903
1182
  onProg={openProgress}
1183
+ onPreview={openPreview}
1184
+ onClone={isDraft ? null : cloneCur}
904
1185
  onSource={parentRef ? openParentBeside : null}
905
1186
  onOverview={() => app.onNavigate && app.onNavigate('#/overview')}
906
1187
  onFormat={(op) => editorApiRef.current?.format?.(op)}
907
1188
  onTurn={(id2) => editorApiRef.current?.turn?.(id2)}
1189
+ onChain={isDraft ? null : () => setChainOpen(true)}
908
1190
  />
909
1191
 
910
1192
  <MdPanes
@@ -937,8 +1219,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
937
1219
  />
938
1220
 
939
1221
  {/* 验收条:已完成任务的 ack 卡——放在**正文末尾**(用户口径):读完正文
940
- 正好看到 agent 的完成总结,等你回复——划选正文评论 = 提详细问题(生成
941
- 新任务);重做 = 评论模式下带反馈重开;通行 = 验收通过。 */}
1222
+ 正好看到 agent 的完成总结,等你回复——反馈 = 新开任务;划选评论 = 回写
1223
+ 本任务;通行 = 验收通过。 */}
942
1224
  {!isDraft && taskRow?.completedAt && (
943
1225
  <div className="mdw-review" ref={reviewBarRef}>
944
1226
  <div className="mdw-review-main">
@@ -969,8 +1251,8 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
969
1251
  <span className="mdw-review-ok">已验收</span>
970
1252
  ) : (
971
1253
  <>
972
- <button type="button" className="ghost" onClick={redoTask}>
973
- 重做(带反馈)
1254
+ <button type="button" className="ghost" onClick={openFeedback} title="新开一条任务携带反馈(原任务不动)">
1255
+ 反馈
974
1256
  </button>
975
1257
  <button type="button" className="primary" onClick={ackReview}>
976
1258
  通行
@@ -1028,3 +1310,86 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model }
1028
1310
  </div>
1029
1311
  );
1030
1312
  }
1313
+
1314
+ /**
1315
+ * 预览弹层(任务 #65):「agent 执行 get 会收到的提示词」。
1316
+ *
1317
+ * 只展示服务端渲染好的原文(data.rendered)+ 段落来源,**不在前端二次拼装**——
1318
+ * 前端一拼就会与真实交付漂移,而预览的全部价值就是「所见即所得」。
1319
+ */
1320
+ function PreviewModal({ state, onClose }) {
1321
+ const toast = useToast();
1322
+ const data = state?.data;
1323
+ const copy = async () => {
1324
+ try {
1325
+ await navigator.clipboard.writeText(String(data?.rendered || ''));
1326
+ toast('已复制原文');
1327
+ } catch {
1328
+ toast('复制失败(剪贴板不可用)');
1329
+ }
1330
+ };
1331
+ const sw = data?.switches || {};
1332
+ const swLine = data
1333
+ ? [
1334
+ `回调提示词 ${sw.suffix?.on ? `开(${sw.suffix.count} 条)` : '关'}`,
1335
+ `ack ${sw.ack?.on ? `开(${sw.ack.count} 条)` : '关'}`,
1336
+ `交付上下文 ${sw.deliveryTemplate?.custom ? '自定义' : '内置默认'}`,
1337
+ `持续 get ${data.getLoop?.enabled ? `开(${data.getLoop.waitMinutes} 分钟)` : '关'}`,
1338
+ ].join(' · ')
1339
+ : '';
1340
+ const title = data
1341
+ ? `预览:agent 执行 get 会收到的提示词${data.task?.id ? ` · #${data.task.id}` : ' · 草稿'}`
1342
+ : '预览:agent 执行 get 会收到的提示词';
1343
+ return (
1344
+ <Modal
1345
+ title={title}
1346
+ size='wide'
1347
+ onClose={onClose}
1348
+ footer={
1349
+ <>
1350
+ <span className='mdw-prev-hint'>与 CLI 取任务共用同一份排版;不含「已取得下一条任务…」头部行。</span>
1351
+ <span className='grow' />
1352
+ <button type='button' className='btn ghost sm' onClick={copy} disabled={!data}>复制原文</button>
1353
+ <button type='button' className='btn sm' onClick={onClose}>关闭</button>
1354
+ </>
1355
+ }
1356
+ >
1357
+ {state.busy && <div className='mdw-prev-note'>渲染中…</div>}
1358
+ {state.error && (
1359
+ <div className='mdw-prev-note'>
1360
+ 预览失败:{state.error}
1361
+ {/* 「接口不存在」= 正在跑的 serve 进程比页面资产旧(路由启动时加载、
1362
+ 资产现读磁盘,#65 验收反馈实锤过这个 404)——引导重启,别让它
1363
+ 看起来像瞬时故障。与 overview 批量删除 / use-templates 同一处理。 */}
1364
+ {/接口不存在/.test(String(state.error)) && (
1365
+ <div className='mdw-prev-hint'>
1366
+ 本机面板服务较旧:重启面板(结束当前 serve 进程后重新启动)即可生效,刷新页面不够。
1367
+ </div>
1368
+ )}
1369
+ </div>
1370
+ )}
1371
+ {data && (
1372
+ <>
1373
+ <pre className='mdw-prev-body'>{data.rendered || ''}</pre>
1374
+ {data.segments?.length ? (
1375
+ <details className='mdw-prev-seg'>
1376
+ <summary>段落来源({data.segments.length} 段)</summary>
1377
+ <ol>
1378
+ {data.segments.map((s, i) => (
1379
+ <li key={i}>
1380
+ <span className='mdw-prev-seg-lab'>{s.label}</span>
1381
+ <span className='mdw-prev-seg-n'>{String(s.text || '').length} 字</span>
1382
+ </li>
1383
+ ))}
1384
+ </ol>
1385
+ <div className='mdw-prev-note'>改这些段去「设置 → 提示词 / 模板」;「持续 get」在项目级设置里。</div>
1386
+ </details>
1387
+ ) : (
1388
+ <div className='mdw-prev-note'>当前没有任何模板段:交付时就只有任务正文。</div>
1389
+ )}
1390
+ <div className='mdw-prev-switch'>{swLine}</div>
1391
+ </>
1392
+ )}
1393
+ </Modal>
1394
+ );
1395
+ }