taskboard-workbench 0.3.3 → 0.3.5
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 +75 -0
- package/README.md +1 -1
- package/index.js +10 -0
- package/package.json +1 -1
- package/spec//345/233/242/351/230/237agent.md +18 -0
- package/src/core/cli-dispatch.mjs +90 -0
- package/src/core/diagnostics.mjs +260 -4
- package/src/core/dispatch-target.mjs +144 -0
- package/src/core/executor.mjs +56 -9
- package/src/core/loop.mjs +35 -9
- package/src/core/requirements.mjs +97 -0
- package/src/core/store.mjs +350 -29
- package/src/core/team-bridge.mjs +274 -0
- package/src/core/team.mjs +33 -0
- package/src/host/tool-surface.mjs +15 -2
- package/src/server/api.mjs +349 -13
- package/web/app.js +400 -33
- package/web/tokens.css +24 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 派发目标解析(卡 `-264` / 需求 `R188`)—— **纯逻辑 + 注入探活**,不碰宿主、不写库。
|
|
3
|
+
*
|
|
4
|
+
* 背景(用户原话,2026-11-13):默认指派 dsh 或其他 agent 授权执行任务卡片时,**应优先选取已绑定本项目的
|
|
5
|
+
* 空闲会话接手**;没有绑定会话时,**要求第一次授权**,或在卡片点「执行」时**把授权指令一并带进去**。
|
|
6
|
+
*
|
|
7
|
+
* 此前行为:`/api/tasks/:ref/execute` 在没显式给 sessionId 时**一律新建会话** ——
|
|
8
|
+
* · 每派一张卡就多一条孤立会话(`project_sessions` 无行),只能靠 `-263` 的派生绑定才不被门挡住;
|
|
9
|
+
* · 项目里明明有空闲的主会话 / 已批准会话,却完全没被利用(主会话闲着也不用)。
|
|
10
|
+
*
|
|
11
|
+
* 判据分层(**只选判得出空闲的**,判不准一律不算 —— 不猜):
|
|
12
|
+
* 1. 主会话(`projects.initial_session_id`)
|
|
13
|
+
* 2. 已批准关联会话(`project_sessions.status='approved'`,最近活跃优先)
|
|
14
|
+
* 3. 派生执行会话(`tasks.session_id`,`-263`)—— **仅当它名下没有 `in_progress` 卡**(干完了待验收的才算空闲)
|
|
15
|
+
* 空闲 = 宿主判得出:`exists !== false && live === true && running === false && pending === 0`。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** 会话是否「此刻空闲」——判不准(live=false / 无宿主通道 / 存在性未知但无 live)一律 false。 */
|
|
19
|
+
export function isIdleLiveness(liveness) {
|
|
20
|
+
if (!liveness || typeof liveness !== "object") return false;
|
|
21
|
+
if (liveness.exists === false) return false; // 确认失效
|
|
22
|
+
if (liveness.live !== true) return false; // 进程内没有 Agent ⇒ 不知道它空不空闲(不猜)
|
|
23
|
+
if (liveness.running === true) return false; // 正在跑
|
|
24
|
+
if (Number(liveness.pending ?? 0) > 0) return false; // inbox 里还有没消费的指令
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 候选来源的**验收口径命名** —— `main` / `approved` / `executor`(需求 `R188` 验收①点名的三档)。
|
|
30
|
+
*
|
|
31
|
+
* 为什么另起一档(不直接用 `role`):`role` 是**内部**说法(`associated` = 已批准关联会话),
|
|
32
|
+
* 而验收条款对外说的是「main / approved / executor」—— 对外回包与界面文案用 `kind`,
|
|
33
|
+
* 免得「同一个东西两个名字」在回包里对不上。
|
|
34
|
+
*/
|
|
35
|
+
const REUSED_FROM_KINDS = { main: "main", associated: "approved", executor: "executor" };
|
|
36
|
+
|
|
37
|
+
/** 把内部 `role` 映射成验收口径的来源名(认不出来的角色 ⇒ null,不臆断)。 */
|
|
38
|
+
export function reusedFromKind(role) {
|
|
39
|
+
return Object.prototype.hasOwnProperty.call(REUSED_FROM_KINDS, role) ? REUSED_FROM_KINDS[role] : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 枚举「已绑定本项目的会话」候选(**未探活**,纯读库)。
|
|
44
|
+
* 顺序 = 主会话 > 已批准关联 > 派生执行会话;同一会话只出现一次(高优先级的那条胜出)。
|
|
45
|
+
*/
|
|
46
|
+
export function listBoundCandidates(store, projectId) {
|
|
47
|
+
const project = store.getProject(projectId) ?? null;
|
|
48
|
+
const out = [];
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
const push = (item) => {
|
|
51
|
+
if (!item?.sessionId || seen.has(item.sessionId)) return;
|
|
52
|
+
seen.add(item.sessionId);
|
|
53
|
+
out.push(item);
|
|
54
|
+
};
|
|
55
|
+
if (project?.initialSessionId) push({ sessionId: project.initialSessionId, role: "main", kind: "main", source: "project-main" });
|
|
56
|
+
const approved = (store.listProjectSessions(projectId) ?? [])
|
|
57
|
+
.filter((row) => row.sessionId && row.status === "approved")
|
|
58
|
+
.sort((a, b) => String(b.updatedAt ?? "").localeCompare(String(a.updatedAt ?? "")));
|
|
59
|
+
for (const row of approved) push({ sessionId: row.sessionId, role: "associated", kind: "approved", source: "project-approved", updatedAt: row.updatedAt ?? null });
|
|
60
|
+
// 派生执行会话:名下只要还有 in_progress 卡,就说明它正干着别的活 —— 不作为「空闲候选」。
|
|
61
|
+
for (const ex of store.listExecutorSessions(projectId) ?? []) {
|
|
62
|
+
const statuses = Array.isArray(ex.statuses) ? ex.statuses : [];
|
|
63
|
+
if (statuses.includes("in_progress")) continue;
|
|
64
|
+
push({ sessionId: ex.sessionId, role: "executor", kind: "executor", source: "task-derived", updatedAt: ex.lastActivityAt ?? null, tasks: ex.tasks ?? [] });
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 选出派发目标。返回:
|
|
71
|
+
* ```
|
|
72
|
+
* { decision: "reuse" | "create-and-authorize",
|
|
73
|
+
* target: { sessionId, role, kind, source, liveness } | null,
|
|
74
|
+
* candidates: [{ sessionId, role, kind, source, idle, why, liveness }],
|
|
75
|
+
* reason }
|
|
76
|
+
* ```
|
|
77
|
+
* `sessionStateOf(sessionId)` / `sessionOriginOf(sessionId, project)` 由调用方注入(api 层已有同一份实现,
|
|
78
|
+
* 这里**不另写第二份探活**)。
|
|
79
|
+
*/
|
|
80
|
+
export async function pickDispatchTarget(store, projectId, { sessionStateOf = null, sessionOriginOf = null } = {}) {
|
|
81
|
+
const project = store.getProject(projectId) ?? null;
|
|
82
|
+
const candidates = [];
|
|
83
|
+
for (const c of listBoundCandidates(store, projectId)) {
|
|
84
|
+
// 归属校验:别把**别的项目工作区**的会话派给这张卡(FR-84 的同一把尺子)。
|
|
85
|
+
let origin = null;
|
|
86
|
+
if (typeof sessionOriginOf === "function") {
|
|
87
|
+
try { origin = await sessionOriginOf(c.sessionId, project); } catch { origin = null; }
|
|
88
|
+
}
|
|
89
|
+
let liveness = null;
|
|
90
|
+
if (typeof sessionStateOf === "function") {
|
|
91
|
+
try { liveness = await sessionStateOf(c.sessionId); } catch { liveness = null; }
|
|
92
|
+
}
|
|
93
|
+
let why = null;
|
|
94
|
+
let idle = false;
|
|
95
|
+
if (origin?.mismatch === true) why = "other-workspace";
|
|
96
|
+
else if (!liveness) why = "no-liveness";
|
|
97
|
+
else if (liveness.exists === false) why = "session-gone";
|
|
98
|
+
else if (liveness.live !== true) why = "liveness-unknown";
|
|
99
|
+
else if (liveness.running === true) why = "running";
|
|
100
|
+
else if (Number(liveness.pending ?? 0) > 0) why = "pending-prompts";
|
|
101
|
+
else { idle = true; why = "idle"; }
|
|
102
|
+
candidates.push({ ...c, idle, why, liveness, originCwd: origin?.cwd ?? null });
|
|
103
|
+
}
|
|
104
|
+
const hit = candidates.find((c) => c.idle) ?? null;
|
|
105
|
+
return {
|
|
106
|
+
decision: hit ? "reuse" : "create-and-authorize",
|
|
107
|
+
target: hit ? { sessionId: hit.sessionId, role: hit.role, kind: hit.kind ?? reusedFromKind(hit.role), source: hit.source, liveness: hit.liveness } : null,
|
|
108
|
+
candidates,
|
|
109
|
+
reason: hit ? "bound-idle" : (candidates.length ? "bound-but-busy-or-unknown" : "no-bound-session"),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 投给**复用会话**的任务书。与 CLI 任务书(`executor.mjs#buildTaskPrompt`)不同:
|
|
115
|
+
* 这是给**宿主会话**的短指令 —— 它本来就在工作区里,不需要 `--add-dir` / `cd` 那一套。
|
|
116
|
+
* 但必须说清三件事:① 已授权(别再申请关联);② 回写口径(四节);③ 红线(不得置 done)。
|
|
117
|
+
*/
|
|
118
|
+
export function buildReuseDirective({ task, project, target = null } = {}) {
|
|
119
|
+
const lines = [
|
|
120
|
+
`任务 ${task?.identifier ?? ""}:${task?.title ?? ""}`,
|
|
121
|
+
``,
|
|
122
|
+
`本会话已绑定项目「${project?.name ?? project?.id ?? ""}」(${project?.id ?? ""})—— 工作台不会挡你;`,
|
|
123
|
+
`这是**已授权**的派发(来源:${target?.role ?? "已绑定会话"}),**不需要再申请关联**。`,
|
|
124
|
+
];
|
|
125
|
+
if (task?.acceptance) lines.push(`验收:${task.acceptance}`);
|
|
126
|
+
if (task?.verifyCommand) lines.push(`复核动作:${task.verifyCommand}`);
|
|
127
|
+
lines.push("操作指引:执行 → 回写四节证据(判定 / 偏离说明 / 边界自查 / 产物路径)→ 提交「待验收」;**不得置「完成」**(人工确认)。");
|
|
128
|
+
lines.push("若本会话正在处理别的任务:先做完或显式说明冲突,不要静默丢弃本单。");
|
|
129
|
+
return lines.join("\n");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 投给**新建会话**的授权段(会拼进 `createSession({preset})` 与任务书)。 */
|
|
133
|
+
export function buildAuthorizationDirective({ task, project, sessionId = null } = {}) {
|
|
134
|
+
return [
|
|
135
|
+
`【授权】本会话由看板「启动执行」显式授权,**首次绑定**项目「${project?.name ?? project?.id ?? ""}」(${project?.id ?? ""})。`,
|
|
136
|
+
`你**不得再申请**关联(本会话已被授权),配置页「会话关联」会显示本会话;工作台不会挡你。`,
|
|
137
|
+
task?.identifier ? `本单:任务 ${task.identifier}:${task.title}` : "",
|
|
138
|
+
// 与**复用路径**的任务书对齐:新建出来的会话同样是「空手接单」,不告诉它验收标准与复核动作,
|
|
139
|
+
// 它就只能凭标题猜「做成什么样算做完」。(`R188` 判据锚点:任务书要写明哪张卡 + 回写与红线。)
|
|
140
|
+
task?.acceptance ? `验收:${task.acceptance}` : "",
|
|
141
|
+
task?.verifyCommand ? `复核动作:${task.verifyCommand}` : "",
|
|
142
|
+
`完成后回写四节证据并提交「待验收」;**不得置「完成」**(人工确认)。`,
|
|
143
|
+
].filter(Boolean).join("\n");
|
|
144
|
+
}
|
package/src/core/executor.mjs
CHANGED
|
@@ -71,15 +71,58 @@ export function resolveCliExecutor(settings, { role = "engineer" } = {}) {
|
|
|
71
71
|
?? null;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* 派发工作目录(2026-11-13 · 方案 A)。
|
|
76
|
+
*
|
|
77
|
+
* **背景(真机事故)**:本项目 `project.workspacePath` = `00-project-real`,而前端卡片的目标文件在
|
|
78
|
+
* 兄弟目录 `00-project-realdemo/app-vue/`。派单器把 `workspacePath` 同时用作 ① `--add-dir`、
|
|
79
|
+
* ② 任务书 Step 0 的 `cd`、③ 硬边界那句「只允许改 X 内的文件」,于是三处一起指错:
|
|
80
|
+
* CLI 的写权限收敛在 `00-project-real`,目标文件在界外 —— 执行器在 Step 0 就得停(且停得对)。
|
|
81
|
+
*
|
|
82
|
+
* 修法:把「派发目录」与「文档/仓库工作区」解耦。`teamTemplate.engineer.cwd` 一旦配置,
|
|
83
|
+
* 上面三处统一改用它;不配置即**逐字节**维持旧行为(零回归)。
|
|
84
|
+
*/
|
|
85
|
+
export function resolveDispatchDir({ project, settings } = {}) {
|
|
86
|
+
const raw = settings?.teamTemplate?.engineer?.cwd;
|
|
87
|
+
const cwd = typeof raw === "string" && raw.trim() ? raw.trim() : null;
|
|
88
|
+
return cwd ?? project?.workspacePath ?? null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 硬边界指向的路径(写进任务书那句「只允许改 …… 内的文件」)。
|
|
93
|
+
*
|
|
94
|
+
* `teamTemplate.engineer.writable` 是**相对派发目录**的子路径(如 `app-vue`):
|
|
95
|
+
* 配了就渲染成 `<派发目录>/app-vue`,没配就是整个派发目录。
|
|
96
|
+
* 注意:这是**文字边界**,不是 ACL —— 真正的进程级收敛仍是 `--add-dir`(见 `cliArgsFor`)。
|
|
97
|
+
*/
|
|
98
|
+
export function resolveWritableScope({ project, settings } = {}) {
|
|
99
|
+
const dir = resolveDispatchDir({ project, settings });
|
|
100
|
+
// 既有字段优先:`teamTemplate.writeScope`(数组,本项目原本就写着 ["scada-docs/", ".doc-backups/"],
|
|
101
|
+
// 但此前**没有任何代码读它** —— 边界那行一直只渲染整个 workspacePath)。
|
|
102
|
+
// 条目语义:相对派发目录;以 `/` 开头的当绝对路径用(这样不换 cwd 也能放行兄弟目录)。
|
|
103
|
+
const list = settings?.teamTemplate?.writeScope;
|
|
104
|
+
const fromScope = Array.isArray(list) ? list.map(String).map((x) => x.trim()).filter(Boolean) : [];
|
|
105
|
+
const single = settings?.teamTemplate?.engineer?.writable;
|
|
106
|
+
const items = fromScope.length ? fromScope
|
|
107
|
+
: (typeof single === "string" && single.trim() ? [single.trim()] : []);
|
|
108
|
+
if (!items.length) return dir;
|
|
109
|
+
const abs = items.map((x) => (x.startsWith("/") ? x : (dir ? `${dir}/${x.replace(/^\.\//, "")}` : x)));
|
|
110
|
+
return abs.join("、");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** CLI 参数:非交互 + 显式放行工具 + 允许访问派发目录(可被设置里的 `engineer.args` 覆盖)。 */
|
|
75
114
|
export function cliArgsFor({ executorId, cwd, settings }) {
|
|
76
115
|
const override = settings?.teamTemplate?.engineer?.args;
|
|
77
116
|
if (Array.isArray(override) && override.length) return override.map(String);
|
|
117
|
+
const extra = Array.isArray(settings?.teamTemplate?.engineer?.extraDirs)
|
|
118
|
+
? settings.teamTemplate.engineer.extraDirs.map(String).filter((d) => d.trim())
|
|
119
|
+
: [];
|
|
78
120
|
return [
|
|
79
121
|
"-p",
|
|
80
122
|
"--permission-mode", "acceptEdits",
|
|
81
123
|
"--allowedTools", String(settings?.teamTemplate?.engineer?.allowedTools ?? DEFAULT_ALLOWED_TOOLS),
|
|
82
124
|
"--add-dir", cwd,
|
|
125
|
+
...extra.flatMap((d) => ["--add-dir", d]),
|
|
83
126
|
];
|
|
84
127
|
}
|
|
85
128
|
|
|
@@ -119,8 +162,8 @@ export function argsAllowEdits(args) {
|
|
|
119
162
|
* 本函数产出的就是「要嵌进外层 ``` 围栏」的正文,故正文内**任何代码块一律 4 反引号**。
|
|
120
163
|
* §一 硬规则 #2:**每个 Step 必须同时给判据与停下情形**,缺一即为不合格模板。
|
|
121
164
|
*/
|
|
122
|
-
export function buildTaskPrompt(task, { project, requirementId = null, verifyCommand = null } = {}) {
|
|
123
|
-
const cwd = project
|
|
165
|
+
export function buildTaskPrompt(task, { project, settings = null, requirementId = null, verifyCommand = null } = {}) {
|
|
166
|
+
const cwd = resolveDispatchDir({ project, settings });
|
|
124
167
|
const steps = [
|
|
125
168
|
`## Step 0 — 预检(只读,不通过就停)`,
|
|
126
169
|
``,
|
|
@@ -151,7 +194,7 @@ export function buildTaskPrompt(task, { project, requirementId = null, verifyCom
|
|
|
151
194
|
`- ❌ 不删任何既有数据(任务 / 看板项目 / 需求条目)。`,
|
|
152
195
|
`- ❌ 不改本任务范围外的文件;共享文件(core/store、server/api、web/app.js)改动保持最小。`,
|
|
153
196
|
`- ❌ **不自行置「完成(done)」** —— 完成只能由人确认,你只提交「待验收」。`,
|
|
154
|
-
|
|
197
|
+
resolveWritableScope({ project, settings }) ? `- ✅ 只允许改 ${resolveWritableScope({ project, settings })} 内的文件。` : "",
|
|
155
198
|
`- ✅ 隔离验证用临时目录 / 临时端口 / 独立进程,跑完即删。`,
|
|
156
199
|
``,
|
|
157
200
|
`## 已知前置`,
|
|
@@ -390,14 +433,18 @@ export function pathsOfStatusLines(lines = []) {
|
|
|
390
433
|
* 终态仍由写回决定(成功 → 待验收;失败 → 统一受阻入口)。
|
|
391
434
|
*
|
|
392
435
|
* 任何一步失败都不阻断执行——执行结果仍会如实写回看板。
|
|
436
|
+
*
|
|
437
|
+
* `sessionId`(卡 `-257` / 需求 `R183`):经项目主会话下发的执行**必须**把会话标识一并落到
|
|
438
|
+
* `tasks.session_id` 与 `task_runs.session_id` —— 否则「打开执行会话」指不到记录所在的那条会话,
|
|
439
|
+
* 本轮要修的正是这个可观察性缺口。直跑路径不传(保持 `null`,与既有读数一致)。
|
|
393
440
|
*/
|
|
394
|
-
export function claimForCliExecution(store, ref, { actor = "cli-executor" } = {}) {
|
|
441
|
+
export function claimForCliExecution(store, ref, { actor = "cli-executor", sessionId = null } = {}) {
|
|
395
442
|
const outcome = { claimed: false, runStarted: false, fromStatus: null, toStatus: null, note: null };
|
|
396
443
|
try {
|
|
397
444
|
const fresh = store.requireTaskRef(ref);
|
|
398
445
|
outcome.fromStatus = fresh.status;
|
|
399
446
|
if (fresh.status === "todo") {
|
|
400
|
-
store.startTaskExecution(fresh.identifier, { sessionId
|
|
447
|
+
store.startTaskExecution(fresh.identifier, { sessionId });
|
|
401
448
|
outcome.claimed = true;
|
|
402
449
|
outcome.note = "authorized";
|
|
403
450
|
} else if (fresh.status !== "in_progress") {
|
|
@@ -413,7 +460,7 @@ export function claimForCliExecution(store, ref, { actor = "cli-executor" } = {}
|
|
|
413
460
|
}
|
|
414
461
|
const cur = store.requireTaskRef(fresh.identifier);
|
|
415
462
|
if (cur.status === "in_progress" && typeof store.getCurrentRun === "function" && !store.getCurrentRun(cur)) {
|
|
416
|
-
store.startTaskRun(cur.identifier, { actor });
|
|
463
|
+
store.startTaskRun(cur.identifier, { actor, sessionId });
|
|
417
464
|
outcome.runStarted = true;
|
|
418
465
|
}
|
|
419
466
|
outcome.toStatus = store.requireTaskRef(fresh.identifier).status;
|
|
@@ -433,14 +480,14 @@ export async function runCliExecutor({
|
|
|
433
480
|
argsOverride = null, promptVia = "stdin",
|
|
434
481
|
} = {}) {
|
|
435
482
|
if (!executor?.cli) return { started: false, reason: "no-cli-executor" };
|
|
436
|
-
const workdir = cwd ?? project
|
|
483
|
+
const workdir = cwd ?? resolveDispatchDir({ project, settings }) ?? null;
|
|
437
484
|
if (!workdir) return { started: false, reason: "no-workspace", executorId: executor.id };
|
|
438
485
|
// 测试/离线替身:`TB_CLI_EXECUTOR_BIN` 指定可执行文件时优先使用(不改 executor id 语义)。
|
|
439
486
|
// `binPath` 优先于裸命令名:宿主由 launchd 拉起时 PATH 常缺 `~/.npm-global/bin`,
|
|
440
487
|
// 只写命令名会在 `exec-cli` 真跑时报 ENOENT(探测到绝对路径就用它)。
|
|
441
488
|
// `TB_CLI_EXECUTOR_BIN` 仍是最高优先(测试/离线替身语义不变)。
|
|
442
489
|
const cli = String(env?.TB_CLI_EXECUTOR_BIN ?? "") || executor.binPath || executor.cli;
|
|
443
|
-
const prompt = buildTaskPrompt(task, { project, requirementId, verifyCommand });
|
|
490
|
+
const prompt = buildTaskPrompt(task, { project, settings, requirementId, verifyCommand });
|
|
444
491
|
const explicitArgs = Array.isArray(argsOverride) && argsOverride.length ? argsOverride.map(String) : null;
|
|
445
492
|
const args = explicitArgs ?? cliArgsFor({ executorId: executor.id, cwd: workdir, settings });
|
|
446
493
|
// 参数来源与「能不能写文件」都要如实记进结果(证据与状态都取它,见 isBlindRun)。
|
package/src/core/loop.mjs
CHANGED
|
@@ -12,7 +12,17 @@ import { normalizeQualityGates } from "./team.mjs";
|
|
|
12
12
|
*/
|
|
13
13
|
const cliRuns = new Map();
|
|
14
14
|
export function activeCliRuns() { return [...cliRuns.keys()]; }
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 团队派发指令正文(卡 `-270` · 需求 `R186`)。
|
|
17
|
+
*
|
|
18
|
+
* 状态取值一律**英文枚举在前、中文作括号对照**(与工具描述同形态):
|
|
19
|
+
* 中文只出现在「括号里当列名解释」的位置,**不再出现在「该传什么值」的位置** ——
|
|
20
|
+
* 执行 agent 照抄指令填中文必然被拒(`INVALID_FIELD`),这正是 R186 要消灭的那类系统性误导。
|
|
21
|
+
*
|
|
22
|
+
* 导出供守卫直接断言**真正下发的这份文本**(此前守卫靠 `find` 源码某一行,
|
|
23
|
+
* 锁到的是相邻说明行 ⇒ 真正下发的内容从没人锁过)。
|
|
24
|
+
*/
|
|
25
|
+
export function directiveFor(engine, { teamId, taskRef, requirementId, qualityGates = null }) {
|
|
16
26
|
const head = engine === "official"
|
|
17
27
|
? `[派发团队 · DSH官方自带] teamId=${teamId} 请作为 Lead 用 spawn_teammate 召集成员、team_task_create 建任务看板。`
|
|
18
28
|
: engine === "nanmicoder"
|
|
@@ -25,9 +35,9 @@ function directiveFor(engine, { teamId, taskRef, requirementId, qualityGates = n
|
|
|
25
35
|
head,
|
|
26
36
|
`目标:${taskRef}`,
|
|
27
37
|
requirementId ? `需求:${requirementId}` : "",
|
|
28
|
-
`工作台任务标识:${taskRef}
|
|
38
|
+
`工作台任务标识:${taskRef}(状态回写用英文枚举:in_progress(进行中)/ in_review(待验收)/ blocked(受阻)/ canceled(取消);失败→blocked)`,
|
|
29
39
|
`质量门(${source === "configured" ? "配置" : "默认"}):${gates.join("→")}`,
|
|
30
|
-
"操作指引:按依赖就绪认领 → 执行 →
|
|
40
|
+
"操作指引:按依赖就绪认领 → 执行 → 提交 in_review(待验收);不得置 done(完成只能人工确认)。",
|
|
31
41
|
].filter(Boolean).join("\n");
|
|
32
42
|
}
|
|
33
43
|
|
|
@@ -255,6 +265,27 @@ function inflightOf(store, task) {
|
|
|
255
265
|
return null;
|
|
256
266
|
}
|
|
257
267
|
|
|
268
|
+
/**
|
|
269
|
+
* 投给项目**主会话**的汇总指令正文(卡 `-270` · 需求 `R186`)。
|
|
270
|
+
*
|
|
271
|
+
* 抽成独立纯函数有两个理由:
|
|
272
|
+
* ① **守卫必须锁「真正发出去的那份文本」** —— 此前守卫靠 `find` 源码里的某一行,
|
|
273
|
+
* 结果锁到的是相邻的说明行(`工作台任务标识:` 那行),而**真正投进会话的**
|
|
274
|
+
* 「提交"待验收"(失败→受阻)」从来没人锁过 ⇒ 口径错、守卫却绿。
|
|
275
|
+
* ② 口径只改一处:状态取值**英文枚举在前、中文作括号对照**,中文不再出现在
|
|
276
|
+
* 「该传什么值」的位置(`提交 in_review(待验收)`/`失败回写 blocked(受阻)`)。
|
|
277
|
+
*
|
|
278
|
+
* 导出供守卫直接断言真实产出,而不是去源码里捞某一行字符串。
|
|
279
|
+
*/
|
|
280
|
+
export function buildDispatchBriefLines(dispatched = []) {
|
|
281
|
+
// 一轮只投递**一条**汇总指令(避免拆解出大量子任务时刷屏目标会话)。
|
|
282
|
+
const lines = [`[任务工作台下发] 本轮派发 ${dispatched.length} 条任务(请作为项目执行团队承接):`];
|
|
283
|
+
for (const d of dispatched) lines.push(`· ${d.task}(teamId=${d.teamId})`);
|
|
284
|
+
lines.push("操作指引:按依赖就绪逐个认领 → 执行 → 提交 in_review(待验收);失败回写 blocked(受阻);不得置 done(完成只能人工确认)。");
|
|
285
|
+
lines.push("状态回写:taskboard_update_status 的 status 取英文枚举 in_progress(进行中)/ in_review(待验收)/ blocked(受阻)/ canceled(取消);中文只是列名,传中文会被拒。完成不得自行置 done(人工确认)。");
|
|
286
|
+
return lines;
|
|
287
|
+
}
|
|
288
|
+
|
|
258
289
|
/**
|
|
259
290
|
* 任务下发:把派发指令投递到项目**主会话**(真实闭环)。无绑定会话 / 宿主无 prompt 能力则如实标注降级。
|
|
260
291
|
*/
|
|
@@ -266,13 +297,8 @@ async function deliverDispatched(store, project, dispatched) {
|
|
|
266
297
|
const reason = boundSessionId ? "prompt-unavailable" : "no-bound-session";
|
|
267
298
|
for (const d of dispatched) { d.delivered = false; d.deliveryReason = reason; }
|
|
268
299
|
if (!boundSessionId || typeof port?.sendPrompt !== "function") return result;
|
|
269
|
-
// 一轮只投递**一条**汇总指令(避免拆解出大量子任务时刷屏目标会话)。
|
|
270
|
-
const lines = [`[任务工作台下发] 本轮派发 ${dispatched.length} 条任务(请作为项目执行团队承接):`];
|
|
271
|
-
for (const d of dispatched) lines.push(`· ${d.task}(teamId=${d.teamId})`);
|
|
272
|
-
lines.push("操作指引:按依赖就绪逐个认领 → 执行 → 提交\"待验收\"(失败→受阻);不得置\"完成\"(人工确认)。");
|
|
273
|
-
lines.push("状态回写:任务看板 taskboard_update_status(进行中/待验收/受阻),完成由人工确认。");
|
|
274
300
|
let r = null;
|
|
275
|
-
try { r = await port.sendPrompt(boundSessionId,
|
|
301
|
+
try { r = await port.sendPrompt(boundSessionId, buildDispatchBriefLines(dispatched).join("\n")); } catch { r = null; }
|
|
276
302
|
const sent = Boolean(r?.sent);
|
|
277
303
|
for (const d of dispatched) {
|
|
278
304
|
d.delivered = sent;
|
|
@@ -156,6 +156,10 @@ export function assertSplitTasks(tasks) {
|
|
|
156
156
|
out.push({
|
|
157
157
|
title,
|
|
158
158
|
description: t.description === undefined || t.description === null ? "" : String(t.description),
|
|
159
|
+
// 卡 `-273`(需求 `R189`):acceptance 也必须**穿过**校验层。
|
|
160
|
+
// 2026-11-17 真机读数:批量生成 16 张卡 desc=0 / acc=0,而条目本身 desc 4509 / acc 213
|
|
161
|
+
// —— 内容全被这一层丢掉,与 2026-10-28 `kind` 丢失是**同一个缺陷形状**(界面/接口给了,实现静默丢)。
|
|
162
|
+
acceptance: t.acceptance === undefined || t.acceptance === null ? "" : String(t.acceptance),
|
|
159
163
|
owner: t.owner === undefined || t.owner === null ? null : String(t.owner),
|
|
160
164
|
// 2026-10-28:kind 必须**穿过**校验层(旧实现丢字段 ⇒ 界面填了等于没填)
|
|
161
165
|
kind: normalizeSplitKind(t.kind),
|
|
@@ -167,6 +171,99 @@ export function assertSplitTasks(tasks) {
|
|
|
167
171
|
return out;
|
|
168
172
|
}
|
|
169
173
|
|
|
174
|
+
/** 条目正文里取「标签:」段(含后续同段行;用于兜底装配卡片正文;取不到返回空串)。 */
|
|
175
|
+
const BLOCK_LABELS = ["目标", "范围", "改动范围", "禁止", "约束", "硬约束", "做法", "报告", "停下", "验收", "关联", "背景"];
|
|
176
|
+
const LABEL_LINE_RE = new RegExp(`^[\\s>*【]*(?:${BLOCK_LABELS.join("|")})\\s*[】]*\\s*[::]`);
|
|
177
|
+
|
|
178
|
+
/** 显式截断:**不静默砍**(-232 的教训:静默 slice 比报错更难查)。 */
|
|
179
|
+
function clipText(text, maxChars) {
|
|
180
|
+
if (text.length <= maxChars) return text;
|
|
181
|
+
const head = text.slice(0, maxChars);
|
|
182
|
+
// 尽量在句读处断开,别把一句话砍成半个词。
|
|
183
|
+
const cut = Math.max(head.lastIndexOf(";"), head.lastIndexOf("。"), head.lastIndexOf("、"));
|
|
184
|
+
const body = cut > maxChars * 0.4 ? head.slice(0, cut) : head;
|
|
185
|
+
return `${body}…(截断,全文见需求条目)`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function pickLabelledBlock(body, labels, maxChars = 9999) {
|
|
189
|
+
const lines = String(body ?? "").split(/\r?\n/);
|
|
190
|
+
for (const label of labels) {
|
|
191
|
+
const head = new RegExp(`^[\\s>*【]*(?:${label})\\s*[】]*\\s*[::]\\s*(.*)$`);
|
|
192
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
193
|
+
const m = head.exec(lines[i]);
|
|
194
|
+
if (!m) continue;
|
|
195
|
+
const parts = [];
|
|
196
|
+
if (m[1].trim()) parts.push(m[1].trim());
|
|
197
|
+
for (let j = i + 1; j < lines.length; j += 1) {
|
|
198
|
+
const line = lines[j];
|
|
199
|
+
if (line.trim() === "") break;
|
|
200
|
+
if (LABEL_LINE_RE.test(line)) break;
|
|
201
|
+
parts.push(line.trim());
|
|
202
|
+
}
|
|
203
|
+
const text = parts.join(";").replace(/;{2,}/g, ";").replace(/:;/g, ":").trim();
|
|
204
|
+
if (text === "") return "";
|
|
205
|
+
return clipText(text, maxChars);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return "";
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 卡 `-273`(需求 `R189`):**批量/分拆生成任务时的兜底正文**(规范 `docs/规范/07-条目详情规范.md` §2.1 七块)。
|
|
213
|
+
*
|
|
214
|
+
* 为什么要有兜底:入口(界面「批量生成任务」、MCP、CLI)都只传 `{title}` 时,旧实现会建出
|
|
215
|
+
* **description 为空**的卡 —— 执行者打开只看到一句标题,没有范围、没有禁止、没有验收,
|
|
216
|
+
* 于是「怎么做都对」「做没做完说不清」。条目上明明写着这些内容,却在建卡时丢了。
|
|
217
|
+
*
|
|
218
|
+
* 口径:**只装配、不臆造** —— 条目写了「范围:」「约束:」就摘出来;没写就如实写「未写,开工前须补」,
|
|
219
|
+
* 绝不替人编一个范围。八个标签顺序固定,便于逐行核对。
|
|
220
|
+
*
|
|
221
|
+
* 2026-11-17 二修:首版只摘「范围:」**同一行**,而本仓条目普遍写成「范围:」换行 + ①②③ 清单
|
|
222
|
+
* ⇒ 摘出来只剩一句「包含(本仓库可改):」,等于没写。改为**摘整段**并按预算显式截断。
|
|
223
|
+
*/
|
|
224
|
+
export function buildSplitTaskDescription(item, title) {
|
|
225
|
+
const ref = String(item?.identifier ?? "").trim();
|
|
226
|
+
const body = String(item?.description ?? "");
|
|
227
|
+
const itemTitle = String(item?.title ?? "").trim() || String(title ?? "").trim();
|
|
228
|
+
const scopeFull = pickLabelledBlock(body, ["范围", "改动范围"]);
|
|
229
|
+
const forbidFull = pickLabelledBlock(body, ["禁止", "约束", "硬约束"]);
|
|
230
|
+
const acceptance = String(item?.acceptance ?? "").trim();
|
|
231
|
+
// 验收整段照搬会把正文顶出 800 字预算(-272 实测 593 字)⇒ 超过 200 字改指向验收字段,不重复粘贴。
|
|
232
|
+
const accLine = acceptance === ""
|
|
233
|
+
? "需求条目未写验收 —— 开工前必须补,否则本卡无法判定完成"
|
|
234
|
+
: acceptance.length <= 200
|
|
235
|
+
? acceptance
|
|
236
|
+
: `见本卡「验收标准」字段(原文 ${acceptance.length} 字,此处不重复粘贴)`;
|
|
237
|
+
|
|
238
|
+
const assemble = (scopeChars, forbidChars) => [
|
|
239
|
+
`${String(title ?? "").trim()}(来自需求 ${ref || "(未命名)"})`,
|
|
240
|
+
"",
|
|
241
|
+
`目标:${itemTitle}`,
|
|
242
|
+
`范围:${scopeFull ? clipText(scopeFull, scopeChars) : `包含:按需求 ${ref || "(未命名)"} 正文所列落点;移出:需求之外的一切(条目未写「范围」段 —— 开工前须补)`}`,
|
|
243
|
+
`禁止:AGENTS.md §3 硬禁令(不碰 :3080 运行实例 / 不改 ~/.dsh/** / 不删用户数据 / 对外动作须报批)${forbidFull ? `;本轮特禁:${clipText(forbidFull, forbidChars)}` : ";本轮特禁:未指定(开工前须补)"}`,
|
|
244
|
+
"做法:1) 读需求条目正文与相关文件,先贴原文;2) 按「范围」改动,一次一处;3) 改完再贴改后原文",
|
|
245
|
+
"报告:四节证据(判定 / 偏离说明 / 边界自查 / 产物路径 + sha256)",
|
|
246
|
+
"停下:报错 / 超范围 / 验收不满足 / 需新变量 ⇒ 停,不重试",
|
|
247
|
+
`验收:${accLine}`,
|
|
248
|
+
`关联:需求 ${ref || "(未命名)"};规范 docs/规范/07-条目详情规范.md §2.1`,
|
|
249
|
+
].join("\n");
|
|
250
|
+
|
|
251
|
+
// 预算 800(规范 07 §4):从宽到紧逐档收缩,**每一档都是显式截断**(带「截断」字样)。
|
|
252
|
+
const caps = [[360, 220], [260, 150], [180, 100], [120, 70], [80, 50]];
|
|
253
|
+
let text = "";
|
|
254
|
+
for (const [scopeChars, forbidChars] of caps) {
|
|
255
|
+
text = assemble(scopeChars, forbidChars);
|
|
256
|
+
if (text.length <= 800) break;
|
|
257
|
+
}
|
|
258
|
+
return text;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 卡 `-273`(需求 `R189`):兜底验收 —— 条目有验收就逐字沿用,没有就**显式标注缺口**(不留空)。 */
|
|
262
|
+
export function buildSplitTaskAcceptance(item) {
|
|
263
|
+
const acceptance = String(item?.acceptance ?? "").trim();
|
|
264
|
+
return acceptance || "需求条目未写验收 —— 开工前必须补";
|
|
265
|
+
}
|
|
266
|
+
|
|
170
267
|
// ------------------------------------------------------------------ AI 条目化(FR-36,首选路径;规则解析为 fallback)
|
|
171
268
|
|
|
172
269
|
/** 构造 AI 条目化的系统提示(要求严格 JSON 输出)。 */
|