nx-kv 0.42.3 → 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 +88 -0
- package/README.md +1 -1
- package/assets/kv-get/SKILL.md +4 -4
- package/assets/kv-get/references/localget.md +2 -2
- package/package.json +1 -1
- package/src/core/attachmentdb/docs.js +12 -0
- package/src/core/attachmentdb/relations.js +17 -0
- package/src/core/attachmentdb.js +1 -0
- package/src/modules/docs/attach.js +46 -1
- package/src/modules/docs/brief.js +35 -4
- package/src/modules/docs/index.js +15 -1
- package/src/modules/docs/service.js +10 -6
- package/src/modules/localtask/action-attach.js +25 -0
- package/src/modules/localtask/action-flags.js +0 -1
- package/src/modules/localtask/action-lifecycle.js +6 -4
- package/src/modules/localtask/action-waiting.js +3 -3
- package/src/modules/localtask/repo/rows.js +3 -0
- package/src/modules/localtask/repo/tasks.js +18 -2
- package/src/modules/localtask/task-lifecycle.js +3 -3
- package/src/modules/localtask/task-ops.js +17 -4
- package/src/modules/localtask/task-view.js +14 -6
- package/src/modules/tasktool/attach-resource.js +3 -0
- package/src/modules/tasktool/attach.js +62 -0
- package/src/modules/tasktool/get.js +1 -2
- 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/plugins/waitgoal-config.js +1 -1
- package/src/modules/tasktool/wait.js +20 -4
- package/src/shared/doc-title.js +71 -0
- package/src/shared/prompt-blocks.js +21 -0
- package/src/web/frontend/components/md/attach-area.jsx +56 -6
- package/src/web/frontend/components/md/attach-common.js +16 -3
- package/src/web/frontend/components/md/attach-modal.jsx +42 -2
- package/src/web/frontend/components/md/md-panes-helpers.js +4 -1
- package/src/web/frontend/components/repos/get-loop-modal.jsx +1 -1
- package/src/web/frontend/components/task-panel/layout.jsx +64 -0
- package/src/web/frontend/components/task-panel/page-shell.jsx +38 -0
- package/src/web/frontend/components/tool-acts/modules.js +2 -0
- package/src/web/frontend/modules/md/md-render.js +34 -11
- package/src/web/frontend/modules/md/progress-chain.js +29 -0
- package/src/web/frontend/modules/md/progress-search.js +14 -0
- package/src/web/frontend/modules/md/styles/chrome.css +9 -0
- package/src/web/frontend/modules/md/styles/panels.css +2 -0
- package/src/web/frontend/modules/md/styles/shell.css +2 -10
- package/src/web/frontend/page/dir/index.jsx +8 -5
- package/src/web/frontend/page/dir/landing.jsx +92 -99
- 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 +22 -6
- package/src/web/frontend/page/doc/index.jsx +24 -12
- package/src/web/frontend/page/group/index.jsx +145 -68
- package/src/web/frontend/page/progress/index.jsx +67 -19
- package/src/web/frontend/page/settings/prompt-template-params.js +38 -2
- package/src/web/frontend/styles-v2/views.css +5 -1
- package/src/web/public/assets/Introduction-CDSLSy0q.js +6 -0
- package/src/web/public/assets/{bar-C0LZwZoX.js → bar-Dp9JHQEk.js} +1 -1
- package/src/web/public/assets/{cloud-ol3se4zn.js → cloud-D13Ed3Pg.js} +1 -1
- package/src/web/public/assets/{composer-panel-O04Eac_2.js → composer-panel-eKhM7jDM.js} +1 -1
- package/src/web/public/assets/deleted-panel-QHsQZ5Ez.js +1 -0
- package/src/web/public/assets/dir-CiDjsHfd.js +5 -0
- package/src/web/public/assets/group-DDXtRIPf.js +2 -0
- package/src/web/public/assets/index-DGvBoOdp.css +1 -0
- package/src/web/public/assets/{index-BAS6Qpjs.js → index-Dq7eNqAB.js} +2 -2
- package/src/web/public/assets/md-history-DI1Ukbvc.js +39 -0
- package/src/web/public/assets/{overview-CIeUo4At.js → overview-BE6O6j51.js} +1 -1
- package/src/web/public/assets/progress-Bx0reVYl.js +3 -0
- package/src/web/public/assets/{refs-BpET-Lxl.js → refs-BkncFh9X.js} +1 -1
- package/src/web/public/assets/{repos-K67Ie07A.js → repos-C9wx2OXj.js} +2 -2
- package/src/web/public/assets/{route-crumb-B7T_Hupr.js → route-crumb-_IyS9fTT.js} +1 -1
- package/src/web/public/assets/settings-DlgWRz3r.js +7 -0
- package/src/web/public/assets/{status-tag-B7CrVhQP.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-6moKn9GB.js → templates-CK9nH5WD.js} +1 -1
- package/src/web/public/assets/tool-bar-9LD5jcE3.js +1 -0
- package/src/web/public/index.html +2 -2
- package/src/web/public/assets/Introduction--ILYt-bQ.js +0 -1
- package/src/web/public/assets/dir-B_HW1kpE.js +0 -5
- package/src/web/public/assets/group-BCOXDlvk.js +0 -1
- package/src/web/public/assets/index-CZzMw1zg.css +0 -1
- package/src/web/public/assets/md-history-DCgN2zcc.js +0 -39
- package/src/web/public/assets/progress-DHDlz9O9.js +0 -3
- package/src/web/public/assets/settings-Bek4c_r_.js +0 -6
- package/src/web/public/assets/task-DHca1uMu.js +0 -11
- package/src/web/public/assets/task-row-W12GJMCO.js +0 -1
- package/src/web/public/assets/tool-bar-CDUi6q4z.js +0 -1
|
@@ -230,6 +230,9 @@ export function normalizeTask(t, siblings, readyOpts = {}) {
|
|
|
230
230
|
reopenCount: Number(t.reopenCount) || 0,
|
|
231
231
|
// 派生子任务数(#144):>0 = 已有后续轮次/评论派生——反馈入口只在链尖显示
|
|
232
232
|
childCount: Number(t.childCount) || 0,
|
|
233
|
+
// 派生的「下一轮」数(#172):reopen 边数——>0 = 本条已被下一轮取代(不是链尖)。
|
|
234
|
+
// 进程面板据此只留链尖,旧轮次去任务链里看;comment / feedback 边(旁支新活)不计入。
|
|
235
|
+
childRoundCount: Number(t.childRoundCount) || 0,
|
|
233
236
|
// 链上第几轮(#122 进程面板「楼数」):根任务 = 1,派生 = 来源 + 1(schema 语义
|
|
234
237
|
// 见 v1.sql tasks.round)。库里存的是 round 列,JSON 形态只带 reopenCount = round-1
|
|
235
238
|
// (repo/rows.js),这里换算回来 —— 前端显示「第 N 楼」/按楼搜索不必再回溯链。
|
|
@@ -399,16 +402,21 @@ export async function taskChain({ id, cwd, key } = {}) {
|
|
|
399
402
|
|
|
400
403
|
// 节点 = 链上每一代任务(每轮一条,seq 做面板 key),从根排到叶;自己是"当前尖"
|
|
401
404
|
// wrapper = getTaskRowById 的返回({ row, task });row.topicId 是主题内部 id
|
|
402
|
-
|
|
405
|
+
// 链边的类型(reopen=反馈轮次 / comment=评论旁支)从**边**上取:task_links 是链的
|
|
406
|
+
// 唯一来源,任务自身那个旧 forkKind 字段多半是空的——空着的话面板的链上每一格
|
|
407
|
+
// 都显示成「起点」,看不出哪一轮是反馈、哪一条是评论旁支(#172)。
|
|
408
|
+
const nodeOf = (wrapper, linkType) => {
|
|
403
409
|
const owner = topicsRepo.getTopicById(wrapper.row.topicId);
|
|
410
|
+
const lite = chainLite(owner || { key: k, name: t.name }, wrapper.task);
|
|
404
411
|
return {
|
|
405
|
-
...
|
|
412
|
+
...lite,
|
|
413
|
+
forkKind: linkType || lite.forkKind || '',
|
|
406
414
|
at: String(wrapper.task.createdAt || ''),
|
|
407
415
|
current: Number(wrapper.task.id) === Number(selfRow.task.id),
|
|
408
416
|
};
|
|
409
417
|
};
|
|
410
|
-
const upNodes = ancestorLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id)));
|
|
411
|
-
const downNodes = descendantLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id)));
|
|
418
|
+
const upNodes = ancestorLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id), l.type));
|
|
419
|
+
const downNodes = descendantLinks.map((l) => nodeOf(tasksRepo.getTaskRowById(l.id), l.type));
|
|
412
420
|
const selfNode = nodeOf(selfRow);
|
|
413
421
|
// 根 → … → 自己 → … → 叶(自己是"当前尖";查询哪条,哪条就是尖)
|
|
414
422
|
const nodes = [...upNodes, selfNode, ...downNodes].map(
|
|
@@ -416,8 +424,8 @@ export async function taskChain({ id, cwd, key } = {}) {
|
|
|
416
424
|
);
|
|
417
425
|
|
|
418
426
|
// 祖先/子任务清单(旧字段形状保留:面板兼容)
|
|
419
|
-
const ancestors = upNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.
|
|
420
|
-
const children = downNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.
|
|
427
|
+
const ancestors = upNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.forkKind || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
|
|
428
|
+
const children = downNodes.map((n) => ({ key: n.key, name: n.name, id: n.id, status: n.status, forkKind: n.forkKind || '', forkOf: '', createdAt: n.createdAt, excerpt: n.excerpt }));
|
|
421
429
|
|
|
422
430
|
return {
|
|
423
431
|
status: 'ok',
|
|
@@ -268,6 +268,9 @@ export function resourceOf(row, lookups = {}) {
|
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
// ref:文档库里的 md(locator 是 docs 树相对路径,或外部 md 的绝对路径)
|
|
271
|
+
// 标题口径(#168):**文档标题**(正文首行的 # 标题)优先 —— 服务端在标注层
|
|
272
|
+
// (tasktool/attach.js 的 annotateRefTitles)读盘补上并覆盖 title/name;
|
|
273
|
+
// 这里先给文件名占位,读不到标题时前端回落它。
|
|
271
274
|
const info = lookups.refs && lookups.refs.get(String(meta.refId || row.targetKey || ''));
|
|
272
275
|
const refId = String(meta.refId || row.targetKey || (info && info.refId) || '');
|
|
273
276
|
const relPath = String((info && info.locator) || meta.locator || '');
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
listTaskAttachmentsBySeq,
|
|
41
41
|
resolveRefId,
|
|
42
42
|
unlinkAttachment,
|
|
43
|
+
updateAttachmentNote,
|
|
43
44
|
upsertFileAttachment,
|
|
44
45
|
} from '../../core/attachmentdb.js';
|
|
45
46
|
import * as service from '../localtask/service.js';
|
|
@@ -73,6 +74,35 @@ function annotateFileRows(rows, lookups, store, mirror) {
|
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/**
|
|
78
|
+
* 给 ref 型附件补**文档标题**(#168):标题 = 文档正文首行的 `# 标题`。
|
|
79
|
+
* 服务端补(读盘),前端直接显示——用户「填写了标题」后,附件区与 md 编辑器
|
|
80
|
+
* 里的引用名就该是那个标题,而不是文件名。读不到就留空(前端回落附件名)。
|
|
81
|
+
*/
|
|
82
|
+
async function annotateRefTitles(attachments) {
|
|
83
|
+
const refs = (attachments || [])
|
|
84
|
+
.filter((a) => a.kind === 'ref')
|
|
85
|
+
.map((a) => ({ id: a.refId || a.targetKey || '', locator: a.relPath || a.targetKey || '' }));
|
|
86
|
+
if (!refs.length) return attachments;
|
|
87
|
+
let titles = new Map();
|
|
88
|
+
try {
|
|
89
|
+
const { refTitlesOf } = await import('../docs/brief.js');
|
|
90
|
+
titles = await refTitlesOf(refs);
|
|
91
|
+
} catch {
|
|
92
|
+
titles = new Map();
|
|
93
|
+
}
|
|
94
|
+
for (const a of attachments) {
|
|
95
|
+
if (a.kind !== 'ref') continue;
|
|
96
|
+
const t = titles.get(String(a.refId || a.targetKey || ''));
|
|
97
|
+
if (!t) continue;
|
|
98
|
+
a.docTitle = t;
|
|
99
|
+
// 视图标题一并覆盖:附件区、md 编辑器引用名、指令段都读它——一处改,处处一致
|
|
100
|
+
a.title = t;
|
|
101
|
+
a.name = t;
|
|
102
|
+
}
|
|
103
|
+
return attachments;
|
|
104
|
+
}
|
|
105
|
+
|
|
76
106
|
/**
|
|
77
107
|
* 领取/查看时刻的附件标注:本机仓优先 → 云端镜像兜底 → 标注本地路径。
|
|
78
108
|
*
|
|
@@ -116,6 +146,7 @@ export async function annotateTaskDelivery(task, { sync: allowSync = true, topic
|
|
|
116
146
|
|
|
117
147
|
const mirror = await cloudMirrorIndex(gid, cfg.attachmentsDir);
|
|
118
148
|
const attachments = annotateFileRows(rows, targetLookupsOf(getDb(), rows), store, mirror);
|
|
149
|
+
await annotateRefTitles(attachments);
|
|
119
150
|
if (inlineDocs) await inlineDocContent(attachments);
|
|
120
151
|
return { task: { ...task, attachments }, sync };
|
|
121
152
|
}
|
|
@@ -330,6 +361,7 @@ export async function listTaskAttachments({ id, cwd, key } = {}) {
|
|
|
330
361
|
const mirror = await cloudMirrorIndex(gid, cfg.attachmentsDir);
|
|
331
362
|
const rows = listTaskAttachmentsBySeq(getDb(), { topicKey: cur.key || key, seq: cur.id });
|
|
332
363
|
const attachments = annotateFileRows(rows, targetLookupsOf(getDb(), rows), store, mirror);
|
|
364
|
+
await annotateRefTitles(attachments);
|
|
333
365
|
|
|
334
366
|
return {
|
|
335
367
|
task: { id: cur.id, key: cur.key || key },
|
|
@@ -343,6 +375,36 @@ export async function listTaskAttachments({ id, cwd, key } = {}) {
|
|
|
343
375
|
};
|
|
344
376
|
}
|
|
345
377
|
|
|
378
|
+
/**
|
|
379
|
+
* 改一条附件绑定上的**说明**(desc,#168):面板里给已挂载的文档绑定补/改说明。
|
|
380
|
+
* 只动边上的 note(角色/位置不动)——「这条边是什么」与「它讲什么」分开。
|
|
381
|
+
*/
|
|
382
|
+
export async function noteTaskAttachment({ id, cwd, key, attachment, note = '' } = {}) {
|
|
383
|
+
const cur = await service.getTask({ id, cwd, key });
|
|
384
|
+
const topicKey = cur.key || key || '';
|
|
385
|
+
const attId = String(attachment || '').trim();
|
|
386
|
+
if (!attId) throw badInput('需要 --attachment <资源 id>(见 localtask attachments 输出)');
|
|
387
|
+
const db = getDb();
|
|
388
|
+
let changed = 0;
|
|
389
|
+
tx(
|
|
390
|
+
(conn) => {
|
|
391
|
+
const gid = taskGlobalIdOf(conn, { topicKey, seq: cur.id });
|
|
392
|
+
if (!gid) throw badInput(`任务 #${cur.id} 已不存在`);
|
|
393
|
+
changed = updateAttachmentNote(conn, { host: 'task', hostId: gid, attachmentId: attId, note });
|
|
394
|
+
},
|
|
395
|
+
{ db, mode: 'IMMEDIATE' }
|
|
396
|
+
);
|
|
397
|
+
if (!changed) throw badInput(`这条任务上没有附件 ${attId}`);
|
|
398
|
+
return {
|
|
399
|
+
status: 'ok',
|
|
400
|
+
key: cur.key || key,
|
|
401
|
+
name: topicNameOf(cur),
|
|
402
|
+
task: { id: cur.id },
|
|
403
|
+
attachment: attId,
|
|
404
|
+
note: String(note || ''),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
346
408
|
/**
|
|
347
409
|
* 解除任务与一条资源的关系(CLI `localtask detach`)。
|
|
348
410
|
*
|
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
import { waitForTask } from './wait.js';
|
|
16
16
|
import { getLoopForCwd, DEFAULT_GET_LOOP_TEMPLATE } from './getloop.js';
|
|
17
17
|
|
|
18
|
-
export async function getTask({ cwd,
|
|
18
|
+
export async function getTask({ cwd, timeoutSec, open = true, params } = {}) {
|
|
19
19
|
const loop = await getLoopForCwd(cwd);
|
|
20
20
|
// 项目开启「持续 get」时,循环指令作为 getloop 区块随其余系统段一起由
|
|
21
21
|
// buildTaskDelivery 统一编排(不再在 get 层后置拼接,避免同一份 instruction
|
|
22
22
|
// 有两个拼装入口)。
|
|
23
23
|
const r = await waitForTask({
|
|
24
24
|
cwd,
|
|
25
|
-
summary,
|
|
26
25
|
// 未开启持续 get → instant(waitForTask 内部忽略 timeout 直接快路径);
|
|
27
26
|
// 开启 → 阻塞窗口 = 项目配置分钟数(显式 --timeout 仍最高优先)。
|
|
28
27
|
timeoutSec: timeoutSec ?? (loop.enabled ? loop.waitMinutes * 60 : undefined),
|
|
@@ -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,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { badInput } from '../../../core/errors.js';
|
|
16
16
|
|
|
17
17
|
export const DEFAULT_GET_LOOP_TEMPLATE =
|
|
18
|
-
'{{#if task}}不要直接结束本轮:完成上面的任务({{task.id}})之后,继续调用 nx-kv localtask get
|
|
18
|
+
'{{#if task}}不要直接结束本轮:完成上面的任务({{task.id}})之后,继续调用 nx-kv localtask get 领取下一条任务。队列里有活会立即返回;没活时每次最多阻塞 {{getloop.waitMinutes}} 分钟,直到 get 返回 timeout 为止。{{/if}}';
|
|
19
19
|
|
|
20
20
|
export const GET_LOOP_DEFAULT_MINUTES = 10; // 阻塞窗口默认 10 分钟(上限仍受 wait 的 600s 夹制)
|
|
21
21
|
|
|
@@ -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):最新轮反馈
|
|
@@ -300,7 +316,7 @@ function blocksCoverBody(templates) {
|
|
|
300
316
|
* 返回带 source: 'local' | 'global' 标明任务来自哪个队列。
|
|
301
317
|
* @param {string} [cwd] 工作目录(主题按目录名识别);缺省 → 进程当前 cwd。
|
|
302
318
|
* 注意:显式传 cwd **不会**关闭全局兜底——本地空了一定去全局领。
|
|
303
|
-
* @param {string} summary
|
|
319
|
+
* @param {string} [summary] 当前现状(#171 起不再必填:面板上没有对应输入界面)
|
|
304
320
|
* @param {number} [timeoutSec] 阻塞上限(秒);缺省 → 页面配置(推荐 180,最大 600)
|
|
305
321
|
* @param {number} [timeoutMs] 兼容旧参数(毫秒)
|
|
306
322
|
* @param {boolean} [open] 是否自动打开浏览器弹窗(测试可关)
|
|
@@ -319,7 +335,7 @@ export async function waitForTask({
|
|
|
319
335
|
getLoopWaitMinutes = 0, // 项目级阻塞窗口(分钟):进 getloop 模板 ctx,让 agent 知道每轮会等多久
|
|
320
336
|
} = {}) {
|
|
321
337
|
const { key, cwd, name } = normalizeCwd(rawCwd);
|
|
322
|
-
const summary = normalizeSummary(rawSummary); //
|
|
338
|
+
const summary = normalizeSummary(rawSummary, { optional: true }); // #171:现状不再必填
|
|
323
339
|
// 领取方身份:记进 task.claimedBy(事后能看出"这条被谁领的")
|
|
324
340
|
const by = { key, cwd, name };
|
|
325
341
|
// 仓库上下文:这个目录属于哪个已登记仓库、周围关联哪些看板。
|