taskboard-workbench 0.0.0-stage → 0.2.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 +132 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/cli/tb.mjs +314 -0
- package/cordis.patch.yml +5 -0
- package/index.js +633 -0
- package/lib/client.js +522 -0
- package/package.json +83 -4
- package/spec//345/233/242/351/230/237agent.md +171 -0
- package/src/core/advance.mjs +192 -0
- package/src/core/agent-teams.mjs +48 -0
- package/src/core/binding.mjs +44 -0
- package/src/core/config.mjs +22 -0
- package/src/core/debug-dispatch.mjs +94 -0
- package/src/core/delivery.mjs +93 -0
- package/src/core/deps.mjs +53 -0
- package/src/core/diagnostics.mjs +648 -0
- package/src/core/domain.mjs +235 -0
- package/src/core/empty-state.mjs +240 -0
- package/src/core/errors.mjs +139 -0
- package/src/core/executor.mjs +645 -0
- package/src/core/human-review.mjs +773 -0
- package/src/core/intake.mjs +116 -0
- package/src/core/kickoff.mjs +147 -0
- package/src/core/loop.mjs +498 -0
- package/src/core/memory.mjs +193 -0
- package/src/core/next-step.mjs +377 -0
- package/src/core/notify.mjs +183 -0
- package/src/core/owner.mjs +41 -0
- package/src/core/requirements.mjs +262 -0
- package/src/core/review.mjs +82 -0
- package/src/core/session-naming.mjs +64 -0
- package/src/core/split-ask.mjs +107 -0
- package/src/core/store.mjs +3103 -0
- package/src/core/team.mjs +170 -0
- package/src/core/verify.mjs +170 -0
- package/src/core/watchdog.mjs +144 -0
- package/src/host/ai-elaborator.mjs +26 -0
- package/src/host/team-engine.mjs +125 -0
- package/src/host/tool-surface.mjs +205 -0
- package/src/server/api.mjs +1974 -0
- package/src/server/events.mjs +32 -0
- package/src/server/kickoff.mjs +46 -0
- package/src/server/server.mjs +211 -0
- package/src/server/verify.mjs +112 -0
- package/tools/env-check.mjs +35 -0
- package/tools/seed.mjs +67 -0
- package/web/app.js +5237 -0
- package/web/index.html +15 -0
- package/web/tokens.css +1139 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tool-surface.mjs —— 反向链路:把工作台任务暴露给 Code Agent 认领/更新(FR-25/29 + R-WS-34)。
|
|
3
|
+
*
|
|
4
|
+
* 形态:宿主工具面 `taskboard_*`,经 `ctx.tools.register(...)` 注册。
|
|
5
|
+
* - 归属:`exec.agent?.id`(= SessionId)写入任务 session_id(谁在做)。
|
|
6
|
+
* - 项目绑定:按会话 cwd(`exec.agent` 上下文或参数)用 binding 解析项目 + 需求文档。
|
|
7
|
+
* - 创建(FR-29 `taskboard_create_task`):cwd→项目匹配(`matchProjectForCwd`),**未匹配即回落默认项目
|
|
8
|
+
* 并在返回值里如实提示**(`fallback`/`hint`);新建一律 backlog ⇒ 与「backlog 不得执行」同一条红线。
|
|
9
|
+
* - 治理:**执行侧不得写 done**(复用 store.teamSetTaskStatus 的固定红线);backlog 不得认领。
|
|
10
|
+
*
|
|
11
|
+
* 说明:参数用**纯 JSON-schema 对象**(对齐 defineTool 契约,无需 schemastery);
|
|
12
|
+
* `defineTool` 可注入(默认恒等),因此本模块**不静态 import 任何 @deepseek-ai/*,可独立测试**。
|
|
13
|
+
*/
|
|
14
|
+
import { matchProjectForCwd, resolveContext, resolveProjectForCwd } from "../core/binding.mjs";
|
|
15
|
+
import { TbError } from "../core/errors.mjs";
|
|
16
|
+
|
|
17
|
+
const text = (v) => [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v, null, 2) }];
|
|
18
|
+
// 宿主 tools 服务对 JSON-schema 有**子集校验**(dsh-tools/json-schema):`type` 只能是
|
|
19
|
+
// object/array/string/number/integer/boolean/null。旧值 `{type:"json"}` 非法 →
|
|
20
|
+
// `tools register failed: unsupported JSON schema`,导致 taskboard_* 全部注册失败。
|
|
21
|
+
// 这里改用合法对象 schema(放开 additionalProperties,允许任意字段)。
|
|
22
|
+
const tool = (defineTool, spec) => defineTool({ output: { schema: { type: "object", additionalProperties: true }, render: (_a, v) => text(v) }, ...spec });
|
|
23
|
+
|
|
24
|
+
export function registerTaskboardTools({ tools, store, events = null, defineTool = (o) => o } = {}) {
|
|
25
|
+
if (!tools || typeof tools.register !== "function") return () => {};
|
|
26
|
+
const disposers = [];
|
|
27
|
+
const reg = (spec) => disposers.push(tools.register(tool(defineTool, spec)));
|
|
28
|
+
const actorOf = (exec) => exec?.agent?.id ?? exec?.agentId ?? null;
|
|
29
|
+
// 反向链路:Agent 通过工具改任务后,把"失效信号"推给工作台(SSE)→ 看板实时刷新。
|
|
30
|
+
const changed = (task) => { try { events?.publish?.("task.updated", { taskId: task?.id, identifier: task?.identifier, status: task?.status }); } catch { /* ignore */ } };
|
|
31
|
+
|
|
32
|
+
reg({
|
|
33
|
+
name: "taskboard_context",
|
|
34
|
+
description: "返回当前工作区对应的项目与需求文档(工作区→项目→需求文档的初始绑定)。",
|
|
35
|
+
parameters: { cwd: { type: "string", description: "工作目录;省略则用会话所在目录。" } },
|
|
36
|
+
async execute(args, exec) {
|
|
37
|
+
const cwd = args?.cwd ?? exec?.cwd ?? exec?.agent?.cwd ?? null;
|
|
38
|
+
const ctx = resolveContext(store, cwd);
|
|
39
|
+
return { cwd, project: ctx.project ? { id: ctx.project.id, name: ctx.project.name, workspacePath: ctx.project.workspacePath } : null, requirementDoc: ctx.requirementDoc ? { id: ctx.requirementDoc.id, version: ctx.requirementDoc.version } : null };
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
reg({
|
|
44
|
+
name: "taskboard_create_task",
|
|
45
|
+
description: "在会话中顺手指派一条任务(FR-29):按 cwd 落到匹配项目,**未匹配时回落默认项目并在返回里明确提示**(`fallback`/`hint`);返回可引用的编号(identifier)。新建任务一律落「待办池(backlog)」⊂ 未授权,执行侧不得自行推进。",
|
|
46
|
+
parameters: {
|
|
47
|
+
title: { type: "string", required: true, description: "任务标题(必填)。" },
|
|
48
|
+
description: { type: "string", description: "任务描述。" },
|
|
49
|
+
acceptance: { type: "string", description: "完成验收标准(FR-94,便于事后快速复核)。" },
|
|
50
|
+
verifyCommand: { type: "string", description: "复核动作 / 验证命令(FR-94)。" },
|
|
51
|
+
project: { type: "string", description: "显式指定目标项目 id;省略则按 cwd 匹配、未匹配回落默认项目。" },
|
|
52
|
+
priority: { type: "string", description: "优先级:none/low/medium/high/urgent(缺省 none)。" },
|
|
53
|
+
owner: { type: "string", description: "负责人 / 角色。" },
|
|
54
|
+
labels: { type: "string", description: "标签(逗号分隔)。" },
|
|
55
|
+
requirement: { type: "string", description: "关联的需求条目编号(归因,便于之后可开工)。" },
|
|
56
|
+
cwd: { type: "string", description: "工作目录;省略则用会话所在目录。" },
|
|
57
|
+
},
|
|
58
|
+
async execute(args, exec) {
|
|
59
|
+
const cwd = args?.cwd ?? exec?.cwd ?? exec?.agent?.cwd ?? null;
|
|
60
|
+
const explicit = typeof args?.project === "string" && args.project.trim() !== "" ? args.project.trim() : null;
|
|
61
|
+
// 目标项目判定:显式指定 > 会话归属项目 > cwd 匹配(含回落)。三档都要能分清"命中"与"回落"。
|
|
62
|
+
let project = null;
|
|
63
|
+
let fallback = false;
|
|
64
|
+
let reason = "explicit";
|
|
65
|
+
if (explicit) {
|
|
66
|
+
project = store.requireProject(explicit);
|
|
67
|
+
} else {
|
|
68
|
+
const bySession = actorOf(exec) ? store.findProjectBySession(actorOf(exec)) : null;
|
|
69
|
+
if (bySession) {
|
|
70
|
+
project = bySession.project;
|
|
71
|
+
reason = "session";
|
|
72
|
+
} else {
|
|
73
|
+
const m = matchProjectForCwd(store, cwd);
|
|
74
|
+
project = m.project;
|
|
75
|
+
fallback = !m.matched;
|
|
76
|
+
reason = m.matched ? "cwd" : "fallback";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!project) throw new TbError("PROJECT_NOT_FOUND", "没有可用项目:请先建项目,或用 project 显式指定目标项目", { cwd });
|
|
80
|
+
// 执行侧不得自建"已授权"卡:一律 backlog(与「backlog 不得执行」同一条红线)。
|
|
81
|
+
const task = store.createTask({
|
|
82
|
+
projectId: project.id,
|
|
83
|
+
title: args?.title,
|
|
84
|
+
description: args?.description,
|
|
85
|
+
acceptance: args?.acceptance,
|
|
86
|
+
verifyCommand: args?.verifyCommand,
|
|
87
|
+
status: "backlog",
|
|
88
|
+
priority: args?.priority,
|
|
89
|
+
owner: args?.owner,
|
|
90
|
+
labels: args?.labels ?? [],
|
|
91
|
+
// P0:归因**随建卡同事务**(旧实现是「先建卡再关联」⇒ 跨项目报错时会留一张孤儿卡,
|
|
92
|
+
// 这正是无归因卡的一个生产源)。现在跨项目直接整笔回滚:**不建卡、不吃编号**。
|
|
93
|
+
requirementId: args?.requirement ?? null,
|
|
94
|
+
});
|
|
95
|
+
const requirement = task.requirementId ?? null;
|
|
96
|
+
changed(task);
|
|
97
|
+
// FR-29 验收要点③:落在默认项目(cwd 未匹配)时**必须有明确提示** —— 由工具返回值如实带出。
|
|
98
|
+
return {
|
|
99
|
+
identifier: task.identifier,
|
|
100
|
+
title: task.title,
|
|
101
|
+
status: task.status,
|
|
102
|
+
project: { id: project.id, name: project.name, workspacePath: project.workspacePath ?? null },
|
|
103
|
+
matchedBy: reason, // explicit / session / cwd / fallback
|
|
104
|
+
fallback, // true = cwd 无法匹配项目,已回落默认项目
|
|
105
|
+
requirementId: requirement,
|
|
106
|
+
hint: fallback
|
|
107
|
+
? `工作目录 ${cwd ?? "(未知)"} 未匹配任何项目的 workspacePath → **已落到默认项目 ${project.name}(${project.id})**。若不是你要的项目,请重试并显式传 project=<项目id>。`
|
|
108
|
+
: `已落到项目 ${project.name}(${project.id}),任务编号 ${task.identifier}(新建任务在「待办池」,需人工授权开工)。`,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
reg({
|
|
114
|
+
name: "taskboard_list_tasks",
|
|
115
|
+
description: "列出任务(可按项目/状态/负责人过滤)。",
|
|
116
|
+
parameters: { project: { type: "string" }, status: { type: "string" }, owner: { type: "string" }, cwd: { type: "string" } },
|
|
117
|
+
async execute(args, exec) {
|
|
118
|
+
const project = args?.project ? store.requireProject(args.project) : resolveProjectForCwd(store, args?.cwd ?? exec?.cwd);
|
|
119
|
+
const filter = {};
|
|
120
|
+
if (project) filter.projectId = project.id;
|
|
121
|
+
if (args?.status) filter.status = args.status;
|
|
122
|
+
if (args?.owner) filter.owner = args.owner;
|
|
123
|
+
const tasks = store.listTasks(filter);
|
|
124
|
+
return { count: tasks.length, tasks: tasks.map((t) => ({ identifier: t.identifier, title: t.title, status: t.status, priority: t.priority, owner: t.owner, sessionId: t.sessionId ?? null })) };
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
reg({
|
|
129
|
+
name: "taskboard_get_task",
|
|
130
|
+
description: "读取单个任务详情(含评论)。",
|
|
131
|
+
parameters: { ref: { type: "string", required: true } },
|
|
132
|
+
async execute(args) {
|
|
133
|
+
const task = store.requireTaskRef(args.ref);
|
|
134
|
+
return { task, comments: store.listComments(task.id).map((c) => ({ id: c.id, body: c.body, createdAt: c.createdAt })) };
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
reg({
|
|
139
|
+
name: "taskboard_claim_task",
|
|
140
|
+
description: "认领任务(todo→进行中),把当前会话写入归属;backlog 未授权不得认领。",
|
|
141
|
+
parameters: { ref: { type: "string", required: true } },
|
|
142
|
+
async execute(args, exec) {
|
|
143
|
+
const actor = actorOf(exec);
|
|
144
|
+
store.assertAttributed(args.ref); // 归因门(共享断言)
|
|
145
|
+
const r = store.startTaskExecution(args.ref, { sessionId: actor }); // backlog→拒绝;todo→in_progress + session
|
|
146
|
+
changed(r.task);
|
|
147
|
+
return { identifier: r.task.identifier, status: r.task.status, sessionId: r.task.sessionId, launch: r.launch };
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
reg({
|
|
152
|
+
name: "taskboard_comment",
|
|
153
|
+
description: "在任务下追加评论(执行证据/进展)。",
|
|
154
|
+
parameters: { ref: { type: "string", required: true }, body: { type: "string", required: true } },
|
|
155
|
+
async execute(args) {
|
|
156
|
+
const task = store.requireTaskRef(args.ref);
|
|
157
|
+
const c = store.addComment(task.id, { body: args.body });
|
|
158
|
+
changed(task);
|
|
159
|
+
return { commentId: c.id, taskId: task.identifier };
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
reg({
|
|
164
|
+
name: "taskboard_update_status",
|
|
165
|
+
description: "更新任务状态(执行侧可用:进行中/待验收/受阻/取消);**不得写 done**(人工确认)。置「受阻」时可带 kind(dependency/needs_input/capability/transient)以便分类与循环升级;置「待验收」= **请求评审**(FR-83,欢迎带 comment 说明与触发的疑问)。",
|
|
166
|
+
parameters: { ref: { type: "string", required: true }, status: { type: "string", required: true }, kind: { type: "string" }, reason: { type: "string" }, comment: { type: "string" } },
|
|
167
|
+
async execute(args, exec) {
|
|
168
|
+
const actor = actorOf(exec) ?? "agent";
|
|
169
|
+
// FR-80:置「受阻」走统一分类入口(带类型 + 复发升级);
|
|
170
|
+
// FR-83:置「待验收」= 请求评审(记来源列,返工才回得去正确的列);其它状态走原有红线校验
|
|
171
|
+
const task = args.status === "blocked"
|
|
172
|
+
? store.blockTask(args.ref, { kind: args.kind ?? "transient", reason: args.reason ?? null, actor }).task
|
|
173
|
+
: args.status === "in_review"
|
|
174
|
+
? store.requestReview(args.ref, { comment: args.comment ?? "", actor }).task
|
|
175
|
+
: store.teamSetTaskStatus(args.ref, { status: args.status, actor }); // 红线:done→GOVERNANCE_AGENT_DONE
|
|
176
|
+
changed(task);
|
|
177
|
+
return { identifier: task.identifier, status: task.status, blockKind: task.blockKind ?? null, blockRecurrences: task.blockRecurrences ?? 0, triageAt: task.triageAt ?? null };
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
reg({
|
|
182
|
+
name: "taskboard_heartbeat",
|
|
183
|
+
description: "汇报执行心跳(FR-77):表示本执行单元仍在推进。心跳缺失不算失败;超过阈值会被回收认领。可带 note 作为进展备注。",
|
|
184
|
+
parameters: { ref: { type: "string", required: true }, note: { type: "string" } },
|
|
185
|
+
async execute(args) {
|
|
186
|
+
const r = store.heartbeatTask(args.ref, { note: args?.note ?? null });
|
|
187
|
+
const claim = store.taskClaimState(args.ref);
|
|
188
|
+
return { ok: r.ok, reason: r.reason ?? null, at: r.at ?? null, claim };
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
reg({
|
|
193
|
+
name: "taskboard_list_requirements",
|
|
194
|
+
description: "列出当前项目(或指定项目)的需求条目。",
|
|
195
|
+
parameters: { project: { type: "string" }, cwd: { type: "string" } },
|
|
196
|
+
async execute(args, exec) {
|
|
197
|
+
const project = args?.project ? store.requireProject(args.project) : resolveProjectForCwd(store, args?.cwd ?? exec?.cwd);
|
|
198
|
+
if (!project) return { count: 0, items: [] };
|
|
199
|
+
const items = store.listRequirementItems({ projectId: project.id });
|
|
200
|
+
return { project: project.id, count: items.length, items: items.map((i) => ({ identifier: i.identifier, title: i.title, status: i.status, feasibility: i.feasibility })) };
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return () => { for (const d of disposers) { try { d?.(); } catch { /* ignore */ } } };
|
|
205
|
+
}
|