nx-kv 0.63.0 → 0.64.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 (183) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -5
  3. package/package.json +2 -2
  4. package/src/core/attachmentdb/docs.ts +3 -6
  5. package/src/core/attachmentdb/query.ts +2 -2
  6. package/src/core/attachmentdb/relations.ts +36 -21
  7. package/src/core/db/import-json/refs.ts +17 -19
  8. package/src/core/db/import-json/repos.ts +4 -8
  9. package/src/core/db/migrations/index.ts +2 -0
  10. package/src/core/db/migrations/v13.sql +24 -0
  11. package/src/core/db/seed-templates.ts +15 -4
  12. package/src/core/db/version.ts +3 -1
  13. package/src/modules/docs/actions/_manifest.generated.ts +0 -3
  14. package/src/modules/docs/actions/doc-attach.ts +0 -1
  15. package/src/modules/docs/actions/docs-bindings.ts +2 -5
  16. package/src/modules/docs/actions/docs-link.ts +1 -2
  17. package/src/modules/docs/attach.ts +1 -36
  18. package/src/modules/docs/bound-docs.ts +2 -2
  19. package/src/modules/docs/brief.ts +0 -2
  20. package/src/modules/docs/docref.ts +7 -17
  21. package/src/modules/docs/knowledge-md.ts +1 -1
  22. package/src/modules/docs/knowledge.ts +48 -45
  23. package/src/modules/docs/ref-sync.ts +1 -5
  24. package/src/modules/docs/refs.ts +7 -10
  25. package/src/modules/docs/service.ts +1 -3
  26. package/src/modules/localtask/actions/localtask-config.ts +19 -58
  27. package/src/modules/localtask/actions/localtask-prune.ts +7 -2
  28. package/src/modules/localtask/repo/open.ts +0 -4
  29. package/src/modules/localtask/repo/settings.ts +20 -196
  30. package/src/modules/localtask/task-lifecycle.ts +7 -9
  31. package/src/modules/localtask/task-templates.ts +4 -4
  32. package/src/modules/localtask/task-view.ts +4 -0
  33. package/src/modules/localtask/topics.ts +30 -28
  34. package/src/modules/promptplug/actions/_manifest.generated.ts +0 -3
  35. package/src/modules/promptplug/actions/prompt-registry.ts +19 -30
  36. package/src/modules/promptplug/base.ts +69 -25
  37. package/src/modules/promptplug/compose.ts +40 -23
  38. package/src/modules/promptplug/factory.ts +91 -59
  39. package/src/modules/promptplug/index.ts +25 -11
  40. package/src/modules/promptplug/plugins/ack.ts +28 -0
  41. package/src/modules/promptplug/plugins/attachment.ts +237 -19
  42. package/src/modules/promptplug/plugins/context.ts +124 -30
  43. package/src/modules/promptplug/plugins/doneguard.ts +33 -0
  44. package/src/modules/promptplug/plugins/ext.ts +34 -11
  45. package/src/modules/promptplug/plugins/getloop.ts +29 -8
  46. package/src/modules/promptplug/plugins/goal-shape.ts +34 -0
  47. package/src/modules/promptplug/plugins/goalhint.ts +33 -0
  48. package/src/modules/promptplug/plugins/timecheck.ts +33 -0
  49. package/src/modules/promptplug/registry.ts +99 -0
  50. package/src/modules/promptplug/schema-bridge.ts +77 -13
  51. package/src/modules/repos/actions/board-rekey.ts +1 -1
  52. package/src/modules/repos/actions/repo-doc-add.ts +2 -3
  53. package/src/modules/repos/boards/core.ts +1 -13
  54. package/src/modules/repos/boards/docs.ts +2 -12
  55. package/src/modules/repos/boards/members.ts +2 -14
  56. package/src/modules/repos/boards/transfer.ts +2 -11
  57. package/src/modules/repos/keys.ts +4 -11
  58. package/src/modules/repos/repo/refs.ts +3 -5
  59. package/src/modules/repos/repo/repos.ts +12 -13
  60. package/src/modules/repos/repo/rows.ts +2 -8
  61. package/src/modules/repos/service/context.ts +0 -2
  62. package/src/modules/repos/service/crud.ts +1 -4
  63. package/src/modules/repos/service/store.ts +6 -7
  64. package/src/modules/repos/transfer/export.ts +3 -8
  65. package/src/modules/repos/transfer/import.ts +0 -13
  66. package/src/modules/repos/transfer/layout.ts +2 -2
  67. package/src/modules/tasktool/attach-template.ts +3 -3
  68. package/src/modules/tasktool/groupctx.ts +4 -5
  69. package/src/modules/tasktool/plugins/waitgoal-config.ts +5 -6
  70. package/src/modules/tasktool/preview.ts +20 -23
  71. package/src/modules/tasktool/wait.ts +24 -46
  72. package/src/modules/templates/actions/_manifest.generated.ts +3 -0
  73. package/src/modules/templates/actions/templates-reorder.ts +28 -0
  74. package/src/modules/templates/repo/templates.ts +32 -2
  75. package/src/modules/templates/service.ts +45 -0
  76. package/src/shared/prompt-blocks.ts +7 -173
  77. package/src/shared/prompt-plugin.ts +79 -59
  78. package/src/web/frontend/App.tsx +27 -1
  79. package/src/web/frontend/api/cli-tree.json +20 -35
  80. package/src/web/frontend/api/client.generated.ts +22 -32
  81. package/src/web/frontend/components/Introduction/rail.tsx +2 -2
  82. package/src/web/frontend/components/Introduction/use-intro.ts +2 -5
  83. package/src/web/frontend/components/bindings/bind-tags.tsx +1 -3
  84. package/src/web/frontend/components/list-search.tsx +37 -0
  85. package/src/web/frontend/components/md/attach-area.tsx +10 -15
  86. package/src/web/frontend/components/md/live-block.tsx +5 -14
  87. package/src/web/frontend/components/md/md-panes.tsx +3 -19
  88. package/src/web/frontend/modules/list-filter.ts +37 -0
  89. package/src/web/frontend/modules/md/fill-session.ts +36 -0
  90. package/src/web/frontend/modules/md/manage-session.ts +24 -0
  91. package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
  92. package/src/web/frontend/modules/md/styles/editor.css +5 -12
  93. package/src/web/frontend/modules/md/styles/shell.css +4 -0
  94. package/src/web/frontend/modules/md/task-intent.ts +29 -0
  95. package/src/web/frontend/modules/md/use-templates.ts +8 -0
  96. package/src/web/frontend/modules/prompts/template-preview.ts +12 -20
  97. package/src/web/frontend/modules/refs/api.ts +0 -1
  98. package/src/web/frontend/page/dir/index.tsx +20 -5
  99. package/src/web/frontend/page/dir/task-actions.ts +14 -0
  100. package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
  101. package/src/web/frontend/page/dir/task.tsx +19 -0
  102. package/src/web/frontend/page/doc/api.ts +2 -3
  103. package/src/web/frontend/page/doc/bindings.tsx +46 -16
  104. package/src/web/frontend/page/doc/index.tsx +3 -4
  105. package/src/web/frontend/page/group/index.tsx +65 -117
  106. package/src/web/frontend/page/refs/index.tsx +27 -3
  107. package/src/web/frontend/page/refs/style.css +3 -0
  108. package/src/web/frontend/page/repos/bind-modals.tsx +18 -2
  109. package/src/web/frontend/page/repos/board-admin.tsx +1 -1
  110. package/src/web/frontend/page/repos/index.tsx +4 -8
  111. package/src/web/frontend/page/repos/ref-block.tsx +5 -12
  112. package/src/web/frontend/page/repos/ref-panel.tsx +3 -4
  113. package/src/web/frontend/page/repos/repo-form-modal.tsx +1 -8
  114. package/src/web/frontend/page/repos/repo-table.tsx +4 -29
  115. package/src/web/frontend/page/repos/use-repos-derive.ts +4 -5
  116. package/src/web/frontend/page/settings/api.ts +7 -15
  117. package/src/web/frontend/page/settings/prompt-templates-section.tsx +261 -289
  118. package/src/web/frontend/page/settings/prompt-vars.ts +56 -0
  119. package/src/web/frontend/page/settings/style.css +46 -64
  120. package/src/web/frontend/page/templates/fill.tsx +124 -0
  121. package/src/web/frontend/page/templates/index.tsx +11 -0
  122. package/src/web/frontend/page/templates/manage.tsx +218 -0
  123. package/src/web/frontend/page/templates/style.css +46 -0
  124. package/src/web/frontend/page/templates/template-list.tsx +58 -54
  125. package/src/web/frontend/refs/api.ts +0 -2
  126. package/src/web/frontend/routes/route-eq.ts +22 -0
  127. package/src/web/frontend/routes/templates.ts +20 -0
  128. package/src/web/frontend/style.css +1 -0
  129. package/src/web/frontend/styles/list-search.css +44 -0
  130. package/src/web/frontend/types.ts +5 -1
  131. package/src/web/public/assets/{bar-CYWfxHfm.js → bar-j14ON7uZ.js} +1 -1
  132. package/src/web/public/assets/{composer-launch-Bor4ngrQ.js → composer-launch-DRi9mZE1.js} +1 -1
  133. package/src/web/public/assets/{composer-panel-C7mNI7EW.js → composer-panel-swmDqlPw.js} +1 -1
  134. package/src/web/public/assets/dir-DhsB1ZhL.js +3 -0
  135. package/src/web/public/assets/doc-D4po3sDc.js +6 -0
  136. package/src/web/public/assets/fill-session-fHxQHFaD.js +1 -0
  137. package/src/web/public/assets/group-BxmSNzIB.js +1 -0
  138. package/src/web/public/assets/index-CMjG5NVU.js +2 -0
  139. package/src/web/public/assets/index-uMjSWNVr.css +1 -0
  140. package/src/web/public/assets/list-filter-D-x94TvA.js +1 -0
  141. package/src/web/public/assets/manage-session-CS8UvmUd.js +1 -0
  142. package/src/web/public/assets/md-history-CZUF_FhN.js +39 -0
  143. package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +1 -0
  144. package/src/web/public/assets/refs-TuuoaRs7.js +2 -0
  145. package/src/web/public/assets/refs-zSA2k_45.css +1 -0
  146. package/src/web/public/assets/render-template-body-bXdedFig.js +1 -0
  147. package/src/web/public/assets/repo-form-modal-BD4N37MI.js +1 -0
  148. package/src/web/public/assets/repos-BPeuX4N9.js +12 -0
  149. package/src/web/public/assets/settings-CZJaKLZW.js +1 -0
  150. package/src/web/public/assets/settings-Cc6puKd5.css +1 -0
  151. package/src/web/public/assets/task-DgbbF5gy.js +11 -0
  152. package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
  153. package/src/web/public/assets/{task-utils-DpnPjZKJ.js → task-utils-bJH1-Cjy.js} +1 -1
  154. package/src/web/public/assets/templates-CBXlwyof.js +11 -0
  155. package/src/web/public/assets/templates-plA8R7jJ.css +1 -0
  156. package/src/web/public/assets/use-rail-drag-ufwy2XZB.js +1 -0
  157. package/src/web/public/index.html +8 -6
  158. package/src/modules/docs/actions/doc-attach-note.ts +0 -32
  159. package/src/modules/promptplug/Template/blockTemplates.json +0 -90
  160. package/src/modules/promptplug/actions/prompt-order.ts +0 -38
  161. package/src/modules/promptplug/ensure.ts +0 -57
  162. package/src/modules/promptplug/keys.ts +0 -9
  163. package/src/modules/promptplug/plugins/readonly-blocks.ts +0 -75
  164. package/src/modules/promptplug/template-bundle.ts +0 -59
  165. package/src/web/frontend/modules/md/template-locks.ts +0 -105
  166. package/src/web/frontend/page/settings/prompt-editor.tsx +0 -279
  167. package/src/web/frontend/page/settings/prompt-rail.tsx +0 -170
  168. package/src/web/public/assets/dir-CcffxXL2.js +0 -3
  169. package/src/web/public/assets/doc-BxWVzWkw.js +0 -6
  170. package/src/web/public/assets/group-C5Yu3oJr.js +0 -1
  171. package/src/web/public/assets/index-BvyZ1MA2.js +0 -2
  172. package/src/web/public/assets/index-Cp-TtHyA.css +0 -1
  173. package/src/web/public/assets/md-history-DejKuR12.js +0 -39
  174. package/src/web/public/assets/refs-DJdKV8_H.css +0 -1
  175. package/src/web/public/assets/refs-VbDnDTV0.js +0 -2
  176. package/src/web/public/assets/repo-form-modal-Dkdvu_uN.js +0 -1
  177. package/src/web/public/assets/repos-CY0eZheu.js +0 -16
  178. package/src/web/public/assets/settings-AwzLRYUu.css +0 -1
  179. package/src/web/public/assets/settings-D3T-vgCl.js +0 -1
  180. package/src/web/public/assets/task-CkCD82h_.js +0 -11
  181. package/src/web/public/assets/templates-BcuCbT4U.js +0 -10
  182. package/src/web/public/assets/templates-gNdtaMI2.css +0 -1
  183. package/src/web/public/assets/use-rail-drag-DMvr8-GE.js +0 -1
@@ -1,36 +1,254 @@
1
- // attachment 插件(order 20):附件识别。数据变换(attachTemplateCtx)留在
2
- // tasktool/attach-template.ts(依赖 attach-resource 的标注工具链,随插件搬会牵动
3
- // 三处引用)——插件消费宿主取数标注后的 attach 对象,schema 声明变量目录。
1
+ // attachment 插件(order 20):附件识别。
2
+ //
3
+ // 数据变换(attachTemplateCtx)留在 tasktool/attach-template.ts —— 它依赖
4
+ // attach-resource 的标注工具链(kind 归一 / 可读性探测 / 取用命令),随插件搬会
5
+ // 牵动三处引用。插件消费宿主标注后的 attach 对象,**schema 逐字对齐它的真实形状**。
6
+ //
7
+ // ⚠️ 这里不能用 `z.array(z.looseObject({}))` 敷衍:schema 不只是「校验开关」,它是
8
+ // 变量目录的唯一来源(`GET /api/prompt/registry` 的 fields)——写成空对象,设置页就
9
+ // 再也说不出每个附件条目到底能引哪些变量,模板作者只能靠猜。
10
+ //
11
+ // 附件的真实形状是「一份公共清单字段 + 按 kind 分支的子对象」(见 attach-template.ts
12
+ // 的 ctxItemOf):
13
+ // file → file{localPath,fileId,exists,syncCmd} 本机附件仓的盘上副本
14
+ // url → url{href,host} 外部链接,直接抓取
15
+ // task → task{topicKey,seq,title,status,…,showCmd} 任务引用(不是副本,读最新正文)
16
+ // ref → ref{refId,title,desc,readCmd,content} 文档库实体(docs get --ref)
17
+ // mdfile → mdfile{absPath,anchorDir,content,…,readCmd} 外部 .md 指针(docs mdfile)
18
+ // folder → folder{absPath,exists,missing,readCmd} 本地目录指针(先列目录)
19
+ // 各 kind 的顶层同时平铺了子对象的字段(历史兼容:老模板写 {{localPath}} / {{href}}),
20
+ // 所以顶层用 discriminatedUnion + looseObject:kind 决定形状,未声明的扩展字段原样保留。
4
21
  import { z } from 'zod';
5
- import { PromptPlugin } from '../base.js';
22
+ import { PromptPlugin, supplied, type Supply, type TemplateText } from '../base.js';
23
+
24
+ /** 附件 kind(与 attach-resource.ts 的 baseKind 归一结果一致)。 */
25
+ export const ATTACH_KINDS = ['file', 'url', 'task', 'ref', 'mdfile', 'folder'] as const;
26
+ /** 来源:正文内嵌 / 附件区(关系表 role 决定)。 */
27
+ export const ATTACH_ORIGINS = ['inline', 'area'] as const;
28
+
29
+ const kind = z.enum(ATTACH_KINDS);
30
+ /** 每条附件的类型说明(union 各分支共用同一句,去重后目录里能看到完整枚举)。 */
31
+ const KIND_DESC = '附件类型:file / url / task / ref / mdfile / folder(决定子对象形状与取用命令)';
32
+ const origin = z.enum(ATTACH_ORIGINS);
33
+
34
+ /**
35
+ * 每条附件都有的清单字段(ctxItemOf 的 item 部分,逐字对齐)。
36
+ *
37
+ * `origin` / `area` 是同义字段(area 是旧名),`kindLabel` / `originLabel` /
38
+ * `sizeText` 是渲染用的人类可读串——模板里直接写 {{kindLabel}} 就行,不必自己拼。
39
+ */
40
+ const baseItem = {
41
+ id: z.string().describe('附件 id(kind=folder/mdfile 时也是 file content / docs mdfile 的入参)'),
42
+ kind: kind.describe(KIND_DESC),
43
+ kindLabel: z.string().describe('类型中文名:附件 / 图片 / 链接 / 任务 / 文档 / md / 文件夹'),
44
+ isImage: z.boolean().describe('是否图片(仅 kind=file 且扩展名或 MIME 命中)'),
45
+ name: z.string().describe('展示名(任务类为「#seq 标题」)'),
46
+ size: z.number().describe('字节数(url/task/ref 为 0)'),
47
+ sizeText: z.string().describe('人类可读体积(1.2 MB / 22 B;0 为空串)'),
48
+ mime: z.string(),
49
+ storage: z.string().describe('local(本机附件仓)/ external(磁盘原地)/ internal(库内实体)/ url'),
50
+ role: z.string().describe('关系表角色:inline / reference / attach / doc'),
51
+ origin,
52
+ originLabel: z.string().describe('来源中文名:正文内嵌 / 附件区'),
53
+ /** 旧字段名(= origin),老模板仍在用 */
54
+ area: origin.describe('= origin(旧写法,正文内嵌 / 附件区)'),
55
+ areaLabel: z.string(),
56
+ usage: z.string().describe('取用方式(一句话 + 具体命令),直接可读给 agent'),
57
+ cmd: z.string().describe('取用命令(有则给,url/file 可能为空)'),
58
+ locator: z.string().describe('定位串(清单行末尾展示的「在哪」)'),
59
+ needsSync: z.boolean().describe('是否需要额外同步(本机模型恒 false)'),
60
+ note: z.string().describe('边上的说明(attach --note 的落点)'),
61
+ target: z.string(),
62
+ targetKind: z.string(),
63
+ targetKey: z.string(),
64
+ targetSeq: z.number().nullable(),
65
+ };
66
+
67
+ /** kind=file:本机附件仓的盘上副本。**直接读 file.localPath**。 */
68
+ const fileItem = z.looseObject({
69
+ ...baseItem,
70
+ kind: z.literal('file').describe(KIND_DESC),
71
+ localPath: z.string().describe('本机绝对路径(不存在时为空串,看 file.exists)'),
72
+ fileId: z.string(),
73
+ exists: z.boolean().describe('盘上是否真有这个文件'),
74
+ syncCmd: z.string().describe('历史字段,恒为空串(本机附件没有同步这一步)'),
75
+ path: z.string().describe('= localPath(旧写法)'),
76
+ file: z.looseObject({
77
+ localPath: z.string(),
78
+ fileId: z.string(),
79
+ exists: z.boolean(),
80
+ syncCmd: z.string(),
81
+ }).describe('本机文件视图:模板里用 {{#if file}}{{file.localPath}}{{/if}}'),
82
+ });
83
+
84
+ /** kind=url:外部链接,**直接抓 url.href**。 */
85
+ const urlItem = z.looseObject({
86
+ ...baseItem,
87
+ kind: z.literal('url').describe(KIND_DESC),
88
+ href: z.string().describe('外部链接地址'),
89
+ host: z.string().describe('host(从 href 解析,解析失败为空串)'),
90
+ urlText: z.string().describe('= href(旧写法)'),
91
+ url: z.looseObject({ href: z.string(), host: z.string() }).describe('链接视图:{{url.href}}'),
92
+ });
93
+
94
+ /** kind=task:任务引用(不是副本)。**用 task.showCmd 读最新正文**。 */
95
+ const taskItem = z.looseObject({
96
+ ...baseItem,
97
+ kind: z.literal('task').describe(KIND_DESC),
98
+ taskId: z.number().describe('本地外键(任务搬家后不变;已被清理时为 0)'),
99
+ topicKey: z.string(),
100
+ topicName: z.string(),
101
+ seq: z.number().describe('任务号(localtask show --id)'),
102
+ title: z.string(),
103
+ status: z.string().describe('pending / claimed / done / cancelled'),
104
+ statusLabel: z.string().describe('状态中文名(清理后为「已清理」)'),
105
+ address: z.string().describe('当前地址 topicKey:seq'),
106
+ storedAddress: z.string().describe('登记时存下的地址(与 address 不同 = 地址漂移)'),
107
+ addressDrift: z.boolean(),
108
+ resolved: z.boolean().describe('能否读到目标任务(false = 已被清理)'),
109
+ purged: z.boolean(),
110
+ deleted: z.boolean().describe('目标任务是否已软删'),
111
+ showCmd: z.string().describe('读最新正文的命令:nx-kv localtask show --id <seq> [--key <topicKey>]'),
112
+ task: z.looseObject({
113
+ taskId: z.number(),
114
+ topicKey: z.string(),
115
+ topicName: z.string(),
116
+ seq: z.number(),
117
+ title: z.string(),
118
+ status: z.string(),
119
+ statusLabel: z.string(),
120
+ address: z.string(),
121
+ storedAddress: z.string(),
122
+ addressDrift: z.boolean(),
123
+ resolved: z.boolean(),
124
+ purged: z.boolean(),
125
+ deleted: z.boolean(),
126
+ showCmd: z.string(),
127
+ }).describe('任务引用视图:{{#if task}}{{task.statusLabel}}{{/if}}'),
128
+ });
129
+
130
+ /** kind=ref:文档库实体(v7 起没有物理路径)。**用 ref.readCmd / refId 取正文**。 */
131
+ const refItem = z.looseObject({
132
+ ...baseItem,
133
+ kind: z.literal('ref').describe(KIND_DESC),
134
+ refId: z.string().describe('文档 id(ref:xxxxxxxx)'),
135
+ title: z.string().describe('文档标题(正文首行 # 标题,读不到时回落 desc / 文件名)'),
136
+ desc: z.string(),
137
+ readCmd: z.string().describe('读正文的命令:nx-kv docs get --ref <refId>'),
138
+ content: z.string().describe('已内联的文档原文(role=doc 且读到全文时才有;可能为空)'),
139
+ truncated: z.boolean().describe('内联原文是否被截断(超长时给命令自己取)'),
140
+ ref: z.looseObject({
141
+ refId: z.string(),
142
+ title: z.string(),
143
+ desc: z.string(),
144
+ readCmd: z.string(),
145
+ content: z.string(),
146
+ truncated: z.boolean(),
147
+ }).describe('文档视图:{{#if ref}}{{ref.content}}{{/if}}'),
148
+ });
149
+
150
+ /** kind=mdfile:外部 .md 文件指针。**用 mdfile.readCmd 读磁盘当前内容**。 */
151
+ const mdfileItem = z.looseObject({
152
+ ...baseItem,
153
+ kind: z.literal('mdfile').describe(KIND_DESC),
154
+ absPath: z.string().describe('磁盘绝对路径'),
155
+ anchorDir: z.string().describe('登记时的锚定目录(相对路径按它解析)'),
156
+ path: z.string().describe('= absPath(旧写法)'),
157
+ mdPath: z.string().describe('= absPath(旧写法)'),
158
+ content: z.string().describe('已内联的磁盘正文(可能为空)'),
159
+ truncated: z.boolean(),
160
+ stale: z.boolean().describe('磁盘内容与登记指纹不一致'),
161
+ missing: z.boolean().describe('文件当前不可读'),
162
+ mdfile: z.looseObject({
163
+ absPath: z.string(),
164
+ anchorDir: z.string(),
165
+ content: z.string(),
166
+ truncated: z.boolean(),
167
+ stale: z.boolean(),
168
+ missing: z.boolean(),
169
+ readCmd: z.string().describe('读磁盘内容的命令:nx-kv docs mdfile <id>'),
170
+ }).describe('外部 md 视图:读正文用 {{mdfile.readCmd}},内联正文在 {{mdfile.content}}'),
171
+ });
172
+
173
+ /** kind=folder:本地目录指针。**先列 absPath 目录,再读需要的文件**。 */
174
+ const folderItem = z.looseObject({
175
+ ...baseItem,
176
+ kind: z.literal('folder').describe(KIND_DESC),
177
+ absPath: z.string().describe('目录绝对路径(先列这个目录,再读需要的文件)'),
178
+ path: z.string().describe('= absPath(旧写法)'),
179
+ exists: z.boolean(),
180
+ missing: z.boolean(),
181
+ folder: z.looseObject({
182
+ absPath: z.string(),
183
+ exists: z.boolean(),
184
+ missing: z.boolean(),
185
+ readCmd: z.string().describe('查看目录状态的命令:nx-kv file content <id>'),
186
+ }).describe('目录视图:{{#if folder}}{{folder.absPath}}{{/if}}'),
187
+ });
188
+
189
+ /** 一条附件:kind 决定形状(discriminatedUnion 给的是「kind 与字段必须自洽」这道闸)。 */
190
+ const attachItem = z
191
+ .discriminatedUnion('kind', [fileItem, urlItem, taskItem, refItem, mdfileItem, folderItem])
192
+ .describe('附件条目:file / url / task / ref / mdfile / folder,各有自己的子对象与取用命令');
6
193
 
7
194
  const schema = z.strictObject({
8
- // 内层 looseObject 且字段全 optional:attach 对象由宿主(attachTemplateCtx)构造,
9
- // schema 的校验职责收敛在「顶层段键 ∈ writes」(strictObject),子形状是变量目录
10
- attach: z.looseObject({
11
- count: z.number().optional(),
12
- inlineCount: z.number().optional(),
13
- areaCount: z.number().optional(),
14
- hasInline: z.boolean().optional(),
15
- hasArea: z.boolean().optional(),
16
- list: z.array(z.looseObject({})).optional(),
17
- }).nullable(),
195
+ // strictObject 只钉顶层段键(attach);attach 由宿主构造,段内形状见上。
196
+ attach: z
197
+ .looseObject({
198
+ count: z.number().describe('附件总数'),
199
+ inlineCount: z.number().describe('正文内嵌数量'),
200
+ areaCount: z.number().describe('附件区数量'),
201
+ hasInline: z.boolean(),
202
+ hasArea: z.boolean(),
203
+ list: z.array(attachItem).describe('结构化清单:模板用 {{#each attach.list}} 展开'),
204
+ })
205
+ .nullable(),
18
206
  });
19
207
 
208
+ /** 内置模板(#152:正文进代码)。 */
209
+ const BUILTIN: TemplateText = {
210
+ id: 'builtin',
211
+ name: '系统内置',
212
+ text: `{{#if attach}}
213
+ 〔附件〕本任务包含 {{attach.count}} 个附件(正文内嵌 {{attach.inlineCount}} · 附件区 {{attach.areaCount}})。请先识别附件内容(图片先看图、文档先读内容、文件夹先列目录)再开始处理,不要跳过附件。
214
+
215
+ 附件清单:
216
+ {{#each attach.list}}
217
+ - [{{originLabel}}] {{kindLabel}} {{name}}{{#if sizeText}}({{sizeText}}){{/if}}:{{#if file}}{{#if file.exists}}{{file.localPath}}{{else}}未同步到本地(fileId {{file.fileId}}){{/if}}{{/if}}{{#if url}}{{url.href}}{{/if}}{{#if task}}{{#if task.resolved}}#{{task.seq}} {{task.title}} · 地址 {{task.address}}({{task.statusLabel}}){{else}}地址 {{task.address}}({{task.statusLabel}}){{/if}}{{/if}}{{#if ref}}{{ref.title}}{{/if}}{{#if mdfile}}{{mdfile.absPath}}{{#if mdfile.missing}}(源文件已不在){{/if}}{{/if}}{{#if folder}}{{folder.absPath}}{{#if folder.missing}}(目录已不在){{/if}}{{/if}}{{#if note}} # {{note}}{{/if}}
218
+ {{/each}}
219
+
220
+ 取用方式:
221
+ {{#each attach.list}}
222
+ - {{kindLabel}} 《{{name}}》:{{usage}}
223
+ {{/each}}
224
+ {{#each attach.list}}{{#if mdfile}}{{#if mdfile.content}}〔外部 md · {{name}}〕({{mdfile.absPath}}{{#if mdfile.truncated}},已截断{{/if}}{{#if mdfile.stale}},内容有变化{{/if}}):
225
+
226
+ {{mdfile.content}}
227
+
228
+ {{/if}}{{/if}}{{/each}}
229
+ {{#each attach.list}}{{#if ref}}{{#if ref.content}}〔文档原文 · {{ref.title}}〕:
230
+
231
+ {{ref.content}}
232
+
233
+ {{/if}}{{/if}}{{/each}}
234
+ {{/if}}`,
235
+ };
236
+
20
237
  export class AttachmentPlugin extends PromptPlugin<typeof schema> {
21
238
  readonly id = 'attachment';
22
239
  readonly order = 20;
240
+ readonly group = 'get' as const;
23
241
  readonly tag = 'nx-kv.attachment';
24
242
  readonly label = '附件识别';
25
- override readonly writes = ['attach'];
26
243
  readonly dataSchema = schema;
244
+ readonly templates = [BUILTIN];
27
245
 
28
- /** deps.attach:attachTemplateCtx(attachments).attach(无附件 → null) */
29
- constructor(template: string, private readonly deps: { attach: unknown }) {
246
+ /** deps.attach:attachTemplateCtx(attachments).attach(无附件 → null);可传函数惰性求值 */
247
+ constructor(template: string, private readonly deps: { attach: Supply<unknown> }) {
30
248
  super(template);
31
249
  }
32
250
 
33
- protected data() {
34
- return { attach: (this.deps.attach ?? null) as z.infer<typeof schema>['attach'] };
251
+ protected async buildData() {
252
+ return { attach: (await supplied(this.deps.attach) ?? null) as z.infer<typeof schema>['attach'] };
35
253
  }
36
254
  }
@@ -2,40 +2,76 @@
2
2
  // data() 搬自 tasktool/delivery-template.ts 的 deliveryCtxOf(原文件随 S1 删除),
3
3
  // 口径注释一并迁入——#81 空壳组过滤、#104 已登记无介绍可见、参考仓库去重并集。
4
4
  import { z } from 'zod';
5
- import { PromptPlugin } from '../base.js';
5
+ import { PromptPlugin, supplied, type Supply, type TemplateText } from '../base.js';
6
6
 
7
+ // ── schema = 变量目录的唯一真相 ─────────────────────────────────────────
8
+ // 每个字段的 .describe() 就是设置页「可使用变量」里显示的含义(schema-bridge 把
9
+ // describe 读成 FieldDecl.label)。写清楚「这个变量是什么」,模板作者不用翻代码。
7
10
  const docItemShape = z.looseObject({
8
- refId: z.string(),
9
- desc: z.string(),
10
- title: z.string(),
11
- hasBody: z.boolean(),
12
- note: z.string(),
11
+ refId: z.string().describe('文档 id(nx-kv docs get --ref 用)'),
12
+ desc: z.string().describe('一句话描述(列表里的定位标签)'),
13
+ title: z.string().describe('文档标题(正文首行 # 标题)'),
14
+ hasBody: z.boolean().describe('是否已写正文(false = 只有条目,没有内容)'),
15
+ });
16
+
17
+ const refRepoShape = z.looseObject({
18
+ key: z.string().describe('参考仓库 key(仓库清单里的唯一标识)'),
19
+ name: z.string().describe('参考仓库名'),
20
+ path: z.string().describe('本地绝对路径(可直接读)'),
21
+ });
22
+
23
+ const peerShape = z.looseObject({
24
+ name: z.string().describe('成员仓库名'),
25
+ note: z.string().describe('组内描述:它在组里的角色与配合关系'),
26
+ path: z.string().describe('本地绝对路径'),
27
+ hasNote: z.boolean().describe('是否写了组内描述'),
13
28
  });
14
- const refRepoShape = z.looseObject({ key: z.string(), name: z.string(), path: z.string(), note: z.string() });
15
- const peerShape = z.looseObject({ name: z.string(), note: z.string(), path: z.string(), hasNote: z.boolean() });
16
29
 
17
30
  const repoShape = z.looseObject({
18
- name: z.string(), key: z.string(),
19
- intro: z.string(), introPath: z.string(), introRefId: z.string(), introDesc: z.string(),
20
- docs: z.array(docItemShape), docCount: z.number(),
21
- refRepos: z.array(refRepoShape), refRepoCount: z.number(),
31
+ name: z.string().describe('项目名(登记名;未填时回落 key)'),
32
+ key: z.string().describe('项目 key(本机组内唯一标识)'),
33
+ intro: z.string().describe('项目介绍正文(主篇全文)'),
34
+ introPath: z.string().describe('项目介绍文档路径(本地 md;没有为空串)'),
35
+ introRefId: z.string().describe('项目介绍文档 id(docs get --ref 用)'),
36
+ introDesc: z.string().describe('项目介绍的一句话描述'),
37
+ docs: z.array(docItemShape).describe('项目文档清单(refId / desc / title)'),
38
+ docCount: z.number().describe('项目文档数'),
39
+ refRepos: z.array(refRepoShape).describe('绑定到本项目的参考仓库清单'),
40
+ refRepoCount: z.number().describe('参考仓库数'),
22
41
  });
42
+
23
43
  const groupShape = z.looseObject({
24
- name: z.string(), key: z.string(), desc: z.string(),
25
- intro: z.string(), introPath: z.string(), introRefId: z.string(), introDesc: z.string(),
26
- note: z.string(), position: z.string(),
27
- peers: z.array(peerShape), peerCount: z.number(),
28
- docs: z.array(docItemShape), docCount: z.number(),
29
- refRepos: z.array(refRepoShape), refRepoCount: z.number(),
44
+ name: z.string().describe('项目组名'),
45
+ key: z.string().describe('项目组 key(组内唯一标识)'),
46
+ desc: z.string().describe('组定位:这个组是干什么的(一句话)'),
47
+ intro: z.string().describe('组介绍正文(主篇全文)'),
48
+ introPath: z.string().describe('组介绍文档路径(本地 md;没有为空串)'),
49
+ introRefId: z.string().describe('组介绍文档 id(docs get --ref 用)'),
50
+ introDesc: z.string().describe('组介绍的一句话描述'),
51
+ note: z.string().describe('组内描述:本项目在组里的位置(角色 / 协作关系)'),
52
+ position: z.string().describe('= note(旧字段名,新模板用 note)'),
53
+ peers: z.array(peerShape).describe('组内成员(name / note / path)'),
54
+ peerCount: z.number().describe('组内成员数'),
55
+ docs: z.array(docItemShape).describe('组文档清单'),
56
+ docCount: z.number().describe('组文档数'),
57
+ refRepos: z.array(refRepoShape).describe('组级绑定的参考仓库清单'),
58
+ refRepoCount: z.number().describe('组级参考仓库数'),
30
59
  });
31
60
 
32
61
  const schema = z.strictObject({
33
- repo: repoShape.nullable(),
34
- group: groupShape.nullable(),
35
- refRepos: z.looseObject({ list: z.array(refRepoShape), count: z.number() }),
36
- groups: z.array(z.looseObject({ name: z.string(), desc: z.string(), path: z.string() })),
62
+ repo: repoShape.nullable().describe('本项目(工作目录对应的登记仓库);未登记 → null,整段换「未登记」提示'),
63
+ group: groupShape.nullable().describe('本次任务所属的项目组;没有组 / 空壳组 → null'),
64
+ refRepos: z
65
+ .looseObject({
66
+ list: z.array(refRepoShape).describe('项目绑定 ∪ 组级绑定(去重,项目在前)'),
67
+ count: z.number().describe('去重后的总数'),
68
+ })
69
+ .describe('可直接读取的参考仓库(交付里单列一段)'),
70
+ groups: z
71
+ .array(z.looseObject({ name: z.string(), desc: z.string(), path: z.string() }))
72
+ .describe('其它有内容的项目组概览(主组之外)'),
37
73
  // 可见 seed 变量({{cwd}}),data() 不返回它
38
- cwd: z.string().optional(),
74
+ cwd: z.string().optional().describe('工作目录绝对路径(seed,宿主传入)'),
39
75
  });
40
76
 
41
77
  /** 「项目文档 / 组文档」→ 结构化数组(模板用 {{#each}} 组织行)。 */
@@ -46,7 +82,6 @@ function docItems(links: any) {
46
82
  desc: d.desc || '',
47
83
  title: d.title || '',
48
84
  hasBody: d.hasBody !== false,
49
- note: d.note || '',
50
85
  }));
51
86
  }
52
87
 
@@ -66,7 +101,6 @@ function refRepoItems(list: any) {
66
101
  key: r.key || '',
67
102
  name: r.name || '',
68
103
  path: r.path || '',
69
- note: r.note || '',
70
104
  }));
71
105
  }
72
106
 
@@ -97,7 +131,7 @@ export function deliveryCtxOf(groupCtx: any) {
97
131
  const groupRefRepos = g ? refRepoItems(g.refRepos) : [];
98
132
  // 交付口径:本仓库直接绑定 ∪ 本次任务所属组的组级绑定,去重后按本仓库在前排序。
99
133
  const seenRefRepoKeys = new Set<string>();
100
- const refRepoList: { key: string; name: string; path: string; note: string }[] = [];
134
+ const refRepoList: { key: string; name: string; path: string }[] = [];
101
135
  for (const r of [...repoRefRepos, ...groupRefRepos]) {
102
136
  const k = r.key || r.name;
103
137
  if (seenRefRepoKeys.has(k)) continue;
@@ -149,19 +183,79 @@ export function deliveryCtxOf(groupCtx: any) {
149
183
  };
150
184
  }
151
185
 
186
+ /** 内置模板(#152:正文进代码,不再有 JSON 注册表 / DB seed)。 */
187
+ const BUILTIN: TemplateText = {
188
+ id: 'builtin',
189
+ name: '系统内置',
190
+ text: `{{#if repo}}
191
+ {{#if repo.intro}}
192
+ 〔项目介绍 · {{repo.name}}〕
193
+ {{repo.intro}}
194
+ {{/if}}
195
+ {{#if repo.docs}}
196
+ 〔项目文档〕按需取用:nx-kv docs get --ref <refId>
197
+ {{#each repo.docs}}
198
+ - {{#if title}}{{title}}{{else}}未命名文档{{/if}}{{#if desc}}
199
+ {{desc}}{{/if}}
200
+ 取用:nx-kv docs get --ref {{refId}}
201
+ {{/each}}
202
+ {{/if}}
203
+ {{#if repo.intro}}{{else}}{{#if repo.docs}}{{else}}
204
+ 〔项目上下文 · {{repo.name}}〕已登记为本机仓库({{repo.key}}),但没有项目介绍文档:nx-kv repo doc add {{repo.key}} --ref <refId>
205
+ {{/if}}{{/if}}
206
+ {{/if}}
207
+ {{#if repo}}{{else}}{{#if cwd}}
208
+ 〔项目上下文〕工作目录 {{cwd}} 未登记为本机仓库,本次交付没有项目介绍 / 组上下文。登记(不需要 .git,给 key 即可):nx-kv repo add "{{cwd}}" --key <key>
209
+ {{/if}}{{/if}}
210
+ {{#if group}}
211
+ 〔项目组上下文 · {{group.name}}〕
212
+ {{#if group.desc}}
213
+ 组定位:{{group.desc}}
214
+ {{/if}}
215
+ {{#if group.note}}
216
+ 本项目在组里的位置:{{group.note}}
217
+ {{/if}}
218
+ {{#if group.introRefId}}
219
+ 组介绍:{{#if group.introDesc}}{{group.introDesc}}{{else}}(无描述){{/if}}
220
+ 取用:nx-kv docs get --ref {{group.introRefId}}
221
+ {{/if}}
222
+ {{#if group.peers}}
223
+ 组内成员:
224
+ {{#each group.peers}}
225
+ - {{name}}:{{#if note}}{{note}}{{else}}(无组内描述){{/if}}{{#if path}}({{path}}){{/if}}
226
+ {{/each}}
227
+ {{/if}}
228
+ {{#if group.docs}}
229
+ 组文档(按需取用):
230
+ {{#each group.docs}}
231
+ - {{#if title}}{{title}}{{else}}未命名文档{{/if}}{{#if desc}}
232
+ {{desc}}{{/if}}
233
+ 取用:nx-kv docs get --ref {{refId}}
234
+ {{/each}}
235
+ {{/if}}
236
+ {{/if}}
237
+ {{#if refRepos.count}}
238
+ 参考仓库(可直接读取,共 {{refRepos.count}} 个):
239
+ {{#each refRepos.list}}
240
+ - {{name}}{{#if path}}({{path}}){{/if}}
241
+ {{/each}}
242
+ {{/if}}`,
243
+ };
244
+
152
245
  export class ContextPlugin extends PromptPlugin<typeof schema> {
153
246
  readonly id = 'context';
154
247
  readonly order = 10;
248
+ readonly group = 'get' as const;
155
249
  readonly tag = 'nx-kv.context';
156
250
  readonly label = '组 / 项目上下文';
157
- override readonly writes = ['repo', 'group', 'refRepos', 'groups'];
158
251
  readonly dataSchema = schema;
252
+ readonly templates = [BUILTIN];
159
253
 
160
- constructor(template: string, private readonly deps: { groupCtx: unknown }) {
254
+ constructor(template: string, private readonly deps: { groupCtx: Supply<unknown> }) {
161
255
  super(template);
162
256
  }
163
257
 
164
- protected data() {
165
- return deliveryCtxOf(this.deps.groupCtx);
258
+ protected async buildData() {
259
+ return deliveryCtxOf(await supplied(this.deps.groupCtx));
166
260
  }
167
261
  }
@@ -0,0 +1,33 @@
1
+ // doneguard 段(order 50 / done 链):未到点不许 done 的拦截文案。
2
+ //
3
+ // 一个段一个文件:正文就是这个类里的 BUILTIN。
4
+ // 条件渲染(goal.blocked)——时间没到才输出,到了就整段消失。
5
+ import { z } from 'zod';
6
+ import { PromptPlugin, type TemplateText } from '../base.js';
7
+ import { goalShape, taskShape } from './goal-shape.js';
8
+
9
+ const schema = z.strictObject({ goal: goalShape, task: taskShape });
10
+
11
+ const BUILTIN: TemplateText = {
12
+ id: 'builtin',
13
+ name: '系统内置',
14
+ text: `{{#if goal.blocked}}
15
+ 〔完成门禁 · 时间未到〕任务 #{{task.id}} 还不能 done:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),剩余 {{goal.remainingHuman}}。
16
+ - 现在可做:{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}收尾整理(收敛改动 / 补验证 / 写清遗留),或派 sub agent 提出新的需求继续推进{{else}}继续推进主线,并派 sub agent 重新提出新的需求{{/if}}。
17
+ - 每轮推进先跑:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>"
18
+ - 到点后再:nx-kv localtask done --id {{task.id}} --summary "<完成总结>"
19
+ {{/if}}`,
20
+ };
21
+
22
+ export class DoneguardPlugin extends PromptPlugin<typeof schema> {
23
+ readonly id = 'doneguard';
24
+ readonly order = 50;
25
+ readonly group = 'done' as const;
26
+ readonly tag = 'nx-kv.doneguard';
27
+ readonly label = '完成门禁提示(timegoal)';
28
+ readonly dataSchema = schema;
29
+ readonly templates = [BUILTIN];
30
+
31
+ constructor(template = '') { super(template); }
32
+ protected buildData() { return {} as never; }
33
+ }
@@ -1,32 +1,55 @@
1
1
  // ext 插件(order 60):待领取队列。变换薄(count>0 才进 ctx,空队列 null 段消失),
2
2
  // 从 wait.ts 的 extCtx 组装搬入;pendingQueueInfo 的 I/O 由宿主完成后注入结果。
3
3
  import { z } from 'zod';
4
- import { PromptPlugin } from '../base.js';
4
+ import { PromptPlugin, supplied, type Supply, type TemplateText } from '../base.js';
5
+
6
+ // 内层字段全 optional:queueInfo 由宿主(pendingQueueInfo)构造,校验职责收敛在顶层段键。
7
+ // .describe() 是设置页变量目录显示的含义(schema-bridge 读它当 label)。
8
+ const queueItemShape = z.looseObject({
9
+ id: z.number().optional().describe('任务号(localtask show --id)'),
10
+ title: z.string().optional().describe('任务标题(正文首个非空行)'),
11
+ });
5
12
 
6
13
  const schema = z.strictObject({
7
- // 内层字段全 optional:queueInfo 由宿主(pendingQueueInfo)构造,校验职责收敛在顶层段键
8
- ext: z.looseObject({
9
- topic: z.string().optional(),
10
- count: z.number().optional(),
11
- list: z.array(z.looseObject({ id: z.number().optional(), title: z.string().optional() })).optional(),
12
- }).nullable(),
14
+ ext: z
15
+ .looseObject({
16
+ topic: z.string().optional().describe('队列所属主题(工作目录名)'),
17
+ count: z.number().optional().describe('还有多少条待领取任务'),
18
+ list: z.array(queueItemShape).optional().describe('待领取任务清单(最多前几条)'),
19
+ })
20
+ .nullable()
21
+ .describe('同主题剩余队列;空队列 → null(整段不输出)'),
13
22
  });
14
23
 
24
+ /** 内置模板(#152:正文进代码)。 */
25
+ const BUILTIN: TemplateText = {
26
+ id: 'builtin',
27
+ name: '系统内置',
28
+ text: `{{#if ext.count}}
29
+ 本队列({{ext.topic}})还有 {{ext.count}} 条待领取任务:
30
+ {{#each ext.list}}
31
+ - #{{id}} {{title}}
32
+ {{/each}}
33
+ 先完成当前任务,再领取下一条;不要因为后面还有活就提前收尾或分心。
34
+ {{/if}}`,
35
+ };
36
+
15
37
  export class ExtPlugin extends PromptPlugin<typeof schema> {
16
38
  readonly id = 'ext';
17
39
  readonly order = 60;
40
+ readonly group = 'get' as const;
18
41
  readonly tag = 'nx-kv.ext';
19
42
  readonly label = '待领取队列(ext)';
20
- override readonly writes = ['ext'];
21
43
  readonly dataSchema = schema;
44
+ readonly templates = [BUILTIN];
22
45
 
23
46
  /** deps.queueInfo:pendingQueueInfo(topicKey, taskId) 的结果(读取失败 → null) */
24
- constructor(template: string, private readonly deps: { queueInfo: { topic: string; count: number; list: { id: number; title: string }[] } | null }) {
47
+ constructor(template: string, private readonly deps: { queueInfo: Supply<{ topic: string; count: number; list: { id: number; title: string }[] } | null> }) {
25
48
  super(template);
26
49
  }
27
50
 
28
- protected data() {
29
- const q = this.deps.queueInfo;
51
+ protected async buildData() {
52
+ const q = await supplied(this.deps.queueInfo);
30
53
  return { ext: q && q.count > 0 ? { topic: q.topic, count: q.count, list: q.list } : null };
31
54
  }
32
55
  }
@@ -2,28 +2,49 @@
2
2
  // deps.loopText 是宿主先把「项目级收尾指令模板」渲染好的文本(wait.ts 保留这一步
3
3
  // 与其 renderWarnings 告警口径);waitMinutes=0 时模板闸门 {{#if (gt …)}} 收口。
4
4
  import { z } from 'zod';
5
- import { PromptPlugin } from '../base.js';
5
+ import { PromptPlugin, supplied, type Supply, type TemplateText } from '../base.js';
6
6
 
7
7
  const schema = z.strictObject({
8
- getloop: z.looseObject({ text: z.string(), waitMinutes: z.number() }).nullable(),
8
+ getloop: z
9
+ .looseObject({
10
+ text: z.string().describe('「继续 get」的整段指令(宿主已渲染好的文本)'),
11
+ waitMinutes: z.number().describe('没活时每次阻塞的分钟数(0 = 不阻塞)'),
12
+ })
13
+ .nullable()
14
+ .describe('项目级持续 get;未开启 → null(整段不输出)'),
9
15
  // 可见 seed 变量({{task.id}}),data() 不返回它
10
- task: z.looseObject({ id: z.number(), text: z.string() }).optional().nullable(),
16
+ task: z
17
+ .looseObject({ id: z.number().describe('任务号'), text: z.string().describe('任务正文原文') })
18
+ .optional()
19
+ .nullable()
20
+ .describe('当前任务(seed,宿主传入)'),
11
21
  });
12
22
 
23
+ /** 内置模板(#152:正文进代码)。 */
24
+ const BUILTIN: TemplateText = {
25
+ id: 'builtin',
26
+ name: '系统内置',
27
+ text: `{{#if getloop}}
28
+ {{#if task}}不要直接结束本轮:完成上面的任务({{task.id}})之后,继续调用 nx-kv localtask get 领取下一条任务。队列里有活会立即返回;{{#if (gt getloop.waitMinutes 0)}}没活时每次最多阻塞 {{getloop.waitMinutes}} 分钟,直到 get 返回 timeout 为止。{{/if}}{{/if}}
29
+ {{/if}}`,
30
+ };
31
+
13
32
  export class GetloopPlugin extends PromptPlugin<typeof schema> {
14
33
  readonly id = 'getloop';
15
34
  readonly order = 80;
35
+ readonly group = 'get' as const;
16
36
  readonly tag = 'nx-kv.getloop';
17
37
  readonly label = '持续 get';
18
- override readonly writes = ['getloop'];
19
38
  readonly dataSchema = schema;
39
+ readonly templates = [BUILTIN];
20
40
 
21
- constructor(template: string, private readonly deps: { loopText: string; waitMinutes: number }) {
41
+ constructor(template: string, private readonly deps: { loopText: Supply<string>; waitMinutes: Supply<number> }) {
22
42
  super(template);
23
43
  }
24
44
 
25
- protected data() {
26
- const text = String(this.deps.loopText || '').trim();
27
- return { getloop: text ? { text, waitMinutes: Number(this.deps.waitMinutes) || 0 } : null };
45
+ protected async buildData() {
46
+ const text = String(await supplied(this.deps.loopText) || '').trim();
47
+ const waitMinutes = Number(await supplied(this.deps.waitMinutes)) || 0;
48
+ return { getloop: text ? { text, waitMinutes } : null };
28
49
  }
29
50
  }