taskboard-workbench 0.0.0-stage → 0.3.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 +403 -0
- package/LICENSE +21 -0
- package/README.md +210 -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 +96 -4
- package/scripts/tb-flow.mjs +86 -0
- package/skills/taskboard-flow/SKILL.md +89 -0
- package/skills/taskboard-flow/references/errors.md +61 -0
- package/skills/taskboard-flow/references/injection.md +70 -0
- package/skills/taskboard-flow/references/steps/S0.md +31 -0
- package/skills/taskboard-flow/references/steps/S1.md +28 -0
- package/skills/taskboard-flow/references/steps/S2.md +31 -0
- package/skills/taskboard-flow/references/steps/S3.md +22 -0
- package/skills/taskboard-flow/references/steps/S4.md +25 -0
- package/skills/taskboard-flow/references/steps/S5.md +36 -0
- package/skills/taskboard-flow/references/steps/S6.md +30 -0
- package/skills/taskboard-flow/references/steps/S7.md +23 -0
- package/spec/norms/acceptance.md +36 -0
- package/spec/norms/card-update.md +39 -0
- package/spec/norms/doc-editing.md +30 -0
- package/spec/norms/flow.md +45 -0
- package/spec/norms/manifest.json +41 -0
- package/spec/norms/project-defaults.md +33 -0
- package/spec//345/233/242/351/230/237agent.md +171 -0
- package/src/core/acceptance.mjs +62 -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/contract.mjs +287 -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 +142 -0
- package/src/core/evidence.mjs +86 -0
- package/src/core/executor.mjs +645 -0
- package/src/core/human-review.mjs +773 -0
- package/src/core/intake.mjs +179 -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 +292 -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 +3442 -0
- package/src/core/team.mjs +170 -0
- package/src/core/ticket-stage.mjs +150 -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/mcp/flow-block.mjs +173 -0
- package/src/mcp/server.mjs +156 -0
- package/src/mcp/tools.mjs +764 -0
- package/src/server/api.mjs +2050 -0
- package/src/server/events.mjs +32 -0
- package/src/server/kickoff.mjs +46 -0
- package/src/server/server.mjs +214 -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 +5337 -0
- package/web/index.html +15 -0
- package/web/tokens.css +1151 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ai-elaborator.mjs —— DSH 宿主侧 AI 条目化(FR-36 首选路径)。
|
|
3
|
+
*
|
|
4
|
+
* T-6 结论:DSH 在 Cordis Context 上暴露 `llm` 服务(`LlmRuntime.stream`),
|
|
5
|
+
* **无需发起会话**即可直连一次模型调用。本模块把它包成 api 层可注入的 `aiElaborator`。
|
|
6
|
+
* 规则解析(`store.elaborateRequirementDoc`)保留为 fallback。
|
|
7
|
+
*
|
|
8
|
+
* 说明:真实调用依赖运行期已配置的 provider/model(【需实测】);本文件只做接线。
|
|
9
|
+
*/
|
|
10
|
+
import { buildElaborationMessages, parseElaborationOutput } from "../core/requirements.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {{ llm?: { stream?: Function }, provider?: string, model?: string }} opts
|
|
14
|
+
* @returns {null | ((doc: {body: string}) => Promise<Array<object>>)}
|
|
15
|
+
*/
|
|
16
|
+
export function createLlmElaborator({ llm, provider, model } = {}) {
|
|
17
|
+
if (!llm || typeof llm.stream !== "function" || !provider || !model) return null;
|
|
18
|
+
return async function elaborate(doc) {
|
|
19
|
+
const { system, messages } = buildElaborationMessages(doc.body);
|
|
20
|
+
let text = "";
|
|
21
|
+
for await (const chunk of llm.stream({ provider, model, system, messages })) {
|
|
22
|
+
if (chunk && chunk.type === "text-delta" && typeof chunk.text === "string") text += chunk.text;
|
|
23
|
+
}
|
|
24
|
+
return parseElaborationOutput(text);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* team-engine.mjs —— TeamEnginePort 真实 adapter(切片3 宿主集成)。
|
|
3
|
+
*
|
|
4
|
+
* 对齐 HostSessionPort 的**懒取**模式:每次调用经 getService(name) 现取服务,不 eager 注入。
|
|
5
|
+
* 双实现共用同一接口,差异只在 createDraft 的引擎调用:
|
|
6
|
+
* - instruction(P2,默认):建会话 + 把"派发指令"作为预置内容发给会话;approve 为 no-op。
|
|
7
|
+
* - agent-teams(P1,占位):经 tools.call('agent_teams_create', {approval:'required',...});
|
|
8
|
+
* 不可用时**自动降级**为 instruction 路径(mode="agent-teams-fallback")。T-5 通过后一键切换。
|
|
9
|
+
*
|
|
10
|
+
* 接口:createDraft({teamId,targetTask,targetRequirement,members,tasks}) → {teamId,draft,mode,sessionId?,presetApplied?}
|
|
11
|
+
* approve(teamId) · readTeamStatus(teamId) · subscribeTeamEvents(cb) · mode(getter)
|
|
12
|
+
*/
|
|
13
|
+
import { normalizeQualityGates } from "../core/team.mjs";
|
|
14
|
+
|
|
15
|
+
export const TEAM_ENGINE_MODES = Object.freeze(["instruction", "agent-teams", "official"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 双引擎"下发对接":按引擎生成派发指令(供 P2 会话/工作台回显)。
|
|
19
|
+
* official = DSH 官方自带(spawn_teammate / team_task_*)
|
|
20
|
+
* nanmicoder = @nanmicoder/dsh-agent-teams(agent_teams_create)
|
|
21
|
+
* instruction = 指令降级
|
|
22
|
+
*/
|
|
23
|
+
export function buildTeamDirective({ teamId, targetTask, targetRequirement, members = [], tasks = [], qualityGates = null }, engine = "instruction") {
|
|
24
|
+
// FR-50:质量门链**按项目配置渲染**(顺序 = 配置数组声明顺序);未配置回落契约默认链并注明来源。
|
|
25
|
+
const { gates, source } = normalizeQualityGates({ qualityGates });
|
|
26
|
+
const gateLine = `质量门(${source === "configured" ? "配置" : "默认"}):${gates.join("→")}`;
|
|
27
|
+
const head = engine === "official"
|
|
28
|
+
? `[派发团队 · DSH官方自带] teamId=${teamId}\n请作为 Lead 用 spawn_teammate 召集成员、用 team_task_create 建任务看板。`
|
|
29
|
+
: engine === "nanmicoder"
|
|
30
|
+
? `[派发团队 · @nanmicoder/dsh-agent-teams] teamId=${teamId}\n(引擎:agent_teams_create,approval=required)`
|
|
31
|
+
: `[派发团队] teamId=${teamId}`;
|
|
32
|
+
const lines = [head];
|
|
33
|
+
if (targetTask) lines.push(`目标:${targetTask}`);
|
|
34
|
+
if (targetRequirement) lines.push(`需求:${targetRequirement}`);
|
|
35
|
+
if (members.length) lines.push(`成员:${members.map((m) => (typeof m === "string" ? m : m.role ?? m.name ?? "member")).join("、")}`);
|
|
36
|
+
if (tasks.length) lines.push(`任务:${tasks.map((t) => (typeof t === "string" ? t : t.subject ?? t.title ?? t.task ?? t.id ?? "task")).join(";")}`);
|
|
37
|
+
lines.push(gateLine);
|
|
38
|
+
lines.push("操作指引:按依赖就绪逐个认领 → 执行 → 提交\"待验收\";审查未过不得解锁下游;不得置\"完成\"(人工确认)。");
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildDirective({ teamId, targetTask, targetRequirement, members = [], tasks = [], qualityGates = null }) {
|
|
43
|
+
const lines = [`[派发团队] teamId=${teamId}`];
|
|
44
|
+
if (targetTask) lines.push(`目标:${targetTask}`);
|
|
45
|
+
if (targetRequirement) lines.push(`需求:${targetRequirement}`);
|
|
46
|
+
if (members.length) lines.push(`成员:${members.map((m) => (typeof m === "string" ? m : m.role ?? m.name ?? "member")).join("、")}`);
|
|
47
|
+
if (tasks.length) lines.push(`任务:${tasks.map((t) => (typeof t === "string" ? t : t.subject ?? t.title ?? t.id ?? "task")).join(";")}`);
|
|
48
|
+
// FR-50:P2 指令路径与 `buildTeamDirective` 同口径 —— 质量门链按项目配置渲染,未配置回落默认并注明来源。
|
|
49
|
+
// (2026-10-27 补口:此前只有建队 / 执行循环两条指令带门链,nanmicoder 走 `createDraft` 时丢链 ⇒ 三处口径不一。)
|
|
50
|
+
const { gates, source } = normalizeQualityGates({ qualityGates });
|
|
51
|
+
lines.push(`质量门(${source === "configured" ? "配置" : "默认"}):${gates.join("→")}`);
|
|
52
|
+
lines.push("操作指引:按依赖就绪逐个认领 → 执行 → 提交\"待验收\";审查未过不得解锁下游;不得置\"完成\"(人工确认)。");
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createTeamEnginePort({ getService, mode = "instruction" } = {}) {
|
|
57
|
+
const sessions = () => getService?.("sessions");
|
|
58
|
+
const tools = () => getService?.("tools");
|
|
59
|
+
|
|
60
|
+
/** P2:建会话 + 预置"派发指令"(预置失败不抛错)。 */
|
|
61
|
+
async function instructionDraft(input) {
|
|
62
|
+
const directive = buildDirective(input);
|
|
63
|
+
let sessionId = null;
|
|
64
|
+
let presetApplied = false;
|
|
65
|
+
const api = sessions();
|
|
66
|
+
if (typeof api?.create === "function") {
|
|
67
|
+
try {
|
|
68
|
+
const created = await api.create({});
|
|
69
|
+
sessionId = typeof created === "string" ? created : (created?.sessionId ?? created?.id ?? null);
|
|
70
|
+
} catch {
|
|
71
|
+
sessionId = null;
|
|
72
|
+
}
|
|
73
|
+
if (sessionId && typeof api.sendMessage === "function") {
|
|
74
|
+
try {
|
|
75
|
+
await api.sendMessage(sessionId, directive);
|
|
76
|
+
presetApplied = true;
|
|
77
|
+
} catch {
|
|
78
|
+
presetApplied = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { teamId: input.teamId, mode: "instruction", draft: { directive }, sessionId, presetApplied };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** P1(占位):经 tools.call('agent_teams_create', {approval:'required'});不可用则降级 P2。 */
|
|
86
|
+
async function agentTeamsDraft(input) {
|
|
87
|
+
const t = tools();
|
|
88
|
+
if (typeof t?.call === "function") {
|
|
89
|
+
try {
|
|
90
|
+
const created = await t.call("agent_teams_create", {
|
|
91
|
+
approval: "required",
|
|
92
|
+
name: input.name ?? `team-${input.teamId}`,
|
|
93
|
+
description: input.description ?? "",
|
|
94
|
+
plan: { members: input.members ?? [], tasks: input.tasks ?? [] },
|
|
95
|
+
});
|
|
96
|
+
return { teamId: input.teamId, mode: "agent-teams", draft: created ?? null };
|
|
97
|
+
} catch {
|
|
98
|
+
/* 降级 */
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const fallback = await instructionDraft(input);
|
|
102
|
+
return { ...fallback, mode: "agent-teams-fallback", fallbackReason: "agent-teams-unavailable" };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const implemented = mode === "agent-teams" ? agentTeamsDraft : instructionDraft;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
get mode() {
|
|
109
|
+
return mode;
|
|
110
|
+
},
|
|
111
|
+
createDraft: implemented,
|
|
112
|
+
/** P2:指令已发出,approve 为 no-op;P1 占位(T-5 通过后接 agent_teams_approve)。 */
|
|
113
|
+
async approve() {
|
|
114
|
+
return { approved: true, mode };
|
|
115
|
+
},
|
|
116
|
+
/** 团队状态以本项目 team_runs/team_tasks 为准(api 层读取);此处占位。 */
|
|
117
|
+
async readTeamStatus() {
|
|
118
|
+
return null;
|
|
119
|
+
},
|
|
120
|
+
/** 事件回流:本项目 SSE(api 层已 publish);此处占位。 */
|
|
121
|
+
subscribeTeamEvents() {
|
|
122
|
+
return () => {};
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flow-block.mjs —— 「装载块」的唯一生成器(P4 · 2026-10-29)
|
|
3
|
+
*
|
|
4
|
+
* 三档开局(档 A 人贴 / 档 B 外部 agent 约定 / 将来的档 C 宿主注入)**必须产出同一份文本**,
|
|
5
|
+
* 否则会出现三份不同的说明书 —— 这正是本仓过去栽过的坑(同名两条 SOP,谁都不知道信哪个)。
|
|
6
|
+
*
|
|
7
|
+
* 所以这里只有一处实现:
|
|
8
|
+
* · `node scripts/tb-flow.mjs start` → `buildFlowBlock()`
|
|
9
|
+
* · MCP prompt `taskboard.flow` → `buildFlowBlock()`
|
|
10
|
+
* · 将来的宿主注入(档 C) → 也调 `buildFlowBlock()`
|
|
11
|
+
*
|
|
12
|
+
* **不复制 SKILL.md 的正文**:八步表格与五条硬规则都从 `skills/taskboard-flow/SKILL.md`
|
|
13
|
+
* 的标记区间里**原样抽取**(`<!-- flow-block:steps -->` / `<!-- flow-block:rules -->`)。
|
|
14
|
+
* 这样 skill 改了,装载块跟着改;本文件永远不会"自己长出一份规则"。
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
import { PKG_ROOT, deriveFlowNext, projectGaps, resolveProject } from "./tools.mjs";
|
|
20
|
+
|
|
21
|
+
export const SKILL_DIR = path.join(PKG_ROOT, "skills", "taskboard-flow");
|
|
22
|
+
export const SKILL_PATH = path.join(SKILL_DIR, "SKILL.md");
|
|
23
|
+
|
|
24
|
+
const STEPS_OPEN = "<!-- flow-block:steps -->";
|
|
25
|
+
const STEPS_CLOSE = "<!-- /flow-block:steps -->";
|
|
26
|
+
const RULES_OPEN = "<!-- flow-block:rules -->";
|
|
27
|
+
const RULES_CLOSE = "<!-- /flow-block:rules -->";
|
|
28
|
+
|
|
29
|
+
function sliceBetween(text, open, close) {
|
|
30
|
+
const i = text.indexOf(open);
|
|
31
|
+
const j = text.indexOf(close);
|
|
32
|
+
if (i < 0 || j < 0 || j <= i) return "";
|
|
33
|
+
return text.slice(i + open.length, j).trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 读 SKILL.md 的 frontmatter(只支持本项目用到的 `key: value` 平铺形状)。 */
|
|
37
|
+
function parseFrontmatter(text) {
|
|
38
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
39
|
+
if (!m) return {};
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
42
|
+
const kv = /^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(line.trim());
|
|
43
|
+
if (!kv) continue;
|
|
44
|
+
let value = kv[2].trim();
|
|
45
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
46
|
+
value = value.slice(1, -1).split(",").map((x) => x.trim().replace(/^["']|["']$/g, "")).filter(Boolean);
|
|
47
|
+
} else {
|
|
48
|
+
value = value.replace(/^["']|["']$/g, "");
|
|
49
|
+
if (/^\d+$/.test(value)) value = Number(value);
|
|
50
|
+
}
|
|
51
|
+
out[kv[1]] = value;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 只读:把 skill 的三段(meta / 八步 / 五条硬规则)取出来。 */
|
|
57
|
+
export function readSkill() {
|
|
58
|
+
if (!existsSync(SKILL_PATH)) {
|
|
59
|
+
throw new Error(`skill 缺失:${SKILL_PATH}(打包时请确认 package.json#files 含 "skills")`);
|
|
60
|
+
}
|
|
61
|
+
const text = readFileSync(SKILL_PATH, "utf8");
|
|
62
|
+
const meta = parseFrontmatter(text);
|
|
63
|
+
const steps = sliceBetween(text, STEPS_OPEN, STEPS_CLOSE);
|
|
64
|
+
const rules = sliceBetween(text, RULES_OPEN, RULES_CLOSE);
|
|
65
|
+
if (!steps) throw new Error(`SKILL.md 缺少八步标记区间(${STEPS_OPEN} … ${STEPS_CLOSE})`);
|
|
66
|
+
if (!rules) throw new Error(`SKILL.md 缺少硬规则标记区间(${RULES_OPEN} … ${RULES_CLOSE})`);
|
|
67
|
+
return { meta, steps, rules, path: SKILL_PATH, relPath: "skills/taskboard-flow/SKILL.md" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const shortDigest = (d) => (typeof d === "string" && d.length >= 8 ? `${d.slice(0, 8)}…` : "(未取到)");
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 生成装载块(纯读:不写库、不建目录)。
|
|
74
|
+
*
|
|
75
|
+
* @returns {{text:string, project:object, contract:object, gaps:object, nextStep:object, skill:object}}
|
|
76
|
+
*/
|
|
77
|
+
export function buildFlowBlock({ store, project, cwd, matchedBy } = {}) {
|
|
78
|
+
const skill = readSkill();
|
|
79
|
+
const resolved = project && typeof project === "object"
|
|
80
|
+
? { project, matchedBy: matchedBy ?? "explicit" }
|
|
81
|
+
: resolveProject(store, { project, cwd });
|
|
82
|
+
const { tasks, items, gaps } = projectGaps(store, resolved.project);
|
|
83
|
+
const nextStep = deriveFlowNext({ tasks, items, gaps });
|
|
84
|
+
const snap = store.contractSnapshot(resolved.project.id);
|
|
85
|
+
const snapVersion = snap.snapshot.contractVersion;
|
|
86
|
+
const normOf = (id) => (snap.snapshot.norms ?? []).find((n) => n.id === id);
|
|
87
|
+
const changed = Array.isArray(snap.changed?.changedFiles) ? snap.changed.changedFiles : [];
|
|
88
|
+
|
|
89
|
+
const lines = [
|
|
90
|
+
"# 任务看板主流程 · 装载块",
|
|
91
|
+
"",
|
|
92
|
+
`> 由 taskboard-workbench 生成(skill \`taskboard-flow@v${skill.meta.version ?? "?"}\` · 契约 \`${snapVersion}\`)。`,
|
|
93
|
+
"> 把这一整块当本轮上下文即可开工;**下面第 4 节的八步是全文,不要只看摘要**。",
|
|
94
|
+
"",
|
|
95
|
+
"## 1. 项目",
|
|
96
|
+
"",
|
|
97
|
+
`- id:\`${resolved.project.id}\``,
|
|
98
|
+
`- 名称:${resolved.project.name}`,
|
|
99
|
+
`- 工作区:${resolved.project.workspacePath ? `\`${resolved.project.workspacePath}\`` : "(未设置)"}`,
|
|
100
|
+
`- 主会话:${resolved.project.initialSessionId ? `\`${resolved.project.initialSessionId}\`` : "**未绑定**(投递会落空)"}`,
|
|
101
|
+
`- 匹配方式:${resolved.matchedBy}`,
|
|
102
|
+
"",
|
|
103
|
+
"## 2. 契约",
|
|
104
|
+
"",
|
|
105
|
+
`- contract_version:\`${snapVersion}\``,
|
|
106
|
+
`- 规范:${(snap.snapshot.norms ?? []).map((n) => `${n.id}@v${n.version}(${shortDigest(n.digest)})`).join(" · ")}`,
|
|
107
|
+
`- 与基线比对:${snap.stale ? `**已漂移**(${changed.join(" / ") || "未报出文件"})—— 先读变更部分再动手` : "一致"}`,
|
|
108
|
+
`- 门档:${Object.entries(snap.snapshot.gates ?? {}).map(([k, v]) => `${k}=${v}`).join(" · ")}`,
|
|
109
|
+
"",
|
|
110
|
+
"## 3. 现在缺什么(gaps)",
|
|
111
|
+
"",
|
|
112
|
+
`- 未归因卡:**${gaps.unattributedTasks}**${gaps.unattributedTasks ? `(先补归因再派发,否则 \`EXECUTION_NOT_ATTRIBUTED\`)` : "(干净)"}`,
|
|
113
|
+
`- 未绑定主会话:${gaps.unboundSession ? "**是** ⇒ 回看板「重建/绑定主会话」" : "否"}`,
|
|
114
|
+
`- 待确认候选:**${gaps.pendingCandidates}**${gaps.pendingCandidates > 20 ? "(超阈值 20 ⇒ 先确认/丢弃,别急着条目化)" : ""}`,
|
|
115
|
+
`- 无任务的条目:${gaps.requirementsWithoutTasks} · 评审中卡:${gaps.tasksInReview} · 受阻卡:${gaps.tasksBlocked}`,
|
|
116
|
+
`- 看板:任务 ${tasks.length} · 需求条目 ${items.length}`,
|
|
117
|
+
"",
|
|
118
|
+
"## 4. 本轮该先做",
|
|
119
|
+
"",
|
|
120
|
+
`**${nextStep.step} · ${nextStep.title}** —— ${nextStep.why}`,
|
|
121
|
+
nextStep.humanAction === "authorize" ? "\n> ⚠ 这一步要**人**做(`backlog → todo` 是人工授权),执行侧不得代点。" : "",
|
|
122
|
+
nextStep.humanAction === "accept" ? "\n> ⚠ 这一步要**人**做(`done` 只能人点;评审门 + 人工收口)。" : "",
|
|
123
|
+
"",
|
|
124
|
+
"## 5. 八步(完整定义,取自 `skills/taskboard-flow/SKILL.md`)",
|
|
125
|
+
"",
|
|
126
|
+
skill.steps,
|
|
127
|
+
"",
|
|
128
|
+
"## 6. 五条硬规则(都由门守,不靠自觉)",
|
|
129
|
+
"",
|
|
130
|
+
skill.rules,
|
|
131
|
+
"",
|
|
132
|
+
"## 7. 取规范正文(别凭记忆)",
|
|
133
|
+
"",
|
|
134
|
+
"- 主流程:`norm_get { norm: \"flow\" }`",
|
|
135
|
+
"- 卡片更新(回填要它的 digest):`norm_get { norm: \"card-update\" }`",
|
|
136
|
+
"- 项目自有补充:`norm_get { norm: \"project\", project: \"" + resolved.project.id + "\" }`(读 `<workspace>/AGENTS.md`)",
|
|
137
|
+
"",
|
|
138
|
+
"## 8. 开工前的自检(一条命令)",
|
|
139
|
+
"",
|
|
140
|
+
"```bash",
|
|
141
|
+
`node scripts/tb-flow.mjs start --project ${resolved.project.id} # 与本块同源`,
|
|
142
|
+
"```",
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
text: lines.filter((l) => l !== undefined).join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n",
|
|
147
|
+
project: { id: resolved.project.id, name: resolved.project.name, workspacePath: resolved.project.workspacePath ?? null, matchedBy: resolved.matchedBy },
|
|
148
|
+
contract: { version: snapVersion, stale: Boolean(snap.stale), changed, gates: snap.snapshot.gates ?? {} },
|
|
149
|
+
gaps,
|
|
150
|
+
nextStep,
|
|
151
|
+
skill: { name: skill.meta.name ?? "taskboard-flow", version: skill.meta.version ?? null, requiresContract: skill.meta.requires_contract ?? null, path: skill.relPath },
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 档 B:给项目 `AGENTS.md` 用的片段(只指路,不复制正文)。 */
|
|
156
|
+
export function buildAgentsSnippet({ project, pkgPath } = {}) {
|
|
157
|
+
const pkg = pkgPath ?? PKG_ROOT;
|
|
158
|
+
const proj = project ? ` --project ${project}` : " --project <项目id>";
|
|
159
|
+
return [
|
|
160
|
+
"## 开工(任务看板主流程)",
|
|
161
|
+
"",
|
|
162
|
+
"本项目用 taskboard-workbench 管任务。**动代码之前**先跑:",
|
|
163
|
+
"",
|
|
164
|
+
"```bash",
|
|
165
|
+
`node ${pkg}/scripts/tb-flow.mjs start${proj}`,
|
|
166
|
+
"```",
|
|
167
|
+
"",
|
|
168
|
+
"把输出的「装载块」当本轮上下文:`nextStep` 就是本轮该先做的事,`gaps` 告诉你哪里还欠账。",
|
|
169
|
+
`流程细节见 \`${pkg}/skills/taskboard-flow/SKILL.md\`。`,
|
|
170
|
+
"",
|
|
171
|
+
"> 这段只指路,不替代本文件其余约定。",
|
|
172
|
+
].join("\n");
|
|
173
|
+
}
|