nx-kv 0.26.1 → 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 (44) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +1 -1
  3. package/src/modules/localtask/index.js +16 -1
  4. package/src/modules/localtask/store-io.js +10 -1
  5. package/src/modules/localtask/task-lifecycle.js +24 -0
  6. package/src/modules/localtask/task-templates.js +17 -0
  7. package/src/modules/localtask/topics.js +8 -3
  8. package/src/modules/tasktool/attach.js +50 -14
  9. package/src/modules/tasktool/delivery-template.js +20 -2
  10. package/src/modules/tasktool/preview.js +1 -0
  11. package/src/modules/tasktool/wait.js +46 -8
  12. package/src/shared/feedback-text.js +57 -0
  13. package/src/web/frontend/App.jsx +3 -10
  14. package/src/web/frontend/components/layout/breadcrumb.jsx +1 -1
  15. package/src/web/frontend/components/layout/crumbs.js +15 -15
  16. package/src/web/frontend/modules/board/reopen-text.js +17 -17
  17. package/src/web/frontend/page/dir/index.jsx +40 -14
  18. package/src/web/frontend/page/dir/task.jsx +59 -17
  19. package/src/web/frontend/page/settings/prompts-section.jsx +214 -5
  20. package/src/web/frontend/page/settings/style.css +13 -0
  21. package/src/web/public/assets/{Introduction-DM8UsY4h.js → Introduction-vTffOL-5.js} +1 -1
  22. package/src/web/public/assets/{cloud-CNaaEd1U.js → cloud-truDniwE.js} +1 -1
  23. package/src/web/public/assets/{dag-CbvygK6N.js → dag-BPV2Yvmk.js} +1 -1
  24. package/src/web/public/assets/{dir-d7zH4NlJ.js → dir-Cmrrc252.js} +3 -3
  25. package/src/web/public/assets/{group-CrO4vK2Z.js → group-B26fV4Ec.js} +1 -1
  26. package/src/web/public/assets/{index-BZXYd3aX.js → index-CFkF2w23.js} +2 -2
  27. package/src/web/public/assets/{md-history-D7QLmaSB.js → md-history-BLnTGoI5.js} +1 -1
  28. package/src/web/public/assets/{member-picker-DACtPBSm.js → member-picker-CNGyhd0r.js} +1 -1
  29. package/src/web/public/assets/{overview-C_K6CESc.js → overview-CRPbHHGF.js} +1 -1
  30. package/src/web/public/assets/{progress-CF0jxABq.js → progress-CNgMymPb.js} +1 -1
  31. package/src/web/public/assets/reopen-text-DIFfS71D.js +6 -0
  32. package/src/web/public/assets/{repos-DNpvvMU4.js → repos-CPSsUWZ5.js} +1 -1
  33. package/src/web/public/assets/route-crumb-DTo_wUoT.js +1 -0
  34. package/src/web/public/assets/settings-BQ3gTrIV.js +12 -0
  35. package/src/web/public/assets/{settings-CRK86fnJ.css → settings-knWtG9Kc.css} +1 -1
  36. package/src/web/public/assets/task-D_7iKWwt.js +7 -0
  37. package/src/web/public/assets/{template-slots-OwSHkvYK.js → template-slots-Bc70bnzR.js} +1 -1
  38. package/src/web/public/assets/{templates-CWumcZMp.js → templates-ChQO154-.js} +1 -1
  39. package/src/web/public/assets/{upload-DqECQ-17.js → upload-CzUtsVcG.js} +1 -1
  40. package/src/web/public/index.html +1 -1
  41. package/src/web/public/assets/reopen-text-DSB76_rF.js +0 -5
  42. package/src/web/public/assets/route-crumb-C9Y1m8Oy.js +0 -1
  43. package/src/web/public/assets/settings-fyoIVpgK.js +0 -8
  44. package/src/web/public/assets/task-D1c-iO3T.js +0 -6
package/CHANGELOG.md CHANGED
@@ -2,6 +2,54 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.27.0] - 2026-11-06 提示词模板体系收口(变量字典 + 附件模板)+ 交付提示词修复
6
+
7
+ ### Added
8
+
9
+ - **设置页「变量字典」:全部提示词模板的占位符聚到一页(任务 #82)**:提示词 / 模板栏
10
+ 新增首页(打开默认落在它)——先列模板清单(七份模板各管什么、在哪配,含项目级
11
+ getLoop 与暂不可配的任务级 check 指令),再分四张变量表:通用(task / source /
12
+ summary / cwd / name / params)、项目 / 组(repo.* / group.* / groups 与各自段落闸门)、
13
+ 时间目标、附件段。占位符语法(Mustache 同形子集、`{{#sec}}…{{/sec}}` 段落闸门、列表
14
+ 预拼接、空壳组整段不渲染)一并写进页头——先认识变量,再动手改模板。
15
+ - **附件段提示词可配(任务 #82)**:交付里的〔附件〕段(附件清单 + 本地路径 / 图床 id +
16
+ 拉取命令 + 云端同步详情)从硬编码升级为模板——设置页「附件提示词」子页签编辑,
17
+ 留空 = 内置默认(历史输出逐字节不变);附件段带本地路径,不能关。可用变量
18
+ `{{attach.count}}` / `{{attach.list}}` / `{{attach.sync}}` + `{{#attachSync}}` 闸门(本次
19
+ 没跑云端同步整段消失)+ 通用 `{{task.*}}` / `{{source}}` / `{{summary}}` / `{{cwd}}` /
20
+ `{{name}}`;渲染失败自动回退内置默认,附件交付永不因模板写坏而丢。
21
+ - **时间目标暴露可运算字段(任务 #82)**:回调 / ack / getLoop 模板里的 `{{goal.*}}` 新增
22
+ `{{goal.remainingSec}}` / `{{goal.remainingMin}}`(向上取整)/ `{{goal.overtimeSec}}` /
23
+ `{{goal.reached}}`——此前只有人话的 remainingHuman,模板层没法写「剩余不足 N 分钟
24
+ 就先收尾」这类条件。目录级目标本来就有这些字段,任务级(`--duration`)从截止戳补
25
+ 算;已有字段不覆盖,解析不了就不动。
26
+
27
+ ### Fixed
28
+
29
+ - **仓库页面包屑不再挂组前缀——与侧栏的「独立模块」语义对齐(任务 #84)**:
30
+ 侧栏 2026-11-03 起仓库就是平铺的独立行(项目组只是指向它的指针),但左上角
31
+ 面包屑还按旧容器语义拼组名——侧栏里的「单独仓库」一进面板又变回
32
+ `[ nx/nx-kv/#81 ]`,两个视图自相矛盾。根因在面包屑上下文:仓库路由也从
33
+ `repo.boards[0]` 回落取组名,只要登记过组就带上前缀。现在仓库页 / 任务页
34
+ 面包屑只到仓库(`[ nx-kv ]` / `[ nx-kv/#81 ]`),目录页「←」兜底回总览
35
+ (不再回组页);组名只在组实体自己的页面出现(App 的面板命名同步收口)。
36
+ - **自定义交付模板从未生效过(#62 遗留,#82 排查附件模板时两进程实测抓到)**:
37
+ store-io 的 settings 白名单重建漏了 `deliveryTemplate`——面板保存成功、写盘成功,
38
+ 但**每次读盘**重建 settings 时这个键被直接剥掉(业务 store 不缓存,读回即丢),
39
+ 交付永远渲染内置默认,且全程无任何报错。`deliveryTemplate` / 新增的 `attachTemplate`
40
+ 一并钉进白名单,回归单测锁死「落盘后重读不丢」。
41
+ - **设置页提示词栏的「关闭」不再伪装成退出(任务 #80)**:它排在「保存 / 撤销改动」
42
+ 一排里,看着像关掉设置面板,一点却把全部已配置条目清空并停用(保存后不可恢复)——
43
+ 反直觉且易丢配置。改名**「停用」**(红色危险样式,悬停说明后果),已有条目时先弹
44
+ 确认框(列出将删除的条数,取消即不动作);空列表无需确认直接停用。
45
+ - **空壳项目组不再向交付提示词喷空标签(任务 #81)**:组只要登记了定位 / 组介绍 /
46
+ 组内位置 / 参考文件 / 有描述的成员之一,照常渲染组上下文;仅有成员名单(全员无
47
+ 「组内描述」)的空壳组——如只有两名成员却什么材料都没配的组——其「项目组上下文」
48
+ 整段不再出现,不再印出「组定位:」「组介绍():」这类零信息空标签,也让不在任何
49
+ 组的仓库与「被归了组但组里没料」的仓库交付观感一致。多组归属时跳过空壳组、选第一
50
+ 个有料的当主组。排查确认:组成员判定一直是显式名单(前缀自动归组废除后无隐式归属),
51
+ 单独仓库的交付本身不含组信息;本次修的是模板化(#62)时丢掉的空值逐行判空。
52
+
5
53
  ## [0.26.1] - 2026-11-05 任务页头部收敛 + `skill install --all`
6
54
 
7
55
  ### Added
@@ -15,6 +63,19 @@
15
63
 
16
64
  ### Changed
17
65
 
66
+ - **评论 / 反馈不再丢数据(任务 #79)**:回写后的正文**第一个区块永远是完整的之前的任务**,
67
+ 接着才是引用字符(`> 锚定:`)和评论。此前面板拿会话编辑器里的正文当 base 整篇拼回去
68
+ 重写——会话 doc 过期(别的会话改过 / 上一轮重开追加过 / 首轮未加载完)时,盘上新内容
69
+ 被旧正文覆盖,「评论一次丢一次」。
70
+ - `localtask reopen`:反馈不带 `text` 时由**服务端**把反馈段原子追加到盘上当前正文
71
+ (新增 `--feedback-heading` / `--feedback-bold` 覆盖段名与加粗口径;缺省
72
+ comment=反馈修改/不加粗,reopen=验收反馈/加粗);显式 `--text` 整篇替换口径不变。
73
+ - 面板划选评论:干净态(无未保存编辑、无附件片段)不再传 text,走服务端拼装;
74
+ 带未保存编辑 / 附件片段时先取服务端最新正文再整篇回写;拿不到正文直接中止并提示,
75
+ 绝不发空壳回写。
76
+ - 验收反馈(新开任务)与列表页重做:base 同样先取服务端当前正文(原取 rows 快照 /
77
+ 会话 doc)。
78
+ - 段名 / 锚定 / 加粗口径收口 `src/shared/feedback-text.js`(服务端与面板共用一份)。
18
79
  - **任务页头部收敛(任务 #78)**:头部只留「模式 · 时间目标勋章 | 新任务 · 提交 · 更多」——
19
80
  任务链 / 预览提示词 / 插入图片 / 添加附件 / 导入 / 克隆 / 评论 / 存草稿 / 删除 / 总览 /
20
81
  进程 / 原文 / 快捷键全部收进「更多」菜单;MD 格式条撤出头部(划选浮条 + 行首 `/` 命令 +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -168,6 +168,7 @@ function renderPreview(d) {
168
168
  `── 开关 ── 回调提示词 ${sw.suffix?.on ? `开(${sw.suffix.count} 条)` : '关'}` +
169
169
  ` · ack ${sw.ack?.on ? `开(${sw.ack.count} 条)` : '关'}` +
170
170
  ` · 交付上下文 ${sw.deliveryTemplate?.custom ? '自定义' : '内置默认'}` +
171
+ ` · 附件段 ${sw.attachTemplate?.custom ? '自定义' : '内置默认'}` +
171
172
  ` · 持续 get ${d.getLoop?.enabled ? `开(${d.getLoop.waitMinutes} 分钟)` : '关'}`,
172
173
  );
173
174
  return lines.join('\n');
@@ -336,7 +337,9 @@ export default {
336
337
  text: { type: 'string', hint: '修改后的任务正文(Markdown);不给则只重开不改内容' },
337
338
  kind: { type: 'string', hint: 'reopen(验收反馈,默认)或 comment(划选评论)' },
338
339
  quote: { type: 'string', hint: '划选原文(comment 时)' },
339
- feedback: { type: 'string', hint: '用户反馈原文(写入 history 节点)' },
340
+ feedback: { type: 'string', hint: '用户反馈原文;不给 text 时追加到当前正文末尾(#79,base = 服务端最新正文)' },
341
+ feedbackHeading: { type: 'string', hint: '追加反馈段的段名(缺省 comment=## 反馈修改 / reopen=## 验收反馈)' },
342
+ feedbackBold: { type: 'boolean', hint: '追加的反馈是否逐行加粗(缺省 comment=false / reopen=true)' },
340
343
  },
341
344
  run: async (ctx) => {
342
345
  // 重开也可能带着改过的归属(--text 的 frontmatter.project 变了)→ 同样搬家
@@ -349,6 +352,8 @@ export default {
349
352
  kind: ctx.kind,
350
353
  quote: ctx.quote,
351
354
  feedback: ctx.feedback,
355
+ feedbackHeading: ctx.feedbackHeading,
356
+ feedbackBold: ctx.feedbackBold,
352
357
  attachments: ctx.attachments,
353
358
  });
354
359
  },
@@ -738,6 +743,12 @@ export default {
738
743
  hint: '交付上下文模板(原始提示词之外那段「组/项目关键路径」怎么写)。占位符:{{task.text}} {{repo.name}} {{repo.intro}} {{repo.introPath}} {{repo.docs}} {{group.name}} {{group.desc}} {{group.intro}} {{group.introPath}} {{group.note}} {{group.peers}} {{group.docs}} {{source}} {{summary}} {{cwd}} {{name}};段落 {{#repo}}…{{/repo}}、{{#group}}…{{/group}};外部参数 {{params.k}} 与顶层 {{k}}。置空 = 恢复内置默认模板',
739
744
  },
740
745
  'reset-delivery-template': { type: 'boolean', hint: '恢复内置默认交付上下文模板' },
746
+ 'attach-template': {
747
+ type: 'string',
748
+ hint: '附件段提示词(交付里〔附件〕段的清单与拉取 SOP 怎么写)。占位符:{{task.id}} {{task.text}} {{attach.count}} {{attach.list}} {{attach.sync}};段落 {{#attachSync}}…{{/attachSync}}(本次跑过云端同步才出现)。置空 = 用内置默认(附件段带本地路径,不能真关掉)',
749
+ },
750
+ attachTemplate: { type: 'string', hint: '同 --attach-template(驼峰写法,HTTP body 用)' },
751
+ 'reset-attach-template': { type: 'boolean', hint: '恢复内置默认附件段提示词' },
741
752
  },
742
753
  run: async (ctx) => {
743
754
  const patch = { timeoutSec: ctx.timeout };
@@ -777,6 +788,10 @@ export default {
777
788
  // 交付上下文模板(任务 #62):置空 = 恢复内置默认模板
778
789
  if (ctx['delivery-template'] !== undefined) patch.deliveryTemplate = ctx['delivery-template'];
779
790
  if (ctx['reset-delivery-template']) patch.deliveryTemplate = '';
791
+ // 附件段提示词(任务 #82):置空 = 恢复内置默认
792
+ const attachTpl = ctx.attachTemplate ?? ctx['attach-template'];
793
+ if (attachTpl !== undefined) patch.attachTemplate = attachTpl;
794
+ if (ctx['reset-attach-template']) patch.attachTemplate = '';
780
795
  return service.updateSettings(patch);
781
796
  },
782
797
  render: (s) => {
@@ -7,7 +7,7 @@
7
7
  import { basename } from 'node:path';
8
8
  import { badInput } from '../../core/errors.js';
9
9
  import { createJsonStore } from '../../core/json-store.js';
10
- import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList } from './task-templates.js';
10
+ import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList, clampDeliveryTemplate, clampAttachTemplate } from './task-templates.js';
11
11
  import { storePath, legacyStorePath } from './paths.js';
12
12
  export const DEFAULT_TIMEOUT_MS = 180_000; // 阻塞默认 3 分钟(推荐值)
13
13
  export const DEFAULT_TIMEOUT_SEC = 180; // 推荐阻塞时长(3 分钟)
@@ -121,6 +121,15 @@ function normalizeRawStore(data) {
121
121
  ackPrompt: settings && Object.prototype.hasOwnProperty.call(settings, 'ackPrompt')
122
122
  ? clampAckPromptList(settings.ackPrompt)
123
123
  : [],
124
+ // 交付上下文模板(#62)/ 附件段提示词(#82):字段存在才认,缺省 = 空(用内置默认)。
125
+ // ⚠️ 白名单里必须有这两个键——之前 deliveryTemplate 漏在这里,写盘成功、读时被
126
+ // 剥掉,serve 重启即静默丢失(#82 两进程实测抓到)。
127
+ deliveryTemplate: settings && Object.prototype.hasOwnProperty.call(settings, 'deliveryTemplate')
128
+ ? clampDeliveryTemplate(settings.deliveryTemplate)
129
+ : '',
130
+ attachTemplate: settings && Object.prototype.hasOwnProperty.call(settings, 'attachTemplate')
131
+ ? clampAttachTemplate(settings.attachTemplate)
132
+ : '',
124
133
  },
125
134
  topics,
126
135
  };
@@ -4,6 +4,11 @@
4
4
  import { badInput, notFound } from '../../core/errors.js';
5
5
  import { formatDuration } from '../../core/instruction-template.js';
6
6
  import { preserveFrontmatter } from '../../shared/frontmatter.js';
7
+ import {
8
+ FEEDBACK_HEADING,
9
+ PLAIN_FEEDBACK_HEADING,
10
+ appendFeedback,
11
+ } from '../../shared/feedback-text.js';
7
12
  import { findFirstReadyPending } from './dag.js';
8
13
  import { basename } from 'node:path';
9
14
  import { isGlobalKey, resolveTaskKey, topicKeyFor } from './paths.js';
@@ -73,6 +78,8 @@ export async function reopenTask({
73
78
  kind: rawKind,
74
79
  quote,
75
80
  feedback,
81
+ feedbackHeading,
82
+ feedbackBold,
76
83
  attachments,
77
84
  } = {}) {
78
85
  const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
@@ -103,8 +110,25 @@ export async function reopenTask({
103
110
  }
104
111
 
105
112
  const body = String(text ?? '').trim();
113
+ const fb = String(feedback ?? '').trim();
106
114
  if (body) {
107
115
  task.text = preserveFrontmatter(task.text, normalizeText(body));
116
+ } else if (fb) {
117
+ // #79:反馈不带 text —— 服务端把反馈段**追加**到盘上当前正文。
118
+ // base 永远是服务端正文(完整、最新):面板会话 doc 可能落后于盘上
119
+ // (别的会话改过 / 上一轮重开追加过 / 首轮还没加载完),拿旧正文整篇拼回去
120
+ // 重写,就是「评论一次丢一次」。只有显式给 text(带未保存编辑的整篇回写)
121
+ // 才替换正文。段名 / 锚定 / 加粗与面板共用 src/shared/feedback-text.js。
122
+ const heading = String(feedbackHeading ?? '').trim()
123
+ || (kind === 'comment' ? PLAIN_FEEDBACK_HEADING : FEEDBACK_HEADING);
124
+ const useBold = typeof feedbackBold === 'boolean' ? feedbackBold : kind !== 'comment';
125
+ task.text = preserveFrontmatter(task.text, appendFeedback({
126
+ base: task.text,
127
+ heading,
128
+ quote,
129
+ feedback: fb,
130
+ bold: useBold,
131
+ }));
108
132
  }
109
133
 
110
134
  // 本轮事件节点:记反馈/选区/附件;text 取**更新后**的正文(旁路点开即这一轮交付形态)
@@ -69,6 +69,23 @@ export function clampDeliveryTemplate(v) {
69
69
  return s.slice(0, MAX_DELIVERY_TEMPLATE_LEN);
70
70
  }
71
71
 
72
+ // ─── 附件段提示词(settings.attachTemplate,任务 #82)──────────────────
73
+ //
74
+ // 交付里的〔附件〕段(附件清单 + 本地路径 + 拉取 SOP)原先硬编码在
75
+ // tasktool/attach.js 的 attachmentInstruction。模板化后:
76
+ // - 空串 = 用内置默认(**不是关掉**——附件段带本地路径,关掉 agent 就找不到文件);
77
+ // - 占位符:{{task.id}} {{task.text}} {{attach.count}} {{attach.list}}
78
+ // {{attach.sync}}(详情串:目录/下载/跳过/失败),段落闸门 {{#attachSync}}…{{/attachSync}}
79
+ // (本次没跑云端同步 → 整段消失);渲染失败回退内置默认。
80
+ export const MAX_ATTACH_TEMPLATE_LEN = 4000;
81
+
82
+ export function clampAttachTemplate(v) {
83
+ if (v === undefined || v === null) return '';
84
+ const s = String(v).trim();
85
+ if (!s) return '';
86
+ return s.slice(0, MAX_ATTACH_TEMPLATE_LEN);
87
+ }
88
+
72
89
  export function clampAckPromptList(v) {
73
90
  if (v === undefined || v === null) return [];
74
91
  const raw = Array.isArray(v) ? v : [v];
@@ -12,7 +12,7 @@ import {
12
12
  normalizeSummary,
13
13
  topicOf,
14
14
  } from './store-io.js';
15
- import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList, clampDeliveryTemplate } from './task-templates.js';
15
+ import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList, clampDeliveryTemplate, clampAttachTemplate } from './task-templates.js';
16
16
  import { foreignResolver, isPending, topicView } from './task-view.js';
17
17
  import { deleteGuard } from './deletion.js';
18
18
  import { repoContextIndex, repoCtxOf } from './repo-ctx.js';
@@ -38,6 +38,9 @@ function settingsView(s) {
38
38
  // 交付上下文模板(任务 #62):原始提示词之外的那段「组 / 项目关键路径」
39
39
  // 怎么写。空串 = 用内置默认模板(不是关掉——关掉就丢上下文了)。
40
40
  deliveryTemplate: clampDeliveryTemplate(s && s.deliveryTemplate),
41
+ // 附件段提示词(任务 #82):交付里的〔附件〕段(清单 + 本地路径 + 拉取 SOP)。
42
+ // 空串 = 用内置默认(附件段带路径,不能真关掉)。
43
+ attachTemplate: clampAttachTemplate(s && s.attachTemplate),
41
44
  };
42
45
  }
43
46
 
@@ -128,12 +131,13 @@ export async function pruneTopics({ allFinished = false, dryRun = false } = {})
128
131
  // 也兼容 string(旧单条写法,整体算一条)。条数上限 10、单条 ≤2000 字;
129
132
  // 含 {{ 占位符 → 渲染进返回的 instruction 字段;纯文本 → 追加到 task.text 末尾;
130
133
  // 传 '' / [] 关闭、不传保持不变。
131
- export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt, deliveryTemplate } = {}) {
134
+ export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt, deliveryTemplate, attachTemplate } = {}) {
132
135
  const hasTimeout = timeoutSec !== undefined && timeoutSec !== null;
133
136
  const hasSuffix = taskSuffix !== undefined;
134
137
  const hasAck = ackPrompt !== undefined;
135
138
  const hasDelivery = deliveryTemplate !== undefined;
136
- if (!hasTimeout && !hasSuffix && !hasAck && !hasDelivery) {
139
+ const hasAttach = attachTemplate !== undefined;
140
+ if (!hasTimeout && !hasSuffix && !hasAck && !hasDelivery && !hasAttach) {
137
141
  throw badInput(
138
142
  '请至少指定一项:--timeout <秒>,或 --suffix "<收尾指令模板>"(--no-suffix 关闭、--reset-suffix 恢复默认、--suffix-add/--suffix-remove 按条增删),或 --ack "<ack 提示词>"'
139
143
  );
@@ -150,6 +154,7 @@ export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt, delive
150
154
  if (hasSuffix) next.taskSuffix = clampTaskSuffixList(taskSuffix);
151
155
  if (hasAck) next.ackPrompt = clampAckPromptList(ackPrompt);
152
156
  if (hasDelivery) next.deliveryTemplate = clampDeliveryTemplate(deliveryTemplate);
157
+ if (hasAttach) next.attachTemplate = clampAttachTemplate(attachTemplate);
153
158
  store.settings = next;
154
159
  await saveStore(store);
155
160
  return settingsView(store.settings);
@@ -20,6 +20,7 @@
20
20
  import { readFile } from 'node:fs/promises';
21
21
  import { basename, resolve as resolvePath } from 'node:path';
22
22
  import { badInput } from '../../core/errors.js';
23
+ import { renderInstruction } from '../../core/instruction-template.js';
23
24
  import { loadConfig, resolveGroupId } from '../../core/config.js';
24
25
  import { contentTypeOf, isImageName } from '../../core/fileapi.js';
25
26
  import { localIndex as cloudMirrorIndex, syncAttachments } from '../../core/attachstore.js';
@@ -95,23 +96,58 @@ export async function annotateTaskDelivery(task, { sync: allowSync = true } = {}
95
96
  export function attachmentInstruction(attachments, sync) {
96
97
  const list = Array.isArray(attachments) ? attachments : [];
97
98
  if (!list.length) return '';
98
- const lines = ['〔附件〕本任务正文引用了附件(嵌入即附件,正文随任务走):'];
99
- for (const a of list) {
100
- const kindLabel = a.kind === 'image' ? '图片' : '附件';
101
- lines.push(
102
- ` - ${kindLabel} ${a.name}: ` +
103
- (a.localPath || `未同步到本地(图床 id ${a.id};nx-kv file sync --ids ${a.id} 可拉到本地)`)
104
- );
105
- }
106
- if (sync) {
107
- lines.push(
108
- ` 同步: 目录 ${sync.dir || '—'} · 下载 ${sync.downloaded || 0} · 跳过 ${sync.skipped || 0}` +
109
- (sync.failures && sync.failures.length ? ` · 失败 ${sync.failures.length}` : '')
110
- );
111
- }
99
+ const lines = ['〔附件〕本任务正文引用了附件(嵌入即附件,正文随任务走):', ...list.map(attachmentLine)];
100
+ const syncText = attachmentSyncText(sync);
101
+ if (syncText) lines.push(` 同步: ${syncText}`);
112
102
  return lines.join('\n');
113
103
  }
114
104
 
105
+ // 单个附件的默认清单行(attachmentInstruction 与模板渲染共用同一份口径)。
106
+ function attachmentLine(a) {
107
+ const kindLabel = a.kind === 'image' ? '图片' : '附件';
108
+ return (
109
+ ` - ${kindLabel} ${a.name}: ` +
110
+ (a.localPath || `未同步到本地(图床 id ${a.id};nx-kv file sync --ids ${a.id} 可拉到本地)`)
111
+ );
112
+ }
113
+
114
+ // 同步详情串(模板里 {{attach.sync}};没跑云端同步 → '',闸门 {{#attachSync}} 关)。
115
+ function attachmentSyncText(sync) {
116
+ if (!sync) return '';
117
+ return (
118
+ `目录 ${sync.dir || '—'} · 下载 ${sync.downloaded || 0} · 跳过 ${sync.skipped || 0}` +
119
+ (sync.failures && sync.failures.length ? ` · 失败 ${sync.failures.length}` : '')
120
+ );
121
+ }
122
+
123
+ /**
124
+ * 〔附件〕段渲染(任务 #82 模板化):
125
+ * - 配置了模板(settings.attachTemplate)→ 模板渲染。ctx:{{task.id}}/{{task.text}}、
126
+ * {{attach.count}}/{{attach.list}}(清单多行)/{{attach.sync}}(同步详情,空串)、
127
+ * 段落闸门 {{#attachSync}}…{{/attachSync}};
128
+ * - 空/未配置 → 内置默认(attachmentInstruction,历史输出逐字节不变);
129
+ * - 渲染失败 → 回退内置默认(fail-open:附件路径必须到达 agent)。
130
+ */
131
+ export function attachInstructionOf(tpl, attachments, sync, task) {
132
+ const list = Array.isArray(attachments) ? attachments : [];
133
+ const t = String(tpl || '').trim();
134
+ if (!t || !list.length) return attachmentInstruction(list, sync);
135
+ try {
136
+ const syncText = attachmentSyncText(sync);
137
+ return renderInstruction(t, {
138
+ task: task ? { id: task.id, text: String(task.text || '') } : null,
139
+ attach: {
140
+ count: list.length,
141
+ list: list.map(attachmentLine).join('\n'),
142
+ sync: syncText,
143
+ },
144
+ attachSync: syncText ? {} : null, // 闸门:本次跑过云端同步才出现
145
+ });
146
+ } catch {
147
+ return attachmentInstruction(list, sync);
148
+ }
149
+ }
150
+
115
151
  /**
116
152
  * 给任务追加附件(CLI `localtask attach`):--path 落**本机附件仓**(本地任务
117
153
  * 的附件与云端零关联),或 --fileId 引用已有附件(本机仓 / 云端 id 都认);
@@ -22,7 +22,8 @@
22
22
  // {{params.k}} 与顶层 {{k}} 外部参数(平面扩展;内建同名键不被覆盖)
23
23
  //
24
24
  // 段落:{{#repo}}…{{/repo}} / {{#group}}…{{/group}} —— ctx 里没这个键就整段丢弃
25
- // (项目级任务没有组,那一段就不出现)。
25
+ // (项目级任务没有组,那一段就不出现;组在但毫无可交付内容——空壳组——同样整段
26
+ // 丢弃,#81:只挂着成员名单的组会喷出一排空标签,让「单独仓库」看着像被归了组)。
26
27
  import { renderInstruction } from '../../core/instruction-template.js';
27
28
 
28
29
  /**
@@ -69,6 +70,19 @@ function peerLines(peers) {
69
70
  return (peers || []).map((p) => ` - ${p.name}:${p.note || '(无组内描述)'}`).join('\n');
70
71
  }
71
72
 
73
+ /**
74
+ * 组有没有值得交付的内容:定位 / 介绍 / 位置 / 参考文件 / 有描述的成员,任一即可。
75
+ * 纯「成员名单(全员无描述)」不算——那只会喷出一排空标签,还让单独仓库看起来
76
+ * 被当成了组成员(#81:这种空壳组的 {{#group}} 段整个不渲染)。
77
+ */
78
+ function groupHasContent(g) {
79
+ if (!g) return false;
80
+ if (g.desc || g.note) return true;
81
+ if (g.intro && g.intro.body) return true;
82
+ if (g.docLinks && g.docLinks.length) return true;
83
+ return (g.peers || []).some((p) => p.note);
84
+ }
85
+
72
86
  /**
73
87
  * 组上下文 → 模板 ctx(数据,不含成文措辞——措辞归模板)。
74
88
  * @param {object} groupCtx readGroupContext 的返回值
@@ -76,7 +90,11 @@ function peerLines(peers) {
76
90
  */
77
91
  export function deliveryCtxOf(groupCtx) {
78
92
  const repo = groupCtx && groupCtx.repo ? groupCtx.repo : null;
79
- const groups = (groupCtx && groupCtx.groups) || [];
93
+ const allGroups = (groupCtx && groupCtx.groups) || [];
94
+ // {{#group}} 的闸门是「键在不在」,不是「内容空不空」——空壳组进了 ctx 就会
95
+ // 印出「组定位:」「组介绍():」这样的空标签(#81)。过滤掉空壳;多组时
96
+ // 跳过空壳选第一个有料的当主组,其余有料的进 {{groups}} 概览。
97
+ const groups = allGroups.filter(groupHasContent);
80
98
  const g = groups[0] || null;
81
99
  const repoDocs = linkLines(repo && repo.docLinks);
82
100
  const peers = g ? peerLines(g.peers) : '';
@@ -90,6 +90,7 @@ export async function previewTaskDelivery({ task, cwd, key, summary, params } =
90
90
  suffix: { on: suffixList.length > 0, count: suffixList.length },
91
91
  ack: { on: ackList.length > 0, count: ackList.length },
92
92
  deliveryTemplate: { custom: !!(settings.deliveryTemplate || '').trim() },
93
+ attachTemplate: { custom: !!(settings.attachTemplate || '').trim() },
93
94
  attachments: delivery.attachmentsSync ? { synced: delivery.attachmentsSync } : null,
94
95
  },
95
96
  };
@@ -36,7 +36,7 @@ import {
36
36
  import { ensureMainPanel, deepLinkUrl, escortPanel } from './panel-escort.js';
37
37
  import { ensureTaskGoal, previewTaskGoal } from './taskgoal.js';
38
38
  import { readGroupContext } from './groupctx.js';
39
- import { annotateTaskDelivery, attachmentInstruction } from './attach.js';
39
+ import { annotateTaskDelivery, attachInstructionOf } from './attach.js';
40
40
  import * as timegoal from './timegoal.js';
41
41
 
42
42
  // 跨进程兜底轮询间隔(只定这里的读取节奏;队列写入节奏与它无关)
@@ -49,6 +49,35 @@ function parseStampMs(v) {
49
49
  return new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]).getTime();
50
50
  }
51
51
 
52
+ // goal 上下文的**时间运算字段**统一在这里补齐(任务 #82:模板层要能拿剩余/超时做运算,
53
+ // 不能只有人话的 remainingHuman)。目录级 show 自带 reached/remainingSec/overtimeSec;
54
+ // 任务级只有 deadline 戳——同式解析补算。缺哪个补哪个,已有的不覆盖。
55
+ export function enrichGoalTiming(g) {
56
+ if (!g) return g;
57
+ let { remainingSec, overtimeSec, reached } = g;
58
+ remainingSec = Number(remainingSec);
59
+ overtimeSec = Number(overtimeSec);
60
+ if (!Number.isFinite(remainingSec) && !Number.isFinite(overtimeSec)) {
61
+ const ms = parseStampMs(g.deadline);
62
+ if (Number.isFinite(ms)) {
63
+ const diff = Math.round((ms - Date.now()) / 1000);
64
+ remainingSec = diff >= 0 ? diff : 0;
65
+ overtimeSec = diff >= 0 ? 0 : -diff;
66
+ }
67
+ }
68
+ if (reached === undefined) {
69
+ if (Number.isFinite(overtimeSec)) reached = overtimeSec > 0;
70
+ else if (Number.isFinite(remainingSec)) reached = remainingSec <= 0;
71
+ }
72
+ if (Number.isFinite(remainingSec)) {
73
+ g.remainingSec = remainingSec;
74
+ g.remainingMin = Math.ceil(remainingSec / 60);
75
+ }
76
+ if (Number.isFinite(overtimeSec)) g.overtimeSec = overtimeSec;
77
+ if (reached !== undefined) g.reached = reached;
78
+ return g;
79
+ }
80
+
52
81
  // ─── 时间目标探针与交付时刻的目标上下文 ──────────────────────────────
53
82
  //
54
83
  // 与 localtask wait 的两处融合(都 fail-open:timegoal 坏了绝不拖垮 wait):
@@ -84,6 +113,9 @@ async function readGoalCtx(cwd) {
84
113
  name: g.name || show.name || '',
85
114
  deadline: g.deadline || '',
86
115
  prompt: g.prompt || '',
116
+ reached: !!show.reached,
117
+ remainingSec: show.remainingSec,
118
+ overtimeSec: show.overtimeSec,
87
119
  remainingHuman: formatGoalTiming({
88
120
  reached: show.reached,
89
121
  remainingSec: show.remainingSec,
@@ -127,14 +159,15 @@ export async function buildTaskDelivery(task, suffix, { source, summary, cwd, na
127
159
  // 附件标注(任务 #15:正文里的 ![名](fileId) 嵌入 → 附件清单 + 本地路径)。
128
160
  // fail-open:标注失败绝不拖垮交付;正文没有引用时 annotateTaskDelivery 返回
129
161
  // null,载荷与改造前**逐字节一致**(与 todo 读任务的同一条纪律)。
130
- let attSeg = '';
162
+ // 〔附件〕段本身等 settings 读到后再渲染(模板可配,任务 #82)——标注先行。
163
+ let att = null;
131
164
  let attSync = null;
132
165
  try {
133
- const att = await annotateTaskDelivery(task, { sync: !preview });
134
- if (att) {
135
- task = att.task;
136
- attSeg = attachmentInstruction(att.task.attachments, att.sync);
137
- attSync = att.sync;
166
+ const a = await annotateTaskDelivery(task, { sync: !preview });
167
+ if (a) {
168
+ task = a.task;
169
+ att = a;
170
+ attSync = a.sync;
138
171
  }
139
172
  } catch {
140
173
  /* 标注失败照常交付(agent 还能从正文里的嵌入自行处理) */
@@ -165,7 +198,7 @@ export async function buildTaskDelivery(task, suffix, { source, summary, cwd, na
165
198
  startedAtMs: parseStampMs(task.consumedAt) || undefined,
166
199
  });
167
200
  }
168
- const goal = taskGoalCtx || (await readGoalCtx(cwd));
201
+ const goal = enrichGoalTiming(taskGoalCtx || (await readGoalCtx(cwd)));
169
202
 
170
203
  // 项目组上下文(组概念 + 本项目位置 + 兄弟成员 + 参考文件地址):
171
204
  // 只进 instruction,**task.text 保持库存原文**——todo 的口径是
@@ -176,6 +209,11 @@ export async function buildTaskDelivery(task, suffix, { source, summary, cwd, na
176
209
  // ctx,模板里 {{k}} 直接取——引擎支持平面扩展。
177
210
  const groupCtx = await readGroupContext(cwd);
178
211
  const settings = await getSettings().catch(() => null);
212
+ // 〔附件〕段:配置了模板(settings.attachTemplate)按模板渲染(ctx 见设置页
213
+ // 「变量字典」),空 = 内置默认(历史输出逐字节不变)。
214
+ const attSeg = att
215
+ ? attachInstructionOf(settings && settings.attachTemplate, att.task.attachments, att.sync, att.task)
216
+ : '';
179
217
  const deliveryTpl = (settings && settings.deliveryTemplate) || DEFAULT_DELIVERY_TEMPLATE;
180
218
  const groupText = renderDelivery(
181
219
  deliveryTpl,
@@ -0,0 +1,57 @@
1
+ // 评论 / 反馈回写的正文拼装原语 —— 服务端与面板共用同一份(#79)。
2
+ //
3
+ // 为什么要有这一份:段名(## 反馈修改 / ## 验收反馈 / ## 上一轮完成总结)、
4
+ // 锚定引用格式(> 锚定:)、逐行加粗口径,此前只在面板 modules/board/reopen-text.js
5
+ // 有一份;服务端要把反馈**追加**到盘上正文(#79:面板会话 doc 可能过期,拿旧正文
6
+ // 拼回去就是「评论一次丢一次」),两处各写一套,段名与格式迟早分叉——收口到这里。
7
+ //
8
+ // 纯函数、零依赖:node 单测直接 import,vite 打包进前端,服务端 src/modules 共用。
9
+
10
+ /** 上轮 ack 完成总结段标题 */
11
+ export const ACK_SUMMARY_HEADING = '## 上一轮完成总结';
12
+ /** 验收反馈段标题(ack 场景:已完成任务的重做) */
13
+ export const FEEDBACK_HEADING = '## 验收反馈';
14
+ /** 普通反馈段标题(非 ack 场景:任务没完成时的「反馈修改」) */
15
+ export const PLAIN_FEEDBACK_HEADING = '## 反馈修改';
16
+
17
+ /**
18
+ * 反馈逐行加粗(用户口径:重开的任务要携带着反馈文字在正文中,最好加粗)。
19
+ * 空行不加粗(`**` 会渲染成一行空的粗体)。 */
20
+ export function boldFeedback(text) {
21
+ return String(text ?? '')
22
+ .split('\n')
23
+ .map((line) => (line.trim() ? `**${line}**` : line))
24
+ .join('\n');
25
+ }
26
+
27
+ /** 划选原文 → 锚定引用块(面板与服务端共用一种格式);空选区返回空串 */
28
+ export function quoteBlock(quote) {
29
+ const q = String(quote ?? '').trim();
30
+ if (!q) return '';
31
+ return `> 锚定:\n> ${q.replace(/\n/g, '\n> ')}`;
32
+ }
33
+
34
+ /**
35
+ * 反馈段:段名 +(可选)锚定引用 + 反馈正文(bold 时逐行加粗)。
36
+ * 反馈与选区都空 → 返回空串(调用方据此不追加)。
37
+ */
38
+ export function feedbackSection({ heading, quote, feedback, bold = false } = {}) {
39
+ const fb = String(feedback ?? '').trim();
40
+ if (!fb) return '';
41
+ const body = bold ? boldFeedback(fb) : fb;
42
+ const anchor = quoteBlock(quote);
43
+ return `${String(heading ?? PLAIN_FEEDBACK_HEADING)}\n\n${anchor ? `${anchor}\n\n` : ''}${body}`;
44
+ }
45
+
46
+ /**
47
+ * 把反馈段**追加**到一份完整正文末尾(#79 服务端评论回写的拼装口径):
48
+ * 第一个区块永远是完整的之前的任务,接着才是引用字符和评论。
49
+ * base 空 → 只返回反馈段;反馈段空 → base 原样返回(带收尾换行规整)。
50
+ */
51
+ export function appendFeedback({ base, heading, quote, feedback, bold = false } = {}) {
52
+ const b = String(base ?? '').trimEnd();
53
+ const sec = feedbackSection({ heading, quote, feedback, bold });
54
+ if (b && !sec) return `${b}\n`;
55
+ if (!b && !sec) return '';
56
+ return `${b ? `${b}\n\n` : ''}${sec}\n`;
57
+ }
@@ -261,25 +261,18 @@ export default function App() {
261
261
  // ─── 路由 → 面板:地址指向哪块,就打开/聚焦哪块 ───
262
262
  const specCtx = useMemo(() => {
263
263
  // group 路由的 key = 看板 id;dir 路由的 key = 主题 key——两组身份别混。
264
+ // 组名只给组页的面板命名用——仓库是独立模块,仓库路由不再向上挂组(#84)。
264
265
  const boardById = (repoData.boards || []).find((b) => b.id === route.key);
265
266
  const topic = rows.find((r) => r.key === route.key);
266
- // 目录页面包屑要带上所属组([ nx/nx-kv/draft ]):优先 topic.repo.boards,
267
- // 再回落到仓库登记里的 boards[]。
268
- const repo =
269
- (topic && topic.repo) ||
270
- (repoData.repos || []).find((r) => topic && (r.id === topic.repo?.id || r.path === topic.cwd)) ||
271
- null;
272
- const boardFromRepo = (repo && repo.boards && repo.boards[0]) || null;
273
267
  const taskRow = topic && route.task
274
268
  ? (topic.tasks || []).find((t) => String(t.id) === String(route.task))
275
269
  : null;
276
270
  return {
277
- boardName: (boardById && boardById.name) || (boardFromRepo && boardFromRepo.name) || '',
278
- boardId: (boardById && boardById.id) || (boardFromRepo && boardFromRepo.id) || '',
271
+ boardName: (boardById && boardById.name) || '',
279
272
  dirName: topic ? topic.name : '',
280
273
  pageTitle: taskRow ? `#${taskRow.id}` : '',
281
274
  };
282
- }, [repoData.boards, repoData.repos, rows, route.key, route.task]);
275
+ }, [repoData.boards, rows, route.key, route.task]);
283
276
 
284
277
  // 路由 → 面板:地址指向哪块,就打开/聚焦哪块。
285
278
  // **只跟路由走**(模型用 ref):模型一变就重跑,会按**旧路由**把面板抢回去
@@ -1,5 +1,5 @@
1
1
  // 面包屑(工作区顶部)——2026-11-04 #33:页签与页签条删掉之后,
2
- // 「我现在在哪」由顶部这条路径回答([ nx/nx-kv/draft ])。
2
+ // 「我现在在哪」由顶部这条路径回答([ nx-kv/#81 ];仓库是独立模块,不再带组前缀——#84)。
3
3
  //
4
4
  // 数据来自**路由**(地址栏即位置)——不是从布局模型反推:布局里没有页签了,
5
5
  // 路由才是唯一的「当前位置」真源(面板身份也由路由决定)。