nx-kv 0.43.0 → 0.44.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.
- package/CHANGELOG.md +23 -0
- package/package.json +1 -1
- package/src/modules/localtask/task-ops.js +17 -4
- package/src/modules/tasktool/index.js +12 -5
- package/src/modules/tasktool/plugins/goal-template.js +86 -0
- package/src/modules/tasktool/plugins/taskgoal-store.js +61 -43
- package/src/modules/tasktool/plugins/timegoal-task-store.js +40 -3
- package/src/modules/tasktool/wait.js +18 -2
- package/src/shared/prompt-blocks.js +21 -0
- package/src/web/frontend/page/dir/task-actions.js +13 -5
- package/src/web/frontend/page/dir/task-goal-section.jsx +29 -24
- package/src/web/frontend/page/dir/task-goal.js +6 -1
- package/src/web/frontend/page/dir/task.jsx +3 -3
- package/src/web/frontend/page/settings/prompt-template-params.js +38 -2
- package/src/web/public/assets/{Introduction-DAXj7E6q.js → Introduction-CDSLSy0q.js} +1 -1
- package/src/web/public/assets/{bar-KTPTE33i.js → bar-Dp9JHQEk.js} +1 -1
- package/src/web/public/assets/{cloud-CLco1knr.js → cloud-D13Ed3Pg.js} +1 -1
- package/src/web/public/assets/{composer-panel-D3N_wO9r.js → composer-panel-eKhM7jDM.js} +1 -1
- package/src/web/public/assets/{deleted-panel-B6sZddUs.js → deleted-panel-QHsQZ5Ez.js} +1 -1
- package/src/web/public/assets/{dir-DEbQhSfL.js → dir-CiDjsHfd.js} +1 -1
- package/src/web/public/assets/{group-CxqVtyyh.js → group-DDXtRIPf.js} +1 -1
- package/src/web/public/assets/{index-DNB8tgNi.js → index-Dq7eNqAB.js} +2 -2
- package/src/web/public/assets/{md-history-C9vOgGLz.js → md-history-DI1Ukbvc.js} +1 -1
- package/src/web/public/assets/{overview-9nXafXeK.js → overview-BE6O6j51.js} +1 -1
- package/src/web/public/assets/{refs-B5YIZ9SG.js → refs-BkncFh9X.js} +1 -1
- package/src/web/public/assets/{repos-Dbr-i-gg.js → repos-C9wx2OXj.js} +1 -1
- package/src/web/public/assets/{route-crumb-BfRi1GKw.js → route-crumb-_IyS9fTT.js} +1 -1
- package/src/web/public/assets/settings-DlgWRz3r.js +7 -0
- package/src/web/public/assets/{status-tag-p3fo3Hbr.js → status-tag-Bop-R-gG.js} +1 -1
- package/src/web/public/assets/task-CNbU9Z6v.js +11 -0
- package/src/web/public/assets/{templates-BGhPIp0x.js → templates-CK9nH5WD.js} +1 -1
- package/src/web/public/assets/{tool-bar-DpwpQ47h.js → tool-bar-9LD5jcE3.js} +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/assets/settings-B4FvZtu0.js +0 -6
- package/src/web/public/assets/task-CUb7dohw.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.44.0] - 2026-11-10 时间目标提示词模板化 + 特殊功能提示栏(#152)
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **提示词模板新增「特殊功能提示(timegoal)」栏(#152)**:设置 → 提示词模板多一栏
|
|
10
|
+
`goalhint`,只在任务带时间目标时出现;模板里可直接写 `{{task.id}}` / `{{task.text}}`
|
|
11
|
+
与 `{{goal.durationHuman}}` / `{{goal.remainingHuman}}` / `{{goal.reached}}` 等
|
|
12
|
+
上下文变量。默认文案给出任务号、持续时长与剩余/到点状态,不改代码即可 DIY。
|
|
13
|
+
- **时间目标的 check 返回对象带实时上下文(#152)**:`timegoal check` 现在按**当下**
|
|
14
|
+
的 ctx 重新渲染 goal prompt 模板,返回 `promptRendered`(实时渲染)、`task`
|
|
15
|
+
(任务实时原文)、`goal`(剩余/已过/超时/是否到点);CLI 展示「实时渲染」并附
|
|
16
|
+
本轮任务原文,agent 每轮都能拿到最新的任务正文与时间状态。
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **任务级 goal prompt 改为模板落库(#152)**:`goals.prompt` 存的是带占位符的模板,
|
|
21
|
+
领取交付时用领取那一刻的 ctx 渲染(输出与改造前逐字一致),每轮 check 用当下 ctx
|
|
22
|
+
重新渲染;占位符清单见设置页参数速查与 `plugins/goal-template.js` 注释。
|
|
23
|
+
- **附加要求支持领取后动态编辑(#152)**:`localtask update --goal-prompt` 在已领取
|
|
24
|
+
状态下仍可改(服务端放宽为 prompt-only;时长与清除仍锁定,要调整先 reopen)。
|
|
25
|
+
面板同步:已领取时「更多 → 时间目标」保留附加要求输入框,时长改为只读展示;
|
|
26
|
+
改动在下一轮 check / 后续交付即生效。
|
|
27
|
+
|
|
5
28
|
## [0.43.0] - 2026-11-10 任务面板统一 + 进程链折叠 + 文档绑定收口
|
|
6
29
|
|
|
7
30
|
### Removed
|
package/package.json
CHANGED
|
@@ -328,15 +328,17 @@ export async function updateTask({
|
|
|
328
328
|
}
|
|
329
329
|
if (hasGoalInput) {
|
|
330
330
|
const live = topicsRepo.getTopic(host.key).tasks.find((x) => Number(x.id) === Number(hostTask.id));
|
|
331
|
-
if (live.status !== 'pending') {
|
|
332
|
-
throw badInput(`#${want} 已领取或已交付,时间目标声明不可改——要调整先 reopen 重开任务`);
|
|
333
|
-
}
|
|
334
331
|
if (live.deletedAt) throw badInput(`#${want} 已删除,时间目标声明不可改`);
|
|
335
332
|
if (live.migratedTo) throw badInput(`#${want} 已迁出,时间目标声明不可改`);
|
|
333
|
+
// 任务 #87:**附加要求支持动态编辑**——领取后仍可改 prompt(下一轮 check / 交付即生效);
|
|
334
|
+
// 时长与清除仍锁定(领取即计时,起表后声明是既成事实,要调先 reopen)。
|
|
335
|
+
const locked = live.status !== 'pending';
|
|
336
336
|
if (goal.clear) {
|
|
337
|
+
if (locked) throw badInput(`#${want} 已领取或已交付,时间目标不可清除——要调整先 reopen(附加要求可直接改)`);
|
|
337
338
|
tasksRepo.updateTask(host.id, live.id, { timegoal: null });
|
|
338
339
|
goalChanged = 'cleared';
|
|
339
|
-
} else {
|
|
340
|
+
} else if (goal.duration != null) {
|
|
341
|
+
if (locked) throw badInput(`#${want} 已领取或已交付,时长不可改——要调整先 reopen(附加要求可直接改)`);
|
|
340
342
|
// 只改时长没带 prompt → 保留原附加要求;带了(含空串)→ 以传入为准
|
|
341
343
|
const prev = sanitizeTaskGoal(live.timegoal);
|
|
342
344
|
const prompt = goal.prompt != null ? String(goal.prompt).trim() : prev ? prev.prompt : '';
|
|
@@ -344,6 +346,17 @@ export async function updateTask({
|
|
|
344
346
|
timegoal: sanitizeTaskGoal({ duration: goal.duration, prompt }),
|
|
345
347
|
});
|
|
346
348
|
goalChanged = 'set';
|
|
349
|
+
} else {
|
|
350
|
+
// prompt-only:pending / 已领取都放行(动态编辑)
|
|
351
|
+
const prev = sanitizeTaskGoal(live.timegoal);
|
|
352
|
+
if (!prev) {
|
|
353
|
+
throw badInput(`#${want} 还没有时间目标,附加要求无处挂载(先用 --duration 设目标)`);
|
|
354
|
+
}
|
|
355
|
+
const prompt = String(goal.prompt ?? '').trim();
|
|
356
|
+
tasksRepo.updateTask(host.id, live.id, {
|
|
357
|
+
timegoal: sanitizeTaskGoal({ duration: prev.duration, prompt }),
|
|
358
|
+
});
|
|
359
|
+
goalChanged = 'set';
|
|
347
360
|
}
|
|
348
361
|
}
|
|
349
362
|
// 搬家动了两个队列,源/目标都要顶 revision(引擎在途快照对两个都可能过期)
|
|
@@ -64,18 +64,25 @@ function renderCheck(d) {
|
|
|
64
64
|
const status = d.reached
|
|
65
65
|
? `已到点(reached:true)${d.overtimeSec ? ` · 已超时 ${fmtDur(d.overtimeSec)}` : ''}—— 这轮结束后停手并写最终总结`
|
|
66
66
|
: `未到点(reached:false)· 剩余 ${fmtDur(d.remainingSec)}(已用 ${fmtDur(d.elapsedSec)})`;
|
|
67
|
-
// prompt
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
// 任务 #87:任务级 goal 的 prompt 是模板,这里优先展示**本轮实时渲染**的结果
|
|
68
|
+
// (时间变量 + 任务实时原文都按当下取值);目录级 goal 仍回显 store 原文。
|
|
69
|
+
const full = d.promptRendered || d.prompt || '';
|
|
70
|
+
const prompt = full.length > 2000 ? full.slice(0, 2000) + '…' : full;
|
|
71
|
+
const lines = [
|
|
70
72
|
`[timegoal] 主题「${d.name}」`,
|
|
71
73
|
` 状态:${status}`,
|
|
72
74
|
` 截止:${d.deadline}(now=${d.now})`,
|
|
73
75
|
` 现状:${d.summary}`,
|
|
74
76
|
` 完成度 / 下一步:${d.progress}`,
|
|
75
77
|
` 日志:本目录已记录 ${d.logCount} 次检查(${d.checkedAt})`,
|
|
76
|
-
`
|
|
78
|
+
` 本轮提示词(${d.promptRendered ? '实时渲染' : 'store 原文'}):`,
|
|
77
79
|
prompt,
|
|
78
|
-
]
|
|
80
|
+
];
|
|
81
|
+
if (d.task && d.task.text) {
|
|
82
|
+
const text = d.task.text.length > 2000 ? d.task.text.slice(0, 2000) + '…' : d.task.text;
|
|
83
|
+
lines.push(` 任务 #${d.task.id} 实时原文:`, text);
|
|
84
|
+
}
|
|
85
|
+
return lines.join('\n');
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
function renderClear(d) {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// 任务级 timegoal 的提示词模板(任务 #87)——**领取交付**与**每轮 check** 的同源代码。
|
|
2
|
+
//
|
|
3
|
+
// 为什么单独一个文件:领取路径(taskgoal-store)与 check 路径(timegoal-task-store)
|
|
4
|
+
// 都要渲染同一份模板;而这两个模块在 timegoal-store 里已经互相 import,把模板
|
|
5
|
+
// 放在这里可以避免循环依赖,也保证两边变量口径永远一致。
|
|
6
|
+
//
|
|
7
|
+
// goals.prompt 落库的是**模板原文**(占位符保留),渲染发生在:
|
|
8
|
+
// - 领取交付:用「领取那一刻」的 ctx(输出与改造前逐字一致);
|
|
9
|
+
// - 每轮 check:用「当下」的 ctx 重新渲染——于是每轮都能拿到实时时间目标
|
|
10
|
+
// 与**任务实时原文**({{task.text}})。
|
|
11
|
+
//
|
|
12
|
+
// 可用占位符(与提示词模板同一套 Handlebars 引擎):
|
|
13
|
+
// {{task.id}} {{task.text}}
|
|
14
|
+
// {{goal.goalKey}} {{goal.durationHuman}} {{goal.durationSec}}
|
|
15
|
+
// {{goal.startedAt}} {{goal.deadline}} {{goal.remainingHuman}} {{goal.remainingSec}}
|
|
16
|
+
// {{goal.elapsedHuman}} {{goal.elapsedSec}} {{goal.overtimeSec}} {{goal.reached}}
|
|
17
|
+
// {{goal.extra}}
|
|
18
|
+
// {{check.summary}} {{check.progress}} {{check.at}} {{check.count}}(仅 check 渲染时)
|
|
19
|
+
import { formatDuration, renderInstruction } from '../../../core/instruction-template.js';
|
|
20
|
+
|
|
21
|
+
export const TASK_GOAL_PROMPT_TEMPLATE = [
|
|
22
|
+
'本任务带时间目标(领取即计时,持续 {{goal.durationHuman}})。',
|
|
23
|
+
'- 每轮推进先执行:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>" --progress "<进展/下一步>"',
|
|
24
|
+
'- 时间未到不得标记完成——应派出 sub agent 重新提出新的需求,再继续推进。',
|
|
25
|
+
'- check 返回 reached:true 后才允许:nx-kv localtask done --id {{task.id}} --summary "<完成总结>"',
|
|
26
|
+
'{{#if goal.extra}}',
|
|
27
|
+
'附加要求(发布方):',
|
|
28
|
+
'{{goal.extra}}',
|
|
29
|
+
'{{/if}}',
|
|
30
|
+
].join('\n');
|
|
31
|
+
|
|
32
|
+
/** 戳(本地时间字符串)→ epoch ms。 */
|
|
33
|
+
export function stampMsOf(v) {
|
|
34
|
+
if (typeof v === 'number') return v;
|
|
35
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/.exec(String(v || ''));
|
|
36
|
+
if (!m) return NaN;
|
|
37
|
+
return new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]).getTime();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** epoch ms → 本地时间戳(与 timegoal 存储的 stamp 同格式)。 */
|
|
41
|
+
export function stampOfMs(ms) {
|
|
42
|
+
if (!Number.isFinite(Number(ms))) return '';
|
|
43
|
+
const d = new Date(Number(ms));
|
|
44
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
45
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** goal 模板渲染的 ctx(领取 / check 共用同一构造,保证两处变量口径一致)。 */
|
|
49
|
+
export function taskGoalTemplateCtx({ taskId, taskText, goalKey, durationSec, extra, startedAt, deadline, nowMs, check }) {
|
|
50
|
+
const dur = Number(durationSec) || 0;
|
|
51
|
+
const startMs = typeof startedAt === 'number' ? startedAt : stampMsOf(startedAt);
|
|
52
|
+
const endMs = typeof deadline === 'number' ? deadline : stampMsOf(deadline);
|
|
53
|
+
const now = Number(nowMs) || Date.now();
|
|
54
|
+
const remainingSec = Number.isFinite(endMs) ? Math.max(0, Math.round((endMs - now) / 1000)) : 0;
|
|
55
|
+
const overtimeSec = Number.isFinite(endMs) ? Math.max(0, Math.round((now - endMs) / 1000)) : 0;
|
|
56
|
+
const elapsedSec = Number.isFinite(startMs) ? Math.max(0, Math.round((now - startMs) / 1000)) : 0;
|
|
57
|
+
const reached = Number.isFinite(endMs) ? now >= endMs : false;
|
|
58
|
+
return {
|
|
59
|
+
task: { id: taskId, text: String(taskText || '') },
|
|
60
|
+
goal: {
|
|
61
|
+
goalKey: String(goalKey || ''),
|
|
62
|
+
durationHuman: formatDuration(dur),
|
|
63
|
+
durationSec: dur,
|
|
64
|
+
startedAt: typeof startedAt === 'string' ? startedAt : stampOfMs(startedAt),
|
|
65
|
+
deadline: typeof deadline === 'string' ? deadline : stampOfMs(deadline),
|
|
66
|
+
remainingHuman: reached ? '' : formatDuration(remainingSec),
|
|
67
|
+
remainingSec,
|
|
68
|
+
elapsedHuman: formatDuration(elapsedSec),
|
|
69
|
+
elapsedSec,
|
|
70
|
+
overtimeSec,
|
|
71
|
+
reached,
|
|
72
|
+
extra: String(extra || ''),
|
|
73
|
+
},
|
|
74
|
+
check: check || null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 渲染模板;模板坏了就退回原文(check 绝不能因为渲染失败拿不到提示词)。 */
|
|
79
|
+
export function renderTaskGoalPrompt(ctx, template = TASK_GOAL_PROMPT_TEMPLATE) {
|
|
80
|
+
const src = String(template || '').trim() ? template : TASK_GOAL_PROMPT_TEMPLATE;
|
|
81
|
+
try {
|
|
82
|
+
return renderInstruction(src, ctx);
|
|
83
|
+
} catch {
|
|
84
|
+
return src;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
//
|
|
16
16
|
// 本文件不依赖 localtask(纯 timegoal 存储 + core),localtask 反过来引用这里。
|
|
17
17
|
import { badInput } from '../../../core/errors.js';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
TASK_GOAL_PROMPT_TEMPLATE,
|
|
20
|
+
renderTaskGoalPrompt,
|
|
21
|
+
taskGoalTemplateCtx,
|
|
22
|
+
} from './goal-template.js';
|
|
19
23
|
import { MAX_PROMPT, parseDuration, startTaskGoal, taskGoalState, taskGoalKey, recordTaskCheck } from './timegoal-store.js';
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -35,34 +39,18 @@ export function sanitizeTaskGoal(raw) {
|
|
|
35
39
|
return { duration, prompt };
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
/**
|
|
39
|
-
* 任务级 goal 的固化 prompt = **check 指令**(系统部分,agent 每轮照做)
|
|
40
|
-
* + 用户 --goal-prompt 追加说明(可选)。
|
|
41
|
-
* goalKey 先算出来直接嵌进指令——agent 复制执行即可,不用自己拼 key。
|
|
42
|
-
*/
|
|
43
|
-
function taskGoalPrompt({ goalKey, taskId, durationHuman, extra }) {
|
|
44
|
-
return [
|
|
45
|
-
`本任务带时间目标(领取即计时,持续 ${durationHuman})。`,
|
|
46
|
-
`- 每轮推进先执行:nx-kv timegoal check --task ${goalKey} --summary "<本轮现状>" --progress "<进展/下一步>"`,
|
|
47
|
-
`- 时间未到不得标记完成——应派出 sub agent 重新提出新的需求,再继续推进。`,
|
|
48
|
-
`- check 返回 reached:true 后才允许:nx-kv localtask done --id ${taskId} --summary "<完成总结>"`,
|
|
49
|
-
extra ? `\n附加要求(发布方):\n${extra}` : '',
|
|
50
|
-
]
|
|
51
|
-
.filter(Boolean)
|
|
52
|
-
.join('\n');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
42
|
/**
|
|
56
43
|
* 交付时刻调用:确保任务级 goal 已起表(**领取即计时**,幂等——重复领取不重置起点),
|
|
57
44
|
* 并返回渲染用 goal 上下文(与目录级 readGoalCtx 同形状:name/deadline/prompt)。
|
|
58
45
|
* 声明的时长不合法 → 返回 null(发布端已校验,这里是防御)。
|
|
59
46
|
*
|
|
60
|
-
* @param {{topicKey:string, taskId:number, cwd?:string, name?:string,
|
|
47
|
+
* @param {{topicKey:string, taskId:number, cwd?:string, name?:string, text?:string,
|
|
61
48
|
* timegoal:{duration:string,prompt?:string}, startedAtMs?:number}} p
|
|
62
|
-
* @returns {Promise<null | {name, deadline, prompt, goalKey, durationSec}>}
|
|
49
|
+
* @returns {Promise<null | {name, deadline, prompt, promptTemplate, goalKey, durationSec, extra}>}
|
|
63
50
|
*/
|
|
64
51
|
export async function ensureTaskGoal(p) {
|
|
65
52
|
const { topicKey, taskId, cwd, name, timegoal, startedAtMs } = p || {};
|
|
53
|
+
const taskText = p && p.text;
|
|
66
54
|
if (!timegoal || !topicKey || taskId === undefined || taskId === null) return null;
|
|
67
55
|
let durationSec;
|
|
68
56
|
try {
|
|
@@ -71,29 +59,39 @@ export async function ensureTaskGoal(p) {
|
|
|
71
59
|
return null;
|
|
72
60
|
}
|
|
73
61
|
const goalKey = taskGoalKey(topicKey, taskId);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
taskId,
|
|
77
|
-
durationHuman: formatDuration(durationSec),
|
|
78
|
-
extra: timegoal.prompt,
|
|
79
|
-
});
|
|
62
|
+
// 落库的是**模板**(占位符保留),交付时用领取那一刻的 ctx 渲染。
|
|
63
|
+
const promptTemplate = TASK_GOAL_PROMPT_TEMPLATE;
|
|
80
64
|
const r = await startTaskGoal({
|
|
81
65
|
topicKey,
|
|
82
66
|
taskId,
|
|
83
67
|
cwd,
|
|
84
68
|
name,
|
|
85
69
|
durationSec,
|
|
86
|
-
prompt,
|
|
70
|
+
prompt: promptTemplate,
|
|
87
71
|
startedAtMs,
|
|
88
72
|
});
|
|
89
73
|
const g = r && r.goal;
|
|
90
74
|
if (!g) return null;
|
|
75
|
+
const extra = timegoal.prompt;
|
|
76
|
+
const ctx = taskGoalTemplateCtx({
|
|
77
|
+
taskId,
|
|
78
|
+
taskText,
|
|
79
|
+
goalKey: g.key || goalKey,
|
|
80
|
+
durationSec: g.durationSec || durationSec,
|
|
81
|
+
extra,
|
|
82
|
+
startedAt: g.startedAt || g.started_at,
|
|
83
|
+
deadline: g.deadline,
|
|
84
|
+
nowMs: Date.now(),
|
|
85
|
+
});
|
|
91
86
|
return {
|
|
92
87
|
name: g.name,
|
|
93
88
|
deadline: g.deadline,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
// check 指令用同一套模板渲染:之后每轮 check 会按当下 ctx 重新渲染(任务 #87)
|
|
90
|
+
prompt: renderTaskGoalPrompt(ctx, g.prompt || promptTemplate),
|
|
91
|
+
promptTemplate: g.prompt || promptTemplate,
|
|
92
|
+
goalKey: g.key || goalKey,
|
|
93
|
+
durationSec: g.durationSec || durationSec,
|
|
94
|
+
extra: extra || '',
|
|
97
95
|
};
|
|
98
96
|
}
|
|
99
97
|
|
|
@@ -104,7 +102,7 @@ export async function ensureTaskGoal(p) {
|
|
|
104
102
|
* - 已经起过表 → 回显固化后的 prompt(领取时写死在 goal 里的那份原文);
|
|
105
103
|
* - 还没起表(pending 任务)→ 按声明现算(= 领取那一刻会固化的同一份文本)。
|
|
106
104
|
*/
|
|
107
|
-
export async function previewTaskGoal({ topicKey, taskId, name, timegoal }) {
|
|
105
|
+
export async function previewTaskGoal({ topicKey, taskId, name, timegoal, text }) {
|
|
108
106
|
if (!timegoal || !topicKey || taskId === undefined || taskId === null) return null;
|
|
109
107
|
let durationSec;
|
|
110
108
|
try {
|
|
@@ -112,29 +110,49 @@ export async function previewTaskGoal({ topicKey, taskId, name, timegoal }) {
|
|
|
112
110
|
} catch {
|
|
113
111
|
return null;
|
|
114
112
|
}
|
|
113
|
+
const goalKey = taskGoalKey(topicKey, taskId);
|
|
115
114
|
const state = await taskGoalState({ topicKey, taskId }).catch(() => null);
|
|
116
115
|
if (state && state.hasGoal && state.goal) {
|
|
116
|
+
const g = state.goal;
|
|
117
|
+
const ctx = taskGoalTemplateCtx({
|
|
118
|
+
taskId,
|
|
119
|
+
taskText: text,
|
|
120
|
+
goalKey: g.key || goalKey,
|
|
121
|
+
durationSec: g.durationSec || durationSec,
|
|
122
|
+
extra: timegoal.prompt,
|
|
123
|
+
startedAt: g.startedAt || g.started_at,
|
|
124
|
+
deadline: g.deadline,
|
|
125
|
+
nowMs: Date.now(),
|
|
126
|
+
});
|
|
117
127
|
return {
|
|
118
|
-
name:
|
|
119
|
-
deadline:
|
|
120
|
-
prompt:
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
name: g.name || name || `任务 #${taskId}`,
|
|
129
|
+
deadline: g.deadline || '',
|
|
130
|
+
prompt: renderTaskGoalPrompt(ctx, g.prompt),
|
|
131
|
+
promptTemplate: g.prompt || '',
|
|
132
|
+
goalKey: g.key || goalKey,
|
|
133
|
+
durationSec: g.durationSec || durationSec,
|
|
134
|
+
extra: timegoal.prompt || '',
|
|
123
135
|
started: true,
|
|
124
136
|
};
|
|
125
137
|
}
|
|
126
|
-
const
|
|
138
|
+
const ctx = taskGoalTemplateCtx({
|
|
139
|
+
taskId,
|
|
140
|
+
taskText: text,
|
|
141
|
+
goalKey,
|
|
142
|
+
durationSec,
|
|
143
|
+
extra: timegoal.prompt,
|
|
144
|
+
startedAt: Date.now(),
|
|
145
|
+
deadline: Date.now() + durationSec * 1000,
|
|
146
|
+
nowMs: Date.now(),
|
|
147
|
+
});
|
|
127
148
|
return {
|
|
128
149
|
name: name || `任务 #${taskId}`,
|
|
129
150
|
deadline: '',
|
|
130
|
-
prompt:
|
|
131
|
-
|
|
132
|
-
taskId,
|
|
133
|
-
durationHuman: formatDuration(durationSec),
|
|
134
|
-
extra: timegoal.prompt,
|
|
135
|
-
}),
|
|
151
|
+
prompt: renderTaskGoalPrompt(ctx),
|
|
152
|
+
promptTemplate: TASK_GOAL_PROMPT_TEMPLATE,
|
|
136
153
|
goalKey,
|
|
137
154
|
durationSec,
|
|
155
|
+
extra: timegoal.prompt || '',
|
|
138
156
|
started: false,
|
|
139
157
|
};
|
|
140
158
|
}
|
|
@@ -10,6 +10,10 @@ import { tx } from '../../../core/db/index.js';
|
|
|
10
10
|
import { db as ltDb } from '../../localtask/repo/open.js';
|
|
11
11
|
import { nowMs } from '../../../core/db/time.js';
|
|
12
12
|
import * as goalsRepo from '../../localtask/repo/goals.js';
|
|
13
|
+
import {
|
|
14
|
+
renderTaskGoalPrompt,
|
|
15
|
+
taskGoalTemplateCtx,
|
|
16
|
+
} from './goal-template.js';
|
|
13
17
|
import {
|
|
14
18
|
clampDuration,
|
|
15
19
|
durationLabel,
|
|
@@ -201,16 +205,49 @@ function applyGoalCheck(conn, row, parsed, summary, progress) {
|
|
|
201
205
|
progress,
|
|
202
206
|
});
|
|
203
207
|
const totalChecks = goalsRepo.countChecks(Number(row.id), conn);
|
|
208
|
+
// 每轮 check 同源渲染(任务 #87):读任务**当下**的原文与附加要求,
|
|
209
|
+
// 用与交付时同一套 ctx 重新渲染 goals.prompt 模板 —— 占位符里的时间/任务
|
|
210
|
+
// 永远是最新的;附加要求领取后动态改,下一轮 check 即生效。
|
|
211
|
+
const taskRow = conn.get('SELECT id, seq, body, ext FROM tasks WHERE id = :id', {
|
|
212
|
+
id: Number(row.task_id),
|
|
213
|
+
});
|
|
214
|
+
let extra = '';
|
|
215
|
+
if (taskRow && taskRow.ext) {
|
|
216
|
+
try {
|
|
217
|
+
const decl = JSON.parse(String(taskRow.ext)).ext_timegoal;
|
|
218
|
+
extra = String((decl && decl.prompt) || '');
|
|
219
|
+
} catch {
|
|
220
|
+
/* 声明损坏就当没有附加要求 */
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const taskSeq = Number(taskRow && taskRow.seq) || Number(parsed.seq);
|
|
224
|
+
const goalKey = taskGoalKey(parsed.topicKey, taskSeq);
|
|
225
|
+
const checkedAt = stampOf(at);
|
|
226
|
+
const ctx = taskGoalTemplateCtx({
|
|
227
|
+
taskId: taskSeq,
|
|
228
|
+
taskText: taskRow ? taskRow.text : '',
|
|
229
|
+
goalKey,
|
|
230
|
+
durationSec: row.duration_sec,
|
|
231
|
+
extra,
|
|
232
|
+
startedAt: row.started_at,
|
|
233
|
+
deadline: row.deadline,
|
|
234
|
+
nowMs: at,
|
|
235
|
+
check: { summary, progress, at: checkedAt, count: totalChecks },
|
|
236
|
+
});
|
|
237
|
+
const promptTemplate = String(row.prompt || '');
|
|
204
238
|
return {
|
|
205
239
|
...result,
|
|
206
|
-
prompt:
|
|
240
|
+
prompt: promptTemplate, // 模板原文(占位符保留)
|
|
241
|
+
promptRendered: renderTaskGoalPrompt(ctx, promptTemplate), // 本轮实时渲染(CLI 展示用)
|
|
242
|
+
task: { id: taskSeq, text: String((taskRow && taskRow.body) || '') },
|
|
243
|
+
goal: ctx.goal,
|
|
207
244
|
summary,
|
|
208
245
|
progress,
|
|
209
|
-
checkedAt
|
|
246
|
+
checkedAt,
|
|
210
247
|
startedAt: goal.startedAt,
|
|
211
248
|
deadline: goal.deadline,
|
|
212
249
|
now: stampNow(new Date(at)),
|
|
213
|
-
key:
|
|
250
|
+
key: goalKey,
|
|
214
251
|
name: String(row.topic_name || ''),
|
|
215
252
|
cwd: String(row.topic_cwd || ''),
|
|
216
253
|
logCount: totalChecks,
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
} from '../localtask/service.js';
|
|
39
39
|
import { ensureMainPanel, deepLinkUrl, escortPanel } from './panel-escort.js';
|
|
40
40
|
import { ensureTaskGoal, previewTaskGoal } from './taskgoal.js';
|
|
41
|
+
import { formatDuration } from '../../core/instruction-template.js';
|
|
41
42
|
import { readGroupContext } from './groupctx.js';
|
|
42
43
|
import { annotateTaskDelivery, attachTemplateCtx } from './attach.js';
|
|
43
44
|
import { composeSystemBlocks } from './system-blocks.js';
|
|
@@ -79,6 +80,13 @@ export function enrichGoalTiming(g) {
|
|
|
79
80
|
}
|
|
80
81
|
if (Number.isFinite(overtimeSec)) g.overtimeSec = overtimeSec;
|
|
81
82
|
if (reached !== undefined) g.reached = reached;
|
|
83
|
+
// 任务 #87:模板里要能直接写「持续 {{goal.durationHuman}}」——人话时长统一在这里补。
|
|
84
|
+
if (Number.isFinite(Number(g.durationSec)) && Number(g.durationSec) > 0) {
|
|
85
|
+
g.durationHuman = g.durationHuman || formatDuration(Number(g.durationSec));
|
|
86
|
+
}
|
|
87
|
+
if (Number.isFinite(Number(g.elapsedSec))) {
|
|
88
|
+
g.elapsedHuman = g.elapsedHuman || formatDuration(Number(g.elapsedSec));
|
|
89
|
+
}
|
|
82
90
|
return g;
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -175,12 +183,13 @@ export async function buildTaskDelivery(task, { source, summary, cwd, name, topi
|
|
|
175
183
|
.find(Boolean) || `任务 #${task.id}`).slice(0, 40);
|
|
176
184
|
// 预览走只读版本:同一份 check 指令文本,但不落盘、不起表
|
|
177
185
|
taskGoalCtx = preview
|
|
178
|
-
? await previewTaskGoal({ topicKey, taskId: task.id, cwd, name: title, timegoal: task.timegoal })
|
|
186
|
+
? await previewTaskGoal({ topicKey, taskId: task.id, cwd, name: title, timegoal: task.timegoal, text: task.text })
|
|
179
187
|
: await ensureTaskGoal({
|
|
180
188
|
topicKey,
|
|
181
189
|
taskId: task.id,
|
|
182
190
|
cwd,
|
|
183
191
|
name: title,
|
|
192
|
+
text: task.text,
|
|
184
193
|
timegoal: task.timegoal,
|
|
185
194
|
startedAtMs: parseStampMs(task.consumedAt) || undefined,
|
|
186
195
|
});
|
|
@@ -206,7 +215,14 @@ export async function buildTaskDelivery(task, { source, summary, cwd, name, topi
|
|
|
206
215
|
...deliveryCtx,
|
|
207
216
|
// 共享 ctx 里的 goal 同时暴露 check / statusLine,模板不必区分两种来源。
|
|
208
217
|
goal: goal
|
|
209
|
-
? {
|
|
218
|
+
? {
|
|
219
|
+
...goal,
|
|
220
|
+
// 任务 #87:goal.extra(附加要求,领取后可动态改)与 goalKey 供模板直接引用
|
|
221
|
+
extra: taskGoalCtx ? taskGoalCtx.extra || '' : '',
|
|
222
|
+
goalKey: taskGoalCtx ? taskGoalCtx.goalKey || '' : '',
|
|
223
|
+
check: goalCheck || '',
|
|
224
|
+
statusLine: goalStatus || '',
|
|
225
|
+
}
|
|
210
226
|
: null,
|
|
211
227
|
...attachCtx,
|
|
212
228
|
// task.text 交给模板前做「倒序聚焦 + 历史精简」重排(#157):最新轮反馈
|
|
@@ -142,6 +142,20 @@ export const DEFAULT_TIMECHECK_TEMPLATE = [
|
|
|
142
142
|
'{{/if}}',
|
|
143
143
|
].join('\n');
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* 默认「特殊功能提示」段(任务 #87):只在任务带时间目标时出现,给 agent 一份
|
|
147
|
+
* **可运算的**时间上下文(持续 / 剩余 / 是否到点)与任务号。
|
|
148
|
+
*
|
|
149
|
+
* 这一栏存在的意义是「占位符的可见入口」:goal.* 与 task.* 都是每轮 check 同源
|
|
150
|
+
* 渲染的同一份 ctx(check 返回对象走同一套模板),用户在这里改文案即可定制提示,
|
|
151
|
+
* 不必改代码。默认文案刻意不复述 check 指令(那在 timecheck 段里),只补状态。
|
|
152
|
+
*/
|
|
153
|
+
export const DEFAULT_GOALHINT_TEMPLATE = [
|
|
154
|
+
'{{#if goal.check}}',
|
|
155
|
+
'〔特殊功能提示 · 时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}},{{#if goal.reached}}已到点{{else}}剩余 {{goal.remainingHuman}}{{/if}}。',
|
|
156
|
+
'{{/if}}',
|
|
157
|
+
].join('\n');
|
|
158
|
+
|
|
145
159
|
/**
|
|
146
160
|
* 默认 ext(扩展 / 队列余量):同主题还有多少待领取任务、分别是什么标题,
|
|
147
161
|
* 并明确优先级。队列为空 → `ext` 为 null,整段不出现({{#if ext.count}} 闸门)。
|
|
@@ -194,6 +208,13 @@ export const BLOCK_DEFS = Object.freeze([
|
|
|
194
208
|
desc: '任务带时间目标时出现:check 指令或目录级状态',
|
|
195
209
|
defaultTemplate: DEFAULT_TIMECHECK_TEMPLATE,
|
|
196
210
|
},
|
|
211
|
+
{
|
|
212
|
+
id: 'goalhint',
|
|
213
|
+
tag: 'nx-kv.goalhint',
|
|
214
|
+
label: '特殊功能提示(timegoal)',
|
|
215
|
+
desc: '任务带时间目标时出现:可直接用 goal.* 时间变量与 task 全文占位;每轮 check 同源渲染',
|
|
216
|
+
defaultTemplate: DEFAULT_GOALHINT_TEMPLATE,
|
|
217
|
+
},
|
|
197
218
|
{
|
|
198
219
|
id: 'ext',
|
|
199
220
|
tag: 'nx-kv.ext',
|
|
@@ -30,7 +30,7 @@ export function useTaskActions({
|
|
|
30
30
|
groupAnchored, groupId, rows, app, model, tabId, tpl, refreshLocal,
|
|
31
31
|
markDirty, histRef, editorApiRef, attachAreaRef,
|
|
32
32
|
setDirty,
|
|
33
|
-
goal, goalEditable, declaredGoal, guard, dialog, showDockTab,
|
|
33
|
+
goal, goalEditable, goalPromptEditable, declaredGoal, guard, dialog, showDockTab,
|
|
34
34
|
}) {
|
|
35
35
|
const toast = useToast();
|
|
36
36
|
|
|
@@ -52,15 +52,23 @@ export function useTaskActions({
|
|
|
52
52
|
const duration = (goal.duration || '').trim();
|
|
53
53
|
const prompt = (goal.prompt || '').trim();
|
|
54
54
|
if (prompt && !duration) return { error: '时间目标要填时长(如 2h / 90m);只写附加要求无效' };
|
|
55
|
-
if (!goalEditable) return {};
|
|
56
55
|
if (!isDraft) {
|
|
57
56
|
const prevDur = declaredGoal?.duration || '';
|
|
58
57
|
const prevPrompt = declaredGoal?.prompt || '';
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const durChanged = duration !== prevDur;
|
|
59
|
+
const promptChanged = prompt !== prevPrompt;
|
|
60
|
+
if (!durChanged && !promptChanged) return {};
|
|
61
|
+
if (durChanged) {
|
|
62
|
+
// 时长:领取即计时,只有待领取能改
|
|
63
|
+
if (!goalEditable) return { error: '已领取计时,时长不可改(附加要求仍可直接改)' };
|
|
64
|
+
return duration ? { duration, goalPrompt: prompt } : { clearGoal: true };
|
|
65
|
+
}
|
|
66
|
+
// 任务 #87:只改附加要求 → 领取后也放行(下一轮 check 用新值渲染)
|
|
67
|
+
if (!goalPromptEditable) return {};
|
|
68
|
+
return { goalPrompt: prompt };
|
|
61
69
|
}
|
|
62
70
|
return duration ? { duration, goalPrompt: prompt } : {};
|
|
63
|
-
}, [goal, goalEditable, isDraft, declaredGoal]);
|
|
71
|
+
}, [goal, goalEditable, goalPromptEditable, isDraft, declaredGoal]);
|
|
64
72
|
|
|
65
73
|
const submit = useCallback(() => guard(async () => {
|
|
66
74
|
if (!doc) return;
|
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
// 时间目标 UI(#78):设置收进「更多」菜单,外部只以勋章回显。
|
|
2
|
-
export function goalSection({ goal, setGoalDraft, goalEditable, declaredGoal, openGoalLog, markDirty, task }) {
|
|
2
|
+
export function goalSection({ goal, setGoalDraft, goalEditable, goalPromptEditable, declaredGoal, openGoalLog, markDirty, task }) {
|
|
3
3
|
const goalDur = (goal.duration || '').trim();
|
|
4
4
|
const goalPrompt = (goal.prompt || '').trim();
|
|
5
|
+
const canEditPrompt = !!goalPromptEditable;
|
|
5
6
|
const goalBadge = (goalDur || goalPrompt)
|
|
6
7
|
? {
|
|
7
8
|
label: `⏱ ${goalDur || '目标'}`,
|
|
8
9
|
title: goalPrompt
|
|
9
|
-
|| (goalEditable ? '任务级时间目标(在「更多」里设置;领取即计时)' : '
|
|
10
|
+
|| (goalEditable ? '任务级时间目标(在「更多」里设置;领取即计时)' : '已领取计时,时长不可改(附加要求仍可编辑)'),
|
|
10
11
|
}
|
|
11
12
|
: null;
|
|
12
|
-
const goalMenu = (goalEditable || declaredGoal) ? (
|
|
13
|
+
const goalMenu = (goalEditable || canEditPrompt || declaredGoal) ? (
|
|
13
14
|
<div className="mdw-goal-menu">
|
|
14
15
|
<div className="mdw-goal-menu-lab">时间目标</div>
|
|
15
16
|
{goalEditable ? (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/>
|
|
26
|
-
<input
|
|
27
|
-
className="mdw-goal-prompt"
|
|
28
|
-
value={goal.prompt}
|
|
29
|
-
placeholder="附加要求(可选,随 check 指令一起固化)"
|
|
30
|
-
onChange={(e) => {
|
|
31
|
-
setGoalDraft({ ...goal, prompt: e.target.value });
|
|
32
|
-
markDirty();
|
|
33
|
-
}}
|
|
34
|
-
/>
|
|
35
|
-
</>
|
|
17
|
+
<input
|
|
18
|
+
className="mdw-goal-dur mono"
|
|
19
|
+
value={goal.duration}
|
|
20
|
+
placeholder="2h / 90m / 30分钟,留空不带"
|
|
21
|
+
onChange={(e) => {
|
|
22
|
+
setGoalDraft({ ...goal, duration: e.target.value });
|
|
23
|
+
markDirty();
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
36
26
|
) : (
|
|
37
|
-
<span className="mdw-goal-ro mono" title=
|
|
27
|
+
<span className="mdw-goal-ro mono" title="已领取计时,时长不可改">
|
|
38
28
|
{declaredGoal?.duration || '—'} · 已领取计时
|
|
39
29
|
</span>
|
|
40
30
|
)}
|
|
31
|
+
{canEditPrompt ? (
|
|
32
|
+
<input
|
|
33
|
+
className="mdw-goal-prompt"
|
|
34
|
+
value={goal.prompt}
|
|
35
|
+
placeholder="附加要求(可选;领取后仍可改,下一轮 check 即生效)"
|
|
36
|
+
onChange={(e) => {
|
|
37
|
+
setGoalDraft({ ...goal, prompt: e.target.value });
|
|
38
|
+
markDirty();
|
|
39
|
+
}}
|
|
40
|
+
/>
|
|
41
|
+
) : declaredGoal?.prompt ? (
|
|
42
|
+
<span className="mdw-goal-ro" title="任务已到终态,附加要求不可改">
|
|
43
|
+
{declaredGoal.prompt}
|
|
44
|
+
</span>
|
|
45
|
+
) : null}
|
|
41
46
|
{declaredGoal && task != null ? (
|
|
42
47
|
<button type="button" className="ghost" onClick={openGoalLog} title="查看时间目标的每轮 check 记录">
|
|
43
48
|
查看每轮 check 日志
|
|
@@ -13,6 +13,11 @@ export function useGoal({ id, isDraft, topicKey, task, taskRow }) {
|
|
|
13
13
|
const goal = goalDraft || { duration: declaredGoal?.duration || '', prompt: declaredGoal?.prompt || '' };
|
|
14
14
|
// 只有「待领取」能改时间目标声明(已领取在计时、已交付是终态;要改先 reopen)
|
|
15
15
|
const goalEditable = isDraft || (!!taskRow && taskRow.status === 'pending');
|
|
16
|
+
// 任务 #87:**附加要求**支持动态编辑——领取后仍可改(下一轮 check 即生效),
|
|
17
|
+
// 只有已交付 / 已取消这种终态才锁死;时长仍由 goalEditable 把关。
|
|
18
|
+
const goalPromptEditable = isDraft
|
|
19
|
+
|| (!!taskRow && taskRow.status !== 'done' && taskRow.status !== 'cancelled'
|
|
20
|
+
&& (taskRow.status === 'pending' || !!declaredGoal));
|
|
16
21
|
|
|
17
22
|
// 时间目标 check 流水(#74):已声明目标的任务才可查,逐轮读 goal_checks。
|
|
18
23
|
const canShowGoalLog = !isDraft && !!declaredGoal && task != null;
|
|
@@ -30,7 +35,7 @@ export function useGoal({ id, isDraft, topicKey, task, taskRow }) {
|
|
|
30
35
|
}, [canShowGoalLog, loadGoalLog]);
|
|
31
36
|
|
|
32
37
|
return {
|
|
33
|
-
goalDraft, setGoalDraft, goal, goalEditable, declaredGoal,
|
|
38
|
+
goalDraft, setGoalDraft, goal, goalEditable, goalPromptEditable, declaredGoal,
|
|
34
39
|
goalLog, loadGoalLog, canShowGoalLog,
|
|
35
40
|
};
|
|
36
41
|
}
|