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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,86 @@
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
+
53
+ ## [0.26.1] - 2026-11-05 任务页头部收敛 + `skill install --all`
54
+
55
+ ### Added
56
+
57
+ - **`skill install --all`:一次装齐包内全部 skill,且直接覆盖**。以前要给本机装全
58
+ 只能逐个点名或按 `--group` 一组一组来(组表是别名,漏登记的 skill 就装不上)。
59
+ `--all` 的范围由 `assets/` **目录扫描**决定——事实源是 `assets/<x>/SKILL.md`,
60
+ 新增 skill 忘了写进 `groups.json` 也照样装得到。覆盖是隐式的:不用再补 `--force`,
61
+ 目标目录会被删掉重建,与包内版本对齐(要保留本地改动就别用 `--all`)。
62
+ `--all` 与 `<name>` / `--group` 互斥,同时给会直接报错。
63
+
64
+ ### Changed
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`(服务端与面板共用一份)。
79
+ - **任务页头部收敛(任务 #78)**:头部只留「模式 · 时间目标勋章 | 新任务 · 提交 · 更多」——
80
+ 任务链 / 预览提示词 / 插入图片 / 添加附件 / 导入 / 克隆 / 评论 / 存草稿 / 删除 / 总览 /
81
+ 进程 / 原文 / 快捷键全部收进「更多」菜单;MD 格式条撤出头部(划选浮条 + 行首 `/` 命令 +
82
+ Ctrl/⌘B 等快捷键已覆盖);时间目标不再占一整行——设置进「更多」菜单顶部编辑,
83
+ 设了目标外部以勋章(⏱ 时长)回显、点勋章同样展开菜单,没设目标零噪音。
84
+
5
85
  ## [0.26.0] - 2026-11-05 ack 与评论统一回写原任务 + 任务链可视化
6
86
 
7
87
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,6 +12,29 @@ function exclusive(ctx, cmd) {
12
12
  if (ctx.group !== undefined && ctx.group !== null && ctx.group !== '' && ctx.name) {
13
13
  throw badInput(`${cmd} 的 <name> 与 --group 只能给一个`);
14
14
  }
15
+ // --all 是「全装」:再点名某个 skill 或某个组就是自相矛盾。
16
+ // 放在这里而不是 service 里,因为 service 侧的 name 有默认值,分不出是用户给的还是补的。
17
+ if (ctx.all) {
18
+ if (ctx.name) throw badInput(`${cmd} 的 <name> 与 --all 只能给一个(--all 已装全部)`);
19
+ if (ctx.group !== undefined && ctx.group !== null && ctx.group !== '') {
20
+ throw badInput(`${cmd} 的 --group 与 --all 只能给一个(--all 已覆盖所有组)`);
21
+ }
22
+ }
23
+ }
24
+
25
+ // 聚合结果(--group / --all)的人读渲染:一行汇总 + 每个 skill 一行三态。
26
+ // 两种范围共用同一段渲染,只有标题不同——避免两处各写一遍后逻辑漂移。
27
+ function renderScoped(label, d) {
28
+ const done = d.skills.filter((r) => r.status === 'ok').length;
29
+ const lines = [`${label}: ${done}/${d.skills.length} 已就绪`];
30
+ for (const r of d.skills) {
31
+ const what = r.status === 'conflict'
32
+ ? `冲突(${r.count} 个文件不同)→ 用 --force 覆盖`
33
+ : r.skipped ? '已是最新'
34
+ : `${r.replaced ? '已更新' : '已安装'}(${r.files} 个文件)-> ${r.path}`;
35
+ lines.push(` ${r.name.padEnd(16)} ${what}`);
36
+ }
37
+ return lines.join('\n');
15
38
  }
16
39
 
17
40
  const GROUP_FLAG = { type: 'string', hint: 'groups.json 里的组名(与 <name> 互斥)' };
@@ -113,32 +136,28 @@ export default {
113
136
  id: 'bundled.install',
114
137
  cli: ['skill', 'install'],
115
138
  http: ['POST', '/api/bundled/install'],
116
- summary: '安装内置 skill 到 skills 目录(默认 nx-kv → ~/.claude/skills;--group <key> 一键装一组)',
139
+ summary: '安装内置 skill 到 skills 目录(默认 nx-kv → ~/.claude/skills;--group <key> 一键装一组;--all 装全部并直接覆盖)',
117
140
  args: [{ name: 'name', required: false }],
118
- flags: { group: GROUP_FLAG, to: { type: 'string' }, force: { type: 'boolean' } },
141
+ flags: {
142
+ group: GROUP_FLAG,
143
+ to: { type: 'string' },
144
+ force: { type: 'boolean' },
145
+ all: { type: 'boolean', hint: '装 assets/ 下的全部内置 skill(隐式覆盖,不需要 --force)' },
146
+ },
119
147
  run: (ctx) => {
120
148
  exclusive(ctx, 'skill install');
121
149
  return service.installBundledSkill({
122
150
  name: ctx.name || service.DEFAULT_SKILL_NAME,
123
151
  group: ctx.group,
152
+ all: ctx.all,
124
153
  to: ctx.to,
125
154
  force: ctx.force,
126
155
  });
127
156
  },
128
157
  render: (d) => {
129
- // 聚合形状用**显式 group 字段**判别,不做形状嗅探(B04 §实现要点)
130
- if (d.group) {
131
- const done = d.skills.filter((r) => r.status === 'ok').length;
132
- const lines = [`group ${d.group}: ${done}/${d.skills.length} 已就绪`];
133
- for (const r of d.skills) {
134
- const what = r.status === 'conflict'
135
- ? `冲突(${r.count} 个文件不同)→ 用 --force 覆盖`
136
- : r.skipped ? '已是最新'
137
- : `${r.replaced ? '已更新' : '已安装'}(${r.files} 个文件)-> ${r.path}`;
138
- lines.push(` ${r.name.padEnd(16)} ${what}`);
139
- }
140
- return lines.join('\n');
141
- }
158
+ // 聚合形状用**显式字段**判别,不做形状嗅探(B04 §实现要点):先 group 后 all
159
+ if (d.group) return renderScoped(`group ${d.group}`, d);
160
+ if (d.all) return renderScoped(`--all(${d.count} 个 skill,已覆盖)`, d);
142
161
  if (d.status === 'conflict') {
143
162
  const files = d.files.map((f) => ` ${f.file} ${f.side}`).join('\n');
144
163
  return `目标已存在且内容不同(${d.count} 个文件): ${d.path}\n${files}\n用 --force 覆盖,或先删除目标目录`;
@@ -193,13 +193,43 @@ async function installOne(name, { to, force } = {}) {
193
193
  return { status: 'ok', installed: !exists, replaced: exists, name, path: dst, files: files.length, group: null };
194
194
  }
195
195
 
196
+ // `--all`:把 assets/ 下**所有**内置 skill 一次装齐,且**隐式覆盖**(不需要 --force)。
197
+ //
198
+ // 与 `--group` 的关键差别:范围由**目录扫描**决定,不由 groups.json 决定。组表只是
199
+ // 便捷别名,`assets/<x>/SKILL.md` 才是事实源——新加一个 skill 忘了登记组时,
200
+ // `--all` 照样装得上,`--group` 会漏。所以「本机装全」该用 --all 而不是列举组名。
201
+ async function installAll({ to } = {}) {
202
+ const names = await assetSkillDirs();
203
+ if (!names.length) throw notFound('assets/ 下没有任何内置 skill(缺 SKILL.md?)');
204
+ const skills = [];
205
+ // force 恒为 true:--all 的语义就是「装全 + 对齐到包内版本」,
206
+ // 让人再补一个 --force 只是多一次来回。要保留本地改动就别用 --all。
207
+ for (const s of names) skills.push(await installOne(s, { to, force: true }));
208
+ return {
209
+ status: skills.every((r) => r.status === 'ok') ? 'ok' : 'conflict',
210
+ all: true,
211
+ count: skills.length,
212
+ skills,
213
+ };
214
+ }
215
+
196
216
  // 安装内置 skill 到目标 skills 目录(默认 nx-kv → ~/.claude/skills)。
197
217
  // 返回 { status: 'ok' | 'conflict', ... }——已存在且内容不同是**业务结果**,
198
218
  // 需要用户决定是否覆盖,不是错误。
199
219
  //
200
220
  // `group` 给定时装该组的**全部** skill,返回聚合形状 { status, group, skills:[…] };
201
- // 不给则装单个,形状与历史一致。两者的判别靠显式 `group` 字段。
202
- export async function installBundledSkill({ name = DEFAULT_SKILL_NAME, group, to, force } = {}) {
221
+ // `all` 给定时装**目录里有的全部**,形状 { status, all, skills:[…] }(隐式 force);
222
+ // 都不给则装单个,形状与历史一致。判别一律靠显式字段,不做形状嗅探。
223
+ export async function installBundledSkill({ name = DEFAULT_SKILL_NAME, group, all, to, force } = {}) {
224
+ if (all) {
225
+ // name 有默认值,这里分不出「用户显式给了 name」还是「默认」,
226
+ // 所以 name 与 --all 的互斥放在 CLI 层(ctx.name 才是用户真正输入的)。
227
+ // group 给了就是调用方用错了,直接报。
228
+ if (group !== undefined && group !== null && group !== '') {
229
+ throw badInput('--all 与 --group 只能给一个(--all 已覆盖所有组)');
230
+ }
231
+ return installAll({ to });
232
+ }
203
233
  if (group !== undefined && group !== null && group !== '') {
204
234
  const g = await resolveGroup(group);
205
235
  const skills = [];
@@ -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,