nx-kv 0.53.3 → 0.54.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 +43 -0
- package/assets/nx-kv/SKILL.md +1 -1
- package/assets/nx-kv/references/A02-/346/217/220/344/272/244/344/273/273/345/212/241.md +5 -3
- package/assets/nx-kv/references/A03-/345/256/214/346/210/220/344/270/216/351/207/215/345/274/200.md +35 -21
- package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +1 -1
- package/package.json +1 -1
- package/src/modules/localtask/actions/_manifest.generated.ts +3 -0
- package/src/modules/localtask/actions/localtask-add.ts +6 -1
- package/src/modules/localtask/actions/localtask-claim.ts +7 -1
- package/src/modules/localtask/actions/localtask-done.ts +2 -0
- package/src/modules/localtask/actions/localtask-get.ts +2 -0
- package/src/modules/localtask/actions/localtask-reopen.ts +6 -6
- package/src/modules/localtask/actions/localtask-tasks.ts +113 -0
- package/src/modules/localtask/actions/localtask-update.ts +6 -1
- package/src/modules/localtask/contract-views.ts +129 -0
- package/src/runtime/dartgen.ts +32 -7
- package/src/web/frontend/api/cli-tree.json +16 -1
- package/src/web/frontend/api/client.generated.ts +16 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.54.0] - 2026-11-14 契约铺到写操作:领 / 改 / 完成 / 重开都能被端侧强类型调用
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **`localtask` 六条 action 出参进契约**:`get`(任务详情 + 附件清单)、`claim`、`add`、
|
|
10
|
+
`update`、`done`、`reopen`。端侧不再为「领一条任务」手写 HTTP。
|
|
11
|
+
- **一份共享出参视图 `src/modules/localtask/contract-views.ts`**:任务/附件的字段只写一次,
|
|
12
|
+
六条 action 引用同一份 —— 写成六份的话,字段迟早分叉成「同一个东西两个名字」。
|
|
13
|
+
- **写操作只回编号**:`claim` / `add` / `update` 的视图只给 `id`(`claim` 给 `taskId`),
|
|
14
|
+
正文与附件一律留给 `localtask.get` —— 领一条不必顺带解码 200KB 正文。
|
|
15
|
+
实现方式是在返回值上**附加**一个顶层字段,CLI 的 `--json` 与 HTTP 的原有键一个不少:
|
|
16
|
+
契约只描述视图,不裁剪运行时响应。
|
|
17
|
+
- **新增 `localtask.tasks`(`GET /api/localtasks/tasks`)**:看**一个主题**的任务清单,
|
|
18
|
+
只回列表需要的字段(标题/状态/轮次/可领),正文留给 `localtask.get`。
|
|
19
|
+
为什么不给 `localtask.list` 加 `tasks`:那会让首页每次刷新都吞几 MB(某主题 194 条),
|
|
20
|
+
而首页真正要的只是「几个主题、各几条待领」。
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **生成器两处真实缺陷**(铺到写操作才暴露):① 同一字段的驼峰/连字符别名
|
|
25
|
+
(`goalPrompt` / `goal-prompt`)会撞成同一个 Dart 形参名 → 编译不过,现在按「留驼峰」去重;
|
|
26
|
+
② 位置参数上不该写 `required`(Dart 只允许命名参数带它),必填字段的 query 也不再生成
|
|
27
|
+
`if (x != null)`。
|
|
28
|
+
- **T2 保真测试会先造任务**:写操作的 action 在空库里没有返回可校验,现在按 action 打各自的
|
|
29
|
+
夹具(待领 / 已完成 / 可改 / 可完成),并断言 `claim` 真的把 `taskId` 提到了顶层。
|
|
30
|
+
|
|
31
|
+
## [0.53.4] - 2026-11-14 修掉 reopen 的「名实不符」
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- **`localtask reopen` 的 CLI 帮助/输出文案与源码对齐**:源码是 T04 派生模型——按反馈
|
|
36
|
+
**派生一条新编号的 pending 任务**(round+1),旧任务 `done` 保持 done、claimed/pending
|
|
37
|
+
变 `cancelled + supersededBy`,链记在 `task_links`;旧文案却说「回写原任务正文、旧态压进
|
|
38
|
+
history、已完成回到 pending 待再领」,与实现相反。`render` 改成「已派生 #新 ← #旧」。
|
|
39
|
+
- **skill A02 / A03 / B02 与插件主文档同步改正**:写明「不要自己 add 新任务,用 reopen
|
|
40
|
+
派生下一轮」「后续动作都用新编号」「`chain` 读 task_links」;A03 补了旧/新任务状态表、
|
|
41
|
+
反馈段与完成总结 callout、顺链走到当前尖、时间目标重新计时等细节。
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- 语义守卫单测:文档与 CLI 帮助必须出现「派生」、不得再出现「就地重开/同号回写/已完成→
|
|
46
|
+
pending」,A03 必须写明「done 保持 done」——防止旧模型再被写回来。
|
|
47
|
+
|
|
5
48
|
## [0.53.3] - 2026-11-14 skill 按源码校准:命令与参数逐条对齐 action 表
|
|
6
49
|
|
|
7
50
|
### Fixed
|
package/assets/nx-kv/SKILL.md
CHANGED
|
@@ -28,7 +28,7 @@ description: nx-kv 本机任务队列与仓库上下文的**唯一 skill**(原
|
|
|
28
28
|
| **领取指定编号**的任务 | `show --id N` 确认 → `reorder` 提到队首 → `get` 领走 | [[A01-领取任务]] |
|
|
29
29
|
| 阻塞等人回填(本轮最后一步) | `nx-kv localtask get --timeout 60 --json`(项目开了「持续 get」可省参数) | [[A04-阻塞等待与时间目标]] |
|
|
30
30
|
| 干完标完成 | `nx-kv localtask done --id N --summary "…"` | [[A03-完成与重开]] |
|
|
31
|
-
| 用户提修改意见 | `nx-kv localtask reopen --id N
|
|
31
|
+
| 用户提修改意见 | `nx-kv localtask reopen --id N …` 派生下一轮(生成新编号,别自己 add) | [[A03-完成与重开]] |
|
|
32
32
|
| 把本对话的需求交给别的目录 | 提炼 → 自包含任务文本 → `localtask add --cwd …` | [[A02-提交任务]] |
|
|
33
33
|
| 任务带图片/文档附件 | 读 `instruction` 给的本机绝对路径;要加附件用 `attach` | [[A05-附件]] |
|
|
34
34
|
| 「这组仓库是什么、怎么配合」 | `board list --json` → 出关系报告 | [[A06-仓库与项目组]] |
|
|
@@ -45,13 +45,15 @@ nx-kv localtask add "<A 的文本>" --cwd "<目标目录>" --gate --json
|
|
|
45
45
|
正在 wait/get 的 agent 约 0.5 秒内取走,没人等就排队。**记下 `task.id`**,向用户报告
|
|
46
46
|
「已提交到哪个目录(或全局池)、第几号」。
|
|
47
47
|
|
|
48
|
-
## 用户看完结果要改 →
|
|
48
|
+
## 用户看完结果要改 → 用 reopen 派生下一轮,不要自己 add
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
nx-kv localtask reopen --id <n> --
|
|
51
|
+
nx-kv localtask reopen --id <n> --feedback "<用户原话>" --json
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
`reopen` 会**派生一条新编号的 pending 任务**(带上一轮完成总结 + 本轮反馈),旧任务保持
|
|
55
|
+
done / 被取代。已领取/已完成的任务不会再被派发,不走 reopen 就等于需求没提。
|
|
56
|
+
细则见 [[A03-完成与重开]]。
|
|
55
57
|
|
|
56
58
|
## 偏差
|
|
57
59
|
|
package/assets/nx-kv/references/A03-/345/256/214/346/210/220/344/270/216/351/207/215/345/274/200.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# A03 ·
|
|
1
|
+
# A03 · 完成与「按反馈派生下一轮」(reopen)
|
|
2
2
|
|
|
3
3
|
## 三步
|
|
4
4
|
|
|
5
5
|
1. 干完 → `localtask done --id N --summary "…"`(summary 必须写:它是下一轮唯一的上文)。
|
|
6
6
|
2. 若返回 `blocked / goal_not_reached`(时间目标未到)→ **不要硬标**,派 sub agent 重提需求,
|
|
7
7
|
等 `timegoal check` 的 `reached:true` 再 done。
|
|
8
|
-
3. 用户提修改意见 → `localtask reopen --id N
|
|
8
|
+
3. 用户提修改意见 → `localtask reopen --id N …` 让系统**派生下一轮**,不要自己 `add` 一条新任务。
|
|
9
9
|
|
|
10
10
|
## 标完成
|
|
11
11
|
|
|
@@ -13,40 +13,54 @@
|
|
|
13
13
|
nx-kv localtask done --id <n> --summary "改了什么 / 关键决策 / 遗留问题" --json
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
`--summary`
|
|
17
|
-
|
|
16
|
+
`--summary` 记为该任务的终态 + timegoal 日志,也是**下一轮正文里的完成总结 callout**。
|
|
17
|
+
不要写「已完成」「搞定了」。
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
带时间目标的任务(`add --duration`)到点前 `done` 会返回业务结果(不是错误):
|
|
19
|
+
被时间目标挡住时返回业务结果(不是错误):
|
|
22
20
|
|
|
23
21
|
```json
|
|
24
22
|
{ "status":"blocked", "reason":"goal_not_reached", "remainingSec":1830,
|
|
25
23
|
"hint":"时间未到,不能标记完成——请派出 sub agent 重新提出新的需求;到点后…再来标完成" }
|
|
26
24
|
```
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
处理:按 hint 派 sub agent 重提需求,check 返回 `reached:true` 后再 done。
|
|
27
|
+
|
|
28
|
+
## `reopen` 到底是什么(**不是把 done 改回 pending**)
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
源码口径是 **T04 派生模型**:名字叫 reopen,行为是「按反馈**派生一条新任务**」,旧任务定格。
|
|
32
31
|
|
|
33
32
|
```bash
|
|
34
|
-
# 用户给了新诉求原文 →
|
|
33
|
+
# 用户给了新诉求原文 → 新任务正文整篇替换(保住 frontmatter)
|
|
35
34
|
nx-kv localtask reopen --id <n> --text "<改后的正文>" --kind reopen --json
|
|
36
|
-
#
|
|
37
|
-
nx-kv localtask reopen --id <n> --feedback "<用户原话>" --kind
|
|
38
|
-
|
|
35
|
+
# 只想把反馈追加到正文末尾 → 系统自动带上上一轮的完成总结 callout
|
|
36
|
+
nx-kv localtask reopen --id <n> --feedback "<用户原话>" --kind reopen --json
|
|
37
|
+
# 划选评论(不增加轮次)
|
|
38
|
+
nx-kv localtask reopen --id <n> --feedback "<评论>" --kind comment --quote "<划选的原文>" --json
|
|
39
|
+
# 看整条派生链(根 → 当前尖)
|
|
40
|
+
nx-kv localtask chain --id <新任务 id> --json
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
| 对象 | 结果 |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| **旧任务(父)** | `done` **保持 done**(交付事实不消失);若还是 `claimed`/`pending` → `cancelled` + `supersededBy` 指向新任务 |
|
|
46
|
+
| **新任务(子)** | **新编号**、`round = 父 + 1`、状态 `pending` 立即可领;时间目标/依赖/闸门跟着走(重新计时) |
|
|
47
|
+
| **正文** | 给 `--text` 就整篇替换;只给 `--feedback` 就 = 旧正文 + 第 N 轮完成总结 callout + 反馈段(reopen 逐行加粗,comment 不加粗) |
|
|
48
|
+
| **链** | `task_links(src=新, dst=旧, type=reopen\|comment)` 是唯一来源,`chain` 读它;`history[]` 已下线 |
|
|
49
|
+
|
|
50
|
+
两个容易踩的点:
|
|
51
|
+
|
|
52
|
+
- 对**已被取代的 cancelled 任务**再 reopen → 自动顺链走到当前尖,从尖上派生(不会让死记录复活);
|
|
53
|
+
手动作废(无 superseder)的 cancelled 会被拒绝,要继续请新建任务。
|
|
54
|
+
- `--feedback` 的 base 永远是**服务端最新正文**,连续评论不会「评论一次丢一次」。
|
|
55
|
+
|
|
56
|
+
所以:用户改意见 → `reopen`(命令负责建新号、串链、带总结),你随后 `get` 领到的就是
|
|
57
|
+
新编号的下一轮;**不要用原编号去 `done`/`update`**。
|
|
45
58
|
|
|
46
59
|
## 偏差
|
|
47
60
|
|
|
48
61
|
| 偏差 | 正确做法 |
|
|
49
62
|
| --- | --- |
|
|
50
|
-
|
|
|
51
|
-
| `
|
|
52
|
-
|
|
|
63
|
+
| 以为 reopen 把 done 改回 pending、还用原编号继续 | 它是派生新编号;后续动作都用新 id |
|
|
64
|
+
| 用户提意见就自己 `add` 一条 | 用 `reopen`,链和完成总结才不会丢 |
|
|
65
|
+
| `done` 不写 summary | 必须写:下一轮正文会引用它 |
|
|
66
|
+
| 被 `blocked` 后硬改时间 / 绕过 | 按 hint 派 sub agent 重提需求 |
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
| `localtask show` | `--id N` | 看单条(只读,**不领取**) |
|
|
14
14
|
| `localtask list` | — | 全部主题概览(目录、现状、等待中、待领取数) |
|
|
15
15
|
| `localtask done` | `--id N` `--summary "…"` | 标完成;summary 记为本轮终态 + timegoal 日志 |
|
|
16
|
-
| `localtask reopen` | `--id N` `--text` `--kind reopen\|comment` `--quote` `--feedback` |
|
|
16
|
+
| `localtask reopen` | `--id N` `--text` `--kind reopen\|comment` `--quote` `--feedback` | **按反馈派生新任务**(新编号、pending);旧 done 保持 done,链记在 task_links。只给 `--feedback` 时新正文 = 旧正文 + 完成总结 callout + 反馈段 |
|
|
17
17
|
| `localtask chain` | `--id N` | 任务链(origin / reopen / comment / current) |
|
|
18
18
|
| `localtask update` | `--id` `--text` `--duration` `--goal-prompt` `--clear-goal` `--block-by` `--clear-block-by` `--gate true\|false` | 改正文 / 时间目标 / DAG 依赖 / 闸门(`--text` 仅未领取时) |
|
|
19
19
|
| `localtask reorder` | `--id N` `--before-id M` / `--after-id M` | 调序(领指定编号时用) |
|
package/package.json
CHANGED
|
@@ -31,6 +31,7 @@ import { LocaltaskRemoveManyAction } from './localtask-removeMany.js';
|
|
|
31
31
|
import { LocaltaskReopenAction } from './localtask-reopen.js';
|
|
32
32
|
import { LocaltaskReorderAction } from './localtask-reorder.js';
|
|
33
33
|
import { LocaltaskTaskRestoreAction } from './localtask-task-restore.js';
|
|
34
|
+
import { LocaltaskTasksAction } from './localtask-tasks.js';
|
|
34
35
|
import { LocaltaskTimegoalLogAction } from './localtask-timegoalLog.js';
|
|
35
36
|
import { LocaltaskTopicAddAction } from './localtask-topic-add.js';
|
|
36
37
|
import { LocaltaskTopicRemoveAction } from './localtask-topic-remove.js';
|
|
@@ -65,6 +66,7 @@ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
|
|
|
65
66
|
LocaltaskReopenAction,
|
|
66
67
|
LocaltaskReorderAction,
|
|
67
68
|
LocaltaskTaskRestoreAction,
|
|
69
|
+
LocaltaskTasksAction,
|
|
68
70
|
LocaltaskTimegoalLogAction,
|
|
69
71
|
LocaltaskTopicAddAction,
|
|
70
72
|
LocaltaskTopicRemoveAction,
|
|
@@ -99,6 +101,7 @@ export { LocaltaskRemoveManyAction };
|
|
|
99
101
|
export { LocaltaskReopenAction };
|
|
100
102
|
export { LocaltaskReorderAction };
|
|
101
103
|
export { LocaltaskTaskRestoreAction };
|
|
104
|
+
export { LocaltaskTasksAction };
|
|
102
105
|
export { LocaltaskTimegoalLogAction };
|
|
103
106
|
export { LocaltaskTopicAddAction };
|
|
104
107
|
export { LocaltaskTopicRemoveAction };
|
|
@@ -5,6 +5,7 @@ import { action } from '../../../runtime/action-decorator.js';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
7
|
import { renderAdd as _renderAdd } from '../action-render.js';
|
|
8
|
+
import { addView } from '../contract-views.js';
|
|
8
9
|
const renderAdd: any = _renderAdd;
|
|
9
10
|
|
|
10
11
|
/** localtask.add 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
@@ -35,6 +36,7 @@ export class LocaltaskAddAction extends ActionBase<typeof input> {
|
|
|
35
36
|
summary: '向某主题(工作目录)的队列回填一条任务(有 wait 在等则即时投递,否则排队);--global 推到全局共享池;--duration 给任务带时间目标(领取即计时,完成前必须 check);--board/--project 让任务带工作组语义(正文 frontmatter:board + project + 双方介绍引用),并落进该项目的队列;正文自带 frontmatter 时同样认归属——补介绍引用,落点跟到项目队列(显式给过 --cwd 时不挪窝)',
|
|
36
37
|
args: ['text'],
|
|
37
38
|
input,
|
|
39
|
+
output: addView,
|
|
38
40
|
render: renderAdd,
|
|
39
41
|
})
|
|
40
42
|
override async run(ctx: ActionInput<this['_input']>) {
|
|
@@ -49,7 +51,7 @@ export class LocaltaskAddAction extends ActionBase<typeof input> {
|
|
|
49
51
|
const blockBy: any = rawBlock != null && String(rawBlock).trim()
|
|
50
52
|
? normalizeBlockBy(String(rawBlock), 0)
|
|
51
53
|
: [];
|
|
52
|
-
|
|
54
|
+
const r: any = await submitTask({
|
|
53
55
|
text: ctx.text,
|
|
54
56
|
cwd: ctx.cwd,
|
|
55
57
|
summary: ctx.summary,
|
|
@@ -63,6 +65,9 @@ export class LocaltaskAddAction extends ActionBase<typeof input> {
|
|
|
63
65
|
forkOf: ctx.forkOf ?? ctx['fork-of'],
|
|
64
66
|
forkKind: ctx.forkKind ?? ctx['fork-kind'],
|
|
65
67
|
});
|
|
68
|
+
// 出参契约(addView)只回编号:把 task.id 提到顶层(纯附加,原有键不变)
|
|
69
|
+
if (r && r.task && r.task.id != null) r.id = r.task.id;
|
|
70
|
+
return r;
|
|
66
71
|
|
|
67
72
|
}
|
|
68
73
|
}
|
|
@@ -5,6 +5,7 @@ import { action } from '../../../runtime/action-decorator.js';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput, type ActionRunMeta } from '../../../runtime/action-base.js';
|
|
7
7
|
import { renderWait as _renderWait } from '../action-render.js';
|
|
8
|
+
import { claimView } from '../contract-views.js';
|
|
8
9
|
const renderWait: any = _renderWait;
|
|
9
10
|
|
|
10
11
|
/** localtask.claim 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
@@ -22,6 +23,7 @@ export class LocaltaskClaimAction extends ActionBase<typeof input> {
|
|
|
22
23
|
http: ['POST', '/api/localtasks/claim'],
|
|
23
24
|
summary: '领取任务:有任务立即领(含任务级 timegoal 的 check 指令);没任务默认立即返回 timeout,项目开启「持续 get」后自动唤起阻塞窗口等人回填',
|
|
24
25
|
input,
|
|
26
|
+
output: claimView,
|
|
25
27
|
render: renderWait,
|
|
26
28
|
})
|
|
27
29
|
override async run(ctx: ActionInput<this['_input']>, meta: ActionRunMeta = {}) {
|
|
@@ -30,13 +32,17 @@ export class LocaltaskClaimAction extends ActionBase<typeof input> {
|
|
|
30
32
|
const { parseParams } = await (import('../../tasktool/params.js') as any);
|
|
31
33
|
// HTTP:不阻塞、不开浏览器(面板/脚本调用不该挂住请求,也不该弹窗)
|
|
32
34
|
const viaHttp: any = !!(meta && meta.transport === 'http');
|
|
33
|
-
|
|
35
|
+
const r: any = await getTask({
|
|
34
36
|
cwd: ctx.cwd,
|
|
35
37
|
timeoutSec: viaHttp ? undefined : ctx.timeout,
|
|
36
38
|
open: viaHttp ? false : !ctx['no-open'],
|
|
37
39
|
instant: viaHttp ? true : undefined,
|
|
38
40
|
params: parseParams(ctx.param),
|
|
39
41
|
});
|
|
42
|
+
// 出参契约(contract-views.ts 的 claimView)只回编号:把 task.id 提到顶层。
|
|
43
|
+
// 纯附加字段 —— CLI 的 --json 与 HTTP 响应原有键一个不少,只是多了 taskId。
|
|
44
|
+
if (r && r.task && r.task.id != null) r.taskId = r.task.id;
|
|
45
|
+
return r;
|
|
40
46
|
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -5,6 +5,7 @@ import { action } from '../../../runtime/action-decorator.js';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
7
|
import * as serviceNs from '../service.js';
|
|
8
|
+
import { doneView } from '../contract-views.js';
|
|
8
9
|
const service: any = serviceNs;
|
|
9
10
|
|
|
10
11
|
/** localtask.done 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
@@ -22,6 +23,7 @@ export class LocaltaskDoneAction extends ActionBase<typeof input> {
|
|
|
22
23
|
http: ['POST', '/api/localtasks/done'],
|
|
23
24
|
summary: '标记任务完成:--summary 完成总结必填;带时间目标的任务未到点会被拒绝(blocked),到点自动记录最终 check',
|
|
24
25
|
input,
|
|
26
|
+
output: doneView,
|
|
25
27
|
render: (d: any) => {
|
|
26
28
|
if (d.status === 'blocked') {
|
|
27
29
|
// #90:未到点的拦截文案来自可配置的 doneguard 模板(d.guard);模板空/渲染失败
|
|
@@ -6,6 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
7
|
import * as serviceNs from '../service.js';
|
|
8
8
|
import { renderTask as _renderTask } from '../action-render.js';
|
|
9
|
+
import { taskView } from '../contract-views.js';
|
|
9
10
|
const service: any = serviceNs;
|
|
10
11
|
const renderTask: any = _renderTask;
|
|
11
12
|
|
|
@@ -23,6 +24,7 @@ export class LocaltaskGetAction extends ActionBase<typeof input> {
|
|
|
23
24
|
http: ['GET', '/api/localtasks/item'],
|
|
24
25
|
summary: '查看单条任务(按 --id,定位到 --cwd 主题或 --key);正文引用附件时带附件清单与本地路径(自动下载跟随本机设置)',
|
|
25
26
|
input,
|
|
27
|
+
output: taskView,
|
|
26
28
|
render: renderTask,
|
|
27
29
|
})
|
|
28
30
|
override async run(ctx: ActionInput<this['_input']>) {
|
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
import { action } from '../../../runtime/action-decorator.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
|
+
import { reopenView } from '../contract-views.js';
|
|
7
8
|
|
|
8
9
|
/** localtask.reopen 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
9
10
|
const input = z.object({
|
|
10
11
|
id: z.number().describe("任务编号"),
|
|
11
12
|
cwd: z.string().optional(),
|
|
12
13
|
key: z.string().optional(),
|
|
13
|
-
text: z.string().optional().describe("
|
|
14
|
+
text: z.string().optional().describe("下一轮任务正文(Markdown;保住 frontmatter);不给则继承旧正文,只带 --feedback 时追加完成总结+反馈段"),
|
|
14
15
|
kind: z.string().optional().describe("reopen(验收反馈,默认)或 comment(划选评论)"),
|
|
15
16
|
quote: z.string().optional().describe("划选原文(comment 时)"),
|
|
16
|
-
feedback: z.string().optional().describe("
|
|
17
|
+
feedback: z.string().optional().describe("用户反馈原文;派生出的新任务正文会追加反馈段(base = 服务端最新正文,防连续评论丢内容)"),
|
|
17
18
|
feedbackHeading: z.string().optional().describe("追加反馈段的段名(缺省 comment=## 反馈修改 / reopen=## 验收反馈)"),
|
|
18
19
|
feedbackBold: z.boolean().optional().describe("追加的反馈是否逐行加粗(缺省 comment=false / reopen=true)"),
|
|
19
20
|
});
|
|
@@ -23,12 +24,11 @@ export class LocaltaskReopenAction extends ActionBase<typeof input> {
|
|
|
23
24
|
id: 'localtask.reopen',
|
|
24
25
|
cli: ['localtask', 'reopen'],
|
|
25
26
|
http: ['POST', '/api/localtasks/reopen'],
|
|
26
|
-
summary: '
|
|
27
|
+
summary: '按反馈派生下一轮(验收反馈 / 重做 / 评论):新任务新编号、pending 立即可领;旧任务 done 保持 done(claimed/pending → cancelled),链记在 task_links',
|
|
27
28
|
input,
|
|
29
|
+
output: reopenView,
|
|
28
30
|
render: (d: any) =>
|
|
29
|
-
|
|
30
|
-
(d.before?.completedAt ? '(已完成→待领取)' : '') +
|
|
31
|
-
(d.historyId != null ? `;链节点 #${d.historyId}` : '') +
|
|
31
|
+
`已派生 #${d.id} @ ${d.name}(← #${d.parentId}${d.before?.completedAt ? ' 已完成' : ''})` +
|
|
32
32
|
(d.moved && d.movedFrom ? `;已改归属项目,原 ${d.movedFrom.name} #${d.movedFrom.id}` : ''),
|
|
33
33
|
})
|
|
34
34
|
override async run(ctx: ActionInput<this['_input']>) {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// localtask.tasks —— 一个主题的**任务清单**(只回轻量视图,不含正文)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么另开一条而不再给 localtask.list 加 `tasks`:
|
|
4
|
+
// list 的语义是「主题总览」,每个主题都挂着它的全部任务(实测某主题 194 条、
|
|
5
|
+
// 单条正文 200KB 量级),把这些一起塞进总览,端侧每次刷首页都要吞几 MB,
|
|
6
|
+
// 而首页真正要的只是「几个主题、各几条待领」。
|
|
7
|
+
// 要看某个主题的清单时**点名去看这一个**,并只回列表需要的字段:
|
|
8
|
+
// 标题、状态、第几轮、可不可领 —— 正文留给 localtask.get。
|
|
9
|
+
//
|
|
10
|
+
// 这是给端侧(fr 的 nx-kv 原生界面)用的读接口,CLI 上也顺手给了 `localtask tasks`:
|
|
11
|
+
// 一条命令看清某个队列里有什么,不必先 list 再在几 MB JSON 里翻。
|
|
12
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
15
|
+
import * as serviceNs from '../service.js';
|
|
16
|
+
|
|
17
|
+
const service: any = serviceNs;
|
|
18
|
+
|
|
19
|
+
/** localtask.tasks 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
20
|
+
const input = z.object({
|
|
21
|
+
key: z.string().optional().describe('主题键(board/xxx 或 group/xxx)'),
|
|
22
|
+
cwd: z.string().optional().describe('主题绑定的工作目录(不给 --key 时用它定位;都不给=当前目录)'),
|
|
23
|
+
status: z.string().optional().describe('只看某个状态:pending / claimed / done / cancelled'),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 清单里的一行:够 UI 画出一个列表 + 点进详情,**不含正文**。
|
|
28
|
+
*/
|
|
29
|
+
const row = z.object({
|
|
30
|
+
id: z.int().describe('任务编号'),
|
|
31
|
+
status: z.string().describe('pending / claimed / done / cancelled'),
|
|
32
|
+
title: z.string().describe('正文首个标题行(没有标题就取首行,已截断)'),
|
|
33
|
+
round: z.int().describe('第几轮'),
|
|
34
|
+
ready: z.boolean().describe('当前是否可领取'),
|
|
35
|
+
reopenCount: z.int(),
|
|
36
|
+
createdAt: z.string(),
|
|
37
|
+
consumedAt: z.string().describe('被领取的时间;未领取为空串'),
|
|
38
|
+
completedAt: z.string(),
|
|
39
|
+
claimedByName: z.string(),
|
|
40
|
+
roundSummary: z.string().describe('本轮完成总结;未完成时为空串'),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const output = z.object({
|
|
44
|
+
key: z.string().describe('主题键'),
|
|
45
|
+
name: z.string().describe('主题名'),
|
|
46
|
+
cwd: z.string().describe('主题绑定的工作目录'),
|
|
47
|
+
total: z.int().describe('本主题任务总数(未过滤前)'),
|
|
48
|
+
tasks: z.array(row),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** 取正文里的标题:跳过 frontmatter,首个 `#` 标题优先,否则首行;按 80 字截断。 */
|
|
52
|
+
function titleOf(text: unknown): string {
|
|
53
|
+
const raw = String(text ?? '');
|
|
54
|
+
// frontmatter:文件以 --- 开头时,跳到第二个 --- 之后
|
|
55
|
+
let body = raw;
|
|
56
|
+
if (raw.startsWith('---')) {
|
|
57
|
+
const end = raw.indexOf('\n---', 3);
|
|
58
|
+
if (end > 0) body = raw.slice(end + 4);
|
|
59
|
+
}
|
|
60
|
+
const lines = body.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
61
|
+
const heading = lines.find((l) => /^#{1,6}\s+/.test(l));
|
|
62
|
+
const line = (heading ?? lines[0] ?? '').replace(/^#{1,6}\s+/, '');
|
|
63
|
+
return line.length > 80 ? line.slice(0, 80) + '…' : line;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class LocaltaskTasksAction extends ActionBase<typeof input> {
|
|
67
|
+
@action({
|
|
68
|
+
id: 'localtask.tasks',
|
|
69
|
+
cli: ['localtask', 'tasks'],
|
|
70
|
+
http: ['GET', '/api/localtasks/tasks'],
|
|
71
|
+
summary: '看一个主题的任务清单(按 --key 或 --cwd 定位):只回列表需要的字段(标题/状态/轮次/可领),不含正文',
|
|
72
|
+
input,
|
|
73
|
+
output,
|
|
74
|
+
render: (d: any) => {
|
|
75
|
+
const head = `${d.name}(${d.key})· ${d.tasks.length}/${d.total} 条`;
|
|
76
|
+
const rows = d.tasks.map(
|
|
77
|
+
(t: any) => ` #${t.id} [${t.status}] 第${t.round}轮 ${t.title}`,
|
|
78
|
+
);
|
|
79
|
+
return [head, ...rows].join('\n');
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
83
|
+
const { resolveTopicKey } = await (import('../paths.js') as any);
|
|
84
|
+
const key = resolveTopicKey({ key: ctx.key, cwd: ctx.cwd });
|
|
85
|
+
const list: any = await service.listTasks();
|
|
86
|
+
const topic = (list.topics as any[]).find((t) => t.key === key);
|
|
87
|
+
if (!topic) {
|
|
88
|
+
const { badInput } = await (import('../../../core/errors.js') as any);
|
|
89
|
+
throw badInput(`主题不存在: ${key}`);
|
|
90
|
+
}
|
|
91
|
+
const all = (topic.tasks ?? []).filter((t: any) => !t.deletedAt && !t.archivedAt);
|
|
92
|
+
const filtered = ctx.status ? all.filter((t: any) => t.status === ctx.status) : all;
|
|
93
|
+
return {
|
|
94
|
+
key: topic.key,
|
|
95
|
+
name: topic.name,
|
|
96
|
+
cwd: topic.cwd,
|
|
97
|
+
total: all.length,
|
|
98
|
+
tasks: filtered.map((t: any) => ({
|
|
99
|
+
id: t.id,
|
|
100
|
+
status: t.status,
|
|
101
|
+
title: titleOf(t.text),
|
|
102
|
+
round: t.round ?? 1,
|
|
103
|
+
ready: !!t.ready,
|
|
104
|
+
reopenCount: t.reopenCount ?? 0,
|
|
105
|
+
createdAt: t.createdAt ?? '',
|
|
106
|
+
consumedAt: t.consumedAt ?? '',
|
|
107
|
+
completedAt: t.completedAt ?? '',
|
|
108
|
+
claimedByName: t.claimedByName ?? '',
|
|
109
|
+
roundSummary: t.roundSummary ?? '',
|
|
110
|
+
})),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { action } from '../../../runtime/action-decorator.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
7
|
+
import { updateView } from '../contract-views.js';
|
|
7
8
|
|
|
8
9
|
/** localtask.update 的入参契约(CLI 与 HTTP 共用同一份)。 */
|
|
9
10
|
const input = z.object({
|
|
@@ -30,6 +31,7 @@ export class LocaltaskUpdateAction extends ActionBase<typeof input> {
|
|
|
30
31
|
http: ['PATCH', '/api/localtasks/item'],
|
|
31
32
|
summary: '编辑任务内容(按 --id,定位到 --cwd 主题或 --key);可同时改时间目标声明(--duration/--goal-prompt/--clear-goal,仅未领取时可改——领取即计时,起表后声明是既成事实)',
|
|
32
33
|
input,
|
|
34
|
+
output: updateView,
|
|
33
35
|
render: (d: any) =>
|
|
34
36
|
(d.moved
|
|
35
37
|
? `已改归属项目:迁到主题「${d.name}」#${d.task.id}` +
|
|
@@ -63,7 +65,7 @@ export class LocaltaskUpdateAction extends ActionBase<typeof input> {
|
|
|
63
65
|
// 改归属即搬家(任务 #43):正文 effective project 变了 → 任务迁到新项目的队列。
|
|
64
66
|
// 编排在 tasktool/update.js,与派任务(tasktool/add.js)同一套落点判定。
|
|
65
67
|
const { updateTask: editTask } = await (import('../../tasktool/update.js') as any);
|
|
66
|
-
|
|
68
|
+
const r: any = await editTask({
|
|
67
69
|
id: ctx.id,
|
|
68
70
|
text: ctx.text,
|
|
69
71
|
cwd: ctx.cwd,
|
|
@@ -73,6 +75,9 @@ export class LocaltaskUpdateAction extends ActionBase<typeof input> {
|
|
|
73
75
|
clearBlockBy,
|
|
74
76
|
blocksFollowing: ctx.gate,
|
|
75
77
|
});
|
|
78
|
+
// 出参契约(updateView)只回编号:把 task.id 提到顶层(纯附加,原有键不变)
|
|
79
|
+
if (r && r.task && r.task.id != null) r.id = r.task.id;
|
|
80
|
+
return r;
|
|
76
81
|
|
|
77
82
|
}
|
|
78
83
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// localtask 的**跨语言出参视图**(契约用,见 ActionMeta.output)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么单独一个文件:`localtask.get` / `claim` / `done` / `reopen` / `add` / `update`
|
|
4
|
+
// 六条 action 都要往外说话,其中「一条任务长什么样」必须**只写一次**——写成六份,
|
|
5
|
+
// 字段迟早分叉,端侧就会看到「同一个东西,两个名字」。
|
|
6
|
+
//
|
|
7
|
+
// 一条纪律:**这里是视图,不是 service 的返回结构**。
|
|
8
|
+
// · `localtask.list` 刻意不声明 `tasks`(每个主题挂着全部任务,某主题实测 194 条);
|
|
9
|
+
// · `claim` / `done` / `reopen` 刻意不声明 `task` 整体,只给 `taskId`——
|
|
10
|
+
// 端侧要看详情就调 `localtask.get`,别让「领一条」变成「解码一份长正文」;
|
|
11
|
+
// · 声明少了不影响服务端返回(契约不裁剪运行时响应,见设计 §4.3),
|
|
12
|
+
// CLI 与 HTTP 的完整返回一个字都不变。
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
|
|
15
|
+
/** 正文里引用到的一个附件(服务端已标好本地路径与用法)。 */
|
|
16
|
+
export const attachmentView = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
kind: z.string().describe('file / url / task / ref …'),
|
|
19
|
+
kindLabel: z.string().describe('给人看的种类名'),
|
|
20
|
+
name: z.string(),
|
|
21
|
+
sizeText: z.string().describe('已格式化的大小(65.8 KB);url 类可能为空串'),
|
|
22
|
+
isImage: z.boolean(),
|
|
23
|
+
size: z.int().optional(),
|
|
24
|
+
mime: z.string().optional(),
|
|
25
|
+
note: z.string().optional().describe('附件上的备注(原型图、日志…)'),
|
|
26
|
+
localPath: z.string().optional().describe('本机绝对路径;未落盘时为空'),
|
|
27
|
+
exists: z.boolean().optional().describe('本地文件是否还在'),
|
|
28
|
+
needsSync: z.boolean().optional(),
|
|
29
|
+
cmd: z.string().optional().describe('需要同步时给用户的一条命令'),
|
|
30
|
+
usage: z.string().optional().describe('agent/端侧该怎么用它(已在本机就直接读)'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/** 一条任务:端侧详情页要显示的全部字段。 */
|
|
34
|
+
export const taskView = z.object({
|
|
35
|
+
id: z.int().describe('任务编号(主题内自增,跨主题不唯一)'),
|
|
36
|
+
text: z.string().describe('正文(Markdown,可能带 frontmatter)'),
|
|
37
|
+
status: z.string().describe('pending / claimed / done / cancelled'),
|
|
38
|
+
round: z.int().describe('第几轮(每次重开 +1)'),
|
|
39
|
+
roundSummary: z.string().describe('本轮完成总结;未完成时为空串'),
|
|
40
|
+
reopenCount: z.int(),
|
|
41
|
+
childCount: z.int(),
|
|
42
|
+
childRoundCount: z.int(),
|
|
43
|
+
createdAt: z.string(),
|
|
44
|
+
consumedAt: z.string().describe('被领取的时间;未领取为空串'),
|
|
45
|
+
pickupSec: z.int().nullable().describe('入队到领取的秒数;未领取为 null'),
|
|
46
|
+
completedAt: z.string(),
|
|
47
|
+
doneAt: z.string(),
|
|
48
|
+
feedback: z.string().describe('完成总结原文(与服务端历史同一份)'),
|
|
49
|
+
claimedBy: z.string().describe('领取方标识(agent / 端侧)'),
|
|
50
|
+
claimedByName: z.string(),
|
|
51
|
+
claimedFrom: z.string().describe('local / global'),
|
|
52
|
+
ready: z.boolean().describe('当前是否「可领取」'),
|
|
53
|
+
blocksFollowing: z.boolean().describe('是否为闸门任务'),
|
|
54
|
+
blockBy: z.array(z.string()).describe('依赖的任务 id(全部完成后本条才可领)'),
|
|
55
|
+
deletedAt: z.string(),
|
|
56
|
+
archivedAt: z.string(),
|
|
57
|
+
archivedReason: z.string(),
|
|
58
|
+
attachments: z
|
|
59
|
+
.array(attachmentView)
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('正文引用到的附件;标注失败时整个字段缺失(fail-open)'),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 「领一条」的结果视图。
|
|
66
|
+
*
|
|
67
|
+
* status 是**三态闭集**:ok 领到 / timeout 暂时没活 / blocked 被依赖或闸门挡住。
|
|
68
|
+
* 端侧据此决定「进详情」「停在队列」「解释为什么领不了」,不必解析错误文本。
|
|
69
|
+
*
|
|
70
|
+
* 只回**编号**不回整条任务:领到手的那一刻端侧要跳详情,但详情页的正文、
|
|
71
|
+
* 附件、轮次是 `localtask.get` 的活 —— 让「领一条」顺手多解码一份长正文,
|
|
72
|
+
* 是端侧最容易被拖慢的地方(历史某主题一条正文 200KB)。
|
|
73
|
+
*/
|
|
74
|
+
export const claimView = z.object({
|
|
75
|
+
status: z.enum(['ok', 'timeout', 'blocked']).describe('领取结果:ok / timeout / blocked'),
|
|
76
|
+
taskId: z.int().optional().describe('领到的任务编号(status=ok 时有)'),
|
|
77
|
+
name: z.string().optional().describe('主题名'),
|
|
78
|
+
summary: z.string().optional().describe('主题现状'),
|
|
79
|
+
timeoutMs: z.int().optional().describe('timeout 时的等待上限(毫秒)'),
|
|
80
|
+
instant: z.boolean().optional().describe('是否为「没活就立刻回」的即时模式'),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** 「新建一条」的结果视图(只回编号:详情交给 `localtask.get`)。 */
|
|
84
|
+
export const addView = z.object({
|
|
85
|
+
status: z.string(),
|
|
86
|
+
id: z.int().describe('新任务编号'),
|
|
87
|
+
name: z.string().optional().describe('落进哪个主题'),
|
|
88
|
+
cwd: z.string().optional(),
|
|
89
|
+
delivered: z.boolean().optional().describe('是否即时投递给正在 wait 的 agent'),
|
|
90
|
+
queued: z.boolean().optional().describe('是否只是排队等人领取'),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/** 「改正文」的结果视图(只回编号)。 */
|
|
94
|
+
export const updateView = z.object({
|
|
95
|
+
status: z.string(),
|
|
96
|
+
id: z.int().describe('被改的任务编号'),
|
|
97
|
+
name: z.string().optional().describe('当前所在主题'),
|
|
98
|
+
cwd: z.string().optional(),
|
|
99
|
+
moved: z.boolean().optional().describe('是否因归属变了而换了队列'),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/** 「标完成」的结果视图。 */
|
|
103
|
+
export const doneView = z.object({
|
|
104
|
+
status: z.string().describe('ok / blocked'),
|
|
105
|
+
completed: z.boolean().optional().describe('本次是否真的标成了完成'),
|
|
106
|
+
already: z.boolean().optional().describe('之前就已经完成过(无需重复标记)'),
|
|
107
|
+
completedAt: z.string().optional(),
|
|
108
|
+
reason: z.string().optional().describe('blocked 的原因:not_claimed / goal_not_reached …'),
|
|
109
|
+
remainingSec: z.int().optional().describe('时间目标未到点时还差多少秒'),
|
|
110
|
+
deadline: z.string().optional().describe('时间目标的截止时间'),
|
|
111
|
+
hint: z.string().optional().describe('给人看的下一步提示'),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 「重开 / 评论」的结果视图。
|
|
116
|
+
*
|
|
117
|
+
* 注意 `id` 是**新任务**的编号,`parentId` 才是被评论的那条——
|
|
118
|
+
* 端侧提交完评价后应该跳到 `id`,否则会停在一条已经被历史压住的任务上。
|
|
119
|
+
*/
|
|
120
|
+
export const reopenView = z.object({
|
|
121
|
+
status: z.string(),
|
|
122
|
+
id: z.int().describe('重开后产生的新任务编号'),
|
|
123
|
+
parentId: z.int().optional().describe('被重开的原任务编号'),
|
|
124
|
+
kind: z.string().optional().describe('reopen(验收反馈)/ comment(划选评论)'),
|
|
125
|
+
name: z.string().optional(),
|
|
126
|
+
moved: z.boolean().optional().describe('是否因正文里的归属变了而换了队列'),
|
|
127
|
+
reopened: z.boolean().optional(),
|
|
128
|
+
forked: z.boolean().optional(),
|
|
129
|
+
});
|
package/src/runtime/dartgen.ts
CHANGED
|
@@ -53,6 +53,25 @@ function collect(output: TypeNode, models: Map<string, TypeNode & { k: 'model' }
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* 入参去重:同一个 Dart 形参只能出现一次。
|
|
58
|
+
*
|
|
59
|
+
* 为什么会重名:action 的 input 允许「两种写法指向同一个字段」的别名
|
|
60
|
+
* (`--goal-prompt` 与驼峰 `goalPrompt`,CLI 与 HTTP body 各用各的)。
|
|
61
|
+
* 生成器按 camelCase 取形参名,两个别名就撞成同一个 `goalPrompt` ——
|
|
62
|
+
* Dart 侧直接编译不过(duplicate parameter name)。这里按「优先没有连字符的写法」
|
|
63
|
+
* 只留一个:发出去的 body 键名仍然是 action 声明过的,语义不变。
|
|
64
|
+
*/
|
|
65
|
+
function dedupeInput(input: FieldDesc[]): FieldDesc[] {
|
|
66
|
+
const byName = new Map<string, FieldDesc>();
|
|
67
|
+
for (const f of input) {
|
|
68
|
+
const n = dartName(f.name);
|
|
69
|
+
const prev = byName.get(n);
|
|
70
|
+
if (!prev || (prev.name.includes('-') && !f.name.includes('-'))) byName.set(n, f);
|
|
71
|
+
}
|
|
72
|
+
return [...byName.values()];
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
/** Dart 类型名 */
|
|
57
76
|
function dartType(t: TypeNode): string {
|
|
58
77
|
switch (t.k) {
|
|
@@ -155,7 +174,9 @@ function paramOf(f: FieldDesc): string {
|
|
|
155
174
|
: f.kind === 'enum'
|
|
156
175
|
? 'String'
|
|
157
176
|
: 'String';
|
|
158
|
-
|
|
177
|
+
// 位置参数上写 `required` 是语法错误(Dart 只允许命名参数带它):
|
|
178
|
+
// 必填与否已经由「非空类型 + 没有默认值」表达,这里不能再加修饰符。
|
|
179
|
+
return `${type}${f.required ? '' : '?'} ${dartName(f.name)}`;
|
|
159
180
|
}
|
|
160
181
|
|
|
161
182
|
function methodNameOf(id: string, used: Set<string>): string {
|
|
@@ -203,10 +224,11 @@ export function emitDartPackage(snapshot: ContractSnapshot): Record<string, stri
|
|
|
203
224
|
const root = rootModels.get(a.id)!;
|
|
204
225
|
if (root.k !== 'model') throw new Error(`action ${a.id} 的出参不是模型`);
|
|
205
226
|
const [method, path] = (a.http ?? 'GET ').split(' ') as [string, string];
|
|
206
|
-
const
|
|
227
|
+
const fields = dedupeInput(a.input);
|
|
228
|
+
const params = fields.map(paramOf).join(', ');
|
|
207
229
|
const isGet = method === 'GET' || method === 'HEAD';
|
|
208
|
-
const body = isGet ? 'null' : bodyMap(
|
|
209
|
-
const query = isGet ? queryMap(
|
|
230
|
+
const body = isGet ? 'null' : bodyMap(fields);
|
|
231
|
+
const query = isGet ? queryMap(fields) : 'const <String, String>{}';
|
|
210
232
|
methodLines.push(
|
|
211
233
|
[
|
|
212
234
|
...docComment(a.summary, ' '),
|
|
@@ -315,14 +337,17 @@ function queryMap(input: FieldDesc[]): string {
|
|
|
315
337
|
if (!input.length) return 'const <String, String>{}';
|
|
316
338
|
const lines = input.map((f) => {
|
|
317
339
|
const v = dartName(f.name);
|
|
340
|
+
// 必填字段没有「没给」这种状态:它的 Dart 类型就是非空,写 `if (x != null)` 只会
|
|
341
|
+
// 让 analyzer 报 unnecessary_null_comparison(其余 action 里全是要判空的,所以分开写)
|
|
342
|
+
const guard = f.required ? '' : `if (${v} != null) `;
|
|
318
343
|
if (f.kind === 'array') {
|
|
319
|
-
return `
|
|
344
|
+
return ` ${guard}'${f.name}': (${v} as List).join(','),`;
|
|
320
345
|
}
|
|
321
346
|
if (f.kind === 'kv' || f.kind === 'raw') {
|
|
322
|
-
return `
|
|
347
|
+
return ` ${guard}'${f.name}': jsonEncode(${v}),`;
|
|
323
348
|
}
|
|
324
349
|
// 生成 Dart 的 '${x}' 插值:这里用拼接写,避免在模板串里嵌套插值把自己绕晕
|
|
325
|
-
return '
|
|
350
|
+
return ' ' + guard + "'" + f.name + "': '${" + v + "}',";
|
|
326
351
|
});
|
|
327
352
|
return ['<String, String>{', ...lines, ' }'].join('\n');
|
|
328
353
|
}
|
|
@@ -1461,7 +1461,7 @@
|
|
|
1461
1461
|
"action": {
|
|
1462
1462
|
"id": "localtask.reopen",
|
|
1463
1463
|
"module": "localtask",
|
|
1464
|
-
"summary": "
|
|
1464
|
+
"summary": "按反馈派生下一轮(验收反馈 / 重做 / 评论):新任务新编号、pending 立即可领;旧任务 done 保持 done(claimed/pending → cancelled),链记在 task_links",
|
|
1465
1465
|
"usage": "localtask reopen",
|
|
1466
1466
|
"http": "POST /api/localtasks/reopen"
|
|
1467
1467
|
},
|
|
@@ -1508,6 +1508,21 @@
|
|
|
1508
1508
|
}
|
|
1509
1509
|
]
|
|
1510
1510
|
},
|
|
1511
|
+
{
|
|
1512
|
+
"name": "tasks",
|
|
1513
|
+
"path": [
|
|
1514
|
+
"localtask",
|
|
1515
|
+
"tasks"
|
|
1516
|
+
],
|
|
1517
|
+
"action": {
|
|
1518
|
+
"id": "localtask.tasks",
|
|
1519
|
+
"module": "localtask",
|
|
1520
|
+
"summary": "看一个主题的任务清单(按 --key 或 --cwd 定位):只回列表需要的字段(标题/状态/轮次/可领),不含正文",
|
|
1521
|
+
"usage": "localtask tasks",
|
|
1522
|
+
"http": "GET /api/localtasks/tasks"
|
|
1523
|
+
},
|
|
1524
|
+
"children": []
|
|
1525
|
+
},
|
|
1511
1526
|
{
|
|
1512
1527
|
"name": "timegoal-log",
|
|
1513
1528
|
"path": [
|
|
@@ -64,6 +64,7 @@ import type {
|
|
|
64
64
|
LocaltaskReopenAction,
|
|
65
65
|
LocaltaskReorderAction,
|
|
66
66
|
LocaltaskTaskRestoreAction,
|
|
67
|
+
LocaltaskTasksAction,
|
|
67
68
|
LocaltaskTimegoalLogAction,
|
|
68
69
|
LocaltaskTopicAddAction,
|
|
69
70
|
LocaltaskTopicRemoveAction,
|
|
@@ -322,12 +323,14 @@ export interface ApiClient {
|
|
|
322
323
|
localtaskRemove(input: z.input<InstanceType<typeof LocaltaskRemoveAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskRemoveAction>['run']>>>;
|
|
323
324
|
/** 批量删除任务(按 --ids,定位到 --cwd 主题或 --key):一次落盘,逐条软删除(可 restore 恢复);缺失的编号不阻断其余删除 */
|
|
324
325
|
removeMany(input: z.input<InstanceType<typeof LocaltaskRemoveManyAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskRemoveManyAction>['run']>>>;
|
|
325
|
-
/**
|
|
326
|
+
/** 按反馈派生下一轮(验收反馈 / 重做 / 评论):新任务新编号、pending 立即可领;旧任务 done 保持 done(claimed/pending → cancelled),链记在 task_links */
|
|
326
327
|
reopen(input: z.input<InstanceType<typeof LocaltaskReopenAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskReopenAction>['run']>>>;
|
|
327
328
|
/** 调整待领取任务优先级(--id <编号> 移到 --before-id <编号> 前或 --after-id <编号> 后) */
|
|
328
329
|
reorder(input: z.input<InstanceType<typeof LocaltaskReorderAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskReorderAction>['run']>>>;
|
|
329
330
|
/** 恢复一条被删除(软删除)的任务(撤销删除) */
|
|
330
331
|
restore(input: z.input<InstanceType<typeof LocaltaskTaskRestoreAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskTaskRestoreAction>['run']>>>;
|
|
332
|
+
/** 看一个主题的任务清单(按 --key 或 --cwd 定位):只回列表需要的字段(标题/状态/轮次/可领),不含正文 */
|
|
333
|
+
tasks(input?: z.input<InstanceType<typeof LocaltaskTasksAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskTasksAction>['run']>>>;
|
|
331
334
|
/** 查看任务级时间目标的每轮 check 记录(时间、已用/剩余、是否到点、当轮总结) */
|
|
332
335
|
timegoalLog(input: z.input<InstanceType<typeof LocaltaskTimegoalLogAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof LocaltaskTimegoalLogAction>['run']>>>;
|
|
333
336
|
/** 登记一个工作目录:空目录也常驻(prune 不清);--summary 顺带写「现状摘要」(面板顶栏摘要的编辑入口) */
|
|
@@ -1059,6 +1062,18 @@ export function createApiClient(transport: Transport): ApiClient {
|
|
|
1059
1062
|
const body = { "id": inp["id"], "cwd": inp["cwd"], "key": inp["key"] };
|
|
1060
1063
|
return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof LocaltaskTaskRestoreAction>['run']>>;
|
|
1061
1064
|
},
|
|
1065
|
+
// action: localtask.tasks
|
|
1066
|
+
async tasks(input?: z.input<InstanceType<typeof LocaltaskTasksAction>['_input']>) {
|
|
1067
|
+
const inp = input ?? ({} as z.input<InstanceType<typeof LocaltaskTasksAction>['_input']>);
|
|
1068
|
+
let path = `/api/localtasks/tasks`;
|
|
1069
|
+
const q = new URLSearchParams();
|
|
1070
|
+
if (inp["key"] !== undefined) q.set("key", String(inp["key"]));
|
|
1071
|
+
if (inp["cwd"] !== undefined) q.set("cwd", String(inp["cwd"]));
|
|
1072
|
+
if (inp["status"] !== undefined) q.set("status", String(inp["status"]));
|
|
1073
|
+
const query = q.toString();
|
|
1074
|
+
if (query) path += path.includes('?') ? '&' + query : '?' + query;
|
|
1075
|
+
return (await transport.request("GET", path)) as Awaited<ReturnType<InstanceType<typeof LocaltaskTasksAction>['run']>>;
|
|
1076
|
+
},
|
|
1062
1077
|
// action: localtask.timegoalLog
|
|
1063
1078
|
async timegoalLog(input: z.input<InstanceType<typeof LocaltaskTimegoalLogAction>['_input']>) {
|
|
1064
1079
|
const inp = input ?? ({} as z.input<InstanceType<typeof LocaltaskTimegoalLogAction>['_input']>);
|