nx-kv 0.65.0 → 0.65.2

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 (76) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/package.json +1 -1
  3. package/src/core/db/seed-templates.ts +2 -86
  4. package/src/modules/localtask/task-lifecycle.ts +1 -1
  5. package/src/modules/promptplug/delivery.ts +151 -0
  6. package/src/modules/promptplug/factory.ts +3 -3
  7. package/src/modules/promptplug/index.ts +3 -1
  8. package/src/modules/promptplug/plugins/getloop.ts +8 -7
  9. package/src/modules/{tasktool/plugins/goal-template.ts → promptplug/plugins/goal-prompt.ts} +4 -3
  10. package/src/modules/tasktool/delivery.ts +231 -0
  11. package/src/modules/tasktool/get.ts +2 -2
  12. package/src/modules/tasktool/plugins/taskgoal-store.ts +1 -1
  13. package/src/modules/tasktool/plugins/timegoal-task-store.ts +2 -2
  14. package/src/modules/tasktool/plugins/waitgoal-config.ts +1 -25
  15. package/src/modules/tasktool/plugins/waitgoal.ts +0 -4
  16. package/src/modules/tasktool/preview.ts +3 -4
  17. package/src/modules/tasktool/wait.ts +16 -283
  18. package/src/modules/templates/actions/templates-default.ts +2 -5
  19. package/src/modules/templates/actions/templates-update.ts +1 -3
  20. package/src/modules/templates/service.ts +11 -13
  21. package/src/modules/templates/support.ts +0 -15
  22. package/src/web/frontend/App.tsx +0 -12
  23. package/src/web/frontend/api/client.generated.ts +2 -2
  24. package/src/web/frontend/components/md/live-block.tsx +1 -5
  25. package/src/web/frontend/components/md/md-panes-root.tsx +0 -4
  26. package/src/web/frontend/components/md/md-panes.tsx +1 -11
  27. package/src/web/frontend/modules/md/styles/docs.css +0 -7
  28. package/src/web/frontend/modules/md/styles/editor.css +0 -17
  29. package/src/web/frontend/modules/md/use-templates.ts +3 -13
  30. package/src/web/frontend/page/dir/index.tsx +3 -15
  31. package/src/web/frontend/page/dir/task-actions.ts +1 -16
  32. package/src/web/frontend/page/dir/task.tsx +2 -16
  33. package/src/web/frontend/page/group/index.tsx +6 -19
  34. package/src/web/frontend/page/settings/index.tsx +1 -1
  35. package/src/web/frontend/page/templates/index.tsx +5 -54
  36. package/src/web/frontend/page/templates/manage.tsx +1 -5
  37. package/src/web/frontend/page/templates/style.css +1 -43
  38. package/src/web/frontend/page/templates/template-list.tsx +7 -15
  39. package/src/web/frontend/routes/route-eq.ts +2 -3
  40. package/src/web/frontend/routes/templates.ts +0 -10
  41. package/src/web/frontend/styles-v2/shell.css +7 -0
  42. package/src/web/frontend/types.ts +2 -1
  43. package/src/web/public/assets/{bar-csH6ZW39.js → bar-Dc5Tq1eE.js} +1 -1
  44. package/src/web/public/assets/{composer-launch-Ba9cBxhb.js → composer-launch-fp2IzGzQ.js} +1 -1
  45. package/src/web/public/assets/{composer-panel-7SHKllt5.js → composer-panel-Dh681iO6.js} +1 -1
  46. package/src/web/public/assets/dir-d16q1GLe.js +3 -0
  47. package/src/web/public/assets/{doc-BmGb9F-k.js → doc-DRSKD0Re.js} +1 -1
  48. package/src/web/public/assets/group-Dc3ZgW24.js +1 -0
  49. package/src/web/public/assets/{index-D1wpt-oL.css → index-BIVxGd6t.css} +1 -1
  50. package/src/web/public/assets/index-Bg0m8gbJ.js +2 -0
  51. package/src/web/public/assets/{md-history-DVI47hu4.js → md-history-DNtgaIdH.js} +6 -6
  52. package/src/web/public/assets/{refs-P8HrKv4T.js → refs-TzxZYy7T.js} +1 -1
  53. package/src/web/public/assets/{repo-form-modal-BiBZ63DZ.js → repo-form-modal-Dg3hJWUV.js} +1 -1
  54. package/src/web/public/assets/{repos-B9D8q6U7.js → repos-uNqSR5YB.js} +1 -1
  55. package/src/web/public/assets/task-DuFOXLPC.js +11 -0
  56. package/src/web/public/assets/{task-utils-DPGXUIOk.js → task-utils-DAPxKm4c.js} +1 -1
  57. package/src/web/public/assets/templates-CwYDIBYn.css +1 -0
  58. package/src/web/public/assets/templates-DNiGvmdq.js +10 -0
  59. package/src/web/public/assets/{use-rail-drag-TGx8CLcY.js → use-rail-drag-DxIYcszo.js} +1 -1
  60. package/src/web/public/index.html +6 -7
  61. package/src/web/frontend/modules/md/fill-session.ts +0 -36
  62. package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
  63. package/src/web/frontend/modules/md/task-intent.ts +0 -29
  64. package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
  65. package/src/web/frontend/modules/prompts/template-preview.ts +0 -62
  66. package/src/web/frontend/page/templates/fill.tsx +0 -126
  67. package/src/web/public/assets/dir-D5AImCiy.js +0 -3
  68. package/src/web/public/assets/fill-session-fHxQHFaD.js +0 -1
  69. package/src/web/public/assets/group-CTktws14.js +0 -1
  70. package/src/web/public/assets/index-Byb7MFTl.js +0 -2
  71. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +0 -1
  72. package/src/web/public/assets/render-template-body-bXdedFig.js +0 -1
  73. package/src/web/public/assets/task-BBk0TQZi.js +0 -11
  74. package/src/web/public/assets/task-intent-CX5DZccN.js +0 -1
  75. package/src/web/public/assets/templates-BN9i9-6c.js +0 -11
  76. package/src/web/public/assets/templates-plA8R7jJ.css +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.65.2] - 2026-11-19 getloop 残留预渲染链清理(#230 审计)
6
+
7
+ ### Changed
8
+
9
+ - **getloop 段模板清理**(#230,审计裁决「没删干净的残留」):#182 下线仓库级 template
10
+ 口子时,`getLoopInstruction → getLoopTpl → loopText Supply → data.getloop.text` 这条
11
+ 预渲染管道没拆——预渲染上下文缺 `getloop` 键,产出的 `text` 是残缺副本(分钟子句被
12
+ 丢),插件内置模板也从不消费它;同一段文案存在三份(两个别名常量 + BUILTIN)。
13
+ 已整条删除:getloop 插件改收 `enabled` 开关 Supply,`dataSchema` 去掉 `text` 字段
14
+ (变量目录与 `prompt.registry` 同步收窄),文案唯一真相 = 插件内置模板。
15
+ **交付渲染输出逐字节不变**(golden 仅 ctx 基线重生成,`.txt` 正文基线零变化)。
16
+ - 契约与 Dart 包按流程重新生成(`pnpm gen:dart`,变量目录变化同步)。
17
+
18
+ ### Removed
19
+
20
+ - `tasktool/plugins/waitgoal-config.ts` 的 `DEFAULT_GETLOOP_INSTRUCTION` /
21
+ `DEFAULT_GET_LOOP_TEMPLATE` 常量与 `getLoopInstruction()`(随预渲染链一并删除;
22
+ 外部取文案请读 getloop 插件类内置模板)。
23
+
24
+ ## [0.65.1] - 2026-11-19 交付组装收编 promptplug(#227 重构)
25
+
26
+ ### Changed
27
+
28
+ - **交付组装收编 promptplug**(#227):`buildTaskDelivery` 的组装下半段(seed 构造 /
29
+ 平面扩展键保护 / getloop 预渲染 / get+check+done 三链合并 / coversBody 判定)从
30
+ `tasktool/wait.ts` 收编为 `promptplug/delivery.ts` 的 `assembleDelivery()`;宿主取数
31
+ (附件标注 / timegoal 起表 / 组上下文 / 队列余量)留在新文件 `tasktool/delivery.ts`,
32
+ `wait.ts` 只剩阻塞编排(跨进程轮询 / goal 到点收尾 / 面板随行)。边界从此可查:
33
+ **promptplug 管模板正文 + 变量 + 组装 + 渲染,tasktool 管取数 + 阻塞**。
34
+ 交付输出**逐字节不变**(prompt-golden 等 1106 项单测 + smoke 96/96 全绿钉住)。
35
+ - **任务级 timegoal 提示词模板归位**(#227):`goal-template.ts` 从 `tasktool/plugins/`
36
+ 迁为 `promptplug/plugins/goal-prompt.ts`——模板正文归提示词模板体系;领取路径
37
+ (taskgoal-store)与 check 路径(timegoal-task-store)改从 promptplug 取用,
38
+ 依赖方向单一(tasktool → promptplug),不再依赖「模板夹在两个互相 import 的
39
+ store 之间」来防环。
40
+
5
41
  ## [0.65.0] - 2026-11-19 提示词三段化 / 段模板管理 / check 历史警告
6
42
 
7
43
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.65.0",
3
+ "version": "0.65.2",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,44 +17,7 @@
17
17
  import type { DbApi } from './driver.js';
18
18
 
19
19
  /**
20
- * 插槽的**统一写法**(#218):`{{content}}`。
21
- *
22
- * 为什么不许自定义名字:#217 的锁定判定靠「模板里有槽位就把它当可编辑出口」,
23
- * 名字各写各的(`{{问题}}` / `{{任务}}` / `{{需求}}`)时,一眼看不出哪段是插槽,
24
- * 也没法在文案里给用户一个固定说法。所以对用户只认一个名字 —— 一个模板可以有
25
- * 多个 `{{content}}`,它们共享同一个值(模板正文里重复出现同一段内容时用得上)。
26
- *
27
- * 渲染层仍按 `{{名字}}` 通用解析(老模板不至于一升级就失效),但出厂文本、
28
- * 新建骨架、面板文案一律只出现 `content`。
29
- */
30
- export const SLOT_NAME = 'content';
31
-
32
- /** 内置模板的槽位默认值:提示文字,不是空串(空块看不出该写什么)。 */
33
- const CONTENT_HINT = '(把你要问这个仓库的问题写在这里)';
34
-
35
- /** 模板正文里有没有插槽(含 `{{content}}` 或任何 `{{名字}}`)。 */
36
- function hasSlot(body: string): boolean {
37
- return /\{\{\s*[^}{\s][^{}]*?\s*\}\}/.test(String(body || ''));
38
- }
39
-
40
- /**
41
- * 出厂正文「被当成普通正文保存过一次」的样子:插槽已经渲染成默认值。
42
- *
43
- * #217 的模板编辑器曾经把正文渲染后再给用户编辑(保存即把 `{{content}}`
44
- * 写成提示文字),库里因此留下一批「没有插槽的内置模板」。#218 修了编辑器,
45
- * 同时用这个形态做**自愈判据**:body 与它逐字相同 = 用户没改过内容,可以安全
46
- * 恢复成带插槽的出厂文本;差一个字都不动(T06:内置不被代码覆盖用户编辑)。
47
- */
48
- function renderedFactoryBody(t: { body: string; vars?: Readonly<Record<string, unknown>> }): string {
49
- const vals = t.vars || {};
50
- return String(t.body || '').replace(/\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g, (_all, name) => {
51
- const v = vals[String(name).trim()];
52
- return v === undefined || v === null ? '' : String(v);
53
- });
54
- }
55
-
56
- /**
57
- * 内置「ref 生成」任务模板的正文(#137;#218 起插槽统一 `{{content}}`)。
20
+ * 内置「ref 生成」任务模板的正文(#137)。
58
21
  *
59
22
  * 它是**新任务正文骨架**:用户在这个仓库里提一个问题 → agent 按正文里的
60
23
  * 「零知识起步 SOP」走一遍 → 这轮问答被归档成一篇 ref,挂进该仓库的文档列表。
@@ -64,7 +27,6 @@ function renderedFactoryBody(t: { body: string; vars?: Readonly<Record<string, u
64
27
  */
65
28
  export const NEWTASK_REF_BODY = `## 本轮问题
66
29
 
67
- {{content}}
68
30
 
69
31
  ---
70
32
 
@@ -142,10 +104,7 @@ export const BUILTIN_TEMPLATES = Object.freeze([
142
104
  slot: 'suffix',
143
105
  body: NEWTASK_REF_BODY,
144
106
  varsSchema: [],
145
- // 槽位默认值 = 用户看到的「填这里」提示:渲染后任务里不是空块,点进去改成自己的问题即可。
146
- // 默认值是**提示文字**而不是空串,是因为 #217 之后这块在编辑器里是「可编辑插槽」——
147
- // 空块看不出该写什么。
148
- vars: { [SLOT_NAME]: CONTENT_HINT },
107
+ vars: {},
149
108
  isDefault: 1,
150
109
  },
151
110
  {
@@ -244,48 +203,5 @@ export function seedBuiltinTemplates(conn: DbApi, atMs: number): number {
244
203
  }
245
204
  );
246
205
  }
247
- // ③ 出厂正文自愈(#218):插槽被旧编辑器吃掉的 builtin 行恢复成带 {{content}} 的出厂文本
248
- healRenderedBuiltinBodies(conn, atMs);
249
206
  return BUILTIN_TEMPLATES.length;
250
207
  }
251
-
252
- /**
253
- * 出厂正文自愈(#218;seedBuiltinTemplates 的第 ③ 步,独立导出以便单测)。
254
- *
255
- * 两条判据,都只碰 `builtin = 1` 的行(用户自建模板 builtin=0,一律不动):
256
- *
257
- * ① **逐字相等**:body === 「出厂文本按默认值渲染后的样子」。
258
- * 旧编辑器「先渲染再编辑、保存回库」的产物,插槽变了提示文字。
259
- * ② **渲染残留**:库里这行一个插槽都没有,**但还留着出厂的提示文字**
260
- * (`{{content}}` 被替换成的「(把你要问这个仓库的问题写在这里)」)。
261
- * 跨了几个版本之后 ① 对不上(出厂文本本身改过),但症状一样:正文里再也
262
- * 检不出槽位,「新建任务」永远进不了参数填写页(#153 验收反馈)。
263
- * 只认「提示文字还在」这一种残留——用户手写的正文里没有这句提示,
264
- * 照旧按 T06 不动。
265
- *
266
- * 返回被恢复的模板 id(正常库上是空数组,幂等)。
267
- */
268
- export function healRenderedBuiltinBodies(conn: DbApi, atMs: number): string[] {
269
- const healed: string[] = [];
270
- for (const t of BUILTIN_TEMPLATES) {
271
- if (!hasSlot(t.body)) continue;
272
- const eaten = renderedFactoryBody(t);
273
- if (eaten === t.body) continue;
274
- const row = conn.get('SELECT body, builtin FROM templates WHERE id = :id', { id: t.id }) as
275
- | { body?: string; builtin?: number }
276
- | undefined;
277
- if (!row || !Number(row.builtin)) continue;
278
- const cur = String(row.body || '');
279
- const rendered = cur === eaten;
280
- // 跨版本的渲染残留:没有插槽,但出厂提示文字还在(= 旧编辑器把插槽渲染成了提示)
281
- const staleRender = !hasSlot(cur) && cur.includes(CONTENT_HINT);
282
- if (!rendered && !staleRender) continue;
283
- conn.run(
284
- `UPDATE templates SET body = :body, vars = :vars, updated_at = :at
285
- WHERE id = :id AND builtin = 1`,
286
- { id: t.id, body: t.body, vars: JSON.stringify(t.vars || {}), at: atMs },
287
- );
288
- healed.push(t.id);
289
- }
290
- return healed;
291
- }
@@ -4,7 +4,7 @@
4
4
  import { badInput, notFound } from '../../core/errors.js';
5
5
  import { formatDuration, renderInstruction } from '../../core/instruction-template.js';
6
6
  import { activeTemplateOf } from '../promptplug/index.js';
7
- import { taskGoalTemplateCtx } from '../tasktool/plugins/goal-template.js';
7
+ import { taskGoalTemplateCtx } from '../promptplug/plugins/goal-prompt.js';
8
8
  import { preserveFrontmatter } from '../../shared/frontmatter.js';
9
9
  import {
10
10
  FEEDBACK_HEADING,
@@ -0,0 +1,151 @@
1
+ // promptplug/delivery.ts —— 交付组装(assembleDelivery):seed 构造 + 三链合并 + compose。
2
+ //
3
+ // 这是「一条交付提示词怎么拼出来」的**唯一实现**(#227 重构:原样从 tasktool/wait.ts
4
+ // 的 buildTaskDelivery 下半段收编进来)。宿主(tasktool/delivery.ts)完成领域取数
5
+ // (附件标注 / 时间目标起表 / 组上下文 / 队列余量)后,把取好的数据装进
6
+ // DeliveryHostData 交到这里;本文件不再碰任何业务模块——promptplug 不 import
7
+ // 其他模块的边界保持不变。
8
+ //
9
+ // #230 清理:原「getLoopTpl 预渲染 → data.getloop.text」残留链路已删——#182 起项目级
10
+ // template 口子下线,getloop 文案唯一真相是插件内置模板,本文件只给 enabled 开关与分钟数。
11
+ // 之所以收进 promptplug:组装配方(平面扩展的键保护 / 三链合并 / coversBody 判定)
12
+ // 是提示词域的语义,不是队列域的。
13
+ // 之前它埋在 wait.ts(阻塞编排文件)里,测试只能各自手工复刻(prompt-golden /
14
+ // delivery-template 两个测试都有「与 wait.ts 同构」的最小组装)——现在它们可以
15
+ // 直接调 assembleDelivery。
16
+ import { reorderRoundsForDelivery } from '../../shared/feedback-text.js';
17
+ import { compose, type RenderTraceEntry, type RenderWarning, type SegmentMeta } from './compose.js';
18
+ import { buildPlugins } from './factory.js';
19
+
20
+ /** compose 的分段元信息(面板「这段是哪来的」的展示标签),交付组装的固定清单。 */
21
+ export const DELIVERY_SEGMENTS: SegmentMeta[] = [
22
+ { id: 'context', label: '组 / 项目上下文(模板)', traceId: 'delivery' },
23
+ { id: 'attachment', label: '附件段(清单 / 本地路径)', traceId: 'attach' },
24
+ { id: 'timegoal', label: '时间目标启动(介绍 / 每轮怎么做)', traceId: 'goal' },
25
+ { id: 'doneguard', label: '完成门禁提示(timegoal)', traceId: 'doneguard' },
26
+ { id: 'ext', label: '待领取队列(ext)', traceId: 'ext' },
27
+ { id: 'ack', label: 'ack 完成总结提示词', traceId: 'ack' },
28
+ { id: 'getloop', label: '持续 get 指令(项目级)', traceId: 'getloop' },
29
+ ];
30
+
31
+ // 平面扩展的**内建键保护名单**:外部参数(--param k=v)顶层直达 {{k}},
32
+ // 但不许覆盖 seed 的内建键(ctx 形状是插件 dataSchema 白名单的前提)。
33
+ const SEED_PROTECTED_KEYS = ['task', 'goal', 'cwd', 'source', 'summary', 'name', 'repo', 'group', 'refRepos', 'groups'];
34
+
35
+ /** 外部参数 → 平面扩展表({{k}} 顶层直达;内建键被保护不被覆盖;{{params.k}} 永远可用)。 */
36
+ export function flatParamsOf(params?: Record<string, string>): Record<string, unknown> {
37
+ const flat: Record<string, unknown> = {};
38
+ for (const [k, v] of Object.entries(params || {})) {
39
+ if (SEED_PROTECTED_KEYS.includes(k)) continue;
40
+ flat[k] = v;
41
+ }
42
+ return flat;
43
+ }
44
+
45
+ /** 宿主取好的领域数据(取数细节见 tasktool/delivery.ts——本文件不做任何 IO)。 */
46
+ export interface DeliveryHostData {
47
+ /** 标注后的任务行(id / text);无任务 → null(指令段也照常渲染) */
48
+ task: any | null;
49
+ /** 附件段 ctx(attachTemplateCtx 产物);无附件 → null */
50
+ attachCtx: any | null;
51
+ /** 最终 goal ctx(enrichGoalTiming + 任务级/目录级合并后);无目标 → null */
52
+ goalCtx: any | null;
53
+ /** 组上下文(readGroupContext 产物);非组任务 → null */
54
+ groupCtx: any | null;
55
+ /** 队列余量(pendingQueueInfo 产物,count>0 才给);null → ext 段不出 */
56
+ queueInfo: { topic: string; count: number; list: { id: number; title: string }[] } | null;
57
+ /** 项目级「持续 get」开关(宿主从 waitgoal 配置读出);false = 段不出 */
58
+ getLoopEnabled?: boolean;
59
+ /** 项目级阻塞窗口(分钟):进 getloop 模板 ctx */
60
+ getLoopWaitMinutes?: number;
61
+ /** 外部参数(--param k=v 解析产物):{{params.k}} + 平面扩展 {{k}} */
62
+ params?: Record<string, string>;
63
+ /** 设置里的追加模式:'plain' 直拼文本,其余(含缺省)包 XML 标签 */
64
+ appendMode?: unknown;
65
+ /** seed 原样透传的上下文键(保持 unknown:宿主传什么 seed 就是什么) */
66
+ source?: unknown;
67
+ summary?: unknown;
68
+ cwd?: unknown;
69
+ name?: unknown;
70
+ /** 宿主侧告警(如 ext 读取失败),并入 renderWarnings(排在本文件告警之后) */
71
+ hostWarnings?: RenderWarning[];
72
+ /** 逐段来源追踪(面板预览用;真实领取不传) */
73
+ trace?: RenderTraceEntry[];
74
+ }
75
+
76
+ export interface AssembledDelivery {
77
+ /** 拼好的完整指令;空串 = 没有任何段输出(宿主按「只回任务」降级) */
78
+ instruction: string;
79
+ /** 任一模板含 {{task.text}} → 指令自包含任务正文(服务端判定,CLI 不做子串猜测) */
80
+ coversBody: boolean;
81
+ /** 渲染告警(段渲染失败但交付继续的口径),已并宿主告警 */
82
+ renderWarnings: RenderWarning[];
83
+ }
84
+
85
+ /**
86
+ * 组装一次交付提示词。**单一路径**:所有段落(上下文 / 附件 / 时间目标 / ack /
87
+ * 持续 get / done 门禁)合并成一条 instruction;task.text 始终是库存原文,
88
+ * 绝不把系统提示词拼进正文。
89
+ *
90
+ * 交付一次给全三条链(get → check → done,合并后按各段 order 全局排序):
91
+ * check(时间目标)与 done(完成门禁)没有独立的注入点——它们本来就是
92
+ * 「领取时告诉 agent 每轮怎么检查、什么时候才能收口」,等 agent 真去 done 再给
93
+ * 已经晚了;三者链内都是条件渲染,无数据即不出段。
94
+ */
95
+ export async function assembleDelivery(host: DeliveryHostData): Promise<AssembledDelivery> {
96
+ const {
97
+ task,
98
+ attachCtx: attach,
99
+ goalCtx: goal,
100
+ groupCtx,
101
+ queueInfo,
102
+ getLoopEnabled = false,
103
+ getLoopWaitMinutes = 0,
104
+ params,
105
+ appendMode,
106
+ trace,
107
+ } = host;
108
+ const renderWarnings: RenderWarning[] = [];
109
+
110
+ const flat = flatParamsOf(params);
111
+ const seedCtx: Record<string, any> = {
112
+ task: task ? { id: task.id, text: reorderRoundsForDelivery(String(task.text || '')) } : null,
113
+ goal: goal ?? null,
114
+ source: host.source || '',
115
+ summary: host.summary || '',
116
+ cwd: host.cwd || '',
117
+ name: host.name || '',
118
+ params: { ...(params || {}) },
119
+ ...flat,
120
+ };
121
+
122
+ const mode: 'xml' | 'plain' = appendMode === 'plain' ? 'plain' : 'xml';
123
+ // #152:模板是插件类的内置正文(不再从 settings 解析)。
124
+ // 宿主取数以 Supply 注入(惰性:不消费就不算)。
125
+ const plugins = [
126
+ ...buildPlugins('get', {
127
+ groupCtx: () => groupCtx,
128
+ attach: () => attach,
129
+ queueInfo: () => queueInfo,
130
+ enabled: () => !!getLoopEnabled,
131
+ waitMinutes: () => Number(getLoopWaitMinutes) || 0,
132
+ }),
133
+ ...buildPlugins('check'),
134
+ ...buildPlugins('done'),
135
+ ];
136
+ const full = await compose({
137
+ plugins,
138
+ groups: ['get', 'check', 'done'],
139
+ seed: seedCtx,
140
+ mode,
141
+ trace,
142
+ segments: DELIVERY_SEGMENTS,
143
+ });
144
+ // coversBody = 本次交付链的任一模板含 {{task.text}}(instruction 自包含任务正文)。
145
+ // 由服务端判定,避免 CLI 端做子串猜测。
146
+ return {
147
+ instruction: full,
148
+ coversBody: plugins.some((p) => /\{\{\s*task\.text\s*\}\}/.test(p.get())),
149
+ renderWarnings: [...renderWarnings, ...(host.hostWarnings || [])],
150
+ };
151
+ }
@@ -32,7 +32,7 @@ export interface DeliveryPluginDeps {
32
32
  groupCtx: Supply<unknown>;
33
33
  attach: Supply<unknown>;
34
34
  queueInfo: Supply<{ topic: string; count: number; list: { id: number; title: string }[] } | null>;
35
- loopText: Supply<string>;
35
+ enabled: Supply<boolean>;
36
36
  waitMinutes: Supply<number>;
37
37
  }
38
38
 
@@ -41,7 +41,7 @@ export const EMPTY_DEPS: DeliveryPluginDeps = {
41
41
  groupCtx: null,
42
42
  attach: null,
43
43
  queueInfo: null,
44
- loopText: '',
44
+ enabled: false,
45
45
  waitMinutes: 0,
46
46
  };
47
47
 
@@ -66,7 +66,7 @@ export function buildPlugins(
66
66
  new ExtPlugin(text('ext'), { queueInfo: d.queueInfo }),
67
67
  new AckPlugin(text('ack')),
68
68
  new TimegoalPlugin(text('timegoal')),
69
- new GetloopPlugin(text('getloop'), { loopText: d.loopText, waitMinutes: d.waitMinutes }),
69
+ new GetloopPlugin(text('getloop'), { enabled: d.enabled, waitMinutes: d.waitMinutes }),
70
70
  ];
71
71
  case 'check':
72
72
  // #161 三段化:check 链只有这一个段(进度 + 每轮检查提醒)
@@ -3,7 +3,7 @@
3
3
  // 插件工厂 / 注册表 / 字段目录在 factory.ts + registry.ts(actions 经 manifest 引
4
4
  // 工厂,不能回环引本文件)。依赖方向(设计内):tasktool 是唯一消费方——宿主完成
5
5
  // 领域取数,以 Supply 形式注入插件;插件在自己的 buildData() 里变换。
6
- // promptplug 不 import 其他模块。
6
+ // promptplug 不 import 其他模块(delivery.ts 的交付组装同样只收宿主取好的数据)。
7
7
  import { ModuleBase } from '../../runtime/types/module.js';
8
8
  import { zodActionsOf, type ZodBoundAction } from '../../runtime/action-decorator.js';
9
9
  import { container, type Container } from '../../runtime/container.js';
@@ -34,6 +34,8 @@ export {
34
34
  export { PLUGIN_GROUPS } from './base.js';
35
35
  export type { PluginGroup, TemplateText } from './base.js';
36
36
  export { compose } from './compose.js';
37
+ export { assembleDelivery, flatParamsOf, DELIVERY_SEGMENTS } from './delivery.js';
38
+ export type { AssembledDelivery, DeliveryHostData } from './delivery.js';
37
39
 
38
40
  /**
39
41
  * 提示词插件模块:注册表外露(prompt.registry)。
@@ -1,13 +1,14 @@
1
1
  // getloop 插件(order 80):持续 get。
2
- // deps.loopText 是宿主先把「项目级收尾指令模板」渲染好的文本(wait.ts 保留这一步
3
- // 与其 renderWarnings 告警口径);waitMinutes=0 时模板闸门 {{#if (gt …)}} 收口。
2
+ // deps.enabled 是宿主从 waitgoal 配置(repos.json repo.getLoop)读出的开关;
3
+ // 关 → 整段不出。#230 清理:原「宿主预渲染 loopText → data.getloop.text」链路
4
+ // 已删——#182 起项目级 template 口子下线,文案唯一真相就是本类的内置模板
5
+ // (预渲染上下文缺 getloop 键,产出的 text 是残缺副本,BUILTIN 也从不消费它)。
4
6
  import { z } from 'zod';
5
7
  import { PromptPlugin, supplied, type Supply, type TemplateText } from '../base.js';
6
8
 
7
9
  const schema = z.strictObject({
8
10
  getloop: z
9
11
  .looseObject({
10
- text: z.string().describe('「继续 get」的整段指令(宿主已渲染好的文本)'),
11
12
  waitMinutes: z.number().describe('没活时每次阻塞的分钟数(0 = 不阻塞)'),
12
13
  })
13
14
  .nullable()
@@ -20,7 +21,7 @@ const schema = z.strictObject({
20
21
  .describe('当前任务(seed,宿主传入)'),
21
22
  });
22
23
 
23
- /** 内置模板(#152:正文进代码)。 */
24
+ /** 内置模板(#152:正文进代码;#230 起它就是「继续 get」文案的唯一真相)。 */
24
25
  const BUILTIN: TemplateText = {
25
26
  id: 'builtin',
26
27
  name: '系统内置',
@@ -38,13 +39,13 @@ export class GetloopPlugin extends PromptPlugin<typeof schema> {
38
39
  readonly dataSchema = schema;
39
40
  readonly templates = [BUILTIN];
40
41
 
41
- constructor(template: string, private readonly deps: { loopText: Supply<string>; waitMinutes: Supply<number> }) {
42
+ constructor(template: string, private readonly deps: { enabled: Supply<boolean>; waitMinutes: Supply<number> }) {
42
43
  super(template);
43
44
  }
44
45
 
45
46
  protected async buildData() {
46
- const text = String(await supplied(this.deps.loopText) || '').trim();
47
+ const enabled = !!(await supplied(this.deps.enabled));
47
48
  const waitMinutes = Number(await supplied(this.deps.waitMinutes)) || 0;
48
- return { getloop: text ? { text, waitMinutes } : null };
49
+ return { getloop: enabled ? { waitMinutes } : null };
49
50
  }
50
51
  }
@@ -1,8 +1,9 @@
1
1
  // 任务级 timegoal 的提示词模板(任务 #87)——**领取交付**与**每轮 check** 的同源代码。
2
2
  //
3
- // 为什么单独一个文件:领取路径(taskgoal-store)与 check 路径(timegoal-task-store)
4
- // 都要渲染同一份模板;而这两个模块在 timegoal-store 里已经互相 import,把模板
5
- // 放在这里可以避免循环依赖,也保证两边变量口径永远一致。
3
+ // 为什么在 promptplug(#227 重构):模板正文归提示词模板体系(出厂正文 / 兜底文案
4
+ // 都在 promptplug/plugins/ 下);taskgoal-store(领取路径)与 timegoal-task-store
5
+ // (check 路径)作为 tasktool 宿主从这里取用——依赖方向单一(tasktool → promptplug),
6
+ // 两边变量口径永远一致,也不再依赖「模板夹在两个互相 import 的 store 之间」来防环。
6
7
  //
7
8
  // goals.prompt 落库的是**模板原文**(占位符保留),渲染发生在:
8
9
  // - 领取交付:用「领取那一刻」的 ctx(输出与改造前逐字一致);
@@ -0,0 +1,231 @@
1
+ // tasktool/delivery.ts —— 交付宿主:领域取数 → Supply → promptplug 的 assembleDelivery。
2
+ //
3
+ // #227 重构:从 wait.ts 拆出。wait.ts 只剩阻塞编排(跨进程轮询 / goal 到点收尾 /
4
+ // 面板随行),本文件专管「交付一条任务时要把哪些领域数据取齐」:
5
+ // ① 附件标注(annotateTaskDelivery → attachTemplateCtx)
6
+ // ② 任务级 timegoal 起表(领取即计时;preview 走只读版)
7
+ // ③ 组上下文(readGroupContext,按正文 frontmatter 的 board 决定组材料)
8
+ // ④ 目录级 goal 上下文(readGoalCtx)+ 时间运算字段补齐(enrichGoalTiming)
9
+ // ⑤ 队列余量(pendingQueueInfo)
10
+ // 之后把数据装进 DeliveryHostData,调 promptplug/delivery.ts 的 assembleDelivery
11
+ // 完成组装——模板正文、变量、三链合并、渲染全部在 promptplug。
12
+ // 任何异常都降级为「只回任务」——wait 绝不能因渲染挂掉(fail-open 纪律)。
13
+ //
14
+ // preview / trace(任务 #65「预览 get 提示词」):
15
+ // preview=true → **零副作用**:不启动任务级 timegoal 计时、不写库、不领取;
16
+ // timegoal 的 check 指令用声明现算(与真实领取同一份)。其余渲染路径与真实领取
17
+ // 完全同一条代码,所以预览出来的字符串就是 agent 会拿到的那一份。
18
+ // trace=[] → 按顺序记下每一段的来源(谁贡献的、开关是否开着),供面板展示
19
+ // 「这段是哪来的」。真实领取不传 trace,行为与改造前逐字节一致。
20
+ import { formatDuration, formatGoalTiming } from '../../core/instruction-template.js';
21
+ import { parseFrontmatter } from '../../shared/frontmatter.js';
22
+ import { getSettings, isGlobalKey, pendingQueueInfo } from '../localtask/service.js';
23
+ import { assembleDelivery, type AssembledDelivery } from '../promptplug/delivery.js';
24
+ import { annotateTaskDelivery, attachTemplateCtx } from './attach.js';
25
+ import { readGroupContext } from './groupctx.js';
26
+ import { ensureTaskGoal, previewTaskGoal } from './taskgoal.js';
27
+ import * as timegoal from './timegoal.js';
28
+
29
+ export interface DeliveryOptions {
30
+ source?: string;
31
+ summary?: unknown;
32
+ cwd?: unknown;
33
+ name?: unknown;
34
+ topicKey?: unknown;
35
+ params?: Record<string, string>;
36
+ preview?: boolean;
37
+ trace?: import('../promptplug/compose.js').RenderTraceEntry[];
38
+ getLoopEnabled?: boolean;
39
+ getLoopWaitMinutes?: number;
40
+ }
41
+
42
+ // 「YYYY-MM-DD HH:mm:ss」→ epoch ms(任务级 goal 的起点 = consumedAt);解析不了返回 NaN
43
+ function parseStampMs(v: unknown): number {
44
+ const m = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/.exec(String(v || ''));
45
+ if (!m) return NaN;
46
+ return new Date(Number(m?.[1]), Number(m?.[2]) - 1, Number(m?.[3]), Number(m?.[4]), Number(m?.[5]), Number(m?.[6])).getTime();
47
+ }
48
+
49
+ // goal 上下文的**时间运算字段**统一在这里补齐(任务 #82:模板层要能拿剩余/超时做运算,
50
+ // 不能只有人话的 remainingHuman)。目录级 show 自带 reached/remainingSec/overtimeSec;
51
+ // 任务级只有 deadline 戳——同式解析补算。缺哪个补哪个,已有的不覆盖。
52
+ export function enrichGoalTiming(g: any): any {
53
+ if (!g) return g;
54
+ let { remainingSec, overtimeSec, reached } = g;
55
+ remainingSec = Number(remainingSec);
56
+ overtimeSec = Number(overtimeSec);
57
+ if (!Number.isFinite(remainingSec) && !Number.isFinite(overtimeSec)) {
58
+ const ms = parseStampMs(g.deadline);
59
+ if (Number.isFinite(ms)) {
60
+ const diff = Math.round((ms - Date.now()) / 1000);
61
+ remainingSec = diff >= 0 ? diff : 0;
62
+ overtimeSec = diff >= 0 ? 0 : -diff;
63
+ }
64
+ }
65
+ if (reached === undefined) {
66
+ if (Number.isFinite(overtimeSec)) reached = overtimeSec > 0;
67
+ else if (Number.isFinite(remainingSec)) reached = remainingSec <= 0;
68
+ }
69
+ if (Number.isFinite(remainingSec)) {
70
+ g.remainingSec = remainingSec;
71
+ g.remainingMin = Math.ceil(remainingSec / 60);
72
+ }
73
+ if (Number.isFinite(overtimeSec)) g.overtimeSec = overtimeSec;
74
+ if (reached !== undefined) g.reached = reached;
75
+ // 任务 #87:模板里要能直接写「持续 {{goal.durationHuman}}」——人话时长统一在这里补。
76
+ if (Number.isFinite(Number(g.durationSec)) && Number(g.durationSec) > 0) {
77
+ g.durationHuman = g.durationHuman || formatDuration(Number(g.durationSec));
78
+ }
79
+ if (Number.isFinite(Number(g.elapsedSec))) {
80
+ g.elapsedHuman = g.elapsedHuman || formatDuration(Number(g.elapsedSec));
81
+ }
82
+ return g;
83
+ }
84
+
85
+ // wait/get **返回时刻**的目标上下文(渲染 instruction 用)。fail-open:加载失败 /
86
+ // 读不到 / 没目标 / 出错 → null,instruction 照常渲染(goal 段被整段丢弃)。
87
+ // 绝不写盘:showTimegoal 走 loadRecycledStore({persist:false})——timegoals.json
88
+ // 字节数不变,goal-expiry 单测字节比对钉着。
89
+ async function readGoalCtx(cwd: unknown): Promise<Record<string, any> | null> {
90
+ if (!cwd || isGlobalKey(cwd)) return null; // cwd 是路径,isGlobalKey 恒 false——纯防御
91
+ try {
92
+ const show = await timegoal.showTimegoal({ cwd });
93
+ if (!show || !show.hasGoal) return null;
94
+ const g = show.goal || {};
95
+ return {
96
+ name: g.name || show.name || '',
97
+ deadline: g.deadline || '',
98
+ prompt: g.prompt || '',
99
+ reached: !!show.reached,
100
+ remainingSec: show.remainingSec,
101
+ overtimeSec: show.overtimeSec,
102
+ remainingHuman: formatGoalTiming({
103
+ reached: show.reached,
104
+ remainingSec: show.remainingSec,
105
+ overtimeSec: show.overtimeSec,
106
+ }),
107
+ };
108
+ } catch {
109
+ return null;
110
+ }
111
+ }
112
+
113
+ // 组装 wait/get 返回的任务载荷 + 指令。**单一路径**:
114
+ // 所有段落(上下文 / 附件 / 时间目标 / ack / 持续 get)一律进返回载荷的
115
+ // instruction 字段;task.text 始终是库存原文,绝不把系统提示词拼进正文。
116
+ // 旧 rule 区块已删除:done 指令与收尾要求统一由 ack 区块承载。
117
+ export async function buildTaskDelivery(
118
+ task: any,
119
+ { source, summary, cwd, name, topicKey, params, preview = false, trace, getLoopEnabled = false, getLoopWaitMinutes = 0 }: DeliveryOptions = {},
120
+ ): Promise<Record<string, any>> {
121
+ // 附件标注(任务 #15:正文里的 ![名](fileId) 嵌入 → 附件清单 + 本地路径)。
122
+ // fail-open:标注失败绝不拖垮交付;正文没有引用时 annotateTaskDelivery 返回
123
+ // null,载荷与改造前**逐字节一致**(与 localtask 读任务的同一条纪律)。
124
+ let att: any = null;
125
+ try {
126
+ // inlineDocs(#162):文档资料绑定(role=doc)随交付带全文——只读盘(自有树 /
127
+ // 绑定闭包),预览同样安全;读不到内容留空,不阻断交付。
128
+ const a = await annotateTaskDelivery(task, { topicKey, inlineDocs: true });
129
+ if (a) {
130
+ task = a.task;
131
+ att = a;
132
+ }
133
+ } catch {
134
+ /* 标注失败照常交付(agent 还能从正文里的嵌入自行处理) */
135
+ }
136
+ try {
137
+ // 任务级 timegoal(发布带 --duration):**领取即计时**——这里起表(幂等),
138
+ // goal 上下文换成任务级(prompt = check 指令,固化进 timegoal 存储,之后每轮原文回显)。
139
+ // 目录级 goal 仍作兜底:任务没带时间目标时,渲染等待方目录的目标状态。
140
+ let taskGoalCtx: any = null;
141
+ if (task && task.timegoal && topicKey) {
142
+ const title = (String(task.text || '')
143
+ .split('\n')
144
+ .map((l) => l.trim())
145
+ .find(Boolean) || `任务 #${task.id}`).slice(0, 40);
146
+ // 预览走只读版本:同一份 check 指令文本,但不落盘、不起表
147
+ taskGoalCtx = preview
148
+ ? await previewTaskGoal({ topicKey, taskId: task.id, cwd, name: title, timegoal: task.timegoal, text: task.text })
149
+ : await ensureTaskGoal({
150
+ topicKey,
151
+ taskId: task.id,
152
+ cwd,
153
+ name: title,
154
+ text: task.text,
155
+ timegoal: task.timegoal,
156
+ startedAtMs: parseStampMs(task.consumedAt) || undefined,
157
+ });
158
+ }
159
+ const goal = enrichGoalTiming(taskGoalCtx || (await readGoalCtx(cwd)));
160
+
161
+ // 项目组上下文(组概念 + 本项目位置 + 兄弟成员 + 参考文件地址):只进 instruction。
162
+ // #64 作用域:组材料只挂**组任务**(正文 frontmatter 带 board);单 repo 主题里
163
+ // 提交的纯项目任务只带项目介绍,不把所属组的材料挂进来。
164
+ const boardMark = String(parseFrontmatter(String((task && task.text) || '')).board || '').trim();
165
+ const groupCtx = await readGroupContext(cwd as string, { board: boardMark });
166
+ const settings: any = (await getSettings().catch(() => null)) || {};
167
+
168
+ // ── 插件化组装(promptplug):宿主完成领域取数,插件 data() 做同步变换 ──
169
+ // 任务级 goal → 完整 check 指令;目录级 goal → 状态行(二者都进 timecheck 段)。
170
+ const goalCheck = taskGoalCtx ? taskGoalCtx.prompt : null;
171
+ const goalStatus = !taskGoalCtx && goal
172
+ ? `〔时间目标「${goal.name || ''}」${goal.remainingHuman || ''}〕`
173
+ : null;
174
+ const goalCtx = goal
175
+ ? {
176
+ ...goal,
177
+ // 任务 #87:goal.extra(附加要求,领取后可动态改)与 goalKey 供模板直接引用
178
+ extra: taskGoalCtx ? taskGoalCtx.extra || '' : '',
179
+ goalKey: taskGoalCtx ? taskGoalCtx.goalKey || '' : '',
180
+ check: goalCheck || '',
181
+ statusLine: goalStatus || '',
182
+ }
183
+ : null;
184
+ const attach = att ? attachTemplateCtx(att.task.attachments).attach : null;
185
+
186
+ // ext(队列余量):同主题还有多少待领取任务 + 标题。现算(同主题一次读取);
187
+ // 读取失败不阻断领取:按缺失处理,并把原因记进 renderWarnings。
188
+ let queueInfo: { topic: string; count: number; list: { id: number; title: string }[] } | null = null;
189
+ const hostWarnings: import('../promptplug/compose.js').RenderWarning[] = [];
190
+ try {
191
+ const q = await pendingQueueInfo(topicKey as string, task && task.id);
192
+ if (q && q.count > 0) queueInfo = { topic: q.topic, count: q.count, list: q.list };
193
+ } catch (e) {
194
+ hostWarnings.push({
195
+ block: 'ext',
196
+ label: '待领取队列(ext)',
197
+ message: String((e as Error).message || e).replace(/\s+/g, ' ').trim(),
198
+ });
199
+ }
200
+
201
+ const delivery: AssembledDelivery = await assembleDelivery({
202
+ task,
203
+ attachCtx: attach,
204
+ goalCtx,
205
+ groupCtx,
206
+ queueInfo,
207
+ getLoopEnabled,
208
+ getLoopWaitMinutes,
209
+ params,
210
+ appendMode: settings.appendMode,
211
+ source: source || '',
212
+ summary,
213
+ cwd,
214
+ name,
215
+ hostWarnings,
216
+ trace,
217
+ });
218
+ const warnField = delivery.renderWarnings.length ? { renderWarnings: delivery.renderWarnings } : {};
219
+ if (!delivery.instruction) {
220
+ return { task, ...warnField };
221
+ }
222
+ return {
223
+ task,
224
+ instruction: delivery.instruction,
225
+ coversBody: delivery.coversBody,
226
+ ...warnField,
227
+ };
228
+ } catch {
229
+ return { task };
230
+ }
231
+ }