nx-kv 0.64.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 (151) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/assets/nx-kv/SKILL.md +5 -2
  3. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -0
  4. package/assets/nx-kv/references/A04-/344/273/223/345/272/223/344/270/216/351/241/271/347/233/256/347/273/204.md +79 -6
  5. package/assets/nx-kv/templates/ref-main-doc.md +46 -0
  6. package/package.json +1 -1
  7. package/src/core/db/seed-templates.ts +2 -86
  8. package/src/modules/localtask/task-lifecycle.ts +1 -1
  9. package/src/modules/promptplug/actions/_manifest.generated.ts +9 -0
  10. package/src/modules/promptplug/actions/prompt-registry.ts +4 -1
  11. package/src/modules/promptplug/actions/prompt-template-activate.ts +31 -0
  12. package/src/modules/promptplug/actions/prompt-template-delete.ts +30 -0
  13. package/src/modules/promptplug/actions/prompt-template-save.ts +52 -0
  14. package/src/modules/promptplug/delivery.ts +151 -0
  15. package/src/modules/promptplug/factory.ts +16 -8
  16. package/src/modules/promptplug/index.ts +3 -1
  17. package/src/modules/promptplug/plugins/doneguard.ts +3 -0
  18. package/src/modules/promptplug/plugins/getloop.ts +8 -7
  19. package/src/modules/{tasktool/plugins/goal-template.ts → promptplug/plugins/goal-prompt.ts} +57 -4
  20. package/src/modules/promptplug/plugins/goal-shape.ts +17 -0
  21. package/src/modules/promptplug/plugins/goalhint.ts +22 -9
  22. package/src/modules/promptplug/plugins/timecheck.ts +25 -14
  23. package/src/modules/promptplug/registry.ts +3 -3
  24. package/src/modules/promptplug/template-store.ts +145 -0
  25. package/src/modules/tasktool/delivery.ts +231 -0
  26. package/src/modules/tasktool/get.ts +2 -2
  27. package/src/modules/tasktool/plugins/taskgoal-store.ts +28 -22
  28. package/src/modules/tasktool/plugins/timegoal-task-store.ts +70 -5
  29. package/src/modules/tasktool/plugins/waitgoal-config.ts +1 -25
  30. package/src/modules/tasktool/plugins/waitgoal.ts +0 -4
  31. package/src/modules/tasktool/preview.ts +3 -4
  32. package/src/modules/tasktool/wait.ts +16 -284
  33. package/src/modules/templates/actions/templates-default.ts +2 -5
  34. package/src/modules/templates/actions/templates-update.ts +1 -3
  35. package/src/modules/templates/service.ts +11 -13
  36. package/src/modules/templates/support.ts +0 -15
  37. package/src/web/frontend/App.tsx +0 -12
  38. package/src/web/frontend/api/cli-tree.json +58 -0
  39. package/src/web/frontend/api/client.generated.ts +32 -2
  40. package/src/web/frontend/components/doc/doc-head.tsx +13 -4
  41. package/src/web/frontend/components/icons.tsx +9 -199
  42. package/src/web/frontend/components/md/live-block.tsx +1 -5
  43. package/src/web/frontend/components/md/md-panes-root.tsx +0 -4
  44. package/src/web/frontend/components/md/md-panes.tsx +1 -11
  45. package/src/web/frontend/components/md/tool-bar.tsx +9 -0
  46. package/src/web/frontend/components/sidebar/index.tsx +13 -2
  47. package/src/web/frontend/components/sidebar/model.ts +3 -0
  48. package/src/web/frontend/components/tool-acts/bar.tsx +40 -29
  49. package/src/web/frontend/components/tool-acts/layout-panel.tsx +7 -3
  50. package/src/web/frontend/components/tool-acts/modules.ts +53 -51
  51. package/src/web/frontend/components/tool-acts/style.css +7 -3
  52. package/src/web/frontend/modules/md/styles/docs.css +0 -7
  53. package/src/web/frontend/modules/md/styles/editor.css +0 -17
  54. package/src/web/frontend/modules/md/styles/shell.css +3 -0
  55. package/src/web/frontend/modules/md/use-templates.ts +3 -13
  56. package/src/web/frontend/page/dir/index.tsx +3 -15
  57. package/src/web/frontend/page/dir/task-actions.ts +1 -16
  58. package/src/web/frontend/page/dir/task.tsx +2 -16
  59. package/src/web/frontend/page/group/index.tsx +6 -19
  60. package/src/web/frontend/page/repos/branch-persist.ts +32 -0
  61. package/src/web/frontend/page/repos/icons.tsx +47 -229
  62. package/src/web/frontend/page/repos/index.tsx +12 -8
  63. package/src/web/frontend/page/repos/repo-table.tsx +24 -3
  64. package/src/web/frontend/page/settings/api.ts +20 -0
  65. package/src/web/frontend/page/settings/index.tsx +1 -1
  66. package/src/web/frontend/page/settings/prompt-template-editor.tsx +180 -0
  67. package/src/web/frontend/page/settings/prompt-templates-section.tsx +39 -34
  68. package/src/web/frontend/page/settings/style.css +30 -0
  69. package/src/web/frontend/page/templates/index.tsx +5 -54
  70. package/src/web/frontend/page/templates/manage.tsx +1 -5
  71. package/src/web/frontend/page/templates/style.css +1 -43
  72. package/src/web/frontend/page/templates/template-list.tsx +7 -15
  73. package/src/web/frontend/routes/route-eq.ts +2 -3
  74. package/src/web/frontend/routes/static.ts +2 -2
  75. package/src/web/frontend/routes/templates.ts +0 -10
  76. package/src/web/frontend/styles/repos.css +22 -0
  77. package/src/web/frontend/styles-v2/shell.css +7 -0
  78. package/src/web/frontend/svghub/catalog-act.ts +168 -0
  79. package/src/web/frontend/svghub/catalog-doc.ts +102 -0
  80. package/src/web/frontend/svghub/catalog-nav.ts +192 -0
  81. package/src/web/frontend/svghub/catalog-repo.ts +102 -0
  82. package/src/web/frontend/svghub/catalog-state.ts +70 -0
  83. package/src/web/frontend/svghub/icon.tsx +95 -0
  84. package/src/web/frontend/svghub/index.ts +66 -0
  85. package/src/web/frontend/svghub/serialize.ts +39 -0
  86. package/src/web/frontend/svghub/types.ts +67 -0
  87. package/src/web/frontend/types.ts +2 -1
  88. package/src/web/public/assets/app-context-BqCBcDsx.js +1 -0
  89. package/src/web/public/assets/bar-Dc5Tq1eE.js +1 -0
  90. package/src/web/public/assets/{button-BEWXOABr.js → button-3JlUeln_.js} +1 -1
  91. package/src/web/public/assets/{composer-launch-DRi9mZE1.js → composer-launch-fp2IzGzQ.js} +1 -1
  92. package/src/web/public/assets/{composer-panel-swmDqlPw.js → composer-panel-Dh681iO6.js} +1 -1
  93. package/src/web/public/assets/dag-DnaU0I_z.js +1 -0
  94. package/src/web/public/assets/dir-d16q1GLe.js +3 -0
  95. package/src/web/public/assets/doc-DRSKD0Re.js +6 -0
  96. package/src/web/public/assets/group-Dc3ZgW24.js +1 -0
  97. package/src/web/public/assets/index-BIVxGd6t.css +1 -0
  98. package/src/web/public/assets/index-Bg0m8gbJ.js +2 -0
  99. package/src/web/public/assets/{list-filter-D-x94TvA.js → list-filter-CWxiOSg_.js} +1 -1
  100. package/src/web/public/assets/md-history-CLIs9Dr0.css +1 -0
  101. package/src/web/public/assets/md-history-DNtgaIdH.js +39 -0
  102. package/src/web/public/assets/{member-picker-Cvbv24IK.js → member-picker-BZgE3HGb.js} +1 -1
  103. package/src/web/public/assets/model-CtG2jIDv.js +2 -0
  104. package/src/web/public/assets/{overview-CctJfO3D.js → overview-C68QpcT9.js} +1 -1
  105. package/src/web/public/assets/popup-DZ2Khv2c.js +1 -0
  106. package/src/web/public/assets/progress-CEmAFxo9.js +3 -0
  107. package/src/web/public/assets/refs-TzxZYy7T.js +2 -0
  108. package/src/web/public/assets/repo-form-modal-Dg3hJWUV.js +1 -0
  109. package/src/web/public/assets/repos-uNqSR5YB.js +12 -0
  110. package/src/web/public/assets/{route-crumb-BcDPd7Ht.js → route-crumb-C4DgkJ8G.js} +1 -1
  111. package/src/web/public/assets/{settings-Cc6puKd5.css → settings-BWHjNegB.css} +1 -1
  112. package/src/web/public/assets/settings-BzIllshQ.js +1 -0
  113. package/src/web/public/assets/{status-tag-BD_0iWMB.js → status-tag-8cLH8hl9.js} +1 -1
  114. package/src/web/public/assets/task-DuFOXLPC.js +11 -0
  115. package/src/web/public/assets/{task-row-CQgzQmzu.js → task-row-CRjuAfKW.js} +1 -1
  116. package/src/web/public/assets/{task-utils-bJH1-Cjy.js → task-utils-DAPxKm4c.js} +1 -1
  117. package/src/web/public/assets/templates-CwYDIBYn.css +1 -0
  118. package/src/web/public/assets/templates-DNiGvmdq.js +10 -0
  119. package/src/web/public/assets/{use-rail-drag-ufwy2XZB.js → use-rail-drag-DxIYcszo.js} +1 -1
  120. package/src/web/public/assets/{workspace-D3jbcTwf.js → workspace-DojQ3RP4.js} +2 -2
  121. package/src/web/public/index.html +15 -16
  122. package/src/web/frontend/modules/md/fill-session.ts +0 -36
  123. package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
  124. package/src/web/frontend/modules/md/task-intent.ts +0 -29
  125. package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
  126. package/src/web/frontend/modules/prompts/template-preview.ts +0 -62
  127. package/src/web/frontend/page/templates/fill.tsx +0 -124
  128. package/src/web/public/assets/app-context-DDQnrPSP.js +0 -1
  129. package/src/web/public/assets/bar-j14ON7uZ.js +0 -1
  130. package/src/web/public/assets/dag-BzdFYMml.js +0 -1
  131. package/src/web/public/assets/dir-DhsB1ZhL.js +0 -3
  132. package/src/web/public/assets/doc-D4po3sDc.js +0 -6
  133. package/src/web/public/assets/fill-session-fHxQHFaD.js +0 -1
  134. package/src/web/public/assets/group-BxmSNzIB.js +0 -1
  135. package/src/web/public/assets/index-CMjG5NVU.js +0 -2
  136. package/src/web/public/assets/index-uMjSWNVr.css +0 -1
  137. package/src/web/public/assets/md-history-1h2zairf.css +0 -1
  138. package/src/web/public/assets/md-history-CZUF_FhN.js +0 -39
  139. package/src/web/public/assets/model-Cc2EoUQp.js +0 -2
  140. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +0 -1
  141. package/src/web/public/assets/popup-D8KWI6-Q.js +0 -1
  142. package/src/web/public/assets/progress-CawQRCQf.js +0 -3
  143. package/src/web/public/assets/refs-TuuoaRs7.js +0 -2
  144. package/src/web/public/assets/render-template-body-bXdedFig.js +0 -1
  145. package/src/web/public/assets/repo-form-modal-BD4N37MI.js +0 -1
  146. package/src/web/public/assets/repos-BPeuX4N9.js +0 -12
  147. package/src/web/public/assets/settings-CZJaKLZW.js +0 -1
  148. package/src/web/public/assets/task-DgbbF5gy.js +0 -11
  149. package/src/web/public/assets/task-intent-CX5DZccN.js +0 -1
  150. package/src/web/public/assets/templates-CBXlwyof.js +0 -11
  151. package/src/web/public/assets/templates-plA8R7jJ.css +0 -1
@@ -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
+ }
@@ -9,7 +9,10 @@
9
9
  // 形式交给插件;插件在自己的 buildData() 里 await supplied() 后只做变换。
10
10
  // promptplug 不 import 其他模块。
11
11
  //
12
- // #152 起模板不再注入:每个插件类的 `templates` 就是它的正文,构造只传 overrides(预览/测试用)。
12
+ // #152 起模板不再注入:每个插件类的 `templates` 就是它的出厂正文。
13
+ // #161:出厂正文之外允许**用户层模板**(template-store:每段多条 + 启用哪条)——
14
+ // 装配时把「启用中的用户正文」作为 override 传进构造;'builtin' / 未设置 → ''(用类内默认)。
15
+ // 优先级:显式 overrides(预览/测试)> 用户启用模板 > 类内出厂。
13
16
  import type { AnyPromptPlugin } from '../../shared/prompt-plugin.js';
14
17
  import type { PluginGroup, Supply } from './base.js';
15
18
  import { ContextPlugin } from './plugins/context.js';
@@ -18,17 +21,18 @@ import { ExtPlugin } from './plugins/ext.js';
18
21
  import { GetloopPlugin } from './plugins/getloop.js';
19
22
  import { AckPlugin } from './plugins/ack.js';
20
23
  import { DoneguardPlugin } from './plugins/doneguard.js';
21
- import { GoalhintPlugin } from './plugins/goalhint.js';
22
- import { TimecheckPlugin } from './plugins/timecheck.js';
24
+ import { TimecheckPlugin } from './plugins/goalhint.js';
25
+ import { TimegoalPlugin } from './plugins/timecheck.js';
23
26
  import { varScopeOf as varScopeOfFields } from '../../shared/prompt-plugin.js';
24
27
  import { allPluginIds, groupPluginIds, pluginMeta } from './registry.js';
28
+ import { activeTemplateTextOf } from './template-store.js';
25
29
 
26
30
  /** 交付插件构造所需的宿主取数(值或惰性函数;异步留给 HTTP 类取数)。 */
27
31
  export interface DeliveryPluginDeps {
28
32
  groupCtx: Supply<unknown>;
29
33
  attach: Supply<unknown>;
30
34
  queueInfo: Supply<{ topic: string; count: number; list: { id: number; title: string }[] } | null>;
31
- loopText: Supply<string>;
35
+ enabled: Supply<boolean>;
32
36
  waitMinutes: Supply<number>;
33
37
  }
34
38
 
@@ -37,7 +41,7 @@ export const EMPTY_DEPS: DeliveryPluginDeps = {
37
41
  groupCtx: null,
38
42
  attach: null,
39
43
  queueInfo: null,
40
- loopText: '',
44
+ enabled: false,
41
45
  waitMinutes: 0,
42
46
  };
43
47
 
@@ -51,7 +55,9 @@ export function buildPlugins(
51
55
  overrides: TemplateOverrides = {},
52
56
  ): AnyPromptPlugin[] {
53
57
  const d = { ...EMPTY_DEPS, ...deps };
54
- const text = (id: string): string => String(overrides[id] ?? '');
58
+ // 显式 overrides(预览/测试)> 用户启用模板(template-store)> 类内出厂('')
59
+ const text = (id: string): string =>
60
+ overrides[id] != null ? String(overrides[id]) : activeTemplateTextOf(id);
55
61
  switch (group) {
56
62
  case 'get':
57
63
  return [
@@ -59,10 +65,12 @@ export function buildPlugins(
59
65
  new AttachmentPlugin(text('attachment'), { attach: d.attach }),
60
66
  new ExtPlugin(text('ext'), { queueInfo: d.queueInfo }),
61
67
  new AckPlugin(text('ack')),
62
- new GetloopPlugin(text('getloop'), { loopText: d.loopText, waitMinutes: d.waitMinutes }),
68
+ new TimegoalPlugin(text('timegoal')),
69
+ new GetloopPlugin(text('getloop'), { enabled: d.enabled, waitMinutes: d.waitMinutes }),
63
70
  ];
64
71
  case 'check':
65
- return [new TimecheckPlugin(text('timecheck')), new GoalhintPlugin(text('goalhint'))];
72
+ // #161 三段化:check 链只有这一个段(进度 + 每轮检查提醒)
73
+ return [new TimecheckPlugin(text('timecheck'))];
66
74
  case 'done':
67
75
  return [new DoneguardPlugin(text('doneguard'))];
68
76
  default:
@@ -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)。
@@ -14,6 +14,9 @@ const BUILTIN: TemplateText = {
14
14
  text: `{{#if goal.blocked}}
15
15
  〔完成门禁 · 时间未到〕任务 #{{task.id}} 还不能 done:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),剩余 {{goal.remainingHuman}}。
16
16
  - 现在可做:{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}收尾整理(收敛改动 / 补验证 / 写清遗留),或派 sub agent 提出新的需求继续推进{{else}}继续推进主线,并派 sub agent 重新提出新的需求{{/if}}。
17
+ {{#if (and goal.checks (lte goal.sinceLastCheckSec 600))}}
18
+ ⚠️ 严重警告:距上次检查不到 10 分钟就想 done——这轮几乎没有新进展。禁止 sleep / 空转等待:派一个 sub agent 找一个**全新的切入角度**(换模块 / 换验证方式 / 补测试 / 收尾整理),拿新产出再来。
19
+ {{/if}}
17
20
  - 每轮推进先跑:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>"
18
21
  - 到点后再:nx-kv localtask done --id {{task.id}} --summary "<完成总结>"
19
22
  {{/if}}`,
@@ -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(输出与改造前逐字一致);
@@ -55,10 +56,22 @@ export interface TaskGoalTemplateCtxInput {
55
56
  deadline: unknown;
56
57
  nowMs?: unknown;
57
58
  check?: unknown;
59
+ /** 本轮**之前**的检查流水(旧→新,不含本次;check 路径查 goal_checks 传入) */
60
+ history?: GoalCheckRecord[];
61
+ }
62
+
63
+ /** 单条检查流水的仓库层形状(goal_checks 行的最小集)。 */
64
+ export interface GoalCheckRecord {
65
+ atMs: number;
66
+ elapsedSec: number;
67
+ remainingSec: number;
68
+ overtimeSec: number;
69
+ reached: boolean;
70
+ summary: string;
58
71
  }
59
72
 
60
73
  /** goal 模板渲染的 ctx(领取 / check 共用同一构造,保证两处变量口径一致)。 */
61
- export function taskGoalTemplateCtx({ taskId, taskText, goalKey, durationSec, extra, startedAt, deadline, nowMs, check }: TaskGoalTemplateCtxInput): Record<string, any> {
74
+ export function taskGoalTemplateCtx({ taskId, taskText, goalKey, durationSec, extra, startedAt, deadline, nowMs, check, history }: TaskGoalTemplateCtxInput): Record<string, any> {
62
75
  const dur = Number(durationSec) || 0;
63
76
  const startMs = typeof startedAt === 'number' ? startedAt : stampMsOf(startedAt);
64
77
  const endMs = typeof deadline === 'number' ? deadline : stampMsOf(deadline);
@@ -67,9 +80,27 @@ export function taskGoalTemplateCtx({ taskId, taskText, goalKey, durationSec, ex
67
80
  const overtimeSec = Number.isFinite(endMs) ? Math.max(0, Math.round((now - endMs) / 1000)) : 0;
68
81
  const elapsedSec = Number.isFinite(startMs) ? Math.max(0, Math.round((now - startMs) / 1000)) : 0;
69
82
  const reached = Number.isFinite(endMs) ? now >= endMs : false;
83
+ // #161:check 历史(本轮**之前**的流水,旧→新)+ 距上次检查秒数——
84
+ // 模板据此做「重复检查太频繁 → 严重警告(防 AI 死胡同空转 sleep)」的分支。
85
+ const hist = Array.isArray(history) ? history : [];
86
+ const lastMs = hist.length ? Number(hist[hist.length - 1]?.atMs) : NaN;
87
+ const sinceLastCheckSec = hist.length && Number.isFinite(lastMs) && Number.isFinite(now)
88
+ ? Math.max(0, Math.round((now - lastMs) / 1000))
89
+ : undefined;
70
90
  return {
71
91
  task: { id: taskId, text: String(taskText || '') },
72
92
  goal: {
93
+ checks: hist.length
94
+ ? hist.map((c) => ({
95
+ at: stampOfMs(Number(c.atMs)),
96
+ elapsedSec: Number(c.elapsedSec) || 0,
97
+ remainingSec: Number(c.remainingSec) || 0,
98
+ overtimeSec: Number(c.overtimeSec) || 0,
99
+ reached: !!c.reached,
100
+ summary: String(c.summary || ''),
101
+ }))
102
+ : undefined,
103
+ ...(sinceLastCheckSec !== undefined ? { sinceLastCheckSec } : {}),
73
104
  goalKey: String(goalKey || ''),
74
105
  durationHuman: formatDuration(dur),
75
106
  durationSec: dur,
@@ -96,3 +127,25 @@ export function renderTaskGoalPrompt(ctx: unknown, template: unknown = TASK_GOAL
96
127
  return src as string;
97
128
  }
98
129
  }
130
+
131
+ // ── #161:出厂正文已搬进 timecheck 段模板(promptplug),goals.prompt 只存「用户自定义」──
132
+ //
133
+ // 旧 goal 行落库里存的出厂原文(TASK_GOAL_PROMPT_TEMPLATE)不再视为自定义——
134
+ // 否则段模板编辑会被 goal.check 双层遮住、对旧行永远失效。出厂原文 → 走段模板。
135
+
136
+ /** 落库的 goals.prompt 里「用户自定义」的部分:空 / 出厂原文 → ''(正文走 timecheck 段模板)。 */
137
+ export function customGoalPromptOf(v: unknown): string {
138
+ const s = String(v ?? '').trim();
139
+ return s && s !== TASK_GOAL_PROMPT_TEMPLATE.trim() ? String(v) : '';
140
+ }
141
+
142
+ /** 只渲染用户自定义 prompt(没有 → '';渲染失败退回原文——自定义是发布方的硬要求,宁可原文也不吞)。 */
143
+ export function renderCustomGoalPrompt(ctx: unknown, template: unknown): string {
144
+ const src = customGoalPromptOf(template);
145
+ if (!src) return '';
146
+ try {
147
+ return renderInstruction(src, ctx);
148
+ } catch {
149
+ return src;
150
+ }
151
+ }
@@ -22,6 +22,23 @@ export const goalShape = z
22
22
  extra: z.string().optional().describe('领取后追加的要求(可动态改)'),
23
23
  check: z.string().optional().describe('本轮检查指令整段文本(有任务级目标时才有)'),
24
24
  statusLine: z.string().optional().describe('目录级目标的状态行(「剩余 12 分钟」)'),
25
+ checks: z
26
+ .array(
27
+ z.looseObject({
28
+ at: z.string().describe('检查时刻(YYYY-MM-DD HH:mm:ss)'),
29
+ elapsedSec: z.number().describe('那一刻已过秒数'),
30
+ remainingSec: z.number().describe('那一刻剩余秒数'),
31
+ overtimeSec: z.number().describe('那一刻超时秒数'),
32
+ reached: z.boolean().describe('那一刻是否已到点'),
33
+ summary: z.string().describe('那一轮汇报的现状'),
34
+ }),
35
+ )
36
+ .optional()
37
+ .describe('本轮之前的检查流水(旧→新,最后一条 = 最近一次;用 {{#each goal.checks}} 遍历)'),
38
+ sinceLastCheckSec: z
39
+ .number()
40
+ .optional()
41
+ .describe('距上次检查的秒数(首次检查时没有此值;小于 600 = 10 分钟内重复检查,该严重警告)'),
25
42
  })
26
43
  .optional()
27
44
  .nullable()
@@ -1,6 +1,8 @@
1
- // goalhint 段(order 40 / check 链):时间目标的可算上下文(进度百分比 / 该收口还是继续)。
1
+ // timecheck 段(order 30 / check 链,**该链唯一段**):时间目标进度 + 每轮检查提醒。
2
2
  //
3
- // 一个段一个文件:正文就是这个类里的 BUILTIN。
3
+ // #161 用户口径三段化(get 一段介绍 / check 一段进度 / done 一段拦截)——原
4
+ // timecheck(壳 {{goal.check}})与 goalhint(进度行)合并成这一段。判据
5
+ // goal.goalKey(任务级 goal);目录级目标只有 statusLine 一行。
4
6
  import { z } from 'zod';
5
7
  import { PromptPlugin, type TemplateText } from '../base.js';
6
8
  import { goalShape, taskShape } from './goal-shape.js';
@@ -10,21 +12,32 @@ const schema = z.strictObject({ goal: goalShape, task: taskShape });
10
12
  const BUILTIN: TemplateText = {
11
13
  id: 'builtin',
12
14
  name: '系统内置',
13
- text: `{{#if goal.check}}
14
- 〔特殊功能提示 · 时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),{{#if goal.reached}}已到点(超时 {{formatDuration goal.overtimeSec}}){{else}}剩余 {{goal.remainingHuman}}{{/if}}。
15
+ text: `{{#if goal.goalKey}}
16
+ 〔时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),{{#if goal.reached}}已到点(超时 {{formatDuration goal.overtimeSec}}){{else}}剩余 {{goal.remainingHuman}}{{/if}}。
15
17
  {{#if goal.reached}}——时间已到:可以收口,把改动收敛成可交付状态,补验证与说明后按 ack 段 done。
16
18
  {{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}——已过 2/3:进入收尾整理(收敛改动 / 补验证 / 写清遗留),别开新战线。
17
19
  {{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 50)}}——已过半:先确认主线走到哪,剩余时间只做收尾必需项。
18
20
  {{else}}——时间尚足:先做主线,再补细节。{{/if}}{{/if}}{{/if}}
21
+ {{#if (and goal.checks (lte goal.sinceLastCheckSec 600))}}
22
+ ⚠️ 严重警告:距上次检查不到 10 分钟({{formatDuration goal.sinceLastCheckSec}})——你极可能已经走进死胡同在原地打转,甚至开始调用 sleep 空转。立即停止当前路径:派一个 sub agent 去找一个**全新的切入角度**(换模块 / 换验证方式 / 补测试 / 整理交付),用新产出来填这一轮;而不是重复汇报同样的现状。
23
+ {{/if}}
24
+ - 每轮检查照旧执行:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>"
25
+ {{#if goal.extra}}
26
+ 附加要求(发布方):
27
+ {{goal.extra}}
28
+ {{/if}}
29
+ {{/if}}
30
+ {{#if goal.statusLine}}
31
+ {{goal.statusLine}}
19
32
  {{/if}}`,
20
33
  };
21
34
 
22
- export class GoalhintPlugin extends PromptPlugin<typeof schema> {
23
- readonly id = 'goalhint';
24
- readonly order = 40;
35
+ export class TimecheckPlugin extends PromptPlugin<typeof schema> {
36
+ readonly id = 'timecheck';
37
+ readonly order = 30;
25
38
  readonly group = 'check' as const;
26
- readonly tag = 'nx-kv.goalhint';
27
- readonly label = '特殊功能提示(timegoal)';
39
+ readonly tag = 'nx-kv.timecheck';
40
+ readonly label = '时间目标检查';
28
41
  readonly dataSchema = schema;
29
42
  readonly templates = [BUILTIN];
30
43
 
@@ -1,30 +1,41 @@
1
- // timecheck 段(order 30 / check 链):时间目标检查指令 / 状态行。
1
+ // timegoal 段(order 65 / get 链):时间目标**启动介绍**(#161 用户口径三段化——
2
+ // get 一段介绍、check 一段进度、done 一段拦截)。
2
3
  //
3
- // 一个段一个文件:正文就是这个类里的 BUILTIN。
4
- // 有任务级时间目标时给完整 check 指令;只有目录级目标时给一行状态。
4
+ // 一个段一个文件:正文就是这个类里的 BUILTIN。出厂指令完整写在正文里(所见即所得);
5
+ // goal.check 只装用户自定义 prompt(timegoal set/update --prompt),有值时整体替换。
5
6
  import { z } from 'zod';
6
7
  import { PromptPlugin, type TemplateText } from '../base.js';
7
- import { goalShape } from './goal-shape.js';
8
+ import { goalShape, taskShape } from './goal-shape.js';
8
9
 
9
- const schema = z.strictObject({ goal: goalShape });
10
+ const schema = z.strictObject({ goal: goalShape, task: taskShape });
10
11
 
12
+ // 出厂指令正文(#161):完整写在段模板里——设置页所见即所得,编辑这里的正文
13
+ // 对 get 交付与 timegoal check CLI 同时生效(CLI 的「本轮提示词」也走这条链渲染)。
14
+ // goal.check 只装「用户自定义的 per-goal 提示词」(timegoal set/update --prompt),
15
+ // 出厂模板不再落库到 goals.prompt(落库原文 ≠ 自定义),没有自定义就走下面的正文。
11
16
  const BUILTIN: TemplateText = {
12
17
  id: 'builtin',
13
18
  name: '系统内置',
14
19
  text: `{{#if goal.check}}
15
20
  {{goal.check}}
21
+ {{else}}{{#if goal.goalKey}}
22
+ 〔时间目标 · 启动〕本任务领取即计时,持续 {{goal.durationHuman}}(截止 {{goal.deadline}})。
23
+ - 每轮推进先执行:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>"
24
+ - 时间未到不得标记完成——应派出 sub agent 重新提出新的需求,再继续推进。
25
+ - check 返回 reached:true 后才允许:nx-kv localtask done --id {{task.id}} --summary "<完成总结>"
26
+ {{#if goal.extra}}
27
+ 附加要求(发布方):
28
+ {{goal.extra}}
16
29
  {{/if}}
17
- {{#if goal.statusLine}}
18
- {{goal.statusLine}}
19
- {{/if}}`,
30
+ {{/if}}{{/if}}`,
20
31
  };
21
32
 
22
- export class TimecheckPlugin extends PromptPlugin<typeof schema> {
23
- readonly id = 'timecheck';
24
- readonly order = 30;
25
- readonly group = 'check' as const;
26
- readonly tag = 'nx-kv.timecheck';
27
- readonly label = '时间目标检查';
33
+ export class TimegoalPlugin extends PromptPlugin<typeof schema> {
34
+ readonly id = 'timegoal';
35
+ readonly order = 65;
36
+ readonly group = 'get' as const;
37
+ readonly tag = 'nx-kv.timegoal';
38
+ readonly label = '时间目标启动';
28
39
  readonly dataSchema = schema;
29
40
  readonly templates = [BUILTIN];
30
41
 
@@ -19,8 +19,8 @@ import { ExtPlugin } from './plugins/ext.js';
19
19
  import { GetloopPlugin } from './plugins/getloop.js';
20
20
  import { AckPlugin } from './plugins/ack.js';
21
21
  import { DoneguardPlugin } from './plugins/doneguard.js';
22
- import { GoalhintPlugin } from './plugins/goalhint.js';
23
- import { TimecheckPlugin } from './plugins/timecheck.js';
22
+ import { TimecheckPlugin } from './plugins/goalhint.js';
23
+ import { TimegoalPlugin } from './plugins/timecheck.js';
24
24
 
25
25
  /** 插件类(构造签名不统一:有的只吃模板,有的还要宿主 deps)。 */
26
26
  type PluginCtor = new (template: string, deps?: any) => AnyPromptPlugin;
@@ -32,8 +32,8 @@ type PluginCtor = new (template: string, deps?: any) => AnyPromptPlugin;
32
32
  export const PLUGIN_CLASSES: readonly PluginCtor[] = [
33
33
  ContextPlugin,
34
34
  AttachmentPlugin,
35
+ TimegoalPlugin,
35
36
  TimecheckPlugin,
36
- GoalhintPlugin,
37
37
  DoneguardPlugin,
38
38
  ExtPlugin,
39
39
  AckPlugin,