nx-kv 0.53.4 → 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 CHANGED
@@ -2,6 +2,32 @@
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
+
5
31
  ## [0.53.4] - 2026-11-14 修掉 reopen 的「名实不符」
6
32
 
7
33
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.53.4",
3
+ "version": "0.54.0",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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
- return submitTask({
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
- return getTask({
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,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 { reopenView } from '../contract-views.js';
7
8
 
8
9
  /** localtask.reopen 的入参契约(CLI 与 HTTP 共用同一份)。 */
9
10
  const input = z.object({
@@ -25,6 +26,7 @@ export class LocaltaskReopenAction extends ActionBase<typeof input> {
25
26
  http: ['POST', '/api/localtasks/reopen'],
26
27
  summary: '按反馈派生下一轮(验收反馈 / 重做 / 评论):新任务新编号、pending 立即可领;旧任务 done 保持 done(claimed/pending → cancelled),链记在 task_links',
27
28
  input,
29
+ output: reopenView,
28
30
  render: (d: any) =>
29
31
  `已派生 #${d.id} @ ${d.name}(← #${d.parentId}${d.before?.completedAt ? ' 已完成' : ''})` +
30
32
  (d.moved && d.movedFrom ? `;已改归属项目,原 ${d.movedFrom.name} #${d.movedFrom.id}` : ''),
@@ -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
- return editTask({
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
+ });
@@ -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
- return `${f.required ? 'required ' : ''}${type}${f.required ? '' : '?'} ${dartName(f.name)}`;
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 params = a.input.map(paramOf).join(', ');
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(a.input);
209
- const query = isGet ? queryMap(a.input) : 'const <String, String>{}';
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 ` if (${v} != null) '${f.name}': (${v} as List).join(','),`;
344
+ return ` ${guard}'${f.name}': (${v} as List).join(','),`;
320
345
  }
321
346
  if (f.kind === 'kv' || f.kind === 'raw') {
322
- return ` if (${v} != null) '${f.name}': jsonEncode(${v}),`;
347
+ return ` ${guard}'${f.name}': jsonEncode(${v}),`;
323
348
  }
324
349
  // 生成 Dart 的 '${x}' 插值:这里用拼接写,避免在模板串里嵌套插值把自己绕晕
325
- return ' if (' + v + " != null) '" + f.name + "': '${" + v + "}',";
350
+ return ' ' + guard + "'" + f.name + "': '${" + v + "}',";
326
351
  });
327
352
  return ['<String, String>{', ...lines, ' }'].join('\n');
328
353
  }
@@ -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,
@@ -328,6 +329,8 @@ export interface ApiClient {
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']>);