nx-kv 0.24.5 → 0.24.6
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.
- package/CHANGELOG.md +19 -0
- package/package.json +1 -1
- package/src/core/instruction-template.js +18 -8
- package/src/modules/localtask/index.js +14 -1
- package/src/modules/localtask/task-templates.js +11 -0
- package/src/modules/localtask/topics.js +8 -3
- package/src/modules/tasktool/delivery-template.js +169 -0
- package/src/modules/tasktool/get.js +2 -1
- package/src/modules/tasktool/params.js +34 -0
- package/src/modules/tasktool/wait.js +22 -7
- package/src/web/frontend/page/settings/prompts-section.jsx +83 -0
- package/src/web/public/assets/{Introduction-DXYXCsLt.js → Introduction-B_U-xbb9.js} +1 -1
- package/src/web/public/assets/{cloud-B5tEFW73.js → cloud-zp3n4ola.js} +1 -1
- package/src/web/public/assets/{dag-BR57inO8.js → dag-Clekc4yJ.js} +1 -1
- package/src/web/public/assets/{dir-DUEAkp2o.js → dir-Cll78K45.js} +1 -1
- package/src/web/public/assets/{group-DuB9bfSA.js → group-dtrdwnRv.js} +1 -1
- package/src/web/public/assets/{index-EJe-dAu1.js → index-3r8gg9d1.js} +2 -2
- package/src/web/public/assets/{md-history-D1OkTAPF.js → md-history-DUYRtww_.js} +1 -1
- package/src/web/public/assets/{member-picker-Cu0zN4sN.js → member-picker-Bw2AsF1j.js} +1 -1
- package/src/web/public/assets/{overview-C4X_IeGF.js → overview-B4pRZYIr.js} +1 -1
- package/src/web/public/assets/{progress-DBGZEvg7.js → progress-Bwcg-x19.js} +1 -1
- package/src/web/public/assets/{repos-BDC1oViD.js → repos-BO0Eoktc.js} +1 -1
- package/src/web/public/assets/{route-crumb-DuxH--DL.js → route-crumb-DWHcDjTH.js} +1 -1
- package/src/web/public/assets/settings-BUSNdkTd.js +8 -0
- package/src/web/public/assets/{task-D3Zw8rd-.js → task-DrUzpfEg.js} +1 -1
- package/src/web/public/assets/{template-slots-FCW6EtPa.js → template-slots-D6x4JKZ3.js} +1 -1
- package/src/web/public/assets/{templates-CMJoZIKG.js → templates-CESTAUsK.js} +1 -1
- package/src/web/public/assets/{upload-wBPvXjB0.js → upload-d5Uchr6Y.js} +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/assets/settings-CenGelQ_.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.24.6] - 2026-11-05 交付提示词模板化 + 外部参数平面扩展
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- **交付给 agent 的提示词改成「模板 + 占位符」,并在面板上可见可改**(任务 #62):
|
|
10
|
+
领到组内仓库的任务时,交付文本 = **原始提示词(正文逐字)** + **组 / 项目的关键路径**
|
|
11
|
+
(组 / 项目的描述本身就是本地 markdown,给的是磁盘真实路径,agent 拿到就能读盘)。
|
|
12
|
+
- 新增 `tasktool/delivery-template.js`:默认模板逐字复现改造前的输出口径;ctx 只给
|
|
13
|
+
**数据**,措辞归模板(`{{repo.*}}` / `{{group.*}}` / `{{task.text}}` / `{{goal.*}}`…)。
|
|
14
|
+
- 模板存设置里(`settings.deliveryTemplate`):CLI `localtask config
|
|
15
|
+
--delivery-template "…"`(`--reset-delivery-template` 恢复默认);面板设置 →
|
|
16
|
+
「提示词 / 模板」→「交付上下文」一栏,多行编辑 + **占位符清单**。
|
|
17
|
+
- **领取引擎支持平面扩展**:`localtask get` / `wait` 新增 `--param k=v`(可重复 /
|
|
18
|
+
逗号分隔),参数进 ctx 顶层(`{{k}}`)同时归拢在 `{{params.k}}`;内建同名键不被覆盖。
|
|
19
|
+
- 渲染器(`core/instruction-template.js`)段落名推广到**任意名字**(`{{#repo}}`、
|
|
20
|
+
`{{#group}}`…):`goal` / `task` 缺失即丢弃的旧语义不变,其他名字在 ctx 里显式给了
|
|
21
|
+
键才按值取舍。
|
|
22
|
+
|
|
23
|
+
> 评估文档:`plan/cli-get-template-eval.md`(现状评估 + 设计 + 遗留建议)。
|
|
5
24
|
## [0.24.5] - 2026-11-05 侧栏支持单项目
|
|
6
25
|
|
|
7
26
|
### Changed
|
package/package.json
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
// (DEFAULT_TASK_SUFFIX)留在 localtask service。
|
|
8
8
|
//
|
|
9
9
|
// 语法(v1 无转义:模板正文无法表达字面 {{,纯文本后缀不该含 {{):
|
|
10
|
-
// 段落 {{#goal}}…{{/goal}}、{{#task}}…{{/task}}
|
|
11
|
-
//
|
|
10
|
+
// 段落 {{#goal}}…{{/goal}}、{{#task}}…{{/task}}、{{#任意名}}…{{/任意名}}
|
|
11
|
+
// goal / task:ctx 里缺失(null/undefined)时整段丢弃;
|
|
12
|
+
// 其他名字:ctx **显式给了这个键**才按值取舍(null → 丢弃),
|
|
13
|
+
// 没给这个键 → 当未知标记处理(内容保留,与旧语义一致)
|
|
12
14
|
// 占位符 {{goal.name}} {{goal.deadline}} {{goal.remainingHuman}} {{goal.prompt}}
|
|
13
15
|
// {{task.id}} {{task.text}} {{source}} {{summary}} {{cwd}} {{name}}
|
|
14
16
|
// 按 `.` 分段走 ctx,任何一步缺失或未知路径一律 ''(宽容,绝不抛错)
|
|
@@ -26,8 +28,16 @@
|
|
|
26
28
|
//
|
|
27
29
|
// 单测:tests/unit/instruction-template.test.mjs(段落/占位符/单遍/空白全钉死)。
|
|
28
30
|
|
|
29
|
-
const TOKEN_RE = /\{\{(#|\/)(
|
|
30
|
-
|
|
31
|
+
const TOKEN_RE = /\{\{(#|\/)([A-Za-z][A-Za-z0-9_]*)\}\}|\{\{([^{}]*)\}\}/g;
|
|
32
|
+
// 段落取舍:goal / task 缺了就整段丢弃(既有语义不变);
|
|
33
|
+
// 其他名字——ctx 里**显式给了这个键**才按值取舍(给 null 即丢弃),
|
|
34
|
+
// 没给这个键 = 未知标记,当普通占位符处理(内容保留,兼容旧行为)。
|
|
35
|
+
function sectionKeep(name, ctx) {
|
|
36
|
+
if (name === 'goal' || name === 'task') return !!(ctx && ctx[name]);
|
|
37
|
+
if (!ctx || typeof ctx !== 'object') return true;
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(ctx, name)) return true;
|
|
39
|
+
return !!ctx[name];
|
|
40
|
+
}
|
|
31
41
|
|
|
32
42
|
/** 含任意 {{ 即视为模板(决定走渲染路径还是旧的纯文本追加路径)。 */
|
|
33
43
|
export function hasTemplateMarkers(template) {
|
|
@@ -85,11 +95,11 @@ export function renderInstruction(template, ctx = {}) {
|
|
|
85
95
|
for (let m = TOKEN_RE.exec(src); m; m = TOKEN_RE.exec(src)) {
|
|
86
96
|
// 字面段:插入值(此处是模板里的字面文本)只在发射态进入输出
|
|
87
97
|
if (emitting()) out += src.slice(last, m.index);
|
|
88
|
-
|
|
98
|
+
|
|
89
99
|
let consumed = TOKEN_RE.lastIndex;
|
|
90
100
|
if (m[1] === '#') {
|
|
91
101
|
const name = m[2];
|
|
92
|
-
frames.push({ name, keep: name
|
|
102
|
+
frames.push({ name, keep: sectionKeep(name, ctx) });
|
|
93
103
|
} else if (m[1] === '/') {
|
|
94
104
|
// 按名匹配才弹栈:错配的 close(如 goal 段里写 {{/task}})是无操作——
|
|
95
105
|
// 宽容但不泄漏:被丢弃段的内容不会因为一个错配 close 就提前"出栈"见光。
|
|
@@ -99,8 +109,8 @@ export function renderInstruction(template, ctx = {}) {
|
|
|
99
109
|
out += resolvePath(m[3].trim(), ctx);
|
|
100
110
|
}
|
|
101
111
|
// 独占一行的段落标记:连同紧跟的换行一起消费(丢弃段不留空行;保留段不多空行)。
|
|
102
|
-
//
|
|
103
|
-
if (
|
|
112
|
+
// 只吞"标记之后"的换行——标记之前的换行天然属于上一行。
|
|
113
|
+
if ((m[1] === '#' || m[1] === '/') && src[consumed] === '\n') consumed += 1;
|
|
104
114
|
last = consumed;
|
|
105
115
|
TOKEN_RE.lastIndex = consumed;
|
|
106
116
|
}
|
|
@@ -183,10 +183,12 @@ export default {
|
|
|
183
183
|
summary: { type: 'string', hint: '当前现状(agent 状态,展示给用户)' },
|
|
184
184
|
timeout: { type: 'number', hint: '阻塞上限(秒);仅项目开启「持续 get」时有意义' },
|
|
185
185
|
'no-open': { type: 'boolean', hint: '不自动打开浏览器(测试用)' },
|
|
186
|
+
param: { type: 'array', hint: '外部参数(平面扩展):k=v,可重复或逗号分隔;进交付模板 ctx,模板里 {{k}} / {{params.k}} 取' },
|
|
186
187
|
},
|
|
187
188
|
run: async (ctx) => {
|
|
188
189
|
const { getTask } = await import('../tasktool/get.js');
|
|
189
|
-
|
|
190
|
+
const { parseParams } = await import('../tasktool/params.js');
|
|
191
|
+
return getTask({ cwd: ctx.cwd, summary: ctx.summary, timeoutSec: ctx.timeout, open: !ctx['no-open'], params: parseParams(ctx.param) });
|
|
190
192
|
},
|
|
191
193
|
render: renderWait, // 返回形状与 wait 同构(ok/timeout),复用同一份人读渲染
|
|
192
194
|
},
|
|
@@ -577,6 +579,11 @@ export default {
|
|
|
577
579
|
suffixList: { type: 'array', hint: '同 --suffix-list(驼峰写法,HTTP body 用)' },
|
|
578
580
|
'ack-list': { type: 'array', hint: '整体替换 ack 完成总结提示词列表(多条)' },
|
|
579
581
|
ackList: { type: 'array', hint: '同 --ack-list(驼峰写法,HTTP body 用)' },
|
|
582
|
+
'delivery-template': {
|
|
583
|
+
type: 'string',
|
|
584
|
+
hint: '交付上下文模板(原始提示词之外那段「组/项目关键路径」怎么写)。占位符:{{task.text}} {{repo.name}} {{repo.intro}} {{repo.introPath}} {{repo.docs}} {{group.name}} {{group.desc}} {{group.intro}} {{group.introPath}} {{group.note}} {{group.peers}} {{group.docs}} {{source}} {{summary}} {{cwd}} {{name}};段落 {{#repo}}…{{/repo}}、{{#group}}…{{/group}};外部参数 {{params.k}} 与顶层 {{k}}。置空 = 恢复内置默认模板',
|
|
585
|
+
},
|
|
586
|
+
'reset-delivery-template': { type: 'boolean', hint: '恢复内置默认交付上下文模板' },
|
|
580
587
|
},
|
|
581
588
|
run: async (ctx) => {
|
|
582
589
|
const patch = { timeoutSec: ctx.timeout };
|
|
@@ -613,6 +620,9 @@ export default {
|
|
|
613
620
|
} else if (ctx['no-suffix']) patch.taskSuffix = [];
|
|
614
621
|
else if (ctx['reset-suffix']) patch.taskSuffix = [service.DEFAULT_TASK_SUFFIX];
|
|
615
622
|
else if (ctx.suffix !== undefined) patch.taskSuffix = ctx.suffix;
|
|
623
|
+
// 交付上下文模板(任务 #62):置空 = 恢复内置默认模板
|
|
624
|
+
if (ctx['delivery-template'] !== undefined) patch.deliveryTemplate = ctx['delivery-template'];
|
|
625
|
+
if (ctx['reset-delivery-template']) patch.deliveryTemplate = '';
|
|
616
626
|
return service.updateSettings(patch);
|
|
617
627
|
},
|
|
618
628
|
render: (s) => {
|
|
@@ -737,15 +747,18 @@ export default {
|
|
|
737
747
|
summary: SUMMARY,
|
|
738
748
|
timeout: { type: 'number', hint: '阻塞上限(秒);缺省用页面配置(推荐 180,最大 600)' },
|
|
739
749
|
'no-open': { type: 'boolean', hint: '不自动打开浏览器(测试用)' },
|
|
750
|
+
param: { type: 'array', hint: '外部参数(平面扩展):k=v,可重复或逗号分隔;进交付模板 ctx,模板里 {{k}} / {{params.k}} 取' },
|
|
740
751
|
},
|
|
741
752
|
run: async (ctx) => {
|
|
742
753
|
// wait 编排已迁 tasktool/wait.js(任务工具语义归 tasktool;命令名不变)
|
|
743
754
|
const { waitForTask } = await import('../tasktool/wait.js');
|
|
755
|
+
const { parseParams } = await import('../tasktool/params.js');
|
|
744
756
|
return waitForTask({
|
|
745
757
|
cwd: ctx.cwd,
|
|
746
758
|
summary: ctx.summary,
|
|
747
759
|
timeoutSec: ctx.timeout,
|
|
748
760
|
open: !ctx['no-open'],
|
|
761
|
+
params: parseParams(ctx.param),
|
|
749
762
|
});
|
|
750
763
|
},
|
|
751
764
|
render: renderWait,
|
|
@@ -58,6 +58,17 @@ export function joinTaskSuffix(v) {
|
|
|
58
58
|
// 任何东西,默认交付逐字不变。
|
|
59
59
|
// 2. 它不是「收尾指令」,是「总结格式要求」——所以不拼进 task.text,只进
|
|
60
60
|
// instruction 字段。
|
|
61
|
+
/** 交付上下文模板(任务 #62)的长度上限——防把整本书塞进设置。 */
|
|
62
|
+
export const MAX_DELIVERY_TEMPLATE_LEN = 8000;
|
|
63
|
+
|
|
64
|
+
/** 交付上下文模板:空串 = 用内置默认模板(不关掉这一段)。 */
|
|
65
|
+
export function clampDeliveryTemplate(v) {
|
|
66
|
+
if (v === undefined || v === null) return '';
|
|
67
|
+
const s = String(v).trim();
|
|
68
|
+
if (!s) return '';
|
|
69
|
+
return s.slice(0, MAX_DELIVERY_TEMPLATE_LEN);
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
export function clampAckPromptList(v) {
|
|
62
73
|
if (v === undefined || v === null) return [];
|
|
63
74
|
const raw = Array.isArray(v) ? v : [v];
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
normalizeSummary,
|
|
13
13
|
topicOf,
|
|
14
14
|
} from './store-io.js';
|
|
15
|
-
import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList } from './task-templates.js';
|
|
15
|
+
import { DEFAULT_TASK_SUFFIX, clampTaskSuffixList, clampAckPromptList, clampDeliveryTemplate } from './task-templates.js';
|
|
16
16
|
import { foreignResolver, isPending, topicView } from './task-view.js';
|
|
17
17
|
import { deleteGuard } from './deletion.js';
|
|
18
18
|
import { repoContextIndex, repoCtxOf } from './repo-ctx.js';
|
|
@@ -35,6 +35,9 @@ function settingsView(s) {
|
|
|
35
35
|
suffixEnabled: suffixList.length > 0,
|
|
36
36
|
// ack 完成总结提示词(多条):缺省空 = 不追加(默认交付逐字不变)
|
|
37
37
|
ackPromptList: clampAckPromptList(s && s.ackPrompt),
|
|
38
|
+
// 交付上下文模板(任务 #62):原始提示词之外的那段「组 / 项目关键路径」
|
|
39
|
+
// 怎么写。空串 = 用内置默认模板(不是关掉——关掉就丢上下文了)。
|
|
40
|
+
deliveryTemplate: clampDeliveryTemplate(s && s.deliveryTemplate),
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -125,11 +128,12 @@ export async function pruneTopics({ allFinished = false, dryRun = false } = {})
|
|
|
125
128
|
// 也兼容 string(旧单条写法,整体算一条)。条数上限 10、单条 ≤2000 字;
|
|
126
129
|
// 含 {{ 占位符 → 渲染进返回的 instruction 字段;纯文本 → 追加到 task.text 末尾;
|
|
127
130
|
// 传 '' / [] 关闭、不传保持不变。
|
|
128
|
-
export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt } = {}) {
|
|
131
|
+
export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt, deliveryTemplate } = {}) {
|
|
129
132
|
const hasTimeout = timeoutSec !== undefined && timeoutSec !== null;
|
|
130
133
|
const hasSuffix = taskSuffix !== undefined;
|
|
131
134
|
const hasAck = ackPrompt !== undefined;
|
|
132
|
-
|
|
135
|
+
const hasDelivery = deliveryTemplate !== undefined;
|
|
136
|
+
if (!hasTimeout && !hasSuffix && !hasAck && !hasDelivery) {
|
|
133
137
|
throw badInput(
|
|
134
138
|
'请至少指定一项:--timeout <秒>,或 --suffix "<收尾指令模板>"(--no-suffix 关闭、--reset-suffix 恢复默认、--suffix-add/--suffix-remove 按条增删),或 --ack "<ack 提示词>"'
|
|
135
139
|
);
|
|
@@ -145,6 +149,7 @@ export async function updateSettings({ timeoutSec, taskSuffix, ackPrompt } = {})
|
|
|
145
149
|
}
|
|
146
150
|
if (hasSuffix) next.taskSuffix = clampTaskSuffixList(taskSuffix);
|
|
147
151
|
if (hasAck) next.ackPrompt = clampAckPromptList(ackPrompt);
|
|
152
|
+
if (hasDelivery) next.deliveryTemplate = clampDeliveryTemplate(deliveryTemplate);
|
|
148
153
|
store.settings = next;
|
|
149
154
|
await saveStore(store);
|
|
150
155
|
return settingsView(store.settings);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// tasktool/delivery-template.js —— **交付提示词的模板化**(任务 #62)。
|
|
2
|
+
//
|
|
3
|
+
// 交付给 agent 的提示词 = **原始提示词(task.text 原文)** + **项目组的关键路径**
|
|
4
|
+
// (组 / 项目的介绍 md 与可读路径)。组与项目的描述本身就是本地 markdown,
|
|
5
|
+
// 所以「关键路径」是磁盘上的真实文件路径——agent 拿到就能读盘。
|
|
6
|
+
//
|
|
7
|
+
// 改造前那段「上下文封装」是硬编码的字符串拼装(tasktool/groupctx.js)。
|
|
8
|
+
// 现在它是一份**模板 + 占位符**:
|
|
9
|
+
// - 默认模板(DEFAULT_DELIVERY_TEMPLATE)复现改造前的输出口径;
|
|
10
|
+
// - 模板存在设置里(settings.deliveryTemplate),设置面板「提示词 / 模板」可见可改;
|
|
11
|
+
// - 引擎支持**平面扩展**:外部参数(--param k=v)平铺进 ctx,模板里 {{k}} 直接取。
|
|
12
|
+
//
|
|
13
|
+
// ctx 形状(占位符按 `.` 分段走 ctx,缺失一律空串——见 core/instruction-template.js):
|
|
14
|
+
// {{task.text}} 原始提示词(任务正文,逐字)
|
|
15
|
+
// {{task.id}} 任务编号
|
|
16
|
+
// {{repo.name}} {{repo.intro}} {{repo.introPath}} 项目介绍(正文 + 可读路径)
|
|
17
|
+
// {{repo.docs}} 项目登记的补充文档(可读路径列表,多行)
|
|
18
|
+
// {{group.name}} {{group.desc}} {{group.intro}} {{group.introPath}} {{group.note}}
|
|
19
|
+
// {{group.peers}} {{group.docs}} 组内成员 / 组绑定参考文件
|
|
20
|
+
// {{groups}} 多组时其余组的概览(多行)
|
|
21
|
+
// {{source}} {{summary}} {{cwd}} {{name}} {{goal.*}}
|
|
22
|
+
// {{params.k}} 与顶层 {{k}} 外部参数(平面扩展;内建同名键不被覆盖)
|
|
23
|
+
//
|
|
24
|
+
// 段落:{{#repo}}…{{/repo}} / {{#group}}…{{/group}} —— ctx 里没这个键就整段丢弃
|
|
25
|
+
// (项目级任务没有组,那一段就不出现)。
|
|
26
|
+
import { renderInstruction } from '../../core/instruction-template.js';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 默认交付上下文模板。复现改造前 renderGroupContext 的输出口径:
|
|
30
|
+
* 〔项目介绍 · X〕(路径):正文
|
|
31
|
+
* 〔项目组上下文 · Y〕组定位 / 组介绍 / 本项目位置 / 组内成员 / 组绑定参考文件
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_DELIVERY_TEMPLATE = [
|
|
34
|
+
'{{#repo}}〔项目介绍 · {{repo.name}}〕({{repo.introPath}}):',
|
|
35
|
+
'{{repo.intro}}',
|
|
36
|
+
'{{#repoDocs}}',
|
|
37
|
+
'项目补充文档(可直接读取):',
|
|
38
|
+
'{{repo.docs}}',
|
|
39
|
+
'{{/repoDocs}}',
|
|
40
|
+
'{{/repo}}',
|
|
41
|
+
'{{#group}}〔项目组上下文 · {{group.name}}〕',
|
|
42
|
+
'组定位:{{group.desc}}',
|
|
43
|
+
'组介绍({{group.introPath}}):',
|
|
44
|
+
'{{group.intro}}',
|
|
45
|
+
'本项目在组里的位置:{{group.note}}',
|
|
46
|
+
'{{#groupPeers}}',
|
|
47
|
+
'组内成员:',
|
|
48
|
+
'{{group.peers}}',
|
|
49
|
+
'{{/groupPeers}}',
|
|
50
|
+
'{{#groupDocs}}',
|
|
51
|
+
'组绑定参考文件(可直接读取):',
|
|
52
|
+
'{{group.docs}}',
|
|
53
|
+
'{{/groupDocs}}',
|
|
54
|
+
'{{/group}}',
|
|
55
|
+
].join('\n');
|
|
56
|
+
|
|
57
|
+
/** 「补充文档 / 参考文件」列表的可读路径行(每行一条,带标签与说明)。 */
|
|
58
|
+
function linkLines(links) {
|
|
59
|
+
return (links || [])
|
|
60
|
+
.map((d) => {
|
|
61
|
+
const p = d.abs || d.rel || d.path || '';
|
|
62
|
+
return ` - ${p}${d.tag ? ` [${d.tag}]` : ''}${d.note ? ` # ${d.note}` : ''}`;
|
|
63
|
+
})
|
|
64
|
+
.join('\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 组内成员行:名字 + 组内描述。 */
|
|
68
|
+
function peerLines(peers) {
|
|
69
|
+
return (peers || []).map((p) => ` - ${p.name}:${p.note || '(无组内描述)'}`).join('\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 组上下文 → 模板 ctx(数据,不含成文措辞——措辞归模板)。
|
|
74
|
+
* @param {object} groupCtx readGroupContext 的返回值
|
|
75
|
+
* @returns {object} ctx 片段
|
|
76
|
+
*/
|
|
77
|
+
export function deliveryCtxOf(groupCtx) {
|
|
78
|
+
const repo = groupCtx && groupCtx.repo ? groupCtx.repo : null;
|
|
79
|
+
const groups = (groupCtx && groupCtx.groups) || [];
|
|
80
|
+
const g = groups[0] || null;
|
|
81
|
+
const repoDocs = linkLines(repo && repo.docLinks);
|
|
82
|
+
const peers = g ? peerLines(g.peers) : '';
|
|
83
|
+
const gdocs = g ? linkLines(g.docLinks) : '';
|
|
84
|
+
const others = groups
|
|
85
|
+
.slice(1)
|
|
86
|
+
.map((x) => ` - ${x.name}${x.desc ? `(${x.desc})` : ''}${x.intro && x.intro.path ? ` ${x.intro.path}` : ''}`)
|
|
87
|
+
.join('\n');
|
|
88
|
+
return {
|
|
89
|
+
repo: repo && repo.intro && repo.intro.body
|
|
90
|
+
? {
|
|
91
|
+
name: repo.name || repo.key || '',
|
|
92
|
+
key: repo.key || '',
|
|
93
|
+
intro: repo.intro.body || '',
|
|
94
|
+
introPath: repo.intro.path || '',
|
|
95
|
+
docs: repoDocs,
|
|
96
|
+
}
|
|
97
|
+
: null,
|
|
98
|
+
repoDocs: repoDocs ? {} : null,
|
|
99
|
+
group: g
|
|
100
|
+
? {
|
|
101
|
+
name: g.name || '',
|
|
102
|
+
key: g.key || '',
|
|
103
|
+
desc: g.desc || '',
|
|
104
|
+
intro: (g.intro && g.intro.body) || '',
|
|
105
|
+
introPath: (g.intro && g.intro.path) || '',
|
|
106
|
+
note: g.note || '',
|
|
107
|
+
// 段内容放在 group 里(占位符 {{group.peers}} 从根 ctx 取),
|
|
108
|
+
// groupPeers / groupDocs 只是**闸门**(有没有就整段在不在)。
|
|
109
|
+
peers,
|
|
110
|
+
docs: gdocs,
|
|
111
|
+
}
|
|
112
|
+
: null,
|
|
113
|
+
groupPeers: peers ? {} : null,
|
|
114
|
+
groupDocs: gdocs ? {} : null,
|
|
115
|
+
groups: others ? { text: others } : null,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 组装交付 ctx:内建字段 + 组上下文片段 + 外部参数(平面扩展)。
|
|
121
|
+
* @param {object} p
|
|
122
|
+
* @param {object|null} p.task 任务行
|
|
123
|
+
* @param {object|null} p.goal timegoal 上下文
|
|
124
|
+
* @param {string} [p.source] local / global
|
|
125
|
+
* @param {string} [p.summary] 等待方现状
|
|
126
|
+
* @param {string} [p.cwd] 等待方目录
|
|
127
|
+
* @param {string} [p.name] 等待方名字
|
|
128
|
+
* @param {object|null} [p.groupCtx] readGroupContext 的返回值
|
|
129
|
+
* @param {object} [p.params] 外部参数(平面扩展:顶层可直接 {{k}},也可 {{params.k}})
|
|
130
|
+
* @returns {object} ctx
|
|
131
|
+
*/
|
|
132
|
+
export function buildDeliveryCtx({ task, goal, source, summary, cwd, name, groupCtx, params } = {}) {
|
|
133
|
+
const base = {
|
|
134
|
+
task: task ? { id: task.id, text: String(task.text || '') } : null,
|
|
135
|
+
goal: goal || null,
|
|
136
|
+
source: source || '',
|
|
137
|
+
summary: summary || '',
|
|
138
|
+
cwd: cwd || '',
|
|
139
|
+
name: name || '',
|
|
140
|
+
};
|
|
141
|
+
const extra = deliveryCtxOf(groupCtx);
|
|
142
|
+
const flat = {};
|
|
143
|
+
for (const [k, v] of Object.entries(params || {})) {
|
|
144
|
+
if (k in base || k in extra) continue; // 内建键不被外部参数覆盖
|
|
145
|
+
flat[k] = v;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
...base,
|
|
149
|
+
...extra,
|
|
150
|
+
params: { ...(params || {}) },
|
|
151
|
+
...flat,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 渲染交付上下文模板。空模板 / 渲染异常 → 返回空串(fail-open:上下文是增强,
|
|
157
|
+
* 不是领取的前提)。
|
|
158
|
+
* @param {string} tpl 模板(缺省用默认模板)
|
|
159
|
+
* @param {object} ctx buildDeliveryCtx 的返回值
|
|
160
|
+
* @returns {string}
|
|
161
|
+
*/
|
|
162
|
+
export function renderDelivery(tpl, ctx) {
|
|
163
|
+
const template = String(tpl == null || tpl === '' ? DEFAULT_DELIVERY_TEMPLATE : tpl);
|
|
164
|
+
try {
|
|
165
|
+
return renderInstruction(template, ctx || {});
|
|
166
|
+
} catch {
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -16,7 +16,7 @@ import { waitForTask } from './wait.js';
|
|
|
16
16
|
import { getLoopForCwd, DEFAULT_GET_LOOP_TEMPLATE } from './getloop.js';
|
|
17
17
|
import { hasTemplateMarkers, renderInstruction } from '../../core/instruction-template.js';
|
|
18
18
|
|
|
19
|
-
export async function getTask({ cwd, summary, timeoutSec, open = true } = {}) {
|
|
19
|
+
export async function getTask({ cwd, summary, timeoutSec, open = true, params } = {}) {
|
|
20
20
|
const loop = await getLoopForCwd(cwd);
|
|
21
21
|
const r = await waitForTask({
|
|
22
22
|
cwd,
|
|
@@ -26,6 +26,7 @@ export async function getTask({ cwd, summary, timeoutSec, open = true } = {}) {
|
|
|
26
26
|
timeoutSec: timeoutSec ?? (loop.enabled ? loop.waitMinutes * 60 : undefined),
|
|
27
27
|
open,
|
|
28
28
|
instant: !loop.enabled,
|
|
29
|
+
params: params || {}, // 外部参数(平面扩展)进交付模板
|
|
29
30
|
});
|
|
30
31
|
if (r.status !== 'ok' || !r.task) return r;
|
|
31
32
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// tasktool/params.js —— **外部参数(平面扩展)**的解析(任务 #62)。
|
|
2
|
+
//
|
|
3
|
+
// 领取任务的引擎(get / wait)支持往交付模板的 ctx 里塞**任意**外部参数:
|
|
4
|
+
// nx-kv localtask wait --cwd "<dir>" --param lane=payment --param retry=2
|
|
5
|
+
//
|
|
6
|
+
// 模板里两种取法都能用:
|
|
7
|
+
// {{lane}} 平铺(顶层)——外部参数直接占一个键
|
|
8
|
+
// {{params.lane}} 归拢(params 子树)——与内建字段(task/goal/source…)不打架
|
|
9
|
+
//
|
|
10
|
+
// 内建同名键**不被外部参数覆盖**(否则一条 --param task=… 就能把任务正文顶掉)。
|
|
11
|
+
//
|
|
12
|
+
// 解析口径:'k=v' 列表(可重复给、可逗号分隔);没有 '=' 的项忽略;键与值都去空白;
|
|
13
|
+
// 值可以为空(k= → 空串)。
|
|
14
|
+
/**
|
|
15
|
+
* 外部参数列表 → 普通对象。
|
|
16
|
+
* @param {string[]|string|undefined|null} list 'k=v' 列表(可重复 / 逗号分隔)
|
|
17
|
+
* @returns {Record<string, string>} 参数表
|
|
18
|
+
*/
|
|
19
|
+
export function parseParams(list) {
|
|
20
|
+
const out = {};
|
|
21
|
+
const items = Array.isArray(list) ? list : list === undefined || list === null ? [] : [list];
|
|
22
|
+
for (const item of items) {
|
|
23
|
+
for (const part of String(item).split(',')) {
|
|
24
|
+
const s = part.trim();
|
|
25
|
+
if (!s) continue;
|
|
26
|
+
const i = s.indexOf('=');
|
|
27
|
+
if (i <= 0) continue; // 没有键(= 开头)或没有 '=' 的项忽略
|
|
28
|
+
const k = s.slice(0, i).trim();
|
|
29
|
+
if (!k) continue;
|
|
30
|
+
out[k] = s.slice(i + 1).trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// 同模块的 timegoal.js(探针只读 + 交付时刻的目标上下文)。
|
|
11
11
|
import { DEFAULT_PORT } from '../../core/paths.js';
|
|
12
12
|
import { formatGoalTiming, hasTemplateMarkers, renderInstruction } from '../../core/instruction-template.js';
|
|
13
|
+
import { DEFAULT_DELIVERY_TEMPLATE, buildDeliveryCtx, renderDelivery } from './delivery-template.js';
|
|
13
14
|
import {
|
|
14
15
|
clampTaskSuffix,
|
|
15
16
|
clampTimeoutSec,
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
} from '../localtask/service.js';
|
|
35
36
|
import { ensureMainPanel, deepLinkUrl, escortPanel } from './panel-escort.js';
|
|
36
37
|
import { ensureTaskGoal } from './taskgoal.js';
|
|
37
|
-
import { readGroupContext
|
|
38
|
+
import { readGroupContext } from './groupctx.js';
|
|
38
39
|
import { annotateTaskDelivery, attachmentInstruction } from './attach.js';
|
|
39
40
|
import * as timegoal from './timegoal.js';
|
|
40
41
|
|
|
@@ -112,7 +113,7 @@ function withTaskSuffix(task, suffix) {
|
|
|
112
113
|
// (模板原文若追加进正文会把 {{...}} 漏进任务文本);
|
|
113
114
|
// ''(关闭) → 只回任务。
|
|
114
115
|
// 任何异常都降级为「只回任务」——wait 绝不能因渲染挂掉(与探针同一条 fail-open 纪律)。
|
|
115
|
-
async function buildTaskDelivery(task, suffix, { source, summary, cwd, name, topicKey } = {}) {
|
|
116
|
+
async function buildTaskDelivery(task, suffix, { source, summary, cwd, name, topicKey, params } = {}) {
|
|
116
117
|
// 多条收尾指令(settings.taskSuffix 存 string[])先按空行拼成单串再分流;
|
|
117
118
|
// 兼容旧单条 string(joinTaskSuffix 对 string 原样算一条)。
|
|
118
119
|
const tpl = joinTaskSuffix(suffix);
|
|
@@ -155,7 +156,17 @@ async function buildTaskDelivery(task, suffix, { source, summary, cwd, name, top
|
|
|
155
156
|
// 项目组上下文(组概念 + 本项目位置 + 兄弟成员 + 参考文件地址):
|
|
156
157
|
// 只进 instruction,**task.text 保持库存原文**——todo 的口径是
|
|
157
158
|
// 「封装对应的提示词保持在原本的提示此任务下面对上下文环境进行一个封装」。
|
|
158
|
-
|
|
159
|
+
//
|
|
160
|
+
// **模板化**(任务 #62):这段封装是一份模板 + 占位符(默认模板复现旧口径,
|
|
161
|
+
// 设置里可改,面板「提示词 / 模板」可见);外部参数(--param k=v)平铺进
|
|
162
|
+
// ctx,模板里 {{k}} 直接取——引擎支持平面扩展。
|
|
163
|
+
const groupCtx = await readGroupContext(cwd);
|
|
164
|
+
const settings = await getSettings().catch(() => null);
|
|
165
|
+
const deliveryTpl = (settings && settings.deliveryTemplate) || DEFAULT_DELIVERY_TEMPLATE;
|
|
166
|
+
const groupText = renderDelivery(
|
|
167
|
+
deliveryTpl,
|
|
168
|
+
buildDeliveryCtx({ task, goal, source, summary, cwd, name, groupCtx, params }),
|
|
169
|
+
);
|
|
159
170
|
|
|
160
171
|
// 〔ack 完成总结格式要求〕:settings.ackPrompt(多条,设置面板「提示词 / 模板」
|
|
161
172
|
// 一栏可配)——agent 领取时就拿到「完成总结该按什么格式写」的提示词。
|
|
@@ -215,7 +226,10 @@ async function buildTaskDelivery(task, suffix, { source, summary, cwd, name, top
|
|
|
215
226
|
// coversBody = 模板是否包含 {{task.text}}(即 instruction 是否自包含任务正文)。
|
|
216
227
|
// 由服务端判定而不是 CLI 端做子串猜测——短任务文本可能碰巧是指令的子串,
|
|
217
228
|
// 子串启发会误吞正文块的显示。
|
|
218
|
-
|
|
229
|
+
// **交付上下文模板也算**:它在正文之外另起一段,自带原文时同样覆盖正文块。
|
|
230
|
+
const coversBody =
|
|
231
|
+
(hasTemplateMarkers(tpl) && /\{\{\s*task\.text\s*\}\}/.test(tpl)) ||
|
|
232
|
+
(hasTemplateMarkers(deliveryTpl) && /\{\{\s*task\.text\s*\}\}/.test(deliveryTpl));
|
|
219
233
|
return {
|
|
220
234
|
task,
|
|
221
235
|
instruction: full,
|
|
@@ -246,6 +260,7 @@ export async function waitForTask({
|
|
|
246
260
|
timeoutMs,
|
|
247
261
|
open = true,
|
|
248
262
|
onReady,
|
|
263
|
+
params = {}, // 外部参数(平面扩展):进交付模板的 ctx(--param k=v)
|
|
249
264
|
instant = false, // get 的「直接领」形态:没有 pending 立即空手而回,不开窗不阻塞
|
|
250
265
|
} = {}) {
|
|
251
266
|
const { key, cwd, name } = normalizeCwd(rawCwd);
|
|
@@ -269,7 +284,7 @@ export async function waitForTask({
|
|
|
269
284
|
// 1. 主题队列已有 pending → 立即取走,不开窗、不阻塞;记录本轮完成总结
|
|
270
285
|
const queued = await consumeFirstPending(key, summary, by);
|
|
271
286
|
if (queued) {
|
|
272
|
-
const delivery = await buildTaskDelivery(queued, suffix, { source: 'local', summary, cwd, name, topicKey: key });
|
|
287
|
+
const delivery = await buildTaskDelivery(queued, suffix, { source: 'local', summary, cwd, name, topicKey: key, params });
|
|
273
288
|
return { status: 'ok', key, cwd, name, summary, ...delivery, queued: true, source: 'local', repo: repoCtx };
|
|
274
289
|
}
|
|
275
290
|
|
|
@@ -286,7 +301,7 @@ export async function waitForTask({
|
|
|
286
301
|
if (fromGlobal) {
|
|
287
302
|
// 全局池投递渲染的仍是**等待方目录**的 goal——目标绑定在等待中的 agent 目录上,
|
|
288
303
|
// 与任务来自哪个队列无关。
|
|
289
|
-
const delivery = await buildTaskDelivery(fromGlobal, suffix, { source: 'global', summary, cwd, name, topicKey: key });
|
|
304
|
+
const delivery = await buildTaskDelivery(fromGlobal, suffix, { source: 'global', summary, cwd, name, topicKey: key, params });
|
|
290
305
|
return {
|
|
291
306
|
status: 'ok',
|
|
292
307
|
key,
|
|
@@ -404,7 +419,7 @@ export async function waitForTask({
|
|
|
404
419
|
// 只对拿到任务的结果生效——timeout/goal_expired/cancelled 的返回形状是钉死的契约,不动。
|
|
405
420
|
const delivery =
|
|
406
421
|
r.kind === 'task'
|
|
407
|
-
? await buildTaskDelivery(r.task, suffix, { source: r.source || 'local', summary, cwd, name, topicKey: key })
|
|
422
|
+
? await buildTaskDelivery(r.task, suffix, { source: r.source || 'local', summary, cwd, name, topicKey: key, params })
|
|
408
423
|
: null;
|
|
409
424
|
result =
|
|
410
425
|
r.kind === 'timeout'
|
|
@@ -19,6 +19,7 @@ const TABS = [
|
|
|
19
19
|
{ id: 'template', label: '任务模板' },
|
|
20
20
|
{ id: 'suffix', label: '回调提示词' },
|
|
21
21
|
{ id: 'ack', label: 'ack 总结' },
|
|
22
|
+
{ id: 'delivery', label: '交付上下文' },
|
|
22
23
|
];
|
|
23
24
|
|
|
24
25
|
/** 全局提示词列表(回调 / ack 共用一套读写) */
|
|
@@ -197,6 +198,87 @@ function TemplateSlots({ openTemplates }) {
|
|
|
197
198
|
);
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
/**
|
|
202
|
+
* 交付上下文模板(任务 #62):原始提示词之外那段「组 / 项目关键路径」怎么写。
|
|
203
|
+
* 面板上**看得见、改得动**——占位符清单直接列在旁边,不靠记忆。
|
|
204
|
+
*/
|
|
205
|
+
function DeliveryTemplate() {
|
|
206
|
+
const toast = useToast();
|
|
207
|
+
const [text, setText] = useState(null); // null = 还没读
|
|
208
|
+
const [busy, setBusy] = useState(false);
|
|
209
|
+
|
|
210
|
+
const load = useCallback(() => {
|
|
211
|
+
api('/api/localtasks')
|
|
212
|
+
.then((d) => setText(d?.settings?.deliveryTemplate ?? ''))
|
|
213
|
+
.catch((e) => toast('读取失败:' + (e.message || e)));
|
|
214
|
+
}, [toast]);
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
load();
|
|
218
|
+
}, [load]);
|
|
219
|
+
|
|
220
|
+
const save = async () => {
|
|
221
|
+
if (busy) return;
|
|
222
|
+
setBusy(true);
|
|
223
|
+
try {
|
|
224
|
+
const d = await api('/api/localtasks/setting', {
|
|
225
|
+
method: 'PATCH',
|
|
226
|
+
body: { deliveryTemplate: text ?? '' },
|
|
227
|
+
});
|
|
228
|
+
setText(d?.deliveryTemplate ?? '');
|
|
229
|
+
toast('已保存交付上下文模板');
|
|
230
|
+
} catch (e) {
|
|
231
|
+
toast(String(e.message || e));
|
|
232
|
+
} finally {
|
|
233
|
+
setBusy(false);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const reset = async () => {
|
|
238
|
+
if (busy) return;
|
|
239
|
+
setBusy(true);
|
|
240
|
+
try {
|
|
241
|
+
const d = await api('/api/localtasks/setting', {
|
|
242
|
+
method: 'PATCH',
|
|
243
|
+
body: { deliveryTemplate: '' },
|
|
244
|
+
});
|
|
245
|
+
setText(d?.deliveryTemplate ?? '');
|
|
246
|
+
toast('已恢复内置默认模板');
|
|
247
|
+
} catch (e) {
|
|
248
|
+
toast(String(e.message || e));
|
|
249
|
+
} finally {
|
|
250
|
+
setBusy(false);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<div className="setp-suffix">
|
|
256
|
+
<div className="setp-row">
|
|
257
|
+
<span>交付上下文模板(原始提示词之外的组 / 项目关键路径)</span>
|
|
258
|
+
<button type="button" className="btn ghost sm" onClick={save} disabled={busy || text === null}>
|
|
259
|
+
保存
|
|
260
|
+
</button>
|
|
261
|
+
<button type="button" className="btn ghost sm" onClick={reset} disabled={busy || text === null}>
|
|
262
|
+
恢复默认
|
|
263
|
+
</button>
|
|
264
|
+
</div>
|
|
265
|
+
<textarea
|
|
266
|
+
className="setp-area"
|
|
267
|
+
rows={12}
|
|
268
|
+
value={text ?? ''}
|
|
269
|
+
placeholder={'留空 = 用内置默认模板'}
|
|
270
|
+
disabled={text === null}
|
|
271
|
+
onChange={(e) => setText(e.target.value)}
|
|
272
|
+
/>
|
|
273
|
+
<details className="setp-tpl-preview">
|
|
274
|
+
<summary>可用占位符</summary>
|
|
275
|
+
<pre className="setp-tpl-preview-body">
|
|
276
|
+
{'{{task.text}} 原始提示词(正文逐字)\n{{repo.name}} {{repo.intro}} {{repo.introPath}} {{repo.docs}} 项目介绍与补充文档\n{{group.name}} {{group.desc}} {{group.intro}} {{group.introPath}} {{group.note}} {{group.peers}} {{group.docs}}\n{{source}} {{summary}} {{cwd}} {{name}} {{goal.*}}\n{{params.k}} / {{k}} 外部参数(--param k=v 平铺传入)\n段落:{{#repo}}…{{/repo}}、{{#group}}…{{/group}}(ctx 里没有就整段不出现)'}
|
|
277
|
+
</pre>
|
|
278
|
+
</details>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
200
282
|
export default function PromptsSection({ openTemplates }) {
|
|
201
283
|
const [tab, setTab] = useState('template');
|
|
202
284
|
|
|
@@ -233,6 +315,7 @@ export default function PromptsSection({ openTemplates }) {
|
|
|
233
315
|
offText="已关闭 ack 提示词"
|
|
234
316
|
/>
|
|
235
317
|
)}
|
|
318
|
+
{tab === 'delivery' && <DeliveryTemplate />}
|
|
236
319
|
</div>
|
|
237
320
|
</div>
|
|
238
321
|
);
|