taskboard-workbench 0.3.1 → 0.3.3
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 +101 -2
- package/index.js +112 -13
- package/package.json +6 -2
- package/scripts/tb-flow.mjs +109 -8
- package/skills/taskboard-flow/SKILL.md +2 -2
- package/skills/taskboard-flow/references/injection.md +76 -29
- package/skills/taskboard-flow/references/steps/S5.md +21 -1
- package/spec/docs/01-/351/241/271/347/233/256/345/274/200/345/261/200.md +63 -0
- package/spec/docs/02-/346/265/201/347/250/213/346/211/247/350/241/214/344/270/216/346/235/241/347/233/256.md +110 -0
- package/spec/docs/README.md +36 -0
- package/spec/docs/assets//346/235/241/347/233/256/350/257/246/346/203/205/346/250/241/346/235/277.md +105 -0
- package/spec/norms/item-detail.md +73 -0
- package/spec/norms/manifest.json +7 -0
- package/src/core/config.mjs +12 -3
- package/src/core/contract.mjs +17 -7
- package/src/core/data-dir-hint.mjs +52 -0
- package/src/core/docs-assets.mjs +135 -0
- package/src/core/errors.mjs +11 -0
- package/src/core/evidence.mjs +28 -0
- package/src/core/executor.mjs +27 -7
- package/src/core/executors.mjs +279 -0
- package/src/core/flow-inject.mjs +190 -0
- package/src/core/instance-lease.mjs +113 -0
- package/src/core/kickoff.mjs +289 -0
- package/src/core/norms.mjs +177 -0
- package/src/core/requirements.mjs +38 -0
- package/src/core/store.mjs +333 -36
- package/src/core/verify.mjs +39 -4
- package/src/mcp/flow-block.mjs +30 -0
- package/src/mcp/server.mjs +19 -6
- package/src/mcp/tools.mjs +99 -7
- package/src/server/api.mjs +361 -11
- package/web/app.js +1077 -82
- package/web/tokens.css +166 -28
package/src/core/store.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* owner 为 tasks 正式列(t24)——老库的 `owner:<role>` 标签在打开时一次性迁移(幂等)。
|
|
5
5
|
* 注意:tasks_owner_idx 只在迁移函数里创建(老库建表语句是 no-op,提前建索引会因缺列失败)。
|
|
6
6
|
*/
|
|
7
|
-
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { mkdirSync } from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import { normalizeOwner, splitOwnerLabels } from "./owner.mjs";
|
|
21
21
|
import { TbError, invalidField } from "./errors.mjs";
|
|
22
22
|
import { computeContract, diffContract, evaluateSubmittedContract, loadNorms } from "./contract.mjs";
|
|
23
|
+
import { resolveNorms } from "./norms.mjs";
|
|
23
24
|
import { UNTAKEN_COMMENT_MARKER, detectUntakenDelivery } from "./delivery.mjs";
|
|
24
25
|
import { VERIFY_MAX_COMMAND, parseVerifyComment } from "./verify.mjs";
|
|
25
26
|
import {
|
|
@@ -27,16 +28,18 @@ import {
|
|
|
27
28
|
elaborateDocument, formatRequirementIdentifier, normalizeTitle, parseRequirementIdentifier,
|
|
28
29
|
titleKey, assertRequirementStatus, normalizeCandidates, summarizeRequirementCompletion,
|
|
29
30
|
clampElaborateLimit, ELABORATE_PREVIEW_SIZE, DEFAULT_ELABORATE_LIMIT, MAX_ELABORATE_LIMIT,
|
|
31
|
+
deriveDetailState,
|
|
30
32
|
} from "./requirements.mjs";
|
|
31
33
|
import { TEAM_WRITABLE_STATUSES } from "./team.mjs";
|
|
32
|
-
import { evidenceProblems, normalizeArtifactRefs, verifyArtifactRefs } from "./evidence.mjs";
|
|
34
|
+
import { evidenceProblems, makeResolver, normalizeArtifactRefs, verifyArtifactRefs } from "./evidence.mjs";
|
|
33
35
|
import { REVIEW_SOURCE_STATUSES, REVIEW_IDLE_MS, detectReviewDeadlock, reviewReturnStatus } from "./review.mjs";
|
|
34
36
|
import { NOTIFY_DELIVERY_MODES, buildNotifyMessage, normalizeDeliveryMode, selectNotifyEvents } from "./notify.mjs";
|
|
35
37
|
import { HUMAN_REVIEW_LABEL, assertConclusion, categoryLabel, conclusionOutcome, isHumanReviewTask, validateHumanReviewDraft } from "./human-review.mjs";
|
|
36
38
|
// 项目记忆(2026-10-28 拍板 D-M1):L2 记忆条目,与内核表同库;**不是第二真源**(必带 provenance)。
|
|
37
39
|
import { createMemoryApi } from "./memory.mjs";
|
|
40
|
+
import { createLeaseApi } from "./instance-lease.mjs";
|
|
38
41
|
|
|
39
|
-
export const SCHEMA_VERSION =
|
|
42
|
+
export const SCHEMA_VERSION = 15; // 15:agents / agent_sessions + task_evidence.evidence_hash + WAL(0-B-b · 卡 -239);14:项目设置 flow_inject_policy(P5 档 C · 卡 -210);13:交付物证据 task_evidence + 授权快照 task_mandates(0-B · 卡 -197);12:契约快照
|
|
40
43
|
// 条目化数量口径(卡 `-169` P4②):定义在 requirements.mjs(纯模块),此处转发以便调用方就近取用。
|
|
41
44
|
export { clampElaborateLimit, DEFAULT_ELABORATE_LIMIT, MAX_ELABORATE_LIMIT, ELABORATE_PREVIEW_SIZE };
|
|
42
45
|
|
|
@@ -62,12 +65,16 @@ export function normalizeAcceptance(value) {
|
|
|
62
65
|
/**
|
|
63
66
|
* 任务级「复核动作」(命令)归一:空串/未传 → `null` =**回落**(任务级 → 项目 `envConfig.verifyCommand`
|
|
64
67
|
* → 内置默认),只有显式写了命令才覆盖。长度上限与 FR-90 的 `normalizeVerifyCommand` **同口径**
|
|
65
|
-
* (常量从 `verify.mjs`
|
|
68
|
+
* (常量从 `verify.mjs` 取,避免两份);超限**抛错不截断**(截断会把命令切成语法错误 ⇒ 自动复核 exit 2)。
|
|
66
69
|
*/
|
|
67
70
|
export function normalizeTaskVerifyCommand(value) {
|
|
68
71
|
if (value === undefined || value === null) return null;
|
|
69
72
|
const s = String(value).trim();
|
|
70
|
-
|
|
73
|
+
if (s === "") return null;
|
|
74
|
+
if (s.length > VERIFY_MAX_COMMAND) {
|
|
75
|
+
throw new TbError("USAGE_ERROR", `复核命令过长(${s.length} 字符 > 上限 ${VERIFY_MAX_COMMAND}):请压短后再提交(旧行为是静默截断,截断后命令会变成语法错误)`, { length: s.length, max: VERIFY_MAX_COMMAND });
|
|
76
|
+
}
|
|
77
|
+
return s;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
// ---- 尝试记录与事件流(FR-82) ------------------------------------------------
|
|
@@ -240,6 +247,9 @@ create table if not exists project_settings (
|
|
|
240
247
|
env_config text not null default '{}',
|
|
241
248
|
team_template text not null default '{}',
|
|
242
249
|
loop_config text not null default '{}',
|
|
250
|
+
-- P5 档 C(卡 -210 · 需求 R128):开局注入策略 off(默认)/ main-only / main+exec / all。
|
|
251
|
+
-- 读点在 index.js 的 createSession() 出口与 src/core/flow-inject.mjs;默认 off ⇒ 零行为变化。
|
|
252
|
+
flow_inject_policy text not null default 'off',
|
|
243
253
|
updated_at text not null
|
|
244
254
|
);
|
|
245
255
|
create table if not exists project_sessions (
|
|
@@ -279,6 +289,8 @@ create table if not exists task_evidence (
|
|
|
279
289
|
verdict text not null, deviation text not null default '', boundary text not null default '',
|
|
280
290
|
artifacts text not null default '[]', artifact_refs text not null default '[]',
|
|
281
291
|
refs_state text not null default 'unchecked',
|
|
292
|
+
-- 0-B-b(FR-106 第 5 条):同一份证据重复提交按指纹幂等(返回首次结果、不增行)
|
|
293
|
+
evidence_hash text,
|
|
282
294
|
actor text not null, task_version integer not null, created_at text not null
|
|
283
295
|
);
|
|
284
296
|
create index if not exists task_evidence_task_idx on task_evidence(task_id, created_at);
|
|
@@ -289,6 +301,24 @@ create table if not exists task_mandates (
|
|
|
289
301
|
requirement_ref text, contract_version text, norms_digest text,
|
|
290
302
|
scope text not null default '', claim_owner text, claim_source text, created_at text not null
|
|
291
303
|
);
|
|
304
|
+
-- agent 身份(FR-108 / 0-B-b):**进程级本地身份**,不是鉴权体系。
|
|
305
|
+
-- token_hash 只建表留接口 —— stdio MCP 没有鉴权通道,令牌要等 S3 才有载体;
|
|
306
|
+
-- 所以**任何地方都不得以「有这张表」为由宣称鉴权已生效**。
|
|
307
|
+
create table if not exists agents (
|
|
308
|
+
id text primary key,
|
|
309
|
+
kind text not null default 'agent' check (kind in ('human','agent')),
|
|
310
|
+
display_name text not null default '',
|
|
311
|
+
token_hash text,
|
|
312
|
+
permission_profile text,
|
|
313
|
+
created_at text not null
|
|
314
|
+
);
|
|
315
|
+
-- 身份 ≠ 会话:会话绑定只是 agent 的**可选**属性(未绑定会话的本地 agent 同样有身份)。
|
|
316
|
+
create table if not exists agent_sessions (
|
|
317
|
+
agent_id text not null references agents(id) on delete cascade,
|
|
318
|
+
session_id text,
|
|
319
|
+
bound_at text not null,
|
|
320
|
+
primary key (agent_id, session_id)
|
|
321
|
+
);
|
|
292
322
|
create index if not exists task_mandates_task_idx on task_mandates(task_id, created_at);
|
|
293
323
|
|
|
294
324
|
create index if not exists task_runs_task_idx on task_runs(task_id, started_at);
|
|
@@ -575,6 +605,8 @@ const rowToRequirementItem = (row) => (row ? {
|
|
|
575
605
|
id: row.id, identifier: row.identifier, projectId: row.project_id, docId: row.doc_id,
|
|
576
606
|
title: row.title, description: row.description, acceptance: row.acceptance,
|
|
577
607
|
priority: row.priority, status: row.status, source: row.source, normTitle: row.norm_title,
|
|
608
|
+
// `R159`(D-1=`c` / D-3=派生):完整性形态是**算出来的**,不是存的 —— 列表/详情/完成度三处同源。
|
|
609
|
+
detailState: deriveDetailState(row.description),
|
|
578
610
|
feasibility: row.feasibility ?? null, feasibilityReason: row.feasibility_reason ?? null,
|
|
579
611
|
feasibilityBy: row.feasibility_by ?? null, feasibilityOverride: row.feasibility_override ?? null,
|
|
580
612
|
createdAt: row.created_at, updatedAt: row.updated_at,
|
|
@@ -599,6 +631,85 @@ function insertRequirementItem(db, { id, projectId, docId, title, description, a
|
|
|
599
631
|
return identifier;
|
|
600
632
|
}
|
|
601
633
|
|
|
634
|
+
// ---------------- 卡 `-234`(需求 `R171`):需求条目「简写」与「报错要能照抄」 ----------------
|
|
635
|
+
/**
|
|
636
|
+
* 简写形态:`R170`(只有序号,不带项目前缀)。
|
|
637
|
+
*
|
|
638
|
+
* 为什么简写**必须带 projectId 才解析**:identifier 是 `<项目id>-R<序号>`,同一个序号在**多个项目**里都可能
|
|
639
|
+
* 存在;没有项目范围就只能猜,而猜必然选错(卡里明令禁止把简写做成跨项目模糊匹配)。
|
|
640
|
+
* 没有项目范围时不是「猜一个」,而是报错并把各项目的候选列出来(列候选 ≠ 解析)。
|
|
641
|
+
*/
|
|
642
|
+
const REQUIREMENT_SHORT_REF = /^R([1-9]\d*)$/;
|
|
643
|
+
/** 报错体里给几条例目示例:够照抄,又不把错误体撑大。 */
|
|
644
|
+
const REQUIREMENT_REF_EXAMPLES = 5;
|
|
645
|
+
|
|
646
|
+
/** 取若干条「可照抄」的 identifier(给了项目就只取该项目的 —— 跨项目示例会把人带偏)。 */
|
|
647
|
+
function requirementRefExamples(db, projectId) {
|
|
648
|
+
const rows = projectId
|
|
649
|
+
? db.prepare("select identifier from requirement_items where project_id = ? order by created_at, rowid limit ?").all(projectId, REQUIREMENT_REF_EXAMPLES)
|
|
650
|
+
: db.prepare("select identifier from requirement_items order by created_at, rowid limit ?").all(REQUIREMENT_REF_EXAMPLES);
|
|
651
|
+
return rows.map((row) => row.identifier);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* `REQUIREMENT_NOT_FOUND` 的**唯一**构造点(错误码一字不改:下游按 `code` 分支)。
|
|
656
|
+
*
|
|
657
|
+
* 两条硬口径(卡 `-234`):
|
|
658
|
+
* ① **不得谎报**:`R170` 这条不存在 ≠ 需求不存在;「写法没被认出来」更不等于「数据没有」。
|
|
659
|
+
* ② **报错就是文档**:`details` 里必须带可直接照抄的完整标识(`hint` + `examples`),
|
|
660
|
+
* 调用方不必再去翻文档就知道该写什么。
|
|
661
|
+
*/
|
|
662
|
+
function buildRequirementNotFoundError(db, ref, options = {}) {
|
|
663
|
+
const raw = typeof ref === "string" ? ref.trim() : String(ref ?? "");
|
|
664
|
+
const projectId = typeof options?.projectId === "string" ? options.projectId.trim() : "";
|
|
665
|
+
const examples = requirementRefExamples(db, projectId);
|
|
666
|
+
const exampleText = examples.length ? examples.join(" / ") : "(库里暂无条目)";
|
|
667
|
+
// 没给项目时示例只能跨项目取 —— 必须标明「不限项目」,否则等于暗示这条在本项目里可用。
|
|
668
|
+
const exampleLabel = projectId === "" ? "库里现有条目(不限项目)" : "本项目可用条目";
|
|
669
|
+
const short = REQUIREMENT_SHORT_REF.exec(raw);
|
|
670
|
+
if (short) {
|
|
671
|
+
const sequence = Number(short[1]);
|
|
672
|
+
const resolvedIdentifier = projectId === "" ? null : formatRequirementIdentifier(projectId, sequence);
|
|
673
|
+
if (resolvedIdentifier) {
|
|
674
|
+
// 已按项目解析成完整标识,仍然查不到 ⇒ 是「条目不存在」,不是「写法不对」。
|
|
675
|
+
return new TbError("REQUIREMENT_NOT_FOUND", `需求条目不存在:${raw}(简写已按项目 ${projectId} 解析为 ${resolvedIdentifier},该项目内没有这条)`, {
|
|
676
|
+
ref: raw,
|
|
677
|
+
refKind: "short",
|
|
678
|
+
projectId,
|
|
679
|
+
resolvedIdentifier,
|
|
680
|
+
hint: `\`${raw}\` 这种简写只在「给定项目」内解析:本次按 \`${projectId}\` 解析成 \`${resolvedIdentifier}\`,照样查不到 ⇒ 是**条目不存在**,不是写法没被认出来。可照抄的${exampleLabel}:${exampleText}。`,
|
|
681
|
+
examples,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
// 没有项目范围:**不猜**。把各项目里同序号的全标识列成候选,让人自己挑一条。
|
|
685
|
+
const candidates = db
|
|
686
|
+
.prepare("select identifier from requirement_items where identifier like ? order by created_at, rowid limit ?")
|
|
687
|
+
.all(`%-R${sequence}`, REQUIREMENT_REF_EXAMPLES)
|
|
688
|
+
.map((row) => row.identifier);
|
|
689
|
+
const suggest = candidates[0] ?? examples[0] ?? `<项目id>-R${sequence}`;
|
|
690
|
+
return new TbError("REQUIREMENT_NOT_FOUND", `需求条目引用无法解析:${raw} —— 简写缺少项目范围(同一序号在多个项目里都可能存在,未做跨项目猜测);请写完整标识,如 ${suggest}`, {
|
|
691
|
+
ref: raw,
|
|
692
|
+
refKind: "short",
|
|
693
|
+
projectId: null,
|
|
694
|
+
resolvedIdentifier: null,
|
|
695
|
+
candidates,
|
|
696
|
+
hint: `简写 \`${raw}\` 必须带项目才能解析。两条路:① 写完整标识(形如 \`<项目id>-R${sequence}\`)${candidates.length ? `,库里现有:${candidates.join(" / ")}` : ""};② 走带项目的入口(如 \`POST /api/tasks\` 给 projectId,简写即按该项目解析)。`,
|
|
697
|
+
examples,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
// 非简写:id / 完整标识 / 其它形态 —— 统一补上「能照抄的写法」,message 保持原文(真·不存在)。
|
|
701
|
+
const kind = parseRequirementIdentifier(raw) ? "identifier" : "other";
|
|
702
|
+
return new TbError("REQUIREMENT_NOT_FOUND", `需求条目不存在:${raw}`, {
|
|
703
|
+
ref: raw,
|
|
704
|
+
refKind: kind,
|
|
705
|
+
...(projectId === "" ? {} : { projectId }),
|
|
706
|
+
hint: kind === "identifier"
|
|
707
|
+
? `\`${raw}\` 是完整标识形态(\`<项目id>-R<序号>\`),本次就是按完整标识查的 ⇒ 该条目确实不存在。可照抄的${exampleLabel}:${exampleText}。`
|
|
708
|
+
: `\`${raw}\` 既不是条目 id、也不是 \`<项目id>-R<序号>\` 形态;可用写法:完整标识(如 \`${examples[0] ?? "<项目id>-R<序号>"}\`)或简写 \`R<序号>\`(需带项目)。`,
|
|
709
|
+
examples,
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
602
713
|
function isConstraintError(error, needle) {
|
|
603
714
|
const message = String(error?.message ?? "");
|
|
604
715
|
return message.includes("UNIQUE constraint failed") && message.includes(needle);
|
|
@@ -610,12 +721,37 @@ function rowToTaskEvidence(row) {
|
|
|
610
721
|
id: row.id, taskId: row.task_id,
|
|
611
722
|
verdict: row.verdict, deviation: row.deviation, boundary: row.boundary,
|
|
612
723
|
artifacts: safeJsonArray(row.artifacts), artifactRefs: safeJsonArray(row.artifact_refs),
|
|
613
|
-
refsState: row.refs_state,
|
|
724
|
+
refsState: row.refs_state, evidenceHash: row.evidence_hash ?? null,
|
|
725
|
+
actor: row.actor, taskVersion: row.task_version, createdAt: row.created_at,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
function rowToAgent(row) {
|
|
729
|
+
return {
|
|
730
|
+
id: row.id, kind: row.kind, displayName: row.display_name,
|
|
731
|
+
// 注意:**不回传 token_hash 原文之外的任何东西** —— 这里只如实标注"有没有登记过",
|
|
732
|
+
// 不把哈希值抛给调用方(哈希本身也不该在 UI/日志里流转)。
|
|
733
|
+
hasTokenHash: Boolean(row.token_hash),
|
|
734
|
+
permissionProfile: row.permission_profile ?? null, createdAt: row.created_at,
|
|
614
735
|
};
|
|
615
736
|
}
|
|
616
737
|
function safeJsonArray(raw) {
|
|
617
738
|
try { const v = JSON.parse(raw ?? "[]"); return Array.isArray(v) ? v : []; } catch { return []; }
|
|
618
739
|
}
|
|
740
|
+
/**
|
|
741
|
+
* 证据指纹(FR-106 第 5 条 / 0-B-b):同一次回填重复调用不该长第二行。
|
|
742
|
+
*
|
|
743
|
+
* 为什么用 sha256 而不是拿内容建唯一索引:内容列是 JSON 文本,顺序一变就不等;
|
|
744
|
+
* 指纹先归一(固定字段序 + 归一后的 refs),同一份证据无论怎么传都得到同一个值。
|
|
745
|
+
* 与 `src/mcp/tools.mjs` 的 `evidenceHash` **不是一回事**:那个给评论去重、只覆盖 `evidence[]`。
|
|
746
|
+
*/
|
|
747
|
+
function evidenceFingerprint({ verdict, deviation, boundary, artifacts, refs }) {
|
|
748
|
+
const material = JSON.stringify({
|
|
749
|
+
verdict, deviation, boundary,
|
|
750
|
+
artifacts: [...artifacts],
|
|
751
|
+
refs: (refs ?? []).map((r) => [r.kind, r.ref, r.note ?? ""]),
|
|
752
|
+
});
|
|
753
|
+
return createHash("sha256").update(material).digest("hex").slice(0, 32);
|
|
754
|
+
}
|
|
619
755
|
|
|
620
756
|
export function migrateOwnerField(db) {
|
|
621
757
|
const columns = db.prepare("pragma table_info(tasks)").all().map((row) => row.name);
|
|
@@ -671,12 +807,30 @@ export function migrateTeamMembers(db) {
|
|
|
671
807
|
return { addedTeamMemberExecutorColumn: false };
|
|
672
808
|
}
|
|
673
809
|
|
|
810
|
+
/**
|
|
811
|
+
* 迁移(幂等,0-B-b):老库的 `task_evidence` 补 `evidence_hash` 列 + 指纹索引。
|
|
812
|
+
*
|
|
813
|
+
* 为什么必须用迁移而不是只改建表语句:`create table if not exists` 对已存在的表是 no-op,
|
|
814
|
+
* 老库(schema 14)不会自动长出新列 —— 那样「幂等提交」在存量库上会直接报 no column。
|
|
815
|
+
*/
|
|
816
|
+
export function migrateTaskEvidenceHash(db) {
|
|
817
|
+
const columns = db.prepare("pragma table_info(task_evidence)").all().map((row) => row.name);
|
|
818
|
+
if (columns.length === 0) return { addedEvidenceHashColumn: false };
|
|
819
|
+
if (!columns.includes("evidence_hash")) {
|
|
820
|
+
db.exec("alter table task_evidence add column evidence_hash text");
|
|
821
|
+
db.exec("create index if not exists task_evidence_hash_idx on task_evidence(task_id, evidence_hash)");
|
|
822
|
+
return { addedEvidenceHashColumn: true };
|
|
823
|
+
}
|
|
824
|
+
db.exec("create index if not exists task_evidence_hash_idx on task_evidence(task_id, evidence_hash)");
|
|
825
|
+
return { addedEvidenceHashColumn: false };
|
|
826
|
+
}
|
|
827
|
+
|
|
674
828
|
/** 迁移(幂等):老库的 projects 表补 `next_req_seq` 列(需求条目编号序列)。 */
|
|
675
829
|
export function migrateRequirementSeq(db) {
|
|
676
830
|
const projectColumns = db.prepare("pragma table_info(projects)").all().map((row) => row.name);
|
|
677
831
|
const taskColumns = db.prepare("pragma table_info(tasks)").all().map((row) => row.name);
|
|
678
832
|
const candidateColumns = db.prepare("pragma table_info(requirement_candidates)").all().map((row) => row.name);
|
|
679
|
-
const result = { addedReqSeqColumn: false, addedTaskRequirementColumn: false, addedCandidateSourceColumn: false, addedTaskSessionColumn: false, addedProjectSessionColumn: false, addedClaimColumn: false, addedFailureColumn: false, addedBlockColumn: false, addedRunColumn: false, addedReviewColumn: false, addedCommentEditColumn: false, addedBoardPositionColumn: false };
|
|
833
|
+
const result = { addedReqSeqColumn: false, addedTaskRequirementColumn: false, addedCandidateSourceColumn: false, addedTaskSessionColumn: false, addedProjectSessionColumn: false, addedClaimColumn: false, addedFailureColumn: false, addedBlockColumn: false, addedRunColumn: false, addedReviewColumn: false, addedCommentEditColumn: false, addedBoardPositionColumn: false, addedFlowInjectPolicyColumn: false };
|
|
680
834
|
if (!projectColumns.includes("next_req_seq")) {
|
|
681
835
|
db.exec("alter table projects add column next_req_seq integer not null default 1");
|
|
682
836
|
result.addedReqSeqColumn = true;
|
|
@@ -690,6 +844,11 @@ export function migrateRequirementSeq(db) {
|
|
|
690
844
|
db.exec("alter table project_settings add column loop_config text not null default '{}'");
|
|
691
845
|
result.addedLoopColumn = true;
|
|
692
846
|
}
|
|
847
|
+
// P5 档 C(卡 `-210`):老库补 `flow_inject_policy`。默认 `off` ⇒ **迁移本身不改变任何行为**。
|
|
848
|
+
if (psColumns.length && !psColumns.includes("flow_inject_policy")) {
|
|
849
|
+
db.exec("alter table project_settings add column flow_inject_policy text not null default 'off'");
|
|
850
|
+
result.addedFlowInjectPolicyColumn = true;
|
|
851
|
+
}
|
|
693
852
|
const depColumns = db.prepare("pragma table_info(task_dependencies)").all().map((row) => row.name);
|
|
694
853
|
if (depColumns.length && !depColumns.includes("reason")) {
|
|
695
854
|
db.exec("alter table task_dependencies add column reason text");
|
|
@@ -883,10 +1042,20 @@ export function openStore(options = {}) {
|
|
|
883
1042
|
// 回滚开关:`TB_CONTRACT_MODE=warn`(一行降级,等价 2026-10-29 起的旧行为)。
|
|
884
1043
|
const contractMode =
|
|
885
1044
|
String((options.env ?? process.env)?.TB_CONTRACT_MODE ?? "reject").trim().toLowerCase() === "warn" ? "warn" : "reject";
|
|
886
|
-
// P1 契约快照:机器规范默认随包读 `spec/norms/*.md`;测试可传 `normsDir`
|
|
887
|
-
|
|
1045
|
+
// P1 契约快照:机器规范默认随包读 `spec/norms/*.md`;测试可传 `normsDir` / 直接传 `norms` / 传解析器。
|
|
1046
|
+
// 卡 `-216`(R160):项目若有 `<工作区>/.taskboard/norms/`,**优先用副本**,缺项逐份回落包内。
|
|
1047
|
+
const packagedNormsDir = options.normsDir ?? path.join(PKG_ROOT, "spec", "norms");
|
|
888
1048
|
const injectedNorms = Array.isArray(options.norms) ? options.norms : null;
|
|
889
|
-
const
|
|
1049
|
+
const resolveNormsForProject = (projectId) => {
|
|
1050
|
+
if (injectedNorms) return { source: "injected", dir: packagedNormsDir, norms: injectedNorms, fallbackIds: [] };
|
|
1051
|
+
if (typeof options.normsResolver === "function") {
|
|
1052
|
+
const out = options.normsResolver(projectId);
|
|
1053
|
+
return Array.isArray(out) ? { source: "injected", dir: packagedNormsDir, norms: out, fallbackIds: [] } : out;
|
|
1054
|
+
}
|
|
1055
|
+
if (options.normsDir) return { source: "packaged", dir: packagedNormsDir, norms: loadNorms(packagedNormsDir), fallbackIds: [] };
|
|
1056
|
+
const project = store.getProject(projectId);
|
|
1057
|
+
return resolveNorms({ packagedDir: packagedNormsDir, workspacePath: project?.workspacePath ?? null });
|
|
1058
|
+
};
|
|
890
1059
|
|
|
891
1060
|
let db;
|
|
892
1061
|
let migration;
|
|
@@ -895,8 +1064,14 @@ export function openStore(options = {}) {
|
|
|
895
1064
|
db = new DatabaseSync(dbPath);
|
|
896
1065
|
db.exec("pragma foreign_keys = on");
|
|
897
1066
|
db.exec("pragma busy_timeout = 5000");
|
|
1067
|
+
// 0-B-b · F6:`WAL` —— 读写不互相阻塞(Web 读看板时 MCP/CLI 仍可写)。
|
|
1068
|
+
// **连带义务**:备份不能只拷 `.sqlite`(已提交但未 checkpoint 的页在 `-wal` 里),
|
|
1069
|
+
// 必须走 `.backup` / `VACUUM INTO`;`tools/baseline-metrics.mjs` 已用 `backup()`,
|
|
1070
|
+
// `tools/audit-intake.mjs` 与 `tools/seed-docs.mjs` 本轮一并改掉 `copyFileSync`。
|
|
1071
|
+
// `:memory:` 不支持 WAL(也无意义),显式跳过。
|
|
1072
|
+
if (dbPath !== ":memory:") db.exec("pragma journal_mode = wal");
|
|
898
1073
|
db.exec(SCHEMA_SQL);
|
|
899
|
-
migration = { ...migrateOwnerField(db), ...migrateRequirementSeq(db), ...migrateTeamMembers(db) };
|
|
1074
|
+
migration = { ...migrateOwnerField(db), ...migrateRequirementSeq(db), ...migrateTeamMembers(db), ...migrateTaskEvidenceHash(db) };
|
|
900
1075
|
} catch (error) {
|
|
901
1076
|
const wrapped = new TbError(
|
|
902
1077
|
"STORE_UNAVAILABLE",
|
|
@@ -1047,7 +1222,8 @@ export function openStore(options = {}) {
|
|
|
1047
1222
|
contractSnapshot(projectId) {
|
|
1048
1223
|
const project = store.requireProject(projectId);
|
|
1049
1224
|
const doc = store.getRequirementDoc(projectId);
|
|
1050
|
-
const
|
|
1225
|
+
const resolved = resolveNormsForProject(projectId);
|
|
1226
|
+
const norms = resolved.norms;
|
|
1051
1227
|
const gates = {
|
|
1052
1228
|
attribution: strictAttribution ? "reject" : "warn",
|
|
1053
1229
|
authorization: "hard",
|
|
@@ -1061,7 +1237,9 @@ export function openStore(options = {}) {
|
|
|
1061
1237
|
: null;
|
|
1062
1238
|
return {
|
|
1063
1239
|
project: { id: project.id, name: project.name },
|
|
1064
|
-
normsDir,
|
|
1240
|
+
normsDir: resolved.dir ?? packagedNormsDir,
|
|
1241
|
+
normsSource: resolved.source ?? "packaged",
|
|
1242
|
+
normsFallbackIds: resolved.fallbackIds ?? [],
|
|
1065
1243
|
snapshot,
|
|
1066
1244
|
baseline: stored,
|
|
1067
1245
|
changed,
|
|
@@ -1314,7 +1492,8 @@ export function openStore(options = {}) {
|
|
|
1314
1492
|
// 归因校验必须在**同一事务内**:条目不存在 / 跨项目 ⇒ 整笔回滚(连 next_seq 一起回滚,
|
|
1315
1493
|
// 不留编号空洞、不留孤儿卡)。
|
|
1316
1494
|
if (requirementRef !== "") {
|
|
1317
|
-
|
|
1495
|
+
// 卡 `-234`:建卡**一定**有 projectId ⇒ 简写 `R170` 在这里按本项目解析(不用跨项目猜)。
|
|
1496
|
+
const item = store.requireRequirementItemRef(requirementRef, { projectId });
|
|
1318
1497
|
if (item.projectId !== projectId) {
|
|
1319
1498
|
throw new TbError("DEPENDENCY_CROSS_PROJECT", `条目与任务必须同项目(条目 ${item.projectId},任务 ${projectId})`, { requirementProjectId: item.projectId, taskProjectId: projectId });
|
|
1320
1499
|
}
|
|
@@ -1730,14 +1909,33 @@ export function openStore(options = {}) {
|
|
|
1730
1909
|
},
|
|
1731
1910
|
|
|
1732
1911
|
// ---------------------------------------------------------------- 需求条目(FR-35)
|
|
1733
|
-
|
|
1912
|
+
/**
|
|
1913
|
+
* 需求条目引用解析:条目 id / 完整 identifier(`<项目id>-R<序号>`)/ **简写 `R170`**。
|
|
1914
|
+
*
|
|
1915
|
+
* 卡 `-234`(需求 `R171`):此前只认前两种,于是「照着需求编号写」的人写 `R170` 直接吃
|
|
1916
|
+
* `需求条目不存在:R170` —— 把「写法没被认出来」说成「数据没有」,引导人去查数据。
|
|
1917
|
+
*
|
|
1918
|
+
* 简写**只在给定 `projectId` 的范围内**解析(`R170` → `<projectId>-R170`,DB 唯一约束保证不打嗝);
|
|
1919
|
+
* 没给 `projectId` 时**不猜**(跨项目同序号必然选错),交给 `requireRequirementItemRef` 报错并列候选。
|
|
1920
|
+
*
|
|
1921
|
+
* @param {string} ref
|
|
1922
|
+
* @param {{ projectId?: string }} [options]
|
|
1923
|
+
*/
|
|
1924
|
+
getRequirementItemRef(ref, options = {}) {
|
|
1734
1925
|
if (typeof ref !== "string" || ref.trim() === "") return null;
|
|
1735
1926
|
const value = ref.trim();
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1927
|
+
const direct = store.getRequirementItemById(value) ?? store.getRequirementItemByIdentifier(value);
|
|
1928
|
+
if (direct) return direct;
|
|
1929
|
+
const short = REQUIREMENT_SHORT_REF.exec(value);
|
|
1930
|
+
if (!short) return null;
|
|
1931
|
+
const projectId = typeof options?.projectId === "string" ? options.projectId.trim() : "";
|
|
1932
|
+
if (projectId === "") return null;
|
|
1933
|
+
return store.getRequirementItemByIdentifier(formatRequirementIdentifier(projectId, Number(short[1])));
|
|
1934
|
+
},
|
|
1935
|
+
/** 同上,查不到就抛 `REQUIREMENT_NOT_FOUND`(错误码不变;`details` 带可直接照抄的完整标识)。 */
|
|
1936
|
+
requireRequirementItemRef(ref, options = {}) {
|
|
1937
|
+
const item = store.getRequirementItemRef(ref, options);
|
|
1938
|
+
if (!item) throw buildRequirementNotFoundError(db, ref, options);
|
|
1741
1939
|
return item;
|
|
1742
1940
|
},
|
|
1743
1941
|
getRequirementItemById(id) {
|
|
@@ -2482,6 +2680,29 @@ export function openStore(options = {}) {
|
|
|
2482
2680
|
return store.requestReview(ref, { comment, actor: "team" }).task;
|
|
2483
2681
|
},
|
|
2484
2682
|
// ---------------- 评审流程(FR-83) ----------------
|
|
2683
|
+
/**
|
|
2684
|
+
* 缺省评审者(卡 `-244` / 需求 `R178`):项目团队模板里含 `review` 的角色名。
|
|
2685
|
+
*
|
|
2686
|
+
* 为什么要有:`requestReview` 不传 reviewer 时原来一律留空,而 `detectReviewDeadlock`
|
|
2687
|
+
* 对「reviewer 为空且超过阈值」**必然**产出 `unassigned` 死锁(`review.mjs:73-79`)——
|
|
2688
|
+
* 即「待验收」只要没人手填评审者就注定变高危诊断。真机里 8 张卡 reviewer 全空、
|
|
2689
|
+
* vibe-5/6 挂 37 分钟,就是这条的产物。
|
|
2690
|
+
* 找不到 review 角色(或项目没配团队模板)⇒ 仍返回 null,**旧行为一字不变**。
|
|
2691
|
+
*/
|
|
2692
|
+
pickDefaultReviewer(projectId) {
|
|
2693
|
+
try {
|
|
2694
|
+
const roles = store.getProjectSettings(projectId)?.teamTemplate?.roles;
|
|
2695
|
+
const norm = (name) => String(name ?? "").trim().toLowerCase();
|
|
2696
|
+
if (Array.isArray(roles)) {
|
|
2697
|
+
const hit = roles.map((r) => norm(r?.role ?? r)).find((n) => n.includes("review"));
|
|
2698
|
+
if (hit) return hit;
|
|
2699
|
+
} else if (roles && typeof roles === "object") {
|
|
2700
|
+
const hit = Object.keys(roles).map(norm).find((n) => n.includes("review"));
|
|
2701
|
+
if (hit) return hit;
|
|
2702
|
+
}
|
|
2703
|
+
} catch { /* 项目设置读不到 ⇒ 不指派,保持旧行为 */ }
|
|
2704
|
+
return null;
|
|
2705
|
+
},
|
|
2485
2706
|
/**
|
|
2486
2707
|
* 请求评审(FR-83 的一等流程):进「待验收」+ **指派评审者** + 记下**来源列**(返工退回哪一列)。
|
|
2487
2708
|
* 释放实现认领(FR-77);执行成功照 FR-78 记账;事件流写 `review_requested`。
|
|
@@ -2489,6 +2710,9 @@ export function openStore(options = {}) {
|
|
|
2489
2710
|
requestReview(ref, { reviewer = null, dependsOn = null, comment = "", actor = "team", now = null } = {}) {
|
|
2490
2711
|
const task = store.requireTaskRef(ref);
|
|
2491
2712
|
const at = new Date(now ?? Date.now()).toISOString();
|
|
2713
|
+
// 卡 `-244`(R178):显式传了的优先;没传就按项目团队模板补一个评审角色,
|
|
2714
|
+
// 否则「待验收」必然在阈值后变成 `unassigned` 评审死锁。
|
|
2715
|
+
const assigned = reviewer ?? store.pickDefaultReviewer(task.projectId);
|
|
2492
2716
|
// 来源列:第一次提交时记下当前列;返工后重提则**沿用**上次来源列(保证返工总回同一实现列)
|
|
2493
2717
|
const source = task.status === "in_review"
|
|
2494
2718
|
? (task.reviewSourceStatus ?? "in_progress")
|
|
@@ -2499,13 +2723,17 @@ export function openStore(options = {}) {
|
|
|
2499
2723
|
review_depends_on = case when ? is null then review_depends_on else ? end,
|
|
2500
2724
|
claim_lock = null, claim_expires = null, claim_owner = null, last_heartbeat_at = null,
|
|
2501
2725
|
version = version + 1, updated_at = ? where id = ?`,
|
|
2502
|
-
).run(
|
|
2726
|
+
).run(assigned, at, source, dependsOn, dependsOn, at, task.id);
|
|
2503
2727
|
if (comment) store.addComment(task.id, { body: comment });
|
|
2504
2728
|
store.markTaskSucceeded(task.identifier); // FR-78:产出已提交待验收 = 本次执行成功
|
|
2505
|
-
|
|
2506
|
-
|
|
2729
|
+
// 卡 `-245`(R178):已经在「待验收」再点一次,是同态迁移 —— 不写空转事件
|
|
2730
|
+
// (真机 8 卡攒了 16 条 `in_review→in_review`,纯日志噪音)。`review_requested` 照写,动作本身要留痕。
|
|
2731
|
+
if (task.status !== "in_review") {
|
|
2732
|
+
store.recordTaskEvent(task.id, { type: "status_changed", from: task.status, to: "in_review", actor });
|
|
2733
|
+
}
|
|
2734
|
+
store.recordTaskEvent(task.id, { type: "review_requested", to: "in_review", actor, detail: `${assigned ? `指派评审者 ${assigned}` : "未指派评审者"}·来源列 ${source}${comment ? `|${comment}` : ""}` });
|
|
2507
2735
|
const next = store.getTaskById(task.id);
|
|
2508
|
-
if (!
|
|
2736
|
+
if (!assigned) {
|
|
2509
2737
|
try { store.addComment(task.id, { body: `待评审(未指派评审者):${REVIEW_IDLE_MS / 60000} 分钟无人处理将产出「评审死锁」诊断。` }); } catch { /* ignore */ }
|
|
2510
2738
|
}
|
|
2511
2739
|
return { task: next, review: { state: next.reviewState, reviewer: next.reviewer, sourceStatus: source, round: next.reviewRound }, deadlock: detectReviewDeadlock(store, next) };
|
|
@@ -2700,6 +2928,15 @@ export function openStore(options = {}) {
|
|
|
2700
2928
|
* 不留半条记录。`refs_state` 由调用方给定的 `resolve` 决定(不给则 `unchecked`):解不开的
|
|
2701
2929
|
* `artifact_refs` 永远不许被当作"已校验通过"。
|
|
2702
2930
|
*/
|
|
2931
|
+
/**
|
|
2932
|
+
* 写一条交付物证据(FR-106 的唯一落库点:MCP `card_evidence_submit` 与 HTTP `POST /api/tasks/:ref/evidence` 都走这里)。
|
|
2933
|
+
*
|
|
2934
|
+
* 三条口径(0-B-b 卡 `-239`):
|
|
2935
|
+
* ① **四字段硬门**在事务前 —— 缺一即 `EVIDENCE_INCOMPLETE`,零落库(既有行为,不改);
|
|
2936
|
+
* ② **核验 root 绑 `project.workspacePath`** —— 不传 `resolve` 时用项目工作区,**不用 `process.cwd()`**
|
|
2937
|
+
* (MCP 子进程的 cwd 是客户端目录,拿它核验等于核到别的仓库);
|
|
2938
|
+
* ③ **同指纹幂等** —— 同一张卡上 `evidenceHash` 相同 ⇒ 返回首次那条,不增行。
|
|
2939
|
+
*/
|
|
2703
2940
|
addTaskEvidence(ref, input = {}) {
|
|
2704
2941
|
const task = store.requireTaskRef(ref);
|
|
2705
2942
|
const problems = evidenceProblems(input);
|
|
@@ -2708,15 +2945,28 @@ export function openStore(options = {}) {
|
|
|
2708
2945
|
}
|
|
2709
2946
|
const artifacts = (Array.isArray(input.artifacts) ? input.artifacts : []).map((a) => String(a).trim()).filter(Boolean);
|
|
2710
2947
|
const refs = normalizeArtifactRefs(input.artifactRefs);
|
|
2711
|
-
|
|
2948
|
+
// 核验器:调用方给就用调用方的(测试注入),否则**必须**按项目工作区建。
|
|
2949
|
+
let resolver = input.resolve;
|
|
2950
|
+
if (typeof resolver !== "function") {
|
|
2951
|
+
const project = store.getProject(task.projectId);
|
|
2952
|
+
resolver = makeResolver({ root: project?.workspacePath ?? null });
|
|
2953
|
+
}
|
|
2954
|
+
const verified = verifyArtifactRefs(refs, resolver);
|
|
2955
|
+
const verdict = String(input.verdict).trim();
|
|
2956
|
+
const deviation = String(input.deviation ?? "").trim();
|
|
2957
|
+
const boundary = String(input.boundary ?? "").trim();
|
|
2958
|
+
const evidenceHash = evidenceFingerprint({ verdict, deviation, boundary, artifacts, refs });
|
|
2959
|
+
const existing = db.prepare("select * from task_evidence where task_id = ? and evidence_hash = ? order by created_at, rowid limit 1").get(task.id, evidenceHash);
|
|
2960
|
+
if (existing) return { ...rowToTaskEvidence(existing), deduped: true };
|
|
2712
2961
|
const id = randomUUID();
|
|
2713
2962
|
const at = nowIso();
|
|
2714
2963
|
db.prepare(
|
|
2715
|
-
`insert into task_evidence (id, task_id, verdict, deviation, boundary, artifacts, artifact_refs, refs_state, actor, task_version, created_at)
|
|
2716
|
-
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
2717
|
-
).run(id, task.id,
|
|
2718
|
-
JSON.stringify(artifacts), JSON.stringify(refs), verified.state,
|
|
2719
|
-
|
|
2964
|
+
`insert into task_evidence (id, task_id, verdict, deviation, boundary, artifacts, artifact_refs, refs_state, evidence_hash, actor, task_version, created_at)
|
|
2965
|
+
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
2966
|
+
).run(id, task.id, verdict, deviation, boundary,
|
|
2967
|
+
JSON.stringify(artifacts), JSON.stringify(refs), verified.state, evidenceHash,
|
|
2968
|
+
String(input.actor ?? "agent"), Number(task.version), at);
|
|
2969
|
+
return { ...store.getTaskEvidenceById(id), deduped: false };
|
|
2720
2970
|
},
|
|
2721
2971
|
getTaskEvidenceById(id) {
|
|
2722
2972
|
const row = db.prepare("select * from task_evidence where id = ?").get(id);
|
|
@@ -2726,6 +2976,42 @@ export function openStore(options = {}) {
|
|
|
2726
2976
|
const task = store.requireTaskRef(ref);
|
|
2727
2977
|
return db.prepare("select * from task_evidence where task_id = ? order by created_at, rowid").all(task.id).map(rowToTaskEvidence);
|
|
2728
2978
|
},
|
|
2979
|
+
/**
|
|
2980
|
+
* 登记 agent 身份(FR-108 / 0-B-b)—— **进程级本地身份**,不是鉴权。
|
|
2981
|
+
*
|
|
2982
|
+
* 幂等:同一个 `id` 再登记**复用已有行**(不新建、不换 id),只补空字段。
|
|
2983
|
+
* `tokenHash` 只落接口位:stdio MCP 没有鉴权通道,**本轮不宣称鉴权生效**。
|
|
2984
|
+
*/
|
|
2985
|
+
registerAgent(input = {}) {
|
|
2986
|
+
const declared = typeof input.id === "string" ? input.id.trim() : "";
|
|
2987
|
+
const id = declared !== "" ? declared : `anon-${randomUUID()}`;
|
|
2988
|
+
const existing = db.prepare("select * from agents where id = ?").get(id);
|
|
2989
|
+
const at = nowIso();
|
|
2990
|
+
if (existing) {
|
|
2991
|
+
// 只补空字段,不覆盖已登记的值(否则重启时传不同 display_name 会把历史身份改掉)。
|
|
2992
|
+
db.prepare("update agents set display_name = case when display_name = '' then ? else display_name end, permission_profile = coalesce(permission_profile, ?) where id = ?")
|
|
2993
|
+
.run(String(input.displayName ?? "").trim(), input.permissionProfile ?? null, id);
|
|
2994
|
+
return { ...rowToAgent(db.prepare("select * from agents where id = ?").get(id)), created: false };
|
|
2995
|
+
}
|
|
2996
|
+
db.prepare("insert into agents (id, kind, display_name, token_hash, permission_profile, created_at) values (?, ?, ?, ?, ?, ?)")
|
|
2997
|
+
.run(id, input.kind === "human" ? "human" : "agent", String(input.displayName ?? "").trim(),
|
|
2998
|
+
input.tokenHash ?? null, input.permissionProfile ?? null, at);
|
|
2999
|
+
return { ...rowToAgent(db.prepare("select * from agents where id = ?").get(id)), created: true };
|
|
3000
|
+
},
|
|
3001
|
+
getAgent(id) {
|
|
3002
|
+
const row = db.prepare("select * from agents where id = ?").get(String(id));
|
|
3003
|
+
return row ? rowToAgent(row) : null;
|
|
3004
|
+
},
|
|
3005
|
+
listAgents() {
|
|
3006
|
+
return db.prepare("select * from agents order by created_at, rowid").all().map(rowToAgent);
|
|
3007
|
+
},
|
|
3008
|
+
bindAgentSession(agentId, sessionId) {
|
|
3009
|
+
if (!store.getAgent(agentId)) throw new TbError("AGENT_NOT_FOUND", `未登记的 agent:${agentId}`, { agentId });
|
|
3010
|
+
if (sessionId === null || sessionId === undefined || String(sessionId).trim() === "") return null;
|
|
3011
|
+
db.prepare("insert or ignore into agent_sessions (agent_id, session_id, bound_at) values (?, ?, ?)")
|
|
3012
|
+
.run(String(agentId), String(sessionId), nowIso());
|
|
3013
|
+
return { agentId: String(agentId), sessionId: String(sessionId) };
|
|
3014
|
+
},
|
|
2729
3015
|
/** 有效证据 = 最新一条(历史留档但不再生效)。 */
|
|
2730
3016
|
latestTaskEvidence(ref) {
|
|
2731
3017
|
const all = store.listTaskEvidence(ref);
|
|
@@ -3105,21 +3391,23 @@ export function openStore(options = {}) {
|
|
|
3105
3391
|
store.requireProject(projectId);
|
|
3106
3392
|
const row = db.prepare("select * from project_settings where project_id = ?").get(projectId);
|
|
3107
3393
|
const parse = (s) => { try { return JSON.parse(s); } catch { return {}; } };
|
|
3394
|
+
// `flowInjectPolicy`:P5 档 C(卡 `-210`)的开局注入策略;无设置行 / 老库(列已迁移,默认 `off`)一律 `off`。
|
|
3108
3395
|
return row
|
|
3109
|
-
? { projectId, envConfig: parse(row.env_config), teamTemplate: parse(row.team_template), loop: parse(row.loop_config), updatedAt: row.updated_at }
|
|
3110
|
-
: { projectId, envConfig: {}, teamTemplate: {}, loop: {}, updatedAt: null };
|
|
3396
|
+
? { projectId, envConfig: parse(row.env_config), teamTemplate: parse(row.team_template), loop: parse(row.loop_config), flowInjectPolicy: row.flow_inject_policy ?? "off", updatedAt: row.updated_at }
|
|
3397
|
+
: { projectId, envConfig: {}, teamTemplate: {}, loop: {}, flowInjectPolicy: "off", updatedAt: null };
|
|
3111
3398
|
},
|
|
3112
|
-
saveProjectSettings(projectId, { envConfig, teamTemplate, loop } = {}) {
|
|
3399
|
+
saveProjectSettings(projectId, { envConfig, teamTemplate, loop, flowInjectPolicy } = {}) {
|
|
3113
3400
|
store.requireProject(projectId);
|
|
3114
3401
|
const current = store.getProjectSettings(projectId);
|
|
3115
3402
|
const nextEnv = envConfig === undefined ? current.envConfig : envConfig;
|
|
3116
3403
|
const nextTpl = teamTemplate === undefined ? current.teamTemplate : teamTemplate;
|
|
3117
3404
|
const nextLoop = loop === undefined ? current.loop : loop;
|
|
3405
|
+
const nextPolicy = flowInjectPolicy === undefined ? (current.flowInjectPolicy ?? "off") : flowInjectPolicy;
|
|
3118
3406
|
const ts = nowIso();
|
|
3119
3407
|
db.prepare(
|
|
3120
|
-
`insert into project_settings (project_id, env_config, team_template, loop_config, updated_at) values (
|
|
3121
|
-
on conflict(project_id) do update set env_config = excluded.env_config, team_template = excluded.team_template, loop_config = excluded.loop_config, updated_at = excluded.updated_at`,
|
|
3122
|
-
).run(projectId, JSON.stringify(nextEnv ?? {}), JSON.stringify(nextTpl ?? {}), JSON.stringify(nextLoop ?? {}), ts);
|
|
3408
|
+
`insert into project_settings (project_id, env_config, team_template, loop_config, flow_inject_policy, updated_at) values (?,?,?,?,?,?)
|
|
3409
|
+
on conflict(project_id) do update set env_config = excluded.env_config, team_template = excluded.team_template, loop_config = excluded.loop_config, flow_inject_policy = excluded.flow_inject_policy, updated_at = excluded.updated_at`,
|
|
3410
|
+
).run(projectId, JSON.stringify(nextEnv ?? {}), JSON.stringify(nextTpl ?? {}), JSON.stringify(nextLoop ?? {}), String(nextPolicy ?? "off"), ts);
|
|
3123
3411
|
return store.getProjectSettings(projectId);
|
|
3124
3412
|
},
|
|
3125
3413
|
/** 列出团队执行记录(可按目标任务过滤),并带出目标任务编号/标题,供工作台"归属团队"视图使用。 */
|
|
@@ -3460,6 +3748,13 @@ export function openStore(options = {}) {
|
|
|
3460
3748
|
legacyOwnerLabels: count("select count(*) as n from tasks where labels like '%owner:%'"),
|
|
3461
3749
|
dbPath,
|
|
3462
3750
|
dataDir,
|
|
3751
|
+
// 卡 `-237`:`role` = writer | follower;follower 表示「另一个实例正持有写者租约」。
|
|
3752
|
+
// 这里刻意用 **现读**(fresh):health 是给「我现在能不能写」这个判断看的,
|
|
3753
|
+
// 吃 15s 的本地缓存会让提示滞后于事实。
|
|
3754
|
+
role: typeof store.instanceRoleFresh === "function" ? store.instanceRoleFresh() : "writer",
|
|
3755
|
+
leaseOwner: typeof store.instanceLeaseOwnerFresh === "function" ? store.instanceLeaseOwnerFresh() : null,
|
|
3756
|
+
// 卡 `-236`:默认目录搬家后的**只读**迁移提示(空新库 + 有数据的旧库)。由宿主侧探测后挂上,探测不到就是 null。
|
|
3757
|
+
dataDirHint: store.dataDirHint ?? null,
|
|
3463
3758
|
schemaVersion: SCHEMA_VERSION,
|
|
3464
3759
|
migration,
|
|
3465
3760
|
};
|
|
@@ -3468,6 +3763,8 @@ export function openStore(options = {}) {
|
|
|
3468
3763
|
|
|
3469
3764
|
// 项目记忆:同库、同事务语义,但**不感知** MCP/CLI/Web(只是用例层的又一扇门)。
|
|
3470
3765
|
Object.assign(store, createMemoryApi({ db, nowIso, randomUUID }));
|
|
3766
|
+
// 卡 `-237`(R173):多实例单写者租约(不 acquire 的调用方恒 writer ⇒ 零行为变化)。
|
|
3767
|
+
Object.assign(store, createLeaseApi({ db, nowIso, randomUUID }));
|
|
3471
3768
|
|
|
3472
3769
|
return store;
|
|
3473
3770
|
}
|