nx-kv 0.44.2 → 0.45.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 +24 -0
- package/assets/kv-get/references/wait-workflow.md +14 -4
- package/assets/kv-get/references/waitloop.md +7 -1
- package/package.json +1 -1
- package/src/core/instruction-template.js +187 -0
- package/src/modules/localtask/action-lifecycle.js +6 -2
- package/src/modules/localtask/task-lifecycle.js +41 -1
- package/src/shared/prompt-blocks.js +36 -7
- package/src/web/frontend/page/settings/prompt-template-params.js +36 -0
- package/src/web/public/assets/{Introduction-DhwPj5cV.js → Introduction-EHroxF1H.js} +1 -1
- package/src/web/public/assets/{bar-Asff3O_q.js → bar-BvS_Jfi4.js} +1 -1
- package/src/web/public/assets/{cloud-B4teh9iW.js → cloud-DlWk0wnP.js} +1 -1
- package/src/web/public/assets/{composer-panel-DdJnqWyB.js → composer-panel-D3w-CjhN.js} +1 -1
- package/src/web/public/assets/{deleted-panel-Du_QekTw.js → deleted-panel-BMJEEBWD.js} +1 -1
- package/src/web/public/assets/{dir-Bm8iRhk_.js → dir-BtjHgH4Q.js} +1 -1
- package/src/web/public/assets/{group-DWUqMR0V.js → group-Bxq8JamU.js} +1 -1
- package/src/web/public/assets/{index-D2fKyD1k.js → index-ChlZPTea.js} +2 -2
- package/src/web/public/assets/{md-history-CfpJ9GT6.js → md-history-CBqcR086.js} +1 -1
- package/src/web/public/assets/{overview-B8afcbd6.js → overview-BP5sB1WX.js} +1 -1
- package/src/web/public/assets/{refs-OOuAfThN.js → refs-Dt7DQIOo.js} +1 -1
- package/src/web/public/assets/{repos-C8HvsdC7.js → repos-Zl1_SfPX.js} +1 -1
- package/src/web/public/assets/{route-crumb-CvrRU1gp.js → route-crumb-PqhQSVWL.js} +1 -1
- package/src/web/public/assets/settings-CXWFvvvv.js +8 -0
- package/src/web/public/assets/{status-tag-BhZgdBJz.js → status-tag-BK-45ld2.js} +1 -1
- package/src/web/public/assets/{task-Bq8Rd03M.js → task-COFIPegR.js} +1 -1
- package/src/web/public/assets/{templates-C9VpC4gA.js → templates-CIxgTTt-.js} +1 -1
- package/src/web/public/assets/{tool-bar-D5yvblnb.js → tool-bar-TIqYxsQl.js} +1 -1
- package/src/web/public/index.html +1 -1
- package/src/web/public/assets/settings-jom_vACN.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.45.0] - 2026-11-10 模板 helper + 时间目标分档提示 + 未到点 done 拦截可配(#90)
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **模板引擎内置 helper(25 个,全区块共用)**:比较 `eq/ne/gt/gte/lt/lte/between`、
|
|
10
|
+
逻辑 `and/or/not`、数值 `add/sub/mul/div/mod/round/floor/ceil/percent/ratio/clamp`、
|
|
11
|
+
字符串 `includes/length/default`、时间 `formatDuration`。于是可以按进度换话术,例如
|
|
12
|
+
`{{#if (gte (percent goal.elapsedSec goal.durationSec) 50)}}…过半…{{/if}}`。
|
|
13
|
+
约定写死并测过:helper **不抛错**;比较拿不到数 → `false`;数值坏输入 → 可见的
|
|
14
|
+
`NaN`;除零照 JS;`percent/ratio` 总量为 0 → `NaN`。
|
|
15
|
+
- **goalhint 默认文案升级**:显示已过百分比,并按 50% / 67% / 到点三档给不同指引
|
|
16
|
+
(确认主线 / 收尾整理 / 收口交付),发布方可在设置里继续改。
|
|
17
|
+
- **doneguard 区块(未到点就 done 的拦截提示可配)**:`localtask done` 被时间门禁拦下时,
|
|
18
|
+
blocked 返回新增 `guard` 字段,内容是 doneguard 模板的渲染结果(默认给剩余时间、
|
|
19
|
+
`timegoal check` 与 `done` 的确切命令);CLI 展示优先用它,取不到回落到原固定提示。
|
|
20
|
+
设置 → 提示词模板多出「完成门禁提示(timegoal)」一栏;该区块**不进正常交付**、
|
|
21
|
+
不占 `<nx-kv>` 里的段落。
|
|
22
|
+
|
|
23
|
+
### Docs
|
|
24
|
+
|
|
25
|
+
- `docs/glossary.md`:区块清单补到 8 个(goalhint / doneguard / ext),新增 helper 条目;
|
|
26
|
+
- `assets/kv-get`:wait/workflow 与 waitloop 同步 8 区块、helper 清单与 doneguard 语义;
|
|
27
|
+
- 新增 `docs/decisions/2026-11-10-template-helpers.md`(选型与边界)。
|
|
28
|
+
|
|
5
29
|
## [0.44.2] - 2026-11-10 领取补上 HTTP 路由(serve 在跑也能领)
|
|
6
30
|
|
|
7
31
|
### Added
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
自动打开浏览器弹窗,然后阻塞。
|
|
22
22
|
4. 用户看清现状,回填新任务。
|
|
23
23
|
5. wait 解除阻塞,stdout(--json) 返回 {status:"ok", task},进程退出。
|
|
24
|
-
6. agent 从工具结果读 task.text(任务本体)与 instruction
|
|
24
|
+
6. agent 从工具结果读 task.text(任务本体)与 instruction(系统区块的渲染结果,
|
|
25
25
|
有则必读),继续干活、提交结果;做完【必须】回到第 2 步——
|
|
26
26
|
循环,不许自行中断。
|
|
27
27
|
7. 若阻塞时限(默认 180 秒)内没有回填:wait 返回 {status:"timeout"}(exit 0),
|
|
@@ -91,13 +91,19 @@ wait 必带一句当前现状总结(≤2000 字,连续空白会折叠为单
|
|
|
91
91
|
(全局任务池);agent 不必区分,照常执行 `task.text`。
|
|
92
92
|
- **任务内容永远读 `task.text`**,多行换行原样保留。
|
|
93
93
|
- **`instruction` 有则必读**:系统区块的服务端渲染结果——项目 / 组上下文、附件清单与
|
|
94
|
-
本地路径、时间目标状态(任务级目标另带 check
|
|
94
|
+
本地路径、时间目标状态(任务级目标另带 check 指令)、时间目标特殊提示(goalhint)、
|
|
95
|
+
ack 汇报指令、项目级持续 get 指令。
|
|
95
96
|
字段缺席 = 本轮没有可渲染内容,直接执行任务。
|
|
96
97
|
- **配置模型(一份共享变量 + Handlebars 模板)**:所有系统段落都由同一份入参列表渲染——
|
|
97
98
|
项目(`repo.*`)、项目组(`group.*`,含组定位 / 本项目位置 / 成员 / 绑定文档)、
|
|
98
99
|
任务(`task.*`)、附件(`attach.*`)、时间目标(`goal.*`)、持续 get(`getloop.*`),
|
|
99
100
|
外加 `source / summary / cwd / name / params`。引擎是 **Handlebars 4.x**:
|
|
100
101
|
`{{var}}` 取值、`{{#if x}}…{{else}}…{{/if}}` 条件、`{{#each list}}…{{/each}}` 循环。
|
|
102
|
+
另有内置 helper:比较 `eq / ne / gt / gte / lt / lte / between`(拿不到数 → `false`)、
|
|
103
|
+
逻辑 `and / or / not`、数值 `add / sub / mul / div / mod / round / floor / ceil /
|
|
104
|
+
percent / ratio / clamp`(坏输入 → 可见的 `NaN`;`percent a b [位数]` 算百分比)、
|
|
105
|
+
串 `includes / length / default`、时间 `formatDuration`。helper 永不抛错,
|
|
106
|
+
可直接写 `{{#if (gte (percent goal.elapsedSec goal.durationSec) 50)}}`。
|
|
101
107
|
列表类变量是**结构化数组**(`group.peers` / `repo.docs` / `group.docs` / `attach.list` /
|
|
102
108
|
`groups`),模板用循环组织,服务端不预拼多行文本。
|
|
103
109
|
`attach.list` 每条按 `kind` 分型:`file`(`file.localPath/fileId/exists/syncCmd`)、
|
|
@@ -122,11 +128,15 @@ wait 必带一句当前现状总结(≤2000 字,连续空白会折叠为单
|
|
|
122
128
|
- **系统上下文默认是 XML 区块**:`instruction` 里每段系统内容各包一个标签——
|
|
123
129
|
`<nx-kv.context>`(组 / 项目上下文)、`<nx-kv.attachment>`(附件清单与识别要求)、
|
|
124
130
|
`<nx-kv.timecheck>`(时间目标状态 / check 指令)、
|
|
131
|
+
`<nx-kv.goalhint>`(时间目标特殊提示,任务级目标才有)、
|
|
132
|
+
`<nx-kv.ext>`(同主题待领取队列,队列空时不出现)、
|
|
125
133
|
`<nx-kv.ack>`(完成总结汇报指令,默认内置)、`<nx-kv.getloop>`(项目开启持续 get 时),
|
|
126
134
|
整体再包一层 `<nx-kv>`。看到这些标签就知道是系统追加内容,`task.text` 仍是任务原文。
|
|
135
|
+
`<nx-kv.doneguard>` 不进正常交付:只有未到点就想 `done` 时,出现在 blocked 返回的
|
|
136
|
+
`guard` 字段里(可用「设置 → 提示词模板 → 完成门禁提示」定制)。
|
|
127
137
|
追加模式可配:`--append-mode xml|plain`(默认 `xml`;`plain` = 按空行直拼)。
|
|
128
|
-
- **每个区块各自一份模板列表**:context / attachment / timecheck /
|
|
129
|
-
|
|
138
|
+
- **每个区块各自一份模板列表**:context / attachment / timecheck / goalhint / doneguard /
|
|
139
|
+
ext / ack / getloop 各自有独立的列表与生效项(共 8 个区块)。面板「设置 → 提示词模板」按区块新建 / 编辑 /
|
|
130
140
|
复制 / 删除 / 启用;CLI 用 `--block-templates '<JSON>'` 整体或按区块更新。
|
|
131
141
|
每个区块始终保留系统内置模板(不可删除);用户模板删光后按内置渲染。
|
|
132
142
|
旧配置(`{{block.content}}` 包装模板、多段 items、`deliveryTemplate/attachTemplate/
|
|
@@ -81,12 +81,18 @@ nx-kv localtask wait --summary "<当前现状总结>" --json
|
|
|
81
81
|
`{id, text, status, createdAt, consumedAt, roundSummary}`,**任务内容在 `task.text`**。
|
|
82
82
|
|
|
83
83
|
**`instruction` 字段(有则必读)**:wait 返回额外带 `instruction` —— 服务端按
|
|
84
|
-
|
|
84
|
+
8 个区块(context / attachment / timecheck / goalhint / doneguard / ext / ack / getloop)
|
|
85
|
+
渲染的**本轮根指令**:
|
|
85
86
|
默认含组 / 项目上下文、时间目标状态(`〔时间目标「目录名」剩余 X〕`,该目录挂了
|
|
86
87
|
timegoal 才出现),以及 ack 完成总结(默认「完成后调用 `localtask done` 回填结果」)。
|
|
87
88
|
规则:
|
|
88
89
|
|
|
89
90
|
- `task.text` 永远是任务本体原文;`instruction` 是**包裹它的执行指令**,两者一起读。
|
|
91
|
+
- goalhint 是任务级时间目标的「特殊功能提示」(默认带已过百分比与过半 / 2/3 分档话术);
|
|
92
|
+
doneguard 只在未到点就想 `done` 时出现在 blocked 返回的 `guard` 里,不进正常交付。
|
|
93
|
+
- 模板可用一套内置 helper:比较(`eq/ne/gt/gte/lt/lte/between`)、逻辑(`and/or/not`)、
|
|
94
|
+
数值(`add/sub/mul/div/mod/round/floor/ceil/percent/ratio/clamp`)、串(`includes/length/default`)、
|
|
95
|
+
时间(`formatDuration`);失败输出可见的 `NaN` / `false`,不抛错。
|
|
90
96
|
- 自定义模板可含 `{{task.text}}`(此时 instruction 自包含,正文以它为准)。
|
|
91
97
|
- ack 是完成指令与收尾要求的**唯一出口**(旧 `rule` 区块已删除并并入 ack)。
|
|
92
98
|
- 该目录的 timegoal 到点后,instruction 会显示「已到点」——预算用完,本轮该收尾了。
|
package/package.json
CHANGED
|
@@ -50,6 +50,193 @@ const COMPILE_OPTS = { noEscape: true, strict: false };
|
|
|
50
50
|
const CACHE_MAX = 256;
|
|
51
51
|
const cache = new Map();
|
|
52
52
|
|
|
53
|
+
// ---- 模板 helper(#90)----------------------------------------------------------
|
|
54
|
+
//
|
|
55
|
+
// 为什么自带一套而不是引 handlebars-helpers:那套 100+ helper 拖一堆依赖(还带
|
|
56
|
+
// lodash),而这里只需要「比较 / 逻辑 / 数值 / 串 / 时间」五小类;命名仍沿用社区
|
|
57
|
+
// 习惯(eq/ne/gt/gte/lt/lte/between、and/or/not、add/sub/mul/div/mod、round/
|
|
58
|
+
// floor/ceil、clamp、includes/length/default),写模板的人不用记新方言。
|
|
59
|
+
//
|
|
60
|
+
// 三条边界约定(写进 docs/glossary.md):
|
|
61
|
+
// 1. **绝不抛错**——任何 helper 出问题都只影响它自己那一小段输出,不拖垮整份渲染;
|
|
62
|
+
// 2. **数值失败可见**——数值类拿不到有限数时输出 `NaN`(模板里一眼能看见),
|
|
63
|
+
// 比较类拿不到数一律 `false`(条件分支安全地走 else);
|
|
64
|
+
// 3. **零值语义照 JS**——除零得 `Infinity` / `-Infinity` / `NaN`,`mod` 负数照 JS。
|
|
65
|
+
//
|
|
66
|
+
// 用法:`{{gte goal.elapsedSec 1800}}`、`{{#if (and goal.check (lt goal.remainingSec 300))}}`、
|
|
67
|
+
// `{{percent goal.elapsedSec goal.durationSec}}`(0 位小数)、`{{percent a b 1}}`(1 位)。
|
|
68
|
+
|
|
69
|
+
/** 数字归一:有限数 → 数;否则 null(区分「0」与「拿不到」)。 */
|
|
70
|
+
function toNum(v) {
|
|
71
|
+
if (typeof v === 'number') return Number.isFinite(v) ? v : null;
|
|
72
|
+
if (typeof v === 'boolean') return v ? 1 : 0;
|
|
73
|
+
const s = String(v ?? '').trim();
|
|
74
|
+
if (!s) return null;
|
|
75
|
+
const n = Number(s);
|
|
76
|
+
return Number.isFinite(n) ? n : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 数值输出:有限数原样字符串(-0 归一成 0);Infinity 照 JS 语义;拿不到数 → 可见的 `NaN`。 */
|
|
80
|
+
function numOut(n) {
|
|
81
|
+
if (Number.isNaN(n)) return 'NaN';
|
|
82
|
+
if (!Number.isFinite(n)) return n > 0 ? 'Infinity' : '-Infinity';
|
|
83
|
+
return String(Object.is(n, -0) ? 0 : n);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 可预测的相等:两边都能当数就按数比,否则按字符串比。 */
|
|
87
|
+
function looseEq(a, b) {
|
|
88
|
+
if (a === b) return true;
|
|
89
|
+
if (a == null || b == null) return false;
|
|
90
|
+
const na = toNum(a);
|
|
91
|
+
const nb = toNum(b);
|
|
92
|
+
if (na !== null && nb !== null) return na === nb;
|
|
93
|
+
return String(a) === String(b);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 折叠末尾多余的 0:1.50 → 1.5、2.00 → 2。 */
|
|
97
|
+
function fixed(n, digits) {
|
|
98
|
+
const d = Math.max(0, Math.min(20, Math.trunc(toNum(digits) ?? 0)));
|
|
99
|
+
const s = n.toFixed(d);
|
|
100
|
+
return d > 0 ? String(Number(s)) : s;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const HELPER_DEFS = {
|
|
104
|
+
// —— 比较(返回布尔;拿不到数 → false,保证 {{#if}} 走 else)——
|
|
105
|
+
eq: (a, b) => looseEq(a, b),
|
|
106
|
+
ne: (a, b) => !looseEq(a, b),
|
|
107
|
+
gt: (a, b) => {
|
|
108
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
109
|
+
return x !== null && y !== null && x > y;
|
|
110
|
+
},
|
|
111
|
+
gte: (a, b) => {
|
|
112
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
113
|
+
return x !== null && y !== null && x >= y;
|
|
114
|
+
},
|
|
115
|
+
lt: (a, b) => {
|
|
116
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
117
|
+
return x !== null && y !== null && x < y;
|
|
118
|
+
},
|
|
119
|
+
lte: (a, b) => {
|
|
120
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
121
|
+
return x !== null && y !== null && x <= y;
|
|
122
|
+
},
|
|
123
|
+
// 闭区间:min ≤ v ≤ max(min > max 时恒 false,不自动翻转)
|
|
124
|
+
between: (v, min, max) => {
|
|
125
|
+
const [x, lo, hi] = [toNum(v), toNum(min), toNum(max)];
|
|
126
|
+
return x !== null && lo !== null && hi !== null && x >= lo && x <= hi;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
// —— 逻辑(参数由 wrapper 剥掉 options 后原样传入,对象也按真值参与)——
|
|
130
|
+
and: (...args) => args.every(Boolean),
|
|
131
|
+
or: (...args) => args.some(Boolean),
|
|
132
|
+
not: (v) => !v,
|
|
133
|
+
|
|
134
|
+
// —— 数值(失败 → 可见的 NaN)——
|
|
135
|
+
add: (...args) => {
|
|
136
|
+
const nums = args.map(toNum);
|
|
137
|
+
if (nums.some((n) => n === null)) return 'NaN';
|
|
138
|
+
return numOut(nums.reduce((s, n) => s + n, 0));
|
|
139
|
+
},
|
|
140
|
+
sub: (a, ...rest) => {
|
|
141
|
+
const nums = [a, ...rest].map(toNum);
|
|
142
|
+
if (nums.some((n) => n === null)) return 'NaN';
|
|
143
|
+
return numOut(nums.slice(1).reduce((s, n) => s - n, nums[0]));
|
|
144
|
+
},
|
|
145
|
+
mul: (...args) => {
|
|
146
|
+
const nums = args.map(toNum);
|
|
147
|
+
if (nums.some((n) => n === null)) return 'NaN';
|
|
148
|
+
return numOut(nums.reduce((s, n) => s * n, 1));
|
|
149
|
+
},
|
|
150
|
+
// 除零照 JS:x/0 → Infinity / -Infinity;0/0 → NaN
|
|
151
|
+
div: (a, b) => {
|
|
152
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
153
|
+
if (x === null || y === null) return 'NaN';
|
|
154
|
+
return numOut(x / y);
|
|
155
|
+
},
|
|
156
|
+
mod: (a, b) => {
|
|
157
|
+
const [x, y] = [toNum(a), toNum(b)];
|
|
158
|
+
if (x === null || y === null) return 'NaN';
|
|
159
|
+
return numOut(x % y);
|
|
160
|
+
},
|
|
161
|
+
round: (v, digits = 0) => {
|
|
162
|
+
const n = toNum(v);
|
|
163
|
+
if (n === null) return 'NaN';
|
|
164
|
+
const d = Math.max(0, Math.min(20, Math.trunc(toNum(digits) ?? 0)));
|
|
165
|
+
const f = 10 ** d;
|
|
166
|
+
return numOut(Math.round(n * f) / f);
|
|
167
|
+
},
|
|
168
|
+
floor: (v) => {
|
|
169
|
+
const n = toNum(v);
|
|
170
|
+
return n === null ? 'NaN' : numOut(Math.floor(n));
|
|
171
|
+
},
|
|
172
|
+
ceil: (v) => {
|
|
173
|
+
const n = toNum(v);
|
|
174
|
+
return n === null ? 'NaN' : numOut(Math.ceil(n));
|
|
175
|
+
},
|
|
176
|
+
// percent(part, total, digits=0):part 占总量的百分比;total 为 0 / 非数 → NaN
|
|
177
|
+
// (百分比里的「∞%」没有意义,这里刻意不走 JS 的除零语义,输出可见的 NaN)
|
|
178
|
+
percent: (part, total, digits = 0) => {
|
|
179
|
+
const [p, t] = [toNum(part), toNum(total)];
|
|
180
|
+
if (p === null || t === null || t === 0) return 'NaN';
|
|
181
|
+
return fixed((p / t) * 100, digits);
|
|
182
|
+
},
|
|
183
|
+
// ratio(part, total, digits=2):比例(不做 ×100);total 为 0 → NaN(与 percent 同口径)
|
|
184
|
+
ratio: (part, total, digits = 2) => {
|
|
185
|
+
const [p, t] = [toNum(part), toNum(total)];
|
|
186
|
+
if (p === null || t === null || t === 0) return 'NaN';
|
|
187
|
+
return fixed(p / t, digits);
|
|
188
|
+
},
|
|
189
|
+
// clamp(v, min, max):把 v 夹进 [min, max];非数 → NaN
|
|
190
|
+
clamp: (v, min, max) => {
|
|
191
|
+
const [x, lo, hi] = [toNum(v), toNum(min), toNum(max)];
|
|
192
|
+
if (x === null || lo === null || hi === null) return 'NaN';
|
|
193
|
+
return numOut(Math.min(Math.max(x, lo), hi));
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// —— 字符串 ——
|
|
197
|
+
includes: (haystack, needle) => {
|
|
198
|
+
if (haystack == null) return false;
|
|
199
|
+
const h = Array.isArray(haystack) ? haystack : String(haystack);
|
|
200
|
+
return Array.isArray(h) ? h.some((x) => looseEq(x, needle)) : h.includes(String(needle ?? ''));
|
|
201
|
+
},
|
|
202
|
+
// 字符串 / 数组的长度;null / 数字等拿不到长度 → 0(模板里可直接当数比)
|
|
203
|
+
length: (v) => {
|
|
204
|
+
if (v == null) return 0;
|
|
205
|
+
if (typeof v === 'string' || Array.isArray(v)) return v.length;
|
|
206
|
+
return String(v).length;
|
|
207
|
+
},
|
|
208
|
+
// default(v, fallback):v 为空(null / undefined / 空串 / 空数组)时给兜底文本
|
|
209
|
+
default: (v, fallback = '') => {
|
|
210
|
+
if (v == null) return fallback;
|
|
211
|
+
if (typeof v === 'string' && !v.trim()) return fallback;
|
|
212
|
+
if (Array.isArray(v) && v.length === 0) return fallback;
|
|
213
|
+
return v;
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
// —— 时间 ——
|
|
217
|
+
// 秒 → 人话(与交付文本里的「剩余 / 已过」同一套措辞)
|
|
218
|
+
formatDuration: (sec) => formatDuration(sec),
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/** 已注册的 helper 名(文档 / 测试 / 设置页速查共用)。 */
|
|
222
|
+
export const TEMPLATE_HELPERS = Object.keys(HELPER_DEFS);
|
|
223
|
+
|
|
224
|
+
// 统一包一层 try/catch:任何 helper 自身异常都退化成可见兜底,不拖垮整份渲染(#90 约束)
|
|
225
|
+
for (const [name, fn] of Object.entries(HELPER_DEFS)) {
|
|
226
|
+
HB.registerHelper(name, (...args) => {
|
|
227
|
+
try {
|
|
228
|
+
// Handlebars 会把 options 对象塞在最后一个参数里
|
|
229
|
+
const plain = args.length && typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null
|
|
230
|
+
? args.slice(0, -1)
|
|
231
|
+
: args;
|
|
232
|
+
return fn(...plain);
|
|
233
|
+
} catch {
|
|
234
|
+
return 'NaN';
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
53
240
|
// 旧语法识别(不兼容、不迁移):
|
|
54
241
|
// - 旧闸门 `{{#repo}}` / `{{#group}}` / `{{#attachSync}}` / `{{#goalCheck}}` 等:
|
|
55
242
|
// 只允许 `{{#if}}` / `{{#each}}` 两种块。
|
|
@@ -170,8 +170,12 @@ export const lifecycleActions = [
|
|
|
170
170
|
service.completeTask({ id: ctx.id, cwd: ctx.cwd, key: ctx.key, summary: ctx.summary }),
|
|
171
171
|
render: (d) => {
|
|
172
172
|
if (d.status === 'blocked') {
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
// #90:未到点的拦截文案来自可配置的 doneguard 模板(d.guard);模板空/渲染失败
|
|
174
|
+
// 才退回内置 hint 的一行式兜底。
|
|
175
|
+
if (d.reason === 'not_claimed') return `[blocked] 任务 #${d.id} 暂不能标完成:${d.hint}`;
|
|
176
|
+
const head = `时间未到(剩 ${d.remainingHuman || Math.round((d.remainingSec || 0) / 60) + ' 分钟'},截止 ${d.deadline})`;
|
|
177
|
+
if (d.guard) return `[blocked] 任务 #${d.id} 暂不能标完成。\n${d.guard}\n(${head})`;
|
|
178
|
+
return `[blocked] 任务 #${d.id} 暂不能标完成:${head}——${d.hint}`;
|
|
175
179
|
}
|
|
176
180
|
if (d.already) return `任务 #${d.id} 之前已完成(${d.completedAt}),无需重复标记。`;
|
|
177
181
|
const goal = d.goal && d.goal.recorded ? '(最终 check 已记录)' : '';
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// 跳过被依赖/闸门挡住的 pending)、completeTask(完成门禁:timegoal 未到点返回 blocked
|
|
3
3
|
// 业务值而不是抛错)、reopenTask(用户修改反馈 → **就地重开原任务**,历史进 history 链)。
|
|
4
4
|
import { badInput, notFound } from '../../core/errors.js';
|
|
5
|
-
import { formatDuration } from '../../core/instruction-template.js';
|
|
5
|
+
import { formatDuration, renderInstruction } from '../../core/instruction-template.js';
|
|
6
|
+
import { resolveBlockTemplates } from '../../shared/prompt-blocks.js';
|
|
7
|
+
import { getLtSettings } from './repo/settings.js';
|
|
8
|
+
import { taskGoalTemplateCtx } from '../tasktool/plugins/goal-template.js';
|
|
6
9
|
import { preserveFrontmatter } from '../../shared/frontmatter.js';
|
|
7
10
|
import {
|
|
8
11
|
FEEDBACK_HEADING,
|
|
@@ -23,6 +26,34 @@ import {
|
|
|
23
26
|
txw as tx,
|
|
24
27
|
} from './repo/index.js';
|
|
25
28
|
|
|
29
|
+
/**
|
|
30
|
+
* 「未到点就想 done」的拦截提示(#90):模板来自设置 lt.blockTemplates.doneguard,
|
|
31
|
+
* 与其余系统段同一套 Handlebars 引擎与 ctx;渲染失败退回 '',调用方仍用内置 hint,
|
|
32
|
+
* 门禁本身的业务结果不受模板影响。
|
|
33
|
+
*/
|
|
34
|
+
function renderDoneGuard({ taskId, taskText, goalKey, st }) {
|
|
35
|
+
try {
|
|
36
|
+
const s = getLtSettings();
|
|
37
|
+
const tpl = resolveBlockTemplates(s && s.blockTemplates).doneguard.template;
|
|
38
|
+
const goal = st.goal || {};
|
|
39
|
+
const ctx = taskGoalTemplateCtx({
|
|
40
|
+
taskId,
|
|
41
|
+
taskText: taskText || '',
|
|
42
|
+
goalKey,
|
|
43
|
+
durationSec: Number(goal.durationSec) || 0,
|
|
44
|
+
extra: '',
|
|
45
|
+
startedAt: goal.startedAt,
|
|
46
|
+
deadline: goal.deadline,
|
|
47
|
+
nowMs: Date.now(),
|
|
48
|
+
});
|
|
49
|
+
// 只在这一条路径上置真:正常交付渲染时没有这个变量,doneguard 段整段省略
|
|
50
|
+
ctx.goal.blocked = true;
|
|
51
|
+
return String(renderInstruction(tpl, ctx) || '').trim();
|
|
52
|
+
} catch {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
26
57
|
/**
|
|
27
58
|
* 解析 supersededBy:本地是数字(同主题 seq),跨队列搬家后写的是 "key:seq"。
|
|
28
59
|
* 主题 key 本身不含 ':'(见 core/topic-key.js),所以最后一个 ':' 就是分隔符。
|
|
@@ -311,6 +342,14 @@ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawS
|
|
|
311
342
|
const { taskGoalState, recordTaskCheck } = await import('../tasktool/taskgoal.js');
|
|
312
343
|
const st = await taskGoalState({ topicKey: key, taskId: want });
|
|
313
344
|
if (st.hasGoal && !st.reached) {
|
|
345
|
+
// 「未到点就想 done」的拦截提示可配(#90):模板与其它区块同源,落
|
|
346
|
+
// lt.blockTemplates.doneguard;渲染失败退回内置 hint,不挡业务结果。
|
|
347
|
+
const guard = renderDoneGuard({
|
|
348
|
+
taskId: want,
|
|
349
|
+
taskText: task.text,
|
|
350
|
+
goalKey: st.key,
|
|
351
|
+
st,
|
|
352
|
+
});
|
|
314
353
|
return {
|
|
315
354
|
status: 'blocked',
|
|
316
355
|
reason: 'goal_not_reached',
|
|
@@ -322,6 +361,7 @@ export async function completeTask({ cwd: rawCwd, key: rawKey, id, summary: rawS
|
|
|
322
361
|
remainingSec: st.remainingSec,
|
|
323
362
|
remainingHuman: formatDuration(st.remainingSec),
|
|
324
363
|
hint: '时间未到,不能标记完成——请派出 sub agent 重新提出新的需求;到点后(timegoal check 返回 reached:true)再来标完成',
|
|
364
|
+
guard,
|
|
325
365
|
};
|
|
326
366
|
}
|
|
327
367
|
if (st.hasGoal) {
|
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
// - 整个渲染领域只有一个 ctx(见 delivery-template.js 的 buildDeliveryCtx):
|
|
5
5
|
// `{ task, repo, group, attach, goal, getloop, source, summary, cwd, name, params }`。
|
|
6
6
|
// 所有区块模板都从这同一份数据取值——不存在「某模块自带一套变量域」。
|
|
7
|
-
// - 每个区块(context / attachment / timecheck / ack /
|
|
8
|
-
//
|
|
7
|
+
// - 每个区块(context / attachment / timecheck / goalhint / doneguard / ext / ack /
|
|
8
|
+
// getloop)各自有一份独立的模板列表:
|
|
9
|
+
// `blockTemplates[id] = { active, list: [{ id, name, template, builtin }] }`。
|
|
9
10
|
// 旧 rule 区块已合并进 ack(done 指令与收尾要求只留这一个出口)。
|
|
10
11
|
// 列表里可以新建、编辑、复制、删除,并由 `active` 指定该区块当前生效的模板。
|
|
11
12
|
// - 每个区块**始终至少有一个系统内置模板**(id 固定 `builtin`):不可删除,
|
|
12
13
|
// 内容固定为该区块的默认模板;用户模板删光后 active 自动回落到它。
|
|
13
14
|
// - 模板由 core/instruction-template.js(Handlebars 4.x)渲染;列表变量是结构化数组,
|
|
14
|
-
// 用 `{{#each}}` 展开;有无用 `{{#if}}`
|
|
15
|
+
// 用 `{{#each}}` 展开;有无用 `{{#if}}` 判断。另有一组内置 helper(比较 / 逻辑 /
|
|
16
|
+
// 数值 / 字符串 / 时间,见该文件的 HELPER_DEFS),失败输出可见的 NaN / false,不抛错。
|
|
15
17
|
// - 旧语法(`{{#repo}}…{{/repo}}` 闸门、`{{group.peers}}` 这类纯文本占位符、
|
|
16
18
|
// `{{attach.sync}}` 旧别名)**不再兼容**;保存校验会直接拒绝并提示改用新语法。
|
|
17
19
|
//
|
|
@@ -143,16 +145,36 @@ export const DEFAULT_TIMECHECK_TEMPLATE = [
|
|
|
143
145
|
].join('\n');
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
* 默认「特殊功能提示」段(任务 #87
|
|
147
|
-
*
|
|
148
|
+
* 默认「特殊功能提示」段(任务 #87,文案在 #90 里补全):只在任务带时间目标时出现,
|
|
149
|
+
* 给 agent 一份**可运算的**时间上下文(持续 / 已过 / 剩余 / 是否到点)与任务号,
|
|
150
|
+
* 并按进度给阶段口径(过半提醒、2/3 收尾、到点收口)。
|
|
148
151
|
*
|
|
149
152
|
* 这一栏存在的意义是「占位符的可见入口」:goal.* 与 task.* 都是每轮 check 同源
|
|
150
153
|
* 渲染的同一份 ctx(check 返回对象走同一套模板),用户在这里改文案即可定制提示,
|
|
151
|
-
* 不必改代码。默认文案刻意不复述 check 指令(那在 timecheck
|
|
154
|
+
* 不必改代码。默认文案刻意不复述 check 指令(那在 timecheck 段里),只补状态与阶段。
|
|
155
|
+
* 进度用内置 helper 现算(percent / gte),不新增 ctx 字段。
|
|
152
156
|
*/
|
|
153
157
|
export const DEFAULT_GOALHINT_TEMPLATE = [
|
|
154
158
|
'{{#if goal.check}}',
|
|
155
|
-
'〔特殊功能提示 · 时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}}
|
|
159
|
+
'〔特殊功能提示 · 时间目标〕任务 #{{task.id}} 正在计时:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),{{#if goal.reached}}已到点(超时 {{formatDuration goal.overtimeSec}}){{else}}剩余 {{goal.remainingHuman}}{{/if}}。',
|
|
160
|
+
'{{#if goal.reached}}——时间已到:可以收口,把改动收敛成可交付状态,补验证与说明后按 ack 段 done。',
|
|
161
|
+
'{{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}——已过 2/3:进入收尾整理(收敛改动 / 补验证 / 写清遗留),别开新战线。',
|
|
162
|
+
'{{else}}{{#if (gte (percent goal.elapsedSec goal.durationSec) 50)}}——已过半:先确认主线走到哪,剩余时间只做收尾必需项。',
|
|
163
|
+
'{{else}}——时间尚足:先做主线,再补细节。{{/if}}{{/if}}{{/if}}',
|
|
164
|
+
'{{/if}}',
|
|
165
|
+
].join('\n');
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 默认「完成门禁提示」段(#90):agent 未到点就想 `localtask done` 时**代替**原来那句
|
|
169
|
+
* 固定 hint 出现在 blocked 返回里。与其它区块同源:模板可改、变量是 goal.* / task.*,
|
|
170
|
+
* 并能用 helper 按进度给不同口径。`goal.blocked` 只在这条路径上为真,交付渲染时整段省略。
|
|
171
|
+
*/
|
|
172
|
+
export const DEFAULT_DONEGUARD_TEMPLATE = [
|
|
173
|
+
'{{#if goal.blocked}}',
|
|
174
|
+
'〔完成门禁 · 时间未到〕任务 #{{task.id}} 还不能 done:持续 {{goal.durationHuman}},已过 {{goal.elapsedHuman}}({{percent goal.elapsedSec goal.durationSec}}%),剩余 {{goal.remainingHuman}}。',
|
|
175
|
+
'- 现在可做:{{#if (gte (percent goal.elapsedSec goal.durationSec) 67)}}收尾整理(收敛改动 / 补验证 / 写清遗留),或派 sub agent 提出新的需求继续推进{{else}}继续推进主线,并派 sub agent 重新提出新的需求{{/if}}。',
|
|
176
|
+
'- 每轮推进先跑:nx-kv timegoal check --task {{goal.goalKey}} --summary "<本轮现状>" --progress "<进展/下一步>"',
|
|
177
|
+
'- 到点后再:nx-kv localtask done --id {{task.id}} --summary "<完成总结>"',
|
|
156
178
|
'{{/if}}',
|
|
157
179
|
].join('\n');
|
|
158
180
|
|
|
@@ -215,6 +237,13 @@ export const BLOCK_DEFS = Object.freeze([
|
|
|
215
237
|
desc: '任务带时间目标时出现:可直接用 goal.* 时间变量与 task 全文占位;每轮 check 同源渲染',
|
|
216
238
|
defaultTemplate: DEFAULT_GOALHINT_TEMPLATE,
|
|
217
239
|
},
|
|
240
|
+
{
|
|
241
|
+
id: 'doneguard',
|
|
242
|
+
tag: 'nx-kv.doneguard',
|
|
243
|
+
label: '完成门禁提示(timegoal)',
|
|
244
|
+
desc: 'agent 未到点就想 done 时出现(blocked 返回的 guard):说明剩余时间与可做事项,可用 helper 按进度分档',
|
|
245
|
+
defaultTemplate: DEFAULT_DONEGUARD_TEMPLATE,
|
|
246
|
+
},
|
|
218
247
|
{
|
|
219
248
|
id: 'ext',
|
|
220
249
|
tag: 'nx-kv.ext',
|
|
@@ -206,6 +206,42 @@ export const BLOCK_PARAMS = {
|
|
|
206
206
|
],
|
|
207
207
|
},
|
|
208
208
|
],
|
|
209
|
+
// #90:未到点就 done 的拦截文案(blocked 返回里的 guard 字段)
|
|
210
|
+
doneguard: [
|
|
211
|
+
{
|
|
212
|
+
label: '时间目标上下文(任务级)',
|
|
213
|
+
items: [
|
|
214
|
+
['goal.blocked', '恒为 true(只在这条拦截路径上出现,交付渲染时整段省略)'],
|
|
215
|
+
['goal.goalKey', '任务级目标 key(check --task 用)'],
|
|
216
|
+
['goal.durationHuman', '持续时长(人话)'],
|
|
217
|
+
['goal.durationSec', '持续秒数'],
|
|
218
|
+
['goal.startedAt', '开始计时时间'],
|
|
219
|
+
['goal.deadline', '截止时间'],
|
|
220
|
+
['goal.remainingHuman', '剩余时长(人话)'],
|
|
221
|
+
['goal.remainingSec', '剩余秒数'],
|
|
222
|
+
['goal.elapsedHuman', '已过时长(人话)'],
|
|
223
|
+
['goal.elapsedSec', '已过秒数'],
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
label: '任务',
|
|
228
|
+
items: [
|
|
229
|
+
['task.id', '任务号'],
|
|
230
|
+
['task.text', '任务实时原文'],
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
label: '可用的 helper(与所有区块同一套)',
|
|
235
|
+
items: [
|
|
236
|
+
['percent goal.elapsedSec goal.durationSec', '已用百分比(0 位小数;可加第三参控制小数位)'],
|
|
237
|
+
['gte a b / gt / lt / lte / eq / ne / between v min max', '比较,返回布尔,可直接进 {{#if}}'],
|
|
238
|
+
['and / or / not', '逻辑'],
|
|
239
|
+
['add / sub / mul / div / mod / round / floor / ceil / ratio / clamp', '数值计算(坏输入输出 NaN,不抛错)'],
|
|
240
|
+
['includes / length / default', '字符串'],
|
|
241
|
+
['formatDuration', '秒数转人话'],
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
],
|
|
209
245
|
ext: [
|
|
210
246
|
{
|
|
211
247
|
label: '队列',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{g as e,h as t,l as n,m as r,o as i,p as a,v as o,y as s}from"./task-status-BnymQMTw.js";import{r as c,v as l,w as u}from"./workspace-C_5X2gIr.js";import{n as d}from"./app-context-D7HAx67n.js";import{_ as f,a as p,i as m,n as h,p as g,r as _,t as v,u as y,v as b,y as x}from"./md-history-
|
|
1
|
+
import{g as e,h as t,l as n,m as r,o as i,p as a,v as o,y as s}from"./task-status-BnymQMTw.js";import{r as c,v as l,w as u}from"./workspace-C_5X2gIr.js";import{n as d}from"./app-context-D7HAx67n.js";import{_ as f,a as p,i as m,n as h,p as g,r as _,t as v,u as y,v as b,y as x}from"./md-history-CBqcR086.js";import{a as S,i as C}from"./upload-BIMbGcCB.js";import{r as ee}from"./md-parse-awNLHAzO.js";import{t as w}from"./route-crumb-PqhQSVWL.js";import{a as T,c as E,i as D,l as O,o as te,r as k,s as A,t as j,u as ne}from"./tool-bar-TIqYxsQl.js";var M=s(e(),1),N=u(),P=t(),F=`doc`,I=[{id:`edit`,label:`编辑`},{id:`doc`,label:`文档`},{id:`view`,label:`查看`}];function re({crumb:e=null,title:t,pathLabel:n=``,dirty:r=!1,writable:i=!1,onSave:a=null,onSaveLabel:o=`保存`,menuGroups:s=[],saving:c=!1,external:l=!1,afterTitle:u=null}){let d=D(),{layout:f,setLayout:p}=te(F),[m,h]=(0,M.useState)(!1),g={};for(let e of s||[])for(let t of e?.items||[])t&&t.id&&(g[t.id]=t);g.save=a&&{id:`save`,label:c?`保存中…`:o,run:a,primary:!0,disabled:c||!r};let _=e=>e===`more`||!!g[e],v=f.filter(e=>O(F,e)&&_(e.id)),y=f.filter(e=>A(F,e)&&_(e.id)),b=e=>{g[e]?.run?.(),d.setOpen(!1)},x=e=>{if(e===`more`)return(0,P.jsx)(`div`,{className:`docp-more`,ref:d.ref,children:(0,P.jsx)(`button`,{type:`button`,className:`btn ghost sm${d.open?` on`:``}`,title:`更多操作`,"aria-haspopup":`menu`,"aria-expanded":d.open,onClick:e=>k(d,e,`right`),children:`更多`})},`more`);let t=g[e];return t?(0,P.jsx)(`button`,{type:`button`,className:t.primary||e===`save`?`btn sm primary docp-save`:`btn ghost sm`,disabled:!!t.disabled,onClick:()=>b(e),children:t.label||E(F,e).label||e},e):null},S=I.map(e=>({...e,items:y.filter(t=>E(F,t.id).menuGroup===e.id)})).filter(e=>e.items.length),C=y.filter(e=>!E(F,e.id).menuGroup);return i?(0,P.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,P.jsxs)(`div`,{className:`mdw-head`,children:[(0,P.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,P.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,P.jsx)(`span`,{className:`grow`}),u,(0,P.jsxs)(`div`,{className:`docp-actions`,children:[v.map(e=>x(e.id)),(0,P.jsxs)(j,{menu:d,className:`mdw-act-menu`,children:[S.map(e=>(0,P.jsxs)(`div`,{className:`mdw-fmt-menu-group`,role:`group`,"aria-label":e.label,children:[(0,P.jsx)(`div`,{className:`mdw-fmt-menu-cap`,children:e.label}),e.items.map(e=>{let t=g[e.id],n=t?.danger||E(F,e.id).danger;return(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(n?` danger`:``),onClick:()=>b(e.id),children:[t?.label||E(F,e.id).label||e.id,t?.hint?(0,P.jsx)(`span`,{className:`hint`,children:t.hint}):null]},e.id)})]},e.id)),C.map(e=>{let t=g[e.id];return(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(t?.danger||E(F,e.id).danger?` danger`:``),onClick:()=>b(e.id),children:t?.label||E(F,e.id).label||e.id},e.id)}),(0,P.jsx)(`div`,{className:`mdw-fmt-menu-sep`,role:`separator`}),(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`,onClick:()=>{d.setOpen(!1),h(!0)},children:`自定义工具栏…`})]})]})]}),m&&(0,N.createPortal)((0,P.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>h(!1),children:(0,P.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,P.jsx)(T,{kind:F,layout:f,setLayout:p,onClose:()=>h(!1)})})}),document.body)]}):(0,P.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,P.jsxs)(`div`,{className:`mdw-head`,children:[(0,P.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,P.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,P.jsx)(`span`,{className:`grow`}),u,(0,P.jsx)(`div`,{className:`docp-actions`,children:(0,P.jsx)(`span`,{className:`docp-tag ext`,children:`只读`})})]})]})}function L(e,t,n){return{id:e,label:t,items:n.filter(Boolean)}}function R(e){let t=String(e??``).replace(/^/,``).replace(/\r\n/g,`
|
|
2
2
|
`),n=t.match(/^---\n([\s\S]*?)\n---\n?/),r=n?t.slice(n[0].length):t;for(let e of r.split(`
|
|
3
3
|
`)){let t=e.trim();if(t)return t}return``}function z(e){let t=R(e).match(/^#\s+(.+)$/);return t?t[1].trim():``}function ie(e,t){let n=String(e??``),r=String(t||``).trim()||`未命名文档`,i=n.replace(/\r\n/g,`
|
|
4
4
|
`),a=i.match(/^---\n([\s\S]*?)\n---\n?/),o=a?i.slice(0,a[0].length):``,s=(a?i.slice(a[0].length):i).split(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e,h as t,y as n}from"./task-status-BnymQMTw.js";import{w as r}from"./workspace-C_5X2gIr.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-
|
|
1
|
+
import{g as e,h as t,y as n}from"./task-status-BnymQMTw.js";import{w as r}from"./workspace-C_5X2gIr.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-TIqYxsQl.js";var l=n(e(),1),u=r(),d=t();function f({kind:e,renderers:t={},actions:n={},titles:r={},disabled:f={},labels:p={},className:m=``}){let{layout:h,setLayout:g}=s(e),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(!1),C=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!_)return;let e=e=>{C.current?.contains(e.target)||w.current?.contains(e.target)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]);let T=h.filter(t=>o(e,t)),E=h.filter(t=>c(e,t)),D=t=>p[t]||a(e,t).label||t,O=(e,t={})=>(0,d.jsx)(`button`,{type:`button`,className:t.primary?`btn small primary`:`btn small ghost`,title:r[e]||D(e),disabled:!!f[e],onClick:()=>n[e]&&n[e](),children:D(e)},e),k=n=>n===`more`?(0,d.jsxs)(`button`,{ref:C,type:`button`,className:`btn small ghost`+(_?` is-open`:``),title:r.more||`更多操作`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();b({top:t.bottom+6,right:Math.max(8,window.innerWidth-t.right)}),v(e=>!e)},children:[D(`more`),` ▾`]},`more`):t[n]?(0,d.jsx)(`span`,{className:`ta-slot`,children:t[n]({open:_})},n):O(n,{primary:a(e,n).section===`primary`});return(0,d.jsxs)(`div`,{className:`ta-bar`+(m?` ${m}`:``),children:[T.map(e=>k(e.id)),_&&y&&(0,u.createPortal)((0,d.jsxs)(`div`,{ref:w,className:`ta-more-menu`,role:`menu`,style:{top:y.top,right:y.right},children:[E.length===0&&(0,d.jsx)(`div`,{className:`ta-more-empty`,children:`没有收纳的工具——可在编排里把按钮收入更多`}),E.map(e=>(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it`,disabled:!!f[e.id],title:r[e.id]||D(e.id),onClick:()=>{v(!1),n[e.id]&&n[e.id]()},children:D(e.id)},e.id)),(0,d.jsx)(`div`,{className:`ta-more-sep`}),(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it ta-more-cfg`,onClick:()=>{v(!1),S(!0)},children:`自定义工具栏…`})]}),document.body),x&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>S(!1),children:(0,d.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,d.jsx)(i,{kind:e,layout:h,setLayout:g,onClose:()=>S(!1)})})}),document.body)]})}export{f as t};
|