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.
Files changed (75) hide show
  1. package/CHANGELOG.md +403 -0
  2. package/LICENSE +21 -0
  3. package/README.md +210 -2
  4. package/cli/tb.mjs +314 -0
  5. package/cordis.patch.yml +5 -0
  6. package/index.js +633 -0
  7. package/lib/client.js +522 -0
  8. package/package.json +96 -4
  9. package/scripts/tb-flow.mjs +86 -0
  10. package/skills/taskboard-flow/SKILL.md +89 -0
  11. package/skills/taskboard-flow/references/errors.md +61 -0
  12. package/skills/taskboard-flow/references/injection.md +70 -0
  13. package/skills/taskboard-flow/references/steps/S0.md +31 -0
  14. package/skills/taskboard-flow/references/steps/S1.md +28 -0
  15. package/skills/taskboard-flow/references/steps/S2.md +31 -0
  16. package/skills/taskboard-flow/references/steps/S3.md +22 -0
  17. package/skills/taskboard-flow/references/steps/S4.md +25 -0
  18. package/skills/taskboard-flow/references/steps/S5.md +36 -0
  19. package/skills/taskboard-flow/references/steps/S6.md +30 -0
  20. package/skills/taskboard-flow/references/steps/S7.md +23 -0
  21. package/spec/norms/acceptance.md +36 -0
  22. package/spec/norms/card-update.md +39 -0
  23. package/spec/norms/doc-editing.md +30 -0
  24. package/spec/norms/flow.md +45 -0
  25. package/spec/norms/manifest.json +41 -0
  26. package/spec/norms/project-defaults.md +33 -0
  27. package/spec//345/233/242/351/230/237agent.md +171 -0
  28. package/src/core/acceptance.mjs +62 -0
  29. package/src/core/advance.mjs +192 -0
  30. package/src/core/agent-teams.mjs +48 -0
  31. package/src/core/binding.mjs +44 -0
  32. package/src/core/config.mjs +22 -0
  33. package/src/core/contract.mjs +287 -0
  34. package/src/core/debug-dispatch.mjs +94 -0
  35. package/src/core/delivery.mjs +93 -0
  36. package/src/core/deps.mjs +53 -0
  37. package/src/core/diagnostics.mjs +648 -0
  38. package/src/core/domain.mjs +235 -0
  39. package/src/core/empty-state.mjs +240 -0
  40. package/src/core/errors.mjs +142 -0
  41. package/src/core/evidence.mjs +86 -0
  42. package/src/core/executor.mjs +645 -0
  43. package/src/core/human-review.mjs +773 -0
  44. package/src/core/intake.mjs +179 -0
  45. package/src/core/kickoff.mjs +147 -0
  46. package/src/core/loop.mjs +498 -0
  47. package/src/core/memory.mjs +193 -0
  48. package/src/core/next-step.mjs +377 -0
  49. package/src/core/notify.mjs +183 -0
  50. package/src/core/owner.mjs +41 -0
  51. package/src/core/requirements.mjs +292 -0
  52. package/src/core/review.mjs +82 -0
  53. package/src/core/session-naming.mjs +64 -0
  54. package/src/core/split-ask.mjs +107 -0
  55. package/src/core/store.mjs +3442 -0
  56. package/src/core/team.mjs +170 -0
  57. package/src/core/ticket-stage.mjs +150 -0
  58. package/src/core/verify.mjs +170 -0
  59. package/src/core/watchdog.mjs +144 -0
  60. package/src/host/ai-elaborator.mjs +26 -0
  61. package/src/host/team-engine.mjs +125 -0
  62. package/src/host/tool-surface.mjs +205 -0
  63. package/src/mcp/flow-block.mjs +173 -0
  64. package/src/mcp/server.mjs +156 -0
  65. package/src/mcp/tools.mjs +764 -0
  66. package/src/server/api.mjs +2050 -0
  67. package/src/server/events.mjs +32 -0
  68. package/src/server/kickoff.mjs +46 -0
  69. package/src/server/server.mjs +214 -0
  70. package/src/server/verify.mjs +112 -0
  71. package/tools/env-check.mjs +35 -0
  72. package/tools/seed.mjs +67 -0
  73. package/web/app.js +5337 -0
  74. package/web/index.html +15 -0
  75. package/web/tokens.css +1151 -0
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * server.mjs —— Taskboard Workbench MCP server(stdio · 零依赖 · 只读四工具)。
4
+ *
5
+ * 方案依据:§6.1 —— **stdio 而不是 HTTP**:① 不占端口、不碰 `:3080`;② 不需要重载宿主、
6
+ * 不写 `~/.dsh/**`;③ 每个 agent 会话一个进程,天然隔离。数据连**同一个** `taskboard.sqlite`。
7
+ *
8
+ * 用法:
9
+ * node src/mcp/server.mjs --data-dir <dir> # 由 MCP 客户端作为子进程拉起
10
+ * node src/mcp/server.mjs --print-tools # 打印工具清单(调试 / 守卫测试用)
11
+ *
12
+ * 传输:newline-delimited JSON-RPC 2.0(MCP stdio transport)。
13
+ * stdout **只允许**出现协议消息;日志一律走 stderr(否则客户端解析失败)。
14
+ */
15
+ import { createInterface } from "node:readline";
16
+ import { readFileSync } from "node:fs";
17
+ import path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+
20
+ import { openStore } from "../core/store.mjs";
21
+ import { TbError } from "../core/errors.mjs";
22
+ import { TOOLS, TOOL_NAMES, PKG_ROOT } from "./tools.mjs";
23
+ import { buildFlowBlock, readSkill } from "./flow-block.mjs";
24
+
25
+ const argv = process.argv.slice(2);
26
+ const argOf = (name) => {
27
+ const i = argv.indexOf(name);
28
+ return i >= 0 && i + 1 < argv.length ? argv[i + 1] : null;
29
+ };
30
+ const has = (name) => argv.includes(name);
31
+
32
+ if (has("--help") || has("-h")) {
33
+ process.stderr.write(`taskboard-workbench MCP server(9 个工具:只读五 / 写四 · prompt 1)
34
+ 用法: node src/mcp/server.mjs [--data-dir <dir>] [--print-tools]
35
+ 工具: ${TOOL_NAMES.join(", ")}
36
+ 提示: prompt taskboard.flow(= node scripts/tb-flow.mjs start 的输出)
37
+ 数据: --data-dir > $TB_DATA_DIR > 默认(同 Web/CLI)
38
+ `);
39
+ process.exit(0);
40
+ }
41
+
42
+ const pkg = JSON.parse(readFileSync(path.join(PKG_ROOT, "package.json"), "utf8"));
43
+
44
+ if (has("--print-tools")) {
45
+ process.stdout.write(`${JSON.stringify({ name: pkg.name, version: pkg.version, tools: TOOLS.map((t) => t.name) }, null, 2)}\n`);
46
+ process.exit(0);
47
+ }
48
+
49
+ const dataDir = argOf("--data-dir") ?? process.env.TB_DATA_DIR ?? undefined;
50
+ const store = openStore({ dataDir, env: process.env });
51
+ const ctx = { store };
52
+ let skillMeta = null;
53
+ try { skillMeta = readSkill().meta; } catch { /* skill 缺失时不影响工具面;prompts/* 会报出具体原因 */ }
54
+ process.stderr.write(`[tb-mcp] ready dataDir=${store.dataDir} tools=${TOOL_NAMES.join(",")} prompt=taskboard.flow skill=${skillMeta ? `v${skillMeta.version}` : "missing"}\n`);
55
+
56
+ const SERVER_INFO = { name: "taskboard-workbench", version: pkg.version };
57
+ const DEFAULT_PROTOCOL = "2025-06-18";
58
+
59
+ const send = (payload) => {
60
+ if (payload === null || payload === undefined) return;
61
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
62
+ };
63
+ const result = (id, value) => ({ jsonrpc: "2.0", id, result: value });
64
+ const rpcError = (id, code, message, data) => ({ jsonrpc: "2.0", id, error: { code, message, ...(data === undefined ? {} : { data }) } });
65
+
66
+ /** 工具错误 → `isError:true` 的 content(协议层没坏,是这次调用不成立)。 */
67
+ const toolError = (error) => {
68
+ const body = error instanceof TbError
69
+ ? { error: { code: error.code, message: error.message, details: error.details ?? null } }
70
+ : { error: { code: "INTERNAL_ERROR", message: error?.message ?? String(error) } };
71
+ return { content: [{ type: "text", text: JSON.stringify(body, null, 2) }], isError: true };
72
+ };
73
+
74
+ function listTools() {
75
+ return TOOLS.map((t) => ({
76
+ name: t.name,
77
+ description: t.description,
78
+ inputSchema: t.inputSchema,
79
+ annotations: t.annotations,
80
+ }));
81
+ }
82
+
83
+ async function handle(message) {
84
+ if (!message || typeof message !== "object" || Array.isArray(message)) return rpcError(null, -32600, "Invalid Request");
85
+ const { id, method, params } = message;
86
+ const isNotification = id === undefined || id === null;
87
+
88
+ if (method === "initialize") {
89
+ const requested = typeof params?.protocolVersion === "string" ? params.protocolVersion : DEFAULT_PROTOCOL;
90
+ return result(id, { protocolVersion: requested, capabilities: { tools: { listChanged: false }, prompts: { listChanged: false } }, serverInfo: SERVER_INFO });
91
+ }
92
+ if (typeof method === "string" && method.startsWith("notifications/")) return null;
93
+ if (method === "ping") return result(id, {});
94
+ if (method === "tools/list") return result(id, { tools: listTools() });
95
+ if (method === "tools/call") {
96
+ const name = params?.name;
97
+ const tool = TOOLS.find((t) => t.name === name);
98
+ if (!tool) return rpcError(id, -32602, `Unknown tool: ${name ?? "(missing)"}`, { tools: TOOL_NAMES });
99
+ try {
100
+ const value = await tool.handler(ctx, params?.arguments ?? {});
101
+ return result(id, { content: [{ type: "text", text: JSON.stringify(value, null, 2) }], isError: false });
102
+ } catch (error) {
103
+ return result(id, toolError(error));
104
+ }
105
+ }
106
+ // ---- prompts:档 A「一键拉取装载块」 ----
107
+ // 与 `node scripts/tb-flow.mjs start` 共用 buildFlowBlock() ⇒ 两处输出**必须逐字节相同**(守卫测试钉住)。
108
+ if (method === "prompts/list") {
109
+ return result(id, {
110
+ prompts: [{
111
+ name: "taskboard.flow",
112
+ title: "任务看板主流程装载块",
113
+ description: "八步主流程 + 当前项目快照 + 本轮该先做的事(只读;与 `tb-flow start` 同源)",
114
+ arguments: [
115
+ { name: "project", description: "项目 id(省略则按 cwd 匹配)", required: false },
116
+ { name: "cwd", description: "工作目录(默认进程 cwd)", required: false },
117
+ ],
118
+ }],
119
+ });
120
+ }
121
+ if (method === "prompts/get") {
122
+ const name = params?.name;
123
+ if (name !== "taskboard.flow") return rpcError(id, -32602, `Unknown prompt: ${name ?? "(missing)"}`, { prompts: ["taskboard.flow"] });
124
+ const args = params?.arguments ?? {};
125
+ try {
126
+ const block = buildFlowBlock({ store: ctx.store, project: args.project, cwd: args.cwd });
127
+ return result(id, {
128
+ description: `任务看板主流程装载块(${block.project.id} · 契约 ${block.contract.version})`,
129
+ messages: [{ role: "user", content: { type: "text", text: block.text } }],
130
+ });
131
+ } catch (error) {
132
+ return rpcError(id, -32603, error instanceof TbError ? `${error.code}: ${error.message}` : (error?.message ?? String(error)), error instanceof TbError ? { code: error.code, details: error.details ?? null } : undefined);
133
+ }
134
+ }
135
+ if (isNotification) return null;
136
+ return rpcError(id, -32601, `Method not found: ${method ?? "(missing)"}`);
137
+ }
138
+
139
+ const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
140
+ rl.on("line", (line) => {
141
+ const text = line.trim();
142
+ if (text === "") return;
143
+ let message;
144
+ try { message = JSON.parse(text); }
145
+ catch (error) {
146
+ send(rpcError(null, -32700, `Parse error: ${error.message}`));
147
+ return;
148
+ }
149
+ Promise.resolve(handle(message)).then(send).catch((error) => {
150
+ send(rpcError(message?.id ?? null, -32603, error?.message ?? "Internal error"));
151
+ });
152
+ });
153
+ rl.on("close", () => {
154
+ try { store.close(); } catch { /* ignore */ }
155
+ process.exit(0);
156
+ });