nx-kv 0.26.0 → 0.27.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 (52) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/package.json +1 -1
  3. package/src/modules/bundled/index.js +34 -15
  4. package/src/modules/bundled/service.js +32 -2
  5. package/src/modules/localtask/index.js +16 -1
  6. package/src/modules/localtask/store-io.js +10 -1
  7. package/src/modules/localtask/task-lifecycle.js +24 -0
  8. package/src/modules/localtask/task-templates.js +17 -0
  9. package/src/modules/localtask/topics.js +8 -3
  10. package/src/modules/tasktool/attach.js +50 -14
  11. package/src/modules/tasktool/delivery-template.js +20 -2
  12. package/src/modules/tasktool/preview.js +1 -0
  13. package/src/modules/tasktool/wait.js +46 -8
  14. package/src/shared/feedback-text.js +57 -0
  15. package/src/web/frontend/App.jsx +3 -10
  16. package/src/web/frontend/components/layout/breadcrumb.jsx +1 -1
  17. package/src/web/frontend/components/layout/crumbs.js +15 -15
  18. package/src/web/frontend/components/md/tool-bar.jsx +39 -152
  19. package/src/web/frontend/modules/board/reopen-text.js +17 -17
  20. package/src/web/frontend/modules/md/style.css +18 -36
  21. package/src/web/frontend/page/dir/index.jsx +40 -14
  22. package/src/web/frontend/page/dir/task.jsx +116 -60
  23. package/src/web/frontend/page/settings/prompts-section.jsx +214 -5
  24. package/src/web/frontend/page/settings/style.css +13 -0
  25. package/src/web/public/assets/{Introduction-ka0UxW_S.js → Introduction-vTffOL-5.js} +1 -1
  26. package/src/web/public/assets/{cloud-y1mZIdlN.js → cloud-truDniwE.js} +1 -1
  27. package/src/web/public/assets/{dag-CiMSs7uT.js → dag-BPV2Yvmk.js} +1 -1
  28. package/src/web/public/assets/{dir-DKzzrY8P.js → dir-Cmrrc252.js} +3 -3
  29. package/src/web/public/assets/{group-DOLdLkaj.js → group-B26fV4Ec.js} +1 -1
  30. package/src/web/public/assets/{index-CbZfbzqr.js → index-CFkF2w23.js} +2 -2
  31. package/src/web/public/assets/index-DUxHMjZA.css +1 -0
  32. package/src/web/public/assets/{md-edit-ops-Bl0Zx0aJ.js → md-edit-ops-BIXUZ5BM.js} +1 -1
  33. package/src/web/public/assets/md-history-BLnTGoI5.js +5 -0
  34. package/src/web/public/assets/{member-picker-Dsy1GH0E.js → member-picker-CNGyhd0r.js} +1 -1
  35. package/src/web/public/assets/{overview-ty9m-bCh.js → overview-CRPbHHGF.js} +1 -1
  36. package/src/web/public/assets/{progress-BQJhISlF.js → progress-CNgMymPb.js} +1 -1
  37. package/src/web/public/assets/reopen-text-DIFfS71D.js +6 -0
  38. package/src/web/public/assets/{repos-Di5InllN.js → repos-CPSsUWZ5.js} +1 -1
  39. package/src/web/public/assets/route-crumb-DTo_wUoT.js +1 -0
  40. package/src/web/public/assets/settings-BQ3gTrIV.js +12 -0
  41. package/src/web/public/assets/{settings-CRK86fnJ.css → settings-knWtG9Kc.css} +1 -1
  42. package/src/web/public/assets/task-D_7iKWwt.js +7 -0
  43. package/src/web/public/assets/{template-slots-D40ponA2.js → template-slots-Bc70bnzR.js} +1 -1
  44. package/src/web/public/assets/{templates-Ca1jXhnO.js → templates-ChQO154-.js} +1 -1
  45. package/src/web/public/assets/{upload-BeiJetbd.js → upload-CzUtsVcG.js} +1 -1
  46. package/src/web/public/index.html +2 -2
  47. package/src/web/public/assets/index-DUvCgdUV.css +0 -1
  48. package/src/web/public/assets/md-history-Ddk04A_2.js +0 -5
  49. package/src/web/public/assets/reopen-text-DSB76_rF.js +0 -5
  50. package/src/web/public/assets/route-crumb-g3leiQhY.js +0 -1
  51. package/src/web/public/assets/settings-CE-rlcXr.js +0 -8
  52. package/src/web/public/assets/task-D97dEZdc.js +0 -6
@@ -158,6 +158,16 @@ export default function DirPanel({ dirKey }) {
158
158
  { label: '管理模板…', icon: 'gear', onClick: openTplPanel },
159
159
  ];
160
160
 
161
+ // #79:反馈的 base 以**服务端当前正文**为准——列表行的 t.text 是 rows 快照,
162
+ // 可能落后于盘上(别的会话改过 / 上一轮重开追加过),拿旧正文拼回去就是丢数据。
163
+ const fetchServerTask = async (t) => {
164
+ if (t == null) return null;
165
+ const q = isGlobal
166
+ ? `key=${encodeURIComponent(GLOBAL_KEY)}&id=${Number(t.id)}`
167
+ : `cwd=${encodeURIComponent(topic?.cwd || '')}&id=${Number(t.id)}`;
168
+ return api(`/api/localtasks/item?${q}`).catch(() => null);
169
+ };
170
+
161
171
  const reopenTask = (t) => {
162
172
  if (!t) return;
163
173
  const title = (t.text || '').split('\n').find((l) => l.trim()) || `#${t.id}`;
@@ -172,20 +182,29 @@ export default function DirPanel({ dirKey }) {
172
182
  });
173
183
  if (body === null || body === undefined) return;
174
184
  const fb = String(body).trim();
175
- const ackSummary = acked ? t.roundSummary || '' : '';
176
- const text =
177
- fb || ackSummary
185
+ // #79:base 取服务端当前正文(取不到才退回 rows 快照);两头的都没有就中止。
186
+ const fresh = await fetchServerTask(t);
187
+ const baseText = String(fresh?.text ?? '').trim() || String(t.text || '').trim();
188
+ const ackSummary = acked ? (fresh?.roundSummary || t.roundSummary || '') : '';
189
+ if (!fb && !acked && !baseText) {
190
+ // 只重开(不改正文)不需要 base;带反馈但拿不到正文时不能瞎拼
191
+ toast('拿不到任务当前正文,已取消(防止丢内容)');
192
+ return;
193
+ }
194
+
195
+ // #75:已完成 → 反馈 = **新开任务**(forkOf 指回本条),原任务留档不动。
196
+ // 新任务的正文 = 完整之前的任务 + 上轮总结 + 本轮反馈(面板拼装——新任务
197
+ // 的落点内容只能整篇给)。
198
+ if (acked) {
199
+ const text = fb
178
200
  ? buildReopenText({
179
- base: t.text || '',
201
+ base: baseText,
180
202
  feedback: fb,
181
203
  ackSummary,
182
- feedbackHeading: acked ? FEEDBACK_HEADING : PLAIN_FEEDBACK_HEADING,
183
- bold: acked,
204
+ feedbackHeading: FEEDBACK_HEADING,
205
+ bold: true,
184
206
  })
185
207
  : '';
186
-
187
- // #75:已完成 → 反馈 = **新开任务**(forkOf 指回本条),原任务留档不动
188
- if (acked) {
189
208
  if (!text) {
190
209
  toast('写一下反馈');
191
210
  return;
@@ -204,20 +223,27 @@ export default function DirPanel({ dirKey }) {
204
223
  return;
205
224
  }
206
225
 
207
- // 未完成:就地回写(#74 reopen)
226
+ // 未完成:就地回写(#74 reopen)。#79:纯反馈不传 text——服务端把反馈段
227
+ // 原子追加到盘上当前正文;「只重开不改正文」(无反馈)维持只翻状态。
208
228
  const res = await api('/api/localtasks/reopen', {
209
229
  method: 'POST',
210
230
  body: {
211
- ...(isGlobal ? { key: GLOBAL_KEY } : { cwd: topic.cwd }),
231
+ ...scopeBody(),
212
232
  id: t.id,
213
233
  kind: 'reopen',
214
- feedback: fb,
215
- ...(text ? { text } : {}),
234
+ ...(fb
235
+ ? {
236
+ feedback: fb,
237
+ feedbackHeading: PLAIN_FEEDBACK_HEADING,
238
+ feedbackBold: false,
239
+ }
240
+ : {}),
216
241
  },
217
242
  });
218
243
  const landedKey = res?.key || dirKey;
219
244
  const sameId = String(res?.task?.id ?? t.id);
220
- if (text) saveDoc(docIdOf(scopeOf(landedKey), sameId), { body: text });
245
+ const finalText = String(res?.task?.text ?? '');
246
+ if (finalText) saveDoc(docIdOf(scopeOf(landedKey), sameId), { body: finalText });
221
247
  toast(
222
248
  `已回写「${title.replace(/^#\s*/, '')}」#${sameId}` +
223
249
  (res?.moved && res.name ? `;归属迁到「${res.name}」` : ''),
@@ -17,6 +17,7 @@ import {
17
17
  buildReopenText,
18
18
  FEEDBACK_HEADING,
19
19
  PLAIN_FEEDBACK_HEADING,
20
+ quoteBlock,
20
21
  } from '../../modules/board/reopen-text.js';
21
22
  import { extractAckNodes } from '../../modules/board/ack-nodes.js';
22
23
  import ToolBar from '../../components/md/tool-bar.jsx';
@@ -153,7 +154,19 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
153
154
  }
154
155
  submitCommentInPlace(p);
155
156
  };
156
- /** 验收反馈 → 新开任务(#75):正文 = 原正文 + 上轮总结 + 本轮反馈;forkOf 指回本条。 */
157
+ /** 服务端当前任务(#79):评论/反馈的 base 以**盘上正文**为准——会话 doc 可能
158
+ * 过期(别的会话改过 / 上一轮重开追加过 / 首轮还没加载完),拿旧正文拼回去
159
+ * 整篇重写就是「评论一次丢一次」。草稿没有服务端正文,返回 null。 */
160
+ const fetchServerTask = async () => {
161
+ if (isDraft || task == null || /^draft/i.test(String(task))) return null;
162
+ const q = isGlobal
163
+ ? `key=${encodeURIComponent(GLOBAL_KEY)}&id=${Number(task)}`
164
+ : `cwd=${encodeURIComponent(topic?.cwd || '')}&id=${Number(task)}`;
165
+ return api(`/api/localtasks/item?${q}`).catch(() => null);
166
+ };
167
+ /** 验收反馈 → 新开任务(#75):正文 = 完整之前的任务 + 上轮总结 + 本轮反馈;
168
+ * forkOf 指回本条。#79:base 取服务端当前正文,取不到才退回会话 doc——
169
+ * 两头都空就中止(真实任务),绝不发一条丢掉原任务的空壳反馈。 */
157
170
  const spawnFeedbackTask = ({ text: fbRaw, attachments = [], inserts = '' } = {}) => {
158
171
  const fb = String(fbRaw || '').trim();
159
172
  closeSelMenu();
@@ -163,12 +176,18 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
163
176
  }
164
177
  const title = doc?.title || `#${task}`;
165
178
  guard(async () => {
179
+ const fresh = await fetchServerTask();
180
+ const baseText = String(fresh?.text ?? '').trim() || String(doc?.body ?? '').trim();
181
+ if (!baseText && !isDraft) {
182
+ toast('拿不到任务当前正文,已取消反馈(防止丢内容)');
183
+ return;
184
+ }
166
185
  let feedbackBody = fb || '(见附件)';
167
186
  if (inserts) feedbackBody = `${feedbackBody}${inserts}`;
168
187
  const text = buildReopenText({
169
- base: doc?.body || '',
188
+ base: baseText,
170
189
  feedback: feedbackBody,
171
- ackSummary: taskRow?.roundSummary || '',
190
+ ackSummary: fresh?.roundSummary || taskRow?.roundSummary || '',
172
191
  feedbackHeading: FEEDBACK_HEADING,
173
192
  bold: true,
174
193
  });
@@ -196,7 +215,11 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
196
215
  if (app.openPage) app.openPage({ dirKey: landedKey, task: newId, name: `${title.slice(0, 24)}(反馈)` });
197
216
  });
198
217
  };
199
- /** 划选评论 → 就地回写原任务(#74),可带附件。 */
218
+ /** 划选评论 → 就地回写原任务(#74),可带附件。
219
+ * #79 防丢数据:第一个区块永远是**完整的之前的任务**,接着才是引用字符和评论。
220
+ * 干净态(无未保存编辑、无附件片段)干脆不传 text——服务端把评论段原子追加到
221
+ * 盘上正文,谁先改过都不丢;带未保存编辑 / 附件片段时才由面板拉服务端最新正文
222
+ * 整篇回写(编辑器里正在写的内容以编辑器为准)。 */
200
223
  const submitCommentInPlace = ({ text: fbRaw, attachments = [], inserts = '', quote } = {}) => {
201
224
  const fb = String(fbRaw || '').trim();
202
225
  const quoteText = String(quote || lastSel.current || '').trim();
@@ -209,26 +232,41 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
209
232
  toast('先划选一段再评论');
210
233
  return;
211
234
  }
235
+ if (isDraft || task == null || /^draft/i.test(String(task))) {
236
+ toast('草稿先提交成任务再评论');
237
+ return;
238
+ }
212
239
  const title = doc?.title || `#${task}`;
213
240
  guard(async () => {
214
- let feedbackBody = fb;
215
- if (quoteText) {
216
- feedbackBody = `> 锚定:\n> ${quoteText.replace(/\n/g, '\n> ')}\n\n${fb || '(见附件)'}`;
241
+ // 纯文字 + 无未保存编辑 → 服务端拼装(不传 text,base = 服务端正文)
242
+ const serverCompose = !dirty && !inserts && !(attachments && attachments.length);
243
+ let text;
244
+ if (!serverCompose) {
245
+ const fresh = await fetchServerTask();
246
+ const baseText = String(fresh?.text ?? '').trim() || String(doc?.body ?? '').trim();
247
+ if (!baseText) {
248
+ toast('拿不到任务当前正文,已取消评论(防止丢内容)');
249
+ return;
250
+ }
251
+ const feedbackBody = [
252
+ quoteBlock(quoteText),
253
+ fb || '(见附件)',
254
+ inserts,
255
+ ].filter(Boolean).join('\n\n');
256
+ text = buildReopenText({
257
+ base: baseText,
258
+ feedback: feedbackBody,
259
+ ackSummary: '',
260
+ feedbackHeading: PLAIN_FEEDBACK_HEADING,
261
+ bold: false,
262
+ });
217
263
  }
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,
225
- });
226
264
  const res = await api('/api/localtasks/reopen', {
227
265
  method: 'POST',
228
266
  body: {
229
267
  ...(isGlobal ? { key: GLOBAL_KEY } : { cwd: topic?.cwd }),
230
268
  id: Number(task),
231
- text,
269
+ ...(text ? { text } : {}),
232
270
  kind: 'comment',
233
271
  quote: quoteText,
234
272
  feedback: fb,
@@ -241,9 +279,13 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
241
279
  })),
242
280
  },
243
281
  });
282
+ // 回写后的正文以服务端为准刷回编辑器(服务端拼装时新段只有服务端知道)
244
283
  const landedKey = res?.key || dirKey;
245
284
  const sameId = String(res?.task?.id ?? task);
246
- saveDoc(docIdOf(scopeOf(landedKey), sameId), { title: titleFromMd(text), body: text });
285
+ const finalText = String(res?.task?.text ?? text ?? '');
286
+ if (finalText) {
287
+ saveDoc(docIdOf(scopeOf(landedKey), sameId), { title: titleFromMd(finalText), body: finalText });
288
+ }
247
289
  if (attachments?.length) persistAtt(sameId, [...(doc?.attachments || []), ...attachments]);
248
290
  if (model && tabId && landedKey !== dirKey) {
249
291
  model.doAction(Actions.updateNodeAttributes(tabId, { config: { dirKey: landedKey, task: sameId } }));
@@ -1059,6 +1101,51 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
1059
1101
  );
1060
1102
  }
1061
1103
 
1104
+ // ─── 时间目标 UI(#78)───
1105
+ // 设置收进「更多」菜单(goalMenu),外部只以勋章回显(goalBadge)——头部不再
1106
+ // 给整行;没设(无草稿值也无声明)勋章就不出现,零噪音。勋章跟随 goalDraft
1107
+ // (正在编辑的草稿值),落库仍走 submit 里的 goalPatchOf 同一套口径。
1108
+ const goalDur = (goal.duration || '').trim();
1109
+ const goalPrompt = (goal.prompt || '').trim();
1110
+ const goalBadge = (goalDur || goalPrompt)
1111
+ ? {
1112
+ label: `⏱ ${goalDur || '目标'}`,
1113
+ title: goalPrompt
1114
+ || (goalEditable ? '任务级时间目标(在「更多」里设置;领取即计时)' : '已领取计时,声明不可改'),
1115
+ }
1116
+ : null;
1117
+ const goalMenu = (goalEditable || declaredGoal) ? (
1118
+ <div className="mdw-goal-menu">
1119
+ <div className="mdw-goal-menu-lab">时间目标</div>
1120
+ {goalEditable ? (
1121
+ <>
1122
+ <input
1123
+ className="mdw-goal-dur mono"
1124
+ value={goal.duration}
1125
+ placeholder="2h / 90m / 30分钟,留空不带"
1126
+ onChange={(e) => {
1127
+ setGoalDraft({ ...goal, duration: e.target.value });
1128
+ markDirty();
1129
+ }}
1130
+ />
1131
+ <input
1132
+ className="mdw-goal-prompt"
1133
+ value={goal.prompt}
1134
+ placeholder="附加要求(可选,随 check 指令一起固化)"
1135
+ onChange={(e) => {
1136
+ setGoalDraft({ ...goal, prompt: e.target.value });
1137
+ markDirty();
1138
+ }}
1139
+ />
1140
+ </>
1141
+ ) : (
1142
+ <span className="mdw-goal-ro mono" title={declaredGoal?.prompt || '已领取计时,声明不可改'}>
1143
+ {declaredGoal?.duration || '—'} · 已领取计时
1144
+ </span>
1145
+ )}
1146
+ </div>
1147
+ ) : null;
1148
+
1062
1149
  return (
1063
1150
  <div className={`mdw${beside ? ' is-beside' : ''}`} data-mode={doc.mode || 'split'} onMouseUp={onPreviewMouseUp}>
1064
1151
  {dialogNode}
@@ -1098,40 +1185,6 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
1098
1185
  </div>
1099
1186
  </div>
1100
1187
 
1101
- {/* 时间目标行:可编辑(草稿/未领取)或只读回显(已领取计时中)。整行在没有
1102
- 任何目标信息且不可编辑时隐藏,不给已完成页面添噪音。 */}
1103
- {(goalEditable || declaredGoal) && (
1104
- <div className="mdw-goal">
1105
- <span className="mdw-goal-lab" title="任务级 timegoal:领取即计时,未到点不许标完成">⏱ 时间目标</span>
1106
- {goalEditable ? (
1107
- <>
1108
- <input
1109
- className="mdw-goal-dur mono"
1110
- value={goal.duration}
1111
- placeholder="2h / 90m / 30分钟,留空不带"
1112
- onChange={(e) => {
1113
- setGoalDraft({ ...goal, duration: e.target.value });
1114
- markDirty();
1115
- }}
1116
- />
1117
- <input
1118
- className="mdw-goal-prompt"
1119
- value={goal.prompt}
1120
- placeholder="附加要求(可选,随 check 指令一起固化)"
1121
- onChange={(e) => {
1122
- setGoalDraft({ ...goal, prompt: e.target.value });
1123
- markDirty();
1124
- }}
1125
- />
1126
- </>
1127
- ) : (
1128
- <span className="mdw-goal-ro mono" title={declaredGoal?.prompt || '已领取计时,声明不可改'}>
1129
- {declaredGoal?.duration || '—'} · 已领取计时
1130
- </span>
1131
- )}
1132
- </div>
1133
- )}
1134
-
1135
1188
  {/* 归属项目(组任务):组面板「新增任务」带 frontmatter 的草稿/任务才显示。
1136
1189
  草稿与未领取可改(改写 frontmatter),已领取只读;提交按 project 路由队列。 */}
1137
1190
  {boardCtx && (
@@ -1165,28 +1218,31 @@ export default function PagePanel({ dirKey, task, beside = false, tabId, model,
1165
1218
  </div>
1166
1219
  )}
1167
1220
 
1221
+ {/* #78:头部只留 新任务 / 提交;其余动作(含进程/原文/快捷键)全进「更多」,
1222
+ 时间目标在「更多」顶部编辑、外部勋章回显。MD 格式条撤出头部——
1223
+ 划选浮条 + 行首 / 命令 + Ctrl/⌘B 等快捷键已覆盖。 */}
1168
1224
  <ToolBar
1169
1225
  mode={doc.mode}
1170
1226
  onMode={(m) => saveDoc(id, { mode: m })}
1171
1227
  showMark={doc.mode !== 'edit'}
1172
1228
  submitLabel={isDraft ? '提交为任务' : '保存并同步'}
1229
+ onNew={newTask}
1230
+ onSubmit={submit}
1231
+ onChain={isDraft ? null : () => setChainOpen(true)}
1232
+ onPreview={openPreview}
1173
1233
  onImg={() => pickAtt('image/*')}
1174
1234
  onAtt={() => pickAtt('image/*,.pdf,.zip,.txt,.json,.csv')}
1175
- onShortcuts={() => setShowShortcuts(true)}
1176
1235
  onImport={() => fileMdRef.current?.click()}
1177
- onNew={newTask}
1236
+ onClone={isDraft ? null : cloneCur}
1178
1237
  onMark={openCommentFromToolbar}
1179
1238
  onDraft={() => toast('草稿随页签保留(刷新后需从侧栏或页签重新打开)')}
1180
- onSubmit={submit}
1181
1239
  onDelete={isDraft ? null : delTask}
1240
+ onOverview={() => app.onNavigate && app.onNavigate('#/overview')}
1182
1241
  onProg={openProgress}
1183
- onPreview={openPreview}
1184
- onClone={isDraft ? null : cloneCur}
1185
1242
  onSource={parentRef ? openParentBeside : null}
1186
- onOverview={() => app.onNavigate && app.onNavigate('#/overview')}
1187
- onFormat={(op) => editorApiRef.current?.format?.(op)}
1188
- onTurn={(id2) => editorApiRef.current?.turn?.(id2)}
1189
- onChain={isDraft ? null : () => setChainOpen(true)}
1243
+ onShortcuts={() => setShowShortcuts(true)}
1244
+ goalBadge={goalBadge}
1245
+ goalMenu={goalMenu}
1190
1246
  />
1191
1247
 
1192
1248
  <MdPanes
@@ -8,6 +8,7 @@
8
8
  import { useCallback, useEffect, useState } from 'react';
9
9
  import { api } from '../../api/client.js';
10
10
  import { useToast } from '../../components/toast/index.jsx';
11
+ import { useDialog } from '../../components/popup/index.jsx';
11
12
  import { useTemplates } from '../../modules/md/use-templates.js';
12
13
  import { PromptItemsEditor } from '../../modules/prompts/prompt-editor.jsx';
13
14
  import { TemplateSlotsEditor } from '../../modules/prompts/template-slots.jsx';
@@ -16,15 +17,202 @@ import { renderTemplateBody } from '../../modules/prompts/placeholders.js';
16
17
  const MAX_ITEMS = 10; // 与服务端 clampTaskSuffixList / clampAckPromptList 一致
17
18
 
18
19
  const TABS = [
20
+ { id: 'vars', label: '变量字典' },
19
21
  { id: 'template', label: '任务模板' },
20
22
  { id: 'suffix', label: '回调提示词' },
21
23
  { id: 'ack', label: 'ack 总结' },
24
+ { id: 'attach', label: '附件提示词' },
22
25
  { id: 'delivery', label: '交付上下文' },
23
26
  ];
24
27
 
28
+ // ─── 变量字典(任务 #82)─────────────────────────────────────────────
29
+ //
30
+ // 所有提示词模板的占位符都聚在这一页:每份模板管什么、在哪配、能用哪些变量、
31
+ // 每个变量装的是什么。第一页放它——「先认识变量,再动手改模板」。
32
+
33
+ /** 字典表:两列(变量 / 含义),行数据驱动的纯展示。 */
34
+ function VarsTable({ rows }) {
35
+ return (
36
+ <div className="setp-vars-wrap">
37
+ <table>
38
+ <tbody>
39
+ {rows.map(([v, desc]) => (
40
+ <tr key={v}>
41
+ <td>
42
+ <code>{v}</code>
43
+ </td>
44
+ <td>{desc}</td>
45
+ </tr>
46
+ ))}
47
+ </tbody>
48
+ </table>
49
+ </div>
50
+ );
51
+ }
52
+
53
+ /** 模板清单:系统里每份提示词模板的位置与配置入口。 */
54
+ function TemplateMap() {
55
+ const rows = [
56
+ ['交付上下文', '任务原文之外的组 / 项目关键路径(介绍、成员、参考文件路径)', '本页「交付上下文」'],
57
+ ['回调提示词', '领取任务后的收尾指令(可多条,按空行拼接)', '本页「回调提示词」'],
58
+ ['ack 总结', '完成任务时写总结的格式要求', '本页「ack 总结」'],
59
+ ['附件提示词', '交付里〔附件〕段的清单与拉取 SOP', '本页「附件提示词」'],
60
+ ['任务模板', '新建任务的正文骨架(槽位填写)', '本页「任务模板」'],
61
+ ['持续 get 指令', '项目开启持续 get 后追加的循环指令', '项目级设置(侧栏项目 → 持续 get)'],
62
+ ['任务级 check 指令', '任务带时间目标(--duration)时的计时 check 要求', '系统内置:发布时固化,暂不可配'],
63
+ ];
64
+ return (
65
+ <div className="setp-vars-wrap">
66
+ <table>
67
+ <thead>
68
+ <tr>
69
+ <th>模板</th>
70
+ <th>管什么</th>
71
+ <th>在哪配</th>
72
+ </tr>
73
+ </thead>
74
+ <tbody>
75
+ {rows.map(([name, what, where]) => (
76
+ <tr key={name}>
77
+ <td>{name}</td>
78
+ <td>{what}</td>
79
+ <td>{where}</td>
80
+ </tr>
81
+ ))}
82
+ </tbody>
83
+ </table>
84
+ </div>
85
+ );
86
+ }
87
+
88
+ function VarDictionary() {
89
+ return (
90
+ <div className="setp-vars">
91
+ <div className="setp-note">
92
+ 所有模板共用一套占位符语法(与 Mustache 同形的子集):<code>{'{{var}}'}</code> 取值;
93
+ <code>{'{{#sec}}…{{/sec}}'}</code> 是段落闸门——上下文里没有这个键,整段就不出现。
94
+ 列表类变量(成员、文档、附件清单)是预拼接好的多行文本,写进模板即整块展开。
95
+ 空壳组(没有任何可交付内容的组)整段不渲染。
96
+ </div>
97
+ <h4>模板清单(都在哪配)</h4>
98
+ <TemplateMap />
99
+ <h4>通用变量(所有模板可用)</h4>
100
+ <VarsTable
101
+ rows={[
102
+ ['{{task.id}}', '任务编号'],
103
+ ['{{task.text}}', '任务正文(逐字)。交付模板含它 = 交付自包含原文'],
104
+ ['{{source}}', '任务来源:local(本目录队列)/ global(全局共享池)'],
105
+ ['{{summary}}', '领取方现状(wait/get --summary)'],
106
+ ['{{cwd}}', '工作目录绝对路径'],
107
+ ['{{name}}', '目录名'],
108
+ ['{{params.k}} / {{k}}', '外部参数(--param k=v 平铺传入;内建同名键不被覆盖)'],
109
+ ]}
110
+ />
111
+ <h4>项目 / 组(交付上下文模板)</h4>
112
+ <VarsTable
113
+ rows={[
114
+ ['{{repo.name}} / {{repo.key}}', '仓库名 / 仓库 key(github.com/owner/repo)'],
115
+ ['{{repo.intro}} / {{repo.introPath}}', '项目介绍正文 / 主篇文件路径'],
116
+ ['{{repo.docs}}', '项目登记的补充文档清单(多行,可直接读取)'],
117
+ ['{{#repo}}…{{/repo}}', '闸门:有项目介绍才出现'],
118
+ ['{{group.name}} / {{group.desc}}', '组名 / 组定位(组描述)'],
119
+ ['{{group.intro}} / {{group.introPath}}', '组介绍正文 / 主篇路径'],
120
+ ['{{group.note}}', '本项目在组里的位置(本仓库的组内描述)'],
121
+ ['{{group.peers}}', '组内成员清单(多行:名字 + 组内描述)'],
122
+ ['{{group.docs}}', '组绑定参考文件清单(多行,可直接读取)'],
123
+ ['{{groups}}', '多组归属时其余组的概览(一行一组)'],
124
+ ['{{#group}} / {{#groupPeers}} / {{#groupDocs}}', '闸门:组在 / 有成员 / 有参考文件才出现'],
125
+ ]}
126
+ />
127
+ <h4>时间目标(回调 / ack / getLoop 模板)</h4>
128
+ <VarsTable
129
+ rows={[
130
+ ['{{goal.name}}', '时间目标名'],
131
+ ['{{goal.deadline}}', '截止时刻(YYYY-MM-DD HH:mm:ss)'],
132
+ ['{{goal.prompt}}', '任务级 check 指令原文(任务带 --duration 时固化)'],
133
+ ['{{goal.remainingHuman}}', '人话时间:「剩 12 分钟」/「已超时 3 分钟」'],
134
+ ['{{goal.remainingSec}} / {{goal.remainingMin}}', '剩余秒数 / 剩余分钟(向上取整,可做运算比较)'],
135
+ ['{{goal.overtimeSec}}', '已超时秒数(未超时 = 0)'],
136
+ ['{{goal.reached}}', '是否已到点'],
137
+ ['{{#goal}}…{{/goal}}', '闸门:没有时间目标整段消失'],
138
+ ]}
139
+ />
140
+ <h4>附件段(附件提示词模板)</h4>
141
+ <VarsTable
142
+ rows={[
143
+ ['{{attach.count}}', '附件个数'],
144
+ ['{{attach.list}}', '附件清单(多行:「- 图片 名: 本地路径 / 图床 id 与拉取命令」)'],
145
+ ['{{attach.sync}}', '本次云端同步详情(目录 · 下载 · 跳过 · 失败);空串 = 本次没跑同步'],
146
+ ['{{#attachSync}}…{{/attachSync}}', '闸门:本次跑过云端同步才出现'],
147
+ ]}
148
+ />
149
+ </div>
150
+ );
151
+ }
152
+
153
+ /** 附件段提示词(任务 #82):交付里〔附件〕段的清单与拉取 SOP,可配;空 = 内置默认。 */
154
+ function AttachTemplate() {
155
+ const toast = useToast();
156
+ const [text, setText] = useState(null); // null = 还没读
157
+ const [busy, setBusy] = useState(false);
158
+
159
+ const load = useCallback(() => {
160
+ api('/api/localtasks')
161
+ .then((d) => setText(d?.settings?.attachTemplate ?? ''))
162
+ .catch((e) => toast('读取失败:' + (e.message || e)));
163
+ }, [toast]);
164
+
165
+ useEffect(() => {
166
+ load();
167
+ }, [load]);
168
+
169
+ const save = async (v) => {
170
+ if (busy) return;
171
+ setBusy(true);
172
+ try {
173
+ const d = await api('/api/localtasks/setting', { method: 'PATCH', body: { attachTemplate: v ?? '' } });
174
+ setText(d?.attachTemplate ?? '');
175
+ toast(v && v.trim() ? '已保存附件段提示词' : '已恢复内置默认附件段');
176
+ } catch (e) {
177
+ toast(String(e.message || e));
178
+ } finally {
179
+ setBusy(false);
180
+ }
181
+ };
182
+
183
+ return (
184
+ <div className="setp-suffix">
185
+ <div className="setp-row">
186
+ <span>附件段提示词(〔附件〕段的清单与拉取 SOP;空 = 内置默认,附件段不能关)</span>
187
+ <button type="button" className="btn ghost sm" onClick={() => save(text)} disabled={busy || text === null}>
188
+ 保存
189
+ </button>
190
+ <button type="button" className="btn ghost sm" onClick={() => save('')} disabled={busy || text === null}>
191
+ 恢复默认
192
+ </button>
193
+ </div>
194
+ <textarea
195
+ className="setp-area"
196
+ rows={8}
197
+ value={text ?? ''}
198
+ placeholder={'留空 = 用内置默认(附件清单 + 本地路径 + 拉取命令)'}
199
+ disabled={text === null}
200
+ onChange={(e) => setText(e.target.value)}
201
+ />
202
+ <details className="setp-tpl-preview">
203
+ <summary>可用占位符(完整含义见「变量字典」页)</summary>
204
+ <pre className="setp-tpl-preview-body">
205
+ {'{{task.id}} {{task.text}} {{source}} {{summary}} {{cwd}} {{name}}\n{{attach.count}} 附件个数\n{{attach.list}} 附件清单(多行:路径 / 图床 id 与拉取命令)\n{{attach.sync}} 本次同步详情(空串 = 没跑云端同步)\n{{#attachSync}}…{{/attachSync}} 跑过同步才出现的段'}
206
+ </pre>
207
+ </details>
208
+ </div>
209
+ );
210
+ }
211
+
25
212
  /** 全局提示词列表(回调 / ack 共用一套读写) */
26
213
  function GlobalPrompts({ listFlag, listKey, placeholder, offText }) {
27
214
  const toast = useToast();
215
+ const { dialog, node: dialogNode } = useDialog();
28
216
  const [items, setItems] = useState(null);
29
217
  const [busy, setBusy] = useState(false);
30
218
  const [openIdx, setOpenIdx] = useState(-1); // 手风琴展开态(受控:新增条目自动展开)
@@ -56,6 +244,23 @@ function GlobalPrompts({ listFlag, listKey, placeholder, offText }) {
56
244
  }
57
245
  };
58
246
 
247
+ // 停用 = 清空全部条目(save([]))。曾用文案「关闭」排在「保存 / 撤销改动」
248
+ // 一排里,怎么看都是「关掉这个页面」——一点却把整份已配置的条目清掉
249
+ // (#80:反直觉且不可恢复)。改成明说后果的「停用」,有配置时先弹确认。
250
+ const disableAll = async () => {
251
+ if (busy || items === null) return;
252
+ if (items.length) {
253
+ const ok = await dialog({
254
+ title: '清空并停用?',
255
+ message: `将删除全部 ${items.length} 条已配置条目并停用,保存后不可恢复。`,
256
+ okText: '清空并停用',
257
+ danger: true,
258
+ });
259
+ if (!ok) return;
260
+ }
261
+ save([]);
262
+ };
263
+
59
264
  return (
60
265
  <div className="setp-suffix">
61
266
  {items !== null && !items.length && <span className="setp-badge">已关闭</span>}
@@ -88,17 +293,18 @@ function GlobalPrompts({ listFlag, listKey, placeholder, offText }) {
88
293
  保存
89
294
  </button>
90
295
  <button
91
- className="btn ghost sm"
296
+ className="btn ghost sm danger"
92
297
  disabled={busy || items === null}
93
- onClick={() => save([])}
94
- title={offText}
298
+ onClick={disableAll}
299
+ title="清空全部条目并停用"
95
300
  >
96
- 关闭
301
+ 停用
97
302
  </button>
98
303
  <button className="btn ghost sm" disabled={busy} onClick={load}>
99
304
  撤销改动
100
305
  </button>
101
306
  </div>
307
+ {dialogNode}
102
308
  </div>
103
309
  );
104
310
  }
@@ -280,7 +486,8 @@ function DeliveryTemplate() {
280
486
  );
281
487
  }
282
488
  export default function PromptsSection({ openTemplates }) {
283
- const [tab, setTab] = useState('template');
489
+ // 第一页 = 变量字典(#82):先认识有哪些变量,再动手改模板。
490
+ const [tab, setTab] = useState('vars');
284
491
 
285
492
  return (
286
493
  <div className="setp-prompts">
@@ -298,6 +505,7 @@ export default function PromptsSection({ openTemplates }) {
298
505
  ))}
299
506
  </nav>
300
507
  <div className="setp-prompts-pane">
508
+ {tab === 'vars' && <VarDictionary />}
301
509
  {tab === 'template' && <TemplateSlots openTemplates={openTemplates} />}
302
510
  {tab === 'suffix' && (
303
511
  <GlobalPrompts
@@ -315,6 +523,7 @@ export default function PromptsSection({ openTemplates }) {
315
523
  offText="已关闭 ack 提示词"
316
524
  />
317
525
  )}
526
+ {tab === 'attach' && <AttachTemplate />}
318
527
  {tab === 'delivery' && <DeliveryTemplate />}
319
528
  </div>
320
529
  </div>
@@ -259,3 +259,16 @@
259
259
  border:1px solid var(--line,#E4E2DC);border-radius:6px;background:var(--paper,#fff);color:var(--ink,#16181C);
260
260
  }
261
261
  .setp-oneline-input:focus{outline:none;border-color:var(--mdw-accent,#2F6F5E)}
262
+
263
+ /* 变量字典(任务 #82):所有提示词模板的占位符与模板清单,放在「提示词 / 模板」第一页 */
264
+ .setp-vars{display:flex;flex-direction:column;gap:6px;min-width:0}
265
+ .setp-vars-wrap{overflow-x:auto}
266
+ .setp-vars table{width:100%;border-collapse:collapse;font-size:11.5px;margin:2px 0 10px;min-width:420px}
267
+ .setp-vars th,.setp-vars td{text-align:left;padding:4px 8px;border-bottom:1px solid var(--line,#E4E2DC);vertical-align:top}
268
+ .setp-vars th{color:var(--mid,#8A8578);font-weight:600;white-space:nowrap}
269
+ .setp-vars td:first-child{white-space:nowrap}
270
+ .setp-vars code{
271
+ font:400 11px/1.5 ui-monospace,Consolas,monospace;
272
+ background:var(--soft,#F1F0EC);border-radius:4px;padding:1px 4px;color:var(--ink,#16181C);
273
+ }
274
+ .setp-vars h4{margin:10px 0 2px;font-size:12px;color:var(--ink,#16181C)}